attaform 0.15.1 → 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 (92) 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 +75 -70
  17. package/dist/index.d.mts +75 -70
  18. package/dist/index.d.ts +75 -70
  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.CvOXSpCb.mjs +1908 -0
  46. package/dist/shared/attaform.CvOXSpCb.mjs.map +1 -0
  47. package/dist/shared/{attaform.qxyip_aN.mjs → attaform.DILbdvfo.mjs} +12 -5
  48. package/dist/shared/{attaform.CDJVeoJU.cjs.map → attaform.DILbdvfo.mjs.map} +1 -1
  49. package/dist/shared/attaform.DdnithOf.mjs +1555 -0
  50. package/dist/shared/attaform.DdnithOf.mjs.map +1 -0
  51. package/dist/shared/attaform.DfrYByDj.cjs +1916 -0
  52. package/dist/shared/attaform.DfrYByDj.cjs.map +1 -0
  53. package/dist/shared/{attaform.BOi138GE.cjs → attaform.c_NzdRyc.cjs} +4 -4
  54. package/dist/shared/{attaform.BOi138GE.cjs.map → attaform.c_NzdRyc.cjs.map} +1 -1
  55. package/dist/shared/{attaform.DXye3JKf.mjs → attaform.jrxE_xZw.mjs} +2 -2
  56. package/dist/shared/{attaform.DXye3JKf.mjs.map → attaform.jrxE_xZw.mjs.map} +1 -1
  57. package/dist/shared/attaform.ls_7jBYc.d.ts +84 -0
  58. package/dist/shared/{attaform.BgYBU8gV.cjs → attaform.rIRYSUI1.cjs} +461 -61
  59. package/dist/shared/attaform.rIRYSUI1.cjs.map +1 -0
  60. package/dist/shared/attaform.xIcmqscx.d.cts +84 -0
  61. package/dist/vite.cjs +62 -9
  62. package/dist/vite.cjs.map +1 -1
  63. package/dist/vite.d.cts +23 -32
  64. package/dist/vite.d.mts +23 -32
  65. package/dist/vite.d.ts +23 -32
  66. package/dist/vite.mjs +62 -9
  67. package/dist/vite.mjs.map +1 -1
  68. package/dist/zod-v3.cjs +9 -1553
  69. package/dist/zod-v3.cjs.map +1 -1
  70. package/dist/zod-v3.mjs +3 -1553
  71. package/dist/zod-v3.mjs.map +1 -1
  72. package/dist/zod-v4.cjs +21 -0
  73. package/dist/zod-v4.cjs.map +1 -0
  74. package/dist/zod-v4.d.cts +104 -0
  75. package/dist/zod-v4.d.mts +104 -0
  76. package/dist/zod-v4.d.ts +104 -0
  77. package/dist/zod-v4.mjs +4 -0
  78. package/dist/zod-v4.mjs.map +1 -0
  79. package/dist/zod.cjs +19 -1900
  80. package/dist/zod.cjs.map +1 -1
  81. package/dist/zod.d.cts +27 -155
  82. package/dist/zod.d.mts +27 -155
  83. package/dist/zod.d.ts +27 -155
  84. package/dist/zod.mjs +19 -1896
  85. package/dist/zod.mjs.map +1 -1
  86. package/package.json +6 -2
  87. package/dist/shared/attaform.BgYBU8gV.cjs.map +0 -1
  88. package/dist/shared/attaform.CRk8NhlD.mjs.map +0 -1
  89. package/dist/shared/attaform.RypIkgVy.cjs +0 -417
  90. package/dist/shared/attaform.RypIkgVy.cjs.map +0 -1
  91. package/dist/shared/attaform.a99dQV7Q.mjs +0 -392
  92. package/dist/shared/attaform.a99dQV7Q.mjs.map +0 -1
