@drarzter/kafka-client 0.9.4 → 0.11.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 +693 -8
- package/dist/chunk-OR7TPAAE.mjs +4760 -0
- package/dist/chunk-OR7TPAAE.mjs.map +1 -0
- package/dist/chunk-PQVBRDNV.mjs +149 -0
- package/dist/chunk-PQVBRDNV.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-SM4FZKAZ.mjs → cli/index.js} +1073 -309
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +356 -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 +163 -0
- package/dist/client/kafka.client/consumer/handler.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/ops.d.ts +64 -0
- package/dist/client/kafka.client/consumer/ops.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/pipeline.d.ts +168 -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 +68 -0
- package/dist/client/kafka.client/consumer/retry-topic.d.ts.map +1 -0
- package/dist/client/kafka.client/consumer/setup.d.ts +66 -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 +75 -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 +79 -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 +124 -0
- package/dist/client/message/schema-registry.d.ts.map +1 -0
- package/dist/client/message/serde.d.ts +68 -0
- package/dist/client/message/serde.d.ts.map +1 -0
- package/dist/client/message/topic.d.ts +159 -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 +221 -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 +167 -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 +13 -314
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +1466 -123
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +45 -3
- package/dist/index.d.ts +7 -128
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1483 -123
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -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/serde.d.ts +157 -0
- package/dist/serde.d.ts.map +1 -0
- package/dist/serde.js +308 -0
- package/dist/serde.js.map +1 -0
- package/dist/serde.mjs +158 -0
- package/dist/serde.mjs.map +1 -0
- 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 +26 -0
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +26 -0
- package/dist/testing.mjs.map +1 -1
- package/package.json +40 -8
- package/dist/chunk-SM4FZKAZ.mjs.map +0 -1
- package/dist/client-1irhGEu0.d.mts +0 -751
- package/dist/client-BpFjkHhr.d.ts +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
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Options for `KafkaTestContainer`. */
|
|
2
|
+
export interface KafkaTestContainerOptions {
|
|
3
|
+
/** Docker image. Default: `"confluentinc/cp-kafka:7.7.0"`. */
|
|
4
|
+
image?: string;
|
|
5
|
+
/** Warm up the transactional coordinator on start. Default: `true`. */
|
|
6
|
+
transactionWarmup?: boolean;
|
|
7
|
+
/** Topics to pre-create. Each entry can be a string (1 partition) or `{ topic, numPartitions }`. */
|
|
8
|
+
topics?: Array<string | {
|
|
9
|
+
topic: string;
|
|
10
|
+
numPartitions?: number;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Thin wrapper around `@testcontainers/kafka` that starts a single-node
|
|
15
|
+
* KRaft Kafka container and exposes `brokers` for use with `KafkaClient`.
|
|
16
|
+
*
|
|
17
|
+
* Handles common setup pain points:
|
|
18
|
+
* - Transaction coordinator warmup (avoids transactional producer hangs)
|
|
19
|
+
* - Topic pre-creation (avoids race conditions)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const container = new KafkaTestContainer({ topics: ['orders', 'payments'] });
|
|
24
|
+
* const brokers = await container.start();
|
|
25
|
+
*
|
|
26
|
+
* const kafka = new KafkaClient('test', 'test-group', brokers);
|
|
27
|
+
* // ... run tests ...
|
|
28
|
+
*
|
|
29
|
+
* await container.stop();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Jest lifecycle
|
|
33
|
+
* ```ts
|
|
34
|
+
* let container: KafkaTestContainer;
|
|
35
|
+
* let brokers: string[];
|
|
36
|
+
*
|
|
37
|
+
* beforeAll(async () => {
|
|
38
|
+
* container = new KafkaTestContainer({ topics: ['orders'] });
|
|
39
|
+
* brokers = await container.start();
|
|
40
|
+
* }, 120_000);
|
|
41
|
+
*
|
|
42
|
+
* afterAll(() => container.stop());
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class KafkaTestContainer {
|
|
46
|
+
private container;
|
|
47
|
+
private readonly image;
|
|
48
|
+
private readonly transactionWarmup;
|
|
49
|
+
private readonly topics;
|
|
50
|
+
constructor(options?: KafkaTestContainerOptions);
|
|
51
|
+
/**
|
|
52
|
+
* Start the Kafka container, pre-create topics, and optionally warm up
|
|
53
|
+
* the transaction coordinator.
|
|
54
|
+
*
|
|
55
|
+
* @returns Broker connection strings, e.g. `["localhost:55123"]`.
|
|
56
|
+
*/
|
|
57
|
+
start(): Promise<string[]>;
|
|
58
|
+
/** Stop and remove the container. */
|
|
59
|
+
stop(): Promise<void>;
|
|
60
|
+
/** Broker connection strings. Throws if container is not started. */
|
|
61
|
+
get brokers(): string[];
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=test.container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.container.d.ts","sourceRoot":"","sources":["../../src/testing/test.container.ts"],"names":[],"mappings":"AAOA,wCAAwC;AACxC,MAAM,WAAW,yBAAyB;IACxC,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,oGAAoG;IACpG,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,SAAS,CAAoC;IACrD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAU;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAErB;gBAEU,OAAO,CAAC,EAAE,yBAAyB;IAM/C;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IA2DhC,qCAAqC;IAC/B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B,qEAAqE;IACrE,IAAI,OAAO,IAAI,MAAM,EAAE,CAOtB;CACF"}
|
|
@@ -1,113 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { I as IKafkaClient, a as IAdmin, b as IPartitionWatermarks, c as IGroupTopicOffsets, d as IPartitionOffset, e as IGroupDescription, f as ITopicMetadata, g as IConsumer, h as IConsumerCreationOptions, i as IConsumerRunConfig, j as ITopicPartitions, k as ITopicPartitionOffset, l as ITopicPartition, m as IMessage, n as IProducer, o as IProducerRecord, p as ITransaction, q as IProducerCreationOptions, K as KafkaTransport } from './client-1irhGEu0.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Fully typed mock of `IKafkaClient<T>` where every method is a mock function.
|
|
6
|
-
* Compatible with Jest, Vitest, or any framework whose `fn()` returns
|
|
7
|
-
* an object with `.mock`, `.mockResolvedValue`, etc.
|
|
8
|
-
*/
|
|
9
|
-
type MockKafkaClient<T extends TopicMapConstraint<T>> = {
|
|
10
|
-
[K in keyof IKafkaClient<T>]: IKafkaClient<T>[K] & Record<string, any>;
|
|
11
|
-
};
|
|
12
|
-
/** Factory that creates a no-op mock function (e.g. `() => jest.fn()`). */
|
|
13
|
-
type MockFactory = () => (...args: any[]) => any;
|
|
14
|
-
/**
|
|
15
|
-
* Create a fully typed mock implementing every `IKafkaClient<T>` method.
|
|
16
|
-
* Useful for unit-testing services that depend on `KafkaClient` without
|
|
17
|
-
* touching a real broker.
|
|
18
|
-
*
|
|
19
|
-
* Auto-detects Jest (`jest.fn()`) or Vitest (`vi.fn()`). Pass a custom
|
|
20
|
-
* `mockFactory` for other frameworks.
|
|
21
|
-
*
|
|
22
|
-
* All methods resolve to sensible defaults:
|
|
23
|
-
* - `checkStatus()` → `{ status: 'up', clientId: 'mock-client', topics: [] }`
|
|
24
|
-
* - `getClientId()` → `"mock-client"`
|
|
25
|
-
* - void methods → `undefined`
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* const kafka = createMockKafkaClient<MyTopics>();
|
|
30
|
-
*
|
|
31
|
-
* const service = new OrdersService(kafka);
|
|
32
|
-
* await service.createOrder();
|
|
33
|
-
*
|
|
34
|
-
* expect(kafka.sendMessage).toHaveBeenCalledWith(
|
|
35
|
-
* 'order.created',
|
|
36
|
-
* expect.objectContaining({ orderId: '123' }),
|
|
37
|
-
* );
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare function createMockKafkaClient<T extends TopicMapConstraint<T>>(mockFactory?: MockFactory): MockKafkaClient<T>;
|
|
41
|
-
|
|
42
|
-
/** Options for `KafkaTestContainer`. */
|
|
43
|
-
interface KafkaTestContainerOptions {
|
|
44
|
-
/** Docker image. Default: `"confluentinc/cp-kafka:7.7.0"`. */
|
|
45
|
-
image?: string;
|
|
46
|
-
/** Warm up the transactional coordinator on start. Default: `true`. */
|
|
47
|
-
transactionWarmup?: boolean;
|
|
48
|
-
/** Topics to pre-create. Each entry can be a string (1 partition) or `{ topic, numPartitions }`. */
|
|
49
|
-
topics?: Array<string | {
|
|
50
|
-
topic: string;
|
|
51
|
-
numPartitions?: number;
|
|
52
|
-
}>;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Thin wrapper around `@testcontainers/kafka` that starts a single-node
|
|
56
|
-
* KRaft Kafka container and exposes `brokers` for use with `KafkaClient`.
|
|
57
|
-
*
|
|
58
|
-
* Handles common setup pain points:
|
|
59
|
-
* - Transaction coordinator warmup (avoids transactional producer hangs)
|
|
60
|
-
* - Topic pre-creation (avoids race conditions)
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* const container = new KafkaTestContainer({ topics: ['orders', 'payments'] });
|
|
65
|
-
* const brokers = await container.start();
|
|
66
|
-
*
|
|
67
|
-
* const kafka = new KafkaClient('test', 'test-group', brokers);
|
|
68
|
-
* // ... run tests ...
|
|
69
|
-
*
|
|
70
|
-
* await container.stop();
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @example Jest lifecycle
|
|
74
|
-
* ```ts
|
|
75
|
-
* let container: KafkaTestContainer;
|
|
76
|
-
* let brokers: string[];
|
|
77
|
-
*
|
|
78
|
-
* beforeAll(async () => {
|
|
79
|
-
* container = new KafkaTestContainer({ topics: ['orders'] });
|
|
80
|
-
* brokers = await container.start();
|
|
81
|
-
* }, 120_000);
|
|
82
|
-
*
|
|
83
|
-
* afterAll(() => container.stop());
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
declare class KafkaTestContainer {
|
|
87
|
-
private container;
|
|
88
|
-
private readonly image;
|
|
89
|
-
private readonly transactionWarmup;
|
|
90
|
-
private readonly topics;
|
|
91
|
-
constructor(options?: KafkaTestContainerOptions);
|
|
92
|
-
/**
|
|
93
|
-
* Start the Kafka container, pre-create topics, and optionally warm up
|
|
94
|
-
* the transaction coordinator.
|
|
95
|
-
*
|
|
96
|
-
* @returns Broker connection strings, e.g. `["localhost:55123"]`.
|
|
97
|
-
*/
|
|
98
|
-
start(): Promise<string[]>;
|
|
99
|
-
/** Stop and remove the container. */
|
|
100
|
-
stop(): Promise<void>;
|
|
101
|
-
/** Broker connection strings. Throws if container is not started. */
|
|
102
|
-
get brokers(): string[];
|
|
103
|
-
}
|
|
104
|
-
|
|
1
|
+
import type { KafkaTransport, IProducer, IConsumer, IAdmin, ITransaction, IProducerRecord, IProducerCreationOptions, IConsumerCreationOptions, IConsumerRunConfig, ITopicPartition, ITopicPartitions, ITopicPartitionOffset, IPartitionWatermarks, IPartitionOffset, IGroupTopicOffsets, IGroupDescription, ITopicMetadata, IMessage } from "../client/transport/transport.interface";
|
|
105
2
|
/**
|
|
106
3
|
* An in-memory Kafka transaction.
|
|
107
4
|
* Staged sends are visible in `staged`; committed sends are flushed
|
|
108
5
|
* to the owning `FakeProducer.sent` on `commit()`.
|
|
109
6
|
*/
|
|
110
|
-
declare class FakeTransaction implements ITransaction {
|
|
7
|
+
export declare class FakeTransaction implements ITransaction {
|
|
111
8
|
private readonly producer;
|
|
112
9
|
/** Records staged within this transaction (not yet committed). */
|
|
113
10
|
readonly staged: IProducerRecord[];
|
|
@@ -142,7 +39,7 @@ declare class FakeTransaction implements ITransaction {
|
|
|
142
39
|
* In-memory producer. All `send()` calls are captured in `sent`.
|
|
143
40
|
* Transactions are backed by `FakeTransaction`.
|
|
144
41
|
*/
|
|
145
|
-
declare class FakeProducer implements IProducer {
|
|
42
|
+
export declare class FakeProducer implements IProducer {
|
|
146
43
|
/** All records delivered via `send()` (direct + committed transactions). */
|
|
147
44
|
readonly sent: IProducerRecord[];
|
|
148
45
|
/** All transactions opened via `transaction()`. */
|
|
@@ -166,7 +63,7 @@ declare class FakeProducer implements IProducer {
|
|
|
166
63
|
* Call `deliver(topic, message)` from your test to push messages through
|
|
167
64
|
* the `eachMessage` handler without a real broker.
|
|
168
65
|
*/
|
|
169
|
-
declare class FakeConsumer implements IConsumer {
|
|
66
|
+
export declare class FakeConsumer implements IConsumer {
|
|
170
67
|
readonly groupId: string;
|
|
171
68
|
readonly fromBeginning: boolean;
|
|
172
69
|
/** Topics subscribed via `subscribe()`. */
|
|
@@ -209,7 +106,7 @@ declare class FakeConsumer implements IConsumer {
|
|
|
209
106
|
* Pre-populate `topicOffsets`, `groupOffsets`, and `existingTopics`
|
|
210
107
|
* to control what admin queries return.
|
|
211
108
|
*/
|
|
212
|
-
declare class FakeAdmin implements IAdmin {
|
|
109
|
+
export declare class FakeAdmin implements IAdmin {
|
|
213
110
|
/** Topics returned by `listTopics()`. Add to this from your test. */
|
|
214
111
|
readonly existingTopics: string[];
|
|
215
112
|
/** Per-topic partition watermarks returned by `fetchTopicOffsets()`. */
|
|
@@ -280,7 +177,7 @@ declare class FakeAdmin implements IAdmin {
|
|
|
280
177
|
* expect(transport.mainProducer.sentTo('orders')).toHaveLength(1);
|
|
281
178
|
* ```
|
|
282
179
|
*/
|
|
283
|
-
declare class FakeTransport implements KafkaTransport {
|
|
180
|
+
export declare class FakeTransport implements KafkaTransport {
|
|
284
181
|
private readonly _producers;
|
|
285
182
|
private readonly _consumers;
|
|
286
183
|
private readonly _admin;
|
|
@@ -314,5 +211,4 @@ declare class FakeTransport implements KafkaTransport {
|
|
|
314
211
|
offset?: string;
|
|
315
212
|
}): Promise<void>;
|
|
316
213
|
}
|
|
317
|
-
|
|
318
|
-
export { FakeAdmin, FakeConsumer, FakeProducer, FakeTransaction, FakeTransport, KafkaTestContainer, type KafkaTestContainerOptions, type MockKafkaClient, createMockKafkaClient };
|
|
214
|
+
//# sourceMappingURL=transport.fake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.fake.d.ts","sourceRoot":"","sources":["../../src/testing/transport.fake.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,SAAS,EACT,MAAM,EACN,YAAY,EACZ,eAAe,EACf,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACT,MAAM,yCAAyC,CAAC;AAIjD;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,YAAY;IAatC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAZrC,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,CAAM;IACxC,wCAAwC;IACxC,SAAS,UAAS;IAClB,uCAAuC;IACvC,OAAO,UAAS;IAChB,8CAA8C;IAC9C,QAAQ,CAAC,gBAAgB,EAAE,KAAK,CAAC;QAC/B,QAAQ,EAAE,SAAS,CAAC;QACpB,MAAM,EAAE,KAAK,CAAC;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,gBAAgB,EAAE,CAAA;SAAE,CAAC,CAAC;KAClE,CAAC,CAAM;gBAEqB,QAAQ,EAAE,YAAY;IAE7C,IAAI,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,WAAW,CAAC,OAAO,EAAE;QACzB,QAAQ,EAAE,SAAS,CAAC;QACpB,MAAM,EAAE,KAAK,CAAC;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,KAAK,CAAC;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EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACZ,GACL,OAAO,CAAC,IAAI,CAAC;CAuBjB"}
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,318 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Fully typed mock of `IKafkaClient<T>` where every method is a mock function.
|
|
6
|
-
* Compatible with Jest, Vitest, or any framework whose `fn()` returns
|
|
7
|
-
* an object with `.mock`, `.mockResolvedValue`, etc.
|
|
8
|
-
*/
|
|
9
|
-
type MockKafkaClient<T extends TopicMapConstraint<T>> = {
|
|
10
|
-
[K in keyof IKafkaClient<T>]: IKafkaClient<T>[K] & Record<string, any>;
|
|
11
|
-
};
|
|
12
|
-
/** Factory that creates a no-op mock function (e.g. `() => jest.fn()`). */
|
|
13
|
-
type MockFactory = () => (...args: any[]) => any;
|
|
14
|
-
/**
|
|
15
|
-
* Create a fully typed mock implementing every `IKafkaClient<T>` method.
|
|
16
|
-
* Useful for unit-testing services that depend on `KafkaClient` without
|
|
17
|
-
* touching a real broker.
|
|
18
|
-
*
|
|
19
|
-
* Auto-detects Jest (`jest.fn()`) or Vitest (`vi.fn()`). Pass a custom
|
|
20
|
-
* `mockFactory` for other frameworks.
|
|
21
|
-
*
|
|
22
|
-
* All methods resolve to sensible defaults:
|
|
23
|
-
* - `checkStatus()` → `{ status: 'up', clientId: 'mock-client', topics: [] }`
|
|
24
|
-
* - `getClientId()` → `"mock-client"`
|
|
25
|
-
* - void methods → `undefined`
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* const kafka = createMockKafkaClient<MyTopics>();
|
|
30
|
-
*
|
|
31
|
-
* const service = new OrdersService(kafka);
|
|
32
|
-
* await service.createOrder();
|
|
33
|
-
*
|
|
34
|
-
* expect(kafka.sendMessage).toHaveBeenCalledWith(
|
|
35
|
-
* 'order.created',
|
|
36
|
-
* expect.objectContaining({ orderId: '123' }),
|
|
37
|
-
* );
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare function createMockKafkaClient<T extends TopicMapConstraint<T>>(mockFactory?: MockFactory): MockKafkaClient<T>;
|
|
41
|
-
|
|
42
|
-
/** Options for `KafkaTestContainer`. */
|
|
43
|
-
interface KafkaTestContainerOptions {
|
|
44
|
-
/** Docker image. Default: `"confluentinc/cp-kafka:7.7.0"`. */
|
|
45
|
-
image?: string;
|
|
46
|
-
/** Warm up the transactional coordinator on start. Default: `true`. */
|
|
47
|
-
transactionWarmup?: boolean;
|
|
48
|
-
/** Topics to pre-create. Each entry can be a string (1 partition) or `{ topic, numPartitions }`. */
|
|
49
|
-
topics?: Array<string | {
|
|
50
|
-
topic: string;
|
|
51
|
-
numPartitions?: number;
|
|
52
|
-
}>;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Thin wrapper around `@testcontainers/kafka` that starts a single-node
|
|
56
|
-
* KRaft Kafka container and exposes `brokers` for use with `KafkaClient`.
|
|
57
|
-
*
|
|
58
|
-
* Handles common setup pain points:
|
|
59
|
-
* - Transaction coordinator warmup (avoids transactional producer hangs)
|
|
60
|
-
* - Topic pre-creation (avoids race conditions)
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* const container = new KafkaTestContainer({ topics: ['orders', 'payments'] });
|
|
65
|
-
* const brokers = await container.start();
|
|
66
|
-
*
|
|
67
|
-
* const kafka = new KafkaClient('test', 'test-group', brokers);
|
|
68
|
-
* // ... run tests ...
|
|
69
|
-
*
|
|
70
|
-
* await container.stop();
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @example Jest lifecycle
|
|
74
|
-
* ```ts
|
|
75
|
-
* let container: KafkaTestContainer;
|
|
76
|
-
* let brokers: string[];
|
|
77
|
-
*
|
|
78
|
-
* beforeAll(async () => {
|
|
79
|
-
* container = new KafkaTestContainer({ topics: ['orders'] });
|
|
80
|
-
* brokers = await container.start();
|
|
81
|
-
* }, 120_000);
|
|
82
|
-
*
|
|
83
|
-
* afterAll(() => container.stop());
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
declare class KafkaTestContainer {
|
|
87
|
-
private container;
|
|
88
|
-
private readonly image;
|
|
89
|
-
private readonly transactionWarmup;
|
|
90
|
-
private readonly topics;
|
|
91
|
-
constructor(options?: KafkaTestContainerOptions);
|
|
92
|
-
/**
|
|
93
|
-
* Start the Kafka container, pre-create topics, and optionally warm up
|
|
94
|
-
* the transaction coordinator.
|
|
95
|
-
*
|
|
96
|
-
* @returns Broker connection strings, e.g. `["localhost:55123"]`.
|
|
97
|
-
*/
|
|
98
|
-
start(): Promise<string[]>;
|
|
99
|
-
/** Stop and remove the container. */
|
|
100
|
-
stop(): Promise<void>;
|
|
101
|
-
/** Broker connection strings. Throws if container is not started. */
|
|
102
|
-
get brokers(): string[];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* An in-memory Kafka transaction.
|
|
107
|
-
* Staged sends are visible in `staged`; committed sends are flushed
|
|
108
|
-
* to the owning `FakeProducer.sent` on `commit()`.
|
|
109
|
-
*/
|
|
110
|
-
declare class FakeTransaction implements ITransaction {
|
|
111
|
-
private readonly producer;
|
|
112
|
-
/** Records staged within this transaction (not yet committed). */
|
|
113
|
-
readonly staged: IProducerRecord[];
|
|
114
|
-
/** True after `commit()` was called. */
|
|
115
|
-
committed: boolean;
|
|
116
|
-
/** True after `abort()` was called. */
|
|
117
|
-
aborted: boolean;
|
|
118
|
-
/** sendOffsets calls (for EOS assertions). */
|
|
119
|
-
readonly offsetsCommitted: Array<{
|
|
120
|
-
consumer: IConsumer;
|
|
121
|
-
topics: Array<{
|
|
122
|
-
topic: string;
|
|
123
|
-
partitions: IPartitionOffset[];
|
|
124
|
-
}>;
|
|
125
|
-
}>;
|
|
126
|
-
constructor(producer: FakeProducer);
|
|
127
|
-
send(record: IProducerRecord): Promise<void>;
|
|
128
|
-
sendOffsets(options: {
|
|
129
|
-
consumer: IConsumer;
|
|
130
|
-
topics: Array<{
|
|
131
|
-
topic: string;
|
|
132
|
-
partitions: Array<{
|
|
133
|
-
partition: number;
|
|
134
|
-
offset: string;
|
|
135
|
-
}>;
|
|
136
|
-
}>;
|
|
137
|
-
}): Promise<void>;
|
|
138
|
-
commit(): Promise<void>;
|
|
139
|
-
abort(): Promise<void>;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* In-memory producer. All `send()` calls are captured in `sent`.
|
|
143
|
-
* Transactions are backed by `FakeTransaction`.
|
|
144
|
-
*/
|
|
145
|
-
declare class FakeProducer implements IProducer {
|
|
146
|
-
/** All records delivered via `send()` (direct + committed transactions). */
|
|
147
|
-
readonly sent: IProducerRecord[];
|
|
148
|
-
/** All transactions opened via `transaction()`. */
|
|
149
|
-
readonly transactions: FakeTransaction[];
|
|
150
|
-
readonly options: IProducerCreationOptions | undefined;
|
|
151
|
-
connected: boolean;
|
|
152
|
-
constructor(options?: IProducerCreationOptions);
|
|
153
|
-
connect(): Promise<void>;
|
|
154
|
-
disconnect(): Promise<void>;
|
|
155
|
-
send(record: IProducerRecord): Promise<void>;
|
|
156
|
-
transaction(): Promise<ITransaction>;
|
|
157
|
-
/** Return the last committed transaction, or throw if none exist. */
|
|
158
|
-
get lastTransaction(): FakeTransaction;
|
|
159
|
-
/** All topic names that received at least one message. */
|
|
160
|
-
sentTopics(): string[];
|
|
161
|
-
/** All messages sent to a specific topic. */
|
|
162
|
-
sentTo(topic: string): IProducerRecord["messages"];
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* In-memory consumer.
|
|
166
|
-
* Call `deliver(topic, message)` from your test to push messages through
|
|
167
|
-
* the `eachMessage` handler without a real broker.
|
|
168
|
-
*/
|
|
169
|
-
declare class FakeConsumer implements IConsumer {
|
|
170
|
-
readonly groupId: string;
|
|
171
|
-
readonly fromBeginning: boolean;
|
|
172
|
-
/** Topics subscribed via `subscribe()`. */
|
|
173
|
-
readonly subscribed: string[];
|
|
174
|
-
private _runConfig;
|
|
175
|
-
private _assignments;
|
|
176
|
-
readonly pausedTopics: Set<string>;
|
|
177
|
-
connected: boolean;
|
|
178
|
-
private readonly onRebalance;
|
|
179
|
-
constructor(options: IConsumerCreationOptions);
|
|
180
|
-
connect(): Promise<void>;
|
|
181
|
-
disconnect(): Promise<void>;
|
|
182
|
-
subscribe(options: {
|
|
183
|
-
topics: (string | RegExp)[];
|
|
184
|
-
}): Promise<void>;
|
|
185
|
-
run(config: IConsumerRunConfig): Promise<void>;
|
|
186
|
-
pause(assignments: ITopicPartitions[]): void;
|
|
187
|
-
resume(assignments: ITopicPartitions[]): void;
|
|
188
|
-
seek(_options: ITopicPartitionOffset): void;
|
|
189
|
-
assignment(): ITopicPartition[];
|
|
190
|
-
commitOffsets(_offsets: ITopicPartitionOffset[]): Promise<void>;
|
|
191
|
-
stop(): Promise<void>;
|
|
192
|
-
/**
|
|
193
|
-
* Push a message through the `eachMessage` handler.
|
|
194
|
-
* Throws if `run()` has not been called yet.
|
|
195
|
-
*/
|
|
196
|
-
deliver(topic: string, message: Partial<IMessage> & {
|
|
197
|
-
value: Buffer | null;
|
|
198
|
-
}, partition?: number, offset?: string): Promise<void>;
|
|
199
|
-
/**
|
|
200
|
-
* Simulate a partition-assign rebalance event.
|
|
201
|
-
* Useful for testing onRebalance callbacks.
|
|
202
|
-
*/
|
|
203
|
-
triggerRebalance(type: "assign" | "revoke", assignments: ITopicPartition[]): void;
|
|
204
|
-
/** Whether `run()` has been called (consumer is active). */
|
|
205
|
-
get isRunning(): boolean;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* In-memory admin client.
|
|
209
|
-
* Pre-populate `topicOffsets`, `groupOffsets`, and `existingTopics`
|
|
210
|
-
* to control what admin queries return.
|
|
211
|
-
*/
|
|
212
|
-
declare class FakeAdmin implements IAdmin {
|
|
213
|
-
/** Topics returned by `listTopics()`. Add to this from your test. */
|
|
214
|
-
readonly existingTopics: string[];
|
|
215
|
-
/** Per-topic partition watermarks returned by `fetchTopicOffsets()`. */
|
|
216
|
-
readonly topicOffsets: Map<string, IPartitionWatermarks[]>;
|
|
217
|
-
/** Per-groupId committed offsets returned by `fetchOffsets()`. */
|
|
218
|
-
readonly groupOffsets: Map<string, IGroupTopicOffsets[]>;
|
|
219
|
-
/** Calls captured by `setOffsets()` — inspect in tests. */
|
|
220
|
-
readonly setOffsetsCalls: Array<{
|
|
221
|
-
groupId: string;
|
|
222
|
-
topic: string;
|
|
223
|
-
partitions: IPartitionOffset[];
|
|
224
|
-
}>;
|
|
225
|
-
/** Group IDs deleted via `deleteGroups()`. */
|
|
226
|
-
readonly deletedGroups: string[];
|
|
227
|
-
/** Records deleted via `deleteTopicRecords()`. */
|
|
228
|
-
readonly deletedRecords: Array<{
|
|
229
|
-
topic: string;
|
|
230
|
-
partitions: IPartitionOffset[];
|
|
231
|
-
}>;
|
|
232
|
-
connected: boolean;
|
|
233
|
-
connect(): Promise<void>;
|
|
234
|
-
disconnect(): Promise<void>;
|
|
235
|
-
createTopics(options: {
|
|
236
|
-
topics: Array<{
|
|
237
|
-
topic: string;
|
|
238
|
-
numPartitions: number;
|
|
239
|
-
}>;
|
|
240
|
-
}): Promise<void>;
|
|
241
|
-
fetchTopicOffsets(topic: string): Promise<IPartitionWatermarks[]>;
|
|
242
|
-
fetchTopicOffsetsByTimestamp(_topic: string, _timestamp: number): Promise<IPartitionOffset[]>;
|
|
243
|
-
fetchOffsets(options: {
|
|
244
|
-
groupId: string;
|
|
245
|
-
}): Promise<IGroupTopicOffsets[]>;
|
|
246
|
-
setOffsets(options: {
|
|
247
|
-
groupId: string;
|
|
248
|
-
topic: string;
|
|
249
|
-
partitions: IPartitionOffset[];
|
|
250
|
-
}): Promise<void>;
|
|
251
|
-
listTopics(): Promise<string[]>;
|
|
252
|
-
listGroups(): Promise<{
|
|
253
|
-
groups: IGroupDescription[];
|
|
254
|
-
}>;
|
|
255
|
-
fetchTopicMetadata(_options?: {
|
|
256
|
-
topics?: string[];
|
|
257
|
-
}): Promise<{
|
|
258
|
-
topics: ITopicMetadata[];
|
|
259
|
-
}>;
|
|
260
|
-
deleteGroups(groupIds: string[]): Promise<void>;
|
|
261
|
-
deleteTopicRecords(options: {
|
|
262
|
-
topic: string;
|
|
263
|
-
partitions: IPartitionOffset[];
|
|
264
|
-
}): Promise<void>;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* In-memory `KafkaTransport` for unit testing.
|
|
268
|
-
*
|
|
269
|
-
* Inject into `KafkaClient` via `KafkaClientOptions.transport` to test
|
|
270
|
-
* producer/consumer logic without `jest.mock('@confluentinc/kafka-javascript')`.
|
|
271
|
-
*
|
|
272
|
-
* @example
|
|
273
|
-
* ```ts
|
|
274
|
-
* const transport = new FakeTransport();
|
|
275
|
-
* const client = new KafkaClient('svc', 'grp', [], { transport });
|
|
276
|
-
*
|
|
277
|
-
* await client.connectProducer();
|
|
278
|
-
* await client.sendMessage('orders', { id: '1' });
|
|
279
|
-
*
|
|
280
|
-
* expect(transport.mainProducer.sentTo('orders')).toHaveLength(1);
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
declare class FakeTransport implements KafkaTransport {
|
|
284
|
-
private readonly _producers;
|
|
285
|
-
private readonly _consumers;
|
|
286
|
-
private readonly _admin;
|
|
287
|
-
producer(options?: IProducerCreationOptions): IProducer;
|
|
288
|
-
consumer(options: IConsumerCreationOptions): IConsumer;
|
|
289
|
-
admin(): IAdmin;
|
|
290
|
-
/** The admin client shared across all admin() calls. */
|
|
291
|
-
get fakeAdmin(): FakeAdmin;
|
|
292
|
-
/**
|
|
293
|
-
* The first (default) producer — the non-transactional producer
|
|
294
|
-
* created during `KafkaClient` construction.
|
|
295
|
-
*/
|
|
296
|
-
get mainProducer(): FakeProducer;
|
|
297
|
-
/** All producers created so far (main + transactional). */
|
|
298
|
-
get producers(): readonly FakeProducer[];
|
|
299
|
-
/** All consumers created so far. */
|
|
300
|
-
get consumers(): readonly FakeConsumer[];
|
|
301
|
-
/**
|
|
302
|
-
* Find the consumer for a given group ID.
|
|
303
|
-
* Throws if no consumer with that group exists.
|
|
304
|
-
*/
|
|
305
|
-
consumerFor(groupId: string): FakeConsumer;
|
|
306
|
-
/**
|
|
307
|
-
* Deliver a JSON-serialized message to the first consumer subscribed to `topic`.
|
|
308
|
-
* Simulates a broker dispatching a message to the consumer handler.
|
|
309
|
-
*/
|
|
310
|
-
deliver<T>(topic: string, payload: T, options?: {
|
|
311
|
-
key?: string;
|
|
312
|
-
headers?: Record<string, string>;
|
|
313
|
-
partition?: number;
|
|
314
|
-
offset?: string;
|
|
315
|
-
}): Promise<void>;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
export { FakeAdmin, FakeConsumer, FakeProducer, FakeTransaction, FakeTransport, KafkaTestContainer, type KafkaTestContainerOptions, type MockKafkaClient, createMockKafkaClient };
|
|
1
|
+
export * from "./testing/index";
|
|
2
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/testing.js
CHANGED
|
@@ -63,6 +63,7 @@ function createMockKafkaClient(mockFactory) {
|
|
|
63
63
|
getClientId: returning("mock-client"),
|
|
64
64
|
sendMessage: resolved(void 0),
|
|
65
65
|
sendBatch: resolved(void 0),
|
|
66
|
+
sendTombstone: resolved(void 0),
|
|
66
67
|
transaction: mock().mockImplementation(
|
|
67
68
|
async (cb) => {
|
|
68
69
|
const ctx = {
|
|
@@ -82,6 +83,21 @@ function createMockKafkaClient(mockFactory) {
|
|
|
82
83
|
stop: mock().mockResolvedValue(void 0),
|
|
83
84
|
ready: mock().mockResolvedValue(void 0)
|
|
84
85
|
}),
|
|
86
|
+
startWindowConsumer: resolved({
|
|
87
|
+
groupId: "mock-group",
|
|
88
|
+
stop: mock().mockResolvedValue(void 0),
|
|
89
|
+
ready: mock().mockResolvedValue(void 0)
|
|
90
|
+
}),
|
|
91
|
+
startRoutedConsumer: resolved({
|
|
92
|
+
groupId: "mock-group",
|
|
93
|
+
stop: mock().mockResolvedValue(void 0),
|
|
94
|
+
ready: mock().mockResolvedValue(void 0)
|
|
95
|
+
}),
|
|
96
|
+
startTransactionalConsumer: resolved({
|
|
97
|
+
groupId: "mock-group",
|
|
98
|
+
stop: mock().mockResolvedValue(void 0),
|
|
99
|
+
ready: mock().mockResolvedValue(void 0)
|
|
100
|
+
}),
|
|
85
101
|
stopConsumer: resolved(void 0),
|
|
86
102
|
consume: returning(
|
|
87
103
|
(function* () {
|
|
@@ -101,6 +117,15 @@ function createMockKafkaClient(mockFactory) {
|
|
|
101
117
|
dedupCount: 0
|
|
102
118
|
}),
|
|
103
119
|
resetMetrics: mock(),
|
|
120
|
+
listConsumerGroups: resolved([]),
|
|
121
|
+
describeTopics: resolved([]),
|
|
122
|
+
deleteRecords: resolved(void 0),
|
|
123
|
+
readSnapshot: resolved(/* @__PURE__ */ new Map()),
|
|
124
|
+
checkpointOffsets: resolved({ groupId: "mock-group", checkpoints: [] }),
|
|
125
|
+
restoreFromCheckpoint: resolved(void 0),
|
|
126
|
+
connectProducer: resolved(void 0),
|
|
127
|
+
disconnectProducer: resolved(void 0),
|
|
128
|
+
onModuleDestroy: resolved(void 0),
|
|
104
129
|
disconnect: resolved(void 0),
|
|
105
130
|
enableGracefulShutdown: mock()
|
|
106
131
|
};
|
|
@@ -194,6 +219,7 @@ var FakeTransaction = class {
|
|
|
194
219
|
constructor(producer) {
|
|
195
220
|
this.producer = producer;
|
|
196
221
|
}
|
|
222
|
+
producer;
|
|
197
223
|
/** Records staged within this transaction (not yet committed). */
|
|
198
224
|
staged = [];
|
|
199
225
|
/** True after `commit()` was called. */
|