UNPKG

@furystack/repository

Version:

Repository implementation for FuryStack

73 lines 2.92 kB
import type { CreateResult, FilterType, FindOptions, PartialResult, WithOptionalId } from '@furystack/core'; import type { Injector } from '@furystack/inject'; import { EventHub } from '@furystack/utils'; import type { DataSetSettings } from './data-set-setting.js'; /** * An authorized Repository Store instance */ export declare class DataSet<T, TPrimaryKey extends keyof T, TWritableData = WithOptionalId<T, TPrimaryKey>> extends EventHub<{ onEntityAdded: { injector: Injector; entity: T; }; onEntityUpdated: { injector: Injector; id: T[TPrimaryKey]; change: Partial<T>; }; onEntityRemoved: { injector: Injector; key: T[TPrimaryKey]; }; }> implements Disposable { readonly settings: DataSetSettings<T, TPrimaryKey, TWritableData>; /** * Primary key of the contained entity */ primaryKey: TPrimaryKey; /** * Adds an entity to the DataSet * @param injector The injector from the context * @param entities The entities to add * @returns The CreateResult with the created entities */ add(injector: Injector, ...entities: TWritableData[]): Promise<CreateResult<T>>; /** * Updates an entity in the store * @param injector The injector from the context * @param id The identifier of the entity * @param change The update */ update(injector: Injector, id: T[TPrimaryKey], change: Partial<T>): Promise<void>; /** * Returns a Promise with the entity count * @param injector The Injector from the context * @param filter The Filter that will be applied * @returns the Count */ count(injector: Injector, filter?: FilterType<T>): Promise<number>; /** * Returns a filtered subset of the entity * @param injector The Injector from the context * @param filter The Filter definition * @returns A result with the current items */ find<TFields extends Array<keyof T>>(injector: Injector, filter: FindOptions<T, TFields>): Promise<Array<PartialResult<T, TFields>>>; /** * Returns an entity based on its primary key * @param injector The injector from the context * @param key The identifier of the entity * @param select A field list used for projection * @returns An item with the current unique key or Undefined */ get(injector: Injector, key: T[TPrimaryKey], select?: Array<keyof T>): Promise<PartialResult<T, (keyof T)[]> | undefined>; /** * Removes an entity based on its primary key * @param injector The Injector from the context * @param key The primary key * @returns A promise that will be resolved / rejected based on the remove success */ remove(injector: Injector, key: T[TPrimaryKey]): Promise<void>; constructor(settings: DataSetSettings<T, TPrimaryKey, TWritableData>); } //# sourceMappingURL=data-set.d.ts.map