@omegup/msync 0.1.11 → 0.1.13
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 +32 -20
- package/index.js +32 -19
- 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,18 @@ 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 = whenNotMatched !== 'fail'
|
|
833
|
+
? mergeObjects(root().of('old').expr(), field({
|
|
834
|
+
deletedAt: ['deletedAt', orNull(root().of('old').of('deletedAt').expr())],
|
|
835
|
+
touchedAt: ['touchedAt', root().of('merged').of('touchedAt').expr()],
|
|
836
|
+
}))
|
|
837
|
+
: root().of('old').expr();
|
|
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;
|
|
837
840
|
};
|
|
838
841
|
const $mergeX = (out, keys, f, map, ext) => {
|
|
839
842
|
const patch = mapExact(keys, v => sub(v, f));
|
|
@@ -853,14 +856,14 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
853
856
|
on: root().of('_id'),
|
|
854
857
|
whenNotMatched: 'insert',
|
|
855
858
|
stages: true,
|
|
856
|
-
whenMatched:
|
|
859
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
857
860
|
})).stages
|
|
858
861
|
: link().with($merge_({
|
|
859
862
|
into: out.coll,
|
|
860
863
|
on: root().of('_id'),
|
|
861
864
|
whenNotMatched: 'fail',
|
|
862
865
|
stages: true,
|
|
863
|
-
whenMatched:
|
|
866
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
864
867
|
})).stages;
|
|
865
868
|
const teardown = (coll) => ({
|
|
866
869
|
collection: coll,
|
|
@@ -897,9 +900,12 @@ const assertNotNull$1 = (expr) => expr;
|
|
|
897
900
|
|
|
898
901
|
const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
899
902
|
const e = extra;
|
|
900
|
-
const
|
|
903
|
+
const mergeOldWithNew = mapExact0(args, (v, k) => to(first
|
|
901
904
|
? ctx()('new').of(k).expr()
|
|
902
|
-
: 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
|
+
}));
|
|
903
909
|
const gidPath = root().of(gid).expr();
|
|
904
910
|
const mapId = (k, v) => map1(k, v);
|
|
905
911
|
const F1 = {
|
|
@@ -914,18 +920,24 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
914
920
|
};
|
|
915
921
|
const addExtra = mapExact0(e, to);
|
|
916
922
|
const updater = set()(addExtra);
|
|
923
|
+
const whenMatched = getWhenMatched(out.whenNotMatched);
|
|
917
924
|
return link()
|
|
918
925
|
.with($set_(set()(addExtraAndMerge)))
|
|
919
926
|
.with($merge_({
|
|
920
927
|
...out,
|
|
921
|
-
whenNotMatched: 'fail',
|
|
922
928
|
on: root().of(gid),
|
|
923
929
|
vars: { new: ['new', root().expr()] },
|
|
924
930
|
stages: 'ctx',
|
|
925
931
|
whenMatched: link()
|
|
932
|
+
.with($replaceWith_(field({ old: ['old', root().expr()], merged: ['merged', root().expr()] })))
|
|
926
933
|
.with(mergeAggregates)
|
|
927
|
-
.with($set_(
|
|
928
|
-
|
|
934
|
+
.with($set_(set()({
|
|
935
|
+
merged: [
|
|
936
|
+
'merged',
|
|
937
|
+
subUpdater(updater, root().of('merged')),
|
|
938
|
+
],
|
|
939
|
+
})))
|
|
940
|
+
.with(whenMatched).stages,
|
|
929
941
|
})).stages;
|
|
930
942
|
};
|
|
931
943
|
|
|
@@ -1470,7 +1482,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
|
|
|
1470
1482
|
into: out,
|
|
1471
1483
|
on: root().of('_id'),
|
|
1472
1484
|
stages: true,
|
|
1473
|
-
whenMatched:
|
|
1485
|
+
whenMatched: getWhenMatchedForMerge('insert'),
|
|
1474
1486
|
whenNotMatched: 'insert',
|
|
1475
1487
|
})).stages;
|
|
1476
1488
|
},
|
|
@@ -1994,4 +2006,4 @@ const makeCol = async (docs, database, name) => {
|
|
|
1994
2006
|
}
|
|
1995
2007
|
};
|
|
1996
2008
|
|
|
1997
|
-
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 };
|
|
2009
|
+
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,18 @@ 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 = whenNotMatched !== 'fail'
|
|
835
|
+
? mergeObjects(root().of('old').expr(), field({
|
|
836
|
+
deletedAt: ['deletedAt', orNull(root().of('old').of('deletedAt').expr())],
|
|
837
|
+
touchedAt: ['touchedAt', root().of('merged').of('touchedAt').expr()],
|
|
838
|
+
}))
|
|
839
|
+
: root().of('old').expr();
|
|
840
|
+
const same = eq(preMergeOld)(root().of('merged').expr());
|
|
841
|
+
return link().with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
|
|
839
842
|
};
|
|
840
843
|
const $mergeX = (out, keys, f, map, ext) => {
|
|
841
844
|
const patch = mapExact(keys, v => sub(v, f));
|
|
@@ -855,14 +858,14 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
855
858
|
on: root().of('_id'),
|
|
856
859
|
whenNotMatched: 'insert',
|
|
857
860
|
stages: true,
|
|
858
|
-
whenMatched:
|
|
861
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
859
862
|
})).stages
|
|
860
863
|
: link().with($merge_({
|
|
861
864
|
into: out.coll,
|
|
862
865
|
on: root().of('_id'),
|
|
863
866
|
whenNotMatched: 'fail',
|
|
864
867
|
stages: true,
|
|
865
|
-
whenMatched:
|
|
868
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
866
869
|
})).stages;
|
|
867
870
|
const teardown = (coll) => ({
|
|
868
871
|
collection: coll,
|
|
@@ -899,9 +902,12 @@ const assertNotNull$1 = (expr) => expr;
|
|
|
899
902
|
|
|
900
903
|
const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
901
904
|
const e = extra;
|
|
902
|
-
const
|
|
905
|
+
const mergeOldWithNew = mapExact0(args, (v, k) => to(first
|
|
903
906
|
? ctx()('new').of(k).expr()
|
|
904
|
-
: v.merge(root().of(k).expr(), ctx()('new').of(k).expr())))
|
|
907
|
+
: v.merge(root().of('old').of(k).expr(), ctx()('new').of(k).expr())));
|
|
908
|
+
const mergeAggregates = $set_(set()({
|
|
909
|
+
merged: ['merged', set()(mergeOldWithNew)],
|
|
910
|
+
}));
|
|
905
911
|
const gidPath = root().of(gid).expr();
|
|
906
912
|
const mapId = (k, v) => map1(k, v);
|
|
907
913
|
const F1 = {
|
|
@@ -916,18 +922,24 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
916
922
|
};
|
|
917
923
|
const addExtra = mapExact0(e, to);
|
|
918
924
|
const updater = set()(addExtra);
|
|
925
|
+
const whenMatched = getWhenMatched(out.whenNotMatched);
|
|
919
926
|
return link()
|
|
920
927
|
.with($set_(set()(addExtraAndMerge)))
|
|
921
928
|
.with($merge_({
|
|
922
929
|
...out,
|
|
923
|
-
whenNotMatched: 'fail',
|
|
924
930
|
on: root().of(gid),
|
|
925
931
|
vars: { new: ['new', root().expr()] },
|
|
926
932
|
stages: 'ctx',
|
|
927
933
|
whenMatched: link()
|
|
934
|
+
.with($replaceWith_(field({ old: ['old', root().expr()], merged: ['merged', root().expr()] })))
|
|
928
935
|
.with(mergeAggregates)
|
|
929
|
-
.with($set_(
|
|
930
|
-
|
|
936
|
+
.with($set_(set()({
|
|
937
|
+
merged: [
|
|
938
|
+
'merged',
|
|
939
|
+
subUpdater(updater, root().of('merged')),
|
|
940
|
+
],
|
|
941
|
+
})))
|
|
942
|
+
.with(whenMatched).stages,
|
|
931
943
|
})).stages;
|
|
932
944
|
};
|
|
933
945
|
|
|
@@ -1472,7 +1484,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
|
|
|
1472
1484
|
into: out,
|
|
1473
1485
|
on: root().of('_id'),
|
|
1474
1486
|
stages: true,
|
|
1475
|
-
whenMatched:
|
|
1487
|
+
whenMatched: getWhenMatchedForMerge('insert'),
|
|
1476
1488
|
whenNotMatched: 'insert',
|
|
1477
1489
|
})).stages;
|
|
1478
1490
|
},
|
|
@@ -2084,6 +2096,7 @@ exports.floor = floor;
|
|
|
2084
2096
|
exports.from = from;
|
|
2085
2097
|
exports.func = func;
|
|
2086
2098
|
exports.getWhenMatched = getWhenMatched;
|
|
2099
|
+
exports.getWhenMatchedForMerge = getWhenMatchedForMerge;
|
|
2087
2100
|
exports.gt = gt;
|
|
2088
2101
|
exports.gte = gte;
|
|
2089
2102
|
exports.inArray = inArray;
|