attaform 0.16.2 → 0.16.3

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.
Files changed (52) hide show
  1. package/README.md +7 -7
  2. package/dist/index.d.cts +3 -3
  3. package/dist/index.d.mts +3 -3
  4. package/dist/index.d.ts +3 -3
  5. package/dist/nuxt.d.cts +1 -1
  6. package/dist/nuxt.d.mts +1 -1
  7. package/dist/nuxt.d.ts +1 -1
  8. package/dist/shared/{attaform.CVv9Oh0a.d.mts → attaform.Bls_kFR6.d.mts} +1 -1
  9. package/dist/shared/attaform.C8CyvYa_.cjs +36 -0
  10. package/dist/shared/attaform.C8CyvYa_.cjs.map +1 -0
  11. package/dist/shared/attaform.C9Ph2SMx.cjs.map +1 -1
  12. package/dist/shared/{attaform.DdnithOf.mjs → attaform.CFA6y0KF.mjs} +6 -17
  13. package/dist/shared/attaform.CFA6y0KF.mjs.map +1 -0
  14. package/dist/shared/attaform.D13GMFgK.mjs +32 -0
  15. package/dist/shared/attaform.D13GMFgK.mjs.map +1 -0
  16. package/dist/shared/{attaform.DfrYByDj.cjs → attaform.DGuGGNg9.cjs} +8 -15
  17. package/dist/shared/attaform.DGuGGNg9.cjs.map +1 -0
  18. package/dist/shared/attaform.DILbdvfo.mjs.map +1 -1
  19. package/dist/shared/{attaform.Dq5BabH1.d.cts → attaform.DLnKT7wk.d.cts} +1 -1
  20. package/dist/shared/{attaform.Bp1c-uGF.cjs → attaform.KrNw10aW.cjs} +6 -17
  21. package/dist/shared/attaform.KrNw10aW.cjs.map +1 -0
  22. package/dist/shared/{attaform.CvOXSpCb.mjs → attaform.XYOMTvuO.mjs} +8 -15
  23. package/dist/shared/attaform.XYOMTvuO.mjs.map +1 -0
  24. package/dist/shared/{attaform.0Gxd_OOx.d.cts → attaform._EqYNPYF.d.cts} +21 -13
  25. package/dist/shared/{attaform.0Gxd_OOx.d.mts → attaform._EqYNPYF.d.mts} +21 -13
  26. package/dist/shared/{attaform.0Gxd_OOx.d.ts → attaform._EqYNPYF.d.ts} +21 -13
  27. package/dist/shared/{attaform.CWCx2r0x.d.ts → attaform.lFNwBcA3.d.ts} +1 -1
  28. package/dist/zod-v3.cjs +1 -1
  29. package/dist/zod-v3.d.cts +19 -14
  30. package/dist/zod-v3.d.mts +19 -14
  31. package/dist/zod-v3.d.ts +19 -14
  32. package/dist/zod-v3.mjs +1 -1
  33. package/dist/zod-v4.cjs +1 -1
  34. package/dist/zod-v4.d.cts +94 -5
  35. package/dist/zod-v4.d.mts +94 -5
  36. package/dist/zod-v4.d.ts +94 -5
  37. package/dist/zod-v4.mjs +1 -1
  38. package/dist/zod.cjs +22 -4
  39. package/dist/zod.cjs.map +1 -1
  40. package/dist/zod.d.cts +51 -7
  41. package/dist/zod.d.mts +51 -7
  42. package/dist/zod.d.ts +51 -7
  43. package/dist/zod.mjs +21 -4
  44. package/dist/zod.mjs.map +1 -1
  45. package/package.json +1 -1
  46. package/dist/shared/attaform.BAuJTWuT.d.mts +0 -84
  47. package/dist/shared/attaform.Bp1c-uGF.cjs.map +0 -1
  48. package/dist/shared/attaform.CvOXSpCb.mjs.map +0 -1
  49. package/dist/shared/attaform.DdnithOf.mjs.map +0 -1
  50. package/dist/shared/attaform.DfrYByDj.cjs.map +0 -1
  51. package/dist/shared/attaform.ls_7jBYc.d.ts +0 -84
  52. package/dist/shared/attaform.xIcmqscx.d.cts +0 -84
package/dist/zod.cjs CHANGED
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const plugin = require('./shared/attaform.rIRYSUI1.cjs');
4
- const useForm$1 = require('./shared/attaform.Bp1c-uGF.cjs');
5
- const index = require('./shared/attaform.DfrYByDj.cjs');
4
+ const useForm$1 = require('./shared/attaform.KrNw10aW.cjs');
5
+ const index = require('./shared/attaform.DGuGGNg9.cjs');
6
6
  const useFormContext = require('./shared/attaform.C9Ph2SMx.cjs');
