@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.
Files changed (254) hide show
  1. package/adapter/adapter.d.ts +57 -0
  2. package/adapter/adapter.js +58 -0
  3. package/adapter/host.d.ts +27 -0
  4. package/adapter/host.js +33 -0
  5. package/application/application.d.ts +18 -0
  6. package/application/application.js +51 -0
  7. package/application/config.d.ts +16 -0
  8. package/application/config.js +47 -0
  9. package/application/http.module-defenition.d.ts +8 -0
  10. package/application/http.module-defenition.js +6 -0
  11. package/application/http.module.d.ts +3 -0
  12. package/application/http.module.js +21 -0
  13. package/application/http.service.d.ts +11 -0
  14. package/application/http.service.js +43 -0
  15. package/application/starter.d.ts +41 -0
  16. package/application/starter.js +140 -0
  17. package/constants.d.ts +12 -0
  18. package/constants.js +15 -0
  19. package/context/context.d.ts +56 -0
  20. package/context/context.js +102 -0
  21. package/context/response.controller.d.ts +30 -0
  22. package/context/response.controller.js +86 -0
  23. package/decorators/controller.decorator.d.ts +82 -0
  24. package/decorators/controller.decorator.js +53 -0
  25. package/decorators/header.decorator.d.ts +12 -0
  26. package/decorators/header.decorator.js +23 -0
  27. package/decorators/http-code.decorator.d.ts +9 -0
  28. package/decorators/http-code.decorator.js +19 -0
  29. package/decorators/index.d.ts +9 -0
  30. package/decorators/index.js +25 -0
  31. package/decorators/redirect.decorator.d.ts +6 -0
  32. package/decorators/redirect.decorator.js +16 -0
  33. package/decorators/render.decorator.d.ts +10 -0
  34. package/decorators/render.decorator.js +20 -0
  35. package/decorators/request-mapping.decorator.d.ts +78 -0
  36. package/decorators/request-mapping.decorator.js +98 -0
  37. package/decorators/route-params.decorator.d.ts +378 -0
  38. package/decorators/route-params.decorator.js +227 -0
  39. package/decorators/sse.decorator.d.ts +6 -0
  40. package/decorators/sse.decorator.js +20 -0
  41. package/decorators/version.decorator.d.ts +7 -0
  42. package/decorators/version.decorator.js +20 -0
  43. package/enums/http-status.enum.d.ts +53 -0
  44. package/enums/http-status.enum.js +57 -0
  45. package/enums/index.d.ts +4 -0
  46. package/enums/index.js +20 -0
  47. package/enums/request-method.enum.d.ts +11 -0
  48. package/enums/request-method.enum.js +15 -0
  49. package/enums/route-paramtypes.enum.d.ts +14 -0
  50. package/enums/route-paramtypes.enum.js +18 -0
  51. package/enums/version-type.enum.d.ts +9 -0
  52. package/enums/version-type.enum.js +13 -0
  53. package/errors/bad-gateway.exception.d.ts +33 -0
  54. package/errors/bad-gateway.exception.js +41 -0
  55. package/errors/bad-request.exception.d.ts +33 -0
  56. package/errors/bad-request.exception.js +41 -0
  57. package/errors/conflict.exception.d.ts +33 -0
  58. package/errors/conflict.exception.js +41 -0
  59. package/errors/forbidden.exception.d.ts +33 -0
  60. package/errors/forbidden.exception.js +41 -0
  61. package/errors/gateway-timeout.exception.d.ts +33 -0
  62. package/errors/gateway-timeout.exception.js +41 -0
  63. package/errors/gone.exception.d.ts +33 -0
  64. package/errors/gone.exception.js +41 -0
  65. package/errors/http-version-not-supported.exception.d.ts +33 -0
  66. package/errors/http-version-not-supported.exception.js +41 -0
  67. package/errors/http.exception.d.ts +79 -0
  68. package/errors/http.exception.js +123 -0
  69. package/errors/im-a-teapot.exception.d.ts +36 -0
  70. package/errors/im-a-teapot.exception.js +44 -0
  71. package/errors/index.d.ts +11 -0
  72. package/errors/index.js +27 -0
  73. package/errors/internal-server-error.exception.d.ts +33 -0
  74. package/errors/internal-server-error.exception.js +41 -0
  75. package/errors/invalid-middleware-configuration.exception.d.ts +4 -0
  76. package/errors/invalid-middleware-configuration.exception.js +11 -0
  77. package/errors/invalid-middleware.exception.d.ts +4 -0
  78. package/errors/invalid-middleware.exception.js +11 -0
  79. package/errors/not-found.exception.d.ts +33 -0
  80. package/errors/not-found.exception.js +41 -0
  81. package/errors/unknown-request-mapping.exception.d.ts +5 -0
  82. package/errors/unknown-request-mapping.exception.js +11 -0
  83. package/exceptions/messages.d.ts +4 -0
  84. package/exceptions/messages.js +13 -0
  85. package/explorers/path.explorer.d.ts +8 -0
  86. package/explorers/path.explorer.js +38 -0
  87. package/explorers/router.explorer.d.ts +51 -0
  88. package/explorers/router.explorer.js +195 -0
  89. package/factory/context-id.factory.d.ts +41 -0
  90. package/factory/context-id.factory.js +52 -0
  91. package/factory/index.d.ts +4 -0
  92. package/factory/index.js +20 -0
  93. package/factory/method.factory.d.ts +5 -0
  94. package/factory/method.factory.js +30 -0
  95. package/factory/params.factory.d.ts +5 -0
  96. package/factory/params.factory.js +39 -0
  97. package/factory/path.factory.d.ts +13 -0
  98. package/factory/path.factory.js +95 -0
  99. package/filters/context.d.ts +9 -0
  100. package/filters/context.js +15 -0
  101. package/filters/filter.d.ts +22 -0
  102. package/filters/filter.js +78 -0
  103. package/helpers/adapter.helper.d.ts +27 -0
  104. package/helpers/adapter.helper.js +37 -0
  105. package/helpers/exclude-route.helper.d.ts +4 -0
  106. package/helpers/exclude-route.helper.js +18 -0
  107. package/helpers/flatten-routes.helper.d.ts +5 -0
  108. package/helpers/flatten-routes.helper.js +27 -0
  109. package/helpers/index.d.ts +6 -0
  110. package/helpers/index.js +22 -0
  111. package/helpers/messages.helper.d.ts +6 -0
  112. package/helpers/messages.helper.js +25 -0
  113. package/helpers/path.helper.d.ts +3 -0
  114. package/helpers/path.helper.js +13 -0
  115. package/helpers/sse.helper.d.ts +45 -0
  116. package/helpers/sse.helper.js +83 -0
  117. package/index.d.ts +1 -0
  118. package/index.js +3 -0
  119. package/interfaces/http/cors.interface.d.ts +58 -0
  120. package/interfaces/http/cors.interface.js +2 -0
  121. package/interfaces/http/exception.interface.d.ts +6 -0
  122. package/interfaces/http/exception.interface.js +2 -0
  123. package/interfaces/http/exclude-route.interface.d.ts +15 -0
  124. package/interfaces/http/exclude-route.interface.js +2 -0
  125. package/interfaces/http/index.d.ts +10 -0
  126. package/interfaces/http/index.js +26 -0
  127. package/interfaces/http/message-event.interface.d.ts +6 -0
  128. package/interfaces/http/message-event.interface.js +2 -0
  129. package/interfaces/http/module.inteface.d.ts +5 -0
  130. package/interfaces/http/module.inteface.js +2 -0
  131. package/interfaces/http/options.interface.d.ts +127 -0
  132. package/interfaces/http/options.interface.js +2 -0
  133. package/interfaces/http/path-metadata.interface.d.ts +31 -0
  134. package/interfaces/http/path-metadata.interface.js +2 -0
  135. package/interfaces/http/prefix-options.interface.d.ts +7 -0
  136. package/interfaces/http/prefix-options.interface.js +2 -0
  137. package/interfaces/http/raw-request.d.ts +4 -0
  138. package/interfaces/http/raw-request.js +2 -0
  139. package/interfaces/http/routes.interface.d.ts +7 -0
  140. package/interfaces/http/routes.interface.js +2 -0
  141. package/interfaces/http/server.interface.d.ts +54 -0
  142. package/interfaces/http/server.interface.js +2 -0
  143. package/interfaces/index.d.ts +3 -0
  144. package/interfaces/index.js +19 -0
  145. package/interfaces/middleware/config-proxy.interface.d.ts +23 -0
  146. package/interfaces/middleware/config-proxy.interface.js +2 -0
  147. package/interfaces/middleware/configuration.interface.d.ts +12 -0
  148. package/interfaces/middleware/configuration.interface.js +2 -0
  149. package/interfaces/middleware/consumer.interface.d.ts +16 -0
  150. package/interfaces/middleware/consumer.interface.js +2 -0
  151. package/interfaces/middleware/index.d.ts +4 -0
  152. package/interfaces/middleware/index.js +20 -0
  153. package/interfaces/middleware/middleware.interface.d.ts +7 -0
  154. package/interfaces/middleware/middleware.interface.js +2 -0
  155. package/interfaces/router/callback-paramtypes.interface.d.ts +1 -0
  156. package/interfaces/router/callback-paramtypes.interface.js +2 -0
  157. package/interfaces/router/definition.interface.d.ts +10 -0
  158. package/interfaces/router/definition.interface.js +2 -0
  159. package/interfaces/router/index.d.ts +3 -0
  160. package/interfaces/router/index.js +19 -0
  161. package/interfaces/router/version-options.interface.d.ts +92 -0
  162. package/interfaces/router/version-options.interface.js +9 -0
  163. package/middleware/builder.d.ts +15 -0
  164. package/middleware/builder.js +78 -0
  165. package/middleware/container.d.ts +13 -0
  166. package/middleware/container.js +50 -0
  167. package/middleware/extractor.d.ts +15 -0
  168. package/middleware/extractor.js +50 -0
  169. package/middleware/index.d.ts +1 -0
  170. package/middleware/index.js +17 -0
  171. package/middleware/module.d.ts +33 -0
  172. package/middleware/module.js +180 -0
  173. package/middleware/resolver.d.ts +10 -0
  174. package/middleware/resolver.js +27 -0
  175. package/middleware/routes-mapper.d.ts +19 -0
  176. package/middleware/routes-mapper.js +111 -0
  177. package/middleware/utils.d.ts +8 -0
  178. package/middleware/utils.js +86 -0
  179. package/package.json +41 -0
  180. package/router/module.d.ts +18 -0
  181. package/router/module.js +88 -0
  182. package/router/resolver.d.ts +31 -0
  183. package/router/resolver.js +128 -0
  184. package/storage/http-instance.storage.d.ts +9 -0
  185. package/storage/http-instance.storage.js +19 -0
  186. package/stream/index.d.ts +1 -0
  187. package/stream/index.js +17 -0
  188. package/stream/interfaces/index.d.ts +2 -0
  189. package/stream/interfaces/index.js +18 -0
  190. package/stream/interfaces/streamable-handler-response.interface.d.ts +12 -0
  191. package/stream/interfaces/streamable-handler-response.interface.js +2 -0
  192. package/stream/interfaces/streamable-options.interface.d.ts +10 -0
  193. package/stream/interfaces/streamable-options.interface.js +2 -0
  194. package/stream/streamable-file.d.ts +22 -0
  195. package/stream/streamable-file.js +55 -0
  196. package/test/context/response.controller.spec.d.ts +1 -0
  197. package/test/context/response.controller.spec.js +328 -0
  198. package/test/decorators/controller.decorator.spec.d.ts +1 -0
  199. package/test/decorators/controller.decorator.spec.js +113 -0
  200. package/test/decorators/header.decorator.spec.d.ts +1 -0
  201. package/test/decorators/header.decorator.spec.js +33 -0
  202. package/test/decorators/http-code.decorator.spec.d.ts +1 -0
  203. package/test/decorators/http-code.decorator.spec.js +30 -0
  204. package/test/decorators/redirect.decorator.spec.d.ts +1 -0
  205. package/test/decorators/redirect.decorator.spec.js +36 -0
  206. package/test/decorators/render.decorator.spec.d.ts +1 -0
  207. package/test/decorators/render.decorator.spec.js +30 -0
  208. package/test/decorators/request-mapping.decorator.spec.d.ts +1 -0
  209. package/test/decorators/request-mapping.decorator.spec.js +85 -0
  210. package/test/decorators/route-params.decorator.spec.d.ts +1 -0
  211. package/test/decorators/route-params.decorator.spec.js +493 -0
  212. package/test/decorators/sse.decorator.spec.d.ts +1 -0
  213. package/test/decorators/sse.decorator.spec.js +35 -0
  214. package/test/decorators/version.decorator.spec.d.ts +1 -0
  215. package/test/decorators/version.decorator.spec.js +43 -0
  216. package/test/exceptions/handler.spec.d.ts +1 -0
  217. package/test/exceptions/handler.spec.js +145 -0
  218. package/test/exceptions/proxy.spec.d.ts +1 -0
  219. package/test/exceptions/proxy.spec.js +74 -0
  220. package/test/explorers/path.explorer.spec.d.ts +1 -0
  221. package/test/explorers/path.explorer.spec.js +190 -0
  222. package/test/explorers/router.explorer.spec.d.ts +1 -0
  223. package/test/explorers/router.explorer.spec.js +206 -0
  224. package/test/factory/method.factory.spec.d.ts +1 -0
  225. package/test/factory/method.factory.spec.js +33 -0
  226. package/test/factory/params.factory.spec.d.ts +1 -0
  227. package/test/factory/params.factory.spec.js +104 -0
  228. package/test/factory/path.factory.spec.d.ts +1 -0
  229. package/test/factory/path.factory.spec.js +260 -0
  230. package/test/filters/context.spec.d.ts +1 -0
  231. package/test/filters/context.spec.js +96 -0
  232. package/test/filters/filter.spec.d.ts +1 -0
  233. package/test/filters/filter.spec.js +96 -0
  234. package/test/helpers/flatten-routes.helper.spec.d.ts +1 -0
  235. package/test/helpers/flatten-routes.helper.spec.js +131 -0
  236. package/test/helpers/sse.helper.spec.d.ts +1 -0
  237. package/test/helpers/sse.helper.spec.js +132 -0
  238. package/test/middleware/builder.spec.d.ts +1 -0
  239. package/test/middleware/builder.spec.js +235 -0
  240. package/test/middleware/container.spec.d.ts +1 -0
  241. package/test/middleware/container.spec.js +81 -0
  242. package/test/middleware/module.spec.d.ts +1 -0
  243. package/test/middleware/module.spec.js +206 -0
  244. package/test/middleware/route-info-path-extractor.spec.d.ts +1 -0
  245. package/test/middleware/route-info-path-extractor.spec.js +123 -0
  246. package/test/middleware/routes-mapper.spec.d.ts +1 -0
  247. package/test/middleware/routes-mapper.spec.js +162 -0
  248. package/test/middleware/utils.spec.d.ts +1 -0
  249. package/test/middleware/utils.spec.js +132 -0
  250. package/test/router/module.spec.d.ts +1 -0
  251. package/test/router/module.spec.js +40 -0
  252. package/test/router/resolver.spec.d.ts +1 -0
  253. package/test/router/resolver.spec.js +326 -0
  254. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const params_factory_1 = require("@venok/http/factory/params.factory");
