@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
30 lines (29 loc) • 1.39 kB
TypeScript
import { Struct } from './Struct';
import { FetchOptions, Gateway } from '../types/Gateway';
import { Repository } from '../types/Repository';
import { Constructor } from '../types/Constructor';
import { Json, JsonValue } from '../types/Json';
import { PageList } from '../types/PageList';
import { Id, Key } from '../types/Id';
import { List } from '../types/List';
export type RepoAction = 'add' | 'update' | 'remove';
export declare class Repo<T extends Struct, Options = FetchOptions> extends Repository<T, Options> {
protected ctor: Constructor<T>;
private readonly gateway;
constructor(ctor: Constructor<T>, gateway: Gateway<Options>);
create: (item: T | Json) => T;
all(options?: Options): Promise<PageList<T>>;
byId(id: Id): Promise<T>;
byIds(...ids: Id[]): Promise<List<T>>;
byKey(key: Key, options?: Options): Promise<PageList<T>>;
by(key: keyof T, value: JsonValue, options?: Options): Promise<PageList<T>>;
search(q: JsonValue, options?: Options): Promise<PageList<T>>;
filter(options?: Options): Promise<PageList<T>>;
exists(id: Id): Promise<boolean>;
add(t: T | Json): Promise<T>;
update(id: Id, json: Json): Promise<T>;
remove(id: Id): Promise<boolean>;
extend(item: T, _action?: RepoAction): Promise<T>;
validate(item: T, _action?: RepoAction): Promise<T>;
upsert(id: Id, item: Json): Promise<T>;
}