@omegup/msync 0.0.77 → 0.0.78

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
@@ -480,10 +480,10 @@ declare const $set: <V extends O>() => <R extends O, C = unknown>(fields: MapO<V
480
480
  declare const $replaceWith: <T extends O, V extends O>(expr: Expr<V, T>) => DeltaStages<O, T, V> & LinStages<O, T, V>;
481
481
 
482
482
  type s$1 = string;
483
- declare const $unwindDelta: <K1 extends s$1, T extends doc, K2 extends s$1, U extends doc, Null extends null = never>(k1: AsLiteral<K1>, k2: AsLiteral<K2>, k: K1 | K2 | false, includeNull?: Null) => RawStages<Delta<Rec<K1, T>>, Delta<Rec<K1, T> & Rec<K2, Arr<U>>>, Delta<Rec<K1, T> & Rec<K2, U | Null> & ID>>;
483
+ declare const $unwindDelta: <K1 extends s$1, T extends doc, K2 extends s$1, U extends doc, Null extends null = never>(k1: AsLiteral<K1>, k2: AsLiteral<K2>, k: K1 | K2 | false, includeNull?: Null, middle?: string) => RawStages<Delta<Rec<K1, T>>, Delta<Rec<K1, T> & Rec<K2, Arr<U>>>, Delta<Rec<K1, T> & Rec<K2, U | Null> & ID>>;
484
484
 
485
485
  type s = string;
486
- 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>>;
486
+ declare const $unwind: <T extends doc, K extends s, U extends doc>(k: AsLiteral<K>, dict: RORec<K, "key">, middle?: string) => DeltaStages<O, T & Rec<K, Arr<U>>, T & Rec<K, U>>;
487
487
 
488
488
  type Allowed$2<K extends string> = Exclude<K, keyof (TS & ID)>;
489
489
  type Patch<V, KK extends StrKey<V> = StrKey<V>> = ((OPick<V, Allowed$2<KK>> & ID) | (Rec<Allowed$2<KK>, N> & ID)) & TS;
package/index.esm.js CHANGED
@@ -932,7 +932,7 @@ const dualIn = operator();
932
932
  const $in = dualIn('$in');
933
933
  const $nin = dualIn('$nin');
934
934
 
935
- const $unwindDelta = (k1, k2, k, includeNull) => {
935
+ const $unwindDelta = (k1, k2, k, includeNull, middle) => {
936
936
  const outer = includeNull === null;
937
937
  const newItems = {
938
938
  $filter: {
@@ -978,7 +978,7 @@ const $unwindDelta = (k1, k2, k, includeNull) => {
978
978
  },
979
979
  };
980
980
  const ifNull = (k, part, str = `$${k}.${part}._id`) => outer && k == k2 ? { $ifNull: [str, 'null'] } : str;
981
- const interDot = ([a, b]) => [a, '.', b];
981
+ const interDot = ([a, b]) => [a, middle ?? '.', b];
982
982
  const partReplace = (part) => ({
983
983
  $cond: {
984
984
  if: { $or: [{ $eq: [`$${k1}.${part}`, null] }, { $eq: [`$${k2}.${part}`, null] }] },
@@ -1059,18 +1059,25 @@ const $unwindDelta = (k1, k2, k, includeNull) => {
1059
1059
  after: partReplace('after'),
1060
1060
  },
1061
1061
  },
1062
+ ...(!k && middle
1063
+ ? [
1064
+ {
1065
+ $set: { _id: { $ifNull: ['$before._id', '$after._id'] } },
1066
+ },
1067
+ ]
1068
+ : []),
1062
1069
  ]))
1063
1070
  .with($match_($expr(ne(part('before'))(part('after'))))).stages;
1064
1071
  return stages;
1065
1072
  };
1066
1073
 
1067
- const $unwind = (k, dict) => ({
1074
+ const $unwind = (k, dict, middle) => ({
1068
1075
  delta: link()
1069
1076
  .with($replaceWithDelta(field({
1070
1077
  left: ['left', root().expr()],
1071
1078
  right: ['right', root().of(k).expr()],
1072
1079
  })))
1073
- .with($unwindDelta('left', 'right', false))
1080
+ .with($unwindDelta('left', 'right', false, undefined, middle))
1074
1081
  .with($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({
1075
1082
  key: root().of('right').expr(),
1076
1083
  }, dict)))).stages,
package/index.js CHANGED
@@ -934,7 +934,7 @@ const dualIn = operator();
934
934
  const $in = dualIn('$in');
935
935
  const $nin = dualIn('$nin');
936
936
 
937
- const $unwindDelta = (k1, k2, k, includeNull) => {
937
+ const $unwindDelta = (k1, k2, k, includeNull, middle) => {
938
938
  const outer = includeNull === null;
939
939
  const newItems = {
940
940
  $filter: {
@@ -980,7 +980,7 @@ const $unwindDelta = (k1, k2, k, includeNull) => {
980
980
  },
981
981
  };
982
982
  const ifNull = (k, part, str = `$${k}.${part}._id`) => outer && k == k2 ? { $ifNull: [str, 'null'] } : str;
983
- const interDot = ([a, b]) => [a, '.', b];
983
+ const interDot = ([a, b]) => [a, middle ?? '.', b];
984
984
  const partReplace = (part) => ({
985
985
  $cond: {
986
986
  if: { $or: [{ $eq: [`$${k1}.${part}`, null] }, { $eq: [`$${k2}.${part}`, null] }] },
@@ -1061,18 +1061,25 @@ const $unwindDelta = (k1, k2, k, includeNull) => {
1061
1061
  after: partReplace('after'),
1062
1062
  },
1063
1063
  },
1064
+ ...(!k && middle
1065
+ ? [
1066
+ {
1067
+ $set: { _id: { $ifNull: ['$before._id', '$after._id'] } },
1068
+ },
1069
+ ]
1070
+ : []),
1064
1071
  ]))
1065
1072
  .with($match_($expr(ne(part('before'))(part('after'))))).stages;
1066
1073
  return stages;
1067
1074
  };
1068
1075
 
1069
- const $unwind = (k, dict) => ({
1076
+ const $unwind = (k, dict, middle) => ({
1070
1077
  delta: link()
1071
1078
  .with($replaceWithDelta(field({
1072
1079
  left: ['left', root().expr()],
1073
1080
  right: ['right', root().of(k).expr()],
1074
1081
  })))
1075
- .with($unwindDelta('left', 'right', false))
1082
+ .with($unwindDelta('left', 'right', false, undefined, middle))
1076
1083
  .with($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({
1077
1084
  key: root().of('right').expr(),
1078
1085
  }, dict)))).stages,
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.77",
6
+ "version": "0.0.78",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",