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,16 +1,54 @@
1
- import { A as AttaformErrorCode, n as isPlainRecord, s as slimKindOf } from './attaform.B8k8JrmK.mjs';
2
- import { e as canonicalizePath } from './attaform.wfY8XFvm.mjs';
3
- import { a as safeOwnRead, b as safeAssign } from './attaform.h0i6LijT.mjs';
1
+ import { A as AttaformErrorCode, k as isPlainRecord, s as slimKindOf } from './attaform.DNJOWjQw.mjs';
2
+ import { e as canonicalizePath, h as SET_MEMBER_SEGMENT } from './attaform.CdZIEf7_.mjs';
3
+ import { a as safeOwnRead, b as safeAssign } from './attaform.BRDDQeHV.mjs';
4
4
 
5
5
  const PATH_SEPARATOR = ".";
6
- function createAbstractSchema(rootSchema, intro, services, formKey, options) {
6
+ function isOpaqueKind(kind) {
7
+ return kind === "any" || kind === "unknown" || kind === "custom";
8
+ }
9
+ const MEMO_CAP = 4096;
10
+ const ROOT_KINDS = /* @__PURE__ */ new Set(["object"]);
11
+ const NO_KINDS = /* @__PURE__ */ new Set();
12
+ function memoPut(memo, key, value) {
13
+ if (memo.size >= MEMO_CAP) memo.clear();
14
+ memo.set(key, value);
15
+ return value;
16
+ }
17
+ function createSharedSchemaStore() {
18
+ const bySchema = /* @__PURE__ */ new WeakMap();
19
+ return (rootSchema, maxRecursionDepth, build) => {
20
+ let byDepth = bySchema.get(rootSchema);
21
+ if (byDepth === void 0) {
22
+ byDepth = /* @__PURE__ */ new Map();
23
+ bySchema.set(rootSchema, byDepth);
24
+ }
25
+ const hit = byDepth.get(maxRecursionDepth);
26
+ if (hit !== void 0) return hit;
27
+ const built = build();
28
+ byDepth.set(maxRecursionDepth, built);
29
+ return built;
30
+ };
31
+ }
32
+ function createAbstractSchema(rootSchema, intro, services, options) {
7
33
  const maxRecursionDepth = options.maxRecursionDepth;
8
34
  const leafCache = /* @__PURE__ */ new Map();
9
35
  const preprocessOrCoerceCache = /* @__PURE__ */ new Map();
36
+ const opaqueLeafCache = /* @__PURE__ */ new Map();
10
37
  const discriminatorCache = /* @__PURE__ */ new Map();
38
+ const entryKeyKindCache = /* @__PURE__ */ new Map();
39
+ const slimKindsCache = /* @__PURE__ */ new Map();
11
40
  let asyncValidationFlag = null;
12
41
  let containerRefineFlag = null;
13
42
  let discriminatedUnionFlag = null;
43
+ function mapKeySegmentKind(schema) {
44
+ const keyType = intro.getMapKeyType(schema);
45
+ if (keyType === void 0) return void 0;
46
+ const kinds = services.slimPrimitivesOf(keyType, maxRecursionDepth);
47
+ const string = kinds.has("string");
48
+ const number = kinds.has("number");
49
+ if (string === number) return void 0;
50
+ return string ? "string" : "number";
51
+ }
14
52
  function computeDiscriminator(path) {
15
53
  const candidates = path.length === 0 ? [rootSchema] : services.getNestedSchemasAtPath(rootSchema, path, maxRecursionDepth);
16
54
  let matchedUnion;
@@ -42,7 +80,7 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
42
80
  if (intro.kindOf(litSchema) !== "literal") continue;
43
81
  const literalValues = intro.getLiteralValues(litSchema);
44
82
  if (literalValues.includes(value)) {
45
- return services.deriveDefault(opt, true, maxRecursionDepth, formKey);
83
+ return services.deriveDefault(opt, true, maxRecursionDepth);
46
84
  }
47
85
  }
48
86
  return void 0;
@@ -53,7 +91,6 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
53
91
  };
54
92
  }
