@expressots/adapter-express 3.0.0 → 4.0.0-preview.3
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/LICENSE.md +21 -21
- package/README.md +61 -118
- package/lib/CHANGELOG.md +36 -5
- package/lib/README.md +61 -118
- package/lib/cjs/adapter-express/application-express.base.js +3 -1
- package/lib/cjs/adapter-express/application-express.js +1405 -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 +225 -59
- 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 +827 -64
- 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/path-pattern-compat.js +129 -0
- package/lib/cjs/adapter-express/express-utils/permission-preloader.middleware.js +48 -0
- package/lib/cjs/adapter-express/express-utils/route-constraints.js +104 -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 +8 -38
- 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 +272 -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 +10 -0
- package/lib/cjs/adapter-express/studio/studio-integration.js +267 -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 +316 -33
- 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/path-pattern-compat.d.ts +66 -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 +98 -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 +83 -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 +170 -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 +1656 -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 +604 -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 +1047 -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/path-pattern-compat.js +125 -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 +100 -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 +157 -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 +266 -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 +236 -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 +453 -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/path-pattern-compat.d.ts +66 -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 +98 -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 +83 -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 +170 -0
- package/lib/esm/types/index.d.ts +1 -0
- package/lib/package.json +170 -146
- package/package.json +170 -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, Logger, 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
|
|
@@ -14,7 +14,7 @@ import { interfaces } from "../di/di.interfaces";
|
|
|
14
14
|
* @method isDevelopment - Verifies if the current environment is development.
|
|
15
15
|
*/
|
|
16
16
|
export declare class AppExpress implements Server.IWebServer {
|
|
17
|
-
|
|
17
|
+
protected logger: Logger;
|
|
18
18
|
private console;
|
|
19
19
|
private app;
|
|
20
20
|
private serverInstance;
|
|
@@ -26,53 +26,146 @@ 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 originalGlobalConsole;
|
|
55
|
+
/**
|
|
56
|
+
* Disable log buffering. Called by micro() to restore normal console output
|
|
57
|
+
* since micro API doesn't use the banner system.
|
|
58
|
+
* @public API
|
|
59
|
+
*/
|
|
60
|
+
static disableBuffering(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Start buffering all console output for the banner-first display flow.
|
|
63
|
+
* Captures both `console.*` and direct `process.stdout.write` / `process.stderr.write`
|
|
64
|
+
* calls so they can be flushed in the correct order after the banner displays.
|
|
65
|
+
*
|
|
66
|
+
* Idempotent: calling this multiple times is safe.
|
|
67
|
+
*
|
|
68
|
+
* @public API — called by `bootstrap()` so logs emitted during container
|
|
69
|
+
* setup are captured before the `AppExpress` instance exists. Also called
|
|
70
|
+
* automatically inside the constructor as a safety net.
|
|
71
|
+
*/
|
|
72
|
+
static startLogBuffering(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Stop buffering but keep the buffered logs for later flushing.
|
|
75
|
+
* This restores normal console/stdout output.
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
private static stopBuffering;
|
|
79
|
+
/**
|
|
80
|
+
* Flush all buffered logs to stdout.
|
|
81
|
+
* Should be called after stopBuffering() and after displaying the banner.
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
private static flushBufferedLogs;
|
|
29
85
|
constructor();
|
|
86
|
+
/**
|
|
87
|
+
* Helper function to handle both sync and async method calls.
|
|
88
|
+
* If the result is a Promise, awaits it; otherwise returns immediately.
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
private handleSyncOrAsync;
|
|
30
92
|
/**
|
|
31
93
|
* 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
|
-
*
|
|
94
|
+
* This method is called synchronously in the constructor before any other
|
|
95
|
+
* server initialization methods. Use this method to configure global settings
|
|
96
|
+
* that apply to the entire server application.
|
|
97
|
+
*
|
|
98
|
+
* Note: This method is synchronous and called during object construction.
|
|
99
|
+
* For asynchronous initialization, use `configureServices()` instead.
|
|
35
100
|
*
|
|
36
101
|
* @abstract
|
|
37
|
-
* @returns {void
|
|
102
|
+
* @returns {void}
|
|
38
103
|
* @public API
|
|
39
104
|
*/
|
|
40
|
-
protected globalConfiguration():
|
|
105
|
+
protected globalConfiguration(): void;
|
|
41
106
|
/**
|
|
42
107
|
* Implement this method to set up required services or configurations before
|
|
43
108
|
* the server starts. This is essential for initializing dependencies or settings
|
|
44
|
-
* necessary for server operation. Supports
|
|
109
|
+
* necessary for server operation. Supports both synchronous and asynchronous setup.
|
|
45
110
|
*
|
|
46
111
|
* @abstract
|
|
47
112
|
* @returns {void | Promise<void>}
|
|
48
113
|
* @public API
|
|
49
114
|
*/
|
|
50
|
-
protected configureServices(): Promise<void>;
|
|
115
|
+
protected configureServices(): void | Promise<void>;
|
|
51
116
|
/**
|
|
52
117
|
* Implement this method to execute actions or configurations after the server
|
|
53
118
|
* has started. Use this for operations that need to run once the server is
|
|
54
|
-
* operational. Supports
|
|
119
|
+
* operational. Supports both synchronous and asynchronous execution.
|
|
55
120
|
*
|
|
56
121
|
* @abstract
|
|
57
122
|
* @returns {void | Promise<void>}
|
|
58
123
|
* @public API
|
|
59
124
|
*/
|
|
60
|
-
protected postServerInitialization(): Promise<void>;
|
|
125
|
+
protected postServerInitialization(): void | Promise<void>;
|
|
61
126
|
/**
|
|
62
127
|
* Implement this method to handle cleanup and final actions when the server
|
|
63
128
|
* is shutting down. Ideal for closing resources, stopping tasks, or other
|
|
64
|
-
* cleanup procedures to ensure a graceful server shutdown. Supports
|
|
65
|
-
*
|
|
129
|
+
* cleanup procedures to ensure a graceful server shutdown. Supports both
|
|
130
|
+
* synchronous and asynchronous cleanup.
|
|
131
|
+
*
|
|
132
|
+
* The signal parameter indicates what triggered the shutdown:
|
|
133
|
+
* - SIGTERM: Graceful termination (e.g., Kubernetes pod shutdown)
|
|
134
|
+
* - SIGINT: User interrupt (e.g., Ctrl+C)
|
|
135
|
+
* - SIGHUP: Terminal hangup
|
|
136
|
+
* - SIGQUIT: Quit with core dump
|
|
137
|
+
* - SIGBREAK: Windows break signal
|
|
66
138
|
*
|
|
67
139
|
* @abstract
|
|
140
|
+
* @param signal - The signal that triggered the shutdown (optional for backward compatibility)
|
|
68
141
|
* @returns {void | Promise<void>}
|
|
69
142
|
* @public API
|
|
70
143
|
*/
|
|
71
|
-
protected serverShutdown(): Promise<void>;
|
|
144
|
+
protected serverShutdown(signal?: NodeJS.Signals): void | Promise<void>;
|
|
72
145
|
/**
|
|
73
|
-
*
|
|
146
|
+
* Performs graceful shutdown of the application.
|
|
147
|
+
*
|
|
148
|
+
* Shutdown sequence:
|
|
149
|
+
* 1. Execute lifecycle shutdown hooks on all IShutdown providers
|
|
150
|
+
* 2. Call user's serverShutdown hook
|
|
151
|
+
* 3. Close the HTTP server to stop accepting new connections
|
|
152
|
+
*
|
|
153
|
+
* @param signal - The signal that triggered the shutdown
|
|
154
|
+
* @returns Promise that resolves when shutdown is complete
|
|
155
|
+
* @internal
|
|
74
156
|
*/
|
|
75
157
|
private handleExit;
|
|
158
|
+
/**
|
|
159
|
+
* Destroy all active connections immediately.
|
|
160
|
+
* Used during forced shutdown.
|
|
161
|
+
* @private
|
|
162
|
+
*/
|
|
163
|
+
private destroyAllConnections;
|
|
164
|
+
/**
|
|
165
|
+
* Track a new connection for shutdown management.
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
private trackConnection;
|
|
76
169
|
/**
|
|
77
170
|
* Initialize the InversifyJS container with the provided modules and options.
|
|
78
171
|
* @param appModules - An array of application modules to be loaded into the container.
|
|
@@ -85,6 +178,11 @@ export declare class AppExpress implements Server.IWebServer {
|
|
|
85
178
|
* @public API
|
|
86
179
|
*/
|
|
87
180
|
configContainer(appModules: Array<interfaces.ContainerModule>, containerOptions?: interfaces.ContainerOptions): AppContainer;
|
|
181
|
+
/**
|
|
182
|
+
* Creates a middleware wrapper that automatically injects container when exception filters are enabled
|
|
183
|
+
* This allows users to simply set enableExceptionFilters: true without manually passing the container
|
|
184
|
+
*/
|
|
185
|
+
private createMiddlewareWrapper;
|
|
88
186
|
/**
|
|
89
187
|
* Get the ProviderManager instance.
|
|
90
188
|
* @returns The ProviderManager instance.
|
|
@@ -117,6 +215,37 @@ export declare class AppExpress implements Server.IWebServer {
|
|
|
117
215
|
* @public API
|
|
118
216
|
*/
|
|
119
217
|
listen(port: number | string, appInfo?: IConsoleMessage): Promise<IWebServerPublic>;
|
|
218
|
+
/**
|
|
219
|
+
* Close existing server instance if it exists.
|
|
220
|
+
* @private
|
|
221
|
+
*/
|
|
222
|
+
private closeExistingServer;
|
|
223
|
+
/**
|
|
224
|
+
* Wait for a specified duration.
|
|
225
|
+
* @private
|
|
226
|
+
*/
|
|
227
|
+
private delay;
|
|
228
|
+
/**
|
|
229
|
+
* Kill the process using a specific port.
|
|
230
|
+
* @private
|
|
231
|
+
*/
|
|
232
|
+
private killProcessOnPort;
|
|
233
|
+
/**
|
|
234
|
+
* Check if the port is available by attempting to bind to it.
|
|
235
|
+
* @private
|
|
236
|
+
*/
|
|
237
|
+
private isPortAvailable;
|
|
238
|
+
/**
|
|
239
|
+
* Ensure the port is available, killing the existing process if needed.
|
|
240
|
+
* This is the safest approach for hot-reload scenarios.
|
|
241
|
+
* @private
|
|
242
|
+
*/
|
|
243
|
+
private ensurePortAvailable;
|
|
244
|
+
/**
|
|
245
|
+
* Remove existing shutdown signal handlers to prevent duplicates.
|
|
246
|
+
* @private
|
|
247
|
+
*/
|
|
248
|
+
private removeShutdownHandlers;
|
|
120
249
|
/**
|
|
121
250
|
* Sets the global route prefix for the application.
|
|
122
251
|
* @method setGlobalRoutePrefix
|
|
@@ -137,34 +266,188 @@ export declare class AppExpress implements Server.IWebServer {
|
|
|
137
266
|
* @param {EngineOptions} [options] - The configuration options for the view engine
|
|
138
267
|
* @public API
|
|
139
268
|
*/
|
|
140
|
-
setEngine<T extends RenderEngine.EngineOptions>(engine: RenderEngine.Engine, options?: T): Promise<void>;
|
|
141
269
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
270
|
+
* Configure the startup banner display.
|
|
271
|
+
* Can be called in configureServices() or globalConfiguration().
|
|
272
|
+
*
|
|
273
|
+
* @param config - Banner configuration options
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* export class App extends AppExpress {
|
|
277
|
+
* configureServices(): void {
|
|
278
|
+
* this.setBanner({
|
|
279
|
+
* style: "full",
|
|
280
|
+
* showMetrics: true,
|
|
281
|
+
* showFeatures: true,
|
|
282
|
+
* showConfig: true,
|
|
283
|
+
* showPerformance: true,
|
|
284
|
+
* showResources: true,
|
|
285
|
+
* // Environment-specific overrides
|
|
286
|
+
* environment: {
|
|
287
|
+
* production: {
|
|
288
|
+
* style: "compact",
|
|
289
|
+
* showConfig: false,
|
|
290
|
+
* showResources: false,
|
|
291
|
+
* },
|
|
292
|
+
* },
|
|
293
|
+
* });
|
|
294
|
+
* }
|
|
295
|
+
* }
|
|
296
|
+
* ```
|
|
144
297
|
* @public API
|
|
145
298
|
*/
|
|
146
|
-
|
|
299
|
+
setBanner(config: BannerConfig): void;
|
|
147
300
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
301
|
+
* Configure ExpressoTS Studio integration.
|
|
302
|
+
* When enabled and @expressots/studio-agent is installed, automatically
|
|
303
|
+
* instruments the application for request recording and real-time monitoring.
|
|
304
|
+
*
|
|
305
|
+
* By default, Studio is auto-enabled in development if the package is installed.
|
|
306
|
+
* Use this method to customize behavior or enable in production.
|
|
307
|
+
*
|
|
308
|
+
* @param config - Studio configuration options
|
|
152
309
|
* @example
|
|
153
310
|
* ```typescript
|
|
154
|
-
* {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
311
|
+
* export class App extends AppExpress {
|
|
312
|
+
* configureServices(): void {
|
|
313
|
+
* this.setStudio({
|
|
314
|
+
* enabled: true, // Force enable (default: auto in dev)
|
|
315
|
+
* port: 3334, // WebSocket port for UI connection
|
|
316
|
+
* serviceName: 'my-app', // Service name for tracing
|
|
317
|
+
* });
|
|
318
|
+
* }
|
|
319
|
+
* }
|
|
320
|
+
* ```
|
|
321
|
+
* @public API
|
|
322
|
+
*/
|
|
323
|
+
setStudio(config: {
|
|
324
|
+
enabled?: boolean;
|
|
325
|
+
port?: number;
|
|
326
|
+
dbPath?: string;
|
|
327
|
+
serviceName?: string;
|
|
328
|
+
}): void;
|
|
329
|
+
/**
|
|
330
|
+
* Check if ExpressoTS Studio is currently enabled.
|
|
331
|
+
* @returns Boolean indicating if Studio Agent is running.
|
|
161
332
|
* @public API
|
|
162
333
|
*/
|
|
163
|
-
|
|
334
|
+
isStudioEnabled(): boolean;
|
|
335
|
+
/**
|
|
336
|
+
* Configure a view engine for server-side rendering.
|
|
337
|
+
*
|
|
338
|
+
* @deprecated Use `this.Middleware.render()` instead. Will be removed in v5.0.0.
|
|
339
|
+
*
|
|
340
|
+
* @example Migration
|
|
341
|
+
* ```typescript
|
|
342
|
+
* // Before (deprecated)
|
|
343
|
+
* this.setEngine(RenderEngine.Engine.EJS, { viewsDir: 'views' });
|
|
344
|
+
*
|
|
345
|
+
* // After (recommended)
|
|
346
|
+
* this.Middleware.render({ engine: 'ejs', viewsDir: 'views' });
|
|
347
|
+
*
|
|
348
|
+
* // Or with auto-detection
|
|
349
|
+
* this.Middleware.render();
|
|
350
|
+
* ```
|
|
351
|
+
*
|
|
352
|
+
* @param engine - The view engine to set
|
|
353
|
+
* @param options - The configuration options for the view engine
|
|
354
|
+
* @public API
|
|
355
|
+
*/
|
|
356
|
+
setEngine<T extends RenderEngine.EngineOptions>(engine: RenderEngine.Engine, options?: T): Promise<void>;
|
|
357
|
+
/**
|
|
358
|
+
* Verifies if the current environment is development.
|
|
359
|
+
* @returns A boolean value indicating whether the current environment is development or not.
|
|
360
|
+
* @public API
|
|
361
|
+
*/
|
|
362
|
+
isDevelopment(): Promise<boolean>;
|
|
164
363
|
/**
|
|
165
364
|
* Get the underlying HTTP server. (default: Express.js)
|
|
166
365
|
* @returns The underlying HTTP server after initialization.
|
|
167
366
|
* @public API
|
|
168
367
|
*/
|
|
169
368
|
getHttpServer(): Promise<HTTPServer>;
|
|
369
|
+
/**
|
|
370
|
+
* Get the port the server is listening on.
|
|
371
|
+
* Useful for dynamic port assignment (port: 0) in testing scenarios.
|
|
372
|
+
* @returns The actual port number the server is bound to.
|
|
373
|
+
* @public API
|
|
374
|
+
*/
|
|
375
|
+
getPort(): Promise<number>;
|
|
376
|
+
/**
|
|
377
|
+
* Detect API versions from @Version() decorators on controllers.
|
|
378
|
+
* @returns Array of unique API versions (e.g., ["v1", "v2"])
|
|
379
|
+
* @private
|
|
380
|
+
*/
|
|
381
|
+
private detectApiVersions;
|
|
382
|
+
/**
|
|
383
|
+
* Harvest provider + interceptor *names* from DI metadata so the
|
|
384
|
+
* Studio Status page can drill down into the items behind the
|
|
385
|
+
* "Providers" / "Interceptors" counters.
|
|
386
|
+
*
|
|
387
|
+
* Reads the same metadata that {@link MetricsCollector} uses for the
|
|
388
|
+
* CLI banner — so what shows up here is the source of truth, not the
|
|
389
|
+
* agent's static file scan (which can't see framework-registered
|
|
390
|
+
* items like `Logger` or `LifecycleRegistry`).
|
|
391
|
+
*
|
|
392
|
+
* Returns `undefined` instead of an empty object so {@link
|
|
393
|
+
* reportStudioRuntimeInfo} can skip forwarding when nothing was
|
|
394
|
+
* harvested (keeps the WS payload small).
|
|
395
|
+
*/
|
|
396
|
+
private collectStudioRuntimeItems;
|
|
397
|
+
/**
|
|
398
|
+
* Harvest controller- and route-scoped middleware bindings from
|
|
399
|
+
* Reflect metadata. Each entry describes a single edge the Studio
|
|
400
|
+
* architecture map should draw, e.g. "AuthMiddleware → UserController
|
|
401
|
+
* (route POST /users/:id)".
|
|
402
|
+
*
|
|
403
|
+
* The middleware values stored on `ControllerMetadata.middleware` are
|
|
404
|
+
* a polymorphic union (class, function, registered name, conditional
|
|
405
|
+
* config, …). We normalise each to a display name; entries we can't
|
|
406
|
+
* name (anonymous arrow functions, plain object configs without a
|
|
407
|
+
* `name` field) are omitted. The agent's static scan picks up the
|
|
408
|
+
* remaining named cases via decorator parsing — between the two
|
|
409
|
+
* sources Studio sees a complete graph for the common patterns.
|
|
410
|
+
*/
|
|
411
|
+
private collectMiddlewareBindings;
|
|
412
|
+
/**
|
|
413
|
+
* Combine a controller's base path with a route path, normalising
|
|
414
|
+
* leading/trailing slashes. Mirrors the simpler logic Studio uses to
|
|
415
|
+
* build `RouteInfo.path` so the bindings line up with route entries.
|
|
416
|
+
*/
|
|
417
|
+
private joinRoutePath;
|
|
418
|
+
/**
|
|
419
|
+
* Collect the ordered middleware pipeline from the Middleware service
|
|
420
|
+
* for forwarding to Studio. Uses feature-detection so older core
|
|
421
|
+
* versions that lack `getPipelineInfo()` won't break.
|
|
422
|
+
*/
|
|
423
|
+
private collectMiddlewarePipelineItems;
|
|
424
|
+
/**
|
|
425
|
+
* Build the middleware preset info snapshot for Studio. Reads the
|
|
426
|
+
* last applied preset from the Middleware service and transforms it
|
|
427
|
+
* into the shape Studio expects.
|
|
428
|
+
*/
|
|
429
|
+
private collectMiddlewarePresetInfo;
|
|
430
|
+
/**
|
|
431
|
+
* Display middleware startup logs after the banner.
|
|
432
|
+
*
|
|
433
|
+
* Warnings (e.g. missing optional packages like `helmet`) are always surfaced
|
|
434
|
+
* so the developer can act on them. Informational entries (e.g. "Security
|
|
435
|
+
* configured", "Applied preset: api") are demoted to `debug` since the
|
|
436
|
+
* dashboard already shows the active middleware count; set `LOG_LEVEL=DEBUG`
|
|
437
|
+
* to see the full breakdown.
|
|
438
|
+
* @private
|
|
439
|
+
*/
|
|
440
|
+
private displayMiddlewareStartupLogs;
|
|
441
|
+
/**
|
|
442
|
+
* Display startup banner with application metrics.
|
|
443
|
+
* @param appInfo - Application info
|
|
444
|
+
* @private
|
|
445
|
+
*/
|
|
446
|
+
private displayStartupBanner;
|
|
447
|
+
/**
|
|
448
|
+
* Display CI detection logs after the banner but before middleware logs.
|
|
449
|
+
* @param appInfo - Application info containing CI detection data
|
|
450
|
+
* @private
|
|
451
|
+
*/
|
|
452
|
+
private displayCIDetectionLogs;
|
|
170
453
|
}
|
|
@@ -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;
|