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,29 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { A as AttaformError, e as canonicalizePath, a as InvalidUseFormConfigError } from './attaform.
|
|
3
|
-
import { s as slimPrimitivesWalk, d as deriveDefaultWalk, m as mergeDeep, f as fixStructuralDefaults, w as walkPathSegments, c as createAbstractSchema, b as buildFieldMetaPathMap,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
function zodIssuesToValidationErrors(issues) {
|
|
7
|
-
return issues.map((issue) => {
|
|
8
|
-
let code;
|
|
9
|
-
if (typeof issue.code === "string" && issue.code.length > 0) {
|
|
10
|
-
code = `zod:${issue.code}`;
|
|
11
|
-
} else {
|
|
12
|
-
code = "zod:unknown";
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
message: issue.message,
|
|
16
|
-
// Adapter-side paths stay schema-relative — the validation
|
|
17
|
-
// pipeline in `create-form-store.ts` prepends the parent path
|
|
18
|
-
// to absolutise, then routes form-level (absolute path length 0)
|
|
19
|
-
// entries to the empty-string bucket at storage time.
|
|
20
|
-
path: issue.path.map((seg) => typeof seg === "number" ? seg : String(seg)),
|
|
21
|
-
code
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
class UnsupportedSchemaError extends AttaformError {
|
|
26
|
-
}
|
|
1
|
+
import { j as humanize, c as useAbstractForm } from './attaform.DNJOWjQw.mjs';
|
|
2
|
+
import { A as AttaformError, e as canonicalizePath, a as InvalidUseFormConfigError } from './attaform.CdZIEf7_.mjs';
|
|
3
|
+
import { s as slimPrimitivesWalk, d as deriveDefaultWalk, m as mergeDeep, f as fixStructuralDefaults, w as walkPathSegments, c as createAbstractSchema, a as createSharedSchemaStore, b as buildFieldMetaPathMap, e as getFieldMetaListForSchema, g as getFieldMetaForSchema } from './attaform.CUfrMK7t.mjs';
|
|
4
|
+
import { c as callConsumerSchemaFn } from './attaform.BRDDQeHV.mjs';
|
|
27
5
|
|
|
28
6
|
function readDef(schema) {
|
|
29
7
|
if (schema === null || typeof schema !== "object") return void 0;
|
|
@@ -70,7 +48,9 @@ const IDENTITY_KINDS = /* @__PURE__ */ new Set([
|
|
|
70
48
|
"file",
|
|
71
49
|
"map",
|
|
72
50
|
"symbol",
|
|
73
|
-
"function"
|
|
51
|
+
"function",
|
|
52
|
+
"nonoptional",
|
|
53
|
+
"success"
|
|
74
54
|
]);
|
|
75
55
|
function kindOf(schema) {
|
|
76
56
|
const def = readDef(schema);
|
|
@@ -103,6 +83,8 @@ function getRecordValueType(schema) {
|
|
|
103
83
|
const def = readDef(schema);
|
|
104
84
|
return def?.valueType;
|
|
105
85
|
}
|
|
86
|
+
const getMapKeyType = getRecordKeyType;
|
|
87
|
+
const getMapValueType = getRecordValueType;
|
|
106
88
|
function getTupleItems(schema) {
|
|
107
89
|
const def = readDef(schema);
|
|
108
90
|
return def?.items ?? [];
|
|
@@ -149,11 +131,7 @@ function unwrapLazy(schema) {
|
|
|
149
131
|
const def = readDef(schema);
|
|
150
132
|
const getter = def?.getter;
|
|
151
133
|
if (typeof getter !== "function") return void 0;
|
|
152
|
-
return getter();
|
|
153
|
-
}
|
|
154
|
-
function getLazyGetter(schema) {
|
|
155
|
-
const def = readDef(schema);
|
|
156
|
-
return typeof def?.getter === "function" ? def.getter : void 0;
|
|
134
|
+
return callConsumerSchemaFn(() => getter(), void 0);
|
|
157
135
|
}
|
|
158
136
|
function getIntersectionLeft(schema) {
|
|
159
137
|
const def = readDef(schema);
|
|
@@ -167,11 +145,9 @@ function getCatchDefault(schema) {
|
|
|
167
145
|
const def = readDef(schema);
|
|
168
146
|
const cv = def?.catchValue;
|
|
169
147
|
if (typeof cv !== "function") return void 0;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return void 0;
|
|
174
|
-
}
|
|
148
|
+
return callConsumerSchemaFn(
|
|
149
|
+
() => cv({ error: new Error("atta:default-values"), input: void 0 }),
|
|
150
|
+
void 0);
|
|
175
151
|
}
|
|
176
152
|
function hasCatchValue(schema) {
|
|
177
153
|
const def = readDef(schema);
|
|
@@ -179,7 +155,7 @@ function hasCatchValue(schema) {
|
|
|
179
155
|
}
|
|
180
156
|
function getDefaultValue(schema) {
|
|
181
157
|
const def = readDef(schema);
|
|
182
|
-
return def?.defaultValue;
|
|
158
|
+
return callConsumerSchemaFn(() => def?.defaultValue, void 0);
|
|
183
159
|
}
|
|
184
160
|
function getNativeEnumValues(_schema) {
|
|
185
161
|
return void 0;
|
|
@@ -190,11 +166,6 @@ function unwrapEffectsSource(_schema) {
|
|
|
190
166
|
function unwrapBranded(_schema) {
|
|
191
167
|
return void 0;
|
|
192
168
|
}
|
|
193
|
-
function hasChecks(schema) {
|
|
194
|
-
const def = readDef(schema);
|
|
195
|
-
const checks = def?.checks;
|
|
196
|
-
return Array.isArray(checks) && checks.length > 0;
|
|
197
|
-
}
|
|
198
169
|
function getChecks(schema) {
|
|
199
170
|
const def = readDef(schema);
|
|
200
171
|
const checks = def?.checks;
|
|
@@ -328,123 +299,6 @@ function isAsyncCheck(check) {
|
|
|
328
299
|
return fn.constructor.name === "AsyncFunction";
|
|
329
300
|
}
|
|
330
301
|
|
|
331
|
-
const UNSUPPORTED = [
|
|
332
|
-
"promise",
|
|
333
|
-
"custom",
|
|
334
|
-
"template-literal",
|
|
335
|
-
"map",
|
|
336
|
-
"symbol",
|
|
337
|
-
"function"
|
|
338
|
-
];
|
|
339
|
-
function labelPath(path) {
|
|
340
|
-
return path.length === 0 ? "<root>" : path.join(".");
|
|
341
|
-
}
|
|
342
|
-
function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
343
|
-
const kind = kindOf(schema);
|
|
344
|
-
if (UNSUPPORTED.includes(kind)) {
|
|
345
|
-
throw new UnsupportedSchemaError(
|
|
346
|
-
`[attaform] AF02 attaform.dev/e/af02 '${kind}' at '${labelPath(path)}'`
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
switch (kind) {
|
|
350
|
-
case "object": {
|
|
351
|
-
const shape = getObjectShape(schema);
|
|
352
|
-
for (const [key, sub] of Object.entries(shape)) {
|
|
353
|
-
assertSupportedKinds(sub, [...path, key], lazyGetters);
|
|
354
|
-
}
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
case "array":
|
|
358
|
-
assertSupportedKinds(getArrayElement(schema), [...path, "*"], lazyGetters);
|
|
359
|
-
return;
|
|
360
|
-
case "set":
|
|
361
|
-
assertSupportedKinds(getSetValueType(schema), [...path, "*"], lazyGetters);
|
|
362
|
-
return;
|
|
363
|
-
case "record":
|
|
364
|
-
assertSupportedKinds(getRecordValueType(schema), [...path, "*"], lazyGetters);
|
|
365
|
-
return;
|
|
366
|
-
case "tuple": {
|
|
367
|
-
const items = getTupleItems(schema);
|
|
368
|
-
items.forEach((item, i) => assertSupportedKinds(item, [...path, String(i)], lazyGetters));
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
case "union": {
|
|
372
|
-
const options = getUnionOptions(schema);
|
|
373
|
-
options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
case "discriminated-union": {
|
|
377
|
-
const options = getDiscriminatedOptions(schema);
|
|
378
|
-
options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
case "optional":
|
|
382
|
-
case "nullable":
|
|
383
|
-
case "default":
|
|
384
|
-
case "readonly":
|
|
385
|
-
case "catch": {
|
|
386
|
-
const inner = unwrapInner(schema);
|
|
387
|
-
if (inner !== void 0) assertSupportedKinds(inner, path, lazyGetters);
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
case "pipe": {
|
|
391
|
-
const inner = unwrapPipe(schema);
|
|
392
|
-
if (inner !== void 0) assertSupportedKinds(inner, path, lazyGetters);
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
case "lazy": {
|
|
396
|
-
const getter = getLazyGetter(schema);
|
|
397
|
-
if (getter !== void 0 && lazyGetters.includes(getter)) return;
|
|
398
|
-
const inner = unwrapLazy(schema);
|
|
399
|
-
if (inner !== void 0) {
|
|
400
|
-
assertSupportedKinds(
|
|
401
|
-
inner,
|
|
402
|
-
path,
|
|
403
|
-
getter === void 0 ? lazyGetters : [...lazyGetters, getter]
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
case "intersection": {
|
|
409
|
-
const left = getIntersectionLeft(schema);
|
|
410
|
-
const right = getIntersectionRight(schema);
|
|
411
|
-
if (left !== void 0) assertSupportedKinds(left, [...path, "left"], lazyGetters);
|
|
412
|
-
if (right !== void 0) assertSupportedKinds(right, [...path, "right"], lazyGetters);
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
// Leaves: nothing to descend into.
|
|
416
|
-
case "string":
|
|
417
|
-
case "number":
|
|
418
|
-
case "boolean":
|
|
419
|
-
case "bigint":
|
|
420
|
-
case "date":
|
|
421
|
-
case "enum":
|
|
422
|
-
case "literal":
|
|
423
|
-
case "null":
|
|
424
|
-
case "undefined":
|
|
425
|
-
case "nan":
|
|
426
|
-
case "any":
|
|
427
|
-
case "unknown":
|
|
428
|
-
case "void":
|
|
429
|
-
case "never":
|
|
430
|
-
case "promise":
|
|
431
|
-
case "custom":
|
|
432
|
-
case "template-literal":
|
|
433
|
-
case "transform":
|
|
434
|
-
case "file":
|
|
435
|
-
case "map":
|
|
436
|
-
case "symbol":
|
|
437
|
-
case "function":
|
|
438
|
-
return;
|
|
439
|
-
default: {
|
|
440
|
-
const _exhaustive = kind;
|
|
441
|
-
throw new Error(
|
|
442
|
-
`[attaform] AF03 attaform.dev/e/af03 '${_exhaustive}'`
|
|
443
|
-
);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
302
|
function unwrapToDiscriminatedUnion(schema) {
|
|
449
303
|
let current = schema;
|
|
450
304
|
for (let i = 0; i < 64; i++) {
|
|
@@ -471,6 +325,26 @@ function unwrapToDiscriminatedUnion(schema) {
|
|
|
471
325
|
return void 0;
|
|
472
326
|
}
|
|
473
327
|
|
|
328
|
+
function zodIssuesToValidationErrors(issues) {
|
|
329
|
+
return issues.map((issue) => {
|
|
330
|
+
let code;
|
|
331
|
+
if (typeof issue.code === "string" && issue.code.length > 0) {
|
|
332
|
+
code = `zod:${issue.code}`;
|
|
333
|
+
} else {
|
|
334
|
+
code = "zod:unknown";
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
message: issue.message,
|
|
338
|
+
// Adapter-side paths stay schema-relative — the validation
|
|
339
|
+
// pipeline in `create-form-store.ts` prepends the parent path
|
|
340
|
+
// to absolutise, then routes form-level (absolute path length 0)
|
|
341
|
+
// entries to the empty-string bucket at storage time.
|
|
342
|
+
path: issue.path.map((seg) => typeof seg === "number" ? seg : String(seg)),
|
|
343
|
+
code
|
|
344
|
+
};
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
474
348
|
const V4_INTROSPECTOR = {
|
|
475
349
|
kindOf: (schema) => kindOf(schema),
|
|
476
350
|
getObjectShape: (schema) => getObjectShape(schema),
|
|
@@ -490,8 +364,9 @@ const V4_INTROSPECTOR = {
|
|
|
490
364
|
return getArrayElement(schema);
|
|
491
365
|
},
|
|
492
366
|
getSetValueType: (schema) => kindOf(schema) === "set" ? getSetValueType(schema) : void 0,
|
|
493
|
-
getRecordKeyType: (schema) => kindOf(schema) === "record" ? getRecordKeyType(schema) : void 0,
|
|
494
367
|
getRecordValueType: (schema) => kindOf(schema) === "record" ? getRecordValueType(schema) : void 0,
|
|
368
|
+
getMapKeyType: (schema) => kindOf(schema) === "map" ? getMapKeyType(schema) : void 0,
|
|
369
|
+
getMapValueType: (schema) => kindOf(schema) === "map" ? getMapValueType(schema) : void 0,
|
|
495
370
|
getUnionOptions,
|
|
496
371
|
getIntersectionLeft,
|
|
497
372
|
getIntersectionRight,
|
|
@@ -503,7 +378,6 @@ const V4_INTROSPECTOR = {
|
|
|
503
378
|
unwrapPipeIn,
|
|
504
379
|
unwrapPipeOut,
|
|
505
380
|
unwrapLazy,
|
|
506
|
-
getLazyGetter,
|
|
507
381
|
getDefaultValue,
|
|
508
382
|
getCatchDefault,
|
|
509
383
|
hasCatchValue
|
|
@@ -514,15 +388,12 @@ function slimPrimitivesOf(schema, maxRecursionDepth) {
|
|
|
514
388
|
}
|
|
515
389
|
|
|
516
390
|
function deriveDefault(schema, useDefault, maxRecursionDepth) {
|
|
517
|
-
return deriveDefaultWalk(schema, useDefault, V4_INTROSPECTOR, maxRecursionDepth
|
|
518
|
-
// v4 has an exhaustive switch against `SchemaIntrospector.kindOf`;
|
|
519
|
-
// unknown kinds genuinely shouldn't appear, so return undefined.
|
|
520
|
-
unsupportedKindFallback: () => void 0
|
|
521
|
-
});
|
|
391
|
+
return deriveDefaultWalk(schema, useDefault, V4_INTROSPECTOR, maxRecursionDepth);
|
|
522
392
|
}
|
|
523
393
|
function getDefaultValuesFromZodSchema(opts) {
|
|
524
394
|
const { schema, useDefaultSchemaValues, constraints, maxRecursionDepth } = opts;
|
|
525
395
|
const initial = deriveDefault(schema, useDefaultSchemaValues, maxRecursionDepth);
|
|
396
|
+
if (constraints === void 0) return { data: initial, success: true };
|
|
526
397
|
const merged = mergeDeep(initial, constraints);
|
|
527
398
|
return fixStructuralDefaults(
|
|
528
399
|
schema,
|
|
@@ -554,137 +425,6 @@ function getNestedZodSchemasAtPath(schema, path, maxRecursionDepth) {
|
|
|
554
425
|
);
|
|
555
426
|
}
|
|
556
427
|
|
|
557
|
-
function carrySyncChecks(rebuilt, original) {
|
|
558
|
-
if (!hasChecks(original)) return rebuilt;
|
|
559
|
-
const checks = getChecks(original).filter((c) => !isAsyncCheck(c));
|
|
560
|
-
if (checks.length === 0) return rebuilt;
|
|
561
|
-
return rebuilt.check(
|
|
562
|
-
...checks
|
|
563
|
-
);
|
|
564
|
-
}
|
|
565
|
-
function stripAsyncChecks(schema) {
|
|
566
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
567
|
-
function recurse(s) {
|
|
568
|
-
if (seen.has(s)) return s;
|
|
569
|
-
seen.add(s);
|
|
570
|
-
const kind = kindOf(s);
|
|
571
|
-
switch (kind) {
|
|
572
|
-
case "string":
|
|
573
|
-
return hasChecks(s) ? carrySyncChecks(z.string(), s) : s;
|
|
574
|
-
case "number":
|
|
575
|
-
return hasChecks(s) ? carrySyncChecks(z.number(), s) : s;
|
|
576
|
-
case "bigint":
|
|
577
|
-
return hasChecks(s) ? carrySyncChecks(z.bigint(), s) : s;
|
|
578
|
-
case "array": {
|
|
579
|
-
const element = getArrayElement(s);
|
|
580
|
-
return carrySyncChecks(z.array(recurse(element)), s);
|
|
581
|
-
}
|
|
582
|
-
case "set": {
|
|
583
|
-
return carrySyncChecks(z.set(recurse(getSetValueType(s))), s);
|
|
584
|
-
}
|
|
585
|
-
case "tuple": {
|
|
586
|
-
const items = getTupleItems(s).map(recurse);
|
|
587
|
-
const rebuilt = z.tuple(
|
|
588
|
-
items
|
|
589
|
-
);
|
|
590
|
-
return carrySyncChecks(rebuilt, s);
|
|
591
|
-
}
|
|
592
|
-
case "object": {
|
|
593
|
-
const shape = getObjectShape(s);
|
|
594
|
-
const next = {};
|
|
595
|
-
for (const [k, v] of Object.entries(shape)) {
|
|
596
|
-
next[k] = recurse(v);
|
|
597
|
-
}
|
|
598
|
-
return carrySyncChecks(z.object(next), s);
|
|
599
|
-
}
|
|
600
|
-
case "record": {
|
|
601
|
-
const keyType = getRecordKeyType(s);
|
|
602
|
-
const valueType = recurse(getRecordValueType(s));
|
|
603
|
-
return carrySyncChecks(
|
|
604
|
-
z.record(keyType, valueType),
|
|
605
|
-
s
|
|
606
|
-
);
|
|
607
|
-
}
|
|
608
|
-
case "union": {
|
|
609
|
-
const options = getUnionOptions(s).map(recurse);
|
|
610
|
-
return carrySyncChecks(
|
|
611
|
-
z.union(options),
|
|
612
|
-
s
|
|
613
|
-
);
|
|
614
|
-
}
|
|
615
|
-
case "discriminated-union": {
|
|
616
|
-
const options = getDiscriminatedOptions(s).map((opt) => recurse(opt));
|
|
617
|
-
const discriminator = getDiscriminator(s);
|
|
618
|
-
if (discriminator === void 0) return s;
|
|
619
|
-
return z.discriminatedUnion(
|
|
620
|
-
discriminator,
|
|
621
|
-
options
|
|
622
|
-
);
|
|
623
|
-
}
|
|
624
|
-
case "optional": {
|
|
625
|
-
const inner = unwrapInner(s);
|
|
626
|
-
return inner === void 0 ? s : recurse(inner).optional();
|
|
627
|
-
}
|
|
628
|
-
case "nullable": {
|
|
629
|
-
const inner = unwrapInner(s);
|
|
630
|
-
return inner === void 0 ? s : recurse(inner).nullable();
|
|
631
|
-
}
|
|
632
|
-
case "default": {
|
|
633
|
-
const inner = unwrapInner(s);
|
|
634
|
-
if (inner === void 0) return s;
|
|
635
|
-
return recurse(inner).default(getDefaultValue(s));
|
|
636
|
-
}
|
|
637
|
-
case "readonly": {
|
|
638
|
-
const inner = unwrapInner(s);
|
|
639
|
-
return inner === void 0 ? s : recurse(inner).readonly();
|
|
640
|
-
}
|
|
641
|
-
case "lazy": {
|
|
642
|
-
const inner = unwrapLazy(s);
|
|
643
|
-
if (inner === void 0) return s;
|
|
644
|
-
const stripped = recurse(inner);
|
|
645
|
-
return z.lazy(() => stripped);
|
|
646
|
-
}
|
|
647
|
-
case "intersection": {
|
|
648
|
-
const left = getIntersectionLeft(s);
|
|
649
|
-
const right = getIntersectionRight(s);
|
|
650
|
-
if (left === void 0 || right === void 0) return s;
|
|
651
|
-
return z.intersection(recurse(left), recurse(right));
|
|
652
|
-
}
|
|
653
|
-
case "catch": {
|
|
654
|
-
const inner = unwrapInner(s);
|
|
655
|
-
if (inner === void 0) return s;
|
|
656
|
-
return recurse(inner).catch(getCatchDefault(s));
|
|
657
|
-
}
|
|
658
|
-
// Pipes pass through (see the docblock); the rest are leaves
|
|
659
|
-
// whose checks the strip walker deliberately leaves in place —
|
|
660
|
-
// an async check on one of these still poisons the sync parse
|
|
661
|
-
// and the callers' defensive catch owns that case.
|
|
662
|
-
case "pipe":
|
|
663
|
-
case "boolean":
|
|
664
|
-
case "date":
|
|
665
|
-
case "enum":
|
|
666
|
-
case "literal":
|
|
667
|
-
case "null":
|
|
668
|
-
case "undefined":
|
|
669
|
-
case "any":
|
|
670
|
-
case "unknown":
|
|
671
|
-
case "nan":
|
|
672
|
-
case "void":
|
|
673
|
-
case "never":
|
|
674
|
-
case "promise":
|
|
675
|
-
case "custom":
|
|
676
|
-
case "template-literal":
|
|
677
|
-
case "transform":
|
|
678
|
-
case "file":
|
|
679
|
-
case "map":
|
|
680
|
-
case "symbol":
|
|
681
|
-
case "function":
|
|
682
|
-
return s;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
return recurse(schema);
|
|
686
|
-
}
|
|
687
|
-
|
|
688
428
|
function unwrapStructuralWrappers(schema) {
|
|
689
429
|
let current = schema;
|
|
690
430
|
for (let i = 0; i < 64; i++) {
|
|
@@ -697,6 +437,13 @@ function unwrapStructuralWrappers(schema) {
|
|
|
697
437
|
}
|
|
698
438
|
return current;
|
|
699
439
|
}
|
|
440
|
+
function assertKeyedRoot(rootSchema) {
|
|
441
|
+
const kind = kindOf(peelAllWrappers(rootSchema));
|
|
442
|
+
if (kind === "object" || kind === "record" || kind === "discriminated-union") return;
|
|
443
|
+
throw new AttaformError(
|
|
444
|
+
`[attaform] AF15 attaform.dev/e/af15 '${kind}'`
|
|
445
|
+
);
|
|
446
|
+
}
|
|
700
447
|
function peelAllWrappers(schema) {
|
|
701
448
|
let current = schema;
|
|
702
449
|
for (let i = 0; i < 64; i++) {
|
|
@@ -770,22 +517,21 @@ function isLeafRequired(schema, depth = 0) {
|
|
|
770
517
|
}
|
|
771
518
|
function zodV4Adapter(rootSchema) {
|
|
772
519
|
assertZodVersion(rootSchema);
|
|
773
|
-
|
|
774
|
-
return (
|
|
520
|
+
assertKeyedRoot(rootSchema);
|
|
521
|
+
return (_formKey, options) => sharedV4Schemas(
|
|
775
522
|
rootSchema,
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
523
|
+
options.maxRecursionDepth,
|
|
524
|
+
() => createAbstractSchema(
|
|
525
|
+
rootSchema,
|
|
526
|
+
V4_INTROSPECTOR,
|
|
527
|
+
buildV4Services(),
|
|
528
|
+
options
|
|
529
|
+
)
|
|
780
530
|
);
|
|
781
531
|
}
|
|
782
|
-
|
|
783
|
-
const { fingerprintZodSchema } = await import('../chunks/fingerprint2.mjs');
|
|
784
|
-
return fingerprintZodSchema(schema);
|
|
785
|
-
}
|
|
532
|
+
const sharedV4Schemas = createSharedSchemaStore();
|
|
786
533
|
function buildV4Services() {
|
|
787
534
|
return {
|
|
788
|
-
fingerprint: (schema) => lazyFingerprint(schema),
|
|
789
535
|
getNestedSchemasAtPath: (schema, path, maxRecursionDepth) => getNestedZodSchemasAtPath(schema, path, maxRecursionDepth),
|
|
790
536
|
// v4 doesn't pre-strip for the slim-mode walk — its path walker
|
|
791
537
|
// already peels every transparent wrapper inline, so the slim and
|
|
@@ -793,7 +539,7 @@ function buildV4Services() {
|
|
|
793
539
|
getNestedSchemasInSlimMode: (schema, path, maxRecursionDepth) => getNestedZodSchemasAtPath(schema, path, maxRecursionDepth),
|
|
794
540
|
slimPrimitivesOf: (schema, maxRecursionDepth) => slimPrimitivesOf(schema, maxRecursionDepth),
|
|
795
541
|
deriveDefault: (schema, useDefault, maxRecursionDepth) => deriveDefault(schema, useDefault, maxRecursionDepth),
|
|
796
|
-
|
|
542
|
+
runGetDefaults: (schema, config, maxRecursionDepth) => runGetDefaultsV4(schema, config, maxRecursionDepth),
|
|
797
543
|
unwrapStructuralWrappers: (schema) => unwrapStructuralWrappers(schema),
|
|
798
544
|
unwrapToDiscriminatedUnion: (schema) => unwrapToDiscriminatedUnion(schema),
|
|
799
545
|
peelAllWrappers: (schema) => peelAllWrappers(schema),
|
|
@@ -808,47 +554,40 @@ function buildV4Services() {
|
|
|
808
554
|
const result = await schema.safeParseAsync(data);
|
|
809
555
|
return result.success ? { success: true, data: result.data } : { success: false, issues: result.error.issues };
|
|
810
556
|
},
|
|
811
|
-
makeSubSchema: (schema,
|
|
557
|
+
makeSubSchema: (schema, maxRecursionDepth) => buildSubSchemaStubV4(schema, maxRecursionDepth)
|
|
812
558
|
};
|
|
813
559
|
}
|
|
814
|
-
function
|
|
560
|
+
function runGetDefaultsV4(rootSchema, config, maxRecursionDepth) {
|
|
815
561
|
const { data } = getDefaultValuesFromZodSchema({
|
|
816
562
|
schema: rootSchema,
|
|
817
563
|
useDefaultSchemaValues: config.useDefaultSchemaValues,
|
|
818
564
|
constraints: config.constraints,
|
|
819
565
|
maxRecursionDepth
|
|
820
566
|
});
|
|
821
|
-
if (
|
|
822
|
-
return { data, errors: void 0, success: true
|
|
823
|
-
}
|
|
824
|
-
if (containsAsyncTransform(rootSchema)) {
|
|
825
|
-
return { data, errors: void 0, success: true, formKey };
|
|
567
|
+
if (containsAsyncTransform(rootSchema) || containsAsyncRefine(rootSchema)) {
|
|
568
|
+
return { data, errors: void 0, success: true };
|
|
826
569
|
}
|
|
827
|
-
const parseTarget = containsAsyncRefine(rootSchema) ? stripAsyncChecks(rootSchema) : rootSchema;
|
|
828
570
|
try {
|
|
829
|
-
const
|
|
830
|
-
if (
|
|
831
|
-
return { data, errors: void 0, success: true
|
|
571
|
+
const parseResult = rootSchema.safeParse(data);
|
|
572
|
+
if (parseResult.success) {
|
|
573
|
+
return { data, errors: void 0, success: true };
|
|
832
574
|
}
|
|
833
575
|
return {
|
|
834
576
|
data,
|
|
835
|
-
errors: zodIssuesToValidationErrors(
|
|
836
|
-
success: false
|
|
837
|
-
formKey
|
|
577
|
+
errors: zodIssuesToValidationErrors(parseResult.error.issues),
|
|
578
|
+
success: false
|
|
838
579
|
};
|
|
839
580
|
} catch {
|
|
840
|
-
return { data, errors: void 0, success: true
|
|
581
|
+
return { data, errors: void 0, success: true };
|
|
841
582
|
}
|
|
842
583
|
}
|
|
843
|
-
function buildSubSchemaStubV4(schema,
|
|
584
|
+
function buildSubSchemaStubV4(schema, maxRecursionDepth) {
|
|
844
585
|
return {
|
|
845
|
-
fingerprint: () => lazyFingerprint(schema),
|
|
846
586
|
needsAsyncValidation: () => containsAsyncRefine(schema),
|
|
847
587
|
getDefaultValues: () => ({
|
|
848
588
|
data: deriveDefault(schema, true, maxRecursionDepth),
|
|
849
589
|
errors: void 0,
|
|
850
|
-
success: true
|
|
851
|
-
formKey
|
|
590
|
+
success: true
|
|
852
591
|
}),
|
|
853
592
|
getSchemasAtPath: () => [],
|
|
854
593
|
validateAtPath: async (data) => {
|
|
@@ -857,15 +596,13 @@ function buildSubSchemaStubV4(schema, formKey, maxRecursionDepth) {
|
|
|
857
596
|
return {
|
|
858
597
|
data: result.data,
|
|
859
598
|
errors: void 0,
|
|
860
|
-
success: true
|
|
861
|
-
formKey
|
|
599
|
+
success: true
|
|
862
600
|
};
|
|
863
601
|
}
|
|
864
602
|
return {
|
|
865
603
|
data: void 0,
|
|
866
604
|
errors: zodIssuesToValidationErrors(result.error.issues),
|
|
867
|
-
success: false
|
|
868
|
-
formKey
|
|
605
|
+
success: false
|
|
869
606
|
};
|
|
870
607
|
}
|
|
871
608
|
};
|
|
@@ -917,4 +654,4 @@ function useForm(configuration) {
|
|
|
917
654
|
});
|
|
918
655
|
}
|
|
919
656
|
|
|
920
|
-
export {
|
|
657
|
+
export { assertZodVersion as a, kindOf as k, useForm as u, zodV4Adapter as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as InvalidUseFormConfigError } from './attaform.
|
|
2
|
-
import { u as useForm$2 } from './attaform.
|
|
3
|
-
import { u as useForm$1 } from './attaform.
|
|
4
|
-
import { i as installingFieldMetaStore, g as getFieldMetaForSchema } from './attaform.
|
|
1
|
+
import { a as InvalidUseFormConfigError } from './attaform.CdZIEf7_.mjs';
|
|
2
|
+
import { u as useForm$2 } from './attaform.CJ8DpRGj.mjs';
|
|
3
|
+
import { u as useForm$1 } from './attaform.BXneBxEj.mjs';
|
|
4
|
+
import { i as installingFieldMetaStore, g as getFieldMetaForSchema } from './attaform.CUfrMK7t.mjs';
|
|
5
5
|
|
|
6
6
|
function isZodV4SchemaShape(value) {
|
|
7
7
|
if (typeof value !== "object" || value === null) return false;
|