@fluojs/runtime 1.0.0-beta.2 → 1.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.ko.md +7 -0
  2. package/README.md +7 -0
  3. package/dist/adapters/request-response-factory.d.ts +9 -0
  4. package/dist/adapters/request-response-factory.d.ts.map +1 -1
  5. package/dist/adapters/request-response-factory.js +11 -0
  6. package/dist/bootstrap.d.ts.map +1 -1
  7. package/dist/bootstrap.js +220 -46
  8. package/dist/health/diagnostics.d.ts +38 -0
  9. package/dist/health/diagnostics.d.ts.map +1 -1
  10. package/dist/health/diagnostics.js +48 -0
  11. package/dist/health/health.d.ts +21 -0
  12. package/dist/health/health.d.ts.map +1 -1
  13. package/dist/health/health.js +27 -0
  14. package/dist/logging/json-logger.d.ts +5 -0
  15. package/dist/logging/json-logger.d.ts.map +1 -1
  16. package/dist/logging/json-logger.js +6 -0
  17. package/dist/logging/logger.d.ts +5 -0
  18. package/dist/logging/logger.d.ts.map +1 -1
  19. package/dist/logging/logger.js +6 -0
  20. package/dist/module-graph.d.ts.map +1 -1
  21. package/dist/module-graph.js +17 -7
  22. package/dist/node/internal-node-compression.d.ts +15 -0
  23. package/dist/node/internal-node-compression.d.ts.map +1 -1
  24. package/dist/node/internal-node-compression.js +16 -0
  25. package/dist/node/internal-node-request.d.ts +21 -0
  26. package/dist/node/internal-node-request.d.ts.map +1 -1
  27. package/dist/node/internal-node-request.js +100 -29
  28. package/dist/node/internal-node-response.d.ts +21 -1
  29. package/dist/node/internal-node-response.d.ts.map +1 -1
  30. package/dist/node/internal-node-response.js +42 -3
  31. package/dist/node/internal-node.d.ts +40 -0
  32. package/dist/node/internal-node.d.ts.map +1 -1
  33. package/dist/node/internal-node.js +56 -3
  34. package/dist/node/node-request.d.ts +1 -1
  35. package/dist/node/node-request.d.ts.map +1 -1
  36. package/dist/node/node-request.js +1 -1
  37. package/dist/platform-shell.d.ts +4 -0
  38. package/dist/platform-shell.d.ts.map +1 -1
  39. package/dist/platform-shell.js +72 -20
  40. package/dist/request-transaction.d.ts +28 -0
  41. package/dist/request-transaction.d.ts.map +1 -1
  42. package/dist/request-transaction.js +33 -0
  43. package/dist/types.d.ts +9 -0
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/web.d.ts.map +1 -1
  46. package/dist/web.js +116 -40
  47. package/package.json +6 -6
package/README.ko.md CHANGED
@@ -123,6 +123,13 @@ class UsersModule {}
123
123
  ## 동작 계약
124
124
 
125
125
  - 요청 바디 파싱은 Web 표준 요청과 Node 기반 요청 모두에서 바이트가 스트리밍되는 동안 `maxBodySize`를 강제합니다.
126
+ - Node 기반 및 Web 표준 요청 wrapper는 바디 파싱 전에 저비용 요청 metadata를 snapshot으로 고정한 뒤 dispatch 경계에서 `body`/`rawBody`를 한 번 materialize하므로 userland는 계속 동기 parsed 값을 관찰합니다.
127
+ - Node 기반 쿠키/쿼리 값과 Web 표준 헤더는 요청 wrapper가 생성되는 시점에 snapshot으로 고정된 뒤 요청별로 lazy하게 normalize되고 memoize됩니다. 이후 upstream 객체가 변경되어도 `FrameworkRequest` view는 바뀌지 않습니다.
128
+ - `ApplicationContext.get()`과 `Application.get()`은 bootstrap 시점에 알려진 직접 root singleton class/factory provider 조회만 memoize하며, alias, request, transient, 종료 이후, multi-provider, `container.override()` 해석 의미는 그대로 유지합니다.
129
+ - `multi: true` provider token은 context cache에 memoize되지 않습니다. 각 `get()` 호출은 DI로 위임되어 컨테이너가 새로운 contribution 배열을 조립하며, 각 contribution 자체는 해당 provider scope에 따라 재사용됩니다.
130
+ - `duplicateProviderPolicy`가 `warn` 또는 `ignore`일 때 context cache 적격성과 lifecycle hook 실행은 bootstrap이 선택한 effective winning provider를 기준으로 결정됩니다. stale losing provider는 cache entry나 lifecycle hook을 만들지 않습니다.
131
+ - 애플리케이션 또는 컨텍스트 bootstrap이 런타임 리소스나 lifecycle instance 생성 이후 실패하면 fluo는 readiness를 초기화하고, 등록된 runtime cleanup callback을 실행하며, 그 시점까지 해석된 instance의 shutdown hook을 `bootstrap-failed`로 호출하고, 컨테이너를 dispose하고, cleanup 실패를 로그로 남긴 뒤 원래 bootstrap error를 다시 던집니다.
132
+ - Bootstrap은 독립적인 singleton lifecycle provider를 병렬로 해석한 뒤 lifecycle hook은 결정적인 provider 순서대로 실행합니다.
126
133
  - 멀티파트 파싱은 누적 바디 크기가 설정된 `multipart.maxTotalSize`를 넘으면 즉시 거부되며, 런타임 어댑터는 별도 재정의가 없으면 이 한도를 `maxBodySize`와 동일하게 맞춥니다.
