import type { ExprResult, ValidPaths, ValidPathsWithCond } from './types.js'; import type { Get } from 'type-fest'; /** * A compiled update operation ready for use in DynamoDB requests. * * @typeParam T - The entity type this update operates on */ export type CompiledUpdateOperation = { type: 'update_operation'; exprResult: ExprResult; value?: T; }; /** * A SET operation that assigns a value to an attribute. * * @typeParam T - The entity type * @typeParam Key - The path to the attribute being set */ export type SetOperation = ValidPaths> = { type: 'update_set_value'; key: Key; value: Get | (Get extends number ? AddOp : never) | IfNotExistsOp; }; /** * An arithmetic add operation for numeric attributes. * * @typeParam T - The entity type */ type AddOp = { type: 'update_primitive_add_op'; key: ValidPathsWithCond; value: number; }; /** * A conditional set operation that only sets if the attribute doesn't exist. * * @typeParam T - The entity type * @typeParam Key - The path to the attribute */ type IfNotExistsOp = ValidPaths> = { type: 'update_if_not_exists_op'; key: Key; value: Get; }; /** * An operation that appends values to a list attribute. * * @typeParam T - The entity type * @typeParam Path - The path to the list attribute */ type SetAppendOperation = ValidPathsWithCond> = { type: 'update_set_append'; key: Path; value: Get; }; /** * An operation that prepends values to a list attribute. * * @typeParam T - The entity type * @typeParam Path - The path to the list attribute */ type SetPrependOperation = ValidPathsWithCond> = { type: 'update_set_prepend'; key: Path; value: Get; }; /** * Union of all possible update operation types. */ export type AnyOperation = SetOperation | SetAppendOperation | SetPrependOperation | UpdateOperation; /** * An array of update operations to be applied together. * * @typeParam T - The entity type this update operates on */ export type UpdateOperation = AnyOperation[]; /** * Operations available in the update builder callback. * * @typeParam T - The entity type the updates operate on */ export type UpdateOps = { /** Sets an attribute to a value, optionally with add or if_not_exists modifiers */ set: >(key: Key, value: Get | (Get extends number ? AddOp : never) | IfNotExistsOp) => SetOperation; /** Creates an add operation for incrementing numeric attributes */ opAdd: (key: ValidPathsWithCond, value: number) => AddOp; /** Creates an if_not_exists operation for conditional setting */ opIfNotExists: >(key: Key, value: Get) => IfNotExistsOp; /** Appends values to the end of a list attribute */ append: >(key: Path, value: Get) => SetAppendOperation; /** Prepends values to the beginning of a list attribute */ prepend: >(key: Path, value: Get) => SetPrependOperation; }; /** * Creates an add operation for incrementing a numeric attribute. * * @typeParam T - The entity type * @param key - Path to the numeric attribute * @param value - Amount to add (can be negative for subtraction) * @returns An AddOp to use with set() */ export declare function opAdd(key: ValidPathsWithCond, value: number): AddOp; /** * Creates an if_not_exists operation for conditional attribute setting. * * @typeParam T - The entity type * @typeParam Key - The path to the attribute * @param key - Path to the attribute * @param value - Default value if attribute doesn't exist * @returns An IfNotExistsOp to use with set() */ export declare function opIfNotExists>(key: Key, value: Get): IfNotExistsOp; /** * Creates an update expression using a type-safe builder pattern. * * @typeParam T - The entity type the update operates on * @param builder - Callback that receives update operations and returns an array of operations * @returns An array of update operations ready for compilation * * @example * ```ts * const update = exprUpdate(({ set, opAdd }) => [ * set("name", "John"), * set("loginCount", opAdd("loginCount", 1)) * ]); * ``` */ export declare function exprUpdate(builder: (ops: UpdateOps) => AnyOperation[]): UpdateOperation; /** * Compiles an update operation into a DynamoDB-ready expression. * * @typeParam T - The entity type the update operates on * @param operations - The update operations to compile * @returns A compiled update with expression string and attribute maps */ export declare function compileUpdateExpr(operations: UpdateOperation): CompiledUpdateOperation; export {}; //# sourceMappingURL=update.d.ts.map