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