@orpc/zod 0.43.0 → 0.44.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
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
3
  </div>
4
4
 
5
5
  <h1></h1>
@@ -0,0 +1,89 @@
1
+ import { Context } from '@orpc/server';
2
+ import { Plugin } from '@orpc/server/plugins';
3
+ import { StandardHandlerOptions } from '@orpc/server/standard';
4
+ import { Schema } from '@orpc/contract';
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';
9
+
10
+ declare class ZodSmartCoercionPlugin<TContext extends Context> implements Plugin<TContext> {
11
+ init(options: StandardHandlerOptions<TContext>): void;
12
+ }
13
+
14
+ declare const NON_LOGIC_KEYWORDS: ("default" | "$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly" | "contentEncoding" | "contentMediaType")[];
15
+ declare const UNSUPPORTED_JSON_SCHEMA: {
16
+ not: {};
17
+ };
18
+ declare const UNDEFINED_JSON_SCHEMA: {
19
+ const: string;
20
+ };
21
+ interface ZodToJsonSchemaOptions {
22
+ /**
23
+ * Max depth of lazy type, if it exceeds.
24
+ *
25
+ * Used `{}` when reach max depth
26
+ *
27
+ * @default 5
28
+ */
29
+ maxLazyDepth?: number;
30
+ /**
31
+ * The length used to track the depth of lazy type
32
+ *
33
+ * @internal
34
+ */
35
+ lazyDepth?: number;
36
+ /**
37
+ * The expected json schema for input or output zod schema
38
+ *
39
+ * @default input
40
+ */
41
+ mode?: 'input' | 'output';
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;
54
+ }
55
+ declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema.JSONSchema, boolean>;
56
+ declare class ZodToJsonSchemaConverter implements SchemaConverter {
57
+ condition(schema: Schema): boolean;
58
+ convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
59
+ }
60
+
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
+ declare const oz: {
81
+ openapi: typeof openapi;
82
+ file: typeof file;
83
+ blob: typeof blob;
84
+ invalidDate: typeof invalidDate;
85
+ regexp: typeof regexp;
86
+ url: typeof url;
87
+ };
88
+
89
+ export { type CustomZodType, NON_LOGIC_KEYWORDS, UNDEFINED_JSON_SCHEMA, UNSUPPORTED_JSON_SCHEMA, ZodSmartCoercionPlugin as ZodAutoCoercePlugin, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, file, getCustomJSONSchema, getCustomZodFileMimeType, getCustomZodType, invalidDate, openapi, oz, regexp, url, zodToJsonSchema };
@@ -0,0 +1,89 @@
1
+ import { Context } from '@orpc/server';
2
+ import { Plugin } from '@orpc/server/plugins';
3
+ import { StandardHandlerOptions } from '@orpc/server/standard';
4
+ import { Schema } from '@orpc/contract';
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';
9
+
10
+ declare class ZodSmartCoercionPlugin<TContext extends Context> implements Plugin<TContext> {
11
+ init(options: StandardHandlerOptions<TContext>): void;
12
+ }
13
+
14
+ declare const NON_LOGIC_KEYWORDS: ("default" | "$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly" | "contentEncoding" | "contentMediaType")[];
15
+ declare const UNSUPPORTED_JSON_SCHEMA: {
16
+ not: {};
17
+ };
18
+ declare const UNDEFINED_JSON_SCHEMA: {
19
+ const: string;
20
+ };
21
+ interface ZodToJsonSchemaOptions {
22
+ /**
23
+ * Max depth of lazy type, if it exceeds.
24
+ *
25
+ * Used `{}` when reach max depth
26
+ *
27
+ * @default 5
28
+ */
29
+ maxLazyDepth?: number;
30
+ /**
31
+ * The length used to track the depth of lazy type
32
+ *
33
+ * @internal
34
+ */
35
+ lazyDepth?: number;
36
+ /**
37
+ * The expected json schema for input or output zod schema
38
+ *
39
+ * @default input
40
+ */
41
+ mode?: 'input' | 'output';
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;
54
+ }
55
+ declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema.JSONSchema, boolean>;
56
+ declare class ZodToJsonSchemaConverter implements SchemaConverter {
57
+ condition(schema: Schema): boolean;
58
+ convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
59
+ }
60
+
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
+ declare const oz: {
81
+ openapi: typeof openapi;
82
+ file: typeof file;
83
+ blob: typeof blob;
84
+ invalidDate: typeof invalidDate;
85
+ regexp: typeof regexp;
86
+ url: typeof url;
87
+ };
88
+
89
+ export { type CustomZodType, NON_LOGIC_KEYWORDS, UNDEFINED_JSON_SCHEMA, UNSUPPORTED_JSON_SCHEMA, ZodSmartCoercionPlugin as ZodAutoCoercePlugin, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, file, getCustomJSONSchema, getCustomZodFileMimeType, getCustomZodType, invalidDate, openapi, oz, regexp, url, zodToJsonSchema };
@@ -1,48 +1,11 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
- // If the importer is in node compatibility mode or this is not an ESM
20
- // file that has been converted to a CommonJS file using a Babel-
21
- // compatible transform (i.e. "__esModule" has not been set), then set
22
- // "default" to the CommonJS "module.exports" for node compatibility.
23
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
- mod
25
- ));
26
-
27
- // ../../node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js
28
- var require_escape_string_regexp = __commonJS({
29
- "../../node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js"(exports, module) {
30
- "use strict";
31
- module.exports = (string) => {
32
- if (typeof string !== "string") {
33
- throw new TypeError("Expected a string");
34
- }
35
- return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
36
- };
37
- }
38
- });
1
+ import { guard, isObject } from '@orpc/shared';
2
+ import { getCustomZodType as getCustomZodType$1 } from '@orpc/zod';
3
+ import { ZodFirstPartyTypeKind, custom } from 'zod';
4
+ import { JSONSchemaFormat } from '@orpc/openapi';
5
+ import escapeStringRegexp from 'escape-string-regexp';
6
+ import wcmatch from 'wildcard-match';
39
7
 
