attaform 0.14.0 → 0.15.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 (69) hide show
  1. package/dist/chunks/devtools.cjs +3 -3
  2. package/dist/chunks/devtools.cjs.map +1 -1
  3. package/dist/chunks/devtools.mjs +3 -3
  4. package/dist/chunks/devtools.mjs.map +1 -1
  5. package/dist/chunks/indexeddb.cjs +1 -1
  6. package/dist/chunks/indexeddb.mjs +1 -1
  7. package/dist/chunks/local-storage.cjs +1 -1
  8. package/dist/chunks/local-storage.mjs +1 -1
  9. package/dist/chunks/session-storage.cjs +1 -1
  10. package/dist/chunks/session-storage.mjs +1 -1
  11. package/dist/index.cjs +5 -4
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +4 -4
  14. package/dist/index.d.mts +4 -4
  15. package/dist/index.d.ts +4 -4
  16. package/dist/index.mjs +6 -6
  17. package/dist/nuxt.d.cts +1 -1
  18. package/dist/nuxt.d.mts +1 -1
  19. package/dist/nuxt.d.ts +1 -1
  20. package/dist/runtime/plugins/attaform.cjs +1 -1
  21. package/dist/runtime/plugins/attaform.mjs +1 -1
  22. package/dist/shared/{attaform.DDXrY-1Q.d.mts → attaform.0Gxd_OOx.d.cts} +558 -174
  23. package/dist/shared/{attaform.DDXrY-1Q.d.ts → attaform.0Gxd_OOx.d.mts} +558 -174
  24. package/dist/shared/{attaform.DDXrY-1Q.d.cts → attaform.0Gxd_OOx.d.ts} +558 -174
  25. package/dist/shared/{attaform.xKWYHMdq.cjs → attaform.BOi138GE.cjs} +10 -2
  26. package/dist/shared/{attaform.xKWYHMdq.cjs.map → attaform.BOi138GE.cjs.map} +1 -1
  27. package/dist/shared/{attaform.CRgix6_n.cjs → attaform.BgYBU8gV.cjs} +18 -17
  28. package/dist/shared/attaform.BgYBU8gV.cjs.map +1 -0
  29. package/dist/shared/attaform.Bubm_slq.cjs.map +1 -1
  30. package/dist/shared/{attaform.CNJO3mME.cjs → attaform.CDJVeoJU.cjs} +633 -236
  31. package/dist/shared/attaform.CDJVeoJU.cjs.map +1 -0
  32. package/dist/shared/{attaform.CXZgUECn.d.cts → attaform.CPx7zTgS.d.mts} +39 -9
  33. package/dist/shared/{attaform.DlgKK10S.mjs → attaform.CRk8NhlD.mjs} +18 -17
  34. package/dist/shared/attaform.CRk8NhlD.mjs.map +1 -0
  35. package/dist/shared/attaform.CXpzmj38.mjs.map +1 -1
  36. package/dist/shared/{attaform.DOKOyb3Y.d.mts → attaform.D-eHWfVx.d.cts} +39 -9
  37. package/dist/shared/{attaform.Cc93zNzD.mjs → attaform.DXye3JKf.mjs} +10 -3
  38. package/dist/shared/{attaform.Cc93zNzD.mjs.map → attaform.DXye3JKf.mjs.map} +1 -1
  39. package/dist/shared/{attaform.B5GWYl76.cjs → attaform.RypIkgVy.cjs} +38 -7
  40. package/dist/shared/attaform.RypIkgVy.cjs.map +1 -0
  41. package/dist/shared/{attaform.al_rpt7_.mjs → attaform.a99dQV7Q.mjs} +39 -8
  42. package/dist/shared/attaform.a99dQV7Q.mjs.map +1 -0
  43. package/dist/shared/{attaform.BRTxpA3q.mjs → attaform.qxyip_aN.mjs} +634 -238
  44. package/dist/shared/attaform.qxyip_aN.mjs.map +1 -0
  45. package/dist/shared/{attaform.BYc9kugA.d.ts → attaform.riAENZQM.d.ts} +39 -9
  46. package/dist/transforms.d.cts +2 -2
  47. package/dist/transforms.d.mts +2 -2
  48. package/dist/transforms.d.ts +2 -2
  49. package/dist/zod-v3.cjs +55 -3
  50. package/dist/zod-v3.cjs.map +1 -1
  51. package/dist/zod-v3.d.cts +77 -4
  52. package/dist/zod-v3.d.mts +77 -4
  53. package/dist/zod-v3.d.ts +77 -4
  54. package/dist/zod-v3.mjs +56 -6
  55. package/dist/zod-v3.mjs.map +1 -1
  56. package/dist/zod.cjs +372 -5
  57. package/dist/zod.cjs.map +1 -1
  58. package/dist/zod.d.cts +120 -4
  59. package/dist/zod.d.mts +120 -4
  60. package/dist/zod.d.ts +120 -4
  61. package/dist/zod.mjs +371 -8
  62. package/dist/zod.mjs.map +1 -1
  63. package/package.json +3 -1
  64. package/dist/shared/attaform.B5GWYl76.cjs.map +0 -1
  65. package/dist/shared/attaform.BRTxpA3q.mjs.map +0 -1
  66. package/dist/shared/attaform.CNJO3mME.cjs.map +0 -1
  67. package/dist/shared/attaform.CRgix6_n.cjs.map +0 -1
  68. package/dist/shared/attaform.DlgKK10S.mjs.map +0 -1
  69. package/dist/shared/attaform.al_rpt7_.mjs.map +0 -1
