attaform 0.27.6 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abstract.d.mts +5 -4
- package/dist/abstract.mjs +4 -3
- package/dist/chunks/fingerprint.mjs +0 -1
- package/dist/chunks/fingerprint2.mjs +1 -2
- package/dist/dev/abstract.mjs +4 -0
- package/dist/{chunks → dev/chunks}/dev-key-collision-warnings.mjs +0 -1
- package/dist/{chunks → dev/chunks}/devtools.mjs +5 -6
- package/dist/{chunks/fingerprint.cjs → dev/chunks/fingerprint.mjs} +7 -10
- package/dist/{chunks/fingerprint2.cjs → dev/chunks/fingerprint2.mjs} +32 -35
- package/dist/dev/directive.mjs +1 -0
- package/dist/dev/history.mjs +89 -0
- package/dist/dev/index.mjs +5 -0
- package/dist/dev/runtime/plugins/attaform.mjs +40 -0
- package/dist/{shared/attaform.D6tk90Rc.cjs → dev/shared/attaform-dev.6qxD-Yqo.mjs} +187 -43
- package/dist/{shared/attaform.CQN9R62B.cjs → dev/shared/attaform-dev.BJGA_UOS.mjs} +1 -4
- package/dist/{shared/attaform.DYEr28Pt.mjs → dev/shared/attaform-dev.BR8u0YOZ.mjs} +6 -7
- package/dist/dev/shared/attaform-dev.BXE2cr0L.mjs +220 -0
- package/dist/dev/shared/attaform-dev.By4PRjt0.mjs +248 -0
- package/dist/{shared/attaform.B1ZYt2Li.mjs → dev/shared/attaform-dev.D2I8e_Mm.mjs} +132 -568
- package/dist/dev/shared/attaform-dev.Dr2YzS5B.mjs +197 -0
- package/dist/{shared/attaform.nMaz2C5P.mjs → dev/shared/attaform-dev.P7cseiEG.mjs} +178 -397
- package/dist/{shared/attaform.CKH2lGdL.mjs → dev/shared/attaform-dev.WmuhD_CZ.mjs} +3944 -5056
- package/dist/{shared/attaform.DMxM2kol.mjs → dev/shared/attaform-dev.oYrkP9dj.mjs} +160 -508
- package/dist/dev/zod-v3.mjs +17 -0
- package/dist/dev/zod-v4.mjs +16 -0
- package/dist/dev/zod.mjs +5 -0
- package/dist/directive.d.mts +20 -0
- package/dist/directive.mjs +1 -0
- package/dist/esbuild.mjs +0 -1
- package/dist/history.d.mts +59 -0
- package/dist/history.mjs +89 -0
- package/dist/index.d.mts +11 -5
- package/dist/index.mjs +5 -4
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.mjs +5 -2
- package/dist/rollup.mjs +0 -1
- package/dist/rspack.d.mts +6 -1
- package/dist/rspack.mjs +0 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +9 -8
- package/dist/runtime/plugins/attaform.mjs +1 -2
- package/dist/shared/{attaform.Fp3sCrVs.d.ts → attaform.B4VkS43-.d.mts} +2 -2
- package/dist/shared/{attaform.DrvMscNX.cjs → attaform.B8k8JrmK.mjs} +4073 -5630
- package/dist/shared/attaform.BJGA_UOS.mjs +0 -1
- package/dist/shared/{attaform.CoR4mWfv.mjs → attaform.C09fpdLS.mjs} +172 -16
- package/dist/shared/{attaform.D8kliaKw.cjs → attaform.CJP3RkGa.mjs} +141 -590
- package/dist/shared/{attaform.DniawQLP.d.cts → attaform.Cgu-hdSb.d.mts} +268 -68
- package/dist/shared/attaform.Cs2Rbdlo.mjs +0 -1
- package/dist/shared/{attaform.CHlJLAiv.d.mts → attaform.D5V4tZWq.d.mts} +69 -179
- package/dist/shared/{attaform.B9Wyhfro.cjs → attaform.D6DCnnQu.mjs} +11 -16
- package/dist/shared/attaform.DhnPb6nK.mjs +0 -1
- package/dist/shared/attaform.Dq4vWxuG.mjs +197 -0
- package/dist/shared/attaform.JfSWdEcb.d.mts +44 -0
- package/dist/shared/attaform.KvlEedlF.mjs +0 -1
- package/dist/shared/{attaform.DdQN7sgN.cjs → attaform.NLmerepI.mjs} +175 -557
- package/dist/shared/attaform.h0i6LijT.mjs +242 -0
- package/dist/shared/{attaform.Biytrv0-.cjs → attaform.uLbun31C.mjs} +204 -544
- package/dist/shared/attaform.v0fQtWyA.mjs +0 -1
- package/dist/shared/attaform.wfY8XFvm.mjs +197 -0
- package/dist/transforms.mjs +0 -1
- package/dist/vite.d.mts +17 -5
- package/dist/vite.mjs +24 -2
- package/dist/webpack.d.mts +6 -1
- package/dist/webpack.mjs +0 -1
- package/dist/zod-v3.d.mts +11 -6
- package/dist/zod-v3.mjs +17 -4
- package/dist/zod-v4.d.mts +12 -6
- package/dist/zod-v4.mjs +16 -4
- package/dist/zod.d.mts +4 -3
- package/dist/zod.mjs +5 -4
- package/package.json +23 -8
- package/skills/attaform/SKILL.md +2 -1
- package/dist/abstract.cjs +0 -48
- package/dist/abstract.cjs.map +0 -1
- package/dist/abstract.d.cts +0 -42
- package/dist/abstract.d.ts +0 -42
- package/dist/abstract.mjs.map +0 -1
- package/dist/chunks/dev-key-collision-warnings.cjs +0 -25
- package/dist/chunks/dev-key-collision-warnings.cjs.map +0 -1
- package/dist/chunks/dev-key-collision-warnings.mjs.map +0 -1
- package/dist/chunks/devtools.cjs +0 -157
- package/dist/chunks/devtools.cjs.map +0 -1
- package/dist/chunks/devtools.mjs.map +0 -1
- package/dist/chunks/fingerprint.cjs.map +0 -1
- package/dist/chunks/fingerprint.mjs.map +0 -1
- package/dist/chunks/fingerprint2.cjs.map +0 -1
- package/dist/chunks/fingerprint2.mjs.map +0 -1
- package/dist/esbuild.cjs +0 -28
- package/dist/esbuild.cjs.map +0 -1
- package/dist/esbuild.d.cts +0 -56
- package/dist/esbuild.d.ts +0 -56
- package/dist/esbuild.mjs.map +0 -1
- package/dist/index.cjs +0 -51
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -249
- package/dist/index.d.ts +0 -249
- package/dist/index.mjs.map +0 -1
- package/dist/nuxt.cjs +0 -84
- package/dist/nuxt.cjs.map +0 -1
- package/dist/nuxt.d.cts +0 -66
- package/dist/nuxt.d.ts +0 -66
- package/dist/nuxt.mjs.map +0 -1
- package/dist/rollup.cjs +0 -24
- package/dist/rollup.cjs.map +0 -1
- package/dist/rollup.d.cts +0 -35
- package/dist/rollup.d.ts +0 -35
- package/dist/rollup.mjs.map +0 -1
- package/dist/rspack.cjs +0 -10
- package/dist/rspack.cjs.map +0 -1
- package/dist/rspack.d.cts +0 -40
- package/dist/rspack.d.ts +0 -40
- package/dist/rspack.mjs.map +0 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue.d.ts +0 -7
- package/dist/runtime/components/DevtoolsValueTree.vue.d.ts +0 -35
- package/dist/runtime/plugins/attaform.cjs +0 -43
- package/dist/runtime/plugins/attaform.cjs.map +0 -1
- package/dist/runtime/plugins/attaform.d.cts +0 -5
- package/dist/runtime/plugins/attaform.d.ts +0 -5
- package/dist/runtime/plugins/attaform.mjs.map +0 -1
- package/dist/shared/attaform.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.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.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.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,56 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { A as AttaformError,
|
|
1
|
+
import { s as slimPrimitivesWalk, c as createAbstractSchema, w as walkPathSegments, d as deriveDefaultWalk, b as buildFieldMetaPathMap, g as getFieldMetaForSchema, m as mergeDeep, f as fixStructuralDefaults, a as getFieldMetaListForSchema } from './attaform-dev.6qxD-Yqo.mjs';
|
|
2
|
+
import { o as humanize, h as useAbstractForm } from './attaform-dev.WmuhD_CZ.mjs';
|
|
3
|
+
import { A as AttaformError, e as canonicalizePath, a as InvalidUseFormConfigError } from './attaform-dev.Dr2YzS5B.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
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;
|
|
5
|
+
class UnsupportedSchemaError extends AttaformError {
|
|
54
6
|
}
|
|
55
7
|
|
|
56
8
|
function isZodSchemaType(schema, expectedType) {
|
|
@@ -234,12 +186,15 @@ function isAsyncEffect(schema) {
|
|
|
234
186
|
return fn.constructor.name === "AsyncFunction";
|
|
235
187
|
}
|
|
236
188
|
function containsAsyncRefine(schema, seen) {
|
|
237
|
-
return
|
|
189
|
+
return walkForTarget(schema, "refinement", seen ?? /* @__PURE__ */ new WeakSet());
|
|
190
|
+
}
|
|
191
|
+
function containsDiscriminatedUnion(schema, seen) {
|
|
192
|
+
return walkForTarget(schema, "discriminated-union", seen ?? /* @__PURE__ */ new WeakSet());
|
|
238
193
|
}
|
|
239
194
|
function containsAsyncTransform(schema, seen) {
|
|
240
|
-
return
|
|
195
|
+
return walkForTarget(schema, "transform-or-preprocess", seen ?? /* @__PURE__ */ new WeakSet());
|
|
241
196
|
}
|
|
242
|
-
function
|
|
197
|
+
function walkForTarget(schema, target, visited) {
|
|
243
198
|
const candidate = schema;
|
|
244
199
|
if (typeof candidate !== "object" || candidate === null) return false;
|
|
245
200
|
if (visited.has(candidate)) return false;
|
|
@@ -251,66 +206,69 @@ function walkForAsync(schema, target, visited) {
|
|
|
251
206
|
return true;
|
|
252
207
|
}
|
|
253
208
|
const inner = unwrapEffectsSource(schema);
|
|
254
|
-
return inner !== void 0 &&
|
|
209
|
+
return inner !== void 0 && walkForTarget(inner, target, visited);
|
|
255
210
|
}
|
|
256
211
|
if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodReadonly")) {
|
|
257
212
|
const inner = unwrapInner(schema);
|
|
258
|
-
return inner !== void 0 &&
|
|
213
|
+
return inner !== void 0 && walkForTarget(inner, target, visited);
|
|
259
214
|
}
|
|
260
215
|
if (isZodSchemaType(schema, "ZodBranded")) {
|
|
261
216
|
const inner = unwrapBranded(schema);
|
|
262
|
-
return inner !== void 0 &&
|
|
217
|
+
return inner !== void 0 && walkForTarget(inner, target, visited);
|
|
263
218
|
}
|
|
264
219
|
if (isZodSchemaType(schema, "ZodLazy")) {
|
|
265
220
|
const inner = unwrapLazy(schema);
|
|
266
|
-
return inner !== void 0 &&
|
|
221
|
+
return inner !== void 0 && walkForTarget(inner, target, visited);
|
|
267
222
|
}
|
|
268
223
|
if (isZodSchemaType(schema, "ZodPipeline")) {
|
|
269
224
|
const inSide = unwrapPipeIn(schema);
|
|
270
|
-
if (inSide !== void 0 &&
|
|
225
|
+
if (inSide !== void 0 && walkForTarget(inSide, target, visited)) return true;
|
|
271
226
|
const outSide = unwrapPipeOut(schema);
|
|
272
|
-
if (outSide !== void 0 &&
|
|
227
|
+
if (outSide !== void 0 && walkForTarget(outSide, target, visited)) return true;
|
|
273
228
|
return false;
|
|
274
229
|
}
|
|
275
230
|
if (isZodSchemaType(schema, "ZodObject")) {
|
|
276
231
|
for (const sub of Object.values(getObjectShape(schema))) {
|
|
277
|
-
if (
|
|
232
|
+
if (walkForTarget(sub, target, visited)) return true;
|
|
278
233
|
}
|
|
279
234
|
return false;
|
|
280
235
|
}
|
|
281
236
|
if (isZodSchemaType(schema, "ZodArray")) {
|
|
282
237
|
const elem = getArrayElement(schema);
|
|
283
|
-
return elem !== void 0 &&
|
|
238
|
+
return elem !== void 0 && walkForTarget(elem, target, visited);
|
|
284
239
|
}
|
|
285
240
|
if (isZodSchemaType(schema, "ZodTuple")) {
|
|
286
241
|
for (const it of getTupleItems(schema)) {
|
|
287
|
-
if (
|
|
242
|
+
if (walkForTarget(it, target, visited)) return true;
|
|
288
243
|
}
|
|
289
244
|
return false;
|
|
290
245
|
}
|
|
291
246
|
if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
|
|
247
|
+
if (target === "discriminated-union" && isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
292
250
|
for (const opt of getUnionOptions(schema)) {
|
|
293
|
-
if (
|
|
251
|
+
if (walkForTarget(opt, target, visited)) return true;
|
|
294
252
|
}
|
|
295
253
|
return false;
|
|
296
254
|
}
|
|
297
255
|
if (isZodSchemaType(schema, "ZodIntersection")) {
|
|
298
256
|
const left = getIntersectionLeft(schema);
|
|
299
|
-
if (left !== void 0 &&
|
|
257
|
+
if (left !== void 0 && walkForTarget(left, target, visited)) return true;
|
|
300
258
|
const right = getIntersectionRight(schema);
|
|
301
|
-
if (right !== void 0 &&
|
|
259
|
+
if (right !== void 0 && walkForTarget(right, target, visited)) return true;
|
|
302
260
|
return false;
|
|
303
261
|
}
|
|
304
262
|
if (isZodSchemaType(schema, "ZodRecord")) {
|
|
305
263
|
const keyType = getRecordKeyType(schema);
|
|
306
|
-
if (keyType !== void 0 &&
|
|
264
|
+
if (keyType !== void 0 && walkForTarget(keyType, target, visited)) return true;
|
|
307
265
|
const valueType = getRecordValueType(schema);
|
|
308
|
-
if (valueType !== void 0 &&
|
|
266
|
+
if (valueType !== void 0 && walkForTarget(valueType, target, visited)) return true;
|
|
309
267
|
return false;
|
|
310
268
|
}
|
|
311
269
|
if (isZodSchemaType(schema, "ZodSet")) {
|
|
312
270
|
const elem = getSetValueType(schema);
|
|
313
|
-
return elem !== void 0 &&
|
|
271
|
+
return elem !== void 0 && walkForTarget(elem, target, visited);
|
|
314
272
|
}
|
|
315
273
|
return false;
|
|
316
274
|
}
|
|
@@ -347,7 +305,7 @@ function getNativeEnumValues(schema) {
|
|
|
347
305
|
const def = readDef(schema);
|
|
348
306
|
return def?.values;
|
|
349
307
|
}
|
|
350
|
-
function getDefaultValue
|
|
308
|
+
function getDefaultValue(schema) {
|
|
351
309
|
const def = readDef(schema);
|
|
352
310
|
const thunk = def?.defaultValue;
|
|
353
311
|
if (typeof thunk !== "function") return void 0;
|
|
@@ -371,11 +329,6 @@ function hasCatchValue(schema) {
|
|
|
371
329
|
const def = readDef(schema);
|
|
372
330
|
return typeof def?.catchValue === "function";
|
|
373
331
|
}
|
|
374
|
-
function hasChecks(schema) {
|
|
375
|
-
const def = readDef(schema);
|
|
376
|
-
const checks = def?.checks;
|
|
377
|
-
return Array.isArray(checks) && checks.length > 0;
|
|
378
|
-
}
|
|
379
332
|
function hasContainerOrRootRefine(schema, seen) {
|
|
380
333
|
const visited = seen ?? /* @__PURE__ */ new WeakSet();
|
|
381
334
|
const candidate = schema;
|
|
@@ -471,71 +424,6 @@ function isContainerAfterWrapperPeel(schema) {
|
|
|
471
424
|
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
425
|
}
|
|
473
426
|
|
|
474
|
-
function rebuildWithDef(original, defPatch) {
|
|
475
|
-
const node = Object.create(Object.getPrototypeOf(original));
|
|
476
|
-
node._def = { ...original._def, ...defPatch };
|
|
477
|
-
return node;
|
|
478
|
-
}
|
|
479
|
-
function rebuildObject(original, shape) {
|
|
480
|
-
const node = rebuildWithDef(original, { shape: () => shape, unknownKeys: "strip" });
|
|
481
|
-
node._cached = null;
|
|
482
|
-
return node;
|
|
483
|
-
}
|
|
484
|
-
function rebuildArray(original, element) {
|
|
485
|
-
return rebuildWithDef(original, {
|
|
486
|
-
type: element,
|
|
487
|
-
minLength: null,
|
|
488
|
-
maxLength: null,
|
|
489
|
-
exactLength: null
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
function rebuildSet(original, valueType) {
|
|
493
|
-
return rebuildWithDef(original, {
|
|
494
|
-
valueType,
|
|
495
|
-
minSize: null,
|
|
496
|
-
maxSize: null
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
function rebuildRecord(original, valueType, keyType) {
|
|
500
|
-
const patch = { valueType };
|
|
501
|
-
if (keyType !== void 0) patch["keyType"] = keyType;
|
|
502
|
-
return rebuildWithDef(original, patch);
|
|
503
|
-
}
|
|
504
|
-
function rebuildTuple(original, items) {
|
|
505
|
-
return rebuildWithDef(original, { items, rest: null });
|
|
506
|
-
}
|
|
507
|
-
function rebuildUnion(original, options) {
|
|
508
|
-
return rebuildWithDef(original, { options });
|
|
509
|
-
}
|
|
510
|
-
function rebuildIntersection(original, left, right) {
|
|
511
|
-
return rebuildWithDef(original, { left, right });
|
|
512
|
-
}
|
|
513
|
-
function rebuildWrapperInner(original, inner) {
|
|
514
|
-
return rebuildWithDef(original, { innerType: inner });
|
|
515
|
-
}
|
|
516
|
-
function rebuildLazy(original, target) {
|
|
517
|
-
return rebuildWithDef(original, { getter: () => target });
|
|
518
|
-
}
|
|
519
|
-
function stripLeafChecks(original) {
|
|
520
|
-
return rebuildWithDef(original, { checks: [] });
|
|
521
|
-
}
|
|
522
|
-
function rebuildDiscriminatedUnion(original, options) {
|
|
523
|
-
const originalOptions = getDiscriminatedOptions(original);
|
|
524
|
-
const originalMap = getDiscriminatedOptionsMap(original);
|
|
525
|
-
const optionsMap = /* @__PURE__ */ new Map();
|
|
526
|
-
if (originalMap !== void 0) {
|
|
527
|
-
for (const [value, originalOption] of originalMap) {
|
|
528
|
-
const index = originalOptions.indexOf(originalOption);
|
|
529
|
-
const replacement = index >= 0 ? options[index] : void 0;
|
|
530
|
-
if (replacement !== void 0) optionsMap.set(value, replacement);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
return rebuildWithDef(original, { options, optionsMap });
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
class UnsupportedSchemaError extends AttaformError {
|
|
537
|
-
}
|
|
538
|
-
|
|
539
427
|
const UNSUPPORTED_TYPE_NAMES = /* @__PURE__ */ new Set(["ZodPromise", "ZodFunction", "ZodMap", "ZodSymbol"]);
|
|
540
428
|
function labelPath(path) {
|
|
541
429
|
return path.length === 0 ? "<root>" : path.join(".");
|
|
@@ -544,7 +432,7 @@ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
|
544
432
|
const typeName = getTypeName(schema);
|
|
545
433
|
if (typeName !== void 0 && UNSUPPORTED_TYPE_NAMES.has(typeName)) {
|
|
546
434
|
throw new UnsupportedSchemaError(
|
|
547
|
-
`[attaform/zod-v3] unsupported kind '${typeName}' at '${labelPath(path)}'`
|
|
435
|
+
`[attaform/zod-v3] unsupported kind '${typeName}' at '${labelPath(path)}'`
|
|
548
436
|
);
|
|
549
437
|
}
|
|
550
438
|
if (isZodSchemaType(schema, "ZodObject")) {
|
|
@@ -636,6 +524,7 @@ const V3_INTROSPECTOR = {
|
|
|
636
524
|
isCoercePrimitive,
|
|
637
525
|
containsAsyncRefine,
|
|
638
526
|
containsAsyncTransform,
|
|
527
|
+
containsDiscriminatedUnion,
|
|
639
528
|
hasContainerOrRootRefine,
|
|
640
529
|
// Walker accessors (D2 / D3 / D5).
|
|
641
530
|
getArrayElement,
|
|
@@ -657,7 +546,7 @@ const V3_INTROSPECTOR = {
|
|
|
657
546
|
unwrapPipeOut,
|
|
658
547
|
unwrapLazy,
|
|
659
548
|
getLazyGetter,
|
|
660
|
-
getDefaultValue
|
|
549
|
+
getDefaultValue,
|
|
661
550
|
getCatchDefault,
|
|
662
551
|
hasCatchValue
|
|
663
552
|
};
|
|
@@ -666,6 +555,65 @@ function slimPrimitivesV3(schema) {
|
|
|
666
555
|
return new Set(slimPrimitivesWalk(schema, V3_INTROSPECTOR, 64));
|
|
667
556
|
}
|
|
668
557
|
|
|
558
|
+
function rebuildWithDef(original, defPatch) {
|
|
559
|
+
const node = Object.create(Object.getPrototypeOf(original));
|
|
560
|
+
node._def = { ...original._def, ...defPatch };
|
|
561
|
+
return node;
|
|
562
|
+
}
|
|
563
|
+
function rebuildObject(original, shape) {
|
|
564
|
+
const node = rebuildWithDef(original, { shape: () => shape, unknownKeys: "strip" });
|
|
565
|
+
node._cached = null;
|
|
566
|
+
return node;
|
|
567
|
+
}
|
|
568
|
+
function rebuildArray(original, element) {
|
|
569
|
+
return rebuildWithDef(original, {
|
|
570
|
+
type: element,
|
|
571
|
+
minLength: null,
|
|
572
|
+
maxLength: null,
|
|
573
|
+
exactLength: null
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
function rebuildSet(original, valueType) {
|
|
577
|
+
return rebuildWithDef(original, {
|
|
578
|
+
valueType,
|
|
579
|
+
minSize: null,
|
|
580
|
+
maxSize: null
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
function rebuildRecord(original, valueType, keyType) {
|
|
584
|
+
const patch = { valueType };
|
|
585
|
+
if (keyType !== void 0) patch["keyType"] = keyType;
|
|
586
|
+
return rebuildWithDef(original, patch);
|
|
587
|
+
}
|
|
588
|
+
function rebuildTuple(original, items) {
|
|
589
|
+
return rebuildWithDef(original, { items, rest: null });
|
|
590
|
+
}
|
|
591
|
+
function rebuildUnion(original, options) {
|
|
592
|
+
return rebuildWithDef(original, { options });
|
|
593
|
+
}
|
|
594
|
+
function rebuildIntersection(original, left, right) {
|
|
595
|
+
return rebuildWithDef(original, { left, right });
|
|
596
|
+
}
|
|
597
|
+
function rebuildWrapperInner(original, inner) {
|
|
598
|
+
return rebuildWithDef(original, { innerType: inner });
|
|
599
|
+
}
|
|
600
|
+
function rebuildLazy(original, target) {
|
|
601
|
+
return rebuildWithDef(original, { getter: () => target });
|
|
602
|
+
}
|
|
603
|
+
function rebuildDiscriminatedUnion(original, options) {
|
|
604
|
+
const originalOptions = getDiscriminatedOptions(original);
|
|
605
|
+
const originalMap = getDiscriminatedOptionsMap(original);
|
|
606
|
+
const optionsMap = /* @__PURE__ */ new Map();
|
|
607
|
+
if (originalMap !== void 0) {
|
|
608
|
+
for (const [value, originalOption] of originalMap) {
|
|
609
|
+
const index = originalOptions.indexOf(originalOption);
|
|
610
|
+
const replacement = index >= 0 ? options[index] : void 0;
|
|
611
|
+
if (replacement !== void 0) optionsMap.set(value, replacement);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return rebuildWithDef(original, { options, optionsMap });
|
|
615
|
+
}
|
|
616
|
+
|
|
669
617
|
function stripAsyncChecks(schema) {
|
|
670
618
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
671
619
|
function recurse(s) {
|
|
@@ -688,7 +636,7 @@ function stripAsyncChecks(schema) {
|
|
|
688
636
|
if (isZodSchemaType(s, "ZodDefault")) {
|
|
689
637
|
const inner = unwrapInner(s);
|
|
690
638
|
if (inner === void 0) return s;
|
|
691
|
-
const def = getDefaultValue
|
|
639
|
+
const def = getDefaultValue(s);
|
|
692
640
|
return recurse(inner).default(def);
|
|
693
641
|
}
|
|
694
642
|
if (isZodSchemaType(s, "ZodCatch")) {
|
|
@@ -821,33 +769,13 @@ function carryObjectChecks(rebuilt, original) {
|
|
|
821
769
|
return next;
|
|
822
770
|
}
|
|
823
771
|
|
|
824
|
-
const PATH_SEPARATOR = ".";
|
|
825
772
|
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
773
|
let warnedZodCodeMissing = false;
|
|
840
774
|
function zodAdapter(zodSchema) {
|
|
841
775
|
assertSupportedKinds(zodSchema);
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
stripOptional: true,
|
|
846
|
-
stripZodEffects: true,
|
|
847
|
-
stripZodRefinements: true
|
|
848
|
-
});
|
|
849
|
-
if (!isZodSchemaType(_strippedRoot, "ZodObject") && !isZodSchemaType(_strippedRoot, "ZodRecord") && !isZodSchemaType(_strippedRoot, "ZodDiscriminatedUnion")) {
|
|
850
|
-
const name = getTypeName(_strippedRoot);
|
|
776
|
+
const peeledRoot = peelAllV3Wrappers(zodSchema);
|
|
777
|
+
if (!isZodSchemaType(peeledRoot, "ZodObject") && !isZodSchemaType(peeledRoot, "ZodRecord") && !isZodSchemaType(peeledRoot, "ZodDiscriminatedUnion")) {
|
|
778
|
+
const name = getTypeName(peeledRoot);
|
|
851
779
|
throw new Error(
|
|
852
780
|
`Attaform: useForm schema root must be a ZodObject, ZodRecord, or ZodDiscriminatedUnion (got ${name}). Wrap other shapes under a key.`
|
|
853
781
|
);
|
|
@@ -872,7 +800,10 @@ function buildV3Services() {
|
|
|
872
800
|
// slim-mode walks — `getSlimPrimitiveTypesAtPath` and
|
|
873
801
|
// `getSchemasAtPath` both consume this variant so the yielded
|
|
874
802
|
// candidates reflect the slim shape.
|
|
875
|
-
|
|
803
|
+
// The slim-root projection is gone (size-teardown P7): the shared
|
|
804
|
+
// path walker peels wrappers / effects inline, so the slim and
|
|
805
|
+
// unstripped walks coincide — same aliasing v4 always had.
|
|
806
|
+
getNestedSchemasInSlimMode: (schema, path, maxRecursionDepth) => getNestedZodSchemasAtPath(schema, path, maxRecursionDepth),
|
|
876
807
|
slimPrimitivesOf: (schema, _maxRecursionDepth) => slimPrimitivesV3(schema),
|
|
877
808
|
deriveDefault: (schema, useDefault, _maxRecursionDepth, formKey) => getDefaultValuesFromZodSchema(schema, useDefault, formKey),
|
|
878
809
|
runStrictGetDefaults: (schema, config, formKey, maxRecursionDepth) => runStrictGetDefaultsV3(schema, config, formKey, maxRecursionDepth),
|
|
@@ -881,7 +812,7 @@ function buildV3Services() {
|
|
|
881
812
|
peelAllWrappers: (schema) => peelAllV3Wrappers(schema),
|
|
882
813
|
isLeafRequired: (schema) => isLeafRequiredV3(schema),
|
|
883
814
|
resolveFieldMetaAtPath: (schema, path, maxRecursionDepth) => resolveFieldMetaAtPathV3(schema, path, maxRecursionDepth),
|
|
884
|
-
issuesToValidationErrors: (issues
|
|
815
|
+
issuesToValidationErrors: (issues) => zodIssuesToValidationErrors(issues),
|
|
885
816
|
safeParseSync: (schema, data) => {
|
|
886
817
|
const result = schema.safeParse(data);
|
|
887
818
|
return result.success ? { success: true, data: result.data } : { success: false, issues: result.error.issues };
|
|
@@ -903,7 +834,7 @@ function buildV3Services() {
|
|
|
903
834
|
)
|
|
904
835
|
};
|
|
905
836
|
}
|
|
906
|
-
function zodIssuesToValidationErrors(issues
|
|
837
|
+
function zodIssuesToValidationErrors(issues) {
|
|
907
838
|
const validationErrors = [];
|
|
908
839
|
for (const issue of issues) {
|
|
909
840
|
let code;
|
|
@@ -911,7 +842,7 @@ function zodIssuesToValidationErrors(issues, formKey) {
|
|
|
911
842
|
code = `zod:${issue.code}`;
|
|
912
843
|
} else {
|
|
913
844
|
code = "zod:unknown";
|
|
914
|
-
if (
|
|
845
|
+
if (!warnedZodCodeMissing) {
|
|
915
846
|
warnedZodCodeMissing = true;
|
|
916
847
|
console.warn(
|
|
917
848
|
"[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 +863,6 @@ function zodIssuesToValidationErrors(issues, formKey) {
|
|
|
932
863
|
// to absolutise, then routes form-level (absolute path length 0)
|
|
933
864
|
// entries to the empty-string bucket at storage time.
|
|
934
865
|
path: coercePathSegments(issue.path),
|
|
935
|
-
formKey,
|
|
936
866
|
code
|
|
937
867
|
});
|
|
938
868
|
}
|
|
@@ -1092,271 +1022,6 @@ function unwrapToDiscriminatedUnion(schema, depth = 0) {
|
|
|
1092
1022
|
}
|
|
1093
1023
|
return void 0;
|
|
1094
1024
|
}
|
|
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
1025
|
function peelAllV3Wrappers(schema) {
|
|
1361
1026
|
let current = schema;
|
|
1362
1027
|
for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
|
|
@@ -1383,6 +1048,17 @@ function peelAllV3Wrappers(schema) {
|
|
|
1383
1048
|
}
|
|
1384
1049
|
return current;
|
|
1385
1050
|
}
|
|
1051
|
+
function getDefaultValuesFromZodSchema(formSchema, useDefaultSchemaValues, formKey) {
|
|
1052
|
+
return deriveDefaultWalk(formSchema, useDefaultSchemaValues, V3_INTROSPECTOR, 64, {
|
|
1053
|
+
unsupportedKindFallback: (schema) => {
|
|
1054
|
+
const kindName = schema.constructor?.name ?? "unknown";
|
|
1055
|
+
console.warn(
|
|
1056
|
+
`[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.`
|
|
1057
|
+
);
|
|
1058
|
+
return null;
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1386
1062
|
function resolveFieldMetaAtPathV3(rootSchema, path, maxRecursionDepth) {
|
|
1387
1063
|
const lastSegment = path.length === 0 ? "" : path[path.length - 1];
|
|
1388
1064
|
const target = path.length === 0 ? rootSchema : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth)[0];
|
|
@@ -1394,14 +1070,14 @@ function resolveFieldMetaAtPathV3(rootSchema, path, maxRecursionDepth) {
|
|
|
1394
1070
|
meta: Object.freeze({})
|
|
1395
1071
|
};
|
|
1396
1072
|
}
|
|
1397
|
-
const pathMap =
|
|
1073
|
+
const pathMap = buildFieldMetaPathMap(rootSchema, {
|
|
1398
1074
|
intro: V3_INTROSPECTOR,
|
|
1399
1075
|
peelAllWrappers: peelAllV3Wrappers,
|
|
1400
|
-
getFieldMetaList
|
|
1076
|
+
getFieldMetaList: getFieldMetaListForSchema
|
|
1401
1077
|
});
|
|
1402
1078
|
const pathKey = canonicalizePath(path).key;
|
|
1403
1079
|
const peeled = peelV3Wrappers(target);
|
|
1404
|
-
const payload = pathMap
|
|
1080
|
+
const payload = pathMap?.get(pathKey) ?? getFieldMetaForSchema(target) ?? (peeled !== target ? getFieldMetaForSchema(peeled) : void 0);
|
|
1405
1081
|
const targetDescription = typeof target.description === "string" ? target.description : void 0;
|
|
1406
1082
|
const peeledDescription = peeled !== target && typeof peeled.description === "string" ? peeled.description : void 0;
|
|
1407
1083
|
const schemaDescription = targetDescription ?? peeledDescription;
|
|
@@ -1418,24 +1094,7 @@ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1418
1094
|
config.useDefaultSchemaValues,
|
|
1419
1095
|
formKey
|
|
1420
1096
|
);
|
|
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
|
-
}
|
|
1097
|
+
const rawDefaultValues = mergeDeep(defaultValuesWithoutConstraints, config.constraints);
|
|
1439
1098
|
if ((config.strict ?? true) !== false) {
|
|
1440
1099
|
if (containsAsyncTransform(rootSchema)) {
|
|
1441
1100
|
return {
|
|
@@ -1457,7 +1116,7 @@ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1457
1116
|
}
|
|
1458
1117
|
return {
|
|
1459
1118
|
data: rawDefaultValues,
|
|
1460
|
-
errors: zodIssuesToValidationErrors(strictResult.error.issues
|
|
1119
|
+
errors: zodIssuesToValidationErrors(strictResult.error.issues),
|
|
1461
1120
|
success: false,
|
|
1462
1121
|
formKey
|
|
1463
1122
|
};
|
|
@@ -1476,7 +1135,7 @@ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1476
1135
|
}
|
|
1477
1136
|
return {
|
|
1478
1137
|
data: rawDefaultValues,
|
|
1479
|
-
errors: zodIssuesToValidationErrors(strippedResult.error.issues
|
|
1138
|
+
errors: zodIssuesToValidationErrors(strippedResult.error.issues),
|
|
1480
1139
|
success: false,
|
|
1481
1140
|
formKey
|
|
1482
1141
|
};
|
|
@@ -1497,119 +1156,25 @@ function runStrictGetDefaultsV3(rootSchema, config, formKey, maxRecursionDepth)
|
|
|
1497
1156
|
};
|
|
1498
1157
|
}
|
|
1499
1158
|
}
|
|
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
|
-
}
|
|
1159
|
+
const fixed = fixStructuralDefaults(
|
|
1160
|
+
rootSchema,
|
|
1161
|
+
rawDefaultValues,
|
|
1162
|
+
config.useDefaultSchemaValues,
|
|
1163
|
+
maxRecursionDepth,
|
|
1164
|
+
{
|
|
1165
|
+
intro: V3_INTROSPECTOR,
|
|
1166
|
+
slimPrimitivesOf: (s) => slimPrimitivesV3(s),
|
|
1167
|
+
deriveDefault: (s, useDefault) => getDefaultValuesFromZodSchema(s, useDefault, formKey),
|
|
1168
|
+
unwrapToDiscriminatedUnion: (s) => unwrapToDiscriminatedUnion(s)
|
|
1581
1169
|
}
|
|
1582
|
-
|
|
1583
|
-
fixedData = mergeDeep(rawDefaultValues, fixedData);
|
|
1584
|
-
const secondParse = slimSchema.safeParse(fixedData);
|
|
1585
|
-
const finalData = secondParse.success ? secondParse.data : fixedData;
|
|
1170
|
+
);
|
|
1586
1171
|
return {
|
|
1587
|
-
data:
|
|
1172
|
+
data: fixed.data,
|
|
1588
1173
|
errors: void 0,
|
|
1589
1174
|
success: true,
|
|
1590
1175
|
formKey
|
|
1591
1176
|
};
|
|
1592
1177
|
}
|
|
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
1178
|
|
|
1614
1179
|
function useForm(configuration) {
|
|
1615
1180
|
if (configuration === void 0 || configuration === null || configuration.schema === void 0) {
|
|
@@ -1627,5 +1192,4 @@ function useForm(configuration) {
|
|
|
1627
1192
|
});
|
|
1628
1193
|
}
|
|
1629
1194
|
|
|
1630
|
-
export {
|
|
1631
|
-
//# sourceMappingURL=attaform.B1ZYt2Li.mjs.map
|
|
1195
|
+
export { isZodSchemaType as i, useForm as u, zodAdapter as z };
|