UNPKG

@whook/whook

Version:

Build strong and efficient REST web services.

46 lines (45 loc) 3.21 kB
import { type LogService } from 'common-services'; import { type ValidateFunction } from 'ajv'; import { type OpenAPIParameter, type OpenAPIExtension, type OpenAPI, type OpenAPISecurityScheme, type OpenAPIReference } from 'ya-open-api-types'; import { type WhookCoercionOptions } from './coercion.js'; import { JSONSchema, type ExpressiveJSONSchema } from 'ya-json-schema-types'; import { type WhookSchemaValidatorsService } from '../services/schemaValidators.js'; import { type WhookRequestBody } from '../types/http.js'; import { type WhookOpenAPIOperation, type WhookOpenAPI, type WhookSupportedParameter } from '../types/openapi.js'; export type WhookBodyValidator = (operation: WhookOpenAPIOperation, contentType: string, body: WhookRequestBody | void) => void; export declare function prepareBodyValidator({ API, schemaValidators, }: { API: OpenAPI; schemaValidators: WhookSchemaValidatorsService; }, operation: WhookOpenAPIOperation): Promise<WhookBodyValidator>; export declare function extractOperationSecurityParameters({ API }: { API: WhookOpenAPI; }, operation: WhookOpenAPIOperation): Promise<WhookSupportedParameter[]>; export declare function pickupOperationSecuritySchemes({ API }: { API: WhookOpenAPI; }, operation: WhookOpenAPIOperation): Promise<{ [name: string]: OpenAPISecurityScheme<OpenAPIExtension>; }>; export declare function extractParametersFromSecuritySchemes(securitySchemes: OpenAPISecurityScheme<OpenAPIExtension>[]): WhookSupportedParameter[]; export declare function resolveParameters({ API, log, }: { API: WhookOpenAPI; log?: LogService; }, parameters: (OpenAPIParameter<ExpressiveJSONSchema, OpenAPIExtension> | OpenAPIReference<OpenAPIParameter<ExpressiveJSONSchema, OpenAPIExtension>>)[]): Promise<WhookSupportedParameter[]>; export type WhookParameterValue = boolean | boolean[] | string | string[] | number | number[] | undefined; export type WhookParameterCaster = (str: string) => WhookParameterValue; export type WhookParameterValidator = (str: string | undefined) => WhookParameterValue; export type WhookParametersValidators = Record<'query' | 'header' | 'path' | 'cookie', Record<string, WhookParameterValidator>>; export declare function getCasterForSchema({ API, COERCION_OPTIONS, }: { API: WhookOpenAPI; COERCION_OPTIONS: WhookCoercionOptions; }, schema: JSONSchema): Promise<WhookParameterCaster>; export declare function createParameterValidator({ API, COERCION_OPTIONS, schemaValidators, }: { API: WhookOpenAPI; COERCION_OPTIONS: WhookCoercionOptions; schemaValidators: WhookSchemaValidatorsService; }, parameter: WhookSupportedParameter): Promise<WhookParameterValidator>; export declare function createParametersValidators({ API, COERCION_OPTIONS, schemaValidators, }: { API: WhookOpenAPI; COERCION_OPTIONS: WhookCoercionOptions; schemaValidators: WhookSchemaValidatorsService; }, parameters: WhookSupportedParameter[]): Promise<WhookParametersValidators>; export declare function validateParameter(parameter: OpenAPIParameter<ExpressiveJSONSchema, OpenAPIExtension>, caster: WhookParameterCaster | undefined, validator: ValidateFunction, str: string | undefined): WhookParameterValue | undefined;