@tsed/platform-http 8.11.1 → 8.12.0-rc.1

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 (228) hide show
  1. package/lib/esm/common/builder/PlatformBuilder.js +0 -1
  2. package/lib/esm/common/builder/__fixtures__/PlatformCustom.js +0 -1
  3. package/lib/esm/common/config/interfaces/PlatformJsonMapperSettings.js +0 -1
  4. package/lib/esm/common/config/interfaces/PlatformMulterSettings.js +0 -1
  5. package/lib/esm/common/config/interfaces/PlatformRouterSettings.js +0 -1
  6. package/lib/esm/common/config/interfaces/PlatformStaticsSettings.js +0 -1
  7. package/lib/esm/common/config/services/PlatformConfiguration.js +0 -1
  8. package/lib/esm/common/constants/routerOptions.js +0 -1
  9. package/lib/esm/common/decorators/PlatformProvider.js +0 -1
  10. package/lib/esm/common/decorators/multer/multerFileSize.js +0 -1
  11. package/lib/esm/common/decorators/multer/multerOptions.js +0 -1
  12. package/lib/esm/common/decorators/multer/multipartFile.js +0 -1
  13. package/lib/esm/common/decorators/params/error.js +0 -1
  14. package/lib/esm/common/decorators/params/next.js +0 -1
  15. package/lib/esm/common/decorators/params/request.js +0 -1
  16. package/lib/esm/common/decorators/params/response.js +0 -1
  17. package/lib/esm/common/domain/AnyToPromiseWithCtx.js +0 -1
  18. package/lib/esm/common/domain/EndpointMetadata.js +0 -1
  19. package/lib/esm/common/domain/PlatformContext.js +0 -1
  20. package/lib/esm/common/domain/PlatformRouteDetails.js +0 -1
  21. package/lib/esm/common/exports.js +0 -1
  22. package/lib/esm/common/fn/adapter.js +0 -1
  23. package/lib/esm/common/fn/application.js +0 -1
  24. package/lib/esm/common/index.js +0 -1
  25. package/lib/esm/common/interfaces/AfterInit.js +0 -1
  26. package/lib/esm/common/interfaces/AfterListen.js +0 -1
  27. package/lib/esm/common/interfaces/AfterRoutesInit.js +0 -1
  28. package/lib/esm/common/interfaces/BeforeInit.js +0 -1
  29. package/lib/esm/common/interfaces/BeforeListen.js +0 -1
  30. package/lib/esm/common/interfaces/BeforeRoutesInit.js +0 -1
  31. package/lib/esm/common/interfaces/HandlerType.js +0 -1
  32. package/lib/esm/common/interfaces/IncomingEvent.js +0 -1
  33. package/lib/esm/common/interfaces/OnReady.js +0 -1
  34. package/lib/esm/common/interfaces/OnRequest.js +0 -1
  35. package/lib/esm/common/interfaces/OnResponse.js +0 -1
  36. package/lib/esm/common/interfaces/OnRoutesInit.js +0 -1
  37. package/lib/esm/common/interfaces/PlatformRouteOptions.js +0 -1
  38. package/lib/esm/common/interfaces/ResponseErrorObject.js +0 -1
  39. package/lib/esm/common/interfaces/Route.js +0 -1
  40. package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js +0 -1
  41. package/lib/esm/common/middlewares/PlatformMulterMiddleware.js +0 -1
  42. package/lib/esm/common/services/Platform.js +0 -1
  43. package/lib/esm/common/services/PlatformAdapter.js +0 -1
  44. package/lib/esm/common/services/PlatformApplication.js +0 -1
  45. package/lib/esm/common/services/PlatformHandler.js +0 -1
  46. package/lib/esm/common/services/PlatformRequest.js +0 -1
  47. package/lib/esm/common/services/PlatformResponse.js +0 -1
  48. package/lib/esm/common/utils/closeServer.js +0 -1
  49. package/lib/esm/common/utils/createContext.js +0 -1
  50. package/lib/esm/common/utils/createHttpServer.js +0 -1
  51. package/lib/esm/common/utils/createHttpsServer.js +0 -1
  52. package/lib/esm/common/utils/createInjector.js +0 -1
  53. package/lib/esm/common/utils/createServer.js +0 -1
  54. package/lib/esm/common/utils/ensureContext.js +0 -1
  55. package/lib/esm/common/utils/getConfiguration.js +0 -1
  56. package/lib/esm/common/utils/getStaticsOptions.js +0 -1
  57. package/lib/esm/common/utils/listenServer.js +0 -1
  58. package/lib/esm/common/utils/mapReturnedResponse.js +0 -1
  59. package/lib/esm/common/utils/printRoutes.js +0 -1
  60. package/lib/esm/common/utils/resolveControllers.js +0 -1
  61. package/lib/esm/common/utils/setResponseHeaders.js +0 -1
  62. package/lib/esm/index.js +0 -1
  63. package/lib/esm/testing/FakeAdapter.js +0 -1
  64. package/lib/esm/testing/FakeResponse.js +0 -1
  65. package/lib/esm/testing/PlatformTest.js +0 -1
  66. package/lib/esm/testing/index.js +0 -1
  67. package/package.json +20 -17
  68. package/.barrelsby.json +0 -5
  69. package/lib/esm/common/builder/PlatformBuilder.js.map +0 -1
  70. package/lib/esm/common/builder/__fixtures__/PlatformCustom.js.map +0 -1
  71. package/lib/esm/common/config/interfaces/PlatformJsonMapperSettings.js.map +0 -1
  72. package/lib/esm/common/config/interfaces/PlatformMulterSettings.js.map +0 -1
  73. package/lib/esm/common/config/interfaces/PlatformRouterSettings.js.map +0 -1
  74. package/lib/esm/common/config/interfaces/PlatformStaticsSettings.js.map +0 -1
  75. package/lib/esm/common/config/services/PlatformConfiguration.js.map +0 -1
  76. package/lib/esm/common/constants/routerOptions.js.map +0 -1
  77. package/lib/esm/common/decorators/PlatformProvider.js.map +0 -1
  78. package/lib/esm/common/decorators/multer/multerFileSize.js.map +0 -1
  79. package/lib/esm/common/decorators/multer/multerOptions.js.map +0 -1
  80. package/lib/esm/common/decorators/multer/multipartFile.js.map +0 -1
  81. package/lib/esm/common/decorators/params/error.js.map +0 -1
  82. package/lib/esm/common/decorators/params/next.js.map +0 -1
  83. package/lib/esm/common/decorators/params/request.js.map +0 -1
  84. package/lib/esm/common/decorators/params/response.js.map +0 -1
  85. package/lib/esm/common/domain/AnyToPromiseWithCtx.js.map +0 -1
  86. package/lib/esm/common/domain/EndpointMetadata.js.map +0 -1
  87. package/lib/esm/common/domain/PlatformContext.js.map +0 -1
  88. package/lib/esm/common/domain/PlatformRouteDetails.js.map +0 -1
  89. package/lib/esm/common/exports.js.map +0 -1
  90. package/lib/esm/common/fn/adapter.js.map +0 -1
  91. package/lib/esm/common/fn/application.js.map +0 -1
  92. package/lib/esm/common/index.js.map +0 -1
  93. package/lib/esm/common/interfaces/AfterInit.js.map +0 -1
  94. package/lib/esm/common/interfaces/AfterListen.js.map +0 -1
  95. package/lib/esm/common/interfaces/AfterRoutesInit.js.map +0 -1
  96. package/lib/esm/common/interfaces/BeforeInit.js.map +0 -1
  97. package/lib/esm/common/interfaces/BeforeListen.js.map +0 -1
  98. package/lib/esm/common/interfaces/BeforeRoutesInit.js.map +0 -1
  99. package/lib/esm/common/interfaces/HandlerType.js.map +0 -1
  100. package/lib/esm/common/interfaces/IncomingEvent.js.map +0 -1
  101. package/lib/esm/common/interfaces/OnReady.js.map +0 -1
  102. package/lib/esm/common/interfaces/OnRequest.js.map +0 -1
  103. package/lib/esm/common/interfaces/OnResponse.js.map +0 -1
  104. package/lib/esm/common/interfaces/OnRoutesInit.js.map +0 -1
  105. package/lib/esm/common/interfaces/PlatformRouteOptions.js.map +0 -1
  106. package/lib/esm/common/interfaces/ResponseErrorObject.js.map +0 -1
  107. package/lib/esm/common/interfaces/Route.js.map +0 -1
  108. package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js.map +0 -1
  109. package/lib/esm/common/middlewares/PlatformMulterMiddleware.js.map +0 -1
  110. package/lib/esm/common/services/Platform.js.map +0 -1
  111. package/lib/esm/common/services/PlatformAdapter.js.map +0 -1
  112. package/lib/esm/common/services/PlatformApplication.js.map +0 -1
  113. package/lib/esm/common/services/PlatformHandler.js.map +0 -1
  114. package/lib/esm/common/services/PlatformRequest.js.map +0 -1
  115. package/lib/esm/common/services/PlatformResponse.js.map +0 -1
  116. package/lib/esm/common/utils/closeServer.js.map +0 -1
  117. package/lib/esm/common/utils/createContext.js.map +0 -1
  118. package/lib/esm/common/utils/createHttpServer.js.map +0 -1
  119. package/lib/esm/common/utils/createHttpsServer.js.map +0 -1
  120. package/lib/esm/common/utils/createInjector.js.map +0 -1
  121. package/lib/esm/common/utils/createServer.js.map +0 -1
  122. package/lib/esm/common/utils/ensureContext.js.map +0 -1
  123. package/lib/esm/common/utils/getConfiguration.js.map +0 -1
  124. package/lib/esm/common/utils/getStaticsOptions.js.map +0 -1
  125. package/lib/esm/common/utils/listenServer.js.map +0 -1
  126. package/lib/esm/common/utils/mapReturnedResponse.js.map +0 -1
  127. package/lib/esm/common/utils/printRoutes.js.map +0 -1
  128. package/lib/esm/common/utils/resolveControllers.js.map +0 -1
  129. package/lib/esm/common/utils/setResponseHeaders.js.map +0 -1
  130. package/lib/esm/index.js.map +0 -1
  131. package/lib/esm/testing/FakeAdapter.js.map +0 -1
  132. package/lib/esm/testing/FakeResponse.js.map +0 -1
  133. package/lib/esm/testing/PlatformTest.js.map +0 -1
  134. package/lib/esm/testing/index.js.map +0 -1
  135. package/src/common/builder/PlatformBuilder.spec.ts +0 -331
  136. package/src/common/builder/PlatformBuilder.ts +0 -426
  137. package/src/common/builder/__fixtures__/PlatformCustom.ts +0 -39
  138. package/src/common/config/interfaces/PlatformJsonMapperSettings.ts +0 -11
  139. package/src/common/config/interfaces/PlatformMulterSettings.ts +0 -22
  140. package/src/common/config/interfaces/PlatformRouterSettings.ts +0 -11
  141. package/src/common/config/interfaces/PlatformStaticsSettings.ts +0 -23
  142. package/src/common/config/services/PlatformConfiguration.spec.ts +0 -181
  143. package/src/common/config/services/PlatformConfiguration.ts +0 -158
  144. package/src/common/constants/routerOptions.ts +0 -1
  145. package/src/common/decorators/PlatformProvider.ts +0 -14
  146. package/src/common/decorators/multer/multerFileSize.ts +0 -31
  147. package/src/common/decorators/multer/multerOptions.ts +0 -45
  148. package/src/common/decorators/multer/multipartFile.ts +0 -51
  149. package/src/common/decorators/params/error.spec.ts +0 -15
  150. package/src/common/decorators/params/error.ts +0 -16
  151. package/src/common/decorators/params/next.spec.ts +0 -15
  152. package/src/common/decorators/params/next.ts +0 -31
  153. package/src/common/decorators/params/request.spec.ts +0 -50
  154. package/src/common/decorators/params/request.ts +0 -86
  155. package/src/common/decorators/params/response.spec.ts +0 -37
  156. package/src/common/decorators/params/response.ts +0 -74
  157. package/src/common/domain/AnyToPromiseWithCtx.spec.ts +0 -20
  158. package/src/common/domain/AnyToPromiseWithCtx.ts +0 -30
  159. package/src/common/domain/EndpointMetadata.ts +0 -1
  160. package/src/common/domain/PlatformContext.spec.ts +0 -124
  161. package/src/common/domain/PlatformContext.ts +0 -136
  162. package/src/common/domain/PlatformRouteDetails.ts +0 -7
  163. package/src/common/exports.ts +0 -4
  164. package/src/common/fn/adapter.ts +0 -42
  165. package/src/common/fn/application.ts +0 -11
  166. package/src/common/index.ts +0 -61
  167. package/src/common/interfaces/AfterInit.ts +0 -3
  168. package/src/common/interfaces/AfterListen.ts +0 -3
  169. package/src/common/interfaces/AfterRoutesInit.ts +0 -3
  170. package/src/common/interfaces/BeforeInit.ts +0 -3
  171. package/src/common/interfaces/BeforeListen.ts +0 -3
  172. package/src/common/interfaces/BeforeRoutesInit.ts +0 -3
  173. package/src/common/interfaces/HandlerType.ts +0 -12
  174. package/src/common/interfaces/IncomingEvent.ts +0 -6
  175. package/src/common/interfaces/OnReady.ts +0 -3
  176. package/src/common/interfaces/OnRequest.ts +0 -5
  177. package/src/common/interfaces/OnResponse.ts +0 -5
  178. package/src/common/interfaces/OnRoutesInit.ts +0 -3
  179. package/src/common/interfaces/PlatformRouteOptions.ts +0 -17
  180. package/src/common/interfaces/ResponseErrorObject.ts +0 -8
  181. package/src/common/interfaces/Route.ts +0 -12
  182. package/src/common/middlewares/PlatformAcceptMimesMiddleware.spec.ts +0 -215
  183. package/src/common/middlewares/PlatformAcceptMimesMiddleware.ts +0 -34
  184. package/src/common/middlewares/PlatformMulterMiddleware.ts +0 -6
  185. package/src/common/services/Platform.spec.ts +0 -145
  186. package/src/common/services/Platform.ts +0 -79
  187. package/src/common/services/PlatformAdapter.ts +0 -102
  188. package/src/common/services/PlatformApplication.spec.ts +0 -89
  189. package/src/common/services/PlatformApplication.ts +0 -38
  190. package/src/common/services/PlatformHandler.spec.ts +0 -152
  191. package/src/common/services/PlatformHandler.ts +0 -137
  192. package/src/common/services/PlatformRequest.spec.ts +0 -185
  193. package/src/common/services/PlatformRequest.ts +0 -182
  194. package/src/common/services/PlatformResponse.spec.ts +0 -364
  195. package/src/common/services/PlatformResponse.ts +0 -393
  196. package/src/common/utils/closeServer.spec.ts +0 -11
  197. package/src/common/utils/closeServer.ts +0 -8
  198. package/src/common/utils/createContext.spec.ts +0 -111
  199. package/src/common/utils/createContext.ts +0 -52
  200. package/src/common/utils/createHttpServer.spec.ts +0 -75
  201. package/src/common/utils/createHttpServer.ts +0 -16
  202. package/src/common/utils/createHttpsServer.spec.ts +0 -74
  203. package/src/common/utils/createHttpsServer.ts +0 -17
  204. package/src/common/utils/createInjector.spec.ts +0 -42
  205. package/src/common/utils/createInjector.ts +0 -25
  206. package/src/common/utils/createServer.ts +0 -52
  207. package/src/common/utils/ensureContext.spec.ts +0 -41
  208. package/src/common/utils/ensureContext.ts +0 -17
  209. package/src/common/utils/getConfiguration.spec.ts +0 -163
  210. package/src/common/utils/getConfiguration.ts +0 -34
  211. package/src/common/utils/getStaticsOptions.spec.ts +0 -27
  212. package/src/common/utils/getStaticsOptions.ts +0 -24
  213. package/src/common/utils/listenServer.ts +0 -18
  214. package/src/common/utils/mapReturnedResponse.spec.ts +0 -35
  215. package/src/common/utils/mapReturnedResponse.ts +0 -10
  216. package/src/common/utils/printRoutes.spec.ts +0 -19
  217. package/src/common/utils/printRoutes.ts +0 -40
  218. package/src/common/utils/resolveControllers.spec.ts +0 -40
  219. package/src/common/utils/resolveControllers.ts +0 -54
  220. package/src/common/utils/setResponseHeaders.spec.ts +0 -84
  221. package/src/common/utils/setResponseHeaders.ts +0 -31
  222. package/src/index.ts +0 -2
  223. package/src/testing/FakeAdapter.ts +0 -69
  224. package/src/testing/FakeResponse.ts +0 -115
  225. package/src/testing/PlatformTest.spec.ts +0 -53
  226. package/src/testing/PlatformTest.ts +0 -161
  227. package/src/testing/index.ts +0 -5
  228. package/vitest.config.mts +0 -25
