Compare commits

...

4 Commits

Author SHA1 Message Date
78e8171a6a 1.0.47 2020-10-06 14:29:50 +00:00
c97a535035 fix(core): update 2020-10-06 14:29:49 +00:00
dcf198787a 1.0.46 2020-09-29 15:51:06 +00:00
a1e0ebd658 fix(core): update 2020-09-29 15:51:05 +00:00
3 changed files with 18 additions and 6 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@apiglobal/typedrequest",
"version": "1.0.45",
"version": "1.0.47",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -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",

View File

@ -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,