@orpc/zod 1.6.6 → 1.7.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 CHANGED
@@ -72,7 +72,7 @@ More schemas that [Zod](https://zod.dev/) doesn't support yet, and provides `Zod
72
72
 
73
73
  ```ts
74
74
  import { oz } from '@orpc/zod'
75
- import { z } from 'zod'
75
+ import { z } from 'zod/v3'
76
76
 
77
77
  const Example = z.object({
78
78
  url: oz.url(),
@@ -86,7 +86,7 @@ const Example = z.object({
86
86
 
87
87
  ```ts
88
88
  import { OpenAPIGenerator } from '@orpc/openapi'
89
- import { ZodToJsonSchemaConverter } from '@orpc/zod'
89
+ import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
90
90
 
91
91
  const openAPIGenerator = new OpenAPIGenerator({
92
92
  schemaConverters: [new ZodToJsonSchemaConverter()],
@@ -111,7 +111,7 @@ const specFromRouter = await openAPIGenerator.generate(router, {
111
111
 
112
112
  ```ts
113
113
  import { oz } from '@orpc/zod'
114
- import { z } from 'zod'
114
+ import * as z from 'zod'
115
115
 
116
116
  const InputSchema = oz.openapi(
117
117
  z.object({
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
2
- import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
2
+ import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod/v3';
3
3
  import { Context } from '@orpc/server';
4
4
  import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
5
5
  import { AnySchema } from '@orpc/contract';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
2
- import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
2
+ import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod/v3';
3
3
  import { Context } from '@orpc/server';
4
4
  import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
5
5
  import { AnySchema } from '@orpc/contract';
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { custom, ZodFirstPartyTypeKind } from 'zod';
1
+ import { custom, ZodFirstPartyTypeKind } from 'zod/v3';
2
2
  import wcmatch from 'wildcard-match';
3
3
  import { isObject, guard, toArray } from '@orpc/shared';
4
+ import { JsonSchemaXNativeType } from '@orpc/json-schema';
4
5
  import { JSONSchemaFormat } from '@orpc/openapi';
5
6
  import escapeStringRegexp from 'escape-string-regexp';
6
7
 
@@ -563,7 +564,11 @@ class ZodToJsonSchemaConverter {
563
564
  return [true, json];
564
565
  }
565
566
  case ZodFirstPartyTypeKind.ZodBigInt: {
566
- const json = { type: "string", pattern: "^-?[0-9]+$" };
567
+ const json = {
568
+ "type": "string",
569
+ "pattern": "^-?[0-9]+$",
570
+ "x-native-type": JsonSchemaXNativeType.BigInt
571
+ };
567
572
  return [true, json];
568
573
  }
569
574
  case ZodFirstPartyTypeKind.ZodNaN: {
@@ -573,7 +578,11 @@ class ZodToJsonSchemaConverter {
573
578
  return [true, { type: "boolean" }];
574
579
  }
575
580
  case ZodFirstPartyTypeKind.ZodDate: {
576
- const schema2 = { type: "string", format: JSONSchemaFormat.DateTime };
581
+ const schema2 = {
582
+ "type": "string",
583
+ "format": JSONSchemaFormat.DateTime,
584
+ "x-native-type": JsonSchemaXNativeType.Date
585
+ };
577
586
  return [true, schema2];
578
587
  }
579
588
  case ZodFirstPartyTypeKind.ZodNull: {
@@ -681,7 +690,11 @@ class ZodToJsonSchemaConverter {
681
690
  }
682
691
  case ZodFirstPartyTypeKind.ZodSet: {
683
692
  const schema_ = schema;
684
- const json = { type: "array", uniqueItems: true };
693
+ const json = {
694
+ "type": "array",
695
+ "uniqueItems": true,
696
+ "x-native-type": JsonSchemaXNativeType.Set
697
+ };
685
698
  const [itemRequired, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
686
699
  json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
687
700
  return [true, json];
@@ -690,9 +703,9 @@ class ZodToJsonSchemaConverter {
690
703
  const schema_ = schema;
691
704
  const [keyRequired, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false, structureDepth + 1);
692
705
  const [valueRequired, valueJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
693
- return [true, {
694
- type: "array",
695
- items: {
706
+ const json = {
707
+ "type": "array",
708
+ "items": {
696
709
  type: "array",
697
710
  prefixItems: [
698
711
  this.#toArrayItemJsonSchema(keyRequired, keyJson, options.strategy),
@@ -700,8 +713,10 @@ class ZodToJsonSchemaConverter {
700
713
  ],
701
714
  maxItems: 2,
702
715
  minItems: 2
703
- }
704
- }];
716
+ },
717
+ "x-native-type": JsonSchemaXNativeType.Map
718
+ };
719
+ return [true, json];
705
720
  }
706
721
  case ZodFirstPartyTypeKind.ZodUnion:
707
722
  case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
@@ -808,12 +823,17 @@ class ZodToJsonSchemaConverter {
808
823
  }
809
824
  case "regexp": {
810
825
  return {
811
- type: "string",
812
- pattern: "^\\/(.*)\\/([a-z]*)$"
826
+ "type": "string",
827
+ "pattern": "^\\/(.*)\\/([a-z]*)$",
828
+ "x-native-type": JsonSchemaXNativeType.RegExp
813
829
  };
814
830
  }
815
831
  case "url": {
816
- return { type: "string", format: JSONSchemaFormat.URI };
832
+ return {
833
+ "type": "string",
834
+ "format": JSONSchemaFormat.URI,
835
+ "x-native-type": JsonSchemaXNativeType.Url
836
+ };
817
837
  }
818
838
  }
819
839
  }
@@ -6,12 +6,15 @@ 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
 
9
+ /**
10
+ * @deprecated Use [Smart Coercion Plugin](https://orpc.unnoq.com/docs/openapi/plugins/smart-coercion) instead.
11
+ */
9
12
  declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
10
13
  #private;
11
14
  init(options: StandardHandlerOptions<TContext>): void;
12
15
  }
13
16
 
14
- interface experimental_ZodToJsonSchemaOptions {
17
+ interface ZodToJsonSchemaConverterOptions {
15
18
  /**
16
19
  * Max depth of lazy type.
17
20
  *
@@ -56,7 +59,7 @@ interface experimental_ZodToJsonSchemaOptions {
56
59
  jsonSchema: Exclude<JSONSchema, boolean>
57
60
  ]>[];
58
61
  }
59
- declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
62
+ declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
60
63
  #private;
61
64
  private readonly maxLazyDepth;
62
65
  private readonly maxStructureDepth;
@@ -64,7 +67,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
64
67
  private readonly unsupportedJsonSchema;
65
68
  private readonly undefinedJsonSchema;
66
69
  private readonly interceptors;
67
- constructor(options?: experimental_ZodToJsonSchemaOptions);
70
+ constructor(options?: ZodToJsonSchemaConverterOptions);
68
71
  condition(schema: AnySchema | undefined): boolean;
69
72
  convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
70
73
  }
@@ -86,7 +89,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
86
89
  * })
87
90
  * ```
88
91
  */
89
- declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
92
+ declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
90
93
  $anchor?: string;
91
94
  $comment?: string;
92
95
  $defs?: Record<string, JSONSchema>;
@@ -165,7 +168,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
165
168
  * })
166
169
  * ```
167
170
  */
168
- declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
171
+ declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
169
172
  $anchor?: string;
170
173
  $comment?: string;
171
174
  $defs?: Record<string, JSONSchema>;
@@ -244,7 +247,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<
244
247
  * })
245
248
  * ```
246
249
  */
247
- declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
250
+ declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
248
251
  $anchor?: string;
249
252
  $comment?: string;
250
253
  $defs?: Record<string, JSONSchema>;
@@ -307,5 +310,5 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry
307
310
  writeOnly?: boolean;
308
311
  }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
309
312
 
310
- export { experimental_JSON_SCHEMA_INPUT_REGISTRY, experimental_JSON_SCHEMA_OUTPUT_REGISTRY, experimental_JSON_SCHEMA_REGISTRY, experimental_ZodSmartCoercionPlugin, experimental_ZodToJsonSchemaConverter };
311
- export type { experimental_ZodToJsonSchemaOptions };
313
+ export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter, experimental_ZodSmartCoercionPlugin };
314
+ export type { ZodToJsonSchemaConverterOptions };
@@ -6,12 +6,15 @@ 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
 
9
+ /**
10
+ * @deprecated Use [Smart Coercion Plugin](https://orpc.unnoq.com/docs/openapi/plugins/smart-coercion) instead.
11
+ */
9
12
  declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
10
13
  #private;
11
14
  init(options: StandardHandlerOptions<TContext>): void;
12
15
  }