5
+ const enums_1 = require("@venok/http/enums");
6
+ describe("RouteParamsFactory", () => {
7
+ let factory;
8
+ beforeEach(() => {
9
+ factory = new params_factory_1.RouteParamsFactory();
10
+ });
11
+ describe("exchangeKeyForValue", () => {
12
+ const res = {};
13
+ const next = () => ({});
14
+ const req = {
15
+ ip: "ip",
16
+ session: null,
17
+ body: {
18
+ foo: "bar",
19
+ },
20
+ headers: {
21
+ foo: "bar",
22
+ },
23
+ params: {
24
+ foo: "bar",
25
+ },
26
+ hosts: {
27
+ foo: "bar",
28
+ },
29
+ query: {
30
+ foo: "bar",
31
+ },
32
+ file: "file",
33
+ files: "files",
34
+ };
35
+ describe("when key is", () => {
36
+ const args = [null, [req, res, next]];
37
+ describe(`RouteParamtypes.NEXT`, () => {
38
+ it("should return next object", () => {
39
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.NEXT, ...args)).to.be.eql(next);
40
+ });
41
+ });
42
+ describe(`RouteParamtypes.RESPONSE`, () => {
43
+ it("should return response object", () => {
44
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.RESPONSE, ...args)).to.be.eql(res);
45
+ });
46
+ });
47
+ describe(`RouteParamtypes.REQUEST`, () => {
48
+ it("should return request object", () => {
49
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.REQUEST, ...args)).to.be.eql(req);
50
+ });
51
+ });
52
+ describe(`RouteParamtypes.BODY`, () => {
53
+ it("should return body object", () => {
54
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.BODY, ...args)).to.be.eql(req.body);
55
+ });
56
+ });
57
+ describe(`RouteParamtypes.HEADERS`, () => {
58
+ it("should return headers object", () => {
59
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.HEADERS, ...args)).to.be.eql(req.headers);
60
+ });
61
+ });
62
+ describe(`RouteParamtypes.IP`, () => {
63
+ it("should return ip property", () => {
64
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.IP, ...args)).to.be.equal(req.ip);
65
+ });
66
+ });
67
+ describe(`RouteParamtypes.SESSION`, () => {
68
+ it("should return session object", () => {
69
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.SESSION, ...args)).to.be.eql(req.session);
70
+ });
71
+ });
72
+ describe(`RouteParamtypes.QUERY`, () => {
73
+ it("should return query object", () => {
74
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.QUERY, ...args)).to.be.eql(req.query);
75
+ });
76
+ });
77
+ describe(`RouteParamtypes.PARAM`, () => {
78
+ it("should return params object", () => {
79
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.PARAM, ...args)).to.be.eql(req.params);
80
+ });
81
+ });
82
+ describe(`RouteParamtypes.HOST`, () => {
83
+ it("should return hosts object", () => {
84
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.HOST, ...args)).to.be.eql(req.hosts);
85
+ });
86
+ });
87
+ describe(`RouteParamtypes.FILE`, () => {
88
+ it("should return file object", () => {
89
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.FILE, ...args)).to.be.eql(req.file);
90
+ });
91
+ });
92
+ describe(`RouteParamtypes.FILES`, () => {
93
+ it("should return files object", () => {
94
+ (0, chai_1.expect)(factory.exchangeKeyForValue(enums_1.RouteParamtypes.FILES, ...args)).to.be.eql(req.files);
95
+ });
96
+ });
97
+ describe("not available", () => {
98
+ it("should return null", () => {
99
+ (0, chai_1.expect)(factory.exchangeKeyForValue(-1, ...args)).to.be.eql(null);
100
+ });
101
+ });
102
+ });
103
+ });
104
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,260 @@
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 path_to_regexp_1 = require("path-to-regexp");
8
+ const sinon_1 = __importDefault(require("sinon"));
9
+ const factory_1 = require("../../factory");
10
+ const enums_1 = require("../../enums");
11
+ const interfaces_1 = require("../../interfaces");
12
+ const config_1 = require("../../application/config");
13
+ describe("RoutePathFactory", () => {
14
+ let routePathFactory;
15
+ let httpConfig;
16
+ beforeEach(() => {
17
+ httpConfig = new config_1.HttpConfig();
18
+ routePathFactory = new factory_1.RoutePathFactory(httpConfig);
19
+ });
20
+ describe("create", () => {
21
+ it("should return valid, concatenated paths (various combinations)", () => {
22
+ (0, chai_1.expect)(routePathFactory.create({
23
+ ctrlPath: "ctrlPath/",
24
+ methodPath: "",
25
+ })).to.deep.equal(["/ctrlPath"]);
26
+ (0, chai_1.expect)(routePathFactory.create({
27
+ ctrlPath: "/ctrlPath",
28
+ methodPath: "",
29
+ })).to.deep.equal(["/ctrlPath"]);
30
+ (0, chai_1.expect)(routePathFactory.create({
31
+ ctrlPath: "/ctrlPath/",
32
+ methodPath: "/methodPath",
33
+ })).to.deep.equal(["/ctrlPath/methodPath"]);
34
+ (0, chai_1.expect)(routePathFactory.create({
35
+ ctrlPath: "ctrlPath/",
36
+ methodPath: "methodPath/",
37
+ })).to.deep.equal(["/ctrlPath/methodPath"]);
38
+ (0, chai_1.expect)(routePathFactory.create({
39
+ ctrlPath: "ctrlPath/",
40
+ methodPath: "methodPath",
41
+ modulePath: "modulePath",
42
+ })).to.deep.equal(["/modulePath/ctrlPath/methodPath"]);
43
+ (0, chai_1.expect)(routePathFactory.create({
44
+ ctrlPath: "ctrlPath/",
45
+ methodPath: "methodPath",
46
+ modulePath: "/modulePath",
47
+ })).to.deep.equal(["/modulePath/ctrlPath/methodPath"]);
48
+ (0, chai_1.expect)(routePathFactory.create({
49
+ ctrlPath: "/ctrlPath/",
50
+ methodPath: "/methodPath/",
51
+ modulePath: "/modulePath/",
52
+ })).to.deep.equal(["/modulePath/ctrlPath/methodPath"]);
53
+ (0, chai_1.expect)(routePathFactory.create({
54
+ ctrlPath: "/ctrlPath/",
55
+ methodPath: "/methodPath/",
56
+ modulePath: "/modulePath/",
57
+ globalPrefix: "api",
58
+ })).to.deep.equal(["/api/modulePath/ctrlPath/methodPath"]);
59
+ (0, chai_1.expect)(routePathFactory.create({
60
+ ctrlPath: "/ctrlPath/",
61
+ methodPath: "/methodPath/",
62
+ modulePath: "/modulePath/",
63
+ globalPrefix: "/api",
64
+ })).to.deep.equal(["/api/modulePath/ctrlPath/methodPath"]);
65
+ (0, chai_1.expect)(routePathFactory.create({
66
+ ctrlPath: "/ctrlPath/",
67
+ methodPath: "/methodPath/",
68
+ modulePath: "/modulePath/",
69
+ globalPrefix: "/api",
70
+ versioningOptions: {
71
+ type: enums_1.VersioningType.HEADER,
72
+ header: "x",
73
+ },
74
+ methodVersion: "1.0.0",
75
+ controllerVersion: "1.1.1",
76
+ })).to.deep.equal(["/api/modulePath/ctrlPath/methodPath"]);
77
+ (0, chai_1.expect)(routePathFactory.create({
78
+ ctrlPath: "/ctrlPath/",
79
+ methodPath: "/methodPath/",
80
+ modulePath: "/modulePath/",
81
+ globalPrefix: "/api/",
82
+ versioningOptions: {
83
+ type: enums_1.VersioningType.URI,
84
+ },
85
+ methodVersion: "1.0.0",
86
+ controllerVersion: "1.1.1",
87
+ })).to.deep.equal(["/api/v1.0.0/modulePath/ctrlPath/methodPath"]);
88
+ (0, chai_1.expect)(routePathFactory.create({
89
+ ctrlPath: "/ctrlPath/",
90
+ methodPath: "/methodPath/",
91
+ modulePath: "/modulePath/",
92
+ versioningOptions: {
93
+ type: enums_1.VersioningType.URI,
94
+ },
95
+ methodVersion: "1.0.0",
96
+ controllerVersion: "1.1.1",
97
+ })).to.deep.equal(["/v1.0.0/modulePath/ctrlPath/methodPath"]);
98
+ (0, chai_1.expect)(routePathFactory.create({
99
+ ctrlPath: "/ctrlPath/",
100
+ methodPath: "/methodPath/",
101
+ globalPrefix: "/api",
102
+ versioningOptions: {
103
+ type: enums_1.VersioningType.URI,
104
+ },
105
+ methodVersion: "1.0.0",
106
+ controllerVersion: "1.1.1",
107
+ })).to.deep.equal(["/api/v1.0.0/ctrlPath/methodPath"]);
108
+ (0, chai_1.expect)(routePathFactory.create({
109
+ ctrlPath: "/ctrlPath/",
110
+ methodPath: "/methodPath/",
111
+ globalPrefix: "/api",
112
+ versioningOptions: {
113
+ type: enums_1.VersioningType.URI,
114
+ },
115
+ controllerVersion: "1.1.1",
116
+ })).to.deep.equal(["/api/v1.1.1/ctrlPath/methodPath"]);
117
+ (0, chai_1.expect)(routePathFactory.create({
118
+ ctrlPath: "/ctrlPath/",
119
+ methodPath: "/methodPath/",
120
+ globalPrefix: "/api",
121
+ versioningOptions: {
122
+ type: enums_1.VersioningType.URI,
123
+ },
124
+ controllerVersion: ["1.1.1", "1.2.3"],
125
+ })).to.deep.equal(["/api/v1.1.1/ctrlPath/methodPath", "/api/v1.2.3/ctrlPath/methodPath"]);
126
+ (0, chai_1.expect)(routePathFactory.create({
127
+ ctrlPath: "",
128
+ methodPath: "",
129
+ globalPrefix: "/api",
130
+ versioningOptions: {
131
+ type: enums_1.VersioningType.URI,
132
+ },
133
+ controllerVersion: ["1.1.1", "1.2.3"],
134
+ })).to.deep.equal(["/api/v1.1.1", "/api/v1.2.3"]);
135
+ (0, chai_1.expect)(routePathFactory.create({
136
+ ctrlPath: "",
137
+ methodPath: "",
138
+ globalPrefix: "",
139
+ controllerVersion: interfaces_1.VERSION_NEUTRAL,
140
+ versioningOptions: {
141
+ type: enums_1.VersioningType.URI,
142
+ defaultVersion: interfaces_1.VERSION_NEUTRAL,
143
+ },
144
+ })).to.deep.equal(["/"]);
145
+ (0, chai_1.expect)(routePathFactory.create({
146
+ ctrlPath: "",
147
+ methodPath: "",
148
+ globalPrefix: "",
149
+ controllerVersion: ["1", interfaces_1.VERSION_NEUTRAL],
150
+ versioningOptions: {
151
+ type: enums_1.VersioningType.URI,
152
+ defaultVersion: ["1", interfaces_1.VERSION_NEUTRAL],
153
+ },
154
+ })).to.deep.equal(["/v1", "/"]);
155
+ (0, chai_1.expect)(routePathFactory.create({
156
+ ctrlPath: "",
157
+ methodPath: "",
158
+ globalPrefix: "",
159
+ })).to.deep.equal(["/"]);
160
+ sinon_1.default.stub(routePathFactory, "isExcludedFromGlobalPrefix").returns(true);
161
+ (0, chai_1.expect)(routePathFactory.create({
162
+ ctrlPath: "/ctrlPath/",
163
+ methodPath: "/",
164
+ modulePath: "/",
165
+ globalPrefix: "/api",
166
+ })).to.deep.equal(["/ctrlPath"]);
167
+ sinon_1.default.restore();
168
+ });
169
+ });
170
+ describe("isExcludedFromGlobalPrefix", () => {
171
+ describe("when there is no exclude configuration", () => {
172
+ it("should return false", () => {
173
+ sinon_1.default.stub(httpConfig, "getGlobalPrefixOptions").returns({
174
+ exclude: undefined,
175
+ });
176
+ (0, chai_1.expect)(routePathFactory.isExcludedFromGlobalPrefix("/cats", enums_1.RequestMethod.GET)).to.be.false;
177
+ });
178
+ });
179
+ describe("otherwise", () => {
180
+ describe("when route is not excluded", () => {
181
+ it("should return false", () => {
182
+ sinon_1.default.stub(httpConfig, "getGlobalPrefixOptions").returns({
183
+ exclude: [
184
+ {
185
+ path: "/random",
186
+ pathRegex: (0, path_to_regexp_1.pathToRegexp)("/random"),
187
+ requestMethod: enums_1.RequestMethod.ALL,
188
+ },
189
+ ],
190
+ });
191
+ (0, chai_1.expect)(routePathFactory.isExcludedFromGlobalPrefix("/cats", enums_1.RequestMethod.GET)).to.be.false;
192
+ });
193
+ });
194
+ describe("when route is excluded (by path)", () => {
195
+ it("should return true", () => {
196
+ sinon_1.default.stub(httpConfig, "getGlobalPrefixOptions").returns({
197
+ exclude: [
198
+ {
199
+ path: "/cats",
200
+ pathRegex: (0, path_to_regexp_1.pathToRegexp)("/cats"),
201
+ requestMethod: enums_1.RequestMethod.ALL,
202
+ },
203
+ ],
204
+ });
205
+ (0, chai_1.expect)(routePathFactory.isExcludedFromGlobalPrefix("/cats", enums_1.RequestMethod.GET)).to.be.true;
206
+ });
207
+ describe("when route is excluded (by method and path)", () => {
208
+ it("should return true", () => {
209
+ sinon_1.default.stub(httpConfig, "getGlobalPrefixOptions").returns({
210
+ exclude: [
211
+ {
212
+ path: "/cats",
213
+ pathRegex: (0, path_to_regexp_1.pathToRegexp)("/cats"),
214
+ requestMethod: enums_1.RequestMethod.GET,
215
+ },
216
+ ],
217
+ });
218
+ (0, chai_1.expect)(routePathFactory.isExcludedFromGlobalPrefix("/cats", enums_1.RequestMethod.GET)).to.be.true;
219
+ (0, chai_1.expect)(routePathFactory.isExcludedFromGlobalPrefix("/cats", enums_1.RequestMethod.POST)).to.be.false;
220
+ });
221
+ });
222
+ });
223
+ });
224
+ });
225
+ describe("getVersionPrefix", () => {
226
+ describe("when URI versioning is enabled", () => {
227
+ describe("and prefix is disabled", () => {
228
+ it("should return empty string", () => {
229
+ (0, chai_1.expect)(routePathFactory.getVersionPrefix({
230
+ type: enums_1.VersioningType.URI,
231
+ prefix: false,
232
+ })).to.equal("");
233
+ });
234
+ });
235
+ describe("and prefix is undefined", () => {
236
+ it("should return the default prefix", () => {
237
+ (0, chai_1.expect)(routePathFactory.getVersionPrefix({
238
+ type: enums_1.VersioningType.URI,
239
+ })).to.equal("v");
240
+ });
241
+ });
242
+ describe("and prefix is specified", () => {
243
+ it("should return it", () => {
244
+ (0, chai_1.expect)(routePathFactory.getVersionPrefix({
245
+ type: enums_1.VersioningType.URI,
246
+ prefix: "test",
247
+ })).to.equal("test");
248
+ });
249
+ });
250
+ });
251
+ describe("when URI versioning is disabled", () => {
252
+ it("should return default prefix", () => {
253
+ (0, chai_1.expect)(routePathFactory.getVersionPrefix({
254
+ type: enums_1.VersioningType.HEADER,
255
+ header: "X",
256
+ })).to.equal("v");
257
+ });
258
+ });
259
+ });
260
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,96 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const chai_1 = require("chai");
13
+ const sinon_1 = __importDefault(require("sinon"));
14
+ const core_1 = require("../../../core/index.ts");
15
+ const context_1 = require("../../filters/context");
16
+ const helpers_1 = require("../../helpers");
17
+ const wrapper_1 = require("../../../core/injector/instance/wrapper");
18
+ const filter_1 = require("../../filters/filter");
19
+ describe("RouterExceptionFiltersContext", () => {
20
+ let applicationConfig;
21
+ let exceptionFilter;
22
+ class CustomException {
23
+ }
24
+ let ExceptionFilter = class ExceptionFilter {
25
+ catch(exc, res) { }
26
+ };
27
+ ExceptionFilter = __decorate([
28
+ (0, core_1.Catch)(CustomException)
29
+ ], ExceptionFilter);
30
+ beforeEach(() => {
31
+ applicationConfig = new core_1.ApplicationConfig();
32
+ exceptionFilter = new context_1.RouterExceptionFiltersContext(new core_1.VenokContainer(), applicationConfig,
33
+ // new HttpConfig(),
34
+ new helpers_1.NoopHttpAdapter({}));
35
+ });
36
+ describe("create", () => {
37
+ describe("when filters metadata is empty", () => {
38
+ class EmptyMetadata {
39
+ }
40
+ beforeEach(() => {
41
+ sinon_1.default.stub(exceptionFilter, "createContext").returns([]);
42
+ });
43
+ it("should return plain ExceptionHandler object", () => {
44
+ const filter = exceptionFilter.create(new EmptyMetadata(), () => ({}), undefined);
45
+ (0, chai_1.expect)(filter.filters).to.be.empty;
46
+ });
47
+ });
48
+ describe("when filters metadata is not empty", () => {
49
+ let WithMetadata = class WithMetadata {
50
+ };
51
+ WithMetadata = __decorate([
52
+ (0, core_1.UseFilters)(new filter_1.HttpExceptionFilter())
53
+ ], WithMetadata);
54
+ it("should return ExceptionHandler object with exception filters", () => {
55
+ const filter = exceptionFilter.create(new WithMetadata(), () => ({}), undefined);
56
+ (0, chai_1.expect)(filter.filters).to.not.be.empty;
57
+ });
58
+ });
59
+ });
60
+ describe("reflectCatchExceptions", () => {
61
+ it("should return FILTER_CATCH_EXCEPTIONS metadata", () => {
62
+ (0, chai_1.expect)(exceptionFilter.reflectCatchExceptions(new ExceptionFilter())).to.be.eql([CustomException]);
63
+ });
64
+ });
65
+ describe("createConcreteContext", () => {
66
+ class InvalidFilter {
67
+ }
68
+ const filters = [new ExceptionFilter(), new InvalidFilter(), "test"];
69
+ it("should return expected exception filters metadata", () => {
70
+ const resolved = exceptionFilter.createConcreteContext(filters);
71
+ (0, chai_1.expect)(resolved).to.have.length(1);
72
+ (0, chai_1.expect)(resolved[0].exceptionMetatypes).to.be.deep.equal([CustomException]);
73
+ (0, chai_1.expect)(resolved[0].func).to.be.a("function");
74
+ });
75
+ });
76
+ describe("getGlobalMetadata", () => {
77
+ describe("when contextId is static and inquirerId is nil", () => {
78
+ it("should return global filters", () => {
79
+ const expectedResult = applicationConfig.getGlobalFilters();
80
+ (0, chai_1.expect)(exceptionFilter.getGlobalMetadata()).to.be.equal(expectedResult);
81
+ });
82
+ });
83
+ describe("otherwise", () => {
84
+ it("should merge static global with request/transient scoped filters", () => {
85
+ const globalFilters = ["test"];
86
+ const instanceWrapper = new wrapper_1.InstanceWrapper();
87
+ const instance = "request-scoped";
88
+ const scopedFilterWrappers = [instanceWrapper];
89
+ sinon_1.default.stub(applicationConfig, "getGlobalFilters").callsFake(() => globalFilters);
90
+ sinon_1.default.stub(applicationConfig, "getGlobalRequestFilters").callsFake(() => scopedFilterWrappers);
91
+ sinon_1.default.stub(instanceWrapper, "getInstanceByContextId").callsFake(() => ({ instance }));
92
+ (0, chai_1.expect)(exceptionFilter.getGlobalMetadata({ id: 3 })).to.contains(instance, ...globalFilters);
93
+ });
94
+ });
95
+ });
96
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,96 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const chai_1 = require("chai");
13
+ const sinon_1 = __importDefault(require("sinon"));
14
+ const core_1 = require("../../../core/index.ts");
15
+ const context_1 = require("../../filters/context");
16
+ const config_1 = require("../../application/config");
17
+ const helpers_1 = require("../../helpers");
18
+ const wrapper_1 = require("../../../core/injector/instance/wrapper");
19
+ describe("RouterExceptionFiltersContext", () => {
20
+ let applicationConfig;
21
+ let httpConfig;
22
+ let exceptionFilter;
23
+ class CustomException {
24
+ }
25
+ let ExceptionFilter = class ExceptionFilter {
26
+ catch(exc, res) { }
27
+ };
28
+ ExceptionFilter = __decorate([
29
+ (0, core_1.Catch)(CustomException)
30
+ ], ExceptionFilter);
31
+ beforeEach(() => {
32
+ applicationConfig = new core_1.ApplicationConfig();
33
+ httpConfig = new config_1.HttpConfig();
34
+ exceptionFilter = new context_1.RouterExceptionFiltersContext(new core_1.VenokContainer(), applicationConfig, new helpers_1.NoopHttpAdapter({}));
35
+ });
36
+ describe("create", () => {
37
+ describe("when filters metadata is empty", () => {
38
+ class EmptyMetadata {
39
+ }
40
+ beforeEach(() => {
41
+ sinon_1.default.stub(exceptionFilter, "createContext").returns([]);
42
+ });
43
+ it("should return plain ExceptionHandler object", () => {
44
+ const filter = exceptionFilter.create(new EmptyMetadata(), () => ({}), undefined);
45
+ (0, chai_1.expect)(filter.filters).to.be.empty;
46
+ });
47
+ });
48
+ describe("when filters metadata is not empty", () => {
49
+ let WithMetadata = class WithMetadata {
50
+ };
51
+ WithMetadata = __decorate([
52
+ (0, core_1.UseFilters)(new ExceptionFilter())
53
+ ], WithMetadata);
54
+ it("should return ExceptionHandler object with exception filters", () => {
55
+ const filter = exceptionFilter.create(new WithMetadata(), () => ({}), undefined);
56
+ (0, chai_1.expect)(filter.filters).to.not.be.empty;
57
+ });
58
+ });
59
+ });
60
+ describe("reflectCatchExceptions", () => {
61
+ it("should return FILTER_CATCH_EXCEPTIONS metadata", () => {
62
+ (0, chai_1.expect)(exceptionFilter.reflectCatchExceptions(new ExceptionFilter())).to.be.eql([CustomException]);
63
+ });
64
+ });
65
+ describe("createConcreteContext", () => {
66
+ class InvalidFilter {
67
+ }
68
+ const filters = [new ExceptionFilter(), new InvalidFilter(), "test"];
69
+ it("should return expected exception filters metadata", () => {
70
+ const resolved = exceptionFilter.createConcreteContext(filters);
71
+ (0, chai_1.expect)(resolved).to.have.length(1);
72
+ (0, chai_1.expect)(resolved[0].exceptionMetatypes).to.be.deep.equal([CustomException]);
73
+ (0, chai_1.expect)(resolved[0].func).to.be.a("function");
74
+ });
75
+ });
76
+ describe("getGlobalMetadata", () => {
77
+ describe("when contextId is static and inquirerId is nil", () => {
78
+ it("should return global filters", () => {
79
+ const expectedResult = applicationConfig.getGlobalFilters();
80
+ (0, chai_1.expect)(exceptionFilter.getGlobalMetadata()).to.be.equal(expectedResult);
81
+ });
82
+ });
83
+ describe("otherwise", () => {
84
+ it("should merge static global with request/transient scoped filters", () => {
85
+ const globalFilters = ["test"];
86
+ const instanceWrapper = new wrapper_1.InstanceWrapper();
87
+ const instance = "request-scoped";
88
+ const scopedFilterWrappers = [instanceWrapper];
89
+ sinon_1.default.stub(applicationConfig, "getGlobalFilters").callsFake(() => globalFilters);
90
+ sinon_1.default.stub(applicationConfig, "getGlobalRequestFilters").callsFake(() => scopedFilterWrappers);
91
+ sinon_1.default.stub(instanceWrapper, "getInstanceByContextId").callsFake(() => ({ instance }));
92
+ (0, chai_1.expect)(exceptionFilter.getGlobalMetadata({ id: 3 })).to.contains(instance, ...globalFilters);
93
+ });
94
+ });
95
+ });
96
+ });
@@ -0,0 +1 @@
1
+ export {};