-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
48 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type FetchT from "@notainc/typed-api-spec/fetch"; | ||
import type { Spec } from "./spec.ts"; | ||
export const GITHUB_API_ORIGIN = "https://api.github.com"; | ||
|
||
let fetchGitHub = fetch as FetchT<typeof GITHUB_API_ORIGIN, Spec>; | ||
if (import.meta.env.DEV) { | ||
const { withValidation } = await import("@notainc/typed-api-spec/fetch"); | ||
const { ZodSpec } = await import("./spec.ts"); | ||
const { newZodValidator } = await import("@notainc/typed-api-spec"); | ||
const v = newZodValidator(ZodSpec); | ||
fetchGitHub = withValidation( | ||
fetch, | ||
ZodSpec, | ||
v.req, | ||
v.res, | ||
) as typeof fetchGitHub; | ||
} | ||
export default fetchGitHub; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ZodApiEndpoints } from "@notainc/typed-api-spec"; | ||
import z from "zod"; | ||
import { ToApiEndpoints } from "@notainc/typed-api-spec/zod"; | ||
|
||
// See https://docs.github.com/ja/rest/repos/repos?apiVersion=2022-11-28#get-all-repository-topics | ||
export const ZodSpec = { | ||
"/repos/:owner/:repo/topics": { | ||
get: { | ||
responses: { | ||
200: { body: z.object({ names: z.string().array() }) }, | ||
400: { | ||
body: z.object({ | ||
message: z.string(), | ||
errors: z.string(), | ||
documentation_url: z.string(), | ||
status: z.number(), | ||
}), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} satisfies ZodApiEndpoints; | ||
export type Spec = ToApiEndpoints<typeof ZodSpec>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters