@omegup/msync 0.0.77 → 0.0.79

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,11 @@ 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
+ type TOf<TT, K extends string> = doc & Omit<TT, K>;
487
+ declare const $unwind: <TT extends O, K extends s, U extends doc>(k: AsLiteral<K>, dict: RORec<K, "key">, middle: string) => DeltaStages<O, TOf<TT, K> & Rec<K, Arr<U>>, TOf<TT, K> & Rec<K, U>>;
487
488
 
488
489
  type Allowed$2<K extends string> = Exclude<K, keyof (TS & ID)>;
489
490
  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,23 +1059,32 @@ 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) => ({
1068
- delta: link()
1069
- .with($replaceWithDelta(field({
1070
- left: ['left', root().expr()],
1071
- right: ['right', root().of(k).expr()],
1072
- })))
1073
- .with($unwindDelta('left', 'right', false))
1074
- .with($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({
1075
- key: root().of('right').expr(),
1076
- }, dict)))).stages,
1077
- raw: $unwind1(k),
1078
- });
1074
+ const $unwind = (k, dict, middle) => {
1075
+ return {
1076
+ delta: link()
1077
+ .with($replaceWithDelta(field({
1078
+ left: ['left', root().expr()],
1079
+ right: ['right', root().of(k).expr()],
1080
+ })))
1081
+ .with($unwindDelta('left', 'right', false, undefined, middle))
1082
+ .with($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({
1083
+ key: root().of('right').expr(),
1084
+ }, dict)))).stages,
1085
+ raw: $unwind1(k),
1086
+ };
1087
+ };
1079
1088
 
1080
1089
  const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, includeNull) => {
1081
1090
  return link()
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,23 +1061,32 @@ 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) => ({
1070
- delta: link()
1071
- .with($replaceWithDelta(field({
1072
- left: ['left', root().expr()],
1073
- right: ['right', root().of(k).expr()],
1074
- })))
1075
- .with($unwindDelta('left', 'right', false))
1076
- .with($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({
1077
- key: root().of('right').expr(),
1078
- }, dict)))).stages,
1079
- raw: $unwind1(k),
1080
- });
1076
+ const $unwind = (k, dict, middle) => {
1077
+ return {
1078
+ delta: link()
1079
+ .with($replaceWithDelta(field({
1080
+ left: ['left', root().expr()],
1081
+ right: ['right', root().of(k).expr()],
1082
+ })))
1083
+ .with($unwindDelta('left', 'right', false, undefined, middle))
1084
+ .with($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({
1085
+ key: root().of('right').expr(),
1086
+ }, dict)))).stages,
1087
+ raw: $unwind1(k),
1088
+ };
1089
+ };
1081
1090
 
1082
1091
  const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, includeNull) => {
1083
1092
  return link()
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.79",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",