typespeed 2.0.13 → 2.0.16
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 +0 -1
- package/dist/database.decorator.js +0 -1
- package/dist/default/express-server.class.js +0 -1
- package/dist/default/log-default.class.js +0 -1
- package/dist/default/node-cache.class.js +0 -1
- package/dist/default/rabbitmq.class.js +0 -1
- package/dist/default/read-write-db.class.js +0 -1
- package/dist/default/redis.class.js +0 -1
- package/dist/factory/cache-factory.class.js +0 -1
- package/dist/factory/data-source-factory.class.js +0 -1
- package/dist/factory/log-factory.class.js +0 -1
- package/dist/factory/server-factory.class.js +0 -1
- package/dist/route.decorator.js +0 -1
- package/dist/scaffold/command.js +0 -1
- package/dist/typespeed.d.ts +133 -12
- package/dist/typespeed.js +1 -1
- package/package.json +2 -2
- package/src/typespeed.d.ts +133 -0
- package/src/typespeed.ts +2 -1
- package/test/node_modules/.package-lock.json +112 -4
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +17 -0
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +30 -0
- package/test/node_modules/@acuminous/bitsyntax/LICENSE +6 -0
- package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +21 -0
- package/test/node_modules/@acuminous/bitsyntax/Makefile +15 -0
- package/test/node_modules/@acuminous/bitsyntax/README.md +308 -0
- package/test/node_modules/@acuminous/bitsyntax/index.js +10 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +303 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +142 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +67 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +232 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +32 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +1173 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +119 -0
- package/test/node_modules/@acuminous/bitsyntax/package.json +36 -0
- package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +50 -0
- package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +193 -0
- package/test/node_modules/@types/node/README.md +1 -1
- package/test/node_modules/@types/node/buffer.d.ts +5 -2
- package/test/node_modules/@types/node/child_process.d.ts +27 -0
- package/test/node_modules/@types/node/globals.d.ts +1 -0
- package/test/node_modules/@types/node/package.json +2 -2
- package/test/node_modules/@types/node/test.d.ts +43 -20
- package/test/node_modules/@types/node/ts4.8/buffer.d.ts +5 -2
- package/test/node_modules/@types/node/ts4.8/child_process.d.ts +27 -0
- package/test/node_modules/@types/node/ts4.8/globals.d.ts +1 -0
- package/test/node_modules/@types/node/ts4.8/test.d.ts +43 -19
- package/test/node_modules/@types/node/ts4.8/url.d.ts +3 -3
- package/test/node_modules/@types/node/ts4.8/util.d.ts +1 -1
- package/test/node_modules/@types/node/url.d.ts +3 -3
- package/test/node_modules/@types/node/util.d.ts +1 -1
- package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/test/node_modules/amqplib/.github/workflows/test.yml +38 -0
- package/test/node_modules/amqplib/CHANGELOG.md +430 -0
- package/test/node_modules/amqplib/LICENSE +6 -0
- package/test/node_modules/amqplib/LICENSE-MIT +21 -0
- package/test/node_modules/amqplib/Makefile +47 -0
- package/test/node_modules/amqplib/README.md +157 -0
- package/test/node_modules/amqplib/bin/generate-defs.js +722 -0
- package/test/node_modules/amqplib/callback_api.js +22 -0
- package/test/node_modules/amqplib/channel_api.js +16 -0
- package/test/node_modules/amqplib/examples/headers.js +42 -0
- package/test/node_modules/amqplib/examples/receive_generator.js +39 -0
- package/test/node_modules/amqplib/examples/send_generators.js +42 -0
- package/test/node_modules/amqplib/examples/ssl.js +64 -0
- package/test/node_modules/amqplib/examples/tutorials/README.md +93 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +28 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +30 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +27 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +27 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +30 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +36 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +56 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +55 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +49 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +45 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +29 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +35 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log.js +19 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +20 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +19 -0
- package/test/node_modules/amqplib/examples/tutorials/new_task.js +18 -0
- package/test/node_modules/amqplib/examples/tutorials/package.json +16 -0
- package/test/node_modules/amqplib/examples/tutorials/receive.js +21 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +28 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +44 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +43 -0
- package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +52 -0
- package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +39 -0
- package/test/node_modules/amqplib/examples/tutorials/send.js +23 -0
- package/test/node_modules/amqplib/examples/tutorials/worker.js +28 -0
- package/test/node_modules/amqplib/examples/waitForConfirms.js +22 -0
- package/test/node_modules/amqplib/lib/api_args.js +314 -0
- package/test/node_modules/amqplib/lib/bitset.js +130 -0
- package/test/node_modules/amqplib/lib/callback_model.js +327 -0
- package/test/node_modules/amqplib/lib/channel.js +499 -0
- package/test/node_modules/amqplib/lib/channel_model.js +302 -0
- package/test/node_modules/amqplib/lib/codec.js +321 -0
- package/test/node_modules/amqplib/lib/connect.js +189 -0
- package/test/node_modules/amqplib/lib/connection.js +663 -0
- package/test/node_modules/amqplib/lib/credentials.js +42 -0
- package/test/node_modules/amqplib/lib/defs.js +4966 -0
- package/test/node_modules/amqplib/lib/error.js +24 -0
- package/test/node_modules/amqplib/lib/format.js +40 -0
- package/test/node_modules/amqplib/lib/frame.js +113 -0
- package/test/node_modules/amqplib/lib/heartbeat.js +89 -0
- package/test/node_modules/amqplib/lib/mux.js +129 -0
- package/test/node_modules/amqplib/package.json +37 -0
- package/test/node_modules/amqplib/test/bitset.js +69 -0
- package/test/node_modules/amqplib/test/callback_api.js +312 -0
- package/test/node_modules/amqplib/test/channel.js +621 -0
- package/test/node_modules/amqplib/test/channel_api.js +596 -0
- package/test/node_modules/amqplib/test/codec.js +237 -0
- package/test/node_modules/amqplib/test/connect.js +197 -0
- package/test/node_modules/amqplib/test/connection.js +390 -0
- package/test/node_modules/amqplib/test/data.js +254 -0
- package/test/node_modules/amqplib/test/frame.js +198 -0
- package/test/node_modules/amqplib/test/mux.js +204 -0
- package/test/node_modules/amqplib/test/util.js +219 -0
- package/test/node_modules/buffer-more-ints/.travis.yml +6 -0
- package/test/node_modules/buffer-more-ints/LICENSE +19 -0
- package/test/node_modules/buffer-more-ints/README.md +69 -0
- package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +183 -0
- package/test/node_modules/buffer-more-ints/buffer-more-ints.js +432 -0
- package/test/node_modules/buffer-more-ints/package.json +19 -0
- package/test/node_modules/buffer-more-ints/polyfill.js +71 -0
- package/test/node_modules/core-util-is/LICENSE +19 -0
- package/test/node_modules/core-util-is/README.md +3 -0
- package/test/node_modules/core-util-is/lib/util.js +107 -0
- package/test/node_modules/core-util-is/package.json +38 -0
- package/test/node_modules/debug/LICENSE +20 -0
- package/test/node_modules/debug/README.md +481 -0
- package/test/node_modules/debug/package.json +59 -0
- package/test/node_modules/debug/src/browser.js +269 -0
- package/test/node_modules/debug/src/common.js +274 -0
- package/test/node_modules/debug/src/index.js +10 -0
- package/test/node_modules/debug/src/node.js +263 -0
- package/test/node_modules/inherits/LICENSE +16 -0
- package/test/node_modules/inherits/README.md +42 -0
- package/test/node_modules/inherits/inherits.js +9 -0
- package/test/node_modules/inherits/inherits_browser.js +27 -0
- package/test/node_modules/inherits/package.json +29 -0
- package/test/node_modules/isarray/README.md +54 -0
- package/test/node_modules/isarray/build/build.js +209 -0
- package/test/node_modules/isarray/component.json +19 -0
- package/test/node_modules/isarray/index.js +3 -0
- package/test/node_modules/isarray/package.json +25 -0
- package/test/node_modules/ms/index.js +162 -0
- package/test/node_modules/ms/license.md +21 -0
- package/test/node_modules/ms/package.json +37 -0
- package/test/node_modules/ms/readme.md +60 -0
- package/test/node_modules/querystringify/LICENSE +22 -0
- package/test/node_modules/querystringify/README.md +61 -0
- package/test/node_modules/querystringify/index.js +118 -0
- package/test/node_modules/querystringify/package.json +38 -0
- package/test/node_modules/readable-stream/LICENSE +18 -0
- package/test/node_modules/readable-stream/README.md +15 -0
- package/test/node_modules/readable-stream/duplex.js +1 -0
- package/test/node_modules/readable-stream/float.patch +923 -0
- package/test/node_modules/readable-stream/lib/_stream_duplex.js +89 -0
- package/test/node_modules/readable-stream/lib/_stream_passthrough.js +46 -0
- package/test/node_modules/readable-stream/lib/_stream_readable.js +951 -0
- package/test/node_modules/readable-stream/lib/_stream_transform.js +209 -0
- package/test/node_modules/readable-stream/lib/_stream_writable.js +477 -0
- package/test/node_modules/readable-stream/package.json +32 -0
- package/test/node_modules/readable-stream/passthrough.js +1 -0
- package/test/node_modules/readable-stream/readable.js +10 -0
- package/test/node_modules/readable-stream/transform.js +1 -0
- package/test/node_modules/readable-stream/writable.js +1 -0
- package/test/node_modules/requires-port/.travis.yml +19 -0
- package/test/node_modules/requires-port/LICENSE +22 -0
- package/test/node_modules/requires-port/README.md +47 -0
- package/test/node_modules/requires-port/index.js +38 -0
- package/test/node_modules/requires-port/package.json +47 -0
- package/test/node_modules/requires-port/test.js +98 -0
- package/test/node_modules/safe-buffer/LICENSE +21 -0
- package/test/node_modules/safe-buffer/README.md +584 -0
- package/test/node_modules/safe-buffer/index.d.ts +187 -0
- package/test/node_modules/safe-buffer/index.js +62 -0
- package/test/node_modules/safe-buffer/package.json +37 -0
- package/test/node_modules/string_decoder/LICENSE +20 -0
- package/test/node_modules/string_decoder/README.md +7 -0
- package/test/node_modules/string_decoder/index.js +221 -0
- package/test/node_modules/string_decoder/package.json +25 -0
- package/test/node_modules/url-parse/LICENSE +22 -0
- package/test/node_modules/url-parse/README.md +153 -0
- package/test/node_modules/url-parse/dist/url-parse.js +755 -0
- package/test/node_modules/url-parse/dist/url-parse.min.js +1 -0
- package/test/node_modules/url-parse/dist/url-parse.min.js.map +1 -0
- package/test/node_modules/url-parse/index.js +589 -0
- package/test/node_modules/url-parse/package.json +49 -0
- package/test/src/test-mq.class.ts +1 -2
- package/tsconfig.json +4 -3
- package/dist/core.decorator.d.ts +0 -18
- package/dist/core.decorator.js.map +0 -1
- package/dist/database.decorator.d.ts +0 -24
- package/dist/database.decorator.js.map +0 -1
- package/dist/default/express-server.class.d.ts +0 -15
- package/dist/default/express-server.class.js.map +0 -1
- package/dist/default/log-default.class.d.ts +0 -6
- package/dist/default/log-default.class.js.map +0 -1
- package/dist/default/node-cache.class.d.ts +0 -13
- package/dist/default/node-cache.class.js.map +0 -1
- package/dist/default/rabbitmq.class.d.ts +0 -9
- package/dist/default/rabbitmq.class.js.map +0 -1
- package/dist/default/read-write-db.class.d.ts +0 -10
- package/dist/default/read-write-db.class.js.map +0 -1
- package/dist/default/redis.class.d.ts +0 -5
- package/dist/default/redis.class.js.map +0 -1
- package/dist/factory/cache-factory.class.d.ts +0 -7
- package/dist/factory/cache-factory.class.js.map +0 -1
- package/dist/factory/data-source-factory.class.d.ts +0 -4
- package/dist/factory/data-source-factory.class.js.map +0 -1
- package/dist/factory/log-factory.class.d.ts +0 -4
- package/dist/factory/log-factory.class.js.map +0 -1
- package/dist/factory/server-factory.class.d.ts +0 -6
- package/dist/factory/server-factory.class.js.map +0 -1
- package/dist/route.decorator.d.ts +0 -8
- package/dist/route.decorator.js.map +0 -1
- package/dist/scaffold/command.d.ts +0 -2
- package/dist/scaffold/command.js.map +0 -1
- package/dist/typespeed.js.map +0 -1
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
//
|
|
2
|
+
//
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
var defs = require('./defs');
|
|
8
|
+
var inherits = require('util').inherits;
|
|
9
|
+
var EventEmitter = require('events').EventEmitter;
|
|
10
|
+
var BaseChannel = require('./channel').BaseChannel;
|
|
11
|
+
var acceptMessage = require('./channel').acceptMessage;
|
|
12
|
+
var Args = require('./api_args');
|
|
13
|
+
|
|
14
|
+
function CallbackModel(connection) {
|
|
15
|
+
if (!(this instanceof CallbackModel))
|
|
16
|
+
return new CallbackModel(connection);
|
|
17
|
+
EventEmitter.call( this );
|
|
18
|
+
this.connection = connection;
|
|
19
|
+
var self = this;
|
|
20
|
+
['error', 'close', 'blocked', 'unblocked'].forEach(function(ev) {
|
|
21
|
+
connection.on(ev, self.emit.bind(self, ev));
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
inherits(CallbackModel, EventEmitter);
|
|
25
|
+
|
|
26
|
+
module.exports.CallbackModel = CallbackModel;
|
|
27
|
+
|
|
28
|
+
CallbackModel.prototype.close = function(cb) {
|
|
29
|
+
this.connection.close(cb);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function Channel(connection) {
|
|
33
|
+
BaseChannel.call(this, connection);
|
|
34
|
+
this.on('delivery', this.handleDelivery.bind(this));
|
|
35
|
+
this.on('cancel', this.handleCancel.bind(this));
|
|
36
|
+
}
|
|
37
|
+
inherits(Channel, BaseChannel);
|
|
38
|
+
|
|
39
|
+
module.exports.Channel = Channel;
|
|
40
|
+
|
|
41
|
+
CallbackModel.prototype.createChannel = function(cb) {
|
|
42
|
+
var ch = new Channel(this.connection);
|
|
43
|
+
ch.open(function(err, ok) {
|
|
44
|
+
if (err === null) cb && cb(null, ch);
|
|
45
|
+
else cb && cb(err);
|
|
46
|
+
});
|
|
47
|
+
return ch;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Wrap an RPC callback to make sure the callback is invoked with
|
|
51
|
+
// either `(null, value)` or `(error)`, i.e., never two non-null
|
|
52
|
+
// values. Also substitutes a stub if the callback is `undefined` or
|
|
53
|
+
// otherwise falsey, for convenience in methods for which the callback
|
|
54
|
+
// is optional (that is, most of them).
|
|
55
|
+
function callbackWrapper(ch, cb) {
|
|
56
|
+
return (cb) ? function(err, ok) {
|
|
57
|
+
if (err === null) {
|
|
58
|
+
cb(null, ok);
|
|
59
|
+
}
|
|
60
|
+
else cb(err);
|
|
61
|
+
} : function() {};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// This encodes straight-forward RPC: no side-effects and return the
|
|
65
|
+
// fields from the server response. It wraps the callback given it, so
|
|
66
|
+
// the calling method argument can be passed as-is. For anything that
|
|
67
|
+
// needs to have side-effects, or needs to change the server response,
|
|
68
|
+
// use `#_rpc(...)` and remember to dereference `.fields` of the
|
|
69
|
+
// server response.
|
|
70
|
+
Channel.prototype.rpc = function(method, fields, expect, cb0) {
|
|
71
|
+
var cb = callbackWrapper(this, cb0);
|
|
72
|
+
this._rpc(method, fields, expect, function(err, ok) {
|
|
73
|
+
cb(err, ok && ok.fields); // in case of an error, ok will be
|
|
74
|
+
// undefined
|
|
75
|
+
});
|
|
76
|
+
return this;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// === Public API ===
|
|
80
|
+
|
|
81
|
+
Channel.prototype.open = function(cb) {
|
|
82
|
+
try { this.allocate(); }
|
|
83
|
+
catch (e) { return cb(e); }
|
|
84
|
+
|
|
85
|
+
return this.rpc(defs.ChannelOpen, {outOfBand: ""},
|
|
86
|
+
defs.ChannelOpenOk, cb);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
Channel.prototype.close = function(cb) {
|
|
90
|
+
return this.closeBecause("Goodbye", defs.constants.REPLY_SUCCESS,
|
|
91
|
+
function() { cb && cb(null); });
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
Channel.prototype.assertQueue = function(queue, options, cb) {
|
|
95
|
+
return this.rpc(defs.QueueDeclare,
|
|
96
|
+
Args.assertQueue(queue, options),
|
|
97
|
+
defs.QueueDeclareOk, cb);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Channel.prototype.checkQueue = function(queue, cb) {
|
|
101
|
+
return this.rpc(defs.QueueDeclare,
|
|
102
|
+
Args.checkQueue(queue),
|
|
103
|
+
defs.QueueDeclareOk, cb);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
Channel.prototype.deleteQueue = function(queue, options, cb) {
|
|
107
|
+
return this.rpc(defs.QueueDelete,
|
|
108
|
+
Args.deleteQueue(queue, options),
|
|
109
|
+
defs.QueueDeleteOk, cb);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
Channel.prototype.purgeQueue = function(queue, cb) {
|
|
113
|
+
return this.rpc(defs.QueuePurge,
|
|
114
|
+
Args.purgeQueue(queue),
|
|
115
|
+
defs.QueuePurgeOk, cb);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
Channel.prototype.bindQueue =
|
|
119
|
+
function(queue, source, pattern, argt, cb) {
|
|
120
|
+
return this.rpc(defs.QueueBind,
|
|
121
|
+
Args.bindQueue(queue, source, pattern, argt),
|
|
122
|
+
defs.QueueBindOk, cb);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
Channel.prototype.unbindQueue =
|
|
126
|
+
function(queue, source, pattern, argt, cb) {
|
|
127
|
+
return this.rpc(defs.QueueUnbind,
|
|
128
|
+
Args.unbindQueue(queue, source, pattern, argt),
|
|
129
|
+
defs.QueueUnbindOk, cb);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
Channel.prototype.assertExchange = function(ex, type, options, cb0) {
|
|
133
|
+
var cb = callbackWrapper(this, cb0);
|
|
134
|
+
this._rpc(defs.ExchangeDeclare,
|
|
135
|
+
Args.assertExchange(ex, type, options),
|
|
136
|
+
defs.ExchangeDeclareOk,
|
|
137
|
+
function(e, _) { cb(e, {exchange: ex}); });
|
|
138
|
+
return this;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
Channel.prototype.checkExchange = function(exchange, cb) {
|
|
142
|
+
return this.rpc(defs.ExchangeDeclare,
|
|
143
|
+
Args.checkExchange(exchange),
|
|
144
|
+
defs.ExchangeDeclareOk, cb);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
Channel.prototype.deleteExchange = function(exchange, options, cb) {
|
|
148
|
+
return this.rpc(defs.ExchangeDelete,
|
|
149
|
+
Args.deleteExchange(exchange, options),
|
|
150
|
+
defs.ExchangeDeleteOk, cb);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
Channel.prototype.bindExchange =
|
|
154
|
+
function(dest, source, pattern, argt, cb) {
|
|
155
|
+
return this.rpc(defs.ExchangeBind,
|
|
156
|
+
Args.bindExchange(dest, source, pattern, argt),
|
|
157
|
+
defs.ExchangeBindOk, cb);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
Channel.prototype.unbindExchange =
|
|
161
|
+
function(dest, source, pattern, argt, cb) {
|
|
162
|
+
return this.rpc(defs.ExchangeUnbind,
|
|
163
|
+
Args.unbindExchange(dest, source, pattern, argt),
|
|
164
|
+
defs.ExchangeUnbindOk, cb);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
Channel.prototype.publish =
|
|
168
|
+
function(exchange, routingKey, content, options) {
|
|
169
|
+
var fieldsAndProps = Args.publish(exchange, routingKey, options);
|
|
170
|
+
return this.sendMessage(fieldsAndProps, fieldsAndProps, content);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
Channel.prototype.sendToQueue = function(queue, content, options) {
|
|
174
|
+
return this.publish('', queue, content, options);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
Channel.prototype.consume = function(queue, callback, options, cb0) {
|
|
178
|
+
var cb = callbackWrapper(this, cb0);
|
|
179
|
+
var fields = Args.consume(queue, options);
|
|
180
|
+
var self = this;
|
|
181
|
+
this._rpc(
|
|
182
|
+
defs.BasicConsume, fields, defs.BasicConsumeOk,
|
|
183
|
+
function(err, ok) {
|
|
184
|
+
if (err === null) {
|
|
185
|
+
self.registerConsumer(ok.fields.consumerTag, callback);
|
|
186
|
+
cb(null, ok.fields);
|
|
187
|
+
}
|
|
188
|
+
else cb(err);
|
|
189
|
+
});
|
|
190
|
+
return this;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
Channel.prototype.cancel = function(consumerTag, cb0) {
|
|
194
|
+
var cb = callbackWrapper(this, cb0);
|
|
195
|
+
var self = this;
|
|
196
|
+
this._rpc(
|
|
197
|
+
defs.BasicCancel, Args.cancel(consumerTag), defs.BasicCancelOk,
|
|
198
|
+
function(err, ok) {
|
|
199
|
+
if (err === null) {
|
|
200
|
+
self.unregisterConsumer(consumerTag);
|
|
201
|
+
cb(null, ok.fields);
|
|
202
|
+
}
|
|
203
|
+
else cb(err);
|
|
204
|
+
});
|
|
205
|
+
return this;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
Channel.prototype.get = function(queue, options, cb0) {
|
|
209
|
+
var self = this;
|
|
210
|
+
var fields = Args.get(queue, options);
|
|
211
|
+
var cb = callbackWrapper(this, cb0);
|
|
212
|
+
this.sendOrEnqueue(defs.BasicGet, fields, function(err, f) {
|
|
213
|
+
if (err === null) {
|
|
214
|
+
if (f.id === defs.BasicGetEmpty) {
|
|
215
|
+
cb(null, false);
|
|
216
|
+
}
|
|
217
|
+
else if (f.id === defs.BasicGetOk) {
|
|
218
|
+
self.handleMessage = acceptMessage(function(m) {
|
|
219
|
+
m.fields = f.fields;
|
|
220
|
+
cb(null, m);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
cb(new Error("Unexpected response to BasicGet: " +
|
|
225
|
+
inspect(f)));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return this;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
Channel.prototype.ack = function(message, allUpTo) {
|
|
233
|
+
this.sendImmediately(
|
|
234
|
+
defs.BasicAck, Args.ack(message.fields.deliveryTag, allUpTo));
|
|
235
|
+
return this;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
Channel.prototype.ackAll = function() {
|
|
239
|
+
this.sendImmediately(defs.BasicAck, Args.ack(0, true));
|
|
240
|
+
return this;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
Channel.prototype.nack = function(message, allUpTo, requeue) {
|
|
244
|
+
this.sendImmediately(
|
|
245
|
+
defs.BasicNack,
|
|
246
|
+
Args.nack(message.fields.deliveryTag, allUpTo, requeue));
|
|
247
|
+
return this;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
Channel.prototype.nackAll = function(requeue) {
|
|
251
|
+
this.sendImmediately(
|
|
252
|
+
defs.BasicNack, Args.nack(0, true, requeue))
|
|
253
|
+
return this;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
Channel.prototype.reject = function(message, requeue) {
|
|
257
|
+
this.sendImmediately(
|
|
258
|
+
defs.BasicReject,
|
|
259
|
+
Args.reject(message.fields.deliveryTag, requeue));
|
|
260
|
+
return this;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
Channel.prototype.prefetch = function(count, global, cb) {
|
|
264
|
+
return this.rpc(defs.BasicQos,
|
|
265
|
+
Args.prefetch(count, global),
|
|
266
|
+
defs.BasicQosOk, cb);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
Channel.prototype.recover = function(cb) {
|
|
270
|
+
return this.rpc(defs.BasicRecover,
|
|
271
|
+
Args.recover(),
|
|
272
|
+
defs.BasicRecoverOk, cb);
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
function ConfirmChannel(connection) {
|
|
276
|
+
Channel.call(this, connection);
|
|
277
|
+
}
|
|
278
|
+
inherits(ConfirmChannel, Channel);
|
|
279
|
+
|
|
280
|
+
module.exports.ConfirmChannel = ConfirmChannel;
|
|
281
|
+
|
|
282
|
+
CallbackModel.prototype.createConfirmChannel = function(cb) {
|
|
283
|
+
var ch = new ConfirmChannel(this.connection);
|
|
284
|
+
ch.open(function(err) {
|
|
285
|
+
if (err !== null) return cb && cb(err);
|
|
286
|
+
else {
|
|
287
|
+
ch.rpc(defs.ConfirmSelect, {nowait: false},
|
|
288
|
+
defs.ConfirmSelectOk, function(err, _ok) {
|
|
289
|
+
if (err !== null) return cb && cb(err);
|
|
290
|
+
else cb && cb(null, ch);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
return ch;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
ConfirmChannel.prototype.publish = function(exchange, routingKey,
|
|
298
|
+
content, options, cb) {
|
|
299
|
+
this.pushConfirmCallback(cb);
|
|
300
|
+
return Channel.prototype.publish.call(
|
|
301
|
+
this, exchange, routingKey, content, options);
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
ConfirmChannel.prototype.sendToQueue = function(queue, content,
|
|
305
|
+
options, cb) {
|
|
306
|
+
return this.publish('', queue, content, options, cb);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
ConfirmChannel.prototype.waitForConfirms = function(k) {
|
|
310
|
+
var awaiting = [];
|
|
311
|
+
var unconfirmed = this.unconfirmed;
|
|
312
|
+
unconfirmed.forEach(function(val, index) {
|
|
313
|
+
if (val === null); // already confirmed
|
|
314
|
+
else {
|
|
315
|
+
var confirmed = new Promise(function(resolve, reject) {
|
|
316
|
+
unconfirmed[index] = function(err) {
|
|
317
|
+
if (val) val(err);
|
|
318
|
+
if (err === null) resolve();
|
|
319
|
+
else reject(err);
|
|
320
|
+
};
|
|
321
|
+
});
|
|
322
|
+
awaiting.push(confirmed);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
return Promise.all(awaiting).then(function() { k(); },
|
|
326
|
+
function(err) { k(err); });
|
|
327
|
+
};
|