rascal 13.0.6 → 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 +204 -1
  4. package/README.md +634 -396
  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 +18 -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 -110
  29. package/lib/amqp/Vhost.js +366 -171
  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 -51
  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 +26 -34
  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,15 +1,14 @@
1
- const debug = require('debug')('rascal:config:configure');
2
- const format = require('util').format;
3
- const url = require('url');
4
- const _ = require('lodash');
5
- const uuid = require('uuid').v4;
6
- const baseline = require('./baseline');
7
- const fqn = require('./fqn');
8
- const XRegExp = require('xregexp');
9
- const freeze = require('deep-freeze');
1
+ const debug = require("debug")("rascal:config:configure");
2
+ const format = require("util").format;
3
+ const url = require("url");
4
+ const _ = require("lodash");
5
+ const uuid = require("uuid").v4;
6
+ const baseline = require("./baseline");
7
+ const fqn = require("./fqn");
8
+ const XRegExp = require("xregexp");
9
+ const freeze = require("deep-freeze");
10
10
 
11
11
  module.exports = _.curry((rascalConfig, next) => {
12
-
13
12
  rascalConfig = _.defaultsDeep(rascalConfig, baseline);
14
13
 
15
14
  let err;
@@ -21,11 +20,11 @@ module.exports = _.curry((rascalConfig, next) => {
21
20
  configureSubscriptions(rascalConfig.subscriptions, rascalConfig.vhosts);
22
21
  configureShovels(rascalConfig.shovels);
23
22
  configureCounters(rascalConfig.redeliveries.counters);
24
- } catch(_err) {
23
+ } catch (_err) {
25
24
  err = _err;
26
25
  }
27
26
 
28
- return err ? next(err) :next(null, freeze(rascalConfig));
27
+ return err ? next(err) : next(null, freeze(rascalConfig));
29
28
 
30
29
  function configureVhosts(vhosts) {
31
30
  _.each(vhosts, (vhostConfig, name) => {
@@ -39,54 +38,78 @@ module.exports = _.curry((rascalConfig, next) => {
39
38
  }
40
39
 
41
40
  function configureVhost(name, vhostConfig) {
42
- debug('Configuring vhost: %s', name);
43
- rascalConfig.vhosts[name] = _.defaultsDeep(vhostConfig, {
44
- name,
45
- namespace: rascalConfig.defaults.vhosts.namespace,
46
- connectionStrategy: rascalConfig.defaults.vhosts.connectionStrategy,
47
- publicationChannelPools: rascalConfig.defaults.vhosts.publicationChannelPools,
48
- }, { defaults: rascalConfig.defaults.vhosts });
49
- rascalConfig.vhosts[name].namespace = vhostConfig.namespace === true ? uuid() : vhostConfig.namespace;
41
+ debug("Configuring vhost: %s", name);
42
+ rascalConfig.vhosts[name] = _.defaultsDeep(
43
+ vhostConfig,
44
+ {
45
+ name,
46
+ namespace: rascalConfig.defaults.vhosts.namespace,
47
+ connectionStrategy: rascalConfig.defaults.vhosts.connectionStrategy,
48
+ publicationChannelPools:
49
+ rascalConfig.defaults.vhosts.publicationChannelPools,
50
+ },
51
+ { defaults: rascalConfig.defaults.vhosts }
52
+ );
53
+ rascalConfig.vhosts[name].namespace =
54
+ vhostConfig.namespace === true ? uuid() : vhostConfig.namespace;
50
55
  configureConnections(vhostConfig, name);
51
56
  }
52
57
 
53
58
  function configureConnections(vhostConfig, vhostName) {
54
- vhostConfig.connections = _.chain([]).concat(vhostConfig.connections, vhostConfig.connection).compact().uniq().map((connection) => {
55
- return _.isString(connection) ? { url: connection } : connection;
56
- }).value();
59
+ vhostConfig.connections = _.chain([])
60
+ .concat(vhostConfig.connections, vhostConfig.connection)
61
+ .compact()
62
+ .uniq()
63
+ .map((connection) => {
64
+ return _.isString(connection) ? { url: connection } : connection;
65
+ })
66
+ .value();
57
67
  if (vhostConfig.connections.length === 0) vhostConfig.connections.push({});
58
68
  _.each(vhostConfig.connections, (connection, index) => {
59
69
  configureConnection(vhostConfig, vhostName, connection, index);
60
70
  });
61
- vhostConfig.connections = _.sortBy(vhostConfig.connections, 'index');
71
+ vhostConfig.connections = _.sortBy(vhostConfig.connections, "index");
62
72
  delete vhostConfig.connection;
63
73
  }
64
74
 
65
75
  function configureConnection(vhostConfig, vhostName, connection, index) {
66
76
  _.defaultsDeep(connection, vhostConfig.defaults.connection);
67
- connection.vhost = connection.vhost !== undefined ? connection.vhost : vhostName;
68
- connection.auth = connection.auth || getAuth(connection.user, connection.password);
69
- connection.pathname = connection.vhost === '/' ? '' : connection.vhost;
77
+ connection.vhost =
78
+ connection.vhost !== undefined ? connection.vhost : vhostName;
79
+ connection.auth =
80
+ connection.auth || getAuth(connection.user, connection.password);
81
+ connection.pathname = connection.vhost === "/" ? "" : connection.vhost;
70
82
  connection.query = connection.options;
71
83
  connection.url = connection.url || url.format(connection);
72
- connection.loggableUrl = connection.url.replace(/:[^:]*?@/, ':***@');
73
- connection.index = getConnectionIndex(vhostConfig.connectionStrategy, connection, index);
84
+ connection.loggableUrl = connection.url.replace(/:[^:]*?@/, ":***@");
85
+ connection.index = getConnectionIndex(
86
+ vhostConfig.connectionStrategy,
87
+ connection,
88
+ index
89
+ );
74
90
  configureManagementConnection(vhostConfig, vhostName, connection);
75
91
  }
76
92
 
77
93
  function configureManagementConnection(vhostConfig, vhostName, connection) {
78
94
  _.defaultsDeep(connection.management, { hostname: connection.hostname });
79
- connection.management.auth = connection.management.auth || getAuth(connection.management.user, connection.management.password) || connection.auth;
80
- connection.management.url = connection.management.url || url.format(connection.management);
81
- connection.management.loggableUrl = connection.management.url.replace(/:[^:]*?@/, ':***@');
95
+ connection.management.auth =
96
+ connection.management.auth ||
97
+ getAuth(connection.management.user, connection.management.password) ||
98
+ connection.auth;
99
+ connection.management.url =
100
+ connection.management.url || url.format(connection.management);
101
+ connection.management.loggableUrl = connection.management.url.replace(
102
+ /:[^:]*?@/,
103
+ ":***@"
104
+ );
82
105
  }
83
106
 
84
107
  function getAuth(user, password) {
85
- return user && password ? user + ':' + password : undefined;
108
+ return user && password ? user + ":" + password : undefined;
86
109
  }
87
110
 
88
111
  function getConnectionIndex(strategy, connection, index) {
89
- if (strategy === 'fixed') return index;
112
+ if (strategy === "fixed") return index;
90
113
  const host = url.parse(connection.url).host;
91
114
  if (_.has(connectionIndexes, host)) return connectionIndexes[host];
92
115
  connectionIndexes[host] = Math.random();
@@ -102,33 +125,76 @@ module.exports = _.curry((rascalConfig, next) => {
102
125
  }
103
126
 
104
127
  function configurePublications(publications, vhosts) {
105
- const defaultPublications = _.reduce(vhosts, (publications, vhost) => {
106
- _.each(vhost.exchanges, (exchange) => {
107
- const name = vhost.name === '/' ? format('/%s', exchange.name) : format('%s/%s', vhost.name, exchange.name);
108
- publications[name] = { exchange: exchange.name, vhost: vhost.name, autoCreated: true };
109
- });
110
- _.each(vhost.queues, (queue) => {
111
- const name = vhost.name === '/' ? format('/%s', queue.name) : format('%s/%s', vhost.name, queue.name);
112
- publications[name] = { queue: queue.name, vhost: vhost.name, autoCreated: true };
113
- });
114
- return publications;
115
- }, {});
116
-
117
- _.each(_.defaults({}, publications, defaultPublications), configurePublication);
128
+ const defaultPublications = _.reduce(
129
+ vhosts,
130
+ (publications, vhost) => {
131
+ _.each(vhost.exchanges, (exchange) => {
132
+ const name =
133
+ vhost.name === "/"
134
+ ? format("/%s", exchange.name)
135
+ : format("%s/%s", vhost.name, exchange.name);
136
+ publications[name] = {
137
+ exchange: exchange.name,
138
+ vhost: vhost.name,
139
+ autoCreated: true,
140
+ };
141
+ });
142
+ _.each(vhost.queues, (queue) => {
143
+ const name =
144
+ vhost.name === "/"
145
+ ? format("/%s", queue.name)
146
+ : format("%s/%s", vhost.name, queue.name);
147
+ publications[name] = {
148
+ queue: queue.name,
149
+ vhost: vhost.name,
150
+ autoCreated: true,
151
+ };
152
+ });
153
+ return publications;
154
+ },
155
+ {}
156
+ );
157
+
158
+ _.each(
159
+ _.defaults({}, publications, defaultPublications),
160
+ configurePublication
161
+ );
118
162
  }
119
163
 
120
164
  function configurePublication(publicationConfig, name) {
121
- debug('Configuring publication: %s', name);
122
- if (rascalConfig.publications[name] && rascalConfig.publications[name].vhost !== publicationConfig.vhost) throw new Error(format('Duplicate publication: %s', name));
123
- rascalConfig.publications[name] = _.defaultsDeep(publicationConfig, { name }, rascalConfig.defaults.publications);
165
+ debug("Configuring publication: %s", name);
166
+ if (
167
+ rascalConfig.publications[name] &&
168
+ rascalConfig.publications[name].vhost !== publicationConfig.vhost
169
+ )
170
+ throw new Error(format("Duplicate publication: %s", name));
171
+ rascalConfig.publications[name] = _.defaultsDeep(
172
+ publicationConfig,
173
+ { name },
174
+ rascalConfig.defaults.publications
175
+ );
124
176
  if (!rascalConfig.vhosts[publicationConfig.vhost]) return;
125
- const destination = Object.prototype.hasOwnProperty.call(publicationConfig, 'exchange')
126
- ? rascalConfig.vhosts[publicationConfig.vhost].exchanges[publicationConfig.exchange]
127
- : rascalConfig.vhosts[publicationConfig.vhost].queues[publicationConfig.queue];
128
- rascalConfig.publications[name].destination = destination.fullyQualifiedName;
129
-
130
- if (publicationConfig.encryption && _.isString(publicationConfig.encryption)) {
131
- rascalConfig.publications[name].encryption = _.defaultsDeep({ name: publicationConfig.encryption }, rascalConfig.encryption[publicationConfig.encryption]);
177
+ const destination = Object.prototype.hasOwnProperty.call(
178
+ publicationConfig,
179
+ "exchange"
180
+ )
181
+ ? rascalConfig.vhosts[publicationConfig.vhost].exchanges[
182
+ publicationConfig.exchange
183
+ ]
184
+ : rascalConfig.vhosts[publicationConfig.vhost].queues[
185
+ publicationConfig.queue
186
+ ];
187
+ rascalConfig.publications[name].destination =
188
+ destination.fullyQualifiedName;
189
+
190
+ if (
191
+ publicationConfig.encryption &&
192
+ _.isString(publicationConfig.encryption)
193
+ ) {
194
+ rascalConfig.publications[name].encryption = _.defaultsDeep(
195
+ { name: publicationConfig.encryption },
196
+ rascalConfig.encryption[publicationConfig.encryption]
197
+ );
132
198
  }
133
199
  }
134
200
 
@@ -141,23 +207,50 @@ module.exports = _.curry((rascalConfig, next) => {
141
207
  }
142
208
 
143
209
  function configureSubscriptions(subscriptions, vhosts) {
144
- const defaultSubscriptions = _.reduce(vhosts, (subscriptions, vhost) => {
145
- _.each(vhost.queues, (queue) => {
146
- const name = vhost.name === '/' ? format('/%s', queue.name) : format('%s/%s', vhost.name, queue.name);
147
- subscriptions[name] = { queue: queue.name, vhost: vhost.name, autoCreated: true };
148
- });
149
- return subscriptions;
150
- }, {});
151
- _.each(_.defaults({}, subscriptions, defaultSubscriptions), configureSubscription);
210
+ const defaultSubscriptions = _.reduce(
211
+ vhosts,
212
+ (subscriptions, vhost) => {
213
+ _.each(vhost.queues, (queue) => {
214
+ const name =
215
+ vhost.name === "/"
216
+ ? format("/%s", queue.name)
217
+ : format("%s/%s", vhost.name, queue.name);
218
+ subscriptions[name] = {
219
+ queue: queue.name,
220
+ vhost: vhost.name,
221
+ autoCreated: true,
222
+ };
223
+ });
224
+ return subscriptions;
225
+ },
226
+ {}
227
+ );
228
+ _.each(
229
+ _.defaults({}, subscriptions, defaultSubscriptions),
230
+ configureSubscription
231
+ );
152
232
  }
153
233
 
154
234
  function configureSubscription(subscriptionConfig, name) {
155
- debug('Configuring subscription: %s', name);
156
- if (rascalConfig.subscriptions[name] && rascalConfig.subscriptions[name].vhost !== subscriptionConfig.vhost) throw new Error(format('Duplicate subscription: %s', name));
157
- rascalConfig.subscriptions[name] = _.defaultsDeep(subscriptionConfig, { name }, rascalConfig.defaults.subscriptions);
235
+ debug("Configuring subscription: %s", name);
236
+ if (
237
+ rascalConfig.subscriptions[name] &&
238
+ rascalConfig.subscriptions[name].vhost !== subscriptionConfig.vhost
239
+ )
240
+ throw new Error(format("Duplicate subscription: %s", name));
241
+ rascalConfig.subscriptions[name] = _.defaultsDeep(
242
+ subscriptionConfig,
243
+ { name },
244
+ rascalConfig.defaults.subscriptions
245
+ );
158
246
  if (!rascalConfig.vhosts[subscriptionConfig.vhost]) return;
159
- subscriptionConfig.source = rascalConfig.vhosts[subscriptionConfig.vhost].queues[subscriptionConfig.queue].fullyQualifiedName;
160
- subscriptionConfig.encryption = subscriptionConfig.encryption || _.defaultsDeep({}, rascalConfig.encryption);
247
+ subscriptionConfig.source =
248
+ rascalConfig.vhosts[subscriptionConfig.vhost].queues[
249
+ subscriptionConfig.queue
250
+ ].fullyQualifiedName;
251
+ subscriptionConfig.encryption =
252
+ subscriptionConfig.encryption ||
253
+ _.defaultsDeep({}, rascalConfig.encryption);
161
254
  }
162
255
 
163
256
  function configureShovels(shovels) {
@@ -166,15 +259,28 @@ module.exports = _.curry((rascalConfig, next) => {
166
259
  }
167
260
 
168
261
  function configureShovel(shovelConfig, name) {
169
- debug('Configuring shovel: %s', name);
262
+ debug("Configuring shovel: %s", name);
170
263
  const parsedConfig = parseShovelName(name);
171
- rascalConfig.shovels[name] = _.defaultsDeep(shovelConfig, { name }, parsedConfig, rascalConfig.defaults.shovels);
264
+ rascalConfig.shovels[name] = _.defaultsDeep(
265
+ shovelConfig,
266
+ { name },
267
+ parsedConfig,
268
+ rascalConfig.defaults.shovels
269
+ );
172
270
  }
173
271
 
174
272
  function parseShovelName(name) {
175
- const pattern = XRegExp('(?<subscription>[\\w:]+)\\s*->\\s*(?<publication>[\\w:]+)');
273
+ const pattern = XRegExp(
274
+ "(?<subscription>[\\w:]+)\\s*->\\s*(?<publication>[\\w:]+)"
275
+ );
176
276
  const match = XRegExp.exec(name, pattern);
177
- return match ? { name, subscription: match.groups.subscription, publication: match.groups.publication } : { name };
277
+ return match
278
+ ? {
279
+ name,
280
+ subscription: match.groups.subscription,
281
+ publication: match.groups.publication,
282
+ }
283
+ : { name };
178
284
  }
179
285
 
180
286
  function configureCounters(counters) {
@@ -183,55 +289,100 @@ module.exports = _.curry((rascalConfig, next) => {
183
289
  }
184
290
 
185
291
  function configureCounter(counterConfig, name) {
186
- debug('Configuring counter: %s', name);
292
+ debug("Configuring counter: %s", name);
187
293
  const counterType = counterConfig.type || name;
188
- const counterDefaultConfigPath = 'defaults.redeliveries.counters.' + counterType;
294
+ const counterDefaultConfigPath =
295
+ "defaults.redeliveries.counters." + counterType;
189
296
  const counterDefaults = _.get(rascalConfig, counterDefaultConfigPath);
190
- rascalConfig.redeliveries.counters[name] = _.defaultsDeep(counterConfig, { name, type: name }, counterDefaults);
297
+ rascalConfig.redeliveries.counters[name] = _.defaultsDeep(
298
+ counterConfig,
299
+ { name, type: name },
300
+ counterDefaults
301
+ );
191
302
  }
192
303
 
193
304
  function configureExchanges(config) {
194
- const defaultExchange = { '': {} };
195
- config.exchanges = _.defaultsDeep(ensureKeyedCollection(config.exchanges), defaultExchange);
305
+ const defaultExchange = { "": {} };
306
+ config.exchanges = _.defaultsDeep(
307
+ ensureKeyedCollection(config.exchanges),
308
+ defaultExchange
309
+ );
196
310
  _.each(config.exchanges, (exchangeConfig, name) => {
197
- debug('Configuring exchange: %s', name);
198
- config.exchanges[name] = _.defaultsDeep(exchangeConfig, { name, fullyQualifiedName: fqn.qualify(name, config.namespace) }, config.defaults.exchanges);
311
+ debug("Configuring exchange: %s", name);
312
+ config.exchanges[name] = _.defaultsDeep(
313
+ exchangeConfig,
314
+ { name, fullyQualifiedName: fqn.qualify(name, config.namespace) },
315
+ config.defaults.exchanges
316
+ );
199
317
  });
200
318
  }
201
319
 
202
320
  function configureQueues(config) {
203
321
  config.queues = ensureKeyedCollection(config.queues);
204
322
  _.each(config.queues, (queueConfig, name) => {
205
- debug('Configuring queue: %s', name);
206
- queueConfig.replyTo = queueConfig.replyTo === true ? uuid() : queueConfig.replyTo;
207
- qualifyArguments(config.namespace, queueConfig.options && queueConfig.options.arguments);
208
- config.queues[name] = _.defaultsDeep(queueConfig, { name, fullyQualifiedName: fqn.qualify(name, config.namespace, queueConfig.replyTo) }, config.defaults.queues);
323
+ debug("Configuring queue: %s", name);
324
+ queueConfig.replyTo =
325
+ queueConfig.replyTo === true ? uuid() : queueConfig.replyTo;
326
+ qualifyArguments(
327
+ config.namespace,
328
+ queueConfig.options && queueConfig.options.arguments
329
+ );
330
+ config.queues[name] = _.defaultsDeep(
331
+ queueConfig,
332
+ {
333
+ name,
334
+ fullyQualifiedName: fqn.qualify(
335
+ name,
336
+ config.namespace,
337
+ queueConfig.replyTo
338
+ ),
339
+ },
340
+ config.defaults.queues
341
+ );
209
342
  });
210
343
  }
211
344
 
212
345
  function configureBindings(config) {
213
-
214
346
  config.bindings = expandBindings(ensureKeyedCollection(config.bindings));
215
347
 
216
348
  _.each(config.bindings, (bindingConfig, name) => {
217
- debug('Configuring binding: %s', name);
349
+ debug("Configuring binding: %s", name);
218
350
 
219
- config.bindings[name] = _.defaultsDeep(bindingConfig, config.defaults.bindings);
351
+ config.bindings[name] = _.defaultsDeep(
352
+ bindingConfig,
353
+ config.defaults.bindings
354
+ );
220
355
 
221
356
  if (bindingConfig.qualifyBindingKeys) {
222
- config.bindings[name].bindingKey = fqn.qualify(bindingConfig.bindingKey, config.namespace);
357
+ config.bindings[name].bindingKey = fqn.qualify(
358
+ bindingConfig.bindingKey,
359
+ config.namespace
360
+ );
223
361
  }
224
- if (bindingConfig.destinationType === 'queue') {
362
+ if (bindingConfig.destinationType === "queue") {
225
363
  const queue = config.queues[bindingConfig.destination];
226
- config.bindings[name].bindingKey = fqn.prefix(queue && queue.replyTo, bindingConfig.bindingKey, '.');
364
+ config.bindings[name].bindingKey = fqn.prefix(
365
+ queue && queue.replyTo,
366
+ bindingConfig.bindingKey,
367
+ "."
368
+ );
227
369
  }
228
370
  });
229
371
  }
230
372
 
231
373
  function parseBindingName(name) {
232
- const pattern = XRegExp('(?<source>[\\w:\\.\\-]+)\\s*(?:\\[\\s*(?<keys>.*)\\s*\\])?\\s*->\\s*(?<destination>[\\w:\\.\\-]+)');
374
+ const pattern = XRegExp(
375
+ "(?<source>[\\w:\\.\\-]+)\\s*(?:\\[\\s*(?<keys>.*)\\s*\\])?\\s*->\\s*(?<destination>[\\w:\\.\\-]+)"
376
+ );
233
377
  const match = XRegExp.exec(name, pattern);
234
- return match ? { name, source: match.groups.source, destination: match.groups.destination, bindingKeys: splitBindingKeys(match.groups.keys) } : { name };
378
+ return match
379
+ ? {
380
+ name,
381
+ source: match.groups.source,
382
+ destination: match.groups.destination,
383
+ bindingKeys: splitBindingKeys(match.groups.keys),
384
+ }
385
+ : { name };
235
386
  }
236
387
 
237
388
  function splitBindingKeys(keys) {
@@ -242,13 +393,27 @@ module.exports = _.curry((rascalConfig, next) => {
242
393
  const result = {};
243
394
  _.each(definitions, (bindingConfig, name) => {
244
395
  const parsedConfig = parseBindingName(name);
245
- const bindingKeys = _.chain([]).concat(bindingConfig.bindingKeys, bindingConfig.bindingKey, parsedConfig.bindingKeys).compact().uniq().value();
396
+ const bindingKeys = _.chain([])
397
+ .concat(
398
+ bindingConfig.bindingKeys,
399
+ bindingConfig.bindingKey,
400
+ parsedConfig.bindingKeys
401
+ )
402
+ .compact()
403
+ .uniq()
404
+ .value();
246
405
  if (bindingKeys.length <= 1) {
247
- result[name] = _({ bindingKey: bindingKeys[0] }).defaults(bindingConfig, parsedConfig).omit('bindingKeys').value();
406
+ result[name] = _({ bindingKey: bindingKeys[0] })
407
+ .defaults(bindingConfig, parsedConfig)
408
+ .omit("bindingKeys")
409
+ .value();
248
410
  return result[name];
249
411
  }
250
412
  _.each(bindingKeys, (bindingKey) => {
251
- result[format('%s:%s', name, bindingKey)] = _({ bindingKey }).defaults(bindingConfig, parsedConfig).omit('bindingKeys').value();
413
+ result[format("%s:%s", name, bindingKey)] = _({ bindingKey })
414
+ .defaults(bindingConfig, parsedConfig)
415
+ .omit("bindingKeys")
416
+ .value();
252
417
  });
253
418
  });
254
419
  return result;
@@ -256,15 +421,23 @@ module.exports = _.curry((rascalConfig, next) => {
256
421
 
257
422
  function qualifyArguments(namespace, args) {
258
423
  if (!args) return;
259
- _.each(['x-dead-letter-exchange'], (name) => {
260
- args[name] = args[name] !== undefined ? fqn.qualify(args[name], namespace) : args[name];
424
+ _.each(["x-dead-letter-exchange"], (name) => {
425
+ args[name] =
426
+ args[name] !== undefined
427
+ ? fqn.qualify(args[name], namespace)
428
+ : args[name];
261
429
  });
262
430
  }
263
431
 
264
432
  function ensureKeyedCollection(collection) {
265
433
  if (!_.isArray(collection)) return collection;
266
- return _.chain(collection).map((item) => {
267
- return _.isString(item) ? { name: item } : _.defaults(item, { name: 'unnamed-' + uuid() });
268
- }).keyBy('name').value();
434
+ return _.chain(collection)
435
+ .map((item) => {
436
+ return _.isString(item)
437
+ ? { name: item }
438
+ : _.defaults(item, { name: "unnamed-" + uuid() });
439
+ })
440
+ .keyBy("name")
441
+ .value();
269
442
  }
270
443
  });
package/lib/config/fqn.js CHANGED
@@ -5,16 +5,16 @@ module.exports = {
5
5
  };
6
6
 
7
7
  function qualify(name, namespace, unique) {
8
- if (name === '') return name;
8
+ if (name === "") return name;
9
9
  name = prefix(namespace, name);
10
10
  name = suffix(unique || undefined, name);
11
11
  return name;
12
12
  }
13
13
 
14
14
  function prefix(prefix, name, separator) {
15
- return prefix ? prefix + (separator || ':') + name : name;
15
+ return prefix ? prefix + (separator || ":") + name : name;
16
16
  }
17
17
 
18
18
  function suffix(suffix, name, separator) {
19
- return suffix ? name + (separator || ':') + suffix : name;
19
+ return suffix ? name + (separator || ":") + suffix : name;
20
20
  }
@@ -1,41 +1,44 @@
1
- const _ = require('lodash').runInContext();
2
- const defaultConfig = require('./defaults');
1
+ const _ = require("lodash").runInContext();
2
+ const defaultConfig = require("./defaults");
3
3
 
4
- module.exports = _.defaultsDeep({
5
- defaults: {
6
- vhosts: {
7
- connection: {
8
- options: {
9
- heartbeat: 50,
4
+ module.exports = _.defaultsDeep(
5
+ {
6
+ defaults: {
7
+ vhosts: {
8
+ connection: {
9
+ options: {
10
+ heartbeat: 50,
11
+ },
10
12
  },
11
- },
12
- namespace: true,
13
- exchanges: {
14
- options: {
15
- durable: false,
13
+ namespace: true,
14
+ exchanges: {
15
+ options: {
16
+ durable: false,
17
+ },
18
+ },
19
+ queues: {
20
+ purge: true,
21
+ options: {
22
+ durable: false,
23
+ },
16
24
  },
17
25
  },
18
- queues: {
19
- purge: true,
26
+ publications: {
20
27
  options: {
21
- durable: false,
28
+ persistent: false,
22
29
  },
23
30
  },
24
- },
25
- publications: {
26
- options: {
27
- persistent: false,
31
+ subscriptions: {
32
+ deferCloseChannel: 100,
28
33
  },
29
34
  },
30
- subscriptions: {
31
- deferCloseChannel: 100,
32
- },
33
- },
34
- redeliveries: {
35
- "counters": {
36
- "inMemory": {
37
- "size": 1000,
35
+ redeliveries: {
36
+ counters: {
37
+ inMemory: {
38
+ size: 1000,
39
+ },
38
40
  },
39
41
  },
40
42
  },
41
- }, defaultConfig);
43
+ defaultConfig
44
+ );