attaform 0.17.2 → 0.18.1

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 (115) hide show
  1. package/README.md +77 -36
  2. package/dist/chunks/devtools.cjs +10 -37
  3. package/dist/chunks/devtools.cjs.map +1 -1
  4. package/dist/chunks/devtools.mjs +10 -37
  5. package/dist/chunks/devtools.mjs.map +1 -1
  6. package/dist/chunks/indexeddb.cjs +4 -4
  7. package/dist/chunks/indexeddb.cjs.map +1 -1
  8. package/dist/chunks/indexeddb.mjs +1 -1
  9. package/dist/chunks/local-storage.cjs +2 -2
  10. package/dist/chunks/local-storage.cjs.map +1 -1
  11. package/dist/chunks/local-storage.mjs +1 -1
  12. package/dist/chunks/session-storage.cjs +2 -2
  13. package/dist/chunks/session-storage.cjs.map +1 -1
  14. package/dist/chunks/session-storage.mjs +1 -1
  15. package/dist/index.cjs +42 -37
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +159 -196
  18. package/dist/index.d.mts +159 -196
  19. package/dist/index.d.ts +159 -196
  20. package/dist/index.mjs +5 -7
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/nuxt.cjs +31 -40
  23. package/dist/nuxt.cjs.map +1 -1
  24. package/dist/nuxt.d.cts +8 -1
  25. package/dist/nuxt.d.mts +8 -1
  26. package/dist/nuxt.d.ts +8 -1
  27. package/dist/nuxt.mjs +32 -41
  28. package/dist/nuxt.mjs.map +1 -1
  29. package/dist/runtime/components/AttaformDevtoolsPanel.d.vue.ts +7 -0
  30. package/dist/runtime/components/AttaformDevtoolsPanel.vue +453 -0
  31. package/dist/runtime/components/AttaformDevtoolsPanel.vue.d.ts +7 -0
  32. package/dist/runtime/components/DevtoolsValueTree.d.vue.ts +37 -0
  33. package/dist/runtime/components/DevtoolsValueTree.vue +192 -0
  34. package/dist/runtime/components/DevtoolsValueTree.vue.d.ts +37 -0
  35. package/dist/runtime/plugins/attaform.cjs +17 -6
  36. package/dist/runtime/plugins/attaform.cjs.map +1 -1
  37. package/dist/runtime/plugins/attaform.mjs +15 -4
  38. package/dist/runtime/plugins/attaform.mjs.map +1 -1
  39. package/dist/shared/{attaform.C0iFnTN0.d.ts → attaform.2b7M2mww.d.mts} +57 -23
  40. package/dist/shared/attaform.5UhpSVFI.cjs +63 -0
  41. package/dist/shared/attaform.5UhpSVFI.cjs.map +1 -0
  42. package/dist/shared/attaform.BDdFdjeX.mjs +57 -0
  43. package/dist/shared/attaform.BDdFdjeX.mjs.map +1 -0
  44. package/dist/shared/{attaform.Dee2rU1P.cjs → attaform.BqK_L4gK.cjs} +310 -24
  45. package/dist/shared/attaform.BqK_L4gK.cjs.map +1 -0
  46. package/dist/shared/attaform.Bubm_slq.cjs.map +1 -1
  47. package/dist/shared/attaform.CXpzmj38.mjs.map +1 -1
  48. package/dist/shared/{attaform.Drt6fivF.mjs → attaform.CtNUB9nf.mjs} +74 -76
  49. package/dist/shared/attaform.CtNUB9nf.mjs.map +1 -0
  50. package/dist/shared/{attaform.C5MH4lNh.d.mts → attaform.DF8wo-ry.d.ts} +4 -4
  51. package/dist/shared/attaform.DK9aj0N8.d.ts +1651 -0
  52. package/dist/shared/{attaform.BPRHR3Zs.cjs → attaform.DUHru0OF.cjs} +83 -85
  53. package/dist/shared/attaform.DUHru0OF.cjs.map +1 -0
  54. package/dist/shared/{attaform.C6lbmMUe.d.ts → attaform.DVLB6CAn.d.mts} +4 -4
  55. package/dist/shared/{attaform.C_5aB6EQ.d.ts → attaform.Dj9mwbaV.d.cts} +756 -148
  56. package/dist/shared/{attaform.C_5aB6EQ.d.mts → attaform.Dj9mwbaV.d.mts} +756 -148
  57. package/dist/shared/{attaform.C_5aB6EQ.d.cts → attaform.Dj9mwbaV.d.ts} +756 -148
  58. package/dist/shared/{attaform.BV40t5y2.cjs → attaform.Dlk1jMuv.cjs} +245 -108
  59. package/dist/shared/attaform.Dlk1jMuv.cjs.map +1 -0
  60. package/dist/shared/attaform.DoSuaKMd.d.cts +1651 -0
  61. package/dist/shared/{attaform.B3ZaPIzS.mjs → attaform.DsC3rZHG.mjs} +1804 -219
  62. package/dist/shared/attaform.DsC3rZHG.mjs.map +1 -0
  63. package/dist/shared/{attaform.Cer8JO_P.cjs → attaform.II89Pcf4.cjs} +1860 -272
  64. package/dist/shared/attaform.II89Pcf4.cjs.map +1 -0
  65. package/dist/shared/{attaform.CHorcsIU.d.cts → attaform.M33WKVV4.d.cts} +57 -23
  66. package/dist/shared/{attaform.CIEQgJnM.mjs → attaform.Xhg0AYNa.mjs} +300 -26
  67. package/dist/shared/attaform.Xhg0AYNa.mjs.map +1 -0
  68. package/dist/shared/{attaform.CpERWz3u.mjs → attaform.Xt0A3QUd.mjs} +232 -95
  69. package/dist/shared/attaform.Xt0A3QUd.mjs.map +1 -0
  70. package/dist/shared/attaform.iTqxvl-P.d.mts +1651 -0
  71. package/dist/shared/{attaform.CuE-bS1C.d.mts → attaform.tsNFcEW7.d.ts} +57 -23
  72. package/dist/shared/{attaform.DtMN-MAm.d.cts → attaform.tts_OM7j.d.cts} +4 -4
  73. package/dist/vite.cjs +288 -2
  74. package/dist/vite.cjs.map +1 -1
  75. package/dist/vite.mjs +288 -2
  76. package/dist/vite.mjs.map +1 -1
  77. package/dist/zod-v3.cjs +11 -8
  78. package/dist/zod-v3.cjs.map +1 -1
  79. package/dist/zod-v3.d.cts +6 -6
  80. package/dist/zod-v3.d.mts +6 -6
  81. package/dist/zod-v3.d.ts +6 -6
  82. package/dist/zod-v3.mjs +3 -3
  83. package/dist/zod-v4.cjs +11 -8
  84. package/dist/zod-v4.cjs.map +1 -1
  85. package/dist/zod-v4.d.cts +5 -5
  86. package/dist/zod-v4.d.mts +5 -5
  87. package/dist/zod-v4.d.ts +5 -5
  88. package/dist/zod-v4.mjs +3 -3
  89. package/dist/zod.cjs +15 -16
  90. package/dist/zod.cjs.map +1 -1
  91. package/dist/zod.d.cts +127 -40
  92. package/dist/zod.d.mts +127 -40
  93. package/dist/zod.d.ts +127 -40
  94. package/dist/zod.mjs +7 -11
  95. package/dist/zod.mjs.map +1 -1
  96. package/package.json +18 -7
  97. package/dist/shared/attaform.B1jvxsOF.d.mts +0 -156
  98. package/dist/shared/attaform.B3ZaPIzS.mjs.map +0 -1
  99. package/dist/shared/attaform.BBM2muQ9.cjs +0 -101
  100. package/dist/shared/attaform.BBM2muQ9.cjs.map +0 -1
  101. package/dist/shared/attaform.BPRHR3Zs.cjs.map +0 -1
  102. package/dist/shared/attaform.BV40t5y2.cjs.map +0 -1
  103. package/dist/shared/attaform.C6qzEdIM.d.cts +0 -156
  104. package/dist/shared/attaform.C8LVFVVe.cjs +0 -32
  105. package/dist/shared/attaform.C8LVFVVe.cjs.map +0 -1
  106. package/dist/shared/attaform.CIEQgJnM.mjs.map +0 -1
  107. package/dist/shared/attaform.CTwNcpLE.d.ts +0 -156
  108. package/dist/shared/attaform.Cer8JO_P.cjs.map +0 -1
  109. package/dist/shared/attaform.CpERWz3u.mjs.map +0 -1
  110. package/dist/shared/attaform.Dee2rU1P.cjs.map +0 -1
  111. package/dist/shared/attaform.Drt6fivF.mjs.map +0 -1
  112. package/dist/shared/attaform.Vo-Kft0t.mjs +0 -29
  113. package/dist/shared/attaform.Vo-Kft0t.mjs.map +0 -1
  114. package/dist/shared/attaform.h1sq3BFu.mjs +0 -92
  115. package/dist/shared/attaform.h1sq3BFu.mjs.map +0 -1
