@fluojs/http 1.0.0-beta.9 → 1.1.0

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 (34) hide show
  1. package/README.ko.md +78 -11
  2. package/README.md +78 -11
  3. package/dist/context/request-context-node-store.d.ts +25 -0
  4. package/dist/context/request-context-node-store.d.ts.map +1 -0
  5. package/dist/context/request-context-node-store.js +32 -0
  6. package/dist/context/request-context-stack-store.d.ts +8 -0
  7. package/dist/context/request-context-stack-store.d.ts.map +1 -0
  8. package/dist/context/request-context-stack-store.js +29 -0
  9. package/dist/context/request-context-store.d.ts +7 -0
  10. package/dist/context/request-context-store.d.ts.map +1 -0
  11. package/dist/context/request-context-store.js +1 -0
  12. package/dist/context/request-context.d.ts +7 -3
  13. package/dist/context/request-context.d.ts.map +1 -1
  14. package/dist/context/request-context.js +17 -5
  15. package/dist/context/sse.d.ts +20 -0
  16. package/dist/context/sse.d.ts.map +1 -1
  17. package/dist/context/sse.js +19 -0
  18. package/dist/decorators.d.ts +10 -0
  19. package/dist/decorators.d.ts.map +1 -1
  20. package/dist/decorators.js +279 -53
  21. package/dist/dispatch/dispatcher.d.ts.map +1 -1
  22. package/dist/dispatch/dispatcher.js +142 -2
  23. package/dist/dispatch/fast-path/eligibility-checker.d.ts +22 -0
  24. package/dist/dispatch/fast-path/eligibility-checker.d.ts.map +1 -1
  25. package/dist/dispatch/fast-path/eligibility-checker.js +32 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +1 -1
  29. package/dist/internal.d.ts +2 -0
  30. package/dist/internal.d.ts.map +1 -1
  31. package/dist/internal.js +1 -0
  32. package/dist/middleware/correlation.d.ts.map +1 -1
  33. package/dist/middleware/correlation.js +8 -2
  34. package/package.json +4 -4
@@ -41,6 +41,15 @@ function determineMiddlewareRequirement(handler, appMiddleware) {
41
41
  const moduleMiddleware = handler.metadata.moduleMiddleware;
42
42
  return moduleMiddleware !== undefined && moduleMiddleware.length > 0;
43
43
  }
