kafka-ts 1.1.8 → 1.2.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.
Files changed (77) hide show
  1. package/README.md +1 -1
  2. package/dist/consumer/consumer-group.js +84 -99
  3. package/dist/consumer/consumer.js +23 -32
  4. package/dist/consumer/offset-manager.js +6 -5
  5. package/dist/distributors/group-by-leader-id.d.ts +10 -0
  6. package/dist/distributors/group-by-leader-id.js +13 -0
  7. package/dist/distributors/group-partitions-by-topic.d.ts +6 -0
  8. package/dist/distributors/group-partitions-by-topic.js +12 -0
  9. package/dist/metadata.d.ts +1 -1
  10. package/dist/metadata.js +1 -1
  11. package/dist/producer/producer-buffer.d.ts +20 -0
  12. package/dist/producer/producer-buffer.js +118 -0
  13. package/dist/producer/producer-state.d.ts +15 -0
  14. package/dist/producer/producer-state.js +33 -0
  15. package/dist/producer/producer.d.ts +6 -11
  16. package/dist/producer/producer.js +32 -108
  17. package/dist/utils/decoder.js +13 -8
  18. package/dist/utils/encoder.d.ts +10 -8
  19. package/dist/utils/encoder.js +95 -58
  20. package/dist/utils/promise-chain.d.ts +5 -0
  21. package/dist/utils/promise-chain.js +39 -0
  22. package/dist/utils/retry.d.ts +1 -0
  23. package/dist/utils/retry.js +19 -0
  24. package/dist/utils/shared.d.ts +1 -1
  25. package/dist/utils/shared.js +8 -7
  26. package/package.json +1 -1
  27. package/dist/consumer/metadata.d.ts +0 -24
  28. package/dist/consumer/metadata.js +0 -64
  29. package/dist/distributors/messages-to-topic-partition-leaders.d.ts +0 -17
  30. package/dist/distributors/messages-to-topic-partition-leaders.js +0 -15
  31. package/dist/distributors/messages-to-topic-partition-leaders.test.d.ts +0 -1
  32. package/dist/distributors/messages-to-topic-partition-leaders.test.js +0 -30
  33. package/dist/examples/src/replicator.js +0 -34
  34. package/dist/examples/src/utils/json.js +0 -5
  35. package/dist/request-handler.d.ts +0 -16
  36. package/dist/request-handler.js +0 -67
  37. package/dist/request-handler.test.d.ts +0 -1
  38. package/dist/request-handler.test.js +0 -340
  39. package/dist/src/api/api-versions.js +0 -18
  40. package/dist/src/api/create-topics.js +0 -46
  41. package/dist/src/api/delete-topics.js +0 -26
  42. package/dist/src/api/fetch.js +0 -95
  43. package/dist/src/api/find-coordinator.js +0 -34
  44. package/dist/src/api/heartbeat.js +0 -22
  45. package/dist/src/api/index.js +0 -38
  46. package/dist/src/api/init-producer-id.js +0 -24
  47. package/dist/src/api/join-group.js +0 -48
  48. package/dist/src/api/leave-group.js +0 -30
  49. package/dist/src/api/list-offsets.js +0 -39
  50. package/dist/src/api/metadata.js +0 -47
  51. package/dist/src/api/offset-commit.js +0 -39
  52. package/dist/src/api/offset-fetch.js +0 -44
  53. package/dist/src/api/produce.js +0 -119
  54. package/dist/src/api/sync-group.js +0 -31
  55. package/dist/src/broker.js +0 -35
  56. package/dist/src/connection.js +0 -21
  57. package/dist/src/consumer/consumer-group.js +0 -131
  58. package/dist/src/consumer/consumer.js +0 -103
  59. package/dist/src/consumer/metadata.js +0 -52
  60. package/dist/src/consumer/offset-manager.js +0 -23
  61. package/dist/src/index.js +0 -19
  62. package/dist/src/producer/producer.js +0 -84
  63. package/dist/src/request-handler.js +0 -57
  64. package/dist/src/request-handler.test.js +0 -321
  65. package/dist/src/types.js +0 -2
  66. package/dist/src/utils/api.js +0 -5
  67. package/dist/src/utils/decoder.js +0 -161
  68. package/dist/src/utils/encoder.js +0 -137
  69. package/dist/src/utils/error.js +0 -10
  70. package/dist/utils/debug.d.ts +0 -2
  71. package/dist/utils/debug.js +0 -11
  72. package/dist/utils/lock.d.ts +0 -8
  73. package/dist/utils/lock.js +0 -44
  74. package/dist/utils/memo.d.ts +0 -1
  75. package/dist/utils/memo.js +0 -16
  76. package/dist/utils/mutex.d.ts +0 -3
  77. package/dist/utils/mutex.js +0 -32
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Lock = void 0;
7
- const events_1 = __importDefault(require("events"));
8
- const logger_1 = require("./logger");
9
- class Lock extends events_1.default {
10
- locks = {};
11
- constructor() {
12
- super();
13
- this.setMaxListeners(Infinity);
14
- }
15
- async acquire(keys, callback) {
16
- await Promise.all(keys.map((key) => this.acquireKey(key)));
17
- try {
18
- await callback();
19
- }
20
- finally {
21
- keys.forEach((key) => this.releaseKey(key));
22
- }
23
- }
24
- async acquireKey(key) {
25
- while (this.locks[key]) {
26
- await new Promise((resolve) => {
27
- const timeout = setTimeout(() => {
28
- logger_1.log.warn(`Lock timed out`, { key });
29
- this.releaseKey(key);
30
- }, 60_000);
31
- this.once(`release:${key}`, () => {
32
- clearTimeout(timeout);
33
- resolve();
34
- });
35
- });
36
- }
37
- this.locks[key] = true;
38
- }
39
- releaseKey(key) {
40
- this.locks[key] = false;
41
- this.emit(`release:${key}`);
42
- }
43
- }
44
- exports.Lock = Lock;
@@ -1 +0,0 @@
1
- export declare const memo: <T extends (...args: any[]) => any>(fn: T) => (...args: Parameters<T>) => ReturnType<T>;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.memo = void 0;
4
- const memo = (fn) => {
5
- const cache = {};
6
- return (...args) => {
7
- const key = JSON.stringify(args);
8
- if (cache[key]) {
9
- return cache[key];
10
- }
11
- const result = fn(...args);
12
- cache[key] = result;
13
- return result;
14
- };
15
- };
16
- exports.memo = memo;
@@ -1,3 +0,0 @@
1
- export declare const createMutex: () => {
2
- exclusive: (fn: () => Promise<void>) => Promise<void>;
3
- };
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMutex = void 0;
4
- const createMutex = () => {
5
- const queue = [];
6
- let isLocked = false;
7
- const acquire = () => {
8
- return new Promise((resolve) => {
9
- if (!isLocked) {
10
- isLocked = true;
11
- return resolve();
12
- }
13
- queue.push(resolve);
14
- });
15
- };
16
- const release = () => {
17
- isLocked = false;
18
- const next = queue.shift();
19
- next && next();
20
- };
21
- const exclusive = async (fn) => {
22
- await acquire();
23
- try {
24
- await fn();
25
- }
26
- finally {
27
- release();
28
- }
29
- };
30
- return { exclusive };
31
- };
32
- exports.createMutex = createMutex;