@tsed/common 7.0.0-beta.13 → 7.0.0-beta.16

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 (143) hide show
  1. package/jest.config.js +4 -4
  2. package/lib/cjs/builder/PlatformBuilder.js +20 -10
  3. package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
  4. package/lib/cjs/decorators/params/error.js +1 -1
  5. package/lib/cjs/decorators/params/error.js.map +1 -1
  6. package/lib/cjs/domain/AnyToPromiseWithCtx.js +1 -3
  7. package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -1
  8. package/lib/cjs/domain/PlatformContext.js +28 -1
  9. package/lib/cjs/domain/PlatformContext.js.map +1 -1
  10. package/lib/cjs/domain/PlatformRouteDetails.js +0 -25
  11. package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -1
  12. package/lib/cjs/exports.js +1 -0
  13. package/lib/cjs/exports.js.map +1 -1
  14. package/lib/cjs/index.js +1 -7
  15. package/lib/cjs/index.js.map +1 -1
  16. package/lib/cjs/interfaces/Route.js.map +1 -1
  17. package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -1
  18. package/lib/cjs/services/FakeAdapter.js +5 -9
  19. package/lib/cjs/services/FakeAdapter.js.map +1 -1
  20. package/lib/cjs/services/Platform.js +41 -85
  21. package/lib/cjs/services/Platform.js.map +1 -1
  22. package/lib/cjs/services/PlatformAdapter.js +0 -2
  23. package/lib/cjs/services/PlatformAdapter.js.map +1 -1
  24. package/lib/cjs/services/PlatformApplication.js +22 -10
  25. package/lib/cjs/services/PlatformApplication.js.map +1 -1
  26. package/lib/cjs/services/PlatformHandler.js +87 -163
  27. package/lib/cjs/services/PlatformHandler.js.map +1 -1
  28. package/lib/cjs/services/PlatformMiddlewaresChain.js +2 -18
  29. package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
  30. package/lib/cjs/services/PlatformRequest.js +2 -2
  31. package/lib/cjs/services/PlatformRequest.js.map +1 -1
  32. package/lib/cjs/services/PlatformResponse.js +5 -9
  33. package/lib/cjs/services/PlatformResponse.js.map +1 -1
  34. package/lib/cjs/services/PlatformTest.js +1 -0
  35. package/lib/cjs/services/PlatformTest.js.map +1 -1
  36. package/lib/cjs/utils/createContext.js +7 -11
  37. package/lib/cjs/utils/createContext.js.map +1 -1
  38. package/lib/cjs/utils/createInjector.js +0 -2
  39. package/lib/cjs/utils/createInjector.js.map +1 -1
  40. package/lib/cjs/utils/ensureContext.js +16 -0
  41. package/lib/cjs/utils/ensureContext.js.map +1 -0
  42. package/lib/cjs/utils/printRoutes.js +10 -8
  43. package/lib/cjs/utils/printRoutes.js.map +1 -1
  44. package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
  45. package/lib/esm/builder/PlatformBuilder.js +20 -10
  46. package/lib/esm/builder/PlatformBuilder.js.map +1 -1
  47. package/lib/esm/decorators/params/error.js +1 -1
  48. package/lib/esm/decorators/params/error.js.map +1 -1
  49. package/lib/esm/domain/AnyToPromiseWithCtx.js +1 -3
  50. package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -1
  51. package/lib/esm/domain/PlatformContext.js +28 -1
  52. package/lib/esm/domain/PlatformContext.js.map +1 -1
  53. package/lib/esm/domain/PlatformRouteDetails.js +1 -23
  54. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -1
  55. package/lib/esm/exports.js +1 -0
  56. package/lib/esm/exports.js.map +1 -1
  57. package/lib/esm/index.js +1 -7
  58. package/lib/esm/index.js.map +1 -1
  59. package/lib/esm/interfaces/Route.js.map +1 -1
  60. package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -1
  61. package/lib/esm/services/FakeAdapter.js +5 -9
  62. package/lib/esm/services/FakeAdapter.js.map +1 -1
  63. package/lib/esm/services/Platform.js +42 -86
  64. package/lib/esm/services/Platform.js.map +1 -1
  65. package/lib/esm/services/PlatformAdapter.js +0 -2
  66. package/lib/esm/services/PlatformAdapter.js.map +1 -1
  67. package/lib/esm/services/PlatformApplication.js +22 -10
  68. package/lib/esm/services/PlatformApplication.js.map +1 -1
  69. package/lib/esm/services/PlatformHandler.js +89 -165
  70. package/lib/esm/services/PlatformHandler.js.map +1 -1
  71. package/lib/esm/services/PlatformMiddlewaresChain.js +2 -18
  72. package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -1
  73. package/lib/esm/services/PlatformRequest.js +2 -2
  74. package/lib/esm/services/PlatformRequest.js.map +1 -1
  75. package/lib/esm/services/PlatformResponse.js +5 -9
  76. package/lib/esm/services/PlatformResponse.js.map +1 -1
  77. package/lib/esm/services/PlatformTest.js +1 -0
  78. package/lib/esm/services/PlatformTest.js.map +1 -1
  79. package/lib/esm/utils/createContext.js +5 -9
  80. package/lib/esm/utils/createContext.js.map +1 -1
  81. package/lib/esm/utils/createInjector.js +0 -2
  82. package/lib/esm/utils/createInjector.js.map +1 -1
  83. package/lib/esm/utils/ensureContext.js +12 -0
  84. package/lib/esm/utils/ensureContext.js.map +1 -0
  85. package/lib/esm/utils/printRoutes.js +10 -8
  86. package/lib/esm/utils/printRoutes.js.map +1 -1
  87. package/lib/esm/utils/setResponseHeaders.js.map +1 -1
  88. package/lib/types/builder/PlatformBuilder.d.ts +13 -11
  89. package/lib/types/domain/AnyToPromiseWithCtx.d.ts +1 -9
  90. package/lib/types/domain/PlatformContext.d.ts +16 -1
  91. package/lib/types/domain/PlatformRouteDetails.d.ts +6 -15
  92. package/lib/types/exports.d.ts +1 -0
  93. package/lib/types/index.d.ts +1 -7
  94. package/lib/types/interfaces/Route.d.ts +2 -3
  95. package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +1 -1
  96. package/lib/types/services/FakeAdapter.d.ts +7 -6
  97. package/lib/types/services/Platform.d.ts +11 -28
  98. package/lib/types/services/PlatformAdapter.d.ts +19 -10
  99. package/lib/types/services/PlatformApplication.d.ts +14 -6
  100. package/lib/types/services/PlatformHandler.d.ts +19 -55
  101. package/lib/types/services/PlatformMiddlewaresChain.d.ts +1 -2
  102. package/lib/types/services/PlatformRequest.d.ts +1 -5
  103. package/lib/types/services/PlatformResponse.d.ts +2 -4
  104. package/lib/types/services/PlatformTest.d.ts +2 -1
  105. package/lib/types/utils/createContext.d.ts +2 -2
  106. package/lib/types/utils/createInjector.d.ts +1 -1
  107. package/lib/types/utils/ensureContext.d.ts +2 -0
  108. package/package.json +16 -15
  109. package/lib/cjs/builder/PlatformControllerBuilder.js +0 -82
  110. package/lib/cjs/builder/PlatformControllerBuilder.js.map +0 -1
  111. package/lib/cjs/domain/ControllerProvider.js +0 -52
  112. package/lib/cjs/domain/ControllerProvider.js.map +0 -1
  113. package/lib/cjs/domain/HandlerMetadata.js +0 -62
  114. package/lib/cjs/domain/HandlerMetadata.js.map +0 -1
  115. package/lib/cjs/middlewares/bindEndpointMiddleware.js +0 -13
  116. package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +0 -1
  117. package/lib/cjs/services/PlatformRouter.js +0 -114
  118. package/lib/cjs/services/PlatformRouter.js.map +0 -1
  119. package/lib/cjs/utils/createHandlerMetadata.js +0 -49
  120. package/lib/cjs/utils/createHandlerMetadata.js.map +0 -1
  121. package/lib/cjs/utils/useCtxHandler.js +0 -15
  122. package/lib/cjs/utils/useCtxHandler.js.map +0 -1
  123. package/lib/esm/builder/PlatformControllerBuilder.js +0 -76
  124. package/lib/esm/builder/PlatformControllerBuilder.js.map +0 -1
  125. package/lib/esm/domain/ControllerProvider.js +0 -48
  126. package/lib/esm/domain/ControllerProvider.js.map +0 -1
  127. package/lib/esm/domain/HandlerMetadata.js +0 -58
  128. package/lib/esm/domain/HandlerMetadata.js.map +0 -1
  129. package/lib/esm/middlewares/bindEndpointMiddleware.js +0 -9
  130. package/lib/esm/middlewares/bindEndpointMiddleware.js.map +0 -1
  131. package/lib/esm/services/PlatformRouter.js +0 -111
  132. package/lib/esm/services/PlatformRouter.js.map +0 -1
  133. package/lib/esm/utils/createHandlerMetadata.js +0 -45
  134. package/lib/esm/utils/createHandlerMetadata.js.map +0 -1
  135. package/lib/esm/utils/useCtxHandler.js +0 -11
  136. package/lib/esm/utils/useCtxHandler.js.map +0 -1
  137. package/lib/types/builder/PlatformControllerBuilder.d.ts +0 -18
  138. package/lib/types/domain/ControllerProvider.d.ts +0 -24
  139. package/lib/types/domain/HandlerMetadata.d.ts +0 -32
  140. package/lib/types/middlewares/bindEndpointMiddleware.d.ts +0 -6
  141. package/lib/types/services/PlatformRouter.d.ts +0 -51
  142. package/lib/types/utils/createHandlerMetadata.d.ts +0 -8
  143. package/lib/types/utils/useCtxHandler.d.ts +0 -13
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Type } from "@tsed/core";
3
3
  import { InjectorService, ProviderOpts, TokenProvider } from "@tsed/di";