55
93
  const abstractSchema = {
56
- fingerprint: () => services.fingerprint(rootSchema),
57
94
  needsAsyncValidation() {
58
95
  asyncValidationFlag ?? (asyncValidationFlag = intro.containsAsyncRefine(rootSchema) || intro.containsAsyncTransform(rootSchema));
59
96
  return asyncValidationFlag;
@@ -67,24 +104,24 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
67
104
  return discriminatedUnionFlag;
68
105
  },
69
106
  getDefaultValues(config) {
70
- return services.runStrictGetDefaults(rootSchema, config, formKey, maxRecursionDepth);
107
+ return services.runGetDefaults(rootSchema, config, maxRecursionDepth);
71
108
  },
72
109
  getDefaultAtPath(path) {
73
110
  if (path.length === 0) {
74
- return services.deriveDefault(rootSchema, true, maxRecursionDepth, formKey);
111
+ return services.deriveDefault(rootSchema, true, maxRecursionDepth);
75
112
  }
76
113
  const [first] = services.getNestedSchemasAtPath(rootSchema, path, maxRecursionDepth);
77
114
  if (first === void 0) return void 0;
78
115
  const peeled = services.unwrapStructuralWrappers(first);
79
- return services.deriveDefault(peeled, true, maxRecursionDepth, formKey);
116
+ return services.deriveDefault(peeled, true, maxRecursionDepth);
80
117
  },
81
118
  getEmptyValueAtPath(path) {
82
119
  if (path.length === 0) {
83
- return services.deriveDefault(rootSchema, false, maxRecursionDepth, formKey);
120
+ return services.deriveDefault(rootSchema, false, maxRecursionDepth);
84
121
  }
85
122
  const [first] = services.getNestedSchemasAtPath(rootSchema, path, maxRecursionDepth);
86
123
  if (first === void 0) return void 0;
87
- return services.deriveDefault(first, false, maxRecursionDepth, formKey);
124
+ return services.deriveDefault(first, false, maxRecursionDepth);
88
125
  },
89
126
  arrayShapeAtPath(path) {
90
127
  if (path.length === 0) return null;
@@ -102,31 +139,59 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
102
139
  if (resolved.length === 0) return false;
103
140
  return resolved.every((s) => intro.kindOf(services.peelAllWrappers(s)) === "object");
104
141
  },
142
+ entryKeyKindAtPath(path) {
143
+ const cacheKey = canonicalizePath(path).key;
144
+ if (entryKeyKindCache.has(cacheKey)) return entryKeyKindCache.get(cacheKey);
145
+ const resolved = path.length === 0 ? [rootSchema] : services.getNestedSchemasAtPath(rootSchema, path, maxRecursionDepth);
146
+ let answer;
147
+ const only = resolved.length === 1 ? resolved[0] : void 0;
148
+ if (only !== void 0) {
149
+ switch (intro.kindOf(services.peelAllWrappers(only))) {
150
+ case "array":
151
+ case "tuple":
152
+ answer = "number";
153
+ break;
154
+ case "object":
155
+ case "record":
156
+ answer = "string";
157
+ break;
158
+ case "map":
159
+ answer = mapKeySegmentKind(services.peelAllWrappers(only));
160
+ break;
161
+ default:
162
+ answer = void 0;
163
+ }
164
+ }
165
+ return memoPut(entryKeyKindCache, cacheKey, answer);
166
+ },
105
167
  getSchemasAtPath(path) {
106
168
  const resolved = services.getNestedSchemasInSlimMode(rootSchema, path, maxRecursionDepth);
107
169
  if (resolved.length === 0) return [];
108
- return resolved.map((sub) => services.makeSubSchema(sub, formKey, maxRecursionDepth));
170
+ return resolved.map((sub) => services.makeSubSchema(sub, maxRecursionDepth));
109
171
  },
110
172
  getSlimPrimitiveTypesAtPath(path) {
111
- if (path.length === 0) return /* @__PURE__ */ new Set(["object"]);
173
+ if (path.length === 0) return ROOT_KINDS;
174
+ const cacheKey = canonicalizePath(path).key;
175
+ const hit = slimKindsCache.get(cacheKey);
176
+ if (hit !== void 0) return hit;
112
177
  const resolved = services.getNestedSchemasInSlimMode(rootSchema, path, maxRecursionDepth);
113
- if (resolved.length === 0) return /* @__PURE__ */ new Set();
178
+ if (resolved.length === 0) return memoPut(slimKindsCache, cacheKey, NO_KINDS);
114
179
  const out = /* @__PURE__ */ new Set();
115
180
  for (const candidate of resolved) {
116
181
  for (const k of services.slimPrimitivesOf(candidate, maxRecursionDepth)) {
117
182
  out.add(k);
118
183
  }
119
184
  }
120
- return out;
185
+ return memoPut(slimKindsCache, cacheKey, out);
121
186
  },
122
187
  isLeafAtPath(path) {
123
188
  const cacheKey = canonicalizePath(path).key;
124
189
  const cached = leafCache.get(cacheKey);
125
190
  if (cached !== void 0) return cached;
126
- const prim = this.getSlimPrimitiveTypesAtPath(path);
127
- const isLeaf = prim.size > 0 && !prim.has("object") && !prim.has("array") && !prim.has("map") && !prim.has("set");
128
- leafCache.set(cacheKey, isLeaf);
129
- return isLeaf;
191
+ const opaque = path.length > 0 && this.isOpaqueLeafAtPath(path);
192
+ const prim = opaque ? void 0 : this.getSlimPrimitiveTypesAtPath(path);
193
+ const isLeaf = opaque || prim !== void 0 && prim.size > 0 && !prim.has("object") && !prim.has("array") && !prim.has("map") && !prim.has("set");
194
+ return memoPut(leafCache, cacheKey, isLeaf);
130
195
  },
131
196
  isPreprocessOrCoerceLeaf(path) {
132
197
  const cacheKey = canonicalizePath(path).key;
@@ -143,8 +208,17 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
143
208
  }
144
209
  }
