@fjell/lib
Version:
Server-side Library for Fjell
38 lines (37 loc) • 2.99 kB
TypeScript
import { ActionMethod, AllActionMethod, AllFacetMethod, CreateOptions, FacetMethod, FinderMethod, OperationParams } from "@fjell/types";
import { ComKey, Item, PriKey } from "@fjell/types";
import type { SchemaValidator } from "@fjell/validation";
import { AggregationDefinition, ReferenceDefinition } from "./processing";
export type { FinderMethod, ActionMethod, AllActionMethod, FacetMethod, AllFacetMethod, OperationParams, CreateOptions };
export type FinderParams = OperationParams;
export type { SchemaValidator };
export interface ValidationOptions<V> {
schema?: SchemaValidator<V>;
updateSchema?: SchemaValidator<Partial<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?: CreateOptions<S, 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>;
onChange?: (originalItem: V, updatedItem: V) => Promise<void> | void;
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?: CreateOptions<S, 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>>;
references?: ReferenceDefinition[];
aggregations?: AggregationDefinition[];
validation?: ValidationOptions<V>;
}
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>;