rascal 13.1.2 → 13.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/.husky/pre-commit +1 -1
  2. package/.prettierrc.json +1 -0
  3. package/CHANGELOG.md +195 -1
  4. package/README.md +630 -395
  5. package/examples/advanced/cluster.js +8 -8
  6. package/examples/advanced/config.js +117 -114
  7. package/examples/advanced/handlers/deleteUser.js +23 -17
  8. package/examples/advanced/handlers/saveUser.js +38 -32
  9. package/examples/advanced/index.js +105 -78
  10. package/examples/busy-publisher/config.js +14 -17
  11. package/examples/busy-publisher/index.js +27 -22
  12. package/examples/default-exchange/config.js +10 -10
  13. package/examples/default-exchange/index.js +27 -18
  14. package/examples/mocha/config.js +9 -11
  15. package/examples/mocha/test.js +42 -35
  16. package/examples/promises/config.js +11 -13
  17. package/examples/promises/index.js +24 -17
  18. package/examples/simple/config.js +16 -18
  19. package/examples/simple/index.js +25 -23
  20. package/index.js +7 -7
  21. package/lib/amqp/Broker.js +154 -99
  22. package/lib/amqp/BrokerAsPromised.js +56 -35
  23. package/lib/amqp/Publication.js +219 -78
  24. package/lib/amqp/PublicationSession.js +13 -14
  25. package/lib/amqp/SubscriberError.js +293 -132
  26. package/lib/amqp/SubscriberSession.js +95 -56
  27. package/lib/amqp/SubscriberSessionAsPromised.js +4 -6
  28. package/lib/amqp/Subscription.js +328 -109
  29. package/lib/amqp/Vhost.js +341 -170
  30. package/lib/amqp/tasks/applyBindings.js +51 -18
  31. package/lib/amqp/tasks/assertExchanges.js +20 -11
  32. package/lib/amqp/tasks/assertQueues.js +13 -9
  33. package/lib/amqp/tasks/assertVhost.js +21 -17
  34. package/lib/amqp/tasks/bounceVhost.js +1 -1
  35. package/lib/amqp/tasks/checkExchanges.js +13 -9
  36. package/lib/amqp/tasks/checkQueues.js +13 -9
  37. package/lib/amqp/tasks/checkVhost.js +21 -17
  38. package/lib/amqp/tasks/closeChannel.js +3 -4
  39. package/lib/amqp/tasks/closeConnection.js +3 -3
  40. package/lib/amqp/tasks/createChannel.js +3 -4
  41. package/lib/amqp/tasks/createConnection.js +71 -53
  42. package/lib/amqp/tasks/deleteExchanges.js +14 -10
  43. package/lib/amqp/tasks/deleteQueues.js +13 -9
  44. package/lib/amqp/tasks/deleteVhost.js +26 -17
  45. package/lib/amqp/tasks/forewarnVhost.js +1 -1
  46. package/lib/amqp/tasks/index.js +25 -25
  47. package/lib/amqp/tasks/initCounters.js +18 -13
  48. package/lib/amqp/tasks/initPublications.js +17 -13
  49. package/lib/amqp/tasks/initShovels.js +29 -20
  50. package/lib/amqp/tasks/initSubscriptions.js +23 -13
  51. package/lib/amqp/tasks/initVhosts.js +21 -17
  52. package/lib/amqp/tasks/nukeVhost.js +1 -1
  53. package/lib/amqp/tasks/purgeQueues.js +13 -9
  54. package/lib/amqp/tasks/purgeVhost.js +1 -1
  55. package/lib/amqp/tasks/shutdownVhost.js +1 -1
  56. package/lib/backoff/exponential.js +9 -8
  57. package/lib/backoff/index.js +3 -3
  58. package/lib/backoff/linear.js +5 -7
  59. package/lib/config/baseline.js +25 -35
  60. package/lib/config/configure.js +274 -101
  61. package/lib/config/fqn.js +3 -3
  62. package/lib/config/tests.js +32 -29
  63. package/lib/config/validate.js +460 -70
  64. package/lib/counters/inMemory.js +3 -3
  65. package/lib/counters/inMemoryCluster.js +48 -30
  66. package/lib/counters/index.js +4 -4
  67. package/lib/counters/stub.js +2 -3
  68. package/lib/management/client.js +47 -17
  69. package/lib/utils/setTimeoutUnref.js +1 -1
  70. package/package.json +12 -4
@@ -1,8 +1,8 @@
1
- const cluster = require('cluster');
2
- const inMemory = require('./inMemory');
3
- const uuid = require('uuid').v4;
4
- const Stashback = require('stashback');
5
- const debug = 'rascal:counters:inMemoryCluster';
1
+ const cluster = require("cluster");
2
+ const inMemory = require("./inMemory");
3
+ const uuid = require("uuid").v4;
4
+ const Stashback = require("stashback");
5
+ const debug = "rascal:counters:inMemoryCluster";
6
6
 
