@omegup/msync 0.0.6 → 0.0.7

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 +44 -36
  2. package/index.js +44 -36
  3. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -715,45 +715,53 @@ const $unwindDelta = (k1, k2, k) => {
715
715
  .with(asStages([
716
716
  {
717
717
  $replaceWith: {
718
- _id: "$_id",
719
- before: {
720
- $cond: {
721
- if: { $or: [{ $eq: [`$${k1}.before`, null] }, { $eq: [`$${k2}.before`, null] }] },
722
- then: null,
723
- else: {
724
- _id: {
725
- $concat: k
726
- ? `$${k}.before._id`
727
- : [
728
- `$${[k1, k2].sort()[0]}.before._id`,
729
- '.',
730
- `$${[k1, k2].sort()[1]}.before._id`,
731
- ],
732
- },
733
- [k1]: `$${k1}.before`,
734
- [k2]: `$${k2}.before`,
718
+ $let: {
719
+ vars: {
720
+ beforeId: {
721
+ $concat: k
722
+ ? `$${k}.before._id`
723
+ : [
724
+ `$${[k1, k2].sort()[0]}.before._id`,
725
+ '.',
726
+ `$${[k1, k2].sort()[1]}.before._id`,
727
+ ],
728
+ },
729
+ afterId: {
730
+ $concat: k
731
+ ? `$${k}.after._id`
732
+ : [
733
+ `$${[k1, k2].sort()[0]}.after._id`,
734
+ '.',
735
+ `$${[k1, k2].sort()[1]}.after._id`,
736
+ ],
735
737
  },
736
738
  },
737
- },
738
- after: {
739
- $cond: {
740
- if: { $or: [{ $eq: [`$${k1}.after`, null] }, { $eq: [`$${k2}.after`, null] }] },
741
- then: null,
742
- else: {
743
- _id: {
744
- $concat: k
745
- ? `$${k}.after._id`
746
- : [
747
- `$${[k1, k2].sort()[0]}.after._id`,
748
- '.',
749
- `$${[k1, k2].sort()[1]}.after._id`,
750
- ],
739
+ in: {
740
+ _id: { $ifNull: ['$$afterId', '$$beforeId'] },
741
+ before: {
742
+ $cond: {
743
+ if: { $or: [{ $eq: [`$${k1}.before`, null] }, { $eq: [`$${k2}.before`, null] }] },
744
+ then: null,
745
+ else: {
746
+ _id: '$$beforeId',
747
+ [k1]: `$${k1}.before`,
748
+ [k2]: `$${k2}.before`,
749
+ },
751
750
  },
752
- [k1]: `$${k1}.after`,
753
- [k2]: `$${k2}.after`,
754
751
  },
755
- },
756
- },
752
+ after: {
753
+ $cond: {
754
+ if: { $or: [{ $eq: [`$${k1}.after`, null] }, { $eq: [`$${k2}.after`, null] }] },
755
+ then: null,
756
+ else: {
757
+ _id: '$$afterId',
758
+ [k1]: `$${k1}.after`,
759
+ [k2]: `$${k2}.after`,
760
+ },
761
+ },
762
+ },
763
+ }
764
+ }
757
765
  },
758
766
  },
759
767
  ])).stages;
@@ -1088,7 +1096,7 @@ const addTeardown = (it, tr) => {
1088
1096
  const changeKeys = ['fullDocument', 'fullDocumentBeforeChange'];
1089
1097
  const subQ = (a, f) => ({ raw: g => a.raw(g.with(f)) });
1090
1098
  const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startAt) => {
1091
- const projection = mapExactToObject(p, v => v);
1099
+ const projection = { ...mapExactToObject(p, v => v), deletedAt: 1 };
1092
1100
  const pipeline = [];
1093
1101
  if (m) {
1094
1102
  const q = $or(...changeKeys.map((k) => subQ(m, root().of(k))));
package/index.js CHANGED
@@ -717,45 +717,53 @@ const $unwindDelta = (k1, k2, k) => {
717
717
  .with(asStages([
718
718
  {
719
719
  $replaceWith: {
720
- _id: "$_id",
721
- before: {
722
- $cond: {
723
- if: { $or: [{ $eq: [`$${k1}.before`, null] }, { $eq: [`$${k2}.before`, null] }] },
724
- then: null,
725
- else: {
726
- _id: {
727
- $concat: k
728
- ? `$${k}.before._id`
729
- : [
730
- `$${[k1, k2].sort()[0]}.before._id`,
731
- '.',
732
- `$${[k1, k2].sort()[1]}.before._id`,
733
- ],
734
- },
735
- [k1]: `$${k1}.before`,
736
- [k2]: `$${k2}.before`,
720
+ $let: {
721
+ vars: {
722
+ beforeId: {
723
+ $concat: k
724
+ ? `$${k}.before._id`
725
+ : [
726
+ `$${[k1, k2].sort()[0]}.before._id`,
727
+ '.',
728
+ `$${[k1, k2].sort()[1]}.before._id`,
729
+ ],
730
+ },
731
+ afterId: {
732
+ $concat: k
733
+ ? `$${k}.after._id`
734
+ : [
735
+ `$${[k1, k2].sort()[0]}.after._id`,
736
+ '.',
737
+ `$${[k1, k2].sort()[1]}.after._id`,
738
+ ],
737
739
  },
738
740
  },
739
- },
740
- after: {
741
- $cond: {
742
- if: { $or: [{ $eq: [`$${k1}.after`, null] }, { $eq: [`$${k2}.after`, null] }] },
743
- then: null,
744
- else: {
745
- _id: {
746
- $concat: k
747
- ? `$${k}.after._id`
748
- : [
749
- `$${[k1, k2].sort()[0]}.after._id`,
750
- '.',
751
- `$${[k1, k2].sort()[1]}.after._id`,
752
- ],
741
+ in: {
742
+ _id: { $ifNull: ['$$afterId', '$$beforeId'] },
743
+ before: {
744
+ $cond: {
745
+ if: { $or: [{ $eq: [`$${k1}.before`, null] }, { $eq: [`$${k2}.before`, null] }] },
746
+ then: null,
747
+ else: {
748
+ _id: '$$beforeId',
749
+ [k1]: `$${k1}.before`,
750
+ [k2]: `$${k2}.before`,
751
+ },
753
752
  },
754
- [k1]: `$${k1}.after`,
755
- [k2]: `$${k2}.after`,
756
753
  },
757
- },
758
- },
754
+ after: {
755
+ $cond: {
756
+ if: { $or: [{ $eq: [`$${k1}.after`, null] }, { $eq: [`$${k2}.after`, null] }] },
757
+ then: null,
758
+ else: {
759
+ _id: '$$afterId',
760
+ [k1]: `$${k1}.after`,
761
+ [k2]: `$${k2}.after`,
762
+ },
763
+ },
764
+ },
765
+ }
766
+ }
759
767
  },
760
768
  },
761
769
  ])).stages;
@@ -1090,7 +1098,7 @@ const addTeardown = (it, tr) => {
1090
1098
  const changeKeys = ['fullDocument', 'fullDocumentBeforeChange'];
1091
1099
  const subQ = (a, f) => ({ raw: g => a.raw(g.with(f)) });
1092
1100
  const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startAt) => {
1093
- const projection = mapExactToObject(p, v => v);
1101
+ const projection = { ...mapExactToObject(p, v => v), deletedAt: 1 };
1094
1102
  const pipeline = [];
1095
1103
  if (m) {
1096
1104
  const q = $or(...changeKeys.map((k) => subQ(m, root().of(k))));
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.6",
6
+ "version": "0.0.7",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",