UNPKG

@api.global/typedrequest

Version:

A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.

43 lines (42 loc) 2 kB
import * as plugins from './plugins.js'; import { VirtualStream } from './classes.virtualstream.js'; import { TypedHandler } from './classes.typedhandler.js'; /** * A typed router decides on which typed handler to call based on the method * specified in the typed request * This is thought for reusing the same url endpoint for different methods */ export declare class TypedRouter { routerMap: plugins.lik.ObjectMap<TypedRouter>; handlerMap: plugins.lik.ObjectMap<TypedHandler<any>>; registeredVirtualStreams: plugins.lik.ObjectMap<VirtualStream<any>>; fireEventInterestMap: plugins.lik.InterestMap<string, plugins.typedRequestInterfaces.ITypedRequest>; /** * adds the handler to the routing map * @param typedHandlerArg */ addTypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest>(typedHandlerArg: TypedHandler<T>): void; /** * adds another sub typedRouter * @param typedRequest */ addTypedRouter(typedRouterArg: TypedRouter): void; checkForTypedHandler(methodArg: string): boolean; /** * gets a typed Router from the router chain, upstream and downstream * @param methodArg * @param checkUpstreamRouter */ getTypedHandlerForMethod(methodArg: string, checkedRouters?: TypedRouter[]): TypedHandler<any>; /** * if typedrequest object has correlation.phase === 'request' -> routes a typed request object to a handler * if typedrequest object has correlation.phase === 'response' -> routes a typed request object to request fire event * @param typedRequestArg */ routeAndAddResponse<T extends plugins.typedRequestInterfaces.ITypedRequest = plugins.typedRequestInterfaces.ITypedRequest>(typedRequestArg: T, localRequestArg?: boolean): Promise<T>; /** * handle streaming * @param streamTrArg */ handleStreamTypedRequest(streamTrArg: plugins.typedRequestInterfaces.IStreamRequest): Promise<plugins.typedRequestInterfaces.IStreamRequest>; }