13
16
 
14
- interface experimental_ZodToJsonSchemaOptions {
17
+ interface ZodToJsonSchemaConverterOptions {
15
18
  /**
16
19
  * Max depth of lazy type.
17
20
  *
@@ -56,7 +59,7 @@ interface experimental_ZodToJsonSchemaOptions {
56
59
  jsonSchema: Exclude<JSONSchema, boolean>
57
60
  ]>[];
58
61
  }
59
- declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
62
+ declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
60
63
  #private;
61
64
  private readonly maxLazyDepth;
62
65
  private readonly maxStructureDepth;
@@ -64,7 +67,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
64
67
  private readonly unsupportedJsonSchema;
65
68
  private readonly undefinedJsonSchema;
66
69
  private readonly interceptors;
67
- constructor(options?: experimental_ZodToJsonSchemaOptions);
70
+ constructor(options?: ZodToJsonSchemaConverterOptions);
68
71
  condition(schema: AnySchema | undefined): boolean;
69
72
  convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
70
73
  }
@@ -86,7 +89,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
86
89
  * })
87
90
  * ```
88
91
  */
89
- declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
92
+ declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
90
93
  $anchor?: string;
91
94
  $comment?: string;
92
95
  $defs?: Record<string, JSONSchema>;
@@ -165,7 +168,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
165
168
  * })
