@dunx/http 3.0.1 → 3.0.2

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.
@@ -1,4 +1,4 @@
1
- import { type Deps, type DynamicModule, type FactoryProvider, type Token } from '@dunx/core';
1
+ import { type Deps, type DynamicModule, type AsyncModuleConfig, type Token } from '@dunx/core';
2
2
  import { type HttpClientOptionsInit } from './options.js';
3
3
  import { HttpService } from './service.js';
4
4
  /**
@@ -57,5 +57,5 @@ export declare class HttpModule {
57
57
  * token has to exist before the factory runs.
58
58
  */
59
59
  static forRootAsync(load: () => HttpClientOptionsInit | Promise<HttpClientOptionsInit>, name?: string): DynamicModule;
60
- static forRootAsync<const D extends Deps>(config: FactoryProvider<HttpClientOptionsInit, D>, name?: string): DynamicModule;
60
+ static forRootAsync<const D extends Deps>(config: AsyncModuleConfig<HttpClientOptionsInit, D>, name?: string): DynamicModule;
61
61
  }
package/dist/client.js CHANGED
@@ -292,11 +292,12 @@ var serviceFrom = (target, optionsToken) => provide(target, {
292
292
  useFactory: (options, logger, context) => new HttpService(options, logger, context),
293
293
  inject: [optionsToken, Logger2, RequestContext2]
294
294
  });
