UNPKG

@whook/whook

Version:

Build strong and efficient REST web services.

49 lines (48 loc) 1.85 kB
import { type ValidateFunction } from 'ajv/dist/2020.js'; import { type LogService } from 'common-services'; import { type AppEnvVars } from 'application-services'; import { type OpenAPIReference, type OpenAPI } from 'ya-open-api-types'; import { type ExpressiveJSONSchema, type JSONSchema } from 'ya-json-schema-types'; export declare const DEFAULT_SCHEMA_VALIDATORS_OPTIONS: { readonly lazy: false; readonly dedupe: false; readonly hashLength: 16; readonly buildSchemas: false; }; /** Options for schema validation */ export interface WhookSchemaValidatorsOptions { /** Compile only at first validation */ lazy: boolean; /** * Dedupe schemas based on their JSON representation * to reduce the amount of compiled validations functions */ dedupe: boolean; /** * Size of the shake256 hash for deduping */ hashLength: number; /** * Wether schemas will be built or not */ buildSchemas: boolean; } export interface WhookSchemaValidatorsConfig { DEBUG_NODE_ENVS: string[]; SCHEMA_VALIDATORS_OPTIONS?: WhookSchemaValidatorsOptions; } export type WhookSchemaValidatorsDependencies = WhookSchemaValidatorsConfig & { API: OpenAPI; ENV: AppEnvVars; log?: LogService; }; export type WhookSchemaValidatorsService = (schema: JSONSchema | ExpressiveJSONSchema | OpenAPIReference<ExpressiveJSONSchema>) => ValidateFunction; declare const _default: import("knifecycle").ServiceInitializer<WhookSchemaValidatorsDependencies, WhookSchemaValidatorsService>; export default _default; export declare function buildSchemaValidatorsMap({ DEBUG_NODE_ENVS, SCHEMA_VALIDATORS_OPTIONS, API, ENV, log, }: { DEBUG_NODE_ENVS: string[]; SCHEMA_VALIDATORS_OPTIONS: WhookSchemaValidatorsOptions; API: OpenAPI; ENV: AppEnvVars; log: LogService; }): Promise<string>;