@drarzter/kafka-client 0.9.3 → 0.10.0
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/README.md +625 -8
- package/dist/chunk-CMO7SMVK.mjs +4814 -0
- package/dist/chunk-CMO7SMVK.mjs.map +1 -0
- package/dist/cli/dlq.d.ts +119 -0
- package/dist/cli/dlq.d.ts.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/{chunk-TPIP5VV7.mjs → cli/index.js} +965 -265
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +355 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/client/config/from-env.d.ts +188 -0
- package/dist/client/config/from-env.d.ts.map +1 -0
- package/dist/client/config/index.d.ts +2 -0
- package/dist/client/config/index.d.ts.map +1 -0
- package/dist/client/errors.d.ts +67 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/kafka.client/admin/ops.d.ts +114 -0
- package/dist/client/kafka.client/admin/ops.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/features/delayed.d.ts +24 -0
- package/dist/client/kafka.client/consumer/features/delayed.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/features/dlq-replay.d.ts +52 -0
- package/dist/client/kafka.client/consumer/features/dlq-replay.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/features/routed.d.ts +4 -0
- package/dist/client/kafka.client/consumer/features/routed.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/features/snapshot.d.ts +10 -0
- package/dist/client/kafka.client/consumer/features/snapshot.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/features/window.d.ts +5 -0
- package/dist/client/kafka.client/consumer/features/window.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/handler.d.ts +149 -0
- package/dist/client/kafka.client/consumer/handler.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/ops.d.ts +51 -0
- package/dist/client/kafka.client/consumer/ops.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/pipeline.d.ts +167 -0
- package/dist/client/kafka.client/consumer/pipeline.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/queue.d.ts +37 -0
- package/dist/client/kafka.client/consumer/queue.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/retry-topic.d.ts +65 -0
- package/dist/client/kafka.client/consumer/retry-topic.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/setup.d.ts +63 -0
- package/dist/client/kafka.client/consumer/setup.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/start.d.ts +7 -0
- package/dist/client/kafka.client/consumer/start.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/stop.d.ts +19 -0
- package/dist/client/kafka.client/consumer/stop.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/subscribe-retry.d.ts +4 -0
- package/dist/client/kafka.client/consumer/subscribe-retry.d.ts.map +1 -0
- package/dist/client/kafka.client/context.d.ts +72 -0
- package/dist/client/kafka.client/context.d.ts.map +1 -0
- package/dist/client/kafka.client/index.d.ts +155 -0
- package/dist/client/kafka.client/index.d.ts.map +1 -0
- package/dist/client/kafka.client/infra/circuit-breaker.manager.d.ts +61 -0
- package/dist/client/kafka.client/infra/circuit-breaker.manager.d.ts.map +1 -0
- package/dist/client/kafka.client/infra/dedup.store.d.ts +28 -0
- package/dist/client/kafka.client/infra/dedup.store.d.ts.map +1 -0
- package/dist/client/kafka.client/infra/inflight.tracker.d.ts +22 -0
- package/dist/client/kafka.client/infra/inflight.tracker.d.ts.map +1 -0
- package/dist/client/kafka.client/infra/metrics.manager.d.ts +67 -0
- package/dist/client/kafka.client/infra/metrics.manager.d.ts.map +1 -0
- package/dist/client/kafka.client/producer/lifecycle.d.ts +41 -0
- package/dist/client/kafka.client/producer/lifecycle.d.ts.map +1 -0
- package/dist/client/kafka.client/producer/ops.d.ts +70 -0
- package/dist/client/kafka.client/producer/ops.d.ts.map +1 -0
- package/dist/client/kafka.client/producer/send.d.ts +21 -0
- package/dist/client/kafka.client/producer/send.d.ts.map +1 -0
- package/dist/client/kafka.client/validate-options.d.ts +11 -0
- package/dist/client/kafka.client/validate-options.d.ts.map +1 -0
- package/dist/client/message/envelope.d.ts +105 -0
- package/dist/client/message/envelope.d.ts.map +1 -0
- package/dist/client/message/schema-registry.d.ts +105 -0
- package/dist/client/message/schema-registry.d.ts.map +1 -0
- package/dist/client/message/topic.d.ts +138 -0
- package/dist/client/message/topic.d.ts.map +1 -0
- package/dist/client/message/versioned-schema.d.ts +53 -0
- package/dist/client/message/versioned-schema.d.ts.map +1 -0
- package/dist/client/outbox/index.d.ts +4 -0
- package/dist/client/outbox/index.d.ts.map +1 -0
- package/dist/client/outbox/outbox.relay.d.ts +90 -0
- package/dist/client/outbox/outbox.relay.d.ts.map +1 -0
- package/dist/client/outbox/outbox.store.d.ts +42 -0
- package/dist/client/outbox/outbox.store.d.ts.map +1 -0
- package/dist/client/outbox/outbox.types.d.ts +144 -0
- package/dist/client/outbox/outbox.types.d.ts.map +1 -0
- package/dist/client/security/acl.d.ts +108 -0
- package/dist/client/security/acl.d.ts.map +1 -0
- package/dist/client/security/index.d.ts +5 -0
- package/dist/client/security/index.d.ts.map +1 -0
- package/dist/client/security/providers.d.ts +88 -0
- package/dist/client/security/providers.d.ts.map +1 -0
- package/dist/client/security/resolve-security.d.ts +19 -0
- package/dist/client/security/resolve-security.d.ts.map +1 -0
- package/dist/client/security/security.types.d.ts +76 -0
- package/dist/client/security/security.types.d.ts.map +1 -0
- package/dist/client/transport/confluent.transport.d.ts +32 -0
- package/dist/client/transport/confluent.transport.d.ts.map +1 -0
- package/dist/client/transport/transport.interface.d.ts +216 -0
- package/dist/client/transport/transport.interface.d.ts.map +1 -0
- package/dist/client/types/admin.interface.d.ts +174 -0
- package/dist/client/types/admin.interface.d.ts.map +1 -0
- package/dist/client/types/admin.types.d.ts +140 -0
- package/dist/client/types/admin.types.d.ts.map +1 -0
- package/dist/client/types/client.d.ts +21 -0
- package/dist/client/types/client.d.ts.map +1 -0
- package/dist/client/types/common.d.ts +84 -0
- package/dist/client/types/common.d.ts.map +1 -0
- package/dist/client/types/config.types.d.ts +150 -0
- package/dist/client/types/config.types.d.ts.map +1 -0
- package/dist/client/types/consumer.interface.d.ts +115 -0
- package/dist/client/types/consumer.interface.d.ts.map +1 -0
- package/dist/{consumer.types-fFCag3VJ.d.mts → client/types/consumer.types.d.ts} +62 -383
- package/dist/client/types/consumer.types.d.ts.map +1 -0
- package/dist/client/types/dedup.types.d.ts +50 -0
- package/dist/client/types/dedup.types.d.ts.map +1 -0
- package/dist/client/types/lifecycle.interface.d.ts +72 -0
- package/dist/client/types/lifecycle.interface.d.ts.map +1 -0
- package/dist/client/types/producer.interface.d.ts +52 -0
- package/dist/client/types/producer.interface.d.ts.map +1 -0
- package/dist/client/types/producer.types.d.ts +90 -0
- package/dist/client/types/producer.types.d.ts.map +1 -0
- package/dist/client/types.d.ts +8 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/core.d.ts +10 -314
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +1326 -74
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +39 -3
- package/dist/index.d.ts +7 -128
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1343 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -3
- package/dist/index.mjs.map +1 -1
- package/dist/nest/kafka.constants.d.ts +5 -0
- package/dist/nest/kafka.constants.d.ts.map +1 -0
- package/dist/nest/kafka.decorator.d.ts +49 -0
- package/dist/nest/kafka.decorator.d.ts.map +1 -0
- package/dist/nest/kafka.explorer.d.ts +17 -0
- package/dist/nest/kafka.explorer.d.ts.map +1 -0
- package/dist/nest/kafka.health.d.ts +7 -0
- package/dist/nest/kafka.health.d.ts.map +1 -0
- package/dist/nest/kafka.module.d.ts +61 -0
- package/dist/nest/kafka.module.d.ts.map +1 -0
- package/dist/otel.d.ts +83 -5
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +100 -6
- package/dist/otel.js.map +1 -1
- package/dist/otel.mjs +98 -5
- package/dist/otel.mjs.map +1 -1
- package/dist/testing/client.mock.d.ts +47 -0
- package/dist/testing/client.mock.d.ts.map +1 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/test.container.d.ts +63 -0
- package/dist/testing/test.container.d.ts.map +1 -0
- package/dist/{testing.d.mts → testing/transport.fake.d.ts} +7 -111
- package/dist/testing/transport.fake.d.ts.map +1 -0
- package/dist/testing.d.ts +2 -318
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +28 -2
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +28 -2
- package/dist/testing.mjs.map +1 -1
- package/package.json +22 -9
- package/dist/chunk-TPIP5VV7.mjs.map +0 -1
- package/dist/client-CBBUDDtu.d.ts +0 -751
- package/dist/client-D-SxYV2b.d.mts +0 -751
- package/dist/consumer.types-fFCag3VJ.d.ts +0 -958
- package/dist/core.d.mts +0 -314
- package/dist/index.d.mts +0 -128
- package/dist/otel.d.mts +0 -27
package/dist/core.d.mts
DELETED
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { q as KafkaLogger, K as KafkaInstrumentation, s as MessageLostContext, F as TtlExpiredContext, T as TopicMapConstraint, C as ClientId, G as GroupId, b as TopicDescriptor, v as SendOptions, M as MessageHeaders, B as BatchMessageItem, d as BatchSendOptions, z as TransactionContext, k as EventEnvelope, a as ConsumerOptions, h as ConsumerHandle, c as BatchMeta, J as WindowMeta, W as WindowConsumerOptions, t as RoutingOptions, A as TransactionalHandlerContext, r as KafkaMetrics } from './consumer.types-fFCag3VJ.mjs';
|
|
2
|
-
export { e as BeforeConsumeResult, f as CircuitBreakerOptions, g as CompressionType, i as ConsumerInterceptor, D as DeduplicationOptions, j as DlqReason, E as EnvelopeHeaderOptions, H as HEADER_CORRELATION_ID, l as HEADER_EVENT_ID, m as HEADER_LAMPORT_CLOCK, n as HEADER_SCHEMA_VERSION, o as HEADER_TIMESTAMP, p as HEADER_TRACEPARENT, I as InferSchema, R as RetryOptions, S as SchemaLike, u as SchemaParseContext, w as SubscribeRetryOptions, x as TTopicMessageMap, y as TopicsFrom, L as buildEnvelopeHeaders, N as decodeHeaders, O as extractEnvelope, P as getEnvelopeContext, Q as runWithEnvelopeContext, U as topic } from './consumer.types-fFCag3VJ.mjs';
|
|
3
|
-
import { K as KafkaTransport, I as IKafkaClient, D as DlqReplayOptions, R as ReadSnapshotOptions, t as CheckpointResult, z as RestoreCheckpointOptions, s as CheckpointRestoreResult, r as KafkaHealthResult, u as ConsumerGroupSummary, T as TopicDescription } from './client-D-SxYV2b.mjs';
|
|
4
|
-
export { C as CheckpointEntry, v as IKafkaAdmin, w as IKafkaConsumer, x as IKafkaLifecycle, y as IKafkaProducer, A as TopicPartitionInfo } from './client-D-SxYV2b.mjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Options for `KafkaClient` constructor.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* const kafka = new KafkaClient(kafkaConfig, 'my-service', {
|
|
12
|
-
* transactionalId: `my-service-tx-${replicaIndex}`,
|
|
13
|
-
* lagThrottle: { maxLag: 10_000, pollIntervalMs: 3_000 },
|
|
14
|
-
* clockRecovery: { topics: ['orders.created'] },
|
|
15
|
-
* onMessageLost: (ctx) => alerting.fire('kafka.message-lost', ctx),
|
|
16
|
-
* instrumentation: [otelInstrumentation()],
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
interface KafkaClientOptions {
|
|
21
|
-
/** Auto-create topics via admin before the first `sendMessage`, `sendBatch`, or `transaction` for each topic. Useful for development — not recommended in production. */
|
|
22
|
-
autoCreateTopics?: boolean;
|
|
23
|
-
/** When `true`, string topic keys are validated against any schema previously registered via a TopicDescriptor. Default: `true`. */
|
|
24
|
-
strictSchemas?: boolean;
|
|
25
|
-
/** Custom logger. Defaults to console with `[KafkaClient:<clientId>]` prefix. */
|
|
26
|
-
logger?: KafkaLogger;
|
|
27
|
-
/** Number of partitions for auto-created topics. Default: `1`. */
|
|
28
|
-
numPartitions?: number;
|
|
29
|
-
/** Client-wide instrumentation hooks (e.g. OTel). Applied to both send and consume paths. */
|
|
30
|
-
instrumentation?: KafkaInstrumentation[];
|
|
31
|
-
/**
|
|
32
|
-
* Override the transactional producer ID used by `transaction()`.
|
|
33
|
-
* Defaults to `${clientId}-tx`.
|
|
34
|
-
*
|
|
35
|
-
* The transactional ID must be **unique per producer instance** across the
|
|
36
|
-
* entire Kafka cluster. Two `KafkaClient` instances with the same ID will
|
|
37
|
-
* cause Kafka to fence one of the producers — the fenced producer will fail
|
|
38
|
-
* on the next `transaction()` call. Set a distinct value per replica when
|
|
39
|
-
* running multiple instances of the same service.
|
|
40
|
-
*/
|
|
41
|
-
transactionalId?: string;
|
|
42
|
-
/**
|
|
43
|
-
* Called when a message is dropped without being sent to a DLQ.
|
|
44
|
-
* Fires when the handler throws after all retries, or schema validation fails — and `dlq` is not enabled.
|
|
45
|
-
* Use this to alert, log to external systems, or trigger fallback logic.
|
|
46
|
-
*/
|
|
47
|
-
onMessageLost?: (ctx: MessageLostContext) => void | Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* Called when a message is dropped due to TTL expiration (`messageTtlMs`).
|
|
50
|
-
* Fires instead of `onMessageLost` for expired messages when `dlq` is not enabled.
|
|
51
|
-
* When `dlq: true`, expired messages go to the DLQ and this callback is NOT called.
|
|
52
|
-
*
|
|
53
|
-
* **Client-wide fallback**: if `ConsumerOptions.onTtlExpired` is set on the consumer,
|
|
54
|
-
* it takes precedence over this client-level callback.
|
|
55
|
-
*/
|
|
56
|
-
onTtlExpired?: (ctx: TtlExpiredContext) => void | Promise<void>;
|
|
57
|
-
/**
|
|
58
|
-
* Called whenever a consumer group rebalance occurs.
|
|
59
|
-
* - `'assign'` — new partitions were granted to this instance.
|
|
60
|
-
* - `'revoke'` — partitions were taken away (e.g. another consumer joined).
|
|
61
|
-
*
|
|
62
|
-
* Applied to every consumer created by this client. If you need per-consumer
|
|
63
|
-
* rebalance handling, use separate `KafkaClient` instances.
|
|
64
|
-
*/
|
|
65
|
-
onRebalance?: (type: "assign" | "revoke", partitions: Array<{
|
|
66
|
-
topic: string;
|
|
67
|
-
partition: number;
|
|
68
|
-
}>) => void;
|
|
69
|
-
/**
|
|
70
|
-
* Recover the Lamport clock from the last message in the given topics on `connectProducer()`.
|
|
71
|
-
*
|
|
72
|
-
* On startup the producer creates a short-lived consumer, seeks each partition to its
|
|
73
|
-
* last message (`highWatermark − 1`), reads the `x-lamport-clock` header, then
|
|
74
|
-
* initialises `_lamportClock` to the maximum value found. This guarantees monotonic
|
|
75
|
-
* clock values across restarts without an external store.
|
|
76
|
-
*
|
|
77
|
-
* Topics that do not exist or are empty are silently skipped.
|
|
78
|
-
*/
|
|
79
|
-
clockRecovery?: {
|
|
80
|
-
/** Topic names to scan for the highest Lamport clock. */
|
|
81
|
-
topics: string[];
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Delay `sendMessage` / `sendBatch` / `sendTombstone` when the observed lag of a
|
|
85
|
-
* consumer group exceeds `maxLag`. Resumes immediately when lag drops below the threshold.
|
|
86
|
-
*
|
|
87
|
-
* Lag is polled via `getConsumerLag()` every `pollIntervalMs` in the background;
|
|
88
|
-
* no admin call is made on each individual send.
|
|
89
|
-
*
|
|
90
|
-
* When `maxWaitMs` is exceeded the send is unblocked with a warning — this is
|
|
91
|
-
* best-effort throttling, not hard back-pressure.
|
|
92
|
-
*
|
|
93
|
-
* Requires `connectProducer()` to have been called to start the polling loop.
|
|
94
|
-
*/
|
|
95
|
-
lagThrottle?: {
|
|
96
|
-
/** Consumer group whose lag is monitored. Defaults to the client's default group. */
|
|
97
|
-
groupId?: string;
|
|
98
|
-
/** Lag threshold (number of messages) above which sends are delayed. */
|
|
99
|
-
maxLag: number;
|
|
100
|
-
/** How often to poll `getConsumerLag()`. Default: `5000` ms. */
|
|
101
|
-
pollIntervalMs?: number;
|
|
102
|
-
/**
|
|
103
|
-
* Maximum time (ms) a send will wait while throttled before proceeding anyway.
|
|
104
|
-
* Default: `30_000` ms.
|
|
105
|
-
*/
|
|
106
|
-
maxWaitMs?: number;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Custom transport implementation.
|
|
110
|
-
*
|
|
111
|
-
* By default `KafkaClient` uses `ConfluentTransport` which wraps
|
|
112
|
-
* `@confluentinc/kafka-javascript` (librdkafka). Inject a different
|
|
113
|
-
* `KafkaTransport` to target an alternative broker library, or to supply
|
|
114
|
-
* a deterministic fake in unit tests without mocking the confluentinc module.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```ts
|
|
118
|
-
* // In tests — no jest.mock() needed
|
|
119
|
-
* const kafka = new KafkaClient('svc', 'grp', [], {
|
|
120
|
-
* transport: new FakeTransport(),
|
|
121
|
-
* });
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
transport?: KafkaTransport;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Type-safe Kafka client.
|
|
129
|
-
* Wraps @confluentinc/kafka-javascript (librdkafka) with JSON serialization,
|
|
130
|
-
* retries, DLQ, transactions, and interceptors.
|
|
131
|
-
*
|
|
132
|
-
* @typeParam T - Topic-to-message type mapping for compile-time safety.
|
|
133
|
-
*/
|
|
134
|
-
declare class KafkaClient<T extends TopicMapConstraint<T>> implements IKafkaClient<T> {
|
|
135
|
-
readonly clientId: ClientId;
|
|
136
|
-
private readonly ctx;
|
|
137
|
-
/**
|
|
138
|
-
* Create a new KafkaClient.
|
|
139
|
-
* @param clientId Unique client identifier (used in Kafka metadata and logs).
|
|
140
|
-
* @param groupId Default consumer group ID for this client.
|
|
141
|
-
* @param brokers Array of broker addresses, e.g. `['localhost:9092']`.
|
|
142
|
-
* @param options Optional client-wide configuration.
|
|
143
|
-
* @example
|
|
144
|
-
* ```ts
|
|
145
|
-
* const kafka = new KafkaClient('my-service', 'my-service-group', ['localhost:9092'], {
|
|
146
|
-
* lagThrottle: { maxLag: 10_000 },
|
|
147
|
-
* onMessageLost: (ctx) => logger.error('Message lost', ctx),
|
|
148
|
-
* });
|
|
149
|
-
* await kafka.connectProducer();
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
constructor(clientId: ClientId, groupId: GroupId, brokers: string[], options?: KafkaClientOptions);
|
|
153
|
-
/** @inheritDoc */
|
|
154
|
-
sendMessage<D extends TopicDescriptor<string & keyof T, T[string & keyof T]>>(descriptor: D, message: D["__type"], options?: SendOptions): Promise<void>;
|
|
155
|
-
sendMessage<K extends keyof T>(topic: K, message: T[K], options?: SendOptions): Promise<void>;
|
|
156
|
-
/** @inheritDoc */
|
|
157
|
-
sendTombstone(topic: string, key: string, headers?: MessageHeaders): Promise<void>;
|
|
158
|
-
/** @inheritDoc */
|
|
159
|
-
sendBatch<D extends TopicDescriptor<string & keyof T, T[string & keyof T]>>(descriptor: D, messages: Array<BatchMessageItem<D["__type"]>>, options?: BatchSendOptions): Promise<void>;
|
|
160
|
-
sendBatch<K extends keyof T>(topic: K, messages: Array<BatchMessageItem<T[K]>>, options?: BatchSendOptions): Promise<void>;
|
|
161
|
-
/** @inheritDoc */
|
|
162
|
-
transaction(fn: (ctx: TransactionContext<T>) => Promise<void>): Promise<void>;
|
|
163
|
-
/** @inheritDoc */
|
|
164
|
-
connectProducer(): Promise<void>;
|
|
165
|
-
/** @internal */
|
|
166
|
-
disconnectProducer(): Promise<void>;
|
|
167
|
-
/** @inheritDoc */
|
|
168
|
-
startConsumer<K extends Array<keyof T>>(topics: K, handleMessage: (envelope: EventEnvelope<T[K[number]]>) => Promise<void>, options?: ConsumerOptions<T>): Promise<ConsumerHandle>;
|
|
169
|
-
startConsumer<D extends TopicDescriptor<string & keyof T, T[string & keyof T]>>(topics: D[], handleMessage: (envelope: EventEnvelope<D["__type"]>) => Promise<void>, options?: ConsumerOptions<T>): Promise<ConsumerHandle>;
|
|
170
|
-
/** @inheritDoc */
|
|
171
|
-
startBatchConsumer<K extends Array<keyof T>>(topics: K, handleBatch: (envelopes: EventEnvelope<T[K[number]]>[], meta: BatchMeta) => Promise<void>, options?: ConsumerOptions<T>): Promise<ConsumerHandle>;
|
|
172
|
-
startBatchConsumer<D extends TopicDescriptor<string & keyof T, T[string & keyof T]>>(topics: D[], handleBatch: (envelopes: EventEnvelope<D["__type"]>[], meta: BatchMeta) => Promise<void>, options?: ConsumerOptions<T>): Promise<ConsumerHandle>;
|
|
173
|
-
/** @inheritDoc */
|
|
174
|
-
consume<K extends keyof T & string>(topic: K, options?: ConsumerOptions<T>): AsyncIterableIterator<EventEnvelope<T[K]>>;
|
|
175
|
-
/** @inheritDoc */
|
|
176
|
-
startWindowConsumer<K extends keyof T & string>(topic: K, handler: (envelopes: EventEnvelope<T[K]>[], meta: WindowMeta) => Promise<void>, options: WindowConsumerOptions<T>): Promise<ConsumerHandle>;
|
|
177
|
-
/** @inheritDoc */
|
|
178
|
-
startRoutedConsumer<K extends Array<keyof T>>(topics: K, routing: RoutingOptions<T[K[number]]>, options?: ConsumerOptions<T>): Promise<ConsumerHandle>;
|
|
179
|
-
/** @inheritDoc */
|
|
180
|
-
startTransactionalConsumer<K extends Array<keyof T>>(topics: K, handler: (envelope: EventEnvelope<T[K[number]]>, tx: TransactionalHandlerContext<T>) => Promise<void>, options?: ConsumerOptions<T>): Promise<ConsumerHandle>;
|
|
181
|
-
/** @inheritDoc */
|
|
182
|
-
stopConsumer(groupId?: string): Promise<void>;
|
|
183
|
-
/** @inheritDoc */
|
|
184
|
-
pauseConsumer(groupId: string | undefined, assignments: Array<{
|
|
185
|
-
topic: string;
|
|
186
|
-
partitions: number[];
|
|
187
|
-
}>): void;
|
|
188
|
-
/** @inheritDoc */
|
|
189
|
-
resumeConsumer(groupId: string | undefined, assignments: Array<{
|
|
190
|
-
topic: string;
|
|
191
|
-
partitions: number[];
|
|
192
|
-
}>): void;
|
|
193
|
-
/** @inheritDoc */
|
|
194
|
-
replayDlq(topic: string, options?: DlqReplayOptions): Promise<{
|
|
195
|
-
replayed: number;
|
|
196
|
-
skipped: number;
|
|
197
|
-
}>;
|
|
198
|
-
/** @inheritDoc */
|
|
199
|
-
readSnapshot<K extends keyof T & string>(topic: K, options?: ReadSnapshotOptions): Promise<Map<string, EventEnvelope<T[K]>>>;
|
|
200
|
-
/** @inheritDoc */
|
|
201
|
-
checkpointOffsets(groupId: string | undefined, checkpointTopic: string): Promise<CheckpointResult>;
|
|
202
|
-
/** @inheritDoc */
|
|
203
|
-
restoreFromCheckpoint(groupId: string | undefined, checkpointTopic: string, options?: RestoreCheckpointOptions): Promise<CheckpointRestoreResult>;
|
|
204
|
-
/** @inheritDoc */
|
|
205
|
-
resetOffsets(groupId: string | undefined, topic: string, position: "earliest" | "latest"): Promise<void>;
|
|
206
|
-
/** @inheritDoc */
|
|
207
|
-
seekToOffset(groupId: string | undefined, assignments: Array<{
|
|
208
|
-
topic: string;
|
|
209
|
-
partition: number;
|
|
210
|
-
offset: string;
|
|
211
|
-
}>): Promise<void>;
|
|
212
|
-
/** @inheritDoc */
|
|
213
|
-
seekToTimestamp(groupId: string | undefined, assignments: Array<{
|
|
214
|
-
topic: string;
|
|
215
|
-
partition: number;
|
|
216
|
-
timestamp: number;
|
|
217
|
-
}>): Promise<void>;
|
|
218
|
-
/** @inheritDoc */
|
|
219
|
-
getConsumerLag(groupId?: string): Promise<Array<{
|
|
220
|
-
topic: string;
|
|
221
|
-
partition: number;
|
|
222
|
-
lag: number;
|
|
223
|
-
}>>;
|
|
224
|
-
/** @inheritDoc */
|
|
225
|
-
checkStatus(): Promise<KafkaHealthResult>;
|
|
226
|
-
/** @inheritDoc */
|
|
227
|
-
listConsumerGroups(): Promise<ConsumerGroupSummary[]>;
|
|
228
|
-
/** @inheritDoc */
|
|
229
|
-
describeTopics(topics?: string[]): Promise<TopicDescription[]>;
|
|
230
|
-
/** @inheritDoc */
|
|
231
|
-
deleteRecords(topic: string, partitions: Array<{
|
|
232
|
-
partition: number;
|
|
233
|
-
offset: string;
|
|
234
|
-
}>): Promise<void>;
|
|
235
|
-
/** @inheritDoc */
|
|
236
|
-
getCircuitState(topic: string, partition: number, groupId?: string): {
|
|
237
|
-
status: "closed" | "open" | "half-open";
|
|
238
|
-
failures: number;
|
|
239
|
-
windowSize: number;
|
|
240
|
-
} | undefined;
|
|
241
|
-
/** @inheritDoc */
|
|
242
|
-
getMetrics(topic?: string): Readonly<KafkaMetrics>;
|
|
243
|
-
/** @inheritDoc */
|
|
244
|
-
resetMetrics(topic?: string): void;
|
|
245
|
-
getClientId(): ClientId;
|
|
246
|
-
/** @inheritDoc */
|
|
247
|
-
disconnect(drainTimeoutMs?: number): Promise<void>;
|
|
248
|
-
/** NestJS lifecycle hook — called automatically on module teardown. */
|
|
249
|
-
onModuleDestroy(): Promise<void>;
|
|
250
|
-
/** @inheritDoc */
|
|
251
|
-
enableGracefulShutdown(signals?: NodeJS.Signals[], drainTimeoutMs?: number): void;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Error thrown when a consumer message handler fails.
|
|
256
|
-
* @example
|
|
257
|
-
* ```ts
|
|
258
|
-
* await kafka.startConsumer(['orders'], async (envelope) => {
|
|
259
|
-
* try { await process(envelope); }
|
|
260
|
-
* catch (err) {
|
|
261
|
-
* if (err instanceof KafkaProcessingError) {
|
|
262
|
-
* console.error(err.topic, err.originalMessage);
|
|
263
|
-
* }
|
|
264
|
-
* }
|
|
265
|
-
* });
|
|
266
|
-
* ```
|
|
267
|
-
*/
|
|
268
|
-
declare class KafkaProcessingError extends Error {
|
|
269
|
-
readonly topic: string;
|
|
270
|
-
readonly originalMessage: unknown;
|
|
271
|
-
readonly cause?: Error;
|
|
272
|
-
constructor(message: string, topic: string, originalMessage: unknown, options?: {
|
|
273
|
-
cause?: Error;
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Error thrown when schema validation fails on send or consume.
|
|
278
|
-
* @example
|
|
279
|
-
* ```ts
|
|
280
|
-
* try { await kafka.sendMessage('orders.created', invalidPayload); }
|
|
281
|
-
* catch (err) {
|
|
282
|
-
* if (err instanceof KafkaValidationError) {
|
|
283
|
-
* console.error('Validation failed for topic:', err.topic);
|
|
284
|
-
* }
|
|
285
|
-
* }
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
declare class KafkaValidationError extends Error {
|
|
289
|
-
readonly topic: string;
|
|
290
|
-
readonly originalMessage: unknown;
|
|
291
|
-
readonly cause?: Error;
|
|
292
|
-
constructor(topic: string, originalMessage: unknown, options?: {
|
|
293
|
-
cause?: Error;
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Error thrown when all retry attempts are exhausted for a message.
|
|
298
|
-
* @example
|
|
299
|
-
* ```ts
|
|
300
|
-
* const kafka = new KafkaClient(config, groupId, { onMessageLost: (ctx) => {
|
|
301
|
-
* if (ctx.error instanceof KafkaRetryExhaustedError) {
|
|
302
|
-
* console.error(`Exhausted after ${ctx.error.attempts} attempts on ${ctx.error.topic}`);
|
|
303
|
-
* }
|
|
304
|
-
* }});
|
|
305
|
-
* ```
|
|
306
|
-
*/
|
|
307
|
-
declare class KafkaRetryExhaustedError extends KafkaProcessingError {
|
|
308
|
-
readonly attempts: number;
|
|
309
|
-
constructor(topic: string, originalMessage: unknown, attempts: number, options?: {
|
|
310
|
-
cause?: Error;
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
export { BatchMessageItem, BatchMeta, BatchSendOptions, CheckpointRestoreResult, CheckpointResult, ClientId, ConsumerGroupSummary, ConsumerHandle, ConsumerOptions, DlqReplayOptions, EventEnvelope, GroupId, IKafkaClient, KafkaClient, type KafkaClientOptions, KafkaHealthResult, KafkaInstrumentation, KafkaLogger, KafkaMetrics, KafkaProcessingError, KafkaRetryExhaustedError, KafkaValidationError, MessageHeaders, MessageLostContext, ReadSnapshotOptions, RestoreCheckpointOptions, RoutingOptions, SendOptions, TopicDescription, TopicDescriptor, TopicMapConstraint, TransactionContext, TransactionalHandlerContext, TtlExpiredContext, WindowConsumerOptions, WindowMeta };
|
package/dist/index.d.mts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { KafkaClientOptions } from './core.mjs';
|
|
2
|
-
export { KafkaClient, KafkaProcessingError, KafkaRetryExhaustedError, KafkaValidationError } from './core.mjs';
|
|
3
|
-
import { T as TopicMapConstraint, C as ClientId, G as GroupId, K as KafkaInstrumentation, S as SchemaLike, a as ConsumerOptions, b as TopicDescriptor } from './consumer.types-fFCag3VJ.mjs';
|
|
4
|
-
export { B as BatchMessageItem, c as BatchMeta, d as BatchSendOptions, e as BeforeConsumeResult, f as CircuitBreakerOptions, g as CompressionType, h as ConsumerHandle, i as ConsumerInterceptor, D as DeduplicationOptions, j as DlqReason, E as EnvelopeHeaderOptions, k as EventEnvelope, H as HEADER_CORRELATION_ID, l as HEADER_EVENT_ID, m as HEADER_LAMPORT_CLOCK, n as HEADER_SCHEMA_VERSION, o as HEADER_TIMESTAMP, p as HEADER_TRACEPARENT, I as InferSchema, q as KafkaLogger, r as KafkaMetrics, M as MessageHeaders, s as MessageLostContext, R as RetryOptions, t as RoutingOptions, u as SchemaParseContext, v as SendOptions, w as SubscribeRetryOptions, x as TTopicMessageMap, y as TopicsFrom, z as TransactionContext, A as TransactionalHandlerContext, F as TtlExpiredContext, W as WindowConsumerOptions, J as WindowMeta, L as buildEnvelopeHeaders, N as decodeHeaders, O as extractEnvelope, P as getEnvelopeContext, Q as runWithEnvelopeContext, U as topic } from './consumer.types-fFCag3VJ.mjs';
|
|
5
|
-
import { DynamicModule, OnModuleInit } from '@nestjs/common';
|
|
6
|
-
import { DiscoveryService, ModuleRef } from '@nestjs/core';
|
|
7
|
-
import { I as IKafkaClient, r as KafkaHealthResult } from './client-D-SxYV2b.mjs';
|
|
8
|
-
export { C as CheckpointEntry, s as CheckpointRestoreResult, t as CheckpointResult, u as ConsumerGroupSummary, D as DlqReplayOptions, v as IKafkaAdmin, w as IKafkaConsumer, x as IKafkaLifecycle, y as IKafkaProducer, R as ReadSnapshotOptions, z as RestoreCheckpointOptions, T as TopicDescription, A as TopicPartitionInfo } from './client-D-SxYV2b.mjs';
|
|
9
|
-
|
|
10
|
-
/** Shared configuration fields for both `register()` and `registerAsync()`. */
|
|
11
|
-
interface KafkaModuleBaseOptions {
|
|
12
|
-
/** Optional name for multi-client setups. Must match `@InjectKafkaClient(name)`. */
|
|
13
|
-
name?: string;
|
|
14
|
-
/** If true, makes KAFKA_CLIENT available globally without importing KafkaModule in every feature module. */
|
|
15
|
-
isGlobal?: boolean;
|
|
16
|
-
}
|
|
17
|
-
/** Synchronous configuration for `KafkaModule.register()`. */
|
|
18
|
-
interface KafkaModuleOptions extends KafkaModuleBaseOptions {
|
|
19
|
-
/** Unique Kafka client identifier. */
|
|
20
|
-
clientId: ClientId;
|
|
21
|
-
/** Consumer group identifier. */
|
|
22
|
-
groupId: GroupId;
|
|
23
|
-
/** List of Kafka broker addresses. */
|
|
24
|
-
brokers: string[];
|
|
25
|
-
/** Auto-create topics via admin on first use (send/consume). Useful for development. */
|
|
26
|
-
autoCreateTopics?: boolean;
|
|
27
|
-
/** When `true`, string topic keys are validated against any schema previously registered via a TopicDescriptor. Default: `true`. */
|
|
28
|
-
strictSchemas?: boolean;
|
|
29
|
-
/** Number of partitions for auto-created topics. Default: `1`. */
|
|
30
|
-
numPartitions?: number;
|
|
31
|
-
/** Client-wide instrumentation hooks (e.g. OTel). Applied to both send and consume paths. */
|
|
32
|
-
instrumentation?: KafkaInstrumentation[];
|
|
33
|
-
/** Called when a message is dropped without being sent to a DLQ. @see `KafkaClientOptions.onMessageLost` */
|
|
34
|
-
onMessageLost?: KafkaClientOptions["onMessageLost"];
|
|
35
|
-
/** Called whenever a consumer group rebalance occurs. @see `KafkaClientOptions.onRebalance` */
|
|
36
|
-
onRebalance?: KafkaClientOptions["onRebalance"];
|
|
37
|
-
}
|
|
38
|
-
/** Async configuration for `KafkaModule.registerAsync()` with dependency injection. */
|
|
39
|
-
interface KafkaModuleAsyncOptions extends KafkaModuleBaseOptions {
|
|
40
|
-
imports?: any[];
|
|
41
|
-
useFactory: (...args: any[]) => KafkaModuleOptions | Promise<KafkaModuleOptions>;
|
|
42
|
-
inject?: any[];
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* NestJS dynamic module for registering type-safe Kafka clients.
|
|
46
|
-
* Use `register()` for static config or `registerAsync()` for DI-based config.
|
|
47
|
-
*/
|
|
48
|
-
declare class KafkaModule {
|
|
49
|
-
/** Register a Kafka client with static options. */
|
|
50
|
-
static register<T extends TopicMapConstraint<T>>(options: KafkaModuleOptions): DynamicModule;
|
|
51
|
-
/** Register a Kafka client with async/factory-based options. */
|
|
52
|
-
static registerAsync<T extends TopicMapConstraint<T>>(asyncOptions: KafkaModuleAsyncOptions): DynamicModule;
|
|
53
|
-
private static buildClient;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Default DI token for the Kafka client. */
|
|
57
|
-
declare const KAFKA_CLIENT = "KAFKA_CLIENT";
|
|
58
|
-
/** Returns the DI token for a named (or default) Kafka client instance. */
|
|
59
|
-
declare const getKafkaClientToken: (name?: string) => string;
|
|
60
|
-
|
|
61
|
-
/** Reflect metadata key used to store `@SubscribeTo` entries on a class constructor. */
|
|
62
|
-
declare const KAFKA_SUBSCRIBER_METADATA = "KAFKA_SUBSCRIBER_METADATA";
|
|
63
|
-
/** Internal shape stored per `@SubscribeTo()` decoration on a class. */
|
|
64
|
-
interface KafkaSubscriberMetadata {
|
|
65
|
-
/** Resolved topic name strings (descriptors are unwrapped to their `__topic` string). */
|
|
66
|
-
topics: string[];
|
|
67
|
-
/** Per-topic schema validators extracted from `TopicDescriptor` objects (if any). */
|
|
68
|
-
schemas?: Map<string, SchemaLike>;
|
|
69
|
-
/** Additional consumer options forwarded to `startConsumer` / `startBatchConsumer`. */
|
|
70
|
-
options?: ConsumerOptions;
|
|
71
|
-
/** Named client identifier — resolves to `KAFKA_CLIENT_<clientName>` in the DI container. */
|
|
72
|
-
clientName?: string;
|
|
73
|
-
/** When `true`, routes to `startBatchConsumer` instead of `startConsumer`. */
|
|
74
|
-
batch?: boolean;
|
|
75
|
-
/** Name of the decorated method on the provider class. */
|
|
76
|
-
methodName?: string | symbol;
|
|
77
|
-
}
|
|
78
|
-
/** Inject a `KafkaClient` instance. Pass a name to target a specific named client. */
|
|
79
|
-
declare const InjectKafkaClient: (name?: string) => ParameterDecorator;
|
|
80
|
-
/**
|
|
81
|
-
* Method decorator that auto-subscribes the decorated method to one or more Kafka topics
|
|
82
|
-
* when the NestJS module initialises.
|
|
83
|
-
*
|
|
84
|
-
* The decorated method receives a fully-decoded `EventEnvelope` for each message
|
|
85
|
-
* (or an array of envelopes + `BatchMeta` when `batch: true`).
|
|
86
|
-
*
|
|
87
|
-
* @param topics One or more topic names or `TopicDescriptor` objects. Schemas embedded in
|
|
88
|
-
* descriptors are automatically extracted and forwarded to the consumer.
|
|
89
|
-
* @param options Consumer and routing options:
|
|
90
|
-
* - All `ConsumerOptions` fields (`groupId`, `retry`, `dlq`, `fromBeginning`, …)
|
|
91
|
-
* - `clientName` — target a named `KafkaClient` (resolves `KAFKA_CLIENT_<name>` from the DI container)
|
|
92
|
-
* - `batch` — use `startBatchConsumer` instead of `startConsumer`
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```ts
|
|
96
|
-
* @SubscribeTo('orders.created', { groupId: 'orders-svc', retry: { maxRetries: 3 } })
|
|
97
|
-
* async handleOrder(envelope: EventEnvelope<Order>) { ... }
|
|
98
|
-
*
|
|
99
|
-
* @SubscribeTo(OrdersTopic, { batch: true })
|
|
100
|
-
* async handleBatch(envelopes: EventEnvelope<Order>[], meta: BatchMeta) { ... }
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
declare const SubscribeTo: (topics: string | string[] | TopicDescriptor | TopicDescriptor[] | (string | TopicDescriptor)[], options?: ConsumerOptions & {
|
|
104
|
-
clientName?: string;
|
|
105
|
-
batch?: boolean;
|
|
106
|
-
}) => MethodDecorator;
|
|
107
|
-
|
|
108
|
-
/** Discovers `@SubscribeTo()` decorators and wires them to their Kafka clients on startup. */
|
|
109
|
-
declare class KafkaExplorer implements OnModuleInit {
|
|
110
|
-
private readonly discoveryService;
|
|
111
|
-
private readonly moduleRef;
|
|
112
|
-
private readonly logger;
|
|
113
|
-
constructor(discoveryService: DiscoveryService, moduleRef: ModuleRef);
|
|
114
|
-
/**
|
|
115
|
-
* Scan all NestJS providers for `@SubscribeTo()` metadata and wire each decorated
|
|
116
|
-
* method to its Kafka client via `startConsumer` or `startBatchConsumer`.
|
|
117
|
-
*
|
|
118
|
-
* Called automatically by the NestJS lifecycle — do not invoke manually.
|
|
119
|
-
*/
|
|
120
|
-
onModuleInit(): Promise<void>;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Health check service. Call `check(client)` to verify broker connectivity. */
|
|
124
|
-
declare class KafkaHealthIndicator {
|
|
125
|
-
check<T extends TopicMapConstraint<T>>(client: IKafkaClient<T>): Promise<KafkaHealthResult>;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export { ClientId, ConsumerOptions, GroupId, IKafkaClient, InjectKafkaClient, KAFKA_CLIENT, KAFKA_SUBSCRIBER_METADATA, KafkaClientOptions, KafkaExplorer, KafkaHealthIndicator, KafkaHealthResult, KafkaInstrumentation, KafkaModule, type KafkaModuleAsyncOptions, type KafkaModuleOptions, type KafkaSubscriberMetadata, SchemaLike, SubscribeTo, TopicDescriptor, TopicMapConstraint, getKafkaClientToken };
|
package/dist/otel.d.mts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { K as KafkaInstrumentation } from './consumer.types-fFCag3VJ.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Create a `KafkaInstrumentation` that automatically propagates
|
|
5
|
-
* W3C Trace Context via Kafka headers.
|
|
6
|
-
*
|
|
7
|
-
* Requires `@opentelemetry/api` as a peer dependency.
|
|
8
|
-
*
|
|
9
|
-
* **Send path:** injects `traceparent` into message headers from the
|
|
10
|
-
* active OpenTelemetry context.
|
|
11
|
-
*
|
|
12
|
-
* **Consume path:** extracts `traceparent` from message headers,
|
|
13
|
-
* starts a `CONSUMER` span as a child of the extracted context,
|
|
14
|
-
* and ends it when the handler completes.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* import { otelInstrumentation } from '@drarzter/kafka-client/otel';
|
|
19
|
-
*
|
|
20
|
-
* const kafka = new KafkaClient('my-app', 'my-group', brokers, {
|
|
21
|
-
* instrumentation: [otelInstrumentation()],
|
|
22
|
-
* });
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
declare function otelInstrumentation(): KafkaInstrumentation;
|
|
26
|
-
|
|
27
|
-
export { otelInstrumentation };
|