Last active
September 3, 2021 08:41
-
-
Save rricard/af2f722d0cd1c7d4336de9b1698caad9 to your computer and use it in GitHub Desktop.
requestrouter.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import JsCore from "@jscore"; | |
import EventEmitter from "@jscore/event-emitter"; | |
export interface RequestHandler<T, R> { | |
(request: T, ...args: any[]): R; | |
} | |
declare const RequestRouter_base: new () => EventEmitter<{ | |
/** | |
* Fires when something happens | |
* @event | |
*/ | |
miscomparison: {}; | |
}>; | |
/** | |
* This class allows for the routing between two functions which share the same | |
* 'Request' and 'Response' type based off of a provided 'condition'. | |
*/ | |
export declare class RequestRouter<Request, Response> extends RequestRouter_base { | |
d_oldHandler: RequestHandler<Request, Response>; | |
d_newHandler: RequestHandler<Request, Response>; | |
d_condition: () => Promise<boolean>; | |
d_comparator?: InstanceType<typeof JsCore.value.ComparatorSpec>; | |
constructor(oldHandler: RequestHandler<Request, Response>, newHandler: RequestHandler<Request, Response>, condition: () => Promise<boolean>, comparator?: InstanceType<typeof JsCore.value.ComparatorSpec>); | |
/** | |
* Given a 'Request' and any extra arguments, resolve which handler should | |
* be used via 'd_condition', send the request with the given handler(s), | |
* compare the responses, and return the value. If the old handler is | |
* specified for use, no comparison will be done. If the deep compare fails, | |
* the response from the old handler will be used, and an event will be emitted | |
* with the data being compared | |
*/ | |
process(request: Request, ...args: any[]): Promise<Response>; | |
/** | |
* Fires when something happens | |
* @event | |
*/ | |
miscomparison(event: {}); | |
} | |
export {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import JsCore from "@jscore"; | |
import EventEmitter from "@jscore/event-emitter"; | |
export interface RequestHandler<T, R> { | |
(request: T, ...args: any[]): R; | |
} | |
declare const RequestRouter_base: new () => EventEmitter<{ | |
/** | |
* Fires when something happens | |
* @event | |
*/ | |
miscomparison: {}; | |
}>; | |
/** | |
* This class allows for the routing between two functions which share the same | |
* 'Request' and 'Response' type based off of a provided 'condition'. | |
*/ | |
export declare class RequestRouter< | |
Request, | |
Response | |
> extends RequestRouter_base { | |
d_oldHandler: RequestHandler<Request, Response>; | |
d_newHandler: RequestHandler<Request, Response>; | |
d_condition: () => Promise<boolean>; | |
d_comparator?: InstanceType<typeof JsCore.value.ComparatorSpec>; | |
constructor( | |
oldHandler: RequestHandler<Request, Response>, | |
newHandler: RequestHandler<Request, Response>, | |
condition: () => Promise<boolean>, | |
comparator?: InstanceType<typeof JsCore.value.ComparatorSpec> | |
); | |
/** | |
* Given a 'Request' and any extra arguments, resolve which handler should | |
* be used via 'd_condition', send the request with the given handler(s), | |
* compare the responses, and return the value. If the old handler is | |
* specified for use, no comparison will be done. If the deep compare fails, | |
* the response from the old handler will be used, and an event will be emitted | |
* with the data being compared | |
*/ | |
process(request: Request, ...args: any[]): Promise<Response>; | |
} | |
export {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment