@omegup/msync 0.0.81 → 0.0.83
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 +2 -2
- package/index.esm.js +48 -34
- package/index.js +48 -34
- package/package.json +1 -1
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
|
|
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,
|
|
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
|
@@ -646,13 +646,13 @@ const $setEach1 = (updater, dict) => {
|
|
|
646
646
|
return $set1(set()(mapExact1(dict, updater)));
|
|
647
647
|
};
|
|
648
648
|
const $setEach = (updater, dict) => $setEach1(updater, dict)(root);
|
|
649
|
-
const $
|
|
650
|
-
const t = deltaExpr(expr);
|
|
649
|
+
const $replaceWithEach1 = (t) => {
|
|
651
650
|
return $setEach(k => to(t(k)), {
|
|
652
651
|
after: ['after', 'after'],
|
|
653
652
|
before: ['before', 'before'],
|
|
654
653
|
});
|
|
655
654
|
};
|
|
655
|
+
const $replaceWithEach = (expr) => $replaceWithEach1(deltaExpr(expr));
|
|
656
656
|
|
|
657
657
|
const $replaceWithDelta = (expr) => $replaceWithEach((field) => sub(expr, root().of(field)));
|
|
658
658
|
const $setDelta = (updater) => {
|
|
@@ -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,
|
|
936
|
-
const
|
|
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`) =>
|
|
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
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
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
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
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
|
-
|
|
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:
|
|
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,
|
|
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,
|
|
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,17 @@ 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
|
-
}))
|
|
1121
|
+
}))
|
|
1122
|
+
.with(includeNull1 === null
|
|
1123
|
+
? $replaceWithEach1((f) => {
|
|
1124
|
+
const otherField = root().of(f === 'after' ? 'before' : 'after');
|
|
1125
|
+
return $ifNull(root().of(f).expr(), field(omit.backward(mergeExpr(omit.forward(map1(k2, otherField.of(k2).expr())), map1(k1, nil)))));
|
|
1126
|
+
})
|
|
1127
|
+
: link().stages)
|
|
1128
|
+
.with($unwindDelta(k1, k2, k, undefined, includeNull1, includeNull2)).stages;
|
|
1115
1129
|
};
|
|
1116
1130
|
|
|
1117
1131
|
const $lookupRaw = ({ field1, field2 }, { coll, exec, input }, k2, k, includeNull) => (f) => {
|
|
@@ -1279,8 +1293,8 @@ const join = ({ lField, rField, left, right, as }, leftSnapshot, rightSnapshot,
|
|
|
1279
1293
|
stages: consume => consume(concatTStages(resultingSnapshot, asBefore(stagesUntilNextLookup.raw))),
|
|
1280
1294
|
out: (finalInput) => {
|
|
1281
1295
|
const leftJoinField = { field1: rField, field2: lField };
|
|
1282
|
-
const joinL_Delta = $lookupDelta(leftJoinField, leftSnapshot, 'right', 'left', joinId);
|
|
1283
|
-
const joinR_Delta = $lookupDelta(rightJoinField, rightSnapshot, 'left', 'right', joinId, outerLeft);
|
|
1296
|
+
const joinL_Delta = $lookupDelta(leftJoinField, leftSnapshot, 'right', 'left', joinId, outerLeft);
|
|
1297
|
+
const joinR_Delta = $lookupDelta(rightJoinField, rightSnapshot, 'left', 'right', joinId, undefined, outerLeft);
|
|
1284
1298
|
const mergeForeignIntoDoc = concatStages($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({ a: root().of('right').expr(), b: root().of('_id').expr() }, dictId))), stagesUntilNextLookup.delta);
|
|
1285
1299
|
const lRunnerInput = concatStages(joinR_Delta, mergeForeignIntoDoc);
|
|
1286
1300
|
const rRunnerInput = concatStages(joinL_Delta, mergeForeignIntoDoc);
|
package/index.js
CHANGED
|
@@ -648,13 +648,13 @@ const $setEach1 = (updater, dict) => {
|
|
|
648
648
|
return $set1(set()(mapExact1(dict, updater)));
|
|
649
649
|
};
|
|
650
650
|
const $setEach = (updater, dict) => $setEach1(updater, dict)(root);
|
|
651
|
-
const $
|
|
652
|
-
const t = deltaExpr(expr);
|
|
651
|
+
const $replaceWithEach1 = (t) => {
|
|
653
652
|
return $setEach(k => to(t(k)), {
|
|
654
653
|
after: ['after', 'after'],
|
|
655
654
|
before: ['before', 'before'],
|
|
656
655
|
});
|
|
657
656
|
};
|
|
657
|
+
const $replaceWithEach = (expr) => $replaceWithEach1(deltaExpr(expr));
|
|
658
658
|
|
|
659
659
|
const $replaceWithDelta = (expr) => $replaceWithEach((field) => sub(expr, root().of(field)));
|
|
660
660
|
const $setDelta = (updater) => {
|
|
@@ -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,
|
|
938
|
-
const
|
|
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`) =>
|
|
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
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
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
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
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
|
-
|
|
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:
|
|
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,
|
|
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,
|
|
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,17 @@ 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
|
-
}))
|
|
1123
|
+
}))
|
|
1124
|
+
.with(includeNull1 === null
|
|
1125
|
+
? $replaceWithEach1((f) => {
|
|
1126
|
+
const otherField = root().of(f === 'after' ? 'before' : 'after');
|
|
1127
|
+
return $ifNull(root().of(f).expr(), field(omit.backward(mergeExpr(omit.forward(map1(k2, otherField.of(k2).expr())), map1(k1, nil)))));
|
|
1128
|
+
})
|
|
1129
|
+
: link().stages)
|
|
1130
|
+
.with($unwindDelta(k1, k2, k, undefined, includeNull1, includeNull2)).stages;
|
|
1117
1131
|
};
|
|
1118
1132
|
|
|
1119
1133
|
const $lookupRaw = ({ field1, field2 }, { coll, exec, input }, k2, k, includeNull) => (f) => {
|
|
@@ -1281,8 +1295,8 @@ const join = ({ lField, rField, left, right, as }, leftSnapshot, rightSnapshot,
|
|
|
1281
1295
|
stages: consume => consume(concatTStages(resultingSnapshot, asBefore(stagesUntilNextLookup.raw))),
|
|
1282
1296
|
out: (finalInput) => {
|
|
1283
1297
|
const leftJoinField = { field1: rField, field2: lField };
|
|
1284
|
-
const joinL_Delta = $lookupDelta(leftJoinField, leftSnapshot, 'right', 'left', joinId);
|
|
1285
|
-
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);
|
|
1286
1300
|
const mergeForeignIntoDoc = concatStages($replaceWithDelta(mergeObjects(root().of('left').expr(), fieldM({ a: root().of('right').expr(), b: root().of('_id').expr() }, dictId))), stagesUntilNextLookup.delta);
|
|
1287
1301
|
const lRunnerInput = concatStages(joinR_Delta, mergeForeignIntoDoc);
|
|
1288
1302
|
const rRunnerInput = concatStages(joinL_Delta, mergeForeignIntoDoc);
|