stratal 0.0.6 → 0.0.7
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/dist/application.d.ts +10 -42
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +36 -77
- package/dist/application.js.map +1 -1
- package/dist/config/config.module.d.ts.map +1 -1
- package/dist/config/config.module.js +2 -1
- package/dist/config/config.module.js.map +1 -1
- package/dist/config/errors/config-module-not-initialized.error.d.ts +10 -0
- package/dist/config/errors/config-module-not-initialized.error.d.ts.map +1 -0
- package/dist/config/errors/config-module-not-initialized.error.js +12 -0
- package/dist/config/errors/config-module-not-initialized.error.js.map +1 -0
- package/dist/config/errors/index.d.ts +1 -0
- package/dist/config/errors/index.d.ts.map +1 -1
- package/dist/config/errors/index.js +1 -0
- package/dist/config/errors/index.js.map +1 -1
- package/dist/di/container.d.ts +5 -267
- package/dist/di/container.d.ts.map +1 -1
- package/dist/di/container.js +13 -288
- package/dist/di/container.js.map +1 -1
- package/dist/di/errors/request-scope-operation-not-allowed.error.d.ts +0 -1
- package/dist/di/errors/request-scope-operation-not-allowed.error.d.ts.map +1 -1
- package/dist/di/errors/request-scope-operation-not-allowed.error.js +0 -1
- package/dist/di/errors/request-scope-operation-not-allowed.error.js.map +1 -1
- package/dist/di/index.d.ts +0 -1
- package/dist/di/index.d.ts.map +1 -1
- package/dist/di/index.js +0 -1
- package/dist/di/index.js.map +1 -1
- package/dist/errors/error-codes.d.ts +2 -0
- package/dist/errors/error-codes.d.ts.map +1 -1
- package/dist/errors/error-codes.js +2 -0
- package/dist/errors/error-codes.js.map +1 -1
- package/dist/events/types.d.ts +1 -1
- package/dist/execution-context.d.ts +4 -0
- package/dist/execution-context.d.ts.map +1 -0
- package/dist/execution-context.js +2 -0
- package/dist/execution-context.js.map +1 -0
- package/dist/i18n/messages/en/errors.d.ts +2 -2
- package/dist/i18n/messages/en/errors.js +2 -2
- package/dist/i18n/messages/en/errors.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/logger/services/logger.service.d.ts +2 -15
- package/dist/logger/services/logger.service.d.ts.map +1 -1
- package/dist/logger/services/logger.service.js +11 -16
- package/dist/logger/services/logger.service.js.map +1 -1
- package/dist/router/errors/hono-app-already-configured.error.d.ts +10 -0
- package/dist/router/errors/hono-app-already-configured.error.d.ts.map +1 -0
- package/dist/router/errors/hono-app-already-configured.error.js +12 -0
- package/dist/router/errors/hono-app-already-configured.error.js.map +1 -0
- package/dist/router/errors/index.d.ts +1 -2
- package/dist/router/errors/index.d.ts.map +1 -1
- package/dist/router/errors/index.js +1 -2
- package/dist/router/errors/index.js.map +1 -1
- package/dist/router/hono-app.d.ts +38 -0
- package/dist/router/hono-app.d.ts.map +1 -0
- package/dist/router/hono-app.js +128 -0
- package/dist/router/hono-app.js.map +1 -0
- package/dist/router/index.d.ts +3 -3
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +6 -4
- package/dist/router/index.js.map +1 -1
- package/dist/router/router.tokens.d.ts +0 -28
- package/dist/router/router.tokens.d.ts.map +1 -1
- package/dist/router/router.tokens.js +0 -28
- package/dist/router/router.tokens.js.map +1 -1
- package/dist/router/services/index.d.ts +0 -1
- package/dist/router/services/index.d.ts.map +1 -1
- package/dist/router/services/index.js +0 -1
- package/dist/router/services/index.js.map +1 -1
- package/dist/stratal.d.ts +9 -26
- package/dist/stratal.d.ts.map +1 -1
- package/dist/stratal.js +22 -50
- package/dist/stratal.js.map +1 -1
- package/package.json +8 -8
- package/dist/di/request-context-store.d.ts +0 -122
- package/dist/di/request-context-store.d.ts.map +0 -1
- package/dist/di/request-context-store.js +0 -135
- package/dist/di/request-context-store.js.map +0 -1
- package/dist/router/errors/router-already-configured.error.d.ts +0 -5
- package/dist/router/errors/router-already-configured.error.d.ts.map +0 -1
- package/dist/router/errors/router-already-configured.error.js +0 -8
- package/dist/router/errors/router-already-configured.error.js.map +0 -1
- package/dist/router/errors/router-not-configured.error.d.ts +0 -5
- package/dist/router/errors/router-not-configured.error.d.ts.map +0 -1
- package/dist/router/errors/router-not-configured.error.js +0 -8
- package/dist/router/errors/router-not-configured.error.js.map +0 -1
- package/dist/router/router.service.d.ts +0 -62
- package/dist/router/router.service.d.ts.map +0 -1
- package/dist/router/router.service.js +0 -166
- package/dist/router/router.service.js.map +0 -1
- package/dist/router/services/request-scope.service.d.ts +0 -42
- package/dist/router/services/request-scope.service.d.ts.map +0 -1
- package/dist/router/services/request-scope.service.js +0 -76
- package/dist/router/services/request-scope.service.js.map +0 -1
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { cors } from 'hono/cors';
|
|
14
|
-
import { inject } from 'tsyringe';
|
|
15
|
-
import { CONTAINER_TOKEN } from '../di';
|
|
16
|
-
import { Transient } from '../di/decorators';
|
|
17
|
-
import { DI_TOKENS } from '../di/tokens';
|
|
18
|
-
import { getHttpStatus } from '../errors';
|
|
19
|
-
import { OpenAPIHono } from '../i18n/validation';
|
|
20
|
-
import { LOGGER_TOKENS } from '../logger';
|
|
21
|
-
import { MiddlewareConfigurationService, } from '../middleware';
|
|
22
|
-
import { OPENAPI_TOKENS } from '../openapi';
|
|
23
|
-
import { ROUTER_CONTEXT_KEYS } from './constants';
|
|
24
|
-
import { RouteNotFoundError, RouterAlreadyConfiguredError, RouterNotConfiguredError } from './errors';
|
|
25
|
-
import { SchemaValidationError } from './errors/schema-validation.error';
|
|
26
|
-
import { createLoggerMiddleware } from './middleware';
|
|
27
|
-
import { ROUTER_TOKENS } from './router.tokens';
|
|
28
|
-
import { RequestScopeService } from './services/request-scope.service';
|
|
29
|
-
import { RouteRegistrationService } from './services/route-registration.service';
|
|
30
|
-
/**
|
|
31
|
-
* RouterService manages HTTP routing and request handling with OpenAPI support
|
|
32
|
-
*
|
|
33
|
-
* Responsibilities:
|
|
34
|
-
* - Creates and configures OpenAPIHono application
|
|
35
|
-
* - Delegates to specialized services:
|
|
36
|
-
* - RequestScopeService: Request-scoped container setup
|
|
37
|
-
* - OpenAPIService: OpenAPI spec and documentation endpoints
|
|
38
|
-
* - RouteRegistrationService: Controller and route registration
|
|
39
|
-
* - Registers global middleware (CORS, logging, error handling)
|
|
40
|
-
* - Handles fetch requests via Hono
|
|
41
|
-
*
|
|
42
|
-
* Note: Route access control (domain-based enforcement) is handled by
|
|
43
|
-
* RouteAccessMiddleware in the tenancy module, applied via TenancyModule.configure().
|
|
44
|
-
*
|
|
45
|
-
* The service is registered as a singleton in the DI container
|
|
46
|
-
* and accessed by the Backend worker's fetch() method.
|
|
47
|
-
*/
|
|
48
|
-
let RouterService = class RouterService {
|
|
49
|
-
logger;
|
|
50
|
-
container;
|
|
51
|
-
app;
|
|
52
|
-
configured = false;
|
|
53
|
-
constructor(logger, container) {
|
|
54
|
-
this.logger = logger;
|
|
55
|
-
this.container = container;
|
|
56
|
-
this.app = new OpenAPIHono({
|
|
57
|
-
defaultHook: (result, c) => {
|
|
58
|
-
if (!result.success) {
|
|
59
|
-
// Get request container (created by RequestScopeService)
|
|
60
|
-
const requestContainer = c.get(ROUTER_CONTEXT_KEYS.REQUEST_CONTAINER);
|
|
61
|
-
// Resolve GlobalErrorHandler from request container for i18n support
|
|
62
|
-
const errorHandler = requestContainer.resolve(DI_TOKENS.ErrorHandler);
|
|
63
|
-
// Convert ZodError to SchemaValidationError
|
|
64
|
-
const validationError = new SchemaValidationError(result.error);
|
|
65
|
-
// Process through global error handler for consistent formatting
|
|
66
|
-
const errorResponse = errorHandler.handle(validationError);
|
|
67
|
-
// Get HTTP status code from error code
|
|
68
|
-
const status = getHttpStatus(errorResponse.code);
|
|
69
|
-
return c.json(errorResponse, status);
|
|
70
|
-
}
|
|
71
|
-
// Validation succeeded, continue to handler
|
|
72
|
-
return;
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
this.setupMiddleware();
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Setup all middleware in correct order
|
|
79
|
-
* Note: OpenAPI setup is deferred to configure() because it needs controllers
|
|
80
|
-
*/
|
|
81
|
-
setupMiddleware() {
|
|
82
|
-
// 1. Request-scoped container setup (MUST be FIRST)
|
|
83
|
-
const requestScopeService = new RequestScopeService(this.container);
|
|
84
|
-
requestScopeService.setupMiddleware(this.app);
|
|
85
|
-
// 2. Global middleware (CORS, logging, error handling)
|
|
86
|
-
this.setupGlobalMiddleware();
|
|
87
|
-
// 3. OpenAPI documentation endpoints - deferred to configure()
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Setup global middleware that runs for all requests
|
|
91
|
-
*/
|
|
92
|
-
setupGlobalMiddleware() {
|
|
93
|
-
// CORS middleware
|
|
94
|
-
this.app.use('*', cors());
|
|
95
|
-
// Request logger middleware (uses our Logger service)
|
|
96
|
-
this.app.use('*', createLoggerMiddleware(this.logger));
|
|
97
|
-
// Global error handler
|
|
98
|
-
this.app.onError((err, c) => {
|
|
99
|
-
// Resolve GlobalErrorHandler from request container (has I18nService for translation)
|
|
100
|
-
const requestContainer = c.get(ROUTER_CONTEXT_KEYS.REQUEST_CONTAINER);
|
|
101
|
-
const errorHandler = requestContainer.resolve(DI_TOKENS.ErrorHandler);
|
|
102
|
-
// Handle all errors via GlobalErrorHandler
|
|
103
|
-
const errorResponse = errorHandler.handle(err);
|
|
104
|
-
const status = getHttpStatus(errorResponse.code);
|
|
105
|
-
return c.json(errorResponse, status);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Configure router with middlewares and controllers atomically
|
|
110
|
-
* This MUST be called immediately after RouterService construction
|
|
111
|
-
* and can only be called once.
|
|
112
|
-
*
|
|
113
|
-
* @param middlewareConfigs - Array of middleware configuration entries from modules
|
|
114
|
-
* @param controllers - Array of controller classes from modules
|
|
115
|
-
*/
|
|
116
|
-
configure(middlewareConfigs, controllers) {
|
|
117
|
-
if (this.configured) {
|
|
118
|
-
throw new RouterAlreadyConfiguredError();
|
|
119
|
-
}
|
|
120
|
-
this.logger.info('Configuring router', {
|
|
121
|
-
middlewareConfigCount: middlewareConfigs.length,
|
|
122
|
-
controllerCount: controllers.length,
|
|
123
|
-
});
|
|
124
|
-
// 3. Apply middleware configurations FIRST (includes LocaleExtractionMiddleware, RouteAccessMiddleware)
|
|
125
|
-
// Middleware must run before OpenAPI endpoints so locale and route context are available
|
|
126
|
-
const middlewareConfigService = new MiddlewareConfigurationService(this.logger);
|
|
127
|
-
middlewareConfigService.applyMiddlewares(this.app, middlewareConfigs, controllers, this.container);
|
|
128
|
-
// 4. OpenAPI documentation endpoints (needs middleware to run first for i18n and route filtering)
|
|
129
|
-
const openAPIService = this.container.resolve(OPENAPI_TOKENS.OpenAPIService);
|
|
130
|
-
openAPIService.setupEndpoints(this.app, controllers);
|
|
131
|
-
// 5. Register controllers and routes
|
|
132
|
-
const routeRegistrationService = new RouteRegistrationService(this.logger);
|
|
133
|
-
routeRegistrationService.configure(this.app, controllers);
|
|
134
|
-
// 6. Register 404 handler last
|
|
135
|
-
this.app.notFound((c) => {
|
|
136
|
-
throw new RouteNotFoundError(c.req.path, c.req.method);
|
|
137
|
-
});
|
|
138
|
-
this.configured = true;
|
|
139
|
-
this.logger.info('Router configuration complete');
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Handle incoming fetch request via Hono
|
|
143
|
-
*
|
|
144
|
-
* This method is called by the Backend worker's fetch() method.
|
|
145
|
-
* The request-scoped container is created in RequestScopeService.
|
|
146
|
-
*
|
|
147
|
-
* @param request - Incoming Request object
|
|
148
|
-
* @param env - Cloudflare environment bindings
|
|
149
|
-
* @param ctx - Cloudflare execution context
|
|
150
|
-
* @returns Response object
|
|
151
|
-
*/
|
|
152
|
-
fetch(request, env, ctx) {
|
|
153
|
-
if (!this.configured) {
|
|
154
|
-
throw new RouterNotConfiguredError();
|
|
155
|
-
}
|
|
156
|
-
return this.app.fetch(request, env, ctx);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
RouterService = __decorate([
|
|
160
|
-
Transient(ROUTER_TOKENS.RouterService),
|
|
161
|
-
__param(0, inject(LOGGER_TOKENS.LoggerService)),
|
|
162
|
-
__param(1, inject(CONTAINER_TOKEN)),
|
|
163
|
-
__metadata("design:paramtypes", [Function, Function])
|
|
164
|
-
], RouterService);
|
|
165
|
-
export { RouterService };
|
|
166
|
-
//# sourceMappingURL=router.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.service.js","sourceRoot":"","sources":["../../src/router/router.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,eAAe,EAAkB,MAAM,OAAO,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,EAAsB,aAAa,EAA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EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACxD,CAAC,CAAC,CAAA;QAEF,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;QACtB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAA;IACnD,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,OAAgB,EAAE,GAAe,EAAE,GAAqB;QAC5D,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,wBAAwB,EAAE,CAAA;QACtC,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;IAC1C,CAAC;CACF,CAAA;AArIY,aAAa;IADzB,SAAS,CAAC,aAAa,CAAC,aAAa,CAAC;IAMlC,WAAA,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,CAAA;IAEnC,WAAA,MAAM,CAAC,eAAe,CAAC,CAAA;;GAPf,aAAa,CAqIzB"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIHono } from '../../i18n/validation';
|
|
2
|
-
import { Container } from '../../di';
|
|
3
|
-
import type { RouterEnv } from '../types';
|
|
4
|
-
/**
|
|
5
|
-
* Request Scope Service
|
|
6
|
-
*
|
|
7
|
-
* Manages request-scoped container setup and lifecycle.
|
|
8
|
-
* Creates context-enriched instances of `@RequestScoped` services.
|
|
9
|
-
*
|
|
10
|
-
* **Two-Tier Container Architecture:**
|
|
11
|
-
* ```
|
|
12
|
-
* Container (manages global container)
|
|
13
|
-
* ↓
|
|
14
|
-
* container.createRequestScope(routerContext)
|
|
15
|
-
* ↓
|
|
16
|
-
* Request Container (child, per request)
|
|
17
|
-
* ↓
|
|
18
|
-
* Context-enriched instances via withContext(routerContext)
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* **Responsibilities:**
|
|
22
|
-
* - Setup request-scoped container middleware
|
|
23
|
-
* - Create context-enriched instances of `@RequestScoped` services
|
|
24
|
-
*
|
|
25
|
-
* **Note:**
|
|
26
|
-
* - AuthContext registration is handled by AuthModule's AuthContextMiddleware
|
|
27
|
-
* - Locale extraction is handled by I18nModule's LocaleExtractionMiddleware
|
|
28
|
-
* - Zod i18n context is handled by I18nModule's I18nContextMiddleware
|
|
29
|
-
* - Session verification is handled by AuthModule's SessionVerificationMiddleware
|
|
30
|
-
*/
|
|
31
|
-
export declare class RequestScopeService {
|
|
32
|
-
private readonly container;
|
|
33
|
-
constructor(container: Container);
|
|
34
|
-
/**
|
|
35
|
-
* Setup request-scoped container middleware
|
|
36
|
-
*
|
|
37
|
-
* This MUST run before all other middleware and routes.
|
|
38
|
-
* Creates a child container with context-enriched service instances.
|
|
39
|
-
*/
|
|
40
|
-
setupMiddleware(app: OpenAPIHono<RouterEnv>): void;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=request-scope.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request-scope.service.d.ts","sourceRoot":"","sources":["../../../src/router/services/request-scope.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,EAAE,SAAS,EAAmB,MAAM,UAAU,CAAA;AAIrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBACa,mBAAmB;IAG5B,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAGvC;;;;;OAKG;IACH,eAAe,CAAC,GAAG,EAAE,WAAW,CAAC,SAAS,CAAC,GAAG,IAAI;CAgBnD"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { inject } from 'tsyringe';
|
|
14
|
-
import { Container, CONTAINER_TOKEN } from '../../di';
|
|
15
|
-
import { Transient } from '../../di/decorators';
|
|
16
|
-
import { ROUTER_CONTEXT_KEYS } from '../constants';
|
|
17
|
-
import { RouterContext } from '../router-context';
|
|
18
|
-
/**
|
|
19
|
-
* Request Scope Service
|
|
20
|
-
*
|
|
21
|
-
* Manages request-scoped container setup and lifecycle.
|
|
22
|
-
* Creates context-enriched instances of `@RequestScoped` services.
|
|
23
|
-
*
|
|
24
|
-
* **Two-Tier Container Architecture:**
|
|
25
|
-
* ```
|
|
26
|
-
* Container (manages global container)
|
|
27
|
-
* ↓
|
|
28
|
-
* container.createRequestScope(routerContext)
|
|
29
|
-
* ↓
|
|
30
|
-
* Request Container (child, per request)
|
|
31
|
-
* ↓
|
|
32
|
-
* Context-enriched instances via withContext(routerContext)
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* **Responsibilities:**
|
|
36
|
-
* - Setup request-scoped container middleware
|
|
37
|
-
* - Create context-enriched instances of `@RequestScoped` services
|
|
38
|
-
*
|
|
39
|
-
* **Note:**
|
|
40
|
-
* - AuthContext registration is handled by AuthModule's AuthContextMiddleware
|
|
41
|
-
* - Locale extraction is handled by I18nModule's LocaleExtractionMiddleware
|
|
42
|
-
* - Zod i18n context is handled by I18nModule's I18nContextMiddleware
|
|
43
|
-
* - Session verification is handled by AuthModule's SessionVerificationMiddleware
|
|
44
|
-
*/
|
|
45
|
-
let RequestScopeService = class RequestScopeService {
|
|
46
|
-
container;
|
|
47
|
-
constructor(container) {
|
|
48
|
-
this.container = container;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Setup request-scoped container middleware
|
|
52
|
-
*
|
|
53
|
-
* This MUST run before all other middleware and routes.
|
|
54
|
-
* Creates a child container with context-enriched service instances.
|
|
55
|
-
*/
|
|
56
|
-
setupMiddleware(app) {
|
|
57
|
-
app.use('*', async (c, next) => {
|
|
58
|
-
// Create RouterContext
|
|
59
|
-
const routerContext = new RouterContext(c);
|
|
60
|
-
// Create request scope using Container
|
|
61
|
-
const requestContainer = this.container.createRequestScope(routerContext);
|
|
62
|
-
// Store in Hono context
|
|
63
|
-
c.set(ROUTER_CONTEXT_KEYS.REQUEST_CONTAINER, requestContainer);
|
|
64
|
-
// Run request within AsyncLocalStorage context
|
|
65
|
-
// Cleanup is automatic in runWithContextStore
|
|
66
|
-
await requestContainer.runWithContextStore(() => next());
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
RequestScopeService = __decorate([
|
|
71
|
-
Transient(),
|
|
72
|
-
__param(0, inject(CONTAINER_TOKEN)),
|
|
73
|
-
__metadata("design:paramtypes", [Container])
|
|
74
|
-
], RequestScopeService);
|
|
75
|
-
export { RequestScopeService };
|
|
76
|
-
//# sourceMappingURL=request-scope.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request-scope.service.js","sourceRoot":"","sources":["../../../src/router/services/request-scope.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAGX;IAFnB,YAEmB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IACpC,CAAC;IAEJ;;;;;OAKG;IACH,eAAe,CAAC,GAA2B;QACzC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;YAC7B,uBAAuB;YACvB,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,CAAuB,CAAC,CAAA;YAEhE,uCAAuC;YACvC,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAA;YAEzE,wBAAwB;YACxB,CAAC,CAAC,GAAG,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAA;YAE9D,+CAA+C;YAC/C,8CAA8C;YAC9C,MAAM,gBAAgB,CAAC,mBAAmB,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;QAC1D,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AA5BY,mBAAmB;IAD/B,SAAS,EAAE;IAGP,WAAA,MAAM,CAAC,eAAe,CAAC,CAAA;qCACI,SAAS;GAH5B,mBAAmB,CA4B/B"}
|