145
210
  }
146
- preprocessOrCoerceCache.set(cacheKey, hit);
147
- return hit;
211
+ return memoPut(preprocessOrCoerceCache, cacheKey, hit);
212
+ },
213
+ isOpaqueLeafAtPath(path) {
214
+ const cacheKey = canonicalizePath(path).key;
215
+ const cached = opaqueLeafCache.get(cacheKey);
216
+ if (cached !== void 0) return cached;
217
+ const resolved = path.length === 0 ? [rootSchema] : services.getNestedSchemasAtPath(rootSchema, path, maxRecursionDepth);
218
+ const opaque = resolved.length > 0 && resolved.every(
219
+ (candidate) => isOpaqueKind(intro.kindOf(services.peelAllWrappers(candidate)))
220
+ );
221
+ return memoPut(opaqueLeafCache, cacheKey, opaque);
148
222
  },
149
223
  isRequiredAtPath(path) {
150
224
  if (path.length === 0) return true;
@@ -160,9 +234,7 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
160
234
  if (discriminatorCache.has(cacheKey)) {
161
235
  return discriminatorCache.get(cacheKey);
162
236
  }
163
- const result = computeDiscriminator(path);
164
- discriminatorCache.set(cacheKey, result);
165
- return result;
237
+ return memoPut(discriminatorCache, cacheKey, computeDiscriminator(path));
166
238
  },
167
239
  validateAtPath(data, path, validateOptions) {
168
240
  const trySync = validateOptions?.sync === true;
@@ -174,11 +246,10 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
174
246
  }
175
247
  return runAsync();
176
248
  function parseResultToResponse(result) {
177
- return result.success ? { data: result.data, errors: void 0, success: true, formKey } : {
249
+ return result.success ? { data: result.data, errors: void 0, success: true } : {
178
250
  data: void 0,
179
251
  errors: services.issuesToValidationErrors(result.issues),
180
- success: false,
181
- formKey
252
+ success: false
182
253
  };
183
254
  }
184
255
  function runSync() {
@@ -193,7 +264,7 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
193
264
  if (response.success) return response;
194
265
  aggregated.push(...response.errors);
195
266
  }
196
- return { data: void 0, errors: aggregated, success: false, formKey };
267
+ return { data: void 0, errors: aggregated, success: false };
197
268
  }
198
269
  async function runAsync() {
199
270
  if (path === void 0) {
@@ -219,7 +290,7 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
219
290
  if (response.success) return response;
220
291
  aggregated.push(...response.errors);
221
292
  }
222
- return { data: void 0, errors: aggregated, success: false, formKey };
293
+ return { data: void 0, errors: aggregated, success: false };
223
294
  }