package/dist/zod.mjs CHANGED
@@ -1,9 +1,31 @@
1
- import { g as getAtPath, s as slimKindOf, e as setAtPath, f as isPlainRecord, A as AttaformErrorCode, c as useAbstractForm } from './shared/attaform.BRTxpA3q.mjs';
2
- export { i as injectForm, b as isUnset, u as unset } from './shared/attaform.BRTxpA3q.mjs';
3
- import { c as canonicalizePath } from './shared/attaform.Cc93zNzD.mjs';
4
- import { a as AttaformError, _ as __DEV__ } from './shared/attaform.al_rpt7_.mjs';
5
- export { u as useRegister } from './shared/attaform.al_rpt7_.mjs';
1
+ import { g as getAtPath, s as slimKindOf, e as setAtPath, f as isPlainRecord, A as AttaformErrorCode, h as humanize, c as useAbstractForm } from './shared/attaform.qxyip_aN.mjs';
2
+ export { i as injectForm, b as isUnset, u as unset } from './shared/attaform.qxyip_aN.mjs';
6
3
  import { z } from 'zod';
4
+ import { c as canonicalizePath } from './shared/attaform.DXye3JKf.mjs';
5
+ import { a as AttaformError, _ as __DEV__ } from './shared/attaform.a99dQV7Q.mjs';
6
+ export { u as useRegister } from './shared/attaform.a99dQV7Q.mjs';
7
+
8
+ const fieldMeta = z.registry();
9
+ const fieldMetaLists = /* @__PURE__ */ new WeakMap();
10
+ const originalAdd = fieldMeta.add.bind(fieldMeta);
11
+ fieldMeta.add = function add(schema, payload) {
12
+ const list = fieldMetaLists.get(schema) ?? [];
13
+ list.push(payload);
14
+ fieldMetaLists.set(schema, list);
15
+ return originalAdd(schema, payload);
16
+ };
17
+ function getFieldMetaList(schema) {
18
+ return fieldMetaLists.get(schema) ?? [];
19
+ }
20
+ function withMeta(schema, payload) {
21
+ const existing = fieldMeta.get(schema) ?? {};
22
+ const cloned = schema.clone();
23
+ fieldMeta.add(cloned, { ...existing, ...payload });
24
+ return cloned;
25
+ }
26
+ function getFieldMeta(schema) {
27
+ return fieldMeta.get(schema);
28
+ }
7
29
 
8
30
  let warnedZodCodeMissing = false;
