@fluojs/http 1.0.0-beta.10 → 1.0.0-beta.11
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.ko.md +4 -1
- package/README.md +4 -1
- package/dist/context/request-context-node-store.d.ts +25 -0
- package/dist/context/request-context-node-store.d.ts.map +1 -0
- package/dist/context/request-context-node-store.js +32 -0
- package/dist/context/request-context-stack-store.d.ts +8 -0
- package/dist/context/request-context-stack-store.d.ts.map +1 -0
- package/dist/context/request-context-stack-store.js +29 -0
- package/dist/context/request-context-store.d.ts +7 -0
- package/dist/context/request-context-store.d.ts.map +1 -0
- package/dist/context/request-context-store.js +1 -0
- package/dist/context/request-context.d.ts +7 -3
- package/dist/context/request-context.d.ts.map +1 -1
- package/dist/context/request-context.js +17 -5
- package/dist/dispatch/dispatcher.d.ts.map +1 -1
- package/dist/dispatch/dispatcher.js +4 -0
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/middleware/correlation.d.ts.map +1 -1
- package/dist/middleware/correlation.js +8 -2
- package/package.json +4 -4
package/README.ko.md
CHANGED
|
@@ -96,6 +96,8 @@ function someDeepHelper() {
|
|
|
96
96
|
}
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
+
`runWithRequestContext(...)`는 호스트가 `globalThis.AsyncLocalStorage` 또는 Node 내장 `node:async_hooks` 모듈로 `AsyncLocalStorage`를 제공할 때 활성 컨텍스트를 `await` 이후까지 보존합니다. 선언된 `>=20.0.0` 지원 범위의 Node 런타임은 `process.getBuiltinModule(...)`이 없어도 `node:async_hooks`를 동적으로 해석해 ALS 의미론을 유지합니다. 비동기 컨텍스트 primitive가 없는 비 Node 호스트에서는 동기 stack fallback을 사용하며, 겹치는 비동기 요청이 서로의 컨텍스트를 관찰하지 않도록 awaited continuation이 재개되기 전에 컨텍스트를 비웁니다.
|
|
100
|
+
|
|
99
101
|
### 프록시 뒤의 속도 제한
|
|
100
102
|
|
|
101
103
|
`createRateLimitMiddleware(...)`는 기본적으로 raw socket `remoteAddress`만으로 클라이언트 식별자를 해석합니다. `Forwarded`, `X-Forwarded-For`, `X-Real-IP`를 신뢰하려면 해당 헤더를 신뢰 가능한 프록시가 덮어쓰는 환경에서만 `trustProxyHeaders: true`를 명시적으로 켜세요. 어댑터가 신뢰 가능한 프록시 체인도 raw socket 식별자도 제공하지 않는다면 공유 fallback 버킷에 의존하지 말고 명시적인 `keyResolver`를 설정하세요.
|
|
@@ -133,7 +135,7 @@ Fluo의 HTTP 데코레이터는 TC39 표준 데코레이터이며, runtime 또
|
|
|
133
135
|
|
|
134
136
|
## 요청 정리와 런타임 이식성
|
|
135
137
|
|
|
136
|
-
디스패처는 활성 dispatch 동안에만
|
|
138
|
+
디스패처는 활성 dispatch 동안에만 호스트 비동기 컨텍스트 저장소로 `RequestContext`를 바인딩합니다. 지원되는 Node 20+ 런타임을 포함해 `AsyncLocalStorage`가 있는 호스트에서는 컨텍스트가 awaited work 이후까지 유지됩니다. 비동기 컨텍스트 primitive가 없는 비 Node 호스트에서는 fallback 컨텍스트가 동기 프레임에만 유효하고, 겹치는 요청이 서로의 컨텍스트를 관찰하지 않도록 `await` 이후에는 의도적으로 사용할 수 없습니다. 요청이 controller graph, middleware, guard, interceptor, observer, DTO converter, custom binder 또는 수동 `getCurrentRequestContext()` / `assertRequestContext()` container 접근을 통해 request-scoped DI를 사용할 수 있으면, 디스패처는 요청 observer가 끝난 뒤 `finally` 경로에서 isolated request-scoped DI 컨테이너를 생성하고 dispose합니다. Singleton-only route는 `RequestContext.container`가 접근되기 전까지 이 컨테이너 lifecycle을 건너뛰어 baseline 경로의 불필요한 per-request allocation을 피하면서도, graph가 모호하거나 request-scoped이면 request-scoped provider isolation을 유지합니다. 따라서 공개 `RequestContext.container` 읽기는 request-scoped provider resolve에 항상 안전합니다. singleton-only fast path는 내부 dispatcher 최적화일 뿐, 공개 context가 root container를 노출한다는 약속이 아닙니다.
|
|
137
139
|
|
|
138
140
|
어댑터는 플랫폼이 제공한다면 `FrameworkRequest.signal`에 `AbortSignal`을 전달해야 합니다. SSE에서는 가능하면 `FrameworkResponse.stream.onClose(...)`도 노출해야 합니다. `SseResponse`는 request abort와 raw stream close를 모두 구독하고, 멱등하게 닫히며, 어느 쪽이 먼저 종료되더라도 등록한 listener를 제거합니다.
|
|
139
141
|
|
|
@@ -158,6 +160,7 @@ Fluo의 HTTP 데코레이터는 TC39 표준 데코레이터이며, runtime 또
|
|
|
158
160
|
- Native route handoff는 framework request에 붙는 시점의 method와 path를 함께 스냅샷합니다. app middleware가 handler matching 전에 둘 중 하나를 rewrite하면 dispatcher는 stale handoff를 무시하고 일반 route matching으로 fallback합니다.
|
|
159
161
|
- `isRoutePathNormalizationSensitive(path)`: duplicate slash와 trailing slash 요청을 generic dispatcher 경로에 남기기 위한 내부 guard.
|
|
160
162
|
- `resolveClientIdentity(request)`: 속도 제한과 런타임 통합에서 사용하는 보수적 클라이언트 식별 해석기.
|
|
163
|
+
- `createFetchStyleHttpAdapterRealtimeCapability(...)`, `Dispatcher`, `HttpApplicationAdapter`: 전체 HTTP root barrel을 instantiate하면 안 되는 edge/fetch-style platform package를 위한 내부 adapter seam.
|
|
161
164
|
|
|
162
165
|
## 관련 패키지
|
|
163
166
|
|
package/README.md
CHANGED
|
@@ -98,6 +98,8 @@ function someDeepHelper() {
|
|
|
98
98
|
}
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
`runWithRequestContext(...)` preserves the active context across awaited work when the host provides `AsyncLocalStorage` through `globalThis.AsyncLocalStorage` or Node's built-in `node:async_hooks` module. Node runtimes in the declared `>=20.0.0` support range keep ALS semantics even when `process.getBuiltinModule(...)` is unavailable by resolving `node:async_hooks` dynamically. Non-Node hosts without an async-context primitive use a synchronous stack fallback that clears the context before awaited continuations resume, avoiding cross-request leaks instead of pretending to isolate overlapping async work.
|
|
102
|
+
|
|
101
103
|
### Rate limiting behind proxies
|
|
102
104
|
|
|
103
105
|
`createRateLimitMiddleware(...)` resolves client identity from the raw socket `remoteAddress` by default. To trust `Forwarded`, `X-Forwarded-For`, or `X-Real-IP`, opt in with `trustProxyHeaders: true` only when your adapter sits behind a trusted proxy that overwrites those headers. If your adapter exposes neither a trusted proxy chain nor a raw socket identity, provide an explicit `keyResolver`.
|
|
@@ -135,7 +137,7 @@ This compatibility path is an execution fallback for Bun bundle output; applicat
|
|
|
135
137
|
|
|
136
138
|
## Request Cleanup and Portability
|
|
137
139
|
|
|
138
|
-
The dispatcher binds `RequestContext` with
|
|
140
|
+
The dispatcher binds `RequestContext` with host async-context storage for the active dispatch only. On hosts with `AsyncLocalStorage`, including supported Node 20+ runtimes, the context remains available across awaited work. On non-Node hosts without an async-context primitive, the fallback context is synchronous-only and intentionally unavailable after `await` so overlapping requests cannot observe one another's context. When a request may use request-scoped DI through its controller graph, middleware, guards, interceptors, observers, DTO converters, a custom binder, or manual `getCurrentRequestContext()` / `assertRequestContext()` container access, the dispatcher creates and disposes an isolated request-scoped DI container from its `finally` path after request observers finish. Singleton-only routes skip that container lifecycle until `RequestContext.container` is accessed, so the baseline path avoids unnecessary per-request allocation while preserving request-scoped provider isolation whenever the graph is ambiguous or request-scoped. Public `RequestContext.container` reads are therefore always safe for resolving request-scoped providers; the singleton-only fast path is an internal dispatcher optimization, not a promise that the public context exposes the root container.
|
|
139
141
|
|
|
140
142
|
Adapters should pass an `AbortSignal` on `FrameworkRequest.signal` when the platform exposes one. For SSE, adapters should also expose `FrameworkResponse.stream.onClose(...)` when possible; `SseResponse` listens to both request abort and raw stream close, closes idempotently, and removes registered listeners when either side terminates first.
|
|
141
143
|
|
|
@@ -160,6 +162,7 @@ The `./internal` subpath exports only the low-level utilities used by platform a
|
|
|
160
162
|
- Native route handoffs snapshot the framework request method and path when attached; if app middleware rewrites either value before handler matching, the dispatcher ignores the stale handoff and falls back to normal route matching.
|
|
161
163
|
- `isRoutePathNormalizationSensitive(path)`: Internal guard for keeping duplicate-slash and trailing-slash requests on the generic dispatcher path.
|
|
162
164
|
- `resolveClientIdentity(request)`: Conservative client identity resolver used by rate limiting and other runtime integrations.
|
|
165
|
+
- `createFetchStyleHttpAdapterRealtimeCapability(...)`, `Dispatcher`, and `HttpApplicationAdapter`: internal adapter seams for edge/fetch-style platform packages that must avoid instantiating the full HTTP root barrel.
|
|
163
166
|
|
|
164
167
|
## Related Packages
|
|
165
168
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RequestContextStore } from './request-context-store.js';
|
|
2
|
+
type AsyncLocalStorageConstructor = new () => RequestContextStore;
|
|
3
|
+
type NodeAsyncHooksModule = {
|
|
4
|
+
AsyncLocalStorage?: AsyncLocalStorageConstructor;
|
|
5
|
+
};
|
|
6
|
+
type AsyncLocalStorageResolutionHost = {
|
|
7
|
+
AsyncLocalStorage?: AsyncLocalStorageConstructor;
|
|
8
|
+
process?: {
|
|
9
|
+
getBuiltinModule?(id: 'node:async_hooks'): NodeAsyncHooksModule;
|
|
10
|
+
versions?: {
|
|
11
|
+
node?: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type NodeAsyncHooksLoader = () => Promise<NodeAsyncHooksModule>;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the host `AsyncLocalStorage` constructor without eagerly importing Node built-ins.
|
|
18
|
+
*
|
|
19
|
+
* @param host Host global-like object to inspect for async-context support.
|
|
20
|
+
* @param loadNodeAsyncHooks Lazy loader for Node's `node:async_hooks` module.
|
|
21
|
+
* @returns The resolved `AsyncLocalStorage` constructor, or `undefined` when unavailable.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveAsyncLocalStorageConstructor(host?: AsyncLocalStorageResolutionHost, loadNodeAsyncHooks?: NodeAsyncHooksLoader): Promise<AsyncLocalStorageConstructor | undefined>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=request-context-node-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context-node-store.d.ts","sourceRoot":"","sources":["../../src/context/request-context-node-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,KAAK,4BAA4B,GAAG,UAAU,mBAAmB,CAAC;AAElE,KAAK,oBAAoB,GAAG;IAC1B,iBAAiB,CAAC,EAAE,4BAA4B,CAAC;CAClD,CAAC;AAEF,KAAK,+BAA+B,GAAG;IACrC,iBAAiB,CAAC,EAAE,4BAA4B,CAAC;IACjD,OAAO,CAAC,EAAE;QACR,gBAAgB,CAAC,CAAC,EAAE,EAAE,kBAAkB,GAAG,oBAAoB,CAAC;QAChE,QAAQ,CAAC,EAAE;YACT,IAAI,CAAC,EAAE,MAAM,CAAC;SACf,CAAC;KACH,CAAC;CACH,CAAC;AAEF,KAAK,oBAAoB,GAAG,MAAM,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEhE;;;;;;GAMG;AACH,wBAAsB,mCAAmC,CACvD,IAAI,GAAE,+BAA4C,EAClD,kBAAkB,GAAE,oBAA2C,GAC9D,OAAO,CAAC,4BAA4B,GAAG,SAAS,CAAC,CAsBnD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves the host `AsyncLocalStorage` constructor without eagerly importing Node built-ins.
|
|
3
|
+
*
|
|
4
|
+
* @param host Host global-like object to inspect for async-context support.
|
|
5
|
+
* @param loadNodeAsyncHooks Lazy loader for Node's `node:async_hooks` module.
|
|
6
|
+
* @returns The resolved `AsyncLocalStorage` constructor, or `undefined` when unavailable.
|
|
7
|
+
*/
|
|
8
|
+
export async function resolveAsyncLocalStorageConstructor(host = globalThis, loadNodeAsyncHooks = importNodeAsyncHooks) {
|
|
9
|
+
if (typeof host.AsyncLocalStorage === 'function') {
|
|
10
|
+
return host.AsyncLocalStorage;
|
|
11
|
+
}
|
|
12
|
+
const builtinAsyncLocalStorage = host.process?.getBuiltinModule?.('node:async_hooks').AsyncLocalStorage;
|
|
13
|
+
if (typeof builtinAsyncLocalStorage === 'function') {
|
|
14
|
+
return builtinAsyncLocalStorage;
|
|
15
|
+
}
|
|
16
|
+
if (!isNodeHost(host)) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const nodeAsyncHooks = await loadNodeAsyncHooks();
|
|
21
|
+
return nodeAsyncHooks.AsyncLocalStorage;
|
|
22
|
+
} catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function isNodeHost(host) {
|
|
27
|
+
return typeof host.process?.versions?.node === 'string';
|
|
28
|
+
}
|
|
29
|
+
function importNodeAsyncHooks() {
|
|
30
|
+
const nodeAsyncHooksSpecifier = `node:${'async_hooks'}`;
|
|
31
|
+
return import(nodeAsyncHooksSpecifier);
|
|
32
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RequestContextStore } from './request-context-store.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the synchronous fallback request-context store used when no async-context primitive exists.
|
|
4
|
+
*
|
|
5
|
+
* @returns A stack-backed request-context store scoped to synchronous callback frames.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createStackRequestContextStore(): RequestContextStore;
|
|
8
|
+
//# sourceMappingURL=request-context-stack-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context-stack-store.d.ts","sourceRoot":"","sources":["../../src/context/request-context-stack-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE;;;;GAIG;AACH,wBAAgB,8BAA8B,IAAI,mBAAmB,CAmBpE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the synchronous fallback request-context store used when no async-context primitive exists.
|
|
3
|
+
*
|
|
4
|
+
* @returns A stack-backed request-context store scoped to synchronous callback frames.
|
|
5
|
+
*/
|
|
6
|
+
export function createStackRequestContextStore() {
|
|
7
|
+
const stack = [];
|
|
8
|
+
return {
|
|
9
|
+
getStore() {
|
|
10
|
+
return stack.at(-1);
|
|
11
|
+
},
|
|
12
|
+
run(context, callback) {
|
|
13
|
+
stack.push(context);
|
|
14
|
+
try {
|
|
15
|
+
return callback();
|
|
16
|
+
} catch (error) {
|
|
17
|
+
throw error;
|
|
18
|
+
} finally {
|
|
19
|
+
removeStackContext(stack, context);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function removeStackContext(stack, context) {
|
|
25
|
+
const index = stack.lastIndexOf(context);
|
|
26
|
+
if (index >= 0) {
|
|
27
|
+
stack.splice(index, 1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RequestContext } from '../types.js';
|
|
2
|
+
/** Store abstraction shared by host async-context implementations and the synchronous fallback. */
|
|
3
|
+
export type RequestContextStore = {
|
|
4
|
+
getStore(): RequestContext | undefined;
|
|
5
|
+
run<T>(context: RequestContext, callback: () => T): T;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=request-context-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context-store.d.ts","sourceRoot":"","sources":["../../src/context/request-context-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,mGAAmG;AACnG,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,IAAI,cAAc,GAAG,SAAS,CAAC;IACvC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;CACvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { ContextKey, RequestContext } from '../types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Runs a callback inside the request-scoped
|
|
3
|
+
* Runs a callback inside the request-scoped async context.
|
|
4
|
+
*
|
|
5
|
+
* Hosts with `AsyncLocalStorage` preserve the context across awaited work. Hosts without an async
|
|
6
|
+
* context primitive use a stack fallback that keeps the context only for the synchronous callback
|
|
7
|
+
* frame and clears it before awaited continuations resume.
|
|
4
8
|
*
|
|
5
9
|
* @param context Request context snapshot to bind to the current async execution chain.
|
|
6
10
|
* @param callback Callback executed with `context` available through request-context helpers.
|
|
@@ -21,9 +25,9 @@ export declare function getCurrentRequestContext(): RequestContext | undefined;
|
|
|
21
25
|
*/
|
|
22
26
|
export declare function assertRequestContext(): RequestContext;
|
|
23
27
|
/**
|
|
24
|
-
* Creates a defensive clone of a request context for
|
|
28
|
+
* Creates a defensive clone of a request context for async-context storage.
|
|
25
29
|
*
|
|
26
|
-
* @param context Request context to clone before storing in
|
|
30
|
+
* @param context Request context to clone before storing in the active async-context store.
|
|
27
31
|
* @returns A shallow clone with copied metadata map to avoid cross-request mutation.
|
|
28
32
|
*/
|
|
29
33
|
export declare function createRequestContext(context: RequestContext): RequestContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-context.d.ts","sourceRoot":"","sources":["../../src/context/request-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request-context.d.ts","sourceRoot":"","sources":["../../src/context/request-context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAO9D;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAEtF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,cAAc,GAAG,SAAS,CAErE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CAUrD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAK5E;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAKtE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAE7F;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAE9F"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
1
|
import { FluoError } from '@fluojs/core';
|
|
3
|
-
|
|
2
|
+
import { resolveAsyncLocalStorageConstructor } from './request-context-node-store.js';
|
|
3
|
+
import { createStackRequestContextStore } from './request-context-stack-store.js';
|
|
4
|
+
const requestContextStore = await createRequestContextStore();
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
* Runs a callback inside the request-scoped
|
|
7
|
+
* Runs a callback inside the request-scoped async context.
|
|
8
|
+
*
|
|
9
|
+
* Hosts with `AsyncLocalStorage` preserve the context across awaited work. Hosts without an async
|
|
10
|
+
* context primitive use a stack fallback that keeps the context only for the synchronous callback
|
|
11
|
+
* frame and clears it before awaited continuations resume.
|
|
7
12
|
*
|
|
8
13
|
* @param context Request context snapshot to bind to the current async execution chain.
|
|
9
14
|
* @param callback Callback executed with `context` available through request-context helpers.
|
|
@@ -39,9 +44,9 @@ export function assertRequestContext() {
|
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
/**
|
|
42
|
-
* Creates a defensive clone of a request context for
|
|
47
|
+
* Creates a defensive clone of a request context for async-context storage.
|
|
43
48
|
*
|
|
44
|
-
* @param context Request context to clone before storing in
|
|
49
|
+
* @param context Request context to clone before storing in the active async-context store.
|
|
45
50
|
* @returns A shallow clone with copied metadata map to avoid cross-request mutation.
|
|
46
51
|
*/
|
|
47
52
|
export function createRequestContext(context) {
|
|
@@ -86,4 +91,11 @@ export function getContextValue(context, key) {
|
|
|
86
91
|
*/
|
|
87
92
|
export function setContextValue(context, key, value) {
|
|
88
93
|
context.metadata[key.id] = value;
|
|
94
|
+
}
|
|
95
|
+
async function createRequestContextStore() {
|
|
96
|
+
const AsyncLocalStorage = await resolveAsyncLocalStorageConstructor();
|
|
97
|
+
if (typeof AsyncLocalStorage === 'function') {
|
|
98
|
+
return new AsyncLocalStorage();
|
|
99
|
+
}
|
|
100
|
+
return createStackRequestContextStore();
|
|
89
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAyB,MAAM,YAAY,CAAC;AAQnE,OAAO,KAAK,EACV,MAAM,EACN,yBAAyB,EACzB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAIjB,cAAc,EAEd,eAAe,EAEf,cAAc,EAId,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAKrB,OAAO,EAKL,KAAK,aAAa,EAOnB,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE5F,gEAAgE;AAChE,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,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B,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -356,6 +356,10 @@ async function dispatchNativeFastRoute(match, request, response, options, conten
|
|
|
356
356
|
if (!shouldUseFastPathForRequest(eligibility, request)) {
|
|
357
357
|
return false;
|
|
358
358
|
}
|
|
359
|
+
if (options.fastPathDebugHeaders === true && eligibility && !response.committed) {
|
|
360
|
+
const debugInfo = createPathDebugInfo(eligibility);
|
|
361
|
+
addPathDebugHeader(response.setHeader.bind(response), debugInfo);
|
|
362
|
+
}
|
|
359
363
|
const dispatchRequest = request;
|
|
360
364
|
const dispatchScope = createRootDispatchScope(options.rootContainer);
|
|
361
365
|
let phaseContext;
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { createFetchStyleHttpAdapterRealtimeCapability, type HttpApplicationAdapter, } from './adapter.js';
|
|
1
2
|
export { DefaultBinder } from './adapters/binding.js';
|
|
2
3
|
export { resolveClientIdentity } from './client-identity.js';
|
|
4
|
+
export type { Dispatcher } from './types.js';
|
|
3
5
|
export { attachFrameworkRequestNativeRouteHandoff, bindRawRequestNativeRouteHandoff, consumeRawRequestNativeRouteHandoff, isRoutePathNormalizationSensitive, readFrameworkRequestNativeRouteHandoff, type NativeRouteHandoff, } from './dispatch/native-route-handoff.js';
|
|
4
6
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EACL,wCAAwC,EACxC,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,sCAAsC,EACtC,KAAK,kBAAkB,GACxB,MAAM,oCAAoC,CAAC"}
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6CAA6C,EAC7C,KAAK,sBAAsB,GAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,wCAAwC,EACxC,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,sCAAsC,EACtC,KAAK,kBAAkB,GACxB,MAAM,oCAAoC,CAAC"}
|
package/dist/internal.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { createFetchStyleHttpAdapterRealtimeCapability } from './adapter.js';
|
|
1
2
|
export { DefaultBinder } from './adapters/binding.js';
|
|
2
3
|
export { resolveClientIdentity } from './client-identity.js';
|
|
3
4
|
export { attachFrameworkRequestNativeRouteHandoff, bindRawRequestNativeRouteHandoff, consumeRawRequestNativeRouteHandoff, isRoutePathNormalizationSensitive, readFrameworkRequestNativeRouteHandoff } from './dispatch/native-route-handoff.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"correlation.d.ts","sourceRoot":"","sources":["../../src/middleware/correlation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"correlation.d.ts","sourceRoot":"","sources":["../../src/middleware/correlation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAsB9C;;;;GAIG;AACH,wBAAgB,2BAA2B,IAAI,UAAU,CAYxD"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
1
|
const REQUEST_ID_HEADER = 'x-request-id';
|
|
3
2
|
const CORRELATION_ID_HEADER = 'x-correlation-id';
|
|
4
3
|
function resolveInboundRequestId(headers) {
|
|
5
4
|
const requestId = headers[REQUEST_ID_HEADER] ?? headers[CORRELATION_ID_HEADER];
|
|
6
5
|
const value = Array.isArray(requestId) ? requestId[0] : requestId;
|
|
7
|
-
return value ??
|
|
6
|
+
return value ?? createRequestId();
|
|
7
|
+
}
|
|
8
|
+
function createRequestId() {
|
|
9
|
+
const randomUUID = globalThis.crypto?.randomUUID;
|
|
10
|
+
if (randomUUID) {
|
|
11
|
+
return randomUUID.call(globalThis.crypto);
|
|
12
|
+
}
|
|
13
|
+
return `req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`;
|
|
8
14
|
}
|
|
9
15
|
|
|
10
16
|
/**
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"controller",
|
|
11
11
|
"rest"
|
|
12
12
|
],
|
|
13
|
-
"version": "1.0.0-beta.
|
|
13
|
+
"version": "1.0.0-beta.11",
|
|
14
14
|
"private": false,
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"repository": {
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@fluojs/core": "^1.0.0-beta.
|
|
45
|
-
"@fluojs/validation": "^1.0.0-beta.
|
|
46
|
-
"@fluojs/di": "^1.0.0-beta.
|
|
44
|
+
"@fluojs/core": "^1.0.0-beta.6",
|
|
45
|
+
"@fluojs/validation": "^1.0.0-beta.4",
|
|
46
|
+
"@fluojs/di": "^1.0.0-beta.8"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"vitest": "^3.2.4"
|