@pristine-ts/networking 0.0.165 → 0.0.166
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/cjs/decorators/body.decorator.js +20 -1
- package/dist/lib/cjs/decorators/body.decorator.js.map +1 -1
- package/dist/lib/cjs/decorators/controller.decorator.js +13 -1
- package/dist/lib/cjs/decorators/controller.decorator.js.map +1 -1
- package/dist/lib/cjs/decorators/decorators.js +1 -1
- package/dist/lib/cjs/decorators/decorators.js.map +1 -1
- package/dist/lib/cjs/decorators/headers.decorator.js +20 -1
- package/dist/lib/cjs/decorators/headers.decorator.js.map +1 -1
- package/dist/lib/cjs/decorators/identity.decorator.js +20 -1
- package/dist/lib/cjs/decorators/identity.decorator.js.map +1 -1
- package/dist/lib/cjs/decorators/query-parameter.decorator.js +22 -1
- package/dist/lib/cjs/decorators/query-parameter.decorator.js.map +1 -1
- package/dist/lib/cjs/decorators/query-parameters.decorator.js +20 -1
- package/dist/lib/cjs/decorators/query-parameters.decorator.js.map +1 -1
- package/dist/lib/cjs/decorators/request.decorator.js +20 -1
- package/dist/lib/cjs/decorators/request.decorator.js.map +1 -1
- package/dist/lib/cjs/decorators/response-header.decorator.js +24 -2
- package/dist/lib/cjs/decorators/response-header.decorator.js.map +1 -1
- package/dist/lib/cjs/decorators/route-parameter.decorator.js +21 -1
- package/dist/lib/cjs/decorators/route-parameter.decorator.js.map +1 -1
- package/dist/lib/cjs/decorators/route.decorator.js +21 -1
- package/dist/lib/cjs/decorators/route.decorator.js.map +1 -1
- package/dist/lib/cjs/enrichers/router-response.enricher.js +4 -0
- package/dist/lib/cjs/enrichers/router-response.enricher.js.map +1 -1
- package/dist/lib/cjs/errors/errors.js +3 -1
- package/dist/lib/cjs/errors/errors.js.map +1 -1
- package/dist/lib/cjs/errors/http.error.js +1 -1
- package/dist/lib/cjs/errors/http.error.js.map +1 -1
- package/dist/lib/cjs/errors/method-router-adding.error.js +25 -0
- package/dist/lib/cjs/errors/method-router-adding.error.js.map +1 -0
- package/dist/lib/cjs/errors/path-router-adding.error.js +3 -2
- package/dist/lib/cjs/errors/path-router-adding.error.js.map +1 -1
- package/dist/lib/cjs/errors/path-router-instantiation.error.js +3 -2
- package/dist/lib/cjs/errors/path-router-instantiation.error.js.map +1 -1
- package/dist/lib/cjs/interfaces/interfaces.js +2 -2
- package/dist/lib/cjs/interfaces/interfaces.js.map +1 -1
- package/dist/lib/cjs/models/models.js +0 -1
- package/dist/lib/cjs/models/models.js.map +1 -1
- package/dist/lib/cjs/models/request.js +10 -4
- package/dist/lib/cjs/models/request.js.map +1 -1
- package/dist/lib/cjs/models/response.js +6 -0
- package/dist/lib/cjs/models/response.js.map +1 -1
- package/dist/lib/cjs/models/route.js +4 -0
- package/dist/lib/cjs/models/route.js.map +1 -1
- package/dist/lib/cjs/networking.module.js +0 -6
- package/dist/lib/cjs/networking.module.js.map +1 -1
- package/dist/lib/cjs/nodes/method-router.node.js +19 -4
- package/dist/lib/cjs/nodes/method-router.node.js.map +1 -1
- package/dist/lib/cjs/nodes/path-router.node.js +22 -12
- package/dist/lib/cjs/nodes/path-router.node.js.map +1 -1
- package/dist/lib/cjs/resolvers/body-parameter-decorator.resolver.js +18 -0
- package/dist/lib/cjs/resolvers/body-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/cjs/resolvers/controller-method-parameter-decorator.resolver.js +14 -0
- package/dist/lib/cjs/resolvers/controller-method-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/cjs/resolvers/headers-parameter-decorator.resolver.js +18 -0
- package/dist/lib/cjs/resolvers/headers-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/cjs/resolvers/identity-parameter-decorator.resolver.js +18 -0
- package/dist/lib/cjs/resolvers/identity-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/cjs/resolvers/query-parameter-decorator.resolver.js +19 -0
- package/dist/lib/cjs/resolvers/query-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/cjs/resolvers/query-parameters-decorator.resolver.js +18 -0
- package/dist/lib/cjs/resolvers/query-parameters-decorator.resolver.js.map +1 -1
- package/dist/lib/cjs/resolvers/route-parameter-decorator.resolver.js +18 -0
- package/dist/lib/cjs/resolvers/route-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/cjs/router.js +16 -0
- package/dist/lib/cjs/router.js.map +1 -1
- package/dist/lib/esm/decorators/body.decorator.js +20 -1
- package/dist/lib/esm/decorators/body.decorator.js.map +1 -1
- package/dist/lib/esm/decorators/controller.decorator.js +13 -1
- package/dist/lib/esm/decorators/controller.decorator.js.map +1 -1
- package/dist/lib/esm/decorators/decorators.js +1 -1
- package/dist/lib/esm/decorators/decorators.js.map +1 -1
- package/dist/lib/esm/decorators/headers.decorator.js +20 -1
- package/dist/lib/esm/decorators/headers.decorator.js.map +1 -1
- package/dist/lib/esm/decorators/identity.decorator.js +20 -1
- package/dist/lib/esm/decorators/identity.decorator.js.map +1 -1
- package/dist/lib/esm/decorators/query-parameter.decorator.js +22 -1
- package/dist/lib/esm/decorators/query-parameter.decorator.js.map +1 -1
- package/dist/lib/esm/decorators/query-parameters.decorator.js +20 -1
- package/dist/lib/esm/decorators/query-parameters.decorator.js.map +1 -1
- package/dist/lib/esm/decorators/request.decorator.js +20 -1
- package/dist/lib/esm/decorators/request.decorator.js.map +1 -1
- package/dist/lib/esm/decorators/response-header.decorator.js +24 -2
- package/dist/lib/esm/decorators/response-header.decorator.js.map +1 -1
- package/dist/lib/esm/decorators/route-parameter.decorator.js +21 -1
- package/dist/lib/esm/decorators/route-parameter.decorator.js.map +1 -1
- package/dist/lib/esm/decorators/route.decorator.js +21 -1
- package/dist/lib/esm/decorators/route.decorator.js.map +1 -1
- package/dist/lib/esm/enrichers/router-response.enricher.js +4 -0
- package/dist/lib/esm/enrichers/router-response.enricher.js.map +1 -1
- package/dist/lib/esm/errors/errors.js +3 -1
- package/dist/lib/esm/errors/errors.js.map +1 -1
- package/dist/lib/esm/errors/http.error.js +1 -1
- package/dist/lib/esm/errors/http.error.js.map +1 -1
- package/dist/lib/esm/errors/method-router-adding.error.js +21 -0
- package/dist/lib/esm/errors/method-router-adding.error.js.map +1 -0
- package/dist/lib/esm/errors/path-router-adding.error.js +3 -2
- package/dist/lib/esm/errors/path-router-adding.error.js.map +1 -1
- package/dist/lib/esm/errors/path-router-instantiation.error.js +3 -2
- package/dist/lib/esm/errors/path-router-instantiation.error.js.map +1 -1
- package/dist/lib/esm/interfaces/interfaces.js +2 -2
- package/dist/lib/esm/interfaces/interfaces.js.map +1 -1
- package/dist/lib/esm/models/models.js +0 -1
- package/dist/lib/esm/models/models.js.map +1 -1
- package/dist/lib/esm/models/request.js +10 -4
- package/dist/lib/esm/models/request.js.map +1 -1
- package/dist/lib/esm/models/response.js +6 -0
- package/dist/lib/esm/models/response.js.map +1 -1
- package/dist/lib/esm/models/route.js +4 -0
- package/dist/lib/esm/models/route.js.map +1 -1
- package/dist/lib/esm/networking.module.js +0 -6
- package/dist/lib/esm/networking.module.js.map +1 -1
- package/dist/lib/esm/nodes/method-router.node.js +19 -4
- package/dist/lib/esm/nodes/method-router.node.js.map +1 -1
- package/dist/lib/esm/nodes/path-router.node.js +22 -12
- package/dist/lib/esm/nodes/path-router.node.js.map +1 -1
- package/dist/lib/esm/resolvers/body-parameter-decorator.resolver.js +18 -0
- package/dist/lib/esm/resolvers/body-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/esm/resolvers/controller-method-parameter-decorator.resolver.js +14 -0
- package/dist/lib/esm/resolvers/controller-method-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/esm/resolvers/headers-parameter-decorator.resolver.js +18 -0
- package/dist/lib/esm/resolvers/headers-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/esm/resolvers/identity-parameter-decorator.resolver.js +18 -0
- package/dist/lib/esm/resolvers/identity-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/esm/resolvers/query-parameter-decorator.resolver.js +19 -0
- package/dist/lib/esm/resolvers/query-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/esm/resolvers/query-parameters-decorator.resolver.js +18 -0
- package/dist/lib/esm/resolvers/query-parameters-decorator.resolver.js.map +1 -1
- package/dist/lib/esm/resolvers/route-parameter-decorator.resolver.js +18 -0
- package/dist/lib/esm/resolvers/route-parameter-decorator.resolver.js.map +1 -1
- package/dist/lib/esm/router.js +16 -0
- package/dist/lib/esm/router.js.map +1 -1
- package/dist/types/decorators/body.decorator.d.ts +3 -0
- package/dist/types/decorators/controller.decorator.d.ts +4 -0
- package/dist/types/decorators/decorators.d.ts +1 -1
- package/dist/types/decorators/headers.decorator.d.ts +3 -0
- package/dist/types/decorators/identity.decorator.d.ts +3 -0
- package/dist/types/decorators/query-parameter.decorator.d.ts +4 -0
- package/dist/types/decorators/query-parameters.decorator.d.ts +3 -0
- package/dist/types/decorators/request.decorator.d.ts +3 -0
- package/dist/types/decorators/response-header.decorator.d.ts +7 -0
- package/dist/types/decorators/route-parameter.decorator.d.ts +4 -0
- package/dist/types/decorators/route.decorator.d.ts +6 -1
- package/dist/types/enrichers/router-response.enricher.d.ts +4 -0
- package/dist/types/errors/errors.d.ts +3 -1
- package/dist/types/errors/http.error.d.ts +1 -1
- package/dist/types/errors/method-router-adding.error.d.ts +10 -0
- package/dist/types/errors/path-router-adding.error.d.ts +4 -3
- package/dist/types/errors/path-router-instantiation.error.d.ts +4 -3
- package/dist/types/interfaces/controller-method-parameter-decorator-resolver.interface.d.ts +19 -2
- package/dist/types/interfaces/interfaces.d.ts +2 -2
- package/dist/types/interfaces/parameter-decorator.interface.d.ts +4 -0
- package/dist/types/interfaces/query-parameters-decorator.interface.d.ts +4 -0
- package/dist/types/interfaces/route-parameter-decorator.interface.d.ts +1 -1
- package/dist/types/interfaces/router.interface.d.ts +2 -2
- package/dist/types/models/models.d.ts +0 -1
- package/dist/types/models/request.d.ts +16 -4
- package/dist/types/models/response.d.ts +15 -0
- package/dist/types/models/route.d.ts +4 -0
- package/dist/types/nodes/method-router.node.d.ts +17 -4
- package/dist/types/nodes/path-router.node.d.ts +11 -7
- package/dist/types/nodes/router.node.d.ts +3 -3
- package/dist/types/resolvers/body-parameter-decorator.resolver.d.ts +22 -2
- package/dist/types/resolvers/controller-method-parameter-decorator.resolver.d.ts +14 -0
- package/dist/types/resolvers/headers-parameter-decorator.resolver.d.ts +22 -2
- package/dist/types/resolvers/identity-parameter-decorator.resolver.d.ts +22 -2
- package/dist/types/resolvers/query-parameter-decorator.resolver.d.ts +23 -2
- package/dist/types/resolvers/query-parameters-decorator.resolver.d.ts +22 -2
- package/dist/types/resolvers/route-parameter-decorator.resolver.d.ts +22 -2
- package/dist/types/router.d.ts +12 -0
- package/package.json +5 -5
- package/dist/lib/cjs/enums/enums.js +0 -1
- package/dist/lib/cjs/enums/enums.js.map +0 -1
- package/dist/lib/cjs/models/error-response-body.js +0 -7
- package/dist/lib/cjs/models/error-response-body.js.map +0 -1
- package/dist/lib/esm/enums/enums.js +0 -1
- package/dist/lib/esm/enums/enums.js.map +0 -1
- package/dist/lib/esm/models/error-response-body.js +0 -3
- package/dist/lib/esm/models/error-response-body.js.map +0 -1
- package/dist/types/enums/enums.d.ts +0 -0
- package/dist/types/models/error-response-body.d.ts +0 -4
|
@@ -8,12 +8,30 @@ import { injectable } from "tsyringe";
|
|
|
8
8
|
import { moduleScoped, ServiceDefinitionTagEnum, tag } from "@pristine-ts/common";
|
|
9
9
|
import { NetworkingModuleKeyname } from "../networking.module.keyname";
|
|
10
10
|
import Url from 'url-parse';
|
|
11
|
+
/**
|
|
12
|
+
* The QueryParametersDecoratorResolver resolves the value (a map) of the query parameters of the request so that it can be injected it into the
|
|
13
|
+
* parameter of the route of the controller that was annotated with the @queryParameters decorator.
|
|
14
|
+
* It is tagged as an MethodParameterDecoratorResolver so it can be automatically injected with the all the other MethodParameterDecoratorResolvers.
|
|
15
|
+
*/
|
|
11
16
|
let QueryParametersDecoratorResolver = class QueryParametersDecoratorResolver {
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the value of all the query parameters of the request.
|
|
19
|
+
* The router than injects that value into the parameter of the controller method.
|
|
20
|
+
* @param methodArgument The method argument created by the decorator.
|
|
21
|
+
* @param request The request
|
|
22
|
+
* @param routeParameters The router parameters
|
|
23
|
+
* @param identity The identity making the request
|
|
24
|
+
*/
|
|
12
25
|
resolve(methodArgument, request, routeParameters, identity) {
|
|
13
26
|
var _a;
|
|
14
27
|
const url = new Url(request.url, true);
|
|
15
28
|
return Promise.resolve((_a = url.query) !== null && _a !== void 0 ? _a : null);
|
|
16
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns whether or not the resolver support such a method argument.
|
|
32
|
+
* Usually we will check the methodArgument.type field to determine if it is a supported type.
|
|
33
|
+
* @param methodArgument
|
|
34
|
+
*/
|
|
17
35
|
supports(methodArgument) {
|
|
18
36
|
return methodArgument && methodArgument.hasOwnProperty("type") && methodArgument.type === "queryParameters";
|
|
19
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-parameters-decorator.resolver.js","sourceRoot":"","sources":["../../../../src/resolvers/query-parameters-decorator.resolver.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAoB,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AACrE,OAAO,GAAG,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"query-parameters-decorator.resolver.js","sourceRoot":"","sources":["../../../../src/resolvers/query-parameters-decorator.resolver.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAoB,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AACrE,OAAO,GAAG,MAAM,WAAW,CAAC;AAI5B;;;;GAIG;AAIH,IAAa,gCAAgC,GAA7C,MAAa,gCAAgC;IAEzC;;;;;;;OAOG;IACH,OAAO,CAAC,cAAiD,EACjD,OAAgB,EAChB,eAAwC,EACxC,QAA4B;;QAChC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAEvC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAA,GAAG,CAAC,KAAK,mCAAI,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,cAA2C;QAChD,OAAO,cAAc,IAAI,cAAc,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,cAAc,CAAC,IAAI,KAAK,iBAAiB,CAAC;IAChH,CAAC;CACJ,CAAA;AA3BY,gCAAgC;IAH5C,YAAY,CAAC,uBAAuB,CAAC;IACrC,GAAG,CAAC,wBAAwB,CAAC,gCAAgC,CAAC;IAC9D,UAAU,EAAE;GACA,gCAAgC,CA2B5C;SA3BY,gCAAgC"}
|
|
@@ -7,11 +7,29 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { injectable } from "tsyringe";
|
|
8
8
|
import { moduleScoped, ServiceDefinitionTagEnum, tag } from "@pristine-ts/common";
|
|
9
9
|
import { NetworkingModuleKeyname } from "../networking.module.keyname";
|
|
10
|
+
/**
|
|
11
|
+
* The RouteParameterDecoratorResolver resolves the value of the route parameter specified of the request so that it can be injected it into the
|
|
12
|
+
* parameter of the route of the controller that was annotated with the @routeParameter decorator.
|
|
13
|
+
* It is tagged as an MethodParameterDecoratorResolver so it can be automatically injected with the all the other MethodParameterDecoratorResolvers.
|
|
14
|
+
*/
|
|
10
15
|
let RouteParameterDecoratorResolver = class RouteParameterDecoratorResolver {
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the value of the the route parameter with the specified name of the request.
|
|
18
|
+
* The router than injects that value into the parameter of the controller method.
|
|
19
|
+
* @param methodArgument The method argument created by the decorator, including the name of the parameter to resolve.
|
|
20
|
+
* @param request The request
|
|
21
|
+
* @param routeParameters The router parameters
|
|
22
|
+
* @param identity The identity making the request
|
|
23
|
+
*/
|
|
11
24
|
resolve(methodArgument, request, routeParameters, identity) {
|
|
12
25
|
var _a;
|
|
13
26
|
return Promise.resolve((_a = routeParameters[methodArgument.routeParameterName]) !== null && _a !== void 0 ? _a : null);
|
|
14
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns whether or not the resolver support such a method argument.
|
|
30
|
+
* Usually we will check the methodArgument.type field to determine if it is a supported type.
|
|
31
|
+
* @param methodArgument
|
|
32
|
+
*/
|
|
15
33
|
supports(methodArgument) {
|
|
16
34
|
return methodArgument && methodArgument.hasOwnProperty("type") && methodArgument.type === "routeParameter";
|
|
17
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-parameter-decorator.resolver.js","sourceRoot":"","sources":["../../../../src/resolvers/route-parameter-decorator.resolver.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAoB,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"route-parameter-decorator.resolver.js","sourceRoot":"","sources":["../../../../src/resolvers/route-parameter-decorator.resolver.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAoB,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AAGrE;;;;GAIG;AAIH,IAAa,+BAA+B,GAA5C,MAAa,+BAA+B;IAExC;;;;;;;OAOG;IACH,OAAO,CAAC,cAAgD,EAChD,OAAgB,EAChB,eAAwC,EACxC,QAA4B;;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAA,eAAe,CAAC,cAAc,CAAC,kBAAkB,CAAC,mCAAI,IAAI,CAAC,CAAC;IACvF,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,cAA2C;QAChD,OAAO,cAAc,IAAI,cAAc,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,cAAc,CAAC,IAAI,KAAK,gBAAgB,CAAC;IAC/G,CAAC;CACJ,CAAA;AAzBY,+BAA+B;IAH3C,YAAY,CAAC,uBAAuB,CAAC;IACrC,GAAG,CAAC,wBAAwB,CAAC,gCAAgC,CAAC;IAC9D,UAAU,EAAE;GACA,+BAA+B,CAyB3C;SAzBY,+BAA+B"}
|
package/dist/lib/esm/router.js
CHANGED
|
@@ -30,7 +30,19 @@ import Url from 'url-parse';
|
|
|
30
30
|
import { ServiceDefinitionTagEnum } from "@pristine-ts/common";
|
|
31
31
|
import { NetworkingModuleKeyname } from "./networking.module.keyname";
|
|
32
32
|
import { SpanKeynameEnum } from "@pristine-ts/telemetry";
|
|
33
|
+
/**
|
|
34
|
+
* The router service is the service that creates the routing tree from the controllers.
|
|
35
|
+
* It also executes a request properly by routing it to the intended controller and returns the response.
|
|
36
|
+
*/
|
|
33
37
|
let Router = class Router {
|
|
38
|
+
/**
|
|
39
|
+
* The router service is the service that creates the routing tree from the controllers.
|
|
40
|
+
* It also executes a request properly by routing it to the intended controller and returns the response.
|
|
41
|
+
* @param loghandler The log handler
|
|
42
|
+
* @param controllerMethodParameterDecoratorResolver The controller method parameter decorator resolver used to resolve the values.
|
|
43
|
+
* @param authorizerManager The authorizer manager to validate authorization.
|
|
44
|
+
* @param authenticationManager The authentication manager to validate authentication.
|
|
45
|
+
*/
|
|
34
46
|
constructor(loghandler, controllerMethodParameterDecoratorResolver, authorizerManager, authenticationManager) {
|
|
35
47
|
this.loghandler = loghandler;
|
|
36
48
|
this.controllerMethodParameterDecoratorResolver = controllerMethodParameterDecoratorResolver;
|
|
@@ -96,6 +108,7 @@ let Router = class Router {
|
|
|
96
108
|
routeParameters
|
|
97
109
|
}, NetworkingModuleKeyname);
|
|
98
110
|
let identity;
|
|
111
|
+
// Authenticate the request
|
|
99
112
|
try {
|
|
100
113
|
const routerRequestAuthenticationSpan = tracingManager.startSpan(SpanKeynameEnum.RouterRequestAuthentication, SpanKeynameEnum.RouterRequestExecution);
|
|
101
114
|
identity = yield this.authenticationManager.authenticate(request, methodNode.route.context, container);
|
|
@@ -120,6 +133,7 @@ let Router = class Router {
|
|
|
120
133
|
}
|
|
121
134
|
// Call the controller with the resolved Method arguments
|
|
122
135
|
try {
|
|
136
|
+
// Verify that the identity making the request is authorized to make such a request
|
|
123
137
|
if ((yield this.authorizerManager.isAuthorized(request, methodNode.route.context, container, identity)) === false) {
|
|
124
138
|
this.loghandler.error("User not authorized to access this url.", {
|
|
125
139
|
request,
|
|
@@ -130,6 +144,7 @@ let Router = class Router {
|
|
|
130
144
|
routerRequestExecutionSpan.end();
|
|
131
145
|
return reject(new ForbiddenHttpError("You are not allowed to access this."));
|
|
132
146
|
}
|
|
147
|
+
// Execute all the enrichers to enrich the request.
|
|
133
148
|
const requestEnrichersSpan = tracingManager.startSpan(SpanKeynameEnum.RouterRequestEnrichers, SpanKeynameEnum.RouterRequestExecution);
|
|
134
149
|
const enrichedRequest = yield this.executeRequestEnrichers(request, container, methodNode);
|
|
135
150
|
requestEnrichersSpan.end();
|
|
@@ -137,6 +152,7 @@ let Router = class Router {
|
|
|
137
152
|
request,
|
|
138
153
|
enrichedRequest,
|
|
139
154
|
}, NetworkingModuleKeyname);
|
|
155
|
+
// Resolve the value to inject in the method arguments that have a decorator resolver
|
|
140
156
|
const resolvedMethodArguments = [];
|
|
141
157
|
for (const methodArgument of methodNode.route.methodArguments) {
|
|
142
158
|
resolvedMethodArguments.push(yield this.controllerMethodParameterDecoratorResolver.resolve(methodArgument, enrichedRequest, routeParameters, identity));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAsB,MAAM,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AAEhE,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAC,iBAAiB,EAAC,MAAM,+BAA+B,CAAC;AAGhE,OAAO,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AAGxD,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAC,0CAA0C,EAAC,MAAM,4DAA4D,CAAC;AACtH,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,EAAgC,wBAAwB,EAAC,MAAM,qBAAqB,CAAC;AAK5F,OAAO,EAAC,uBAAuB,EAAC,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAO,eAAe,EAA0B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAsB,MAAM,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AAEhE,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAC,iBAAiB,EAAC,MAAM,+BAA+B,CAAC;AAGhE,OAAO,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AAGxD,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAC,0CAA0C,EAAC,MAAM,4DAA4D,CAAC;AACtH,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,E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,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;oBAC9B,+HAA+H;oBAC/H,2EAA2E;oBAC3E,IAAI,OAAO,QAAQ,CAAC,aAAa,KAAK,WAAW,EAAE;wBAC/C,kCAAkC;wBAClC,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,GAAG,yHAAyH,CAAC,CAAA;qBAClN;oBAED,IAAI;wBACA,8CAA8C;wBAC9C,eAAe,GAAG,MAAM,OAAO,CAAC,OAAO,CAAE,QAA2C,CAAC,aAAa,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC,CAAC;qBACpI;oBAAC,OAAO,CAAC,EAAE;wBACR,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,kHAAkH,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,GAAG,IAAI,EAAE,EAAC,CAAC,EAAC,EAAE,uBAAuB,CAAC,CAAC;wBAC3M,MAAM,CAAC,CAAC;qBACX;iBACJ;aACJ;YAED,OAAO,eAAe,CAAC;QAC3B,CAAC;KAAA;CACJ,CAAA;AA/QY,MAAM;IADlB,SAAS,EAAE;IAYa,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;IAE7B,WAAA,MAAM,CAAC,4BAA4B,CAAC,CAAA;IACpC,WAAA,MAAM,CAAC,gCAAgC,CAAC,CAAA;6CAFoB,0CAA0C;GAZlH,MAAM,CA+QlB;SA/QY,MAAM"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export declare const controllerRegistry: any[];
|
|
2
|
+
/**
|
|
3
|
+
* The controller decorator can be used on a class to register this class as a controller in the router.
|
|
4
|
+
* @param basePath The base path for all the routes in the controller.
|
|
5
|
+
*/
|
|
2
6
|
export declare const controller: (basePath: string) => (constructor: Function) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./body.decorator";
|
|
2
2
|
export * from "./controller.decorator";
|
|
3
|
-
export * from "./identity.decorator";
|
|
4
3
|
export * from "./headers.decorator";
|
|
4
|
+
export * from "./identity.decorator";
|
|
5
5
|
export * from "./query-parameter.decorator";
|
|
6
6
|
export * from "./query-parameters.decorator";
|
|
7
7
|
export * from "./request.decorator";
|
|
@@ -1 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The queryParameter decorator can be used to inject a specific query parameter of a request in a parameter of a method in a controller.
|
|
3
|
+
* @param name The name of the query parameter to inject.
|
|
4
|
+
*/
|
|
1
5
|
export declare const queryParameter: (name: string) => (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The responseHeader decorator can be used to specify a header that needs to be added to the response before sending it back.
|
|
3
|
+
* This decorator can be used with either method (route) or a class (controller).
|
|
4
|
+
* If used on the class than it will be applied to every route of the controller.
|
|
5
|
+
* @param key The key of the header
|
|
6
|
+
* @param value The value to set the header to.
|
|
7
|
+
*/
|
|
1
8
|
export declare const responseHeader: (key: string, value: string) => (target: any, propertyKey?: string | undefined, descriptor?: PropertyDescriptor | undefined) => void;
|
|
@@ -1 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The routeParameter decorator can be used to inject a specific route parameter of a request in a parameter of a method in a controller.
|
|
3
|
+
* @param name The name of the route(path) parameter to inject.
|
|
4
|
+
*/
|
|
1
5
|
export declare const routeParameter: (name: string) => (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { HttpMethod } from "@pristine-ts/common";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The route decorator can be used on a method to register this method as a route of the controller in the router.
|
|
4
|
+
* @param httpMethod The http method of the route
|
|
5
|
+
* @param path The part of the path following the base path of the controller. For path parameters use the colons. (ie: resources/:id)
|
|
6
|
+
*/
|
|
7
|
+
export declare const route: (httpMethod: HttpMethod | string, path: string) => (target: Object, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -2,6 +2,10 @@ import { Response } from "../models/response";
|
|
|
2
2
|
import { Request } from "../models/request";
|
|
3
3
|
import { RouterResponseEnricherInterface } from "../interfaces/router-response-enricher.interface";
|
|
4
4
|
import { MethodRouterNode } from "../nodes/method-router.node";
|
|
5
|
+
/**
|
|
6
|
+
* The RouterResponseEnricher enriches the response of the router by adding the response headers specified by the response header decorator.
|
|
7
|
+
* It is tagged as an RouterResponseEnricher so it can be automatically injected with the all the other RouterResponseEnrichers.
|
|
8
|
+
*/
|
|
5
9
|
export declare class RouterResponseEnricher implements RouterResponseEnricherInterface {
|
|
6
10
|
enrichResponse(response: Response, request: Request, methodNode: MethodRouterNode): Promise<Response>;
|
|
7
11
|
}
|
|
@@ -2,5 +2,7 @@ export * from "./bad-request.http-error";
|
|
|
2
2
|
export * from "./forbidden.http-error";
|
|
3
3
|
export * from "./http.error";
|
|
4
4
|
export * from "./invalid-body.http-error";
|
|
5
|
-
export * from "./
|
|
5
|
+
export * from "./method-router-adding.error";
|
|
6
6
|
export * from "./not-found.http-error";
|
|
7
|
+
export * from "./path-router-adding.error";
|
|
8
|
+
export * from "./path-router-instantiation.error";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
1
2
|
/**
|
|
2
3
|
* This class defines a basic HttpError. In your code, feel free to throw an HttpError to have this error returned via HTTP.
|
|
3
4
|
* If you throw this error when handling an Event, it won't be returned.
|
|
4
5
|
*/
|
|
5
|
-
import { LoggableError } from "@pristine-ts/common";
|
|
6
6
|
export declare class HttpError extends LoggableError {
|
|
7
7
|
readonly httpStatus: number;
|
|
8
8
|
readonly message: string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HttpMethod, LoggableError } from "@pristine-ts/common";
|
|
2
|
+
import { Route } from "../models/route";
|
|
3
|
+
import { MethodRouterNode } from "../nodes/method-router.node";
|
|
4
|
+
/**
|
|
5
|
+
* This Error is thrown when there's an error that happens when the networking is being initialized.
|
|
6
|
+
* It is thrown when trying to add a child node to a MethodRouterNode, since a MethodRouterNode is a leaf it cannot have any children.
|
|
7
|
+
*/
|
|
8
|
+
export declare class MethodRouterAddingError extends LoggableError {
|
|
9
|
+
constructor(message: string, splitPaths: string[], method: HttpMethod | string, route: Route, methodRouterNode: MethodRouterNode);
|
|
10
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This Error is thrown when there's an error that happens when the networking is being initialized
|
|
3
|
-
*/
|
|
4
1
|
import { HttpMethod, LoggableError } from "@pristine-ts/common";
|
|
5
2
|
import { PathRouterNode } from "../nodes/path-router.node";
|
|
6
3
|
import { Route } from "../models/route";
|
|
4
|
+
/**
|
|
5
|
+
* This Error is thrown when there's an error that happens when the networking is being initialized.
|
|
6
|
+
* It is thrown when an error occurs when trying to add a child node to a PathRouterNode.
|
|
7
|
+
*/
|
|
7
8
|
export declare class PathRouterAddingError extends LoggableError {
|
|
8
9
|
constructor(message: string, splitPaths: string[], method: HttpMethod | string, route: Route, pathRouterNode: PathRouterNode);
|
|
9
10
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This Error is thrown when there's an error that happens when the networking is being initialized
|
|
3
|
-
*/
|
|
4
1
|
import { LoggableError } from "@pristine-ts/common";
|
|
5
2
|
import { PathRouterNode } from "../nodes/path-router.node";
|
|
3
|
+
/**
|
|
4
|
+
* This Error is thrown when there's an error that happens when the networking is being initialized.
|
|
5
|
+
* It is thrown when an error occurs when trying to instantiate a PathRouterNode.
|
|
6
|
+
*/
|
|
6
7
|
export declare class PathRouterInstantiationError extends LoggableError {
|
|
7
8
|
constructor(message: string, path: string, parent?: PathRouterNode);
|
|
8
9
|
}
|
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { Request } from "../models/request";
|
|
2
2
|
import { IdentityInterface } from "@pristine-ts/common";
|
|
3
|
+
import { ParameterDecoratorInterface } from "./parameter-decorator.interface";
|
|
4
|
+
/**
|
|
5
|
+
* This interface defines the methods that a decorator resolver for method parameter in a controller must implement.
|
|
6
|
+
*/
|
|
3
7
|
export interface ControllerMethodParameterDecoratorResolverInterface {
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Returns whether or not the resolver support such a method argument.
|
|
10
|
+
* Usually we will check the methodArgument.type field to determine if it is a supported type.
|
|
11
|
+
* @param methodArgument
|
|
12
|
+
*/
|
|
13
|
+
supports(methodArgument: ParameterDecoratorInterface): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the value for the decorator.
|
|
16
|
+
* The router than injects that value into the parameter of the controller method.
|
|
17
|
+
* @param methodArgument The information on where to retrieve the value.
|
|
18
|
+
* @param request The request itself.
|
|
19
|
+
* @param routeParameters The parameters and their values in the route of the controller.
|
|
20
|
+
* @param identity The identity making the request
|
|
21
|
+
*/
|
|
22
|
+
resolve(methodArgument: ParameterDecoratorInterface, request: Request, routeParameters: {
|
|
6
23
|
[key: string]: string;
|
|
7
24
|
}, identity?: IdentityInterface): Promise<any>;
|
|
8
25
|
}
|
|
@@ -6,8 +6,8 @@ export * from "./parameter-decorator.interface";
|
|
|
6
6
|
export * from "./query-parameter-decorator.interface";
|
|
7
7
|
export * from "./query-parameters-decorator.interface";
|
|
8
8
|
export * from "./request-parameter-decorator.interface";
|
|
9
|
-
export * from "./router-request-enricher.interface";
|
|
10
|
-
export * from "./router-response-enricher.interface";
|
|
11
9
|
export * from "./route-method-decorator.interface";
|
|
12
10
|
export * from "./route-parameter-decorator.interface";
|
|
13
11
|
export * from "./router.interface";
|
|
12
|
+
export * from "./router-request-enricher.interface";
|
|
13
|
+
export * from "./router-response-enricher.interface";
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { ParameterDecoratorInterface } from "./parameter-decorator.interface";
|
|
2
|
+
/**
|
|
3
|
+
* This interface represents the object that will contain the information required to know how to handle the
|
|
4
|
+
* @queryParameters decorator.
|
|
5
|
+
*/
|
|
2
6
|
export interface QueryParametersDecoratorInterface extends ParameterDecoratorInterface {
|
|
3
7
|
type: "queryParameters";
|
|
4
8
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ParameterDecoratorInterface } from "./parameter-decorator.interface";
|
|
2
2
|
/**
|
|
3
3
|
* This interface represents the object that will contain the information to know how to handle the
|
|
4
|
-
* @
|
|
4
|
+
* @routeParameter decorator.
|
|
5
5
|
*/
|
|
6
6
|
export interface RouteParameterDecoratorInterface extends ParameterDecoratorInterface {
|
|
7
7
|
type: "routeParameter";
|
|
@@ -4,7 +4,7 @@ import { Response } from "../models/response";
|
|
|
4
4
|
import { Request } from "../models/request";
|
|
5
5
|
import { Route } from "../models/route";
|
|
6
6
|
/**
|
|
7
|
-
* This
|
|
7
|
+
* This interface defines the methods that the router must implement.
|
|
8
8
|
*/
|
|
9
9
|
export interface RouterInterface {
|
|
10
10
|
/**
|
|
@@ -18,7 +18,7 @@ export interface RouterInterface {
|
|
|
18
18
|
register(path: string, method: HttpMethod | string, route: Route): any;
|
|
19
19
|
/**
|
|
20
20
|
* This method executes the request passed as a parameter. A container must also be passed since we want each
|
|
21
|
-
* request to have its own container so that memory isn't
|
|
21
|
+
* request to have its own container so that memory isn't accidentally shared between requests.
|
|
22
22
|
*
|
|
23
23
|
* @param request
|
|
24
24
|
* @param container
|
|
@@ -4,30 +4,42 @@ import { RequestInterface } from "@pristine-ts/common";
|
|
|
4
4
|
* This Request object represents the class used internally that represents a Request.
|
|
5
5
|
*/
|
|
6
6
|
export declare class Request implements RequestInterface {
|
|
7
|
+
/**
|
|
8
|
+
* The http method of the request.
|
|
9
|
+
*/
|
|
7
10
|
httpMethod: HttpMethod | string;
|
|
11
|
+
/**
|
|
12
|
+
* The url of the request.
|
|
13
|
+
*/
|
|
8
14
|
url: string;
|
|
15
|
+
/**
|
|
16
|
+
* The headers of the request.
|
|
17
|
+
*/
|
|
9
18
|
headers: {
|
|
10
19
|
[key: string]: string;
|
|
11
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* The body of the request.
|
|
23
|
+
*/
|
|
12
24
|
body: any;
|
|
13
25
|
constructor(requestInterface: RequestInterface);
|
|
14
26
|
/**
|
|
15
27
|
* This method sets a header parameter in the Request.
|
|
16
28
|
*
|
|
17
|
-
* @param name
|
|
18
|
-
* @param value
|
|
29
|
+
* @param name The name of the header.
|
|
30
|
+
* @param value The value of the header.
|
|
19
31
|
*/
|
|
20
32
|
setHeader(name: string, value: string): void;
|
|
21
33
|
/**
|
|
22
34
|
* This method returns whether or not the header exists in the Request.
|
|
23
35
|
*
|
|
24
|
-
* @param name
|
|
36
|
+
* @param name The name of the header.
|
|
25
37
|
*/
|
|
26
38
|
hasHeader(name: string): boolean;
|
|
27
39
|
/**
|
|
28
40
|
* This method returns the header corresponding to the name or undefined if it doesn't exist.
|
|
29
41
|
*
|
|
30
|
-
* @param name
|
|
42
|
+
* @param name The name of the header.
|
|
31
43
|
*/
|
|
32
44
|
getHeader(name: string): string | undefined;
|
|
33
45
|
}
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { RequestInterface } from "@pristine-ts/common";
|
|
2
|
+
/**
|
|
3
|
+
* This Response object represents the class used internally that represents a Response.
|
|
4
|
+
*/
|
|
2
5
|
export declare class Response {
|
|
6
|
+
/**
|
|
7
|
+
* The status code of the response. By default we return a 200.
|
|
8
|
+
*/
|
|
3
9
|
status: number;
|
|
10
|
+
/**
|
|
11
|
+
* The headers of the response.
|
|
12
|
+
*/
|
|
4
13
|
headers?: {
|
|
5
14
|
[key: string]: string;
|
|
6
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* The body of the response.
|
|
18
|
+
*/
|
|
7
19
|
body?: any;
|
|
20
|
+
/**
|
|
21
|
+
* The request that triggered this response.
|
|
22
|
+
*/
|
|
8
23
|
request?: RequestInterface;
|
|
9
24
|
}
|
|
@@ -13,5 +13,9 @@ export declare class Route {
|
|
|
13
13
|
* This contains the Route context for dynamic usage.
|
|
14
14
|
*/
|
|
15
15
|
context?: any;
|
|
16
|
+
/**
|
|
17
|
+
* @param controllerInstantiationToken The instantiation token of the controller. Usually this will be the controller's constructor name.
|
|
18
|
+
* @param methodPropertyKey The name of the method that corresponds to the route in the controller.
|
|
19
|
+
*/
|
|
16
20
|
constructor(controllerInstantiationToken: any, methodPropertyKey: string);
|
|
17
21
|
}
|
|
@@ -4,12 +4,24 @@ import { PathRouterNode } from "./path-router.node";
|
|
|
4
4
|
import { Route } from "../models/route";
|
|
5
5
|
/**
|
|
6
6
|
* This class represents the Leaf node of the RouteTree.
|
|
7
|
+
* It will always have a parent node that will be a PathRouterNode.
|
|
7
8
|
*/
|
|
8
9
|
export declare class MethodRouterNode extends RouterNode {
|
|
9
10
|
readonly method: HttpMethod | string;
|
|
10
11
|
readonly route: Route;
|
|
11
12
|
readonly levelFromRoot: number;
|
|
13
|
+
/**
|
|
14
|
+
* @param parent The parent node of the current node.
|
|
15
|
+
* @param method The http method of the current method node.
|
|
16
|
+
* @param route The route associated with the current node.
|
|
17
|
+
* @param levelFromRoot The depth level from the root node.
|
|
18
|
+
*/
|
|
12
19
|
constructor(parent: PathRouterNode, method: HttpMethod | string, route: Route, levelFromRoot: number);
|
|
20
|
+
/**
|
|
21
|
+
* Returns whether or not the node matches.
|
|
22
|
+
* This verification is made by verify the http method matches with the http method of the current node.
|
|
23
|
+
* @param method The http method to compare.
|
|
24
|
+
*/
|
|
13
25
|
matches(method: HttpMethod | string): boolean;
|
|
14
26
|
/**
|
|
15
27
|
* A MethodRouterNode is never a catch-all node.
|
|
@@ -17,19 +29,20 @@ export declare class MethodRouterNode extends RouterNode {
|
|
|
17
29
|
isCatchAll(): boolean;
|
|
18
30
|
/**
|
|
19
31
|
* This method adds all the required nodes to match the splitPaths and the method.
|
|
20
|
-
*
|
|
32
|
+
* Since a MethodRouterNode is a leaf node, you can't add anything after it, this method therefore doesn't do anything.
|
|
21
33
|
* @param splitPaths
|
|
22
34
|
* @param method
|
|
23
35
|
* @param route
|
|
24
36
|
*/
|
|
25
37
|
add(splitPaths: string[], method: HttpMethod | string, route: Route): void;
|
|
26
38
|
/**
|
|
27
|
-
* This method
|
|
39
|
+
* This method receives an array of path and recursively calls its children if this node matches
|
|
40
|
+
* the first splitPath. If the node is a MethodRouterNode, it checks to see if the method matches. If yes,
|
|
28
41
|
* it returns itself as the node found. This method should always return a MethodRouterNode. However, Typescript
|
|
29
42
|
* doesn't like these recursive imports so we return the base class
|
|
30
43
|
*
|
|
31
|
-
* @param splitPaths
|
|
32
|
-
* @param method
|
|
44
|
+
* @param splitPaths A list of all the parts of the paths spliced at the forward slashes.
|
|
45
|
+
* @param method The http method for which to find a node.
|
|
33
46
|
*/
|
|
34
47
|
find(splitPaths: string[], method: HttpMethod | string): RouterNode | null;
|
|
35
48
|
}
|
|
@@ -6,13 +6,17 @@ import { Route } from "../models/route";
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class PathRouterNode extends RouterNode {
|
|
8
8
|
readonly path: string;
|
|
9
|
+
/**
|
|
10
|
+
* @param path The path associated with the current node.
|
|
11
|
+
* @param parent The parent node of the current node.
|
|
12
|
+
*/
|
|
9
13
|
constructor(path: string, parent?: PathRouterNode);
|
|
10
14
|
/**
|
|
11
15
|
* This method adds all the required nodes to match the splitPaths and the method.
|
|
12
16
|
*
|
|
13
|
-
* @param splitPaths
|
|
14
|
-
* @param method
|
|
15
|
-
* @param route
|
|
17
|
+
* @param splitPaths A list of all the parts of the paths spliced at the forward slashes.
|
|
18
|
+
* @param method The http method for this route.
|
|
19
|
+
* @param route The route.
|
|
16
20
|
*/
|
|
17
21
|
add(splitPaths: string[], method: HttpMethod | string, route: Route, levelFromRoot: number): void;
|
|
18
22
|
/**
|
|
@@ -21,14 +25,14 @@ export declare class PathRouterNode extends RouterNode {
|
|
|
21
25
|
* it returns itself as the node found. This method should always return a MethodRouterNode. However, Typescript
|
|
22
26
|
* doesn't like these recursive imports so we return the base class
|
|
23
27
|
*
|
|
24
|
-
* @param splitPaths
|
|
25
|
-
* @param method
|
|
28
|
+
* @param splitPaths A list of all the parts of the paths spliced at the forward slashes.
|
|
29
|
+
* @param method The http method for which to find a node.
|
|
26
30
|
*/
|
|
27
31
|
find(splitPaths: string[], method: HttpMethod | string): RouterNode | null;
|
|
28
32
|
/**
|
|
29
33
|
* This httpMethod navigates the tree upwards and returns all the routeParameters
|
|
30
34
|
*
|
|
31
|
-
* @param splitPaths
|
|
35
|
+
* @param splitPaths A list of all the parts of the paths spliced at the forward slashes.
|
|
32
36
|
*/
|
|
33
37
|
getRouteParameters(splitPaths: string[]): {
|
|
34
38
|
[key: string]: string;
|
|
@@ -38,7 +42,7 @@ export declare class PathRouterNode extends RouterNode {
|
|
|
38
42
|
*/
|
|
39
43
|
isCatchAll(): boolean;
|
|
40
44
|
/**
|
|
41
|
-
* This method returns whether or not this pathRouterNode represents a route parameter, e.g.: /{id} or
|
|
45
|
+
* This method returns whether or not this pathRouterNode represents a route parameter, e.g.: /{id} or /:id
|
|
42
46
|
*/
|
|
43
47
|
isRouteParameter(): boolean;
|
|
44
48
|
/**
|
|
@@ -20,7 +20,7 @@ export declare abstract class RouterNode {
|
|
|
20
20
|
/**
|
|
21
21
|
* This method adds all the required nodes to match the splitPaths and the method.
|
|
22
22
|
*
|
|
23
|
-
* @param splitPaths
|
|
23
|
+
* @param splitPaths A list of all the parts of the paths spliced at the forward slashes.
|
|
24
24
|
* @param method
|
|
25
25
|
* @param route
|
|
26
26
|
* @param levelFromRoot This parameter represents the number of level from the root. The root is at 0.
|
|
@@ -32,8 +32,8 @@ export declare abstract class RouterNode {
|
|
|
32
32
|
* it returns itself as the node found. This method should always return a MethodRouterNode. However, Typescript
|
|
33
33
|
* doesn't like these recursive imports so we return the base class
|
|
34
34
|
*
|
|
35
|
-
* @param splitPaths
|
|
36
|
-
* @param method
|
|
35
|
+
* @param splitPaths A list of all the parts of the paths spliced at the forward slashes.
|
|
36
|
+
* @param method The http method for which to find a node.
|
|
37
37
|
*/
|
|
38
38
|
abstract find(splitPaths: string[], method: HttpMethod | string): RouterNode | null;
|
|
39
39
|
/**
|