127
134
  - 응답 스트림 백프레셔 헬퍼는 `drain`, `close`, `error` 중 어느 경우에도 `waitForDrain()`을 완료시켜 끊어진 연결에서 스트리밍 작성기가 멈추지 않도록 합니다.
128
135
  - 런타임 health 모듈은 bootstrap이 ready로 표시하기 전까지 `/ready`를 HTTP 503과 `starting`으로 보고하며, 애플리케이션/컨텍스트 종료가 시작되는 즉시, 종료 시도가 실패하더라도 다시 `starting`으로 내려갑니다.
package/README.md CHANGED
@@ -123,6 +123,13 @@ class UsersModule {}
123
123
  ## Behavioral Contracts
124
124
 
125
125
  - Request body parsing enforces `maxBodySize` while bytes are still streaming for both Web-standard and Node-backed requests.
126
+ - Node-backed and Web-standard request wrappers snapshot cheap request metadata before body parsing, then materialize `body`/`rawBody` once at the dispatch boundary so userland continues to observe synchronous parsed values.
127
+ - Node-backed cookies/query values and Web-standard headers are snapshotted when the request wrapper is created, then lazily normalized and memoized per request; later upstream object mutations do not change the `FrameworkRequest` view.
128
+ - `ApplicationContext.get()` and `Application.get()` memoize only direct root singleton class/factory provider lookups known at bootstrap, while preserving alias, request, transient, post-close, multi-provider, and `container.override()` resolution semantics.
129
+ - `multi: true` provider tokens are not context-cache memoized: each `get()` call delegates to DI so the container can assemble a fresh contribution array while still reusing each contribution according to its own provider scope.
130
+ - When `duplicateProviderPolicy` is `warn` or `ignore`, context-cache eligibility and lifecycle hook execution are based on the effective winning provider selected by bootstrap; stale losing providers do not seed cache entries or lifecycle hooks.
131
+ - If application or context bootstrap fails after runtime resources or lifecycle instances have been created, fluo resets readiness, runs registered runtime cleanup callbacks, invokes shutdown hooks for instances resolved so far with `bootstrap-failed`, disposes the container, logs cleanup failures, and rethrows the original bootstrap error.
132
+ - Bootstrap resolves independent singleton lifecycle providers concurrently, then runs lifecycle hooks in deterministic provider order.
126
133
  - Multipart parsing rejects payloads when the cumulative body size exceeds the configured `multipart.maxTotalSize`; runtime adapters default that limit to `maxBodySize` unless you override it.
127
134
  - Response stream backpressure helpers settle `waitForDrain()` on `drain`, `close`, or `error` so streaming writers do not hang on dead connections.
128
135
  - Runtime health modules report `/ready` as `starting` with HTTP 503 until bootstrap marks them ready, and they return to `starting` as soon as application/context shutdown begins, including failed shutdown attempts.
@@ -1,11 +1,14 @@
1
1
  import type { Dispatcher, FrameworkRequest, FrameworkResponse } from '@fluojs/http';
2
+ /** Request/response factory seam used by shared HTTP adapter dispatch helpers. */
2
3
  export interface RequestResponseFactory<RawRequest, RawResponse, Response extends FrameworkResponse = FrameworkResponse> {
3
4
  createRequest(rawRequest: RawRequest, signal: AbortSignal): Promise<FrameworkRequest>;
4
5
  createRequestSignal(rawResponse: RawResponse): AbortSignal;
5
6
  createResponse(rawResponse: RawResponse, rawRequest: RawRequest): Response;
7
+ materializeRequest?(request: FrameworkRequest): Promise<void>;
6
8
  resolveRequestId(rawRequest: RawRequest): string | undefined;
7
9
  writeErrorResponse(error: unknown, response: Response, requestId?: string): Promise<void>;
8
10
  }
11
+ /** Options for dispatching one raw platform request through a request/response factory. */
9
12
  export interface DispatchWithRequestResponseFactoryOptions<RawRequest, RawResponse, Response extends FrameworkResponse = FrameworkResponse> {
10
13
  dispatcher?: Dispatcher;
11
14
  dispatcherNotReadyMessage: string;
@@ -13,5 +16,11 @@ export interface DispatchWithRequestResponseFactoryOptions<RawRequest, RawRespon
13
16
  rawRequest: RawRequest;
14
17
  rawResponse: RawResponse;
15
18
  }
19
+ /**
20
+ * Dispatches one raw platform request through the shared request/response factory lifecycle.
21
+ *
22
+ * @param options - Factory, dispatcher, and raw platform request/response values for one dispatch.
23
+ * @returns The framework response after dispatch, error serialization, or default finalization.
24
+ */
16
25
  export declare function dispatchWithRequestResponseFactory<RawRequest, RawResponse, Response extends FrameworkResponse = FrameworkResponse>({ dispatcher, dispatcherNotReadyMessage, factory, rawRequest, rawResponse, }: DispatchWithRequestResponseFactoryOptions<RawRequest, RawResponse, Response>): Promise<Response>;
