attaform 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -11
- package/dist/chunks/devtools.cjs +4 -4
- package/dist/chunks/devtools.cjs.map +1 -1
- package/dist/chunks/devtools.mjs +2 -2
- package/dist/chunks/indexeddb.cjs +4 -4
- package/dist/chunks/indexeddb.cjs.map +1 -1
- package/dist/chunks/indexeddb.mjs +1 -1
- package/dist/chunks/local-storage.cjs +2 -2
- package/dist/chunks/local-storage.cjs.map +1 -1
- package/dist/chunks/local-storage.mjs +1 -1
- package/dist/chunks/session-storage.cjs +2 -2
- package/dist/chunks/session-storage.cjs.map +1 -1
- package/dist/chunks/session-storage.mjs +1 -1
- package/dist/index.cjs +23 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -71
- package/dist/index.d.mts +76 -71
- package/dist/index.d.ts +76 -71
- package/dist/index.mjs +6 -6
- package/dist/nuxt.cjs +5 -11
- package/dist/nuxt.cjs.map +1 -1
- package/dist/nuxt.d.cts +8 -0
- package/dist/nuxt.d.mts +8 -0
- package/dist/nuxt.d.ts +8 -0
- package/dist/nuxt.mjs +6 -12
- package/dist/nuxt.mjs.map +1 -1
- package/dist/runtime/plugins/attaform.cjs +3 -2
- package/dist/runtime/plugins/attaform.cjs.map +1 -1
- package/dist/runtime/plugins/attaform.mjs +2 -1
- package/dist/runtime/plugins/attaform.mjs.map +1 -1
- package/dist/shared/{attaform.BwaYWtMs.d.cts → attaform.B7rzpK1U.d.cts} +34 -5
- package/dist/shared/{attaform.BwaYWtMs.d.mts → attaform.B7rzpK1U.d.mts} +34 -5
- package/dist/shared/{attaform.BwaYWtMs.d.ts → attaform.B7rzpK1U.d.ts} +34 -5
- package/dist/shared/attaform.BAuJTWuT.d.mts +84 -0
- package/dist/shared/{attaform.CRk8NhlD.mjs → attaform.BfMxsfmE.mjs} +428 -49
- package/dist/shared/attaform.BfMxsfmE.mjs.map +1 -0
- package/dist/shared/attaform.Bp1c-uGF.cjs +1561 -0
- package/dist/shared/attaform.Bp1c-uGF.cjs.map +1 -0
- package/dist/shared/{attaform.CDJVeoJU.cjs → attaform.C9Ph2SMx.cjs} +49 -42
- package/dist/shared/{attaform.qxyip_aN.mjs.map → attaform.C9Ph2SMx.cjs.map} +1 -1
- package/dist/shared/attaform.CINUMjPq.mjs +29 -0
- package/dist/shared/attaform.CINUMjPq.mjs.map +1 -0
- package/dist/shared/attaform.CJttVxRj.cjs +32 -0
- package/dist/shared/attaform.CJttVxRj.cjs.map +1 -0
- package/dist/shared/{attaform.CPx7zTgS.d.mts → attaform.CVv9Oh0a.d.mts} +9 -7
- package/dist/shared/{attaform.riAENZQM.d.ts → attaform.CWCx2r0x.d.ts} +9 -7
- package/dist/shared/attaform.CvOXSpCb.mjs +1908 -0
- package/dist/shared/attaform.CvOXSpCb.mjs.map +1 -0
- package/dist/shared/{attaform.qxyip_aN.mjs → attaform.DILbdvfo.mjs} +12 -5
- package/dist/shared/{attaform.CDJVeoJU.cjs.map → attaform.DILbdvfo.mjs.map} +1 -1
- package/dist/shared/attaform.DdnithOf.mjs +1555 -0
- package/dist/shared/attaform.DdnithOf.mjs.map +1 -0
- package/dist/shared/attaform.DfrYByDj.cjs +1916 -0
- package/dist/shared/attaform.DfrYByDj.cjs.map +1 -0
- package/dist/shared/{attaform.D-eHWfVx.d.cts → attaform.Dq5BabH1.d.cts} +9 -7
- package/dist/shared/{attaform.BOi138GE.cjs → attaform.c_NzdRyc.cjs} +4 -4
- package/dist/shared/{attaform.BOi138GE.cjs.map → attaform.c_NzdRyc.cjs.map} +1 -1
- package/dist/shared/{attaform.DXye3JKf.mjs → attaform.jrxE_xZw.mjs} +2 -2
- package/dist/shared/{attaform.DXye3JKf.mjs.map → attaform.jrxE_xZw.mjs.map} +1 -1
- package/dist/shared/attaform.ls_7jBYc.d.ts +84 -0
- package/dist/shared/{attaform.BgYBU8gV.cjs → attaform.rIRYSUI1.cjs} +461 -61
- package/dist/shared/attaform.rIRYSUI1.cjs.map +1 -0
- package/dist/shared/attaform.xIcmqscx.d.cts +84 -0
- package/dist/vite.cjs +62 -9
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +23 -32
- package/dist/vite.d.mts +23 -32
- package/dist/vite.d.ts +23 -32
- package/dist/vite.mjs +62 -9
- package/dist/vite.mjs.map +1 -1
- package/dist/zod-v3.cjs +9 -1553
- package/dist/zod-v3.cjs.map +1 -1
- package/dist/zod-v3.d.cts +1 -1
- package/dist/zod-v3.d.mts +1 -1
- package/dist/zod-v3.d.ts +1 -1
- package/dist/zod-v3.mjs +3 -1553
- package/dist/zod-v3.mjs.map +1 -1
- package/dist/zod-v4.cjs +21 -0
- package/dist/zod-v4.cjs.map +1 -0
- package/dist/zod-v4.d.cts +104 -0
- package/dist/zod-v4.d.mts +104 -0
- package/dist/zod-v4.d.ts +104 -0
- package/dist/zod-v4.mjs +4 -0
- package/dist/zod-v4.mjs.map +1 -0
- package/dist/zod.cjs +19 -1900
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +28 -156
- package/dist/zod.d.mts +28 -156
- package/dist/zod.d.ts +28 -156
- package/dist/zod.mjs +19 -1896
- package/dist/zod.mjs.map +1 -1
- package/package.json +6 -2
- package/dist/shared/attaform.BgYBU8gV.cjs.map +0 -1
- package/dist/shared/attaform.CRk8NhlD.mjs.map +0 -1
- package/dist/shared/attaform.RypIkgVy.cjs +0 -417
- package/dist/shared/attaform.RypIkgVy.cjs.map +0 -1
- package/dist/shared/attaform.a99dQV7Q.mjs +0 -392
- package/dist/shared/attaform.a99dQV7Q.mjs.map +0 -1
|
@@ -0,0 +1,1561 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const lodashEs = require('lodash-es');
|
|
4
|
+
const zod = require('zod');
|
|
5
|
+
const useFormContext = require('./attaform.C9Ph2SMx.cjs');
|
|
6
|
+
const paths = require('./attaform.c_NzdRyc.cjs');
|
|
7
|
+
const plugin = require('./attaform.rIRYSUI1.cjs');
|
|
8
|
+
|
|
9
|
+
const store = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
const fieldMeta = {
|
|
11
|
+
add(schema, payload) {
|
|
12
|
+
store.set(schema, payload);
|
|
13
|
+
return fieldMeta;
|
|
14
|
+
},
|
|
15
|
+
get(schema) {
|
|
16
|
+
return store.get(schema);
|
|
17
|
+
},
|
|
18
|
+
has(schema) {
|
|
19
|
+
return store.has(schema);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function withMeta(schema, payload) {
|
|
23
|
+
const existing = store.get(schema) ?? {};
|
|
24
|
+
const Ctor = schema.constructor;
|
|
25
|
+
const cloned = new Ctor(schema._def);
|
|
26
|
+
store.set(cloned, { ...existing, ...payload });
|
|
27
|
+
return cloned;
|
|
28
|
+
}
|
|
29
|
+
function getFieldMeta(schema) {
|
|
30
|
+
return store.get(schema);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class UnsupportedSchemaError extends plugin.AttaformError {
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isZodSchemaType(schema, expectedType) {
|
|
37
|
+
if (typeof schema !== "object" || schema === null) return false;
|
|
38
|
+
const maybeDef = schema._def;
|
|
39
|
+
return maybeDef?.typeName === expectedType;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const UNSUPPORTED_TYPE_NAMES = /* @__PURE__ */ new Set(["ZodPromise", "ZodFunction", "ZodMap", "ZodSymbol"]);
|
|
43
|
+
function labelPath(path) {
|
|
44
|
+
return path.length === 0 ? "<root>" : path.join(".");
|
|
45
|
+
}
|
|
46
|
+
function getTypeName(schema) {
|
|
47
|
+
const def = schema._def;
|
|
48
|
+
return def?.typeName;
|
|
49
|
+
}
|
|
50
|
+
function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
51
|
+
const typeName = getTypeName(schema);
|
|
52
|
+
if (typeName !== void 0 && UNSUPPORTED_TYPE_NAMES.has(typeName)) {
|
|
53
|
+
throw new UnsupportedSchemaError(
|
|
54
|
+
`[attaform/zod-v3] unsupported kind '${typeName}' at '${labelPath(path)}'`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
if (isZodSchemaType(schema, "ZodObject")) {
|
|
58
|
+
const shape = schema.shape;
|
|
59
|
+
for (const [key, sub] of Object.entries(shape)) {
|
|
60
|
+
assertSupportedKinds(sub, [...path, key], lazyGetters);
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (isZodSchemaType(schema, "ZodArray")) {
|
|
65
|
+
const inner = schema._def.type;
|
|
66
|
+
if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (isZodSchemaType(schema, "ZodSet")) {
|
|
70
|
+
const inner = schema._def.valueType;
|
|
71
|
+
if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (isZodSchemaType(schema, "ZodRecord")) {
|
|
75
|
+
const inner = schema._def.valueType;
|
|
76
|
+
if (inner) assertSupportedKinds(inner, [...path, "*"], lazyGetters);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (isZodSchemaType(schema, "ZodTuple")) {
|
|
80
|
+
const items = schema._def.items ?? [];
|
|
81
|
+
items.forEach((item, i) => assertSupportedKinds(item, [...path, String(i)], lazyGetters));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (isZodSchemaType(schema, "ZodUnion")) {
|
|
85
|
+
const options = schema._def.options ?? [];
|
|
86
|
+
options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
|
|
90
|
+
const options = schema._def.options ?? [];
|
|
91
|
+
options.forEach((opt, i) => assertSupportedKinds(opt, [...path, `|${i}`], lazyGetters));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (isZodSchemaType(schema, "ZodIntersection")) {
|
|
95
|
+
const def = schema._def;
|
|
96
|
+
if (def.left) assertSupportedKinds(def.left, [...path, "left"], lazyGetters);
|
|
97
|
+
if (def.right) assertSupportedKinds(def.right, [...path, "right"], lazyGetters);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodBranded")) {
|
|
101
|
+
const inner = schema._def.innerType ?? schema._def.type;
|
|
102
|
+
if (inner) assertSupportedKinds(inner, path, lazyGetters);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (isZodSchemaType(schema, "ZodEffects")) {
|
|
106
|
+
const inner = schema.innerType();
|
|
107
|
+
assertSupportedKinds(inner, path, lazyGetters);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (isZodSchemaType(schema, "ZodPipeline")) {
|
|
111
|
+
const inner = schema._def.in;
|
|
112
|
+
if (inner) assertSupportedKinds(inner, path, lazyGetters);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (isZodSchemaType(schema, "ZodLazy")) {
|
|
116
|
+
const getter = schema._def.getter;
|
|
117
|
+
if (getter !== void 0 && lazyGetters.includes(getter)) {
|
|
118
|
+
throw new UnsupportedSchemaError(
|
|
119
|
+
`[attaform/zod-v3] Recursive z.lazy() at '${labelPath(path)}'`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
const inner = getter?.();
|
|
123
|
+
if (inner !== void 0) {
|
|
124
|
+
assertSupportedKinds(
|
|
125
|
+
inner,
|
|
126
|
+
path,
|
|
127
|
+
getter === void 0 ? lazyGetters : [...lazyGetters, getter]
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const cyclicSentinel = "<cyclic>";
|
|
135
|
+
function fingerprintZodSchema(schema) {
|
|
136
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
137
|
+
const inProgress = /* @__PURE__ */ new WeakSet();
|
|
138
|
+
return visit(schema, cache, inProgress);
|
|
139
|
+
}
|
|
140
|
+
function visit(schema, cache, inProgress) {
|
|
141
|
+
const key = schema;
|
|
142
|
+
const cached = cache.get(key);
|
|
143
|
+
if (cached !== void 0) return cached;
|
|
144
|
+
if (inProgress.has(key)) return cyclicSentinel;
|
|
145
|
+
inProgress.add(key);
|
|
146
|
+
try {
|
|
147
|
+
const computed = computeFingerprint(schema, cache, inProgress);
|
|
148
|
+
cache.set(key, computed);
|
|
149
|
+
return computed;
|
|
150
|
+
} finally {
|
|
151
|
+
inProgress.delete(key);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function getDef(schema) {
|
|
155
|
+
return schema._def;
|
|
156
|
+
}
|
|
157
|
+
function computeFingerprint(schema, cache, inProgress) {
|
|
158
|
+
const def = getDef(schema);
|
|
159
|
+
const kind = def.typeName ?? "ZodUnknown";
|
|
160
|
+
const recurse = (child) => visit(child, cache, inProgress);
|
|
161
|
+
switch (kind) {
|
|
162
|
+
case "ZodString":
|
|
163
|
+
case "ZodNumber":
|
|
164
|
+
case "ZodBigInt":
|
|
165
|
+
case "ZodDate":
|
|
166
|
+
return `${kind}${formatChecks(def.checks)}`;
|
|
167
|
+
case "ZodBoolean":
|
|
168
|
+
case "ZodNull":
|
|
169
|
+
case "ZodUndefined":
|
|
170
|
+
case "ZodAny":
|
|
171
|
+
case "ZodUnknown":
|
|
172
|
+
case "ZodNaN":
|
|
173
|
+
case "ZodVoid":
|
|
174
|
+
case "ZodNever":
|
|
175
|
+
return kind;
|
|
176
|
+
case "ZodLiteral":
|
|
177
|
+
return `ZodLiteral:${canonicalStringify(def.value)}`;
|
|
178
|
+
case "ZodEnum":
|
|
179
|
+
case "ZodNativeEnum": {
|
|
180
|
+
const values = def.values ?? [];
|
|
181
|
+
const sorted = [...values].sort((a, b) => {
|
|
182
|
+
const as = String(a);
|
|
183
|
+
const bs = String(b);
|
|
184
|
+
return as < bs ? -1 : as > bs ? 1 : 0;
|
|
185
|
+
});
|
|
186
|
+
return `${kind}:${canonicalStringify(sorted)}`;
|
|
187
|
+
}
|
|
188
|
+
case "ZodObject": {
|
|
189
|
+
const shape = readShapeSafely(def);
|
|
190
|
+
const sortedEntries = Object.entries(shape).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${recurse(v)}`);
|
|
191
|
+
return `ZodObject{${sortedEntries.join(",")}}`;
|
|
192
|
+
}
|
|
193
|
+
case "ZodArray":
|
|
194
|
+
return `ZodArray[${def.type === void 0 ? "?" : recurse(def.type)}]${formatChecks(def.checks)}`;
|
|
195
|
+
case "ZodTuple": {
|
|
196
|
+
const items = def.items ?? [];
|
|
197
|
+
return `ZodTuple[${items.map(recurse).join(",")}]`;
|
|
198
|
+
}
|
|
199
|
+
case "ZodRecord": {
|
|
200
|
+
const keyPart = def.keyType === void 0 ? "?" : recurse(def.keyType);
|
|
201
|
+
const valuePart = def.valueType === void 0 ? "?" : recurse(def.valueType);
|
|
202
|
+
return `ZodRecord<${keyPart},${valuePart}>`;
|
|
203
|
+
}
|
|
204
|
+
case "ZodUnion": {
|
|
205
|
+
const options = (def.options ?? []).map(recurse).sort();
|
|
206
|
+
return `ZodUnion(${options.join("|")})`;
|
|
207
|
+
}
|
|
208
|
+
case "ZodDiscriminatedUnion": {
|
|
209
|
+
const disc = def.discriminator ?? "?";
|
|
210
|
+
const options = (def.options ?? []).map(recurse).sort();
|
|
211
|
+
return `ZodDiscriminatedUnion[${JSON.stringify(disc)}](${options.join("|")})`;
|
|
212
|
+
}
|
|
213
|
+
case "ZodOptional": {
|
|
214
|
+
const inner = def.innerType;
|
|
215
|
+
return inner === void 0 ? "ZodOptional(?)" : `ZodOptional(${recurse(inner)})`;
|
|
216
|
+
}
|
|
217
|
+
case "ZodNullable": {
|
|
218
|
+
const inner = def.innerType;
|
|
219
|
+
return inner === void 0 ? "ZodNullable(?)" : `ZodNullable(${recurse(inner)})`;
|
|
220
|
+
}
|
|
221
|
+
case "ZodDefault": {
|
|
222
|
+
const inner = def.innerType;
|
|
223
|
+
return `ZodDefault[${defaultFactoryRepr(def.defaultValue)}](${inner === void 0 ? "?" : recurse(inner)})`;
|
|
224
|
+
}
|
|
225
|
+
case "ZodReadonly": {
|
|
226
|
+
const inner = def.innerType;
|
|
227
|
+
return inner === void 0 ? "ZodReadonly(?)" : `ZodReadonly(${recurse(inner)})`;
|
|
228
|
+
}
|
|
229
|
+
case "ZodEffects": {
|
|
230
|
+
const effectType = def.effect?.type ?? "effect";
|
|
231
|
+
const inner = def.schema;
|
|
232
|
+
return `ZodEffects:${effectType}:fn:*(${inner === void 0 ? "?" : recurse(inner)})`;
|
|
233
|
+
}
|
|
234
|
+
case "ZodPipeline": {
|
|
235
|
+
const inner = def.schema;
|
|
236
|
+
return inner === void 0 ? "ZodPipeline(?)" : `ZodPipeline(${recurse(inner)})`;
|
|
237
|
+
}
|
|
238
|
+
case "ZodCatch": {
|
|
239
|
+
const inner = def.innerType ?? def.schema;
|
|
240
|
+
const catchRepr = defaultFactoryRepr(def.catchValue);
|
|
241
|
+
return `ZodCatch[${catchRepr}](${inner === void 0 ? "?" : recurse(inner)})`;
|
|
242
|
+
}
|
|
243
|
+
case "ZodLazy": {
|
|
244
|
+
const resolve = def.getter;
|
|
245
|
+
if (typeof resolve !== "function") return "ZodLazy(?)";
|
|
246
|
+
try {
|
|
247
|
+
const inner = resolve();
|
|
248
|
+
return `ZodLazy(${recurse(inner)})`;
|
|
249
|
+
} catch {
|
|
250
|
+
return "ZodLazy(?)";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
case "ZodIntersection": {
|
|
254
|
+
const leftPart = def.left === void 0 ? "?" : recurse(def.left);
|
|
255
|
+
const rightPart = def.right === void 0 ? "?" : recurse(def.right);
|
|
256
|
+
const parts = [leftPart, rightPart].sort();
|
|
257
|
+
return `ZodIntersection(${parts.join("&")})`;
|
|
258
|
+
}
|
|
259
|
+
// Structural opacity — schemas whose runtime behaviour isn't
|
|
260
|
+
// introspectable via `_def` fall here. Still distinguishable
|
|
261
|
+
// from other kinds by the returned string.
|
|
262
|
+
case "ZodPromise":
|
|
263
|
+
case "ZodFunction":
|
|
264
|
+
case "ZodMap":
|
|
265
|
+
case "ZodSet":
|
|
266
|
+
case "ZodSymbol":
|
|
267
|
+
case "ZodBranded":
|
|
268
|
+
default:
|
|
269
|
+
return `${kind}:*`;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function readShapeSafely(def) {
|
|
273
|
+
if (typeof def.shape !== "function") return {};
|
|
274
|
+
try {
|
|
275
|
+
return def.shape();
|
|
276
|
+
} catch {
|
|
277
|
+
return {};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function defaultFactoryRepr(factory) {
|
|
281
|
+
if (typeof factory !== "function") return "none";
|
|
282
|
+
let first;
|
|
283
|
+
let second;
|
|
284
|
+
try {
|
|
285
|
+
first = factory();
|
|
286
|
+
second = factory();
|
|
287
|
+
} catch {
|
|
288
|
+
return "fn:*";
|
|
289
|
+
}
|
|
290
|
+
if (!Object.is(first, second)) return "fn:*";
|
|
291
|
+
if (typeof first === "function") return "fn:*";
|
|
292
|
+
return canonicalStringify(first);
|
|
293
|
+
}
|
|
294
|
+
function formatChecks(checks) {
|
|
295
|
+
if (!Array.isArray(checks) || checks.length === 0) return "";
|
|
296
|
+
const parts = checks.map((c) => canonicalStringify(c)).sort();
|
|
297
|
+
return `[${parts.join(";")}]`;
|
|
298
|
+
}
|
|
299
|
+
function canonicalStringify(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
300
|
+
if (value === null) return "null";
|
|
301
|
+
if (value === void 0) return "undefined";
|
|
302
|
+
const t = typeof value;
|
|
303
|
+
if (t === "string") return JSON.stringify(value);
|
|
304
|
+
if (t === "number" || t === "boolean") return String(value);
|
|
305
|
+
if (t === "bigint") return `${String(value)}n`;
|
|
306
|
+
if (t === "function") return "fn:*";
|
|
307
|
+
if (t === "symbol") return "symbol:*";
|
|
308
|
+
if (Array.isArray(value)) {
|
|
309
|
+
if (seen.has(value)) return "<cyclic>";
|
|
310
|
+
seen.add(value);
|
|
311
|
+
try {
|
|
312
|
+
return `[${value.map((v) => canonicalStringify(v, seen)).join(",")}]`;
|
|
313
|
+
} finally {
|
|
314
|
+
seen.delete(value);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (t === "object") {
|
|
318
|
+
const obj = value;
|
|
319
|
+
if (seen.has(obj)) return "<cyclic>";
|
|
320
|
+
seen.add(obj);
|
|
321
|
+
try {
|
|
322
|
+
if (value instanceof Date) return `date:${value.getTime()}`;
|
|
323
|
+
if (value instanceof RegExp) return `regex:${String(value)}`;
|
|
324
|
+
const entries = Object.entries(obj).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonicalStringify(v, seen)}`);
|
|
325
|
+
return `{${entries.join(",")}}`;
|
|
326
|
+
} finally {
|
|
327
|
+
seen.delete(obj);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return "unknown";
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const PERMISSIVE_V3 = /* @__PURE__ */ new Set([
|
|
334
|
+
"string",
|
|
335
|
+
"number",
|
|
336
|
+
"boolean",
|
|
337
|
+
"bigint",
|
|
338
|
+
"date",
|
|
339
|
+
"null",
|
|
340
|
+
"undefined",
|
|
341
|
+
"object",
|
|
342
|
+
"array",
|
|
343
|
+
"symbol",
|
|
344
|
+
"function",
|
|
345
|
+
"map",
|
|
346
|
+
"set"
|
|
347
|
+
]);
|
|
348
|
+
const MAX_LAZY_DEPTH_V3 = 64;
|
|
349
|
+
function slimPrimitivesV3(schema, depth = 0) {
|
|
350
|
+
if (depth > MAX_LAZY_DEPTH_V3) return new Set(PERMISSIVE_V3);
|
|
351
|
+
const def = schema._def;
|
|
352
|
+
const typeName = def?.typeName;
|
|
353
|
+
if (isZodSchemaType(schema, "ZodString")) return /* @__PURE__ */ new Set(["string"]);
|
|
354
|
+
if (isZodSchemaType(schema, "ZodNumber")) return /* @__PURE__ */ new Set(["number"]);
|
|
355
|
+
if (isZodSchemaType(schema, "ZodBoolean")) return /* @__PURE__ */ new Set(["boolean"]);
|
|
356
|
+
if (isZodSchemaType(schema, "ZodBigInt")) return /* @__PURE__ */ new Set(["bigint"]);
|
|
357
|
+
if (isZodSchemaType(schema, "ZodDate")) return /* @__PURE__ */ new Set(["date"]);
|
|
358
|
+
if (isZodSchemaType(schema, "ZodNull")) return /* @__PURE__ */ new Set(["null"]);
|
|
359
|
+
if (isZodSchemaType(schema, "ZodUndefined")) return /* @__PURE__ */ new Set(["undefined"]);
|
|
360
|
+
if (typeName === "ZodVoid") return /* @__PURE__ */ new Set(["undefined"]);
|
|
361
|
+
if (typeName === "ZodNaN") return /* @__PURE__ */ new Set(["number"]);
|
|
362
|
+
if (isZodSchemaType(schema, "ZodEnum")) {
|
|
363
|
+
const options = schema.options;
|
|
364
|
+
const out = /* @__PURE__ */ new Set();
|
|
365
|
+
for (const v of options) {
|
|
366
|
+
if (typeof v === "string") out.add("string");
|
|
367
|
+
else if (typeof v === "number") out.add("number");
|
|
368
|
+
}
|
|
369
|
+
return out.size === 0 ? /* @__PURE__ */ new Set(["string"]) : out;
|
|
370
|
+
}
|
|
371
|
+
if (isZodSchemaType(schema, "ZodLiteral")) {
|
|
372
|
+
const value = schema.value;
|
|
373
|
+
return /* @__PURE__ */ new Set([slimKindOfRawV3(value)]);
|
|
374
|
+
}
|
|
375
|
+
if (isZodSchemaType(schema, "ZodObject") || typeName === "ZodRecord") {
|
|
376
|
+
return /* @__PURE__ */ new Set(["object"]);
|
|
377
|
+
}
|
|
378
|
+
if (isZodSchemaType(schema, "ZodArray") || typeName === "ZodTuple") {
|
|
379
|
+
return /* @__PURE__ */ new Set(["array"]);
|
|
380
|
+
}
|
|
381
|
+
if (isZodSchemaType(schema, "ZodSet")) {
|
|
382
|
+
return /* @__PURE__ */ new Set(["set"]);
|
|
383
|
+
}
|
|
384
|
+
if (isZodSchemaType(schema, "ZodOptional")) {
|
|
385
|
+
const inner = def?.innerType;
|
|
386
|
+
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : slimPrimitivesV3(inner, depth + 1);
|
|
387
|
+
innerSet.add("undefined");
|
|
388
|
+
return innerSet;
|
|
389
|
+
}
|
|
390
|
+
if (isZodSchemaType(schema, "ZodNullable")) {
|
|
391
|
+
const inner = def?.innerType;
|
|
392
|
+
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : slimPrimitivesV3(inner, depth + 1);
|
|
393
|
+
innerSet.add("null");
|
|
394
|
+
return innerSet;
|
|
395
|
+
}
|
|
396
|
+
if (isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodBranded")) {
|
|
397
|
+
const inner = def?.innerType ?? def?.type;
|
|
398
|
+
return inner === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(inner, depth + 1);
|
|
399
|
+
}
|
|
400
|
+
if (isZodSchemaType(schema, "ZodEffects")) {
|
|
401
|
+
const inner = def?.schema;
|
|
402
|
+
return inner === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(inner, depth + 1);
|
|
403
|
+
}
|
|
404
|
+
if (isZodSchemaType(schema, "ZodPipeline")) {
|
|
405
|
+
const inner = def?.in;
|
|
406
|
+
return inner === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(inner, depth + 1);
|
|
407
|
+
}
|
|
408
|
+
if (typeName === "ZodLazy") {
|
|
409
|
+
const getter = def?.getter;
|
|
410
|
+
if (typeof getter !== "function") return new Set(PERMISSIVE_V3);
|
|
411
|
+
return slimPrimitivesV3(getter(), depth + 1);
|
|
412
|
+
}
|
|
413
|
+
if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
|
|
414
|
+
const options = def?.options ?? [];
|
|
415
|
+
const out = /* @__PURE__ */ new Set();
|
|
416
|
+
for (const opt of options) {
|
|
417
|
+
for (const k of slimPrimitivesV3(opt, depth + 1)) out.add(k);
|
|
418
|
+
}
|
|
419
|
+
return out.size === 0 ? new Set(PERMISSIVE_V3) : out;
|
|
420
|
+
}
|
|
421
|
+
if (typeName === "ZodIntersection") {
|
|
422
|
+
const left = def?.left;
|
|
423
|
+
const right = def?.right;
|
|
424
|
+
const leftSet = left === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(left, depth + 1);
|
|
425
|
+
const rightSet = right === void 0 ? new Set(PERMISSIVE_V3) : slimPrimitivesV3(right, depth + 1);
|
|
426
|
+
const out = /* @__PURE__ */ new Set();
|
|
427
|
+
for (const k of leftSet) if (rightSet.has(k)) out.add(k);
|
|
428
|
+
return out;
|
|
429
|
+
}
|
|
430
|
+
if (typeName === "ZodNever") return /* @__PURE__ */ new Set();
|
|
431
|
+
if (typeName === "ZodAny" || typeName === "ZodUnknown") return new Set(PERMISSIVE_V3);
|
|
432
|
+
return new Set(PERMISSIVE_V3);
|
|
433
|
+
}
|
|
434
|
+
function slimKindOfRawV3(value) {
|
|
435
|
+
if (value === null) return "null";
|
|
436
|
+
if (value === void 0) return "undefined";
|
|
437
|
+
if (Array.isArray(value)) return "array";
|
|
438
|
+
if (value instanceof Date) return "date";
|
|
439
|
+
const t = typeof value;
|
|
440
|
+
switch (t) {
|
|
441
|
+
case "string":
|
|
442
|
+
return "string";
|
|
443
|
+
case "number":
|
|
444
|
+
return "number";
|
|
445
|
+
case "boolean":
|
|
446
|
+
return "boolean";
|
|
447
|
+
case "bigint":
|
|
448
|
+
return "bigint";
|
|
449
|
+
case "symbol":
|
|
450
|
+
return "symbol";
|
|
451
|
+
case "function":
|
|
452
|
+
return "function";
|
|
453
|
+
case "undefined":
|
|
454
|
+
return "undefined";
|
|
455
|
+
case "object":
|
|
456
|
+
return "object";
|
|
457
|
+
default:
|
|
458
|
+
return "object";
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const PATH_SEPARATOR = ".";
|
|
463
|
+
const MAX_UNWRAP_STEPS = 64;
|
|
464
|
+
function isPrimitive(input) {
|
|
465
|
+
const type = typeof input;
|
|
466
|
+
if (type === "string" || type === "number" || type === "boolean" || type === "bigint" || type === "undefined")
|
|
467
|
+
return true;
|
|
468
|
+
return input === null;
|
|
469
|
+
}
|
|
470
|
+
function constraintsAreSlimValid(slimSchema, constraints) {
|
|
471
|
+
try {
|
|
472
|
+
return slimSchema.safeParse(constraints).success;
|
|
473
|
+
} catch {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
let warnedZodCodeMissing = false;
|
|
478
|
+
function zodAdapter(zodSchema) {
|
|
479
|
+
function getAbstractSchema(_formKey, _zodSchema, _isRootSchema) {
|
|
480
|
+
if (_isRootSchema) {
|
|
481
|
+
assertSupportedKinds(_zodSchema);
|
|
482
|
+
const [_schema] = stripRootSchema(_zodSchema, {
|
|
483
|
+
stripDefaultValues: true,
|
|
484
|
+
stripNullable: true,
|
|
485
|
+
stripOptional: true,
|
|
486
|
+
stripZodEffects: true,
|
|
487
|
+
stripZodRefinements: true
|
|
488
|
+
});
|
|
489
|
+
if (!isZodSchemaType(_schema, "ZodObject")) {
|
|
490
|
+
const name = _schema._def.typeName;
|
|
491
|
+
throw new Error(`ZodAdapter: expected ZodObject, got ${name}`);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
const leafCache = /* @__PURE__ */ new Map();
|
|
495
|
+
const abstractSchema = {
|
|
496
|
+
fingerprint: () => fingerprintZodSchema(_zodSchema),
|
|
497
|
+
getDefaultValues(config) {
|
|
498
|
+
const defaultValuesWithoutConstraints = getDefaultValuesFromZodSchema(
|
|
499
|
+
_zodSchema,
|
|
500
|
+
config.useDefaultSchemaValues,
|
|
501
|
+
_formKey
|
|
502
|
+
);
|
|
503
|
+
const slimSchema = getSlimSchema({
|
|
504
|
+
schema: _zodSchema,
|
|
505
|
+
stripConfig: {
|
|
506
|
+
stripZodEffects: true,
|
|
507
|
+
stripDefaultValues: true,
|
|
508
|
+
// `strict: false` strips refinements (so empty defaults
|
|
509
|
+
// pass); strict keeps them so the slim parse below
|
|
510
|
+
// surfaces refinement errors. Async refines are guarded
|
|
511
|
+
// by the try/catch below — they can't be surfaced
|
|
512
|
+
// synchronously regardless.
|
|
513
|
+
stripZodRefinements: (config.strict ?? true) === false
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
let rawDefaultValues = defaultValuesWithoutConstraints;
|
|
517
|
+
if (!isPrimitive(rawDefaultValues)) {
|
|
518
|
+
rawDefaultValues = lodashEs.merge(defaultValuesWithoutConstraints, config.constraints);
|
|
519
|
+
} else if (constraintsAreSlimValid(slimSchema, config.constraints)) {
|
|
520
|
+
rawDefaultValues = config.constraints;
|
|
521
|
+
}
|
|
522
|
+
let parseResult;
|
|
523
|
+
try {
|
|
524
|
+
parseResult = slimSchema.safeParse(rawDefaultValues);
|
|
525
|
+
} catch {
|
|
526
|
+
return {
|
|
527
|
+
data: rawDefaultValues,
|
|
528
|
+
errors: void 0,
|
|
529
|
+
success: true,
|
|
530
|
+
formKey: _formKey
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
const { data, success, error } = parseResult;
|
|
534
|
+
if (success) {
|
|
535
|
+
return {
|
|
536
|
+
data,
|
|
537
|
+
errors: void 0,
|
|
538
|
+
success,
|
|
539
|
+
formKey: _formKey
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
let fixedData = {};
|
|
543
|
+
{
|
|
544
|
+
for (const issue of error.issues) {
|
|
545
|
+
const schemasAtPath = getNestedZodSchemasAtPath(slimSchema, issue.path);
|
|
546
|
+
const path = coercePathSegments(issue.path);
|
|
547
|
+
if (!schemasAtPath.length) {
|
|
548
|
+
console.error(
|
|
549
|
+
`[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.)`
|
|
550
|
+
);
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
const candidate = schemasAtPath[0];
|
|
554
|
+
if (candidate !== void 0) {
|
|
555
|
+
const valueAtPath = useFormContext.getAtPath(rawDefaultValues, path);
|
|
556
|
+
const slimKinds = slimPrimitivesV3(candidate);
|
|
557
|
+
if (slimKinds.size > 0 && slimKinds.has(useFormContext.slimKindOf(valueAtPath))) {
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
for (const schemaAtPath of schemasAtPath) {
|
|
562
|
+
if (issue.code === "invalid_type") {
|
|
563
|
+
const isDiscriminatedUnion = isZodSchemaType(schemaAtPath, "ZodDiscriminatedUnion");
|
|
564
|
+
const defaultValueContext = isDiscriminatedUnion ? {
|
|
565
|
+
formKey: _formKey,
|
|
566
|
+
discriminator: {
|
|
567
|
+
isDiscriminatorKey: true,
|
|
568
|
+
schema: schemaAtPath,
|
|
569
|
+
useDefaultSchemaValues: false
|
|
570
|
+
}
|
|
571
|
+
} : {
|
|
572
|
+
formKey: _formKey,
|
|
573
|
+
discriminator: {
|
|
574
|
+
isDiscriminatorKey: false,
|
|
575
|
+
schema: void 0,
|
|
576
|
+
useDefaultSchemaValues: false
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
const defaultValue2 = getDefaultValue(issue.expected, defaultValueContext);
|
|
580
|
+
lodashEs.set(fixedData, path, defaultValue2);
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
const [defaultValue, found] = unwrapDefault(schemaAtPath);
|
|
584
|
+
if (found) {
|
|
585
|
+
lodashEs.set(fixedData, path, defaultValue);
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
const ctx = {
|
|
589
|
+
formKey: _formKey,
|
|
590
|
+
discriminator: {
|
|
591
|
+
isDiscriminatorKey: false,
|
|
592
|
+
schema: void 0,
|
|
593
|
+
useDefaultSchemaValues: false
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
const slimKinds = slimPrimitivesV3(schemaAtPath);
|
|
597
|
+
const firstKind = [...slimKinds][0];
|
|
598
|
+
if (firstKind !== void 0) {
|
|
599
|
+
const expected = firstKind === "string" ? "string" : firstKind === "number" ? "number" : firstKind === "boolean" ? "boolean" : firstKind === "bigint" ? "bigint" : firstKind === "date" ? "date" : firstKind === "array" ? "array" : firstKind === "object" ? "object" : null;
|
|
600
|
+
if (expected !== null) {
|
|
601
|
+
lodashEs.set(fixedData, path, getDefaultValue(expected, ctx));
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
fixedData = lodashEs.merge(rawDefaultValues, fixedData);
|
|
607
|
+
}
|
|
608
|
+
const secondParse = slimSchema.safeParse(fixedData);
|
|
609
|
+
const finalData = secondParse.success ? secondParse.data : fixedData;
|
|
610
|
+
if ((config.strict ?? true) === false) {
|
|
611
|
+
return {
|
|
612
|
+
data: finalData,
|
|
613
|
+
errors: void 0,
|
|
614
|
+
success: true,
|
|
615
|
+
formKey: _formKey
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
if (secondParse.success) {
|
|
619
|
+
return {
|
|
620
|
+
data: finalData,
|
|
621
|
+
errors: void 0,
|
|
622
|
+
success: true,
|
|
623
|
+
formKey: _formKey
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
return {
|
|
627
|
+
data: finalData,
|
|
628
|
+
errors: zodIssuesToValidationErrors(error.issues, _formKey),
|
|
629
|
+
success: false,
|
|
630
|
+
formKey: _formKey
|
|
631
|
+
};
|
|
632
|
+
},
|
|
633
|
+
getDefaultAtPath(path) {
|
|
634
|
+
if (path.length === 0) {
|
|
635
|
+
return getDefaultValuesFromZodSchema(_zodSchema, true, _formKey);
|
|
636
|
+
}
|
|
637
|
+
const leaf = walkV3ToLeafSchema(_zodSchema, path);
|
|
638
|
+
if (!leaf) return void 0;
|
|
639
|
+
const peeled = unwrapStructuralLeafV3(leaf);
|
|
640
|
+
return getDefaultValuesFromZodSchema(peeled, true, _formKey);
|
|
641
|
+
},
|
|
642
|
+
arrayShapeAtPath(path) {
|
|
643
|
+
if (path.length === 0) return void 0;
|
|
644
|
+
const leaf = walkV3ToLeafSchema(_zodSchema, path);
|
|
645
|
+
if (!leaf) return void 0;
|
|
646
|
+
let peeled = peelV3Wrappers(leaf);
|
|
647
|
+
for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
|
|
648
|
+
if (!isZodSchemaType(peeled, "ZodCatch")) break;
|
|
649
|
+
const inner = peeled._def.innerType;
|
|
650
|
+
if (!inner) break;
|
|
651
|
+
peeled = peelV3Wrappers(inner);
|
|
652
|
+
}
|
|
653
|
+
if (isZodSchemaType(peeled, "ZodTuple")) {
|
|
654
|
+
const items = peeled._def.items;
|
|
655
|
+
return Array.isArray(items) ? items.length : void 0;
|
|
656
|
+
}
|
|
657
|
+
if (isZodSchemaType(peeled, "ZodArray")) return null;
|
|
658
|
+
return void 0;
|
|
659
|
+
},
|
|
660
|
+
getSchemasAtPath(path) {
|
|
661
|
+
const [strippedSchema] = stripRootSchema(_zodSchema, {
|
|
662
|
+
stripDefaultValues: true,
|
|
663
|
+
stripNullable: true,
|
|
664
|
+
stripOptional: true,
|
|
665
|
+
stripZodEffects: true
|
|
666
|
+
});
|
|
667
|
+
const slimSchema = getSlimSchema({
|
|
668
|
+
schema: strippedSchema,
|
|
669
|
+
stripConfig: {
|
|
670
|
+
stripDefaultValues: true,
|
|
671
|
+
stripZodEffects: true
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
const nestedZodSchemas = getNestedZodSchemasAtPath(slimSchema, path);
|
|
675
|
+
if (!nestedZodSchemas.length) return [];
|
|
676
|
+
return nestedZodSchemas.map(
|
|
677
|
+
(n) => getAbstractSchema(_formKey, n, false)
|
|
678
|
+
);
|
|
679
|
+
},
|
|
680
|
+
isRequiredAtPath(path) {
|
|
681
|
+
if (path.length === 0) return true;
|
|
682
|
+
const leaf = walkV3ToLeafSchema(_zodSchema, path);
|
|
683
|
+
if (!leaf) return false;
|
|
684
|
+
return isLeafRequiredV3(leaf);
|
|
685
|
+
},
|
|
686
|
+
getFieldMetaAtPath(path) {
|
|
687
|
+
return resolveFieldMetaAtPathV3(_zodSchema, path);
|
|
688
|
+
},
|
|
689
|
+
getUnionDiscriminatorAtPath(path) {
|
|
690
|
+
const candidates = path.length === 0 ? [_zodSchema] : getNestedZodSchemasAtPath(_zodSchema, path);
|
|
691
|
+
let matchedUnion;
|
|
692
|
+
for (const candidate of candidates) {
|
|
693
|
+
const peeled = peelV3Wrappers(candidate);
|
|
694
|
+
if (!isZodSchemaType(peeled, "ZodDiscriminatedUnion")) continue;
|
|
695
|
+
if (matchedUnion !== void 0 && matchedUnion !== peeled) return void 0;
|
|
696
|
+
matchedUnion = peeled;
|
|
697
|
+
}
|
|
698
|
+
if (matchedUnion === void 0) return void 0;
|
|
699
|
+
const discKey = matchedUnion._def.discriminator;
|
|
700
|
+
const options = matchedUnion._def.options;
|
|
701
|
+
return {
|
|
702
|
+
discriminatorKey: discKey,
|
|
703
|
+
getVariantDefault(value) {
|
|
704
|
+
for (const opt of options) {
|
|
705
|
+
const litSchema = opt.shape[discKey];
|
|
706
|
+
if (!litSchema) continue;
|
|
707
|
+
if (!isZodSchemaType(litSchema, "ZodLiteral")) continue;
|
|
708
|
+
if (litSchema._def.value === value) {
|
|
709
|
+
return getDefaultValuesFromZodSchema(opt, true, _formKey);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return void 0;
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
},
|
|
716
|
+
getSlimPrimitiveTypesAtPath(path) {
|
|
717
|
+
if (path.length === 0) return /* @__PURE__ */ new Set(["object"]);
|
|
718
|
+
const [strippedSchema] = stripRootSchema(_zodSchema, {
|
|
719
|
+
stripDefaultValues: true,
|
|
720
|
+
stripNullable: true,
|
|
721
|
+
stripOptional: true,
|
|
722
|
+
stripZodEffects: true
|
|
723
|
+
});
|
|
724
|
+
const slimSchema = getSlimSchema({
|
|
725
|
+
schema: strippedSchema,
|
|
726
|
+
stripConfig: { stripDefaultValues: true, stripZodEffects: true }
|
|
727
|
+
});
|
|
728
|
+
const resolved = getNestedZodSchemasAtPath(slimSchema, path);
|
|
729
|
+
if (resolved.length === 0) return /* @__PURE__ */ new Set();
|
|
730
|
+
const out = /* @__PURE__ */ new Set();
|
|
731
|
+
for (const candidate of resolved) {
|
|
732
|
+
for (const k of slimPrimitivesV3(candidate)) out.add(k);
|
|
733
|
+
}
|
|
734
|
+
return out;
|
|
735
|
+
},
|
|
736
|
+
isLeafAtPath(path) {
|
|
737
|
+
const cacheKey = paths.canonicalizePath(path).key;
|
|
738
|
+
const cached = leafCache.get(cacheKey);
|
|
739
|
+
if (cached !== void 0) return cached;
|
|
740
|
+
const prim = abstractSchema.getSlimPrimitiveTypesAtPath(path);
|
|
741
|
+
const isLeaf = prim.size > 0 && !prim.has("object") && !prim.has("array") && !prim.has("map") && !prim.has("set");
|
|
742
|
+
leafCache.set(cacheKey, isLeaf);
|
|
743
|
+
return isLeaf;
|
|
744
|
+
},
|
|
745
|
+
validateAtPath(data, path, options) {
|
|
746
|
+
const trySync = options?.sync === true;
|
|
747
|
+
if (trySync) {
|
|
748
|
+
try {
|
|
749
|
+
return runSync();
|
|
750
|
+
} catch {
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return runAsync();
|
|
754
|
+
function runSync() {
|
|
755
|
+
if (path === void 0) {
|
|
756
|
+
const { success, data: successData, error } = _zodSchema.safeParse(data);
|
|
757
|
+
return success ? { data: successData, success, errors: void 0, formKey: _formKey } : {
|
|
758
|
+
success,
|
|
759
|
+
data: void 0,
|
|
760
|
+
errors: zodIssuesToValidationErrors(error.issues, _formKey),
|
|
761
|
+
formKey: _formKey
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
const nestedZodSchemas = nestedSchemasAtPath(path);
|
|
765
|
+
if (!nestedZodSchemas.length) return pathNotFound(path);
|
|
766
|
+
const accumulatedErrors = [];
|
|
767
|
+
for (const nestedSchema of nestedZodSchemas) {
|
|
768
|
+
const { data: successData, success, error } = nestedSchema.safeParse(data);
|
|
769
|
+
if (!success) {
|
|
770
|
+
accumulatedErrors.push(error);
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
return { data: successData, errors: void 0, success: true, formKey: _formKey };
|
|
774
|
+
}
|
|
775
|
+
return aggregatedFailure(accumulatedErrors);
|
|
776
|
+
}
|
|
777
|
+
async function runAsync() {
|
|
778
|
+
if (path === void 0) {
|
|
779
|
+
const { success, data: successData, error } = await _zodSchema.safeParseAsync(data);
|
|
780
|
+
return success ? { data: successData, success, errors: void 0, formKey: _formKey } : {
|
|
781
|
+
success,
|
|
782
|
+
data: void 0,
|
|
783
|
+
errors: zodIssuesToValidationErrors(error.issues, _formKey),
|
|
784
|
+
formKey: _formKey
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
const nestedZodSchemas = nestedSchemasAtPath(path);
|
|
788
|
+
if (!nestedZodSchemas.length) return pathNotFound(path);
|
|
789
|
+
const accumulatedErrors = [];
|
|
790
|
+
for (const nestedSchema of nestedZodSchemas) {
|
|
791
|
+
const { data: successData, success, error } = await nestedSchema.safeParseAsync(data);
|
|
792
|
+
if (!success) {
|
|
793
|
+
accumulatedErrors.push(error);
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
return { data: successData, errors: void 0, success: true, formKey: _formKey };
|
|
797
|
+
}
|
|
798
|
+
return aggregatedFailure(accumulatedErrors);
|
|
799
|
+
}
|
|
800
|
+
function nestedSchemasAtPath(p) {
|
|
801
|
+
const [strippedSchema] = stripRootSchema(_zodSchema, {
|
|
802
|
+
stripDefaultValues: true,
|
|
803
|
+
stripNullable: true,
|
|
804
|
+
stripOptional: true
|
|
805
|
+
});
|
|
806
|
+
const slimSchema = getSlimSchema({
|
|
807
|
+
schema: strippedSchema,
|
|
808
|
+
stripConfig: { stripDefaultValues: true }
|
|
809
|
+
});
|
|
810
|
+
return getNestedZodSchemasAtPath(slimSchema, p);
|
|
811
|
+
}
|
|
812
|
+
function pathNotFound(p) {
|
|
813
|
+
return {
|
|
814
|
+
data: void 0,
|
|
815
|
+
errors: NO_SCHEMAS_FOUND_AT_PATH_OF_CONCRETE_SCHEMA([...p], _formKey),
|
|
816
|
+
success: false,
|
|
817
|
+
formKey: _formKey
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
function aggregatedFailure(errors) {
|
|
821
|
+
const allIssues = errors.reduce((acc, e) => [...acc, ...e.issues], []);
|
|
822
|
+
return {
|
|
823
|
+
data: void 0,
|
|
824
|
+
errors: zodIssuesToValidationErrors(allIssues, _formKey),
|
|
825
|
+
success: false,
|
|
826
|
+
formKey: _formKey
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
return abstractSchema;
|
|
832
|
+
}
|
|
833
|
+
return (formKey) => getAbstractSchema(formKey, zodSchema, true);
|
|
834
|
+
}
|
|
835
|
+
function zodIssuesToValidationErrors(issues, formKey) {
|
|
836
|
+
const validationErrors = [];
|
|
837
|
+
for (const issue of issues) {
|
|
838
|
+
let code;
|
|
839
|
+
if (typeof issue.code === "string" && issue.code.length > 0) {
|
|
840
|
+
code = `zod:${issue.code}`;
|
|
841
|
+
} else {
|
|
842
|
+
code = "zod:unknown";
|
|
843
|
+
if (plugin.__DEV__ && !warnedZodCodeMissing) {
|
|
844
|
+
warnedZodCodeMissing = true;
|
|
845
|
+
console.warn(
|
|
846
|
+
"[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."
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
validationErrors.push({
|
|
851
|
+
message: issue.message,
|
|
852
|
+
// `ValidationError.path` is `(string | number)[]` per the
|
|
853
|
+
// public type. v3's `issue.path` is the same in the standard
|
|
854
|
+
// case, but a custom check via `ctx.addIssue({ path: [...] })`
|
|
855
|
+
// can smuggle a Symbol through — the public surface promised
|
|
856
|
+
// strings/numbers, so coerce defensively to keep the contract.
|
|
857
|
+
// Mirrors v4's behaviour at the same site.
|
|
858
|
+
path: coercePathSegments(issue.path),
|
|
859
|
+
formKey,
|
|
860
|
+
code
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
return validationErrors;
|
|
864
|
+
}
|
|
865
|
+
function coercePathSegments(path) {
|
|
866
|
+
const out = [];
|
|
867
|
+
for (const seg of path) {
|
|
868
|
+
out.push(typeof seg === "number" ? seg : typeof seg === "string" ? seg : String(seg));
|
|
869
|
+
}
|
|
870
|
+
return out;
|
|
871
|
+
}
|
|
872
|
+
const NO_SCHEMAS_FOUND_AT_PATH_OF_CONCRETE_SCHEMA = (path, formKey) => [
|
|
873
|
+
{
|
|
874
|
+
message: `Programming Error: useForm.validateAtPath failed to find 1 or more schemas corresponding to the path ${path} in the concrete schema. Does the nested schema exist on form with key '${formKey}'?`,
|
|
875
|
+
path,
|
|
876
|
+
formKey,
|
|
877
|
+
code: useFormContext.AttaformErrorCode.PathNotFound
|
|
878
|
+
}
|
|
879
|
+
];
|
|
880
|
+
function getNestedZodSchemasAtPath(zodSchema, segments) {
|
|
881
|
+
function getOptionSchemasFromDiscriminatorByArbitraryKey(schema, key) {
|
|
882
|
+
const successfulOptions = [];
|
|
883
|
+
const options = schema._def.options;
|
|
884
|
+
for (const option of options) {
|
|
885
|
+
if (!(key in option.shape)) continue;
|
|
886
|
+
successfulOptions.push(option);
|
|
887
|
+
}
|
|
888
|
+
return successfulOptions;
|
|
889
|
+
}
|
|
890
|
+
let currentSchema = zodSchema;
|
|
891
|
+
for (let index = 0; index < segments.length; index++) {
|
|
892
|
+
const key = String(segments[index] ?? "");
|
|
893
|
+
if (isZodSchemaType(currentSchema, "ZodObject")) {
|
|
894
|
+
const shape = currentSchema._def.shape();
|
|
895
|
+
currentSchema = Object.hasOwn(shape, key) ? shape[key] : void 0;
|
|
896
|
+
} else if (isZodSchemaType(currentSchema, "ZodArray")) {
|
|
897
|
+
currentSchema = currentSchema._def.type;
|
|
898
|
+
} else if (isZodSchemaType(currentSchema, "ZodSet")) {
|
|
899
|
+
currentSchema = currentSchema._def.valueType;
|
|
900
|
+
} else if (isZodSchemaType(currentSchema, "ZodRecord")) {
|
|
901
|
+
currentSchema = currentSchema._def.valueType;
|
|
902
|
+
} else if (isZodSchemaType(currentSchema, "ZodDiscriminatedUnion")) {
|
|
903
|
+
const optionalSchemas = getOptionSchemasFromDiscriminatorByArbitraryKey(currentSchema, key);
|
|
904
|
+
const remainingSegments = segments.slice(index);
|
|
905
|
+
if (!remainingSegments.length) return optionalSchemas;
|
|
906
|
+
const foundSchemas = [];
|
|
907
|
+
for (const optionSchema of optionalSchemas) {
|
|
908
|
+
getNestedZodSchemasAtPath(optionSchema, remainingSegments).forEach((schema) => {
|
|
909
|
+
foundSchemas.push(schema);
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
return foundSchemas;
|
|
913
|
+
} else {
|
|
914
|
+
return [];
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
if (!currentSchema) return [];
|
|
918
|
+
return [currentSchema];
|
|
919
|
+
}
|
|
920
|
+
function unwrapStructuralLeafV3(schema) {
|
|
921
|
+
let current = schema;
|
|
922
|
+
for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
|
|
923
|
+
if (!(isZodSchemaType(current, "ZodOptional") || isZodSchemaType(current, "ZodNullable"))) {
|
|
924
|
+
break;
|
|
925
|
+
}
|
|
926
|
+
const inner = current._def.innerType;
|
|
927
|
+
if (!inner) return current;
|
|
928
|
+
if (!isStructuralV3Kind(inner)) break;
|
|
929
|
+
current = inner;
|
|
930
|
+
}
|
|
931
|
+
return current;
|
|
932
|
+
}
|
|
933
|
+
function isStructuralV3Kind(schema) {
|
|
934
|
+
return isZodSchemaType(schema, "ZodObject") || isZodSchemaType(schema, "ZodArray") || isZodSchemaType(schema, "ZodRecord") || isZodSchemaType(schema, "ZodTuple") || isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion") || // Wrappers that themselves resolve to a structural type — keep
|
|
935
|
+
// peeling at the next iteration.
|
|
936
|
+
isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodEffects") || // Newer transparent wrappers (v3.23+). Each wraps a single inner
|
|
937
|
+
// schema with no structural impact — `peelV3Wrappers` resolves them.
|
|
938
|
+
isZodSchemaType(schema, "ZodPipeline") || isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodBranded");
|
|
939
|
+
}
|
|
940
|
+
function peelV3Wrappers(schema) {
|
|
941
|
+
let current = schema;
|
|
942
|
+
for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
|
|
943
|
+
if (isZodSchemaType(current, "ZodOptional") || isZodSchemaType(current, "ZodNullable") || isZodSchemaType(current, "ZodDefault")) {
|
|
944
|
+
const inner = current._def.innerType;
|
|
945
|
+
if (!inner) return current;
|
|
946
|
+
current = inner;
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
if (isZodSchemaType(current, "ZodEffects")) {
|
|
950
|
+
const inner = current._def.schema;
|
|
951
|
+
if (!inner) return current;
|
|
952
|
+
current = inner;
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
if (isZodSchemaType(current, "ZodPipeline")) {
|
|
956
|
+
const inner = current._def.in;
|
|
957
|
+
if (!inner) return current;
|
|
958
|
+
current = inner;
|
|
959
|
+
continue;
|
|
960
|
+
}
|
|
961
|
+
if (isZodSchemaType(current, "ZodReadonly")) {
|
|
962
|
+
const inner = current._def.innerType;
|
|
963
|
+
if (!inner) return current;
|
|
964
|
+
current = inner;
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
if (isZodSchemaType(current, "ZodBranded")) {
|
|
968
|
+
const inner = current._def.type;
|
|
969
|
+
if (!inner) return current;
|
|
970
|
+
current = inner;
|
|
971
|
+
continue;
|
|
972
|
+
}
|
|
973
|
+
break;
|
|
974
|
+
}
|
|
975
|
+
return current;
|
|
976
|
+
}
|
|
977
|
+
function walkV3ToLeafSchema(schema, segments) {
|
|
978
|
+
let current = schema;
|
|
979
|
+
let i = 0;
|
|
980
|
+
let safetyTicks = 0;
|
|
981
|
+
while (i < segments.length && current && safetyTicks < segments.length * MAX_UNWRAP_STEPS + MAX_UNWRAP_STEPS) {
|
|
982
|
+
safetyTicks++;
|
|
983
|
+
current = peelV3Wrappers(current);
|
|
984
|
+
const key = String(segments[i] ?? "");
|
|
985
|
+
if (isZodSchemaType(current, "ZodObject")) {
|
|
986
|
+
const shape = current._def.shape();
|
|
987
|
+
current = Object.hasOwn(shape, key) ? shape[key] : void 0;
|
|
988
|
+
i++;
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
if (isZodSchemaType(current, "ZodArray")) {
|
|
992
|
+
current = current._def.type;
|
|
993
|
+
i++;
|
|
994
|
+
continue;
|
|
995
|
+
}
|
|
996
|
+
if (isZodSchemaType(current, "ZodRecord")) {
|
|
997
|
+
current = current._def.valueType;
|
|
998
|
+
i++;
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
if (isZodSchemaType(current, "ZodTuple")) {
|
|
1002
|
+
const idx = Number(key);
|
|
1003
|
+
if (!Number.isInteger(idx) || idx < 0) return void 0;
|
|
1004
|
+
const items = current._def.items;
|
|
1005
|
+
const item = items[idx];
|
|
1006
|
+
if (!item) return void 0;
|
|
1007
|
+
current = item;
|
|
1008
|
+
i++;
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
if (isZodSchemaType(current, "ZodDiscriminatedUnion")) {
|
|
1012
|
+
const options = current._def.options;
|
|
1013
|
+
const matching = options.filter((o) => key in o.shape);
|
|
1014
|
+
const candidates = matching.length > 0 ? matching : options;
|
|
1015
|
+
const first = candidates[0];
|
|
1016
|
+
if (!first) return void 0;
|
|
1017
|
+
current = first;
|
|
1018
|
+
continue;
|
|
1019
|
+
}
|
|
1020
|
+
if (isZodSchemaType(current, "ZodUnion")) {
|
|
1021
|
+
const options = current._def.options;
|
|
1022
|
+
const first = options[0];
|
|
1023
|
+
if (!first) return void 0;
|
|
1024
|
+
current = first;
|
|
1025
|
+
continue;
|
|
1026
|
+
}
|
|
1027
|
+
return void 0;
|
|
1028
|
+
}
|
|
1029
|
+
return current;
|
|
1030
|
+
}
|
|
1031
|
+
function isLeafRequiredV3(schema, depth = 0) {
|
|
1032
|
+
if (depth > MAX_UNWRAP_STEPS) return true;
|
|
1033
|
+
if (isZodSchemaType(schema, "ZodOptional") || isZodSchemaType(schema, "ZodNullable") || isZodSchemaType(schema, "ZodDefault") || isZodSchemaType(schema, "ZodCatch") || isZodSchemaType(schema, "ZodUndefined") || isZodSchemaType(schema, "ZodNull")) {
|
|
1034
|
+
return false;
|
|
1035
|
+
}
|
|
1036
|
+
if (isZodSchemaType(schema, "ZodReadonly") || isZodSchemaType(schema, "ZodBranded")) {
|
|
1037
|
+
const inner = schema._def.innerType;
|
|
1038
|
+
const branded = schema._def.type;
|
|
1039
|
+
const next = inner ?? branded;
|
|
1040
|
+
return next === void 0 ? true : isLeafRequiredV3(next, depth + 1);
|
|
1041
|
+
}
|
|
1042
|
+
if (isZodSchemaType(schema, "ZodPipeline")) {
|
|
1043
|
+
const inner = schema._def.in;
|
|
1044
|
+
return inner === void 0 ? true : isLeafRequiredV3(inner, depth + 1);
|
|
1045
|
+
}
|
|
1046
|
+
if (isZodSchemaType(schema, "ZodEffects")) {
|
|
1047
|
+
const inner = schema._def.schema;
|
|
1048
|
+
return inner === void 0 ? true : isLeafRequiredV3(inner, depth + 1);
|
|
1049
|
+
}
|
|
1050
|
+
if (isZodSchemaType(schema, "ZodUnion") || isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
|
|
1051
|
+
const options = schema._def.options ?? [];
|
|
1052
|
+
if (options.length === 0) return true;
|
|
1053
|
+
return options.every((opt) => isLeafRequiredV3(opt, depth + 1));
|
|
1054
|
+
}
|
|
1055
|
+
if (isZodSchemaType(schema, "ZodIntersection")) {
|
|
1056
|
+
const def = schema._def;
|
|
1057
|
+
const leftReq = def.left === void 0 ? true : isLeafRequiredV3(def.left, depth + 1);
|
|
1058
|
+
const rightReq = def.right === void 0 ? true : isLeafRequiredV3(def.right, depth + 1);
|
|
1059
|
+
return leftReq || rightReq;
|
|
1060
|
+
}
|
|
1061
|
+
return true;
|
|
1062
|
+
}
|
|
1063
|
+
function unwrapToDiscriminatedUnion(schema) {
|
|
1064
|
+
let currentSchema = schema;
|
|
1065
|
+
for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
|
|
1066
|
+
if (isZodSchemaType(currentSchema, "ZodDiscriminatedUnion")) {
|
|
1067
|
+
return currentSchema;
|
|
1068
|
+
}
|
|
1069
|
+
if (isZodSchemaType(currentSchema, "ZodDefault") || isZodSchemaType(currentSchema, "ZodOptional") || isZodSchemaType(currentSchema, "ZodNullable")) {
|
|
1070
|
+
currentSchema = currentSchema._def.innerType;
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1073
|
+
if (isZodSchemaType(currentSchema, "ZodReadonly")) {
|
|
1074
|
+
const inner = currentSchema._def.innerType;
|
|
1075
|
+
if (!inner) return void 0;
|
|
1076
|
+
currentSchema = inner;
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
if (isZodSchemaType(currentSchema, "ZodBranded")) {
|
|
1080
|
+
const inner = currentSchema._def.type;
|
|
1081
|
+
if (!inner) return void 0;
|
|
1082
|
+
currentSchema = inner;
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1085
|
+
if (isZodSchemaType(currentSchema, "ZodPipeline")) {
|
|
1086
|
+
const inner = currentSchema._def.in;
|
|
1087
|
+
if (!inner) return void 0;
|
|
1088
|
+
currentSchema = inner;
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
return void 0;
|
|
1092
|
+
}
|
|
1093
|
+
return void 0;
|
|
1094
|
+
}
|
|
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 === "map") return /* @__PURE__ */ new Map();
|
|
1129
|
+
if (expected === "promise") return new Promise((res) => res(void 0));
|
|
1130
|
+
if (expected === "symbol") return Symbol();
|
|
1131
|
+
if (expected === "function") return () => void 0;
|
|
1132
|
+
if (expected === "undefined") return void 0;
|
|
1133
|
+
if (expected === "unknown") return void 0;
|
|
1134
|
+
if (expected === "nan") return Number("nan");
|
|
1135
|
+
return void 0;
|
|
1136
|
+
}
|
|
1137
|
+
function unwrapDefault(schema) {
|
|
1138
|
+
let current = schema;
|
|
1139
|
+
for (let i = 0; i < MAX_UNWRAP_STEPS; i++) {
|
|
1140
|
+
if (isZodSchemaType(current, "ZodDefault")) {
|
|
1141
|
+
const defaultValue = current._def.defaultValue();
|
|
1142
|
+
return [defaultValue, true];
|
|
1143
|
+
}
|
|
1144
|
+
if (isZodSchemaType(current, "ZodCatch")) {
|
|
1145
|
+
const catchValue = current._def.catchValue;
|
|
1146
|
+
if (typeof catchValue === "function") {
|
|
1147
|
+
return [catchValue({ error: null, input: void 0 }), true];
|
|
1148
|
+
}
|
|
1149
|
+
const inner = current._def.innerType;
|
|
1150
|
+
if (!inner) break;
|
|
1151
|
+
current = inner;
|
|
1152
|
+
continue;
|
|
1153
|
+
}
|
|
1154
|
+
if (isZodSchemaType(current, "ZodNullable") || isZodSchemaType(current, "ZodOptional")) {
|
|
1155
|
+
current = current._def.innerType;
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1158
|
+
if (isZodSchemaType(current, "ZodReadonly")) {
|
|
1159
|
+
const inner = current._def.innerType;
|
|
1160
|
+
if (!inner) break;
|
|
1161
|
+
current = inner;
|
|
1162
|
+
continue;
|
|
1163
|
+
}
|
|
1164
|
+
if (isZodSchemaType(current, "ZodBranded")) {
|
|
1165
|
+
const inner = current._def.type;
|
|
1166
|
+
if (!inner) break;
|
|
1167
|
+
current = inner;
|
|
1168
|
+
continue;
|
|
1169
|
+
}
|
|
1170
|
+
if (isZodSchemaType(current, "ZodPipeline")) {
|
|
1171
|
+
const inner = current._def.in;
|
|
1172
|
+
if (!inner) break;
|
|
1173
|
+
current = inner;
|
|
1174
|
+
continue;
|
|
1175
|
+
}
|
|
1176
|
+
if (isZodSchemaType(current, "ZodEffects")) {
|
|
1177
|
+
const effect = current._def.effect;
|
|
1178
|
+
if (effect !== null && typeof effect === "object" && "_def" in effect) {
|
|
1179
|
+
current = effect;
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
const inner = current.innerType?.();
|
|
1183
|
+
if (inner) {
|
|
1184
|
+
current = inner;
|
|
1185
|
+
continue;
|
|
1186
|
+
}
|
|
1187
|
+
break;
|
|
1188
|
+
}
|
|
1189
|
+
break;
|
|
1190
|
+
}
|
|
1191
|
+
return [null, false];
|
|
1192
|
+
}
|
|
1193
|
+
function getDefaultValuesFromZodSchema(formSchema, useDefaultSchemaValues, formKey) {
|
|
1194
|
+
function generateValue(schema) {
|
|
1195
|
+
if (useDefaultSchemaValues) {
|
|
1196
|
+
const [defaultValue, foundDefaultValue] = unwrapDefault(schema);
|
|
1197
|
+
if (foundDefaultValue) {
|
|
1198
|
+
return defaultValue;
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
if (isZodSchemaType(schema, "ZodNullable")) {
|
|
1202
|
+
return null;
|
|
1203
|
+
}
|
|
1204
|
+
if (isZodSchemaType(schema, "ZodObject")) {
|
|
1205
|
+
const shape = schema.shape;
|
|
1206
|
+
return Object.keys(shape).reduce((acc, key) => {
|
|
1207
|
+
acc[key] = generateValue(shape[key]);
|
|
1208
|
+
return acc;
|
|
1209
|
+
}, {});
|
|
1210
|
+
}
|
|
1211
|
+
if (isZodSchemaType(schema, "ZodArray")) {
|
|
1212
|
+
return [];
|
|
1213
|
+
}
|
|
1214
|
+
if (isZodSchemaType(schema, "ZodString")) {
|
|
1215
|
+
return "";
|
|
1216
|
+
}
|
|
1217
|
+
if (isZodSchemaType(schema, "ZodNumber")) {
|
|
1218
|
+
return 0;
|
|
1219
|
+
}
|
|
1220
|
+
if (isZodSchemaType(schema, "ZodBigInt")) {
|
|
1221
|
+
return 0n;
|
|
1222
|
+
}
|
|
1223
|
+
if (isZodSchemaType(schema, "ZodDate")) {
|
|
1224
|
+
return /* @__PURE__ */ new Date(0);
|
|
1225
|
+
}
|
|
1226
|
+
if (isZodSchemaType(schema, "ZodBoolean")) {
|
|
1227
|
+
return false;
|
|
1228
|
+
}
|
|
1229
|
+
if (isZodSchemaType(schema, "ZodEnum")) {
|
|
1230
|
+
return schema.options[0];
|
|
1231
|
+
}
|
|
1232
|
+
if (isZodSchemaType(schema, "ZodNull")) {
|
|
1233
|
+
return null;
|
|
1234
|
+
}
|
|
1235
|
+
if (isZodSchemaType(schema, "ZodUndefined")) {
|
|
1236
|
+
return void 0;
|
|
1237
|
+
}
|
|
1238
|
+
if (isZodSchemaType(schema, "ZodLiteral")) {
|
|
1239
|
+
return schema._def.value;
|
|
1240
|
+
}
|
|
1241
|
+
if (isZodSchemaType(schema, "ZodOptional")) {
|
|
1242
|
+
return void 0;
|
|
1243
|
+
}
|
|
1244
|
+
if (isZodSchemaType(schema, "ZodUnion")) {
|
|
1245
|
+
return generateValue(schema._def.options[0]);
|
|
1246
|
+
}
|
|
1247
|
+
if (isZodSchemaType(schema, "ZodTuple")) {
|
|
1248
|
+
return schema._def.items.map((item) => generateValue(item));
|
|
1249
|
+
}
|
|
1250
|
+
if (isZodSchemaType(schema, "ZodRecord")) {
|
|
1251
|
+
return {};
|
|
1252
|
+
}
|
|
1253
|
+
if (isZodSchemaType(schema, "ZodDefault")) {
|
|
1254
|
+
return generateValue(schema._def.innerType);
|
|
1255
|
+
}
|
|
1256
|
+
if (isZodSchemaType(schema, "ZodEffects")) {
|
|
1257
|
+
return generateValue(schema.innerType());
|
|
1258
|
+
}
|
|
1259
|
+
if (isZodSchemaType(schema, "ZodDiscriminatedUnion")) {
|
|
1260
|
+
const discriminantSchema = getSchemaByDiscriminatorKey(schema);
|
|
1261
|
+
return generateValue(discriminantSchema);
|
|
1262
|
+
}
|
|
1263
|
+
if (isZodSchemaType(schema, "ZodCatch")) {
|
|
1264
|
+
const catchValue = schema._def.catchValue;
|
|
1265
|
+
if (typeof catchValue === "function") {
|
|
1266
|
+
return catchValue({ error: null, input: void 0 });
|
|
1267
|
+
}
|
|
1268
|
+
const inner = schema._def.innerType;
|
|
1269
|
+
if (inner) return generateValue(inner);
|
|
1270
|
+
}
|
|
1271
|
+
if (isZodSchemaType(schema, "ZodReadonly")) {
|
|
1272
|
+
const inner = schema._def.innerType;
|
|
1273
|
+
if (inner) return generateValue(inner);
|
|
1274
|
+
}
|
|
1275
|
+
if (isZodSchemaType(schema, "ZodBranded")) {
|
|
1276
|
+
const inner = schema._def.type;
|
|
1277
|
+
if (inner) return generateValue(inner);
|
|
1278
|
+
}
|
|
1279
|
+
if (isZodSchemaType(schema, "ZodPipeline")) {
|
|
1280
|
+
const inner = schema._def.in;
|
|
1281
|
+
if (inner) return generateValue(inner);
|
|
1282
|
+
}
|
|
1283
|
+
if (isZodSchemaType(schema, "ZodLazy")) {
|
|
1284
|
+
const inner = schema._def.getter?.();
|
|
1285
|
+
if (inner) return generateValue(inner);
|
|
1286
|
+
}
|
|
1287
|
+
if (isZodSchemaType(schema, "ZodIntersection")) {
|
|
1288
|
+
const def = schema._def;
|
|
1289
|
+
const left = def.left ? generateValue(def.left) : void 0;
|
|
1290
|
+
const right = def.right ? generateValue(def.right) : void 0;
|
|
1291
|
+
return lodashEs.merge({}, left, right);
|
|
1292
|
+
}
|
|
1293
|
+
if (isZodSchemaType(schema, "ZodNativeEnum")) {
|
|
1294
|
+
const values = schema._def.values;
|
|
1295
|
+
if (values) {
|
|
1296
|
+
const lookup = values;
|
|
1297
|
+
const validKeys = Object.keys(lookup).filter(
|
|
1298
|
+
(k) => typeof lookup[lookup[k]] !== "number"
|
|
1299
|
+
);
|
|
1300
|
+
if (validKeys.length > 0) {
|
|
1301
|
+
const first = validKeys[0];
|
|
1302
|
+
if (first !== void 0) return lookup[first];
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
if (isZodSchemaType(schema, "ZodSet")) {
|
|
1307
|
+
return /* @__PURE__ */ new Set();
|
|
1308
|
+
}
|
|
1309
|
+
console.warn(
|
|
1310
|
+
`[attaform] zod-v3 adapter: unsupported schema kind '${schema.constructor.name}' on form '${formKey}'. Defaulting the field to null. Use a supported zod kind (object/array/record/string/number/etc.) at this path.`
|
|
1311
|
+
);
|
|
1312
|
+
return null;
|
|
1313
|
+
}
|
|
1314
|
+
return generateValue(formSchema);
|
|
1315
|
+
}
|
|
1316
|
+
function getSchemaByDiscriminatorKey(unionSchema, key) {
|
|
1317
|
+
if (!isZodSchemaType(unionSchema, "ZodDiscriminatedUnion")) {
|
|
1318
|
+
throw new TypeError("Provided schema is not a discriminated union.");
|
|
1319
|
+
}
|
|
1320
|
+
{
|
|
1321
|
+
const options = unionSchema._def.options;
|
|
1322
|
+
if (!options.length) {
|
|
1323
|
+
throw new TypeError("Provided ZodDiscriminatedUnion does not have any options");
|
|
1324
|
+
}
|
|
1325
|
+
return options[0];
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
function hasChecks(schema) {
|
|
1329
|
+
if (!("_def" in schema)) return false;
|
|
1330
|
+
const schemaDef = schema._def;
|
|
1331
|
+
if (!("checks" in schemaDef)) return false;
|
|
1332
|
+
const checks = schemaDef["checks"];
|
|
1333
|
+
if (!Array.isArray(checks)) return false;
|
|
1334
|
+
return checks.length > 0;
|
|
1335
|
+
}
|
|
1336
|
+
function stripRefinements(schema) {
|
|
1337
|
+
function _stripRefinements(_schema, depth) {
|
|
1338
|
+
if (depth >= MAX_UNWRAP_STEPS) return _schema;
|
|
1339
|
+
if (isZodSchemaType(_schema, "ZodString") && _schema._def.checks.length > 0) {
|
|
1340
|
+
return zod.z.string();
|
|
1341
|
+
}
|
|
1342
|
+
if (isZodSchemaType(_schema, "ZodNumber") && _schema._def.checks.length > 0) {
|
|
1343
|
+
return zod.z.number();
|
|
1344
|
+
}
|
|
1345
|
+
if (isZodSchemaType(_schema, "ZodArray")) {
|
|
1346
|
+
return zod.z.array(_stripRefinements(_schema._def.type, depth + 1));
|
|
1347
|
+
}
|
|
1348
|
+
if (isZodSchemaType(_schema, "ZodObject")) {
|
|
1349
|
+
const shape = _schema.shape;
|
|
1350
|
+
const strippedShape = Object.fromEntries(
|
|
1351
|
+
Object.entries(shape).map(([key, value]) => [
|
|
1352
|
+
key,
|
|
1353
|
+
_stripRefinements(value, depth + 1)
|
|
1354
|
+
])
|
|
1355
|
+
);
|
|
1356
|
+
return zod.z.object(strippedShape);
|
|
1357
|
+
}
|
|
1358
|
+
if (isZodSchemaType(_schema, "ZodEffects")) {
|
|
1359
|
+
return _stripRefinements(_schema.innerType(), depth + 1);
|
|
1360
|
+
}
|
|
1361
|
+
if (isZodSchemaType(_schema, "ZodOptional")) {
|
|
1362
|
+
return zod.z.optional(_stripRefinements(_schema.unwrap(), depth + 1));
|
|
1363
|
+
}
|
|
1364
|
+
if (isZodSchemaType(_schema, "ZodNullable")) {
|
|
1365
|
+
return zod.z.nullable(_stripRefinements(_schema.unwrap(), depth + 1));
|
|
1366
|
+
}
|
|
1367
|
+
if (isZodSchemaType(_schema, "ZodReadonly")) {
|
|
1368
|
+
const inner = _schema._def.innerType;
|
|
1369
|
+
if (!inner) return _schema;
|
|
1370
|
+
return _stripRefinements(inner, depth + 1);
|
|
1371
|
+
}
|
|
1372
|
+
if (isZodSchemaType(_schema, "ZodBranded")) {
|
|
1373
|
+
const inner = _schema._def.type;
|
|
1374
|
+
if (!inner) return _schema;
|
|
1375
|
+
return _stripRefinements(inner, depth + 1);
|
|
1376
|
+
}
|
|
1377
|
+
if (isZodSchemaType(_schema, "ZodPipeline")) {
|
|
1378
|
+
const inner = _schema._def.in;
|
|
1379
|
+
if (!inner) return _schema;
|
|
1380
|
+
return _stripRefinements(inner, depth + 1);
|
|
1381
|
+
}
|
|
1382
|
+
if (isZodSchemaType(_schema, "ZodSet")) {
|
|
1383
|
+
const valueType = _schema._def.valueType;
|
|
1384
|
+
if (!valueType) return _schema;
|
|
1385
|
+
return zod.z.set(_stripRefinements(valueType, depth + 1));
|
|
1386
|
+
}
|
|
1387
|
+
if (isZodSchemaType(_schema, "ZodTuple")) {
|
|
1388
|
+
const items = _schema._def.items;
|
|
1389
|
+
if (!items) return _schema;
|
|
1390
|
+
const stripped = items.map((it) => _stripRefinements(it, depth + 1));
|
|
1391
|
+
return zod.z.tuple(stripped);
|
|
1392
|
+
}
|
|
1393
|
+
if (isZodSchemaType(_schema, "ZodRecord")) {
|
|
1394
|
+
const def = _schema._def;
|
|
1395
|
+
if (!def.valueType) return _schema;
|
|
1396
|
+
const value = _stripRefinements(def.valueType, depth + 1);
|
|
1397
|
+
if (def.keyType) {
|
|
1398
|
+
return zod.z.record(def.keyType, value);
|
|
1399
|
+
}
|
|
1400
|
+
return zod.z.record(value);
|
|
1401
|
+
}
|
|
1402
|
+
if (isZodSchemaType(_schema, "ZodUnion")) {
|
|
1403
|
+
const options = _schema._def.options;
|
|
1404
|
+
if (!options) return _schema;
|
|
1405
|
+
const stripped = options.map((o) => _stripRefinements(o, depth + 1));
|
|
1406
|
+
return zod.z.union(stripped);
|
|
1407
|
+
}
|
|
1408
|
+
if (isZodSchemaType(_schema, "ZodDiscriminatedUnion")) {
|
|
1409
|
+
const def = _schema._def;
|
|
1410
|
+
if (def.discriminator === void 0 || !def.options) return _schema;
|
|
1411
|
+
const stripped = def.options.map(
|
|
1412
|
+
(o) => _stripRefinements(o, depth + 1)
|
|
1413
|
+
);
|
|
1414
|
+
return zod.z.discriminatedUnion(
|
|
1415
|
+
def.discriminator,
|
|
1416
|
+
stripped
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
if (isZodSchemaType(_schema, "ZodIntersection")) {
|
|
1420
|
+
const def = _schema._def;
|
|
1421
|
+
if (!def.left || !def.right) return _schema;
|
|
1422
|
+
return zod.z.intersection(
|
|
1423
|
+
_stripRefinements(def.left, depth + 1),
|
|
1424
|
+
_stripRefinements(def.right, depth + 1)
|
|
1425
|
+
);
|
|
1426
|
+
}
|
|
1427
|
+
if (isZodSchemaType(_schema, "ZodLazy")) {
|
|
1428
|
+
const getter = _schema._def.getter;
|
|
1429
|
+
if (!getter) return _schema;
|
|
1430
|
+
const stripped = _stripRefinements(getter(), depth + 1);
|
|
1431
|
+
return zod.z.lazy(() => stripped);
|
|
1432
|
+
}
|
|
1433
|
+
return _schema;
|
|
1434
|
+
}
|
|
1435
|
+
return _stripRefinements(schema, 0);
|
|
1436
|
+
}
|
|
1437
|
+
function stripRootSchema(schema, stripConfig) {
|
|
1438
|
+
function recursion(_schema, _stripped = false) {
|
|
1439
|
+
if (getStripInstruction(stripConfig.stripNullable, _schema) && isZodSchemaType(_schema, "ZodNullable")) {
|
|
1440
|
+
return recursion(_schema.unwrap(), true);
|
|
1441
|
+
}
|
|
1442
|
+
if (getStripInstruction(stripConfig.stripOptional, _schema) && isZodSchemaType(_schema, "ZodOptional")) {
|
|
1443
|
+
return recursion(_schema.unwrap(), true);
|
|
1444
|
+
}
|
|
1445
|
+
if (getStripInstruction(stripConfig.stripZodEffects, _schema) && isZodSchemaType(_schema, "ZodEffects")) {
|
|
1446
|
+
return recursion(_schema.innerType(), true);
|
|
1447
|
+
}
|
|
1448
|
+
if (getStripInstruction(stripConfig.stripDefaultValues, _schema) && isZodSchemaType(_schema, "ZodDefault")) {
|
|
1449
|
+
return recursion(_schema._def.innerType, true);
|
|
1450
|
+
}
|
|
1451
|
+
if (getStripInstruction(stripConfig.stripZodRefinements, _schema) && hasChecks(_schema)) {
|
|
1452
|
+
return recursion(stripRefinements(_schema));
|
|
1453
|
+
}
|
|
1454
|
+
return [_schema, _stripped];
|
|
1455
|
+
}
|
|
1456
|
+
return recursion(schema, false);
|
|
1457
|
+
}
|
|
1458
|
+
const getStripInstruction = (stripValueOrCallback, schema) => {
|
|
1459
|
+
if (stripValueOrCallback === void 0 || stripValueOrCallback === false) return false;
|
|
1460
|
+
return lodashEs.isFunction(stripValueOrCallback) ? stripValueOrCallback(schema) : stripValueOrCallback;
|
|
1461
|
+
};
|
|
1462
|
+
function getSlimSchema(config) {
|
|
1463
|
+
function _getSlimSchema(_schema) {
|
|
1464
|
+
if (isZodSchemaType(_schema, "ZodObject")) {
|
|
1465
|
+
const newShape = {};
|
|
1466
|
+
for (const key in _schema.shape) {
|
|
1467
|
+
const value = _schema.shape[key];
|
|
1468
|
+
newShape[key] = _getSlimSchema(value);
|
|
1469
|
+
}
|
|
1470
|
+
return zod.z.object(newShape);
|
|
1471
|
+
}
|
|
1472
|
+
if (isZodSchemaType(_schema, "ZodArray")) {
|
|
1473
|
+
return zod.z.array(_getSlimSchema(_schema.element));
|
|
1474
|
+
}
|
|
1475
|
+
if (isZodSchemaType(_schema, "ZodRecord")) {
|
|
1476
|
+
const key = _getSlimSchema(_schema._def.keyType);
|
|
1477
|
+
const value = _getSlimSchema(_schema._def.valueType);
|
|
1478
|
+
return zod.z.record(key, value);
|
|
1479
|
+
}
|
|
1480
|
+
if (isZodSchemaType(_schema, "ZodDiscriminatedUnion")) {
|
|
1481
|
+
const slimmedSchemas = [];
|
|
1482
|
+
for (const option of _schema._def.options) {
|
|
1483
|
+
const slimmedSchema = _getSlimSchema(option);
|
|
1484
|
+
const deepCloneSlimmedSchema = lodashEs.cloneDeep(slimmedSchema);
|
|
1485
|
+
slimmedSchemas.push(deepCloneSlimmedSchema);
|
|
1486
|
+
}
|
|
1487
|
+
return zod.z.discriminatedUnion(
|
|
1488
|
+
_schema._def.discriminator,
|
|
1489
|
+
slimmedSchemas
|
|
1490
|
+
);
|
|
1491
|
+
}
|
|
1492
|
+
if (getStripInstruction(config.stripConfig.stripZodEffects, _schema) && isZodSchemaType(_schema, "ZodEffects")) {
|
|
1493
|
+
return _getSlimSchema(_schema.innerType());
|
|
1494
|
+
}
|
|
1495
|
+
if (getStripInstruction(config.stripConfig.stripNullable, _schema) && isZodSchemaType(_schema, "ZodNullable")) {
|
|
1496
|
+
return _getSlimSchema(_schema._def.innerType);
|
|
1497
|
+
}
|
|
1498
|
+
if (getStripInstruction(config.stripConfig.stripOptional, _schema) && isZodSchemaType(_schema, "ZodOptional")) {
|
|
1499
|
+
return _getSlimSchema(_schema._def.innerType);
|
|
1500
|
+
}
|
|
1501
|
+
if (getStripInstruction(config.stripConfig.stripZodRefinements, _schema) && hasChecks(_schema)) {
|
|
1502
|
+
return stripRefinements(_schema);
|
|
1503
|
+
}
|
|
1504
|
+
if (getStripInstruction(config.stripConfig.stripDefaultValues, _schema) && isZodSchemaType(_schema, "ZodDefault")) {
|
|
1505
|
+
return _getSlimSchema(_schema._def.innerType);
|
|
1506
|
+
}
|
|
1507
|
+
const unionSchema = unwrapToDiscriminatedUnion(_schema);
|
|
1508
|
+
if (unionSchema && getStripInstruction(config.stripConfig.stripDefaultValues, unionSchema)) {
|
|
1509
|
+
return _getSlimSchema(unionSchema);
|
|
1510
|
+
}
|
|
1511
|
+
return _schema;
|
|
1512
|
+
}
|
|
1513
|
+
const processedRootSchema = stripRootSchema(config.schema, config.stripConfig)[0];
|
|
1514
|
+
return _getSlimSchema(processedRootSchema);
|
|
1515
|
+
}
|
|
1516
|
+
function resolveFieldMetaAtPathV3(rootSchema, path) {
|
|
1517
|
+
const lastSegment = path.length === 0 ? "" : path[path.length - 1];
|
|
1518
|
+
const target = path.length === 0 ? rootSchema : walkV3ToLeafSchema(rootSchema, path);
|
|
1519
|
+
if (target === void 0) {
|
|
1520
|
+
return {
|
|
1521
|
+
label: useFormContext.humanize(lastSegment),
|
|
1522
|
+
description: void 0,
|
|
1523
|
+
placeholder: void 0,
|
|
1524
|
+
meta: Object.freeze({})
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
const peeled = peelV3Wrappers(target);
|
|
1528
|
+
const payload = getFieldMeta(target) ?? (peeled !== target ? getFieldMeta(peeled) : void 0);
|
|
1529
|
+
const targetDescription = typeof target.description === "string" ? target.description : void 0;
|
|
1530
|
+
const peeledDescription = peeled !== target && typeof peeled.description === "string" ? peeled.description : void 0;
|
|
1531
|
+
const schemaDescription = targetDescription ?? peeledDescription;
|
|
1532
|
+
return {
|
|
1533
|
+
label: payload?.label ?? useFormContext.humanize(lastSegment),
|
|
1534
|
+
description: payload?.description ?? schemaDescription ?? void 0,
|
|
1535
|
+
placeholder: payload?.placeholder ?? void 0,
|
|
1536
|
+
meta: Object.freeze({ ...payload ?? {} })
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
function useForm(configuration) {
|
|
1541
|
+
if (configuration === void 0 || configuration === null || configuration.schema === void 0) {
|
|
1542
|
+
throw new plugin.InvalidUseFormConfigError();
|
|
1543
|
+
}
|
|
1544
|
+
function isZodType(value) {
|
|
1545
|
+
return typeof value === "object" && value !== null && "_def" in value;
|
|
1546
|
+
}
|
|
1547
|
+
const { schema } = configuration;
|
|
1548
|
+
const abstractSchema = isZodType(schema) ? zodAdapter(schema) : schema;
|
|
1549
|
+
return useFormContext.useAbstractForm({
|
|
1550
|
+
...configuration,
|
|
1551
|
+
schema: abstractSchema,
|
|
1552
|
+
defaultValues: configuration.defaultValues
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
exports.fieldMeta = fieldMeta;
|
|
1557
|
+
exports.isZodSchemaType = isZodSchemaType;
|
|
1558
|
+
exports.useForm = useForm;
|
|
1559
|
+
exports.withMeta = withMeta;
|
|
1560
|
+
exports.zodAdapter = zodAdapter;
|
|
1561
|
+
//# sourceMappingURL=attaform.Bp1c-uGF.cjs.map
|