attaform 0.15.0 → 0.16.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 (98) hide show
  1. package/README.md +21 -11
  2. package/dist/chunks/devtools.cjs +4 -4
  3. package/dist/chunks/devtools.cjs.map +1 -1
  4. package/dist/chunks/devtools.mjs +2 -2
  5. package/dist/chunks/indexeddb.cjs +4 -4
  6. package/dist/chunks/indexeddb.cjs.map +1 -1
  7. package/dist/chunks/indexeddb.mjs +1 -1
  8. package/dist/chunks/local-storage.cjs +2 -2
  9. package/dist/chunks/local-storage.cjs.map +1 -1
  10. package/dist/chunks/local-storage.mjs +1 -1
  11. package/dist/chunks/session-storage.cjs +2 -2
  12. package/dist/chunks/session-storage.cjs.map +1 -1
  13. package/dist/chunks/session-storage.mjs +1 -1
  14. package/dist/index.cjs +23 -22
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +76 -71
  17. package/dist/index.d.mts +76 -71
  18. package/dist/index.d.ts +76 -71
  19. package/dist/index.mjs +6 -6
  20. package/dist/nuxt.cjs +5 -11
  21. package/dist/nuxt.cjs.map +1 -1
  22. package/dist/nuxt.d.cts +8 -0
  23. package/dist/nuxt.d.mts +8 -0
  24. package/dist/nuxt.d.ts +8 -0
  25. package/dist/nuxt.mjs +6 -12
  26. package/dist/nuxt.mjs.map +1 -1
  27. package/dist/runtime/plugins/attaform.cjs +3 -2
  28. package/dist/runtime/plugins/attaform.cjs.map +1 -1
  29. package/dist/runtime/plugins/attaform.mjs +2 -1
  30. package/dist/runtime/plugins/attaform.mjs.map +1 -1
  31. package/dist/shared/{attaform.BwaYWtMs.d.cts → attaform.B7rzpK1U.d.cts} +34 -5
  32. package/dist/shared/{attaform.BwaYWtMs.d.mts → attaform.B7rzpK1U.d.mts} +34 -5
  33. package/dist/shared/{attaform.BwaYWtMs.d.ts → attaform.B7rzpK1U.d.ts} +34 -5
  34. package/dist/shared/attaform.BAuJTWuT.d.mts +84 -0
  35. package/dist/shared/{attaform.CRk8NhlD.mjs → attaform.BfMxsfmE.mjs} +428 -49
  36. package/dist/shared/attaform.BfMxsfmE.mjs.map +1 -0
  37. package/dist/shared/attaform.Bp1c-uGF.cjs +1561 -0
  38. package/dist/shared/attaform.Bp1c-uGF.cjs.map +1 -0
  39. package/dist/shared/{attaform.CDJVeoJU.cjs → attaform.C9Ph2SMx.cjs} +49 -42
  40. package/dist/shared/{attaform.qxyip_aN.mjs.map → attaform.C9Ph2SMx.cjs.map} +1 -1
  41. package/dist/shared/attaform.CINUMjPq.mjs +29 -0
  42. package/dist/shared/attaform.CINUMjPq.mjs.map +1 -0
  43. package/dist/shared/attaform.CJttVxRj.cjs +32 -0
  44. package/dist/shared/attaform.CJttVxRj.cjs.map +1 -0
  45. package/dist/shared/{attaform.CPx7zTgS.d.mts → attaform.CVv9Oh0a.d.mts} +9 -7
  46. package/dist/shared/{attaform.riAENZQM.d.ts → attaform.CWCx2r0x.d.ts} +9 -7
  47. package/dist/shared/attaform.CvOXSpCb.mjs +1908 -0
  48. package/dist/shared/attaform.CvOXSpCb.mjs.map +1 -0
  49. package/dist/shared/{attaform.qxyip_aN.mjs → attaform.DILbdvfo.mjs} +12 -5
  50. package/dist/shared/{attaform.CDJVeoJU.cjs.map → attaform.DILbdvfo.mjs.map} +1 -1
  51. package/dist/shared/attaform.DdnithOf.mjs +1555 -0
  52. package/dist/shared/attaform.DdnithOf.mjs.map +1 -0
  53. package/dist/shared/attaform.DfrYByDj.cjs +1916 -0
  54. package/dist/shared/attaform.DfrYByDj.cjs.map +1 -0
  55. package/dist/shared/{attaform.D-eHWfVx.d.cts → attaform.Dq5BabH1.d.cts} +9 -7
  56. package/dist/shared/{attaform.BOi138GE.cjs → attaform.c_NzdRyc.cjs} +4 -4
  57. package/dist/shared/{attaform.BOi138GE.cjs.map → attaform.c_NzdRyc.cjs.map} +1 -1
  58. package/dist/shared/{attaform.DXye3JKf.mjs → attaform.jrxE_xZw.mjs} +2 -2
  59. package/dist/shared/{attaform.DXye3JKf.mjs.map → attaform.jrxE_xZw.mjs.map} +1 -1
  60. package/dist/shared/attaform.ls_7jBYc.d.ts +84 -0
  61. package/dist/shared/{attaform.BgYBU8gV.cjs → attaform.rIRYSUI1.cjs} +461 -61
  62. package/dist/shared/attaform.rIRYSUI1.cjs.map +1 -0
  63. package/dist/shared/attaform.xIcmqscx.d.cts +84 -0
  64. package/dist/vite.cjs +62 -9
  65. package/dist/vite.cjs.map +1 -1
  66. package/dist/vite.d.cts +23 -32
  67. package/dist/vite.d.mts +23 -32
  68. package/dist/vite.d.ts +23 -32
  69. package/dist/vite.mjs +62 -9
  70. package/dist/vite.mjs.map +1 -1
  71. package/dist/zod-v3.cjs +9 -1553
  72. package/dist/zod-v3.cjs.map +1 -1
  73. package/dist/zod-v3.d.cts +1 -1
  74. package/dist/zod-v3.d.mts +1 -1
  75. package/dist/zod-v3.d.ts +1 -1
  76. package/dist/zod-v3.mjs +3 -1553
  77. package/dist/zod-v3.mjs.map +1 -1
  78. package/dist/zod-v4.cjs +21 -0
  79. package/dist/zod-v4.cjs.map +1 -0
  80. package/dist/zod-v4.d.cts +104 -0
  81. package/dist/zod-v4.d.mts +104 -0
  82. package/dist/zod-v4.d.ts +104 -0
  83. package/dist/zod-v4.mjs +4 -0
  84. package/dist/zod-v4.mjs.map +1 -0
  85. package/dist/zod.cjs +19 -1900
  86. package/dist/zod.cjs.map +1 -1
  87. package/dist/zod.d.cts +28 -156
  88. package/dist/zod.d.mts +28 -156
  89. package/dist/zod.d.ts +28 -156
  90. package/dist/zod.mjs +19 -1896
  91. package/dist/zod.mjs.map +1 -1
  92. package/package.json +6 -2
  93. package/dist/shared/attaform.BgYBU8gV.cjs.map +0 -1
  94. package/dist/shared/attaform.CRk8NhlD.mjs.map +0 -1
  95. package/dist/shared/attaform.RypIkgVy.cjs +0 -417
  96. package/dist/shared/attaform.RypIkgVy.cjs.map +0 -1
  97. package/dist/shared/attaform.a99dQV7Q.mjs +0 -392
  98. package/dist/shared/attaform.a99dQV7Q.mjs.map +0 -1