9
31
  function zodIssuesToValidationErrors(issues, formKey) {
@@ -839,7 +861,9 @@ function walkSegments(schema, segments) {
839
861
  function carryChecks(rebuilt, original, stripConfig) {
840
862
  if (stripConfig.stripRefinements === true) return rebuilt;
841
863
  if (!hasChecks(original)) return rebuilt;
842
- const checks = getChecks(original);
864
+ const all = getChecks(original);
865
+ const checks = stripConfig.shouldKeepCheck === void 0 ? all : all.filter(stripConfig.shouldKeepCheck);
866
+ if (checks.length === 0) return rebuilt;
843
867
  return rebuilt.check(
844
868
  ...checks
845
869
  );
@@ -944,6 +968,131 @@ function stripRefinements(schema) {
944
968
  }
945
969
  }
946
970
  }
971
+ function stripAsyncChecks(schema) {
972
+ const config = {
973
+ stripRefinements: false,
974
+ shouldKeepCheck: (c) => !isAsyncCheck(c)
975
+ };
976
+ const seen = /* @__PURE__ */ new WeakSet();
977
+ function recurse(s) {
978
+ if (seen.has(s)) return s;
979
+ seen.add(s);
980
+ const kind = kindOf(s);
981
+ switch (kind) {
982
+ case "string":
983
+ return hasChecks(s) ? carryChecks(z.string(), s, config) : s;
984
+ case "number":
985
+ return hasChecks(s) ? carryChecks(z.number(), s, config) : s;
986
+ case "bigint":
987
+ return hasChecks(s) ? carryChecks(z.bigint(), s, config) : s;
988
+ case "array": {
989
+ const element = getArrayElement(s);
990
+ return carryChecks(z.array(recurse(element)), s, config);
991
+ }
992
+ case "set": {
993
+ const valueType = getSetValueType(s);
994
+ return carryChecks(z.set(recurse(valueType)), s, config);
995
+ }
996
+ case "tuple": {
997
+ const items = getTupleItems(s).map(recurse);
998
+ const rebuilt = z.tuple(
999
+ items
1000
+ );
1001
+ return carryChecks(rebuilt, s, config);
1002
+ }
1003
+ case "object": {
1004
+ const shape = getObjectShape(s);
1005
+ const next = {};
1006
+ for (const [k, v] of Object.entries(shape)) {
1007
+ next[k] = recurse(v);
1008
+ }
1009
+ return carryChecks(z.object(next), s, config);
1010
+ }
1011
+ case "record": {
1012
+ const keyType = getRecordKeyType(s);
1013
+ const valueType = recurse(getRecordValueType(s));
1014
+ const rebuilt = z.record(keyType, valueType);
1015
+ return carryChecks(rebuilt, s, config);
1016
+ }
1017
+ case "union": {
1018
+ const options = getUnionOptions(s).map(recurse);
1019
+ const rebuilt = z.union(
1020
+ options
1021
+ );
1022
+ return carryChecks(rebuilt, s, config);
1023
+ }
1024
+ case "discriminated-union": {
1025
+ const options = getDiscriminatedOptions(s).map((opt) => recurse(opt));
1026
+ const discriminator = getDiscriminator(s);
1027
+ if (discriminator === void 0) return s;
1028
+ return z.discriminatedUnion(
1029
+ discriminator,
1030
+ options
1031
+ );
1032
+ }
1033
+ case "optional": {
1034
+ const inner = unwrapInner(s);
1035
+ if (inner === void 0) return s;
1036
+ return recurse(inner).optional();
1037
+ }
1038
+ case "nullable": {
1039
+ const inner = unwrapInner(s);
1040
+ if (inner === void 0) return s;
1041
+ return recurse(inner).nullable();
1042
+ }
1043
+ case "default": {
1044
+ const inner = unwrapInner(s);
1045
+ if (inner === void 0) return s;
1046
+ return recurse(inner).default(getDefaultValue(s));
1047
+ }
1048
+ case "readonly": {
1049
+ const inner = unwrapInner(s);
1050
+ if (inner === void 0) return s;
1051
+ return recurse(inner).readonly();
1052
+ }
1053
+ case "pipe":
1054
+ return s;
1055
+ case "lazy": {
1056
+ const inner = unwrapLazy(s);
1057
+ if (inner === void 0) return s;
1058
+ const stripped = recurse(inner);
1059
+ return z.lazy(() => stripped);
1060
+ }
1061
+ case "intersection": {
1062
+ const left = getIntersectionLeft(s);
1063
+ const right = getIntersectionRight(s);
1064
+ if (left === void 0 || right === void 0) return s;
1065
+ return z.intersection(recurse(left), recurse(right));
1066
+ }
1067
+ case "catch": {
1068
+ const inner = unwrapInner(s);
1069
+ if (inner === void 0) return s;
1070
+ return recurse(inner).catch(getCatchDefault(s));
1071
+ }
1072
+ // Leaves with no checks — pass through unchanged.
1073
+ case "boolean":
1074
+ case "date":
1075
+ case "enum":
1076
+ case "literal":
1077
+ case "null":
1078
+ case "undefined":
1079
+ case "any":
1080
+ case "unknown":
1081
+ case "nan":
1082
+ case "void":
1083
+ case "never":
1084
+ case "promise":
1085
+ case "custom":
1086
+ case "template-literal":
1087
+ return s;
1088
+ default: {
1089
+ const _exhaustive = kind;
1090
+ throw new Error(`stripAsyncChecks: unhandled ZodKind '${_exhaustive}'`);
1091
+ }
1092
+ }
1093
+ }
1094
+ return recurse(schema);
1095
+ }
947
1096
  function getSlimSchema(schema, stripConfig) {
948
1097
  const kind = kindOf(schema);
949
1098
  switch (kind) {
@@ -1352,7 +1501,21 @@ function zodV4Adapter(rootSchema) {
1352
1501
  formKey
1353
1502
  };
1354
1503
  } catch {
1355
- return { data, errors: void 0, success: true, formKey };
1504
+ try {
1505
+ const syncOnly = stripAsyncChecks(rootSchema);
1506
+ const syncResult = syncOnly.safeParse(data);
1507
+ if (syncResult.success) {
1508
+ return { data, errors: void 0, success: true, formKey };
1509
+ }
1510
+ return {
1511
+ data,
1512
+ errors: zodIssuesToValidationErrors(syncResult.error.issues, formKey),
1513
+ success: false,
1514
+ formKey
1515
+ };
1516
+ } catch {
1517
+ return { data, errors: void 0, success: true, formKey };
1518
+ }
1356
1519
  }
1357
1520
  }
1358
1521
  return { data, errors: void 0, success: true, formKey };
@@ -1426,6 +1589,9 @@ function zodV4Adapter(rootSchema) {
1426
1589
  if (resolved.length === 0) return false;
1427
1590
  return resolved.every((candidate) => isLeafRequired(candidate));
1428
1591
  },
1592
+ getFieldMetaAtPath(path) {
1593
+ return resolveFieldMetaAtPath(rootSchema, path);
1594
+ },
1429
1595
  getUnionDiscriminatorAtPath(path) {
1430
1596
  const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
1431
1597
  let matchedUnion;
@@ -1526,6 +1692,203 @@ function zodV4Adapter(rootSchema) {
1526
1692
  };
1527
1693
  };
1528
1694
  }
