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,499 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// Channel machinery.
|
|
6
|
-
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
var defs = require('./defs');
|
|
10
|
-
var closeMsg = require('./format').closeMessage;
|
|
11
|
-
var inspect = require('./format').inspect;
|
|
12
|
-
var methodName = require('./format').methodName;
|
|
13
|
-
var assert = require('assert');
|
|
14
|
-
var inherits = require('util').inherits;
|
|
15
|
-
var EventEmitter = require('events').EventEmitter;
|
|
16
|
-
var fmt = require('util').format;
|
|
17
|
-
var IllegalOperationError = require('./error').IllegalOperationError;
|
|
18
|
-
var stackCapture = require('./error').stackCapture;
|
|
19
|
-
function Channel(connection) {
|
|
20
|
-
EventEmitter.call( this );
|
|
21
|
-
this.connection = connection;
|
|
22
|
-
// for the presently outstanding RPC
|
|
23
|
-
this.reply = null;
|
|
24
|
-
// for the RPCs awaiting action
|
|
25
|
-
this.pending = [];
|
|
26
|
-
// for unconfirmed messages
|
|
27
|
-
this.lwm = 1; // the least, unconfirmed deliveryTag
|
|
28
|
-
this.unconfirmed = []; // rolling window of delivery callbacks
|
|
29
|
-
this.on('ack', this.handleConfirm.bind(this, function(cb) {
|
|
30
|
-
if (cb) cb(null);
|
|
31
|
-
}));
|
|
32
|
-
this.on('nack', this.handleConfirm.bind(this, function(cb) {
|
|
33
|
-
if (cb) cb(new Error('message nacked'));
|
|
34
|
-
}));
|
|
35
|
-
this.on('close', function () {
|
|
36
|
-
var cb;
|
|
37
|
-
while (cb = this.unconfirmed.shift()) {
|
|
38
|
-
if (cb) cb(new Error('channel closed'));
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
// message frame state machine
|
|
42
|
-
this.handleMessage = acceptDeliveryOrReturn;
|
|
43
|
-
}
|
|
44
|
-
inherits(Channel, EventEmitter);
|
|
45
|
-
|
|
46
|
-
module.exports.Channel = Channel;
|
|
47
|
-
module.exports.acceptMessage = acceptMessage;
|
|
48
|
-
|
|
49
|
-
var C = Channel.prototype;
|
|
50
|
-
|
|
51
|
-
C.allocate = function() {
|
|
52
|
-
this.ch = this.connection.freshChannel(this);
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Incoming frames are either notifications of e.g., message delivery,
|
|
57
|
-
// or replies to something we've sent. In general I deal with the
|
|
58
|
-
// former by emitting an event, and with the latter by keeping a track
|
|
59
|
-
// of what's expecting a reply.
|
|
60
|
-
//
|
|
61
|
-
// The AMQP specification implies that RPCs can't be pipelined; that
|
|
62
|
-
// is, you can have only one outstanding RPC on a channel at a
|
|
63
|
-
// time. Certainly that's what RabbitMQ and its clients assume. For
|
|
64
|
-
// this reason, I buffer RPCs if the channel is already waiting for a
|
|
65
|
-
// reply.
|
|
66
|
-
|
|
67
|
-
// Just send the damn frame.
|
|
68
|
-
C.sendImmediately = function(method, fields) {
|
|
69
|
-
return this.connection.sendMethod(this.ch, method, fields);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// Invariant: !this.reply -> pending.length == 0. That is, whenever we
|
|
73
|
-
// clear a reply, we must send another RPC (and thereby fill
|
|
74
|
-
// this.reply) if there is one waiting. The invariant relevant here
|
|
75
|
-
// and in `accept`.
|
|
76
|
-
C.sendOrEnqueue = function(method, fields, reply) {
|
|
77
|
-
if (!this.reply) { // if no reply waiting, we can go
|
|
78
|
-
assert(this.pending.length === 0);
|
|
79
|
-
this.reply = reply;
|
|
80
|
-
this.sendImmediately(method, fields);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
this.pending.push({method: method,
|
|
84
|
-
fields: fields,
|
|
85
|
-
reply: reply});
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
C.sendMessage = function(fields, properties, content) {
|
|
90
|
-
return this.connection.sendMessage(
|
|
91
|
-
this.ch,
|
|
92
|
-
defs.BasicPublish, fields,
|
|
93
|
-
defs.BasicProperties, properties,
|
|
94
|
-
content);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// Internal, synchronously resolved RPC; the return value is resolved
|
|
98
|
-
// with the whole frame.
|
|
99
|
-
C._rpc = function(method, fields, expect, cb) {
|
|
100
|
-
var self = this;
|
|
101
|
-
|
|
102
|
-
function reply(err, f) {
|
|
103
|
-
if (err === null) {
|
|
104
|
-
if (f.id === expect) {
|
|
105
|
-
return cb(null, f);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
// We have detected a problem, so it's up to us to close the
|
|
109
|
-
// channel
|
|
110
|
-
var expectedName = methodName(expect);
|
|
111
|
-
|
|
112
|
-
var e = new Error(fmt("Expected %s; got %s",
|
|
113
|
-
expectedName, inspect(f, false)));
|
|
114
|
-
self.closeWithError(f.id, fmt('Expected %s; got %s',
|
|
115
|
-
expectedName, methodName(f.id)),
|
|
116
|
-
defs.constants.UNEXPECTED_FRAME, e);
|
|
117
|
-
return cb(e);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// An error will be given if, for example, this is waiting to be
|
|
121
|
-
// sent and the connection closes
|
|
122
|
-
else if (err instanceof Error) return cb(err);
|
|
123
|
-
// A close frame will be given if this is the RPC awaiting reply
|
|
124
|
-
// and the channel is closed by the server
|
|
125
|
-
else {
|
|
126
|
-
// otherwise, it's a close frame
|
|
127
|
-
var closeReason =
|
|
128
|
-
(err.fields.classId << 16) + err.fields.methodId;
|
|
129
|
-
var e = (method === closeReason)
|
|
130
|
-
? fmt("Operation failed: %s; %s",
|
|
131
|
-
methodName(method), closeMsg(err))
|
|
132
|
-
: fmt("Channel closed by server: %s", closeMsg(err));
|
|
133
|
-
var closeFrameError = new Error(e);
|
|
134
|
-
closeFrameError.code = err.fields.replyCode;
|
|
135
|
-
closeFrameError.classId = err.fields.classId;
|
|
136
|
-
closeFrameError.methodId = err.fields.methodId;
|
|
137
|
-
return cb(closeFrameError);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
this.sendOrEnqueue(method, fields, reply);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
// Shutdown protocol. There's three scenarios:
|
|
145
|
-
//
|
|
146
|
-
// 1. The application decides to shut the channel
|
|
147
|
-
// 2. The server decides to shut the channel, possibly because of
|
|
148
|
-
// something the application did
|
|
149
|
-
// 3. The connection is closing, so there won't be any more frames
|
|
150
|
-
// going back and forth.
|
|
151
|
-
//
|
|
152
|
-
// 1 and 2 involve an exchange of method frames (Close and CloseOk),
|
|
153
|
-
// while 3 doesn't; the connection simply says "shutdown" to the
|
|
154
|
-
// channel, which then acts as if it's closing, without going through
|
|
155
|
-
// the exchange.
|
|
156
|
-
|
|
157
|
-
function invalidOp(msg, stack) {
|
|
158
|
-
return function() {
|
|
159
|
-
throw new IllegalOperationError(msg, stack);
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function invalidateSend(ch, msg, stack) {
|
|
164
|
-
ch.sendImmediately = ch.sendOrEnqueue = ch.sendMessage =
|
|
165
|
-
invalidOp(msg, stack);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Move to entirely closed state.
|
|
169
|
-
C.toClosed = function(capturedStack) {
|
|
170
|
-
this._rejectPending();
|
|
171
|
-
invalidateSend(this, 'Channel closed', capturedStack);
|
|
172
|
-
this.accept = invalidOp('Channel closed', capturedStack);
|
|
173
|
-
this.connection.releaseChannel(this.ch);
|
|
174
|
-
this.emit('close');
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// Stop being able to send and receive methods and content. Used when
|
|
178
|
-
// we close the channel. Invokes the continuation once the server has
|
|
179
|
-
// acknowledged the close, but before the channel is moved to the
|
|
180
|
-
// closed state.
|
|
181
|
-
C.toClosing = function(capturedStack, k) {
|
|
182
|
-
var send = this.sendImmediately.bind(this);
|
|
183
|
-
invalidateSend(this, 'Channel closing', capturedStack);
|
|
184
|
-
|
|
185
|
-
this.accept = function(f) {
|
|
186
|
-
if (f.id === defs.ChannelCloseOk) {
|
|
187
|
-
if (k) k();
|
|
188
|
-
var s = stackCapture('ChannelCloseOk frame received');
|
|
189
|
-
this.toClosed(s);
|
|
190
|
-
}
|
|
191
|
-
else if (f.id === defs.ChannelClose) {
|
|
192
|
-
send(defs.ChannelCloseOk, {});
|
|
193
|
-
}
|
|
194
|
-
// else ignore frame
|
|
195
|
-
};
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
C._rejectPending = function() {
|
|
199
|
-
function rej(r) {
|
|
200
|
-
r(new Error("Channel ended, no reply will be forthcoming"));
|
|
201
|
-
}
|
|
202
|
-
if (this.reply !== null) rej(this.reply);
|
|
203
|
-
this.reply = null;
|
|
204
|
-
|
|
205
|
-
var discard;
|
|
206
|
-
while (discard = this.pending.shift()) rej(discard.reply);
|
|
207
|
-
this.pending = null; // so pushes will break
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
C.closeBecause = function(reason, code, k) {
|
|
211
|
-
this.sendImmediately(defs.ChannelClose, {
|
|
212
|
-
replyText: reason,
|
|
213
|
-
replyCode: code,
|
|
214
|
-
methodId:0, classId: 0
|
|
215
|
-
});
|
|
216
|
-
var s = stackCapture('closeBecause called: ' + reason);
|
|
217
|
-
this.toClosing(s, k);
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
// If we close because there's been an error, we need to distinguish
|
|
221
|
-
// between what we tell the server (`reason`) and what we report as
|
|
222
|
-
// the cause in the client (`error`).
|
|
223
|
-
C.closeWithError = function(id, reason, code, error) {
|
|
224
|
-
var self = this;
|
|
225
|
-
this.closeBecause(reason, code, function() {
|
|
226
|
-
error.code = code;
|
|
227
|
-
// content frames and consumer errors do not provide a method a class/method ID
|
|
228
|
-
if (id) {
|
|
229
|
-
error.classId = defs.info(id).classId;
|
|
230
|
-
error.methodId = defs.info(id).methodId;
|
|
231
|
-
}
|
|
232
|
-
self.emit('error', error);
|
|
233
|
-
});
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
// A trampolining state machine for message frames on a channel. A
|
|
237
|
-
// message arrives in at least two frames: first, a method announcing
|
|
238
|
-
// the message (either a BasicDeliver or BasicGetOk); then, a message
|
|
239
|
-
// header with the message properties; then, zero or more content
|
|
240
|
-
// frames.
|
|
241
|
-
|
|
242
|
-
// Keep the try/catch localised, in an attempt to avoid disabling
|
|
243
|
-
// optimisation
|
|
244
|
-
C.acceptMessageFrame = function(f) {
|
|
245
|
-
try {
|
|
246
|
-
this.handleMessage = this.handleMessage(f);
|
|
247
|
-
}
|
|
248
|
-
catch (msg) {
|
|
249
|
-
if (typeof msg === 'string') {
|
|
250
|
-
this.closeWithError(f.id, msg, defs.constants.UNEXPECTED_FRAME,
|
|
251
|
-
new Error(msg));
|
|
252
|
-
}
|
|
253
|
-
else if (msg instanceof Error) {
|
|
254
|
-
this.closeWithError(f.id, 'Error while processing message',
|
|
255
|
-
defs.constants.INTERNAL_ERROR, msg);
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
this.closeWithError(f.id, 'Internal error while processing message',
|
|
259
|
-
defs.constants.INTERNAL_ERROR,
|
|
260
|
-
new Error(msg.toString()));
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
// Kick off a message delivery given a BasicDeliver or BasicReturn
|
|
266
|
-
// frame (BasicGet uses the RPC mechanism)
|
|
267
|
-
function acceptDeliveryOrReturn(f) {
|
|
268
|
-
var event;
|
|
269
|
-
if (f.id === defs.BasicDeliver) event = 'delivery';
|
|
270
|
-
else if (f.id === defs.BasicReturn) event = 'return';
|
|
271
|
-
else throw fmt("Expected BasicDeliver or BasicReturn; got %s",
|
|
272
|
-
inspect(f));
|
|
273
|
-
|
|
274
|
-
var self = this;
|
|
275
|
-
var fields = f.fields;
|
|
276
|
-
return acceptMessage(function(message) {
|
|
277
|
-
message.fields = fields;
|
|
278
|
-
self.emit(event, message);
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Move to the state of waiting for message frames (headers, then
|
|
283
|
-
// one or more content frames)
|
|
284
|
-
function acceptMessage(continuation) {
|
|
285
|
-
var totalSize = 0, remaining = 0;
|
|
286
|
-
var buffers = null;
|
|
287
|
-
|
|
288
|
-
var message = {
|
|
289
|
-
fields: null,
|
|
290
|
-
properties: null,
|
|
291
|
-
content: null
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
return headers;
|
|
295
|
-
|
|
296
|
-
// expect a headers frame
|
|
297
|
-
function headers(f) {
|
|
298
|
-
if (f.id === defs.BasicProperties) {
|
|
299
|
-
message.properties = f.fields;
|
|
300
|
-
totalSize = remaining = f.size;
|
|
301
|
-
|
|
302
|
-
// for zero-length messages, content frames aren't required.
|
|
303
|
-
if (totalSize === 0) {
|
|
304
|
-
message.content = Buffer.alloc(0);
|
|
305
|
-
continuation(message);
|
|
306
|
-
return acceptDeliveryOrReturn;
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
return content;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
throw "Expected headers frame after delivery";
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// expect a content frame
|
|
318
|
-
// %%% TODO cancelled messages (sent as zero-length content frame)
|
|
319
|
-
function content(f) {
|
|
320
|
-
if (f.content) {
|
|
321
|
-
var size = f.content.length;
|
|
322
|
-
remaining -= size;
|
|
323
|
-
if (remaining === 0) {
|
|
324
|
-
if (buffers !== null) {
|
|
325
|
-
buffers.push(f.content);
|
|
326
|
-
message.content = Buffer.concat(buffers);
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
message.content = f.content;
|
|
330
|
-
}
|
|
331
|
-
continuation(message);
|
|
332
|
-
return acceptDeliveryOrReturn;
|
|
333
|
-
}
|
|
334
|
-
else if (remaining < 0) {
|
|
335
|
-
throw fmt("Too much content sent! Expected %d bytes",
|
|
336
|
-
totalSize);
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
if (buffers !== null)
|
|
340
|
-
buffers.push(f.content);
|
|
341
|
-
else
|
|
342
|
-
buffers = [f.content];
|
|
343
|
-
return content;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
else throw "Expected content frame after headers"
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
C.handleConfirm = function(handle, f) {
|
|
351
|
-
var tag = f.deliveryTag;
|
|
352
|
-
var multi = f.multiple;
|
|
353
|
-
|
|
354
|
-
if (multi) {
|
|
355
|
-
var confirmed = this.unconfirmed.splice(0, tag - this.lwm + 1);
|
|
356
|
-
this.lwm = tag + 1;
|
|
357
|
-
confirmed.forEach(handle);
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
var c;
|
|
361
|
-
if (tag === this.lwm) {
|
|
362
|
-
c = this.unconfirmed.shift();
|
|
363
|
-
this.lwm++;
|
|
364
|
-
// Advance the LWM and the window to the next non-gap, or
|
|
365
|
-
// possibly to the end
|
|
366
|
-
while (this.unconfirmed[0] === null) {
|
|
367
|
-
this.unconfirmed.shift();
|
|
368
|
-
this.lwm++;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
c = this.unconfirmed[tag - this.lwm];
|
|
373
|
-
this.unconfirmed[tag - this.lwm] = null;
|
|
374
|
-
}
|
|
375
|
-
// Technically, in the single-deliveryTag case, I should report a
|
|
376
|
-
// protocol breach if it's already been confirmed.
|
|
377
|
-
handle(c);
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
C.pushConfirmCallback = function(cb) {
|
|
382
|
-
// `null` is used specifically for marking already confirmed slots,
|
|
383
|
-
// so I coerce `undefined` and `null` to false; functions are never
|
|
384
|
-
// falsey.
|
|
385
|
-
this.unconfirmed.push(cb || false);
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
// Interface for connection to use
|
|
389
|
-
|
|
390
|
-
C.accept = function(f) {
|
|
391
|
-
|
|
392
|
-
switch (f.id) {
|
|
393
|
-
|
|
394
|
-
// Message frames
|
|
395
|
-
case undefined: // content frame!
|
|
396
|
-
case defs.BasicDeliver:
|
|
397
|
-
case defs.BasicReturn:
|
|
398
|
-
case defs.BasicProperties:
|
|
399
|
-
return this.acceptMessageFrame(f);
|
|
400
|
-
|
|
401
|
-
// confirmations, need to do confirm.select first
|
|
402
|
-
case defs.BasicAck:
|
|
403
|
-
return this.emit('ack', f.fields);
|
|
404
|
-
case defs.BasicNack:
|
|
405
|
-
return this.emit('nack', f.fields);
|
|
406
|
-
case defs.BasicCancel:
|
|
407
|
-
// The broker can send this if e.g., the queue is deleted.
|
|
408
|
-
return this.emit('cancel', f.fields);
|
|
409
|
-
|
|
410
|
-
case defs.ChannelClose:
|
|
411
|
-
// Any remote closure is an error to us. Reject the pending reply
|
|
412
|
-
// with the close frame, so it can see whether it was that
|
|
413
|
-
// operation that caused it to close.
|
|
414
|
-
if (this.reply) {
|
|
415
|
-
var reply = this.reply; this.reply = null;
|
|
416
|
-
reply(f);
|
|
417
|
-
}
|
|
418
|
-
var emsg = "Channel closed by server: " + closeMsg(f);
|
|
419
|
-
this.sendImmediately(defs.ChannelCloseOk, {});
|
|
420
|
-
|
|
421
|
-
var error = new Error(emsg);
|
|
422
|
-
error.code = f.fields.replyCode;
|
|
423
|
-
error.classId = f.fields.classId;
|
|
424
|
-
error.methodId = f.fields.methodId;
|
|
425
|
-
this.emit('error', error);
|
|
426
|
-
|
|
427
|
-
var s = stackCapture(emsg);
|
|
428
|
-
this.toClosed(s);
|
|
429
|
-
return;
|
|
430
|
-
|
|
431
|
-
case defs.BasicFlow:
|
|
432
|
-
// RabbitMQ doesn't send this, it just blocks the TCP socket
|
|
433
|
-
return this.closeWithError(f.id, "Flow not implemented",
|
|
434
|
-
defs.constants.NOT_IMPLEMENTED,
|
|
435
|
-
new Error('Flow not implemented'));
|
|
436
|
-
|
|
437
|
-
default: // assume all other things are replies
|
|
438
|
-
// Resolving the reply may lead to another RPC; to make sure we
|
|
439
|
-
// don't hold that up, clear this.reply
|
|
440
|
-
var reply = this.reply; this.reply = null;
|
|
441
|
-
// however, maybe there's an RPC waiting to go? If so, that'll
|
|
442
|
-
// fill this.reply again, restoring the invariant. This does rely
|
|
443
|
-
// on any response being recv'ed after resolving the promise,
|
|
444
|
-
// below; hence, I use synchronous defer.
|
|
445
|
-
if (this.pending.length > 0) {
|
|
446
|
-
var send = this.pending.shift();
|
|
447
|
-
this.reply = send.reply;
|
|
448
|
-
this.sendImmediately(send.method, send.fields);
|
|
449
|
-
}
|
|
450
|
-
return reply(null, f);
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
C.onBufferDrain = function() {
|
|
455
|
-
this.emit('drain');
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
// This adds just a bit more stuff useful for the APIs, but not
|
|
460
|
-
// low-level machinery.
|
|
461
|
-
function BaseChannel(connection) {
|
|
462
|
-
Channel.call(this, connection);
|
|
463
|
-
this.consumers = new Map();
|
|
464
|
-
}
|
|
465
|
-
inherits(BaseChannel, Channel);
|
|
466
|
-
|
|
467
|
-
module.exports.BaseChannel = BaseChannel;
|
|
468
|
-
|
|
469
|
-
// Not sure I like the ff, it's going to be changing hidden classes
|
|
470
|
-
// all over the place. On the other hand, whaddya do.
|
|
471
|
-
BaseChannel.prototype.registerConsumer = function(tag, callback) {
|
|
472
|
-
this.consumers.set(tag, callback);
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
BaseChannel.prototype.unregisterConsumer = function(tag) {
|
|
476
|
-
this.consumers.delete(tag);
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
BaseChannel.prototype.dispatchMessage = function(fields, message) {
|
|
480
|
-
var consumerTag = fields.consumerTag;
|
|
481
|
-
var consumer = this.consumers.get(consumerTag);
|
|
482
|
-
if (consumer) {
|
|
483
|
-
return consumer(message);
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
// %%% Surely a race here
|
|
487
|
-
throw new Error("Unknown consumer: " + consumerTag);
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
BaseChannel.prototype.handleDelivery = function(message) {
|
|
492
|
-
return this.dispatchMessage(message.fields, message);
|
|
493
|
-
};
|
|
494
|
-
|
|
495
|
-
BaseChannel.prototype.handleCancel = function(fields) {
|
|
496
|
-
var result = this.dispatchMessage(fields, null);
|
|
497
|
-
this.unregisterConsumer(fields.consumerTag);
|
|
498
|
-
return result;
|
|
499
|
-
};
|