@fjell/lib
Version:
Server-side Library for Fjell
50 lines (49 loc) • 4.44 kB
TypeScript
import { ComKey, Item, LocKeyArray, PriKey } from "@fjell/core";
export interface ActionMethod<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
(item: V, actionParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>): Promise<V>;
}
export interface AllActionMethod<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
(allActionParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<V[]>;
}
export interface FacetMethod<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
(item: V, facetParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>): Promise<any>;
}
export interface AllFacetMethod<L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
(allFacetParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<any>;
}
export type FinderParams = Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>;
export type FinderMethod<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = (params: FinderParams, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []) => Promise<V[]>;
export interface Options<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
hooks?: {
preCreate?: (item: Partial<Item<S, L1, L2, L3, L4, L5>>, options?: {
key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>;
locations?: never;
} | {
key?: never;
locations: LocKeyArray<L1, L2, L3, L4, L5>;
}) => Promise<Partial<Item<S, L1, L2, L3, L4, L5>>>;
postCreate?: (item: V) => Promise<V>;
preUpdate?: (key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>, item: Partial<Item<S, L1, L2, L3, L4, L5>>) => Promise<Partial<Item<S, L1, L2, L3, L4, L5>>>;
postUpdate?: (item: V) => Promise<V>;
preRemove?: (key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>) => Promise<Partial<Item<S, L1, L2, L3, L4, L5>>>;
postRemove?: (item: V) => Promise<V>;
};
validators?: {
onCreate?: (item: Partial<Item<S, L1, L2, L3, L4, L5>>, options?: {
key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>;
locations?: never;
} | {
key?: never;
locations: LocKeyArray<L1, L2, L3, L4, L5>;
}) => Promise<boolean>;
onUpdate?: (key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>, item: Partial<Item<S, L1, L2, L3, L4, L5>>) => Promise<boolean>;
onRemove?: (key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>) => Promise<boolean>;
};
finders?: Record<string, FinderMethod<V, S, L1, L2, L3, L4, L5>>;
actions?: Record<string, ActionMethod<V, S, L1, L2, L3, L4, L5>>;
facets?: Record<string, FacetMethod<V, S, L1, L2, L3, L4, L5>>;
allActions?: Record<string, AllActionMethod<V, S, L1, L2, L3, L4, L5>>;
allFacets?: Record<string, AllFacetMethod<L1, L2, L3, L4, L5>>;
}
export declare const createDefaultOptions: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>() => Options<V, S, L1, L2, L3, L4, L5>;
export declare const createOptions: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(options?: Options<V, S, L1, L2, L3, L4, L5>) => Options<V, S, L1, L2, L3, L4, L5>;