attaform 0.19.0 → 0.20.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 (110) hide show
  1. package/dist/chunks/devtools.cjs +1 -1
  2. package/dist/chunks/devtools.mjs +1 -1
  3. package/dist/chunks/indexeddb.cjs +1 -1
  4. package/dist/chunks/indexeddb.mjs +1 -1
  5. package/dist/chunks/local-storage.cjs +1 -1
  6. package/dist/chunks/local-storage.mjs +1 -1
  7. package/dist/chunks/session-storage.cjs +1 -1
  8. package/dist/chunks/session-storage.mjs +1 -1
  9. package/dist/index.cjs +3 -6
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +14 -40
  12. package/dist/index.d.mts +14 -40
  13. package/dist/index.d.ts +14 -40
  14. package/dist/index.mjs +5 -5
  15. package/dist/nuxt.d.cts +1 -1
  16. package/dist/nuxt.d.mts +1 -1
  17. package/dist/nuxt.d.ts +1 -1
  18. package/dist/runtime/components/AttaformDevtoolsPanel.vue +2 -2
  19. package/dist/runtime/components/DevtoolsValueTree.d.vue.ts +1 -3
  20. package/dist/runtime/components/DevtoolsValueTree.vue.d.ts +1 -3
  21. package/dist/runtime/plugins/attaform.cjs +2 -2
  22. package/dist/runtime/plugins/attaform.mjs +2 -2
  23. package/dist/shared/{attaform.CrpjyXdO.mjs → attaform.BKozEdTr.mjs} +275 -266
  24. package/dist/shared/attaform.BKozEdTr.mjs.map +1 -0
  25. package/dist/shared/{attaform.Bubm_slq.cjs → attaform.BM6YD9kZ.cjs} +212 -269
  26. package/dist/shared/attaform.BM6YD9kZ.cjs.map +1 -0
  27. package/dist/shared/{attaform.CoxJ8Qm8.cjs → attaform.BPxsYtTe.cjs} +2 -26
  28. package/dist/shared/attaform.BPxsYtTe.cjs.map +1 -0
  29. package/dist/shared/{attaform.BqEfHpVB.cjs → attaform.BPy-4qRx.cjs} +275 -268
  30. package/dist/shared/attaform.BPy-4qRx.cjs.map +1 -0
  31. package/dist/shared/attaform.BWgAFnsj.mjs +770 -0
  32. package/dist/shared/attaform.BWgAFnsj.mjs.map +1 -0
  33. package/dist/shared/{attaform.BTpuvGec.d.ts → attaform.Bh3ACtts.d.ts} +109 -101
  34. package/dist/shared/{attaform.CXpzmj38.mjs → attaform.BupwXkj_.mjs} +213 -270
  35. package/dist/shared/attaform.BupwXkj_.mjs.map +1 -0
  36. package/dist/shared/{attaform.JBx8cfMA.cjs → attaform.CIn4bMsD.cjs} +263 -799
  37. package/dist/shared/attaform.CIn4bMsD.cjs.map +1 -0
  38. package/dist/shared/{attaform.BTi-PsHr.mjs → attaform.CKFbKFb6.mjs} +1818 -1472
  39. package/dist/shared/attaform.CKFbKFb6.mjs.map +1 -0
  40. package/dist/shared/{attaform.ePUcKxId.d.cts → attaform.D5-1XGQU.d.cts} +109 -101
  41. package/dist/shared/{attaform.a3uBo-gw.mjs → attaform.DEBvCjeH.mjs} +257 -793
  42. package/dist/shared/attaform.DEBvCjeH.mjs.map +1 -0
  43. package/dist/shared/{attaform.C1msmO2v.cjs → attaform.DL4CQ-oW.cjs} +1823 -1477
  44. package/dist/shared/attaform.DL4CQ-oW.cjs.map +1 -0
  45. package/dist/shared/{attaform.D4I63aBV.d.ts → attaform.DSD85fHb.d.cts} +1 -19
  46. package/dist/shared/{attaform.CBjmobqk.d.cts → attaform.DSD85fHb.d.mts} +1 -19
  47. package/dist/shared/{attaform.DXYHL99q.d.mts → attaform.DSD85fHb.d.ts} +1 -19
  48. package/dist/shared/{attaform.B7rzpK1U.d.cts → attaform.DkA5J8NW.d.cts} +1 -17
  49. package/dist/shared/{attaform.B7rzpK1U.d.mts → attaform.DkA5J8NW.d.mts} +1 -17
  50. package/dist/shared/{attaform.B7rzpK1U.d.ts → attaform.DkA5J8NW.d.ts} +1 -17
  51. package/dist/shared/{attaform.CJ-e9gYI.d.ts → attaform.Dl5kDY-A.d.ts} +1 -1
  52. package/dist/shared/attaform.Dmb6itxC.cjs +781 -0
  53. package/dist/shared/attaform.Dmb6itxC.cjs.map +1 -0
  54. package/dist/shared/{attaform.CRNA0vrd.d.mts → attaform.DoKXru-a.d.mts} +1 -1
  55. package/dist/shared/attaform.DvA-CJJW.mjs +1876 -0
  56. package/dist/shared/attaform.DvA-CJJW.mjs.map +1 -0
  57. package/dist/shared/{attaform.BtBmfLQN.d.mts → attaform.EMzJcQci.d.mts} +109 -101
  58. package/dist/shared/attaform.EZG6fOFb.mjs +35 -0
  59. package/dist/shared/attaform.EZG6fOFb.mjs.map +1 -0
  60. package/dist/shared/{attaform.QvygsFGh.d.cts → attaform.GbDo_lJi.d.cts} +1 -1
  61. package/dist/shared/{attaform.C0uGZQ4M.d.ts → attaform.SfhU0OEY.d.cts} +134 -30
  62. package/dist/shared/{attaform.C0uGZQ4M.d.cts → attaform.SfhU0OEY.d.mts} +134 -30
  63. package/dist/shared/{attaform.C0uGZQ4M.d.mts → attaform.SfhU0OEY.d.ts} +134 -30
  64. package/dist/shared/attaform.jgzuNZVC.cjs +1882 -0
  65. package/dist/shared/attaform.jgzuNZVC.cjs.map +1 -0
  66. package/dist/transforms.cjs +2 -2
  67. package/dist/transforms.d.cts +22 -13
  68. package/dist/transforms.d.mts +22 -13
  69. package/dist/transforms.d.ts +22 -13
  70. package/dist/transforms.mjs +1 -1
  71. package/dist/vite.cjs +8 -7
  72. package/dist/vite.cjs.map +1 -1
  73. package/dist/vite.mjs +8 -7
  74. package/dist/vite.mjs.map +1 -1
  75. package/dist/zod-v3.cjs +3 -3
  76. package/dist/zod-v3.d.cts +32 -6
  77. package/dist/zod-v3.d.mts +32 -6
  78. package/dist/zod-v3.d.ts +32 -6
  79. package/dist/zod-v3.mjs +3 -3
  80. package/dist/zod-v4.cjs +3 -3
  81. package/dist/zod-v4.d.cts +12 -8
  82. package/dist/zod-v4.d.mts +12 -8
  83. package/dist/zod-v4.d.ts +12 -8
  84. package/dist/zod-v4.mjs +3 -3
  85. package/dist/zod.cjs +8 -8
  86. package/dist/zod.cjs.map +1 -1
  87. package/dist/zod.d.cts +6 -6
  88. package/dist/zod.d.mts +6 -6
  89. package/dist/zod.d.ts +6 -6
  90. package/dist/zod.mjs +6 -6
  91. package/package.json +1 -1
  92. package/dist/shared/attaform.BTi-PsHr.mjs.map +0 -1
  93. package/dist/shared/attaform.BqEfHpVB.cjs.map +0 -1
  94. package/dist/shared/attaform.Bubm_slq.cjs.map +0 -1
  95. package/dist/shared/attaform.C1msmO2v.cjs.map +0 -1
  96. package/dist/shared/attaform.C8CyvYa_.cjs +0 -36
  97. package/dist/shared/attaform.C8CyvYa_.cjs.map +0 -1
  98. package/dist/shared/attaform.CXpzmj38.mjs.map +0 -1
  99. package/dist/shared/attaform.Cghpuav8.mjs +0 -57
  100. package/dist/shared/attaform.Cghpuav8.mjs.map +0 -1
  101. package/dist/shared/attaform.CiMqJHDm.mjs +0 -1594
  102. package/dist/shared/attaform.CiMqJHDm.mjs.map +0 -1
  103. package/dist/shared/attaform.CoxJ8Qm8.cjs.map +0 -1
  104. package/dist/shared/attaform.CrpjyXdO.mjs.map +0 -1
  105. package/dist/shared/attaform.D13GMFgK.mjs +0 -32
  106. package/dist/shared/attaform.D13GMFgK.mjs.map +0 -1
  107. package/dist/shared/attaform.JBx8cfMA.cjs.map +0 -1
  108. package/dist/shared/attaform.OznWyOPy.cjs +0 -1600
  109. package/dist/shared/attaform.OznWyOPy.cjs.map +0 -1
  110. package/dist/shared/attaform.a3uBo-gw.mjs.map +0 -1
