import { TablesRelationalConfig } from "drizzle-orm"; import { PostgresJsDatabase, PostgresJsTransaction } from "drizzle-orm/postgres-js"; import { DbOrTx, GenericEventBase, GenericEventsTable, GenericProjectionsTable, InputOf } from "./schemaHelpers"; import { ObjectWithOnlyStringOrNumberValuesOrArrayValues } from "./utils"; import { PgInsertValue, PgUpdateSetSource } from "drizzle-orm/pg-core"; export type EventClient = any, J extends Record = any, K extends TablesRelationalConfig = any, Db extends PostgresJsDatabase = any> = { readonly saveEvent: (eventInput: InputOf, tx?: PostgresJsTransaction) => Promise; readonly saveEvents: >(eventInputs: T[], tx?: DbOrTx) => Promise<(Events & { type: EventType; })[]>; readonly getLatestEvent: (eventType: EventType, options?: EventQueryOptions) => Promise; readonly getEventStream: (eventTypes: T[], options?: EventQueryOptions) => Promise<(Events & { type: T; })[]>; readonly getEventStreams: (streams: { eventTypes: T[]; options?: EventQueryOptions; }[]) => Promise<(Events & { type: T; })[]>; readonly saveProjection: (params: { type: string; id: string; data: Record; latestEventId: string; forceUpdate?: boolean; } & PgInsertValue & PgUpdateSetSource) => Promise<{ id: string; data: unknown; type: string; latestEventId: string; status: "created" | "updated" | "skipped"; }>; readonly forceUpdateProjection: (params: Parameters[0]) => Promise<{ id: string; data: unknown; type: string; latestEventId: string; status: "created" | "updated" | "skipped"; }>; readonly conditionalUpdateProjection: (params: Parameters[0]) => Promise<{ id: string; data: unknown; type: string; latestEventId: string; status: "created" | "updated" | "skipped"; }>; readonly getProjection: (params: { type: string; id: string; }) => Promise<{ data: T; latestEventId: string; } | undefined>; readonly queryProjections: Promise>; }>(params: { type: string; data?: Partial>>; }) => Promise<{ data: Awaited>; latestEventId: string; }[]>; readonly saveEventWithStreamValidation: (eventInput: InputOf, latestEventId: string, streams: StreamDefinition[]) => Promise; }; /** This is a utility type that helps to get type safety and autocomplete for the data field in the query options. */ type EventQueryOptions, D extends DbOrTx> = DbOrTx>> = { /** The id of the event after which to query. */ after?: string; /** The data to filter the events by. If an array is provided, the events will be filtered as if * any one of the values in the array matches. Only string and number values are supported. */ data?: Partial>; tx?: D; }; type StreamDefinition> = { types: T[]; identifier: Partial>; }; export declare function createEventClient, J extends Record, K extends TablesRelationalConfig, Db extends PostgresJsDatabase>>(db: DbOrTx, events: GenericEventsTable, projections: GenericProjectionsTable, ulidGenerator?: import("ulidx").ULIDFactory): { readonly saveEvent: (eventInput: InputOf, tx?: PostgresJsTransaction) => Promise; readonly saveEvents: >(eventInputs: T[], tx?: DbOrTx) => Promise<(Events & { type: EventType; })[]>; readonly getLatestEvent: (eventType: EventType, options?: EventQueryOptions) => Promise; readonly getEventStream: (eventTypes: T[], options?: EventQueryOptions) => Promise<(Events & { type: T; })[]>; readonly getEventStreams: (streams: { eventTypes: T[]; options?: EventQueryOptions; }[]) => Promise<(Events & { type: T; })[]>; /** * Save a projection to the database. If the projection already exists, * it will be updated as long as the incoming latestEventId * is greater than the current latestEventId. If the projection * does not exist, it will be created. A projection will be returned * regardless of whether it was updated or created, but the * `updated` field will be false if the projection already exists and * the incoming latestEventId was not greater than the current * latestEventId. */ readonly saveProjection: (params: { type: string; id: string; data: Record; latestEventId: string; forceUpdate?: boolean; } & PgInsertValue & PgUpdateSetSource) => Promise<{ status: "created" | "updated" | "skipped"; type: string; id: string; data: unknown; latestEventId: string; }>; readonly forceUpdateProjection: (params: Parameters[0]) => Promise<{ status: "created" | "updated" | "skipped"; type: string; id: string; data: unknown; latestEventId: string; }>; readonly conditionalUpdateProjection: (params: Parameters[0]) => Promise<{ status: "created" | "updated" | "skipped"; type: string; id: string; data: unknown; latestEventId: string; }>; readonly getProjection: (params: { type: string; id: string; }) => Promise<{ data: T; latestEventId: string; } | undefined>; readonly queryProjections: Promise>; }>(params: { type: string; data?: Partial>>; }) => Promise<{ data: Awaited>; latestEventId: string; }[]>; readonly saveEventWithStreamValidation: (eventInput: InputOf, latestEventId: string, streams: StreamDefinition[]) => Promise; }; export {};