attaform 0.28.0 → 0.30.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 (66) hide show
  1. package/dist/abstract.d.mts +5 -5
  2. package/dist/abstract.mjs +4 -4
  3. package/dist/dev/abstract.mjs +4 -4
  4. package/dist/dev/chunks/dev-key-collision-warnings.mjs +47 -8
  5. package/dist/dev/chunks/devtools.mjs +1 -1
  6. package/dist/dev/directive.mjs +1 -1
  7. package/dist/dev/history.mjs +1 -2
  8. package/dist/dev/index.mjs +5 -5
  9. package/dist/dev/runtime/plugins/attaform.mjs +3 -3
  10. package/dist/dev/shared/{attaform-dev.oYrkP9dj.mjs → attaform-dev.BK6Ge2qR.mjs} +80 -341
  11. package/dist/dev/shared/{attaform-dev.Dr2YzS5B.mjs → attaform-dev.BQc5QV3Y.mjs} +11 -19
  12. package/dist/dev/shared/{attaform-dev.BR8u0YOZ.mjs → attaform-dev.BcNtyOmf.mjs} +4 -4
  13. package/dist/{shared/attaform.h0i6LijT.mjs → dev/shared/attaform-dev.BcYT6tFh.mjs} +152 -20
  14. package/dist/dev/shared/{attaform-dev.6qxD-Yqo.mjs → attaform-dev.BisFstxh.mjs} +227 -88
  15. package/dist/dev/shared/{attaform-dev.WmuhD_CZ.mjs → attaform-dev.CQ2rJiAX.mjs} +833 -656
  16. package/dist/dev/shared/{attaform-dev.P7cseiEG.mjs → attaform-dev.D6CLvaQT.mjs} +20 -11
  17. package/dist/dev/shared/{attaform-dev.D2I8e_Mm.mjs → attaform-dev.DTrHonpc.mjs} +225 -238
  18. package/dist/dev/shared/{attaform-dev.BXE2cr0L.mjs → attaform-dev.DUZckyV8.mjs} +1 -3
  19. package/dist/dev/zod-v3.mjs +6 -6
  20. package/dist/dev/zod-v4.mjs +6 -6
  21. package/dist/dev/zod.mjs +5 -5
  22. package/dist/directive.d.mts +2 -2
  23. package/dist/directive.mjs +1 -1
  24. package/dist/history.d.mts +1 -1
  25. package/dist/history.mjs +1 -2
  26. package/dist/index.d.mts +9 -7
  27. package/dist/index.mjs +5 -5
  28. package/dist/nuxt.d.mts +11 -20
  29. package/dist/nuxt.mjs +0 -1
  30. package/dist/runtime/plugins/attaform.mjs +3 -3
  31. package/dist/shared/{attaform.uLbun31C.mjs → attaform.B3resMQ1.mjs} +19 -11
  32. package/dist/shared/{attaform.Cs2Rbdlo.mjs → attaform.BK0cgu2K.mjs} +123 -139
  33. package/dist/{dev/shared/attaform-dev.By4PRjt0.mjs → shared/attaform.BRDDQeHV.mjs} +136 -26
  34. package/dist/shared/{attaform.NLmerepI.mjs → attaform.BXneBxEj.mjs} +71 -334
  35. package/dist/shared/{attaform.D6DCnnQu.mjs → attaform.ByWP6kSx.mjs} +4 -4
  36. package/dist/shared/{attaform.CJP3RkGa.mjs → attaform.CJ8DpRGj.mjs} +223 -238
  37. package/dist/shared/{attaform.C09fpdLS.mjs → attaform.CUfrMK7t.mjs} +227 -88
  38. package/dist/shared/{attaform.wfY8XFvm.mjs → attaform.CdZIEf7_.mjs} +11 -19
  39. package/dist/shared/{attaform.JfSWdEcb.d.mts → attaform.Clz0ArIi.d.mts} +1 -1
  40. package/dist/shared/{attaform.B8k8JrmK.mjs → attaform.DNJOWjQw.mjs} +826 -612
  41. package/dist/shared/{attaform.B4VkS43-.d.mts → attaform.Rc9u4Vfw.d.mts} +1 -1
  42. package/dist/shared/{attaform.D5V4tZWq.d.mts → attaform.UGyOK83T.d.mts} +200 -218
  43. package/dist/shared/{attaform.Dq4vWxuG.mjs → attaform.WiGdIqgx.mjs} +1 -3
  44. package/dist/shared/{attaform.Cgu-hdSb.d.mts → attaform.bKLzMU0o.d.mts} +321 -523
  45. package/dist/transforms.d.mts +0 -22
  46. package/dist/transforms.mjs +1 -1
  47. package/dist/vite.d.mts +13 -4
  48. package/dist/vite.mjs +8 -2
  49. package/dist/zod-v3.d.mts +6 -4
  50. package/dist/zod-v3.mjs +6 -6
  51. package/dist/zod-v4.d.mts +18 -31
  52. package/dist/zod-v4.mjs +6 -6
  53. package/dist/zod.d.mts +4 -4
  54. package/dist/zod.mjs +5 -5
  55. package/package.json +19 -15
  56. package/skills/attaform/SKILL.md +6 -3
  57. package/skills/attaform/references/custom-components.md +8 -3
  58. package/skills/attaform/references/errors.md +8 -3
  59. package/skills/attaform/references/saving.md +77 -0
  60. package/skills/attaform/references/wizards.md +10 -8
  61. package/dist/chunks/fingerprint.mjs +0 -183
  62. package/dist/chunks/fingerprint2.mjs +0 -159
  63. package/dist/dev/chunks/fingerprint.mjs +0 -183
  64. package/dist/dev/chunks/fingerprint2.mjs +0 -159
  65. package/dist/dev/shared/attaform-dev.BJGA_UOS.mjs +0 -36
  66. package/dist/shared/attaform.BJGA_UOS.mjs +0 -36
