import { $ as TIdentification, A as TDbActionLevel, B as TDbIndexType, C as TCascadeResolver, D as TCrudPermissions, E as TCrudOp, F as TDbDeleteResult, G as TDbStorageType, H as TDbInsertResult, I as TDbFieldMeta, J as TExistingTableOption, K as TDbUpdateResult, L as TDbForeignKey, M as TDbCollation, N as TDbDefaultFn, O as TDbActionInfo, P as TDbDefaultValue, Q as TIdDescriptor, R as TDbIndex, S as PrimaryKeyOf, T as TColumnDiff, U as TDbReferentialAction, V as TDbInsertManyResult, W as TDbRelation, X as TFkLookupResolver, Y as TFieldMeta, Z as TFkLookupTarget, _ as FieldOpsFor, _t as TGenericLogger, a as TDbEncryptionOptions, at as TTableOptionDiff, b as NavPropsOf, c as BaseDbAdapter, ct as TWriteTableResolver, d as AggregateFn, dt as UniqueryControls, et as TMetaResponse, f as AggregateQuery, ft as WithRelation, g as DbQuery, gt as NoopLogger, h as DbControls, ht as isGeoPointType, i as DbEncryption, it as TSyncColumnResult, j as TDbActionProcessor, k as TDbActionIntent, l as AggregateControls, lt as TypedWithRelation, m as AtscriptDbWritable, mt as isGeoIndexableType, n as DbResponse, nt as TRelationInfo, o as DocumentFieldMapper, ot as TTableResolver, p as AggregateResult, pt as TableMetadata, q as TExistingColumn, r as resolveDesignType, rt as TSearchIndexInfo, s as FieldMappingStrategy, st as TValueFormatterPair, t as AtscriptDbReadable, tt as TMetadataOverrides, u as AggregateExpr, ut as Uniquery, v as FilterExpr, vt as UniquSelect, w as TCascadeTarget, x as OwnPropsOf, y as FlatOf, z as TDbIndexField } from "./db-readable-DoJqR5pb.cjs"; import { a as $mul, c as $update, d as TDbFieldOp, f as TFieldOps, g as separateFieldOps, h as separateCas, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, p as getDbFieldOp, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-DJRnNTVo.cjs"; import { a as TViewColumnMapping, c as AtscriptQueryNode, d as TViewPlan, f as translateQueryTree, h as NativeIntegrity, i as AtscriptDbView, l as AtscriptRef, m as IntegrityStrategy, n as TAdapterFactory, o as AtscriptQueryComparison, p as AtscriptDbTable, r as TDbSpaceOptions, s as AtscriptQueryFieldRef, t as DbSpace, u as TViewJoin } from "./db-space-Bglferws.cjs"; import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.cjs"; import { c as TArrayPatch, i as buildValidationContext, l as TDbPatch, n as ValidatorMode, o as forceNavNonOptional, r as buildDbValidator, s as isNavRelation, t as ValidationContext, u as getKeyProps } from "./validator-Crqe6vRW.cjs"; import { AggregateQuery as AggregateQuery$1, FilterExpr as FilterExpr$1, FilterVisitor, Uniquery as Uniquery$1, computeInsights, isPrimitive, walkFilter } from "@uniqu/core"; //#region src/strategies/relational-field-mapper.d.ts /** * Field mapper for relational adapters (e.g. SQLite, MySQL). * Flattens nested objects to `__`-separated column names and * reconstructs them on read. Applies full physical-name translation * for queries, filters, and controls. */ declare class RelationalFieldMapper extends FieldMappingStrategy { reconstructFromRead(row: Record, meta: TableMetadata): Record; translateQuery(query: Uniquery$1, meta: TableMetadata): DbQuery; translateAggregateQuery(query: AggregateQuery$1, meta: TableMetadata): DbQuery; /** * Overrides the base `translateFilter` to use `leafByLogical` for key resolution * (handles flattened nested paths like `contact.email` → `contact__email`). */ translateFilter(filter: FilterExpr$1, meta: TableMetadata): FilterExpr$1; /** * Translates filter with key renaming from logical to physical names. * Used by the relational query path where field paths must be mapped * to `__`-separated column names. */ translateFilterWithRename(filter: FilterExpr$1, meta: TableMetadata): FilterExpr$1; prepareForWrite(payload: Record, meta: TableMetadata, adapter: BaseDbAdapter): Record; translatePatchKeys(update: Record, meta: TableMetadata): Record; /** * Translates field names in sort and projection controls from * logical dot-paths to physical column names. */ private translateControls; /** * Flattens nested object fields into __-separated keys and * JSON-stringifies @db.json / array fields. */ private flattenPayload; /** * Classifies and writes a single field to the result object. * Recurses into nested objects that should be flattened. */ private writeFlattenedField; /** * When a parent object is null/undefined, set all its flattened children to null. */ private setFlattenedChildrenNull; } //#endregion //#region src/strategies/application-integrity.d.ts /** * Integrity strategy for adapters without native FK support (e.g. MongoDB). * Validates FK constraints and executes cascade/setNull actions at * the application level. */ declare class ApplicationIntegrity extends IntegrityStrategy { /** * Validates FK constraints by querying target tables for referenced records. * Collects unique FK values across items, batches them into target-table * lookups, and throws FK_VIOLATION if any references are missing. */ validateForeignKeys(items: Array>, meta: TableMetadata, fkLookupResolver: TFkLookupResolver | undefined, writeTableResolver: TWriteTableResolver | undefined, partial?: boolean, excludeTargetTable?: string): Promise; /** * Applies cascade/setNull actions on child tables before deleting parent records. * Finds all records matching `filter`, extracts their PK values, then for each * child table with a FK pointing to this table: * - `restrict`: throws if any children exist * - `cascade`: recursively deletes child records * - `setNull`: sets FK fields to null */ cascadeBeforeDelete(filter: FilterExpr$1, tableName: string, meta: TableMetadata, cascadeResolver: TCascadeResolver, translateFilter: (f: FilterExpr$1) => FilterExpr$1, adapter: BaseDbAdapter): Promise; needsCascade(cascadeResolver: TCascadeResolver | undefined): boolean; private recordKey; /** * Builds a filter for child records whose FK matches the deleted parent's PK values. */ private buildCascadeChildFilter; } //#endregion //#region src/db-error.d.ts type DbErrorCode = "CONFLICT" | "FK_VIOLATION" | "NOT_FOUND" | "CASCADE_CYCLE" | "INVALID_QUERY" | "DEPTH_EXCEEDED" | "VERSION_COLUMN_WRITE" | "CAS_EXHAUSTED" | "ENC_CONFIG_MISSING" | "ENC_KEY_INVALID" | "ENC_NOT_ENCRYPTED" | "ENC_DECRYPT_FAILED" | "ENC_FIELD_FILTER" | "ENC_FIELD_SORT" | "ENC_FIELD_AGG" | "ENC_FIELD_PATCH_OP" | "GEO_INDEX_MISSING" | "GEO_NOT_SUPPORTED" | "FILTER_TYPE_MISMATCH"; declare class DbError extends Error { readonly code: DbErrorCode; readonly errors: Array<{ path: string; message: string; }>; name: string; constructor(code: DbErrorCode, errors: Array<{ path: string; message: string; }>, message?: string); } /** * Thrown by {@link withOptimisticRetry} when `maxAttempts` is reached * without a successful CAS commit — the target row kept changing under * the read-modify-write loop. Surfaces the attempt count and the * last-observed version so callers can log/report the contention. */ declare class CasExhaustedError extends DbError { readonly attempts: number; readonly lastSeenVersion: number | undefined; name: string; constructor(attempts: number, lastSeenVersion: number | undefined); } //#endregion //#region src/query/query-guards.d.ts /** * Engine-agnostic query-time guards, applied in the core layer BEFORE filter * translation (field-encryption spec §6, geo-index spec §4.2): * * - filters referencing an `@db.encrypted` field (incl. nested paths into an * encrypted object) → `ENC_FIELD_FILTER` * - `$sort` on an encrypted field → `ENC_FIELD_SORT` * - `$groupBy` / aggregate refs on an encrypted field → `ENC_FIELD_AGG` * - `$geoWithin` on a non-geoPoint field → `FILTER_TYPE_MISMATCH` * - `$geoWithin` with a malformed circle → `INVALID_QUERY` * - `$geoWithin` on an adapter without geo support → `GEO_NOT_SUPPORTED` */ /** Validates a `[lng, lat]` tuple (GeoJSON coordinate order). */ declare function assertGeoPoint(point: unknown, path: string): asserts point is [number, number]; /** * Walks a filter expression, rejecting encrypted-field references and * validating `$geoWithin` operator nodes. */ declare function guardFilter(meta: TableMetadata, adapter: BaseDbAdapter, filter: FilterExpr$1 | undefined, encCode?: "ENC_FIELD_FILTER" | "ENC_FIELD_AGG"): void; /** Shared read-path guard: filter + $sort. */ declare function guardQuery(meta: TableMetadata, adapter: BaseDbAdapter, query: { filter?: FilterExpr$1; controls?: { $sort?: unknown; }; } | undefined): void; /** Aggregate-path guard: $groupBy / $select / $having refs + filter + $sort. */ declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1): void; //#endregion //#region src/with-optimistic-retry.d.ts interface WithOptimisticRetryOptions { /** Maximum number of attempts before giving up. Defaults to `5`. */ maxAttempts?: number; /** * Optional hook invoked between failed attempts. Receives the 1-based * attempt number that just failed. Useful for exponential backoff with * jitter. Default behavior is to retry immediately. */ delay?: (attempt: number) => Promise; } /** * Runs a read-modify-write loop under optimistic concurrency control (OCC). * * Reads the row via `findOne({ filter })`, hands it to `mutator`, then applies * the returned patch with `$cas: { [versionColumn]: row[versionColumn] }`. On * a version conflict (`matchedCount === 0`) it re-reads the row, calls the * mutator with the fresh state, and retries — up to `maxAttempts` times. * * The filter (typically the primary key) is threaded into the update payload * so the table layer can extract the row identity. If `mutator` returns * fields that overlap with the filter, the patch wins (last-write semantics * inside a single object spread). * * @throws {DbError} with code `INVALID_QUERY` if `table` has no * `@db.column.version` column — the helper would have no version to thread * into `$cas` and would silently degrade to last-write-wins. * @throws {DbError} with code `NOT_FOUND` if the initial `findOne` returns * `null`. The mutator is not invoked with a fabricated row. * @throws {CasExhaustedError} if `maxAttempts` is reached without a * successful commit. */ declare function withOptimisticRetry>(table: AtscriptDbTable, filter: Record, mutator: (row: TRow) => Promise> | Record, opts?: WithOptimisticRetryOptions): Promise; //#endregion //#region src/patch/patch-decomposer.d.ts /** * Decomposes a patch payload into a flat update object for adapters * that don't support native patch operations. * * Handles: * - Top-level array patches (`$replace`, `$insert`, `$upsert`, `$update`, `$remove`) * - Merge strategy for nested objects * - Simple field sets * * For adapters with native patch support (e.g., MongoDB aggregation pipelines), * use {@link BaseDbAdapter.nativePatch} instead. * * @param payload - The patch payload from the user. * @param table - The AtscriptDbTable instance for metadata access. * @returns A flat update object suitable for a basic `updateOne` call. */ declare function decomposePatch(payload: Record, table: AtscriptDbTable): Record; /** * Throws if the payload attempts to write the version column directly. * * The version column is server-managed: the adapter auto-increments it * on every update. Direct writes (plain SET, `$inc`, `$mul`) would * either silently no-op (overwritten by the auto-bump) or corrupt the * OCC invariant. Reject them at the patch layer so the failure is * loud and adapter-agnostic. * * Inspects the payload AFTER `separateCas` has stripped `$cas` (so * that the legitimate `$cas` → expectedVersion path is not flagged). * * The check is intentionally narrow: only the physical column name at * the top level of the (already-decomposed) payload. Nested objects * cannot reach the version column through dot-paths because the * decomposer flattens those into top-level dot-keys; the version * column, being a scalar at the root, cannot be nested. * * Zero-allocation when the version column is not present. * * @throws {DbError} with code `VERSION_COLUMN_WRITE` when the version * column appears as a top-level key in `data` or as the target of a * `$inc`/`$mul` field op. */ declare function assertNoVersionWrites(data: Record, versionColumn: string): void; //#endregion export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, type AggregateControls, type AggregateExpr, type AggregateFn, type AggregateQuery, type AggregateResult, ApplicationIntegrity, AtscriptDbReadable, AtscriptDbTable, AtscriptDbView, type AtscriptDbWritable, type AtscriptQueryComparison, type AtscriptQueryFieldRef, type AtscriptQueryNode, type AtscriptRef, BaseDbAdapter, CasExhaustedError, type DbControls, DbEncryption, DbError, type DbErrorCode, type DbQuery, type DbResponse, DbSpace, type DbValidationContext, DocumentFieldMapper, FieldMappingStrategy, type FieldOpsFor, type FilterExpr, type FilterVisitor, type FlatOf, IntegrityStrategy, NativeIntegrity, type NavPropsOf, NoopLogger, type OwnPropsOf, type PrimaryKeyOf, RelationalFieldMapper, type TAdapterFactory, type TArrayPatch, type TCascadeResolver, type TCascadeTarget, type TColumnDiff, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TDbCas, type TDbCollation, type TDbDefaultFn, type TDbDefaultValue, type TDbDeleteResult, type TDbEncryptionOptions, type TDbFieldMeta, type TDbFieldOp, type TDbForeignKey, type TDbIndex, type TDbIndexField, type TDbIndexType, type TDbInsertManyResult, type TDbInsertResult, type TDbPatch, type TDbReferentialAction, type TDbRelation, type TDbSpaceOptions, type TDbStorageType, type TDbUpdateResult, type TExistingColumn, type TExistingTableOption, type TFieldMeta, type TFieldOps, type TFkLookupResolver, type TFkLookupTarget, type TGenericLogger, type TIdDescriptor, type TIdentification, type TMetaResponse, type TMetadataOverrides, type TRelationInfo, type TSearchIndexInfo, type TSyncColumnResult, type TTableOptionDiff, type TTableResolver, type TValueFormatterPair, type TViewColumnMapping, type TViewJoin, type TViewPlan, type TWriteTableResolver, TableMetadata, type TypedWithRelation, UniquSelect, type Uniquery, type UniqueryControls, type ValidationContext, type ValidatorMode, type WithOptimisticRetryOptions, type WithRelation, assertGeoPoint, assertNoVersionWrites, buildDbValidator, buildValidationContext, computeInsights, createDbValidatorPlugin, decomposePatch, forceNavNonOptional, getDbFieldOp, getKeyProps, guardAggregate, guardFilter, guardQuery, isDbFieldOp, isGeoIndexableType, isGeoPointType, isNavRelation, isPrimitive, resolveDesignType, separateCas, separateFieldOps, translateQueryTree, walkFilter, withOptimisticRetry };