40
- // src/coercer.ts
41
- import { guard, isObject } from "@orpc/shared";
42
- import {
43
- ZodFirstPartyTypeKind
44
- } from "zod";
45
- var ZodSmartCoercionPlugin = class {
8
+ class ZodSmartCoercionPlugin {
46
9
  init(options) {
47
10
  options.clientInterceptors ??= [];
48
11
  options.clientInterceptors.unshift((options2) => {
@@ -54,7 +17,7 @@ var ZodSmartCoercionPlugin = class {
54
17
  return options2.next({ ...options2, input: coercedInput });
55
18
  });
56
19
  }
57
- };
20
+ }
58
21
  function zodCoerceInternal(schema, value, options) {
59
22
  const isRoot = options?.isRoot ?? true;
60
23
  const options_ = { ...options, isRoot: false };
@@ -65,7 +28,7 @@ function zodCoerceInternal(schema, value, options) {
65
28
  }
66
29
  return zodCoerceInternal(schema, value, options_);
67
30
  }
68
- const customType = getCustomZodType(schema._def);
31
+ const customType = getCustomZodType$1(schema._def);
69
32
  if (customType === "Invalid Date") {
70
33
  if (typeof value === "string" && value.toLocaleLowerCase() === "invalid date") {
71
34
  return /* @__PURE__ */ new Date("Invalid Date");
@@ -80,9 +43,9 @@ function zodCoerceInternal(schema, value, options) {
80
43
  }
81
44
  } else if (customType === "URL") {
82
45
  if (typeof value === "string") {
83
- const url2 = guard(() => new URL(value));
84
- if (url2 !== void 0) {
85
- return url2;
46
+ const url = guard(() => new URL(value));
47
+ if (url !== void 0) {
48
+ return url;
86
49
  }
87
50
  }
88
51
  }
@@ -348,29 +311,15 @@ function zodCoerceInternal(schema, value, options) {
348
311
  }
349
312
  }
350
313
  }
351
- } else {
352
- const _expected = typeName;
353
- }
314
+ } else ;
354
315
  return value;
355
316
  }
356
317
 