@@ -1,9 +1,7 @@
1
- import { s as slimPrimitivesWalk, c as createAbstractSchema, w as walkPathSegments, d as deriveDefaultWalk, b as buildFieldMetaPathMap, g as getFieldMetaForSchema, m as mergeDeep, f as fixStructuralDefaults, a as getFieldMetaListForSchema } from './attaform-dev.6qxD-Yqo.mjs';
2
- import { o as humanize, h as useAbstractForm } from './attaform-dev.WmuhD_CZ.mjs';
3
- import { A as AttaformError, e as canonicalizePath, a as InvalidUseFormConfigError } from './attaform-dev.Dr2YzS5B.mjs';
4
-
5
- class UnsupportedSchemaError extends AttaformError {
6
- }
1
+ import { w as walkPathSegments, s as slimPrimitivesWalk, c as createAbstractSchema, a as createSharedSchemaStore, b as buildFieldMetaPathMap, g as getFieldMetaForSchema, f as fixStructuralDefaults, m as mergeDeep, d as deriveDefaultWalk, e as getFieldMetaListForSchema } from './attaform-dev.BisFstxh.mjs';
2
+ import { h as getAtPath, j as humanize, c as useAbstractForm } from './attaform-dev.CQ2rJiAX.mjs';
3
+ import { c as callConsumerSchemaFn } from './attaform-dev.BcYT6tFh.mjs';
4
+ import { A as AttaformError, e as canonicalizePath, a as InvalidUseFormConfigError } from './attaform-dev.BQc5QV3Y.mjs';
7
5
 