224
295
  function validatorThrewResponse(err, errPath) {
225
296
  const message = err instanceof Error ? err.message : typeof err === "string" ? err : "Validator threw";
@@ -232,8 +303,7 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
232
303
  code: AttaformErrorCode.ValidatorThrew
233
304
  }
234
305
  ],
235
- success: false,
236
- formKey
306
+ success: false
237
307
  };
238
308
  }
239
309
  function pathNotFound(p) {
@@ -246,8 +316,7 @@ function createAbstractSchema(rootSchema, intro, services, formKey, options) {
246
316
  code: AttaformErrorCode.PathNotFound
247
317
  }
248
318
  ],
249
- success: false,
250
- formKey
319
+ success: false
251
320
  };
252
321
  }
253
322
  }
@@ -289,6 +358,7 @@ function walkPathSegments(schema, segments, intro, maxDepth, lazyDepth) {
289
358
  return inner === void 0 ? [] : walkPathSegments(inner, rest, intro, maxDepth, lazyDepth);
290
359
  }
291
360
  case "set": {
361
+ if (head !== SET_MEMBER_SEGMENT) return [];
292
362
  const inner = intro.getSetValueType(schema);
293
363
  return inner === void 0 ? [] : walkPathSegments(inner, rest, intro, maxDepth, lazyDepth);
294
364
  }
@@ -296,6 +366,10 @@ function walkPathSegments(schema, segments, intro, maxDepth, lazyDepth) {
296
366
  const inner = intro.getRecordValueType(schema);
297
367
  return inner === void 0 ? [] : walkPathSegments(inner, rest, intro, maxDepth, lazyDepth);
298
368
  }
