@omegup/msync 0.0.80 → 0.0.82

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
@@ -449,7 +449,7 @@ type Denied<GID = never> = keyof (TS & ID) | GID;
449
449
  type GI<GG> = Exclude<GG, keyof TS>;
450
450
  declare const $groupMerge: <T extends O, Grp extends notArr, V extends O, GG extends string, EE = {}, Out extends Loose<Grp, V, GG> = Loose<Grp, V, GG>>(id: Expr<Grp, T>, args: DeltaAccumulators<T, O & Omit<V, Denied<GI<GG>>>>, out: MergeInto<Strict<Grp, V, GG, EE>, Out, WriteonlyCollection<Replace<Out, Strict<Grp, V, GG, EE>>>>, gid: AsLiteral<GI<GG>>, extra: ExprsExact<Extra<EE, V, GG>, V_Grp<V, GG, Grp>>, idPrefix?: string) => StreamRunnerParam<Delta<T>, "out">;
451
451
  declare const $groupId: <T extends O, V extends O, EE = {}, Out extends Loose<string, V, "_id"> = Loose<string, V, "_id">>(id: Expr<string, T>, args: DeltaAccumulators<T, O & Omit<V, Denied>>, out: RWCollection<Replace<Out, Strict<string, V, "_id", EE>>, Out>, extra: ExprsExact<Omit<EE, IdAndTsKeys | keyof Omit<V, IdAndTsKeys>>, doc & Omit<V, IdAndTsKeys>>) => StreamRunnerParam<Delta<T>, "out">;
452
- declare const $group: <T extends O, Grp extends notArr, V extends O, EE = {}, Out extends Loose<Grp, V, "_grp"> = Loose<Grp, V, "_grp">>(id: Expr<Grp, T>, args: DeltaAccumulators<T, O & Omit<V, Denied<"_grp">>>, out: RWCollection<Strict<Grp, V, "_grp", EE>, Out>, extra: ExprsExact<Omit<EE, IdAndTsKeys | "_grp" | keyof Omit<V, IdAndTsKeys | "_grp">>, Rec<"_grp", Grp> & Omit<V, IdAndTsKeys | "_grp">>, idPrefix?: string) => StreamRunnerParam<Delta<T>, "out">;
452
+ declare const $group: <T extends O, Grp extends notArr, V extends O, EE = {}, Out extends Loose<Grp, V, "_grp"> = Loose<Grp, V, "_grp">>(id: Expr<Grp, T>, args: DeltaAccumulators<T, O & Omit<V, Denied<"_grp">>>, out: RWCollection<Strict<Grp, V, "_grp", EE>, Out>, extra: ExprsExact<Omit<EE, IdAndTsKeys | "_grp" | Exclude<keyof V, IdAndTsKeys | "_grp">>, Rec<"_grp", Grp> & Omit<V, IdAndTsKeys | "_grp">>, idPrefix?: string) => StreamRunnerParam<Delta<T>, "out">;
453
453
 
454
454
  type Params<As extends string, LQ extends O, RQ extends O, RE extends RQ, S extends notArr> = {
455
455
  localField: Field<LQ, S>;
@@ -480,7 +480,7 @@ 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, middle?: string) => 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, N1 extends null = never, N2 extends null = never>(k1: AsLiteral<K1>, k2: AsLiteral<K2>, k: K1 | K2 | false, middle?: string, includeNull1?: N1, includeNull2?: N2) => RawStages<Delta<Rec<K1, T | N1>>, Delta<Rec<K1, T | N1> & Rec<K2, Arr<U>>>, Delta<Rec<K1, T | N1> & Rec<K2, U | N2> & ID>>;
484
484
 
485
485
  type s = string;
486
486
  type TOf<TT, K extends string> = doc & Omit<TT, K>;
package/index.esm.js CHANGED
@@ -932,8 +932,9 @@ const dualIn = operator();
932
932
  const $in = dualIn('$in');
933
933
  const $nin = dualIn('$nin');
934
934
 
