@platformatic/kafka 2.2.3 → 2.3.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 CHANGED
@@ -16,7 +16,9 @@ A modern, high-performance, pure TypeScript/JavaScript type safe client for Apac
16
16
 
17
17
  ## Supported Kafka Version
18
18
 
19
- Supported Kafka version are from **3.5.0** to **4.1.0** and equivalent, edges included.
19
+ Supported Apache Kafka versions are from **3.5.0** to **4.2.0** and equivalent, edges included.
20
+
21
+ These are tested in CI against the corresponding Confluent Platform releases, from **7.5.0** to **8.2.0** (rule of thumb: Confluent Platform version = Apache Kafka version + 4.0.0).
20
22
 
21
23
  ## Supported KIPs
22
24
 
@@ -78,6 +78,7 @@ export function parseResponse(_correlationId, apiKey, apiVersion, reader) {
78
78
  return topic;
79
79
  })
80
80
  };
81
+ reader.readTaggedFields();
81
82
  if (errors.length) {
82
83
  throw new ResponseError(apiKey, apiVersion, Object.fromEntries(errors), response);
83
84
  }
@@ -6,6 +6,4 @@ export type CallbackWithPromise<ReturnType> = Callback<ReturnType> & {
6
6
  [kCallbackPromise]?: Promise<ReturnType>;
7
7
  };
8
8
  export declare function createPromisifiedCallback<ReturnType>(): CallbackWithPromise<ReturnType>;
9
- export declare function runConcurrentCallbacks<ReturnType, K, V>(errorMessage: string, collection: Map<K, V>, operation: (item: [K, V], cb: Callback<ReturnType>) => void, callback: Callback<ReturnType[]>): void;
10
- export declare function runConcurrentCallbacks<ReturnType, V>(errorMessage: string, collection: Set<V>, operation: (item: V, cb: Callback<ReturnType>) => void, callback: Callback<ReturnType[]>): void;
11
- export declare function runConcurrentCallbacks<ReturnType, V>(errorMessage: string, collection: V[], operation: (item: V, cb: Callback<ReturnType>) => void, callback: Callback<ReturnType[]>): void;
9
+ export declare function runConcurrentCallbacks<R, V>(errorMessage: string, collection: Iterable<V>, operation: (item: V, cb: Callback<R>) => void, callback: Callback<R[]>): void;
@@ -19,28 +19,43 @@ export function createPromisifiedCallback() {
19
19
  return callback;
20
20
  }
21
21
  export function runConcurrentCallbacks(errorMessage, collection, operation, callback) {
22
- let remaining = Array.isArray(collection) ? collection.length : collection.size;
22
+ let allScheduled = false;
23
+ let completed = 0;
24
+ let callbackCalled = false;
23
25
  let hasErrors = false;
24
- const errors = Array.from(Array(remaining));
25
- const results = Array.from(Array(remaining));
26
+ const errors = [];
27
+ const results = [];
26
28
  let i = 0;
27
29
  function operationCallback(index, e, result) {
28
30
  if (e) {
29
31
  hasErrors = true;
30
- errors[index] = e;
32
+ errors.push([index, e]);
33
+ results.push([index, undefined]);
31
34
  }
32
35
  else {
33
- results[index] = result;
36
+ results.push([index, result]);
34
37
  }
35
- remaining--;
36
- if (remaining === 0) {
37
- callback(hasErrors ? new MultipleErrors(errorMessage, errors.filter(Boolean)) : null, results);
38
+ completed++;
39
+ if (allScheduled && completed === i) {
40
+ callbackCalled = true;
41
+ const e = errors.sort((a, b) => a[0] - b[0]).map(([_, error]) => error);
42
+ const r = results.sort((a, b) => a[0] - b[0]).map(([_, result]) => result);
43
+ callback(hasErrors ? new MultipleErrors(errorMessage, e) : null, r);
38
44
  }
39
45
  }
40
- if (remaining === 0) {
41
- callback(null, results);
42
- }
43
46
  for (const item of collection) {
44
47
  operation(item, operationCallback.bind(null, i++));
45
48
  }
49
+ if (i === 0) {
50
+ callback(null, []);
51
+ return;
52
+ }
53
+ allScheduled = true;
54
+ // If all operations were synchronous, allScheduled is not set to true in time for the operation
55
+ // callback to pick it up. In that case, call the callback here.
56
+ if (completed === i && !callbackCalled) {
57
+ const e = errors.sort((a, b) => a[0] - b[0]).map(([_, error]) => error);
58
+ const r = results.sort((a, b) => a[0] - b[0]).map(([_, result]) => result);
59
+ callback(hasErrors ? new MultipleErrors(errorMessage, e) : null, r);
60
+ }
46
61
  }