attaform 0.27.6 → 0.29.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 +1 -2
- package/dist/chunks/fingerprint2.mjs +2 -3
- 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/dev/shared/attaform-dev.A-TpJW0B.mjs +207 -0
- package/dist/dev/shared/attaform-dev.BO-71R54.mjs +820 -0
- package/dist/{shared/attaform.D6tk90Rc.cjs → dev/shared/attaform-dev.BgM6FdtA.mjs} +324 -73
- package/dist/dev/shared/attaform-dev.ButTkwHd.mjs +375 -0
- package/dist/{shared/attaform.BJGA_UOS.mjs → dev/shared/attaform-dev.BxfsuwBR.mjs} +8 -1
- package/dist/{shared/attaform.nMaz2C5P.mjs → dev/shared/attaform-dev.D8aoKb89.mjs} +190 -400
- package/dist/dev/shared/attaform-dev.DD5m2W51.mjs +220 -0
- package/dist/{shared/attaform.CKH2lGdL.mjs → dev/shared/attaform-dev.DHuydLAC.mjs} +3867 -4731
- package/dist/{shared/attaform.DYEr28Pt.mjs → dev/shared/attaform-dev.DrzObAZo.mjs} +6 -7
- package/dist/{shared/attaform.B1ZYt2Li.mjs → dev/shared/attaform-dev.q6UutkCx.mjs} +274 -672
- 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 +14 -6
- package/dist/index.mjs +5 -4
- package/dist/nuxt.d.mts +10 -10
- 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.CoR4mWfv.mjs → attaform.B0dKL8ST.mjs} +309 -46
- package/dist/shared/{attaform.Cs2Rbdlo.mjs → attaform.BK0cgu2K.mjs} +123 -140
- package/dist/shared/{attaform.B9Wyhfro.cjs → attaform.BndjUUYX.mjs} +11 -16
- package/dist/shared/{attaform.CQN9R62B.cjs → attaform.BxfsuwBR.mjs} +9 -4
- package/dist/shared/attaform.C2MVyuxC.mjs +811 -0
- package/dist/shared/{attaform.Fp3sCrVs.d.ts → attaform.CIWLMY-R.d.mts} +2 -2
- package/dist/shared/attaform.CZMAYwSK.mjs +6383 -0
- package/dist/shared/attaform.CZYt_5N_.mjs +207 -0
- package/dist/shared/{attaform.DniawQLP.d.cts → attaform.CsoeRi3P.d.mts} +490 -98
- package/dist/shared/attaform.Cvao8bW5.mjs +358 -0
- package/dist/shared/attaform.D0x-qSXm.mjs +197 -0
- package/dist/shared/{attaform.D8kliaKw.cjs → attaform.D1fnTifF.mjs} +279 -692
- package/dist/shared/{attaform.CHlJLAiv.d.mts → attaform.DDtqHYv1.d.mts} +155 -184
- package/dist/shared/{attaform.Biytrv0-.cjs → attaform.DffRL5pP.mjs} +215 -547
- package/dist/shared/attaform.DhnPb6nK.mjs +0 -1
- package/dist/shared/attaform.KvlEedlF.mjs +0 -1
- package/dist/shared/attaform.axHXVQO7.d.mts +44 -0
- package/dist/shared/attaform.v0fQtWyA.mjs +0 -1
- package/dist/transforms.d.mts +0 -22
- package/dist/transforms.mjs +1 -2
- package/dist/vite.d.mts +30 -9
- package/dist/vite.mjs +27 -4
- package/dist/webpack.d.mts +6 -1
- package/dist/webpack.mjs +0 -1
- package/dist/zod-v3.d.mts +13 -6
- package/dist/zod-v3.mjs +17 -4
- package/dist/zod-v4.d.mts +19 -26
- package/dist/zod-v4.mjs +16 -4
- package/dist/zod.d.mts +4 -3
- package/dist/zod.mjs +5 -4
- package/package.json +38 -20
- package/skills/attaform/SKILL.md +6 -2
- package/skills/attaform/references/custom-components.md +7 -2
- 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/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.B1ZYt2Li.mjs.map +0 -1
- package/dist/shared/attaform.B9Wyhfro.cjs.map +0 -1
- package/dist/shared/attaform.BGDV42hI.d.cts +0 -232
- package/dist/shared/attaform.BJGA_UOS.mjs.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.C9fPTxjB.d.cts +0 -41
- package/dist/shared/attaform.C9fPTxjB.d.ts +0 -41
- package/dist/shared/attaform.CKH2lGdL.mjs.map +0 -1
- package/dist/shared/attaform.CQN9R62B.cjs.map +0 -1
- package/dist/shared/attaform.CoR4mWfv.mjs.map +0 -1
- package/dist/shared/attaform.Cs2Rbdlo.mjs.map +0 -1
- package/dist/shared/attaform.D6tk90Rc.cjs.map +0 -1
- package/dist/shared/attaform.D8kliaKw.cjs.map +0 -1
- package/dist/shared/attaform.DLknk9nF.d.mts +0 -232
- package/dist/shared/attaform.DMxM2kol.mjs +0 -1275
- package/dist/shared/attaform.DMxM2kol.mjs.map +0 -1
- package/dist/shared/attaform.DRUT703x.d.cts +0 -56
- package/dist/shared/attaform.DRUT703x.d.ts +0 -56
- package/dist/shared/attaform.DYEr28Pt.mjs.map +0 -1
- package/dist/shared/attaform.DdQN7sgN.cjs +0 -1302
- package/dist/shared/attaform.DdQN7sgN.cjs.map +0 -1
- package/dist/shared/attaform.DhnPb6nK.mjs.map +0 -1
- package/dist/shared/attaform.DniawQLP.d.mts +0 -4763
- package/dist/shared/attaform.DniawQLP.d.ts +0 -4763
- package/dist/shared/attaform.DoQm_Vkd.cjs +0 -58
- package/dist/shared/attaform.DoQm_Vkd.cjs.map +0 -1
- package/dist/shared/attaform.DrvMscNX.cjs +0 -7697
- package/dist/shared/attaform.DrvMscNX.cjs.map +0 -1
- package/dist/shared/attaform.F2Q8iv38.d.ts +0 -2494
- package/dist/shared/attaform.FmqKO1Ex.d.cts +0 -2494
- 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.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,59 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const devtoolsShared = require('./attaform.Biytrv0-.cjs');
|
|
6
|
-
|
|
7
|
-
const fieldMeta = walkFieldMeta.fieldMetaStore;
|
|
8
|
-
function withMeta(schema, payload) {
|
|
9
|
-
const existing = walkFieldMeta.getFieldMetaForSchema(schema) ?? {};
|
|
10
|
-
const Ctor = schema.constructor;
|
|
11
|
-
const cloned = new Ctor(schema._def);
|
|
12
|
-
walkFieldMeta.fieldMetaStore.add(cloned, { ...existing, ...payload });
|
|
13
|
-
return cloned;
|
|
14
|
-
}
|
|
15
|
-
function getFieldMeta(schema) {
|
|
16
|
-
return walkFieldMeta.getFieldMetaForSchema(schema);
|
|
17
|
-
}
|
|
18
|
-
function getFieldMetaList(schema) {
|
|
19
|
-
return walkFieldMeta.getFieldMetaListForSchema(schema);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function cloneSchemaDeep(value) {
|
|
23
|
-
return clone(value, /* @__PURE__ */ new WeakMap());
|
|
24
|
-
}
|
|
25
|
-
function clone(value, seen) {
|
|
26
|
-
if (value === null || typeof value !== "object") return value;
|
|
27
|
-
if (seen.has(value)) return seen.get(value);
|
|
28
|
-
if (value instanceof RegExp) {
|
|
29
|
-
const copy2 = new RegExp(value.source, value.flags);
|
|
30
|
-
copy2.lastIndex = value.lastIndex;
|
|
31
|
-
seen.set(value, copy2);
|
|
32
|
-
return copy2;
|
|
33
|
-
}
|
|
34
|
-
if (value instanceof Date) {
|
|
35
|
-
const copy2 = new Date(value.getTime());
|
|
36
|
-
seen.set(value, copy2);
|
|
37
|
-
return copy2;
|
|
38
|
-
}
|
|
39
|
-
if (Array.isArray(value)) {
|
|
40
|
-
const copy2 = [];
|
|
41
|
-
seen.set(value, copy2);
|
|
42
|
-
for (let i = 0; i < value.length; i++) {
|
|
43
|
-
copy2[i] = clone(value[i], seen);
|
|
44
|
-
}
|
|
45
|
-
return copy2;
|
|
46
|
-
}
|
|
47
|
-
const copy = Object.create(Object.getPrototypeOf(value));
|
|
48
|
-
seen.set(value, copy);
|
|
49
|
-
const source = value;
|
|
50
|
-
for (const key of Reflect.ownKeys(value)) {
|
|
51
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
52
|
-
if (descriptor?.enumerable !== true) continue;
|
|
53
|
-
copy[key] = clone(source[key], seen);
|
|
54
|
-
}
|
|
55
|
-
return copy;
|
|
56
|
-
}
|
|
1
|
+
import { w as walkPathSegments, s as slimPrimitivesWalk, c as createAbstractSchema, b as buildFieldMetaPathMap, g as getFieldMetaForSchema, m as mergeDeep, f as fixStructuralDefaults, d as deriveDefaultWalk, a as getFieldMetaListForSchema } from './attaform.B0dKL8ST.mjs';
|
|
2
|
+
import { p as getAtPath, q as humanize, h as useAbstractForm } from './attaform.CZMAYwSK.mjs';
|
|
3
|
+
import { c as callConsumerSchemaFn } from './attaform.Cvao8bW5.mjs';
|
|
4
|
+
import { A as AttaformError, e as canonicalizePath, a as InvalidUseFormConfigError } from './attaform.CZYt_5N_.mjs';
|
|
57
5
|
|
|
58
6
|
function isZodSchemaType(schema, expectedType) {
|
|
59
7
|
if (typeof schema !== "object" || schema === null) return false;
|
|
@@ -173,6 +121,8 @@ function getRecordValueType(schema) {
|
|
|
173
121
|
const def = readDef(schema);
|
|
174
122
|
return def?.valueType;
|
|
175
123
|
}
|
|
124
|
+
const getMapKeyType = getRecordKeyType;
|
|
125
|
+
const getMapValueType = getRecordValueType;
|
|
176
126
|
function getTupleItems(schema) {
|
|
177
127
|
const def = readDef(schema);
|
|
178
128
|
return def?.items ?? [];
|
|
@@ -213,6 +163,10 @@ function unwrapEffectsSource(schema) {
|
|
|
213
163
|
const def = readDef(schema);
|
|
214
164
|
return def?.schema;
|
|
215
165
|
}
|
|
166
|
+
function getEffect(schema) {
|
|
167
|
+
const def = readDef(schema);
|
|
168
|
+
return def?.effect;
|
|
169
|
+
}
|
|
216
170
|
function getEffectsKind(schema) {
|
|
217
171
|
const def = readDef(schema);
|
|
218
172
|
const type = def?.effect?.type;
|
|
@@ -236,12 +190,18 @@ function isAsyncEffect(schema) {
|
|
|
236
190
|
return fn.constructor.name === "AsyncFunction";
|
|
237
191
|
}
|
|
238
192
|
function containsAsyncRefine(schema, seen) {
|
|
239
|
-
return
|
|
193
|
+
return walkForTarget(schema, "refinement", seen ?? /* @__PURE__ */ new WeakSet());
|
|
194
|
+
}
|
|
195
|
+
function containsMapOrSet(schema, seen) {
|
|
196
|
+
return walkForTarget(schema, "map-or-set", /* @__PURE__ */ new WeakSet());
|
|
197
|
+
}
|
|
198
|
+
function containsDiscriminatedUnion(schema, seen) {
|
|
199
|
+
return walkForTarget(schema, "discriminated-union", seen ?? /* @__PURE__ */ new WeakSet());
|
|
240
200
|
}
|
|
241
201
|
function containsAsyncTransform(schema, seen) {
|
|
242
|
-
return
|
|
202
|
+
return walkForTarget(schema, "transform-or-preprocess", seen ?? /* @__PURE__ */ new WeakSet());
|
|
243
203
|
}
|
|
244
|
-
function
|
|
204
|
+
function walkForTarget(schema, target, visited) {
|
|
245
205
|
const candidate = schema;
|
|
246
206
|
if (typeof candidate !== "object" || candidate === null) return false;
|
|
247
207
|
if (visited.has(candidate)) return false;
|
|
@@ -253,66 +213,77 @@ function walkForAsync(schema, target, visited) {
|
|
|
253
213
|
return true;
|
|
254
214
|
}
|
|
255
215
|
const inner = unwrapEffectsSource(schema);
|
|
256
|
-
return inner !== void 0 &&
|
|
216
|
+
return inner !== void 0 && walkForTarget(inner, target, visited);
|
|
257
217
|
}
|
|
258
218
|
if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodReadonly")) {
|
|
259
219
|
const inner = unwrapInner(schema);
|
|
260
|
-
return inner !== void 0 &&
|
|
220
|
+
return inner !== void 0 && walkForTarget(inner, target, visited);
|
|
261
221
|
}
|
|
262
222
|
if (isZodSchemaType(schema, "ZodBranded")) {
|
|
263
223
|
const inner = unwrapBranded(schema);
|
|
264
|
-
return inner !== void 0 &&
|
|
224
|
+
return inner !== void 0 && walkForTarget(inner, target, visited);
|
|
265
225
|
}
|
|
266
226
|
if (isZodSchemaType(schema, "ZodLazy")) {
|
|
267
227
|
const inner = unwrapLazy(schema);
|
|
268
|
-
return inner !== void 0 &&
|
|
228
|
+
return inner !== void 0 && walkForTarget(inner, target, visited);
|
|
269
229
|
}
|
|
270
230
|
if (isZodSchemaType(schema, "ZodPipeline")) {
|
|
271
231
|
const inSide = unwrapPipeIn(schema);
|
|
272
|
-
if (inSide !== void 0 &&
|
|
232
|
+
if (inSide !== void 0 && walkForTarget(inSide, target, visited)) return true;
|
|
273
233
|
const outSide = unwrapPipeOut(schema);
|
|
274
|
-
if (outSide !== void 0 &&
|
|
234
|
+
if (outSide !== void 0 && walkForTarget(outSide, target, visited)) return true;
|
|
275
235
|
return false;
|
|
276
236
|
}
|
|
277
237
|
if (isZodSchemaType(schema, "ZodObject")) {
|
|
278
238
|
for (const sub of Object.values(getObjectShape(schema))) {
|
|
279
|
-
if (
|
|
239
|
+
if (walkForTarget(sub, target, visited)) return true;
|
|
280
240
|
}
|
|
281
241
|
return false;
|
|
282
242
|
}
|
|
283
243
|
if (isZodSchemaType(schema, "ZodArray")) {
|
|
284
244
|
const elem = getArrayElement(schema);
|
|
285
|
-
return elem !== void 0 &&
|
|
245
|
+
return elem !== void 0 && walkForTarget(elem, target, visited);
|
|
286
246
|
}
|
|
287
247
|
if (isZodSchemaType(schema, "ZodTuple")) {
|
|
288
248
|
for (const it of getTupleItems(schema)) {
|
|
289
|
-
if (
|
|
249
|
+
if (walkForTarget(it, target, visited)) return true;
|
|
290
250
|
}
|
|
291
251
|
return false;
|
|
292
252
|
}
|
|
293
253
|
if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
|
|
254
|
+
if (target === "discriminated-union" && isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
294
257
|
for (const opt of getUnionOptions(schema)) {
|
|
295
|
-
if (
|
|
258
|
+
if (walkForTarget(opt, target, visited)) return true;
|
|
296
259
|
}
|
|
297
260
|
return false;
|
|
298
261
|
}
|
|
299
262
|
if (isZodSchemaType(schema, "ZodIntersection")) {
|
|
300
263
|
const left = getIntersectionLeft(schema);
|
|
301
|
-
if (left !== void 0 &&
|
|
264
|
+
if (left !== void 0 && walkForTarget(left, target, visited)) return true;
|
|
302
265
|
const right = getIntersectionRight(schema);
|
|
303
|
-
if (right !== void 0 &&
|
|
266
|
+
if (right !== void 0 && walkForTarget(right, target, visited)) return true;
|
|
304
267
|
return false;
|
|
305
268
|
}
|
|
306
269
|
if (isZodSchemaType(schema, "ZodRecord")) {
|
|
307
270
|
const keyType = getRecordKeyType(schema);
|
|
308
|
-
if (keyType !== void 0 &&
|
|
271
|
+
if (keyType !== void 0 && walkForTarget(keyType, target, visited)) return true;
|
|
309
272
|
const valueType = getRecordValueType(schema);
|
|
310
|
-
if (valueType !== void 0 &&
|
|
273
|
+
if (valueType !== void 0 && walkForTarget(valueType, target, visited)) return true;
|
|
311
274
|
return false;
|
|
312
275
|
}
|
|
313
276
|
if (isZodSchemaType(schema, "ZodSet")) {
|
|
277
|
+
if (target === "map-or-set") return true;
|
|
314
278
|
const elem = getSetValueType(schema);
|
|
315
|
-
return elem !== void 0 &&
|
|
279
|
+
return elem !== void 0 && walkForTarget(elem, target, visited);
|
|
280
|
+
}
|
|
281
|
+
if (isZodSchemaType(schema, "ZodMap")) {
|
|
282
|
+
if (target === "map-or-set") return true;
|
|
283
|
+
const keyType = getMapKeyType(schema);
|
|
284
|
+
if (keyType !== void 0 && walkForTarget(keyType, target, visited)) return true;
|
|
285
|
+
const valueType = getMapValueType(schema);
|
|
286
|
+
return valueType !== void 0 && walkForTarget(valueType, target, visited);
|
|
316
287
|
}
|
|
317
288
|
return false;
|
|
318
289
|
}
|
|
@@ -328,11 +299,7 @@ function unwrapLazy(schema) {
|
|
|
328
299
|
const def = readDef(schema);
|
|
329
300
|
const getter = def?.getter;
|
|
330
301
|
if (typeof getter !== "function") return void 0;
|
|
331
|
-
|
|
332
|
-
return getter();
|
|
333
|
-
} catch {
|
|
334
|
-
return void 0;
|
|
335
|
-
}
|
|
302
|
+
return callConsumerSchemaFn(() => getter(), void 0);
|
|
336
303
|
}
|
|
337
304
|
function getLazyGetter(schema) {
|
|
338
305
|
const def = readDef(schema);
|
|
@@ -349,35 +316,24 @@ function getNativeEnumValues(schema) {
|
|
|
349
316
|
const def = readDef(schema);
|
|
350
317
|
return def?.values;
|
|
351
318
|
}
|
|
352
|
-
function getDefaultValue
|
|
319
|
+
function getDefaultValue(schema) {
|
|
353
320
|
const def = readDef(schema);
|
|
354
321
|
const thunk = def?.defaultValue;
|
|
355
322
|
if (typeof thunk !== "function") return void 0;
|
|
356
|
-
|
|
357
|
-
return thunk();
|
|
358
|
-
} catch {
|
|
359
|
-
return void 0;
|
|
360
|
-
}
|
|
323
|
+
return callConsumerSchemaFn(() => thunk(), void 0);
|
|
361
324
|
}
|
|
362
325
|
function getCatchDefault(schema) {
|
|
363
326
|
const def = readDef(schema);
|
|
364
327
|
const cv = def?.catchValue;
|
|
365
328
|
if (typeof cv !== "function") return void 0;
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
return void 0;
|
|
370
|
-
}
|
|
329
|
+
return callConsumerSchemaFn(
|
|
330
|
+
() => cv({ error: null, input: void 0 }),
|
|
331
|
+
void 0);
|
|
371
332
|
}
|
|
372
333
|
function hasCatchValue(schema) {
|
|
373
334
|
const def = readDef(schema);
|
|
374
335
|
return typeof def?.catchValue === "function";
|
|
375
336
|
}
|
|
376
|
-
function hasChecks(schema) {
|
|
377
|
-
const def = readDef(schema);
|
|
378
|
-
const checks = def?.checks;
|
|
379
|
-
return Array.isArray(checks) && checks.length > 0;
|
|
380
|
-
}
|
|
381
337
|
function hasContainerOrRootRefine(schema, seen) {
|
|
382
338
|
const visited = seen ?? /* @__PURE__ */ new WeakSet();
|
|
383
339
|
const candidate = schema;
|
|
@@ -473,10 +429,124 @@ function isContainerAfterWrapperPeel(schema) {
|
|
|
473
429
|
return isZodSchemaType(cur, "ZodObject") || isZodSchemaType(cur, "ZodArray") || isZodSchemaType(cur, "ZodTuple") || isZodSchemaType(cur, "ZodIntersection") || isZodSchemaType(cur, "ZodUnion") || isZodSchemaType(cur, "ZodDiscriminatedUnion") || isZodSchemaType(cur, "ZodRecord") || isZodSchemaType(cur, "ZodSet");
|
|
474
430
|
}
|
|
475
431
|
|
|
432
|
+
const V3_INTROSPECTOR = {
|
|
433
|
+
kindOf: (schema) => kindOf(schema),
|
|
434
|
+
getObjectShape,
|
|
435
|
+
getTupleItems,
|
|
436
|
+
getDiscriminatedOptions: (schema) => getDiscriminatedOptions(schema),
|
|
437
|
+
getDiscriminator,
|
|
438
|
+
getLiteralValues,
|
|
439
|
+
isPreprocessNode,
|
|
440
|
+
isCoercePrimitive,
|
|
441
|
+
containsAsyncRefine,
|
|
442
|
+
containsAsyncTransform,
|
|
443
|
+
containsDiscriminatedUnion,
|
|
444
|
+
hasContainerOrRootRefine,
|
|
445
|
+
// Walker accessors (D2 / D3 / D5).
|
|
446
|
+
getArrayElement,
|
|
447
|
+
getSetValueType,
|
|
448
|
+
getRecordKeyType,
|
|
449
|
+
getRecordValueType,
|
|
450
|
+
getMapKeyType: (schema) => kindOf(schema) === "map" ? getMapKeyType(schema) : void 0,
|
|
451
|
+
getMapValueType: (schema) => kindOf(schema) === "map" ? getMapValueType(schema) : void 0,
|
|
452
|
+
getUnionOptions,
|
|
453
|
+
getIntersectionLeft,
|
|
454
|
+
getIntersectionRight,
|
|
455
|
+
getEnumValues: (schema) => {
|
|
456
|
+
if (!isZodSchemaType(schema, "ZodEnum")) return [];
|
|
457
|
+
return schema.options;
|
|
458
|
+
},
|
|
459
|
+
getNativeEnumValues,
|
|
460
|
+
unwrapInner,
|
|
461
|
+
unwrapBranded,
|
|
462
|
+
unwrapEffectsSource,
|
|
463
|
+
unwrapPipeIn,
|
|
464
|
+
unwrapPipeOut,
|
|
465
|
+
unwrapLazy,
|
|
466
|
+
getLazyGetter,
|
|
467
|
+
getDefaultValue,
|
|
468
|
+
getCatchDefault,
|
|
469
|
+
hasCatchValue
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
function mapKeyAt(value, index) {
|
|
473
|
+
if (!(value instanceof Map)) return void 0;
|
|
474
|
+
if (typeof index !== "number" || !Number.isInteger(index) || index < 0) return void 0;
|
|
475
|
+
let i = 0;
|
|
476
|
+
for (const key of value.keys()) {
|
|
477
|
+
if (i === index) return key;
|
|
478
|
+
i += 1;
|
|
479
|
+
}
|
|
480
|
+
return void 0;
|
|
481
|
+
}
|
|
482
|
+
function stepSchema(schema, segment, maxRecursionDepth) {
|
|
483
|
+
if (schema === void 0) return void 0;
|
|
484
|
+
return walkPathSegments(schema, [String(segment)], V3_INTROSPECTOR, maxRecursionDepth, 0)[0];
|
|
485
|
+
}
|
|
486
|
+
function normalizeIssuePaths(issues, rootSchema, data, maxRecursionDepth, peel) {
|
|
487
|
+
let out = null;
|
|
488
|
+
for (let i = 0; i < issues.length; i++) {
|
|
489
|
+
const issue = issues[i];
|
|
490
|
+
const next = normalizeOne(issue.path, rootSchema, data, maxRecursionDepth, peel);
|
|
491
|
+
if (next === null) continue;
|
|
492
|
+
out ?? (out = [...issues]);
|
|
493
|
+
out[i] = { ...issue, path: next };
|
|
494
|
+
}
|
|
495
|
+
return out ?? issues;
|
|
496
|
+
}
|
|
497
|
+
function normalizeOne(path, rootSchema, data, maxRecursionDepth, peel) {
|
|
498
|
+
const out = [];
|
|
499
|
+
let schema = rootSchema;
|
|
500
|
+
let value = data;
|
|
501
|
+
let changed = false;
|
|
502
|
+
let i = 0;
|
|
503
|
+
while (i < path.length) {
|
|
504
|
+
const peeled = schema === void 0 ? void 0 : peel(schema);
|
|
505
|
+
const kind = peeled === void 0 ? void 0 : V3_INTROSPECTOR.kindOf(peeled);
|
|
506
|
+
if (kind === "set") {
|
|
507
|
+
changed = true;
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
if (kind === "map") {
|
|
511
|
+
const key = mapKeyAt(value, path[i]);
|
|
512
|
+
if (key === void 0) {
|
|
513
|
+
changed = true;
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
if (typeof key !== "string" && typeof key !== "number") {
|
|
517
|
+
changed = true;
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
out.push(key);
|
|
521
|
+
value = value.get(key);
|
|
522
|
+
schema = V3_INTROSPECTOR.getMapValueType(peeled);
|
|
523
|
+
changed = true;
|
|
524
|
+
const half = path[i + 1];
|
|
525
|
+
i += half === "key" || half === "value" ? 2 : 1;
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
const segment = path[i];
|
|
529
|
+
out.push(segment);
|
|
530
|
+
value = getAtPath(value, [segment]);
|
|
531
|
+
schema = stepSchema(schema, segment, maxRecursionDepth);
|
|
532
|
+
i += 1;
|
|
533
|
+
}
|
|
534
|
+
return changed ? out : null;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function slimPrimitivesV3(schema) {
|
|
538
|
+
return new Set(slimPrimitivesWalk(schema, V3_INTROSPECTOR, 64));
|
|
539
|
+
}
|
|
540
|
+
|
|
476
541
|
function rebuildWithDef(original, defPatch) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
542
|
+
return Object.create(Object.getPrototypeOf(original), {
|
|
543
|
+
_def: {
|
|
544
|
+
value: { ...original._def, ...defPatch },
|
|
545
|
+
writable: true,
|
|
546
|
+
enumerable: true,
|
|
547
|
+
configurable: true
|
|
548
|
+
}
|
|
549
|
+
});
|
|
480
550
|
}
|
|
481
551
|
function rebuildObject(original, shape) {
|
|
482
552
|
const node = rebuildWithDef(original, { shape: () => shape, unknownKeys: "strip" });
|
|
@@ -518,9 +588,6 @@ function rebuildWrapperInner(original, inner) {
|
|
|
518
588
|
function rebuildLazy(original, target) {
|
|
519
589
|
return rebuildWithDef(original, { getter: () => target });
|
|
520
590
|
}
|
|
521
|
-
function stripLeafChecks(original) {
|
|
522
|
-
return rebuildWithDef(original, { checks: [] });
|
|
523
|
-
}
|
|
524
591
|
function rebuildDiscriminatedUnion(original, options) {
|
|
525
592
|
const originalOptions = getDiscriminatedOptions(original);
|
|
526
593
|
const originalMap = getDiscriminatedOptionsMap(original);
|
|
@@ -534,141 +601,20 @@ function rebuildDiscriminatedUnion(original, options) {
|
|
|
534
601
|
}
|
|
535
602
|
return rebuildWithDef(original, { options, optionsMap });
|
|
536
603
|
}
|
|
537
|
-
|
|
538
|
-
|
|
604
|
+
function rebuildEffects(original, source, effect) {
|
|
605
|
+
return rebuildWithDef(original, { schema: source, effect });
|
|
539
606
|
}
|
|
540
607
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
return path.length === 0 ? "<root>" : path.join(".");
|
|
544
|
-
}
|
|
545
|
-
function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
546
|
-
const typeName = getTypeName(schema);
|
|
547
|
-
if (typeName !== void 0 && UNSUPPORTED_TYPE_NAMES.has(typeName)) {
|
|
548
|
-
throw new UnsupportedSchemaError(
|
|
549
|
-
`[attaform/zod-v3] unsupported kind '${typeName}' at '${labelPath(path)}'`
|
|
550
|
-
);
|
|
551
|
-
}
|
|
552
|
-
if (isZodSchemaType(schema, "ZodObject")) {
|
|
553
|
-
for (const [key, sub] of Object.entries(getObjectShape(schema))) {
|
|
554
|
-
assertSupportedKinds(sub, [...path, key], lazyGetters);
|
|
555
|
-
}
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
if (isZodSchemaType(schema, "ZodArray")) {
|
|
559
|
-
const inner = getArrayElement(schema);
|
|
560
|
-
if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
if (isZodSchemaType(schema, "ZodSet")) {
|
|
564
|
-
const inner = getSetValueType(schema);
|
|
565
|
-
if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
if (isZodSchemaType(schema, "ZodRecord")) {
|
|
569
|
-
const inner = getRecordValueType(schema);
|
|
570
|
-
if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
if (isZodSchemaType(schema, "ZodTuple")) {
|
|
574
|
-
const items = getTupleItems(schema);
|
|
575
|
-
items.forEach((item, i) => assertSupportedKinds(item, [...path, String(i)], lazyGetters));
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
if (isZodSchemaType(schema, "ZodUnion")) {
|
|
579
|
-
const options = getUnionOptions(schema);
|
|
580
|
-
options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
if (isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
|
|
584
|
-
const options = getDiscriminatedOptions(schema);
|
|
585
|
-
options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
if (isZodSchemaType(schema, "ZodIntersection")) {
|
|
589
|
-
const left = getIntersectionLeft(schema);
|
|
590
|
-
if (left) assertSupportedKinds(left, [...path, "left"], lazyGetters);
|
|
591
|
-
const right = getIntersectionRight(schema);
|
|
592
|
-
if (right) assertSupportedKinds(right, [...path, "right"], lazyGetters);
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodCatch")) {
|
|
596
|
-
const inner = unwrapInner(schema);
|
|
597
|
-
if (inner) assertSupportedKinds(inner, path, lazyGetters);
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
if (isZodSchemaType(schema, "ZodBranded")) {
|
|
601
|
-
const inner = unwrapBranded(schema);
|
|
602
|
-
if (inner) assertSupportedKinds(inner, path, lazyGetters);
|
|
603
|
-
return;
|
|
604
|
-
}
|
|
605
|
-
if (isZodSchemaType(schema, "ZodEffects")) {
|
|
606
|
-
const inner = unwrapEffectsSource(schema);
|
|
607
|
-
if (inner) assertSupportedKinds(inner, path, lazyGetters);
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
if (isZodSchemaType(schema, "ZodPipeline")) {
|
|
611
|
-
const inner = unwrapPipeIn(schema);
|
|
612
|
-
if (inner) assertSupportedKinds(inner, path, lazyGetters);
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
if (isZodSchemaType(schema, "ZodLazy")) {
|
|
616
|
-
const getter = getLazyGetter(schema);
|
|
617
|
-
if (getter !== void 0 && lazyGetters.includes(getter)) return;
|
|
618
|
-
const inner = getter?.();
|
|
619
|
-
if (inner !== void 0) {
|
|
620
|
-
assertSupportedKinds(
|
|
621
|
-
inner,
|
|
622
|
-
path,
|
|
623
|
-
getter === void 0 ? lazyGetters : [...lazyGetters, getter]
|
|
624
|
-
);
|
|
625
|
-
}
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
608
|
+
function stripAsyncChecks(schema) {
|
|
609
|
+
return walkEffects(schema, "strip");
|
|
628
610
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
kindOf: (schema) => kindOf(schema),
|
|
632
|
-
getObjectShape,
|
|
633
|
-
getTupleItems,
|
|
634
|
-
getDiscriminatedOptions: (schema) => getDiscriminatedOptions(schema),
|
|
635
|
-
getDiscriminator,
|
|
636
|
-
getLiteralValues,
|
|
637
|
-
isPreprocessNode,
|
|
638
|
-
isCoercePrimitive,
|
|
639
|
-
containsAsyncRefine,
|
|
640
|
-
containsAsyncTransform,
|
|
641
|
-
hasContainerOrRootRefine,
|
|
642
|
-
// Walker accessors (D2 / D3 / D5).
|
|
643
|
-
getArrayElement,
|
|
644
|
-
getSetValueType,
|
|
645
|
-
getRecordKeyType,
|
|
646
|
-
getRecordValueType,
|
|
647
|
-
getUnionOptions,
|
|
648
|
-
getIntersectionLeft,
|
|
649
|
-
getIntersectionRight,
|
|
650
|
-
getEnumValues: (schema) => {
|
|
651
|
-
if (!isZodSchemaType(schema, "ZodEnum")) return [];
|
|
652
|
-
return schema.options;
|
|
653
|
-
},
|
|
654
|
-
getNativeEnumValues,
|
|
655
|
-
unwrapInner,
|
|
656
|
-
unwrapBranded,
|
|
657
|
-
unwrapEffectsSource,
|
|
658
|
-
unwrapPipeIn,
|
|
659
|
-
unwrapPipeOut,
|
|
660
|
-
unwrapLazy,
|
|
661
|
-
getLazyGetter,
|
|
662
|
-
getDefaultValue: getDefaultValue$1,
|
|
663
|
-
getCatchDefault,
|
|
664
|
-
hasCatchValue
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
function slimPrimitivesV3(schema) {
|
|
668
|
-
return new Set(walkFieldMeta.slimPrimitivesWalk(schema, V3_INTROSPECTOR, 64));
|
|
611
|
+
function wrapAsyncSafeRefinements(schema) {
|
|
612
|
+
return walkEffects(schema, "wrap");
|
|
669
613
|
}
|
|
670
|
-
|
|
671
|
-
|
|
614
|
+
function isThenable(value) {
|
|
615
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
616
|
+
}
|
|
617
|
+
function walkEffects(schema, policy) {
|
|
672
618
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
673
619
|
function recurse(s) {
|
|
674
620
|
const candidate = s;
|
|
@@ -677,7 +623,26 @@ function stripAsyncChecks(schema) {
|
|
|
677
623
|
seen.add(candidate);
|
|
678
624
|
if (isZodSchemaType(s, "ZodEffects")) {
|
|
679
625
|
const inner = unwrapEffectsSource(s);
|
|
680
|
-
|
|
626
|
+
if (inner === void 0) return s;
|
|
627
|
+
if (policy === "strip") return recurse(inner);
|
|
628
|
+
const effect = getEffect(s);
|
|
629
|
+
const rebuiltInner = recurse(inner);
|
|
630
|
+
const original = effect?.["refinement"];
|
|
631
|
+
if (effect === void 0 || typeof original !== "function") {
|
|
632
|
+
return rebuildEffects(s, rebuiltInner, effect);
|
|
633
|
+
}
|
|
634
|
+
const refine = original;
|
|
635
|
+
const safeEffect = {
|
|
636
|
+
...effect,
|
|
637
|
+
refinement: (value, ctx) => {
|
|
638
|
+
const result = refine(value, ctx);
|
|
639
|
+
if (isThenable(result)) {
|
|
640
|
+
void result.catch(() => void 0);
|
|
641
|
+
}
|
|
642
|
+
return result;
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
return rebuildEffects(s, rebuiltInner, safeEffect);
|
|
681
646
|
}
|
|
682
647
|
if (isZodSchemaType(s, "ZodOptional")) {
|
|
683
648
|
const inner = unwrapInner(s);
|
|
@@ -690,7 +655,7 @@ function stripAsyncChecks(schema) {
|
|
|
690
655
|
if (isZodSchemaType(s, "ZodDefault")) {
|
|
691
656
|
const inner = unwrapInner(s);
|
|
692
657
|
if (inner === void 0) return s;
|
|
693
|
-
const def = getDefaultValue
|
|
658
|
+
const def = getDefaultValue(s);
|
|
694
659
|
return recurse(inner).default(def);
|
|
695
660
|
}
|
|
696
661
|
if (isZodSchemaType(s, "ZodCatch")) {
|
|
@@ -823,89 +788,88 @@ function carryObjectChecks(rebuilt, original) {
|
|
|
823
788
|
return next;
|
|
824
789
|
}
|
|
825
790
|
|
|
826
|
-
const PATH_SEPARATOR = ".";
|
|
827
791
|
const MAX_UNWRAP_STEPS = 64;
|
|
828
|
-
function isPrimitive(input) {
|
|
829
|
-
const type = typeof input;
|
|
830
|
-
if (type === "string" || type === "number" || type === "boolean" || type === "bigint" || type === "undefined")
|
|
831
|
-
return true;
|
|
832
|
-
return input === null;
|
|
833
|
-
}
|
|
834
|
-
function constraintsAreSlimValid(slimSchema, constraints) {
|
|
835
|
-
try {
|
|
836
|
-
return slimSchema.safeParse(constraints).success;
|
|
837
|
-
} catch {
|
|
838
|
-
return false;
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
let warnedZodCodeMissing = false;
|
|
842
792
|
function zodAdapter(zodSchema) {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
stripZodEffects: true,
|
|
849
|
-
stripZodRefinements: true
|
|
850
|
-
});
|
|
851
|
-
if (!isZodSchemaType(_strippedRoot, "ZodObject") && !isZodSchemaType(_strippedRoot, "ZodRecord") && !isZodSchemaType(_strippedRoot, "ZodDiscriminatedUnion")) {
|
|
852
|
-
const name = getTypeName(_strippedRoot);
|
|
853
|
-
throw new Error(
|
|
854
|
-
`Attaform: useForm schema root must be a ZodObject, ZodRecord, or ZodDiscriminatedUnion (got ${name}). Wrap other shapes under a key.`
|
|
793
|
+
const peeledRoot = peelAllV3Wrappers(zodSchema);
|
|
794
|
+
if (!isZodSchemaType(peeledRoot, "ZodObject") && !isZodSchemaType(peeledRoot, "ZodRecord") && !isZodSchemaType(peeledRoot, "ZodDiscriminatedUnion")) {
|
|
795
|
+
const name = getTypeName(peeledRoot) ?? "unknown";
|
|
796
|
+
throw new AttaformError(
|
|
797
|
+
`[attaform] AF15 attaform.dev/e/af15 '${name}'`
|
|
855
798
|
);
|
|
856
799
|
}
|
|
857
|
-
return (formKey, options) =>
|
|
800
|
+
return (formKey, options) => createAbstractSchema(
|
|
858
801
|
zodSchema,
|
|
859
802
|
V3_INTROSPECTOR,
|
|
860
|
-
buildV3Services(),
|
|
803
|
+
buildV3Services(options.maxRecursionDepth),
|
|
861
804
|
formKey,
|
|
862
805
|
options
|
|
863
806
|
);
|
|
864
807
|
}
|
|
865
808
|
async function lazyFingerprint(schema) {
|
|
866
|
-
const { fingerprintZodSchema } = await import('../chunks/fingerprint.
|
|
809
|
+
const { fingerprintZodSchema } = await import('../chunks/fingerprint.mjs');
|
|
867
810
|
return fingerprintZodSchema(schema);
|
|
868
811
|
}
|
|
869
|
-
|
|
812
|
+
const syncSafeCache = /* @__PURE__ */ new WeakMap();
|
|
813
|
+
function syncSafe(schema) {
|
|
814
|
+
const cached = syncSafeCache.get(schema);
|
|
815
|
+
if (cached !== void 0) return cached;
|
|
816
|
+
const wrapped = wrapAsyncSafeRefinements(schema);
|
|
817
|
+
syncSafeCache.set(schema, wrapped);
|
|
818
|
+
return wrapped;
|
|
819
|
+
}
|
|
820
|
+
function buildV3Services(maxRecursionDepth) {
|
|
821
|
+
const mapOrSetBySchema = /* @__PURE__ */ new WeakMap();
|
|
822
|
+
const refileIssues = (schema, data, issues) => {
|
|
823
|
+
let hasMapOrSet = mapOrSetBySchema.get(schema);
|
|
824
|
+
if (hasMapOrSet === void 0) {
|
|
825
|
+
hasMapOrSet = containsMapOrSet(schema);
|
|
826
|
+
mapOrSetBySchema.set(schema, hasMapOrSet);
|
|
827
|
+
}
|
|
828
|
+
if (!hasMapOrSet) return issues;
|
|
829
|
+
return normalizeIssuePaths(issues, schema, data, maxRecursionDepth, peelAllV3Wrappers);
|
|
830
|
+
};
|
|
870
831
|
return {
|
|
871
832
|
fingerprint: (schema) => lazyFingerprint(schema),
|
|
872
|
-
getNestedSchemasAtPath: (schema, path,
|
|
833
|
+
getNestedSchemasAtPath: (schema, path, maxRecursionDepth2) => getNestedZodSchemasAtPath(schema, path, maxRecursionDepth2),
|
|
873
834
|
// v3 pre-strips refinements / defaults / wrappers off the root for
|
|
874
835
|
// slim-mode walks — `getSlimPrimitiveTypesAtPath` and
|
|
875
836
|
// `getSchemasAtPath` both consume this variant so the yielded
|
|
876
837
|
// candidates reflect the slim shape.
|
|
877
|
-
|
|
838
|
+
// The slim-root projection is gone (size-teardown P7): the shared
|
|
839
|
+
// path walker peels wrappers / effects inline, so the slim and
|
|
840
|
+
// unstripped walks coincide — same aliasing v4 always had.
|
|
841
|
+
getNestedSchemasInSlimMode: (schema, path, maxRecursionDepth2) => getNestedZodSchemasAtPath(schema, path, maxRecursionDepth2),
|
|
878
842
|
slimPrimitivesOf: (schema, _maxRecursionDepth) => slimPrimitivesV3(schema),
|
|
879
843
|
deriveDefault: (schema, useDefault, _maxRecursionDepth, formKey) => getDefaultValuesFromZodSchema(schema, useDefault, formKey),
|
|
880
|
-
runStrictGetDefaults: (schema, config, formKey,
|
|
844
|
+
runStrictGetDefaults: (schema, config, formKey, maxRecursionDepth2) => runStrictGetDefaultsV3(schema, config, formKey, maxRecursionDepth2),
|
|
881
845
|
unwrapStructuralWrappers: (schema) => unwrapStructuralLeafV3(schema),
|
|
882
846
|
unwrapToDiscriminatedUnion: (schema) => unwrapToDiscriminatedUnion(schema),
|
|
883
847
|
peelAllWrappers: (schema) => peelAllV3Wrappers(schema),
|
|
884
848
|
isLeafRequired: (schema) => isLeafRequiredV3(schema),
|
|
885
|
-
resolveFieldMetaAtPath: (schema, path,
|
|
886
|
-
issuesToValidationErrors: (issues
|
|
849
|
+
resolveFieldMetaAtPath: (schema, path, maxRecursionDepth2) => resolveFieldMetaAtPathV3(schema, path, maxRecursionDepth2),
|
|
850
|
+
issuesToValidationErrors: (issues) => zodIssuesToValidationErrors(issues),
|
|
887
851
|
safeParseSync: (schema, data) => {
|
|
888
|
-
const result = schema.safeParse(data);
|
|
889
|
-
return result.success ? { success: true, data: result.data } : { success: false, issues: result.error.issues };
|
|
852
|
+
const result = syncSafe(schema).safeParse(data);
|
|
853
|
+
return result.success ? { success: true, data: result.data } : { success: false, issues: refileIssues(schema, data, result.error.issues) };
|
|
890
854
|
},
|
|
891
855
|
safeParseAsync: async (schema, data) => {
|
|
892
856
|
const result = await schema.safeParseAsync(data);
|
|
893
|
-
return result.success ? { success: true, data: result.data } : { success: false, issues: result.error.issues };
|
|
857
|
+
return result.success ? { success: true, data: result.data } : { success: false, issues: refileIssues(schema, data, result.error.issues) };
|
|
894
858
|
},
|
|
895
859
|
// v3 returns the full recursive AbstractSchema for sub-schemas (the
|
|
896
860
|
// historical shape) — `getSchemasAtPath` consumers may probe any
|
|
897
861
|
// method on the result. The factory call rebuilds the full surface
|
|
898
862
|
// against the sub-schema with its own per-form caches.
|
|
899
|
-
makeSubSchema: (sub, formKey,
|
|
863
|
+
makeSubSchema: (sub, formKey, maxRecursionDepth2) => createAbstractSchema(
|
|
900
864
|
sub,
|
|
901
865
|
V3_INTROSPECTOR,
|
|
902
|
-
buildV3Services(),
|
|
866
|
+
buildV3Services(maxRecursionDepth2),
|
|
903
867
|
formKey,
|
|
904
|
-
{ maxRecursionDepth }
|
|
868
|
+
{ maxRecursionDepth: maxRecursionDepth2 }
|
|
905
869
|
)
|
|
906
870
|
};
|
|
907
871
|
}
|
|
908
|
-
function zodIssuesToValidationErrors(issues
|
|
872
|
+
function zodIssuesToValidationErrors(issues) {
|
|
909
873
|
const validationErrors = [];
|
|
910
874
|
for (const issue of issues) {
|
|
911
875
|
let code;
|
|
@@ -913,12 +877,6 @@ function zodIssuesToValidationErrors(issues, formKey) {
|
|
|
913
877
|
code = `zod:${issue.code}`;
|
|
914
878
|
} else {
|
|
915
879
|
code = "zod:unknown";
|
|
916
|
-
if (devtoolsShared.__DEV__ && !warnedZodCodeMissing) {
|
|
917
|
-
warnedZodCodeMissing = true;
|
|
918
|
-
console.warn(
|
|
919
|
-
"[attaform] zod-v3 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."
|
|
920
|
-
);
|
|
921
|
-
}
|
|
922
880
|
}
|
|
923
881
|
validationErrors.push({
|
|
924
882
|
message: issue.message,
|
|
@@ -934,7 +892,6 @@ function zodIssuesToValidationErrors(issues, formKey) {
|
|
|
934
892
|
// to absolutise, then routes form-level (absolute path length 0)
|
|
935
893
|
// entries to the empty-string bucket at storage time.
|
|
936
894
|
path: coercePathSegments(issue.path),
|
|
937
|
-
formKey,
|
|
938
895
|
code
|
|
939
896
|
});
|
|
940
897
|
}
|
|
@@ -949,7 +906,7 @@ function coercePathSegments(path) {
|
|
|
949
906
|
}
|
|
950
907
|
function getNestedZodSchemasAtPath(schema, segments, maxRecursionDepth) {
|
|
951
908
|
if (segments.length === 0) return [schema];
|
|
952
|
-
return
|
|
909
|
+
return walkPathSegments(schema, segments.map(String), V3_INTROSPECTOR, maxRecursionDepth, 0);
|
|
953
910
|
}
|
|
954
911
|
function unwrapStructuralLeafV3(schema) {
|
|
955
912
|
let current = schema;
|
|
@@ -1094,271 +1051,6 @@ function unwrapToDiscriminatedUnion(schema, depth = 0) {
|
|
|
1094
1051
|
}
|
|
1095
1052
|
return void 0;
|
|
1096
1053
|
}
|
|
1097
|
-
function getDefaultValue(expected, context) {
|
|
1098
|
-
const discriminatorContext = context.discriminator;
|
|
1099
|
-
if (discriminatorContext.isDiscriminatorKey) {
|
|
1100
|
-
if (!discriminatorContext.schema) {
|
|
1101
|
-
throw new Error("discriminatorContext.schema unspecified");
|
|
1102
|
-
}
|
|
1103
|
-
if (!isZodSchemaType(discriminatorContext.schema, "ZodDiscriminatedUnion")) {
|
|
1104
|
-
throw new TypeError(
|
|
1105
|
-
"Programming error: discriminatorContext.schema is not a ZodDiscriminatedUnion schema."
|
|
1106
|
-
);
|
|
1107
|
-
}
|
|
1108
|
-
const optionDiscriminator = getSchemaByDiscriminatorKey(
|
|
1109
|
-
discriminatorContext.schema);
|
|
1110
|
-
if (!optionDiscriminator) {
|
|
1111
|
-
throw new Error("ZodDiscriminatedUnion: default option not found");
|
|
1112
|
-
}
|
|
1113
|
-
return getDefaultValuesFromZodSchema(
|
|
1114
|
-
optionDiscriminator,
|
|
1115
|
-
discriminatorContext.useDefaultSchemaValues,
|
|
1116
|
-
context.formKey
|
|
1117
|
-
);
|
|
1118
|
-
}
|
|
1119
|
-
if (expected === "string") return "";
|
|
1120
|
-
if (expected === "number") return 0;
|
|
1121
|
-
if (expected === "array") return [];
|
|
1122
|
-
if (expected === "boolean") return false;
|
|
1123
|
-
if (expected === "bigint") return 0n;
|
|
1124
|
-
if (expected === "float") return 0;
|
|
1125
|
-
if (expected === "integer") return 0;
|
|
1126
|
-
if (expected === "null") return null;
|
|
1127
|
-
if (expected === "object") return {};
|
|
1128
|
-
if (expected === "set") return /* @__PURE__ */ new Set();
|
|
1129
|
-
if (expected === "date") return /* @__PURE__ */ new Date();
|
|
1130
|
-
if (expected === "undefined") return void 0;
|
|
1131
|
-
if (expected === "unknown") return void 0;
|
|
1132
|
-
if (expected === "nan") return Number("nan");
|
|
1133
|
-
return void 0;
|
|
1134
|
-
}
|
|
1135
|
-
function getDefaultValuesFromZodSchema(formSchema, useDefaultSchemaValues, formKey) {
|
|
1136
|
-
return walkFieldMeta.deriveDefaultWalk(formSchema, useDefaultSchemaValues, V3_INTROSPECTOR, 64, {
|
|
1137
|
-
unsupportedKindFallback: (schema) => {
|
|
1138
|
-
console.warn(
|
|
1139
|
-
`[attaform] zod-v3 adapter: unsupported schema kind '${schema.constructor?.name ?? "unknown"}' on form '${formKey}'. Defaulting the field to null. Use a supported zod kind (object/array/record/string/number/etc.) at this path.`
|
|
1140
|
-
);
|
|
1141
|
-
return null;
|
|
1142
|
-
},
|
|
1143
|
-
// v3 historically surfaces the `.catch(v)` fallback even when
|
|
1144
|
-
// `useDefaultSchemaValues=false`. Pinned by
|
|
1145
|
-
// `test/adapters/zod-v3/wrappers.test.ts` ('surfaces the catch
|
|
1146
|
-
// fallback even when useDefaultSchemaValues is false').
|
|
1147
|
-
catchOnUseDefaultFalse: "preserveCatch"
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
function getSchemaByDiscriminatorKey(unionSchema, key) {
|
|
1151
|
-
if (!isZodSchemaType(unionSchema, "ZodDiscriminatedUnion")) {
|
|
1152
|
-
throw new TypeError("Provided schema is not a discriminated union.");
|
|
1153
|
-
}
|
|
1154
|
-
{
|
|
1155
|
-
const options = getDiscriminatedOptions(unionSchema);
|
|
1156
|
-
if (!options.length) {
|
|
1157
|
-
throw new TypeError("Provided ZodDiscriminatedUnion does not have any options");
|
|
1158
|
-
}
|
|
1159
|
-
return options[0];
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
function stripRefinements(schema) {
|
|
1163
|
-
function _stripRefinements(_schema, depth) {
|
|
1164
|
-
if (depth >= MAX_UNWRAP_STEPS) return _schema;
|
|
1165
|
-
if (isZodSchemaType(_schema, "ZodString") && hasChecks(_schema)) {
|
|
1166
|
-
return stripLeafChecks(_schema);
|
|
1167
|
-
}
|
|
1168
|
-
if (isZodSchemaType(_schema, "ZodNumber") && hasChecks(_schema)) {
|
|
1169
|
-
return stripLeafChecks(_schema);
|
|
1170
|
-
}
|
|
1171
|
-
if (isZodSchemaType(_schema, "ZodArray")) {
|
|
1172
|
-
const inner = getArrayElement(_schema);
|
|
1173
|
-
if (!inner) return _schema;
|
|
1174
|
-
return rebuildArray(_schema, _stripRefinements(inner, depth + 1));
|
|
1175
|
-
}
|
|
1176
|
-
if (isZodSchemaType(_schema, "ZodObject")) {
|
|
1177
|
-
const strippedShape = Object.fromEntries(
|
|
1178
|
-
Object.entries(getObjectShape(_schema)).map(([key, value]) => [
|
|
1179
|
-
key,
|
|
1180
|
-
_stripRefinements(value, depth + 1)
|
|
1181
|
-
])
|
|
1182
|
-
);
|
|
1183
|
-
return rebuildObject(_schema, strippedShape);
|
|
1184
|
-
}
|
|
1185
|
-
if (isZodSchemaType(_schema, "ZodEffects")) {
|
|
1186
|
-
const inner = unwrapEffectsSource(_schema);
|
|
1187
|
-
if (!inner) return _schema;
|
|
1188
|
-
return _stripRefinements(inner, depth + 1);
|
|
1189
|
-
}
|
|
1190
|
-
if (isZodSchemaType(_schema, "ZodOptional")) {
|
|
1191
|
-
const inner = unwrapInner(_schema);
|
|
1192
|
-
if (!inner) return _schema;
|
|
1193
|
-
return rebuildWrapperInner(_schema, _stripRefinements(inner, depth + 1));
|
|
1194
|
-
}
|
|
1195
|
-
if (isZodSchemaType(_schema, "ZodNullable")) {
|
|
1196
|
-
const inner = unwrapInner(_schema);
|
|
1197
|
-
if (!inner) return _schema;
|
|
1198
|
-
return rebuildWrapperInner(_schema, _stripRefinements(inner, depth + 1));
|
|
1199
|
-
}
|
|
1200
|
-
if (isZodSchemaType(_schema, "ZodReadonly")) {
|
|
1201
|
-
const inner = unwrapInner(_schema);
|
|
1202
|
-
if (!inner) return _schema;
|
|
1203
|
-
return _stripRefinements(inner, depth + 1);
|
|
1204
|
-
}
|
|
1205
|
-
if (isZodSchemaType(_schema, "ZodBranded")) {
|
|
1206
|
-
const inner = unwrapBranded(_schema);
|
|
1207
|
-
if (!inner) return _schema;
|
|
1208
|
-
return _stripRefinements(inner, depth + 1);
|
|
1209
|
-
}
|
|
1210
|
-
if (isZodSchemaType(_schema, "ZodPipeline")) {
|
|
1211
|
-
const inner = unwrapPipeIn(_schema);
|
|
1212
|
-
if (!inner) return _schema;
|
|
1213
|
-
return _stripRefinements(inner, depth + 1);
|
|
1214
|
-
}
|
|
1215
|
-
if (isZodSchemaType(_schema, "ZodSet")) {
|
|
1216
|
-
const valueType = getSetValueType(_schema);
|
|
1217
|
-
if (!valueType) return _schema;
|
|
1218
|
-
return rebuildSet(_schema, _stripRefinements(valueType, depth + 1));
|
|
1219
|
-
}
|
|
1220
|
-
if (isZodSchemaType(_schema, "ZodTuple")) {
|
|
1221
|
-
const items = getTupleItems(_schema);
|
|
1222
|
-
if (items.length === 0) return _schema;
|
|
1223
|
-
const stripped = items.map((it) => _stripRefinements(it, depth + 1));
|
|
1224
|
-
return rebuildTuple(_schema, stripped);
|
|
1225
|
-
}
|
|
1226
|
-
if (isZodSchemaType(_schema, "ZodRecord")) {
|
|
1227
|
-
const valueType = getRecordValueType(_schema);
|
|
1228
|
-
if (!valueType) return _schema;
|
|
1229
|
-
const value = _stripRefinements(valueType, depth + 1);
|
|
1230
|
-
const keyType = getRecordKeyType(_schema);
|
|
1231
|
-
if (keyType) {
|
|
1232
|
-
return rebuildRecord(_schema, value, keyType);
|
|
1233
|
-
}
|
|
1234
|
-
return rebuildRecord(_schema, value);
|
|
1235
|
-
}
|
|
1236
|
-
if (isZodSchemaType(_schema, "ZodUnion")) {
|
|
1237
|
-
const options = getUnionOptions(_schema);
|
|
1238
|
-
if (options.length === 0) return _schema;
|
|
1239
|
-
const stripped = options.map((o) => _stripRefinements(o, depth + 1));
|
|
1240
|
-
return rebuildUnion(_schema, stripped);
|
|
1241
|
-
}
|
|
1242
|
-
if (isZodSchemaType(_schema, "ZodDiscriminatedUnion")) {
|
|
1243
|
-
const discKey = getDiscriminator(_schema);
|
|
1244
|
-
const options = getDiscriminatedOptions(_schema);
|
|
1245
|
-
if (discKey === void 0 || options.length === 0) return _schema;
|
|
1246
|
-
const stripped = options.map(
|
|
1247
|
-
(o) => _stripRefinements(o, depth + 1)
|
|
1248
|
-
);
|
|
1249
|
-
return rebuildDiscriminatedUnion(_schema, stripped);
|
|
1250
|
-
}
|
|
1251
|
-
if (isZodSchemaType(_schema, "ZodIntersection")) {
|
|
1252
|
-
const left = getIntersectionLeft(_schema);
|
|
1253
|
-
const right = getIntersectionRight(_schema);
|
|
1254
|
-
if (!left || !right) return _schema;
|
|
1255
|
-
return rebuildIntersection(
|
|
1256
|
-
_schema,
|
|
1257
|
-
_stripRefinements(left, depth + 1),
|
|
1258
|
-
_stripRefinements(right, depth + 1)
|
|
1259
|
-
);
|
|
1260
|
-
}
|
|
1261
|
-
if (isZodSchemaType(_schema, "ZodLazy")) {
|
|
1262
|
-
const inner = unwrapLazy(_schema);
|
|
1263
|
-
if (!inner) return _schema;
|
|
1264
|
-
const stripped = _stripRefinements(inner, depth + 1);
|
|
1265
|
-
return rebuildLazy(_schema, stripped);
|
|
1266
|
-
}
|
|
1267
|
-
return _schema;
|
|
1268
|
-
}
|
|
1269
|
-
return _stripRefinements(schema, 0);
|
|
1270
|
-
}
|
|
1271
|
-
function stripRootSchema(schema, stripConfig) {
|
|
1272
|
-
function recursion(_schema, _stripped = false) {
|
|
1273
|
-
if (getStripInstruction(stripConfig.stripNullable, _schema) && isZodSchemaType(_schema, "ZodNullable")) {
|
|
1274
|
-
return recursion(_schema.unwrap(), true);
|
|
1275
|
-
}
|
|
1276
|
-
if (getStripInstruction(stripConfig.stripOptional, _schema) && isZodSchemaType(_schema, "ZodOptional")) {
|
|
1277
|
-
return recursion(_schema.unwrap(), true);
|
|
1278
|
-
}
|
|
1279
|
-
if (getStripInstruction(stripConfig.stripZodEffects, _schema) && isZodSchemaType(_schema, "ZodEffects")) {
|
|
1280
|
-
const inner = unwrapEffectsSource(_schema);
|
|
1281
|
-
if (inner) return recursion(inner, true);
|
|
1282
|
-
}
|
|
1283
|
-
if (getStripInstruction(stripConfig.stripDefaultValues, _schema) && isZodSchemaType(_schema, "ZodDefault")) {
|
|
1284
|
-
const inner = unwrapInner(_schema);
|
|
1285
|
-
if (inner) return recursion(inner, true);
|
|
1286
|
-
}
|
|
1287
|
-
if (getStripInstruction(stripConfig.stripZodRefinements, _schema) && hasChecks(_schema)) {
|
|
1288
|
-
return recursion(stripRefinements(_schema));
|
|
1289
|
-
}
|
|
1290
|
-
return [_schema, _stripped];
|
|
1291
|
-
}
|
|
1292
|
-
return recursion(schema, false);
|
|
1293
|
-
}
|
|
1294
|
-
const getStripInstruction = (stripValueOrCallback, schema) => {
|
|
1295
|
-
if (stripValueOrCallback === void 0 || stripValueOrCallback === false) return false;
|
|
1296
|
-
return typeof stripValueOrCallback === "function" ? stripValueOrCallback(schema) : stripValueOrCallback;
|
|
1297
|
-
};
|
|
1298
|
-
function getSlimSchema(config) {
|
|
1299
|
-
function _getSlimSchema(_schema) {
|
|
1300
|
-
if (isZodSchemaType(_schema, "ZodObject")) {
|
|
1301
|
-
const newShape = {};
|
|
1302
|
-
for (const [key, value] of Object.entries(getObjectShape(_schema))) {
|
|
1303
|
-
newShape[key] = _getSlimSchema(value);
|
|
1304
|
-
}
|
|
1305
|
-
return rebuildObject(_schema, newShape);
|
|
1306
|
-
}
|
|
1307
|
-
if (isZodSchemaType(_schema, "ZodArray")) {
|
|
1308
|
-
const inner = getArrayElement(_schema);
|
|
1309
|
-
if (!inner) return _schema;
|
|
1310
|
-
return rebuildArray(_schema, _getSlimSchema(inner));
|
|
1311
|
-
}
|
|
1312
|
-
if (isZodSchemaType(_schema, "ZodRecord")) {
|
|
1313
|
-
const keyType = getRecordKeyType(_schema);
|
|
1314
|
-
const valueType = getRecordValueType(_schema);
|
|
1315
|
-
if (!keyType || !valueType) return _schema;
|
|
1316
|
-
const key = _getSlimSchema(keyType);
|
|
1317
|
-
const value = _getSlimSchema(valueType);
|
|
1318
|
-
return rebuildRecord(_schema, value, key);
|
|
1319
|
-
}
|
|
1320
|
-
if (isZodSchemaType(_schema, "ZodDiscriminatedUnion")) {
|
|
1321
|
-
const slimmedSchemas = [];
|
|
1322
|
-
const discKey = getDiscriminator(_schema);
|
|
1323
|
-
if (discKey === void 0) return _schema;
|
|
1324
|
-
for (const option of getDiscriminatedOptions(_schema)) {
|
|
1325
|
-
const slimmedSchema = _getSlimSchema(option);
|
|
1326
|
-
const deepCloneSlimmedSchema = cloneSchemaDeep(slimmedSchema);
|
|
1327
|
-
slimmedSchemas.push(deepCloneSlimmedSchema);
|
|
1328
|
-
}
|
|
1329
|
-
return rebuildDiscriminatedUnion(
|
|
1330
|
-
_schema,
|
|
1331
|
-
slimmedSchemas
|
|
1332
|
-
);
|
|
1333
|
-
}
|
|
1334
|
-
if (getStripInstruction(config.stripConfig.stripZodEffects, _schema) && isZodSchemaType(_schema, "ZodEffects")) {
|
|
1335
|
-
const inner = unwrapEffectsSource(_schema);
|
|
1336
|
-
if (inner) return _getSlimSchema(inner);
|
|
1337
|
-
}
|
|
1338
|
-
if (getStripInstruction(config.stripConfig.stripNullable, _schema) && isZodSchemaType(_schema, "ZodNullable")) {
|
|
1339
|
-
const inner = unwrapInner(_schema);
|
|
1340
|
-
if (inner) return _getSlimSchema(inner);
|
|
1341
|
-
}
|
|
1342
|
-
if (getStripInstruction(config.stripConfig.stripOptional, _schema) && isZodSchemaType(_schema, "ZodOptional")) {
|
|
1343
|
-
const inner = unwrapInner(_schema);
|
|
1344
|
-
if (inner) return _getSlimSchema(inner);
|
|
1345
|
-
}
|
|
1346
|
-
if (getStripInstruction(config.stripConfig.stripZodRefinements, _schema) && hasChecks(_schema)) {
|
|
1347
|
-
return stripRefinements(_schema);
|
|
1348
|
-
}
|
|
1349
|
-
if (getStripInstruction(config.stripConfig.stripDefaultValues, _schema) && isZodSchemaType(_schema, "ZodDefault")) {
|
|
1350
|
-
const inner = unwrapInner(_schema);
|
|
1351
|
-
if (inner) return _getSlimSchema(inner);
|
|
1352
|
-
}
|
|
1353
|
-
const unionSchema = unwrapToDiscriminatedUnion(_schema);
|
|
1354
|
-
if (unionSchema && getStripInstruction(config.stripConfig.stripDefaultValues, unionSchema)) {
|
|
1355
|
-
return _getSlimSchema(unionSchema);
|
|
1356
|
-
}
|
|
1357
|
-
return _schema;
|
|
1358
|
-
}
|
|
1359
|
-
const processedRootSchema = stripRootSchema(config.schema, config.stripConfig)[0];
|
|
1360
|
-
return _getSlimSchema(processedRootSchema);
|
|
1361
|
-
}
|
|
1362
1054
|
function peelAllV3Wrappers(schema) {
|
|
1363
1055
|
let current = schema;
|
|
1364
1056
|
for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
|
|
@@ -1385,30 +1077,41 @@ function peelAllV3Wrappers(schema) {
|
|
|
1385
1077
|
}
|
|
1386
1078
|
return current;
|
|
1387
1079
|
}
|
|
1080
|
+
function getDefaultValuesFromZodSchema(formSchema, useDefaultSchemaValues, formKey) {
|
|
1081
|
+
return deriveDefaultWalk(formSchema, useDefaultSchemaValues, V3_INTROSPECTOR, 64, {
|
|
1082
|
+
unsupportedKindFallback: (schema) => {
|
|
1083
|
+
const kindName = schema.constructor?.name ?? "unknown";
|
|
1084
|
+
console.warn(
|
|
1085
|
+
`[attaform] AF13 attaform.dev/e/af13 '${kindName}' on '${formKey}'`
|
|
1086
|
+
);
|
|
1087
|
+
return null;
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1388
1091
|
function resolveFieldMetaAtPathV3(rootSchema, path, maxRecursionDepth) {
|
|
1389
1092
|
const lastSegment = path.length === 0 ? "" : path[path.length - 1];
|
|
1390
1093
|
const target = path.length === 0 ? rootSchema : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth)[0];
|
|
1391
1094
|
if (target === void 0) {
|
|
1392
1095
|
return {
|
|
1393
|
-
label:
|
|
1096
|
+
label: humanize(lastSegment),
|
|
1394
1097
|
description: void 0,
|
|
1395
1098
|
placeholder: void 0,
|
|
1396
1099
|
meta: Object.freeze({})
|
|
1397
1100
|
};
|
|
1398
1101
|
}
|
|
1399
|
-
const pathMap =
|
|
1102
|
+
const pathMap = buildFieldMetaPathMap(rootSchema, {
|
|
1400
1103
|
intro: V3_INTROSPECTOR,
|
|
1401
1104
|
peelAllWrappers: peelAllV3Wrappers,
|
|
1402
|
-
getFieldMetaList
|
|
1105
|
+
getFieldMetaList: getFieldMetaListForSchema
|
|
1403
1106
|
});
|
|
1404
|
-
const pathKey =
|
|
1107
|
+
const pathKey = canonicalizePath(path).key;
|
|
1405
1108
|
const peeled = peelV3Wrappers(target);
|
|
1406
|
-
const payload = pathMap
|
|
1109
|
+
const payload = pathMap?.get(pathKey) ?? getFieldMetaForSchema(target) ?? (peeled !== target ? getFieldMetaForSchema(peeled) : void 0);
|
|
1407
1110
|
const targetDescription = typeof target.description === "string" ? target.description : void 0;
|
|
1408
1111
|
const peeledDescription = peeled !== target && typeof peeled.description === "string" ? peeled.description : void 0;
|
|
1409
1112
|
const schemaDescription = targetDescription ?? peeledDescription;
|
|
1410
1113
|
return {
|
|
1411
|
-
label: payload?.label ??
|
|
1114
|
+
label: payload?.label ?? humanize(lastSegment),
|
|
1412
1115
|
description: payload?.description ?? schemaDescription ?? void 0,
|
|
1413
1116
|
placeholder: payload?.placeholder ?? void 0,
|
|
1414
1117
|
meta: Object.freeze({ ...payload ?? {} })
|
|
@@ -1420,24 +1123,7 @@ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1420
1123
|
config.useDefaultSchemaValues,
|
|
1421
1124
|
formKey
|
|
1422
1125
|
);
|
|
1423
|
-
const
|
|
1424
|
-
schema: rootSchema,
|
|
1425
|
-
stripConfig: {
|
|
1426
|
-
stripZodEffects: true,
|
|
1427
|
-
stripDefaultValues: true,
|
|
1428
|
-
// `strict: false` strips refinements (so empty defaults pass);
|
|
1429
|
-
// strict keeps them so the slim parse below surfaces refinement
|
|
1430
|
-
// errors. Async refines are guarded by the try/catch — they
|
|
1431
|
-
// can't be surfaced synchronously regardless.
|
|
1432
|
-
stripZodRefinements: (config.strict ?? true) === false
|
|
1433
|
-
}
|
|
1434
|
-
});
|
|
1435
|
-
let rawDefaultValues = defaultValuesWithoutConstraints;
|
|
1436
|
-
if (!isPrimitive(rawDefaultValues)) {
|
|
1437
|
-
rawDefaultValues = walkFieldMeta.mergeDeep(defaultValuesWithoutConstraints, config.constraints);
|
|
1438
|
-
} else if (constraintsAreSlimValid(slimSchema, config.constraints)) {
|
|
1439
|
-
rawDefaultValues = config.constraints;
|
|
1440
|
-
}
|
|
1126
|
+
const rawDefaultValues = mergeDeep(defaultValuesWithoutConstraints, config.constraints);
|
|
1441
1127
|
if ((config.strict ?? true) !== false) {
|
|
1442
1128
|
if (containsAsyncTransform(rootSchema)) {
|
|
1443
1129
|
return {
|
|
@@ -1448,7 +1134,7 @@ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1448
1134
|
};
|
|
1449
1135
|
}
|
|
1450
1136
|
try {
|
|
1451
|
-
const strictResult = rootSchema.safeParse(rawDefaultValues);
|
|
1137
|
+
const strictResult = syncSafe(rootSchema).safeParse(rawDefaultValues);
|
|
1452
1138
|
if (strictResult.success) {
|
|
1453
1139
|
return {
|
|
1454
1140
|
data: rawDefaultValues,
|
|
@@ -1459,7 +1145,7 @@ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1459
1145
|
}
|
|
1460
1146
|
return {
|
|
1461
1147
|
data: rawDefaultValues,
|
|
1462
|
-
errors: zodIssuesToValidationErrors(strictResult.error.issues
|
|
1148
|
+
errors: zodIssuesToValidationErrors(strictResult.error.issues),
|
|
1463
1149
|
success: false,
|
|
1464
1150
|
formKey
|
|
1465
1151
|
};
|
|
@@ -1467,7 +1153,7 @@ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1467
1153
|
const isAsyncDetect = err instanceof Error && err.message.includes("Async refinement encountered");
|
|
1468
1154
|
if (isAsyncDetect) {
|
|
1469
1155
|
try {
|
|
1470
|
-
const strippedResult = stripAsyncChecks(rootSchema).safeParse(rawDefaultValues);
|
|
1156
|
+
const strippedResult = syncSafe(stripAsyncChecks(rootSchema)).safeParse(rawDefaultValues);
|
|
1471
1157
|
if (strippedResult.success) {
|
|
1472
1158
|
return {
|
|
1473
1159
|
data: rawDefaultValues,
|
|
@@ -1478,7 +1164,7 @@ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1478
1164
|
}
|
|
1479
1165
|
return {
|
|
1480
1166
|
data: rawDefaultValues,
|
|
1481
|
-
errors: zodIssuesToValidationErrors(strippedResult.error.issues
|
|
1167
|
+
errors: zodIssuesToValidationErrors(strippedResult.error.issues),
|
|
1482
1168
|
success: false,
|
|
1483
1169
|
formKey
|
|
1484
1170
|
};
|
|
@@ -1499,139 +1185,40 @@ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1499
1185
|
};
|
|
1500
1186
|
}
|
|
1501
1187
|
}
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
formKey
|
|
1511
|
-
|
|
1512
|
-
}
|
|
1513
|
-
const { data, success, error } = parseResult;
|
|
1514
|
-
if (success) {
|
|
1515
|
-
return {
|
|
1516
|
-
data,
|
|
1517
|
-
errors: void 0,
|
|
1518
|
-
success,
|
|
1519
|
-
formKey
|
|
1520
|
-
};
|
|
1521
|
-
}
|
|
1522
|
-
let fixedData = {};
|
|
1523
|
-
for (const issue of error.issues) {
|
|
1524
|
-
const schemasAtPath = getNestedZodSchemasAtPath(slimSchema, issue.path, maxRecursionDepth);
|
|
1525
|
-
const path = coercePathSegments(issue.path);
|
|
1526
|
-
if (!schemasAtPath.length) {
|
|
1527
|
-
console.error(
|
|
1528
|
-
`[attaform] zod-v3 adapter: no schema at path '${path.join(PATH_SEPARATOR)}' for key '${formKey}'. Skipping the issue. (This is a library-internal invariant \u2014 please file a bug.)`
|
|
1529
|
-
);
|
|
1530
|
-
continue;
|
|
1531
|
-
}
|
|
1532
|
-
const candidate = schemasAtPath[0];
|
|
1533
|
-
if (candidate !== void 0) {
|
|
1534
|
-
const valueAtPath = serializeScript.getAtPath(rawDefaultValues, path);
|
|
1535
|
-
const slimKinds = slimPrimitivesV3(candidate);
|
|
1536
|
-
if (slimKinds.size > 0 && slimKinds.has(serializeScript.slimKindOf(valueAtPath))) {
|
|
1537
|
-
continue;
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
for (const schemaAtPath of schemasAtPath) {
|
|
1541
|
-
if (issue.code === "invalid_type") {
|
|
1542
|
-
const isDiscriminatedUnion = isZodSchemaType(schemaAtPath, "ZodDiscriminatedUnion");
|
|
1543
|
-
const defaultValueContext = isDiscriminatedUnion ? {
|
|
1544
|
-
formKey,
|
|
1545
|
-
discriminator: {
|
|
1546
|
-
isDiscriminatorKey: true,
|
|
1547
|
-
schema: schemaAtPath,
|
|
1548
|
-
useDefaultSchemaValues: false
|
|
1549
|
-
}
|
|
1550
|
-
} : {
|
|
1551
|
-
formKey,
|
|
1552
|
-
discriminator: {
|
|
1553
|
-
isDiscriminatorKey: false,
|
|
1554
|
-
schema: void 0,
|
|
1555
|
-
useDefaultSchemaValues: false
|
|
1556
|
-
}
|
|
1557
|
-
};
|
|
1558
|
-
const defaultValue = getDefaultValue(issue.expected, defaultValueContext);
|
|
1559
|
-
fixedData = serializeScript.setAtPath(fixedData, path, defaultValue);
|
|
1560
|
-
continue;
|
|
1561
|
-
}
|
|
1562
|
-
const peeled = walkFieldMeta.peelEmbeddedDefault(schemaAtPath, V3_INTROSPECTOR);
|
|
1563
|
-
if (peeled !== walkFieldMeta.NO_EMBEDDED_DEFAULT) {
|
|
1564
|
-
fixedData = serializeScript.setAtPath(fixedData, path, peeled);
|
|
1565
|
-
continue;
|
|
1566
|
-
}
|
|
1567
|
-
const ctx = {
|
|
1568
|
-
formKey,
|
|
1569
|
-
discriminator: {
|
|
1570
|
-
isDiscriminatorKey: false,
|
|
1571
|
-
schema: void 0,
|
|
1572
|
-
useDefaultSchemaValues: false
|
|
1573
|
-
}
|
|
1574
|
-
};
|
|
1575
|
-
const slimKinds = slimPrimitivesV3(schemaAtPath);
|
|
1576
|
-
const firstKind = [...slimKinds][0];
|
|
1577
|
-
if (firstKind !== void 0) {
|
|
1578
|
-
const expected = firstKind === "string" ? "string" : firstKind === "number" ? "number" : firstKind === "boolean" ? "boolean" : firstKind === "bigint" ? "bigint" : firstKind === "date" ? "date" : firstKind === "array" ? "array" : firstKind === "object" ? "object" : null;
|
|
1579
|
-
if (expected !== null) {
|
|
1580
|
-
fixedData = serializeScript.setAtPath(fixedData, path, getDefaultValue(expected, ctx));
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1188
|
+
const fixed = fixStructuralDefaults(
|
|
1189
|
+
rootSchema,
|
|
1190
|
+
rawDefaultValues,
|
|
1191
|
+
config.useDefaultSchemaValues,
|
|
1192
|
+
maxRecursionDepth,
|
|
1193
|
+
{
|
|
1194
|
+
intro: V3_INTROSPECTOR,
|
|
1195
|
+
slimPrimitivesOf: (s) => slimPrimitivesV3(s),
|
|
1196
|
+
deriveDefault: (s, useDefault) => getDefaultValuesFromZodSchema(s, useDefault, formKey),
|
|
1197
|
+
unwrapToDiscriminatedUnion: (s) => unwrapToDiscriminatedUnion(s)
|
|
1583
1198
|
}
|
|
1584
|
-
|
|
1585
|
-
fixedData = walkFieldMeta.mergeDeep(rawDefaultValues, fixedData);
|
|
1586
|
-
const secondParse = slimSchema.safeParse(fixedData);
|
|
1587
|
-
const finalData = secondParse.success ? secondParse.data : fixedData;
|
|
1199
|
+
);
|
|
1588
1200
|
return {
|
|
1589
|
-
data:
|
|
1201
|
+
data: fixed.data,
|
|
1590
1202
|
errors: void 0,
|
|
1591
1203
|
success: true,
|
|
1592
1204
|
formKey
|
|
1593
1205
|
};
|
|
1594
1206
|
}
|
|
1595
|
-
const slimRootCacheV3 = /* @__PURE__ */ new WeakMap();
|
|
1596
|
-
function getSlimRootV3(rootSchema) {
|
|
1597
|
-
const cached = slimRootCacheV3.get(rootSchema);
|
|
1598
|
-
if (cached !== void 0) return cached;
|
|
1599
|
-
const [strippedSchema] = stripRootSchema(rootSchema, {
|
|
1600
|
-
stripDefaultValues: true,
|
|
1601
|
-
stripNullable: true,
|
|
1602
|
-
stripOptional: true,
|
|
1603
|
-
stripZodEffects: true
|
|
1604
|
-
});
|
|
1605
|
-
const slimSchema = getSlimSchema({
|
|
1606
|
-
schema: strippedSchema,
|
|
1607
|
-
stripConfig: { stripDefaultValues: true, stripZodEffects: true }
|
|
1608
|
-
});
|
|
1609
|
-
slimRootCacheV3.set(rootSchema, slimSchema);
|
|
1610
|
-
return slimSchema;
|
|
1611
|
-
}
|
|
1612
|
-
function getNestedSchemasInSlimModeV3(rootSchema, path, maxRecursionDepth) {
|
|
1613
|
-
return getNestedZodSchemasAtPath(getSlimRootV3(rootSchema), path, maxRecursionDepth);
|
|
1614
|
-
}
|
|
1615
1207
|
|
|
1616
1208
|
function useForm(configuration) {
|
|
1617
1209
|
if (configuration === void 0 || configuration === null || configuration.schema === void 0) {
|
|
1618
|
-
throw new
|
|
1210
|
+
throw new InvalidUseFormConfigError();
|
|
1619
1211
|
}
|
|
1620
1212
|
function isZodType(value) {
|
|
1621
1213
|
return typeof value === "object" && value !== null && "_def" in value;
|
|
1622
1214
|
}
|
|
1623
1215
|
const { schema } = configuration;
|
|
1624
1216
|
const abstractSchema = isZodType(schema) ? zodAdapter(schema) : schema;
|
|
1625
|
-
return
|
|
1217
|
+
return useAbstractForm({
|
|
1626
1218
|
...configuration,
|
|
1627
1219
|
schema: abstractSchema,
|
|
1628
1220
|
defaultValues: configuration.defaultValues
|
|
1629
1221
|
});
|
|
1630
1222
|
}
|
|
1631
1223
|
|
|
1632
|
-
|
|
1633
|
-
exports.isZodSchemaType = isZodSchemaType;
|
|
1634
|
-
exports.useForm = useForm;
|
|
1635
|
-
exports.withMeta = withMeta;
|
|
1636
|
-
exports.zodAdapter = zodAdapter;
|
|
1637
|
-
//# sourceMappingURL=attaform.D8kliaKw.cjs.map
|
|
1224
|
+
export { isZodSchemaType as i, useForm as u, zodAdapter as z };
|