//#region src/ops.d.ts /** A numeric field operation (increment, decrement, or multiply). */ interface TDbFieldOp { $inc?: number; $dec?: number; $mul?: number; } /** * A compare-and-set assertion: the update applies only if the version * column currently equals `value`. Used inline in update payloads: * * { ...patch, $cas: { version: 4 } } * * The map shape is forward-compatible with multi-field CAS; v1 has * exactly one entry keyed by the table's version column name. */ interface TDbCas { [versionColumn: string]: number; } /** Increment a numeric field by `value` (default 1). */ declare function $inc(value?: number): TDbFieldOp; /** Decrement a numeric field by `value` (default 1). */ declare function $dec(value?: number): TDbFieldOp; /** Multiply a numeric field by `value`. */ declare function $mul(value: number): TDbFieldOp; /** * Build a CAS marker for an inline payload. * * Use as a sibling to plain SET fields in an update payload: * * await users.updateOne({ id, status: 'active', ...$cas('version', 4) }) * * The wrapped object can be spread directly so the marker stays a * single, type-safe top-level entry. */ declare function $cas(versionColumn: string, value: number): { $cas: TDbCas; }; /** Replace the entire array. */ declare function $replace(items: T[]): { $replace: T[]; }; /** Append items to an array. */ declare function $insert(items: T[]): { $insert: T[]; }; /** Insert-or-update items by key. */ declare function $upsert(items: T[]): { $upsert: T[]; }; /** Update existing items matched by key. */ declare function $update(items: Partial[]): { $update: Partial[]; }; /** Remove items matched by key or value. */ declare function $remove(items: Partial[]): { $remove: Partial[]; }; /** Pre-separated field operations, ready for adapters. */ interface TFieldOps { inc?: Record; mul?: Record; } /** * Returns `true` when `value` is a field operation object * (`{ $inc: N }`, `{ $dec: N }`, or `{ $mul: N }`). */ declare function isDbFieldOp(value: unknown): value is TDbFieldOp; /** * Extracts the normalized operation from a field op value. * Returns `undefined` when `value` is not a field op. * * `$dec` is normalized to `{ op: 'inc', value: -N }` so consumers * only need to handle `inc` and `mul`. */ declare function getDbFieldOp(value: unknown): { op: "inc" | "mul"; value: number; } | undefined; /** * Separates field operations from a data payload. * * Mutates `data` in-place (removes op entries) and returns the separated ops. * When no ops are found, returns `undefined` — zero allocation for the * common non-op case. * * Hot path: uses `for...in` (no array allocation), inlines detection to * avoid intermediate `{ op, value }` objects, and short-circuits on typeof. */ declare function separateFieldOps(data: Record): TFieldOps | undefined; /** * Strips the top-level `$cas` operator from a write payload. * * Mutates `data` (deletes `$cas`) and returns the extracted expected * version, or `undefined` if no `$cas` was present. * * The caller is expected to know the table's version column name and * either trust the lookup or pass it explicitly for validation. v1 * accepts a single-entry `$cas` map; the returned number is the value * of that entry. * * Errors (all thrown as {@link DbError}): * - `$cas` is not a plain object → `"$cas operator: ..."` * - `$cas` map is empty * - `$cas` value is non-numeric / non-integer * - `$cas` has more than one entry (v1 single-column constraint) * - `$cas` key does not match `versionColumn` (when provided) * - `$cas` is present on a non-versioned table (`versionColumn === undefined`) * * Zero-allocation on the no-op (no `$cas`) path. */ declare function separateCas(data: Record, versionColumn?: string): number | undefined; //#endregion export { $mul as a, $update as c, TDbFieldOp as d, TFieldOps as f, separateFieldOps as g, separateCas as h, $insert as i, $upsert as l, isDbFieldOp as m, $dec as n, $remove as o, getDbFieldOp as p, $inc as r, $replace as s, $cas as t, TDbCas as u };