@orpc/zod 1.2.0 → 1.3.0
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 +1 -0
- package/dist/zod4/index.d.mts +11 -11
- package/dist/zod4/index.d.ts +11 -11
- package/dist/zod4/index.mjs +68 -61
- package/package.json +7 -19
package/README.md
CHANGED
@@ -49,6 +49,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
49
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
50
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
51
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
52
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
|
52
53
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
53
54
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
54
55
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
package/dist/zod4/index.d.mts
CHANGED
@@ -2,9 +2,9 @@ import { Context } from '@orpc/server';
|
|
2
2
|
import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
3
3
|
import { AnySchema } from '@orpc/contract';
|
4
4
|
import { JSONSchema, SchemaConvertOptions, ConditionalSchemaConverter } from '@orpc/openapi';
|
5
|
-
import { Interceptor
|
6
|
-
import * as
|
7
|
-
import { $ZodType, $input, $output } from '
|
5
|
+
import { Interceptor } from '@orpc/shared';
|
6
|
+
import * as zod_v4_core from 'zod/v4/core';
|
7
|
+
import { $ZodType, $input, $output } from 'zod/v4/core';
|
8
8
|
|
9
9
|
declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
|
10
10
|
#private;
|
@@ -46,7 +46,7 @@ interface experimental_ZodToJsonSchemaOptions {
|
|
46
46
|
}, [
|
47
47
|
required: boolean,
|
48
48
|
jsonSchema: Exclude<JSONSchema, boolean>
|
49
|
-
]
|
49
|
+
]>[];
|
50
50
|
}
|
51
51
|
declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
52
52
|
#private;
|
@@ -57,7 +57,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
57
57
|
private readonly interceptors;
|
58
58
|
constructor(options?: experimental_ZodToJsonSchemaOptions);
|
59
59
|
condition(schema: AnySchema | undefined): boolean;
|
60
|
-
convert(schema: AnySchema | undefined, options: SchemaConvertOptions):
|
60
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
61
61
|
}
|
62
62
|
|
63
63
|
/**
|
@@ -77,7 +77,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
77
77
|
* })
|
78
78
|
* ```
|
79
79
|
*/
|
80
|
-
declare const experimental_JSON_SCHEMA_REGISTRY:
|
80
|
+
declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
81
81
|
$anchor?: string;
|
82
82
|
$comment?: string;
|
83
83
|
$defs?: Record<string, JSONSchema>;
|
@@ -138,7 +138,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: _zod_core.$ZodRegistry<{
|
|
138
138
|
unevaluatedProperties?: JSONSchema;
|
139
139
|
uniqueItems?: boolean;
|
140
140
|
writeOnly?: boolean;
|
141
|
-
},
|
141
|
+
}, zod_v4_core.$ZodType<unknown, unknown>>;
|
142
142
|
/**
|
143
143
|
* Zod registry for customizing generated JSON schema, only useful for .input
|
144
144
|
*
|
@@ -156,7 +156,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: _zod_core.$ZodRegistry<{
|
|
156
156
|
* })
|
157
157
|
* ```
|
158
158
|
*/
|
159
|
-
declare const experimental_JSON_SCHEMA_INPUT_REGISTRY:
|
159
|
+
declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
160
160
|
$anchor?: string;
|
161
161
|
$comment?: string;
|
162
162
|
$defs?: Record<string, JSONSchema>;
|
@@ -217,7 +217,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: _zod_core.$ZodRegistry<{
|
|
217
217
|
unevaluatedProperties?: JSONSchema;
|
218
218
|
uniqueItems?: boolean;
|
219
219
|
writeOnly?: boolean;
|
220
|
-
},
|
220
|
+
}, zod_v4_core.$ZodType<unknown, unknown>>;
|
221
221
|
/**
|
222
222
|
* Zod registry for customizing generated JSON schema, only useful for .input
|
223
223
|
*
|
@@ -235,7 +235,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: _zod_core.$ZodRegistry<{
|
|
235
235
|
* })
|
236
236
|
* ```
|
237
237
|
*/
|
238
|
-
declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY:
|
238
|
+
declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
239
239
|
$anchor?: string;
|
240
240
|
$comment?: string;
|
241
241
|
$defs?: Record<string, JSONSchema>;
|
@@ -296,7 +296,7 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: _zod_core.$ZodRegistry<{
|
|
296
296
|
unevaluatedProperties?: JSONSchema;
|
297
297
|
uniqueItems?: boolean;
|
298
298
|
writeOnly?: boolean;
|
299
|
-
},
|
299
|
+
}, zod_v4_core.$ZodType<unknown, unknown>>;
|
300
300
|
|
301
301
|
export { experimental_JSON_SCHEMA_INPUT_REGISTRY, experimental_JSON_SCHEMA_OUTPUT_REGISTRY, experimental_JSON_SCHEMA_REGISTRY, experimental_ZodSmartCoercionPlugin, experimental_ZodToJsonSchemaConverter };
|
302
302
|
export type { experimental_ZodToJsonSchemaOptions };
|
package/dist/zod4/index.d.ts
CHANGED
@@ -2,9 +2,9 @@ import { Context } from '@orpc/server';
|
|
2
2
|
import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
3
3
|
import { AnySchema } from '@orpc/contract';
|
4
4
|
import { JSONSchema, SchemaConvertOptions, ConditionalSchemaConverter } from '@orpc/openapi';
|
5
|
-
import { Interceptor
|
6
|
-
import * as
|
7
|
-
import { $ZodType, $input, $output } from '
|
5
|
+
import { Interceptor } from '@orpc/shared';
|
6
|
+
import * as zod_v4_core from 'zod/v4/core';
|
7
|
+
import { $ZodType, $input, $output } from 'zod/v4/core';
|
8
8
|
|
9
9
|
declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
|
10
10
|
#private;
|
@@ -46,7 +46,7 @@ interface experimental_ZodToJsonSchemaOptions {
|
|
46
46
|
}, [
|
47
47
|
required: boolean,
|
48
48
|
jsonSchema: Exclude<JSONSchema, boolean>
|
49
|
-
]
|
49
|
+
]>[];
|
50
50
|
}
|
51
51
|
declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
52
52
|
#private;
|
@@ -57,7 +57,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
57
57
|
private readonly interceptors;
|
58
58
|
constructor(options?: experimental_ZodToJsonSchemaOptions);
|
59
59
|
condition(schema: AnySchema | undefined): boolean;
|
60
|
-
convert(schema: AnySchema | undefined, options: SchemaConvertOptions):
|
60
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
61
61
|
}
|
62
62
|
|
63
63
|
/**
|
@@ -77,7 +77,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
77
77
|
* })
|
78
78
|
* ```
|
79
79
|
*/
|
80
|
-
declare const experimental_JSON_SCHEMA_REGISTRY:
|
80
|
+
declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
81
81
|
$anchor?: string;
|
82
82
|
$comment?: string;
|
83
83
|
$defs?: Record<string, JSONSchema>;
|
@@ -138,7 +138,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: _zod_core.$ZodRegistry<{
|
|
138
138
|
unevaluatedProperties?: JSONSchema;
|
139
139
|
uniqueItems?: boolean;
|
140
140
|
writeOnly?: boolean;
|
141
|
-
},
|
141
|
+
}, zod_v4_core.$ZodType<unknown, unknown>>;
|
142
142
|
/**
|
143
143
|
* Zod registry for customizing generated JSON schema, only useful for .input
|
144
144
|
*
|
@@ -156,7 +156,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: _zod_core.$ZodRegistry<{
|
|
156
156
|
* })
|
157
157
|
* ```
|
158
158
|
*/
|
159
|
-
declare const experimental_JSON_SCHEMA_INPUT_REGISTRY:
|
159
|
+
declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
160
160
|
$anchor?: string;
|
161
161
|
$comment?: string;
|
162
162
|
$defs?: Record<string, JSONSchema>;
|
@@ -217,7 +217,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: _zod_core.$ZodRegistry<{
|
|
217
217
|
unevaluatedProperties?: JSONSchema;
|
218
218
|
uniqueItems?: boolean;
|
219
219
|
writeOnly?: boolean;
|
220
|
-
},
|
220
|
+
}, zod_v4_core.$ZodType<unknown, unknown>>;
|
221
221
|
/**
|
222
222
|
* Zod registry for customizing generated JSON schema, only useful for .input
|
223
223
|
*
|
@@ -235,7 +235,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: _zod_core.$ZodRegistry<{
|
|
235
235
|
* })
|
236
236
|
* ```
|
237
237
|
*/
|
238
|
-
declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY:
|
238
|
+
declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
239
239
|
$anchor?: string;
|
240
240
|
$comment?: string;
|
241
241
|
$defs?: Record<string, JSONSchema>;
|
@@ -296,7 +296,7 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: _zod_core.$ZodRegistry<{
|
|
296
296
|
unevaluatedProperties?: JSONSchema;
|
297
297
|
uniqueItems?: boolean;
|
298
298
|
writeOnly?: boolean;
|
299
|
-
},
|
299
|
+
}, zod_v4_core.$ZodType<unknown, unknown>>;
|
300
300
|
|
301
301
|
export { experimental_JSON_SCHEMA_INPUT_REGISTRY, experimental_JSON_SCHEMA_OUTPUT_REGISTRY, experimental_JSON_SCHEMA_REGISTRY, experimental_ZodSmartCoercionPlugin, experimental_ZodToJsonSchemaConverter };
|
302
302
|
export type { experimental_ZodToJsonSchemaOptions };
|
package/dist/zod4/index.mjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { isObject, guard, intercept } from '@orpc/shared';
|
2
2
|
import { JSONSchemaFormat, JSONSchemaContentEncoding } from '@orpc/openapi';
|
3
|
-
import { registry, globalRegistry } from '
|
3
|
+
import { registry, globalRegistry } from 'zod/v4/core';
|
4
4
|
|
5
5
|
class experimental_ZodSmartCoercionPlugin {
|
6
6
|
init(options) {
|
@@ -207,10 +207,17 @@ class experimental_ZodSmartCoercionPlugin {
|
|
207
207
|
return this.#coerce(pipe._zod.def.in, value);
|
208
208
|
}
|
209
209
|
case "default":
|
210
|
-
case "
|
210
|
+
case "prefault": {
|
211
211
|
const default_ = schema;
|
212
|
+
if (value === void 0) {
|
213
|
+
return value;
|
214
|
+
}
|
212
215
|
return this.#coerce(default_._zod.def.innerType, value);
|
213
216
|
}
|
217
|
+
case "catch": {
|
218
|
+
const catch_ = schema;
|
219
|
+
return this.#coerce(catch_._zod.def.innerType, value);
|
220
|
+
}
|
214
221
|
case "lazy": {
|
215
222
|
const lazy = schema;
|
216
223
|
if (value !== void 0) {
|
@@ -301,11 +308,11 @@ class experimental_ZodToJsonSchemaConverter {
|
|
301
308
|
return intercept(
|
302
309
|
this.interceptors,
|
303
310
|
{ schema, options, lazyDepth, isHandledCustomJSONSchema },
|
304
|
-
|
311
|
+
({ schema: schema2, options: options2, lazyDepth: lazyDepth2, isHandledCustomJSONSchema: isHandledCustomJSONSchema2 }) => {
|
305
312
|
if (!isHandledCustomJSONSchema2) {
|
306
313
|
const customJSONSchema = this.#getCustomJsonSchema(schema2, options2);
|
307
314
|
if (customJSONSchema) {
|
308
|
-
const [required, json] =
|
315
|
+
const [required, json] = this.#convert(schema2, options2, lazyDepth2, true);
|
309
316
|
return [required, { ...json, ...customJSONSchema }];
|
310
317
|
}
|
311
318
|
}
|
@@ -313,20 +320,20 @@ class experimental_ZodToJsonSchemaConverter {
|
|
313
320
|
case "string": {
|
314
321
|
const string = schema2;
|
315
322
|
const json = { type: "string" };
|
316
|
-
const { minimum, maximum, format, pattern, contentEncoding } = string._zod.
|
317
|
-
if (minimum
|
323
|
+
const { minimum, maximum, format, pattern, contentEncoding } = string._zod.bag;
|
324
|
+
if (typeof minimum === "number") {
|
318
325
|
json.minLength = minimum;
|
319
326
|
}
|
320
|
-
if (maximum
|
327
|
+
if (typeof maximum === "number") {
|
321
328
|
json.maxLength = maximum;
|
322
329
|
}
|
323
|
-
if (contentEncoding
|
330
|
+
if (typeof contentEncoding === "string") {
|
324
331
|
json.contentEncoding = this.#handleContentEncoding(contentEncoding);
|
325
332
|
}
|
326
|
-
if (format
|
333
|
+
if (typeof format === "string" && format !== "regex" && json.contentEncoding === void 0) {
|
327
334
|
json.format = this.#handleStringFormat(format);
|
328
335
|
}
|
329
|
-
if (pattern
|
336
|
+
if (pattern instanceof RegExp && json.contentEncoding === void 0 && json.format === void 0) {
|
330
337
|
json.pattern = pattern.source;
|
331
338
|
}
|
332
339
|
if (format === "jwt" && json.contentEncoding === void 0 && json.format === void 0 && json.pattern === void 0) {
|
@@ -337,25 +344,23 @@ class experimental_ZodToJsonSchemaConverter {
|
|
337
344
|
case "number": {
|
338
345
|
const number = schema2;
|
339
346
|
const json = { type: "number" };
|
340
|
-
const { minimum, maximum, format, multipleOf,
|
341
|
-
if (format?.includes("int")) {
|
347
|
+
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = number._zod.bag;
|
348
|
+
if (typeof format === "string" && format?.includes("int")) {
|
342
349
|
json.type = "integer";
|
343
350
|
}
|
344
|
-
if (minimum
|
345
|
-
|
346
|
-
json.minimum = minimum;
|
347
|
-
} else {
|
348
|
-
json.exclusiveMinimum = minimum;
|
349
|
-
}
|
351
|
+
if (typeof minimum === "number") {
|
352
|
+
json.minimum = minimum;
|
350
353
|
}
|
351
|
-
if (maximum
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
}
|
354
|
+
if (typeof maximum === "number") {
|
355
|
+
json.maximum = maximum;
|
356
|
+
}
|
357
|
+
if (typeof exclusiveMinimum === "number") {
|
358
|
+
json.exclusiveMinimum = exclusiveMinimum;
|
357
359
|
}
|
358
|
-
if (
|
360
|
+
if (typeof exclusiveMaximum === "number") {
|
361
|
+
json.exclusiveMaximum = exclusiveMaximum;
|
362
|
+
}
|
363
|
+
if (typeof multipleOf === "number") {
|
359
364
|
json.multipleOf = multipleOf;
|
360
365
|
}
|
361
366
|
return [true, json];
|
@@ -388,21 +393,21 @@ class experimental_ZodToJsonSchemaConverter {
|
|
388
393
|
case "array": {
|
389
394
|
const array = schema2;
|
390
395
|
const json = { type: "array" };
|
391
|
-
const { minimum, maximum } = array._zod.
|
392
|
-
if (minimum
|
396
|
+
const { minimum, maximum } = array._zod.bag;
|
397
|
+
if (typeof minimum === "number") {
|
393
398
|
json.minItems = minimum;
|
394
399
|
}
|
395
|
-
if (maximum
|
400
|
+
if (typeof maximum === "number") {
|
396
401
|
json.maxItems = maximum;
|
397
402
|
}
|
398
|
-
json.items = this.#handleArrayItemJsonSchema(
|
403
|
+
json.items = this.#handleArrayItemJsonSchema(this.#convert(array._zod.def.element, options2, lazyDepth2), options2);
|
399
404
|
return [true, json];
|
400
405
|
}
|
401
406
|
case "object": {
|
402
407
|
const object = schema2;
|
403
408
|
const json = { type: "object" };
|
404
409
|
for (const [key, value] of Object.entries(object._zod.def.shape)) {
|
405
|
-
const [itemRequired, itemJson] =
|
410
|
+
const [itemRequired, itemJson] = this.#convert(value, options2, lazyDepth2);
|
406
411
|
json.properties ??= {};
|
407
412
|
json.properties[key] = itemJson;
|
408
413
|
if (itemRequired) {
|
@@ -414,7 +419,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
414
419
|
if (object._zod.def.catchall._zod.def.type === "never") {
|
415
420
|
json.additionalProperties = false;
|
416
421
|
} else {
|
417
|
-
const [_, addJson] =
|
422
|
+
const [_, addJson] = this.#convert(object._zod.def.catchall, options2, lazyDepth2);
|
418
423
|
json.additionalProperties = addJson;
|
419
424
|
}
|
420
425
|
}
|
@@ -425,7 +430,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
425
430
|
const anyOf = [];
|
426
431
|
let required = true;
|
427
432
|
for (const item of union._zod.def.options) {
|
428
|
-
const [itemRequired, itemJson] =
|
433
|
+
const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2);
|
429
434
|
if (!itemRequired) {
|
430
435
|
required = false;
|
431
436
|
}
|
@@ -446,7 +451,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
446
451
|
const json = { allOf: [] };
|
447
452
|
let required = false;
|
448
453
|
for (const item of [intersection._zod.def.left, intersection._zod.def.right]) {
|
449
|
-
const [itemRequired, itemJson] =
|
454
|
+
const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2);
|
450
455
|
json.allOf.push(itemJson);
|
451
456
|
if (itemRequired) {
|
452
457
|
required = true;
|
@@ -458,16 +463,16 @@ class experimental_ZodToJsonSchemaConverter {
|
|
458
463
|
const tuple = schema2;
|
459
464
|
const json = { type: "array", prefixItems: [] };
|
460
465
|
for (const item of tuple._zod.def.items) {
|
461
|
-
json.prefixItems.push(this.#handleArrayItemJsonSchema(
|
466
|
+
json.prefixItems.push(this.#handleArrayItemJsonSchema(this.#convert(item, options2, lazyDepth2), options2));
|
462
467
|
}
|
463
468
|
if (tuple._zod.def.rest) {
|
464
|
-
json.items = this.#handleArrayItemJsonSchema(
|
469
|
+
json.items = this.#handleArrayItemJsonSchema(this.#convert(tuple._zod.def.rest, options2, lazyDepth2), options2);
|
465
470
|
}
|
466
|
-
const { minimum, maximum } = tuple._zod.
|
467
|
-
if (minimum
|
471
|
+
const { minimum, maximum } = tuple._zod.bag;
|
472
|
+
if (typeof minimum === "number") {
|
468
473
|
json.minItems = minimum;
|
469
474
|
}
|
470
|
-
if (maximum
|
475
|
+
if (typeof maximum === "number") {
|
471
476
|
json.maxItems = maximum;
|
472
477
|
}
|
473
478
|
return [true, json];
|
@@ -475,8 +480,8 @@ class experimental_ZodToJsonSchemaConverter {
|
|
475
480
|
case "record": {
|
476
481
|
const record = schema2;
|
477
482
|
const json = { type: "object" };
|
478
|
-
json.propertyNames =
|
479
|
-
json.additionalProperties =
|
483
|
+
json.propertyNames = this.#convert(record._zod.def.keyType, options2, lazyDepth2)[1];
|
484
|
+
json.additionalProperties = this.#convert(record._zod.def.valueType, options2, lazyDepth2)[1];
|
480
485
|
return [true, json];
|
481
486
|
}
|
482
487
|
case "map": {
|
@@ -486,8 +491,8 @@ class experimental_ZodToJsonSchemaConverter {
|
|
486
491
|
items: {
|
487
492
|
type: "array",
|
488
493
|
prefixItems: [
|
489
|
-
this.#handleArrayItemJsonSchema(
|
490
|
-
this.#handleArrayItemJsonSchema(
|
494
|
+
this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.keyType, options2, lazyDepth2), options2),
|
495
|
+
this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.valueType, options2, lazyDepth2), options2)
|
491
496
|
],
|
492
497
|
maxItems: 2,
|
493
498
|
minItems: 2
|
@@ -499,7 +504,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
499
504
|
return [true, {
|
500
505
|
type: "array",
|
501
506
|
uniqueItems: true,
|
502
|
-
items: this.#handleArrayItemJsonSchema(
|
507
|
+
items: this.#handleArrayItemJsonSchema(this.#convert(set._zod.def.valueType, options2, lazyDepth2), options2)
|
503
508
|
}];
|
504
509
|
}
|
505
510
|
case "enum": {
|
@@ -523,12 +528,14 @@ class experimental_ZodToJsonSchemaConverter {
|
|
523
528
|
case "file": {
|
524
529
|
const file = schema2;
|
525
530
|
const oneOf = [];
|
526
|
-
const { mime } = file._zod.
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
531
|
+
const { mime } = file._zod.bag;
|
532
|
+
if (mime === void 0 || Array.isArray(mime) && mime.every((m) => typeof m === "string")) {
|
533
|
+
for (const type of mime ?? ["*/*"]) {
|
534
|
+
oneOf.push({
|
535
|
+
type: "string",
|
536
|
+
contentMediaType: type
|
537
|
+
});
|
538
|
+
}
|
532
539
|
}
|
533
540
|
return [true, oneOf.length === 1 ? oneOf[0] : { anyOf: oneOf }];
|
534
541
|
}
|
@@ -537,40 +544,40 @@ class experimental_ZodToJsonSchemaConverter {
|
|
537
544
|
}
|
538
545
|
case "nullable": {
|
539
546
|
const nullable = schema2;
|
540
|
-
const [required, json] =
|
547
|
+
const [required, json] = this.#convert(nullable._zod.def.innerType, options2, lazyDepth2);
|
541
548
|
return [required, { anyOf: [json, { type: "null" }] }];
|
542
549
|
}
|
543
550
|
case "nonoptional": {
|
544
551
|
const nonoptional = schema2;
|
545
|
-
const [, json] =
|
552
|
+
const [, json] = this.#convert(nonoptional._zod.def.innerType, options2, lazyDepth2);
|
546
553
|
return [true, json];
|
547
554
|
}
|
548
555
|
case "success": {
|
549
556
|
return [true, { type: "boolean" }];
|
550
557
|
}
|
551
|
-
case "default":
|
558
|
+
case "default":
|
559
|
+
case "prefault": {
|
552
560
|
const default_ = schema2;
|
553
|
-
const [, json] =
|
561
|
+
const [, json] = this.#convert(default_._zod.def.innerType, options2, lazyDepth2);
|
554
562
|
return [false, {
|
555
563
|
...json,
|
556
|
-
default: default_._zod.def.defaultValue
|
564
|
+
default: default_._zod.def.defaultValue
|
557
565
|
}];
|
558
566
|
}
|
559
567
|
case "catch": {
|
560
568
|
const catch_ = schema2;
|
561
|
-
|
562
|
-
return [false, json];
|
569
|
+
return this.#convert(catch_._zod.def.innerType, options2, lazyDepth2);
|
563
570
|
}
|
564
571
|
case "nan": {
|
565
572
|
return [true, options2.strategy === "input" ? this.unsupportedJsonSchema : { type: "null" }];
|
566
573
|
}
|
567
574
|
case "pipe": {
|
568
575
|
const pipe = schema2;
|
569
|
-
return
|
576
|
+
return this.#convert(options2.strategy === "input" ? pipe._zod.def.in : pipe._zod.def.out, options2, lazyDepth2);
|
570
577
|
}
|
571
578
|
case "readonly": {
|
572
579
|
const readonly_ = schema2;
|
573
|
-
const [required, json] =
|
580
|
+
const [required, json] = this.#convert(readonly_._zod.def.innerType, options2, lazyDepth2);
|
574
581
|
return [required, { ...json, readOnly: true }];
|
575
582
|
}
|
576
583
|
case "template_literal": {
|
@@ -582,7 +589,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
582
589
|
}
|
583
590
|
case "optional": {
|
584
591
|
const optional = schema2;
|
585
|
-
const [, json] =
|
592
|
+
const [, json] = this.#convert(optional._zod.def.innerType, options2, lazyDepth2);
|
586
593
|
return [false, json];
|
587
594
|
}
|
588
595
|
case "lazy": {
|
@@ -590,7 +597,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
590
597
|
if (lazyDepth2 >= this.maxLazyDepth) {
|
591
598
|
return [false, this.anyJsonSchema];
|
592
599
|
}
|
593
|
-
return
|
600
|
+
return this.#convert(lazy._zod.def.getter(), options2, lazyDepth2 + 1);
|
594
601
|
}
|
595
602
|
default: {
|
596
603
|
schema2._zod.def.type;
|
@@ -619,7 +626,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
619
626
|
}
|
620
627
|
}
|
621
628
|
#handleArrayItemJsonSchema([required, schema], options) {
|
622
|
-
if (required || options.strategy === "input") {
|
629
|
+
if (required || options.strategy === "input" || schema.default !== void 0) {
|
623
630
|
return schema;
|
624
631
|
}
|
625
632
|
if (schema === this.undefinedJsonSchema) {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/zod",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.
|
4
|
+
"version": "1.3.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -29,31 +29,19 @@
|
|
29
29
|
"dist"
|
30
30
|
],
|
31
31
|
"peerDependencies": {
|
32
|
-
"@zod/core": ">=0.11.4",
|
33
32
|
"zod": ">=3.24.2",
|
34
|
-
"@orpc/contract": "1.
|
35
|
-
"@orpc/server": "1.
|
36
|
-
},
|
37
|
-
"peerDependenciesMeta": {
|
38
|
-
"@zod/core": {
|
39
|
-
"optional": true
|
40
|
-
},
|
41
|
-
"zod": {
|
42
|
-
"optional": true
|
43
|
-
}
|
33
|
+
"@orpc/contract": "1.3.0",
|
34
|
+
"@orpc/server": "1.3.0"
|
44
35
|
},
|
45
36
|
"dependencies": {
|
46
37
|
"escape-string-regexp": "^5.0.0",
|
47
38
|
"wildcard-match": "^5.1.3",
|
48
|
-
"@orpc/openapi": "1.
|
49
|
-
"@orpc/shared": "1.
|
39
|
+
"@orpc/openapi": "1.3.0",
|
40
|
+
"@orpc/shared": "1.3.0"
|
50
41
|
},
|
51
42
|
"devDependencies": {
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"zod": "^3.24.2",
|
55
|
-
"zod-to-json-schema": "^3.24.5",
|
56
|
-
"zod4": "npm:zod@^4.0.0-beta.20250505T012514"
|
43
|
+
"zod": "^3.25.11",
|
44
|
+
"zod-to-json-schema": "^3.24.5"
|
57
45
|
},
|
58
46
|
"scripts": {
|
59
47
|
"build": "unbuild",
|