@fluojs/http 1.0.0-beta.1 → 1.0.0-beta.10

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 (94) hide show
  1. package/README.ko.md +36 -5
  2. package/README.md +36 -5
  3. package/dist/adapter.d.ts +31 -0
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +37 -0
  6. package/dist/adapters/binding.d.ts +6 -0
  7. package/dist/adapters/binding.d.ts.map +1 -1
  8. package/dist/adapters/binding.js +54 -55
  9. package/dist/adapters/dto-binding-plan.d.ts +22 -0
  10. package/dist/adapters/dto-binding-plan.d.ts.map +1 -0
  11. package/dist/adapters/dto-binding-plan.js +86 -0
  12. package/dist/adapters/dto-validation-adapter.d.ts +3 -1
  13. package/dist/adapters/dto-validation-adapter.d.ts.map +1 -1
  14. package/dist/adapters/dto-validation-adapter.js +10 -16
  15. package/dist/context/sse.d.ts +38 -0
  16. package/dist/context/sse.d.ts.map +1 -1
  17. package/dist/context/sse.js +50 -2
  18. package/dist/decorators.d.ts.map +1 -1
  19. package/dist/decorators.js +262 -53
  20. package/dist/dispatch/dispatch-content-negotiation.d.ts +17 -0
  21. package/dist/dispatch/dispatch-content-negotiation.d.ts.map +1 -1
  22. package/dist/dispatch/dispatch-content-negotiation.js +21 -0
  23. package/dist/dispatch/dispatch-error-policy.d.ts +8 -0
  24. package/dist/dispatch/dispatch-error-policy.d.ts.map +1 -1
  25. package/dist/dispatch/dispatch-error-policy.js +9 -0
  26. package/dist/dispatch/dispatch-handler-policy.d.ts +11 -1
  27. package/dist/dispatch/dispatch-handler-policy.d.ts.map +1 -1
  28. package/dist/dispatch/dispatch-handler-policy.js +17 -5
  29. package/dist/dispatch/dispatch-response-policy.d.ts +11 -1
  30. package/dist/dispatch/dispatch-response-policy.d.ts.map +1 -1
  31. package/dist/dispatch/dispatch-response-policy.js +44 -2
  32. package/dist/dispatch/dispatch-routing-policy.d.ts +13 -0
  33. package/dist/dispatch/dispatch-routing-policy.d.ts.map +1 -1
  34. package/dist/dispatch/dispatch-routing-policy.js +49 -4
  35. package/dist/dispatch/dispatcher.d.ts +24 -7
  36. package/dist/dispatch/dispatcher.d.ts.map +1 -1
  37. package/dist/dispatch/dispatcher.js +460 -48
  38. package/dist/dispatch/fast-path/debug-visibility.d.ts +18 -0
  39. package/dist/dispatch/fast-path/debug-visibility.d.ts.map +1 -0
  40. package/dist/dispatch/fast-path/debug-visibility.js +39 -0
  41. package/dist/dispatch/fast-path/eligibility-checker.d.ts +22 -0
  42. package/dist/dispatch/fast-path/eligibility-checker.d.ts.map +1 -0
  43. package/dist/dispatch/fast-path/eligibility-checker.js +107 -0
  44. package/dist/dispatch/fast-path/eligibility.d.ts +61 -0
  45. package/dist/dispatch/fast-path/eligibility.d.ts.map +1 -0
  46. package/dist/dispatch/fast-path/eligibility.js +23 -0
  47. package/dist/dispatch/fast-path/fast-path-executor.d.ts +21 -0
  48. package/dist/dispatch/fast-path/fast-path-executor.d.ts.map +1 -0
  49. package/dist/dispatch/fast-path/fast-path-executor.js +80 -0
  50. package/dist/dispatch/fast-path/index.d.ts +6 -0
  51. package/dist/dispatch/fast-path/index.d.ts.map +1 -0
  52. package/dist/dispatch/fast-path/index.js +4 -0
  53. package/dist/dispatch/native-route-handoff.d.ts +53 -0
  54. package/dist/dispatch/native-route-handoff.d.ts.map +1 -0
  55. package/dist/dispatch/native-route-handoff.js +97 -0
  56. package/dist/errors.d.ts +3 -0
  57. package/dist/errors.d.ts.map +1 -1
  58. package/dist/errors.js +4 -0
  59. package/dist/guards.d.ts +7 -0
  60. package/dist/guards.d.ts.map +1 -1
  61. package/dist/guards.js +11 -0
  62. package/dist/index.d.ts +2 -0
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +1 -0
  65. package/dist/input-error-detail.d.ts +9 -0
  66. package/dist/input-error-detail.d.ts.map +1 -1
  67. package/dist/input-error-detail.js +10 -0
  68. package/dist/interceptors.d.ts +8 -0
  69. package/dist/interceptors.d.ts.map +1 -1
  70. package/dist/interceptors.js +14 -1
  71. package/dist/internal.d.ts +1 -0
  72. package/dist/internal.d.ts.map +1 -1
  73. package/dist/internal.js +2 -1
  74. package/dist/mapping.d.ts +7 -0
  75. package/dist/mapping.d.ts.map +1 -1
  76. package/dist/mapping.js +93 -11
  77. package/dist/middleware/correlation.d.ts +5 -0
  78. package/dist/middleware/correlation.d.ts.map +1 -1
  79. package/dist/middleware/correlation.js +6 -0
  80. package/dist/middleware/cors.d.ts +9 -0
  81. package/dist/middleware/cors.d.ts.map +1 -1
  82. package/dist/middleware/cors.js +11 -0
  83. package/dist/middleware/middleware.d.ts +34 -0
  84. package/dist/middleware/middleware.d.ts.map +1 -1
  85. package/dist/middleware/middleware.js +47 -0
  86. package/dist/middleware/security-headers.d.ts +9 -0
  87. package/dist/middleware/security-headers.d.ts.map +1 -1
  88. package/dist/middleware/security-headers.js +11 -0
  89. package/dist/route-path.d.ts +41 -0
  90. package/dist/route-path.d.ts.map +1 -1
  91. package/dist/route-path.js +50 -0
  92. package/dist/types.d.ts +17 -0
  93. package/dist/types.d.ts.map +1 -1
  94. package/package.json +4 -4