166
169
  * ```
167
170
  */
168
- declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
171
+ declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
169
172
  $anchor?: string;
170
173
  $comment?: string;
171
174
  $defs?: Record<string, JSONSchema>;
@@ -244,7 +247,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<
244
247
  * })
245
248
  * ```
246
249
  */
247
- declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
250
+ declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
248
251
  $anchor?: string;
249
252
  $comment?: string;
250
253
  $defs?: Record<string, JSONSchema>;
@@ -307,5 +310,5 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry
307
310
  writeOnly?: boolean;
308
311
  }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
309
312
 
310
- export { experimental_JSON_SCHEMA_INPUT_REGISTRY, experimental_JSON_SCHEMA_OUTPUT_REGISTRY, experimental_JSON_SCHEMA_REGISTRY, experimental_ZodSmartCoercionPlugin, experimental_ZodToJsonSchemaConverter };
311
- export type { experimental_ZodToJsonSchemaOptions };
313
+ export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter, experimental_ZodSmartCoercionPlugin };
314
+ export type { ZodToJsonSchemaConverterOptions };
@@ -1,4 +1,5 @@
1
1
  import { isObject, guard, intercept, toArray } from '@orpc/shared';
2
+ import { JsonSchemaXNativeType } from '@orpc/json-schema';
2
3
  import { JSONSchemaFormat, JSONSchemaContentEncoding } from '@orpc/openapi';
3
4
  import { registry, globalRegistry } from 'zod/v4/core';
4
5
 
@@ -268,11 +269,11 @@ class experimental_ZodSmartCoercionPlugin {
268
269
  }
269
270
  }
270
271
 
271
- const experimental_JSON_SCHEMA_REGISTRY = registry();
272
- const experimental_JSON_SCHEMA_INPUT_REGISTRY = registry();
273
- const experimental_JSON_SCHEMA_OUTPUT_REGISTRY = registry();
272
+ const JSON_SCHEMA_REGISTRY = registry();
273
+ const JSON_SCHEMA_INPUT_REGISTRY = registry();
274
+ const JSON_SCHEMA_OUTPUT_REGISTRY = registry();
274
275
 
