@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
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Studio Integration - Auto-detects and integrates ExpressoTS Studio Agent
|
|
3
|
+
*
|
|
4
|
+
* This module provides automatic integration with @expressots/studio-agent
|
|
5
|
+
* when it's installed in the project. It enables request recording, tracing,
|
|
6
|
+
* and real-time monitoring without requiring manual setup.
|
|
7
|
+
*/
|
|
8
|
+
let studioAgent = null;
|
|
9
|
+
let studioEnabled = false;
|
|
10
|
+
/**
|
|
11
|
+
* Check if @expressots/studio-agent is installed
|
|
12
|
+
*/
|
|
13
|
+
async function isStudioAgentInstalled() {
|
|
14
|
+
const debug = process.env.EXPRESSOTS_STUDIO_DEBUG === "true";
|
|
15
|
+
try {
|
|
16
|
+
// Try to resolve the module first (works for both CJS and ESM)
|
|
17
|
+
const resolved = require.resolve("@expressots/studio-agent");
|
|
18
|
+
if (debug)
|
|
19
|
+
console.log("[Studio] Resolved studio-agent at:", resolved);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (debug)
|
|
24
|
+
console.log("[Studio] Cannot resolve studio-agent:", error instanceof Error ? error.message : error);
|
|
25
|
+
// Module not installed
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the Studio Agent if available
|
|
31
|
+
*/
|
|
32
|
+
export async function initializeStudio(app, config = {}, appContainer) {
|
|
33
|
+
const debug = process.env.EXPRESSOTS_STUDIO_DEBUG === "true";
|
|
34
|
+
// Check if explicitly disabled
|
|
35
|
+
if (config.enabled === false || process.env.EXPRESSOTS_STUDIO === "false") {
|
|
36
|
+
if (debug)
|
|
37
|
+
console.log("[Studio] Disabled via config or env");
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// Only enable in development by default
|
|
41
|
+
const isDev = process.env.NODE_ENV === "development" || !process.env.NODE_ENV;
|
|
42
|
+
if (!isDev && config.enabled !== true) {
|
|
43
|
+
if (debug)
|
|
44
|
+
console.log("[Studio] Not in development mode, skipping");
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
// Check if studio-agent is installed
|
|
48
|
+
const installed = await isStudioAgentInstalled();
|
|
49
|
+
if (debug)
|
|
50
|
+
console.log("[Studio] studio-agent installed:", installed);
|
|
51
|
+
if (!installed) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
// Defensive: if a previous agent instance from this same process is still
|
|
55
|
+
// around (e.g. App.init() called twice without a stop in between) shut it
|
|
56
|
+
// down first so we don't leak the WebSocket port.
|
|
57
|
+
if (studioAgent) {
|
|
58
|
+
try {
|
|
59
|
+
await studioAgent.stop();
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// best-effort cleanup
|
|
63
|
+
}
|
|
64
|
+
studioAgent = null;
|
|
65
|
+
studioEnabled = false;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
if (debug)
|
|
69
|
+
console.log("[Studio] Attempting dynamic import...");
|
|
70
|
+
// Dynamic import for ESM module
|
|
71
|
+
const studioAgentModule = await import("@expressots/studio-agent");
|
|
72
|
+
if (debug)
|
|
73
|
+
console.log("[Studio] Import successful, keys:", Object.keys(studioAgentModule));
|
|
74
|
+
// studio-agent ships only named exports; cast through `any` so the
|
|
75
|
+
// ESM build does not reject the legacy `default.StudioAgent`
|
|
76
|
+
// fallback (kept for older preview tarballs).
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
const studioAgentModuleAny = studioAgentModule;
|
|
79
|
+
const StudioAgent = studioAgentModuleAny.StudioAgent || studioAgentModuleAny.default?.StudioAgent;
|
|
80
|
+
if (!StudioAgent) {
|
|
81
|
+
console.warn("⚠️ Studio Agent module found but StudioAgent class not exported");
|
|
82
|
+
if (debug)
|
|
83
|
+
console.log("[Studio] Module contents:", studioAgentModule);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (debug)
|
|
87
|
+
console.log("[Studio] StudioAgent class found, initializing...");
|
|
88
|
+
const agentOptions = {
|
|
89
|
+
port: config.port ?? parseInt(process.env.EXPRESSOTS_STUDIO_PORT ?? "3334", 10),
|
|
90
|
+
dbPath: config.dbPath ?? process.env.EXPRESSOTS_STUDIO_DB ?? ".studio/studio.db",
|
|
91
|
+
serviceName: config.serviceName ?? "expressots-app",
|
|
92
|
+
enableRecording: true,
|
|
93
|
+
enableProfiling: true,
|
|
94
|
+
expressApp: app, // Pass Express app for runtime route scanning
|
|
95
|
+
appContainer, // Pass AppContainer so the agent can build a DI snapshot
|
|
96
|
+
appPort: config.appPort,
|
|
97
|
+
globalPrefix: config.globalPrefix,
|
|
98
|
+
};
|
|
99
|
+
studioAgent = new StudioAgent(agentOptions);
|
|
100
|
+
// Add the middleware BEFORE other routes to capture all requests
|
|
101
|
+
const middleware = studioAgent.createMiddleware();
|
|
102
|
+
app.use(middleware);
|
|
103
|
+
// Start the agent (this also scans routes)
|
|
104
|
+
await studioAgent.start();
|
|
105
|
+
studioEnabled = true;
|
|
106
|
+
console.log(`[ExpressoTS] Studio Agent listening on ws://localhost:${agentOptions.port}`);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
// Best-effort cleanup so a half-initialised agent doesn't hold the
|
|
111
|
+
// WebSocket port across a retry.
|
|
112
|
+
if (studioAgent) {
|
|
113
|
+
try {
|
|
114
|
+
await studioAgent.stop();
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// ignore
|
|
118
|
+
}
|
|
119
|
+
studioAgent = null;
|
|
120
|
+
}
|
|
121
|
+
studioEnabled = false;
|
|
122
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
123
|
+
const errorCode = error && typeof error === "object" && "code" in error
|
|
124
|
+
? error.code
|
|
125
|
+
: undefined;
|
|
126
|
+
// Expected when @expressots/studio-agent isn't installed — silent.
|
|
127
|
+
if (errorMessage.includes("Cannot find module") ||
|
|
128
|
+
errorMessage.includes("ERR_MODULE_NOT_FOUND")) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
// Friendlier message for the most common failure mode: hot-reload
|
|
132
|
+
// race left the port in TIME_WAIT.
|
|
133
|
+
if (errorCode === "EADDRINUSE") {
|
|
134
|
+
console.warn(`⚠️ Studio Agent could not bind its WebSocket port ` +
|
|
135
|
+
`(${errorMessage}). The host app will continue without Studio. ` +
|
|
136
|
+
`If this happened during hot-reload, the next restart should recover.`);
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
console.warn("⚠️ Failed to initialize Studio Agent:", errorMessage);
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Push runtime details to the agent that the host only knows after the
|
|
145
|
+
* HTTP server has started — most importantly the actual listening port
|
|
146
|
+
* and total boot time. No-ops when:
|
|
147
|
+
* - the agent isn't running, or
|
|
148
|
+
* - the installed agent is from an older preview without
|
|
149
|
+
* `updateRuntimeInfo()` (we feature-detect to stay forward-compatible).
|
|
150
|
+
*/
|
|
151
|
+
export function reportStudioRuntimeInfo(patch) {
|
|
152
|
+
if (!studioAgent)
|
|
153
|
+
return;
|
|
154
|
+
if (typeof studioAgent.updateRuntimeInfo !== "function")
|
|
155
|
+
return;
|
|
156
|
+
try {
|
|
157
|
+
studioAgent.updateRuntimeInfo(patch);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Best-effort — never break the host on a status-page update.
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Stop the Studio Agent
|
|
165
|
+
*/
|
|
166
|
+
export async function stopStudio() {
|
|
167
|
+
if (studioAgent) {
|
|
168
|
+
await studioAgent.stop();
|
|
169
|
+
studioAgent = null;
|
|
170
|
+
studioEnabled = false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Check if Studio is enabled
|
|
175
|
+
*/
|
|
176
|
+
export function isStudioEnabled() {
|
|
177
|
+
return studioEnabled;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get the Studio Agent instance
|
|
181
|
+
*/
|
|
182
|
+
export function getStudioAgent() {
|
|
183
|
+
return studioAgent;
|
|
184
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./adapter-express/index.js";
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract class ApplicationBase.
|
|
3
|
+
*
|
|
4
|
+
* ApplicationBase serves as the foundational structure for building
|
|
5
|
+
* server applications. It declares the lifecycle hooks that allow
|
|
6
|
+
* subclasses to configure services, handle post-server initialization,
|
|
7
|
+
* and perform cleanup when the server is shutting down. Extending
|
|
8
|
+
* classes are required to provide implementations for these methods
|
|
9
|
+
* to define specific behaviors for their particular use cases.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* class Application extends ApplicationBase {
|
|
13
|
+
* protected configureServices() { //... }
|
|
14
|
+
* protected postServerInitialization() { //... }
|
|
15
|
+
* protected serverShutdown(signal) {
|
|
16
|
+
* console.log(`Shutting down due to ${signal}`);
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* @export
|
|
21
|
+
* @abstract
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class ApplicationBase {
|
|
24
|
+
/**
|
|
25
|
+
* Implement this method to set up global configurations for the server.
|
|
26
|
+
* This method is called synchronously in the constructor before any other
|
|
27
|
+
* server initialization methods. Use this method to configure global settings
|
|
28
|
+
* that apply to the entire server application.
|
|
29
|
+
*
|
|
30
|
+
* Note: This method is synchronous and called during object construction.
|
|
31
|
+
* For asynchronous initialization, use `configureServices()` instead.
|
|
32
|
+
*
|
|
33
|
+
* @abstract
|
|
34
|
+
* @returns {void}
|
|
35
|
+
* @public API
|
|
36
|
+
*/
|
|
37
|
+
protected abstract globalConfiguration(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Implement this method to set up required services or configurations before
|
|
40
|
+
* the server starts. This is essential for initializing dependencies or settings
|
|
41
|
+
* necessary for server operation. Supports asynchronous setup with a Promise.
|
|
42
|
+
*
|
|
43
|
+
* @abstract
|
|
44
|
+
* @returns {void | Promise<void>}
|
|
45
|
+
* @public API
|
|
46
|
+
*/
|
|
47
|
+
protected abstract configureServices(): void | Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Implement this method to execute actions or configurations after the server
|
|
50
|
+
* has started. Use this for operations that need to run once the server is
|
|
51
|
+
* operational. Supports asynchronous execution with a Promise.
|
|
52
|
+
*
|
|
53
|
+
* @abstract
|
|
54
|
+
* @returns {void | Promise<void>}
|
|
55
|
+
* @public API
|
|
56
|
+
*/
|
|
57
|
+
protected abstract postServerInitialization(): void | Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Implement this method to handle cleanup and final actions when the server
|
|
60
|
+
* is shutting down. Ideal for closing resources, stopping tasks, or other
|
|
61
|
+
* cleanup procedures to ensure a graceful server shutdown. Supports asynchronous
|
|
62
|
+
* cleanup with a Promise.
|
|
63
|
+
*
|
|
64
|
+
* The signal parameter indicates what triggered the shutdown:
|
|
65
|
+
* - SIGTERM: Graceful termination (e.g., Kubernetes pod shutdown)
|
|
66
|
+
* - SIGINT: User interrupt (e.g., Ctrl+C)
|
|
67
|
+
* - SIGHUP: Terminal hangup
|
|
68
|
+
* - SIGQUIT: Quit with core dump
|
|
69
|
+
* - SIGBREAK: Windows break signal
|
|
70
|
+
*
|
|
71
|
+
* @abstract
|
|
72
|
+
* @param signal - The signal that triggered the shutdown (optional for backward compatibility)
|
|
73
|
+
* @returns {void | Promise<void>}
|
|
74
|
+
* @public API
|
|
75
|
+
*/
|
|
76
|
+
protected abstract serverShutdown(signal?: NodeJS.Signals): void | Promise<void>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { Server as HTTPServer } from "http";
|
|
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
|
+
/**
|
|
6
|
+
* The AppExpress class provides methods for configuring and running an Express application.
|
|
7
|
+
* @class AppExpress
|
|
8
|
+
* @implements {IWebServer} - Interface for the WebServer application implementation.
|
|
9
|
+
* @extends {ApplicationBase} - Base class for the application implementation that provides lifecycle hooks.
|
|
10
|
+
* @method configure - Configures the InversifyJS container.
|
|
11
|
+
* @method listen - Start listening on the given port and environment.
|
|
12
|
+
* @method setGlobalRoutePrefix - Sets the global route prefix for the application.
|
|
13
|
+
* @method setEngine - Configures the application's view engine based on the provided configuration options.
|
|
14
|
+
* @method isDevelopment - Verifies if the current environment is development.
|
|
15
|
+
*/
|
|
16
|
+
export declare class AppExpress implements Server.IWebServer {
|
|
17
|
+
private logger;
|
|
18
|
+
private console;
|
|
19
|
+
private app;
|
|
20
|
+
private serverInstance;
|
|
21
|
+
private port;
|
|
22
|
+
private environment?;
|
|
23
|
+
private appContainer;
|
|
24
|
+
private globalPrefix;
|
|
25
|
+
private middlewareManager;
|
|
26
|
+
private middlewares;
|
|
27
|
+
private providerManager;
|
|
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;
|
|
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;
|
|
88
|
+
/**
|
|
89
|
+
* Implement this method to set up global configurations for the server.
|
|
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.
|
|
96
|
+
*
|
|
97
|
+
* @abstract
|
|
98
|
+
* @returns {void}
|
|
99
|
+
* @public API
|
|
100
|
+
*/
|
|
101
|
+
protected globalConfiguration(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Implement this method to set up required services or configurations before
|
|
104
|
+
* the server starts. This is essential for initializing dependencies or settings
|
|
105
|
+
* necessary for server operation. Supports both synchronous and asynchronous setup.
|
|
106
|
+
*
|
|
107
|
+
* @abstract
|
|
108
|
+
* @returns {void | Promise<void>}
|
|
109
|
+
* @public API
|
|
110
|
+
*/
|
|
111
|
+
protected configureServices(): void | Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Implement this method to execute actions or configurations after the server
|
|
114
|
+
* has started. Use this for operations that need to run once the server is
|
|
115
|
+
* operational. Supports both synchronous and asynchronous execution.
|
|
116
|
+
*
|
|
117
|
+
* @abstract
|
|
118
|
+
* @returns {void | Promise<void>}
|
|
119
|
+
* @public API
|
|
120
|
+
*/
|
|
121
|
+
protected postServerInitialization(): void | Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Implement this method to handle cleanup and final actions when the server
|
|
124
|
+
* is shutting down. Ideal for closing resources, stopping tasks, or other
|
|
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
|
|
134
|
+
*
|
|
135
|
+
* @abstract
|
|
136
|
+
* @param signal - The signal that triggered the shutdown (optional for backward compatibility)
|
|
137
|
+
* @returns {void | Promise<void>}
|
|
138
|
+
* @public API
|
|
139
|
+
*/
|
|
140
|
+
protected serverShutdown(signal?: NodeJS.Signals): void | Promise<void>;
|
|
141
|
+
/**
|
|
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
|
|
152
|
+
*/
|
|
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;
|
|
165
|
+
/**
|
|
166
|
+
* Initialize the InversifyJS container with the provided modules and options.
|
|
167
|
+
* @param appModules - An array of application modules to be loaded into the container.
|
|
168
|
+
* @param containerOptions - Container global configuration options.
|
|
169
|
+
* @option skipBaseClassChecks - Skip the base class checks for the container.
|
|
170
|
+
* @option autoBindInjectable - Automatically bind the injectable classes.
|
|
171
|
+
* @option defaultScope - The default scope to use for bindings.
|
|
172
|
+
*
|
|
173
|
+
* @returns The configured AppContainer instance.
|
|
174
|
+
* @public API
|
|
175
|
+
*/
|
|
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;
|
|
182
|
+
/**
|
|
183
|
+
* Get the ProviderManager instance.
|
|
184
|
+
* @returns The ProviderManager instance.
|
|
185
|
+
* @public API
|
|
186
|
+
*/
|
|
187
|
+
get Provider(): ProviderManager;
|
|
188
|
+
/**
|
|
189
|
+
* Get the Middleware instance.
|
|
190
|
+
* @returns The Middleware instance.
|
|
191
|
+
* @public API
|
|
192
|
+
*/
|
|
193
|
+
get Middleware(): IMiddleware;
|
|
194
|
+
/**
|
|
195
|
+
* Configures the Express application with the provided middleware entries.
|
|
196
|
+
* @param app - The Express application instance.
|
|
197
|
+
* @param middlewareEntries - An array of Express middleware entries to be applied.
|
|
198
|
+
*/
|
|
199
|
+
private configureMiddleware;
|
|
200
|
+
/**
|
|
201
|
+
* Create and configure the Express application.
|
|
202
|
+
* @param container - The InversifyJS container.
|
|
203
|
+
* @param middlewares - An array of Express middlewares to be applied.
|
|
204
|
+
* @returns The configured Application instance.
|
|
205
|
+
*/
|
|
206
|
+
private init;
|
|
207
|
+
/**
|
|
208
|
+
* Start listening on the given port and environment.
|
|
209
|
+
* @param port - The port number to listen on.
|
|
210
|
+
* @param appInfo - Optional message to display the app name and version.
|
|
211
|
+
* @public API
|
|
212
|
+
*/
|
|
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;
|
|
245
|
+
/**
|
|
246
|
+
* Sets the global route prefix for the application.
|
|
247
|
+
* @method setGlobalRoutePrefix
|
|
248
|
+
* @param {string} prefix - The prefix to use for all routes.
|
|
249
|
+
* @public API
|
|
250
|
+
*/
|
|
251
|
+
setGlobalRoutePrefix(prefix: string): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Configures the application's view engine based on the provided configuration options.
|
|
254
|
+
*/
|
|
255
|
+
private configEngine;
|
|
256
|
+
/**
|
|
257
|
+
* Configures the application's view engine based on the provided configuration options.
|
|
258
|
+
* @method setEngine
|
|
259
|
+
* @template T - A generic type extending from RenderTemplateOptions.
|
|
260
|
+
*
|
|
261
|
+
* @param {Engine} engine - The view engine to set
|
|
262
|
+
* @param {EngineOptions} [options] - The configuration options for the view engine
|
|
263
|
+
* @public API
|
|
264
|
+
*/
|
|
265
|
+
/**
|
|
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
|
+
* ```
|
|
293
|
+
* @public API
|
|
294
|
+
*/
|
|
295
|
+
setBanner(config: BannerConfig): void;
|
|
296
|
+
/**
|
|
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
|
|
305
|
+
* @example
|
|
306
|
+
* ```typescript
|
|
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
|
|
350
|
+
* @public API
|
|
351
|
+
*/
|
|
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>;
|
|
359
|
+
/**
|
|
360
|
+
* Get the underlying HTTP server. (default: Express.js)
|
|
361
|
+
* @returns The underlying HTTP server after initialization.
|
|
362
|
+
* @public API
|
|
363
|
+
*/
|
|
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;
|
|
411
|
+
}
|