UNPKG

@fusions/core

Version:

188 lines (187 loc) 4.58 kB
import Model from "./Model"; export interface IConfig { type: string; secret: string; } export interface IModels { [key: string]: IModelActive; } export interface IModel { name: string; prototype: any; scopes: IScope; struct: IStruct; endpoints: IEndpoints; new (props: { name: string; scopes: IScope; struct: IStruct; endpoints: IEndpoints; models: IModel[]; }): IModelActive; } export interface IModelActive extends Model { name: string; scopes: IScope; struct: IStructActive; endpoints: IEndpoints; onAccess?(request: IRequest, response: IResponse, guard: () => void): { request: IRequest; response: IResponse; }; onValidation?(request: IRequest, response: IResponse, validator: () => void): { request: IRequest; response: IResponse; }; onRender?(request: IRequest, response: IResponse, renderer: () => void): { request: IRequest; response: IResponse; }; } export interface IScope { [key: string]: string | string[]; } export interface IStruct { [key: string]: string | { key?: boolean; primary?: boolean; required?: boolean; immutable?: boolean; options?: { [key: string]: any; }; type: string; struct: IStruct; }; } export interface IStructActive { [key: string]: IStructDefinition; } export interface IStructDefinition { key: boolean; primary: boolean; required: boolean; immutable: boolean; options: { [key: string]: any; }; hooks: IHook[]; pointer: string | null; type: string; struct: IStructActive | null; sourceField?: string; } export interface IHook { matchOn: [string, string]; from: [string, string]; to: [string, string]; function?: string[]; external?: { from: [string, string]; as: string; }[]; } export interface IHookToSet { toSetAt: [string, string]; matchOn: [string, string]; from: [string, string]; to: [string, string]; function?: string[]; external?: { from: [string, string]; as: string; }[]; } export interface IEndpoints { [key: string]: [string, ((request: IRequest, response: IResponse) => IResponse | Promise<IResponse>)]; } export interface IProps { scopes: IScope; struct: IStruct; endpoints: IEndpoints; } export interface IPackages { parser: (request: any, response: any) => { request: IRequest; response: IResponse; } | Promise<{ request: IRequest; response: IResponse; }>; guard: (request: IRequest, response: IResponse, config: IConfig, model: IModelActive) => { request: IRequest; response: IResponse; } | Promise<{ request: IRequest; response: IResponse; }>; validator: (request: IRequest, response: IResponse, config: IConfig, model: IModelActive, models: IModels) => { request: IRequest; response: IResponse; } | Promise<{ request: IRequest; response: IResponse; }>; database: any | null; renderer: (request: IRequest | null, response: IResponse, config?: IConfig, model?: IModelActive) => IResponse | Promise<IResponse>; } export interface IRequest { method: string; path: string; model: string | null; endpoint: string; headers: { [key: string]: string; }; query: { fields: { [key: string]: string | number | { [key: string]: string | number; } | string[]; }; projection: string[]; limit: number; sorting: { field: string; direction: string; } | null; start: string | null; } | null; body: any; scope: { user: string | null; pool: string | null; app: string; role: string; sri: string; permission: string; iss: string; } | null; connection: { ip: string | null; port: string | null; }; } export interface IResponse { statusCode: number; headers: { [key: string]: string; }; body: any; } export interface IRoutes { [key: string]: { name: string; endpoint: string; }; } export interface IError extends Error { errors?: { [key: string]: string | { [key: string]: string; }; }; } export interface IRequestHandler { (input: any, output: any): any; }