import type { InferAttributes, PickByType, QueryOperator, WhereOptions } from "../@types/index"; import { TransactionContext } from "./client"; import type { Schema } from "./decorator"; import { SCHEMA } from "./decorator"; type WhereFilters = { [K in keyof InferAttributes]?: InferAttributes[K] | ({ [N in Exclude]?: InferAttributes[K]; } & { in?: InferAttributes[K][]; $in?: InferAttributes[K][]; }); }; /** * @description Lifecycle hook signature. `this` is the model instance; update hooks receive the changes delta. * @description Firma de un hook de ciclo de vida. `this` es la instancia del modelo; los hooks de update reciben el delta de cambios. */ export type HookFn = (this: T, changes?: Partial>) => void | Promise; /** * @description Options for mutation operations. `hook` is opt-in (default false); `tx` runs the operation inside a transaction. * @description Opciones para operaciones de mutación. `hook` es opt-in (default false); `tx` ejecuta la operación dentro de una transacción. */ export interface MutationOptions { hook?: boolean; tx?: TransactionContext; } /** * @description Result of a query: the instances plus the cursor of the next page, when there is one. * @description Resultado de una consulta: las instancias más el cursor de la página siguiente, cuando la hay. */ export type QueryResult = M[] & { cursor?: Record; }; export default class Table { static [SCHEMA]: Schema; constructor(props?: Partial); toJSON(): Record; /** * @description Convierte la instancia a un payload listo para DynamoDB * @returns Objeto con nombres de columnas de DB y valores apropiados */ private _toDBPayload; toString(): string; save(options?: MutationOptions): Promise; update(data: Partial>, options?: MutationOptions): Promise; destroy(options?: MutationOptions): Promise; forceDestroy(options?: MutationOptions): Promise; attach(RelatedModel: new () => R, related_id: string, pivot_data?: Record): Promise; detach(RelatedModel: new () => R, related_id: string): Promise; /** * Sincronizar relación ManyToMany reemplazando todas las relaciones existentes * @param RelatedModel Modelo relacionado * @param related_ids Array de IDs a sincronizar */ sync(RelatedModel: new () => R, related_ids: string[]): Promise; /** * @description Builds the DynamoDB key of a record from its primary key value. * @description Construye la clave DynamoDB de un registro a partir del valor de su clave primaria. */ private static _key; /** * @description Sends write requests in batches of 25, retrying whatever DynamoDB leaves unprocessed. * @description Envía peticiones de escritura en lotes de 25, reintentando lo que DynamoDB deje sin procesar. */ private static _batchWrite; /** * @description Runs the write pipeline of a column over a value, with the current one as reference. * @description Ejecuta el pipeline de escritura de una columna sobre un valor, con el actual como referencia. */ private static _apply; /** * @description Run the registered hooks of a given type on an instance, in declaration order. * @description Ejecuta los hooks registrados de un tipo dado sobre una instancia, en orden de declaración. */ private static _run_hooks; static create(this: new (data: any) => M, data: Partial>, options?: MutationOptions): Promise; /** * @description Creates several records with BatchWriteItem, 25 items per request. It does not check * for duplicate primary keys, which BatchWriteItem cannot express: an existing record is overwritten. * @description Crea varios registros con BatchWriteItem, 25 items por petición. No comprueba claves * primarias duplicadas, que BatchWriteItem no admite: un registro existente se sobreescribe. * @param rows Datos de cada registro * @param options Opciones de mutación * @example * const logs = await Log.createMany([{ message: "a" }, { message: "b" }]); */ static createMany(this: new (data: any) => M, rows: Array>>, options?: MutationOptions): Promise; /** * @description Deletes records by primary key with BatchWriteItem, without reading them first. * Always a hard delete: it ignores `@DeleteAt` and does not run destroy hooks. * @description Elimina registros por clave primaria con BatchWriteItem, sin leerlos antes. * Siempre es borrado definitivo: ignora `@DeleteAt` y no ejecuta hooks de destrucción. * @param ids Claves primarias a eliminar * @param options Opciones de mutación * @example * await Log.deleteMany(["01H...", "01J..."]); */ static deleteMany(this: new (data: any) => M, ids: Array, options?: MutationOptions): Promise; /** * @description Extract PK value from filters if the filter is a simple PK equality. Returns null otherwise. * @description Extrae el valor de PK de los filtros si es una igualdad simple por PK. Retorna null en otro caso. */ private static _extractPK; static update(this: new (data: any) => M, updates: Partial>, filters: Partial>, options?: MutationOptions): Promise; static delete(this: new (data: any) => M, filters: Partial>, options?: MutationOptions): Promise; /** * @description Atomically increment a numeric field by amount. Uses DynamoDB SET expression. * @description Incrementa atómicamente un campo numérico. Usa expresión SET de DynamoDB. */ private static _atomicAdd; static increment(this: new (data: any) => M, field: keyof PickByType, number>, amount: number, filters: WhereFilters, options?: MutationOptions): Promise; static decrement(this: new (data: any) => M, field: keyof PickByType, number>, amount: number, filters: WhereFilters, options?: MutationOptions): Promise; increment, number>>(field: K, amount?: number): Promise; decrement, number>>(field: K, amount?: number): Promise; static where(this: new (props?: any) => M, key: keyof InferAttributes, value: InferAttributes[typeof key], options?: WhereOptions): Promise>; static where(this: new (props?: any) => M, key: keyof InferAttributes, operator: QueryOperator, value: any, options?: WhereOptions): Promise>; static where(this: new (props?: any) => M, filters: WhereFilters, options?: WhereOptions): Promise>; static first(this: new (props?: any) => M, filters: WhereFilters, options?: WhereOptions): Promise; static last(this: new (props?: any) => M, filters?: WhereFilters, options?: WhereOptions): Promise; } export {};