attaform 0.27.6 → 0.29.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 (192) hide show
  1. package/dist/abstract.d.mts +5 -4
  2. package/dist/abstract.mjs +4 -3
  3. package/dist/chunks/fingerprint.mjs +1 -2
  4. package/dist/chunks/fingerprint2.mjs +2 -3
  5. package/dist/dev/abstract.mjs +4 -0
  6. package/dist/{chunks → dev/chunks}/dev-key-collision-warnings.mjs +0 -1
  7. package/dist/{chunks → dev/chunks}/devtools.mjs +5 -6
  8. package/dist/{chunks/fingerprint.cjs → dev/chunks/fingerprint.mjs} +7 -10
  9. package/dist/{chunks/fingerprint2.cjs → dev/chunks/fingerprint2.mjs} +32 -35
  10. package/dist/dev/directive.mjs +1 -0
  11. package/dist/dev/history.mjs +89 -0
  12. package/dist/dev/index.mjs +5 -0
  13. package/dist/dev/runtime/plugins/attaform.mjs +40 -0
  14. package/dist/dev/shared/attaform-dev.A-TpJW0B.mjs +207 -0
  15. package/dist/dev/shared/attaform-dev.BO-71R54.mjs +820 -0
  16. package/dist/{shared/attaform.D6tk90Rc.cjs → dev/shared/attaform-dev.BgM6FdtA.mjs} +324 -73
  17. package/dist/dev/shared/attaform-dev.ButTkwHd.mjs +375 -0
  18. package/dist/{shared/attaform.BJGA_UOS.mjs → dev/shared/attaform-dev.BxfsuwBR.mjs} +8 -1
  19. package/dist/{shared/attaform.nMaz2C5P.mjs → dev/shared/attaform-dev.D8aoKb89.mjs} +190 -400
  20. package/dist/dev/shared/attaform-dev.DD5m2W51.mjs +220 -0
  21. package/dist/{shared/attaform.CKH2lGdL.mjs → dev/shared/attaform-dev.DHuydLAC.mjs} +3867 -4731
  22. package/dist/{shared/attaform.DYEr28Pt.mjs → dev/shared/attaform-dev.DrzObAZo.mjs} +6 -7
  23. package/dist/{shared/attaform.B1ZYt2Li.mjs → dev/shared/attaform-dev.q6UutkCx.mjs} +274 -672
  24. package/dist/dev/zod-v3.mjs +17 -0
  25. package/dist/dev/zod-v4.mjs +16 -0
  26. package/dist/dev/zod.mjs +5 -0
  27. package/dist/directive.d.mts +20 -0
  28. package/dist/directive.mjs +1 -0
  29. package/dist/esbuild.mjs +0 -1
  30. package/dist/history.d.mts +59 -0
  31. package/dist/history.mjs +89 -0
  32. package/dist/index.d.mts +14 -6
  33. package/dist/index.mjs +5 -4
  34. package/dist/nuxt.d.mts +10 -10
  35. package/dist/nuxt.mjs +5 -2
  36. package/dist/rollup.mjs +0 -1
  37. package/dist/rspack.d.mts +6 -1
  38. package/dist/rspack.mjs +0 -1
  39. package/dist/runtime/components/AttaformDevtoolsPanel.vue +9 -8
  40. package/dist/runtime/plugins/attaform.mjs +1 -2
  41. package/dist/shared/{attaform.CoR4mWfv.mjs → attaform.B0dKL8ST.mjs} +309 -46
  42. package/dist/shared/{attaform.Cs2Rbdlo.mjs → attaform.BK0cgu2K.mjs} +123 -140
  43. package/dist/shared/{attaform.B9Wyhfro.cjs → attaform.BndjUUYX.mjs} +11 -16
  44. package/dist/shared/{attaform.CQN9R62B.cjs → attaform.BxfsuwBR.mjs} +9 -4
  45. package/dist/shared/attaform.C2MVyuxC.mjs +811 -0
  46. package/dist/shared/{attaform.Fp3sCrVs.d.ts → attaform.CIWLMY-R.d.mts} +2 -2
  47. package/dist/shared/attaform.CZMAYwSK.mjs +6383 -0
  48. package/dist/shared/attaform.CZYt_5N_.mjs +207 -0
  49. package/dist/shared/{attaform.DniawQLP.d.cts → attaform.CsoeRi3P.d.mts} +490 -98
  50. package/dist/shared/attaform.Cvao8bW5.mjs +358 -0
  51. package/dist/shared/attaform.D0x-qSXm.mjs +197 -0
  52. package/dist/shared/{attaform.D8kliaKw.cjs → attaform.D1fnTifF.mjs} +279 -692
  53. package/dist/shared/{attaform.CHlJLAiv.d.mts → attaform.DDtqHYv1.d.mts} +155 -184
  54. package/dist/shared/{attaform.Biytrv0-.cjs → attaform.DffRL5pP.mjs} +215 -547
  55. package/dist/shared/attaform.DhnPb6nK.mjs +0 -1
  56. package/dist/shared/attaform.KvlEedlF.mjs +0 -1
  57. package/dist/shared/attaform.axHXVQO7.d.mts +44 -0
  58. package/dist/shared/attaform.v0fQtWyA.mjs +0 -1
  59. package/dist/transforms.d.mts +0 -22
  60. package/dist/transforms.mjs +1 -2
  61. package/dist/vite.d.mts +30 -9
  62. package/dist/vite.mjs +27 -4
  63. package/dist/webpack.d.mts +6 -1
  64. package/dist/webpack.mjs +0 -1
  65. package/dist/zod-v3.d.mts +13 -6
  66. package/dist/zod-v3.mjs +17 -4
  67. package/dist/zod-v4.d.mts +19 -26
  68. package/dist/zod-v4.mjs +16 -4
  69. package/dist/zod.d.mts +4 -3
  70. package/dist/zod.mjs +5 -4
  71. package/package.json +38 -20
  72. package/skills/attaform/SKILL.md +6 -2
  73. package/skills/attaform/references/custom-components.md +7 -2
  74. package/skills/attaform/references/errors.md +8 -3
  75. package/skills/attaform/references/saving.md +77 -0
  76. package/skills/attaform/references/wizards.md +10 -8
  77. package/dist/abstract.cjs +0 -48
  78. package/dist/abstract.cjs.map +0 -1
  79. package/dist/abstract.d.cts +0 -42
  80. package/dist/abstract.d.ts +0 -42
  81. package/dist/abstract.mjs.map +0 -1
  82. package/dist/chunks/dev-key-collision-warnings.cjs +0 -25
  83. package/dist/chunks/dev-key-collision-warnings.cjs.map +0 -1
  84. package/dist/chunks/dev-key-collision-warnings.mjs.map +0 -1
  85. package/dist/chunks/devtools.cjs +0 -157
  86. package/dist/chunks/devtools.cjs.map +0 -1
  87. package/dist/chunks/devtools.mjs.map +0 -1
  88. package/dist/chunks/fingerprint.cjs.map +0 -1
  89. package/dist/chunks/fingerprint.mjs.map +0 -1
  90. package/dist/chunks/fingerprint2.cjs.map +0 -1
  91. package/dist/chunks/fingerprint2.mjs.map +0 -1
  92. package/dist/esbuild.cjs +0 -28
  93. package/dist/esbuild.cjs.map +0 -1
  94. package/dist/esbuild.d.cts +0 -56
  95. package/dist/esbuild.d.ts +0 -56
  96. package/dist/esbuild.mjs.map +0 -1
  97. package/dist/index.cjs +0 -51
  98. package/dist/index.cjs.map +0 -1
  99. package/dist/index.d.cts +0 -249
  100. package/dist/index.d.ts +0 -249
  101. package/dist/index.mjs.map +0 -1
  102. package/dist/nuxt.cjs +0 -84
  103. package/dist/nuxt.cjs.map +0 -1
  104. package/dist/nuxt.d.cts +0 -66
  105. package/dist/nuxt.d.ts +0 -66
  106. package/dist/nuxt.mjs.map +0 -1
  107. package/dist/rollup.cjs +0 -24
  108. package/dist/rollup.cjs.map +0 -1
  109. package/dist/rollup.d.cts +0 -35
  110. package/dist/rollup.d.ts +0 -35
  111. package/dist/rollup.mjs.map +0 -1
  112. package/dist/rspack.cjs +0 -10
  113. package/dist/rspack.cjs.map +0 -1
  114. package/dist/rspack.d.cts +0 -40
  115. package/dist/rspack.d.ts +0 -40
  116. package/dist/rspack.mjs.map +0 -1
  117. package/dist/runtime/components/AttaformDevtoolsPanel.vue.d.ts +0 -7
  118. package/dist/runtime/components/DevtoolsValueTree.vue.d.ts +0 -35
  119. package/dist/runtime/plugins/attaform.cjs +0 -43
  120. package/dist/runtime/plugins/attaform.cjs.map +0 -1
  121. package/dist/runtime/plugins/attaform.d.cts +0 -5
  122. package/dist/runtime/plugins/attaform.d.ts +0 -5
  123. package/dist/runtime/plugins/attaform.mjs.map +0 -1
  124. package/dist/shared/attaform.B1ZYt2Li.mjs.map +0 -1
  125. package/dist/shared/attaform.B9Wyhfro.cjs.map +0 -1
  126. package/dist/shared/attaform.BGDV42hI.d.cts +0 -232
  127. package/dist/shared/attaform.BJGA_UOS.mjs.map +0 -1
  128. package/dist/shared/attaform.Biytrv0-.cjs.map +0 -1
  129. package/dist/shared/attaform.Bn0IzhD_.cjs +0 -800
  130. package/dist/shared/attaform.Bn0IzhD_.cjs.map +0 -1
  131. package/dist/shared/attaform.C9fPTxjB.d.cts +0 -41
  132. package/dist/shared/attaform.C9fPTxjB.d.ts +0 -41
  133. package/dist/shared/attaform.CKH2lGdL.mjs.map +0 -1
  134. package/dist/shared/attaform.CQN9R62B.cjs.map +0 -1
  135. package/dist/shared/attaform.CoR4mWfv.mjs.map +0 -1
  136. package/dist/shared/attaform.Cs2Rbdlo.mjs.map +0 -1
  137. package/dist/shared/attaform.D6tk90Rc.cjs.map +0 -1
  138. package/dist/shared/attaform.D8kliaKw.cjs.map +0 -1
  139. package/dist/shared/attaform.DLknk9nF.d.mts +0 -232
  140. package/dist/shared/attaform.DMxM2kol.mjs +0 -1275
  141. package/dist/shared/attaform.DMxM2kol.mjs.map +0 -1
  142. package/dist/shared/attaform.DRUT703x.d.cts +0 -56
  143. package/dist/shared/attaform.DRUT703x.d.ts +0 -56
  144. package/dist/shared/attaform.DYEr28Pt.mjs.map +0 -1
  145. package/dist/shared/attaform.DdQN7sgN.cjs +0 -1302
  146. package/dist/shared/attaform.DdQN7sgN.cjs.map +0 -1
  147. package/dist/shared/attaform.DhnPb6nK.mjs.map +0 -1
  148. package/dist/shared/attaform.DniawQLP.d.mts +0 -4763
  149. package/dist/shared/attaform.DniawQLP.d.ts +0 -4763
  150. package/dist/shared/attaform.DoQm_Vkd.cjs +0 -58
  151. package/dist/shared/attaform.DoQm_Vkd.cjs.map +0 -1
  152. package/dist/shared/attaform.DrvMscNX.cjs +0 -7697
  153. package/dist/shared/attaform.DrvMscNX.cjs.map +0 -1
  154. package/dist/shared/attaform.F2Q8iv38.d.ts +0 -2494
  155. package/dist/shared/attaform.FmqKO1Ex.d.cts +0 -2494
  156. package/dist/shared/attaform.KvlEedlF.mjs.map +0 -1
  157. package/dist/shared/attaform.RaTzp1WF.cjs +0 -26
  158. package/dist/shared/attaform.RaTzp1WF.cjs.map +0 -1
  159. package/dist/shared/attaform.nMaz2C5P.mjs.map +0 -1
  160. package/dist/shared/attaform.v0fQtWyA.mjs.map +0 -1
  161. package/dist/shared/attaform.yUrz7C2z.cjs +0 -29
  162. package/dist/shared/attaform.yUrz7C2z.cjs.map +0 -1
  163. package/dist/transforms.cjs +0 -12
  164. package/dist/transforms.cjs.map +0 -1
  165. package/dist/transforms.d.cts +0 -73
  166. package/dist/transforms.d.ts +0 -73
  167. package/dist/transforms.mjs.map +0 -1
  168. package/dist/vite.cjs +0 -363
  169. package/dist/vite.cjs.map +0 -1
  170. package/dist/vite.d.cts +0 -133
  171. package/dist/vite.d.ts +0 -133
  172. package/dist/vite.mjs.map +0 -1
  173. package/dist/webpack.cjs +0 -10
  174. package/dist/webpack.cjs.map +0 -1
  175. package/dist/webpack.d.cts +0 -37
  176. package/dist/webpack.d.ts +0 -37
  177. package/dist/webpack.mjs.map +0 -1
  178. package/dist/zod-v3.cjs +0 -53
  179. package/dist/zod-v3.cjs.map +0 -1
  180. package/dist/zod-v3.d.cts +0 -246
  181. package/dist/zod-v3.d.ts +0 -246
  182. package/dist/zod-v3.mjs.map +0 -1
  183. package/dist/zod-v4.cjs +0 -55
  184. package/dist/zod-v4.cjs.map +0 -1
  185. package/dist/zod-v4.d.cts +0 -172
  186. package/dist/zod-v4.d.ts +0 -172
  187. package/dist/zod-v4.mjs.map +0 -1
  188. package/dist/zod.cjs +0 -51
  189. package/dist/zod.cjs.map +0 -1
  190. package/dist/zod.d.cts +0 -7
  191. package/dist/zod.d.ts +0 -7
  192. package/dist/zod.mjs.map +0 -1
