diff --git a/CHANGELOG.md b/CHANGELOG.md index 42f3495d..755fdace 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - Enable useArrowFunction lint rule to prefer arrow functions for cleaner syntax - Enable noUselessCatch lint rule to prevent useless catch blocks that only rethrow errors - Enable noArguments rule to enforce modern rest parameters instead of legacy arguments object +- Enable bracketSpacing formatting rule to add spaces inside object literals ## v0.10.9 - Add support for IPv6 urls diff --git a/bin/generate-defs.js b/bin/generate-defs.js index 5d4a979b..22103ded 100644 --- a/bin/generate-defs.js +++ b/bin/generate-defs.js @@ -53,7 +53,7 @@ function initial(part) { function argument(a) { const type = a.type || domains[a.domain]; const friendlyName = propertyName(a.name); - return {type: type, name: friendlyName, default: a['default-value']}; + return { type: type, name: friendlyName, default: a['default-value'] }; } const domains = {}; @@ -529,7 +529,7 @@ function decoderFn(method) { } function infoObj(thing) { - const info = JSON.stringify({id: thing.id, classId: thing.clazzId, methodId: thing.methodId, name: thing.name, args: thing.args}); + const info = JSON.stringify({ id: thing.id, classId: thing.clazzId, methodId: thing.methodId, name: thing.name, args: thing.args }); println('var %s = module.exports.%s = %s;', thing.info, thing.info, info); } diff --git a/biome.json b/biome.json index 8908255d..56d8b492 100644 --- a/biome.json +++ b/biome.json @@ -36,7 +36,7 @@ "formatter": { "arrowParentheses": "always", "bracketSameLine": false, - "bracketSpacing": false, + "bracketSpacing": true, "jsxQuoteStyle": "double", "quoteProperties": "asNeeded", "quoteStyle": "single", diff --git a/examples/direct_reply_to_client.js b/examples/direct_reply_to_client.js index 53fdfdb0..f39c3567 100644 --- a/examples/direct_reply_to_client.js +++ b/examples/direct_reply_to_client.js @@ -15,10 +15,10 @@ const queue = 'rpc_queue'; await channel.close(); await connection.close(); }, - {noAck: true}, + { noAck: true }, ); - await channel.assertQueue(queue, {durable: false}); + await channel.assertQueue(queue, { durable: false }); channel.sendToQueue(queue, Buffer.from(' [X] ping'), { replyTo: 'amq.rabbitmq.reply-to', diff --git a/examples/direct_reply_to_server.js b/examples/direct_reply_to_server.js index ee60b442..c96f70e2 100644 --- a/examples/direct_reply_to_server.js +++ b/examples/direct_reply_to_server.js @@ -13,14 +13,14 @@ const queue = 'rpc_queue'; await connection.close(); }); - await channel.assertQueue(queue, {durable: false}); + await channel.assertQueue(queue, { durable: false }); await channel.consume( queue, (message) => { console.log(message.content.toString()); channel.sendToQueue(message.properties.replyTo, Buffer.from(' [.] pong')); }, - {noAck: true}, + { noAck: true }, ); console.log(' [x] To exit press CTRL+C.'); diff --git a/examples/headers.js b/examples/headers.js index 0f6ff7b9..493b546f 100755 --- a/examples/headers.js +++ b/examples/headers.js @@ -11,8 +11,8 @@ const amqp = require('../'); await connection.close(); }); - const {exchange} = await channel.assertExchange('matching exchange', 'headers'); - const {queue} = await channel.assertQueue(); + const { exchange } = await channel.assertExchange('matching exchange', 'headers'); + const { queue } = await channel.assertQueue(); // When using a headers exchange, the headers to be matched go in // the binding arguments. The routing key is ignore, so best left @@ -32,12 +32,12 @@ const amqp = require('../'); (message) => { console.log(message.content.toString()); }, - {noAck: true}, + { noAck: true }, ); - channel.publish(exchange, '', Buffer.from('hello'), {headers: {baz: 'boo'}}); - channel.publish(exchange, '', Buffer.from('hello'), {headers: {foo: 'bar'}}); - channel.publish(exchange, '', Buffer.from('lost'), {headers: {meh: 'nah'}}); + channel.publish(exchange, '', Buffer.from('hello'), { headers: { baz: 'boo' } }); + channel.publish(exchange, '', Buffer.from('hello'), { headers: { foo: 'bar' } }); + channel.publish(exchange, '', Buffer.from('lost'), { headers: { meh: 'nah' } }); console.log(' [x] To exit press CTRL+C.'); })(); diff --git a/examples/receive_generator.js b/examples/receive_generator.js index 9f88970f..847dcb3c 100644 --- a/examples/receive_generator.js +++ b/examples/receive_generator.js @@ -18,7 +18,7 @@ co(function* () { channel.sendToQueue(q, Buffer.from(msg)); console.log(" [x] Sent '%s'", msg); // consume the message - yield channel.consume(q, myConsumer, {noAck: true}); + yield channel.consume(q, myConsumer, { noAck: true }); }).catch((err) => { console.warn('Error:', err); }); diff --git a/examples/tutorials/callback_api/emit_log.js b/examples/tutorials/callback_api/emit_log.js index 71d4533e..e50da0bd 100755 --- a/examples/tutorials/callback_api/emit_log.js +++ b/examples/tutorials/callback_api/emit_log.js @@ -9,7 +9,7 @@ amqp.connect((err, connection) => { if (err) return bail(err); connection.createChannel((err, channel) => { if (err) return bail(err, connection); - channel.assertExchange(exchange, 'fanout', {durable: false}, (err) => { + channel.assertExchange(exchange, 'fanout', { durable: false }, (err) => { if (err) return bail(err, connection); channel.publish(exchange, '', Buffer.from(text)); console.log(" [x] Sent '%s'", text); diff --git a/examples/tutorials/callback_api/emit_log_direct.js b/examples/tutorials/callback_api/emit_log_direct.js index 0d2b243e..dc763429 100755 --- a/examples/tutorials/callback_api/emit_log_direct.js +++ b/examples/tutorials/callback_api/emit_log_direct.js @@ -11,7 +11,7 @@ amqp.connect((err, connection) => { if (err) return bail(err); connection.createChannel((err, channel) => { if (err) return bail(err, connection); - channel.assertExchange(exchange, 'direct', {durable: false}, (err) => { + channel.assertExchange(exchange, 'direct', { durable: false }, (err) => { if (err) return bail(err, connection); channel.publish(exchange, routingKey, Buffer.from(text)); console.log(" [x] Sent '%s'", text); diff --git a/examples/tutorials/callback_api/emit_log_topic.js b/examples/tutorials/callback_api/emit_log_topic.js index 8c427b2f..5afd9e16 100755 --- a/examples/tutorials/callback_api/emit_log_topic.js +++ b/examples/tutorials/callback_api/emit_log_topic.js @@ -11,7 +11,7 @@ amqp.connect((err, connection) => { if (err) return bail(err); connection.createChannel((err, channel) => { if (err) return bail(err, connection); - channel.assertExchange(exchange, 'topic', {durable: false}, (err) => { + channel.assertExchange(exchange, 'topic', { durable: false }, (err) => { if (err) return bail(err, connection); channel.publish(exchange, routingKey, Buffer.from(text)); console.log(" [x] Sent '%s'", text); diff --git a/examples/tutorials/callback_api/new_task.js b/examples/tutorials/callback_api/new_task.js index d1d725bf..9f8d2724 100755 --- a/examples/tutorials/callback_api/new_task.js +++ b/examples/tutorials/callback_api/new_task.js @@ -9,9 +9,9 @@ amqp.connect((err, connection) => { if (err) return bail(err); connection.createChannel((err, channel) => { if (err) return bail(err, connection); - channel.assertQueue(queue, {durable: true}, (err) => { + channel.assertQueue(queue, { durable: true }, (err) => { if (err) return bails(err, connection); - channel.sendToQueue(queue, Buffer.from(text), {persistent: true}); + channel.sendToQueue(queue, Buffer.from(text), { persistent: true }); console.log(" [x] Sent '%s'", text); channel.close(() => { connection.close(); diff --git a/examples/tutorials/callback_api/receive.js b/examples/tutorials/callback_api/receive.js index 5c8f9503..6f7fe294 100755 --- a/examples/tutorials/callback_api/receive.js +++ b/examples/tutorials/callback_api/receive.js @@ -15,7 +15,7 @@ amqp.connect((err, connection) => { }); }); - channel.assertQueue(queue, {durable: false}, (err) => { + channel.assertQueue(queue, { durable: false }, (err) => { if (err) return bail(err, connection); channel.consume( queue, @@ -23,7 +23,7 @@ amqp.connect((err, connection) => { if (message) console.log(" [x] Received '%s'", message.content.toString()); else console.warn(' [x] Consumer cancelled'); }, - {noAck: true}, + { noAck: true }, (err) => { if (err) return bail(err, connection); console.log(' [*] Waiting for logs. To exit press CTRL+C.'); diff --git a/examples/tutorials/callback_api/receive_logs.js b/examples/tutorials/callback_api/receive_logs.js index 28453695..de941389 100755 --- a/examples/tutorials/callback_api/receive_logs.js +++ b/examples/tutorials/callback_api/receive_logs.js @@ -15,9 +15,9 @@ amqp.connect((err, connection) => { }); }); - channel.assertExchange(exchange, 'fanout', {durable: false}, (err, {queue: _queue}) => { + channel.assertExchange(exchange, 'fanout', { durable: false }, (err, { queue: _queue }) => { if (err) return bail(err, connection); - channel.assertQueue('', {exclusive: true}, (err, {queue}) => { + channel.assertQueue('', { exclusive: true }, (err, { queue }) => { if (err) return bail(err, connection); channel.bindQueue(queue, exchange, '', {}, (err) => { if (err) return bail(err, connection); @@ -27,7 +27,7 @@ amqp.connect((err, connection) => { if (message) console.log(" [x] '%s'", message.content.toString()); else console.warn(' [x] Consumer cancelled'); }, - {noAck: true}, + { noAck: true }, (err) => { if (err) return bail(err, connection); console.log(' [*] Waiting for logs. To exit press CTRL+C.'); diff --git a/examples/tutorials/callback_api/receive_logs_direct.js b/examples/tutorials/callback_api/receive_logs_direct.js index 55ab1d6a..cd189497 100755 --- a/examples/tutorials/callback_api/receive_logs_direct.js +++ b/examples/tutorials/callback_api/receive_logs_direct.js @@ -1,7 +1,7 @@ #!/usr/bin/env node const amqp = require('amqplib/callback_api'); -const {basename} = require('node:path'); +const { basename } = require('node:path'); const exchange = 'direct_logs'; const severities = process.argv.slice(2); @@ -21,9 +21,9 @@ amqp.connect((err, connection) => { }); }); - channel.assertExchange(exchange, 'direct', {durable: false}, (err) => { + channel.assertExchange(exchange, 'direct', { durable: false }, (err) => { if (err) return bail(err, connection); - channel.assertQueue('', {exclusive: true}, (err, {queue}) => { + channel.assertQueue('', { exclusive: true }, (err, { queue }) => { if (err) return bail(err, connection); channel.consume( queue, @@ -31,7 +31,7 @@ amqp.connect((err, connection) => { if (message) console.log(" [x] %s:'%s'", message.fields.routingKey, message.content.toString()); else console.warn(' [x] Consumer cancelled'); }, - {noAck: true}, + { noAck: true }, (err) => { if (err) return bail(err, connection); console.log(' [*] Waiting for logs. To exit press CTRL+C.'); diff --git a/examples/tutorials/callback_api/receive_logs_topic.js b/examples/tutorials/callback_api/receive_logs_topic.js index 7d4d6de1..99478109 100755 --- a/examples/tutorials/callback_api/receive_logs_topic.js +++ b/examples/tutorials/callback_api/receive_logs_topic.js @@ -1,7 +1,7 @@ #!/usr/bin/env node const amqp = require('amqplib/callback_api'); -const {basename} = require('node:path'); +const { basename } = require('node:path'); const exchange = 'topic_logs'; const severities = process.argv.slice(2); @@ -21,9 +21,9 @@ amqp.connect((err, connection) => { }); }); - channel.assertExchange(exchange, 'topic', {durable: false}, (err) => { + channel.assertExchange(exchange, 'topic', { durable: false }, (err) => { if (err) return bail(err, connection); - channel.assertQueue('', {exclusive: true}, (err, {queue}) => { + channel.assertQueue('', { exclusive: true }, (err, { queue }) => { if (err) return bail(err, connection); channel.consume( queue, @@ -31,7 +31,7 @@ amqp.connect((err, connection) => { if (message) console.log(" [x] %s:'%s'", message.fields.routingKey, message.content.toString()); else console.warn(' [x] Consumer cancelled'); }, - {noAck: true}, + { noAck: true }, (err) => { if (err) return bail(err, connection); console.log(' [*] Waiting for logs. To exit press CTRL+C.'); diff --git a/examples/tutorials/callback_api/rpc_client.js b/examples/tutorials/callback_api/rpc_client.js index d42003bf..80d5a451 100755 --- a/examples/tutorials/callback_api/rpc_client.js +++ b/examples/tutorials/callback_api/rpc_client.js @@ -1,8 +1,8 @@ #!/usr/bin/env node const amqp = require('amqplib/callback_api'); -const {basename} = require('node:path'); -const {v4: uuid} = require('uuid'); +const { basename } = require('node:path'); +const { v4: uuid } = require('uuid'); const queue = 'rpc_queue'; @@ -16,7 +16,7 @@ amqp.connect((err, connection) => { if (err) return bail(err); connection.createChannel((err, channel) => { if (err) return bail(err, connection); - channel.assertQueue('', {exclusive: true}, (err, {queue: replyTo}) => { + channel.assertQueue('', { exclusive: true }, (err, { queue: replyTo }) => { if (err) return bail(err, connection); const correlationId = uuid(); @@ -31,10 +31,10 @@ amqp.connect((err, connection) => { }); } }, - {noAck: true}, + { noAck: true }, ); - channel.assertQueue(queue, {durable: false}, (err) => { + channel.assertQueue(queue, { durable: false }, (err) => { if (err) return bail(err, connection); console.log(' [x] Requesting fib(%d)', n); channel.sendToQueue(queue, Buffer.from(n.toString()), { diff --git a/examples/tutorials/callback_api/rpc_server.js b/examples/tutorials/callback_api/rpc_server.js index 28f0fa17..4193e5ad 100755 --- a/examples/tutorials/callback_api/rpc_server.js +++ b/examples/tutorials/callback_api/rpc_server.js @@ -15,7 +15,7 @@ amqp.connect((err, connection) => { }); }); - channel.assertQueue(queue, {durable: false}, (err) => { + channel.assertQueue(queue, { durable: false }, (err) => { if (err) return bail(err, connection); channel.prefetch(1); channel.consume( @@ -29,7 +29,7 @@ amqp.connect((err, connection) => { }); channel.ack(message); }, - {noAck: false}, + { noAck: false }, (err) => { if (err) return bail(err, conn); console.log(' [x] Awaiting RPC requests. To exit press CTRL+C.'); diff --git a/examples/tutorials/callback_api/send.js b/examples/tutorials/callback_api/send.js index 27d8b645..26a01f5c 100755 --- a/examples/tutorials/callback_api/send.js +++ b/examples/tutorials/callback_api/send.js @@ -9,7 +9,7 @@ amqp.connect((err, connection) => { if (err) return bail(err); connection.createChannel((err, channel) => { if (err) return bail(err, connection); - channel.assertQueue(queue, {durable: false}, (err) => { + channel.assertQueue(queue, { durable: false }, (err) => { if (err) return bail(err, connection); channel.sendToQueue(queue, Buffer.from(text)); console.log(" [x] Sent '%s'", text); diff --git a/examples/tutorials/callback_api/worker.js b/examples/tutorials/callback_api/worker.js index 3116837d..2ef76592 100755 --- a/examples/tutorials/callback_api/worker.js +++ b/examples/tutorials/callback_api/worker.js @@ -15,7 +15,7 @@ amqp.connect((err, connection) => { }); }); - channel.assertQueue(queue, {durable: true}, (err, {queue}) => { + channel.assertQueue(queue, { durable: true }, (err, { queue }) => { if (err) return bail(err, connection); channel.consume( queue, @@ -28,7 +28,7 @@ amqp.connect((err, connection) => { channel.ack(message); }, seconds * 1000); }, - {noAck: false}, + { noAck: false }, ); console.log(' [*] Waiting for messages. To exit press CTRL+C'); }); diff --git a/examples/tutorials/emit_log.js b/examples/tutorials/emit_log.js index 93d68683..07773ea2 100755 --- a/examples/tutorials/emit_log.js +++ b/examples/tutorials/emit_log.js @@ -10,7 +10,7 @@ const text = process.argv.slice(2).join(' ') || 'info: Hello World!'; try { connection = await amqp.connect('amqp://localhost'); const channel = await connection.createChannel(); - await channel.assertExchange(exchange, 'fanout', {durable: false}); + await channel.assertExchange(exchange, 'fanout', { durable: false }); channel.publish(exchange, '', Buffer.from(text)); console.log(" [x] Sent '%s'", text); await channel.close(); diff --git a/examples/tutorials/emit_log_direct.js b/examples/tutorials/emit_log_direct.js index 7b39ed03..f637b230 100755 --- a/examples/tutorials/emit_log_direct.js +++ b/examples/tutorials/emit_log_direct.js @@ -12,7 +12,7 @@ const text = args.slice(1).join(' ') || 'Hello World!'; try { connection = await amqp.connect('amqp://localhost'); const channel = await connection.createChannel(); - await channel.assertExchange(exchange, 'direct', {durable: false}); + await channel.assertExchange(exchange, 'direct', { durable: false }); channel.publish(exchange, routingKey, Buffer.from(text)); console.log(" [x] Sent %s:'%s'", routingKey, text); await channel.close(); diff --git a/examples/tutorials/emit_log_topic.js b/examples/tutorials/emit_log_topic.js index a2604bb4..50142674 100755 --- a/examples/tutorials/emit_log_topic.js +++ b/examples/tutorials/emit_log_topic.js @@ -12,7 +12,7 @@ const text = args.slice(1).join(' ') || 'Hello World!'; try { connection = await amqp.connect('amqp://localhost'); const channel = await connection.createChannel(); - await channel.assertExchange(exchange, 'topic', {durable: false}); + await channel.assertExchange(exchange, 'topic', { durable: false }); channel.publish(exchange, routingKeys, Buffer.from(text)); console.log(" [x] Sent %s:'%s'", routingKeys, text); await channel.close(); diff --git a/examples/tutorials/new_task.js b/examples/tutorials/new_task.js index 43bc5283..42cee319 100755 --- a/examples/tutorials/new_task.js +++ b/examples/tutorials/new_task.js @@ -11,8 +11,8 @@ const text = process.argv.slice(2).join(' ') || 'Hello World!'; try { connection = await amqp.connect('amqp://localhost'); const channel = await connection.createChannel(); - await channel.assertQueue(queue, {durable: true}); - channel.sendToQueue(queue, Buffer.from(text), {persistent: true}); + await channel.assertQueue(queue, { durable: true }); + channel.sendToQueue(queue, Buffer.from(text), { persistent: true }); console.log(" [x] Sent '%s'", text); await channel.close(); } catch (err) { diff --git a/examples/tutorials/receive.js b/examples/tutorials/receive.js index 9da42598..0b764845 100755 --- a/examples/tutorials/receive.js +++ b/examples/tutorials/receive.js @@ -14,13 +14,13 @@ const queue = 'hello'; await connection.close(); }); - await channel.assertQueue(queue, {durable: false}); + await channel.assertQueue(queue, { durable: false }); await channel.consume( queue, (message) => { console.log(" [x] Received '%s'", message.content.toString()); }, - {noAck: true}, + { noAck: true }, ); console.log(' [*] Waiting for messages. To exit press CTRL+C'); diff --git a/examples/tutorials/receive_logs.js b/examples/tutorials/receive_logs.js index 6f2f5251..4a1aad4d 100755 --- a/examples/tutorials/receive_logs.js +++ b/examples/tutorials/receive_logs.js @@ -14,8 +14,8 @@ const exchange = 'logs'; await connection.close(); }); - await channel.assertExchange(exchange, 'fanout', {durable: false}); - const {queue} = await channel.assertQueue('', {exclusive: true}); + await channel.assertExchange(exchange, 'fanout', { durable: false }); + const { queue } = await channel.assertQueue('', { exclusive: true }); await channel.bindQueue(queue, exchange, ''); await channel.consume( @@ -24,7 +24,7 @@ const exchange = 'logs'; if (message) console.log(" [x] '%s'", message.content.toString()); else console.warn(' [x] Consumer cancelled'); }, - {noAck: true}, + { noAck: true }, ); console.log(' [*] Waiting for logs. To exit press CTRL+C'); diff --git a/examples/tutorials/receive_logs_direct.js b/examples/tutorials/receive_logs_direct.js index be390845..64aec09c 100755 --- a/examples/tutorials/receive_logs_direct.js +++ b/examples/tutorials/receive_logs_direct.js @@ -1,7 +1,7 @@ #!/usr/bin/env node const amqp = require('../..'); -const {basename} = require('node:path'); +const { basename } = require('node:path'); const exchange = 'direct_logs'; const bindingKeys = process.argv.slice(2); @@ -20,8 +20,8 @@ if (bindingKeys.length < 1) { await connection.close(); }); - await channel.assertExchange(exchange, 'direct', {durable: false}); - const {queue} = await channel.assertQueue('', {exclusive: true}); + await channel.assertExchange(exchange, 'direct', { durable: false }); + const { queue } = await channel.assertQueue('', { exclusive: true }); await Promise.all( bindingKeys.map(async (bindingKey) => { await channel.bindQueue(queue, exchange, bindingKey); @@ -34,7 +34,7 @@ if (bindingKeys.length < 1) { if (message) console.log(" [x] %s:'%s'", message.fields.routingKey, message.content.toString()); else console.warn(' [x] Consumer cancelled'); }, - {noAck: true}, + { noAck: true }, ); console.log(' [*] Waiting for logs. To exit press CTRL+C.'); diff --git a/examples/tutorials/receive_logs_topic.js b/examples/tutorials/receive_logs_topic.js index 363a11d4..00494649 100755 --- a/examples/tutorials/receive_logs_topic.js +++ b/examples/tutorials/receive_logs_topic.js @@ -1,7 +1,7 @@ #!/usr/bin/env node const amqp = require('../..'); -const {basename} = require('node:path'); +const { basename } = require('node:path'); const exchange = 'topic_logs'; const bindingKeys = process.argv.slice(2); @@ -20,8 +20,8 @@ if (bindingKeys.length < 1) { await connection.close(); }); - await channel.assertExchange(exchange, 'topic', {durable: false}); - const {queue} = await channel.assertQueue('', {exclusive: true}); + await channel.assertExchange(exchange, 'topic', { durable: false }); + const { queue } = await channel.assertQueue('', { exclusive: true }); await Promise.all( bindingKeys.map(async (bindingKey) => { await channel.bindQueue(queue, exchange, bindingKey); @@ -34,7 +34,7 @@ if (bindingKeys.length < 1) { if (message) console.log(" [x] %s:'%s'", message.fields.routingKey, message.content.toString()); else console.warn(' [x] Consumer cancelled'); }, - {noAck: true}, + { noAck: true }, ); console.log(' [*] Waiting for logs. To exit press CTRL+C.'); diff --git a/examples/tutorials/rpc_client.js b/examples/tutorials/rpc_client.js index 5ce313aa..3ff52088 100755 --- a/examples/tutorials/rpc_client.js +++ b/examples/tutorials/rpc_client.js @@ -1,8 +1,8 @@ #!/usr/bin/env node const amqp = require('amqplib'); -const {basename} = require('node:path'); -const {v4: uuid} = require('uuid'); +const { basename } = require('node:path'); +const { v4: uuid } = require('uuid'); const queue = 'rpc_queue'; @@ -20,7 +20,7 @@ if (Number.isNaN(n)) { const correlationId = uuid(); const requestFib = new Promise(async (resolve) => { - const {queue: replyTo} = await channel.assertQueue('', {exclusive: true}); + const { queue: replyTo } = await channel.assertQueue('', { exclusive: true }); await channel.consume( replyTo, @@ -30,10 +30,10 @@ if (Number.isNaN(n)) { resolve(message.content.toString()); } }, - {noAck: true}, + { noAck: true }, ); - await channel.assertQueue(queue, {durable: false}); + await channel.assertQueue(queue, { durable: false }); console.log(' [x] Requesting fib(%d)', n); channel.sendToQueue(queue, Buffer.from(n.toString()), { correlationId, diff --git a/examples/tutorials/rpc_server.js b/examples/tutorials/rpc_server.js index f2eb10cd..6851e731 100755 --- a/examples/tutorials/rpc_server.js +++ b/examples/tutorials/rpc_server.js @@ -14,7 +14,7 @@ const queue = 'rpc_queue'; await connection.close(); }); - await channel.assertQueue(queue, {durable: false}); + await channel.assertQueue(queue, { durable: false }); channel.prefetch(1); await channel.consume(queue, (message) => { diff --git a/examples/tutorials/send.js b/examples/tutorials/send.js index ef6052a8..98d6e3e8 100755 --- a/examples/tutorials/send.js +++ b/examples/tutorials/send.js @@ -11,7 +11,7 @@ const text = 'Hello World!'; connection = await amqp.connect('amqp://localhost'); const channel = await connection.createChannel(); - await channel.assertQueue(queue, {durable: false}); + await channel.assertQueue(queue, { durable: false }); // NB: `sentToQueue` and `publish` both return a boolean // indicating whether it's OK to send again straight away, or diff --git a/examples/tutorials/worker.js b/examples/tutorials/worker.js index acd4d834..5b77bf19 100755 --- a/examples/tutorials/worker.js +++ b/examples/tutorials/worker.js @@ -13,7 +13,7 @@ const queue = 'task_queue'; }); const channel = await connection.createChannel(); - await channel.assertQueue(queue, {durable: true}); + await channel.assertQueue(queue, { durable: true }); channel.prefetch(1); await channel.consume( @@ -27,7 +27,7 @@ const queue = 'task_queue'; channel.ack(message); }, seconds * 1000); }, - {noAck: false}, + { noAck: false }, ); console.log(' [*] Waiting for messages. To exit press CTRL+C'); diff --git a/lib/api_args.js b/lib/api_args.js index a3c1b762..a6bc1e97 100644 --- a/lib/api_args.js +++ b/lib/api_args.js @@ -284,6 +284,6 @@ Args.prefetch = (count, global) => ({ global: !!global, }); -Args.recover = () => ({requeue: true}); +Args.recover = () => ({ requeue: true }); module.exports = Object.freeze(Args); diff --git a/lib/callback_model.js b/lib/callback_model.js index d47aa937..35ec20e5 100644 --- a/lib/callback_model.js +++ b/lib/callback_model.js @@ -45,7 +45,7 @@ class CallbackModel extends EventEmitter { ch.open((err) => { if (err !== null) return cb && cb(err); else { - ch.rpc(defs.ConfirmSelect, {nowait: false}, defs.ConfirmSelectOk, (err, _ok) => { + ch.rpc(defs.ConfirmSelect, { nowait: false }, defs.ConfirmSelectOk, (err, _ok) => { if (err !== null) return cb && cb(err); else cb && cb(null, ch); }); @@ -86,7 +86,7 @@ class Channel extends BaseChannel { return cb(e); } - return this.rpc(defs.ChannelOpen, {outOfBand: ''}, defs.ChannelOpenOk, cb); + return this.rpc(defs.ChannelOpen, { outOfBand: '' }, defs.ChannelOpenOk, cb); } close(cb) { @@ -122,7 +122,7 @@ class Channel extends BaseChannel { assertExchange(ex, type, options, cb0) { const cb = callbackWrapper(this, cb0); this._rpc(defs.ExchangeDeclare, Args.assertExchange(ex, type, options), defs.ExchangeDeclareOk, (e, _) => { - cb(e, {exchange: ex}); + cb(e, { exchange: ex }); }); return this; } diff --git a/lib/channel_model.js b/lib/channel_model.js index 797bc8f2..e64bdb18 100644 --- a/lib/channel_model.js +++ b/lib/channel_model.js @@ -1,10 +1,10 @@ const EventEmitter = require('node:events'); const promisify = require('node:util').promisify; const defs = require('./defs'); -const {BaseChannel} = require('./channel'); -const {acceptMessage} = require('./channel'); +const { BaseChannel } = require('./channel'); +const { acceptMessage } = require('./channel'); const Args = require('./api_args'); -const {inspect} = require('./format'); +const { inspect } = require('./format'); class ChannelModel extends EventEmitter { constructor(connection) { @@ -35,7 +35,7 @@ class ChannelModel extends EventEmitter { const channel = new ConfirmChannel(this.connection); channel.setOptions(options); await channel.open(); - await channel.rpc(defs.ConfirmSelect, {nowait: false}, defs.ConfirmSelectOk); + await channel.rpc(defs.ConfirmSelect, { nowait: false }, defs.ConfirmSelectOk); return channel; } } @@ -63,7 +63,7 @@ class Channel extends BaseChannel { // Do the remarkably simple channel open handshake async open() { const ch = await this.allocate.bind(this)(); - return ch.rpc(defs.ChannelOpen, {outOfBand: ''}, defs.ChannelOpenOk); + return ch.rpc(defs.ChannelOpen, { outOfBand: '' }, defs.ChannelOpenOk); } close() { @@ -102,7 +102,7 @@ class Channel extends BaseChannel { // The server reply is an empty set of fields, but it's convenient // to have the exchange name handed to the continuation. return this.rpc(defs.ExchangeDeclare, Args.assertExchange(exchange, type, options), defs.ExchangeDeclareOk).then((_ok) => { - return {exchange}; + return { exchange }; }); } diff --git a/lib/codec.js b/lib/codec.js index 20aabfee..6c9d079a 100644 --- a/lib/codec.js +++ b/lib/codec.js @@ -245,13 +245,13 @@ function decodeFields(slice) { offset++; const digits = slice.readUInt32BE(offset); offset += 4; - val = {'!': 'decimal', value: {places: places, digits: digits}}; + val = { '!': 'decimal', value: { places: places, digits: digits } }; break; } case 'T': val = ints.readUInt64BE(slice, offset); offset += 8; - val = {'!': 'timestamp', value: val}; + val = { '!': 'timestamp', value: val }; break; case 'F': len = slice.readUInt32BE(offset); diff --git a/lib/connection.js b/lib/connection.js index 14a12d01..c7a46d21 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -44,7 +44,7 @@ class Connection extends EventEmitter { this.freeChannels = new BitSet(); this.channels = [ { - channel: {accept: channel0(this)}, + channel: { accept: channel0(this) }, buffer: underlying, }, ]; @@ -385,7 +385,7 @@ class Connection extends EventEmitter { objectMode: true, highWaterMark: hwm, }); - this.channels[next] = {channel: channel, buffer: writeBuffer}; + this.channels[next] = { channel: channel, buffer: writeBuffer }; writeBuffer.on('drain', () => { channel.onBufferDrain(); }); diff --git a/lib/credentials.js b/lib/credentials.js index 02d9080d..17f19008 100644 --- a/lib/credentials.js +++ b/lib/credentials.js @@ -21,7 +21,7 @@ module.exports.amqplain = (user, passwd) => ({ mechanism: 'AMQPLAIN', response: () => { const buffer = Buffer.alloc(16384); - const size = codec.encodeTable(buffer, {LOGIN: user, PASSWORD: passwd}, 0); + const size = codec.encodeTable(buffer, { LOGIN: user, PASSWORD: passwd }, 0); return buffer.subarray(4, size); }, username: user, diff --git a/lib/frame.js b/lib/frame.js index 7306399b..c1ed07ef 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -125,7 +125,7 @@ function parseFrame(bin) { module.exports.parseFrame = parseFrame; -const HEARTBEAT = {channel: 0}; +const HEARTBEAT = { channel: 0 }; /** * Decode AMQP frame into JS object @@ -141,7 +141,7 @@ module.exports.decodeFrame = (frame) => { const id = payload.readUInt32BE(0); const args = payload.subarray(4); const fields = decode(id, args); - return {id, channel, fields}; + return { id, channel, fields }; } case FRAME_HEADER: { const id = payload.readUInt16BE(0); @@ -149,10 +149,10 @@ module.exports.decodeFrame = (frame) => { const size = readInt64BE(payload, 4); const flagsAndfields = payload.subarray(12); const fields = decode(id, flagsAndfields); - return {id, channel, size, fields}; + return { id, channel, size, fields }; } case FRAME_BODY: - return {channel, content: payload}; + return { channel, content: payload }; case FRAME_HEARTBEAT: return HEARTBEAT; default: diff --git a/test/bitset.js b/test/bitset.js index ce852577..7e1b360c 100644 --- a/test/bitset.js +++ b/test/bitset.js @@ -1,7 +1,7 @@ const claire = require('claire'); -const {BitSet} = require('../lib/bitset'); +const { BitSet } = require('../lib/bitset'); -const {forAll, data: arb, label, choice, transform} = claire; +const { forAll, data: arb, label, choice, transform } = claire; const PosInt = transform(Math.floor, arb.Positive); diff --git a/test/callback_api.js b/test/callback_api.js index a241ce2d..c53d5028 100644 --- a/test/callback_api.js +++ b/test/callback_api.js @@ -197,7 +197,7 @@ suite('bindings', () => { suite('sending messages', () => { channel_test('send to queue and consume noAck', (ch, done) => { const msg = randomString(); - ch.assertQueue('', {exclusive: true}, (e, q) => { + ch.assertQueue('', { exclusive: true }, (e, q) => { if (e !== null) return done(e); ch.consume( q.queue, @@ -205,7 +205,7 @@ suite('sending messages', () => { if (m.content.toString() === msg) done(); else done(new Error(`message content doesn't match:${msg} =/= ${m.content.toString()}`)); }, - {noAck: true, exclusive: true}, + { noAck: true, exclusive: true }, ); ch.sendToQueue(q.queue, Buffer.from(msg)); }); @@ -213,7 +213,7 @@ suite('sending messages', () => { channel_test('send to queue and consume ack', (ch, done) => { const msg = randomString(); - ch.assertQueue('', {exclusive: true}, (e, q) => { + ch.assertQueue('', { exclusive: true }, (e, q) => { if (e !== null) return done(e); ch.consume( q.queue, @@ -223,20 +223,20 @@ suite('sending messages', () => { done(); } else done(new Error(`message content doesn't match:${msg} =/= ${m.content.toString()}`)); }, - {noAck: false, exclusive: true}, + { noAck: false, exclusive: true }, ); ch.sendToQueue(q.queue, Buffer.from(msg)); }); }); channel_test('send to and get from queue', (ch, done) => { - ch.assertQueue('', {exclusive: true}, (e, q) => { + ch.assertQueue('', { exclusive: true }, (e, q) => { if (e != null) return done(e); const msg = randomString(); ch.sendToQueue(q.queue, Buffer.from(msg)); waitForMessages(ch, q.queue, (e, _) => { if (e != null) return done(e); - ch.get(q.queue, {noAck: true}, (e, m) => { + ch.get(q.queue, { noAck: true }, (e, m) => { if (e != null) return done(e); else if (!m) return done(new Error('Empty (false) not expected')); else if (m.content.toString() === msg) return done(); @@ -251,7 +251,7 @@ suite('sending messages', () => { channel_test('find high watermark', (ch, done) => { const msg = randomString(); let baseline = 0; - ch.assertQueue('', {exclusive: true}, (e, q) => { + ch.assertQueue('', { exclusive: true }, (e, q) => { if (e !== null) return done(e); while (ch.sendToQueue(q.queue, Buffer.from(msg))) { baseline++; @@ -263,7 +263,7 @@ suite('sending messages', () => { channel_test('set high watermark', channelOptions, (ch, done) => { const msg = randomString(); - ch.assertQueue('', {exclusive: true}, (e, q) => { + ch.assertQueue('', { exclusive: true }, (e, q) => { if (e !== null) return done(e); let ok; for (let i = 0; i < channelOptions.highWaterMark; i++) { @@ -295,7 +295,7 @@ suite('ConfirmChannel', () => { confirm_channel_test('find high watermark', (ch, done) => { const msg = randomString(); let baseline = 0; - ch.assertQueue('', {exclusive: true}, (e, q) => { + ch.assertQueue('', { exclusive: true }, (e, q) => { if (e !== null) return done(e); while (ch.sendToQueue(q.queue, Buffer.from(msg))) { baseline++; @@ -307,7 +307,7 @@ suite('ConfirmChannel', () => { confirm_channel_test('set high watermark', channelOptions, (ch, done) => { const msg = randomString(); - ch.assertQueue('', {exclusive: true}, (e, q) => { + ch.assertQueue('', { exclusive: true }, (e, q) => { if (e !== null) return done(e); let ok; for (let i = 0; i < channelOptions.highWaterMark; i++) { @@ -384,7 +384,7 @@ suite('Error handling', () => { error_test('Get callback throws error', (ch, done, dom) => { dom.on('error', failCallback(done)); ch.assertQueue('test.cb.get-with-error', {}, (_err, _ok) => { - ch.get('test.cb.get-with-error', {noAck: true}, () => { + ch.get('test.cb.get-with-error', { noAck: true }, () => { throw new Error('Spurious callback error'); }); }); @@ -393,7 +393,7 @@ suite('Error handling', () => { error_test('Consume callback throws error', (ch, done, dom) => { dom.on('error', failCallback(done)); ch.assertQueue('test.cb.consume-with-error', {}, (_err, _ok) => { - ch.consume('test.cb.consume-with-error', ignore, {noAck: true}, () => { + ch.consume('test.cb.consume-with-error', ignore, { noAck: true }, () => { throw new Error('Spurious callback error'); }); }); diff --git a/test/channel.js b/test/channel.js index 777dab02..8790e6aa 100644 --- a/test/channel.js +++ b/test/channel.js @@ -54,7 +54,7 @@ function channelTest(client, server) { function channel_handshake(send, wait) { return wait(defs.ChannelOpen)().then((open) => { assert.notEqual(0, open.channel); - send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, open.channel); + send(defs.ChannelOpenOk, { channelId: Buffer.from('') }, open.channel); return open.channel; }); } @@ -73,7 +73,7 @@ const DELIVER_FIELDS = { function open(ch) { ch.allocate(); return promisify((cb) => { - ch._rpc(defs.ChannelOpen, {outOfBand: ''}, defs.ChannelOpenOk, cb); + ch._rpc(defs.ChannelOpen, { outOfBand: '' }, defs.ChannelOpenOk, cb); })(); } @@ -268,7 +268,7 @@ suite('channel machinery', () => { }); open(ch).then(() => { - ch._rpc(defs.BasicRecover, {requeue: true}, defs.BasicRecoverOk, (err) => { + ch._rpc(defs.BasicRecover, { requeue: true }, defs.BasicRecoverOk, (err) => { if (err !== null) errLatch(); else errLatch(new Error('Expected RPC failure')); }); @@ -277,7 +277,7 @@ suite('channel machinery', () => { (send, wait, done, ch) => wait()() .then(() => { - send(defs.BasicGetEmpty, {clusterId: ''}, ch); + send(defs.BasicGetEmpty, { clusterId: '' }, ch); }) // oh wait! that was wrong! expect a channel close .then(wait(defs.ChannelClose)) .then(() => { @@ -310,11 +310,11 @@ suite('channel machinery', () => { } const fail1 = new Promise((resolve, reject) => - ch._rpc(defs.BasicRecover, {requeue: true}, defs.BasicRecoverOk, failureCb(resolve, reject)), + ch._rpc(defs.BasicRecover, { requeue: true }, defs.BasicRecoverOk, failureCb(resolve, reject)), ); const fail2 = new Promise((resolve, reject) => - ch._rpc(defs.BasicRecover, {requeue: true}, defs.BasicRecoverOk, failureCb(resolve, reject)), + ch._rpc(defs.BasicRecover, { requeue: true }, defs.BasicRecoverOk, failureCb(resolve, reject)), ); Promise.all([close, fail1, fail2]).then(succeed(done)).catch(fail(done)); @@ -418,7 +418,7 @@ suite('channel machinery', () => { ticket: 0, }, { - headers: {foo: Buffer.alloc(3000)}, + headers: { foo: Buffer.alloc(3000) }, }, Buffer.from('foobar'), ); @@ -548,7 +548,7 @@ suite('channel machinery', () => { completes(() => { open(ch); assert.throws(() => { - ch.sendMessage({routingKey: 'foo', exchange: 'amq.direct'}, {}, null); + ch.sendMessage({ routingKey: 'foo', exchange: 'amq.direct' }, {}, null); }); }, done); }, @@ -565,7 +565,7 @@ suite('channel machinery', () => { completes(() => { open(ch); assert.throws(() => { - ch.sendMessage({routingKey: 'foo', exchange: 'amq.direct'}, {contentEncoding: 7}, Buffer.from('foobar')); + ch.sendMessage({ routingKey: 'foo', exchange: 'amq.direct' }, { contentEncoding: 7 }, Buffer.from('foobar')); }); }, done); }, @@ -617,7 +617,7 @@ suite('channel machinery', () => { }); ch.on('delivery', () => { - ch.sendMessage({routingKey: 'foo', exchange: 'amq.direct'}, {}, null); // can't send null + ch.sendMessage({ routingKey: 'foo', exchange: 'amq.direct' }, {}, null); // can't send null }); open(ch); @@ -728,9 +728,9 @@ suite('channel machinery', () => { }, (send, _wait, done, ch) => { completes(() => { - send(defs.BasicAck, {deliveryTag: 2, multiple: false}, ch); - send(defs.BasicAck, {deliveryTag: 3, multiple: false}, ch); - send(defs.BasicAck, {deliveryTag: 1, multiple: false}, ch); + send(defs.BasicAck, { deliveryTag: 2, multiple: false }, ch); + send(defs.BasicAck, { deliveryTag: 3, multiple: false }, ch); + send(defs.BasicAck, { deliveryTag: 1, multiple: false }, ch); }, done); }, ), @@ -755,8 +755,8 @@ suite('channel machinery', () => { }, (send, _wait, done, ch) => { completes(() => { - send(defs.BasicAck, {deliveryTag: 2, multiple: false}, ch); - send(defs.BasicAck, {deliveryTag: 1, multiple: false}, ch); + send(defs.BasicAck, { deliveryTag: 2, multiple: false }, ch); + send(defs.BasicAck, { deliveryTag: 1, multiple: false }, ch); }, done); }, ), diff --git a/test/channel_api.js b/test/channel_api.js index e29e8ec2..9a9aabe1 100644 --- a/test/channel_api.js +++ b/test/channel_api.js @@ -74,8 +74,8 @@ suite('updateSecret', () => { }); }); -const QUEUE_OPTS = {durable: false}; -const EX_OPTS = {durable: false}; +const QUEUE_OPTS = { durable: false }; +const EX_OPTS = { durable: false }; suite('assert, check, delete', () => { chtest('assert and check queue', (ch) => @@ -92,8 +92,8 @@ suite('assert, check, delete', () => { chtest('fail on reasserting queue with different options', (ch) => { const q = 'test.reassert-queue'; return ch - .assertQueue(q, {durable: false, autoDelete: true}) - .then(() => expectFail(ch.assertQueue(q, {durable: false, autoDelete: false}))); + .assertQueue(q, { durable: false, autoDelete: true }) + .then(() => expectFail(ch.assertQueue(q, { durable: false, autoDelete: false }))); }); chtest("fail on checking a queue that's not there", (ch) => expectFail(ch.checkQueue(`test.random-${randomString()}`))); @@ -166,7 +166,7 @@ suite('sendMessage', () => { ch.sendToQueue(q, Buffer.from(msg)); return waitForMessages(q); }) - .then(() => ch.get(q, {noAck: true})) + .then(() => ch.get(q, { noAck: true })) .then((m) => { assert(m); assert.equal(msg, m.content.toString()); @@ -181,7 +181,7 @@ suite('sendMessage', () => { ch.sendToQueue(q, msg); return waitForMessages(q); }) - .then(() => ch.get(q, {noAck: true})) + .then(() => ch.get(q, { noAck: true })) .then((m) => { assert(m); assert.deepEqual(msg, m.content); @@ -206,7 +206,7 @@ suite('binding, consuming', () => { ch.publish(ex, '', Buffer.from(msg)); return waitForMessages(q); }) - .then(() => ch.get(q, {noAck: true})) + .then(() => ch.get(q, { noAck: true })) .then((m) => { assert(m); assert.equal(msg, m.content.toString()); @@ -217,14 +217,14 @@ suite('binding, consuming', () => { chtest('purge queue', (ch) => { const q = 'test.purge-queue'; return ch - .assertQueue(q, {durable: false}) + .assertQueue(q, { durable: false }) .then(() => { ch.sendToQueue(q, Buffer.from('foobar')); return waitForMessages(q); }) .then(() => { ch.purgeQueue(q); - return ch.get(q, {noAck: true}); + return ch.get(q, { noAck: true }); }) .then((m) => { assert(!m); // get-empty @@ -250,7 +250,7 @@ suite('binding, consuming', () => { }) .then(() => { // message got through! - return ch.get(q, {noAck: true}).then((m) => { + return ch.get(q, { noAck: true }).then((m) => { assert(m); }); }) @@ -280,7 +280,7 @@ suite('binding, consuming', () => { const msg = randomString(); return Promise.all([ ch.assertExchange(ex1, 'direct', EX_OPTS), - ch.assertExchange(ex2, 'fanout', {durable: false, internal: true}), + ch.assertExchange(ex2, 'fanout', { durable: false, internal: true }), ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q), ch.bindExchange(ex2, ex1, rk, {}), @@ -292,7 +292,7 @@ suite('binding, consuming', () => { if (m.content.toString() === msg) resolve(); else reject(new Error('Wrong message')); } - ch.consume(q, delivery, {noAck: true}).then(() => { + ch.consume(q, delivery, { noAck: true }).then(() => { ch.publish(ex1, rk, Buffer.from(msg)); }); }), @@ -321,7 +321,7 @@ suite('binding, consuming', () => { }) .then(() => { // message got through! - return ch.get(q, {noAck: true}).then((m) => { + return ch.get(q, { noAck: true }).then((m) => { assert(m); }); }) @@ -351,7 +351,7 @@ suite('binding, consuming', () => { ch.purgeQueue(q), // My callback is 'resolve the promise in `arrived`' ch - .consume(q, resolve, {noAck: true}) + .consume(q, resolve, { noAck: true }) .then((ok) => { ctag = ok.consumerTag; ch.sendToQueue(q, Buffer.from('foo')); @@ -366,7 +366,7 @@ suite('binding, consuming', () => { // but check a message did arrive in the queue waitForMessages(q), ]) - .then(() => ch.get(q, {noAck: true})) + .then(() => ch.get(q, { noAck: true })) .then((m) => { // I'm going to reject it, because I flip succeed/fail // just below @@ -405,7 +405,7 @@ suite('binding, consuming', () => { ch.sendToQueue(q, Buffer.from(msg2)); return waitForMessages(q, 2); }) - .then(() => ch.get(q, {noAck: false})) + .then(() => ch.get(q, { noAck: false })) .then((m) => { assert.equal(msg1, m.content.toString()); ch.ack(m); @@ -430,7 +430,7 @@ suite('binding, consuming', () => { ch.sendToQueue(q, Buffer.from(msg1)); return waitForMessages(q); }) - .then(() => ch.get(q, {noAck: false})) + .then(() => ch.get(q, { noAck: false })) .then((m) => { assert.equal(msg1, m.content.toString()); ch.nack(m); @@ -454,7 +454,7 @@ suite('binding, consuming', () => { ch.sendToQueue(q, Buffer.from(msg1)); return waitForMessages(q); }) - .then(() => ch.get(q, {noAck: false})) + .then(() => ch.get(q, { noAck: false })) .then((m) => { assert.equal(msg1, m.content.toString()); ch.reject(m); @@ -485,7 +485,7 @@ suite('binding, consuming', () => { resolve(messageCount); } } - return ch.consume(q, receive, {noAck: false}); + return ch.consume(q, receive, { noAck: false }); }), ) .then((c) => assert.equal(2, c)); diff --git a/test/codec.js b/test/codec.js index 0586236e..48bf45ec 100644 --- a/test/codec.js +++ b/test/codec.js @@ -10,65 +10,69 @@ const forAll = C.forAll; const testCases = [ // integers - ['byte', {byte: 112}, [4, 98, 121, 116, 101, 98, 112]], - ['byte max value', {byte: 127}, [4, 98, 121, 116, 101, 98, 127]], - ['byte min value', {byte: -128}, [4, 98, 121, 116, 101, 98, 128]], - ['< -128 promoted to signed short', {short: -129}, [5, 115, 104, 111, 114, 116, 115, 255, 127]], - ['> 127 promoted to short', {short: 128}, [5, 115, 104, 111, 114, 116, 115, 0, 128]], - ['< 2^15 still a short', {short: 0x7fff}, [5, 115, 104, 111, 114, 116, 115, 127, 255]], - ['-2^15 still a short', {short: -0x8000}, [5, 115, 104, 111, 114, 116, 115, 128, 0]], - ['>= 2^15 promoted to int', {int: 0x8000}, [3, 105, 110, 116, 73, 0, 0, 128, 0]], - ['< -2^15 promoted to int', {int: -0x8001}, [3, 105, 110, 116, 73, 255, 255, 127, 255]], - ['< 2^31 still an int', {int: 0x7fffffff}, [3, 105, 110, 116, 73, 127, 255, 255, 255]], - ['>= -2^31 still an int', {int: -0x80000000}, [3, 105, 110, 116, 73, 128, 0, 0, 0]], - ['>= 2^31 promoted to long', {long: 0x80000000}, [4, 108, 111, 110, 103, 108, 0, 0, 0, 0, 128, 0, 0, 0]], - ['< -2^31 promoted to long', {long: -0x80000001}, [4, 108, 111, 110, 103, 108, 255, 255, 255, 255, 127, 255, 255, 255]], + ['byte', { byte: 112 }, [4, 98, 121, 116, 101, 98, 112]], + ['byte max value', { byte: 127 }, [4, 98, 121, 116, 101, 98, 127]], + ['byte min value', { byte: -128 }, [4, 98, 121, 116, 101, 98, 128]], + ['< -128 promoted to signed short', { short: -129 }, [5, 115, 104, 111, 114, 116, 115, 255, 127]], + ['> 127 promoted to short', { short: 128 }, [5, 115, 104, 111, 114, 116, 115, 0, 128]], + ['< 2^15 still a short', { short: 0x7fff }, [5, 115, 104, 111, 114, 116, 115, 127, 255]], + ['-2^15 still a short', { short: -0x8000 }, [5, 115, 104, 111, 114, 116, 115, 128, 0]], + ['>= 2^15 promoted to int', { int: 0x8000 }, [3, 105, 110, 116, 73, 0, 0, 128, 0]], + ['< -2^15 promoted to int', { int: -0x8001 }, [3, 105, 110, 116, 73, 255, 255, 127, 255]], + ['< 2^31 still an int', { int: 0x7fffffff }, [3, 105, 110, 116, 73, 127, 255, 255, 255]], + ['>= -2^31 still an int', { int: -0x80000000 }, [3, 105, 110, 116, 73, 128, 0, 0, 0]], + ['>= 2^31 promoted to long', { long: 0x80000000 }, [4, 108, 111, 110, 103, 108, 0, 0, 0, 0, 128, 0, 0, 0]], + ['< -2^31 promoted to long', { long: -0x80000001 }, [4, 108, 111, 110, 103, 108, 255, 255, 255, 255, 127, 255, 255, 255]], // floating point - ['float value', {double: 0.5}, [6, 100, 111, 117, 98, 108, 101, 100, 63, 224, 0, 0, 0, 0, 0, 0]], - ['negative float value', {double: -0.5}, [6, 100, 111, 117, 98, 108, 101, 100, 191, 224, 0, 0, 0, 0, 0, 0]], + ['float value', { double: 0.5 }, [6, 100, 111, 117, 98, 108, 101, 100, 63, 224, 0, 0, 0, 0, 0, 0]], + ['negative float value', { double: -0.5 }, [6, 100, 111, 117, 98, 108, 101, 100, 191, 224, 0, 0, 0, 0, 0, 0]], // %% test some boundaries of precision? // string - ['string', {string: 'boop'}, [6, 115, 116, 114, 105, 110, 103, 83, 0, 0, 0, 4, 98, 111, 111, 112]], + ['string', { string: 'boop' }, [6, 115, 116, 114, 105, 110, 103, 83, 0, 0, 0, 4, 98, 111, 111, 112]], // buffer -> byte array - ['byte array from buffer', {bytes: Buffer.from([1, 2, 3, 4])}, [5, 98, 121, 116, 101, 115, 120, 0, 0, 0, 4, 1, 2, 3, 4]], + ['byte array from buffer', { bytes: Buffer.from([1, 2, 3, 4]) }, [5, 98, 121, 116, 101, 115, 120, 0, 0, 0, 4, 1, 2, 3, 4]], // boolean, void - ['true', {bool: true}, [4, 98, 111, 111, 108, 116, 1]], - ['false', {bool: false}, [4, 98, 111, 111, 108, 116, 0]], - ['null', {void: null}, [4, 118, 111, 105, 100, 86]], + ['true', { bool: true }, [4, 98, 111, 111, 108, 116, 1]], + ['false', { bool: false }, [4, 98, 111, 111, 108, 116, 0]], + ['null', { void: null }, [4, 118, 111, 105, 100, 86]], // array, object - ['array', {array: [6, true, 'foo']}, [5, 97, 114, 114, 97, 121, 65, 0, 0, 0, 12, 98, 6, 116, 1, 83, 0, 0, 0, 3, 102, 111, 111]], + ['array', { array: [6, true, 'foo'] }, [5, 97, 114, 114, 97, 121, 65, 0, 0, 0, 12, 98, 6, 116, 1, 83, 0, 0, 0, 3, 102, 111, 111]], [ 'object', - {object: {foo: 'bar', baz: 12}}, + { object: { foo: 'bar', baz: 12 } }, [6, 111, 98, 106, 101, 99, 116, 70, 0, 0, 0, 18, 3, 102, 111, 111, 83, 0, 0, 0, 3, 98, 97, 114, 3, 98, 97, 122, 98, 12], ], // exotic types [ 'timestamp', - {timestamp: {'!': 'timestamp', value: 1357212277527}}, + { timestamp: { '!': 'timestamp', value: 1357212277527 } }, [9, 116, 105, 109, 101, 115, 116, 97, 109, 112, 84, 0, 0, 1, 60, 0, 39, 219, 23], ], - ['decimal', {decimal: {'!': 'decimal', value: {digits: 2345, places: 2}}}, [7, 100, 101, 99, 105, 109, 97, 108, 68, 2, 0, 0, 9, 41]], - ['float', {float: {'!': 'float', value: 0.1}}, [5, 102, 108, 111, 97, 116, 102, 61, 204, 204, 205]], + [ + 'decimal', + { decimal: { '!': 'decimal', value: { digits: 2345, places: 2 } } }, + [7, 100, 101, 99, 105, 109, 97, 108, 68, 2, 0, 0, 9, 41], + ], + ['float', { float: { '!': 'float', value: 0.1 } }, [5, 102, 108, 111, 97, 116, 102, 61, 204, 204, 205]], [ 'unsignedbyte', - {unsignedbyte: {'!': 'unsignedbyte', value: 255}}, + { unsignedbyte: { '!': 'unsignedbyte', value: 255 } }, [12, 117, 110, 115, 105, 103, 110, 101, 100, 98, 121, 116, 101, 66, 255], ], [ 'unsignedshort', - {unsignedshort: {'!': 'unsignedshort', value: 65535}}, + { unsignedshort: { '!': 'unsignedshort', value: 65535 } }, [13, 117, 110, 115, 105, 103, 110, 101, 100, 115, 104, 111, 114, 116, 117, 255, 255], ], [ 'unsignedint', - {unsignedint: {'!': 'unsignedint', value: 4294967295}}, + { unsignedint: { '!': 'unsignedint', value: 4294967295 } }, [11, 117, 110, 115, 105, 103, 110, 101, 100, 105, 110, 116, 105, 255, 255, 255, 255], ], ]; @@ -108,7 +112,7 @@ function roundtrip_table(t) { } function roundtrips(T) { - return forAll(T).satisfy((v) => roundtrip_table({value: v})); + return forAll(T).satisfy((v) => roundtrip_table({ value: v })); } suite('Roundtrip values', () => { diff --git a/test/connect.js b/test/connect.js index 73fd04bb..49527808 100644 --- a/test/connect.js +++ b/test/connect.js @@ -114,7 +114,7 @@ suite('Connect API', () => { u = auth[0]; p = auth[1]; } - connect(URL, {credentials: require('../lib/credentials').plain(u, p)}, kCallback(succeed(done), fail(done))); + connect(URL, { credentials: require('../lib/credentials').plain(u, p) }, kCallback(succeed(done), fail(done))); }); test('using amqplain credentials', (done) => { @@ -127,7 +127,7 @@ suite('Connect API', () => { u = auth[0]; p = auth[1]; } - connect(URL, {credentials: require('../lib/credentials').amqplain(u, p)}, kCallback(succeed(done), fail(done))); + connect(URL, { credentials: require('../lib/credentials').amqplain(u, p) }, kCallback(succeed(done), fail(done))); }); test('ipv6', (done) => { @@ -144,13 +144,13 @@ suite('Connect API', () => { mechanism: 'UNSUPPORTED', response: () => Buffer.from(''), }; - connect(URL, {credentials: creds}, kCallback(fail(done), succeed(done))); + connect(URL, { credentials: creds }, kCallback(fail(done), succeed(done))); }); test('with a given connection timeout', (done) => { const timeoutServer = net.createServer(() => {}).listen(31991); - connect('amqp://localhost:31991', {timeout: 50}, (_err, val) => { + connect('amqp://localhost:31991', { timeout: 50 }, (_err, val) => { timeoutServer.close(); if (val) done(new Error('Expected connection timeout, did not')); else done(); diff --git a/test/connection.js b/test/connection.js index b34f771b..d953669a 100644 --- a/test/connection.js +++ b/test/connection.js @@ -42,12 +42,12 @@ function happy_open(send, wait) { }); return wait(defs.ConnectionStartOk)() .then((_f) => { - send(defs.ConnectionTune, {channelMax: 0, heartbeat: 0, frameMax: 0}); + send(defs.ConnectionTune, { channelMax: 0, heartbeat: 0, frameMax: 0 }); }) .then(wait(defs.ConnectionTuneOk)) .then(wait(defs.ConnectionOpen)) .then((_f) => { - send(defs.ConnectionOpenOk, {knownHosts: ''}); + send(defs.ConnectionOpenOk, { knownHosts: '' }); }); } module.exports.connection_handshake = happy_open; @@ -115,7 +115,7 @@ suite('Connection open', () => { (send, _wait, done) => { // bad server! bad! whatever were you thinking? completes(() => { - send(defs.ConnectionTune, {channelMax: 0, heartbeat: 0, frameMax: 0}); + send(defs.ConnectionTune, { channelMax: 0, heartbeat: 0, frameMax: 0 }); }, done); }, ), @@ -159,7 +159,7 @@ suite('Connection running', () => { // there's actually nothing that would plausibly be sent to a // just opened connection, so this is violating more than one // rule. Nonetheless. - send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, 0); + send(defs.ChannelOpenOk, { channelId: Buffer.from('') }, 0); }) .then(wait(defs.ConnectionClose)) .then((_close) => { @@ -183,7 +183,7 @@ suite('Connection running', () => { // there's actually nothing that would plausibly be sent to a // just opened connection, so this is violating more than one // rule. Nonetheless. - send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, 3); + send(defs.ChannelOpenOk, { channelId: Buffer.from('') }, 3); }) .then(wait(defs.ConnectionClose)) .then((_close) => { @@ -229,7 +229,7 @@ suite('Connection running', () => { (send, wait, done, _socket) => { happy_open(send, wait) .then(() => { - send(defs.ConnectionBlocked, {reason: 'felt like it'}, 0); + send(defs.ConnectionBlocked, { reason: 'felt like it' }, 0); }) .then(succeed(done)); }, diff --git a/test/data.js b/test/data.js index 562ad4ba..fd9df0bd 100644 --- a/test/data.js +++ b/test/data.js @@ -53,7 +53,7 @@ function floatChooser(maxExp) { function explicitType(t, underlying) { return label( t, - transform((n) => ({'!': t, value: n}), underlying), + transform((n) => ({ '!': t, value: n }), underlying), ); } @@ -81,23 +81,23 @@ const Double = label('double', asGenerator(floatChooser(308))); const Float = label('float', transform(toFloat32, floatChooser(38))); const Timestamp = label( 'timestamp', - transform((n) => ({'!': 'timestamp', value: n}), ULongLong), + transform((n) => ({ '!': 'timestamp', value: n }), ULongLong), ); const Decimal = label( 'decimal', - transform((args) => ({'!': 'decimal', value: {places: args[1], digits: args[0]}}), sequence(arb.UInt, Octet)), + transform((args) => ({ '!': 'decimal', value: { places: args[1], digits: args[0] } }), sequence(arb.UInt, Octet)), ); const UnsignedByte = label( 'unsignedbyte', - transform((n) => ({'!': 'unsignedbyte', value: n}), Octet), + transform((n) => ({ '!': 'unsignedbyte', value: n }), Octet), ); const UnsignedShort = label( 'unsignedshort', - transform((n) => ({'!': 'unsignedshort', value: n}), UShort), + transform((n) => ({ '!': 'unsignedshort', value: n }), UShort), ); const UnsignedInt = label( 'unsignedint', - transform((n) => ({'!': 'unsignedint', value: n}), ULong), + transform((n) => ({ '!': 'unsignedint', value: n }), ULong), ); // Signed 8 bit int @@ -202,7 +202,7 @@ const domainProps = [ suite('Domains', () => { domainProps.forEach((p) => { - test(`${p[0]} domain`, forAll(p[0]).satisfy(p[1]).asTest({times: 500})); + test(`${p[0]} domain`, forAll(p[0]).satisfy(p[1]).asTest({ times: 500 })); }); }); @@ -250,7 +250,7 @@ function method(info) { const names = info.args.map(name); return label( info.name, - transform((fieldVals) => ({id: info.id, fields: zipObject(fieldVals, names)}), domain), + transform((fieldVals) => ({ id: info.id, fields: zipObject(fieldVals, names) }), domain), ); } @@ -261,7 +261,7 @@ function properties(info) { const names = info.args.map(name); return label( info.name, - transform((fieldVals) => ({id: info.id, size: fieldVals[0], fields: zipObject(fieldVals.slice(1), names)}), domain), + transform((fieldVals) => ({ id: info.id, size: fieldVals[0], fields: zipObject(fieldVals.slice(1), names) }), domain), ); } diff --git a/test/frame.js b/test/frame.js index 5243d646..08f684ba 100644 --- a/test/frame.js +++ b/test/frame.js @@ -12,7 +12,7 @@ const defs = require('../lib/defs'); function inputs() { // don't coalesce buffers, since that could mess up properties // (e.g., encoded frame size) - return new PassThrough({objectMode: true}); + return new PassThrough({ objectMode: true }); } const HB = Buffer.from([ @@ -135,7 +135,7 @@ suite('Parsing', () => { if (ex) throw ex; return i === t.length; }) - .asTest({times: 20}); + .asTest({ times: 20 }); } test( diff --git a/test/mux.js b/test/mux.js index 33316579..fefe7a32 100644 --- a/test/mux.js +++ b/test/mux.js @@ -6,7 +6,7 @@ const latch = require('./util').latch; const schedule = require('./util').schedule; function stream() { - return new PassThrough({objectMode: true}); + return new PassThrough({ objectMode: true }); } function readAllObjects(s, cb) { diff --git a/test/util.js b/test/util.js index 1b32fa41..7cd9298e 100644 --- a/test/util.js +++ b/test/util.js @@ -40,7 +40,7 @@ function socketPair() { server.end = end.bind(client); client.end = end.bind(server); - return {client: client, server: server}; + return { client: client, server: server }; } function runServer(socket, run) {