Skip to content

Commit

Permalink
🏷️ モジュール外で型の名前が重複しないよう変更
Browse files Browse the repository at this point in the history
  • Loading branch information
ZEKE320 committed Apr 7, 2024
1 parent 700b531 commit bad010e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions astro/src/lib/pagedbAPI/createPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const endpoint_url = import.meta.env.PUBLIC_CREATEPAGES_ENDPOINT as string
const PageCreationOutputZod = z.object({
uri: z.string(),
})
type output = z.infer<typeof PageCreationOutputZod>
export type pageCreationOutput = z.infer<typeof PageCreationOutputZod>

/**
* pageDBへページを追加
Expand All @@ -21,7 +21,7 @@ export const api = async ({
}: {
uri: string
accessJwt: string
}): Promise<output | typeof etype> => {
}): Promise<pageCreationOutput | typeof etype> => {
return fetch(endpoint_url, {
method: "POST",
headers: {
Expand All @@ -43,7 +43,7 @@ export const api = async ({
e.name = "Unexpected Response Type@createPage::api"
throw e
}
const apiResult: output = responseParsed.data
const apiResult: pageCreationOutput = responseParsed.data
return apiResult
})
.catch((e: Error) => {
Expand Down
6 changes: 3 additions & 3 deletions astro/src/lib/pagedbAPI/deletePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const endpoint_url = import.meta.env.PUBLIC_DELETEPAGE_ENDPOINT as string
const PageDeletionOutputZod = z.object({
result: z.string(),
})
type output = z.infer<typeof PageDeletionOutputZod>
export type pageDeletionOutput = z.infer<typeof PageDeletionOutputZod>

/**
* pageDBからデータを削除
Expand All @@ -24,7 +24,7 @@ export const api = async ({
id: string
did: string
accessJwt: string
}): Promise<output | typeof etype> => {
}): Promise<pageDeletionOutput | typeof etype> => {
return fetch(endpoint_url, {
method: "POST",
headers: {
Expand All @@ -48,7 +48,7 @@ export const api = async ({
e.name = "Unexpected Response Type@deletePage::api"
throw e
}
const apiResult: output = responseParsed.data
const apiResult: pageDeletionOutput = responseParsed.data
return apiResult
})
.catch((e: Error) => {
Expand Down
10 changes: 6 additions & 4 deletions astro/src/lib/pagedbAPI/getIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ const object = "user"
const IdsFetchOutputZod = z.object({
ids: z.array(z.string()),
})
type output = {
export type idsFetchOutput = {
ids: Array<string>
}

export const api = async ({
handle,
}: {
handle: string
}): Promise<output | typeof etype> => {
}): Promise<idsFetchOutput | typeof etype> => {
const url = new URL(object + "/" + encodeURIComponent(handle), endpoint_url)
return fetch(url, {
method: "GET",
Expand All @@ -26,12 +26,14 @@ export const api = async ({
const responseParsed = IdsFetchOutputZod.safeParse(response.json())

if (!responseParsed.success) {
const e: Error = new Error("Unexpected Response Type@getIds::api")
const e: Error = new Error(
"Unexpected Response Type@getIds::api",
)
e.name = "Unexpected Response Type@getIds::api"
throw e
}

const apiResult: output = responseParsed.data
const apiResult: idsFetchOutput = responseParsed.data
return apiResult
})
.catch((e: Error) => {
Expand Down
14 changes: 7 additions & 7 deletions astro/src/lib/pagedbAPI/getPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export const PageFetchOutputZod = z.object({
}),
),
})
export type output = z.infer<typeof PageFetchOutputZod>
export type pageFetchOutput = z.infer<typeof PageFetchOutputZod>

export const api = async ({
id,
}: {
id: string
}): Promise<output | typeof etype> => {
}): Promise<pageFetchOutput | typeof etype> => {
const url = new URL(object + "/" + encodeURIComponent(id), endpoint_url)
return fetch(url, {
method: "GET",
Expand All @@ -27,17 +27,17 @@ export const api = async ({
},
})
.then(response => {
const responseParsed = PageFetchOutputZod.safeParse(
response.json(),
)
const responseParsed = PageFetchOutputZod.safeParse(response.json())

if (!responseParsed.success) {
const e: Error = new Error("Unexpected Response Type@getPages::api")
const e: Error = new Error(
"Unexpected Response Type@getPages::api",
)
e.name = "Unexpected Response Type@getPages::api"
throw e
}

const apiResult: output = responseParsed.data
const apiResult: pageFetchOutput = responseParsed.data
return apiResult
})
.catch((e: Error) => {
Expand Down

0 comments on commit bad010e

Please sign in to comment.