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