@@ -0,0 +1,1555 @@
1
+ import { merge, set, isFunction, cloneDeep } from 'lodash-es';
2
+ import { z } from 'zod';
3
+ import { g as getAtPath, s as slimKindOf, A as AttaformErrorCode, h as humanize, c as useAbstractForm } from './attaform.DILbdvfo.mjs';
4
+ import { c as canonicalizePath } from './attaform.jrxE_xZw.mjs';
5
+ import { a as AttaformError, _ as __DEV__, b as InvalidUseFormConfigError } from './attaform.BfMxsfmE.mjs';
6
+
7
+ const store = /* @__PURE__ */ new WeakMap();
8
+ const fieldMeta = {
9
+ add(schema, payload) {
10
+ store.set(schema, payload);
11
+ return fieldMeta;
12
+ },
13
+ get(schema) {
14
+ return store.get(schema);
15
+ },
16
+ has(schema) {
17
+ return store.has(schema);
18
+ }
19
+ };
20
+ function withMeta(schema, payload) {
21
+ const existing = store.get(schema) ?? {};
22
+ const Ctor = schema.constructor;
23
+ const cloned = new Ctor(schema._def);
24
+ store.set(cloned, { ...existing, ...payload });
25
+ return cloned;
26
+ }
27
+ function getFieldMeta(schema) {
28
+ return store.get(schema);
29
+ }
30
+
31
+ class UnsupportedSchemaError extends AttaformError {
32
+ }
33
+
34
+ function isZodSchemaType(schema, expectedType) {
35
+ if (typeof schema !== "object" || schema === null) return false;
36
+ const maybeDef = schema._def;
37
+ return maybeDef?.typeName === expectedType;
38
+ }
39
+
40
+ const UNSUPPORTED_TYPE_NAMES = /* @__PURE__ */ new Set(["ZodPromise", "ZodFunction", "ZodMap", "ZodSymbol"]);
41
+ function labelPath(path) {
42
+ return path.length === 0 ? "<root>" : path.join(".");
43
+ }
44
+ function getTypeName(schema) {
45
+ const def = schema._def;
46
+ return def?.typeName;
47
+ }
48
+ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
49
+ const typeName = getTypeName(schema);
50
+ if (typeName !== void 0 && UNSUPPORTED_TYPE_NAMES.has(typeName)) {
51
+ throw new UnsupportedSchemaError(
52
+ `[attaform/zod-v3] unsupported kind '${typeName}' at '${labelPath(path)}'`
53
+ );
54
+ }
55
+ if (isZodSchemaType(schema, "ZodObject")) {
56
+ const shape = schema.shape;
57
+ for (const [key, sub] of Object.entries(shape)) {
58
+ assertSupportedKinds(sub, [...path, key], lazyGetters);
59
+ }
60
+ return;
61
+ }
62
+ if (isZodSchemaType(schema, "ZodArray")) {
63
+ const inner = schema._def.type;
64
+ if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
65
+ return;
66
+ }
67
+ if (isZodSchemaType(schema, "ZodSet")) {
68
+ const inner = schema._def.valueType;
69
+ if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
70
+ return;
71
+ }
72
+ if (isZodSchemaType(schema, "ZodRecord")) {
73
+ const inner = schema._def.valueType;
74
+ if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
75
+ return;
76
+ }
77
+ if (isZodSchemaType(schema, "ZodTuple")) {
78
+ const items = schema._def.items ?? [];
79
+ items.forEach((item, i) => assertSupportedKinds(item, [...path, String(i)], lazyGetters));
80
+ return;
81
+ }
82
+ if (isZodSchemaType(schema, "ZodUnion")) {
83
+ const options = schema._def.options ?? [];
84
+ options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
85
+ return;
86
+ }
87
+ if (isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
88
+ const options = schema._def.options ?? [];
89
+ options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
90
+ return;
91
+ }
92
+ if (isZodSchemaType(schema, "ZodIntersection")) {
93
+ const def = schema._def;
94
+ if (def.left) assertSupportedKinds(def.left, [...path, "left"], lazyGetters);
95
+ if (def.right) assertSupportedKinds(def.right, [...path, "right"], lazyGetters);
96
+ return;
97
+ }
98
+ if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodBranded")) {
99
+ const inner = schema._def.innerType ?? schema._def.type;
100
+ if (inner) assertSupportedKinds(inner, path, lazyGetters);
101
+ return;
102
+ }
103
+ if (isZodSchemaType(schema, "ZodEffects")) {
104
+ const inner = schema.innerType();
105
+ assertSupportedKinds(inner, path, lazyGetters);
106
+ return;
107
+ }
108
+ if (isZodSchemaType(schema, "ZodPipeline")) {
109
+ const inner = schema._def.in;
110
+ if (inner) assertSupportedKinds(inner, path, lazyGetters);
111
+ return;
112
+ }
113
+ if (isZodSchemaType(schema, "ZodLazy")) {
114
+ const getter = schema._def.getter;
115
+ if (getter !== void 0 && lazyGetters.includes(getter)) {
116
+ throw new UnsupportedSchemaError(
117
+ `[attaform/zod-v3] Recursive z.lazy() at '${labelPath(path)}'`
118
+ );
119
+ }
120
+ const inner = getter?.();
121
+ if (inner !== void 0) {
122
+ assertSupportedKinds(
123
+ inner,
124
+ path,
125
+ getter === void 0 ? lazyGetters : [...lazyGetters, getter]
126
+ );
127
+ }
128
+ return;
129
+ }
130
+ }
131
+
132
+ const cyclicSentinel = "<cyclic>";
133
+ function fingerprintZodSchema(schema) {
134
+ const cache = /* @__PURE__ */ new WeakMap();
135
+ const inProgress = /* @__PURE__ */ new WeakSet();
136
+ return visit(schema, cache, inProgress);
137
+ }
138
+ function visit(schema, cache, inProgress) {
139
+ const key = schema;
140
+ const cached = cache.get(key);
141
+ if (cached !== void 0) return cached;
142
+ if (inProgress.has(key)) return cyclicSentinel;
143
+ inProgress.add(key);
144
+ try {
145
+ const computed = computeFingerprint(schema, cache, inProgress);
146
+ cache.set(key, computed);
147
+ return computed;
148
+ } finally {
149
+ inProgress.delete(key);
150
+ }
151
+ }
152
+ function getDef(schema) {
153
+ return schema._def;
154
+ }
155
+ function computeFingerprint(schema, cache, inProgress) {
156
+ const def = getDef(schema);
157
+ const kind = def.typeName ?? "ZodUnknown";
158
+ const recurse = (child) => visit(child, cache, inProgress);
159
+ switch (kind) {
160
+ case "ZodString":
161
+ case "ZodNumber":
162
+ case "ZodBigInt":
163
+ case "ZodDate":
164
+ return `${kind}${formatChecks(def.checks)}`;
165
+ case "ZodBoolean":
166
+ case "ZodNull":
167
+ case "ZodUndefined":
168
+ case "ZodAny":
169
+ case "ZodUnknown":
170
+ case "ZodNaN":
171
+ case "ZodVoid":
172
+ case "ZodNever":
173
+ return kind;
174
+ case "ZodLiteral":
175
+ return `ZodLiteral:${canonicalStringify(def.value)}`;
176
+ case "ZodEnum":
177
+ case "ZodNativeEnum": {
178
+ const values = def.values ?? [];
179
+ const sorted = [...values].sort((a, b) => {
180
+ const as = String(a);
181
+ const bs = String(b);
182
+ return as < bs ? -1 : as > bs ? 1 : 0;
183
+ });
184
+ return `${kind}:${canonicalStringify(sorted)}`;
185
+ }
186
+ case "ZodObject": {
187
+ const shape = readShapeSafely(def);
188
+ const sortedEntries = Object.entries(shape).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${recurse(v)}`);
189
+ return `ZodObject{${sortedEntries.join(",")}}`;
190
+ }
191
+ case "ZodArray":
192
+ return `ZodArray[${def.type === void 0 ? "?" : recurse(def.type)}]${formatChecks(def.checks)}`;
193
+ case "ZodTuple": {
194
+ const items = def.items ?? [];
195
+ return `ZodTuple[${items.map(recurse).join(",")}]`;
196
+ }
197
+ case "ZodRecord": {
198
+ const keyPart = def.keyType === void 0 ? "?" : recurse(def.keyType);
199
+ const valuePart = def.valueType === void 0 ? "?" : recurse(def.valueType);
200
+ return `ZodRecord<${keyPart},${valuePart}>`;
201
+ }
202
+ case "ZodUnion": {
203
+ const options = (def.options ?? []).map(recurse).sort();
204
+ return `ZodUnion(${options.join("|")})`;
205
+ }
206
+ case "ZodDiscriminatedUnion": {
207
+ const disc = def.discriminator ?? "?";
208
+ const options = (def.options ?? []).map(recurse).sort();
209
+ return `ZodDiscriminatedUnion[${JSON.stringify(disc)}](${options.join("|")})`;
210
+ }
211
+ case "ZodOptional": {
212
+ const inner = def.innerType;
213
+ return inner === void 0 ? "ZodOptional(?)" : `ZodOptional(${recurse(inner)})`;
214
+ }
215
+ case "ZodNullable": {
216
+ const inner = def.innerType;
217
+ return inner === void 0 ? "ZodNullable(?)" : `ZodNullable(${recurse(inner)})`;
218
+ }
219
+ case "ZodDefault": {
220
+ const inner = def.innerType;
221
+ return `ZodDefault[${defaultFactoryRepr(def.defaultValue)}](${inner === void 0 ? "?" : recurse(inner)})`;
222
+ }
223
+ case "ZodReadonly": {
224
+ const inner = def.innerType;
225
+ return inner === void 0 ? "ZodReadonly(?)" : `ZodReadonly(${recurse(inner)})`;
226
+ }
227
+ case "ZodEffects": {
228
+ const effectType = def.effect?.type ?? "effect";
229
+ const inner = def.schema;
230
+ return `ZodEffects:${effectType}:fn:*(${inner === void 0 ? "?" : recurse(inner)})`;
231
+ }
232
+ case "ZodPipeline": {
233
+ const inner = def.schema;
234
+ return inner === void 0 ? "ZodPipeline(?)" : `ZodPipeline(${recurse(inner)})`;
235
+ }
236
+ case "ZodCatch": {
237
+ const inner = def.innerType ?? def.schema;
238
+ const catchRepr = defaultFactoryRepr(def.catchValue);
239
+ return `ZodCatch[${catchRepr}](${inner === void 0 ? "?" : recurse(inner)})`;
240
+ }
241
+ case "ZodLazy": {
242
+ const resolve = def.getter;
243
+ if (typeof resolve !== "function") return "ZodLazy(?)";
244
+ try {
245
+ const inner = resolve();
246
+ return `ZodLazy(${recurse(inner)})`;
247
+ } catch {
248
+ return "ZodLazy(?)";
249
+ }
250
+ }
251
+ case "ZodIntersection": {
252
+ const leftPart = def.left === void 0 ? "?" : recurse(def.left);
253
+ const rightPart = def.right === void 0 ? "?" : recurse(def.right);
254
+ const parts = [leftPart, rightPart].sort();
255
+ return `ZodIntersection(${parts.join("&")})`;
256
+ }
257
+ // Structural opacity — schemas whose runtime behaviour isn't
258
+ // introspectable via `_def` fall here. Still distinguishable
259
+ // from other kinds by the returned string.
260
+ case "ZodPromise":
261
+ case "ZodFunction":
262
+ case "ZodMap":
263
+ case "ZodSet":
264
+ case "ZodSymbol":
265
+ case "ZodBranded":
266
+ default:
267
+ return `${kind}:*`;
268
+ }
269
+ }
270
+ function readShapeSafely(def) {
271
+ if (typeof def.shape !== "function") return {};
272
+ try {
273
+ return def.shape();
274
+ } catch {
275
+ return {};
276
+ }
277
+ }
278
+ function defaultFactoryRepr(factory) {
279
+ if (typeof factory !== "function") return "none";
280
+ let first;
281
+ let second;
282
+ try {
283
+ first = factory();
284
+ second = factory();
285
+ } catch {
286
+ return "fn:*";
287
+ }
288
+ if (!Object.is(first, second)) return "fn:*";
289
+ if (typeof first === "function") return "fn:*";
290
+ return canonicalStringify(first);
291
+ }
292
+ function formatChecks(checks) {
293
+ if (!Array.isArray(checks) || checks.length === 0) return "";
294
+ const parts = checks.map((c) => canonicalStringify(c)).sort();
295
+ return `[${parts.join(";")}]`;
296
+ }
297
+ function canonicalStringify(value, seen = /* @__PURE__ */ new WeakSet()) {
298
+ if (value === null) return "null";
299
+ if (value === void 0) return "undefined";
300
+ const t = typeof value;
301
+ if (t === "string") return JSON.stringify(value);
302
+ if (t === "number" || t === "boolean") return String(value);
303
+ if (t === "bigint") return `${String(value)}n`;
304
+ if (t === "function") return "fn:*";
305
+ if (t === "symbol") return "symbol:*";
306
+ if (Array.isArray(value)) {
307
+ if (seen.has(value)) return "<cyclic>";
308
+ seen.add(value);
309
+ try {
310
+ return `[${value.map((v) => canonicalStringify(v, seen)).join(",")}]`;
311
+ } finally {
312
+ seen.delete(value);
313
+ }
314
+ }
315
+ if (t === "object") {
316
+ const obj = value;
317
+ if (seen.has(obj)) return "<cyclic>";
318
+ seen.add(obj);
319
+ try {
320
+ if (value instanceof Date) return `date:${value.getTime()}`;
321
+ if (value instanceof RegExp) return `regex:${String(value)}`;
322
+ const entries = Object.entries(obj).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonicalStringify(v, seen)}`);
323
+ return `{${entries.join(",")}}`;
324
+ } finally {
325
+ seen.delete(obj);
326
+ }
327
+ }
328
+ return "unknown";
329
+ }
330
+
331
+ const PERMISSIVE_V3 = /* @__PURE__ */ new Set([
332
+ "string",
333
+ "number",
334
+ "boolean",
335
+ "bigint",
336
+ "date",
337
+ "null",
338
+ "undefined",
339
+ "object",
340
+ "array",
341
+ "symbol",
342
+ "function",
343
+ "map",
344
+ "set"
345
+ ]);
346
+ const MAX_LAZY_DEPTH_V3 = 64;
347
+ function slimPrimitivesV3(schema, depth = 0) {
348
+ if (depth > MAX_LAZY_DEPTH_V3) return new Set(PERMISSIVE_V3);
349
+ const def = schema._def;
350
+ const typeName = def?.typeName;
351
+ if (isZodSchemaType(schema, "ZodString")) return /* @__PURE__ */ new Set(["string"]);
352
+ if (isZodSchemaType(schema, "ZodNumber")) return /* @__PURE__ */ new Set(["number"]);
353
+ if (isZodSchemaType(schema, "ZodBoolean")) return /* @__PURE__ */ new Set(["boolean"]);
354
+ if (isZodSchemaType(schema, "ZodBigInt")) return /* @__PURE__ */ new Set(["bigint"]);
355
+ if (isZodSchemaType(schema, "ZodDate")) return /* @__PURE__ */ new Set(["date"]);
356
+ if (isZodSchemaType(schema, "ZodNull")) return /* @__PURE__ */ new Set(["null"]);
357
+ if (isZodSchemaType(schema, "ZodUndefined")) return /* @__PURE__ */ new Set(["undefined"]);
358
+ if (typeName === "ZodVoid") return /* @__PURE__ */ new Set(["undefined"]);
359
+ if (typeName === "ZodNaN") return /* @__PURE__ */ new Set(["number"]);
360
+ if (isZodSchemaType(schema, "ZodEnum")) {
361
+ const options = schema.options;
362
+ const out = /* @__PURE__ */ new Set();
363
+ for (const v of options) {
364
+ if (typeof v === "string") out.add("string");
365
+ else if (typeof v === "number") out.add("number");
366
+ }
367
+ return out.size === 0 ? /* @__PURE__ */ new Set(["string"]) : out;
368
+ }
369
+ if (isZodSchemaType(schema, "ZodLiteral")) {
370
+ const value = schema.value;
371
+ return /* @__PURE__ */ new Set([slimKindOfRawV3(value)]);
372
+ }
373
+ if (isZodSchemaType(schema, "ZodObject") || typeName === "ZodRecord") {
374
+ return /* @__PURE__ */ new Set(["object"]);
375
+ }
376
+ if (isZodSchemaType(schema, "ZodArray") || typeName === "ZodTuple") {
377
+ return /* @__PURE__ */ new Set(["array"]);
378
+ }
379
+ if (isZodSchemaType(schema, "ZodSet")) {
380
+ return /* @__PURE__ */ new Set(["set"]);
381
+ }
382
+ if (isZodSchemaType(schema, "ZodOptional")) {
383
+ const inner = def?.innerType;
384
+ const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : slimPrimitivesV3(inner, depth + 1);
385
+ innerSet.add("undefined");
386
+ return innerSet;
387
+ }
388
+ if (isZodSchemaType(schema, "ZodNullable")) {
389
+ const inner = def?.innerType;
390
+ const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : slimPrimitivesV3(inner, depth + 1);
391
+ innerSet.add("null");
392
+ return innerSet;
393
+ }
394
+ if (isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodBranded")) {
395
+ const inner = def?.innerType ?? def?.type;
396
+ return inner === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(inner, depth + 1);
397
+ }
398
+ if (isZodSchemaType(schema, "ZodEffects")) {
399
+ const inner = def?.schema;
400
+ return inner === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(inner, depth + 1);
401
+ }
402
+ if (isZodSchemaType(schema, "ZodPipeline")) {
403
+ const inner = def?.in;
404
+ return inner === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(inner, depth + 1);
405
+ }
406
+ if (typeName === "ZodLazy") {
407
+ const getter = def?.getter;
408
+ if (typeof getter !== "function") return new Set(PERMISSIVE_V3);
409
+ return slimPrimitivesV3(getter(), depth + 1);
410
+ }
411
+ if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
412
+ const options = def?.options ?? [];
413
+ const out = /* @__PURE__ */ new Set();
414
+ for (const opt of options) {
415
+ for (const k of slimPrimitivesV3(opt, depth + 1)) out.add(k);
416
+ }
417
+ return out.size === 0 ? new Set(PERMISSIVE_V3) : out;
418
+ }
419
+ if (typeName === "ZodIntersection") {
420
+ const left = def?.left;
421
+ const right = def?.right;
422
+ const leftSet = left === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(left, depth + 1);
423
+ const rightSet = right === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(right, depth + 1);
424
+ const out = /* @__PURE__ */ new Set();
425
+ for (const k of leftSet) if (rightSet.has(k)) out.add(k);
426
+ return out;
427
+ }
428
+ if (typeName === "ZodNever") return /* @__PURE__ */ new Set();
429
+ if (typeName === "ZodAny" || typeName === "ZodUnknown") return new Set(PERMISSIVE_V3);
430
+ return new Set(PERMISSIVE_V3);
431
+ }
432
+ function slimKindOfRawV3(value) {
433
+ if (value === null) return "null";
434
+ if (value === void 0) return "undefined";
435
+ if (Array.isArray(value)) return "array";
436
+ if (value instanceof Date) return "date";
437
+ const t = typeof value;
438
+ switch (t) {
439
+ case "string":
440
+ return "string";
441
+ case "number":
442
+ return "number";
443
+ case "boolean":
444
+ return "boolean";
445
+ case "bigint":
446
+ return "bigint";
447
+ case "symbol":
448
+ return "symbol";
449
+ case "function":
450
+ return "function";
451
+ case "undefined":
452
+ return "undefined";
453
+ case "object":
454
+ return "object";
455
+ default:
456
+ return "object";
457
+ }
458
+ }
459
+
460
+ const PATH_SEPARATOR = ".";
461
+ const MAX_UNWRAP_STEPS = 64;
462
+ function isPrimitive(input) {
463
+ const type = typeof input;
464
+ if (type === "string" || type === "number" || type === "boolean" || type === "bigint" || type === "undefined")
465
+ return true;
466
+ return input === null;
467
+ }
468
+ function constraintsAreSlimValid(slimSchema, constraints) {
469
+ try {
470
+ return slimSchema.safeParse(constraints).success;
471
+ } catch {
472
+ return false;
473
+ }
474
+ }
475
+ let warnedZodCodeMissing = false;
476
+ function zodAdapter(zodSchema) {
477
+ function getAbstractSchema(_formKey, _zodSchema, _isRootSchema) {
478
+ if (_isRootSchema) {
479
+ assertSupportedKinds(_zodSchema);
480
+ const [_schema] = stripRootSchema(_zodSchema, {
481
+ stripDefaultValues: true,
482
+ stripNullable: true,
483
+ stripOptional: true,
484
+ stripZodEffects: true,
485
+ stripZodRefinements: true
486
+ });
487
+ if (!isZodSchemaType(_schema, "ZodObject")) {
488
+ const name = _schema._def.typeName;
489
+ throw new Error(`ZodAdapter: expected ZodObject, got ${name}`);
490
+ }
491
+ }
492
+ const leafCache = /* @__PURE__ */ new Map();
493
+ const abstractSchema = {
494
+ fingerprint: () => fingerprintZodSchema(_zodSchema),
495
+ getDefaultValues(config) {
496
+ const defaultValuesWithoutConstraints = getDefaultValuesFromZodSchema(
497
+ _zodSchema,
498
+ config.useDefaultSchemaValues,
499
+ _formKey
500
+ );
501
+ const slimSchema = getSlimSchema({
502
+ schema: _zodSchema,
503
+ stripConfig: {
504
+ stripZodEffects: true,
505
+ stripDefaultValues: true,
506
+ // `strict: false` strips refinements (so empty defaults
507
+ // pass); strict keeps them so the slim parse below
508
+ // surfaces refinement errors. Async refines are guarded
509
+ // by the try/catch below — they can't be surfaced
510
+ // synchronously regardless.
511
+ stripZodRefinements: (config.strict ?? true) === false
512
+ }
513
+ });
514
+ let rawDefaultValues = defaultValuesWithoutConstraints;
515
+ if (!isPrimitive(rawDefaultValues)) {
516
+ rawDefaultValues = merge(defaultValuesWithoutConstraints, config.constraints);
517
+ } else if (constraintsAreSlimValid(slimSchema, config.constraints)) {
518
+ rawDefaultValues = config.constraints;
519
+ }
520
+ let parseResult;
521
+ try {
522
+ parseResult = slimSchema.safeParse(rawDefaultValues);
523
+ } catch {
524
+ return {
525
+ data: rawDefaultValues,
526
+ errors: void 0,
527
+ success: true,
528
+ formKey: _formKey
529
+ };
530
+ }
531
+ const { data, success, error } = parseResult;
532
+ if (success) {
533
+ return {
534
+ data,
535
+ errors: void 0,
536
+ success,
537
+ formKey: _formKey
538
+ };
539
+ }
540
+ let fixedData = {};
541
+ {
542
+ for (const issue of error.issues) {
543
+ const schemasAtPath = getNestedZodSchemasAtPath(slimSchema, issue.path);
544
+ const path = coercePathSegments(issue.path);
545
+ if (!schemasAtPath.length) {
546
+ console.error(
547
+ `[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.)`
548
+ );
549
+ continue;
550
+ }
551
+ const candidate = schemasAtPath[0];
552
+ if (candidate !== void 0) {
553
+ const valueAtPath = getAtPath(rawDefaultValues, path);
554
+ const slimKinds = slimPrimitivesV3(candidate);
555
+ if (slimKinds.size > 0 && slimKinds.has(slimKindOf(valueAtPath))) {
556
+ continue;
557
+ }
558
+ }
559
+ for (const schemaAtPath of schemasAtPath) {
560
+ if (issue.code === "invalid_type") {
561
+ const isDiscriminatedUnion = isZodSchemaType(schemaAtPath, "ZodDiscriminatedUnion");
562
+ const defaultValueContext = isDiscriminatedUnion ? {
563
+ formKey: _formKey,
564
+ discriminator: {
565
+ isDiscriminatorKey: true,
566
+ schema: schemaAtPath,
567
+ useDefaultSchemaValues: false
568
+ }
569
+ } : {
570
+ formKey: _formKey,
571
+ discriminator: {
572
+ isDiscriminatorKey: false,
573
+ schema: void 0,
574
+ useDefaultSchemaValues: false
575
+ }
576
+ };
577
+ const defaultValue2 = getDefaultValue(issue.expected, defaultValueContext);
578
+ set(fixedData, path, defaultValue2);
579
+ continue;
580
+ }
581
+ const [defaultValue, found] = unwrapDefault(schemaAtPath);
582
+ if (found) {
583
+ set(fixedData, path, defaultValue);
584
+ continue;
585
+ }
586
+ const ctx = {
587
+ formKey: _formKey,
588
+ discriminator: {
589
+ isDiscriminatorKey: false,
590
+ schema: void 0,
591
+ useDefaultSchemaValues: false
592
+ }
593
+ };
594
+ const slimKinds = slimPrimitivesV3(schemaAtPath);
595
+ const firstKind = [...slimKinds][0];
596
+ if (firstKind !== void 0) {
597
+ const expected = firstKind === "string" ? "string" : firstKind === "number" ? "number" : firstKind === "boolean" ? "boolean" : firstKind === "bigint" ? "bigint" : firstKind === "date" ? "date" : firstKind === "array" ? "array" : firstKind === "object" ? "object" : null;
598
+ if (expected !== null) {
599
+ set(fixedData, path, getDefaultValue(expected, ctx));
600
+ }
601
+ }
602
+ }
603
+ }
604
+ fixedData = merge(rawDefaultValues, fixedData);
605
+ }
606
+ const secondParse = slimSchema.safeParse(fixedData);
607
+ const finalData = secondParse.success ? secondParse.data : fixedData;
608
+ if ((config.strict ?? true) === false) {
609
+ return {
610
+ data: finalData,
611
+ errors: void 0,
612
+ success: true,
613
+ formKey: _formKey
614
+ };
615
+ }
616
+ if (secondParse.success) {
617
+ return {
618
+ data: finalData,
619
+ errors: void 0,
620
+ success: true,
621
+ formKey: _formKey
622
+ };
623
+ }
624
+ return {
625
+ data: finalData,
626
+ errors: zodIssuesToValidationErrors(error.issues, _formKey),
627
+ success: false,
628
+ formKey: _formKey
629
+ };
630
+ },
631
+ getDefaultAtPath(path) {
632
+ if (path.length === 0) {
633
+ return getDefaultValuesFromZodSchema(_zodSchema, true, _formKey);
634
+ }
635
+ const leaf = walkV3ToLeafSchema(_zodSchema, path);
636
+ if (!leaf) return void 0;
637
+ const peeled = unwrapStructuralLeafV3(leaf);
638
+ return getDefaultValuesFromZodSchema(peeled, true, _formKey);
639
+ },
640
+ arrayShapeAtPath(path) {
641
+ if (path.length === 0) return void 0;
642
+ const leaf = walkV3ToLeafSchema(_zodSchema, path);
643
+ if (!leaf) return void 0;
644
+ let peeled = peelV3Wrappers(leaf);
645
+ for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
646
+ if (!isZodSchemaType(peeled, "ZodCatch")) break;
647
+ const inner = peeled._def.innerType;
648
+ if (!inner) break;
649
+ peeled = peelV3Wrappers(inner);
650
+ }
651
+ if (isZodSchemaType(peeled, "ZodTuple")) {
652
+ const items = peeled._def.items;
653
+ return Array.isArray(items) ? items.length : void 0;
654
+ }
655
+ if (isZodSchemaType(peeled, "ZodArray")) return null;
656
+ return void 0;
657
+ },
658
+ getSchemasAtPath(path) {
659
+ const [strippedSchema] = stripRootSchema(_zodSchema, {
660
+ stripDefaultValues: true,
661
+ stripNullable: true,
662
+ stripOptional: true,
663
+ stripZodEffects: true
664
+ });
665
+ const slimSchema = getSlimSchema({
666
+ schema: strippedSchema,
667
+ stripConfig: {
668
+ stripDefaultValues: true,
669
+ stripZodEffects: true
670
+ }
671
+ });
672
+ const nestedZodSchemas = getNestedZodSchemasAtPath(slimSchema, path);
673
+ if (!nestedZodSchemas.length) return [];
674
+ return nestedZodSchemas.map(
675
+ (n) => getAbstractSchema(_formKey, n, false)
676
+ );
677
+ },
678
+ isRequiredAtPath(path) {
679
+ if (path.length === 0) return true;
680
+ const leaf = walkV3ToLeafSchema(_zodSchema, path);
681
+ if (!leaf) return false;
682
+ return isLeafRequiredV3(leaf);
683
+ },
684
+ getFieldMetaAtPath(path) {
685
+ return resolveFieldMetaAtPathV3(_zodSchema, path);
686
+ },
687
+ getUnionDiscriminatorAtPath(path) {
688
+ const candidates = path.length === 0 ? [_zodSchema] : getNestedZodSchemasAtPath(_zodSchema, path);
689
+ let matchedUnion;
690
+ for (const candidate of candidates) {
691
+ const peeled = peelV3Wrappers(candidate);
692
+ if (!isZodSchemaType(peeled, "ZodDiscriminatedUnion")) continue;
693
+ if (matchedUnion !== void 0 && matchedUnion !== peeled) return void 0;
694
+ matchedUnion = peeled;
695
+ }
696
+ if (matchedUnion === void 0) return void 0;
697
+ const discKey = matchedUnion._def.discriminator;
698
+ const options = matchedUnion._def.options;
699
+ return {
700
+ discriminatorKey: discKey,
701
+ getVariantDefault(value) {
702
+ for (const opt of options) {
703
+ const litSchema = opt.shape[discKey];
704
+ if (!litSchema) continue;
705
+ if (!isZodSchemaType(litSchema, "ZodLiteral")) continue;
706
+ if (litSchema._def.value === value) {
707
+ return getDefaultValuesFromZodSchema(opt, true, _formKey);
708
+ }
709
+ }
710
+ return void 0;
711
+ }
712
+ };
713
+ },
714
+ getSlimPrimitiveTypesAtPath(path) {
715
+ if (path.length === 0) return /* @__PURE__ */ new Set(["object"]);
716
+ const [strippedSchema] = stripRootSchema(_zodSchema, {
717
+ stripDefaultValues: true,
718
+ stripNullable: true,
719
+ stripOptional: true,
720
+ stripZodEffects: true
721
+ });
722
+ const slimSchema = getSlimSchema({
723
+ schema: strippedSchema,
724
+ stripConfig: { stripDefaultValues: true, stripZodEffects: true }
725
+ });
726
+ const resolved = getNestedZodSchemasAtPath(slimSchema, path);
727
+ if (resolved.length === 0) return /* @__PURE__ */ new Set();
728
+ const out = /* @__PURE__ */ new Set();
729
+ for (const candidate of resolved) {
730
+ for (const k of slimPrimitivesV3(candidate)) out.add(k);
731
+ }
732
+ return out;
733
+ },
734
+ isLeafAtPath(path) {
735
+ const cacheKey = canonicalizePath(path).key;
736
+ const cached = leafCache.get(cacheKey);
737
+ if (cached !== void 0) return cached;
738
+ const prim = abstractSchema.getSlimPrimitiveTypesAtPath(path);
739
+ const isLeaf = prim.size > 0 && !prim.has("object") && !prim.has("array") && !prim.has("map") && !prim.has("set");
740
+ leafCache.set(cacheKey, isLeaf);
741
+ return isLeaf;
742
+ },
743
+ validateAtPath(data, path, options) {
744
+ const trySync = options?.sync === true;
745
+ if (trySync) {
746
+ try {
747
+ return runSync();
748
+ } catch {
749
+ }
750
+ }
751
+ return runAsync();
752
+ function runSync() {
753
+ if (path === void 0) {
754
+ const { success, data: successData, error } = _zodSchema.safeParse(data);
755
+ return success ? { data: successData, success, errors: void 0, formKey: _formKey } : {
756
+ success,
757
+ data: void 0,
758
+ errors: zodIssuesToValidationErrors(error.issues, _formKey),
759
+ formKey: _formKey
760
+ };
761
+ }
762
+ const nestedZodSchemas = nestedSchemasAtPath(path);
763
+ if (!nestedZodSchemas.length) return pathNotFound(path);
764
+ const accumulatedErrors = [];
765
+ for (const nestedSchema of nestedZodSchemas) {
766
+ const { data: successData, success, error } = nestedSchema.safeParse(data);
767
+ if (!success) {
768
+ accumulatedErrors.push(error);
769
+ continue;
770
+ }
771
+ return { data: successData, errors: void 0, success: true, formKey: _formKey };
772
+ }
773
+ return aggregatedFailure(accumulatedErrors);
774
+ }
775
+ async function runAsync() {
776
+ if (path === void 0) {
777
+ const { success, data: successData, error } = await _zodSchema.safeParseAsync(data);
778
+ return success ? { data: successData, success, errors: void 0, formKey: _formKey } : {
779
+ success,
780
+ data: void 0,
781
+ errors: zodIssuesToValidationErrors(error.issues, _formKey),
782
+ formKey: _formKey
783
+ };
784
+ }
785
+ const nestedZodSchemas = nestedSchemasAtPath(path);
786
+ if (!nestedZodSchemas.length) return pathNotFound(path);
787
+ const accumulatedErrors = [];
788
+ for (const nestedSchema of nestedZodSchemas) {
789
+ const { data: successData, success, error } = await nestedSchema.safeParseAsync(data);
790
+ if (!success) {
791
+ accumulatedErrors.push(error);
792
+ continue;
793
+ }
794
+ return { data: successData, errors: void 0, success: true, formKey: _formKey };
795
+ }
796
+ return aggregatedFailure(accumulatedErrors);
797
+ }
798
+ function nestedSchemasAtPath(p) {
799
+ const [strippedSchema] = stripRootSchema(_zodSchema, {
800
+ stripDefaultValues: true,
801
+ stripNullable: true,
802
+ stripOptional: true
803
+ });
804
+ const slimSchema = getSlimSchema({
805
+ schema: strippedSchema,
806
+ stripConfig: { stripDefaultValues: true }
807
+ });
808
+ return getNestedZodSchemasAtPath(slimSchema, p);
809
+ }
810
+ function pathNotFound(p) {
811
+ return {
812
+ data: void 0,
813
+ errors: NO_SCHEMAS_FOUND_AT_PATH_OF_CONCRETE_SCHEMA([...p], _formKey),
814
+ success: false,
815
+ formKey: _formKey
816
+ };
817
+ }
818
+ function aggregatedFailure(errors) {
819
+ const allIssues = errors.reduce((acc, e) => [...acc, ...e.issues], []);
820
+ return {
821
+ data: void 0,
822
+ errors: zodIssuesToValidationErrors(allIssues, _formKey),
823
+ success: false,
824
+ formKey: _formKey
825
+ };
826
+ }
827
+ }
828
+ };
829
+ return abstractSchema;
830
+ }
831
+ return (formKey) => getAbstractSchema(formKey, zodSchema, true);
832
+ }
833
+ function zodIssuesToValidationErrors(issues, formKey) {
834
+ const validationErrors = [];
835
+ for (const issue of issues) {
836
+ let code;
837
+ if (typeof issue.code === "string" && issue.code.length > 0) {
838
+ code = `zod:${issue.code}`;
839
+ } else {
840
+ code = "zod:unknown";
841
+ if (__DEV__ && !warnedZodCodeMissing) {
842
+ warnedZodCodeMissing = true;
843
+ console.warn(
844
+ "[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."
845
+ );
846
+ }
847
+ }
848
+ validationErrors.push({
849
+ message: issue.message,
850
+ // `ValidationError.path` is `(string | number)[]` per the
851
+ // public type. v3's `issue.path` is the same in the standard
852
+ // case, but a custom check via `ctx.addIssue({ path: [...] })`
853
+ // can smuggle a Symbol through — the public surface promised
854
+ // strings/numbers, so coerce defensively to keep the contract.
855
+ // Mirrors v4's behaviour at the same site.
856
+ path: coercePathSegments(issue.path),
857
+ formKey,
858
+ code
859
+ });
860
+ }
861
+ return validationErrors;
862
+ }
863
+ function coercePathSegments(path) {
864
+ const out = [];
865
+ for (const seg of path) {
866
+ out.push(typeof seg === "number" ? seg : typeof seg === "string" ? seg : String(seg));
867
+ }
868
+ return out;
869
+ }
870
+ const NO_SCHEMAS_FOUND_AT_PATH_OF_CONCRETE_SCHEMA = (path, formKey) => [
871
+ {
872
+ message: `Programming Error: useForm.validateAtPath failed to find 1 or more schemas corresponding to the path ${path} in the concrete schema. Does the nested schema exist on form with key '${formKey}'?`,
873
+ path,
874
+ formKey,
875
+ code: AttaformErrorCode.PathNotFound
876
+ }
877
+ ];
878
+ function getNestedZodSchemasAtPath(zodSchema, segments) {
879
+ function getOptionSchemasFromDiscriminatorByArbitraryKey(schema, key) {
880
+ const successfulOptions = [];
881
+ const options = schema._def.options;
882
+ for (const option of options) {
883
+ if (!(key in option.shape)) continue;
884
+ successfulOptions.push(option);
885
+ }
886
+ return successfulOptions;
887
+ }
888
+ let currentSchema = zodSchema;
889
+ for (let index = 0; index < segments.length; index++) {
890
+ const key = String(segments[index] ?? "");
891
+ if (isZodSchemaType(currentSchema, "ZodObject")) {
892
+ const shape = currentSchema._def.shape();
893
+ currentSchema = Object.hasOwn(shape, key) ? shape[key] : void 0;
894
+ } else if (isZodSchemaType(currentSchema, "ZodArray")) {
895
+ currentSchema = currentSchema._def.type;
896
+ } else if (isZodSchemaType(currentSchema, "ZodSet")) {
897
+ currentSchema = currentSchema._def.valueType;
898
+ } else if (isZodSchemaType(currentSchema, "ZodRecord")) {
899
+ currentSchema = currentSchema._def.valueType;
900
+ } else if (isZodSchemaType(currentSchema, "ZodDiscriminatedUnion")) {
901
+ const optionalSchemas = getOptionSchemasFromDiscriminatorByArbitraryKey(currentSchema, key);
902
+ const remainingSegments = segments.slice(index);
903
+ if (!remainingSegments.length) return optionalSchemas;
904
+ const foundSchemas = [];
905
+ for (const optionSchema of optionalSchemas) {
906
+ getNestedZodSchemasAtPath(optionSchema, remainingSegments).forEach((schema) => {
907
+ foundSchemas.push(schema);
908
+ });
909
+ }
910
+ return foundSchemas;
911
+ } else {
912
+ return [];
913
+ }
914
+ }
915
+ if (!currentSchema) return [];
916
+ return [currentSchema];
917
+ }
918
+ function unwrapStructuralLeafV3(schema) {
919
+ let current = schema;
920
+ for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
921
+ if (!(isZodSchemaType(current, "ZodOptional") || isZodSchemaType(current, "ZodNullable"))) {
922
+ break;
923
+ }
924
+ const inner = current._def.innerType;
925
+ if (!inner) return current;
926
+ if (!isStructuralV3Kind(inner)) break;
927
+ current = inner;
928
+ }
929
+ return current;
930
+ }
931
+ function isStructuralV3Kind(schema) {
932
+ 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
933
+ // peeling at the next iteration.
934
+ isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodEffects") || // Newer transparent wrappers (v3.23+). Each wraps a single inner
935
+ // schema with no structural impact — `peelV3Wrappers` resolves them.
936
+ isZodSchemaType(schema, "ZodPipeline") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodBranded");
937
+ }
938
+ function peelV3Wrappers(schema) {
939
+ let current = schema;
940
+ for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
941
+ if (isZodSchemaType(current, "ZodOptional") || isZodSchemaType(current, "ZodNullable") || isZodSchemaType(current, "ZodDefault")) {
942
+ const inner = current._def.innerType;
943
+ if (!inner) return current;
944
+ current = inner;
945
+ continue;
946
+ }
947
+ if (isZodSchemaType(current, "ZodEffects")) {
948
+ const inner = current._def.schema;
949
+ if (!inner) return current;
950
+ current = inner;
951
+ continue;
952
+ }
953
+ if (isZodSchemaType(current, "ZodPipeline")) {
954
+ const inner = current._def.in;
955
+ if (!inner) return current;
956
+ current = inner;
957
+ continue;
958
+ }
959
+ if (isZodSchemaType(current, "ZodReadonly")) {
960
+ const inner = current._def.innerType;
961
+ if (!inner) return current;
962
+ current = inner;
963
+ continue;
964
+ }
965
+ if (isZodSchemaType(current, "ZodBranded")) {
966
+ const inner = current._def.type;
967
+ if (!inner) return current;
968
+ current = inner;
969
+ continue;
970
+ }
971
+ break;
972
+ }
973
+ return current;
974
+ }
975
+ function walkV3ToLeafSchema(schema, segments) {
976
+ let current = schema;
977
+ let i = 0;
978
+ let safetyTicks = 0;
979
+ while (i < segments.length && current && safetyTicks < segments.length * MAX_UNWRAP_STEPS + MAX_UNWRAP_STEPS) {
980
+ safetyTicks++;
981
+ current = peelV3Wrappers(current);
982
+ const key = String(segments[i] ?? "");
983
+ if (isZodSchemaType(current, "ZodObject")) {
984
+ const shape = current._def.shape();
985
+ current = Object.hasOwn(shape, key) ? shape[key] : void 0;
986
+ i++;
987
+ continue;
988
+ }
989
+ if (isZodSchemaType(current, "ZodArray")) {
990
+ current = current._def.type;
991
+ i++;
992
+ continue;
993
+ }
994
+ if (isZodSchemaType(current, "ZodRecord")) {
995
+ current = current._def.valueType;
996
+ i++;
997
+ continue;
998
+ }
999
+ if (isZodSchemaType(current, "ZodTuple")) {
1000
+ const idx = Number(key);
1001
+ if (!Number.isInteger(idx) || idx < 0) return void 0;
1002
+ const items = current._def.items;
1003
+ const item = items[idx];
1004
+ if (!item) return void 0;
1005
+ current = item;
1006
+ i++;
1007
+ continue;
1008
+ }
1009
+ if (isZodSchemaType(current, "ZodDiscriminatedUnion")) {
1010
+ const options = current._def.options;
1011
+ const matching = options.filter((o) => key in o.shape);
1012
+ const candidates = matching.length > 0 ? matching : options;
1013
+ const first = candidates[0];
1014
+ if (!first) return void 0;
1015
+ current = first;
1016
+ continue;
1017
+ }
1018
+ if (isZodSchemaType(current, "ZodUnion")) {
1019
+ const options = current._def.options;
1020
+ const first = options[0];
1021
+ if (!first) return void 0;
1022
+ current = first;
1023
+ continue;
1024
+ }
1025
+ return void 0;
1026
+ }
1027
+ return current;
1028
+ }
1029
+ function isLeafRequiredV3(schema, depth = 0) {
1030
+ if (depth > MAX_UNWRAP_STEPS) return true;
1031
+ if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodUndefined") || isZodSchemaType(schema, "ZodNull")) {
1032
+ return false;
1033
+ }
1034
+ if (isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodBranded")) {
1035
+ const inner = schema._def.innerType;
1036
+ const branded = schema._def.type;
1037
+ const next = inner ?? branded;
1038
+ return next === void 0 ? true : isLeafRequiredV3(next, depth + 1);
1039
+ }
1040
+ if (isZodSchemaType(schema, "ZodPipeline")) {
1041
+ const inner = schema._def.in;
1042
+ return inner === void 0 ? true : isLeafRequiredV3(inner, depth + 1);
1043
+ }
1044
+ if (isZodSchemaType(schema, "ZodEffects")) {
1045
+ const inner = schema._def.schema;
1046
+ return inner === void 0 ? true : isLeafRequiredV3(inner, depth + 1);
1047
+ }
1048
+ if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
1049
+ const options = schema._def.options ?? [];
1050
+ if (options.length === 0) return true;
1051
+ return options.every((opt) => isLeafRequiredV3(opt, depth + 1));
1052
+ }
1053
+ if (isZodSchemaType(schema, "ZodIntersection")) {
1054
+ const def = schema._def;
1055
+ const leftReq = def.left === void 0 ? true : isLeafRequiredV3(def.left, depth + 1);
1056
+ const rightReq = def.right === void 0 ? true : isLeafRequiredV3(def.right, depth + 1);
1057
+ return leftReq || rightReq;
1058
+ }
1059
+ return true;
1060
+ }
1061
+ function unwrapToDiscriminatedUnion(schema) {
1062
+ let currentSchema = schema;
1063
+ for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
1064
+ if (isZodSchemaType(currentSchema, "ZodDiscriminatedUnion")) {
1065
+ return currentSchema;
1066
+ }
1067
+ if (isZodSchemaType(currentSchema, "ZodDefault") || isZodSchemaType(currentSchema, "ZodOptional") || isZodSchemaType(currentSchema, "ZodNullable")) {
1068
+ currentSchema = currentSchema._def.innerType;
1069
+ continue;
1070
+ }
1071
+ if (isZodSchemaType(currentSchema, "ZodReadonly")) {
1072
+ const inner = currentSchema._def.innerType;
1073
+ if (!inner) return void 0;
1074
+ currentSchema = inner;
1075
+ continue;
1076
+ }
1077
+ if (isZodSchemaType(currentSchema, "ZodBranded")) {
1078
+ const inner = currentSchema._def.type;
1079
+ if (!inner) return void 0;
1080
+ currentSchema = inner;
1081
+ continue;
1082
+ }
1083
+ if (isZodSchemaType(currentSchema, "ZodPipeline")) {
1084
+ const inner = currentSchema._def.in;
1085
+ if (!inner) return void 0;
1086
+ currentSchema = inner;
1087
+ continue;
1088
+ }
1089
+ return void 0;
1090
+ }
1091
+ return void 0;
1092
+ }
1093
+ function getDefaultValue(expected, context) {
1094
+ const discriminatorContext = context.discriminator;
1095
+ if (discriminatorContext.isDiscriminatorKey) {
1096
+ if (!discriminatorContext.schema) {
1097
+ throw new Error("discriminatorContext.schema unspecified");
1098
+ }
1099
+ if (!isZodSchemaType(discriminatorContext.schema, "ZodDiscriminatedUnion")) {
1100
+ throw new TypeError(
1101
+ "Programming error: discriminatorContext.schema is not a ZodDiscriminatedUnion schema."
1102
+ );
1103
+ }
1104
+ const optionDiscriminator = getSchemaByDiscriminatorKey(
1105
+ discriminatorContext.schema);
1106
+ if (!optionDiscriminator) {
1107
+ throw new Error("ZodDiscriminatedUnion: default option not found");
1108
+ }
1109
+ return getDefaultValuesFromZodSchema(
1110
+ optionDiscriminator,
1111
+ discriminatorContext.useDefaultSchemaValues,
1112
+ context.formKey
1113
+ );
1114
+ }
1115
+ if (expected === "string") return "";
1116
+ if (expected === "number") return 0;
1117
+ if (expected === "array") return [];
1118
+ if (expected === "boolean") return false;
1119
+ if (expected === "bigint") return 0n;
1120
+ if (expected === "float") return 0;
1121
+ if (expected === "integer") return 0;
1122
+ if (expected === "null") return null;
1123
+ if (expected === "object") return {};
1124
+ if (expected === "set") return /* @__PURE__ */ new Set();
1125
+ if (expected === "date") return /* @__PURE__ */ new Date();
1126
+ if (expected === "map") return /* @__PURE__ */ new Map();
1127
+ if (expected === "promise") return new Promise((res) => res(void 0));
1128
+ if (expected === "symbol") return Symbol();
1129
+ if (expected === "function") return () => void 0;
1130
+ if (expected === "undefined") return void 0;
1131
+ if (expected === "unknown") return void 0;
1132
+ if (expected === "nan") return Number("nan");
1133
+ return void 0;
1134
+ }
1135
+ function unwrapDefault(schema) {
1136
+ let current = schema;
1137
+ for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
1138
+ if (isZodSchemaType(current, "ZodDefault")) {
1139
+ const defaultValue = current._def.defaultValue();
1140
+ return [defaultValue, true];
1141
+ }
1142
+ if (isZodSchemaType(current, "ZodCatch")) {
1143
+ const catchValue = current._def.catchValue;
1144
+ if (typeof catchValue === "function") {
1145
+ return [catchValue({ error: null, input: void 0 }), true];
1146
+ }
1147
+ const inner = current._def.innerType;
1148
+ if (!inner) break;
1149
+ current = inner;
1150
+ continue;
1151
+ }
1152
+ if (isZodSchemaType(current, "ZodNullable") || isZodSchemaType(current, "ZodOptional")) {
1153
+ current = current._def.innerType;
1154
+ continue;
1155
+ }
1156
+ if (isZodSchemaType(current, "ZodReadonly")) {
1157
+ const inner = current._def.innerType;
1158
+ if (!inner) break;
1159
+ current = inner;
1160
+ continue;
1161
+ }
1162
+ if (isZodSchemaType(current, "ZodBranded")) {
1163
+ const inner = current._def.type;
1164
+ if (!inner) break;
1165
+ current = inner;
1166
+ continue;
1167
+ }
1168
+ if (isZodSchemaType(current, "ZodPipeline")) {
1169
+ const inner = current._def.in;
1170
+ if (!inner) break;
1171
+ current = inner;
1172
+ continue;
1173
+ }
1174
+ if (isZodSchemaType(current, "ZodEffects")) {
1175
+ const effect = current._def.effect;
1176
+ if (effect !== null && typeof effect === "object" && "_def" in effect) {
1177
+ current = effect;
1178
+ continue;
1179
+ }
1180
+ const inner = current.innerType?.();
1181
+ if (inner) {
1182
+ current = inner;
1183
+ continue;
1184
+ }
1185
+ break;
1186
+ }
1187
+ break;
1188
+ }
1189
+ return [null, false];
1190
+ }
1191
+ function getDefaultValuesFromZodSchema(formSchema, useDefaultSchemaValues, formKey) {
1192
+ function generateValue(schema) {
1193
+ if (useDefaultSchemaValues) {
1194
+ const [defaultValue, foundDefaultValue] = unwrapDefault(schema);
1195
+ if (foundDefaultValue) {
1196
+ return defaultValue;
1197
+ }
1198
+ }
1199
+ if (isZodSchemaType(schema, "ZodNullable")) {
1200
+ return null;
1201
+ }
1202
+ if (isZodSchemaType(schema, "ZodObject")) {
1203
+ const shape = schema.shape;
1204
+ return Object.keys(shape).reduce((acc, key) => {
1205
+ acc[key] = generateValue(shape[key]);
1206
+ return acc;
1207
+ }, {});
1208
+ }
1209
+ if (isZodSchemaType(schema, "ZodArray")) {
1210
+ return [];
1211
+ }
1212
+ if (isZodSchemaType(schema, "ZodString")) {
1213
+ return "";
1214
+ }
1215
+ if (isZodSchemaType(schema, "ZodNumber")) {
1216
+ return 0;
1217
+ }
1218
+ if (isZodSchemaType(schema, "ZodBigInt")) {
1219
+ return 0n;
1220
+ }
1221
+ if (isZodSchemaType(schema, "ZodDate")) {
1222
+ return /* @__PURE__ */ new Date(0);
1223
+ }
1224
+ if (isZodSchemaType(schema, "ZodBoolean")) {
1225
+ return false;
1226
+ }
1227
+ if (isZodSchemaType(schema, "ZodEnum")) {
1228
+ return schema.options[0];
1229
+ }
1230
+ if (isZodSchemaType(schema, "ZodNull")) {
1231
+ return null;
1232
+ }
1233
+ if (isZodSchemaType(schema, "ZodUndefined")) {
1234
+ return void 0;
1235
+ }
1236
+ if (isZodSchemaType(schema, "ZodLiteral")) {
1237
+ return schema._def.value;
1238
+ }
1239
+ if (isZodSchemaType(schema, "ZodOptional")) {
1240
+ return void 0;
1241
+ }
1242
+ if (isZodSchemaType(schema, "ZodUnion")) {
1243
+ return generateValue(schema._def.options[0]);
1244
+ }
1245
+ if (isZodSchemaType(schema, "ZodTuple")) {
1246
+ return schema._def.items.map((item) => generateValue(item));
1247
+ }
1248
+ if (isZodSchemaType(schema, "ZodRecord")) {
1249
+ return {};
1250
+ }
1251
+ if (isZodSchemaType(schema, "ZodDefault")) {
1252
+ return generateValue(schema._def.innerType);
1253
+ }
1254
+ if (isZodSchemaType(schema, "ZodEffects")) {
1255
+ return generateValue(schema.innerType());
1256
+ }
1257
+ if (isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
1258
+ const discriminantSchema = getSchemaByDiscriminatorKey(schema);
1259
+ return generateValue(discriminantSchema);
1260
+ }
1261
+ if (isZodSchemaType(schema, "ZodCatch")) {
1262
+ const catchValue = schema._def.catchValue;
1263
+ if (typeof catchValue === "function") {
1264
+ return catchValue({ error: null, input: void 0 });
1265
+ }
1266
+ const inner = schema._def.innerType;
1267
+ if (inner) return generateValue(inner);
1268
+ }
1269
+ if (isZodSchemaType(schema, "ZodReadonly")) {
1270
+ const inner = schema._def.innerType;
1271
+ if (inner) return generateValue(inner);
1272
+ }
1273
+ if (isZodSchemaType(schema, "ZodBranded")) {
1274
+ const inner = schema._def.type;
1275
+ if (inner) return generateValue(inner);
1276
+ }
1277
+ if (isZodSchemaType(schema, "ZodPipeline")) {
1278
+ const inner = schema._def.in;
1279
+ if (inner) return generateValue(inner);
1280
+ }
1281
+ if (isZodSchemaType(schema, "ZodLazy")) {
1282
+ const inner = schema._def.getter?.();
1283
+ if (inner) return generateValue(inner);
1284
+ }
1285
+ if (isZodSchemaType(schema, "ZodIntersection")) {
1286
+ const def = schema._def;
1287
+ const left = def.left ? generateValue(def.left) : void 0;
1288
+ const right = def.right ? generateValue(def.right) : void 0;
1289
+ return merge({}, left, right);
1290
+ }
1291
+ if (isZodSchemaType(schema, "ZodNativeEnum")) {
1292
+ const values = schema._def.values;
1293
+ if (values) {
1294
+ const lookup = values;
1295
+ const validKeys = Object.keys(lookup).filter(
1296
+ (k) => typeof lookup[lookup[k]] !== "number"
1297
+ );
1298
+ if (validKeys.length > 0) {
1299
+ const first = validKeys[0];
1300
+ if (first !== void 0) return lookup[first];
1301
+ }
1302
+ }
1303
+ }
1304
+ if (isZodSchemaType(schema, "ZodSet")) {
1305
+ return /* @__PURE__ */ new Set();
1306
+ }
1307
+ console.warn(
1308
+ `[attaform] zod-v3 adapter: unsupported schema kind '${schema.constructor.name}' on form '${formKey}'. Defaulting the field to null. Use a supported zod kind (object/array/record/string/number/etc.) at this path.`
1309
+ );
1310
+ return null;
1311
+ }
1312
+ return generateValue(formSchema);
1313
+ }
1314
+ function getSchemaByDiscriminatorKey(unionSchema, key) {
1315
+ if (!isZodSchemaType(unionSchema, "ZodDiscriminatedUnion")) {
1316
+ throw new TypeError("Provided schema is not a discriminated union.");
1317
+ }
1318
+ {
1319
+ const options = unionSchema._def.options;
1320
+ if (!options.length) {
1321
+ throw new TypeError("Provided ZodDiscriminatedUnion does not have any options");
1322
+ }
1323
+ return options[0];
1324
+ }
1325
+ }
1326
+ function hasChecks(schema) {
1327
+ if (!("_def" in schema)) return false;
1328
+ const schemaDef = schema._def;
1329
+ if (!("checks" in schemaDef)) return false;
1330
+ const checks = schemaDef["checks"];
1331
+ if (!Array.isArray(checks)) return false;
1332
+ return checks.length > 0;
1333
+ }
1334
+ function stripRefinements(schema) {
1335
+ function _stripRefinements(_schema, depth) {
1336
+ if (depth >= MAX_UNWRAP_STEPS) return _schema;
1337
+ if (isZodSchemaType(_schema, "ZodString") && _schema._def.checks.length > 0) {
1338
+ return z.string();
1339
+ }
1340
+ if (isZodSchemaType(_schema, "ZodNumber") && _schema._def.checks.length > 0) {
1341
+ return z.number();
1342
+ }
1343
+ if (isZodSchemaType(_schema, "ZodArray")) {
1344
+ return z.array(_stripRefinements(_schema._def.type, depth + 1));
1345
+ }
1346
+ if (isZodSchemaType(_schema, "ZodObject")) {
1347
+ const shape = _schema.shape;
1348
+ const strippedShape = Object.fromEntries(
1349
+ Object.entries(shape).map(([key, value]) => [
1350
+ key,
1351
+ _stripRefinements(value, depth + 1)
1352
+ ])
1353
+ );
1354
+ return z.object(strippedShape);
1355
+ }
1356
+ if (isZodSchemaType(_schema, "ZodEffects")) {
1357
+ return _stripRefinements(_schema.innerType(), depth + 1);
1358
+ }
1359
+ if (isZodSchemaType(_schema, "ZodOptional")) {
1360
+ return z.optional(_stripRefinements(_schema.unwrap(), depth + 1));
1361
+ }
1362
+ if (isZodSchemaType(_schema, "ZodNullable")) {
1363
+ return z.nullable(_stripRefinements(_schema.unwrap(), depth + 1));
1364
+ }
1365
+ if (isZodSchemaType(_schema, "ZodReadonly")) {
1366
+ const inner = _schema._def.innerType;
1367
+ if (!inner) return _schema;
1368
+ return _stripRefinements(inner, depth + 1);
1369
+ }
1370
+ if (isZodSchemaType(_schema, "ZodBranded")) {
1371
+ const inner = _schema._def.type;
1372
+ if (!inner) return _schema;
1373
+ return _stripRefinements(inner, depth + 1);
1374
+ }
1375
+ if (isZodSchemaType(_schema, "ZodPipeline")) {
1376
+ const inner = _schema._def.in;
1377
+ if (!inner) return _schema;
1378
+ return _stripRefinements(inner, depth + 1);
1379
+ }
1380
+ if (isZodSchemaType(_schema, "ZodSet")) {
1381
+ const valueType = _schema._def.valueType;
1382
+ if (!valueType) return _schema;
1383
+ return z.set(_stripRefinements(valueType, depth + 1));
1384
+ }
1385
+ if (isZodSchemaType(_schema, "ZodTuple")) {
1386
+ const items = _schema._def.items;
1387
+ if (!items) return _schema;
1388
+ const stripped = items.map((it) => _stripRefinements(it, depth + 1));
1389
+ return z.tuple(stripped);
1390
+ }
1391
+ if (isZodSchemaType(_schema, "ZodRecord")) {
1392
+ const def = _schema._def;
1393
+ if (!def.valueType) return _schema;
1394
+ const value = _stripRefinements(def.valueType, depth + 1);
1395
+ if (def.keyType) {
1396
+ return z.record(def.keyType, value);
1397
+ }
1398
+ return z.record(value);
1399
+ }
1400
+ if (isZodSchemaType(_schema, "ZodUnion")) {
1401
+ const options = _schema._def.options;
1402
+ if (!options) return _schema;
1403
+ const stripped = options.map((o) => _stripRefinements(o, depth + 1));
1404
+ return z.union(stripped);
1405
+ }
1406
+ if (isZodSchemaType(_schema, "ZodDiscriminatedUnion")) {
1407
+ const def = _schema._def;
1408
+ if (def.discriminator === void 0 || !def.options) return _schema;
1409
+ const stripped = def.options.map(
1410
+ (o) => _stripRefinements(o, depth + 1)
1411
+ );
1412
+ return z.discriminatedUnion(
1413
+ def.discriminator,
1414
+ stripped
1415
+ );
1416
+ }
1417
+ if (isZodSchemaType(_schema, "ZodIntersection")) {
1418
+ const def = _schema._def;
1419
+ if (!def.left || !def.right) return _schema;
1420
+ return z.intersection(
1421
+ _stripRefinements(def.left, depth + 1),
1422
+ _stripRefinements(def.right, depth + 1)
1423
+ );
1424
+ }
1425
+ if (isZodSchemaType(_schema, "ZodLazy")) {
1426
+ const getter = _schema._def.getter;
1427
+ if (!getter) return _schema;
1428
+ const stripped = _stripRefinements(getter(), depth + 1);
1429
+ return z.lazy(() => stripped);
1430
+ }
1431
+ return _schema;
1432
+ }
1433
+ return _stripRefinements(schema, 0);
1434
+ }
1435
+ function stripRootSchema(schema, stripConfig) {
1436
+ function recursion(_schema, _stripped = false) {
1437
+ if (getStripInstruction(stripConfig.stripNullable, _schema) && isZodSchemaType(_schema, "ZodNullable")) {
1438
+ return recursion(_schema.unwrap(), true);
1439
+ }
1440
+ if (getStripInstruction(stripConfig.stripOptional, _schema) && isZodSchemaType(_schema, "ZodOptional")) {
1441
+ return recursion(_schema.unwrap(), true);
1442
+ }
1443
+ if (getStripInstruction(stripConfig.stripZodEffects, _schema) && isZodSchemaType(_schema, "ZodEffects")) {
1444
+ return recursion(_schema.innerType(), true);
1445
+ }
1446
+ if (getStripInstruction(stripConfig.stripDefaultValues, _schema) && isZodSchemaType(_schema, "ZodDefault")) {
1447
+ return recursion(_schema._def.innerType, true);
1448
+ }
1449
+ if (getStripInstruction(stripConfig.stripZodRefinements, _schema) && hasChecks(_schema)) {
1450
+ return recursion(stripRefinements(_schema));
1451
+ }
1452
+ return [_schema, _stripped];
1453
+ }
1454
+ return recursion(schema, false);
1455
+ }
1456
+ const getStripInstruction = (stripValueOrCallback, schema) => {
1457
+ if (stripValueOrCallback === void 0 || stripValueOrCallback === false) return false;
1458
+ return isFunction(stripValueOrCallback) ? stripValueOrCallback(schema) : stripValueOrCallback;
1459
+ };
1460
+ function getSlimSchema(config) {
1461
+ function _getSlimSchema(_schema) {
1462
+ if (isZodSchemaType(_schema, "ZodObject")) {
1463
+ const newShape = {};
1464
+ for (const key in _schema.shape) {
1465
+ const value = _schema.shape[key];
1466
+ newShape[key] = _getSlimSchema(value);
1467
+ }
1468
+ return z.object(newShape);
1469
+ }
1470
+ if (isZodSchemaType(_schema, "ZodArray")) {
1471
+ return z.array(_getSlimSchema(_schema.element));
1472
+ }
1473
+ if (isZodSchemaType(_schema, "ZodRecord")) {
1474
+ const key = _getSlimSchema(_schema._def.keyType);
1475
+ const value = _getSlimSchema(_schema._def.valueType);
1476
+ return z.record(key, value);
1477
+ }
1478
+ if (isZodSchemaType(_schema, "ZodDiscriminatedUnion")) {
1479
+ const slimmedSchemas = [];
1480
+ for (const option of _schema._def.options) {
1481
+ const slimmedSchema = _getSlimSchema(option);
1482
+ const deepCloneSlimmedSchema = cloneDeep(slimmedSchema);
1483
+ slimmedSchemas.push(deepCloneSlimmedSchema);
1484
+ }
1485
+ return z.discriminatedUnion(
1486
+ _schema._def.discriminator,
1487
+ slimmedSchemas
1488
+ );
1489
+ }
1490
+ if (getStripInstruction(config.stripConfig.stripZodEffects, _schema) && isZodSchemaType(_schema, "ZodEffects")) {
1491
+ return _getSlimSchema(_schema.innerType());
1492
+ }
1493
+ if (getStripInstruction(config.stripConfig.stripNullable, _schema) && isZodSchemaType(_schema, "ZodNullable")) {
1494
+ return _getSlimSchema(_schema._def.innerType);
1495
+ }
1496
+ if (getStripInstruction(config.stripConfig.stripOptional, _schema) && isZodSchemaType(_schema, "ZodOptional")) {
1497
+ return _getSlimSchema(_schema._def.innerType);
1498
+ }
1499
+ if (getStripInstruction(config.stripConfig.stripZodRefinements, _schema) && hasChecks(_schema)) {
1500
+ return stripRefinements(_schema);
1501
+ }
1502
+ if (getStripInstruction(config.stripConfig.stripDefaultValues, _schema) && isZodSchemaType(_schema, "ZodDefault")) {
1503
+ return _getSlimSchema(_schema._def.innerType);
1504
+ }
1505
+ const unionSchema = unwrapToDiscriminatedUnion(_schema);
1506
+ if (unionSchema && getStripInstruction(config.stripConfig.stripDefaultValues, unionSchema)) {
1507
+ return _getSlimSchema(unionSchema);
1508
+ }
1509
+ return _schema;
1510
+ }
1511
+ const processedRootSchema = stripRootSchema(config.schema, config.stripConfig)[0];
1512
+ return _getSlimSchema(processedRootSchema);
1513
+ }
1514
+ function resolveFieldMetaAtPathV3(rootSchema, path) {
1515
+ const lastSegment = path.length === 0 ? "" : path[path.length - 1];
1516
+ const target = path.length === 0 ? rootSchema : walkV3ToLeafSchema(rootSchema, path);
1517
+ if (target === void 0) {
1518
+ return {
1519
+ label: humanize(lastSegment),
1520
+ description: void 0,
1521
+ placeholder: void 0,
1522
+ meta: Object.freeze({})
1523
+ };
1524
+ }
1525
+ const peeled = peelV3Wrappers(target);
1526
+ const payload = getFieldMeta(target) ?? (peeled !== target ? getFieldMeta(peeled) : void 0);
1527
+ const targetDescription = typeof target.description === "string" ? target.description : void 0;
1528
+ const peeledDescription = peeled !== target && typeof peeled.description === "string" ? peeled.description : void 0;
1529
+ const schemaDescription = targetDescription ?? peeledDescription;
1530
+ return {
1531
+ label: payload?.label ?? humanize(lastSegment),
1532
+ description: payload?.description ?? schemaDescription ?? void 0,
1533
+ placeholder: payload?.placeholder ?? void 0,
1534
+ meta: Object.freeze({ ...payload ?? {} })
1535
+ };
1536
+ }
1537
+
1538
+ function useForm(configuration) {
1539
+ if (configuration === void 0 || configuration === null || configuration.schema === void 0) {
1540
+ throw new InvalidUseFormConfigError();
1541
+ }
1542
+ function isZodType(value) {
1543
+ return typeof value === "object" && value !== null && "_def" in value;
1544
+ }
1545
+ const { schema } = configuration;
1546
+ const abstractSchema = isZodType(schema) ? zodAdapter(schema) : schema;
1547
+ return useAbstractForm({
1548
+ ...configuration,
1549
+ schema: abstractSchema,
1550
+ defaultValues: configuration.defaultValues
1551
+ });
1552
+ }
1553
+
1554
+ export { fieldMeta as f, isZodSchemaType as i, useForm as u, withMeta as w, zodAdapter as z };
1555
+ //# sourceMappingURL=attaform.DdnithOf.mjs.map