arrest
Version:
OpenAPI v3 compliant REST framework for Node.js, with support for MongoDB and JSON-Schema
43 lines (42 loc) • 2.35 kB
TypeScript
import { Ability, AnyMongoAbility } from '@casl/ability';
import { Scopes } from '@vivocha/scopes';
import { NextFunction, RequestHandler, Router } from 'express';
import { OpenAPIV3 } from 'openapi-police';
import { API } from './api.js';
import { Resource } from './resource.js';
import { APIRequest, APIRequestHandler, APIResponse, Method } from './types.js';
export declare abstract class Operation {
resource: Resource;
path: string;
method: Method;
info: OpenAPIV3.OperationObject;
api: API;
internalId: string;
scopes: Scopes;
constructor(resource: Resource, path: string, method: Method, id?: string, opts?: any);
get swaggerPath(): string;
get swaggerScopes(): OpenAPIV3.OAuth2SecurityScopes;
protected getInfo(opts?: any): OpenAPIV3.OperationObject;
protected getDefaultInfo(opts?: any): OpenAPIV3.OperationObject;
protected getCustomInfo(opts?: any): OpenAPIV3.OperationObject;
protected createParameterValidators(key: string, parameters: OpenAPIV3.ParameterObject[]): APIRequestHandler;
protected createJSONParser(type?: string | string[]): RequestHandler;
protected createUrlencodedParser(): RequestHandler;
protected createBodyValidators(): undefined | APIRequestHandler[];
protected createBodyValidator(type: string, bodySpec: OpenAPIV3.MediaTypeObject, required?: boolean): APIRequestHandler;
protected useSecurityValidator(): boolean;
protected securityValidator(req: APIRequest, res: APIResponse, next: NextFunction): void;
protected errorHandler(err: any, req: APIRequest, res: APIResponse, next: NextFunction): void;
attach(api: API): void;
router(router: Router): Promise<Router>;
abstract handler(req: APIRequest, res: APIResponse, next?: NextFunction): any;
checkAbility(ability: Ability, data?: any, filterFields?: boolean, filterData?: boolean): any;
checkAbilityForPath(ability: Ability, path: string): boolean;
filterFields(ability: Ability, data: any): any;
permittedFields(ability: AnyMongoAbility): Set<string>;
}
export declare class SimpleOperation extends Operation {
protected customHandler: APIRequestHandler;
constructor(customHandler: APIRequestHandler, resource: Resource, path: string, method: Method, id?: string);
handler(req: APIRequest, res: APIResponse, next?: NextFunction): void;
}