@@ -1,14 +1,30 @@
1
- import { A as AttaformErrorCode, n as isPlainRecord, s as safeOwnRead, o as safeAssign, p as slimKindOf } from './attaform.CKH2lGdL.mjs';
2
- import { f as canonicalizePath } from './attaform.nMaz2C5P.mjs';
1
+ import { A as AttaformErrorCode, n as isPlainRecord, s as slimKindOf, o as crossCopyState } from './attaform.CZMAYwSK.mjs';
2
+ import { e as canonicalizePath, h as SET_MEMBER_SEGMENT } from './attaform.CZYt_5N_.mjs';
3
+ import { a as safeOwnRead, b as safeAssign } from './attaform.Cvao8bW5.mjs';
3
4
 
4
5
  const PATH_SEPARATOR = ".";
6
+ function isOpaqueKind(kind) {
7
+ return kind === "any" || kind === "unknown" || kind === "custom";
8
+ }
5
9
  function createAbstractSchema(rootSchema, intro, services, formKey, options) {
6
10
  const maxRecursionDepth = options.maxRecursionDepth;
7
11
  const leafCache = /* @__PURE__ */ new Map();
8
12
  const preprocessOrCoerceCache = /* @__PURE__ */ new Map();
13
+ const opaqueLeafCache = /* @__PURE__ */ new Map();
9
14
  const discriminatorCache = /* @__PURE__ */ new Map();
15
+ const entryKeyKindCache = /* @__PURE__ */ new Map();
10
16
  let asyncValidationFlag = null;
11
17
  let containerRefineFlag = null;
18
+ let discriminatedUnionFlag = null;
19
+ function mapKeySegmentKind(schema) {
20
+ const keyType = intro.getMapKeyType(schema);
21
+ if (keyType === void 0) return void 0;
22
+ const kinds = services.slimPrimitivesOf(keyType, maxRecursionDepth);
23
+ const string = kinds.has("string");
24
+ const number = kinds.has("number");
25
+ if (string === number) return void 0;
26
+ return string ? "string" : "number";
27
+ }
12
28
  function computeDiscriminator(path) {
13
29
  const candidates = path.length === 0 ? [rootSchema] : services.getNestedSchemasAtPath(rootSchema, path, maxRecursionDepth);
14
30
  let matchedUnion;
@@ -60,6 +76,10 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
60
76
  containerRefineFlag ?? (containerRefineFlag = intro.hasContainerOrRootRefine(rootSchema));
61
77
  return containerRefineFlag;
62
78
  },
79
+ hasDiscriminatedUnions() {
80
+ discriminatedUnionFlag ?? (discriminatedUnionFlag = intro.containsDiscriminatedUnion(rootSchema));
81
+ return discriminatedUnionFlag;
82
+ },
63
83
  getDefaultValues(config) {
64
84
  return services.runStrictGetDefaults(rootSchema, config, formKey, maxRecursionDepth);
65
85
  },
@@ -81,14 +101,12 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
81
101
  return services.deriveDefault(first, false, maxRecursionDepth, formKey);
82
102
  },