275
- class experimental_ZodToJsonSchemaConverter {
276
+ class ZodToJsonSchemaConverter {
276
277
  maxLazyDepth;
277
278
  maxStructureDepth;
278
279
  anyJsonSchema;
@@ -376,10 +377,18 @@ class experimental_ZodToJsonSchemaConverter {
376
377
  return [true, { type: "boolean" }];
377
378
  }
378
379
  case "bigint": {
379
- return [true, { type: "string", pattern: "^-?[0-9]+$" }];
380
+ return [true, {
381
+ "type": "string",
382
+ "pattern": "^-?[0-9]+$",
383
+ "x-native-type": JsonSchemaXNativeType.BigInt
384
+ }];
380
385
  }
381
386
  case "date": {
382
- return [true, { type: "string", format: JSONSchemaFormat.DateTime }];
387
+ return [true, {
388
+ "type": "string",
389
+ "format": JSONSchemaFormat.DateTime,
390
+ "x-native-type": JsonSchemaXNativeType.Date
391
+ }];
383
392
  }
384
393
  case "null": {
385
394
  return [true, { type: "null" }];
@@ -494,8 +503,8 @@ class experimental_ZodToJsonSchemaConverter {
494
503
  case "map": {
495
504
  const map = schema2;
496
505
  return [true, {
497
- type: "array",
498
- items: {
506
+ "type": "array",
507
+ "items": {
499
508
  type: "array",
500
509
  prefixItems: [
501
510
  this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.keyType, options2, lazyDepth2, structureDepth + 1), options2),
@@ -503,15 +512,17 @@ class experimental_ZodToJsonSchemaConverter {
503
512
  ],
504
513
  maxItems: 2,
505
514
  minItems: 2
506
- }
515
+ },
516
+ "x-native-type": JsonSchemaXNativeType.Map
507
517
  }];
508
518
  }
509
519
  case "set": {
510
520
  const set = schema2;
511
521
  return [true, {
512
- type: "array",
513
- uniqueItems: true,
514
- items: this.#handleArrayItemJsonSchema(this.#convert(set._zod.def.valueType, options2, lazyDepth2, structureDepth + 1), options2)
522
+ "type": "array",
523
+ "uniqueItems": true,
524
+ "items": this.#handleArrayItemJsonSchema(this.#convert(set._zod.def.valueType, options2, lazyDepth2, structureDepth + 1), options2),
525
+ "x-native-type": JsonSchemaXNativeType.Set
515
526
  }];
516
527
  }
517
528
  case "enum": {
@@ -616,14 +627,14 @@ class experimental_ZodToJsonSchemaConverter {
616
627
  );
617
628
  }
618
629
  #getCustomJsonSchema(schema, options) {
619
- if (options.strategy === "input" && experimental_JSON_SCHEMA_INPUT_REGISTRY.has(schema)) {
620
- return experimental_JSON_SCHEMA_INPUT_REGISTRY.get(schema);
630
+ if (options.strategy === "input" && JSON_SCHEMA_INPUT_REGISTRY.has(schema)) {
631
+ return JSON_SCHEMA_INPUT_REGISTRY.get(schema);
621
632
  }
622
- if (options.strategy === "output" && experimental_JSON_SCHEMA_OUTPUT_REGISTRY.has(schema)) {
623
- return experimental_JSON_SCHEMA_OUTPUT_REGISTRY.get(schema);
633
+ if (options.strategy === "output" && JSON_SCHEMA_OUTPUT_REGISTRY.has(schema)) {
634
+ return JSON_SCHEMA_OUTPUT_REGISTRY.get(schema);
624
635
  }
625
- if (experimental_JSON_SCHEMA_REGISTRY.has(schema)) {
626
- return experimental_JSON_SCHEMA_REGISTRY.get(schema);
636
+ if (JSON_SCHEMA_REGISTRY.has(schema)) {
637
+ return JSON_SCHEMA_REGISTRY.get(schema);
627
638
  }
628
639
  const global = globalRegistry.get(schema);
629
640
  if (global) {
@@ -665,4 +676,4 @@ class experimental_ZodToJsonSchemaConverter {
665
676
  }
666
677
  }
667
678
 
668
- export { experimental_JSON_SCHEMA_INPUT_REGISTRY, experimental_JSON_SCHEMA_OUTPUT_REGISTRY, experimental_JSON_SCHEMA_REGISTRY, experimental_ZodSmartCoercionPlugin, experimental_ZodToJsonSchemaConverter };
679
+ export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter, experimental_ZodSmartCoercionPlugin };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/zod",
3
3
  "type": "module",
4
- "version": "1.6.6",
4
+ "version": "1.7.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,19 +29,19 @@
29
29
  "dist"
30
30
  ],
31
31
  "peerDependencies": {
32
- "zod": ">=3.24.2",
33
- "@orpc/contract": "1.6.6",
34
- "@orpc/server": "1.6.6"
32
+ "zod": ">=3.25.0",
33
+ "@orpc/contract": "1.7.0",
34
+ "@orpc/server": "1.7.0"
35
35
  },
36
36
  "dependencies": {
37
37
  "escape-string-regexp": "^5.0.0",
38
38
  "wildcard-match": "^5.1.3",
39
- "@orpc/openapi": "1.6.6",
40
- "@orpc/shared": "1.6.6"
39
+ "@orpc/json-schema": "1.7.0",
40
+ "@orpc/openapi": "1.7.0",
41
+ "@orpc/shared": "1.7.0"
41
42
  },
42
43
  "devDependencies": {
43
- "zod": "^3.25.74",
44
- "zod-to-json-schema": "^3.24.6"
44
+ "zod": "^4.0.5"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "unbuild",