17
26
  //# sourceMappingURL=request-response-factory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"request-response-factory.d.ts","sourceRoot":"","sources":["../../src/adapters/request-response-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEpF,MAAM,WAAW,sBAAsB,CACrC,UAAU,EACV,WAAW,EACX,QAAQ,SAAS,iBAAiB,GAAG,iBAAiB;IAEtD,aAAa,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACtF,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,CAAC;IAC3D,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC3E,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;IAC7D,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3F;AAED,MAAM,WAAW,yCAAyC,CACxD,UAAU,EACV,WAAW,EACX,QAAQ,SAAS,iBAAiB,GAAG,iBAAiB;IAEtD,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,yBAAyB,EAAE,MAAM,CAAC;IAClC,OAAO,EAAE,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AU,EACV,WAAW,EACX,QAAQ,SAAS,iBAAiB,GAAG,iBAAiB;IAEtD,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,yBAAyB,EAAE,MAAM,CAAC;IAClC,OAAO,EAAE,sBAAsB,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IACnE,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAsB,kCAAkC,CACtD,UAAU,EACV,WAAW,EACX,QAAQ,SAAS,iBAAiB,GAAG,iBAAiB,EACtD,EACA,UAAU,EACV,yBAAyB,EACzB,OAAO,EACP,UAAU,EACV,WAAW,GACZ,EAAE,yCAAyC,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2BlG"}