@@ -1,9 +1,8 @@
1
1
  import { merge, set, isFunction, cloneDeep } from 'lodash-es';
2
2
  import { z } from 'zod';
3
- import { g as getAtPath, s as slimKindOf, A as AttaformErrorCode, h as humanize, e as useAbstractForm } from './attaform.B3ZaPIzS.mjs';
4
- import { c as canonicalizePath } from './attaform.h1sq3BFu.mjs';
3
+ import { h as getAtPath, s as slimKindOf, A as AttaformErrorCode, j as humanize, g as useAbstractForm } from './attaform.DsC3rZHG.mjs';
4
+ import { b as AttaformError, a as canonicalizePath, _ as __DEV__, d as InvalidUseFormConfigError } from './attaform.Xhg0AYNa.mjs';
5
5
  import { f as fieldMetaStore, g as getFieldMetaForSchema } from './attaform.D13GMFgK.mjs';
6
- import { a as AttaformError, _ as __DEV__, b as InvalidUseFormConfigError } from './attaform.CIEQgJnM.mjs';
7
6
 
8
7
  const fieldMeta = fieldMetaStore;
9
8
  function withMeta(schema, payload) {
@@ -326,22 +325,37 @@ const PERMISSIVE_V3 = /* @__PURE__ */ new Set([
326
325
  "symbol",
327
326
  "function",
328
327
  "map",
329
- "set"
328
+ "set",
329
+ "file"
330
330
  ]);
331
+ const KIND_STRING = /* @__PURE__ */ new Set(["string"]);
332
+ const KIND_NUMBER = /* @__PURE__ */ new Set(["number"]);
333
+ const KIND_BOOLEAN = /* @__PURE__ */ new Set(["boolean"]);
334
+ const KIND_BIGINT = /* @__PURE__ */ new Set(["bigint"]);
335
+ const KIND_DATE = /* @__PURE__ */ new Set(["date"]);
336
+ const KIND_NULL = /* @__PURE__ */ new Set(["null"]);
337
+ const KIND_UNDEFINED = /* @__PURE__ */ new Set(["undefined"]);
338
+ const KIND_OBJECT = /* @__PURE__ */ new Set(["object"]);
339
+ const KIND_ARRAY = /* @__PURE__ */ new Set(["array"]);
340
+ const KIND_SET = /* @__PURE__ */ new Set(["set"]);
341
+ const EMPTY_KINDS = /* @__PURE__ */ new Set();
331
342
  const MAX_LAZY_DEPTH_V3 = 64;
332
343
  function slimPrimitivesV3(schema, depth = 0) {
333
- if (depth > MAX_LAZY_DEPTH_V3) return new Set(PERMISSIVE_V3);
344
+ return new Set(walk(schema, depth));
345
+ }
346
+ function walk(schema, depth) {
347
+ if (depth > MAX_LAZY_DEPTH_V3) return PERMISSIVE_V3;
334
348
  const def = schema._def;
335
349
  const typeName = def?.typeName;
336
- if (isZodSchemaType(schema, "ZodString")) return /* @__PURE__ */ new Set(["string"]);
337
- if (isZodSchemaType(schema, "ZodNumber")) return /* @__PURE__ */ new Set(["number"]);
338
- if (isZodSchemaType(schema, "ZodBoolean")) return /* @__PURE__ */ new Set(["boolean"]);
339
- if (isZodSchemaType(schema, "ZodBigInt")) return /* @__PURE__ */ new Set(["bigint"]);
340
- if (isZodSchemaType(schema, "ZodDate")) return /* @__PURE__ */ new Set(["date"]);
341
- if (isZodSchemaType(schema, "ZodNull")) return /* @__PURE__ */ new Set(["null"]);
342
- if (isZodSchemaType(schema, "ZodUndefined")) return /* @__PURE__ */ new Set(["undefined"]);
343
- if (typeName === "ZodVoid") return /* @__PURE__ */ new Set(["undefined"]);
344
- if (typeName === "ZodNaN") return /* @__PURE__ */ new Set(["number"]);
350
+ if (isZodSchemaType(schema, "ZodString")) return KIND_STRING;
351
+ if (isZodSchemaType(schema, "ZodNumber")) return KIND_NUMBER;
352
+ if (isZodSchemaType(schema, "ZodBoolean")) return KIND_BOOLEAN;
353
+ if (isZodSchemaType(schema, "ZodBigInt")) return KIND_BIGINT;
354
+ if (isZodSchemaType(schema, "ZodDate")) return KIND_DATE;
355
+ if (isZodSchemaType(schema, "ZodNull")) return KIND_NULL;
356
+ if (isZodSchemaType(schema, "ZodUndefined")) return KIND_UNDEFINED;
357
+ if (typeName === "ZodVoid") return KIND_UNDEFINED;
358
+ if (typeName === "ZodNaN") return KIND_NUMBER;
345
359
  if (isZodSchemaType(schema, "ZodEnum")) {
346
360
  const options = schema.options;
347
361
  const out = /* @__PURE__ */ new Set();
@@ -349,70 +363,72 @@ function slimPrimitivesV3(schema, depth = 0) {
349
363
  if (typeof v === "string") out.add("string");
350
364
  else if (typeof v === "number") out.add("number");
351
365
  }
352
- return out.size === 0 ? /* @__PURE__ */ new Set(["string"]) : out;
366
+ return out.size === 0 ? KIND_STRING : out;
353
367
  }
354
368
  if (isZodSchemaType(schema, "ZodLiteral")) {
355
369
  const value = schema.value;
356
370
  return /* @__PURE__ */ new Set([slimKindOfRawV3(value)]);
357
371
  }
358
372
  if (isZodSchemaType(schema, "ZodObject") || typeName === "ZodRecord") {
359
- return /* @__PURE__ */ new Set(["object"]);
373
+ return KIND_OBJECT;
360
374
  }
361
375
  if (isZodSchemaType(schema, "ZodArray") || typeName === "ZodTuple") {
362
- return /* @__PURE__ */ new Set(["array"]);
376
+ return KIND_ARRAY;
363
377
  }
364
378
  if (isZodSchemaType(schema, "ZodSet")) {
365
- return /* @__PURE__ */ new Set(["set"]);
379
+ return KIND_SET;
366
380
  }
367
381
  if (isZodSchemaType(schema, "ZodOptional")) {
368
382
  const inner = def?.innerType;
369
- const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : slimPrimitivesV3(inner, depth + 1);
370
- innerSet.add("undefined");
371
- return innerSet;
383
+ const innerSet = inner === void 0 ? EMPTY_KINDS : walk(inner, depth + 1);
384
+ const out = new Set(innerSet);
385
+ out.add("undefined");
386
+ return out;
372
387
  }
373
388
  if (isZodSchemaType(schema, "ZodNullable")) {
374
389
  const inner = def?.innerType;
375
- const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : slimPrimitivesV3(inner, depth + 1);
376
- innerSet.add("null");
377
- return innerSet;
390
+ const innerSet = inner === void 0 ? EMPTY_KINDS : walk(inner, depth + 1);
391
+ const out = new Set(innerSet);
392
+ out.add("null");
393
+ return out;
378
394
  }
379
395
  if (isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodBranded")) {
380
396
  const inner = def?.innerType ?? def?.type;
381
- return inner === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(inner, depth + 1);
397
+ return inner === void 0 ? PERMISSIVE_V3 : walk(inner, depth + 1);
382
398
  }
383
399
  if (isZodSchemaType(schema, "ZodEffects")) {
384
400
  const inner = def?.schema;
385
- return inner === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(inner, depth + 1);
401
+ return inner === void 0 ? PERMISSIVE_V3 : walk(inner, depth + 1);
386
402
  }
387
403
  if (isZodSchemaType(schema, "ZodPipeline")) {
388
404
  const inner = def?.in;
389
- return inner === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(inner, depth + 1);
405
+ return inner === void 0 ? PERMISSIVE_V3 : walk(inner, depth + 1);
390
406
  }
391
407
  if (typeName === "ZodLazy") {
392
408
  const getter = def?.getter;
393
- if (typeof getter !== "function") return new Set(PERMISSIVE_V3);
394
- return slimPrimitivesV3(getter(), depth + 1);
409
+ if (typeof getter !== "function") return PERMISSIVE_V3;
410
+ return walk(getter(), depth + 1);
395
411
  }
396
412
  if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
397
413
  const options = def?.options ?? [];
398
414
  const out = /* @__PURE__ */ new Set();
399
415
  for (const opt of options) {
400
- for (const k of slimPrimitivesV3(opt, depth + 1)) out.add(k);
416
+ for (const k of walk(opt, depth + 1)) out.add(k);
401
417
  }
402
- return out.size === 0 ? new Set(PERMISSIVE_V3) : out;
418
+ return out.size === 0 ? PERMISSIVE_V3 : out;
403
419
  }
404
420
  if (typeName === "ZodIntersection") {
405
421
  const left = def?.left;
406
422
  const right = def?.right;
407
- const leftSet = left === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(left, depth + 1);
408
- const rightSet = right === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(right, depth + 1);
423
+ const leftSet = left === void 0 ? PERMISSIVE_V3 : walk(left, depth + 1);
424
+ const rightSet = right === void 0 ? PERMISSIVE_V3 : walk(right, depth + 1);
409
425
  const out = /* @__PURE__ */ new Set();
410
426
  for (const k of leftSet) if (rightSet.has(k)) out.add(k);
411
427
  return out;
412
428
  }
413
- if (typeName === "ZodNever") return /* @__PURE__ */ new Set();
414
- if (typeName === "ZodAny" || typeName === "ZodUnknown") return new Set(PERMISSIVE_V3);
415
- return new Set(PERMISSIVE_V3);
429
+ if (typeName === "ZodNever") return EMPTY_KINDS;
430
+ if (typeName === "ZodAny" || typeName === "ZodUnknown") return PERMISSIVE_V3;
431
+ return PERMISSIVE_V3;
416
432
  }
