@omegup/msync 0.0.45 → 0.0.46
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 +17 -12
- package/index.js +17 -12
- package/package.json +1 -1
package/index.esm.js
CHANGED
|
@@ -1276,18 +1276,18 @@ const $outerLookup = (p, outer) => (l) => $lookup1({
|
|
|
1276
1276
|
left: l(emptyDelta()),
|
|
1277
1277
|
}, outer);
|
|
1278
1278
|
|
|
1279
|
-
const
|
|
1280
|
-
return (op, args) =>
|
|
1279
|
+
const filterUndefined = (applyOperator) => {
|
|
1280
|
+
return (op, args) => applyOperator(op, args.filter(defined));
|
|
1281
1281
|
};
|
|
1282
|
-
const combine = (op,
|
|
1283
|
-
const
|
|
1284
|
-
return
|
|
1282
|
+
const combine = (op, applyOperatorToPreItems) => (...args) => {
|
|
1283
|
+
const mapToItems = applyOperatorToPreItems(op, args);
|
|
1284
|
+
return mapToItems && { raw: field => mapToItems(x => x.raw(field)) };
|
|
1285
1285
|
};
|
|
1286
|
-
const all = (op, x) =>
|
|
1286
|
+
const all = (op, x) => x.length === 0 ? undefined : f => ({ [op]: x.map(f) });
|
|
1287
1287
|
const first = (op, x) => (x.length === 1 ? f => f(x[0]) : all(op, x));
|
|
1288
|
-
const $and = combine('$and',
|
|
1289
|
-
const $nor = combine('$nor',
|
|
1290
|
-
const $or = combine('$or',
|
|
1288
|
+
const $and = combine('$and', filterUndefined(first));
|
|
1289
|
+
const $nor = combine('$nor', filterUndefined(all));
|
|
1290
|
+
const $or = combine('$or', filterUndefined(first));
|
|
1291
1291
|
|
|
1292
1292
|
const $matchDelta = (query) => concatStages($replaceWithDelta(ite(query, root().expr(), nil)), $match_($or(root().of('after').has($ne(null)), root().of('before').has($ne(null)))));
|
|
1293
1293
|
|
|
@@ -1484,7 +1484,9 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1484
1484
|
streamNames[streamName] = hash;
|
|
1485
1485
|
else if (streamNames[streamName] != hash)
|
|
1486
1486
|
throw new Error(`streamName ${streamName} already used`);
|
|
1487
|
-
const { collection, projection, hardMatch, match } = view;
|
|
1487
|
+
const { collection, projection, hardMatch: pre, match } = view;
|
|
1488
|
+
const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($ne(null)) : null));
|
|
1489
|
+
const hardMatch = $and(pre, ...removeNotYetSynchronizedFields);
|
|
1488
1490
|
const job = {};
|
|
1489
1491
|
const db = collection.s.db, coll = collection.collectionName;
|
|
1490
1492
|
db.command({
|
|
@@ -1493,7 +1495,7 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1493
1495
|
});
|
|
1494
1496
|
createIndex(collection, { touchedAt: 1 }, hardMatch
|
|
1495
1497
|
? {
|
|
1496
|
-
partialFilterExpression: hardMatch,
|
|
1498
|
+
partialFilterExpression: hardMatch.raw(root()),
|
|
1497
1499
|
name: 'touchedAt_hard_' + new UUID().toString('base64'),
|
|
1498
1500
|
}
|
|
1499
1501
|
: {}).catch(e => e.code == 86 || Promise.reject(e));
|
|
@@ -1637,7 +1639,10 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1637
1639
|
const step8 = (l) => {
|
|
1638
1640
|
return nextData(l.aggResult.cursor.firstBatch)(() => l.stream
|
|
1639
1641
|
.tryNext()
|
|
1640
|
-
.catch(err => {
|
|
1642
|
+
.catch(err => {
|
|
1643
|
+
log('restarting', err);
|
|
1644
|
+
return 1;
|
|
1645
|
+
})
|
|
1641
1646
|
.then(doc => (doc ? next(step2, 'restart') : step8(l))), 'wait for change');
|
|
1642
1647
|
};
|
|
1643
1648
|
return stop;
|
package/index.js
CHANGED
|
@@ -1278,18 +1278,18 @@ const $outerLookup = (p, outer) => (l) => $lookup1({
|
|
|
1278
1278
|
left: l(emptyDelta()),
|
|
1279
1279
|
}, outer);
|
|
1280
1280
|
|
|
1281
|
-
const
|
|
1282
|
-
return (op, args) =>
|
|
1281
|
+
const filterUndefined = (applyOperator) => {
|
|
1282
|
+
return (op, args) => applyOperator(op, args.filter(defined));
|
|
1283
1283
|
};
|
|
1284
|
-
const combine = (op,
|
|
1285
|
-
const
|
|
1286
|
-
return
|
|
1284
|
+
const combine = (op, applyOperatorToPreItems) => (...args) => {
|
|
1285
|
+
const mapToItems = applyOperatorToPreItems(op, args);
|
|
1286
|
+
return mapToItems && { raw: field => mapToItems(x => x.raw(field)) };
|
|
1287
1287
|
};
|
|
1288
|
-
const all = (op, x) =>
|
|
1288
|
+
const all = (op, x) => x.length === 0 ? undefined : f => ({ [op]: x.map(f) });
|
|
1289
1289
|
const first = (op, x) => (x.length === 1 ? f => f(x[0]) : all(op, x));
|
|
1290
|
-
const $and = combine('$and',
|
|
1291
|
-
const $nor = combine('$nor',
|
|
1292
|
-
const $or = combine('$or',
|
|
1290
|
+
const $and = combine('$and', filterUndefined(first));
|
|
1291
|
+
const $nor = combine('$nor', filterUndefined(all));
|
|
1292
|
+
const $or = combine('$or', filterUndefined(first));
|
|
1293
1293
|
|
|
1294
1294
|
const $matchDelta = (query) => concatStages($replaceWithDelta(ite(query, root().expr(), nil)), $match_($or(root().of('after').has($ne(null)), root().of('before').has($ne(null)))));
|
|
1295
1295
|
|
|
@@ -1486,7 +1486,9 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1486
1486
|
streamNames[streamName] = hash;
|
|
1487
1487
|
else if (streamNames[streamName] != hash)
|
|
1488
1488
|
throw new Error(`streamName ${streamName} already used`);
|
|
1489
|
-
const { collection, projection, hardMatch, match } = view;
|
|
1489
|
+
const { collection, projection, hardMatch: pre, match } = view;
|
|
1490
|
+
const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($ne(null)) : null));
|
|
1491
|
+
const hardMatch = $and(pre, ...removeNotYetSynchronizedFields);
|
|
1490
1492
|
const job = {};
|
|
1491
1493
|
const db = collection.s.db, coll = collection.collectionName;
|
|
1492
1494
|
db.command({
|
|
@@ -1495,7 +1497,7 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1495
1497
|
});
|
|
1496
1498
|
createIndex(collection, { touchedAt: 1 }, hardMatch
|
|
1497
1499
|
? {
|
|
1498
|
-
partialFilterExpression: hardMatch,
|
|
1500
|
+
partialFilterExpression: hardMatch.raw(root()),
|
|
1499
1501
|
name: 'touchedAt_hard_' + new mongodb.UUID().toString('base64'),
|
|
1500
1502
|
}
|
|
1501
1503
|
: {}).catch(e => e.code == 86 || Promise.reject(e));
|
|
@@ -1639,7 +1641,10 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1639
1641
|
const step8 = (l) => {
|
|
1640
1642
|
return nextData(l.aggResult.cursor.firstBatch)(() => l.stream
|
|
1641
1643
|
.tryNext()
|
|
1642
|
-
.catch(err => {
|
|
1644
|
+
.catch(err => {
|
|
1645
|
+
log('restarting', err);
|
|
1646
|
+
return 1;
|
|
1647
|
+
})
|
|
1643
1648
|
.then(doc => (doc ? next(step2, 'restart') : step8(l))), 'wait for change');
|
|
1644
1649
|
};
|
|
1645
1650
|
return stop;
|