Skip to content

Commit 1dfdf04

Browse files
committed
fix: changeFields parsing
1 parent 74cc797 commit 1dfdf04

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "salesforce-pubsub-api-client",
3-
"version": "2.4.0",
3+
"version": "2.4.1",
44
"type": "module",
55
"description": "A node client for the Salesforce Pub/Sub API",
66
"author": "pozil",
@@ -22,21 +22,21 @@
2222
"prepublishOnly": "npm run build"
2323
},
2424
"dependencies": {
25-
"@grpc/grpc-js": "^1.8.7",
26-
"@grpc/proto-loader": "^0.7.4",
25+
"@grpc/grpc-js": "^1.8.11",
26+
"@grpc/proto-loader": "^0.7.5",
2727
"avro-js": "^1.11.1",
2828
"certifi": "^14.5.15",
2929
"dotenv": "^16.0.3",
3030
"jsforce": "^1.11.0",
31-
"undici": "^5.16.0"
31+
"undici": "^5.20.0"
3232
},
3333
"devDependencies": {
3434
"@chialab/esbuild-plugin-meta-url": "^0.17.2",
35-
"eslint": "^8.33.0",
35+
"eslint": "^8.35.0",
3636
"husky": "^8.0.3",
37-
"lint-staged": "^13.1.0",
38-
"prettier": "^2.8.1",
39-
"tsup": "^6.5.0",
37+
"lint-staged": "^13.1.2",
38+
"prettier": "^2.8.4",
39+
"tsup": "^6.6.3",
4040
"typescript": "^4.9.5"
4141
},
4242
"lint-staged": {

src/eventParser.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,23 @@ function parseFieldBitmaps(allFields, fieldBitmapsAsHex) {
4747
if (fieldBitmapsAsHex.length === 0) {
4848
return [];
4949
}
50+
5051
let fieldNames = [];
5152
// Replace top field level bitmap with list of fields
5253
if (fieldBitmapsAsHex[0].startsWith('0x')) {
53-
fieldNames = fieldNames.concat(
54-
getFieldNamesFromBitmap(allFields, fieldBitmapsAsHex[0])
55-
);
54+
fieldNames = getFieldNamesFromBitmap(allFields, fieldBitmapsAsHex[0]);
5655
}
5756
// Process compound fields
58-
if (fieldBitmapsAsHex[fieldBitmapsAsHex.length - 1].indexOf('-') !== -1) {
57+
if (
58+
fieldBitmapsAsHex.length > 1 &&
59+
fieldBitmapsAsHex[fieldBitmapsAsHex.length - 1].indexOf('-') !== -1
60+
) {
5961
fieldBitmapsAsHex.forEach((fieldBitmapAsHex) => {
6062
const bitmapMapStrings = fieldBitmapAsHex.split('-');
6163
// Ignore top level field bitmap
6264
if (bitmapMapStrings.length >= 2) {
63-
const parentField = allFields[parseInt(bitmapMapStrings[0])];
65+
const parentField =
66+
allFields[parseInt(bitmapMapStrings[0], 10)];
6467
const childFields = getChildFields(parentField);
6568
const childFieldNames = getFieldNamesFromBitmap(
6669
childFields,
@@ -83,8 +86,6 @@ function getChildFields(parentField) {
8386
types.forEach((type) => {
8487
if (type instanceof avro.types.RecordType) {
8588
fields = fields.concat(type.getFields());
86-
} else if (type instanceof avro.types.NullType) {
87-
fields.push(null);
8889
}
8990
});
9091
return fields;
@@ -94,10 +95,12 @@ function getChildFields(parentField) {
9495
* Loads field names from a bitmap
9596
* @param {Field[]} fields list of Avro Field
9697
* @param {string} fieldBitmapAsHex
98+
* @returns {string[]} field names
9799
*/
98100
function getFieldNamesFromBitmap(fields, fieldBitmapAsHex) {
101+
// Convert hex to binary and reverse bits
99102
let binValue = hexToBin(fieldBitmapAsHex);
100-
binValue = reverseBytes(binValue); // Reverse byte order to match expected format
103+
binValue = binValue.split('').reverse().join('');
101104
// Use bitmap to figure out field names based on index
102105
const fieldNames = [];
103106
for (let i = 0; i < binValue.length && i < fields.length; i++) {
@@ -108,14 +111,6 @@ function getFieldNamesFromBitmap(fields, fieldBitmapAsHex) {
108111
return fieldNames;
109112
}
110113

111-
function reverseBytes(input) {
112-
let output = '';
113-
for (let i = input.length / 8 - 1; i >= 0; i--) {
114-
output += input.substring(i * 8, (i + 1) * 8);
115-
}
116-
return output;
117-
}
118-
119114
/**
120115
* Decodes the value of a replay ID from a buffer
121116
* @param {Buffer} encodedReplayId
@@ -139,7 +134,7 @@ export function encodeReplayId(replayId) {
139134
/**
140135
* Converts a hexadecimal string into a string binary representation
141136
* @param {string} hex
142-
* @returns
137+
* @returns {string}
143138
*/
144139
function hexToBin(hex) {
145140
let bin = hex.substring(2); // Remove 0x prefix

0 commit comments

Comments
 (0)