@omegup/msync 0.1.30 → 0.1.32
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 +36 -19
- package/index.js +36 -19
- package/package.json +1 -1
package/index.esm.js
CHANGED
|
@@ -1636,35 +1636,52 @@ async function* tailOplog(db) {
|
|
|
1636
1636
|
while (true) {
|
|
1637
1637
|
const cursor = coll.find({
|
|
1638
1638
|
ts: { $gt: lastTs },
|
|
1639
|
-
|
|
1640
|
-
|
|
1639
|
+
$or: [
|
|
1640
|
+
{
|
|
1641
|
+
ns: RegExp(`^${db.namespace}\\.(?!tmp_)(?!__).*(?<!_snapshot)$`),
|
|
1642
|
+
op: { $in: ['i', 'u'] },
|
|
1643
|
+
},
|
|
1644
|
+
{
|
|
1645
|
+
ns: 'admin.$cmd',
|
|
1646
|
+
op: 'c',
|
|
1647
|
+
'o.applyOps': {
|
|
1648
|
+
$elemMatch: {
|
|
1649
|
+
ns: RegExp(`^${db.namespace}\\.(?!tmp_)(?!__).*(?<!_snapshot)$`),
|
|
1650
|
+
op: { $in: ['i', 'u'] },
|
|
1651
|
+
},
|
|
1652
|
+
},
|
|
1653
|
+
},
|
|
1654
|
+
],
|
|
1641
1655
|
}, {
|
|
1642
1656
|
tailable: true,
|
|
1643
1657
|
awaitData: true,
|
|
1644
1658
|
noCursorTimeout: true,
|
|
1645
1659
|
});
|
|
1646
1660
|
try {
|
|
1647
|
-
for await (const
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
if (doc.o['$v'] !== 2) {
|
|
1655
|
-
throw new Error(`Expected update with $v: 2, got ${JSON.stringify(doc)}`);
|
|
1661
|
+
for await (const docs of cursor) {
|
|
1662
|
+
for (const doc of docs.op === 'c' ? docs.o['applyOps'] : [docs]) {
|
|
1663
|
+
doc.ts = docs.ts;
|
|
1664
|
+
if (doc.op === 'i' || '_id' in doc.o) {
|
|
1665
|
+
const fields = new Set(Object.keys(doc.o));
|
|
1666
|
+
fields.delete('_id');
|
|
1667
|
+
yield { fields, doc };
|
|
1656
1668
|
}
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
if (['u', 'i', 'd'].includes(updateOp)) {
|
|
1661
|
-
updatedFields.push(...Object.keys(diff[updateOp]));
|
|
1669
|
+
else {
|
|
1670
|
+
if (doc.o['$v'] !== 2) {
|
|
1671
|
+
throw new Error(`Expected update with $v: 2, got ${JSON.stringify(doc)}`);
|
|
1662
1672
|
}
|
|
1663
|
-
|
|
1664
|
-
|
|
1673
|
+
const updatedFields = [];
|
|
1674
|
+
const diff = doc.o['diff'];
|
|
1675
|
+
for (const updateOp in diff) {
|
|
1676
|
+
if (['u', 'i', 'd'].includes(updateOp)) {
|
|
1677
|
+
updatedFields.push(...Object.keys(diff[updateOp]));
|
|
1678
|
+
}
|
|
1679
|
+
else if (updateOp.startsWith('s')) {
|
|
1680
|
+
updatedFields.push(updateOp.slice(1));
|
|
1681
|
+
}
|
|
1665
1682
|
}
|
|
1683
|
+
yield { fields: new Set(updatedFields), doc };
|
|
1666
1684
|
}
|
|
1667
|
-
yield { fields: new Set(updatedFields), doc };
|
|
1668
1685
|
}
|
|
1669
1686
|
}
|
|
1670
1687
|
}
|
package/index.js
CHANGED
|
@@ -1638,35 +1638,52 @@ async function* tailOplog(db) {
|
|
|
1638
1638
|
while (true) {
|
|
1639
1639
|
const cursor = coll.find({
|
|
1640
1640
|
ts: { $gt: lastTs },
|
|
1641
|
-
|
|
1642
|
-
|
|
1641
|
+
$or: [
|
|
1642
|
+
{
|
|
1643
|
+
ns: RegExp(`^${db.namespace}\\.(?!tmp_)(?!__).*(?<!_snapshot)$`),
|
|
1644
|
+
op: { $in: ['i', 'u'] },
|
|
1645
|
+
},
|
|
1646
|
+
{
|
|
1647
|
+
ns: 'admin.$cmd',
|
|
1648
|
+
op: 'c',
|
|
1649
|
+
'o.applyOps': {
|
|
1650
|
+
$elemMatch: {
|
|
1651
|
+
ns: RegExp(`^${db.namespace}\\.(?!tmp_)(?!__).*(?<!_snapshot)$`),
|
|
1652
|
+
op: { $in: ['i', 'u'] },
|
|
1653
|
+
},
|
|
1654
|
+
},
|
|
1655
|
+
},
|
|
1656
|
+
],
|
|
1643
1657
|
}, {
|
|
1644
1658
|
tailable: true,
|
|
1645
1659
|
awaitData: true,
|
|
1646
1660
|
noCursorTimeout: true,
|
|
1647
1661
|
});
|
|
1648
1662
|
try {
|
|
1649
|
-
for await (const
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
if (doc.o['$v'] !== 2) {
|
|
1657
|
-
throw new Error(`Expected update with $v: 2, got ${JSON.stringify(doc)}`);
|
|
1663
|
+
for await (const docs of cursor) {
|
|
1664
|
+
for (const doc of docs.op === 'c' ? docs.o['applyOps'] : [docs]) {
|
|
1665
|
+
doc.ts = docs.ts;
|
|
1666
|
+
if (doc.op === 'i' || '_id' in doc.o) {
|
|
1667
|
+
const fields = new Set(Object.keys(doc.o));
|
|
1668
|
+
fields.delete('_id');
|
|
1669
|
+
yield { fields, doc };
|
|
1658
1670
|
}
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
if (['u', 'i', 'd'].includes(updateOp)) {
|
|
1663
|
-
updatedFields.push(...Object.keys(diff[updateOp]));
|
|
1671
|
+
else {
|
|
1672
|
+
if (doc.o['$v'] !== 2) {
|
|
1673
|
+
throw new Error(`Expected update with $v: 2, got ${JSON.stringify(doc)}`);
|
|
1664
1674
|
}
|
|
1665
|
-
|
|
1666
|
-
|
|
1675
|
+
const updatedFields = [];
|
|
1676
|
+
const diff = doc.o['diff'];
|
|
1677
|
+
for (const updateOp in diff) {
|
|
1678
|
+
if (['u', 'i', 'd'].includes(updateOp)) {
|
|
1679
|
+
updatedFields.push(...Object.keys(diff[updateOp]));
|
|
1680
|
+
}
|
|
1681
|
+
else if (updateOp.startsWith('s')) {
|
|
1682
|
+
updatedFields.push(updateOp.slice(1));
|
|
1683
|
+
}
|
|
1667
1684
|
}
|
|
1685
|
+
yield { fields: new Set(updatedFields), doc };
|
|
1668
1686
|
}
|
|
1669
|
-
yield { fields: new Set(updatedFields), doc };
|
|
1670
1687
|
}
|
|
1671
1688
|
}
|
|
1672
1689
|
}
|