import type { $ZodRegistry, $ZodType } from 'zod/v4/core'; import type { ZodFormsConfig } from './config.js'; import type { FieldConfig, FormMeta } from './types.js'; /** * Register a schema and all its nested fields in a registry using a * path-structured {@link FieldConfig} tree. * * Only the flat metadata fields (`fieldType`, `order`, `hidden`, `section`, * `props`, etc.) are passed to `registry.add()` for each schema. The * structural keys `fields` and `arrayItems` are used purely to drive the * recursive walk and are never stored in the registry. * * @example * ```ts * const formRegistry = z.registry(); * * const schema = z.object({ * name: z.string(), * address: z.object({ street: z.string(), city: z.string() }), * tags: z.array(z.string()), * }); * * registerDeep(formRegistry, schema, { * component: 'form', * fields: { * name: { component: 'Input', order: 0 }, * address: { * component: 'Fieldset', * fields: { * street: { component: 'Input' }, * city: { component: 'Input', hidden: true }, * }, * }, * tags: { * component: 'ArrayField', * arrayItems: { component: 'Input' }, * }, * }, * }); * ``` * * @remarks * Recursively walks a FieldConfig tree, separating traversal keys (fields, arrayItems) * from flat metadata keys (component, order, hidden). Only flat keys are stored in the * registry — structural keys drive the recursion. Warns on config keys that don't match * schema shape (helpful for typo detection). * * @useWhen * - You have a deeply-nested FieldConfig mirroring your schema shape * - Recommended for complex schemas with nested objects and arrays * * @avoidWhen * - For simple flat configs — registerFlat() is simpler and more direct * - Don't use if your config comes from dot-path format (CLI global fields) * * @never * - NEVER mix with registerFlat() on the same schema — registry entries conflict silently * - NEVER forget the structural keys (fields, arrayItems) for nested config — without them, child config is silently ignored * * @category Registration */ export declare function registerDeep(registry: $ZodRegistry, schema: S, config: FieldConfig): void; /** * Register flat dot-path field configs against a schema's registry. * * Typically called with the merged output of `resolveFieldConfig()`, * a flat `Record` keyed by dot-paths like * `"name"`, `"address.street"`, `"tags[]"` — and resolves each path against * the schema structure, calling `registry.add()` for the target schema node. * * This bridges the existing flat config format (used by CLI and * `ZodFormsConfig.fields`) into the registry so that `walkSchema` can * consume it uniformly. * * @example * ```ts * const formRegistry = z.registry(); * const schema = z.object({ * name: z.string(), * address: z.object({ street: z.string(), city: z.string() }), * }); * * registerFlat(formRegistry, schema, { * name: { component: 'Input', order: 0 }, * 'address.street': { component: 'Input' }, * 'address.city': { component: 'Input', hidden: true }, * }); * ``` * * @remarks * Maps flat dot-path keys (e.g., "address.street", "tags[]") to their target schemas * via resolveSchemaPath(). This bridges the flat config format (used by CLI and global fields) * into the registry. Warns on unresolved paths — check logs for typo detection. * * @useWhen * - Merging global field configs from z2f.config.ts into a registry * - Your config uses dot-path notation rather than nested structure * * @avoidWhen * - Your config is already nested mirroring schema shape — use registerDeep() instead * * @never * - NEVER mix with registerDeep() on the same schema — registry entries conflict silently * - NEVER assume numeric path segments matter — "items.0.name" and "items.2.name" resolve to the same target * * @param registry - The Zod registry to register field metadata into. * @param schema - The root Zod schema whose nested nodes are resolved by dot-path. * @param fields - Flat `Record` keyed by dot-path (e.g. `"address.street"`, `"tags[]"`). * * @category Registration */ export declare function registerFlat(registry: $ZodRegistry, schema: $ZodType, fields: Record): void; /** * Register `defineConfig({ schemas: ... })` entries by exported schema identity. * * Any configured export that resolves to a Zod schema in `moduleExports` is * attached to the registry via `registerDeep()`, so a reused exported subschema * carries its default component + nested field config everywhere it appears. */ export declare function registerSchemaConfigs(registry: $ZodRegistry, moduleExports: Record, schemaConfigs: ZodFormsConfig>['schemas'] | undefined): void; //# sourceMappingURL=register.d.ts.map