83
103
  arrayShapeAtPath(path) {
84
- if (path.length === 0) return void 0;
104
+ if (path.length === 0) return null;
85
105
  const [first] = services.getNestedSchemasAtPath(rootSchema, path, maxRecursionDepth);
86
- if (first === void 0) return void 0;
106
+ if (first === void 0) return null;
87
107
  const peeled = services.peelAllWrappers(first);
88
- const kind = intro.kindOf(peeled);
89
- if (kind === "tuple") return intro.getTupleItems(peeled).length;
90
- if (kind === "array") return null;
91
- return void 0;
108
+ if (intro.kindOf(peeled) === "tuple") return intro.getTupleItems(peeled).length;
109
+ return null;
92
110
  },
93
111
  isFixedObjectAtPath(path) {
94
112
  if (path.length === 0) {
@@ -98,6 +116,32 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
98
116
  if (resolved.length === 0) return false;
99
117
  return resolved.every((s) => intro.kindOf(services.peelAllWrappers(s)) === "object");
100
118
  },
119
+ entryKeyKindAtPath(path) {
120
+ const cacheKey = canonicalizePath(path).key;
121
+ if (entryKeyKindCache.has(cacheKey)) return entryKeyKindCache.get(cacheKey);
122
+ const resolved = path.length === 0 ? [rootSchema] : services.getNestedSchemasAtPath(rootSchema, path, maxRecursionDepth);
123
+ let answer;
124
+ const only = resolved.length === 1 ? resolved[0] : void 0;
125
+ if (only !== void 0) {
126
+ switch (intro.kindOf(services.peelAllWrappers(only))) {
127
+ case "array":
128
+ case "tuple":
129
+ answer = "number";
130
+ break;
131
+ case "object":
132
+ case "record":
133
+ answer = "string";
134
+ break;
135
+ case "map":
136
+ answer = mapKeySegmentKind(services.peelAllWrappers(only));
137
+ break;
138
+ default:
139
+ answer = void 0;
140
+ }
141
+ }
142
+ entryKeyKindCache.set(cacheKey, answer);
143
+ return answer;
144
+ },
101
145
  getSchemasAtPath(path) {
102
146
  const resolved = services.getNestedSchemasInSlimMode(rootSchema, path, maxRecursionDepth);
103
147
  if (resolved.length === 0) return [];
@@ -119,8 +163,9 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
119
163
  const cacheKey = canonicalizePath(path).key;
120
164
  const cached = leafCache.get(cacheKey);
121
165
  if (cached !== void 0) return cached;
122
- const prim = this.getSlimPrimitiveTypesAtPath(path);
123
- const isLeaf = prim.size > 0 && !prim.has("object") && !prim.has("array") && !prim.has("map") && !prim.has("set");
166
+ const opaque = path.length > 0 && this.isOpaqueLeafAtPath(path);
167
+ const prim = opaque ? void 0 : this.getSlimPrimitiveTypesAtPath(path);
168
+ const isLeaf = opaque || prim !== void 0 && prim.size > 0 && !prim.has("object") && !prim.has("array") && !prim.has("map") && !prim.has("set");
124
169
  leafCache.set(cacheKey, isLeaf);
125
170
  return isLeaf;
126
171
  },
@@ -142,6 +187,17 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
142
187
  preprocessOrCoerceCache.set(cacheKey, hit);
143
188
  return hit;
144
189
  },
