@expressots/adapter-express 3.0.0 → 4.0.0-preview.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/README.md +39 -96
- package/lib/CHANGELOG.md +31 -5
- package/lib/README.md +39 -96
- package/lib/cjs/adapter-express/application-express.base.js +3 -1
- package/lib/cjs/adapter-express/application-express.js +1049 -85
- package/lib/cjs/adapter-express/express-utils/conditional-middleware.js +102 -0
- package/lib/cjs/adapter-express/express-utils/constants.js +17 -0
- package/lib/cjs/adapter-express/express-utils/content-negotiation-decorators.js +129 -0
- package/lib/cjs/adapter-express/express-utils/decorators.js +186 -49
- package/lib/cjs/adapter-express/express-utils/exception-filter-decorators.js +11 -0
- package/lib/cjs/adapter-express/express-utils/guard-context-factory.js +84 -0
- package/lib/cjs/adapter-express/express-utils/guard-middleware.js +115 -0
- package/lib/cjs/adapter-express/express-utils/guard-utils.js +18 -0
- package/lib/cjs/adapter-express/express-utils/http-context-store.js +15 -0
- package/lib/cjs/adapter-express/express-utils/http-status-middleware.js +37 -2
- package/lib/cjs/adapter-express/express-utils/index.js +67 -1
- package/lib/cjs/adapter-express/express-utils/interceptor-middleware.js +132 -0
- package/lib/cjs/adapter-express/express-utils/inversify-express-server.js +810 -63
- package/lib/cjs/adapter-express/express-utils/lazy-module-middleware.js +241 -0
- package/lib/cjs/adapter-express/express-utils/middleware-composition.js +95 -0
- package/lib/cjs/adapter-express/express-utils/permission-preloader.middleware.js +48 -0
- package/lib/cjs/adapter-express/express-utils/route-constraints.js +95 -0
- package/lib/cjs/adapter-express/express-utils/scope-extractor.interface.js +2 -0
- package/lib/cjs/adapter-express/express-utils/scope-extractor.js +66 -0
- package/lib/cjs/adapter-express/express-utils/setup-authorization.js +71 -0
- package/lib/cjs/adapter-express/express-utils/setup-event-system.js +113 -0
- package/lib/cjs/adapter-express/express-utils/setup-interceptors.js +103 -0
- package/lib/cjs/adapter-express/express-utils/setup-lazy-loading.js +228 -0
- package/lib/cjs/adapter-express/express-utils/utils.js +30 -12
- package/lib/cjs/adapter-express/express-utils/validation-decorators.js +205 -0
- package/lib/cjs/adapter-express/express-utils/validation-service.js +252 -0
- package/lib/cjs/adapter-express/index.js +7 -5
- package/lib/cjs/adapter-express/micro-api/application-express-micro-route.js +31 -1
- package/lib/cjs/adapter-express/micro-api/application-express-micro.js +11 -37
- package/lib/cjs/adapter-express/micro-api/gateway/circuit-breaker.js +174 -0
- package/lib/cjs/adapter-express/micro-api/gateway/index.js +11 -0
- package/lib/cjs/adapter-express/micro-api/gateway/service-proxy.js +214 -0
- package/lib/cjs/adapter-express/micro-api/index.js +27 -3
- package/lib/cjs/adapter-express/micro-api/micro.js +217 -0
- package/lib/cjs/adapter-express/micro-api/queue/index.js +8 -0
- package/lib/cjs/adapter-express/micro-api/queue/queue.interface.js +2 -0
- package/lib/cjs/adapter-express/micro-api/queue/rabbitmq-consumer.js +255 -0
- package/lib/cjs/adapter-express/micro-api/serverless/aws-lambda.adapter.js +183 -0
- package/lib/cjs/adapter-express/micro-api/serverless/cloudflare.adapter.js +158 -0
- package/lib/cjs/adapter-express/micro-api/serverless/index.js +12 -0
- package/lib/cjs/adapter-express/micro-api/serverless/vercel.adapter.js +102 -0
- package/lib/cjs/adapter-express/micro-api/service-mesh/index.js +10 -0
- package/lib/cjs/adapter-express/micro-api/service-mesh/service-client.js +194 -0
- package/lib/cjs/adapter-express/micro-api/service-mesh/service-discovery.js +261 -0
- package/lib/cjs/adapter-express/middleware/index.js +21 -0
- package/lib/cjs/adapter-express/middleware/request-logging.middleware.js +244 -0
- package/lib/cjs/adapter-express/render/engine.js +15 -15
- package/lib/cjs/adapter-express/render/index.js +5 -0
- package/lib/cjs/adapter-express/studio/index.js +9 -0
- package/lib/cjs/adapter-express/studio/studio-integration.js +214 -0
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/types/adapter-express/application-express.base.d.ts +20 -7
- package/lib/cjs/types/adapter-express/application-express.d.ts +273 -32
- package/lib/cjs/types/adapter-express/express-utils/base-middleware.d.ts +2 -2
- package/lib/cjs/types/adapter-express/express-utils/conditional-middleware.d.ts +97 -0
- package/lib/cjs/types/adapter-express/express-utils/constants.d.ts +13 -0
- package/lib/cjs/types/adapter-express/express-utils/content-negotiation-decorators.d.ts +94 -0
- package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts +54 -6
- package/lib/cjs/types/adapter-express/express-utils/exception-filter-decorators.d.ts +6 -0
- package/lib/cjs/types/adapter-express/express-utils/guard-context-factory.d.ts +17 -0
- package/lib/cjs/types/adapter-express/express-utils/guard-middleware.d.ts +22 -0
- package/lib/cjs/types/adapter-express/express-utils/guard-utils.d.ts +11 -0
- package/lib/cjs/types/adapter-express/express-utils/http-context-store.d.ts +20 -0
- package/lib/cjs/types/adapter-express/express-utils/httpResponseMessage.d.ts +1 -1
- package/lib/cjs/types/adapter-express/express-utils/index.d.ts +30 -2
- package/lib/cjs/types/adapter-express/express-utils/interceptor-middleware.d.ts +40 -0
- package/lib/cjs/types/adapter-express/express-utils/interfaces.d.ts +42 -5
- package/lib/cjs/types/adapter-express/express-utils/inversify-express-server.d.ts +114 -2
- package/lib/cjs/types/adapter-express/express-utils/lazy-module-middleware.d.ts +122 -0
- package/lib/cjs/types/adapter-express/express-utils/middleware-composition.d.ts +85 -0
- package/lib/cjs/types/adapter-express/express-utils/permission-preloader.middleware.d.ts +10 -0
- package/lib/cjs/types/adapter-express/express-utils/route-constraints.d.ts +89 -0
- package/lib/cjs/types/adapter-express/express-utils/scope-extractor.d.ts +21 -0
- package/lib/cjs/types/adapter-express/express-utils/scope-extractor.interface.d.ts +12 -0
- package/lib/cjs/types/adapter-express/express-utils/setup-authorization.d.ts +34 -0
- package/lib/cjs/types/adapter-express/express-utils/setup-event-system.d.ts +118 -0
- package/lib/cjs/types/adapter-express/express-utils/setup-interceptors.d.ts +115 -0
- package/lib/cjs/types/adapter-express/express-utils/setup-lazy-loading.d.ts +123 -0
- package/lib/cjs/types/adapter-express/express-utils/utils.d.ts +17 -2
- package/lib/cjs/types/adapter-express/express-utils/validation-decorators.d.ts +145 -0
- package/lib/cjs/types/adapter-express/express-utils/validation-service.d.ts +88 -0
- package/lib/cjs/types/adapter-express/index.d.ts +6 -4
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro-route.d.ts +25 -14
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro.d.ts +3 -10
- package/lib/cjs/types/adapter-express/micro-api/gateway/circuit-breaker.d.ts +111 -0
- package/lib/cjs/types/adapter-express/micro-api/gateway/index.d.ts +5 -0
- package/lib/cjs/types/adapter-express/micro-api/gateway/service-proxy.d.ts +83 -0
- package/lib/cjs/types/adapter-express/micro-api/index.d.ts +7 -1
- package/lib/cjs/types/adapter-express/micro-api/micro.d.ts +66 -0
- package/lib/cjs/types/adapter-express/micro-api/queue/index.d.ts +5 -0
- package/lib/cjs/types/adapter-express/micro-api/queue/queue.interface.d.ts +60 -0
- package/lib/cjs/types/adapter-express/micro-api/queue/rabbitmq-consumer.d.ts +86 -0
- package/lib/cjs/types/adapter-express/micro-api/serverless/aws-lambda.adapter.d.ts +77 -0
- package/lib/cjs/types/adapter-express/micro-api/serverless/cloudflare.adapter.d.ts +64 -0
- package/lib/cjs/types/adapter-express/micro-api/serverless/index.d.ts +6 -0
- package/lib/cjs/types/adapter-express/micro-api/serverless/vercel.adapter.d.ts +56 -0
- package/lib/cjs/types/adapter-express/micro-api/service-mesh/index.d.ts +5 -0
- package/lib/cjs/types/adapter-express/micro-api/service-mesh/service-client.d.ts +122 -0
- package/lib/cjs/types/adapter-express/micro-api/service-mesh/service-discovery.d.ts +150 -0
- package/lib/cjs/types/adapter-express/middleware/index.d.ts +5 -0
- package/lib/cjs/types/adapter-express/middleware/request-logging.middleware.d.ts +65 -0
- package/lib/cjs/types/adapter-express/render/index.d.ts +1 -0
- package/lib/cjs/types/adapter-express/studio/index.d.ts +1 -0
- package/lib/cjs/types/adapter-express/studio/studio-integration.d.ts +92 -0
- package/lib/cjs/types/index.d.ts +1 -1
- package/lib/esm/adapter-express/application-express.base.js +24 -0
- package/lib/esm/adapter-express/application-express.js +1300 -0
- package/lib/esm/adapter-express/application-express.types.js +1 -0
- package/lib/esm/adapter-express/express-utils/base-middleware.js +19 -0
- package/lib/esm/adapter-express/express-utils/conditional-middleware.js +96 -0
- package/lib/esm/adapter-express/express-utils/constants.js +63 -0
- package/lib/esm/adapter-express/express-utils/content/httpContent.js +6 -0
- package/lib/esm/adapter-express/express-utils/content-negotiation-decorators.js +120 -0
- package/lib/esm/adapter-express/express-utils/decorators.js +575 -0
- package/lib/esm/adapter-express/express-utils/exception-filter-decorators.js +6 -0
- package/lib/esm/adapter-express/express-utils/guard-context-factory.js +83 -0
- package/lib/esm/adapter-express/express-utils/guard-middleware.js +115 -0
- package/lib/esm/adapter-express/express-utils/guard-utils.js +14 -0
- package/lib/esm/adapter-express/express-utils/http-context-store.js +10 -0
- package/lib/esm/adapter-express/express-utils/http-status-middleware.js +116 -0
- package/lib/esm/adapter-express/express-utils/httpResponseMessage.js +29 -0
- package/lib/esm/adapter-express/express-utils/index.js +24 -0
- package/lib/esm/adapter-express/express-utils/interceptor-middleware.js +130 -0
- package/lib/esm/adapter-express/express-utils/interfaces.js +1 -0
- package/lib/esm/adapter-express/express-utils/inversify-express-server.js +1031 -0
- package/lib/esm/adapter-express/express-utils/lazy-module-middleware.js +236 -0
- package/lib/esm/adapter-express/express-utils/middleware-composition.js +89 -0
- package/lib/esm/adapter-express/express-utils/permission-preloader.middleware.js +45 -0
- package/lib/esm/adapter-express/express-utils/resolver-multer.js +30 -0
- package/lib/esm/adapter-express/express-utils/route-constraints.js +91 -0
- package/lib/esm/adapter-express/express-utils/scope-extractor.interface.js +1 -0
- package/lib/esm/adapter-express/express-utils/scope-extractor.js +63 -0
- package/lib/esm/adapter-express/express-utils/setup-authorization.js +68 -0
- package/lib/esm/adapter-express/express-utils/setup-event-system.js +110 -0
- package/lib/esm/adapter-express/express-utils/setup-interceptors.js +100 -0
- package/lib/esm/adapter-express/express-utils/setup-lazy-loading.js +225 -0
- package/lib/esm/adapter-express/express-utils/utils.js +68 -0
- package/lib/esm/adapter-express/express-utils/validation-decorators.js +199 -0
- package/lib/esm/adapter-express/express-utils/validation-service.js +251 -0
- package/lib/esm/adapter-express/index.js +7 -0
- package/lib/esm/adapter-express/micro-api/application-express-micro-container.js +48 -0
- package/lib/esm/adapter-express/micro-api/application-express-micro-route.js +128 -0
- package/lib/esm/adapter-express/micro-api/application-express-micro.js +161 -0
- package/lib/esm/adapter-express/micro-api/gateway/circuit-breaker.js +174 -0
- package/lib/esm/adapter-express/micro-api/gateway/index.js +5 -0
- package/lib/esm/adapter-express/micro-api/gateway/service-proxy.js +210 -0
- package/lib/esm/adapter-express/micro-api/index.js +10 -0
- package/lib/esm/adapter-express/micro-api/micro.js +211 -0
- package/lib/esm/adapter-express/micro-api/queue/index.js +4 -0
- package/lib/esm/adapter-express/micro-api/queue/queue.interface.js +1 -0
- package/lib/esm/adapter-express/micro-api/queue/rabbitmq-consumer.js +229 -0
- package/lib/esm/adapter-express/micro-api/serverless/aws-lambda.adapter.js +180 -0
- package/lib/esm/adapter-express/micro-api/serverless/cloudflare.adapter.js +155 -0
- package/lib/esm/adapter-express/micro-api/serverless/index.js +6 -0
- package/lib/esm/adapter-express/micro-api/serverless/vercel.adapter.js +99 -0
- package/lib/esm/adapter-express/micro-api/service-mesh/index.js +5 -0
- package/lib/esm/adapter-express/micro-api/service-mesh/service-client.js +191 -0
- package/lib/esm/adapter-express/micro-api/service-mesh/service-discovery.js +259 -0
- package/lib/esm/adapter-express/middleware/index.js +5 -0
- package/lib/esm/adapter-express/middleware/request-logging.middleware.js +239 -0
- package/lib/esm/adapter-express/render/constants.js +37 -0
- package/lib/esm/adapter-express/render/engine.js +51 -0
- package/lib/esm/adapter-express/render/index.js +1 -0
- package/lib/esm/adapter-express/render/resolve-render.js +30 -0
- package/lib/esm/adapter-express/studio/index.js +1 -0
- package/lib/esm/adapter-express/studio/studio-integration.js +184 -0
- package/lib/esm/index.mjs +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/types/adapter-express/application-express.base.d.ts +77 -0
- package/lib/esm/types/adapter-express/application-express.d.ts +411 -0
- package/lib/esm/types/adapter-express/application-express.types.d.ts +23 -0
- package/lib/esm/types/adapter-express/express-utils/base-middleware.d.ts +8 -0
- package/lib/esm/types/adapter-express/express-utils/conditional-middleware.d.ts +97 -0
- package/lib/esm/types/adapter-express/express-utils/constants.d.ts +57 -0
- package/lib/esm/types/adapter-express/express-utils/content/httpContent.d.ts +6 -0
- package/lib/esm/types/adapter-express/express-utils/content-negotiation-decorators.d.ts +94 -0
- package/lib/esm/types/adapter-express/express-utils/decorators.d.ts +257 -0
- package/lib/esm/types/adapter-express/express-utils/exception-filter-decorators.d.ts +6 -0
- package/lib/esm/types/adapter-express/express-utils/guard-context-factory.d.ts +17 -0
- package/lib/esm/types/adapter-express/express-utils/guard-middleware.d.ts +22 -0
- package/lib/esm/types/adapter-express/express-utils/guard-utils.d.ts +11 -0
- package/lib/esm/types/adapter-express/express-utils/http-context-store.d.ts +20 -0
- package/lib/esm/types/adapter-express/express-utils/http-status-middleware.d.ts +26 -0
- package/lib/esm/types/adapter-express/express-utils/httpResponseMessage.d.ts +14 -0
- package/lib/esm/types/adapter-express/express-utils/index.d.ts +30 -0
- package/lib/esm/types/adapter-express/express-utils/interceptor-middleware.d.ts +40 -0
- package/lib/esm/types/adapter-express/express-utils/interfaces.d.ts +115 -0
- package/lib/esm/types/adapter-express/express-utils/inversify-express-server.d.ts +172 -0
- package/lib/esm/types/adapter-express/express-utils/lazy-module-middleware.d.ts +122 -0
- package/lib/esm/types/adapter-express/express-utils/middleware-composition.d.ts +85 -0
- package/lib/esm/types/adapter-express/express-utils/permission-preloader.middleware.d.ts +10 -0
- package/lib/esm/types/adapter-express/express-utils/resolver-multer.d.ts +7 -0
- package/lib/esm/types/adapter-express/express-utils/route-constraints.d.ts +89 -0
- package/lib/esm/types/adapter-express/express-utils/scope-extractor.d.ts +21 -0
- package/lib/esm/types/adapter-express/express-utils/scope-extractor.interface.d.ts +12 -0
- package/lib/esm/types/adapter-express/express-utils/setup-authorization.d.ts +34 -0
- package/lib/esm/types/adapter-express/express-utils/setup-event-system.d.ts +118 -0
- package/lib/esm/types/adapter-express/express-utils/setup-interceptors.d.ts +115 -0
- package/lib/esm/types/adapter-express/express-utils/setup-lazy-loading.d.ts +123 -0
- package/lib/esm/types/adapter-express/express-utils/utils.d.ts +24 -0
- package/lib/esm/types/adapter-express/express-utils/validation-decorators.d.ts +145 -0
- package/lib/esm/types/adapter-express/express-utils/validation-service.d.ts +88 -0
- package/lib/esm/types/adapter-express/index.d.ts +7 -0
- package/lib/esm/types/adapter-express/micro-api/application-express-micro-container.d.ts +47 -0
- package/lib/esm/types/adapter-express/micro-api/application-express-micro-route.d.ts +104 -0
- package/lib/esm/types/adapter-express/micro-api/application-express-micro.d.ts +72 -0
- package/lib/esm/types/adapter-express/micro-api/gateway/circuit-breaker.d.ts +111 -0
- package/lib/esm/types/adapter-express/micro-api/gateway/index.d.ts +5 -0
- package/lib/esm/types/adapter-express/micro-api/gateway/service-proxy.d.ts +83 -0
- package/lib/esm/types/adapter-express/micro-api/index.d.ts +7 -0
- package/lib/esm/types/adapter-express/micro-api/micro.d.ts +66 -0
- package/lib/esm/types/adapter-express/micro-api/queue/index.d.ts +5 -0
- package/lib/esm/types/adapter-express/micro-api/queue/queue.interface.d.ts +60 -0
- package/lib/esm/types/adapter-express/micro-api/queue/rabbitmq-consumer.d.ts +86 -0
- package/lib/esm/types/adapter-express/micro-api/serverless/aws-lambda.adapter.d.ts +77 -0
- package/lib/esm/types/adapter-express/micro-api/serverless/cloudflare.adapter.d.ts +64 -0
- package/lib/esm/types/adapter-express/micro-api/serverless/index.d.ts +6 -0
- package/lib/esm/types/adapter-express/micro-api/serverless/vercel.adapter.d.ts +56 -0
- package/lib/esm/types/adapter-express/micro-api/service-mesh/index.d.ts +5 -0
- package/lib/esm/types/adapter-express/micro-api/service-mesh/service-client.d.ts +122 -0
- package/lib/esm/types/adapter-express/micro-api/service-mesh/service-discovery.d.ts +150 -0
- package/lib/esm/types/adapter-express/middleware/index.d.ts +5 -0
- package/lib/esm/types/adapter-express/middleware/request-logging.middleware.d.ts +65 -0
- package/lib/esm/types/adapter-express/render/constants.d.ts +26 -0
- package/lib/esm/types/adapter-express/render/engine.d.ts +20 -0
- package/lib/esm/types/adapter-express/render/index.d.ts +5 -0
- package/lib/esm/types/adapter-express/render/resolve-render.d.ts +7 -0
- package/lib/esm/types/adapter-express/studio/index.d.ts +1 -0
- package/lib/esm/types/adapter-express/studio/studio-integration.d.ts +92 -0
- package/lib/esm/types/index.d.ts +1 -0
- package/lib/package.json +156 -146
- package/package.json +156 -146
- package/lib/cjs/di/di.interfaces.js +0 -10
- package/lib/cjs/types/di/di.interfaces.d.ts +0 -289
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Server as HTTPServer } from "http";
|
|
2
|
-
import { AppContainer, IConsoleMessage, IMiddleware, ProviderManager } from "@expressots/core";
|
|
3
|
-
import {
|
|
4
|
-
import { interfaces } from "
|
|
2
|
+
import { AppContainer, IConsoleMessage, IMiddleware, ProviderManager, BannerConfig } from "@expressots/core";
|
|
3
|
+
import { IWebServerPublic, RenderEngine, Server } from "@expressots/shared";
|
|
4
|
+
import { interfaces } from "@expressots/core";
|
|
5
5
|
/**
|
|
6
6
|
* The AppExpress class provides methods for configuring and running an Express application.
|
|
7
7
|
* @class AppExpress
|
|
@@ -26,53 +26,142 @@ export declare class AppExpress implements Server.IWebServer {
|
|
|
26
26
|
private middlewares;
|
|
27
27
|
private providerManager;
|
|
28
28
|
private renderOptions;
|
|
29
|
+
private lifecycleRegistry;
|
|
30
|
+
private isShuttingDown;
|
|
31
|
+
private bannerGenerator;
|
|
32
|
+
private bannerConfig;
|
|
33
|
+
private shutdownHandlers;
|
|
34
|
+
private studioConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Latest snapshot of application metrics produced by `MetricsCollector`
|
|
37
|
+
* during banner display. We cache it so that `reportStudioRuntimeInfo`
|
|
38
|
+
* can forward the *runtime* provider/interceptor counts (which match
|
|
39
|
+
* what the CLI banner shows) to the Studio Agent without recomputing.
|
|
40
|
+
*/
|
|
41
|
+
private lastApplicationMetrics;
|
|
42
|
+
/** Track active connections for force-close during shutdown */
|
|
43
|
+
private activeConnections;
|
|
44
|
+
/** Timeout for force-closing connections during shutdown (ms) */
|
|
45
|
+
private shutdownTimeout;
|
|
46
|
+
/** Number of retries when port is in use (for hot-reload scenarios) */
|
|
47
|
+
private portRetryAttempts;
|
|
48
|
+
/** Delay between port retry attempts (ms) */
|
|
49
|
+
private portRetryDelay;
|
|
50
|
+
private static originalStdoutWrite;
|
|
51
|
+
private static originalStderrWrite;
|
|
52
|
+
private static logBuffer;
|
|
53
|
+
private static isBuffering;
|
|
54
|
+
private static bufferingInitialized;
|
|
55
|
+
private static originalGlobalConsole;
|
|
56
|
+
private static initBuffering;
|
|
57
|
+
/**
|
|
58
|
+
* Disable log buffering. Called by micro() to restore normal console output
|
|
59
|
+
* since micro API doesn't use the banner system.
|
|
60
|
+
* @public API
|
|
61
|
+
*/
|
|
62
|
+
static disableBuffering(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Start buffering all console output.
|
|
65
|
+
* This captures both console.log and direct process.stdout.write calls.
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
private static startLogBuffering;
|
|
69
|
+
/**
|
|
70
|
+
* Stop buffering but keep the buffered logs for later flushing.
|
|
71
|
+
* This restores normal console/stdout output.
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
private static stopBuffering;
|
|
75
|
+
/**
|
|
76
|
+
* Flush all buffered logs to stdout.
|
|
77
|
+
* Should be called after stopBuffering() and after displaying the banner.
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
private static flushBufferedLogs;
|
|
29
81
|
constructor();
|
|
82
|
+
/**
|
|
83
|
+
* Helper function to handle both sync and async method calls.
|
|
84
|
+
* If the result is a Promise, awaits it; otherwise returns immediately.
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
private handleSyncOrAsync;
|
|
30
88
|
/**
|
|
31
89
|
* Implement this method to set up global configurations for the server.
|
|
32
|
-
* This method is called before any other
|
|
33
|
-
* Use this method to configure global settings
|
|
34
|
-
*
|
|
90
|
+
* This method is called synchronously in the constructor before any other
|
|
91
|
+
* server initialization methods. Use this method to configure global settings
|
|
92
|
+
* that apply to the entire server application.
|
|
93
|
+
*
|
|
94
|
+
* Note: This method is synchronous and called during object construction.
|
|
95
|
+
* For asynchronous initialization, use `configureServices()` instead.
|
|
35
96
|
*
|
|
36
97
|
* @abstract
|
|
37
|
-
* @returns {void
|
|
98
|
+
* @returns {void}
|
|
38
99
|
* @public API
|
|
39
100
|
*/
|
|
40
|
-
protected globalConfiguration():
|
|
101
|
+
protected globalConfiguration(): void;
|
|
41
102
|
/**
|
|
42
103
|
* Implement this method to set up required services or configurations before
|
|
43
104
|
* the server starts. This is essential for initializing dependencies or settings
|
|
44
|
-
* necessary for server operation. Supports
|
|
105
|
+
* necessary for server operation. Supports both synchronous and asynchronous setup.
|
|
45
106
|
*
|
|
46
107
|
* @abstract
|
|
47
108
|
* @returns {void | Promise<void>}
|
|
48
109
|
* @public API
|
|
49
110
|
*/
|
|
50
|
-
protected configureServices(): Promise<void>;
|
|
111
|
+
protected configureServices(): void | Promise<void>;
|
|
51
112
|
/**
|
|
52
113
|
* Implement this method to execute actions or configurations after the server
|
|
53
114
|
* has started. Use this for operations that need to run once the server is
|
|
54
|
-
* operational. Supports
|
|
115
|
+
* operational. Supports both synchronous and asynchronous execution.
|
|
55
116
|
*
|
|
56
117
|
* @abstract
|
|
57
118
|
* @returns {void | Promise<void>}
|
|
58
119
|
* @public API
|
|
59
120
|
*/
|
|
60
|
-
protected postServerInitialization(): Promise<void>;
|
|
121
|
+
protected postServerInitialization(): void | Promise<void>;
|
|
61
122
|
/**
|
|
62
123
|
* Implement this method to handle cleanup and final actions when the server
|
|
63
124
|
* is shutting down. Ideal for closing resources, stopping tasks, or other
|
|
64
|
-
* cleanup procedures to ensure a graceful server shutdown. Supports
|
|
65
|
-
*
|
|
125
|
+
* cleanup procedures to ensure a graceful server shutdown. Supports both
|
|
126
|
+
* synchronous and asynchronous cleanup.
|
|
127
|
+
*
|
|
128
|
+
* The signal parameter indicates what triggered the shutdown:
|
|
129
|
+
* - SIGTERM: Graceful termination (e.g., Kubernetes pod shutdown)
|
|
130
|
+
* - SIGINT: User interrupt (e.g., Ctrl+C)
|
|
131
|
+
* - SIGHUP: Terminal hangup
|
|
132
|
+
* - SIGQUIT: Quit with core dump
|
|
133
|
+
* - SIGBREAK: Windows break signal
|
|
66
134
|
*
|
|
67
135
|
* @abstract
|
|
136
|
+
* @param signal - The signal that triggered the shutdown (optional for backward compatibility)
|
|
68
137
|
* @returns {void | Promise<void>}
|
|
69
138
|
* @public API
|
|
70
139
|
*/
|
|
71
|
-
protected serverShutdown(): Promise<void>;
|
|
140
|
+
protected serverShutdown(signal?: NodeJS.Signals): void | Promise<void>;
|
|
72
141
|
/**
|
|
73
|
-
*
|
|
142
|
+
* Performs graceful shutdown of the application.
|
|
143
|
+
*
|
|
144
|
+
* Shutdown sequence:
|
|
145
|
+
* 1. Execute lifecycle shutdown hooks on all IShutdown providers
|
|
146
|
+
* 2. Call user's serverShutdown hook
|
|
147
|
+
* 3. Close the HTTP server to stop accepting new connections
|
|
148
|
+
*
|
|
149
|
+
* @param signal - The signal that triggered the shutdown
|
|
150
|
+
* @returns Promise that resolves when shutdown is complete
|
|
151
|
+
* @internal
|
|
74
152
|
*/
|
|
75
153
|
private handleExit;
|
|
154
|
+
/**
|
|
155
|
+
* Destroy all active connections immediately.
|
|
156
|
+
* Used during forced shutdown.
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
private destroyAllConnections;
|
|
160
|
+
/**
|
|
161
|
+
* Track a new connection for shutdown management.
|
|
162
|
+
* @private
|
|
163
|
+
*/
|
|
164
|
+
private trackConnection;
|
|
76
165
|
/**
|
|
77
166
|
* Initialize the InversifyJS container with the provided modules and options.
|
|
78
167
|
* @param appModules - An array of application modules to be loaded into the container.
|
|
@@ -85,6 +174,11 @@ export declare class AppExpress implements Server.IWebServer {
|
|
|
85
174
|
* @public API
|
|
86
175
|
*/
|
|
87
176
|
configContainer(appModules: Array<interfaces.ContainerModule>, containerOptions?: interfaces.ContainerOptions): AppContainer;
|
|
177
|
+
/**
|
|
178
|
+
* Creates a middleware wrapper that automatically injects container when exception filters are enabled
|
|
179
|
+
* This allows users to simply set enableExceptionFilters: true without manually passing the container
|
|
180
|
+
*/
|
|
181
|
+
private createMiddlewareWrapper;
|
|
88
182
|
/**
|
|
89
183
|
* Get the ProviderManager instance.
|
|
90
184
|
* @returns The ProviderManager instance.
|
|
@@ -117,6 +211,37 @@ export declare class AppExpress implements Server.IWebServer {
|
|
|
117
211
|
* @public API
|
|
118
212
|
*/
|
|
119
213
|
listen(port: number | string, appInfo?: IConsoleMessage): Promise<IWebServerPublic>;
|
|
214
|
+
/**
|
|
215
|
+
* Close existing server instance if it exists.
|
|
216
|
+
* @private
|
|
217
|
+
*/
|
|
218
|
+
private closeExistingServer;
|
|
219
|
+
/**
|
|
220
|
+
* Wait for a specified duration.
|
|
221
|
+
* @private
|
|
222
|
+
*/
|
|
223
|
+
private delay;
|
|
224
|
+
/**
|
|
225
|
+
* Kill the process using a specific port.
|
|
226
|
+
* @private
|
|
227
|
+
*/
|
|
228
|
+
private killProcessOnPort;
|
|
229
|
+
/**
|
|
230
|
+
* Check if the port is available by attempting to bind to it.
|
|
231
|
+
* @private
|
|
232
|
+
*/
|
|
233
|
+
private isPortAvailable;
|
|
234
|
+
/**
|
|
235
|
+
* Ensure the port is available, killing the existing process if needed.
|
|
236
|
+
* This is the safest approach for hot-reload scenarios.
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
private ensurePortAvailable;
|
|
240
|
+
/**
|
|
241
|
+
* Remove existing shutdown signal handlers to prevent duplicates.
|
|
242
|
+
* @private
|
|
243
|
+
*/
|
|
244
|
+
private removeShutdownHandlers;
|
|
120
245
|
/**
|
|
121
246
|
* Sets the global route prefix for the application.
|
|
122
247
|
* @method setGlobalRoutePrefix
|
|
@@ -137,34 +262,150 @@ export declare class AppExpress implements Server.IWebServer {
|
|
|
137
262
|
* @param {EngineOptions} [options] - The configuration options for the view engine
|
|
138
263
|
* @public API
|
|
139
264
|
*/
|
|
140
|
-
setEngine<T extends RenderEngine.EngineOptions>(engine: RenderEngine.Engine, options?: T): Promise<void>;
|
|
141
265
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
266
|
+
* Configure the startup banner display.
|
|
267
|
+
* Can be called in configureServices() or globalConfiguration().
|
|
268
|
+
*
|
|
269
|
+
* @param config - Banner configuration options
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* export class App extends AppExpress {
|
|
273
|
+
* configureServices(): void {
|
|
274
|
+
* this.setBanner({
|
|
275
|
+
* style: "full",
|
|
276
|
+
* showMetrics: true,
|
|
277
|
+
* showFeatures: true,
|
|
278
|
+
* showConfig: true,
|
|
279
|
+
* showPerformance: true,
|
|
280
|
+
* showResources: true,
|
|
281
|
+
* // Environment-specific overrides
|
|
282
|
+
* environment: {
|
|
283
|
+
* production: {
|
|
284
|
+
* style: "compact",
|
|
285
|
+
* showConfig: false,
|
|
286
|
+
* showResources: false,
|
|
287
|
+
* },
|
|
288
|
+
* },
|
|
289
|
+
* });
|
|
290
|
+
* }
|
|
291
|
+
* }
|
|
292
|
+
* ```
|
|
144
293
|
* @public API
|
|
145
294
|
*/
|
|
146
|
-
|
|
295
|
+
setBanner(config: BannerConfig): void;
|
|
147
296
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
297
|
+
* Configure ExpressoTS Studio integration.
|
|
298
|
+
* When enabled and @expressots/studio-agent is installed, automatically
|
|
299
|
+
* instruments the application for request recording and real-time monitoring.
|
|
300
|
+
*
|
|
301
|
+
* By default, Studio is auto-enabled in development if the package is installed.
|
|
302
|
+
* Use this method to customize behavior or enable in production.
|
|
303
|
+
*
|
|
304
|
+
* @param config - Studio configuration options
|
|
152
305
|
* @example
|
|
153
306
|
* ```typescript
|
|
154
|
-
* {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
307
|
+
* export class App extends AppExpress {
|
|
308
|
+
* configureServices(): void {
|
|
309
|
+
* this.setStudio({
|
|
310
|
+
* enabled: true, // Force enable (default: auto in dev)
|
|
311
|
+
* port: 3334, // WebSocket port for UI connection
|
|
312
|
+
* serviceName: 'my-app', // Service name for tracing
|
|
313
|
+
* });
|
|
314
|
+
* }
|
|
315
|
+
* }
|
|
316
|
+
* ```
|
|
317
|
+
* @public API
|
|
318
|
+
*/
|
|
319
|
+
setStudio(config: {
|
|
320
|
+
enabled?: boolean;
|
|
321
|
+
port?: number;
|
|
322
|
+
dbPath?: string;
|
|
323
|
+
serviceName?: string;
|
|
324
|
+
}): void;
|
|
325
|
+
/**
|
|
326
|
+
* Check if ExpressoTS Studio is currently enabled.
|
|
327
|
+
* @returns Boolean indicating if Studio Agent is running.
|
|
328
|
+
* @public API
|
|
329
|
+
*/
|
|
330
|
+
isStudioEnabled(): boolean;
|
|
331
|
+
/**
|
|
332
|
+
* Configure a view engine for server-side rendering.
|
|
333
|
+
*
|
|
334
|
+
* @deprecated Use `this.Middleware.render()` instead. Will be removed in v5.0.0.
|
|
335
|
+
*
|
|
336
|
+
* @example Migration
|
|
337
|
+
* ```typescript
|
|
338
|
+
* // Before (deprecated)
|
|
339
|
+
* this.setEngine(RenderEngine.Engine.EJS, { viewsDir: 'views' });
|
|
340
|
+
*
|
|
341
|
+
* // After (recommended)
|
|
342
|
+
* this.Middleware.render({ engine: 'ejs', viewsDir: 'views' });
|
|
343
|
+
*
|
|
344
|
+
* // Or with auto-detection
|
|
345
|
+
* this.Middleware.render();
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* @param engine - The view engine to set
|
|
349
|
+
* @param options - The configuration options for the view engine
|
|
161
350
|
* @public API
|
|
162
351
|
*/
|
|
163
|
-
|
|
352
|
+
setEngine<T extends RenderEngine.EngineOptions>(engine: RenderEngine.Engine, options?: T): Promise<void>;
|
|
353
|
+
/**
|
|
354
|
+
* Verifies if the current environment is development.
|
|
355
|
+
* @returns A boolean value indicating whether the current environment is development or not.
|
|
356
|
+
* @public API
|
|
357
|
+
*/
|
|
358
|
+
isDevelopment(): Promise<boolean>;
|
|
164
359
|
/**
|
|
165
360
|
* Get the underlying HTTP server. (default: Express.js)
|
|
166
361
|
* @returns The underlying HTTP server after initialization.
|
|
167
362
|
* @public API
|
|
168
363
|
*/
|
|
169
364
|
getHttpServer(): Promise<HTTPServer>;
|
|
365
|
+
/**
|
|
366
|
+
* Get the port the server is listening on.
|
|
367
|
+
* Useful for dynamic port assignment (port: 0) in testing scenarios.
|
|
368
|
+
* @returns The actual port number the server is bound to.
|
|
369
|
+
* @public API
|
|
370
|
+
*/
|
|
371
|
+
getPort(): Promise<number>;
|
|
372
|
+
/**
|
|
373
|
+
* Detect API versions from @Version() decorators on controllers.
|
|
374
|
+
* @returns Array of unique API versions (e.g., ["v1", "v2"])
|
|
375
|
+
* @private
|
|
376
|
+
*/
|
|
377
|
+
private detectApiVersions;
|
|
378
|
+
/**
|
|
379
|
+
* Harvest provider + interceptor *names* from DI metadata so the
|
|
380
|
+
* Studio Status page can drill down into the items behind the
|
|
381
|
+
* "Providers" / "Interceptors" counters.
|
|
382
|
+
*
|
|
383
|
+
* Reads the same metadata that {@link MetricsCollector} uses for the
|
|
384
|
+
* CLI banner — so what shows up here is the source of truth, not the
|
|
385
|
+
* agent's static file scan (which can't see framework-registered
|
|
386
|
+
* items like `Logger` or `LifecycleRegistry`).
|
|
387
|
+
*
|
|
388
|
+
* Returns `undefined` instead of an empty object so {@link
|
|
389
|
+
* reportStudioRuntimeInfo} can skip forwarding when nothing was
|
|
390
|
+
* harvested (keeps the WS payload small).
|
|
391
|
+
*/
|
|
392
|
+
private collectStudioRuntimeItems;
|
|
393
|
+
/**
|
|
394
|
+
* Display middleware startup logs after the banner.
|
|
395
|
+
* This makes startup logging transparent to the user - no need for manual code in postServerInitialization().
|
|
396
|
+
* @private
|
|
397
|
+
*/
|
|
398
|
+
private displayMiddlewareStartupLogs;
|
|
399
|
+
/**
|
|
400
|
+
* Display startup banner with application metrics.
|
|
401
|
+
* @param appInfo - Application info
|
|
402
|
+
* @private
|
|
403
|
+
*/
|
|
404
|
+
private displayStartupBanner;
|
|
405
|
+
/**
|
|
406
|
+
* Display CI detection logs after the banner but before middleware logs.
|
|
407
|
+
* @param appInfo - Application info containing CI detection data
|
|
408
|
+
* @private
|
|
409
|
+
*/
|
|
410
|
+
private displayCIDetectionLogs;
|
|
170
411
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from "express";
|
|
2
|
-
import { interfaces as inversifyInterfaces } from "
|
|
3
|
-
import type { HttpContext } from "./interfaces";
|
|
2
|
+
import { interfaces as inversifyInterfaces } from "@expressots/core";
|
|
3
|
+
import type { HttpContext } from "./interfaces.js";
|
|
4
4
|
export declare abstract class BaseMiddleware implements BaseMiddleware {
|
|
5
5
|
httpContext: HttpContext;
|
|
6
6
|
protected bind<T>(serviceIdentifier: inversifyInterfaces.ServiceIdentifier<T>): inversifyInterfaces.BindingToSyntax<T>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Request } from "express";
|
|
2
|
+
import type { Middleware, MiddlewareClass } from "./interfaces.js";
|
|
3
|
+
/**
|
|
4
|
+
* Type definition for middleware condition functions.
|
|
5
|
+
* Can be synchronous (returns boolean) or asynchronous (returns Promise<boolean>).
|
|
6
|
+
*/
|
|
7
|
+
export type MiddlewareCondition = (req: Request) => boolean | Promise<boolean>;
|
|
8
|
+
/**
|
|
9
|
+
* Configuration object for conditional middleware execution.
|
|
10
|
+
* When the condition evaluates to true, the middleware is executed.
|
|
11
|
+
* When false, the middleware is skipped and next() is called.
|
|
12
|
+
*/
|
|
13
|
+
export interface ConditionalMiddlewareConfig {
|
|
14
|
+
/**
|
|
15
|
+
* The condition function that determines whether the middleware should execute.
|
|
16
|
+
* Receives the Express Request object and returns a boolean or Promise<boolean>.
|
|
17
|
+
*/
|
|
18
|
+
condition: MiddlewareCondition;
|
|
19
|
+
/**
|
|
20
|
+
* The middleware to execute when the condition is true.
|
|
21
|
+
* Can be any valid ExpressoTS middleware type (function, class instance, or container-bound).
|
|
22
|
+
*/
|
|
23
|
+
middleware: Middleware;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to skip middleware execution when condition is false.
|
|
26
|
+
* Default: true (skip if condition is false, execute if true)
|
|
27
|
+
* If false, the behavior is inverted (execute if condition is false).
|
|
28
|
+
*/
|
|
29
|
+
skipOnFalse?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Symbol to identify conditional middleware configuration objects.
|
|
33
|
+
* Used internally for type checking.
|
|
34
|
+
*/
|
|
35
|
+
export declare const CONDITIONAL_MIDDLEWARE_SYMBOL: unique symbol;
|
|
36
|
+
/**
|
|
37
|
+
* Type guard to check if an object is a ConditionalMiddlewareConfig.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isConditionalMiddleware(item: unknown): item is ConditionalMiddlewareConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a conditional middleware configuration that executes the middleware
|
|
42
|
+
* when the condition evaluates to true.
|
|
43
|
+
*
|
|
44
|
+
* @param condition - Function that receives the Request and returns boolean or Promise<boolean>
|
|
45
|
+
* @param middleware - The middleware to execute when condition is true
|
|
46
|
+
* @returns ConditionalMiddlewareConfig object
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Phase 2: Class reference support - no 'new' keyword needed
|
|
51
|
+
* @Get("/admin",
|
|
52
|
+
* when(req => req.hostname.startsWith("admin."), AdminMiddleware),
|
|
53
|
+
* AuthMiddleware
|
|
54
|
+
* )
|
|
55
|
+
* async adminHandler() {}
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Async condition with class reference (Phase 2)
|
|
61
|
+
* @Get("/api",
|
|
62
|
+
* when(async req => {
|
|
63
|
+
* const user = await getUser(req);
|
|
64
|
+
* return user.isAdmin;
|
|
65
|
+
* }, AdminMiddleware)
|
|
66
|
+
* )
|
|
67
|
+
* async apiHandler() {}
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function when(condition: MiddlewareCondition, middleware: Middleware | MiddlewareClass | any): ConditionalMiddlewareConfig;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a conditional middleware configuration that executes the middleware
|
|
73
|
+
* when the condition evaluates to false (inverse of `when`).
|
|
74
|
+
*
|
|
75
|
+
* @param condition - Function that receives the Request and returns boolean or Promise<boolean>
|
|
76
|
+
* @param middleware - The middleware to execute when condition is false
|
|
77
|
+
* @returns ConditionalMiddlewareConfig object
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Phase 2: Class reference support - no 'new' keyword needed
|
|
82
|
+
* @Get("/public",
|
|
83
|
+
* unless(req => req.headers.authorization, AuthMiddleware)
|
|
84
|
+
* )
|
|
85
|
+
* async publicHandler() {}
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* // Skip authentication for public routes (Phase 2: class reference)
|
|
91
|
+
* @Get("/health",
|
|
92
|
+
* unless(req => req.path.startsWith("/api"), AuthMiddleware)
|
|
93
|
+
* )
|
|
94
|
+
* async healthCheck() {}
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function unless(condition: MiddlewareCondition, middleware: Middleware | MiddlewareClass | any): ConditionalMiddlewareConfig;
|
|
@@ -8,6 +8,19 @@ export declare const METADATA_KEY: {
|
|
|
8
8
|
controllerMethod: string;
|
|
9
9
|
controllerParameter: string;
|
|
10
10
|
httpContext: string;
|
|
11
|
+
version: string;
|
|
12
|
+
accept: string;
|
|
13
|
+
consumes: string;
|
|
14
|
+
produces: string;
|
|
15
|
+
csvOptions: string;
|
|
16
|
+
xmlOptions: string;
|
|
17
|
+
yamlOptions: string;
|
|
18
|
+
streamResponse: string;
|
|
19
|
+
validationSchema: string;
|
|
20
|
+
validationOptions: string;
|
|
21
|
+
exceptionFilter: string;
|
|
22
|
+
controllerExceptionFilters: string;
|
|
23
|
+
methodExceptionFilters: string;
|
|
11
24
|
};
|
|
12
25
|
export declare const HTTP_CODE_METADATA: {
|
|
13
26
|
httpCode: string;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import type { CsvFormatOptions, XmlFormatOptions, YamlFormatOptions } from "@expressots/core";
|
|
3
|
+
/**
|
|
4
|
+
* Accept decorator to specify which content types this route accepts for responses.
|
|
5
|
+
* Used for content negotiation based on Accept header.
|
|
6
|
+
* @param contentTypes - Array of accepted content types (e.g., ["application/json", "application/xml"])
|
|
7
|
+
* @returns MethodDecorator
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Accept("application/json", "application/xml")
|
|
11
|
+
* @Get("/users")
|
|
12
|
+
* getUsers() {
|
|
13
|
+
* return [{ id: 1, name: "John" }];
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
* @public API
|
|
17
|
+
*/
|
|
18
|
+
export declare function Accept(...contentTypes: Array<string>): MethodDecorator;
|
|
19
|
+
/**
|
|
20
|
+
* Consumes decorator to specify which content types this route consumes for requests.
|
|
21
|
+
* Used for content negotiation based on Content-Type header.
|
|
22
|
+
* @param contentTypes - Array of consumed content types (e.g., ["application/json", "application/xml"])
|
|
23
|
+
* @returns MethodDecorator
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* @Consumes("application/json", "application/xml")
|
|
27
|
+
* @Post("/users")
|
|
28
|
+
* createUser(@body() user: UserDto) {
|
|
29
|
+
* return this.userService.create(user);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
* @public API
|
|
33
|
+
*/
|
|
34
|
+
export declare function Consumes(...contentTypes: Array<string>): MethodDecorator;
|
|
35
|
+
/**
|
|
36
|
+
* Produces decorator to specify which content types this route produces for responses.
|
|
37
|
+
* Alias for @Accept() decorator.
|
|
38
|
+
* @param contentTypes - Array of produced content types
|
|
39
|
+
* @returns MethodDecorator
|
|
40
|
+
* @public API
|
|
41
|
+
*/
|
|
42
|
+
export declare function Produces(...contentTypes: Array<string>): MethodDecorator;
|
|
43
|
+
/**
|
|
44
|
+
* CsvOptions decorator to configure CSV formatting options for a route.
|
|
45
|
+
* @param options - CSV formatting options
|
|
46
|
+
* @returns MethodDecorator
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* @CsvOptions({ fields: ["id", "name"], includeHeaders: true })
|
|
50
|
+
* @Get("/users")
|
|
51
|
+
* getUsers() {
|
|
52
|
+
* return [{ id: 1, name: "John", email: "john@example.com" }];
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
* @public API
|
|
56
|
+
*/
|
|
57
|
+
export declare function CsvOptions(options: CsvFormatOptions): MethodDecorator;
|
|
58
|
+
/**
|
|
59
|
+
* XmlOptions decorator to configure XML formatting options for a route.
|
|
60
|
+
* @param options - XML formatting options
|
|
61
|
+
* @returns MethodDecorator
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* @XmlOptions({ rootElement: "users", itemElement: "user", prettyPrint: true })
|
|
65
|
+
* @Get("/users")
|
|
66
|
+
* getUsers() {
|
|
67
|
+
* return [{ id: 1, name: "John" }];
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
* @public API
|
|
71
|
+
*/
|
|
72
|
+
export declare function XmlOptions(options: XmlFormatOptions): MethodDecorator;
|
|
73
|
+
/**
|
|
74
|
+
* YamlOptions decorator to configure YAML formatting options for a route.
|
|
75
|
+
* @param options - YAML formatting options
|
|
76
|
+
* @returns MethodDecorator
|
|
77
|
+
* @public API
|
|
78
|
+
*/
|
|
79
|
+
export declare function YamlOptions(options: YamlFormatOptions): MethodDecorator;
|
|
80
|
+
/**
|
|
81
|
+
* StreamResponse decorator to indicate that the response should be streamed.
|
|
82
|
+
* Useful for large datasets.
|
|
83
|
+
* @returns MethodDecorator
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* @StreamResponse()
|
|
87
|
+
* @Get("/large-dataset")
|
|
88
|
+
* getLargeDataset() {
|
|
89
|
+
* return this.dataService.streamLargeDataset(); // Returns async iterator
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
* @public API
|
|
93
|
+
*/
|
|
94
|
+
export declare function StreamResponse(): MethodDecorator;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { PARAMETER_TYPE, HTTP_VERBS_ENUM } from "./constants";
|
|
3
|
-
import type { HandlerDecorator, Middleware } from "./interfaces";
|
|
2
|
+
import { PARAMETER_TYPE, HTTP_VERBS_ENUM } from "./constants.js";
|
|
3
|
+
import type { HandlerDecorator, Middleware, NewableFunction } from "./interfaces.js";
|
|
4
4
|
import { Request } from "express";
|
|
5
|
-
export declare const injectHttpContext:
|
|
5
|
+
export declare const injectHttpContext: ParameterDecorator & PropertyDecorator;
|
|
6
6
|
/**
|
|
7
7
|
* Controller decorator to define a new controller
|
|
8
8
|
* @param path route path
|
|
@@ -24,6 +24,25 @@ export declare function controller(path: string, ...middleware: Array<Middleware
|
|
|
24
24
|
* @public API
|
|
25
25
|
*/
|
|
26
26
|
export declare function Http(code: number): (target: object, key: string | symbol, descriptor: TypedPropertyDescriptor<any>) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Version decorator to define the API version for a controller or route method
|
|
29
|
+
* @param version API version (e.g., "1", "1.0", "v1", or 1)
|
|
30
|
+
* @returns ClassDecorator | MethodDecorator
|
|
31
|
+
* @example ```typescript
|
|
32
|
+
* @Version("1")
|
|
33
|
+
* @controller("/users")
|
|
34
|
+
* class UserController {}
|
|
35
|
+
*
|
|
36
|
+
* // Or at method level:
|
|
37
|
+
* @Version("2")
|
|
38
|
+
* @Get("/")
|
|
39
|
+
* getUsers() {
|
|
40
|
+
* return "v2 users";
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
* @public API
|
|
44
|
+
*/
|
|
45
|
+
export declare function Version(version: string | number): (target: any, key?: string | symbol, descriptor?: any) => void;
|
|
27
46
|
/**
|
|
28
47
|
* Decorator to allow accept all HTTP methods
|
|
29
48
|
* @param path route path, wildcard
|
|
@@ -195,11 +214,40 @@ type FieldOptions = {
|
|
|
195
214
|
maxCount?: number;
|
|
196
215
|
};
|
|
197
216
|
/**
|
|
198
|
-
* File upload decorator to handle file uploads
|
|
199
|
-
*
|
|
200
|
-
*
|
|
217
|
+
* File upload decorator to handle file uploads.
|
|
218
|
+
*
|
|
219
|
+
* This decorator integrates with the global upload configuration
|
|
220
|
+
* set via `Middleware.upload()` in app.ts. If global config exists,
|
|
221
|
+
* it will be used as defaults, with local options taking precedence.
|
|
222
|
+
*
|
|
223
|
+
* @param options - Field configuration (fieldName, maxCount, none, any)
|
|
224
|
+
* @param multerOptions - Optional multer options (overrides global config)
|
|
201
225
|
* @default { none: true }
|
|
202
226
|
* @returns MethodDecorator
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* // In app.ts - configure globally (optional)
|
|
231
|
+
* this.Middleware.upload({
|
|
232
|
+
* destination: './uploads',
|
|
233
|
+
* limits: { fileSize: 10 * 1024 * 1024 }
|
|
234
|
+
* });
|
|
235
|
+
*
|
|
236
|
+
* // In controller - uses global config automatically
|
|
237
|
+
* @Post('avatar')
|
|
238
|
+
* @FileUpload({ fieldName: 'avatar' })
|
|
239
|
+
* uploadAvatar(req: Request) {
|
|
240
|
+
* return req.file;
|
|
241
|
+
* }
|
|
242
|
+
*
|
|
243
|
+
* // Override global config for specific endpoint
|
|
244
|
+
* @Post('document')
|
|
245
|
+
* @FileUpload({ fieldName: 'doc' }, { limits: { fileSize: 50 * 1024 * 1024 } })
|
|
246
|
+
* uploadDocument(req: Request) {
|
|
247
|
+
* return req.file;
|
|
248
|
+
* }
|
|
249
|
+
* ```
|
|
250
|
+
*
|
|
203
251
|
* @public API
|
|
204
252
|
*/
|
|
205
253
|
export declare function FileUpload(options?: FieldOptions | Array<FieldOptions> | {
|