@orpc/zod 0.0.0-next.e7ee5a9 → 0.0.0-next.e98b833
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.d.mts +53 -60
- package/dist/index.d.ts +53 -60
- package/dist/index.mjs +708 -794
- package/package.json +9 -8
package/README.md
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
33
33
|
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
34
34
|
- **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
|
35
|
-
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
|
35
|
+
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid), Pinia Colada, and more.
|
36
36
|
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
37
37
|
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
38
38
|
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
@@ -55,6 +55,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
55
55
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
56
56
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
57
57
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
58
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
58
59
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
59
60
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
60
61
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
package/dist/index.d.mts
CHANGED
@@ -1,89 +1,82 @@
|
|
1
|
+
import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
2
|
+
import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
|
1
3
|
import { Context } from '@orpc/server';
|
2
|
-
import {
|
4
|
+
import { HandlerPlugin } from '@orpc/server/plugins';
|
3
5
|
import { StandardHandlerOptions } from '@orpc/server/standard';
|
4
|
-
import {
|
5
|
-
import { JSONSchema, SchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
6
|
-
import { StandardSchemaV1 } from '@standard-schema/spec';
|
7
|
-
import { JSONSchema as JSONSchema$1 } from 'json-schema-typed/draft-2020-12';
|
8
|
-
import { ZodTypeDef, CustomErrorParams, ZodType, ZodEffects, ZodTypeAny, input, output } from 'zod';
|
6
|
+
import { AnySchema } from '@orpc/contract';
|
9
7
|
|
10
|
-
declare
|
11
|
-
|
12
|
-
}
|
8
|
+
declare function getCustomJsonSchema(def: ZodTypeDef, options: {
|
9
|
+
strategy: 'input' | 'output' | 'both';
|
10
|
+
}): Exclude<JSONSchema, boolean> | undefined;
|
11
|
+
declare function customJsonSchema<T extends ZodTypeAny, TStrategy extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema<TStrategy extends 'input' ? input<T> : TStrategy extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
|
12
|
+
strategy?: TStrategy;
|
13
|
+
}): T;
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
not: {};
|
15
|
+
type CustomParams = CustomErrorParams & {
|
16
|
+
fatal?: boolean;
|
17
17
|
};
|
18
|
-
|
19
|
-
|
18
|
+
type CustomZodDef = {
|
19
|
+
type: 'blob' | 'regexp' | 'url';
|
20
|
+
} | {
|
21
|
+
type: 'file';
|
22
|
+
mimeType?: string;
|
23
|
+
};
|
24
|
+
declare function setCustomZodDef<T extends ZodTypeDef>(def: T, custom: CustomZodDef): void;
|
25
|
+
declare function getCustomZodDef(def: ZodTypeDef): CustomZodDef | undefined;
|
26
|
+
declare function composeParams<T = unknown>(defaultMessage: (input: T) => string, params: undefined | string | CustomParams | ((input: T) => CustomParams)): (input: T) => CustomParams;
|
27
|
+
|
28
|
+
declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Blob, ZodTypeDef, Blob>;
|
29
|
+
|
30
|
+
declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<File, ZodTypeDef, File> & {
|
31
|
+
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<File, ZodTypeDef, File>, File, File>;
|
20
32
|
};
|
33
|
+
|
34
|
+
declare function regexp(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<RegExp, ZodTypeDef, RegExp>;
|
35
|
+
|
36
|
+
declare function url(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<URL, ZodTypeDef, URL>;
|
37
|
+
|
38
|
+
declare class ZodSmartCoercionPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
39
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
40
|
+
}
|
41
|
+
|
21
42
|
interface ZodToJsonSchemaOptions {
|
22
43
|
/**
|
23
44
|
* Max depth of lazy type, if it exceeds.
|
24
45
|
*
|
25
46
|
* Used `{}` when reach max depth
|
26
47
|
*
|
27
|
-
* @default
|
48
|
+
* @default 3
|
28
49
|
*/
|
29
50
|
maxLazyDepth?: number;
|
30
51
|
/**
|
31
|
-
* The
|
52
|
+
* The schema to be used when the Zod schema is unsupported.
|
32
53
|
*
|
33
|
-
* @
|
54
|
+
* @default { not: {} }
|
34
55
|
*/
|
35
|
-
|
56
|
+
unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
|
36
57
|
/**
|
37
|
-
* The
|
58
|
+
* The schema to be used to represent the any | unknown type.
|
38
59
|
*
|
39
|
-
* @default
|
60
|
+
* @default { }
|
40
61
|
*/
|
41
|
-
|
42
|
-
/**
|
43
|
-
* Track if current level schema is handled custom json schema to prevent recursive
|
44
|
-
*
|
45
|
-
* @internal
|
46
|
-
*/
|
47
|
-
isHandledCustomJSONSchema?: boolean;
|
48
|
-
/**
|
49
|
-
* Track if current level schema is handled zod description to prevent recursive
|
50
|
-
*
|
51
|
-
* @internal
|
52
|
-
*/
|
53
|
-
isHandledZodDescription?: boolean;
|
62
|
+
anyJsonSchema?: Exclude<JSONSchema, boolean>;
|
54
63
|
}
|
55
|
-
declare
|
56
|
-
|
57
|
-
|
58
|
-
|
64
|
+
declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
65
|
+
#private;
|
66
|
+
private readonly maxLazyDepth;
|
67
|
+
private readonly unsupportedJsonSchema;
|
68
|
+
private readonly anyJsonSchema;
|
69
|
+
constructor(options?: ZodToJsonSchemaOptions);
|
70
|
+
condition(schema: AnySchema | undefined): boolean;
|
71
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
59
72
|
}
|
60
73
|
|
61
|
-
type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL';
|
62
|
-
type CustomParams = CustomErrorParams & {
|
63
|
-
fatal?: boolean;
|
64
|
-
};
|
65
|
-
declare function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined;
|
66
|
-
declare function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined;
|
67
|
-
declare function getCustomJSONSchema(def: ZodTypeDef, options?: {
|
68
|
-
mode?: 'input' | 'output';
|
69
|
-
}): Exclude<JSONSchema$1, boolean> | undefined;
|
70
|
-
declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
|
71
|
-
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>;
|
72
|
-
};
|
73
|
-
declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>;
|
74
|
-
declare function invalidDate(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Date, ZodTypeDef, Date>;
|
75
|
-
declare function regexp(options?: CustomParams): ZodType<RegExp, ZodTypeDef, RegExp>;
|
76
|
-
declare function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL>;
|
77
|
-
declare function openapi<T extends ZodTypeAny, TMode extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema$1<TMode extends 'input' ? input<T> : TMode extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
|
78
|
-
mode: TMode;
|
79
|
-
}): ReturnType<T['refine']>;
|
80
74
|
declare const oz: {
|
81
|
-
openapi: typeof openapi;
|
82
75
|
file: typeof file;
|
83
76
|
blob: typeof blob;
|
84
|
-
invalidDate: typeof invalidDate;
|
85
|
-
regexp: typeof regexp;
|
86
77
|
url: typeof url;
|
78
|
+
regexp: typeof regexp;
|
79
|
+
openapi: typeof customJsonSchema;
|
87
80
|
};
|
88
81
|
|
89
|
-
export { type
|
82
|
+
export { type CustomParams, type CustomZodDef, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
|
package/dist/index.d.ts
CHANGED
@@ -1,89 +1,82 @@
|
|
1
|
+
import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
2
|
+
import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
|
1
3
|
import { Context } from '@orpc/server';
|
2
|
-
import {
|
4
|
+
import { HandlerPlugin } from '@orpc/server/plugins';
|
3
5
|
import { StandardHandlerOptions } from '@orpc/server/standard';
|
4
|
-
import {
|
5
|
-
import { JSONSchema, SchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
6
|
-
import { StandardSchemaV1 } from '@standard-schema/spec';
|
7
|
-
import { JSONSchema as JSONSchema$1 } from 'json-schema-typed/draft-2020-12';
|
8
|
-
import { ZodTypeDef, CustomErrorParams, ZodType, ZodEffects, ZodTypeAny, input, output } from 'zod';
|
6
|
+
import { AnySchema } from '@orpc/contract';
|
9
7
|
|
10
|
-
declare
|
11
|
-
|
12
|
-
}
|
8
|
+
declare function getCustomJsonSchema(def: ZodTypeDef, options: {
|
9
|
+
strategy: 'input' | 'output' | 'both';
|
10
|
+
}): Exclude<JSONSchema, boolean> | undefined;
|
11
|
+
declare function customJsonSchema<T extends ZodTypeAny, TStrategy extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema<TStrategy extends 'input' ? input<T> : TStrategy extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
|
12
|
+
strategy?: TStrategy;
|
13
|
+
}): T;
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
not: {};
|
15
|
+
type CustomParams = CustomErrorParams & {
|
16
|
+
fatal?: boolean;
|
17
17
|
};
|
18
|
-
|
19
|
-
|
18
|
+
type CustomZodDef = {
|
19
|
+
type: 'blob' | 'regexp' | 'url';
|
20
|
+
} | {
|
21
|
+
type: 'file';
|
22
|
+
mimeType?: string;
|
23
|
+
};
|
24
|
+
declare function setCustomZodDef<T extends ZodTypeDef>(def: T, custom: CustomZodDef): void;
|
25
|
+
declare function getCustomZodDef(def: ZodTypeDef): CustomZodDef | undefined;
|
26
|
+
declare function composeParams<T = unknown>(defaultMessage: (input: T) => string, params: undefined | string | CustomParams | ((input: T) => CustomParams)): (input: T) => CustomParams;
|
27
|
+
|
28
|
+
declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Blob, ZodTypeDef, Blob>;
|
29
|
+
|
30
|
+
declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<File, ZodTypeDef, File> & {
|
31
|
+
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<File, ZodTypeDef, File>, File, File>;
|
20
32
|
};
|
33
|
+
|
34
|
+
declare function regexp(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<RegExp, ZodTypeDef, RegExp>;
|
35
|
+
|
36
|
+
declare function url(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<URL, ZodTypeDef, URL>;
|
37
|
+
|
38
|
+
declare class ZodSmartCoercionPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
39
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
40
|
+
}
|
41
|
+
|
21
42
|
interface ZodToJsonSchemaOptions {
|
22
43
|
/**
|
23
44
|
* Max depth of lazy type, if it exceeds.
|
24
45
|
*
|
25
46
|
* Used `{}` when reach max depth
|
26
47
|
*
|
27
|
-
* @default
|
48
|
+
* @default 3
|
28
49
|
*/
|
29
50
|
maxLazyDepth?: number;
|
30
51
|
/**
|
31
|
-
* The
|
52
|
+
* The schema to be used when the Zod schema is unsupported.
|
32
53
|
*
|
33
|
-
* @
|
54
|
+
* @default { not: {} }
|
34
55
|
*/
|
35
|
-
|
56
|
+
unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
|
36
57
|
/**
|
37
|
-
* The
|
58
|
+
* The schema to be used to represent the any | unknown type.
|
38
59
|
*
|
39
|
-
* @default
|
60
|
+
* @default { }
|
40
61
|
*/
|
41
|
-
|
42
|
-
/**
|
43
|
-
* Track if current level schema is handled custom json schema to prevent recursive
|
44
|
-
*
|
45
|
-
* @internal
|
46
|
-
*/
|
47
|
-
isHandledCustomJSONSchema?: boolean;
|
48
|
-
/**
|
49
|
-
* Track if current level schema is handled zod description to prevent recursive
|
50
|
-
*
|
51
|
-
* @internal
|
52
|
-
*/
|
53
|
-
isHandledZodDescription?: boolean;
|
62
|
+
anyJsonSchema?: Exclude<JSONSchema, boolean>;
|
54
63
|
}
|
55
|
-
declare
|
56
|
-
|
57
|
-
|
58
|
-
|
64
|
+
declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
65
|
+
#private;
|
66
|
+
private readonly maxLazyDepth;
|
67
|
+
private readonly unsupportedJsonSchema;
|
68
|
+
private readonly anyJsonSchema;
|
69
|
+
constructor(options?: ZodToJsonSchemaOptions);
|
70
|
+
condition(schema: AnySchema | undefined): boolean;
|
71
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
59
72
|
}
|
60
73
|
|
61
|
-
type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL';
|
62
|
-
type CustomParams = CustomErrorParams & {
|
63
|
-
fatal?: boolean;
|
64
|
-
};
|
65
|
-
declare function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined;
|
66
|
-
declare function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined;
|
67
|
-
declare function getCustomJSONSchema(def: ZodTypeDef, options?: {
|
68
|
-
mode?: 'input' | 'output';
|
69
|
-
}): Exclude<JSONSchema$1, boolean> | undefined;
|
70
|
-
declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
|
71
|
-
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>;
|
72
|
-
};
|
73
|
-
declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>;
|
74
|
-
declare function invalidDate(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Date, ZodTypeDef, Date>;
|
75
|
-
declare function regexp(options?: CustomParams): ZodType<RegExp, ZodTypeDef, RegExp>;
|
76
|
-
declare function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL>;
|
77
|
-
declare function openapi<T extends ZodTypeAny, TMode extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema$1<TMode extends 'input' ? input<T> : TMode extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
|
78
|
-
mode: TMode;
|
79
|
-
}): ReturnType<T['refine']>;
|
80
74
|
declare const oz: {
|
81
|
-
openapi: typeof openapi;
|
82
75
|
file: typeof file;
|
83
76
|
blob: typeof blob;
|
84
|
-
invalidDate: typeof invalidDate;
|
85
|
-
regexp: typeof regexp;
|
86
77
|
url: typeof url;
|
78
|
+
regexp: typeof regexp;
|
79
|
+
openapi: typeof customJsonSchema;
|
87
80
|
};
|
88
81
|
|
89
|
-
export { type
|
82
|
+
export { type CustomParams, type CustomZodDef, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
|