import { type ComparablePrimitive } from '../index.ts'; import type { EventContextInterface, TableDefForTableName } from './index.ts'; import type { RowType, TableIndexes, UntypedTableDef } from '../lib/table.ts'; import type { ClientTableCoreImplementable } from './client_table.ts'; import type { UntypedRemoteModule } from './spacetime_module.ts'; import type { TableNamesOf } from '../lib/schema.ts'; import type { ReadonlyIndexes } from '../lib/indexes.ts'; import type { Prettify } from '../lib/type_util.ts'; export type Operation = Record> = { type: 'insert' | 'delete'; rowId: ComparablePrimitive; row: RowType; }; export type TableUpdate = { tableName: string; operations: Operation>[]; }; export type PendingCallback = { type: 'insert' | 'delete' | 'update'; table: string; cb: () => void; }; export type TableIndexView> = ReadonlyIndexes, TableIndexes>>; export type TableCache> = TableCacheImpl & TableIndexView; /** * Builder to generate calls to query a `table` in the database */ export declare class TableCacheImpl> implements ClientTableCoreImplementable { #private; private readonly hasPrimaryKey; private rows; private tableDef; private emitter; /** * @param name the table name * @param primaryKeyCol column index designated as `#[primarykey]` * @param primaryKey column name designated as `#[primarykey]` * @param entityClass the entityClass */ constructor(tableDef: TableDefForTableName); /** * @returns number of rows in the table */ count(): bigint; /** * @returns The values of the rows in the table */ iter(): IteratorObject>>, undefined>; /** * Allows iteration over the rows in the table * @returns An iterator over the rows in the table */ [Symbol.iterator](): IteratorObject>>, undefined>; /** Delete every cached reference, including overlaps between subscriptions. */ snapshotDeleteOperations: () => Operation>>[]; applyOperations: (operations: Operation>>[], ctx: EventContextInterface, options?: { /** Suppress unchanged rows during reconnect reconciliation. */ skipIdenticalUpdates?: boolean; }) => PendingCallback[]; update: (ctx: EventContextInterface, rowId: ComparablePrimitive, newRow: RowType>, refCountDelta?: number, skipIfIdentical?: boolean) => PendingCallback | undefined; insert: (ctx: EventContextInterface, operation: Operation>>, count?: number) => PendingCallback | undefined; delete: (ctx: EventContextInterface, operation: Operation>>, count?: number) => PendingCallback | undefined; /** * Register a callback for when a row is newly inserted into the database. * * ```ts * ctx.db.user.onInsert((reducerEvent, user) => { * if (reducerEvent) { * console.log("New user on reducer", reducerEvent, user); * } else { * console.log("New user received during subscription update on insert", user); * } * }); * ``` * * @param cb Callback to be called when a new row is inserted */ onInsert: (cb: (ctx: EventContextInterface, row: Prettify>>) => void) => void; /** * Register a callback for when a row is deleted from the database. * * ```ts * ctx.db.user.onDelete((reducerEvent, user) => { * if (reducerEvent) { * console.log("Deleted user on reducer", reducerEvent, user); * } else { * console.log("Deleted user received during subscription update on update", user); * } * }); * ``` * * @param cb Callback to be called when a new row is inserted */ onDelete: (cb: (ctx: EventContextInterface, row: Prettify>>) => void) => void; /** * Register a callback for when a row is updated into the database. * * ```ts * ctx.db.user.onInsert((reducerEvent, oldUser, user) => { * if (reducerEvent) { * console.log("Updated user on reducer", reducerEvent, user); * } else { * console.log("Updated user received during subscription update on delete", user); * } * }); * ``` * * @param cb Callback to be called when a new row is inserted */ onUpdate: (cb: (ctx: EventContextInterface, oldRow: Prettify>>, row: Prettify>>) => void) => void; /** * Remove a callback for when a row is newly inserted into the database. * * @param cb Callback to be removed */ removeOnInsert: (cb: (ctx: EventContextInterface, row: Prettify>>) => void) => void; /** * Remove a callback for when a row is deleted from the database. * * @param cb Callback to be removed */ removeOnDelete: (cb: (ctx: EventContextInterface, row: Prettify>>) => void) => void; /** * Remove a callback for when a row is updated into the database. * * @param cb Callback to be removed */ removeOnUpdate: (cb: (ctx: EventContextInterface, oldRow: Prettify>>, row: Prettify>>) => void) => void; } //# sourceMappingURL=table_cache.d.ts.map