4
+ import { PlatformLayer } from "@tsed/platform-router";
4
5
  import type { IncomingMessage, ServerResponse } from "http";
5
6
  import { Platform } from "../services/Platform";
6
7
  import { PlatformAdapter, PlatformBuilderSettings } from "../services/PlatformAdapter";
@@ -8,18 +9,18 @@ import { PlatformApplication } from "../services/PlatformApplication";
8
9
  /**
9
10
  * @platform
10
11
  */
11
- export declare class PlatformBuilder<App = TsED.Application, Router = TsED.Router> {
12
+ export declare class PlatformBuilder<App = TsED.Application> {
12
13
  #private;
13
- static adapter: Type<PlatformAdapter<any, any>>;
14
+ static adapter: Type<PlatformAdapter<any>>;
14
15
  readonly name: string;
15
16
  protected startedAt: Date;
16
17
  protected current: Date;
17
- protected constructor(adapter: Type<PlatformAdapter<App, Router>> | undefined, module: Type, settings: Partial<TsED.Configuration>);
18
+ protected constructor(adapter: Type<PlatformAdapter<App>> | undefined, module: Type, settings: Partial<TsED.Configuration>);
18
19
  get injector(): InjectorService;
19
20
  get rootModule(): any;
20
- get app(): PlatformApplication<App, Router>;
21
+ get app(): PlatformApplication<App>;
21
22
  get platform(): Platform;
22
- get adapter(): PlatformAdapter<App, Router>;
23
+ get adapter(): PlatformAdapter<App>;
23
24
  /**
24
25
  * Return the settings configured by the decorator @@Configuration@@.
25
26
  *
@@ -44,16 +45,16 @@ export declare class PlatformBuilder<App = TsED.Application, Router = TsED.Route
44
45
  get settings(): import("@tsed/di").DIConfiguration;
45
46
  get logger(): import("@tsed/di").DILogger;
46
47
  get disableBootstrapLog(): any;
47
- static create<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>): PlatformBuilder<App, Router>;
48
- static build<App = TsED.Application, Router = TsED.Router>(module: Type<any>, { adapter, ...settings }: PlatformBuilderSettings<App, Router>): PlatformBuilder<App, Router>;
48
+ static create<App = TsED.Application>(module: Type<any>, settings: PlatformBuilderSettings<App>): PlatformBuilder<App>;
49
+ static build<App = TsED.Application>(module: Type<any>, { adapter, ...settings }: PlatformBuilderSettings<App>): PlatformBuilder<App>;
49
50
  /**
50
51
  * Bootstrap a server application
51
52
  * @param module
52
53
  * @param settings
53
54
  */
54
- static bootstrap<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>): Promise<PlatformBuilder<App, Router>>;
55
- callback(): (req: IncomingMessage, res: ServerResponse) => void;
56
- callback(req: IncomingMessage, res: ServerResponse): void;
55
+ static bootstrap<App = TsED.Application>(module: Type<any>, settings: PlatformBuilderSettings<App>): Promise<PlatformBuilder<App>>;
56
+ callback(): (req: IncomingMessage, res: ServerResponse) => any;
57
+ callback(req: IncomingMessage, res: ServerResponse): any;
57
58
  log(...data: any[]): any;
58
59
  /**
59
60
  * Add classes to the components list
@@ -91,6 +92,7 @@ export declare class PlatformBuilder<App = TsED.Application, Router = TsED.Route
91
92
  useProvider(token: Type<any>, settings?: Partial<ProviderOpts>): this;
92
93
  bootstrap(): Promise<this>;
93
94
  protected loadRoutes(): Promise<void>;
95
+ protected mapRouters(): Promise<void>;
94
96
  protected diff(): string;
95
97
  /**
96
98
  * Load middlewares from configuration for the given hook
@@ -100,5 +102,5 @@ export declare class PlatformBuilder<App = TsED.Application, Router = TsED.Route
100
102
  protected loadMiddlewaresFor(hook: string): void;
101
103
  protected createHttpServers(): void;
102
104
  protected listenServers(): Promise<void>;
103
- protected logRoutes(): Promise<void>;
105
+ protected logRoutes(layers: PlatformLayer[]): Promise<void>;
104
106
  }
@@ -1,16 +1,8 @@
1
1
  import { AnyPromiseResult, AnyToPromise } from "@tsed/core";
2
2
  import { PlatformContext } from "./PlatformContext";
3
- /**
4
- * @ignore
5
- */
6
- export interface HandlerContextOptions {
7
- $ctx: PlatformContext;
8
- err?: any;
9
- }
10
3
  export declare class AnyToPromiseWithCtx extends AnyToPromise {
11
4
  $ctx: PlatformContext;
12
- err: unknown;
13
- constructor({ $ctx, err }: HandlerContextOptions);
5
+ constructor($ctx: PlatformContext);
14
6
  isDone(): boolean;
15
7
  call(cb: Function): Promise<AnyPromiseResult<any>>;
16
8
  destroy(): void;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { ContextMethods, DIContext, DIContextOptions } from "@tsed/di";
3
+ import { PlatformHandlerMetadata } from "@tsed/platform-router";
3
4
  import { EndpointMetadata } from "@tsed/schema";
4
5
  import { IncomingMessage, ServerResponse } from "http";
5
6
  import { IncomingEvent } from "../interfaces/IncomingEvent";
@@ -28,6 +29,10 @@ export declare class PlatformContext<PReq extends PlatformRequest = PlatformRequ
28
29
  * The error caught by the current handler
29
30
  */
30
31
  error?: unknown;
32
+ /**
33
+ *
34
+ */
35
+ next?: any;
31
36
  /**
32
37
  * The current @@PlatformResponse@@.
33
38
  */
@@ -43,8 +48,18 @@ export declare class PlatformContext<PReq extends PlatformRequest = PlatformRequ
43
48
  */
44
49
  get endpoint(): EndpointMetadata;
45
50
  set endpoint(endpoint: EndpointMetadata);
51
+ /**
52
+ * The current @@PlatformHandlerMetadata@@ resolved by Ts.ED during the request.
53
+ */
54
+ get handlerMetadata(): PlatformHandlerMetadata;
55
+ /**
56
+ * The current @@PlatformHandlerMetadata@@ resolved by Ts.ED during the request.
57
+ */
58
+ set handlerMetadata(metadata: PlatformHandlerMetadata);
46
59
  get url(): string;
47
- get app(): PlatformApplication<TsED.Application, TsED.Router>;
60
+ get app(): PlatformApplication<TsED.Application>;
61
+ start(): Promise<void>;
62
+ finish(): Promise<void>;
48
63
  destroy(): Promise<void>;
49
64
  isDone(): any;
50
65
  /**
@@ -1,16 +1,7 @@
1
- import { EndpointMetadata, JsonOperationRoute } from "@tsed/schema";
2
- import { ControllerProvider } from "./ControllerProvider";
3
- export declare class PlatformRouteDetails extends JsonOperationRoute<EndpointMetadata> {
4
- readonly rawBody: boolean;
5
- readonly provider: ControllerProvider;
6
- constructor(options: Partial<PlatformRouteDetails>);
7
- toJSON(): {
8
- method: string;
9
- name: string;
10
- url: string;
11
- className: string;
12
- methodClassName: string;
13
- parameters: import("@tsed/schema").JsonParameterStore[];
14
- rawBody: boolean;
15
- };
1
+ export interface PlatformRouteDetails {
2
+ method: string;
3
+ name: string;
4
+ url: string;
5
+ className: string;
6
+ methodClassName: string;
16
7
  }
@@ -8,5 +8,6 @@ export * from "@tsed/platform-cache";
8
8
  export * from "@tsed/platform-middlewares";
9
9
  export * from "@tsed/components-scan";
10
10
  export * from "@tsed/platform-log-middleware";
11
+ export * from "@tsed/platform-router";
11
12
  export { $log, Logger } from "@tsed/logger";
12
13
  export { AcceptMime, Location, Redirect, View, Get, Post, Put, Patch, Delete, Head, Options, All } from "@tsed/schema";
@@ -3,7 +3,6 @@
3
3
  */
4
4
  export * from "./exports";
5
5
  export * from "./builder/PlatformBuilder";
6
- export * from "./builder/PlatformControllerBuilder";
7
6
  export * from "./config/interfaces/ConverterSettings";
8
7
  export * from "./config/interfaces/PlatformLoggerSettings";
9
8
  export * from "./config/interfaces/PlatformMulterSettings";
@@ -18,9 +17,7 @@ export * from "./decorators/params/next";
18
17
  export * from "./decorators/params/request";
19
18
  export * from "./decorators/params/response";
20
19
  export * from "./domain/AnyToPromiseWithCtx";
21
- export * from "./domain/ControllerProvider";
22
20
  export * from "./domain/EndpointMetadata";
23
- export * from "./domain/HandlerMetadata";
24
21
  export * from "./domain/PlatformContext";
25
22
  export * from "./domain/PlatformRouteDetails";
26
23
  export * from "./interfaces/AfterInit";
@@ -40,7 +37,6 @@ export * from "./interfaces/ResponseErrorObject";
40
37
  export * from "./interfaces/Route";
41
38
  export * from "./middlewares/PlatformAcceptMimesMiddleware";
42
39
  export * from "./middlewares/PlatformMulterMiddleware";
43
- export * from "./middlewares/bindEndpointMiddleware";
44
40
  export * from "./services/FakeAdapter";
45
41
  export * from "./services/Platform";
46
42
  export * from "./services/PlatformAdapter";
@@ -49,16 +45,14 @@ export * from "./services/PlatformHandler";
49
45
  export * from "./services/PlatformMiddlewaresChain";
50
46
  export * from "./services/PlatformRequest";
51
47
  export * from "./services/PlatformResponse";
52
- export * from "./services/PlatformRouter";
53
48
  export * from "./services/PlatformTest";
54
49
  export * from "./utils/createContext";
55
- export * from "./utils/createHandlerMetadata";
56
50
  export * from "./utils/createHttpServer";
57
51
  export * from "./utils/createHttpsServer";
58
52
  export * from "./utils/createInjector";
53
+ export * from "./utils/ensureContext";
59
54
  export * from "./utils/getStaticsOptions";
60
55
  export * from "./utils/listenServer";
61
56
  export * from "./utils/mapReturnedResponse";
62
57
  export * from "./utils/printRoutes";
63
58
  export * from "./utils/setResponseHeaders";
64
- export * from "./utils/useCtxHandler";
@@ -1,10 +1,9 @@
1
- import { TokenProvider } from "@tsed/di";
2
- import { ControllerProvider } from "../domain/ControllerProvider";
1
+ import { Provider, TokenProvider } from "@tsed/di";
3
2
  export interface Route extends Record<string, any> {
4
3
  route: string;
5
4
  token: TokenProvider;
6
5
  }
7
6
  export interface RouteController {
8
7
  route: string;
9
- provider: ControllerProvider;
8
+ provider: Provider;
10
9
  }
@@ -1,7 +1,7 @@
1
- import type { MulterError } from "multer";
2
1
  import { BadRequest } from "@tsed/exceptions";
3
2
  import { MiddlewareMethods } from "@tsed/platform-middlewares";
4
3
  import { Context } from "@tsed/platform-params";
4
+ import type { MulterError } from "multer";
5
5
  import { PlatformMulterField, PlatformMulterSettings } from "../config/interfaces/PlatformMulterSettings";
6
6
  import { PlatformApplication } from "../services/PlatformApplication";
7
7
  export interface MulterInputOptions {
@@ -1,8 +1,10 @@
1
1
  import { ProviderOpts } from "@tsed/di";
2
- import { PlatformAdapter } from "./PlatformAdapter";
2
+ import { PlatformContextHandler, PlatformLayer } from "@tsed/platform-router";
3
3
  import { PlatformMulter, PlatformMulterSettings } from "../config/interfaces/PlatformMulterSettings";
4
4
  import { PlatformStaticsOptions } from "../config/interfaces/PlatformStaticsSettings";
5
- export declare class FakeAdapter implements PlatformAdapter<any, any> {
5
+ import { PlatformContext } from "../domain/PlatformContext";
6
+ import { PlatformAdapter } from "./PlatformAdapter";
7
+ export declare class FakeAdapter implements PlatformAdapter<any> {
6
8
  providers: ProviderOpts[];
7
9
  static createFakeRawDriver(): {
8
10
  (): void;
@@ -21,10 +23,9 @@ export declare class FakeAdapter implements PlatformAdapter<any, any> {
21
23
  callback(): any;
22
24
  };
23
25
  multipart(options: PlatformMulterSettings): PlatformMulter;
24
- router(routerOptions: any): {
25
- router: any;
26
- callback(): any;
27
- };
28
26
  statics(endpoint: string, options: PlatformStaticsOptions): any;
29
27
  bodyParser(type: string): any;
28
+ mapLayers(layers: PlatformLayer[]): void;
29
+ mapHandler(handler: PlatformContextHandler<PlatformContext>): PlatformContextHandler<PlatformContext<import("./PlatformRequest").PlatformRequest<any>, import("./PlatformResponse").PlatformResponse<any>>>;
30
+ useContext(): void;
30
31
  }
@@ -1,46 +1,29 @@
1
1
  import { InjectorService, TokenProvider } from "@tsed/di";
2
- import { PlatformRouteDetails } from "../domain/PlatformRouteDetails";
2
+ import { PlatformRouters } from "@tsed/platform-router";
3
3
  import { Route, RouteController } from "../interfaces/Route";
4
4
  import { PlatformApplication } from "./PlatformApplication";
5
+ import { PlatformHandler } from "./PlatformHandler";
6
+ import { PlatformMiddlewaresChain } from "./PlatformMiddlewaresChain";
5
7
  /**
6
8
  * `Platform` is used to provide all routes collected by annotation `@Controller`.
7
9
  *
8
10
  * @platform
9
11
  */
10
12
  export declare class Platform {
13
+ #private;
11
14
  readonly injector: InjectorService;
12
15
  readonly platformApplication: PlatformApplication;
13
- private _routes;
14
- private _controllers;
15
- constructor(injector: InjectorService, platformApplication: PlatformApplication);
16
- get app(): PlatformApplication<TsED.Application, TsED.Router>;
17
- get routes(): PlatformRouteDetails[];
16
+ readonly platformRouters: PlatformRouters;
17
+ readonly platformHandler: PlatformHandler;
18
+ readonly platformMiddlewaresChain: PlatformMiddlewaresChain;
19
+ constructor(injector: InjectorService, platformApplication: PlatformApplication, platformRouters: PlatformRouters, platformHandler: PlatformHandler, platformMiddlewaresChain: PlatformMiddlewaresChain);
20
+ get app(): PlatformApplication<TsED.Application>;
18
21
  addRoutes(routes: Route[]): void;
19
- addRoute(basePath: string, token: TokenProvider): this | undefined;
20
- /**
21
- * Get all routes built by TsExpressDecorators and mounted on Express application.
22
- * @returns {PlatformRouteDetails[]}
23
- */
24
- getRoutes(): PlatformRouteDetails[];
22
+ addRoute(route: string, token: TokenProvider): this;
23
+ getLayers(): import("@tsed/platform-router").PlatformLayer[];
25
24
  /**
26
25
  * Get all controllers mounted on the application.
27
26
  * @returns {RouteController[]}
28
27
  */
29
28
  getMountedControllers(): RouteController[];
30
- protected $onInit(): void;
31
- /**
32
- * Create routers from the collected controllers.
33
- * @private
34
- */
35
- private createRouters;
36
- /**
37
- * Get all router controllers from the controller token.
38
- * @private
39
- */
40
- private getAllControllers;
41
- /**
42
- * Create controllers from DI
43
- * @private
44
- */
45
- private buildControllers;
46
29
  }
@@ -1,9 +1,9 @@
1
1
  import { Type } from "@tsed/core";
2
2
  import { ProviderOpts } from "@tsed/di";
3
+ import { PlatformHandlerMetadata, PlatformLayer } from "@tsed/platform-router";
3
4
  import { PlatformMulter, PlatformMulterSettings } from "../config/interfaces/PlatformMulterSettings";
4
5
  import { PlatformStaticsOptions } from "../config/interfaces/PlatformStaticsSettings";
5
- import { RouterOptions } from "express";
6
- export declare abstract class PlatformAdapter<App = TsED.Application, Router = TsED.Router> {
6
+ export declare abstract class PlatformAdapter<App = TsED.Application> {
7
7
  /**
8
8
  * Load providers in top priority
9
9
  */
@@ -14,16 +14,25 @@ export declare abstract class PlatformAdapter<App = TsED.Application, Router = T
14
14
  onInit?: () => any;
15
15
  beforeLoadRoutes?: () => Promise<any>;
16
16
  afterLoadRoutes?: () => Promise<any>;
17
- useRouter?: () => any;
18
- useContext?: () => any;
17
+ /**
18
+ * create initial context
19
+ */
20
+ abstract useContext: () => any;
21
+ /**
22
+ * Map router layer to the targeted framework
23
+ */
24
+ abstract mapLayers: (layer: PlatformLayer[]) => void;
25
+ /**
26
+ * Map handler to the targeted framework
27
+ */
28
+ abstract mapHandler: (handler: Function, layer: PlatformHandlerMetadata) => Function;
29
+ /**
30
+ * Return the app instance
31
+ */
19
32
  abstract app(): {
20
33
  app: App;
21
34
  callback(): any;
22
35
  };
23
- abstract router(routerOptions?: Partial<RouterOptions>): {
24
- router: Router;
25
- callback(): any;
26
- };
27
36
  /**
28
37
  * Return the statics middlewares
29
38
  * @param endpoint
@@ -42,6 +51,6 @@ export declare abstract class PlatformAdapter<App = TsED.Application, Router = T
42
51
  */
43
52
  abstract bodyParser(type: string, opts?: Record<string, any>): any;
44
53
  }
45
- export interface PlatformBuilderSettings<App = TsED.Application, Router = TsED.Router> extends Partial<TsED.Configuration> {
46
- adapter?: Type<PlatformAdapter<App, Router>>;
54
+ export interface PlatformBuilderSettings<App = TsED.Application> extends Partial<TsED.Configuration> {
55
+ adapter?: Type<PlatformAdapter<App>>;
47
56
  }
@@ -1,5 +1,9 @@
1
- import { PlatformHandler } from "./PlatformHandler";
2
- import { PlatformRouter } from "./PlatformRouter";
1
+ /// <reference types="multer" />
2
+ /// <reference types="node" />
3
+ import { InjectorService } from "@tsed/di";
4
+ import { PlatformRouter } from "@tsed/platform-router";
5
+ import { IncomingMessage, ServerResponse } from "http";
6
+ import { PlatformMulterSettings } from "../config/interfaces/PlatformMulterSettings";
3
7
  import { PlatformAdapter } from "./PlatformAdapter";
4
8
  declare global {
5
9
  namespace TsED {
@@ -12,10 +16,14 @@ declare global {
12
16
  *
13
17
  * @platform
14
18
  */
15
- export declare class PlatformApplication<App = TsED.Application, Router = TsED.Router> extends PlatformRouter<App, Router> {
16
- raw: App;
19
+ export declare class PlatformApplication<App = TsED.Application> extends PlatformRouter {
20
+ adapter: PlatformAdapter<App>;
21
+ injector: InjectorService;
17
22
  rawApp: App;
18
- rawRouter: Router;
19
- constructor(platformHandler: PlatformHandler, adapter: PlatformAdapter<App, Router>);
23
+ rawCallback: () => any;
24
+ constructor(adapter: PlatformAdapter<App>, injector: InjectorService);
20
25
  getApp(): App;
26
+ multer(options: PlatformMulterSettings): import("multer").Multer;
27
+ callback(): (req: IncomingMessage, res: ServerResponse) => any;
28
+ callback(req: IncomingMessage, res: ServerResponse): any;
21
29
  }
@@ -1,80 +1,44 @@
1
- import { InjectorService, Provider } from "@tsed/di";
2
- import { ArgScope, HandlerWithScope, PlatformParams } from "@tsed/platform-params";
1
+ import { Provider } from "@tsed/di";
2
+ import { PlatformParams, PlatformParamsCallback } from "@tsed/platform-params";
3
3
  import { PlatformResponseFilter } from "@tsed/platform-response-filter";
4
- import { EndpointMetadata } from "@tsed/schema";
5
- import { HandlerMetadata } from "../domain/HandlerMetadata";
4
+ import { PlatformContextHandler, PlatformHandlerMetadata, PlatformRouters } from "@tsed/platform-router";
6
5
  import { PlatformContext } from "../domain/PlatformContext";
7
- import { PlatformRouteWithoutHandlers } from "../interfaces/PlatformRouteOptions";
8
- export interface OnRequestOptions {
9
- $ctx: PlatformContext;
10
- metadata: HandlerMetadata;
11
- handler: HandlerWithScope;
12
- next?: any;
13
- err?: any;
14
- [key: string]: any;
15
- }
16
6
  /**
17
7
  * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
18
8
  * @platform
19
9
  */
20
10
  export declare class PlatformHandler {
21
- protected injector: InjectorService;
22
- protected params: PlatformParams;
23
11
  protected responseFilter: PlatformResponseFilter;
24
- constructor(injector: InjectorService, params: PlatformParams);
25
- /**
26
- * Create a native middleware based on the given metadata and return an instance of AnyToPromiseWithCtx
27
- * @param input
28
- * @param options
29
- */
30
- createHandler(input: EndpointMetadata | HandlerMetadata | any, options?: PlatformRouteWithoutHandlers): any;
12
+ protected platformRouters: PlatformRouters;
13
+ protected platformParams: PlatformParams;
14
+ createHandler(handler: PlatformParamsCallback, handlerMetadata: PlatformHandlerMetadata): PlatformContextHandler;
31
15
  /**
32
- * Create injectable handler from the given provider
33
16
  * @param provider
34
17
  * @param propertyKey
35
18
  */
36
- createCustomHandler(provider: Provider, propertyKey: string): ($ctx: PlatformContext, next?: any) => Promise<any>;
19
+ createCustomHandler(provider: Provider, propertyKey: string): ($ctx: PlatformContext) => Promise<any>;
37
20
  /**
38
21
  * Send the response to the consumer.
39
- * @param data
40
- * @param ctx
41
22
  * @protected
23
+ * @param $ctx
42
24
  */
43
- flush(data: any, ctx: PlatformContext): Promise<void>;
44
- compileHandler(metadata: HandlerMetadata): (scope: Record<string, any>) => Promise<any>;
45
- protected onCtxRequest(requestOptions: OnRequestOptions): Promise<any>;
25
+ flush($ctx: PlatformContext): Promise<import("./PlatformResponse").PlatformResponse<any>>;
26
+ setResponseHeaders($ctx: PlatformContext): void;
46
27
  /**
47
- * Call handler when a request his handle
48
- * @param requestOptions
49
- */
50
- protected onRequest(requestOptions: OnRequestOptions): Promise<any>;
51
- protected onError(er: Error, requestOptions: OnRequestOptions): Promise<any>;
52
- /**
53
- * Manage success scenario
54
- * @param data
55
- * @param requestOptions
56
- * @protected
57
- */
58
- protected onSuccess(data: any, requestOptions: OnRequestOptions): Promise<any>;
59
- /**
60
- * Call the returned middleware by the handler.
61
- * @param middleware
62
- * @param ctx
28
+ * @param error
63
29
  * @param next
64
- * @protected
30
+ * @param $ctx
65
31
  */
66
- protected callReturnedMiddleware(middleware: any, ctx: PlatformContext, next: any): any;
32
+ next(error: unknown, next: Function, $ctx: PlatformContext): any;
67
33
  /**
68
- * create Raw handler
69
- * @param metadata
34
+ * Call handler when a request his handle
70
35
  */
71
- protected createRawHandler(metadata: HandlerMetadata): any;
36
+ onRequest(handler: PlatformParamsCallback, $ctx: PlatformContext): Promise<any>;
37
+ protected onError(error: unknown, $ctx: PlatformContext): Promise<void>;
72
38
  /**
73
- * Set response headers
74
- * @param ctx
39
+ * Manage success scenario
40
+ * @param $ctx
75
41
  * @protected
76
42
  */
77
- protected setHeaders(ctx: PlatformContext): void;
78
- protected next(requestOptions: OnRequestOptions): any;
79
- protected getDefaultArgs(metadata: HandlerMetadata): (scope: ArgScope<PlatformContext>) => Promise<any[]>;
43
+ protected onSuccess($ctx: PlatformContext): Promise<any>;
80
44
  }
@@ -1,10 +1,9 @@
1
1
  import { JsonOperationRoute } from "@tsed/schema";
2
- import { ControllerProvider } from "../domain/ControllerProvider";
3
2
  import { PlatformAdapter } from "../services/PlatformAdapter";
4
3
  export declare class PlatformMiddlewaresChain {
5
4
  protected acceptMimes: string[];
6
5
  protected adapter: PlatformAdapter;
7
- get(provider: ControllerProvider, operationRoute: JsonOperationRoute, parentMiddlewares?: any[]): any[];
6
+ get(allMiddlewares: any[], operationRoute: JsonOperationRoute): any[];
8
7
  protected hasAcceptMimes(operationRoute: JsonOperationRoute): number;
9
8
  protected getParamTypes(middlewares: any[], operationRoute: JsonOperationRoute): any;
10
9
  }
@@ -6,10 +6,6 @@ declare global {
6
6
  namespace TsED {
7
7
  interface Request {
8
8
  id: string;
9
- /**
10
- * @deprecated
11
- */
12
- $ctx: PlatformContext;
13
9
  }
14
10
  }
15
11
  }
@@ -74,7 +70,7 @@ export declare class PlatformRequest<Req extends {
74
70
  [key: string]: any;
75
71
  };
76
72
  get files(): any;
77
- get route(): any;
73
+ get route(): import("@tsed/platform-router").SinglePathType;
78
74
  /**
79
75
  * Return the original request framework instance
80
76
  */
@@ -1,14 +1,13 @@
1
1
  /// <reference types="node" />
2
2
  import { OutgoingHttpHeaders, ServerResponse } from "http";
3
- import type { PlatformRequest } from "./PlatformRequest";
4
3
  import type { PlatformContext } from "../domain/PlatformContext";
4
+ import { PlatformRequest } from "./PlatformRequest";
5
5
  declare global {
6
6
  namespace TsED {
7
7
  interface Response {
8
8
  }
9
9
  }
10
10
  }
11
- export declare type HeaderValue = Array<boolean | number | string> | boolean | number | string;
12
11
  /**
13
12
  * Platform Response abstraction layer.
14
13
  * @platform
@@ -40,7 +39,6 @@ export declare class PlatformResponse<Res extends Record<string, any> = any> {
40
39
  * Return the original response node.js instance
41
40
  */
42
41
  get res(): ServerResponse;
43
- static onFinished(res: any, cb: (er: Error | null, message: string) => void): void;
44
42
  /**
45
43
  * Returns the HTTP response header specified by field. The match is case-insensitive.
46
44
  *
@@ -143,7 +141,7 @@ export declare class PlatformResponse<Res extends Record<string, any> = any> {
143
141
  * Send any data to your consumer.
144
142
  *
145
143
  * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
146
- * It choose the better way to send the data.
144
+ * It chooses the better way to send the data.
147
145
  *
148
146
  * @param data
149
147
  */
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { Type } from "@tsed/core";
2
3
  import { DITest, DITestOptions, InjectorService } from "@tsed/di";
3
4
  import { PlatformContext, PlatformContextOptions } from "../domain/PlatformContext";
@@ -51,7 +52,7 @@ export declare class PlatformTest extends DITest {
51
52
  * });
52
53
  * ```
53
54
  */
54
- static callback(): any;
55
+ static callback(): ((req: import("http").IncomingMessage, res: import("http").ServerResponse) => any) | undefined;
55
56
  static createRequest(options?: any): any;
56
57
  static createResponse(options?: any): any;
57
58
  static createRequestContext(options?: Partial<PlatformContextOptions & any>): PlatformContext<import("./PlatformRequest").PlatformRequest<any>, import("./PlatformResponse").PlatformResponse<any>>;
@@ -1,9 +1,9 @@
1
1
  import { InjectorService } from "@tsed/di";
2
2
  import { PlatformContext } from "../domain/PlatformContext";
3
+ import { IncomingEvent } from "../interfaces/IncomingEvent";
3
4
  import { PlatformRequest } from "../services/PlatformRequest";
4
5
  import { PlatformResponse } from "../services/PlatformResponse";
5
- import { IncomingEvent } from "../interfaces/IncomingEvent";
6
- export declare function ignoreLog(ignoreUrlPatterns: any[] | undefined): ((ignore: boolean, data: any, url: string) => any) | undefined;
6
+ export declare function buildIgnoreLog(ignoreUrlPatterns: any[] | undefined): ((ignore: boolean, data: any, url: string) => any) | undefined;
7
7
  /**
8
8
  * Create the TsED context to wrap request, response, injector, etc...
9
9
  * @param injector
@@ -2,7 +2,7 @@ import { Type } from "@tsed/core";
2
2
  import { InjectorService } from "@tsed/di";
3
3
  import { PlatformAdapter } from "../services/PlatformAdapter";
4
4
  interface CreateInjectorOptions {
5
- adapter?: Type<PlatformAdapter<any, any>>;
5
+ adapter?: Type<PlatformAdapter<any>>;
6
6
  settings?: Partial<TsED.Configuration>;
7
7
  }
8
8
  export declare function createInjector({ adapter, settings }: CreateInjectorOptions): InjectorService;
@@ -0,0 +1,2 @@
1
+ import { PlatformContext } from "../domain/PlatformContext";
2
+ export declare function ensureContext(request: any, cb: ($ctx: PlatformContext) => any, fallback?: () => void): any;