935
- const $unwindDelta = (k1, k2, k, includeNull, middle) => {
936
- const outer = includeNull === null;
935
+ const $unwindDelta = (k1, k2, k, middle, includeNull1, includeNull2) => {
936
+ const outer1 = includeNull1 === null;
937
+ const outer2 = includeNull2 === null;
937
938
  const newItems = {
938
939
  $filter: {
939
940
  input: { $ifNull: [`$after.${k2}`, []] },
@@ -977,31 +978,37 @@ const $unwindDelta = (k1, k2, k, includeNull, middle) => {
977
978
  },
978
979
  },
979
980
  };
980
- const ifNull = (k, part, str = `$${k}.${part}._id`) => outer && k == k2 ? { $ifNull: [str, 'null'] } : str;
981
+ const ifNull = (k, part, str = `$${k}.${part}._id`) => outer2 && k == k2 ? { $ifNull: [str, 'null'] } : str;
981
982
  const interDot = ([a, b]) => [a, middle ?? '.', b];
982
- const partReplace = (part) => ({
983
- $cond: {
984
- if: { $or: [{ $eq: [`$${k1}.${part}`, null] }, { $eq: [`$${k2}.${part}`, null] }] },
985
- then: null,
986
- else: {
987
- _id: k
988
- ? ifNull(k, part)
989
- : {
990
- $concat: interDot([k1, k2].sort().map(k => ifNull(k, part))),
983
+ const partReplace = (part) => {
984
+ const def = {
985
+ _id: k
986
+ ? ifNull(k, part)
987
+ : {
988
+ $concat: interDot([k1, k2].sort().map(k => ifNull(k, part))),
989
+ },
990
+ [k1]: `$${k1}.${part}`,
991
+ [k2]: outer2
992
+ ? {
993
+ $cond: {
994
+ if: `$${k2}.${part}._id`,
995
+ then: `$${k2}.${part}`,
996
+ else: null,
991
997
  },
992
- [k1]: `$${k1}.${part}`,
993
- [k2]: outer
994
- ? {
995
- $cond: {
996
- if: `$${k2}.${part}._id`,
997
- then: `$${k2}.${part}`,
998
- else: null,
999
- },
1000
- }
1001
- : `$${k2}.${part}`,
998
+ }
999
+ : `$${k2}.${part}`,
1000
+ };
1001
+ const skipNulls = [{ $eq: [`$${k1}.${part}`, null] }, { $eq: [`$${k2}.${part}`, null] }].filter((_, i) => ![outer1, outer2][i]);
1002
+ if (skipNulls.length === 0)
1003
+ return def;
1004
+ return {
1005
+ $cond: {
1006
+ if: skipNulls.length === 1 ? skipNulls[0] : { $or: skipNulls },
1007
+ then: null,
1008
+ else: def,
1002
1009
  },
1003
- },
1004
- });
1010
+ };
1011
+ };
1005
1012
  const part = (k) => root().of(k).expr();
1006
1013
  const stages = link()
1007
1014
  .with(asStages([
@@ -1013,7 +1020,7 @@ const $unwindDelta = (k1, k2, k, includeNull, middle) => {
1013
1020
  },
1014
1021
  [k2]: {
1015
1022
  $concatArrays: [
1016
- outer
1023
+ outer2
1017
1024
  ? {
1018
1025
  $cond: {
1019
1026
  if: { $eq: [`$before.${k2}`, []] },
@@ -1030,7 +1037,7 @@ const $unwindDelta = (k1, k2, k, includeNull, middle) => {
1030
1037
  : oldItems,
1031
1038
  {
1032
1039
  $map: {
1033
- input: outer
1040
+ input: outer2
1034
1041
  ? {
1035
1042
  $cond: {
1036
1043
  if: {
@@ -1073,7 +1080,7 @@ const $unwind = (k, dict, middle) => {
1073
1080
  left: ['left', root().expr()],
1074
1081
  right: ['right', root().of(k).expr()],
1075
1082
  })))
1076
- .with($unwindDelta('left', 'right', false, undefined, middle))
1083
+ .with($unwindDelta('left', 'right', false, middle))
1077
1084
  .with($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({
1078
1085
  key: root().of('right').expr(),
1079
1086
  id: root().of('_id').expr(),
@@ -1082,7 +1089,8 @@ const $unwind = (k, dict, middle) => {
1082
1089
  };
1083
1090
  };
1084
1091
 
1085
- const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, includeNull) => {
1092
+ const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, includeNull1, includeNull2) => {
1093
+ const omit = omitRORec();
1086
1094
  return link()
1087
1095
  .with($replaceWithDelta(field(map1(k1, root().expr()))))
1088
1096
  .with($simpleLookup_({
@@ -1107,11 +1115,19 @@ const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, incl
1107
1115
  }))
1108
1116
  .with($replaceWithEach((f) => {
1109
1117
  const f1 = f === 'after' ? 'a' : 'b';
1110
- const omit = omitRORec();
1111
1118
  const a = root().of(f1).of('before').expr();
1112
1119
  const part = root().of(f);
1113
1120
  return ite(eq(root().of(f).expr())(nil), nil, field(omit.backward(mergeExpr(omit.forward(map1(k2, a)), map1(k1, part.of(k1).expr())))));
1114
- })).with($unwindDelta(k1, k2, k, includeNull)).stages;
1121
+ }))
1122
+ .with(includeNull1 === null
1123
+ ? $replaceWithEach((f) => {
1124
+ return $ifNull(root().of(f).expr(), field(omit.backward(mergeExpr(omit.forward(map1(k2, root()
1125
+ .of(f === 'after' ? 'before' : 'after')
1126
+ .of(k2)
1127
+ .expr())), map1(k1, nil)))));
1128
+ })
1129
+ : link().stages)
1130
+ .with($unwindDelta(k1, k2, k, undefined, includeNull1, includeNull2)).stages;
1115
1131
  };
1116
1132
 
1117
1133
  const $lookupRaw = ({ field1, field2 }, { coll, exec, input }, k2, k, includeNull) => (f) => {
@@ -1154,7 +1170,10 @@ const createIndex = async (collection, indexSpec, options) => {
1154
1170
  }
1155
1171
  };
1156
1172
 
1157
- const patch = (x, k, v) => ({ ...x, [k]: v });
1173
+ const patch = ({ ...x }, k, v) => {
1174
+ delete x[k];
1175
+ return { ...x, [k]: v };
1176
+ };
1158
1177
  const restart = (sources) => {
1159
1178
  return map(sources, x => x.stop());
1160
1179
  };
@@ -1276,8 +1295,8 @@ const join = ({ lField, rField, left, right, as }, leftSnapshot, rightSnapshot,
1276
1295
  stages: consume => consume(concatTStages(resultingSnapshot, asBefore(stagesUntilNextLookup.raw))),
1277
1296
  out: (finalInput) => {
1278
1297
  const leftJoinField = { field1: rField, field2: lField };
1279
- const joinL_Delta = $lookupDelta(leftJoinField, leftSnapshot, 'right', 'left', joinId);
1280
- const joinR_Delta = $lookupDelta(rightJoinField, rightSnapshot, 'left', 'right', joinId, outerLeft);
1298
+ const joinL_Delta = $lookupDelta(leftJoinField, leftSnapshot, 'right', 'left', joinId, outerLeft);
1299
+ const joinR_Delta = $lookupDelta(rightJoinField, rightSnapshot, 'left', 'right', joinId, undefined, outerLeft);
1281
1300
  const mergeForeignIntoDoc = concatStages($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({ a: root().of('right').expr(), b: root().of('_id').expr() }, dictId))), stagesUntilNextLookup.delta);
1282
1301
  const lRunnerInput = concatStages(joinR_Delta, mergeForeignIntoDoc);
1283
1302
  const rRunnerInput = concatStages(joinL_Delta, mergeForeignIntoDoc);
@@ -1642,8 +1661,8 @@ const executes$2 = (view, input, streamName, skip = false, after) => {
1642
1661
  await after?.();
1643
1662
  return nextData([])(async () => {
1644
1663
  await new Promise(resolve => setTimeout(resolve, 1000));
1645
- return step3(same)();
1646
- }, 'clone into new collection');
1664
+ return next(step3(same), 'clone into new collection');
1665
+ }, 'wait for clone into new collection');
1647
1666
  };
1648
1667
  const step3 = (lastTS) => async () => {
1649
1668
  const notDeleted = eq($ifNull(root().of('deletedAt').expr(), nil))(nil);
package/index.js CHANGED
@@ -934,8 +934,9 @@ const dualIn = operator();
934
934
  const $in = dualIn('$in');
935
935
  const $nin = dualIn('$nin');
936
936
 
937
- const $unwindDelta = (k1, k2, k, includeNull, middle) => {
938
- const outer = includeNull === null;
937
+ const $unwindDelta = (k1, k2, k, middle, includeNull1, includeNull2) => {
938
+ const outer1 = includeNull1 === null;
939
+ const outer2 = includeNull2 === null;
939
940
  const newItems = {
940
941
  $filter: {
941
942
  input: { $ifNull: [`$after.${k2}`, []] },
@@ -979,31 +980,37 @@ const $unwindDelta = (k1, k2, k, includeNull, middle) => {
979
980
  },
980
981
  },
981
982
  };
982
- const ifNull = (k, part, str = `$${k}.${part}._id`) => outer && k == k2 ? { $ifNull: [str, 'null'] } : str;
983
+ const ifNull = (k, part, str = `$${k}.${part}._id`) => outer2 && k == k2 ? { $ifNull: [str, 'null'] } : str;
983
984
  const interDot = ([a, b]) => [a, middle ?? '.', b];
984
- const partReplace = (part) => ({
985
- $cond: {
986
- if: { $or: [{ $eq: [`$${k1}.${part}`, null] }, { $eq: [`$${k2}.${part}`, null] }] },
987
- then: null,
988
- else: {
989
- _id: k
990
- ? ifNull(k, part)
991
- : {
992
- $concat: interDot([k1, k2].sort().map(k => ifNull(k, part))),
985
+ const partReplace = (part) => {
986
+ const def = {
987
+ _id: k
988
+ ? ifNull(k, part)
989
+ : {
990
+ $concat: interDot([k1, k2].sort().map(k => ifNull(k, part))),
991
+ },
992
+ [k1]: `$${k1}.${part}`,
993
+ [k2]: outer2
994
+ ? {
995
+ $cond: {
996
+ if: `$${k2}.${part}._id`,
997
+ then: `$${k2}.${part}`,
998
+ else: null,
993
999
  },
994
- [k1]: `$${k1}.${part}`,
995
- [k2]: outer
996
- ? {
997
- $cond: {
998
- if: `$${k2}.${part}._id`,
999
- then: `$${k2}.${part}`,
1000
- else: null,
1001
- },
1002
- }
1003
- : `$${k2}.${part}`,
1000
+ }
1001
+ : `$${k2}.${part}`,
1002
+ };
1003
+ const skipNulls = [{ $eq: [`$${k1}.${part}`, null] }, { $eq: [`$${k2}.${part}`, null] }].filter((_, i) => ![outer1, outer2][i]);
1004
+ if (skipNulls.length === 0)
1005
+ return def;
1006
+ return {
1007
+ $cond: {
1008
+ if: skipNulls.length === 1 ? skipNulls[0] : { $or: skipNulls },
1009
+ then: null,
1010
+ else: def,
1004
1011
  },
1005
- },
1006
- });
1012
+ };
1013
+ };
1007
1014
  const part = (k) => root().of(k).expr();
1008
1015
  const stages = link()
1009
1016
  .with(asStages([
@@ -1015,7 +1022,7 @@ const $unwindDelta = (k1, k2, k, includeNull, middle) => {
1015
1022
  },
1016
1023
  [k2]: {
1017
1024
  $concatArrays: [
1018
- outer
1025
+ outer2
1019
1026
  ? {
1020
1027
  $cond: {
1021
1028
  if: { $eq: [`$before.${k2}`, []] },
@@ -1032,7 +1039,7 @@ const $unwindDelta = (k1, k2, k, includeNull, middle) => {
1032
1039
  : oldItems,
1033
1040
  {
1034
1041
  $map: {
1035
- input: outer
1042
+ input: outer2
1036
1043
  ? {
1037
1044
  $cond: {
1038
1045
  if: {
@@ -1075,7 +1082,7 @@ const $unwind = (k, dict, middle) => {
1075
1082
  left: ['left', root().expr()],
1076
1083
  right: ['right', root().of(k).expr()],
1077
1084
  })))
1078
- .with($unwindDelta('left', 'right', false, undefined, middle))
1085
+ .with($unwindDelta('left', 'right', false, middle))
1079
1086
  .with($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({
1080
1087
  key: root().of('right').expr(),
1081
1088
  id: root().of('_id').expr(),
@@ -1084,7 +1091,8 @@ const $unwind = (k, dict, middle) => {
1084
1091
  };
1085
1092
  };
1086
1093
 
1087
- const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, includeNull) => {
1094
+ const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, includeNull1, includeNull2) => {
1095
+ const omit = omitRORec();
1088
1096
  return link()
1089
1097
  .with($replaceWithDelta(field(map1(k1, root().expr()))))
1090
1098
  .with($simpleLookup_({
@@ -1109,11 +1117,19 @@ const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, incl
1109
1117
  }))
1110
1118
  .with($replaceWithEach((f) => {
1111
1119
  const f1 = f === 'after' ? 'a' : 'b';
1112
- const omit = omitRORec();
1113
1120
  const a = root().of(f1).of('before').expr();
1114
1121
  const part = root().of(f);
1115
1122
  return ite(eq(root().of(f).expr())(nil), nil, field(omit.backward(mergeExpr(omit.forward(map1(k2, a)), map1(k1, part.of(k1).expr())))));
1116
- })).with($unwindDelta(k1, k2, k, includeNull)).stages;
1123
+ }))
1124
+ .with(includeNull1 === null
1125
+ ? $replaceWithEach((f) => {
1126
+ return $ifNull(root().of(f).expr(), field(omit.backward(mergeExpr(omit.forward(map1(k2, root()
1127
+ .of(f === 'after' ? 'before' : 'after')
1128
+ .of(k2)
1129
+ .expr())), map1(k1, nil)))));
1130
+ })
1131
+ : link().stages)
1132
+ .with($unwindDelta(k1, k2, k, undefined, includeNull1, includeNull2)).stages;
1117
1133
  };
1118
1134
 
1119
1135
  const $lookupRaw = ({ field1, field2 }, { coll, exec, input }, k2, k, includeNull) => (f) => {
@@ -1156,7 +1172,10 @@ const createIndex = async (collection, indexSpec, options) => {
1156
1172
  }
1157
1173
  };
1158
1174
 
1159
- const patch = (x, k, v) => ({ ...x, [k]: v });
1175
+ const patch = ({ ...x }, k, v) => {
1176
+ delete x[k];
1177
+ return { ...x, [k]: v };
1178
+ };
1160
1179
  const restart = (sources) => {
1161
1180
  return map(sources, x => x.stop());
1162
1181
  };
@@ -1278,8 +1297,8 @@ const join = ({ lField, rField, left, right, as }, leftSnapshot, rightSnapshot,
1278
1297
  stages: consume => consume(concatTStages(resultingSnapshot, asBefore(stagesUntilNextLookup.raw))),
1279
1298
  out: (finalInput) => {
1280
1299
  const leftJoinField = { field1: rField, field2: lField };
1281
- const joinL_Delta = $lookupDelta(leftJoinField, leftSnapshot, 'right', 'left', joinId);
1282
- const joinR_Delta = $lookupDelta(rightJoinField, rightSnapshot, 'left', 'right', joinId, outerLeft);
1300
+ const joinL_Delta = $lookupDelta(leftJoinField, leftSnapshot, 'right', 'left', joinId, outerLeft);
1301
+ const joinR_Delta = $lookupDelta(rightJoinField, rightSnapshot, 'left', 'right', joinId, undefined, outerLeft);
1283
1302
  const mergeForeignIntoDoc = concatStages($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({ a: root().of('right').expr(), b: root().of('_id').expr() }, dictId))), stagesUntilNextLookup.delta);
1284
1303
  const lRunnerInput = concatStages(joinR_Delta, mergeForeignIntoDoc);
1285
1304
  const rRunnerInput = concatStages(joinL_Delta, mergeForeignIntoDoc);
@@ -1644,8 +1663,8 @@ const executes$2 = (view, input, streamName, skip = false, after) => {
1644
1663
  await after?.();
1645
1664
  return nextData([])(async () => {
1646
1665
  await new Promise(resolve => setTimeout(resolve, 1000));
1647
- return step3(same)();
1648
- }, 'clone into new collection');
1666
+ return next(step3(same), 'clone into new collection');
1667
+ }, 'wait for clone into new collection');
1649
1668
  };
1650
1669
  const step3 = (lastTS) => async () => {
1651
1670
  const notDeleted = eq($ifNull(root().of('deletedAt').expr(), nil))(nil);
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.80",
6
+ "version": "0.0.82",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",