attaform 0.30.1 → 0.31.1
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 -5
- package/dist/abstract.mjs +4 -4
- package/dist/dev/abstract.mjs +4 -4
- package/dist/dev/chunks/devtools.mjs +3 -3
- package/dist/dev/directive.mjs +1 -1
- package/dist/dev/history.mjs +15 -2
- package/dist/dev/index.mjs +5 -5
- package/dist/dev/runtime/plugins/attaform.mjs +1 -1
- package/dist/dev/shared/{attaform-dev.zlvDr0WB.mjs → attaform-dev.04aupFBW.mjs} +3 -2
- package/dist/dev/shared/{attaform-dev.DxHdkkPG.mjs → attaform-dev.3uTCYwy8.mjs} +770 -254
- package/dist/dev/shared/{attaform-dev.BJK1kqHY.mjs → attaform-dev.BpVGFSFa.mjs} +88 -115
- package/dist/dev/shared/{attaform-dev.Chm4D6SJ.mjs → attaform-dev.Bu6wgrA5.mjs} +3 -3
- package/dist/dev/shared/{attaform-dev.BMQ3GcgD.mjs → attaform-dev.Cbx0AiQF.mjs} +476 -337
- package/dist/dev/shared/attaform-dev.CwYTWyPX.mjs +120 -0
- package/dist/dev/shared/{attaform-dev.DuEE4GU1.mjs → attaform-dev.D7lKyM_7.mjs} +4 -4
- package/dist/dev/shared/{attaform-dev.CT7MDjPy.mjs → attaform-dev.OceE0X3v.mjs} +154 -229
- package/dist/{shared/attaform.DRsANMok.mjs → dev/shared/attaform-dev.PTGM9KE1.mjs} +16 -15
- package/dist/{shared/attaform.8mfKZCwH.mjs → dev/shared/attaform-dev.n6n00owJ.mjs} +49 -128
- package/dist/dev/zod-v3.mjs +6 -6
- package/dist/dev/zod-v4.mjs +6 -6
- package/dist/dev/zod.mjs +5 -5
- package/dist/directive.d.mts +2 -2
- package/dist/directive.mjs +1 -1
- package/dist/history.d.mts +1 -1
- package/dist/history.mjs +15 -2
- package/dist/index.d.mts +16 -55
- package/dist/index.mjs +5 -5
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +3 -3
- package/dist/runtime/plugins/attaform.mjs +1 -1
- package/dist/shared/{attaform.CO918TdU.mjs → attaform.B5b-HmhH.mjs} +88 -115
- package/dist/shared/{attaform.2FslhB9R.d.mts → attaform.B9PYKlhB.d.mts} +43 -19
- package/dist/shared/{attaform.D_f1WgYf.mjs → attaform.BPMOl562.mjs} +458 -319
- package/dist/{dev/shared/attaform-dev.CZz4GYZ6.mjs → shared/attaform.BPSqtU7a.mjs} +44 -156
- package/dist/shared/{attaform.CdZIEf7_.mjs → attaform.BhtAZysa.mjs} +3 -2
- package/dist/shared/{attaform.BcQwgWaq.d.mts → attaform.CYlF4P6X.d.mts} +58 -17
- package/dist/shared/{attaform.WiGdIqgx.mjs → attaform.CdA9bfRv.mjs} +3 -3
- package/dist/shared/{attaform.BIWicztt.mjs → attaform.DAf4ehIe.mjs} +765 -251
- package/dist/shared/{attaform.ZYn2ahzJ.mjs → attaform.DBCbxlyk.mjs} +59 -1
- package/dist/shared/{attaform.L0kUn3vL.d.mts → attaform.DZOynI6c.d.mts} +1 -1
- package/dist/shared/{attaform.B2iebkPA.mjs → attaform.KEfNRDot.mjs} +4 -4
- package/dist/shared/attaform._1Zp3mDG.mjs +96 -0
- package/dist/shared/{attaform.Br8EBn5B.d.mts → attaform.i13OEHJF.d.mts} +195 -38
- package/dist/{dev/shared/attaform-dev.BUIFcTYf.mjs → shared/attaform.j9xI_ObC.mjs} +16 -15
- package/dist/shared/{attaform.D_pt1gOj.mjs → attaform.u6jfHoed.mjs} +154 -229
- package/dist/transforms.mjs +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/zod-v3.d.mts +4 -4
- package/dist/zod-v3.mjs +6 -6
- package/dist/zod-v4.d.mts +22 -16
- package/dist/zod-v4.mjs +6 -6
- package/dist/zod.d.mts +4 -4
- package/dist/zod.mjs +5 -5
- package/package.json +2 -1
- package/skills/attaform/SKILL.md +2 -1
- package/skills/attaform/references/custom-components.md +4 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { j as humanize, c as useAbstractForm } from './attaform.
|
|
2
|
-
import { A as AttaformError, e as canonicalizePath, a as InvalidUseFormConfigError } from './attaform.
|
|
3
|
-
import { s as slimPrimitivesWalk, d as deriveDefaultWalk, m as mergeDeep, f as fixStructuralDefaults, w as walkPathSegments, c as createAbstractSchema, a as createSharedSchemaStore, b as buildFieldMetaPathMap, e as getFieldMetaListForSchema, g as getFieldMetaForSchema } from './attaform.
|
|
4
|
-
import {
|
|
1
|
+
import { j as humanize, c as useAbstractForm } from './attaform.DAf4ehIe.mjs';
|
|
2
|
+
import { A as AttaformError, e as canonicalizePath, a as InvalidUseFormConfigError } from './attaform.BhtAZysa.mjs';
|
|
3
|
+
import { s as slimPrimitivesWalk, d as deriveDefaultWalk, m as mergeDeep, f as fixStructuralDefaults, w as walkPathSegments, c as createAbstractSchema, a as createSharedSchemaStore, b as buildFieldMetaPathMap, e as getFieldMetaListForSchema, g as getFieldMetaForSchema } from './attaform.j9xI_ObC.mjs';
|
|
4
|
+
import { d as callConsumerFn } from './attaform._1Zp3mDG.mjs';
|
|
5
5
|
|
|
6
6
|
function readDef(schema) {
|
|
7
7
|
if (schema === null || typeof schema !== "object") return void 0;
|
|
@@ -119,9 +119,7 @@ function isCoercePrimitive(schema) {
|
|
|
119
119
|
return readDef(schema)?.coerce === true;
|
|
120
120
|
}
|
|
121
121
|
function isPreprocessNode(schema) {
|
|
122
|
-
|
|
123
|
-
const pipeIn = unwrapPipeIn(schema);
|
|
124
|
-
return pipeIn !== void 0 && kindOf(pipeIn) === "transform";
|
|
122
|
+
return kindOf(schema) === "pipe" && kindOf(readDef(schema)?.in) === "transform";
|
|
125
123
|
}
|
|
126
124
|
function unwrapPipeOut(schema) {
|
|
127
125
|
const def = readDef(schema);
|
|
@@ -181,6 +179,9 @@ function getDiscriminatedOptions(schema) {
|
|
|
181
179
|
return Array.isArray(options) ? options : [];
|
|
182
180
|
}
|
|
183
181
|
function assertZodVersion(schema) {
|
|
182
|
+
assertZodV4Node(schema);
|
|
183
|
+
}
|
|
184
|
+
function assertZodV4Node(schema) {
|
|
184
185
|
const def = readDef(schema);
|
|
185
186
|
if (def?.type === void 0) {
|
|
186
187
|
throw new Error(
|
|
@@ -200,60 +201,6 @@ const DESCEND_SINGLE = [
|
|
|
200
201
|
];
|
|
201
202
|
const DESCEND_RECORD = ["shape", "entries"];
|
|
202
203
|
const DESCEND_LIST = ["options", "items"];
|
|
203
|
-
function walkSchemaTree(schema, visit, seen) {
|
|
204
|
-
const visited = seen ?? /* @__PURE__ */ new WeakSet();
|
|
205
|
-
const candidate = schema;
|
|
206
|
-
if (typeof candidate !== "object" || candidate === null) return false;
|
|
207
|
-
if (visited.has(candidate)) return false;
|
|
208
|
-
visited.add(candidate);
|
|
209
|
-
if (visit(schema)) return true;
|
|
210
|
-
const def = readDef(schema);
|
|
211
|
-
if (def === void 0) return false;
|
|
212
|
-
const slots = def;
|
|
213
|
-
for (const key of DESCEND_SINGLE) {
|
|
214
|
-
const child = slots[key];
|
|
215
|
-
if (child !== void 0 && walkSchemaTree(child, visit, visited)) return true;
|
|
216
|
-
}
|
|
217
|
-
for (const key of DESCEND_RECORD) {
|
|
218
|
-
const record = slots[key];
|
|
219
|
-
if (record !== void 0) {
|
|
220
|
-
for (const sub of Object.values(record)) {
|
|
221
|
-
if (walkSchemaTree(sub, visit, visited)) return true;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
for (const key of DESCEND_LIST) {
|
|
226
|
-
const list = slots[key];
|
|
227
|
-
if (list !== void 0) {
|
|
228
|
-
for (const sub of list) {
|
|
229
|
-
if (walkSchemaTree(sub, visit, visited)) return true;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (typeof def.getter === "function") {
|
|
234
|
-
try {
|
|
235
|
-
const inner = def.getter();
|
|
236
|
-
if (walkSchemaTree(inner, visit, visited)) return true;
|
|
237
|
-
} catch {
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
function containsDiscriminatedUnion(schema, seen) {
|
|
243
|
-
return walkSchemaTree(schema, (node) => kindOf(node) === "discriminated-union", seen);
|
|
244
|
-
}
|
|
245
|
-
function containsAsyncRefine(schema, seen) {
|
|
246
|
-
return walkSchemaTree(
|
|
247
|
-
schema,
|
|
248
|
-
(node) => {
|
|
249
|
-
for (const check of getChecks(node)) {
|
|
250
|
-
if (isAsyncCheck(check)) return true;
|
|
251
|
-
}
|
|
252
|
-
return false;
|
|
253
|
-
},
|
|
254
|
-
seen
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
204
|
const CONTAINER_SLOTS = [
|
|
258
205
|
"shape",
|
|
259
206
|
"entries",
|
|
@@ -265,31 +212,60 @@ const CONTAINER_SLOTS = [
|
|
|
265
212
|
"left",
|
|
266
213
|
"right"
|
|
267
214
|
];
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
215
|
+
const capabilityMemo = /* @__PURE__ */ new WeakMap();
|
|
216
|
+
function capabilitiesOf(schema) {
|
|
217
|
+
let capabilities = capabilityMemo.get(schema);
|
|
218
|
+
if (capabilities === void 0) {
|
|
219
|
+
capabilities = scanCapabilities(schema);
|
|
220
|
+
const key = schema;
|
|
221
|
+
if (typeof key === "object" && key !== null) capabilityMemo.set(key, capabilities);
|
|
222
|
+
}
|
|
223
|
+
return capabilities;
|
|
224
|
+
}
|
|
225
|
+
function scanCapabilities(schema) {
|
|
226
|
+
const capabilities = {
|
|
227
|
+
asyncRefine: false,
|
|
228
|
+
asyncTransform: false,
|
|
229
|
+
discriminatedUnion: false,
|
|
230
|
+
containerOrRootRefine: false,
|
|
231
|
+
preprocessOrCoerce: false
|
|
232
|
+
};
|
|
233
|
+
walkCapabilities(schema, capabilities, /* @__PURE__ */ new WeakSet());
|
|
234
|
+
return capabilities;
|
|
235
|
+
}
|
|
236
|
+
function walkCapabilities(node, capabilities, visited) {
|
|
237
|
+
if (typeof node !== "object" || node === null || visited.has(node)) return;
|
|
238
|
+
visited.add(node);
|
|
239
|
+
const def = readDef(node);
|
|
240
|
+
if (def === void 0) return;
|
|
241
|
+
const checks = getChecks(node);
|
|
242
|
+
if (checks.some(isAsyncCheck)) capabilities.asyncRefine = true;
|
|
243
|
+
if (checks.some(isVerdictCheck) && CONTAINER_SLOTS.some((key) => def[key] !== void 0)) {
|
|
244
|
+
capabilities.containerOrRootRefine = true;
|
|
245
|
+
}
|
|
246
|
+
if (typeof def.transform === "function" && def.transform.constructor.name === "AsyncFunction") {
|
|
247
|
+
capabilities.asyncTransform = true;
|
|
248
|
+
}
|
|
249
|
+
if (kindOf(node) === "discriminated-union") capabilities.discriminatedUnion = true;
|
|
250
|
+
if (isCoercePrimitive(node) || isPreprocessNode(node)) capabilities.preprocessOrCoerce = true;
|
|
251
|
+
for (const key of DESCEND_SINGLE) walkCapabilities(def[key], capabilities, visited);
|
|
252
|
+
for (const key of DESCEND_RECORD) {
|
|
253
|
+
for (const sub of Object.values(def[key] ?? {})) walkCapabilities(sub, capabilities, visited);
|
|
254
|
+
}
|
|
255
|
+
for (const key of DESCEND_LIST) {
|
|
256
|
+
for (const sub of def[key] ?? []) walkCapabilities(sub, capabilities, visited);
|
|
257
|
+
}
|
|
258
|
+
if (typeof def.getter === "function") {
|
|
259
|
+
try {
|
|
260
|
+
walkCapabilities(def.getter(), capabilities, visited);
|
|
261
|
+
} catch {
|
|
262
|
+
}
|
|
263
|
+
}
|
|
280
264
|
}
|
|
281
|
-
function
|
|
282
|
-
return
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const def = readDef(node);
|
|
286
|
-
if (def === void 0) return false;
|
|
287
|
-
const fn = def.transform;
|
|
288
|
-
if (typeof fn !== "function") return false;
|
|
289
|
-
return fn.constructor.name === "AsyncFunction";
|
|
290
|
-
},
|
|
291
|
-
seen
|
|
292
|
-
);
|
|
265
|
+
function isVerdictCheck(check) {
|
|
266
|
+
if (typeof check !== "object" || check === null) return true;
|
|
267
|
+
const kind = check._zod?.def?.check;
|
|
268
|
+
return kind !== "describe" && kind !== "meta";
|
|
293
269
|
}
|
|
294
270
|
function isAsyncCheck(check) {
|
|
295
271
|
if (typeof check !== "object" || check === null) return false;
|
|
@@ -347,17 +323,14 @@ function zodIssuesToValidationErrors(issues) {
|
|
|
347
323
|
|
|
348
324
|
const V4_INTROSPECTOR = {
|
|
349
325
|
kindOf: (schema) => kindOf(schema),
|
|
350
|
-
getObjectShape
|
|
326
|
+
getObjectShape,
|
|
351
327
|
getTupleItems,
|
|
352
|
-
getDiscriminatedOptions
|
|
328
|
+
getDiscriminatedOptions,
|
|
353
329
|
getDiscriminator,
|
|
354
330
|
getLiteralValues,
|
|
355
331
|
isPreprocessNode,
|
|
356
332
|
isCoercePrimitive,
|
|
357
|
-
|
|
358
|
-
containsAsyncTransform,
|
|
359
|
-
containsDiscriminatedUnion,
|
|
360
|
-
hasContainerOrRootRefine,
|
|
333
|
+
capabilitiesOf,
|
|
361
334
|
// Walker accessors (D2 / D3 / D5).
|
|
362
335
|
getArrayElement: (schema) => {
|
|
363
336
|
if (kindOf(schema) !== "array") return void 0;
|
|
@@ -384,7 +357,7 @@ const V4_INTROSPECTOR = {
|
|
|
384
357
|
};
|
|
385
358
|
|
|
386
359
|
function slimPrimitivesOf(schema, maxRecursionDepth) {
|
|
387
|
-
return
|
|
360
|
+
return slimPrimitivesWalk(schema, V4_INTROSPECTOR, maxRecursionDepth);
|
|
388
361
|
}
|
|
389
362
|
|
|
390
363
|
function deriveDefault(schema, useDefault, maxRecursionDepth) {
|
|
@@ -516,7 +489,7 @@ function isLeafRequired(schema, depth = 0) {
|
|
|
516
489
|
return true;
|
|
517
490
|
}
|
|
518
491
|
function zodV4Adapter(rootSchema) {
|
|
519
|
-
|
|
492
|
+
assertZodV4Node(rootSchema);
|
|
520
493
|
assertKeyedRoot(rootSchema);
|
|
521
494
|
return (_formKey, options) => sharedV4Schemas(
|
|
522
495
|
rootSchema,
|
|
@@ -540,6 +513,7 @@ function buildV4Services() {
|
|
|
540
513
|
slimPrimitivesOf: (schema, maxRecursionDepth) => slimPrimitivesOf(schema, maxRecursionDepth),
|
|
541
514
|
deriveDefault: (schema, useDefault, maxRecursionDepth) => deriveDefault(schema, useDefault, maxRecursionDepth),
|
|
542
515
|
runGetDefaults: (schema, config, maxRecursionDepth) => runGetDefaultsV4(schema, config, maxRecursionDepth),
|
|
516
|
+
validateSync: (schema, data) => validateSyncV4(schema, data),
|
|
543
517
|
unwrapStructuralWrappers: (schema) => unwrapStructuralWrappers(schema),
|
|
544
518
|
unwrapToDiscriminatedUnion: (schema) => unwrapToDiscriminatedUnion(schema),
|
|
545
519
|
peelAllWrappers: (schema) => peelAllWrappers(schema),
|
|
@@ -558,37 +532,35 @@ function buildV4Services() {
|
|
|
558
532
|
};
|
|
559
533
|
}
|
|
560
534
|
function runGetDefaultsV4(rootSchema, config, maxRecursionDepth) {
|
|
561
|
-
|
|
535
|
+
return getDefaultValuesFromZodSchema({
|
|
562
536
|
schema: rootSchema,
|
|
563
537
|
useDefaultSchemaValues: config.useDefaultSchemaValues,
|
|
564
538
|
constraints: config.constraints,
|
|
565
539
|
maxRecursionDepth
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
540
|
+
}).data;
|
|
541
|
+
}
|
|
542
|
+
const verdictRan = /* @__PURE__ */ new WeakMap();
|
|
543
|
+
function validateSyncV4(rootSchema, data) {
|
|
544
|
+
const { asyncRefine, asyncTransform } = capabilitiesOf(rootSchema);
|
|
545
|
+
if (asyncRefine || asyncTransform) return [];
|
|
570
546
|
try {
|
|
571
|
-
const
|
|
572
|
-
if (
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return {
|
|
576
|
-
data,
|
|
577
|
-
errors: zodIssuesToValidationErrors(parseResult.error.issues),
|
|
578
|
-
success: false
|
|
579
|
-
};
|
|
547
|
+
const jitless = !verdictRan.has(rootSchema);
|
|
548
|
+
if (jitless) verdictRan.set(rootSchema, true);
|
|
549
|
+
const parseResult = rootSchema.safeParse(data, { jitless });
|
|
550
|
+
return parseResult.success ? [] : zodIssuesToValidationErrors(parseResult.error.issues);
|
|
580
551
|
} catch {
|
|
581
|
-
return
|
|
552
|
+
return [];
|
|
582
553
|
}
|
|
583
554
|
}
|
|
584
555
|
function buildSubSchemaStubV4(schema, maxRecursionDepth) {
|
|
585
556
|
return {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
}
|
|
557
|
+
// Async work of either kind, as the root's `needsAsyncValidation`
|
|
558
|
+
// counts it: the field's `valid` waits for the first async pass.
|
|
559
|
+
needsAsyncValidation: () => {
|
|
560
|
+
const { asyncRefine, asyncTransform } = scanCapabilities(schema);
|
|
561
|
+
return asyncRefine || asyncTransform;
|
|
562
|
+
},
|
|
563
|
+
getDefaultValues: () => deriveDefault(schema, true, maxRecursionDepth),
|
|
592
564
|
getSchemasAtPath: () => [],
|
|
593
565
|
validateAtPath: async (data) => {
|
|
594
566
|
const result = await schema.safeParseAsync(data);
|
|
@@ -638,7 +610,8 @@ function resolveFieldMetaAtPath(rootSchema, path, maxRecursionDepth) {
|
|
|
638
610
|
};
|
|
639
611
|
}
|
|
640
612
|
function readDescription(schema) {
|
|
641
|
-
const
|
|
613
|
+
const scope = globalThis;
|
|
614
|
+
const candidate = scope.__zod_globalRegistry?.get(schema)?.description ?? schema.description;
|
|
642
615
|
return typeof candidate === "string" ? candidate : void 0;
|
|
643
616
|
}
|
|
644
617
|
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { G as GenericForm, l as FlatPath, s as NestedType, F as FormKey, U as UseFormConfiguration, A as AbstractSchema,
|
|
2
|
+
import { G as GenericForm, l as FlatPath, s as NestedType, F as FormKey, U as UseFormConfiguration, A as AbstractSchema, ap as AcceptableDefaults, ab as ValidateOnConfig, a as UseFormReturnType } from './attaform.i13OEHJF.mjs';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A Zod v4 schema whose core definition matches `Def`, named by the
|
|
6
|
+
* `_zod` internals that classic `zod` and `zod/mini` schemas both carry.
|
|
7
|
+
*/
|
|
8
|
+
type ZodV4SchemaOf<Def> = {
|
|
9
|
+
_zod: {
|
|
10
|
+
def: Def;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Any Zod v4 schema, from `zod` or `zod/mini`. The public signatures that
|
|
15
|
+
* take a v4 schema below the root (`PathInput`, `PathOutput`, `withMeta`)
|
|
16
|
+
* constrain on it, for the reasons `SupportedRootSchema` gives.
|
|
17
|
+
*/
|
|
18
|
+
type ZodV4Schema = ZodV4SchemaOf<{
|
|
19
|
+
type: string;
|
|
20
|
+
}>;
|
|
4
21
|
/**
|
|
5
22
|
* The Zod v4 schema roots `useForm` accepts. A fixed-shape
|
|
6
23
|
* `z.object({ … })` is the common case; `z.record(K, V)` admits a
|
|
@@ -16,22 +33,29 @@ import { G as GenericForm, l as FlatPath, s as NestedType, F as FormKey, U as Us
|
|
|
16
33
|
* `z.map` / `z.set`) are not form roots; wrap them under a key. The
|
|
17
34
|
* adapter's runtime construction rejects them with a legible error.
|
|
18
35
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* `
|
|
31
|
-
*
|
|
32
|
-
*
|
|
36
|
+
* Each arm is structural on `_zod.def.type`, Zod's core internals, so a
|
|
37
|
+
* `zod/mini` root binds exactly as its classic twin does, and the form
|
|
38
|
+
* types project through `z.input` / `z.output`, which are core's too. A
|
|
39
|
+
* plain union's `def` has no `discriminator`, which keeps it out of the
|
|
40
|
+
* third arm.
|
|
41
|
+
*
|
|
42
|
+
* The alias names nothing from `zod`, and the unified `attaform/zod`
|
|
43
|
+
* entry depends on that. Its published `.d.mts` resolves `zod` against
|
|
44
|
+
* the one major a consumer installed, and in a v3-only install a classic
|
|
45
|
+
* class reference such as `z.ZodObject` degrades to an `any`-like error
|
|
46
|
+
* type, which a v3 schema satisfies: the v4 overload would capture it and
|
|
47
|
+
* collapse its read slot to `never`. No v3 schema carries `_zod`, so this
|
|
48
|
+
* constraint sends every v3 schema to the v3 overload however `zod`
|
|
49
|
+
* resolves. The v3-only bundled-types fixture guards it.
|
|
33
50
|
*/
|
|
34
|
-
type SupportedRootSchema =
|
|
51
|
+
type SupportedRootSchema = ZodV4SchemaOf<{
|
|
52
|
+
type: 'object';
|
|
53
|
+
}> | ZodV4SchemaOf<{
|
|
54
|
+
type: 'record';
|
|
55
|
+
}> | ZodV4SchemaOf<{
|
|
56
|
+
type: 'union';
|
|
57
|
+
discriminator: string;
|
|
58
|
+
}>;
|
|
35
59
|
|
|
36
60
|
/**
|
|
37
61
|
* The shape `form.values.<key>` returns at runtime. Four cases per leaf:
|
|
@@ -164,7 +188,7 @@ type StorageLeaf<L> = InputIsUnknown<L> extends true ? unknown : L extends {
|
|
|
164
188
|
* type FlagWriteIn = PathInput<typeof schema, 'flag'> // string
|
|
165
189
|
* ```
|
|
166
190
|
*/
|
|
167
|
-
type PathInput<Schema extends
|
|
191
|
+
type PathInput<Schema extends ZodV4Schema, Path extends string> = z.input<Schema> extends GenericForm ? Path extends FlatPath<z.input<Schema>> ? NestedType<z.input<Schema>, Path> : never : never;
|
|
168
192
|
/**
|
|
169
193
|
* What `Path` holds after the full parse pipeline: the schema's
|
|
170
194
|
* `z.output<Schema>` shape there. It matches `form.parse()`'s `data` and
|
|
@@ -177,7 +201,7 @@ type PathInput<Schema extends z.ZodType, Path extends string> = z.input<Schema>
|
|
|
177
201
|
* type FlagParsedOut = PathOutput<typeof schema, 'flag'> // boolean
|
|
178
202
|
* ```
|
|
179
203
|
*/
|
|
180
|
-
type PathOutput<Schema extends
|
|
204
|
+
type PathOutput<Schema extends ZodV4Schema, Path extends string> = z.output<Schema> extends GenericForm ? Path extends FlatPath<z.output<Schema>> ? NestedType<z.output<Schema>, Path> : never : never;
|
|
181
205
|
/**
|
|
182
206
|
* Factor the three identical-shape conditionals out of `useForm`'s public
|
|
183
207
|
* signature, so the bundled `.d.ts` carries one alias per shape instead
|
|
@@ -217,4 +241,4 @@ declare function useForm<Schema extends SupportedRootSchema, K extends FormKey =
|
|
|
217
241
|
} & ValidateOnConfig): UseFormReturnType<FormOf<Schema>, OutOf<Schema>, ReadOf<Schema>, K>;
|
|
218
242
|
|
|
219
243
|
export { useForm as u };
|
|
220
|
-
export type { PathInput as P, SupportedRootSchema as S, PathOutput as a, StorageShape as b };
|
|
244
|
+
export type { PathInput as P, SupportedRootSchema as S, ZodV4Schema as Z, PathOutput as a, StorageShape as b };
|