@tsed/platform-http 8.11.1 → 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.
- package/lib/esm/common/builder/PlatformBuilder.js +0 -1
- package/lib/esm/common/builder/__fixtures__/PlatformCustom.js +0 -1
- package/lib/esm/common/config/interfaces/PlatformJsonMapperSettings.js +0 -1
- package/lib/esm/common/config/interfaces/PlatformMulterSettings.js +0 -1
- package/lib/esm/common/config/interfaces/PlatformRouterSettings.js +0 -1
- package/lib/esm/common/config/interfaces/PlatformStaticsSettings.js +0 -1
- package/lib/esm/common/config/services/PlatformConfiguration.js +0 -1
- package/lib/esm/common/constants/routerOptions.js +0 -1
- package/lib/esm/common/decorators/PlatformProvider.js +0 -1
- package/lib/esm/common/decorators/multer/multerFileSize.js +0 -1
- package/lib/esm/common/decorators/multer/multerOptions.js +0 -1
- package/lib/esm/common/decorators/multer/multipartFile.js +0 -1
- package/lib/esm/common/decorators/params/error.js +0 -1
- package/lib/esm/common/decorators/params/next.js +0 -1
- package/lib/esm/common/decorators/params/request.js +0 -1
- package/lib/esm/common/decorators/params/response.js +0 -1
- package/lib/esm/common/domain/AnyToPromiseWithCtx.js +0 -1
- package/lib/esm/common/domain/EndpointMetadata.js +0 -1
- package/lib/esm/common/domain/PlatformContext.js +0 -1
- package/lib/esm/common/domain/PlatformRouteDetails.js +0 -1
- package/lib/esm/common/exports.js +0 -1
- package/lib/esm/common/fn/adapter.js +0 -1
- package/lib/esm/common/fn/application.js +0 -1
- package/lib/esm/common/index.js +0 -1
- package/lib/esm/common/interfaces/AfterInit.js +0 -1
- package/lib/esm/common/interfaces/AfterListen.js +0 -1
- package/lib/esm/common/interfaces/AfterRoutesInit.js +0 -1
- package/lib/esm/common/interfaces/BeforeInit.js +0 -1
- package/lib/esm/common/interfaces/BeforeListen.js +0 -1
- package/lib/esm/common/interfaces/BeforeRoutesInit.js +0 -1
- package/lib/esm/common/interfaces/HandlerType.js +0 -1
- package/lib/esm/common/interfaces/IncomingEvent.js +0 -1
- package/lib/esm/common/interfaces/OnReady.js +0 -1
- package/lib/esm/common/interfaces/OnRequest.js +0 -1
- package/lib/esm/common/interfaces/OnResponse.js +0 -1
- package/lib/esm/common/interfaces/OnRoutesInit.js +0 -1
- package/lib/esm/common/interfaces/PlatformRouteOptions.js +0 -1
- package/lib/esm/common/interfaces/ResponseErrorObject.js +0 -1
- package/lib/esm/common/interfaces/Route.js +0 -1
- package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js +0 -1
- package/lib/esm/common/middlewares/PlatformMulterMiddleware.js +0 -1
- package/lib/esm/common/services/Platform.js +0 -1
- package/lib/esm/common/services/PlatformAdapter.js +0 -1
- package/lib/esm/common/services/PlatformApplication.js +0 -1
- package/lib/esm/common/services/PlatformHandler.js +0 -1
- package/lib/esm/common/services/PlatformRequest.js +0 -1
- package/lib/esm/common/services/PlatformResponse.js +0 -1
- package/lib/esm/common/utils/closeServer.js +0 -1
- package/lib/esm/common/utils/createContext.js +0 -1
- package/lib/esm/common/utils/createHttpServer.js +0 -1
- package/lib/esm/common/utils/createHttpsServer.js +0 -1
- package/lib/esm/common/utils/createInjector.js +0 -1
- package/lib/esm/common/utils/createServer.js +0 -1
- package/lib/esm/common/utils/ensureContext.js +0 -1
- package/lib/esm/common/utils/getConfiguration.js +0 -1
- package/lib/esm/common/utils/getStaticsOptions.js +0 -1
- package/lib/esm/common/utils/listenServer.js +0 -1
- package/lib/esm/common/utils/mapReturnedResponse.js +0 -1
- package/lib/esm/common/utils/printRoutes.js +0 -1
- package/lib/esm/common/utils/resolveControllers.js +0 -1
- package/lib/esm/common/utils/setResponseHeaders.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/testing/FakeAdapter.js +0 -1
- package/lib/esm/testing/FakeResponse.js +0 -1
- package/lib/esm/testing/PlatformTest.js +0 -1
- package/lib/esm/testing/index.js +0 -1
- package/package.json +20 -17
- package/.barrelsby.json +0 -5
- package/lib/esm/common/builder/PlatformBuilder.js.map +0 -1
- package/lib/esm/common/builder/__fixtures__/PlatformCustom.js.map +0 -1
- package/lib/esm/common/config/interfaces/PlatformJsonMapperSettings.js.map +0 -1
- package/lib/esm/common/config/interfaces/PlatformMulterSettings.js.map +0 -1
- package/lib/esm/common/config/interfaces/PlatformRouterSettings.js.map +0 -1
- package/lib/esm/common/config/interfaces/PlatformStaticsSettings.js.map +0 -1
- package/lib/esm/common/config/services/PlatformConfiguration.js.map +0 -1
- package/lib/esm/common/constants/routerOptions.js.map +0 -1
- package/lib/esm/common/decorators/PlatformProvider.js.map +0 -1
- package/lib/esm/common/decorators/multer/multerFileSize.js.map +0 -1
- package/lib/esm/common/decorators/multer/multerOptions.js.map +0 -1
- package/lib/esm/common/decorators/multer/multipartFile.js.map +0 -1
- package/lib/esm/common/decorators/params/error.js.map +0 -1
- package/lib/esm/common/decorators/params/next.js.map +0 -1
- package/lib/esm/common/decorators/params/request.js.map +0 -1
- package/lib/esm/common/decorators/params/response.js.map +0 -1
- package/lib/esm/common/domain/AnyToPromiseWithCtx.js.map +0 -1
- package/lib/esm/common/domain/EndpointMetadata.js.map +0 -1
- package/lib/esm/common/domain/PlatformContext.js.map +0 -1
- package/lib/esm/common/domain/PlatformRouteDetails.js.map +0 -1
- package/lib/esm/common/exports.js.map +0 -1
- package/lib/esm/common/fn/adapter.js.map +0 -1
- package/lib/esm/common/fn/application.js.map +0 -1
- package/lib/esm/common/index.js.map +0 -1
- package/lib/esm/common/interfaces/AfterInit.js.map +0 -1
- package/lib/esm/common/interfaces/AfterListen.js.map +0 -1
- package/lib/esm/common/interfaces/AfterRoutesInit.js.map +0 -1
- package/lib/esm/common/interfaces/BeforeInit.js.map +0 -1
- package/lib/esm/common/interfaces/BeforeListen.js.map +0 -1
- package/lib/esm/common/interfaces/BeforeRoutesInit.js.map +0 -1
- package/lib/esm/common/interfaces/HandlerType.js.map +0 -1
- package/lib/esm/common/interfaces/IncomingEvent.js.map +0 -1
- package/lib/esm/common/interfaces/OnReady.js.map +0 -1
- package/lib/esm/common/interfaces/OnRequest.js.map +0 -1
- package/lib/esm/common/interfaces/OnResponse.js.map +0 -1
- package/lib/esm/common/interfaces/OnRoutesInit.js.map +0 -1
- package/lib/esm/common/interfaces/PlatformRouteOptions.js.map +0 -1
- package/lib/esm/common/interfaces/ResponseErrorObject.js.map +0 -1
- package/lib/esm/common/interfaces/Route.js.map +0 -1
- package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js.map +0 -1
- package/lib/esm/common/middlewares/PlatformMulterMiddleware.js.map +0 -1
- package/lib/esm/common/services/Platform.js.map +0 -1
- package/lib/esm/common/services/PlatformAdapter.js.map +0 -1
- package/lib/esm/common/services/PlatformApplication.js.map +0 -1
- package/lib/esm/common/services/PlatformHandler.js.map +0 -1
- package/lib/esm/common/services/PlatformRequest.js.map +0 -1
- package/lib/esm/common/services/PlatformResponse.js.map +0 -1
- package/lib/esm/common/utils/closeServer.js.map +0 -1
- package/lib/esm/common/utils/createContext.js.map +0 -1
- package/lib/esm/common/utils/createHttpServer.js.map +0 -1
- package/lib/esm/common/utils/createHttpsServer.js.map +0 -1
- package/lib/esm/common/utils/createInjector.js.map +0 -1
- package/lib/esm/common/utils/createServer.js.map +0 -1
- package/lib/esm/common/utils/ensureContext.js.map +0 -1
- package/lib/esm/common/utils/getConfiguration.js.map +0 -1
- package/lib/esm/common/utils/getStaticsOptions.js.map +0 -1
- package/lib/esm/common/utils/listenServer.js.map +0 -1
- package/lib/esm/common/utils/mapReturnedResponse.js.map +0 -1
- package/lib/esm/common/utils/printRoutes.js.map +0 -1
- package/lib/esm/common/utils/resolveControllers.js.map +0 -1
- package/lib/esm/common/utils/setResponseHeaders.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/testing/FakeAdapter.js.map +0 -1
- package/lib/esm/testing/FakeResponse.js.map +0 -1
- package/lib/esm/testing/PlatformTest.js.map +0 -1
- package/lib/esm/testing/index.js.map +0 -1
- package/src/common/builder/PlatformBuilder.spec.ts +0 -331
- package/src/common/builder/PlatformBuilder.ts +0 -426
- package/src/common/builder/__fixtures__/PlatformCustom.ts +0 -39
- package/src/common/config/interfaces/PlatformJsonMapperSettings.ts +0 -11
- package/src/common/config/interfaces/PlatformMulterSettings.ts +0 -22
- package/src/common/config/interfaces/PlatformRouterSettings.ts +0 -11
- package/src/common/config/interfaces/PlatformStaticsSettings.ts +0 -23
- package/src/common/config/services/PlatformConfiguration.spec.ts +0 -181
- package/src/common/config/services/PlatformConfiguration.ts +0 -158
- package/src/common/constants/routerOptions.ts +0 -1
- package/src/common/decorators/PlatformProvider.ts +0 -14
- package/src/common/decorators/multer/multerFileSize.ts +0 -31
- package/src/common/decorators/multer/multerOptions.ts +0 -45
- package/src/common/decorators/multer/multipartFile.ts +0 -51
- package/src/common/decorators/params/error.spec.ts +0 -15
- package/src/common/decorators/params/error.ts +0 -16
- package/src/common/decorators/params/next.spec.ts +0 -15
- package/src/common/decorators/params/next.ts +0 -31
- package/src/common/decorators/params/request.spec.ts +0 -50
- package/src/common/decorators/params/request.ts +0 -86
- package/src/common/decorators/params/response.spec.ts +0 -37
- package/src/common/decorators/params/response.ts +0 -74
- package/src/common/domain/AnyToPromiseWithCtx.spec.ts +0 -20
- package/src/common/domain/AnyToPromiseWithCtx.ts +0 -30
- package/src/common/domain/EndpointMetadata.ts +0 -1
- package/src/common/domain/PlatformContext.spec.ts +0 -124
- package/src/common/domain/PlatformContext.ts +0 -136
- package/src/common/domain/PlatformRouteDetails.ts +0 -7
- package/src/common/exports.ts +0 -4
- package/src/common/fn/adapter.ts +0 -42
- package/src/common/fn/application.ts +0 -11
- package/src/common/index.ts +0 -61
- package/src/common/interfaces/AfterInit.ts +0 -3
- package/src/common/interfaces/AfterListen.ts +0 -3
- package/src/common/interfaces/AfterRoutesInit.ts +0 -3
- package/src/common/interfaces/BeforeInit.ts +0 -3
- package/src/common/interfaces/BeforeListen.ts +0 -3
- package/src/common/interfaces/BeforeRoutesInit.ts +0 -3
- package/src/common/interfaces/HandlerType.ts +0 -12
- package/src/common/interfaces/IncomingEvent.ts +0 -6
- package/src/common/interfaces/OnReady.ts +0 -3
- package/src/common/interfaces/OnRequest.ts +0 -5
- package/src/common/interfaces/OnResponse.ts +0 -5
- package/src/common/interfaces/OnRoutesInit.ts +0 -3
- package/src/common/interfaces/PlatformRouteOptions.ts +0 -17
- package/src/common/interfaces/ResponseErrorObject.ts +0 -8
- package/src/common/interfaces/Route.ts +0 -12
- package/src/common/middlewares/PlatformAcceptMimesMiddleware.spec.ts +0 -215
- package/src/common/middlewares/PlatformAcceptMimesMiddleware.ts +0 -34
- package/src/common/middlewares/PlatformMulterMiddleware.ts +0 -6
- package/src/common/services/Platform.spec.ts +0 -145
- package/src/common/services/Platform.ts +0 -79
- package/src/common/services/PlatformAdapter.ts +0 -102
- package/src/common/services/PlatformApplication.spec.ts +0 -89
- package/src/common/services/PlatformApplication.ts +0 -38
- package/src/common/services/PlatformHandler.spec.ts +0 -152
- package/src/common/services/PlatformHandler.ts +0 -137
- package/src/common/services/PlatformRequest.spec.ts +0 -185
- package/src/common/services/PlatformRequest.ts +0 -182
- package/src/common/services/PlatformResponse.spec.ts +0 -364
- package/src/common/services/PlatformResponse.ts +0 -393
- package/src/common/utils/closeServer.spec.ts +0 -11
- package/src/common/utils/closeServer.ts +0 -8
- package/src/common/utils/createContext.spec.ts +0 -111
- package/src/common/utils/createContext.ts +0 -52
- package/src/common/utils/createHttpServer.spec.ts +0 -75
- package/src/common/utils/createHttpServer.ts +0 -16
- package/src/common/utils/createHttpsServer.spec.ts +0 -74
- package/src/common/utils/createHttpsServer.ts +0 -17
- package/src/common/utils/createInjector.spec.ts +0 -42
- package/src/common/utils/createInjector.ts +0 -25
- package/src/common/utils/createServer.ts +0 -52
- package/src/common/utils/ensureContext.spec.ts +0 -41
- package/src/common/utils/ensureContext.ts +0 -17
- package/src/common/utils/getConfiguration.spec.ts +0 -163
- package/src/common/utils/getConfiguration.ts +0 -34
- package/src/common/utils/getStaticsOptions.spec.ts +0 -27
- package/src/common/utils/getStaticsOptions.ts +0 -24
- package/src/common/utils/listenServer.ts +0 -18
- package/src/common/utils/mapReturnedResponse.spec.ts +0 -35
- package/src/common/utils/mapReturnedResponse.ts +0 -10
- package/src/common/utils/printRoutes.spec.ts +0 -19
- package/src/common/utils/printRoutes.ts +0 -40
- package/src/common/utils/resolveControllers.spec.ts +0 -40
- package/src/common/utils/resolveControllers.ts +0 -54
- package/src/common/utils/setResponseHeaders.spec.ts +0 -84
- package/src/common/utils/setResponseHeaders.ts +0 -31
- package/src/index.ts +0 -2
- package/src/testing/FakeAdapter.ts +0 -69
- package/src/testing/FakeResponse.ts +0 -115
- package/src/testing/PlatformTest.spec.ts +0 -53
- package/src/testing/PlatformTest.ts +0 -161
- package/src/testing/index.ts +0 -5
- 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
|
-
}
|
package/src/common/exports.ts
DELETED
package/src/common/fn/adapter.ts
DELETED
|
@@ -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
|
-
}
|
package/src/common/index.ts
DELETED
|
@@ -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";
|