44
+
45
+ /**
46
+ * Compiles the conservative fast-path eligibility decision for one handler.
47
+ *
48
+ * @param handler Handler descriptor being analyzed.
49
+ * @param options Dispatcher options that can introduce full-path requirements.
50
+ * @param adapter Human-readable adapter label used in observability metadata.
51
+ * @returns The compiled eligibility metadata and boolean eligibility flag.
52
+ */
44
53
  export function compileFastPathEligibility(handler, options, adapter) {
45
54
  const routeId = `${handler.route.method}:${handler.route.path}`;
46
55
  const hasGuard = (handler.route.guards?.length ?? 0) > 0;
@@ -49,6 +58,7 @@ export function compileFastPathEligibility(handler, options, adapter) {
49
58
  const hasRequestScopedDI = determineRequestScopeRequirement(handler, options);
50
59
  const hasMiddleware = determineMiddlewareRequirement(handler, options.appMiddleware ?? []);
51
60
  const hasContentNegotiation = options.contentNegotiation?.formatters !== undefined && options.contentNegotiation.formatters.length > 0;
61
+ const isSseRoute = handler.route.produces?.some(mediaType => mediaType.toLowerCase().startsWith('text/event-stream')) === true;
52
62
  const eligibility = {
53
63
  adapter,
54
64
  executionPath: 'full',
@@ -88,6 +98,9 @@ export function compileFastPathEligibility(handler, options, adapter) {
88
98
  if (hasContentNegotiation) {
89
99
  blockingReasons.push('content negotiation');
90
100
  }
101
+ if (isSseRoute) {
102
+ blockingReasons.push('SSE streaming');
103
+ }
91
104
  const isEligible = blockingReasons.length === 0;
92
105
  if (!isEligible) {
93
106
  eligibility.fallbackReason = `Full path required due to: ${blockingReasons.join(', ')}`;
@@ -99,9 +112,27 @@ export function compileFastPathEligibility(handler, options, adapter) {
99
112
  isEligible
100
113
  };
101
114
  }
115
+
116
+ /**
117
+ * Reads fast-path eligibility metadata attached to a handler descriptor.
118
+ *
119
+ * @param handler Handler descriptor previously analyzed by the dispatcher.
120
+ * @returns The attached eligibility metadata, when present.
121
+ */
102
122
  export function getHandlerFastPathEligibility(handler) {
103
123
  return handler[FAST_PATH_ELIGIBILITY_SYMBOL];
104
124
  }
125
+
126
+ /**
127
+ * Attaches fast-path eligibility metadata to a handler descriptor.
128
+ *
129
+ * @param handler Handler descriptor to annotate.
130
+ * @param eligibility Eligibility metadata to expose through dispatcher observability.
131
+ */
105
132
  export function setHandlerFastPathEligibility(handler, eligibility) {
106
133
  handler[FAST_PATH_ELIGIBILITY_SYMBOL] = eligibility;
107
- }
134
+ }
135
+
136
+ /** Options shared by fast-path executor helpers. */
137
+
138
+ /** Result returned after attempting fast-path handler execution. */
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from './adapter.js';
2
2
  export * from './middleware/correlation.js';
3
3
  export * from './middleware/cors.js';
4
- export { All, Controller, Convert, Delete, FromBody, FromCookie, FromHeader, FromPath, FromQuery, Get, Head, Header, HttpCode, Optional, Options, Patch, Post, Produces, Put, Redirect, RequestDto, UseGuards, UseInterceptors, Version, } from './decorators.js';
4
+ export { All, Controller, Convert, Delete, FromBody, FromCookie, FromHeader, FromPath, FromQuery, Get, Head, Header, HttpCode, Optional, Options, Patch, Post, Produces, Put, Redirect, RequestDto, Sse, UseGuards, UseInterceptors, Version, } from './decorators.js';
5
5
  export * from './dispatch/dispatcher.js';
6
6
  export type { FastPathEligibility, FastPathStats } from './dispatch/fast-path/index.js';
7
7
  export { FAST_PATH_ELIGIBILITY_SYMBOL, FAST_PATH_STATS_SYMBOL, formatFastPathStats, getDispatcherFastPathStats, } from './dispatch/dispatcher.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,OAAO,EACL,GAAG,EACH,UAAU,EACV,OAAO,EACP,MAAM,EACN,QAAQ,EACR,UAAU,EACV,UAAU,EACV,QAAQ,EACR,SAAS,EACT,GAAG,EACH,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,KAAK,EACL,IAAI,EACJ,QA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,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,OAAO,EACL,SAAS,EACT,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from './adapter.js';
2
2
  export * from './middleware/correlation.js';
3
3
  export * from './middleware/cors.js';
4
- export { All, Controller, Convert, Delete, FromBody, FromCookie, FromHeader, FromPath, FromQuery, Get, Head, Header, HttpCode, Optional, Options, Patch, Post, Produces, Put, Redirect, RequestDto, UseGuards, UseInterceptors, Version } from './decorators.js';
4
+ export { All, Controller, Convert, Delete, FromBody, FromCookie, FromHeader, FromPath, FromQuery, Get, Head, Header, HttpCode, Optional, Options, Patch, Post, Produces, Put, Redirect, RequestDto, Sse, UseGuards, UseInterceptors, Version } from './decorators.js';
5
5
  export * from './dispatch/dispatcher.js';
6
6
  export { FAST_PATH_ELIGIBILITY_SYMBOL, FAST_PATH_STATS_SYMBOL, formatFastPathStats, getDispatcherFastPathStats } from './dispatch/dispatcher.js';
7
7
  export * from './errors.js';
@@ -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
@@ -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":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAY9C;;;;GAIG;AACH,wBAAgB,2BAA2B,IAAI,UAAU,CAYxD"}
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 ?? randomUUID();
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.9",
13
+ "version": "1.1.0",
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.2",
45
- "@fluojs/validation": "^1.0.0-beta.1",
46
- "@fluojs/di": "^1.0.0-beta.5"
44
+ "@fluojs/core": "^1.0.3",
45
+ "@fluojs/validation": "^1.0.4",
46
+ "@fluojs/di": "^1.0.3"
47
47
  },
48
48
  "devDependencies": {
49
49
  "vitest": "^3.2.4"