import type { NextFunction, Request, Response } from "express"; import type { ParamsDictionary } from "express-serve-static-core"; import type { ValidationChain } from "express-validator"; import type { Middleware } from "express-validator/src/base"; import type { ModelNames, ParamNames } from "./models"; import type { ABACActions, ABACModels } from "./permission"; export type SwaggerParameterSchema = { title?: string; description?: string | string[]; name?: string; type?: SwaggerDataTypes | `${SwaggerBaseDataTypes}${SwaggerTypeOperators}`; $ref?: string; properties?: SwaggerSchemaProperties; items?: SwaggerSchemaItemType; required?: string[]; additionalProperties?: boolean | SwaggerSchemaProperties; example?: string; enum?: readonly string[]; }; export type SwaggerParameter = { name?: string; in?: string; required?: boolean; $ref?: ParamNames; explode?: boolean; content?: { [y in SwaggerContentType]?: { schema: SwaggerSchemaProperties[keyof SwaggerSchemaProperties]; }; }; schema?: undefined; } | { name?: string; in?: string; required?: boolean; $ref?: ParamNames; explode?: boolean; content?: undefined; schema?: SwaggerSchemaProperties[keyof SwaggerSchemaProperties]; }; export type SwaggerSchemaItemType = SwaggerDataTypes | SwaggerSchemaItems; export interface SwaggerSchemaItems { type?: SwaggerDataTypes | `${SwaggerBaseDataTypes}${SwaggerTypeOperators}`; properties?: SwaggerSchemaProperties; $ref?: string; format?: string; enum?: readonly string[]; title?: string; nullable?: boolean; items?: SwaggerSchemaItemType; isPopulation?: boolean; } export type SwaggerContentType = "application/json" | "multipart/form-data" | "application/pdf"; export type SwaggerSchemaType = { title?: string; description?: string | string[]; name?: string; format?: string; type?: SwaggerDataTypes | `${SwaggerBaseDataTypes}${SwaggerTypeOperators}`; $ref?: string; properties?: SwaggerSchemaProperties; items?: SwaggerSchemaItemType; required?: string[]; } | `@${ModelNames}` | `@${ModelNames}${SwaggerTypeOperators}${SwaggerTypeOperatorsArrays}` | `${SwaggerBaseDataTypes}` | `${SwaggerBaseDataTypes}${SwaggerTypeOperators}${SwaggerTypeOperatorsArrays}`; export interface SwaggerRequestBody { required?: boolean; description?: string | string[]; content: { [y in SwaggerContentType]?: { schema: SwaggerSchemaType; }; }; } export interface SwaggerResponses { [x: number]: Partial | SwaggerSchemaType; } type operationIdPatterns = `all${string}` | `get${string}ById` | `edit${string}` | `delete${string}` | `deleteAll${string}` | `create${string}` | `getMe` | `getMy${string}` | `login` | `register` | `logout` | `verifyEmail`; type adminOperationIdPatterns = `allAdmin${string}` | `getAdmin${string}ById` | `editAdmin${string}` | `getAdmin${string}` | `deleteAdmin${string}` | `deleteAllAdmin${string}` | `createAdmin${string}` | `adminLogin`; type SwaggerOptionsFlags = { deprecated?: boolean; }; export interface SwaggerOptions { operationId: operationIdPatterns | adminOperationIdPatterns | string; cache?: { key: `\`${string}\``; expiresInSeconds?: number; }; purgeKey?: `\`${string}\`` | `\`${string}\``[]; permission?: [ABACActions, ABACModels]; summary?: string; description?: string | string[]; parameters?: SwaggerParameter[]; responses?: SwaggerResponses; requestBody?: SwaggerRequestBody | SwaggerSchemaType; flags?: SwaggerOptionsFlags; } type SwaggerShorthandOperators = "::" | "|"; type SwaggerBaseDataTypes = "string" | "number" | "integer" | "boolean" | "array" | "object" | "Date" | "ObjectId"; type SwaggerTypeOperators = "!" | "?" | ""; type SwaggerTypeOperatorsArrays = "" | "[]"; export type SwaggerDataTypes = `@${ModelNames}` | `@${ModelNames}${SwaggerTypeOperators}${SwaggerTypeOperatorsArrays}` | SwaggerBaseDataTypes | `${SwaggerBaseDataTypes}${SwaggerShorthandOperators}${SwaggerStringFormats | string}${SwaggerShorthandOperators}${string | SwaggerStringFormats}` | `${SwaggerBaseDataTypes}${SwaggerShorthandOperators}${SwaggerStringFormats | string}` | `${SwaggerBaseDataTypes}${SwaggerTypeOperators}${SwaggerShorthandOperators}${SwaggerStringFormats | string}${SwaggerShorthandOperators}${string | SwaggerStringFormats}` | `${SwaggerBaseDataTypes}${SwaggerTypeOperators}${SwaggerShorthandOperators}${SwaggerStringFormats | string}`; export type SwaggerDataTypesString = SwaggerDataTypes | `${SwaggerBaseDataTypes}${SwaggerTypeOperatorsArrays}${SwaggerTypeOperators}`; export type SwaggerStringFormats = "date" | "date-time" | "password" | "byte" | "binary"; export type SwaggerSchemaProperties = { [x: string]: ({ title?: string; format?: SwaggerStringFormats; example?: string; $ref?: string; enum?: readonly string[]; items?: SwaggerSchemaItemType; nullable?: boolean; minItems?: number; maxItems?: number; minLength?: number; maxLength?: number; pattern?: string; uniqueItems?: boolean; readOnly?: boolean; writeOnly?: boolean; minProperties?: number; maxProperties?: number; minimum?: number; maximum?: number; exclusiveMinimum?: boolean; exclusiveMaximum?: boolean; required?: string[]; isPopulation?: boolean; } & ({ type?: SwaggerDataTypes | `${SwaggerBaseDataTypes}${SwaggerTypeOperators}`; properties?: SwaggerSchemaProperties; additionalProperties?: boolean | SwaggerSchemaProperties; } | { type?: "object" | `object${SwaggerTypeOperators}`; properties?: undefined; additionalProperties: boolean | SwaggerSchemaProperties; } | { type?: "object" | `object${SwaggerTypeOperators}`; properties: SwaggerSchemaProperties; additionalProperties?: boolean | SwaggerSchemaProperties; })) | SwaggerDataTypesString; }; export type SwaggerSchema = { name: string; noTimestamps?: boolean; type?: undefined; properties: SwaggerSchemaProperties; nullable?: boolean; required?: string[]; } | { name: string; noTimestamps?: boolean; type: "string"; properties?: undefined; enum: readonly string[]; nullable?: boolean; required?: string[]; }; export interface SwaggerModel { modelName: string; schemas?: SwaggerSchema[]; parameters?: SwaggerParameter[]; } type ValidationType = ValidationChain | Middleware; export interface ApiService { paramName?: string; swaggerModel: SwaggerModel; _getValidation?: ValidationType[]; _postValidation?: ValidationType[]; _putValidation?: ValidationType[]; _optionsValidation?: ValidationType[]; _deleteValidation?: ValidationType[]; _patchValidation?: ValidationType[]; _headValidation?: ValidationType[]; _traceValidation?: ValidationType[]; _connectValidation?: ValidationType[]; _postMulter?: boolean; _patchMulter?: boolean; _putMulter?: boolean; _postMultipleMulter?: boolean; _patchMultipleMulter?: boolean; _putMultipleMulter?: boolean; _get?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _post?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _put?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _options?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _delete?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _patch?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _head?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _trace?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _connect?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _getSwagger?: Omit; _postSwagger?: SwaggerOptions; _putSwagger?: SwaggerOptions; _optionsSwagger?: SwaggerOptions; _deleteSwagger?: SwaggerOptions; _patchSwagger?: SwaggerOptions; _headSwagger?: SwaggerOptions; _traceSwagger?: SwaggerOptions; _connectSwagger?: SwaggerOptions; _getOverrideAuth?: Middleware; _postOverrideAuth?: Middleware; _putOverrideAuth?: Middleware; _patchOverrideAuth?: Middleware; _optionsOverrideAuth?: Middleware; _deleteOverrideAuth?: Middleware; _headOverrideAuth?: Middleware; _traceOverrideAuth?: Middleware; _connectOverrideAuth?: Middleware; } /** * Base request type used for the handler declarations on {@link BaseApiService}. * * The query generic is left as `any` (instead of Express's default `ParsedQs`) so * that the generated per-method request types — which may declare query parameters * as required (e.g. `{ companyVatNumber: string }` for a `required: true` query * param) — stay assignable when overriding these handlers. Express's `ParsedQs` * guarantees no keys, so a required query property would otherwise be reported as * incompatible in any contravariant position (strict property override, * `RequestHandler` assignment, etc.). */ type BaseHandlerRequest = Request; export declare abstract class BaseApiService { paramName: string; constructor(filename: string); getParamFrom(req: Request): string; swaggerModel: SwaggerModel; _getValidation?: ValidationType[]; _postValidation?: ValidationType[]; _putValidation?: ValidationType[]; _optionsValidation?: ValidationType[]; _deleteValidation?: ValidationType[]; _patchValidation?: ValidationType[]; _headValidation?: ValidationType[]; _traceValidation?: ValidationType[]; _connectValidation?: ValidationType[]; _postMulter?: boolean; _patchMulter?: boolean; _putMulter?: boolean; _postMultipleMulter?: boolean; _patchMultipleMulter?: boolean; _putMultipleMulter?: boolean; _get?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _post?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _put?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _options?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _delete?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _patch?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _head?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _trace?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _connect?(req: BaseHandlerRequest, res: Response, next: NextFunction): any; _getSwagger?: Omit; _postSwagger?: SwaggerOptions; _putSwagger?: SwaggerOptions; _optionsSwagger?: SwaggerOptions; _deleteSwagger?: SwaggerOptions; _patchSwagger?: SwaggerOptions; _headSwagger?: SwaggerOptions; _traceSwagger?: SwaggerOptions; _connectSwagger?: SwaggerOptions; _getOverrideAuth?: Middleware; _postOverrideAuth?: Middleware; _putOverrideAuth?: Middleware; _patchOverrideAuth?: Middleware; _optionsOverrideAuth?: Middleware; _deleteOverrideAuth?: Middleware; _headOverrideAuth?: Middleware; _traceOverrideAuth?: Middleware; _connectOverrideAuth?: Middleware; } export type SwaggerFormats = { [key: string]: { example: any; }; }; export type OpenApiDocument = { openapi: string; info: { title: string; version: string; }; tags: { name: string; }[]; components: { schemas: { [key: string]: any; }; parameters: { [key: string]: any; }; }; paths: { [key: string]: any; }; }; export {};