@fluojs/http 1.0.0-beta.2 → 1.0.0-beta.3

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 (59) hide show
  1. package/dist/adapter.d.ts +31 -0
  2. package/dist/adapter.d.ts.map +1 -1
  3. package/dist/adapter.js +37 -0
  4. package/dist/adapters/binding.d.ts +6 -0
  5. package/dist/adapters/binding.d.ts.map +1 -1
  6. package/dist/adapters/binding.js +8 -0
  7. package/dist/adapters/dto-validation-adapter.d.ts +3 -0
  8. package/dist/adapters/dto-validation-adapter.d.ts.map +1 -1
  9. package/dist/adapters/dto-validation-adapter.js +3 -0
  10. package/dist/dispatch/dispatch-content-negotiation.d.ts +17 -0
  11. package/dist/dispatch/dispatch-content-negotiation.d.ts.map +1 -1
  12. package/dist/dispatch/dispatch-content-negotiation.js +21 -0
  13. package/dist/dispatch/dispatch-error-policy.d.ts +8 -0
  14. package/dist/dispatch/dispatch-error-policy.d.ts.map +1 -1
  15. package/dist/dispatch/dispatch-error-policy.js +9 -0
  16. package/dist/dispatch/dispatch-handler-policy.d.ts +8 -0
  17. package/dist/dispatch/dispatch-handler-policy.d.ts.map +1 -1
  18. package/dist/dispatch/dispatch-handler-policy.js +9 -0
  19. package/dist/dispatch/dispatch-response-policy.d.ts +10 -0
  20. package/dist/dispatch/dispatch-response-policy.d.ts.map +1 -1
  21. package/dist/dispatch/dispatch-response-policy.js +11 -0
  22. package/dist/dispatch/dispatch-routing-policy.d.ts +13 -0
  23. package/dist/dispatch/dispatch-routing-policy.d.ts.map +1 -1
  24. package/dist/dispatch/dispatch-routing-policy.js +14 -0
  25. package/dist/dispatch/dispatcher.d.ts.map +1 -1
  26. package/dist/dispatch/dispatcher.js +55 -16
  27. package/dist/errors.d.ts +3 -0
  28. package/dist/errors.d.ts.map +1 -1
  29. package/dist/errors.js +4 -0
  30. package/dist/guards.d.ts +7 -0
  31. package/dist/guards.d.ts.map +1 -1
  32. package/dist/guards.js +11 -0
  33. package/dist/input-error-detail.d.ts +9 -0
  34. package/dist/input-error-detail.d.ts.map +1 -1
  35. package/dist/input-error-detail.js +10 -0
  36. package/dist/interceptors.d.ts +8 -0
  37. package/dist/interceptors.d.ts.map +1 -1
  38. package/dist/interceptors.js +14 -1
  39. package/dist/mapping.d.ts +7 -0
  40. package/dist/mapping.d.ts.map +1 -1
  41. package/dist/mapping.js +93 -11
  42. package/dist/middleware/correlation.d.ts +5 -0
  43. package/dist/middleware/correlation.d.ts.map +1 -1
  44. package/dist/middleware/correlation.js +6 -0
  45. package/dist/middleware/cors.d.ts +9 -0
  46. package/dist/middleware/cors.d.ts.map +1 -1
  47. package/dist/middleware/cors.js +11 -0
  48. package/dist/middleware/middleware.d.ts +34 -0
  49. package/dist/middleware/middleware.d.ts.map +1 -1
  50. package/dist/middleware/middleware.js +47 -0
  51. package/dist/middleware/security-headers.d.ts +9 -0
  52. package/dist/middleware/security-headers.d.ts.map +1 -1
  53. package/dist/middleware/security-headers.js +11 -0
  54. package/dist/route-path.d.ts +41 -0
  55. package/dist/route-path.d.ts.map +1 -1
  56. package/dist/route-path.js +50 -0
  57. package/dist/types.d.ts +5 -0
  58. package/dist/types.d.ts.map +1 -1
  59. package/package.json +3 -3
package/dist/adapter.d.ts CHANGED
@@ -1,14 +1,23 @@
1
1
  import type { MaybePromise } from '@fluojs/core';
2
2
  import type { Dispatcher } from './types.js';
3
+ /**
4
+ * Describes the server backed http adapter realtime capability contract.
5
+ */
3
6
  export interface ServerBackedHttpAdapterRealtimeCapability {
4
7
  kind: 'server-backed';
5
8
  server: unknown;
6
9
  }
