zod-compare 1.0.0 → 2.0.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.
Files changed (71) hide show
  1. package/README.md +28 -7
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +45 -162
  5. package/dist/index.js +20 -251
  6. package/dist/index.js.map +1 -1
  7. package/dist/is-compatible-type-BA3YzVJ3.cjs +2 -0
  8. package/dist/is-compatible-type-BA3YzVJ3.cjs.map +1 -0
  9. package/dist/is-compatible-type-CA7-IozU.js +2985 -0
  10. package/dist/is-compatible-type-CA7-IozU.js.map +1 -0
  11. package/dist/is-compatible-type-CN9ljc9s.cjs +2 -0
  12. package/dist/is-compatible-type-CN9ljc9s.cjs.map +1 -0
  13. package/dist/is-compatible-type-DEERQsQI.js +431 -0
  14. package/dist/is-compatible-type-DEERQsQI.js.map +1 -0
  15. package/dist/utils.d.ts +9 -0
  16. package/dist/zod3/create-compare-fn.d.ts +7 -0
  17. package/dist/zod3/index.d.ts +5 -0
  18. package/dist/zod3/is-compatible-type.d.ts +46 -0
  19. package/dist/zod3/is-same-type.d.ts +95 -0
  20. package/dist/zod3/rules.d.ts +5 -0
  21. package/dist/zod3/types.d.ts +13 -0
  22. package/dist/zod3/utils.d.ts +7 -0
  23. package/dist/zod3.cjs +2 -0
  24. package/dist/zod3.cjs.map +1 -0
  25. package/dist/zod3.js +15 -0
  26. package/dist/zod3.js.map +1 -0
  27. package/dist/zod4/compat.d.ts +17 -0
  28. package/dist/zod4/create-compare-fn.d.ts +4 -0
  29. package/dist/zod4/index.d.ts +6 -0
  30. package/dist/zod4/is-compatible-type.d.ts +22 -0
  31. package/dist/zod4/is-same-type.d.ts +25 -0
  32. package/dist/zod4/rules.d.ts +5 -0
  33. package/dist/zod4/types.d.ts +13 -0
  34. package/dist/zod4/utils.d.ts +9 -0
  35. package/dist/zod4.cjs +2 -0
  36. package/dist/zod4.cjs.map +1 -0
  37. package/dist/zod4.js +15 -0
  38. package/dist/zod4.js.map +1 -0
  39. package/package.json +29 -16
  40. package/src/__tests__/__snapshots__/is-compatible-type.diff +4 -0
  41. package/src/__tests__/__snapshots__/is-same-type.diff +4 -0
  42. package/src/__tests__/diff.test.ts +27 -0
  43. package/src/index.ts +79 -8
  44. package/src/utils.ts +36 -30
  45. package/src/zod3/__tests__/__snapshots__/context.test.ts.snap +142 -0
  46. package/src/zod3/__tests__/context.test.ts +56 -0
  47. package/src/{__tests__ → zod3/__tests__}/is-compatible-type.test.ts +1 -1
  48. package/src/{__tests__ → zod3/__tests__}/is-same-type.test.ts +1 -97
  49. package/src/zod3/__tests__/specific.test.ts +39 -0
  50. package/src/{create-compare-fn.ts → zod3/create-compare-fn.ts} +2 -1
  51. package/src/zod3/index.ts +8 -0
  52. package/src/{is-compatible-type.ts → zod3/is-compatible-type.ts} +1 -1
  53. package/src/{is-same-type.ts → zod3/is-same-type.ts} +1 -1
  54. package/src/{types.ts → zod3/types.ts} +1 -1
  55. package/src/zod3/utils.ts +35 -0
  56. package/src/zod4/__tests__/__snapshots__/context.test.ts.snap +166 -0
  57. package/src/zod4/__tests__/__snapshots__/shape.test.ts.snap +1479 -0
  58. package/src/zod4/__tests__/context.test.ts +53 -0
  59. package/src/zod4/__tests__/is-compatible-type.test.ts +143 -0
  60. package/src/zod4/__tests__/is-same-type.test.ts +193 -0
  61. package/src/zod4/__tests__/shape.test.ts +104 -0
  62. package/src/zod4/__tests__/specific.test.ts +80 -0
  63. package/src/zod4/compat.ts +46 -0
  64. package/src/zod4/create-compare-fn.ts +51 -0
  65. package/src/zod4/index.ts +9 -0
  66. package/src/zod4/is-compatible-type.ts +157 -0
  67. package/src/zod4/is-same-type.ts +442 -0
  68. package/src/zod4/rules.ts +6 -0
  69. package/src/zod4/types.ts +22 -0
  70. package/src/zod4/utils.ts +204 -0
  71. /package/src/{rules.ts → zod3/rules.ts} +0 -0
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Compare two [Zod](https://zod.dev/) schemas recursively.
7
7
 
8
- `zod-compare` provides functions to compare Zod schemas, allowing you to determine whether two schemas are the same or compatible.
8
+ `zod-compare` provides functions to compare Zod schemas, allowing you to determine whether two schemas are the same or compatible. Supports both Zod v3 and Zod v4.
9
9
 
10
10
  ## Installation
11
11
 
@@ -41,6 +41,26 @@ isCompatibleType(
41
41
  // true
42
42
  ```
43
43
 
44
+ Use the top-level helpers to compare schemas:
45
+
46
+ - `isSameType(a, b)`: true only if the two schemas have the same shape and types (ignores refinements like min/max/length, transforms, etc.)
47
+ - `isCompatibleType(higherType, lowerType)`: true if the looser schema (higherType) can be accepted wherever the stricter schema (lowerType) is expected
48
+
49
+ ### Versions and entry points
50
+
51
+ The top-level APIs accept inputs from Zod v3 or v4 and automatically route to the right comparison engine when both inputs are from the same major. If inputs are mixed (v3 vs v4), both functions throw.
52
+
53
+ If you’re on Zod v4, import from the v4 entry for the best types/inference:
54
+
55
+ ```ts
56
+ import { isSameType } from "zod-compare/zod4";
57
+ import { z } from "zod/v4";
58
+
59
+ isSameType(z.string(), z.string()); // true
60
+ ```
61
+
62
+ If you use Zod v3 exclusively, import from `zod-compare/zod3`.
63
+
44
64
  ## Advanced Usage
45
65
 
46
66
  ### Custom Rules
@@ -104,7 +124,7 @@ Compares two Zod schemas and returns `true` if they are the same.
104
124
  ```ts
105
125
  import { isSameType } from "zod-compare";
106
126
 
107
- type isSameType: (a: ZodType, b: ZodType, context?: CompareContext) => boolean;
127
+ type isSameType: (a: $ZodType, b: $ZodType, context?: CompareContext) => boolean;
108
128
  ```
109
129
 
110
130
  ### `createCompareFn`
@@ -137,7 +157,7 @@ Compares two Zod schemas and returns `true` if they are compatible.
137
157
  import { isCompatibleType } from "zod-compare";
138
158
  // The `higherType` should be a looser type
139
159
  // The `lowerType` should be a stricter type
140
- type isCompatibleType: (higherType: ZodType, lowerType: ZodType) => boolean;
160
+ type isCompatibleType: (higherType: $ZodType, lowerType: $ZodType) => boolean;
141
161
  ```
142
162
 
143
163
  ### Preset Rules
@@ -160,15 +180,16 @@ const yourIsSameType = createCompareFn([customRule, ...isSameTypePresetRules]);
160
180
  type CompareContext = {
161
181
  stacks?: {
162
182
  name: string;
163
- target: [a: ZodType, b: ZodType];
183
+ target: [a: $ZodTypes, b: $ZodTypes];
184
+ result: boolean;
164
185
  }[];
165
186
  } & Record<string, unknown>;
166
187
 
167
188
  type CompareFn = (
168
- a: ZodType,
169
- b: ZodType,
189
+ a: $ZodTypes,
190
+ b: $ZodTypes,
170
191
  next: () => boolean,
171
- recheck: (a: ZodType, b: ZodType) => boolean,
192
+ recheck: (a: $ZodType, b: $ZodType) => boolean,
172
193
  context: CompareContext,
173
194
  ) => boolean;
174
195
 
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("zod"),m=e=>{const n=(t,o,a={})=>{let i=-1;const s=f=>{if(f===e.length)throw new Error("Failed to compare type! "+t+" "+o);if(f===i)throw new Error("next() called multiple times");i=f;const u=e[f],d=u.compare(t,o,()=>s(f+1),(y,_)=>n(y,_,a),a);return"stacks"in a&&Array.isArray(a.stacks)&&a.stacks.push({name:u.name,target:[t,o],result:d}),d};return s(0)};return n},h=m,p=e=>e instanceof r.z.ZodString||e instanceof r.z.ZodNumber||e instanceof r.z.ZodNaN||e instanceof r.z.ZodBigInt||e instanceof r.z.ZodBoolean||e instanceof r.z.ZodDate||e instanceof r.z.ZodSymbol||e instanceof r.z.ZodUndefined||e instanceof r.z.ZodNull||e instanceof r.z.ZodAny||e instanceof r.z.ZodUnknown||e instanceof r.z.ZodNever||e instanceof r.z.ZodVoid,c=e=>e.options.flatMap(n=>n instanceof r.z.ZodUnion?c(n):n),l=[{name:"undefined check",compare:(e,n,t)=>{if(e===void 0||n===void 0)throw new Error("Failed to compare type! "+e+" "+n);return t()}},{name:"compare reference",compare:(e,n,t)=>e===n?!0:t()},{name:"compare constructor",compare:(e,n,t)=>e.constructor!==n.constructor?!1:t()},{name:"compare typeName",compare:(e,n,t)=>{if(!("typeName"in e._def)||!("typeName"in n._def))throw new Error("Failed to compare type! "+e._def+" "+n._def);return e._def.typeName!==n._def.typeName?!1:t()}},{name:"compare ZodBranded",compare:(e,n,t)=>e instanceof r.z.ZodBranded||n instanceof r.z.ZodBranded?!1:t()},{name:"unwrap ZodType",compare:(e,n,t,o)=>"unwrap"in e&&typeof e.unwrap=="function"?"unwrap"in n&&typeof n.unwrap=="function"?o(e.unwrap(),n.unwrap()):!1:t()},{name:"is same primitive",compare:(e,n,t)=>p(e)&&p(n)&&e.constructor===n.constructor?!0:t()},{name:"compare ZodObject",compare:(e,n,t,o)=>{if(e instanceof r.z.ZodObject&&n instanceof r.z.ZodObject){const a=e.shape,i=n.shape;if(Object.keys(a).length!==Object.keys(i).length)return!1;for(const s in a)if(!(s in i)||!o(a[s],i[s]))return!1;return!0}return t()}},{name:"compare ZodArray",compare:(e,n,t,o)=>e instanceof r.z.ZodArray&&n instanceof r.z.ZodArray?o(e.element,n.element):t()},{name:"compare ZodTuple",compare:(e,n,t,o)=>{if(e instanceof r.z.ZodTuple&&n instanceof r.z.ZodTuple){if(e.items.length!==n.items.length)return!1;for(let a=0;a<e.items.length;a++)if(!o(e.items[a],n.items[a]))return!1;return e._def.rest||n._def.rest?!e._def.rest||!n._def.rest?!1:o(e._def.rest,n._def.rest):!0}return t()}},{name:"compare ZodLiteral",compare:(e,n,t)=>e instanceof r.z.ZodLiteral&&n instanceof r.z.ZodLiteral?e.value===n.value:t()},{name:"compare ZodIntersection",compare:(e,n,t,o)=>e instanceof r.z.ZodIntersection&&n instanceof r.z.ZodIntersection?o(e._def.left,n._def.left)&&o(e._def.right,n._def.right)||o(e._def.left,n._def.right)&&o(e._def.right,n._def.left):t()},{name:"compare ZodUnion",compare:(e,n,t,o)=>{if(e instanceof r.z.ZodUnion&&n instanceof r.z.ZodUnion){const a=c(e),i=c(n);if(a.length!==i.length)return!1;for(let s of a){let f=i.findIndex(u=>o(s,u));if(f===-1)return!1;i.splice(f,1)}return i.length===0}return t()}},{name:"compare ZodReadonly",compare:(e,n,t,o)=>e instanceof r.z.ZodReadonly&&n instanceof r.z.ZodReadonly?o(e._def.innerType,n._def.innerType):t()},{name:"compare ZodRecord",compare:(e,n,t,o)=>e instanceof r.z.ZodRecord&&n instanceof r.z.ZodRecord?o(e.keySchema,n.keySchema)&&o(e.valueSchema,n.valueSchema):t()},{name:"compare ZodMap",compare:(e,n,t,o)=>e instanceof r.z.ZodMap&&n instanceof r.z.ZodMap?o(e.keySchema,n.keySchema)&&o(e.valueSchema,n.valueSchema):t()},{name:"compare ZodSet",compare:(e,n,t,o)=>e instanceof r.z.ZodSet&&n instanceof r.z.ZodSet?o(e._def.valueType,n._def.valueType):t()},{name:"compare ZodFunction",compare:(e,n,t,o)=>e instanceof r.z.ZodFunction&&n instanceof r.z.ZodFunction?o(e.parameters(),n.parameters())&&o(e.returnType(),n.returnType()):t()},{name:"compare ZodEnum",compare:(e,n,t)=>{if(e instanceof r.z.ZodEnum&&n instanceof r.z.ZodEnum){const o=e.options,a=n.options;if(o.length!==a.length)return!1;for(let i=0;i<o.length;i++)if(o[i]!==a[i])return!1;return!0}return t()}},{name:"compare ZodNativeEnum",compare:(e,n,t)=>{if(e instanceof r.z.ZodNativeEnum&&n instanceof r.z.ZodNativeEnum){const o=e.enum,a=n.enum;if(Object.keys(o).length!==Object.keys(a).length)return!1;for(const i in o)if(o[i]!==a[i])return!1;return!0}return t()}}],Z=m(l),z=[{name:"is same type",compare:(e,n,t)=>Z(e,n)?!0:t()},{name:"check typeName",compare:(e,n,t)=>{if(!("typeName"in e._def)||!("typeName"in n._def))throw new Error("Failed to compare type! "+e._def+" "+n._def);return t()}},{name:"check ZodOptional/ZodNullable",compare:(e,n,t,o)=>n instanceof r.z.ZodOptional||n instanceof r.z.ZodNullable?o(e,n.unwrap()):t()},{name:"check ZodUnion",compare:(e,n,t,o)=>{if(e instanceof r.z.ZodUnion&&n instanceof r.z.ZodUnion){const a=c(e),i=c(n);for(let s=0;s<a.length;s++)if(!i.some(u=>o(a[s],u)))return!1;return!0}return e instanceof r.z.ZodUnion?c(e).every(i=>o(i,n)):n instanceof r.z.ZodUnion?c(n).some(i=>o(e,i)):t()}},{name:"compare constructor",compare:(e,n,t)=>e.constructor!==n.constructor?!1:t()},{name:"check ZodObject",compare:(e,n,t,o)=>{if(e instanceof r.z.ZodObject&&n instanceof r.z.ZodObject){const a=e.shape,i=n.shape;if(Object.keys(a).length<Object.keys(i).length)return!1;for(const s in i)if(!(s in a)||!o(a[s],i[s]))return!1;return!0}return t()}},{name:"check ZodArray",compare:(e,n,t,o)=>e instanceof r.z.ZodArray&&n instanceof r.z.ZodArray?o(e.element,n.element):t()},{name:"check ZodTuple",compare:(e,n,t,o)=>{if(e instanceof r.z.ZodTuple&&n instanceof r.z.ZodTuple){if(e.items.length<n.items.length)return!1;for(let a=0;a<n.items.length;a++)if(!o(e.items[a],n.items[a]))return!1;return n._def.rest?e._def.rest?o(e._def.rest,n._def.rest):!1:!0}return t()}}],S=m(z),O=(e,n)=>({name:e,rule:n});exports.createCompareFn=m;exports.createIsSameTypeFn=h;exports.defineCompareRule=O;exports.isCompatibleType=S;exports.isCompatibleTypePresetRules=z;exports.isSameType=Z;exports.isSameTypePresetRules=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./is-compatible-type-BA3YzVJ3.cjs"),s=require("./is-compatible-type-CN9ljc9s.cjs"),i=e=>!!(o.isLegacyZodFunction(e)||"_zod"in e),t=e=>!i(e),n=(e,r)=>!!(t(e)&&t(r)||i(e)&&i(r)),p=(e,r)=>{if(i(e)&&i(r))return o.isSameType(e,r);if(t(e)&&t(r))return s.isSameType(e,r);throw new Error("Failed to compare types: different Zod versions")},a=(e,r)=>{if(i(e)&&i(r))return o.isCompatibleType(e,r);if(t(e)&&t(r))return s.isCompatibleType(e,r);throw new Error("Failed to compare types: different Zod versions")};exports.haveSameZodMajor=n;exports.isCompatibleType=a;exports.isSameType=p;exports.isZod3Schema=t;exports.isZod4Schema=i;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/create-compare-fn.ts","../src/utils.ts","../src/is-same-type.ts","../src/is-compatible-type.ts","../src/rules.ts"],"sourcesContent":["import type { ZodType } from \"zod\";\nimport { type CompareContext, type CompareRule } from \"./types.ts\";\n\nexport const createCompareFn = (rules: CompareRule[]) => {\n const isSameTypeFn = (\n a: ZodType,\n b: ZodType,\n context: CompareContext = {},\n ): boolean => {\n let prevIndex = -1;\n const runner = (index: number): boolean => {\n if (index === rules.length) {\n throw new Error(\"Failed to compare type! \" + a + \" \" + b);\n }\n if (index === prevIndex) {\n throw new Error(\"next() called multiple times\");\n }\n prevIndex = index;\n const rule = rules[index];\n\n const compareResult = rule.compare(\n a,\n b,\n () => runner(index + 1),\n (a, b) => isSameTypeFn(a, b, context),\n context,\n );\n\n if (\"stacks\" in context && Array.isArray(context.stacks)) {\n context.stacks.push({\n name: rule.name,\n target: [a, b],\n result: compareResult,\n });\n }\n\n return compareResult;\n };\n\n return runner(0);\n };\n return isSameTypeFn;\n};\n\n/**\n * @deprecated Use {@link createCompareFn} instead.\n */\nexport const createIsSameTypeFn = createCompareFn;\n","import { z, type ZodType } from \"zod\";\n\n// See ZodFirstPartyTypeKind\nexport const isPrimitiveType = (a: ZodType): boolean => {\n return (\n a instanceof z.ZodString ||\n a instanceof z.ZodNumber ||\n a instanceof z.ZodNaN ||\n a instanceof z.ZodBigInt ||\n a instanceof z.ZodBoolean ||\n a instanceof z.ZodDate ||\n a instanceof z.ZodSymbol ||\n a instanceof z.ZodUndefined ||\n a instanceof z.ZodNull ||\n a instanceof z.ZodAny ||\n a instanceof z.ZodUnknown ||\n a instanceof z.ZodNever ||\n a instanceof z.ZodVoid\n );\n};\n\ntype Mutable<T> = { -readonly [k in keyof T]: T[k] };\n\nexport const flatUnwrapUnion = <\n T extends z.ZodUnionOptions = readonly [z.ZodTypeAny, ...z.ZodTypeAny[]],\n>(\n t: z.ZodUnion<T>,\n): Mutable<T> => {\n return t.options.flatMap((x) => {\n if (x instanceof z.ZodUnion) {\n return flatUnwrapUnion(x);\n }\n return x;\n }) as unknown as T;\n};\n","import { z } from \"zod\";\nimport { createCompareFn } from \"./create-compare-fn.ts\";\nimport type { CompareRule } from \"./types.ts\";\nimport { flatUnwrapUnion, isPrimitiveType } from \"./utils.ts\";\n\nexport const isSameTypePresetRules = [\n {\n name: \"undefined check\",\n compare: (a, b, next) => {\n if (a === undefined || b === undefined) {\n throw new Error(\"Failed to compare type! \" + a + \" \" + b);\n }\n return next();\n },\n },\n {\n name: \"compare reference\",\n compare: (a, b, next) => {\n if (a === b) {\n return true;\n }\n return next();\n },\n },\n {\n name: \"compare constructor\",\n compare: (a, b, next) => {\n // https://stackoverflow.com/questions/24959862/how-to-tell-if-two-javascript-instances-are-of-the-same-class-type\n if (a.constructor !== b.constructor) {\n return false;\n }\n return next();\n },\n },\n {\n name: \"compare typeName\",\n compare: (a, b, next) => {\n if (!(\"typeName\" in a._def) || !(\"typeName\" in b._def)) {\n throw new Error(\"Failed to compare type! \" + a._def + \" \" + b._def);\n }\n if (a._def.typeName !== b._def.typeName) {\n return false;\n }\n return next();\n },\n },\n {\n name: \"compare ZodBranded\",\n compare: (a, b, next) => {\n if (a instanceof z.ZodBranded || b instanceof z.ZodBranded) {\n // We can not distinguish different branded type\n // throw new Error(\"Can not distinguish different branded type!\");\n return false;\n }\n return next();\n },\n },\n {\n name: \"unwrap ZodType\",\n // ZodPromise ZodOptional ZodNullable ZodBranded\n compare: (a, b, next, recheck) => {\n if (\"unwrap\" in a && typeof a.unwrap === \"function\") {\n if (!(\"unwrap\" in b && typeof b.unwrap === \"function\")) {\n return false;\n }\n return recheck(a.unwrap(), b.unwrap());\n }\n return next();\n },\n },\n {\n name: \"is same primitive\",\n compare: (a, b, next) => {\n if (\n isPrimitiveType(a) &&\n isPrimitiveType(b) &&\n a.constructor === b.constructor\n ) {\n return true;\n }\n return next();\n },\n },\n {\n name: \"compare ZodObject\",\n compare: (a, b, next, recheck) => {\n if (a instanceof z.ZodObject && b instanceof z.ZodObject) {\n const aShape = a.shape;\n const bShape = b.shape;\n if (Object.keys(aShape).length !== Object.keys(bShape).length)\n return false;\n for (const key in aShape) {\n if (!(key in bShape)) return false;\n if (!recheck(aShape[key], bShape[key])) return false;\n }\n return true;\n }\n return next();\n },\n },\n {\n name: \"compare ZodArray\",\n compare: (a, b, next, recheck) => {\n if (a instanceof z.ZodArray && b instanceof z.ZodArray) {\n return recheck(a.element, b.element);\n }\n return next();\n },\n },\n {\n name: \"compare ZodTuple\",\n compare: (a, b, next, recheck) => {\n if (a instanceof z.ZodTuple && b instanceof z.ZodTuple) {\n if (a.items.length !== b.items.length) return false;\n for (let i = 0; i < a.items.length; i++) {\n if (!recheck(a.items[i], b.items[i])) return false;\n }\n // Compare rest\n if (a._def.rest || b._def.rest) {\n // If one has rest, the other must have rest\n if (!a._def.rest || !b._def.rest) return false;\n return recheck(a._def.rest, b._def.rest);\n }\n return true;\n }\n return next();\n },\n },\n {\n name: \"compare ZodLiteral\",\n compare: (a, b, next) => {\n if (a instanceof z.ZodLiteral && b instanceof z.ZodLiteral) {\n return a.value === b.value;\n }\n return next();\n },\n },\n {\n name: \"compare ZodIntersection\",\n compare: (a, b, next, recheck) => {\n // ZodIntersection aka and\n if (a instanceof z.ZodIntersection && b instanceof z.ZodIntersection) {\n return (\n (recheck(a._def.left, b._def.left) &&\n recheck(a._def.right, b._def.right)) ||\n (recheck(a._def.left, b._def.right) &&\n recheck(a._def.right, b._def.left))\n );\n }\n return next();\n },\n },\n {\n name: \"compare ZodUnion\",\n compare: (a, b, next, recheck) => {\n // ZodUnion aka or\n if (a instanceof z.ZodUnion && b instanceof z.ZodUnion) {\n const aOptions = flatUnwrapUnion(a as z.ZodUnion<z.ZodUnionOptions>);\n const bOptions = flatUnwrapUnion(b as z.ZodUnion<z.ZodUnionOptions>);\n if (aOptions.length !== bOptions.length) return false;\n for (let optionA of aOptions) {\n let matchIndex = bOptions.findIndex((optionB) =>\n recheck(optionA, optionB),\n );\n if (matchIndex === -1) return false;\n bOptions.splice(matchIndex, 1);\n }\n return bOptions.length === 0;\n }\n return next();\n },\n },\n {\n name: \"compare ZodReadonly\",\n compare: (a, b, next, recheck) => {\n if (a instanceof z.ZodReadonly && b instanceof z.ZodReadonly) {\n return recheck(a._def.innerType, b._def.innerType);\n }\n return next();\n },\n },\n {\n name: \"compare ZodRecord\",\n compare: (a, b, next, recheck) => {\n if (a instanceof z.ZodRecord && b instanceof z.ZodRecord) {\n return (\n recheck(a.keySchema, b.keySchema) &&\n recheck(a.valueSchema, b.valueSchema)\n );\n }\n return next();\n },\n },\n {\n name: \"compare ZodMap\",\n compare: (a, b, next, recheck) => {\n if (a instanceof z.ZodMap && b instanceof z.ZodMap) {\n return (\n recheck(a.keySchema, b.keySchema) &&\n recheck(a.valueSchema, b.valueSchema)\n );\n }\n return next();\n },\n },\n {\n name: \"compare ZodSet\",\n compare: (a, b, next, recheck) => {\n if (a instanceof z.ZodSet && b instanceof z.ZodSet) {\n return recheck(a._def.valueType, b._def.valueType);\n }\n return next();\n },\n },\n {\n name: \"compare ZodFunction\",\n compare: (a, b, next, recheck) => {\n if (a instanceof z.ZodFunction && b instanceof z.ZodFunction) {\n return (\n recheck(a.parameters(), b.parameters()) &&\n recheck(a.returnType(), b.returnType())\n );\n }\n return next();\n },\n },\n {\n name: \"compare ZodEnum\",\n compare: (a, b, next) => {\n if (a instanceof z.ZodEnum && b instanceof z.ZodEnum) {\n const optionsA: [string, ...string[]] = a.options;\n const optionsB: [string, ...string[]] = b.options;\n if (optionsA.length !== optionsB.length) return false;\n for (let i = 0; i < optionsA.length; i++) {\n if (optionsA[i] !== optionsB[i]) return false;\n }\n return true;\n }\n return next();\n },\n },\n {\n name: \"compare ZodNativeEnum\",\n compare: (a, b, next) => {\n if (a instanceof z.ZodNativeEnum && b instanceof z.ZodNativeEnum) {\n const enumA: z.EnumLike = a.enum;\n const enumB: z.EnumLike = b.enum;\n if (Object.keys(enumA).length !== Object.keys(enumB).length)\n return false;\n for (const key in enumA) {\n if (enumA[key] !== enumB[key]) return false;\n }\n return true;\n }\n return next();\n },\n },\n] as const satisfies CompareRule[];\n\nexport const strictIsSameTypeRules = [\n {\n name: \"compare optional\",\n compare: (a, b, next) => {\n if (a.isOptional() !== b.isOptional()) return false;\n return next();\n },\n },\n {\n name: \"compare nullable\",\n compare: (a, b, next) => {\n if (a.isNullable() !== b.isNullable()) return false;\n return next();\n },\n },\n {\n name: \"compare corece\",\n compare: (a, b, next) => {\n if (\"corece\" in a._def && \"corece\" in b._def) {\n if (a._def.corece !== b._def.corece) {\n return false;\n }\n }\n if (\"corece\" in a._def) {\n return false;\n }\n if (\"corece\" in b._def) {\n return false;\n }\n return next();\n },\n },\n {\n name: \"compare description\",\n compare: (a, b, next) => {\n if (a.description !== b.description) {\n return false;\n }\n return next();\n },\n },\n] as const satisfies CompareRule[];\n\n/**\n * isSameType is a function that checks if two ZodTypes are the same.\n *\n * Caveats:\n * - The function does not validate specific criteria such as min or max values, length, email, etc.\n * - It excludes comparisons involving methods like .describe(), .catch(), .default(), .refine(), and .transform().\n *\n * @param a - The first ZodType to compare.\n * @param b - The second ZodType to compare.\n * @returns A boolean indicating whether the two types are the same.\n *\n * @throws Will throw an error if it encounters an unknown type.\n *\n * @example\n * ```ts\n * isSameType(z.string(), z.string()); // true\n * isSameType(z.string(), z.number()); // false\n * ```\n */\nexport const isSameType = createCompareFn(isSameTypePresetRules);\n","import { z, type ZodType } from \"zod\";\nimport { createCompareFn } from \"./create-compare-fn.ts\";\nimport { isSameType } from \"./is-same-type.ts\";\nimport type { CompareRule } from \"./types.ts\";\nimport { flatUnwrapUnion } from \"./utils.ts\";\n\nexport const isCompatibleTypePresetRules = [\n {\n name: \"is same type\",\n compare: (higherType, lowerType, next) => {\n if (isSameType(higherType, lowerType)) {\n return true;\n }\n return next();\n },\n },\n {\n name: \"check typeName\",\n compare: (higherType, lowerType, next) => {\n if (!(\"typeName\" in higherType._def) || !(\"typeName\" in lowerType._def)) {\n throw new Error(\n \"Failed to compare type! \" + higherType._def + \" \" + lowerType._def,\n );\n }\n return next();\n },\n },\n {\n name: \"check ZodOptional/ZodNullable\",\n compare: (higherType, lowerType, next, recheck) => {\n if (\n lowerType instanceof z.ZodOptional ||\n lowerType instanceof z.ZodNullable\n ) {\n return recheck(higherType, lowerType.unwrap());\n }\n return next();\n },\n },\n {\n name: \"check ZodUnion\",\n compare: (higherType, lowerType, next, recheck) => {\n if (higherType instanceof z.ZodUnion && lowerType instanceof z.ZodUnion) {\n const higherOptions = flatUnwrapUnion(higherType);\n const lowerOptions = flatUnwrapUnion(lowerType);\n for (let i = 0; i < higherOptions.length; i++) {\n const match = lowerOptions.some((option: ZodType) =>\n recheck(higherOptions[i], option),\n );\n if (!match) return false;\n }\n return true;\n }\n if (higherType instanceof z.ZodUnion) {\n const higherOptions = flatUnwrapUnion(higherType);\n return higherOptions.every((option: ZodType) =>\n recheck(option, lowerType),\n );\n }\n if (lowerType instanceof z.ZodUnion) {\n const lowerOptions = flatUnwrapUnion(lowerType);\n return lowerOptions.some((option: ZodType) =>\n recheck(higherType, option),\n );\n }\n return next();\n },\n },\n {\n name: \"compare constructor\",\n compare: (higherType, lowerType, next) => {\n // We have already checked if the types are ZodUnion or ZodOptional/ZodNullable before\n if (higherType.constructor !== lowerType.constructor) {\n return false;\n }\n return next();\n },\n },\n {\n name: \"check ZodObject\",\n compare: (higherType, lowerType, next, recheck) => {\n if (\n higherType instanceof z.ZodObject &&\n lowerType instanceof z.ZodObject\n ) {\n const superTypeShape = higherType.shape;\n const subTypeShape = lowerType.shape;\n if (\n Object.keys(superTypeShape).length < Object.keys(subTypeShape).length\n )\n return false;\n for (const key in subTypeShape) {\n if (!(key in superTypeShape)) return false;\n if (!recheck(superTypeShape[key], subTypeShape[key])) {\n return false;\n }\n }\n return true;\n }\n return next();\n },\n },\n {\n name: \"check ZodArray\",\n compare: (higherType, lowerType, next, recheck) => {\n if (higherType instanceof z.ZodArray && lowerType instanceof z.ZodArray) {\n return recheck(higherType.element, lowerType.element);\n }\n return next();\n },\n },\n {\n name: \"check ZodTuple\",\n compare: (higherType, lowerType, next, recheck) => {\n if (higherType instanceof z.ZodTuple && lowerType instanceof z.ZodTuple) {\n if (higherType.items.length < lowerType.items.length) return false;\n for (let i = 0; i < lowerType.items.length; i++) {\n if (!recheck(higherType.items[i], lowerType.items[i])) {\n return false;\n }\n }\n // Check rest\n if (lowerType._def.rest) {\n if (!higherType._def.rest) return false;\n return recheck(higherType._def.rest, lowerType._def.rest);\n }\n return true;\n }\n return next();\n },\n },\n] as const satisfies CompareRule[];\n\n/**\n * Check if a the higherType matches the lowerType\n *\n * @deprecated This a unstable API and still in development\n *\n * @param higherType The looser type\n * @param lowerType The stricter type\n *\n * @example\n * ```ts\n * isCompatibleType(z.string(), z.string()); // true\n *\n * isCompatibleType(\n * z.object({ name: z.string(), other: z.number() }),\n * z.object({ name: z.string() })\n * );\n * // true\n * ```\n */\nexport const isCompatibleType = createCompareFn(isCompatibleTypePresetRules);\n","import type { CompareFn } from \"./types.ts\";\n\nexport const defineCompareRule = (name: string, rule: CompareFn) => ({\n name,\n rule,\n});\n"],"names":["createCompareFn","rules","isSameTypeFn","a","b","context","prevIndex","runner","index","rule","compareResult","createIsSameTypeFn","isPrimitiveType","z","flatUnwrapUnion","t","x","isSameTypePresetRules","next","recheck","aShape","bShape","key","i","aOptions","bOptions","optionA","matchIndex","optionB","optionsA","optionsB","enumA","enumB","isSameType","isCompatibleTypePresetRules","higherType","lowerType","higherOptions","lowerOptions","option","superTypeShape","subTypeShape","isCompatibleType","defineCompareRule","name"],"mappings":"uGAGaA,EAAmBC,GAAyB,CACvD,MAAMC,EAAe,CACnBC,EACAC,EACAC,EAA0B,CAAA,IACd,CACZ,IAAIC,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,EAAAA,EAAE,UACvB,CACA,MAAM2B,EAAiBL,EAAW,MAC5BM,EAAeL,EAAU,MAE7B,GAAA,OAAO,KAAKI,CAAc,EAAE,OAAS,OAAO,KAAKC,CAAY,EAAE,OAExD,MAAA,GACT,UAAWnB,KAAOmB,EAEZ,GADA,EAAEnB,KAAOkB,IACT,CAACrB,EAAQqB,EAAelB,CAAG,EAAGmB,EAAanB,CAAG,CAAC,EAC1C,MAAA,GAGJ,MAAA,EACT,CACA,OAAOJ,EAAK,CACd,CACF,EACA,CACE,KAAM,iBACN,QAAS,CAACiB,EAAYC,EAAWlB,EAAMC,IACjCgB,aAAsBtB,EAAAA,EAAE,UAAYuB,aAAqBvB,EAAAA,EAAE,SACtDM,EAAQgB,EAAW,QAASC,EAAU,OAAO,EAE/ClB,EAAK,CAEhB,EACA,CACE,KAAM,iBACN,QAAS,CAACiB,EAAYC,EAAWlB,EAAMC,IAAY,CACjD,GAAIgB,aAAsBtB,EAAAA,EAAE,UAAYuB,aAAqBvB,EAAAA,EAAE,SAAU,CACvE,GAAIsB,EAAW,MAAM,OAASC,EAAU,MAAM,OAAe,MAAA,GAC7D,QAASb,EAAI,EAAGA,EAAIa,EAAU,MAAM,OAAQb,IACtC,GAAA,CAACJ,EAAQgB,EAAW,MAAMZ,CAAC,EAAGa,EAAU,MAAMb,CAAC,CAAC,EAC3C,MAAA,GAIP,OAAAa,EAAU,KAAK,KACZD,EAAW,KAAK,KACdhB,EAAQgB,EAAW,KAAK,KAAMC,EAAU,KAAK,IAAI,EADtB,GAG7B,EACT,CACA,OAAOlB,EAAK,CACd,CACF,CACF,EAqBawB,EAAmB1C,EAAgBkC,CAA2B,ECtJ9DS,EAAoB,CAACC,EAAcnC,KAAqB,CACnE,KAAAmC,EACA,KAAAnC,CACF"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/index.ts"],"sourcesContent":["import type * as z3 from \"zod/v3\";\nimport type * as z4 from \"zod/v4/core\";\nimport { isLegacyZodFunction, type LegacyZodFunction } from \"./zod4/compat.ts\";\n\n/**\n * See https://zod.dev/library-authors?id=how-to-support-zod-3-and-zod-4-simultaneously\n */\nexport const isZod4Schema = (\n schema: z3.ZodTypeAny | z4.$ZodType | LegacyZodFunction,\n): schema is z4.$ZodType => {\n if (isLegacyZodFunction(schema)) {\n // version >= v4.0 && <4.1\n return true;\n }\n if (\"_zod\" in schema) {\n // This is a Zod 4 schema\n // You can access the schema definition using `schema._zod.def`\n return true;\n } else {\n // This is a Zod 3 schema\n // You can access the schema definition using `schema._def`\n return false;\n }\n};\n\nexport const isZod3Schema = (\n schema: z3.ZodTypeAny | z4.$ZodType | LegacyZodFunction,\n): schema is z3.ZodTypeAny => !isZod4Schema(schema);\n\nexport const haveSameZodMajor = (\n schemaA: z3.ZodTypeAny | z4.$ZodType,\n schemaB: z3.ZodTypeAny | z4.$ZodType,\n): boolean => {\n if (isZod3Schema(schemaA) && isZod3Schema(schemaB)) {\n return true; // Both are Zod 3 schemas\n }\n if (isZod4Schema(schemaA) && isZod4Schema(schemaB)) {\n return true; // Both are Zod 4 schemas\n }\n return false; // One is Zod 3 and the other is Zod 4\n};\n","import type * as z3 from \"zod/v3\";\nimport type * as z4 from \"zod/v4/core\";\nimport { haveSameZodMajor, isZod3Schema, isZod4Schema } from \"./utils.ts\";\nimport {\n isCompatibleType as isCompatibleZod3Type,\n isSameType as isSameZod3Type,\n} from \"./zod3/index.ts\";\nimport type { LegacyZodFunction } from \"./zod4/compat.ts\";\nimport {\n isCompatibleType as isCompatibleZod4Type,\n isSameType as isSameZod4Type,\n} from \"./zod4/index.ts\";\n\n// Export versions checking utilities\nexport { haveSameZodMajor, isZod3Schema, isZod4Schema };\n\n/**\n * isSameType is a function that checks if two ZodTypes are the same.\n *\n * Caveats:\n * - The function does not validate specific criteria such as min or max values, length, email, etc.\n * - It excludes comparisons involving methods like .describe(), .catch(), .default(), .refine(), and .transform().\n *\n * @param a - The first ZodType to compare.\n * @param b - The second ZodType to compare.\n * @returns A boolean indicating whether the two types are the same.\n *\n * @throws Will throw an error if it encounters an unknown type.\n *\n * @example\n * ```ts\n * isSameType(z.string(), z.string()); // true\n * isSameType(z.string(), z.number()); // false\n * ```\n */\nexport const isSameType = (\n a: z3.ZodTypeAny | z4.$ZodType | LegacyZodFunction,\n b: z3.ZodTypeAny | z4.$ZodType | LegacyZodFunction,\n): boolean => {\n if (isZod4Schema(a) && isZod4Schema(b)) {\n return isSameZod4Type(a, b);\n }\n if (isZod3Schema(a) && isZod3Schema(b)) {\n return isSameZod3Type(a, b);\n }\n throw new Error(\"Failed to compare types: different Zod versions\");\n};\n\n/**\n * Check if a the higherType matches the lowerType\n *\n * @deprecated This a unstable API and still in development\n *\n * @param higherType The looser type\n * @param lowerType The stricter type\n *\n * @example\n * ```ts\n * isCompatibleType(z.string(), z.string()); // true\n *\n * isCompatibleType(\n * z.object({ name: z.string(), other: z.number() }),\n * z.object({ name: z.string() })\n * );\n * // true\n * ```\n */\nexport const isCompatibleType = (\n a: z3.ZodTypeAny | z4.$ZodType | LegacyZodFunction,\n b: z3.ZodTypeAny | z4.$ZodType | LegacyZodFunction,\n): boolean => {\n if (isZod4Schema(a) && isZod4Schema(b)) {\n return isCompatibleZod4Type(a, b);\n }\n if (isZod3Schema(a) && isZod3Schema(b)) {\n return isCompatibleZod3Type(a, b);\n }\n throw new Error(\"Failed to compare types: different Zod versions\");\n};\n"],"names":["isZod4Schema","schema","isLegacyZodFunction","isZod3Schema","haveSameZodMajor","schemaA","schemaB","isSameType","a","b","isSameZod4Type","isSameZod3Type","isCompatibleType","isCompatibleZod4Type","isCompatibleZod3Type"],"mappings":"oLAOaA,EACXC,GAEIC,GAAAA,EAAAA,oBAAoBD,CAAM,GAI1B,SAAUA,GAWHE,EACXF,GAC4B,CAACD,EAAaC,CAAM,EAErCG,EAAmB,CAC9BC,EACAC,IAEI,GAAAH,EAAaE,CAAO,GAAKF,EAAaG,CAAO,GAG7CN,EAAaK,CAAO,GAAKL,EAAaM,CAAO,GCDtCC,EAAa,CACxBC,EACAC,IACY,CACZ,GAAIT,EAAaQ,CAAC,GAAKR,EAAaS,CAAC,EACnC,OAAOC,EAAAA,WAAeF,EAAGC,CAAC,EAE5B,GAAIN,EAAaK,CAAC,GAAKL,EAAaM,CAAC,EACnC,OAAOE,EAAAA,WAAeH,EAAGC,CAAC,EAE5B,MAAM,IAAI,MAAM,iDAAiD,CACnE,EAqBaG,EAAmB,CAC9BJ,EACAC,IACY,CACZ,GAAIT,EAAaQ,CAAC,GAAKR,EAAaS,CAAC,EACnC,OAAOI,EAAAA,iBAAqBL,EAAGC,CAAC,EAElC,GAAIN,EAAaK,CAAC,GAAKL,EAAaM,CAAC,EACnC,OAAOK,EAAAA,iBAAqBN,EAAGC,CAAC,EAElC,MAAM,IAAI,MAAM,iDAAiD,CACnE"}
package/dist/index.d.ts CHANGED
@@ -1,162 +1,45 @@
1
- import { CompareContext as CompareContext_2 } from './types.ts';
2
- import { z } from 'zod';
3
- import { ZodType } from 'zod';
4
-
5
- export declare type CompareContext = {
6
- stacks?: {
7
- name: string;
8
- target: [a: ZodType, b: ZodType];
9
- result: boolean;
10
- }[];
11
- } & Record<string, unknown>;
12
-
13
- export declare type CompareFn = (a: ZodType, b: ZodType, next: () => boolean, recheck: (a: ZodType, b: ZodType) => boolean, context: CompareContext) => boolean;
14
-
15
- export declare type CompareRule = {
16
- name: string;
17
- compare: CompareFn;
18
- };
19
-
20
- export declare const createCompareFn: (rules: CompareRule[]) => (a: ZodType, b: ZodType, context?: CompareContext) => boolean;
21
-
22
- /**
23
- * @deprecated Use {@link createCompareFn} instead.
24
- */
25
- export declare const createIsSameTypeFn: (rules: CompareRule[]) => (a: ZodType, b: ZodType, context?: CompareContext) => boolean;
26
-
27
- export declare const defineCompareRule: (name: string, rule: CompareFn) => {
28
- name: string;
29
- rule: CompareFn;
30
- };
31
-
32
- /**
33
- * Check if a the higherType matches the lowerType
34
- *
35
- * @deprecated This a unstable API and still in development
36
- *
37
- * @param higherType The looser type
38
- * @param lowerType The stricter type
39
- *
40
- * @example
41
- * ```ts
42
- * isCompatibleType(z.string(), z.string()); // true
43
- *
44
- * isCompatibleType(
45
- * z.object({ name: z.string(), other: z.number() }),
46
- * z.object({ name: z.string() })
47
- * );
48
- * // true
49
- * ```
50
- */
51
- export declare const isCompatibleType: (a: ZodType, b: ZodType, context?: CompareContext_2) => boolean;
52
-
53
- export declare const isCompatibleTypePresetRules: [{
54
- readonly name: "is same type";
55
- readonly compare: (higherType: z.ZodType<any, z.ZodTypeDef, any>, lowerType: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
56
- }, {
57
- readonly name: "check typeName";
58
- readonly compare: (higherType: z.ZodType<any, z.ZodTypeDef, any>, lowerType: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
59
- }, {
60
- readonly name: "check ZodOptional/ZodNullable";
61
- readonly compare: (higherType: z.ZodType<any, z.ZodTypeDef, any>, lowerType: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: ZodType, b: ZodType) => boolean) => boolean;
62
- }, {
63
- readonly name: "check ZodUnion";
64
- readonly compare: (higherType: z.ZodType<any, z.ZodTypeDef, any>, lowerType: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: ZodType, b: ZodType) => boolean) => any;
65
- }, {
66
- readonly name: "compare constructor";
67
- readonly compare: (higherType: z.ZodType<any, z.ZodTypeDef, any>, lowerType: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
68
- }, {
69
- readonly name: "check ZodObject";
70
- readonly compare: (higherType: z.ZodType<any, z.ZodTypeDef, any>, lowerType: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: ZodType, b: ZodType) => boolean) => boolean;
71
- }, {
72
- readonly name: "check ZodArray";
73
- readonly compare: (higherType: z.ZodType<any, z.ZodTypeDef, any>, lowerType: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: ZodType, b: ZodType) => boolean) => boolean;
74
- }, {
75
- readonly name: "check ZodTuple";
76
- readonly compare: (higherType: z.ZodType<any, z.ZodTypeDef, any>, lowerType: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: ZodType, b: ZodType) => boolean) => boolean;
77
- }];
78
-
79
- /**
80
- * isSameType is a function that checks if two ZodTypes are the same.
81
- *
82
- * Caveats:
83
- * - The function does not validate specific criteria such as min or max values, length, email, etc.
84
- * - It excludes comparisons involving methods like .describe(), .catch(), .default(), .refine(), and .transform().
85
- *
86
- * @param a - The first ZodType to compare.
87
- * @param b - The second ZodType to compare.
88
- * @returns A boolean indicating whether the two types are the same.
89
- *
90
- * @throws Will throw an error if it encounters an unknown type.
91
- *
92
- * @example
93
- * ```ts
94
- * isSameType(z.string(), z.string()); // true
95
- * isSameType(z.string(), z.number()); // false
96
- * ```
97
- */
98
- export declare const isSameType: (a: z.ZodType, b: z.ZodType, context?: CompareContext_2) => boolean;
99
-
100
- export declare const isSameTypePresetRules: [{
101
- readonly name: "undefined check";
102
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
103
- }, {
104
- readonly name: "compare reference";
105
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
106
- }, {
107
- readonly name: "compare constructor";
108
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
109
- }, {
110
- readonly name: "compare typeName";
111
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
112
- }, {
113
- readonly name: "compare ZodBranded";
114
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
115
- }, {
116
- readonly name: "unwrap ZodType";
117
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
118
- }, {
119
- readonly name: "is same primitive";
120
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
121
- }, {
122
- readonly name: "compare ZodObject";
123
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
124
- }, {
125
- readonly name: "compare ZodArray";
126
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
127
- }, {
128
- readonly name: "compare ZodTuple";
129
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
130
- }, {
131
- readonly name: "compare ZodLiteral";
132
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
133
- }, {
134
- readonly name: "compare ZodIntersection";
135
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
136
- }, {
137
- readonly name: "compare ZodUnion";
138
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
139
- }, {
140
- readonly name: "compare ZodReadonly";
141
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
142
- }, {
143
- readonly name: "compare ZodRecord";
144
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
145
- }, {
146
- readonly name: "compare ZodMap";
147
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
148
- }, {
149
- readonly name: "compare ZodSet";
150
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
151
- }, {
152
- readonly name: "compare ZodFunction";
153
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean, recheck: (a: z.ZodType, b: z.ZodType) => boolean) => boolean;
154
- }, {
155
- readonly name: "compare ZodEnum";
156
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
157
- }, {
158
- readonly name: "compare ZodNativeEnum";
159
- readonly compare: (a: z.ZodType<any, z.ZodTypeDef, any>, b: z.ZodType<any, z.ZodTypeDef, any>, next: () => boolean) => boolean;
160
- }];
161
-
162
- export { }
1
+ import { haveSameZodMajor, isZod3Schema, isZod4Schema } from './utils.ts';
2
+ import { LegacyZodFunction } from './zod4/compat.ts';
3
+ import type * as z3 from "zod/v3";
4
+ import type * as z4 from "zod/v4/core";
5
+ export { haveSameZodMajor, isZod3Schema, isZod4Schema };
6
+ /**
7
+ * isSameType is a function that checks if two ZodTypes are the same.
8
+ *
9
+ * Caveats:
10
+ * - The function does not validate specific criteria such as min or max values, length, email, etc.
11
+ * - It excludes comparisons involving methods like .describe(), .catch(), .default(), .refine(), and .transform().
12
+ *
13
+ * @param a - The first ZodType to compare.
14
+ * @param b - The second ZodType to compare.
15
+ * @returns A boolean indicating whether the two types are the same.
16
+ *
17
+ * @throws Will throw an error if it encounters an unknown type.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * isSameType(z.string(), z.string()); // true
22
+ * isSameType(z.string(), z.number()); // false
23
+ * ```
24
+ */
25
+ export declare const isSameType: (a: z3.ZodTypeAny | z4.$ZodType | LegacyZodFunction, b: z3.ZodTypeAny | z4.$ZodType | LegacyZodFunction) => boolean;
26
+ /**
27
+ * Check if a the higherType matches the lowerType
28
+ *
29
+ * @deprecated This a unstable API and still in development
30
+ *
31
+ * @param higherType The looser type
32
+ * @param lowerType The stricter type
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * isCompatibleType(z.string(), z.string()); // true
37
+ *
38
+ * isCompatibleType(
39
+ * z.object({ name: z.string(), other: z.number() }),
40
+ * z.object({ name: z.string() })
41
+ * );
42
+ * // true
43
+ * ```
44
+ */
45
+ export declare const isCompatibleType: (a: z3.ZodTypeAny | z4.$ZodType | LegacyZodFunction, b: z3.ZodTypeAny | z4.$ZodType | LegacyZodFunction) => boolean;
package/dist/index.js CHANGED
@@ -1,254 +1,23 @@
1
- import { z as r } from "zod";
2
- const m = (e) => {
3
- const n = (t, o, a = {}) => {
4
- let i = -1;
5
- const s = (f) => {
6
- if (f === e.length)
7
- throw new Error("Failed to compare type! " + t + " " + o);
8
- if (f === i)
9
- throw new Error("next() called multiple times");
10
- i = f;
11
- const u = e[f], d = u.compare(
12
- t,
13
- o,
14
- () => s(f + 1),
15
- (l, Z) => n(l, Z, a),
16
- a
17
- );
18
- return "stacks" in a && Array.isArray(a.stacks) && a.stacks.push({
19
- name: u.name,
20
- target: [t, o],
21
- result: d
22
- }), d;
23
- };
24
- return s(0);
25
- };
26
- return n;
27
- }, S = m, p = (e) => e instanceof r.ZodString || e instanceof r.ZodNumber || e instanceof r.ZodNaN || e instanceof r.ZodBigInt || e instanceof r.ZodBoolean || e instanceof r.ZodDate || e instanceof r.ZodSymbol || e instanceof r.ZodUndefined || e instanceof r.ZodNull || e instanceof r.ZodAny || e instanceof r.ZodUnknown || e instanceof r.ZodNever || e instanceof r.ZodVoid, c = (e) => e.options.flatMap((n) => n instanceof r.ZodUnion ? c(n) : n), y = [
28
- {
29
- name: "undefined check",
30
- compare: (e, n, t) => {
31
- if (e === void 0 || n === void 0)
32
- throw new Error("Failed to compare type! " + e + " " + n);
33
- return t();
34
- }
35
- },
36
- {
37
- name: "compare reference",
38
- compare: (e, n, t) => e === n ? !0 : t()
39
- },
40
- {
41
- name: "compare constructor",
42
- compare: (e, n, t) => e.constructor !== n.constructor ? !1 : t()
43
- },
44
- {
45
- name: "compare typeName",
46
- compare: (e, n, t) => {
47
- if (!("typeName" in e._def) || !("typeName" in n._def))
48
- throw new Error("Failed to compare type! " + e._def + " " + n._def);
49
- return e._def.typeName !== n._def.typeName ? !1 : t();
50
- }
51
- },
52
- {
53
- name: "compare ZodBranded",
54
- compare: (e, n, t) => e instanceof r.ZodBranded || n instanceof r.ZodBranded ? !1 : t()
55
- },
56
- {
57
- name: "unwrap ZodType",
58
- // ZodPromise ZodOptional ZodNullable ZodBranded
59
- compare: (e, n, t, o) => "unwrap" in e && typeof e.unwrap == "function" ? "unwrap" in n && typeof n.unwrap == "function" ? o(e.unwrap(), n.unwrap()) : !1 : t()
60
- },
61
- {
62
- name: "is same primitive",
63
- compare: (e, n, t) => p(e) && p(n) && e.constructor === n.constructor ? !0 : t()
64
- },
65
- {
66
- name: "compare ZodObject",
67
- compare: (e, n, t, o) => {
68
- if (e instanceof r.ZodObject && n instanceof r.ZodObject) {
69
- const a = e.shape, i = n.shape;
70
- if (Object.keys(a).length !== Object.keys(i).length)
71
- return !1;
72
- for (const s in a)
73
- if (!(s in i) || !o(a[s], i[s])) return !1;
74
- return !0;
75
- }
76
- return t();
77
- }
78
- },
79
- {
80
- name: "compare ZodArray",
81
- compare: (e, n, t, o) => e instanceof r.ZodArray && n instanceof r.ZodArray ? o(e.element, n.element) : t()
82
- },
83
- {
84
- name: "compare ZodTuple",
85
- compare: (e, n, t, o) => {
86
- if (e instanceof r.ZodTuple && n instanceof r.ZodTuple) {
87
- if (e.items.length !== n.items.length) return !1;
88
- for (let a = 0; a < e.items.length; a++)
89
- if (!o(e.items[a], n.items[a])) return !1;
90
- return e._def.rest || n._def.rest ? !e._def.rest || !n._def.rest ? !1 : o(e._def.rest, n._def.rest) : !0;
91
- }
92
- return t();
93
- }
94
- },
95
- {
96
- name: "compare ZodLiteral",
97
- compare: (e, n, t) => e instanceof r.ZodLiteral && n instanceof r.ZodLiteral ? e.value === n.value : t()
98
- },
99
- {
100
- name: "compare ZodIntersection",
101
- compare: (e, n, t, o) => e instanceof r.ZodIntersection && n instanceof r.ZodIntersection ? o(e._def.left, n._def.left) && o(e._def.right, n._def.right) || o(e._def.left, n._def.right) && o(e._def.right, n._def.left) : t()
102
- },
103
- {
104
- name: "compare ZodUnion",
105
- compare: (e, n, t, o) => {
106
- if (e instanceof r.ZodUnion && n instanceof r.ZodUnion) {
107
- const a = c(e), i = c(n);
108
- if (a.length !== i.length) return !1;
109
- for (let s of a) {
110
- let f = i.findIndex(
111
- (u) => o(s, u)
112
- );
113
- if (f === -1) return !1;
114
- i.splice(f, 1);
115
- }
116
- return i.length === 0;
117
- }
118
- return t();
119
- }
120
- },
121
- {
122
- name: "compare ZodReadonly",
123
- compare: (e, n, t, o) => e instanceof r.ZodReadonly && n instanceof r.ZodReadonly ? o(e._def.innerType, n._def.innerType) : t()
124
- },
125
- {
126
- name: "compare ZodRecord",
127
- compare: (e, n, t, o) => e instanceof r.ZodRecord && n instanceof r.ZodRecord ? o(e.keySchema, n.keySchema) && o(e.valueSchema, n.valueSchema) : t()
128
- },
129
- {
130
- name: "compare ZodMap",
131
- compare: (e, n, t, o) => e instanceof r.ZodMap && n instanceof r.ZodMap ? o(e.keySchema, n.keySchema) && o(e.valueSchema, n.valueSchema) : t()
132
- },
133
- {
134
- name: "compare ZodSet",
135
- compare: (e, n, t, o) => e instanceof r.ZodSet && n instanceof r.ZodSet ? o(e._def.valueType, n._def.valueType) : t()
136
- },
137
- {
138
- name: "compare ZodFunction",
139
- compare: (e, n, t, o) => e instanceof r.ZodFunction && n instanceof r.ZodFunction ? o(e.parameters(), n.parameters()) && o(e.returnType(), n.returnType()) : t()
140
- },
141
- {
142
- name: "compare ZodEnum",
143
- compare: (e, n, t) => {
144
- if (e instanceof r.ZodEnum && n instanceof r.ZodEnum) {
145
- const o = e.options, a = n.options;
146
- if (o.length !== a.length) return !1;
147
- for (let i = 0; i < o.length; i++)
148
- if (o[i] !== a[i]) return !1;
149
- return !0;
150
- }
151
- return t();
152
- }
153
- },
154
- {
155
- name: "compare ZodNativeEnum",
156
- compare: (e, n, t) => {
157
- if (e instanceof r.ZodNativeEnum && n instanceof r.ZodNativeEnum) {
158
- const o = e.enum, a = n.enum;
159
- if (Object.keys(o).length !== Object.keys(a).length)
160
- return !1;
161
- for (const i in o)
162
- if (o[i] !== a[i]) return !1;
163
- return !0;
164
- }
165
- return t();
166
- }
167
- }
168
- ], _ = m(y), h = [
169
- {
170
- name: "is same type",
171
- compare: (e, n, t) => _(e, n) ? !0 : t()
172
- },
173
- {
174
- name: "check typeName",
175
- compare: (e, n, t) => {
176
- if (!("typeName" in e._def) || !("typeName" in n._def))
177
- throw new Error(
178
- "Failed to compare type! " + e._def + " " + n._def
179
- );
180
- return t();
181
- }
182
- },
183
- {
184
- name: "check ZodOptional/ZodNullable",
185
- compare: (e, n, t, o) => n instanceof r.ZodOptional || n instanceof r.ZodNullable ? o(e, n.unwrap()) : t()
186
- },
187
- {
188
- name: "check ZodUnion",
189
- compare: (e, n, t, o) => {
190
- if (e instanceof r.ZodUnion && n instanceof r.ZodUnion) {
191
- const a = c(e), i = c(n);
192
- for (let s = 0; s < a.length; s++)
193
- if (!i.some(
194
- (u) => o(a[s], u)
195
- )) return !1;
196
- return !0;
197
- }
198
- return e instanceof r.ZodUnion ? c(e).every(
199
- (i) => o(i, n)
200
- ) : n instanceof r.ZodUnion ? c(n).some(
201
- (i) => o(e, i)
202
- ) : t();
203
- }
204
- },
205
- {
206
- name: "compare constructor",
207
- compare: (e, n, t) => e.constructor !== n.constructor ? !1 : t()
208
- },
209
- {
210
- name: "check ZodObject",
211
- compare: (e, n, t, o) => {
212
- if (e instanceof r.ZodObject && n instanceof r.ZodObject) {
213
- const a = e.shape, i = n.shape;
214
- if (Object.keys(a).length < Object.keys(i).length)
215
- return !1;
216
- for (const s in i)
217
- if (!(s in a) || !o(a[s], i[s]))
218
- return !1;
219
- return !0;
220
- }
221
- return t();
222
- }
223
- },
224
- {
225
- name: "check ZodArray",
226
- compare: (e, n, t, o) => e instanceof r.ZodArray && n instanceof r.ZodArray ? o(e.element, n.element) : t()
227
- },
228
- {
229
- name: "check ZodTuple",
230
- compare: (e, n, t, o) => {
231
- if (e instanceof r.ZodTuple && n instanceof r.ZodTuple) {
232
- if (e.items.length < n.items.length) return !1;
233
- for (let a = 0; a < n.items.length; a++)
234
- if (!o(e.items[a], n.items[a]))
235
- return !1;
236
- return n._def.rest ? e._def.rest ? o(e._def.rest, n._def.rest) : !1 : !0;
237
- }
238
- return t();
239
- }
240
- }
241
- ], g = m(h), v = (e, n) => ({
242
- name: e,
243
- rule: n
244
- });
1
+ import { i as o, a as s, b as n } from "./is-compatible-type-DEERQsQI.js";
2
+ import { i as a, a as f } from "./is-compatible-type-CA7-IozU.js";
3
+ const t = (e) => !!(o(e) || "_zod" in e), i = (e) => !t(e), m = (e, r) => !!(i(e) && i(r) || t(e) && t(r)), d = (e, r) => {
4
+ if (t(e) && t(r))
5
+ return s(e, r);
6
+ if (i(e) && i(r))
7
+ return a(e, r);
8
+ throw new Error("Failed to compare types: different Zod versions");
9
+ }, y = (e, r) => {
10
+ if (t(e) && t(r))
11
+ return n(e, r);
12
+ if (i(e) && i(r))
13
+ return f(e, r);
14
+ throw new Error("Failed to compare types: different Zod versions");
15
+ };
245
16
  export {
246
- m as createCompareFn,
247
- S as createIsSameTypeFn,
248
- v as defineCompareRule,
249
- g as isCompatibleType,
250
- h as isCompatibleTypePresetRules,
251
- _ as isSameType,
252
- y as isSameTypePresetRules
17
+ m as haveSameZodMajor,
18
+ y as isCompatibleType,
19
+ d as isSameType,
20
+ i as isZod3Schema,
21
+ t as isZod4Schema
253
22
  };
254
23
  //# sourceMappingURL=index.js.map