190
+ isOpaqueLeafAtPath(path) {
191
+ const cacheKey = canonicalizePath(path).key;
192
+ const cached = opaqueLeafCache.get(cacheKey);
193
+ if (cached !== void 0) return cached;
194
+ const resolved = path.length === 0 ? [rootSchema] : services.getNestedSchemasAtPath(rootSchema, path, maxRecursionDepth);
195
+ const opaque = resolved.length > 0 && resolved.every(
196
+ (candidate) => isOpaqueKind(intro.kindOf(services.peelAllWrappers(candidate)))
197
+ );
198
+ opaqueLeafCache.set(cacheKey, opaque);
199
+ return opaque;
200
+ },
145
201
  isRequiredAtPath(path) {
146
202
  if (path.length === 0) return true;
147
203
  const resolved = services.getNestedSchemasAtPath(rootSchema, path, maxRecursionDepth);
@@ -172,7 +228,7 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
172
228
  function parseResultToResponse(result) {
173
229
  return result.success ? { data: result.data, errors: void 0, success: true, formKey } : {
174
230
  data: void 0,
175
- errors: services.issuesToValidationErrors(result.issues, formKey),
231
+ errors: services.issuesToValidationErrors(result.issues),
176
232
  success: false,
177
233
  formKey
178
234
  };
@@ -225,7 +281,6 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
225
281
  {
226
282
  message,
227
283
  path: [...errPath],
228
- formKey,
229
284
  code: AttaformErrorCode.ValidatorThrew
230
285
  }
231
286
  ],
@@ -240,7 +295,6 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
240
295
  {
241
296
  message: `Path '${p.join(PATH_SEPARATOR)}' did not resolve to any schema`,
242
297
  path: [...p],
243
- formKey,
244
298
  code: AttaformErrorCode.PathNotFound
245
299
  }
246
300
  ],
