UNPKG

@fusions/core

Version:

203 lines (202 loc) 5.08 kB
export interface IConfig { name: string; secret: string; domain: string; cors?: boolean; } export interface IModels { [key: string]: IModelActive; } export interface IModel { name: string; prototype: any; scopes: IScope; struct: IStruct; endpoints: IEndpoints; new (props: IProps): IModelActive; } export interface IModelActive { name: string; scopes: IScope; struct: IStructActive; endpoints: IEndpointsActive; hooksToSet: IHookToSet[]; setHooks: (hooksToSet: IHookToSet[]) => void; toSource?: () => string; 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 | 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[]; params?: string[]; external?: { from: [string, string]; as: string; }[]; } export interface IHookToSet { toSetAt: [string, string]; matchOn: [string, string]; from: [string, string]; to: [string, string]; function?: string[]; params?: string[]; external?: { from: [string, string]; as: string; }[]; } export interface IEndpoints { [key: string]: [string, (request: IRequest, response: IResponse) => IResponse | Promise<IResponse>, IStruct?]; } export interface IEndpointsActive { [key: string]: [string, (request: IRequest, response: IResponse) => IResponse | Promise<IResponse>, IStructActive?]; } export interface IProps { name: string; scopes: IScope; models: IModel[]; endpoints: IEndpoints; struct: IStruct; } 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; messenger: 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; }; cookies: { [key: string]: string; }; query: { fields: { [key: string]: string | number | boolean | { [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; usagePlan: string | null; app: string; role: string; sri: string; permission: string; allowedFields: { read: string | string[]; write: string | string[]; }; iss: string; exp: number; } | null; apiKey: 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; }