@platformatic/kafka 1.26.0 → 1.27.0-alpha.1
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/dist/native.wasm +0 -0
- package/dist/protocol/compression.js +6 -45
- package/dist/protocol/crc32c.js +3 -4
- package/dist/protocol/native.d.ts +8 -0
- package/dist/protocol/native.js +48 -0
- package/dist/typescript-4/dist/protocol/native.d.ts +8 -0
- package/dist/version.js +1 -1
- package/package.json +10 -9
package/dist/native.wasm
ADDED
|
Binary file
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
1
|
import zlib from 'node:zlib';
|
|
3
2
|
import { UnsupportedCompressionError } from "../errors.js";
|
|
4
3
|
import { DynamicBuffer } from "./dynamic-buffer.js";
|
|
5
|
-
|
|
4
|
+
import { lz4Compress, lz4Decompress, snappyCompress, snappyDecompress } from "./native.js";
|
|
6
5
|
const { zstdCompressSync, zstdDecompressSync, gzipSync, gunzipSync } = zlib;
|
|
7
6
|
export const CompressionAlgorithms = {
|
|
8
7
|
NONE: 'none',
|
|
@@ -13,34 +12,12 @@ export const CompressionAlgorithms = {
|
|
|
13
12
|
};
|
|
14
13
|
export const allowedCompressionsAlgorithms = Object.values(CompressionAlgorithms);
|
|
15
14
|
function ensureBuffer(data) {
|
|
16
|
-
return DynamicBuffer.isDynamicBuffer(data) ? data.
|
|
17
|
-
}
|
|
18
|
-
let snappyCompressSync;
|
|
19
|
-
let snappyDecompressSync;
|
|
20
|
-
let lz4CompressFrameSync;
|
|
21
|
-
let lz4DecompressFrameSync;
|
|
22
|
-
function loadSnappy() {
|
|
23
|
-
try {
|
|
24
|
-
const snappy = require('snappy');
|
|
25
|
-
snappyCompressSync = snappy.compressSync;
|
|
26
|
-
snappyDecompressSync = snappy.uncompressSync;
|
|
27
|
-
/* c8 ignore next 5 - In tests snappy is always available */
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
throw new UnsupportedCompressionError('Cannot load snappy module, which is an optionalDependency. Please check your local installation.');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function loadLZ4() {
|
|
34
|
-
try {
|
|
35
|
-
const lz4 = require('lz4-napi');
|
|
36
|
-
lz4CompressFrameSync = lz4.compressFrameSync;
|
|
37
|
-
lz4DecompressFrameSync = lz4.decompressFrameSync;
|
|
38
|
-
/* c8 ignore next 5 - In tests lz4-napi is always available */
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
throw new UnsupportedCompressionError('Cannot load lz4-napi module, which is an optionalDependency. Please check your local installation.');
|
|
42
|
-
}
|
|
15
|
+
return DynamicBuffer.isDynamicBuffer(data) ? data.buffer : data;
|
|
43
16
|
}
|
|
17
|
+
const snappyCompressSync = snappyCompress;
|
|
18
|
+
const snappyDecompressSync = snappyDecompress;
|
|
19
|
+
const lz4CompressFrameSync = lz4Compress;
|
|
20
|
+
const lz4DecompressFrameSync = lz4Decompress;
|
|
44
21
|
export const compressionsAlgorithms = {
|
|
45
22
|
/* c8 ignore next 8 - 'none' is actually never used but this is to please Typescript */
|
|
46
23
|
none: {
|
|
@@ -65,17 +42,9 @@ export const compressionsAlgorithms = {
|
|
|
65
42
|
},
|
|
66
43
|
snappy: {
|
|
67
44
|
compressSync(data) {
|
|
68
|
-
/* c8 ignore next 4 - In tests snappy is always available */
|
|
69
|
-
if (!snappyCompressSync) {
|
|
70
|
-
loadSnappy();
|
|
71
|
-
}
|
|
72
45
|
return snappyCompressSync(ensureBuffer(data));
|
|
73
46
|
},
|
|
74
47
|
decompressSync(data) {
|
|
75
|
-
/* c8 ignore next 4 - In tests snappy is always available */
|
|
76
|
-
if (!snappyDecompressSync) {
|
|
77
|
-
loadSnappy();
|
|
78
|
-
}
|
|
79
48
|
return snappyDecompressSync(ensureBuffer(data));
|
|
80
49
|
},
|
|
81
50
|
bitmask: 2,
|
|
@@ -83,17 +52,9 @@ export const compressionsAlgorithms = {
|
|
|
83
52
|
},
|
|
84
53
|
lz4: {
|
|
85
54
|
compressSync(data) {
|
|
86
|
-
/* c8 ignore next 4 - In tests lz4-napi is always available */
|
|
87
|
-
if (!lz4CompressFrameSync) {
|
|
88
|
-
loadLZ4();
|
|
89
|
-
}
|
|
90
55
|
return lz4CompressFrameSync(ensureBuffer(data));
|
|
91
56
|
},
|
|
92
57
|
decompressSync(data) {
|
|
93
|
-
/* c8 ignore next 4 - In tests lz4-napi is always available */
|
|
94
|
-
if (!lz4DecompressFrameSync) {
|
|
95
|
-
loadLZ4();
|
|
96
|
-
}
|
|
97
58
|
return lz4DecompressFrameSync(ensureBuffer(data));
|
|
98
59
|
},
|
|
99
60
|
bitmask: 3,
|
package/dist/protocol/crc32c.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Based on the work from: https://github.com/tulios/kafkajs/blob/master/src/protocol/recordBatch/crc32C/crc32C.js
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { DynamicBuffer } from "./dynamic-buffer.js";
|
|
4
|
+
import { crc32c as wasmCRC32C } from "./native.js";
|
|
4
5
|
/* prettier-ignore */
|
|
5
6
|
const CRC = [
|
|
6
7
|
0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4,
|
|
@@ -85,9 +86,7 @@ export function loadNativeCRC32C() {
|
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
export function jsCRC32C(data) {
|
|
88
|
-
const bytes = DynamicBuffer.isDynamicBuffer(data)
|
|
89
|
-
? data.buffer
|
|
90
|
-
: new Uint8Array(data);
|
|
89
|
+
const bytes = DynamicBuffer.isDynamicBuffer(data) ? data.buffer : data;
|
|
91
90
|
let crc = 0xffffffff;
|
|
92
91
|
for (let i = 0, len = bytes.length; i < len; ++i) {
|
|
93
92
|
crc = CRC[(crc ^ bytes[i]) & 0xff] ^ (crc >>> 8);
|
|
@@ -95,4 +94,4 @@ export function jsCRC32C(data) {
|
|
|
95
94
|
return (crc ^ 0xffffffff) >>> 0;
|
|
96
95
|
}
|
|
97
96
|
/* c8 ignore next - Hard to test */
|
|
98
|
-
export const crc32c = loadNativeCRC32C() ??
|
|
97
|
+
export const crc32c = loadNativeCRC32C() ?? wasmCRC32C;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DynamicBuffer } from './dynamic-buffer.ts';
|
|
2
|
+
export declare function prepareInput(data: Buffer | Uint8Array | DynamicBuffer): void;
|
|
3
|
+
export declare function prepareOutput(combined: bigint): Buffer;
|
|
4
|
+
export declare function crc32c(data: Buffer | Uint8Array | DynamicBuffer): number;
|
|
5
|
+
export declare function lz4Compress(data: Buffer | DynamicBuffer): Buffer;
|
|
6
|
+
export declare function lz4Decompress(data: Buffer | DynamicBuffer): Buffer;
|
|
7
|
+
export declare function snappyCompress(data: Buffer | DynamicBuffer): Buffer;
|
|
8
|
+
export declare function snappyDecompress(data: Buffer | DynamicBuffer): Buffer;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { DynamicBuffer } from "./dynamic-buffer.js";
|
|
3
|
+
// @ts-expect-error - Buffer[Symbol.species] is not typed in Node.js types
|
|
4
|
+
const FastBuffer = Buffer[Symbol.species];
|
|
5
|
+
const wasm = readFileSync(new URL('../../dist/native.wasm', import.meta.url));
|
|
6
|
+
const wasmModule = new WebAssembly.Module(wasm);
|
|
7
|
+
const instance = new WebAssembly.Instance(wasmModule);
|
|
8
|
+
const { alloc, crc32c: _crc32c, dealloc, lz4_compress: _lz4Compress, lz4_decompress: _lz4Decompress, memory, snappy_compress: _snappyCompress, snappy_decompress: _snappyDecompress } = instance.exports;
|
|
9
|
+
let currentBufferLength = 4096;
|
|
10
|
+
let currentBufferOffset = alloc(currentBufferLength);
|
|
11
|
+
let currentBuffer = new Uint8Array(memory.buffer, currentBufferOffset, currentBufferLength);
|
|
12
|
+
export function prepareInput(data) {
|
|
13
|
+
const input = DynamicBuffer.isDynamicBuffer(data) ? data.buffer : data;
|
|
14
|
+
if (currentBuffer.length < data.length) {
|
|
15
|
+
dealloc(currentBufferOffset, currentBufferLength);
|
|
16
|
+
currentBufferLength = data.length;
|
|
17
|
+
currentBufferOffset = alloc(currentBufferLength);
|
|
18
|
+
currentBuffer = new Uint8Array(memory.buffer, currentBufferOffset, currentBufferLength);
|
|
19
|
+
}
|
|
20
|
+
currentBuffer.set(input);
|
|
21
|
+
}
|
|
22
|
+
export function prepareOutput(combined) {
|
|
23
|
+
const len = Number(BigInt.asUintN(32, combined));
|
|
24
|
+
const ptr = Number(combined >> 32n);
|
|
25
|
+
const output = Buffer.from(new FastBuffer(memory.buffer, ptr, len));
|
|
26
|
+
dealloc(ptr, len);
|
|
27
|
+
return output;
|
|
28
|
+
}
|
|
29
|
+
export function crc32c(data) {
|
|
30
|
+
prepareInput(data);
|
|
31
|
+
return _crc32c(currentBufferOffset, data.length) >>> 0;
|
|
32
|
+
}
|
|
33
|
+
export function lz4Compress(data) {
|
|
34
|
+
prepareInput(data);
|
|
35
|
+
return prepareOutput(_lz4Compress(currentBufferOffset, data.length));
|
|
36
|
+
}
|
|
37
|
+
export function lz4Decompress(data) {
|
|
38
|
+
prepareInput(data);
|
|
39
|
+
return prepareOutput(_lz4Decompress(currentBufferOffset, data.length));
|
|
40
|
+
}
|
|
41
|
+
export function snappyCompress(data) {
|
|
42
|
+
prepareInput(data);
|
|
43
|
+
return prepareOutput(_snappyCompress(currentBufferOffset, data.length));
|
|
44
|
+
}
|
|
45
|
+
export function snappyDecompress(data) {
|
|
46
|
+
prepareInput(data);
|
|
47
|
+
return prepareOutput(_snappyDecompress(currentBufferOffset, data.length));
|
|
48
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DynamicBuffer } from "./dynamic-buffer";
|
|
2
|
+
export declare function prepareInput(data: Buffer | Uint8Array | DynamicBuffer): void;
|
|
3
|
+
export declare function prepareOutput(combined: bigint): Buffer;
|
|
4
|
+
export declare function crc32c(data: Buffer | Uint8Array | DynamicBuffer): number;
|
|
5
|
+
export declare function lz4Compress(data: Buffer | DynamicBuffer): Buffer;
|
|
6
|
+
export declare function lz4Decompress(data: Buffer | DynamicBuffer): Buffer;
|
|
7
|
+
export declare function snappyCompress(data: Buffer | DynamicBuffer): Buffer;
|
|
8
|
+
export declare function snappyDecompress(data: Buffer | DynamicBuffer): Buffer;
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = "@platformatic/kafka";
|
|
2
|
-
export const version = "1.
|
|
2
|
+
export const version = "1.27.0-alpha.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/kafka",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.27.0-alpha.1",
|
|
4
4
|
"description": "Modern and performant client for Apache Kafka",
|
|
5
5
|
"homepage": "https://github.com/platformatic/kafka",
|
|
6
6
|
"author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
|
|
@@ -32,9 +32,7 @@
|
|
|
32
32
|
"scule": "^1.3.0"
|
|
33
33
|
},
|
|
34
34
|
"optionalDependencies": {
|
|
35
|
-
"@node-rs/crc32": "^1.10.6"
|
|
36
|
-
"lz4-napi": "^2.9.0",
|
|
37
|
-
"snappy": "^7.3.3"
|
|
35
|
+
"@node-rs/crc32": "^1.10.6"
|
|
38
36
|
},
|
|
39
37
|
"devDependencies": {
|
|
40
38
|
"@babel/generator": "^7.28.5",
|
|
@@ -44,11 +42,12 @@
|
|
|
44
42
|
"@confluentinc/kafka-javascript": "^1.5.0",
|
|
45
43
|
"@opentelemetry/instrumentation": "^0.210.0",
|
|
46
44
|
"@platformatic/rdkafka": "^4.0.0",
|
|
45
|
+
"@swc-node/register": "^1.11.1",
|
|
47
46
|
"@types/babel__generator": "^7.27.0",
|
|
48
47
|
"@types/babel__traverse": "^7.28.0",
|
|
49
48
|
"@types/debug": "^4.1.12",
|
|
50
49
|
"@types/kerberos": "^1.1.5",
|
|
51
|
-
"@types/node": "^22.18.
|
|
50
|
+
"@types/node": "^22.18.8",
|
|
52
51
|
"@types/semver": "^7.7.1",
|
|
53
52
|
"@watchable/unpromise": "^1.0.2",
|
|
54
53
|
"avsc": "^5.7.9",
|
|
@@ -62,12 +61,14 @@
|
|
|
62
61
|
"json5": "^2.2.3",
|
|
63
62
|
"kafkajs": "^2.2.4",
|
|
64
63
|
"kerberos": "^2.2.2",
|
|
64
|
+
"lz4-napi": "^2.9.0",
|
|
65
65
|
"neostandard": "^0.12.2",
|
|
66
66
|
"parse5": "^7.3.0",
|
|
67
67
|
"prettier": "^3.6.2",
|
|
68
68
|
"prettier-plugin-space-before-function-paren": "^0.0.8",
|
|
69
69
|
"prom-client": "^15.1.3",
|
|
70
70
|
"semver": "^7.7.2",
|
|
71
|
+
"snappy": "^7.3.3",
|
|
71
72
|
"table": "^6.9.0",
|
|
72
73
|
"typescript": "^5.9.2"
|
|
73
74
|
},
|
|
@@ -83,16 +84,16 @@
|
|
|
83
84
|
},
|
|
84
85
|
"scripts": {
|
|
85
86
|
"build": "rm -rf dist && tsc -p tsconfig.base.json",
|
|
86
|
-
"
|
|
87
|
+
"build:native": "cd native && docker compose up",
|
|
88
|
+
"postbuild": "./scripts/node scripts/postbuild.ts && npm run build:native",
|
|
87
89
|
"lint": "eslint --cache",
|
|
88
90
|
"typecheck": "tsc -p . --noEmit",
|
|
89
91
|
"format": "prettier -w benchmarks playground src test",
|
|
90
|
-
"test": "c8 -c test/config/c8-local.json node --
|
|
91
|
-
"test:ci": "c8 -c test/config/c8-ci.json node --
|
|
92
|
+
"test": "c8 -c test/config/c8-local.json ./scripts/node --test --test-reporter=cleaner-spec-reporter 'test/*.test.ts' 'test/*/*.test.ts' 'test/*/*/*.test.ts'",
|
|
93
|
+
"test:ci": "c8 -c test/config/c8-ci.json ./scripts/node --test --test-reporter=cleaner-spec-reporter 'test/*.test.ts' 'test/*/*.test.ts' 'test/*/*/*.test.ts'",
|
|
92
94
|
"test:docker:up": "docker-compose up -d --wait",
|
|
93
95
|
"test:docker:down": "docker-compose down",
|
|
94
96
|
"ci": "npm run build && npm run lint && npm run test:ci",
|
|
95
|
-
"ci:v20": "npm run lint && rm -rf dist && tsc -p tsconfig.json && node dist/scripts/postbuild.js && cd dist && node --env-file=../test/config/env --no-warnings --test --test-timeout=600000",
|
|
96
97
|
"generate:apis": "node scripts/generate-apis.ts",
|
|
97
98
|
"generate:errors": "node scripts/generate-errors.ts",
|
|
98
99
|
"create:api": "node scripts/create-api.ts"
|