├── README.md ├── consumer-producer-pattern ├── receive.js └── send.js ├── node_modules ├── .yarn-integrity ├── amqplib │ ├── CHANGELOG.md │ ├── LICENSE │ ├── LICENSE-MIT │ ├── Makefile │ ├── README.md │ ├── callback_api.js │ ├── channel_api.js │ ├── examples │ │ ├── headers.js │ │ ├── receive_generator.js │ │ ├── send_generators.js │ │ ├── ssl.js │ │ ├── tutorials │ │ │ ├── README.md │ │ │ ├── callback_api │ │ │ │ ├── emit_log.js │ │ │ │ ├── emit_log_direct.js │ │ │ │ ├── emit_log_topic.js │ │ │ │ ├── new_task.js │ │ │ │ ├── receive.js │ │ │ │ ├── receive_logs.js │ │ │ │ ├── receive_logs_direct.js │ │ │ │ ├── receive_logs_topic.js │ │ │ │ ├── rpc_client.js │ │ │ │ ├── rpc_server.js │ │ │ │ ├── send.js │ │ │ │ └── worker.js │ │ │ ├── emit_log.js │ │ │ ├── emit_log_direct.js │ │ │ ├── emit_log_topic.js │ │ │ ├── new_task.js │ │ │ ├── package.json │ │ │ ├── receive.js │ │ │ ├── receive_logs.js │ │ │ ├── receive_logs_direct.js │ │ │ ├── receive_logs_topic.js │ │ │ ├── rpc_client.js │ │ │ ├── rpc_server.js │ │ │ ├── send.js │ │ │ └── worker.js │ │ └── waitForConfirms.js │ ├── lib │ │ ├── api_args.js │ │ ├── bitset.js │ │ ├── callback_model.js │ │ ├── channel.js │ │ ├── channel_model.js │ │ ├── codec.js │ │ ├── connect.js │ │ ├── connection.js │ │ ├── credentials.js │ │ ├── defs.js │ │ ├── error.js │ │ ├── format.js │ │ ├── frame.js │ │ ├── heartbeat.js │ │ └── mux.js │ ├── package.json │ └── test │ │ ├── bitset.js │ │ ├── callback_api.js │ │ ├── channel.js │ │ ├── channel_api.js │ │ ├── codec.js │ │ ├── connect.js │ │ ├── connection.js │ │ ├── data.js │ │ ├── frame.js │ │ ├── mux.js │ │ └── util.js ├── bitsyntax │ ├── .npmignore │ ├── .travis.yml │ ├── Makefile │ ├── README.md │ ├── index.js │ ├── lib │ │ ├── compile.js │ │ ├── constructor.js │ │ ├── grammar.pegjs │ │ ├── interp.js │ │ ├── parse.js │ │ ├── parser.js │ │ └── pattern.js │ ├── package.json │ └── test │ │ ├── consing.js │ │ └── matching.js ├── bluebird │ ├── LICENSE │ ├── README.md │ ├── changelog.md │ ├── js │ │ ├── browser │ │ │ ├── bluebird.core.js │ │ │ ├── bluebird.core.min.js │ │ │ ├── bluebird.js │ │ │ └── bluebird.min.js │ │ └── release │ │ │ ├── any.js │ │ │ ├── assert.js │ │ │ ├── async.js │ │ │ ├── bind.js │ │ │ ├── bluebird.js │ │ │ ├── call_get.js │ │ │ ├── cancel.js │ │ │ ├── catch_filter.js │ │ │ ├── context.js │ │ │ ├── debuggability.js │ │ │ ├── direct_resolve.js │ │ │ ├── each.js │ │ │ ├── errors.js │ │ │ ├── es5.js │ │ │ ├── filter.js │ │ │ ├── finally.js │ │ │ ├── generators.js │ │ │ ├── join.js │ │ │ ├── map.js │ │ │ ├── method.js │ │ │ ├── nodeback.js │ │ │ ├── nodeify.js │ │ │ ├── promise.js │ │ │ ├── promise_array.js │ │ │ ├── promisify.js │ │ │ ├── props.js │ │ │ ├── queue.js │ │ │ ├── race.js │ │ │ ├── reduce.js │ │ │ ├── schedule.js │ │ │ ├── settle.js │ │ │ ├── some.js │ │ │ ├── synchronous_inspection.js │ │ │ ├── thenables.js │ │ │ ├── timers.js │ │ │ ├── using.js │ │ │ └── util.js │ └── package.json ├── buffer-more-ints │ ├── .npmignore │ ├── LICENSE │ ├── README.md │ ├── buffer-more-ints-tests.js │ ├── buffer-more-ints.js │ ├── package.json │ └── polyfill.js ├── core-util-is │ ├── LICENSE │ ├── README.md │ ├── float.patch │ ├── lib │ │ └── util.js │ ├── package.json │ └── test.js ├── inherits │ ├── LICENSE │ ├── README.md │ ├── inherits.js │ ├── inherits_browser.js │ └── package.json ├── isarray │ ├── README.md │ ├── build │ │ └── build.js │ ├── component.json │ ├── index.js │ └── package.json ├── readable-stream │ ├── .npmignore │ ├── LICENSE │ ├── README.md │ ├── duplex.js │ ├── float.patch │ ├── lib │ │ ├── _stream_duplex.js │ │ ├── _stream_passthrough.js │ │ ├── _stream_readable.js │ │ ├── _stream_transform.js │ │ └── _stream_writable.js │ ├── package.json │ ├── passthrough.js │ ├── readable.js │ ├── transform.js │ └── writable.js ├── safe-buffer │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── index.js │ ├── package.json │ └── test.js └── string_decoder │ ├── .npmignore │ ├── LICENSE │ ├── README.md │ ├── index.js │ └── package.json ├── package.json ├── publish-subscribe-pattern-01-fanout ├── emit_log.js └── receive_logs.js ├── publish-subscribe-pattern-02-direct ├── emit_log_direct.js └── receive_logs_direct.js ├── work-queue-pattern ├── new_task.js └── worker.js └── yarn.lock /consumer-producer-pattern/receive.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const amqp = require('amqplib/callback_api') 3 | 4 | // Create connection 5 | amqp.connect('amqp://localhost', (err, conn) => { 6 | // Create channel 7 | conn.createChannel((err, ch) => { 8 | // Name of the queue 9 | const q = 'hello' 10 | // Declare the queue 11 | ch.assertQueue(q, { durable: false }) 12 | 13 | // Wait for Queue Messages 14 | console.log(` [*] Waiting for messages in ${q}. To exit press CTRL+C`) 15 | ch.consume( q, msg => { 16 | console.log(` [x] Received ${msg.content.toString()}`) 17 | }, { noAck: true } 18 | ) 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /consumer-producer-pattern/send.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const amqp = require('amqplib/callback_api') 3 | 4 | // Create connection 5 | amqp.connect('amqp://localhost', (err, conn) => { 6 | // Create channel 7 | conn.createChannel((err, ch) => { 8 | // Name of the queue 9 | const q = 'hello' 10 | // Declare the queue 11 | ch.assertQueue(q, { durable: false }) 12 | 13 | // Send message to the queue 14 | ch.sendToQueue(q, new Buffer('Hello World!')) 15 | console.log(" {x} Sent 'Hello World'") 16 | 17 | // Close the connection and exit 18 | setTimeout(() => { 19 | conn.close() 20 | process.exit(0) 21 | }, 500) 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /node_modules/.yarn-integrity: -------------------------------------------------------------------------------- 1 | { 2 | "nodeVersion": "v9.4.0", 3 | "modulesFolders": [ 4 | "node_modules" 5 | ], 6 | "flags": [], 7 | "linkedModules": [ 8 | "skafold" 9 | ], 10 | "topLevelPatterns": [ 11 | "amqplib@^0.5.2" 12 | ], 13 | "lockfileEntries": { 14 | "amqplib@^0.5.2": "https://registry.yarnpkg.com/amqplib/-/amqplib-0.5.2.tgz#d2d7313c7ffaa4d10bcf1e6252de4591b6cc7b63", 15 | "bitsyntax@~0.0.4": "https://registry.yarnpkg.com/bitsyntax/-/bitsyntax-0.0.4.tgz#eb10cc6f82b8c490e3e85698f07e83d46e0cba82", 16 | "bluebird@^3.4.6": "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9", 17 | "buffer-more-ints@0.0.2": "https://registry.yarnpkg.com/buffer-more-ints/-/buffer-more-ints-0.0.2.tgz#26b3885d10fa13db7fc01aae3aab870199e0124c", 18 | "core-util-is@~1.0.0": "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7", 19 | "inherits@~2.0.1": "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de", 20 | "isarray@0.0.1": "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf", 21 | "readable-stream@1.x >=1.1.9": "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9", 22 | "safe-buffer@^5.0.1": "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853", 23 | "string_decoder@~0.10.x": "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" 24 | }, 25 | "files": [], 26 | "artifacts": {} 27 | } -------------------------------------------------------------------------------- /node_modules/amqplib/LICENSE: -------------------------------------------------------------------------------- 1 | amqplib copyright (c) 2013, 2014 2 | Michael Bridgen 3 | 4 | This package, "amqplib", is licensed under the MIT License. A copy may 5 | be found in the file LICENSE-MIT in this directory, or downloaded from 6 | http://opensource.org/licenses/MIT. 7 | -------------------------------------------------------------------------------- /node_modules/amqplib/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013, 2014 Michael Bridgen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /node_modules/amqplib/Makefile: -------------------------------------------------------------------------------- 1 | RABBITMQ_SRC_VERSION=rabbitmq_v3_2_1 2 | JSON=amqp-rabbitmq-0.9.1.json 3 | RABBITMQ_CODEGEN=https://raw.githubusercontent.com/rabbitmq/rabbitmq-codegen 4 | AMQP_JSON=$(RABBITMQ_CODEGEN)/$(RABBITMQ_SRC_VERSION)/$(JSON) 5 | NODEJS_VERSIONS='0.8' '0.9' '0.10' '0.11' '0.12' '1.6' '2.5' '3.3' '4.2' '5.5' '6.2' '8.9' '9.1' 6 | 7 | MOCHA=./node_modules/.bin/mocha 8 | _MOCHA=./node_modules/.bin/_mocha 9 | UGLIFY=./node_modules/.bin/uglifyjs 10 | ISTANBUL=./node_modules/.bin/istanbul 11 | 12 | .PHONY: test test-all-nodejs all clean coverage 13 | 14 | all: lib/defs.js 15 | 16 | clean: 17 | rm lib/defs.js bin/amqp-rabbitmq-0.9.1.json 18 | rm -rf ./coverage 19 | 20 | lib/defs.js: $(UGLIFY) bin/generate-defs.js bin/amqp-rabbitmq-0.9.1.json 21 | (cd bin; node ./generate-defs.js > ../lib/defs.js) 22 | $(UGLIFY) ./lib/defs.js -o ./lib/defs.js \ 23 | -c 'sequences=false' --comments \ 24 | -b 'indent-level=2' 2>&1 | (grep -v 'WARN' || true) 25 | 26 | test: lib/defs.js 27 | $(MOCHA) --check-leaks -u tdd test/ 28 | 29 | test-all-nodejs: lib/defs.js 30 | for v in $(NODEJS_VERSIONS); \ 31 | do nave use $$v $(MOCHA) -u tdd -R progress test; \ 32 | done 33 | 34 | coverage: $(ISTANBUL) lib/defs.js 35 | $(ISTANBUL) cover $(_MOCHA) -- -u tdd -R progress test/ 36 | $(ISTANBUL) report 37 | @echo "HTML report at file://$$(pwd)/coverage/lcov-report/index.html" 38 | 39 | bin/amqp-rabbitmq-0.9.1.json: 40 | curl -L $(AMQP_JSON) > $@ 41 | 42 | $(ISTANBUL): 43 | npm install 44 | 45 | $(UGLIFY): 46 | npm install 47 | -------------------------------------------------------------------------------- /node_modules/amqplib/README.md: -------------------------------------------------------------------------------- 1 | # AMQP 0-9-1 library and client for Node.JS 2 | 3 | [![Build Status](https://travis-ci.org/squaremo/amqp.node.png)](https://travis-ci.org/squaremo/amqp.node) 4 | 5 | npm install amqplib 6 | 7 | * [Change log][changelog] 8 | * [GitHub pages][gh-pages] 9 | * [API reference][gh-pages-apiref] 10 | * [Examples from RabbitMQ tutorials][tutes] 11 | 12 | A library for making AMQP 0-9-1 clients for Node.JS, and an AMQP 0-9-1 13 | client for Node.JS v0.8-0.12, v4-v9, and the intervening io.js 14 | releases. 15 | 16 | This library does not implement [AMQP 17 | 1.0](https://github.com/squaremo/amqp.node/issues/63) or [AMQP 18 | 0-10](https://github.com/squaremo/amqp.node/issues/94). 19 | 20 | Project status: 21 | 22 | - Expected to work 23 | - Complete high-level and low-level APIs (i.e., all bits of the protocol) 24 | - Stable APIs 25 | - A fair few tests 26 | - Measured test coverage 27 | - Ports of the [RabbitMQ tutorials][rabbitmq-tutes] as [examples][tutes] 28 | - Used in production 29 | 30 | Still working on: 31 | 32 | - Getting to 100% (or very close to 100%) test coverage 33 | 34 | ## Callback API example 35 | 36 | ```javascript 37 | var q = 'tasks'; 38 | 39 | function bail(err) { 40 | console.error(err); 41 | process.exit(1); 42 | } 43 | 44 | // Publisher 45 | function publisher(conn) { 46 | conn.createChannel(on_open); 47 | function on_open(err, ch) { 48 | if (err != null) bail(err); 49 | ch.assertQueue(q); 50 | ch.sendToQueue(q, new Buffer('something to do')); 51 | } 52 | } 53 | 54 | // Consumer 55 | function consumer(conn) { 56 | var ok = conn.createChannel(on_open); 57 | function on_open(err, ch) { 58 | if (err != null) bail(err); 59 | ch.assertQueue(q); 60 | ch.consume(q, function(msg) { 61 | if (msg !== null) { 62 | console.log(msg.content.toString()); 63 | ch.ack(msg); 64 | } 65 | }); 66 | } 67 | } 68 | 69 | require('amqplib/callback_api') 70 | .connect('amqp://localhost', function(err, conn) { 71 | if (err != null) bail(err); 72 | consumer(conn); 73 | publisher(conn); 74 | }); 75 | ``` 76 | 77 | ## Promise API example 78 | 79 | ```javascript 80 | var q = 'tasks'; 81 | 82 | var open = require('amqplib').connect('amqp://localhost'); 83 | 84 | // Publisher 85 | open.then(function(conn) { 86 | return conn.createChannel(); 87 | }).then(function(ch) { 88 | return ch.assertQueue(q).then(function(ok) { 89 | return ch.sendToQueue(q, new Buffer('something to do')); 90 | }); 91 | }).catch(console.warn); 92 | 93 | // Consumer 94 | open.then(function(conn) { 95 | return conn.createChannel(); 96 | }).then(function(ch) { 97 | return ch.assertQueue(q).then(function(ok) { 98 | return ch.consume(q, function(msg) { 99 | if (msg !== null) { 100 | console.log(msg.content.toString()); 101 | ch.ack(msg); 102 | } 103 | }); 104 | }); 105 | }).catch(console.warn); 106 | ``` 107 | 108 | ## Running tests 109 | 110 | npm test 111 | 112 | To run the tests RabbitMQ is required. Either install it with your package 113 | manager, or use [docker][] to run a RabbitMQ instance. 114 | 115 | docker run -d --name amqp.test -p 5672:5672 rabbitmq 116 | 117 | If prefer not to run RabbitMQ locally it is also possible to use a 118 | instance of RabbitMQ hosted elsewhere. Use the `URL` environment 119 | variable to configure a different amqp host to connect to. You may 120 | also need to do this if docker is not on localhost; e.g., if it's 121 | running in docker-machine. 122 | 123 | One public host is dev.rabbitmq.com: 124 | 125 | URL=amqp://dev.rabbitmq.com npm test 126 | 127 | **NB** You may experience test failures due to timeouts if using the 128 | dev.rabbitmq.com instance. 129 | 130 | You can run it under different versions of Node.JS using [nave][]: 131 | 132 | nave use 0.8 npm test 133 | 134 | or run the tests on all supported versions of Node.JS in one go: 135 | 136 | make test-all-nodejs 137 | 138 | (which also needs `nave` installed, of course). 139 | 140 | Lastly, setting the environment variable `LOG_ERRORS` will cause the 141 | tests to output error messages encountered, to the console; this is 142 | really only useful for checking the kind and formatting of the errors. 143 | 144 | LOG_ERRORS=true npm test 145 | 146 | ## Test coverage 147 | 148 | make coverage 149 | open file://`pwd`/coverage/lcov-report/index.html 150 | 151 | [gh-pages]: http://squaremo.github.com/amqp.node/ 152 | [gh-pages-apiref]: http://squaremo.github.com/amqp.node/channel_api.html 153 | [nave]: https://github.com/isaacs/nave 154 | [tutes]: https://github.com/squaremo/amqp.node/tree/master/examples/tutorials 155 | [rabbitmq-tutes]: http://www.rabbitmq.com/getstarted.html 156 | [changelog]: https://github.com/squaremo/amqp.node/blob/master/CHANGELOG.md 157 | [docker]: https://www.docker.com/ 158 | -------------------------------------------------------------------------------- /node_modules/amqplib/callback_api.js: -------------------------------------------------------------------------------- 1 | var raw_connect = require('./lib/connect').connect; 2 | var CallbackModel = require('./lib/callback_model').CallbackModel; 3 | 4 | // Supports three shapes: 5 | // connect(url, options, callback) 6 | // connect(url, callback) 7 | // connect(callback) 8 | function connect(url, options, cb) { 9 | if (typeof url === 'function') 10 | cb = url, url = false, options = false; 11 | else if (typeof options === 'function') 12 | cb = options, options = false; 13 | 14 | raw_connect(url, options, function(err, c) { 15 | if (err === null) cb(null, new CallbackModel(c)); 16 | else cb(err); 17 | }); 18 | }; 19 | 20 | module.exports.connect = connect; 21 | module.exports.credentials = require('./lib/credentials'); 22 | module.exports.IllegalOperationError = require('./lib/error').IllegalOperationError; 23 | -------------------------------------------------------------------------------- /node_modules/amqplib/channel_api.js: -------------------------------------------------------------------------------- 1 | var raw_connect = require('./lib/connect').connect; 2 | var ChannelModel = require('./lib/channel_model').ChannelModel; 3 | var Promise = require('bluebird'); 4 | 5 | function connect(url, connOptions) { 6 | return Promise.fromCallback(function(cb) { 7 | return raw_connect(url, connOptions, cb); 8 | }) 9 | .then(function(conn) { 10 | return new ChannelModel(conn); 11 | }); 12 | }; 13 | 14 | module.exports.connect = connect; 15 | module.exports.credentials = require('./lib/credentials'); 16 | module.exports.IllegalOperationError = require('./lib/error').IllegalOperationError; 17 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/headers.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Example of using a headers exchange 4 | 5 | var amqp = require('../') 6 | 7 | amqp.connect().then(function(conn) { 8 | return conn.createChannel().then(withChannel); 9 | }, console.error); 10 | 11 | function withChannel(ch) { 12 | // NB the type of the exchange is 'headers' 13 | ch.assertExchange('matching exchange', 'headers').then(function(ex) { 14 | ch.assertQueue().then(function(q) { 15 | bindAndConsume(ch, ex, q).then(function() { 16 | send(ch, ex); 17 | }); 18 | }); 19 | }); 20 | } 21 | 22 | function bindAndConsume(ch, ex, q) { 23 | // When using a headers exchange, the headers to be matched go in 24 | // the binding arguments. The routing key is ignore, so best left 25 | // empty. 26 | 27 | // 'x-match' is 'all' or 'any', meaning "all fields must match" or 28 | // "at least one field must match", respectively. The values to be 29 | // matched go in subsequent fields. 30 | ch.bindQueue(q.queue, ex.exchange, '', {'x-match': 'any', 31 | 'foo': 'bar', 32 | 'baz': 'boo'}); 33 | return ch.consume(q.queue, function(msg) { 34 | console.log(msg.content.toString()); 35 | }, {noAck: true}); 36 | } 37 | 38 | function send(ch, ex) { 39 | // The headers for a message are given as an option to `publish`: 40 | ch.publish(ex.exchange, '', Buffer.from('hello'), {headers: {baz: 'boo'}}); 41 | ch.publish(ex.exchange, '', Buffer.from('world'), {headers: {foo: 'bar'}}); 42 | } 43 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/receive_generator.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | const co = require('co'); 5 | const amqp = require('amqplib'); 6 | const readline = require('readline'); 7 | 8 | co(function* () { 9 | const myConsumer = (msg) => { 10 | if (msg !== null) { 11 | console.log('consuming message %s in generator', JSON.stringify(msg.content.toString())); 12 | } 13 | }; 14 | const conn = yield amqp.connect('amqp://localhost'); 15 | try { 16 | // create a message to consume 17 | const q = 'hello'; 18 | const msg = 'Hello World!'; 19 | const channel = yield conn.createChannel(); 20 | yield channel.assertQueue(q); 21 | channel.sendToQueue(q, Buffer.from(msg)); 22 | console.log(" [x] Sent '%s'", msg); 23 | // consume the message 24 | yield channel.consume(q, myConsumer, { noAck: true }); 25 | } 26 | catch (e) { 27 | throw e; 28 | } 29 | }).catch(err => { 30 | console.warn('Error:', err); 31 | }); 32 | 33 | const rl = readline.createInterface({ 34 | input: process.stdin, 35 | output: process.stdout 36 | }); 37 | 38 | // pend until message is consumed 39 | rl.question('newline to exit', () => process.exit()); -------------------------------------------------------------------------------- /node_modules/amqplib/examples/send_generators.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | // NB this requires the module 'co': 6 | // npm install co 7 | const co = require('co'); 8 | const amqp = require('amqplib'); 9 | 10 | co(function* () { 11 | // connection errors are handled in the co .catch handler 12 | const conn = yield amqp.connect('amqp://localhost'); 13 | 14 | // try catch will throw any errors from the yielding the following promises to the co .catch handler 15 | try { 16 | const q = 'hello'; 17 | const msg = 'Hello World!'; 18 | 19 | // use a confirm channel so we can check the message is sent OK. 20 | const channel = yield conn.createConfirmChannel(); 21 | 22 | yield channel.assertQueue(q); 23 | 24 | channel.sendToQueue(q, Buffer.from(msg)); 25 | 26 | // if message has been nacked, this will result in an error (rejected promise); 27 | yield channel.waitForConfirms(); 28 | 29 | console.log(" [x] Sent '%s'", msg); 30 | 31 | channel.close(); 32 | } 33 | catch (e) { 34 | throw e; 35 | } 36 | finally { 37 | conn.close(); 38 | } 39 | 40 | }).catch(err => { 41 | console.warn('Error:', err); 42 | }); 43 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/ssl.js: -------------------------------------------------------------------------------- 1 | // Example of using a TLS/SSL connection. Note that the server must be 2 | // configured to accept SSL connections; see, for example, 3 | // http://www.rabbitmq.com/ssl.html. 4 | // 5 | // When trying this out, I followed the RabbitMQ SSL guide above, 6 | // almost verbatim. I set the CN of the server certificate to 7 | // 'localhost' rather than $(hostname) (since on my MBP hostname ends 8 | // up being ".local", which is just weird). My client 9 | // certificates etc., are in `../etc/client/`. My testca certificate 10 | // is in `../etc/testca` and server certs etc., in `../etc/server`, 11 | // and I've made a `rabbitmq.config` file, with which I start 12 | // RabbitMQ: 13 | // 14 | // RABBITMQ_CONFIG_FILE=`pwd`/../etc/server/rabbitmq \ 15 | // /usr/local/sbin/rabbitmq-server & 16 | // 17 | // A way to check RabbitMQ's running with SSL OK is to use 18 | // 19 | // openssl s_client -connect localhost:5671 20 | 21 | var amqp = require('../'); 22 | var fs = require('fs'); 23 | 24 | // Assemble the SSL options; for verification we need at least 25 | // * a certificate to present to the server ('cert', in PEM format) 26 | // * the private key for the certificate ('key', in PEM format) 27 | // * (possibly) a passphrase for the private key 28 | // 29 | // The first two may be replaced with a PKCS12 file ('pfx', in pkcs12 30 | // format) 31 | 32 | // We will also want to list the CA certificates that we will trust, 33 | // since we're using a self-signed certificate. It is NOT recommended 34 | // to use `rejectUnauthorized: false`. 35 | 36 | // Options for full client and server verification: 37 | var opts = { 38 | cert: fs.readFileSync('../etc/client/cert.pem'), 39 | key: fs.readFileSync('../etc/client/key.pem'), 40 | // cert and key or 41 | // pfx: fs.readFileSync('../etc/client/keycert.p12'), 42 | passphrase: 'MySecretPassword', 43 | ca: [fs.readFileSync('../etc/testca/cacert.pem')] 44 | }; 45 | 46 | // Options for just confidentiality. This requires RabbitMQ's SSL 47 | // configuration to include the items 48 | // 49 | // {verify, verify_none}, 50 | // {fail_if_no_peer_cert,false} 51 | // 52 | // var opts = { ca: [fs.readFileSync('../etc/testca/cacert.pem')] }; 53 | 54 | // Option to use the SSL client certificate for authentication 55 | // opts.credentials = amqp.credentials.external(); 56 | 57 | var open = amqp.connect('amqps://localhost', opts); 58 | 59 | open.then(function(conn) { 60 | process.on('SIGINT', conn.close.bind(conn)); 61 | return conn.createChannel().then(function(ch) { 62 | ch.sendToQueue('foo', Buffer.from('Hello World!')); 63 | }); 64 | }).then(null, console.warn); 65 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/README.md: -------------------------------------------------------------------------------- 1 | # RabbitMQ tutorials 2 | 3 | This directory contains the [RabbitMQ tutorials][rabbitmq-tutes], 4 | ported to amqplib. The sub-directory `callback_api` has translations 5 | of the tutorial programs to the callback-oriented API. 6 | 7 | ## Preparation 8 | 9 | To run the tutorial code, you need amqplib installed. Assuming you are 10 | in a clone of the amqplib repository, from the tutorials directory: 11 | 12 | npm install 13 | 14 | or to use the latest released version, 15 | 16 | npm install amqplib 17 | 18 | Then just run each file as a script, e.g., in bash 19 | 20 | ./send.js 21 | 22 | or 23 | 24 | node send.js 25 | 26 | or 27 | 28 | nave use 0.8 node send.js 29 | 30 | ## [Tutorial one: Hello World!][tute-one] 31 | 32 | A "Hello World" example, with one script sending a message to a queue, 33 | and another receiving messages from the same queue. 34 | 35 | * [send.js](send.js) 36 | * [receive.js](receive.js) 37 | 38 | ## [Tutorial two: Work queues][tute-two] 39 | 40 | Using RabbitMQ as a work queue; `new_task` creates a task, and 41 | `worker` processes tasks. Multiple `worker` process will share the 42 | tasks among them. Long-running tasks are simulated by supplying a 43 | string with dots, e.g., '...' to `new_task`. Each dot makes the worker 44 | "work" for a second. 45 | 46 | * [new_task.js](new_task.js) 47 | * [worker.js](worker.js) 48 | 49 | ## [Tutorial three: Publish/Subscribe][tute-three] 50 | 51 | Using RabbitMQ as a broadcast mechanism. `emit_log` sends a "log" 52 | message to a fanout exchange, and all `receive_logs` processes receive 53 | log messages. 54 | 55 | * [emit_log.js](emit_log.js) 56 | * [receive_logs.js](receive_logs.js) 57 | 58 | ## [Tutorial four: Routing][tute-four] 59 | 60 | Using RabbitMQ as a routing ('somecast') mechanism. `emit_log_direct` 61 | sends a log message with a severity, and all `receive_logs_direct` 62 | processes receive log messages for the severities on which they are 63 | listening. 64 | 65 | * [emit_log_direct.js](emit_log_direct.js) 66 | * [receive_logs_direct.js](receive_logs_direct.js) 67 | 68 | ## [Tutorial five: Topics][tute-five] 69 | 70 | Extends the previous tutorial to routing with wildcarded patterns. 71 | 72 | * [emit_log_topic.js](emit_log_topic.js) 73 | * [receive_logs_topic.js](receive_logs_topic.js) 74 | 75 | ## [Tutorial six: RPC][tute-six] 76 | 77 | Using RabbitMQ as an RPC intermediary, queueing requests for servers 78 | and routing replies back to clients. 79 | 80 | * [rpc_server.js](rpc_server.js) 81 | * [rpc_client.js](rpc_client.js) 82 | 83 | I depart slightly from the original tutorial code, which I think has 84 | some needless object-orientation (in the Python code; you don't get a 85 | choice about needless object-orientation in Java). 86 | 87 | [rabbitmq-tutes]: http://github.com/rabbitmq/rabbitmq-tutorials 88 | [tute-one]: http://www.rabbitmq.com/tutorials/tutorial-one-python.html 89 | [tute-two]: http://www.rabbitmq.com/tutorials/tutorial-two-python.html 90 | [tute-three]: http://www.rabbitmq.com/tutorials/tutorial-three-python.html 91 | [tute-four]: http://www.rabbitmq.com/tutorials/tutorial-four-python.html 92 | [tute-five]: http://www.rabbitmq.com/tutorials/tutorial-five-python.html 93 | [tute-six]: http://www.rabbitmq.com/tutorials/tutorial-six-python.html 94 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/emit_log.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | function bail(err, conn) { 6 | console.error(err); 7 | if (conn) conn.close(function() { process.exit(1); }); 8 | } 9 | 10 | function on_connect(err, conn) { 11 | if (err !== null) return bail(err); 12 | 13 | var ex = 'logs'; 14 | 15 | function on_channel_open(err, ch) { 16 | if (err !== null) return bail(err, conn); 17 | ch.assertExchange(ex, 'fanout', {durable: false}); 18 | var msg = process.argv.slice(2).join(' ') || 19 | 'info: Hello World!'; 20 | ch.publish(ex, '', Buffer.from(msg)); 21 | console.log(" [x] Sent '%s'", msg); 22 | ch.close(function() { conn.close(); }); 23 | } 24 | 25 | conn.createChannel(on_channel_open); 26 | } 27 | 28 | amqp.connect(on_connect); 29 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | var args = process.argv.slice(2); 6 | var severity = (args.length > 0) ? args[0] : 'info'; 7 | var message = args.slice(1).join(' ') || 'Hello World!'; 8 | 9 | function bail(err, conn) { 10 | console.error(err); 11 | if (conn) conn.close(function() { process.exit(1); }); 12 | } 13 | 14 | function on_connect(err, conn) { 15 | if (err !== null) return bail(err); 16 | 17 | var ex = 'direct_logs'; 18 | var exopts = {durable: false}; 19 | 20 | function on_channel_open(err, ch) { 21 | if (err !== null) return bail(err, conn); 22 | ch.assertExchange(ex, 'direct', exopts, function(err, ok) { 23 | ch.publish(ex, severity, Buffer.from(message)); 24 | ch.close(function() { conn.close(); }); 25 | }); 26 | } 27 | conn.createChannel(on_channel_open); 28 | } 29 | 30 | amqp.connect(on_connect); 31 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | var args = process.argv.slice(2); 6 | var key = (args.length > 0) ? args[0] : 'info'; 7 | var message = args.slice(1).join(' ') || 'Hello World!'; 8 | 9 | function bail(err, conn) { 10 | console.error(err); 11 | if (conn) conn.close(function() { process.exit(1); }); 12 | } 13 | 14 | function on_connect(err, conn) { 15 | if (err !== null) return bail(err); 16 | var ex = 'topic_logs', exopts = {durable: false}; 17 | conn.createChannel(function(err, ch) { 18 | ch.assertExchange(ex, 'topic', exopts, function(err, ok) { 19 | if (err !== null) return bail(err, conn); 20 | ch.publish(ex, key, Buffer.from(message)); 21 | console.log(" [x] Sent %s:'%s'", key, message); 22 | ch.close(function() { conn.close(); }); 23 | }); 24 | }); 25 | } 26 | 27 | amqp.connect(on_connect); 28 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/new_task.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | function bail(err, conn) { 6 | console.error(err); 7 | if (conn) conn.close(function() { process.exit(1); }); 8 | } 9 | 10 | function on_connect(err, conn) { 11 | if (err !== null) return bail(err); 12 | 13 | var q = 'task_queue'; 14 | 15 | conn.createChannel(function(err, ch) { 16 | if (err !== null) return bail(err, conn); 17 | ch.assertQueue(q, {durable: true}, function(err, _ok) { 18 | if (err !== null) return bail(err, conn); 19 | var msg = process.argv.slice(2).join(' ') || "Hello World!"; 20 | ch.sendToQueue(q, Buffer.from(msg), {persistent: true}); 21 | console.log(" [x] Sent '%s'", msg); 22 | ch.close(function() { conn.close(); }); 23 | }); 24 | }); 25 | } 26 | 27 | amqp.connect(on_connect); 28 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/receive.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | function bail(err, conn) { 6 | console.error(err); 7 | if (conn) conn.close(function() { process.exit(1); }); 8 | } 9 | 10 | function on_connect(err, conn) { 11 | if (err !== null) return bail(err); 12 | process.once('SIGINT', function() { conn.close(); }); 13 | 14 | var q = 'hello'; 15 | 16 | function on_channel_open(err, ch) { 17 | ch.assertQueue(q, {durable: false}, function(err, ok) { 18 | if (err !== null) return bail(err, conn); 19 | ch.consume(q, function(msg) { // message callback 20 | console.log(" [x] Received '%s'", msg.content.toString()); 21 | }, {noAck: true}, function(_consumeOk) { // consume callback 22 | console.log(' [*] Waiting for messages. To exit press CTRL+C'); 23 | }); 24 | }); 25 | } 26 | 27 | conn.createChannel(on_channel_open); 28 | } 29 | 30 | amqp.connect(on_connect); 31 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | function bail(err, conn) { 6 | console.error(err); 7 | if (conn) conn.close(function() { process.exit(1); }); 8 | } 9 | 10 | function on_connect(err, conn) { 11 | if (err !== null) return bail(err); 12 | process.once('SIGINT', function() { conn.close(); }); 13 | 14 | var ex = 'logs'; 15 | 16 | function on_channel_open(err, ch) { 17 | if (err !== null) return bail(err, conn); 18 | ch.assertQueue('', {exclusive: true}, function(err, ok) { 19 | var q = ok.queue; 20 | ch.bindQueue(q, ex, ''); 21 | ch.consume(q, logMessage, {noAck: true}, function(err, ok) { 22 | if (err !== null) return bail(err, conn); 23 | console.log(" [*] Waiting for logs. To exit press CTRL+C."); 24 | }); 25 | }); 26 | } 27 | 28 | function logMessage(msg) { 29 | if (msg) 30 | console.log(" [x] '%s'", msg.content.toString()); 31 | } 32 | 33 | conn.createChannel(on_channel_open); 34 | } 35 | 36 | amqp.connect(on_connect); 37 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | var basename = require('path').basename; 6 | 7 | var severities = process.argv.slice(2); 8 | if (severities.length < 1) { 9 | console.log('Usage %s [info] [warning] [error]', 10 | basename(process.argv[1])); 11 | process.exit(1); 12 | } 13 | 14 | function bail(err, conn) { 15 | console.error(err); 16 | if (conn) conn.close(function() { process.exit(1); }); 17 | } 18 | 19 | function on_connect(err, conn) { 20 | if (err !== null) return bail(err); 21 | process.once('SIGINT', function() { conn.close(); }); 22 | 23 | conn.createChannel(function(err, ch) { 24 | if (err !== null) return bail(err, conn); 25 | var ex = 'direct_logs', exopts = {durable: false}; 26 | 27 | ch.assertExchange(ex, 'direct', exopts); 28 | ch.assertQueue('', {exclusive: true}, function(err, ok) { 29 | if (err !== null) return bail(err, conn); 30 | 31 | var queue = ok.queue, i = 0; 32 | 33 | function sub(err) { 34 | if (err !== null) return bail(err, conn); 35 | else if (i < severities.length) { 36 | ch.bindQueue(queue, ex, severities[i], {}, sub); 37 | i++; 38 | } 39 | } 40 | 41 | ch.consume(queue, logMessage, {noAck: true}, function(err) { 42 | if (err !== null) return bail(err, conn); 43 | console.log(' [*] Waiting for logs. To exit press CTRL+C.'); 44 | sub(null); 45 | }); 46 | }); 47 | }); 48 | } 49 | 50 | function logMessage(msg) { 51 | console.log(" [x] %s:'%s'", 52 | msg.fields.routingKey, 53 | msg.content.toString()); 54 | } 55 | 56 | amqp.connect(on_connect); 57 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | var basename = require('path').basename; 5 | 6 | var keys = process.argv.slice(2); 7 | if (keys.length < 1) { 8 | console.log('Usage %s pattern [pattern...]', 9 | basename(process.argv[1])); 10 | process.exit(1); 11 | } 12 | 13 | function bail(err, conn) { 14 | console.error(err); 15 | if (conn) conn.close(function() { process.exit(1); }); 16 | } 17 | 18 | function on_connect(err, conn) { 19 | if (err !== null) return bail(err); 20 | process.once('SIGINT', function() { conn.close(); }); 21 | 22 | conn.createChannel(function(err, ch) { 23 | if (err !== null) return bail(err, conn); 24 | var ex = 'topic_logs', exopts = {durable: false}; 25 | 26 | ch.assertExchange(ex, 'topic', exopts); 27 | ch.assertQueue('', {exclusive: true}, function(err, ok) { 28 | if (err !== null) return bail(err, conn); 29 | 30 | var queue = ok.queue, i = 0; 31 | 32 | function sub(err) { 33 | if (err !== null) return bail(err, conn); 34 | else if (i < keys.length) { 35 | ch.bindQueue(queue, ex, keys[i], {}, sub); 36 | i++; 37 | } 38 | } 39 | 40 | ch.consume(queue, logMessage, {noAck: true}, function(err) { 41 | if (err !== null) return bail(err, conn); 42 | console.log(' [*] Waiting for logs. To exit press CTRL+C.'); 43 | sub(null); 44 | }); 45 | }); 46 | }); 47 | } 48 | 49 | function logMessage(msg) { 50 | console.log(" [x] %s:'%s'", 51 | msg.fields.routingKey, 52 | msg.content.toString()); 53 | } 54 | 55 | amqp.connect(on_connect); 56 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | var basename = require('path').basename; 5 | var uuid = require('node-uuid'); 6 | 7 | var n; 8 | try { 9 | if (process.argv.length < 3) throw Error('Too few args'); 10 | n = parseInt(process.argv[2]); 11 | } 12 | catch (e) { 13 | console.error(e); 14 | console.warn('Usage: %s number', basename(process.argv[1])); 15 | process.exit(1); 16 | } 17 | 18 | function bail(err, conn) { 19 | console.error(err); 20 | if (conn) conn.close(function() { process.exit(1); }); 21 | } 22 | 23 | function on_connect(err, conn) { 24 | if (err !== null) return bail(err); 25 | conn.createChannel(function(err, ch) { 26 | if (err !== null) return bail(err, conn); 27 | 28 | var correlationId = uuid(); 29 | function maybeAnswer(msg) { 30 | if (msg.properties.correlationId === correlationId) { 31 | console.log(' [.] Got %d', msg.content.toString()); 32 | } 33 | else return bail(new Error('Unexpected message'), conn); 34 | ch.close(function() { conn.close(); }); 35 | } 36 | 37 | ch.assertQueue('', {exclusive: true}, function(err, ok) { 38 | if (err !== null) return bail(err, conn); 39 | var queue = ok.queue; 40 | ch.consume(queue, maybeAnswer, {noAck:true}); 41 | console.log(' [x] Requesting fib(%d)', n); 42 | ch.sendToQueue('rpc_queue', Buffer.from(n.toString()), { 43 | replyTo: queue, correlationId: correlationId 44 | }); 45 | }); 46 | }); 47 | } 48 | 49 | amqp.connect(on_connect); 50 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | function fib(n) { 6 | var a = 0, b = 1; 7 | for (var i=0; i < n; i++) { 8 | var c = a + b; 9 | a = b; b = c; 10 | } 11 | return a; 12 | } 13 | 14 | function bail(err, conn) { 15 | console.error(err); 16 | if (conn) conn.close(function() { process.exit(1); }); 17 | } 18 | 19 | function on_connect(err, conn) { 20 | if (err !== null) return bail(err); 21 | 22 | process.once('SIGINT', function() { conn.close(); }); 23 | 24 | var q = 'rpc_queue'; 25 | 26 | conn.createChannel(function(err, ch) { 27 | ch.assertQueue(q, {durable: false}); 28 | ch.prefetch(1); 29 | ch.consume(q, reply, {noAck:false}, function(err) { 30 | if (err !== null) return bail(err, conn); 31 | console.log(' [x] Awaiting RPC requests'); 32 | }); 33 | 34 | function reply(msg) { 35 | var n = parseInt(msg.content.toString()); 36 | console.log(' [.] fib(%d)', n); 37 | ch.sendToQueue(msg.properties.replyTo, 38 | Buffer.from(fib(n).toString()), 39 | {correlationId: msg.properties.correlationId}); 40 | ch.ack(msg); 41 | } 42 | }); 43 | } 44 | 45 | amqp.connect(on_connect); 46 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/send.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | function bail(err, conn) { 6 | console.error(err); 7 | if (conn) conn.close(function() { process.exit(1); }); 8 | } 9 | 10 | function on_connect(err, conn) { 11 | if (err !== null) return bail(err); 12 | 13 | var q = 'hello'; 14 | var msg = 'Hello World!'; 15 | 16 | function on_channel_open(err, ch) { 17 | if (err !== null) return bail(err, conn); 18 | ch.assertQueue(q, {durable: false}, function(err, ok) { 19 | if (err !== null) return bail(err, conn); 20 | ch.sendToQueue(q, Buffer.from(msg)); 21 | console.log(" [x] Sent '%s'", msg); 22 | ch.close(function() { conn.close(); }); 23 | }); 24 | } 25 | 26 | conn.createChannel(on_channel_open); 27 | } 28 | 29 | amqp.connect(on_connect); 30 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/callback_api/worker.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | function bail(err, conn) { 6 | console.error(err); 7 | if (conn) conn.close(function() { process.exit(1); }); 8 | } 9 | 10 | function on_connect(err, conn) { 11 | if (err !== null) return bail(err); 12 | process.once('SIGINT', function() { conn.close(); }); 13 | 14 | var q = 'task_queue'; 15 | 16 | conn.createChannel(function(err, ch) { 17 | if (err !== null) return bail(err, conn); 18 | ch.assertQueue(q, {durable: true}, function(err, _ok) { 19 | ch.consume(q, doWork, {noAck: false}); 20 | console.log(" [*] Waiting for messages. To exit press CTRL+C"); 21 | }); 22 | 23 | function doWork(msg) { 24 | var body = msg.content.toString(); 25 | console.log(" [x] Received '%s'", body); 26 | var secs = body.split('.').length - 1; 27 | setTimeout(function() { 28 | console.log(" [x] Done"); 29 | ch.ack(msg); 30 | }, secs * 1000); 31 | } 32 | }); 33 | } 34 | 35 | amqp.connect(on_connect); 36 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/emit_log.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib'); 4 | 5 | amqp.connect('amqp://localhost').then(function(conn) { 6 | return conn.createChannel().then(function(ch) { 7 | var ex = 'logs'; 8 | var ok = ch.assertExchange(ex, 'fanout', {durable: false}) 9 | 10 | var message = process.argv.slice(2).join(' ') || 11 | 'info: Hello World!'; 12 | 13 | return ok.then(function() { 14 | ch.publish(ex, '', Buffer.from(message)); 15 | console.log(" [x] Sent '%s'", message); 16 | return ch.close(); 17 | }); 18 | }).finally(function() { conn.close(); }); 19 | }).catch(console.warn); 20 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/emit_log_direct.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib'); 4 | 5 | var args = process.argv.slice(2); 6 | var severity = (args.length > 0) ? args[0] : 'info'; 7 | var message = args.slice(1).join(' ') || 'Hello World!'; 8 | 9 | amqp.connect('amqp://localhost').then(function(conn) { 10 | return conn.createChannel().then(function(ch) { 11 | var ex = 'direct_logs'; 12 | var ok = ch.assertExchange(ex, 'direct', {durable: false}); 13 | 14 | return ok.then(function() { 15 | ch.publish(ex, severity, Buffer.from(message)); 16 | console.log(" [x] Sent %s:'%s'", severity, message); 17 | return ch.close(); 18 | }); 19 | }).finally(function() { conn.close(); }); 20 | }).catch(console.warn); 21 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/emit_log_topic.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib'); 4 | 5 | var args = process.argv.slice(2); 6 | var key = (args.length > 0) ? args[0] : 'info'; 7 | var message = args.slice(1).join(' ') || 'Hello World!'; 8 | 9 | amqp.connect('amqp://localhost').then(function(conn) { 10 | return conn.createChannel().then(function(ch) { 11 | var ex = 'topic_logs'; 12 | var ok = ch.assertExchange(ex, 'topic', {durable: false}); 13 | return ok.then(function() { 14 | ch.publish(ex, key, Buffer.from(message)); 15 | console.log(" [x] Sent %s:'%s'", key, message); 16 | return ch.close(); 17 | }); 18 | }).finally(function() { conn.close(); }) 19 | }).catch(console.log); 20 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/new_task.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Post a new task to the work queue 3 | 4 | var amqp = require('amqplib'); 5 | 6 | amqp.connect('amqp://localhost').then(function(conn) { 7 | return conn.createChannel().then(function(ch) { 8 | var q = 'task_queue'; 9 | var ok = ch.assertQueue(q, {durable: true}); 10 | 11 | return ok.then(function() { 12 | var msg = process.argv.slice(2).join(' ') || "Hello World!"; 13 | ch.sendToQueue(q, Buffer.from(msg), {deliveryMode: true}); 14 | console.log(" [x] Sent '%s'", msg); 15 | return ch.close(); 16 | }); 17 | }).finally(function() { conn.close(); }); 18 | }).catch(console.warn); 19 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "amqplib-tutorials", 3 | "version": "0.0.1", 4 | "description": "The RabbitMQ tutorials, ported to amqplib", 5 | "main": "send.js", 6 | "dependencies": { 7 | "amqplib": "../..", 8 | "node-uuid": "*" 9 | }, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": "", 14 | "author": "Michael Bridgen ", 15 | "license": "MPL 2.0" 16 | } 17 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/receive.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib'); 4 | 5 | amqp.connect('amqp://localhost').then(function(conn) { 6 | process.once('SIGINT', function() { conn.close(); }); 7 | return conn.createChannel().then(function(ch) { 8 | 9 | var ok = ch.assertQueue('hello', {durable: false}); 10 | 11 | ok = ok.then(function(_qok) { 12 | return ch.consume('hello', function(msg) { 13 | console.log(" [x] Received '%s'", msg.content.toString()); 14 | }, {noAck: true}); 15 | }); 16 | 17 | return ok.then(function(_consumeOk) { 18 | console.log(' [*] Waiting for messages. To exit press CTRL+C'); 19 | }); 20 | }); 21 | }).catch(console.warn); 22 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/receive_logs.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib'); 4 | 5 | amqp.connect('amqp://localhost').then(function(conn) { 6 | process.once('SIGINT', function() { conn.close(); }); 7 | return conn.createChannel().then(function(ch) { 8 | var ok = ch.assertExchange('logs', 'fanout', {durable: false}); 9 | ok = ok.then(function() { 10 | return ch.assertQueue('', {exclusive: true}); 11 | }); 12 | ok = ok.then(function(qok) { 13 | return ch.bindQueue(qok.queue, 'logs', '').then(function() { 14 | return qok.queue; 15 | }); 16 | }); 17 | ok = ok.then(function(queue) { 18 | return ch.consume(queue, logMessage, {noAck: true}); 19 | }); 20 | return ok.then(function() { 21 | console.log(' [*] Waiting for logs. To exit press CTRL+C'); 22 | }); 23 | 24 | function logMessage(msg) { 25 | console.log(" [x] '%s'", msg.content.toString()); 26 | } 27 | }); 28 | }).catch(console.warn); 29 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/receive_logs_direct.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib'); 4 | var all = require('bluebird').all; 5 | var basename = require('path').basename; 6 | 7 | var severities = process.argv.slice(2); 8 | if (severities.length < 1) { 9 | console.warn('Usage: %s [info] [warning] [error]', 10 | basename(process.argv[1])); 11 | process.exit(1); 12 | } 13 | 14 | amqp.connect('amqp://localhost').then(function(conn) { 15 | process.once('SIGINT', function() { conn.close(); }); 16 | return conn.createChannel().then(function(ch) { 17 | var ex = 'direct_logs'; 18 | 19 | var ok = ch.assertExchange(ex, 'direct', {durable: false}); 20 | 21 | ok = ok.then(function() { 22 | return ch.assertQueue('', {exclusive: true}); 23 | }); 24 | 25 | ok = ok.then(function(qok) { 26 | var queue = qok.queue; 27 | return all(severities.map(function(sev) { 28 | ch.bindQueue(queue, ex, sev); 29 | })).then(function() { return queue; }); 30 | }); 31 | 32 | ok = ok.then(function(queue) { 33 | return ch.consume(queue, logMessage, {noAck: true}); 34 | }); 35 | return ok.then(function() { 36 | console.log(' [*] Waiting for logs. To exit press CTRL+C.'); 37 | }); 38 | 39 | function logMessage(msg) { 40 | console.log(" [x] %s:'%s'", 41 | msg.fields.routingKey, 42 | msg.content.toString()); 43 | } 44 | }); 45 | }).catch(console.warn); 46 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/receive_logs_topic.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib'); 4 | var basename = require('path').basename; 5 | var all = require('bluebird').all; 6 | 7 | var keys = process.argv.slice(2); 8 | if (keys.length < 1) { 9 | console.log('Usage: %s pattern [pattern...]', 10 | basename(process.argv[1])); 11 | process.exit(1); 12 | } 13 | 14 | amqp.connect('amqp://localhost').then(function(conn) { 15 | process.once('SIGINT', function() { conn.close(); }); 16 | return conn.createChannel().then(function(ch) { 17 | var ex = 'topic_logs'; 18 | var ok = ch.assertExchange(ex, 'topic', {durable: false}); 19 | 20 | ok = ok.then(function() { 21 | return ch.assertQueue('', {exclusive: true}); 22 | }); 23 | 24 | ok = ok.then(function(qok) { 25 | var queue = qok.queue; 26 | return all(keys.map(function(rk) { 27 | ch.bindQueue(queue, ex, rk); 28 | })).then(function() { return queue; }); 29 | }); 30 | 31 | ok = ok.then(function(queue) { 32 | return ch.consume(queue, logMessage, {noAck: true}); 33 | }); 34 | return ok.then(function() { 35 | console.log(' [*] Waiting for logs. To exit press CTRL+C.'); 36 | }); 37 | 38 | function logMessage(msg) { 39 | console.log(" [x] %s:'%s'", 40 | msg.fields.routingKey, 41 | msg.content.toString()); 42 | } 43 | }); 44 | }).catch(console.warn); 45 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/rpc_client.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib'); 4 | var basename = require('path').basename; 5 | var Promise = require('bluebird'); 6 | var uuid = require('node-uuid'); 7 | 8 | // I've departed from the form of the original RPC tutorial, which 9 | // needlessly introduces a class definition, and doesn't even 10 | // parameterise the request. 11 | 12 | var n; 13 | try { 14 | if (process.argv.length < 3) throw Error('Too few args'); 15 | n = parseInt(process.argv[2]); 16 | } 17 | catch (e) { 18 | console.error(e); 19 | console.warn('Usage: %s number', basename(process.argv[1])); 20 | process.exit(1); 21 | } 22 | 23 | amqp.connect('amqp://localhost').then(function(conn) { 24 | return conn.createChannel().then(function(ch) { 25 | return new Promise(function(resolve) { 26 | var corrId = uuid(); 27 | function maybeAnswer(msg) { 28 | if (msg.properties.correlationId === corrId) { 29 | resolve(msg.content.toString()); 30 | } 31 | } 32 | 33 | var ok = ch.assertQueue('', {exclusive: true}) 34 | .then(function(qok) { return qok.queue; }); 35 | 36 | ok = ok.then(function(queue) { 37 | return ch.consume(queue, maybeAnswer, {noAck: true}) 38 | .then(function() { return queue; }); 39 | }); 40 | 41 | ok = ok.then(function(queue) { 42 | console.log(' [x] Requesting fib(%d)', n); 43 | ch.sendToQueue('rpc_queue', Buffer.from(n.toString()), { 44 | correlationId: corrId, replyTo: queue 45 | }); 46 | }); 47 | }); 48 | }) 49 | .then(function(fibN) { 50 | console.log(' [.] Got %d', fibN); 51 | }) 52 | .finally(function() { conn.close(); }); 53 | }).catch(console.warn); 54 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/rpc_server.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib'); 4 | 5 | function fib(n) { 6 | // Do it the ridiculous, but not most ridiculous, way. For better, 7 | // see http://nayuki.eigenstate.org/page/fast-fibonacci-algorithms 8 | var a = 0, b = 1; 9 | for (var i=0; i < n; i++) { 10 | var c = a + b; 11 | a = b; b = c; 12 | } 13 | return a; 14 | } 15 | 16 | amqp.connect('amqp://localhost').then(function(conn) { 17 | process.once('SIGINT', function() { conn.close(); }); 18 | return conn.createChannel().then(function(ch) { 19 | var q = 'rpc_queue'; 20 | var ok = ch.assertQueue(q, {durable: false}); 21 | var ok = ok.then(function() { 22 | ch.prefetch(1); 23 | return ch.consume(q, reply); 24 | }); 25 | return ok.then(function() { 26 | console.log(' [x] Awaiting RPC requests'); 27 | }); 28 | 29 | function reply(msg) { 30 | var n = parseInt(msg.content.toString()); 31 | console.log(' [.] fib(%d)', n); 32 | var response = fib(n); 33 | ch.sendToQueue(msg.properties.replyTo, 34 | Buffer.from(response.toString()), 35 | {correlationId: msg.properties.correlationId}); 36 | ch.ack(msg); 37 | } 38 | }); 39 | }).catch(console.warn); 40 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/send.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib'); 4 | 5 | amqp.connect('amqp://localhost').then(function(conn) { 6 | return conn.createChannel().then(function(ch) { 7 | var q = 'hello'; 8 | var msg = 'Hello World!'; 9 | 10 | var ok = ch.assertQueue(q, {durable: false}); 11 | 12 | return ok.then(function(_qok) { 13 | // NB: `sentToQueue` and `publish` both return a boolean 14 | // indicating whether it's OK to send again straight away, or 15 | // (when `false`) that you should wait for the event `'drain'` 16 | // to fire before writing again. We're just doing the one write, 17 | // so we'll ignore it. 18 | ch.sendToQueue(q, Buffer.from(msg)); 19 | console.log(" [x] Sent '%s'", msg); 20 | return ch.close(); 21 | }); 22 | }).finally(function() { conn.close(); }); 23 | }).catch(console.warn); 24 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/tutorials/worker.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Process tasks from the work queue 3 | 4 | var amqp = require('amqplib'); 5 | 6 | amqp.connect('amqp://localhost').then(function(conn) { 7 | process.once('SIGINT', function() { conn.close(); }); 8 | return conn.createChannel().then(function(ch) { 9 | var ok = ch.assertQueue('task_queue', {durable: true}); 10 | ok = ok.then(function() { ch.prefetch(1); }); 11 | ok = ok.then(function() { 12 | ch.consume('task_queue', doWork, {noAck: false}); 13 | console.log(" [*] Waiting for messages. To exit press CTRL+C"); 14 | }); 15 | return ok; 16 | 17 | function doWork(msg) { 18 | var body = msg.content.toString(); 19 | console.log(" [x] Received '%s'", body); 20 | var secs = body.split('.').length - 1; 21 | //console.log(" [x] Task takes %d seconds", secs); 22 | setTimeout(function() { 23 | console.log(" [x] Done"); 24 | ch.ack(msg); 25 | }, secs * 1000); 26 | } 27 | }); 28 | }).catch(console.warn); 29 | -------------------------------------------------------------------------------- /node_modules/amqplib/examples/waitForConfirms.js: -------------------------------------------------------------------------------- 1 | var amqp = require('../'); 2 | 3 | var NUM_MSGS = 20; 4 | 5 | function mkCallback(i) { 6 | return (i % 2) === 0 ? function(err) { 7 | if (err !== null) { console.error('Message %d failed!', i); } 8 | else { console.log('Message %d confirmed', i); } 9 | } : null; 10 | } 11 | 12 | amqp.connect().then(function(c) { 13 | c.createConfirmChannel().then(function(ch) { 14 | for (var i=0; i < NUM_MSGS; i++) { 15 | ch.publish('amq.topic', 'whatever', Buffer.from('blah'), {}, mkCallback(i)); 16 | } 17 | ch.waitForConfirms().then(function() { 18 | console.log('All messages done'); 19 | c.close(); 20 | }).catch(console.error); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /node_modules/amqplib/lib/bitset.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | // A bitset implementation, after that in java.util. Yes there 6 | // already exist such things, but none implement next{Clear|Set}Bit or 7 | // equivalent, and none involved me tooling about for an evening. 8 | 9 | 'use strict'; 10 | 11 | function BitSet(size) { 12 | if (size) { 13 | var numWords = Math.ceil(size / 32); 14 | this.words = new Array(numWords); 15 | } 16 | else { 17 | this.words = []; 18 | } 19 | this.wordsInUse = 0; // = number, not index 20 | } 21 | 22 | var P = BitSet.prototype; 23 | 24 | function wordIndex(bitIndex) { 25 | return Math.floor(bitIndex / 32); 26 | } 27 | 28 | // Make sure we have at least numWords 29 | P.ensureSize = function(numWords) { 30 | var wordsPresent = this.words.length; 31 | if (wordsPresent < numWords) { 32 | this.words = this.words.concat(new Array(numWords - wordsPresent)); 33 | } 34 | } 35 | 36 | P.set = function(bitIndex) { 37 | var w = wordIndex(bitIndex); 38 | if (w >= this.wordsInUse) { 39 | this.ensureSize(w + 1); 40 | this.wordsInUse = w + 1; 41 | } 42 | var bit = 1 << bitIndex; 43 | this.words[w] |= bit; 44 | }; 45 | 46 | P.clear = function(bitIndex) { 47 | var w = wordIndex(bitIndex); 48 | if (w >= this.wordsInUse) return; 49 | var mask = ~(1 << bitIndex); 50 | this.words[w] &= mask; 51 | }; 52 | 53 | P.get = function(bitIndex) { 54 | var w = wordIndex(bitIndex); 55 | if (w >= this.wordsInUse) return false; // >= since index vs size 56 | var bit = 1 << bitIndex; 57 | return !!(this.words[w] & bit); 58 | } 59 | 60 | function trailingZeros(i) { 61 | // From Hacker's Delight, via JDK. Probably far less effective here, 62 | // since bit ops are not necessarily the quick way to do things in 63 | // JS. 64 | if (i === 0) return 32; 65 | var y, n = 31; 66 | y = i << 16; if (y != 0) { n = n -16; i = y; } 67 | y = i << 8; if (y != 0) { n = n - 8; i = y; } 68 | y = i << 4; if (y != 0) { n = n - 4; i = y; } 69 | y = i << 2; if (y != 0) { n = n - 2; i = y; } 70 | return n - ((i << 1) >>> 31); 71 | } 72 | 73 | // Give the next bit that's set on or after fromIndex, or -1 if no such 74 | // bit 75 | P.nextSetBit = function(fromIndex) { 76 | var w = wordIndex(fromIndex); 77 | if (w >= this.wordsInUse) return -1; 78 | 79 | // the right-hand side is shifted to only test the bits of the first 80 | // word that are > fromIndex 81 | var word = this.words[w] & (0xffffffff << fromIndex); 82 | while (true) { 83 | if (word) return (w * 32) + trailingZeros(word); 84 | w++; 85 | if (w === this.wordsInUse) return -1; 86 | word = this.words[w]; 87 | } 88 | }; 89 | 90 | P.nextClearBit = function(fromIndex) { 91 | var w = wordIndex(fromIndex); 92 | if (w >= this.wordsInUse) return fromIndex; 93 | 94 | var word = ~(this.words[w]) & (0xffffffff << fromIndex); 95 | while (true) { 96 | if (word) return (w * 32) + trailingZeros(word); 97 | w++; 98 | if (w == this.wordsInUse) return w * 32; 99 | word = ~(this.words[w]); 100 | } 101 | }; 102 | 103 | module.exports.BitSet = BitSet; 104 | -------------------------------------------------------------------------------- /node_modules/amqplib/lib/credentials.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | // Different kind of credentials that can be supplied when opening a 6 | // connection, corresponding to SASL mechanisms There's only two 7 | // useful mechanisms that RabbitMQ implements: 8 | // * PLAIN (send username and password in the plain) 9 | // * EXTERNAL (assume the server will figure out who you are from 10 | // context, i.e., your SSL certificate) 11 | var Buffer = require('safe-buffer').Buffer 12 | 13 | module.exports.plain = function(user, passwd) { 14 | return { 15 | mechanism: 'PLAIN', 16 | response: function() { 17 | return Buffer.from(['', user, passwd].join(String.fromCharCode(0))) 18 | }, 19 | username: user, 20 | password: passwd 21 | } 22 | } 23 | 24 | module.exports.external = function() { 25 | return { 26 | mechanism: 'EXTERNAL', 27 | response: function() { return Buffer.from(''); } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /node_modules/amqplib/lib/error.js: -------------------------------------------------------------------------------- 1 | var inherits = require('util').inherits; 2 | 3 | function trimStack(stack, num) { 4 | return stack && stack.split('\n').slice(num).join('\n'); 5 | } 6 | 7 | function IllegalOperationError(msg, stack) { 8 | var tmp = new Error(); 9 | this.message = msg; 10 | this.stack = this.toString() + '\n' + trimStack(tmp.stack, 2); 11 | this.stackAtStateChange = stack; 12 | } 13 | inherits(IllegalOperationError, Error); 14 | 15 | IllegalOperationError.prototype.name = 'IllegalOperationError'; 16 | 17 | function stackCapture(reason) { 18 | var e = new Error(); 19 | return 'Stack capture: ' + reason + '\n' + 20 | trimStack(e.stack, 2); 21 | } 22 | 23 | module.exports.IllegalOperationError = IllegalOperationError; 24 | module.exports.stackCapture = stackCapture; 25 | -------------------------------------------------------------------------------- /node_modules/amqplib/lib/format.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | // Stringifying various things 6 | 7 | 'use strict'; 8 | 9 | var defs = require('./defs'); 10 | var format = require('util').format; 11 | var inherits = require('util').inherits; 12 | var HEARTBEAT = require('./frame').HEARTBEAT; 13 | 14 | module.exports.closeMessage = function(close) { 15 | var code = close.fields.replyCode; 16 | return format('%d (%s) with message "%s"', 17 | code, defs.constant_strs[code], 18 | close.fields.replyText); 19 | } 20 | 21 | module.exports.methodName = function(id) { 22 | return defs.info(id).name; 23 | }; 24 | 25 | module.exports.inspect = function(frame, showFields) { 26 | if (frame === HEARTBEAT) { 27 | return ''; 28 | } 29 | else if (!frame.id) { 30 | return format('', 31 | frame.channel, frame.size); 32 | } 33 | else { 34 | var info = defs.info(frame.id); 35 | return format('<%s channel:%d%s>', info.name, frame.channel, 36 | (showFields) 37 | ? ' ' + JSON.stringify(frame.fields, undefined, 2) 38 | : ''); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /node_modules/amqplib/lib/frame.js: -------------------------------------------------------------------------------- 1 | // The river sweeps through 2 | // Silt and twigs, gravel and leaves 3 | // Driving the wheel on 4 | 5 | 'use strict'; 6 | 7 | var defs = require('./defs'); 8 | var constants = defs.constants; 9 | var decode = defs.decode; 10 | var Buffer = require('safe-buffer').Buffer 11 | 12 | var Bits = require('bitsyntax'); 13 | 14 | module.exports.PROTOCOL_HEADER = "AMQP" + String.fromCharCode(0, 0, 9, 1); 15 | 16 | /* 17 | Frame format: 18 | 19 | 0 1 3 7 size+7 size+8 20 | +------+---------+-------------+ +------------+ +-----------+ 21 | | type | channel | size | | payload | | frame-end | 22 | +------+---------+-------------+ +------------+ +-----------+ 23 | octet short long size octets octet 24 | 25 | In general I want to know those first three things straight away, so I 26 | can discard frames early. 27 | 28 | */ 29 | 30 | // framing constants 31 | var FRAME_METHOD = constants.FRAME_METHOD, 32 | FRAME_HEARTBEAT = constants.FRAME_HEARTBEAT, 33 | FRAME_HEADER = constants.FRAME_HEADER, 34 | FRAME_BODY = constants.FRAME_BODY, 35 | FRAME_END = constants.FRAME_END; 36 | 37 | var bodyCons = 38 | Bits.builder(FRAME_BODY, 39 | 'channel:16, size:32, payload:size/binary', 40 | FRAME_END); 41 | 42 | // %%% TESTME possibly better to cons the first bit and write the 43 | // second directly, in the absence of IO lists 44 | module.exports.makeBodyFrame = function(channel, payload) { 45 | return bodyCons({channel: channel, size: payload.length, payload: payload}); 46 | }; 47 | 48 | var frameHeaderPattern = Bits.matcher('type:8', 'channel:16', 49 | 'size:32', 'rest/binary'); 50 | 51 | function parseFrame(bin, max) { 52 | var fh = frameHeaderPattern(bin); 53 | if (fh) { 54 | var size = fh.size, rest = fh.rest; 55 | if (size > max) { 56 | throw new Error('Frame size exceeds frame max'); 57 | } 58 | else if (rest.length > size) { 59 | if (rest[size] !== FRAME_END) 60 | throw new Error('Invalid frame'); 61 | 62 | return { 63 | type: fh.type, 64 | channel: fh.channel, 65 | size: size, 66 | payload: rest.slice(0, size), 67 | rest: rest.slice(size + 1) 68 | }; 69 | } 70 | } 71 | return false; 72 | } 73 | 74 | module.exports.parseFrame = parseFrame; 75 | 76 | var headerPattern = Bits.matcher('class:16', 77 | '_weight:16', 78 | 'size:64', 79 | 'flagsAndfields/binary'); 80 | 81 | var methodPattern = Bits.matcher('id:32, args/binary'); 82 | 83 | var HEARTBEAT = {channel: 0}; 84 | 85 | module.exports.decodeFrame = function(frame) { 86 | var payload = frame.payload; 87 | switch (frame.type) { 88 | case FRAME_METHOD: 89 | var idAndArgs = methodPattern(payload); 90 | var id = idAndArgs.id; 91 | var fields = decode(id, idAndArgs.args); 92 | return {id: id, channel: frame.channel, fields: fields}; 93 | case FRAME_HEADER: 94 | var parts = headerPattern(payload); 95 | var id = parts['class']; 96 | var fields = decode(id, parts.flagsAndfields); 97 | return {id: id, channel: frame.channel, 98 | size: parts.size, fields: fields}; 99 | case FRAME_BODY: 100 | return {channel: frame.channel, content: frame.payload}; 101 | case FRAME_HEARTBEAT: 102 | return HEARTBEAT; 103 | default: 104 | throw new Error('Unknown frame type ' + frame.type); 105 | } 106 | } 107 | 108 | // encoded heartbeat 109 | module.exports.HEARTBEAT_BUF = Buffer.from([constants.FRAME_HEARTBEAT, 110 | 0, 0, 0, 0, // size = 0 111 | 0, 0, // channel = 0 112 | constants.FRAME_END]); 113 | 114 | module.exports.HEARTBEAT = HEARTBEAT; 115 | -------------------------------------------------------------------------------- /node_modules/amqplib/lib/heartbeat.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | // Heartbeats. In AMQP both clients and servers may expect a heartbeat 6 | // frame if there is no activity on the connection for a negotiated 7 | // period of time. If there's no activity for two such intervals, the 8 | // server or client is allowed to close the connection on the 9 | // presumption that the other party is dead. 10 | // 11 | // The client has two jobs here: the first is to send a heartbeat 12 | // frame if it's not sent any frames for a while, so that the server 13 | // doesn't think it's dead; the second is to check periodically that 14 | // it's seen activity from the server, and to advise if there doesn't 15 | // appear to have been any for over two intervals. 16 | // 17 | // Node.JS timers are a bit unreliable, in that they endeavour only to 18 | // fire at some indeterminate point *after* the given time (rather 19 | // gives the lie to 'realtime', dunnit). Because the scheduler is just 20 | // an event loop, it's quite easy to delay timers indefinitely by 21 | // reacting to some I/O with a lot of computation. 22 | // 23 | // To mitigate this I need a bit of creative interpretation: 24 | // 25 | // - I'll schedule a server activity check for every `interval`, and 26 | // check just how much time has passed. It will overshoot by at 27 | // least a small margin; modulo missing timer deadlines, it'll 28 | // notice between two and three intervals after activity actually 29 | // stops (otherwise, at some point after two intervals). 30 | // 31 | // - Every `interval / 2` I'll check that we've sent something since 32 | // the last check, and if not, send a heartbeat frame. If we're 33 | // really too busy to even run the check for two whole heartbeat 34 | // intervals, there must be a lot of I (but not O, at least not on 35 | // the connection), or computation, in which case perhaps it's best 36 | // the server cuts us off anyway. Why `interval / 2`? Because the 37 | // edge case is that the client sent a frame just after a 38 | // heartbeat, which would mean I only send one after almost two 39 | // intervals. (NB a heartbeat counts as a send, so it'll be checked 40 | // at least twice before sending another) 41 | // 42 | // This design is based largely on RabbitMQ's heartbeating: 43 | // https://github.com/rabbitmq/rabbitmq-common/blob/master/src/rabbit_heartbeat.erl 44 | 45 | // %% Yes, I could apply the same 'actually passage of time' thing to 46 | // %% send as well as to recv. 47 | 48 | 'use strict'; 49 | 50 | var inherits = require('util').inherits; 51 | var EventEmitter = require('events').EventEmitter; 52 | 53 | // Exported so that we can mess with it in tests 54 | module.exports.UNITS_TO_MS = 1000; 55 | 56 | function Heart(interval, checkSend, checkRecv) { 57 | EventEmitter.call(this); 58 | this.interval = interval; 59 | 60 | var intervalMs = interval * module.exports.UNITS_TO_MS; 61 | // Function#bind is my new best friend 62 | var beat = this.emit.bind(this, 'beat'); 63 | var timeout = this.emit.bind(this, 'timeout'); 64 | 65 | this.sendTimer = setInterval( 66 | this.runHeartbeat.bind(this, checkSend, beat), intervalMs / 2); 67 | 68 | // A timeout occurs if I see nothing for *two consecutive* intervals 69 | var recvMissed = 0; 70 | function missedTwo() { 71 | if (!checkRecv()) return (++recvMissed < 2); 72 | else { recvMissed = 0; return true; } 73 | } 74 | this.recvTimer = setInterval( 75 | this.runHeartbeat.bind(this, missedTwo, timeout), intervalMs); 76 | } 77 | inherits(Heart, EventEmitter); 78 | 79 | module.exports.Heart = Heart; 80 | 81 | Heart.prototype.clear = function() { 82 | clearInterval(this.sendTimer); 83 | clearInterval(this.recvTimer); 84 | }; 85 | 86 | Heart.prototype.runHeartbeat = function(check, fail) { 87 | // Have we seen activity? 88 | if (!check()) fail(); 89 | }; 90 | -------------------------------------------------------------------------------- /node_modules/amqplib/lib/mux.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | 'use strict'; 6 | 7 | // A Mux is an object into which other readable streams may be piped; 8 | // it then writes 'packets' from the upstreams to the given 9 | // downstream. 10 | 11 | var inherits = require('util').inherits; 12 | var assert = require('assert'); 13 | 14 | var schedule = (typeof setImmediate === 'function') ? 15 | setImmediate : process.nextTick; 16 | 17 | function Mux(downstream) { 18 | this.newStreams = []; 19 | this.oldStreams = []; 20 | this.blocked = false; 21 | this.scheduledRead = false; 22 | 23 | this.out = downstream; 24 | var self = this; 25 | downstream.on('drain', function() { 26 | self.blocked = false; 27 | self._readIncoming(); 28 | }); 29 | } 30 | 31 | // There are 2 states we can be in: 32 | 33 | // - waiting for outbound capacity, which will be signalled by a 34 | // - 'drain' event on the downstream; or, 35 | 36 | // - no packets to send, waiting for an inbound buffer to have 37 | // packets, which will be signalled by a 'readable' event 38 | 39 | // If we write all packets available whenever there is outbound 40 | // capacity, we will either run out of outbound capacity (`#write` 41 | // returns false), or run out of packets (all calls to an 42 | // `inbound.read()` have returned null). 43 | 44 | Mux.prototype._readIncoming = function() { 45 | 46 | // We may be sent here speculatively, if an incoming stream has 47 | // become readable 48 | if (this.blocked) return; 49 | 50 | var self = this; 51 | var accepting = true; 52 | var out = this.out; 53 | 54 | // Try to read a chunk from each stream in turn, until all streams 55 | // are empty, or we exhaust our ability to accept chunks. 56 | function roundrobin(streams) { 57 | var s; 58 | // if there's just one incoming stream we don't have to 59 | // go through all the dequeue/enqueueing 60 | if (streams.length === 1) { 61 | s = streams.shift(); 62 | while (accepting) { 63 | var chunk = s.read(); 64 | if (chunk !== null) { 65 | accepting = out.write(chunk); 66 | } 67 | else break; 68 | } 69 | if (!accepting) streams.push(s); 70 | } 71 | else { 72 | while (accepting && (s = streams.shift())) { 73 | var chunk = s.read(); 74 | if (chunk !== null) { 75 | accepting = out.write(chunk); 76 | streams.push(s); 77 | } 78 | } 79 | } 80 | } 81 | 82 | roundrobin(this.newStreams); 83 | 84 | // Either we exhausted the new queues, or we ran out of capacity. If 85 | // we ran out of capacity, all the remaining new streams (i.e., 86 | // those with packets left) become old streams. This effectively 87 | // prioritises streams that keep their buffers close to empty over 88 | // those that are constantly near full. 89 | 90 | if (accepting) { // all new queues are exhausted, write as many as 91 | // we can from the old streams 92 | assert.equal(0, this.newStreams.length); 93 | roundrobin(this.oldStreams); 94 | } 95 | else { // ran out of room 96 | assert(this.newStreams.length > 0, "Expect some new streams to remain"); 97 | this.oldStreams = this.oldStreams.concat(this.newStreams); 98 | this.newStreams = []; 99 | } 100 | // We may have exhausted all the old queues, or run out of room; 101 | // either way, all we need to do is record whether we have capacity 102 | // or not, so any speculative reads will know 103 | this.blocked = !accepting; 104 | }; 105 | 106 | Mux.prototype._scheduleRead = function() { 107 | var self = this; 108 | 109 | if (!self.scheduledRead) { 110 | schedule(function() { 111 | self.scheduledRead = false; 112 | self._readIncoming(); 113 | }); 114 | self.scheduledRead = true; 115 | } 116 | }; 117 | 118 | Mux.prototype.pipeFrom = function(readable) { 119 | var self = this; 120 | 121 | function enqueue() { 122 | self.newStreams.push(readable); 123 | self._scheduleRead(); 124 | } 125 | 126 | function cleanup() { 127 | readable.removeListener('readable', enqueue); 128 | readable.removeListener('error', cleanup); 129 | readable.removeListener('end', cleanup); 130 | readable.removeListener('unpipeFrom', cleanupIfMe); 131 | } 132 | function cleanupIfMe(dest) { 133 | if (dest === self) cleanup(); 134 | } 135 | 136 | readable.on('unpipeFrom', cleanupIfMe); 137 | readable.on('end', cleanup); 138 | readable.on('error', cleanup); 139 | readable.on('readable', enqueue); 140 | }; 141 | 142 | Mux.prototype.unpipeFrom = function(readable) { 143 | readable.emit('unpipeFrom', this); 144 | }; 145 | 146 | module.exports.Mux = Mux; 147 | -------------------------------------------------------------------------------- /node_modules/amqplib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "amqplib", 3 | "homepage": "http://squaremo.github.io/amqp.node/", 4 | "main": "./channel_api.js", 5 | "version": "0.5.2", 6 | "description": "An AMQP 0-9-1 (e.g., RabbitMQ) library and client.", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/squaremo/amqp.node.git" 10 | }, 11 | "engines": { 12 | "node": ">=0.8 <=9" 13 | }, 14 | "dependencies": { 15 | "bitsyntax": "~0.0.4", 16 | "bluebird": "^3.4.6", 17 | "buffer-more-ints": "0.0.2", 18 | "readable-stream": "1.x >=1.1.9", 19 | "safe-buffer": "^5.0.1" 20 | }, 21 | "devDependencies": { 22 | "mocha": "~1", 23 | "claire": "0.4.1", 24 | "uglify-js": "2.4.x", 25 | "istanbul": "0.1.x" 26 | }, 27 | "scripts": { 28 | "test": "make test", 29 | "prepublish": "make" 30 | }, 31 | "keywords": [ 32 | "AMQP", 33 | "AMQP 0-9-1", 34 | "RabbitMQ" 35 | ], 36 | "author": "Michael Bridgen ", 37 | "license": "MIT" 38 | } 39 | -------------------------------------------------------------------------------- /node_modules/amqplib/test/bitset.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var claire = require('claire'); 4 | 5 | var forAll = claire.forAll, 6 | arb = claire.data, 7 | label = claire.label, 8 | choice = claire.choice, 9 | transform = claire.transform; 10 | 11 | var BitSet = require('../lib/bitset').BitSet; 12 | var PosInt = transform(Math.floor, arb.Positive); 13 | 14 | var EmptyBitSet = label('bitset', transform( 15 | function(size) { 16 | return new BitSet(size); 17 | }, 18 | choice(arb.Nothing, PosInt))); 19 | 20 | suite('BitSet', function() { 21 | 22 | test('get bit', forAll(EmptyBitSet, PosInt) 23 | .satisfy(function(b, bit) { 24 | b.set(bit); 25 | return b.get(bit); 26 | }).asTest()); 27 | 28 | test('clear bit', forAll(EmptyBitSet, PosInt) 29 | .satisfy(function(b, bit) { 30 | b.set(bit); 31 | b.clear(bit); 32 | return !b.get(bit); 33 | }).asTest()); 34 | 35 | test('next set of empty', forAll(EmptyBitSet) 36 | .satisfy(function(b) { 37 | return b.nextSetBit(0) === -1; 38 | }).asTest()); 39 | 40 | test('next set of one bit', forAll(EmptyBitSet, PosInt) 41 | .satisfy(function(b, bit) { 42 | b.set(bit); 43 | return b.nextSetBit(0) === bit; 44 | }).asTest()); 45 | 46 | test('next set same bit', forAll(EmptyBitSet, PosInt) 47 | .satisfy(function(b, bit) { 48 | b.set(bit); 49 | return b.nextSetBit(bit) === bit; 50 | }).asTest()); 51 | 52 | test('next set following bit', forAll(EmptyBitSet, PosInt) 53 | .satisfy(function(b, bit) { 54 | b.set(bit); 55 | return b.nextSetBit(bit+1) === -1; 56 | }).asTest()); 57 | 58 | test('next clear of empty', forAll(EmptyBitSet, PosInt) 59 | .satisfy(function(b, bit) { return b.nextClearBit(bit) === bit; }) 60 | .asTest()); 61 | 62 | test('next clear of one set', forAll(EmptyBitSet, PosInt) 63 | .satisfy(function(b, bit) { 64 | b.set(bit); 65 | return b.nextClearBit(bit) === bit + 1; 66 | }).asTest()); 67 | 68 | }); 69 | -------------------------------------------------------------------------------- /node_modules/amqplib/test/connect.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var connect = require('../lib/connect').connect; 4 | var Buffer = require('safe-buffer').Buffer 5 | var credentialsFromUrl = require('../lib/connect').credentialsFromUrl; 6 | var assert = require('assert'); 7 | var util = require('./util'); 8 | var net = require('net'); 9 | var fail = util.fail, succeed = util.succeed, 10 | kCallback = util.kCallback, 11 | succeedIfAttributeEquals = util.succeedIfAttributeEquals; 12 | var format = require('util').format; 13 | 14 | var URL = process.env.URL || 'amqp://localhost'; 15 | 16 | suite("Credentials", function() { 17 | 18 | function checkCreds(creds, user, pass, done) { 19 | if (creds.mechanism != 'PLAIN') { 20 | return done('expected mechanism PLAIN'); 21 | } 22 | if (creds.username != user || creds.password != pass) { 23 | return done(format("expected '%s', '%s'; got '%s', '%s'", 24 | user, pass, creds.username, creds.password)); 25 | } 26 | done(); 27 | } 28 | 29 | test("no creds", function(done) { 30 | var parts = {auth: ''}; 31 | var creds = credentialsFromUrl(parts); 32 | checkCreds(creds, 'guest', 'guest', done); 33 | }); 34 | test("usual user:pass", function(done) { 35 | var parts = {auth: 'user:pass'}; 36 | var creds = credentialsFromUrl(parts); 37 | checkCreds(creds, 'user', 'pass', done); 38 | }); 39 | test("missing user", function(done) { 40 | var parts = {auth: ':password'}; 41 | var creds = credentialsFromUrl(parts); 42 | checkCreds(creds, '', 'password', done); 43 | }); 44 | test("missing password", function(done) { 45 | var parts = {auth: 'username'}; 46 | var creds = credentialsFromUrl(parts); 47 | checkCreds(creds, 'username', '', done); 48 | }); 49 | test("colon in password", function(done) { 50 | var parts = {auth: 'username:pass:word'}; 51 | var creds = credentialsFromUrl(parts); 52 | checkCreds(creds, 'username', 'pass:word', done); 53 | }); 54 | }); 55 | 56 | suite("Connect API", function() { 57 | 58 | test("Connection refused", function(done) { 59 | connect('amqp://localhost:23450', {}, 60 | kCallback(fail(done), succeed(done))); 61 | }); 62 | 63 | // %% this ought to fail the promise, rather than throwing an error 64 | test("bad URL", function() { 65 | assert.throws(function() { 66 | connect('blurble'); 67 | }); 68 | }); 69 | 70 | test("wrongly typed open option", function(done) { 71 | var url = require('url'); 72 | var parts = url.parse(URL, true); 73 | var q = parts.query || {}; 74 | q.frameMax = 'NOT A NUMBER'; 75 | parts.query = q; 76 | var u = url.format(parts); 77 | connect(u, {}, kCallback(fail(done), succeed(done))); 78 | }); 79 | 80 | test("using custom heartbeat option", function(done) { 81 | var url = require('url'); 82 | var parts = url.parse(URL, true); 83 | var config = parts.query || {}; 84 | config.heartbeat = 20; 85 | connect(config, {}, kCallback(succeedIfAttributeEquals('heartbeat', 20, done), fail(done))); 86 | }); 87 | 88 | test("wrongly typed heartbeat option", function(done) { 89 | var url = require('url'); 90 | var parts = url.parse(URL, true); 91 | var config = parts.query || {}; 92 | config.heartbeat = 'NOT A NUMBER'; 93 | connect(config, {}, kCallback(fail(done), succeed(done))); 94 | }); 95 | 96 | test("using plain credentials", function(done) { 97 | var url = require('url'); 98 | var parts = url.parse(URL, true); 99 | var u = 'guest', p = 'guest'; 100 | if (parts.auth) { 101 | var auth = parts.auth.split(":"); 102 | u = auth[0], p = auth[1]; 103 | } 104 | connect(URL, {credentials: require('../lib/credentials').plain(u, p)}, 105 | kCallback(succeed(done), fail(done))); 106 | }); 107 | 108 | test("using unsupported mechanism", function(done) { 109 | var creds = { 110 | mechanism: 'UNSUPPORTED', 111 | response: function() { return Buffer.from(''); } 112 | }; 113 | connect(URL, {credentials: creds}, 114 | kCallback(fail(done), succeed(done))); 115 | }); 116 | 117 | test("with a given connection timeout", function(done) { 118 | var timeoutServer = net.createServer(function() {}).listen(31991); 119 | 120 | connect('amqp://localhost:31991', {timeout: 50}, function(err, val) { 121 | timeoutServer.close(); 122 | if (val) done(new Error('Expected connection timeout, did not')); 123 | else done(); 124 | }); 125 | }); 126 | 127 | }); 128 | -------------------------------------------------------------------------------- /node_modules/amqplib/test/mux.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('assert'); 4 | var Mux = require('../lib/mux').Mux; 5 | var PassThrough = require('stream').PassThrough || 6 | require('readable-stream/passthrough'); 7 | 8 | var latch = require('./util').latch; 9 | var schedule = require('./util').schedule; 10 | 11 | function stream() { 12 | return new PassThrough({objectMode: true}); 13 | } 14 | 15 | function readAllObjects(s, cb) { 16 | var objs = []; 17 | 18 | function read() { 19 | var v = s.read(); 20 | while (v !== null) { 21 | objs.push(v); 22 | v = s.read(); 23 | } 24 | } 25 | 26 | s.on('end', function() { cb(objs); }); 27 | s.on('readable', read); 28 | 29 | read(); 30 | } 31 | 32 | test("single input", function(done) { 33 | var input = stream(); 34 | var output = stream(); 35 | input.on('end', function() { output.end() }); 36 | 37 | var mux = new Mux(output); 38 | mux.pipeFrom(input); 39 | 40 | var data = [1,2,3,4,5,6,7,8,9]; 41 | // not 0, it's treated specially by PassThrough for some reason. By 42 | // 'specially' I mean it breaks the stream. See e.g., 43 | // https://github.com/isaacs/readable-stream/pull/55 44 | data.forEach(input.write.bind(input)); 45 | 46 | readAllObjects(output, function(vals) { 47 | assert.deepEqual(data, vals); 48 | done(); 49 | }); 50 | 51 | input.end(); 52 | }); 53 | 54 | test("two sequential inputs", function(done) { 55 | var input1 = stream(); 56 | var input2 = stream(); 57 | var output = stream(); 58 | var mux = new Mux(output); 59 | mux.pipeFrom(input1); 60 | mux.pipeFrom(input2); 61 | 62 | var data = [1,2,3,4,5,6,7,8,9]; 63 | data.forEach(function(v) { input1.write(v); }); 64 | 65 | input1.on('end', function() { 66 | data.forEach(function (v) { input2.write(v); }); 67 | input2.end(); 68 | }); 69 | input2.on('end', function() { output.end(); }); 70 | 71 | input1.end(); 72 | readAllObjects(output, function(vs) { 73 | assert.equal(2 * data.length, vs.length); 74 | done(); 75 | }); 76 | }); 77 | 78 | test("two interleaved inputs", function(done) { 79 | var input1 = stream(); 80 | var input2 = stream(); 81 | var output = stream(); 82 | var mux = new Mux(output); 83 | mux.pipeFrom(input1); 84 | mux.pipeFrom(input2); 85 | 86 | var endLatch = latch(2, function() { output.end(); }); 87 | input1.on('end', endLatch); 88 | input2.on('end', endLatch); 89 | 90 | var data = [1,2,3,4,5,6,7,8,9]; 91 | data.forEach(function(v) { input1.write(v); }); 92 | input1.end(); 93 | 94 | data.forEach(function(v) { input2.write(v); }); 95 | input2.end(); 96 | 97 | readAllObjects(output, function(vs) { 98 | assert.equal(2 * data.length, vs.length); 99 | done(); 100 | }); 101 | }); 102 | 103 | test("unpipe", function(done) { 104 | var input = stream(); 105 | var output = stream(); 106 | var mux = new Mux(output); 107 | 108 | var pipedData = [1,2,3,4,5]; 109 | var unpipedData = [6,7,8,9]; 110 | 111 | mux.pipeFrom(input); 112 | 113 | schedule(function() { 114 | pipedData.forEach(input.write.bind(input)); 115 | mux.unpipeFrom(input); 116 | 117 | schedule(function() { 118 | unpipedData.forEach(input.write.bind(input)); 119 | input.end(); 120 | schedule(function() { 121 | // exhaust so that 'end' fires 122 | var v; while (v = input.read()); 123 | }); 124 | }); 125 | }); 126 | 127 | input.on('end', function() { 128 | output.end(); 129 | }); 130 | 131 | readAllObjects(output, function(vals) { 132 | try { 133 | assert.deepEqual(pipedData, vals); 134 | done(); 135 | } 136 | catch (e) { done(e); } 137 | }); 138 | }); 139 | 140 | test("roundrobin", function(done) { 141 | var input1 = stream(); 142 | var input2 = stream(); 143 | var output = stream(); 144 | var mux = new Mux(output); 145 | 146 | mux.pipeFrom(input1); 147 | mux.pipeFrom(input2); 148 | 149 | var endLatch = latch(2, function() { output.end(); }); 150 | input1.on('end', endLatch); 151 | input2.on('end', endLatch); 152 | 153 | var ones = [1,1,1,1,1]; 154 | ones.forEach(function(v) { input1.write(v); }); 155 | input1.end(); 156 | 157 | var twos = [2,2,2,2,2]; 158 | twos.forEach(function(v) { input2.write(v); }); 159 | input2.end(); 160 | 161 | readAllObjects(output, function(vs) { 162 | assert.deepEqual([1,2,1,2,1,2,1,2,1,2], vs); 163 | done(); 164 | }); 165 | 166 | }); 167 | -------------------------------------------------------------------------------- /node_modules/bitsyntax/.npmignore: -------------------------------------------------------------------------------- 1 | sketches 2 | *~ 3 | scratch 4 | -------------------------------------------------------------------------------- /node_modules/bitsyntax/.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "0.10" 5 | - "0.8" 6 | - "0.6" 7 | - "0.11" 8 | -------------------------------------------------------------------------------- /node_modules/bitsyntax/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test all 2 | 3 | GRAMMAR=lib/grammar.pegjs 4 | PEGJS=./node_modules/.bin/pegjs 5 | 6 | all: lib/parser.js 7 | 8 | lib/parser.js: $(PEGJS) 9 | $(PEGJS) $(GRAMMAR) $@ 10 | 11 | $(PEGJS): 12 | npm install 13 | 14 | test: lib/parser.js 15 | ./node_modules/.bin/mocha --check-leaks -R list -u tdd test/*.js 16 | -------------------------------------------------------------------------------- /node_modules/bitsyntax/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports.parse = require('./lib/parse').parse; 4 | module.exports.match = require('./lib/interp').match; 5 | module.exports.build = require('./lib/constructor').build; 6 | module.exports.write = require('./lib/constructor').write; 7 | 8 | module.exports.matcher = module.exports.compile = 9 | require('./lib/compile').compile; 10 | module.exports.builder = require('./lib/compile').compile_builder; 11 | -------------------------------------------------------------------------------- /node_modules/bitsyntax/lib/constructor.js: -------------------------------------------------------------------------------- 1 | // -*- js-indent-level: 2 -*- 2 | 3 | // Constructors given patterns 4 | 5 | 'use strict'; 6 | 7 | var ints = require('buffer-more-ints'); 8 | 9 | // Interpret the pattern, writing values into a buffer 10 | function write(buf, offset, pattern, bindings) { 11 | for (var i=0, len = pattern.length; i < len; i++) { 12 | var segment = pattern[i]; 13 | 14 | switch (segment.type) { 15 | case 'string': 16 | offset += buf.write(segment.value, offset, 'utf8'); 17 | break; 18 | case 'binary': 19 | offset += writeBinary(segment, buf, offset, bindings); 20 | break; 21 | case 'integer': 22 | offset += writeInteger(segment, buf, offset, bindings); 23 | break; 24 | case 'float': 25 | offset += writeFloat(segment, buf, offset, bindings); 26 | break; 27 | } 28 | } 29 | return offset; 30 | } 31 | 32 | function build(pattern, bindings) { 33 | var bufsize = size_of(pattern, bindings); 34 | var buf = new Buffer(bufsize); 35 | write(buf, 0, pattern, bindings); 36 | return buf; 37 | } 38 | 39 | // In bytes 40 | function size_of_segment(segment, bindings) { 41 | // size refers to a variable 42 | if (typeof segment.size === 'string') { 43 | return (bindings[segment.size] * segment.unit) / 8; 44 | } 45 | if (segment.type === 'string') { 46 | return Buffer.byteLength(segment.value, 'utf8'); 47 | } 48 | if (segment.type === 'binary' && segment.size === true) { 49 | var val = bindings[segment.name]; 50 | return val.length; 51 | } 52 | return (segment.size * segment.unit) / 8; 53 | } 54 | 55 | // size of the to-be-constructed binary, in bytes 56 | function size_of(segments, bindings) { 57 | var size = 0; 58 | for (var i=0, len = segments.length; i < len; i++) { 59 | size += size_of_segment(segments[i], bindings); 60 | } 61 | return size; 62 | } 63 | 64 | function writeBinary(segment, buf, offset, bindings) { 65 | var bin = bindings[segment.name]; 66 | var size = size_of_segment(segment, bindings); 67 | bin.copy(buf, offset, 0, size); 68 | return size; 69 | } 70 | 71 | // TODO in ff might use the noAssert argument to Buffer.write*() but 72 | // need to check that it does the right thing wrt little-endian 73 | 74 | function writeInteger(segment, buf, offset, bindings) { 75 | var value = (segment.name) ? bindings[segment.name] : segment.value; 76 | var size = size_of_segment(segment, bindings); 77 | return write_int(buf, value, offset, size, segment.bigendian); 78 | } 79 | 80 | function write_int(buf, value, offset, size, bigendian) { 81 | switch (size) { 82 | case 1: 83 | buf.writeUInt8(value, offset); 84 | break; 85 | case 2: 86 | (bigendian) ? 87 | buf.writeUInt16BE(value, offset) : 88 | buf.writeUInt16LE(value, offset); 89 | break; 90 | case 4: 91 | (bigendian) ? 92 | buf.writeUInt32BE(value, offset) : 93 | buf.writeUInt32LE(value, offset); 94 | break; 95 | case 8: 96 | (bigendian) ? 97 | ints.writeUInt64BE(buf, value, offset) : 98 | ints.writeUInt64LE(buf, value, offset); 99 | break; 100 | default: 101 | throw new Error("integer size * unit must be 8, 16, 32 or 64"); 102 | } 103 | return size; 104 | } 105 | 106 | function writeFloat(segment, buf, offset, bindings) { 107 | var value = (segment.name) ? bindings[segment.name] : segment.value; 108 | var size = size_of_segment(segment, bindings); 109 | return write_float(buf, value, offset, size, segment.bigendian); 110 | } 111 | 112 | function write_float(buf, value, offset, size, bigendian) { 113 | if (size === 4) { 114 | (bigendian) ? 115 | buf.writeFloatBE(value, offset) : 116 | buf.writeFloatLE(value, offset); 117 | } 118 | else if (size === 8) { 119 | (bigendian) ? 120 | buf.writeDoubleBE(value, offset) : 121 | buf.writeDoubleLE(value, offset); 122 | } 123 | else { 124 | throw new Error("float size * unit must be 32 or 64"); 125 | } 126 | return size; 127 | } 128 | 129 | var parse = require('./parse').parse; 130 | 131 | module.exports.write = write; 132 | module.exports.build = build; 133 | module.exports.write_int = write_int; 134 | module.exports.write_float = write_float; 135 | 136 | module.exports.builder = function(pstr) { 137 | pstr = (arguments.length > 1) ? [].join.call(arguments, ',') : pstr; 138 | var pattern = parse(pstr); 139 | return function(vars) { 140 | return build(pattern, vars); 141 | }; 142 | }; 143 | -------------------------------------------------------------------------------- /node_modules/bitsyntax/lib/grammar.pegjs: -------------------------------------------------------------------------------- 1 | 2 | start 3 | = ws head:segment tail:segmentTail* { tail.unshift(head); return tail; } 4 | 5 | segmentTail 6 | = ws ',' ws seg:segment { return seg; } 7 | 8 | segment 9 | = str:string { return {string: str}; } 10 | / v:identifier size:size ? specs:specifierList ? 11 | { return {name: v, size: size, specifiers: specs}; } 12 | / v:number size:size ? specs:specifierList ? 13 | { return {value: v, size: size, specifiers: specs}; } 14 | 15 | string 16 | = '"' '"' { return ""; } 17 | / '"' chars:chars '"' { return chars; } 18 | 19 | /* From JSON example 20 | https://github.com/dmajda/pegjs/blob/master/examples/json.pegjs */ 21 | 22 | chars 23 | = chars:char+ { return chars.join(""); } 24 | 25 | char 26 | = [^"\\\0-\x1F\x7f] 27 | / '\\"' { return '"'; } 28 | / "\\\\" { return "\\"; } 29 | / "\\/" { return "/"; } 30 | / "\\b" { return "\b"; } 31 | / "\\f" { return "\f"; } 32 | / "\\n" { return "\n"; } 33 | / "\\r" { return "\r"; } 34 | / "\\t" { return "\t"; } 35 | / "\\u" h1:hexDigit h2:hexDigit h3:hexDigit h4:hexDigit { 36 | return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4)); 37 | } 38 | 39 | hexDigit 40 | = [0-9a-fA-F] 41 | 42 | identifier 43 | = (head:[_a-zA-Z] tail:[_a-zA-Z0-9]*) { return head + tail.join(''); } 44 | 45 | number 46 | = '0' { return 0; } 47 | / head:[1-9] tail:[0-9]* { return parseInt(head + tail.join('')); } 48 | 49 | size 50 | = ':' num:number { return num; } 51 | / ':' id:identifier { return id; } 52 | 53 | specifierList 54 | = '/' head:specifier tail:specifierTail* { tail.unshift(head); return tail; } 55 | 56 | specifierTail 57 | = '-' spec:specifier { return spec; } 58 | 59 | specifier 60 | = 'little' / 'big' / 'signed' / 'unsigned' 61 | / 'integer' / 'binary' / 'float' 62 | / unit 63 | 64 | unit 65 | = 'unit:' num:number { return 'unit:' + num; } 66 | 67 | ws = [ \t\n]* 68 | -------------------------------------------------------------------------------- /node_modules/bitsyntax/lib/parse.js: -------------------------------------------------------------------------------- 1 | // Parse patterns in string form into the form we use for interpreting 2 | // (and later, for compiling). 3 | 4 | 'use strict'; 5 | 6 | var ast = require('./pattern'); 7 | var parser = require('./parser'); 8 | 9 | function parse_pattern(string) { 10 | var segments = parser.parse(string); 11 | for (var i=0, len = segments.length; i < len; i++) { 12 | var s = segments[i]; 13 | if (s.string != undefined) { 14 | segments[i] = ast.string(s.string); 15 | } 16 | else if (s.value != undefined) { 17 | segments[i] = ast.value(s.value, s.size, s.specifiers); 18 | } 19 | else if (s.name != undefined) { 20 | segments[i] = ast.variable(s.name, s.size, s.specifiers); 21 | } 22 | else { 23 | throw "Unknown segment " + s; 24 | } 25 | } 26 | return segments; 27 | } 28 | 29 | module.exports.parse = function() { 30 | var str = [].join.call(arguments, ','); 31 | return parse_pattern(str); 32 | }; 33 | -------------------------------------------------------------------------------- /node_modules/bitsyntax/lib/pattern.js: -------------------------------------------------------------------------------- 1 | // -*- js-indent-level: 2 -*- 2 | // Constructing patterns 3 | 4 | 'use strict'; 5 | 6 | function set(values) { 7 | var s = {}; 8 | for (var i in values) { 9 | s[values[i]] = 1; 10 | } 11 | return s; 12 | } 13 | 14 | // Construct a segment bound to a variable, e.g., from a segment like 15 | // "Len:32/unsigned-big". `specifiers0` is an array. 16 | function variable(name, size, specifiers0) { 17 | var specifiers = set(specifiers0); 18 | var segment = {name: name}; 19 | segment.type = type_in(specifiers); 20 | specs(segment, segment.type, specifiers); 21 | segment.size = size_of(segment, segment.type, size, segment.unit); 22 | return segment; 23 | } 24 | 25 | module.exports.variable = variable; 26 | module.exports.rest = function() { 27 | return variable('_', true, ['binary']); 28 | } 29 | 30 | // Construct a segment with a literal value, e.g., from a segment like 31 | // "206". `specifiers0` is an array. 32 | 33 | function value(val, size, specifiers0) { 34 | var specifiers = set(specifiers0); 35 | var segment = {value: val}; 36 | segment.type = type_in(specifiers); 37 | // TODO check type v. value .. 38 | specs(segment, segment.type, specifiers); 39 | segment.size = size_of(segment, segment.type, size, segment.unit); 40 | return segment; 41 | } 42 | 43 | module.exports.value = value; 44 | 45 | // A string can appear as a literal, but it must appear without 46 | // specifiers. 47 | function string(val) { 48 | return {value: val, type: 'string'}; 49 | } 50 | module.exports.string = string; 51 | 52 | var TYPES = {'integer': 1, 'binary': 1, 'float': 1}; 53 | function type_in(specifiers) { 54 | for (var t in specifiers) { 55 | if (TYPES[t]) { return t; } 56 | } 57 | return 'integer'; 58 | } 59 | 60 | function specs(segment, type, specifiers) { 61 | switch (type) { 62 | case 'integer': 63 | segment.signed = signed_in(specifiers); 64 | // fall through 65 | case 'float': 66 | segment.bigendian = endian_in(specifiers); 67 | // fall through 68 | default: 69 | segment.unit = unit_in(specifiers, segment.type); 70 | } 71 | return segment; 72 | } 73 | 74 | function endian_in(specifiers) { 75 | // default is big, but I have chosen true = bigendian 76 | return !specifiers['little']; 77 | } 78 | 79 | function signed_in(specifiers) { 80 | // this time I got it right; default is unsigned 81 | return specifiers['signed']; 82 | } 83 | 84 | function unit_in(specifiers, type) { 85 | for (var s in specifiers) { 86 | if (s.substr(0, 5) == 'unit:') { 87 | var unit = parseInt(s.substr(5)); 88 | // TODO check sane for type 89 | return unit; 90 | } 91 | } 92 | // OK defaults then 93 | switch (type) { 94 | case 'binary': 95 | return 8; 96 | case 'integer': 97 | case 'float': 98 | return 1; 99 | } 100 | } 101 | 102 | function size_of(segment, type, size, unit) { 103 | if (size !== undefined && size !== '') { 104 | return size; 105 | } 106 | else { 107 | switch (type) { 108 | case 'integer': 109 | return 8; 110 | case 'float': 111 | return 64; 112 | case 'binary': 113 | return true; 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /node_modules/bitsyntax/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": { 3 | "name": "Michael Bridgen", 4 | "email": "" 5 | }, 6 | "name": "bitsyntax", 7 | "description": "Pattern-matching on byte buffers", 8 | "version": "0.0.4", 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/squaremo/bitsyntax-js.git" 12 | }, 13 | "main": "./index", 14 | "scripts": { 15 | "test": "make test", 16 | "prepublish": "make all" 17 | }, 18 | "engines": { 19 | "node": ">=0.6" 20 | }, 21 | "dependencies": { 22 | "buffer-more-ints": "0.0.2" 23 | }, 24 | "devDependencies": { 25 | "pegjs": "0.7.x", 26 | "mocha": "1.x" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /node_modules/bitsyntax/test/consing.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var parse = require('../').parse; 3 | var build = require('../').build; 4 | var builder = require('../').builder; 5 | var write = require('../').write; 6 | 7 | TEST_CASES = [ 8 | ['n:8', {n:255}, [255]], 9 | ['n:16', {n: 0xf0f0}, [240, 240]], 10 | ['n:32', {n: 0x12345678}, [18,52,86,120]], 11 | ['n:64', {n: 0xffffffffffffffff}, [255,255,255,255,255,255,255,255]], 12 | 13 | ['n:8, s/binary', {n: 255, s: new Buffer("foobar")}, [255, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72]], 14 | ['n:8, "foobar", m:8', {n: 255, m:0}, [255, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72, 0]], 15 | ['n:8, s:n/binary', {n:6, s: new Buffer('foobar')}, [6, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72]], 16 | ['n:8, s:n/binary', {n:4, s: new Buffer('foobar')}, [4, 0x66, 0x6f, 0x6f, 0x62]], 17 | ['n:size', {n:4, size:8}, [4]], 18 | ['206:n/unit:8', {n:1}, [206]] 19 | ]; 20 | 21 | function bufferToArray(buf) { 22 | return Array.prototype.slice.call(buf); 23 | } 24 | 25 | suite("Construction", function() { 26 | TEST_CASES.forEach(function(c) { 27 | var p = parse(c[0]); 28 | test(c[0], function() { 29 | assert.deepEqual(c[2], bufferToArray(build(p, c[1]))); 30 | }); 31 | test(c[0], function() { 32 | var buf = new Buffer(1024); 33 | var end = write(buf, 7, p, c[1]); 34 | buf = buf.slice(7, end); 35 | assert.deepEqual(c[2], bufferToArray(buf)); 36 | }); 37 | test(c[0], function() { 38 | var cons = builder(c[0]); 39 | var buf = cons(c[1]); 40 | assert.deepEqual(c[2], bufferToArray(buf)); 41 | }); 42 | 43 | }); 44 | 45 | }); 46 | -------------------------------------------------------------------------------- /node_modules/bluebird/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2017 Petka Antonov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /node_modules/bluebird/README.md: -------------------------------------------------------------------------------- 1 | 2 | Promises/A+ logo 4 | 5 | 6 | [![Build Status](https://travis-ci.org/petkaantonov/bluebird.svg?branch=master)](https://travis-ci.org/petkaantonov/bluebird) 7 | [![coverage-98%](https://img.shields.io/badge/coverage-98%25-brightgreen.svg?style=flat)](http://petkaantonov.github.io/bluebird/coverage/debug/index.html) 8 | 9 | **Got a question?** Join us on [stackoverflow](http://stackoverflow.com/questions/tagged/bluebird), the [mailing list](https://groups.google.com/forum/#!forum/bluebird-js) or chat on [IRC](https://webchat.freenode.net/?channels=#promises) 10 | 11 | # Introduction 12 | 13 | Bluebird is a fully featured promise library with focus on innovative features and performance 14 | 15 | See the [**bluebird website**](http://bluebirdjs.com/docs/getting-started.html) for further documentation, references and instructions. See the [**API reference**](http://bluebirdjs.com/docs/api-reference.html) here. 16 | 17 | For bluebird 2.x documentation and files, see the [2.x tree](https://github.com/petkaantonov/bluebird/tree/2.x). 18 | 19 | # Questions and issues 20 | 21 | The [github issue tracker](https://github.com/petkaantonov/bluebird/issues) is **_only_** for bug reports and feature requests. Anything else, such as questions for help in using the library, should be posted in [StackOverflow](http://stackoverflow.com/questions/tagged/bluebird) under tags `promise` and `bluebird`. 22 | 23 | 24 | 25 | ## Thanks 26 | 27 | Thanks to BrowserStack for providing us with a free account which lets us support old browsers like IE8. 28 | 29 | # License 30 | 31 | The MIT License (MIT) 32 | 33 | Copyright (c) 2013-2017 Petka Antonov 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in 43 | all copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | THE SOFTWARE. 52 | 53 | -------------------------------------------------------------------------------- /node_modules/bluebird/changelog.md: -------------------------------------------------------------------------------- 1 | [http://bluebirdjs.com/docs/changelog.html](http://bluebirdjs.com/docs/changelog.html) 2 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/any.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise) { 3 | var SomePromiseArray = Promise._SomePromiseArray; 4 | function any(promises) { 5 | var ret = new SomePromiseArray(promises); 6 | var promise = ret.promise(); 7 | ret.setHowMany(1); 8 | ret.setUnwrap(); 9 | ret.init(); 10 | return promise; 11 | } 12 | 13 | Promise.any = function (promises) { 14 | return any(promises); 15 | }; 16 | 17 | Promise.prototype.any = function () { 18 | return any(this); 19 | }; 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/assert.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = (function(){ 3 | var AssertionError = (function() { 4 | function AssertionError(a) { 5 | this.constructor$(a); 6 | this.message = a; 7 | this.name = "AssertionError"; 8 | } 9 | AssertionError.prototype = new Error(); 10 | AssertionError.prototype.constructor = AssertionError; 11 | AssertionError.prototype.constructor$ = Error; 12 | return AssertionError; 13 | })(); 14 | 15 | function getParams(args) { 16 | var params = []; 17 | for (var i = 0; i < args.length; ++i) params.push("arg" + i); 18 | return params; 19 | } 20 | 21 | function nativeAssert(callName, args, expect) { 22 | try { 23 | var params = getParams(args); 24 | var constructorArgs = params; 25 | constructorArgs.push("return " + 26 | callName + "("+ params.join(",") + ");"); 27 | var fn = Function.apply(null, constructorArgs); 28 | return fn.apply(null, args); 29 | } catch (e) { 30 | if (!(e instanceof SyntaxError)) { 31 | throw e; 32 | } else { 33 | return expect; 34 | } 35 | } 36 | } 37 | 38 | return function assert(boolExpr, message) { 39 | if (boolExpr === true) return; 40 | 41 | if (typeof boolExpr === "string" && 42 | boolExpr.charAt(0) === "%") { 43 | var nativeCallName = boolExpr; 44 | var $_len = arguments.length;var args = new Array(Math.max($_len - 2, 0)); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];}; 45 | if (nativeAssert(nativeCallName, args, message) === message) return; 46 | message = (nativeCallName + " !== " + message); 47 | } 48 | 49 | var ret = new AssertionError(message); 50 | if (Error.captureStackTrace) { 51 | Error.captureStackTrace(ret, assert); 52 | } 53 | throw ret; 54 | }; 55 | })(); 56 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/async.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var firstLineError; 3 | try {throw new Error(); } catch (e) {firstLineError = e;} 4 | var schedule = require("./schedule"); 5 | var Queue = require("./queue"); 6 | var util = require("./util"); 7 | 8 | function Async() { 9 | this._customScheduler = false; 10 | this._isTickUsed = false; 11 | this._lateQueue = new Queue(16); 12 | this._normalQueue = new Queue(16); 13 | this._haveDrainedQueues = false; 14 | this._trampolineEnabled = true; 15 | var self = this; 16 | this.drainQueues = function () { 17 | self._drainQueues(); 18 | }; 19 | this._schedule = schedule; 20 | } 21 | 22 | Async.prototype.setScheduler = function(fn) { 23 | var prev = this._schedule; 24 | this._schedule = fn; 25 | this._customScheduler = true; 26 | return prev; 27 | }; 28 | 29 | Async.prototype.hasCustomScheduler = function() { 30 | return this._customScheduler; 31 | }; 32 | 33 | Async.prototype.enableTrampoline = function() { 34 | this._trampolineEnabled = true; 35 | }; 36 | 37 | Async.prototype.disableTrampolineIfNecessary = function() { 38 | if (util.hasDevTools) { 39 | this._trampolineEnabled = false; 40 | } 41 | }; 42 | 43 | Async.prototype.haveItemsQueued = function () { 44 | return this._isTickUsed || this._haveDrainedQueues; 45 | }; 46 | 47 | 48 | Async.prototype.fatalError = function(e, isNode) { 49 | if (isNode) { 50 | process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e) + 51 | "\n"); 52 | process.exit(2); 53 | } else { 54 | this.throwLater(e); 55 | } 56 | }; 57 | 58 | Async.prototype.throwLater = function(fn, arg) { 59 | if (arguments.length === 1) { 60 | arg = fn; 61 | fn = function () { throw arg; }; 62 | } 63 | if (typeof setTimeout !== "undefined") { 64 | setTimeout(function() { 65 | fn(arg); 66 | }, 0); 67 | } else try { 68 | this._schedule(function() { 69 | fn(arg); 70 | }); 71 | } catch (e) { 72 | throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 73 | } 74 | }; 75 | 76 | function AsyncInvokeLater(fn, receiver, arg) { 77 | this._lateQueue.push(fn, receiver, arg); 78 | this._queueTick(); 79 | } 80 | 81 | function AsyncInvoke(fn, receiver, arg) { 82 | this._normalQueue.push(fn, receiver, arg); 83 | this._queueTick(); 84 | } 85 | 86 | function AsyncSettlePromises(promise) { 87 | this._normalQueue._pushOne(promise); 88 | this._queueTick(); 89 | } 90 | 91 | if (!util.hasDevTools) { 92 | Async.prototype.invokeLater = AsyncInvokeLater; 93 | Async.prototype.invoke = AsyncInvoke; 94 | Async.prototype.settlePromises = AsyncSettlePromises; 95 | } else { 96 | Async.prototype.invokeLater = function (fn, receiver, arg) { 97 | if (this._trampolineEnabled) { 98 | AsyncInvokeLater.call(this, fn, receiver, arg); 99 | } else { 100 | this._schedule(function() { 101 | setTimeout(function() { 102 | fn.call(receiver, arg); 103 | }, 100); 104 | }); 105 | } 106 | }; 107 | 108 | Async.prototype.invoke = function (fn, receiver, arg) { 109 | if (this._trampolineEnabled) { 110 | AsyncInvoke.call(this, fn, receiver, arg); 111 | } else { 112 | this._schedule(function() { 113 | fn.call(receiver, arg); 114 | }); 115 | } 116 | }; 117 | 118 | Async.prototype.settlePromises = function(promise) { 119 | if (this._trampolineEnabled) { 120 | AsyncSettlePromises.call(this, promise); 121 | } else { 122 | this._schedule(function() { 123 | promise._settlePromises(); 124 | }); 125 | } 126 | }; 127 | } 128 | 129 | Async.prototype._drainQueue = function(queue) { 130 | while (queue.length() > 0) { 131 | var fn = queue.shift(); 132 | if (typeof fn !== "function") { 133 | fn._settlePromises(); 134 | continue; 135 | } 136 | var receiver = queue.shift(); 137 | var arg = queue.shift(); 138 | fn.call(receiver, arg); 139 | } 140 | }; 141 | 142 | Async.prototype._drainQueues = function () { 143 | this._drainQueue(this._normalQueue); 144 | this._reset(); 145 | this._haveDrainedQueues = true; 146 | this._drainQueue(this._lateQueue); 147 | }; 148 | 149 | Async.prototype._queueTick = function () { 150 | if (!this._isTickUsed) { 151 | this._isTickUsed = true; 152 | this._schedule(this.drainQueues); 153 | } 154 | }; 155 | 156 | Async.prototype._reset = function () { 157 | this._isTickUsed = false; 158 | }; 159 | 160 | module.exports = Async; 161 | module.exports.firstLineError = firstLineError; 162 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/bind.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) { 3 | var calledBind = false; 4 | var rejectThis = function(_, e) { 5 | this._reject(e); 6 | }; 7 | 8 | var targetRejected = function(e, context) { 9 | context.promiseRejectionQueued = true; 10 | context.bindingPromise._then(rejectThis, rejectThis, null, this, e); 11 | }; 12 | 13 | var bindingResolved = function(thisArg, context) { 14 | if (((this._bitField & 50397184) === 0)) { 15 | this._resolveCallback(context.target); 16 | } 17 | }; 18 | 19 | var bindingRejected = function(e, context) { 20 | if (!context.promiseRejectionQueued) this._reject(e); 21 | }; 22 | 23 | Promise.prototype.bind = function (thisArg) { 24 | if (!calledBind) { 25 | calledBind = true; 26 | Promise.prototype._propagateFrom = debug.propagateFromFunction(); 27 | Promise.prototype._boundValue = debug.boundValueFunction(); 28 | } 29 | var maybePromise = tryConvertToPromise(thisArg); 30 | var ret = new Promise(INTERNAL); 31 | ret._propagateFrom(this, 1); 32 | var target = this._target(); 33 | ret._setBoundTo(maybePromise); 34 | if (maybePromise instanceof Promise) { 35 | var context = { 36 | promiseRejectionQueued: false, 37 | promise: ret, 38 | target: target, 39 | bindingPromise: maybePromise 40 | }; 41 | target._then(INTERNAL, targetRejected, undefined, ret, context); 42 | maybePromise._then( 43 | bindingResolved, bindingRejected, undefined, ret, context); 44 | ret._setOnCancel(maybePromise); 45 | } else { 46 | ret._resolveCallback(target); 47 | } 48 | return ret; 49 | }; 50 | 51 | Promise.prototype._setBoundTo = function (obj) { 52 | if (obj !== undefined) { 53 | this._bitField = this._bitField | 2097152; 54 | this._boundTo = obj; 55 | } else { 56 | this._bitField = this._bitField & (~2097152); 57 | } 58 | }; 59 | 60 | Promise.prototype._isBound = function () { 61 | return (this._bitField & 2097152) === 2097152; 62 | }; 63 | 64 | Promise.bind = function (thisArg, value) { 65 | return Promise.resolve(value).bind(thisArg); 66 | }; 67 | }; 68 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/bluebird.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var old; 3 | if (typeof Promise !== "undefined") old = Promise; 4 | function noConflict() { 5 | try { if (Promise === bluebird) Promise = old; } 6 | catch (e) {} 7 | return bluebird; 8 | } 9 | var bluebird = require("./promise")(); 10 | bluebird.noConflict = noConflict; 11 | module.exports = bluebird; 12 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/call_get.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var cr = Object.create; 3 | if (cr) { 4 | var callerCache = cr(null); 5 | var getterCache = cr(null); 6 | callerCache[" size"] = getterCache[" size"] = 0; 7 | } 8 | 9 | module.exports = function(Promise) { 10 | var util = require("./util"); 11 | var canEvaluate = util.canEvaluate; 12 | var isIdentifier = util.isIdentifier; 13 | 14 | var getMethodCaller; 15 | var getGetter; 16 | if (!false) { 17 | var makeMethodCaller = function (methodName) { 18 | return new Function("ensureMethod", " \n\ 19 | return function(obj) { \n\ 20 | 'use strict' \n\ 21 | var len = this.length; \n\ 22 | ensureMethod(obj, 'methodName'); \n\ 23 | switch(len) { \n\ 24 | case 1: return obj.methodName(this[0]); \n\ 25 | case 2: return obj.methodName(this[0], this[1]); \n\ 26 | case 3: return obj.methodName(this[0], this[1], this[2]); \n\ 27 | case 0: return obj.methodName(); \n\ 28 | default: \n\ 29 | return obj.methodName.apply(obj, this); \n\ 30 | } \n\ 31 | }; \n\ 32 | ".replace(/methodName/g, methodName))(ensureMethod); 33 | }; 34 | 35 | var makeGetter = function (propertyName) { 36 | return new Function("obj", " \n\ 37 | 'use strict'; \n\ 38 | return obj.propertyName; \n\ 39 | ".replace("propertyName", propertyName)); 40 | }; 41 | 42 | var getCompiled = function(name, compiler, cache) { 43 | var ret = cache[name]; 44 | if (typeof ret !== "function") { 45 | if (!isIdentifier(name)) { 46 | return null; 47 | } 48 | ret = compiler(name); 49 | cache[name] = ret; 50 | cache[" size"]++; 51 | if (cache[" size"] > 512) { 52 | var keys = Object.keys(cache); 53 | for (var i = 0; i < 256; ++i) delete cache[keys[i]]; 54 | cache[" size"] = keys.length - 256; 55 | } 56 | } 57 | return ret; 58 | }; 59 | 60 | getMethodCaller = function(name) { 61 | return getCompiled(name, makeMethodCaller, callerCache); 62 | }; 63 | 64 | getGetter = function(name) { 65 | return getCompiled(name, makeGetter, getterCache); 66 | }; 67 | } 68 | 69 | function ensureMethod(obj, methodName) { 70 | var fn; 71 | if (obj != null) fn = obj[methodName]; 72 | if (typeof fn !== "function") { 73 | var message = "Object " + util.classString(obj) + " has no method '" + 74 | util.toString(methodName) + "'"; 75 | throw new Promise.TypeError(message); 76 | } 77 | return fn; 78 | } 79 | 80 | function caller(obj) { 81 | var methodName = this.pop(); 82 | var fn = ensureMethod(obj, methodName); 83 | return fn.apply(obj, this); 84 | } 85 | Promise.prototype.call = function (methodName) { 86 | var $_len = arguments.length;var args = new Array(Math.max($_len - 1, 0)); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}; 87 | if (!false) { 88 | if (canEvaluate) { 89 | var maybeCaller = getMethodCaller(methodName); 90 | if (maybeCaller !== null) { 91 | return this._then( 92 | maybeCaller, undefined, undefined, args, undefined); 93 | } 94 | } 95 | } 96 | args.push(methodName); 97 | return this._then(caller, undefined, undefined, args, undefined); 98 | }; 99 | 100 | function namedGetter(obj) { 101 | return obj[this]; 102 | } 103 | function indexedGetter(obj) { 104 | var index = +this; 105 | if (index < 0) index = Math.max(0, index + obj.length); 106 | return obj[index]; 107 | } 108 | Promise.prototype.get = function (propertyName) { 109 | var isIndex = (typeof propertyName === "number"); 110 | var getter; 111 | if (!isIndex) { 112 | if (canEvaluate) { 113 | var maybeGetter = getGetter(propertyName); 114 | getter = maybeGetter !== null ? maybeGetter : namedGetter; 115 | } else { 116 | getter = namedGetter; 117 | } 118 | } else { 119 | getter = indexedGetter; 120 | } 121 | return this._then(getter, undefined, undefined, propertyName, undefined); 122 | }; 123 | }; 124 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/cancel.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise, PromiseArray, apiRejection, debug) { 3 | var util = require("./util"); 4 | var tryCatch = util.tryCatch; 5 | var errorObj = util.errorObj; 6 | var async = Promise._async; 7 | 8 | Promise.prototype["break"] = Promise.prototype.cancel = function() { 9 | if (!debug.cancellation()) return this._warn("cancellation is disabled"); 10 | 11 | var promise = this; 12 | var child = promise; 13 | while (promise._isCancellable()) { 14 | if (!promise._cancelBy(child)) { 15 | if (child._isFollowing()) { 16 | child._followee().cancel(); 17 | } else { 18 | child._cancelBranched(); 19 | } 20 | break; 21 | } 22 | 23 | var parent = promise._cancellationParent; 24 | if (parent == null || !parent._isCancellable()) { 25 | if (promise._isFollowing()) { 26 | promise._followee().cancel(); 27 | } else { 28 | promise._cancelBranched(); 29 | } 30 | break; 31 | } else { 32 | if (promise._isFollowing()) promise._followee().cancel(); 33 | promise._setWillBeCancelled(); 34 | child = promise; 35 | promise = parent; 36 | } 37 | } 38 | }; 39 | 40 | Promise.prototype._branchHasCancelled = function() { 41 | this._branchesRemainingToCancel--; 42 | }; 43 | 44 | Promise.prototype._enoughBranchesHaveCancelled = function() { 45 | return this._branchesRemainingToCancel === undefined || 46 | this._branchesRemainingToCancel <= 0; 47 | }; 48 | 49 | Promise.prototype._cancelBy = function(canceller) { 50 | if (canceller === this) { 51 | this._branchesRemainingToCancel = 0; 52 | this._invokeOnCancel(); 53 | return true; 54 | } else { 55 | this._branchHasCancelled(); 56 | if (this._enoughBranchesHaveCancelled()) { 57 | this._invokeOnCancel(); 58 | return true; 59 | } 60 | } 61 | return false; 62 | }; 63 | 64 | Promise.prototype._cancelBranched = function() { 65 | if (this._enoughBranchesHaveCancelled()) { 66 | this._cancel(); 67 | } 68 | }; 69 | 70 | Promise.prototype._cancel = function() { 71 | if (!this._isCancellable()) return; 72 | this._setCancelled(); 73 | async.invoke(this._cancelPromises, this, undefined); 74 | }; 75 | 76 | Promise.prototype._cancelPromises = function() { 77 | if (this._length() > 0) this._settlePromises(); 78 | }; 79 | 80 | Promise.prototype._unsetOnCancel = function() { 81 | this._onCancelField = undefined; 82 | }; 83 | 84 | Promise.prototype._isCancellable = function() { 85 | return this.isPending() && !this._isCancelled(); 86 | }; 87 | 88 | Promise.prototype.isCancellable = function() { 89 | return this.isPending() && !this.isCancelled(); 90 | }; 91 | 92 | Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) { 93 | if (util.isArray(onCancelCallback)) { 94 | for (var i = 0; i < onCancelCallback.length; ++i) { 95 | this._doInvokeOnCancel(onCancelCallback[i], internalOnly); 96 | } 97 | } else if (onCancelCallback !== undefined) { 98 | if (typeof onCancelCallback === "function") { 99 | if (!internalOnly) { 100 | var e = tryCatch(onCancelCallback).call(this._boundValue()); 101 | if (e === errorObj) { 102 | this._attachExtraTrace(e.e); 103 | async.throwLater(e.e); 104 | } 105 | } 106 | } else { 107 | onCancelCallback._resultCancelled(this); 108 | } 109 | } 110 | }; 111 | 112 | Promise.prototype._invokeOnCancel = function() { 113 | var onCancelCallback = this._onCancel(); 114 | this._unsetOnCancel(); 115 | async.invoke(this._doInvokeOnCancel, this, onCancelCallback); 116 | }; 117 | 118 | Promise.prototype._invokeInternalOnCancel = function() { 119 | if (this._isCancellable()) { 120 | this._doInvokeOnCancel(this._onCancel(), true); 121 | this._unsetOnCancel(); 122 | } 123 | }; 124 | 125 | Promise.prototype._resultCancelled = function() { 126 | this.cancel(); 127 | }; 128 | 129 | }; 130 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/catch_filter.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(NEXT_FILTER) { 3 | var util = require("./util"); 4 | var getKeys = require("./es5").keys; 5 | var tryCatch = util.tryCatch; 6 | var errorObj = util.errorObj; 7 | 8 | function catchFilter(instances, cb, promise) { 9 | return function(e) { 10 | var boundTo = promise._boundValue(); 11 | predicateLoop: for (var i = 0; i < instances.length; ++i) { 12 | var item = instances[i]; 13 | 14 | if (item === Error || 15 | (item != null && item.prototype instanceof Error)) { 16 | if (e instanceof item) { 17 | return tryCatch(cb).call(boundTo, e); 18 | } 19 | } else if (typeof item === "function") { 20 | var matchesPredicate = tryCatch(item).call(boundTo, e); 21 | if (matchesPredicate === errorObj) { 22 | return matchesPredicate; 23 | } else if (matchesPredicate) { 24 | return tryCatch(cb).call(boundTo, e); 25 | } 26 | } else if (util.isObject(e)) { 27 | var keys = getKeys(item); 28 | for (var j = 0; j < keys.length; ++j) { 29 | var key = keys[j]; 30 | if (item[key] != e[key]) { 31 | continue predicateLoop; 32 | } 33 | } 34 | return tryCatch(cb).call(boundTo, e); 35 | } 36 | } 37 | return NEXT_FILTER; 38 | }; 39 | } 40 | 41 | return catchFilter; 42 | }; 43 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/context.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise) { 3 | var longStackTraces = false; 4 | var contextStack = []; 5 | 6 | Promise.prototype._promiseCreated = function() {}; 7 | Promise.prototype._pushContext = function() {}; 8 | Promise.prototype._popContext = function() {return null;}; 9 | Promise._peekContext = Promise.prototype._peekContext = function() {}; 10 | 11 | function Context() { 12 | this._trace = new Context.CapturedTrace(peekContext()); 13 | } 14 | Context.prototype._pushContext = function () { 15 | if (this._trace !== undefined) { 16 | this._trace._promiseCreated = null; 17 | contextStack.push(this._trace); 18 | } 19 | }; 20 | 21 | Context.prototype._popContext = function () { 22 | if (this._trace !== undefined) { 23 | var trace = contextStack.pop(); 24 | var ret = trace._promiseCreated; 25 | trace._promiseCreated = null; 26 | return ret; 27 | } 28 | return null; 29 | }; 30 | 31 | function createContext() { 32 | if (longStackTraces) return new Context(); 33 | } 34 | 35 | function peekContext() { 36 | var lastIndex = contextStack.length - 1; 37 | if (lastIndex >= 0) { 38 | return contextStack[lastIndex]; 39 | } 40 | return undefined; 41 | } 42 | Context.CapturedTrace = null; 43 | Context.create = createContext; 44 | Context.deactivateLongStackTraces = function() {}; 45 | Context.activateLongStackTraces = function() { 46 | var Promise_pushContext = Promise.prototype._pushContext; 47 | var Promise_popContext = Promise.prototype._popContext; 48 | var Promise_PeekContext = Promise._peekContext; 49 | var Promise_peekContext = Promise.prototype._peekContext; 50 | var Promise_promiseCreated = Promise.prototype._promiseCreated; 51 | Context.deactivateLongStackTraces = function() { 52 | Promise.prototype._pushContext = Promise_pushContext; 53 | Promise.prototype._popContext = Promise_popContext; 54 | Promise._peekContext = Promise_PeekContext; 55 | Promise.prototype._peekContext = Promise_peekContext; 56 | Promise.prototype._promiseCreated = Promise_promiseCreated; 57 | longStackTraces = false; 58 | }; 59 | longStackTraces = true; 60 | Promise.prototype._pushContext = Context.prototype._pushContext; 61 | Promise.prototype._popContext = Context.prototype._popContext; 62 | Promise._peekContext = Promise.prototype._peekContext = peekContext; 63 | Promise.prototype._promiseCreated = function() { 64 | var ctx = this._peekContext(); 65 | if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this; 66 | }; 67 | }; 68 | return Context; 69 | }; 70 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/direct_resolve.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise) { 3 | function returner() { 4 | return this.value; 5 | } 6 | function thrower() { 7 | throw this.reason; 8 | } 9 | 10 | Promise.prototype["return"] = 11 | Promise.prototype.thenReturn = function (value) { 12 | if (value instanceof Promise) value.suppressUnhandledRejections(); 13 | return this._then( 14 | returner, undefined, undefined, {value: value}, undefined); 15 | }; 16 | 17 | Promise.prototype["throw"] = 18 | Promise.prototype.thenThrow = function (reason) { 19 | return this._then( 20 | thrower, undefined, undefined, {reason: reason}, undefined); 21 | }; 22 | 23 | Promise.prototype.catchThrow = function (reason) { 24 | if (arguments.length <= 1) { 25 | return this._then( 26 | undefined, thrower, undefined, {reason: reason}, undefined); 27 | } else { 28 | var _reason = arguments[1]; 29 | var handler = function() {throw _reason;}; 30 | return this.caught(reason, handler); 31 | } 32 | }; 33 | 34 | Promise.prototype.catchReturn = function (value) { 35 | if (arguments.length <= 1) { 36 | if (value instanceof Promise) value.suppressUnhandledRejections(); 37 | return this._then( 38 | undefined, returner, undefined, {value: value}, undefined); 39 | } else { 40 | var _value = arguments[1]; 41 | if (_value instanceof Promise) _value.suppressUnhandledRejections(); 42 | var handler = function() {return _value;}; 43 | return this.caught(value, handler); 44 | } 45 | }; 46 | }; 47 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/each.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise, INTERNAL) { 3 | var PromiseReduce = Promise.reduce; 4 | var PromiseAll = Promise.all; 5 | 6 | function promiseAllThis() { 7 | return PromiseAll(this); 8 | } 9 | 10 | function PromiseMapSeries(promises, fn) { 11 | return PromiseReduce(promises, fn, INTERNAL, INTERNAL); 12 | } 13 | 14 | Promise.prototype.each = function (fn) { 15 | return PromiseReduce(this, fn, INTERNAL, 0) 16 | ._then(promiseAllThis, undefined, undefined, this, undefined); 17 | }; 18 | 19 | Promise.prototype.mapSeries = function (fn) { 20 | return PromiseReduce(this, fn, INTERNAL, INTERNAL); 21 | }; 22 | 23 | Promise.each = function (promises, fn) { 24 | return PromiseReduce(promises, fn, INTERNAL, 0) 25 | ._then(promiseAllThis, undefined, undefined, promises, undefined); 26 | }; 27 | 28 | Promise.mapSeries = PromiseMapSeries; 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/errors.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var es5 = require("./es5"); 3 | var Objectfreeze = es5.freeze; 4 | var util = require("./util"); 5 | var inherits = util.inherits; 6 | var notEnumerableProp = util.notEnumerableProp; 7 | 8 | function subError(nameProperty, defaultMessage) { 9 | function SubError(message) { 10 | if (!(this instanceof SubError)) return new SubError(message); 11 | notEnumerableProp(this, "message", 12 | typeof message === "string" ? message : defaultMessage); 13 | notEnumerableProp(this, "name", nameProperty); 14 | if (Error.captureStackTrace) { 15 | Error.captureStackTrace(this, this.constructor); 16 | } else { 17 | Error.call(this); 18 | } 19 | } 20 | inherits(SubError, Error); 21 | return SubError; 22 | } 23 | 24 | var _TypeError, _RangeError; 25 | var Warning = subError("Warning", "warning"); 26 | var CancellationError = subError("CancellationError", "cancellation error"); 27 | var TimeoutError = subError("TimeoutError", "timeout error"); 28 | var AggregateError = subError("AggregateError", "aggregate error"); 29 | try { 30 | _TypeError = TypeError; 31 | _RangeError = RangeError; 32 | } catch(e) { 33 | _TypeError = subError("TypeError", "type error"); 34 | _RangeError = subError("RangeError", "range error"); 35 | } 36 | 37 | var methods = ("join pop push shift unshift slice filter forEach some " + 38 | "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" "); 39 | 40 | for (var i = 0; i < methods.length; ++i) { 41 | if (typeof Array.prototype[methods[i]] === "function") { 42 | AggregateError.prototype[methods[i]] = Array.prototype[methods[i]]; 43 | } 44 | } 45 | 46 | es5.defineProperty(AggregateError.prototype, "length", { 47 | value: 0, 48 | configurable: false, 49 | writable: true, 50 | enumerable: true 51 | }); 52 | AggregateError.prototype["isOperational"] = true; 53 | var level = 0; 54 | AggregateError.prototype.toString = function() { 55 | var indent = Array(level * 4 + 1).join(" "); 56 | var ret = "\n" + indent + "AggregateError of:" + "\n"; 57 | level++; 58 | indent = Array(level * 4 + 1).join(" "); 59 | for (var i = 0; i < this.length; ++i) { 60 | var str = this[i] === this ? "[Circular AggregateError]" : this[i] + ""; 61 | var lines = str.split("\n"); 62 | for (var j = 0; j < lines.length; ++j) { 63 | lines[j] = indent + lines[j]; 64 | } 65 | str = lines.join("\n"); 66 | ret += str + "\n"; 67 | } 68 | level--; 69 | return ret; 70 | }; 71 | 72 | function OperationalError(message) { 73 | if (!(this instanceof OperationalError)) 74 | return new OperationalError(message); 75 | notEnumerableProp(this, "name", "OperationalError"); 76 | notEnumerableProp(this, "message", message); 77 | this.cause = message; 78 | this["isOperational"] = true; 79 | 80 | if (message instanceof Error) { 81 | notEnumerableProp(this, "message", message.message); 82 | notEnumerableProp(this, "stack", message.stack); 83 | } else if (Error.captureStackTrace) { 84 | Error.captureStackTrace(this, this.constructor); 85 | } 86 | 87 | } 88 | inherits(OperationalError, Error); 89 | 90 | var errorTypes = Error["__BluebirdErrorTypes__"]; 91 | if (!errorTypes) { 92 | errorTypes = Objectfreeze({ 93 | CancellationError: CancellationError, 94 | TimeoutError: TimeoutError, 95 | OperationalError: OperationalError, 96 | RejectionError: OperationalError, 97 | AggregateError: AggregateError 98 | }); 99 | es5.defineProperty(Error, "__BluebirdErrorTypes__", { 100 | value: errorTypes, 101 | writable: false, 102 | enumerable: false, 103 | configurable: false 104 | }); 105 | } 106 | 107 | module.exports = { 108 | Error: Error, 109 | TypeError: _TypeError, 110 | RangeError: _RangeError, 111 | CancellationError: errorTypes.CancellationError, 112 | OperationalError: errorTypes.OperationalError, 113 | TimeoutError: errorTypes.TimeoutError, 114 | AggregateError: errorTypes.AggregateError, 115 | Warning: Warning 116 | }; 117 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/es5.js: -------------------------------------------------------------------------------- 1 | var isES5 = (function(){ 2 | "use strict"; 3 | return this === undefined; 4 | })(); 5 | 6 | if (isES5) { 7 | module.exports = { 8 | freeze: Object.freeze, 9 | defineProperty: Object.defineProperty, 10 | getDescriptor: Object.getOwnPropertyDescriptor, 11 | keys: Object.keys, 12 | names: Object.getOwnPropertyNames, 13 | getPrototypeOf: Object.getPrototypeOf, 14 | isArray: Array.isArray, 15 | isES5: isES5, 16 | propertyIsWritable: function(obj, prop) { 17 | var descriptor = Object.getOwnPropertyDescriptor(obj, prop); 18 | return !!(!descriptor || descriptor.writable || descriptor.set); 19 | } 20 | }; 21 | } else { 22 | var has = {}.hasOwnProperty; 23 | var str = {}.toString; 24 | var proto = {}.constructor.prototype; 25 | 26 | var ObjectKeys = function (o) { 27 | var ret = []; 28 | for (var key in o) { 29 | if (has.call(o, key)) { 30 | ret.push(key); 31 | } 32 | } 33 | return ret; 34 | }; 35 | 36 | var ObjectGetDescriptor = function(o, key) { 37 | return {value: o[key]}; 38 | }; 39 | 40 | var ObjectDefineProperty = function (o, key, desc) { 41 | o[key] = desc.value; 42 | return o; 43 | }; 44 | 45 | var ObjectFreeze = function (obj) { 46 | return obj; 47 | }; 48 | 49 | var ObjectGetPrototypeOf = function (obj) { 50 | try { 51 | return Object(obj).constructor.prototype; 52 | } 53 | catch (e) { 54 | return proto; 55 | } 56 | }; 57 | 58 | var ArrayIsArray = function (obj) { 59 | try { 60 | return str.call(obj) === "[object Array]"; 61 | } 62 | catch(e) { 63 | return false; 64 | } 65 | }; 66 | 67 | module.exports = { 68 | isArray: ArrayIsArray, 69 | keys: ObjectKeys, 70 | names: ObjectKeys, 71 | defineProperty: ObjectDefineProperty, 72 | getDescriptor: ObjectGetDescriptor, 73 | freeze: ObjectFreeze, 74 | getPrototypeOf: ObjectGetPrototypeOf, 75 | isES5: isES5, 76 | propertyIsWritable: function() { 77 | return true; 78 | } 79 | }; 80 | } 81 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/filter.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise, INTERNAL) { 3 | var PromiseMap = Promise.map; 4 | 5 | Promise.prototype.filter = function (fn, options) { 6 | return PromiseMap(this, fn, options, INTERNAL); 7 | }; 8 | 9 | Promise.filter = function (promises, fn, options) { 10 | return PromiseMap(promises, fn, options, INTERNAL); 11 | }; 12 | }; 13 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/method.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = 3 | function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) { 4 | var util = require("./util"); 5 | var tryCatch = util.tryCatch; 6 | 7 | Promise.method = function (fn) { 8 | if (typeof fn !== "function") { 9 | throw new Promise.TypeError("expecting a function but got " + util.classString(fn)); 10 | } 11 | return function () { 12 | var ret = new Promise(INTERNAL); 13 | ret._captureStackTrace(); 14 | ret._pushContext(); 15 | var value = tryCatch(fn).apply(this, arguments); 16 | var promiseCreated = ret._popContext(); 17 | debug.checkForgottenReturns( 18 | value, promiseCreated, "Promise.method", ret); 19 | ret._resolveFromSyncValue(value); 20 | return ret; 21 | }; 22 | }; 23 | 24 | Promise.attempt = Promise["try"] = function (fn) { 25 | if (typeof fn !== "function") { 26 | return apiRejection("expecting a function but got " + util.classString(fn)); 27 | } 28 | var ret = new Promise(INTERNAL); 29 | ret._captureStackTrace(); 30 | ret._pushContext(); 31 | var value; 32 | if (arguments.length > 1) { 33 | debug.deprecated("calling Promise.try with more than 1 argument"); 34 | var arg = arguments[1]; 35 | var ctx = arguments[2]; 36 | value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg) 37 | : tryCatch(fn).call(ctx, arg); 38 | } else { 39 | value = tryCatch(fn)(); 40 | } 41 | var promiseCreated = ret._popContext(); 42 | debug.checkForgottenReturns( 43 | value, promiseCreated, "Promise.try", ret); 44 | ret._resolveFromSyncValue(value); 45 | return ret; 46 | }; 47 | 48 | Promise.prototype._resolveFromSyncValue = function (value) { 49 | if (value === util.errorObj) { 50 | this._rejectCallback(value.e, false); 51 | } else { 52 | this._resolveCallback(value, true); 53 | } 54 | }; 55 | }; 56 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/nodeback.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var util = require("./util"); 3 | var maybeWrapAsError = util.maybeWrapAsError; 4 | var errors = require("./errors"); 5 | var OperationalError = errors.OperationalError; 6 | var es5 = require("./es5"); 7 | 8 | function isUntypedError(obj) { 9 | return obj instanceof Error && 10 | es5.getPrototypeOf(obj) === Error.prototype; 11 | } 12 | 13 | var rErrorKey = /^(?:name|message|stack|cause)$/; 14 | function wrapAsOperationalError(obj) { 15 | var ret; 16 | if (isUntypedError(obj)) { 17 | ret = new OperationalError(obj); 18 | ret.name = obj.name; 19 | ret.message = obj.message; 20 | ret.stack = obj.stack; 21 | var keys = es5.keys(obj); 22 | for (var i = 0; i < keys.length; ++i) { 23 | var key = keys[i]; 24 | if (!rErrorKey.test(key)) { 25 | ret[key] = obj[key]; 26 | } 27 | } 28 | return ret; 29 | } 30 | util.markAsOriginatingFromRejection(obj); 31 | return obj; 32 | } 33 | 34 | function nodebackForPromise(promise, multiArgs) { 35 | return function(err, value) { 36 | if (promise === null) return; 37 | if (err) { 38 | var wrapped = wrapAsOperationalError(maybeWrapAsError(err)); 39 | promise._attachExtraTrace(wrapped); 40 | promise._reject(wrapped); 41 | } else if (!multiArgs) { 42 | promise._fulfill(value); 43 | } else { 44 | var $_len = arguments.length;var args = new Array(Math.max($_len - 1, 0)); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}; 45 | promise._fulfill(args); 46 | } 47 | promise = null; 48 | }; 49 | } 50 | 51 | module.exports = nodebackForPromise; 52 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/nodeify.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise) { 3 | var util = require("./util"); 4 | var async = Promise._async; 5 | var tryCatch = util.tryCatch; 6 | var errorObj = util.errorObj; 7 | 8 | function spreadAdapter(val, nodeback) { 9 | var promise = this; 10 | if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback); 11 | var ret = 12 | tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val)); 13 | if (ret === errorObj) { 14 | async.throwLater(ret.e); 15 | } 16 | } 17 | 18 | function successAdapter(val, nodeback) { 19 | var promise = this; 20 | var receiver = promise._boundValue(); 21 | var ret = val === undefined 22 | ? tryCatch(nodeback).call(receiver, null) 23 | : tryCatch(nodeback).call(receiver, null, val); 24 | if (ret === errorObj) { 25 | async.throwLater(ret.e); 26 | } 27 | } 28 | function errorAdapter(reason, nodeback) { 29 | var promise = this; 30 | if (!reason) { 31 | var newReason = new Error(reason + ""); 32 | newReason.cause = reason; 33 | reason = newReason; 34 | } 35 | var ret = tryCatch(nodeback).call(promise._boundValue(), reason); 36 | if (ret === errorObj) { 37 | async.throwLater(ret.e); 38 | } 39 | } 40 | 41 | Promise.prototype.asCallback = Promise.prototype.nodeify = function (nodeback, 42 | options) { 43 | if (typeof nodeback == "function") { 44 | var adapter = successAdapter; 45 | if (options !== undefined && Object(options).spread) { 46 | adapter = spreadAdapter; 47 | } 48 | this._then( 49 | adapter, 50 | errorAdapter, 51 | undefined, 52 | this, 53 | nodeback 54 | ); 55 | } 56 | return this; 57 | }; 58 | }; 59 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/props.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function( 3 | Promise, PromiseArray, tryConvertToPromise, apiRejection) { 4 | var util = require("./util"); 5 | var isObject = util.isObject; 6 | var es5 = require("./es5"); 7 | var Es6Map; 8 | if (typeof Map === "function") Es6Map = Map; 9 | 10 | var mapToEntries = (function() { 11 | var index = 0; 12 | var size = 0; 13 | 14 | function extractEntry(value, key) { 15 | this[index] = value; 16 | this[index + size] = key; 17 | index++; 18 | } 19 | 20 | return function mapToEntries(map) { 21 | size = map.size; 22 | index = 0; 23 | var ret = new Array(map.size * 2); 24 | map.forEach(extractEntry, ret); 25 | return ret; 26 | }; 27 | })(); 28 | 29 | var entriesToMap = function(entries) { 30 | var ret = new Es6Map(); 31 | var length = entries.length / 2 | 0; 32 | for (var i = 0; i < length; ++i) { 33 | var key = entries[length + i]; 34 | var value = entries[i]; 35 | ret.set(key, value); 36 | } 37 | return ret; 38 | }; 39 | 40 | function PropertiesPromiseArray(obj) { 41 | var isMap = false; 42 | var entries; 43 | if (Es6Map !== undefined && obj instanceof Es6Map) { 44 | entries = mapToEntries(obj); 45 | isMap = true; 46 | } else { 47 | var keys = es5.keys(obj); 48 | var len = keys.length; 49 | entries = new Array(len * 2); 50 | for (var i = 0; i < len; ++i) { 51 | var key = keys[i]; 52 | entries[i] = obj[key]; 53 | entries[i + len] = key; 54 | } 55 | } 56 | this.constructor$(entries); 57 | this._isMap = isMap; 58 | this._init$(undefined, isMap ? -6 : -3); 59 | } 60 | util.inherits(PropertiesPromiseArray, PromiseArray); 61 | 62 | PropertiesPromiseArray.prototype._init = function () {}; 63 | 64 | PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) { 65 | this._values[index] = value; 66 | var totalResolved = ++this._totalResolved; 67 | if (totalResolved >= this._length) { 68 | var val; 69 | if (this._isMap) { 70 | val = entriesToMap(this._values); 71 | } else { 72 | val = {}; 73 | var keyOffset = this.length(); 74 | for (var i = 0, len = this.length(); i < len; ++i) { 75 | val[this._values[i + keyOffset]] = this._values[i]; 76 | } 77 | } 78 | this._resolve(val); 79 | return true; 80 | } 81 | return false; 82 | }; 83 | 84 | PropertiesPromiseArray.prototype.shouldCopyValues = function () { 85 | return false; 86 | }; 87 | 88 | PropertiesPromiseArray.prototype.getActualLength = function (len) { 89 | return len >> 1; 90 | }; 91 | 92 | function props(promises) { 93 | var ret; 94 | var castValue = tryConvertToPromise(promises); 95 | 96 | if (!isObject(castValue)) { 97 | return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 98 | } else if (castValue instanceof Promise) { 99 | ret = castValue._then( 100 | Promise.props, undefined, undefined, undefined, undefined); 101 | } else { 102 | ret = new PropertiesPromiseArray(castValue).promise(); 103 | } 104 | 105 | if (castValue instanceof Promise) { 106 | ret._propagateFrom(castValue, 2); 107 | } 108 | return ret; 109 | } 110 | 111 | Promise.prototype.props = function () { 112 | return props(this); 113 | }; 114 | 115 | Promise.props = function (promises) { 116 | return props(promises); 117 | }; 118 | }; 119 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/queue.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function arrayMove(src, srcIndex, dst, dstIndex, len) { 3 | for (var j = 0; j < len; ++j) { 4 | dst[j + dstIndex] = src[j + srcIndex]; 5 | src[j + srcIndex] = void 0; 6 | } 7 | } 8 | 9 | function Queue(capacity) { 10 | this._capacity = capacity; 11 | this._length = 0; 12 | this._front = 0; 13 | } 14 | 15 | Queue.prototype._willBeOverCapacity = function (size) { 16 | return this._capacity < size; 17 | }; 18 | 19 | Queue.prototype._pushOne = function (arg) { 20 | var length = this.length(); 21 | this._checkCapacity(length + 1); 22 | var i = (this._front + length) & (this._capacity - 1); 23 | this[i] = arg; 24 | this._length = length + 1; 25 | }; 26 | 27 | Queue.prototype.push = function (fn, receiver, arg) { 28 | var length = this.length() + 3; 29 | if (this._willBeOverCapacity(length)) { 30 | this._pushOne(fn); 31 | this._pushOne(receiver); 32 | this._pushOne(arg); 33 | return; 34 | } 35 | var j = this._front + length - 3; 36 | this._checkCapacity(length); 37 | var wrapMask = this._capacity - 1; 38 | this[(j + 0) & wrapMask] = fn; 39 | this[(j + 1) & wrapMask] = receiver; 40 | this[(j + 2) & wrapMask] = arg; 41 | this._length = length; 42 | }; 43 | 44 | Queue.prototype.shift = function () { 45 | var front = this._front, 46 | ret = this[front]; 47 | 48 | this[front] = undefined; 49 | this._front = (front + 1) & (this._capacity - 1); 50 | this._length--; 51 | return ret; 52 | }; 53 | 54 | Queue.prototype.length = function () { 55 | return this._length; 56 | }; 57 | 58 | Queue.prototype._checkCapacity = function (size) { 59 | if (this._capacity < size) { 60 | this._resizeTo(this._capacity << 1); 61 | } 62 | }; 63 | 64 | Queue.prototype._resizeTo = function (capacity) { 65 | var oldCapacity = this._capacity; 66 | this._capacity = capacity; 67 | var front = this._front; 68 | var length = this._length; 69 | var moveItemsCount = (front + length) & (oldCapacity - 1); 70 | arrayMove(this, 0, this, oldCapacity, moveItemsCount); 71 | }; 72 | 73 | module.exports = Queue; 74 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/race.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function( 3 | Promise, INTERNAL, tryConvertToPromise, apiRejection) { 4 | var util = require("./util"); 5 | 6 | var raceLater = function (promise) { 7 | return promise.then(function(array) { 8 | return race(array, promise); 9 | }); 10 | }; 11 | 12 | function race(promises, parent) { 13 | var maybePromise = tryConvertToPromise(promises); 14 | 15 | if (maybePromise instanceof Promise) { 16 | return raceLater(maybePromise); 17 | } else { 18 | promises = util.asArray(promises); 19 | if (promises === null) 20 | return apiRejection("expecting an array or an iterable object but got " + util.classString(promises)); 21 | } 22 | 23 | var ret = new Promise(INTERNAL); 24 | if (parent !== undefined) { 25 | ret._propagateFrom(parent, 3); 26 | } 27 | var fulfill = ret._fulfill; 28 | var reject = ret._reject; 29 | for (var i = 0, len = promises.length; i < len; ++i) { 30 | var val = promises[i]; 31 | 32 | if (val === undefined && !(i in promises)) { 33 | continue; 34 | } 35 | 36 | Promise.cast(val)._then(fulfill, reject, undefined, ret, null); 37 | } 38 | return ret; 39 | } 40 | 41 | Promise.race = function (promises) { 42 | return race(promises, undefined); 43 | }; 44 | 45 | Promise.prototype.race = function () { 46 | return race(this, undefined); 47 | }; 48 | 49 | }; 50 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/schedule.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var util = require("./util"); 3 | var schedule; 4 | var noAsyncScheduler = function() { 5 | throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 6 | }; 7 | var NativePromise = util.getNativePromise(); 8 | if (util.isNode && typeof MutationObserver === "undefined") { 9 | var GlobalSetImmediate = global.setImmediate; 10 | var ProcessNextTick = process.nextTick; 11 | schedule = util.isRecentNode 12 | ? function(fn) { GlobalSetImmediate.call(global, fn); } 13 | : function(fn) { ProcessNextTick.call(process, fn); }; 14 | } else if (typeof NativePromise === "function" && 15 | typeof NativePromise.resolve === "function") { 16 | var nativePromise = NativePromise.resolve(); 17 | schedule = function(fn) { 18 | nativePromise.then(fn); 19 | }; 20 | } else if ((typeof MutationObserver !== "undefined") && 21 | !(typeof window !== "undefined" && 22 | window.navigator && 23 | (window.navigator.standalone || window.cordova))) { 24 | schedule = (function() { 25 | var div = document.createElement("div"); 26 | var opts = {attributes: true}; 27 | var toggleScheduled = false; 28 | var div2 = document.createElement("div"); 29 | var o2 = new MutationObserver(function() { 30 | div.classList.toggle("foo"); 31 | toggleScheduled = false; 32 | }); 33 | o2.observe(div2, opts); 34 | 35 | var scheduleToggle = function() { 36 | if (toggleScheduled) return; 37 | toggleScheduled = true; 38 | div2.classList.toggle("foo"); 39 | }; 40 | 41 | return function schedule(fn) { 42 | var o = new MutationObserver(function() { 43 | o.disconnect(); 44 | fn(); 45 | }); 46 | o.observe(div, opts); 47 | scheduleToggle(); 48 | }; 49 | })(); 50 | } else if (typeof setImmediate !== "undefined") { 51 | schedule = function (fn) { 52 | setImmediate(fn); 53 | }; 54 | } else if (typeof setTimeout !== "undefined") { 55 | schedule = function (fn) { 56 | setTimeout(fn, 0); 57 | }; 58 | } else { 59 | schedule = noAsyncScheduler; 60 | } 61 | module.exports = schedule; 62 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/settle.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = 3 | function(Promise, PromiseArray, debug) { 4 | var PromiseInspection = Promise.PromiseInspection; 5 | var util = require("./util"); 6 | 7 | function SettledPromiseArray(values) { 8 | this.constructor$(values); 9 | } 10 | util.inherits(SettledPromiseArray, PromiseArray); 11 | 12 | SettledPromiseArray.prototype._promiseResolved = function (index, inspection) { 13 | this._values[index] = inspection; 14 | var totalResolved = ++this._totalResolved; 15 | if (totalResolved >= this._length) { 16 | this._resolve(this._values); 17 | return true; 18 | } 19 | return false; 20 | }; 21 | 22 | SettledPromiseArray.prototype._promiseFulfilled = function (value, index) { 23 | var ret = new PromiseInspection(); 24 | ret._bitField = 33554432; 25 | ret._settledValueField = value; 26 | return this._promiseResolved(index, ret); 27 | }; 28 | SettledPromiseArray.prototype._promiseRejected = function (reason, index) { 29 | var ret = new PromiseInspection(); 30 | ret._bitField = 16777216; 31 | ret._settledValueField = reason; 32 | return this._promiseResolved(index, ret); 33 | }; 34 | 35 | Promise.settle = function (promises) { 36 | debug.deprecated(".settle()", ".reflect()"); 37 | return new SettledPromiseArray(promises).promise(); 38 | }; 39 | 40 | Promise.prototype.settle = function () { 41 | return Promise.settle(this); 42 | }; 43 | }; 44 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/some.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = 3 | function(Promise, PromiseArray, apiRejection) { 4 | var util = require("./util"); 5 | var RangeError = require("./errors").RangeError; 6 | var AggregateError = require("./errors").AggregateError; 7 | var isArray = util.isArray; 8 | var CANCELLATION = {}; 9 | 10 | 11 | function SomePromiseArray(values) { 12 | this.constructor$(values); 13 | this._howMany = 0; 14 | this._unwrap = false; 15 | this._initialized = false; 16 | } 17 | util.inherits(SomePromiseArray, PromiseArray); 18 | 19 | SomePromiseArray.prototype._init = function () { 20 | if (!this._initialized) { 21 | return; 22 | } 23 | if (this._howMany === 0) { 24 | this._resolve([]); 25 | return; 26 | } 27 | this._init$(undefined, -5); 28 | var isArrayResolved = isArray(this._values); 29 | if (!this._isResolved() && 30 | isArrayResolved && 31 | this._howMany > this._canPossiblyFulfill()) { 32 | this._reject(this._getRangeError(this.length())); 33 | } 34 | }; 35 | 36 | SomePromiseArray.prototype.init = function () { 37 | this._initialized = true; 38 | this._init(); 39 | }; 40 | 41 | SomePromiseArray.prototype.setUnwrap = function () { 42 | this._unwrap = true; 43 | }; 44 | 45 | SomePromiseArray.prototype.howMany = function () { 46 | return this._howMany; 47 | }; 48 | 49 | SomePromiseArray.prototype.setHowMany = function (count) { 50 | this._howMany = count; 51 | }; 52 | 53 | SomePromiseArray.prototype._promiseFulfilled = function (value) { 54 | this._addFulfilled(value); 55 | if (this._fulfilled() === this.howMany()) { 56 | this._values.length = this.howMany(); 57 | if (this.howMany() === 1 && this._unwrap) { 58 | this._resolve(this._values[0]); 59 | } else { 60 | this._resolve(this._values); 61 | } 62 | return true; 63 | } 64 | return false; 65 | 66 | }; 67 | SomePromiseArray.prototype._promiseRejected = function (reason) { 68 | this._addRejected(reason); 69 | return this._checkOutcome(); 70 | }; 71 | 72 | SomePromiseArray.prototype._promiseCancelled = function () { 73 | if (this._values instanceof Promise || this._values == null) { 74 | return this._cancel(); 75 | } 76 | this._addRejected(CANCELLATION); 77 | return this._checkOutcome(); 78 | }; 79 | 80 | SomePromiseArray.prototype._checkOutcome = function() { 81 | if (this.howMany() > this._canPossiblyFulfill()) { 82 | var e = new AggregateError(); 83 | for (var i = this.length(); i < this._values.length; ++i) { 84 | if (this._values[i] !== CANCELLATION) { 85 | e.push(this._values[i]); 86 | } 87 | } 88 | if (e.length > 0) { 89 | this._reject(e); 90 | } else { 91 | this._cancel(); 92 | } 93 | return true; 94 | } 95 | return false; 96 | }; 97 | 98 | SomePromiseArray.prototype._fulfilled = function () { 99 | return this._totalResolved; 100 | }; 101 | 102 | SomePromiseArray.prototype._rejected = function () { 103 | return this._values.length - this.length(); 104 | }; 105 | 106 | SomePromiseArray.prototype._addRejected = function (reason) { 107 | this._values.push(reason); 108 | }; 109 | 110 | SomePromiseArray.prototype._addFulfilled = function (value) { 111 | this._values[this._totalResolved++] = value; 112 | }; 113 | 114 | SomePromiseArray.prototype._canPossiblyFulfill = function () { 115 | return this.length() - this._rejected(); 116 | }; 117 | 118 | SomePromiseArray.prototype._getRangeError = function (count) { 119 | var message = "Input array must contain at least " + 120 | this._howMany + " items but contains only " + count + " items"; 121 | return new RangeError(message); 122 | }; 123 | 124 | SomePromiseArray.prototype._resolveEmptyArray = function () { 125 | this._reject(this._getRangeError(0)); 126 | }; 127 | 128 | function some(promises, howMany) { 129 | if ((howMany | 0) !== howMany || howMany < 0) { 130 | return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 131 | } 132 | var ret = new SomePromiseArray(promises); 133 | var promise = ret.promise(); 134 | ret.setHowMany(howMany); 135 | ret.init(); 136 | return promise; 137 | } 138 | 139 | Promise.some = function (promises, howMany) { 140 | return some(promises, howMany); 141 | }; 142 | 143 | Promise.prototype.some = function (howMany) { 144 | return some(this, howMany); 145 | }; 146 | 147 | Promise._SomePromiseArray = SomePromiseArray; 148 | }; 149 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/synchronous_inspection.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise) { 3 | function PromiseInspection(promise) { 4 | if (promise !== undefined) { 5 | promise = promise._target(); 6 | this._bitField = promise._bitField; 7 | this._settledValueField = promise._isFateSealed() 8 | ? promise._settledValue() : undefined; 9 | } 10 | else { 11 | this._bitField = 0; 12 | this._settledValueField = undefined; 13 | } 14 | } 15 | 16 | PromiseInspection.prototype._settledValue = function() { 17 | return this._settledValueField; 18 | }; 19 | 20 | var value = PromiseInspection.prototype.value = function () { 21 | if (!this.isFulfilled()) { 22 | throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 23 | } 24 | return this._settledValue(); 25 | }; 26 | 27 | var reason = PromiseInspection.prototype.error = 28 | PromiseInspection.prototype.reason = function () { 29 | if (!this.isRejected()) { 30 | throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 31 | } 32 | return this._settledValue(); 33 | }; 34 | 35 | var isFulfilled = PromiseInspection.prototype.isFulfilled = function() { 36 | return (this._bitField & 33554432) !== 0; 37 | }; 38 | 39 | var isRejected = PromiseInspection.prototype.isRejected = function () { 40 | return (this._bitField & 16777216) !== 0; 41 | }; 42 | 43 | var isPending = PromiseInspection.prototype.isPending = function () { 44 | return (this._bitField & 50397184) === 0; 45 | }; 46 | 47 | var isResolved = PromiseInspection.prototype.isResolved = function () { 48 | return (this._bitField & 50331648) !== 0; 49 | }; 50 | 51 | PromiseInspection.prototype.isCancelled = function() { 52 | return (this._bitField & 8454144) !== 0; 53 | }; 54 | 55 | Promise.prototype.__isCancelled = function() { 56 | return (this._bitField & 65536) === 65536; 57 | }; 58 | 59 | Promise.prototype._isCancelled = function() { 60 | return this._target().__isCancelled(); 61 | }; 62 | 63 | Promise.prototype.isCancelled = function() { 64 | return (this._target()._bitField & 8454144) !== 0; 65 | }; 66 | 67 | Promise.prototype.isPending = function() { 68 | return isPending.call(this._target()); 69 | }; 70 | 71 | Promise.prototype.isRejected = function() { 72 | return isRejected.call(this._target()); 73 | }; 74 | 75 | Promise.prototype.isFulfilled = function() { 76 | return isFulfilled.call(this._target()); 77 | }; 78 | 79 | Promise.prototype.isResolved = function() { 80 | return isResolved.call(this._target()); 81 | }; 82 | 83 | Promise.prototype.value = function() { 84 | return value.call(this._target()); 85 | }; 86 | 87 | Promise.prototype.reason = function() { 88 | var target = this._target(); 89 | target._unsetRejectionIsUnhandled(); 90 | return reason.call(target); 91 | }; 92 | 93 | Promise.prototype._value = function() { 94 | return this._settledValue(); 95 | }; 96 | 97 | Promise.prototype._reason = function() { 98 | this._unsetRejectionIsUnhandled(); 99 | return this._settledValue(); 100 | }; 101 | 102 | Promise.PromiseInspection = PromiseInspection; 103 | }; 104 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/thenables.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise, INTERNAL) { 3 | var util = require("./util"); 4 | var errorObj = util.errorObj; 5 | var isObject = util.isObject; 6 | 7 | function tryConvertToPromise(obj, context) { 8 | if (isObject(obj)) { 9 | if (obj instanceof Promise) return obj; 10 | var then = getThen(obj); 11 | if (then === errorObj) { 12 | if (context) context._pushContext(); 13 | var ret = Promise.reject(then.e); 14 | if (context) context._popContext(); 15 | return ret; 16 | } else if (typeof then === "function") { 17 | if (isAnyBluebirdPromise(obj)) { 18 | var ret = new Promise(INTERNAL); 19 | obj._then( 20 | ret._fulfill, 21 | ret._reject, 22 | undefined, 23 | ret, 24 | null 25 | ); 26 | return ret; 27 | } 28 | return doThenable(obj, then, context); 29 | } 30 | } 31 | return obj; 32 | } 33 | 34 | function doGetThen(obj) { 35 | return obj.then; 36 | } 37 | 38 | function getThen(obj) { 39 | try { 40 | return doGetThen(obj); 41 | } catch (e) { 42 | errorObj.e = e; 43 | return errorObj; 44 | } 45 | } 46 | 47 | var hasProp = {}.hasOwnProperty; 48 | function isAnyBluebirdPromise(obj) { 49 | try { 50 | return hasProp.call(obj, "_promise0"); 51 | } catch (e) { 52 | return false; 53 | } 54 | } 55 | 56 | function doThenable(x, then, context) { 57 | var promise = new Promise(INTERNAL); 58 | var ret = promise; 59 | if (context) context._pushContext(); 60 | promise._captureStackTrace(); 61 | if (context) context._popContext(); 62 | var synchronous = true; 63 | var result = util.tryCatch(then).call(x, resolve, reject); 64 | synchronous = false; 65 | 66 | if (promise && result === errorObj) { 67 | promise._rejectCallback(result.e, true, true); 68 | promise = null; 69 | } 70 | 71 | function resolve(value) { 72 | if (!promise) return; 73 | promise._resolveCallback(value); 74 | promise = null; 75 | } 76 | 77 | function reject(reason) { 78 | if (!promise) return; 79 | promise._rejectCallback(reason, synchronous, true); 80 | promise = null; 81 | } 82 | return ret; 83 | } 84 | 85 | return tryConvertToPromise; 86 | }; 87 | -------------------------------------------------------------------------------- /node_modules/bluebird/js/release/timers.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = function(Promise, INTERNAL, debug) { 3 | var util = require("./util"); 4 | var TimeoutError = Promise.TimeoutError; 5 | 6 | function HandleWrapper(handle) { 7 | this.handle = handle; 8 | } 9 | 10 | HandleWrapper.prototype._resultCancelled = function() { 11 | clearTimeout(this.handle); 12 | }; 13 | 14 | var afterValue = function(value) { return delay(+this).thenReturn(value); }; 15 | var delay = Promise.delay = function (ms, value) { 16 | var ret; 17 | var handle; 18 | if (value !== undefined) { 19 | ret = Promise.resolve(value) 20 | ._then(afterValue, null, null, ms, undefined); 21 | if (debug.cancellation() && value instanceof Promise) { 22 | ret._setOnCancel(value); 23 | } 24 | } else { 25 | ret = new Promise(INTERNAL); 26 | handle = setTimeout(function() { ret._fulfill(); }, +ms); 27 | if (debug.cancellation()) { 28 | ret._setOnCancel(new HandleWrapper(handle)); 29 | } 30 | ret._captureStackTrace(); 31 | } 32 | ret._setAsyncGuaranteed(); 33 | return ret; 34 | }; 35 | 36 | Promise.prototype.delay = function (ms) { 37 | return delay(ms, this); 38 | }; 39 | 40 | var afterTimeout = function (promise, message, parent) { 41 | var err; 42 | if (typeof message !== "string") { 43 | if (message instanceof Error) { 44 | err = message; 45 | } else { 46 | err = new TimeoutError("operation timed out"); 47 | } 48 | } else { 49 | err = new TimeoutError(message); 50 | } 51 | util.markAsOriginatingFromRejection(err); 52 | promise._attachExtraTrace(err); 53 | promise._reject(err); 54 | 55 | if (parent != null) { 56 | parent.cancel(); 57 | } 58 | }; 59 | 60 | function successClear(value) { 61 | clearTimeout(this.handle); 62 | return value; 63 | } 64 | 65 | function failureClear(reason) { 66 | clearTimeout(this.handle); 67 | throw reason; 68 | } 69 | 70 | Promise.prototype.timeout = function (ms, message) { 71 | ms = +ms; 72 | var ret, parent; 73 | 74 | var handleWrapper = new HandleWrapper(setTimeout(function timeoutTimeout() { 75 | if (ret.isPending()) { 76 | afterTimeout(ret, message, parent); 77 | } 78 | }, ms)); 79 | 80 | if (debug.cancellation()) { 81 | parent = this.then(); 82 | ret = parent._then(successClear, failureClear, 83 | undefined, handleWrapper, undefined); 84 | ret._setOnCancel(handleWrapper); 85 | } else { 86 | ret = this._then(successClear, failureClear, 87 | undefined, handleWrapper, undefined); 88 | } 89 | 90 | return ret; 91 | }; 92 | 93 | }; 94 | -------------------------------------------------------------------------------- /node_modules/bluebird/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bluebird", 3 | "description": "Full featured Promises/A+ implementation with exceptionally good performance", 4 | "version": "3.5.1", 5 | "keywords": [ 6 | "promise", 7 | "performance", 8 | "promises", 9 | "promises-a", 10 | "promises-aplus", 11 | "async", 12 | "await", 13 | "deferred", 14 | "deferreds", 15 | "future", 16 | "flow control", 17 | "dsl", 18 | "fluent interface" 19 | ], 20 | "scripts": { 21 | "lint": "node scripts/jshint.js", 22 | "test": "node tools/test.js", 23 | "istanbul": "istanbul", 24 | "prepublish": "npm run generate-browser-core && npm run generate-browser-full", 25 | "generate-browser-full": "node tools/build.js --no-clean --no-debug --release --browser --minify", 26 | "generate-browser-core": "node tools/build.js --features=core --no-debug --release --zalgo --browser --minify && mv js/browser/bluebird.js js/browser/bluebird.core.js && mv js/browser/bluebird.min.js js/browser/bluebird.core.min.js" 27 | }, 28 | "homepage": "https://github.com/petkaantonov/bluebird", 29 | "repository": { 30 | "type": "git", 31 | "url": "git://github.com/petkaantonov/bluebird.git" 32 | }, 33 | "bugs": { 34 | "url": "http://github.com/petkaantonov/bluebird/issues" 35 | }, 36 | "license": "MIT", 37 | "author": { 38 | "name": "Petka Antonov", 39 | "email": "petka_antonov@hotmail.com", 40 | "url": "http://github.com/petkaantonov/" 41 | }, 42 | "devDependencies": { 43 | "acorn": "~0.6.0", 44 | "baconjs": "^0.7.43", 45 | "bluebird": "^2.9.2", 46 | "body-parser": "^1.10.2", 47 | "browserify": "^8.1.1", 48 | "cli-table": "~0.3.1", 49 | "co": "^4.2.0", 50 | "cross-spawn": "^0.2.3", 51 | "glob": "^4.3.2", 52 | "grunt-saucelabs": "~8.4.1", 53 | "highland": "^2.3.0", 54 | "istanbul": "^0.3.5", 55 | "jshint": "^2.6.0", 56 | "jshint-stylish": "~0.2.0", 57 | "mkdirp": "~0.5.0", 58 | "mocha": "~2.1", 59 | "open": "~0.0.5", 60 | "optimist": "~0.6.1", 61 | "rimraf": "~2.2.6", 62 | "rx": "^2.3.25", 63 | "serve-static": "^1.7.1", 64 | "sinon": "~1.7.3", 65 | "uglify-js": "~2.4.16", 66 | "kefir": "^2.4.1" 67 | }, 68 | "readmeFilename": "README.md", 69 | "main": "./js/release/bluebird.js", 70 | "webpack": "./js/release/bluebird.js", 71 | "browser": "./js/browser/bluebird.js", 72 | "files": [ 73 | "js/browser", 74 | "js/release", 75 | "LICENSE" 76 | ] 77 | } 78 | -------------------------------------------------------------------------------- /node_modules/buffer-more-ints/.npmignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | *~ 3 | -------------------------------------------------------------------------------- /node_modules/buffer-more-ints/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 David Wragg. All rights reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /node_modules/buffer-more-ints/README.md: -------------------------------------------------------------------------------- 1 | # buffer-more-ints: Add support for more integer widths to Buffer 2 | 3 | Node's Buffer only supports reading and writing integers of a limited 4 | range of widths. This module provides support for more widths, so 5 | that integers from 1 to 8 bytes (64 bits) can be accessed. The 6 | support takes two forms. Firstly, as stand-alone functions similar to 7 | the integer reading/writing methods of Buffer: 8 | 9 | $ node 10 | > var moreints = require('buffer-more-ints') 11 | undefined 12 | > moreints.readInt64BE(new Buffer("0000deadbeef0000", "hex"), 0).toString(16) 13 | 'deadbeef0000' 14 | 15 | Read and write functions for the regular widths (8, 16, 32) are also 16 | present in this module, for consistency. 17 | 18 | The second form is methods patched into `Buffer.prototype`, installed 19 | by requiring `'buffer-more-ints/polyfill'`: 20 | 21 | $ node 22 | > require('buffer-more-ints/polyfill') 23 | {} 24 | > new Buffer("0000deadbeef0000", "hex").readInt64BE(0).toString(16) 25 | 'deadbeef0000' 26 | 27 | 28 | buffer-more-ints/polyfill also adds methods `readIntBE`, `writeIntBE`, 29 | and their LE and UInt counterparts, which take an initial argument 30 | giving the width of the integer in bytes: 31 | 32 | > var b = new Buffer(3); 33 | > b.writeIntLE(3, -123456, 0); 34 | > b.toString('hex') 35 | 'c01dfe' 36 | > b.readIntLE(3, 0); 37 | -123456 38 | 39 | The functions added by buffer-more-ints are all implemented in terms 40 | of the core Buffer functions. Part way through writing the code, I 41 | discovered that node.js currently implements those in JavaScript, so 42 | this doesn't lead to performance benefits. But should node ever 43 | switch to implementing its Buffer operations natively, this 44 | module should get a speed boost. 45 | 46 | ## Limitations 47 | 48 | As JavaScript uses IEEE754 doubles for numbers, the contiguous range 49 | of integers it can represent is [-2^53 - 1, 2^53 - 1]. So only 50 | integer widths up to 6 bytes or 48 bits can be read exactly. Reads of 51 | 7 or 8 bytes (56 or 64 bits) will return the closest value that can be 52 | represented as a JavaScript number. 53 | 54 | In certain situations it might be important to check that a JavaScript 55 | number was read exactly. The `isContiguousInt` or 56 | `Buffer.isContiguousInt` (polyfill) function will determine this: 57 | 58 | > Buffer.isContiguousInt(0x1fffffffffffff); 59 | true 60 | > Buffer.isContiguousInt(0x20000000000000); 61 | false 62 | 63 | And `assertContiguousInt` asserts that a number is so: 64 | 65 | > Buffer.assertContiguousInt(0x1fffffffffffff); 66 | undefined 67 | > Buffer.assertContiguousInt(0x20000000000000); 68 | AssertionError: number cannot be represented as a contiguous integer 69 | -------------------------------------------------------------------------------- /node_modules/buffer-more-ints/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "buffer-more-ints", 3 | "version": "0.0.2", 4 | "author": "David Wragg ", 5 | "description": "Add support for more integer widths to Buffer", 6 | "homepage": "https://github.com/dpw/node-buffer-more-ints", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/dpw/node-buffer-more-ints.git" 10 | }, 11 | "main": "buffer-more-ints.js", 12 | "devDependencies": { 13 | "nodeunit": "" 14 | }, 15 | "scripts" : { 16 | "test" : "node ./node_modules/nodeunit/bin/nodeunit buffer-more-ints-tests.js" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /node_modules/buffer-more-ints/polyfill.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var bmi = require('./buffer-more-ints'); 4 | 5 | Buffer.isContiguousInt = bmi.isContiguousInt; 6 | Buffer.assertContiguousInt = bmi.assertContiguousInt; 7 | 8 | ['UInt', 'Int'].forEach(function (signed) { 9 | ['24', '40', '48', '56', '64'].forEach(function (size) { 10 | ['BE', 'LE'].forEach(function (endian) { 11 | var read = 'read' + signed + size + endian; 12 | var reader = bmi[read]; 13 | Buffer.prototype[read] = function(offset, noAssert) { 14 | return reader(this, offset, noAssert); 15 | }; 16 | var write = 'write' + signed + size + endian; 17 | var writer = bmi[write]; 18 | Buffer.prototype[write] = function(val, offset, noAssert) { 19 | writer(this, val, offset, noAssert); 20 | }; 21 | }); 22 | }); 23 | }); 24 | 25 | // Buffer.prototype.read{UInt,Int}8 returns undefined if the offset is 26 | // outside of the buffer, unlike for other widths. These functions 27 | // make it consistent with the others. 28 | var consistent_readX8 = { 29 | readUInt8: function (offset, noAssert) { 30 | return this.readUInt8(offset, noAssert) || 0; 31 | }, 32 | readInt8: function (offset, noAssert) { 33 | return this.readInt8(offset, noAssert) || 0; 34 | } 35 | }; 36 | 37 | function make_accessor(read, prefix, suffix) { 38 | var accessors = [false, 39 | (read ? consistent_readX8 : Buffer.prototype)[prefix + 8]]; 40 | 41 | for (var i = 16; i <= 64; i += 8) { 42 | accessors.push(Buffer.prototype[prefix + i + suffix]); 43 | } 44 | 45 | if (read) { 46 | Buffer.prototype[prefix + suffix] = function (len, offset, noAssert) { 47 | var reader = accessors[len]; 48 | if (reader) { 49 | return reader.call(this, offset, noAssert); 50 | } else { 51 | throw new Error("Cannot read integer of length " + len); 52 | } 53 | }; 54 | } else { 55 | Buffer.prototype[prefix + suffix] = function (len, val, offset, noAssert) { 56 | var writer = accessors[len]; 57 | if (writer) { 58 | return writer.call(this, val, offset, noAssert); 59 | } else { 60 | throw new Error("Cannot write integer of length " + len); 61 | } 62 | } 63 | } 64 | } 65 | 66 | ['UInt', 'Int'].forEach(function (t) { 67 | ['BE', 'LE'].forEach(function (e) { 68 | make_accessor(true, "read" + t, e); 69 | make_accessor(false, "write" + t, e); 70 | }); 71 | }); 72 | -------------------------------------------------------------------------------- /node_modules/core-util-is/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Node.js contributors. All rights reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /node_modules/core-util-is/README.md: -------------------------------------------------------------------------------- 1 | # core-util-is 2 | 3 | The `util.is*` functions introduced in Node v0.12. 4 | -------------------------------------------------------------------------------- /node_modules/core-util-is/lib/util.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // NOTE: These type checking functions intentionally don't use `instanceof` 23 | // because it is fragile and can be easily faked with `Object.create()`. 24 | 25 | function isArray(arg) { 26 | if (Array.isArray) { 27 | return Array.isArray(arg); 28 | } 29 | return objectToString(arg) === '[object Array]'; 30 | } 31 | exports.isArray = isArray; 32 | 33 | function isBoolean(arg) { 34 | return typeof arg === 'boolean'; 35 | } 36 | exports.isBoolean = isBoolean; 37 | 38 | function isNull(arg) { 39 | return arg === null; 40 | } 41 | exports.isNull = isNull; 42 | 43 | function isNullOrUndefined(arg) { 44 | return arg == null; 45 | } 46 | exports.isNullOrUndefined = isNullOrUndefined; 47 | 48 | function isNumber(arg) { 49 | return typeof arg === 'number'; 50 | } 51 | exports.isNumber = isNumber; 52 | 53 | function isString(arg) { 54 | return typeof arg === 'string'; 55 | } 56 | exports.isString = isString; 57 | 58 | function isSymbol(arg) { 59 | return typeof arg === 'symbol'; 60 | } 61 | exports.isSymbol = isSymbol; 62 | 63 | function isUndefined(arg) { 64 | return arg === void 0; 65 | } 66 | exports.isUndefined = isUndefined; 67 | 68 | function isRegExp(re) { 69 | return objectToString(re) === '[object RegExp]'; 70 | } 71 | exports.isRegExp = isRegExp; 72 | 73 | function isObject(arg) { 74 | return typeof arg === 'object' && arg !== null; 75 | } 76 | exports.isObject = isObject; 77 | 78 | function isDate(d) { 79 | return objectToString(d) === '[object Date]'; 80 | } 81 | exports.isDate = isDate; 82 | 83 | function isError(e) { 84 | return (objectToString(e) === '[object Error]' || e instanceof Error); 85 | } 86 | exports.isError = isError; 87 | 88 | function isFunction(arg) { 89 | return typeof arg === 'function'; 90 | } 91 | exports.isFunction = isFunction; 92 | 93 | function isPrimitive(arg) { 94 | return arg === null || 95 | typeof arg === 'boolean' || 96 | typeof arg === 'number' || 97 | typeof arg === 'string' || 98 | typeof arg === 'symbol' || // ES6 symbol 99 | typeof arg === 'undefined'; 100 | } 101 | exports.isPrimitive = isPrimitive; 102 | 103 | exports.isBuffer = Buffer.isBuffer; 104 | 105 | function objectToString(o) { 106 | return Object.prototype.toString.call(o); 107 | } 108 | -------------------------------------------------------------------------------- /node_modules/core-util-is/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "core-util-is", 3 | "version": "1.0.2", 4 | "description": "The `util.is*` functions introduced in Node v0.12.", 5 | "main": "lib/util.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/isaacs/core-util-is" 9 | }, 10 | "keywords": [ 11 | "util", 12 | "isBuffer", 13 | "isArray", 14 | "isNumber", 15 | "isString", 16 | "isRegExp", 17 | "isThis", 18 | "isThat", 19 | "polyfill" 20 | ], 21 | "author": "Isaac Z. Schlueter (http://blog.izs.me/)", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/isaacs/core-util-is/issues" 25 | }, 26 | "scripts": { 27 | "test": "tap test.js" 28 | }, 29 | "devDependencies": { 30 | "tap": "^2.3.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /node_modules/core-util-is/test.js: -------------------------------------------------------------------------------- 1 | var assert = require('tap'); 2 | 3 | var t = require('./lib/util'); 4 | 5 | assert.equal(t.isArray([]), true); 6 | assert.equal(t.isArray({}), false); 7 | 8 | assert.equal(t.isBoolean(null), false); 9 | assert.equal(t.isBoolean(true), true); 10 | assert.equal(t.isBoolean(false), true); 11 | 12 | assert.equal(t.isNull(null), true); 13 | assert.equal(t.isNull(undefined), false); 14 | assert.equal(t.isNull(false), false); 15 | assert.equal(t.isNull(), false); 16 | 17 | assert.equal(t.isNullOrUndefined(null), true); 18 | assert.equal(t.isNullOrUndefined(undefined), true); 19 | assert.equal(t.isNullOrUndefined(false), false); 20 | assert.equal(t.isNullOrUndefined(), true); 21 | 22 | assert.equal(t.isNumber(null), false); 23 | assert.equal(t.isNumber('1'), false); 24 | assert.equal(t.isNumber(1), true); 25 | 26 | assert.equal(t.isString(null), false); 27 | assert.equal(t.isString('1'), true); 28 | assert.equal(t.isString(1), false); 29 | 30 | assert.equal(t.isSymbol(null), false); 31 | assert.equal(t.isSymbol('1'), false); 32 | assert.equal(t.isSymbol(1), false); 33 | assert.equal(t.isSymbol(Symbol()), true); 34 | 35 | assert.equal(t.isUndefined(null), false); 36 | assert.equal(t.isUndefined(undefined), true); 37 | assert.equal(t.isUndefined(false), false); 38 | assert.equal(t.isUndefined(), true); 39 | 40 | assert.equal(t.isRegExp(null), false); 41 | assert.equal(t.isRegExp('1'), false); 42 | assert.equal(t.isRegExp(new RegExp()), true); 43 | 44 | assert.equal(t.isObject({}), true); 45 | assert.equal(t.isObject([]), true); 46 | assert.equal(t.isObject(new RegExp()), true); 47 | assert.equal(t.isObject(new Date()), true); 48 | 49 | assert.equal(t.isDate(null), false); 50 | assert.equal(t.isDate('1'), false); 51 | assert.equal(t.isDate(new Date()), true); 52 | 53 | assert.equal(t.isError(null), false); 54 | assert.equal(t.isError({ err: true }), false); 55 | assert.equal(t.isError(new Error()), true); 56 | 57 | assert.equal(t.isFunction(null), false); 58 | assert.equal(t.isFunction({ }), false); 59 | assert.equal(t.isFunction(function() {}), true); 60 | 61 | assert.equal(t.isPrimitive(null), true); 62 | assert.equal(t.isPrimitive(''), true); 63 | assert.equal(t.isPrimitive(0), true); 64 | assert.equal(t.isPrimitive(new Date()), false); 65 | 66 | assert.equal(t.isBuffer(null), false); 67 | assert.equal(t.isBuffer({}), false); 68 | assert.equal(t.isBuffer(new Buffer(0)), true); 69 | -------------------------------------------------------------------------------- /node_modules/inherits/LICENSE: -------------------------------------------------------------------------------- 1 | The ISC License 2 | 3 | Copyright (c) Isaac Z. Schlueter 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 11 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 14 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | PERFORMANCE OF THIS SOFTWARE. 16 | 17 | -------------------------------------------------------------------------------- /node_modules/inherits/README.md: -------------------------------------------------------------------------------- 1 | Browser-friendly inheritance fully compatible with standard node.js 2 | [inherits](http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor). 3 | 4 | This package exports standard `inherits` from node.js `util` module in 5 | node environment, but also provides alternative browser-friendly 6 | implementation through [browser 7 | field](https://gist.github.com/shtylman/4339901). Alternative 8 | implementation is a literal copy of standard one located in standalone 9 | module to avoid requiring of `util`. It also has a shim for old 10 | browsers with no `Object.create` support. 11 | 12 | While keeping you sure you are using standard `inherits` 13 | implementation in node.js environment, it allows bundlers such as 14 | [browserify](https://github.com/substack/node-browserify) to not 15 | include full `util` package to your client code if all you need is 16 | just `inherits` function. It worth, because browser shim for `util` 17 | package is large and `inherits` is often the single function you need 18 | from it. 19 | 20 | It's recommended to use this package instead of 21 | `require('util').inherits` for any code that has chances to be used 22 | not only in node.js but in browser too. 23 | 24 | ## usage 25 | 26 | ```js 27 | var inherits = require('inherits'); 28 | // then use exactly as the standard one 29 | ``` 30 | 31 | ## note on version ~1.0 32 | 33 | Version ~1.0 had completely different motivation and is not compatible 34 | neither with 2.0 nor with standard node.js `inherits`. 35 | 36 | If you are using version ~1.0 and planning to switch to ~2.0, be 37 | careful: 38 | 39 | * new version uses `super_` instead of `super` for referencing 40 | superclass 41 | * new version overwrites current prototype while old one preserves any 42 | existing fields on it 43 | -------------------------------------------------------------------------------- /node_modules/inherits/inherits.js: -------------------------------------------------------------------------------- 1 | try { 2 | var util = require('util'); 3 | if (typeof util.inherits !== 'function') throw ''; 4 | module.exports = util.inherits; 5 | } catch (e) { 6 | module.exports = require('./inherits_browser.js'); 7 | } 8 | -------------------------------------------------------------------------------- /node_modules/inherits/inherits_browser.js: -------------------------------------------------------------------------------- 1 | if (typeof Object.create === 'function') { 2 | // implementation from standard node.js 'util' module 3 | module.exports = function inherits(ctor, superCtor) { 4 | ctor.super_ = superCtor 5 | ctor.prototype = Object.create(superCtor.prototype, { 6 | constructor: { 7 | value: ctor, 8 | enumerable: false, 9 | writable: true, 10 | configurable: true 11 | } 12 | }); 13 | }; 14 | } else { 15 | // old school shim for old browsers 16 | module.exports = function inherits(ctor, superCtor) { 17 | ctor.super_ = superCtor 18 | var TempCtor = function () {} 19 | TempCtor.prototype = superCtor.prototype 20 | ctor.prototype = new TempCtor() 21 | ctor.prototype.constructor = ctor 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /node_modules/inherits/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inherits", 3 | "description": "Browser-friendly inheritance fully compatible with standard node.js inherits()", 4 | "version": "2.0.3", 5 | "keywords": [ 6 | "inheritance", 7 | "class", 8 | "klass", 9 | "oop", 10 | "object-oriented", 11 | "inherits", 12 | "browser", 13 | "browserify" 14 | ], 15 | "main": "./inherits.js", 16 | "browser": "./inherits_browser.js", 17 | "repository": "git://github.com/isaacs/inherits", 18 | "license": "ISC", 19 | "scripts": { 20 | "test": "node test" 21 | }, 22 | "devDependencies": { 23 | "tap": "^7.1.0" 24 | }, 25 | "files": [ 26 | "inherits.js", 27 | "inherits_browser.js" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /node_modules/isarray/README.md: -------------------------------------------------------------------------------- 1 | 2 | # isarray 3 | 4 | `Array#isArray` for older browsers. 5 | 6 | ## Usage 7 | 8 | ```js 9 | var isArray = require('isarray'); 10 | 11 | console.log(isArray([])); // => true 12 | console.log(isArray({})); // => false 13 | ``` 14 | 15 | ## Installation 16 | 17 | With [npm](http://npmjs.org) do 18 | 19 | ```bash 20 | $ npm install isarray 21 | ``` 22 | 23 | Then bundle for the browser with 24 | [browserify](https://github.com/substack/browserify). 25 | 26 | With [component](http://component.io) do 27 | 28 | ```bash 29 | $ component install juliangruber/isarray 30 | ``` 31 | 32 | ## License 33 | 34 | (MIT) 35 | 36 | Copyright (c) 2013 Julian Gruber <julian@juliangruber.com> 37 | 38 | Permission is hereby granted, free of charge, to any person obtaining a copy of 39 | this software and associated documentation files (the "Software"), to deal in 40 | the Software without restriction, including without limitation the rights to 41 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 42 | of the Software, and to permit persons to whom the Software is furnished to do 43 | so, subject to the following conditions: 44 | 45 | The above copyright notice and this permission notice shall be included in all 46 | copies or substantial portions of the Software. 47 | 48 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 49 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 51 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 54 | SOFTWARE. 55 | -------------------------------------------------------------------------------- /node_modules/isarray/component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "isarray", 3 | "description" : "Array#isArray for older browsers", 4 | "version" : "0.0.1", 5 | "repository" : "juliangruber/isarray", 6 | "homepage": "https://github.com/juliangruber/isarray", 7 | "main" : "index.js", 8 | "scripts" : [ 9 | "index.js" 10 | ], 11 | "dependencies" : {}, 12 | "keywords": ["browser","isarray","array"], 13 | "author": { 14 | "name": "Julian Gruber", 15 | "email": "mail@juliangruber.com", 16 | "url": "http://juliangruber.com" 17 | }, 18 | "license": "MIT" 19 | } 20 | -------------------------------------------------------------------------------- /node_modules/isarray/index.js: -------------------------------------------------------------------------------- 1 | module.exports = Array.isArray || function (arr) { 2 | return Object.prototype.toString.call(arr) == '[object Array]'; 3 | }; 4 | -------------------------------------------------------------------------------- /node_modules/isarray/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "isarray", 3 | "description" : "Array#isArray for older browsers", 4 | "version" : "0.0.1", 5 | "repository" : { 6 | "type" : "git", 7 | "url" : "git://github.com/juliangruber/isarray.git" 8 | }, 9 | "homepage": "https://github.com/juliangruber/isarray", 10 | "main" : "index.js", 11 | "scripts" : { 12 | "test" : "tap test/*.js" 13 | }, 14 | "dependencies" : {}, 15 | "devDependencies" : { 16 | "tap" : "*" 17 | }, 18 | "keywords": ["browser","isarray","array"], 19 | "author": { 20 | "name": "Julian Gruber", 21 | "email": "mail@juliangruber.com", 22 | "url": "http://juliangruber.com" 23 | }, 24 | "license": "MIT" 25 | } 26 | -------------------------------------------------------------------------------- /node_modules/readable-stream/.npmignore: -------------------------------------------------------------------------------- 1 | build/ 2 | test/ 3 | examples/ 4 | fs.js 5 | zlib.js -------------------------------------------------------------------------------- /node_modules/readable-stream/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | Permission is hereby granted, free of charge, to any person obtaining a copy 3 | of this software and associated documentation files (the "Software"), to 4 | deal in the Software without restriction, including without limitation the 5 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 6 | sell copies of the Software, and to permit persons to whom the Software is 7 | furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in 10 | all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 18 | IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /node_modules/readable-stream/README.md: -------------------------------------------------------------------------------- 1 | # readable-stream 2 | 3 | ***Node-core streams for userland*** 4 | 5 | [![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/) 6 | [![NPM](https://nodei.co/npm-dl/readable-stream.png&months=6&height=3)](https://nodei.co/npm/readable-stream/) 7 | 8 | This package is a mirror of the Streams2 and Streams3 implementations in Node-core. 9 | 10 | If you want to guarantee a stable streams base, regardless of what version of Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core. 11 | 12 | **readable-stream** comes in two major versions, v1.0.x and v1.1.x. The former tracks the Streams2 implementation in Node 0.10, including bug-fixes and minor improvements as they are added. The latter tracks Streams3 as it develops in Node 0.11; we will likely see a v1.2.x branch for Node 0.12. 13 | 14 | **readable-stream** uses proper patch-level versioning so if you pin to `"~1.0.0"` you’ll get the latest Node 0.10 Streams2 implementation, including any fixes and minor non-breaking improvements. The patch-level versions of 1.0.x and 1.1.x should mirror the patch-level versions of Node-core releases. You should prefer the **1.0.x** releases for now and when you’re ready to start using Streams3, pin to `"~1.1.0"` 15 | 16 | -------------------------------------------------------------------------------- /node_modules/readable-stream/duplex.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./lib/_stream_duplex.js") 2 | -------------------------------------------------------------------------------- /node_modules/readable-stream/lib/_stream_duplex.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // a duplex stream is just a stream that is both readable and writable. 23 | // Since JS doesn't have multiple prototypal inheritance, this class 24 | // prototypally inherits from Readable, and then parasitically from 25 | // Writable. 26 | 27 | module.exports = Duplex; 28 | 29 | /**/ 30 | var objectKeys = Object.keys || function (obj) { 31 | var keys = []; 32 | for (var key in obj) keys.push(key); 33 | return keys; 34 | } 35 | /**/ 36 | 37 | 38 | /**/ 39 | var util = require('core-util-is'); 40 | util.inherits = require('inherits'); 41 | /**/ 42 | 43 | var Readable = require('./_stream_readable'); 44 | var Writable = require('./_stream_writable'); 45 | 46 | util.inherits(Duplex, Readable); 47 | 48 | forEach(objectKeys(Writable.prototype), function(method) { 49 | if (!Duplex.prototype[method]) 50 | Duplex.prototype[method] = Writable.prototype[method]; 51 | }); 52 | 53 | function Duplex(options) { 54 | if (!(this instanceof Duplex)) 55 | return new Duplex(options); 56 | 57 | Readable.call(this, options); 58 | Writable.call(this, options); 59 | 60 | if (options && options.readable === false) 61 | this.readable = false; 62 | 63 | if (options && options.writable === false) 64 | this.writable = false; 65 | 66 | this.allowHalfOpen = true; 67 | if (options && options.allowHalfOpen === false) 68 | this.allowHalfOpen = false; 69 | 70 | this.once('end', onend); 71 | } 72 | 73 | // the no-half-open enforcer 74 | function onend() { 75 | // if we allow half-open state, or if the writable side ended, 76 | // then we're ok. 77 | if (this.allowHalfOpen || this._writableState.ended) 78 | return; 79 | 80 | // no more data can be written. 81 | // But allow more writes to happen in this tick. 82 | process.nextTick(this.end.bind(this)); 83 | } 84 | 85 | function forEach (xs, f) { 86 | for (var i = 0, l = xs.length; i < l; i++) { 87 | f(xs[i], i); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /node_modules/readable-stream/lib/_stream_passthrough.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // a passthrough stream. 23 | // basically just the most minimal sort of Transform stream. 24 | // Every written chunk gets output as-is. 25 | 26 | module.exports = PassThrough; 27 | 28 | var Transform = require('./_stream_transform'); 29 | 30 | /**/ 31 | var util = require('core-util-is'); 32 | util.inherits = require('inherits'); 33 | /**/ 34 | 35 | util.inherits(PassThrough, Transform); 36 | 37 | function PassThrough(options) { 38 | if (!(this instanceof PassThrough)) 39 | return new PassThrough(options); 40 | 41 | Transform.call(this, options); 42 | } 43 | 44 | PassThrough.prototype._transform = function(chunk, encoding, cb) { 45 | cb(null, chunk); 46 | }; 47 | -------------------------------------------------------------------------------- /node_modules/readable-stream/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "readable-stream", 3 | "version": "1.1.14", 4 | "description": "Streams3, a user-land copy of the stream library from Node.js v0.11.x", 5 | "main": "readable.js", 6 | "dependencies": { 7 | "core-util-is": "~1.0.0", 8 | "isarray": "0.0.1", 9 | "string_decoder": "~0.10.x", 10 | "inherits": "~2.0.1" 11 | }, 12 | "devDependencies": { 13 | "tap": "~0.2.6" 14 | }, 15 | "scripts": { 16 | "test": "tap test/simple/*.js" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git://github.com/isaacs/readable-stream" 21 | }, 22 | "keywords": [ 23 | "readable", 24 | "stream", 25 | "pipe" 26 | ], 27 | "browser": { 28 | "util": false 29 | }, 30 | "author": "Isaac Z. Schlueter (http://blog.izs.me/)", 31 | "license": "MIT" 32 | } 33 | -------------------------------------------------------------------------------- /node_modules/readable-stream/passthrough.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./lib/_stream_passthrough.js") 2 | -------------------------------------------------------------------------------- /node_modules/readable-stream/readable.js: -------------------------------------------------------------------------------- 1 | exports = module.exports = require('./lib/_stream_readable.js'); 2 | exports.Stream = require('stream'); 3 | exports.Readable = exports; 4 | exports.Writable = require('./lib/_stream_writable.js'); 5 | exports.Duplex = require('./lib/_stream_duplex.js'); 6 | exports.Transform = require('./lib/_stream_transform.js'); 7 | exports.PassThrough = require('./lib/_stream_passthrough.js'); 8 | if (!process.browser && process.env.READABLE_STREAM === 'disable') { 9 | module.exports = require('stream'); 10 | } 11 | -------------------------------------------------------------------------------- /node_modules/readable-stream/transform.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./lib/_stream_transform.js") 2 | -------------------------------------------------------------------------------- /node_modules/readable-stream/writable.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./lib/_stream_writable.js") 2 | -------------------------------------------------------------------------------- /node_modules/safe-buffer/.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 'node' 4 | - '5' 5 | - '4' 6 | - '0.12' 7 | - '0.10' 8 | -------------------------------------------------------------------------------- /node_modules/safe-buffer/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Feross Aboukhadijeh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /node_modules/safe-buffer/index.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable node/no-deprecated-api */ 2 | var buffer = require('buffer') 3 | var Buffer = buffer.Buffer 4 | 5 | // alternative to using Object.keys for old browsers 6 | function copyProps (src, dst) { 7 | for (var key in src) { 8 | dst[key] = src[key] 9 | } 10 | } 11 | if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { 12 | module.exports = buffer 13 | } else { 14 | // Copy properties from require('buffer') 15 | copyProps(buffer, exports) 16 | exports.Buffer = SafeBuffer 17 | } 18 | 19 | function SafeBuffer (arg, encodingOrOffset, length) { 20 | return Buffer(arg, encodingOrOffset, length) 21 | } 22 | 23 | // Copy static methods from Buffer 24 | copyProps(Buffer, SafeBuffer) 25 | 26 | SafeBuffer.from = function (arg, encodingOrOffset, length) { 27 | if (typeof arg === 'number') { 28 | throw new TypeError('Argument must not be a number') 29 | } 30 | return Buffer(arg, encodingOrOffset, length) 31 | } 32 | 33 | SafeBuffer.alloc = function (size, fill, encoding) { 34 | if (typeof size !== 'number') { 35 | throw new TypeError('Argument must be a number') 36 | } 37 | var buf = Buffer(size) 38 | if (fill !== undefined) { 39 | if (typeof encoding === 'string') { 40 | buf.fill(fill, encoding) 41 | } else { 42 | buf.fill(fill) 43 | } 44 | } else { 45 | buf.fill(0) 46 | } 47 | return buf 48 | } 49 | 50 | SafeBuffer.allocUnsafe = function (size) { 51 | if (typeof size !== 'number') { 52 | throw new TypeError('Argument must be a number') 53 | } 54 | return Buffer(size) 55 | } 56 | 57 | SafeBuffer.allocUnsafeSlow = function (size) { 58 | if (typeof size !== 'number') { 59 | throw new TypeError('Argument must be a number') 60 | } 61 | return buffer.SlowBuffer(size) 62 | } 63 | -------------------------------------------------------------------------------- /node_modules/safe-buffer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "safe-buffer", 3 | "description": "Safer Node.js Buffer API", 4 | "version": "5.1.1", 5 | "author": { 6 | "name": "Feross Aboukhadijeh", 7 | "email": "feross@feross.org", 8 | "url": "http://feross.org" 9 | }, 10 | "bugs": { 11 | "url": "https://github.com/feross/safe-buffer/issues" 12 | }, 13 | "devDependencies": { 14 | "standard": "*", 15 | "tape": "^4.0.0", 16 | "zuul": "^3.0.0" 17 | }, 18 | "homepage": "https://github.com/feross/safe-buffer", 19 | "keywords": [ 20 | "buffer", 21 | "buffer allocate", 22 | "node security", 23 | "safe", 24 | "safe-buffer", 25 | "security", 26 | "uninitialized" 27 | ], 28 | "license": "MIT", 29 | "main": "index.js", 30 | "repository": { 31 | "type": "git", 32 | "url": "git://github.com/feross/safe-buffer.git" 33 | }, 34 | "scripts": { 35 | "test": "standard && tape test.js" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /node_modules/safe-buffer/test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable node/no-deprecated-api */ 2 | 3 | var test = require('tape') 4 | var SafeBuffer = require('./').Buffer 5 | 6 | test('new SafeBuffer(value) works just like Buffer', function (t) { 7 | t.deepEqual(new SafeBuffer('hey'), new Buffer('hey')) 8 | t.deepEqual(new SafeBuffer('hey', 'utf8'), new Buffer('hey', 'utf8')) 9 | t.deepEqual(new SafeBuffer('686579', 'hex'), new Buffer('686579', 'hex')) 10 | t.deepEqual(new SafeBuffer([1, 2, 3]), new Buffer([1, 2, 3])) 11 | t.deepEqual(new SafeBuffer(new Uint8Array([1, 2, 3])), new Buffer(new Uint8Array([1, 2, 3]))) 12 | 13 | t.equal(typeof SafeBuffer.isBuffer, 'function') 14 | t.equal(SafeBuffer.isBuffer(new SafeBuffer('hey')), true) 15 | t.equal(Buffer.isBuffer(new SafeBuffer('hey')), true) 16 | t.notOk(SafeBuffer.isBuffer({})) 17 | 18 | t.end() 19 | }) 20 | 21 | test('SafeBuffer.from(value) converts to a Buffer', function (t) { 22 | t.deepEqual(SafeBuffer.from('hey'), new Buffer('hey')) 23 | t.deepEqual(SafeBuffer.from('hey', 'utf8'), new Buffer('hey', 'utf8')) 24 | t.deepEqual(SafeBuffer.from('686579', 'hex'), new Buffer('686579', 'hex')) 25 | t.deepEqual(SafeBuffer.from([1, 2, 3]), new Buffer([1, 2, 3])) 26 | t.deepEqual(SafeBuffer.from(new Uint8Array([1, 2, 3])), new Buffer(new Uint8Array([1, 2, 3]))) 27 | 28 | t.end() 29 | }) 30 | 31 | test('SafeBuffer.alloc(number) returns zeroed-out memory', function (t) { 32 | for (var i = 0; i < 10; i++) { 33 | var expected1 = new Buffer(1000) 34 | expected1.fill(0) 35 | t.deepEqual(SafeBuffer.alloc(1000), expected1) 36 | 37 | var expected2 = new Buffer(1000 * 1000) 38 | expected2.fill(0) 39 | t.deepEqual(SafeBuffer.alloc(1000 * 1000), expected2) 40 | } 41 | t.end() 42 | }) 43 | 44 | test('SafeBuffer.allocUnsafe(number)', function (t) { 45 | var buf = SafeBuffer.allocUnsafe(100) // unitialized memory 46 | t.equal(buf.length, 100) 47 | t.equal(SafeBuffer.isBuffer(buf), true) 48 | t.equal(Buffer.isBuffer(buf), true) 49 | t.end() 50 | }) 51 | 52 | test('SafeBuffer.from() throws with number types', function (t) { 53 | t.plan(5) 54 | t.throws(function () { 55 | SafeBuffer.from(0) 56 | }) 57 | t.throws(function () { 58 | SafeBuffer.from(-1) 59 | }) 60 | t.throws(function () { 61 | SafeBuffer.from(NaN) 62 | }) 63 | t.throws(function () { 64 | SafeBuffer.from(Infinity) 65 | }) 66 | t.throws(function () { 67 | SafeBuffer.from(99) 68 | }) 69 | }) 70 | 71 | test('SafeBuffer.allocUnsafe() throws with non-number types', function (t) { 72 | t.plan(4) 73 | t.throws(function () { 74 | SafeBuffer.allocUnsafe('hey') 75 | }) 76 | t.throws(function () { 77 | SafeBuffer.allocUnsafe('hey', 'utf8') 78 | }) 79 | t.throws(function () { 80 | SafeBuffer.allocUnsafe([1, 2, 3]) 81 | }) 82 | t.throws(function () { 83 | SafeBuffer.allocUnsafe({}) 84 | }) 85 | }) 86 | 87 | test('SafeBuffer.alloc() throws with non-number types', function (t) { 88 | t.plan(4) 89 | t.throws(function () { 90 | SafeBuffer.alloc('hey') 91 | }) 92 | t.throws(function () { 93 | SafeBuffer.alloc('hey', 'utf8') 94 | }) 95 | t.throws(function () { 96 | SafeBuffer.alloc([1, 2, 3]) 97 | }) 98 | t.throws(function () { 99 | SafeBuffer.alloc({}) 100 | }) 101 | }) 102 | -------------------------------------------------------------------------------- /node_modules/string_decoder/.npmignore: -------------------------------------------------------------------------------- 1 | build 2 | test 3 | -------------------------------------------------------------------------------- /node_modules/string_decoder/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Joyent, Inc. and other Node contributors. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to permit 8 | persons to whom the Software is furnished to do so, subject to the 9 | following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /node_modules/string_decoder/README.md: -------------------------------------------------------------------------------- 1 | **string_decoder.js** (`require('string_decoder')`) from Node.js core 2 | 3 | Copyright Joyent, Inc. and other Node contributors. See LICENCE file for details. 4 | 5 | Version numbers match the versions found in Node core, e.g. 0.10.24 matches Node 0.10.24, likewise 0.11.10 matches Node 0.11.10. **Prefer the stable version over the unstable.** 6 | 7 | The *build/* directory contains a build script that will scrape the source from the [joyent/node](https://github.com/joyent/node) repo given a specific Node version. -------------------------------------------------------------------------------- /node_modules/string_decoder/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "string_decoder", 3 | "version": "0.10.31", 4 | "description": "The string_decoder module from Node core", 5 | "main": "index.js", 6 | "dependencies": {}, 7 | "devDependencies": { 8 | "tap": "~0.4.8" 9 | }, 10 | "scripts": { 11 | "test": "tap test/simple/*.js" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git://github.com/rvagg/string_decoder.git" 16 | }, 17 | "homepage": "https://github.com/rvagg/string_decoder", 18 | "keywords": [ 19 | "string", 20 | "decoder", 21 | "browser", 22 | "browserify" 23 | ], 24 | "license": "MIT" 25 | } 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-rabbitmq", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "amqplib": "^0.5.2" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /publish-subscribe-pattern-01-fanout/emit_log.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const amqp = require('amqplib/callback_api') 3 | 4 | // Create connection 5 | amqp.connect('amqp://localhost', (err, conn) => { 6 | // Create channel 7 | conn.createChannel((err, ch) => { 8 | // Name of the exchange 9 | const ex = 'logs' 10 | // Write a message 11 | const msg = process.argv.slice(2).join(' ') || "Hello World!" 12 | 13 | // Declare the exchange 14 | ch.assertExchange(ex, 'fanout', { durable: false }) // 'fanout' will broadcast all messages to all the queues it knows 15 | 16 | // Send message to the exchange 17 | ch.publish(ex, '', new Buffer(msg)) // '' empty string means that message will not be sent to a specific queue 18 | console.log(` {x} Sent '${msg}'`) 19 | 20 | // Close the connection and exit 21 | setTimeout(() => { 22 | conn.close() 23 | process.exit(0) 24 | }, 500) 25 | }) 26 | }) 27 | -------------------------------------------------------------------------------- /publish-subscribe-pattern-01-fanout/receive_logs.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const amqp = require('amqplib/callback_api') 3 | 4 | // Create connection 5 | amqp.connect('amqp://localhost', (err, conn) => { 6 | // Create channel 7 | conn.createChannel((err, ch) => { 8 | // Name of the exchange 9 | const ex = 'logs' 10 | // Declare the exchange 11 | ch.assertExchange(ex, 'fanout', { durable: false }) // 'fanout' will broadcast all messages to all the queues it knows 12 | 13 | // Declare the queues 14 | ch.assertQueue('', {exclusive: true}, (err, q) => { 15 | // Wait for Queue Messages 16 | console.log(` [*] Waiting for messages in ${q}. To exit press CTRL+C`) 17 | // Tell exchange to send messages to queue 18 | ch.bindQueue(q.queue, ex, '') 19 | // Consume queue messages 20 | ch.consume(q.queue, msg => { 21 | console.log(` [x] ${msg.content.toString()}`) 22 | }, {noAck: true}) 23 | }) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /publish-subscribe-pattern-02-direct/emit_log_direct.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const amqp = require('amqplib/callback_api') 3 | 4 | // Create connection 5 | amqp.connect('amqp://localhost', (err, conn) => { 6 | // Create channel 7 | conn.createChannel((err, ch) => { 8 | // Name of the exchange 9 | const ex = 'direct_logs' 10 | // Store message as args 11 | const args = process.argv.slice(2) 12 | // Write a message 13 | const msg = args.slice(1).join(' ') || "Hello World!" 14 | // Use severity as the binding key 15 | const severity = (args.length > 0) ? args[0] : 'info' 16 | 17 | // Declare the exchange 18 | ch.assertExchange(ex, 'direct', { durable: false }) // 'direct' will broadcast messages to its corresponding binding key (i.e. severity) 19 | 20 | // Send message to the exchange 21 | ch.publish(ex, severity, new Buffer(msg)) // '' empty string means that message will not be sent to a specific queue 22 | console.log(` {x} Sent ${severity}: '${msg}'`) 23 | 24 | // Close the connection and exit 25 | setTimeout(() => { 26 | conn.close() 27 | process.exit(0) 28 | }, 500) 29 | }) 30 | }) 31 | -------------------------------------------------------------------------------- /publish-subscribe-pattern-02-direct/receive_logs_direct.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const amqp = require('amqplib/callback_api') 3 | 4 | // Store message as args 5 | const args = process.argv.slice(2); 6 | 7 | // Choose what type of binding key `receive_logs_direct.js` is going to use 8 | // If no arguments were provided, output instructions 9 | if (args.length == 0) { 10 | console.log("Usage: receive_logs_direct.js [info] [warning] [error]"); 11 | process.exit(1); 12 | } 13 | 14 | // Create connection 15 | amqp.connect('amqp://localhost', (err, conn) => { 16 | // Create channel 17 | conn.createChannel((err, ch) => { 18 | // Name of the exchange 19 | const ex = 'direct_logs' 20 | // Declare the exchange 21 | ch.assertExchange(ex, 'direct', { durable: false }) // 'direct' will broadcast messages to its corresponding binding key (i.e. severity) 22 | 23 | // Declare the queues 24 | ch.assertQueue('', {exclusive: true}, (err, q) => { 25 | // Wait for Queue Messages 26 | console.log(` [*] Waiting for messages in ${q}. To exit press CTRL+C`) 27 | // For each binding key, tell exchange to send messages to queue 28 | args.forEach( severity => { 29 | ch.bindQueue(q.queue, ex, severity) 30 | }) 31 | 32 | // Consume queue messages 33 | ch.consume(q.queue, msg => { 34 | console.log(` [x] ${msg.fields.routingKey}: ${msg.content.toString()}`) 35 | }, {noAck: true}) 36 | }) 37 | }) 38 | }) 39 | -------------------------------------------------------------------------------- /work-queue-pattern/new_task.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const amqp = require('amqplib/callback_api') 3 | 4 | // Create connection 5 | amqp.connect('amqp://localhost', (err, conn) => { 6 | // Create channel 7 | conn.createChannel((err, ch) => { 8 | // Name of the queue 9 | const q = 'task_queue_durable' 10 | // Write a message 11 | const msg = process.argv.slice(2).join(' ') || "Hello World!" 12 | 13 | // Declare the queue 14 | ch.assertQueue(q, { durable: true }) // { durable: true } ensures that the message will still be redelivered even if RabbitMQ service is turned off/restarted 15 | 16 | // Send message to the queue 17 | ch.sendToQueue(q, new Buffer(msg), {persistent: true}) // {persistent: true} saves the message to disk/cache 18 | console.log(` {x} Sent '${msg}'`) 19 | 20 | // Close the connection and exit 21 | setTimeout(() => { 22 | conn.close() 23 | process.exit(0) 24 | }, 500) 25 | }) 26 | }) 27 | -------------------------------------------------------------------------------- /work-queue-pattern/worker.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const amqp = require('amqplib/callback_api') 3 | 4 | // Create connection 5 | amqp.connect('amqp://localhost', (err, conn) => { 6 | // Create channel 7 | conn.createChannel((err, ch) => { 8 | // Name of the queue 9 | const q = 'task_queue_durable' 10 | // Declare the queue 11 | ch.assertQueue(q, { durable: true }) // { durable: true } ensures that the message will still be redelivered even if RabbitMQ service is turned off/restarted 12 | // Tell RabbitMQ not to give more than 1 message per worker 13 | ch.prefetch(1) 14 | 15 | // Wait for Queue Messages 16 | console.log(` [*] Waiting for messages in ${q}. To exit press CTRL+C`) 17 | ch.consume( q, msg => { 18 | // Just to simulate a fake task, length of dots in the message 19 | // is the number of secs the task will run 20 | const secs = msg.content.toString().split('.').length - 1 21 | 22 | console.log(` [x] Received ${msg.content.toString()}`) 23 | console.log(` [x] Task will run for ${secs} secs`) 24 | 25 | // Fake task which simulates execution time 26 | setTimeout(() => { 27 | console.log(` [x] Done ${msg.content.toString()}`); 28 | // Send acknowledgment 29 | ch.ack(msg) 30 | }, secs * 1000) 31 | 32 | }, { noAck: false } // noAck: false means Message acknowledgments is turned on 33 | // When message acknowledgements are turned on, even if a worker.js is killed (Ctrl+C) 34 | // while processing a message, it will be redelivered 35 | ) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | amqplib@^0.5.2: 6 | version "0.5.2" 7 | resolved "https://registry.yarnpkg.com/amqplib/-/amqplib-0.5.2.tgz#d2d7313c7ffaa4d10bcf1e6252de4591b6cc7b63" 8 | dependencies: 9 | bitsyntax "~0.0.4" 10 | bluebird "^3.4.6" 11 | buffer-more-ints "0.0.2" 12 | readable-stream "1.x >=1.1.9" 13 | safe-buffer "^5.0.1" 14 | 15 | bitsyntax@~0.0.4: 16 | version "0.0.4" 17 | resolved "https://registry.yarnpkg.com/bitsyntax/-/bitsyntax-0.0.4.tgz#eb10cc6f82b8c490e3e85698f07e83d46e0cba82" 18 | dependencies: 19 | buffer-more-ints "0.0.2" 20 | 21 | bluebird@^3.4.6: 22 | version "3.5.1" 23 | resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9" 24 | 25 | buffer-more-ints@0.0.2: 26 | version "0.0.2" 27 | resolved "https://registry.yarnpkg.com/buffer-more-ints/-/buffer-more-ints-0.0.2.tgz#26b3885d10fa13db7fc01aae3aab870199e0124c" 28 | 29 | core-util-is@~1.0.0: 30 | version "1.0.2" 31 | resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" 32 | 33 | inherits@~2.0.1: 34 | version "2.0.3" 35 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" 36 | 37 | isarray@0.0.1: 38 | version "0.0.1" 39 | resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" 40 | 41 | "readable-stream@1.x >=1.1.9": 42 | version "1.1.14" 43 | resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9" 44 | dependencies: 45 | core-util-is "~1.0.0" 46 | inherits "~2.0.1" 47 | isarray "0.0.1" 48 | string_decoder "~0.10.x" 49 | 50 | safe-buffer@^5.0.1: 51 | version "5.1.1" 52 | resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" 53 | 54 | string_decoder@~0.10.x: 55 | version "0.10.31" 56 | resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" 57 | --------------------------------------------------------------------------------