@drarzter/kafka-client 0.7.1 → 0.7.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.
package/dist/core.mjs CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  getEnvelopeContext,
16
16
  runWithEnvelopeContext,
17
17
  topic
18
- } from "./chunk-AMEGMOZH.mjs";
18
+ } from "./chunk-XP7LLRGQ.mjs";
19
19
  import "./chunk-EQQGB2QZ.mjs";
20
20
  export {
21
21
  HEADER_CORRELATION_ID,
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { KafkaClient, KafkaProcessingError, KafkaRetryExhaustedError, KafkaValidationError } from './core.mjs';
2
- import { T as TopicMapConstraint, C as ClientId, G as GroupId, K as KafkaInstrumentation, a as KafkaClientOptions, S as SchemaLike, b as ConsumerOptions, c as TopicDescriptor, I as IKafkaClient, d as KafkaHealthResult } from './types-BEIGjmV6.mjs';
3
- export { B as BatchMessageItem, e as BatchMeta, f as BeforeConsumeResult, g as CircuitBreakerOptions, h as ConsumerHandle, i as ConsumerInterceptor, D as DeduplicationOptions, j as DlqReason, k as DlqReplayOptions, E as EnvelopeHeaderOptions, l as EventEnvelope, H as HEADER_CORRELATION_ID, m as HEADER_EVENT_ID, n as HEADER_LAMPORT_CLOCK, o as HEADER_SCHEMA_VERSION, p as HEADER_TIMESTAMP, q as HEADER_TRACEPARENT, r as InferSchema, s as KafkaLogger, t as KafkaMetrics, M as MessageHeaders, u as MessageLostContext, R as RetryOptions, v as SchemaParseContext, w as SendOptions, x as SubscribeRetryOptions, y as TTopicMessageMap, z as TopicsFrom, A as TransactionContext, F as TtlExpiredContext, J as buildEnvelopeHeaders, L as decodeHeaders, N as extractEnvelope, O as getEnvelopeContext, P as runWithEnvelopeContext, Q as topic } from './types-BEIGjmV6.mjs';
2
+ import { T as TopicMapConstraint, C as ClientId, G as GroupId, K as KafkaInstrumentation, a as KafkaClientOptions, S as SchemaLike, b as ConsumerOptions, c as TopicDescriptor, I as IKafkaClient, d as KafkaHealthResult } from './types-4qWrf2aJ.mjs';
3
+ export { B as BatchMessageItem, e as BatchMeta, f as BatchSendOptions, g as BeforeConsumeResult, h as CircuitBreakerOptions, i as CompressionType, j as ConsumerGroupSummary, k as ConsumerHandle, l as ConsumerInterceptor, D as DeduplicationOptions, m as DlqReason, n as DlqReplayOptions, E as EnvelopeHeaderOptions, o as EventEnvelope, H as HEADER_CORRELATION_ID, p as HEADER_EVENT_ID, q as HEADER_LAMPORT_CLOCK, r as HEADER_SCHEMA_VERSION, s as HEADER_TIMESTAMP, t as HEADER_TRACEPARENT, u as InferSchema, v as KafkaLogger, w as KafkaMetrics, M as MessageHeaders, x as MessageLostContext, R as RetryOptions, y as SchemaParseContext, z as SendOptions, A as SubscribeRetryOptions, F as TTopicMessageMap, J as TopicDescription, L as TopicPartitionInfo, N as TopicsFrom, O as TransactionContext, P as TtlExpiredContext, Q as buildEnvelopeHeaders, U as decodeHeaders, V as extractEnvelope, W as getEnvelopeContext, X as runWithEnvelopeContext, Y as topic } from './types-4qWrf2aJ.mjs';
4
4
  import { DynamicModule, OnModuleInit } from '@nestjs/common';
5
5
  import { DiscoveryService, ModuleRef } from '@nestjs/core';
6
6
 
@@ -55,20 +55,47 @@ declare const KAFKA_CLIENT = "KAFKA_CLIENT";
55
55
  /** Returns the DI token for a named (or default) Kafka client instance. */
56
56
  declare const getKafkaClientToken: (name?: string) => string;
57
57
 
58
+ /** Reflect metadata key used to store `@SubscribeTo` entries on a class constructor. */
58
59
  declare const KAFKA_SUBSCRIBER_METADATA = "KAFKA_SUBSCRIBER_METADATA";
60
+ /** Internal shape stored per `@SubscribeTo()` decoration on a class. */
59
61
  interface KafkaSubscriberMetadata {
62
+ /** Resolved topic name strings (descriptors are unwrapped to their `__topic` string). */
60
63
  topics: string[];
64
+ /** Per-topic schema validators extracted from `TopicDescriptor` objects (if any). */
61
65
  schemas?: Map<string, SchemaLike>;
66
+ /** Additional consumer options forwarded to `startConsumer` / `startBatchConsumer`. */
62
67
  options?: ConsumerOptions;
68
+ /** Named client identifier — resolves to `KAFKA_CLIENT_<clientName>` in the DI container. */
63
69
  clientName?: string;
70
+ /** When `true`, routes to `startBatchConsumer` instead of `startConsumer`. */
64
71
  batch?: boolean;
72
+ /** Name of the decorated method on the provider class. */
65
73
  methodName?: string | symbol;
66
74
  }
67
75
  /** Inject a `KafkaClient` instance. Pass a name to target a specific named client. */
68
76
  declare const InjectKafkaClient: (name?: string) => ParameterDecorator;
69
77
  /**
70
- * Decorator that auto-subscribes a method to Kafka topics on module init.
71
- * The decorated method receives `(message, topic)` for each consumed message.
78
+ * Method decorator that auto-subscribes the decorated method to one or more Kafka topics
79
+ * when the NestJS module initialises.
80
+ *
81
+ * The decorated method receives a fully-decoded `EventEnvelope` for each message
82
+ * (or an array of envelopes + `BatchMeta` when `batch: true`).
83
+ *
84
+ * @param topics One or more topic names or `TopicDescriptor` objects. Schemas embedded in
85
+ * descriptors are automatically extracted and forwarded to the consumer.
86
+ * @param options Consumer and routing options:
87
+ * - All `ConsumerOptions` fields (`groupId`, `retry`, `dlq`, `fromBeginning`, …)
88
+ * - `clientName` — target a named `KafkaClient` (resolves `KAFKA_CLIENT_<name>` from the DI container)
89
+ * - `batch` — use `startBatchConsumer` instead of `startConsumer`
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * @SubscribeTo('orders.created', { groupId: 'orders-svc', retry: { maxRetries: 3 } })
94
+ * async handleOrder(envelope: EventEnvelope<Order>) { ... }
95
+ *
96
+ * @SubscribeTo(OrdersTopic, { batch: true })
97
+ * async handleBatch(envelopes: EventEnvelope<Order>[], meta: BatchMeta) { ... }
98
+ * ```
72
99
  */
73
100
  declare const SubscribeTo: (topics: string | string[] | TopicDescriptor | TopicDescriptor[] | (string | TopicDescriptor)[], options?: ConsumerOptions & {
74
101
  clientName?: string;
@@ -81,6 +108,12 @@ declare class KafkaExplorer implements OnModuleInit {
81
108
  private readonly moduleRef;
82
109
  private readonly logger;
83
110
  constructor(discoveryService: DiscoveryService, moduleRef: ModuleRef);
111
+ /**
112
+ * Scan all NestJS providers for `@SubscribeTo()` metadata and wire each decorated
113
+ * method to its Kafka client via `startConsumer` or `startBatchConsumer`.
114
+ *
115
+ * Called automatically by the NestJS lifecycle — do not invoke manually.
116
+ */
84
117
  onModuleInit(): Promise<void>;
85
118
  }
86
119
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { KafkaClient, KafkaProcessingError, KafkaRetryExhaustedError, KafkaValidationError } from './core.js';
2
- import { T as TopicMapConstraint, C as ClientId, G as GroupId, K as KafkaInstrumentation, a as KafkaClientOptions, S as SchemaLike, b as ConsumerOptions, c as TopicDescriptor, I as IKafkaClient, d as KafkaHealthResult } from './types-BEIGjmV6.js';
3
- export { B as BatchMessageItem, e as BatchMeta, f as BeforeConsumeResult, g as CircuitBreakerOptions, h as ConsumerHandle, i as ConsumerInterceptor, D as DeduplicationOptions, j as DlqReason, k as DlqReplayOptions, E as EnvelopeHeaderOptions, l as EventEnvelope, H as HEADER_CORRELATION_ID, m as HEADER_EVENT_ID, n as HEADER_LAMPORT_CLOCK, o as HEADER_SCHEMA_VERSION, p as HEADER_TIMESTAMP, q as HEADER_TRACEPARENT, r as InferSchema, s as KafkaLogger, t as KafkaMetrics, M as MessageHeaders, u as MessageLostContext, R as RetryOptions, v as SchemaParseContext, w as SendOptions, x as SubscribeRetryOptions, y as TTopicMessageMap, z as TopicsFrom, A as TransactionContext, F as TtlExpiredContext, J as buildEnvelopeHeaders, L as decodeHeaders, N as extractEnvelope, O as getEnvelopeContext, P as runWithEnvelopeContext, Q as topic } from './types-BEIGjmV6.js';
2
+ import { T as TopicMapConstraint, C as ClientId, G as GroupId, K as KafkaInstrumentation, a as KafkaClientOptions, S as SchemaLike, b as ConsumerOptions, c as TopicDescriptor, I as IKafkaClient, d as KafkaHealthResult } from './types-4qWrf2aJ.js';
3
+ export { B as BatchMessageItem, e as BatchMeta, f as BatchSendOptions, g as BeforeConsumeResult, h as CircuitBreakerOptions, i as CompressionType, j as ConsumerGroupSummary, k as ConsumerHandle, l as ConsumerInterceptor, D as DeduplicationOptions, m as DlqReason, n as DlqReplayOptions, E as EnvelopeHeaderOptions, o as EventEnvelope, H as HEADER_CORRELATION_ID, p as HEADER_EVENT_ID, q as HEADER_LAMPORT_CLOCK, r as HEADER_SCHEMA_VERSION, s as HEADER_TIMESTAMP, t as HEADER_TRACEPARENT, u as InferSchema, v as KafkaLogger, w as KafkaMetrics, M as MessageHeaders, x as MessageLostContext, R as RetryOptions, y as SchemaParseContext, z as SendOptions, A as SubscribeRetryOptions, F as TTopicMessageMap, J as TopicDescription, L as TopicPartitionInfo, N as TopicsFrom, O as TransactionContext, P as TtlExpiredContext, Q as buildEnvelopeHeaders, U as decodeHeaders, V as extractEnvelope, W as getEnvelopeContext, X as runWithEnvelopeContext, Y as topic } from './types-4qWrf2aJ.js';
4
4
  import { DynamicModule, OnModuleInit } from '@nestjs/common';
5
5
  import { DiscoveryService, ModuleRef } from '@nestjs/core';
6
6
 
@@ -55,20 +55,47 @@ declare const KAFKA_CLIENT = "KAFKA_CLIENT";
55
55
  /** Returns the DI token for a named (or default) Kafka client instance. */
56
56
  declare const getKafkaClientToken: (name?: string) => string;
57
57
 
58
+ /** Reflect metadata key used to store `@SubscribeTo` entries on a class constructor. */
58
59
  declare const KAFKA_SUBSCRIBER_METADATA = "KAFKA_SUBSCRIBER_METADATA";
60
+ /** Internal shape stored per `@SubscribeTo()` decoration on a class. */
59
61
  interface KafkaSubscriberMetadata {
62
+ /** Resolved topic name strings (descriptors are unwrapped to their `__topic` string). */
60
63
  topics: string[];
64
+ /** Per-topic schema validators extracted from `TopicDescriptor` objects (if any). */
61
65
  schemas?: Map<string, SchemaLike>;
66
+ /** Additional consumer options forwarded to `startConsumer` / `startBatchConsumer`. */
62
67
  options?: ConsumerOptions;
68
+ /** Named client identifier — resolves to `KAFKA_CLIENT_<clientName>` in the DI container. */
63
69
  clientName?: string;
70
+ /** When `true`, routes to `startBatchConsumer` instead of `startConsumer`. */
64
71
  batch?: boolean;
72
+ /** Name of the decorated method on the provider class. */
65
73
  methodName?: string | symbol;
66
74
  }
67
75
  /** Inject a `KafkaClient` instance. Pass a name to target a specific named client. */
68
76
  declare const InjectKafkaClient: (name?: string) => ParameterDecorator;
69
77
  /**
70
- * Decorator that auto-subscribes a method to Kafka topics on module init.
71
- * The decorated method receives `(message, topic)` for each consumed message.
78
+ * Method decorator that auto-subscribes the decorated method to one or more Kafka topics
79
+ * when the NestJS module initialises.
80
+ *
81
+ * The decorated method receives a fully-decoded `EventEnvelope` for each message
82
+ * (or an array of envelopes + `BatchMeta` when `batch: true`).
83
+ *
84
+ * @param topics One or more topic names or `TopicDescriptor` objects. Schemas embedded in
85
+ * descriptors are automatically extracted and forwarded to the consumer.
86
+ * @param options Consumer and routing options:
87
+ * - All `ConsumerOptions` fields (`groupId`, `retry`, `dlq`, `fromBeginning`, …)
88
+ * - `clientName` — target a named `KafkaClient` (resolves `KAFKA_CLIENT_<name>` from the DI container)
89
+ * - `batch` — use `startBatchConsumer` instead of `startConsumer`
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * @SubscribeTo('orders.created', { groupId: 'orders-svc', retry: { maxRetries: 3 } })
94
+ * async handleOrder(envelope: EventEnvelope<Order>) { ... }
95
+ *
96
+ * @SubscribeTo(OrdersTopic, { batch: true })
97
+ * async handleBatch(envelopes: EventEnvelope<Order>[], meta: BatchMeta) { ... }
98
+ * ```
72
99
  */
73
100
  declare const SubscribeTo: (topics: string | string[] | TopicDescriptor | TopicDescriptor[] | (string | TopicDescriptor)[], options?: ConsumerOptions & {
74
101
  clientName?: string;
@@ -81,6 +108,12 @@ declare class KafkaExplorer implements OnModuleInit {
81
108
  private readonly moduleRef;
82
109
  private readonly logger;
83
110
  constructor(discoveryService: DiscoveryService, moduleRef: ModuleRef);
111
+ /**
112
+ * Scan all NestJS providers for `@SubscribeTo()` metadata and wire each decorated
113
+ * method to its Kafka client via `startConsumer` or `startBatchConsumer`.
114
+ *
115
+ * Called automatically by the NestJS lifecycle — do not invoke manually.
116
+ */
84
117
  onModuleInit(): Promise<void>;
85
118
  }
86
119