kafka-ts 0.0.1-beta.3 → 0.0.1-beta.6
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 +19 -6
- package/README.md +15 -21
- package/dist/api/api-versions.d.ts +9 -0
- package/dist/api/api-versions.js +24 -0
- package/dist/api/create-topics.d.ts +38 -0
- package/dist/api/create-topics.js +53 -0
- package/dist/api/delete-topics.d.ts +18 -0
- package/dist/api/delete-topics.js +33 -0
- package/dist/api/fetch.d.ts +84 -0
- package/dist/api/fetch.js +142 -0
- package/dist/api/find-coordinator.d.ts +21 -0
- package/dist/api/find-coordinator.js +39 -0
- package/dist/api/heartbeat.d.ts +11 -0
- package/dist/api/heartbeat.js +27 -0
- package/dist/api/index.d.ts +578 -0
- package/dist/api/index.js +165 -0
- package/dist/api/init-producer-id.d.ts +13 -0
- package/dist/api/init-producer-id.js +29 -0
- package/dist/api/join-group.d.ts +34 -0
- package/dist/api/join-group.js +51 -0
- package/dist/api/leave-group.d.ts +19 -0
- package/dist/api/leave-group.js +39 -0
- package/dist/api/list-offsets.d.ts +29 -0
- package/dist/api/list-offsets.js +48 -0
- package/dist/api/metadata.d.ts +40 -0
- package/dist/api/metadata.js +58 -0
- package/dist/api/offset-commit.d.ts +28 -0
- package/dist/api/offset-commit.js +48 -0
- package/dist/api/offset-fetch.d.ts +33 -0
- package/dist/api/offset-fetch.js +57 -0
- package/dist/api/produce.d.ts +54 -0
- package/dist/api/produce.js +126 -0
- package/dist/api/sasl-authenticate.d.ts +11 -0
- package/dist/api/sasl-authenticate.js +23 -0
- package/dist/api/sasl-handshake.d.ts +6 -0
- package/dist/api/sasl-handshake.js +19 -0
- package/dist/api/sync-group.d.ts +24 -0
- package/dist/api/sync-group.js +36 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/plain.d.ts +5 -0
- package/dist/auth/plain.js +12 -0
- package/dist/auth/scram.d.ts +9 -0
- package/dist/auth/scram.js +40 -0
- package/dist/broker.d.ts +30 -0
- package/dist/broker.js +55 -0
- package/dist/client.d.ts +23 -0
- package/dist/client.js +36 -0
- package/dist/cluster.d.ts +27 -0
- package/dist/cluster.js +70 -0
- package/dist/cluster.test.d.ts +1 -0
- package/dist/cluster.test.js +345 -0
- package/dist/codecs/gzip.d.ts +2 -0
- package/dist/codecs/gzip.js +8 -0
- package/dist/codecs/index.d.ts +2 -0
- package/dist/codecs/index.js +17 -0
- package/dist/codecs/none.d.ts +2 -0
- package/dist/codecs/none.js +7 -0
- package/dist/codecs/types.d.ts +5 -0
- package/dist/codecs/types.js +2 -0
- package/dist/connection.d.ts +26 -0
- package/dist/connection.js +175 -0
- package/dist/consumer/consumer-group.d.ts +41 -0
- package/dist/consumer/consumer-group.js +217 -0
- package/dist/consumer/consumer-metadata.d.ts +7 -0
- package/dist/consumer/consumer-metadata.js +14 -0
- package/dist/consumer/consumer.d.ts +44 -0
- package/dist/consumer/consumer.js +225 -0
- package/dist/consumer/fetch-manager.d.ts +33 -0
- package/dist/consumer/fetch-manager.js +140 -0
- package/dist/consumer/fetcher.d.ts +25 -0
- package/dist/consumer/fetcher.js +64 -0
- package/dist/consumer/offset-manager.d.ts +22 -0
- package/dist/consumer/offset-manager.js +66 -0
- package/dist/consumer/processor.d.ts +19 -0
- package/dist/consumer/processor.js +59 -0
- package/dist/distributors/assignments-to-replicas.d.ts +16 -0
- package/dist/distributors/assignments-to-replicas.js +59 -0
- package/dist/distributors/assignments-to-replicas.test.d.ts +1 -0
- package/dist/distributors/assignments-to-replicas.test.js +40 -0
- package/dist/distributors/messages-to-topic-partition-leaders.d.ts +17 -0
- package/dist/distributors/messages-to-topic-partition-leaders.js +15 -0
- package/dist/distributors/messages-to-topic-partition-leaders.test.d.ts +1 -0
- package/dist/distributors/messages-to-topic-partition-leaders.test.js +30 -0
- package/dist/distributors/partitioner.d.ts +7 -0
- package/dist/distributors/partitioner.js +23 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +26 -0
- package/dist/metadata.d.ts +24 -0
- package/dist/metadata.js +106 -0
- package/dist/producer/producer.d.ts +24 -0
- package/dist/producer/producer.js +131 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +2 -0
- package/dist/utils/api.d.ts +9 -0
- package/dist/utils/api.js +5 -0
- package/dist/utils/crypto.d.ts +8 -0
- package/dist/utils/crypto.js +18 -0
- package/dist/utils/decoder.d.ts +30 -0
- package/dist/utils/decoder.js +152 -0
- package/dist/utils/delay.d.ts +1 -0
- package/dist/utils/delay.js +5 -0
- package/dist/utils/encoder.d.ts +28 -0
- package/dist/utils/encoder.js +125 -0
- package/dist/utils/error.d.ts +11 -0
- package/dist/utils/error.js +27 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/logger.js +32 -0
- package/dist/utils/memo.d.ts +1 -0
- package/dist/utils/memo.js +16 -0
- package/dist/utils/murmur2.d.ts +3 -0
- package/dist/utils/murmur2.js +40 -0
- package/dist/utils/retrier.d.ts +10 -0
- package/dist/utils/retrier.js +22 -0
- package/dist/utils/tracer.d.ts +5 -0
- package/dist/utils/tracer.js +39 -0
- package/docker-compose.yml +3 -3
- package/examples/package-lock.json +3501 -3
- package/examples/package.json +8 -1
- package/examples/src/benchmark/common.ts +98 -0
- package/examples/src/benchmark/kafka-ts.ts +67 -0
- package/examples/src/benchmark/kafkajs.ts +51 -0
- package/examples/src/client.ts +4 -1
- package/examples/src/consumer.ts +7 -1
- package/examples/src/create-topic.ts +3 -3
- package/examples/src/opentelemetry.ts +46 -0
- package/examples/src/producer.ts +11 -11
- package/examples/src/replicator.ts +2 -1
- package/package.json +4 -2
- package/scripts/create-scram-user.sh +4 -2
- package/scripts/generate-certs.sh +2 -0
- package/src/__snapshots__/cluster.test.ts.snap +160 -53
- package/src/api/fetch.ts +83 -28
- package/src/api/index.ts +3 -1
- package/src/api/metadata.ts +1 -1
- package/src/api/produce.ts +7 -10
- package/src/cluster.test.ts +10 -7
- package/src/cluster.ts +36 -38
- package/src/codecs/gzip.ts +9 -0
- package/src/codecs/index.ts +16 -0
- package/src/codecs/none.ts +6 -0
- package/src/codecs/types.ts +4 -0
- package/src/connection.ts +31 -17
- package/src/consumer/consumer-group.ts +43 -21
- package/src/consumer/consumer.ts +58 -37
- package/src/consumer/fetch-manager.ts +36 -46
- package/src/consumer/fetcher.ts +20 -13
- package/src/consumer/offset-manager.ts +18 -7
- package/src/consumer/processor.ts +14 -8
- package/src/distributors/assignments-to-replicas.ts +1 -3
- package/src/index.ts +2 -0
- package/src/metadata.ts +4 -0
- package/src/producer/producer.ts +14 -9
- package/src/utils/api.ts +1 -1
- package/src/utils/decoder.ts +9 -3
- package/src/utils/encoder.ts +26 -19
- package/src/utils/logger.ts +37 -0
- package/src/utils/tracer.ts +40 -22
- package/certs/ca.key +0 -52
- package/certs/ca.srl +0 -1
- package/certs/kafka.crt +0 -29
- package/certs/kafka.csr +0 -26
- package/certs/kafka.key +0 -52
- package/src/utils/debug.ts +0 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`
|
|
3
|
+
exports[`Low-level API > should commit offsets 1`] = `
|
|
4
4
|
{
|
|
5
5
|
"_tag": undefined,
|
|
6
6
|
"_tag2": undefined,
|
|
@@ -21,7 +21,7 @@ exports[`Request handler > should commit offsets 1`] = `
|
|
|
21
21
|
}
|
|
22
22
|
`;
|
|
23
23
|
|
|
24
|
-
exports[`
|
|
24
|
+
exports[`Low-level API > should create topics 1`] = `
|
|
25
25
|
{
|
|
26
26
|
"_tag": undefined,
|
|
27
27
|
"_tag2": undefined,
|
|
@@ -282,15 +282,15 @@ exports[`Request handler > should create topics 1`] = `
|
|
|
282
282
|
"errorCode": 0,
|
|
283
283
|
"errorMessage": null,
|
|
284
284
|
"name": "kafka-ts-test-topic",
|
|
285
|
-
"numPartitions":
|
|
286
|
-
"replicationFactor":
|
|
285
|
+
"numPartitions": 10,
|
|
286
|
+
"replicationFactor": 3,
|
|
287
287
|
"topicId": "Any<UUID>",
|
|
288
288
|
},
|
|
289
289
|
],
|
|
290
290
|
}
|
|
291
291
|
`;
|
|
292
292
|
|
|
293
|
-
exports[`
|
|
293
|
+
exports[`Low-level API > should delete topics 1`] = `
|
|
294
294
|
{
|
|
295
295
|
"_tag": undefined,
|
|
296
296
|
"_tag2": undefined,
|
|
@@ -307,7 +307,7 @@ exports[`Request handler > should delete topics 1`] = `
|
|
|
307
307
|
}
|
|
308
308
|
`;
|
|
309
309
|
|
|
310
|
-
exports[`
|
|
310
|
+
exports[`Low-level API > should fail join group request with new memberId 1`] = `
|
|
311
311
|
{
|
|
312
312
|
"_tag": undefined,
|
|
313
313
|
"_tag2": undefined,
|
|
@@ -323,7 +323,7 @@ exports[`Request handler > should fail join group request with new memberId 1`]
|
|
|
323
323
|
}
|
|
324
324
|
`;
|
|
325
325
|
|
|
326
|
-
exports[`
|
|
326
|
+
exports[`Low-level API > should fetch messages 1`] = `
|
|
327
327
|
{
|
|
328
328
|
"_tag": undefined,
|
|
329
329
|
"_tag2": undefined,
|
|
@@ -339,7 +339,7 @@ exports[`Request handler > should fetch messages 1`] = `
|
|
|
339
339
|
"highWatermark": 1n,
|
|
340
340
|
"lastStableOffset": 1n,
|
|
341
341
|
"logStartOffset": 0n,
|
|
342
|
-
"partitionIndex":
|
|
342
|
+
"partitionIndex": 6,
|
|
343
343
|
"preferredReadReplica": -1,
|
|
344
344
|
"records": [
|
|
345
345
|
{
|
|
@@ -348,7 +348,11 @@ exports[`Request handler > should fetch messages 1`] = `
|
|
|
348
348
|
"baseSequence": 0,
|
|
349
349
|
"baseTimestamp": 0n,
|
|
350
350
|
"batchLength": 94,
|
|
351
|
+
"compression": 0,
|
|
351
352
|
"crc": 0,
|
|
353
|
+
"hasDeleteHorizonMs": false,
|
|
354
|
+
"isControlBatch": false,
|
|
355
|
+
"isTransactional": false,
|
|
352
356
|
"lastOffsetDelta": 0,
|
|
353
357
|
"magic": 2,
|
|
354
358
|
"maxTimestamp": 0n,
|
|
@@ -416,6 +420,7 @@ exports[`Request handler > should fetch messages 1`] = `
|
|
|
416
420
|
},
|
|
417
421
|
},
|
|
418
422
|
],
|
|
423
|
+
"timestampType": "CreateTime",
|
|
419
424
|
},
|
|
420
425
|
],
|
|
421
426
|
},
|
|
@@ -428,7 +433,7 @@ exports[`Request handler > should fetch messages 1`] = `
|
|
|
428
433
|
}
|
|
429
434
|
`;
|
|
430
435
|
|
|
431
|
-
exports[`
|
|
436
|
+
exports[`Low-level API > should fetch offsets 1`] = `
|
|
432
437
|
{
|
|
433
438
|
"_tag": undefined,
|
|
434
439
|
"_tag2": undefined,
|
|
@@ -459,7 +464,7 @@ exports[`Request handler > should fetch offsets 1`] = `
|
|
|
459
464
|
}
|
|
460
465
|
`;
|
|
461
466
|
|
|
462
|
-
exports[`
|
|
467
|
+
exports[`Low-level API > should find coordinator 1`] = `
|
|
463
468
|
{
|
|
464
469
|
"_tag": undefined,
|
|
465
470
|
"_tag2": undefined,
|
|
@@ -478,7 +483,7 @@ exports[`Request handler > should find coordinator 1`] = `
|
|
|
478
483
|
}
|
|
479
484
|
`;
|
|
480
485
|
|
|
481
|
-
exports[`
|
|
486
|
+
exports[`Low-level API > should heartbeat 1`] = `
|
|
482
487
|
{
|
|
483
488
|
"_tag": undefined,
|
|
484
489
|
"_tag2": undefined,
|
|
@@ -487,7 +492,7 @@ exports[`Request handler > should heartbeat 1`] = `
|
|
|
487
492
|
}
|
|
488
493
|
`;
|
|
489
494
|
|
|
490
|
-
exports[`
|
|
495
|
+
exports[`Low-level API > should init producer id 1`] = `
|
|
491
496
|
{
|
|
492
497
|
"_tag": undefined,
|
|
493
498
|
"_tag2": undefined,
|
|
@@ -498,7 +503,7 @@ exports[`Request handler > should init producer id 1`] = `
|
|
|
498
503
|
}
|
|
499
504
|
`;
|
|
500
505
|
|
|
501
|
-
exports[`
|
|
506
|
+
exports[`Low-level API > should join group 1`] = `
|
|
502
507
|
{
|
|
503
508
|
"_tag": undefined,
|
|
504
509
|
"_tag2": undefined,
|
|
@@ -556,7 +561,7 @@ exports[`Request handler > should join group 1`] = `
|
|
|
556
561
|
}
|
|
557
562
|
`;
|
|
558
563
|
|
|
559
|
-
exports[`
|
|
564
|
+
exports[`Low-level API > should leave group 1`] = `
|
|
560
565
|
{
|
|
561
566
|
"_tag": undefined,
|
|
562
567
|
"_tag2": undefined,
|
|
@@ -573,7 +578,7 @@ exports[`Request handler > should leave group 1`] = `
|
|
|
573
578
|
}
|
|
574
579
|
`;
|
|
575
580
|
|
|
576
|
-
exports[`
|
|
581
|
+
exports[`Low-level API > should produce messages 1`] = `
|
|
577
582
|
{
|
|
578
583
|
"_tag": undefined,
|
|
579
584
|
"_tag2": undefined,
|
|
@@ -587,7 +592,7 @@ exports[`Request handler > should produce messages 1`] = `
|
|
|
587
592
|
"baseOffset": 0n,
|
|
588
593
|
"errorCode": 0,
|
|
589
594
|
"errorMessage": null,
|
|
590
|
-
"index":
|
|
595
|
+
"index": 6,
|
|
591
596
|
"logAppendTime": -1n,
|
|
592
597
|
"logStartOffset": 0n,
|
|
593
598
|
"recordErrors": [],
|
|
@@ -599,7 +604,7 @@ exports[`Request handler > should produce messages 1`] = `
|
|
|
599
604
|
}
|
|
600
605
|
`;
|
|
601
606
|
|
|
602
|
-
exports[`
|
|
607
|
+
exports[`Low-level API > should request api versions 1`] = `
|
|
603
608
|
{
|
|
604
609
|
"errorCode": 0,
|
|
605
610
|
"throttleTimeMs": 0,
|
|
@@ -893,7 +898,7 @@ exports[`Request handler > should request api versions 1`] = `
|
|
|
893
898
|
}
|
|
894
899
|
`;
|
|
895
900
|
|
|
896
|
-
exports[`
|
|
901
|
+
exports[`Low-level API > should request metadata for a topic 1`] = `
|
|
897
902
|
{
|
|
898
903
|
"_tag": undefined,
|
|
899
904
|
"_tag2": undefined,
|
|
@@ -920,7 +925,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
920
925
|
"rack": null,
|
|
921
926
|
},
|
|
922
927
|
],
|
|
923
|
-
"clusterId": "4L6g3nShT-eMCtK--X86sw",
|
|
928
|
+
"clusterId": "Some(4L6g3nShT-eMCtK--X86sw)",
|
|
924
929
|
"controllerId": 0,
|
|
925
930
|
"throttleTimeMs": 0,
|
|
926
931
|
"topics": [
|
|
@@ -930,6 +935,20 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
930
935
|
"isInternal": false,
|
|
931
936
|
"name": "kafka-ts-test-topic",
|
|
932
937
|
"partitions": [
|
|
938
|
+
{
|
|
939
|
+
"_tag": undefined,
|
|
940
|
+
"errorCode": 0,
|
|
941
|
+
"isrNodes": [
|
|
942
|
+
0,
|
|
943
|
+
],
|
|
944
|
+
"leaderEpoch": 0,
|
|
945
|
+
"leaderId": 0,
|
|
946
|
+
"offlineReplicas": [],
|
|
947
|
+
"partitionIndex": 6,
|
|
948
|
+
"replicaNodes": [
|
|
949
|
+
0,
|
|
950
|
+
],
|
|
951
|
+
},
|
|
933
952
|
{
|
|
934
953
|
"_tag": undefined,
|
|
935
954
|
"errorCode": 0,
|
|
@@ -944,6 +963,118 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
944
963
|
0,
|
|
945
964
|
],
|
|
946
965
|
},
|
|
966
|
+
{
|
|
967
|
+
"_tag": undefined,
|
|
968
|
+
"errorCode": 0,
|
|
969
|
+
"isrNodes": [
|
|
970
|
+
0,
|
|
971
|
+
],
|
|
972
|
+
"leaderEpoch": 0,
|
|
973
|
+
"leaderId": 0,
|
|
974
|
+
"offlineReplicas": [],
|
|
975
|
+
"partitionIndex": 2,
|
|
976
|
+
"replicaNodes": [
|
|
977
|
+
0,
|
|
978
|
+
],
|
|
979
|
+
},
|
|
980
|
+
{
|
|
981
|
+
"_tag": undefined,
|
|
982
|
+
"errorCode": 0,
|
|
983
|
+
"isrNodes": [
|
|
984
|
+
0,
|
|
985
|
+
],
|
|
986
|
+
"leaderEpoch": 0,
|
|
987
|
+
"leaderId": 0,
|
|
988
|
+
"offlineReplicas": [],
|
|
989
|
+
"partitionIndex": 1,
|
|
990
|
+
"replicaNodes": [
|
|
991
|
+
0,
|
|
992
|
+
],
|
|
993
|
+
},
|
|
994
|
+
{
|
|
995
|
+
"_tag": undefined,
|
|
996
|
+
"errorCode": 0,
|
|
997
|
+
"isrNodes": [
|
|
998
|
+
0,
|
|
999
|
+
],
|
|
1000
|
+
"leaderEpoch": 0,
|
|
1001
|
+
"leaderId": 0,
|
|
1002
|
+
"offlineReplicas": [],
|
|
1003
|
+
"partitionIndex": 9,
|
|
1004
|
+
"replicaNodes": [
|
|
1005
|
+
0,
|
|
1006
|
+
],
|
|
1007
|
+
},
|
|
1008
|
+
{
|
|
1009
|
+
"_tag": undefined,
|
|
1010
|
+
"errorCode": 0,
|
|
1011
|
+
"isrNodes": [
|
|
1012
|
+
0,
|
|
1013
|
+
],
|
|
1014
|
+
"leaderEpoch": 0,
|
|
1015
|
+
"leaderId": 0,
|
|
1016
|
+
"offlineReplicas": [],
|
|
1017
|
+
"partitionIndex": 8,
|
|
1018
|
+
"replicaNodes": [
|
|
1019
|
+
0,
|
|
1020
|
+
],
|
|
1021
|
+
},
|
|
1022
|
+
{
|
|
1023
|
+
"_tag": undefined,
|
|
1024
|
+
"errorCode": 0,
|
|
1025
|
+
"isrNodes": [
|
|
1026
|
+
0,
|
|
1027
|
+
],
|
|
1028
|
+
"leaderEpoch": 0,
|
|
1029
|
+
"leaderId": 0,
|
|
1030
|
+
"offlineReplicas": [],
|
|
1031
|
+
"partitionIndex": 5,
|
|
1032
|
+
"replicaNodes": [
|
|
1033
|
+
0,
|
|
1034
|
+
],
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
"_tag": undefined,
|
|
1038
|
+
"errorCode": 0,
|
|
1039
|
+
"isrNodes": [
|
|
1040
|
+
0,
|
|
1041
|
+
],
|
|
1042
|
+
"leaderEpoch": 0,
|
|
1043
|
+
"leaderId": 0,
|
|
1044
|
+
"offlineReplicas": [],
|
|
1045
|
+
"partitionIndex": 4,
|
|
1046
|
+
"replicaNodes": [
|
|
1047
|
+
0,
|
|
1048
|
+
],
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
"_tag": undefined,
|
|
1052
|
+
"errorCode": 0,
|
|
1053
|
+
"isrNodes": [
|
|
1054
|
+
0,
|
|
1055
|
+
],
|
|
1056
|
+
"leaderEpoch": 0,
|
|
1057
|
+
"leaderId": 0,
|
|
1058
|
+
"offlineReplicas": [],
|
|
1059
|
+
"partitionIndex": 3,
|
|
1060
|
+
"replicaNodes": [
|
|
1061
|
+
0,
|
|
1062
|
+
],
|
|
1063
|
+
},
|
|
1064
|
+
{
|
|
1065
|
+
"_tag": undefined,
|
|
1066
|
+
"errorCode": 0,
|
|
1067
|
+
"isrNodes": [
|
|
1068
|
+
0,
|
|
1069
|
+
],
|
|
1070
|
+
"leaderEpoch": 0,
|
|
1071
|
+
"leaderId": 0,
|
|
1072
|
+
"offlineReplicas": [],
|
|
1073
|
+
"partitionIndex": 7,
|
|
1074
|
+
"replicaNodes": [
|
|
1075
|
+
0,
|
|
1076
|
+
],
|
|
1077
|
+
},
|
|
947
1078
|
],
|
|
948
1079
|
"topicAuthorizedOperations": -2147483648,
|
|
949
1080
|
"topicId": "Any<UUID>",
|
|
@@ -952,7 +1083,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
952
1083
|
}
|
|
953
1084
|
`;
|
|
954
1085
|
|
|
955
|
-
exports[`
|
|
1086
|
+
exports[`Low-level API > should request metadata for all topics 1`] = `
|
|
956
1087
|
{
|
|
957
1088
|
"_tag": undefined,
|
|
958
1089
|
"_tag2": undefined,
|
|
@@ -979,7 +1110,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
979
1110
|
"rack": null,
|
|
980
1111
|
},
|
|
981
1112
|
],
|
|
982
|
-
"clusterId": "4L6g3nShT-eMCtK--X86sw",
|
|
1113
|
+
"clusterId": "Some(4L6g3nShT-eMCtK--X86sw)",
|
|
983
1114
|
"controllerId": 0,
|
|
984
1115
|
"throttleTimeMs": 0,
|
|
985
1116
|
"topics": [
|
|
@@ -987,22 +1118,8 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
987
1118
|
"_tag": undefined,
|
|
988
1119
|
"errorCode": 0,
|
|
989
1120
|
"isInternal": false,
|
|
990
|
-
"name": "
|
|
1121
|
+
"name": "kafka-ts-test-topic",
|
|
991
1122
|
"partitions": [
|
|
992
|
-
{
|
|
993
|
-
"_tag": undefined,
|
|
994
|
-
"errorCode": 0,
|
|
995
|
-
"isrNodes": [
|
|
996
|
-
0,
|
|
997
|
-
],
|
|
998
|
-
"leaderEpoch": 0,
|
|
999
|
-
"leaderId": 0,
|
|
1000
|
-
"offlineReplicas": [],
|
|
1001
|
-
"partitionIndex": 5,
|
|
1002
|
-
"replicaNodes": [
|
|
1003
|
-
0,
|
|
1004
|
-
],
|
|
1005
|
-
},
|
|
1006
1123
|
{
|
|
1007
1124
|
"_tag": undefined,
|
|
1008
1125
|
"errorCode": 0,
|
|
@@ -1054,7 +1171,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1054
1171
|
"leaderEpoch": 0,
|
|
1055
1172
|
"leaderId": 0,
|
|
1056
1173
|
"offlineReplicas": [],
|
|
1057
|
-
"partitionIndex":
|
|
1174
|
+
"partitionIndex": 1,
|
|
1058
1175
|
"replicaNodes": [
|
|
1059
1176
|
0,
|
|
1060
1177
|
],
|
|
@@ -1068,7 +1185,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1068
1185
|
"leaderEpoch": 0,
|
|
1069
1186
|
"leaderId": 0,
|
|
1070
1187
|
"offlineReplicas": [],
|
|
1071
|
-
"partitionIndex":
|
|
1188
|
+
"partitionIndex": 9,
|
|
1072
1189
|
"replicaNodes": [
|
|
1073
1190
|
0,
|
|
1074
1191
|
],
|
|
@@ -1096,7 +1213,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1096
1213
|
"leaderEpoch": 0,
|
|
1097
1214
|
"leaderId": 0,
|
|
1098
1215
|
"offlineReplicas": [],
|
|
1099
|
-
"partitionIndex":
|
|
1216
|
+
"partitionIndex": 5,
|
|
1100
1217
|
"replicaNodes": [
|
|
1101
1218
|
0,
|
|
1102
1219
|
],
|
|
@@ -1110,7 +1227,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1110
1227
|
"leaderEpoch": 0,
|
|
1111
1228
|
"leaderId": 0,
|
|
1112
1229
|
"offlineReplicas": [],
|
|
1113
|
-
"partitionIndex":
|
|
1230
|
+
"partitionIndex": 4,
|
|
1114
1231
|
"replicaNodes": [
|
|
1115
1232
|
0,
|
|
1116
1233
|
],
|
|
@@ -1124,21 +1241,11 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1124
1241
|
"leaderEpoch": 0,
|
|
1125
1242
|
"leaderId": 0,
|
|
1126
1243
|
"offlineReplicas": [],
|
|
1127
|
-
"partitionIndex":
|
|
1244
|
+
"partitionIndex": 3,
|
|
1128
1245
|
"replicaNodes": [
|
|
1129
1246
|
0,
|
|
1130
1247
|
],
|
|
1131
1248
|
},
|
|
1132
|
-
],
|
|
1133
|
-
"topicAuthorizedOperations": -2147483648,
|
|
1134
|
-
"topicId": "Any<UUID>",
|
|
1135
|
-
},
|
|
1136
|
-
{
|
|
1137
|
-
"_tag": undefined,
|
|
1138
|
-
"errorCode": 0,
|
|
1139
|
-
"isInternal": false,
|
|
1140
|
-
"name": "kafka-ts-test-topic",
|
|
1141
|
-
"partitions": [
|
|
1142
1249
|
{
|
|
1143
1250
|
"_tag": undefined,
|
|
1144
1251
|
"errorCode": 0,
|
|
@@ -1148,7 +1255,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1148
1255
|
"leaderEpoch": 0,
|
|
1149
1256
|
"leaderId": 0,
|
|
1150
1257
|
"offlineReplicas": [],
|
|
1151
|
-
"partitionIndex":
|
|
1258
|
+
"partitionIndex": 7,
|
|
1152
1259
|
"replicaNodes": [
|
|
1153
1260
|
0,
|
|
1154
1261
|
],
|
|
@@ -1161,7 +1268,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1161
1268
|
}
|
|
1162
1269
|
`;
|
|
1163
1270
|
|
|
1164
|
-
exports[`
|
|
1271
|
+
exports[`Low-level API > should sync group 1`] = `
|
|
1165
1272
|
{
|
|
1166
1273
|
"_tag": undefined,
|
|
1167
1274
|
"_tag2": undefined,
|
package/src/api/fetch.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { findCodec } from '../codecs';
|
|
1
2
|
import { createApi } from '../utils/api';
|
|
2
3
|
import { Decoder } from '../utils/decoder';
|
|
3
4
|
import { KafkaTSApiError } from '../utils/error';
|
|
@@ -7,6 +8,8 @@ export const enum IsolationLevel {
|
|
|
7
8
|
READ_COMMITTED = 1,
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
export type FetchResponse = Awaited<ReturnType<(typeof FETCH)['response']>>;
|
|
12
|
+
|
|
10
13
|
export const FETCH = createApi({
|
|
11
14
|
apiKey: 1,
|
|
12
15
|
apiVersion: 16,
|
|
@@ -68,7 +71,7 @@ export const FETCH = createApi({
|
|
|
68
71
|
)
|
|
69
72
|
.writeCompactString(data.rackId)
|
|
70
73
|
.writeUVarInt(0),
|
|
71
|
-
response: (decoder) => {
|
|
74
|
+
response: async (decoder) => {
|
|
72
75
|
const result = {
|
|
73
76
|
_tag: decoder.readTagBuffer(),
|
|
74
77
|
throttleTimeMs: decoder.readInt32(),
|
|
@@ -88,56 +91,108 @@ export const FETCH = createApi({
|
|
|
88
91
|
_tag: abortedTransaction.readTagBuffer(),
|
|
89
92
|
})),
|
|
90
93
|
preferredReadReplica: partition.readInt32(),
|
|
91
|
-
records:
|
|
94
|
+
records: decodeRecordBatch(partition),
|
|
92
95
|
_tag: partition.readTagBuffer(),
|
|
93
96
|
})),
|
|
94
97
|
_tag: response.readTagBuffer(),
|
|
95
98
|
})),
|
|
96
99
|
_tag2: decoder.readTagBuffer(),
|
|
97
100
|
};
|
|
101
|
+
|
|
98
102
|
if (result.errorCode) throw new KafkaTSApiError(result.errorCode, null, result);
|
|
99
103
|
result.responses.forEach((response) => {
|
|
100
104
|
response.partitions.forEach((partition) => {
|
|
101
105
|
if (partition.errorCode) throw new KafkaTSApiError(partition.errorCode, null, result);
|
|
102
106
|
});
|
|
103
107
|
});
|
|
104
|
-
|
|
108
|
+
|
|
109
|
+
const decompressedResponses = await Promise.all(
|
|
110
|
+
result.responses.map(async (response) => ({
|
|
111
|
+
...response,
|
|
112
|
+
partitions: await Promise.all(
|
|
113
|
+
response.partitions.map(async (partition) => ({
|
|
114
|
+
...partition,
|
|
115
|
+
records: await Promise.all(
|
|
116
|
+
partition.records.map(async ({ recordsLength, compressedRecords, ...record }) => {
|
|
117
|
+
const { decompress } = findCodec(record.compression);
|
|
118
|
+
const decompressedRecords = await decompress(compressedRecords);
|
|
119
|
+
const decompressedDecoder = new Decoder(
|
|
120
|
+
Buffer.concat([recordsLength, decompressedRecords]),
|
|
121
|
+
);
|
|
122
|
+
return { ...record, records: decodeRecord(decompressedDecoder) };
|
|
123
|
+
}),
|
|
124
|
+
),
|
|
125
|
+
})),
|
|
126
|
+
),
|
|
127
|
+
})),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
return { ...result, responses: decompressedResponses };
|
|
105
131
|
},
|
|
106
132
|
});
|
|
107
133
|
|
|
108
|
-
const
|
|
134
|
+
const decodeRecordBatch = (decoder: Decoder) => {
|
|
109
135
|
const size = decoder.readUVarInt() - 1;
|
|
110
136
|
if (size <= 0) {
|
|
111
137
|
return [];
|
|
112
138
|
}
|
|
113
139
|
|
|
140
|
+
const recordBatchDecoder = new Decoder(decoder.read(size));
|
|
141
|
+
|
|
114
142
|
const results = [];
|
|
115
|
-
while (
|
|
143
|
+
while (recordBatchDecoder.getBufferLength() > recordBatchDecoder.getOffset() + 12) {
|
|
144
|
+
const baseOffset = recordBatchDecoder.readInt64();
|
|
145
|
+
const batchLength = recordBatchDecoder.readInt32();
|
|
146
|
+
if (!batchLength) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const batchDecoder = new Decoder(recordBatchDecoder.read(batchLength));
|
|
151
|
+
|
|
152
|
+
const result = {
|
|
153
|
+
baseOffset,
|
|
154
|
+
batchLength,
|
|
155
|
+
partitionLeaderEpoch: batchDecoder.readInt32(),
|
|
156
|
+
magic: batchDecoder.readInt8(),
|
|
157
|
+
crc: batchDecoder.readUInt32(),
|
|
158
|
+
attributes: batchDecoder.readInt16(),
|
|
159
|
+
lastOffsetDelta: batchDecoder.readInt32(),
|
|
160
|
+
baseTimestamp: batchDecoder.readInt64(),
|
|
161
|
+
maxTimestamp: batchDecoder.readInt64(),
|
|
162
|
+
producerId: batchDecoder.readInt64(),
|
|
163
|
+
producerEpoch: batchDecoder.readInt16(),
|
|
164
|
+
baseSequence: batchDecoder.readInt32(),
|
|
165
|
+
recordsLength: batchDecoder.read(4),
|
|
166
|
+
compressedRecords: batchDecoder.read(),
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const compression = result.attributes & 0x07;
|
|
170
|
+
const timestampType = (result.attributes & 0x08) >> 3 ? 'LogAppendTime' : 'CreateTime';
|
|
171
|
+
const isTransactional = !!((result.attributes & 0x10) >> 4);
|
|
172
|
+
const isControlBatch = !!((result.attributes & 0x20) >> 5);
|
|
173
|
+
const hasDeleteHorizonMs = !!((result.attributes & 0x40) >> 6);
|
|
174
|
+
|
|
116
175
|
results.push({
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
lastOffsetDelta: decoder.readInt32(),
|
|
124
|
-
baseTimestamp: decoder.readInt64(),
|
|
125
|
-
maxTimestamp: decoder.readInt64(),
|
|
126
|
-
producerId: decoder.readInt64(),
|
|
127
|
-
producerEpoch: decoder.readInt16(),
|
|
128
|
-
baseSequence: decoder.readInt32(),
|
|
129
|
-
records: decoder.readRecords((record) => ({
|
|
130
|
-
attributes: record.readInt8(),
|
|
131
|
-
timestampDelta: record.readVarLong(),
|
|
132
|
-
offsetDelta: record.readVarInt(),
|
|
133
|
-
key: record.readVarIntBuffer(),
|
|
134
|
-
value: record.readVarIntBuffer(),
|
|
135
|
-
headers: record.readCompactArray((header) => ({
|
|
136
|
-
key: header.readVarIntBuffer(),
|
|
137
|
-
value: header.readVarIntBuffer(),
|
|
138
|
-
})),
|
|
139
|
-
})),
|
|
176
|
+
...result,
|
|
177
|
+
compression,
|
|
178
|
+
timestampType,
|
|
179
|
+
isTransactional,
|
|
180
|
+
isControlBatch,
|
|
181
|
+
hasDeleteHorizonMs,
|
|
140
182
|
});
|
|
141
183
|
}
|
|
142
184
|
return results;
|
|
143
185
|
};
|
|
186
|
+
|
|
187
|
+
const decodeRecord = (decoder: Decoder) =>
|
|
188
|
+
decoder.readRecords((record) => ({
|
|
189
|
+
attributes: record.readInt8(),
|
|
190
|
+
timestampDelta: record.readVarLong(),
|
|
191
|
+
offsetDelta: record.readVarInt(),
|
|
192
|
+
key: record.readVarIntBuffer(),
|
|
193
|
+
value: record.readVarIntBuffer(),
|
|
194
|
+
headers: record.readVarIntArray((header) => ({
|
|
195
|
+
key: header.readVarIntBuffer(),
|
|
196
|
+
value: header.readVarIntBuffer(),
|
|
197
|
+
})),
|
|
198
|
+
}));
|
package/src/api/index.ts
CHANGED
|
@@ -37,7 +37,9 @@ export const API = {
|
|
|
37
37
|
SYNC_GROUP,
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const apiNameByKey = Object.fromEntries(Object.entries(API).map(([k, v]) => [v.apiKey, k]));
|
|
41
|
+
|
|
42
|
+
export const getApiName = <Request, Response>(api: Api<Request, Response>) => apiNameByKey[api.apiKey];
|
|
41
43
|
|
|
42
44
|
export const API_ERROR = {
|
|
43
45
|
UNKNOWN_SERVER_ERROR: -1,
|
package/src/api/metadata.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createApi } from '../utils/api';
|
|
2
2
|
import { KafkaTSApiError } from '../utils/error';
|
|
3
3
|
|
|
4
|
-
export type Metadata = ReturnType<(typeof METADATA)['response']
|
|
4
|
+
export type Metadata = Awaited<ReturnType<(typeof METADATA)['response']>>;
|
|
5
5
|
|
|
6
6
|
export const METADATA = createApi({
|
|
7
7
|
apiKey: 3,
|
package/src/api/produce.ts
CHANGED
|
@@ -65,10 +65,9 @@ export const PRODUCE = createApi({
|
|
|
65
65
|
.writeVarIntBuffer(record.value)
|
|
66
66
|
.writeVarIntArray(record.headers, (encoder, header) =>
|
|
67
67
|
encoder.writeVarIntBuffer(header.key).writeVarIntBuffer(header.value),
|
|
68
|
-
)
|
|
69
|
-
.value();
|
|
68
|
+
);
|
|
70
69
|
|
|
71
|
-
return encoder.writeVarInt(recordBody.
|
|
70
|
+
return encoder.writeVarInt(recordBody.getByteLength()).writeEncoder(recordBody);
|
|
72
71
|
})
|
|
73
72
|
.value();
|
|
74
73
|
|
|
@@ -76,19 +75,17 @@ export const PRODUCE = createApi({
|
|
|
76
75
|
.writeInt32(partition.partitionLeaderEpoch)
|
|
77
76
|
.writeInt8(2) // magic byte
|
|
78
77
|
.writeUInt32(unsigned(crc32C(batchBody)))
|
|
79
|
-
.write(batchBody)
|
|
80
|
-
.value();
|
|
78
|
+
.write(batchBody);
|
|
81
79
|
|
|
82
80
|
const batch = new Encoder()
|
|
83
81
|
.writeInt64(partition.baseOffset)
|
|
84
|
-
.writeInt32(batchHeader.
|
|
85
|
-
.
|
|
86
|
-
.value();
|
|
82
|
+
.writeInt32(batchHeader.getByteLength())
|
|
83
|
+
.writeEncoder(batchHeader);
|
|
87
84
|
|
|
88
85
|
return encoder
|
|
89
86
|
.writeInt32(partition.index)
|
|
90
|
-
.writeUVarInt(batch.
|
|
91
|
-
.
|
|
87
|
+
.writeUVarInt(batch.getByteLength() + 1) // batch size
|
|
88
|
+
.writeEncoder(batch)
|
|
92
89
|
.writeUVarInt(0);
|
|
93
90
|
})
|
|
94
91
|
.writeUVarInt(0),
|