kafka-ts 0.0.2-beta → 0.0.3-beta
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/.github/workflows/release.yml +14 -14
- package/.prettierrc +3 -2
- package/README.md +43 -33
- package/docker-compose.yml +102 -102
- package/examples/package-lock.json +28 -28
- package/examples/package.json +12 -12
- package/examples/src/client.ts +6 -6
- package/examples/src/consumer.ts +9 -8
- package/examples/src/create-topic.ts +23 -16
- package/examples/src/producer.ts +7 -7
- package/examples/src/replicator.ts +4 -4
- package/examples/src/utils/delay.ts +1 -0
- package/examples/src/utils/json.ts +1 -1
- package/examples/tsconfig.json +2 -2
- package/package.json +21 -19
- package/src/api/api-versions.ts +2 -2
- package/src/api/create-topics.ts +2 -2
- package/src/api/delete-topics.ts +2 -2
- package/src/api/fetch.ts +3 -3
- package/src/api/find-coordinator.ts +2 -2
- package/src/api/heartbeat.ts +2 -2
- package/src/api/index.ts +18 -18
- package/src/api/init-producer-id.ts +2 -2
- package/src/api/join-group.ts +3 -3
- package/src/api/leave-group.ts +2 -2
- package/src/api/list-offsets.ts +3 -3
- package/src/api/metadata.ts +3 -3
- package/src/api/offset-commit.ts +2 -2
- package/src/api/offset-fetch.ts +2 -2
- package/src/api/produce.ts +3 -3
- package/src/api/sasl-authenticate.ts +2 -2
- package/src/api/sasl-handshake.ts +2 -2
- package/src/api/sync-group.ts +2 -2
- package/src/broker.ts +9 -9
- package/src/client.ts +6 -6
- package/src/cluster.test.ts +68 -68
- package/src/cluster.ts +7 -7
- package/src/connection.ts +17 -15
- package/src/consumer/consumer-group.ts +14 -14
- package/src/consumer/consumer-metadata.ts +2 -2
- package/src/consumer/consumer.ts +84 -82
- package/src/consumer/fetch-manager.ts +179 -0
- package/src/consumer/fetcher.ts +57 -0
- package/src/consumer/offset-manager.ts +6 -6
- package/src/consumer/processor.ts +47 -0
- package/src/distributors/assignments-to-replicas.test.ts +7 -7
- package/src/distributors/assignments-to-replicas.ts +1 -1
- package/src/distributors/messages-to-topic-partition-leaders.test.ts +6 -6
- package/src/index.ts +4 -3
- package/src/metadata.ts +4 -4
- package/src/producer/producer.ts +8 -8
- package/src/types.ts +2 -0
- package/src/utils/api.ts +4 -4
- package/src/utils/debug.ts +2 -2
- package/src/utils/decoder.ts +4 -4
- package/src/utils/encoder.ts +6 -6
- package/src/utils/error.ts +3 -3
- package/src/utils/retrier.ts +1 -1
- package/src/utils/tracer.ts +7 -4
- package/tsconfig.json +16 -16
package/src/utils/debug.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export const serializer = (_: string, value: unknown) => (typeof value ===
|
|
1
|
+
export const serializer = (_: string, value: unknown) => (typeof value === 'bigint' ? value.toString() : value);
|
|
2
2
|
|
|
3
3
|
export const createDebugger = (module: string) => (func: string, message: string, data?: unknown) => {
|
|
4
|
-
if (!process.env.DEBUG?.includes(
|
|
4
|
+
if (!process.env.DEBUG?.includes('kafka-ts')) return;
|
|
5
5
|
console.debug(
|
|
6
6
|
`[${module}] ${func}: ${message}`,
|
|
7
7
|
data && `(${data instanceof Error ? data : JSON.stringify(data, serializer, 4)})`,
|
package/src/utils/decoder.ts
CHANGED
|
@@ -81,7 +81,7 @@ export class Decoder {
|
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
const value = this.buffer.toString(
|
|
84
|
+
const value = this.buffer.toString('utf-8', this.offset, this.offset + length);
|
|
85
85
|
this.offset += length;
|
|
86
86
|
return value;
|
|
87
87
|
}
|
|
@@ -92,7 +92,7 @@ export class Decoder {
|
|
|
92
92
|
return null;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
const value = this.buffer.toString(
|
|
95
|
+
const value = this.buffer.toString('utf-8', this.offset, this.offset + length);
|
|
96
96
|
this.offset += length;
|
|
97
97
|
return value;
|
|
98
98
|
}
|
|
@@ -103,13 +103,13 @@ export class Decoder {
|
|
|
103
103
|
return null;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
const value = this.buffer.toString(
|
|
106
|
+
const value = this.buffer.toString('utf-8', this.offset, this.offset + length);
|
|
107
107
|
this.offset += length;
|
|
108
108
|
return value;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
public readUUID() {
|
|
112
|
-
const value = this.buffer.toString(
|
|
112
|
+
const value = this.buffer.toString('hex', this.offset, this.offset + 16);
|
|
113
113
|
this.offset += 16;
|
|
114
114
|
return value;
|
|
115
115
|
}
|
package/src/utils/encoder.ts
CHANGED
|
@@ -74,9 +74,9 @@ export class Encoder {
|
|
|
74
74
|
if (value === null) {
|
|
75
75
|
return this.writeInt16(-1);
|
|
76
76
|
}
|
|
77
|
-
const byteLength = Buffer.byteLength(value,
|
|
77
|
+
const byteLength = Buffer.byteLength(value, 'utf-8');
|
|
78
78
|
const buffer = Buffer.alloc(byteLength);
|
|
79
|
-
buffer.write(value, 0, byteLength,
|
|
79
|
+
buffer.write(value, 0, byteLength, 'utf-8');
|
|
80
80
|
return this.writeInt16(byteLength).write(buffer);
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -85,9 +85,9 @@ export class Encoder {
|
|
|
85
85
|
return this.writeUVarInt(0);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
const byteLength = Buffer.byteLength(value,
|
|
88
|
+
const byteLength = Buffer.byteLength(value, 'utf-8');
|
|
89
89
|
const buffer = Buffer.alloc(byteLength);
|
|
90
|
-
buffer.write(value, 0, byteLength,
|
|
90
|
+
buffer.write(value, 0, byteLength, 'utf-8');
|
|
91
91
|
return this.writeUVarInt(byteLength + 1).write(buffer);
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -95,14 +95,14 @@ export class Encoder {
|
|
|
95
95
|
if (value === null) {
|
|
96
96
|
return this.writeVarInt(-1);
|
|
97
97
|
}
|
|
98
|
-
return this.writeVarInt(Buffer.byteLength(value,
|
|
98
|
+
return this.writeVarInt(Buffer.byteLength(value, 'utf-8')).write(Buffer.from(value, 'utf-8'));
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
public writeUUID(value: string | null) {
|
|
102
102
|
if (value === null) {
|
|
103
103
|
return this.write(Buffer.alloc(16));
|
|
104
104
|
}
|
|
105
|
-
return this.write(Buffer.from(value,
|
|
105
|
+
return this.write(Buffer.from(value, 'hex'));
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
public writeBoolean(value: boolean) {
|
package/src/utils/error.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { API_ERROR } from
|
|
1
|
+
import { API_ERROR } from '../api';
|
|
2
2
|
|
|
3
3
|
export class KafkaTSError extends Error {
|
|
4
4
|
constructor(message: string) {
|
|
@@ -13,8 +13,8 @@ export class KafkaTSApiError<T = any> extends KafkaTSError {
|
|
|
13
13
|
public errorMessage: string | null,
|
|
14
14
|
public response: T,
|
|
15
15
|
) {
|
|
16
|
-
const [errorName] = Object.entries(API_ERROR).find(([, value]) => value === errorCode) ?? [
|
|
17
|
-
super(`${errorName}${errorMessage ? `: ${errorMessage}` :
|
|
16
|
+
const [errorName] = Object.entries(API_ERROR).find(([, value]) => value === errorCode) ?? ['UNKNOWN'];
|
|
17
|
+
super(`${errorName}${errorMessage ? `: ${errorMessage}` : ''}`);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
package/src/utils/retrier.ts
CHANGED
package/src/utils/tracer.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { serializer } from
|
|
1
|
+
import { serializer } from './debug';
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const createTracer =
|
|
4
|
+
(module: string, attributes?: Record<string, unknown>) =>
|
|
4
5
|
(fn?: (...args: any[]) => Record<string, unknown> | undefined) =>
|
|
5
6
|
(target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
|
|
6
|
-
if (!process.env.DEBUG?.includes(
|
|
7
|
+
if (!process.env.DEBUG?.includes('kafka-ts')) return;
|
|
7
8
|
|
|
8
9
|
const original = descriptor.value;
|
|
9
10
|
descriptor.value = function (...args: any[]) {
|
|
@@ -12,7 +13,7 @@ export const trace =
|
|
|
12
13
|
|
|
13
14
|
const onEnd = <T>(result: T): T => {
|
|
14
15
|
console.log(
|
|
15
|
-
`[${propertyKey}] +${Date.now() - startTime}ms ${JSON.stringify({ ...metadata, result }, serializer)}`,
|
|
16
|
+
`[${module}.${propertyKey}] +${Date.now() - startTime}ms ${JSON.stringify({ ...attributes, ...metadata, result }, serializer)}`,
|
|
16
17
|
);
|
|
17
18
|
return result;
|
|
18
19
|
};
|
|
@@ -26,3 +27,5 @@ export const trace =
|
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
};
|
|
30
|
+
|
|
31
|
+
export const trace = createTracer('GLOBAL');
|
package/tsconfig.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["es2023"],
|
|
4
|
+
"target": "es2022",
|
|
5
|
+
"module": "node16",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"forceConsistentCasingInFileNames": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"moduleResolution": "node16",
|
|
11
|
+
"outDir": "dist",
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"emitDecoratorMetadata": true,
|
|
14
|
+
"experimentalDecorators": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*"]
|
|
17
|
+
}
|