295
- var namedModule = (name, options) => {
295
+ var namedModule = (name, options, imports = []) => {
296
296
  const optionsToken = token(`HttpClientOptions(${name})`);
297
297
  const optionsProvider = options instanceof HttpClientOptions ? provide(optionsToken, { useValue: options }) : provide(optionsToken, options);
298
298
  return {
299
299
  module: HttpModule,
300
+ imports,
300
301
  exports: [optionsToken, httpClient(name)],
301
302
  providers: [optionsProvider, serviceFrom(httpClient(name), optionsToken)]
302
303
  };
@@ -319,12 +320,14 @@ class HttpModule {
319
320
  static forRootAsync(source, name) {
320
321
  const load = typeof source === "function" ? source : source.useFactory;
321
322
  const inject = typeof source === "function" ? [] : source.inject ?? [];
323
+ const imports = typeof source === "function" ? [] : source.imports ?? [];
322
324
  const useFactory = async (...deps) => new HttpClientOptions(await load(...deps));
323
325
  if (name !== undefined) {
324
- return namedModule(name, { useFactory, inject });
326
+ return namedModule(name, { useFactory, inject }, imports);
325
327
  }
326
328
  return {
327
329
  module: HttpModule,
330
+ imports,
328
331
  exports: [HttpClientOptions, HttpService],
329
332
  providers: [
330
333
  provide(HttpClientOptions, { useFactory, inject }),
@@ -1,4 +1,4 @@
1
- import { type Deps, type DynamicModule, type FactoryProvider } from '@dunx/core';
1
+ import { type Deps, type DynamicModule, type AsyncModuleConfig } from '@dunx/core';
2
2
  import { type CompressionOptionsInit } from './options.js';
3
3
  /**
4
4
  * Binds `Compression` and its options. Like `StaticModule`, importing it does not
@@ -14,7 +14,5 @@ import { type CompressionOptionsInit } from './options.js';
14
14
  export declare class CompressionModule {
15
15
  static forRoot(init?: CompressionOptionsInit): DynamicModule;
16
16
  /** `forRoot` with the options read off the container - a config value, usually. */
17
- static forRootAsync<const D extends Deps>(config: FactoryProvider<CompressionOptionsInit, D> & {
18
- readonly imports?: DynamicModule['imports'];
19
- }): DynamicModule;
17
+ static forRootAsync<const D extends Deps>(config: AsyncModuleConfig<CompressionOptionsInit, D>): DynamicModule;
20
18
  }
@@ -1,4 +1,4 @@
1
- import { type Deps, type DynamicModule, type FactoryProvider } from '@dunx/core';
1
+ import { type Deps, type DynamicModule, type AsyncModuleConfig } from '@dunx/core';
2
2
  import { type HealthOptionsInit } from './registry.js';
3
3
  /**
4
4
  * Liveness and readiness, and the drain that makes readiness worth having.
@@ -33,8 +33,7 @@ export declare class HealthModule {
33
33
  * table is folded into one closure per route when the server binds, so it cannot
34
34
  * wait on a factory. Pass `routes: false` and mount your own if that matters.
35
35
  */
36
- static forRootAsync<const D extends Deps>(config: FactoryProvider<HealthOptionsInit, D> & {
37
- readonly imports?: DynamicModule['imports'];
36
+ static forRootAsync<const D extends Deps>(config: AsyncModuleConfig<HealthOptionsInit, D> & {
38
37
  readonly routes?: boolean;
39
38
  readonly documented?: boolean;
40
39
  }): DynamicModule;
@@ -1,5 +1,5 @@
1
1
  import type { OnBeforeShutdown } from '@dunx/core';
2
- export interface ReadinessOptionsInit {
2
+ interface ReadinessOptionsInit {
3
3
  /**
4
4
  * How long to keep failing readiness after the drain starts, before the server
5
5
  * stops accepting. Default `0`.
@@ -49,3 +49,4 @@ export declare class Readiness implements OnBeforeShutdown {
49
49
  */
50
50
  onBeforeShutdown(): Promise<void>;
51
51
  }
52
+ export {};
package/dist/index.js CHANGED
@@ -77,6 +77,8 @@ var trustedHops = (setting) => {
77
77
  return 0;
78
78
  return Number.isFinite(setting) ? Math.max(0, Math.trunc(setting)) : 0;
79
79
  };
80
+ var IPV4_MAPPED = /^::ffff:(\d{1,3}(?:\.\d{1,3}){3})$/i;
81
+ var unmap = (address) => address === undefined ? undefined : IPV4_MAPPED.exec(address)?.[1] ?? address;
80
82
  var sources = new WeakMap;
81
83
 
82
84
  class ClientAddress {
@@ -90,9 +92,9 @@ class ClientAddress {
90
92
  const entries = (req.headers.get("x-forwarded-for") ?? "").split(",").map((entry2) => entry2.trim()).filter((entry2) => entry2.length > 0);
91
93
  const entry = entries[Math.max(0, entries.length - hops)];
92
94
  if (entry)
93
- return entry;
95
+ return unmap(entry);
94
96
  }
95
- return source.server.requestIP(req)?.address;
97
+ return unmap(source.server.requestIP(req)?.address);
96
98
  }
97
99
  }
98
100
  var attachAddressSource = (target, source) => {
@@ -1,5 +1,5 @@
1
1
  import type { BunRequest, Server } from 'bun';
2
- export interface AddressSource {
2
+ interface AddressSource {
3
3
  readonly server: Server<unknown>;
4
4
  readonly trustProxy: boolean | number;
5
5
  }
@@ -8,6 +8,9 @@ export interface AddressSource {
8
8
  * right of `X-Forwarded-For` by the number of trusted hops, never from the left: a
9
9
  * client can send anything, and only the entries a proxy appended carry weight.
10
10
  *
11
+ * An IPv4-mapped IPv6 address is returned in its IPv4 form: `::ffff:10.0.0.1`
12
+ * comes back as `10.0.0.1`, from the header and from the socket alike.
13
+ *
11
14
  * Bound by `HttpFactory`'s global wrapper, which is not optional under module
12
15
  * scoping - an unbound class self-binds into whichever scope asks first, so a
13
16
  * second module injecting it was a boot error.
@@ -17,3 +20,4 @@ export declare class ClientAddress {
17
20
  }
18
21
  /** Internal: `listen()` hands the bound server to the resolved singleton. */
19
22
  export declare const attachAddressSource: (target: ClientAddress, source: AddressSource) => void;
23
+ export {};
@@ -1,4 +1,4 @@
1
- import { type Deps, type DynamicModule, type FactoryProvider } from '@dunx/core';
1
+ import { type Deps, type DynamicModule, type AsyncModuleConfig } from '@dunx/core';
2
2
  import { type StaticOptionsInit } from './options.js';
3
3
  /**
4
4
  * Serves a directory. Like the dashboard, it does not register itself:
@@ -46,7 +46,5 @@ import { type StaticOptionsInit } from './options.js';
46
46
  export declare class StaticModule {
47
47
  static forRoot(init: StaticOptionsInit): DynamicModule;
48
48
  /** `forRoot` with the root read off the container - a config value, usually. */
49
- static forRootAsync<const D extends Deps>(config: FactoryProvider<StaticOptionsInit, D> & {
50
- readonly imports?: DynamicModule['imports'];
51
- }): DynamicModule;
49
+ static forRootAsync<const D extends Deps>(config: AsyncModuleConfig<StaticOptionsInit, D>): DynamicModule;
52
50
  }
@@ -1,4 +1,4 @@
1
- import { type Deps, type DynamicModule, type FactoryProvider } from '@dunx/core';
1
+ import { type Deps, type DynamicModule, type AsyncModuleConfig } from '@dunx/core';
2
2
  import { type ThrottleOptionsInit } from './options.js';
3
3
  /**
4
4
  * The decorator, the guard, the counter and its options.
@@ -27,7 +27,5 @@ import { type ThrottleOptionsInit } from './options.js';
27
27
  export declare class ThrottleModule {
28
28
  static forRoot(init: ThrottleOptionsInit): DynamicModule;
29
29
  /** `forRoot` with the limit read off the container - a config value, usually. */
30
- static forRootAsync<const D extends Deps>(config: FactoryProvider<ThrottleOptionsInit, D> & {
31
- readonly imports?: DynamicModule['imports'];
32
- }): DynamicModule;
30
+ static forRootAsync<const D extends Deps>(config: AsyncModuleConfig<ThrottleOptionsInit, D>): DynamicModule;
33
31
  }
@@ -31,10 +31,11 @@ export interface WebSocketRuntime {
31
31
  */
32
32
  readonly warnings: readonly string[];
33
33
  }
34
- export interface GatewaySummary {
34
+ interface GatewaySummary {
35
35
  readonly name: string;
36
36
  readonly path: string;
37
37
  /** `@OnMessage('name')` events. A raw catch-all has no name to report. */
38
38
  readonly events: readonly string[];
39
39
  }
40
40
  export declare const buildWebSocket: (discovered: readonly DiscoveredGateway[], options?: SocketOptions, middleware?: readonly SocketMiddleware[]) => WebSocketRuntime;
41
+ export {};
@@ -1,4 +1,4 @@
1
- import { type Ctor, type InjectionToken, type ResolvedModule } from '@dunx/core';
1
+ import { type InjectionToken, type ResolvedModule } from '@dunx/core';
2
2
  import { type HandlerKind } from './marker.js';
3
3
  /**
4
4
  * A discovered handler, already bound to its instance. Every kind has a different
@@ -26,12 +26,6 @@ export declare const normalizePath: (path: string) => string;
26
26
  * handler is bound off the instance.
27
27
  */
28
28
  export declare const discoverGateway: (instance: object) => DiscoveredGateway;
29
- /**
30
- * The name of the first handler a class declares, without constructing it. A
31
- * provider that declares one but is not a gateway would silently never receive a
32
- * frame, so that becomes a boot error naming the method.
33
- */
34
- export declare const findHandlerMethod: (ctor: Ctor<unknown>) => string | undefined;
35
29
  /**
36
30
  * Gateways are declared in `@Module({ providers })` like any other injectable and
37
31
  * found here by their marker - the same discovery-by-inspection controllers get,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dunx/http",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Bun.serve adapter for the dunx framework: controllers, middleware and WebSocket gateways",
5
5
  "keywords": [
6
6
  "bun",
@@ -62,7 +62,7 @@
62
62
  "@dunx/core": "workspace:*"
63
63
  },
64
64
  "peerDependencies": {
65
- "@dunx/core": "^3.0.1",
65
+ "@dunx/core": "^3.0.2",
66
66
  "@types/bun": ">=1.3.0"
67
67
  },
68
68
  "peerDependenciesMeta": {