@thirdweb-dev/service-utils 0.8.11-nightly-879148f37e61f12e40bdfd8844189944a4df9f83-20250301054921 → 0.8.11-nightly-323e9d7a3744020c5721048e2874f7f395803092-20250302000354
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/node/kafka.js
CHANGED
@@ -22,11 +22,12 @@ class KafkaProducer {
|
|
22
22
|
writable: true,
|
23
23
|
value: void 0
|
24
24
|
});
|
25
|
-
|
25
|
+
// Use a promise to ensure `connect()` is called at most once.
|
26
|
+
Object.defineProperty(this, "connectPromise", {
|
26
27
|
enumerable: true,
|
27
28
|
configurable: true,
|
28
29
|
writable: true,
|
29
|
-
value:
|
30
|
+
value: void 0
|
30
31
|
});
|
31
32
|
const { producerName, kafkaServers, username, password, config } = options;
|
32
33
|
this.producer = new kafka_javascript_1.KafkaJS.Kafka({}).producer({
|
@@ -44,10 +45,17 @@ class KafkaProducer {
|
|
44
45
|
}
|
45
46
|
/**
|
46
47
|
* Connects the producer. Can be called explicitly at the start of your service, or will be called automatically when sending messages.
|
48
|
+
*
|
49
|
+
* A cached promise is used so this function is safe to call more than once and concurrently.
|
47
50
|
*/
|
48
51
|
async connect() {
|
49
|
-
|
50
|
-
|
52
|
+
if (!this.connectPromise) {
|
53
|
+
this.connectPromise = this.producer.connect().catch((err) => {
|
54
|
+
this.connectPromise = undefined;
|
55
|
+
throw err;
|
56
|
+
});
|
57
|
+
}
|
58
|
+
await this.connectPromise;
|
51
59
|
}
|
52
60
|
/**
|
53
61
|
* Send messages to a Kafka topic.
|
@@ -60,9 +68,7 @@ class KafkaProducer {
|
|
60
68
|
* @param messages
|
61
69
|
*/
|
62
70
|
async send(topic, messages) {
|
63
|
-
|
64
|
-
await this.connect();
|
65
|
-
}
|
71
|
+
await this.connect();
|
66
72
|
await this.producer.send({
|
67
73
|
topic,
|
68
74
|
messages: messages.map((m) => ({
|
@@ -75,14 +81,11 @@ class KafkaProducer {
|
|
75
81
|
* Useful when shutting down the service to flush in-flight events.
|
76
82
|
*/
|
77
83
|
async disconnect() {
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
await this.producer.disconnect();
|
82
|
-
}
|
83
|
-
catch { }
|
84
|
-
this.isConnected = false;
|
84
|
+
try {
|
85
|
+
await this.producer.flush();
|
86
|
+
await this.producer.disconnect();
|
85
87
|
}
|
88
|
+
catch { }
|
86
89
|
}
|
87
90
|
}
|
88
91
|
exports.KafkaProducer = KafkaProducer;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":";;;AAAA,qEAGwC;AAgBxC;;;;;;;;;;;GAWG;AACH,MAAa,aAAa;
|
1
|
+
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":";;;AAAA,qEAGwC;AAgBxC;;;;;;;;;;;GAWG;AACH,MAAa,aAAa;IAKxB,YAAY,OAgBX;QApBO;;;;;WAA2B;QACnC,8DAA8D;QACtD;;;;;WAA+B;QAmBrC,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAE3E,IAAI,CAAC,QAAQ,GAAG,IAAI,0BAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC;YAC7C,WAAW,EAAE,YAAY;YACzB,mBAAmB,EAAE,YAAY;YACjC,mBAAmB,EAAE,UAAU;YAC/B,iBAAiB,EAAE,OAAO;YAC1B,eAAe,EAAE,QAAQ;YACzB,eAAe,EAAE,QAAQ;YACzB,mBAAmB,EAAE,KAAK;YAC1B,0BAA0B,EAAE,IAAI;YAChC,uCAAuC;YACvC,GAAG,MAAM;SACV,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC1D,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;gBAChC,MAAM,GAAG,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,IAAI,CAAC,cAAc,CAAC;IAC5B,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,IAAI,CACR,KAAa,EACb,QAAmC;QAEnC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QAErB,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACvB,KAAK;YACL,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC7B,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;aACzB,CAAC,CAAC;SACJ,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACZ,CAAC;CACF;AAvFD,sCAuFC"}
|
package/dist/esm/node/kafka.js
CHANGED
@@ -19,11 +19,12 @@ export class KafkaProducer {
|
|
19
19
|
writable: true,
|
20
20
|
value: void 0
|
21
21
|
});
|
22
|
-
|
22
|
+
// Use a promise to ensure `connect()` is called at most once.
|
23
|
+
Object.defineProperty(this, "connectPromise", {
|
23
24
|
enumerable: true,
|
24
25
|
configurable: true,
|
25
26
|
writable: true,
|
26
|
-
value:
|
27
|
+
value: void 0
|
27
28
|
});
|
28
29
|
const { producerName, kafkaServers, username, password, config } = options;
|
29
30
|
this.producer = new KafkaJS.Kafka({}).producer({
|
@@ -41,10 +42,17 @@ export class KafkaProducer {
|
|
41
42
|
}
|
42
43
|
/**
|
43
44
|
* Connects the producer. Can be called explicitly at the start of your service, or will be called automatically when sending messages.
|
45
|
+
*
|
46
|
+
* A cached promise is used so this function is safe to call more than once and concurrently.
|
44
47
|
*/
|
45
48
|
async connect() {
|
46
|
-
|
47
|
-
|
49
|
+
if (!this.connectPromise) {
|
50
|
+
this.connectPromise = this.producer.connect().catch((err) => {
|
51
|
+
this.connectPromise = undefined;
|
52
|
+
throw err;
|
53
|
+
});
|
54
|
+
}
|
55
|
+
await this.connectPromise;
|
48
56
|
}
|
49
57
|
/**
|
50
58
|
* Send messages to a Kafka topic.
|
@@ -57,9 +65,7 @@ export class KafkaProducer {
|
|
57
65
|
* @param messages
|
58
66
|
*/
|
59
67
|
async send(topic, messages) {
|
60
|
-
|
61
|
-
await this.connect();
|
62
|
-
}
|
68
|
+
await this.connect();
|
63
69
|
await this.producer.send({
|
64
70
|
topic,
|
65
71
|
messages: messages.map((m) => ({
|
@@ -72,14 +78,11 @@ export class KafkaProducer {
|
|
72
78
|
* Useful when shutting down the service to flush in-flight events.
|
73
79
|
*/
|
74
80
|
async disconnect() {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
await this.producer.disconnect();
|
79
|
-
}
|
80
|
-
catch { }
|
81
|
-
this.isConnected = false;
|
81
|
+
try {
|
82
|
+
await this.producer.flush();
|
83
|
+
await this.producer.disconnect();
|
82
84
|
}
|
85
|
+
catch { }
|
83
86
|
}
|
84
87
|
}
|
85
88
|
//# sourceMappingURL=kafka.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,GAER,MAAM,gCAAgC,CAAC;AAgBxC;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;
|
1
|
+
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"m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AC;gBAC7B,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;aACzB,CAAC,CAAC;SACJ,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACZ,CAAC;CACF"}
|
@@ -23,7 +23,7 @@ export interface KafkaProducerSendOptions {
|
|
23
23
|
*/
|
24
24
|
export declare class KafkaProducer {
|
25
25
|
private producer;
|
26
|
-
private
|
26
|
+
private connectPromise?;
|
27
27
|
constructor(options: {
|
28
28
|
/**
|
29
29
|
* A descriptive name for your service. Example: "storage-server"
|
@@ -42,6 +42,8 @@ export declare class KafkaProducer {
|
|
42
42
|
});
|
43
43
|
/**
|
44
44
|
* Connects the producer. Can be called explicitly at the start of your service, or will be called automatically when sending messages.
|
45
|
+
*
|
46
|
+
* A cached promise is used so this function is safe to call more than once and concurrently.
|
45
47
|
*/
|
46
48
|
connect(): Promise<void>;
|
47
49
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"kafka.d.ts","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,gCAAgC,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,wBAAwB;IAEvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAmB;
|
1
|
+
{"version":3,"file":"kafka.d.ts","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,gCAAgC,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,wBAAwB;IAEvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAmB;IAEnC,OAAO,CAAC,cAAc,CAAC,CAAgB;gBAE3B,OAAO,EAAE;QACnB;;WAEG;QACH,YAAY,EAAE,MAAM,CAAC;QACrB;;WAEG;QACH,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QAEjB;;WAEG;QACH,MAAM,CAAC,EAAE,oBAAoB,CAAC;KAC/B;IAiBD;;;;OAIG;IACG,OAAO;IAUb;;;;;;;;;OASG;IACG,IAAI,CACR,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAClC,OAAO,CAAC,IAAI,CAAC;IAWhB;;;OAGG;IACG,UAAU;CAMjB"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@thirdweb-dev/service-utils",
|
3
|
-
"version": "0.8.11-nightly-
|
3
|
+
"version": "0.8.11-nightly-323e9d7a3744020c5721048e2874f7f395803092-20250302000354",
|
4
4
|
"type": "module",
|
5
5
|
"main": "dist/cjs/index.js",
|
6
6
|
"module": "dist/esm/index.js",
|