@@ -287,6 +341,7 @@ function walkPathSegments(schema, segments, intro, maxDepth, lazyDepth) {
287
341
  return inner === void 0 ? [] : walkPathSegments(inner, rest, intro, maxDepth, lazyDepth);
288
342
  }
289
343
  case "set": {
344
+ if (head !== SET_MEMBER_SEGMENT) return [];
290
345
  const inner = intro.getSetValueType(schema);
291
346
  return inner === void 0 ? [] : walkPathSegments(inner, rest, intro, maxDepth, lazyDepth);
292
347
  }
@@ -294,6 +349,10 @@ function walkPathSegments(schema, segments, intro, maxDepth, lazyDepth) {
294
349
  const inner = intro.getRecordValueType(schema);
295
350
  return inner === void 0 ? [] : walkPathSegments(inner, rest, intro, maxDepth, lazyDepth);
296
351
  }
352
+ case "map": {
353
+ const inner = intro.getMapValueType(schema);
354
+ return inner === void 0 ? [] : walkPathSegments(inner, rest, intro, maxDepth, lazyDepth);
355
+ }
297
356
  case "tuple": {
298
357
  const index = Number(head);
299
358
  if (!Number.isInteger(index)) return [];
@@ -347,16 +406,165 @@ function walkPathSegments(schema, segments, intro, maxDepth, lazyDepth) {
347
406
  const rightResults = right === void 0 ? [] : walkPathSegments(right, segments, intro, maxDepth, lazyDepth);
348
407
  return [...leftResults, ...rightResults];
349
408
  }
350
- // Leaves — can't descend further. The unsupported kinds (`map` /
351
- // `symbol` / `function` / `promise`) are rejected at adapter
352
- // construction by `assertSupportedKinds`; falling through to `[]`
353
- // keeps the walker defensive in case construction is skipped
354
- // (e.g. a downstream test instantiates a sub-schema directly).
409
+ // Leaves — can't descend further. Opaque leaves (`any` /
410
+ // `unknown` / `custom`) land here too and `[]` is the truthful
411
+ // answer: the schema declares no sub-paths under them, so none are
412
+ // fabricated. `symbol` / `function` / `promise` hold a value
413
+ // without declaring anything inside it and land here for the same
414
+ // reason. No kind is refused at construction (#607), so this is
415
+ // the only branch they ever take.
355
416
  default:
356
417
  return [];
357
418
  }
358
419
  }
359
420
 