@@ -1,11 +1,35 @@
1
1
  import type { RequestContext } from '../types.js';
2
+ /** Options that customize the fields emitted for one server-sent event frame. */
2
3
  export interface SseSendOptions {
4
+ /** Optional SSE event name. Newline characters are stripped before writing. */
3
5
  event?: string;
6
+ /** Optional SSE event id. Newline characters are stripped before writing. */
4
7
  id?: string | number;
8
+ /** Optional client retry delay in milliseconds. Non-finite or negative values are ignored. */
5
9
  retry?: number;
6
10
  }
11
+ /**
12
+ * Encodes a comment as a canonical server-sent event comment frame.
13
+ *
14
+ * @param comment Comment text to split into SSE comment lines.
15
+ * @returns A complete SSE comment frame ending in a blank line.
16
+ */
7
17
  export declare function encodeSseComment(comment: string): string;
18
+ /**
19
+ * Encodes data and optional event fields as a server-sent event message frame.
20
+ *
21
+ * @param data Payload to write. Strings are sent as-is; other values are JSON serialized.
22
+ * @param options Optional event metadata fields.
23
+ * @returns A complete SSE message frame ending in a blank line.
24
+ * @throws {TypeError} When `data` cannot be represented as an SSE data field.
25
+ */
8
26
  export declare function encodeSseMessage(data: unknown, options?: SseSendOptions): string;
