@omegup/msync 0.0.89 → 0.0.90

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
@@ -427,7 +427,9 @@ type MergeArgs<T extends O, Out extends O, Ctx, In extends O> = {
427
427
  })) | {
428
428
  stages: true;
429
429
  into: RWCollection<In, Out>;
430
- whenMatched: RawStages<unknown, Out, In>;
430
+ whenMatched: RawStages<unknown, Out, In, {
431
+ new: In;
432
+ }>;
431
433
  } | {
432
434
  stages: 'ctx';
433
435
  vars: ExprsExact<Ctx, T>;
package/index.esm.js CHANGED
@@ -1094,7 +1094,7 @@ const $unwind = (k, dict, middle) => {
1094
1094
 
1095
1095
  const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, includeNull1, includeNull2) => {
1096
1096
  const omit = omitRORec();
1097
- const hash = crypto$1.createHash('md5').update(canonicalize(input)).digest('base64url');
1097
+ const hash = crypto$1.createHash('md5').update(coll.collectionName + canonicalize(input) + canonicalize(exec)).digest('base64url');
1098
1098
  const ss = (f) => to($ifNull(root().of(f).of(k1).with(field1).expr(), val(hash)));
1099
1099
  return link()
1100
1100
  .with($replaceWithDelta(field(map1(k1, root().expr()))))
@@ -1378,7 +1378,21 @@ const $mergeX = (out, keys, f, map) => ({
1378
1378
  into: out,
1379
1379
  on: root().of('_id'),
1380
1380
  whenNotMatched: 'fail',
1381
- whenMatched: 'merge',
1381
+ stages: true,
1382
+ whenMatched: asStages([
1383
+ { $replaceWith: { old: '$$ROOT', merged: { $mergeObjects: ['$$ROOT', '$$new'] } } },
1384
+ {
1385
+ $replaceWith: {
1386
+ $cond: {
1387
+ if: {
1388
+ $eq: ['$old', { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] }],
1389
+ },
1390
+ then: '$old',
1391
+ else: '$merged',
1392
+ },
1393
+ },
1394
+ },
1395
+ ]),
1382
1396
  })).stages;
1383
1397
  },
1384
1398
  teardown: c => c({
@@ -1428,7 +1442,24 @@ const $insertX = (out, expr, map, ext, extExpr) => {
1428
1442
  .with($merge_({
1429
1443
  into: out,
1430
1444
  on: root().of('_id'),
1431
- whenMatched: 'merge',
1445
+ stages: true,
1446
+ whenMatched: asStages([
1447
+ { $replaceWith: { old: '$$ROOT', merged: { $mergeObjects: ['$$ROOT', '$$new'] } } },
1448
+ {
1449
+ $replaceWith: {
1450
+ $cond: {
1451
+ if: {
1452
+ $eq: [
1453
+ '$old',
1454
+ { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] },
1455
+ ],
1456
+ },
1457
+ then: '$old',
1458
+ else: '$merged',
1459
+ },
1460
+ },
1461
+ },
1462
+ ]),
1432
1463
  whenNotMatched: 'insert',
1433
1464
  })).stages;
1434
1465
  },
package/index.js CHANGED
@@ -1096,7 +1096,7 @@ const $unwind = (k, dict, middle) => {
1096
1096
 
1097
1097
  const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, includeNull1, includeNull2) => {
1098
1098
  const omit = omitRORec();
1099
- const hash = crypto$1.createHash('md5').update(jsonCanonicalize.canonicalize(input)).digest('base64url');
1099
+ const hash = crypto$1.createHash('md5').update(coll.collectionName + jsonCanonicalize.canonicalize(input) + jsonCanonicalize.canonicalize(exec)).digest('base64url');
1100
1100
  const ss = (f) => to($ifNull(root().of(f).of(k1).with(field1).expr(), val(hash)));
1101
1101
  return link()
1102
1102
  .with($replaceWithDelta(field(map1(k1, root().expr()))))
@@ -1380,7 +1380,21 @@ const $mergeX = (out, keys, f, map) => ({
1380
1380
  into: out,
1381
1381
  on: root().of('_id'),
1382
1382
  whenNotMatched: 'fail',
1383
- whenMatched: 'merge',
1383
+ stages: true,
1384
+ whenMatched: asStages([
1385
+ { $replaceWith: { old: '$$ROOT', merged: { $mergeObjects: ['$$ROOT', '$$new'] } } },
1386
+ {
1387
+ $replaceWith: {
1388
+ $cond: {
1389
+ if: {
1390
+ $eq: ['$old', { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] }],
1391
+ },
1392
+ then: '$old',
1393
+ else: '$merged',
1394
+ },
1395
+ },
1396
+ },
1397
+ ]),
1384
1398
  })).stages;
1385
1399
  },
1386
1400
  teardown: c => c({
@@ -1430,7 +1444,24 @@ const $insertX = (out, expr, map, ext, extExpr) => {
1430
1444
  .with($merge_({
1431
1445
  into: out,
1432
1446
  on: root().of('_id'),
1433
- whenMatched: 'merge',
1447
+ stages: true,
1448
+ whenMatched: asStages([
1449
+ { $replaceWith: { old: '$$ROOT', merged: { $mergeObjects: ['$$ROOT', '$$new'] } } },
1450
+ {
1451
+ $replaceWith: {
1452
+ $cond: {
1453
+ if: {
1454
+ $eq: [
1455
+ '$old',
1456
+ { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] },
1457
+ ],
1458
+ },
1459
+ then: '$old',
1460
+ else: '$merged',
1461
+ },
1462
+ },
1463
+ },
1464
+ ]),
1434
1465
  whenNotMatched: 'insert',
1435
1466
  })).stages;
1436
1467
  },
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.89",
6
+ "version": "0.0.90",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",