421
+ function fixStructuralDefaults(schema, merged, useDefault, maxRecursionDepth, services) {
422
+ const ctx = {
423
+ useDefault,
424
+ maxDepth: maxRecursionDepth,
425
+ clean: true,
426
+ services
427
+ };
428
+ const data = fixNode(schema, merged, ctx, 0);
429
+ return { data, success: ctx.clean };
430
+ }
431
+ function fixNode(schema, value, ctx, lazyDepth) {
432
+ const { intro } = ctx.services;
433
+ if (intro.isCoercePrimitive(schema) || intro.isPreprocessNode(schema)) return value;
434
+ const kinds = ctx.services.slimPrimitivesOf(schema);
435
+ if (kinds.size > 0 && !kinds.has(slimKindOf(value))) {
436
+ const replacement = deriveFixValue(schema, value, ctx);
437
+ if (kinds.has(slimKindOf(replacement))) return replacement;
438
+ ctx.clean = false;
439
+ return replacement;
440
+ }
441
+ switch (intro.kindOf(schema)) {
442
+ case "optional":
443
+ case "nullable": {
444
+ if (value === void 0 || value === null) return value;
445
+ const inner = intro.unwrapInner(schema);
446
+ return inner === void 0 ? value : fixNode(inner, value, ctx, lazyDepth);
447
+ }
448
+ case "default":
449
+ case "readonly":
450
+ case "catch": {
451
+ const inner = intro.unwrapInner(schema);
452
+ return inner === void 0 ? value : fixNode(inner, value, ctx, lazyDepth);
453
+ }
454
+ case "branded": {
455
+ const inner = intro.unwrapBranded(schema);
456
+ return inner === void 0 ? value : fixNode(inner, value, ctx, lazyDepth);
457
+ }
458
+ case "effects": {
459
+ const inner = intro.unwrapEffectsSource(schema);
460
+ return inner === void 0 ? value : fixNode(inner, value, ctx, lazyDepth);
461
+ }
462
+ case "pipe":
463
+ case "pipeline": {
464
+ const pipeIn = intro.unwrapPipeIn(schema);
465
+ if (pipeIn === void 0 || intro.kindOf(pipeIn) === "transform") return value;
466
+ return fixNode(pipeIn, value, ctx, lazyDepth);
467
+ }
468
+ case "lazy": {
469
+ if (lazyDepth >= ctx.maxDepth) return value;
470
+ const inner = intro.unwrapLazy(schema);
471
+ return inner === void 0 ? value : fixNode(inner, value, ctx, lazyDepth + 1);
472
+ }
473
+ case "discriminated-union": {
474
+ if (value === null || typeof value !== "object") return value;
475
+ const variant = selectVariantByValue(schema, value, intro);
476
+ if (variant === void 0) return value;
477
+ const record = value;
478
+ const shape = intro.getObjectShape(variant);
479
+ for (const key of Object.keys(record)) {
480
+ if (!(key in shape)) delete record[key];
481
+ }
482
+ for (const [key, sub] of Object.entries(shape)) {
483
+ record[key] = fixNode(sub, record[key], ctx, lazyDepth);
484
+ }
485
+ return value;
486
+ }
487
+ case "object": {
488
+ if (value === null || typeof value !== "object") return value;
489
+ const record = value;
490
+ for (const [key, sub] of Object.entries(intro.getObjectShape(schema))) {
491
+ record[key] = fixNode(sub, record[key], ctx, lazyDepth);
492
+ }
493
+ return value;
494
+ }
495
+ case "array": {
496
+ if (!Array.isArray(value)) return value;
497
+ const element = intro.getArrayElement(schema);
498
+ if (element === void 0) return value;
499
+ for (let i = 0; i < value.length; i++) {
500
+ value[i] = fixNode(element, value[i], ctx, lazyDepth);
501
+ }
502
+ return value;
503
+ }
504
+ case "tuple": {
505
+ if (!Array.isArray(value)) return value;
506
+ const items = intro.getTupleItems(schema);
507
+ for (let i = 0; i < items.length; i++) {
508
+ const item = items[i];
509
+ if (item !== void 0) value[i] = fixNode(item, value[i], ctx, lazyDepth);
510
+ }
511
+ return value;
512
+ }
513
+ case "record": {
514
+ if (value === null || typeof value !== "object") return value;
515
+ const valueType = intro.getRecordValueType(schema);
516
+ if (valueType === void 0) return value;
517
+ const record = value;
518
+ for (const key of Object.keys(record)) {
519
+ record[key] = fixNode(valueType, record[key], ctx, lazyDepth);
520
+ }
521
+ return value;
522
+ }
523
+ case "map": {
524
+ if (!(value instanceof Map)) return value;
525
+ const valueType = intro.getMapValueType(schema);
526
+ if (valueType === void 0) return value;
527
+ for (const [key, entry] of [...value]) {
528
+ value.set(key, fixNode(valueType, entry, ctx, lazyDepth));
529
+ }
530
+ return value;
531
+ }
532
+ case "intersection": {
533
+ const left = intro.getIntersectionLeft(schema);
534
+ const right = intro.getIntersectionRight(schema);
535
+ let out = value;
536
+ if (left !== void 0) out = fixNode(left, out, ctx, lazyDepth);
537
+ if (right !== void 0) out = fixNode(right, out, ctx, lazyDepth);
538
+ return out;
539
+ }
540
+ default:
541
+ return value;
542
+ }
543
+ }
544
+ function deriveFixValue(schema, value, ctx) {
545
+ const du = ctx.services.unwrapToDiscriminatedUnion(schema);
546
+ if (du !== void 0) {
547
+ const selected = selectVariantByValue(du, value, ctx.services.intro) ?? ctx.services.intro.getDiscriminatedOptions(du)[0];
548
+ if (selected !== void 0) {
549
+ return ctx.services.deriveDefault(selected, ctx.useDefault);
550
+ }
551
+ }
552
+ return ctx.services.deriveDefault(schema, ctx.useDefault);
553
+ }
554
+ function selectVariantByValue(du, value, intro) {
555
+ if (value === null || typeof value !== "object") return void 0;
556
+ const discKey = intro.getDiscriminator(du);
557
+ if (discKey === void 0) return void 0;
558
+ const discValue = value[discKey];
559
+ if (discValue === void 0) return void 0;
560
+ for (const opt of intro.getDiscriminatedOptions(du)) {
561
+ const litSchema = intro.getObjectShape(opt)[discKey];
562
+ if (litSchema === void 0 || intro.kindOf(litSchema) !== "literal") continue;
563
+ if (intro.getLiteralValues(litSchema).includes(discValue)) return opt;
564
+ }
565
+ return void 0;
566
+ }
567
+
360
568
  const NO_EMBEDDED_DEFAULT = /* @__PURE__ */ Symbol("atta:no-embedded-default");
