@omegup/msync 0.1.33 → 0.1.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.
package/index.esm.js CHANGED
@@ -1763,8 +1763,8 @@ const loop = async (db) => {
1763
1763
  const m = watchers.get(doc.ns);
1764
1764
  if (!m)
1765
1765
  continue;
1766
- for (const { cb, keys, rem } of [...m.values()]) {
1767
- if (!keys || keys.some(k => fields.has(k))) {
1766
+ for (const { cb, keys, rem, match } of [...m.values()]) {
1767
+ if (!keys || (doc.op === 'i' ? (match ? true : true) : keys.some(k => fields.has(k)))) {
1768
1768
  cb(doc);
1769
1769
  rem();
1770
1770
  }
@@ -1772,7 +1772,7 @@ const loop = async (db) => {
1772
1772
  }
1773
1773
  }
1774
1774
  };
1775
- const register = (coll, keys, cb) => {
1775
+ const register = (coll, keys, match, cb) => {
1776
1776
  const ns = coll.namespace;
1777
1777
  let m = watchers.get(ns);
1778
1778
  if (!m)
@@ -1783,7 +1783,7 @@ const register = (coll, keys, cb) => {
1783
1783
  if (m.size === 0)
1784
1784
  watchers.delete(ns);
1785
1785
  };
1786
- m.set(id, { cb, keys, rem });
1786
+ m.set(id, { cb, keys, match, rem });
1787
1787
  if (!running) {
1788
1788
  running = true;
1789
1789
  loop(coll.s.db);
@@ -1798,7 +1798,7 @@ const makeWatchStream = async ({ collection, projection: p, hardMatch: m }, stre
1798
1798
  .updateMany({ touchedAt: maxTimestamp }, [{ $set: { touchedAt: '$$CLUSTER_TIME' } }]))).then(() => { }));
1799
1799
  const projection = { ...(p ? mapExactToObject(p, v => v) : {}), deletedAt: 1 };
1800
1800
  let notify = makePromise();
1801
- register(collection, p ? Object.keys(projection) : null, doc => {
1801
+ register(collection, p ? Object.keys(projection) : null, m, doc => {
1802
1802
  log(streamName, 'change detected', doc);
1803
1803
  notify.resolve(doc);
1804
1804
  });
package/index.js CHANGED
@@ -1765,8 +1765,8 @@ const loop = async (db) => {
1765
1765
  const m = watchers.get(doc.ns);
1766
1766
  if (!m)
1767
1767
  continue;
1768
- for (const { cb, keys, rem } of [...m.values()]) {
1769
- if (!keys || keys.some(k => fields.has(k))) {
1768
+ for (const { cb, keys, rem, match } of [...m.values()]) {
1769
+ if (!keys || (doc.op === 'i' ? (match ? true : true) : keys.some(k => fields.has(k)))) {
1770
1770
  cb(doc);
1771
1771
  rem();
1772
1772
  }
@@ -1774,7 +1774,7 @@ const loop = async (db) => {
1774
1774
  }
1775
1775
  }
1776
1776
  };
1777
- const register = (coll, keys, cb) => {
1777
+ const register = (coll, keys, match, cb) => {
1778
1778
  const ns = coll.namespace;
1779
1779
  let m = watchers.get(ns);
1780
1780
  if (!m)
@@ -1785,7 +1785,7 @@ const register = (coll, keys, cb) => {
1785
1785
  if (m.size === 0)
1786
1786
  watchers.delete(ns);
1787
1787
  };
1788
- m.set(id, { cb, keys, rem });
1788
+ m.set(id, { cb, keys, match, rem });
1789
1789
  if (!running) {
1790
1790
  running = true;
1791
1791
  loop(coll.s.db);
@@ -1800,7 +1800,7 @@ const makeWatchStream = async ({ collection, projection: p, hardMatch: m }, stre
1800
1800
  .updateMany({ touchedAt: maxTimestamp }, [{ $set: { touchedAt: '$$CLUSTER_TIME' } }]))).then(() => { }));
1801
1801
  const projection = { ...(p ? mapExactToObject(p, v => v) : {}), deletedAt: 1 };
1802
1802
  let notify = makePromise();
1803
- register(collection, p ? Object.keys(projection) : null, doc => {
1803
+ register(collection, p ? Object.keys(projection) : null, m, doc => {
1804
1804
  log(streamName, 'change detected', doc);
1805
1805
  notify.resolve(doc);
1806
1806
  });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "index.esm.js",
4
4
  "typings": "index.d.ts",
5
5
  "name": "@omegup/msync",
6
- "version": "0.1.33",
6
+ "version": "0.1.35",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",