@venok/http 1.1.0 → 2.0.0
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/constants.js +33 -0
- package/dist/decorators/controller.decorator.js +45 -0
- package/dist/decorators/header.decorator.js +28 -0
- package/dist/decorators/http-code.decorator.js +22 -0
- package/dist/decorators/http-params.decorator.js +63 -0
- package/dist/decorators/method.decorator.js +57 -0
- package/dist/decorators/redirect.decorator.js +28 -0
- package/dist/decorators/version.decorator.js +31 -0
- package/dist/enums/method.enum.js +32 -0
- package/dist/enums/paramtypes.enum.js +33 -0
- package/dist/enums/status.enum.js +71 -0
- package/dist/enums/version-type.enum.js +27 -0
- package/dist/exceptions/bad-gateway.exception.js +29 -0
- package/dist/exceptions/bad-request.exception.js +29 -0
- package/dist/exceptions/conflict.exception.js +29 -0
- package/dist/exceptions/expectation-failed.exception.js +29 -0
- package/dist/exceptions/failed-dependency.exception.js +29 -0
- package/dist/exceptions/forbidden.exception.js +29 -0
- package/dist/exceptions/gateway-timeout.exception.js +29 -0
- package/dist/exceptions/gone.exception.js +29 -0
- package/dist/exceptions/http-version-not-supported.exception.js +29 -0
- package/dist/exceptions/http.exception.js +94 -0
- package/dist/exceptions/im-a-teapot.exception.js +29 -0
- package/dist/exceptions/internal-server-error.exception.js +29 -0
- package/dist/exceptions/length-required.exception.js +29 -0
- package/dist/exceptions/method-not-allowed.exception.js +29 -0
- package/dist/exceptions/misdirected.exception.js +29 -0
- package/dist/exceptions/not-acceptable.exception.js +29 -0
- package/dist/exceptions/not-found.exception.js +29 -0
- package/dist/exceptions/not-implemented.exception.js +29 -0
- package/dist/exceptions/payload-too-large.exception.js +29 -0
- package/dist/exceptions/payment-required.exception.js +29 -0
- package/dist/exceptions/precondition-failed.exception.js +29 -0
- package/dist/exceptions/precondition-required.exception.js +29 -0
- package/dist/exceptions/proxy-authentication-required.exception.js +29 -0
- package/dist/exceptions/request-timeout.exception.js +29 -0
- package/dist/exceptions/requested-range-not-satisfiable.exception.js +29 -0
- package/dist/exceptions/service-unavailable.exception.js +29 -0
- package/dist/exceptions/too-many-requests.exception.js +29 -0
- package/dist/exceptions/unauthorized.exception.js +29 -0
- package/dist/exceptions/unprocessable-entity.exception.js +29 -0
- package/dist/exceptions/unsupported-media-type.exception.js +29 -0
- package/dist/exceptions/uri-too-long.exception.js +29 -0
- package/dist/filters/context.js +28 -0
- package/dist/filters/filter.js +56 -0
- package/dist/helpers/discovery.helper.js +69 -0
- package/dist/helpers/messages.helper.js +41 -0
- package/dist/helpers/middleware.helper.js +69 -0
- package/dist/helpers/path.helper.js +53 -0
- package/dist/helpers/route.helper.js +54 -0
- package/dist/http/adapter.js +294 -0
- package/dist/http/config.js +67 -0
- package/dist/http/configurable-module.js +26 -0
- package/dist/http/context.js +117 -0
- package/dist/http/explorer.js +133 -0
- package/dist/http/module.js +35 -0
- package/dist/http/starter-module.js +85 -0
- package/dist/index.d.ts +2117 -0
- package/dist/index.js +82 -0
- package/dist/interfaces/adapter.interface.js +0 -0
- package/dist/interfaces/exception.interface.js +0 -0
- package/dist/interfaces/index.js +7 -0
- package/dist/interfaces/middleware/config-proxy.interface.js +0 -0
- package/dist/interfaces/middleware/consumer.interface.js +0 -0
- package/dist/interfaces/middleware/index.js +3 -0
- package/dist/interfaces/options.interface.js +0 -0
- package/dist/interfaces/prefix.interface.js +0 -0
- package/dist/interfaces/router/definition.interface.js +0 -0
- package/dist/interfaces/router/exclude-route.interface.js +0 -0
- package/dist/interfaces/router/index.js +7 -0
- package/dist/interfaces/router/info.interface.js +0 -0
- package/dist/interfaces/router/path-metadata.interface.js +0 -0
- package/dist/interfaces/router/tree.interface.js +0 -0
- package/dist/interfaces/router/version.interface.js +21 -0
- package/dist/middleware/builder.js +96 -0
- package/dist/middleware/module.js +22 -0
- package/dist/middleware/routes-mapper.js +107 -0
- package/dist/middleware/service.js +48 -0
- package/dist/middleware/tree.js +91 -0
- package/dist/router/finder.js +64 -0
- package/dist/router/module.js +89 -0
- package/dist/router/path-factory.js +110 -0
- package/dist/symbols.js +33 -0
- package/package.json +41 -46
- package/adapter/adapter.d.ts +0 -57
- package/adapter/adapter.js +0 -58
- package/adapter/host.d.ts +0 -27
- package/adapter/host.js +0 -33
- package/application/application.d.ts +0 -18
- package/application/application.js +0 -51
- package/application/config.d.ts +0 -16
- package/application/config.js +0 -47
- package/application/http.module-defenition.d.ts +0 -8
- package/application/http.module-defenition.js +0 -6
- package/application/http.module.d.ts +0 -3
- package/application/http.module.js +0 -21
- package/application/http.service.d.ts +0 -11
- package/application/http.service.js +0 -43
- package/application/starter.d.ts +0 -41
- package/application/starter.js +0 -140
- package/constants.d.ts +0 -12
- package/constants.js +0 -15
- package/context/context.d.ts +0 -56
- package/context/context.js +0 -102
- package/context/response.controller.d.ts +0 -30
- package/context/response.controller.js +0 -86
- package/decorators/controller.decorator.d.ts +0 -82
- package/decorators/controller.decorator.js +0 -53
- package/decorators/header.decorator.d.ts +0 -12
- package/decorators/header.decorator.js +0 -23
- package/decorators/http-code.decorator.d.ts +0 -9
- package/decorators/http-code.decorator.js +0 -19
- package/decorators/index.d.ts +0 -9
- package/decorators/index.js +0 -25
- package/decorators/redirect.decorator.d.ts +0 -6
- package/decorators/redirect.decorator.js +0 -16
- package/decorators/render.decorator.d.ts +0 -10
- package/decorators/render.decorator.js +0 -20
- package/decorators/request-mapping.decorator.d.ts +0 -78
- package/decorators/request-mapping.decorator.js +0 -98
- package/decorators/route-params.decorator.d.ts +0 -378
- package/decorators/route-params.decorator.js +0 -227
- package/decorators/sse.decorator.d.ts +0 -6
- package/decorators/sse.decorator.js +0 -20
- package/decorators/version.decorator.d.ts +0 -7
- package/decorators/version.decorator.js +0 -20
- package/enums/http-status.enum.d.ts +0 -53
- package/enums/http-status.enum.js +0 -57
- package/enums/index.d.ts +0 -4
- package/enums/index.js +0 -20
- package/enums/request-method.enum.d.ts +0 -11
- package/enums/request-method.enum.js +0 -15
- package/enums/route-paramtypes.enum.d.ts +0 -14
- package/enums/route-paramtypes.enum.js +0 -18
- package/enums/version-type.enum.d.ts +0 -9
- package/enums/version-type.enum.js +0 -13
- package/errors/bad-gateway.exception.d.ts +0 -33
- package/errors/bad-gateway.exception.js +0 -41
- package/errors/bad-request.exception.d.ts +0 -33
- package/errors/bad-request.exception.js +0 -41
- package/errors/conflict.exception.d.ts +0 -33
- package/errors/conflict.exception.js +0 -41
- package/errors/forbidden.exception.d.ts +0 -33
- package/errors/forbidden.exception.js +0 -41
- package/errors/gateway-timeout.exception.d.ts +0 -33
- package/errors/gateway-timeout.exception.js +0 -41
- package/errors/gone.exception.d.ts +0 -33
- package/errors/gone.exception.js +0 -41
- package/errors/http-version-not-supported.exception.d.ts +0 -33
- package/errors/http-version-not-supported.exception.js +0 -41
- package/errors/http.exception.d.ts +0 -79
- package/errors/http.exception.js +0 -123
- package/errors/im-a-teapot.exception.d.ts +0 -36
- package/errors/im-a-teapot.exception.js +0 -44
- package/errors/index.d.ts +0 -11
- package/errors/index.js +0 -27
- package/errors/internal-server-error.exception.d.ts +0 -33
- package/errors/internal-server-error.exception.js +0 -41
- package/errors/invalid-middleware-configuration.exception.d.ts +0 -4
- package/errors/invalid-middleware-configuration.exception.js +0 -11
- package/errors/invalid-middleware.exception.d.ts +0 -4
- package/errors/invalid-middleware.exception.js +0 -11
- package/errors/not-found.exception.d.ts +0 -33
- package/errors/not-found.exception.js +0 -41
- package/errors/unknown-request-mapping.exception.d.ts +0 -5
- package/errors/unknown-request-mapping.exception.js +0 -11
- package/exceptions/messages.d.ts +0 -4
- package/exceptions/messages.js +0 -13
- package/explorers/path.explorer.d.ts +0 -8
- package/explorers/path.explorer.js +0 -38
- package/explorers/router.explorer.d.ts +0 -51
- package/explorers/router.explorer.js +0 -195
- package/factory/context-id.factory.d.ts +0 -41
- package/factory/context-id.factory.js +0 -52
- package/factory/index.d.ts +0 -4
- package/factory/index.js +0 -20
- package/factory/method.factory.d.ts +0 -5
- package/factory/method.factory.js +0 -30
- package/factory/params.factory.d.ts +0 -5
- package/factory/params.factory.js +0 -39
- package/factory/path.factory.d.ts +0 -13
- package/factory/path.factory.js +0 -95
- package/filters/context.d.ts +0 -9
- package/filters/context.js +0 -15
- package/filters/filter.d.ts +0 -22
- package/filters/filter.js +0 -78
- package/helpers/adapter.helper.d.ts +0 -27
- package/helpers/adapter.helper.js +0 -37
- package/helpers/exclude-route.helper.d.ts +0 -4
- package/helpers/exclude-route.helper.js +0 -18
- package/helpers/flatten-routes.helper.d.ts +0 -5
- package/helpers/flatten-routes.helper.js +0 -27
- package/helpers/index.d.ts +0 -6
- package/helpers/index.js +0 -22
- package/helpers/messages.helper.d.ts +0 -6
- package/helpers/messages.helper.js +0 -25
- package/helpers/path.helper.d.ts +0 -3
- package/helpers/path.helper.js +0 -13
- package/helpers/sse.helper.d.ts +0 -45
- package/helpers/sse.helper.js +0 -83
- package/index.d.ts +0 -1
- package/index.js +0 -3
- package/interfaces/http/cors.interface.d.ts +0 -58
- package/interfaces/http/cors.interface.js +0 -2
- package/interfaces/http/exception.interface.d.ts +0 -6
- package/interfaces/http/exception.interface.js +0 -2
- package/interfaces/http/exclude-route.interface.d.ts +0 -15
- package/interfaces/http/exclude-route.interface.js +0 -2
- package/interfaces/http/index.d.ts +0 -10
- package/interfaces/http/index.js +0 -26
- package/interfaces/http/message-event.interface.d.ts +0 -6
- package/interfaces/http/message-event.interface.js +0 -2
- package/interfaces/http/module.inteface.d.ts +0 -5
- package/interfaces/http/module.inteface.js +0 -2
- package/interfaces/http/options.interface.d.ts +0 -127
- package/interfaces/http/options.interface.js +0 -2
- package/interfaces/http/path-metadata.interface.d.ts +0 -31
- package/interfaces/http/path-metadata.interface.js +0 -2
- package/interfaces/http/prefix-options.interface.d.ts +0 -7
- package/interfaces/http/prefix-options.interface.js +0 -2
- package/interfaces/http/raw-request.d.ts +0 -4
- package/interfaces/http/raw-request.js +0 -2
- package/interfaces/http/routes.interface.d.ts +0 -7
- package/interfaces/http/routes.interface.js +0 -2
- package/interfaces/http/server.interface.d.ts +0 -54
- package/interfaces/http/server.interface.js +0 -2
- package/interfaces/index.d.ts +0 -3
- package/interfaces/index.js +0 -19
- package/interfaces/middleware/config-proxy.interface.d.ts +0 -23
- package/interfaces/middleware/config-proxy.interface.js +0 -2
- package/interfaces/middleware/configuration.interface.d.ts +0 -12
- package/interfaces/middleware/configuration.interface.js +0 -2
- package/interfaces/middleware/consumer.interface.d.ts +0 -16
- package/interfaces/middleware/consumer.interface.js +0 -2
- package/interfaces/middleware/index.d.ts +0 -4
- package/interfaces/middleware/index.js +0 -20
- package/interfaces/middleware/middleware.interface.d.ts +0 -7
- package/interfaces/middleware/middleware.interface.js +0 -2
- package/interfaces/router/callback-paramtypes.interface.d.ts +0 -1
- package/interfaces/router/callback-paramtypes.interface.js +0 -2
- package/interfaces/router/definition.interface.d.ts +0 -10
- package/interfaces/router/definition.interface.js +0 -2
- package/interfaces/router/index.d.ts +0 -3
- package/interfaces/router/index.js +0 -19
- package/interfaces/router/version-options.interface.d.ts +0 -92
- package/interfaces/router/version-options.interface.js +0 -9
- package/middleware/builder.d.ts +0 -15
- package/middleware/builder.js +0 -78
- package/middleware/container.d.ts +0 -13
- package/middleware/container.js +0 -50
- package/middleware/extractor.d.ts +0 -15
- package/middleware/extractor.js +0 -50
- package/middleware/index.d.ts +0 -1
- package/middleware/index.js +0 -17
- package/middleware/module.d.ts +0 -33
- package/middleware/module.js +0 -180
- package/middleware/resolver.d.ts +0 -10
- package/middleware/resolver.js +0 -27
- package/middleware/routes-mapper.d.ts +0 -19
- package/middleware/routes-mapper.js +0 -111
- package/middleware/utils.d.ts +0 -8
- package/middleware/utils.js +0 -86
- package/router/module.d.ts +0 -18
- package/router/module.js +0 -88
- package/router/resolver.d.ts +0 -31
- package/router/resolver.js +0 -128
- package/storage/http-instance.storage.d.ts +0 -9
- package/storage/http-instance.storage.js +0 -19
- package/stream/index.d.ts +0 -1
- package/stream/index.js +0 -17
- package/stream/interfaces/index.d.ts +0 -2
- package/stream/interfaces/index.js +0 -18
- package/stream/interfaces/streamable-handler-response.interface.d.ts +0 -12
- package/stream/interfaces/streamable-handler-response.interface.js +0 -2
- package/stream/interfaces/streamable-options.interface.d.ts +0 -10
- package/stream/interfaces/streamable-options.interface.js +0 -2
- package/stream/streamable-file.d.ts +0 -22
- package/stream/streamable-file.js +0 -55
- package/test/context/response.controller.spec.d.ts +0 -1
- package/test/context/response.controller.spec.js +0 -328
- package/test/decorators/controller.decorator.spec.d.ts +0 -1
- package/test/decorators/controller.decorator.spec.js +0 -113
- package/test/decorators/header.decorator.spec.d.ts +0 -1
- package/test/decorators/header.decorator.spec.js +0 -33
- package/test/decorators/http-code.decorator.spec.d.ts +0 -1
- package/test/decorators/http-code.decorator.spec.js +0 -30
- package/test/decorators/redirect.decorator.spec.d.ts +0 -1
- package/test/decorators/redirect.decorator.spec.js +0 -36
- package/test/decorators/render.decorator.spec.d.ts +0 -1
- package/test/decorators/render.decorator.spec.js +0 -30
- package/test/decorators/request-mapping.decorator.spec.d.ts +0 -1
- package/test/decorators/request-mapping.decorator.spec.js +0 -85
- package/test/decorators/route-params.decorator.spec.d.ts +0 -1
- package/test/decorators/route-params.decorator.spec.js +0 -493
- package/test/decorators/sse.decorator.spec.d.ts +0 -1
- package/test/decorators/sse.decorator.spec.js +0 -35
- package/test/decorators/version.decorator.spec.d.ts +0 -1
- package/test/decorators/version.decorator.spec.js +0 -43
- package/test/exceptions/handler.spec.d.ts +0 -1
- package/test/exceptions/handler.spec.js +0 -145
- package/test/exceptions/proxy.spec.d.ts +0 -1
- package/test/exceptions/proxy.spec.js +0 -74
- package/test/explorers/path.explorer.spec.d.ts +0 -1
- package/test/explorers/path.explorer.spec.js +0 -190
- package/test/explorers/router.explorer.spec.d.ts +0 -1
- package/test/explorers/router.explorer.spec.js +0 -206
- package/test/factory/method.factory.spec.d.ts +0 -1
- package/test/factory/method.factory.spec.js +0 -33
- package/test/factory/params.factory.spec.d.ts +0 -1
- package/test/factory/params.factory.spec.js +0 -104
- package/test/factory/path.factory.spec.d.ts +0 -1
- package/test/factory/path.factory.spec.js +0 -260
- package/test/filters/context.spec.d.ts +0 -1
- package/test/filters/context.spec.js +0 -96
- package/test/filters/filter.spec.d.ts +0 -1
- package/test/filters/filter.spec.js +0 -96
- package/test/helpers/flatten-routes.helper.spec.d.ts +0 -1
- package/test/helpers/flatten-routes.helper.spec.js +0 -131
- package/test/helpers/sse.helper.spec.d.ts +0 -1
- package/test/helpers/sse.helper.spec.js +0 -132
- package/test/middleware/builder.spec.d.ts +0 -1
- package/test/middleware/builder.spec.js +0 -235
- package/test/middleware/container.spec.d.ts +0 -1
- package/test/middleware/container.spec.js +0 -81
- package/test/middleware/module.spec.d.ts +0 -1
- package/test/middleware/module.spec.js +0 -206
- package/test/middleware/route-info-path-extractor.spec.d.ts +0 -1
- package/test/middleware/route-info-path-extractor.spec.js +0 -123
- package/test/middleware/routes-mapper.spec.d.ts +0 -1
- package/test/middleware/routes-mapper.spec.js +0 -162
- package/test/middleware/utils.spec.d.ts +0 -1
- package/test/middleware/utils.spec.js +0 -132
- package/test/router/module.spec.d.ts +0 -1
- package/test/router/module.spec.js +0 -40
- package/test/router/resolver.spec.d.ts +0 -1
- package/test/router/resolver.spec.js +0 -326
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const chai_1 = __importDefault(require("chai"));
|
|
16
|
-
const chai_2 = require("chai");
|
|
17
|
-
const chai_as_promised_1 = __importDefault(require("chai-as-promised"));
|
|
18
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
19
|
-
const module_1 = require("../../middleware/module");
|
|
20
|
-
const graph_inspector_1 = require("../../../core/inspector/graph-inspector");
|
|
21
|
-
const decorators_1 = require("../../decorators");
|
|
22
|
-
const enums_1 = require("../../enums");
|
|
23
|
-
const core_1 = require("../../../core");
|
|
24
|
-
const context_1 = require("../../filters/context");
|
|
25
|
-
const config_1 = require("../../application/config");
|
|
26
|
-
const helpers_1 = require("../../helpers");
|
|
27
|
-
const extractor_1 = require("../../middleware/extractor");
|
|
28
|
-
const module_2 = require("../../../core/injector/module/module");
|
|
29
|
-
const container_1 = require("../../middleware/container");
|
|
30
|
-
const middleware_1 = require("../../middleware");
|
|
31
|
-
const exceptions_1 = require("../../../core/errors/exceptions");
|
|
32
|
-
const invalid_middleware_exception_1 = require("../../errors/invalid-middleware.exception");
|
|
33
|
-
const wrapper_1 = require("../../../core/injector/instance/wrapper");
|
|
34
|
-
chai_1.default.use(chai_as_promised_1.default);
|
|
35
|
-
describe("MiddlewareModule", () => {
|
|
36
|
-
let middlewareModule;
|
|
37
|
-
let graphInspector;
|
|
38
|
-
let BasicController = class BasicController {
|
|
39
|
-
};
|
|
40
|
-
BasicController = __decorate([
|
|
41
|
-
(0, decorators_1.Controller)("test")
|
|
42
|
-
], BasicController);
|
|
43
|
-
let BaseController = class BaseController {
|
|
44
|
-
getTest() { }
|
|
45
|
-
getAnother() { }
|
|
46
|
-
};
|
|
47
|
-
__decorate([
|
|
48
|
-
(0, decorators_1.RequestMapping)({ path: "test" }),
|
|
49
|
-
__metadata("design:type", Function),
|
|
50
|
-
__metadata("design:paramtypes", []),
|
|
51
|
-
__metadata("design:returntype", void 0)
|
|
52
|
-
], BaseController.prototype, "getTest", null);
|
|
53
|
-
__decorate([
|
|
54
|
-
(0, decorators_1.RequestMapping)({ path: "another", method: enums_1.RequestMethod.DELETE }),
|
|
55
|
-
__metadata("design:type", Function),
|
|
56
|
-
__metadata("design:paramtypes", []),
|
|
57
|
-
__metadata("design:returntype", void 0)
|
|
58
|
-
], BaseController.prototype, "getAnother", null);
|
|
59
|
-
BaseController = __decorate([
|
|
60
|
-
(0, decorators_1.Controller)("test")
|
|
61
|
-
], BaseController);
|
|
62
|
-
let TestMiddleware = class TestMiddleware {
|
|
63
|
-
use(req, res, next) { }
|
|
64
|
-
};
|
|
65
|
-
TestMiddleware = __decorate([
|
|
66
|
-
(0, core_1.Injectable)()
|
|
67
|
-
], TestMiddleware);
|
|
68
|
-
beforeEach(() => {
|
|
69
|
-
const container = new core_1.VenokContainer();
|
|
70
|
-
const appConfig = new core_1.ApplicationConfig();
|
|
71
|
-
const httpConfig = new config_1.HttpConfig();
|
|
72
|
-
graphInspector = new graph_inspector_1.GraphInspector(container);
|
|
73
|
-
middlewareModule = new module_1.MiddlewareModule();
|
|
74
|
-
middlewareModule["routerExceptionFilter"] = new context_1.RouterExceptionFiltersContext(new core_1.VenokContainer(), appConfig, new helpers_1.NoopHttpAdapter({}));
|
|
75
|
-
middlewareModule["routeInfoPathExtractor"] = new extractor_1.RouteInfoPathExtractor(httpConfig);
|
|
76
|
-
middlewareModule["routerExceptionFilter"] = new context_1.RouterExceptionFiltersContext(container, appConfig, new helpers_1.NoopHttpAdapter({}));
|
|
77
|
-
middlewareModule["graphInspector"] = graphInspector;
|
|
78
|
-
});
|
|
79
|
-
describe("loadConfiguration", () => {
|
|
80
|
-
it('should call "configure" method if method is implemented', async () => {
|
|
81
|
-
const stubContainer = new core_1.VenokContainer();
|
|
82
|
-
stubContainer.getModules().set("Test", new module_2.Module(class {
|
|
83
|
-
}, stubContainer));
|
|
84
|
-
const configureSpy = sinon_1.default.spy();
|
|
85
|
-
const mockModule = {
|
|
86
|
-
instance: {
|
|
87
|
-
configure: configureSpy,
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
middlewareModule.container = stubContainer;
|
|
91
|
-
await middlewareModule.loadConfiguration(new container_1.MiddlewareContainer(stubContainer), mockModule, "Test");
|
|
92
|
-
(0, chai_2.expect)(configureSpy.calledOnce).to.be.true;
|
|
93
|
-
(0, chai_2.expect)(configureSpy.calledWith(new middleware_1.MiddlewareBuilder(middlewareModule.routesMapper, undefined, new extractor_1.RouteInfoPathExtractor(new config_1.HttpConfig())))).to.be.true;
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
describe("registerRouteMiddleware", () => {
|
|
97
|
-
class TestModule {
|
|
98
|
-
}
|
|
99
|
-
let nestContainer;
|
|
100
|
-
beforeEach(() => {
|
|
101
|
-
nestContainer = new core_1.VenokContainer();
|
|
102
|
-
nestContainer.getModules().set("Test", new module_2.Module(TestModule, nestContainer));
|
|
103
|
-
});
|
|
104
|
-
it('should throw "RuntimeException" exception when middleware is not stored in container', () => {
|
|
105
|
-
const route = { path: "Test" };
|
|
106
|
-
const configuration = {
|
|
107
|
-
middleware: [TestMiddleware],
|
|
108
|
-
forRoutes: [BaseController],
|
|
109
|
-
};
|
|
110
|
-
const useSpy = sinon_1.default.spy();
|
|
111
|
-
const app = { use: useSpy };
|
|
112
|
-
middlewareModule["container"] = nestContainer;
|
|
113
|
-
(0, chai_2.expect)(middlewareModule.registerRouteMiddleware(new container_1.MiddlewareContainer(nestContainer), route, configuration, "Test", app)).to.eventually.be.rejectedWith(exceptions_1.RuntimeException);
|
|
114
|
-
});
|
|
115
|
-
it('should throw "InvalidMiddlewareException" exception when middleware does not have "use" method', () => {
|
|
116
|
-
let InvalidMiddleware = class InvalidMiddleware {
|
|
117
|
-
};
|
|
118
|
-
InvalidMiddleware = __decorate([
|
|
119
|
-
(0, core_1.Injectable)()
|
|
120
|
-
], InvalidMiddleware);
|
|
121
|
-
const route = { path: "Test" };
|
|
122
|
-
const configuration = {
|
|
123
|
-
middleware: [InvalidMiddleware],
|
|
124
|
-
forRoutes: [BaseController],
|
|
125
|
-
};
|
|
126
|
-
const useSpy = sinon_1.default.spy();
|
|
127
|
-
const app = { use: useSpy };
|
|
128
|
-
const container = new container_1.MiddlewareContainer(nestContainer);
|
|
129
|
-
const moduleKey = "Test";
|
|
130
|
-
container.insertConfig([configuration], moduleKey);
|
|
131
|
-
const instance = new InvalidMiddleware();
|
|
132
|
-
container.getMiddlewareCollection(moduleKey).set("InvalidMiddleware", {
|
|
133
|
-
metatype: InvalidMiddleware,
|
|
134
|
-
instance,
|
|
135
|
-
});
|
|
136
|
-
(0, chai_2.expect)(middlewareModule.registerRouteMiddleware(container, route, configuration, moduleKey, app)).to.be.rejectedWith(invalid_middleware_exception_1.InvalidMiddlewareException);
|
|
137
|
-
});
|
|
138
|
-
it("should mount middleware when is stored in container", async () => {
|
|
139
|
-
const route = "testPath";
|
|
140
|
-
const configuration = {
|
|
141
|
-
middleware: [TestMiddleware],
|
|
142
|
-
forRoutes: ["test", BasicController, BaseController],
|
|
143
|
-
};
|
|
144
|
-
const createMiddlewareFactoryStub = sinon_1.default.stub().callsFake(() => () => null);
|
|
145
|
-
const app = {
|
|
146
|
-
createMiddlewareFactory: createMiddlewareFactoryStub,
|
|
147
|
-
};
|
|
148
|
-
const stubContainer = new core_1.VenokContainer();
|
|
149
|
-
stubContainer.getModules().set("Test", new module_2.Module(TestModule, stubContainer));
|
|
150
|
-
const container = new container_1.MiddlewareContainer(stubContainer);
|
|
151
|
-
const moduleKey = "Test";
|
|
152
|
-
container.insertConfig([configuration], moduleKey);
|
|
153
|
-
const instance = new TestMiddleware();
|
|
154
|
-
container.getMiddlewareCollection(moduleKey).set(TestMiddleware, new wrapper_1.InstanceWrapper({
|
|
155
|
-
metatype: TestMiddleware,
|
|
156
|
-
instance,
|
|
157
|
-
}));
|
|
158
|
-
sinon_1.default.stub(stubContainer, "getModuleByKey").callsFake(() => new module_2.Module(class {
|
|
159
|
-
}, stubContainer));
|
|
160
|
-
middlewareModule["container"] = stubContainer;
|
|
161
|
-
await middlewareModule.registerRouteMiddleware(container, { path: route, method: enums_1.RequestMethod.ALL }, configuration, moduleKey, app);
|
|
162
|
-
(0, chai_2.expect)(createMiddlewareFactoryStub.calledOnce).to.be.true;
|
|
163
|
-
});
|
|
164
|
-
it("should insert the expected middleware definition", async () => {
|
|
165
|
-
const route = "testPath";
|
|
166
|
-
const configuration = {
|
|
167
|
-
middleware: [TestMiddleware],
|
|
168
|
-
forRoutes: ["test", BasicController, BaseController],
|
|
169
|
-
};
|
|
170
|
-
const instance = new TestMiddleware();
|
|
171
|
-
const instanceWrapper = new wrapper_1.InstanceWrapper({
|
|
172
|
-
metatype: TestMiddleware,
|
|
173
|
-
instance,
|
|
174
|
-
name: TestMiddleware.name,
|
|
175
|
-
});
|
|
176
|
-
const createMiddlewareFactoryStub = sinon_1.default.stub().callsFake(() => () => null);
|
|
177
|
-
const app = {
|
|
178
|
-
createMiddlewareFactory: createMiddlewareFactoryStub,
|
|
179
|
-
};
|
|
180
|
-
const stubContainer = new core_1.VenokContainer();
|
|
181
|
-
stubContainer.getModules().set("Test", new module_2.Module(TestModule, stubContainer));
|
|
182
|
-
const container = new container_1.MiddlewareContainer(stubContainer);
|
|
183
|
-
const moduleKey = "Test";
|
|
184
|
-
container.insertConfig([configuration], moduleKey);
|
|
185
|
-
container.getMiddlewareCollection(moduleKey).set(TestMiddleware, instanceWrapper);
|
|
186
|
-
sinon_1.default.stub(stubContainer, "getModuleByKey").callsFake(() => new module_2.Module(class {
|
|
187
|
-
}, stubContainer));
|
|
188
|
-
middlewareModule["container"] = stubContainer;
|
|
189
|
-
const insertEntrypointDefinitionSpy = sinon_1.default.spy(graphInspector, "insertEntrypointDefinition");
|
|
190
|
-
await middlewareModule.registerRouteMiddleware(container, { path: route, method: enums_1.RequestMethod.ALL }, configuration, moduleKey, app);
|
|
191
|
-
(0, chai_2.expect)(createMiddlewareFactoryStub.calledOnce).to.be.true;
|
|
192
|
-
(0, chai_2.expect)(insertEntrypointDefinitionSpy.calledWith({
|
|
193
|
-
type: "middleware",
|
|
194
|
-
methodName: "use",
|
|
195
|
-
className: instanceWrapper.name,
|
|
196
|
-
classNodeId: instanceWrapper.id,
|
|
197
|
-
metadata: {
|
|
198
|
-
key: route,
|
|
199
|
-
path: route,
|
|
200
|
-
requestMethod: "ALL",
|
|
201
|
-
version: undefined,
|
|
202
|
-
},
|
|
203
|
-
})).to.be.true;
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chai_1 = require("chai");
|
|
4
|
-
const extractor_1 = require("../../middleware/extractor");
|
|
5
|
-
const enums_1 = require("../../enums");
|
|
6
|
-
const utils_1 = require("../../middleware/utils");
|
|
7
|
-
const config_1 = require("../../application/config");
|
|
8
|
-
describe("RouteInfoPathExtractor", () => {
|
|
9
|
-
describe("extractPathsFrom", () => {
|
|
10
|
-
let httpConfig;
|
|
11
|
-
let routeInfoPathExtractor;
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
httpConfig = new config_1.HttpConfig();
|
|
14
|
-
httpConfig.enableVersioning({
|
|
15
|
-
type: enums_1.VersioningType.URI,
|
|
16
|
-
});
|
|
17
|
-
routeInfoPathExtractor = new extractor_1.RouteInfoPathExtractor(httpConfig);
|
|
18
|
-
});
|
|
19
|
-
it(`should return correct paths`, () => {
|
|
20
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathsFrom({
|
|
21
|
-
path: "*",
|
|
22
|
-
method: enums_1.RequestMethod.ALL,
|
|
23
|
-
})).to.eql(["/*"]);
|
|
24
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathsFrom({
|
|
25
|
-
path: "*",
|
|
26
|
-
method: enums_1.RequestMethod.ALL,
|
|
27
|
-
version: "1",
|
|
28
|
-
})).to.eql(["/v1/*"]);
|
|
29
|
-
});
|
|
30
|
-
it(`should return correct paths when set global prefix`, () => {
|
|
31
|
-
Reflect.set(routeInfoPathExtractor, "prefixPath", "/api");
|
|
32
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathsFrom({
|
|
33
|
-
path: "*",
|
|
34
|
-
method: enums_1.RequestMethod.ALL,
|
|
35
|
-
})).to.eql(["/api/*"]);
|
|
36
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathsFrom({
|
|
37
|
-
path: "*",
|
|
38
|
-
method: enums_1.RequestMethod.ALL,
|
|
39
|
-
version: "1",
|
|
40
|
-
})).to.eql(["/api/v1/*"]);
|
|
41
|
-
});
|
|
42
|
-
it(`should return correct paths when set global prefix and global prefix options`, () => {
|
|
43
|
-
Reflect.set(routeInfoPathExtractor, "prefixPath", "/api");
|
|
44
|
-
Reflect.set(routeInfoPathExtractor, "excludedGlobalPrefixRoutes", (0, utils_1.mapToExcludeRoute)(["foo"]));
|
|
45
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathsFrom({
|
|
46
|
-
path: "*",
|
|
47
|
-
method: enums_1.RequestMethod.ALL,
|
|
48
|
-
})).to.eql(["/api/*", "/foo"]);
|
|
49
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathsFrom({
|
|
50
|
-
path: "*",
|
|
51
|
-
method: enums_1.RequestMethod.ALL,
|
|
52
|
-
version: "1",
|
|
53
|
-
})).to.eql(["/api/v1/*", "/v1/foo"]);
|
|
54
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathsFrom({
|
|
55
|
-
path: "foo",
|
|
56
|
-
method: enums_1.RequestMethod.ALL,
|
|
57
|
-
version: "1",
|
|
58
|
-
})).to.eql(["/v1/foo"]);
|
|
59
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathsFrom({
|
|
60
|
-
path: "bar",
|
|
61
|
-
method: enums_1.RequestMethod.ALL,
|
|
62
|
-
version: "1",
|
|
63
|
-
})).to.eql(["/api/v1/bar"]);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
describe("extractPathFrom", () => {
|
|
67
|
-
let httpConfig;
|
|
68
|
-
let routeInfoPathExtractor;
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
httpConfig = new config_1.HttpConfig();
|
|
71
|
-
httpConfig.enableVersioning({
|
|
72
|
-
type: enums_1.VersioningType.URI,
|
|
73
|
-
});
|
|
74
|
-
routeInfoPathExtractor = new extractor_1.RouteInfoPathExtractor(httpConfig);
|
|
75
|
-
});
|
|
76
|
-
it(`should return correct path`, () => {
|
|
77
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathFrom({
|
|
78
|
-
path: "*",
|
|
79
|
-
method: enums_1.RequestMethod.ALL,
|
|
80
|
-
})).to.eql("/*");
|
|
81
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathFrom({
|
|
82
|
-
path: "*",
|
|
83
|
-
method: enums_1.RequestMethod.ALL,
|
|
84
|
-
version: "1",
|
|
85
|
-
})).to.eql("/v1/*");
|
|
86
|
-
});
|
|
87
|
-
it(`should return correct path when set global prefix`, () => {
|
|
88
|
-
Reflect.set(routeInfoPathExtractor, "prefixPath", "/api");
|
|
89
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathFrom({
|
|
90
|
-
path: "*",
|
|
91
|
-
method: enums_1.RequestMethod.ALL,
|
|
92
|
-
})).to.eql("/*");
|
|
93
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathFrom({
|
|
94
|
-
path: "*",
|
|
95
|
-
method: enums_1.RequestMethod.ALL,
|
|
96
|
-
version: "1",
|
|
97
|
-
})).to.eql("/api/v1/*");
|
|
98
|
-
});
|
|
99
|
-
it(`should return correct path when set global prefix and global prefix options`, () => {
|
|
100
|
-
Reflect.set(routeInfoPathExtractor, "prefixPath", "/api");
|
|
101
|
-
Reflect.set(routeInfoPathExtractor, "excludedGlobalPrefixRoutes", (0, utils_1.mapToExcludeRoute)(["foo"]));
|
|
102
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathFrom({
|
|
103
|
-
path: "*",
|
|
104
|
-
method: enums_1.RequestMethod.ALL,
|
|
105
|
-
})).to.eql("/*");
|
|
106
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathFrom({
|
|
107
|
-
path: "*",
|
|
108
|
-
method: enums_1.RequestMethod.ALL,
|
|
109
|
-
version: "1",
|
|
110
|
-
})).to.eql("/api/v1/*");
|
|
111
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathFrom({
|
|
112
|
-
path: "foo",
|
|
113
|
-
method: enums_1.RequestMethod.ALL,
|
|
114
|
-
version: "1",
|
|
115
|
-
})).to.eql("/v1/foo");
|
|
116
|
-
(0, chai_1.expect)(routeInfoPathExtractor.extractPathFrom({
|
|
117
|
-
path: "bar",
|
|
118
|
-
method: enums_1.RequestMethod.ALL,
|
|
119
|
-
version: "1",
|
|
120
|
-
})).to.eql("/api/v1/bar");
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const chai_1 = require("chai");
|
|
13
|
-
const decorators_1 = require("../../decorators");
|
|
14
|
-
const enums_1 = require("../../enums");
|
|
15
|
-
const routes_mapper_1 = require("../../middleware/routes-mapper");
|
|
16
|
-
const core_1 = require("../../../core");
|
|
17
|
-
const config_1 = require("../../application/config");
|
|
18
|
-
describe("RoutesMapper", () => {
|
|
19
|
-
let TestRoute = class TestRoute {
|
|
20
|
-
getTest() { }
|
|
21
|
-
getAnother() { }
|
|
22
|
-
getVersioned() { }
|
|
23
|
-
};
|
|
24
|
-
__decorate([
|
|
25
|
-
(0, decorators_1.RequestMapping)({ path: "test" }),
|
|
26
|
-
__metadata("design:type", Function),
|
|
27
|
-
__metadata("design:paramtypes", []),
|
|
28
|
-
__metadata("design:returntype", void 0)
|
|
29
|
-
], TestRoute.prototype, "getTest", null);
|
|
30
|
-
__decorate([
|
|
31
|
-
(0, decorators_1.RequestMapping)({ path: "another", method: enums_1.RequestMethod.DELETE }),
|
|
32
|
-
__metadata("design:type", Function),
|
|
33
|
-
__metadata("design:paramtypes", []),
|
|
34
|
-
__metadata("design:returntype", void 0)
|
|
35
|
-
], TestRoute.prototype, "getAnother", null);
|
|
36
|
-
__decorate([
|
|
37
|
-
(0, decorators_1.Version)("1"),
|
|
38
|
-
(0, decorators_1.Get)("versioned"),
|
|
39
|
-
__metadata("design:type", Function),
|
|
40
|
-
__metadata("design:paramtypes", []),
|
|
41
|
-
__metadata("design:returntype", void 0)
|
|
42
|
-
], TestRoute.prototype, "getVersioned", null);
|
|
43
|
-
TestRoute = __decorate([
|
|
44
|
-
(0, decorators_1.Controller)("test")
|
|
45
|
-
], TestRoute);
|
|
46
|
-
let mapper;
|
|
47
|
-
beforeEach(() => {
|
|
48
|
-
const httpConfig = new config_1.HttpConfig();
|
|
49
|
-
httpConfig.enableVersioning({ type: enums_1.VersioningType.URI });
|
|
50
|
-
mapper = new routes_mapper_1.RoutesMapper(new core_1.VenokContainer(), httpConfig);
|
|
51
|
-
});
|
|
52
|
-
it('should map @Controller() to "ControllerMetadata" in forRoutes', () => {
|
|
53
|
-
const config = {
|
|
54
|
-
middleware: "Test",
|
|
55
|
-
forRoutes: [
|
|
56
|
-
{ path: "test", method: enums_1.RequestMethod.GET },
|
|
57
|
-
{ path: "versioned", version: "1", method: enums_1.RequestMethod.GET },
|
|
58
|
-
TestRoute,
|
|
59
|
-
],
|
|
60
|
-
};
|
|
61
|
-
(0, chai_1.expect)(mapper.mapRouteToRouteInfo(config.forRoutes[0])).to.deep.equal([
|
|
62
|
-
{ path: "/test", method: enums_1.RequestMethod.GET },
|
|
63
|
-
]);
|
|
64
|
-
(0, chai_1.expect)(mapper.mapRouteToRouteInfo(config.forRoutes[1])).to.deep.equal([
|
|
65
|
-
{ path: "/versioned", version: "1", method: enums_1.RequestMethod.GET },
|
|
66
|
-
]);
|
|
67
|
-
(0, chai_1.expect)(mapper.mapRouteToRouteInfo(config.forRoutes[2])).to.deep.equal([
|
|
68
|
-
{ path: "/test/test", method: enums_1.RequestMethod.GET },
|
|
69
|
-
{ path: "/test/another", method: enums_1.RequestMethod.DELETE },
|
|
70
|
-
{ path: "/test/versioned", method: enums_1.RequestMethod.GET, version: "1" },
|
|
71
|
-
]);
|
|
72
|
-
});
|
|
73
|
-
let TestRouteWithMultiplePaths = class TestRouteWithMultiplePaths {
|
|
74
|
-
getTest() { }
|
|
75
|
-
getAnother() { }
|
|
76
|
-
};
|
|
77
|
-
__decorate([
|
|
78
|
-
(0, decorators_1.RequestMapping)({ path: "test" }),
|
|
79
|
-
__metadata("design:type", Function),
|
|
80
|
-
__metadata("design:paramtypes", []),
|
|
81
|
-
__metadata("design:returntype", void 0)
|
|
82
|
-
], TestRouteWithMultiplePaths.prototype, "getTest", null);
|
|
83
|
-
__decorate([
|
|
84
|
-
(0, decorators_1.RequestMapping)({ path: "another", method: enums_1.RequestMethod.DELETE }),
|
|
85
|
-
__metadata("design:type", Function),
|
|
86
|
-
__metadata("design:paramtypes", []),
|
|
87
|
-
__metadata("design:returntype", void 0)
|
|
88
|
-
], TestRouteWithMultiplePaths.prototype, "getAnother", null);
|
|
89
|
-
TestRouteWithMultiplePaths = __decorate([
|
|
90
|
-
(0, decorators_1.Controller)(["test", "test2"])
|
|
91
|
-
], TestRouteWithMultiplePaths);
|
|
92
|
-
it('should map a controller with multiple paths to "ControllerMetadata" in forRoutes', () => {
|
|
93
|
-
const config = {
|
|
94
|
-
middleware: "Test",
|
|
95
|
-
forRoutes: [{ path: "test", method: enums_1.RequestMethod.GET }, TestRouteWithMultiplePaths],
|
|
96
|
-
};
|
|
97
|
-
(0, chai_1.expect)(mapper.mapRouteToRouteInfo(config.forRoutes[0])).to.deep.equal([
|
|
98
|
-
{ path: "/test", method: enums_1.RequestMethod.GET },
|
|
99
|
-
]);
|
|
100
|
-
(0, chai_1.expect)(mapper.mapRouteToRouteInfo(config.forRoutes[1])).to.deep.equal([
|
|
101
|
-
{ path: "/test/test", method: enums_1.RequestMethod.GET },
|
|
102
|
-
{ path: "/test/another", method: enums_1.RequestMethod.DELETE },
|
|
103
|
-
{ path: "/test2/test", method: enums_1.RequestMethod.GET },
|
|
104
|
-
{ path: "/test2/another", method: enums_1.RequestMethod.DELETE },
|
|
105
|
-
]);
|
|
106
|
-
});
|
|
107
|
-
let VersionedController = class VersionedController {
|
|
108
|
-
hello() {
|
|
109
|
-
return 'Hello from "VersionedController"!';
|
|
110
|
-
}
|
|
111
|
-
override() {
|
|
112
|
-
return 'Hello from "VersionedController"!';
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
__decorate([
|
|
116
|
-
(0, decorators_1.Get)(),
|
|
117
|
-
__metadata("design:type", Function),
|
|
118
|
-
__metadata("design:paramtypes", []),
|
|
119
|
-
__metadata("design:returntype", void 0)
|
|
120
|
-
], VersionedController.prototype, "hello", null);
|
|
121
|
-
__decorate([
|
|
122
|
-
(0, decorators_1.Version)("2"),
|
|
123
|
-
(0, decorators_1.Get)("/override"),
|
|
124
|
-
__metadata("design:type", Function),
|
|
125
|
-
__metadata("design:paramtypes", []),
|
|
126
|
-
__metadata("design:returntype", void 0)
|
|
127
|
-
], VersionedController.prototype, "override", null);
|
|
128
|
-
VersionedController = __decorate([
|
|
129
|
-
(0, decorators_1.Controller)({
|
|
130
|
-
version: "1",
|
|
131
|
-
path: "versioned",
|
|
132
|
-
})
|
|
133
|
-
], VersionedController);
|
|
134
|
-
let MultipleVersionController = class MultipleVersionController {
|
|
135
|
-
multiple() {
|
|
136
|
-
return "Multiple Versions 1 or 2";
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
__decorate([
|
|
140
|
-
(0, decorators_1.Get)("multiple"),
|
|
141
|
-
__metadata("design:type", Function),
|
|
142
|
-
__metadata("design:paramtypes", []),
|
|
143
|
-
__metadata("design:returntype", void 0)
|
|
144
|
-
], MultipleVersionController.prototype, "multiple", null);
|
|
145
|
-
MultipleVersionController = __decorate([
|
|
146
|
-
(0, decorators_1.Controller)({
|
|
147
|
-
version: ["1", "2"],
|
|
148
|
-
})
|
|
149
|
-
], MultipleVersionController);
|
|
150
|
-
it("should map a versioned controller to the corresponding route info objects (single version)", () => {
|
|
151
|
-
(0, chai_1.expect)(mapper.mapRouteToRouteInfo(VersionedController)).to.deep.equal([
|
|
152
|
-
{ path: "/versioned/", version: "1", method: enums_1.RequestMethod.GET },
|
|
153
|
-
{ path: "/versioned/override", version: "2", method: enums_1.RequestMethod.GET },
|
|
154
|
-
]);
|
|
155
|
-
});
|
|
156
|
-
it("should map a versioned controller to the corresponding route info objects (multiple versions)", () => {
|
|
157
|
-
(0, chai_1.expect)(mapper.mapRouteToRouteInfo(MultipleVersionController)).to.deep.equal([
|
|
158
|
-
{ path: "/multiple", version: "1", method: enums_1.RequestMethod.GET },
|
|
159
|
-
{ path: "/multiple", version: "2", method: enums_1.RequestMethod.GET },
|
|
160
|
-
]);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const chai_1 = require("chai");
|
|
7
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
8
|
-
const path_to_regexp_1 = require("path-to-regexp");
|
|
9
|
-
const helpers_1 = require("../../helpers");
|
|
10
|
-
const enums_1 = require("../../enums");
|
|
11
|
-
const utils_1 = require("../../middleware/utils");
|
|
12
|
-
describe("middleware utils", () => {
|
|
13
|
-
const noopAdapter = new helpers_1.NoopHttpAdapter({});
|
|
14
|
-
class Test {
|
|
15
|
-
}
|
|
16
|
-
function fnMiddleware(req, res, next) { }
|
|
17
|
-
describe("mapToExcludeRoute", () => {
|
|
18
|
-
it("should return exclude route metadata", () => {
|
|
19
|
-
const stringRoute = "foo";
|
|
20
|
-
const routeInfo = {
|
|
21
|
-
path: "bar",
|
|
22
|
-
method: enums_1.RequestMethod.GET,
|
|
23
|
-
};
|
|
24
|
-
(0, chai_1.expect)((0, utils_1.mapToExcludeRoute)([stringRoute, routeInfo])).to.eql([
|
|
25
|
-
{
|
|
26
|
-
path: stringRoute,
|
|
27
|
-
requestMethod: enums_1.RequestMethod.ALL,
|
|
28
|
-
pathRegex: (0, path_to_regexp_1.pathToRegexp)((0, helpers_1.addLeadingSlash)(stringRoute)),
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
path: routeInfo.path,
|
|
32
|
-
requestMethod: routeInfo.method,
|
|
33
|
-
pathRegex: (0, path_to_regexp_1.pathToRegexp)((0, helpers_1.addLeadingSlash)(routeInfo.path)),
|
|
34
|
-
},
|
|
35
|
-
]);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe("filterMiddleware", () => {
|
|
39
|
-
let middleware;
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
middleware = [Test, fnMiddleware, undefined, null];
|
|
42
|
-
});
|
|
43
|
-
it("should return filtered middleware", () => {
|
|
44
|
-
(0, chai_1.expect)((0, utils_1.filterMiddleware)(middleware, [], noopAdapter)).to.have.length(2);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
describe("mapToClass", () => {
|
|
48
|
-
describe("when middleware is a class", () => {
|
|
49
|
-
describe("when there is no excluded routes", () => {
|
|
50
|
-
it("should return an identity", () => {
|
|
51
|
-
const type = (0, utils_1.mapToClass)(Test, [], noopAdapter);
|
|
52
|
-
(0, chai_1.expect)(type).to.eql(Test);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
describe("when there are excluded routes", () => {
|
|
56
|
-
it("should return a host class", () => {
|
|
57
|
-
const type = (0, utils_1.mapToClass)(Test, (0, utils_1.mapToExcludeRoute)([{ path: "(.*)", method: enums_1.RequestMethod.ALL }]), noopAdapter);
|
|
58
|
-
(0, chai_1.expect)(type).to.not.eql(Test);
|
|
59
|
-
(0, chai_1.expect)(type.name).to.eql(Test.name);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
describe("when middleware is a function", () => {
|
|
64
|
-
it("should return a metatype", () => {
|
|
65
|
-
const metatype = (0, utils_1.mapToClass)(fnMiddleware, [], noopAdapter);
|
|
66
|
-
(0, chai_1.expect)(metatype).to.not.eql(fnMiddleware);
|
|
67
|
-
});
|
|
68
|
-
it("should define a `use` method", () => {
|
|
69
|
-
const metatype = (0, utils_1.mapToClass)(fnMiddleware, [], noopAdapter);
|
|
70
|
-
(0, chai_1.expect)(new metatype().use).to.exist;
|
|
71
|
-
});
|
|
72
|
-
it("should encapsulate a function", () => {
|
|
73
|
-
const spy = sinon_1.default.spy();
|
|
74
|
-
const metatype = (0, utils_1.mapToClass)(spy, [], noopAdapter);
|
|
75
|
-
new metatype().use();
|
|
76
|
-
(0, chai_1.expect)(spy.called).to.be.true;
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe("isMiddlewareClass", () => {
|
|
81
|
-
describe("when middleware is a class", () => {
|
|
82
|
-
it("should returns true", () => {
|
|
83
|
-
(0, chai_1.expect)((0, utils_1.isMiddlewareClass)(Test)).to.be.true;
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
describe("when middleware is a function", () => {
|
|
87
|
-
it("should returns false", () => {
|
|
88
|
-
(0, chai_1.expect)((0, utils_1.isMiddlewareClass)(fnMiddleware)).to.be.false;
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
describe("assignToken", () => {
|
|
93
|
-
describe("should define `name` property on metatype", () => {
|
|
94
|
-
const AnonymousType = class {
|
|
95
|
-
};
|
|
96
|
-
(0, utils_1.assignToken)(AnonymousType);
|
|
97
|
-
(0, chai_1.expect)(AnonymousType.name).to.exist;
|
|
98
|
-
});
|
|
99
|
-
describe("should use passed token as `name`", () => {
|
|
100
|
-
const AnonymousType = class {
|
|
101
|
-
};
|
|
102
|
-
const token = "token";
|
|
103
|
-
(0, utils_1.assignToken)(AnonymousType, token);
|
|
104
|
-
(0, chai_1.expect)(AnonymousType.name).to.eq(token);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe("isRouteExcluded", () => {
|
|
108
|
-
let adapter;
|
|
109
|
-
beforeEach(() => {
|
|
110
|
-
adapter = new helpers_1.NoopHttpAdapter({});
|
|
111
|
-
sinon_1.default.stub(adapter, "getRequestMethod").callsFake(() => "GET");
|
|
112
|
-
sinon_1.default.stub(adapter, "getRequestUrl").callsFake(() => "/cats/3");
|
|
113
|
-
});
|
|
114
|
-
describe("when route is excluded", () => {
|
|
115
|
-
const path = "/cats/(.*)";
|
|
116
|
-
const excludedRoutes = (0, utils_1.mapToExcludeRoute)([
|
|
117
|
-
{
|
|
118
|
-
path,
|
|
119
|
-
method: enums_1.RequestMethod.GET,
|
|
120
|
-
},
|
|
121
|
-
]);
|
|
122
|
-
it("should return true", () => {
|
|
123
|
-
(0, chai_1.expect)((0, utils_1.isMiddlewareRouteExcluded)({}, excludedRoutes, adapter)).to.be.true;
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
describe("when route is not excluded", () => {
|
|
127
|
-
it("should return false", () => {
|
|
128
|
-
(0, chai_1.expect)((0, utils_1.isMiddlewareRouteExcluded)({}, [], adapter)).to.be.false;
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|