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/package.json
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
"name": "kafka-ts",
|
|
3
|
+
"version": "0.0.3-beta",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"author": "Priit Käärd",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/priitkaard/kafka-ts.git"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"format": "prettier --write .",
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"watch": "tsc -w",
|
|
15
|
+
"test": "vitest --testTimeout 60000 --bail 1"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^20.12.12",
|
|
19
|
+
"prettier": "^3.3.3",
|
|
20
|
+
"typescript": "^5.4.5",
|
|
21
|
+
"vitest": "^1.6.0"
|
|
22
|
+
}
|
|
21
23
|
}
|
package/src/api/api-versions.ts
CHANGED
package/src/api/create-topics.ts
CHANGED
package/src/api/delete-topics.ts
CHANGED
package/src/api/fetch.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createApi } from
|
|
2
|
-
import { Decoder } from
|
|
3
|
-
import { KafkaTSApiError } from
|
|
1
|
+
import { createApi } from '../utils/api';
|
|
2
|
+
import { Decoder } from '../utils/decoder';
|
|
3
|
+
import { KafkaTSApiError } from '../utils/error';
|
|
4
4
|
|
|
5
5
|
export const enum IsolationLevel {
|
|
6
6
|
READ_UNCOMMITTED = 0,
|
package/src/api/heartbeat.ts
CHANGED
package/src/api/index.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { Api } from
|
|
2
|
-
import { API_VERSIONS } from
|
|
3
|
-
import { CREATE_TOPICS } from
|
|
4
|
-
import { DELETE_TOPICS } from
|
|
5
|
-
import { FETCH } from
|
|
6
|
-
import { FIND_COORDINATOR } from
|
|
7
|
-
import { HEARTBEAT } from
|
|
8
|
-
import { INIT_PRODUCER_ID } from
|
|
9
|
-
import { JOIN_GROUP } from
|
|
10
|
-
import { LEAVE_GROUP } from
|
|
11
|
-
import { LIST_OFFSETS } from
|
|
12
|
-
import { METADATA } from
|
|
13
|
-
import { OFFSET_COMMIT } from
|
|
14
|
-
import { OFFSET_FETCH } from
|
|
15
|
-
import { PRODUCE } from
|
|
16
|
-
import { SASL_AUTHENTICATE } from
|
|
17
|
-
import { SASL_HANDSHAKE } from
|
|
18
|
-
import { SYNC_GROUP } from
|
|
1
|
+
import { Api } from '../utils/api';
|
|
2
|
+
import { API_VERSIONS } from './api-versions';
|
|
3
|
+
import { CREATE_TOPICS } from './create-topics';
|
|
4
|
+
import { DELETE_TOPICS } from './delete-topics';
|
|
5
|
+
import { FETCH } from './fetch';
|
|
6
|
+
import { FIND_COORDINATOR } from './find-coordinator';
|
|
7
|
+
import { HEARTBEAT } from './heartbeat';
|
|
8
|
+
import { INIT_PRODUCER_ID } from './init-producer-id';
|
|
9
|
+
import { JOIN_GROUP } from './join-group';
|
|
10
|
+
import { LEAVE_GROUP } from './leave-group';
|
|
11
|
+
import { LIST_OFFSETS } from './list-offsets';
|
|
12
|
+
import { METADATA } from './metadata';
|
|
13
|
+
import { OFFSET_COMMIT } from './offset-commit';
|
|
14
|
+
import { OFFSET_FETCH } from './offset-fetch';
|
|
15
|
+
import { PRODUCE } from './produce';
|
|
16
|
+
import { SASL_AUTHENTICATE } from './sasl-authenticate';
|
|
17
|
+
import { SASL_HANDSHAKE } from './sasl-handshake';
|
|
18
|
+
import { SYNC_GROUP } from './sync-group';
|
|
19
19
|
|
|
20
20
|
export const API = {
|
|
21
21
|
API_VERSIONS,
|
package/src/api/join-group.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createApi } from
|
|
2
|
-
import { Encoder } from
|
|
3
|
-
import { KafkaTSApiError } from
|
|
1
|
+
import { createApi } from '../utils/api';
|
|
2
|
+
import { Encoder } from '../utils/encoder';
|
|
3
|
+
import { KafkaTSApiError } from '../utils/error';
|
|
4
4
|
|
|
5
5
|
export const JOIN_GROUP = createApi({
|
|
6
6
|
apiKey: 11,
|
package/src/api/leave-group.ts
CHANGED
package/src/api/list-offsets.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createApi } from
|
|
2
|
-
import { KafkaTSApiError } from
|
|
3
|
-
import { IsolationLevel } from
|
|
1
|
+
import { createApi } from '../utils/api';
|
|
2
|
+
import { KafkaTSApiError } from '../utils/error';
|
|
3
|
+
import { IsolationLevel } from './fetch';
|
|
4
4
|
|
|
5
5
|
export const LIST_OFFSETS = createApi({
|
|
6
6
|
apiKey: 2,
|
package/src/api/metadata.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createApi } from
|
|
2
|
-
import { KafkaTSApiError } from
|
|
1
|
+
import { createApi } from '../utils/api';
|
|
2
|
+
import { KafkaTSApiError } from '../utils/error';
|
|
3
3
|
|
|
4
|
-
export type Metadata = ReturnType<(typeof METADATA)[
|
|
4
|
+
export type Metadata = ReturnType<(typeof METADATA)['response']>;
|
|
5
5
|
|
|
6
6
|
export const METADATA = createApi({
|
|
7
7
|
apiKey: 3,
|
package/src/api/offset-commit.ts
CHANGED
package/src/api/offset-fetch.ts
CHANGED
package/src/api/produce.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createApi } from
|
|
2
|
-
import { Encoder } from
|
|
3
|
-
import { KafkaTSApiError } from
|
|
1
|
+
import { createApi } from '../utils/api.js';
|
|
2
|
+
import { Encoder } from '../utils/encoder.js';
|
|
3
|
+
import { KafkaTSApiError } from '../utils/error.js';
|
|
4
4
|
|
|
5
5
|
export const PRODUCE = createApi({
|
|
6
6
|
apiKey: 0,
|
package/src/api/sync-group.ts
CHANGED
package/src/broker.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { TcpSocketConnectOpts } from
|
|
2
|
-
import { TLSSocketOptions } from
|
|
3
|
-
import { API } from
|
|
4
|
-
import { Connection, SendRequest } from
|
|
5
|
-
import { KafkaTSError } from
|
|
6
|
-
import { memo } from
|
|
1
|
+
import { TcpSocketConnectOpts } from 'net';
|
|
2
|
+
import { TLSSocketOptions } from 'tls';
|
|
3
|
+
import { API } from './api';
|
|
4
|
+
import { Connection, SendRequest } from './connection';
|
|
5
|
+
import { KafkaTSError } from './utils/error';
|
|
6
|
+
import { memo } from './utils/memo';
|
|
7
7
|
|
|
8
|
-
export type SASLOptions = { mechanism:
|
|
8
|
+
export type SASLOptions = { mechanism: 'PLAIN'; username: string; password: string };
|
|
9
9
|
|
|
10
10
|
type BrokerOptions = {
|
|
11
11
|
clientId: string | null;
|
|
@@ -64,11 +64,11 @@ export class Broker {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
private async saslAuthenticate() {
|
|
67
|
-
if (this.options.sasl?.mechanism !==
|
|
67
|
+
if (this.options.sasl?.mechanism !== 'PLAIN') {
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
const { username, password } = this.options.sasl;
|
|
71
|
-
const authBytes = [null, username, password].join(
|
|
71
|
+
const authBytes = [null, username, password].join('\u0000');
|
|
72
72
|
await this.sendRequest(API.SASL_AUTHENTICATE, { authBytes: Buffer.from(authBytes) });
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/client.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { TcpSocketConnectOpts } from
|
|
2
|
-
import { TLSSocketOptions } from
|
|
3
|
-
import { SASLOptions } from
|
|
4
|
-
import { Cluster } from
|
|
5
|
-
import { Consumer, ConsumerOptions } from
|
|
6
|
-
import { Producer, ProducerOptions } from
|
|
1
|
+
import { TcpSocketConnectOpts } from 'net';
|
|
2
|
+
import { TLSSocketOptions } from 'tls';
|
|
3
|
+
import { SASLOptions } from './broker';
|
|
4
|
+
import { Cluster } from './cluster';
|
|
5
|
+
import { Consumer, ConsumerOptions } from './consumer/consumer';
|
|
6
|
+
import { Producer, ProducerOptions } from './producer/producer';
|
|
7
7
|
|
|
8
8
|
type ClientOptions = {
|
|
9
9
|
clientId?: string | null;
|