@omegup/msync 0.0.98 → 0.0.99

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
@@ -491,6 +491,11 @@ declare const $unwind: <TT extends O, K extends s, U extends doc>(k: AsLiteral<K
491
491
  type Allowed$2<K extends string> = Exclude<K, keyof (TS & ID)>;
492
492
  type Patch<V, KK extends StrKey<V> = StrKey<V>> = ((OPick<V, Allowed$2<KK>> & ID) | (Rec<Allowed$2<KK>, N> & ID)) & TS;
493
493
  type TakeDoc<V, E = ID, KK extends StrKey<V> = StrKey<V>> = OPick<V, Allowed$2<KK>> & E;
494
+ type ND$1 = {
495
+ readonly deletedAt?: null;
496
+ };
497
+ type SafeE$1<E> = Omit<E, `$${string}` | keyof ID>;
498
+ declare const $simpleMergePart: <V extends O>() => <Source extends doc, Out extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, whenNotMatched: "fail" | "discard", ext: Exact<Omit<SafeE$1<EEE>, keyof (ND$1 & TS)>, IdHKT>) => StreamRunnerParam<Source, "out">;
494
499
  declare const $simpleMerge: <V extends O>() => <Source extends doc, Out extends doc>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, whenNotMatched?: "fail" | "discard") => StreamRunnerParam<Source, "out">;
495
500
  declare const $merge: <V extends O>() => <Out extends doc, SourcePart extends doc>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, whenNotMatched?: "fail" | "discard") => StreamRunnerParam<Delta<SourcePart>, "out">;
496
501
 
@@ -698,4 +703,4 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
698
703
  declare const prepare: (testName?: string) => Promise<MongoClient$1>;
699
704
  declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
700
705
 
701
- export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $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 };
706
+ export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $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, $simpleMergePart, $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
@@ -1364,28 +1364,37 @@ const $replaceWith = (expr) => ({
1364
1364
  lin: $replaceWith_(expr),
1365
1365
  });
1366
1366
 
1367
- const $mergeX = (out, keys, f, map, whenNotMatched = 'fail') => ({
1368
- raw: (first) => {
1369
- const patch = mapExact(keys, v => sub(v, f));
1370
- const or = field(omitPick().backward(spread(patch, {
1371
- _id: ['_id', f.of('_id').expr()],
1372
- touchedAt: ['touchedAt', current],
1373
- })));
1374
- const replacer = map(or);
1375
- return link()
1367
+ const $mergeX = (out, keys, f, map, whenNotMatched = 'fail', ext) => {
1368
+ const patch = mapExact(keys, v => sub(v, f));
1369
+ const filter = mapExactToObject(ext, v => ({ $eq: v }));
1370
+ const replacer = map(field(omitPick().backward(spread(patch, {
1371
+ _id: ['_id', f.of('_id').expr()],
1372
+ touchedAt: ['touchedAt', current],
1373
+ deletedAt: ['deletedAt', current],
1374
+ }))));
1375
+ return {
1376
+ raw: (first) => link()
1376
1377
  .with($replaceWith_(replacer))
1377
1378
  .with($merge_({
1378
1379
  into: out,
1379
1380
  on: root().of('_id'),
1380
- whenNotMatched,
1381
+ whenNotMatched: whenNotMatched === 'fail' ? 'fail' : 'insert',
1381
1382
  stages: true,
1382
1383
  whenMatched: asStages([
1383
- { $replaceWith: { old: '$$ROOT', merged: { $mergeObjects: ['$$ROOT', '$$new'] } } },
1384
+ {
1385
+ $replaceWith: {
1386
+ old: { $mergeObjects: ['$$ROOT', { deletedAt: '$deletedAt' }] },
1387
+ merged: { $mergeObjects: ['$$ROOT', '$$new', { deletedAt: '$deletedAt' }] },
1388
+ },
1389
+ },
1384
1390
  {
1385
1391
  $replaceWith: {
1386
1392
  $cond: {
1387
1393
  if: {
1388
- $eq: ['$old', { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] }],
1394
+ $eq: [
1395
+ '$old',
1396
+ { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] },
1397
+ ],
1389
1398
  },
1390
1399
  then: '$old',
1391
1400
  else: '$merged',
@@ -1393,32 +1402,33 @@ const $mergeX = (out, keys, f, map, whenNotMatched = 'fail') => ({
1393
1402
  },
1394
1403
  },
1395
1404
  ]),
1396
- })).stages;
1397
- },
1398
- teardown: c => c({
1399
- collection: out,
1400
- method: 'updateMany',
1401
- params: [
1402
- {},
1403
- [
1404
- {
1405
- $unset: Object.keys(mapExactToObject(keys, () => 1)),
1406
- },
1405
+ })).stages,
1406
+ teardown: c => c({
1407
+ collection: out,
1408
+ method: 'updateMany',
1409
+ params: [
1410
+ filter,
1411
+ [
1412
+ {
1413
+ $unset: Object.keys(mapExactToObject(keys, () => 1)),
1414
+ },
1415
+ ],
1407
1416
  ],
1408
- ],
1409
- }),
1410
- });
1411
- const $mergeId = () => (out, keys, id, whenNotMatched = 'fail') => {
1417
+ }),
1418
+ };
1419
+ };
1420
+ const $mergeId = () => (out, keys, id, ext, whenNotMatched) => {
1412
1421
  const omRORec = omitRORec();
1413
1422
  return $mergeX(out, keys, root().of('after'), or => {
1414
1423
  return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
1415
1424
  _id: ['_id', id],
1416
1425
  touchedAt: ['touchedAt', current],
1417
1426
  }))), or);
