attaform 0.17.2 → 0.18.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/README.md +77 -36
- package/dist/chunks/devtools.cjs +10 -37
- package/dist/chunks/devtools.cjs.map +1 -1
- package/dist/chunks/devtools.mjs +10 -37
- package/dist/chunks/devtools.mjs.map +1 -1
- package/dist/chunks/indexeddb.cjs +4 -4
- package/dist/chunks/indexeddb.cjs.map +1 -1
- package/dist/chunks/indexeddb.mjs +1 -1
- package/dist/chunks/local-storage.cjs +2 -2
- package/dist/chunks/local-storage.cjs.map +1 -1
- package/dist/chunks/local-storage.mjs +1 -1
- package/dist/chunks/session-storage.cjs +2 -2
- package/dist/chunks/session-storage.cjs.map +1 -1
- package/dist/chunks/session-storage.mjs +1 -1
- package/dist/index.cjs +42 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +159 -196
- package/dist/index.d.mts +159 -196
- package/dist/index.d.ts +159 -196
- package/dist/index.mjs +5 -7
- package/dist/index.mjs.map +1 -1
- package/dist/nuxt.cjs +31 -40
- package/dist/nuxt.cjs.map +1 -1
- package/dist/nuxt.d.cts +8 -1
- package/dist/nuxt.d.mts +8 -1
- package/dist/nuxt.d.ts +8 -1
- package/dist/nuxt.mjs +32 -41
- package/dist/nuxt.mjs.map +1 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.d.vue.ts +7 -0
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +453 -0
- package/dist/runtime/components/AttaformDevtoolsPanel.vue.d.ts +7 -0
- package/dist/runtime/components/DevtoolsValueTree.d.vue.ts +37 -0
- package/dist/runtime/components/DevtoolsValueTree.vue +192 -0
- package/dist/runtime/components/DevtoolsValueTree.vue.d.ts +37 -0
- package/dist/runtime/plugins/attaform.cjs +17 -6
- package/dist/runtime/plugins/attaform.cjs.map +1 -1
- package/dist/runtime/plugins/attaform.mjs +15 -4
- package/dist/runtime/plugins/attaform.mjs.map +1 -1
- package/dist/shared/attaform.5UhpSVFI.cjs +63 -0
- package/dist/shared/attaform.5UhpSVFI.cjs.map +1 -0
- package/dist/shared/attaform.BDdFdjeX.mjs +57 -0
- package/dist/shared/attaform.BDdFdjeX.mjs.map +1 -0
- package/dist/shared/attaform.Bgu9l6OG.d.cts +1651 -0
- package/dist/shared/attaform.BmDBu4ql.d.ts +1651 -0
- package/dist/shared/{attaform.Dee2rU1P.cjs → attaform.BqK_L4gK.cjs} +310 -24
- package/dist/shared/attaform.BqK_L4gK.cjs.map +1 -0
- package/dist/shared/{attaform.C_5aB6EQ.d.ts → attaform.BsMdl-35.d.cts} +754 -146
- package/dist/shared/{attaform.C_5aB6EQ.d.mts → attaform.BsMdl-35.d.mts} +754 -146
- package/dist/shared/{attaform.C_5aB6EQ.d.cts → attaform.BsMdl-35.d.ts} +754 -146
- package/dist/shared/attaform.Bubm_slq.cjs.map +1 -1
- package/dist/shared/{attaform.C6lbmMUe.d.ts → attaform.C3x1hKJC.d.mts} +4 -4
- package/dist/shared/{attaform.CuE-bS1C.d.mts → attaform.CWs1Z3p7.d.ts} +57 -23
- package/dist/shared/attaform.CXpzmj38.mjs.map +1 -1
- package/dist/shared/{attaform.C5MH4lNh.d.mts → attaform.CjmJpfLH.d.ts} +4 -4
- package/dist/shared/{attaform.Drt6fivF.mjs → attaform.CtNUB9nf.mjs} +74 -76
- package/dist/shared/attaform.CtNUB9nf.mjs.map +1 -0
- package/dist/shared/{attaform.C0iFnTN0.d.ts → attaform.D-hDvb98.d.cts} +57 -23
- package/dist/shared/attaform.DAH3kvav.d.mts +1651 -0
- package/dist/shared/{attaform.BPRHR3Zs.cjs → attaform.DUHru0OF.cjs} +83 -85
- package/dist/shared/attaform.DUHru0OF.cjs.map +1 -0
- package/dist/shared/{attaform.BV40t5y2.cjs → attaform.Dlk1jMuv.cjs} +245 -108
- package/dist/shared/attaform.Dlk1jMuv.cjs.map +1 -0
- package/dist/shared/{attaform.B3ZaPIzS.mjs → attaform.DsC3rZHG.mjs} +1804 -219
- package/dist/shared/attaform.DsC3rZHG.mjs.map +1 -0
- package/dist/shared/{attaform.DtMN-MAm.d.cts → attaform.Dzi89x8N.d.cts} +4 -4
- package/dist/shared/{attaform.Cer8JO_P.cjs → attaform.II89Pcf4.cjs} +1860 -272
- package/dist/shared/attaform.II89Pcf4.cjs.map +1 -0
- package/dist/shared/{attaform.CIEQgJnM.mjs → attaform.Xhg0AYNa.mjs} +300 -26
- package/dist/shared/attaform.Xhg0AYNa.mjs.map +1 -0
- package/dist/shared/{attaform.CpERWz3u.mjs → attaform.Xt0A3QUd.mjs} +232 -95
- package/dist/shared/attaform.Xt0A3QUd.mjs.map +1 -0
- package/dist/shared/{attaform.CHorcsIU.d.cts → attaform.bH7WvNad.d.mts} +57 -23
- package/dist/vite.cjs +270 -2
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +266 -2
- package/dist/vite.mjs.map +1 -1
- package/dist/zod-v3.cjs +11 -8
- package/dist/zod-v3.cjs.map +1 -1
- package/dist/zod-v3.d.cts +6 -6
- package/dist/zod-v3.d.mts +6 -6
- package/dist/zod-v3.d.ts +6 -6
- package/dist/zod-v3.mjs +3 -3
- package/dist/zod-v4.cjs +11 -8
- package/dist/zod-v4.cjs.map +1 -1
- package/dist/zod-v4.d.cts +5 -5
- package/dist/zod-v4.d.mts +5 -5
- package/dist/zod-v4.d.ts +5 -5
- package/dist/zod-v4.mjs +3 -3
- package/dist/zod.cjs +15 -16
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +127 -40
- package/dist/zod.d.mts +127 -40
- package/dist/zod.d.ts +127 -40
- package/dist/zod.mjs +7 -11
- package/dist/zod.mjs.map +1 -1
- package/package.json +19 -5
- package/dist/shared/attaform.B1jvxsOF.d.mts +0 -156
- package/dist/shared/attaform.B3ZaPIzS.mjs.map +0 -1
- package/dist/shared/attaform.BBM2muQ9.cjs +0 -101
- package/dist/shared/attaform.BBM2muQ9.cjs.map +0 -1
- package/dist/shared/attaform.BPRHR3Zs.cjs.map +0 -1
- package/dist/shared/attaform.BV40t5y2.cjs.map +0 -1
- package/dist/shared/attaform.C6qzEdIM.d.cts +0 -156
- package/dist/shared/attaform.C8LVFVVe.cjs +0 -32
- package/dist/shared/attaform.C8LVFVVe.cjs.map +0 -1
- package/dist/shared/attaform.CIEQgJnM.mjs.map +0 -1
- package/dist/shared/attaform.CTwNcpLE.d.ts +0 -156
- package/dist/shared/attaform.Cer8JO_P.cjs.map +0 -1
- package/dist/shared/attaform.CpERWz3u.mjs.map +0 -1
- package/dist/shared/attaform.Dee2rU1P.cjs.map +0 -1
- package/dist/shared/attaform.Drt6fivF.mjs.map +0 -1
- package/dist/shared/attaform.Vo-Kft0t.mjs +0 -29
- package/dist/shared/attaform.Vo-Kft0t.mjs.map +0 -1
- package/dist/shared/attaform.h1sq3BFu.mjs +0 -92
- package/dist/shared/attaform.h1sq3BFu.mjs.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { h as getAtPath, s as slimKindOf, k as setAtPath, m as isPlainRecord, A as AttaformErrorCode, j as humanize, g as useAbstractForm } from './attaform.DsC3rZHG.mjs';
|
|
2
|
+
import { b as AttaformError, _ as __DEV__, a as canonicalizePath, d as InvalidUseFormConfigError } from './attaform.Xhg0AYNa.mjs';
|
|
3
3
|
import { f as fieldMetaStore, g as getFieldMetaForSchema, a as getFieldMetaListForSchema } from './attaform.D13GMFgK.mjs';
|
|
4
|
-
import { c as canonicalizePath } from './attaform.h1sq3BFu.mjs';
|
|
5
4
|
import { z } from 'zod';
|
|
6
5
|
|
|
7
6
|
const fieldMeta = fieldMetaStore;
|
|
@@ -124,6 +123,8 @@ function kindOf(schema) {
|
|
|
124
123
|
case "template_literal":
|
|
125
124
|
case "templateLiteral":
|
|
126
125
|
return "template-literal";
|
|
126
|
+
case "file":
|
|
127
|
+
return "file";
|
|
127
128
|
default:
|
|
128
129
|
return "unknown";
|
|
129
130
|
}
|
|
@@ -178,14 +179,13 @@ function unwrapPipeIn(schema) {
|
|
|
178
179
|
const def = readDef(schema);
|
|
179
180
|
return def?.in;
|
|
180
181
|
}
|
|
182
|
+
function isCoercePrimitive(schema) {
|
|
183
|
+
return readDef(schema)?.coerce === true;
|
|
184
|
+
}
|
|
181
185
|
function unwrapPipeOut(schema) {
|
|
182
186
|
const def = readDef(schema);
|
|
183
187
|
return def?.out;
|
|
184
188
|
}
|
|
185
|
-
function readTransformFn(schema) {
|
|
186
|
-
const def = readDef(schema);
|
|
187
|
-
return typeof def?.transform === "function" ? def.transform : void 0;
|
|
188
|
-
}
|
|
189
189
|
function unwrapLazy(schema) {
|
|
190
190
|
const def = readDef(schema);
|
|
191
191
|
const getter = def?.getter;
|
|
@@ -310,6 +310,70 @@ function containsAsyncRefine(schema, seen) {
|
|
|
310
310
|
}
|
|
311
311
|
return false;
|
|
312
312
|
}
|
|
313
|
+
function containsAsyncTransform(schema, seen) {
|
|
314
|
+
const visited = seen ?? /* @__PURE__ */ new WeakSet();
|
|
315
|
+
const candidate = schema;
|
|
316
|
+
if (typeof candidate !== "object" || candidate === null) return false;
|
|
317
|
+
if (visited.has(candidate)) return false;
|
|
318
|
+
visited.add(candidate);
|
|
319
|
+
const def = readDef(schema);
|
|
320
|
+
if (def === void 0) return false;
|
|
321
|
+
if (typeof def.transform === "function" && def.transform.constructor.name === "AsyncFunction") {
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
if (def.innerType !== void 0 && containsAsyncTransform(def.innerType, visited)) {
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
if (def.element !== void 0 && containsAsyncTransform(def.element, visited)) {
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
if (def.in !== void 0 && containsAsyncTransform(def.in, visited)) {
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
if (def.out !== void 0 && containsAsyncTransform(def.out, visited)) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
if (def.left !== void 0 && containsAsyncTransform(def.left, visited)) {
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
if (def.right !== void 0 && containsAsyncTransform(def.right, visited)) {
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
if (def.keyType !== void 0 && containsAsyncTransform(def.keyType, visited)) {
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
if (def.valueType !== void 0 && containsAsyncTransform(def.valueType, visited)) {
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
if (def.shape !== void 0) {
|
|
349
|
+
for (const sub of Object.values(def.shape)) {
|
|
350
|
+
if (containsAsyncTransform(sub, visited)) return true;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (def.entries !== void 0) {
|
|
354
|
+
for (const sub of Object.values(def.entries)) {
|
|
355
|
+
if (containsAsyncTransform(sub, visited)) return true;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (def.options !== void 0) {
|
|
359
|
+
for (const sub of def.options) {
|
|
360
|
+
if (containsAsyncTransform(sub, visited)) return true;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (def.items !== void 0) {
|
|
364
|
+
for (const sub of def.items) {
|
|
365
|
+
if (containsAsyncTransform(sub, visited)) return true;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (typeof def.getter === "function") {
|
|
369
|
+
try {
|
|
370
|
+
const inner = def.getter();
|
|
371
|
+
if (containsAsyncTransform(inner, visited)) return true;
|
|
372
|
+
} catch {
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
313
377
|
function isAsyncCheck(check) {
|
|
314
378
|
if (typeof check !== "object" || check === null) return false;
|
|
315
379
|
const c = check;
|
|
@@ -414,6 +478,7 @@ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
|
414
478
|
case "custom":
|
|
415
479
|
case "template-literal":
|
|
416
480
|
case "transform":
|
|
481
|
+
case "file":
|
|
417
482
|
return;
|
|
418
483
|
default: {
|
|
419
484
|
const _exhaustive = kind;
|
|
@@ -569,6 +634,7 @@ function computeFingerprint(schema, cache, inProgress) {
|
|
|
569
634
|
case "custom":
|
|
570
635
|
case "template-literal":
|
|
571
636
|
case "transform":
|
|
637
|
+
case "file":
|
|
572
638
|
return `${kind}:*`;
|
|
573
639
|
default: {
|
|
574
640
|
const _ = kind;
|
|
@@ -648,30 +714,45 @@ const PERMISSIVE = /* @__PURE__ */ new Set([
|
|
|
648
714
|
"symbol",
|
|
649
715
|
"function",
|
|
650
716
|
"map",
|
|
651
|
-
"set"
|
|
717
|
+
"set",
|
|
718
|
+
"file"
|
|
652
719
|
]);
|
|
720
|
+
const KIND_STRING = /* @__PURE__ */ new Set(["string"]);
|
|
721
|
+
const KIND_NUMBER = /* @__PURE__ */ new Set(["number"]);
|
|
722
|
+
const KIND_BOOLEAN = /* @__PURE__ */ new Set(["boolean"]);
|
|
723
|
+
const KIND_BIGINT = /* @__PURE__ */ new Set(["bigint"]);
|
|
724
|
+
const KIND_DATE = /* @__PURE__ */ new Set(["date"]);
|
|
725
|
+
const KIND_NULL = /* @__PURE__ */ new Set(["null"]);
|
|
726
|
+
const KIND_UNDEFINED = /* @__PURE__ */ new Set(["undefined"]);
|
|
727
|
+
const KIND_OBJECT = /* @__PURE__ */ new Set(["object"]);
|
|
728
|
+
const KIND_ARRAY = /* @__PURE__ */ new Set(["array"]);
|
|
729
|
+
const KIND_SET = /* @__PURE__ */ new Set(["set"]);
|
|
730
|
+
const KIND_FILE = /* @__PURE__ */ new Set(["file", "null"]);
|
|
731
|
+
const EMPTY_KINDS = /* @__PURE__ */ new Set();
|
|
653
732
|
function slimPrimitivesOf(schema, maxRecursionDepth) {
|
|
654
|
-
return walk(schema, 0, maxRecursionDepth);
|
|
733
|
+
return new Set(walk(schema, 0, maxRecursionDepth));
|
|
655
734
|
}
|
|
656
735
|
function walk(schema, lazyDepth, maxDepth) {
|
|
657
736
|
const kind = kindOf(schema);
|
|
658
737
|
switch (kind) {
|
|
659
738
|
case "string":
|
|
660
|
-
return
|
|
739
|
+
return KIND_STRING;
|
|
661
740
|
case "number":
|
|
662
741
|
case "nan":
|
|
663
|
-
return
|
|
742
|
+
return KIND_NUMBER;
|
|
664
743
|
case "boolean":
|
|
665
|
-
return
|
|
744
|
+
return KIND_BOOLEAN;
|
|
666
745
|
case "bigint":
|
|
667
|
-
return
|
|
746
|
+
return KIND_BIGINT;
|
|
668
747
|
case "date":
|
|
669
|
-
return
|
|
748
|
+
return KIND_DATE;
|
|
749
|
+
case "file":
|
|
750
|
+
return KIND_FILE;
|
|
670
751
|
case "null":
|
|
671
|
-
return
|
|
752
|
+
return KIND_NULL;
|
|
672
753
|
case "undefined":
|
|
673
754
|
case "void":
|
|
674
|
-
return
|
|
755
|
+
return KIND_UNDEFINED;
|
|
675
756
|
case "enum": {
|
|
676
757
|
const values = getEnumValues(schema);
|
|
677
758
|
const out = /* @__PURE__ */ new Set();
|
|
@@ -679,48 +760,52 @@ function walk(schema, lazyDepth, maxDepth) {
|
|
|
679
760
|
if (typeof v === "string") out.add("string");
|
|
680
761
|
else if (typeof v === "number") out.add("number");
|
|
681
762
|
}
|
|
682
|
-
return out.size === 0 ?
|
|
763
|
+
return out.size === 0 ? KIND_STRING : out;
|
|
683
764
|
}
|
|
684
765
|
case "literal": {
|
|
685
766
|
const values = getLiteralValues(schema);
|
|
686
767
|
const out = /* @__PURE__ */ new Set();
|
|
687
768
|
for (const v of values) out.add(slimKindOfRaw(v));
|
|
688
|
-
return out.size === 0 ?
|
|
769
|
+
return out.size === 0 ? PERMISSIVE : out;
|
|
689
770
|
}
|
|
690
771
|
case "object":
|
|
691
772
|
case "record":
|
|
692
|
-
return
|
|
773
|
+
return KIND_OBJECT;
|
|
693
774
|
case "array":
|
|
694
775
|
case "tuple":
|
|
695
|
-
return
|
|
776
|
+
return KIND_ARRAY;
|
|
696
777
|
case "set":
|
|
697
|
-
return
|
|
778
|
+
return KIND_SET;
|
|
698
779
|
case "optional": {
|
|
699
780
|
const inner = unwrapInner(schema);
|
|
700
|
-
const innerSet = inner === void 0 ?
|
|
701
|
-
innerSet
|
|
702
|
-
|
|
781
|
+
const innerSet = inner === void 0 ? EMPTY_KINDS : walk(inner, lazyDepth, maxDepth);
|
|
782
|
+
const out = new Set(innerSet);
|
|
783
|
+
out.add("undefined");
|
|
784
|
+
return out;
|
|
703
785
|
}
|
|
704
786
|
case "nullable": {
|
|
705
787
|
const inner = unwrapInner(schema);
|
|
706
|
-
const innerSet = inner === void 0 ?
|
|
707
|
-
innerSet
|
|
708
|
-
|
|
788
|
+
const innerSet = inner === void 0 ? EMPTY_KINDS : walk(inner, lazyDepth, maxDepth);
|
|
789
|
+
const out = new Set(innerSet);
|
|
790
|
+
out.add("null");
|
|
791
|
+
return out;
|
|
709
792
|
}
|
|
710
793
|
case "default":
|
|
711
794
|
case "readonly":
|
|
712
795
|
case "catch": {
|
|
713
796
|
const inner = unwrapInner(schema);
|
|
714
|
-
return inner === void 0 ?
|
|
797
|
+
return inner === void 0 ? PERMISSIVE : walk(inner, lazyDepth, maxDepth);
|
|
715
798
|
}
|
|
716
799
|
case "pipe": {
|
|
717
|
-
const
|
|
718
|
-
|
|
800
|
+
const pipeIn = unwrapPipeIn(schema);
|
|
801
|
+
const pipeOut = unwrapPipeOut(schema);
|
|
802
|
+
const inner = pipeIn !== void 0 && kindOf(pipeIn) === "transform" ? pipeOut : pipeIn ?? pipeOut;
|
|
803
|
+
return inner === void 0 ? PERMISSIVE : walk(inner, lazyDepth, maxDepth);
|
|
719
804
|
}
|
|
720
805
|
case "lazy": {
|
|
721
|
-
if (lazyDepth >= maxDepth) return
|
|
806
|
+
if (lazyDepth >= maxDepth) return PERMISSIVE;
|
|
722
807
|
const inner = unwrapLazy(schema);
|
|
723
|
-
return inner === void 0 ?
|
|
808
|
+
return inner === void 0 ? PERMISSIVE : walk(inner, lazyDepth + 1, maxDepth);
|
|
724
809
|
}
|
|
725
810
|
case "union":
|
|
726
811
|
case "discriminated-union": {
|
|
@@ -729,22 +814,22 @@ function walk(schema, lazyDepth, maxDepth) {
|
|
|
729
814
|
for (const opt of options) {
|
|
730
815
|
for (const k of walk(opt, lazyDepth, maxDepth)) out.add(k);
|
|
731
816
|
}
|
|
732
|
-
return out.size === 0 ?
|
|
817
|
+
return out.size === 0 ? PERMISSIVE : out;
|
|
733
818
|
}
|
|
734
819
|
case "intersection": {
|
|
735
820
|
const left = getIntersectionLeft(schema);
|
|
736
821
|
const right = getIntersectionRight(schema);
|
|
737
|
-
const leftSet = left === void 0 ?
|
|
738
|
-
const rightSet = right === void 0 ?
|
|
822
|
+
const leftSet = left === void 0 ? PERMISSIVE : walk(left, lazyDepth, maxDepth);
|
|
823
|
+
const rightSet = right === void 0 ? PERMISSIVE : walk(right, lazyDepth, maxDepth);
|
|
739
824
|
const out = /* @__PURE__ */ new Set();
|
|
740
825
|
for (const k of leftSet) if (rightSet.has(k)) out.add(k);
|
|
741
826
|
return out;
|
|
742
827
|
}
|
|
743
828
|
case "never":
|
|
744
|
-
return
|
|
829
|
+
return EMPTY_KINDS;
|
|
745
830
|
case "any":
|
|
746
831
|
case "unknown":
|
|
747
|
-
return
|
|
832
|
+
return PERMISSIVE;
|
|
748
833
|
// Kinds we don't understand at the slim level: be permissive to
|
|
749
834
|
// avoid false-rejecting legitimate writes against schema shapes
|
|
750
835
|
// we haven't characterised.
|
|
@@ -752,9 +837,9 @@ function walk(schema, lazyDepth, maxDepth) {
|
|
|
752
837
|
case "custom":
|
|
753
838
|
case "template-literal":
|
|
754
839
|
case "transform":
|
|
755
|
-
return
|
|
840
|
+
return PERMISSIVE;
|
|
756
841
|
default:
|
|
757
|
-
return
|
|
842
|
+
return PERMISSIVE;
|
|
758
843
|
}
|
|
759
844
|
}
|
|
760
845
|
function slimKindOfRaw(value) {
|
|
@@ -873,6 +958,7 @@ function walkSegments(schema, segments, maxDepth, lazyDepth) {
|
|
|
873
958
|
case "custom":
|
|
874
959
|
case "template-literal":
|
|
875
960
|
case "transform":
|
|
961
|
+
case "file":
|
|
876
962
|
return [];
|
|
877
963
|
default: {
|
|
878
964
|
const _exhaustive = kind;
|
|
@@ -985,6 +1071,7 @@ function stripRefinements(schema) {
|
|
|
985
1071
|
case "custom":
|
|
986
1072
|
case "template-literal":
|
|
987
1073
|
case "transform":
|
|
1074
|
+
case "file":
|
|
988
1075
|
return schema;
|
|
989
1076
|
default: {
|
|
990
1077
|
const _exhaustive = kind;
|
|
@@ -1109,6 +1196,7 @@ function stripAsyncChecks(schema) {
|
|
|
1109
1196
|
case "custom":
|
|
1110
1197
|
case "template-literal":
|
|
1111
1198
|
case "transform":
|
|
1199
|
+
case "file":
|
|
1112
1200
|
return s;
|
|
1113
1201
|
default: {
|
|
1114
1202
|
const _exhaustive = kind;
|
|
@@ -1254,6 +1342,7 @@ function walkSlim(schema, stripConfig, maxDepth, lazyDepth) {
|
|
|
1254
1342
|
return slimmedInner.catch(getCatchDefault(schema));
|
|
1255
1343
|
}
|
|
1256
1344
|
case "transform":
|
|
1345
|
+
case "file":
|
|
1257
1346
|
return schema;
|
|
1258
1347
|
default: {
|
|
1259
1348
|
const _exhaustive = kind;
|
|
@@ -1262,10 +1351,25 @@ function walkSlim(schema, stripConfig, maxDepth, lazyDepth) {
|
|
|
1262
1351
|
}
|
|
1263
1352
|
}
|
|
1264
1353
|
|
|
1354
|
+
function hasDeclaredDefaultInChain(schema) {
|
|
1355
|
+
let current = schema;
|
|
1356
|
+
for (let i = 0; i < 32; i++) {
|
|
1357
|
+
if (current === void 0) return false;
|
|
1358
|
+
const k = kindOf(current);
|
|
1359
|
+
if (k === "default") return true;
|
|
1360
|
+
if (k === "optional" || k === "nullable" || k === "readonly" || k === "catch") {
|
|
1361
|
+
current = unwrapInner(current);
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
return false;
|
|
1365
|
+
}
|
|
1366
|
+
return false;
|
|
1367
|
+
}
|
|
1265
1368
|
function deriveDefault(schema, useDefault, maxRecursionDepth) {
|
|
1266
1369
|
return defaultForKind(kindOf(schema), schema, useDefault, maxRecursionDepth, 0);
|
|
1267
1370
|
}
|
|
1268
1371
|
function defaultForKind(kind, schema, useDefault, maxDepth, lazyDepth) {
|
|
1372
|
+
if (isCoercePrimitive(schema)) return void 0;
|
|
1269
1373
|
switch (kind) {
|
|
1270
1374
|
case "object": {
|
|
1271
1375
|
const shape = getObjectShape(schema);
|
|
@@ -1289,8 +1393,15 @@ function defaultForKind(kind, schema, useDefault, maxDepth, lazyDepth) {
|
|
|
1289
1393
|
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1290
1394
|
}
|
|
1291
1395
|
case "pipe": {
|
|
1292
|
-
const out = unwrapPipeOut(schema);
|
|
1293
1396
|
const inn = unwrapPipeIn(schema);
|
|
1397
|
+
if (inn !== void 0 && kindOf(inn) === "transform") {
|
|
1398
|
+
const out2 = unwrapPipeOut(schema);
|
|
1399
|
+
if (out2 !== void 0 && hasDeclaredDefaultInChain(out2)) {
|
|
1400
|
+
return defaultForKind(kindOf(out2), out2, useDefault, maxDepth, lazyDepth);
|
|
1401
|
+
}
|
|
1402
|
+
return void 0;
|
|
1403
|
+
}
|
|
1404
|
+
const out = unwrapPipeOut(schema);
|
|
1294
1405
|
const real = inn !== void 0 && kindOf(inn) !== "transform" ? inn : out !== void 0 && kindOf(out) !== "transform" ? out : inn ?? out;
|
|
1295
1406
|
return real === void 0 ? void 0 : defaultForKind(kindOf(real), real, useDefault, maxDepth, lazyDepth);
|
|
1296
1407
|
}
|
|
@@ -1341,7 +1452,12 @@ function defaultForKind(kind, schema, useDefault, maxDepth, lazyDepth) {
|
|
|
1341
1452
|
return NaN;
|
|
1342
1453
|
case "lazy": {
|
|
1343
1454
|
if (lazyDepth >= maxDepth) return void 0;
|
|
1344
|
-
|
|
1455
|
+
let inner;
|
|
1456
|
+
try {
|
|
1457
|
+
inner = unwrapLazy(schema);
|
|
1458
|
+
} catch {
|
|
1459
|
+
return void 0;
|
|
1460
|
+
}
|
|
1345
1461
|
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth + 1);
|
|
1346
1462
|
}
|
|
1347
1463
|
case "intersection": {
|
|
@@ -1365,6 +1481,8 @@ function defaultForKind(kind, schema, useDefault, maxDepth, lazyDepth) {
|
|
|
1365
1481
|
case "template-literal":
|
|
1366
1482
|
case "transform":
|
|
1367
1483
|
return void 0;
|
|
1484
|
+
case "file":
|
|
1485
|
+
return null;
|
|
1368
1486
|
default: {
|
|
1369
1487
|
const _exhaustive = kind;
|
|
1370
1488
|
throw new Error(`deriveDefault: unhandled ZodKind '${_exhaustive}'`);
|
|
@@ -1381,7 +1499,7 @@ function mergeDeep(base, override) {
|
|
|
1381
1499
|
const bVal = base[key];
|
|
1382
1500
|
if (isPlainRecord(oVal) && isPlainRecord(bVal)) {
|
|
1383
1501
|
result[key] = mergeDeep(bVal, oVal);
|
|
1384
|
-
} else
|
|
1502
|
+
} else {
|
|
1385
1503
|
result[key] = oVal;
|
|
1386
1504
|
}
|
|
1387
1505
|
}
|
|
@@ -1407,6 +1525,14 @@ function getDefaultValuesFromZodSchema(opts) {
|
|
|
1407
1525
|
let fixedData = merged;
|
|
1408
1526
|
for (const issue of firstParse.error.issues) {
|
|
1409
1527
|
const pathSegments = issue.path.map((seg) => typeof seg === "number" ? seg : String(seg));
|
|
1528
|
+
const originalCandidate = getNestedZodSchemasAtPath(schema, pathSegments, maxRecursionDepth)[0];
|
|
1529
|
+
if (originalCandidate !== void 0) {
|
|
1530
|
+
if (isCoercePrimitive(originalCandidate)) continue;
|
|
1531
|
+
if (kindOf(originalCandidate) === "pipe") {
|
|
1532
|
+
const pipeIn = unwrapPipeIn(originalCandidate);
|
|
1533
|
+
if (pipeIn !== void 0 && kindOf(pipeIn) === "transform") continue;
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1410
1536
|
const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments, maxRecursionDepth);
|
|
1411
1537
|
if (candidates.length === 0) continue;
|
|
1412
1538
|
const candidate = candidates[0];
|
|
@@ -1535,11 +1661,12 @@ function zodV4Adapter(rootSchema) {
|
|
|
1535
1661
|
return (formKey, options) => {
|
|
1536
1662
|
const maxRecursionDepth = options.maxRecursionDepth;
|
|
1537
1663
|
const leafCache = /* @__PURE__ */ new Map();
|
|
1664
|
+
const preprocessOrCoerceCache = /* @__PURE__ */ new Map();
|
|
1538
1665
|
let asyncValidationFlag = null;
|
|
1539
1666
|
return {
|
|
1540
1667
|
fingerprint: () => fingerprintZodSchema(rootSchema),
|
|
1541
1668
|
needsAsyncValidation() {
|
|
1542
|
-
asyncValidationFlag ?? (asyncValidationFlag = containsAsyncRefine(rootSchema));
|
|
1669
|
+
asyncValidationFlag ?? (asyncValidationFlag = containsAsyncRefine(rootSchema) || containsAsyncTransform(rootSchema));
|
|
1543
1670
|
return asyncValidationFlag;
|
|
1544
1671
|
},
|
|
1545
1672
|
getDefaultValues(config) {
|
|
@@ -1550,8 +1677,12 @@ function zodV4Adapter(rootSchema) {
|
|
|
1550
1677
|
maxRecursionDepth
|
|
1551
1678
|
});
|
|
1552
1679
|
if (config.strict !== false) {
|
|
1680
|
+
if (containsAsyncTransform(rootSchema)) {
|
|
1681
|
+
return { data, errors: void 0, success: true, formKey };
|
|
1682
|
+
}
|
|
1683
|
+
const parseTarget = containsAsyncRefine(rootSchema) ? stripAsyncChecks(rootSchema) : rootSchema;
|
|
1553
1684
|
try {
|
|
1554
|
-
const strictResult =
|
|
1685
|
+
const strictResult = parseTarget.safeParse(
|
|
1555
1686
|
data
|
|
1556
1687
|
);
|
|
1557
1688
|
if (strictResult.success) {
|
|
@@ -1564,56 +1695,11 @@ function zodV4Adapter(rootSchema) {
|
|
|
1564
1695
|
formKey
|
|
1565
1696
|
};
|
|
1566
1697
|
} catch {
|
|
1567
|
-
|
|
1568
|
-
const syncOnly = stripAsyncChecks(rootSchema);
|
|
1569
|
-
const syncResult = syncOnly.safeParse(data);
|
|
1570
|
-
if (syncResult.success) {
|
|
1571
|
-
return { data, errors: void 0, success: true, formKey };
|
|
1572
|
-
}
|
|
1573
|
-
return {
|
|
1574
|
-
data,
|
|
1575
|
-
errors: zodIssuesToValidationErrors(syncResult.error.issues, formKey),
|
|
1576
|
-
success: false,
|
|
1577
|
-
formKey
|
|
1578
|
-
};
|
|
1579
|
-
} catch {
|
|
1580
|
-
return { data, errors: void 0, success: true, formKey };
|
|
1581
|
-
}
|
|
1698
|
+
return { data, errors: void 0, success: true, formKey };
|
|
1582
1699
|
}
|
|
1583
1700
|
}
|
|
1584
1701
|
return { data, errors: void 0, success: true, formKey };
|
|
1585
1702
|
},
|
|
1586
|
-
normalizeWriteValueAtPath(value, path) {
|
|
1587
|
-
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1588
|
-
const [first] = candidates;
|
|
1589
|
-
if (first === void 0) return value;
|
|
1590
|
-
let current = first;
|
|
1591
|
-
let result = value;
|
|
1592
|
-
for (let i = 0; i < 64; i++) {
|
|
1593
|
-
if (kindOf(current) !== "pipe") break;
|
|
1594
|
-
const pipeIn = unwrapPipeIn(current);
|
|
1595
|
-
if (pipeIn === void 0 || kindOf(pipeIn) !== "transform") break;
|
|
1596
|
-
const fn = readTransformFn(pipeIn);
|
|
1597
|
-
if (typeof fn !== "function") break;
|
|
1598
|
-
let next;
|
|
1599
|
-
try {
|
|
1600
|
-
next = fn(result);
|
|
1601
|
-
} catch (cause) {
|
|
1602
|
-
throw new Error(
|
|
1603
|
-
`[attaform] input normalization at path "${path.join(".")}" threw \u2014 write rejected.`,
|
|
1604
|
-
{ cause }
|
|
1605
|
-
);
|
|
1606
|
-
}
|
|
1607
|
-
if (next instanceof Promise) {
|
|
1608
|
-
return value;
|
|
1609
|
-
}
|
|
1610
|
-
result = next;
|
|
1611
|
-
const out = unwrapPipeOut(current);
|
|
1612
|
-
if (out === void 0) break;
|
|
1613
|
-
current = out;
|
|
1614
|
-
}
|
|
1615
|
-
return result;
|
|
1616
|
-
},
|
|
1617
1703
|
getDefaultAtPath(path) {
|
|
1618
1704
|
if (path.length === 0) return deriveDefault(rootSchema, true, maxRecursionDepth);
|
|
1619
1705
|
const [first] = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
@@ -1683,6 +1769,30 @@ function zodV4Adapter(rootSchema) {
|
|
|
1683
1769
|
leafCache.set(cacheKey, isLeaf);
|
|
1684
1770
|
return isLeaf;
|
|
1685
1771
|
},
|
|
1772
|
+
isPreprocessOrCoerceLeaf(path) {
|
|
1773
|
+
const cacheKey = canonicalizePath(path).key;
|
|
1774
|
+
const cached = preprocessOrCoerceCache.get(cacheKey);
|
|
1775
|
+
if (cached !== void 0) return cached;
|
|
1776
|
+
let hit = false;
|
|
1777
|
+
for (let i = 0; i <= path.length && !hit; i++) {
|
|
1778
|
+
const prefix = path.slice(0, i);
|
|
1779
|
+
const candidates = prefix.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, prefix, maxRecursionDepth);
|
|
1780
|
+
for (const candidate of candidates) {
|
|
1781
|
+
if (isCoercePrimitive(candidate)) {
|
|
1782
|
+
hit = true;
|
|
1783
|
+
break;
|
|
1784
|
+
}
|
|
1785
|
+
if (kindOf(candidate) !== "pipe") continue;
|
|
1786
|
+
const pipeIn = unwrapPipeIn(candidate);
|
|
1787
|
+
if (pipeIn !== void 0 && kindOf(pipeIn) === "transform") {
|
|
1788
|
+
hit = true;
|
|
1789
|
+
break;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
preprocessOrCoerceCache.set(cacheKey, hit);
|
|
1794
|
+
return hit;
|
|
1795
|
+
},
|
|
1686
1796
|
isRequiredAtPath(path) {
|
|
1687
1797
|
if (path.length === 0) return true;
|
|
1688
1798
|
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
@@ -1769,9 +1879,14 @@ function zodV4Adapter(rootSchema) {
|
|
|
1769
1879
|
}
|
|
1770
1880
|
async function runAsync() {
|
|
1771
1881
|
if (path === void 0) {
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1882
|
+
let result;
|
|
1883
|
+
try {
|
|
1884
|
+
result = await rootSchema.safeParseAsync(
|
|
1885
|
+
data
|
|
1886
|
+
);
|
|
1887
|
+
} catch (err) {
|
|
1888
|
+
return validatorThrewResponse(err, []);
|
|
1889
|
+
}
|
|
1775
1890
|
return result.success ? { data: result.data, errors: void 0, success: true, formKey } : {
|
|
1776
1891
|
data: void 0,
|
|
1777
1892
|
errors: zodIssuesToValidationErrors(result.error.issues, formKey),
|
|
@@ -1783,7 +1898,12 @@ function zodV4Adapter(rootSchema) {
|
|
|
1783
1898
|
if (resolved.length === 0) return pathNotFound(path);
|
|
1784
1899
|
const aggregated = [];
|
|
1785
1900
|
for (const candidate of resolved) {
|
|
1786
|
-
|
|
1901
|
+
let result;
|
|
1902
|
+
try {
|
|
1903
|
+
result = await candidate.safeParseAsync(data);
|
|
1904
|
+
} catch (err) {
|
|
1905
|
+
return validatorThrewResponse(err, path);
|
|
1906
|
+
}
|
|
1787
1907
|
if (result.success) {
|
|
1788
1908
|
return {
|
|
1789
1909
|
data: result.data,
|
|
@@ -1796,6 +1916,22 @@ function zodV4Adapter(rootSchema) {
|
|
|
1796
1916
|
}
|
|
1797
1917
|
return { data: void 0, errors: aggregated, success: false, formKey };
|
|
1798
1918
|
}
|
|
1919
|
+
function validatorThrewResponse(err, errPath) {
|
|
1920
|
+
const message = err instanceof Error ? err.message : typeof err === "string" ? err : "Validator threw";
|
|
1921
|
+
return {
|
|
1922
|
+
data: void 0,
|
|
1923
|
+
errors: [
|
|
1924
|
+
{
|
|
1925
|
+
message,
|
|
1926
|
+
path: [...errPath],
|
|
1927
|
+
formKey,
|
|
1928
|
+
code: AttaformErrorCode.ValidatorThrew
|
|
1929
|
+
}
|
|
1930
|
+
],
|
|
1931
|
+
success: false,
|
|
1932
|
+
formKey
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1799
1935
|
function pathNotFound(p) {
|
|
1800
1936
|
return {
|
|
1801
1937
|
data: void 0,
|
|
@@ -1969,6 +2105,7 @@ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress)
|
|
|
1969
2105
|
case "custom":
|
|
1970
2106
|
case "template-literal":
|
|
1971
2107
|
case "transform":
|
|
2108
|
+
case "file":
|
|
1972
2109
|
return;
|
|
1973
2110
|
}
|
|
1974
2111
|
} finally {
|
|
@@ -2027,4 +2164,4 @@ function useForm(configuration) {
|
|
|
2027
2164
|
}
|
|
2028
2165
|
|
|
2029
2166
|
export { UnsupportedSchemaError as U, assertZodVersion as a, fieldMeta as f, kindOf as k, useForm as u, withMeta as w, zodV4Adapter as z };
|
|
2030
|
-
//# sourceMappingURL=attaform.
|
|
2167
|
+
//# sourceMappingURL=attaform.Xt0A3QUd.mjs.map
|