@venok/http 1.0.1-canary.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/adapter/adapter.d.ts +57 -0
- package/adapter/adapter.js +58 -0
- package/adapter/host.d.ts +27 -0
- package/adapter/host.js +33 -0
- package/application/application.d.ts +18 -0
- package/application/application.js +51 -0
- package/application/config.d.ts +16 -0
- package/application/config.js +47 -0
- package/application/http.module-defenition.d.ts +8 -0
- package/application/http.module-defenition.js +6 -0
- package/application/http.module.d.ts +3 -0
- package/application/http.module.js +21 -0
- package/application/http.service.d.ts +11 -0
- package/application/http.service.js +43 -0
- package/application/starter.d.ts +41 -0
- package/application/starter.js +140 -0
- package/constants.d.ts +12 -0
- package/constants.js +15 -0
- package/context/context.d.ts +56 -0
- package/context/context.js +102 -0
- package/context/response.controller.d.ts +30 -0
- package/context/response.controller.js +86 -0
- package/decorators/controller.decorator.d.ts +82 -0
- package/decorators/controller.decorator.js +53 -0
- package/decorators/header.decorator.d.ts +12 -0
- package/decorators/header.decorator.js +23 -0
- package/decorators/http-code.decorator.d.ts +9 -0
- package/decorators/http-code.decorator.js +19 -0
- package/decorators/index.d.ts +9 -0
- package/decorators/index.js +25 -0
- package/decorators/redirect.decorator.d.ts +6 -0
- package/decorators/redirect.decorator.js +16 -0
- package/decorators/render.decorator.d.ts +10 -0
- package/decorators/render.decorator.js +20 -0
- package/decorators/request-mapping.decorator.d.ts +78 -0
- package/decorators/request-mapping.decorator.js +98 -0
- package/decorators/route-params.decorator.d.ts +378 -0
- package/decorators/route-params.decorator.js +227 -0
- package/decorators/sse.decorator.d.ts +6 -0
- package/decorators/sse.decorator.js +20 -0
- package/decorators/version.decorator.d.ts +7 -0
- package/decorators/version.decorator.js +20 -0
- package/enums/http-status.enum.d.ts +53 -0
- package/enums/http-status.enum.js +57 -0
- package/enums/index.d.ts +4 -0
- package/enums/index.js +20 -0
- package/enums/request-method.enum.d.ts +11 -0
- package/enums/request-method.enum.js +15 -0
- package/enums/route-paramtypes.enum.d.ts +14 -0
- package/enums/route-paramtypes.enum.js +18 -0
- package/enums/version-type.enum.d.ts +9 -0
- package/enums/version-type.enum.js +13 -0
- package/errors/bad-gateway.exception.d.ts +33 -0
- package/errors/bad-gateway.exception.js +41 -0
- package/errors/bad-request.exception.d.ts +33 -0
- package/errors/bad-request.exception.js +41 -0
- package/errors/conflict.exception.d.ts +33 -0
- package/errors/conflict.exception.js +41 -0
- package/errors/forbidden.exception.d.ts +33 -0
- package/errors/forbidden.exception.js +41 -0
- package/errors/gateway-timeout.exception.d.ts +33 -0
- package/errors/gateway-timeout.exception.js +41 -0
- package/errors/gone.exception.d.ts +33 -0
- package/errors/gone.exception.js +41 -0
- package/errors/http-version-not-supported.exception.d.ts +33 -0
- package/errors/http-version-not-supported.exception.js +41 -0
- package/errors/http.exception.d.ts +79 -0
- package/errors/http.exception.js +123 -0
- package/errors/im-a-teapot.exception.d.ts +36 -0
- package/errors/im-a-teapot.exception.js +44 -0
- package/errors/index.d.ts +11 -0
- package/errors/index.js +27 -0
- package/errors/internal-server-error.exception.d.ts +33 -0
- package/errors/internal-server-error.exception.js +41 -0
- package/errors/invalid-middleware-configuration.exception.d.ts +4 -0
- package/errors/invalid-middleware-configuration.exception.js +11 -0
- package/errors/invalid-middleware.exception.d.ts +4 -0
- package/errors/invalid-middleware.exception.js +11 -0
- package/errors/not-found.exception.d.ts +33 -0
- package/errors/not-found.exception.js +41 -0
- package/errors/unknown-request-mapping.exception.d.ts +5 -0
- package/errors/unknown-request-mapping.exception.js +11 -0
- package/exceptions/messages.d.ts +4 -0
- package/exceptions/messages.js +13 -0
- package/explorers/path.explorer.d.ts +8 -0
- package/explorers/path.explorer.js +38 -0
- package/explorers/router.explorer.d.ts +51 -0
- package/explorers/router.explorer.js +195 -0
- package/factory/context-id.factory.d.ts +41 -0
- package/factory/context-id.factory.js +52 -0
- package/factory/index.d.ts +4 -0
- package/factory/index.js +20 -0
- package/factory/method.factory.d.ts +5 -0
- package/factory/method.factory.js +30 -0
- package/factory/params.factory.d.ts +5 -0
- package/factory/params.factory.js +39 -0
- package/factory/path.factory.d.ts +13 -0
- package/factory/path.factory.js +95 -0
- package/filters/context.d.ts +9 -0
- package/filters/context.js +15 -0
- package/filters/filter.d.ts +22 -0
- package/filters/filter.js +78 -0
- package/helpers/adapter.helper.d.ts +27 -0
- package/helpers/adapter.helper.js +37 -0
- package/helpers/exclude-route.helper.d.ts +4 -0
- package/helpers/exclude-route.helper.js +18 -0
- package/helpers/flatten-routes.helper.d.ts +5 -0
- package/helpers/flatten-routes.helper.js +27 -0
- package/helpers/index.d.ts +6 -0
- package/helpers/index.js +22 -0
- package/helpers/messages.helper.d.ts +6 -0
- package/helpers/messages.helper.js +25 -0
- package/helpers/path.helper.d.ts +3 -0
- package/helpers/path.helper.js +13 -0
- package/helpers/sse.helper.d.ts +45 -0
- package/helpers/sse.helper.js +83 -0
- package/index.d.ts +1 -0
- package/index.js +3 -0
- package/interfaces/http/cors.interface.d.ts +58 -0
- package/interfaces/http/cors.interface.js +2 -0
- package/interfaces/http/exception.interface.d.ts +6 -0
- package/interfaces/http/exception.interface.js +2 -0
- package/interfaces/http/exclude-route.interface.d.ts +15 -0
- package/interfaces/http/exclude-route.interface.js +2 -0
- package/interfaces/http/index.d.ts +10 -0
- package/interfaces/http/index.js +26 -0
- package/interfaces/http/message-event.interface.d.ts +6 -0
- package/interfaces/http/message-event.interface.js +2 -0
- package/interfaces/http/module.inteface.d.ts +5 -0
- package/interfaces/http/module.inteface.js +2 -0
- package/interfaces/http/options.interface.d.ts +127 -0
- package/interfaces/http/options.interface.js +2 -0
- package/interfaces/http/path-metadata.interface.d.ts +31 -0
- package/interfaces/http/path-metadata.interface.js +2 -0
- package/interfaces/http/prefix-options.interface.d.ts +7 -0
- package/interfaces/http/prefix-options.interface.js +2 -0
- package/interfaces/http/raw-request.d.ts +4 -0
- package/interfaces/http/raw-request.js +2 -0
- package/interfaces/http/routes.interface.d.ts +7 -0
- package/interfaces/http/routes.interface.js +2 -0
- package/interfaces/http/server.interface.d.ts +54 -0
- package/interfaces/http/server.interface.js +2 -0
- package/interfaces/index.d.ts +3 -0
- package/interfaces/index.js +19 -0
- package/interfaces/middleware/config-proxy.interface.d.ts +23 -0
- package/interfaces/middleware/config-proxy.interface.js +2 -0
- package/interfaces/middleware/configuration.interface.d.ts +12 -0
- package/interfaces/middleware/configuration.interface.js +2 -0
- package/interfaces/middleware/consumer.interface.d.ts +16 -0
- package/interfaces/middleware/consumer.interface.js +2 -0
- package/interfaces/middleware/index.d.ts +4 -0
- package/interfaces/middleware/index.js +20 -0
- package/interfaces/middleware/middleware.interface.d.ts +7 -0
- package/interfaces/middleware/middleware.interface.js +2 -0
- package/interfaces/router/callback-paramtypes.interface.d.ts +1 -0
- package/interfaces/router/callback-paramtypes.interface.js +2 -0
- package/interfaces/router/definition.interface.d.ts +10 -0
- package/interfaces/router/definition.interface.js +2 -0
- package/interfaces/router/index.d.ts +3 -0
- package/interfaces/router/index.js +19 -0
- package/interfaces/router/version-options.interface.d.ts +92 -0
- package/interfaces/router/version-options.interface.js +9 -0
- package/middleware/builder.d.ts +15 -0
- package/middleware/builder.js +78 -0
- package/middleware/container.d.ts +13 -0
- package/middleware/container.js +50 -0
- package/middleware/extractor.d.ts +15 -0
- package/middleware/extractor.js +50 -0
- package/middleware/index.d.ts +1 -0
- package/middleware/index.js +17 -0
- package/middleware/module.d.ts +33 -0
- package/middleware/module.js +180 -0
- package/middleware/resolver.d.ts +10 -0
- package/middleware/resolver.js +27 -0
- package/middleware/routes-mapper.d.ts +19 -0
- package/middleware/routes-mapper.js +111 -0
- package/middleware/utils.d.ts +8 -0
- package/middleware/utils.js +86 -0
- package/package.json +41 -0
- package/router/module.d.ts +18 -0
- package/router/module.js +88 -0
- package/router/resolver.d.ts +31 -0
- package/router/resolver.js +128 -0
- package/storage/http-instance.storage.d.ts +9 -0
- package/storage/http-instance.storage.js +19 -0
- package/stream/index.d.ts +1 -0
- package/stream/index.js +17 -0
- package/stream/interfaces/index.d.ts +2 -0
- package/stream/interfaces/index.js +18 -0
- package/stream/interfaces/streamable-handler-response.interface.d.ts +12 -0
- package/stream/interfaces/streamable-handler-response.interface.js +2 -0
- package/stream/interfaces/streamable-options.interface.d.ts +10 -0
- package/stream/interfaces/streamable-options.interface.js +2 -0
- package/stream/streamable-file.d.ts +22 -0
- package/stream/streamable-file.js +55 -0
- package/test/context/response.controller.spec.d.ts +1 -0
- package/test/context/response.controller.spec.js +328 -0
- package/test/decorators/controller.decorator.spec.d.ts +1 -0
- package/test/decorators/controller.decorator.spec.js +113 -0
- package/test/decorators/header.decorator.spec.d.ts +1 -0
- package/test/decorators/header.decorator.spec.js +33 -0
- package/test/decorators/http-code.decorator.spec.d.ts +1 -0
- package/test/decorators/http-code.decorator.spec.js +30 -0
- package/test/decorators/redirect.decorator.spec.d.ts +1 -0
- package/test/decorators/redirect.decorator.spec.js +36 -0
- package/test/decorators/render.decorator.spec.d.ts +1 -0
- package/test/decorators/render.decorator.spec.js +30 -0
- package/test/decorators/request-mapping.decorator.spec.d.ts +1 -0
- package/test/decorators/request-mapping.decorator.spec.js +85 -0
- package/test/decorators/route-params.decorator.spec.d.ts +1 -0
- package/test/decorators/route-params.decorator.spec.js +493 -0
- package/test/decorators/sse.decorator.spec.d.ts +1 -0
- package/test/decorators/sse.decorator.spec.js +35 -0
- package/test/decorators/version.decorator.spec.d.ts +1 -0
- package/test/decorators/version.decorator.spec.js +43 -0
- package/test/exceptions/handler.spec.d.ts +1 -0
- package/test/exceptions/handler.spec.js +145 -0
- package/test/exceptions/proxy.spec.d.ts +1 -0
- package/test/exceptions/proxy.spec.js +74 -0
- package/test/explorers/path.explorer.spec.d.ts +1 -0
- package/test/explorers/path.explorer.spec.js +190 -0
- package/test/explorers/router.explorer.spec.d.ts +1 -0
- package/test/explorers/router.explorer.spec.js +206 -0
- package/test/factory/method.factory.spec.d.ts +1 -0
- package/test/factory/method.factory.spec.js +33 -0
- package/test/factory/params.factory.spec.d.ts +1 -0
- package/test/factory/params.factory.spec.js +104 -0
- package/test/factory/path.factory.spec.d.ts +1 -0
- package/test/factory/path.factory.spec.js +260 -0
- package/test/filters/context.spec.d.ts +1 -0
- package/test/filters/context.spec.js +96 -0
- package/test/filters/filter.spec.d.ts +1 -0
- package/test/filters/filter.spec.js +96 -0
- package/test/helpers/flatten-routes.helper.spec.d.ts +1 -0
- package/test/helpers/flatten-routes.helper.spec.js +131 -0
- package/test/helpers/sse.helper.spec.d.ts +1 -0
- package/test/helpers/sse.helper.spec.js +132 -0
- package/test/middleware/builder.spec.d.ts +1 -0
- package/test/middleware/builder.spec.js +235 -0
- package/test/middleware/container.spec.d.ts +1 -0
- package/test/middleware/container.spec.js +81 -0
- package/test/middleware/module.spec.d.ts +1 -0
- package/test/middleware/module.spec.js +206 -0
- package/test/middleware/route-info-path-extractor.spec.d.ts +1 -0
- package/test/middleware/route-info-path-extractor.spec.js +123 -0
- package/test/middleware/routes-mapper.spec.d.ts +1 -0
- package/test/middleware/routes-mapper.spec.js +162 -0
- package/test/middleware/utils.spec.d.ts +1 -0
- package/test/middleware/utils.spec.js +132 -0
- package/test/router/module.spec.d.ts +1 -0
- package/test/router/module.spec.js +40 -0
- package/test/router/resolver.spec.d.ts +1 -0
- package/test/router/resolver.spec.js +326 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const chai_1 = require("chai");
|
|
10
|
+
const core_1 = require("../../../core/index.ts");
|
|
11
|
+
const helpers_1 = require("../../helpers");
|
|
12
|
+
describe("flattenRoutePaths", () => {
|
|
13
|
+
it("should flatten all route paths", () => {
|
|
14
|
+
let ParentModule = class ParentModule {
|
|
15
|
+
};
|
|
16
|
+
ParentModule = __decorate([
|
|
17
|
+
(0, core_1.Module)({})
|
|
18
|
+
], ParentModule);
|
|
19
|
+
let ChildModule = class ChildModule {
|
|
20
|
+
};
|
|
21
|
+
ChildModule = __decorate([
|
|
22
|
+
(0, core_1.Module)({})
|
|
23
|
+
], ChildModule);
|
|
24
|
+
let ChildChildModule = class ChildChildModule {
|
|
25
|
+
};
|
|
26
|
+
ChildChildModule = __decorate([
|
|
27
|
+
(0, core_1.Module)({})
|
|
28
|
+
], ChildChildModule);
|
|
29
|
+
let ChildModule2 = class ChildModule2 {
|
|
30
|
+
};
|
|
31
|
+
ChildModule2 = __decorate([
|
|
32
|
+
(0, core_1.Module)({})
|
|
33
|
+
], ChildModule2);
|
|
34
|
+
let ParentChildModule = class ParentChildModule {
|
|
35
|
+
};
|
|
36
|
+
ParentChildModule = __decorate([
|
|
37
|
+
(0, core_1.Module)({})
|
|
38
|
+
], ParentChildModule);
|
|
39
|
+
let ChildChildModule2 = class ChildChildModule2 {
|
|
40
|
+
};
|
|
41
|
+
ChildChildModule2 = __decorate([
|
|
42
|
+
(0, core_1.Module)({})
|
|
43
|
+
], ChildChildModule2);
|
|
44
|
+
let AuthModule = class AuthModule {
|
|
45
|
+
};
|
|
46
|
+
AuthModule = __decorate([
|
|
47
|
+
(0, core_1.Module)({})
|
|
48
|
+
], AuthModule);
|
|
49
|
+
let CatsModule = class CatsModule {
|
|
50
|
+
};
|
|
51
|
+
CatsModule = __decorate([
|
|
52
|
+
(0, core_1.Module)({})
|
|
53
|
+
], CatsModule);
|
|
54
|
+
let DogsModule = class DogsModule {
|
|
55
|
+
};
|
|
56
|
+
DogsModule = __decorate([
|
|
57
|
+
(0, core_1.Module)({})
|
|
58
|
+
], DogsModule);
|
|
59
|
+
let AuthModule2 = class AuthModule2 {
|
|
60
|
+
};
|
|
61
|
+
AuthModule2 = __decorate([
|
|
62
|
+
(0, core_1.Module)({})
|
|
63
|
+
], AuthModule2);
|
|
64
|
+
let CatsModule2 = class CatsModule2 {
|
|
65
|
+
};
|
|
66
|
+
CatsModule2 = __decorate([
|
|
67
|
+
(0, core_1.Module)({})
|
|
68
|
+
], CatsModule2);
|
|
69
|
+
let CatsModule3 = class CatsModule3 {
|
|
70
|
+
};
|
|
71
|
+
CatsModule3 = __decorate([
|
|
72
|
+
(0, core_1.Module)({})
|
|
73
|
+
], CatsModule3);
|
|
74
|
+
let AuthModule3 = class AuthModule3 {
|
|
75
|
+
};
|
|
76
|
+
AuthModule3 = __decorate([
|
|
77
|
+
(0, core_1.Module)({})
|
|
78
|
+
], AuthModule3);
|
|
79
|
+
const routes = [
|
|
80
|
+
{
|
|
81
|
+
path: "/parent",
|
|
82
|
+
module: ParentModule,
|
|
83
|
+
children: [
|
|
84
|
+
{
|
|
85
|
+
path: "/child",
|
|
86
|
+
module: ChildModule,
|
|
87
|
+
children: [
|
|
88
|
+
{ path: "/child2", module: ChildModule2 },
|
|
89
|
+
{
|
|
90
|
+
path: "/parentchild",
|
|
91
|
+
module: ParentChildModule,
|
|
92
|
+
children: [
|
|
93
|
+
{
|
|
94
|
+
path: "/childchild",
|
|
95
|
+
module: ChildChildModule,
|
|
96
|
+
children: [{ path: "/child2child", module: ChildChildModule2 }],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
{ path: "/v1", children: [AuthModule, CatsModule, DogsModule] },
|
|
105
|
+
{ path: "/v2", children: [AuthModule2, CatsModule2] },
|
|
106
|
+
{ path: "/v3", children: [AuthModule3, CatsModule3] },
|
|
107
|
+
];
|
|
108
|
+
const expectedRoutes = [
|
|
109
|
+
{ path: "/parent", module: ParentModule },
|
|
110
|
+
{ path: "/parent/child", module: ChildModule },
|
|
111
|
+
{ path: "/parent/child/child2", module: ChildModule2 },
|
|
112
|
+
{ path: "/parent/child/parentchild", module: ParentChildModule },
|
|
113
|
+
{
|
|
114
|
+
path: "/parent/child/parentchild/childchild",
|
|
115
|
+
module: ChildChildModule,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
path: "/parent/child/parentchild/childchild/child2child",
|
|
119
|
+
module: ChildChildModule2,
|
|
120
|
+
},
|
|
121
|
+
{ path: "/v1", module: AuthModule },
|
|
122
|
+
{ path: "/v1", module: CatsModule },
|
|
123
|
+
{ path: "/v1", module: DogsModule },
|
|
124
|
+
{ path: "/v2", module: AuthModule2 },
|
|
125
|
+
{ path: "/v2", module: CatsModule2 },
|
|
126
|
+
{ path: "/v3", module: AuthModule3 },
|
|
127
|
+
{ path: "/v3", module: CatsModule3 },
|
|
128
|
+
];
|
|
129
|
+
(0, chai_1.expect)((0, helpers_1.flattenRoutePaths)(routes)).to.be.eql(expectedRoutes);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
// @ts-ignore
|
|
8
|
+
const eventsource_1 = __importDefault(require("eventsource"));
|
|
9
|
+
const http_1 = require("http");
|
|
10
|
+
const stream_1 = require("../../../../../../../stream");
|
|
11
|
+
const sse_helper_1 = require("@venok/http/helpers/sse.helper");
|
|
12
|
+
const noop = () => { };
|
|
13
|
+
const written = (stream) => new Promise((resolve, reject) => stream.on("error", reject).on("finish", resolve));
|
|
14
|
+
class Sink extends stream_1.Writable {
|
|
15
|
+
constructor(writeHead) {
|
|
16
|
+
super({ objectMode: true });
|
|
17
|
+
this.writeHead = writeHead;
|
|
18
|
+
this.chunks = [];
|
|
19
|
+
}
|
|
20
|
+
_write(chunk, encoding, callback) {
|
|
21
|
+
this.chunks.push(chunk);
|
|
22
|
+
callback();
|
|
23
|
+
}
|
|
24
|
+
get content() {
|
|
25
|
+
return this.chunks.join("");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
describe("SseStream", () => {
|
|
29
|
+
it("writes multiple multiline messages", async () => {
|
|
30
|
+
const sse = new sse_helper_1.SseStream();
|
|
31
|
+
const sink = new Sink();
|
|
32
|
+
sse.pipe(sink);
|
|
33
|
+
sse.writeMessage({
|
|
34
|
+
data: "hello\nworld",
|
|
35
|
+
}, noop);
|
|
36
|
+
sse.writeMessage({
|
|
37
|
+
data: "bonjour\nmonde",
|
|
38
|
+
}, noop);
|
|
39
|
+
sse.end();
|
|
40
|
+
await written(sink);
|
|
41
|
+
(0, chai_1.expect)(sink.content).to.equal(`
|
|
42
|
+
id: 1
|
|
43
|
+
data: hello
|
|
44
|
+
data: world
|
|
45
|
+
|
|
46
|
+
id: 2
|
|
47
|
+
data: bonjour
|
|
48
|
+
data: monde
|
|
49
|
+
|
|
50
|
+
`);
|
|
51
|
+
});
|
|
52
|
+
it("writes object messages as JSON", async () => {
|
|
53
|
+
const sse = new sse_helper_1.SseStream();
|
|
54
|
+
const sink = new Sink();
|
|
55
|
+
sse.pipe(sink);
|
|
56
|
+
sse.writeMessage({
|
|
57
|
+
data: { hello: "world" },
|
|
58
|
+
}, noop);
|
|
59
|
+
sse.end();
|
|
60
|
+
await written(sink);
|
|
61
|
+
(0, chai_1.expect)(sink.content).to.equal(`
|
|
62
|
+
id: 1
|
|
63
|
+
data: {"hello":"world"}
|
|
64
|
+
|
|
65
|
+
`);
|
|
66
|
+
});
|
|
67
|
+
it("writes all message attributes", async () => {
|
|
68
|
+
const sse = new sse_helper_1.SseStream();
|
|
69
|
+
const sink = new Sink();
|
|
70
|
+
sse.pipe(sink);
|
|
71
|
+
sse.writeMessage({
|
|
72
|
+
type: "tea-time",
|
|
73
|
+
id: "the-id",
|
|
74
|
+
retry: 222,
|
|
75
|
+
data: "hello",
|
|
76
|
+
}, noop);
|
|
77
|
+
sse.end();
|
|
78
|
+
await written(sink);
|
|
79
|
+
(0, chai_1.expect)(sink.content).to.equal(`
|
|
80
|
+
event: tea-time
|
|
81
|
+
id: the-id
|
|
82
|
+
retry: 222
|
|
83
|
+
data: hello
|
|
84
|
+
|
|
85
|
+
`);
|
|
86
|
+
});
|
|
87
|
+
it("sets headers on destination when it looks like a HTTP Response", (callback) => {
|
|
88
|
+
const sse = new sse_helper_1.SseStream();
|
|
89
|
+
const sink = new Sink((status, headers) => {
|
|
90
|
+
(0, chai_1.expect)(headers).to.deep.equal({
|
|
91
|
+
"Content-Type": "text/event-stream",
|
|
92
|
+
Connection: "keep-alive",
|
|
93
|
+
"Cache-Control": "private, no-cache, no-store, must-revalidate, max-age=0, no-transform",
|
|
94
|
+
Pragma: "no-cache",
|
|
95
|
+
Expire: "0",
|
|
96
|
+
"X-Accel-Buffering": "no",
|
|
97
|
+
});
|
|
98
|
+
callback();
|
|
99
|
+
return sink;
|
|
100
|
+
});
|
|
101
|
+
sse.pipe(sink);
|
|
102
|
+
});
|
|
103
|
+
it("sets additional headers when provided", (callback) => {
|
|
104
|
+
const sse = new sse_helper_1.SseStream();
|
|
105
|
+
const sink = new Sink((status, headers) => {
|
|
106
|
+
(0, chai_1.expect)(headers).to.contain.keys("access-control-headers");
|
|
107
|
+
(0, chai_1.expect)(headers["access-control-headers"]).to.equal("some-cors-value");
|
|
108
|
+
callback();
|
|
109
|
+
return sink;
|
|
110
|
+
});
|
|
111
|
+
sse.pipe(sink, {
|
|
112
|
+
additionalHeaders: { "access-control-headers": "some-cors-value" },
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
it("allows an eventsource to connect", (callback) => {
|
|
116
|
+
let sse;
|
|
117
|
+
const server = (0, http_1.createServer)((req, res) => {
|
|
118
|
+
sse = new sse_helper_1.SseStream(req);
|
|
119
|
+
sse.pipe(res);
|
|
120
|
+
});
|
|
121
|
+
server.listen(() => {
|
|
122
|
+
const es = new eventsource_1.default(`http://localhost:${server.address().port}`);
|
|
123
|
+
es.onmessage = (e) => {
|
|
124
|
+
(0, chai_1.expect)(e.data).to.equal("hello");
|
|
125
|
+
es.close();
|
|
126
|
+
server.close(callback);
|
|
127
|
+
};
|
|
128
|
+
es.onopen = () => sse.writeMessage({ data: "hello" }, noop);
|
|
129
|
+
es.onerror = (e) => callback(new Error(`Error from EventSource: ${JSON.stringify(e)}`));
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,235 @@
|
|
|
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 core_1 = require("../../../core/index.ts");
|
|
14
|
+
const middleware_1 = require("../../middleware");
|
|
15
|
+
const enums_1 = require("../../enums");
|
|
16
|
+
const routes_mapper_1 = require("../../middleware/routes-mapper");
|
|
17
|
+
const helpers_1 = require("../../helpers");
|
|
18
|
+
const extractor_1 = require("../../middleware/extractor");
|
|
19
|
+
const decorators_1 = require("../../decorators");
|
|
20
|
+
const config_1 = require("../../application/config");
|
|
21
|
+
describe("MiddlewareBuilder", () => {
|
|
22
|
+
let builder;
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
const container = new core_1.VenokContainer();
|
|
25
|
+
const httpConfig = new config_1.HttpConfig();
|
|
26
|
+
httpConfig.enableVersioning({ type: enums_1.VersioningType.URI });
|
|
27
|
+
builder = new middleware_1.MiddlewareBuilder(new routes_mapper_1.RoutesMapper(container, httpConfig), new helpers_1.NoopHttpAdapter({}), new extractor_1.RouteInfoPathExtractor(httpConfig));
|
|
28
|
+
});
|
|
29
|
+
describe("apply", () => {
|
|
30
|
+
it("should return configuration proxy", () => {
|
|
31
|
+
const configProxy = builder.apply([]);
|
|
32
|
+
const metatype = middleware_1.MiddlewareBuilder.ConfigProxy;
|
|
33
|
+
(0, chai_1.expect)(configProxy instanceof metatype).to.be.true;
|
|
34
|
+
});
|
|
35
|
+
describe("configuration proxy", () => {
|
|
36
|
+
describe('when "forRoutes()" called', () => {
|
|
37
|
+
let configProxy;
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
configProxy = builder.apply([]);
|
|
40
|
+
});
|
|
41
|
+
let Test = class Test {
|
|
42
|
+
getAll() { }
|
|
43
|
+
getAllVersioned() { }
|
|
44
|
+
};
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, decorators_1.Get)("route"),
|
|
47
|
+
__metadata("design:type", Function),
|
|
48
|
+
__metadata("design:paramtypes", []),
|
|
49
|
+
__metadata("design:returntype", void 0)
|
|
50
|
+
], Test.prototype, "getAll", null);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, decorators_1.Version)("1"),
|
|
53
|
+
(0, decorators_1.Get)("versioned"),
|
|
54
|
+
__metadata("design:type", Function),
|
|
55
|
+
__metadata("design:paramtypes", []),
|
|
56
|
+
__metadata("design:returntype", void 0)
|
|
57
|
+
], Test.prototype, "getAllVersioned", null);
|
|
58
|
+
Test = __decorate([
|
|
59
|
+
(0, decorators_1.Controller)("path")
|
|
60
|
+
], Test);
|
|
61
|
+
const route = { path: "/test", method: enums_1.RequestMethod.GET };
|
|
62
|
+
it("should store configuration passed as argument", () => {
|
|
63
|
+
configProxy.forRoutes(route, Test);
|
|
64
|
+
(0, chai_1.expect)(builder.build()).to.deep.equal([
|
|
65
|
+
{
|
|
66
|
+
middleware: [],
|
|
67
|
+
forRoutes: [
|
|
68
|
+
{
|
|
69
|
+
method: enums_1.RequestMethod.GET,
|
|
70
|
+
path: route.path,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
method: enums_1.RequestMethod.GET,
|
|
74
|
+
path: "/path/route",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
method: enums_1.RequestMethod.GET,
|
|
78
|
+
path: "/path/versioned",
|
|
79
|
+
version: "1",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
let UsersController = class UsersController {
|
|
86
|
+
hRsvp() { }
|
|
87
|
+
oRsvp() { }
|
|
88
|
+
gRsvp() { }
|
|
89
|
+
pRsvp() { }
|
|
90
|
+
puRsvp() { }
|
|
91
|
+
ptRsvp() { }
|
|
92
|
+
dRsvp() { }
|
|
93
|
+
create() { }
|
|
94
|
+
findAll() { }
|
|
95
|
+
findOne() { }
|
|
96
|
+
update() { }
|
|
97
|
+
remove() { }
|
|
98
|
+
};
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, decorators_1.Head)("rsvp"),
|
|
101
|
+
__metadata("design:type", Function),
|
|
102
|
+
__metadata("design:paramtypes", []),
|
|
103
|
+
__metadata("design:returntype", void 0)
|
|
104
|
+
], UsersController.prototype, "hRsvp", null);
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, decorators_1.Options)("rsvp"),
|
|
107
|
+
__metadata("design:type", Function),
|
|
108
|
+
__metadata("design:paramtypes", []),
|
|
109
|
+
__metadata("design:returntype", void 0)
|
|
110
|
+
], UsersController.prototype, "oRsvp", null);
|
|
111
|
+
__decorate([
|
|
112
|
+
(0, decorators_1.Get)("rsvp"),
|
|
113
|
+
__metadata("design:type", Function),
|
|
114
|
+
__metadata("design:paramtypes", []),
|
|
115
|
+
__metadata("design:returntype", void 0)
|
|
116
|
+
], UsersController.prototype, "gRsvp", null);
|
|
117
|
+
__decorate([
|
|
118
|
+
(0, decorators_1.Post)("rsvp"),
|
|
119
|
+
__metadata("design:type", Function),
|
|
120
|
+
__metadata("design:paramtypes", []),
|
|
121
|
+
__metadata("design:returntype", void 0)
|
|
122
|
+
], UsersController.prototype, "pRsvp", null);
|
|
123
|
+
__decorate([
|
|
124
|
+
(0, decorators_1.Put)("rsvp"),
|
|
125
|
+
__metadata("design:type", Function),
|
|
126
|
+
__metadata("design:paramtypes", []),
|
|
127
|
+
__metadata("design:returntype", void 0)
|
|
128
|
+
], UsersController.prototype, "puRsvp", null);
|
|
129
|
+
__decorate([
|
|
130
|
+
(0, decorators_1.Patch)("rsvp"),
|
|
131
|
+
__metadata("design:type", Function),
|
|
132
|
+
__metadata("design:paramtypes", []),
|
|
133
|
+
__metadata("design:returntype", void 0)
|
|
134
|
+
], UsersController.prototype, "ptRsvp", null);
|
|
135
|
+
__decorate([
|
|
136
|
+
(0, decorators_1.Delete)("rsvp"),
|
|
137
|
+
__metadata("design:type", Function),
|
|
138
|
+
__metadata("design:paramtypes", []),
|
|
139
|
+
__metadata("design:returntype", void 0)
|
|
140
|
+
], UsersController.prototype, "dRsvp", null);
|
|
141
|
+
__decorate([
|
|
142
|
+
(0, decorators_1.Post)(),
|
|
143
|
+
__metadata("design:type", Function),
|
|
144
|
+
__metadata("design:paramtypes", []),
|
|
145
|
+
__metadata("design:returntype", void 0)
|
|
146
|
+
], UsersController.prototype, "create", null);
|
|
147
|
+
__decorate([
|
|
148
|
+
(0, decorators_1.Get)(),
|
|
149
|
+
__metadata("design:type", Function),
|
|
150
|
+
__metadata("design:paramtypes", []),
|
|
151
|
+
__metadata("design:returntype", void 0)
|
|
152
|
+
], UsersController.prototype, "findAll", null);
|
|
153
|
+
__decorate([
|
|
154
|
+
(0, decorators_1.Get)(":id"),
|
|
155
|
+
__metadata("design:type", Function),
|
|
156
|
+
__metadata("design:paramtypes", []),
|
|
157
|
+
__metadata("design:returntype", void 0)
|
|
158
|
+
], UsersController.prototype, "findOne", null);
|
|
159
|
+
__decorate([
|
|
160
|
+
(0, decorators_1.Patch)(":id"),
|
|
161
|
+
__metadata("design:type", Function),
|
|
162
|
+
__metadata("design:paramtypes", []),
|
|
163
|
+
__metadata("design:returntype", void 0)
|
|
164
|
+
], UsersController.prototype, "update", null);
|
|
165
|
+
__decorate([
|
|
166
|
+
(0, decorators_1.Delete)(":id"),
|
|
167
|
+
__metadata("design:type", Function),
|
|
168
|
+
__metadata("design:paramtypes", []),
|
|
169
|
+
__metadata("design:returntype", void 0)
|
|
170
|
+
], UsersController.prototype, "remove", null);
|
|
171
|
+
UsersController = __decorate([
|
|
172
|
+
(0, decorators_1.Controller)("users")
|
|
173
|
+
], UsersController);
|
|
174
|
+
it("should remove overlapping routes", () => {
|
|
175
|
+
configProxy.forRoutes(UsersController);
|
|
176
|
+
(0, chai_1.expect)(builder.build()).to.deep.equal([
|
|
177
|
+
{
|
|
178
|
+
middleware: [],
|
|
179
|
+
forRoutes: [
|
|
180
|
+
{
|
|
181
|
+
method: enums_1.RequestMethod.HEAD,
|
|
182
|
+
path: "/users/rsvp",
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
method: enums_1.RequestMethod.OPTIONS,
|
|
186
|
+
path: "/users/rsvp",
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
method: enums_1.RequestMethod.POST,
|
|
190
|
+
path: "/users/rsvp",
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
method: enums_1.RequestMethod.PUT,
|
|
194
|
+
path: "/users/rsvp",
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
method: enums_1.RequestMethod.POST,
|
|
198
|
+
path: "/users/",
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
method: enums_1.RequestMethod.GET,
|
|
202
|
+
path: "/users/",
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
method: enums_1.RequestMethod.GET,
|
|
206
|
+
path: "/users/:id",
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
method: enums_1.RequestMethod.PATCH,
|
|
210
|
+
path: "/users/:id",
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
method: enums_1.RequestMethod.DELETE,
|
|
214
|
+
path: "/users/:id",
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
]);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
describe("exclude", () => {
|
|
224
|
+
it("should map string to RouteInfo", () => {
|
|
225
|
+
const path = "/test";
|
|
226
|
+
const proxy = builder.apply().exclude(path);
|
|
227
|
+
(0, chai_1.expect)(proxy.getExcludedRoutes()).to.be.eql([
|
|
228
|
+
{
|
|
229
|
+
path,
|
|
230
|
+
method: -1,
|
|
231
|
+
},
|
|
232
|
+
]);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
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 core_1 = require("../../../core/index.ts");
|
|
16
|
+
const container_1 = require("../../middleware/container");
|
|
17
|
+
const module_1 = require("../../../core/injector/module/module");
|
|
18
|
+
const wrapper_1 = require("../../../core/injector/instance/wrapper");
|
|
19
|
+
describe("MiddlewareContainer", () => {
|
|
20
|
+
class ExampleModule {
|
|
21
|
+
}
|
|
22
|
+
let TestRoute = class TestRoute {
|
|
23
|
+
getTest() { }
|
|
24
|
+
getAnother() { }
|
|
25
|
+
};
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, decorators_1.RequestMapping)({ path: "test" }),
|
|
28
|
+
__metadata("design:type", Function),
|
|
29
|
+
__metadata("design:paramtypes", []),
|
|
30
|
+
__metadata("design:returntype", void 0)
|
|
31
|
+
], TestRoute.prototype, "getTest", null);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, decorators_1.RequestMapping)({ path: "another", method: enums_1.RequestMethod.DELETE }),
|
|
34
|
+
__metadata("design:type", Function),
|
|
35
|
+
__metadata("design:paramtypes", []),
|
|
36
|
+
__metadata("design:returntype", void 0)
|
|
37
|
+
], TestRoute.prototype, "getAnother", null);
|
|
38
|
+
TestRoute = __decorate([
|
|
39
|
+
(0, decorators_1.Controller)("test")
|
|
40
|
+
], TestRoute);
|
|
41
|
+
let TestMiddleware = class TestMiddleware {
|
|
42
|
+
use(req, res, next) { }
|
|
43
|
+
};
|
|
44
|
+
TestMiddleware = __decorate([
|
|
45
|
+
(0, core_1.Injectable)()
|
|
46
|
+
], TestMiddleware);
|
|
47
|
+
let container;
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
const nestContainer = new core_1.VenokContainer();
|
|
50
|
+
const modules = nestContainer.getModules();
|
|
51
|
+
modules.set("Module", new module_1.Module(ExampleModule, nestContainer));
|
|
52
|
+
modules.set("Test", new module_1.Module(ExampleModule, nestContainer));
|
|
53
|
+
container = new container_1.MiddlewareContainer(nestContainer);
|
|
54
|
+
});
|
|
55
|
+
it("should store expected configurations for given module", () => {
|
|
56
|
+
const config = [
|
|
57
|
+
{
|
|
58
|
+
middleware: [TestMiddleware],
|
|
59
|
+
forRoutes: [TestRoute, "test"],
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
container.insertConfig(config, "Module");
|
|
63
|
+
(0, chai_1.expect)([...container.getConfigurations().get("Module")]).to.deep.equal(config);
|
|
64
|
+
});
|
|
65
|
+
it("should store expected middleware for given module", () => {
|
|
66
|
+
const config = [
|
|
67
|
+
{
|
|
68
|
+
middleware: TestMiddleware,
|
|
69
|
+
forRoutes: [TestRoute],
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
const key = "Test";
|
|
73
|
+
container.insertConfig(config, key);
|
|
74
|
+
const collection = container.getMiddlewareCollection(key);
|
|
75
|
+
const insertedMiddleware = collection.get(TestMiddleware);
|
|
76
|
+
(0, chai_1.expect)(collection.size).to.eql(config.length);
|
|
77
|
+
(0, chai_1.expect)(insertedMiddleware).to.be.instanceOf(wrapper_1.InstanceWrapper);
|
|
78
|
+
(0, chai_1.expect)(insertedMiddleware.scope).to.be.undefined;
|
|
79
|
+
(0, chai_1.expect)(insertedMiddleware.metatype).to.be.eql(TestMiddleware);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|