attaform 0.27.5 → 0.28.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 -4
- package/dist/abstract.mjs +4 -3
- package/dist/chunks/fingerprint.mjs +0 -1
- package/dist/chunks/fingerprint2.mjs +1 -2
- package/dist/dev/abstract.mjs +4 -0
- package/dist/{chunks → dev/chunks}/dev-key-collision-warnings.mjs +0 -1
- package/dist/{chunks → dev/chunks}/devtools.mjs +5 -6
- package/dist/{chunks/fingerprint.cjs → dev/chunks/fingerprint.mjs} +7 -10
- package/dist/{chunks/fingerprint2.cjs → dev/chunks/fingerprint2.mjs} +32 -35
- package/dist/dev/directive.mjs +1 -0
- package/dist/dev/history.mjs +89 -0
- package/dist/dev/index.mjs +5 -0
- package/dist/dev/runtime/plugins/attaform.mjs +40 -0
- package/dist/{shared/attaform.f2zyNh5d.cjs → dev/shared/attaform-dev.6qxD-Yqo.mjs} +187 -43
- package/dist/{shared/attaform.CQN9R62B.cjs → dev/shared/attaform-dev.BJGA_UOS.mjs} +1 -4
- package/dist/{shared/attaform.Dc1mx48r.mjs → dev/shared/attaform-dev.BR8u0YOZ.mjs} +6 -7
- package/dist/dev/shared/attaform-dev.BXE2cr0L.mjs +220 -0
- package/dist/dev/shared/attaform-dev.By4PRjt0.mjs +248 -0
- package/dist/{shared/attaform.Cg_8gFQ7.mjs → dev/shared/attaform-dev.D2I8e_Mm.mjs} +132 -568
- package/dist/dev/shared/attaform-dev.Dr2YzS5B.mjs +197 -0
- package/dist/{shared/attaform.nMaz2C5P.mjs → dev/shared/attaform-dev.P7cseiEG.mjs} +178 -397
- package/dist/{shared/attaform.BypWgXRB.mjs → dev/shared/attaform-dev.WmuhD_CZ.mjs} +3955 -5029
- package/dist/{shared/attaform.Dkjh_F30.mjs → dev/shared/attaform-dev.oYrkP9dj.mjs} +160 -508
- package/dist/dev/zod-v3.mjs +17 -0
- package/dist/dev/zod-v4.mjs +16 -0
- package/dist/dev/zod.mjs +5 -0
- package/dist/directive.d.mts +20 -0
- package/dist/directive.mjs +1 -0
- package/dist/esbuild.mjs +0 -1
- package/dist/history.d.mts +59 -0
- package/dist/history.mjs +89 -0
- package/dist/index.d.mts +11 -5
- package/dist/index.mjs +5 -4
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.mjs +5 -2
- package/dist/rollup.mjs +0 -1
- package/dist/rspack.d.mts +6 -1
- package/dist/rspack.mjs +0 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +9 -8
- package/dist/runtime/plugins/attaform.mjs +1 -2
- package/dist/shared/{attaform.CIBMfxg9.d.ts → attaform.B4VkS43-.d.mts} +2 -2
- package/dist/shared/{attaform.Cg1rUfcF.cjs → attaform.B8k8JrmK.mjs} +3778 -5297
- package/dist/shared/attaform.BJGA_UOS.mjs +0 -1
- package/dist/shared/{attaform.CTiZ9Rrv.mjs → attaform.C09fpdLS.mjs} +172 -16
- package/dist/shared/{attaform.Bh8A6YAc.cjs → attaform.CJP3RkGa.mjs} +141 -590
- package/dist/shared/{attaform.CzL2CZ8U.d.ts → attaform.Cgu-hdSb.d.mts} +328 -78
- package/dist/shared/attaform.Cs2Rbdlo.mjs +0 -1
- package/dist/shared/{attaform.DcFDQVpa.d.ts → attaform.D5V4tZWq.d.mts} +79 -179
- package/dist/shared/{attaform.CF-EnyJn.cjs → attaform.D6DCnnQu.mjs} +11 -16
- package/dist/shared/attaform.DhnPb6nK.mjs +0 -1
- package/dist/shared/attaform.Dq4vWxuG.mjs +197 -0
- package/dist/shared/attaform.JfSWdEcb.d.mts +44 -0
- package/dist/shared/attaform.KvlEedlF.mjs +0 -1
- package/dist/shared/{attaform.Crv0RNiz.cjs → attaform.NLmerepI.mjs} +175 -557
- package/dist/shared/attaform.h0i6LijT.mjs +242 -0
- package/dist/shared/{attaform.Biytrv0-.cjs → attaform.uLbun31C.mjs} +204 -544
- package/dist/shared/attaform.v0fQtWyA.mjs +0 -1
- package/dist/shared/attaform.wfY8XFvm.mjs +197 -0
- package/dist/transforms.mjs +0 -1
- package/dist/vite.d.mts +17 -5
- package/dist/vite.mjs +24 -2
- package/dist/webpack.d.mts +6 -1
- package/dist/webpack.mjs +0 -1
- package/dist/zod-v3.d.mts +11 -6
- package/dist/zod-v3.mjs +17 -4
- package/dist/zod-v4.d.mts +12 -6
- package/dist/zod-v4.mjs +16 -4
- package/dist/zod.d.mts +4 -3
- package/dist/zod.mjs +5 -4
- package/package.json +23 -8
- package/skills/attaform/SKILL.md +2 -1
- package/dist/abstract.cjs +0 -48
- package/dist/abstract.cjs.map +0 -1
- package/dist/abstract.d.cts +0 -42
- package/dist/abstract.d.ts +0 -42
- package/dist/abstract.mjs.map +0 -1
- package/dist/chunks/dev-key-collision-warnings.cjs +0 -25
- package/dist/chunks/dev-key-collision-warnings.cjs.map +0 -1
- package/dist/chunks/dev-key-collision-warnings.mjs.map +0 -1
- package/dist/chunks/devtools.cjs +0 -157
- package/dist/chunks/devtools.cjs.map +0 -1
- package/dist/chunks/devtools.mjs.map +0 -1
- package/dist/chunks/fingerprint.cjs.map +0 -1
- package/dist/chunks/fingerprint.mjs.map +0 -1
- package/dist/chunks/fingerprint2.cjs.map +0 -1
- package/dist/chunks/fingerprint2.mjs.map +0 -1
- package/dist/esbuild.cjs +0 -28
- package/dist/esbuild.cjs.map +0 -1
- package/dist/esbuild.d.cts +0 -56
- package/dist/esbuild.d.ts +0 -56
- package/dist/esbuild.mjs.map +0 -1
- package/dist/index.cjs +0 -51
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -249
- package/dist/index.d.ts +0 -249
- package/dist/index.mjs.map +0 -1
- package/dist/nuxt.cjs +0 -84
- package/dist/nuxt.cjs.map +0 -1
- package/dist/nuxt.d.cts +0 -66
- package/dist/nuxt.d.ts +0 -66
- package/dist/nuxt.mjs.map +0 -1
- package/dist/rollup.cjs +0 -24
- package/dist/rollup.cjs.map +0 -1
- package/dist/rollup.d.cts +0 -35
- package/dist/rollup.d.ts +0 -35
- package/dist/rollup.mjs.map +0 -1
- package/dist/rspack.cjs +0 -10
- package/dist/rspack.cjs.map +0 -1
- package/dist/rspack.d.cts +0 -40
- package/dist/rspack.d.ts +0 -40
- package/dist/rspack.mjs.map +0 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue.d.ts +0 -7
- package/dist/runtime/components/DevtoolsValueTree.vue.d.ts +0 -35
- package/dist/runtime/plugins/attaform.cjs +0 -43
- package/dist/runtime/plugins/attaform.cjs.map +0 -1
- package/dist/runtime/plugins/attaform.d.cts +0 -5
- package/dist/runtime/plugins/attaform.d.ts +0 -5
- package/dist/runtime/plugins/attaform.mjs.map +0 -1
- package/dist/shared/attaform.B3abZaCV.d.cts +0 -2484
- package/dist/shared/attaform.BJGA_UOS.mjs.map +0 -1
- package/dist/shared/attaform.Bh8A6YAc.cjs.map +0 -1
- package/dist/shared/attaform.Biytrv0-.cjs.map +0 -1
- package/dist/shared/attaform.Bn0IzhD_.cjs +0 -800
- package/dist/shared/attaform.Bn0IzhD_.cjs.map +0 -1
- package/dist/shared/attaform.BypWgXRB.mjs.map +0 -1
- package/dist/shared/attaform.C9fPTxjB.d.cts +0 -41
- package/dist/shared/attaform.C9fPTxjB.d.ts +0 -41
- package/dist/shared/attaform.CF-EnyJn.cjs.map +0 -1
- package/dist/shared/attaform.CJ1Z9Mz4.d.mts +0 -2484
- package/dist/shared/attaform.CQN9R62B.cjs.map +0 -1
- package/dist/shared/attaform.CTiZ9Rrv.mjs.map +0 -1
- package/dist/shared/attaform.Cg1rUfcF.cjs.map +0 -1
- package/dist/shared/attaform.Cg_8gFQ7.mjs.map +0 -1
- package/dist/shared/attaform.Crv0RNiz.cjs.map +0 -1
- package/dist/shared/attaform.Cs2Rbdlo.mjs.map +0 -1
- package/dist/shared/attaform.CzL2CZ8U.d.cts +0 -4713
- package/dist/shared/attaform.CzL2CZ8U.d.mts +0 -4713
- package/dist/shared/attaform.DRUT703x.d.cts +0 -56
- package/dist/shared/attaform.DRUT703x.d.ts +0 -56
- package/dist/shared/attaform.DYwyM5Cp.d.cts +0 -232
- package/dist/shared/attaform.Dc1mx48r.mjs.map +0 -1
- package/dist/shared/attaform.DhnPb6nK.mjs.map +0 -1
- package/dist/shared/attaform.Dkjh_F30.mjs.map +0 -1
- package/dist/shared/attaform.DoQm_Vkd.cjs +0 -58
- package/dist/shared/attaform.DoQm_Vkd.cjs.map +0 -1
- package/dist/shared/attaform.DrHOqB-d.d.mts +0 -232
- package/dist/shared/attaform.KvlEedlF.mjs.map +0 -1
- package/dist/shared/attaform.RaTzp1WF.cjs +0 -26
- package/dist/shared/attaform.RaTzp1WF.cjs.map +0 -1
- package/dist/shared/attaform.f2zyNh5d.cjs.map +0 -1
- package/dist/shared/attaform.nMaz2C5P.mjs.map +0 -1
- package/dist/shared/attaform.v0fQtWyA.mjs.map +0 -1
- package/dist/shared/attaform.yUrz7C2z.cjs +0 -29
- package/dist/shared/attaform.yUrz7C2z.cjs.map +0 -1
- package/dist/transforms.cjs +0 -12
- package/dist/transforms.cjs.map +0 -1
- package/dist/transforms.d.cts +0 -73
- package/dist/transforms.d.ts +0 -73
- package/dist/transforms.mjs.map +0 -1
- package/dist/vite.cjs +0 -363
- package/dist/vite.cjs.map +0 -1
- package/dist/vite.d.cts +0 -133
- package/dist/vite.d.ts +0 -133
- package/dist/vite.mjs.map +0 -1
- package/dist/webpack.cjs +0 -10
- package/dist/webpack.cjs.map +0 -1
- package/dist/webpack.d.cts +0 -37
- package/dist/webpack.d.ts +0 -37
- package/dist/webpack.mjs.map +0 -1
- package/dist/zod-v3.cjs +0 -53
- package/dist/zod-v3.cjs.map +0 -1
- package/dist/zod-v3.d.cts +0 -246
- package/dist/zod-v3.d.ts +0 -246
- package/dist/zod-v3.mjs.map +0 -1
- package/dist/zod-v4.cjs +0 -55
- package/dist/zod-v4.cjs.map +0 -1
- package/dist/zod-v4.d.cts +0 -172
- package/dist/zod-v4.d.ts +0 -172
- package/dist/zod-v4.mjs.map +0 -1
- package/dist/zod.cjs +0 -51
- package/dist/zod.cjs.map +0 -1
- package/dist/zod.d.cts +0 -7
- package/dist/zod.d.ts +0 -7
- package/dist/zod.mjs.map +0 -1
|
@@ -1,38 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { o as humanize, h as useAbstractForm } from './attaform.B8k8JrmK.mjs';
|
|
2
|
+
import { A as AttaformError, e as canonicalizePath, a as InvalidUseFormConfigError } from './attaform.wfY8XFvm.mjs';
|
|
3
|
+
import { s as slimPrimitivesWalk, d as deriveDefaultWalk, m as mergeDeep, f as fixStructuralDefaults, w as walkPathSegments, c as createAbstractSchema, b as buildFieldMetaPathMap, a as getFieldMetaListForSchema, g as getFieldMetaForSchema } from './attaform.C09fpdLS.mjs';
|
|
4
|
+
import { z } from 'zod';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
const devtoolsShared = require('./attaform.Biytrv0-.cjs');
|
|
5
|
-
const walkFieldMeta = require('./attaform.f2zyNh5d.cjs');
|
|
6
|
-
const zod = require('zod');
|
|
7
|
-
|
|
8
|
-
const fieldMeta = walkFieldMeta.fieldMetaStore;
|
|
9
|
-
function getFieldMetaList(schema) {
|
|
10
|
-
return walkFieldMeta.getFieldMetaListForSchema(schema);
|
|
11
|
-
}
|
|
12
|
-
function withMeta(schema, payload) {
|
|
13
|
-
const existing = walkFieldMeta.getFieldMetaForSchema(schema) ?? {};
|
|
14
|
-
const cloned = schema.clone();
|
|
15
|
-
walkFieldMeta.fieldMetaStore.add(cloned, { ...existing, ...payload });
|
|
16
|
-
return cloned;
|
|
17
|
-
}
|
|
18
|
-
function getFieldMeta(schema) {
|
|
19
|
-
return walkFieldMeta.getFieldMetaForSchema(schema);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let warnedZodCodeMissing = false;
|
|
23
|
-
function zodIssuesToValidationErrors(issues, formKey) {
|
|
6
|
+
function zodIssuesToValidationErrors(issues) {
|
|
24
7
|
return issues.map((issue) => {
|
|
25
8
|
let code;
|
|
26
9
|
if (typeof issue.code === "string" && issue.code.length > 0) {
|
|
27
10
|
code = `zod:${issue.code}`;
|
|
28
11
|
} else {
|
|
29
12
|
code = "zod:unknown";
|
|
30
|
-
if (devtoolsShared.__DEV__ && !warnedZodCodeMissing) {
|
|
31
|
-
warnedZodCodeMissing = true;
|
|
32
|
-
console.warn(
|
|
33
|
-
"[attaform] zod-v4 adapter received an issue with no string `code`; stamping `'zod:unknown'`. This usually means a custom Zod plugin emitted an issue without the standard code field."
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
13
|
}
|
|
37
14
|
return {
|
|
38
15
|
message: issue.message,
|
|
@@ -41,101 +18,70 @@ function zodIssuesToValidationErrors(issues, formKey) {
|
|
|
41
18
|
// to absolutise, then routes form-level (absolute path length 0)
|
|
42
19
|
// entries to the empty-string bucket at storage time.
|
|
43
20
|
path: issue.path.map((seg) => typeof seg === "number" ? seg : String(seg)),
|
|
44
|
-
formKey,
|
|
45
21
|
code
|
|
46
22
|
};
|
|
47
23
|
});
|
|
48
24
|
}
|
|
49
|
-
class UnsupportedSchemaError extends
|
|
25
|
+
class UnsupportedSchemaError extends AttaformError {
|
|
50
26
|
}
|
|
51
27
|
|
|
52
28
|
function readDef(schema) {
|
|
53
29
|
if (schema === null || typeof schema !== "object") return void 0;
|
|
54
30
|
return schema.def;
|
|
55
31
|
}
|
|
32
|
+
const KIND_ALIAS = /* @__PURE__ */ new Map([
|
|
33
|
+
["discriminated_union", "discriminated-union"],
|
|
34
|
+
["discriminatedUnion", "discriminated-union"],
|
|
35
|
+
["prefault", "default"],
|
|
36
|
+
["template_literal", "template-literal"],
|
|
37
|
+
["templateLiteral", "template-literal"]
|
|
38
|
+
]);
|
|
39
|
+
const IDENTITY_KINDS = /* @__PURE__ */ new Set([
|
|
40
|
+
"object",
|
|
41
|
+
"array",
|
|
42
|
+
"set",
|
|
43
|
+
"record",
|
|
44
|
+
"tuple",
|
|
45
|
+
"string",
|
|
46
|
+
"number",
|
|
47
|
+
"boolean",
|
|
48
|
+
"bigint",
|
|
49
|
+
"date",
|
|
50
|
+
"enum",
|
|
51
|
+
"literal",
|
|
52
|
+
"null",
|
|
53
|
+
"undefined",
|
|
54
|
+
"any",
|
|
55
|
+
"unknown",
|
|
56
|
+
"optional",
|
|
57
|
+
"nullable",
|
|
58
|
+
"default",
|
|
59
|
+
"pipe",
|
|
60
|
+
"readonly",
|
|
61
|
+
"nan",
|
|
62
|
+
"void",
|
|
63
|
+
"never",
|
|
64
|
+
"lazy",
|
|
65
|
+
"intersection",
|
|
66
|
+
"catch",
|
|
67
|
+
"promise",
|
|
68
|
+
"custom",
|
|
69
|
+
"transform",
|
|
70
|
+
"file",
|
|
71
|
+
"map",
|
|
72
|
+
"symbol",
|
|
73
|
+
"function"
|
|
74
|
+
]);
|
|
56
75
|
function kindOf(schema) {
|
|
57
76
|
const def = readDef(schema);
|
|
58
77
|
const rawType = def?.type;
|
|
59
78
|
if (rawType === void 0) return "unknown";
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return "object";
|
|
63
|
-
case "array":
|
|
64
|
-
return "array";
|
|
65
|
-
case "set":
|
|
66
|
-
return "set";
|
|
67
|
-
case "record":
|
|
68
|
-
return "record";
|
|
69
|
-
case "tuple":
|
|
70
|
-
return "tuple";
|
|
71
|
-
case "union":
|
|
72
|
-
return def?.discriminator !== void 0 ? "discriminated-union" : "union";
|
|
73
|
-
case "discriminated_union":
|
|
74
|
-
case "discriminatedUnion":
|
|
75
|
-
return "discriminated-union";
|
|
76
|
-
case "string":
|
|
77
|
-
return "string";
|
|
78
|
-
case "number":
|
|
79
|
-
return "number";
|
|
80
|
-
case "boolean":
|
|
81
|
-
return "boolean";
|
|
82
|
-
case "bigint":
|
|
83
|
-
return "bigint";
|
|
84
|
-
case "date":
|
|
85
|
-
return "date";
|
|
86
|
-
case "enum":
|
|
87
|
-
return "enum";
|
|
88
|
-
case "literal":
|
|
89
|
-
return "literal";
|
|
90
|
-
case "null":
|
|
91
|
-
return "null";
|
|
92
|
-
case "undefined":
|
|
93
|
-
return "undefined";
|
|
94
|
-
case "optional":
|
|
95
|
-
return "optional";
|
|
96
|
-
case "nullable":
|
|
97
|
-
return "nullable";
|
|
98
|
-
case "default":
|
|
99
|
-
case "prefault":
|
|
100
|
-
return "default";
|
|
101
|
-
case "pipe":
|
|
102
|
-
return "pipe";
|
|
103
|
-
case "readonly":
|
|
104
|
-
return "readonly";
|
|
105
|
-
case "any":
|
|
106
|
-
return "any";
|
|
107
|
-
case "nan":
|
|
108
|
-
return "nan";
|
|
109
|
-
case "void":
|
|
110
|
-
return "void";
|
|
111
|
-
case "never":
|
|
112
|
-
return "never";
|
|
113
|
-
case "lazy":
|
|
114
|
-
return "lazy";
|
|
115
|
-
case "intersection":
|
|
116
|
-
return "intersection";
|
|
117
|
-
case "catch":
|
|
118
|
-
return "catch";
|
|
119
|
-
case "transform":
|
|
120
|
-
return "transform";
|
|
121
|
-
case "promise":
|
|
122
|
-
return "promise";
|
|
123
|
-
case "custom":
|
|
124
|
-
return "custom";
|
|
125
|
-
case "template_literal":
|
|
126
|
-
case "templateLiteral":
|
|
127
|
-
return "template-literal";
|
|
128
|
-
case "file":
|
|
129
|
-
return "file";
|
|
130
|
-
case "map":
|
|
131
|
-
return "map";
|
|
132
|
-
case "symbol":
|
|
133
|
-
return "symbol";
|
|
134
|
-
case "function":
|
|
135
|
-
return "function";
|
|
136
|
-
default:
|
|
137
|
-
return "unknown";
|
|
79
|
+
if (rawType === "union") {
|
|
80
|
+
return def?.discriminator !== void 0 ? "discriminated-union" : "union";
|
|
138
81
|
}
|
|
82
|
+
const alias = KIND_ALIAS.get(rawType);
|
|
83
|
+
if (alias !== void 0) return alias;
|
|
84
|
+
return IDENTITY_KINDS.has(rawType) ? rawType : "unknown";
|
|
139
85
|
}
|
|
140
86
|
function getObjectShape(schema) {
|
|
141
87
|
const s = schema;
|
|
@@ -267,10 +213,22 @@ function assertZodVersion(schema) {
|
|
|
267
213
|
const def = readDef(schema);
|
|
268
214
|
if (def?.type === void 0) {
|
|
269
215
|
throw new Error(
|
|
270
|
-
"[attaform
|
|
216
|
+
"[attaform] AF01 attaform.dev/e/af01"
|
|
271
217
|
);
|
|
272
218
|
}
|
|
273
219
|
}
|
|
220
|
+
const DESCEND_SINGLE = [
|
|
221
|
+
"innerType",
|
|
222
|
+
"element",
|
|
223
|
+
"in",
|
|
224
|
+
"out",
|
|
225
|
+
"left",
|
|
226
|
+
"right",
|
|
227
|
+
"keyType",
|
|
228
|
+
"valueType"
|
|
229
|
+
];
|
|
230
|
+
const DESCEND_RECORD = ["shape", "entries"];
|
|
231
|
+
const DESCEND_LIST = ["options", "items"];
|
|
274
232
|
function walkSchemaTree(schema, visit, seen) {
|
|
275
233
|
const visited = seen ?? /* @__PURE__ */ new WeakSet();
|
|
276
234
|
const candidate = schema;
|
|
@@ -280,40 +238,25 @@ function walkSchemaTree(schema, visit, seen) {
|
|
|
280
238
|
if (visit(schema)) return true;
|
|
281
239
|
const def = readDef(schema);
|
|
282
240
|
if (def === void 0) return false;
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
if (def.valueType !== void 0 && walkSchemaTree(def.valueType, visit, visited)) {
|
|
297
|
-
return true;
|
|
298
|
-
}
|
|
299
|
-
if (def.shape !== void 0) {
|
|
300
|
-
for (const sub of Object.values(def.shape)) {
|
|
301
|
-
if (walkSchemaTree(sub, visit, visited)) return true;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
if (def.entries !== void 0) {
|
|
305
|
-
for (const sub of Object.values(def.entries)) {
|
|
306
|
-
if (walkSchemaTree(sub, visit, visited)) return true;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
if (def.options !== void 0) {
|
|
310
|
-
for (const sub of def.options) {
|
|
311
|
-
if (walkSchemaTree(sub, visit, visited)) return true;
|
|
241
|
+
const slots = def;
|
|
242
|
+
for (const key of DESCEND_SINGLE) {
|
|
243
|
+
const child = slots[key];
|
|
244
|
+
if (child !== void 0 && walkSchemaTree(child, visit, visited)) return true;
|
|
245
|
+
}
|
|
246
|
+
for (const key of DESCEND_RECORD) {
|
|
247
|
+
const record = slots[key];
|
|
248
|
+
if (record !== void 0) {
|
|
249
|
+
for (const sub of Object.values(record)) {
|
|
250
|
+
if (walkSchemaTree(sub, visit, visited)) return true;
|
|
251
|
+
}
|
|
312
252
|
}
|
|
313
253
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
254
|
+
for (const key of DESCEND_LIST) {
|
|
255
|
+
const list = slots[key];
|
|
256
|
+
if (list !== void 0) {
|
|
257
|
+
for (const sub of list) {
|
|
258
|
+
if (walkSchemaTree(sub, visit, visited)) return true;
|
|
259
|
+
}
|
|
317
260
|
}
|
|
318
261
|
}
|
|
319
262
|
if (typeof def.getter === "function") {
|
|
@@ -325,6 +268,9 @@ function walkSchemaTree(schema, visit, seen) {
|
|
|
325
268
|
}
|
|
326
269
|
return false;
|
|
327
270
|
}
|
|
271
|
+
function containsDiscriminatedUnion(schema, seen) {
|
|
272
|
+
return walkSchemaTree(schema, (node) => kindOf(node) === "discriminated-union", seen);
|
|
273
|
+
}
|
|
328
274
|
function containsAsyncRefine(schema, seen) {
|
|
329
275
|
return walkSchemaTree(
|
|
330
276
|
schema,
|
|
@@ -337,14 +283,25 @@ function containsAsyncRefine(schema, seen) {
|
|
|
337
283
|
seen
|
|
338
284
|
);
|
|
339
285
|
}
|
|
286
|
+
const CONTAINER_SLOTS = [
|
|
287
|
+
"shape",
|
|
288
|
+
"entries",
|
|
289
|
+
"element",
|
|
290
|
+
"options",
|
|
291
|
+
"items",
|
|
292
|
+
"keyType",
|
|
293
|
+
"valueType",
|
|
294
|
+
"left",
|
|
295
|
+
"right"
|
|
296
|
+
];
|
|
340
297
|
function hasContainerOrRootRefine(schema, seen) {
|
|
341
298
|
return walkSchemaTree(
|
|
342
299
|
schema,
|
|
343
300
|
(node) => {
|
|
344
301
|
const def = readDef(node);
|
|
345
302
|
if (def === void 0) return false;
|
|
346
|
-
const
|
|
347
|
-
if (!
|
|
303
|
+
const slots = def;
|
|
304
|
+
if (!CONTAINER_SLOTS.some((key) => slots[key] !== void 0)) return false;
|
|
348
305
|
return getChecks(node).length > 0;
|
|
349
306
|
},
|
|
350
307
|
seen
|
|
@@ -386,7 +343,7 @@ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
|
386
343
|
const kind = kindOf(schema);
|
|
387
344
|
if (UNSUPPORTED.includes(kind)) {
|
|
388
345
|
throw new UnsupportedSchemaError(
|
|
389
|
-
`[attaform
|
|
346
|
+
`[attaform] AF02 attaform.dev/e/af02 '${kind}' at '${labelPath(path)}'`
|
|
390
347
|
);
|
|
391
348
|
}
|
|
392
349
|
switch (kind) {
|
|
@@ -481,7 +438,9 @@ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
|
481
438
|
return;
|
|
482
439
|
default: {
|
|
483
440
|
const _exhaustive = kind;
|
|
484
|
-
throw new Error(
|
|
441
|
+
throw new Error(
|
|
442
|
+
`[attaform] AF03 attaform.dev/e/af03 '${_exhaustive}'`
|
|
443
|
+
);
|
|
485
444
|
}
|
|
486
445
|
}
|
|
487
446
|
}
|
|
@@ -511,10 +470,6 @@ function unwrapToDiscriminatedUnion(schema) {
|
|
|
511
470
|
}
|
|
512
471
|
return void 0;
|
|
513
472
|
}
|
|
514
|
-
function getDiscriminatedUnionFirstOption(schema) {
|
|
515
|
-
const options = getDiscriminatedOptions(schema);
|
|
516
|
-
return options[0];
|
|
517
|
-
}
|
|
518
473
|
|
|
519
474
|
const V4_INTROSPECTOR = {
|
|
520
475
|
kindOf: (schema) => kindOf(schema),
|
|
@@ -527,6 +482,7 @@ const V4_INTROSPECTOR = {
|
|
|
527
482
|
isCoercePrimitive,
|
|
528
483
|
containsAsyncRefine,
|
|
529
484
|
containsAsyncTransform,
|
|
485
|
+
containsDiscriminatedUnion,
|
|
530
486
|
hasContainerOrRootRefine,
|
|
531
487
|
// Walker accessors (D2 / D3 / D5).
|
|
532
488
|
getArrayElement: (schema) => {
|
|
@@ -554,17 +510,42 @@ const V4_INTROSPECTOR = {
|
|
|
554
510
|
};
|
|
555
511
|
|
|
556
512
|
function slimPrimitivesOf(schema, maxRecursionDepth) {
|
|
557
|
-
return new Set(
|
|
513
|
+
return new Set(slimPrimitivesWalk(schema, V4_INTROSPECTOR, maxRecursionDepth));
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
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
|
+
});
|
|
522
|
+
}
|
|
523
|
+
function getDefaultValuesFromZodSchema(opts) {
|
|
524
|
+
const { schema, useDefaultSchemaValues, constraints, maxRecursionDepth } = opts;
|
|
525
|
+
const initial = deriveDefault(schema, useDefaultSchemaValues, maxRecursionDepth);
|
|
526
|
+
const merged = mergeDeep(initial, constraints);
|
|
527
|
+
return fixStructuralDefaults(
|
|
528
|
+
schema,
|
|
529
|
+
merged,
|
|
530
|
+
useDefaultSchemaValues,
|
|
531
|
+
maxRecursionDepth,
|
|
532
|
+
{
|
|
533
|
+
intro: V4_INTROSPECTOR,
|
|
534
|
+
slimPrimitivesOf: (s) => slimPrimitivesOf(s, maxRecursionDepth),
|
|
535
|
+
deriveDefault: (s, useDefault) => deriveDefault(s, useDefault, maxRecursionDepth),
|
|
536
|
+
unwrapToDiscriminatedUnion
|
|
537
|
+
}
|
|
538
|
+
);
|
|
558
539
|
}
|
|
559
540
|
|
|
560
541
|
const PATH_SEPARATOR = ".";
|
|
561
542
|
function getNestedZodSchemasAtPath(schema, path, maxRecursionDepth) {
|
|
562
543
|
if (Array.isArray(path)) {
|
|
563
|
-
return
|
|
544
|
+
return walkPathSegments(schema, path.map(String), V4_INTROSPECTOR, maxRecursionDepth, 0);
|
|
564
545
|
}
|
|
565
546
|
const pathString = path;
|
|
566
547
|
if (pathString.length === 0) return [schema];
|
|
567
|
-
return
|
|
548
|
+
return walkPathSegments(
|
|
568
549
|
schema,
|
|
569
550
|
pathString.split(PATH_SEPARATOR),
|
|
570
551
|
V4_INTROSPECTOR,
|
|
@@ -573,127 +554,15 @@ function getNestedZodSchemasAtPath(schema, path, maxRecursionDepth) {
|
|
|
573
554
|
);
|
|
574
555
|
}
|
|
575
556
|
|
|
576
|
-
function
|
|
577
|
-
if (stripConfig.stripRefinements === true) return rebuilt;
|
|
557
|
+
function carrySyncChecks(rebuilt, original) {
|
|
578
558
|
if (!hasChecks(original)) return rebuilt;
|
|
579
|
-
const
|
|
580
|
-
const checks = stripConfig.shouldKeepCheck === void 0 ? all : all.filter(stripConfig.shouldKeepCheck);
|
|
559
|
+
const checks = getChecks(original).filter((c) => !isAsyncCheck(c));
|
|
581
560
|
if (checks.length === 0) return rebuilt;
|
|
582
561
|
return rebuilt.check(
|
|
583
562
|
...checks
|
|
584
563
|
);
|
|
585
564
|
}
|
|
586
|
-
function unhandledZodKind(fnName, kind) {
|
|
587
|
-
throw new Error(`${fnName}: unhandled ZodKind '${kind}'`);
|
|
588
|
-
}
|
|
589
|
-
function stripRefinements(schema) {
|
|
590
|
-
const kind = kindOf(schema);
|
|
591
|
-
switch (kind) {
|
|
592
|
-
case "string":
|
|
593
|
-
return hasChecks(schema) ? zod.z.string() : schema;
|
|
594
|
-
case "number":
|
|
595
|
-
return hasChecks(schema) ? zod.z.number() : schema;
|
|
596
|
-
case "bigint":
|
|
597
|
-
return hasChecks(schema) ? zod.z.bigint() : schema;
|
|
598
|
-
case "array": {
|
|
599
|
-
const element = getArrayElement(schema);
|
|
600
|
-
return zod.z.array(stripRefinements(element));
|
|
601
|
-
}
|
|
602
|
-
case "set": {
|
|
603
|
-
const valueType = getSetValueType(schema);
|
|
604
|
-
return zod.z.set(stripRefinements(valueType));
|
|
605
|
-
}
|
|
606
|
-
case "tuple": {
|
|
607
|
-
const items = getTupleItems(schema).map(stripRefinements);
|
|
608
|
-
return zod.z.tuple(items);
|
|
609
|
-
}
|
|
610
|
-
case "object": {
|
|
611
|
-
const shape = getObjectShape(schema);
|
|
612
|
-
const next = {};
|
|
613
|
-
for (const [k, v] of Object.entries(shape)) {
|
|
614
|
-
next[k] = stripRefinements(v);
|
|
615
|
-
}
|
|
616
|
-
return zod.z.object(next);
|
|
617
|
-
}
|
|
618
|
-
case "record": {
|
|
619
|
-
const keyType = getRecordKeyType(
|
|
620
|
-
schema
|
|
621
|
-
);
|
|
622
|
-
const valueType = stripRefinements(getRecordValueType(schema));
|
|
623
|
-
return zod.z.record(keyType, valueType);
|
|
624
|
-
}
|
|
625
|
-
case "union": {
|
|
626
|
-
const options = getUnionOptions(schema).map(stripRefinements);
|
|
627
|
-
return zod.z.union(options);
|
|
628
|
-
}
|
|
629
|
-
case "discriminated-union": {
|
|
630
|
-
const options = getDiscriminatedOptions(schema).map(
|
|
631
|
-
(opt) => stripRefinements(opt)
|
|
632
|
-
);
|
|
633
|
-
const discriminator = getDiscriminator(schema);
|
|
634
|
-
if (discriminator === void 0) return schema;
|
|
635
|
-
return zod.z.discriminatedUnion(
|
|
636
|
-
discriminator,
|
|
637
|
-
options
|
|
638
|
-
);
|
|
639
|
-
}
|
|
640
|
-
// Wrappers: strip the inner, preserve the wrapper semantics where
|
|
641
|
-
// possible. For stripping refinements we typically want wrappers to
|
|
642
|
-
// survive (optional/nullable/default), so leave them alone.
|
|
643
|
-
case "optional":
|
|
644
|
-
case "nullable":
|
|
645
|
-
case "default":
|
|
646
|
-
case "readonly":
|
|
647
|
-
case "pipe":
|
|
648
|
-
return schema;
|
|
649
|
-
case "lazy": {
|
|
650
|
-
const inner = unwrapLazy(schema);
|
|
651
|
-
if (inner === void 0) return schema;
|
|
652
|
-
const slimmedInner = stripRefinements(inner);
|
|
653
|
-
return zod.z.lazy(() => slimmedInner);
|
|
654
|
-
}
|
|
655
|
-
case "intersection": {
|
|
656
|
-
const left = getIntersectionLeft(schema);
|
|
657
|
-
const right = getIntersectionRight(schema);
|
|
658
|
-
if (left === void 0 || right === void 0) return schema;
|
|
659
|
-
return zod.z.intersection(stripRefinements(left), stripRefinements(right));
|
|
660
|
-
}
|
|
661
|
-
case "catch": {
|
|
662
|
-
const inner = unwrapInner(schema);
|
|
663
|
-
if (inner === void 0) return schema;
|
|
664
|
-
const slimmedInner = stripRefinements(inner);
|
|
665
|
-
return slimmedInner.catch(getCatchDefault(schema));
|
|
666
|
-
}
|
|
667
|
-
// Leaf types without refinements, or Zod features we don't rewrite.
|
|
668
|
-
case "boolean":
|
|
669
|
-
case "date":
|
|
670
|
-
case "enum":
|
|
671
|
-
case "literal":
|
|
672
|
-
case "null":
|
|
673
|
-
case "undefined":
|
|
674
|
-
case "any":
|
|
675
|
-
case "unknown":
|
|
676
|
-
case "nan":
|
|
677
|
-
case "void":
|
|
678
|
-
case "never":
|
|
679
|
-
case "promise":
|
|
680
|
-
case "custom":
|
|
681
|
-
case "template-literal":
|
|
682
|
-
case "transform":
|
|
683
|
-
case "file":
|
|
684
|
-
case "map":
|
|
685
|
-
case "symbol":
|
|
686
|
-
case "function":
|
|
687
|
-
return schema;
|
|
688
|
-
default:
|
|
689
|
-
return unhandledZodKind("stripRefinements", kind);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
565
|
function stripAsyncChecks(schema) {
|
|
693
|
-
const config = {
|
|
694
|
-
stripRefinements: false,
|
|
695
|
-
shouldKeepCheck: (c) => !isAsyncCheck(c)
|
|
696
|
-
};
|
|
697
566
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
698
567
|
function recurse(s) {
|
|
699
568
|
if (seen.has(s)) return s;
|
|
@@ -701,25 +570,24 @@ function stripAsyncChecks(schema) {
|
|
|
701
570
|
const kind = kindOf(s);
|
|
702
571
|
switch (kind) {
|
|
703
572
|
case "string":
|
|
704
|
-
return hasChecks(s) ?
|
|
573
|
+
return hasChecks(s) ? carrySyncChecks(z.string(), s) : s;
|
|
705
574
|
case "number":
|
|
706
|
-
return hasChecks(s) ?
|
|
575
|
+
return hasChecks(s) ? carrySyncChecks(z.number(), s) : s;
|
|
707
576
|
case "bigint":
|
|
708
|
-
return hasChecks(s) ?
|
|
577
|
+
return hasChecks(s) ? carrySyncChecks(z.bigint(), s) : s;
|
|
709
578
|
case "array": {
|
|
710
579
|
const element = getArrayElement(s);
|
|
711
|
-
return
|
|
580
|
+
return carrySyncChecks(z.array(recurse(element)), s);
|
|
712
581
|
}
|
|
713
582
|
case "set": {
|
|
714
|
-
|
|
715
|
-
return carryChecks(zod.z.set(recurse(valueType)), s, config);
|
|
583
|
+
return carrySyncChecks(z.set(recurse(getSetValueType(s))), s);
|
|
716
584
|
}
|
|
717
585
|
case "tuple": {
|
|
718
586
|
const items = getTupleItems(s).map(recurse);
|
|
719
|
-
const rebuilt =
|
|
587
|
+
const rebuilt = z.tuple(
|
|
720
588
|
items
|
|
721
589
|
);
|
|
722
|
-
return
|
|
590
|
+
return carrySyncChecks(rebuilt, s);
|
|
723
591
|
}
|
|
724
592
|
case "object": {
|
|
725
593
|
const shape = getObjectShape(s);
|
|
@@ -727,39 +595,39 @@ function stripAsyncChecks(schema) {
|
|
|
727
595
|
for (const [k, v] of Object.entries(shape)) {
|
|
728
596
|
next[k] = recurse(v);
|
|
729
597
|
}
|
|
730
|
-
return
|
|
598
|
+
return carrySyncChecks(z.object(next), s);
|
|
731
599
|
}
|
|
732
600
|
case "record": {
|
|
733
601
|
const keyType = getRecordKeyType(s);
|
|
734
602
|
const valueType = recurse(getRecordValueType(s));
|
|
735
|
-
|
|
736
|
-
|
|
603
|
+
return carrySyncChecks(
|
|
604
|
+
z.record(keyType, valueType),
|
|
605
|
+
s
|
|
606
|
+
);
|
|
737
607
|
}
|
|
738
608
|
case "union": {
|
|
739
609
|
const options = getUnionOptions(s).map(recurse);
|
|
740
|
-
|
|
741
|
-
options
|
|
610
|
+
return carrySyncChecks(
|
|
611
|
+
z.union(options),
|
|
612
|
+
s
|
|
742
613
|
);
|
|
743
|
-
return carryChecks(rebuilt, s, config);
|
|
744
614
|
}
|
|
745
615
|
case "discriminated-union": {
|
|
746
616
|
const options = getDiscriminatedOptions(s).map((opt) => recurse(opt));
|
|
747
617
|
const discriminator = getDiscriminator(s);
|
|
748
618
|
if (discriminator === void 0) return s;
|
|
749
|
-
return
|
|
619
|
+
return z.discriminatedUnion(
|
|
750
620
|
discriminator,
|
|
751
621
|
options
|
|
752
622
|
);
|
|
753
623
|
}
|
|
754
624
|
case "optional": {
|
|
755
625
|
const inner = unwrapInner(s);
|
|
756
|
-
|
|
757
|
-
return recurse(inner).optional();
|
|
626
|
+
return inner === void 0 ? s : recurse(inner).optional();
|
|
758
627
|
}
|
|
759
628
|
case "nullable": {
|
|
760
629
|
const inner = unwrapInner(s);
|
|
761
|
-
|
|
762
|
-
return recurse(inner).nullable();
|
|
630
|
+
return inner === void 0 ? s : recurse(inner).nullable();
|
|
763
631
|
}
|
|
764
632
|
case "default": {
|
|
765
633
|
const inner = unwrapInner(s);
|
|
@@ -768,29 +636,30 @@ function stripAsyncChecks(schema) {
|
|
|
768
636
|
}
|
|
769
637
|
case "readonly": {
|
|
770
638
|
const inner = unwrapInner(s);
|
|
771
|
-
|
|
772
|
-
return recurse(inner).readonly();
|
|
639
|
+
return inner === void 0 ? s : recurse(inner).readonly();
|
|
773
640
|
}
|
|
774
|
-
case "pipe":
|
|
775
|
-
return s;
|
|
776
641
|
case "lazy": {
|
|
777
642
|
const inner = unwrapLazy(s);
|
|
778
643
|
if (inner === void 0) return s;
|
|
779
644
|
const stripped = recurse(inner);
|
|
780
|
-
return
|
|
645
|
+
return z.lazy(() => stripped);
|
|
781
646
|
}
|
|
782
647
|
case "intersection": {
|
|
783
648
|
const left = getIntersectionLeft(s);
|
|
784
649
|
const right = getIntersectionRight(s);
|
|
785
650
|
if (left === void 0 || right === void 0) return s;
|
|
786
|
-
return
|
|
651
|
+
return z.intersection(recurse(left), recurse(right));
|
|
787
652
|
}
|
|
788
653
|
case "catch": {
|
|
789
654
|
const inner = unwrapInner(s);
|
|
790
655
|
if (inner === void 0) return s;
|
|
791
656
|
return recurse(inner).catch(getCatchDefault(s));
|
|
792
657
|
}
|
|
793
|
-
//
|
|
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":
|
|
794
663
|
case "boolean":
|
|
795
664
|
case "date":
|
|
796
665
|
case "enum":
|
|
@@ -811,235 +680,10 @@ function stripAsyncChecks(schema) {
|
|
|
811
680
|
case "symbol":
|
|
812
681
|
case "function":
|
|
813
682
|
return s;
|
|
814
|
-
default:
|
|
815
|
-
return unhandledZodKind("stripAsyncChecks", kind);
|
|
816
683
|
}
|
|
817
684
|
}
|
|
818
685
|
return recurse(schema);
|
|
819
686
|
}
|
|
820
|
-
function getSlimSchema(schema, stripConfig, maxRecursionDepth) {
|
|
821
|
-
return walkSlim(schema, stripConfig, maxRecursionDepth, 0);
|
|
822
|
-
}
|
|
823
|
-
function walkSlim(schema, stripConfig, maxDepth, lazyDepth) {
|
|
824
|
-
const kind = kindOf(schema);
|
|
825
|
-
switch (kind) {
|
|
826
|
-
case "optional": {
|
|
827
|
-
const inner = unwrapInner(schema) ?? schema;
|
|
828
|
-
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
829
|
-
return stripConfig.stripOptional === true ? slimmedInner : slimmedInner.optional();
|
|
830
|
-
}
|
|
831
|
-
case "nullable": {
|
|
832
|
-
const inner = unwrapInner(schema) ?? schema;
|
|
833
|
-
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
834
|
-
return stripConfig.stripNullable === true ? slimmedInner : slimmedInner.nullable();
|
|
835
|
-
}
|
|
836
|
-
case "default": {
|
|
837
|
-
const inner = unwrapInner(schema) ?? schema;
|
|
838
|
-
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
839
|
-
if (stripConfig.stripDefaultValues === true) return slimmedInner;
|
|
840
|
-
const defaultValue = getDefaultValue(schema);
|
|
841
|
-
return slimmedInner.default(defaultValue);
|
|
842
|
-
}
|
|
843
|
-
case "readonly": {
|
|
844
|
-
const inner = unwrapInner(schema);
|
|
845
|
-
return inner === void 0 ? schema : walkSlim(inner, stripConfig, maxDepth, lazyDepth).readonly();
|
|
846
|
-
}
|
|
847
|
-
case "pipe": {
|
|
848
|
-
if (stripConfig.stripPipe === true) {
|
|
849
|
-
const pipeIn = unwrapPipeIn(schema);
|
|
850
|
-
const pipeOut = unwrapPipeOut(schema);
|
|
851
|
-
const real = pipeIn !== void 0 && kindOf(pipeIn) !== "transform" ? pipeIn : pipeOut !== void 0 && kindOf(pipeOut) !== "transform" ? pipeOut : pipeIn ?? pipeOut ?? schema;
|
|
852
|
-
return walkSlim(real, stripConfig, maxDepth, lazyDepth);
|
|
853
|
-
}
|
|
854
|
-
return schema;
|
|
855
|
-
}
|
|
856
|
-
case "object": {
|
|
857
|
-
const shape = getObjectShape(schema);
|
|
858
|
-
const next = {};
|
|
859
|
-
for (const [k, v] of Object.entries(shape)) {
|
|
860
|
-
next[k] = walkSlim(v, stripConfig, maxDepth, lazyDepth);
|
|
861
|
-
}
|
|
862
|
-
return carryChecks(zod.z.object(next), schema, stripConfig);
|
|
863
|
-
}
|
|
864
|
-
case "array": {
|
|
865
|
-
const element = getArrayElement(schema);
|
|
866
|
-
return carryChecks(
|
|
867
|
-
zod.z.array(walkSlim(element, stripConfig, maxDepth, lazyDepth)),
|
|
868
|
-
schema,
|
|
869
|
-
stripConfig
|
|
870
|
-
);
|
|
871
|
-
}
|
|
872
|
-
case "set": {
|
|
873
|
-
const valueType = getSetValueType(schema);
|
|
874
|
-
return carryChecks(
|
|
875
|
-
zod.z.set(walkSlim(valueType, stripConfig, maxDepth, lazyDepth)),
|
|
876
|
-
schema,
|
|
877
|
-
stripConfig
|
|
878
|
-
);
|
|
879
|
-
}
|
|
880
|
-
case "tuple": {
|
|
881
|
-
const items = getTupleItems(schema).map(
|
|
882
|
-
(it) => walkSlim(it, stripConfig, maxDepth, lazyDepth)
|
|
883
|
-
);
|
|
884
|
-
const rebuilt = zod.z.tuple(
|
|
885
|
-
items
|
|
886
|
-
);
|
|
887
|
-
return carryChecks(rebuilt, schema, stripConfig);
|
|
888
|
-
}
|
|
889
|
-
case "record": {
|
|
890
|
-
const keyType = getRecordKeyType(schema);
|
|
891
|
-
const valueType = walkSlim(getRecordValueType(schema), stripConfig, maxDepth, lazyDepth);
|
|
892
|
-
const rebuilt = zod.z.record(keyType, valueType);
|
|
893
|
-
return carryChecks(rebuilt, schema, stripConfig);
|
|
894
|
-
}
|
|
895
|
-
case "union": {
|
|
896
|
-
const options = getUnionOptions(schema).map(
|
|
897
|
-
(opt) => walkSlim(opt, stripConfig, maxDepth, lazyDepth)
|
|
898
|
-
);
|
|
899
|
-
const rebuilt = zod.z.union(options);
|
|
900
|
-
return carryChecks(rebuilt, schema, stripConfig);
|
|
901
|
-
}
|
|
902
|
-
case "discriminated-union": {
|
|
903
|
-
const options = getDiscriminatedOptions(schema).map(
|
|
904
|
-
(opt) => walkSlim(opt, stripConfig, maxDepth, lazyDepth)
|
|
905
|
-
);
|
|
906
|
-
const discriminator = getDiscriminator(schema);
|
|
907
|
-
if (discriminator === void 0) return schema;
|
|
908
|
-
return zod.z.discriminatedUnion(
|
|
909
|
-
discriminator,
|
|
910
|
-
options
|
|
911
|
-
);
|
|
912
|
-
}
|
|
913
|
-
// Leaves: strip refinements if requested, otherwise pass through.
|
|
914
|
-
case "string":
|
|
915
|
-
case "number":
|
|
916
|
-
case "bigint":
|
|
917
|
-
return stripConfig.stripRefinements === true && hasChecks(schema) ? stripRefinements(schema) : schema;
|
|
918
|
-
case "boolean":
|
|
919
|
-
case "date":
|
|
920
|
-
case "enum":
|
|
921
|
-
case "literal":
|
|
922
|
-
case "null":
|
|
923
|
-
case "undefined":
|
|
924
|
-
case "any":
|
|
925
|
-
case "unknown":
|
|
926
|
-
case "nan":
|
|
927
|
-
case "void":
|
|
928
|
-
case "never":
|
|
929
|
-
case "promise":
|
|
930
|
-
case "custom":
|
|
931
|
-
case "template-literal":
|
|
932
|
-
case "map":
|
|
933
|
-
case "symbol":
|
|
934
|
-
case "function":
|
|
935
|
-
return schema;
|
|
936
|
-
case "lazy": {
|
|
937
|
-
if (lazyDepth >= maxDepth) return schema;
|
|
938
|
-
const inner = unwrapLazy(schema);
|
|
939
|
-
if (inner === void 0) return schema;
|
|
940
|
-
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth + 1);
|
|
941
|
-
return zod.z.lazy(() => slimmedInner);
|
|
942
|
-
}
|
|
943
|
-
case "intersection": {
|
|
944
|
-
const left = getIntersectionLeft(schema);
|
|
945
|
-
const right = getIntersectionRight(schema);
|
|
946
|
-
if (left === void 0 || right === void 0) return schema;
|
|
947
|
-
return zod.z.intersection(
|
|
948
|
-
walkSlim(left, stripConfig, maxDepth, lazyDepth),
|
|
949
|
-
walkSlim(right, stripConfig, maxDepth, lazyDepth)
|
|
950
|
-
);
|
|
951
|
-
}
|
|
952
|
-
case "catch": {
|
|
953
|
-
const inner = unwrapInner(schema);
|
|
954
|
-
if (inner === void 0) return schema;
|
|
955
|
-
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
956
|
-
return slimmedInner.catch(getCatchDefault(schema));
|
|
957
|
-
}
|
|
958
|
-
case "transform":
|
|
959
|
-
case "file":
|
|
960
|
-
return schema;
|
|
961
|
-
default:
|
|
962
|
-
return unhandledZodKind("getSlimSchema", kind);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
function deriveDefault(schema, useDefault, maxRecursionDepth) {
|
|
967
|
-
return walkFieldMeta.deriveDefaultWalk(schema, useDefault, V4_INTROSPECTOR, maxRecursionDepth, {
|
|
968
|
-
// v4 has an exhaustive switch against `SchemaIntrospector.kindOf`;
|
|
969
|
-
// unknown kinds genuinely shouldn't appear, so return undefined.
|
|
970
|
-
unsupportedKindFallback: () => void 0,
|
|
971
|
-
// v4 historically recurses into the inner on `useDefault=false`
|
|
972
|
-
// so a `.catch(v)` slot returns the leaf empty rather than the
|
|
973
|
-
// fallback. Pinned by `test/adapters/zod-v4/unsupported-kinds.test.ts`
|
|
974
|
-
// (`z.catch falls through to inner leaf default when useDefault=false`).
|
|
975
|
-
catchOnUseDefaultFalse: "recurseInner"
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
function getDefaultValuesFromZodSchema(opts) {
|
|
979
|
-
const { schema, useDefaultSchemaValues, constraints, maxRecursionDepth } = opts;
|
|
980
|
-
const initial = deriveDefault(schema, useDefaultSchemaValues, maxRecursionDepth);
|
|
981
|
-
const merged = walkFieldMeta.mergeDeep(initial, constraints);
|
|
982
|
-
const slimSchema = getSlimSchema(
|
|
983
|
-
schema,
|
|
984
|
-
{
|
|
985
|
-
stripDefaultValues: true,
|
|
986
|
-
stripPipe: true,
|
|
987
|
-
stripRefinements: true
|
|
988
|
-
},
|
|
989
|
-
maxRecursionDepth
|
|
990
|
-
);
|
|
991
|
-
const firstParse = slimSchema.safeParse(merged);
|
|
992
|
-
if (firstParse.success) {
|
|
993
|
-
return { data: firstParse.data, success: true, slimSchema };
|
|
994
|
-
}
|
|
995
|
-
let fixedData = merged;
|
|
996
|
-
for (const issue of firstParse.error.issues) {
|
|
997
|
-
const pathSegments = issue.path.map((seg) => typeof seg === "number" ? seg : String(seg));
|
|
998
|
-
const originalCandidate = getNestedZodSchemasAtPath(schema, pathSegments, maxRecursionDepth)[0];
|
|
999
|
-
if (originalCandidate !== void 0) {
|
|
1000
|
-
if (isCoercePrimitive(originalCandidate)) continue;
|
|
1001
|
-
if (kindOf(originalCandidate) === "pipe") {
|
|
1002
|
-
const pipeIn = unwrapPipeIn(originalCandidate);
|
|
1003
|
-
if (pipeIn !== void 0 && kindOf(pipeIn) === "transform") continue;
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments, maxRecursionDepth);
|
|
1007
|
-
if (candidates.length === 0) continue;
|
|
1008
|
-
const candidate = candidates[0];
|
|
1009
|
-
if (candidate === void 0) continue;
|
|
1010
|
-
const valueAtPath = serializeScript.getAtPath(merged, pathSegments);
|
|
1011
|
-
const slimKinds = slimPrimitivesOf(candidate, maxRecursionDepth);
|
|
1012
|
-
if (slimKinds.size > 0 && slimKinds.has(serializeScript.slimKindOf(valueAtPath))) {
|
|
1013
|
-
continue;
|
|
1014
|
-
}
|
|
1015
|
-
const fixValue = defaultFromIssue(issue, candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1016
|
-
if (fixValue === SKIP) continue;
|
|
1017
|
-
fixedData = pathSegments.length === 0 ? fixValue : serializeScript.setAtPath(fixedData, pathSegments, fixValue);
|
|
1018
|
-
}
|
|
1019
|
-
const secondParse = slimSchema.safeParse(fixedData);
|
|
1020
|
-
if (secondParse.success) {
|
|
1021
|
-
return { data: secondParse.data, success: true, slimSchema };
|
|
1022
|
-
}
|
|
1023
|
-
return { data: fixedData, success: false, slimSchema };
|
|
1024
|
-
}
|
|
1025
|
-
const SKIP = /* @__PURE__ */ Symbol("atta:skip-fix");
|
|
1026
|
-
function defaultFromIssue(issue, candidate, useDefaultSchemaValues, maxRecursionDepth) {
|
|
1027
|
-
if (issue.code === "invalid_type") {
|
|
1028
|
-
const du = unwrapToDiscriminatedUnion(candidate);
|
|
1029
|
-
if (du !== void 0) {
|
|
1030
|
-
const first = getDiscriminatedUnionFirstOption(du);
|
|
1031
|
-
if (first !== void 0)
|
|
1032
|
-
return deriveDefault(first, useDefaultSchemaValues, maxRecursionDepth);
|
|
1033
|
-
}
|
|
1034
|
-
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1035
|
-
}
|
|
1036
|
-
if (issue.code === "invalid_value") {
|
|
1037
|
-
const values = issue.values;
|
|
1038
|
-
if (values !== void 0 && values.length > 0) return values[0];
|
|
1039
|
-
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1040
|
-
}
|
|
1041
|
-
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1042
|
-
}
|
|
1043
687
|
|
|
1044
688
|
function unwrapStructuralWrappers(schema) {
|
|
1045
689
|
let current = schema;
|
|
@@ -1127,7 +771,7 @@ function isLeafRequired(schema, depth = 0) {
|
|
|
1127
771
|
function zodV4Adapter(rootSchema) {
|
|
1128
772
|
assertZodVersion(rootSchema);
|
|
1129
773
|
assertSupportedKinds(rootSchema);
|
|
1130
|
-
return (formKey, options) =>
|
|
774
|
+
return (formKey, options) => createAbstractSchema(
|
|
1131
775
|
rootSchema,
|
|
1132
776
|
V4_INTROSPECTOR,
|
|
1133
777
|
buildV4Services(),
|
|
@@ -1136,7 +780,7 @@ function zodV4Adapter(rootSchema) {
|
|
|
1136
780
|
);
|
|
1137
781
|
}
|
|
1138
782
|
async function lazyFingerprint(schema) {
|
|
1139
|
-
const { fingerprintZodSchema } = await import('../chunks/fingerprint2.
|
|
783
|
+
const { fingerprintZodSchema } = await import('../chunks/fingerprint2.mjs');
|
|
1140
784
|
return fingerprintZodSchema(schema);
|
|
1141
785
|
}
|
|
1142
786
|
function buildV4Services() {
|
|
@@ -1155,7 +799,7 @@ function buildV4Services() {
|
|
|
1155
799
|
peelAllWrappers: (schema) => peelAllWrappers(schema),
|
|
1156
800
|
isLeafRequired: (schema) => isLeafRequired(schema),
|
|
1157
801
|
resolveFieldMetaAtPath: (schema, path, maxRecursionDepth) => resolveFieldMetaAtPath(schema, path, maxRecursionDepth),
|
|
1158
|
-
issuesToValidationErrors: (issues
|
|
802
|
+
issuesToValidationErrors: (issues) => zodIssuesToValidationErrors(issues),
|
|
1159
803
|
safeParseSync: (schema, data) => {
|
|
1160
804
|
const result = schema.safeParse(data);
|
|
1161
805
|
return result.success ? { success: true, data: result.data } : { success: false, issues: result.error.issues };
|
|
@@ -1188,7 +832,7 @@ function runStrictGetDefaultsV4(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1188
832
|
}
|
|
1189
833
|
return {
|
|
1190
834
|
data,
|
|
1191
|
-
errors: zodIssuesToValidationErrors(strictResult.error.issues
|
|
835
|
+
errors: zodIssuesToValidationErrors(strictResult.error.issues),
|
|
1192
836
|
success: false,
|
|
1193
837
|
formKey
|
|
1194
838
|
};
|
|
@@ -1219,7 +863,7 @@ function buildSubSchemaStubV4(schema, formKey, maxRecursionDepth) {
|
|
|
1219
863
|
}
|
|
1220
864
|
return {
|
|
1221
865
|
data: void 0,
|
|
1222
|
-
errors: zodIssuesToValidationErrors(result.error.issues
|
|
866
|
+
errors: zodIssuesToValidationErrors(result.error.issues),
|
|
1223
867
|
success: false,
|
|
1224
868
|
formKey
|
|
1225
869
|
};
|
|
@@ -1232,25 +876,25 @@ function resolveFieldMetaAtPath(rootSchema, path, maxRecursionDepth) {
|
|
|
1232
876
|
const target = candidates[0];
|
|
1233
877
|
if (target === void 0) {
|
|
1234
878
|
return {
|
|
1235
|
-
label:
|
|
879
|
+
label: humanize(lastSegment),
|
|
1236
880
|
description: void 0,
|
|
1237
881
|
placeholder: void 0,
|
|
1238
882
|
meta: Object.freeze({})
|
|
1239
883
|
};
|
|
1240
884
|
}
|
|
1241
|
-
const pathMap =
|
|
885
|
+
const pathMap = buildFieldMetaPathMap(rootSchema, {
|
|
1242
886
|
intro: V4_INTROSPECTOR,
|
|
1243
887
|
peelAllWrappers,
|
|
1244
|
-
getFieldMetaList
|
|
888
|
+
getFieldMetaList: getFieldMetaListForSchema
|
|
1245
889
|
});
|
|
1246
|
-
const pathKey =
|
|
890
|
+
const pathKey = canonicalizePath(path).key;
|
|
1247
891
|
const peeled = peelAllWrappers(target);
|
|
1248
|
-
const payload = pathMap
|
|
892
|
+
const payload = pathMap?.get(pathKey) ?? getFieldMetaForSchema(target) ?? (peeled !== target ? getFieldMetaForSchema(peeled) : void 0);
|
|
1249
893
|
const targetDescription = readDescription(target);
|
|
1250
894
|
const peeledDescription = peeled !== target ? readDescription(peeled) : void 0;
|
|
1251
895
|
const schemaDescription = targetDescription ?? peeledDescription;
|
|
1252
896
|
return {
|
|
1253
|
-
label: payload?.label ??
|
|
897
|
+
label: payload?.label ?? humanize(lastSegment),
|
|
1254
898
|
description: payload?.description ?? schemaDescription ?? void 0,
|
|
1255
899
|
placeholder: payload?.placeholder ?? void 0,
|
|
1256
900
|
meta: Object.freeze({ ...payload ?? {} })
|
|
@@ -1264,39 +908,13 @@ function readDescription(schema) {
|
|
|
1264
908
|
function useForm(configuration) {
|
|
1265
909
|
const candidate = configuration;
|
|
1266
910
|
if (candidate === void 0 || candidate === null || candidate.schema === void 0) {
|
|
1267
|
-
throw new
|
|
911
|
+
throw new InvalidUseFormConfigError();
|
|
1268
912
|
}
|
|
1269
913
|
const adapter = zodV4Adapter(configuration.schema);
|
|
1270
|
-
return
|
|
914
|
+
return useAbstractForm({
|
|
1271
915
|
...configuration,
|
|
1272
916
|
schema: adapter
|
|
1273
917
|
});
|
|
1274
918
|
}
|
|
1275
919
|
|
|
1276
|
-
|
|
1277
|
-
exports.assertZodVersion = assertZodVersion;
|
|
1278
|
-
exports.fieldMeta = fieldMeta;
|
|
1279
|
-
exports.getArrayElement = getArrayElement;
|
|
1280
|
-
exports.getCatchDefault = getCatchDefault;
|
|
1281
|
-
exports.getChecks = getChecks;
|
|
1282
|
-
exports.getDefaultValue = getDefaultValue;
|
|
1283
|
-
exports.getDiscriminatedOptions = getDiscriminatedOptions;
|
|
1284
|
-
exports.getDiscriminator = getDiscriminator;
|
|
1285
|
-
exports.getEnumValues = getEnumValues;
|
|
1286
|
-
exports.getIntersectionLeft = getIntersectionLeft;
|
|
1287
|
-
exports.getIntersectionRight = getIntersectionRight;
|
|
1288
|
-
exports.getLiteralValues = getLiteralValues;
|
|
1289
|
-
exports.getObjectShape = getObjectShape;
|
|
1290
|
-
exports.getRecordKeyType = getRecordKeyType;
|
|
1291
|
-
exports.getRecordValueType = getRecordValueType;
|
|
1292
|
-
exports.getSetValueType = getSetValueType;
|
|
1293
|
-
exports.getTupleItems = getTupleItems;
|
|
1294
|
-
exports.getUnionOptions = getUnionOptions;
|
|
1295
|
-
exports.kindOf = kindOf;
|
|
1296
|
-
exports.unwrapInner = unwrapInner;
|
|
1297
|
-
exports.unwrapLazy = unwrapLazy;
|
|
1298
|
-
exports.unwrapPipe = unwrapPipe;
|
|
1299
|
-
exports.useForm = useForm;
|
|
1300
|
-
exports.withMeta = withMeta;
|
|
1301
|
-
exports.zodV4Adapter = zodV4Adapter;
|
|
1302
|
-
//# sourceMappingURL=attaform.Crv0RNiz.cjs.map
|
|
920
|
+
export { UnsupportedSchemaError as U, assertZodVersion as a, getIntersectionRight as b, unwrapLazy as c, unwrapInner as d, unwrapPipe as e, getDiscriminator as f, getIntersectionLeft as g, getDiscriminatedOptions as h, getUnionOptions as i, getRecordKeyType as j, kindOf as k, getRecordValueType as l, getTupleItems as m, getSetValueType as n, getArrayElement as o, getObjectShape as p, getEnumValues as q, getLiteralValues as r, getChecks as s, getCatchDefault as t, useForm as u, getDefaultValue as v, zodV4Adapter as z };
|