@@ -1,74 +0,0 @@
1
- import Https from "node:https";
2
-
3
- import {configuration, destroyInjector, injector, InjectorService} from "@tsed/di";
4
-
5
- import {createHttpsServer} from "./createHttpsServer.js";
6
-
7
- describe("createHttpsServer", () => {
8
- afterEach(() => {
9
- vi.resetAllMocks();
10
- });
11
- afterEach(() => destroyInjector());
12
- it("should create an instance of Https (Https port true)", async () => {
13
- configuration().set("httpsPort", true);
14
-
15
- const fn: any = vi.fn();
16
-
17
- const listener = createHttpsServer(fn)!;
18
-
19
- expect(!!injector().get(Https.Server)).toEqual(true);
20
- expect(listener).toBeInstanceOf(Function);
21
-
22
- const server = injector().get(Https.Server)!;
23
-
24
- vi.spyOn(injector().logger, "info").mockReturnValue(undefined);
25
- vi.spyOn(injector().logger, "debug").mockReturnValue(undefined);
26
- vi.spyOn(server, "listen").mockReturnValue(undefined as never);
27
- vi.spyOn(server, "address").mockReturnValue({port: 8089, address: "0.0.0.0"} as never);
28
- vi.spyOn(server, "on").mockImplementation(((event: string, cb: any) => {
29
- if (event === "listening") {
30
- cb();
31
- }
32
- }) as never);
33
-
34
- await listener();
35
-
36
- expect(server.listen).toHaveBeenCalledWith(true, "0.0.0.0");
37
- expect(injector().logger.info).toHaveBeenCalledWith("Listen server on https://0.0.0.0:8089");
38
- });
39
-
40
- it("should create a raw object (Https port false)", () => {
41
- configuration().set("httpsPort", false);
42
-
43
- const fn: any = vi.fn();
44
-
45
- const listener = createHttpsServer(fn);
46
-
47
- expect(injector().get(Https.Server)).toEqual(null);
48
-
49
- expect(listener).toBeUndefined();
50
- });
51
-
52
- it("should create an instance of Https (https port 0)", () => {
53
- configuration().set("httpsPort", 0);
54
-
55
- const fn: any = vi.fn();
56
-
57
- const listener = createHttpsServer(fn);
58
-
59
- expect(!!injector().get(Https.Server)).toEqual(true);
60
-
61
- expect(listener).toBeInstanceOf(Function);
62
- });
63
- it("should create an instance of Https (https port + address)", () => {
64
- configuration().set("httpsPort", "0.0.0.0:8080");
65
-
66
- const fn: any = vi.fn();
67
-
68
- const listener = createHttpsServer(fn);
69
-
70
- expect(!!injector().get(Https.Server)).toEqual(true);
71
-
72
- expect(listener).toBeInstanceOf(Function);
73
- });
74
- });
@@ -1,17 +0,0 @@
1
- import Http from "node:http";
2
- import Https from "node:https";
3
-
4
- import {configuration, constant, InjectorService} from "@tsed/di";
5
-
6
- import {createServer} from "./createServer.js";
7
-
8
- export function createHttpsServer(requestListener?: Http.RequestListener) {
9
- const httpsOptions = configuration().get("httpsOptions");
10
-
11
- return createServer({
12
- type: "https",
13
- token: Https.Server,
14
- port: constant("httpsPort"),
15
- server: () => Https.createServer(httpsOptions, requestListener)
16
- });
17
- }
@@ -1,42 +0,0 @@
1
- import {Env} from "@tsed/core";
2
- import {$log} from "@tsed/logger";
3
-
4
- import {FakeAdapter} from "../../testing/FakeAdapter.js";
5
- import {PlatformConfiguration} from "../config/services/PlatformConfiguration.js";
6
- import {PlatformAdapter} from "../services/PlatformAdapter.js";
7
- import {createInjector} from "./createInjector.js";
8
-
9
- describe("createInjector", () => {
10
- beforeEach(() => {
11
- vi.spyOn($log, "stop").mockReturnValue(undefined as any);
12
- });
13
- afterEach(() => {
14
- vi.resetAllMocks();
15
- });
16
- it("should create injector and stop logger in env Test", () => {
17
- const settings = {
18
- test: "test",
19
- env: Env.TEST,
20
- adapter: FakeAdapter
21
- };
22
-
23
- const injector = createInjector(settings);
24
-
25
- expect(injector.settings).toBeInstanceOf(PlatformConfiguration);
26
- expect(injector.settings.get("test")).toEqual("test");
27
- expect(injector.logger).toEqual($log);
28
- expect(injector.get(PlatformAdapter)).toBeInstanceOf(FakeAdapter);
29
- });
30
-
31
- it("should create injector", () => {
32
- const settings = {
33
- test: "test",
34
- env: Env.PROD,
35
- adapter: FakeAdapter
36
- };
37
-
38
- const injector = createInjector(settings);
39
-
40
- expect(injector.logger.stop).not.toHaveBeenCalled();
41
- });
42
- });
@@ -1,25 +0,0 @@
1
- import {injector, setLoggerConfiguration} from "@tsed/di";
2
- import {$log} from "@tsed/logger";
3
-
4
- import {PlatformConfiguration} from "../config/services/PlatformConfiguration.js";
5
- import {adapter as $adapter} from "../fn/adapter.js";
6
- import {PlatformAdapter} from "../services/PlatformAdapter.js";
7
-
8
- $log.name = "TSED";
9
-
10
- export function createInjector(settings: Partial<TsED.Configuration>) {
11
- const inj = injector();
12
- inj.addProvider(PlatformConfiguration);
13
-
14
- inj.settings = inj.invoke(PlatformConfiguration);
15
- inj.logger = $log;
16
- inj.settings.set(settings);
17
-
18
- setLoggerConfiguration();
19
-
20
- $adapter(settings.adapter);
21
-
22
- inj.invoke(PlatformAdapter);
23
-
24
- return inj;
25
- }
@@ -1,52 +0,0 @@
1
- import Http from "node:http";
2
- import Https from "node:https";
3
-
4
- import {getHostInfoFromPort, ReturnHostInfoFromPort} from "@tsed/core";
5
- import {configuration, injector, logger, ProviderScope, TokenProvider} from "@tsed/di";
6
- import Http2 from "http2";
7
-
8
- import {listenServer} from "./listenServer.js";
9
-
10
- export interface CreateServerOptions {
11
- token: TokenProvider;
12
- type: "http" | "https";
13
- port: string | false | undefined;
14
- listen?: (hostInfo: ReturnHostInfoFromPort) => Promise<any>;
15
- server: () => Http.Server | Https.Server | Http2.Http2Server;
16
- }
17
-
18
- export type CreateServerReturn = () => Promise<Http.Server | Https.Server | Http2.Http2Server>;
19
-
20
- export function createServer({token, type, port, server: get, listen}: CreateServerOptions): undefined | CreateServerReturn {
21
- const server = port !== false ? get() : null;
22
-
23
- injector().addProvider(token, {
24
- scope: ProviderScope.SINGLETON,
25
- useValue: server
26
- });
27
-
28
- injector().invoke(token);
29
-
30
- if (server) {
31
- const hostInfo = getHostInfoFromPort(type, port);
32
-
33
- return async () => {
34
- const url = `${hostInfo.protocol}://${hostInfo.address}:${port}`;
35
- logger().debug(`Start server on ${url}`);
36
-
37
- await (listen ? listen(hostInfo) : listenServer(server, hostInfo));
38
-
39
- const address = server.address();
40
-
41
- if (address && typeof address !== "string") {
42
- hostInfo.address = address.address;
43
- hostInfo.port = address.port;
44
- }
45
-
46
- logger().info(`Listen server on ${hostInfo.toString()}`);
47
- configuration().set(`${type}Port`, `${hostInfo.address}:${hostInfo.port}`);
48
-
49
- return server;
50
- };
51
- }
52
- }
@@ -1,41 +0,0 @@
1
- import {runInContext} from "@tsed/di";
2
-
3
- import {PlatformTest} from "../../testing/PlatformTest.js";
4
- import {ensureContext} from "./ensureContext.js";
5
-
6
- describe("ensureContext()", () => {
7
- beforeEach(() => PlatformTest.create());
8
- afterEach(() => PlatformTest.reset());
9
-
10
- it("should return context (no async_hook)", async () => {
11
- const $ctx = PlatformTest.createRequestContext();
12
- const stub = vi.fn();
13
- const req = {
14
- $ctx
15
- };
16
-
17
- await ensureContext(req, stub);
18
-
19
- expect(stub).toHaveBeenCalledWith($ctx);
20
- });
21
-
22
- it("should return context (with async_hook)", async () => {
23
- const $ctx = PlatformTest.createRequestContext();
24
- const stub = vi.fn();
25
- const req = {};
26
-
27
- await runInContext($ctx, () => ensureContext(req, stub));
28
-
29
- expect(stub).toHaveBeenCalledWith($ctx);
30
- });
31
-
32
- it("should return context (no async_hook, no context)", async () => {
33
- const stub = vi.fn();
34
- const fallback = vi.fn();
35
- const req = {};
36
-
37
- await ensureContext(req, stub, fallback);
38
-
39
- expect(fallback).toHaveBeenCalledWith();
40
- });
41
- });
@@ -1,17 +0,0 @@
1
- import {getContext, runInContext} from "@tsed/di";
2
-
3
- import {PlatformContext} from "../domain/PlatformContext.js";
4
-
5
- export function ensureContext(request: any, cb: ($ctx: PlatformContext) => any, fallback?: () => void) {
6
- const $ctx = getContext<PlatformContext>();
7
-
8
- if ($ctx) {
9
- return cb($ctx);
10
- }
11
-
12
- if (!request?.$ctx && fallback) {
13
- return fallback();
14
- }
15
-
16
- return runInContext(request.$ctx, () => cb(request.$ctx));
17
- }
@@ -1,163 +0,0 @@
1
- import {Env} from "@tsed/core";
2
- import {Configuration} from "@tsed/di";
3
-
4
- import {getConfiguration} from "./getConfiguration.js";
5
-
6
- class MyCtrl {}
7
-
8
- describe("getConfiguration()", () => {
9
- it("should return configuration (2)", () => {
10
- @Configuration({
11
- mount: {
12
- "/v1": [MyCtrl]
13
- }
14
- })
15
- class MyModule {}
16
-
17
- expect(
18
- getConfiguration(
19
- {
20
- mount: {
21
- "/v2": [MyCtrl]
22
- }
23
- },
24
- MyModule
25
- )
26
- ).toEqual({
27
- $$resolved: true,
28
- env: "test",
29
- httpPort: 8080,
30
- httpsPort: false,
31
- logger: {
32
- debug: false,
33
- jsonIndentation: 2,
34
- level: "off",
35
- logRequest: true
36
- },
37
- mount: {
38
- "/v1": [MyCtrl],
39
- "/v2": [MyCtrl]
40
- },
41
- scopes: {
42
- controller: "singleton"
43
- }
44
- });
45
- });
46
- it("should load configuration for test", () => {
47
- @Configuration({})
48
- class App {}
49
-
50
- const config = getConfiguration({}, App);
51
-
52
- expect(config).toEqual({
53
- $$resolved: true,
54
- env: "test",
55
- httpPort: 8080,
56
- httpsPort: false,
57
- logger: {
58
- debug: false,
59
- jsonIndentation: 2,
60
- level: "off",
61
- logRequest: true
62
- },
63
- mount: {},
64
- scopes: {
65
- controller: "singleton"
66
- }
67
- });
68
- });
69
- it("should load configuration for production", () => {
70
- @Configuration({
71
- env: Env.PROD
72
- })
73
- class App {}
74
-
75
- const config = getConfiguration({}, App);
76
-
77
- expect(config).toEqual({
78
- $$resolved: true,
79
- env: Env.PROD,
80
- httpPort: 8080,
81
- httpsPort: false,
82
- logger: {
83
- debug: false,
84
- jsonIndentation: 2,
85
- level: "info",
86
- logRequest: true
87
- },
88
- mount: {},
89
- scopes: {
90
- controller: "singleton"
91
- }
92
- });
93
- });
94
- it("should load configuration with mount from config", () => {
95
- @Configuration({
96
- env: Env.PROD
97
- })
98
- class App {}
99
-
100
- class Ctrl {}
101
-
102
- const config = getConfiguration(
103
- {
104
- mount: {
105
- "/": [Ctrl]
106
- }
107
- },
108
- App
109
- );
110
-
111
- expect(config).toEqual({
112
- $$resolved: true,
113
- env: Env.PROD,
114
- httpPort: 8080,
115
- httpsPort: false,
116
- logger: {
117
- debug: false,
118
- jsonIndentation: 2,
119
- level: "info",
120
- logRequest: true
121
- },
122
- mount: {
123
- "/": [Ctrl]
124
- },
125
- scopes: {
126
- controller: "singleton"
127
- }
128
- });
129
- });
130
- it("should load configuration with mount from decorator", () => {
131
- class Ctrl {}
132
-
133
- @Configuration({
134
- env: Env.PROD,
135
- mount: {
136
- "/": [Ctrl]
137
- }
138
- })
139
- class App {}
140
-
141
- let config = getConfiguration({}, App);
142
- config = getConfiguration(config, App);
143
-
144
- expect(config).toEqual({
145
- $$resolved: true,
146
- env: Env.PROD,
147
- httpPort: 8080,
148
- httpsPort: false,
149
- logger: {
150
- debug: false,
151
- jsonIndentation: 2,
152
- level: "info",
153
- logRequest: true
154
- },
155
- mount: {
156
- "/": [Ctrl]
157
- },
158
- scopes: {
159
- controller: "singleton"
160
- }
161
- });
162
- });
163
- });
@@ -1,34 +0,0 @@
1
- import {Env, Store, Type} from "@tsed/core";
2
- import {mergeMount, ProviderScope, ProviderType} from "@tsed/di";
3
-
4
- export function getConfiguration(configuration: any = {}, module: Type<any> | null = null) {
5
- if (configuration.$$resolved) {
6
- return configuration;
7
- }
8
-
9
- const store = module ? Store.from(module).get("configuration") || {} : {};
10
- const env = configuration.env || store.env || (process.env.NODE_ENV as Env) || Env.DEV;
11
-
12
- return {
13
- $$resolved: true,
14
- env,
15
- httpPort: 8080,
16
- httpsPort: false,
17
- ...store,
18
- ...configuration,
19
- scopes: {
20
- [ProviderType.CONTROLLER]: ProviderScope.SINGLETON,
21
- ...store.scopes,
22
- ...configuration.scopes
23
- },
24
- mount: mergeMount(store.mount, configuration.mount),
25
- logger: {
26
- debug: false,
27
- level: env === Env.TEST ? "off" : "info",
28
- logRequest: true,
29
- ...store.logger,
30
- ...configuration.logger,
31
- jsonIndentation: process.env.NODE_ENV === Env.PROD ? 0 : 2
32
- }
33
- };
34
- }
@@ -1,27 +0,0 @@
1
- import {getStaticsOptions} from "./getStaticsOptions.js";
2
-
3
- describe("getStaticsOptions()", () => {
4
- it("should return the statics files options", () => {
5
- const result = getStaticsOptions({
6
- "/": ["/root", {root: "/root2", test: "test", hook: "$beforeRoutesInit"}]
7
- });
8
-
9
- expect(result).toEqual([
10
- {
11
- options: {
12
- hook: "$afterRoutesInit",
13
- root: "/root"
14
- },
15
- path: "/"
16
- },
17
- {
18
- options: {
19
- hook: "$beforeRoutesInit",
20
- root: "/root2",
21
- test: "test"
22
- },
23
- path: "/"
24
- }
25
- ]);
26
- });
27
- });
@@ -1,24 +0,0 @@
1
- import {getValue} from "@tsed/core";
2
-
3
- import {PlatformStaticsOptions, PlatformStaticsSettings} from "../config/interfaces/PlatformStaticsSettings.js";
4
-
5
- function mapOptions(options: any): any {
6
- const opts: PlatformStaticsOptions = typeof options === "string" ? {root: options} : options;
7
- return {
8
- ...opts,
9
- hook: getValue(opts, "hook", "$afterRoutesInit")
10
- };
11
- }
12
-
13
- export function getStaticsOptions(statics?: PlatformStaticsSettings): {path: string; options: PlatformStaticsOptions}[] {
14
- return Object.entries(statics || {}).reduce(
15
- (statics, [path, items]) => {
16
- [].concat(items as any).forEach((options) => {
17
- statics.push({path, options: mapOptions(options)});
18
- });
19
-
20
- return statics;
21
- },
22
- [] as {path: string; options: PlatformStaticsOptions}[]
23
- );
24
- }
@@ -1,18 +0,0 @@
1
- import type Http from "node:http";
2
- import type Https from "node:https";
3
-
4
- import {getHostInfoFromPort} from "@tsed/core";
5
- import type Http2 from "http2";
6
-
7
- export function listenServer(server: Http.Server | Https.Server | Http2.Http2Server, hostInfo: ReturnType<typeof getHostInfoFromPort>) {
8
- const {address, port} = hostInfo;
9
-
10
- const promise = new Promise((resolve, reject) => {
11
- server.on("listening", resolve);
12
- server.on("error", reject);
13
- });
14
-
15
- server.listen(port, address as any);
16
-
17
- return promise;
18
- }
@@ -1,35 +0,0 @@
1
- import {mapReturnedResponse} from "../index.js";
2
-
3
- describe("mapReturnedResponse", () => {
4
- it("should map the response (1)", () => {
5
- expect(
6
- mapReturnedResponse({
7
- description: "description",
8
- type: "type",
9
- collection: "collection",
10
- headers: "headers"
11
- })
12
- ).toEqual({
13
- description: "description",
14
- type: "type",
15
- collectionType: "collection",
16
- headers: "headers"
17
- });
18
- });
19
-
20
- it("should map the response (2)", () => {
21
- expect(
22
- mapReturnedResponse({
23
- description: "description",
24
- use: "use",
25
- collection: "collection",
26
- headers: "headers"
27
- })
28
- ).toEqual({
29
- description: "description",
30
- type: "use",
31
- collectionType: "collection",
32
- headers: "headers"
33
- });
34
- });
35
- });
@@ -1,10 +0,0 @@
1
- /**
2
- * @ignore
3
- */
4
- export function mapReturnedResponse({use, collection, ...options}: any): any {
5
- return {
6
- ...options,
7
- type: options.type || use,
8
- collectionType: options.collectionType || collection
9
- };
10
- }
@@ -1,19 +0,0 @@
1
- import {printRoutes} from "./printRoutes.js";
2
-
3
- describe("printRoutes()", () => {
4
- it("should return routes", () => {
5
- const routes = [
6
- {
7
- method: "GET",
8
- url: "/",
9
- name: "name",
10
- toJSON() {
11
- return this;
12
- }
13
- }
14
- ];
15
-
16
- // tslint:disable-next-line: no-unused-variable
17
- expect(typeof printRoutes(routes as any)).toBe("string");
18
- });
19
- });
@@ -1,40 +0,0 @@
1
- import {$log, colorize} from "@tsed/logger";
2
-
3
- import {PlatformRouteDetails} from "../domain/PlatformRouteDetails.js";
4
-
5
- export function printRoutes(routes: PlatformRouteDetails[]) {
6
- const mapColor: {[key: string]: string} = {
7
- GET: "green",
8
- POST: "yellow",
9
- PUT: "blue",
10
- DELETE: "red",
11
- PATCH: "magenta",
12
- ALL: "cyan",
13
- STATICS: "white"
14
- };
15
-
16
- const list = routes.map((route) => {
17
- const method = route.method.toUpperCase();
18
-
19
- return {
20
- ...route,
21
- method: {
22
- length: method.length,
23
- toString: () => {
24
- return colorize(method, mapColor[method]);
25
- }
26
- }
27
- };
28
- });
29
-
30
- const str = $log.drawTable(list, {
31
- padding: 1,
32
- header: {
33
- method: "Method",
34
- url: "Endpoint",
35
- name: "Class method"
36
- }
37
- });
38
-
39
- return "\n" + str.trim();
40
- }
@@ -1,40 +0,0 @@
1
- import {nameOf} from "@tsed/core";
2
-
3
- import {Controller} from "../../../../../di/src/common/decorators/controller.js";
4
- import {M1Ctrl1} from "../../../../../di/src/common/utils/__mock__/module1/controllers/M1Ctrl1.js";
5
- import {Module1} from "../../../../../di/src/common/utils/__mock__/module1/Module1.js";
6
- import {M2Ctrl} from "../../../../../di/src/common/utils/__mock__/module2/controllers/M2Ctrl.js";
7
- import {Module2} from "../../../../../di/src/common/utils/__mock__/module2/Module2.js";
8
- import {resolveControllers} from "./resolveControllers.js";
9
-
10
- @Controller("/root")
11
- class TestCtrl {}
12
-
13
- describe("resolveControllers", () => {
14
- it("should load providers and merge configuration", () => {
15
- const configuration = {
16
- mount: {
17
- "/rest": [TestCtrl]
18
- },
19
- imports: [Module1, Module2]
20
- };
21
-
22
- const result = resolveControllers(configuration);
23
- const routes = result.map((item) => ({...item, token: nameOf(item.token)}));
24
-
25
- expect(routes).toEqual([
26
- {
27
- route: "/m1",
28
- token: "M1Ctrl1"
29
- },
30
- {
31
- route: "/mod2",
32
- token: "M2Ctrl"
33
- },
34
- {
35
- route: "/rest",
36
- token: "TestCtrl"
37
- }
38
- ]);
39
- });
40
- });