10
+ /**
11
+ * Describes the unsupported http adapter realtime capability contract.
12
+ */
7
13
  export interface UnsupportedHttpAdapterRealtimeCapability {
8
14
  kind: 'unsupported';
9
15
  mode: 'no-op';
10
16
  reason: string;
11
17
  }
18
+ /**
19
+ * Describes the fetch style http adapter realtime capability contract.
20
+ */
12
21
  export interface FetchStyleHttpAdapterRealtimeCapability {
13
22
  contract: 'raw-websocket-expansion';
14
23
  kind: 'fetch-style';
@@ -17,9 +26,31 @@ export interface FetchStyleHttpAdapterRealtimeCapability {
17
26
  support: 'contract-only' | 'supported';
18
27
  version: 1;
19
28
  }
29
+ /**
30
+ * Defines the http adapter realtime capability type.
31
+ */
20
32
  export type HttpAdapterRealtimeCapability = ServerBackedHttpAdapterRealtimeCapability | FetchStyleHttpAdapterRealtimeCapability | UnsupportedHttpAdapterRealtimeCapability;
33
+ /**
34
+ * Create server backed http adapter realtime capability.
35
+ *
36
+ * @param server The server.
37
+ * @returns The create server backed http adapter realtime capability result.
38
+ */
21
39
  export declare function createServerBackedHttpAdapterRealtimeCapability(server: unknown): ServerBackedHttpAdapterRealtimeCapability;
40
+ /**
41
+ * Create unsupported http adapter realtime capability.
42
+ *
43
+ * @param reason The reason.
44
+ * @returns The create unsupported http adapter realtime capability result.
45
+ */
22
46
  export declare function createUnsupportedHttpAdapterRealtimeCapability(reason: string): UnsupportedHttpAdapterRealtimeCapability;
47
+ /**
48
+ * Create fetch style http adapter realtime capability.
49
+ *
50
+ * @param reason The reason.
51
+ * @param options The options.
52
+ * @returns The create fetch style http adapter realtime capability result.
53
+ */
23
54
  export declare function createFetchStyleHttpAdapterRealtimeCapability(reason: string, options?: {
24
55
  support?: FetchStyleHttpAdapterRealtimeCapability['support'];
25
56
  }): FetchStyleHttpAdapterRealtimeCapability;
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,yCAAyC;IACxD,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,wCAAwC;IACvD,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;I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js CHANGED
@@ -1,9 +1,38 @@
1
+ /**
2
+ * Describes the server backed http adapter realtime capability contract.
3
+ */
4
+
5
+ /**
6
+ * Describes the unsupported http adapter realtime capability contract.
7
+ */
8
+
9
+ /**
10
+ * Describes the fetch style http adapter realtime capability contract.
11
+ */
12
+
13
+ /**
14
+ * Defines the http adapter realtime capability type.
15
+ */
16
+
17
+ /**
18
+ * Create server backed http adapter realtime capability.
19
+ *
20
+ * @param server The server.
21
+ * @returns The create server backed http adapter realtime capability result.
22
+ */
1
23
  export function createServerBackedHttpAdapterRealtimeCapability(server) {
2
24
  return {
3
25
  kind: 'server-backed',
4
26
  server
5
27
  };
6
28
  }
29
+
30
+ /**
31
+ * Create unsupported http adapter realtime capability.
32
+ *
33
+ * @param reason The reason.
34
+ * @returns The create unsupported http adapter realtime capability result.
35
+ */
7
36
  export function createUnsupportedHttpAdapterRealtimeCapability(reason) {
8
37
  return {
9
38
  kind: 'unsupported',
@@ -11,6 +40,14 @@ export function createUnsupportedHttpAdapterRealtimeCapability(reason) {
11
40
  reason
12
41
  };
13
42
  }
43
+
44
+ /**
45
+ * Create fetch style http adapter realtime capability.
46
+ *
47
+ * @param reason The reason.
48
+ * @param options The options.
49
+ * @returns The create fetch style http adapter realtime capability result.
50
+ */
14
51
  export function createFetchStyleHttpAdapterRealtimeCapability(reason, options = {}) {
15
52
  return {
16
53
  contract: 'raw-websocket-expansion',
@@ -1,8 +1,14 @@
1
1
  import { type Constructor } from '@fluojs/core';
2
2
  import type { ArgumentResolverContext, Binder, Converter, ConverterLike, ConverterTarget } from '../types.js';
3
+ /**
4
+ * Represents the default converter.
5
+ */
3
6
  export declare class DefaultConverter implements Converter {
4
7
  convert(value: unknown, _target: ConverterTarget): unknown;
5
8
  }
9
+ /**
10
+ * Represents the default binder.
11
+ */
6
12
  export declare class DefaultBinder implements Binder {
7
13
  private readonly converters;
8
14
  constructor(converters?: readonly ConverterLike[]);
@@ -1 +1 @@
1
- {"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../../src/adapters/binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,WAAW,EAA6D,MAAM,cAAc,CAAC;AAK3H,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAoB,MAAM,aAAa,CAAC;AA4FhI,qBAAa,gBAAiB,YAAW,SAAS;IAChD,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO;CAG3D;AAyDD,qBAAa,aAAc,YAAW,MAAM;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,GAAE,SAAS,aAAa,EAAO;IAEhE,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC;CA0EjF"}
1
+ {"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../../src/adapters/binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,WAAW,EAA6D,MAAM,cAAc,CAAC;AAK3H,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAoB,MAAM,aAAa,CAAC;AA4FhI;;GAEG;AACH,qBAAa,gBAAiB,YAAW,SAAS;IAChD,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO;CAG3D;AAyDD;;GAEG;AACH,qBAAa,aAAc,YAAW,MAAM;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,GAAE,SAAS,aAAa,EAAO;IAEhE,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC;CA0EjF"}
@@ -87,6 +87,10 @@ function validateBodyKeys(request, bodyKeys) {
87
87
  });
88
88
  }
89
89
  }
90
+
91
+ /**
92
+ * Represents the default converter.
93
+ */
90
94
  export class DefaultConverter {
91
95
  convert(value, _target) {
92
96
  return value;
@@ -131,6 +135,10 @@ async function resolveConverter(value, context, cache) {
131
135
  throw error;
132
136
  }
133
137
  }
138
+
139
+ /**
140
+ * Represents the default binder.
141
+ */
134
142
  export class DefaultBinder {
135
143
  constructor(converters = []) {
136
144
  this.converters = converters;
@@ -1,5 +1,8 @@
1
1
  import { type Constructor } from '@fluojs/core';
2
2
  import type { Validator } from '../types.js';
3
+ /**
4
+ * Represents the http dto validation adapter.
5
+ */
3
6
  export declare class HttpDtoValidationAdapter implements Validator {
4
7
  private readonly validator;
5
8
  private throwBadRequestForValidationError;
@@ -1 +1 @@
1
- {"version":3,"file":"dto-validation-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/dto-validation-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAMhD,OAAO,KAAK,EAAmB,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9D,qBAAa,wBAAyB,YAAW,SAAS;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAExD,OAAO,CAAC,iCAAiC;IAMzC,OAAO,CAAC,6BAA6B;IAiB/B,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5D,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAWzE"}
1
+ {"version":3,"file":"dto-validation-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/dto-validation-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAMhD,OAAO,KAAK,EAAmB,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9D;;GAEG;AACH,qBAAa,wBAAyB,YAAW,SAAS;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAExD,OAAO,CAAC,iCAAiC;IAMzC,OAAO,CAAC,6BAA6B;IAiB/B,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5D,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAWzE"}
@@ -2,6 +2,9 @@ import { getDtoBindingSchema } from '@fluojs/core/internal';
2
2
  import { DefaultValidator as BaseDefaultValidator, DtoValidationError } from '@fluojs/validation';
3
3
  import { BadRequestException } from '../exceptions.js';
4
4
  import { toInputErrorDetail } from '../input-error-detail.js';
5
+ /**
6
+ * Represents the http dto validation adapter.
7
+ */
5
8
  export class HttpDtoValidationAdapter {
6
9
  validator = new BaseDefaultValidator();
7
10
  throwBadRequestForValidationError(error) {
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-error-policy.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatch-error-policy.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAiBrD,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvH"}
1
+ {"version":3,"file":"dispatch-error-policy.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatch-error-policy.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAiBrD;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvH"}
@@ -14,6 +14,15 @@ function toHttpException(error) {
14
14
  cause: error
15
15
  });
16
16
  }
17
+
18
+ /**
19
+ * Write error response.
20
+ *
21
+ * @param error The error.
22
+ * @param response The response.
23
+ * @param requestId The request id.
24
+ * @returns The write error response result.
25
+ */
17
26
  export async function writeErrorResponse(error, response, requestId) {
18
27
  if (response.committed) {
19
28
  return;
@@ -1,3 +1,11 @@
1
1
  import type { Binder, HandlerDescriptor, RequestContext } from '../types.js';
2
+ /**
3
+ * Invoke controller handler.
4
+ *
5
+ * @param handler The handler.
6
+ * @param requestContext The request context.
7
+ * @param binder The binder.
8
+ * @returns The invoke controller handler result.
9
+ */
2
10
  export declare function invokeControllerHandler(handler: HandlerDescriptor, requestContext: RequestContext, binder?: Binder): Promise<unknown>;
3
11
  //# sourceMappingURL=dispatch-handler-policy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-handler-policy.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatch-handler-policy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA2B,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAKtG,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,iBAAiB,EAC1B,cAAc,EAAE,cAAc,EAC9B,MAAM,GAAE,MAAsB,GAC7B,OAAO,CAAC,OAAO,CAAC,CAuBlB"}
1
+ {"version":3,"file":"dispatch-handler-policy.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatch-handler-policy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA2B,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAKtG;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,iBAAiB,EAC1B,cAAc,EAAE,cAAc,EAC9B,MAAM,GAAE,MAAsB,GAC7B,OAAO,CAAC,OAAO,CAAC,CAuBlB"}
@@ -3,6 +3,15 @@ import { DefaultBinder } from '../adapters/binding.js';
3
3
  import { HttpDtoValidationAdapter } from '../adapters/dto-validation-adapter.js';
4
4
  const defaultBinder = new DefaultBinder();
5
5
  const defaultValidator = new HttpDtoValidationAdapter();
6
+
7
+ /**
8
+ * Invoke controller handler.
9
+ *
10
+ * @param handler The handler.
11
+ * @param requestContext The request context.
12
+ * @param binder The binder.
13
+ * @returns The invoke controller handler result.
14
+ */
6
15
  export async function invokeControllerHandler(handler, requestContext, binder = defaultBinder) {
7
16
  const controller = await requestContext.container.resolve(handler.controllerToken);
8
17
  const method = controller[handler.methodName];
@@ -1,6 +1,16 @@
1
1
  import { resolveContentNegotiation, type ResolvedContentNegotiation } from './dispatch-content-negotiation.js';
2
2
  import { writeErrorResponse } from './dispatch-error-policy.js';
3
3
  import type { FrameworkRequest, FrameworkResponse, HandlerDescriptor } from '../types.js';
4
+ /**
5
+ * Write success response.
6
+ *
7
+ * @param handler The handler.
8
+ * @param request The request.
9
+ * @param response The response.
10
+ * @param value The value.
11
+ * @param contentNegotiation The content negotiation.
12
+ * @returns The write success response result.
13
+ */
4
14
  export declare function writeSuccessResponse(handler: HandlerDescriptor, request: FrameworkRequest, response: FrameworkResponse, value: unknown, contentNegotiation: ResolvedContentNegotiation | undefined): Promise<void>;
5
15
  export { resolveContentNegotiation, writeErrorResponse };
6
16
  export type { ResolvedContentNegotiation };
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-response-policy.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatch-response-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EAEzB,KAAK,0BAA0B,EAChC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAcrB,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,iBAAiB,EAC3B,KAAK,EAAE,OAAO,EACd,kBAAkB,EAAE,0BAA0B,GAAG,SAAS,GACzD,OAAO,CAAC,IAAI,CAAC,CAoCf;AAED,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,CAAC;AACzD,YAAY,EAAE,0BAA0B,EAAE,CAAC"}
1
+ {"version":3,"file":"dispatch-response-policy.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatch-response-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EAEzB,KAAK,0BAA0B,EAChC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAcrB;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,iBAAiB,EAC3B,KAAK,EAAE,OAAO,EACd,kBAAkB,EAAE,0BAA0B,GAAG,SAAS,GACzD,OAAO,CAAC,IAAI,CAAC,CAoCf;AAED,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,CAAC;AACzD,YAAY,EAAE,0BAA0B,EAAE,CAAC"}
@@ -11,6 +11,17 @@ function resolveDefaultSuccessStatus(handler, value) {
11
11
  return 200;
12
12
  }
13
13
  }
14
+
15
+ /**
16
+ * Write success response.
17
+ *
18
+ * @param handler The handler.
19
+ * @param request The request.
20
+ * @param response The response.
21
+ * @param value The value.
22
+ * @param contentNegotiation The content negotiation.
23
+ * @returns The write success response result.
24
+ */
14
25
  export async function writeSuccessResponse(handler, request, response, value, contentNegotiation) {
15
26
  if (response.committed) {
16
27
  return;
@@ -1,4 +1,17 @@
1
1
  import type { FrameworkRequest, HandlerMapping, HandlerMatch, RequestContext } from '../types.js';
2
+ /**
3
+ * Match handler or throw.
4
+ *
5
+ * @param handlerMapping The handler mapping.
6
+ * @param request The request.
7
+ * @returns The match handler or throw result.
8
+ */
2
9
  export declare function matchHandlerOrThrow(handlerMapping: HandlerMapping, request: FrameworkRequest): HandlerMatch;
10
+ /**
11
+ * Update request params.
12
+ *
13
+ * @param requestContext The request context.
14
+ * @param params The params.
15
+ */
3
16
  export declare function updateRequestParams(requestContext: RequestContext, params: Readonly<Record<string, string>>): void;
4
17
  //# sourceMappingURL=dispatch-routing-policy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-routing-policy.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatch-routing-policy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElG,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,cAAc,EAAE,OAAO,EAAE,gBAAgB,GAAG,YAAY,CAQ3G;AAED,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,CAKlH"}
1
+ {"version":3,"file":"dispatch-routing-policy.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatch-routing-policy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElG;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,cAAc,EAAE,OAAO,EAAE,gBAAgB,GAAG,YAAY,CAQ3G;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,CAKlH"}
@@ -1,4 +1,11 @@
1
1
  import { HandlerNotFoundError } from '../errors.js';
2
+ /**
3
+ * Match handler or throw.
4
+ *
5
+ * @param handlerMapping The handler mapping.
6
+ * @param request The request.
7
+ * @returns The match handler or throw result.
8
+ */
2
9
  export function matchHandlerOrThrow(handlerMapping, request) {
3
10
  const match = handlerMapping.match(request);
4
11
  if (!match) {
@@ -6,6 +13,13 @@ export function matchHandlerOrThrow(handlerMapping, request) {
6
13
  }
7
14
  return match;
8
15
  }
16
+
17
+ /**
18
+ * Update request params.
19
+ *
20
+ * @param requestContext The request context.
21
+ * @param params The params.
22
+ */
9
23
  export function updateRequestParams(requestContext, params) {
10
24
  requestContext.request = {
11
25
  ...requestContext.request,
@@ -1 +1 @@
1
- {"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAW5C,OAAO,KAAK,EACV,MAAM,EACN,yBAAyB,EACzB,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAGjB,cAAc,EACd,eAAe,EAGf,cAAc,EAId,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,MAAM,YAAY,GAA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AAM,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC;AAEpK;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,iDAAiD;IACjD,aAAa,CAAC,EAAE,cAAc,EAAE,CAAC;IACjC,kFAAkF;IAClF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,kBAAkB,CAAC,EAAE,yBAAyB,CAAC;IAC/C,sDAAsD;IACtD,cAAc,EAAE,cAAc,CAAC;IAC/B,2DAA2D;IAC3D,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;IACjC,0DAA0D;IAC1D,SAAS,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAClC,qCAAqC;IACrC,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,qDAAqD;IACrD,aAAa,EAAE,SAAS,CAAC;CAC1B;AA8SD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,UAAU,CAoC7E"}
@@ -31,6 +31,28 @@ function createDispatchRequest(request) {
31
31
  }
32
32
  };
33
33
  }
34
+ function cloneHandlerDescriptor(descriptor) {
35
+ return {
36
+ ...descriptor,
37
+ metadata: {
38
+ ...descriptor.metadata,
39
+ moduleMiddleware: [...descriptor.metadata.moduleMiddleware],
40
+ pathParams: [...descriptor.metadata.pathParams]
41
+ },
42
+ route: {
43
+ ...descriptor.route,
44
+ guards: descriptor.route.guards ? [...descriptor.route.guards] : undefined,
45
+ headers: descriptor.route.headers?.map(header => ({
46
+ ...header
47
+ })),
48
+ interceptors: descriptor.route.interceptors ? [...descriptor.route.interceptors] : undefined,
49
+ produces: descriptor.route.produces ? [...descriptor.route.produces] : undefined,
50
+ redirect: descriptor.route.redirect ? {
51
+ ...descriptor.route.redirect
52
+ } : undefined
53
+ }
54
+ };
55
+ }
34
56
  function readRequestId(request) {
35
57
  const raw = request.headers['x-request-id'] ?? request.headers['X-Request-Id'];
36
58
  const value = Array.isArray(raw) ? raw[0] : raw;
@@ -71,29 +93,41 @@ async function notifyObservers(observers, requestContext, callback, handler) {
71
93
  }
72
94
  }
73
95
  async function notifyObserversSafely(observers, requestContext, callback, logger, handler) {
96
+ if (observers.length === 0) {
97
+ return;
98
+ }
74
99
  try {
75
100
  await notifyObservers(observers, requestContext, callback, handler);
76
101
  } catch (error) {
77
102
  logDispatchFailure(logger, 'Request observer threw an unhandled error.', error);
78
103
  }
79
104
  }
105
+ function mergeInterceptors(globalInterceptors, routeInterceptors) {
106
+ if (globalInterceptors.length === 0) {
107
+ return routeInterceptors;
108
+ }
109
+ if (routeInterceptors.length === 0) {
110
+ return globalInterceptors;
111
+ }
112
+ return [...globalInterceptors, ...routeInterceptors];
113
+ }
80
114
  async function dispatchMatchedHandler(handler, requestContext, observers, contentNegotiation, binder, globalInterceptors, logger) {
81
- const guardContext = {
82
- handler,
83
- requestContext
84
- };
85
- const interceptorContext = {
86
- handler,
87
- requestContext
88
- };
89
- await runGuardChain(handler.route.guards ?? [], guardContext);
115
+ const routeGuards = handler.route.guards ?? [];
116
+ if (routeGuards.length > 0) {
117
+ const guardContext = {
118
+ handler,
119
+ requestContext
120
+ };
121
+ await runGuardChain(routeGuards, guardContext);
122
+ }
90
123
  if (requestContext.response.committed) {
91
124
  return;
92
125
  }
93
- const interceptors = [...(globalInterceptors ?? []), ...(handler.route.interceptors ?? [])];
94
- const result = await runInterceptorChain(interceptors, interceptorContext, async () => {
95
- return invokeControllerHandler(handler, requestContext, binder);
96
- });
126
+ const routeInterceptors = handler.route.interceptors ?? [];
127
+ const result = globalInterceptors.length === 0 && routeInterceptors.length === 0 ? await invokeControllerHandler(handler, requestContext, binder) : await runInterceptorChain(mergeInterceptors(globalInterceptors, routeInterceptors), {
128
+ handler,
129
+ requestContext
130
+ }, async () => invokeControllerHandler(handler, requestContext, binder));
97
131
  ensureRequestNotAborted(requestContext.request);
98
132
  if (!(result instanceof SseResponse) && !requestContext.response.committed) {
99
133
  await writeSuccessResponse(handler, requestContext.request, requestContext.response, result, contentNegotiation);
@@ -143,7 +177,7 @@ async function runDispatchPipeline(context) {
143
177
  response: context.response
144
178
  };
145
179
  await runMiddlewareChain(match.descriptor.metadata.moduleMiddleware ?? [], moduleMiddlewareContext, async () => {
146
- await dispatchMatchedHandler(match.descriptor, context.requestContext, context.observers, context.contentNegotiation, context.options.binder, context.options.interceptors, context.options.logger);
180
+ await dispatchMatchedHandler(match.descriptor, context.requestContext, context.observers, context.contentNegotiation, context.options.binder, context.options.interceptors ?? [], context.options.logger);
147
181
  });
148
182
  });
149
183
  }
@@ -167,11 +201,15 @@ async function handleDispatchError(context, error) {
167
201
  */
168
202
  export function createDispatcher(options) {
169
203
  const contentNegotiation = resolveContentNegotiation(options.contentNegotiation);
170
- return {
204
+ const observers = options.observers ?? [];
205
+ const dispatcher = {
206
+ describeRoutes() {
207
+ return options.handlerMapping.descriptors.map(descriptor => cloneHandlerDescriptor(descriptor));
208
+ },
171
209
  async dispatch(request, response) {
172
210
  const phaseContext = {
173
211
  contentNegotiation,
174
- observers: options.observers ?? [],
212
+ observers,
175
213
  options,
176
214
  requestContext: createDispatchContext(createDispatchRequest(request), response, options.rootContainer),
177
215
  response
@@ -193,4 +231,5 @@ export function createDispatcher(options) {
193
231
  });
194
232
  }
195
233
  };
234
+ return dispatcher;
196
235
  }
package/dist/errors.d.ts CHANGED
@@ -5,6 +5,9 @@ import { FluoError } from '@fluojs/core';
5
5
  export declare class RouteConflictError extends FluoError {
6
6
  constructor(message: string);
7
7
  }
8
+ /**
9
+ * Represents the invalid route path error.
10
+ */
8
11
  export declare class InvalidRoutePathError extends FluoError {
9
12
  constructor(message: string);
10
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;gBACnC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,qBAAsB,SAAQ,SAAS;gBACtC,OAAO,EAAE,MAAM;CAG5B;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;gBACrC,OAAO,EAAE,MAAM;CAG5B;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,SAA4C;CAGhE"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;gBACnC,OAAO,EAAE,MAAM;CAG5B;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,SAAS;gBACtC,OAAO,EAAE,MAAM;CAG5B;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;gBACrC,OAAO,EAAE,MAAM;CAG5B;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,SAA4C;CAGhE"}
package/dist/errors.js CHANGED
@@ -10,6 +10,10 @@ export class RouteConflictError extends FluoError {
10
10
  });
11
11
  }
12
12
  }
13
+
14
+ /**
15
+ * Represents the invalid route path error.
16
+ */
13
17
  export class InvalidRoutePathError extends FluoError {
14
18
  constructor(message) {
15
19
  super(message, {
package/dist/guards.d.ts CHANGED
@@ -1,3 +1,10 @@
1
1
  import type { GuardContext, GuardLike } from './types.js';
2
+ /**
3
+ * Run guard chain.
4
+ *
5
+ * @param definitions The definitions.
6
+ * @param context The context.
7
+ * @returns The run guard chain result.
8
+ */
2
9
  export declare function runGuardChain(definitions: GuardLike[], context: GuardContext): Promise<void>;
3
10
  //# sourceMappingURL=guards.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAS,YAAY,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAC;AAcjF,wBAAsB,aAAa,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CASlG"}
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAS,YAAY,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAC;AAcjF;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAalG"}
package/dist/guards.js CHANGED
@@ -8,7 +8,18 @@ async function resolveGuard(definition, requestContext) {
8
8
  }
9
9
  return requestContext.container.resolve(definition);
10
10
  }
11
+
12
+ /**
13
+ * Run guard chain.
14
+ *
15
+ * @param definitions The definitions.
16
+ * @param context The context.
17
+ * @returns The run guard chain result.
18
+ */
11
19
  export async function runGuardChain(definitions, context) {
20
+ if (definitions.length === 0) {
21
+ return;
22
+ }
12
23
  for (const definition of definitions) {
13
24
  const guard = await resolveGuard(definition, context.requestContext);
14
25
  const result = await guard.canActivate(context);
@@ -1,10 +1,19 @@
1
1
  import type { MetadataSource } from '@fluojs/core';
2
2
  import type { HttpExceptionDetail } from './exceptions.js';
3
+ /**
4
+ * Describes the input error detail contract.
5
+ */
3
6
  export interface InputErrorDetail {
4
7
  code: string;
5
8
  field?: string;
6
9
  message: string;
7
10
  source?: MetadataSource;
8
11
  }
12
+ /**
13
+ * To input error detail.
14
+ *
15
+ * @param detail The detail.
16
+ * @returns The to input error detail result.
17
+ */
9
18
  export declare function toInputErrorDetail(detail: InputErrorDetail): HttpExceptionDetail;
10
19
  //# sourceMappingURL=input-error-detail.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"input-error-detail.d.ts","sourceRoot":"","sources":["../src/input-error-detail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,GAAG,mBAAmB,CAOhF"}
1
+ {"version":3,"file":"input-error-detail.d.ts","sourceRoot":"","sources":["../src/input-error-detail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,GAAG,mBAAmB,CAOhF"}