@omegup/msync 0.1.12 → 0.1.14
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 +3 -2
- package/index.esm.js +35 -21
- package/index.js +35 -20
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -507,7 +507,8 @@ type ND$1 = {
|
|
|
507
507
|
readonly deletedAt?: null;
|
|
508
508
|
};
|
|
509
509
|
type SafeE$1<E> = Omit<E, `$${string}` | keyof ID>;
|
|
510
|
-
declare const
|
|
510
|
+
declare const getWhenMatchedForMerge: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert") => RawStages<O, Out, Out | Replace<Out, P>, RORec<"new", Replace<P, RORec<K, Timestamp>>>>;
|
|
511
|
+
declare const getWhenMatched: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert") => RawStages<O, Rec<"old" | "merged", Out | Replace<Out, P>>, Out | Replace<Out, P>>;
|
|
511
512
|
type MergeCollection<V extends O, Out extends Model> = {
|
|
512
513
|
coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
|
|
513
514
|
whenNotMatched: 'discard';
|
|
@@ -733,4 +734,4 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
|
|
|
733
734
|
declare const prepare: (testName?: string) => Promise<MongoClient$1>;
|
|
734
735
|
declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
|
|
735
736
|
|
|
736
|
-
export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, type ExactKeys, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type MongoTypeNames, type N, type NoRaw, type NullToOBJ, type O, type OPick, type OPickD, type Patch, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, getWhenMatched, gt, gte, inArray, isArray, ite, type jsonPrim, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, type notArr, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
|
|
737
|
+
export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, type ExactKeys, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type MongoTypeNames, type N, type NoRaw, type NullToOBJ, type O, type OPick, type OPickD, type Patch, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, type jsonPrim, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, type notArr, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
|
package/index.esm.js
CHANGED
|
@@ -811,16 +811,8 @@ const $merge_ = ({ into, on, whenNotMatched, ...notMatched }) => asStages([
|
|
|
811
811
|
]);
|
|
812
812
|
const $merge2 = (args) => $merge_(args);
|
|
813
813
|
|
|
814
|
-
const
|
|
815
|
-
const
|
|
816
|
-
const orNull = (e) => (setDeleted ? $ifNull(e, nil) : e);
|
|
817
|
-
const preMergeOld = setDeleted
|
|
818
|
-
? mergeObjects(root().of('old').expr(), field({
|
|
819
|
-
deletedAt: ['deletedAt', orNull(root().of('old').of('deletedAt').expr())],
|
|
820
|
-
touchedAt: ['touchedAt', root().of('merged').of('touchedAt').expr()],
|
|
821
|
-
}))
|
|
822
|
-
: root().of('old').expr();
|
|
823
|
-
const same = eq(preMergeOld)(root().of('merged').expr());
|
|
814
|
+
const getWhenMatchedForMerge = (whenNotMatched) => {
|
|
815
|
+
const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
|
|
824
816
|
const newOrOld = whenNotMatched ===
|
|
825
817
|
'insert'
|
|
826
818
|
? ctx()('new')
|
|
@@ -833,7 +825,16 @@ const getWhenMatched = (whenNotMatched) => {
|
|
|
833
825
|
old: ['old', root().expr()],
|
|
834
826
|
merged: ['merged', merged],
|
|
835
827
|
})))
|
|
836
|
-
.with(
|
|
828
|
+
.with(getWhenMatched(whenNotMatched)).stages;
|
|
829
|
+
};
|
|
830
|
+
const getWhenMatched = (whenNotMatched) => {
|
|
831
|
+
const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
|
|
832
|
+
const preMergeOld = mergeObjects(root().of('old').expr(), field({
|
|
833
|
+
deletedAt: ['deletedAt', orNull(root().of('old').of('deletedAt').expr())],
|
|
834
|
+
touchedAt: ['touchedAt', root().of('merged').of('touchedAt').expr()],
|
|
835
|
+
}));
|
|
836
|
+
const same = eq(preMergeOld)(root().of('merged').expr());
|
|
837
|
+
return link().with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
|
|
837
838
|
};
|
|
838
839
|
const $mergeX = (out, keys, f, map, ext) => {
|
|
839
840
|
const patch = mapExact(keys, v => sub(v, f));
|
|
@@ -853,14 +854,14 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
853
854
|
on: root().of('_id'),
|
|
854
855
|
whenNotMatched: 'insert',
|
|
855
856
|
stages: true,
|
|
856
|
-
whenMatched:
|
|
857
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
857
858
|
})).stages
|
|
858
859
|
: link().with($merge_({
|
|
859
860
|
into: out.coll,
|
|
860
861
|
on: root().of('_id'),
|
|
861
862
|
whenNotMatched: 'fail',
|
|
862
863
|
stages: true,
|
|
863
|
-
whenMatched:
|
|
864
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
864
865
|
})).stages;
|
|
865
866
|
const teardown = (coll) => ({
|
|
866
867
|
collection: coll,
|
|
@@ -897,9 +898,12 @@ const assertNotNull$1 = (expr) => expr;
|
|
|
897
898
|
|
|
898
899
|
const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
899
900
|
const e = extra;
|
|
900
|
-
const
|
|
901
|
+
const mergeOldWithNew = mapExact0(args, (v, k) => to(first
|
|
901
902
|
? ctx()('new').of(k).expr()
|
|
902
|
-
: v.merge(root().of(k).expr(), ctx()('new').of(k).expr())))
|
|
903
|
+
: v.merge(root().of('old').of(k).expr(), ctx()('new').of(k).expr())));
|
|
904
|
+
const mergeAggregates = $set_(set()({
|
|
905
|
+
merged: ['merged', set()(mergeOldWithNew)],
|
|
906
|
+
}));
|
|
903
907
|
const gidPath = root().of(gid).expr();
|
|
904
908
|
const mapId = (k, v) => map1(k, v);
|
|
905
909
|
const F1 = {
|
|
@@ -912,8 +916,12 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
912
916
|
...F1,
|
|
913
917
|
...F2,
|
|
914
918
|
};
|
|
915
|
-
const
|
|
916
|
-
|
|
919
|
+
const addTSAndExtra = {
|
|
920
|
+
...mapExact0(e, to),
|
|
921
|
+
touchedAt: ['touchedAt', to(current)],
|
|
922
|
+
};
|
|
923
|
+
const updater = set()(addTSAndExtra);
|
|
924
|
+
const whenMatched = getWhenMatched(out.whenNotMatched);
|
|
917
925
|
return link()
|
|
918
926
|
.with($set_(set()(addExtraAndMerge)))
|
|
919
927
|
.with($merge_({
|
|
@@ -922,9 +930,15 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
922
930
|
vars: { new: ['new', root().expr()] },
|
|
923
931
|
stages: 'ctx',
|
|
924
932
|
whenMatched: link()
|
|
933
|
+
.with($replaceWith_(field({ old: ['old', root().expr()], merged: ['merged', root().expr()] })))
|
|
925
934
|
.with(mergeAggregates)
|
|
926
|
-
.with($set_(
|
|
927
|
-
|
|
935
|
+
.with($set_(set()({
|
|
936
|
+
merged: [
|
|
937
|
+
'merged',
|
|
938
|
+
subUpdater(updater, root().of('merged')),
|
|
939
|
+
],
|
|
940
|
+
})))
|
|
941
|
+
.with(whenMatched).stages,
|
|
928
942
|
})).stages;
|
|
929
943
|
};
|
|
930
944
|
|
|
@@ -1469,7 +1483,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
|
|
|
1469
1483
|
into: out,
|
|
1470
1484
|
on: root().of('_id'),
|
|
1471
1485
|
stages: true,
|
|
1472
|
-
whenMatched:
|
|
1486
|
+
whenMatched: getWhenMatchedForMerge('insert'),
|
|
1473
1487
|
whenNotMatched: 'insert',
|
|
1474
1488
|
})).stages;
|
|
1475
1489
|
},
|
|
@@ -1993,4 +2007,4 @@ const makeCol = async (docs, database, name) => {
|
|
|
1993
2007
|
}
|
|
1994
2008
|
};
|
|
1995
2009
|
|
|
1996
|
-
export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, getWhenMatched, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
|
|
2010
|
+
export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
|
package/index.js
CHANGED
|
@@ -813,16 +813,8 @@ const $merge_ = ({ into, on, whenNotMatched, ...notMatched }) => asStages([
|
|
|
813
813
|
]);
|
|
814
814
|
const $merge2 = (args) => $merge_(args);
|
|
815
815
|
|
|
816
|
-
const
|
|
817
|
-
const
|
|
818
|
-
const orNull = (e) => (setDeleted ? $ifNull(e, nil) : e);
|
|
819
|
-
const preMergeOld = setDeleted
|
|
820
|
-
? mergeObjects(root().of('old').expr(), field({
|
|
821
|
-
deletedAt: ['deletedAt', orNull(root().of('old').of('deletedAt').expr())],
|
|
822
|
-
touchedAt: ['touchedAt', root().of('merged').of('touchedAt').expr()],
|
|
823
|
-
}))
|
|
824
|
-
: root().of('old').expr();
|
|
825
|
-
const same = eq(preMergeOld)(root().of('merged').expr());
|
|
816
|
+
const getWhenMatchedForMerge = (whenNotMatched) => {
|
|
817
|
+
const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
|
|
826
818
|
const newOrOld = whenNotMatched ===
|
|
827
819
|
'insert'
|
|
828
820
|
? ctx()('new')
|
|
@@ -835,7 +827,16 @@ const getWhenMatched = (whenNotMatched) => {
|
|
|
835
827
|
old: ['old', root().expr()],
|
|
836
828
|
merged: ['merged', merged],
|
|
837
829
|
})))
|
|
838
|
-
.with(
|
|
830
|
+
.with(getWhenMatched(whenNotMatched)).stages;
|
|
831
|
+
};
|
|
832
|
+
const getWhenMatched = (whenNotMatched) => {
|
|
833
|
+
const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
|
|
834
|
+
const preMergeOld = mergeObjects(root().of('old').expr(), field({
|
|
835
|
+
deletedAt: ['deletedAt', orNull(root().of('old').of('deletedAt').expr())],
|
|
836
|
+
touchedAt: ['touchedAt', root().of('merged').of('touchedAt').expr()],
|
|
837
|
+
}));
|
|
838
|
+
const same = eq(preMergeOld)(root().of('merged').expr());
|
|
839
|
+
return link().with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
|
|
839
840
|
};
|
|
840
841
|
const $mergeX = (out, keys, f, map, ext) => {
|
|
841
842
|
const patch = mapExact(keys, v => sub(v, f));
|
|
@@ -855,14 +856,14 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
855
856
|
on: root().of('_id'),
|
|
856
857
|
whenNotMatched: 'insert',
|
|
857
858
|
stages: true,
|
|
858
|
-
whenMatched:
|
|
859
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
859
860
|
})).stages
|
|
860
861
|
: link().with($merge_({
|
|
861
862
|
into: out.coll,
|
|
862
863
|
on: root().of('_id'),
|
|
863
864
|
whenNotMatched: 'fail',
|
|
864
865
|
stages: true,
|
|
865
|
-
whenMatched:
|
|
866
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
866
867
|
})).stages;
|
|
867
868
|
const teardown = (coll) => ({
|
|
868
869
|
collection: coll,
|
|
@@ -899,9 +900,12 @@ const assertNotNull$1 = (expr) => expr;
|
|
|
899
900
|
|
|
900
901
|
const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
901
902
|
const e = extra;
|
|
902
|
-
const
|
|
903
|
+
const mergeOldWithNew = mapExact0(args, (v, k) => to(first
|
|
903
904
|
? ctx()('new').of(k).expr()
|
|
904
|
-
: v.merge(root().of(k).expr(), ctx()('new').of(k).expr())))
|
|
905
|
+
: v.merge(root().of('old').of(k).expr(), ctx()('new').of(k).expr())));
|
|
906
|
+
const mergeAggregates = $set_(set()({
|
|
907
|
+
merged: ['merged', set()(mergeOldWithNew)],
|
|
908
|
+
}));
|
|
905
909
|
const gidPath = root().of(gid).expr();
|
|
906
910
|
const mapId = (k, v) => map1(k, v);
|
|
907
911
|
const F1 = {
|
|
@@ -914,8 +918,12 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
914
918
|
...F1,
|
|
915
919
|
...F2,
|
|
916
920
|
};
|
|
917
|
-
const
|
|
918
|
-
|
|
921
|
+
const addTSAndExtra = {
|
|
922
|
+
...mapExact0(e, to),
|
|
923
|
+
touchedAt: ['touchedAt', to(current)],
|
|
924
|
+
};
|
|
925
|
+
const updater = set()(addTSAndExtra);
|
|
926
|
+
const whenMatched = getWhenMatched(out.whenNotMatched);
|
|
919
927
|
return link()
|
|
920
928
|
.with($set_(set()(addExtraAndMerge)))
|
|
921
929
|
.with($merge_({
|
|
@@ -924,9 +932,15 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
924
932
|
vars: { new: ['new', root().expr()] },
|
|
925
933
|
stages: 'ctx',
|
|
926
934
|
whenMatched: link()
|
|
935
|
+
.with($replaceWith_(field({ old: ['old', root().expr()], merged: ['merged', root().expr()] })))
|
|
927
936
|
.with(mergeAggregates)
|
|
928
|
-
.with($set_(
|
|
929
|
-
|
|
937
|
+
.with($set_(set()({
|
|
938
|
+
merged: [
|
|
939
|
+
'merged',
|
|
940
|
+
subUpdater(updater, root().of('merged')),
|
|
941
|
+
],
|
|
942
|
+
})))
|
|
943
|
+
.with(whenMatched).stages,
|
|
930
944
|
})).stages;
|
|
931
945
|
};
|
|
932
946
|
|
|
@@ -1471,7 +1485,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
|
|
|
1471
1485
|
into: out,
|
|
1472
1486
|
on: root().of('_id'),
|
|
1473
1487
|
stages: true,
|
|
1474
|
-
whenMatched:
|
|
1488
|
+
whenMatched: getWhenMatchedForMerge('insert'),
|
|
1475
1489
|
whenNotMatched: 'insert',
|
|
1476
1490
|
})).stages;
|
|
1477
1491
|
},
|
|
@@ -2083,6 +2097,7 @@ exports.floor = floor;
|
|
|
2083
2097
|
exports.from = from;
|
|
2084
2098
|
exports.func = func;
|
|
2085
2099
|
exports.getWhenMatched = getWhenMatched;
|
|
2100
|
+
exports.getWhenMatchedForMerge = getWhenMatchedForMerge;
|
|
2086
2101
|
exports.gt = gt;
|
|
2087
2102
|
exports.gte = gte;
|
|
2088
2103
|
exports.inArray = inArray;
|