node-cqrs 0.16.0-5 → 0.16.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,40 @@
1
+ ## [0.16.3](https://github.com/snatalenko/node-cqrs/compare/v0.16.2...v0.16.3) (2022-01-28)
2
+
3
+
4
+ ### Changes
5
+
6
+ * Update dev dependencies ([e76db7b](https://github.com/snatalenko/node-cqrs/commit/e76db7be66b53afeb619bda459686e490530556f))
7
+ * Remove InMemoryView data size calculation ([fb4260b](https://github.com/snatalenko/node-cqrs/commit/fb4260b94170e371c02be5b6867ba5b1cf7e428f))
8
+
9
+
10
+ ## [0.16.2](https://github.com/snatalenko/node-cqrs/compare/v0.16.1...v0.16.2) (2021-07-06)
11
+
12
+
13
+ ### Fixes
14
+
15
+ * Vulnerabilities in dependencies ([1bdd491](https://github.com/snatalenko/node-cqrs/commit/1bdd4916e3080bd96b15d87c947f6b85e44d6d40))
16
+
17
+
18
+ ## [0.16.1](https://github.com/snatalenko/node-cqrs/compare/v0.16.0...v0.16.1) (2021-05-28)
19
+
20
+
21
+ ### Fixes
22
+
23
+ * Mark aggregateId optional on command send ([f496ecf](https://github.com/snatalenko/node-cqrs/commit/f496ecfbd5413e8e2a4c69af7848ecc3f1a5365a))
24
+
25
+ ### Changes
26
+
27
+ * Postpone view.get responses to next loop iteration ([950c2e4](https://github.com/snatalenko/node-cqrs/commit/950c2e42f62d7388b0cc668e81fb4f6718656fca))
28
+
29
+
30
+ # [0.16.0](https://github.com/snatalenko/node-cqrs/compare/v0.16.0-5...v0.16.0) (2020-03-18)
31
+
32
+
33
+ ### Fixes
34
+
35
+ * Moderate security issue in "minimist" dev dependency ([579d523](https://github.com/snatalenko/node-cqrs/commit/579d523745a6d33902a5245bc7e9f3fe843abc2b))
36
+
37
+
1
38
  # [0.16.0-5](https://github.com/snatalenko/node-cqrs/compare/v0.16.0-4...v0.16.0-5) (2020-02-19)
2
39
 
3
40
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-cqrs",
3
- "version": "0.16.0-5",
3
+ "version": "0.16.3",
4
4
  "description": "Basic ES6 backbone for CQRS app development",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,12 +42,12 @@
42
42
  "di6": "github:snatalenko/di6#v0.5.0"
43
43
  },
44
44
  "devDependencies": {
45
- "chai": "^4.2.0",
46
- "coveralls": "^3.0.9",
47
- "eslint": "^6.8.0",
48
- "jsdoc": "^3.6.3",
49
- "mocha": "^6.2.2",
50
- "nyc": "^15.0.0",
51
- "sinon": "^7.5.0"
45
+ "chai": "^4.3.6",
46
+ "coveralls": "^3.1.1",
47
+ "eslint": "^8.7.0",
48
+ "jsdoc": "^3.6.10",
49
+ "mocha": "^9.2.0",
50
+ "nyc": "^15.1.0",
51
+ "sinon": "^12.0.1"
52
52
  }
53
53
  }
package/src/CommandBus.js CHANGED
@@ -40,7 +40,7 @@ class CommandBus {
40
40
  * Format and send a command for execution
41
41
  *
42
42
  * @param {string} type
43
- * @param {string} aggregateId
43
+ * @param {string} [aggregateId]
44
44
  * @param {object} [options]
45
45
  * @param {any} [options.payload]
46
46
  * @param {object} [options.context]
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { sizeOf } = require('../utils');
3
+ const nextCycle = () => new Promise(setImmediate);
4
4
 
5
5
  /**
6
6
  * Update given value with an update Cb and return updated value.
@@ -110,6 +110,8 @@ class InMemoryView {
110
110
  if (!this._ready && !(options && options.nowait))
111
111
  await this.once('ready');
112
112
 
113
+ await nextCycle();
114
+
113
115
  return this._map.get(key);
114
116
  }
115
117
 
@@ -125,6 +127,8 @@ class InMemoryView {
125
127
  if (!this._ready)
126
128
  await this.once('ready');
127
129
 
130
+ await nextCycle();
131
+
128
132
  const r = [];
129
133
  for (const entry of this._map.entries()) {
130
134
  if (!filter || filter(entry[1], entry[0]))
@@ -254,7 +258,7 @@ class InMemoryView {
254
258
  * @returns {string}
255
259
  */
256
260
  toString() {
257
- return `${this.size} record${this.size !== 1 ? 's' : ''}, ${sizeOf(this._map)} bytes`;
261
+ return `${this.size} record${this.size !== 1 ? 's' : ''}`;
258
262
  }
259
263
  }
260
264
 
@@ -3,5 +3,4 @@
3
3
  exports.getClassName = require('./getClassName');
4
4
  exports.getHandler = require('./getHandler');
5
5
  exports.isClass = require('./isClass');
6
- exports.sizeOf = require('./sizeOf');
7
6
  exports.validateHandlers = require('./validateHandlers');
@@ -9,7 +9,7 @@ namespace NodeCqrs {
9
9
  on(commandType: string, handler: IMessageHandler): any;
10
10
 
11
11
  /** Format and send a command for execution */
12
- send(type: string, aggregateId: string, options?: { payload?: any, context?: object }, otherArgs?: object): Promise<IEventStream>;
12
+ send(type: string, aggregateId?: string, options?: { payload?: any, context?: object }, otherArgs?: object): Promise<IEventStream>;
13
13
 
14
14
  /** Send a command for execution */
15
15
  sendRaw(command: ICommand): Promise<IEventStream>;
@@ -1,5 +1,5 @@
1
1
  interface ICommandBus extends IObservable {
2
- send(commandType: string, aggregateId: Identifier, options: { payload?: object, context?: object }):
2
+ send(commandType: string, aggregateId: Identifier | undefined, options: { payload?: object, context?: object }):
3
3
  Promise<IEventStream>;
4
4
  sendRaw(ICommand):
5
5
  Promise<IEventStream>;
@@ -1,63 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Calculates an approximate object size in bytes
5
- * @param {Object} object
6
- * @return {Number} object size
7
- */
8
- module.exports = function sizeOf(object) {
9
- if (!object) throw new TypeError('object argument required');
10
-
11
- const queue = [object];
12
- let size = 0;
13
-
14
- for (let i = 0; i < queue.length; i++) {
15
-
16
- const obj = queue[i];
17
-
18
- if (typeof obj === 'boolean') {
19
- size += 4;
20
- }
21
- else if (typeof obj === 'number') {
22
- size += 8;
23
- }
24
- else if (typeof obj === 'string') {
25
- size += Buffer.byteLength(obj, 'utf-8');
26
- }
27
- else if (typeof obj === 'symbol') {
28
- size += 32;
29
- }
30
- else if (obj instanceof Date) {
31
- size += 40; // Buffer.byteLength(obj.toString(), 'utf-8');
32
- }
33
- else if (obj instanceof Buffer) {
34
- size += obj.length;
35
- }
36
- else if (obj instanceof Map) {
37
- for (const [key, innerObj] of obj) {
38
- queue.push(key);
39
- if (typeof innerObj !== 'object' || !queue.includes(innerObj))
40
- queue.push(innerObj);
41
- }
42
- }
43
- else if (obj instanceof Set) {
44
- for (const innerObj of obj) {
45
- if (typeof innerObj !== 'object' || !queue.includes(innerObj))
46
- queue.push(innerObj);
47
- }
48
- }
49
- else if (obj) {
50
- if (!Array.isArray(obj)) {
51
- for (const key of Object.keys(obj))
52
- size += Buffer.byteLength(key, 'utf-8');
53
- }
54
- for (const key of Object.keys(obj)) {
55
- const innerObj = obj[key];
56
- if (typeof innerObj !== 'object' || !queue.includes(innerObj))
57
- queue.push(innerObj);
58
- }
59
- }
60
- }
61
-
62
- return size;
63
- };