8
6
  function isZodSchemaType(schema, expectedType) {
9
7
  if (typeof schema !== "object" || schema === null) return false;
@@ -123,26 +121,35 @@ function getRecordValueType(schema) {
123
121
  const def = readDef(schema);
124
122
  return def?.valueType;
125
123
  }
124
+ const getMapKeyType = getRecordKeyType;
125
+ const getMapValueType = getRecordValueType;
126
126
  function getTupleItems(schema) {
127
127
  const def = readDef(schema);
128
128
  return def?.items ?? [];
129
129
  }
130
+ function readOptionList(options) {
131
+ if (options === void 0) return [];
132
+ if (options instanceof Map) return [...options.values()];
133
+ return [...options];
134
+ }
130
135
  function getUnionOptions(schema) {
131
- const def = readDef(schema);
132
- return def?.options ?? [];
136
+ return readOptionList(readDef(schema)?.options);
133
137
  }
134
138
  function getDiscriminatedOptions(schema) {
135
- const def = readDef(schema);
136
- return def?.options ?? [];
139
+ return readOptionList(readDef(schema)?.options);
137
140
  }
138
141
  function getDiscriminator(schema) {
139
142
  const def = readDef(schema);
140
143
  return def?.discriminator;
141
144
  }
142
145
  function getDiscriminatedOptionsMap(schema) {
143
- const map = readDef(schema)?.optionsMap;
146
+ const def = readDef(schema);
147
+ const map = def?.optionsMap ?? def?.options;
144
148
  return map instanceof Map ? map : void 0;
145
149
  }
150
+ function discriminatedOptionsAreMapped(schema) {
151
+ return readDef(schema)?.options instanceof Map;
152
+ }
146
153
  function getIntersectionLeft(schema) {
147
154
  const def = readDef(schema);
148
155
  return def?.left;
@@ -163,6 +170,10 @@ function unwrapEffectsSource(schema) {
163
170
  const def = readDef(schema);
164
171
  return def?.schema;
165
172
  }
173
+ function getEffect(schema) {
174
+ const def = readDef(schema);
175
+ return def?.effect;
176
+ }
166
177
  function getEffectsKind(schema) {
167
178
  const def = readDef(schema);
168
179
  const type = def?.effect?.type;
@@ -188,6 +199,9 @@ function isAsyncEffect(schema) {
188
199
  function containsAsyncRefine(schema, seen) {
189
200
  return walkForTarget(schema, "refinement", seen ?? /* @__PURE__ */ new WeakSet());
190
201
  }
202
+ function containsMapOrSet(schema, seen) {
203
+ return walkForTarget(schema, "map-or-set", /* @__PURE__ */ new WeakSet());
204
+ }
191
205
  function containsDiscriminatedUnion(schema, seen) {
192
206
  return walkForTarget(schema, "discriminated-union", seen ?? /* @__PURE__ */ new WeakSet());
193
207
  }
@@ -267,9 +281,17 @@ function walkForTarget(schema, target, visited) {
267
281
  return false;
268
282
  }
269
283
  if (isZodSchemaType(schema, "ZodSet")) {
284
+ if (target === "map-or-set") return true;
270
285
  const elem = getSetValueType(schema);
271
286
  return elem !== void 0 && walkForTarget(elem, target, visited);
272
287
  }
288
+ if (isZodSchemaType(schema, "ZodMap")) {
289
+ if (target === "map-or-set") return true;
290
+ const keyType = getMapKeyType(schema);
291
+ if (keyType !== void 0 && walkForTarget(keyType, target, visited)) return true;
292
+ const valueType = getMapValueType(schema);
293
+ return valueType !== void 0 && walkForTarget(valueType, target, visited);
294
+ }
273
295
  return false;
274
296
  }
275
297
  function unwrapPipeIn(schema) {
@@ -284,15 +306,7 @@ function unwrapLazy(schema) {
284
306
  const def = readDef(schema);
285
307
  const getter = def?.getter;
286
308
  if (typeof getter !== "function") return void 0;
287
- try {
288
- return getter();
289
- } catch {
290
- return void 0;
291
- }
292
- }
293
- function getLazyGetter(schema) {
294
- const def = readDef(schema);
295
- return typeof def?.getter === "function" ? def.getter : void 0;
309
+ return callConsumerSchemaFn(() => getter(), void 0, "lazy-getter");
296
310
  }
297
311
  function getLiteralValues(schema) {
298
312
  const def = readDef(schema);
@@ -309,21 +323,17 @@ function getDefaultValue(schema) {
309
323
  const def = readDef(schema);
310
324
  const thunk = def?.defaultValue;
311
325
  if (typeof thunk !== "function") return void 0;
312
- try {
313
- return thunk();
314
- } catch {
315
- return void 0;
316
- }
326
+ return callConsumerSchemaFn(() => thunk(), void 0, "default-factory");
317
327
  }
318
328
  function getCatchDefault(schema) {
319
329
  const def = readDef(schema);
320
330
  const cv = def?.catchValue;
321
331
  if (typeof cv !== "function") return void 0;
322
- try {
323
- return cv({ error: null, input: void 0 });
324
- } catch {
325
- return void 0;
326
- }
332
+ return callConsumerSchemaFn(
333
+ () => cv({ error: null, input: void 0 }),
334
+ void 0,
335
+ "catch-factory"
336
+ );
327
337
  }
328
338
  function hasCatchValue(schema) {
329
339
  const def = readDef(schema);
@@ -424,95 +434,6 @@ function isContainerAfterWrapperPeel(schema) {
424
434
  return isZodSchemaType(cur, "ZodObject") || isZodSchemaType(cur, "ZodArray") || isZodSchemaType(cur, "ZodTuple") || isZodSchemaType(cur, "ZodIntersection") || isZodSchemaType(cur, "ZodUnion") || isZodSchemaType(cur, "ZodDiscriminatedUnion") || isZodSchemaType(cur, "ZodRecord") || isZodSchemaType(cur, "ZodSet");
425
435
  }
426
436
 
427
- const UNSUPPORTED_TYPE_NAMES = /* @__PURE__ */ new Set(["ZodPromise", "ZodFunction", "ZodMap", "ZodSymbol"]);
428
- function labelPath(path) {
429
- return path.length === 0 ? "<root>" : path.join(".");
430
- }
431
- function assertSupportedKinds(schema, path = [], lazyGetters = []) {
432
- const typeName = getTypeName(schema);
433
- if (typeName !== void 0 && UNSUPPORTED_TYPE_NAMES.has(typeName)) {
434
- throw new UnsupportedSchemaError(
435
- `[attaform/zod-v3] unsupported kind '${typeName}' at '${labelPath(path)}'`
436
- );
437
- }
438
- if (isZodSchemaType(schema, "ZodObject")) {
439
- for (const [key, sub] of Object.entries(getObjectShape(schema))) {
440
- assertSupportedKinds(sub, [...path, key], lazyGetters);
441
- }
442
- return;
443
- }
444
- if (isZodSchemaType(schema, "ZodArray")) {
445
- const inner = getArrayElement(schema);
446
- if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
447
- return;
448
- }
449
- if (isZodSchemaType(schema, "ZodSet")) {
450
- const inner = getSetValueType(schema);
451
- if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
452
- return;
453
- }
454
- if (isZodSchemaType(schema, "ZodRecord")) {
455
- const inner = getRecordValueType(schema);
456
- if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
457
- return;
458
- }
459
- if (isZodSchemaType(schema, "ZodTuple")) {
460
- const items = getTupleItems(schema);
461
- items.forEach((item, i) => assertSupportedKinds(item, [...path, String(i)], lazyGetters));
462
- return;
463
- }
464
- if (isZodSchemaType(schema, "ZodUnion")) {
465
- const options = getUnionOptions(schema);
466
- options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
467
- return;
468
- }
469
- if (isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
470
- const options = getDiscriminatedOptions(schema);
471
- options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
472
- return;
473
- }
474
- if (isZodSchemaType(schema, "ZodIntersection")) {
475
- const left = getIntersectionLeft(schema);
476
- if (left) assertSupportedKinds(left, [...path, "left"], lazyGetters);
477
- const right = getIntersectionRight(schema);
478
- if (right) assertSupportedKinds(right, [...path, "right"], lazyGetters);
479
- return;
480
- }
481
- if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodCatch")) {
482
- const inner = unwrapInner(schema);
483
- if (inner) assertSupportedKinds(inner, path, lazyGetters);
484
- return;
485
- }
486
- if (isZodSchemaType(schema, "ZodBranded")) {
487
- const inner = unwrapBranded(schema);
488
- if (inner) assertSupportedKinds(inner, path, lazyGetters);
489
- return;
490
- }
491
- if (isZodSchemaType(schema, "ZodEffects")) {
492
- const inner = unwrapEffectsSource(schema);
493
- if (inner) assertSupportedKinds(inner, path, lazyGetters);
494
- return;
495
- }
496
- if (isZodSchemaType(schema, "ZodPipeline")) {
497
- const inner = unwrapPipeIn(schema);
498
- if (inner) assertSupportedKinds(inner, path, lazyGetters);
499
- return;
500
- }
501
- if (isZodSchemaType(schema, "ZodLazy")) {
502
- const getter = getLazyGetter(schema);
503
- if (getter !== void 0 && lazyGetters.includes(getter)) return;
504
- const inner = getter?.();
505
- if (inner !== void 0) {
506
- assertSupportedKinds(
507
- inner,
508
- path,
509
- getter === void 0 ? lazyGetters : [...lazyGetters, getter]
510
- );
511
- }
512
- return;
513
- }
514
- }
515
-
516
437
  const V3_INTROSPECTOR = {
517
438
  kindOf: (schema) => kindOf(schema),
518
439
  getObjectShape,
@@ -529,8 +450,9 @@ const V3_INTROSPECTOR = {
529
450
  // Walker accessors (D2 / D3 / D5).
530
451
  getArrayElement,
531
452
  getSetValueType,
532
- getRecordKeyType,
533
453
  getRecordValueType,
454
+ getMapKeyType: (schema) => kindOf(schema) === "map" ? getMapKeyType(schema) : void 0,
455
+ getMapValueType: (schema) => kindOf(schema) === "map" ? getMapValueType(schema) : void 0,
534
456
  getUnionOptions,
535
457
  getIntersectionLeft,
536
458
  getIntersectionRight,
@@ -545,20 +467,89 @@ const V3_INTROSPECTOR = {
545
467
  unwrapPipeIn,
546
468
  unwrapPipeOut,
547
469
  unwrapLazy,
548
- getLazyGetter,
549
470
  getDefaultValue,
550
471
  getCatchDefault,
551
472
  hasCatchValue
552
473
  };
553
474
 
475
+ function mapKeyAt(value, index) {
476
+ if (!(value instanceof Map)) return void 0;
477
+ if (typeof index !== "number" || !Number.isInteger(index) || index < 0) return void 0;
478
+ let i = 0;
479
+ for (const key of value.keys()) {
480
+ if (i === index) return key;
481
+ i += 1;
482
+ }
483
+ return void 0;
484
+ }
485
+ function stepSchema(schema, segment, maxRecursionDepth) {
486
+ if (schema === void 0) return void 0;
487
+ return walkPathSegments(schema, [String(segment)], V3_INTROSPECTOR, maxRecursionDepth, 0)[0];
488
+ }
489
+ function normalizeIssuePaths(issues, rootSchema, data, maxRecursionDepth, peel) {
490
+ let out = null;
491
+ for (let i = 0; i < issues.length; i++) {
492
+ const issue = issues[i];
493
+ const next = normalizeOne(issue.path, rootSchema, data, maxRecursionDepth, peel);
494
+ if (next === null) continue;
495
+ out ?? (out = [...issues]);
496
+ out[i] = { ...issue, path: next };
497
+ }
498
+ return out ?? issues;
499
+ }
500
+ function normalizeOne(path, rootSchema, data, maxRecursionDepth, peel) {
501
+ const out = [];
502
+ let schema = rootSchema;
503
+ let value = data;
504
+ let changed = false;
505
+ let i = 0;
506
+ while (i < path.length) {
507
+ const peeled = schema === void 0 ? void 0 : peel(schema);
508
+ const kind = peeled === void 0 ? void 0 : V3_INTROSPECTOR.kindOf(peeled);
509
+ if (kind === "set") {
510
+ changed = true;
511
+ break;
512
+ }
513
+ if (kind === "map") {
514
+ const key = mapKeyAt(value, path[i]);
515
+ if (key === void 0) {
516
+ changed = true;
517
+ break;
518
+ }
519
+ if (typeof key !== "string" && typeof key !== "number") {
520
+ changed = true;
521
+ break;
522
+ }
523
+ out.push(key);
524
+ value = value.get(key);
525
+ schema = V3_INTROSPECTOR.getMapValueType(peeled);
526
+ changed = true;
527
+ const half = path[i + 1];
528
+ i += half === "key" || half === "value" ? 2 : 1;
529
+ continue;
530
+ }
531
+ const segment = path[i];
532
+ out.push(segment);
533
+ value = getAtPath(value, [segment]);
534
+ schema = stepSchema(schema, segment, maxRecursionDepth);
535
+ i += 1;
536
+ }
537
+ return changed ? out : null;
538
+ }
539
+
554
540
  function slimPrimitivesV3(schema) {
555
541
  return new Set(slimPrimitivesWalk(schema, V3_INTROSPECTOR, 64));
556
542
  }
557
543
 
558
544
  function rebuildWithDef(original, defPatch) {
559
- const node = Object.create(Object.getPrototypeOf(original));
560
- node._def = { ...original._def, ...defPatch };
561
- return node;
545
+ return Object.create(Object.getPrototypeOf(original), {
546
+ _def: {
547
+ value: { ...original._def, ...defPatch },
548
+ writable: true,
549
+ enumerable: true,
550
+ configurable: true
551
+ }
552
+ });
562
553
  }
563
554
  function rebuildObject(original, shape) {
564
555
  const node = rebuildWithDef(original, { shape: () => shape, unknownKeys: "strip" });
@@ -611,10 +602,22 @@ function rebuildDiscriminatedUnion(original, options) {
611
602
  if (replacement !== void 0) optionsMap.set(value, replacement);
612
603
  }
613
604
  }
605
+ if (discriminatedOptionsAreMapped(original)) {
606
+ return rebuildWithDef(original, { options: optionsMap });
607
+ }
614
608
  return rebuildWithDef(original, { options, optionsMap });
615
609
  }
610
+ function rebuildEffects(original, source, effect) {
611
+ return rebuildWithDef(original, { schema: source, effect });
612
+ }
616
613
 
617
- function stripAsyncChecks(schema) {
614
+ function wrapAsyncSafeRefinements(schema) {
615
+ return walkEffects(schema);
616
+ }
617
+ function isThenable(value) {
618
+ return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
619
+ }
620
+ function walkEffects(schema) {
618
621
  const seen = /* @__PURE__ */ new WeakSet();
619
622
  function recurse(s) {
620
623
  const candidate = s;
@@ -623,7 +626,25 @@ function stripAsyncChecks(schema) {
623
626
  seen.add(candidate);
624
627
  if (isZodSchemaType(s, "ZodEffects")) {
625
628
  const inner = unwrapEffectsSource(s);
626
- return inner === void 0 ? s : recurse(inner);
629
+ if (inner === void 0) return s;
630
+ const effect = getEffect(s);
631
+ const rebuiltInner = recurse(inner);
632
+ const original = effect?.["refinement"];
633
+ if (effect === void 0 || typeof original !== "function") {
634
+ return rebuildEffects(s, rebuiltInner, effect);
635
+ }
636
+ const refine = original;
637
+ const safeEffect = {
638
+ ...effect,
639
+ refinement: (value, ctx) => {
640
+ const result = refine(value, ctx);
641
+ if (isThenable(result)) {
642
+ void result.catch(() => void 0);
643
+ }
644
+ return result;
645
+ }
646
+ };
647
+ return rebuildEffects(s, rebuiltInner, safeEffect);
627
648
  }
628
649
  if (isZodSchemaType(s, "ZodOptional")) {
629
650
  const inner = unwrapInner(s);
@@ -772,30 +793,46 @@ function carryObjectChecks(rebuilt, original) {
772
793
  const MAX_UNWRAP_STEPS = 64;
773
794
  let warnedZodCodeMissing = false;
774
795
  function zodAdapter(zodSchema) {
775
- assertSupportedKinds(zodSchema);
776
796
  const peeledRoot = peelAllV3Wrappers(zodSchema);
777
797
  if (!isZodSchemaType(peeledRoot, "ZodObject") && !isZodSchemaType(peeledRoot, "ZodRecord") && !isZodSchemaType(peeledRoot, "ZodDiscriminatedUnion")) {
778
- const name = getTypeName(peeledRoot);
779
- throw new Error(
780
- `Attaform: useForm schema root must be a ZodObject, ZodRecord, or ZodDiscriminatedUnion (got ${name}). Wrap other shapes under a key.`
798
+ const name = getTypeName(peeledRoot) ?? "unknown";
799
+ throw new AttaformError(
800
+ `[attaform/zod-v3] useForm schema root must be a ZodObject, ZodRecord, or ZodDiscriminatedUnion (got '${name}'). Wrap other shapes under a key.`
781
801
  );
782
802
  }
783
- return (formKey, options) => createAbstractSchema(
803
+ return (_formKey, options) => sharedV3Schemas(
784
804
  zodSchema,
785
- V3_INTROSPECTOR,
786
- buildV3Services(),
787
- formKey,
788
- options
805
+ options.maxRecursionDepth,
806
+ () => createAbstractSchema(
807
+ zodSchema,
808
+ V3_INTROSPECTOR,
809
+ buildV3Services(options.maxRecursionDepth),
810
+ options
811
+ )
789
812
  );
790
813
  }
791
- async function lazyFingerprint(schema) {
792
- const { fingerprintZodSchema } = await import('../chunks/fingerprint.mjs');
793
- return fingerprintZodSchema(schema);
794
- }
795
- function buildV3Services() {
814
+ const sharedV3Schemas = createSharedSchemaStore();
815
+ const syncSafeCache = /* @__PURE__ */ new WeakMap();
816
+ function syncSafe(schema) {
817
+ const cached = syncSafeCache.get(schema);
818
+ if (cached !== void 0) return cached;
819
+ const wrapped = wrapAsyncSafeRefinements(schema);
820
+ syncSafeCache.set(schema, wrapped);
821
+ return wrapped;
822
+ }
823
+ function buildV3Services(maxRecursionDepth) {
824
+ const mapOrSetBySchema = /* @__PURE__ */ new WeakMap();
825
+ const refileIssues = (schema, data, issues) => {
826
+ let hasMapOrSet = mapOrSetBySchema.get(schema);
827
+ if (hasMapOrSet === void 0) {
828
+ hasMapOrSet = containsMapOrSet(schema);
829
+ mapOrSetBySchema.set(schema, hasMapOrSet);
830
+ }
831
+ if (!hasMapOrSet) return issues;
832
+ return normalizeIssuePaths(issues, schema, data, maxRecursionDepth, peelAllV3Wrappers);
833
+ };
796
834
  return {
797
- fingerprint: (schema) => lazyFingerprint(schema),
798
- getNestedSchemasAtPath: (schema, path, maxRecursionDepth) => getNestedZodSchemasAtPath(schema, path, maxRecursionDepth),
835
+ getNestedSchemasAtPath: (schema, path, maxRecursionDepth2) => getNestedZodSchemasAtPath(schema, path, maxRecursionDepth2),
799
836
  // v3 pre-strips refinements / defaults / wrappers off the root for
800
837
  // slim-mode walks — `getSlimPrimitiveTypesAtPath` and
801
838
  // `getSchemasAtPath` both consume this variant so the yielded
@@ -803,34 +840,33 @@ function buildV3Services() {
803
840
  // The slim-root projection is gone (size-teardown P7): the shared
804
841
  // path walker peels wrappers / effects inline, so the slim and
805
842
  // unstripped walks coincide — same aliasing v4 always had.
806
- getNestedSchemasInSlimMode: (schema, path, maxRecursionDepth) => getNestedZodSchemasAtPath(schema, path, maxRecursionDepth),
843
+ getNestedSchemasInSlimMode: (schema, path, maxRecursionDepth2) => getNestedZodSchemasAtPath(schema, path, maxRecursionDepth2),
807
844
  slimPrimitivesOf: (schema, _maxRecursionDepth) => slimPrimitivesV3(schema),
808
- deriveDefault: (schema, useDefault, _maxRecursionDepth, formKey) => getDefaultValuesFromZodSchema(schema, useDefault, formKey),
809
- runStrictGetDefaults: (schema, config, formKey, maxRecursionDepth) => runStrictGetDefaultsV3(schema, config, formKey, maxRecursionDepth),
845
+ deriveDefault: (schema, useDefault) => getDefaultValuesFromZodSchema(schema, useDefault),
846
+ runGetDefaults: (schema, config, maxRecursionDepth2) => runGetDefaultsV3(schema, config, maxRecursionDepth2),
810
847
  unwrapStructuralWrappers: (schema) => unwrapStructuralLeafV3(schema),
811
848
  unwrapToDiscriminatedUnion: (schema) => unwrapToDiscriminatedUnion(schema),
812
849
  peelAllWrappers: (schema) => peelAllV3Wrappers(schema),
813
850
  isLeafRequired: (schema) => isLeafRequiredV3(schema),
814
- resolveFieldMetaAtPath: (schema, path, maxRecursionDepth) => resolveFieldMetaAtPathV3(schema, path, maxRecursionDepth),
851
+ resolveFieldMetaAtPath: (schema, path, maxRecursionDepth2) => resolveFieldMetaAtPathV3(schema, path, maxRecursionDepth2),
815
852
  issuesToValidationErrors: (issues) => zodIssuesToValidationErrors(issues),
816
853
  safeParseSync: (schema, data) => {
817
- const result = schema.safeParse(data);
818
- return result.success ? { success: true, data: result.data } : { success: false, issues: result.error.issues };
854
+ const result = syncSafe(schema).safeParse(data);
855
+ return result.success ? { success: true, data: result.data } : { success: false, issues: refileIssues(schema, data, result.error.issues) };
819
856
  },
820
857
  safeParseAsync: async (schema, data) => {
821
858
  const result = await schema.safeParseAsync(data);
822
- return result.success ? { success: true, data: result.data } : { success: false, issues: result.error.issues };
859
+ return result.success ? { success: true, data: result.data } : { success: false, issues: refileIssues(schema, data, result.error.issues) };
823
860
  },
824
861
  // v3 returns the full recursive AbstractSchema for sub-schemas (the
825
862
  // historical shape) — `getSchemasAtPath` consumers may probe any
826
863
  // method on the result. The factory call rebuilds the full surface
827
864
  // against the sub-schema with its own per-form caches.
828
- makeSubSchema: (sub, formKey, maxRecursionDepth) => createAbstractSchema(
865
+ makeSubSchema: (sub, maxRecursionDepth2) => createAbstractSchema(
829
866
  sub,
830
867
  V3_INTROSPECTOR,
831
- buildV3Services(),
832
- formKey,
833
- { maxRecursionDepth }
868
+ buildV3Services(maxRecursionDepth2),
869
+ { maxRecursionDepth: maxRecursionDepth2 }
834
870
  )
835
871
  };
836
872
  }
@@ -1048,16 +1084,8 @@ function peelAllV3Wrappers(schema) {
1048
1084
  }
1049
1085
  return current;
1050
1086
  }
1051
- function getDefaultValuesFromZodSchema(formSchema, useDefaultSchemaValues, formKey) {
1052
- return deriveDefaultWalk(formSchema, useDefaultSchemaValues, V3_INTROSPECTOR, 64, {
1053
- unsupportedKindFallback: (schema) => {
1054
- const kindName = schema.constructor?.name ?? "unknown";
1055
- console.warn(
1056
- `[attaform] zod-v3 adapter: unsupported schema kind '${kindName}' on form '${formKey}'. Defaulting the field to null. Use a supported zod kind (object/array/record/string/number/etc.) at this path.`
1057
- );
1058
- return null;
1059
- }
1060
- });
1087
+ function getDefaultValuesFromZodSchema(formSchema, useDefaultSchemaValues) {
1088
+ return deriveDefaultWalk(formSchema, useDefaultSchemaValues, V3_INTROSPECTOR, 64);
1061
1089
  }
1062
1090
  function resolveFieldMetaAtPathV3(rootSchema, path, maxRecursionDepth) {
1063
1091
  const lastSegment = path.length === 0 ? "" : path[path.length - 1];
@@ -1088,92 +1116,51 @@ function resolveFieldMetaAtPathV3(rootSchema, path, maxRecursionDepth) {
1088
1116
  meta: Object.freeze({ ...payload ?? {} })
1089
1117
  };
1090
1118
  }
1091
- function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth) {
1119
+ function runGetDefaultsV3(rootSchema, config, maxRecursionDepth) {
1092
1120
  const defaultValuesWithoutConstraints = getDefaultValuesFromZodSchema(
1093
1121
  rootSchema,
1094
- config.useDefaultSchemaValues,
1095
- formKey
1122
+ config.useDefaultSchemaValues
1096
1123
  );
1097
- const rawDefaultValues = mergeDeep(defaultValuesWithoutConstraints, config.constraints);
1098
- if ((config.strict ?? true) !== false) {
1099
- if (containsAsyncTransform(rootSchema)) {
1100
- return {
1101
- data: rawDefaultValues,
1102
- errors: void 0,
1103
- success: true,
1104
- formKey
1105
- };
1106
- }
1107
- try {
1108
- const strictResult = rootSchema.safeParse(rawDefaultValues);
1109
- if (strictResult.success) {
1110
- return {
1111
- data: rawDefaultValues,
1112
- errors: void 0,
1113
- success: true,
1114
- formKey
1115
- };
1116
- }
1117
- return {
1118
- data: rawDefaultValues,
1119
- errors: zodIssuesToValidationErrors(strictResult.error.issues),
1120
- success: false,
1121
- formKey
1122
- };
1123
- } catch (err) {
1124
- const isAsyncDetect = err instanceof Error && err.message.includes("Async refinement encountered");
1125
- if (isAsyncDetect) {
1126
- try {
1127
- const strippedResult = stripAsyncChecks(rootSchema).safeParse(rawDefaultValues);
1128
- if (strippedResult.success) {
1129
- return {
1130
- data: rawDefaultValues,
1131
- errors: void 0,
1132
- success: true,
1133
- formKey
1134
- };
1135
- }
1136
- return {
1137
- data: rawDefaultValues,
1138
- errors: zodIssuesToValidationErrors(strippedResult.error.issues),
1139
- success: false,
1140
- formKey
1141
- };
1142
- } catch {
1143
- return {
1144
- data: rawDefaultValues,
1145
- errors: void 0,
1146
- success: true,
1147
- formKey
1148
- };
1149
- }
1150
- }
1151
- return {
1152
- data: rawDefaultValues,
1153
- errors: void 0,
1154
- success: true,
1155
- formKey
1156
- };
1157
- }
1158
- }
1159
- const fixed = fixStructuralDefaults(
1124
+ const rawDefaultValues = config.constraints === void 0 ? defaultValuesWithoutConstraints : fixStructuralDefaults(
1160
1125
  rootSchema,
1161
- rawDefaultValues,
1126
+ mergeDeep(defaultValuesWithoutConstraints, config.constraints),
1162
1127
  config.useDefaultSchemaValues,
1163
1128
  maxRecursionDepth,
1164
1129
  {
1165
1130
  intro: V3_INTROSPECTOR,
1166
1131
  slimPrimitivesOf: (s) => slimPrimitivesV3(s),
1167
- deriveDefault: (s, useDefault) => getDefaultValuesFromZodSchema(s, useDefault, formKey),
1132
+ deriveDefault: (s, useDefault) => getDefaultValuesFromZodSchema(s, useDefault),
1168
1133
  unwrapToDiscriminatedUnion: (s) => unwrapToDiscriminatedUnion(s)
1169
1134
  }
1170
- );
1171
- return {
1172
- data: fixed.data,
1173
- errors: void 0,
1174
- success: true,
1175
- formKey
1176
- };
1135
+ ).data;
1136
+ if (containsAsyncTransform(rootSchema)) {
1137
+ return {
1138
+ data: rawDefaultValues,
1139
+ errors: void 0,
1140
+ success: true
1141
+ };
1142
+ }
1143
+ try {
1144
+ const parseResult = syncSafe(rootSchema).safeParse(rawDefaultValues);
1145
+ if (parseResult.success) {
1146
+ return {
1147
+ data: rawDefaultValues,
1148
+ errors: void 0,
1149
+ success: true
1150
+ };
1151
+ }
1152
+ return {
1153
+ data: rawDefaultValues,
1154
+ errors: zodIssuesToValidationErrors(parseResult.error.issues),
1155
+ success: false
1156
+ };
1157
+ } catch {
1158
+ return {
1159
+ data: rawDefaultValues,
1160
+ errors: void 0,
1161
+ success: true
1162
+ };
1163
+ }
1177
1164
  }
1178
1165
 
1179
1166
  function useForm(configuration) {
@@ -1,4 +1,4 @@
1
- import { c as RegistryNotInstalledError, O as OutsideSetupError, g as pathKeyToDotted } from './attaform-dev.Dr2YzS5B.mjs';
1
+ import { c as RegistryNotInstalledError, O as OutsideSetupError, g as pathKeyToDotted } from './attaform-dev.BQc5QV3Y.mjs';
2
2
  import { shallowReactive, getCurrentInstance, inject } from 'vue';
3
3
 
4
4
  function detectSSR(options = {}) {
@@ -17,7 +17,6 @@ const kFormContext = /* @__PURE__ */ Symbol.for("attaform:form-context");
17
17
  const kFormInstanceId = /* @__PURE__ */ Symbol.for("attaform:form-instance-id");
18
18
  function createRegistry(options = {}) {
19
19
  const ssr = detectSSR(options);
20
- const defaults = Object.freeze({ ...options.defaults ?? {} });
21
20
  const forms = shallowReactive(/* @__PURE__ */ new Map());
22
21
  const wizards = shallowReactive(/* @__PURE__ */ new Map());
23
22
  const pendingHydration = shallowReactive(/* @__PURE__ */ new Map());
@@ -102,7 +101,6 @@ function createRegistry(options = {}) {
102
101
  wizards,
103
102
  pendingHydration,
104
103
  ssr,
105
- defaults,
106
104
  trackConsumer,
107
105
  trackWizardConsumer,
108
106
  enqueuePrefetch,
@@ -1,9 +1,9 @@
1
- export { i as isZodSchemaType, u as useForm, z as zodAdapter } from './shared/attaform-dev.D2I8e_Mm.mjs';
2
- import { i as installingFieldMetaStore, g as getFieldMetaForSchema } from './shared/attaform-dev.6qxD-Yqo.mjs';
3
- export { A as AttaformError, I as InvalidPathError, a as InvalidUseFormConfigError, O as OutsideSetupError, R as ROOT_PATH, b as ROOT_PATH_KEY, c as RegistryNotInstalledError, d as ReservedFormKeyError, S as SubmitErrorHandlerError, e as canonicalizePath, i as isPathPrefix, p as parseDottedPath } from './shared/attaform-dev.Dr2YzS5B.mjs';
4
- export { A as AttaformErrorCode, D as DEFAULT_TIMINGS, d as defaultCoercionRules, a as defaultDisplayState, b as defineCoercion, e as escapeForInlineScript, g as gate, i as injectForm, c as injectWizard, f as isUnset, l as lazy, m as makeDefaultDisplayState, u as unset, j as useRegister, k as useWizard } from './shared/attaform-dev.WmuhD_CZ.mjs';
5
- export { D as DEVTOOLS_WINDOW_KEY, c as createAttaform, a as createRegistry, g as getRegistryFromApp, h as hydrateAttaformState, k as kAttaformRegistry, r as renderAttaformState, u as useRegistry } from './shared/attaform-dev.BXE2cr0L.mjs';
6
- export { a as assignKey, i as isRegisterValue, v as vRegister } from './shared/attaform-dev.P7cseiEG.mjs';
1
+ export { i as isZodSchemaType, u as useForm, z as zodAdapter } from './shared/attaform-dev.DTrHonpc.mjs';
2
+ import { i as installingFieldMetaStore, g as getFieldMetaForSchema } from './shared/attaform-dev.BisFstxh.mjs';
3
+ export { A as AttaformError, I as InvalidPathError, a as InvalidUseFormConfigError, O as OutsideSetupError, R as ROOT_PATH, b as ROOT_PATH_KEY, c as RegistryNotInstalledError, d as ReservedFormKeyError, S as SubmitErrorHandlerError, e as canonicalizePath, i as isPathPrefix, p as parseDottedPath } from './shared/attaform-dev.BQc5QV3Y.mjs';
4
+ export { A as AttaformErrorCode, e as escapeForInlineScript, g as gate, i as injectForm, a as injectWizard, b as isUnset, l as lazy, u as unset, d as useRegister, f as useWizard } from './shared/attaform-dev.CQ2rJiAX.mjs';
5
+ export { D as DEVTOOLS_WINDOW_KEY, c as createAttaform, a as createRegistry, g as getRegistryFromApp, h as hydrateAttaformState, k as kAttaformRegistry, r as renderAttaformState, u as useRegistry } from './shared/attaform-dev.DUZckyV8.mjs';
6
+ export { a as assignKey, i as isRegisterValue, v as vRegister } from './shared/attaform-dev.D6CLvaQT.mjs';
7
7
 
8
8
  const fieldMeta = installingFieldMetaStore;
9
9
  function withMeta(schema, payload) {