@@ -1,3 +1,13 @@
1
+ /** Request/response factory seam used by shared HTTP adapter dispatch helpers. */
2
+
3
+ /** Options for dispatching one raw platform request through a request/response factory. */
4
+
5
+ /**
6
+ * Dispatches one raw platform request through the shared request/response factory lifecycle.
7
+ *
8
+ * @param options - Factory, dispatcher, and raw platform request/response values for one dispatch.
9
+ * @returns The framework response after dispatch, error serialization, or default finalization.
10
+ */
1
11
  export async function dispatchWithRequestResponseFactory({
2
12
  dispatcher,
3
13
  dispatcherNotReadyMessage,
@@ -9,6 +19,7 @@ export async function dispatchWithRequestResponseFactory({
9
19
  const signal = factory.createRequestSignal(rawResponse);
10
20
  try {
11
21
  const frameworkRequest = await factory.createRequest(rawRequest, signal);
22
+ await factory.materializeRequest?.(frameworkRequest);
12
23
  if (!dispatcher) {
13
24
  throw new Error(dispatcherNotReadyMessage);
14
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EAEX,uBAAuB,EAGvB,2BAA2B,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AAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,gBAAgB,GAAG,CAAC,CAIjG;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,GAAE,sBAA2B,GAAG,eAAe,CA+B7G;AA4pBD;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,WAAW,CAAC,CAqHrG;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB;;;;;;;OAOG;WACU,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,WAAW,CAAC;IAOzG;;;;;;;OAOG;WACU,wBAAwB,CACnC,UAAU,EAAE,UAAU,EACtB,OAAO,GAAE,+BAAoC,GAC5C,OAAO,CAAC,kBAAkB,CAAC;IAoG9B;;;;;;;;OAQG;WACU,kBAAkB,CAC7B,UAAU,EAAE,UAAU,EACtB,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,uBAAuB,CAAC;CAuBpC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,oBAAc,CAAC"}
package/dist/bootstrap.js CHANGED
@@ -6,7 +6,7 @@ import { createDispatcher, createHandlerMapping } from '@fluojs/http';
6
6
  import { DuplicateProviderError } from './errors.js';
7
7
  import { createBootstrapTimingDiagnostics } from './health/diagnostics.js';
8
8
  import { createConsoleApplicationLogger } from './logging/logger.js';
9
- import { compileModuleGraph, createRuntimeTokenSet, providerToken } from './module-graph.js';
9
+ import { compileModuleGraph, providerToken } from './module-graph.js';
10
10
  import { createRuntimePlatformShell } from './platform-shell.js';
11
11
  import { APPLICATION_LOGGER, COMPILED_MODULES, HTTP_APPLICATION_ADAPTER, PLATFORM_SHELL, RUNTIME_CONTAINER } from './tokens.js';
12
12
  const DEFAULT_MICROSERVICE_TOKEN = Symbol.for('fluo.microservices.service');
@@ -158,44 +158,115 @@ function createDuplicateProviderMessage(token, moduleName, existingModuleName) {
158
158
  const tokenLabel = typeof token === 'function' ? token.name || '<anonymous>' : String(token);
159
159
  return `Duplicate provider token "${tokenLabel}" registered in module "${moduleName}". Previously registered in module "${existingModuleName}".`;
160
160
  }
161
- function collectProvidersForContainer(modules, runtimeProviders, policy, logger) {
162
- const selectedProviders = new Map();
161
+ function createDuplicateRuntimeProviderMessage(token) {
162
+ const tokenLabel = typeof token === 'function' ? token.name || '<anonymous>' : String(token);
163
+ return `Duplicate runtime provider token "${tokenLabel}" registered.`;
164
+ }
165
+ function handleDuplicateProvider(token, moduleName, existingModuleName, policy, logger) {
166
+ const message = createDuplicateProviderMessage(token, moduleName, existingModuleName);
167
+ if (policy === 'throw') {
168
+ throw new DuplicateProviderError(message, {
169
+ module: moduleName,
170
+ token,
171
+ phase: 'provider registration',
172
+ hint: `Remove the duplicate registration from one of the modules, use container.override() for intentional replacements, or set duplicateProviderPolicy to 'warn' or 'ignore'.`
173
+ });
174
+ }
175
+ if (policy === 'warn') {
176
+ logger?.warn(message, 'BootstrapModule');
177
+ }
178
+ }
179
+ function handleDuplicateRuntimeProvider(token, policy, logger) {
180
+ const message = createDuplicateRuntimeProviderMessage(token);
181
+ if (policy === 'throw') {
182
+ throw new DuplicateProviderError(message, {
183
+ module: '<runtime>',
184
+ token,
185
+ phase: 'provider registration',
186
+ hint: `Remove the duplicate runtime provider registration, use container.override() after bootstrap for intentional replacements, or set duplicateProviderPolicy to 'warn' or 'ignore'.`
187
+ });
188
+ }
189
+ if (policy === 'warn') {
190
+ logger?.warn(message, 'BootstrapModule');
191
+ }
192
+ }
193
+ function selectEffectiveBootstrapProviders(modules, runtimeProviders, rootModule, policy, logger) {
194
+ const selectedRuntimeProviderIndexes = new Map();
195
+ const selectedModuleProviderIndexes = new Map();
196
+ const runtimeMultiTokens = new Set();
197
+ const runtimeSingleTokens = new Set();
198
+ const runtimeProviderEntries = [];
199
+ const moduleProviderEntries = [];
163
200
  for (const runtimeProvider of runtimeProviders ?? []) {
164
201
  const token = providerToken(runtimeProvider);
165
- selectedProviders.set(token, {
202
+ const multi = isMultiProvider(runtimeProvider);
203
+ const existingRuntimeProviderIndex = selectedRuntimeProviderIndexes.get(token);
204
+ if (multi) {
205
+ runtimeMultiTokens.add(token);
206
+ } else {
207
+ runtimeSingleTokens.add(token);
208
+ }
209
+ if (!multi && existingRuntimeProviderIndex !== undefined) {
210
+ handleDuplicateRuntimeProvider(token, policy, logger);
211
+ }
212
+ runtimeProviderEntries.push({
166
213
  moduleName: '<runtime>',
167
214
  provider: runtimeProvider,
168
215
  source: 'runtime',
169
216
  token
170
217
  });
218
+ if (!multi) {
219
+ selectedRuntimeProviderIndexes.set(token, runtimeProviderEntries.length - 1);
220
+ }
171
221
  }
172
222
  for (const compiledModule of modules) {
173
223
  for (const provider of compiledModule.definition.providers ?? []) {
174
224
  const token = providerToken(provider);
175
- const existing = selectedProviders.get(token);
176
- if (existing && existing.source === 'module') {
177
- const message = createDuplicateProviderMessage(token, compiledModule.type.name, existing.moduleName);
178
- if (policy === 'throw') {
179
- throw new DuplicateProviderError(message, {
180
- module: compiledModule.type.name,
181
- token,
182
- phase: 'provider registration',
183
- hint: `Remove the duplicate registration from one of the modules, use container.override() for intentional replacements, or set duplicateProviderPolicy to 'warn' or 'ignore'.`
184
- });
185
- }
186
- if (policy === 'warn') {
187
- logger?.warn(message, 'BootstrapModule');
188
- }
225
+ const multi = isMultiProvider(provider);
226
+ const existingModuleProviderIndex = selectedModuleProviderIndexes.get(token);
227
+ const existing = existingModuleProviderIndex === undefined ? undefined : moduleProviderEntries[existingModuleProviderIndex];
228
+ if (!multi && existing && existing.source === 'module') {
229
+ handleDuplicateProvider(token, compiledModule.type.name, existing.moduleName, policy, logger);
189
230
  }
190
- selectedProviders.set(token, {
231
+ const entry = {
191
232
  moduleName: compiledModule.type.name,
233
+ moduleType: compiledModule.type,
192
234
  provider,
193
235
  source: 'module',
194
236
  token
195
- });
237
+ };
238
+ moduleProviderEntries.push(entry);
239
+ if (!multi) {
240
+ selectedModuleProviderIndexes.set(token, moduleProviderEntries.length - 1);
241
+ }
196
242
  }
197
243
  }
198
- return [...selectedProviders.values()].map(entry => entry.provider);
244
+ const selectedModuleProviderIndexesSet = new Set(selectedModuleProviderIndexes.values());
245
+ const selectedRuntimeProviderIndexesSet = new Set(selectedRuntimeProviderIndexes.values());
246
+ const moduleProviders = [];
247
+ const rootModuleProviders = [];
248
+ const effectiveRuntimeProviders = runtimeProviderEntries.filter((entry, index) => isMultiProvider(entry.provider) || selectedRuntimeProviderIndexesSet.has(index)).map(entry => entry.provider);
249
+ moduleProviderEntries.forEach((entry, index) => {
250
+ const multi = isMultiProvider(entry.provider);
251
+ if (entry.source !== 'module' || !multi && !selectedModuleProviderIndexesSet.has(index)) {
252
+ return;
253
+ }
254
+ if (runtimeSingleTokens.has(entry.token) || runtimeMultiTokens.has(entry.token) && !multi) {
255
+ return;
256
+ }
257
+ moduleProviders.push(entry.provider);
258
+ if (entry.moduleType === rootModule) {
259
+ rootModuleProviders.push(entry.provider);
260
+ }
261
+ });
262
+ return {
263
+ moduleProviders,
264
+ rootModuleProviders,
265
+ runtimeProviders: effectiveRuntimeProviders
266
+ };
267
+ }
268
+ function isMultiProvider(provider) {
269
+ return typeof provider === 'object' && provider !== null && 'multi' in provider && provider.multi === true;
199
270
  }
200
271
  function registerControllers(container, modules) {
201
272
  for (const compiledModule of modules) {
@@ -253,18 +324,18 @@ export function bootstrapModule(rootModule, options = {}) {
253
324
  const container = new Container();
254
325
  const policy = options.duplicateProviderPolicy ?? 'warn';
255
326
  const runtimeProviders = options.providers ?? [];
256
- const runtimeProviderTokens = createRuntimeTokenSet(runtimeProviders);
257
- const moduleProviders = collectProvidersForContainer(modules, runtimeProviders, policy, options.logger).filter(provider => !runtimeProviderTokens.has(providerToken(provider)));
258
- if (runtimeProviders.length > 0) {
259
- container.register(...runtimeProviders);
327
+ const effectiveProviders = selectEffectiveBootstrapProviders(modules, runtimeProviders, rootModule, policy, options.logger);
328
+ if (effectiveProviders.runtimeProviders.length > 0) {
329
+ container.register(...effectiveProviders.runtimeProviders);
260
330
  }
261
- if (moduleProviders.length > 0) {
262
- container.register(...moduleProviders);
331
+ if (effectiveProviders.moduleProviders.length > 0) {
332
+ container.register(...effectiveProviders.moduleProviders);
263
333
  }
264
334
  registerControllers(container, modules);
265
335
  registerModuleMiddleware(container, modules);
266
336
  return {
267
337
  container,
338
+ effectiveProviders,
268
339
  modules,
269
340
  rootModule
270
341
  };
@@ -277,9 +348,10 @@ class FluoApplication {
277
348
  applicationState = 'bootstrapped';
278
349
  closed = false;
279
350
  closingPromise;
351
+ contextResolutionCache = new Map();
280
352
  lifecycleInstances;
281
353
  connectedMicroservices = [];
282
- constructor(container, modules, rootModule, dispatcher, bootstrapTiming, adapter, hasHttpAdapter, platformShell, lifecycleInstances, logger, runtimeCleanup) {
354
+ constructor(container, modules, rootModule, dispatcher, bootstrapTiming, adapter, hasHttpAdapter, platformShell, lifecycleInstances, logger, runtimeCleanup, contextCacheableTokens) {
283
355
  this.container = container;
284
356
  this.modules = modules;
285
357
  this.rootModule = rootModule;
@@ -290,13 +362,18 @@ class FluoApplication {
290
362
  this.platformShell = platformShell;
291
363
  this.logger = logger;
292
364
  this.runtimeCleanup = runtimeCleanup;
365
+ this.contextCacheableTokens = contextCacheableTokens;
293
366
  this.lifecycleInstances = lifecycleInstances;
367
+ installContextCacheInvalidation(this.container, this.contextResolutionCache, this.contextCacheableTokens);
294
368
  }
295
369
  get state() {
296
370
  return this.applicationState;
297
371
  }
298
372
  async get(token) {
299
- return this.container.resolve(token);
373
+ if (this.closed) {
374
+ return this.container.resolve(token);
375
+ }
376
+ return resolveContextToken(this.container, token, this.contextCacheableTokens, this.contextResolutionCache);
300
377
  }
301
378
 
302
379
  /**
@@ -383,16 +460,22 @@ class FluoApplication {
383
460
  class FluoApplicationContext {
384
461
  closed = false;
385
462
  closingPromise;
386
- constructor(container, modules, rootModule, bootstrapTiming, lifecycleInstances, runtimeCleanup) {
463
+ contextResolutionCache = new Map();
464
+ constructor(container, modules, rootModule, bootstrapTiming, lifecycleInstances, runtimeCleanup, contextCacheableTokens) {
387
465
  this.container = container;
388
466
  this.modules = modules;
389
467
  this.rootModule = rootModule;
390
468
  this.bootstrapTiming = bootstrapTiming;
391
469
  this.lifecycleInstances = lifecycleInstances;
392
470
  this.runtimeCleanup = runtimeCleanup;
471
+ this.contextCacheableTokens = contextCacheableTokens;
472
+ installContextCacheInvalidation(this.container, this.contextResolutionCache, this.contextCacheableTokens);
393
473
  }
394
474
  async get(token) {
395
- return this.container.resolve(token);
475
+ if (this.closed) {
476
+ return this.container.resolve(token);
477
+ }
478
+ return resolveContextToken(this.container, token, this.contextCacheableTokens, this.contextResolutionCache);
396
479
  }
397
480
  async close(signal) {
398
481
  if (this.closed) {
@@ -492,22 +575,113 @@ class FluoMicroserviceApplication {
492
575
  /**
493
576
  * lifecycle hook이 있는 singleton provider 인스턴스를 미리 해석해 둔다.
494
577
  */
495
- async function resolveLifecycleInstances(container, providers) {
496
- const instances = [];
578
+ async function resolveLifecycleInstances(container, providers, resolvedInstances = []) {
579
+ const lifecycleEntries = [];
497
580
  const seen = new Set();
498
581
  for (const provider of providers) {
499
- const scope = providerScope(provider);
500
- if (scope === 'request' || scope === 'transient') {
501
- continue;
502
- }
503
582
  const token = providerToken(provider);
504
583
  if (seen.has(token)) {
505
584
  continue;
506
585
  }
586
+ if (isHookBearingValueProvider(provider)) {
587
+ seen.add(token);
588
+ lifecycleEntries.push({
589
+ token,
590
+ useValue: provider.useValue
591
+ });
592
+ continue;
593
+ }
594
+ if (!isDirectSingletonContextProvider(provider)) {
595
+ continue;
596
+ }
507
597
  seen.add(token);
508
- instances.push(await container.resolve(token));
598
+ lifecycleEntries.push({
599
+ token
600
+ });
601
+ }
602
+ const resolutionResults = await Promise.allSettled(lifecycleEntries.map(entry => entry.useValue ?? container.resolve(entry.token)));
603
+ let resolutionError;
604
+ let hasResolutionError = false;
605
+ for (const result of resolutionResults) {
606
+ if (result.status === 'fulfilled') {
607
+ resolvedInstances.push(result.value);
608
+ continue;
609
+ }
610
+ if (!hasResolutionError) {
611
+ resolutionError = result.reason;
612
+ hasResolutionError = true;
613
+ }
614
+ }
615
+ if (hasResolutionError) {
616
+ throw resolutionError;
509
617
  }
510
- return instances;
618
+ return resolvedInstances;
619
+ }
620
+ function createContextCacheableTokenSet(effectiveProviders, runtimeTokens) {
621
+ const cacheableTokens = new Set(runtimeTokens);
622
+ for (const provider of effectiveProviders.runtimeProviders) {
623
+ if (!isDirectSingletonContextProvider(provider)) {
624
+ continue;
625
+ }
626
+ cacheableTokens.add(providerToken(provider));
627
+ }
628
+ for (const provider of effectiveProviders.rootModuleProviders) {
629
+ if (!isDirectSingletonContextProvider(provider)) {
630
+ continue;
631
+ }
632
+ cacheableTokens.add(providerToken(provider));
633
+ }
634
+ return cacheableTokens;
635
+ }
636
+ function isDirectSingletonContextProvider(provider) {
637
+ if (isMultiProvider(provider)) {
638
+ return false;
639
+ }
640
+ if (typeof provider === 'function') {
641
+ return providerScope(provider) === 'singleton';
642
+ }
643
+ if ('useExisting' in provider || 'useValue' in provider) {
644
+ return false;
645
+ }
646
+ return providerScope(provider) === 'singleton';
647
+ }
648
+ function isHookBearingValueProvider(provider) {
649
+ return typeof provider === 'object' && provider !== null && 'useValue' in provider && hasLifecycleHook(provider.useValue);
650
+ }
651
+ function hasLifecycleHook(value) {
652
+ return isOnModuleInit(value) || isOnApplicationBootstrap(value) || isOnModuleDestroy(value) || isOnApplicationShutdown(value);
653
+ }
654
+ function installContextCacheInvalidation(container, cache, cacheableTokens) {
655
+ const cacheInvalidatingContainer = container;
656
+ const override = cacheInvalidatingContainer.override.bind(container);
657
+ cacheInvalidatingContainer.override = (...providers) => {
658
+ const result = override(...providers);
659
+ cache.clear();
660
+ for (const provider of providers) {
661
+ const token = providerToken(provider);
662
+ if (isDirectSingletonContextProvider(provider)) {
663
+ cacheableTokens.add(token);
664
+ } else {
665
+ cacheableTokens.delete(token);
666
+ }
667
+ }
668
+ return result;
669
+ };
670
+ }
671
+ async function resolveContextToken(container, token, cacheableTokens, cache) {
672
+ if (!cacheableTokens.has(token)) {
673
+ return container.resolve(token);
674
+ }
675
+ const cached = cache.get(token);
676
+ if (cached) {
677
+ return cached;
678
+ }
679
+ const resolution = container.resolve(token).catch(error => {
680
+ cache.delete(token);
681
+ throw error;
682
+ });
683
+ cache.set(token, resolution);
684
+ return resolution;
511
685
  }
512
686
 
513
687
  /**
@@ -604,9 +778,9 @@ function registerRuntimeApplicationContextTokens(bootstrapped, platformShell) {
604
778
  useValue: platformShell
605
779
  });
606
780
  }
607
- async function resolveBootstrapLifecycleInstances(bootstrapped, runtimeProviders) {
608
- const lifecycleProviders = [...runtimeProviders, ...bootstrapped.modules.flatMap(compiledModule => compiledModule.definition.providers ?? [])];
609
- return resolveLifecycleInstances(bootstrapped.container, lifecycleProviders);
781
+ async function resolveBootstrapLifecycleInstances(bootstrapped, resolvedInstances) {
782
+ const lifecycleProviders = [...bootstrapped.effectiveProviders.runtimeProviders, ...bootstrapped.effectiveProviders.moduleProviders];
783
+ return resolveLifecycleInstances(bootstrapped.container, lifecycleProviders, resolvedInstances);
610
784
  }
611
785
  async function runBootstrapLifecycle(modules, lifecycleInstances, logger, platformShell) {
612
786
  resetReadinessState(modules);
@@ -696,7 +870,7 @@ export async function bootstrapApplication(options) {
696
870
  bootstrappedContainer = bootstrapped.container;
697
871
  bootstrappedModules = bootstrapped.modules;
698
872
  const resolveLifecycleStart = timingEnabled ? runtimePerformance.now() : 0;
699
- lifecycleInstances = await resolveBootstrapLifecycleInstances(bootstrapped, runtimeProviders);
873
+ lifecycleInstances = await resolveBootstrapLifecycleInstances(bootstrapped, lifecycleInstances);
700
874
  lifecycleInstances.push({
701
875
  onModuleDestroy() {
702
876
  return platformShell.stop();
@@ -725,7 +899,7 @@ export async function bootstrapApplication(options) {
725
899
  });
726
900
  }
727
901
  const bootstrapTiming = timingEnabled ? createBootstrapTimingDiagnostics(timingPhases, runtimePerformance.now() - timingStart) : undefined;
728
- return new FluoApplication(bootstrapped.container, bootstrapped.modules, options.rootModule, dispatcher, bootstrapTiming, adapter, hasHttpAdapter, platformShell, lifecycleInstances, logger, runtimeCleanup);
902
+ return new FluoApplication(bootstrapped.container, bootstrapped.modules, options.rootModule, dispatcher, bootstrapTiming, adapter, hasHttpAdapter, platformShell, lifecycleInstances, logger, runtimeCleanup, createContextCacheableTokenSet(bootstrapped.effectiveProviders, [RUNTIME_CONTAINER, COMPILED_MODULES, HTTP_APPLICATION_ADAPTER, PLATFORM_SHELL]));
729
903
  } catch (error) {
730
904
  logger.error('Failed to bootstrap the fluo application. Check the error below for what failed and how to fix it.', error, 'FluoFactory');
731
905
  await runBootstrapFailureCleanup({
@@ -804,7 +978,7 @@ export class FluoFactory {
804
978
  bootstrappedContainer = bootstrapped.container;
805
979
  bootstrappedModules = bootstrapped.modules;
806
980
  const resolveLifecycleStart = timingEnabled ? runtimePerformance.now() : 0;
807
- lifecycleInstances = await resolveBootstrapLifecycleInstances(bootstrapped, runtimeProviders);
981
+ lifecycleInstances = await resolveBootstrapLifecycleInstances(bootstrapped, lifecycleInstances);
808
982
  lifecycleInstances.push({
809
983
  onModuleDestroy() {
810
984
  return platformShell.stop();
@@ -825,7 +999,7 @@ export class FluoFactory {
825
999
  });
826
1000
  }
827
1001
  const bootstrapTiming = timingEnabled ? createBootstrapTimingDiagnostics(timingPhases, runtimePerformance.now() - timingStart) : undefined;
828
- return new FluoApplicationContext(bootstrapped.container, bootstrapped.modules, rootModule, bootstrapTiming, lifecycleInstances, runtimeCleanup);
1002
+ return new FluoApplicationContext(bootstrapped.container, bootstrapped.modules, rootModule, bootstrapTiming, lifecycleInstances, runtimeCleanup, createContextCacheableTokenSet(bootstrapped.effectiveProviders, [RUNTIME_CONTAINER, COMPILED_MODULES, PLATFORM_SHELL]));
829
1003
  } catch (error) {
830
1004
  logger.error('Failed to bootstrap application context. Check the error below for what failed and how to fix it.', error, 'FluoFactory');
831
1005
  await runBootstrapFailureCleanup({
@@ -1,11 +1,17 @@
1
1
  import type { Scope } from '@fluojs/di';
2
2
  import type { CompiledModule, ModuleType } from '../types.js';
3
+ /**
4
+ * Describes the runtime diagnostics graph contract.
5
+ */
3
6
  export interface RuntimeDiagnosticsGraph {
4
7
  version: 1;
5
8
  rootModule: string;
6
9
  modules: RuntimeDiagnosticsModule[];
7
10
  relationships: RuntimeDiagnosticsRelationships;
8
11
  }
12
+ /**
13
+ * Describes the runtime diagnostics module contract.
14
+ */
9
15
  export interface RuntimeDiagnosticsModule {
10
16
  name: string;
11
17
  global: boolean;
@@ -14,12 +20,18 @@ export interface RuntimeDiagnosticsModule {
14
20
  providers: RuntimeDiagnosticsProvider[];
15
21
  exports: string[];
16
22
  }
23
+ /**
24
+ * Describes the runtime diagnostics provider contract.
25
+ */
17
26
  export interface RuntimeDiagnosticsProvider {
18
27
  token: string;
19
28
  type: 'class' | 'factory' | 'value' | 'existing';
20
29
  scope: Scope;
21
30
  multi: boolean;
22
31
  }
32
+ /**
33
+ * Describes the runtime diagnostics relationships contract.
34
+ */
23
35
  export interface RuntimeDiagnosticsRelationships {
24
36
  moduleImports: Array<{
25
37
  from: string;
@@ -41,16 +53,42 @@ export interface RuntimeDiagnosticsRelationships {
41
53
  module: string;
42
54
  }>;
43
55
  }
56
+ /**
57
+ * Describes the bootstrap timing phase contract.
58
+ */
44
59
  export interface BootstrapTimingPhase {
45
60
  durationMs: number;
46
61
  name: 'bootstrap_module' | 'register_runtime_tokens' | 'resolve_lifecycle_instances' | 'run_bootstrap_lifecycle' | 'create_dispatcher';
47
62
  }
63
+ /**
64
+ * Describes the bootstrap timing diagnostics contract.
65
+ */
48
66
  export interface BootstrapTimingDiagnostics {
49
67
  phases: BootstrapTimingPhase[];
50
68
  totalMs: number;
51
69
  version: 1;
52
70
  }
71
+ /**
72
+ * Create runtime diagnostics graph.
73
+ *
74
+ * @param modules The modules.
75
+ * @param rootModule The root module.
76
+ * @returns The create runtime diagnostics graph result.
77
+ */
53
78
  export declare function createRuntimeDiagnosticsGraph(modules: readonly CompiledModule[], rootModule: ModuleType): RuntimeDiagnosticsGraph;
79
+ /**
80
+ * Render runtime diagnostics mermaid.
81
+ *
82
+ * @param graph The graph.
83
+ * @returns The render runtime diagnostics mermaid result.
84
+ */
54
85
  export declare function renderRuntimeDiagnosticsMermaid(graph: RuntimeDiagnosticsGraph): string;
86
+ /**
87
+ * Create bootstrap timing diagnostics.
88
+ *
89
+ * @param phases The phases.
90
+ * @param totalMs The total ms.
91
+ * @returns The create bootstrap timing diagnostics result.
92
+ */
55
93
  export declare function createBootstrapTimingDiagnostics(phases: BootstrapTimingPhase[], totalMs: number): BootstrapTimingDiagnostics;
56
94
  //# sourceMappingURL=diagnostics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/health/diagnostics.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,KAAK,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,CAAC,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,wBAAwB,EAAE,CAAC;IACpC,aAAa,EAAE,+BAA+B,CAAC;CAChD;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,0BAA0B,EAAE,CAAC;IACxC,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,GAA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OAAO,CAAC;KAChB,CAAC,CAAC;IACH,iBAAiB,EAAE,KAAK,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EACA,kBAAkB,GAClB,yBAAyB,GACzB,6BAA6B,GAC7B,yBAAyB,GACzB,mBAAmB,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,CAAC,CAAC;CACZ;AAiFD;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,EAAE,UAAU,EAAE,UAAU,GAAG,uBAAuB,CAkEjI;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,uBAAuB,GAAG,MAAM,CAoCtF;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,oBAAoB,EAAE,EAC9B,OAAO,EAAE,MAAM,GACd,0BAA0B,CAS5B"}
@@ -1,4 +1,29 @@
1
1
  import { getClassDiMetadata } from '@fluojs/core/internal';
2
+
3
+ /**
4
+ * Describes the runtime diagnostics graph contract.
5
+ */
6
+
7
+ /**
8
+ * Describes the runtime diagnostics module contract.
9
+ */
10
+
11
+ /**
12
+ * Describes the runtime diagnostics provider contract.
13
+ */
14
+
15
+ /**
16
+ * Describes the runtime diagnostics relationships contract.
17
+ */
18
+
19
+ /**
20
+ * Describes the bootstrap timing phase contract.
21
+ */
22
+
23
+ /**
24
+ * Describes the bootstrap timing diagnostics contract.
25
+ */
26
+
2
27
  function roundMs(value) {
3
28
  return Number(value.toFixed(3));
4
29
  }
@@ -59,6 +84,14 @@ function normalizeProvider(provider) {
59
84
  type: providerShape(provider)
60
85
  };
61
86
  }
87
+
88
+ /**
89
+ * Create runtime diagnostics graph.
90
+ *
91
+ * @param modules The modules.
92
+ * @param rootModule The root module.
93
+ * @returns The create runtime diagnostics graph result.
94
+ */
62
95
  export function createRuntimeDiagnosticsGraph(modules, rootModule) {
63
96
  const moduleDiagnostics = [];
64
97
  const moduleImports = [];
@@ -119,6 +152,13 @@ export function createRuntimeDiagnosticsGraph(modules, rootModule) {
119
152
  version: 1
120
153
  };
121
154
  }
155
+
156
+ /**
157
+ * Render runtime diagnostics mermaid.
158
+ *
159
+ * @param graph The graph.
160
+ * @returns The render runtime diagnostics mermaid result.
161
+ */
122
162
  export function renderRuntimeDiagnosticsMermaid(graph) {
123
163
  const lines = ['graph TD'];
124
164
  const nodeByModule = new Map();
@@ -143,6 +183,14 @@ export function renderRuntimeDiagnosticsMermaid(graph) {
143
183
  }
144
184
  return lines.join('\n');
145
185
  }
186
+
187
+ /**
188
+ * Create bootstrap timing diagnostics.
189
+ *
190
+ * @param phases The phases.
191
+ * @param totalMs The total ms.
192
+ * @returns The create bootstrap timing diagnostics result.
193
+ */
146
194
  export function createBootstrapTimingDiagnostics(phases, totalMs) {
147
195
  return {
148
196
  phases: phases.map(phase => ({