Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Replace all var declarations with let/const for modern JavaScript standards
- Ensure parseInt calls use explicit radix parameter for clarity and reliability
- Fix precision loss in test data generators by using JavaScript safe integer limits
- Add block scoping to switch statement cases to prevent variable declaration issues

## v0.10.9
- Add support for IPv6 urls
Expand Down
6 changes: 4 additions & 2 deletions bin/generate-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,15 @@ function decoderFn(method) {
case 'timestamp':
println('val = ints.readUInt64BE(buffer, offset); offset += 8;');
break;
case 'bit':
case 'bit': {
const bit = 1 << bitsInARow;
println('val = !!(buffer[offset] & %d);', bit);
if (bitsInARow === 7) {
println('offset++;');
bitsInARow = 0;
} else bitsInARow++;
break;
}
case 'longstr':
println('len = buffer.readUInt32BE(offset); offset += 4;');
println('val = buffer.subarray(offset, offset + len);');
Expand Down Expand Up @@ -644,12 +645,13 @@ function encodePropsFn(props) {
println('ints.writeUInt64BE(buffer, val, offset);');
println('offset += 8;');
break;
case 'shortstr':
case 'shortstr': {
const v = stringLenVar(p);
println('buffer[offset] = %s; offset++;', v);
println("buffer.write(val, offset, 'utf8');");
println('offset += %s;', v);
break;
}
case 'longstr':
println('buffer.writeUInt32BE(val.length, offset);');
println('offset += 4;');
Expand Down
9 changes: 0 additions & 9 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
"noArguments": "off",
"useLiteralKeys": "off"
},
"correctness": {
"noUnusedFunctionParameters": "error",
"noUnusedVariables": "error",
"noInnerDeclarations": "error",
"useParseIntRadix": "error",
"noSwitchDeclarations": "off",
"noInvalidUseBeforeDeclaration": "error",
"noPrecisionLoss": "error"
},
"style": {
"useConst": "off",
"useNodejsImportProtocol": "off",
Expand Down
7 changes: 5 additions & 2 deletions lib/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class Channel extends EventEmitter {
// The broker can send this if e.g., the queue is deleted.
return this.emit('cancel', f.fields);

case defs.ChannelClose:
case defs.ChannelClose: {
// Any remote closure is an error to us. Reject the pending reply
// with the close frame, so it can see whether it was that
// operation that caused it to close.
Expand All @@ -308,12 +308,14 @@ class Channel extends EventEmitter {
const s = stackCapture(emsg);
this.toClosed(s);
return;
}

case defs.BasicFlow:
// RabbitMQ doesn't send this, it just blocks the TCP socket
return this.closeWithError(f.id, 'Flow not implemented', defs.constants.NOT_IMPLEMENTED, new Error('Flow not implemented'));

default: // assume all other things are replies
default: {
// assume all other things are replies
// Resolving the reply may lead to another RPC; to make sure we
// don't hold that up, clear this.reply
const reply = this.reply;
Expand All @@ -328,6 +330,7 @@ class Channel extends EventEmitter {
this.sendImmediately(send.method, send.fields);
}
return reply(null, f);
}
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions lib/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,16 @@ function encodeFieldValue(buffer, value, offset) {
}

switch (type) {
case 'string': // no shortstr in field tables
case 'string': {
// no shortstr in field tables
const len = Buffer.byteLength(val, 'utf8');
tag('S');
buffer.writeUInt32BE(len, offset);
offset += 4;
buffer.write(val, offset, 'utf8');
offset += len;
break;
}
case 'object':
if (val === null) {
tag('V');
Expand Down Expand Up @@ -290,13 +292,15 @@ function decodeFields(slice) {
val = slice.readUInt32BE(offset);
offset += 4;
break;
case 'D': // only positive decimals, apparently.
case 'D': {
// only positive decimals, apparently.
const places = slice[offset];
offset++;
const digits = slice.readUInt32BE(offset);
offset += 4;
val = {'!': 'decimal', value: {places: places, digits: digits}};
break;
}
case 'T':
val = ints.readUInt64BE(slice, offset);
offset += 8;
Expand Down
3 changes: 2 additions & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class Connection extends EventEmitter {
case defs.ConnectionClose:
bail(new Error(fmt('Handshake terminated by server: %s', closeMsg(reply))));
break;
case defs.ConnectionTune:
case defs.ConnectionTune: {
const fields = reply.fields;
tunedOptions.frameMax = negotiate(fields.frameMax, allFields.frameMax);
tunedOptions.channelMax = negotiate(fields.channelMax, allFields.channelMax);
Expand All @@ -173,6 +173,7 @@ class Connection extends EventEmitter {
}
expect(defs.ConnectionOpenOk, onOpenOk);
break;
}
default:
bail(
new Error(
Expand Down
3 changes: 2 additions & 1 deletion test/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,13 @@ function removeExplicitTypes(input) {
case 'decimal':
case 'float':
return input;
case undefined:
case undefined: {
const newObj = {};
for (const k in input) {
newObj[k] = removeExplicitTypes(input[k]);
}
return newObj;
}
default:
return input.value;
}
Expand Down