kafka-crab-js 1.4.0-beta.2 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +162 -0
- package/dist/index.cjs.map +7 -0
- package/{index.d.ts → dist/index.d.ts} +4 -4
- package/dist/index.js +137 -0
- package/dist/index.js.map +7 -0
- package/{kafka-client.d.ts → dist/kafka-client.d.ts} +4 -4
- package/{kafka-stream-readable.d.ts → dist/kafka-stream-readable.d.ts} +2 -2
- package/js-binding.cjs +383 -0
- package/js-binding.d.ts +0 -2
- package/package.json +32 -25
- package/index.js +0 -11
- package/kafka-client.js +0 -49
- package/kafka-stream-readable.js +0 -79
package/README.md
CHANGED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// js-src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
CommitMode: () => import_js_binding2.CommitMode,
|
|
24
|
+
KafkaClient: () => KafkaClient,
|
|
25
|
+
KafkaClientConfig: () => import_js_binding2.KafkaClientConfig,
|
|
26
|
+
KafkaConsumer: () => import_js_binding2.KafkaConsumer,
|
|
27
|
+
KafkaEventName: () => import_js_binding2.KafkaEventName,
|
|
28
|
+
KafkaProducer: () => import_js_binding2.KafkaProducer,
|
|
29
|
+
KafkaStreamReadable: () => KafkaStreamReadable,
|
|
30
|
+
PartitionPosition: () => import_js_binding2.PartitionPosition,
|
|
31
|
+
SecurityProtocol: () => import_js_binding2.SecurityProtocol
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(index_exports);
|
|
34
|
+
var import_js_binding2 = require("../js-binding.cjs");
|
|
35
|
+
|
|
36
|
+
// js-src/kafka-client.ts
|
|
37
|
+
var import_js_binding = require("../js-binding.cjs");
|
|
38
|
+
|
|
39
|
+
// js-src/kafka-stream-readable.ts
|
|
40
|
+
var import_stream = require("stream");
|
|
41
|
+
var KafkaStreamReadable = class extends import_stream.Readable {
|
|
42
|
+
/**
|
|
43
|
+
* Creates a KafkaStreamReadable instance
|
|
44
|
+
*/
|
|
45
|
+
constructor(kafkaConsumer) {
|
|
46
|
+
super({ objectMode: true });
|
|
47
|
+
this.kafkaConsumer = kafkaConsumer;
|
|
48
|
+
if (!kafkaConsumer) {
|
|
49
|
+
throw new Error("A valid KafkaConsumer instance is required.");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Subscribes to topics
|
|
54
|
+
*/
|
|
55
|
+
async subscribe(topics) {
|
|
56
|
+
if (!topics || Array.isArray(topics) && topics.length === 0) {
|
|
57
|
+
throw new Error("Topics must be a non-empty string or array.");
|
|
58
|
+
}
|
|
59
|
+
await this.kafkaConsumer.subscribe(topics);
|
|
60
|
+
}
|
|
61
|
+
seek(topic, partition, offsetModel, timeout) {
|
|
62
|
+
this.kafkaConsumer.seek(topic, partition, offsetModel, timeout);
|
|
63
|
+
}
|
|
64
|
+
commit(topic, partition, offset, commit) {
|
|
65
|
+
this.kafkaConsumer.commit(topic, partition, offset, commit);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Unsubscribe from topics
|
|
69
|
+
*/
|
|
70
|
+
unsubscribe() {
|
|
71
|
+
this.kafkaConsumer.unsubscribe();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Disconnects the Kafka consumer
|
|
75
|
+
*/
|
|
76
|
+
async disconnect() {
|
|
77
|
+
await this.kafkaConsumer.disconnect();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns the raw Kafka consumer
|
|
81
|
+
* @returns {KafkaConsumer} The Kafka consumer instance
|
|
82
|
+
*/
|
|
83
|
+
rawConsumer() {
|
|
84
|
+
return this.kafkaConsumer;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Internal method called by the Readable stream to fetch data
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
async _read() {
|
|
91
|
+
try {
|
|
92
|
+
const message = await this.kafkaConsumer.recv();
|
|
93
|
+
if (message) {
|
|
94
|
+
this.push(message);
|
|
95
|
+
} else {
|
|
96
|
+
this.push(null);
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error instanceof Error) {
|
|
100
|
+
this.destroy(error);
|
|
101
|
+
} else {
|
|
102
|
+
this.destroy();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// js-src/kafka-client.ts
|
|
109
|
+
var KafkaClient = class {
|
|
110
|
+
/**
|
|
111
|
+
* Creates a KafkaClient instance
|
|
112
|
+
* @throws {Error} If the configuration is invalid
|
|
113
|
+
*/
|
|
114
|
+
constructor(kafkaConfiguration) {
|
|
115
|
+
this.kafkaConfiguration = kafkaConfiguration;
|
|
116
|
+
this.kafkaClientConfig = new import_js_binding.KafkaClientConfig(this.kafkaConfiguration);
|
|
117
|
+
}
|
|
118
|
+
kafkaClientConfig;
|
|
119
|
+
/**
|
|
120
|
+
* Creates a KafkaProducer instance
|
|
121
|
+
* @param {ProducerConfiguration} [producerConfiguration] - Optional producer configuration
|
|
122
|
+
* @returns {KafkaProducer} A KafkaProducer instance
|
|
123
|
+
*/
|
|
124
|
+
createProducer(producerConfiguration) {
|
|
125
|
+
if (producerConfiguration) {
|
|
126
|
+
return this.kafkaClientConfig.createProducer(producerConfiguration);
|
|
127
|
+
}
|
|
128
|
+
return this.kafkaClientConfig.createProducer({});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Creates a KafkaConsumer instance
|
|
132
|
+
* @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration
|
|
133
|
+
* @returns {KafkaConsumer} A KafkaConsumer instance
|
|
134
|
+
* @throws {Error} If the configuration is invalid
|
|
135
|
+
*/
|
|
136
|
+
createConsumer(consumerConfiguration) {
|
|
137
|
+
return this.kafkaClientConfig.createConsumer(consumerConfiguration);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Creates a KafkaStreamReadable instance
|
|
141
|
+
* @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration
|
|
142
|
+
* @returns {KafkaStreamReadable} A KafkaStreamReadable instance
|
|
143
|
+
* @throws {Error} If the configuration is invalid
|
|
144
|
+
*/
|
|
145
|
+
createStreamConsumer(consumerConfiguration) {
|
|
146
|
+
const consumer = this.kafkaClientConfig.createConsumer(consumerConfiguration);
|
|
147
|
+
return new KafkaStreamReadable(consumer);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
151
|
+
0 && (module.exports = {
|
|
152
|
+
CommitMode,
|
|
153
|
+
KafkaClient,
|
|
154
|
+
KafkaClientConfig,
|
|
155
|
+
KafkaConsumer,
|
|
156
|
+
KafkaEventName,
|
|
157
|
+
KafkaProducer,
|
|
158
|
+
KafkaStreamReadable,
|
|
159
|
+
PartitionPosition,
|
|
160
|
+
SecurityProtocol
|
|
161
|
+
});
|
|
162
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../js-src/index.ts", "../js-src/kafka-client.ts", "../js-src/kafka-stream-readable.ts"],
|
|
4
|
+
"sourcesContent": ["export type {\n ConsumerConfiguration,\n KafkaConfiguration,\n KafkaCrabError,\n KafkaEvent,\n KafkaEventPayload,\n Message,\n MessageProducer,\n OffsetModel,\n PartitionOffset,\n ProducerConfiguration,\n ProducerRecord,\n RecordMetadata,\n RetryStrategy,\n TopicPartition,\n TopicPartitionConfig,\n} from '../js-binding.js'\n\nexport {\n CommitMode,\n KafkaClientConfig,\n KafkaConsumer,\n KafkaEventName,\n KafkaProducer,\n PartitionPosition,\n SecurityProtocol,\n} from '../js-binding.js'\nexport { KafkaClient } from './kafka-client.js'\nexport { KafkaStreamReadable } from './kafka-stream-readable.js'\n", "import { ConsumerConfiguration, KafkaClientConfig, KafkaConfiguration, ProducerConfiguration } from '../js-binding.js'\n\nimport { KafkaStreamReadable } from './kafka-stream-readable.js'\n\n/**\n * KafkaClient class\n */\nexport class KafkaClient {\n private readonly kafkaClientConfig: KafkaClientConfig\n /**\n * Creates a KafkaClient instance\n * @throws {Error} If the configuration is invalid\n */\n constructor(private readonly kafkaConfiguration: KafkaConfiguration) {\n this.kafkaClientConfig = new KafkaClientConfig(this.kafkaConfiguration)\n }\n\n /**\n * Creates a KafkaProducer instance\n * @param {ProducerConfiguration} [producerConfiguration] - Optional producer configuration\n * @returns {KafkaProducer} A KafkaProducer instance\n */\n createProducer(producerConfiguration: ProducerConfiguration) {\n if (producerConfiguration) {\n return this.kafkaClientConfig.createProducer(producerConfiguration)\n }\n return this.kafkaClientConfig.createProducer({})\n }\n\n /**\n * Creates a KafkaConsumer instance\n * @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration\n * @returns {KafkaConsumer} A KafkaConsumer instance\n * @throws {Error} If the configuration is invalid\n */\n createConsumer(consumerConfiguration: ConsumerConfiguration) {\n return this.kafkaClientConfig.createConsumer(consumerConfiguration)\n }\n\n /**\n * Creates a KafkaStreamReadable instance\n * @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration\n * @returns {KafkaStreamReadable} A KafkaStreamReadable instance\n * @throws {Error} If the configuration is invalid\n */\n createStreamConsumer(consumerConfiguration: ConsumerConfiguration) {\n const consumer = this.kafkaClientConfig.createConsumer(consumerConfiguration)\n return new KafkaStreamReadable(consumer)\n }\n}\n", "import { Readable } from 'stream'\n\nimport { KafkaConsumer, OffsetModel, TopicPartitionConfig } from '../js-binding.js'\nimport { CommitMode } from '../js-binding.js'\n\n/**\n * KafkaStreamReadable class\n * @extends Readable\n */\nexport class KafkaStreamReadable extends Readable {\n /**\n * Creates a KafkaStreamReadable instance\n */\n constructor(private readonly kafkaConsumer: KafkaConsumer) {\n super({ objectMode: true })\n if (!kafkaConsumer) {\n throw new Error('A valid KafkaConsumer instance is required.')\n }\n }\n\n /**\n * Subscribes to topics\n */\n async subscribe(topics: string | Array<TopicPartitionConfig>) {\n if (!topics || (Array.isArray(topics) && topics.length === 0)) {\n throw new Error('Topics must be a non-empty string or array.')\n }\n await this.kafkaConsumer.subscribe(topics)\n }\n\n seek(topic: string, partition: number, offsetModel: OffsetModel, timeout?: number | undefined) {\n this.kafkaConsumer.seek(topic, partition, offsetModel, timeout)\n }\n\n commit(topic: string, partition: number, offset: number, commit: CommitMode) {\n this.kafkaConsumer.commit(topic, partition, offset, commit)\n }\n\n /**\n * Unsubscribe from topics\n */\n unsubscribe() {\n this.kafkaConsumer.unsubscribe()\n }\n\n /**\n * Disconnects the Kafka consumer\n */\n async disconnect() {\n await this.kafkaConsumer.disconnect()\n }\n\n /**\n * Returns the raw Kafka consumer\n * @returns {KafkaConsumer} The Kafka consumer instance\n */\n rawConsumer() {\n return this.kafkaConsumer\n }\n\n /**\n * Internal method called by the Readable stream to fetch data\n * @private\n */\n async _read() {\n try {\n const message = await this.kafkaConsumer.recv() // Call the napi-rs method\n if (message) {\n this.push(message) // Push message into the stream\n } else {\n this.push(null) // No more data, end of stream\n }\n } catch (error) {\n if (error instanceof Error) {\n this.destroy(error)\n } else {\n this.destroy()\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,IAAAA,qBAQO;;;AC1BP,wBAAoG;;;ACApG,oBAAyB;AASlB,IAAM,sBAAN,cAAkC,uBAAS;AAAA;AAAA;AAAA;AAAA,EAIhD,YAA6B,eAA8B;AACzD,UAAM,EAAE,YAAY,KAAK,CAAC;AADC;AAE3B,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAAU,QAA8C;AAC5D,QAAI,CAAC,UAAW,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW,GAAI;AAC7D,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AACA,UAAM,KAAK,cAAc,UAAU,MAAM;AAAA,EAC3C;AAAA,EAEA,KAAK,OAAe,WAAmB,aAA0B,SAA8B;AAC7F,SAAK,cAAc,KAAK,OAAO,WAAW,aAAa,OAAO;AAAA,EAChE;AAAA,EAEA,OAAO,OAAe,WAAmB,QAAgB,QAAoB;AAC3E,SAAK,cAAc,OAAO,OAAO,WAAW,QAAQ,MAAM;AAAA,EAC5D;AAAA;AAAA;AAAA;AAAA,EAKA,cAAc;AACZ,SAAK,cAAc,YAAY;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAAa;AACjB,UAAM,KAAK,cAAc,WAAW;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAc;AACZ,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,QAAQ;AACZ,QAAI;AACF,YAAM,UAAU,MAAM,KAAK,cAAc,KAAK;AAC9C,UAAI,SAAS;AACX,aAAK,KAAK,OAAO;AAAA,MACnB,OAAO;AACL,aAAK,KAAK,IAAI;AAAA,MAChB;AAAA,IACF,SAAS,OAAO;AACd,UAAI,iBAAiB,OAAO;AAC1B,aAAK,QAAQ,KAAK;AAAA,MACpB,OAAO;AACL,aAAK,QAAQ;AAAA,MACf;AAAA,IACF;AAAA,EACF;AACF;;;ADzEO,IAAM,cAAN,MAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,YAA6B,oBAAwC;AAAxC;AAC3B,SAAK,oBAAoB,IAAI,oCAAkB,KAAK,kBAAkB;AAAA,EACxE;AAAA,EAPiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcjB,eAAe,uBAA8C;AAC3D,QAAI,uBAAuB;AACzB,aAAO,KAAK,kBAAkB,eAAe,qBAAqB;AAAA,IACpE;AACA,WAAO,KAAK,kBAAkB,eAAe,CAAC,CAAC;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,eAAe,uBAA8C;AAC3D,WAAO,KAAK,kBAAkB,eAAe,qBAAqB;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,qBAAqB,uBAA8C;AACjE,UAAM,WAAW,KAAK,kBAAkB,eAAe,qBAAqB;AAC5E,WAAO,IAAI,oBAAoB,QAAQ;AAAA,EACzC;AACF;",
|
|
6
|
+
"names": ["import_js_binding"]
|
|
7
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ConsumerConfiguration, KafkaConfiguration, KafkaCrabError, KafkaEvent, KafkaEventPayload, Message, MessageProducer, OffsetModel, PartitionOffset, ProducerConfiguration, ProducerRecord, RecordMetadata, RetryStrategy, TopicPartition, TopicPartitionConfig, } from '
|
|
2
|
-
export { CommitMode, KafkaClientConfig, KafkaConsumer, KafkaEventName, KafkaProducer, PartitionPosition, SecurityProtocol, } from '
|
|
3
|
-
export { KafkaClient } from './kafka-client';
|
|
4
|
-
export { KafkaStreamReadable } from './kafka-stream-readable';
|
|
1
|
+
export type { ConsumerConfiguration, KafkaConfiguration, KafkaCrabError, KafkaEvent, KafkaEventPayload, Message, MessageProducer, OffsetModel, PartitionOffset, ProducerConfiguration, ProducerRecord, RecordMetadata, RetryStrategy, TopicPartition, TopicPartitionConfig, } from '../js-binding.js';
|
|
2
|
+
export { CommitMode, KafkaClientConfig, KafkaConsumer, KafkaEventName, KafkaProducer, PartitionPosition, SecurityProtocol, } from '../js-binding.js';
|
|
3
|
+
export { KafkaClient } from './kafka-client.js';
|
|
4
|
+
export { KafkaStreamReadable } from './kafka-stream-readable.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// js-src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
CommitMode,
|
|
4
|
+
KafkaClientConfig as KafkaClientConfig2,
|
|
5
|
+
KafkaConsumer,
|
|
6
|
+
KafkaEventName,
|
|
7
|
+
KafkaProducer,
|
|
8
|
+
PartitionPosition,
|
|
9
|
+
SecurityProtocol
|
|
10
|
+
} from "../js-binding.js";
|
|
11
|
+
|
|
12
|
+
// js-src/kafka-client.ts
|
|
13
|
+
import { KafkaClientConfig } from "../js-binding.js";
|
|
14
|
+
|
|
15
|
+
// js-src/kafka-stream-readable.ts
|
|
16
|
+
import { Readable } from "stream";
|
|
17
|
+
var KafkaStreamReadable = class extends Readable {
|
|
18
|
+
/**
|
|
19
|
+
* Creates a KafkaStreamReadable instance
|
|
20
|
+
*/
|
|
21
|
+
constructor(kafkaConsumer) {
|
|
22
|
+
super({ objectMode: true });
|
|
23
|
+
this.kafkaConsumer = kafkaConsumer;
|
|
24
|
+
if (!kafkaConsumer) {
|
|
25
|
+
throw new Error("A valid KafkaConsumer instance is required.");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Subscribes to topics
|
|
30
|
+
*/
|
|
31
|
+
async subscribe(topics) {
|
|
32
|
+
if (!topics || Array.isArray(topics) && topics.length === 0) {
|
|
33
|
+
throw new Error("Topics must be a non-empty string or array.");
|
|
34
|
+
}
|
|
35
|
+
await this.kafkaConsumer.subscribe(topics);
|
|
36
|
+
}
|
|
37
|
+
seek(topic, partition, offsetModel, timeout) {
|
|
38
|
+
this.kafkaConsumer.seek(topic, partition, offsetModel, timeout);
|
|
39
|
+
}
|
|
40
|
+
commit(topic, partition, offset, commit) {
|
|
41
|
+
this.kafkaConsumer.commit(topic, partition, offset, commit);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Unsubscribe from topics
|
|
45
|
+
*/
|
|
46
|
+
unsubscribe() {
|
|
47
|
+
this.kafkaConsumer.unsubscribe();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Disconnects the Kafka consumer
|
|
51
|
+
*/
|
|
52
|
+
async disconnect() {
|
|
53
|
+
await this.kafkaConsumer.disconnect();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns the raw Kafka consumer
|
|
57
|
+
* @returns {KafkaConsumer} The Kafka consumer instance
|
|
58
|
+
*/
|
|
59
|
+
rawConsumer() {
|
|
60
|
+
return this.kafkaConsumer;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Internal method called by the Readable stream to fetch data
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
async _read() {
|
|
67
|
+
try {
|
|
68
|
+
const message = await this.kafkaConsumer.recv();
|
|
69
|
+
if (message) {
|
|
70
|
+
this.push(message);
|
|
71
|
+
} else {
|
|
72
|
+
this.push(null);
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error instanceof Error) {
|
|
76
|
+
this.destroy(error);
|
|
77
|
+
} else {
|
|
78
|
+
this.destroy();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// js-src/kafka-client.ts
|
|
85
|
+
var KafkaClient = class {
|
|
86
|
+
/**
|
|
87
|
+
* Creates a KafkaClient instance
|
|
88
|
+
* @throws {Error} If the configuration is invalid
|
|
89
|
+
*/
|
|
90
|
+
constructor(kafkaConfiguration) {
|
|
91
|
+
this.kafkaConfiguration = kafkaConfiguration;
|
|
92
|
+
this.kafkaClientConfig = new KafkaClientConfig(this.kafkaConfiguration);
|
|
93
|
+
}
|
|
94
|
+
kafkaClientConfig;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a KafkaProducer instance
|
|
97
|
+
* @param {ProducerConfiguration} [producerConfiguration] - Optional producer configuration
|
|
98
|
+
* @returns {KafkaProducer} A KafkaProducer instance
|
|
99
|
+
*/
|
|
100
|
+
createProducer(producerConfiguration) {
|
|
101
|
+
if (producerConfiguration) {
|
|
102
|
+
return this.kafkaClientConfig.createProducer(producerConfiguration);
|
|
103
|
+
}
|
|
104
|
+
return this.kafkaClientConfig.createProducer({});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Creates a KafkaConsumer instance
|
|
108
|
+
* @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration
|
|
109
|
+
* @returns {KafkaConsumer} A KafkaConsumer instance
|
|
110
|
+
* @throws {Error} If the configuration is invalid
|
|
111
|
+
*/
|
|
112
|
+
createConsumer(consumerConfiguration) {
|
|
113
|
+
return this.kafkaClientConfig.createConsumer(consumerConfiguration);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Creates a KafkaStreamReadable instance
|
|
117
|
+
* @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration
|
|
118
|
+
* @returns {KafkaStreamReadable} A KafkaStreamReadable instance
|
|
119
|
+
* @throws {Error} If the configuration is invalid
|
|
120
|
+
*/
|
|
121
|
+
createStreamConsumer(consumerConfiguration) {
|
|
122
|
+
const consumer = this.kafkaClientConfig.createConsumer(consumerConfiguration);
|
|
123
|
+
return new KafkaStreamReadable(consumer);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
export {
|
|
127
|
+
CommitMode,
|
|
128
|
+
KafkaClient,
|
|
129
|
+
KafkaClientConfig2 as KafkaClientConfig,
|
|
130
|
+
KafkaConsumer,
|
|
131
|
+
KafkaEventName,
|
|
132
|
+
KafkaProducer,
|
|
133
|
+
KafkaStreamReadable,
|
|
134
|
+
PartitionPosition,
|
|
135
|
+
SecurityProtocol
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../js-src/index.ts", "../js-src/kafka-client.ts", "../js-src/kafka-stream-readable.ts"],
|
|
4
|
+
"sourcesContent": ["export type {\n ConsumerConfiguration,\n KafkaConfiguration,\n KafkaCrabError,\n KafkaEvent,\n KafkaEventPayload,\n Message,\n MessageProducer,\n OffsetModel,\n PartitionOffset,\n ProducerConfiguration,\n ProducerRecord,\n RecordMetadata,\n RetryStrategy,\n TopicPartition,\n TopicPartitionConfig,\n} from '../js-binding.js'\n\nexport {\n CommitMode,\n KafkaClientConfig,\n KafkaConsumer,\n KafkaEventName,\n KafkaProducer,\n PartitionPosition,\n SecurityProtocol,\n} from '../js-binding.js'\nexport { KafkaClient } from './kafka-client.js'\nexport { KafkaStreamReadable } from './kafka-stream-readable.js'\n", "import { ConsumerConfiguration, KafkaClientConfig, KafkaConfiguration, ProducerConfiguration } from '../js-binding.js'\n\nimport { KafkaStreamReadable } from './kafka-stream-readable.js'\n\n/**\n * KafkaClient class\n */\nexport class KafkaClient {\n private readonly kafkaClientConfig: KafkaClientConfig\n /**\n * Creates a KafkaClient instance\n * @throws {Error} If the configuration is invalid\n */\n constructor(private readonly kafkaConfiguration: KafkaConfiguration) {\n this.kafkaClientConfig = new KafkaClientConfig(this.kafkaConfiguration)\n }\n\n /**\n * Creates a KafkaProducer instance\n * @param {ProducerConfiguration} [producerConfiguration] - Optional producer configuration\n * @returns {KafkaProducer} A KafkaProducer instance\n */\n createProducer(producerConfiguration: ProducerConfiguration) {\n if (producerConfiguration) {\n return this.kafkaClientConfig.createProducer(producerConfiguration)\n }\n return this.kafkaClientConfig.createProducer({})\n }\n\n /**\n * Creates a KafkaConsumer instance\n * @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration\n * @returns {KafkaConsumer} A KafkaConsumer instance\n * @throws {Error} If the configuration is invalid\n */\n createConsumer(consumerConfiguration: ConsumerConfiguration) {\n return this.kafkaClientConfig.createConsumer(consumerConfiguration)\n }\n\n /**\n * Creates a KafkaStreamReadable instance\n * @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration\n * @returns {KafkaStreamReadable} A KafkaStreamReadable instance\n * @throws {Error} If the configuration is invalid\n */\n createStreamConsumer(consumerConfiguration: ConsumerConfiguration) {\n const consumer = this.kafkaClientConfig.createConsumer(consumerConfiguration)\n return new KafkaStreamReadable(consumer)\n }\n}\n", "import { Readable } from 'stream'\n\nimport { KafkaConsumer, OffsetModel, TopicPartitionConfig } from '../js-binding.js'\nimport { CommitMode } from '../js-binding.js'\n\n/**\n * KafkaStreamReadable class\n * @extends Readable\n */\nexport class KafkaStreamReadable extends Readable {\n /**\n * Creates a KafkaStreamReadable instance\n */\n constructor(private readonly kafkaConsumer: KafkaConsumer) {\n super({ objectMode: true })\n if (!kafkaConsumer) {\n throw new Error('A valid KafkaConsumer instance is required.')\n }\n }\n\n /**\n * Subscribes to topics\n */\n async subscribe(topics: string | Array<TopicPartitionConfig>) {\n if (!topics || (Array.isArray(topics) && topics.length === 0)) {\n throw new Error('Topics must be a non-empty string or array.')\n }\n await this.kafkaConsumer.subscribe(topics)\n }\n\n seek(topic: string, partition: number, offsetModel: OffsetModel, timeout?: number | undefined) {\n this.kafkaConsumer.seek(topic, partition, offsetModel, timeout)\n }\n\n commit(topic: string, partition: number, offset: number, commit: CommitMode) {\n this.kafkaConsumer.commit(topic, partition, offset, commit)\n }\n\n /**\n * Unsubscribe from topics\n */\n unsubscribe() {\n this.kafkaConsumer.unsubscribe()\n }\n\n /**\n * Disconnects the Kafka consumer\n */\n async disconnect() {\n await this.kafkaConsumer.disconnect()\n }\n\n /**\n * Returns the raw Kafka consumer\n * @returns {KafkaConsumer} The Kafka consumer instance\n */\n rawConsumer() {\n return this.kafkaConsumer\n }\n\n /**\n * Internal method called by the Readable stream to fetch data\n * @private\n */\n async _read() {\n try {\n const message = await this.kafkaConsumer.recv() // Call the napi-rs method\n if (message) {\n this.push(message) // Push message into the stream\n } else {\n this.push(null) // No more data, end of stream\n }\n } catch (error) {\n if (error instanceof Error) {\n this.destroy(error)\n } else {\n this.destroy()\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAkBA;AAAA,EACE;AAAA,EACA,qBAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;AC1BP,SAAgC,yBAAoE;;;ACApG,SAAS,gBAAgB;AASlB,IAAM,sBAAN,cAAkC,SAAS;AAAA;AAAA;AAAA;AAAA,EAIhD,YAA6B,eAA8B;AACzD,UAAM,EAAE,YAAY,KAAK,CAAC;AADC;AAE3B,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAAU,QAA8C;AAC5D,QAAI,CAAC,UAAW,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW,GAAI;AAC7D,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AACA,UAAM,KAAK,cAAc,UAAU,MAAM;AAAA,EAC3C;AAAA,EAEA,KAAK,OAAe,WAAmB,aAA0B,SAA8B;AAC7F,SAAK,cAAc,KAAK,OAAO,WAAW,aAAa,OAAO;AAAA,EAChE;AAAA,EAEA,OAAO,OAAe,WAAmB,QAAgB,QAAoB;AAC3E,SAAK,cAAc,OAAO,OAAO,WAAW,QAAQ,MAAM;AAAA,EAC5D;AAAA;AAAA;AAAA;AAAA,EAKA,cAAc;AACZ,SAAK,cAAc,YAAY;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAAa;AACjB,UAAM,KAAK,cAAc,WAAW;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAc;AACZ,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,QAAQ;AACZ,QAAI;AACF,YAAM,UAAU,MAAM,KAAK,cAAc,KAAK;AAC9C,UAAI,SAAS;AACX,aAAK,KAAK,OAAO;AAAA,MACnB,OAAO;AACL,aAAK,KAAK,IAAI;AAAA,MAChB;AAAA,IACF,SAAS,OAAO;AACd,UAAI,iBAAiB,OAAO;AAC1B,aAAK,QAAQ,KAAK;AAAA,MACpB,OAAO;AACL,aAAK,QAAQ;AAAA,MACf;AAAA,IACF;AAAA,EACF;AACF;;;ADzEO,IAAM,cAAN,MAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,YAA6B,oBAAwC;AAAxC;AAC3B,SAAK,oBAAoB,IAAI,kBAAkB,KAAK,kBAAkB;AAAA,EACxE;AAAA,EAPiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcjB,eAAe,uBAA8C;AAC3D,QAAI,uBAAuB;AACzB,aAAO,KAAK,kBAAkB,eAAe,qBAAqB;AAAA,IACpE;AACA,WAAO,KAAK,kBAAkB,eAAe,CAAC,CAAC;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,eAAe,uBAA8C;AAC3D,WAAO,KAAK,kBAAkB,eAAe,qBAAqB;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,qBAAqB,uBAA8C;AACjE,UAAM,WAAW,KAAK,kBAAkB,eAAe,qBAAqB;AAC5E,WAAO,IAAI,oBAAoB,QAAQ;AAAA,EACzC;AACF;",
|
|
6
|
+
"names": ["KafkaClientConfig"]
|
|
7
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConsumerConfiguration, KafkaConfiguration, ProducerConfiguration } from '
|
|
2
|
-
import { KafkaStreamReadable } from './kafka-stream-readable';
|
|
1
|
+
import { ConsumerConfiguration, KafkaConfiguration, ProducerConfiguration } from '../js-binding.js';
|
|
2
|
+
import { KafkaStreamReadable } from './kafka-stream-readable.js';
|
|
3
3
|
/**
|
|
4
4
|
* KafkaClient class
|
|
5
5
|
*/
|
|
@@ -16,14 +16,14 @@ export declare class KafkaClient {
|
|
|
16
16
|
* @param {ProducerConfiguration} [producerConfiguration] - Optional producer configuration
|
|
17
17
|
* @returns {KafkaProducer} A KafkaProducer instance
|
|
18
18
|
*/
|
|
19
|
-
createProducer(producerConfiguration: ProducerConfiguration): import("
|
|
19
|
+
createProducer(producerConfiguration: ProducerConfiguration): import("../js-binding.js").KafkaProducer;
|
|
20
20
|
/**
|
|
21
21
|
* Creates a KafkaConsumer instance
|
|
22
22
|
* @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration
|
|
23
23
|
* @returns {KafkaConsumer} A KafkaConsumer instance
|
|
24
24
|
* @throws {Error} If the configuration is invalid
|
|
25
25
|
*/
|
|
26
|
-
createConsumer(consumerConfiguration: ConsumerConfiguration): import("
|
|
26
|
+
createConsumer(consumerConfiguration: ConsumerConfiguration): import("../js-binding.js").KafkaConsumer;
|
|
27
27
|
/**
|
|
28
28
|
* Creates a KafkaStreamReadable instance
|
|
29
29
|
* @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { KafkaConsumer, OffsetModel, TopicPartitionConfig } from '../js-binding.js';
|
|
3
|
+
import { CommitMode } from '../js-binding.js';
|
|
4
4
|
/**
|
|
5
5
|
* KafkaStreamReadable class
|
|
6
6
|
* @extends Readable
|
package/js-binding.cjs
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const { createRequire } = require('node:module')
|
|
7
|
+
require = createRequire(__filename)
|
|
8
|
+
|
|
9
|
+
const { readFileSync } = require('node:fs')
|
|
10
|
+
let nativeBinding = null
|
|
11
|
+
const loadErrors = []
|
|
12
|
+
|
|
13
|
+
const isMusl = () => {
|
|
14
|
+
let musl = false
|
|
15
|
+
if (process.platform === 'linux') {
|
|
16
|
+
musl = isMuslFromFilesystem()
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromReport()
|
|
19
|
+
}
|
|
20
|
+
if (musl === null) {
|
|
21
|
+
musl = isMuslFromChildProcess()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return musl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
28
|
+
|
|
29
|
+
const isMuslFromFilesystem = () => {
|
|
30
|
+
try {
|
|
31
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
32
|
+
} catch {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isMuslFromReport = () => {
|
|
38
|
+
let report = null
|
|
39
|
+
if (typeof process.report?.getReport === 'function') {
|
|
40
|
+
process.report.excludeNetwork = true
|
|
41
|
+
report = process.report.getReport()
|
|
42
|
+
}
|
|
43
|
+
if (!report) {
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
50
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const isMuslFromChildProcess = () => {
|
|
58
|
+
try {
|
|
59
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function requireNative() {
|
|
67
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
68
|
+
try {
|
|
69
|
+
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
loadErrors.push(err);
|
|
72
|
+
}
|
|
73
|
+
} else if (process.platform === 'android') {
|
|
74
|
+
if (process.arch === 'arm64') {
|
|
75
|
+
try {
|
|
76
|
+
return require('./kafka-crab-js.android-arm64.node')
|
|
77
|
+
} catch (e) {
|
|
78
|
+
loadErrors.push(e)
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return require('kafka-crab-js-android-arm64')
|
|
82
|
+
} catch (e) {
|
|
83
|
+
loadErrors.push(e)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
} else if (process.arch === 'arm') {
|
|
87
|
+
try {
|
|
88
|
+
return require('./kafka-crab-js.android-arm-eabi.node')
|
|
89
|
+
} catch (e) {
|
|
90
|
+
loadErrors.push(e)
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
return require('kafka-crab-js-android-arm-eabi')
|
|
94
|
+
} catch (e) {
|
|
95
|
+
loadErrors.push(e)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
} else {
|
|
99
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
100
|
+
}
|
|
101
|
+
} else if (process.platform === 'win32') {
|
|
102
|
+
if (process.arch === 'x64') {
|
|
103
|
+
try {
|
|
104
|
+
return require('./kafka-crab-js.win32-x64-msvc.node')
|
|
105
|
+
} catch (e) {
|
|
106
|
+
loadErrors.push(e)
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
return require('kafka-crab-js-win32-x64-msvc')
|
|
110
|
+
} catch (e) {
|
|
111
|
+
loadErrors.push(e)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
} else if (process.arch === 'ia32') {
|
|
115
|
+
try {
|
|
116
|
+
return require('./kafka-crab-js.win32-ia32-msvc.node')
|
|
117
|
+
} catch (e) {
|
|
118
|
+
loadErrors.push(e)
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
return require('kafka-crab-js-win32-ia32-msvc')
|
|
122
|
+
} catch (e) {
|
|
123
|
+
loadErrors.push(e)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
} else if (process.arch === 'arm64') {
|
|
127
|
+
try {
|
|
128
|
+
return require('./kafka-crab-js.win32-arm64-msvc.node')
|
|
129
|
+
} catch (e) {
|
|
130
|
+
loadErrors.push(e)
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
return require('kafka-crab-js-win32-arm64-msvc')
|
|
134
|
+
} catch (e) {
|
|
135
|
+
loadErrors.push(e)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
} else {
|
|
139
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
140
|
+
}
|
|
141
|
+
} else if (process.platform === 'darwin') {
|
|
142
|
+
try {
|
|
143
|
+
return require('./kafka-crab-js.darwin-universal.node')
|
|
144
|
+
} catch (e) {
|
|
145
|
+
loadErrors.push(e)
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
return require('kafka-crab-js-darwin-universal')
|
|
149
|
+
} catch (e) {
|
|
150
|
+
loadErrors.push(e)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (process.arch === 'x64') {
|
|
154
|
+
try {
|
|
155
|
+
return require('./kafka-crab-js.darwin-x64.node')
|
|
156
|
+
} catch (e) {
|
|
157
|
+
loadErrors.push(e)
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
return require('kafka-crab-js-darwin-x64')
|
|
161
|
+
} catch (e) {
|
|
162
|
+
loadErrors.push(e)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
} else if (process.arch === 'arm64') {
|
|
166
|
+
try {
|
|
167
|
+
return require('./kafka-crab-js.darwin-arm64.node')
|
|
168
|
+
} catch (e) {
|
|
169
|
+
loadErrors.push(e)
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
return require('kafka-crab-js-darwin-arm64')
|
|
173
|
+
} catch (e) {
|
|
174
|
+
loadErrors.push(e)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
} else {
|
|
178
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
179
|
+
}
|
|
180
|
+
} else if (process.platform === 'freebsd') {
|
|
181
|
+
if (process.arch === 'x64') {
|
|
182
|
+
try {
|
|
183
|
+
return require('./kafka-crab-js.freebsd-x64.node')
|
|
184
|
+
} catch (e) {
|
|
185
|
+
loadErrors.push(e)
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
return require('kafka-crab-js-freebsd-x64')
|
|
189
|
+
} catch (e) {
|
|
190
|
+
loadErrors.push(e)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
} else if (process.arch === 'arm64') {
|
|
194
|
+
try {
|
|
195
|
+
return require('./kafka-crab-js.freebsd-arm64.node')
|
|
196
|
+
} catch (e) {
|
|
197
|
+
loadErrors.push(e)
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
return require('kafka-crab-js-freebsd-arm64')
|
|
201
|
+
} catch (e) {
|
|
202
|
+
loadErrors.push(e)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
} else {
|
|
206
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
207
|
+
}
|
|
208
|
+
} else if (process.platform === 'linux') {
|
|
209
|
+
if (process.arch === 'x64') {
|
|
210
|
+
if (isMusl()) {
|
|
211
|
+
try {
|
|
212
|
+
return require('./kafka-crab-js.linux-x64-musl.node')
|
|
213
|
+
} catch (e) {
|
|
214
|
+
loadErrors.push(e)
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
return require('kafka-crab-js-linux-x64-musl')
|
|
218
|
+
} catch (e) {
|
|
219
|
+
loadErrors.push(e)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
} else {
|
|
223
|
+
try {
|
|
224
|
+
return require('./kafka-crab-js.linux-x64-gnu.node')
|
|
225
|
+
} catch (e) {
|
|
226
|
+
loadErrors.push(e)
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
return require('kafka-crab-js-linux-x64-gnu')
|
|
230
|
+
} catch (e) {
|
|
231
|
+
loadErrors.push(e)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
} else if (process.arch === 'arm64') {
|
|
236
|
+
if (isMusl()) {
|
|
237
|
+
try {
|
|
238
|
+
return require('./kafka-crab-js.linux-arm64-musl.node')
|
|
239
|
+
} catch (e) {
|
|
240
|
+
loadErrors.push(e)
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
return require('kafka-crab-js-linux-arm64-musl')
|
|
244
|
+
} catch (e) {
|
|
245
|
+
loadErrors.push(e)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
} else {
|
|
249
|
+
try {
|
|
250
|
+
return require('./kafka-crab-js.linux-arm64-gnu.node')
|
|
251
|
+
} catch (e) {
|
|
252
|
+
loadErrors.push(e)
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
return require('kafka-crab-js-linux-arm64-gnu')
|
|
256
|
+
} catch (e) {
|
|
257
|
+
loadErrors.push(e)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
}
|
|
261
|
+
} else if (process.arch === 'arm') {
|
|
262
|
+
if (isMusl()) {
|
|
263
|
+
try {
|
|
264
|
+
return require('./kafka-crab-js.linux-arm-musleabihf.node')
|
|
265
|
+
} catch (e) {
|
|
266
|
+
loadErrors.push(e)
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
return require('kafka-crab-js-linux-arm-musleabihf')
|
|
270
|
+
} catch (e) {
|
|
271
|
+
loadErrors.push(e)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
} else {
|
|
275
|
+
try {
|
|
276
|
+
return require('./kafka-crab-js.linux-arm-gnueabihf.node')
|
|
277
|
+
} catch (e) {
|
|
278
|
+
loadErrors.push(e)
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
return require('kafka-crab-js-linux-arm-gnueabihf')
|
|
282
|
+
} catch (e) {
|
|
283
|
+
loadErrors.push(e)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
}
|
|
287
|
+
} else if (process.arch === 'riscv64') {
|
|
288
|
+
if (isMusl()) {
|
|
289
|
+
try {
|
|
290
|
+
return require('./kafka-crab-js.linux-riscv64-musl.node')
|
|
291
|
+
} catch (e) {
|
|
292
|
+
loadErrors.push(e)
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
return require('kafka-crab-js-linux-riscv64-musl')
|
|
296
|
+
} catch (e) {
|
|
297
|
+
loadErrors.push(e)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
} else {
|
|
301
|
+
try {
|
|
302
|
+
return require('./kafka-crab-js.linux-riscv64-gnu.node')
|
|
303
|
+
} catch (e) {
|
|
304
|
+
loadErrors.push(e)
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
return require('kafka-crab-js-linux-riscv64-gnu')
|
|
308
|
+
} catch (e) {
|
|
309
|
+
loadErrors.push(e)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
} else if (process.arch === 'ppc64') {
|
|
314
|
+
try {
|
|
315
|
+
return require('./kafka-crab-js.linux-ppc64-gnu.node')
|
|
316
|
+
} catch (e) {
|
|
317
|
+
loadErrors.push(e)
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
return require('kafka-crab-js-linux-ppc64-gnu')
|
|
321
|
+
} catch (e) {
|
|
322
|
+
loadErrors.push(e)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
} else if (process.arch === 's390x') {
|
|
326
|
+
try {
|
|
327
|
+
return require('./kafka-crab-js.linux-s390x-gnu.node')
|
|
328
|
+
} catch (e) {
|
|
329
|
+
loadErrors.push(e)
|
|
330
|
+
}
|
|
331
|
+
try {
|
|
332
|
+
return require('kafka-crab-js-linux-s390x-gnu')
|
|
333
|
+
} catch (e) {
|
|
334
|
+
loadErrors.push(e)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
} else {
|
|
338
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
nativeBinding = requireNative()
|
|
346
|
+
|
|
347
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
348
|
+
try {
|
|
349
|
+
nativeBinding = require('./kafka-crab-js.wasi.cjs')
|
|
350
|
+
} catch (err) {
|
|
351
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
352
|
+
loadErrors.push(err)
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (!nativeBinding) {
|
|
356
|
+
try {
|
|
357
|
+
nativeBinding = require('kafka-crab-js-wasm32-wasi')
|
|
358
|
+
} catch (err) {
|
|
359
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
360
|
+
loadErrors.push(err)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (!nativeBinding) {
|
|
367
|
+
if (loadErrors.length > 0) {
|
|
368
|
+
// TODO Link to documentation with potential fixes
|
|
369
|
+
// - The package owner could build/publish bindings for this arch
|
|
370
|
+
// - The user may need to bundle the correct files
|
|
371
|
+
// - The user may need to re-install node_modules to get new packages
|
|
372
|
+
throw new Error('Failed to load native binding', { cause: loadErrors })
|
|
373
|
+
}
|
|
374
|
+
throw new Error(`Failed to load native binding`)
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
module.exports.KafkaClientConfig = nativeBinding.KafkaClientConfig
|
|
378
|
+
module.exports.KafkaConsumer = nativeBinding.KafkaConsumer
|
|
379
|
+
module.exports.KafkaProducer = nativeBinding.KafkaProducer
|
|
380
|
+
module.exports.CommitMode = nativeBinding.CommitMode
|
|
381
|
+
module.exports.KafkaEventName = nativeBinding.KafkaEventName
|
|
382
|
+
module.exports.PartitionPosition = nativeBinding.PartitionPosition
|
|
383
|
+
module.exports.SecurityProtocol = nativeBinding.SecurityProtocol
|
package/js-binding.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kafka-crab-js",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.4.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=20"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
7
15
|
"files": [
|
|
8
|
-
"
|
|
9
|
-
"index.js",
|
|
10
|
-
"kafka-client.js",
|
|
11
|
-
"kafka-client.d.ts",
|
|
12
|
-
"kafka-stream-readable.js",
|
|
13
|
-
"kafka-stream-readable.d.ts",
|
|
16
|
+
"dist",
|
|
14
17
|
"js-binding.js",
|
|
15
|
-
"js-binding.d.ts"
|
|
18
|
+
"js-binding.d.ts",
|
|
19
|
+
"js-binding.cjs"
|
|
16
20
|
],
|
|
17
21
|
"napi": {
|
|
18
22
|
"binaryName": "kafka-crab-js",
|
|
@@ -42,33 +46,36 @@
|
|
|
42
46
|
"devDependencies": {
|
|
43
47
|
"@faker-js/faker": "^9.7.0",
|
|
44
48
|
"@napi-rs/cli": "^3.0.0-alpha.78",
|
|
45
|
-
"@types/
|
|
49
|
+
"@types/copyfiles": "^2.4.4",
|
|
50
|
+
"@types/node": "^22.15.12",
|
|
51
|
+
"copyfiles": "^2.4.1",
|
|
46
52
|
"dprint": "^0.49.1",
|
|
53
|
+
"esbuild": "^0.25.4",
|
|
47
54
|
"nanoid": "^5.1",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"rimraf": "^6.0.1"
|
|
55
|
+
"oxlint": "^0.16.9",
|
|
56
|
+
"rimraf": "^6.0.1",
|
|
57
|
+
"typescript": "^5.8.3"
|
|
52
58
|
},
|
|
53
59
|
"scripts": {
|
|
54
60
|
"artifacts": "napi artifacts",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
61
|
+
"prebuild": "rimraf dist",
|
|
62
|
+
"build": "node build.mjs",
|
|
63
|
+
"postbuild": "tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
57
64
|
"build:debug": "napi build --platform",
|
|
58
65
|
"prepublishOnly": "napi prepublish -t npm",
|
|
59
66
|
"test": "node --test __test__/*.test.*",
|
|
60
67
|
"test:integration": "node --test __test__/integration/*.test.*",
|
|
61
68
|
"version": "napi version",
|
|
62
69
|
"fmt": "dprint fmt",
|
|
63
|
-
"lint": "
|
|
70
|
+
"lint": "oxlint ."
|
|
64
71
|
},
|
|
65
72
|
"packageManager": "pnpm@10.10.0",
|
|
66
73
|
"optionalDependencies": {
|
|
67
|
-
"kafka-crab-js-darwin-x64": "1.4.
|
|
68
|
-
"kafka-crab-js-darwin-arm64": "1.4.
|
|
69
|
-
"kafka-crab-js-linux-x64-gnu": "1.4.
|
|
70
|
-
"kafka-crab-js-linux-x64-musl": "1.4.
|
|
71
|
-
"kafka-crab-js-linux-arm64-gnu": "1.4.
|
|
72
|
-
"kafka-crab-js-linux-arm64-musl": "1.4.
|
|
74
|
+
"kafka-crab-js-darwin-x64": "1.4.1",
|
|
75
|
+
"kafka-crab-js-darwin-arm64": "1.4.1",
|
|
76
|
+
"kafka-crab-js-linux-x64-gnu": "1.4.1",
|
|
77
|
+
"kafka-crab-js-linux-x64-musl": "1.4.1",
|
|
78
|
+
"kafka-crab-js-linux-arm64-gnu": "1.4.1",
|
|
79
|
+
"kafka-crab-js-linux-arm64-musl": "1.4.1"
|
|
73
80
|
}
|
|
74
81
|
}
|
package/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KafkaStreamReadable = exports.KafkaClient = exports.KafkaProducer = exports.KafkaConsumer = exports.KafkaClientConfig = void 0;
|
|
4
|
-
var js_binding_1 = require("./js-binding");
|
|
5
|
-
Object.defineProperty(exports, "KafkaClientConfig", { enumerable: true, get: function () { return js_binding_1.KafkaClientConfig; } });
|
|
6
|
-
Object.defineProperty(exports, "KafkaConsumer", { enumerable: true, get: function () { return js_binding_1.KafkaConsumer; } });
|
|
7
|
-
Object.defineProperty(exports, "KafkaProducer", { enumerable: true, get: function () { return js_binding_1.KafkaProducer; } });
|
|
8
|
-
var kafka_client_1 = require("./kafka-client");
|
|
9
|
-
Object.defineProperty(exports, "KafkaClient", { enumerable: true, get: function () { return kafka_client_1.KafkaClient; } });
|
|
10
|
-
var kafka_stream_readable_1 = require("./kafka-stream-readable");
|
|
11
|
-
Object.defineProperty(exports, "KafkaStreamReadable", { enumerable: true, get: function () { return kafka_stream_readable_1.KafkaStreamReadable; } });
|
package/kafka-client.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KafkaClient = void 0;
|
|
4
|
-
const js_binding_js_1 = require("./js-binding.js");
|
|
5
|
-
const kafka_stream_readable_1 = require("./kafka-stream-readable");
|
|
6
|
-
/**
|
|
7
|
-
* KafkaClient class
|
|
8
|
-
*/
|
|
9
|
-
class KafkaClient {
|
|
10
|
-
/**
|
|
11
|
-
* Creates a KafkaClient instance
|
|
12
|
-
* @throws {Error} If the configuration is invalid
|
|
13
|
-
*/
|
|
14
|
-
constructor(kafkaConfiguration) {
|
|
15
|
-
this.kafkaConfiguration = kafkaConfiguration;
|
|
16
|
-
this.kafkaClientConfig = new js_binding_js_1.KafkaClientConfig(this.kafkaConfiguration);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Creates a KafkaProducer instance
|
|
20
|
-
* @param {ProducerConfiguration} [producerConfiguration] - Optional producer configuration
|
|
21
|
-
* @returns {KafkaProducer} A KafkaProducer instance
|
|
22
|
-
*/
|
|
23
|
-
createProducer(producerConfiguration) {
|
|
24
|
-
if (producerConfiguration) {
|
|
25
|
-
return this.kafkaClientConfig.createProducer(producerConfiguration);
|
|
26
|
-
}
|
|
27
|
-
return this.kafkaClientConfig.createProducer({});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Creates a KafkaConsumer instance
|
|
31
|
-
* @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration
|
|
32
|
-
* @returns {KafkaConsumer} A KafkaConsumer instance
|
|
33
|
-
* @throws {Error} If the configuration is invalid
|
|
34
|
-
*/
|
|
35
|
-
createConsumer(consumerConfiguration) {
|
|
36
|
-
return this.kafkaClientConfig.createConsumer(consumerConfiguration);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Creates a KafkaStreamReadable instance
|
|
40
|
-
* @param {ConsumerConfiguration} consumerConfiguration - Consumer configuration
|
|
41
|
-
* @returns {KafkaStreamReadable} A KafkaStreamReadable instance
|
|
42
|
-
* @throws {Error} If the configuration is invalid
|
|
43
|
-
*/
|
|
44
|
-
createStreamConsumer(consumerConfiguration) {
|
|
45
|
-
const consumer = this.kafkaClientConfig.createConsumer(consumerConfiguration);
|
|
46
|
-
return new kafka_stream_readable_1.KafkaStreamReadable(consumer);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.KafkaClient = KafkaClient;
|
package/kafka-stream-readable.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KafkaStreamReadable = void 0;
|
|
4
|
-
const stream_1 = require("stream");
|
|
5
|
-
/**
|
|
6
|
-
* KafkaStreamReadable class
|
|
7
|
-
* @extends Readable
|
|
8
|
-
*/
|
|
9
|
-
class KafkaStreamReadable extends stream_1.Readable {
|
|
10
|
-
/**
|
|
11
|
-
* Creates a KafkaStreamReadable instance
|
|
12
|
-
*/
|
|
13
|
-
constructor(kafkaConsumer) {
|
|
14
|
-
super({ objectMode: true });
|
|
15
|
-
this.kafkaConsumer = kafkaConsumer;
|
|
16
|
-
if (!kafkaConsumer) {
|
|
17
|
-
throw new Error('A valid KafkaConsumer instance is required.');
|
|
18
|
-
}
|
|
19
|
-
this.kafkaConsumer = kafkaConsumer;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Subscribes to topics
|
|
23
|
-
*/
|
|
24
|
-
async subscribe(topics) {
|
|
25
|
-
if (!topics || (Array.isArray(topics) && topics.length === 0)) {
|
|
26
|
-
throw new Error('Topics must be a non-empty string or array.');
|
|
27
|
-
}
|
|
28
|
-
await this.kafkaConsumer.subscribe(topics);
|
|
29
|
-
}
|
|
30
|
-
seek(topic, partition, offsetModel, timeout) {
|
|
31
|
-
this.kafkaConsumer.seek(topic, partition, offsetModel, timeout);
|
|
32
|
-
}
|
|
33
|
-
commit(topic, partition, offset, commit) {
|
|
34
|
-
this.kafkaConsumer.commit(topic, partition, offset, commit);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Unsubscribe from topics
|
|
38
|
-
*/
|
|
39
|
-
unsubscribe() {
|
|
40
|
-
this.kafkaConsumer.unsubscribe();
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Disconnects the Kafka consumer
|
|
44
|
-
*/
|
|
45
|
-
async disconnect() {
|
|
46
|
-
await this.kafkaConsumer.disconnect();
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Returns the raw Kafka consumer
|
|
50
|
-
* @returns {KafkaConsumer} The Kafka consumer instance
|
|
51
|
-
*/
|
|
52
|
-
rawConsumer() {
|
|
53
|
-
return this.kafkaConsumer;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Internal method called by the Readable stream to fetch data
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
async _read() {
|
|
60
|
-
try {
|
|
61
|
-
const message = await this.kafkaConsumer.recv(); // Call the napi-rs method
|
|
62
|
-
if (message) {
|
|
63
|
-
this.push(message); // Push message into the stream
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
this.push(null); // No more data, end of stream
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
if (error instanceof Error) {
|
|
71
|
-
this.destroy(error);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
this.destroy();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.KafkaStreamReadable = KafkaStreamReadable;
|