fix(core): update

This commit is contained in:
Philipp Kunz 2020-07-14 16:37:44 +00:00
parent 2a681644eb
commit 88022ea14b
5 changed files with 68 additions and 86 deletions

65
package-lock.json generated
View File

@ -1384,9 +1384,9 @@
"integrity": "sha512-P1xLsuA1+8LQpoWCo2nP2vIQXKGUl5wDWU6CD7xTDZc3uw0He5V/qCPHM5zpIZsS7IuZOxDDpWb7aFveB11tXw=="
},
"@pushrocks/lik": {
"version": "4.0.14",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2flik/-/lik-4.0.14.tgz",
"integrity": "sha512-S4AMLp+hs1AQ2iCOz5PYReDEfVmfjdf/mf6S5TnAlEhsLU/v3u78xUmMcTPDFotTfuFQr57dGhncHNvljjQ7EQ==",
"version": "4.0.17",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2flik/-/lik-4.0.17.tgz",
"integrity": "sha512-K5dX3k3i7iVxFMJ+IYwJRljewukJCc2zgj6+88R18/8SajVAq7ITOl3/FTbmEPFCJv5rl/LQ9FtcMynWlwSlzQ==",
"requires": {
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartmatch": "^1.0.7",
@ -1395,49 +1395,6 @@
"@pushrocks/smarttime": "^3.0.24",
"@types/minimatch": "^3.0.3",
"symbol-tree": "^3.2.4"
},
"dependencies": {
"@pushrocks/smartpromise": {
"version": "3.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.6.tgz",
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
},
"@pushrocks/smartrx": {
"version": "2.0.18",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrx/-/smartrx-2.0.18.tgz",
"integrity": "sha512-DqUmtS7mONO6bvWEZmSLy4M9hlxNWysMYc7XOZLr50BMaa0HUNYWI1myUFCMNcbUUOxuQNig01XqR1smfIN69g==",
"requires": {
"@pushrocks/lik": "^4.0.14",
"@pushrocks/smartpromise": "^3.0.6",
"rxjs": "^6.6.0"
}
},
"@pushrocks/smarttime": {
"version": "3.0.24",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarttime/-/smarttime-3.0.24.tgz",
"integrity": "sha512-c/n0Y3CUnVNa3TnuXZ5aRc0bWj4RX7+XSjPes1J4HidU1yBOd9UOt6l08W8aPH5jMjT9Ei2jH0GsheaTGoVEYA==",
"requires": {
"@pushrocks/lik": "^4.0.13",
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartpromise": "^3.0.2",
"croner": "^1.1.23",
"dayjs": "^1.8.29",
"is-nan": "^1.3.0"
}
},
"dayjs": {
"version": "1.8.29",
"resolved": "https://verdaccio.lossless.one/dayjs/-/dayjs-1.8.29.tgz",
"integrity": "sha512-Vm6teig8ZWK7rH/lxzVGxZJCljPdmUr6q/3f4fr5F0VWNGVkZEjZOQJsAN8hUHUqn+NK4XHNEpJZS1MwLyDcLw=="
},
"rxjs": {
"version": "6.6.0",
"resolved": "https://verdaccio.lossless.one/rxjs/-/rxjs-6.6.0.tgz",
"integrity": "sha512-3HMA8z/Oz61DUHe+SdOiQyzIf4tOx5oQHmMir7IZEu6TMqCLHT4LRcmNaUS0NwOz8VLvmmBduMsoaUvMaIiqzg==",
"requires": {
"tslib": "^1.9.0"
}
}
}
},
"@pushrocks/smartbrowser": {
@ -1982,10 +1939,9 @@
}
},
"@pushrocks/smartpromise": {
"version": "3.0.2",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.2.tgz",
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ==",
"dev": true
"version": "3.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.6.tgz",
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
},
"@pushrocks/smartpuppeteer": {
"version": "1.0.15",
@ -2023,7 +1979,6 @@
"version": "2.0.18",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrx/-/smartrx-2.0.18.tgz",
"integrity": "sha512-DqUmtS7mONO6bvWEZmSLy4M9hlxNWysMYc7XOZLr50BMaa0HUNYWI1myUFCMNcbUUOxuQNig01XqR1smfIN69g==",
"dev": true,
"requires": {
"@pushrocks/lik": "^4.0.14",
"@pushrocks/smartpromise": "^3.0.6",
@ -2033,14 +1988,12 @@
"@pushrocks/smartpromise": {
"version": "3.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.6.tgz",
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg==",
"dev": true
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
},
"rxjs": {
"version": "6.6.0",
"resolved": "https://verdaccio.lossless.one/rxjs/-/rxjs-6.6.0.tgz",
"integrity": "sha512-3HMA8z/Oz61DUHe+SdOiQyzIf4tOx5oQHmMir7IZEu6TMqCLHT4LRcmNaUS0NwOz8VLvmmBduMsoaUvMaIiqzg==",
"dev": true,
"requires": {
"tslib": "^1.9.0"
}
@ -2078,7 +2031,6 @@
"version": "3.0.24",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarttime/-/smarttime-3.0.24.tgz",
"integrity": "sha512-c/n0Y3CUnVNa3TnuXZ5aRc0bWj4RX7+XSjPes1J4HidU1yBOd9UOt6l08W8aPH5jMjT9Ei2jH0GsheaTGoVEYA==",
"dev": true,
"requires": {
"@pushrocks/lik": "^4.0.13",
"@pushrocks/smartdelay": "^2.0.10",
@ -4274,8 +4226,7 @@
"dayjs": {
"version": "1.8.29",
"resolved": "https://verdaccio.lossless.one/dayjs/-/dayjs-1.8.29.tgz",
"integrity": "sha512-Vm6teig8ZWK7rH/lxzVGxZJCljPdmUr6q/3f4fr5F0VWNGVkZEjZOQJsAN8hUHUqn+NK4XHNEpJZS1MwLyDcLw==",
"dev": true
"integrity": "sha512-Vm6teig8ZWK7rH/lxzVGxZJCljPdmUr6q/3f4fr5F0VWNGVkZEjZOQJsAN8hUHUqn+NK4XHNEpJZS1MwLyDcLw=="
},
"deasync": {
"version": "0.1.20",

View File

@ -25,8 +25,9 @@
"dependencies": {
"@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/isounique": "^1.0.4",
"@pushrocks/lik": "^4.0.14",
"@pushrocks/lik": "^4.0.17",
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/webrequest": "^2.0.10"
},
"files": [

View File

@ -2,16 +2,38 @@ import * as plugins from './typedrequest.plugins';
import { TypedResponseError } from './typedrequest.classes.typedresponseerror';
import { TypedRouter } from './typedrequest.classes.typedrouter';
export type IPostMethod = (
typedRequestPostObject: plugins.typedRequestInterfaces.ITypedRequest
) => void | Promise<plugins.typedRequestInterfaces.ITypedRequest>;
export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest> {
public typedRouterRef: TypedRouter;
public webrequest = new plugins.webrequest.WebRequest();
public urlEndPoint: string;
/**
* in case we post against a url endpoint
*/
public urlEndPoint?: string;
/**
* in case we post with some other method, ec ipc communication
*/
public postMethod?: IPostMethod;
public method: string;
// STATIC
constructor(urlEndPointArg: string, methodArg: T['method']) {
this.urlEndPoint = urlEndPointArg;
constructor(
postEndPointArg: string | IPostMethod,
methodArg: T['method'],
typedrouterRefArg?: TypedRouter
) {
if (typeof postEndPointArg === 'string') {
this.urlEndPoint = postEndPointArg;
} else {
this.postMethod = postEndPointArg;
}
this.method = methodArg;
this.typedRouterRef = typedrouterRefArg;
}
/**
@ -24,12 +46,34 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
response: null,
correlation: {
id: plugins.isounique.uni(),
phase: 'request'
}
phase: 'request',
},
};
const response = await this.webrequest.postJson(this.urlEndPoint, payload);
const responseBody: T = response;
let responseBody: plugins.typedRequestInterfaces.ITypedRequest;
if (this.urlEndPoint) {
const response = await this.webrequest.postJson(this.urlEndPoint, payload);
responseBody = response;
} else {
let responseInterest: plugins.lik.Interest<
string,
plugins.typedRequestInterfaces.ITypedRequest
>;
if (this.typedRouterRef) {
responseInterest = await this.typedRouterRef.fireEventInterestMap.addInterest(
payload.correlation.id,
payload
);
}
const postMethodReturnValue = await this.postMethod(payload);
if (responseInterest) {
responseBody = await responseInterest.interestFullfilled;
} else if (postMethodReturnValue) {
responseBody = postMethodReturnValue;
} else {
responseBody = payload;
}
}
if (responseBody.error) {
console.error(
`Got an error ${responseBody.error.text} with data ${JSON.stringify(
@ -49,13 +93,4 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
}
return responseBody.response;
}
public addTypedRouterForResponse(typedRouterArg: TypedRouter) {
if (!this.typedRouterRef) {
this.typedRouterRef = typedRouterArg;
typedRouterArg.addTypedRequest(this);
}
}
public registerAlternateFireMethod() {}
}

View File

@ -12,21 +12,15 @@ export class TypedRouter {
public upstreamTypedRouter: TypedRouter;
public routerMap = new plugins.lik.ObjectMap<TypedRouter>();
public typedRequestMap = new plugins.lik.ObjectMap<TypedRequest<any>>();
public handlerMap = new plugins.lik.ObjectMap<
TypedHandler<plugins.typedRequestInterfaces.ITypedRequest>
>();
public fireEventInterestMap = new plugins.lik.InterestMap((correlationId: string) => correlationId);
public addTypedRequest(typedRequestArg: TypedRequest<any>) {
if(!this.typedRequestMap.checkForObject(typedRequestArg)) {
this.typedRequestMap.add(typedRequestArg);
typedRequestArg.addTypedRouterForResponse(this);
}
}
public fireEventInterestMap = new plugins.lik.InterestMap<
string,
plugins.typedRequestInterfaces.ITypedRequest
>((correlationId: string) => correlationId);
/**
* adds the handler to the routing map
@ -112,7 +106,7 @@ export class TypedRouter {
typedRequestArg = await typedHandler.addResponse(typedRequestArg);
} else if (typedRequestArg.correlation.phase === 'response') {
this.fireEventInterestMap.findInterest(typedRequestArg.correlation.id)?.fullfillInterest(typedRequestArg);
}
return typedRequestArg;
}

View File

@ -7,6 +7,7 @@ export { typedRequestInterfaces };
import * as isounique from '@pushrocks/isounique';
import * as lik from '@pushrocks/lik';
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise';
import * as webrequest from '@pushrocks/webrequest';
export { isounique, lik, smartdelay, webrequest };
export { isounique, lik, smartdelay, smartpromise, webrequest };