import { applyParams, type Params } from "./params.ts"; export interface Query { where(entry: Shape): boolean; } export interface StrictQuery< Shape, Strict extends boolean = true, > extends Query { /** @default true */ strict?: Strict; } export function assertStrict( query: StrictQuery, entry?: Shape, ): Shape | null { if (entry) return entry; // strict mode is the default if (query.strict !== false) { throw new TypeError( "No entry found in the collection for the given strict query.", ); } return null; } type DataOrUpdateFn = Params | ((entry: Shape) => Params); export interface UpdateQuery< Shape, Strict extends boolean = true, > extends StrictQuery { data: DataOrUpdateFn; } export function applyUpdateQuery( entry: Shape, query: UpdateQuery, ): Shape { const update = typeof query.data === "function" ? query.data(entry) : query.data; return applyParams(entry, update); }