361
569
  function peelEmbeddedDefault(schema, intro) {
362
570
  let current = schema;
@@ -539,59 +747,68 @@ function deriveDefaultWalk(schema, useDefault, intro, maxDepth, ctx, lazyDepth =
539
747
  }
540
748
  case "catch": {
541
749
  if (useDefault) return intro.getCatchDefault(schema);
542
- if (ctx.catchOnUseDefaultFalse === "preserveCatch" && intro.hasCatchValue(schema)) {
543
- return intro.getCatchDefault(schema);
544
- }
545
750
  const inner = intro.unwrapInner(schema);
546
751
  return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, ctx, lazyDepth);
547
752
  }
548
753
  case "file":
549
754
  return null;
755
+ case "map":
756
+ return /* @__PURE__ */ new Map();
757
+ case "template-literal":
758
+ return "";
550
759
  case "any":
551
760
  case "unknown":
761
+ case "custom":
552
762
  case "void":
553
763
  case "never":
554
764
  case "promise":
555
- case "custom":
556
- case "template-literal":
557
- case "transform":
558
- case "map":
559
765
  case "symbol":
560
766
  case "function":
767
+ case "transform":
561
768
  return void 0;
562
769
  default:
563
770
  return ctx.unsupportedKindFallback(schema, kind);
564
771
  }
565
772
  }
566
773
 
567
- const store = /* @__PURE__ */ new WeakMap();
568
- const lists = /* @__PURE__ */ new WeakMap();
774
+ const state = crossCopyState(/* @__PURE__ */ Symbol.for("attaform:field-meta-state"), () => ({
775
+ store: /* @__PURE__ */ new WeakMap(),
776
+ lists: /* @__PURE__ */ new WeakMap(),
777
+ pathMapBuilder: null
778
+ }));
569
779
  const registry = {
570
780
  add(schema, payload) {
571
- store.set(schema, payload);
572
- const list = lists.get(schema) ?? [];
781
+ state.store.set(schema, payload);
782
+ const list = state.lists.get(schema) ?? [];
573
783
  list.push(payload);
574
- lists.set(schema, list);
784
+ state.lists.set(schema, list);
575
785
  return registry;
576
786
  },
577
787
  get(schema) {
578
- return store.get(schema);
788
+ return state.store.get(schema);
579
789
  },
580
790
  has(schema) {
581
- return store.has(schema);
791
+ return state.store.has(schema);
582
792
  },
583
793
  remove(schema) {
584
- store.delete(schema);
585
- lists.delete(schema);
794
+ state.store.delete(schema);
795
+ state.lists.delete(schema);
586
796
  return registry;
587
797
  }
588
798
  };
589
799
  const fieldMetaStore = registry;
590
800
  function getFieldMetaForSchema(schema) {
591
- return store.get(schema);
801
+ return state.store.get(schema);
592
802
  }
593
803
  function getFieldMetaListForSchema(schema) {
594
- return lists.get(schema) ?? [];
804
+ return state.lists.get(schema) ?? [];
805
+ }
806
+ function installFieldMetaPathMapBuilder(builder) {
807
+ state.pathMapBuilder = builder;
808
+ }
809
+ function buildFieldMetaPathMap(rootSchema, services) {
810
+ const builder = state.pathMapBuilder;
811
+ return builder === null ? void 0 : builder(rootSchema, services);
595
812
  }
596
813
 