@@ -0,0 +1,1916 @@
1
+ 'use strict';
2
+
3
+ const useFormContext = require('./attaform.C9Ph2SMx.cjs');
4
+ const plugin = require('./attaform.rIRYSUI1.cjs');
5
+ const zod = require('zod');
6
+ const paths = require('./attaform.c_NzdRyc.cjs');
7
+
8
+ const fieldMeta = zod.z.registry();
9
+ const fieldMetaLists = /* @__PURE__ */ new WeakMap();
10
+ const originalAdd = fieldMeta.add.bind(fieldMeta);
11
+ fieldMeta.add = function add(schema, payload) {
12
+ const list = fieldMetaLists.get(schema) ?? [];
13
+ list.push(payload);
14
+ fieldMetaLists.set(schema, list);
15
+ return originalAdd(schema, payload);
16
+ };
17
+ function getFieldMetaList(schema) {
18
+ return fieldMetaLists.get(schema) ?? [];
19
+ }
20
+ function withMeta(schema, payload) {
21
+ const existing = fieldMeta.get(schema) ?? {};
22
+ const cloned = schema.clone();
23
+ fieldMeta.add(cloned, { ...existing, ...payload });
24
+ return cloned;
25
+ }
26
+ function getFieldMeta(schema) {
27
+ return fieldMeta.get(schema);
28
+ }
29
+
30
+ let warnedZodCodeMissing = false;
31
+ function zodIssuesToValidationErrors(issues, formKey) {
32
+ return issues.map((issue) => {
33
+ let code;
34
+ if (typeof issue.code === "string" && issue.code.length > 0) {
35
+ code = `zod:${issue.code}`;
36
+ } else {
37
+ code = "zod:unknown";
38
+ if (plugin.__DEV__ && !warnedZodCodeMissing) {
39
+ warnedZodCodeMissing = true;
40
+ console.warn(
41
+ "[attaform] zod-v4 adapter received an issue with no string `code`; stamping `'zod:unknown'`. This usually means a custom Zod plugin emitted an issue without the standard code field."
42
+ );
43
+ }
44
+ }
45
+ return {
46
+ message: issue.message,
47
+ path: issue.path.map((seg) => typeof seg === "number" ? seg : String(seg)),
48
+ formKey,
49
+ code
50
+ };
51
+ });
52
+ }
53
+ class UnsupportedSchemaError extends plugin.AttaformError {
54
+ }
55
+
56
+ function readDef(schema) {
57
+ if (schema === null || typeof schema !== "object") return void 0;
58
+ return schema.def;
59
+ }
60
+ function kindOf(schema) {
61
+ const def = readDef(schema);
62
+ const rawType = def?.type;
63
+ if (rawType === void 0) return "unknown";
64
+ switch (rawType) {
65
+ case "object":
66
+ return "object";
67
+ case "array":
68
+ return "array";
69
+ case "set":
70
+ return "set";
71
+ case "record":
72
+ return "record";
73
+ case "tuple":
74
+ return "tuple";
75
+ case "union":
76
+ return def?.discriminator !== void 0 ? "discriminated-union" : "union";
77
+ case "discriminated_union":
78
+ case "discriminatedUnion":
79
+ return "discriminated-union";
80
+ case "string":
81
+ return "string";
82
+ case "number":
83
+ return "number";
84
+ case "boolean":
85
+ return "boolean";
86
+ case "bigint":
87
+ return "bigint";
88
+ case "date":
89
+ return "date";
90
+ case "enum":
91
+ return "enum";
92
+ case "literal":
93
+ return "literal";
94
+ case "null":
95
+ return "null";
96
+ case "undefined":
97
+ return "undefined";
98
+ case "optional":
99
+ return "optional";
100
+ case "nullable":
101
+ return "nullable";
102
+ case "default":
103
+ case "prefault":
104
+ return "default";
105
+ case "pipe":
106
+ return "pipe";
107
+ case "readonly":
108
+ return "readonly";
109
+ case "any":
110
+ return "any";
111
+ case "nan":
112
+ return "nan";
113
+ case "void":
114
+ return "void";
115
+ case "never":
116
+ return "never";
117
+ case "lazy":
118
+ return "lazy";
119
+ case "intersection":
120
+ return "intersection";
121
+ case "catch":
122
+ return "catch";
123
+ case "promise":
124
+ return "promise";
125
+ case "custom":
126
+ return "custom";
127
+ case "template_literal":
128
+ case "templateLiteral":
129
+ return "template-literal";
130
+ default:
131
+ return "unknown";
132
+ }
133
+ }
134
+ function getObjectShape(schema) {
135
+ const s = schema;
136
+ return s.shape;
137
+ }
138
+ function getArrayElement(schema) {
139
+ const def = readDef(schema);
140
+ return def?.element;
141
+ }
142
+ function getSetValueType(schema) {
143
+ const def = readDef(schema);
144
+ return def?.valueType;
145
+ }
146
+ function getRecordKeyType(schema) {
147
+ const def = readDef(schema);
148
+ return def?.keyType;
149
+ }
150
+ function getRecordValueType(schema) {
151
+ const def = readDef(schema);
152
+ return def?.valueType;
153
+ }
154
+ function getTupleItems(schema) {
155
+ const def = readDef(schema);
156
+ return def?.items ?? [];
157
+ }
158
+ function getUnionOptions(schema) {
159
+ const def = readDef(schema);
160
+ return def?.options ?? [];
161
+ }
162
+ function getLiteralValues(schema) {
163
+ const def = readDef(schema);
164
+ return def?.values ?? [];
165
+ }
166
+ function getEnumValues(schema) {
167
+ const def = readDef(schema);
168
+ const entries = def?.entries;
169
+ if (entries === void 0) return [];
170
+ return Object.values(entries);
171
+ }
172
+ function unwrapInner(schema) {
173
+ const def = readDef(schema);
174
+ return def?.innerType;
175
+ }
176
+ function unwrapPipe(schema) {
177
+ const def = readDef(schema);
178
+ return def?.in ?? def?.out;
179
+ }
180
+ function unwrapLazy(schema) {
181
+ const def = readDef(schema);
182
+ const getter = def?.getter;
183
+ if (typeof getter !== "function") return void 0;
184
+ return getter();
185
+ }
186
+ function getLazyGetter(schema) {
187
+ const def = readDef(schema);
188
+ return typeof def?.getter === "function" ? def.getter : void 0;
189
+ }
190
+ function getIntersectionLeft(schema) {
191
+ const def = readDef(schema);
192
+ return def?.left;
193
+ }
194
+ function getIntersectionRight(schema) {
195
+ const def = readDef(schema);
196
+ return def?.right;
197
+ }
198
+ function getCatchDefault(schema) {
199
+ const def = readDef(schema);
200
+ const cv = def?.catchValue;
201
+ if (typeof cv !== "function") return void 0;
202
+ try {
203
+ return cv({ error: new Error("atta:default-values"), input: void 0 });
204
+ } catch {
205
+ return void 0;
206
+ }
207
+ }
208
+ function getDefaultValue(schema) {
209
+ const def = readDef(schema);
210
+ return def?.defaultValue;
211
+ }
212
+ function hasChecks(schema) {
213
+ const def = readDef(schema);
214
+ const checks = def?.checks;
215
+ return Array.isArray(checks) && checks.length > 0;
216
+ }
217
+ function getChecks(schema) {
218
+ const def = readDef(schema);
219
+ const checks = def?.checks;
220
+ return Array.isArray(checks) ? checks : [];
221
+ }
222
+ function getDiscriminator(schema) {
223
+ const def = readDef(schema);
224
+ return def?.discriminator;
225
+ }
226
+ function getDiscriminatedOptions(schema) {
227
+ const def = readDef(schema);
228
+ const options = def?.options;
229
+ return Array.isArray(options) ? options : [];
230
+ }
231
+ function assertZodVersion(schema) {
232
+ const def = readDef(schema);
233
+ if (def?.type === void 0) {
234
+ throw new Error(
235
+ "[attaform/zod-v4] Schema is not a Zod v4 schema. The `attaform/zod-v4` adapter requires zod@^4. Either: (a) install zod@^4 in your project; (b) import from `attaform/zod`, which auto-detects the Zod version (and tree-shakes to a single adapter when the `attaform/vite` plugin is active); or (c) import from `attaform/zod-v3` if you are staying on Zod v3."
236
+ );
237
+ }
238
+ }
239
+ function containsAsyncRefine(schema, seen) {
240
+ const visited = seen ?? /* @__PURE__ */ new WeakSet();
241
+ const candidate = schema;
242
+ if (typeof candidate !== "object" || candidate === null) return false;
243
+ if (visited.has(candidate)) return false;
244
+ visited.add(candidate);
245
+ const checks = getChecks(schema);
246
+ for (const check of checks) {
247
+ if (isAsyncCheck(check)) return true;
248
+ }
249
+ const def = readDef(schema);
250
+ if (def === void 0) return false;
251
+ if (def.innerType !== void 0 && containsAsyncRefine(def.innerType, visited)) {
252
+ return true;
253
+ }
254
+ if (def.element !== void 0 && containsAsyncRefine(def.element, visited)) {
255
+ return true;
256
+ }
257
+ if (def.in !== void 0 && containsAsyncRefine(def.in, visited)) {
258
+ return true;
259
+ }
260
+ if (def.out !== void 0 && containsAsyncRefine(def.out, visited)) {
261
+ return true;
262
+ }
263
+ if (def.left !== void 0 && containsAsyncRefine(def.left, visited)) {
264
+ return true;
265
+ }
266
+ if (def.right !== void 0 && containsAsyncRefine(def.right, visited)) {
267
+ return true;
268
+ }
269
+ if (def.keyType !== void 0 && containsAsyncRefine(def.keyType, visited)) {
270
+ return true;
271
+ }
272
+ if (def.valueType !== void 0 && containsAsyncRefine(def.valueType, visited)) {
273
+ return true;
274
+ }
275
+ if (def.shape !== void 0) {
276
+ for (const sub of Object.values(def.shape)) {
277
+ if (containsAsyncRefine(sub, visited)) return true;
278
+ }
279
+ }
280
+ if (def.entries !== void 0) {
281
+ for (const sub of Object.values(def.entries)) {
282
+ if (containsAsyncRefine(sub, visited)) return true;
283
+ }
284
+ }
285
+ if (def.options !== void 0) {
286
+ for (const sub of def.options) {
287
+ if (containsAsyncRefine(sub, visited)) return true;
288
+ }
289
+ }
290
+ if (def.items !== void 0) {
291
+ for (const sub of def.items) {
292
+ if (containsAsyncRefine(sub, visited)) return true;
293
+ }
294
+ }
295
+ if (typeof def.getter === "function") {
296
+ try {
297
+ const inner = def.getter();
298
+ if (containsAsyncRefine(inner, visited)) return true;
299
+ } catch {
300
+ }
301
+ }
302
+ return false;
303
+ }
304
+ function isAsyncCheck(check) {
305
+ if (typeof check !== "object" || check === null) return false;
306
+ const c = check;
307
+ const fn = c._def?.fn ?? c.def?.fn ?? c._zod?.def?.fn;
308
+ if (typeof fn !== "function") return false;
309
+ return fn.constructor.name === "AsyncFunction";
310
+ }
311
+
312
+ const UNSUPPORTED = ["promise", "custom", "template-literal"];
313
+ function labelPath(path) {
314
+ return path.length === 0 ? "<root>" : path.join(".");
315
+ }
316
+ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
317
+ const kind = kindOf(schema);
318
+ if (UNSUPPORTED.includes(kind)) {
319
+ throw new UnsupportedSchemaError(
320
+ `[attaform/zod] unsupported kind '${kind}' at '${labelPath(path)}'`
321
+ );
322
+ }
323
+ switch (kind) {
324
+ case "object": {
325
+ const shape = getObjectShape(schema);
326
+ for (const [key, sub] of Object.entries(shape)) {
327
+ assertSupportedKinds(sub, [...path, key], lazyGetters);
328
+ }
329
+ return;
330
+ }
331
+ case "array":
332
+ assertSupportedKinds(getArrayElement(schema), [...path, "*"], lazyGetters);
333
+ return;
334
+ case "set":
335
+ assertSupportedKinds(getSetValueType(schema), [...path, "*"], lazyGetters);
336
+ return;
337
+ case "record":
338
+ assertSupportedKinds(getRecordValueType(schema), [...path, "*"], lazyGetters);
339
+ return;
340
+ case "tuple": {
341
+ const items = getTupleItems(schema);
342
+ items.forEach((item, i) => assertSupportedKinds(item, [...path, String(i)], lazyGetters));
343
+ return;
344
+ }
345
+ case "union": {
346
+ const options = getUnionOptions(schema);
347
+ options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
348
+ return;
349
+ }
350
+ case "discriminated-union": {
351
+ const options = getDiscriminatedOptions(schema);
352
+ options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
353
+ return;
354
+ }
355
+ case "optional":
356
+ case "nullable":
357
+ case "default":
358
+ case "readonly":
359
+ case "catch": {
360
+ const inner = unwrapInner(schema);
361
+ if (inner !== void 0) assertSupportedKinds(inner, path, lazyGetters);
362
+ return;
363
+ }
364
+ case "pipe": {
365
+ const inner = unwrapPipe(schema);
366
+ if (inner !== void 0) assertSupportedKinds(inner, path, lazyGetters);
367
+ return;
368
+ }
369
+ case "lazy": {
370
+ const getter = getLazyGetter(schema);
371
+ if (getter !== void 0 && lazyGetters.includes(getter)) {
372
+ throw new UnsupportedSchemaError(
373
+ `[attaform/zod] Recursive z.lazy() at '${labelPath(path)}'`
374
+ );
375
+ }
376
+ const inner = unwrapLazy(schema);
377
+ if (inner !== void 0) {
378
+ assertSupportedKinds(
379
+ inner,
380
+ path,
381
+ getter === void 0 ? lazyGetters : [...lazyGetters, getter]
382
+ );
383
+ }
384
+ return;
385
+ }
386
+ case "intersection": {
387
+ const left = getIntersectionLeft(schema);
388
+ const right = getIntersectionRight(schema);
389
+ if (left !== void 0) assertSupportedKinds(left, [...path, "left"], lazyGetters);
390
+ if (right !== void 0) assertSupportedKinds(right, [...path, "right"], lazyGetters);
391
+ return;
392
+ }
393
+ // Leaves: nothing to descend into.
394
+ case "string":
395
+ case "number":
396
+ case "boolean":
397
+ case "bigint":
398
+ case "date":
399
+ case "enum":
400
+ case "literal":
401
+ case "null":
402
+ case "undefined":
403
+ case "nan":
404
+ case "any":
405
+ case "unknown":
406
+ case "void":
407
+ case "never":
408
+ case "promise":
409
+ case "custom":
410
+ case "template-literal":
411
+ return;
412
+ default: {
413
+ const _exhaustive = kind;
414
+ throw new Error(`assertSupportedKinds: unhandled ZodKind '${_exhaustive}'`);
415
+ }
416
+ }
417
+ }
418
+
419
+ function unwrapToDiscriminatedUnion(schema) {
420
+ let current = schema;
421
+ for (let i = 0; i < 64; i++) {
422
+ const kind = kindOf(current);
423
+ if (kind === "discriminated-union") return current;
424
+ let next;
425
+ if (kind === "optional" || kind === "nullable" || kind === "default" || kind === "readonly") {
426
+ next = unwrapInner(current);
427
+ } else if (kind === "pipe") {
428
+ next = unwrapPipe(current);
429
+ }
430
+ if (next === void 0) return void 0;
431
+ current = next;
432
+ }
433
+ return void 0;
434
+ }
435
+ function getDiscriminatedUnionFirstOption(schema) {
436
+ const options = getDiscriminatedOptions(schema);
437
+ return options[0];
438
+ }
439
+
440
+ const cyclicSentinel = "<cyclic>";
441
+ function fingerprintZodSchema(schema) {
442
+ const cache = /* @__PURE__ */ new WeakMap();
443
+ const inProgress = /* @__PURE__ */ new WeakSet();
444
+ return visit(schema, cache, inProgress);
445
+ }
446
+ function visit(schema, cache, inProgress) {
447
+ const cached = cache.get(schema);
448
+ if (cached !== void 0) return cached;
449
+ if (inProgress.has(schema)) return cyclicSentinel;
450
+ inProgress.add(schema);
451
+ try {
452
+ const computed = computeFingerprint(schema, cache, inProgress);
453
+ cache.set(schema, computed);
454
+ return computed;
455
+ } finally {
456
+ inProgress.delete(schema);
457
+ }
458
+ }
459
+ function computeFingerprint(schema, cache, inProgress) {
460
+ const kind = kindOf(schema);
461
+ const recurse = (child) => visit(child, cache, inProgress);
462
+ switch (kind) {
463
+ // Kind-only leaves: no further structure to descend into.
464
+ case "boolean":
465
+ case "null":
466
+ case "undefined":
467
+ case "any":
468
+ case "unknown":
469
+ case "nan":
470
+ case "void":
471
+ case "never":
472
+ return kind;
473
+ // Leaves with checks (min/max/email/regex/...). Checks are
474
+ // canonicalised and sorted so `.min(3).max(10)` and `.max(10).min(3)`
475
+ // produce identical fingerprints.
476
+ case "string":
477
+ case "number":
478
+ case "bigint":
479
+ case "date":
480
+ return `${kind}${formatChecks(schema)}`;
481
+ case "literal": {
482
+ const values = [...getLiteralValues(schema)].sort((a, b) => {
483
+ const as = canonicalStringify(a);
484
+ const bs = canonicalStringify(b);
485
+ return as < bs ? -1 : as > bs ? 1 : 0;
486
+ });
487
+ return `literal:${canonicalStringify(values)}`;
488
+ }
489
+ case "enum":
490
+ return `enum:${canonicalStringify([...getEnumValues(schema)].sort((a, b) => compare(a, b)))}`;
491
+ case "object": {
492
+ const shape = getObjectShape(schema);
493
+ const sortedEntries = Object.entries(shape).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${recurse(v)}`);
494
+ return `object{${sortedEntries.join(",")}}${formatChecks(schema)}`;
495
+ }
496
+ case "array":
497
+ return `array[${recurse(getArrayElement(schema))}]${formatChecks(schema)}`;
498
+ case "set":
499
+ return `set<${recurse(getSetValueType(schema))}>${formatChecks(schema)}`;
500
+ case "tuple":
501
+ return `tuple[${getTupleItems(schema).map(recurse).join(",")}]`;
502
+ case "record":
503
+ return `record<${recurse(getRecordKeyType(schema))},${recurse(getRecordValueType(schema))}>`;
504
+ case "union": {
505
+ const options = getUnionOptions(schema).map(recurse).sort();
506
+ return `union(${options.join("|")})`;
507
+ }
508
+ case "discriminated-union": {
509
+ const disc = getDiscriminator(schema) ?? "?";
510
+ const options = getDiscriminatedOptions(schema).map(recurse).sort();
511
+ return `dunion[${JSON.stringify(disc)}](${options.join("|")})`;
512
+ }
513
+ case "optional": {
514
+ const inner = unwrapInner(schema);
515
+ return inner === void 0 ? "optional(?)" : `optional(${recurse(inner)})`;
516
+ }
517
+ case "nullable": {
518
+ const inner = unwrapInner(schema);
519
+ return inner === void 0 ? "nullable(?)" : `nullable(${recurse(inner)})`;
520
+ }
521
+ case "default": {
522
+ const inner = unwrapInner(schema);
523
+ return `default[${stableValueRepr(getDefaultValue, schema)}](${inner === void 0 ? "?" : recurse(inner)})`;
524
+ }
525
+ case "readonly": {
526
+ const inner = unwrapInner(schema);
527
+ return inner === void 0 ? "readonly(?)" : `readonly(${recurse(inner)})`;
528
+ }
529
+ case "pipe": {
530
+ const inner = unwrapPipe(schema);
531
+ return inner === void 0 ? "pipe(?)" : `pipe(${recurse(inner)})`;
532
+ }
533
+ case "catch": {
534
+ const inner = unwrapInner(schema);
535
+ return `catch[${stableValueRepr(getCatchDefault, schema)}](${inner === void 0 ? "?" : recurse(inner)})`;
536
+ }
537
+ case "lazy": {
538
+ const inner = unwrapLazy(schema);
539
+ return inner === void 0 ? "lazy(?)" : `lazy(${recurse(inner)})`;
540
+ }
541
+ case "intersection": {
542
+ const left = getIntersectionLeft(schema);
543
+ const right = getIntersectionRight(schema);
544
+ const leftFp = left === void 0 ? "?" : recurse(left);
545
+ const rightFp = right === void 0 ? "?" : recurse(right);
546
+ const parts = [leftFp, rightFp].sort();
547
+ return `intersection(${parts.join("&")})`;
548
+ }
549
+ // Structural shape isn't observable for these. Bucket them into
550
+ // kind-only fingerprints — a schema-mismatch warning can't do
551
+ // better than "both are `custom`" here, but that still catches
552
+ // `object` vs `custom` mismatches.
553
+ case "promise":
554
+ case "custom":
555
+ case "template-literal":
556
+ return `${kind}:*`;
557
+ default: {
558
+ const _ = kind;
559
+ return `unknown:${String(_)}`;
560
+ }
561
+ }
562
+ }
563
+ function stableValueRepr(get, schema) {
564
+ const first = get(schema);
565
+ const second = get(schema);
566
+ if (!Object.is(first, second) || typeof first === "function") return "fn:*";
567
+ return canonicalStringify(first);
568
+ }
569
+ function formatChecks(schema) {
570
+ const checks = getChecks(schema);
571
+ if (checks.length === 0) return "";
572
+ const parts = checks.map((c) => serializeCheck(c)).sort();
573
+ return `[${parts.join(";")}]`;
574
+ }
575
+ function serializeCheck(check) {
576
+ if (check !== null && typeof check === "object") {
577
+ const def = check._zod?.def;
578
+ if (def !== void 0) return canonicalStringify(def);
579
+ }
580
+ return canonicalStringify(check);
581
+ }
582
+ function canonicalStringify(value, seen = /* @__PURE__ */ new WeakSet()) {
583
+ if (value === null) return "null";
584
+ if (value === void 0) return "undefined";
585
+ const t = typeof value;
586
+ if (t === "string") return JSON.stringify(value);
587
+ if (t === "number" || t === "boolean") return String(value);
588
+ if (t === "bigint") return `${String(value)}n`;
589
+ if (t === "function") return "fn:*";
590
+ if (t === "symbol") return "symbol:*";
591
+ if (Array.isArray(value)) {
592
+ if (seen.has(value)) return "<cyclic>";
593
+ seen.add(value);
594
+ try {
595
+ const parts = value.map((v) => canonicalStringify(v, seen));
596
+ return `[${parts.join(",")}]`;
597
+ } finally {
598
+ seen.delete(value);
599
+ }
600
+ }
601
+ if (t === "object") {
602
+ const obj = value;
603
+ if (seen.has(obj)) return "<cyclic>";
604
+ seen.add(obj);
605
+ try {
606
+ if (value instanceof Date) return `date:${value.getTime()}`;
607
+ if (value instanceof RegExp) return `regex:${String(value)}`;
608
+ const entries = Object.entries(obj).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonicalStringify(v, seen)}`);
609
+ return `{${entries.join(",")}}`;
610
+ } finally {
611
+ seen.delete(obj);
612
+ }
613
+ }
614
+ return "unknown";
615
+ }
616
+ function compare(a, b) {
617
+ const as = String(a);
618
+ const bs = String(b);
619
+ return as < bs ? -1 : as > bs ? 1 : 0;
620
+ }
621
+
622
+ const PERMISSIVE = /* @__PURE__ */ new Set([
623
+ "string",
624
+ "number",
625
+ "boolean",
626
+ "bigint",
627
+ "date",
628
+ "null",
629
+ "undefined",
630
+ "object",
631
+ "array",
632
+ "symbol",
633
+ "function",
634
+ "map",
635
+ "set"
636
+ ]);
637
+ const MAX_LAZY_DEPTH = 64;
638
+ function slimPrimitivesOf(schema) {
639
+ return walk(schema, 0);
640
+ }
641
+ function walk(schema, depth) {
642
+ if (depth > MAX_LAZY_DEPTH) return new Set(PERMISSIVE);
643
+ const kind = kindOf(schema);
644
+ switch (kind) {
645
+ case "string":
646
+ return /* @__PURE__ */ new Set(["string"]);
647
+ case "number":
648
+ case "nan":
649
+ return /* @__PURE__ */ new Set(["number"]);
650
+ case "boolean":
651
+ return /* @__PURE__ */ new Set(["boolean"]);
652
+ case "bigint":
653
+ return /* @__PURE__ */ new Set(["bigint"]);
654
+ case "date":
655
+ return /* @__PURE__ */ new Set(["date"]);
656
+ case "null":
657
+ return /* @__PURE__ */ new Set(["null"]);
658
+ case "undefined":
659
+ case "void":
660
+ return /* @__PURE__ */ new Set(["undefined"]);
661
+ case "enum": {
662
+ const values = getEnumValues(schema);
663
+ const out = /* @__PURE__ */ new Set();
664
+ for (const v of values) {
665
+ if (typeof v === "string") out.add("string");
666
+ else if (typeof v === "number") out.add("number");
667
+ }
668
+ return out.size === 0 ? /* @__PURE__ */ new Set(["string"]) : out;
669
+ }
670
+ case "literal": {
671
+ const values = getLiteralValues(schema);
672
+ const out = /* @__PURE__ */ new Set();
673
+ for (const v of values) out.add(slimKindOfRaw(v));
674
+ return out.size === 0 ? new Set(PERMISSIVE) : out;
675
+ }
676
+ case "object":
677
+ case "record":
678
+ return /* @__PURE__ */ new Set(["object"]);
679
+ case "array":
680
+ case "tuple":
681
+ return /* @__PURE__ */ new Set(["array"]);
682
+ case "set":
683
+ return /* @__PURE__ */ new Set(["set"]);
684
+ case "optional": {
685
+ const inner = unwrapInner(schema);
686
+ const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner, depth + 1);
687
+ innerSet.add("undefined");
688
+ return innerSet;
689
+ }
690
+ case "nullable": {
691
+ const inner = unwrapInner(schema);
692
+ const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner, depth + 1);
693
+ innerSet.add("null");
694
+ return innerSet;
695
+ }
696
+ case "default":
697
+ case "readonly":
698
+ case "catch": {
699
+ const inner = unwrapInner(schema);
700
+ return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, depth + 1);
701
+ }
702
+ case "pipe": {
703
+ const inner = unwrapPipe(schema);
704
+ return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, depth + 1);
705
+ }
706
+ case "lazy": {
707
+ const inner = unwrapLazy(schema);
708
+ return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, depth + 1);
709
+ }
710
+ case "union":
711
+ case "discriminated-union": {
712
+ const options = getUnionOptions(schema);
713
+ const out = /* @__PURE__ */ new Set();
714
+ for (const opt of options) {
715
+ for (const k of walk(opt, depth + 1)) out.add(k);
716
+ }
717
+ return out.size === 0 ? new Set(PERMISSIVE) : out;
718
+ }
719
+ case "intersection": {
720
+ const left = getIntersectionLeft(schema);
721
+ const right = getIntersectionRight(schema);
722
+ const leftSet = left === void 0 ? new Set(PERMISSIVE) : walk(left, depth + 1);
723
+ const rightSet = right === void 0 ? new Set(PERMISSIVE) : walk(right, depth + 1);
724
+ const out = /* @__PURE__ */ new Set();
725
+ for (const k of leftSet) if (rightSet.has(k)) out.add(k);
726
+ return out;
727
+ }
728
+ case "never":
729
+ return /* @__PURE__ */ new Set();
730
+ case "any":
731
+ case "unknown":
732
+ return new Set(PERMISSIVE);
733
+ // Kinds we don't understand at the slim level: be permissive to
734
+ // avoid false-rejecting legitimate writes against schema shapes
735
+ // we haven't characterised.
736
+ case "promise":
737
+ case "custom":
738
+ case "template-literal":
739
+ default:
740
+ return new Set(PERMISSIVE);
741
+ }
742
+ }
743
+ function slimKindOfRaw(value) {
744
+ if (value === null) return "null";
745
+ if (value === void 0) return "undefined";
746
+ if (Array.isArray(value)) return "array";
747
+ if (value instanceof Date) return "date";
748
+ const t = typeof value;
749
+ switch (t) {
750
+ case "string":
751
+ return "string";
752
+ case "number":
753
+ return "number";
754
+ case "boolean":
755
+ return "boolean";
756
+ case "bigint":
757
+ return "bigint";
758
+ case "symbol":
759
+ return "symbol";
760
+ case "undefined":
761
+ return "undefined";
762
+ case "object":
763
+ return "object";
764
+ case "function":
765
+ return "function";
766
+ default:
767
+ return "object";
768
+ }
769
+ }
770
+
771
+ const PATH_SEPARATOR$1 = ".";
772
+ function getNestedZodSchemasAtPath(schema, path) {
773
+ if (Array.isArray(path)) return walkSegments(schema, path.map(String));
774
+ const pathString = path;
775
+ if (pathString.length === 0) return [schema];
776
+ return walkSegments(schema, pathString.split(PATH_SEPARATOR$1));
777
+ }
778
+ function walkSegments(schema, segments) {
779
+ if (segments.length === 0) return [schema];
780
+ const [head, ...rest] = segments;
781
+ if (head === void 0) return [schema];
782
+ const kind = kindOf(schema);
783
+ switch (kind) {
784
+ case "object": {
785
+ const shape = getObjectShape(schema);
786
+ if (!Object.hasOwn(shape, head)) return [];
787
+ const next = shape[head];
788
+ return next === void 0 ? [] : walkSegments(next, rest);
789
+ }
790
+ case "array":
791
+ return walkSegments(getArrayElement(schema), rest);
792
+ case "set":
793
+ return walkSegments(getSetValueType(schema), rest);
794
+ case "record":
795
+ return walkSegments(getRecordValueType(schema), rest);
796
+ case "tuple": {
797
+ const index = Number(head);
798
+ if (!Number.isInteger(index)) return [];
799
+ const items = getTupleItems(schema);
800
+ const item = items[index];
801
+ return item === void 0 ? [] : walkSegments(item, rest);
802
+ }
803
+ case "union":
804
+ return getUnionOptions(schema).flatMap((opt) => walkSegments(opt, segments));
805
+ case "discriminated-union": {
806
+ const options = getDiscriminatedOptions(schema);
807
+ const matching = options.filter((opt) => {
808
+ const shape = getObjectShape(opt);
809
+ return Object.hasOwn(shape, head);
810
+ });
811
+ const candidates = matching.length > 0 ? matching : options;
812
+ return candidates.flatMap((opt) => walkSegments(opt, segments));
813
+ }
814
+ case "optional":
815
+ case "nullable":
816
+ case "default":
817
+ case "readonly":
818
+ case "catch": {
819
+ const inner = unwrapInner(schema);
820
+ return inner === void 0 ? [] : walkSegments(inner, segments);
821
+ }
822
+ case "pipe": {
823
+ const inner = unwrapPipe(schema);
824
+ return inner === void 0 ? [] : walkSegments(inner, segments);
825
+ }
826
+ case "lazy": {
827
+ const inner = unwrapLazy(schema);
828
+ return inner === void 0 ? [] : walkSegments(inner, segments);
829
+ }
830
+ case "intersection": {
831
+ const left = getIntersectionLeft(schema);
832
+ const right = getIntersectionRight(schema);
833
+ const leftResults = left === void 0 ? [] : walkSegments(left, segments);
834
+ const rightResults = right === void 0 ? [] : walkSegments(right, segments);
835
+ return [...leftResults, ...rightResults];
836
+ }
837
+ // Leaf types — can't descend further.
838
+ case "string":
839
+ case "number":
840
+ case "bigint":
841
+ case "boolean":
842
+ case "undefined":
843
+ case "null":
844
+ case "void":
845
+ case "never":
846
+ case "any":
847
+ case "unknown":
848
+ case "date":
849
+ case "enum":
850
+ case "literal":
851
+ case "nan":
852
+ case "promise":
853
+ case "custom":
854
+ case "template-literal":
855
+ return [];
856
+ default: {
857
+ const _exhaustive = kind;
858
+ throw new Error(`walkSegments: unhandled ZodKind '${_exhaustive}'`);
859
+ }
860
+ }
861
+ }
862
+
863
+ function carryChecks(rebuilt, original, stripConfig) {
864
+ if (stripConfig.stripRefinements === true) return rebuilt;
865
+ if (!hasChecks(original)) return rebuilt;
866
+ const all = getChecks(original);
867
+ const checks = stripConfig.shouldKeepCheck === void 0 ? all : all.filter(stripConfig.shouldKeepCheck);
868
+ if (checks.length === 0) return rebuilt;
869
+ return rebuilt.check(
870
+ ...checks
871
+ );
872
+ }
873
+ function stripRefinements(schema) {
874
+ const kind = kindOf(schema);
875
+ switch (kind) {
876
+ case "string":
877
+ return hasChecks(schema) ? zod.z.string() : schema;
878
+ case "number":
879
+ return hasChecks(schema) ? zod.z.number() : schema;
880
+ case "bigint":
881
+ return hasChecks(schema) ? zod.z.bigint() : schema;
882
+ case "array": {
883
+ const element = getArrayElement(schema);
884
+ return zod.z.array(stripRefinements(element));
885
+ }
886
+ case "set": {
887
+ const valueType = getSetValueType(schema);
888
+ return zod.z.set(stripRefinements(valueType));
889
+ }
890
+ case "tuple": {
891
+ const items = getTupleItems(schema).map(stripRefinements);
892
+ return zod.z.tuple(items);
893
+ }
894
+ case "object": {
895
+ const shape = getObjectShape(schema);
896
+ const next = {};
897
+ for (const [k, v] of Object.entries(shape)) {
898
+ next[k] = stripRefinements(v);
899
+ }
900
+ return zod.z.object(next);
901
+ }
902
+ case "record": {
903
+ const keyType = getRecordKeyType(
904
+ schema
905
+ );
906
+ const valueType = stripRefinements(getRecordValueType(schema));
907
+ return zod.z.record(keyType, valueType);
908
+ }
909
+ case "union": {
910
+ const options = getUnionOptions(schema).map(stripRefinements);
911
+ return zod.z.union(options);
912
+ }
913
+ case "discriminated-union": {
914
+ const options = getDiscriminatedOptions(schema).map(
915
+ (opt) => stripRefinements(opt)
916
+ );
917
+ const discriminator = getDiscriminator(schema);
918
+ if (discriminator === void 0) return schema;
919
+ return zod.z.discriminatedUnion(
920
+ discriminator,
921
+ options
922
+ );
923
+ }
924
+ // Wrappers: strip the inner, preserve the wrapper semantics where
925
+ // possible. For stripping refinements we typically want wrappers to
926
+ // survive (optional/nullable/default), so leave them alone.
927
+ case "optional":
928
+ case "nullable":
929
+ case "default":
930
+ case "readonly":
931
+ case "pipe":
932
+ return schema;
933
+ case "lazy": {
934
+ const inner = unwrapLazy(schema);
935
+ if (inner === void 0) return schema;
936
+ const slimmedInner = stripRefinements(inner);
937
+ return zod.z.lazy(() => slimmedInner);
938
+ }
939
+ case "intersection": {
940
+ const left = getIntersectionLeft(schema);
941
+ const right = getIntersectionRight(schema);
942
+ if (left === void 0 || right === void 0) return schema;
943
+ return zod.z.intersection(stripRefinements(left), stripRefinements(right));
944
+ }
945
+ case "catch": {
946
+ const inner = unwrapInner(schema);
947
+ if (inner === void 0) return schema;
948
+ const slimmedInner = stripRefinements(inner);
949
+ return slimmedInner.catch(getCatchDefault(schema));
950
+ }
951
+ // Leaf types without refinements, or Zod features we don't rewrite.
952
+ case "boolean":
953
+ case "date":
954
+ case "enum":
955
+ case "literal":
956
+ case "null":
957
+ case "undefined":
958
+ case "any":
959
+ case "unknown":
960
+ case "nan":
961
+ case "void":
962
+ case "never":
963
+ case "promise":
964
+ case "custom":
965
+ case "template-literal":
966
+ return schema;
967
+ default: {
968
+ const _exhaustive = kind;
969
+ throw new Error(`stripRefinements: unhandled ZodKind '${_exhaustive}'`);
970
+ }
971
+ }
972
+ }
973
+ function stripAsyncChecks(schema) {
974
+ const config = {
975
+ stripRefinements: false,
976
+ shouldKeepCheck: (c) => !isAsyncCheck(c)
977
+ };
978
+ const seen = /* @__PURE__ */ new WeakSet();
979
+ function recurse(s) {
980
+ if (seen.has(s)) return s;
981
+ seen.add(s);
982
+ const kind = kindOf(s);
983
+ switch (kind) {
984
+ case "string":
985
+ return hasChecks(s) ? carryChecks(zod.z.string(), s, config) : s;
986
+ case "number":
987
+ return hasChecks(s) ? carryChecks(zod.z.number(), s, config) : s;
988
+ case "bigint":
989
+ return hasChecks(s) ? carryChecks(zod.z.bigint(), s, config) : s;
990
+ case "array": {
991
+ const element = getArrayElement(s);
992
+ return carryChecks(zod.z.array(recurse(element)), s, config);
993
+ }
994
+ case "set": {
995
+ const valueType = getSetValueType(s);
996
+ return carryChecks(zod.z.set(recurse(valueType)), s, config);
997
+ }
998
+ case "tuple": {
999
+ const items = getTupleItems(s).map(recurse);
1000
+ const rebuilt = zod.z.tuple(
1001
+ items
1002
+ );
1003
+ return carryChecks(rebuilt, s, config);
1004
+ }
1005
+ case "object": {
1006
+ const shape = getObjectShape(s);
1007
+ const next = {};
1008
+ for (const [k, v] of Object.entries(shape)) {
1009
+ next[k] = recurse(v);
1010
+ }
1011
+ return carryChecks(zod.z.object(next), s, config);
1012
+ }
1013
+ case "record": {
1014
+ const keyType = getRecordKeyType(s);
1015
+ const valueType = recurse(getRecordValueType(s));
1016
+ const rebuilt = zod.z.record(keyType, valueType);
1017
+ return carryChecks(rebuilt, s, config);
1018
+ }
1019
+ case "union": {
1020
+ const options = getUnionOptions(s).map(recurse);
1021
+ const rebuilt = zod.z.union(
1022
+ options
1023
+ );
1024
+ return carryChecks(rebuilt, s, config);
1025
+ }
1026
+ case "discriminated-union": {
1027
+ const options = getDiscriminatedOptions(s).map((opt) => recurse(opt));
1028
+ const discriminator = getDiscriminator(s);
1029
+ if (discriminator === void 0) return s;
1030
+ return zod.z.discriminatedUnion(
1031
+ discriminator,
1032
+ options
1033
+ );
1034
+ }
1035
+ case "optional": {
1036
+ const inner = unwrapInner(s);
1037
+ if (inner === void 0) return s;
1038
+ return recurse(inner).optional();
1039
+ }
1040
+ case "nullable": {
1041
+ const inner = unwrapInner(s);
1042
+ if (inner === void 0) return s;
1043
+ return recurse(inner).nullable();
1044
+ }
1045
+ case "default": {
1046
+ const inner = unwrapInner(s);
1047
+ if (inner === void 0) return s;
1048
+ return recurse(inner).default(getDefaultValue(s));
1049
+ }
1050
+ case "readonly": {
1051
+ const inner = unwrapInner(s);
1052
+ if (inner === void 0) return s;
1053
+ return recurse(inner).readonly();
1054
+ }
1055
+ case "pipe":
1056
+ return s;
1057
+ case "lazy": {
1058
+ const inner = unwrapLazy(s);
1059
+ if (inner === void 0) return s;
1060
+ const stripped = recurse(inner);
1061
+ return zod.z.lazy(() => stripped);
1062
+ }
1063
+ case "intersection": {
1064
+ const left = getIntersectionLeft(s);
1065
+ const right = getIntersectionRight(s);
1066
+ if (left === void 0 || right === void 0) return s;
1067
+ return zod.z.intersection(recurse(left), recurse(right));
1068
+ }
1069
+ case "catch": {
1070
+ const inner = unwrapInner(s);
1071
+ if (inner === void 0) return s;
1072
+ return recurse(inner).catch(getCatchDefault(s));
1073
+ }
1074
+ // Leaves with no checks — pass through unchanged.
1075
+ case "boolean":
1076
+ case "date":
1077
+ case "enum":
1078
+ case "literal":
1079
+ case "null":
1080
+ case "undefined":
1081
+ case "any":
1082
+ case "unknown":
1083
+ case "nan":
1084
+ case "void":
1085
+ case "never":
1086
+ case "promise":
1087
+ case "custom":
1088
+ case "template-literal":
1089
+ return s;
1090
+ default: {
1091
+ const _exhaustive = kind;
1092
+ throw new Error(`stripAsyncChecks: unhandled ZodKind '${_exhaustive}'`);
1093
+ }
1094
+ }
1095
+ }
1096
+ return recurse(schema);
1097
+ }
1098
+ function getSlimSchema(schema, stripConfig) {
1099
+ const kind = kindOf(schema);
1100
+ switch (kind) {
1101
+ case "optional": {
1102
+ const inner = unwrapInner(schema) ?? schema;
1103
+ const slimmedInner = getSlimSchema(inner, stripConfig);
1104
+ return stripConfig.stripOptional === true ? slimmedInner : slimmedInner.optional();
1105
+ }
1106
+ case "nullable": {
1107
+ const inner = unwrapInner(schema) ?? schema;
1108
+ const slimmedInner = getSlimSchema(inner, stripConfig);
1109
+ return stripConfig.stripNullable === true ? slimmedInner : slimmedInner.nullable();
1110
+ }
1111
+ case "default": {
1112
+ const inner = unwrapInner(schema) ?? schema;
1113
+ const slimmedInner = getSlimSchema(inner, stripConfig);
1114
+ if (stripConfig.stripDefaultValues === true) return slimmedInner;
1115
+ const defaultValue = getDefaultValue(schema);
1116
+ return slimmedInner.default(defaultValue);
1117
+ }
1118
+ case "readonly": {
1119
+ const inner = unwrapInner(schema);
1120
+ return inner === void 0 ? schema : getSlimSchema(inner, stripConfig).readonly();
1121
+ }
1122
+ case "pipe": {
1123
+ if (stripConfig.stripPipe === true) {
1124
+ const inner = unwrapPipe(schema) ?? schema;
1125
+ return getSlimSchema(inner, stripConfig);
1126
+ }
1127
+ return schema;
1128
+ }
1129
+ case "object": {
1130
+ const shape = getObjectShape(schema);
1131
+ const next = {};
1132
+ for (const [k, v] of Object.entries(shape)) {
1133
+ next[k] = getSlimSchema(v, stripConfig);
1134
+ }
1135
+ return carryChecks(zod.z.object(next), schema, stripConfig);
1136
+ }
1137
+ case "array": {
1138
+ const element = getArrayElement(schema);
1139
+ return carryChecks(zod.z.array(getSlimSchema(element, stripConfig)), schema, stripConfig);
1140
+ }
1141
+ case "set": {
1142
+ const valueType = getSetValueType(schema);
1143
+ return carryChecks(zod.z.set(getSlimSchema(valueType, stripConfig)), schema, stripConfig);
1144
+ }
1145
+ case "tuple": {
1146
+ const items = getTupleItems(schema).map((it) => getSlimSchema(it, stripConfig));
1147
+ const rebuilt = zod.z.tuple(
1148
+ items
1149
+ );
1150
+ return carryChecks(rebuilt, schema, stripConfig);
1151
+ }
1152
+ case "record": {
1153
+ const keyType = getRecordKeyType(schema);
1154
+ const valueType = getSlimSchema(getRecordValueType(schema), stripConfig);
1155
+ const rebuilt = zod.z.record(keyType, valueType);
1156
+ return carryChecks(rebuilt, schema, stripConfig);
1157
+ }
1158
+ case "union": {
1159
+ const options = getUnionOptions(schema).map((opt) => getSlimSchema(opt, stripConfig));
1160
+ const rebuilt = zod.z.union(options);
1161
+ return carryChecks(rebuilt, schema, stripConfig);
1162
+ }
1163
+ case "discriminated-union": {
1164
+ const options = getDiscriminatedOptions(schema).map(
1165
+ (opt) => getSlimSchema(opt, stripConfig)
1166
+ );
1167
+ const discriminator = getDiscriminator(schema);
1168
+ if (discriminator === void 0) return schema;
1169
+ return zod.z.discriminatedUnion(
1170
+ discriminator,
1171
+ options
1172
+ );
1173
+ }
1174
+ // Leaves: strip refinements if requested, otherwise pass through.
1175
+ case "string":
1176
+ case "number":
1177
+ case "bigint":
1178
+ return stripConfig.stripRefinements === true && hasChecks(schema) ? stripRefinements(schema) : schema;
1179
+ case "boolean":
1180
+ case "date":
1181
+ case "enum":
1182
+ case "literal":
1183
+ case "null":
1184
+ case "undefined":
1185
+ case "any":
1186
+ case "unknown":
1187
+ case "nan":
1188
+ case "void":
1189
+ case "never":
1190
+ case "promise":
1191
+ case "custom":
1192
+ case "template-literal":
1193
+ return schema;
1194
+ case "lazy": {
1195
+ const inner = unwrapLazy(schema);
1196
+ if (inner === void 0) return schema;
1197
+ const slimmedInner = getSlimSchema(inner, stripConfig);
1198
+ return zod.z.lazy(() => slimmedInner);
1199
+ }
1200
+ case "intersection": {
1201
+ const left = getIntersectionLeft(schema);
1202
+ const right = getIntersectionRight(schema);
1203
+ if (left === void 0 || right === void 0) return schema;
1204
+ return zod.z.intersection(getSlimSchema(left, stripConfig), getSlimSchema(right, stripConfig));
1205
+ }
1206
+ case "catch": {
1207
+ const inner = unwrapInner(schema);
1208
+ if (inner === void 0) return schema;
1209
+ const slimmedInner = getSlimSchema(inner, stripConfig);
1210
+ return slimmedInner.catch(getCatchDefault(schema));
1211
+ }
1212
+ default: {
1213
+ const _exhaustive = kind;
1214
+ throw new Error(`getSlimSchema: unhandled ZodKind '${_exhaustive}'`);
1215
+ }
1216
+ }
1217
+ }
1218
+
1219
+ function deriveDefault(schema, useDefault) {
1220
+ return defaultForKind(kindOf(schema), schema, useDefault);
1221
+ }
1222
+ function defaultForKind(kind, schema, useDefault) {
1223
+ switch (kind) {
1224
+ case "object": {
1225
+ const shape = getObjectShape(schema);
1226
+ const out = {};
1227
+ for (const [key, subSchema] of Object.entries(shape)) {
1228
+ out[key] = deriveDefault(subSchema, useDefault);
1229
+ }
1230
+ return out;
1231
+ }
1232
+ case "default": {
1233
+ if (useDefault) return getDefaultValue(schema);
1234
+ const inner = unwrapInner(schema);
1235
+ return inner === void 0 ? void 0 : deriveDefault(inner, useDefault);
1236
+ }
1237
+ case "optional":
1238
+ return void 0;
1239
+ case "nullable":
1240
+ return null;
1241
+ case "readonly": {
1242
+ const inner = unwrapInner(schema);
1243
+ return inner === void 0 ? void 0 : deriveDefault(inner, useDefault);
1244
+ }
1245
+ case "pipe": {
1246
+ const inner = unwrapPipe(schema);
1247
+ return inner === void 0 ? void 0 : deriveDefault(inner, useDefault);
1248
+ }
1249
+ case "array":
1250
+ return [];
1251
+ case "set":
1252
+ return /* @__PURE__ */ new Set();
1253
+ case "record":
1254
+ return {};
1255
+ case "tuple": {
1256
+ const items = getTupleItems(schema);
1257
+ return items.map((item) => deriveDefault(item, useDefault));
1258
+ }
1259
+ case "union": {
1260
+ const options = getUnionOptions(schema);
1261
+ const first = options[0];
1262
+ return first === void 0 ? void 0 : deriveDefault(first, useDefault);
1263
+ }
1264
+ case "discriminated-union": {
1265
+ const first = getDiscriminatedUnionFirstOption(schema);
1266
+ return first === void 0 ? void 0 : deriveDefault(first, useDefault);
1267
+ }
1268
+ case "string":
1269
+ return "";
1270
+ case "number":
1271
+ return 0;
1272
+ case "bigint":
1273
+ return 0n;
1274
+ case "boolean":
1275
+ return false;
1276
+ case "date":
1277
+ return /* @__PURE__ */ new Date(0);
1278
+ case "null":
1279
+ return null;
1280
+ case "undefined":
1281
+ return void 0;
1282
+ case "enum": {
1283
+ const values = getEnumValues(schema);
1284
+ return values[0];
1285
+ }
1286
+ case "literal": {
1287
+ const values = getLiteralValues(schema);
1288
+ return values[0];
1289
+ }
1290
+ case "nan":
1291
+ return NaN;
1292
+ case "lazy": {
1293
+ const inner = unwrapLazy(schema);
1294
+ return inner === void 0 ? void 0 : deriveDefault(inner, useDefault);
1295
+ }
1296
+ case "intersection": {
1297
+ const left = getIntersectionLeft(schema);
1298
+ const right = getIntersectionRight(schema);
1299
+ const l = left === void 0 ? void 0 : deriveDefault(left, useDefault);
1300
+ const r = right === void 0 ? void 0 : deriveDefault(right, useDefault);
1301
+ return mergeDeep(l, r);
1302
+ }
1303
+ case "catch": {
1304
+ if (useDefault) return getCatchDefault(schema);
1305
+ const inner = unwrapInner(schema);
1306
+ return inner === void 0 ? void 0 : deriveDefault(inner, useDefault);
1307
+ }
1308
+ case "any":
1309
+ case "unknown":
1310
+ case "void":
1311
+ case "never":
1312
+ case "promise":
1313
+ case "custom":
1314
+ case "template-literal":
1315
+ return void 0;
1316
+ default: {
1317
+ const _exhaustive = kind;
1318
+ throw new Error(`deriveDefault: unhandled ZodKind '${_exhaustive}'`);
1319
+ }
1320
+ }
1321
+ }
1322
+ function mergeDeep(base, override) {
1323
+ if (override === void 0) return base;
1324
+ if (!useFormContext.isPlainRecord(override)) return override;
1325
+ if (!useFormContext.isPlainRecord(base)) return override;
1326
+ const result = { ...base };
1327
+ for (const key of Object.keys(override)) {
1328
+ const oVal = override[key];
1329
+ const bVal = base[key];
1330
+ if (useFormContext.isPlainRecord(oVal) && useFormContext.isPlainRecord(bVal)) {
1331
+ result[key] = mergeDeep(bVal, oVal);
1332
+ } else if (oVal !== void 0) {
1333
+ result[key] = oVal;
1334
+ }
1335
+ }
1336
+ return result;
1337
+ }
1338
+ function getDefaultValuesFromZodSchema(opts) {
1339
+ const { schema, useDefaultSchemaValues, constraints } = opts;
1340
+ const initial = deriveDefault(schema, useDefaultSchemaValues);
1341
+ const merged = mergeDeep(initial, constraints);
1342
+ const slimSchema = getSlimSchema(schema, {
1343
+ stripDefaultValues: true,
1344
+ stripPipe: true,
1345
+ stripRefinements: true
1346
+ });
1347
+ const firstParse = slimSchema.safeParse(merged);
1348
+ if (firstParse.success) {
1349
+ return { data: firstParse.data, success: true, slimSchema };
1350
+ }
1351
+ let fixedData = merged;
1352
+ for (const issue of firstParse.error.issues) {
1353
+ const pathSegments = issue.path.map((seg) => typeof seg === "number" ? seg : String(seg));
1354
+ const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments);
1355
+ if (candidates.length === 0) continue;
1356
+ const candidate = candidates[0];
1357
+ if (candidate === void 0) continue;
1358
+ const valueAtPath = useFormContext.getAtPath(merged, pathSegments);
1359
+ const slimKinds = slimPrimitivesOf(candidate);
1360
+ if (slimKinds.size > 0 && slimKinds.has(useFormContext.slimKindOf(valueAtPath))) {
1361
+ continue;
1362
+ }
1363
+ const fixValue = defaultFromIssue(issue, candidate, useDefaultSchemaValues);
1364
+ if (fixValue === SKIP) continue;
1365
+ fixedData = pathSegments.length === 0 ? fixValue : useFormContext.setAtPath(fixedData, pathSegments, fixValue);
1366
+ }
1367
+ const secondParse = slimSchema.safeParse(fixedData);
1368
+ if (secondParse.success) {
1369
+ return { data: secondParse.data, success: true, slimSchema };
1370
+ }
1371
+ return { data: fixedData, success: false, slimSchema };
1372
+ }
1373
+ const SKIP = Symbol("atta:skip-fix");
1374
+ function defaultFromIssue(issue, candidate, useDefaultSchemaValues) {
1375
+ if (issue.code === "invalid_type") {
1376
+ const du = unwrapToDiscriminatedUnion(candidate);
1377
+ if (du !== void 0) {
1378
+ const first = getDiscriminatedUnionFirstOption(du);
1379
+ if (first !== void 0) return deriveDefault(first, useDefaultSchemaValues);
1380
+ }
1381
+ return deriveDefault(candidate, useDefaultSchemaValues);
1382
+ }
1383
+ if (issue.code === "invalid_value") {
1384
+ const values = issue.values;
1385
+ if (values !== void 0 && values.length > 0) return values[0];
1386
+ return deriveDefault(candidate, useDefaultSchemaValues);
1387
+ }
1388
+ return deriveDefault(candidate, useDefaultSchemaValues);
1389
+ }
1390
+
1391
+ const PATH_SEPARATOR = ".";
1392
+ function unwrapStructuralWrappers(schema) {
1393
+ let current = schema;
1394
+ for (let i = 0; i < 64; i++) {
1395
+ const outerKind = kindOf(current);
1396
+ if (outerKind !== "optional" && outerKind !== "nullable") break;
1397
+ const inner = unwrapInner(current);
1398
+ if (inner === void 0) return current;
1399
+ if (!isStructuralKind(kindOf(inner))) break;
1400
+ current = inner;
1401
+ }
1402
+ return current;
1403
+ }
1404
+ function peelAllWrappers(schema) {
1405
+ let current = schema;
1406
+ for (let i = 0; i < 64; i++) {
1407
+ const k = kindOf(current);
1408
+ let inner;
1409
+ if (k === "optional" || k === "nullable" || k === "default" || k === "readonly" || k === "catch") {
1410
+ inner = unwrapInner(current);
1411
+ } else if (k === "pipe") {
1412
+ inner = unwrapPipe(current);
1413
+ } else if (k === "lazy") {
1414
+ inner = unwrapLazy(current);
1415
+ } else {
1416
+ return current;
1417
+ }
1418
+ if (inner === void 0) return current;
1419
+ current = inner;
1420
+ }
1421
+ return current;
1422
+ }
1423
+ const STRUCTURAL_KINDS = /* @__PURE__ */ new Set([
1424
+ "object",
1425
+ "array",
1426
+ "tuple",
1427
+ "record",
1428
+ "discriminated-union",
1429
+ "union",
1430
+ "intersection",
1431
+ "optional",
1432
+ "nullable",
1433
+ "default",
1434
+ "readonly",
1435
+ "catch",
1436
+ "pipe",
1437
+ "lazy"
1438
+ ]);
1439
+ function isStructuralKind(kind) {
1440
+ return STRUCTURAL_KINDS.has(kind);
1441
+ }
1442
+ const MAX_REQUIRED_DEPTH = 64;
1443
+ function isLeafRequired(schema, depth = 0) {
1444
+ if (depth > MAX_REQUIRED_DEPTH) return true;
1445
+ const kind = kindOf(schema);
1446
+ if (kind === "optional" || kind === "nullable" || kind === "default" || kind === "catch" || kind === "undefined" || kind === "null" || kind === "void") {
1447
+ return false;
1448
+ }
1449
+ if (kind === "readonly") {
1450
+ const inner = unwrapInner(schema);
1451
+ return inner === void 0 ? true : isLeafRequired(inner, depth + 1);
1452
+ }
1453
+ if (kind === "pipe") {
1454
+ const inner = unwrapPipe(schema);
1455
+ return inner === void 0 ? true : isLeafRequired(inner, depth + 1);
1456
+ }
1457
+ if (kind === "lazy") {
1458
+ const inner = unwrapLazy(schema);
1459
+ return inner === void 0 ? true : isLeafRequired(inner, depth + 1);
1460
+ }
1461
+ if (kind === "union" || kind === "discriminated-union") {
1462
+ const options = kind === "discriminated-union" ? getDiscriminatedOptions(schema) : getUnionOptions(schema);
1463
+ if (options.length === 0) return true;
1464
+ return options.every((opt) => isLeafRequired(opt, depth + 1));
1465
+ }
1466
+ if (kind === "intersection") {
1467
+ const left = getIntersectionLeft(schema);
1468
+ const right = getIntersectionRight(schema);
1469
+ const leftReq = left === void 0 ? true : isLeafRequired(left, depth + 1);
1470
+ const rightReq = right === void 0 ? true : isLeafRequired(right, depth + 1);
1471
+ return leftReq || rightReq;
1472
+ }
1473
+ return true;
1474
+ }
1475
+ function zodV4Adapter(rootSchema) {
1476
+ assertZodVersion(rootSchema);
1477
+ assertSupportedKinds(rootSchema);
1478
+ return (formKey) => {
1479
+ const leafCache = /* @__PURE__ */ new Map();
1480
+ let asyncValidationFlag = null;
1481
+ return {
1482
+ fingerprint: () => fingerprintZodSchema(rootSchema),
1483
+ needsAsyncValidation() {
1484
+ asyncValidationFlag ?? (asyncValidationFlag = containsAsyncRefine(rootSchema));
1485
+ return asyncValidationFlag;
1486
+ },
1487
+ getDefaultValues(config) {
1488
+ const { data } = getDefaultValuesFromZodSchema({
1489
+ schema: rootSchema,
1490
+ useDefaultSchemaValues: config.useDefaultSchemaValues,
1491
+ constraints: config.constraints
1492
+ });
1493
+ if (config.strict !== false) {
1494
+ try {
1495
+ const strictResult = rootSchema.safeParse(data);
1496
+ if (strictResult.success) {
1497
+ return { data: strictResult.data, errors: void 0, success: true, formKey };
1498
+ }
1499
+ return {
1500
+ data,
1501
+ errors: zodIssuesToValidationErrors(strictResult.error.issues, formKey),
1502
+ success: false,
1503
+ formKey
1504
+ };
1505
+ } catch {
1506
+ try {
1507
+ const syncOnly = stripAsyncChecks(rootSchema);
1508
+ const syncResult = syncOnly.safeParse(data);
1509
+ if (syncResult.success) {
1510
+ return { data, errors: void 0, success: true, formKey };
1511
+ }
1512
+ return {
1513
+ data,
1514
+ errors: zodIssuesToValidationErrors(syncResult.error.issues, formKey),
1515
+ success: false,
1516
+ formKey
1517
+ };
1518
+ } catch {
1519
+ return { data, errors: void 0, success: true, formKey };
1520
+ }
1521
+ }
1522
+ }
1523
+ return { data, errors: void 0, success: true, formKey };
1524
+ },
1525
+ getDefaultAtPath(path) {
1526
+ if (path.length === 0) return deriveDefault(rootSchema, true);
1527
+ const [first] = getNestedZodSchemasAtPath(rootSchema, path);
1528
+ if (first === void 0) return void 0;
1529
+ return deriveDefault(unwrapStructuralWrappers(first), true);
1530
+ },
1531
+ arrayShapeAtPath(path) {
1532
+ if (path.length === 0) return void 0;
1533
+ const [first] = getNestedZodSchemasAtPath(rootSchema, path);
1534
+ if (first === void 0) return void 0;
1535
+ const peeled = peelAllWrappers(first);
1536
+ const kind = kindOf(peeled);
1537
+ if (kind === "tuple") return getTupleItems(peeled).length;
1538
+ if (kind === "array") return null;
1539
+ return void 0;
1540
+ },
1541
+ getSchemasAtPath(path) {
1542
+ const resolved = getNestedZodSchemasAtPath(rootSchema, path);
1543
+ return resolved.map(
1544
+ (schema) => ({
1545
+ fingerprint: () => fingerprintZodSchema(schema),
1546
+ needsAsyncValidation: () => containsAsyncRefine(schema),
1547
+ getDefaultValues: () => ({
1548
+ data: deriveDefault(schema, true),
1549
+ errors: void 0,
1550
+ success: true,
1551
+ formKey
1552
+ }),
1553
+ getSchemasAtPath: () => [],
1554
+ validateAtPath: async (data) => {
1555
+ const result = await schema.safeParseAsync(data);
1556
+ if (result.success) {
1557
+ return { data: result.data, errors: void 0, success: true, formKey };
1558
+ }
1559
+ return {
1560
+ data: void 0,
1561
+ errors: zodIssuesToValidationErrors(result.error.issues, formKey),
1562
+ success: false,
1563
+ formKey
1564
+ };
1565
+ }
1566
+ })
1567
+ );
1568
+ },
1569
+ getSlimPrimitiveTypesAtPath(path) {
1570
+ if (path.length === 0) return /* @__PURE__ */ new Set(["object"]);
1571
+ const resolved = getNestedZodSchemasAtPath(rootSchema, path);
1572
+ if (resolved.length === 0) return /* @__PURE__ */ new Set();
1573
+ const out = /* @__PURE__ */ new Set();
1574
+ for (const candidate of resolved) {
1575
+ for (const k of slimPrimitivesOf(candidate)) out.add(k);
1576
+ }
1577
+ return out;
1578
+ },
1579
+ isLeafAtPath(path) {
1580
+ const cacheKey = paths.canonicalizePath(path).key;
1581
+ const cached = leafCache.get(cacheKey);
1582
+ if (cached !== void 0) return cached;
1583
+ const prim = this.getSlimPrimitiveTypesAtPath(path);
1584
+ const isLeaf = prim.size > 0 && !prim.has("object") && !prim.has("array") && !prim.has("map") && !prim.has("set");
1585
+ leafCache.set(cacheKey, isLeaf);
1586
+ return isLeaf;
1587
+ },
1588
+ isRequiredAtPath(path) {
1589
+ if (path.length === 0) return true;
1590
+ const resolved = getNestedZodSchemasAtPath(rootSchema, path);
1591
+ if (resolved.length === 0) return false;
1592
+ return resolved.every((candidate) => isLeafRequired(candidate));
1593
+ },
1594
+ getFieldMetaAtPath(path) {
1595
+ return resolveFieldMetaAtPath(rootSchema, path);
1596
+ },
1597
+ getUnionDiscriminatorAtPath(path) {
1598
+ const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
1599
+ let matchedUnion;
1600
+ for (const candidate of candidates) {
1601
+ const du = unwrapToDiscriminatedUnion(candidate);
1602
+ if (du === void 0) continue;
1603
+ if (matchedUnion !== void 0 && matchedUnion !== du) return void 0;
1604
+ matchedUnion = du;
1605
+ }
1606
+ if (matchedUnion === void 0) return void 0;
1607
+ const discKey = getDiscriminator(matchedUnion);
1608
+ if (discKey === void 0) return void 0;
1609
+ const options = getDiscriminatedOptions(matchedUnion);
1610
+ return {
1611
+ discriminatorKey: discKey,
1612
+ getVariantDefault(value) {
1613
+ for (const opt of options) {
1614
+ const shape = getObjectShape(opt);
1615
+ const litSchema = shape[discKey];
1616
+ if (litSchema === void 0) continue;
1617
+ if (kindOf(litSchema) !== "literal") continue;
1618
+ const literalValues = getLiteralValues(litSchema);
1619
+ if (literalValues.includes(value)) return deriveDefault(opt, true);
1620
+ }
1621
+ return void 0;
1622
+ }
1623
+ };
1624
+ },
1625
+ validateAtPath(data, path, options) {
1626
+ const trySync = options?.sync === true;
1627
+ if (trySync) {
1628
+ try {
1629
+ return runSync();
1630
+ } catch {
1631
+ }
1632
+ }
1633
+ return runAsync();
1634
+ function runSync() {
1635
+ if (path === void 0) {
1636
+ const result = rootSchema.safeParse(data);
1637
+ return result.success ? { data: result.data, errors: void 0, success: true, formKey } : {
1638
+ data: void 0,
1639
+ errors: zodIssuesToValidationErrors(result.error.issues, formKey),
1640
+ success: false,
1641
+ formKey
1642
+ };
1643
+ }
1644
+ const resolved = getNestedZodSchemasAtPath(rootSchema, path);
1645
+ if (resolved.length === 0) return pathNotFound(path);
1646
+ const aggregated = [];
1647
+ for (const candidate of resolved) {
1648
+ const result = candidate.safeParse(data);
1649
+ if (result.success) {
1650
+ return { data: result.data, errors: void 0, success: true, formKey };
1651
+ }
1652
+ aggregated.push(...zodIssuesToValidationErrors(result.error.issues, formKey));
1653
+ }
1654
+ return { data: void 0, errors: aggregated, success: false, formKey };
1655
+ }
1656
+ async function runAsync() {
1657
+ if (path === void 0) {
1658
+ const result = await rootSchema.safeParseAsync(data);
1659
+ return result.success ? { data: result.data, errors: void 0, success: true, formKey } : {
1660
+ data: void 0,
1661
+ errors: zodIssuesToValidationErrors(result.error.issues, formKey),
1662
+ success: false,
1663
+ formKey
1664
+ };
1665
+ }
1666
+ const resolved = getNestedZodSchemasAtPath(rootSchema, path);
1667
+ if (resolved.length === 0) return pathNotFound(path);
1668
+ const aggregated = [];
1669
+ for (const candidate of resolved) {
1670
+ const result = await candidate.safeParseAsync(data);
1671
+ if (result.success) {
1672
+ return { data: result.data, errors: void 0, success: true, formKey };
1673
+ }
1674
+ aggregated.push(...zodIssuesToValidationErrors(result.error.issues, formKey));
1675
+ }
1676
+ return { data: void 0, errors: aggregated, success: false, formKey };
1677
+ }
1678
+ function pathNotFound(p) {
1679
+ return {
1680
+ data: void 0,
1681
+ errors: [
1682
+ {
1683
+ message: `Path '${p.join(PATH_SEPARATOR)}' did not resolve to any schema`,
1684
+ path: [...p],
1685
+ formKey,
1686
+ code: useFormContext.AttaformErrorCode.PathNotFound
1687
+ }
1688
+ ],
1689
+ success: false,
1690
+ formKey
1691
+ };
1692
+ }
1693
+ }
1694
+ };
1695
+ };
1696
+ }
1697
+ const pathMetaCache = /* @__PURE__ */ new WeakMap();
1698
+ function getPathMetaMap(rootSchema) {
1699
+ const cached = pathMetaCache.get(rootSchema);
1700
+ if (cached !== void 0) return cached;
1701
+ const map = /* @__PURE__ */ new Map();
1702
+ const counters = /* @__PURE__ */ new Map();
1703
+ const lastPathPerSchema = /* @__PURE__ */ new Map();
1704
+ const inProgress = /* @__PURE__ */ new WeakSet();
1705
+ walkForMeta(rootSchema, [], map, counters, lastPathPerSchema, inProgress);
1706
+ for (const [schema, lastPath] of lastPathPerSchema) {
1707
+ const list = getFieldMetaList(schema);
1708
+ const consumed = counters.get(schema) ?? 0;
1709
+ if (list.length <= consumed) continue;
1710
+ const surplus = list.slice(consumed).reduce((acc, p) => ({ ...acc, ...p }), {});
1711
+ const existing = map.get(lastPath) ?? {};
1712
+ map.set(lastPath, { ...existing, ...surplus });
1713
+ }
1714
+ pathMetaCache.set(rootSchema, map);
1715
+ return map;
1716
+ }
1717
+ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress) {
1718
+ if (inProgress.has(schema)) return;
1719
+ inProgress.add(schema);
1720
+ try {
1721
+ const pathKey = paths.canonicalizePath(path).key;
1722
+ if (!map.has(pathKey)) {
1723
+ const payload = consumePayload(schema, counters);
1724
+ if (payload !== void 0) {
1725
+ map.set(pathKey, payload);
1726
+ lastPathPerSchema.set(schema, pathKey);
1727
+ }
1728
+ }
1729
+ const peeled = peelAllWrappers(schema);
1730
+ if (peeled !== schema && !map.has(pathKey)) {
1731
+ const payload = consumePayload(peeled, counters);
1732
+ if (payload !== void 0) {
1733
+ map.set(pathKey, payload);
1734
+ lastPathPerSchema.set(peeled, pathKey);
1735
+ }
1736
+ }
1737
+ const kind = kindOf(schema);
1738
+ switch (kind) {
1739
+ case "object": {
1740
+ const shape = getObjectShape(schema);
1741
+ for (const [key, child] of Object.entries(shape)) {
1742
+ walkForMeta(child, [...path, key], map, counters, lastPathPerSchema, inProgress);
1743
+ }
1744
+ return;
1745
+ }
1746
+ case "array": {
1747
+ walkForMeta(
1748
+ getArrayElement(schema),
1749
+ [...path, 0],
1750
+ map,
1751
+ counters,
1752
+ lastPathPerSchema,
1753
+ inProgress
1754
+ );
1755
+ return;
1756
+ }
1757
+ case "tuple": {
1758
+ const items = getTupleItems(schema);
1759
+ for (let i = 0; i < items.length; i++) {
1760
+ const item = items[i];
1761
+ if (item !== void 0)
1762
+ walkForMeta(item, [...path, i], map, counters, lastPathPerSchema, inProgress);
1763
+ }
1764
+ return;
1765
+ }
1766
+ case "set":
1767
+ walkForMeta(
1768
+ getSetValueType(schema),
1769
+ [...path, 0],
1770
+ map,
1771
+ counters,
1772
+ lastPathPerSchema,
1773
+ inProgress
1774
+ );
1775
+ return;
1776
+ case "record":
1777
+ walkForMeta(
1778
+ getRecordValueType(schema),
1779
+ [...path, "*"],
1780
+ map,
1781
+ counters,
1782
+ lastPathPerSchema,
1783
+ inProgress
1784
+ );
1785
+ return;
1786
+ case "union": {
1787
+ for (const opt of getUnionOptions(schema)) {
1788
+ walkForMeta(opt, path, map, counters, lastPathPerSchema, inProgress);
1789
+ }
1790
+ return;
1791
+ }
1792
+ case "discriminated-union": {
1793
+ for (const opt of getDiscriminatedOptions(schema)) {
1794
+ walkForMeta(opt, path, map, counters, lastPathPerSchema, inProgress);
1795
+ }
1796
+ return;
1797
+ }
1798
+ case "optional":
1799
+ case "nullable":
1800
+ case "default":
1801
+ case "readonly":
1802
+ case "catch": {
1803
+ const inner = unwrapInner(schema);
1804
+ if (inner !== void 0)
1805
+ walkForMeta(inner, path, map, counters, lastPathPerSchema, inProgress);
1806
+ return;
1807
+ }
1808
+ case "pipe": {
1809
+ const inner = unwrapPipe(schema);
1810
+ if (inner !== void 0)
1811
+ walkForMeta(inner, path, map, counters, lastPathPerSchema, inProgress);
1812
+ return;
1813
+ }
1814
+ case "lazy": {
1815
+ const inner = unwrapLazy(schema);
1816
+ if (inner !== void 0)
1817
+ walkForMeta(inner, path, map, counters, lastPathPerSchema, inProgress);
1818
+ return;
1819
+ }
1820
+ case "intersection": {
1821
+ const left = getIntersectionLeft(schema);
1822
+ const right = getIntersectionRight(schema);
1823
+ if (left !== void 0)
1824
+ walkForMeta(left, path, map, counters, lastPathPerSchema, inProgress);
1825
+ if (right !== void 0)
1826
+ walkForMeta(right, path, map, counters, lastPathPerSchema, inProgress);
1827
+ return;
1828
+ }
1829
+ // Leaf kinds — no children to descend into; metadata for the
1830
+ // path itself was captured above. Listed explicitly so the
1831
+ // exhaustiveness check catches any new kind landing in Zod
1832
+ // without a corresponding decision here.
1833
+ case "string":
1834
+ case "number":
1835
+ case "bigint":
1836
+ case "boolean":
1837
+ case "date":
1838
+ case "enum":
1839
+ case "literal":
1840
+ case "null":
1841
+ case "undefined":
1842
+ case "any":
1843
+ case "unknown":
1844
+ case "nan":
1845
+ case "void":
1846
+ case "never":
1847
+ case "promise":
1848
+ case "custom":
1849
+ case "template-literal":
1850
+ return;
1851
+ }
1852
+ } finally {
1853
+ inProgress.delete(schema);
1854
+ }
1855
+ }
1856
+ function consumePayload(schema, counters) {
1857
+ const list = getFieldMetaList(schema);
1858
+ if (list.length === 0) return void 0;
1859
+ const idx = counters.get(schema) ?? 0;
1860
+ const payload = list[Math.min(idx, list.length - 1)];
1861
+ counters.set(schema, idx + 1);
1862
+ return payload;
1863
+ }
1864
+ function resolveFieldMetaAtPath(rootSchema, path) {
1865
+ const lastSegment = path.length === 0 ? "" : path[path.length - 1];
1866
+ const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
1867
+ const target = candidates[0];
1868
+ if (target === void 0) {
1869
+ return {
1870
+ label: useFormContext.humanize(lastSegment),
1871
+ description: void 0,
1872
+ placeholder: void 0,
1873
+ meta: Object.freeze({})
1874
+ };
1875
+ }
1876
+ const pathMap = getPathMetaMap(rootSchema);
1877
+ const pathKey = paths.canonicalizePath(path).key;
1878
+ const peeled = peelAllWrappers(target);
1879
+ const payload = pathMap.get(pathKey) ?? getFieldMeta(target) ?? (peeled !== target ? getFieldMeta(peeled) : void 0);
1880
+ const targetDescription = readDescription(target);
1881
+ const peeledDescription = peeled !== target ? readDescription(peeled) : void 0;
1882
+ const schemaDescription = targetDescription ?? peeledDescription;
1883
+ return {
1884
+ label: payload?.label ?? useFormContext.humanize(lastSegment),
1885
+ description: payload?.description ?? schemaDescription ?? void 0,
1886
+ placeholder: payload?.placeholder ?? void 0,
1887
+ meta: Object.freeze({ ...payload ?? {} })
1888
+ };
1889
+ }
1890
+ function readDescription(schema) {
1891
+ const candidate = schema.description;
1892
+ return typeof candidate === "string" ? candidate : void 0;
1893
+ }
1894
+
1895
+ function useForm(configuration) {
1896
+ const candidate = configuration;
1897
+ if (candidate === void 0 || candidate === null || candidate.schema === void 0) {
1898
+ throw new plugin.InvalidUseFormConfigError();
1899
+ }
1900
+ const adapter = zodV4Adapter(
1901
+ configuration.schema
1902
+ );
1903
+ return useFormContext.useAbstractForm({
1904
+ ...configuration,
1905
+ schema: adapter
1906
+ });
1907
+ }
1908
+
1909
+ exports.UnsupportedSchemaError = UnsupportedSchemaError;
1910
+ exports.assertZodVersion = assertZodVersion;
1911
+ exports.fieldMeta = fieldMeta;
1912
+ exports.kindOf = kindOf;
1913
+ exports.useForm = useForm;
1914
+ exports.withMeta = withMeta;
1915
+ exports.zodV4Adapter = zodV4Adapter;
1916
+ //# sourceMappingURL=attaform.DfrYByDj.cjs.map