@orpc/zod 0.0.0-next.eae6003 → 0.0.0-next.eaf61c7
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 +4 -6
- package/dist/zod4/index.d.mts +6 -6
- package/dist/zod4/index.d.ts +6 -6
- package/dist/zod4/index.mjs +79 -85
- package/package.json +6 -6
package/README.md
CHANGED
@@ -49,14 +49,12 @@ 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/
|
52
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
53
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
53
54
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
54
|
-
- [@orpc/
|
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).
|
56
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
57
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
55
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
58
56
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
59
|
-
- [@orpc/
|
57
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
60
58
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
61
59
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
62
60
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
package/dist/zod4/index.d.mts
CHANGED
@@ -2,7 +2,7 @@ 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
|
5
|
+
import { Interceptor } from '@orpc/shared';
|
6
6
|
import * as zod_v4_core from 'zod/v4/core';
|
7
7
|
import { $ZodType, $input, $output } from 'zod/v4/core';
|
8
8
|
|
@@ -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
|
/**
|
@@ -138,7 +138,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
138
138
|
unevaluatedProperties?: JSONSchema;
|
139
139
|
uniqueItems?: boolean;
|
140
140
|
writeOnly?: boolean;
|
141
|
-
}, zod_v4_core.$ZodType<unknown, unknown
|
141
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
142
142
|
/**
|
143
143
|
* Zod registry for customizing generated JSON schema, only useful for .input
|
144
144
|
*
|
@@ -217,7 +217,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<
|
|
217
217
|
unevaluatedProperties?: JSONSchema;
|
218
218
|
uniqueItems?: boolean;
|
219
219
|
writeOnly?: boolean;
|
220
|
-
}, zod_v4_core.$ZodType<unknown, unknown
|
220
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
221
221
|
/**
|
222
222
|
* Zod registry for customizing generated JSON schema, only useful for .input
|
223
223
|
*
|
@@ -296,7 +296,7 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry
|
|
296
296
|
unevaluatedProperties?: JSONSchema;
|
297
297
|
uniqueItems?: boolean;
|
298
298
|
writeOnly?: boolean;
|
299
|
-
}, zod_v4_core.$ZodType<unknown, unknown
|
299
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<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,7 +2,7 @@ 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
|
5
|
+
import { Interceptor } from '@orpc/shared';
|
6
6
|
import * as zod_v4_core from 'zod/v4/core';
|
7
7
|
import { $ZodType, $input, $output } from 'zod/v4/core';
|
8
8
|
|
@@ -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
|
/**
|
@@ -138,7 +138,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
138
138
|
unevaluatedProperties?: JSONSchema;
|
139
139
|
uniqueItems?: boolean;
|
140
140
|
writeOnly?: boolean;
|
141
|
-
}, zod_v4_core.$ZodType<unknown, unknown
|
141
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
142
142
|
/**
|
143
143
|
* Zod registry for customizing generated JSON schema, only useful for .input
|
144
144
|
*
|
@@ -217,7 +217,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<
|
|
217
217
|
unevaluatedProperties?: JSONSchema;
|
218
218
|
uniqueItems?: boolean;
|
219
219
|
writeOnly?: boolean;
|
220
|
-
}, zod_v4_core.$ZodType<unknown, unknown
|
220
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
221
221
|
/**
|
222
222
|
* Zod registry for customizing generated JSON schema, only useful for .input
|
223
223
|
*
|
@@ -296,7 +296,7 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry
|
|
296
296
|
unevaluatedProperties?: JSONSchema;
|
297
297
|
uniqueItems?: boolean;
|
298
298
|
writeOnly?: boolean;
|
299
|
-
}, zod_v4_core.$ZodType<unknown, unknown
|
299
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<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
@@ -100,8 +100,7 @@ class experimental_ZodSmartCoercionPlugin {
|
|
100
100
|
}
|
101
101
|
return value;
|
102
102
|
}
|
103
|
-
case "object":
|
104
|
-
case "interface": {
|
103
|
+
case "object": {
|
105
104
|
const object = schema;
|
106
105
|
if (value === void 0) {
|
107
106
|
return {};
|
@@ -165,9 +164,21 @@ class experimental_ZodSmartCoercionPlugin {
|
|
165
164
|
return this.#coerce(union._zod.def.options[0], value);
|
166
165
|
}
|
167
166
|
if (isObject(value)) {
|
167
|
+
const discriminator = "discriminator" in union._zod.def && typeof union._zod.def.discriminator === "string" ? union._zod.def.discriminator : void 0;
|
168
168
|
for (const option of union._zod.def.options) {
|
169
|
-
if (option._zod.
|
170
|
-
|
169
|
+
if (!option._zod.propValues) {
|
170
|
+
continue;
|
171
|
+
}
|
172
|
+
if (discriminator !== void 0) {
|
173
|
+
if (option._zod.propValues[discriminator]?.has(value[discriminator])) {
|
174
|
+
return this.#coerce(option, value);
|
175
|
+
}
|
176
|
+
} else {
|
177
|
+
for (const key in option._zod.propValues) {
|
178
|
+
if (option._zod.propValues[key]?.has(value[key])) {
|
179
|
+
return this.#coerce(option, value);
|
180
|
+
}
|
181
|
+
}
|
171
182
|
}
|
172
183
|
}
|
173
184
|
}
|
@@ -255,30 +266,6 @@ class experimental_ZodSmartCoercionPlugin {
|
|
255
266
|
}
|
256
267
|
return value;
|
257
268
|
}
|
258
|
-
/**
|
259
|
-
* This function is inspired from Zod, because it's not exported
|
260
|
-
* https://github.com/colinhacks/zod/blob/v4/packages/core/src/schemas.ts#L1903C1-L1921C2
|
261
|
-
*/
|
262
|
-
#matchDiscriminators(input, discs) {
|
263
|
-
for (const [key, value] of discs) {
|
264
|
-
const data = input[key];
|
265
|
-
if (value.values.size && !value.values.has(data)) {
|
266
|
-
return false;
|
267
|
-
}
|
268
|
-
if (value.maps.length === 0) {
|
269
|
-
continue;
|
270
|
-
}
|
271
|
-
if (!isObject(data)) {
|
272
|
-
return false;
|
273
|
-
}
|
274
|
-
for (const m of value.maps) {
|
275
|
-
if (!this.#matchDiscriminators(data, m)) {
|
276
|
-
return false;
|
277
|
-
}
|
278
|
-
}
|
279
|
-
}
|
280
|
-
return true;
|
281
|
-
}
|
282
269
|
}
|
283
270
|
|
284
271
|
const experimental_JSON_SCHEMA_REGISTRY = registry();
|
@@ -308,11 +295,11 @@ class experimental_ZodToJsonSchemaConverter {
|
|
308
295
|
return intercept(
|
309
296
|
this.interceptors,
|
310
297
|
{ schema, options, lazyDepth, isHandledCustomJSONSchema },
|
311
|
-
|
298
|
+
({ schema: schema2, options: options2, lazyDepth: lazyDepth2, isHandledCustomJSONSchema: isHandledCustomJSONSchema2 }) => {
|
312
299
|
if (!isHandledCustomJSONSchema2) {
|
313
300
|
const customJSONSchema = this.#getCustomJsonSchema(schema2, options2);
|
314
301
|
if (customJSONSchema) {
|
315
|
-
const [required, json] =
|
302
|
+
const [required, json] = this.#convert(schema2, options2, lazyDepth2, true);
|
316
303
|
return [required, { ...json, ...customJSONSchema }];
|
317
304
|
}
|
318
305
|
}
|
@@ -320,21 +307,28 @@ class experimental_ZodToJsonSchemaConverter {
|
|
320
307
|
case "string": {
|
321
308
|
const string = schema2;
|
322
309
|
const json = { type: "string" };
|
323
|
-
const { minimum, maximum, format,
|
324
|
-
if (minimum
|
310
|
+
const { minimum, maximum, format, patterns, contentEncoding } = string._zod.bag;
|
311
|
+
if (typeof minimum === "number") {
|
325
312
|
json.minLength = minimum;
|
326
313
|
}
|
327
|
-
if (maximum
|
314
|
+
if (typeof maximum === "number") {
|
328
315
|
json.maxLength = maximum;
|
329
316
|
}
|
330
|
-
if (contentEncoding
|
317
|
+
if (typeof contentEncoding === "string") {
|
331
318
|
json.contentEncoding = this.#handleContentEncoding(contentEncoding);
|
332
319
|
}
|
333
|
-
if (format
|
320
|
+
if (typeof format === "string" && format !== "regex" && json.contentEncoding === void 0) {
|
334
321
|
json.format = this.#handleStringFormat(format);
|
335
322
|
}
|
336
|
-
if (
|
337
|
-
|
323
|
+
if (patterns instanceof Set && json.contentEncoding === void 0 && json.format === void 0) {
|
324
|
+
for (const pattern of patterns) {
|
325
|
+
if (json.pattern === void 0) {
|
326
|
+
json.pattern = pattern.source;
|
327
|
+
} else {
|
328
|
+
json.allOf ??= [];
|
329
|
+
json.allOf.push({ pattern: pattern.source });
|
330
|
+
}
|
331
|
+
}
|
338
332
|
}
|
339
333
|
if (format === "jwt" && json.contentEncoding === void 0 && json.format === void 0 && json.pattern === void 0) {
|
340
334
|
json.pattern = /^[\w-]+\.[\w-]+\.[\w-]+$/.source;
|
@@ -344,25 +338,23 @@ class experimental_ZodToJsonSchemaConverter {
|
|
344
338
|
case "number": {
|
345
339
|
const number = schema2;
|
346
340
|
const json = { type: "number" };
|
347
|
-
const { minimum, maximum, format, multipleOf,
|
348
|
-
if (format?.includes("int")) {
|
341
|
+
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = number._zod.bag;
|
342
|
+
if (typeof format === "string" && format?.includes("int")) {
|
349
343
|
json.type = "integer";
|
350
344
|
}
|
351
|
-
if (minimum
|
352
|
-
|
353
|
-
json.minimum = minimum;
|
354
|
-
} else {
|
355
|
-
json.exclusiveMinimum = minimum;
|
356
|
-
}
|
345
|
+
if (typeof minimum === "number") {
|
346
|
+
json.minimum = minimum;
|
357
347
|
}
|
358
|
-
if (maximum
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
}
|
348
|
+
if (typeof maximum === "number") {
|
349
|
+
json.maximum = maximum;
|
350
|
+
}
|
351
|
+
if (typeof exclusiveMinimum === "number") {
|
352
|
+
json.exclusiveMinimum = exclusiveMinimum;
|
364
353
|
}
|
365
|
-
if (
|
354
|
+
if (typeof exclusiveMaximum === "number") {
|
355
|
+
json.exclusiveMaximum = exclusiveMaximum;
|
356
|
+
}
|
357
|
+
if (typeof multipleOf === "number") {
|
366
358
|
json.multipleOf = multipleOf;
|
367
359
|
}
|
368
360
|
return [true, json];
|
@@ -395,21 +387,21 @@ class experimental_ZodToJsonSchemaConverter {
|
|
395
387
|
case "array": {
|
396
388
|
const array = schema2;
|
397
389
|
const json = { type: "array" };
|
398
|
-
const { minimum, maximum } = array._zod.
|
399
|
-
if (minimum
|
390
|
+
const { minimum, maximum } = array._zod.bag;
|
391
|
+
if (typeof minimum === "number") {
|
400
392
|
json.minItems = minimum;
|
401
393
|
}
|
402
|
-
if (maximum
|
394
|
+
if (typeof maximum === "number") {
|
403
395
|
json.maxItems = maximum;
|
404
396
|
}
|
405
|
-
json.items = this.#handleArrayItemJsonSchema(
|
397
|
+
json.items = this.#handleArrayItemJsonSchema(this.#convert(array._zod.def.element, options2, lazyDepth2), options2);
|
406
398
|
return [true, json];
|
407
399
|
}
|
408
400
|
case "object": {
|
409
401
|
const object = schema2;
|
410
402
|
const json = { type: "object" };
|
411
403
|
for (const [key, value] of Object.entries(object._zod.def.shape)) {
|
412
|
-
const [itemRequired, itemJson] =
|
404
|
+
const [itemRequired, itemJson] = this.#convert(value, options2, lazyDepth2);
|
413
405
|
json.properties ??= {};
|
414
406
|
json.properties[key] = itemJson;
|
415
407
|
if (itemRequired) {
|
@@ -421,7 +413,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
421
413
|
if (object._zod.def.catchall._zod.def.type === "never") {
|
422
414
|
json.additionalProperties = false;
|
423
415
|
} else {
|
424
|
-
const [_, addJson] =
|
416
|
+
const [_, addJson] = this.#convert(object._zod.def.catchall, options2, lazyDepth2);
|
425
417
|
json.additionalProperties = addJson;
|
426
418
|
}
|
427
419
|
}
|
@@ -432,7 +424,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
432
424
|
const anyOf = [];
|
433
425
|
let required = true;
|
434
426
|
for (const item of union._zod.def.options) {
|
435
|
-
const [itemRequired, itemJson] =
|
427
|
+
const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2);
|
436
428
|
if (!itemRequired) {
|
437
429
|
required = false;
|
438
430
|
}
|
@@ -453,7 +445,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
453
445
|
const json = { allOf: [] };
|
454
446
|
let required = false;
|
455
447
|
for (const item of [intersection._zod.def.left, intersection._zod.def.right]) {
|
456
|
-
const [itemRequired, itemJson] =
|
448
|
+
const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2);
|
457
449
|
json.allOf.push(itemJson);
|
458
450
|
if (itemRequired) {
|
459
451
|
required = true;
|
@@ -465,16 +457,16 @@ class experimental_ZodToJsonSchemaConverter {
|
|
465
457
|
const tuple = schema2;
|
466
458
|
const json = { type: "array", prefixItems: [] };
|
467
459
|
for (const item of tuple._zod.def.items) {
|
468
|
-
json.prefixItems.push(this.#handleArrayItemJsonSchema(
|
460
|
+
json.prefixItems.push(this.#handleArrayItemJsonSchema(this.#convert(item, options2, lazyDepth2), options2));
|
469
461
|
}
|
470
462
|
if (tuple._zod.def.rest) {
|
471
|
-
json.items = this.#handleArrayItemJsonSchema(
|
463
|
+
json.items = this.#handleArrayItemJsonSchema(this.#convert(tuple._zod.def.rest, options2, lazyDepth2), options2);
|
472
464
|
}
|
473
|
-
const { minimum, maximum } = tuple._zod.
|
474
|
-
if (minimum
|
465
|
+
const { minimum, maximum } = tuple._zod.bag;
|
466
|
+
if (typeof minimum === "number") {
|
475
467
|
json.minItems = minimum;
|
476
468
|
}
|
477
|
-
if (maximum
|
469
|
+
if (typeof maximum === "number") {
|
478
470
|
json.maxItems = maximum;
|
479
471
|
}
|
480
472
|
return [true, json];
|
@@ -482,8 +474,8 @@ class experimental_ZodToJsonSchemaConverter {
|
|
482
474
|
case "record": {
|
483
475
|
const record = schema2;
|
484
476
|
const json = { type: "object" };
|
485
|
-
json.propertyNames =
|
486
|
-
json.additionalProperties =
|
477
|
+
json.propertyNames = this.#convert(record._zod.def.keyType, options2, lazyDepth2)[1];
|
478
|
+
json.additionalProperties = this.#convert(record._zod.def.valueType, options2, lazyDepth2)[1];
|
487
479
|
return [true, json];
|
488
480
|
}
|
489
481
|
case "map": {
|
@@ -493,8 +485,8 @@ class experimental_ZodToJsonSchemaConverter {
|
|
493
485
|
items: {
|
494
486
|
type: "array",
|
495
487
|
prefixItems: [
|
496
|
-
this.#handleArrayItemJsonSchema(
|
497
|
-
this.#handleArrayItemJsonSchema(
|
488
|
+
this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.keyType, options2, lazyDepth2), options2),
|
489
|
+
this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.valueType, options2, lazyDepth2), options2)
|
498
490
|
],
|
499
491
|
maxItems: 2,
|
500
492
|
minItems: 2
|
@@ -506,7 +498,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
506
498
|
return [true, {
|
507
499
|
type: "array",
|
508
500
|
uniqueItems: true,
|
509
|
-
items: this.#handleArrayItemJsonSchema(
|
501
|
+
items: this.#handleArrayItemJsonSchema(this.#convert(set._zod.def.valueType, options2, lazyDepth2), options2)
|
510
502
|
}];
|
511
503
|
}
|
512
504
|
case "enum": {
|
@@ -530,12 +522,14 @@ class experimental_ZodToJsonSchemaConverter {
|
|
530
522
|
case "file": {
|
531
523
|
const file = schema2;
|
532
524
|
const oneOf = [];
|
533
|
-
const { mime } = file._zod.
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
525
|
+
const { mime } = file._zod.bag;
|
526
|
+
if (mime === void 0 || Array.isArray(mime) && mime.every((m) => typeof m === "string")) {
|
527
|
+
for (const type of mime ?? ["*/*"]) {
|
528
|
+
oneOf.push({
|
529
|
+
type: "string",
|
530
|
+
contentMediaType: type
|
531
|
+
});
|
532
|
+
}
|
539
533
|
}
|
540
534
|
return [true, oneOf.length === 1 ? oneOf[0] : { anyOf: oneOf }];
|
541
535
|
}
|
@@ -544,12 +538,12 @@ class experimental_ZodToJsonSchemaConverter {
|
|
544
538
|
}
|
545
539
|
case "nullable": {
|
546
540
|
const nullable = schema2;
|
547
|
-
const [required, json] =
|
541
|
+
const [required, json] = this.#convert(nullable._zod.def.innerType, options2, lazyDepth2);
|
548
542
|
return [required, { anyOf: [json, { type: "null" }] }];
|
549
543
|
}
|
550
544
|
case "nonoptional": {
|
551
545
|
const nonoptional = schema2;
|
552
|
-
const [, json] =
|
546
|
+
const [, json] = this.#convert(nonoptional._zod.def.innerType, options2, lazyDepth2);
|
553
547
|
return [true, json];
|
554
548
|
}
|
555
549
|
case "success": {
|
@@ -558,7 +552,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
558
552
|
case "default":
|
559
553
|
case "prefault": {
|
560
554
|
const default_ = schema2;
|
561
|
-
const [, json] =
|
555
|
+
const [, json] = this.#convert(default_._zod.def.innerType, options2, lazyDepth2);
|
562
556
|
return [false, {
|
563
557
|
...json,
|
564
558
|
default: default_._zod.def.defaultValue
|
@@ -566,18 +560,18 @@ class experimental_ZodToJsonSchemaConverter {
|
|
566
560
|
}
|
567
561
|
case "catch": {
|
568
562
|
const catch_ = schema2;
|
569
|
-
return
|
563
|
+
return this.#convert(catch_._zod.def.innerType, options2, lazyDepth2);
|
570
564
|
}
|
571
565
|
case "nan": {
|
572
566
|
return [true, options2.strategy === "input" ? this.unsupportedJsonSchema : { type: "null" }];
|
573
567
|
}
|
574
568
|
case "pipe": {
|
575
569
|
const pipe = schema2;
|
576
|
-
return
|
570
|
+
return this.#convert(options2.strategy === "input" ? pipe._zod.def.in : pipe._zod.def.out, options2, lazyDepth2);
|
577
571
|
}
|
578
572
|
case "readonly": {
|
579
573
|
const readonly_ = schema2;
|
580
|
-
const [required, json] =
|
574
|
+
const [required, json] = this.#convert(readonly_._zod.def.innerType, options2, lazyDepth2);
|
581
575
|
return [required, { ...json, readOnly: true }];
|
582
576
|
}
|
583
577
|
case "template_literal": {
|
@@ -589,7 +583,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
589
583
|
}
|
590
584
|
case "optional": {
|
591
585
|
const optional = schema2;
|
592
|
-
const [, json] =
|
586
|
+
const [, json] = this.#convert(optional._zod.def.innerType, options2, lazyDepth2);
|
593
587
|
return [false, json];
|
594
588
|
}
|
595
589
|
case "lazy": {
|
@@ -597,7 +591,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
597
591
|
if (lazyDepth2 >= this.maxLazyDepth) {
|
598
592
|
return [false, this.anyJsonSchema];
|
599
593
|
}
|
600
|
-
return
|
594
|
+
return this.#convert(lazy._zod.def.getter(), options2, lazyDepth2 + 1);
|
601
595
|
}
|
602
596
|
default: {
|
603
597
|
schema2._zod.def.type;
|
@@ -621,7 +615,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
621
615
|
if (global) {
|
622
616
|
return {
|
623
617
|
description: global.description,
|
624
|
-
examples: global.examples
|
618
|
+
examples: Array.isArray(global.examples) ? global.examples : void 0
|
625
619
|
};
|
626
620
|
}
|
627
621
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/zod",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.eaf61c7",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -30,17 +30,17 @@
|
|
30
30
|
],
|
31
31
|
"peerDependencies": {
|
32
32
|
"zod": ">=3.24.2",
|
33
|
-
"@orpc/contract": "0.0.0-next.
|
34
|
-
"@orpc/server": "0.0.0-next.
|
33
|
+
"@orpc/contract": "0.0.0-next.eaf61c7",
|
34
|
+
"@orpc/server": "0.0.0-next.eaf61c7"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
37
|
"escape-string-regexp": "^5.0.0",
|
38
38
|
"wildcard-match": "^5.1.3",
|
39
|
-
"@orpc/openapi": "0.0.0-next.
|
40
|
-
"@orpc/shared": "0.0.0-next.
|
39
|
+
"@orpc/openapi": "0.0.0-next.eaf61c7",
|
40
|
+
"@orpc/shared": "0.0.0-next.eaf61c7"
|
41
41
|
},
|
42
42
|
"devDependencies": {
|
43
|
-
"zod": "3.25.
|
43
|
+
"zod": "^3.25.57",
|
44
44
|
"zod-to-json-schema": "^3.24.5"
|
45
45
|
},
|
46
46
|
"scripts": {
|