import * as Domain from "../../../domain"; import type { Model } from "../../models"; import type { Pluto } from "../../Pluto"; import { Query } from "../../types"; export type OptionalId = Omit & { uuid?: string; }; export type WithId = T & Required; /** * @class BaseRepository * * Encapsulate the functionality for interacting with the Store */ export declare abstract class BaseRepository { private readonly store; protected readonly name: string; /** * Allows setting of properties to be present in all Models sent to Store */ protected baseModel: Partial; constructor(store: Pluto.Store, name: string); /** * Persist the Model in the Store. * * @param model * @returns {T} * @throws {@link StoreInsertError} if insert fails * @throws {@link StoreUUIDNotReturned} if UUID not returned */ insert(model: T): Promise; update(model: T): Promise; delete(uuid: string): Promise; /** * Search the Store for Models * * @param query a Query object, a set of values and operators defining the query * @see ../types.ts * * @example * search for a model with uuid and name * ```ts * repo.getModels({ selector: { uuid: "1", name: "eg" }}) * ``` * @example * search for models with uuid of 1 or 2 * ```ts * repo.getModels({ selector: { $or: [{ uuid: "1" }, { uuid: "2" }] }}) * ``` * @example * search for all models * ```ts * repo.getModels() * ``` * * @returns {T[]} Array of matched Models * @throws {@link StoreQueryFailed} if the query fails */ getModels(query?: Query): Promise; /** * Handle internal logic for running a query * * @param builder * @returns {T[]} * @throws {@link StoreQueryFailed} */ private runQuery; /** * Create the query to run from the given query and baseQuery * * @param query * @returns */ private makeMangoQuery; /** * Add the UUID to a Storable and return * * @param {Storable} obj * @param {string} uuid * @returns {T} */ protected withId(obj: X, uuid: string): WithId; }