Compare commits

...

4 Commits

Author SHA1 Message Date
309c282379 1.0.65 2021-11-10 13:14:41 +01:00
90c616ca41 fix(core): update 2021-11-10 13:14:40 +01:00
57177074d0 1.0.64 2021-11-10 01:41:55 +01:00
d3b5c802cd fix(core): update 2021-11-10 01:41:55 +01:00
3 changed files with 20 additions and 25 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@apiglobal/typedrequest",
"version": "1.0.63",
"version": "1.0.65",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@apiglobal/typedrequest",
"version": "1.0.63",
"version": "1.0.65",
"license": "MIT",
"dependencies": {
"@apiglobal/typedrequest-interfaces": "^1.0.15",

View File

@ -1,6 +1,6 @@
{
"name": "@apiglobal/typedrequest",
"version": "1.0.63",
"version": "1.0.65",
"private": false,
"description": "make typed requests towards apis",
"main": "dist_ts/index.js",

View File

@ -9,10 +9,7 @@ import { TypedRequest } from './typedrequest.classes.typedrequest';
* This is thought for reusing the same url endpoint for different methods
*/
export class TypedRouter {
public upstreamTypedRouter: TypedRouter;
public routerMap = new plugins.lik.ObjectMap<TypedRouter>();
public handlerMap = new plugins.lik.ObjectMap<
TypedHandler<any & plugins.typedRequestInterfaces.ITypedRequest>
>();
@ -45,11 +42,11 @@ export class TypedRouter {
* @param typedRequest
*/
public addTypedRouter(typedRouterArg: TypedRouter) {
this.routerMap.add(typedRouterArg);
}
public setUpstreamTypedRouter(typedRouterArg: TypedRouter) {
this.upstreamTypedRouter = typedRouterArg;
const routerExists = this.routerMap.findSync(routerArg => routerArg === typedRouterArg)
if (!routerExists) {
this.routerMap.add(typedRouterArg);
typedRouterArg.addTypedRouter(this);
}
}
public checkForTypedHandler(methodArg: string): boolean {
@ -63,24 +60,22 @@ export class TypedRouter {
*/
public getTypedHandlerForMethod(
methodArg: string,
checkUpstreamRouter = true
checkedRouters: TypedRouter[] = []
): TypedHandler<any> {
checkedRouters.push(this);
let typedHandler: TypedHandler<any>;
if (this.upstreamTypedRouter && checkUpstreamRouter) {
typedHandler = this.upstreamTypedRouter.getTypedHandlerForMethod(methodArg);
} else {
typedHandler = this.handlerMap.findSync((handler) => {
return handler.method === methodArg;
typedHandler = this.handlerMap.findSync((handler) => {
return handler.method === methodArg;
});
if (!typedHandler) {
this.routerMap.getArray().forEach((typedRouterArg) => {
if (!typedHandler && !checkedRouters.includes(typedRouterArg)) {
typedHandler = typedRouterArg.getTypedHandlerForMethod(methodArg, checkedRouters);
}
});
if (!typedHandler) {
this.routerMap.getArray().forEach((typedRouter) => {
if (!typedHandler) {
typedHandler = typedRouter.getTypedHandlerForMethod(methodArg, false);
}
});
}
}
return typedHandler;