1695
+ const pathMetaCache = /* @__PURE__ */ new WeakMap();
1696
+ function getPathMetaMap(rootSchema) {
1697
+ const cached = pathMetaCache.get(rootSchema);
1698
+ if (cached !== void 0) return cached;
1699
+ const map = /* @__PURE__ */ new Map();
1700
+ const counters = /* @__PURE__ */ new Map();
1701
+ const lastPathPerSchema = /* @__PURE__ */ new Map();
1702
+ const inProgress = /* @__PURE__ */ new WeakSet();
1703
+ walkForMeta(rootSchema, [], map, counters, lastPathPerSchema, inProgress);
1704
+ for (const [schema, lastPath] of lastPathPerSchema) {
1705
+ const list = getFieldMetaList(schema);
1706
+ const consumed = counters.get(schema) ?? 0;
1707
+ if (list.length <= consumed) continue;
1708
+ const surplus = list.slice(consumed).reduce((acc, p) => ({ ...acc, ...p }), {});
1709
+ const existing = map.get(lastPath) ?? {};
1710
+ map.set(lastPath, { ...existing, ...surplus });
1711
+ }
1712
+ pathMetaCache.set(rootSchema, map);
1713
+ return map;
1714
+ }
1715
+ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress) {
1716
+ if (inProgress.has(schema)) return;
1717
+ inProgress.add(schema);
1718
+ try {
1719
+ const pathKey = canonicalizePath(path).key;
1720
+ if (!map.has(pathKey)) {
1721
+ const payload = consumePayload(schema, counters);
1722
+ if (payload !== void 0) {
1723
+ map.set(pathKey, payload);
1724
+ lastPathPerSchema.set(schema, pathKey);
1725
+ }
1726
+ }
1727
+ const peeled = peelAllWrappers(schema);
1728
+ if (peeled !== schema && !map.has(pathKey)) {
1729
+ const payload = consumePayload(peeled, counters);
1730
+ if (payload !== void 0) {
1731
+ map.set(pathKey, payload);
1732
+ lastPathPerSchema.set(peeled, pathKey);
1733
+ }
1734
+ }
1735
+ const kind = kindOf(schema);
1736
+ switch (kind) {
1737
+ case "object": {
1738
+ const shape = getObjectShape(schema);
1739
+ for (const [key, child] of Object.entries(shape)) {
1740
+ walkForMeta(child, [...path, key], map, counters, lastPathPerSchema, inProgress);
1741
+ }
1742
+ return;
1743
+ }
1744
+ case "array": {
1745
+ walkForMeta(
1746
+ getArrayElement(schema),
1747
+ [...path, 0],
1748
+ map,
1749
+ counters,
1750
+ lastPathPerSchema,
1751
+ inProgress
1752
+ );
1753
+ return;
1754
+ }
1755
+ case "tuple": {
1756
+ const items = getTupleItems(schema);
1757
+ for (let i = 0; i < items.length; i++) {
1758
+ const item = items[i];
1759
+ if (item !== void 0)
1760
+ walkForMeta(item, [...path, i], map, counters, lastPathPerSchema, inProgress);
1761
+ }
1762
+ return;
1763
+ }
1764
+ case "set":
1765
+ walkForMeta(
1766
+ getSetValueType(schema),
1767
+ [...path, 0],
1768
+ map,
1769
+ counters,
1770
+ lastPathPerSchema,
1771
+ inProgress
1772
+ );
1773
+ return;
1774
+ case "record":
1775
+ walkForMeta(
1776
+ getRecordValueType(schema),
1777
+ [...path, "*"],
1778
+ map,
1779
+ counters,
1780
+ lastPathPerSchema,
1781
+ inProgress
1782
+ );
1783
+ return;
1784
+ case "union": {
1785
+ for (const opt of getUnionOptions(schema)) {
1786
+ walkForMeta(opt, path, map, counters, lastPathPerSchema, inProgress);
1787
+ }
1788
+ return;
1789
+ }
1790
+ case "discriminated-union": {
1791
+ for (const opt of getDiscriminatedOptions(schema)) {
1792
+ walkForMeta(opt, path, map, counters, lastPathPerSchema, inProgress);
1793
+ }
1794
+ return;
1795
+ }
1796
+ case "optional":
1797
+ case "nullable":
1798
+ case "default":
1799
+ case "readonly":
1800
+ case "catch": {
1801
+ const inner = unwrapInner(schema);
1802
+ if (inner !== void 0)
1803
+ walkForMeta(inner, path, map, counters, lastPathPerSchema, inProgress);
1804
+ return;
1805
+ }
1806
+ case "pipe": {
1807
+ const inner = unwrapPipe(schema);
1808
+ if (inner !== void 0)
1809
+ walkForMeta(inner, path, map, counters, lastPathPerSchema, inProgress);
1810
+ return;
1811
+ }
1812
+ case "lazy": {
1813
+ const inner = unwrapLazy(schema);
1814
+ if (inner !== void 0)
1815
+ walkForMeta(inner, path, map, counters, lastPathPerSchema, inProgress);
1816
+ return;
1817
+ }
1818
+ case "intersection": {
1819
+ const left = getIntersectionLeft(schema);
1820
+ const right = getIntersectionRight(schema);
1821
+ if (left !== void 0)
1822
+ walkForMeta(left, path, map, counters, lastPathPerSchema, inProgress);
1823
+ if (right !== void 0)
1824
+ walkForMeta(right, path, map, counters, lastPathPerSchema, inProgress);
1825
+ return;
1826
+ }
1827
+ // Leaf kinds — no children to descend into; metadata for the
1828
+ // path itself was captured above. Listed explicitly so the
1829
+ // exhaustiveness check catches any new kind landing in Zod
1830
+ // without a corresponding decision here.
1831
+ case "string":
1832
+ case "number":
1833
+ case "bigint":
1834
+ case "boolean":
1835
+ case "date":
1836
+ case "enum":
1837
+ case "literal":
1838
+ case "null":
1839
+ case "undefined":
1840
+ case "any":
1841
+ case "unknown":
1842
+ case "nan":
1843
+ case "void":
1844
+ case "never":
1845
+ case "promise":
1846
+ case "custom":
1847
+ case "template-literal":
1848
+ return;
1849
+ }
1850
+ } finally {
1851
+ inProgress.delete(schema);
1852
+ }
1853
+ }
1854
+ function consumePayload(schema, counters) {
1855
+ const list = getFieldMetaList(schema);
1856
+ if (list.length === 0) return void 0;
1857
+ const idx = counters.get(schema) ?? 0;
1858
+ const payload = list[Math.min(idx, list.length - 1)];
1859
+ counters.set(schema, idx + 1);
1860
+ return payload;
1861
+ }
1862
+ function resolveFieldMetaAtPath(rootSchema, path) {
1863
+ const lastSegment = path.length === 0 ? "" : path[path.length - 1];
1864
+ const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
1865
+ const target = candidates[0];
1866
+ if (target === void 0) {
1867
+ return {
1868
+ label: humanize(lastSegment),
1869
+ description: void 0,
1870
+ placeholder: void 0,
1871
+ meta: Object.freeze({})
1872
+ };
1873
+ }
1874
+ const pathMap = getPathMetaMap(rootSchema);
1875
+ const pathKey = canonicalizePath(path).key;
1876
+ const peeled = peelAllWrappers(target);
1877
+ const payload = pathMap.get(pathKey) ?? getFieldMeta(target) ?? (peeled !== target ? getFieldMeta(peeled) : void 0);
1878
+ const targetDescription = readDescription(target);
1879
+ const peeledDescription = peeled !== target ? readDescription(peeled) : void 0;
1880
+ const schemaDescription = targetDescription ?? peeledDescription;
1881
+ return {
1882
+ label: payload?.label ?? humanize(lastSegment),
1883
+ description: payload?.description ?? schemaDescription ?? void 0,
1884
+ placeholder: payload?.placeholder ?? void 0,
1885
+ meta: Object.freeze({ ...payload ?? {} })
1886
+ };
1887
+ }
1888
+ function readDescription(schema) {
1889
+ const candidate = schema.description;
1890
+ return typeof candidate === "string" ? candidate : void 0;
1891
+ }
1529
1892
 
1530
1893
  function useForm(configuration) {
1531
1894
  const adapter = zodV4Adapter(
@@ -1537,5 +1900,5 @@ function useForm(configuration) {
1537
1900
  });
1538
1901
  }
1539
1902
 
1540
- export { AttaformErrorCode, UnsupportedSchemaError, useForm, zodV4Adapter as zodAdapter };
1903
+ export { AttaformErrorCode, UnsupportedSchemaError, assertZodVersion, fieldMeta, kindOf, useForm, withMeta, zodV4Adapter as zodAdapter };
1541
1904
  //# sourceMappingURL=zod.mjs.map