@horizon-republic/nestjs-jetstream 2.11.0 → 2.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -512,6 +512,8 @@ var resolveCaptureBody = (option) => {
512
512
  };
513
513
  };
514
514
  var resolveOtelOptions = (options = {}) => {
515
+ if (options === true) options = {};
516
+ if (options === false) options = { enabled: false };
515
517
  return {
516
518
  enabled: options.enabled ?? true,
517
519
  traces: expandTracesOption(options.traces),
@@ -591,7 +593,7 @@ var extractContext = (ctx, carrier, getter) => import_api.propagation.extract(ct
591
593
 
592
594
  // src/otel/tracer.ts
593
595
  var import_api2 = require("@opentelemetry/api");
594
- var PACKAGE_VERSION = true ? "2.11.0" : "0.0.0";
596
+ var PACKAGE_VERSION = true ? "2.11.1" : "0.0.0";
595
597
  var getTracer = () => import_api2.trace.getTracer(TRACER_NAME, PACKAGE_VERSION);
596
598
 
597
599
  // src/otel/carrier.ts
@@ -2751,6 +2753,7 @@ var JetstreamMetricsService = class {
2751
2753
  activeServers = /* @__PURE__ */ new Set();
2752
2754
  async onApplicationBootstrap() {
2753
2755
  if (this.metrics !== null) return;
2756
+ if (!this.options.metrics || !this.config || !this.promClient) return;
2754
2757
  if (!this.config.register) {
2755
2758
  throw new Error(
2756
2759
  "JetstreamMetricsService requires a prom-client Registry \u2014 none was resolved by JetstreamMetricsModule."
@@ -2776,7 +2779,7 @@ var JetstreamMetricsService = class {
2776
2779
  }
2777
2780
  /** @internal Visible for tests. `0` disables polling. */
2778
2781
  getEffectivePollInterval() {
2779
- return this.config.pollInterval ?? DEFAULT_POLL_INTERVAL_MS;
2782
+ return this.config?.pollInterval ?? DEFAULT_POLL_INTERVAL_MS;
2780
2783
  }
2781
2784
  /**
2782
2785
  * NATS connects during early bootstrap, before this service subscribes to
@@ -2942,28 +2945,29 @@ var normalizeMetricsConfig = (option, promClient) => {
2942
2945
  };
2943
2946
  };
2944
2947
  var JetstreamMetricsModule = class {
2945
- static forFeature(metricsOption) {
2946
- if (!metricsOption) {
2947
- return { module: JetstreamMetricsModule, providers: [], exports: [] };
2948
- }
2948
+ static forFeature() {
2949
2949
  const promClientProvider = {
2950
2950
  provide: JETSTREAM_METRICS_PROM_CLIENT,
2951
- useFactory: async () => {
2951
+ inject: [JETSTREAM_OPTIONS],
2952
+ useFactory: async (opts) => {
2953
+ if (!opts.metrics) return null;
2952
2954
  const mod = await resolvePromClient();
2953
2955
  return { Counter: mod.Counter, Histogram: mod.Histogram, Gauge: mod.Gauge };
2954
2956
  }
2955
2957
  };
2956
2958
  const configProvider = {
2957
2959
  provide: JETSTREAM_METRICS_CONFIG,
2958
- useFactory: async () => {
2960
+ inject: [JETSTREAM_OPTIONS],
2961
+ useFactory: async (opts) => {
2962
+ if (!opts.metrics) return null;
2959
2963
  const mod = await resolvePromClient();
2960
- return normalizeMetricsConfig(metricsOption, mod);
2964
+ return normalizeMetricsConfig(opts.metrics, mod);
2961
2965
  }
2962
2966
  };
2963
2967
  const registryProvider = {
2964
2968
  provide: JETSTREAM_METRICS_REGISTRY,
2965
2969
  inject: [JETSTREAM_METRICS_CONFIG],
2966
- useFactory: (cfg) => cfg.register
2970
+ useFactory: (cfg) => cfg?.register ?? null
2967
2971
  };
2968
2972
  const serviceProvider = {
2969
2973
  provide: JetstreamMetricsService,
@@ -5320,7 +5324,7 @@ var JetstreamModule = class {
5320
5324
  return {
5321
5325
  module: JetstreamModule,
5322
5326
  global: true,
5323
- imports: options.metrics ? [JetstreamMetricsModule.forFeature(options.metrics)] : [],
5327
+ imports: [JetstreamMetricsModule.forFeature()],
5324
5328
  providers,
5325
5329
  exports: [
5326
5330
  JETSTREAM_CONNECTION,
@@ -5346,11 +5350,10 @@ var JetstreamModule = class {
5346
5350
  static forRootAsync(asyncOptions) {
5347
5351
  const asyncProviders = this.createAsyncOptionsProvider(asyncOptions);
5348
5352
  const coreProviders = this.createCoreDependentProviders();
5349
- const metricsImports = asyncOptions.metrics ? [JetstreamMetricsModule.forFeature(asyncOptions.metrics)] : [];
5350
5353
  return {
5351
5354
  module: JetstreamModule,
5352
5355
  global: true,
5353
- imports: [...asyncOptions.imports ?? [], ...metricsImports],
5356
+ imports: [...asyncOptions.imports ?? [], JetstreamMetricsModule.forFeature()],
5354
5357
  providers: [...asyncProviders, ...coreProviders],
5355
5358
  exports: [
5356
5359
  JETSTREAM_CONNECTION,
package/dist/index.d.cts CHANGED
@@ -1234,9 +1234,12 @@ interface JetstreamModuleOptions {
1234
1234
  * consuming application, all tracer calls are no-ops — there is no
1235
1235
  * runtime cost.
1236
1236
  *
1237
+ * Accepts a full {@link OtelOptions} object, or the boolean shorthand
1238
+ * `true` (== defaults) / `false` (== `{ enabled: false }`).
1239
+ *
1237
1240
  * @see OtelOptions
1238
1241
  */
1239
- otel?: OtelOptions;
1242
+ otel?: OtelOptions | boolean;
1240
1243
  }
1241
1244
  /** Options for `JetstreamModule.forFeature()`. */
1242
1245
  interface JetstreamFeatureOptions {
@@ -1258,15 +1261,6 @@ type JetstreamModuleAsyncOptions = {
1258
1261
  name: string;
1259
1262
  /** Additional module imports (e.g., ConfigModule). */
1260
1263
  imports?: ModuleMetadata['imports'];
1261
- /**
1262
- * Built-in Prometheus metrics. Specified at the async-options level (parallel
1263
- * to {@link name}) because module composition is decided synchronously before
1264
- * the async factory runs. Use `true` for defaults, a {@link MetricsConfig}
1265
- * object for full control, or omit/`false` to disable entirely.
1266
- *
1267
- * @see JetstreamModuleOptions.metrics
1268
- */
1269
- metrics?: MetricsOption;
1270
1264
  } & ({
1271
1265
  useFactory(...args: unknown[]): Promise<Omit<JetstreamModuleOptions, 'name'>> | Omit<JetstreamModuleOptions, 'name'>;
1272
1266
  inject?: FactoryProvider['inject'];
package/dist/index.d.ts CHANGED
@@ -1234,9 +1234,12 @@ interface JetstreamModuleOptions {
1234
1234
  * consuming application, all tracer calls are no-ops — there is no
1235
1235
  * runtime cost.
1236
1236
  *
1237
+ * Accepts a full {@link OtelOptions} object, or the boolean shorthand
1238
+ * `true` (== defaults) / `false` (== `{ enabled: false }`).
1239
+ *
1237
1240
  * @see OtelOptions
1238
1241
  */
1239
- otel?: OtelOptions;
1242
+ otel?: OtelOptions | boolean;
1240
1243
  }
1241
1244
  /** Options for `JetstreamModule.forFeature()`. */
1242
1245
  interface JetstreamFeatureOptions {
@@ -1258,15 +1261,6 @@ type JetstreamModuleAsyncOptions = {
1258
1261
  name: string;
1259
1262
  /** Additional module imports (e.g., ConfigModule). */
1260
1263
  imports?: ModuleMetadata['imports'];
1261
- /**
1262
- * Built-in Prometheus metrics. Specified at the async-options level (parallel
1263
- * to {@link name}) because module composition is decided synchronously before
1264
- * the async factory runs. Use `true` for defaults, a {@link MetricsConfig}
1265
- * object for full control, or omit/`false` to disable entirely.
1266
- *
1267
- * @see JetstreamModuleOptions.metrics
1268
- */
1269
- metrics?: MetricsOption;
1270
1264
  } & ({
1271
1265
  useFactory(...args: unknown[]): Promise<Omit<JetstreamModuleOptions, 'name'>> | Omit<JetstreamModuleOptions, 'name'>;
1272
1266
  inject?: FactoryProvider['inject'];
package/dist/index.js CHANGED
@@ -446,6 +446,8 @@ var resolveCaptureBody = (option) => {
446
446
  };
447
447
  };
448
448
  var resolveOtelOptions = (options = {}) => {
449
+ if (options === true) options = {};
450
+ if (options === false) options = { enabled: false };
449
451
  return {
450
452
  enabled: options.enabled ?? true,
451
453
  traces: expandTracesOption(options.traces),
@@ -527,7 +529,7 @@ var extractContext = (ctx, carrier, getter) => propagation.extract(ctx, carrier,
527
529
 
528
530
  // src/otel/tracer.ts
529
531
  import { trace } from "@opentelemetry/api";
530
- var PACKAGE_VERSION = true ? "2.11.0" : "0.0.0";
532
+ var PACKAGE_VERSION = true ? "2.11.1" : "0.0.0";
531
533
  var getTracer = () => trace.getTracer(TRACER_NAME, PACKAGE_VERSION);
532
534
 
533
535
  // src/otel/carrier.ts
@@ -2708,6 +2710,7 @@ var JetstreamMetricsService = class {
2708
2710
  activeServers = /* @__PURE__ */ new Set();
2709
2711
  async onApplicationBootstrap() {
2710
2712
  if (this.metrics !== null) return;
2713
+ if (!this.options.metrics || !this.config || !this.promClient) return;
2711
2714
  if (!this.config.register) {
2712
2715
  throw new Error(
2713
2716
  "JetstreamMetricsService requires a prom-client Registry \u2014 none was resolved by JetstreamMetricsModule."
@@ -2733,7 +2736,7 @@ var JetstreamMetricsService = class {
2733
2736
  }
2734
2737
  /** @internal Visible for tests. `0` disables polling. */
2735
2738
  getEffectivePollInterval() {
2736
- return this.config.pollInterval ?? DEFAULT_POLL_INTERVAL_MS;
2739
+ return this.config?.pollInterval ?? DEFAULT_POLL_INTERVAL_MS;
2737
2740
  }
2738
2741
  /**
2739
2742
  * NATS connects during early bootstrap, before this service subscribes to
@@ -2899,28 +2902,29 @@ var normalizeMetricsConfig = (option, promClient) => {
2899
2902
  };
2900
2903
  };
2901
2904
  var JetstreamMetricsModule = class {
2902
- static forFeature(metricsOption) {
2903
- if (!metricsOption) {
2904
- return { module: JetstreamMetricsModule, providers: [], exports: [] };
2905
- }
2905
+ static forFeature() {
2906
2906
  const promClientProvider = {
2907
2907
  provide: JETSTREAM_METRICS_PROM_CLIENT,
2908
- useFactory: async () => {
2908
+ inject: [JETSTREAM_OPTIONS],
2909
+ useFactory: async (opts) => {
2910
+ if (!opts.metrics) return null;
2909
2911
  const mod = await resolvePromClient();
2910
2912
  return { Counter: mod.Counter, Histogram: mod.Histogram, Gauge: mod.Gauge };
2911
2913
  }
2912
2914
  };
2913
2915
  const configProvider = {
2914
2916
  provide: JETSTREAM_METRICS_CONFIG,
2915
- useFactory: async () => {
2917
+ inject: [JETSTREAM_OPTIONS],
2918
+ useFactory: async (opts) => {
2919
+ if (!opts.metrics) return null;
2916
2920
  const mod = await resolvePromClient();
2917
- return normalizeMetricsConfig(metricsOption, mod);
2921
+ return normalizeMetricsConfig(opts.metrics, mod);
2918
2922
  }
2919
2923
  };
2920
2924
  const registryProvider = {
2921
2925
  provide: JETSTREAM_METRICS_REGISTRY,
2922
2926
  inject: [JETSTREAM_METRICS_CONFIG],
2923
- useFactory: (cfg) => cfg.register
2927
+ useFactory: (cfg) => cfg?.register ?? null
2924
2928
  };
2925
2929
  const serviceProvider = {
2926
2930
  provide: JetstreamMetricsService,
@@ -5286,7 +5290,7 @@ var JetstreamModule = class {
5286
5290
  return {
5287
5291
  module: JetstreamModule,
5288
5292
  global: true,
5289
- imports: options.metrics ? [JetstreamMetricsModule.forFeature(options.metrics)] : [],
5293
+ imports: [JetstreamMetricsModule.forFeature()],
5290
5294
  providers,
5291
5295
  exports: [
5292
5296
  JETSTREAM_CONNECTION,
@@ -5312,11 +5316,10 @@ var JetstreamModule = class {
5312
5316
  static forRootAsync(asyncOptions) {
5313
5317
  const asyncProviders = this.createAsyncOptionsProvider(asyncOptions);
5314
5318
  const coreProviders = this.createCoreDependentProviders();
5315
- const metricsImports = asyncOptions.metrics ? [JetstreamMetricsModule.forFeature(asyncOptions.metrics)] : [];
5316
5319
  return {
5317
5320
  module: JetstreamModule,
5318
5321
  global: true,
5319
- imports: [...asyncOptions.imports ?? [], ...metricsImports],
5322
+ imports: [...asyncOptions.imports ?? [], JetstreamMetricsModule.forFeature()],
5320
5323
  providers: [...asyncProviders, ...coreProviders],
5321
5324
  exports: [
5322
5325
  JETSTREAM_CONNECTION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@horizon-republic/nestjs-jetstream",
3
- "version": "2.11.0",
3
+ "version": "2.11.1",
4
4
  "description": "A NestJS transport for NATS with JetStream events, broadcast fan-out, and Core/JetStream RPC.",
5
5
  "repository": {
6
6
  "type": "git",