@omegup/msync 0.0.73 → 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 +26 -26
- package/index.js +26 -26
- 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
|
@@ -1239,19 +1239,20 @@ class Machine {
|
|
|
1239
1239
|
}
|
|
1240
1240
|
const wrap = (root) => root;
|
|
1241
1241
|
const runCont = async (it, cb) => {
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1242
|
+
while (true) {
|
|
1243
|
+
const { next, stop: _, clear } = it();
|
|
1244
|
+
const res = await next.then(next => ({ ok: true, next }), err => ({ ok: false, err }));
|
|
1245
|
+
if (!res.ok) {
|
|
1246
|
+
console.error(res.err);
|
|
1247
|
+
process.exit(1);
|
|
1248
|
+
}
|
|
1249
|
+
const { cont, info } = res.next;
|
|
1250
|
+
if (cb?.(info)) {
|
|
1251
|
+
await clear();
|
|
1252
|
+
throw new Error('Machine stopped');
|
|
1253
|
+
}
|
|
1254
|
+
it = cont;
|
|
1253
1255
|
}
|
|
1254
|
-
return runCont(cont, cb);
|
|
1255
1256
|
};
|
|
1256
1257
|
|
|
1257
1258
|
const merge = ({ lsource: L, rsource: R, }) => mergeIterators({ sources: { L, R } });
|
|
@@ -1446,7 +1447,7 @@ const addTeardown = (it, tr) => {
|
|
|
1446
1447
|
const changeKeys = ['fullDocument', 'fullDocumentBeforeChange'];
|
|
1447
1448
|
const subQ = (a, f) => ({ raw: g => a.raw(g.with(f)) });
|
|
1448
1449
|
const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startAt, streamName) => {
|
|
1449
|
-
const projection = { ...mapExactToObject(p, v => v), deletedAt: 1 };
|
|
1450
|
+
const projection = p ? { ...mapExactToObject(p, v => v), deletedAt: 1 } : 1;
|
|
1450
1451
|
const pipeline = [];
|
|
1451
1452
|
if (m) {
|
|
1452
1453
|
const q = $or(...changeKeys.map((k) => subQ(m, root().of(k))));
|
|
@@ -1513,19 +1514,19 @@ const actions = {
|
|
|
1513
1514
|
|
|
1514
1515
|
const getFirstStages = (view) => {
|
|
1515
1516
|
const { projection, hardMatch: pre, match } = view;
|
|
1516
|
-
const projectInput = $project_(spread(projection, {
|
|
1517
|
+
const projectInput = projection && $project_(spread(projection, {
|
|
1517
1518
|
deletedAt: ['deletedAt', 1],
|
|
1518
1519
|
_id: ['_id', 1],
|
|
1519
1520
|
}));
|
|
1520
|
-
const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1521
|
-
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;
|
|
1522
1523
|
const firstStages = (lastTS, keepNulls = false) => {
|
|
1523
1524
|
const hardQuery = $and(lastTS
|
|
1524
1525
|
? root().of('touchedAt').has($gtTs(lastTS.ts))
|
|
1525
1526
|
: root().of('deletedAt').has($eq(null)), lastTS ? null : match && $expr(match), keepNulls ? pre : hardMatch);
|
|
1526
|
-
|
|
1527
|
-
.with($match_(hardQuery))
|
|
1528
|
-
|
|
1527
|
+
const ln = link()
|
|
1528
|
+
.with($match_(hardQuery));
|
|
1529
|
+
return (projectInput ? ln.with(projectInput) : ln);
|
|
1529
1530
|
};
|
|
1530
1531
|
return { firstStages, hardMatch };
|
|
1531
1532
|
};
|
|
@@ -1731,8 +1732,8 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1731
1732
|
else if (streamNames[streamName] != hash)
|
|
1732
1733
|
throw new Error('streamName already used');
|
|
1733
1734
|
const { collection, projection, hardMatch: pre, match } = view;
|
|
1734
|
-
const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1735
|
-
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;
|
|
1736
1737
|
const job = {};
|
|
1737
1738
|
const db = collection.s.db, coll = collection.collectionName;
|
|
1738
1739
|
db.command({
|
|
@@ -1744,17 +1745,16 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1744
1745
|
name: 'touchedAt_' + new UUID().toString('base64'),
|
|
1745
1746
|
});
|
|
1746
1747
|
const last = db.collection('__last');
|
|
1747
|
-
const projectInput = $project_(spread(projection, {
|
|
1748
|
+
const projectInput = projection && $project_(spread(projection, {
|
|
1748
1749
|
deletedAt: ['deletedAt', 1],
|
|
1749
1750
|
_id: ['_id', 1],
|
|
1750
1751
|
}));
|
|
1751
1752
|
const notDeleted = root().of('deletedAt').has($eq(null));
|
|
1752
1753
|
const stages = (lastTS) => {
|
|
1753
1754
|
const hardQuery = $and(lastTS && root().of('touchedAt').has($gteTs(lastTS.ts)), hardMatch, notDeleted, match && $expr(match));
|
|
1754
|
-
|
|
1755
|
-
.with($match_(hardQuery))
|
|
1756
|
-
|
|
1757
|
-
.with(input);
|
|
1755
|
+
const ln = link()
|
|
1756
|
+
.with($match_(hardQuery));
|
|
1757
|
+
return (projectInput ? ln.with(projectInput) : ln).with(input);
|
|
1758
1758
|
};
|
|
1759
1759
|
const run = (finalInput) => {
|
|
1760
1760
|
const clear = async () => { };
|
package/index.js
CHANGED
|
@@ -1241,19 +1241,20 @@ class Machine {
|
|
|
1241
1241
|
}
|
|
1242
1242
|
const wrap = (root) => root;
|
|
1243
1243
|
const runCont = async (it, cb) => {
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1244
|
+
while (true) {
|
|
1245
|
+
const { next, stop: _, clear } = it();
|
|
1246
|
+
const res = await next.then(next => ({ ok: true, next }), err => ({ ok: false, err }));
|
|
1247
|
+
if (!res.ok) {
|
|
1248
|
+
console.error(res.err);
|
|
1249
|
+
process.exit(1);
|
|
1250
|
+
}
|
|
1251
|
+
const { cont, info } = res.next;
|
|
1252
|
+
if (cb?.(info)) {
|
|
1253
|
+
await clear();
|
|
1254
|
+
throw new Error('Machine stopped');
|
|
1255
|
+
}
|
|
1256
|
+
it = cont;
|
|
1255
1257
|
}
|
|
1256
|
-
return runCont(cont, cb);
|
|
1257
1258
|
};
|
|
1258
1259
|
|
|
1259
1260
|
const merge = ({ lsource: L, rsource: R, }) => mergeIterators({ sources: { L, R } });
|
|
@@ -1448,7 +1449,7 @@ const addTeardown = (it, tr) => {
|
|
|
1448
1449
|
const changeKeys = ['fullDocument', 'fullDocumentBeforeChange'];
|
|
1449
1450
|
const subQ = (a, f) => ({ raw: g => a.raw(g.with(f)) });
|
|
1450
1451
|
const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startAt, streamName) => {
|
|
1451
|
-
const projection = { ...mapExactToObject(p, v => v), deletedAt: 1 };
|
|
1452
|
+
const projection = p ? { ...mapExactToObject(p, v => v), deletedAt: 1 } : 1;
|
|
1452
1453
|
const pipeline = [];
|
|
1453
1454
|
if (m) {
|
|
1454
1455
|
const q = $or(...changeKeys.map((k) => subQ(m, root().of(k))));
|
|
@@ -1515,19 +1516,19 @@ const actions = {
|
|
|
1515
1516
|
|
|
1516
1517
|
const getFirstStages = (view) => {
|
|
1517
1518
|
const { projection, hardMatch: pre, match } = view;
|
|
1518
|
-
const projectInput = $project_(spread(projection, {
|
|
1519
|
+
const projectInput = projection && $project_(spread(projection, {
|
|
1519
1520
|
deletedAt: ['deletedAt', 1],
|
|
1520
1521
|
_id: ['_id', 1],
|
|
1521
1522
|
}));
|
|
1522
|
-
const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1523
|
-
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;
|
|
1524
1525
|
const firstStages = (lastTS, keepNulls = false) => {
|
|
1525
1526
|
const hardQuery = $and(lastTS
|
|
1526
1527
|
? root().of('touchedAt').has($gtTs(lastTS.ts))
|
|
1527
1528
|
: root().of('deletedAt').has($eq(null)), lastTS ? null : match && $expr(match), keepNulls ? pre : hardMatch);
|
|
1528
|
-
|
|
1529
|
-
.with($match_(hardQuery))
|
|
1530
|
-
|
|
1529
|
+
const ln = link()
|
|
1530
|
+
.with($match_(hardQuery));
|
|
1531
|
+
return (projectInput ? ln.with(projectInput) : ln);
|
|
1531
1532
|
};
|
|
1532
1533
|
return { firstStages, hardMatch };
|
|
1533
1534
|
};
|
|
@@ -1733,8 +1734,8 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1733
1734
|
else if (streamNames[streamName] != hash)
|
|
1734
1735
|
throw new Error('streamName already used');
|
|
1735
1736
|
const { collection, projection, hardMatch: pre, match } = view;
|
|
1736
|
-
const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($exists(true)) : null));
|
|
1737
|
-
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;
|
|
1738
1739
|
const job = {};
|
|
1739
1740
|
const db = collection.s.db, coll = collection.collectionName;
|
|
1740
1741
|
db.command({
|
|
@@ -1746,17 +1747,16 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1746
1747
|
name: 'touchedAt_' + new mongodb.UUID().toString('base64'),
|
|
1747
1748
|
});
|
|
1748
1749
|
const last = db.collection('__last');
|
|
1749
|
-
const projectInput = $project_(spread(projection, {
|
|
1750
|
+
const projectInput = projection && $project_(spread(projection, {
|
|
1750
1751
|
deletedAt: ['deletedAt', 1],
|
|
1751
1752
|
_id: ['_id', 1],
|
|
1752
1753
|
}));
|
|
1753
1754
|
const notDeleted = root().of('deletedAt').has($eq(null));
|
|
1754
1755
|
const stages = (lastTS) => {
|
|
1755
1756
|
const hardQuery = $and(lastTS && root().of('touchedAt').has($gteTs(lastTS.ts)), hardMatch, notDeleted, match && $expr(match));
|
|
1756
|
-
|
|
1757
|
-
.with($match_(hardQuery))
|
|
1758
|
-
|
|
1759
|
-
.with(input);
|
|
1757
|
+
const ln = link()
|
|
1758
|
+
.with($match_(hardQuery));
|
|
1759
|
+
return (projectInput ? ln.with(projectInput) : ln).with(input);
|
|
1760
1760
|
};
|
|
1761
1761
|
const run = (finalInput) => {
|
|
1762
1762
|
const clear = async () => { };
|