import type { MaybePromise } from '../../../shared/src/types.ts'; import { CRUD_MUTATION_NAME, type CRUDMutationArg, type CRUDOp, type DeleteOp, type InsertOp, type UpdateOp, type UpsertOp } from '../../../zero-protocol/src/push.ts'; import type { Schema } from '../../../zero-schema/src/builder/schema-builder.ts'; import type { TableSchema } from '../../../zero-schema/src/table-schema.ts'; import type { IVMSourceBranch } from './ivm-branch.ts'; import type { MutatorDefs, WriteTransaction } from './replicache-types.ts'; import type { InsertValue, UpdateValue, UpsertValue, DeleteID } from '../../../zql/src/mutate/custom.ts'; /** * This is the type of the generated mutate.. function. */ export type TableMutator = { /** * Writes a row if a row with the same primary key doesn't already exists. * Non-primary-key fields that are 'optional' can be omitted or set to * `undefined`. Such fields will be assigned the value `null` optimistically * and then the default value as defined by the server. */ insert: (value: InsertValue) => Promise; /** * Writes a row unconditionally, overwriting any existing row with the same * primary key. Non-primary-key fields that are 'optional' can be omitted or * set to `undefined`. Such fields will be assigned the value `null` * optimistically and then the default value as defined by the server. */ upsert: (value: UpsertValue) => Promise; /** * Updates a row with the same primary key. If no such row exists, this * function does nothing. All non-primary-key fields can be omitted or set to * `undefined`. Such fields will be left unchanged from previous value. */ update: (value: UpdateValue) => Promise; /** * Deletes the row with the specified primary key. If no such row exists, this * function does nothing. */ delete: (id: DeleteID) => Promise; }; export type DBMutator = S['enableLegacyMutators'] extends false ? {} : { [K in keyof S['tables']]: TableMutator; }; export type BatchMutator = (body: (m: DBMutator) => MaybePromise) => Promise; type ZeroCRUDMutate = { [CRUD_MUTATION_NAME]: CRUDMutate; }; /** * This is the zero.mutate object part representing the CRUD operations. If the * queries are `issue` and `label`, then this object will have `issue` and * `label` properties. */ export declare function makeCRUDMutate(schema: S, repMutate: ZeroCRUDMutate): { mutate: DBMutator; mutateBatch: BatchMutator; }; /** * Creates the `{inesrt, upsert, update, delete}` object for use inside a * batch. */ export declare function makeBatchCRUDMutate(tableName: string, schema: Schema, ops: CRUDOp[]): TableMutator; export type WithCRUD = MD & { [CRUD_MUTATION_NAME]: CRUDMutator; }; export type CRUDMutate = (crudArg: CRUDMutationArg) => Promise; export type CRUDMutator = (tx: WriteTransaction, crudArg: CRUDMutationArg) => Promise; export declare function makeCRUDMutator(schema: Schema): CRUDMutator; export declare function insertImpl(tx: WriteTransaction, arg: InsertOp, schema: Schema, ivmBranch: IVMSourceBranch | undefined): Promise; export declare function upsertImpl(tx: WriteTransaction, arg: InsertOp | UpsertOp, schema: Schema, ivmBranch: IVMSourceBranch | undefined): Promise; export declare function updateImpl(tx: WriteTransaction, arg: UpdateOp, schema: Schema, ivmBranch: IVMSourceBranch | undefined): Promise; export declare function deleteImpl(tx: WriteTransaction, arg: DeleteOp, schema: Schema, ivmBranch: IVMSourceBranch | undefined): Promise; export {}; //# sourceMappingURL=crud.d.ts.map