@@ -0,0 +1,1876 @@
1
+ import { isFunction, cloneDeep } from 'lodash-es';
2
+ import { z } from 'zod';
3
+ import { f as fieldMetaStore, g as getFieldMetaForSchema, a as getFieldMetaListForSchema, s as slimPrimitivesWalk, c as createAbstractSchema, w as walkPathSegments, d as deriveDefaultWalk, p as peelEmbeddedDefault, N as NO_EMBEDDED_DEFAULT } from './attaform.BWgAFnsj.mjs';
4
+ import { h as humanize, g as getAtPath, j as slimKindOf, s as setAtPath, e as isPlainRecord, k as useAbstractForm } from './attaform.CKFbKFb6.mjs';
5
+ import { a as AttaformError, _ as __DEV__, j as canonicalizePath, d as InvalidUseFormConfigError } from './attaform.BKozEdTr.mjs';
6
+
7
+ const fieldMeta = fieldMetaStore;
8
+ function withMeta(schema, payload) {
9
+ const existing = getFieldMetaForSchema(schema) ?? {};
10
+ const Ctor = schema.constructor;
11
+ const cloned = new Ctor(schema._def);
12
+ fieldMetaStore.add(cloned, { ...existing, ...payload });
13
+ return cloned;
14
+ }
15
+ function getFieldMeta(schema) {
16
+ return getFieldMetaForSchema(schema);
17
+ }
18
+ function getFieldMetaList(schema) {
19
+ return getFieldMetaListForSchema(schema);
20
+ }
21
+
22
+ class UnsupportedSchemaError extends AttaformError {
23
+ }
24
+
25
+ function isZodSchemaType(schema, expectedType) {
26
+ if (typeof schema !== "object" || schema === null) return false;
27
+ const maybeDef = schema._def;
28
+ return maybeDef?.typeName === expectedType;
29
+ }
30
+
31
+ const MAX_UNWRAP_STEPS$1 = 64;
32
+ function readDef(schema) {
33
+ if (schema === null || typeof schema !== "object") return void 0;
34
+ return schema._def;
35
+ }
36
+ function kindOf(schema) {
37
+ const def = readDef(schema);
38
+ const typeName = def?.typeName;
39
+ if (typeName === void 0) return "unknown";
40
+ switch (typeName) {
41
+ case "ZodObject":
42
+ return "object";
43
+ case "ZodArray":
44
+ return "array";
45
+ case "ZodSet":
46
+ return "set";
47
+ case "ZodRecord":
48
+ return "record";
49
+ case "ZodTuple":
50
+ return "tuple";
51
+ case "ZodUnion":
52
+ return "union";
53
+ case "ZodDiscriminatedUnion":
54
+ return "discriminated-union";
55
+ case "ZodString":
56
+ return "string";
57
+ case "ZodNumber":
58
+ return "number";
59
+ case "ZodBoolean":
60
+ return "boolean";
61
+ case "ZodBigInt":
62
+ return "bigint";
63
+ case "ZodDate":
64
+ return "date";
65
+ case "ZodEnum":
66
+ return "enum";
67
+ case "ZodNativeEnum":
68
+ return "native-enum";
69
+ case "ZodLiteral":
70
+ return "literal";
71
+ case "ZodNull":
72
+ return "null";
73
+ case "ZodUndefined":
74
+ return "undefined";
75
+ case "ZodOptional":
76
+ return "optional";
77
+ case "ZodNullable":
78
+ return "nullable";
79
+ case "ZodDefault":
80
+ return "default";
81
+ case "ZodCatch":
82
+ return "catch";
83
+ case "ZodReadonly":
84
+ return "readonly";
85
+ case "ZodBranded":
86
+ return "branded";
87
+ case "ZodEffects":
88
+ return "effects";
89
+ case "ZodPipeline":
90
+ return "pipeline";
91
+ case "ZodLazy":
92
+ return "lazy";
93
+ case "ZodIntersection":
94
+ return "intersection";
95
+ case "ZodAny":
96
+ return "any";
97
+ case "ZodUnknown":
98
+ return "unknown";
99
+ case "ZodNever":
100
+ return "never";
101
+ case "ZodNaN":
102
+ return "nan";
103
+ case "ZodVoid":
104
+ return "void";
105
+ case "ZodPromise":
106
+ return "promise";
107
+ case "ZodFunction":
108
+ return "function";
109
+ case "ZodMap":
110
+ return "map";
111
+ case "ZodSymbol":
112
+ return "symbol";
113
+ default:
114
+ return "unknown";
115
+ }
116
+ }
117
+ function getTypeName(schema) {
118
+ return readDef(schema)?.typeName;
119
+ }
120
+ function getObjectShape(schema) {
121
+ const def = readDef(schema);
122
+ const raw = def?.shape;
123
+ if (typeof raw === "function") return raw();
124
+ if (raw !== void 0) return raw;
125
+ return schema.shape ?? {};
126
+ }
127
+ function getArrayElement(schema) {
128
+ const def = readDef(schema);
129
+ return def?.type;
130
+ }
131
+ function getSetValueType(schema) {
132
+ const def = readDef(schema);
133
+ return def?.valueType;
134
+ }
135
+ function getRecordKeyType(schema) {
136
+ const def = readDef(schema);
137
+ return def?.keyType;
138
+ }
139
+ function getRecordValueType(schema) {
140
+ const def = readDef(schema);
141
+ return def?.valueType;
142
+ }
143
+ function getTupleItems(schema) {
144
+ const def = readDef(schema);
145
+ return def?.items ?? [];
146
+ }
147
+ function getUnionOptions(schema) {
148
+ const def = readDef(schema);
149
+ return def?.options ?? [];
150
+ }
151
+ function getDiscriminatedOptions(schema) {
152
+ const def = readDef(schema);
153
+ return def?.options ?? [];
154
+ }
155
+ function getDiscriminator(schema) {
156
+ const def = readDef(schema);
157
+ return def?.discriminator;
158
+ }
159
+ function getIntersectionLeft(schema) {
160
+ const def = readDef(schema);
161
+ return def?.left;
162
+ }
163
+ function getIntersectionRight(schema) {
164
+ const def = readDef(schema);
165
+ return def?.right;
166
+ }
167
+ function unwrapInner(schema) {
168
+ const def = readDef(schema);
169
+ return def?.innerType;
170
+ }
171
+ function unwrapBranded(schema) {
172
+ const def = readDef(schema);
173
+ return def?.type;
174
+ }
175
+ function unwrapEffectsSource(schema) {
176
+ const def = readDef(schema);
177
+ return def?.schema;
178
+ }
179
+ function getEffectsKind(schema) {
180
+ const def = readDef(schema);
181
+ const type = def?.effect?.type;
182
+ if (type === "refinement" || type === "transform" || type === "preprocess") return type;
183
+ return void 0;
184
+ }
185
+ function isCoercePrimitive(schema) {
186
+ return readDef(schema)?.coerce === true;
187
+ }
188
+ function isPreprocessNode(schema) {
189
+ if (!isZodSchemaType(schema, "ZodEffects")) return false;
190
+ return getEffectsKind(schema) === "preprocess";
191
+ }
192
+ function isAsyncEffect(schema) {
193
+ const def = readDef(schema);
194
+ const effect = def?.effect;
195
+ if (effect === void 0) return false;
196
+ if (effect.type === "refinement") return false;
197
+ const fn = effect.transform;
198
+ if (typeof fn !== "function") return false;
199
+ return fn.constructor.name === "AsyncFunction";
200
+ }
201
+ function containsAsyncRefine(schema, seen) {
202
+ return walkForAsync(schema, "refinement", /* @__PURE__ */ new WeakSet());
203
+ }
204
+ function containsAsyncTransform(schema, seen) {
205
+ return walkForAsync(schema, "transform-or-preprocess", /* @__PURE__ */ new WeakSet());
206
+ }
207
+ function walkForAsync(schema, target, visited) {
208
+ const candidate = schema;
209
+ if (typeof candidate !== "object" || candidate === null) return false;
210
+ if (visited.has(candidate)) return false;
211
+ visited.add(candidate);
212
+ if (isZodSchemaType(schema, "ZodEffects")) {
213
+ const kind = getEffectsKind(schema);
214
+ if (target === "refinement" && kind === "refinement") return true;
215
+ if (target === "transform-or-preprocess" && (kind === "transform" || kind === "preprocess") && isAsyncEffect(schema)) {
216
+ return true;
217
+ }
218
+ const inner = unwrapEffectsSource(schema);
219
+ return inner !== void 0 && walkForAsync(inner, target, visited);
220
+ }
221
+ if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodReadonly")) {
222
+ const inner = unwrapInner(schema);
223
+ return inner !== void 0 && walkForAsync(inner, target, visited);
224
+ }
225
+ if (isZodSchemaType(schema, "ZodBranded")) {
226
+ const inner = unwrapBranded(schema);
227
+ return inner !== void 0 && walkForAsync(inner, target, visited);
228
+ }
229
+ if (isZodSchemaType(schema, "ZodLazy")) {
230
+ const inner = unwrapLazy(schema);
231
+ return inner !== void 0 && walkForAsync(inner, target, visited);
232
+ }
233
+ if (isZodSchemaType(schema, "ZodPipeline")) {
234
+ const inSide = unwrapPipeIn(schema);
235
+ if (inSide !== void 0 && walkForAsync(inSide, target, visited)) return true;
236
+ const outSide = unwrapPipeOut(schema);
237
+ if (outSide !== void 0 && walkForAsync(outSide, target, visited)) return true;
238
+ return false;
239
+ }
240
+ if (isZodSchemaType(schema, "ZodObject")) {
241
+ for (const sub of Object.values(getObjectShape(schema))) {
242
+ if (walkForAsync(sub, target, visited)) return true;
243
+ }
244
+ return false;
245
+ }
246
+ if (isZodSchemaType(schema, "ZodArray")) {
247
+ const elem = getArrayElement(schema);
248
+ return elem !== void 0 && walkForAsync(elem, target, visited);
249
+ }
250
+ if (isZodSchemaType(schema, "ZodTuple")) {
251
+ for (const it of getTupleItems(schema)) {
252
+ if (walkForAsync(it, target, visited)) return true;
253
+ }
254
+ return false;
255
+ }
256
+ if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
257
+ for (const opt of getUnionOptions(schema)) {
258
+ if (walkForAsync(opt, target, visited)) return true;
259
+ }
260
+ return false;
261
+ }
262
+ if (isZodSchemaType(schema, "ZodIntersection")) {
263
+ const left = getIntersectionLeft(schema);
264
+ if (left !== void 0 && walkForAsync(left, target, visited)) return true;
265
+ const right = getIntersectionRight(schema);
266
+ if (right !== void 0 && walkForAsync(right, target, visited)) return true;
267
+ return false;
268
+ }
269
+ if (isZodSchemaType(schema, "ZodRecord")) {
270
+ const keyType = getRecordKeyType(schema);
271
+ if (keyType !== void 0 && walkForAsync(keyType, target, visited)) return true;
272
+ const valueType = getRecordValueType(schema);
273
+ if (valueType !== void 0 && walkForAsync(valueType, target, visited)) return true;
274
+ return false;
275
+ }
276
+ if (isZodSchemaType(schema, "ZodSet")) {
277
+ const elem = getSetValueType(schema);
278
+ return elem !== void 0 && walkForAsync(elem, target, visited);
279
+ }
280
+ return false;
281
+ }
282
+ function unwrapPipeIn(schema) {
283
+ const def = readDef(schema);
284
+ return def?.in;
285
+ }
286
+ function unwrapPipeOut(schema) {
287
+ const def = readDef(schema);
288
+ return def?.out;
289
+ }
290
+ function unwrapLazy(schema) {
291
+ const def = readDef(schema);
292
+ const getter = def?.getter;
293
+ if (typeof getter !== "function") return void 0;
294
+ try {
295
+ return getter();
296
+ } catch {
297
+ return void 0;
298
+ }
299
+ }
300
+ function getLazyGetter(schema) {
301
+ const def = readDef(schema);
302
+ return typeof def?.getter === "function" ? def.getter : void 0;
303
+ }
304
+ function getLiteralValues(schema) {
305
+ const def = readDef(schema);
306
+ const v = def?.value;
307
+ if (Array.isArray(v)) return v;
308
+ if (v === void 0) return [];
309
+ return [v];
310
+ }
311
+ function getNativeEnumValues(schema) {
312
+ const def = readDef(schema);
313
+ return def?.values;
314
+ }
315
+ function getDefaultValue$1(schema) {
316
+ const def = readDef(schema);
317
+ const thunk = def?.defaultValue;
318
+ if (typeof thunk !== "function") return void 0;
319
+ try {
320
+ return thunk();
321
+ } catch {
322
+ return void 0;
323
+ }
324
+ }
325
+ function getCatchDefault(schema) {
326
+ const def = readDef(schema);
327
+ const cv = def?.catchValue;
328
+ if (typeof cv !== "function") return void 0;
329
+ try {
330
+ return cv({ error: null, input: void 0 });
331
+ } catch {
332
+ return void 0;
333
+ }
334
+ }
335
+ function hasCatchValue(schema) {
336
+ const def = readDef(schema);
337
+ return typeof def?.catchValue === "function";
338
+ }
339
+ function hasChecks(schema) {
340
+ const def = readDef(schema);
341
+ const checks = def?.checks;
342
+ return Array.isArray(checks) && checks.length > 0;
343
+ }
344
+ function hasContainerOrRootRefine(schema, seen) {
345
+ const visited = seen ?? /* @__PURE__ */ new WeakSet();
346
+ const candidate = schema;
347
+ if (typeof candidate !== "object" || candidate === null) return false;
348
+ if (visited.has(candidate)) return false;
349
+ visited.add(candidate);
350
+ if (isZodSchemaType(schema, "ZodEffects")) {
351
+ const inner = unwrapEffectsSource(schema);
352
+ if (inner === void 0) return false;
353
+ if (isContainerAfterWrapperPeel(inner)) return true;
354
+ return hasContainerOrRootRefine(inner, visited);
355
+ }
356
+ if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodReadonly")) {
357
+ const inner = unwrapInner(schema);
358
+ return inner !== void 0 && hasContainerOrRootRefine(inner, visited);
359
+ }
360
+ if (isZodSchemaType(schema, "ZodBranded")) {
361
+ const inner = unwrapBranded(schema);
362
+ return inner !== void 0 && hasContainerOrRootRefine(inner, visited);
363
+ }
364
+ if (isZodSchemaType(schema, "ZodLazy")) {
365
+ const inner = unwrapLazy(schema);
366
+ return inner !== void 0 && hasContainerOrRootRefine(inner, visited);
367
+ }
368
+ if (isZodSchemaType(schema, "ZodPipeline")) {
369
+ const inSide = unwrapPipeIn(schema);
370
+ if (inSide !== void 0 && hasContainerOrRootRefine(inSide, visited)) return true;
371
+ const outSide = unwrapPipeOut(schema);
372
+ if (outSide !== void 0 && hasContainerOrRootRefine(outSide, visited)) return true;
373
+ return false;
374
+ }
375
+ if (isZodSchemaType(schema, "ZodObject")) {
376
+ for (const sub of Object.values(getObjectShape(schema))) {
377
+ if (hasContainerOrRootRefine(sub, visited)) return true;
378
+ }
379
+ return false;
380
+ }
381
+ if (isZodSchemaType(schema, "ZodArray")) {
382
+ const elem = getArrayElement(schema);
383
+ return elem !== void 0 && hasContainerOrRootRefine(elem, visited);
384
+ }
385
+ if (isZodSchemaType(schema, "ZodTuple")) {
386
+ for (const it of getTupleItems(schema)) {
387
+ if (hasContainerOrRootRefine(it, visited)) return true;
388
+ }
389
+ return false;
390
+ }
391
+ if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
392
+ for (const opt of getUnionOptions(schema)) {
393
+ if (hasContainerOrRootRefine(opt, visited)) return true;
394
+ }
395
+ return false;
396
+ }
397
+ if (isZodSchemaType(schema, "ZodIntersection")) {
398
+ const left = getIntersectionLeft(schema);
399
+ if (left !== void 0 && hasContainerOrRootRefine(left, visited)) return true;
400
+ const right = getIntersectionRight(schema);
401
+ if (right !== void 0 && hasContainerOrRootRefine(right, visited)) return true;
402
+ return false;
403
+ }
404
+ if (isZodSchemaType(schema, "ZodRecord")) {
405
+ const keyType = getRecordKeyType(schema);
406
+ if (keyType !== void 0 && hasContainerOrRootRefine(keyType, visited)) return true;
407
+ const valueType = getRecordValueType(schema);
408
+ if (valueType !== void 0 && hasContainerOrRootRefine(valueType, visited)) return true;
409
+ return false;
410
+ }
411
+ if (isZodSchemaType(schema, "ZodSet")) {
412
+ const elem = getSetValueType(schema);
413
+ return elem !== void 0 && hasContainerOrRootRefine(elem, visited);
414
+ }
415
+ return false;
416
+ }
417
+ function isContainerAfterWrapperPeel(schema) {
418
+ let cur = schema;
419
+ for (let i = 0; i < MAX_UNWRAP_STEPS$1; i++) {
420
+ if (isZodSchemaType(cur, "ZodOptional") || isZodSchemaType(cur, "ZodNullable") || isZodSchemaType(cur, "ZodDefault") || isZodSchemaType(cur, "ZodCatch") || isZodSchemaType(cur, "ZodReadonly")) {
421
+ const inner = unwrapInner(cur);
422
+ if (inner === void 0) return false;
423
+ cur = inner;
424
+ } else if (isZodSchemaType(cur, "ZodBranded")) {
425
+ const inner = unwrapBranded(cur);
426
+ if (inner === void 0) return false;
427
+ cur = inner;
428
+ } else if (isZodSchemaType(cur, "ZodLazy")) {
429
+ const inner = unwrapLazy(cur);
430
+ if (inner === void 0) return false;
431
+ cur = inner;
432
+ } else {
433
+ break;
434
+ }
435
+ }
436
+ return isZodSchemaType(cur, "ZodObject") || isZodSchemaType(cur, "ZodArray") || isZodSchemaType(cur, "ZodTuple") || isZodSchemaType(cur, "ZodIntersection") || isZodSchemaType(cur, "ZodUnion") || isZodSchemaType(cur, "ZodDiscriminatedUnion") || isZodSchemaType(cur, "ZodRecord") || isZodSchemaType(cur, "ZodSet");
437
+ }
438
+
439
+ const UNSUPPORTED_TYPE_NAMES = /* @__PURE__ */ new Set(["ZodPromise", "ZodFunction", "ZodMap", "ZodSymbol"]);
440
+ function labelPath(path) {
441
+ return path.length === 0 ? "<root>" : path.join(".");
442
+ }
443
+ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
444
+ const typeName = getTypeName(schema);
445
+ if (typeName !== void 0 && UNSUPPORTED_TYPE_NAMES.has(typeName)) {
446
+ throw new UnsupportedSchemaError(
447
+ `[attaform/zod-v3] unsupported kind '${typeName}' at '${labelPath(path)}'`
448
+ );
449
+ }
450
+ if (isZodSchemaType(schema, "ZodObject")) {
451
+ for (const [key, sub] of Object.entries(getObjectShape(schema))) {
452
+ assertSupportedKinds(sub, [...path, key], lazyGetters);
453
+ }
454
+ return;
455
+ }
456
+ if (isZodSchemaType(schema, "ZodArray")) {
457
+ const inner = getArrayElement(schema);
458
+ if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
459
+ return;
460
+ }
461
+ if (isZodSchemaType(schema, "ZodSet")) {
462
+ const inner = getSetValueType(schema);
463
+ if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
464
+ return;
465
+ }
466
+ if (isZodSchemaType(schema, "ZodRecord")) {
467
+ const inner = getRecordValueType(schema);
468
+ if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
469
+ return;
470
+ }
471
+ if (isZodSchemaType(schema, "ZodTuple")) {
472
+ const items = getTupleItems(schema);
473
+ items.forEach((item, i) => assertSupportedKinds(item, [...path, String(i)], lazyGetters));
474
+ return;
475
+ }
476
+ if (isZodSchemaType(schema, "ZodUnion")) {
477
+ const options = getUnionOptions(schema);
478
+ options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
479
+ return;
480
+ }
481
+ if (isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
482
+ const options = getDiscriminatedOptions(schema);
483
+ options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
484
+ return;
485
+ }
486
+ if (isZodSchemaType(schema, "ZodIntersection")) {
487
+ const left = getIntersectionLeft(schema);
488
+ if (left) assertSupportedKinds(left, [...path, "left"], lazyGetters);
489
+ const right = getIntersectionRight(schema);
490
+ if (right) assertSupportedKinds(right, [...path, "right"], lazyGetters);
491
+ return;
492
+ }
493
+ if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodCatch")) {
494
+ const inner = unwrapInner(schema);
495
+ if (inner) assertSupportedKinds(inner, path, lazyGetters);
496
+ return;
497
+ }
498
+ if (isZodSchemaType(schema, "ZodBranded")) {
499
+ const inner = unwrapBranded(schema);
500
+ if (inner) assertSupportedKinds(inner, path, lazyGetters);
501
+ return;
502
+ }
503
+ if (isZodSchemaType(schema, "ZodEffects")) {
504
+ const inner = unwrapEffectsSource(schema);
505
+ if (inner) assertSupportedKinds(inner, path, lazyGetters);
506
+ return;
507
+ }
508
+ if (isZodSchemaType(schema, "ZodPipeline")) {
509
+ const inner = unwrapPipeIn(schema);
510
+ if (inner) assertSupportedKinds(inner, path, lazyGetters);
511
+ return;
512
+ }
513
+ if (isZodSchemaType(schema, "ZodLazy")) {
514
+ const getter = getLazyGetter(schema);
515
+ if (getter !== void 0 && lazyGetters.includes(getter)) return;
516
+ const inner = getter?.();
517
+ if (inner !== void 0) {
518
+ assertSupportedKinds(
519
+ inner,
520
+ path,
521
+ getter === void 0 ? lazyGetters : [...lazyGetters, getter]
522
+ );
523
+ }
524
+ return;
525
+ }
526
+ }
527
+
528
+ const cyclicSentinel = "<cyclic>";
529
+ function fingerprintZodSchema(schema) {
530
+ const cache = /* @__PURE__ */ new WeakMap();
531
+ const inProgress = /* @__PURE__ */ new WeakSet();
532
+ return visit(schema, cache, inProgress);
533
+ }
534
+ function visit(schema, cache, inProgress) {
535
+ const key = schema;
536
+ const cached = cache.get(key);
537
+ if (cached !== void 0) return cached;
538
+ if (inProgress.has(key)) return cyclicSentinel;
539
+ inProgress.add(key);
540
+ try {
541
+ const computed = computeFingerprint(schema, cache, inProgress);
542
+ cache.set(key, computed);
543
+ return computed;
544
+ } finally {
545
+ inProgress.delete(key);
546
+ }
547
+ }
548
+ function getDef(schema) {
549
+ return schema._def;
550
+ }
551
+ function computeFingerprint(schema, cache, inProgress) {
552
+ const def = getDef(schema);
553
+ const kind = def.typeName ?? "ZodUnknown";
554
+ const recurse = (child) => visit(child, cache, inProgress);
555
+ switch (kind) {
556
+ case "ZodString":
557
+ case "ZodNumber":
558
+ case "ZodBigInt":
559
+ case "ZodDate":
560
+ return `${kind}${formatChecks(def.checks)}`;
561
+ case "ZodBoolean":
562
+ case "ZodNull":
563
+ case "ZodUndefined":
564
+ case "ZodAny":
565
+ case "ZodUnknown":
566
+ case "ZodNaN":
567
+ case "ZodVoid":
568
+ case "ZodNever":
569
+ return kind;
570
+ case "ZodLiteral":
571
+ return `ZodLiteral:${canonicalStringify(def.value)}`;
572
+ case "ZodEnum": {
573
+ const values = Array.isArray(def.values) ? def.values : [];
574
+ const sorted = [...values].sort((a, b) => {
575
+ const as = String(a);
576
+ const bs = String(b);
577
+ return as < bs ? -1 : as > bs ? 1 : 0;
578
+ });
579
+ return `ZodEnum:${canonicalStringify(sorted)}`;
580
+ }
581
+ case "ZodNativeEnum": {
582
+ const values = def.values && typeof def.values === "object" && !Array.isArray(def.values) ? Object.values(def.values) : [];
583
+ const sorted = [...values].sort((a, b) => {
584
+ const as = String(a);
585
+ const bs = String(b);
586
+ return as < bs ? -1 : as > bs ? 1 : 0;
587
+ });
588
+ return `ZodNativeEnum:${canonicalStringify(sorted)}`;
589
+ }
590
+ case "ZodObject": {
591
+ const shape = readShapeSafely(def);
592
+ const sortedEntries = Object.entries(shape).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${recurse(v)}`);
593
+ return `ZodObject{${sortedEntries.join(",")}}${formatChecks(def.checks)}`;
594
+ }
595
+ case "ZodArray":
596
+ return `ZodArray[${def.type === void 0 ? "?" : recurse(def.type)}]${formatChecks(def.checks)}`;
597
+ case "ZodTuple": {
598
+ const items = def.items ?? [];
599
+ return `ZodTuple[${items.map(recurse).join(",")}]`;
600
+ }
601
+ case "ZodRecord": {
602
+ const keyPart = def.keyType === void 0 ? "?" : recurse(def.keyType);
603
+ const valuePart = def.valueType === void 0 ? "?" : recurse(def.valueType);
604
+ return `ZodRecord<${keyPart},${valuePart}>`;
605
+ }
606
+ case "ZodUnion": {
607
+ const options = (def.options ?? []).map(recurse).sort();
608
+ return `ZodUnion(${options.join("|")})`;
609
+ }
610
+ case "ZodDiscriminatedUnion": {
611
+ const disc = def.discriminator ?? "?";
612
+ const options = (def.options ?? []).map(recurse).sort();
613
+ return `ZodDiscriminatedUnion[${JSON.stringify(disc)}](${options.join("|")})`;
614
+ }
615
+ case "ZodOptional": {
616
+ const inner = def.innerType;
617
+ return inner === void 0 ? "ZodOptional(?)" : `ZodOptional(${recurse(inner)})`;
618
+ }
619
+ case "ZodNullable": {
620
+ const inner = def.innerType;
621
+ return inner === void 0 ? "ZodNullable(?)" : `ZodNullable(${recurse(inner)})`;
622
+ }
623
+ case "ZodDefault": {
624
+ const inner = def.innerType;
625
+ return `ZodDefault[${defaultFactoryRepr(def.defaultValue)}](${inner === void 0 ? "?" : recurse(inner)})`;
626
+ }
627
+ case "ZodReadonly": {
628
+ const inner = def.innerType;
629
+ return inner === void 0 ? "ZodReadonly(?)" : `ZodReadonly(${recurse(inner)})`;
630
+ }
631
+ case "ZodEffects": {
632
+ const effectType = def.effect?.type ?? "effect";
633
+ const inner = def.schema;
634
+ return `ZodEffects:${effectType}:fn:*(${inner === void 0 ? "?" : recurse(inner)})`;
635
+ }
636
+ case "ZodPipeline": {
637
+ const inner = def.in ?? def.out;
638
+ return inner === void 0 ? "ZodPipeline(?)" : `ZodPipeline(${recurse(inner)})`;
639
+ }
640
+ case "ZodCatch": {
641
+ const inner = def.innerType ?? def.schema;
642
+ const catchRepr = defaultFactoryRepr(def.catchValue);
643
+ return `ZodCatch[${catchRepr}](${inner === void 0 ? "?" : recurse(inner)})`;
644
+ }
645
+ case "ZodLazy": {
646
+ const resolve = def.getter;
647
+ if (typeof resolve !== "function") return "ZodLazy(?)";
648
+ try {
649
+ const inner = resolve();
650
+ return `ZodLazy(${recurse(inner)})`;
651
+ } catch {
652
+ return "ZodLazy(?)";
653
+ }
654
+ }
655
+ case "ZodIntersection": {
656
+ const leftPart = def.left === void 0 ? "?" : recurse(def.left);
657
+ const rightPart = def.right === void 0 ? "?" : recurse(def.right);
658
+ const parts = [leftPart, rightPart].sort();
659
+ return `ZodIntersection(${parts.join("&")})`;
660
+ }
661
+ case "ZodSet": {
662
+ const inner = def.valueType;
663
+ return inner === void 0 ? "ZodSet(?)" : `ZodSet<${recurse(inner)}>${formatChecks(def.checks)}`;
664
+ }
665
+ case "ZodBranded": {
666
+ const inner = def.type;
667
+ return inner === void 0 ? "ZodBranded(?)" : `ZodBranded(${recurse(inner)})`;
668
+ }
669
+ // Structural opacity — schemas whose runtime behaviour isn't
670
+ // introspectable via `_def` fall here. Still distinguishable
671
+ // from other kinds by the returned string.
672
+ case "ZodPromise":
673
+ case "ZodFunction":
674
+ case "ZodMap":
675
+ case "ZodSymbol":
676
+ default:
677
+ return `${kind}:*`;
678
+ }
679
+ }
680
+ function readShapeSafely(def) {
681
+ if (typeof def.shape !== "function") return {};
682
+ try {
683
+ return def.shape();
684
+ } catch {
685
+ return {};
686
+ }
687
+ }
688
+ function defaultFactoryRepr(factory) {
689
+ if (typeof factory !== "function") return "none";
690
+ let first;
691
+ let second;
692
+ try {
693
+ first = factory();
694
+ second = factory();
695
+ } catch {
696
+ return "fn:*";
697
+ }
698
+ if (!Object.is(first, second)) return "fn:*";
699
+ if (typeof first === "function") return "fn:*";
700
+ return canonicalStringify(first);
701
+ }
702
+ function formatChecks(checks) {
703
+ if (!Array.isArray(checks) || checks.length === 0) return "";
704
+ const parts = checks.map((c) => canonicalStringify(c)).sort();
705
+ return `[${parts.join(";")}]`;
706
+ }
707
+ function canonicalStringify(value, seen = /* @__PURE__ */ new WeakSet()) {
708
+ if (value === null) return "null";
709
+ if (value === void 0) return "undefined";
710
+ const t = typeof value;
711
+ if (t === "string") return JSON.stringify(value);
712
+ if (t === "number" || t === "boolean") return String(value);
713
+ if (t === "bigint") return `${String(value)}n`;
714
+ if (t === "function") return "fn:*";
715
+ if (t === "symbol") return "symbol:*";
716
+ if (Array.isArray(value)) {
717
+ if (seen.has(value)) return "<cyclic>";
718
+ seen.add(value);
719
+ try {
720
+ return `[${value.map((v) => canonicalStringify(v, seen)).join(",")}]`;
721
+ } finally {
722
+ seen.delete(value);
723
+ }
724
+ }
725
+ if (t === "object") {
726
+ const obj = value;
727
+ if (seen.has(obj)) return "<cyclic>";
728
+ seen.add(obj);
729
+ try {
730
+ if (value instanceof Date) return `date:${value.getTime()}`;
731
+ if (value instanceof RegExp) return `regex:${String(value)}`;
732
+ const entries = Object.entries(obj).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonicalStringify(v, seen)}`);
733
+ return `{${entries.join(",")}}`;
734
+ } finally {
735
+ seen.delete(obj);
736
+ }
737
+ }
738
+ return "unknown";
739
+ }
740
+
741
+ const V3_INTROSPECTOR = {
742
+ kindOf: (schema) => kindOf(schema),
743
+ getObjectShape: (schema) => getObjectShape(schema),
744
+ getTupleItems: (schema) => getTupleItems(schema),
745
+ getDiscriminatedOptions: (schema) => getDiscriminatedOptions(schema),
746
+ getDiscriminator: (schema) => getDiscriminator(schema),
747
+ getLiteralValues: (schema) => getLiteralValues(schema),
748
+ isPreprocessNode: (schema) => isPreprocessNode(schema),
749
+ isCoercePrimitive: (schema) => isCoercePrimitive(schema),
750
+ containsAsyncRefine: (schema) => containsAsyncRefine(schema),
751
+ containsAsyncTransform: (schema) => containsAsyncTransform(schema),
752
+ hasContainerOrRootRefine: (schema) => hasContainerOrRootRefine(schema),
753
+ // Walker accessors (D2 / D3 / D5).
754
+ getArrayElement: (schema) => getArrayElement(schema),
755
+ getSetValueType: (schema) => getSetValueType(schema),
756
+ getRecordKeyType: (schema) => getRecordKeyType(schema),
757
+ getRecordValueType: (schema) => getRecordValueType(schema),
758
+ getUnionOptions: (schema) => getUnionOptions(schema),
759
+ getIntersectionLeft: (schema) => getIntersectionLeft(schema),
760
+ getIntersectionRight: (schema) => getIntersectionRight(schema),
761
+ getEnumValues: (schema) => {
762
+ if (!isZodSchemaType(schema, "ZodEnum")) return [];
763
+ return schema.options;
764
+ },
765
+ getNativeEnumValues: (schema) => getNativeEnumValues(schema),
766
+ unwrapInner: (schema) => unwrapInner(schema),
767
+ unwrapBranded: (schema) => unwrapBranded(schema),
768
+ unwrapEffectsSource: (schema) => unwrapEffectsSource(schema),
769
+ unwrapPipeIn: (schema) => unwrapPipeIn(schema),
770
+ unwrapPipeOut: (schema) => unwrapPipeOut(schema),
771
+ unwrapLazy: (schema) => unwrapLazy(schema),
772
+ getLazyGetter: (schema) => getLazyGetter(schema),
773
+ getDefaultValue: (schema) => getDefaultValue$1(schema),
774
+ getCatchDefault: (schema) => getCatchDefault(schema),
775
+ hasCatchValue: (schema) => hasCatchValue(schema)
776
+ };
777
+
778
+ function slimPrimitivesV3(schema) {
779
+ return new Set(slimPrimitivesWalk(schema, V3_INTROSPECTOR, 64));
780
+ }
781
+
782
+ function stripAsyncChecks(schema) {
783
+ const seen = /* @__PURE__ */ new WeakSet();
784
+ function recurse(s) {
785
+ const candidate = s;
786
+ if (typeof candidate !== "object" || candidate === null) return s;
787
+ if (seen.has(candidate)) return s;
788
+ seen.add(candidate);
789
+ if (isZodSchemaType(s, "ZodEffects")) {
790
+ const inner = unwrapEffectsSource(s);
791
+ return inner === void 0 ? s : recurse(inner);
792
+ }
793
+ if (isZodSchemaType(s, "ZodOptional")) {
794
+ const inner = unwrapInner(s);
795
+ return inner === void 0 ? s : z.optional(recurse(inner));
796
+ }
797
+ if (isZodSchemaType(s, "ZodNullable")) {
798
+ const inner = unwrapInner(s);
799
+ return inner === void 0 ? s : z.nullable(recurse(inner));
800
+ }
801
+ if (isZodSchemaType(s, "ZodDefault")) {
802
+ const inner = unwrapInner(s);
803
+ if (inner === void 0) return s;
804
+ const def = getDefaultValue$1(s);
805
+ return recurse(inner).default(def);
806
+ }
807
+ if (isZodSchemaType(s, "ZodCatch")) {
808
+ const inner = unwrapInner(s);
809
+ if (inner === void 0) return s;
810
+ const fallback = getCatchDefault(s);
811
+ return recurse(inner).catch(fallback);
812
+ }
813
+ if (isZodSchemaType(s, "ZodReadonly")) {
814
+ const inner = unwrapInner(s);
815
+ return inner === void 0 ? s : recurse(inner).readonly();
816
+ }
817
+ if (isZodSchemaType(s, "ZodBranded")) {
818
+ const inner = unwrapBranded(s);
819
+ return inner === void 0 ? s : recurse(inner);
820
+ }
821
+ if (isZodSchemaType(s, "ZodLazy")) {
822
+ const inner = unwrapLazy(s);
823
+ if (inner === void 0) return s;
824
+ const stripped = recurse(inner);
825
+ return z.lazy(() => stripped);
826
+ }
827
+ if (isZodSchemaType(s, "ZodPipeline")) {
828
+ const inSide = unwrapPipeIn(s);
829
+ return inSide === void 0 ? s : recurse(inSide);
830
+ }
831
+ if (isZodSchemaType(s, "ZodObject")) {
832
+ const shape = getObjectShape(s);
833
+ const next = {};
834
+ for (const [k, v] of Object.entries(shape)) {
835
+ next[k] = recurse(v);
836
+ }
837
+ return carryObjectChecks(z.object(next), s);
838
+ }
839
+ if (isZodSchemaType(s, "ZodArray")) {
840
+ const element = getArrayElement(s);
841
+ if (element === void 0) return s;
842
+ return carryArrayChecks(z.array(recurse(element)), s);
843
+ }
844
+ if (isZodSchemaType(s, "ZodSet")) {
845
+ const valueType = getSetValueType(s);
846
+ if (valueType === void 0) return s;
847
+ return carrySetChecks(z.set(recurse(valueType)), s);
848
+ }
849
+ if (isZodSchemaType(s, "ZodTuple")) {
850
+ const items = getTupleItems(s).map(recurse);
851
+ const rebuilt = z.tuple(items);
852
+ return rebuilt;
853
+ }
854
+ if (isZodSchemaType(s, "ZodRecord")) {
855
+ const keyType = getRecordKeyType(s);
856
+ const valueType = getRecordValueType(s);
857
+ if (valueType === void 0) return s;
858
+ const next = recurse(valueType);
859
+ return keyType === void 0 ? z.record(next) : z.record(keyType, next);
860
+ }
861
+ if (isZodSchemaType(s, "ZodUnion")) {
862
+ const options = getUnionOptions(s).map(recurse);
863
+ return z.union(options);
864
+ }
865
+ if (isZodSchemaType(s, "ZodDiscriminatedUnion")) {
866
+ const discKey = getDiscriminator(s);
867
+ const options = getDiscriminatedOptions(s).map(
868
+ (o) => recurse(o)
869
+ );
870
+ if (discKey === void 0 || options.length === 0) return s;
871
+ return z.discriminatedUnion(
872
+ discKey,
873
+ options
874
+ );
875
+ }
876
+ if (isZodSchemaType(s, "ZodIntersection")) {
877
+ const left = getIntersectionLeft(s);
878
+ const right = getIntersectionRight(s);
879
+ if (left === void 0 || right === void 0) return s;
880
+ return z.intersection(recurse(left), recurse(right));
881
+ }
882
+ return s;
883
+ }
884
+ return recurse(schema);
885
+ }
886
+ function readArrayLength(schema, key) {
887
+ const def = schema._def;
888
+ const slot = def?.[key];
889
+ if (slot === null || slot === void 0) return void 0;
890
+ return slot;
891
+ }
892
+ function readSetSize(schema, key) {
893
+ const def = schema._def;
894
+ const slot = def?.[key];
895
+ if (slot === null || slot === void 0) return void 0;
896
+ return slot;
897
+ }
898
+ function readObjectUnknownKeys(schema) {
899
+ const def = schema._def;
900
+ const v = def?.unknownKeys;
901
+ if (v === "strict" || v === "passthrough" || v === "strip") return v;
902
+ return void 0;
903
+ }
904
+ function readObjectCatchall(schema) {
905
+ const def = schema._def;
906
+ const ca = def?.catchall;
907
+ if (ca === void 0 || ca === null) return void 0;
908
+ if (typeof ca === "object" && ca._def?.typeName === "ZodNever") {
909
+ return void 0;
910
+ }
911
+ return ca;
912
+ }
913
+ function carryArrayChecks(rebuilt, original) {
914
+ let next = rebuilt;
915
+ const min = readArrayLength(original, "minLength");
916
+ if (min !== void 0) next = next.min(min.value, min.message);
917
+ const max = readArrayLength(original, "maxLength");
918
+ if (max !== void 0) next = next.max(max.value, max.message);
919
+ const exact = readArrayLength(original, "exactLength");
920
+ if (exact !== void 0) next = next.length(exact.value, exact.message);
921
+ return next;
922
+ }
923
+ function carrySetChecks(rebuilt, original) {
924
+ let next = rebuilt;
925
+ const min = readSetSize(original, "minSize");
926
+ if (min !== void 0) next = next.min(min.value, min.message);
927
+ const max = readSetSize(original, "maxSize");
928
+ if (max !== void 0) next = next.max(max.value, max.message);
929
+ return next;
930
+ }
931
+ function carryObjectChecks(rebuilt, original) {
932
+ let next = rebuilt;
933
+ const unknownKeys = readObjectUnknownKeys(original);
934
+ if (unknownKeys === "strict") next = next.strict();
935
+ else if (unknownKeys === "passthrough") next = next.passthrough();
936
+ const catchall = readObjectCatchall(original);
937
+ if (catchall !== void 0) next = next.catchall(catchall);
938
+ return next;
939
+ }
940
+
941
+ const PATH_SEPARATOR = ".";
942
+ const MAX_UNWRAP_STEPS = 64;
943
+ function isPrimitive(input) {
944
+ const type = typeof input;
945
+ if (type === "string" || type === "number" || type === "boolean" || type === "bigint" || type === "undefined")
946
+ return true;
947
+ return input === null;
948
+ }
949
+ function constraintsAreSlimValid(slimSchema, constraints) {
950
+ try {
951
+ return slimSchema.safeParse(constraints).success;
952
+ } catch {
953
+ return false;
954
+ }
955
+ }
956
+ function mergeDeepV3(base, override) {
957
+ if (override === void 0) return base;
958
+ if (!isPlainRecord(override)) return override;
959
+ if (!isPlainRecord(base)) return override;
960
+ const result = { ...base };
961
+ for (const key of Object.keys(override)) {
962
+ const oVal = override[key];
963
+ const bVal = base[key];
964
+ if (isPlainRecord(oVal) && isPlainRecord(bVal)) {
965
+ result[key] = mergeDeepV3(bVal, oVal);
966
+ } else {
967
+ result[key] = oVal;
968
+ }
969
+ }
970
+ return result;
971
+ }
972
+ let warnedZodCodeMissing = false;
973
+ function zodAdapter(zodSchema) {
974
+ assertSupportedKinds(zodSchema);
975
+ const [_strippedRoot] = stripRootSchema(zodSchema, {
976
+ stripDefaultValues: true,
977
+ stripNullable: true,
978
+ stripOptional: true,
979
+ stripZodEffects: true,
980
+ stripZodRefinements: true
981
+ });
982
+ if (!isZodSchemaType(_strippedRoot, "ZodObject")) {
983
+ const name = getTypeName(_strippedRoot);
984
+ throw new Error(`ZodAdapter: expected ZodObject, got ${name}`);
985
+ }
986
+ return (formKey, options) => createAbstractSchema(
987
+ zodSchema,
988
+ V3_INTROSPECTOR,
989
+ buildV3Services(),
990
+ formKey,
991
+ options
992
+ );
993
+ }
994
+ function buildV3Services() {
995
+ return {
996
+ fingerprint: (schema) => fingerprintZodSchema(schema),
997
+ getNestedSchemasAtPath: (schema, path, maxRecursionDepth) => getNestedZodSchemasAtPath(schema, path, maxRecursionDepth),
998
+ // v3 pre-strips refinements / defaults / wrappers off the root for
999
+ // slim-mode walks — `getSlimPrimitiveTypesAtPath` and
1000
+ // `getSchemasAtPath` both consume this variant so the yielded
1001
+ // candidates reflect the slim shape.
1002
+ getNestedSchemasInSlimMode: (schema, path, maxRecursionDepth) => getNestedSchemasInSlimModeV3(schema, path, maxRecursionDepth),
1003
+ slimPrimitivesOf: (schema, _maxRecursionDepth) => slimPrimitivesV3(schema),
1004
+ deriveDefault: (schema, useDefault, _maxRecursionDepth, formKey) => getDefaultValuesFromZodSchema(schema, useDefault, formKey),
1005
+ runStrictGetDefaults: (schema, config, formKey, maxRecursionDepth) => runStrictGetDefaultsV3(schema, config, formKey, maxRecursionDepth),
1006
+ unwrapStructuralWrappers: (schema) => unwrapStructuralLeafV3(schema),
1007
+ unwrapToDiscriminatedUnion: (schema) => unwrapToDiscriminatedUnion(schema),
1008
+ peelAllWrappers: (schema) => peelAllV3Wrappers(schema),
1009
+ isLeafRequired: (schema) => isLeafRequiredV3(schema),
1010
+ resolveFieldMetaAtPath: (schema, path, maxRecursionDepth) => resolveFieldMetaAtPathV3(schema, path, maxRecursionDepth),
1011
+ issuesToValidationErrors: (issues, formKey) => zodIssuesToValidationErrors(issues, formKey),
1012
+ safeParseSync: (schema, data) => {
1013
+ const result = schema.safeParse(data);
1014
+ return result.success ? { success: true, data: result.data } : { success: false, issues: result.error.issues };
1015
+ },
1016
+ safeParseAsync: async (schema, data) => {
1017
+ const result = await schema.safeParseAsync(data);
1018
+ return result.success ? { success: true, data: result.data } : { success: false, issues: result.error.issues };
1019
+ },
1020
+ // v3 returns the full recursive AbstractSchema for sub-schemas (the
1021
+ // historical shape) — `getSchemasAtPath` consumers may probe any
1022
+ // method on the result. The factory call rebuilds the full surface
1023
+ // against the sub-schema with its own per-form caches.
1024
+ makeSubSchema: (sub, formKey, maxRecursionDepth) => createAbstractSchema(
1025
+ sub,
1026
+ V3_INTROSPECTOR,
1027
+ buildV3Services(),
1028
+ formKey,
1029
+ { maxRecursionDepth }
1030
+ )
1031
+ };
1032
+ }
1033
+ function zodIssuesToValidationErrors(issues, formKey) {
1034
+ const validationErrors = [];
1035
+ for (const issue of issues) {
1036
+ let code;
1037
+ if (typeof issue.code === "string" && issue.code.length > 0) {
1038
+ code = `zod:${issue.code}`;
1039
+ } else {
1040
+ code = "zod:unknown";
1041
+ if (__DEV__ && !warnedZodCodeMissing) {
1042
+ warnedZodCodeMissing = true;
1043
+ console.warn(
1044
+ "[attaform] zod-v3 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."
1045
+ );
1046
+ }
1047
+ }
1048
+ validationErrors.push({
1049
+ message: issue.message,
1050
+ // `ValidationError.path` is `(string | number)[]` per the
1051
+ // public type. v3's `issue.path` is the same in the standard
1052
+ // case, but a custom check via `ctx.addIssue({ path: [...] })`
1053
+ // can smuggle a Symbol through — the public surface promised
1054
+ // strings/numbers, so coerce defensively to keep the contract.
1055
+ // Mirrors v4's behaviour at the same site.
1056
+ //
1057
+ // Adapter-side paths stay schema-relative — the validation
1058
+ // pipeline in `create-form-store.ts` prepends the parent path
1059
+ // to absolutise, then routes form-level (absolute path length 0)
1060
+ // entries to the empty-string bucket at storage time.
1061
+ path: coercePathSegments(issue.path),
1062
+ formKey,
1063
+ code
1064
+ });
1065
+ }
1066
+ return validationErrors;
1067
+ }
1068
+ function coercePathSegments(path) {
1069
+ const out = [];
1070
+ for (const seg of path) {
1071
+ out.push(typeof seg === "number" ? seg : typeof seg === "string" ? seg : String(seg));
1072
+ }
1073
+ return out;
1074
+ }
1075
+ function getNestedZodSchemasAtPath(schema, segments, maxRecursionDepth) {
1076
+ if (segments.length === 0) return [schema];
1077
+ return walkPathSegments(schema, segments.map(String), V3_INTROSPECTOR, maxRecursionDepth, 0);
1078
+ }
1079
+ function unwrapStructuralLeafV3(schema) {
1080
+ let current = schema;
1081
+ for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
1082
+ if (!(isZodSchemaType(current, "ZodOptional") || isZodSchemaType(current, "ZodNullable"))) {
1083
+ break;
1084
+ }
1085
+ const inner = unwrapInner(current);
1086
+ if (!inner) return current;
1087
+ if (!isStructuralV3Kind(inner)) break;
1088
+ current = inner;
1089
+ }
1090
+ return current;
1091
+ }
1092
+ function isStructuralV3Kind(schema) {
1093
+ return isZodSchemaType(schema, "ZodObject") || isZodSchemaType(schema, "ZodArray") || isZodSchemaType(schema, "ZodRecord") || isZodSchemaType(schema, "ZodTuple") || isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion") || // Wrappers that themselves resolve to a structural type — keep
1094
+ // peeling at the next iteration.
1095
+ isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodEffects") || // Newer transparent wrappers (v3.23+). Each wraps a single inner
1096
+ // schema with no structural impact — `peelV3Wrappers` resolves them.
1097
+ isZodSchemaType(schema, "ZodPipeline") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodBranded");
1098
+ }
1099
+ function peelV3Wrappers(schema) {
1100
+ let current = schema;
1101
+ for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
1102
+ if (isZodSchemaType(current, "ZodOptional") || isZodSchemaType(current, "ZodNullable") || isZodSchemaType(current, "ZodDefault") || isZodSchemaType(current, "ZodReadonly")) {
1103
+ const inner = unwrapInner(current);
1104
+ if (!inner) return current;
1105
+ current = inner;
1106
+ continue;
1107
+ }
1108
+ if (isZodSchemaType(current, "ZodEffects")) {
1109
+ const inner = unwrapEffectsSource(current);
1110
+ if (!inner) return current;
1111
+ current = inner;
1112
+ continue;
1113
+ }
1114
+ if (isZodSchemaType(current, "ZodPipeline")) {
1115
+ const inner = unwrapPipeIn(current);
1116
+ if (!inner) return current;
1117
+ current = inner;
1118
+ continue;
1119
+ }
1120
+ if (isZodSchemaType(current, "ZodBranded")) {
1121
+ const inner = unwrapBranded(current);
1122
+ if (!inner) return current;
1123
+ current = inner;
1124
+ continue;
1125
+ }
1126
+ break;
1127
+ }
1128
+ return current;
1129
+ }
1130
+ function isLeafRequiredV3(schema, depth = 0) {
1131
+ if (depth > MAX_UNWRAP_STEPS) return true;
1132
+ if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodUndefined") || isZodSchemaType(schema, "ZodNull") || isZodSchemaType(schema, "ZodVoid")) {
1133
+ return false;
1134
+ }
1135
+ if (isZodSchemaType(schema, "ZodReadonly")) {
1136
+ const inner = unwrapInner(schema);
1137
+ return inner === void 0 ? true : isLeafRequiredV3(inner, depth + 1);
1138
+ }
1139
+ if (isZodSchemaType(schema, "ZodBranded")) {
1140
+ const inner = unwrapBranded(schema);
1141
+ return inner === void 0 ? true : isLeafRequiredV3(inner, depth + 1);
1142
+ }
1143
+ if (isZodSchemaType(schema, "ZodPipeline")) {
1144
+ const inner = unwrapPipeIn(schema);
1145
+ return inner === void 0 ? true : isLeafRequiredV3(inner, depth + 1);
1146
+ }
1147
+ if (isZodSchemaType(schema, "ZodEffects")) {
1148
+ const inner = unwrapEffectsSource(schema);
1149
+ return inner === void 0 ? true : isLeafRequiredV3(inner, depth + 1);
1150
+ }
1151
+ if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
1152
+ const options = getUnionOptions(schema);
1153
+ if (options.length === 0) return true;
1154
+ return options.every((opt) => isLeafRequiredV3(opt, depth + 1));
1155
+ }
1156
+ if (isZodSchemaType(schema, "ZodIntersection")) {
1157
+ const left = getIntersectionLeft(schema);
1158
+ const right = getIntersectionRight(schema);
1159
+ const leftReq = left === void 0 ? true : isLeafRequiredV3(left, depth + 1);
1160
+ const rightReq = right === void 0 ? true : isLeafRequiredV3(right, depth + 1);
1161
+ return leftReq || rightReq;
1162
+ }
1163
+ return true;
1164
+ }
1165
+ function unwrapToDiscriminatedUnion(schema, depth = 0) {
1166
+ if (depth > MAX_UNWRAP_STEPS) return void 0;
1167
+ let currentSchema = schema;
1168
+ for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
1169
+ if (isZodSchemaType(currentSchema, "ZodDiscriminatedUnion")) {
1170
+ return currentSchema;
1171
+ }
1172
+ if (isZodSchemaType(currentSchema, "ZodDefault") || isZodSchemaType(currentSchema, "ZodOptional") || isZodSchemaType(currentSchema, "ZodNullable") || isZodSchemaType(currentSchema, "ZodCatch")) {
1173
+ const inner = unwrapInner(currentSchema);
1174
+ if (!inner) return void 0;
1175
+ currentSchema = inner;
1176
+ continue;
1177
+ }
1178
+ if (isZodSchemaType(currentSchema, "ZodReadonly")) {
1179
+ const inner = unwrapInner(currentSchema);
1180
+ if (!inner) return void 0;
1181
+ currentSchema = inner;
1182
+ continue;
1183
+ }
1184
+ if (isZodSchemaType(currentSchema, "ZodBranded")) {
1185
+ const inner = unwrapBranded(currentSchema);
1186
+ if (!inner) return void 0;
1187
+ currentSchema = inner;
1188
+ continue;
1189
+ }
1190
+ if (isZodSchemaType(currentSchema, "ZodPipeline")) {
1191
+ const inner = unwrapPipeIn(currentSchema);
1192
+ if (!inner) return void 0;
1193
+ currentSchema = inner;
1194
+ continue;
1195
+ }
1196
+ if (isZodSchemaType(currentSchema, "ZodEffects")) {
1197
+ const inner = unwrapEffectsSource(currentSchema);
1198
+ if (!inner) return void 0;
1199
+ currentSchema = inner;
1200
+ continue;
1201
+ }
1202
+ if (isZodSchemaType(currentSchema, "ZodIntersection")) {
1203
+ const left = getIntersectionLeft(currentSchema);
1204
+ const right = getIntersectionRight(currentSchema);
1205
+ const leftDU = left ? unwrapToDiscriminatedUnion(left, depth + 1) : void 0;
1206
+ const rightDU = right ? unwrapToDiscriminatedUnion(right, depth + 1) : void 0;
1207
+ if (leftDU !== void 0 && rightDU !== void 0) {
1208
+ return leftDU === rightDU ? leftDU : void 0;
1209
+ }
1210
+ return leftDU ?? rightDU;
1211
+ }
1212
+ return void 0;
1213
+ }
1214
+ return void 0;
1215
+ }
1216
+ function getDefaultValue(expected, context) {
1217
+ const discriminatorContext = context.discriminator;
1218
+ if (discriminatorContext.isDiscriminatorKey) {
1219
+ if (!discriminatorContext.schema) {
1220
+ throw new Error("discriminatorContext.schema unspecified");
1221
+ }
1222
+ if (!isZodSchemaType(discriminatorContext.schema, "ZodDiscriminatedUnion")) {
1223
+ throw new TypeError(
1224
+ "Programming error: discriminatorContext.schema is not a ZodDiscriminatedUnion schema."
1225
+ );
1226
+ }
1227
+ const optionDiscriminator = getSchemaByDiscriminatorKey(
1228
+ discriminatorContext.schema);
1229
+ if (!optionDiscriminator) {
1230
+ throw new Error("ZodDiscriminatedUnion: default option not found");
1231
+ }
1232
+ return getDefaultValuesFromZodSchema(
1233
+ optionDiscriminator,
1234
+ discriminatorContext.useDefaultSchemaValues,
1235
+ context.formKey
1236
+ );
1237
+ }
1238
+ if (expected === "string") return "";
1239
+ if (expected === "number") return 0;
1240
+ if (expected === "array") return [];
1241
+ if (expected === "boolean") return false;
1242
+ if (expected === "bigint") return 0n;
1243
+ if (expected === "float") return 0;
1244
+ if (expected === "integer") return 0;
1245
+ if (expected === "null") return null;
1246
+ if (expected === "object") return {};
1247
+ if (expected === "set") return /* @__PURE__ */ new Set();
1248
+ if (expected === "date") return /* @__PURE__ */ new Date();
1249
+ if (expected === "undefined") return void 0;
1250
+ if (expected === "unknown") return void 0;
1251
+ if (expected === "nan") return Number("nan");
1252
+ return void 0;
1253
+ }
1254
+ function getDefaultValuesFromZodSchema(formSchema, useDefaultSchemaValues, formKey) {
1255
+ return deriveDefaultWalk(formSchema, useDefaultSchemaValues, V3_INTROSPECTOR, 64, {
1256
+ unsupportedKindFallback: (schema) => {
1257
+ console.warn(
1258
+ `[attaform] zod-v3 adapter: unsupported schema kind '${schema.constructor?.name ?? "unknown"}' on form '${formKey}'. Defaulting the field to null. Use a supported zod kind (object/array/record/string/number/etc.) at this path.`
1259
+ );
1260
+ return null;
1261
+ },
1262
+ // v3 historically surfaces the `.catch(v)` fallback even when
1263
+ // `useDefaultSchemaValues=false`. Pinned by
1264
+ // `test/adapters/zod-v3/wrappers.test.ts` ('surfaces the catch
1265
+ // fallback even when useDefaultSchemaValues is false').
1266
+ catchOnUseDefaultFalse: "preserveCatch"
1267
+ });
1268
+ }
1269
+ function getSchemaByDiscriminatorKey(unionSchema, key) {
1270
+ if (!isZodSchemaType(unionSchema, "ZodDiscriminatedUnion")) {
1271
+ throw new TypeError("Provided schema is not a discriminated union.");
1272
+ }
1273
+ {
1274
+ const options = getDiscriminatedOptions(unionSchema);
1275
+ if (!options.length) {
1276
+ throw new TypeError("Provided ZodDiscriminatedUnion does not have any options");
1277
+ }
1278
+ return options[0];
1279
+ }
1280
+ }
1281
+ function stripRefinements(schema) {
1282
+ function _stripRefinements(_schema, depth) {
1283
+ if (depth >= MAX_UNWRAP_STEPS) return _schema;
1284
+ if (isZodSchemaType(_schema, "ZodString") && hasChecks(_schema)) {
1285
+ return z.string();
1286
+ }
1287
+ if (isZodSchemaType(_schema, "ZodNumber") && hasChecks(_schema)) {
1288
+ return z.number();
1289
+ }
1290
+ if (isZodSchemaType(_schema, "ZodArray")) {
1291
+ const inner = getArrayElement(_schema);
1292
+ if (!inner) return _schema;
1293
+ return z.array(_stripRefinements(inner, depth + 1));
1294
+ }
1295
+ if (isZodSchemaType(_schema, "ZodObject")) {
1296
+ const strippedShape = Object.fromEntries(
1297
+ Object.entries(getObjectShape(_schema)).map(([key, value]) => [
1298
+ key,
1299
+ _stripRefinements(value, depth + 1)
1300
+ ])
1301
+ );
1302
+ return z.object(strippedShape);
1303
+ }
1304
+ if (isZodSchemaType(_schema, "ZodEffects")) {
1305
+ const inner = unwrapEffectsSource(_schema);
1306
+ if (!inner) return _schema;
1307
+ return _stripRefinements(inner, depth + 1);
1308
+ }
1309
+ if (isZodSchemaType(_schema, "ZodOptional")) {
1310
+ const inner = unwrapInner(_schema);
1311
+ if (!inner) return _schema;
1312
+ return z.optional(_stripRefinements(inner, depth + 1));
1313
+ }
1314
+ if (isZodSchemaType(_schema, "ZodNullable")) {
1315
+ const inner = unwrapInner(_schema);
1316
+ if (!inner) return _schema;
1317
+ return z.nullable(_stripRefinements(inner, depth + 1));
1318
+ }
1319
+ if (isZodSchemaType(_schema, "ZodReadonly")) {
1320
+ const inner = unwrapInner(_schema);
1321
+ if (!inner) return _schema;
1322
+ return _stripRefinements(inner, depth + 1);
1323
+ }
1324
+ if (isZodSchemaType(_schema, "ZodBranded")) {
1325
+ const inner = unwrapBranded(_schema);
1326
+ if (!inner) return _schema;
1327
+ return _stripRefinements(inner, depth + 1);
1328
+ }
1329
+ if (isZodSchemaType(_schema, "ZodPipeline")) {
1330
+ const inner = unwrapPipeIn(_schema);
1331
+ if (!inner) return _schema;
1332
+ return _stripRefinements(inner, depth + 1);
1333
+ }
1334
+ if (isZodSchemaType(_schema, "ZodSet")) {
1335
+ const valueType = getSetValueType(_schema);
1336
+ if (!valueType) return _schema;
1337
+ return z.set(_stripRefinements(valueType, depth + 1));
1338
+ }
1339
+ if (isZodSchemaType(_schema, "ZodTuple")) {
1340
+ const items = getTupleItems(_schema);
1341
+ if (items.length === 0) return _schema;
1342
+ const stripped = items.map((it) => _stripRefinements(it, depth + 1));
1343
+ return z.tuple(stripped);
1344
+ }
1345
+ if (isZodSchemaType(_schema, "ZodRecord")) {
1346
+ const valueType = getRecordValueType(_schema);
1347
+ if (!valueType) return _schema;
1348
+ const value = _stripRefinements(valueType, depth + 1);
1349
+ const keyType = getRecordKeyType(_schema);
1350
+ if (keyType) {
1351
+ return z.record(keyType, value);
1352
+ }
1353
+ return z.record(value);
1354
+ }
1355
+ if (isZodSchemaType(_schema, "ZodUnion")) {
1356
+ const options = getUnionOptions(_schema);
1357
+ if (options.length === 0) return _schema;
1358
+ const stripped = options.map((o) => _stripRefinements(o, depth + 1));
1359
+ return z.union(stripped);
1360
+ }
1361
+ if (isZodSchemaType(_schema, "ZodDiscriminatedUnion")) {
1362
+ const discKey = getDiscriminator(_schema);
1363
+ const options = getDiscriminatedOptions(_schema);
1364
+ if (discKey === void 0 || options.length === 0) return _schema;
1365
+ const stripped = options.map(
1366
+ (o) => _stripRefinements(o, depth + 1)
1367
+ );
1368
+ return z.discriminatedUnion(
1369
+ discKey,
1370
+ stripped
1371
+ );
1372
+ }
1373
+ if (isZodSchemaType(_schema, "ZodIntersection")) {
1374
+ const left = getIntersectionLeft(_schema);
1375
+ const right = getIntersectionRight(_schema);
1376
+ if (!left || !right) return _schema;
1377
+ return z.intersection(_stripRefinements(left, depth + 1), _stripRefinements(right, depth + 1));
1378
+ }
1379
+ if (isZodSchemaType(_schema, "ZodLazy")) {
1380
+ const inner = unwrapLazy(_schema);
1381
+ if (!inner) return _schema;
1382
+ const stripped = _stripRefinements(inner, depth + 1);
1383
+ return z.lazy(() => stripped);
1384
+ }
1385
+ return _schema;
1386
+ }
1387
+ return _stripRefinements(schema, 0);
1388
+ }
1389
+ function stripRootSchema(schema, stripConfig) {
1390
+ function recursion(_schema, _stripped = false) {
1391
+ if (getStripInstruction(stripConfig.stripNullable, _schema) && isZodSchemaType(_schema, "ZodNullable")) {
1392
+ return recursion(_schema.unwrap(), true);
1393
+ }
1394
+ if (getStripInstruction(stripConfig.stripOptional, _schema) && isZodSchemaType(_schema, "ZodOptional")) {
1395
+ return recursion(_schema.unwrap(), true);
1396
+ }
1397
+ if (getStripInstruction(stripConfig.stripZodEffects, _schema) && isZodSchemaType(_schema, "ZodEffects")) {
1398
+ const inner = unwrapEffectsSource(_schema);
1399
+ if (inner) return recursion(inner, true);
1400
+ }
1401
+ if (getStripInstruction(stripConfig.stripDefaultValues, _schema) && isZodSchemaType(_schema, "ZodDefault")) {
1402
+ const inner = unwrapInner(_schema);
1403
+ if (inner) return recursion(inner, true);
1404
+ }
1405
+ if (getStripInstruction(stripConfig.stripZodRefinements, _schema) && hasChecks(_schema)) {
1406
+ return recursion(stripRefinements(_schema));
1407
+ }
1408
+ return [_schema, _stripped];
1409
+ }
1410
+ return recursion(schema, false);
1411
+ }
1412
+ const getStripInstruction = (stripValueOrCallback, schema) => {
1413
+ if (stripValueOrCallback === void 0 || stripValueOrCallback === false) return false;
1414
+ return isFunction(stripValueOrCallback) ? stripValueOrCallback(schema) : stripValueOrCallback;
1415
+ };
1416
+ function getSlimSchema(config) {
1417
+ function _getSlimSchema(_schema) {
1418
+ if (isZodSchemaType(_schema, "ZodObject")) {
1419
+ const newShape = {};
1420
+ for (const [key, value] of Object.entries(getObjectShape(_schema))) {
1421
+ newShape[key] = _getSlimSchema(value);
1422
+ }
1423
+ return z.object(newShape);
1424
+ }
1425
+ if (isZodSchemaType(_schema, "ZodArray")) {
1426
+ const inner = getArrayElement(_schema);
1427
+ if (!inner) return _schema;
1428
+ return z.array(_getSlimSchema(inner));
1429
+ }
1430
+ if (isZodSchemaType(_schema, "ZodRecord")) {
1431
+ const keyType = getRecordKeyType(_schema);
1432
+ const valueType = getRecordValueType(_schema);
1433
+ if (!keyType || !valueType) return _schema;
1434
+ const key = _getSlimSchema(keyType);
1435
+ const value = _getSlimSchema(valueType);
1436
+ return z.record(key, value);
1437
+ }
1438
+ if (isZodSchemaType(_schema, "ZodDiscriminatedUnion")) {
1439
+ const slimmedSchemas = [];
1440
+ const discKey = getDiscriminator(_schema);
1441
+ if (discKey === void 0) return _schema;
1442
+ for (const option of getDiscriminatedOptions(_schema)) {
1443
+ const slimmedSchema = _getSlimSchema(option);
1444
+ const deepCloneSlimmedSchema = cloneDeep(slimmedSchema);
1445
+ slimmedSchemas.push(deepCloneSlimmedSchema);
1446
+ }
1447
+ return z.discriminatedUnion(
1448
+ discKey,
1449
+ slimmedSchemas
1450
+ );
1451
+ }
1452
+ if (getStripInstruction(config.stripConfig.stripZodEffects, _schema) && isZodSchemaType(_schema, "ZodEffects")) {
1453
+ const inner = unwrapEffectsSource(_schema);
1454
+ if (inner) return _getSlimSchema(inner);
1455
+ }
1456
+ if (getStripInstruction(config.stripConfig.stripNullable, _schema) && isZodSchemaType(_schema, "ZodNullable")) {
1457
+ const inner = unwrapInner(_schema);
1458
+ if (inner) return _getSlimSchema(inner);
1459
+ }
1460
+ if (getStripInstruction(config.stripConfig.stripOptional, _schema) && isZodSchemaType(_schema, "ZodOptional")) {
1461
+ const inner = unwrapInner(_schema);
1462
+ if (inner) return _getSlimSchema(inner);
1463
+ }
1464
+ if (getStripInstruction(config.stripConfig.stripZodRefinements, _schema) && hasChecks(_schema)) {
1465
+ return stripRefinements(_schema);
1466
+ }
1467
+ if (getStripInstruction(config.stripConfig.stripDefaultValues, _schema) && isZodSchemaType(_schema, "ZodDefault")) {
1468
+ const inner = unwrapInner(_schema);
1469
+ if (inner) return _getSlimSchema(inner);
1470
+ }
1471
+ const unionSchema = unwrapToDiscriminatedUnion(_schema);
1472
+ if (unionSchema && getStripInstruction(config.stripConfig.stripDefaultValues, unionSchema)) {
1473
+ return _getSlimSchema(unionSchema);
1474
+ }
1475
+ return _schema;
1476
+ }
1477
+ const processedRootSchema = stripRootSchema(config.schema, config.stripConfig)[0];
1478
+ return _getSlimSchema(processedRootSchema);
1479
+ }
1480
+ function peelAllV3Wrappers(schema) {
1481
+ let current = schema;
1482
+ for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
1483
+ let inner;
1484
+ if (isZodSchemaType(current, "ZodOptional") || isZodSchemaType(current, "ZodNullable") || isZodSchemaType(current, "ZodDefault") || isZodSchemaType(current, "ZodReadonly") || isZodSchemaType(current, "ZodCatch")) {
1485
+ inner = unwrapInner(current);
1486
+ } else if (isZodSchemaType(current, "ZodEffects")) {
1487
+ inner = unwrapEffectsSource(current);
1488
+ } else if (isZodSchemaType(current, "ZodPipeline")) {
1489
+ inner = unwrapPipeIn(current);
1490
+ } else if (isZodSchemaType(current, "ZodBranded")) {
1491
+ inner = unwrapBranded(current);
1492
+ } else if (isZodSchemaType(current, "ZodLazy")) {
1493
+ try {
1494
+ inner = unwrapLazy(current);
1495
+ } catch {
1496
+ return current;
1497
+ }
1498
+ } else {
1499
+ return current;
1500
+ }
1501
+ if (!inner) return current;
1502
+ current = inner;
1503
+ }
1504
+ return current;
1505
+ }
1506
+ const pathMetaCacheV3 = /* @__PURE__ */ new WeakMap();
1507
+ function getPathMetaMapV3(rootSchema) {
1508
+ const cached = pathMetaCacheV3.get(rootSchema);
1509
+ if (cached !== void 0) return cached;
1510
+ const map = /* @__PURE__ */ new Map();
1511
+ const counters = /* @__PURE__ */ new Map();
1512
+ const lastPathPerSchema = /* @__PURE__ */ new Map();
1513
+ const inProgress = /* @__PURE__ */ new WeakSet();
1514
+ walkForMetaV3(rootSchema, [], map, counters, lastPathPerSchema, inProgress);
1515
+ for (const [schema, lastPath] of lastPathPerSchema) {
1516
+ const list = getFieldMetaList(schema);
1517
+ const consumed = counters.get(schema) ?? 0;
1518
+ if (list.length <= consumed) continue;
1519
+ const surplus = list.slice(consumed).reduce((acc, p) => ({ ...acc, ...p }), {});
1520
+ const existing = map.get(lastPath) ?? {};
1521
+ map.set(lastPath, { ...existing, ...surplus });
1522
+ }
1523
+ pathMetaCacheV3.set(rootSchema, map);
1524
+ return map;
1525
+ }
1526
+ function consumePayloadV3(schema, counters) {
1527
+ const list = getFieldMetaList(schema);
1528
+ if (list.length === 0) return void 0;
1529
+ const idx = counters.get(schema) ?? 0;
1530
+ const payload = list[Math.min(idx, list.length - 1)];
1531
+ counters.set(schema, idx + 1);
1532
+ return payload;
1533
+ }
1534
+ function walkForMetaV3(schema, path, map, counters, lastPathPerSchema, inProgress) {
1535
+ if (inProgress.has(schema)) return;
1536
+ inProgress.add(schema);
1537
+ try {
1538
+ const pathKey = canonicalizePath(path).key;
1539
+ if (!map.has(pathKey)) {
1540
+ const payload = consumePayloadV3(schema, counters);
1541
+ if (payload !== void 0) {
1542
+ map.set(pathKey, payload);
1543
+ lastPathPerSchema.set(schema, pathKey);
1544
+ }
1545
+ }
1546
+ const peeled = peelAllV3Wrappers(schema);
1547
+ if (peeled !== schema && !map.has(pathKey)) {
1548
+ const payload = consumePayloadV3(peeled, counters);
1549
+ if (payload !== void 0) {
1550
+ map.set(pathKey, payload);
1551
+ lastPathPerSchema.set(peeled, pathKey);
1552
+ }
1553
+ }
1554
+ if (isZodSchemaType(schema, "ZodObject")) {
1555
+ const shape = getObjectShape(schema);
1556
+ for (const [key, child] of Object.entries(shape)) {
1557
+ walkForMetaV3(
1558
+ child,
1559
+ [...path, key],
1560
+ map,
1561
+ counters,
1562
+ lastPathPerSchema,
1563
+ inProgress
1564
+ );
1565
+ }
1566
+ return;
1567
+ }
1568
+ if (isZodSchemaType(schema, "ZodArray")) {
1569
+ const inner = getArrayElement(schema);
1570
+ if (inner) walkForMetaV3(inner, [...path, 0], map, counters, lastPathPerSchema, inProgress);
1571
+ return;
1572
+ }
1573
+ if (isZodSchemaType(schema, "ZodTuple")) {
1574
+ const items = getTupleItems(schema);
1575
+ items.forEach((item, i) => {
1576
+ walkForMetaV3(
1577
+ item,
1578
+ [...path, i],
1579
+ map,
1580
+ counters,
1581
+ lastPathPerSchema,
1582
+ inProgress
1583
+ );
1584
+ });
1585
+ return;
1586
+ }
1587
+ if (isZodSchemaType(schema, "ZodSet")) {
1588
+ const inner = getSetValueType(schema);
1589
+ if (inner) walkForMetaV3(inner, [...path, 0], map, counters, lastPathPerSchema, inProgress);
1590
+ return;
1591
+ }
1592
+ if (isZodSchemaType(schema, "ZodRecord")) {
1593
+ const inner = getRecordValueType(schema);
1594
+ if (inner) walkForMetaV3(inner, [...path, "*"], map, counters, lastPathPerSchema, inProgress);
1595
+ return;
1596
+ }
1597
+ if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
1598
+ for (const opt of getUnionOptions(schema)) {
1599
+ walkForMetaV3(opt, path, map, counters, lastPathPerSchema, inProgress);
1600
+ }
1601
+ return;
1602
+ }
1603
+ if (isZodSchemaType(schema, "ZodIntersection")) {
1604
+ const left = getIntersectionLeft(schema);
1605
+ const right = getIntersectionRight(schema);
1606
+ if (left) walkForMetaV3(left, path, map, counters, lastPathPerSchema, inProgress);
1607
+ if (right) walkForMetaV3(right, path, map, counters, lastPathPerSchema, inProgress);
1608
+ return;
1609
+ }
1610
+ if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodCatch")) {
1611
+ const inner = unwrapInner(schema);
1612
+ if (inner) walkForMetaV3(inner, path, map, counters, lastPathPerSchema, inProgress);
1613
+ return;
1614
+ }
1615
+ if (isZodSchemaType(schema, "ZodEffects")) {
1616
+ const inner = unwrapEffectsSource(schema);
1617
+ if (inner) walkForMetaV3(inner, path, map, counters, lastPathPerSchema, inProgress);
1618
+ return;
1619
+ }
1620
+ if (isZodSchemaType(schema, "ZodPipeline")) {
1621
+ const inner = unwrapPipeIn(schema);
1622
+ if (inner) walkForMetaV3(inner, path, map, counters, lastPathPerSchema, inProgress);
1623
+ return;
1624
+ }
1625
+ if (isZodSchemaType(schema, "ZodBranded")) {
1626
+ const inner = unwrapBranded(schema);
1627
+ if (inner) walkForMetaV3(inner, path, map, counters, lastPathPerSchema, inProgress);
1628
+ return;
1629
+ }
1630
+ if (isZodSchemaType(schema, "ZodLazy")) {
1631
+ try {
1632
+ const inner = unwrapLazy(schema);
1633
+ if (inner) walkForMetaV3(inner, path, map, counters, lastPathPerSchema, inProgress);
1634
+ } catch {
1635
+ }
1636
+ return;
1637
+ }
1638
+ } finally {
1639
+ inProgress.delete(schema);
1640
+ }
1641
+ }
1642
+ function resolveFieldMetaAtPathV3(rootSchema, path, maxRecursionDepth) {
1643
+ const lastSegment = path.length === 0 ? "" : path[path.length - 1];
1644
+ const target = path.length === 0 ? rootSchema : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth)[0];
1645
+ if (target === void 0) {
1646
+ return {
1647
+ label: humanize(lastSegment),
1648
+ description: void 0,
1649
+ placeholder: void 0,
1650
+ meta: Object.freeze({})
1651
+ };
1652
+ }
1653
+ const pathMap = getPathMetaMapV3(rootSchema);
1654
+ const pathKey = canonicalizePath(path).key;
1655
+ const peeled = peelV3Wrappers(target);
1656
+ const payload = pathMap.get(pathKey) ?? getFieldMeta(target) ?? (peeled !== target ? getFieldMeta(peeled) : void 0);
1657
+ const targetDescription = typeof target.description === "string" ? target.description : void 0;
1658
+ const peeledDescription = peeled !== target && typeof peeled.description === "string" ? peeled.description : void 0;
1659
+ const schemaDescription = targetDescription ?? peeledDescription;
1660
+ return {
1661
+ label: payload?.label ?? humanize(lastSegment),
1662
+ description: payload?.description ?? schemaDescription ?? void 0,
1663
+ placeholder: payload?.placeholder ?? void 0,
1664
+ meta: Object.freeze({ ...payload ?? {} })
1665
+ };
1666
+ }
1667
+ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth) {
1668
+ const defaultValuesWithoutConstraints = getDefaultValuesFromZodSchema(
1669
+ rootSchema,
1670
+ config.useDefaultSchemaValues,
1671
+ formKey
1672
+ );
1673
+ const slimSchema = getSlimSchema({
1674
+ schema: rootSchema,
1675
+ stripConfig: {
1676
+ stripZodEffects: true,
1677
+ stripDefaultValues: true,
1678
+ // `strict: false` strips refinements (so empty defaults pass);
1679
+ // strict keeps them so the slim parse below surfaces refinement
1680
+ // errors. Async refines are guarded by the try/catch — they
1681
+ // can't be surfaced synchronously regardless.
1682
+ stripZodRefinements: (config.strict ?? true) === false
1683
+ }
1684
+ });
1685
+ let rawDefaultValues = defaultValuesWithoutConstraints;
1686
+ if (!isPrimitive(rawDefaultValues)) {
1687
+ rawDefaultValues = mergeDeepV3(defaultValuesWithoutConstraints, config.constraints);
1688
+ } else if (constraintsAreSlimValid(slimSchema, config.constraints)) {
1689
+ rawDefaultValues = config.constraints;
1690
+ }
1691
+ if ((config.strict ?? true) !== false) {
1692
+ if (containsAsyncTransform(rootSchema)) {
1693
+ return {
1694
+ data: rawDefaultValues,
1695
+ errors: void 0,
1696
+ success: true,
1697
+ formKey
1698
+ };
1699
+ }
1700
+ try {
1701
+ const strictResult = rootSchema.safeParse(rawDefaultValues);
1702
+ if (strictResult.success) {
1703
+ return {
1704
+ data: rawDefaultValues,
1705
+ errors: void 0,
1706
+ success: true,
1707
+ formKey
1708
+ };
1709
+ }
1710
+ return {
1711
+ data: rawDefaultValues,
1712
+ errors: zodIssuesToValidationErrors(strictResult.error.issues, formKey),
1713
+ success: false,
1714
+ formKey
1715
+ };
1716
+ } catch (err) {
1717
+ const isAsyncDetect = err instanceof Error && err.message.includes("Async refinement encountered");
1718
+ if (isAsyncDetect) {
1719
+ try {
1720
+ const strippedResult = stripAsyncChecks(rootSchema).safeParse(rawDefaultValues);
1721
+ if (strippedResult.success) {
1722
+ return {
1723
+ data: rawDefaultValues,
1724
+ errors: void 0,
1725
+ success: true,
1726
+ formKey
1727
+ };
1728
+ }
1729
+ return {
1730
+ data: rawDefaultValues,
1731
+ errors: zodIssuesToValidationErrors(strippedResult.error.issues, formKey),
1732
+ success: false,
1733
+ formKey
1734
+ };
1735
+ } catch {
1736
+ return {
1737
+ data: rawDefaultValues,
1738
+ errors: void 0,
1739
+ success: true,
1740
+ formKey
1741
+ };
1742
+ }
1743
+ }
1744
+ return {
1745
+ data: rawDefaultValues,
1746
+ errors: void 0,
1747
+ success: true,
1748
+ formKey
1749
+ };
1750
+ }
1751
+ }
1752
+ let parseResult;
1753
+ try {
1754
+ parseResult = slimSchema.safeParse(rawDefaultValues);
1755
+ } catch {
1756
+ return {
1757
+ data: rawDefaultValues,
1758
+ errors: void 0,
1759
+ success: true,
1760
+ formKey
1761
+ };
1762
+ }
1763
+ const { data, success, error } = parseResult;
1764
+ if (success) {
1765
+ return {
1766
+ data,
1767
+ errors: void 0,
1768
+ success,
1769
+ formKey
1770
+ };
1771
+ }
1772
+ let fixedData = {};
1773
+ for (const issue of error.issues) {
1774
+ const schemasAtPath = getNestedZodSchemasAtPath(slimSchema, issue.path, maxRecursionDepth);
1775
+ const path = coercePathSegments(issue.path);
1776
+ if (!schemasAtPath.length) {
1777
+ console.error(
1778
+ `[attaform] zod-v3 adapter: no schema at path '${path.join(PATH_SEPARATOR)}' for key '${formKey}'. Skipping the issue. (This is a library-internal invariant \u2014 please file a bug.)`
1779
+ );
1780
+ continue;
1781
+ }
1782
+ const candidate = schemasAtPath[0];
1783
+ if (candidate !== void 0) {
1784
+ const valueAtPath = getAtPath(rawDefaultValues, path);
1785
+ const slimKinds = slimPrimitivesV3(candidate);
1786
+ if (slimKinds.size > 0 && slimKinds.has(slimKindOf(valueAtPath))) {
1787
+ continue;
1788
+ }
1789
+ }
1790
+ for (const schemaAtPath of schemasAtPath) {
1791
+ if (issue.code === "invalid_type") {
1792
+ const isDiscriminatedUnion = isZodSchemaType(schemaAtPath, "ZodDiscriminatedUnion");
1793
+ const defaultValueContext = isDiscriminatedUnion ? {
1794
+ formKey,
1795
+ discriminator: {
1796
+ isDiscriminatorKey: true,
1797
+ schema: schemaAtPath,
1798
+ useDefaultSchemaValues: false
1799
+ }
1800
+ } : {
1801
+ formKey,
1802
+ discriminator: {
1803
+ isDiscriminatorKey: false,
1804
+ schema: void 0,
1805
+ useDefaultSchemaValues: false
1806
+ }
1807
+ };
1808
+ const defaultValue = getDefaultValue(issue.expected, defaultValueContext);
1809
+ fixedData = setAtPath(fixedData, path, defaultValue);
1810
+ continue;
1811
+ }
1812
+ const peeled = peelEmbeddedDefault(schemaAtPath, V3_INTROSPECTOR);
1813
+ if (peeled !== NO_EMBEDDED_DEFAULT) {
1814
+ fixedData = setAtPath(fixedData, path, peeled);
1815
+ continue;
1816
+ }
1817
+ const ctx = {
1818
+ formKey,
1819
+ discriminator: {
1820
+ isDiscriminatorKey: false,
1821
+ schema: void 0,
1822
+ useDefaultSchemaValues: false
1823
+ }
1824
+ };
1825
+ const slimKinds = slimPrimitivesV3(schemaAtPath);
1826
+ const firstKind = [...slimKinds][0];
1827
+ if (firstKind !== void 0) {
1828
+ const expected = firstKind === "string" ? "string" : firstKind === "number" ? "number" : firstKind === "boolean" ? "boolean" : firstKind === "bigint" ? "bigint" : firstKind === "date" ? "date" : firstKind === "array" ? "array" : firstKind === "object" ? "object" : null;
1829
+ if (expected !== null) {
1830
+ fixedData = setAtPath(fixedData, path, getDefaultValue(expected, ctx));
1831
+ }
1832
+ }
1833
+ }
1834
+ }
1835
+ fixedData = mergeDeepV3(rawDefaultValues, fixedData);
1836
+ const secondParse = slimSchema.safeParse(fixedData);
1837
+ const finalData = secondParse.success ? secondParse.data : fixedData;
1838
+ return {
1839
+ data: finalData,
1840
+ errors: void 0,
1841
+ success: true,
1842
+ formKey
1843
+ };
1844
+ }
1845
+ function getNestedSchemasInSlimModeV3(rootSchema, path, maxRecursionDepth) {
1846
+ const [strippedSchema] = stripRootSchema(rootSchema, {
1847
+ stripDefaultValues: true,
1848
+ stripNullable: true,
1849
+ stripOptional: true,
1850
+ stripZodEffects: true
1851
+ });
1852
+ const slimSchema = getSlimSchema({
1853
+ schema: strippedSchema,
1854
+ stripConfig: { stripDefaultValues: true, stripZodEffects: true }
1855
+ });
1856
+ return getNestedZodSchemasAtPath(slimSchema, path, maxRecursionDepth);
1857
+ }
1858
+
1859
+ function useForm(configuration) {
1860
+ if (configuration === void 0 || configuration === null || configuration.schema === void 0) {
1861
+ throw new InvalidUseFormConfigError();
1862
+ }
1863
+ function isZodType(value) {
1864
+ return typeof value === "object" && value !== null && "_def" in value;
1865
+ }
1866
+ const { schema } = configuration;
1867
+ const abstractSchema = isZodType(schema) ? zodAdapter(schema) : schema;
1868
+ return useAbstractForm({
1869
+ ...configuration,
1870
+ schema: abstractSchema,
1871
+ defaultValues: configuration.defaultValues
1872
+ });
1873
+ }
1874
+
1875
+ export { fieldMeta as f, isZodSchemaType as i, useForm as u, withMeta as w, zodAdapter as z };
1876
+ //# sourceMappingURL=attaform.DvA-CJJW.mjs.map