@tsed/platform-http 8.11.0 → 8.11.2-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,86 +0,0 @@
1
- import {IncomingMessage} from "node:http";
2
-
3
- import {isClass, Metadata, nameOf, Type} from "@tsed/core";
4
- import {mapParamsOptions, ParamOptions, ParamTypes, UseParam} from "@tsed/platform-params";
5
-
6
- function getParamType(target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) {
7
- const type = Metadata.getOwnParamTypes(target, propertyKey)[parameterIndex];
8
-
9
- if (isClass(type)) {
10
- if (nameOf(type) === "PlatformRequest") {
11
- return {paramType: ParamTypes.PLATFORM_REQUEST, dataPath: "$ctx.request"};
12
- }
13
-
14
- if (type === IncomingMessage) {
15
- return {paramType: ParamTypes.NODE_REQUEST, dataPath: "$ctx.request.req"};
16
- }
17
- }
18
-
19
- return {paramType: ParamTypes.REQUEST, dataPath: "$ctx.request.request"};
20
- }
21
-
22
- /**
23
- * Request service.
24
- *
25
- * @decorator
26
- * @operation
27
- * @input
28
- */
29
- export function Request(expression: string, useType: Type<any>): ParameterDecorator;
30
- export function Request(expression: string): ParameterDecorator;
31
- export function Request(useType: Type<any>): ParameterDecorator;
32
- export function Request(options: ParamOptions<any>): ParameterDecorator;
33
- export function Request(): ParameterDecorator;
34
- export function Request(...args: any[]): ParameterDecorator {
35
- // @ts-ignore
36
- return Req(...args);
37
- }
38
-
39
- /**
40
- * Request service.
41
- *
42
- * @alias Request
43
- * @decorator
44
- * @operation
45
- * @input
46
- */
47
- export function Req(expression: string, useType: Type<any>): ParameterDecorator;
48
- export function Req(expression: string): ParameterDecorator;
49
- export function Req(useType: Type<any>): ParameterDecorator;
50
- export function Req(options: Partial<ParamOptions>): ParameterDecorator;
51
- export function Req(): ParameterDecorator;
52
- export function Req(...args: any[]): ParameterDecorator {
53
- const {expression, useType, useMapper = false, useValidation = false} = mapParamsOptions(args);
54
-
55
- return (target, propertyKey, parameterIndex) => {
56
- const {paramType, dataPath} = getParamType(target, propertyKey, parameterIndex);
57
-
58
- UseParam({
59
- paramType,
60
- dataPath,
61
- expression,
62
- useType,
63
- useMapper,
64
- useValidation
65
- })(target, propertyKey, parameterIndex);
66
- };
67
- }
68
-
69
- /**
70
- * Request service.
71
- *
72
- * @decorator
73
- * @operation
74
- * @input
75
- */
76
- export interface Request extends TsED.Request {}
77
-
78
- /**
79
- * Request service.
80
- *
81
- * @alias Request
82
- * @decorator
83
- * @operation
84
- * @input
85
- */
86
- export interface Req extends Request {}
@@ -1,37 +0,0 @@
1
- import {ServerResponse} from "node:http";
2
-
3
- import {ParamTypes} from "@tsed/platform-params";
4
- import {JsonParameterStore} from "@tsed/schema";
5
-
6
- import {PlatformResponse} from "../../services/PlatformResponse.js";
7
- import {Res, Response} from "./response.js";
8
-
9
- describe("@Res", () => {
10
- it("should register a new parameter instance with the correct property (RawRes)", () => {
11
- class Ctrl {
12
- test(@Response() arg: Response) {}
13
- }
14
-
15
- const param = JsonParameterStore.get(Ctrl, "test", 0);
16
- expect(param.paramType).toEqual(ParamTypes.RESPONSE);
17
- expect(param.type).toEqual(Response);
18
- });
19
- it("should register a new parameter instance with the correct property (PlatformResponse)", () => {
20
- class Ctrl {
21
- test(@Response() arg: PlatformResponse) {}
22
- }
23
-
24
- const param = JsonParameterStore.get(Ctrl, "test", 0);
25
- expect(param.paramType).toEqual(ParamTypes.PLATFORM_RESPONSE);
26
- expect(param.type).toEqual(PlatformResponse);
27
- });
28
- it("should register a new parameter instance with the correct property (ServerResponse)", () => {
29
- class Ctrl {
30
- test(@Response() arg: ServerResponse) {}
31
- }
32
-
33
- const param = JsonParameterStore.get(Ctrl, "test", 0);
34
- expect(param.paramType).toEqual(ParamTypes.NODE_RESPONSE);
35
- expect(param.type).toEqual(ServerResponse);
36
- });
37
- });
@@ -1,74 +0,0 @@
1
- import {ServerResponse} from "node:http";
2
-
3
- import {isClass, Metadata, nameOf} from "@tsed/core";
4
- import {ParamTypes, UseParam} from "@tsed/platform-params";
5
-
6
- function getParamType(target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) {
7
- const type = Metadata.getOwnParamTypes(target, propertyKey)[parameterIndex];
8
-
9
- if (isClass(type)) {
10
- if (nameOf(type) === "PlatformResponse") {
11
- return {paramType: ParamTypes.PLATFORM_RESPONSE, dataPath: "$ctx.response"};
12
- }
13
-
14
- if (type === ServerResponse) {
15
- return {paramType: ParamTypes.NODE_RESPONSE, dataPath: "$ctx.response.res"};
16
- }
17
- }
18
-
19
- return {paramType: ParamTypes.RESPONSE, dataPath: "$ctx.response.response"};
20
- }
21
-
22
- /**
23
- * Response service.
24
- *
25
- * @decorator
26
- * @operation
27
- * @input
28
- * @response
29
- */
30
- export function Response(): ParameterDecorator;
31
- export function Response(): ParameterDecorator {
32
- return Res();
33
- }
34
-
35
- /**
36
- * Request service.
37
- *
38
- * @alias Response
39
- * @decorator
40
- * @operation
41
- * @input
42
- * @response
43
- */
44
- export function Res(): ParameterDecorator;
45
- export function Res(): ParameterDecorator {
46
- return (target, propertyKey, parameterIndex) => {
47
- const {paramType, dataPath} = getParamType(target, propertyKey, parameterIndex);
48
- UseParam({
49
- paramType,
50
- dataPath
51
- })(target, propertyKey, parameterIndex);
52
- };
53
- }
54
-
55
- /**
56
- * Response service.
57
- *
58
- * @decorator
59
- * @operation
60
- * @input
61
- * @response
62
- */
63
- export interface Response extends TsED.Response {}
64
-
65
- /**
66
- * Response service.
67
- *
68
- * @alias Response
69
- * @decorator
70
- * @operation
71
- * @input
72
- * @response
73
- */
74
- export interface Res extends Response {}
@@ -1,20 +0,0 @@
1
- import {PlatformTest} from "../../testing/PlatformTest.js";
2
- import {AnyToPromiseWithCtx} from "./AnyToPromiseWithCtx.js";
3
-
4
- describe("AnyToPromiseWithCtx", () => {
5
- beforeEach(() => PlatformTest.create());
6
- afterEach(() => PlatformTest.reset());
7
-
8
- it("should return value", async () => {
9
- const $ctx = PlatformTest.createRequestContext();
10
- const resolver = new AnyToPromiseWithCtx($ctx);
11
-
12
- const result = await resolver.call(() => "hello");
13
-
14
- expect(result).toEqual({
15
- data: "hello",
16
- state: "RESOLVED",
17
- type: "DATA"
18
- });
19
- });
20
- });
@@ -1,30 +0,0 @@
1
- import {AnyPromiseResult, AnyToPromise} from "@tsed/core";
2
-
3
- import {PlatformContext} from "./PlatformContext.js";
4
-
5
- export class AnyToPromiseWithCtx extends AnyToPromise {
6
- public $ctx: PlatformContext;
7
-
8
- constructor($ctx: PlatformContext) {
9
- super();
10
- this.$ctx = $ctx;
11
- }
12
-
13
- isDone(): boolean {
14
- const {$ctx} = this;
15
-
16
- return $ctx?.isDone() || super.isDone();
17
- }
18
-
19
- call(cb: Function): Promise<AnyPromiseResult<any>> {
20
- return super.call(() => cb(this));
21
- }
22
-
23
- destroy() {
24
- (this.$ctx as any) = null;
25
- }
26
-
27
- isCanceledResponse(process: any) {
28
- return process === this.$ctx.getResponse();
29
- }
30
- }
@@ -1 +0,0 @@
1
- export {EndpointMetadata} from "@tsed/schema";
@@ -1,124 +0,0 @@
1
- import {nameOf} from "@tsed/core";
2
-
3
- import {PlatformTest} from "../../testing/PlatformTest.js";
4
- import {PlatformApplication} from "../services/PlatformApplication.js";
5
- import {PlatformContext} from "./PlatformContext.js";
6
-
7
- describe("PlatformContext", () => {
8
- beforeEach(() => PlatformTest.create());
9
- afterEach(() => PlatformTest.reset());
10
- it("should create a new Context and skip log", () => {
11
- const logger = {
12
- info: vi.fn()
13
- };
14
- const context = new PlatformContext({
15
- event: {
16
- response: PlatformTest.createResponse(),
17
- request: PlatformTest.createRequest({
18
- url: "/admin"
19
- })
20
- },
21
- id: "id",
22
- logger,
23
- maxStackSize: 0,
24
- ignoreUrlPatterns: ["/admin", /\/admin2/],
25
- injector: PlatformTest.injector
26
- });
27
-
28
- context.endpoint = {} as any;
29
- context.logger.info("test");
30
-
31
- context.handlerMetadata = {} as any;
32
- context.endpoint = {} as any;
33
-
34
- expect(context.id).toEqual("id");
35
- expect(context.dateStart).toBeInstanceOf(Date);
36
- expect(context.container).toBeInstanceOf(Map);
37
- expect(context.env).toEqual("test");
38
- expect(context.getRequest()).toEqual(context.request.raw);
39
- expect(context.getResponse()).toEqual(context.response.raw);
40
- expect(context.getReq()).toEqual(context.request.raw);
41
- expect(context.getRes()).toEqual(context.response.raw);
42
- expect(context.app).toBeInstanceOf(PlatformApplication);
43
- expect(context.handlerMetadata).toEqual({});
44
- expect(context.endpoint).toEqual({});
45
- expect(nameOf(context.getApp())).toEqual("FakeRawDriver");
46
- });
47
- it("should create a new Context and log event", () => {
48
- const logger = {
49
- info: vi.fn()
50
- };
51
-
52
- const context = new PlatformContext({
53
- id: "id",
54
- event: {
55
- response: PlatformTest.createResponse(),
56
- request: PlatformTest.createRequest({
57
- url: "/"
58
- })
59
- },
60
- logger,
61
- injector: PlatformTest.injector,
62
- maxStackSize: 0,
63
- ignoreUrlPatterns: ["/admin", /\/admin2/]
64
- });
65
-
66
- context.logger.info("test");
67
-
68
- expect(context.id).toEqual("id");
69
- expect(context.dateStart).toBeInstanceOf(Date);
70
- expect(context.container).toBeInstanceOf(Map);
71
- expect(context.env).toEqual("test");
72
- expect(context.app).toBeInstanceOf(PlatformApplication);
73
- expect(nameOf(context.getApp())).toEqual("FakeRawDriver");
74
- });
75
- it("should return done when the response is empty", async () => {
76
- const context = new PlatformContext({
77
- id: "id",
78
- event: {
79
- response: PlatformTest.createResponse(),
80
- request: PlatformTest.createRequest({
81
- url: "/"
82
- })
83
- },
84
- logger: {
85
- info: vi.fn()
86
- },
87
- injector: PlatformTest.injector,
88
- maxStackSize: 0,
89
- ignoreUrlPatterns: ["/admin"]
90
- });
91
-
92
- expect(context.isDone()).toEqual(false);
93
-
94
- await context.finish();
95
-
96
- expect(context.isDone()).toEqual(true);
97
- });
98
- it("should return done when the response is empty (start context before)", async () => {
99
- // @ts-ignore
100
- const context = new PlatformContext({
101
- id: "id",
102
- event: {
103
- response: PlatformTest.createResponse(),
104
- request: PlatformTest.createRequest({
105
- url: "/"
106
- })
107
- },
108
- logger: {
109
- info: vi.fn()
110
- },
111
- injector: PlatformTest.injector,
112
- maxStackSize: 0,
113
- ignoreUrlPatterns: ["/admin"]
114
- });
115
-
116
- await context.start();
117
-
118
- expect(context.isDone()).toEqual(false);
119
-
120
- await context.finish();
121
-
122
- expect(context.isDone()).toEqual(true);
123
- });
124
- });
@@ -1,136 +0,0 @@
1
- import {IncomingMessage, ServerResponse} from "node:http";
2
-
3
- import {DIContext, DIContextOptions, injector} from "@tsed/di";
4
- import {$asyncEmit} from "@tsed/hooks";
5
- import {PlatformHandlerMetadata} from "@tsed/platform-router";
6
- import {EndpointMetadata} from "@tsed/schema";
7
-
8
- import {IncomingEvent} from "../interfaces/IncomingEvent.js";
9
- import {PlatformApplication} from "../services/PlatformApplication.js";
10
- import {PlatformRequest} from "../services/PlatformRequest.js";
11
- import {PlatformResponse} from "../services/PlatformResponse.js";
12
-
13
- declare global {
14
- namespace TsED {
15
- export interface Context extends PlatformContext {}
16
- }
17
- }
18
-
19
- export interface PlatformContextOptions extends DIContextOptions {
20
- event: IncomingEvent;
21
- ignoreUrlPatterns?: any[];
22
- endpoint?: EndpointMetadata;
23
- }
24
-
25
- export class PlatformContext<
26
- PReq extends PlatformRequest = PlatformRequest,
27
- PRes extends PlatformResponse = PlatformResponse
28
- > extends DIContext {
29
- readonly PLATFORM: string = "WWW";
30
- public event: IncomingEvent;
31
- /**
32
- * The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.
33
- */
34
- public data: any;
35
- /**
36
- * The error caught by the current handler
37
- */
38
- public error?: unknown;
39
- /**
40
- *
41
- */
42
- public next?: any;
43
- /**
44
- * The current @@PlatformResponse@@.
45
- */
46
- readonly response: PRes;
47
- /**
48
- * The current @@PlatformRequest@@.
49
- */
50
- readonly request: PReq;
51
- /**
52
- * The current @@EndpointMetadata@@ resolved by Ts.ED during the request.
53
- */
54
- endpoint: EndpointMetadata;
55
- /**
56
- * The current @@PlatformHandlerMetadata@@ resolved by Ts.ED during the request.
57
- */
58
- handlerMetadata: PlatformHandlerMetadata;
59
-
60
- #isFinished: boolean = false;
61
-
62
- constructor(options: PlatformContextOptions) {
63
- super(options);
64
-
65
- options.endpoint && (this.endpoint = options.endpoint);
66
-
67
- this.event = options.event;
68
- this.response = new (options.ResponseKlass || PlatformResponse)(this);
69
- this.request = new (options.RequestKlass || PlatformRequest)(this);
70
-
71
- this.request.request.$ctx = this;
72
- this.request.request.id = this.id;
73
-
74
- this.response.setHeader("x-request-id", this.id);
75
- }
76
-
77
- get url() {
78
- return this.request.url;
79
- }
80
-
81
- get app() {
82
- return injector().get<PlatformApplication>(PlatformApplication)!;
83
- }
84
-
85
- start() {
86
- return $asyncEmit("$onRequest", [this]);
87
- }
88
-
89
- async finish() {
90
- await Promise.all([$asyncEmit("$onResponse", [this]), this.destroy()]);
91
- this.#isFinished = true;
92
- }
93
-
94
- isFinished() {
95
- return this.#isFinished;
96
- }
97
-
98
- isDone() {
99
- return this.request?.isAborted() || this.response?.isDone() || this.isFinished();
100
- }
101
-
102
- /**
103
- * Return the framework request instance (Express, Koa, etc...)
104
- */
105
- getRequest<Req = any>(): Req {
106
- return this.request.getRequest<Req>();
107
- }
108
-
109
- /**
110
- * Return the framework response instance (Express, Koa, etc...)
111
- */
112
- getResponse<Res = any>(): Res {
113
- return this.response.getResponse<Res>();
114
- }
115
-
116
- /**
117
- * Get Node.js request
118
- */
119
- getReq(): IncomingMessage {
120
- return this.request.getReq();
121
- }
122
-
123
- /**
124
- * Get Node.js response
125
- */
126
- getRes(): ServerResponse {
127
- return this.response.getRes();
128
- }
129
-
130
- /**
131
- * Return the original application instance.
132
- */
133
- getApp<T = any>(): T {
134
- return this.app.getApp() as any;
135
- }
136
- }
@@ -1,7 +0,0 @@
1
- export interface PlatformRouteDetails {
2
- method: string;
3
- name: string;
4
- url: string;
5
- className: string;
6
- methodClassName: string;
7
- }
@@ -1,4 +0,0 @@
1
- import "@tsed/logger";
2
- import "@tsed/platform-exceptions";
3
- import "@tsed/platform-response-filter";
4
- import "@tsed/platform-router";
@@ -1,42 +0,0 @@
1
- import {Type} from "@tsed/core";
2
- import {GlobalProviders, injector, ProviderOpts, refValue} from "@tsed/di";
3
-
4
- import {PlatformAdapter} from "../services/PlatformAdapter.js";
5
-
6
- const ADAPTER = "platform.adapter";
7
-
8
- let globalAdapter: Type<PlatformAdapter<any>>;
9
-
10
- /**
11
- * Set the platform adapter token and his dependencies
12
- */
13
- export function adapter(adapter: Type<PlatformAdapter<any>>, imports?: ProviderOpts[]): Type<PlatformAdapter<any>>;
14
- /**
15
- * Get the platform adapter token
16
- */
17
- export function adapter(): Type<PlatformAdapter<any>>;
18
- export function adapter(adapter?: Type<PlatformAdapter<any>>, imports: ProviderOpts[] = []): Type<PlatformAdapter<any>> {
19
- const ref = refValue<Type<PlatformAdapter<any>>>(ADAPTER);
20
-
21
- if (adapter) {
22
- globalAdapter ||= adapter;
23
-
24
- imports?.forEach(({token, useClass}) => {
25
- const provider = GlobalProviders.get(token);
26
- if (useClass && provider) {
27
- provider.useClass = useClass;
28
- injector().set(token, provider);
29
- }
30
- });
31
-
32
- injector()
33
- .addProvider(PlatformAdapter, {
34
- useClass: adapter
35
- })
36
- .alias(PlatformAdapter, "PlatformAdapter");
37
- }
38
-
39
- ref.value ||= globalAdapter;
40
-
41
- return ref.value as Type<PlatformAdapter<any>>;
42
- }
@@ -1,11 +0,0 @@
1
- import {injector} from "@tsed/di";
2
-
3
- import type {PlatformApplication} from "../services/PlatformApplication.js";
4
-
5
- /**
6
- * Return the injectable Application instance.
7
- * @note Application is only available after PlatformExpress/PlatformKoa instance creation.
8
- */
9
- export function application<App = TsED.Application>() {
10
- return injector().get<PlatformApplication<App>>("PlatformApplication")!;
11
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * @file Automatically generated by @tsed/barrels.
3
- */
4
- export * from "./builder/PlatformBuilder.js";
5
- export * from "./config/interfaces/PlatformJsonMapperSettings.js";
6
- export * from "./config/interfaces/PlatformMulterSettings.js";
7
- export * from "./config/interfaces/PlatformRouterSettings.js";
8
- export * from "./config/interfaces/PlatformStaticsSettings.js";
9
- export * from "./config/services/PlatformConfiguration.js";
10
- export * from "./constants/routerOptions.js";
11
- export * from "./decorators/multer/multerFileSize.js";
12
- export * from "./decorators/multer/multerOptions.js";
13
- export * from "./decorators/multer/multipartFile.js";
14
- export * from "./decorators/params/error.js";
15
- export * from "./decorators/params/next.js";
16
- export * from "./decorators/params/request.js";
17
- export * from "./decorators/params/response.js";
18
- export * from "./decorators/PlatformProvider.js";
19
- export * from "./domain/AnyToPromiseWithCtx.js";
20
- export * from "./domain/EndpointMetadata.js";
21
- export * from "./domain/PlatformContext.js";
22
- export * from "./domain/PlatformRouteDetails.js";
23
- export * from "./exports.js";
24
- export * from "./fn/adapter.js";
25
- export * from "./fn/application.js";
26
- export * from "./interfaces/AfterInit.js";
27
- export * from "./interfaces/AfterListen.js";
28
- export * from "./interfaces/AfterRoutesInit.js";
29
- export * from "./interfaces/BeforeInit.js";
30
- export * from "./interfaces/BeforeListen.js";
31
- export * from "./interfaces/BeforeRoutesInit.js";
32
- export * from "./interfaces/HandlerType.js";
33
- export * from "./interfaces/IncomingEvent.js";
34
- export * from "./interfaces/OnReady.js";
35
- export * from "./interfaces/OnRequest.js";
36
- export * from "./interfaces/OnResponse.js";
37
- export * from "./interfaces/OnRoutesInit.js";
38
- export * from "./interfaces/PlatformRouteOptions.js";
39
- export * from "./interfaces/ResponseErrorObject.js";
40
- export * from "./interfaces/Route.js";
41
- export * from "./middlewares/PlatformAcceptMimesMiddleware.js";
42
- export * from "./middlewares/PlatformMulterMiddleware.js";
43
- export * from "./services/Platform.js";
44
- export * from "./services/PlatformAdapter.js";
45
- export * from "./services/PlatformApplication.js";
46
- export * from "./services/PlatformHandler.js";
47
- export * from "./services/PlatformRequest.js";
48
- export * from "./services/PlatformResponse.js";
49
- export * from "./utils/closeServer.js";
50
- export * from "./utils/createContext.js";
51
- export * from "./utils/createHttpServer.js";
52
- export * from "./utils/createHttpsServer.js";
53
- export * from "./utils/createInjector.js";
54
- export * from "./utils/createServer.js";
55
- export * from "./utils/ensureContext.js";
56
- export * from "./utils/getStaticsOptions.js";
57
- export * from "./utils/listenServer.js";
58
- export * from "./utils/mapReturnedResponse.js";
59
- export * from "./utils/printRoutes.js";
60
- export * from "./utils/resolveControllers.js";
61
- export * from "./utils/setResponseHeaders.js";
@@ -1,3 +0,0 @@
1
- export interface AfterInit {
2
- $afterInit(): void | Promise<any>;
3
- }
@@ -1,3 +0,0 @@
1
- export interface AfterListen {
2
- $afterListen(): void | Promise<any>;
3
- }
@@ -1,3 +0,0 @@
1
- export interface AfterRoutesInit {
2
- $afterRoutesInit(): void | Promise<any>;
3
- }
@@ -1,3 +0,0 @@
1
- export interface BeforeInit {
2
- $beforeInit(): void | Promise<any>;
3
- }
@@ -1,3 +0,0 @@
1
- export interface BeforeListen {
2
- $beforeListen(): void | Promise<any>;
3
- }
@@ -1,3 +0,0 @@
1
- export interface BeforeRoutesInit {
2
- $beforeRoutesInit(): void | Promise<any>;
3
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * @ignore
3
- */
4
- export enum HandlerType {
5
- CUSTOM = "custom",
6
- ENDPOINT = "endpoint",
7
- MIDDLEWARE = "middleware",
8
- ERR_MIDDLEWARE = "err:middleware",
9
- CTX_FN = "context",
10
- RAW_FN = "raw:middleware",
11
- RAW_ERR_FN = "raw:err:middleware"
12
- }