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