357
- // src/converter.ts
358
- var import_escape_string_regexp = __toESM(require_escape_string_regexp(), 1);
359
- import { JSONSchemaFormat } from "@orpc/openapi";
360
- import {
361
- ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
362
- } from "zod";
363
-
364
- // src/schemas.ts
365
- import wcmatch from "wildcard-match";
366
- import {
367
- custom
368
- } from "zod";
369
- var customZodTypeSymbol = Symbol("customZodTypeSymbol");
370
- var customZodFileMimeTypeSymbol = Symbol("customZodFileMimeTypeSymbol");
371
- var CUSTOM_JSON_SCHEMA_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA");
372
- var CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_INPUT");
373
- var CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_OUTPUT");
318
+ const customZodTypeSymbol = Symbol("customZodTypeSymbol");
319
+ const customZodFileMimeTypeSymbol = Symbol("customZodFileMimeTypeSymbol");
320
+ const CUSTOM_JSON_SCHEMA_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA");
321
+ const CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_INPUT");
322
+ const CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_OUTPUT");
374
323
  function getCustomZodType(def) {
375
324
  return customZodTypeSymbol in def ? def[customZodTypeSymbol] : void 0;
376
325
  }
@@ -488,7 +437,7 @@ function openapi(schema, custom2, options) {
488
437
  });
489
438
  return newSchema;
490
439
  }