7
7
  module.exports = {
8
8
  master: function master(options) {
@@ -10,49 +10,67 @@ module.exports = {
10
10
  const counter = inMemory(options);
11
11
 
12
12
  function handleMessage(worker, message) {
13
- if (message.sender !== 'rascal-in-memory-cluster-counter' || message.cmd !== 'incrementAndGet') return;
13
+ if (
14
+ message.sender !== "rascal-in-memory-cluster-counter" ||
15
+ message.cmd !== "incrementAndGet"
16
+ )
17
+ return;
14
18
  counter.incrementAndGet(message.key, (err, value) => {
15
- worker.send({ sender: 'rascal-in-memory-cluster-counter', correlationId: message.correlationId, value: err ? 1 : value });
19
+ worker.send({
20
+ sender: "rascal-in-memory-cluster-counter",
21
+ correlationId: message.correlationId,
22
+ value: err ? 1 : value,
23
+ });
16
24
  });
17
25
  }
18
26
 
19
- cluster.on('fork', (worker) => {
20
- workers[worker.id] = worker;
21
- worker.on('message', (message) => {
22
- handleMessage(worker, message);
27
+ cluster
28
+ .on("fork", (worker) => {
29
+ workers[worker.id] = worker;
30
+ worker.on("message", (message) => {
31
+ handleMessage(worker, message);
32
+ });
33
+ })
34
+ .on("disconnect", (worker) => {
35
+ delete workers[worker.id];
36
+ })
37
+ .on("exit", (worker) => {
38
+ delete workers[worker.id];
23
39
  });
24
- }).on('disconnect', (worker) => {
25
- delete workers[worker.id];
26
- }).on('exit', (worker) => {
27
- delete workers[worker.id];
28
- });
29
40
  },
30
41
  worker: function worker(options) {
31
- if (!cluster.isWorker) throw new Error('You cannot use Rascal\'s in memmory cluster counter outside of a cluster');
42
+ if (!cluster.isWorker)
43
+ throw new Error(
44
+ "You cannot use Rascal's in memmory cluster counter outside of a cluster"
45
+ );
32
46
  if (!options) return worker({});
33
47
  const timeout = options.timeout || 100;
34
48
  const stashback = Stashback({ timeout });
35
49
 
36
- process.on('message', (message) => {
37
- if (message.sender !== 'rascal-in-memory-cluster-counter') return;
50
+ process.on("message", (message) => {
51
+ if (message.sender !== "rascal-in-memory-cluster-counter") return;
38
52
  stashback.unstash(message.correlationId, (err, cb) => {
39
53
  err ? cb(null, 1) : cb(null, message.value);
40
54
  });
41
55
  });
42
56
 
43
57
  return {
44
- incrementAndGet (key, cb) {
58
+ incrementAndGet(key, cb) {
45
59
  const correlationId = uuid();
46
- stashback.stash(correlationId, (err, value) => {
47
- err ? cb(null, 1) : cb(null, value);
48
- }, (err) => {
49
- if (err) return cb(null, 1);
50
- process.send({
51
- sender: 'rascal-in-memory-cluster-counter',
52
- correlationId,
53
- cmd: 'incrementAndGet',
54
- });
55
- });
60
+ stashback.stash(
61
+ correlationId,
62
+ (err, value) => {
63
+ err ? cb(null, 1) : cb(null, value);
64
+ },
65
+ (err) => {
66
+ if (err) return cb(null, 1);
67
+ process.send({
68
+ sender: "rascal-in-memory-cluster-counter",
69
+ correlationId,
70
+ cmd: "incrementAndGet",
71
+ });
72
+ }
73
+ );
56
74
  },
57
75
  };
58
76
  },
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- stub: require('./stub'),
3
- inMemory: require('./inMemory'),
4
- inMemoryCluster: require('./inMemoryCluster'),
5
- };
2
+ stub: require("./stub"),
3
+ inMemory: require("./inMemory"),
4
+ inMemoryCluster: require("./inMemoryCluster"),
5
+ };
@@ -1,8 +1,7 @@
1
- module.exports = function() {
2
-
1
+ module.exports = function () {
3
2
  return {
4
3
  incrementAndGet(key, next) {
5
4
  next(null, 0);
6
5
  },
7
6
  };
8
- };
7
+ };
@@ -1,46 +1,76 @@
1
- const debug = require('debug')('rascal:management:client');
2
- const format = require('util').format;
3
- const _ = require('lodash');
4
- const agent = require('superagent');
1
+ const debug = require("debug")("rascal:management:client");
2
+ const format = require("util").format;
3
+ const _ = require("lodash");
4
+ const agent = require("superagent");
5
5
 
6
6
  function assertVhost(name, config, next) {
7
- debug('Asserting vhost: %s', name);
7
+ debug("Asserting vhost: %s", name);
8
8
  const options = getVhostOptions(name, config);
9
- request('put', options.url, options.timeout, (err) => {
9
+ request("put", options.url, options.timeout, (err) => {
10
10
  if (!err) return next();
11
11
  const message = err.status
12
- ? format('Failed to assert vhost: %s. %s returned status %d', name, config.loggableUrl, err.status)
13
- : format('Failed to assert vhost: %s. %s errored with: %s', name, config.loggableUrl, err.message);
12
+ ? format(
13
+ "Failed to assert vhost: %s. %s returned status %d",
14
+ name,
15
+ config.loggableUrl,
16
+ err.status
17
+ )
18
+ : format(
19
+ "Failed to assert vhost: %s. %s errored with: %s",
20
+ name,
21
+ config.loggableUrl,
22
+ err.message
23
+ );
14
24
  return next(new Error(message));
15
25
  });
16
26
  }
17
27
 
18
28
  function checkVhost(name, config, next) {
19
- debug('Checking vhost: %s', name);
29
+ debug("Checking vhost: %s", name);
20
30
  const options = getVhostOptions(name, config);
21
- request('get', options.url, options.timeout, (err) => {
31
+ request("get", options.url, options.timeout, (err) => {
22
32
  if (!err) return next();
23
33
  const message = err.status
24
- ? format('Failed to check vhost: %s. %s returned status %d', name, config.loggableUrl, err.status)
25
- : format('Failed to check vhost: %s. %s errored with: %s', name, config.loggableUrl, err.message);
34
+ ? format(
35
+ "Failed to check vhost: %s. %s returned status %d",
36
+ name,
37
+ config.loggableUrl,
38
+ err.status
39
+ )
40
+ : format(
41
+ "Failed to check vhost: %s. %s errored with: %s",
42
+ name,
43
+ config.loggableUrl,
44
+ err.message
45
+ );
26
46
  return next(new Error(message));
27
47
  });
28
48
  }
29
49
 
30
50
  function deleteVhost(name, config, next) {
31
- debug('Deleting vhost: %s', name);
51
+ debug("Deleting vhost: %s", name);
32
52
  const options = getVhostOptions(name, config);
33
- request('delete', options.url, options.timeout, (err) => {
53
+ request("delete", options.url, options.timeout, (err) => {
34
54
  if (!err) return next();
35
55
  const message = err.status
36
- ? format('Failed to delete vhost: %s. %s returned status %d', name, config.loggableUrl, err.status)
37
- : format('Failed to delete vhost: %s. %s errored with: %s', name, config.loggableUrl, err.message);
56
+ ? format(
57
+ "Failed to delete vhost: %s. %s returned status %d",
58
+ name,
59
+ config.loggableUrl,
60
+ err.status
61
+ )
62
+ : format(
63
+ "Failed to delete vhost: %s. %s errored with: %s",
64
+ name,
65
+ config.loggableUrl,
66
+ err.message
67
+ );
38
68
  return next(new Error(message));
39
69
  });
40
70
  }
41
71
 
42
72
  function getVhostOptions(name, config) {
43
- const url = format('%s/%s/%s', config.url, 'api/vhosts', name);
73
+ const url = format("%s/%s/%s", config.url, "api/vhosts", name);
44
74
  return _.defaultsDeep({ url }, config.options);
45
75
  }
46
76
 
@@ -1,5 +1,5 @@
1
1
  // See https://github.com/guidesmiths/rascal/issues/89
2
- module.exports = function(fn, millis) {
2
+ module.exports = function (fn, millis) {
3
3
  const t = setTimeout(fn, millis);
4
4
  return t.unref ? t.unref() : t;
5
5
  };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "rascal",
3
- "version": "13.1.2",
3
+ "version": "13.1.3",
4
4
  "description": "A config driven wrapper for amqplib supporting multi-host connections, automatic error recovery, redelivery flood protection, transparent encryption / decryption, channel pooling and publication timeouts",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
- "async": "^3.2.0",
7
+ "async": "^3.2.1",
8
8
  "debug": "^4.1.1",
9
9
  "deep-freeze": "0.0.1",
10
10
  "forward-emitter": "^0.1.1",
@@ -21,10 +21,13 @@
21
21
  "amqplib": "^0.8.0",
22
22
  "chalk": "^4.0.0",
23
23
  "chance": "^1.1.4",
24
- "eslint": "^6.8.0",
25
- "eslint-config-esnext": "^4.1.0",
24
+ "eslint": "^7.32.0",
25
+ "eslint-config-prettier": "^8.3.0",
26
+ "eslint-plugin-prettier": "^4.0.0",
26
27
  "husky": "^6.0.0",
28
+ "lint-staged": "^11.2.4",
27
29
  "nyc": "^15.1.0",
30
+ "prettier": "2.4.1",
28
31
  "random-readable": "^1.0.1",
29
32
  "zunit": "^3.0.8"
30
33
  },
@@ -36,11 +39,16 @@
36
39
  },
37
40
  "scripts": {
38
41
  "test": "zUnit",
42
+ "prettier": "prettier --check .",
39
43
  "lint": "eslint .",
44
+ "lint-staged": "lint-staged",
40
45
  "coverage": "nyc --report html --reporter lcov --reporter text-summary zUnit",
41
46
  "docker": "docker run -d --name rascal-rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management",
42
47
  "prepare": "husky install"
43
48
  },
49
+ "lint-staged": {
50
+ "**/*": "prettier --write --ignore-unknown"
51
+ },
44
52
  "keywords": [
45
53
  "amqplib",
46
54
  "amqp",