fix(core): update
This commit is contained in:
parent
8c7a71ddce
commit
e2708c5bb3
7506
package-lock.json
generated
7506
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -14,19 +14,20 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.24",
|
||||
"@gitzone/tsbundle": "^1.0.69",
|
||||
"@gitzone/tstest": "^1.0.33",
|
||||
"@pushrocks/smartexpress": "^3.0.72",
|
||||
"@pushrocks/tapbundle": "^3.2.1",
|
||||
"@types/node": "^14.0.14",
|
||||
"@gitzone/tsbundle": "^1.0.72",
|
||||
"@gitzone/tstest": "^1.0.43",
|
||||
"@pushrocks/smartexpress": "^3.0.73",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^14.0.23",
|
||||
"tslint": "^6.1.2",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apiglobal/typedrequest-interfaces": "^1.0.13",
|
||||
"@pushrocks/lik": "^4.0.13",
|
||||
"@pushrocks/smartdelay": "^2.0.9",
|
||||
"@pushrocks/webrequest": "^2.0.9"
|
||||
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||
"@pushrocks/isounique": "^1.0.4",
|
||||
"@pushrocks/lik": "^4.0.14",
|
||||
"@pushrocks/smartdelay": "^2.0.10",
|
||||
"@pushrocks/webrequest": "^2.0.10"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
@ -47,6 +47,8 @@ export class TypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
typedRequestArg.response = response;
|
||||
}
|
||||
|
||||
typedRequestArg.correlation.phase = 'response';
|
||||
|
||||
return typedRequestArg;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
import * as plugins from './typedrequest.plugins';
|
||||
import { TypedResponseError } from './typedrequest.classes.typedresponseerror';
|
||||
import { TypedRouter } from './typedrequest.classes.typedrouter';
|
||||
|
||||
export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest> {
|
||||
public typedRouterRef: TypedRouter;
|
||||
public webrequest = new plugins.webrequest.WebRequest();
|
||||
public urlEndPoint: string;
|
||||
public method: string;
|
||||
@ -13,14 +15,20 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* firest the request
|
||||
* fires the request
|
||||
*/
|
||||
public async fire(fireArg: T['request']): Promise<T['response']> {
|
||||
const response = await this.webrequest.postJson(this.urlEndPoint, {
|
||||
const payload: plugins.typedRequestInterfaces.ITypedRequest = {
|
||||
method: this.method,
|
||||
request: fireArg,
|
||||
response: null
|
||||
});
|
||||
response: null,
|
||||
correlation: {
|
||||
id: plugins.isounique.uni(),
|
||||
phase: 'request'
|
||||
}
|
||||
};
|
||||
|
||||
const response = await this.webrequest.postJson(this.urlEndPoint, payload);
|
||||
const responseBody: T = response;
|
||||
if (responseBody.error) {
|
||||
console.error(
|
||||
@ -41,4 +49,13 @@ 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() {}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import * as plugins from './typedrequest.plugins';
|
||||
|
||||
import { TypedHandler } from './typedrequest.classes.typedhandler';
|
||||
import { TypedRequest } from './typedrequest.classes.typedrequest';
|
||||
|
||||
/**
|
||||
* A typed router decides on which typed handler to call based on the method
|
||||
@ -11,11 +12,22 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* adds the handler to the routing map
|
||||
* @param typedHandlerArg
|
||||
@ -64,12 +76,12 @@ export class TypedRouter {
|
||||
if (this.upstreamTypedRouter && checkUpstreamRouter) {
|
||||
typedHandler = this.upstreamTypedRouter.getTypedHandlerForMethod(methodArg);
|
||||
} else {
|
||||
typedHandler = this.handlerMap.find(handler => {
|
||||
typedHandler = this.handlerMap.find((handler) => {
|
||||
return handler.method === methodArg;
|
||||
});
|
||||
|
||||
if (!typedHandler) {
|
||||
this.routerMap.getArray().forEach(typedRouter => {
|
||||
this.routerMap.getArray().forEach((typedRouter) => {
|
||||
if (!typedHandler) {
|
||||
typedHandler = typedRouter.getTypedHandlerForMethod(methodArg, false);
|
||||
}
|
||||
@ -81,22 +93,27 @@ export class TypedRouter {
|
||||
}
|
||||
|
||||
/**
|
||||
* routes a typed request to a handler
|
||||
* if typedrequest object has correlation.phase === 'request' -> routes a typed request object to a handler
|
||||
* if typedrequest object has correlation.phase === 'response' -> routes a typed request object to request fire event
|
||||
* @param typedRequestArg
|
||||
*/
|
||||
public async routeAndAddResponse(typedRequestArg: plugins.typedRequestInterfaces.ITypedRequest) {
|
||||
if (typedRequestArg.correlation.phase === 'request') {
|
||||
const typedHandler = this.getTypedHandlerForMethod(typedRequestArg.method);
|
||||
|
||||
if (!typedHandler) {
|
||||
console.log(`Cannot find handler for methodname ${typedRequestArg.method}`);
|
||||
typedRequestArg.error = {
|
||||
text: 'There is no available method for this call on the server side',
|
||||
data: {}
|
||||
data: {},
|
||||
};
|
||||
return typedRequestArg;
|
||||
}
|
||||
|
||||
typedRequestArg = await typedHandler.addResponse(typedRequestArg);
|
||||
} else if (typedRequestArg.correlation.phase === 'response') {
|
||||
|
||||
}
|
||||
return typedRequestArg;
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,9 @@ import * as typedRequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||
export { typedRequestInterfaces };
|
||||
|
||||
// pushrocks scope
|
||||
import * as isounique from '@pushrocks/isounique';
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as webrequest from '@pushrocks/webrequest';
|
||||
|
||||
export { lik, smartdelay, webrequest };
|
||||
export { isounique, lik, smartdelay, webrequest };
|
||||
|
Loading…
Reference in New Issue
Block a user