@api.global/typedrequest
Version:
A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.
41 lines (40 loc) • 1.76 kB
TypeScript
import { TypedRouter } from './classes.typedrouter.js';
import * as plugins from './plugins.js';
export type IPostMethod = (typedRequestPostObject: plugins.typedRequestInterfaces.ITypedRequest) => Promise<plugins.typedRequestInterfaces.ITypedRequest>;
/**
* this is an alternative to a post url supplied in `new Typedrequest(new TypedTarget(...), 'someMethodName')`
* enables the use of custom post functions
* used for things like broadcast channels
* e.g. @designestate/dees-comms
* the main difference here is, that the response comes back async and is routed by interest through typedrouter
*/
export type IPostMethodWithTypedRouter = (typedRequestPostObject: plugins.typedRequestInterfaces.ITypedRequest) => Promise<void> | Promise<plugins.typedRequestInterfaces.ITypedRequest>;
export interface ITypedTargetConstructorOptions {
url?: string;
postMethod?: IPostMethod;
/**
* a post method that does not return the answer
*/
postMethodWithTypedRouter?: IPostMethodWithTypedRouter;
/**
* this typedrouter allows us to have easy async request response cycles
*/
typedRouterRef?: TypedRouter;
}
/**
* a typed target defines a target for requests
*/
export declare class TypedTarget {
url: string;
type: 'rest' | 'socket';
options: ITypedTargetConstructorOptions;
constructor(optionsArg: ITypedTargetConstructorOptions);
/**
* wether calls to this target are bound to the request/response cycle
* if false, always delivers response as result of a call
* if true, delivers response in a separate call
* can only be async when type is 'socket'
*/
isAsync: boolean;
post<T extends plugins.typedRequestInterfaces.ITypedRequest>(payloadArg: T): Promise<T>;
}