import { Operator } from "./enums"; import type { Patch, State } from "./messages"; /** * EXPERIMENTAL FEATURE - This is a work in progress and subject to change! * * Looking for a simple interface to store and query projections */ /** * A state with a required unique id */ export type Projection = S & { id: string; }; /** * A partial state applied to a record id or a filter */ export type ProjectionPatch = Readonly & ({ id: string; } | { where: ProjectionWhere; })>; /** * A map of projection patches * - `records` patched records by id (inserts, updates, or deletes) * - `updates` patched updates by filter * - `deletes` patched deletes by filter */ export type ProjectionMap = { records: Map>; updates: ProjectionPatch[]; deletes: ProjectionWhere[]; }; /** * *** STORE SECTION *** */ /** * Projection Record * * Stored/cached/materialized `state` after projecting/reducing events * from the stream following specific `Projector` logic * * - `state` the stored state with a unique identifier `id` * - `watermark` the last projected event id */ export type ProjectionRecord = { readonly state: Projection; readonly watermark: number; }; /** * Projection Results * * The results after a `Projection Store` tries to commit the projection records in a `Projection` * * - `upserted` upserted records * - `deleted` deleted records * - `watermark` the new watermark stored in upserted records * - `error?` error message if commit fails */ export type ProjectionResults = { readonly upserted: number; readonly deleted: number; readonly watermark: number; readonly error?: string; }; /** * *** QUERY SECTION *** */ /** * Filter condition. Uses scalar value as a shortcut to eq operator */ export type Condition = { readonly [K in Operator]?: T; } | Readonly; /** * Projection filter expression by fields in record */ export type ProjectionWhere = { readonly [K in keyof Projection]?: Condition>; }; /** * Projection sort expression by fields in record */ export type ProjectionSort = { readonly [K in keyof Projection]?: "asc" | "desc"; }; /** * Projection query options * - `select?` selected fields in projection record * - `where?` filtered fields in projection record (should be indexed) * - `sort?` sorted fields (should be indexed) (combined with limit) * - `limit?` max number of records */ export type ProjectionQuery = { readonly select?: Array>>; readonly where?: ProjectionWhere; readonly sort?: ProjectionSort; readonly limit?: number; }; /** * REST projection query options */ export type RestProjectionQuery = { ids?: string[]; select?: string[]; where?: string[]; sort?: string[]; limit?: number; }; /** * Supported aggregate functions */ export type Agg = "count" | "sum" | "avg" | "min" | "max"; /** * Aggregate query options * - `select` aggregated fields * - `where?` filtered fields in projection record (should be indexed) */ export type AggQuery = { readonly select: { readonly [K in keyof S]?: Agg[]; }; readonly where?: ProjectionWhere; }; /** * REST aggregate query options */ export type RestAggQuery = { select?: string[]; where?: string[]; }; /** * Aggregate results */ export type AggResult = { readonly [K in keyof S]?: Partial>; }; //# sourceMappingURL=projection.d.ts.map