typespeed 2.0.21 → 2.0.22
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/core.decorator.js +1 -30
- package/dist/default/default-authentication.class.js +25 -0
- package/dist/default/express-server.class.js +11 -4
- package/dist/default/log-default.class.js +0 -6
- package/dist/factory/authentication-factory.class.js +11 -0
- package/dist/factory/log-factory.class.js +9 -0
- package/dist/route.decorator.js +92 -2
- package/dist/typespeed.d.ts +25 -3
- package/dist/typespeed.js +3 -1
- package/package.json +1 -1
- package/src/core.decorator.ts +1 -29
- package/src/default/default-authentication.class.ts +10 -0
- package/src/default/express-server.class.ts +12 -5
- package/src/default/log-default.class.ts +0 -10
- package/src/factory/authentication-factory.class.ts +9 -0
- package/src/factory/log-factory.class.ts +9 -2
- package/src/route.decorator.ts +91 -3
- package/src/typespeed.d.ts +25 -3
- package/src/typespeed.ts +1 -0
- package/test/node_modules/.package-lock.json +65 -101
- package/test/node_modules/@types/body-parser/LICENSE +21 -0
- package/test/node_modules/@types/body-parser/README.md +16 -0
- package/test/node_modules/@types/body-parser/index.d.ts +107 -0
- package/test/node_modules/@types/body-parser/package.json +58 -0
- package/test/node_modules/@types/connect/LICENSE +21 -0
- package/test/node_modules/@types/connect/README.md +16 -0
- package/test/node_modules/@types/connect/index.d.ts +93 -0
- package/test/node_modules/@types/connect/package.json +32 -0
- package/test/node_modules/@types/express/LICENSE +21 -0
- package/test/node_modules/@types/express/README.md +16 -0
- package/test/node_modules/@types/express/index.d.ts +136 -0
- package/test/node_modules/@types/express/package.json +45 -0
- package/test/node_modules/@types/express-serve-static-core/LICENSE +21 -0
- package/test/node_modules/@types/express-serve-static-core/README.md +16 -0
- package/test/node_modules/@types/express-serve-static-core/index.d.ts +1281 -0
- package/test/node_modules/@types/express-serve-static-core/package.json +55 -0
- package/test/node_modules/@types/mime/LICENSE +21 -0
- package/test/node_modules/@types/mime/Mime.d.ts +10 -0
- package/test/node_modules/@types/mime/README.md +16 -0
- package/test/node_modules/@types/mime/index.d.ts +35 -0
- package/test/node_modules/@types/mime/lite.d.ts +7 -0
- package/test/node_modules/@types/mime/package.json +29 -0
- package/test/node_modules/@types/qs/LICENSE +21 -0
- package/test/node_modules/@types/qs/README.md +16 -0
- package/test/node_modules/@types/qs/index.d.ts +62 -0
- package/test/node_modules/@types/qs/package.json +65 -0
- package/test/node_modules/@types/range-parser/LICENSE +21 -0
- package/test/node_modules/@types/range-parser/README.md +55 -0
- package/test/node_modules/@types/range-parser/index.d.ts +35 -0
- package/test/node_modules/@types/range-parser/package.json +25 -0
- package/test/node_modules/@types/send/LICENSE +21 -0
- package/test/node_modules/@types/send/README.md +16 -0
- package/test/node_modules/@types/send/index.d.ts +231 -0
- package/test/node_modules/@types/send/package.json +33 -0
- package/test/node_modules/@types/serve-static/LICENSE +21 -0
- package/test/node_modules/@types/serve-static/README.md +16 -0
- package/test/node_modules/@types/serve-static/index.d.ts +113 -0
- package/test/node_modules/@types/serve-static/package.json +38 -0
- package/test/src/config.json +5 -0
- package/test/src/custom-log.class.ts +6 -0
- package/test/src/jwt-authentication.class.ts +29 -0
- package/test/src/test-request.class.ts +36 -0
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +0 -17
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +0 -30
- package/test/node_modules/@acuminous/bitsyntax/LICENSE +0 -6
- package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +0 -21
- package/test/node_modules/@acuminous/bitsyntax/Makefile +0 -15
- package/test/node_modules/@acuminous/bitsyntax/README.md +0 -308
- package/test/node_modules/@acuminous/bitsyntax/index.js +0 -10
- package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +0 -303
- package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +0 -142
- package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +0 -67
- package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +0 -232
- package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +0 -32
- package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +0 -1173
- package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +0 -119
- package/test/node_modules/@acuminous/bitsyntax/package.json +0 -36
- package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +0 -50
- package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +0 -193
- package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/test/node_modules/amqplib/.github/workflows/test.yml +0 -38
- package/test/node_modules/amqplib/CHANGELOG.md +0 -430
- package/test/node_modules/amqplib/LICENSE +0 -6
- package/test/node_modules/amqplib/LICENSE-MIT +0 -21
- package/test/node_modules/amqplib/Makefile +0 -47
- package/test/node_modules/amqplib/README.md +0 -157
- package/test/node_modules/amqplib/bin/generate-defs.js +0 -722
- package/test/node_modules/amqplib/callback_api.js +0 -22
- package/test/node_modules/amqplib/channel_api.js +0 -16
- package/test/node_modules/amqplib/examples/headers.js +0 -42
- package/test/node_modules/amqplib/examples/receive_generator.js +0 -39
- package/test/node_modules/amqplib/examples/send_generators.js +0 -42
- package/test/node_modules/amqplib/examples/ssl.js +0 -64
- package/test/node_modules/amqplib/examples/tutorials/README.md +0 -93
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +0 -28
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +0 -30
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +0 -27
- package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +0 -27
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +0 -30
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +0 -36
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +0 -56
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +0 -55
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +0 -49
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +0 -45
- package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +0 -29
- package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +0 -35
- package/test/node_modules/amqplib/examples/tutorials/emit_log.js +0 -19
- package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +0 -20
- package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +0 -19
- package/test/node_modules/amqplib/examples/tutorials/new_task.js +0 -18
- package/test/node_modules/amqplib/examples/tutorials/package.json +0 -16
- package/test/node_modules/amqplib/examples/tutorials/receive.js +0 -21
- package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +0 -28
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +0 -44
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +0 -43
- package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +0 -52
- package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +0 -39
- package/test/node_modules/amqplib/examples/tutorials/send.js +0 -23
- package/test/node_modules/amqplib/examples/tutorials/worker.js +0 -28
- package/test/node_modules/amqplib/examples/waitForConfirms.js +0 -22
- package/test/node_modules/amqplib/lib/api_args.js +0 -314
- package/test/node_modules/amqplib/lib/bitset.js +0 -130
- package/test/node_modules/amqplib/lib/callback_model.js +0 -327
- package/test/node_modules/amqplib/lib/channel.js +0 -499
- package/test/node_modules/amqplib/lib/channel_model.js +0 -302
- package/test/node_modules/amqplib/lib/codec.js +0 -321
- package/test/node_modules/amqplib/lib/connect.js +0 -189
- package/test/node_modules/amqplib/lib/connection.js +0 -663
- package/test/node_modules/amqplib/lib/credentials.js +0 -42
- package/test/node_modules/amqplib/lib/defs.js +0 -4966
- package/test/node_modules/amqplib/lib/error.js +0 -24
- package/test/node_modules/amqplib/lib/format.js +0 -40
- package/test/node_modules/amqplib/lib/frame.js +0 -113
- package/test/node_modules/amqplib/lib/heartbeat.js +0 -89
- package/test/node_modules/amqplib/lib/mux.js +0 -129
- package/test/node_modules/amqplib/package.json +0 -37
- package/test/node_modules/amqplib/test/bitset.js +0 -69
- package/test/node_modules/amqplib/test/callback_api.js +0 -312
- package/test/node_modules/amqplib/test/channel.js +0 -621
- package/test/node_modules/amqplib/test/channel_api.js +0 -596
- package/test/node_modules/amqplib/test/codec.js +0 -237
- package/test/node_modules/amqplib/test/connect.js +0 -197
- package/test/node_modules/amqplib/test/connection.js +0 -390
- package/test/node_modules/amqplib/test/data.js +0 -254
- package/test/node_modules/amqplib/test/frame.js +0 -198
- package/test/node_modules/amqplib/test/mux.js +0 -204
- package/test/node_modules/amqplib/test/util.js +0 -219
- package/test/node_modules/buffer-more-ints/.travis.yml +0 -6
- package/test/node_modules/buffer-more-ints/LICENSE +0 -19
- package/test/node_modules/buffer-more-ints/README.md +0 -69
- package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +0 -183
- package/test/node_modules/buffer-more-ints/buffer-more-ints.js +0 -432
- package/test/node_modules/buffer-more-ints/package.json +0 -19
- package/test/node_modules/buffer-more-ints/polyfill.js +0 -71
- package/test/node_modules/core-util-is/LICENSE +0 -19
- package/test/node_modules/core-util-is/README.md +0 -3
- package/test/node_modules/core-util-is/lib/util.js +0 -107
- package/test/node_modules/core-util-is/package.json +0 -38
- package/test/node_modules/debug/LICENSE +0 -20
- package/test/node_modules/debug/README.md +0 -481
- package/test/node_modules/debug/package.json +0 -59
- package/test/node_modules/debug/src/browser.js +0 -269
- package/test/node_modules/debug/src/common.js +0 -274
- package/test/node_modules/debug/src/index.js +0 -10
- package/test/node_modules/debug/src/node.js +0 -263
- package/test/node_modules/inherits/LICENSE +0 -16
- package/test/node_modules/inherits/README.md +0 -42
- package/test/node_modules/inherits/inherits.js +0 -9
- package/test/node_modules/inherits/inherits_browser.js +0 -27
- package/test/node_modules/inherits/package.json +0 -29
- package/test/node_modules/isarray/README.md +0 -54
- package/test/node_modules/isarray/build/build.js +0 -209
- package/test/node_modules/isarray/component.json +0 -19
- package/test/node_modules/isarray/index.js +0 -3
- package/test/node_modules/isarray/package.json +0 -25
- package/test/node_modules/ms/index.js +0 -162
- package/test/node_modules/ms/license.md +0 -21
- package/test/node_modules/ms/package.json +0 -37
- package/test/node_modules/ms/readme.md +0 -60
- package/test/node_modules/querystringify/LICENSE +0 -22
- package/test/node_modules/querystringify/README.md +0 -61
- package/test/node_modules/querystringify/index.js +0 -118
- package/test/node_modules/querystringify/package.json +0 -38
- package/test/node_modules/readable-stream/LICENSE +0 -18
- package/test/node_modules/readable-stream/README.md +0 -15
- package/test/node_modules/readable-stream/duplex.js +0 -1
- package/test/node_modules/readable-stream/float.patch +0 -923
- package/test/node_modules/readable-stream/lib/_stream_duplex.js +0 -89
- package/test/node_modules/readable-stream/lib/_stream_passthrough.js +0 -46
- package/test/node_modules/readable-stream/lib/_stream_readable.js +0 -951
- package/test/node_modules/readable-stream/lib/_stream_transform.js +0 -209
- package/test/node_modules/readable-stream/lib/_stream_writable.js +0 -477
- package/test/node_modules/readable-stream/package.json +0 -32
- package/test/node_modules/readable-stream/passthrough.js +0 -1
- package/test/node_modules/readable-stream/readable.js +0 -10
- package/test/node_modules/readable-stream/transform.js +0 -1
- package/test/node_modules/readable-stream/writable.js +0 -1
- package/test/node_modules/requires-port/.travis.yml +0 -19
- package/test/node_modules/requires-port/LICENSE +0 -22
- package/test/node_modules/requires-port/README.md +0 -47
- package/test/node_modules/requires-port/index.js +0 -38
- package/test/node_modules/requires-port/package.json +0 -47
- package/test/node_modules/requires-port/test.js +0 -98
- package/test/node_modules/safe-buffer/LICENSE +0 -21
- package/test/node_modules/safe-buffer/README.md +0 -584
- package/test/node_modules/safe-buffer/index.d.ts +0 -187
- package/test/node_modules/safe-buffer/index.js +0 -62
- package/test/node_modules/safe-buffer/package.json +0 -37
- package/test/node_modules/string_decoder/LICENSE +0 -20
- package/test/node_modules/string_decoder/README.md +0 -7
- package/test/node_modules/string_decoder/index.js +0 -221
- package/test/node_modules/string_decoder/package.json +0 -25
- package/test/node_modules/url-parse/LICENSE +0 -22
- package/test/node_modules/url-parse/README.md +0 -153
- package/test/node_modules/url-parse/dist/url-parse.js +0 -755
- package/test/node_modules/url-parse/dist/url-parse.min.js +0 -1
- package/test/node_modules/url-parse/dist/url-parse.min.js.map +0 -1
- package/test/node_modules/url-parse/index.js +0 -589
- package/test/node_modules/url-parse/package.json +0 -49
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
const EventEmitter = require('events');
|
|
8
|
-
const promisify = require('util').promisify;
|
|
9
|
-
const defs = require('./defs');
|
|
10
|
-
const {BaseChannel} = require('./channel');
|
|
11
|
-
const {acceptMessage} = require('./channel');
|
|
12
|
-
const Args = require('./api_args');
|
|
13
|
-
const {inspect} = require('./format');
|
|
14
|
-
|
|
15
|
-
class ChannelModel extends EventEmitter {
|
|
16
|
-
constructor(connection) {
|
|
17
|
-
super();
|
|
18
|
-
this.connection = connection;
|
|
19
|
-
|
|
20
|
-
['error', 'close', 'blocked', 'unblocked'].forEach(ev => {
|
|
21
|
-
connection.on(ev, this.emit.bind(this, ev));
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
close() {
|
|
26
|
-
return promisify(this.connection.close.bind(this.connection))();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async createChannel() {
|
|
30
|
-
const channel = new Channel(this.connection);
|
|
31
|
-
await channel.open();
|
|
32
|
-
return channel;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async createConfirmChannel() {
|
|
36
|
-
const channel = new ConfirmChannel(this.connection);
|
|
37
|
-
await channel.open();
|
|
38
|
-
await channel.rpc(defs.ConfirmSelect, {nowait: false}, defs.ConfirmSelectOk);
|
|
39
|
-
return channel;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Channels
|
|
44
|
-
|
|
45
|
-
class Channel extends BaseChannel {
|
|
46
|
-
constructor(connection) {
|
|
47
|
-
super(connection);
|
|
48
|
-
this.on('delivery', this.handleDelivery.bind(this));
|
|
49
|
-
this.on('cancel', this.handleCancel.bind(this));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// An RPC that returns a 'proper' promise, which resolves to just the
|
|
53
|
-
// response's fields; this is intended to be suitable for implementing
|
|
54
|
-
// API procedures.
|
|
55
|
-
async rpc(method, fields, expect) {
|
|
56
|
-
const f = await promisify(cb => {
|
|
57
|
-
return this._rpc(method, fields, expect, cb);
|
|
58
|
-
})();
|
|
59
|
-
|
|
60
|
-
return f.fields;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Do the remarkably simple channel open handshake
|
|
64
|
-
async open() {
|
|
65
|
-
const ch = await this.allocate.bind(this)();
|
|
66
|
-
return ch.rpc(defs.ChannelOpen, {outOfBand: ""},
|
|
67
|
-
defs.ChannelOpenOk);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
close() {
|
|
71
|
-
return promisify(cb => {
|
|
72
|
-
return this.closeBecause("Goodbye", defs.constants.REPLY_SUCCESS,
|
|
73
|
-
cb);
|
|
74
|
-
})();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// === Public API, declaring queues and stuff ===
|
|
78
|
-
|
|
79
|
-
assertQueue(queue, options) {
|
|
80
|
-
return this.rpc(defs.QueueDeclare,
|
|
81
|
-
Args.assertQueue(queue, options),
|
|
82
|
-
defs.QueueDeclareOk);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
checkQueue(queue) {
|
|
86
|
-
return this.rpc(defs.QueueDeclare,
|
|
87
|
-
Args.checkQueue(queue),
|
|
88
|
-
defs.QueueDeclareOk);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
deleteQueue(queue, options) {
|
|
92
|
-
return this.rpc(defs.QueueDelete,
|
|
93
|
-
Args.deleteQueue(queue, options),
|
|
94
|
-
defs.QueueDeleteOk);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
purgeQueue(queue) {
|
|
98
|
-
return this.rpc(defs.QueuePurge,
|
|
99
|
-
Args.purgeQueue(queue),
|
|
100
|
-
defs.QueuePurgeOk);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
bindQueue(queue, source, pattern, argt) {
|
|
104
|
-
return this.rpc(defs.QueueBind,
|
|
105
|
-
Args.bindQueue(queue, source, pattern, argt),
|
|
106
|
-
defs.QueueBindOk);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
unbindQueue(queue, source, pattern, argt) {
|
|
110
|
-
return this.rpc(defs.QueueUnbind,
|
|
111
|
-
Args.unbindQueue(queue, source, pattern, argt),
|
|
112
|
-
defs.QueueUnbindOk);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
assertExchange(exchange, type, options) {
|
|
116
|
-
// The server reply is an empty set of fields, but it's convenient
|
|
117
|
-
// to have the exchange name handed to the continuation.
|
|
118
|
-
return this.rpc(defs.ExchangeDeclare,
|
|
119
|
-
Args.assertExchange(exchange, type, options),
|
|
120
|
-
defs.ExchangeDeclareOk)
|
|
121
|
-
.then(_ok => { return { exchange }; });
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
checkExchange(exchange) {
|
|
125
|
-
return this.rpc(defs.ExchangeDeclare,
|
|
126
|
-
Args.checkExchange(exchange),
|
|
127
|
-
defs.ExchangeDeclareOk);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
deleteExchange(name, options) {
|
|
131
|
-
return this.rpc(defs.ExchangeDelete,
|
|
132
|
-
Args.deleteExchange(name, options),
|
|
133
|
-
defs.ExchangeDeleteOk);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
bindExchange(dest, source, pattern, argt) {
|
|
137
|
-
return this.rpc(defs.ExchangeBind,
|
|
138
|
-
Args.bindExchange(dest, source, pattern, argt),
|
|
139
|
-
defs.ExchangeBindOk);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
unbindExchange(dest, source, pattern, argt) {
|
|
143
|
-
return this.rpc(defs.ExchangeUnbind,
|
|
144
|
-
Args.unbindExchange(dest, source, pattern, argt),
|
|
145
|
-
defs.ExchangeUnbindOk);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Working with messages
|
|
149
|
-
|
|
150
|
-
publish(exchange, routingKey, content, options) {
|
|
151
|
-
const fieldsAndProps = Args.publish(exchange, routingKey, options);
|
|
152
|
-
return this.sendMessage(fieldsAndProps, fieldsAndProps, content);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
sendToQueue(queue, content, options) {
|
|
156
|
-
return this.publish('', queue, content, options);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
consume(queue, callback, options) {
|
|
160
|
-
// NB we want the callback to be run synchronously, so that we've
|
|
161
|
-
// registered the consumerTag before any messages can arrive.
|
|
162
|
-
const fields = Args.consume(queue, options);
|
|
163
|
-
return new Promise((resolve, reject) => {
|
|
164
|
-
this._rpc(defs.BasicConsume, fields, defs.BasicConsumeOk, (err, ok) => {
|
|
165
|
-
if (err) return reject(err);
|
|
166
|
-
this.registerConsumer(ok.fields.consumerTag, callback);
|
|
167
|
-
resolve(ok.fields);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
async cancel(consumerTag) {
|
|
173
|
-
const ok = await promisify(cb => {
|
|
174
|
-
this._rpc(defs.BasicCancel, Args.cancel(consumerTag),
|
|
175
|
-
defs.BasicCancelOk,
|
|
176
|
-
cb);
|
|
177
|
-
})()
|
|
178
|
-
.then(ok => {
|
|
179
|
-
this.unregisterConsumer(consumerTag);
|
|
180
|
-
return ok.fields;
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
get(queue, options) {
|
|
185
|
-
const fields = Args.get(queue, options);
|
|
186
|
-
return new Promise((resolve, reject) => {
|
|
187
|
-
this.sendOrEnqueue(defs.BasicGet, fields, (err, f) => {
|
|
188
|
-
if (err) return reject(err);
|
|
189
|
-
if (f.id === defs.BasicGetEmpty) {
|
|
190
|
-
return resolve(false);
|
|
191
|
-
}
|
|
192
|
-
else if (f.id === defs.BasicGetOk) {
|
|
193
|
-
const fields = f.fields;
|
|
194
|
-
this.handleMessage = acceptMessage(m => {
|
|
195
|
-
m.fields = fields;
|
|
196
|
-
resolve(m);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
reject(new Error(`Unexpected response to BasicGet: ${inspect(f)}`));
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
ack(message, allUpTo) {
|
|
207
|
-
this.sendImmediately(
|
|
208
|
-
defs.BasicAck,
|
|
209
|
-
Args.ack(message.fields.deliveryTag, allUpTo));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
ackAll() {
|
|
213
|
-
this.sendImmediately(defs.BasicAck, Args.ack(0, true));
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
nack(message, allUpTo, requeue) {
|
|
217
|
-
this.sendImmediately(
|
|
218
|
-
defs.BasicNack,
|
|
219
|
-
Args.nack(message.fields.deliveryTag, allUpTo, requeue));
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
nackAll(requeue) {
|
|
223
|
-
this.sendImmediately(defs.BasicNack,
|
|
224
|
-
Args.nack(0, true, requeue));
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// `Basic.Nack` is not available in older RabbitMQ versions (or in the
|
|
228
|
-
// AMQP specification), so you have to use the one-at-a-time
|
|
229
|
-
// `Basic.Reject`. This is otherwise synonymous with
|
|
230
|
-
// `#nack(message, false, requeue)`.
|
|
231
|
-
reject(message, requeue) {
|
|
232
|
-
this.sendImmediately(
|
|
233
|
-
defs.BasicReject,
|
|
234
|
-
Args.reject(message.fields.deliveryTag, requeue));
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
recover() {
|
|
238
|
-
return this.rpc(defs.BasicRecover,
|
|
239
|
-
Args.recover(),
|
|
240
|
-
defs.BasicRecoverOk);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
qos(count, global) {
|
|
244
|
-
return this.rpc(defs.BasicQos,
|
|
245
|
-
Args.prefetch(count, global),
|
|
246
|
-
defs.BasicQosOk);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// There are more options in AMQP than exposed here; RabbitMQ only
|
|
251
|
-
// implements prefetch based on message count, and only for individual
|
|
252
|
-
// channels or consumers. RabbitMQ v3.3.0 and after treat prefetch
|
|
253
|
-
// (without `global` set) as per-consumer (for consumers following),
|
|
254
|
-
// and prefetch with `global` set as per-channel.
|
|
255
|
-
Channel.prototype.prefetch = Channel.prototype.qos
|
|
256
|
-
|
|
257
|
-
// Confirm channel. This is a channel with confirms 'switched on',
|
|
258
|
-
// meaning sent messages will provoke a responding 'ack' or 'nack'
|
|
259
|
-
// from the server. The upshot of this is that `publish` and
|
|
260
|
-
// `sendToQueue` both take a callback, which will be called either
|
|
261
|
-
// with `null` as its argument to signify 'ack', or an exception as
|
|
262
|
-
// its argument to signify 'nack'.
|
|
263
|
-
|
|
264
|
-
class ConfirmChannel extends Channel {
|
|
265
|
-
publish(exchange, routingKey, content, options, cb) {
|
|
266
|
-
this.pushConfirmCallback(cb);
|
|
267
|
-
return Channel.prototype.publish.call(this, exchange, routingKey, content, options);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
sendToQueue(queue, content, options, cb) {
|
|
271
|
-
return this.publish('', queue, content, options, cb);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
waitForConfirms() {
|
|
275
|
-
const awaiting = [];
|
|
276
|
-
const unconfirmed = this.unconfirmed;
|
|
277
|
-
unconfirmed.forEach((val, index) => {
|
|
278
|
-
if (val !== null) {
|
|
279
|
-
const confirmed = new Promise((resolve, reject) => {
|
|
280
|
-
unconfirmed[index] = err => {
|
|
281
|
-
if (val) val(err);
|
|
282
|
-
if (err === null) resolve();
|
|
283
|
-
else reject(err);
|
|
284
|
-
};
|
|
285
|
-
});
|
|
286
|
-
awaiting.push(confirmed);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
// Channel closed
|
|
290
|
-
if (!this.pending) {
|
|
291
|
-
var cb;
|
|
292
|
-
while (cb = this.unconfirmed.shift()) {
|
|
293
|
-
if (cb) cb(new Error('channel closed'));
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return Promise.all(awaiting);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
module.exports.ConfirmChannel = ConfirmChannel;
|
|
301
|
-
module.exports.Channel = Channel;
|
|
302
|
-
module.exports.ChannelModel = ChannelModel;
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
|
|
7
|
-
The AMQP 0-9-1 is a mess when it comes to the types that can be
|
|
8
|
-
encoded on the wire.
|
|
9
|
-
|
|
10
|
-
There are four encoding schemes, and three overlapping sets of types:
|
|
11
|
-
frames, methods, (field-)tables, and properties.
|
|
12
|
-
|
|
13
|
-
Each *frame type* has a set layout in which values of given types are
|
|
14
|
-
concatenated along with sections of "raw binary" data.
|
|
15
|
-
|
|
16
|
-
In frames there are `shortstr`s, that is length-prefixed strings of
|
|
17
|
-
UTF8 chars, 8 bit unsigned integers (called `octet`), unsigned 16 bit
|
|
18
|
-
integers (called `short` or `short-uint`), unsigned 32 bit integers
|
|
19
|
-
(called `long` or `long-uint`), unsigned 64 bit integers (called
|
|
20
|
-
`longlong` or `longlong-uint`), and flags (called `bit`).
|
|
21
|
-
|
|
22
|
-
Methods are encoded as a frame giving a method ID and a sequence of
|
|
23
|
-
arguments of known types. The encoded method argument values are
|
|
24
|
-
concatenated (with some fun complications around "packing" consecutive
|
|
25
|
-
bit values into bytes).
|
|
26
|
-
|
|
27
|
-
Along with the types given in frames, method arguments may be long
|
|
28
|
-
byte strings (`longstr`, not required to be UTF8) or 64 bit unsigned
|
|
29
|
-
integers to be interpreted as timestamps (yeah I don't know why
|
|
30
|
-
either), or arbitrary sets of key-value pairs (called `field-table`).
|
|
31
|
-
|
|
32
|
-
Inside a field table the keys are `shortstr` and the values are
|
|
33
|
-
prefixed with a byte tag giving the type. The types are any of the
|
|
34
|
-
above except for bits (which are replaced by byte-wide `bool`), along
|
|
35
|
-
with a NULL value `void`, a special fixed-precision number encoding
|
|
36
|
-
(`decimal`), IEEE754 `float`s and `double`s, signed integers,
|
|
37
|
-
`field-array` (a sequence of tagged values), and nested field-tables.
|
|
38
|
-
|
|
39
|
-
RabbitMQ and QPid use a subset of the field-table types, and different
|
|
40
|
-
value tags, established before the AMQP 0-9-1 specification was
|
|
41
|
-
published. So far as I know, no-one uses the types and tags as
|
|
42
|
-
published. http://www.rabbitmq.com/amqp-0-9-1-errata.html gives the
|
|
43
|
-
list of field-table types.
|
|
44
|
-
|
|
45
|
-
Lastly, there are (sets of) properties, only one of which is given in
|
|
46
|
-
AMQP 0-9-1: `BasicProperties`. These are almost the same as methods,
|
|
47
|
-
except that they appear in content header frames, which include a
|
|
48
|
-
content size, and they carry a set of flags indicating which
|
|
49
|
-
properties are present. This scheme can save ones of bytes per message
|
|
50
|
-
(messages which take a minimum of three frames each to send).
|
|
51
|
-
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
'use strict';
|
|
55
|
-
|
|
56
|
-
var ints = require('buffer-more-ints');
|
|
57
|
-
|
|
58
|
-
// JavaScript uses only doubles so what I'm testing for is whether
|
|
59
|
-
// it's *better* to encode a number as a float or double. This really
|
|
60
|
-
// just amounts to testing whether there's a fractional part to the
|
|
61
|
-
// number, except that see below. NB I don't use bitwise operations to
|
|
62
|
-
// do this 'efficiently' -- it would mask the number to 32 bits.
|
|
63
|
-
//
|
|
64
|
-
// At 2^50, doubles don't have sufficient precision to distinguish
|
|
65
|
-
// between floating point and integer numbers (`Math.pow(2, 50) + 0.1
|
|
66
|
-
// === Math.pow(2, 50)` (and, above 2^53, doubles cannot represent all
|
|
67
|
-
// integers (`Math.pow(2, 53) + 1 === Math.pow(2, 53)`)). Hence
|
|
68
|
-
// anything with a magnitude at or above 2^50 may as well be encoded
|
|
69
|
-
// as a 64-bit integer. Except that only signed integers are supported
|
|
70
|
-
// by RabbitMQ, so anything above 2^63 - 1 must be a double.
|
|
71
|
-
function isFloatingPoint(n) {
|
|
72
|
-
return n >= 0x8000000000000000 ||
|
|
73
|
-
(Math.abs(n) < 0x4000000000000
|
|
74
|
-
&& Math.floor(n) !== n);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function encodeTable(buffer, val, offset) {
|
|
78
|
-
var start = offset;
|
|
79
|
-
offset += 4; // leave room for the table length
|
|
80
|
-
for (var key in val) {
|
|
81
|
-
if (val[key] !== undefined) {
|
|
82
|
-
var len = Buffer.byteLength(key);
|
|
83
|
-
buffer.writeUInt8(len, offset); offset++;
|
|
84
|
-
buffer.write(key, offset, 'utf8'); offset += len;
|
|
85
|
-
offset += encodeFieldValue(buffer, val[key], offset);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
var size = offset - start;
|
|
89
|
-
buffer.writeUInt32BE(size - 4, start);
|
|
90
|
-
return size;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function encodeArray(buffer, val, offset) {
|
|
94
|
-
var start = offset;
|
|
95
|
-
offset += 4;
|
|
96
|
-
for (var i=0, num=val.length; i < num; i++) {
|
|
97
|
-
offset += encodeFieldValue(buffer, val[i], offset);
|
|
98
|
-
}
|
|
99
|
-
var size = offset - start;
|
|
100
|
-
buffer.writeUInt32BE(size - 4, start);
|
|
101
|
-
return size;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function encodeFieldValue(buffer, value, offset) {
|
|
105
|
-
var start = offset;
|
|
106
|
-
var type = typeof value, val = value;
|
|
107
|
-
// A trapdoor for specifying a type, e.g., timestamp
|
|
108
|
-
if (value && type === 'object' && value.hasOwnProperty('!')) {
|
|
109
|
-
val = value.value;
|
|
110
|
-
type = value['!'];
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// If it's a JS number, we'll have to guess what type to encode it
|
|
114
|
-
// as.
|
|
115
|
-
if (type == 'number') {
|
|
116
|
-
// Making assumptions about the kind of number (floating point
|
|
117
|
-
// v integer, signed, unsigned, size) desired is dangerous in
|
|
118
|
-
// general; however, in practice RabbitMQ uses only
|
|
119
|
-
// longstrings and unsigned integers in its arguments, and
|
|
120
|
-
// other clients generally conflate number types anyway. So
|
|
121
|
-
// the only distinction we care about is floating point vs
|
|
122
|
-
// integers, preferring integers since those can be promoted
|
|
123
|
-
// if necessary. If floating point is required, we may as well
|
|
124
|
-
// use double precision.
|
|
125
|
-
if (isFloatingPoint(val)) {
|
|
126
|
-
type = 'double';
|
|
127
|
-
}
|
|
128
|
-
else { // only signed values are used in tables by
|
|
129
|
-
// RabbitMQ. It *used* to (< v3.3.0) treat the byte 'b'
|
|
130
|
-
// type as unsigned, but most clients (and the spec)
|
|
131
|
-
// think it's signed, and now RabbitMQ does too.
|
|
132
|
-
if (val < 128 && val >= -128) {
|
|
133
|
-
type = 'byte';
|
|
134
|
-
}
|
|
135
|
-
else if (val >= -0x8000 && val < 0x8000) {
|
|
136
|
-
type = 'short'
|
|
137
|
-
}
|
|
138
|
-
else if (val >= -0x80000000 && val < 0x80000000) {
|
|
139
|
-
type = 'int';
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
type = 'long';
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function tag(t) { buffer.write(t, offset); offset++; }
|
|
148
|
-
|
|
149
|
-
switch (type) {
|
|
150
|
-
case 'string': // no shortstr in field tables
|
|
151
|
-
var len = Buffer.byteLength(val, 'utf8');
|
|
152
|
-
tag('S');
|
|
153
|
-
buffer.writeUInt32BE(len, offset); offset += 4;
|
|
154
|
-
buffer.write(val, offset, 'utf8'); offset += len;
|
|
155
|
-
break;
|
|
156
|
-
case 'object':
|
|
157
|
-
if (val === null) {
|
|
158
|
-
tag('V');
|
|
159
|
-
}
|
|
160
|
-
else if (Array.isArray(val)) {
|
|
161
|
-
tag('A');
|
|
162
|
-
offset += encodeArray(buffer, val, offset);
|
|
163
|
-
}
|
|
164
|
-
else if (Buffer.isBuffer(val)) {
|
|
165
|
-
tag('x');
|
|
166
|
-
buffer.writeUInt32BE(val.length, offset); offset += 4;
|
|
167
|
-
val.copy(buffer, offset); offset += val.length;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
tag('F');
|
|
171
|
-
offset += encodeTable(buffer, val, offset);
|
|
172
|
-
}
|
|
173
|
-
break;
|
|
174
|
-
case 'boolean':
|
|
175
|
-
tag('t');
|
|
176
|
-
buffer.writeUInt8((val) ? 1 : 0, offset); offset++;
|
|
177
|
-
break;
|
|
178
|
-
// These are the types that are either guessed above, or
|
|
179
|
-
// explicitly given using the {'!': type} notation.
|
|
180
|
-
case 'double':
|
|
181
|
-
case 'float64':
|
|
182
|
-
tag('d');
|
|
183
|
-
buffer.writeDoubleBE(val, offset);
|
|
184
|
-
offset += 8;
|
|
185
|
-
break;
|
|
186
|
-
case 'byte':
|
|
187
|
-
case 'int8':
|
|
188
|
-
tag('b');
|
|
189
|
-
buffer.writeInt8(val, offset); offset++;
|
|
190
|
-
break;
|
|
191
|
-
case 'short':
|
|
192
|
-
case 'int16':
|
|
193
|
-
tag('s');
|
|
194
|
-
buffer.writeInt16BE(val, offset); offset += 2;
|
|
195
|
-
break;
|
|
196
|
-
case 'int':
|
|
197
|
-
case 'int32':
|
|
198
|
-
tag('I');
|
|
199
|
-
buffer.writeInt32BE(val, offset); offset += 4;
|
|
200
|
-
break;
|
|
201
|
-
case 'long':
|
|
202
|
-
case 'int64':
|
|
203
|
-
tag('l');
|
|
204
|
-
ints.writeInt64BE(buffer, val, offset); offset += 8;
|
|
205
|
-
break;
|
|
206
|
-
|
|
207
|
-
// Now for exotic types, those can _only_ be denoted by using
|
|
208
|
-
// `{'!': type, value: val}
|
|
209
|
-
case 'timestamp':
|
|
210
|
-
tag('T');
|
|
211
|
-
ints.writeUInt64BE(buffer, val, offset); offset += 8;
|
|
212
|
-
break;
|
|
213
|
-
case 'float':
|
|
214
|
-
tag('f');
|
|
215
|
-
buffer.writeFloatBE(val, offset); offset += 4;
|
|
216
|
-
break;
|
|
217
|
-
case 'decimal':
|
|
218
|
-
tag('D');
|
|
219
|
-
if (val.hasOwnProperty('places') && val.hasOwnProperty('digits')
|
|
220
|
-
&& val.places >= 0 && val.places < 256) {
|
|
221
|
-
buffer[offset] = val.places; offset++;
|
|
222
|
-
buffer.writeUInt32BE(val.digits, offset); offset += 4;
|
|
223
|
-
}
|
|
224
|
-
else throw new TypeError(
|
|
225
|
-
"Decimal value must be {'places': 0..255, 'digits': uint32}, " +
|
|
226
|
-
"got " + JSON.stringify(val));
|
|
227
|
-
break;
|
|
228
|
-
default:
|
|
229
|
-
throw new TypeError('Unknown type to encode: ' + type);
|
|
230
|
-
}
|
|
231
|
-
return offset - start;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Assume we're given a slice of the buffer that contains just the
|
|
235
|
-
// fields.
|
|
236
|
-
function decodeFields(slice) {
|
|
237
|
-
var fields = {}, offset = 0, size = slice.length;
|
|
238
|
-
var len, key, val;
|
|
239
|
-
|
|
240
|
-
function decodeFieldValue() {
|
|
241
|
-
var tag = String.fromCharCode(slice[offset]); offset++;
|
|
242
|
-
switch (tag) {
|
|
243
|
-
case 'b':
|
|
244
|
-
val = slice.readInt8(offset); offset++;
|
|
245
|
-
break;
|
|
246
|
-
case 'S':
|
|
247
|
-
len = slice.readUInt32BE(offset); offset += 4;
|
|
248
|
-
val = slice.toString('utf8', offset, offset + len);
|
|
249
|
-
offset += len;
|
|
250
|
-
break;
|
|
251
|
-
case 'I':
|
|
252
|
-
val = slice.readInt32BE(offset); offset += 4;
|
|
253
|
-
break;
|
|
254
|
-
case 'D': // only positive decimals, apparently.
|
|
255
|
-
var places = slice[offset]; offset++;
|
|
256
|
-
var digits = slice.readUInt32BE(offset); offset += 4;
|
|
257
|
-
val = {'!': 'decimal', value: {places: places, digits: digits}};
|
|
258
|
-
break;
|
|
259
|
-
case 'T':
|
|
260
|
-
val = ints.readUInt64BE(slice, offset); offset += 8;
|
|
261
|
-
val = {'!': 'timestamp', value: val};
|
|
262
|
-
break;
|
|
263
|
-
case 'F':
|
|
264
|
-
len = slice.readUInt32BE(offset); offset += 4;
|
|
265
|
-
val = decodeFields(slice.slice(offset, offset + len));
|
|
266
|
-
offset += len;
|
|
267
|
-
break;
|
|
268
|
-
case 'A':
|
|
269
|
-
len = slice.readUInt32BE(offset); offset += 4;
|
|
270
|
-
decodeArray(offset + len);
|
|
271
|
-
// NB decodeArray will itself update offset and val
|
|
272
|
-
break;
|
|
273
|
-
case 'd':
|
|
274
|
-
val = slice.readDoubleBE(offset); offset += 8;
|
|
275
|
-
break;
|
|
276
|
-
case 'f':
|
|
277
|
-
val = slice.readFloatBE(offset); offset += 4;
|
|
278
|
-
break;
|
|
279
|
-
case 'l':
|
|
280
|
-
val = ints.readInt64BE(slice, offset); offset += 8;
|
|
281
|
-
break;
|
|
282
|
-
case 's':
|
|
283
|
-
val = slice.readInt16BE(offset); offset += 2;
|
|
284
|
-
break;
|
|
285
|
-
case 't':
|
|
286
|
-
val = slice[offset] != 0; offset++;
|
|
287
|
-
break;
|
|
288
|
-
case 'V':
|
|
289
|
-
val = null;
|
|
290
|
-
break;
|
|
291
|
-
case 'x':
|
|
292
|
-
len = slice.readUInt32BE(offset); offset += 4;
|
|
293
|
-
val = slice.slice(offset, offset + len);
|
|
294
|
-
offset += len;
|
|
295
|
-
break;
|
|
296
|
-
default:
|
|
297
|
-
throw new TypeError('Unexpected type tag "' + tag +'"');
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function decodeArray(until) {
|
|
302
|
-
var vals = [];
|
|
303
|
-
while (offset < until) {
|
|
304
|
-
decodeFieldValue();
|
|
305
|
-
vals.push(val);
|
|
306
|
-
}
|
|
307
|
-
val = vals;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
while (offset < size) {
|
|
311
|
-
len = slice.readUInt8(offset); offset++;
|
|
312
|
-
key = slice.toString('utf8', offset, offset + len);
|
|
313
|
-
offset += len;
|
|
314
|
-
decodeFieldValue();
|
|
315
|
-
fields[key] = val;
|
|
316
|
-
}
|
|
317
|
-
return fields;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
module.exports.encodeTable = encodeTable;
|
|
321
|
-
module.exports.decodeFields = decodeFields;
|