kafka-ts 0.0.17-beta.1 → 0.0.17-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,7 @@ export type ConsumerOptions = {
19
19
  partitionMaxBytes?: number;
20
20
  allowTopicAutoCreation?: boolean;
21
21
  fromBeginning?: boolean;
22
+ fromTimestamp?: bigint;
22
23
  batchGranularity?: BatchGranularity;
23
24
  concurrency?: number;
24
25
  retrier?: Retrier;
@@ -51,6 +51,7 @@ class Consumer extends events_1.default {
51
51
  isolationLevel: options.isolationLevel ?? 0 /* IsolationLevel.READ_UNCOMMITTED */,
52
52
  allowTopicAutoCreation: options.allowTopicAutoCreation ?? false,
53
53
  fromBeginning: options.fromBeginning ?? false,
54
+ fromTimestamp: options.fromTimestamp ?? (options.fromBeginning ? -2n : -1n),
54
55
  batchGranularity: options.batchGranularity ?? 'broker',
55
56
  concurrency: options.concurrency ?? 1,
56
57
  retrier: options.retrier ?? retrier_1.defaultRetrier,
@@ -76,13 +77,13 @@ class Consumer extends events_1.default {
76
77
  : undefined;
77
78
  }
78
79
  async start() {
79
- const { topics, allowTopicAutoCreation, fromBeginning } = this.options;
80
+ const { topics, allowTopicAutoCreation, fromTimestamp } = this.options;
80
81
  this.stopHook = undefined;
81
82
  try {
82
83
  await this.cluster.connect();
83
84
  await this.metadata.fetchMetadata({ topics, allowTopicAutoCreation });
84
85
  this.metadata.setAssignment(this.metadata.getTopicPartitions());
85
- await this.offsetManager.fetchOffsets({ fromBeginning });
86
+ await this.offsetManager.fetchOffsets({ fromTimestamp });
86
87
  await this.consumerGroup?.init();
87
88
  }
88
89
  catch (error) {
@@ -15,7 +15,7 @@ export declare class OffsetManager {
15
15
  resolve(topic: string, partition: number, offset: bigint): void;
16
16
  flush(topicPartitions: Record<string, Set<number>>): void;
17
17
  fetchOffsets(options: {
18
- fromBeginning: boolean;
18
+ fromTimestamp: bigint;
19
19
  }): Promise<void>;
20
20
  private listOffsets;
21
21
  }
@@ -40,7 +40,7 @@ class OffsetManager {
40
40
  nodeAssignment: Object.fromEntries(Object.entries(topicPartitions).map(([topicName, partitions]) => [topicName, Object.keys(partitions).map(Number)])),
41
41
  })));
42
42
  }
43
- async listOffsets({ nodeId, nodeAssignment, fromBeginning, }) {
43
+ async listOffsets({ nodeId, nodeAssignment, fromTimestamp, }) {
44
44
  const { cluster, isolationLevel } = this.options;
45
45
  const offsets = await cluster.sendRequestToNode(nodeId)(api_1.API.LIST_OFFSETS, {
46
46
  replicaId: -1,
@@ -53,7 +53,7 @@ class OffsetManager {
53
53
  {
54
54
  partitionIndex: partition,
55
55
  currentLeaderEpoch: -1,
56
- timestamp: fromBeginning ? -2n : -1n,
56
+ timestamp: fromTimestamp,
57
57
  },
58
58
  ],
59
59
  })),
@@ -124,10 +124,13 @@ class Decoder {
124
124
  const length = this.readInt32();
125
125
  return Array.from({ length }).map(() => {
126
126
  const size = this.readVarInt();
127
+ if (!size) {
128
+ return null;
129
+ }
127
130
  const child = new Decoder(this.buffer.subarray(this.offset, this.offset + size));
128
131
  this.offset += size;
129
132
  return callback(child);
130
- });
133
+ }).filter(x => x !== null);
131
134
  }
132
135
  read(length) {
133
136
  const value = this.buffer.subarray(this.offset, length !== undefined ? this.offset + length : undefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kafka-ts",
3
- "version": "0.0.17-beta.1",
3
+ "version": "0.0.17-beta.2",
4
4
  "main": "dist/index.js",
5
5
  "author": "Priit Käärd",
6
6
  "license": "MIT",