attaform 0.26.0 → 0.27.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/bin/attaform.mjs +78 -0
- package/dist/abstract.cjs +47 -0
- package/dist/abstract.cjs.map +1 -0
- package/dist/abstract.d.cts +42 -0
- package/dist/abstract.d.mts +42 -0
- package/dist/abstract.d.ts +42 -0
- package/dist/abstract.mjs +4 -0
- package/dist/abstract.mjs.map +1 -0
- package/dist/chunks/devtools.cjs +2 -2
- package/dist/chunks/devtools.cjs.map +1 -1
- package/dist/chunks/devtools.mjs +1 -1
- package/dist/chunks/fingerprint2.cjs +1 -1
- package/dist/chunks/fingerprint2.mjs +1 -1
- package/dist/esbuild.cjs +2 -2
- package/dist/esbuild.cjs.map +1 -1
- package/dist/esbuild.d.cts +3 -3
- package/dist/esbuild.d.mts +3 -3
- package/dist/esbuild.d.ts +3 -3
- package/dist/esbuild.mjs +2 -2
- package/dist/esbuild.mjs.map +1 -1
- package/dist/index.cjs +41 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +194 -282
- package/dist/index.d.mts +194 -282
- package/dist/index.d.ts +194 -282
- package/dist/index.mjs +4 -25
- package/dist/index.mjs.map +1 -1
- package/dist/nuxt.cjs +3 -1
- package/dist/nuxt.cjs.map +1 -1
- package/dist/nuxt.d.cts +17 -4
- package/dist/nuxt.d.mts +17 -4
- package/dist/nuxt.d.ts +17 -4
- package/dist/nuxt.mjs +4 -2
- package/dist/nuxt.mjs.map +1 -1
- package/dist/rollup.cjs +2 -2
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +3 -3
- package/dist/rollup.d.mts +3 -3
- package/dist/rollup.d.ts +3 -3
- package/dist/rollup.mjs +2 -2
- package/dist/rollup.mjs.map +1 -1
- package/dist/rspack.cjs +1 -1
- package/dist/rspack.d.cts +1 -1
- package/dist/rspack.d.mts +1 -1
- package/dist/rspack.d.ts +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/runtime/plugins/attaform.cjs +4 -5
- package/dist/runtime/plugins/attaform.cjs.map +1 -1
- package/dist/runtime/plugins/attaform.mjs +1 -2
- package/dist/runtime/plugins/attaform.mjs.map +1 -1
- package/dist/shared/{attaform.BRzKBj2g.cjs → attaform.8tFZu1Ub.cjs} +2 -2
- package/dist/shared/{attaform.BRzKBj2g.cjs.map → attaform.8tFZu1Ub.cjs.map} +1 -1
- package/dist/shared/{attaform.k9V0py0s.mjs → attaform.BERt5YMU.mjs} +2 -2
- package/dist/shared/{attaform.k9V0py0s.mjs.map → attaform.BERt5YMU.mjs.map} +1 -1
- package/dist/shared/{attaform.DSOIz08n.mjs → attaform.BceJrhQ7.mjs} +5 -5
- package/dist/shared/{attaform.DSOIz08n.mjs.map → attaform.BceJrhQ7.mjs.map} +1 -1
- package/dist/shared/{attaform.DBNjHgNj.d.cts → attaform.C3WnCDXz.d.cts} +11 -9
- package/dist/shared/{attaform.DBNjHgNj.d.mts → attaform.C3WnCDXz.d.mts} +11 -9
- package/dist/shared/{attaform.DBNjHgNj.d.ts → attaform.C3WnCDXz.d.ts} +11 -9
- package/dist/shared/{attaform.DuzQYscR.d.mts → attaform.C9fPTxjB.d.cts} +5 -5
- package/dist/shared/{attaform.DuzQYscR.d.ts → attaform.C9fPTxjB.d.mts} +5 -5
- package/dist/shared/{attaform.DuzQYscR.d.cts → attaform.C9fPTxjB.d.ts} +5 -5
- package/dist/shared/{attaform.Be5otUVw.d.ts → attaform.CC_y1_Ej.d.ts} +33 -33
- package/dist/shared/{attaform.ceYeVkjn.d.ts → attaform.CEXUlUkc.d.ts} +1579 -1192
- package/dist/shared/{attaform.tZ0YKisf.cjs → attaform.C__F01CE.cjs} +15 -15
- package/dist/shared/{attaform.tZ0YKisf.cjs.map → attaform.C__F01CE.cjs.map} +1 -1
- package/dist/shared/{attaform.BPl-ECRT.cjs → attaform.Co5LNRnv.cjs} +162 -129
- package/dist/shared/attaform.Co5LNRnv.cjs.map +1 -0
- package/dist/shared/{attaform.B71rfNL5.d.mts → attaform.CpXHK60W.d.cts} +33 -33
- package/dist/shared/{attaform.BFfY7HRI.d.cts → attaform.CvVYOvZF.d.mts} +33 -33
- package/dist/shared/{attaform.BoYqnIPI.mjs → attaform.CyQxTOdX.mjs} +55 -36
- package/dist/shared/attaform.CyQxTOdX.mjs.map +1 -0
- package/dist/shared/{attaform.CEY_WLRJ.d.mts → attaform.D99pd7JG.d.cts} +1579 -1192
- package/dist/shared/{attaform.CXVmZtFq.mjs → attaform.DDAmSFnl.mjs} +4 -4
- package/dist/shared/{attaform.CXVmZtFq.mjs.map → attaform.DDAmSFnl.mjs.map} +1 -1
- package/dist/shared/{attaform.Du9RZp8m.cjs → attaform.DQT7_-FO.cjs} +272 -252
- package/dist/shared/attaform.DQT7_-FO.cjs.map +1 -0
- package/dist/shared/{attaform.DGhIix5D.mjs → attaform.Da8EdI2t.mjs} +160 -129
- package/dist/shared/attaform.Da8EdI2t.mjs.map +1 -0
- package/dist/shared/{attaform.Cs0UZ7q6.cjs → attaform.DhVgG2jh.cjs} +16 -16
- package/dist/shared/{attaform.Cs0UZ7q6.cjs.map → attaform.DhVgG2jh.cjs.map} +1 -1
- package/dist/shared/{attaform.sHkHv_98.mjs → attaform.DhnPb6nK.mjs} +6 -3
- package/dist/shared/attaform.DhnPb6nK.mjs.map +1 -0
- package/dist/shared/attaform.DkD0DR7R.mjs +42 -0
- package/dist/shared/attaform.DkD0DR7R.mjs.map +1 -0
- package/dist/shared/{attaform.CSXDW2tO.mjs → attaform.DlSu08F5.mjs} +4 -4
- package/dist/shared/{attaform.CSXDW2tO.mjs.map → attaform.DlSu08F5.mjs.map} +1 -1
- package/dist/shared/{attaform.LEWUFqUw.cjs → attaform.DoQm_Vkd.cjs} +7 -3
- package/dist/shared/attaform.DoQm_Vkd.cjs.map +1 -0
- package/dist/shared/{attaform.BQflyVOL.cjs → attaform.Drsi43GG.cjs} +19 -19
- package/dist/shared/{attaform.BQflyVOL.cjs.map → attaform.Drsi43GG.cjs.map} +1 -1
- package/dist/shared/attaform.K6Thc6By.cjs +46 -0
- package/dist/shared/attaform.K6Thc6By.cjs.map +1 -0
- package/dist/shared/{attaform.Vp2-CWZB.mjs → attaform.KvlEedlF.mjs} +3 -3
- package/dist/shared/{attaform.Vp2-CWZB.mjs.map → attaform.KvlEedlF.mjs.map} +1 -1
- package/dist/shared/{attaform.BRGIpZo4.cjs → attaform.RaTzp1WF.cjs} +3 -3
- package/dist/shared/attaform.RaTzp1WF.cjs.map +1 -0
- package/dist/shared/{attaform.MgaYKlPP.d.cts → attaform.kBkYlKP_.d.mts} +1579 -1192
- package/dist/shared/{attaform.C3Doa9Pt.mjs → attaform.v0fQtWyA.mjs} +3 -3
- package/dist/shared/attaform.v0fQtWyA.mjs.map +1 -0
- package/dist/shared/{attaform.ZXZ6dH72.cjs → attaform.yUrz7C2z.cjs} +3 -3
- package/dist/shared/{attaform.ZXZ6dH72.cjs.map → attaform.yUrz7C2z.cjs.map} +1 -1
- package/dist/transforms.cjs +1 -1
- package/dist/transforms.mjs +1 -1
- package/dist/vite.cjs +21 -3
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +70 -17
- package/dist/vite.d.mts +70 -17
- package/dist/vite.d.ts +70 -17
- package/dist/vite.mjs +20 -4
- package/dist/vite.mjs.map +1 -1
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.mjs +1 -1
- package/dist/zod-v3.cjs +41 -10
- package/dist/zod-v3.cjs.map +1 -1
- package/dist/zod-v3.d.cts +5 -5
- package/dist/zod-v3.d.mts +5 -5
- package/dist/zod-v3.d.ts +5 -5
- package/dist/zod-v3.mjs +4 -2
- package/dist/zod-v3.mjs.map +1 -1
- package/dist/zod-v4.cjs +41 -10
- package/dist/zod-v4.cjs.map +1 -1
- package/dist/zod-v4.d.cts +7 -7
- package/dist/zod-v4.d.mts +7 -7
- package/dist/zod-v4.d.ts +7 -7
- package/dist/zod-v4.mjs +4 -2
- package/dist/zod-v4.mjs.map +1 -1
- package/dist/zod.cjs +44 -49
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +6 -248
- package/dist/zod.d.mts +6 -248
- package/dist/zod.d.ts +6 -248
- package/dist/zod.mjs +4 -42
- package/dist/zod.mjs.map +1 -1
- package/package.json +12 -2
- package/skills/attaform/SKILL.md +128 -0
- package/skills/attaform/references/custom-components.md +72 -0
- package/skills/attaform/references/errors.md +62 -0
- package/skills/attaform/references/ssr.md +26 -0
- package/skills/attaform/references/validation.md +40 -0
- package/skills/attaform/references/wizards.md +104 -0
- package/dist/shared/attaform.55hFR_cl.d.ts +0 -97
- package/dist/shared/attaform.BPl-ECRT.cjs.map +0 -1
- package/dist/shared/attaform.BRGIpZo4.cjs.map +0 -1
- package/dist/shared/attaform.BoYqnIPI.mjs.map +0 -1
- package/dist/shared/attaform.C3Doa9Pt.mjs.map +0 -1
- package/dist/shared/attaform.D51IwDtP.cjs +0 -39
- package/dist/shared/attaform.D51IwDtP.cjs.map +0 -1
- package/dist/shared/attaform.DGhIix5D.mjs.map +0 -1
- package/dist/shared/attaform.DJRz_bzM.d.cts +0 -97
- package/dist/shared/attaform.Du9RZp8m.cjs.map +0 -1
- package/dist/shared/attaform.JPsaqjLl.d.mts +0 -97
- package/dist/shared/attaform.LEWUFqUw.cjs.map +0 -1
- package/dist/shared/attaform.NqYEzRcM.mjs +0 -35
- package/dist/shared/attaform.NqYEzRcM.mjs.map +0 -1
- package/dist/shared/attaform.sHkHv_98.mjs.map +0 -1
- package/dist/shared/{attaform.DdjDqTah.d.ts → attaform.DRUT703x.d.cts} +14 -14
- package/dist/shared/{attaform.DdjDqTah.d.cts → attaform.DRUT703x.d.mts} +14 -14
- package/dist/shared/{attaform.DdjDqTah.d.mts → attaform.DRUT703x.d.ts} +14 -14
|
@@ -2,9 +2,12 @@ import { readFileSync } from 'node:fs';
|
|
|
2
2
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
|
|
5
|
-
const ZOD_UNIFIED_SPECIFIER = "attaform/zod";
|
|
6
5
|
const ZOD_V3_SPECIFIER = "attaform/zod-v3";
|
|
7
6
|
const ZOD_V4_SPECIFIER = "attaform/zod-v4";
|
|
7
|
+
const REWRITABLE_ZOD_SPECIFIER_FILTER = /^attaform(?:\/zod)?$/;
|
|
8
|
+
function isRewritableZodSpecifier(source) {
|
|
9
|
+
return REWRITABLE_ZOD_SPECIFIER_FILTER.test(source);
|
|
10
|
+
}
|
|
8
11
|
function detectZodMajor(consumerRootDir) {
|
|
9
12
|
const consumerURL = pathToFileURL(join(consumerRootDir, "package.json")).href;
|
|
10
13
|
let resolved;
|
|
@@ -47,5 +50,5 @@ function resolveZodAliasTarget(consumerRootDir, tag, resolveZodAlias, warnState)
|
|
|
47
50
|
return detection.major === 4 ? ZOD_V4_SPECIFIER : ZOD_V3_SPECIFIER;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
export {
|
|
51
|
-
//# sourceMappingURL=attaform.
|
|
53
|
+
export { REWRITABLE_ZOD_SPECIFIER_FILTER as R, isRewritableZodSpecifier as i, resolveZodAliasTarget as r };
|
|
54
|
+
//# sourceMappingURL=attaform.DhnPb6nK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attaform.DhnPb6nK.mjs","sources":["../../src/core/detect-zod-major.ts"],"sourcesContent":["/**\n * Shared build-time Zod-major detection and adapter-alias resolution for\n * the bundler plugins (`attaform/vite`, `attaform/rollup`,\n * `attaform/esbuild`, `attaform/webpack`, `attaform/rspack`).\n *\n * The unified `attaform/zod` entry — and the bare `attaform` barrel, which\n * re-exports the identical surface — runtime-dispatches between the v3 and\n * v4 adapters, so a bundler that does not rewrite the import ships BOTH.\n * Each plugin rewrites those two specifiers (see\n * {@link REWRITABLE_ZOD_SPECIFIER_FILTER}) to the single matching adapter\n * subpath (`attaform/zod-v3` or `attaform/zod-v4`) based on the Zod major\n * resolved from the consumer's project, so the consumer bundle carries\n * one adapter instead of two. This module holds the detection (pure Node,\n * no bundler API) plus the shared diagnostic copy so every plugin behaves\n * and reads identically.\n *\n * Build-time only: imported by the build-tool entries at `src/*.ts`,\n * never by runtime code, so it never reaches a consumer's browser bundle.\n */\nimport { readFileSync } from 'node:fs'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { join } from 'node:path'\n\nexport const ZOD_UNIFIED_SPECIFIER = 'attaform/zod'\nexport const ZOD_V3_SPECIFIER = 'attaform/zod-v3'\nexport const ZOD_V4_SPECIFIER = 'attaform/zod-v4'\nexport const ZOD_BARREL_SPECIFIER = 'attaform'\n\n/**\n * The two specifiers a plugin collapses to a single adapter: the explicit\n * unified `attaform/zod` entry AND the bare `attaform` barrel. Both are\n * structurally identical (the barrel re-exports the same\n * `_shared-exports` + `_zod-binding` surface as `attaform/zod`), so both\n * carry the runtime-dispatching `useForm` that pulls in BOTH adapters —\n * and both rewrite to the same single adapter when one Zod major is\n * detected.\n *\n * The rewrite is value-safe: every runtime binding the barrel exports\n * (`useForm`, `fieldMeta`, `withMeta`, plus everything in\n * `_shared-exports`) is also exported by `attaform/zod-v3` and\n * `attaform/zod-v4`, so redirecting bare `attaform` to a pinned adapter\n * can never strand a runtime import. (Type-only exports are erased before\n * this resolve hook runs and are type-checked against the un-rewritten\n * `attaform` specifier, so their per-adapter asymmetry is irrelevant.)\n *\n * The pattern is anchored (`^...$`) so it matches ONLY those two\n * specifiers: the pinned adapters (`attaform/zod-v3`, `attaform/zod-v4`)\n * and every build-tool / other subpath (`attaform/nuxt`, `attaform/vite`,\n * `attaform/abstract`, `attaform/transforms`, ...) pass through untouched.\n * It serves double duty — as esbuild's `onResolve` `filter` (a Go RE2\n * regexp) and, via `.test()`, as the string-match predicate the other\n * plugins call — so the two representations can never diverge.\n */\nexport const REWRITABLE_ZOD_SPECIFIER_FILTER = /^attaform(?:\\/zod)?$/\n\n/**\n * True when `source` is a specifier the plugins rewrite to a single Zod\n * adapter: the bare `attaform` barrel or the explicit `attaform/zod`.\n * Backed by {@link REWRITABLE_ZOD_SPECIFIER_FILTER} so it stays in lockstep\n * with esbuild's filter.\n */\nexport function isRewritableZodSpecifier(source: string): boolean {\n return REWRITABLE_ZOD_SPECIFIER_FILTER.test(source)\n}\n\nexport type ZodMajorDetection =\n | { major: 3 }\n | { major: 4 }\n | { major: 'missing' }\n | { major: 'unknown' }\n\n/**\n * Read the consumer's installed Zod major by resolving\n * `zod/package.json` from their project root. ESM resolution\n * (`import.meta.resolve`) is sync and stable on Node 20.6+, follows\n * pnpm symlinks, and works with attaform's ESM-only `exports` map.\n *\n * Returns:\n * - `{ major: 3 | 4 }` when zod is resolvable AND its `version`\n * field parses to a known major;\n * - `{ major: 'missing' }` when zod can't be resolved at all;\n * - `{ major: 'unknown' }` for any other failure (corrupted\n * package.json, unexpected version string, monorepo edge case).\n */\nexport function detectZodMajor(consumerRootDir: string): ZodMajorDetection {\n const consumerURL = pathToFileURL(join(consumerRootDir, 'package.json')).href\n let resolved: string\n try {\n resolved = import.meta.resolve('zod/package.json', consumerURL)\n } catch {\n return { major: 'missing' }\n }\n try {\n const pkg = JSON.parse(readFileSync(fileURLToPath(resolved), 'utf8')) as { version?: unknown }\n const version = pkg.version\n if (typeof version !== 'string') return { major: 'unknown' }\n const major = Number.parseInt(version.split('.')[0] ?? '', 10)\n if (major === 3) return { major: 3 }\n if (major === 4) return { major: 4 }\n return { major: 'unknown' }\n } catch {\n return { major: 'unknown' }\n }\n}\n\n/**\n * One-shot latch so a plugin warns about an unclassifiable Zod version\n * only once, however many times its detection runs across a build.\n */\nexport interface ZodDetectionWarnState {\n warned: boolean\n}\n\nfunction missingZodError(tag: string): string {\n return (\n `[${tag}] zod is not installed. attaform requires zod as a peer dependency. ` +\n 'Install `zod@^3` or `zod@^4`, OR pass `attaform({ resolveZodAlias: false })` ' +\n 'to keep the runtime-dispatch unified entry (and silence this check).'\n )\n}\n\nfunction unclassifiableZodWarning(tag: string): string {\n return (\n `[${tag}] Could not classify the installed Zod major (corrupted package.json, ` +\n 'monorepo edge case, or an unexpected version string). Falling through to runtime ' +\n 'dispatch — both Zod adapters will ship in the bundle. ' +\n 'Pass `attaform({ resolveZodAlias: false })` to silence this warning.'\n )\n}\n\n/**\n * Resolve the rewrite target for the unified `attaform/zod` specifier,\n * shared by every bundler plugin so they diagnose identically:\n * - returns `attaform/zod-v3` / `attaform/zod-v4` when the consumer's\n * Zod major is detected;\n * - returns `null` to leave `attaform/zod` on its runtime-dispatch\n * entry, either because `resolveZodAlias` is off or because the\n * version could not be classified (warned once via `warnState`);\n * - throws when zod is not installed at all, a fatal misconfiguration\n * the consumer must fix.\n *\n * `tag` brands the diagnostics (`attaform/vite`, `attaform/rollup`, etc).\n * `resolveZodAlias` and `warnState` are supplied by the calling plugin:\n * its consumer-facing default and its per-instance warn latch live at the\n * plugin surface, not here.\n */\nexport function resolveZodAliasTarget(\n consumerRootDir: string,\n tag: string,\n resolveZodAlias: boolean,\n warnState: ZodDetectionWarnState\n): string | null {\n if (!resolveZodAlias) return null\n const detection = detectZodMajor(consumerRootDir)\n if (detection.major === 'missing') {\n throw new Error(missingZodError(tag))\n }\n if (detection.major === 'unknown') {\n if (!warnState.warned) {\n warnState.warned = true\n console.warn(unclassifiableZodWarning(tag))\n }\n return null\n }\n return detection.major === 4 ? ZOD_V4_SPECIFIER : ZOD_V3_SPECIFIER\n}\n"],"names":[],"mappings":";;;;AAwBO,MAAM,gBAAA,GAAmB,iBAAA;AACzB,MAAM,gBAAA,GAAmB,iBAAA;AA4BzB,MAAM,+BAAA,GAAkC;AAQxC,SAAS,yBAAyB,MAAA,EAAyB;AAChE,EAAA,OAAO,+BAAA,CAAgC,KAAK,MAAM,CAAA;AACpD;AAqBO,SAAS,eAAe,eAAA,EAA4C;AACzE,EAAA,MAAM,cAAc,aAAA,CAAc,IAAA,CAAK,eAAA,EAAiB,cAAc,CAAC,CAAA,CAAE,IAAA;AACzE,EAAA,IAAI,QAAA;AACJ,EAAA,IAAI;AACF,IAAA,QAAA,GAAW,MAAA,CAAA,IAAA,CAAY,OAAA,CAAQ,kBAAA,EAAoB,WAAW,CAAA;AAAA,EAChE,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAE,OAAO,SAAA,EAAU;AAAA,EAC5B;AACA,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,KAAK,KAAA,CAAM,YAAA,CAAa,cAAc,QAAQ,CAAA,EAAG,MAAM,CAAC,CAAA;AACpE,IAAA,MAAM,UAAU,GAAA,CAAI,OAAA;AACpB,IAAA,IAAI,OAAO,OAAA,KAAY,QAAA,EAAU,OAAO,EAAE,OAAO,SAAA,EAAU;AAC3D,IAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,QAAA,CAAS,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,IAAK,EAAA,EAAI,EAAE,CAAA;AAC7D,IAAA,IAAI,KAAA,KAAU,CAAA,EAAG,OAAO,EAAE,OAAO,CAAA,EAAE;AACnC,IAAA,IAAI,KAAA,KAAU,CAAA,EAAG,OAAO,EAAE,OAAO,CAAA,EAAE;AACnC,IAAA,OAAO,EAAE,OAAO,SAAA,EAAU;AAAA,EAC5B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAE,OAAO,SAAA,EAAU;AAAA,EAC5B;AACF;AAUA,SAAS,gBAAgB,GAAA,EAAqB;AAC5C,EAAA,OACE,IAAI,GAAG,CAAA,2NAAA,CAAA;AAIX;AAEA,SAAS,yBAAyB,GAAA,EAAqB;AACrD,EAAA,OACE,IAAI,GAAG,CAAA,wRAAA,CAAA;AAKX;AAkBO,SAAS,qBAAA,CACd,eAAA,EACA,GAAA,EACA,eAAA,EACA,SAAA,EACe;AACf,EAAA,IAAI,CAAC,iBAAiB,OAAO,IAAA;AAC7B,EAAA,MAAM,SAAA,GAAY,eAAe,eAAe,CAAA;AAChD,EAAA,IAAI,SAAA,CAAU,UAAU,SAAA,EAAW;AACjC,IAAA,MAAM,IAAI,KAAA,CAAM,eAAA,CAAgB,GAAG,CAAC,CAAA;AAAA,EACtC;AACA,EAAA,IAAI,SAAA,CAAU,UAAU,SAAA,EAAW;AACjC,IAAA,IAAI,CAAC,UAAU,MAAA,EAAQ;AACrB,MAAA,SAAA,CAAU,MAAA,GAAS,IAAA;AACnB,MAAA,OAAA,CAAQ,IAAA,CAAK,wBAAA,CAAyB,GAAG,CAAC,CAAA;AAAA,IAC5C;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,SAAA,CAAU,KAAA,KAAU,CAAA,GAAI,gBAAA,GAAmB,gBAAA;AACpD;;;;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { a as InvalidUseFormConfigError } from './attaform.Da8EdI2t.mjs';
|
|
2
|
+
import { u as useForm$2 } from './attaform.DlSu08F5.mjs';
|
|
3
|
+
import { u as useForm$1 } from './attaform.BceJrhQ7.mjs';
|
|
4
|
+
import { f as fieldMetaStore, g as getFieldMetaForSchema } from './attaform.DDAmSFnl.mjs';
|
|
5
|
+
|
|
6
|
+
function isZodV4SchemaShape(value) {
|
|
7
|
+
if (typeof value !== "object" || value === null) return false;
|
|
8
|
+
const def = value.def;
|
|
9
|
+
if (typeof def !== "object" || def === null) return false;
|
|
10
|
+
return typeof def.type === "string";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function useForm(configuration) {
|
|
14
|
+
if (configuration === void 0 || configuration === null || configuration.schema === void 0) {
|
|
15
|
+
throw new InvalidUseFormConfigError();
|
|
16
|
+
}
|
|
17
|
+
const { schema } = configuration;
|
|
18
|
+
if (isZodV4SchemaShape(schema)) {
|
|
19
|
+
return useForm$1(configuration);
|
|
20
|
+
}
|
|
21
|
+
return useForm$2(configuration);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const fieldMeta = fieldMetaStore;
|
|
25
|
+
function withMeta(schema, payload) {
|
|
26
|
+
const target = schema;
|
|
27
|
+
const existing = getFieldMetaForSchema(target) ?? {};
|
|
28
|
+
const cloned = cloneSchema(schema);
|
|
29
|
+
fieldMetaStore.add(cloned, { ...existing, ...payload });
|
|
30
|
+
return cloned;
|
|
31
|
+
}
|
|
32
|
+
function cloneSchema(schema) {
|
|
33
|
+
const candidate = schema;
|
|
34
|
+
if (typeof candidate.clone === "function") {
|
|
35
|
+
return candidate.clone();
|
|
36
|
+
}
|
|
37
|
+
const Ctor = candidate.constructor;
|
|
38
|
+
return new Ctor(candidate._def);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { fieldMeta as f, useForm as u, withMeta as w };
|
|
42
|
+
//# sourceMappingURL=attaform.DkD0DR7R.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attaform.DkD0DR7R.mjs","sources":["../../src/runtime/core/zod-shape.ts","../../src/runtime/adapters/unified/use-form.ts","../../src/runtime/adapters/unified/field-meta.ts"],"sourcesContent":["/**\n * Shape detectors for Zod schemas. Used by the unified `attaform/zod`\n * entry's runtime dispatch (`runtime/adapters/unified/use-form.ts`)\n * to route to the v3 or v4 adapter based on the schema's runtime\n * shape. Mirrors the discrimination already used by the v4\n * introspection helper (`adapters/zod-v4/introspect.ts`'s\n * `assertZodVersion`, which reads `def.type`) and the v3 wrapper's\n * legitimate-input branch (`composables/use-form.ts`'s `isZodType`,\n * which reads `_def`).\n *\n * Why this discriminator and not `_zod` / `_def`:\n * - Zod v4 retained `_def` for backward compat — reading `_def` alone\n * misclassifies v4 schemas as v3.\n * - Zod v4's stable shape is `def.type: string` (lowercase tag like\n * `'object'`); Zod v3's is `_def.typeName: string` (capitalised tag\n * like `'ZodObject'`). Both are checked structurally so consumers\n * who alias one Zod major to a non-standard import path still work.\n */\n\ninterface ZodV4Shape {\n def: { type: unknown }\n}\n\ninterface ZodV3Shape {\n _def: { typeName: unknown }\n}\n\n/**\n * Returns true when `value` looks like a Zod schema of either major\n * version. Convenience wrapper around the v3 / v4 detectors.\n */\nexport function isZodSchemaShape(value: unknown): boolean {\n return isZodV4SchemaShape(value) || isZodV3SchemaShape(value)\n}\n\n/**\n * Returns true when `value` looks like a Zod v4 schema (has\n * `def.type: string`). Used by the unified entry's runtime-dispatch\n * to route to the v4 adapter.\n */\nexport function isZodV4SchemaShape(value: unknown): value is ZodV4Shape {\n if (typeof value !== 'object' || value === null) return false\n const def = (value as { def?: unknown }).def\n if (typeof def !== 'object' || def === null) return false\n return typeof (def as { type?: unknown }).type === 'string'\n}\n\n/**\n * Returns true when `value` looks like a Zod v3 schema (has\n * `_def.typeName: string`). Kept distinct from `isZodV4SchemaShape`\n * because some v4 schemas also expose `_def` for backward compat —\n * the v4 detector wins first in `isZodSchemaShape`.\n */\nexport function isZodV3SchemaShape(value: unknown): value is ZodV3Shape {\n if (typeof value !== 'object' || value === null) return false\n const def = (value as { _def?: unknown })._def\n if (typeof def !== 'object' || def === null) return false\n return typeof (def as { typeName?: unknown }).typeName === 'string'\n}\n","/**\n * Unified `useForm` for the `attaform/zod` entry. Runtime-dispatches\n * on schema shape: a Zod v4 schema (`def.type` truthy) routes to the\n * v4 adapter; a Zod v3 schema (or any other `AbstractSchema`) routes\n * to the v3 wrapper, which already accepts both Zod v3 input and\n * `AbstractSchema` directly via its built-in shape branch.\n *\n * Type-level dispatch happens via TWO typed overloads — v4 first, v3\n * second — plus an untyped impl. Each overload mirrors the matching\n * direct adapter's signature exactly, so a v4-schema call site pays\n * the same per-call depth cost as importing from `attaform/zod-v4`\n * directly. Overload resolution at concrete call sites commits to one\n * overload immediately on argument shape — no type-level dispatch tax.\n *\n * Tests and other call sites that need the equivalent of\n * `typeof useForm<X>` should reach for the `UseFormReturn<X>` /\n * `UseFormConfig<X>` helpers in `types-api.ts` — instantiation\n * expressions on overloaded functions follow brittle resolution rules,\n * and the helper types give a deterministic projection.\n *\n * This module is the FALLBACK path. Vite consumers see the\n * `attaform/vite` plugin's `resolveId` hook rewrite `attaform/zod`\n * imports to either `attaform/zod-v3` or `attaform/zod-v4` at build\n * time — in that case this dispatch never runs and the consumer\n * bundle ships only the matching adapter. Other bundlers (and\n * non-bundled ESM consumption) hit this dispatch instead, paying a\n * modest size cost for the convenience of a single hello-world import.\n *\n * Power users who want a guaranteed lean bundle on non-Vite tooling\n * can import directly from `attaform/zod-v3` or `attaform/zod-v4` —\n * those subpaths are never rewritten and never load the other\n * adapter.\n */\nimport { InvalidUseFormConfigError } from '../../core/errors'\nimport { isZodV4SchemaShape } from '../../core/zod-shape'\nimport type { ZodV4Internals } from './types-zod-major'\nimport { useForm as useFormV3 } from '../../composables/use-form'\nimport { useForm as useFormV4 } from '../zod-v4'\nimport type {\n AbstractSchema,\n FormKey,\n ValidateOnConfig,\n UseFormReturnType,\n UseFormConfiguration,\n} from '../../types/types-api'\nimport type { AcceptableDefaults } from '../../types/types-core'\nimport type { SupportedRootSchema as SupportedRootSchemaV4 } from '../zod-v4/types-root'\nimport type { SupportedRootSchema as SupportedRootSchemaV3 } from '../zod-v3/types-root'\nimport type {\n V3FormOf,\n V3OutOf,\n V3ReadOf,\n V3SchemaInput,\n V4FormOf,\n V4OutOf,\n V4ReadOf,\n V4SchemaInput,\n} from './types-projections'\n\n/**\n * Create a form bound to a Zod v4 schema.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod'\n *\n * const form = useForm({\n * schema: z.object({\n * username: z.string().min(2, 'At least 2 characters'),\n * password: z.string().min(8, 'At least 8 characters'),\n * }),\n * })\n * ```\n *\n * The constraint intersects `ZodV4Internals` (the v4-only `_zod`\n * brand) so a v3 schema can't bind this overload even when `z`\n * resolves to v3 in a single-major consumer install; v3 schemas fall\n * through to the v3 overload below. See `types-zod-major.ts`.\n */\nexport function useForm<\n Schema extends SupportedRootSchemaV4 & ZodV4Internals,\n K extends FormKey = FormKey,\n>(\n configuration: Omit<\n UseFormConfiguration<\n V4FormOf<Schema>,\n V4OutOf<Schema>,\n AbstractSchema<V4FormOf<Schema>, V4OutOf<Schema>>,\n // `defaultValues` is Omitted below and re-supplied via the\n // `AcceptableDefaults` intersection, so this `DefaultValues` slot is\n // inert. `never` keeps it from re-instantiating the deep\n // `DefaultValuesInput` cascade here — that redundant instantiation,\n // across both overloads at a concrete call site, tips the bundled\n // `.d.ts` into TS2589.\n never,\n K\n >,\n 'schema' | 'validateOn' | 'debounceMs' | 'defaultValues'\n > & {\n schema: Schema\n // #422: the `AcceptableDefaults` slot adds the schema's own input\n // (`V4SchemaInput<Schema>`) as a reflexive escape arm so a generic form\n // wrapper forwarding `defaultValues` does not trip TS2589 / TS2769.\n // The arm is redundant at concrete call sites (a schema's input is a\n // subset of its `DefaultValuesInput`), so concrete checking is\n // unchanged. The return type never references the slot, so field\n // inference is preserved through the wrapper. See `AcceptableDefaults`.\n defaultValues?: AcceptableDefaults<V4FormOf<Schema>, V4SchemaInput<Schema>>\n } & ValidateOnConfig\n): UseFormReturnType<V4FormOf<Schema>, V4OutOf<Schema>, V4ReadOf<Schema>, K>\n/**\n * Create a form bound to a Zod v3 schema.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod-v3'\n *\n * const form = useForm({\n * schema: z.object({\n * username: z.string().min(2, 'At least 2 characters'),\n * password: z.string().min(8, 'At least 8 characters'),\n * }),\n * })\n * ```\n *\n * v3 schemas match this overload; v4 schemas hit the v4 overload\n * above first and never reach here.\n */\nexport function useForm<Schema extends SupportedRootSchemaV3, K extends FormKey = FormKey>(\n configuration: Omit<\n UseFormConfiguration<\n V3FormOf<Schema>,\n V3OutOf<Schema>,\n AbstractSchema<V3FormOf<Schema>, V3OutOf<Schema>>,\n // Inert `DefaultValues` slot — see the v4 overload above.\n never,\n K\n >,\n 'schema' | 'validateOn' | 'debounceMs' | 'defaultValues'\n > & {\n schema: Schema\n // #422 — see the v4 overload above for the escape-arm rationale.\n defaultValues?: AcceptableDefaults<V3FormOf<Schema>, V3SchemaInput<Schema>>\n } & ValidateOnConfig\n): UseFormReturnType<V3FormOf<Schema>, V3OutOf<Schema>, V3ReadOf<Schema>, K>\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useForm(configuration: any): any {\n if (\n configuration === undefined ||\n configuration === null ||\n (configuration as { schema?: unknown }).schema === undefined\n ) {\n throw new InvalidUseFormConfigError()\n }\n const { schema } = configuration as { schema: unknown }\n if (isZodV4SchemaShape(schema)) {\n return useFormV4(configuration as Parameters<typeof useFormV4>[0])\n }\n return useFormV3(configuration as Parameters<typeof useFormV3>[0])\n}\n","/**\n * Field-metadata write/read API for the unified `attaform/zod` entry.\n *\n * Storage is shared with both adapters via `field-meta-store` — a\n * payload written here is visible to whichever adapter the unified\n * `useForm` dispatches to at runtime, regardless of Zod major. No\n * `zod` runtime import; the type-only `import type` is erased at\n * build, so `attaform/zod` carries no `z.registry` reference even\n * when consumed by a Zod 3 project without the Vite plugin alias.\n *\n * The native v4 chain `schema.register(fieldMeta, payload)` continues\n * to work — Zod 4's `.register()` only calls `.add(this, payload)`\n * structurally, satisfied by the shared store.\n */\nimport type { z } from 'zod'\nimport type { FieldMetaPayload } from '../../core/field-meta'\nimport { fieldMetaStore, getFieldMetaForSchema } from '../../core/field-meta-store'\n\n// Zod v4's `$ZodRegistry` class isn't surfaced under the `z` namespace\n// of the classic external entry, but `z.registry()` returns one — so\n// `ReturnType<typeof z.registry<T>>` resolves to the registry type\n// without needing a direct import. The `import type` keeps the\n// reference type-only; nothing about `z.registry` lands in the bundle.\ntype ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>\n\n/**\n * The shared registry every Attaform-aware Zod schema can register\n * field metadata against, regardless of major. Same instance the v3\n * and v4 adapter entries expose — write in one place, read from\n * any.\n *\n * Cast to Zod 4's `$ZodRegistry<FieldMetaPayload>` so the native\n * `schema.register(fieldMeta, payload)` chain type-checks for v4\n * users; the runtime call only needs `.add` structurally, which the\n * shared store provides.\n */\nexport const fieldMeta = fieldMetaStore as unknown as ZodFieldMetaRegistry\n\n/**\n * Attach `payload` to `schema` in the shared registry and return a\n * clone of `schema` so each call gets its own identity (the registry\n * keys on schema reference, so cloning prevents last-write-wins\n * collisions for sub-schemas reused at multiple paths).\n *\n * Works on both Zod 3 and Zod 4 schemas — branches on the runtime\n * shape of the schema:\n * - Zod 4 schemas expose a public `.clone()` method; we call it.\n * - Zod 3 schemas don't, so we reconstruct via\n * `new schema.constructor(schema._def)`.\n *\n * Both forms produce a fresh schema with the same effective\n * structure, so the registry slot is unique to this call site.\n */\nexport function withMeta<S>(schema: S, payload: FieldMetaPayload): S {\n const target = schema as object\n const existing = getFieldMetaForSchema(target) ?? {}\n const cloned = cloneSchema(schema)\n fieldMetaStore.add(cloned as object, { ...existing, ...payload })\n return cloned\n}\n\nfunction cloneSchema<S>(schema: S): S {\n const candidate = schema as { clone?: unknown; constructor: unknown; _def: unknown }\n if (typeof candidate.clone === 'function') {\n return (candidate.clone as () => S)()\n }\n // Zod 3 path: reconstruct via constructor + _def (no public\n // `.clone()` on v3).\n const Ctor = candidate.constructor as new (def: unknown) => S\n return new Ctor(candidate._def)\n}\n"],"names":["useFormV4","useFormV3"],"mappings":";;;;;AAwCO,SAAS,mBAAmB,KAAA,EAAqC;AACtE,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AACxD,EAAA,MAAM,MAAO,KAAA,CAA4B,GAAA;AACzC,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,MAAM,OAAO,KAAA;AACpD,EAAA,OAAO,OAAQ,IAA2B,IAAA,KAAS,QAAA;AACrD;;ACqGO,SAAS,QAAQ,aAAA,EAAyB;AAC/C,EAAA,IACE,kBAAkB,MAAA,IAClB,aAAA,KAAkB,IAAA,IACjB,aAAA,CAAuC,WAAW,MAAA,EACnD;AACA,IAAA,MAAM,IAAI,yBAAA,EAA0B;AAAA,EACtC;AACA,EAAA,MAAM,EAAE,QAAO,GAAI,aAAA;AACnB,EAAA,IAAI,kBAAA,CAAmB,MAAM,CAAA,EAAG;AAC9B,IAAA,OAAOA,UAAU,aAAgD,CAAA;AAAA,EACnE;AACA,EAAA,OAAOC,UAAU,aAAgD,CAAA;AACnE;;AC3HO,MAAM,SAAA,GAAY;AAiBlB,SAAS,QAAA,CAAY,QAAW,OAAA,EAA8B;AACnE,EAAA,MAAM,MAAA,GAAS,MAAA;AACf,EAAA,MAAM,QAAA,GAAW,qBAAA,CAAsB,MAAM,CAAA,IAAK,EAAC;AACnD,EAAA,MAAM,MAAA,GAAS,YAAY,MAAM,CAAA;AACjC,EAAA,cAAA,CAAe,IAAI,MAAA,EAAkB,EAAE,GAAG,QAAA,EAAU,GAAG,SAAS,CAAA;AAChE,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,YAAe,MAAA,EAAc;AACpC,EAAA,MAAM,SAAA,GAAY,MAAA;AAClB,EAAA,IAAI,OAAO,SAAA,CAAU,KAAA,KAAU,UAAA,EAAY;AACzC,IAAA,OAAQ,UAAU,KAAA,EAAkB;AAAA,EACtC;AAGA,EAAA,MAAM,OAAO,SAAA,CAAU,WAAA;AACvB,EAAA,OAAO,IAAI,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA;AAChC;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { f as fieldMetaStore, g as getFieldMetaForSchema, a as getFieldMetaListForSchema, s as slimPrimitivesWalk, c as createAbstractSchema, w as walkPathSegments, d as deriveDefaultWalk, b as getFieldMetaPathMap, m as mergeDeep, p as peelEmbeddedDefault, N as NO_EMBEDDED_DEFAULT } from './attaform.
|
|
2
|
-
import {
|
|
3
|
-
import { A as AttaformError, _ as __DEV__, f as canonicalizePath, a as InvalidUseFormConfigError } from './attaform.
|
|
1
|
+
import { f as fieldMetaStore, g as getFieldMetaForSchema, a as getFieldMetaListForSchema, s as slimPrimitivesWalk, c as createAbstractSchema, w as walkPathSegments, d as deriveDefaultWalk, b as getFieldMetaPathMap, m as mergeDeep, p as peelEmbeddedDefault, N as NO_EMBEDDED_DEFAULT } from './attaform.DDAmSFnl.mjs';
|
|
2
|
+
import { p as humanize, q as getAtPath, o as slimKindOf, r as setAtPath, g as useAbstractForm } from './attaform.CyQxTOdX.mjs';
|
|
3
|
+
import { A as AttaformError, _ as __DEV__, f as canonicalizePath, a as InvalidUseFormConfigError } from './attaform.Da8EdI2t.mjs';
|
|
4
4
|
|
|
5
5
|
const fieldMeta = fieldMetaStore;
|
|
6
6
|
function withMeta(schema, payload) {
|
|
@@ -1628,4 +1628,4 @@ function useForm(configuration) {
|
|
|
1628
1628
|
}
|
|
1629
1629
|
|
|
1630
1630
|
export { fieldMeta as f, isZodSchemaType as i, useForm as u, withMeta as w, zodAdapter as z };
|
|
1631
|
-
//# sourceMappingURL=attaform.
|
|
1631
|
+
//# sourceMappingURL=attaform.DlSu08F5.mjs.map
|