UNPKG

@whook/whook

Version:

Build strong and efficient REST web services.

50 lines (49 loc) 2.86 kB
import { type Dependencies, type ServiceInitializer, type ProviderInitializer } from 'knifecycle'; import { type JsonValue } from 'type-fest'; import { type BaseJSONSchema, type ArrayJSONSchema, type BooleanJSONSchema, type NullJSONSchema, type NumericJSONSchema, type TextJSONSchema, type ValueOnlyJSONSchema } from 'ya-json-schema-types'; import { type OpenAPIReference } from 'ya-open-api-types'; import { type WhookEnvironmentsConfig } from '../libs/environments.js'; export declare const DEFAULT_COMMAND_CONFIG: WhookCommandConfig; export type WhookBaseCommandConfig = { environments?: WhookEnvironmentsConfig; promptArgs?: boolean; targetHandler?: string; }; export type WhookCommandSchema = NullJSONSchema | (BaseJSONSchema & (ValueOnlyJSONSchema<'null' | 'boolean' | 'number' | 'integer' | 'string'> | TextJSONSchema | NumericJSONSchema | BooleanJSONSchema | ArrayJSONSchema<'null' | 'boolean' | 'number' | 'integer' | 'string'>)); export interface WhookCommandArgumentDefinition<T extends JsonValue | void | unknown = unknown> { name: string; description: string; required?: boolean; schema: WhookCommandSchema | OpenAPIReference<WhookCommandSchema>; example?: T; } export interface WhookCommandConfig extends WhookBaseCommandConfig { } export type WhookCommandDefinition = { name: string; description: string; example: string; arguments: WhookCommandArgumentDefinition[]; config?: WhookCommandConfig; }; export type WhookArgsTypes = string | boolean | number; export type WhookCommandArgs<T extends Record<string, WhookArgsTypes> = Record<string, WhookArgsTypes>> = { namedArguments: T; rest: string[]; command: string; }; export interface WhookCommandHandler<T extends Record<string, WhookArgsTypes> = Record<string, WhookArgsTypes>, D extends WhookCommandDefinition = WhookCommandDefinition> { (args: WhookCommandArgs<T>, definition?: D): Promise<void>; } export type WhookCommandInitializer<T extends Record<string, WhookArgsTypes>, D extends Dependencies = Record<string, WhookArgsTypes>> = ServiceInitializer<D, WhookCommandHandler<T>> | ProviderInitializer<D, WhookCommandHandler<T>>; export declare const COMMAND_ASIDE_COMPONENTS_SUFFIXES: readonly ["Schema"]; export declare const COMMAND_ASIDE_COMPONENTS_PROPERTY_MAP: { readonly Schema: "schema"; }; export type WhookCommandAsideComponentSuffix = (typeof COMMAND_ASIDE_COMPONENTS_SUFFIXES)[number]; export interface WhookCommandModule<T extends Record<string, WhookArgsTypes> = Record<string, WhookArgsTypes>> { default: WhookCommandInitializer<T>; definition: WhookCommandDefinition; [name: `${string}Schema`]: WhookCommandArgumentDefinition<unknown>; } export type WhookCommandHandlerWrapper<T extends Record<string, WhookArgsTypes>> = (handler: WhookCommandHandler<T>) => Promise<WhookCommandHandler<T>>;