amqplib 0.10.8 → 1.0.0
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/.claude/commands/lint-disable.md +9 -0
- package/.claude/commands/lint-enable.md +12 -0
- package/.claude/settings.local.json +16 -0
- package/.github/workflows/publish.yml +1 -1
- package/.github/workflows/test.yml +1 -1
- package/CHANGELOG.md +34 -0
- package/CLAUDE.md +12 -0
- package/Makefile +5 -12
- package/bin/generate-defs.js +382 -369
- package/biome.json +51 -0
- package/callback_api.js +12 -8
- package/channel_api.js +5 -10
- package/examples/direct_reply_to_client.js +9 -5
- package/examples/direct_reply_to_server.js +8 -6
- package/examples/headers.js +13 -10
- package/examples/receive_generator.js +13 -20
- package/examples/send_generators.js +2 -9
- package/examples/ssl.js +2 -3
- package/examples/stream_queues/receive_stream.js +39 -36
- package/examples/stream_queues/send_stream.js +26 -29
- package/examples/tutorials/callback_api/emit_log.js +4 -3
- package/examples/tutorials/callback_api/emit_log_direct.js +5 -4
- package/examples/tutorials/callback_api/emit_log_topic.js +5 -4
- package/examples/tutorials/callback_api/new_task.js +5 -4
- package/examples/tutorials/callback_api/receive.js +16 -10
- package/examples/tutorials/callback_api/receive_logs.js +17 -11
- package/examples/tutorials/callback_api/receive_logs_direct.js +19 -13
- package/examples/tutorials/callback_api/receive_logs_topic.js +19 -14
- package/examples/tutorials/callback_api/rpc_client.js +20 -16
- package/examples/tutorials/callback_api/rpc_server.js +27 -21
- package/examples/tutorials/callback_api/send.js +4 -3
- package/examples/tutorials/callback_api/worker.js +18 -13
- package/examples/tutorials/emit_log.js +4 -6
- package/examples/tutorials/emit_log_direct.js +5 -7
- package/examples/tutorials/emit_log_topic.js +5 -7
- package/examples/tutorials/new_task.js +4 -6
- package/examples/tutorials/receive.js +8 -4
- package/examples/tutorials/receive_logs.js +10 -6
- package/examples/tutorials/receive_logs_direct.js +16 -10
- package/examples/tutorials/receive_logs_topic.js +16 -11
- package/examples/tutorials/rpc_client.js +17 -15
- package/examples/tutorials/rpc_server.js +9 -8
- package/examples/tutorials/send.js +4 -6
- package/examples/tutorials/worker.js +17 -14
- package/examples/waitForConfirms.js +2 -2
- package/lefthook.yml +14 -0
- package/lib/api_args.js +124 -149
- package/lib/bitset.js +28 -18
- package/lib/callback_model.js +134 -190
- package/lib/channel.js +175 -213
- package/lib/channel_model.js +41 -85
- package/lib/codec.js +257 -228
- package/lib/connect.js +74 -82
- package/lib/connection.js +204 -240
- package/lib/credentials.js +21 -29
- package/lib/defs.js +2559 -1927
- package/lib/error.js +5 -6
- package/lib/format.js +15 -33
- package/lib/frame.js +66 -66
- package/lib/heartbeat.js +17 -24
- package/lib/mux.js +32 -41
- package/package.json +8 -5
- package/test/bitset.test.js +65 -0
- package/test/callback_api.test.js +438 -0
- package/test/channel.test.js +592 -0
- package/test/channel_api.test.js +537 -0
- package/test/codec.test.js +172 -0
- package/test/connect.test.js +196 -0
- package/test/connection.test.js +330 -0
- package/test/data.test.js +33 -0
- package/test/frame.test.js +180 -0
- package/test/lib/data.js +249 -0
- package/test/lib/util.js +223 -0
- package/test/mux.test.js +215 -0
- package/test/bitset.js +0 -69
- package/test/callback_api.js +0 -379
- package/test/channel.js +0 -621
- package/test/channel_api.js +0 -606
- package/test/codec.js +0 -237
- package/test/connect.js +0 -197
- package/test/connection.js +0 -390
- package/test/data.js +0 -269
- package/test/frame.js +0 -191
- package/test/mux.js +0 -203
- package/test/util.js +0 -217
package/lib/connect.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
var URL = require('url-parse');
|
|
10
|
-
var QS = require('querystring');
|
|
11
|
-
var Connection = require('./connection').Connection;
|
|
12
|
-
var fmt = require('util').format;
|
|
13
|
-
var credentials = require('./credentials');
|
|
1
|
+
const URL = require('url-parse');
|
|
2
|
+
const QS = require('node:querystring');
|
|
3
|
+
const Connection = require('./connection').Connection;
|
|
4
|
+
const fmt = require('node:util').format;
|
|
5
|
+
const credentials = require('./credentials');
|
|
14
6
|
|
|
15
7
|
function copyInto(obj, target) {
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
const keys = Object.keys(obj);
|
|
9
|
+
let i = keys.length;
|
|
18
10
|
while (i--) {
|
|
19
|
-
|
|
11
|
+
const k = keys[i];
|
|
20
12
|
target[k] = obj[k];
|
|
21
13
|
}
|
|
22
14
|
return target;
|
|
@@ -27,61 +19,60 @@ function clone(obj) {
|
|
|
27
19
|
return copyInto(obj, {});
|
|
28
20
|
}
|
|
29
21
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
22
|
+
const CLIENT_PROPERTIES = {
|
|
23
|
+
product: 'amqplib',
|
|
24
|
+
version: require('../package.json').version,
|
|
25
|
+
platform: fmt('Node.JS %s', process.version),
|
|
26
|
+
information: 'https://amqp-node.github.io/amqplib/',
|
|
27
|
+
capabilities: {
|
|
28
|
+
publisher_confirms: true,
|
|
29
|
+
exchange_exchange_bindings: true,
|
|
30
|
+
'basic.nack': true,
|
|
31
|
+
consumer_cancel_notify: true,
|
|
32
|
+
'connection.blocked': true,
|
|
33
|
+
authentication_failure_close: true,
|
|
34
|
+
},
|
|
43
35
|
};
|
|
44
36
|
|
|
45
37
|
// Construct the main frames used in the opening handshake
|
|
46
38
|
function openFrames(vhost, query, credentials, extraClientProperties) {
|
|
47
|
-
if (!vhost)
|
|
48
|
-
|
|
49
|
-
else
|
|
50
|
-
vhost = QS.unescape(vhost);
|
|
39
|
+
if (!vhost) vhost = '/';
|
|
40
|
+
else vhost = QS.unescape(vhost);
|
|
51
41
|
|
|
52
|
-
|
|
42
|
+
query = query || {};
|
|
53
43
|
|
|
54
44
|
function intOrDefault(val, def) {
|
|
55
|
-
return
|
|
45
|
+
return val === undefined ? def : parseInt(val, 10);
|
|
56
46
|
}
|
|
57
47
|
|
|
58
|
-
|
|
48
|
+
const clientProperties = Object.create(CLIENT_PROPERTIES);
|
|
59
49
|
|
|
60
50
|
return {
|
|
61
51
|
// start-ok
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
clientProperties: copyInto(extraClientProperties, clientProperties),
|
|
53
|
+
mechanism: credentials.mechanism,
|
|
54
|
+
response: credentials.response(),
|
|
55
|
+
locale: query.locale || 'en_US',
|
|
66
56
|
|
|
67
57
|
// tune-ok
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
channelMax: intOrDefault(query.channelMax, 0),
|
|
59
|
+
frameMax: intOrDefault(query.frameMax, 131072),
|
|
60
|
+
heartbeat: intOrDefault(query.heartbeat, 0),
|
|
71
61
|
|
|
72
62
|
// open
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
virtualHost: vhost,
|
|
64
|
+
capabilities: '',
|
|
65
|
+
insist: 0,
|
|
76
66
|
};
|
|
77
67
|
}
|
|
78
68
|
|
|
79
69
|
// Decide on credentials based on what we're supplied.
|
|
80
70
|
function credentialsFromUrl(parts) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
let user = 'guest';
|
|
72
|
+
let passwd = 'guest';
|
|
73
|
+
if (parts.username !== '' || parts.password !== '') {
|
|
74
|
+
user = parts.username ? unescape(parts.username) : '';
|
|
75
|
+
passwd = parts.password ? unescape(parts.password) : '';
|
|
85
76
|
}
|
|
86
77
|
return credentials.plain(user, passwd);
|
|
87
78
|
}
|
|
@@ -91,35 +82,38 @@ function connect(url, socketOptions, openCallback) {
|
|
|
91
82
|
// copies only properties mentioned in `Object.keys()`, when
|
|
92
83
|
// processing the options. So I have to make copies too, rather
|
|
93
84
|
// than using `Object.create()`.
|
|
94
|
-
|
|
85
|
+
const sockopts = clone(socketOptions || {});
|
|
95
86
|
url = url || 'amqp://localhost';
|
|
96
87
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
const noDelay = !!sockopts.noDelay;
|
|
89
|
+
const timeout = sockopts.timeout;
|
|
90
|
+
const keepAlive = !!sockopts.keepAlive;
|
|
100
91
|
// 0 is default for node
|
|
101
|
-
|
|
92
|
+
const keepAliveDelay = sockopts.keepAliveDelay || 0;
|
|
102
93
|
|
|
103
|
-
|
|
94
|
+
const extraClientProperties = sockopts.clientProperties || {};
|
|
104
95
|
|
|
105
|
-
|
|
96
|
+
let protocol;
|
|
97
|
+
let fields;
|
|
106
98
|
if (typeof url === 'object') {
|
|
107
|
-
protocol =
|
|
99
|
+
protocol = `${url.protocol || 'amqp'}:`;
|
|
108
100
|
sockopts.host = url.hostname;
|
|
109
101
|
sockopts.servername = sockopts.servername || url.hostname;
|
|
110
|
-
sockopts.port = url.port || (
|
|
102
|
+
sockopts.port = url.port || (protocol === 'amqp:' ? 5672 : 5671);
|
|
111
103
|
|
|
112
|
-
|
|
104
|
+
let user;
|
|
105
|
+
let pass;
|
|
113
106
|
// Only default if both are missing, to have the same behaviour as
|
|
114
107
|
// the stringly URL.
|
|
115
|
-
if (url.username
|
|
116
|
-
user = 'guest';
|
|
108
|
+
if (url.username === undefined && url.password === undefined) {
|
|
109
|
+
user = 'guest';
|
|
110
|
+
pass = 'guest';
|
|
117
111
|
} else {
|
|
118
112
|
user = url.username || '';
|
|
119
113
|
pass = url.password || '';
|
|
120
114
|
}
|
|
121
115
|
|
|
122
|
-
|
|
116
|
+
const config = {
|
|
123
117
|
locale: url.locale,
|
|
124
118
|
channelMax: url.channelMax,
|
|
125
119
|
frameMax: url.frameMax,
|
|
@@ -128,25 +122,26 @@ function connect(url, socketOptions, openCallback) {
|
|
|
128
122
|
|
|
129
123
|
fields = openFrames(url.vhost, config, sockopts.credentials || credentials.plain(user, pass), extraClientProperties);
|
|
130
124
|
} else {
|
|
131
|
-
|
|
125
|
+
const parts = URL(url, true); // yes, parse the query string
|
|
126
|
+
const host = parts.hostname.replace(/^\[|\]$/g, '');
|
|
132
127
|
protocol = parts.protocol;
|
|
133
|
-
sockopts.host =
|
|
134
|
-
sockopts.servername = sockopts.servername ||
|
|
135
|
-
sockopts.port = parseInt(parts.port) || (
|
|
136
|
-
|
|
128
|
+
sockopts.host = host;
|
|
129
|
+
sockopts.servername = sockopts.servername || host;
|
|
130
|
+
sockopts.port = parseInt(parts.port, 10) || (protocol === 'amqp:' ? 5672 : 5671);
|
|
131
|
+
const vhost = parts.pathname ? parts.pathname.substr(1) : null;
|
|
137
132
|
fields = openFrames(vhost, parts.query, sockopts.credentials || credentialsFromUrl(parts), extraClientProperties);
|
|
138
133
|
}
|
|
139
134
|
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
let sockok = false;
|
|
136
|
+
let sock;
|
|
142
137
|
|
|
143
138
|
function onConnect() {
|
|
144
139
|
sockok = true;
|
|
145
140
|
sock.setNoDelay(noDelay);
|
|
146
141
|
if (keepAlive) sock.setKeepAlive(keepAlive, keepAliveDelay);
|
|
147
142
|
|
|
148
|
-
|
|
149
|
-
c.open(fields,
|
|
143
|
+
const c = new Connection(sock);
|
|
144
|
+
c.open(fields, (err, _ok) => {
|
|
150
145
|
// disable timeout once the connection is open, we don't want
|
|
151
146
|
// it fouling things
|
|
152
147
|
if (timeout) sock.setTimeout(0);
|
|
@@ -162,27 +157,24 @@ function connect(url, socketOptions, openCallback) {
|
|
|
162
157
|
}
|
|
163
158
|
|
|
164
159
|
if (protocol === 'amqp:') {
|
|
165
|
-
sock = require('net').connect(sockopts, onConnect);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
else {
|
|
171
|
-
throw new Error("Expected amqp: or amqps: as the protocol; got " + protocol);
|
|
160
|
+
sock = require('node:net').connect(sockopts, onConnect);
|
|
161
|
+
} else if (protocol === 'amqps:') {
|
|
162
|
+
sock = require('node:tls').connect(sockopts, onConnect);
|
|
163
|
+
} else {
|
|
164
|
+
throw new Error(`Expected amqp: or amqps: as the protocol; got ${protocol}`);
|
|
172
165
|
}
|
|
173
166
|
|
|
174
167
|
if (timeout) {
|
|
175
|
-
sock.setTimeout(timeout,
|
|
168
|
+
sock.setTimeout(timeout, () => {
|
|
176
169
|
sock.end();
|
|
177
170
|
sock.destroy();
|
|
178
171
|
openCallback(new Error('connect ETIMEDOUT'));
|
|
179
172
|
});
|
|
180
173
|
}
|
|
181
174
|
|
|
182
|
-
sock.once('error',
|
|
175
|
+
sock.once('error', (err) => {
|
|
183
176
|
if (!sockok) openCallback(err);
|
|
184
177
|
});
|
|
185
|
-
|
|
186
178
|
}
|
|
187
179
|
|
|
188
180
|
module.exports.connect = connect;
|