27
+ /**
28
+ * Response helper for server-sent event streams backed by an adapter-provided response stream.
29
+ *
30
+ * The helper commits SSE headers immediately, closes idempotently on request abort
31
+ * or raw stream close, and removes all registered close/abort listeners during cleanup.
32
+ */
9
33
  export declare class SseResponse {
10
34
  private readonly context;
11
35
  private closed;
@@ -13,8 +37,22 @@ export declare class SseResponse {
13
37
  private removeCloseListener?;
14
38
  private readonly onAbort;
15
39
  constructor(context: RequestContext);
40
+ /**
41
+ * Writes one SSE data message when the stream is still open.
42
+ *
43
+ * @param data Payload to encode into `data:` lines.
44
+ * @param options Optional event metadata fields.
45
+ * @returns `true` when the underlying stream accepted the frame without backpressure.
46
+ */
16
47
  send(data: unknown, options?: SseSendOptions): boolean;
48
+ /**
49
+ * Writes one SSE comment frame when the stream is still open.
50
+ *
51
+ * @param comment Comment text to encode.
52
+ * @returns `true` when the underlying stream accepted the frame without backpressure.
53
+ */
17
54
  comment(comment: string): boolean;
55
+ /** Closes the SSE stream and removes registered abort/close listeners exactly once. */
18
56
  close(): void;
19
57
  private writeFrame;
20
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/context/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA8C,cAAc,EAAE,MAAM,aAAa,CAAC;AAE9F,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAoCD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,cAAmB,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IAmCpD;;;;;;OAMG;IACH,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO;IAI1D;;;;;OAKG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIjC,uFAAuF;IACvF,KAAK,IAAI,IAAI;IAiBb,OAAO,CAAC,UAAU;CAYnB"}
@@ -1,3 +1,5 @@
1
+ /** Options that customize the fields emitted for one server-sent event frame. */
2
+
1
3
  function sanitizeSseField(value) {
2
4
  return value.replace(/\r/g, '').replace(/\n/g, '');
3
5
  }
@@ -23,11 +25,27 @@ function resolveSseStream(response) {
23
25
  }
24
26
  return response.stream;
25
27
  }
28
+
29
+ /**
30
+ * Encodes a comment as a canonical server-sent event comment frame.
31
+ *
32
+ * @param comment Comment text to split into SSE comment lines.
33
+ * @returns A complete SSE comment frame ending in a blank line.
34
+ */
26
35
  export function encodeSseComment(comment) {
27
36
  const lines = splitSseLines(comment);
28
37
  const encoded = lines.map(line => line.length === 0 ? ':' : `: ${line}`);
29
38
  return `${encoded.join('\n')}\n\n`;
30
39
  }
40
+
41
+ /**
42
+ * Encodes data and optional event fields as a server-sent event message frame.
43
+ *
44
+ * @param data Payload to write. Strings are sent as-is; other values are JSON serialized.
45
+ * @param options Optional event metadata fields.
46
+ * @returns A complete SSE message frame ending in a blank line.
47
+ * @throws {TypeError} When `data` cannot be represented as an SSE data field.
48
+ */
31
49
  export function encodeSseMessage(data, options = {}) {
32
50
  const lines = [];
33
51
  if (options.event !== undefined) {
@@ -44,6 +62,13 @@ export function encodeSseMessage(data, options = {}) {
44
62
  }
45
63
  return `${lines.join('\n')}\n\n`;
46
64
  }
65
+
66
+ /**
67
+ * Response helper for server-sent event streams backed by an adapter-provided response stream.
68
+ *
69
+ * The helper commits SSE headers immediately, closes idempotently on request abort
70
+ * or raw stream close, and removes all registered close/abort listeners during cleanup.
71
+ */
47
72
  export class SseResponse {
48
73
  closed = false;
49
74
  stream;
@@ -70,16 +95,39 @@ export class SseResponse {
70
95
  context.request.signal?.addEventListener('abort', this.onAbort, {
71
96
  once: true
72
97
  });
73
- if (context.request.signal === undefined) {
74
- this.removeCloseListener = this.stream.onClose?.(this.onAbort) ?? undefined;
98
+ const removeCloseListener = this.stream.onClose?.(this.onAbort) ?? undefined;
99
+ if (this.closed) {
100
+ removeCloseListener?.();
101
+ return;
102
+ }
103
+ this.removeCloseListener = removeCloseListener;
104
+ if (this.stream.closed) {
105
+ this.close();
75
106
  }
76
107
  }
108
+
109
+ /**
110
+ * Writes one SSE data message when the stream is still open.
111
+ *
112
+ * @param data Payload to encode into `data:` lines.
113
+ * @param options Optional event metadata fields.
114
+ * @returns `true` when the underlying stream accepted the frame without backpressure.
115
+ */
77
116
  send(data, options = {}) {
78
117
  return this.writeFrame(encodeSseMessage(data, options));
79
118
  }
119
+
120
+ /**
121
+ * Writes one SSE comment frame when the stream is still open.
122
+ *
123
+ * @param comment Comment text to encode.
124
+ * @returns `true` when the underlying stream accepted the frame without backpressure.
125
+ */
80
126
  comment(comment) {
81
127
  return this.writeFrame(encodeSseComment(comment));
82
128
  }
129
+
130
+ /** Closes the SSE stream and removes registered abort/close listeners exactly once. */
83
131
  close() {
84
132
  if (this.closed) {
85
133
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EAEzB,MAAM,cAAc,CAAC;AAQtB,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAc,eAAe,EAAE,MAAM,YAAY,CAAC;AAGxF,KAAK,wBAAwB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,KAAK,IAAI,CAAC;AAC1F,KAAK,yBAAyB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,2BAA2B,KAAK,IAAI,CAAC;AACjG,KAAK,wBAAwB,GAAG,CA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;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE,GAAG,0BAA0B,CAyB5E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,YAAY,EAAE,eAAe,EAAE,GAAG,0BAA0B,CAyB9F"}
@@ -1,8 +1,11 @@
1
- import { metadataSymbol } from '@fluojs/core/internal';
1
+ import { defineControllerMetadata, defineDtoFieldBindingMetadata, defineRouteMetadata, ensureMetadataSymbol, getControllerMetadata, getDtoFieldBindingMetadata, getRouteMetadata, getStandardMetadataBag as readStandardMetadataBag } from '@fluojs/core/internal';
2
2
  import { validateRoutePath } from './route-path.js';
3
3
  const standardControllerMetadataKey = Symbol.for('fluo.standard.controller');
4
4
  const standardRouteMetadataKey = Symbol.for('fluo.standard.route');
5
5
  const standardDtoBindingMetadataKey = Symbol.for('fluo.standard.dto-binding');
6
+ const legacyRouteMetadataStore = new WeakMap();
7
+ const legacyDtoBindingMetadataStore = new WeakMap();
8
+ ensureMetadataSymbol();
6
9
  function normalizeProducesMediaTypes(mediaTypes) {
7
10
  const normalized = [];
8
11
  for (const mediaType of mediaTypes) {
@@ -24,8 +27,115 @@ function mergeUnique(existing, values) {
24
27
  return merged;
25
28
  }
26
29
  function getStandardMetadataBag(metadata) {
27
- void metadataSymbol;
28
- return metadata;
30
+ return typeof metadata === 'object' && metadata !== null ? metadata : {};
31
+ }
32
+ function isStandardDecoratorContext(value) {
33
+ return typeof value === 'object' && value !== null && 'kind' in value && 'name' in value;
34
+ }
35
+ function isMetadataPropertyKey(value) {
36
+ return typeof value === 'string' || typeof value === 'symbol';
37
+ }
38
+ function getLegacyRouteRecord(target, propertyKey) {
39
+ let routeMap = legacyRouteMetadataStore.get(target);
40
+ if (!routeMap) {
41
+ routeMap = new Map();
42
+ legacyRouteMetadataStore.set(target, routeMap);
43
+ }
44
+ let record = routeMap.get(propertyKey);
45
+ if (!record) {
46
+ record = {};
47
+ routeMap.set(propertyKey, record);
48
+ }
49
+ return record;
50
+ }
51
+ function flushLegacyRouteMetadata(target, propertyKey, record) {
52
+ if (!record.method || record.path === undefined) {
53
+ return;
54
+ }
55
+ const existing = getRouteMetadata(target, propertyKey);
56
+ const metadata = {
57
+ guards: mergeUnique(existing?.guards, record.guards ?? []),
58
+ headers: record.headers ?? existing?.headers,
59
+ interceptors: mergeUnique(existing?.interceptors, record.interceptors ?? []),
60
+ method: record.method,
61
+ path: record.path,
62
+ redirect: record.redirect ?? existing?.redirect,
63
+ request: record.request ?? existing?.request,
64
+ successStatus: record.successStatus ?? existing?.successStatus,
65
+ version: record.version ?? existing?.version
66
+ };
67
+ defineRouteMetadata(target, propertyKey, metadata);
68
+ }
69
+ function mergeLegacyRouteMetadata(target, propertyKey, partial) {
70
+ const record = getLegacyRouteRecord(target, propertyKey);
71
+ Object.assign(record, partial);
72
+ flushLegacyRouteMetadata(target, propertyKey, record);
73
+ }
74
+ function defineLegacyControllerMetadata(target, partial) {
75
+ const existing = getControllerMetadata(target);
76
+ defineControllerMetadata(target, {
77
+ basePath: partial.basePath ?? existing?.basePath ?? '',
78
+ guards: partial.guards ?? existing?.guards,
79
+ interceptors: partial.interceptors ?? existing?.interceptors,
80
+ version: partial.version ?? existing?.version
81
+ });
82
+ }
83
+ function getLegacyDtoBindingRecord(target, propertyKey) {
84
+ let bindingMap = legacyDtoBindingMetadataStore.get(target);
85
+ if (!bindingMap) {
86
+ bindingMap = new Map();
87
+ legacyDtoBindingMetadataStore.set(target, bindingMap);
88
+ }
89
+ let record = bindingMap.get(propertyKey);
90
+ if (!record) {
91
+ record = {};
92
+ bindingMap.set(propertyKey, record);
93
+ }
94
+ return record;
95
+ }
96
+ function mergeLegacyDtoBinding(target, propertyKey, partial) {
97
+ const record = getLegacyDtoBindingRecord(target, propertyKey);
98
+ Object.assign(record, partial);
99
+ const source = record.source ?? getDtoFieldBindingMetadata(target, propertyKey)?.source;
100
+ if (!source) {
101
+ return;
102
+ }
103
+ defineDtoFieldBindingMetadata(target, propertyKey, {
104
+ converter: record.converter,
105
+ key: record.key,
106
+ optional: record.optional,
107
+ source
108
+ });
109
+ }
110
+ function appendLegacyRouteHeader(target, propertyKey, name, value) {
111
+ const record = getLegacyRouteRecord(target, propertyKey);
112
+ record.headers = [...(record.headers ?? []), {
113
+ name,
114
+ value
115
+ }];
116
+ flushLegacyRouteMetadata(target, propertyKey, record);
117
+ }
118
+ function appendLegacyControllerGuards(target, guards) {
119
+ const existing = getControllerMetadata(target);
120
+ defineLegacyControllerMetadata(target, {
121
+ guards: mergeUnique(existing?.guards, guards)
122
+ });
123
+ }
124
+ function appendLegacyControllerInterceptors(target, interceptors) {
125
+ const existing = getControllerMetadata(target);
126
+ defineLegacyControllerMetadata(target, {
127
+ interceptors: mergeUnique(existing?.interceptors, interceptors)
128
+ });
129
+ }
130
+ function appendLegacyRouteGuards(target, propertyKey, guards) {
131
+ const record = getLegacyRouteRecord(target, propertyKey);
132
+ record.guards = mergeUnique(record.guards, guards);
133
+ flushLegacyRouteMetadata(target, propertyKey, record);
134
+ }
135
+ function appendLegacyRouteInterceptors(target, propertyKey, interceptors) {
136
+ const record = getLegacyRouteRecord(target, propertyKey);
137
+ record.interceptors = mergeUnique(record.interceptors, interceptors);
138
+ flushLegacyRouteMetadata(target, propertyKey, record);
29
139
  }
30
140
  function getStandardControllerRecord(metadata) {
31
141
  const bag = getStandardMetadataBag(metadata);
@@ -77,29 +187,55 @@ function mergeStandardDtoBinding(metadata, propertyKey, partial) {
77
187
  function createRouteDecorator(method) {
78
188
  return path => {
79
189
  validateRoutePath(path, `@${method}() path`);
80
- const decorator = (_value, context) => {
81
- const route = getStandardRouteRecord(context.metadata, context.name);
82
- route.method = method;
83
- route.path = path;
190
+ const decorator = (valueOrTarget, contextOrPropertyKey) => {
191
+ if (isStandardDecoratorContext(contextOrPropertyKey)) {
192
+ const route = getStandardRouteRecord(contextOrPropertyKey.metadata, contextOrPropertyKey.name);
193
+ route.method = method;
194
+ route.path = path;
195
+ return;
196
+ }
197
+ if (isMetadataPropertyKey(contextOrPropertyKey)) {
198
+ mergeLegacyRouteMetadata(valueOrTarget, contextOrPropertyKey, {
199
+ method,
200
+ path
201
+ });
202
+ }
84
203
  };
85
204
  return decorator;
86
205
  };
87
206
  }
88
207
  function createRouteValueDecorator(apply) {
89
208
  return value => {
90
- const decorator = (_target, context) => {
91
- apply(getStandardRouteRecord(context.metadata, context.name), value);
209
+ const decorator = (valueOrTarget, contextOrPropertyKey) => {
210
+ if (isStandardDecoratorContext(contextOrPropertyKey)) {
211
+ apply(getStandardRouteRecord(contextOrPropertyKey.metadata, contextOrPropertyKey.name), value);
212
+ return;
213
+ }
214
+ if (isMetadataPropertyKey(contextOrPropertyKey)) {
215
+ const record = getLegacyRouteRecord(valueOrTarget, contextOrPropertyKey);
216
+ apply(record, value);
217
+ flushLegacyRouteMetadata(valueOrTarget, contextOrPropertyKey, record);
218
+ }
92
219
  };
93
220
  return decorator;
94
221
  };
95
222
  }
96
223
  function createDtoFieldDecorator(source) {
97
224
  return key => {
98
- const decorator = (_value, context) => {
99
- mergeStandardDtoBinding(context.metadata, context.name, {
100
- key,
101
- source
102
- });
225
+ const decorator = (valueOrTarget, contextOrPropertyKey) => {
226
+ if (isStandardDecoratorContext(contextOrPropertyKey)) {
227
+ mergeStandardDtoBinding(contextOrPropertyKey.metadata, contextOrPropertyKey.name, {
228
+ key,
229
+ source
230
+ });
231
+ return;
232
+ }
233
+ if (isMetadataPropertyKey(contextOrPropertyKey) && valueOrTarget && typeof valueOrTarget === 'object') {
234
+ mergeLegacyDtoBinding(valueOrTarget, contextOrPropertyKey, {
235
+ key,
236
+ source
237
+ });
238
+ }
103
239
  };
104
240
  return decorator;
105
241
  };
@@ -113,8 +249,14 @@ function createDtoFieldDecorator(source) {
113
249
  */
114
250
  export function Controller(basePath = '') {
115
251
  validateRoutePath(basePath, '@Controller() base path');
116
- const decorator = (_target, context) => {
117
- getStandardControllerRecord(context.metadata).basePath = basePath;
252
+ const decorator = (target, context) => {
253
+ if (isStandardDecoratorContext(context)) {
254
+ getStandardControllerRecord(context.metadata).basePath = basePath;
255
+ return;
256
+ }
257
+ defineLegacyControllerMetadata(target, {
258
+ basePath
259
+ });
118
260
  };
119
261
  return decorator;
120
262
  }
@@ -126,12 +268,26 @@ export function Controller(basePath = '') {
126
268
  * @returns A decorator that applies version metadata at class or method scope.
127
269
  */
128
270
  export function Version(version) {
129
- const decorator = (_target, context) => {
130
- if (context.kind === 'class') {
131
- getStandardControllerRecord(context.metadata).version = version;
271
+ const decorator = (target, contextOrPropertyKey) => {
272
+ if (isStandardDecoratorContext(contextOrPropertyKey)) {
273
+ if (contextOrPropertyKey.kind === 'class') {
274
+ getStandardControllerRecord(contextOrPropertyKey.metadata).version = version;
275
+ return;
276
+ }
277
+ getStandardRouteRecord(contextOrPropertyKey.metadata, contextOrPropertyKey.name).version = version;
132
278
  return;
133
279
  }
134
- getStandardRouteRecord(context.metadata, context.name).version = version;
280
+ if (isMetadataPropertyKey(contextOrPropertyKey)) {
281
+ mergeLegacyRouteMetadata(target, contextOrPropertyKey, {
282
+ version
283
+ });
284
+ return;
285
+ }
286
+ if (typeof target === 'function') {
287
+ defineLegacyControllerMetadata(target, {
288
+ version
289
+ });
290
+ }
135
291
  };
136
292
  return decorator;
137
293
  }
@@ -233,9 +389,9 @@ export const HttpCode = createRouteValueDecorator((record, status) => {
233
389
  * @returns A defensive copy of declared media types, or `undefined` when not configured.
234
390
  */
235
391
  export function getRouteProducesMetadata(controllerToken, propertyKey) {
236
- const bag = controllerToken[metadataSymbol];
392
+ const bag = readStandardMetadataBag(controllerToken);
237
393
  const routeMap = bag?.[standardRouteMetadataKey];
238
- const produces = routeMap?.get(propertyKey)?.produces;
394
+ const produces = routeMap?.get(propertyKey)?.produces ?? legacyRouteMetadataStore.get(controllerToken.prototype)?.get(propertyKey)?.produces;
239
395
  return produces ? [...produces] : undefined;
240
396
  }
241
397
 
@@ -281,10 +437,18 @@ export const FromBody = createDtoFieldDecorator('body');
281
437
  * @returns A field decorator that marks the DTO binding as optional.
282
438
  */
283
439
  export function Optional() {
284
- const decorator = (_value, context) => {
285
- mergeStandardDtoBinding(context.metadata, context.name, {
286
- optional: true
287
- });
440
+ const decorator = (valueOrTarget, contextOrPropertyKey) => {
441
+ if (isStandardDecoratorContext(contextOrPropertyKey)) {
442
+ mergeStandardDtoBinding(contextOrPropertyKey.metadata, contextOrPropertyKey.name, {
443
+ optional: true
444
+ });
445
+ return;
446
+ }
447
+ if (isMetadataPropertyKey(contextOrPropertyKey) && valueOrTarget && typeof valueOrTarget === 'object') {
448
+ mergeLegacyDtoBinding(valueOrTarget, contextOrPropertyKey, {
449
+ optional: true
450
+ });
451
+ }
288
452
  };
289
453
  return decorator;
290
454
  }
@@ -296,10 +460,18 @@ export function Optional() {
296
460
  * @returns A field decorator that stores converter metadata for the DTO field.
297
461
  */
298
462
  export function Convert(converter) {
299
- const decorator = (_value, context) => {
300
- mergeStandardDtoBinding(context.metadata, context.name, {
301
- converter
302
- });
463
+ const decorator = (valueOrTarget, contextOrPropertyKey) => {
464
+ if (isStandardDecoratorContext(contextOrPropertyKey)) {
465
+ mergeStandardDtoBinding(contextOrPropertyKey.metadata, contextOrPropertyKey.name, {
466
+ converter
467
+ });
468
+ return;
469
+ }
470
+ if (isMetadataPropertyKey(contextOrPropertyKey) && valueOrTarget && typeof valueOrTarget === 'object') {
471
+ mergeLegacyDtoBinding(valueOrTarget, contextOrPropertyKey, {
472
+ converter
473
+ });
474
+ }
303
475
  };
304
476
  return decorator;
305
477
  }
@@ -312,12 +484,18 @@ export function Convert(converter) {
312
484
  * @returns A method decorator that appends route-level response-header metadata.
313
485
  */
314
486
  export function Header(name, value) {
315
- const decorator = (_target, context) => {
316
- const route = getStandardRouteRecord(context.metadata, context.name);
317
- route.headers = [...(route.headers ?? []), {
318
- name,
319
- value
320
- }];
487
+ const decorator = (valueOrTarget, contextOrPropertyKey) => {
488
+ if (isStandardDecoratorContext(contextOrPropertyKey)) {
489
+ const route = getStandardRouteRecord(contextOrPropertyKey.metadata, contextOrPropertyKey.name);
490
+ route.headers = [...(route.headers ?? []), {
491
+ name,
492
+ value
493
+ }];
494
+ return;
495
+ }
496
+ if (isMetadataPropertyKey(contextOrPropertyKey)) {
497
+ appendLegacyRouteHeader(valueOrTarget, contextOrPropertyKey, name, value);
498
+ }
321
499
  };
322
500
  return decorator;
323
501
  }
@@ -330,11 +508,22 @@ export function Header(name, value) {
330
508
  * @returns A method decorator that writes redirect metadata for the route.
331
509
  */
332
510
  export function Redirect(url, statusCode) {
333
- const decorator = (_target, context) => {
334
- getStandardRouteRecord(context.metadata, context.name).redirect = {
335
- url,
336
- statusCode
337
- };
511
+ const decorator = (valueOrTarget, contextOrPropertyKey) => {
512
+ if (isStandardDecoratorContext(contextOrPropertyKey)) {
513
+ getStandardRouteRecord(contextOrPropertyKey.metadata, contextOrPropertyKey.name).redirect = {
514
+ url,
515
+ statusCode
516
+ };
517
+ return;
518
+ }
519
+ if (isMetadataPropertyKey(contextOrPropertyKey)) {
520
+ mergeLegacyRouteMetadata(valueOrTarget, contextOrPropertyKey, {
521
+ redirect: {
522
+ url,
523
+ statusCode
524
+ }
525
+ });
526
+ }
338
527
  };
339
528
  return decorator;
340
529
  }
@@ -346,14 +535,24 @@ export function Redirect(url, statusCode) {
346
535
  * @returns A decorator applicable to classes and methods.
347
536
  */
348
537
  export function UseGuards(...guards) {
349
- const decorator = (_target, context) => {
350
- if (context.kind === 'class') {
351
- const controller = getStandardControllerRecord(context.metadata);
352
- controller.guards = mergeUnique(controller.guards, guards);
538
+ const decorator = (target, contextOrPropertyKey) => {
539
+ if (isStandardDecoratorContext(contextOrPropertyKey)) {
540
+ if (contextOrPropertyKey.kind === 'class') {
541
+ const controller = getStandardControllerRecord(contextOrPropertyKey.metadata);
542
+ controller.guards = mergeUnique(controller.guards, guards);
543
+ return;
544
+ }
545
+ const route = getStandardRouteRecord(contextOrPropertyKey.metadata, contextOrPropertyKey.name);
546
+ route.guards = mergeUnique(route.guards, guards);
547
+ return;
548
+ }
549
+ if (isMetadataPropertyKey(contextOrPropertyKey)) {
550
+ appendLegacyRouteGuards(target, contextOrPropertyKey, guards);
353
551
  return;
354
552
  }
355
- const route = getStandardRouteRecord(context.metadata, context.name);
356
- route.guards = mergeUnique(route.guards, guards);
553
+ if (typeof target === 'function') {
554
+ appendLegacyControllerGuards(target, guards);
555
+ }
357
556
  };
358
557
  return decorator;
359
558
  }
@@ -365,14 +564,24 @@ export function UseGuards(...guards) {
365
564
  * @returns A decorator applicable to classes and methods.
366
565
  */
367
566
  export function UseInterceptors(...interceptors) {
368
- const decorator = (_target, context) => {
369
- if (context.kind === 'class') {
370
- const controller = getStandardControllerRecord(context.metadata);
371
- controller.interceptors = mergeUnique(controller.interceptors, interceptors);
567
+ const decorator = (target, contextOrPropertyKey) => {
568
+ if (isStandardDecoratorContext(contextOrPropertyKey)) {
569
+ if (contextOrPropertyKey.kind === 'class') {
570
+ const controller = getStandardControllerRecord(contextOrPropertyKey.metadata);
571
+ controller.interceptors = mergeUnique(controller.interceptors, interceptors);
572
+ return;
573
+ }
574
+ const route = getStandardRouteRecord(contextOrPropertyKey.metadata, contextOrPropertyKey.name);
575
+ route.interceptors = mergeUnique(route.interceptors, interceptors);
372
576
  return;
373
577
  }
374
- const route = getStandardRouteRecord(context.metadata, context.name);
375
- route.interceptors = mergeUnique(route.interceptors, interceptors);
578
+ if (isMetadataPropertyKey(contextOrPropertyKey)) {
579
+ appendLegacyRouteInterceptors(target, contextOrPropertyKey, interceptors);
580
+ return;
581
+ }
582
+ if (typeof target === 'function') {
583
+ appendLegacyControllerInterceptors(target, interceptors);
584
+ }
376
585
  };
377
586
  return decorator;
378
587
  }
@@ -1,9 +1,26 @@
1
1
  import type { ContentNegotiationOptions, FrameworkRequest, HandlerDescriptor, ResponseFormatter } from '../types.js';
2
+ /**
3
+ * Describes the resolved content negotiation contract.
4
+ */
2
5
  export interface ResolvedContentNegotiation {
3
6
  defaultFormatter: ResponseFormatter;
4
7
  formatters: ResponseFormatter[];
5
8
  normalizedMediaTypes: string[];
6
9
  }
10
+ /**
11
+ * Resolve content negotiation.
12
+ *
13
+ * @param options The options.
14
+ * @returns The resolve content negotiation result.
15
+ */
7
16
  export declare function resolveContentNegotiation(options: ContentNegotiationOptions | undefined): ResolvedContentNegotiation | undefined;
17
+ /**
18
+ * Select response formatter.
19
+ *
20
+ * @param handler The handler.
21
+ * @param request The request.
22
+ * @param contentNegotiation The content negotiation.
23
+ * @returns The select response formatter result.
24
+ */
8
25
  export declare function selectResponseFormatter(handler: HandlerDescriptor, request: FrameworkRequest, contentNegotiation: ResolvedContentNegotiation): ResponseFormatter;
9
26
  //# sourceMappingURL=dispatch-content-negotiation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-content-negotiation.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatch-content-negotiation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAQrB,MAAM,WAAW,0BAA0B;IACzC,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC;AA2GD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,yBAAyB,GAAG,SAAS,GAAG,0BAA0B,GAAG,SAAS,CA+BhI;AAqCD,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,gBAAgB,EACzB,kBAAkB,EAAE,0BAA0B,GAC7C,iBAAiB,CA2CnB"}
1
+ {"version":3,"file":"dispatch-content-negotiation.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatch-content-negotiation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAQrB;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC;AA2GD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,yBAAyB,GAAG,SAAS,GAAG,0BAA0B,GAAG,SAAS,CA+BhI;AAqCD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,gBAAgB,EACzB,kBAAkB,EAAE,0BAA0B,GAC7C,iBAAiB,CA2CnB"}
@@ -1,4 +1,9 @@
1
1
  import { NotAcceptableException } from '../exceptions.js';
2
+
3
+ /**
4
+ * Describes the resolved content negotiation contract.
5
+ */
6
+
2
7
  const NO_ACCEPTABLE_REPRESENTATION_MESSAGE = 'No acceptable response representation found.';
3
8
  function normalizeMediaType(value) {
4
9
  return value.split(';')[0]?.trim().toLowerCase() ?? '';
@@ -77,6 +82,13 @@ function matchesMediaRange(mediaRange, mediaType) {
77
82
  }
78
83
  return rangeSubtype === '*' || rangeSubtype === mediaTypeSubtype;
79
84
  }
85
+
86
+ /**
87
+ * Resolve content negotiation.
88
+ *
89
+ * @param options The options.
90
+ * @returns The resolve content negotiation result.
91
+ */
80
92
  export function resolveContentNegotiation(options) {
81
93
  if (!options?.formatters?.length) {
82
94
  return undefined;
@@ -128,6 +140,15 @@ function resolveDefaultFormatter(allowedFormatters, allowedNormalizedMediaTypes,
128
140
  const idx = allowedNormalizedMediaTypes.indexOf(defaultMediaType);
129
141
  return idx >= 0 ? allowedFormatters[idx] : allowedFormatters[0] ?? contentNegotiation.defaultFormatter;
130
142
  }
143
+
144
+ /**
145
+ * Select response formatter.
146
+ *
147
+ * @param handler The handler.
148
+ * @param request The request.
149
+ * @param contentNegotiation The content negotiation.
150
+ * @returns The select response formatter result.
151
+ */
131
152
  export function selectResponseFormatter(handler, request, contentNegotiation) {
132
153
  const {
133
154
  formatters: allowedFormatters,
@@ -1,3 +1,11 @@
1
1
  import type { FrameworkResponse } from '../types.js';
2
+ /**
3
+ * Write error response.
4
+ *
5
+ * @param error The error.
6
+ * @param response The response.
7
+ * @param requestId The request id.
8
+ * @returns The write error response result.
9
+ */
2
10
  export declare function writeErrorResponse(error: unknown, response: FrameworkResponse, requestId?: string): Promise<void>;
3
11
  //# sourceMappingURL=dispatch-error-policy.d.ts.map