import type { ReadonlyJSONValue } from '../../../shared/src/json.ts'; import type { MutationOk } from '../../../zero-protocol/src/push.ts'; import type { Schema } from '../../../zero-schema/src/builder/schema-builder.ts'; import type { ClientTransaction, SchemaCRUD, SchemaQuery, Transaction } from '../../../zql/src/mutate/custom.ts'; import type { ClientID } from '../types/client-state.ts'; import type { WriteTransaction } from './replicache-types.ts'; import type { ZeroLogContext } from './zero-log-context.ts'; /** * The shape which a user's custom mutator definitions must conform to. */ export type CustomMutatorDefs = { [namespaceOrKey: string]: { [key: string]: CustomMutatorImpl; } | CustomMutatorImpl; }; export type MutatorResult = { client: Promise; server: Promise; }; export type CustomMutatorImpl = (tx: Transaction, args: TArgs) => Promise; /** * The shape exposed on the `Zero.mutate` instance. * The signature of a custom mutator takes a `transaction` as its first arg * but the user does not provide this arg when calling the mutator. * * This utility strips the `tx` arg from the user's custom mutator signatures. */ export type MakeCustomMutatorInterfaces = { readonly [NamespaceOrName in keyof MD]: MD[NamespaceOrName] extends (tx: Transaction, ...args: infer Args) => Promise ? (...args: Args) => MutatorResult : { readonly [P in keyof MD[NamespaceOrName]]: MakeCustomMutatorInterface; }; }; export type MakeCustomMutatorInterface = F extends (tx: ClientTransaction, ...args: infer Args) => Promise ? (...args: Args) => MutatorResult : never; export declare class TransactionImpl implements ClientTransaction { constructor(lc: ZeroLogContext, repTx: WriteTransaction, schema: S); readonly clientID: ClientID; readonly mutationID: number; readonly reason: 'optimistic' | 'rebase'; readonly location = "client"; readonly mutate: SchemaCRUD; readonly query: SchemaQuery; readonly token: string | undefined; } export declare function makeReplicacheMutator(lc: ZeroLogContext, mutator: CustomMutatorImpl, schema: S): (repTx: WriteTransaction, args: ReadonlyJSONValue) => Promise; //# sourceMappingURL=custom.d.ts.map