@omegup/msync 0.0.7 → 0.0.8

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
@@ -466,9 +466,10 @@ declare const $unwindDelta: <K1 extends s$1, T extends doc, K2 extends s$1, U ex
466
466
  type s = string;
467
467
  declare const $unwind: <T extends doc, K extends s, U extends doc>(k: AsLiteral<K>, dict: RORec<K, "key">) => DeltaStages<O, T & Rec<K, Arr<U>>, T & Rec<K, U>>;
468
468
 
469
+ type OutInputE<T, E, A = T | null> = ID & Rec<'after', A> & E;
469
470
  type Allowed$2<K extends string> = Exclude<K, keyof (TS & ID)>;
470
471
  type Patch<V, KK extends StrKey<V>> = ((OPick<V, Allowed$2<KK>> & ID) | (Rec<Allowed$2<KK>, N> & ID)) & TS;
471
- declare const $merge: <V extends Model & ID>() => <KK extends StrKey<V>, Out extends doc>(out: RWCollection<Out | Replace<Out, Patch<V, KK>>, Out>, keys: ExactKeys<Allowed$2<KK>>) => RawStages<unknown, OutInput<OPick<V, Allowed$2<KK>> & ID>, "out">;
472
+ declare const $merge: <V extends Model & ID>() => <KK extends StrKey<V>, Out extends doc, E = unknown>(out: RWCollection<Out | Replace<Out, Patch<V, KK>>, Out>, keys: ExactKeys<Allowed$2<KK>>, id: Expr<string, OutInputE<OPick<V, Allowed$2<KK>> & ID, E, null>>) => RawStages<unknown, OutInputE<OPick<V, Allowed$2<KK>> & ID, E>, "out">;
472
473
 
473
474
  type ND = {
474
475
  readonly deletedAt?: null;
package/index.esm.js CHANGED
@@ -715,53 +715,45 @@ const $unwindDelta = (k1, k2, k) => {
715
715
  .with(asStages([
716
716
  {
717
717
  $replaceWith: {
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
- ],
737
- },
738
- },
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
- },
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
+ ],
750
732
  },
733
+ [k1]: `$${k1}.before`,
734
+ [k2]: `$${k2}.before`,
751
735
  },
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
- },
736
+ },
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
+ ],
761
751
  },
752
+ [k1]: `$${k1}.after`,
753
+ [k2]: `$${k2}.after`,
762
754
  },
763
- }
764
- }
755
+ },
756
+ },
765
757
  },
766
758
  },
767
759
  ])).stages;
@@ -1018,11 +1010,11 @@ const $replaceWith = (expr) => ({
1018
1010
  lin: $replaceWith_(expr),
1019
1011
  });
1020
1012
 
1021
- const $merge = () => (out, keys) => {
1013
+ const $merge = () => (out, keys, id) => {
1022
1014
  const omRORec = omitRORec();
1023
1015
  const patch = mapExactToObject(keys, (_, k) => [k, root().of('after').of(k).expr()]);
1024
1016
  const replacer = ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
1025
- _id: ['_id', root().of('_id').expr()],
1017
+ _id: ['_id', id],
1026
1018
  touchedAt: ['touchedAt', current],
1027
1019
  }))), field(omitPick().backward(spread(patch, {
1028
1020
  _id: ['_id', root().of('after').of('_id').expr()],
package/index.js CHANGED
@@ -717,53 +717,45 @@ const $unwindDelta = (k1, k2, k) => {
717
717
  .with(asStages([
718
718
  {
719
719
  $replaceWith: {
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
- ],
739
- },
740
- },
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
- },
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
+ ],
752
734
  },
735
+ [k1]: `$${k1}.before`,
736
+ [k2]: `$${k2}.before`,
753
737
  },
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
- },
738
+ },
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
+ ],
763
753
  },
754
+ [k1]: `$${k1}.after`,
755
+ [k2]: `$${k2}.after`,
764
756
  },
765
- }
766
- }
757
+ },
758
+ },
767
759
  },
768
760
  },
769
761
  ])).stages;
@@ -1020,11 +1012,11 @@ const $replaceWith = (expr) => ({
1020
1012
  lin: $replaceWith_(expr),
1021
1013
  });
1022
1014
 
1023
- const $merge = () => (out, keys) => {
1015
+ const $merge = () => (out, keys, id) => {
1024
1016
  const omRORec = omitRORec();
1025
1017
  const patch = mapExactToObject(keys, (_, k) => [k, root().of('after').of(k).expr()]);
1026
1018
  const replacer = ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
1027
- _id: ['_id', root().of('_id').expr()],
1019
+ _id: ['_id', id],
1028
1020
  touchedAt: ['touchedAt', current],
1029
1021
  }))), field(omitPick().backward(spread(patch, {
1030
1022
  _id: ['_id', root().of('after').of('_id').expr()],
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.7",
6
+ "version": "0.0.8",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",