@omegup/msync 0.0.74 → 0.0.75
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.d.ts +1 -1
- package/index.esm.js +14 -15
- package/index.js +14 -15
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -370,7 +370,7 @@ type OPick<V, K extends StrKey<V>, E extends StrKey<V> = never> = O & Pick<V, K
|
|
|
370
370
|
type OPickD<V extends Model, K extends StrKey<V>> = OPick<V, K, 'deletedAt' | '_id'>;
|
|
371
371
|
type View<V extends Model, K extends StrKey<V>> = {
|
|
372
372
|
collection: ReadonlyCollection<V | Del>;
|
|
373
|
-
projection: ExactKeys<K
|
|
373
|
+
projection: ExactKeys<K> | null;
|
|
374
374
|
match?: Expr<boolean, OPickD<V, K>>;
|
|
375
375
|
hardMatch?: Query<V>;
|
|
376
376
|
};
|
package/index.esm.js
CHANGED
|
@@ -1240,7 +1240,7 @@ class Machine {
|
|
|
1240
1240
|
const wrap = (root) => root;
|
|
1241
1241
|
const runCont = async (it, cb) => {
|
|
1242
1242
|
while (true) {
|
|
1243
|
-
const { next, clear } = it();
|
|
1243
|
+
const { next, stop: _, clear } = it();
|
|
1244
1244
|
const res = await next.then(next => ({ ok: true, next }), err => ({ ok: false, err }));
|
|
1245
1245
|
if (!res.ok) {
|
|
1246
1246
|
console.error(res.err);
|
|
@@ -1447,7 +1447,7 @@ const addTeardown = (it, tr) => {
|
|
|
1447
1447
|
const changeKeys = ['fullDocument', 'fullDocumentBeforeChange'];
|
|
1448
1448
|
const subQ = (a, f) => ({ raw: g => a.raw(g.with(f)) });
|
|
1449
1449
|
const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startAt, streamName) => {
|
|
1450
|
-
const projection = { ...mapExactToObject(p, v => v), deletedAt: 1 };
|
|
1450
|
+
const projection = p ? { ...mapExactToObject(p, v => v), deletedAt: 1 } : 1;
|
|
1451
1451
|
const pipeline = [];
|
|
1452
1452
|
if (m) {
|
|
1453
1453
|
const q = $or(...changeKeys.map((k) => subQ(m, root().of(k))));
|
|
@@ -1514,19 +1514,19 @@ const actions = {
|
|
|
1514
1514
|
|
|
1515
1515
|
const getFirstStages = (view) => {
|
|
1516
1516
|
const { projection, hardMatch: pre, match } = view;
|
|
1517
|
-
const projectInput = $project_(spread(projection, {
|
|
1517
|
+
const projectInput = projection && $project_(spread(projection, {
|
|
1518
1518
|
deletedAt: ['deletedAt', 1],
|
|
1519
1519
|
_id: ['_id', 1],
|
|
1520
1520
|
}));
|
|
1521
|
-
const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1522
|
-
const hardMatch = $and(pre, ...removeNotYetSynchronizedFields);
|
|
1521
|
+
const removeNotYetSynchronizedFields = projection && Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1522
|
+
const hardMatch = removeNotYetSynchronizedFields ? $and(pre, ...removeNotYetSynchronizedFields) : pre;
|
|
1523
1523
|
const firstStages = (lastTS, keepNulls = false) => {
|
|
1524
1524
|
const hardQuery = $and(lastTS
|
|
1525
1525
|
? root().of('touchedAt').has($gtTs(lastTS.ts))
|
|
1526
1526
|
: root().of('deletedAt').has($eq(null)), lastTS ? null : match && $expr(match), keepNulls ? pre : hardMatch);
|
|
1527
|
-
|
|
1528
|
-
.with($match_(hardQuery))
|
|
1529
|
-
|
|
1527
|
+
const ln = link()
|
|
1528
|
+
.with($match_(hardQuery));
|
|
1529
|
+
return (projectInput ? ln.with(projectInput) : ln);
|
|
1530
1530
|
};
|
|
1531
1531
|
return { firstStages, hardMatch };
|
|
1532
1532
|
};
|
|
@@ -1732,8 +1732,8 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1732
1732
|
else if (streamNames[streamName] != hash)
|
|
1733
1733
|
throw new Error('streamName already used');
|
|
1734
1734
|
const { collection, projection, hardMatch: pre, match } = view;
|
|
1735
|
-
const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1736
|
-
const hardMatch = $and(pre, ...removeNotYetSynchronizedFields);
|
|
1735
|
+
const removeNotYetSynchronizedFields = projection && Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1736
|
+
const hardMatch = removeNotYetSynchronizedFields ? $and(pre, ...removeNotYetSynchronizedFields) : pre;
|
|
1737
1737
|
const job = {};
|
|
1738
1738
|
const db = collection.s.db, coll = collection.collectionName;
|
|
1739
1739
|
db.command({
|
|
@@ -1745,17 +1745,16 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1745
1745
|
name: 'touchedAt_' + new UUID().toString('base64'),
|
|
1746
1746
|
});
|
|
1747
1747
|
const last = db.collection('__last');
|
|
1748
|
-
const projectInput = $project_(spread(projection, {
|
|
1748
|
+
const projectInput = projection && $project_(spread(projection, {
|
|
1749
1749
|
deletedAt: ['deletedAt', 1],
|
|
1750
1750
|
_id: ['_id', 1],
|
|
1751
1751
|
}));
|
|
1752
1752
|
const notDeleted = root().of('deletedAt').has($eq(null));
|
|
1753
1753
|
const stages = (lastTS) => {
|
|
1754
1754
|
const hardQuery = $and(lastTS && root().of('touchedAt').has($gteTs(lastTS.ts)), hardMatch, notDeleted, match && $expr(match));
|
|
1755
|
-
|
|
1756
|
-
.with($match_(hardQuery))
|
|
1757
|
-
|
|
1758
|
-
.with(input);
|
|
1755
|
+
const ln = link()
|
|
1756
|
+
.with($match_(hardQuery));
|
|
1757
|
+
return (projectInput ? ln.with(projectInput) : ln).with(input);
|
|
1759
1758
|
};
|
|
1760
1759
|
const run = (finalInput) => {
|
|
1761
1760
|
const clear = async () => { };
|
package/index.js
CHANGED
|
@@ -1242,7 +1242,7 @@ class Machine {
|
|
|
1242
1242
|
const wrap = (root) => root;
|
|
1243
1243
|
const runCont = async (it, cb) => {
|
|
1244
1244
|
while (true) {
|
|
1245
|
-
const { next, clear } = it();
|
|
1245
|
+
const { next, stop: _, clear } = it();
|
|
1246
1246
|
const res = await next.then(next => ({ ok: true, next }), err => ({ ok: false, err }));
|
|
1247
1247
|
if (!res.ok) {
|
|
1248
1248
|
console.error(res.err);
|
|
@@ -1449,7 +1449,7 @@ const addTeardown = (it, tr) => {
|
|
|
1449
1449
|
const changeKeys = ['fullDocument', 'fullDocumentBeforeChange'];
|
|
1450
1450
|
const subQ = (a, f) => ({ raw: g => a.raw(g.with(f)) });
|
|
1451
1451
|
const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startAt, streamName) => {
|
|
1452
|
-
const projection = { ...mapExactToObject(p, v => v), deletedAt: 1 };
|
|
1452
|
+
const projection = p ? { ...mapExactToObject(p, v => v), deletedAt: 1 } : 1;
|
|
1453
1453
|
const pipeline = [];
|
|
1454
1454
|
if (m) {
|
|
1455
1455
|
const q = $or(...changeKeys.map((k) => subQ(m, root().of(k))));
|
|
@@ -1516,19 +1516,19 @@ const actions = {
|
|
|
1516
1516
|
|
|
1517
1517
|
const getFirstStages = (view) => {
|
|
1518
1518
|
const { projection, hardMatch: pre, match } = view;
|
|
1519
|
-
const projectInput = $project_(spread(projection, {
|
|
1519
|
+
const projectInput = projection && $project_(spread(projection, {
|
|
1520
1520
|
deletedAt: ['deletedAt', 1],
|
|
1521
1521
|
_id: ['_id', 1],
|
|
1522
1522
|
}));
|
|
1523
|
-
const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1524
|
-
const hardMatch = $and(pre, ...removeNotYetSynchronizedFields);
|
|
1523
|
+
const removeNotYetSynchronizedFields = projection && Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1524
|
+
const hardMatch = removeNotYetSynchronizedFields ? $and(pre, ...removeNotYetSynchronizedFields) : pre;
|
|
1525
1525
|
const firstStages = (lastTS, keepNulls = false) => {
|
|
1526
1526
|
const hardQuery = $and(lastTS
|
|
1527
1527
|
? root().of('touchedAt').has($gtTs(lastTS.ts))
|
|
1528
1528
|
: root().of('deletedAt').has($eq(null)), lastTS ? null : match && $expr(match), keepNulls ? pre : hardMatch);
|
|
1529
|
-
|
|
1530
|
-
.with($match_(hardQuery))
|
|
1531
|
-
|
|
1529
|
+
const ln = link()
|
|
1530
|
+
.with($match_(hardQuery));
|
|
1531
|
+
return (projectInput ? ln.with(projectInput) : ln);
|
|
1532
1532
|
};
|
|
1533
1533
|
return { firstStages, hardMatch };
|
|
1534
1534
|
};
|
|
@@ -1734,8 +1734,8 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1734
1734
|
else if (streamNames[streamName] != hash)
|
|
1735
1735
|
throw new Error('streamName already used');
|
|
1736
1736
|
const { collection, projection, hardMatch: pre, match } = view;
|
|
1737
|
-
const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1738
|
-
const hardMatch = $and(pre, ...removeNotYetSynchronizedFields);
|
|
1737
|
+
const removeNotYetSynchronizedFields = projection && Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1738
|
+
const hardMatch = removeNotYetSynchronizedFields ? $and(pre, ...removeNotYetSynchronizedFields) : pre;
|
|
1739
1739
|
const job = {};
|
|
1740
1740
|
const db = collection.s.db, coll = collection.collectionName;
|
|
1741
1741
|
db.command({
|
|
@@ -1747,17 +1747,16 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1747
1747
|
name: 'touchedAt_' + new mongodb.UUID().toString('base64'),
|
|
1748
1748
|
});
|
|
1749
1749
|
const last = db.collection('__last');
|
|
1750
|
-
const projectInput = $project_(spread(projection, {
|
|
1750
|
+
const projectInput = projection && $project_(spread(projection, {
|
|
1751
1751
|
deletedAt: ['deletedAt', 1],
|
|
1752
1752
|
_id: ['_id', 1],
|
|
1753
1753
|
}));
|
|
1754
1754
|
const notDeleted = root().of('deletedAt').has($eq(null));
|
|
1755
1755
|
const stages = (lastTS) => {
|
|
1756
1756
|
const hardQuery = $and(lastTS && root().of('touchedAt').has($gteTs(lastTS.ts)), hardMatch, notDeleted, match && $expr(match));
|
|
1757
|
-
|
|
1758
|
-
.with($match_(hardQuery))
|
|
1759
|
-
|
|
1760
|
-
.with(input);
|
|
1757
|
+
const ln = link()
|
|
1758
|
+
.with($match_(hardQuery));
|
|
1759
|
+
return (projectInput ? ln.with(projectInput) : ln).with(input);
|
|
1761
1760
|
};
|
|
1762
1761
|
const run = (finalInput) => {
|
|
1763
1762
|
const clear = async () => { };
|