@orpc/zod 1.14.10 → 1.14.11

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/dist/index.d.ts CHANGED
@@ -1,91 +1,256 @@
1
- import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
2
- import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod/v3';
3
- import { Context } from '@orpc/server';
4
- import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
5
- import { AnySchema } from '@orpc/contract';
1
+ import { JsonSchemaConverter, AnySchema, JsonSchemaConverterDirection, JsonSchema } from '@orpc/json-schema';
2
+ import * as zod_v4_core from 'zod/v4/core';
3
+ import { ToJSONSchemaParams, $input, $output } from 'zod/v4/core';
4
+ import * as json_schema_typed from 'json-schema-typed';
6
5
 
7
- declare function getCustomJsonSchema(def: ZodTypeDef, options: {
8
- strategy: 'input' | 'output' | 'both';
9
- }): Exclude<JSONSchema, boolean> | undefined;
10
- 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?: {
11
- strategy?: TStrategy;
12
- }): T;
13
-
14
- type CustomParams = CustomErrorParams & {
15
- fatal?: boolean;
16
- };
17
- type CustomZodDef = {
18
- type: 'blob' | 'regexp' | 'url';
19
- } | {
20
- type: 'file';
21
- mimeType?: string;
22
- };
23
- declare function setCustomZodDef<T extends ZodTypeDef>(def: T, custom: CustomZodDef): void;
24
- declare function getCustomZodDef(def: ZodTypeDef): CustomZodDef | undefined;
25
- declare function composeParams<T = unknown>(defaultMessage: (input: T) => string, params: undefined | string | CustomParams | ((input: T) => CustomParams)): (input: T) => CustomParams;
26
-
27
- declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Blob, ZodTypeDef, Blob>;
28
-
29
- declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<File, ZodTypeDef, File> & {
30
- type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<File, ZodTypeDef, File>, File, File>;
31
- };
32
-
33
- declare function regexp(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<RegExp, ZodTypeDef, RegExp>;
34
-
35
- declare function url(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<URL, ZodTypeDef, URL>;
36
-
37
- declare class ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
38
- init(options: StandardHandlerOptions<TContext>): void;
39
- }
40
-
41
- interface ZodToJsonSchemaOptions {
42
- /**
43
- * Max depth of lazy type
44
- *
45
- * Used `{}` when exceed max depth
46
- *
47
- * @default 3
48
- */
49
- maxLazyDepth?: number;
50
- /**
51
- * Max depth of nested types
52
- *
53
- * Used anyJsonSchema (`{}`) when exceed max depth
54
- *
55
- * @default 10
56
- */
57
- maxStructureDepth?: number;
58
- /**
59
- * The schema to be used to represent the any | unknown type.
60
- *
61
- * @default { }
62
- */
63
- anyJsonSchema?: Exclude<JSONSchema, boolean>;
64
- /**
65
- * The schema to be used when the Zod schema is unsupported.
66
- *
67
- * @default { not: {} }
68
- */
69
- unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
6
+ interface ZodToJsonSchemaConverterOptions extends Omit<ToJSONSchemaParams, 'target' | 'io'> {
70
7
  }
71
- declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
72
- #private;
73
- private readonly maxLazyDepth;
74
- private readonly maxStructureDepth;
75
- private readonly unsupportedJsonSchema;
76
- private readonly anyJsonSchema;
77
- constructor(options?: ZodToJsonSchemaOptions);
78
- condition(schema: AnySchema | undefined): boolean;
79
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean, structureDepth?: number): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
8
+ declare class ZodToJsonSchemaConverter implements JsonSchemaConverter {
9
+ private readonly options;
10
+ constructor(options?: ZodToJsonSchemaConverterOptions);
11
+ condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
12
+ convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
13
+ private convertZod;
14
+ private getCustomJsonSchema;
80
15
  }
81
16
 
82
- declare const oz: {
83
- file: typeof file;
84
- blob: typeof blob;
85
- url: typeof url;
86
- regexp: typeof regexp;
87
- openapi: typeof customJsonSchema;
88
- };
17
+ /**
18
+ * Zod registry for customizing generated JSON schema, can use both for .input and .output
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { JSON_SCHEMA_REGISTRY } from '@orpc/zod'
23
+ *
24
+ * const user = z.object({
25
+ * name: z.string(),
26
+ * age: z.number(),
27
+ * })
28
+ *
29
+ * JSON_SCHEMA_REGISTRY.add(user, {
30
+ * examples: [{ name: 'John', age: 20 }],
31
+ * })
32
+ * ```
33
+ */
34
+ declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
35
+ $anchor?: string;
36
+ $comment?: string;
37
+ $defs?: Record<string, json_schema_typed.JSONSchema>;
38
+ $dynamicAnchor?: string;
39
+ $dynamicRef?: string;
40
+ $id?: string;
41
+ $ref?: string;
42
+ $schema?: string;
43
+ $vocabulary?: Record<string, string>;
44
+ additionalItems?: json_schema_typed.JSONSchema;
45
+ additionalProperties?: json_schema_typed.JSONSchema;
46
+ allOf?: (json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
47
+ anyOf?: (json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
48
+ const?: typeof $input | typeof $output | undefined;
49
+ contains?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
50
+ contentEncoding?: "7bit" | "8bit" | "base64" | "binary" | "ietf-token" | "quoted-printable" | "x-token";
51
+ contentMediaType?: string;
52
+ contentSchema?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
53
+ default?: typeof $input | typeof $output | undefined;
54
+ definitions?: Record<string, json_schema_typed.JSONSchema>;
55
+ dependencies?: Record<string, (string[] | readonly string[]) | json_schema_typed.JSONSchema>;
56
+ dependentRequired?: Record<string, string[] | readonly string[]>;
57
+ dependentSchemas?: Record<string, json_schema_typed.JSONSchema>;
58
+ deprecated?: boolean;
59
+ description?: string;
60
+ else?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
61
+ enum?: ((typeof $input | typeof $output)[] | readonly (typeof $input | typeof $output)[]) | undefined;
62
+ examples?: ((typeof $input | typeof $output)[] | readonly (typeof $input | typeof $output)[]) | undefined;
63
+ exclusiveMaximum?: number;
64
+ exclusiveMinimum?: number;
65
+ format?: string;
66
+ if?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
67
+ items?: json_schema_typed.JSONSchema;
68
+ maxContains?: number;
69
+ maximum?: number;
70
+ maxItems?: number;
71
+ maxLength?: number;
72
+ maxProperties?: number;
73
+ minContains?: number;
74
+ minimum?: number;
75
+ minItems?: number;
76
+ minLength?: number;
77
+ minProperties?: number;
78
+ multipleOf?: number;
79
+ not?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
80
+ oneOf?: (json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
81
+ pattern?: string;
82
+ patternProperties?: Record<string, json_schema_typed.JSONSchema>;
83
+ prefixItems?: (json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[]) | json_schema_typed.JSONSchema;
84
+ properties?: Record<string, json_schema_typed.JSONSchema>;
85
+ propertyNames?: json_schema_typed.JSONSchema;
86
+ readOnly?: boolean;
87
+ required?: string[] | readonly string[];
88
+ then?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
89
+ title?: string;
90
+ type?: json_schema_typed.JSONSchema.TypeValue | undefined;
91
+ unevaluatedItems?: json_schema_typed.JSONSchema;
92
+ unevaluatedProperties?: json_schema_typed.JSONSchema;
93
+ uniqueItems?: boolean;
94
+ writeOnly?: boolean;
95
+ }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
96
+ /**
97
+ * Zod registry for customizing generated JSON schema, only useful for .input
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * import { JSON_SCHEMA_INPUT_REGISTRY } from '@orpc/zod'
102
+ *
103
+ * const user = z.object({
104
+ * name: z.string(),
105
+ * age: z.string().transform(v => Number(v)),
106
+ * })
107
+ *
108
+ * JSON_SCHEMA_INPUT_REGISTRY.add(user, {
109
+ * examples: [{ name: 'John', age: "20" }],
110
+ * })
111
+ * ```
112
+ */
113
+ declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
114
+ $anchor?: string;
115
+ $comment?: string;
116
+ $defs?: Record<string, json_schema_typed.JSONSchema>;
117
+ $dynamicAnchor?: string;
118
+ $dynamicRef?: string;
119
+ $id?: string;
120
+ $ref?: string;
121
+ $schema?: string;
122
+ $vocabulary?: Record<string, string>;
123
+ additionalItems?: json_schema_typed.JSONSchema;
124
+ additionalProperties?: json_schema_typed.JSONSchema;
125
+ allOf?: (json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
126
+ anyOf?: (json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
127
+ const?: typeof $input | undefined;
128
+ contains?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
129
+ contentEncoding?: "7bit" | "8bit" | "base64" | "binary" | "ietf-token" | "quoted-printable" | "x-token";
130
+ contentMediaType?: string;
131
+ contentSchema?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
132
+ default?: typeof $input | undefined;
133
+ definitions?: Record<string, json_schema_typed.JSONSchema>;
134
+ dependencies?: Record<string, (string[] | readonly string[]) | json_schema_typed.JSONSchema>;
135
+ dependentRequired?: Record<string, string[] | readonly string[]>;
136
+ dependentSchemas?: Record<string, json_schema_typed.JSONSchema>;
137
+ deprecated?: boolean;
138
+ description?: string;
139
+ else?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
140
+ enum?: ((typeof $input)[] | readonly (typeof $input)[]) | undefined;
141
+ examples?: ((typeof $input)[] | readonly (typeof $input)[]) | undefined;
142
+ exclusiveMaximum?: number;
143
+ exclusiveMinimum?: number;
144
+ format?: string;
145
+ if?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
146
+ items?: json_schema_typed.JSONSchema;
147
+ maxContains?: number;
148
+ maximum?: number;
149
+ maxItems?: number;
150
+ maxLength?: number;
151
+ maxProperties?: number;
152
+ minContains?: number;
153
+ minimum?: number;
154
+ minItems?: number;
155
+ minLength?: number;
156
+ minProperties?: number;
157
+ multipleOf?: number;
158
+ not?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
159
+ oneOf?: (json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
160
+ pattern?: string;
161
+ patternProperties?: Record<string, json_schema_typed.JSONSchema>;
162
+ prefixItems?: (json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[]) | json_schema_typed.JSONSchema;
163
+ properties?: Record<string, json_schema_typed.JSONSchema>;
164
+ propertyNames?: json_schema_typed.JSONSchema;
165
+ readOnly?: boolean;
166
+ required?: string[] | readonly string[];
167
+ then?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
168
+ title?: string;
169
+ type?: json_schema_typed.JSONSchema.TypeValue | undefined;
170
+ unevaluatedItems?: json_schema_typed.JSONSchema;
171
+ unevaluatedProperties?: json_schema_typed.JSONSchema;
172
+ uniqueItems?: boolean;
173
+ writeOnly?: boolean;
174
+ }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
175
+ /**
176
+ * Zod registry for customizing generated JSON schema, only useful for .output
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * import { JSON_SCHEMA_OUTPUT_REGISTRY } from '@orpc/zod'
181
+ *
182
+ * const user = z.object({
183
+ * name: z.string(),
184
+ * age: z.string().transform(v => Number(v)),
185
+ * })
186
+ *
187
+ * JSON_SCHEMA_OUTPUT_REGISTRY.add(user, {
188
+ * examples: [{ name: 'John', age: 20 }],
189
+ * })
190
+ * ```
191
+ */
192
+ declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
193
+ $anchor?: string;
194
+ $comment?: string;
195
+ $defs?: Record<string, json_schema_typed.JSONSchema>;
196
+ $dynamicAnchor?: string;
197
+ $dynamicRef?: string;
198
+ $id?: string;
199
+ $ref?: string;
200
+ $schema?: string;
201
+ $vocabulary?: Record<string, string>;
202
+ additionalItems?: json_schema_typed.JSONSchema;
203
+ additionalProperties?: json_schema_typed.JSONSchema;
204
+ allOf?: (json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
205
+ anyOf?: (json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
206
+ const?: typeof $output | undefined;
207
+ contains?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
208
+ contentEncoding?: "7bit" | "8bit" | "base64" | "binary" | "ietf-token" | "quoted-printable" | "x-token";
209
+ contentMediaType?: string;
210
+ contentSchema?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
211
+ default?: typeof $output | undefined;
212
+ definitions?: Record<string, json_schema_typed.JSONSchema>;
213
+ dependencies?: Record<string, (string[] | readonly string[]) | json_schema_typed.JSONSchema>;
214
+ dependentRequired?: Record<string, string[] | readonly string[]>;
215
+ dependentSchemas?: Record<string, json_schema_typed.JSONSchema>;
216
+ deprecated?: boolean;
217
+ description?: string;
218
+ else?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
219
+ enum?: ((typeof $output)[] | readonly (typeof $output)[]) | undefined;
220
+ examples?: ((typeof $output)[] | readonly (typeof $output)[]) | undefined;
221
+ exclusiveMaximum?: number;
222
+ exclusiveMinimum?: number;
223
+ format?: string;
224
+ if?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
225
+ items?: json_schema_typed.JSONSchema;
226
+ maxContains?: number;
227
+ maximum?: number;
228
+ maxItems?: number;
229
+ maxLength?: number;
230
+ maxProperties?: number;
231
+ minContains?: number;
232
+ minimum?: number;
233
+ minItems?: number;
234
+ minLength?: number;
235
+ minProperties?: number;
236
+ multipleOf?: number;
237
+ not?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
238
+ oneOf?: (json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
239
+ pattern?: string;
240
+ patternProperties?: Record<string, json_schema_typed.JSONSchema>;
241
+ prefixItems?: (json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[]) | json_schema_typed.JSONSchema;
242
+ properties?: Record<string, json_schema_typed.JSONSchema>;
243
+ propertyNames?: json_schema_typed.JSONSchema;
244
+ readOnly?: boolean;
245
+ required?: string[] | readonly string[];
246
+ then?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
247
+ title?: string;
248
+ type?: json_schema_typed.JSONSchema.TypeValue | undefined;
249
+ unevaluatedItems?: json_schema_typed.JSONSchema;
250
+ unevaluatedProperties?: json_schema_typed.JSONSchema;
251
+ uniqueItems?: boolean;
252
+ writeOnly?: boolean;
253
+ }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
89
254
 
90
- export { ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
91
- export type { CustomParams, CustomZodDef, ZodToJsonSchemaOptions };
255
+ export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter };
256
+ export type { ZodToJsonSchemaConverterOptions };