-
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.
Improving type safety for fetch results (#7)
Improving type safety for fetch results (#7)
- Loading branch information
Showing
25 changed files
with
951 additions
and
392 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,7 @@ | ||
--- | ||
"@zemd/http-client": major | ||
"@zemd/flickr-rest-api": major | ||
"@zemd/figma-rest-api": major | ||
--- | ||
|
||
improving type safety for getting results instead Response, adding tests |
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,34 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: "Build & Test: ${{ matrix.os }}" | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: true | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js ${{ matrix.node_version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node_version }} | ||
|
||
- name: Setup bun | ||
uses: oven-sh/setup-bun@v2 | ||
|
||
- name: Install Dependencies | ||
run: bun install | ||
|
||
- name: Run tests | ||
run: bun run test |
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
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 |
---|---|---|
@@ -1,79 +1,121 @@ | ||
import { z } from "zod"; | ||
import { method, query, type TEndpointDecTuple } from "@zemd/http-client"; | ||
import { method, query } from "@zemd/http-client"; | ||
|
||
export const PaginationQuerySchema = z.object({ | ||
page_size: z.number().optional(), | ||
after: z.number().optional(), | ||
before: z.number().optional(), | ||
}); | ||
|
||
export interface GetTeamComponentsQuery extends z.infer<typeof PaginationQuerySchema> {} | ||
export interface GetTeamComponentsQuery | ||
extends z.infer<typeof PaginationQuerySchema> {} | ||
|
||
/** | ||
* Get a paginated list of published components within a team library | ||
*/ | ||
export const getTeamComponents = (teamId: string, options: GetTeamComponentsQuery): TEndpointDecTuple => { | ||
return [`/v1/teams/${teamId}/components`, [method("GET"), query(PaginationQuerySchema.passthrough().parse(options))]]; | ||
export const getTeamComponents = ( | ||
teamId: string, | ||
options: GetTeamComponentsQuery, | ||
) => { | ||
return { | ||
url: `/v1/teams/${teamId}/components`, | ||
transformers: [ | ||
method("GET"), | ||
query(PaginationQuerySchema.passthrough().parse(options)), | ||
], | ||
}; | ||
}; | ||
|
||
/** | ||
* Get a list of published components within a file library | ||
*/ | ||
export const getFileComponents = (key: string): TEndpointDecTuple => { | ||
return [`/v1/files/${key}/components`, [method("GET")]]; | ||
export const getFileComponents = (key: string) => { | ||
return { | ||
url: `/v1/files/${key}/components`, | ||
transformers: [method("GET")], | ||
}; | ||
}; | ||
|
||
/** | ||
* Get metadata on a component by key. | ||
*/ | ||
export const getComponent = (key: string): TEndpointDecTuple => { | ||
return [`/v1/components/${key}`, [method("GET")]]; | ||
export const getComponent = (key: string) => { | ||
return { | ||
url: `/v1/components/${key}`, | ||
transformers: [method("GET")], | ||
}; | ||
}; | ||
|
||
export interface GetTeamComponentSetsQuery extends z.infer<typeof PaginationQuerySchema> {} | ||
export interface GetTeamComponentSetsQuery | ||
extends z.infer<typeof PaginationQuerySchema> {} | ||
/** | ||
* Get a paginated list of published component sets within a team library | ||
*/ | ||
export const getTeamComponentSets = (teamId: string, options: GetTeamComponentSetsQuery): TEndpointDecTuple => { | ||
return [ | ||
`/v1/teams/${teamId}/component_sets`, | ||
[method("GET"), query(PaginationQuerySchema.passthrough().parse(options))], | ||
]; | ||
export const getTeamComponentSets = ( | ||
teamId: string, | ||
options: GetTeamComponentSetsQuery, | ||
) => { | ||
return { | ||
url: `/v1/teams/${teamId}/component_sets`, | ||
transformers: [ | ||
method("GET"), | ||
query(PaginationQuerySchema.passthrough().parse(options)), | ||
], | ||
}; | ||
}; | ||
|
||
/** | ||
* Get a list of published component sets within a file library | ||
*/ | ||
export const getFileComponentSets = (key: string): TEndpointDecTuple => { | ||
return [`/v1/files/${key}/component_sets`, [method("GET")]]; | ||
export const getFileComponentSets = (key: string) => { | ||
return { | ||
url: `/v1/files/${key}/component_sets`, | ||
transformers: [method("GET")], | ||
}; | ||
}; | ||
|
||
/** | ||
* Get metadata on a component set by key. | ||
*/ | ||
export const getComponentSet = (key: string): TEndpointDecTuple => { | ||
return [`/v1/component_sets/${key}`, [method("GET")]]; | ||
export const getComponentSet = (key: string) => { | ||
return { | ||
url: `/v1/component_sets/${key}`, | ||
transformers: [method("GET")], | ||
}; | ||
}; | ||
|
||
export interface GetTeamStylesQuery extends z.infer<typeof PaginationQuerySchema> {} | ||
export interface GetTeamStylesQuery | ||
extends z.infer<typeof PaginationQuerySchema> {} | ||
|
||
/** | ||
* Get a paginated list of published styles within a team library | ||
*/ | ||
export const getTeamStyles = (teamId: string, options: GetTeamStylesQuery): TEndpointDecTuple => { | ||
return [`/v1/teams/${teamId}/styles`, [method("GET"), query(PaginationQuerySchema.passthrough().parse(options))]]; | ||
export const getTeamStyles = (teamId: string, options: GetTeamStylesQuery) => { | ||
return { | ||
url: `/v1/teams/${teamId}/styles`, | ||
transformers: [ | ||
method("GET"), | ||
query(PaginationQuerySchema.passthrough().parse(options)), | ||
], | ||
}; | ||
}; | ||
|
||
/** | ||
* Get a list of published styles within a file library | ||
*/ | ||
export const getFileStyles = (key: string): TEndpointDecTuple => { | ||
return [`/v1/files/${key}/styles`, [method("GET")]]; | ||
export const getFileStyles = (key: string) => { | ||
return { | ||
url: `/v1/files/${key}/styles`, | ||
transformers: [method("GET")], | ||
}; | ||
}; | ||
|
||
/** | ||
* Get metadata on a style by key. | ||
*/ | ||
export const getStyle = (key: string): TEndpointDecTuple => { | ||
return [`/v1/styles/${key}`, [method("GET")]]; | ||
export const getStyle = (key: string) => { | ||
return { | ||
url: `/v1/styles/${key}`, | ||
transformers: [method("GET")], | ||
}; | ||
}; |
Oops, something went wrong.