369
+ case "map": {
370
+ const inner = intro.getMapValueType(schema);
371
+ return inner === void 0 ? [] : walkPathSegments(inner, rest, intro, maxDepth, lazyDepth);
372
+ }
299
373
  case "tuple": {
300
374
  const index = Number(head);
301
375
  if (!Number.isInteger(index)) return [];
@@ -316,6 +390,8 @@ function walkPathSegments(schema, segments, intro, maxDepth, lazyDepth) {
316
390
  case "optional":
317
391
  case "nullable":
318
392
  case "default":
393
+ case "nonoptional":
394
+ case "success":
319
395
  case "readonly":
320
396
  case "catch": {
321
397
  const inner = intro.unwrapInner(schema);
@@ -349,11 +425,13 @@ function walkPathSegments(schema, segments, intro, maxDepth, lazyDepth) {
349
425
  const rightResults = right === void 0 ? [] : walkPathSegments(right, segments, intro, maxDepth, lazyDepth);
350
426
  return [...leftResults, ...rightResults];
351
427
  }
352
- // Leaves — can't descend further. The unsupported kinds (`map` /
353
- // `symbol` / `function` / `promise`) are rejected at adapter
354
- // construction by `assertSupportedKinds`; falling through to `[]`
355
- // keeps the walker defensive in case construction is skipped
356
- // (e.g. a downstream test instantiates a sub-schema directly).
428
+ // Leaves — can't descend further. Opaque leaves (`any` /
429
+ // `unknown` / `custom`) land here too and `[]` is the truthful
430
+ // answer: the schema declares no sub-paths under them, so none are
431
+ // fabricated. `symbol` / `function` / `promise` hold a value
432
+ // without declaring anything inside it and land here for the same
433
+ // reason. No kind is refused at construction (#607), so this is
434
+ // the only branch they ever take.
357
435
  default:
358
436
  return [];
359
437
  }
@@ -387,6 +465,8 @@ function fixNode(schema, value, ctx, lazyDepth) {
387
465
  return inner === void 0 ? value : fixNode(inner, value, ctx, lazyDepth);
388
466
  }
389
467
  case "default":
468
+ case "nonoptional":
469
+ case "success":
390
470
  case "readonly":
391
471
  case "catch": {
392
472
  const inner = intro.unwrapInner(schema);
@@ -461,6 +541,15 @@ function fixNode(schema, value, ctx, lazyDepth) {
461
541
  }
462
542
  return value;
463
543
  }
544
+ case "map": {
545
+ if (!(value instanceof Map)) return value;
546
+ const valueType = intro.getMapValueType(schema);
547
+ if (valueType === void 0) return value;
548
+ for (const [key, entry] of [...value]) {
549
+ value.set(key, fixNode(valueType, entry, ctx, lazyDepth));
550
+ }
551
+ return value;
552
+ }
464
553
  case "intersection": {
465
554
  const left = intro.getIntersectionLeft(schema);
466
555
  const right = intro.getIntersectionRight(schema);
@@ -543,7 +632,7 @@ function hasDeclaredDefaultInChain(schema, intro) {
543
632
  }
544
633
  return false;
545
634
  }
546
- function deriveDefaultWalk(schema, useDefault, intro, maxDepth, ctx, lazyDepth = 0) {
635
+ function deriveDefaultWalk(schema, useDefault, intro, maxDepth, lazyDepth = 0) {
547
636
  if (useDefault) {
548
637
  const peeled = peelEmbeddedDefault(schema, intro);
549
638
  if (peeled !== NO_EMBEDDED_DEFAULT) return peeled;
@@ -555,11 +644,7 @@ function deriveDefaultWalk(schema, useDefault, intro, maxDepth, ctx, lazyDepth =
555
644
  const shape = intro.getObjectShape(schema);
556
645
  const out = {};
557
646
  for (const [key, subSchema] of Object.entries(shape)) {
558
- safeAssign(
559
- out,
560
- key,
561
- deriveDefaultWalk(subSchema, useDefault, intro, maxDepth, ctx, lazyDepth)
562
- );
647
+ safeAssign(out, key, deriveDefaultWalk(subSchema, useDefault, intro, maxDepth, lazyDepth));
563
648
  }
564
649
  return out;
565
650
  }
@@ -571,19 +656,17 @@ function deriveDefaultWalk(schema, useDefault, intro, maxDepth, ctx, lazyDepth =
571
656
  return {};
572
657
  case "tuple": {
573
658
  const items = intro.getTupleItems(schema);
574
- return items.map(
575
- (item) => deriveDefaultWalk(item, useDefault, intro, maxDepth, ctx, lazyDepth)
576
- );
659
+ return items.map((item) => deriveDefaultWalk(item, useDefault, intro, maxDepth, lazyDepth));
577
660
  }
578
661
  case "union": {
579
662
  const options = intro.getUnionOptions(schema);
580
663
  const first = options[0];
581
- return first === void 0 ? void 0 : deriveDefaultWalk(first, useDefault, intro, maxDepth, ctx, lazyDepth);
664
+ return first === void 0 ? void 0 : deriveDefaultWalk(first, useDefault, intro, maxDepth, lazyDepth);
582
665
  }
583
666
  case "discriminated-union": {
584
667
  const options = intro.getDiscriminatedOptions(schema);
585
668
  const first = options[0];
586
- return first === void 0 ? void 0 : deriveDefaultWalk(first, useDefault, intro, maxDepth, ctx, lazyDepth);
669
+ return first === void 0 ? void 0 : deriveDefaultWalk(first, useDefault, intro, maxDepth, lazyDepth);
587
670
  }
588
671
  case "optional":
589
672
  return void 0;
@@ -592,39 +675,41 @@ function deriveDefaultWalk(schema, useDefault, intro, maxDepth, ctx, lazyDepth =
592
675
  case "default": {
593
676
  if (useDefault) return intro.getDefaultValue(schema);
594
677
  const inner = intro.unwrapInner(schema);
595
- return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, ctx, lazyDepth);
678
+ return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, lazyDepth);
596
679
  }
680
+ case "nonoptional":
681
+ case "success":
597
682
  case "readonly":
598
683
  case "branded": {
599
684
  const inner = kind === "branded" ? intro.unwrapBranded(schema) : intro.unwrapInner(schema);
600
- return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, ctx, lazyDepth);
685
+ return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, lazyDepth);
601
686
  }
602
687
  case "effects": {
603
688
  const inner = intro.unwrapEffectsSource(schema);
604
689
  if (intro.isPreprocessNode(schema)) {
605
690
  if (inner !== void 0 && hasDeclaredDefaultInChain(inner, intro)) {
606
- return deriveDefaultWalk(inner, useDefault, intro, maxDepth, ctx, lazyDepth);
691
+ return deriveDefaultWalk(inner, useDefault, intro, maxDepth, lazyDepth);
607
692
  }
608
693
  return void 0;
609
694
  }
610
- return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, ctx, lazyDepth);
695
+ return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, lazyDepth);
611
696
  }
612
697
  case "pipeline": {
613
698
  const inner = intro.unwrapPipeIn(schema);
614
- return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, ctx, lazyDepth);
699
+ return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, lazyDepth);
615
700
  }
