import { CreateInput, CreateManyInput } from '../input/createInput.js'; import { SelectSubset } from '../util/types.js'; import { BatchPayload } from '../output/batchPayload.js'; import { FindInput, FindUniqueInput } from '../input/findInput.js'; import { UpdateInput, UpdateManyInput } from '../input/updateInput.js'; import { UpsertInput } from '../input/upsertInput.js'; import { DeleteInput, DeleteManyInput } from '../input/deleteInput.js'; import { QualifiedTablename } from '../../util/tablename.js'; import { HKT, Kind } from '../util/hkt.js'; import { SyncInput } from '../input/syncInput.js'; import { ShapeSubscription } from '../../satellite/process.js'; import { LiveResultSubscribeFunction } from '../../util/subscribe.js'; import { ReplicatedRowTransformer } from '../../util/index.js'; /** * Interface that is implemented by Electric clients. */ export interface Model, CreateData extends object, UpdateData extends object, Select, Where extends object | undefined, WhereUnique extends object, Include, OrderBy, ScalarFieldEnum, GetPayload extends HKT> { sync>(i?: T): Promise; /** * Creates a unique record in the DB. * @param i - The record to create. * @returns The record that was inserted in the DB. */ create>(i: SelectSubset>): Promise>; /** * Creates several records in the DB. * @param i - The records to create. * @returns An object indicating how many records were inserted in the DB. */ createMany>(i: SelectSubset>): Promise; /** * Searches for a unique record in the DB. * @param i - An object containing a where field and optionally include and select fields. * @returns The record if found, `null` otherwise. * * @throws {@link InvalidArgumentError} * Thrown if the record is not unique. */ findUnique>(i: SelectSubset>): Promise | null>; /** * @returns The first record that matches the query, or `null` if no matching record is found. */ findFirst>(i: SelectSubset>): Promise | null>; /** * Fetches all records that match the query. * To fetch only a selection of records use * the `take` and `skip` arguments. * * @returns All records that match the query. */ findMany>(i: SelectSubset>): Promise>>; /** * Same as {@link Model#findUnique} but wraps the result in a {@link LiveResult} object. */ liveUnique>(i: SelectSubset>): LiveResultContext | null>; /** * Same as {@link Model#findFirst} but wraps the result in a {@link LiveResult} object. */ liveFirst>(i: SelectSubset>): LiveResultContext | null>; /** * Same as {@link Model#findMany} but wraps the result in a {@link LiveResult} object. */ liveMany>(i: SelectSubset>): LiveResultContext>>; /** * Updates a single record that is uniquely identified by the provided argument. * * @param i - An object that contains the data to update and uniquely identifies the record to update in the DB. * @returns The updated record. * * @throws {@link InvalidArgumentError} * Thrown if the record does not exist or is not unique. */ update>(i: SelectSubset>): Promise>; /** * Updates all the records that match the query. * * @param i - An object identifying the records to update and containing the data to update. * @returns An object indicating how many records were updated. */ updateMany>(i: SelectSubset>): Promise; /** * Inserts a record if it does not exist, * otherwise it updates the existing record. * * @param i - Object containing the data to create and the data to update in case it exists. * @returns The record that was created or updated. * * @throws {@link InvalidArgumentError} * Thrown if the record is not unique. */ upsert>(i: SelectSubset>): Promise>; /** * Deletes the record that is uniquely identified by the provided argument. * * @param i - Object that uniquely identifies a single record. * @returns The deleted record. * * @throws {@link InvalidArgumentError} * Thrown if the record does not exist or is not unique. */ delete>(i: SelectSubset>): Promise>; /** * Deletes all records that match the provided argument. * * @param i - Object that selects zero or more records to delete. * @returns An object indicating how many records were deleted. */ deleteMany>(i: SelectSubset>): Promise; /** * Puts transforms in place such that any data being replicated * to or from this table is first handled appropriately while * retaining type consistency. * * Can be used to encrypt sensitive fields before they are * replicated outside of their secure local source. * * NOTE: usage is discouraged, but ensure transforms are * set before replication is initiated using {@link sync} * to avoid partially transformed tables. * * @param i - Object that determines transforms to apply */ setReplicationTransform(i: ReplicatedRowTransformer): void; /** * Clears any replication transforms set using {@link setReplicationTransform} */ clearReplicationTransform(): void; } export interface LiveResultContext { (): Promise>; subscribe: LiveResultSubscribeFunction; sourceQuery?: Record | undefined; } /** * A live result wrapping the `result` as well as the concerned table names. * The table names are used to subscribe to changes to those tables * in order to re-run the live query when one of the tables change. */ export declare class LiveResult { result: T; tablenames: QualifiedTablename[]; constructor(result: T, tablenames: QualifiedTablename[]); } /** * A live result update wrapping either the `results` or any `error` from the query, * as well as an `updatedAt` timestamp indicating the retrieval time of this result */ export interface LiveResultUpdate { results?: T; error?: unknown; updatedAt?: Date; }