/// declare module "@hatsy/hatsy/core.js" { /** * Error processing means. * * A context with these means is created once error is thrown by one of the handlers right before passing it to error * handler. * * @typeParam TError - Error type. */ export interface ErrorMeans { /** * Error thrown. */ readonly error: TError; } } declare module "@hatsy/hatsy/core.js" { /** * Modification or extension of {@link RequestContext request processing means}. * * The properties present here are added to new context potentially replacing the original ones. * * @typeParam TMeans - A type of request processing means to modify. * @typeParam TExt - A type of request processing means extension. */ export type RequestModification = { [K in keyof TMeans]?: TMeans[K] | undefined; } & { [K in Exclude]: TExt[K]; }; /** * Builds request modification that updates some of the existing properties of request processing means. * * This is a helper function to avoid TypeScript limitation. It is a good idea to inline it. * * @typeParam TMeans - A type of request processing means to modify. * @param modification - Partial request modification. * * @returns Request modification cast to {@link RequestModification}. */ export function requestUpdate(modification: Partial): RequestModification; /** * Builds request modification that adds new properties to request processing means. * * This is a helper function to avoid TypeScript limitation. It is a good idea to inline it. * * @typeParam TMeans - A type of request processing means to modify. * @typeParam TExt - A type of request processing means extension. * @param extension - Request extension containing all the required properties. * * @returns Request extension cast to {@link RequestModification}. */ export function requestExtension(extension: TExt): RequestModification; } declare module "@hatsy/hatsy/core.js" { /** * Request processing context. * * It is passed to {@link RequestHandler request processing handler}. It the necessary means. The handler can either * respond by these means, or delegate processing to the {@link RequestContext.Agent.next next handler}. * * The context instance is immutable. The request processing means it contains can be {@link RequestModification * modified} or even extended when delegating request processing to the {@link RequestContext.Agent.next next handler} * by creating another context based on original one. * * @typeParam TMeans - Request processing means of this context. */ export type RequestContext = TMeans & RequestContext.Agent; export namespace RequestContext { /** * Request processing agent interface. * * It is extended by {@link RequestContext request processing context} in order the {@link RequestHandler handlers} * to be able to {@link next delegate processing} to other handlers. * * @typeParam TMeans - A type of request processing means. */ interface Agent { /** * Delegates request processing to the next `handler` and optionally modifies processing means by creating a new * context with the given `modifications` applied. The rest of the properties remain unchanged. * * @param handler - Target handler to delegate request processing to. * @param modification - Request processing means modification. `this` context will be passed to the next * `handler` when omitted. * * @returns A promise resolved when request processing finishes. Resolves to `true` when request is responded, * or to `false` otherwise. */ next(this: void, handler: RequestHandler, modification?: RequestModification): Promise; } } } declare module "@hatsy/hatsy/core.js" { /** * Request processing handler signature. * * Handler implementations expect a request processing context containing specific processing means. * E.g. the ones for {@link HttpMeans HTTP request processing}. The handler may either respond using the provided means, * or delegate to {@link RequestContext.Agent#next next handler}. * * The handler may be asynchronous. * * @typeParam TMeans - A type of request processing means this handler expects. * @param context - Request processing context containing the necessary means. * * @returns Either nothing if the handler completed its work synchronously, or a promise-like instance resolved when * the handler completed its work asynchronously. */ export type RequestHandler = (this: void, context: RequestContext) => PromiseLike | void; /** * Request processing method signature. * * This is a {@link RequestHandler request handler} that requires a `this` object. * * @typeParam TThis - A type of `this` object. * @typeParam TMeans - A type of request processing means this handler expects. * @param context - Request processing context containing the necessary means. * * @returns Either nothing if the handler completed its work synchronously, or a promise-like instance resolved when * the handler completed its work asynchronously. */ export type RequestHandlerMethod = (this: TThis, context: RequestContext) => PromiseLike | void; /** * Builds a request processing handler that delegates request processing to other handlers. * * Iterates over the given handlers in order and delegates the request processing to them. It stops when either * response is generated, an error thrown, or no handlers left. * * @typeParam TMeans - A type of request processing means `handlers` expect. * @param handlers - Either single handler or iterable of handlers to delegate request processing to. * * @returns Request processing handler. */ export function requestHandler(handlers: RequestHandler | Iterable>): RequestHandler; } declare module "@hatsy/hatsy/core.js" { /** * Dispatches request processing error. * * Processes request with the given handler. If processing fails, processes error with the given `onError` one. * * @typeParam TMeans - Request processing means. * @param onError - Error processing handler. * @param handler - Request processing handler to process the original request with. * * @returns New request processing handler. */ export function dispatchError(onError: RequestHandler, handler: RequestHandler): RequestHandler; } declare module "@hatsy/hatsy/core.js" { import type { Logger } from "@proc7ts/logger"; /** * A logger to use during request processing. */ export interface RequestLogger extends Logger { /** * Logs error. * * @param args - Arbitrary arguments to log. */ error(...args: unknown[]): void; /** * Logs warning. * * @param args - Arbitrary arguments to log. */ warn(...args: unknown[]): void; /** * Logs informational message. * * @param args - Arbitrary arguments to log. */ info(...args: unknown[]): void; /** * Logs debug message. * * @param args - Arbitrary arguments to log. */ debug(...args: unknown[]): void; /** * Logs tracing message. * * This may lead to outputting of stack trace. * * @param args - Arbitrary arguments to log. */ trace(...args: unknown[]): void; } } declare module "@hatsy/hatsy/core.js" { /** * Request logger means. * * @typeParam TLogger - Request logger type. */ export interface LoggerMeans { /** * A logger to use during request processing. */ readonly log: TLogger; } } declare module "@hatsy/hatsy/core.js" { /** * Request processing capability. * * Modifies request processing context in a certain way when delegates to handler. * * Request processing capabilities could be {@link RequestCapability.combine combined}. * * @typeParam TInput - A type of request processing means required in order to apply this capability. * @typeParam TExt - A type of extension to request processing means this capability applies. */ export abstract class RequestCapability { /** * Builds request capability by the given `provider`. * * @typeParam TInput - A type of request processing means required by this provider. * @typeParam TExt - A type of extension to request processing means this provider applies. * @param provider - Request processing capability provider. * * @returns Request processing capability that call the given `provider` in order to apply. */ static of(this: void, provider: RequestCapability.Provider): RequestCapability; /** * Combines two request processing capabilities. * * @typeParam TInput - A type of request processing means expected by the `first` capability. * @typeParam TExt - A type of request processing means extension applied by the `first` capability. * @typeParam TNext - A type of request processing means extension applied by the `second` capability. * @param first - First capability to combine. * @param second - Second capability to combine. Receives requests modified by the `first` one. * * @return Combined request processing capability that applies modifications to request by the `first` capability, * and then - by the `second` one. */ static combine(this: void, first: RequestCapability, second: RequestCapability): RequestCapability; /** * Provides request processing capability to the given handler. * * Builds request processing handler that modifies request and delegates to target `handler`. * * @typeParam TMeans - A type of request processing means expected by constructed handler. * @param handler - Request processing handler that will receive modified request context. * * @returns New request processing handler. */ abstract for(handler: RequestHandler): RequestHandler; /** * Combines this capability with the `next` one. * * @typeParam TNext - A type of extension to request processing means applied by `next` capability. * @param next - Next capability that receives requests modified by this capability. * * @return New request processing capability that applies modifications to request by this capability first, * and then - by the `next` one. * * @see RequestCapability.combine */ and(next: RequestCapability): RequestCapability; } export namespace RequestCapability { /** * Request processing capability provider signature. * * Builds a request processing handler that modifies request and delegates to another one. * * @typeParam TInput - A type of request processing means required by this provider. * @typeParam TExt - A type of extension to request processing means this provider applies. * @typeParam TMeans - A type of request processing means expected by constructed handler. * * @param handler - Request processing handler that will receive modified request context. * * @returns New request processing handler. */ type Provider = (this: void, handler: RequestHandler) => RequestHandler; } } declare module "@hatsy/hatsy/core.js" { /** * Request logging capability. * * Provides {@link LoggerMeans request logger means} for handlers. * * @typeParam TInput - A type of request processing means required in order to apply this capability. * @typeParam TLogger - Request logger type. */ export interface Logging extends RequestCapability> { /** * Configures a logging capability with the given logger. * * @typeParam TNewLogger - Request logger type. * @param log - A logger to use for request processing. * * @returns New request logging capability. */ logBy(log: TNewLogger): Logging; } /** * Request logging capability instance. * * Uses a global `console` as {@link LoggerMeans.log request logger}, unless the logger is present in request context * already. */ export const Logging: Logging; } declare module "@hatsy/hatsy/core.js" { /** * Request body processing means. * * @typeParam TBody - A type of request body. */ export interface RequestBodyMeans { /** * Request body. */ readonly requestBody: TBody; } } declare module "@hatsy/hatsy/core.js" { /** * Generic request processor. * * Can be constructed by {@link requestProcessor} function. * * @typeParam TMeans - A type of initial request processing means. */ export type RequestProcessor = /** * @param means - Initial request processing means. * * @returns A promise resolved when request processing finishes. Resolves to `true` when request is responded, * or to `false` otherwise. */ (this: void, means: TMeans) => Promise; export namespace RequestProcessor { /** * Request processor configuration. * * @typeParam TMeans - A type of initial request processing means. */ interface Config { /** * Initial request processing handler. * * This processor is invoked immediately on request processor call. */ readonly handler: RequestHandlerMethod; /** * Calls the next request processing handler. * * This method is called when {@link RequestContext.Agent.next delegating to request handler}. The value returned * is used as processing result. * * @param handler - Request processing handler. * @param context - Request processing context. * * @returns A promise resolved when request processing finishes. Resolves to `true` when request is responded, * or to `false` otherwise. */ next(handler: RequestHandler, context: RequestContext): Promise; } } /** * Builds a request processor. * * @typeParam TMeans - A type of initial request processing means. * @param config - Request processor configuration. * * @returns New request processor. */ export function requestProcessor(config: RequestProcessor.Config): RequestProcessor; } declare module "@hatsy/hatsy/core.js" { /** * Signature of request value transformer function. * * It is used to transform values in context of request processing. * * @typeParam TMeans - A type of request processing means. * @typeParam TFrom - A type of original, non-transformed value. * @typeParam TTo - A type of transformed value. */ export type RequestValueTransformer = /** * @param from - Original value to transform. * @param context - Request processing context to perform transformation in. * * @returns Transformed value or promise-like instance resolving to it. */ (this: void, from: TFrom, context: RequestContext) => TTo | PromiseLike; } //# sourceMappingURL=hatsy.core.d.ts.map