@livequery/nestjs 1.0.34 → 1.0.35

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.
@@ -15,23 +15,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.LivequeryWebsocketSync = void 0;
16
16
  const websockets_1 = require("@nestjs/websockets");
17
17
  const rxjs_1 = require("rxjs");
18
- const operators_1 = require("rxjs/operators");
19
18
  let LivequeryWebsocketSync = class LivequeryWebsocketSync {
20
19
  connections = new Map();
21
20
  refs = new Map();
22
21
  changes = new rxjs_1.Subject();
23
22
  constructor() {
24
- this.changes.pipe((0, operators_1.mergeMap)(change => {
25
- const map = new Map();
26
- if (!map.has(change.ref))
27
- map.set(change.ref, []);
28
- map.get(change.ref).push(change);
29
- return [...map.entries()].map(([ref, changes]) => ({ ref, changes }));
30
- })).subscribe(({ ref, changes }) => {
31
- const connections = this.refs.get(ref);
23
+ this.changes.pipe().subscribe(({ ref, data, type }) => {
24
+ const connections = new Set([
25
+ ...this.refs.get(ref) || [],
26
+ ...this.refs.get(`${ref}/${data.id}`) || []
27
+ ]);
32
28
  if (!connections)
33
29
  return;
34
- const payload = JSON.stringify({ event: 'sync', data: { changes } });
30
+ const payload = JSON.stringify({ event: 'sync', data: { changes: [{ ref, data, type }] } });
35
31
  for (const cid of connections) {
36
32
  const connection = this.connections.get(cid);
37
33
  connection && connection.socket.OPEN && connection.socket.send(payload);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "repository": {
4
4
  "url": "git@github.com:livequery/nestjs.git"
5
5
  },
6
- "version": "1.0.34",
6
+ "version": "1.0.35",
7
7
  "description": "",
8
8
  "main": "build/index.js",
9
9
  "types": "build/index.d.ts",