1418
- }, whenNotMatched);
1427
+ }, whenNotMatched, ext);
1419
1428
  };
1420
- const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX(out, keys, root(), id$1, whenNotMatched);
1421
- const $merge = () => (out, keys, whenNotMatched = 'fail') => $mergeId()(out, keys, assertNotNull$1(root().of('before').of('_id').expr()), whenNotMatched);
1429
+ const $simpleMergePart = () => (out, keys, whenNotMatched, ext) => $mergeX(out, keys, root(), id$1, whenNotMatched, ext);
1430
+ const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX(out, keys, root(), id$1, whenNotMatched, {});
1431
+ const $merge = () => (out, keys, whenNotMatched = 'fail') => $mergeId()(out, keys, assertNotNull$1(root().of('before').of('_id').expr()), {}, whenNotMatched);
1422
1432
  const assertNotNull$1 = (expr) => expr;
1423
1433
 
1424
1434
  const $insertX = (out, expr, map, ext, extExpr) => {
@@ -1983,4 +1993,4 @@ const makeCol = async (docs, database, name) => {
1983
1993
  }
1984
1994
  };
1985
1995
 
1986
- export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $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 };
1996
+ export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $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, $simpleMergePart, $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
@@ -1366,28 +1366,37 @@ const $replaceWith = (expr) => ({
1366
1366
  lin: $replaceWith_(expr),
1367
1367
  });
1368
1368
 
