@venok/http 1.0.1-canary.5 → 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.
Files changed (337) hide show
  1. package/dist/constants.js +33 -0
  2. package/dist/decorators/controller.decorator.js +45 -0
  3. package/dist/decorators/header.decorator.js +28 -0
  4. package/dist/decorators/http-code.decorator.js +22 -0
  5. package/dist/decorators/http-params.decorator.js +63 -0
  6. package/dist/decorators/method.decorator.js +57 -0
  7. package/dist/decorators/redirect.decorator.js +28 -0
  8. package/dist/decorators/version.decorator.js +31 -0
  9. package/dist/enums/method.enum.js +32 -0
  10. package/dist/enums/paramtypes.enum.js +33 -0
  11. package/dist/enums/status.enum.js +71 -0
  12. package/dist/enums/version-type.enum.js +27 -0
  13. package/dist/exceptions/bad-gateway.exception.js +29 -0
  14. package/dist/exceptions/bad-request.exception.js +29 -0
  15. package/dist/exceptions/conflict.exception.js +29 -0
  16. package/dist/exceptions/expectation-failed.exception.js +29 -0
  17. package/dist/exceptions/failed-dependency.exception.js +29 -0
  18. package/dist/exceptions/forbidden.exception.js +29 -0
  19. package/dist/exceptions/gateway-timeout.exception.js +29 -0
  20. package/dist/exceptions/gone.exception.js +29 -0
  21. package/dist/exceptions/http-version-not-supported.exception.js +29 -0
  22. package/dist/exceptions/http.exception.js +94 -0
  23. package/dist/exceptions/im-a-teapot.exception.js +29 -0
  24. package/dist/exceptions/internal-server-error.exception.js +29 -0
  25. package/dist/exceptions/length-required.exception.js +29 -0
  26. package/dist/exceptions/method-not-allowed.exception.js +29 -0
  27. package/dist/exceptions/misdirected.exception.js +29 -0
  28. package/dist/exceptions/not-acceptable.exception.js +29 -0
  29. package/dist/exceptions/not-found.exception.js +29 -0
  30. package/dist/exceptions/not-implemented.exception.js +29 -0
  31. package/dist/exceptions/payload-too-large.exception.js +29 -0
  32. package/dist/exceptions/payment-required.exception.js +29 -0
  33. package/dist/exceptions/precondition-failed.exception.js +29 -0
  34. package/dist/exceptions/precondition-required.exception.js +29 -0
  35. package/dist/exceptions/proxy-authentication-required.exception.js +29 -0
  36. package/dist/exceptions/request-timeout.exception.js +29 -0
  37. package/dist/exceptions/requested-range-not-satisfiable.exception.js +29 -0
  38. package/dist/exceptions/service-unavailable.exception.js +29 -0
  39. package/dist/exceptions/too-many-requests.exception.js +29 -0
  40. package/dist/exceptions/unauthorized.exception.js +29 -0
  41. package/dist/exceptions/unprocessable-entity.exception.js +29 -0
  42. package/dist/exceptions/unsupported-media-type.exception.js +29 -0
  43. package/dist/exceptions/uri-too-long.exception.js +29 -0
  44. package/dist/filters/context.js +28 -0
  45. package/dist/filters/filter.js +56 -0
  46. package/dist/helpers/discovery.helper.js +69 -0
  47. package/dist/helpers/messages.helper.js +41 -0
  48. package/dist/helpers/middleware.helper.js +69 -0
  49. package/dist/helpers/path.helper.js +53 -0
  50. package/dist/helpers/route.helper.js +54 -0
  51. package/dist/http/adapter.js +294 -0
  52. package/dist/http/config.js +67 -0
  53. package/dist/http/configurable-module.js +26 -0
  54. package/dist/http/context.js +117 -0
  55. package/dist/http/explorer.js +133 -0
  56. package/dist/http/module.js +35 -0
  57. package/dist/http/starter-module.js +85 -0
  58. package/dist/index.d.ts +2117 -0
  59. package/dist/index.js +82 -0
  60. package/dist/interfaces/adapter.interface.js +0 -0
  61. package/dist/interfaces/exception.interface.js +0 -0
  62. package/dist/interfaces/index.js +7 -0
  63. package/dist/interfaces/middleware/config-proxy.interface.js +0 -0
  64. package/dist/interfaces/middleware/consumer.interface.js +0 -0
  65. package/dist/interfaces/middleware/index.js +3 -0
  66. package/dist/interfaces/options.interface.js +0 -0
  67. package/dist/interfaces/prefix.interface.js +0 -0
  68. package/dist/interfaces/router/definition.interface.js +0 -0
  69. package/dist/interfaces/router/exclude-route.interface.js +0 -0
  70. package/dist/interfaces/router/index.js +7 -0
  71. package/dist/interfaces/router/info.interface.js +0 -0
  72. package/dist/interfaces/router/path-metadata.interface.js +0 -0
  73. package/dist/interfaces/router/tree.interface.js +0 -0
  74. package/dist/interfaces/router/version.interface.js +21 -0
  75. package/dist/middleware/builder.js +96 -0
  76. package/dist/middleware/module.js +22 -0
  77. package/dist/middleware/routes-mapper.js +107 -0
  78. package/dist/middleware/service.js +48 -0
  79. package/dist/middleware/tree.js +91 -0
  80. package/dist/router/finder.js +64 -0
  81. package/dist/router/module.js +89 -0
  82. package/dist/router/path-factory.js +110 -0
  83. package/dist/symbols.js +33 -0
  84. package/package.json +41 -46
  85. package/adapter/adapter.d.ts +0 -57
  86. package/adapter/adapter.js +0 -58
  87. package/adapter/host.d.ts +0 -27
  88. package/adapter/host.js +0 -33
  89. package/application/application.d.ts +0 -18
  90. package/application/application.js +0 -51
  91. package/application/config.d.ts +0 -16
  92. package/application/config.js +0 -47
  93. package/application/http.module-defenition.d.ts +0 -8
  94. package/application/http.module-defenition.js +0 -6
  95. package/application/http.module.d.ts +0 -3
  96. package/application/http.module.js +0 -21
  97. package/application/http.service.d.ts +0 -11
  98. package/application/http.service.js +0 -43
  99. package/application/starter.d.ts +0 -41
  100. package/application/starter.js +0 -140
  101. package/constants.d.ts +0 -12
  102. package/constants.js +0 -15
  103. package/context/context.d.ts +0 -56
  104. package/context/context.js +0 -102
  105. package/context/response.controller.d.ts +0 -30
  106. package/context/response.controller.js +0 -86
  107. package/decorators/controller.decorator.d.ts +0 -82
  108. package/decorators/controller.decorator.js +0 -53
  109. package/decorators/header.decorator.d.ts +0 -12
  110. package/decorators/header.decorator.js +0 -23
  111. package/decorators/http-code.decorator.d.ts +0 -9
  112. package/decorators/http-code.decorator.js +0 -19
  113. package/decorators/index.d.ts +0 -9
  114. package/decorators/index.js +0 -25
  115. package/decorators/redirect.decorator.d.ts +0 -6
  116. package/decorators/redirect.decorator.js +0 -16
  117. package/decorators/render.decorator.d.ts +0 -10
  118. package/decorators/render.decorator.js +0 -20
  119. package/decorators/request-mapping.decorator.d.ts +0 -78
  120. package/decorators/request-mapping.decorator.js +0 -98
  121. package/decorators/route-params.decorator.d.ts +0 -378
  122. package/decorators/route-params.decorator.js +0 -227
  123. package/decorators/sse.decorator.d.ts +0 -6
  124. package/decorators/sse.decorator.js +0 -20
  125. package/decorators/version.decorator.d.ts +0 -7
  126. package/decorators/version.decorator.js +0 -20
  127. package/enums/http-status.enum.d.ts +0 -53
  128. package/enums/http-status.enum.js +0 -57
  129. package/enums/index.d.ts +0 -4
  130. package/enums/index.js +0 -20
  131. package/enums/request-method.enum.d.ts +0 -11
  132. package/enums/request-method.enum.js +0 -15
  133. package/enums/route-paramtypes.enum.d.ts +0 -14
  134. package/enums/route-paramtypes.enum.js +0 -18
  135. package/enums/version-type.enum.d.ts +0 -9
  136. package/enums/version-type.enum.js +0 -13
  137. package/errors/bad-gateway.exception.d.ts +0 -33
  138. package/errors/bad-gateway.exception.js +0 -41
  139. package/errors/bad-request.exception.d.ts +0 -33
  140. package/errors/bad-request.exception.js +0 -41
  141. package/errors/conflict.exception.d.ts +0 -33
  142. package/errors/conflict.exception.js +0 -41
  143. package/errors/forbidden.exception.d.ts +0 -33
  144. package/errors/forbidden.exception.js +0 -41
  145. package/errors/gateway-timeout.exception.d.ts +0 -33
  146. package/errors/gateway-timeout.exception.js +0 -41
  147. package/errors/gone.exception.d.ts +0 -33
  148. package/errors/gone.exception.js +0 -41
  149. package/errors/http-version-not-supported.exception.d.ts +0 -33
  150. package/errors/http-version-not-supported.exception.js +0 -41
  151. package/errors/http.exception.d.ts +0 -79
  152. package/errors/http.exception.js +0 -123
  153. package/errors/im-a-teapot.exception.d.ts +0 -36
  154. package/errors/im-a-teapot.exception.js +0 -44
  155. package/errors/index.d.ts +0 -11
  156. package/errors/index.js +0 -27
  157. package/errors/internal-server-error.exception.d.ts +0 -33
  158. package/errors/internal-server-error.exception.js +0 -41
  159. package/errors/invalid-middleware-configuration.exception.d.ts +0 -4
  160. package/errors/invalid-middleware-configuration.exception.js +0 -11
  161. package/errors/invalid-middleware.exception.d.ts +0 -4
  162. package/errors/invalid-middleware.exception.js +0 -11
  163. package/errors/not-found.exception.d.ts +0 -33
  164. package/errors/not-found.exception.js +0 -41
  165. package/errors/unknown-request-mapping.exception.d.ts +0 -5
  166. package/errors/unknown-request-mapping.exception.js +0 -11
  167. package/exceptions/messages.d.ts +0 -4
  168. package/exceptions/messages.js +0 -13
  169. package/explorers/path.explorer.d.ts +0 -8
  170. package/explorers/path.explorer.js +0 -38
  171. package/explorers/router.explorer.d.ts +0 -51
  172. package/explorers/router.explorer.js +0 -195
  173. package/factory/context-id.factory.d.ts +0 -41
  174. package/factory/context-id.factory.js +0 -52
  175. package/factory/index.d.ts +0 -4
  176. package/factory/index.js +0 -20
  177. package/factory/method.factory.d.ts +0 -5
  178. package/factory/method.factory.js +0 -30
  179. package/factory/params.factory.d.ts +0 -5
  180. package/factory/params.factory.js +0 -39
  181. package/factory/path.factory.d.ts +0 -13
  182. package/factory/path.factory.js +0 -95
  183. package/filters/context.d.ts +0 -9
  184. package/filters/context.js +0 -15
  185. package/filters/filter.d.ts +0 -22
  186. package/filters/filter.js +0 -78
  187. package/helpers/adapter.helper.d.ts +0 -27
  188. package/helpers/adapter.helper.js +0 -37
  189. package/helpers/exclude-route.helper.d.ts +0 -4
  190. package/helpers/exclude-route.helper.js +0 -18
  191. package/helpers/flatten-routes.helper.d.ts +0 -5
  192. package/helpers/flatten-routes.helper.js +0 -27
  193. package/helpers/index.d.ts +0 -6
  194. package/helpers/index.js +0 -22
  195. package/helpers/messages.helper.d.ts +0 -6
  196. package/helpers/messages.helper.js +0 -25
  197. package/helpers/path.helper.d.ts +0 -3
  198. package/helpers/path.helper.js +0 -13
  199. package/helpers/sse.helper.d.ts +0 -45
  200. package/helpers/sse.helper.js +0 -83
  201. package/index.d.ts +0 -1
  202. package/index.js +0 -3
  203. package/interfaces/http/cors.interface.d.ts +0 -58
  204. package/interfaces/http/cors.interface.js +0 -2
  205. package/interfaces/http/exception.interface.d.ts +0 -6
  206. package/interfaces/http/exception.interface.js +0 -2
  207. package/interfaces/http/exclude-route.interface.d.ts +0 -15
  208. package/interfaces/http/exclude-route.interface.js +0 -2
  209. package/interfaces/http/index.d.ts +0 -10
  210. package/interfaces/http/index.js +0 -26
  211. package/interfaces/http/message-event.interface.d.ts +0 -6
  212. package/interfaces/http/message-event.interface.js +0 -2
  213. package/interfaces/http/module.inteface.d.ts +0 -5
  214. package/interfaces/http/module.inteface.js +0 -2
  215. package/interfaces/http/options.interface.d.ts +0 -127
  216. package/interfaces/http/options.interface.js +0 -2
  217. package/interfaces/http/path-metadata.interface.d.ts +0 -31
  218. package/interfaces/http/path-metadata.interface.js +0 -2
  219. package/interfaces/http/prefix-options.interface.d.ts +0 -7
  220. package/interfaces/http/prefix-options.interface.js +0 -2
  221. package/interfaces/http/raw-request.d.ts +0 -4
  222. package/interfaces/http/raw-request.js +0 -2
  223. package/interfaces/http/routes.interface.d.ts +0 -7
  224. package/interfaces/http/routes.interface.js +0 -2
  225. package/interfaces/http/server.interface.d.ts +0 -54
  226. package/interfaces/http/server.interface.js +0 -2
  227. package/interfaces/index.d.ts +0 -3
  228. package/interfaces/index.js +0 -19
  229. package/interfaces/middleware/config-proxy.interface.d.ts +0 -23
  230. package/interfaces/middleware/config-proxy.interface.js +0 -2
  231. package/interfaces/middleware/configuration.interface.d.ts +0 -12
  232. package/interfaces/middleware/configuration.interface.js +0 -2
  233. package/interfaces/middleware/consumer.interface.d.ts +0 -16
  234. package/interfaces/middleware/consumer.interface.js +0 -2
  235. package/interfaces/middleware/index.d.ts +0 -4
  236. package/interfaces/middleware/index.js +0 -20
  237. package/interfaces/middleware/middleware.interface.d.ts +0 -7
  238. package/interfaces/middleware/middleware.interface.js +0 -2
  239. package/interfaces/router/callback-paramtypes.interface.d.ts +0 -1
  240. package/interfaces/router/callback-paramtypes.interface.js +0 -2
  241. package/interfaces/router/definition.interface.d.ts +0 -10
  242. package/interfaces/router/definition.interface.js +0 -2
  243. package/interfaces/router/index.d.ts +0 -3
  244. package/interfaces/router/index.js +0 -19
  245. package/interfaces/router/version-options.interface.d.ts +0 -92
  246. package/interfaces/router/version-options.interface.js +0 -9
  247. package/middleware/builder.d.ts +0 -15
  248. package/middleware/builder.js +0 -78
  249. package/middleware/container.d.ts +0 -13
  250. package/middleware/container.js +0 -50
  251. package/middleware/extractor.d.ts +0 -15
  252. package/middleware/extractor.js +0 -50
  253. package/middleware/index.d.ts +0 -1
  254. package/middleware/index.js +0 -17
  255. package/middleware/module.d.ts +0 -33
  256. package/middleware/module.js +0 -180
  257. package/middleware/resolver.d.ts +0 -10
  258. package/middleware/resolver.js +0 -27
  259. package/middleware/routes-mapper.d.ts +0 -19
  260. package/middleware/routes-mapper.js +0 -111
  261. package/middleware/utils.d.ts +0 -8
  262. package/middleware/utils.js +0 -86
  263. package/router/module.d.ts +0 -18
  264. package/router/module.js +0 -88
  265. package/router/resolver.d.ts +0 -31
  266. package/router/resolver.js +0 -128
  267. package/storage/http-instance.storage.d.ts +0 -9
  268. package/storage/http-instance.storage.js +0 -19
  269. package/stream/index.d.ts +0 -1
  270. package/stream/index.js +0 -17
  271. package/stream/interfaces/index.d.ts +0 -2
  272. package/stream/interfaces/index.js +0 -18
  273. package/stream/interfaces/streamable-handler-response.interface.d.ts +0 -12
  274. package/stream/interfaces/streamable-handler-response.interface.js +0 -2
  275. package/stream/interfaces/streamable-options.interface.d.ts +0 -10
  276. package/stream/interfaces/streamable-options.interface.js +0 -2
  277. package/stream/streamable-file.d.ts +0 -22
  278. package/stream/streamable-file.js +0 -55
  279. package/test/context/response.controller.spec.d.ts +0 -1
  280. package/test/context/response.controller.spec.js +0 -328
  281. package/test/decorators/controller.decorator.spec.d.ts +0 -1
  282. package/test/decorators/controller.decorator.spec.js +0 -113
  283. package/test/decorators/header.decorator.spec.d.ts +0 -1
  284. package/test/decorators/header.decorator.spec.js +0 -33
  285. package/test/decorators/http-code.decorator.spec.d.ts +0 -1
  286. package/test/decorators/http-code.decorator.spec.js +0 -30
  287. package/test/decorators/redirect.decorator.spec.d.ts +0 -1
  288. package/test/decorators/redirect.decorator.spec.js +0 -36
  289. package/test/decorators/render.decorator.spec.d.ts +0 -1
  290. package/test/decorators/render.decorator.spec.js +0 -30
  291. package/test/decorators/request-mapping.decorator.spec.d.ts +0 -1
  292. package/test/decorators/request-mapping.decorator.spec.js +0 -85
  293. package/test/decorators/route-params.decorator.spec.d.ts +0 -1
  294. package/test/decorators/route-params.decorator.spec.js +0 -493
  295. package/test/decorators/sse.decorator.spec.d.ts +0 -1
  296. package/test/decorators/sse.decorator.spec.js +0 -35
  297. package/test/decorators/version.decorator.spec.d.ts +0 -1
  298. package/test/decorators/version.decorator.spec.js +0 -43
  299. package/test/exceptions/handler.spec.d.ts +0 -1
  300. package/test/exceptions/handler.spec.js +0 -145
  301. package/test/exceptions/proxy.spec.d.ts +0 -1
  302. package/test/exceptions/proxy.spec.js +0 -74
  303. package/test/explorers/path.explorer.spec.d.ts +0 -1
  304. package/test/explorers/path.explorer.spec.js +0 -190
  305. package/test/explorers/router.explorer.spec.d.ts +0 -1
  306. package/test/explorers/router.explorer.spec.js +0 -206
  307. package/test/factory/method.factory.spec.d.ts +0 -1
  308. package/test/factory/method.factory.spec.js +0 -33
  309. package/test/factory/params.factory.spec.d.ts +0 -1
  310. package/test/factory/params.factory.spec.js +0 -104
  311. package/test/factory/path.factory.spec.d.ts +0 -1
  312. package/test/factory/path.factory.spec.js +0 -260
  313. package/test/filters/context.spec.d.ts +0 -1
  314. package/test/filters/context.spec.js +0 -96
  315. package/test/filters/filter.spec.d.ts +0 -1
  316. package/test/filters/filter.spec.js +0 -96
  317. package/test/helpers/flatten-routes.helper.spec.d.ts +0 -1
  318. package/test/helpers/flatten-routes.helper.spec.js +0 -131
  319. package/test/helpers/sse.helper.spec.d.ts +0 -1
  320. package/test/helpers/sse.helper.spec.js +0 -132
  321. package/test/middleware/builder.spec.d.ts +0 -1
  322. package/test/middleware/builder.spec.js +0 -235
  323. package/test/middleware/container.spec.d.ts +0 -1
  324. package/test/middleware/container.spec.js +0 -81
  325. package/test/middleware/module.spec.d.ts +0 -1
  326. package/test/middleware/module.spec.js +0 -206
  327. package/test/middleware/route-info-path-extractor.spec.d.ts +0 -1
  328. package/test/middleware/route-info-path-extractor.spec.js +0 -123
  329. package/test/middleware/routes-mapper.spec.d.ts +0 -1
  330. package/test/middleware/routes-mapper.spec.js +0 -162
  331. package/test/middleware/utils.spec.d.ts +0 -1
  332. package/test/middleware/utils.spec.js +0 -132
  333. package/test/router/module.spec.d.ts +0 -1
  334. package/test/router/module.spec.js +0 -40
  335. package/test/router/resolver.spec.d.ts +0 -1
  336. package/test/router/resolver.spec.js +0 -326
  337. package/tsconfig.tsbuildinfo +0 -1
@@ -1 +0,0 @@
1
- export {};
@@ -1,104 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,260 +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 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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,96 +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 __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");
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,96 +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 __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");
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
- });
@@ -1 +0,0 @@
1
- export {};