Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
78e8171a6a | |||
c97a535035 | |||
dcf198787a | |||
a1e0ebd658 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apiglobal/typedrequest",
|
||||
"version": "1.0.45",
|
||||
"version": "1.0.47",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apiglobal/typedrequest",
|
||||
"version": "1.0.45",
|
||||
"version": "1.0.47",
|
||||
"private": false,
|
||||
"description": "make typed requests towards apis",
|
||||
"main": "dist_ts/index.js",
|
||||
|
@ -4,9 +4,16 @@ import { TypedRouter } from './typedrequest.classes.typedrouter';
|
||||
|
||||
export type IPostMethod = (
|
||||
typedRequestPostObject: plugins.typedRequestInterfaces.ITypedRequest
|
||||
) => void | Promise<plugins.typedRequestInterfaces.ITypedRequest>;
|
||||
) => Promise<plugins.typedRequestInterfaces.ITypedRequest>;
|
||||
|
||||
export type IPostMethodWithTypedRouter = (
|
||||
typedRequestPostObject: plugins.typedRequestInterfaces.ITypedRequest
|
||||
) => Promise<void> | Promise<plugins.typedRequestInterfaces.ITypedRequest>;
|
||||
|
||||
export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest> {
|
||||
/**
|
||||
* this typedrouter allows us to have easy async request response cycles
|
||||
*/
|
||||
public typedRouterRef: TypedRouter;
|
||||
public webrequest = new plugins.webrequest.WebRequest();
|
||||
|
||||
@ -18,15 +25,19 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
/**
|
||||
* in case we post with some other method, ec ipc communication
|
||||
*/
|
||||
public postMethod?: IPostMethod;
|
||||
public postMethod?: IPostMethod | IPostMethodWithTypedRouter;
|
||||
public method: string;
|
||||
|
||||
// STATIC
|
||||
constructor(
|
||||
postEndPointArg: string | IPostMethod,
|
||||
methodArg: T['method']
|
||||
)
|
||||
constructor(
|
||||
postEndPointArg: string | IPostMethodWithTypedRouter,
|
||||
methodArg: T['method'],
|
||||
typedrouterRefArg?: TypedRouter
|
||||
) {
|
||||
typedrouterRefArg?: TypedRouter)
|
||||
{
|
||||
if (typeof postEndPointArg === 'string') {
|
||||
this.urlEndPoint = postEndPointArg;
|
||||
} else {
|
||||
@ -59,6 +70,7 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
string,
|
||||
plugins.typedRequestInterfaces.ITypedRequest
|
||||
>;
|
||||
// having a typedrouter allows us to work with async request response cycles.
|
||||
if (this.typedRouterRef) {
|
||||
responseInterest = await this.typedRouterRef.fireEventInterestMap.addInterest(
|
||||
payload.correlation.id,
|
||||
|
Reference in New Issue
Block a user