491
- var oz = {
440
+ const oz = {
492
441
  openapi,
493
442
  file,
494
443
  blob,
@@ -497,8 +446,7 @@ var oz = {
497
446
  url
498
447
  };
499
448
 
500
- // src/converter.ts
501
- var NON_LOGIC_KEYWORDS = [
449
+ const NON_LOGIC_KEYWORDS = [
502
450
  // Core Documentation Keywords
503
451
  "$anchor",
504
452
  "$comment",
@@ -525,8 +473,8 @@ var NON_LOGIC_KEYWORDS = [
525
473
  "$dynamicAnchor",
526
474
  "$dynamicRef"
527
475
  ];
528
- var UNSUPPORTED_JSON_SCHEMA = { not: {} };
529
- var UNDEFINED_JSON_SCHEMA = { const: "undefined" };
476
+ const UNSUPPORTED_JSON_SCHEMA = { not: {} };
477
+ const UNDEFINED_JSON_SCHEMA = { const: "undefined" };
530
478
  function zodToJsonSchema(schema, options) {
531
479
  if (schema["~standard"].vendor !== "zod") {
532
480
  console.warn(`Generate JSON schema not support ${schema["~standard"].vendor} yet`);
@@ -579,10 +527,9 @@ function zodToJsonSchema(schema, options) {
579
527
  return { type: "string", format: JSONSchemaFormat.URI };
580
528
  }
581
529
  }
582
- const _expectedCustomType = customType;
583
530
  const typeName = schema__._def.typeName;
584
531
  switch (typeName) {
585
- case ZodFirstPartyTypeKind2.ZodString: {
532
+ case ZodFirstPartyTypeKind.ZodString: {
586
533
  const schema_ = schema__;
587
534
  const json = { type: "string" };
588
535
  for (const check of schema_._def.checks) {
@@ -616,13 +563,13 @@ function zodToJsonSchema(schema, options) {
616
563
  json.maxLength = check.value;
617
564
  break;
618
565
  case "includes":
619
- json.pattern = (0, import_escape_string_regexp.default)(check.value);
566
+ json.pattern = escapeStringRegexp(check.value);
620
567
  break;
621
568
  case "startsWith":
622
- json.pattern = `^${(0, import_escape_string_regexp.default)(check.value)}`;
569
+ json.pattern = `^${escapeStringRegexp(check.value)}`;
623
570
  break;
624
571
  case "endsWith":
625
- json.pattern = `${(0, import_escape_string_regexp.default)(check.value)}$`;
572
+ json.pattern = `${escapeStringRegexp(check.value)}$`;
626
573
  break;
627
574
  case "emoji":
628
575
  json.pattern = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
@@ -658,13 +605,13 @@ function zodToJsonSchema(schema, options) {
658
605
  json.pattern = "^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$";
659
606
  break;
660
607
  default: {
661
- const _expect = check.kind;
608
+ check.kind;
662
609
  }
663
610
  }
664
611
  }
665
612
  return json;
666
613
  }
667
- case ZodFirstPartyTypeKind2.ZodNumber: {
614
+ case ZodFirstPartyTypeKind.ZodNumber: {
668
615
  const schema_ = schema__;
669
616
  const json = { type: "number" };
670
617
  for (const check of schema_._def.checks) {
@@ -682,50 +629,50 @@ function zodToJsonSchema(schema, options) {
682
629
  json.multipleOf = check.value;
683
630
  break;
684
631
  default: {
685
- const _expect = check.kind;
632
+ check.kind;
686
633
  }
687
634
  }
688
635
  }
689
636
  return json;
690
637
  }
691
- case ZodFirstPartyTypeKind2.ZodNaN: {
638
+ case ZodFirstPartyTypeKind.ZodNaN: {
692
639
  return { const: "NaN" };
693
640
  }
694
- case ZodFirstPartyTypeKind2.ZodBigInt: {
641
+ case ZodFirstPartyTypeKind.ZodBigInt: {
695
642
  const json = { type: "string", pattern: "^-?[0-9]+$" };
696
643
  return json;
697
644
  }
698
- case ZodFirstPartyTypeKind2.ZodBoolean: {
645
+ case ZodFirstPartyTypeKind.ZodBoolean: {
699
646
  return { type: "boolean" };
700
647
  }
701
- case ZodFirstPartyTypeKind2.ZodDate: {
648
+ case ZodFirstPartyTypeKind.ZodDate: {
702
649
  const schema2 = { type: "string", format: JSONSchemaFormat.Date };
703
650
  return schema2;
704
651
  }
705
- case ZodFirstPartyTypeKind2.ZodNull: {
652
+ case ZodFirstPartyTypeKind.ZodNull: {
706
653
  return { type: "null" };
707
654
  }
708
- case ZodFirstPartyTypeKind2.ZodVoid:
709
- case ZodFirstPartyTypeKind2.ZodUndefined: {
655
+ case ZodFirstPartyTypeKind.ZodVoid:
656
+ case ZodFirstPartyTypeKind.ZodUndefined: {
710
657
  return UNDEFINED_JSON_SCHEMA;
711
658
  }
712
- case ZodFirstPartyTypeKind2.ZodLiteral: {
659
+ case ZodFirstPartyTypeKind.ZodLiteral: {
713
660
  const schema_ = schema__;
714
661
  return { const: schema_._def.value };
715
662
  }
716
- case ZodFirstPartyTypeKind2.ZodEnum: {
663
+ case ZodFirstPartyTypeKind.ZodEnum: {
717
664
  const schema_ = schema__;
718
665
  return {
719
666
  enum: schema_._def.values
720
667
  };
721
668
  }
722
- case ZodFirstPartyTypeKind2.ZodNativeEnum: {
669
+ case ZodFirstPartyTypeKind.ZodNativeEnum: {
723
670
  const schema_ = schema__;
724
671
  return {
725
672
  enum: Object.values(schema_._def.values)
726
673
  };
727
674
  }
728
- case ZodFirstPartyTypeKind2.ZodArray: {
675
+ case ZodFirstPartyTypeKind.ZodArray: {
729
676
  const schema_ = schema__;
730
677
  const def = schema_._def;
731
678
  const json = { type: "array" };
@@ -742,7 +689,7 @@ function zodToJsonSchema(schema, options) {
742
689
  }
743
690
  return json;
744
691
  }
745
- case ZodFirstPartyTypeKind2.ZodTuple: {
692
+ case ZodFirstPartyTypeKind.ZodTuple: {
746
693
  const schema_ = schema__;
747
694
  const prefixItems = [];
748
695
  const json = { type: "array" };
@@ -760,7 +707,7 @@ function zodToJsonSchema(schema, options) {
760
707
  }
761
708
  return json;
762
709
  }
763
- case ZodFirstPartyTypeKind2.ZodObject: {
710
+ case ZodFirstPartyTypeKind.ZodObject: {
764
711
  const schema_ = schema__;
765
712
  const json = { type: "object" };
766
713
  const properties = {};
@@ -796,7 +743,7 @@ function zodToJsonSchema(schema, options) {
796
743
  }
797
744
  return json;
798
745
  }
799
- case ZodFirstPartyTypeKind2.ZodRecord: {
746
+ case ZodFirstPartyTypeKind.ZodRecord: {
800
747
  const schema_ = schema__;
801
748
  const json = { type: "object" };
802
749
  json.additionalProperties = zodToJsonSchema(
@@ -805,14 +752,14 @@ function zodToJsonSchema(schema, options) {
805
752
  );
806
753
  return json;
807
754
  }
808
- case ZodFirstPartyTypeKind2.ZodSet: {
755
+ case ZodFirstPartyTypeKind.ZodSet: {
809
756
  const schema_ = schema__;
810
757
  return {
811
758
  type: "array",
812
759
  items: zodToJsonSchema(schema_._def.valueType, childOptions)
813
760
  };
814
761
  }
815
- case ZodFirstPartyTypeKind2.ZodMap: {
762
+ case ZodFirstPartyTypeKind.ZodMap: {
816
763
  const schema_ = schema__;
817
764
  return {
818
765
  type: "array",
@@ -827,8 +774,8 @@ function zodToJsonSchema(schema, options) {
827
774
  }
828
775
  };
829
776
  }
830
- case ZodFirstPartyTypeKind2.ZodUnion:
831
- case ZodFirstPartyTypeKind2.ZodDiscriminatedUnion: {
777
+ case ZodFirstPartyTypeKind.ZodUnion:
778
+ case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
832
779
  const schema_ = schema__;
833
780
  const anyOf = [];
834
781
  for (const s of schema_._def.options) {
@@ -836,7 +783,7 @@ function zodToJsonSchema(schema, options) {
836
783
  }
837
784
  return { anyOf };
838
785
  }
839
- case ZodFirstPartyTypeKind2.ZodIntersection: {
786
+ case ZodFirstPartyTypeKind.ZodIntersection: {
840
787
  const schema_ = schema__;
841
788
  const allOf = [];
842
789
  for (const s of [schema_._def.left, schema_._def.right]) {
@@ -844,7 +791,7 @@ function zodToJsonSchema(schema, options) {
844
791
  }
845
792
  return { allOf };
846
793
  }
847
- case ZodFirstPartyTypeKind2.ZodLazy: {
794
+ case ZodFirstPartyTypeKind.ZodLazy: {
848
795
  const schema_ = schema__;
849
796
  const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
850
797
  const lazyDepth = childOptions?.lazyDepth ?? 0;
@@ -856,49 +803,49 @@ function zodToJsonSchema(schema, options) {
856
803
  lazyDepth: lazyDepth + 1
857
804
  });
858
805
  }
859
- case ZodFirstPartyTypeKind2.ZodUnknown:
860
- case ZodFirstPartyTypeKind2.ZodAny:
806
+ case ZodFirstPartyTypeKind.ZodUnknown:
807
+ case ZodFirstPartyTypeKind.ZodAny:
861
808
  case void 0: {
862
809
  return {};
863
810
  }
864
- case ZodFirstPartyTypeKind2.ZodOptional: {
811
+ case ZodFirstPartyTypeKind.ZodOptional: {
865
812
  const schema_ = schema__;
866
813
  const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
867
814
  return {
868
815
  anyOf: [UNDEFINED_JSON_SCHEMA, inner]
869
816
  };
870
817
  }
871
- case ZodFirstPartyTypeKind2.ZodReadonly: {
818
+ case ZodFirstPartyTypeKind.ZodReadonly: {
872
819
  const schema_ = schema__;
873
820
  return zodToJsonSchema(schema_._def.innerType, childOptions);
874
821
  }
875
- case ZodFirstPartyTypeKind2.ZodDefault: {
822
+ case ZodFirstPartyTypeKind.ZodDefault: {
876
823
  const schema_ = schema__;
877
824
  return zodToJsonSchema(schema_._def.innerType, childOptions);
878
825
  }
879
- case ZodFirstPartyTypeKind2.ZodEffects: {
826
+ case ZodFirstPartyTypeKind.ZodEffects: {
880
827
  const schema_ = schema__;
881
828
  if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
882
829
  return {};
883
830
  }
884
831
  return zodToJsonSchema(schema_._def.schema, childOptions);
885
832
  }
886
- case ZodFirstPartyTypeKind2.ZodCatch: {
833
+ case ZodFirstPartyTypeKind.ZodCatch: {
887
834
  const schema_ = schema__;
888
835
  return zodToJsonSchema(schema_._def.innerType, childOptions);
889
836
  }
890
- case ZodFirstPartyTypeKind2.ZodBranded: {
837
+ case ZodFirstPartyTypeKind.ZodBranded: {
891
838
  const schema_ = schema__;
892
839
  return zodToJsonSchema(schema_._def.type, childOptions);
893
840
  }
894
- case ZodFirstPartyTypeKind2.ZodPipeline: {
841
+ case ZodFirstPartyTypeKind.ZodPipeline: {
895
842
  const schema_ = schema__;
896
843
  return zodToJsonSchema(
897
844
  childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
898
845
  childOptions
899
846
  );
900
847
  }
901
- case ZodFirstPartyTypeKind2.ZodNullable: {
848
+ case ZodFirstPartyTypeKind.ZodNullable: {
902
849
  const schema_ = schema__;
903
850
  const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
904
851
  return {
@@ -906,7 +853,6 @@ function zodToJsonSchema(schema, options) {
906
853
  };
907
854
  }
908
855
  }
909
- const _expected = typeName;
910
856
  return UNSUPPORTED_JSON_SCHEMA;
911
857
  }
912
858
  function extractJSONSchema(schema, check, matches = []) {
@@ -949,7 +895,7 @@ function extractJSONSchema(schema, check, matches = []) {
949
895
  }
950
896
  return { schema, matches };
951
897
  }
952
- var ZodToJsonSchemaConverter = class {
898
+ class ZodToJsonSchemaConverter {
953
899
  condition(schema) {
954
900
  return Boolean(schema && schema["~standard"].vendor === "zod");
955
901
  }
@@ -957,24 +903,6 @@ var ZodToJsonSchemaConverter = class {
957
903
  const jsonSchema = schema;
958
904
  return zodToJsonSchema(jsonSchema, { mode: options.strategy });
959
905
  }
960
- };
961
- export {
962
- NON_LOGIC_KEYWORDS,
963
- UNDEFINED_JSON_SCHEMA,
964
- UNSUPPORTED_JSON_SCHEMA,
965
- ZodSmartCoercionPlugin as ZodAutoCoercePlugin,
966
- ZodSmartCoercionPlugin,
967
- ZodToJsonSchemaConverter,
968
- blob,
969
- file,
970
- getCustomJSONSchema,
971
- getCustomZodFileMimeType,
972
- getCustomZodType,
973
- invalidDate,
974
- openapi,
975
- oz,
976
- regexp,
977
- url,
978
- zodToJsonSchema
979
- };
980
- //# sourceMappingURL=index.js.map
906
+ }
907
+
908
+ export { NON_LOGIC_KEYWORDS, UNDEFINED_JSON_SCHEMA, UNSUPPORTED_JSON_SCHEMA, ZodSmartCoercionPlugin as ZodAutoCoercePlugin, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, blob, file, getCustomJSONSchema, getCustomZodFileMimeType, getCustomZodType, invalidDate, openapi, oz, regexp, url, zodToJsonSchema };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/zod",
3
3
  "type": "module",
4
- "version": "0.43.0",
4
+ "version": "0.44.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,33 +15,29 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
21
- },
22
- "./🔒/*": {
23
- "types": "./dist/src/*.d.ts"
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "default": "./dist/index.mjs"
24
21
  }
25
22
  },
26
23
  "files": [
27
- "!**/*.map",
28
- "!**/*.tsbuildinfo",
29
24
  "dist"
30
25
  ],
31
26
  "peerDependencies": {
32
- "@orpc/contract": "0.43.0",
33
- "@orpc/openapi": "0.43.0",
34
- "@orpc/server": "0.43.0"
27
+ "@orpc/contract": "0.44.0",
28
+ "@orpc/server": "0.44.0",
29
+ "@orpc/openapi": "0.44.0"
35
30
  },
36
31
  "dependencies": {
37
32
  "@standard-schema/spec": "^1.0.0",
33
+ "escape-string-regexp": "^5.0.0",
38
34
  "json-schema-typed": "^8.0.1",
39
35
  "wildcard-match": "^5.1.3",
40
36
  "zod": "^3.24.1",
41
- "@orpc/shared": "0.43.0"
37
+ "@orpc/shared": "0.44.0"
42
38
  },
43
39
  "scripts": {
44
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
40
+ "build": "unbuild",
45
41
  "build:watch": "pnpm run build --watch",
46
42
  "type:check": "tsc -b"
47
43
  }
@@ -1,12 +0,0 @@
1
- import type { Context } from '@orpc/server';
2
- import type { Plugin } from '@orpc/server/plugins';
3
- import type { StandardHandlerOptions } from '@orpc/server/standard';
4
- export declare class ZodSmartCoercionPlugin<TContext extends Context> implements Plugin<TContext> {
5
- init(options: StandardHandlerOptions<TContext>): void;
6
- }
7
- export {
8
- /**
9
- * @deprecated ZodAutoCoercePlugin has renamed to ZodSmartCoercionPlugin
10
- */
11
- ZodSmartCoercionPlugin as ZodAutoCoercePlugin, };
12
- //# sourceMappingURL=coercer.d.ts.map
@@ -1,50 +0,0 @@
1
- import type { Schema } from '@orpc/contract';
2
- import type { JSONSchema, SchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
3
- import type { StandardSchemaV1 } from '@standard-schema/spec';
4
- export declare const NON_LOGIC_KEYWORDS: ("$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "contentEncoding" | "contentMediaType" | "default" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly")[];
5
- export declare const UNSUPPORTED_JSON_SCHEMA: {
6
- not: {};
7
- };
8
- export declare const UNDEFINED_JSON_SCHEMA: {
9
- const: string;
10
- };
11
- export interface ZodToJsonSchemaOptions {
12
- /**
13
- * Max depth of lazy type, if it exceeds.
14
- *
15
- * Used `{}` when reach max depth
16
- *
17
- * @default 5
18
- */
19
- maxLazyDepth?: number;
20
- /**
21
- * The length used to track the depth of lazy type
22
- *
23
- * @internal
24
- */
25
- lazyDepth?: number;
26
- /**
27
- * The expected json schema for input or output zod schema
28
- *
29
- * @default input
30
- */
31
- mode?: 'input' | 'output';
32
- /**
33
- * Track if current level schema is handled custom json schema to prevent recursive
34
- *
35
- * @internal
36
- */
37
- isHandledCustomJSONSchema?: boolean;
38
- /**
39
- * Track if current level schema is handled zod description to prevent recursive
40
- *
41
- * @internal
42
- */
43
- isHandledZodDescription?: boolean;
44
- }
45
- export declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema.JSONSchema, boolean>;
46
- export declare class ZodToJsonSchemaConverter implements SchemaConverter {
47
- condition(schema: Schema): boolean;
48
- convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
49
- }
50
- //# sourceMappingURL=converter.d.ts.map
@@ -1,4 +0,0 @@
1
- export * from './coercer';
2
- export * from './converter';
3
- export * from './schemas';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1,31 +0,0 @@
1
- import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
2
- import { type CustomErrorParams, type input, type output, type ZodEffects, type ZodType, type ZodTypeAny, type ZodTypeDef } from 'zod';
3
- export type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL';
4
- type CustomParams = CustomErrorParams & {
5
- fatal?: boolean;
6
- };
7
- export declare function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined;
8
- export declare function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined;
9
- export declare function getCustomJSONSchema(def: ZodTypeDef, options?: {
10
- mode?: 'input' | 'output';
11
- }): Exclude<JSONSchema, boolean> | undefined;
12
- export declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
13
- type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>;
14
- };
15
- export declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>;
16
- export declare function invalidDate(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Date, ZodTypeDef, Date>;
17
- export declare function regexp(options?: CustomParams): ZodType<RegExp, ZodTypeDef, RegExp>;
18
- export declare function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL>;
19
- export declare function openapi<T extends ZodTypeAny, TMode extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema<TMode extends 'input' ? input<T> : TMode extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
20
- mode: TMode;
21
- }): ReturnType<T['refine']>;
22
- export declare const oz: {
23
- openapi: typeof openapi;
24
- file: typeof file;
25
- blob: typeof blob;
26
- invalidDate: typeof invalidDate;
27
- regexp: typeof regexp;
28
- url: typeof url;
29
- };
30
- export {};
31
- //# sourceMappingURL=schemas.d.ts.map