1369
- const $mergeX = (out, keys, f, map, whenNotMatched = 'fail') => ({
1370
- raw: (first) => {
1371
- const patch = mapExact(keys, v => sub(v, f));
1372
- const or = field(omitPick().backward(spread(patch, {
1373
- _id: ['_id', f.of('_id').expr()],
1374
- touchedAt: ['touchedAt', current],
1375
- })));
1376
- const replacer = map(or);
1377
- return link()
1369
+ const $mergeX = (out, keys, f, map, whenNotMatched = 'fail', ext) => {
1370
+ const patch = mapExact(keys, v => sub(v, f));
1371
+ const filter = mapExactToObject(ext, v => ({ $eq: v }));
1372
+ const replacer = map(field(omitPick().backward(spread(patch, {
1373
+ _id: ['_id', f.of('_id').expr()],
1374
+ touchedAt: ['touchedAt', current],
1375
+ deletedAt: ['deletedAt', current],
1376
+ }))));
1377
+ return {
1378
+ raw: (first) => link()
1378
1379
  .with($replaceWith_(replacer))
1379
1380
  .with($merge_({
1380
1381
  into: out,
1381
1382
  on: root().of('_id'),
1382
- whenNotMatched,
1383
+ whenNotMatched: whenNotMatched === 'fail' ? 'fail' : 'insert',
1383
1384
  stages: true,
1384
1385
  whenMatched: asStages([
1385
- { $replaceWith: { old: '$$ROOT', merged: { $mergeObjects: ['$$ROOT', '$$new'] } } },
1386
+ {
1387
+ $replaceWith: {
1388
+ old: { $mergeObjects: ['$$ROOT', { deletedAt: '$deletedAt' }] },
1389
+ merged: { $mergeObjects: ['$$ROOT', '$$new', { deletedAt: '$deletedAt' }] },
1390
+ },
1391
+ },
1386
1392
  {
1387
1393
  $replaceWith: {
1388
1394
  $cond: {
1389
1395
  if: {
1390
- $eq: ['$old', { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] }],
1396
+ $eq: [
1397
+ '$old',
1398
+ { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] },
1399
+ ],
1391
1400
  },
1392
1401
  then: '$old',
1393
1402
  else: '$merged',
@@ -1395,32 +1404,33 @@ const $mergeX = (out, keys, f, map, whenNotMatched = 'fail') => ({
1395
1404
  },
1396
1405
  },
1397
1406
  ]),
1398
- })).stages;
1399
- },
1400
- teardown: c => c({
1401
- collection: out,
1402
- method: 'updateMany',
1403
- params: [
1404
- {},
1405
- [
1406
- {
1407
- $unset: Object.keys(mapExactToObject(keys, () => 1)),
1408
- },
1407
+ })).stages,
1408
+ teardown: c => c({
1409
+ collection: out,
1410
+ method: 'updateMany',
1411
+ params: [
1412
+ filter,
1413
+ [
1414
+ {
1415
+ $unset: Object.keys(mapExactToObject(keys, () => 1)),
1416
+ },
1417
+ ],
1409
1418
  ],
1410
- ],
1411
- }),
1412
- });
1413
- const $mergeId = () => (out, keys, id, whenNotMatched = 'fail') => {
1419
+ }),
1420
+ };
1421
+ };
1422
+ const $mergeId = () => (out, keys, id, ext, whenNotMatched) => {
1414
1423
  const omRORec = omitRORec();
1415
1424
  return $mergeX(out, keys, root().of('after'), or => {
1416
1425
  return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
1417
1426
  _id: ['_id', id],
1418
1427
  touchedAt: ['touchedAt', current],
1419
1428
  }))), or);
1420
- }, whenNotMatched);
1429
+ }, whenNotMatched, ext);
1421
1430
  };
1422
- const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX(out, keys, root(), id$1, whenNotMatched);
1423
- const $merge = () => (out, keys, whenNotMatched = 'fail') => $mergeId()(out, keys, assertNotNull$1(root().of('before').of('_id').expr()), whenNotMatched);
1431
+ const $simpleMergePart = () => (out, keys, whenNotMatched, ext) => $mergeX(out, keys, root(), id$1, whenNotMatched, ext);
1432
+ const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX(out, keys, root(), id$1, whenNotMatched, {});
1433
+ const $merge = () => (out, keys, whenNotMatched = 'fail') => $mergeId()(out, keys, assertNotNull$1(root().of('before').of('_id').expr()), {}, whenNotMatched);
1424
1434
  const assertNotNull$1 = (expr) => expr;
1425
1435
 
1426
1436
  const $insertX = (out, expr, map, ext, extExpr) => {
@@ -2030,6 +2040,7 @@ exports.$replaceWith = $replaceWith;
2030
2040
  exports.$set = $set;
2031
2041
  exports.$simpleInsert = $simpleInsert;
2032
2042
  exports.$simpleMerge = $simpleMerge;
2043
+ exports.$simpleMergePart = $simpleMergePart;
2033
2044
  exports.$sum = $sum;
2034
2045
  exports.$type = $type;
2035
2046
  exports.$unwind = $unwind;
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.98",
6
+ "version": "0.0.99",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",