@omegup/msync 0.0.45 → 0.0.47

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.
Files changed (3) hide show
  1. package/index.esm.js +16 -12
  2. package/index.js +16 -12
  3. 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 make = (alter) => {
1280
- return (op, args) => alter(op, args.filter(defined));
1279
+ const filterUndefined = (applyOperator) => {
1280
+ return (op, args) => applyOperator(op, args.filter(defined));
1281
1281
  };
1282
- const combine = (op, make) => (...args) => {
1283
- const q = make(op, args);
1284
- return q && { raw: field => q(x => x.raw(field)) };
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) => (x.length === 0 ? undefined : f => ({ [op]: x.map(f) }));
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', make(first));
1289
- const $nor = combine('$nor', make(all));
1290
- const $or = combine('$or', make(first));
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
 
@@ -1485,6 +1485,7 @@ const executes$1 = (view, input, streamName) => {
1485
1485
  else if (streamNames[streamName] != hash)
1486
1486
  throw new Error(`streamName ${streamName} already used`);
1487
1487
  const { collection, projection, hardMatch, match } = view;
1488
+ const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($ne(null)) : null));
1488
1489
  const job = {};
1489
1490
  const db = collection.s.db, coll = collection.collectionName;
1490
1491
  db.command({
@@ -1493,7 +1494,7 @@ const executes$1 = (view, input, streamName) => {
1493
1494
  });
1494
1495
  createIndex(collection, { touchedAt: 1 }, hardMatch
1495
1496
  ? {
1496
- partialFilterExpression: hardMatch,
1497
+ partialFilterExpression: hardMatch.raw(root()),
1497
1498
  name: 'touchedAt_hard_' + new UUID().toString('base64'),
1498
1499
  }
1499
1500
  : {}).catch(e => e.code == 86 || Promise.reject(e));
@@ -1568,7 +1569,7 @@ const executes$1 = (view, input, streamName) => {
1568
1569
  const step3 = (lastTS) => async () => {
1569
1570
  const hardQuery = $and(lastTS
1570
1571
  ? root().of('touchedAt').has($gteTs(lastTS.ts))
1571
- : root().of('deletedAt').has($eq(null)), lastTS ? null : match && $expr(match), hardMatch);
1572
+ : root().of('deletedAt').has($eq(null)), lastTS ? null : match && $expr(match), hardMatch, ...removeNotYetSynchronizedFields);
1572
1573
  const notDeleted = eq($ifNull(root().of('deletedAt').expr(), nil))(nil);
1573
1574
  const query = match ? and(notDeleted, match) : notDeleted;
1574
1575
  const replaceRaw = $replaceWith_(field({
@@ -1637,7 +1638,10 @@ const executes$1 = (view, input, streamName) => {
1637
1638
  const step8 = (l) => {
1638
1639
  return nextData(l.aggResult.cursor.firstBatch)(() => l.stream
1639
1640
  .tryNext()
1640
- .catch(err => { log('restarting', err); return 1; })
1641
+ .catch(err => {
1642
+ log('restarting', err);
1643
+ return 1;
1644
+ })
1641
1645
  .then(doc => (doc ? next(step2, 'restart') : step8(l))), 'wait for change');
1642
1646
  };
1643
1647
  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 make = (alter) => {
1282
- return (op, args) => alter(op, args.filter(defined));
1281
+ const filterUndefined = (applyOperator) => {
1282
+ return (op, args) => applyOperator(op, args.filter(defined));
1283
1283
  };
1284
- const combine = (op, make) => (...args) => {
1285
- const q = make(op, args);
1286
- return q && { raw: field => q(x => x.raw(field)) };
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) => (x.length === 0 ? undefined : f => ({ [op]: x.map(f) }));
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', make(first));
1291
- const $nor = combine('$nor', make(all));
1292
- const $or = combine('$or', make(first));
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
 
@@ -1487,6 +1487,7 @@ const executes$1 = (view, input, streamName) => {
1487
1487
  else if (streamNames[streamName] != hash)
1488
1488
  throw new Error(`streamName ${streamName} already used`);
1489
1489
  const { collection, projection, hardMatch, match } = view;
1490
+ const removeNotYetSynchronizedFields = Object.values(mapExactToObject(projection, (_, k) => k.startsWith('_') ? root().of(k).has($ne(null)) : null));
1490
1491
  const job = {};
1491
1492
  const db = collection.s.db, coll = collection.collectionName;
1492
1493
  db.command({
@@ -1495,7 +1496,7 @@ const executes$1 = (view, input, streamName) => {
1495
1496
  });
1496
1497
  createIndex(collection, { touchedAt: 1 }, hardMatch
1497
1498
  ? {
1498
- partialFilterExpression: hardMatch,
1499
+ partialFilterExpression: hardMatch.raw(root()),
1499
1500
  name: 'touchedAt_hard_' + new mongodb.UUID().toString('base64'),
1500
1501
  }
1501
1502
  : {}).catch(e => e.code == 86 || Promise.reject(e));
@@ -1570,7 +1571,7 @@ const executes$1 = (view, input, streamName) => {
1570
1571
  const step3 = (lastTS) => async () => {
1571
1572
  const hardQuery = $and(lastTS
1572
1573
  ? root().of('touchedAt').has($gteTs(lastTS.ts))
1573
- : root().of('deletedAt').has($eq(null)), lastTS ? null : match && $expr(match), hardMatch);
1574
+ : root().of('deletedAt').has($eq(null)), lastTS ? null : match && $expr(match), hardMatch, ...removeNotYetSynchronizedFields);
1574
1575
  const notDeleted = eq($ifNull(root().of('deletedAt').expr(), nil))(nil);
1575
1576
  const query = match ? and(notDeleted, match) : notDeleted;
1576
1577
  const replaceRaw = $replaceWith_(field({
@@ -1639,7 +1640,10 @@ const executes$1 = (view, input, streamName) => {
1639
1640
  const step8 = (l) => {
1640
1641
  return nextData(l.aggResult.cursor.firstBatch)(() => l.stream
1641
1642
  .tryNext()
1642
- .catch(err => { log('restarting', err); return 1; })
1643
+ .catch(err => {
1644
+ log('restarting', err);
1645
+ return 1;
1646
+ })
1643
1647
  .then(doc => (doc ? next(step2, 'restart') : step8(l))), 'wait for change');
1644
1648
  };
1645
1649
  return stop;
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.0.45",
6
+ "version": "0.0.47",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",