import { L as TDbForeignKey, W as TDbRelation, _t as TGenericLogger, c as BaseDbAdapter, ct as TWriteTableResolver, ot as TTableResolver, pt as TableMetadata } from "./db-readable-wyKeE8ut.mjs"; import { t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.mjs"; import { Validator } from "@atscript/typescript/utils"; import { FilterExpr, WithRelation } from "@uniqu/core"; //#region src/rel/relation-loader.d.ts /** Host interface for the relation loader — matches AtscriptDbReadable property names. */ interface TRelationLoaderHost { readonly tableName: string; readonly _meta: { readonly relations: ReadonlyMap; readonly foreignKeys: ReadonlyMap; }; readonly _tableResolver?: TTableResolver; readonly adapter: BaseDbAdapter; readonly logger: TGenericLogger; } /** * Loads related data for `$with` relations and attaches them to result rows. */ declare function loadRelationsImpl(rows: Array>, withRelations: WithRelation[], host: TRelationLoaderHost): Promise; //#endregion //#region src/rel/relation-helpers.d.ts /** * Finds the FK entry that connects a `@db.rel.to` relation to its target. */ declare function findFKForRelation(relation: TDbRelation, foreignKeys: ReadonlyMap): { localFields: string[]; targetFields: string[]; } | undefined; /** * Finds a FK on a remote table that points back to a given table name. */ declare function findRemoteFK(targetTable: { foreignKeys: ReadonlyMap; }, thisTableName: string, alias?: string): TDbForeignKey | undefined; /** * Resolves the target table name from a relation's target type metadata. */ declare function resolveRelationTargetTable(relation: TDbRelation): string; //#endregion //#region src/rel/nested-writer.d.ts /** * Properties the nested writer functions need from the table instance. * AtscriptDbTable satisfies this structurally — pass `this` with a cast. */ interface TNestedWriterHost { readonly tableName: string; readonly _meta: TableMetadata; readonly _writeTableResolver?: TWriteTableResolver; _findFKForRelation(relation: TDbRelation): { localFields: string[]; targetFields: string[]; } | undefined; _findRemoteFK(targetTable: { foreignKeys: ReadonlyMap; }, thisTableName: string, alias?: string): TDbForeignKey | undefined; _extractRecordFilter(payload: Record): FilterExpr; findOne(query: { filter: FilterExpr; controls: Record; }): Promise | null>; } /** * Checks if any payload contains navigational data that would be silently * dropped because maxDepth is 0. */ declare function checkDepthOverflow(payloads: Array>, maxDepth: number, meta: TableMetadata): void; /** * Validates a batch of items using the given validator and context. * Wraps per-item validation errors with array index paths for batch operations. */ declare function validateBatch(validator: Validator, items: Array>, ctx: DbValidationContext): void; /** * Pre-validates FROM children (type + FK constraints) before the main insert. * Catches errors early before the parent record is committed. */ declare function preValidateNestedFrom(host: TNestedWriterHost, originals: Array>): Promise; /** * Batch-creates TO dependencies before the main insert. */ declare function batchInsertNestedTo(host: TNestedWriterHost, items: Array>, maxDepth: number, depth: number): Promise; /** * Batch-creates FROM dependents after the main insert. */ declare function batchInsertNestedFrom(host: TNestedWriterHost, originals: Array>, parentIds: unknown[], maxDepth: number, depth: number): Promise; /** * Batch-creates VIA (M:N) targets and junction entries after the main insert. */ declare function batchInsertNestedVia(host: TNestedWriterHost, originals: Array>, parentIds: unknown[], maxDepth: number, depth: number): Promise; /** * Batch-replaces TO dependencies before the main replace. */ declare function batchReplaceNestedTo(host: TNestedWriterHost, items: Array>, maxDepth: number, depth: number): Promise; /** * Batch-replaces FROM dependents after the main replace. */ declare function batchReplaceNestedFrom(host: TNestedWriterHost, originals: Array>, maxDepth: number, depth: number): Promise; /** * Handles VIA (M:N) relations during replace. */ declare function batchReplaceNestedVia(host: TNestedWriterHost, originals: Array>, maxDepth: number, depth: number): Promise; /** * Batch-patches TO dependencies before the main patch. * Reads FK values from DB if not present in the payload. */ declare function batchPatchNestedTo(host: TNestedWriterHost, items: Array>, maxDepth: number, depth: number): Promise; /** * Batch-patches FROM (1:N) dependencies after the main patch. * Supports patch operators: $replace, $insert, $remove, $update, $upsert. */ declare function batchPatchNestedFrom(host: TNestedWriterHost, originals: Array>, maxDepth: number, depth: number): Promise; /** * Batch-patches VIA (M:N) dependencies after the main patch. * Supports patch operators: $replace, $insert, $remove, $update, $upsert. */ declare function batchPatchNestedVia(host: TNestedWriterHost, originals: Array>, maxDepth: number, depth: number): Promise; //#endregion export { type TNestedWriterHost, type TRelationLoaderHost, batchInsertNestedFrom, batchInsertNestedTo, batchInsertNestedVia, batchPatchNestedFrom, batchPatchNestedTo, batchPatchNestedVia, batchReplaceNestedFrom, batchReplaceNestedTo, batchReplaceNestedVia, checkDepthOverflow, findFKForRelation, findRemoteFK, loadRelationsImpl, preValidateNestedFrom, resolveRelationTargetTable, validateBatch };