7
+ const fieldMetaStore = require('./shared/attaform.C8CyvYa_.cjs');
7
8
 
8
9
  function isZodV4SchemaShape(value) {
9
10
  if (typeof value !== "object" || value === null) return false;
@@ -23,12 +24,29 @@ function useForm(configuration) {
23
24
  return useForm$1.useForm(configuration);
24
25
  }
25
26
 
27
+ const fieldMeta = fieldMetaStore.fieldMetaStore;
28
+ function withMeta(schema, payload) {
29
+ const target = schema;
30
+ const existing = fieldMetaStore.getFieldMetaForSchema(target) ?? {};
31
+ const cloned = cloneSchema(schema);
32
+ fieldMetaStore.fieldMetaStore.add(cloned, { ...existing, ...payload });
33
+ return cloned;
34
+ }
35
+ function cloneSchema(schema) {
36
+ const candidate = schema;
37
+ if (typeof candidate.clone === "function") {
38
+ return candidate.clone();
39
+ }
40
+ const Ctor = candidate.constructor;
41
+ return new Ctor(candidate._def);
42
+ }
43
+
26
44
  exports.useRegister = plugin.useRegister;
27
- exports.fieldMeta = index.fieldMeta;
28
- exports.withMeta = index.withMeta;
29
45
  exports.AttaformErrorCode = useFormContext.AttaformErrorCode;
30
46
  exports.injectForm = useFormContext.injectForm;
31
47
  exports.isUnset = useFormContext.isUnset;
32
48
  exports.unset = useFormContext.unset;
49
+ exports.fieldMeta = fieldMeta;
33
50
  exports.useForm = useForm;
51
+ exports.withMeta = withMeta;
34
52
  //# sourceMappingURL=zod.cjs.map
package/dist/zod.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"zod.cjs","sources":["../src/runtime/core/zod-shape.ts","../src/runtime/adapters/unified/use-form.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 * 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 type { z } from 'zod'\nimport { InvalidUseFormConfigError } from '../../core/errors'\nimport { isZodV4SchemaShape } from '../../core/zod-shape'\nimport { useForm as useFormV3 } from '../../composables/use-form'\nimport { useForm as useFormV4 } from '../zod-v4'\nimport type {\n AbstractSchema,\n ValidateOnConfig,\n UseFormReturnType,\n UseFormConfiguration,\n} from '../../types/types-api'\nimport type { DeepPartial, DefaultValuesShape, GenericForm } from '../../types/types-core'\n\n/**\n * Create a form bound to a Zod schema. Accepts both Zod v3 and Zod v4\n * schemas; the runtime picks the right adapter from the schema's\n * shape.\n *\n * Type inference targets Zod v4 — the recommended major. Consumers\n * still on Zod v3 get correct runtime behavior here, but the strongest\n * TypeScript inference comes from importing `attaform/zod-v3`\n * directly.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod'\n *\n * const form = useForm({\n * schema: z.object({\n * email: z.email(),\n * password: z.string().min(8),\n * }),\n * })\n * ```\n */\nexport function useForm<Schema extends z.ZodObject>(\n configuration: Omit<\n UseFormConfiguration<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n AbstractSchema<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n >,\n DeepPartial<\n DefaultValuesShape<z.output<Schema> extends GenericForm ? z.output<Schema> : never>\n >\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n> {\n // Foot-gun guard mirrors the typed wrappers'.\n if (\n configuration === undefined ||\n configuration === null ||\n (configuration as { schema?: unknown }).schema === undefined\n ) {\n throw new InvalidUseFormConfigError()\n }\n\n const { schema } = configuration as { schema: unknown }\n if (isZodV4SchemaShape(schema)) {\n return useFormV4(configuration as Parameters<typeof useFormV4<Schema>>[0]) as ReturnType<\n typeof useForm<Schema>\n >\n }\n // Anything else (Zod v3 schema, custom AbstractSchema, schema\n // factory) goes through the v3 wrapper, which already accepts both\n // Zod v3 input and AbstractSchema directly via its existing shape\n // branch. Cast through unknown — the unified entry's TS surface\n // tracks v4, but the runtime accepts the broader shape.\n return useFormV3(configuration as never) as unknown as ReturnType<typeof useForm<Schema>>\n}\n"],"names":["InvalidUseFormConfigError","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;;ACUO,SAAS,QACd,aAAA,EAiBA;AAEA,EAAA,IACE,kBAAkB,MAAA,IAClB,aAAA,KAAkB,IAAA,IACjB,aAAA,CAAuC,WAAW,MAAA,EACnD;AACA,IAAA,MAAM,IAAIA,gCAAA,EAA0B;AAAA,EACtC;AAEA,EAAA,MAAM,EAAE,QAAO,GAAI,aAAA;AACnB,EAAA,IAAI,kBAAA,CAAmB,MAAM,CAAA,EAAG;AAC9B,IAAA,OAAOC,cAAU,aAAwD,CAAA;AAAA,EAG3E;AAMA,EAAA,OAAOC,kBAAU,aAAsB,CAAA;AACzC;;;;;;;;;;;"}
1
+ {"version":3,"file":"zod.cjs","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 * 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 type { z } from 'zod'\nimport { InvalidUseFormConfigError } from '../../core/errors'\nimport { isZodV4SchemaShape } from '../../core/zod-shape'\nimport { useForm as useFormV3 } from '../../composables/use-form'\nimport { useForm as useFormV4 } from '../zod-v4'\nimport type {\n AbstractSchema,\n ValidateOnConfig,\n UseFormReturnType,\n UseFormConfiguration,\n} from '../../types/types-api'\nimport type { DeepPartial, DefaultValuesShape, GenericForm } from '../../types/types-core'\n\n/**\n * Create a form bound to a Zod schema. Accepts both Zod v3 and Zod v4\n * schemas; the runtime picks the right adapter from the schema's\n * shape.\n *\n * Type inference targets Zod v4 — the recommended major. Consumers\n * still on Zod v3 get correct runtime behavior here, but the strongest\n * TypeScript inference comes from importing `attaform/zod-v3`\n * directly.\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 */\nexport function useForm<Schema extends z.ZodObject>(\n configuration: Omit<\n UseFormConfiguration<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n AbstractSchema<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n >,\n DeepPartial<\n DefaultValuesShape<z.output<Schema> extends GenericForm ? z.output<Schema> : never>\n >\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n> {\n // Foot-gun guard mirrors the typed wrappers'.\n if (\n configuration === undefined ||\n configuration === null ||\n (configuration as { schema?: unknown }).schema === undefined\n ) {\n throw new InvalidUseFormConfigError()\n }\n\n const { schema } = configuration as { schema: unknown }\n if (isZodV4SchemaShape(schema)) {\n return useFormV4(configuration as Parameters<typeof useFormV4<Schema>>[0]) as ReturnType<\n typeof useForm<Schema>\n >\n }\n // Anything else (Zod v3 schema, custom AbstractSchema, schema\n // factory) goes through the v3 wrapper, which already accepts both\n // Zod v3 input and AbstractSchema directly via its existing shape\n // branch. Cast through unknown — the unified entry's TS surface\n // tracks v4, but the runtime accepts the broader shape.\n return useFormV3(configuration as never) as unknown as ReturnType<typeof useForm<Schema>>\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":["InvalidUseFormConfigError","useFormV4","useFormV3","fieldMetaStore","getFieldMetaForSchema"],"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;;ACUO,SAAS,QACd,aAAA,EAiBA;AAEA,EAAA,IACE,kBAAkB,MAAA,IAClB,aAAA,KAAkB,IAAA,IACjB,aAAA,CAAuC,WAAW,MAAA,EACnD;AACA,IAAA,MAAM,IAAIA,gCAAA,EAA0B;AAAA,EACtC;AAEA,EAAA,MAAM,EAAE,QAAO,GAAI,aAAA;AACnB,EAAA,IAAI,kBAAA,CAAmB,MAAM,CAAA,EAAG;AAC9B,IAAA,OAAOC,cAAU,aAAwD,CAAA;AAAA,EAG3E;AAMA,EAAA,OAAOC,kBAAU,aAAsB,CAAA;AACzC;;AC3DO,MAAM,SAAA,GAAYC;AAiBlB,SAAS,QAAA,CAAY,QAAW,OAAA,EAA8B;AACnE,EAAA,MAAM,MAAA,GAAS,MAAA;AACf,EAAA,MAAM,QAAA,GAAWC,oCAAA,CAAsB,MAAM,CAAA,IAAK,EAAC;AACnD,EAAA,MAAM,MAAA,GAAS,YAAY,MAAM,CAAA;AACjC,EAAAD,6BAAA,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;;;;;;;;;;;"}
package/dist/zod.d.cts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { z } from 'zod';
2
- import { U as UseFormConfiguration, G as GenericForm, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType } from './shared/attaform.0Gxd_OOx.cjs';
3
- export { n as FieldMetaPayload, ac as Unset, am as isUnset, ao as unset } from './shared/attaform.0Gxd_OOx.cjs';
4
- export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.Dq5BabH1.cjs';
5
- export { f as fieldMeta, w as withMeta } from './shared/attaform.xIcmqscx.cjs';
2
+ import { U as UseFormConfiguration, G as GenericForm, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType, n as FieldMetaPayload } from './shared/attaform._EqYNPYF.cjs';
3
+ export { ac as Unset, am as isUnset, ao as unset } from './shared/attaform._EqYNPYF.cjs';
4
+ export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.DLnKT7wk.cjs';
6
5
  import 'vue';
7
6
 
8
7
  /**
@@ -42,8 +41,8 @@ import 'vue';
42
41
  *
43
42
  * const form = useForm({
44
43
  * schema: z.object({
45
- * email: z.email(),
46
- * password: z.string().min(8),
44
+ * username: z.string().min(2, 'At least 2 characters'),
45
+ * password: z.string().min(8, 'At least 8 characters'),
47
46
  * }),
48
47
  * })
49
48
  * ```
@@ -52,4 +51,49 @@ declare function useForm<Schema extends z.ZodObject>(configuration: Omit<UseForm
52
51
  schema: Schema;
53
52
  } & ValidateOnConfig): UseFormReturnType<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>;
54
53
 
55
- export { useForm };
54
+ /**
55
+ * Field-metadata write/read API for the unified `attaform/zod` entry.
56
+ *
57
+ * Storage is shared with both adapters via `field-meta-store` — a
58
+ * payload written here is visible to whichever adapter the unified
59
+ * `useForm` dispatches to at runtime, regardless of Zod major. No
60
+ * `zod` runtime import; the type-only `import type` is erased at
61
+ * build, so `attaform/zod` carries no `z.registry` reference even
62
+ * when consumed by a Zod 3 project without the Vite plugin alias.
63
+ *
64
+ * The native v4 chain `schema.register(fieldMeta, payload)` continues
65
+ * to work — Zod 4's `.register()` only calls `.add(this, payload)`
66
+ * structurally, satisfied by the shared store.
67
+ */
68
+
69
+ type ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>;
70
+ /**
71
+ * The shared registry every Attaform-aware Zod schema can register
72
+ * field metadata against, regardless of major. Same instance the v3
73
+ * and v4 adapter entries expose — write in one place, read from
74
+ * any.
75
+ *
76
+ * Cast to Zod 4's `$ZodRegistry<FieldMetaPayload>` so the native
77
+ * `schema.register(fieldMeta, payload)` chain type-checks for v4
78
+ * users; the runtime call only needs `.add` structurally, which the
79
+ * shared store provides.
80
+ */
81
+ declare const fieldMeta: ZodFieldMetaRegistry;
82
+ /**
83
+ * Attach `payload` to `schema` in the shared registry and return a
84
+ * clone of `schema` so each call gets its own identity (the registry
85
+ * keys on schema reference, so cloning prevents last-write-wins
86
+ * collisions for sub-schemas reused at multiple paths).
87
+ *
88
+ * Works on both Zod 3 and Zod 4 schemas — branches on the runtime
89
+ * shape of the schema:
90
+ * - Zod 4 schemas expose a public `.clone()` method; we call it.
91
+ * - Zod 3 schemas don't, so we reconstruct via
92
+ * `new schema.constructor(schema._def)`.
93
+ *
94
+ * Both forms produce a fresh schema with the same effective
95
+ * structure, so the registry slot is unique to this call site.
96
+ */
97
+ declare function withMeta<S>(schema: S, payload: FieldMetaPayload): S;
98
+
99
+ export { FieldMetaPayload, fieldMeta, useForm, withMeta };
package/dist/zod.d.mts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { z } from 'zod';
2
- import { U as UseFormConfiguration, G as GenericForm, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType } from './shared/attaform.0Gxd_OOx.mjs';
3
- export { n as FieldMetaPayload, ac as Unset, am as isUnset, ao as unset } from './shared/attaform.0Gxd_OOx.mjs';
4
- export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CVv9Oh0a.mjs';
5
- export { f as fieldMeta, w as withMeta } from './shared/attaform.BAuJTWuT.mjs';
2
+ import { U as UseFormConfiguration, G as GenericForm, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType, n as FieldMetaPayload } from './shared/attaform._EqYNPYF.mjs';
3
+ export { ac as Unset, am as isUnset, ao as unset } from './shared/attaform._EqYNPYF.mjs';
4
+ export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.Bls_kFR6.mjs';
6
5
  import 'vue';
7
6
 
8
7
  /**
@@ -42,8 +41,8 @@ import 'vue';
42
41
  *
43
42
  * const form = useForm({
44
43
  * schema: z.object({
45
- * email: z.email(),
46
- * password: z.string().min(8),
44
+ * username: z.string().min(2, 'At least 2 characters'),
45
+ * password: z.string().min(8, 'At least 8 characters'),
47
46
  * }),
48
47
  * })
49
48
  * ```
@@ -52,4 +51,49 @@ declare function useForm<Schema extends z.ZodObject>(configuration: Omit<UseForm
52
51
  schema: Schema;
53
52
  } & ValidateOnConfig): UseFormReturnType<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>;
54
53
 
55
- export { useForm };
54
+ /**
55
+ * Field-metadata write/read API for the unified `attaform/zod` entry.
56
+ *
57
+ * Storage is shared with both adapters via `field-meta-store` — a
58
+ * payload written here is visible to whichever adapter the unified
59
+ * `useForm` dispatches to at runtime, regardless of Zod major. No
60
+ * `zod` runtime import; the type-only `import type` is erased at
61
+ * build, so `attaform/zod` carries no `z.registry` reference even
62
+ * when consumed by a Zod 3 project without the Vite plugin alias.
63
+ *
64
+ * The native v4 chain `schema.register(fieldMeta, payload)` continues
65
+ * to work — Zod 4's `.register()` only calls `.add(this, payload)`
66
+ * structurally, satisfied by the shared store.
67
+ */
68
+
69
+ type ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>;
70
+ /**
71
+ * The shared registry every Attaform-aware Zod schema can register
72
+ * field metadata against, regardless of major. Same instance the v3
73
+ * and v4 adapter entries expose — write in one place, read from
74
+ * any.
75
+ *
76
+ * Cast to Zod 4's `$ZodRegistry<FieldMetaPayload>` so the native
77
+ * `schema.register(fieldMeta, payload)` chain type-checks for v4
78
+ * users; the runtime call only needs `.add` structurally, which the
79
+ * shared store provides.
80
+ */
81
+ declare const fieldMeta: ZodFieldMetaRegistry;
82
+ /**
83
+ * Attach `payload` to `schema` in the shared registry and return a
84
+ * clone of `schema` so each call gets its own identity (the registry
85
+ * keys on schema reference, so cloning prevents last-write-wins
86
+ * collisions for sub-schemas reused at multiple paths).
87
+ *
88
+ * Works on both Zod 3 and Zod 4 schemas — branches on the runtime
89
+ * shape of the schema:
90
+ * - Zod 4 schemas expose a public `.clone()` method; we call it.
91
+ * - Zod 3 schemas don't, so we reconstruct via
92
+ * `new schema.constructor(schema._def)`.
93
+ *
94
+ * Both forms produce a fresh schema with the same effective
95
+ * structure, so the registry slot is unique to this call site.
96
+ */
97
+ declare function withMeta<S>(schema: S, payload: FieldMetaPayload): S;
98
+
99
+ export { FieldMetaPayload, fieldMeta, useForm, withMeta };
package/dist/zod.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { z } from 'zod';
2
- import { U as UseFormConfiguration, G as GenericForm, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType } from './shared/attaform.0Gxd_OOx.js';
3
- export { n as FieldMetaPayload, ac as Unset, am as isUnset, ao as unset } from './shared/attaform.0Gxd_OOx.js';
4
- export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CWCx2r0x.js';
5
- export { f as fieldMeta, w as withMeta } from './shared/attaform.ls_7jBYc.js';
2
+ import { U as UseFormConfiguration, G as GenericForm, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType, n as FieldMetaPayload } from './shared/attaform._EqYNPYF.js';
3
+ export { ac as Unset, am as isUnset, ao as unset } from './shared/attaform._EqYNPYF.js';
4
+ export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.lFNwBcA3.js';
6
5
  import 'vue';
7
6
 
8
7
  /**
@@ -42,8 +41,8 @@ import 'vue';
42
41
  *
43
42
  * const form = useForm({
44
43
  * schema: z.object({
45
- * email: z.email(),
46
- * password: z.string().min(8),
44
+ * username: z.string().min(2, 'At least 2 characters'),
45
+ * password: z.string().min(8, 'At least 8 characters'),
47
46
  * }),
48
47
  * })
49
48
  * ```
@@ -52,4 +51,49 @@ declare function useForm<Schema extends z.ZodObject>(configuration: Omit<UseForm
52
51
  schema: Schema;
53
52
  } & ValidateOnConfig): UseFormReturnType<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>;
54
53
 
55
- export { useForm };
54
+ /**
55
+ * Field-metadata write/read API for the unified `attaform/zod` entry.
56
+ *
57
+ * Storage is shared with both adapters via `field-meta-store` — a
58
+ * payload written here is visible to whichever adapter the unified
59
+ * `useForm` dispatches to at runtime, regardless of Zod major. No
60
+ * `zod` runtime import; the type-only `import type` is erased at
61
+ * build, so `attaform/zod` carries no `z.registry` reference even
62
+ * when consumed by a Zod 3 project without the Vite plugin alias.
63
+ *
64
+ * The native v4 chain `schema.register(fieldMeta, payload)` continues
65
+ * to work — Zod 4's `.register()` only calls `.add(this, payload)`
66
+ * structurally, satisfied by the shared store.
67
+ */
68
+
69
+ type ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>;
70
+ /**
71
+ * The shared registry every Attaform-aware Zod schema can register
72
+ * field metadata against, regardless of major. Same instance the v3
73
+ * and v4 adapter entries expose — write in one place, read from
74
+ * any.
75
+ *
76
+ * Cast to Zod 4's `$ZodRegistry<FieldMetaPayload>` so the native
77
+ * `schema.register(fieldMeta, payload)` chain type-checks for v4
78
+ * users; the runtime call only needs `.add` structurally, which the
79
+ * shared store provides.
80
+ */
81
+ declare const fieldMeta: ZodFieldMetaRegistry;
82
+ /**
83
+ * Attach `payload` to `schema` in the shared registry and return a
84
+ * clone of `schema` so each call gets its own identity (the registry
85
+ * keys on schema reference, so cloning prevents last-write-wins
86
+ * collisions for sub-schemas reused at multiple paths).
87
+ *
88
+ * Works on both Zod 3 and Zod 4 schemas — branches on the runtime
89
+ * shape of the schema:
90
+ * - Zod 4 schemas expose a public `.clone()` method; we call it.
91
+ * - Zod 3 schemas don't, so we reconstruct via
92
+ * `new schema.constructor(schema._def)`.
93
+ *
94
+ * Both forms produce a fresh schema with the same effective
95
+ * structure, so the registry slot is unique to this call site.
96
+ */
97
+ declare function withMeta<S>(schema: S, payload: FieldMetaPayload): S;
98
+
99
+ export { FieldMetaPayload, fieldMeta, useForm, withMeta };
package/dist/zod.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import { b as InvalidUseFormConfigError } from './shared/attaform.BfMxsfmE.mjs';
2
2
  export { u as useRegister } from './shared/attaform.BfMxsfmE.mjs';
3
- import { u as useForm$2 } from './shared/attaform.DdnithOf.mjs';
4
- import { u as useForm$1 } from './shared/attaform.CvOXSpCb.mjs';
5
- export { f as fieldMeta, w as withMeta } from './shared/attaform.CvOXSpCb.mjs';
3
+ import { u as useForm$2 } from './shared/attaform.CFA6y0KF.mjs';
4
+ import { u as useForm$1 } from './shared/attaform.XYOMTvuO.mjs';
6
5
  export { A as AttaformErrorCode, i as injectForm, a as isUnset, u as unset } from './shared/attaform.DILbdvfo.mjs';
6
+ import { f as fieldMetaStore, g as getFieldMetaForSchema } from './shared/attaform.D13GMFgK.mjs';
7
7
 
8
8
  function isZodV4SchemaShape(value) {
9
9
  if (typeof value !== "object" || value === null) return false;
@@ -23,5 +23,22 @@ function useForm(configuration) {
23
23
  return useForm$2(configuration);
24
24
  }
25
25
 
26
- export { useForm };
26
+ const fieldMeta = fieldMetaStore;
27
+ function withMeta(schema, payload) {
28
+ const target = schema;
29
+ const existing = getFieldMetaForSchema(target) ?? {};
30
+ const cloned = cloneSchema(schema);
31
+ fieldMetaStore.add(cloned, { ...existing, ...payload });
32
+ return cloned;
33
+ }
34
+ function cloneSchema(schema) {
35
+ const candidate = schema;
36
+ if (typeof candidate.clone === "function") {
37
+ return candidate.clone();
38
+ }
39
+ const Ctor = candidate.constructor;
40
+ return new Ctor(candidate._def);
41
+ }
42
+
43
+ export { fieldMeta, useForm, withMeta };
27
44
  //# sourceMappingURL=zod.mjs.map
package/dist/zod.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"zod.mjs","sources":["../src/runtime/core/zod-shape.ts","../src/runtime/adapters/unified/use-form.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 * 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 type { z } from 'zod'\nimport { InvalidUseFormConfigError } from '../../core/errors'\nimport { isZodV4SchemaShape } from '../../core/zod-shape'\nimport { useForm as useFormV3 } from '../../composables/use-form'\nimport { useForm as useFormV4 } from '../zod-v4'\nimport type {\n AbstractSchema,\n ValidateOnConfig,\n UseFormReturnType,\n UseFormConfiguration,\n} from '../../types/types-api'\nimport type { DeepPartial, DefaultValuesShape, GenericForm } from '../../types/types-core'\n\n/**\n * Create a form bound to a Zod schema. Accepts both Zod v3 and Zod v4\n * schemas; the runtime picks the right adapter from the schema's\n * shape.\n *\n * Type inference targets Zod v4 — the recommended major. Consumers\n * still on Zod v3 get correct runtime behavior here, but the strongest\n * TypeScript inference comes from importing `attaform/zod-v3`\n * directly.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod'\n *\n * const form = useForm({\n * schema: z.object({\n * email: z.email(),\n * password: z.string().min(8),\n * }),\n * })\n * ```\n */\nexport function useForm<Schema extends z.ZodObject>(\n configuration: Omit<\n UseFormConfiguration<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n AbstractSchema<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n >,\n DeepPartial<\n DefaultValuesShape<z.output<Schema> extends GenericForm ? z.output<Schema> : never>\n >\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n> {\n // Foot-gun guard mirrors the typed wrappers'.\n if (\n configuration === undefined ||\n configuration === null ||\n (configuration as { schema?: unknown }).schema === undefined\n ) {\n throw new InvalidUseFormConfigError()\n }\n\n const { schema } = configuration as { schema: unknown }\n if (isZodV4SchemaShape(schema)) {\n return useFormV4(configuration as Parameters<typeof useFormV4<Schema>>[0]) as ReturnType<\n typeof useForm<Schema>\n >\n }\n // Anything else (Zod v3 schema, custom AbstractSchema, schema\n // factory) goes through the v3 wrapper, which already accepts both\n // Zod v3 input and AbstractSchema directly via its existing shape\n // branch. Cast through unknown — the unified entry's TS surface\n // tracks v4, but the runtime accepts the broader shape.\n return useFormV3(configuration as never) as unknown as ReturnType<typeof useForm<Schema>>\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;;ACUO,SAAS,QACd,aAAA,EAiBA;AAEA,EAAA,IACE,kBAAkB,MAAA,IAClB,aAAA,KAAkB,IAAA,IACjB,aAAA,CAAuC,WAAW,MAAA,EACnD;AACA,IAAA,MAAM,IAAI,yBAAA,EAA0B;AAAA,EACtC;AAEA,EAAA,MAAM,EAAE,QAAO,GAAI,aAAA;AACnB,EAAA,IAAI,kBAAA,CAAmB,MAAM,CAAA,EAAG;AAC9B,IAAA,OAAOA,UAAU,aAAwD,CAAA;AAAA,EAG3E;AAMA,EAAA,OAAOC,UAAU,aAAsB,CAAA;AACzC;;;;"}
1
+ {"version":3,"file":"zod.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 * 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 type { z } from 'zod'\nimport { InvalidUseFormConfigError } from '../../core/errors'\nimport { isZodV4SchemaShape } from '../../core/zod-shape'\nimport { useForm as useFormV3 } from '../../composables/use-form'\nimport { useForm as useFormV4 } from '../zod-v4'\nimport type {\n AbstractSchema,\n ValidateOnConfig,\n UseFormReturnType,\n UseFormConfiguration,\n} from '../../types/types-api'\nimport type { DeepPartial, DefaultValuesShape, GenericForm } from '../../types/types-core'\n\n/**\n * Create a form bound to a Zod schema. Accepts both Zod v3 and Zod v4\n * schemas; the runtime picks the right adapter from the schema's\n * shape.\n *\n * Type inference targets Zod v4 — the recommended major. Consumers\n * still on Zod v3 get correct runtime behavior here, but the strongest\n * TypeScript inference comes from importing `attaform/zod-v3`\n * directly.\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 */\nexport function useForm<Schema extends z.ZodObject>(\n configuration: Omit<\n UseFormConfiguration<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n AbstractSchema<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n >,\n DeepPartial<\n DefaultValuesShape<z.output<Schema> extends GenericForm ? z.output<Schema> : never>\n >\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n> {\n // Foot-gun guard mirrors the typed wrappers'.\n if (\n configuration === undefined ||\n configuration === null ||\n (configuration as { schema?: unknown }).schema === undefined\n ) {\n throw new InvalidUseFormConfigError()\n }\n\n const { schema } = configuration as { schema: unknown }\n if (isZodV4SchemaShape(schema)) {\n return useFormV4(configuration as Parameters<typeof useFormV4<Schema>>[0]) as ReturnType<\n typeof useForm<Schema>\n >\n }\n // Anything else (Zod v3 schema, custom AbstractSchema, schema\n // factory) goes through the v3 wrapper, which already accepts both\n // Zod v3 input and AbstractSchema directly via its existing shape\n // branch. Cast through unknown — the unified entry's TS surface\n // tracks v4, but the runtime accepts the broader shape.\n return useFormV3(configuration as never) as unknown as ReturnType<typeof useForm<Schema>>\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;;ACUO,SAAS,QACd,aAAA,EAiBA;AAEA,EAAA,IACE,kBAAkB,MAAA,IAClB,aAAA,KAAkB,IAAA,IACjB,aAAA,CAAuC,WAAW,MAAA,EACnD;AACA,IAAA,MAAM,IAAI,yBAAA,EAA0B;AAAA,EACtC;AAEA,EAAA,MAAM,EAAE,QAAO,GAAI,aAAA;AACnB,EAAA,IAAI,kBAAA,CAAmB,MAAM,CAAA,EAAG;AAC9B,IAAA,OAAOA,UAAU,aAAwD,CAAA;AAAA,EAG3E;AAMA,EAAA,OAAOC,UAAU,aAAsB,CAAA;AACzC;;AC3DO,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;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attaform",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "main": "./dist/index.mjs",
5
5
  "types": "./dist/index.d.mts",
6
6
  "files": [
@@ -1,84 +0,0 @@
1
- import { z } from 'zod';
2
- import { n as FieldMetaPayload } from './attaform.0Gxd_OOx.mjs';
3
-
4
- /**
5
- * Field-metadata write/read API for the Zod v4 adapter.
6
- *
7
- * Backed by Zod 4's native `z.registry<T>()` mechanism — the schema
8
- * carries the metadata directly through `schema.register(fieldMeta,
9
- * payload)` (returns the schema, chainable) or the `withMeta()`
10
- * helper (same effect, version-agnostic across the v3 / v4 adapter
11
- * split).
12
- *
13
- * **Registration patterns:** both styles work — register on whatever
14
- * schema reference you assign into the parent's shape, OR on the
15
- * inner schema before wrapping. The adapter's resolver tries the
16
- * walker-returned schema first, then falls back to the peeled
17
- * inner so either ordering hits:
18
- *
19
- * // both equivalent — registry hits at lookup time
20
- * withMeta(z.string(), { label: 'Email' }).optional()
21
- * withMeta(z.string().optional(), { label: 'Email' })
22
- * z.string().optional().register(fieldMeta, { label: 'Email' })
23
- * z.string().register(fieldMeta, { label: 'Email' }).optional()
24
- *
25
- * The path walker returns the wrapper at terminal positions
26
- * (`['email']` against `{ email: z.string().optional() }` resolves
27
- * to `ZodOptional<ZodString>`) and peels at intermediate descent
28
- * (`['address', 'street']` peels through `address`'s wrapper to
29
- * reach the inner object). The two-stage lookup covers both leaf
30
- * and container registrations symmetrically.
31
- */
32
-
33
- /**
34
- * The shared registry every Attaform-aware Zod 4 schema can register
35
- * field metadata against. One module-scoped instance per consumer
36
- * project — re-exported from `attaform/zod` so user code reads the
37
- * same registry the runtime does.
38
- *
39
- * Consumers extending `FieldMetaPayload` via declaration merging
40
- * automatically get the richer payload type at every `register` /
41
- * `add` / `get` call site.
42
- *
43
- * **Shared-instance disambiguation.** A single schema instance reused
44
- * at multiple form paths (e.g. one address schema bound to both
45
- * `pickup` and `delivery`) can carry distinct metadata per path —
46
- * even via the canonical `schema.register(fieldMeta, payload)` chain.
47
- * Internally we maintain a parallel WeakMap of payload LISTS indexed
48
- * per schema reference, and the path-resolver walks the form's
49
- * schema tree counting per-schema occurrences to pick the right
50
- * payload for each path. Object literals evaluate left-to-right, so
51
- * registration order matches tree-walk order, and shared schemas
52
- * pair their two registrations to the two paths correctly:
53
- *
54
- * z.object({
55
- * pickup: addressSchema.register(fieldMeta, { label: 'Pickup address' }),
56
- * delivery: addressSchema.register(fieldMeta, { label: 'Delivery address' }),
57
- * })
58
- * // form.fields('pickup').label → 'Pickup address'
59
- * // form.fields('delivery').label → 'Delivery address'
60
- *
61
- * Schemas reused via `withMeta()` get a fresh clone per call (see
62
- * `withMeta` below), so they never share a registry slot in the
63
- * first place.
64
- */
65
- declare const fieldMeta: z.core.$ZodRegistry<FieldMetaPayload, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
66
- /**
67
- * Attach `payload` to `schema` in the shared `fieldMeta` registry
68
- * and return `schema` (chainable). Cross-version with `attaform/zod-v3`'s
69
- * `withMeta()`; user code that uses this helper reads the same on
70
- * either adapter.
71
- *
72
- * Equivalent to `schema.register(fieldMeta, payload)` on Zod 4.
73
- * Prefer the native chain for v4-only code; reach for `withMeta`
74
- * when authoring schema modules that may need to compile under both
75
- * adapters.
76
- *
77
- * Registers on the schema reference passed in. See the
78
- * "Registration rule" note in this file's header — register on the
79
- * inner schema before wrapping with `.optional()` / `.nullable()` /
80
- * `.default()` / etc.
81
- */
82
- declare function withMeta<S extends z.ZodType>(schema: S, payload: FieldMetaPayload): S;
83
-
84
- export { fieldMeta as f, withMeta as w };