616
701
  case "pipe": {
617
702
  const inn = intro.unwrapPipeIn(schema);
618
703
  if (inn !== void 0 && intro.kindOf(inn) === "transform") {
619
704
  const out2 = intro.unwrapPipeOut(schema);
620
705
  if (out2 !== void 0 && hasDeclaredDefaultInChain(out2, intro)) {
621
- return deriveDefaultWalk(out2, useDefault, intro, maxDepth, ctx, lazyDepth);
706
+ return deriveDefaultWalk(out2, useDefault, intro, maxDepth, lazyDepth);
622
707
  }
623
708
  return void 0;
624
709
  }
625
710
  const out = intro.unwrapPipeOut(schema);
626
711
  const real = inn !== void 0 && intro.kindOf(inn) !== "transform" ? inn : out !== void 0 && intro.kindOf(out) !== "transform" ? out : inn ?? out;
627
- return real === void 0 ? void 0 : deriveDefaultWalk(real, useDefault, intro, maxDepth, ctx, lazyDepth);
712
+ return real === void 0 ? void 0 : deriveDefaultWalk(real, useDefault, intro, maxDepth, lazyDepth);
628
713
  }
629
714
  case "string":
630
715
  return "";
@@ -668,74 +753,84 @@ function deriveDefaultWalk(schema, useDefault, intro, maxDepth, ctx, lazyDepth =
668
753
  } catch {
669
754
  return void 0;
670
755
  }
671
- return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, ctx, lazyDepth + 1);
756
+ return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, lazyDepth + 1);
672
757
  }
673
758
  case "intersection": {
674
759
  const left = intro.getIntersectionLeft(schema);
675
760
  const right = intro.getIntersectionRight(schema);
676
- const l = left === void 0 ? void 0 : deriveDefaultWalk(left, useDefault, intro, maxDepth, ctx, lazyDepth);
677
- const r = right === void 0 ? void 0 : deriveDefaultWalk(right, useDefault, intro, maxDepth, ctx, lazyDepth);
761
+ const l = left === void 0 ? void 0 : deriveDefaultWalk(left, useDefault, intro, maxDepth, lazyDepth);
762
+ const r = right === void 0 ? void 0 : deriveDefaultWalk(right, useDefault, intro, maxDepth, lazyDepth);
678
763
  return mergeDeep(l, r);
679
764
  }
680
765
  case "catch": {
681
766
  if (useDefault) return intro.getCatchDefault(schema);
682
767
  const inner = intro.unwrapInner(schema);
683
- return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, ctx, lazyDepth);
768
+ return inner === void 0 ? void 0 : deriveDefaultWalk(inner, useDefault, intro, maxDepth, lazyDepth);
684
769
  }
685
770
  case "file":
686
771
  return null;
772
+ case "map":
773
+ return /* @__PURE__ */ new Map();
774
+ case "template-literal":
775
+ return "";
687
776
  case "any":
688
777
  case "unknown":
778
+ case "custom":
689
779
  case "void":
690
780
  case "never":
691
781
  case "promise":
692
- case "custom":
693
- case "template-literal":
694
- case "transform":
695
- case "map":
696
782
  case "symbol":
697
783
  case "function":
784
+ case "transform":
698
785
  return void 0;
699
786
  default:
700
- return ctx.unsupportedKindFallback(schema, kind);
787
+ return void 0;
701
788
  }
702
789
  }
703
790
 
