import { TAtscriptAnnotatedType, TAtscriptTypeArray, TAtscriptTypeObject, TValidatorPlugin, Validator } from "@atscript/typescript/utils"; //#region src/patch/patch-types.d.ts interface TArrayPatch { $replace?: A; $insert?: A; $upsert?: A; $update?: Array>>; $remove?: Array>>; } type TArrayElement = ArrayType extends ReadonlyArray ? ElementType : never; /** * Maps each property of T into a patch payload: * - Array properties become `TArrayPatch` * - Non-array properties become `Partial` */ type TDbPatch = { [K in keyof T]?: T[K] extends Array ? TArrayPatch : Partial }; /** * Extracts `@expect.array.key` properties from an array-of-objects type. * These keys uniquely identify an element inside the array and are used * for `$update`, `$remove`, and `$upsert` operations. * * @param def - Atscript array type definition. * @returns Set of property names marked as keys; empty set if none. */ declare function getKeyProps(def: TAtscriptAnnotatedType): Set; //#endregion //#region src/validator.d.ts /** Write operation mode for validator configuration. */ type ValidatorMode = "insert" | "patch" | "replace"; /** Singleton db validator plugin — stateless, safe to share across all validators. */ declare const dbPlugin: TValidatorPlugin; /** * Builds a validator for a given write mode. * * Shared between server-side (`AtscriptDbTable`) and client-side (`ClientValidator`). * Both use the same plugin, same `replace`, same `partial` logic. * * @param type - The annotated type to validate against. * @param mode - The write operation mode. * @param extraPlugins - Additional adapter-specific plugins (prepended before the db plugin). * @param opts - `unknownProps` overrides the validator's unknown-property policy * (used by db-client's `lenientWrites`, where the served type may be a * projection of the full server-side type). */ declare function buildDbValidator(type: TAtscriptAnnotatedType, mode: ValidatorMode, extraPlugins?: TValidatorPlugin[], opts?: { unknownProps?: "strip" | "ignore" | "error"; }): Validator; /** * Path-aware `partial` callback for patch/update validation — the single * implementation shared by the server's `bulkUpdate` validator and the * client's patch preflight: * * - the root object is partial (a patch names only the fields it touches) * - nav-relation subtrees are partial (nested data is validated by its own table) * - `@db.patch.strategy "merge"` blocks are partial (the decomposer merges * per leaf, so absent keys survive server-side by design) * * Every other nested object stays strict: non-merge blocks are `$set` as a * whole (replace semantics), so their required fields really are required. */ declare function buildPatchPartial(navPaths: ReadonlySet): (def: TAtscriptAnnotatedType, path: string) => boolean; /** Returns true if the annotated type is a navigation relation (TO/FROM/VIA). */ declare function isNavRelation(type: TAtscriptAnnotatedType): boolean; /** * Forces nav fields non-optional so the plugin handles null/undefined checks. * The Validator caches replace results internally, so this allocates at most once per type node. */ declare function forceNavNonOptional(type: TAtscriptAnnotatedType): TAtscriptAnnotatedType; /** Result of {@link buildValidationContext}. */ interface ValidationContext { /** Flat map of dotted field paths → annotated types (same shape the server builds). */ flatMap: Map; /** Set of field paths that are navigation relations (TO/FROM/VIA). */ navFields: ReadonlySet; } /** * Builds a lightweight validation context from a deserialized Atscript type. * * This is the client-side equivalent of the server's `TableMetadata.build()`, * without any adapter-specific processing (physical columns, index resolution, etc.). * * @param type - A deserialized annotated type (from `deserializeAnnotatedType(meta.type)`). * @returns `flatMap` and `navFields` suitable for passing to `createDbValidatorPlugin` via `DbValidationContext`. */ declare function buildValidationContext(type: TAtscriptAnnotatedType): ValidationContext; //#endregion export { buildValidationContext as a, isNavRelation as c, getKeyProps as d, buildPatchPartial as i, TArrayPatch as l, ValidatorMode as n, dbPlugin as o, buildDbValidator as r, forceNavNonOptional as s, ValidationContext as t, TDbPatch as u };