417
433
  function slimKindOfRawV3(value) {
418
434
  if (value === null) return "null";
@@ -475,6 +491,7 @@ function zodAdapter(zodSchema) {
475
491
  }
476
492
  }
477
493
  const leafCache = /* @__PURE__ */ new Map();
494
+ const preprocessOrCoerceCache = /* @__PURE__ */ new Map();
478
495
  const abstractSchema = {
479
496
  fingerprint: () => fingerprintZodSchema(_zodSchema),
480
497
  getDefaultValues(config) {
@@ -613,35 +630,6 @@ function zodAdapter(zodSchema) {
613
630
  formKey: _formKey
614
631
  };
615
632
  },
616
- normalizeWriteValueAtPath(value, path) {
617
- const candidates = path.length === 0 ? [_zodSchema] : getNestedZodSchemasAtPath(_zodSchema, path);
618
- const [first] = candidates;
619
- if (first === void 0) return value;
620
- let current = first;
621
- let result = value;
622
- for (let i = 0; i < 64; i++) {
623
- if (!isZodSchemaType(current, "ZodEffects")) break;
624
- const def = current._def;
625
- const effect = def.effect;
626
- if (effect?.type !== "preprocess") break;
627
- const fn = effect.transform;
628
- if (typeof fn !== "function") break;
629
- let next;
630
- try {
631
- next = fn(result);
632
- } catch (cause) {
633
- throw new Error(
634
- `[attaform] input normalization at path "${path.join(".")}" threw \u2014 write rejected.`,
635
- { cause }
636
- );
637
- }
638
- if (next instanceof Promise) return value;
639
- result = next;
640
- if (def.schema === void 0) break;
641
- current = def.schema;
642
- }
643
- return result;
644
- },
645
633
  getDefaultAtPath(path) {
646
634
  if (path.length === 0) {
647
635
  return getDefaultValuesFromZodSchema(_zodSchema, true, _formKey);
@@ -772,6 +760,26 @@ function zodAdapter(zodSchema) {
772
760
  leafCache.set(cacheKey, isLeaf);
773
761
  return isLeaf;
774
762
  },
763
+ isPreprocessOrCoerceLeaf(path) {
764
+ const cacheKey = canonicalizePath(path).key;
765
+ const cached = preprocessOrCoerceCache.get(cacheKey);
766
+ if (cached !== void 0) return cached;
767
+ let hit = false;
768
+ for (let i = 0; i <= path.length && !hit; i++) {
769
+ const prefix = path.slice(0, i);
770
+ const candidates = prefix.length === 0 ? [_zodSchema] : getNestedZodSchemasAtPath(_zodSchema, prefix);
771
+ for (const candidate of candidates) {
772
+ if (!isZodSchemaType(candidate, "ZodEffects")) continue;
773
+ const def = candidate._def;
774
+ if (def.effect?.type === "preprocess") {
775
+ hit = true;
776
+ break;
777
+ }
778
+ }
779
+ }
780
+ preprocessOrCoerceCache.set(cacheKey, hit);
781
+ return hit;
782
+ },
775
783
  validateAtPath(data, path, options) {
776
784
  const trySync = options?.sync === true;
777
785
  if (trySync) {
@@ -1577,20 +1585,10 @@ function useForm(configuration) {
1577
1585
  const abstractSchema = isZodType(schema) ? zodAdapter(schema) : schema;
1578
1586
  return useAbstractForm({
1579
1587
  ...configuration,
1580
- // `zodAdapter`'s constraint on its third generic is
1581
- // `GetValueFormType extends TypeWithNullableDynamicKeys<FormSchema>`,
1582
- // and `Schema` at this implementation overload is only constrained
1583
- // by `extends z.ZodSchema<unknown>` — too loose for
1584
- // `z.output<UnwrapZodObject<typeof schema>>` to resolve concretely.
1585
- // Pass `TypeWithNullableDynamicKeys<typeof schema>` here purely to
1586
- // satisfy the adapter's constraint at the structural-cast layer.
1587
- // The PUBLIC signature's `GetValueFormType` default (line 67) is
1588
- // what consumers see — that's `z.output<UnwrapZodObject<Schema>>`,
1589
- // matching the docstring promise. Runtime is unaffected either way.
1590
1588
  schema: abstractSchema,
1591
1589
  defaultValues: configuration.defaultValues
1592
1590
  });
1593
1591
  }
1594
1592
 
1595
1593
  export { fieldMeta as f, isZodSchemaType as i, useForm as u, withMeta as w, zodAdapter as z };
1596
- //# sourceMappingURL=attaform.Drt6fivF.mjs.map
1594
+ //# sourceMappingURL=attaform.CtNUB9nf.mjs.map