704
- const store = /* @__PURE__ */ new WeakMap();
705
- const lists = /* @__PURE__ */ new WeakMap();
791
+ function crossCopyState(key, create) {
792
+ const carrier = globalThis;
793
+ return carrier[key] ?? (carrier[key] = create());
794
+ }
795
+
796
+ const state = crossCopyState(/* @__PURE__ */ Symbol.for("attaform:field-meta-state"), () => ({
797
+ store: /* @__PURE__ */ new WeakMap(),
798
+ lists: /* @__PURE__ */ new WeakMap(),
799
+ pathMapBuilder: null
800
+ }));
706
801
  const registry = {
707
802
  add(schema, payload) {
708
- store.set(schema, payload);
709
- const list = lists.get(schema) ?? [];
803
+ state.store.set(schema, payload);
804
+ const list = state.lists.get(schema) ?? [];
710
805
  list.push(payload);
711
- lists.set(schema, list);
806
+ state.lists.set(schema, list);
712
807
  return registry;
713
808
  },
714
809
  get(schema) {
715
- return store.get(schema);
810
+ return state.store.get(schema);
716
811
  },
717
812
  has(schema) {
718
- return store.has(schema);
813
+ return state.store.has(schema);
719
814
  },
720
815
  remove(schema) {
721
- store.delete(schema);
722
- lists.delete(schema);
816
+ state.store.delete(schema);
817
+ state.lists.delete(schema);
723
818
  return registry;
724
819
  }
725
820
  };
726
821
  const fieldMetaStore = registry;
727
822
  function getFieldMetaForSchema(schema) {
728
- return store.get(schema);
823
+ return state.store.get(schema);
729
824
  }
730
825
  function getFieldMetaListForSchema(schema) {
731
- return lists.get(schema) ?? [];
826
+ return state.lists.get(schema) ?? [];
732
827
  }
733
- let pathMapBuilder = null;
734
828
  function installFieldMetaPathMapBuilder(builder) {
735
- pathMapBuilder = builder;
829
+ state.pathMapBuilder = builder;
736
830
  }
737
831
  function buildFieldMetaPathMap(rootSchema, services) {
738
- return pathMapBuilder === null ? void 0 : pathMapBuilder(rootSchema, services);
832
+ const builder = state.pathMapBuilder;
833
+ return builder === null ? void 0 : builder(rootSchema, services);
739
834
  }
740
835
 
