-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api-client, schema): Add workspace's schemas and types in @k…
…eyshade/schema (#520)
- Loading branch information
Showing
26 changed files
with
1,170 additions
and
320 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
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 was deleted.
Oops, something went wrong.
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,10 +1,18 @@ | ||
//Export all Schemas and types | ||
|
||
export * from './pagination/pagination' | ||
export * from './pagination/pagination.types' | ||
|
||
export * from './api-key' | ||
export * from './environment' | ||
export * from './integration' | ||
export * from './project' | ||
export * from './secret' | ||
export * from './variable' | ||
export * from './workspace' | ||
|
||
export * from './workspace/workspace' | ||
export * from './workspace/workspace.types' | ||
|
||
export * from './workspace-role' | ||
|
||
export * from './enums' |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { z } from 'zod' | ||
|
||
export const PageRequestSchema = z.object({ | ||
page: z.number().optional(), | ||
limit: z.number().optional(), | ||
sort: z.string().optional(), | ||
order: z.string().optional(), | ||
search: z.string().optional() | ||
}) | ||
|
||
export const PageResponseSchema = <T>(itemSchema: z.ZodType<T>) => | ||
z.object({ | ||
items: z.array(itemSchema), | ||
metadata: z.object({ | ||
page: z.number(), | ||
perPage: z.number(), | ||
pageCount: z.number(), | ||
totalCount: z.number(), | ||
links: z.object({ | ||
self: z.string(), | ||
first: z.string(), | ||
previous: z.string().nullable(), | ||
next: z.string().nullable(), | ||
last: z.string() | ||
}) | ||
}) | ||
}) | ||
|
||
export const ResponseErrorSchema = z.object({ | ||
message: z.string(), | ||
error: z.string(), | ||
statusCode: z.number() | ||
}) | ||
|
||
export const ClientResponseSchema = <T>(dataSchema: z.ZodType<T>) => | ||
z | ||
.object({ | ||
success: z.boolean(), | ||
error: ResponseErrorSchema.nullable(), | ||
data: dataSchema.nullable() | ||
}) | ||
.refine((obj) => | ||
obj.success | ||
? obj.data !== null && obj.error == null | ||
: obj.data == null && obj.error !== null | ||
) |
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,17 @@ | ||
import { z } from 'zod' | ||
import { | ||
ClientResponseSchema, | ||
PageRequestSchema, | ||
PageResponseSchema, | ||
ResponseErrorSchema | ||
} from './pagination' | ||
|
||
export type PageRequest = z.infer<typeof PageRequestSchema> | ||
|
||
export type PageResponse<T> = z.infer<ReturnType<typeof PageResponseSchema<T>>> | ||
|
||
export type ResponseError = z.infer<typeof ResponseErrorSchema> | ||
|
||
export type ClientResponse<T> = z.infer< | ||
ReturnType<typeof ClientResponseSchema<T>> | ||
> |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.