import type { ReadonlyIndexes } from '../lib/indexes.ts'; import type { TableNamesOf } from '../lib/schema.ts'; import type { ReadonlyTableMethods, RowType, TableIndexes, UntypedTableDef } from '../lib/table.ts'; import type { ColumnBuilder } from '../lib/type_builders.ts'; import type { Prettify } from '../lib/type_util.ts'; import type { TableDefForTableName } from './client_cache.ts'; import type { EventContextInterface } from './event_context.ts'; import type { UntypedRemoteModule } from './spacetime_module.ts'; export type ClientTablePrimaryKeyMethods> = { /** * Registers a callback to be invoked when a row is updated in the table. * Requires that the table has a primary key defined. * @param cb The callback to invoke when a row is updated. */ onUpdate(cb: (ctx: EventContextInterface, oldRow: Prettify>>, newRow: Prettify>>) => void): void; /** * Removes a previously registered update event listener. * @param cb The callback to remove from the update event listeners. */ removeOnUpdate(cb: (ctx: EventContextInterface, oldRow: Prettify>>, newRow: Prettify>>) => void): void; }; export type ClientTableInsertMethods> = { /** * Registers a callback to be invoked when a row is inserted into the table. */ onInsert(cb: (ctx: EventContextInterface, row: Prettify>>) => void): void; /** * Removes a previously registered insert event listener. * @param cb The callback to remove from the insert event listeners. */ removeOnInsert(cb: (ctx: EventContextInterface, row: Prettify>>) => void): void; }; export type ClientTableDeleteMethods> = { /** * Registers a callback to be invoked when a row is deleted from the table. */ onDelete(cb: (ctx: EventContextInterface, row: Prettify>>) => void): void; /** * Removes a previously registered delete event listener. * @param cb The callback to remove from the delete event listeners. */ removeOnDelete(cb: (ctx: EventContextInterface, row: Prettify>>) => void): void; }; export type ClientTableMethods> = ClientTableInsertMethods & ClientTableDeleteMethods; /** * Table * * - Row: row shape * - UCV: unique-constraint violation error type (never if none) * - AIO: auto-increment overflow error type (never if none) */ /** A client table handle for a connection whose module type is not known statically. */ export type UntypedClientTable = ClientTable>; export type ClientTable> = Prettify & ReadonlyIndexes, TableIndexes>>>; type IsEventTable = TableDef extends { isEvent: true; } ? true : false; type HasPrimaryKey = ColumnsHavePrimaryKey; type ColumnsHavePrimaryKey>> = { [K in keyof Cs]: Cs[K] extends ColumnBuilder ? M extends { isPrimaryKey: true; } ? true : never : never; }[keyof Cs] extends true ? true : false; type MaybePKMethods> = Partial>; /** * A variant of ClientTableCore where the primary key methods are always optional, * allowing for classes like TableCache to implement this interface */ export type ClientTableCoreImplementable> = ReadonlyTableMethods> & ClientTableMethods & MaybePKMethods; /** * Core methods of ClientTable, without the indexes mixed in. * Includes only statically known methods. * * Event tables only expose insert callbacks (no delete or update), * matching the Rust SDK's `EventTable` trait. */ export type ClientTableCore> = ReadonlyTableMethods> & ClientTableInsertMethods & (IsEventTable> extends true ? {} : ClientTableDeleteMethods & (HasPrimaryKey> extends true ? ClientTablePrimaryKeyMethods : {})); export {}; //# sourceMappingURL=client_table.d.ts.map