741
836
  const PERMISSIVE_SLIM_KINDS = /* @__PURE__ */ new Set([
@@ -764,6 +859,16 @@ const KIND_UNDEFINED = /* @__PURE__ */ new Set(["undefined"]);
764
859
  const KIND_OBJECT = /* @__PURE__ */ new Set(["object"]);
765
860
  const KIND_ARRAY = /* @__PURE__ */ new Set(["array"]);
766
861
  const KIND_SET = /* @__PURE__ */ new Set(["set"]);
862
+ const KIND_MAP = /* @__PURE__ */ new Set(["map"]);
863
+ const KIND_SYMBOL = /* @__PURE__ */ new Set(["symbol", "undefined"]);
864
+ const KIND_FUNCTION = /* @__PURE__ */ new Set([
865
+ "function",
866
+ "undefined"
867
+ ]);
868
+ const KIND_PROMISE = /* @__PURE__ */ new Set([
869
+ "object",
870
+ "undefined"
871
+ ]);
767
872
  const KIND_FILE = /* @__PURE__ */ new Set(["file", "null"]);
768
873
  const EMPTY_KINDS = /* @__PURE__ */ new Set();
769
874
  function slimPrimitivesWalk(schema, intro, maxDepth, lazyDepth = 0) {
@@ -820,6 +925,16 @@ function slimPrimitivesWalk(schema, intro, maxDepth, lazyDepth = 0) {
820
925
  return KIND_ARRAY;
821
926
  case "set":
822
927
  return KIND_SET;
928
+ case "map":
929
+ return KIND_MAP;
930
+ case "symbol":
931
+ return KIND_SYMBOL;
932
+ case "function":
933
+ return KIND_FUNCTION;
934
+ case "promise":
935
+ return KIND_PROMISE;
936
+ case "template-literal":
937
+ return KIND_STRING;
823
938
  case "optional": {
824
939
  const inner = intro.unwrapInner(schema);
825
940
  const innerSet = inner === void 0 ? EMPTY_KINDS : slimPrimitivesWalk(inner, intro, maxDepth, lazyDepth);
@@ -836,10 +951,20 @@ function slimPrimitivesWalk(schema, intro, maxDepth, lazyDepth = 0) {
836
951
  }
837
952
  case "default":
838
953
  case "readonly":
954
+ case "success":
839
955
  case "catch": {
840
956
  const inner = intro.unwrapInner(schema);
841
957
  return inner === void 0 ? PERMISSIVE_SLIM_KINDS : slimPrimitivesWalk(inner, intro, maxDepth, lazyDepth);
842
958
  }
959
+ case "nonoptional": {
960
+ const inner = intro.unwrapInner(schema);
961
+ if (inner === void 0) return PERMISSIVE_SLIM_KINDS;
962
+ const innerSet = slimPrimitivesWalk(inner, intro, maxDepth, lazyDepth);
963
+ if (!innerSet.has("undefined")) return innerSet;
964
+ const out = new Set(innerSet);
965
+ out.delete("undefined");
966
+ return out;
967
+ }
843
968
  case "branded": {
844
969
  const inner = intro.unwrapBranded(schema);
845
970
  return inner === void 0 ? PERMISSIVE_SLIM_KINDS : slimPrimitivesWalk(inner, intro, maxDepth, lazyDepth);
@@ -883,14 +1008,19 @@ function slimPrimitivesWalk(schema, intro, maxDepth, lazyDepth = 0) {
883
1008
  }
884
1009
  case "never":
885
1010
  return EMPTY_KINDS;
1011
+ // Opaque leaves: the schema says nothing about the value's shape,
1012
+ // so every kind is admissible. `custom` is the kind
1013
+ // `z.instanceof(X)` and `z.custom<T>()` compile to on v4 (#542);
1014
+ // it belongs with `any` / `unknown` rather than in the defensive
1015
+ // fallthrough, because it reaches here through the public surface.
886
1016
  case "any":
887
1017
  case "unknown":
1018
+ case "custom":
888
1019
  return PERMISSIVE_SLIM_KINDS;
889
- // Opaque / unsupported kinds: be permissive so legitimate writes
890
- // aren't false-rejected. The unsupported kinds (`map` / `symbol` /
891
- // `function` / `promise`) are rejected at adapter construction by
892
- // `assertSupportedKinds`; this fallthrough keeps the walker
893
- // defensive in case construction is skipped.
1020
+ // A kind this walker has no case for — in practice a kind a newer
1021
+ // Zod introduced. Be permissive rather than reject: the adapter
1022
+ // carries the value opaquely and the schema's own parse is what
1023
+ // decides whether it was legal.
894
1024
  default:
895
1025
  return PERMISSIVE_SLIM_KINDS;
896
1026
  }
@@ -984,11 +1114,20 @@ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress,
984
1114
  case "set": {
985
1115
  const inner = intro.getSetValueType(schema);
986
1116
  if (inner !== void 0)
987
- walkForMeta(inner, [...path, 0], map, counters, lastPathPerSchema, inProgress, services);
1117
+ walkForMeta(
1118
+ inner,
1119
+ [...path, SET_MEMBER_SEGMENT],
1120
+ map,
1121
+ counters,
1122
+ lastPathPerSchema,
1123
+ inProgress,
1124
+ services
1125
+ );
988
1126
  return;
989
1127
  }
990
- case "record": {
991
- const inner = intro.getRecordValueType(schema);
1128
+ case "record":
1129
+ case "map": {
1130
+ const inner = kind === "map" ? intro.getMapValueType(schema) : intro.getRecordValueType(schema);
992
1131
  if (inner !== void 0)
993
1132
  walkForMeta(inner, [...path, "*"], map, counters, lastPathPerSchema, inProgress, services);
994
1133
  return;
@@ -1060,4 +1199,4 @@ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress,
1060
1199
  }
1061
1200
  }
1062
1201
 
1063
- 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 };
1202
+ export { createSharedSchemaStore as a, buildFieldMetaPathMap as b, createAbstractSchema as c, deriveDefaultWalk as d, getFieldMetaListForSchema as e, fixStructuralDefaults as f, getFieldMetaForSchema as g, installingFieldMetaStore as i, mergeDeep as m, slimPrimitivesWalk as s, walkPathSegments as w };