597
814
  const PERMISSIVE_SLIM_KINDS = /* @__PURE__ */ new Set([
@@ -620,6 +837,16 @@ const KIND_UNDEFINED = /* @__PURE__ */ new Set(["undefined"]);
620
837
  const KIND_OBJECT = /* @__PURE__ */ new Set(["object"]);
621
838
  const KIND_ARRAY = /* @__PURE__ */ new Set(["array"]);
622
839
  const KIND_SET = /* @__PURE__ */ new Set(["set"]);
840
+ const KIND_MAP = /* @__PURE__ */ new Set(["map"]);
841
+ const KIND_SYMBOL = /* @__PURE__ */ new Set(["symbol", "undefined"]);
842
+ const KIND_FUNCTION = /* @__PURE__ */ new Set([
843
+ "function",
844
+ "undefined"
845
+ ]);
846
+ const KIND_PROMISE = /* @__PURE__ */ new Set([
847
+ "object",
848
+ "undefined"
849
+ ]);
623
850
  const KIND_FILE = /* @__PURE__ */ new Set(["file", "null"]);
624
851
  const EMPTY_KINDS = /* @__PURE__ */ new Set();
625
852
  function slimPrimitivesWalk(schema, intro, maxDepth, lazyDepth = 0) {
@@ -676,6 +903,16 @@ function slimPrimitivesWalk(schema, intro, maxDepth, lazyDepth = 0) {
676
903
  return KIND_ARRAY;
677
904
  case "set":
678
905
  return KIND_SET;
906
+ case "map":
907
+ return KIND_MAP;
908
+ case "symbol":
909
+ return KIND_SYMBOL;
910
+ case "function":
911
+ return KIND_FUNCTION;
912
+ case "promise":
913
+ return KIND_PROMISE;
914
+ case "template-literal":
915
+ return KIND_STRING;
679
916
  case "optional": {
680
917
  const inner = intro.unwrapInner(schema);
681
918
  const innerSet = inner === void 0 ? EMPTY_KINDS : slimPrimitivesWalk(inner, intro, maxDepth, lazyDepth);
@@ -739,19 +976,37 @@ function slimPrimitivesWalk(schema, intro, maxDepth, lazyDepth = 0) {
739
976
  }
740
977
  case "never":
741
978
  return EMPTY_KINDS;
979
+ // Opaque leaves: the schema says nothing about the value's shape,
980
+ // so every kind is admissible. `custom` is the kind
981
+ // `z.instanceof(X)` and `z.custom<T>()` compile to on v4 (#542);
982
+ // it belongs with `any` / `unknown` rather than in the defensive
983
+ // fallthrough, because it reaches here through the public surface.
742
984
  case "any":
743
985
  case "unknown":
986
+ case "custom":
744
987
  return PERMISSIVE_SLIM_KINDS;
745
- // Opaque / unsupported kinds: be permissive so legitimate writes
746
- // aren't false-rejected. The unsupported kinds (`map` / `symbol` /
747
- // `function` / `promise`) are rejected at adapter construction by
748
- // `assertSupportedKinds`; this fallthrough keeps the walker
749
- // defensive in case construction is skipped.
988
+ // A kind this walker has no case for — in practice a kind a newer
989
+ // Zod introduced. Be permissive rather than reject: the adapter
990
+ // carries the value opaquely and the schema's own parse is what
991
+ // decides whether it was legal.
750
992
  default:
751
993
  return PERMISSIVE_SLIM_KINDS;
752
994
  }
753
995
  }
754
996
 
997
+ const installingFieldMetaStore = {
998
+ add(schema, payload) {
999
+ installFieldMetaPathMapBuilder(getFieldMetaPathMap);
1000
+ fieldMetaStore.add(schema, payload);
1001
+ return installingFieldMetaStore;
1002
+ },
1003
+ get: (schema) => fieldMetaStore.get(schema),
1004
+ has: (schema) => fieldMetaStore.has(schema),
1005
+ remove: (schema) => {
1006
+ fieldMetaStore.remove(schema);
1007
+ return installingFieldMetaStore;
1008
+ }
1009
+ };
755
1010
  const pathMetaCache = /* @__PURE__ */ new WeakMap();
756
1011
  function getFieldMetaPathMap(rootSchema, services) {
757
1012
  const cached = pathMetaCache.get(rootSchema);
@@ -827,11 +1082,20 @@ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress,
827
1082
  case "set": {
828
1083
  const inner = intro.getSetValueType(schema);
829
1084
  if (inner !== void 0)
830
- walkForMeta(inner, [...path, 0], map, counters, lastPathPerSchema, inProgress, services);
1085
+ walkForMeta(
1086
+ inner,
1087
+ [...path, SET_MEMBER_SEGMENT],
1088
+ map,
1089
+ counters,
1090
+ lastPathPerSchema,
1091
+ inProgress,
1092
+ services
1093
+ );
831
1094
  return;
832
1095
  }
833
- case "record": {
834
- const inner = intro.getRecordValueType(schema);
1096
+ case "record":
1097
+ case "map": {
1098
+ const inner = kind === "map" ? intro.getMapValueType(schema) : intro.getRecordValueType(schema);
835
1099
  if (inner !== void 0)
836
1100
  walkForMeta(inner, [...path, "*"], map, counters, lastPathPerSchema, inProgress, services);
837
1101
  return;
@@ -903,5 +1167,4 @@ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress,
903
1167
  }
904
1168
  }
905
1169
 
906
- export { NO_EMBEDDED_DEFAULT as N, getFieldMetaListForSchema as a, getFieldMetaPathMap as b, createAbstractSchema as c, deriveDefaultWalk as d, fieldMetaStore as f, getFieldMetaForSchema as g, mergeDeep as m, peelEmbeddedDefault as p, slimPrimitivesWalk as s, walkPathSegments as w };
907
- //# sourceMappingURL=attaform.CoR4mWfv.mjs.map
1170
+ export { getFieldMetaListForSchema as a, buildFieldMetaPathMap as b, createAbstractSchema as c, deriveDefaultWalk as d, fixStructuralDefaults as f, getFieldMetaForSchema as g, installingFieldMetaStore as i, mergeDeep as m, slimPrimitivesWalk as s, walkPathSegments as w };