@omegup/msync 0.0.74 → 0.0.76

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 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
  };
@@ -581,6 +581,8 @@ declare const last: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>;
581
581
  type NullToOBJ<N extends null> = N extends null ? O : N;
582
582
  declare const mergeObjects: <T1, T2, D, C = unknown, N extends null = never>(exprs_0: Expr<T1 | N, D, C>, exprs_1: Expr<T2, D, C>) => Expr<(T1 | NullToOBJ<N>) & T2, D, C>;
583
583
  declare const anyElementTrue: <D, C = unknown>(expr: Expr<Arr<boolean>, D, C>) => Expr<boolean, D, C>;
584
+ type Reduce<T, V> = RORec<'value', V> & RORec<'this', T>;
585
+ declare const $reduce: <T, V, D, C>(input: Expr<Arr<T>, D, C>, initialValue: Expr<V, D, C>, inExpr: Expr<V, D, C & Reduce<T, V>>) => Expr<V, D, C>;
584
586
  declare const slice: <T, D, C>(array: Expr<Arr<T>, D, C>, start: Expr<number, D, C>, end: Expr<number, D, C>) => Expr<Arr<T>, D, C>;
585
587
  declare const except: <T, D, C>(a: Expr<Arr<T>, D, C>, b: Expr<Arr<T>, D, C>) => Expr<Arr<T>, D, C>;
586
588
 
@@ -690,4 +692,4 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
690
692
  declare const prepare: (testName?: string) => Promise<MongoClient$1>;
691
693
  declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
692
694
 
693
- export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $replaceWith, $set, $simpleInsert, $simpleMerge, $sum, $type, $unwind, $unwindDelta, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type MongoTypeNames, type N, type NoRaw, type NullToOBJ, type O, type OPick, type OPickD, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, type notArr, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
695
+ export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $sum, $type, $unwind, $unwindDelta, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type MongoTypeNames, type N, type NoRaw, type NullToOBJ, type O, type OPick, type OPickD, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, type notArr, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
package/index.esm.js CHANGED
@@ -414,7 +414,7 @@ const mergeObjects = (...exprs) => asExpr({
414
414
  const anyElementTrue = (expr) => asExpr({
415
415
  raw: f => asExprRaw({ $anyElementTrue: expr.raw(f).get() }),
416
416
  });
417
- const reduce = (input, initialValue, inExpr) => asExpr({
417
+ const $reduce = (input, initialValue, inExpr) => asExpr({
418
418
  raw: f => asExprRaw({
419
419
  $reduce: {
420
420
  input: input.raw(f).get(),
@@ -442,7 +442,7 @@ const except = (a, b) => {
442
442
  return $let({
443
443
  res: [
444
444
  'res',
445
- reduce(a, field({ out: ['out', array()], except: ['except', b] }), $let({
445
+ $reduce(a, field({ out: ['out', array()], except: ['except', b] }), $let({
446
446
  indexInExcept: ['indexInExcept', indexOfArray(except, curr)],
447
447
  }, ite(gte(indexInExcept, val(0)), field({
448
448
  out: ['out', out],
@@ -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
- return link()
1528
- .with($match_(hardQuery))
1529
- .with(projectInput);
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
- return link()
1756
- .with($match_(hardQuery))
1757
- .with(projectInput)
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 () => { };
@@ -1900,4 +1899,4 @@ const makeCol = async (docs, database, name) => {
1900
1899
  }
1901
1900
  };
1902
1901
 
1903
- export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $replaceWith, $set, $simpleInsert, $simpleMerge, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
1902
+ export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
package/index.js CHANGED
@@ -416,7 +416,7 @@ const mergeObjects = (...exprs) => asExpr({
416
416
  const anyElementTrue = (expr) => asExpr({
417
417
  raw: f => asExprRaw({ $anyElementTrue: expr.raw(f).get() }),
418
418
  });
419
- const reduce = (input, initialValue, inExpr) => asExpr({
419
+ const $reduce = (input, initialValue, inExpr) => asExpr({
420
420
  raw: f => asExprRaw({
421
421
  $reduce: {
422
422
  input: input.raw(f).get(),
@@ -444,7 +444,7 @@ const except = (a, b) => {
444
444
  return $let({
445
445
  res: [
446
446
  'res',
447
- reduce(a, field({ out: ['out', array()], except: ['except', b] }), $let({
447
+ $reduce(a, field({ out: ['out', array()], except: ['except', b] }), $let({
448
448
  indexInExcept: ['indexInExcept', indexOfArray(except, curr)],
449
449
  }, ite(gte(indexInExcept, val(0)), field({
450
450
  out: ['out', out],
@@ -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
- return link()
1530
- .with($match_(hardQuery))
1531
- .with(projectInput);
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
- return link()
1758
- .with($match_(hardQuery))
1759
- .with(projectInput)
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 () => { };
@@ -1941,6 +1940,7 @@ exports.$or = $or;
1941
1940
  exports.$outerLookup = $outerLookup;
1942
1941
  exports.$pushDict = $pushDict;
1943
1942
  exports.$rand = $rand;
1943
+ exports.$reduce = $reduce;
1944
1944
  exports.$replaceWith = $replaceWith;
1945
1945
  exports.$set = $set;
1946
1946
  exports.$simpleInsert = $simpleInsert;
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.74",
6
+ "version": "0.0.76",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",