@omegup/msync 0.1.59 → 0.1.61
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 +6 -5
- package/index.esm.js +27 -12
- package/index.js +27 -11
- package/lib/accumulators/index.d.ts +28 -0
- package/lib/aggregate/$merge.d.ts +38 -0
- package/lib/aggregate/$upsert.d.ts +19 -0
- package/lib/aggregate/group/$group-merge.d.ts +18 -0
- package/lib/aggregate/group/index.d.ts +3 -0
- package/lib/aggregate/group/utils/sub-group.d.ts +6 -0
- package/lib/aggregate/group/utils/sub-merge.d.ts +20 -0
- package/lib/aggregate/index.d.ts +10 -0
- package/lib/aggregate/lookup/$lookup-delta.d.ts +11 -0
- package/lib/aggregate/lookup/$lookup-raw.d.ts +10 -0
- package/lib/aggregate/lookup/index.d.ts +20 -0
- package/lib/aggregate/match/$match-delta.d.ts +4 -0
- package/lib/aggregate/match/$match.d.ts +3 -0
- package/lib/aggregate/match/index.d.ts +2 -0
- package/lib/aggregate/mongo-stages.d.ts +13 -0
- package/lib/aggregate/out.d.ts +37 -0
- package/lib/aggregate/prefix.d.ts +33 -0
- package/lib/aggregate/raws.d.ts +17 -0
- package/lib/aggregate/set/$replace-with-each.d.ts +13 -0
- package/lib/aggregate/set/$set-delta.d.ts +5 -0
- package/lib/aggregate/set/$set.d.ts +9 -0
- package/lib/aggregate/set/index.d.ts +1 -0
- package/lib/aggregate/unwind/$unwind-delta.d.ts +7 -0
- package/lib/aggregate/unwind/index.d.ts +6 -0
- package/lib/boot/boot-simpl.d.ts +14 -0
- package/lib/boot/boot-utils.d.ts +27 -0
- package/lib/boot/boot.d.ts +16 -0
- package/lib/boot/first-stages.d.ts +13 -0
- package/lib/boot/index.d.ts +3 -0
- package/lib/boot/single.d.ts +11 -0
- package/lib/expression/arith.d.ts +34 -0
- package/lib/expression/array.d.ts +30 -0
- package/lib/expression/concat.d.ts +35 -0
- package/lib/expression/date.d.ts +22 -0
- package/lib/expression/expr-base.d.ts +5 -0
- package/lib/expression/index.d.ts +7 -0
- package/lib/expression/logic.d.ts +26 -0
- package/lib/expression/range.d.ts +11 -0
- package/lib/expression/val.d.ts +18 -0
- package/lib/field/field.d.ts +25 -0
- package/lib/field/index.d.ts +1 -0
- package/lib/machine.d.ts +9 -0
- package/lib/predicate/$eq.d.ts +24 -0
- package/lib/predicate/$expr.d.ts +3 -0
- package/lib/predicate/$in.d.ts +2 -0
- package/lib/predicate/index.d.ts +3 -0
- package/lib/predicate/utils.d.ts +5 -0
- package/lib/query/index.d.ts +1 -0
- package/lib/query/logic.d.ts +11 -0
- package/lib/stream/aggregate.d.ts +7 -0
- package/lib/types/accumulator.d.ts +32 -0
- package/lib/types/aggregate.d.ts +9 -0
- package/lib/types/expr.d.ts +27 -0
- package/lib/types/extern.d.ts +4 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/lookup.d.ts +19 -0
- package/lib/types/machine.d.ts +17 -0
- package/lib/types/predicate.d.ts +11 -0
- package/lib/types/query.d.ts +12 -0
- package/lib/types/stream.d.ts +82 -0
- package/lib/update/index.d.ts +1 -0
- package/lib/update/updater.d.ts +23 -0
- package/lib/utils/before.d.ts +3 -0
- package/lib/utils/coll.d.ts +5 -0
- package/lib/utils/db-indexes.d.ts +7 -0
- package/lib/utils/guard.d.ts +21 -0
- package/lib/utils/index.d.ts +5 -0
- package/lib/utils/json.d.ts +9 -0
- package/lib/utils/log.d.ts +1 -0
- package/lib/utils/map-object.d.ts +41 -0
- package/lib/utils/merge/combiners.d.ts +6 -0
- package/lib/utils/merge/index.d.ts +2 -0
- package/lib/utils/merge/merge.d.ts +10 -0
- package/lib/utils/merge/next-winner.d.ts +3 -0
- package/lib/utils/merge/types.d.ts +19 -0
- package/lib/utils/merge/utils.d.ts +4 -0
- package/lib/utils/tear-down.d.ts +2 -0
- package/lib/watch.d.ts +30 -0
- package/package.json +1 -1
- package/test/mongodb.d.ts +9 -0
- package/test/uri.d.ts +1 -0
- package/types/class.d.ts +1 -0
- package/types/extern.d.ts +5 -0
- package/types/global-aug.d.ts +48 -0
- package/types/global.d.ts +2 -0
- package/types/hkt.d.ts +56 -0
- package/types/index.d.ts +6 -0
- package/types/json.d.ts +54 -0
- package/types/mongo.d.ts +24 -0
- package/types/view.d.ts +35 -0
package/index.d.ts
CHANGED
|
@@ -606,8 +606,9 @@ type Result<P> = Expr<P, unknown, {
|
|
|
606
606
|
}>;
|
|
607
607
|
type Update$1<P, Out> = (...args: Args<P, Out>) => Result<P>;
|
|
608
608
|
type UpdateF<P, Out> = <K extends keyof IsDeleted>(...args: Args<Replace<P, RORec<K, Timestamp>>, Out>) => Result<Replace<P, RORec<K, Timestamp>>>;
|
|
609
|
-
declare const
|
|
610
|
-
declare const
|
|
609
|
+
declare const getSubsetMatchForExt: <Out extends Model, P extends Model, E extends Record<keyof E, rawItem>>(ext: Exact<E, IdHKT>) => null | Expr<boolean, Rec<"old" | "merged", Out | Replace<Out, P>>>;
|
|
610
|
+
declare const getWhenMatchedForMerge: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert", update: Update$1<Replace<P, RORec<K, Timestamp>>, Out>, canWrite: Expr<boolean, Rec<"old" | "merged", Out | Replace<Out, P>>> | null) => RawStages<O, Out, Out | Replace<Out, P>, RORec<"new", Replace<P, RORec<K, Timestamp>>>>;
|
|
611
|
+
declare const getWhenMatched: <Out extends Model, P extends Model>(whenNotMatched: "discard" | "fail" | "insert", canWrite: Expr<boolean, Rec<"old" | "merged", Out | Replace<Out, P>>> | null) => RawStages<O, Rec<"old" | "merged", Out | Replace<Out, P>>, Out | Replace<Out, P>>;
|
|
611
612
|
type MergeCollection<V extends O, Out extends Model> = {
|
|
612
613
|
coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
|
|
613
614
|
whenNotMatched: 'discard';
|
|
@@ -632,7 +633,7 @@ type ExprP<P> = Expr<P, unknown, {
|
|
|
632
633
|
}>;
|
|
633
634
|
type Update<P, Out> = (added: ExprP<P>, old: Expr<Out, Out>) => ExprP<P>;
|
|
634
635
|
declare const $insertX: <T extends doc, D extends O, EEE extends RORec<string, rawItem>>(out: RWCollection<Merge<T, EEE>>, expr: Expr<T, D>, map: (x: Expr<T & ND & TS & Omit<SafeE<EEE>, keyof (ND & TS)>, D>) => Expr<Merge<T, EEE>, D>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, extExpr: ExprsExact<Omit<SafeE<EEE>, keyof (ND & TS)>, unknown>, update?: Update<Replace<Merge<T, EEE>, {}>, Merge<T, EEE>>) => StreamRunnerParam<D, "out">;
|
|
635
|
-
declare const $simpleInsert: <T extends doc
|
|
636
|
+
declare const $simpleInsert: <T extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Merge<T, EEE>>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>) => StreamRunnerParam<T, "out">;
|
|
636
637
|
declare const $insertPart: <T extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Merge<T, EEE>>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>) => StreamRunnerParam<Delta<T>, "out">;
|
|
637
638
|
declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
|
|
638
639
|
|
|
@@ -770,7 +771,7 @@ declare const not: <D, C = unknown>(expr: Expr<boolean, D, C>) => Expr<boolean,
|
|
|
770
771
|
declare const eq: <T, D, C = unknown>(a: Expr<T, D, C>) => (b: Expr<T, D, C>) => Expr<boolean, D, C>;
|
|
771
772
|
declare const sub: <T, D, Ctx, P extends O>(a: Expr<T, D, Ctx>, f: Field<P, D, Ctx>) => Expr<T, P, Ctx>;
|
|
772
773
|
declare const eqTyped: <T1 extends Dom, T2 extends Dom, F extends HKT<Dom>, C = unknown, Dom = unknown>(a: Expr<T1 | T2, App<F, T1 | T2>, C>, b: Expr<T1, App<F, T1 | T2>, C>) => BoolExpr<App<F, T1>, App<F, T2>, C>;
|
|
773
|
-
declare const ne: <T, D, C>(a: Expr<T, D, C>) => <K>(b: Expr<K, D, C>) => Expr<boolean, D, C>;
|
|
774
|
+
declare const ne: <T, D, C = unknown>(a: Expr<T, D, C>) => <K>(b: Expr<K, D, C>) => Expr<boolean, D, C>;
|
|
774
775
|
declare const notNull: <T, D, C>(a: Expr<T, D, C>) => Expr<boolean, D, C>;
|
|
775
776
|
declare const $ifNull: {
|
|
776
777
|
<R, D, C = unknown>(...expr: [...Expr<R | null | undefined, D, C>[], Expr<R, D, C>]): Expr<R, D, C>;
|
|
@@ -842,5 +843,5 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
|
|
|
842
843
|
declare const prepare: (testName?: string) => Promise<MongoClient$1>;
|
|
843
844
|
declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
|
|
844
845
|
|
|
845
|
-
export { $accumulator, $and, $countDict, $countDictArray, $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, $substr, $sum, $type, $unwind, $unwindDelta, Expr, Field, Machine, Type, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, emptyDelta, enablePreAndPostImages, eq, eqExtends, eqPar, eqTyped, except, excludeIdem, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, fromEq, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, joinIdOf, last, literalsEqaul, log, lt, lte, makeCol, map, map1, mapExact, mapExact0, mapExact1, mapExactToObject, mapExactToObject0, mapExactToObject1, mapFromPlainDateTime, mapToPlainDateTime, mapVal, matchDelta, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, min, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, omitExclude, omitPick, omitRORec, or, padLeft, prepare, rand, range, reflex, regex, renamedFields, root, set, setField, single, size, slice, sortArray, spread, spread0, staging, startOf, str, sub, subtract, sym, to, toInt, translateOmit, val, weekPart, wrap, year };
|
|
846
|
+
export { $accumulator, $and, $countDict, $countDictArray, $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, $substr, $sum, $type, $unwind, $unwindDelta, Expr, Field, Machine, Type, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, emptyDelta, enablePreAndPostImages, eq, eqExtends, eqPar, eqTyped, except, excludeIdem, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, fromEq, func, getSubsetMatchForExt, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, joinIdOf, last, literalsEqaul, log, lt, lte, makeCol, map, map1, mapExact, mapExact0, mapExact1, mapExactToObject, mapExactToObject0, mapExactToObject1, mapFromPlainDateTime, mapToPlainDateTime, mapVal, matchDelta, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, min, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, omitExclude, omitPick, omitRORec, or, padLeft, prepare, rand, range, reflex, regex, renamedFields, root, set, setField, single, size, slice, sortArray, spread, spread0, staging, startOf, str, sub, subtract, sym, to, toInt, translateOmit, val, weekPart, wrap, year };
|
|
846
847
|
export type { Accumulators, AddO, And, App, AppMap, AppMapRW, ApplyHKT, Arr, ArrHKT, AsLiteral, ConstHKT, DeepFieldHKT, Delta, DeltaAccumulator, DeltaAccumulatorHKT, DeltaAccumulators, DeltaStages, Equal, Exact, ExactKeys, ExactPart, ExactPart1, ExprHKT, Exprs, ExprsExact, ExprsExactHKT, ExprsPart, FieldHKT, GroupCollection, GroupIdCollection, GroupMergeCollection, GroupMergeOut, HKT, I, ID, IdHKT, JoinId, Loose, MapK, MapKDom, MapKPart1, MapO, MapOPart, MappedHKT, Merge, MergeArgs, MergeHKT, MergeInto, MergeMapOArgs, MergedInput, Model, MongoTypeNames, N, NullToOBJ, O, OPick, OPickD, Patch, PromiseHKT, RConstHKT, RORec, RWCollection, RawStages, Rec, RecHKT, RecordHKT, Replace, SnapshotStreamExecutionResult, StrKey, Strict, TS, UBeforeHKT, WithKey1, WriteonlyCollection, doc, jsonPrim, notArr, µ };
|
package/index.esm.js
CHANGED
|
@@ -919,7 +919,17 @@ const $merge_ = ({ into, on, whenNotMatched, ...notMatched }) => asStages([
|
|
|
919
919
|
]);
|
|
920
920
|
const $merge2 = (args) => $merge_(args);
|
|
921
921
|
|
|
922
|
-
const
|
|
922
|
+
const getSubsetMatchForExt = (ext) => {
|
|
923
|
+
const extObj = mapExactToObject(ext, (v, k) => {
|
|
924
|
+
return eq(root()
|
|
925
|
+
.of('old')
|
|
926
|
+
.of(k)
|
|
927
|
+
.expr())(val(v));
|
|
928
|
+
});
|
|
929
|
+
const checks = Object.values(extObj);
|
|
930
|
+
return checks.length ? (checks.length === 1 ? checks[0] : and(...checks)) : null;
|
|
931
|
+
};
|
|
932
|
+
const getWhenMatchedForMerge = (whenNotMatched, update, canWrite) => {
|
|
923
933
|
const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
|
|
924
934
|
const newOrOld = whenNotMatched ===
|
|
925
935
|
'insert'
|
|
@@ -933,22 +943,24 @@ const getWhenMatchedForMerge = (whenNotMatched, update) => {
|
|
|
933
943
|
old: ['old', root().expr()],
|
|
934
944
|
merged: ['merged', merged],
|
|
935
945
|
})))
|
|
936
|
-
.with(getWhenMatched(whenNotMatched)).stages;
|
|
946
|
+
.with(getWhenMatched(whenNotMatched, canWrite)).stages;
|
|
937
947
|
};
|
|
938
|
-
const getWhenMatched = (whenNotMatched) => {
|
|
948
|
+
const getWhenMatched = (whenNotMatched, canWrite) => {
|
|
939
949
|
const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
|
|
940
950
|
const preMergeOld = mergeObjects(root().of('old').expr(), field({
|
|
941
951
|
deletedAt: ['deletedAt', orNull(root().of('old').of('deletedAt').expr())],
|
|
942
952
|
touchedAt: ['touchedAt', root().of('merged').of('touchedAt').expr()],
|
|
943
953
|
}));
|
|
944
|
-
const
|
|
945
|
-
|
|
954
|
+
const diff = ne(preMergeOld)(root().of('merged').expr());
|
|
955
|
+
const useNew = canWrite ? and(diff, canWrite) : diff;
|
|
956
|
+
return link().with($replaceWith_(ite(useNew, root().of('merged').expr(), root().of('old').expr()))).stages;
|
|
946
957
|
};
|
|
947
958
|
const $mergeX = (out, keys, f, map, ext, update) => {
|
|
948
959
|
const patch = mapExact(keys, (v) => {
|
|
949
960
|
return $ifNull(sub(v, f), nil);
|
|
950
961
|
});
|
|
951
962
|
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
963
|
+
const sameSubset = getSubsetMatchForExt(ext);
|
|
952
964
|
const setDeleted = out.whenNotMatched === 'discard';
|
|
953
965
|
const replacer = map(field(omitPick().backward(spread(patch, {
|
|
954
966
|
_id: ['_id', f.of('_id').expr()],
|
|
@@ -964,14 +976,14 @@ const $mergeX = (out, keys, f, map, ext, update) => {
|
|
|
964
976
|
on: root().of('_id'),
|
|
965
977
|
whenNotMatched: 'insert',
|
|
966
978
|
stages: true,
|
|
967
|
-
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
|
|
979
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update, sameSubset),
|
|
968
980
|
})).stages
|
|
969
981
|
: link().with($merge_({
|
|
970
982
|
into: out.coll,
|
|
971
983
|
on: root().of('_id'),
|
|
972
984
|
whenNotMatched: 'fail',
|
|
973
985
|
stages: true,
|
|
974
|
-
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
|
|
986
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update, sameSubset),
|
|
975
987
|
})).stages;
|
|
976
988
|
const teardown = (coll) => ({
|
|
977
989
|
collection: coll,
|
|
@@ -1032,7 +1044,7 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
1032
1044
|
touchedAt: ['touchedAt', to(current)],
|
|
1033
1045
|
};
|
|
1034
1046
|
const updater = set()(addTSAndExtra);
|
|
1035
|
-
const whenMatched = getWhenMatched(out.whenNotMatched);
|
|
1047
|
+
const whenMatched = getWhenMatched(out.whenNotMatched, null);
|
|
1036
1048
|
return link()
|
|
1037
1049
|
.with($set_(set()(addExtraAndMerge)))
|
|
1038
1050
|
.with($merge_({
|
|
@@ -1698,6 +1710,7 @@ const $replaceWith = (expr) => ({
|
|
|
1698
1710
|
|
|
1699
1711
|
const $insertX = (out, expr, map, ext, extExpr, update = x => x) => {
|
|
1700
1712
|
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
1713
|
+
const sameSubset = getSubsetMatchForExt(ext);
|
|
1701
1714
|
return {
|
|
1702
1715
|
teardown: c => c({
|
|
1703
1716
|
collection: out,
|
|
@@ -1718,13 +1731,16 @@ const $insertX = (out, expr, map, ext, extExpr, update = x => x) => {
|
|
|
1718
1731
|
into: out,
|
|
1719
1732
|
on: root().of('_id'),
|
|
1720
1733
|
stages: true,
|
|
1721
|
-
whenMatched: getWhenMatchedForMerge('insert', update),
|
|
1734
|
+
whenMatched: getWhenMatchedForMerge('insert', update, sameSubset),
|
|
1722
1735
|
whenNotMatched: 'insert',
|
|
1723
1736
|
})).stages;
|
|
1724
1737
|
},
|
|
1725
1738
|
};
|
|
1726
1739
|
};
|
|
1727
|
-
const $simpleInsert = (out
|
|
1740
|
+
const $simpleInsert = (out, ext) => {
|
|
1741
|
+
const extExpr = mapExact(ext, (v) => val(v));
|
|
1742
|
+
return $insertX(out, root().expr(), id$1, ext, extExpr);
|
|
1743
|
+
};
|
|
1728
1744
|
const $insertPart = (out, ext) => {
|
|
1729
1745
|
const extExpr = mapExact(ext, (v) => val(v));
|
|
1730
1746
|
return $insertX(out, assertNotNull(root().of('after').expr()), x => ite(eq(root().of('after').expr())(nil), field(mergeExpr(translateOmit().forward(extExpr), {
|
|
@@ -2179,7 +2195,6 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
2179
2195
|
.with(input.delta)
|
|
2180
2196
|
.with(stages).stages,
|
|
2181
2197
|
}), false, start);
|
|
2182
|
-
stages.at(-1).$merge.into.coll;
|
|
2183
2198
|
return next(step5({ ts: result.cursor.atClusterTime, aggResult, stream, nextRes, first }), 'remove handled deleted updated');
|
|
2184
2199
|
};
|
|
2185
2200
|
const step5 = (l) => async () => {
|
|
@@ -2427,4 +2442,4 @@ const makeCol = async (docs, database, name) => {
|
|
|
2427
2442
|
}
|
|
2428
2443
|
};
|
|
2429
2444
|
|
|
2430
|
-
export { $accumulator, $and, $countDict, $countDictArray, $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, $substr, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, emptyDelta, enablePreAndPostImages, eq, eqExtends, eqPar, eqTyped, except, excludeIdem, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, fromEq, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, joinIdOf, last, literalsEqaul, log, lt, lte, makeCol, map, map1, mapExact, mapExact0, mapExact1, mapExactToObject, mapExactToObject0, mapExactToObject1, mapFromPlainDateTime, mapToPlainDateTime, mapVal, matchDelta, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, min, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, omitExclude, omitPick, omitRORec, or, padLeft, prepare, rand, range, reflex, regex, renamedFields, root, set, setField, single, size, slice, sortArray, spread, spread0, staging, startOf, str, sub, subtract, sym, to, toInt, translateOmit, val, weekPart, wrap, year };
|
|
2445
|
+
export { $accumulator, $and, $countDict, $countDictArray, $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, $substr, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, emptyDelta, enablePreAndPostImages, eq, eqExtends, eqPar, eqTyped, except, excludeIdem, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, fromEq, func, getSubsetMatchForExt, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, joinIdOf, last, literalsEqaul, log, lt, lte, makeCol, map, map1, mapExact, mapExact0, mapExact1, mapExactToObject, mapExactToObject0, mapExactToObject1, mapFromPlainDateTime, mapToPlainDateTime, mapVal, matchDelta, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, min, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, omitExclude, omitPick, omitRORec, or, padLeft, prepare, rand, range, reflex, regex, renamedFields, root, set, setField, single, size, slice, sortArray, spread, spread0, staging, startOf, str, sub, subtract, sym, to, toInt, translateOmit, val, weekPart, wrap, year };
|
package/index.js
CHANGED
|
@@ -921,7 +921,17 @@ const $merge_ = ({ into, on, whenNotMatched, ...notMatched }) => asStages([
|
|
|
921
921
|
]);
|
|
922
922
|
const $merge2 = (args) => $merge_(args);
|
|
923
923
|
|
|
924
|
-
const
|
|
924
|
+
const getSubsetMatchForExt = (ext) => {
|
|
925
|
+
const extObj = mapExactToObject(ext, (v, k) => {
|
|
926
|
+
return eq(root()
|
|
927
|
+
.of('old')
|
|
928
|
+
.of(k)
|
|
929
|
+
.expr())(val(v));
|
|
930
|
+
});
|
|
931
|
+
const checks = Object.values(extObj);
|
|
932
|
+
return checks.length ? (checks.length === 1 ? checks[0] : and(...checks)) : null;
|
|
933
|
+
};
|
|
934
|
+
const getWhenMatchedForMerge = (whenNotMatched, update, canWrite) => {
|
|
925
935
|
const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
|
|
926
936
|
const newOrOld = whenNotMatched ===
|
|
927
937
|
'insert'
|
|
@@ -935,22 +945,24 @@ const getWhenMatchedForMerge = (whenNotMatched, update) => {
|
|
|
935
945
|
old: ['old', root().expr()],
|
|
936
946
|
merged: ['merged', merged],
|
|
937
947
|
})))
|
|
938
|
-
.with(getWhenMatched(whenNotMatched)).stages;
|
|
948
|
+
.with(getWhenMatched(whenNotMatched, canWrite)).stages;
|
|
939
949
|
};
|
|
940
|
-
const getWhenMatched = (whenNotMatched) => {
|
|
950
|
+
const getWhenMatched = (whenNotMatched, canWrite) => {
|
|
941
951
|
const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
|
|
942
952
|
const preMergeOld = mergeObjects(root().of('old').expr(), field({
|
|
943
953
|
deletedAt: ['deletedAt', orNull(root().of('old').of('deletedAt').expr())],
|
|
944
954
|
touchedAt: ['touchedAt', root().of('merged').of('touchedAt').expr()],
|
|
945
955
|
}));
|
|
946
|
-
const
|
|
947
|
-
|
|
956
|
+
const diff = ne(preMergeOld)(root().of('merged').expr());
|
|
957
|
+
const useNew = canWrite ? and(diff, canWrite) : diff;
|
|
958
|
+
return link().with($replaceWith_(ite(useNew, root().of('merged').expr(), root().of('old').expr()))).stages;
|
|
948
959
|
};
|
|
949
960
|
const $mergeX = (out, keys, f, map, ext, update) => {
|
|
950
961
|
const patch = mapExact(keys, (v) => {
|
|
951
962
|
return $ifNull(sub(v, f), nil);
|
|
952
963
|
});
|
|
953
964
|
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
965
|
+
const sameSubset = getSubsetMatchForExt(ext);
|
|
954
966
|
const setDeleted = out.whenNotMatched === 'discard';
|
|
955
967
|
const replacer = map(field(omitPick().backward(spread(patch, {
|
|
956
968
|
_id: ['_id', f.of('_id').expr()],
|
|
@@ -966,14 +978,14 @@ const $mergeX = (out, keys, f, map, ext, update) => {
|
|
|
966
978
|
on: root().of('_id'),
|
|
967
979
|
whenNotMatched: 'insert',
|
|
968
980
|
stages: true,
|
|
969
|
-
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
|
|
981
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update, sameSubset),
|
|
970
982
|
})).stages
|
|
971
983
|
: link().with($merge_({
|
|
972
984
|
into: out.coll,
|
|
973
985
|
on: root().of('_id'),
|
|
974
986
|
whenNotMatched: 'fail',
|
|
975
987
|
stages: true,
|
|
976
|
-
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
|
|
988
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update, sameSubset),
|
|
977
989
|
})).stages;
|
|
978
990
|
const teardown = (coll) => ({
|
|
979
991
|
collection: coll,
|
|
@@ -1034,7 +1046,7 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
1034
1046
|
touchedAt: ['touchedAt', to(current)],
|
|
1035
1047
|
};
|
|
1036
1048
|
const updater = set()(addTSAndExtra);
|
|
1037
|
-
const whenMatched = getWhenMatched(out.whenNotMatched);
|
|
1049
|
+
const whenMatched = getWhenMatched(out.whenNotMatched, null);
|
|
1038
1050
|
return link()
|
|
1039
1051
|
.with($set_(set()(addExtraAndMerge)))
|
|
1040
1052
|
.with($merge_({
|
|
@@ -1700,6 +1712,7 @@ const $replaceWith = (expr) => ({
|
|
|
1700
1712
|
|
|
1701
1713
|
const $insertX = (out, expr, map, ext, extExpr, update = x => x) => {
|
|
1702
1714
|
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
1715
|
+
const sameSubset = getSubsetMatchForExt(ext);
|
|
1703
1716
|
return {
|
|
1704
1717
|
teardown: c => c({
|
|
1705
1718
|
collection: out,
|
|
@@ -1720,13 +1733,16 @@ const $insertX = (out, expr, map, ext, extExpr, update = x => x) => {
|
|
|
1720
1733
|
into: out,
|
|
1721
1734
|
on: root().of('_id'),
|
|
1722
1735
|
stages: true,
|
|
1723
|
-
whenMatched: getWhenMatchedForMerge('insert', update),
|
|
1736
|
+
whenMatched: getWhenMatchedForMerge('insert', update, sameSubset),
|
|
1724
1737
|
whenNotMatched: 'insert',
|
|
1725
1738
|
})).stages;
|
|
1726
1739
|
},
|
|
1727
1740
|
};
|
|
1728
1741
|
};
|
|
1729
|
-
const $simpleInsert = (out
|
|
1742
|
+
const $simpleInsert = (out, ext) => {
|
|
1743
|
+
const extExpr = mapExact(ext, (v) => val(v));
|
|
1744
|
+
return $insertX(out, root().expr(), id$1, ext, extExpr);
|
|
1745
|
+
};
|
|
1730
1746
|
const $insertPart = (out, ext) => {
|
|
1731
1747
|
const extExpr = mapExact(ext, (v) => val(v));
|
|
1732
1748
|
return $insertX(out, assertNotNull(root().of('after').expr()), x => ite(eq(root().of('after').expr())(nil), field(mergeExpr(translateOmit().forward(extExpr), {
|
|
@@ -2181,7 +2197,6 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
2181
2197
|
.with(input.delta)
|
|
2182
2198
|
.with(stages).stages,
|
|
2183
2199
|
}), false, start);
|
|
2184
|
-
stages.at(-1).$merge.into.coll;
|
|
2185
2200
|
return next(step5({ ts: result.cursor.atClusterTime, aggResult, stream, nextRes, first }), 'remove handled deleted updated');
|
|
2186
2201
|
};
|
|
2187
2202
|
const step5 = (l) => async () => {
|
|
@@ -2523,6 +2538,7 @@ exports.floor = floor;
|
|
|
2523
2538
|
exports.from = from;
|
|
2524
2539
|
exports.fromEq = fromEq;
|
|
2525
2540
|
exports.func = func;
|
|
2541
|
+
exports.getSubsetMatchForExt = getSubsetMatchForExt;
|
|
2526
2542
|
exports.getWhenMatched = getWhenMatched;
|
|
2527
2543
|
exports.getWhenMatchedForMerge = getWhenMatchedForMerge;
|
|
2528
2544
|
exports.gt = gt;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AppMap, N, O, PRRec } from '../../types';
|
|
2
|
+
import type { ExprHKT } from '../expression/concat';
|
|
3
|
+
import { type AddO } from '../expression/val';
|
|
4
|
+
import type { DeltaAccumulator, Expr, Part } from '../types';
|
|
5
|
+
type AddOs<A extends readonly unknown[]> = {
|
|
6
|
+
[K in keyof A]: AddO<A[K]>;
|
|
7
|
+
};
|
|
8
|
+
type PushSides<V> = {
|
|
9
|
+
0: V[];
|
|
10
|
+
1: V[];
|
|
11
|
+
};
|
|
12
|
+
type PushDict<V> = PRRec<string, PushSides<V>>;
|
|
13
|
+
export declare const $sum: <D extends O, C = unknown>(expr: Expr<number | N, D, C>) => DeltaAccumulator<D, number, C>;
|
|
14
|
+
export declare const $accumulator: <D, T, Ctx, A extends readonly unknown[]>(init: () => T, accumulateArgs: AppMap<ExprHKT<Part<D>, Ctx>, AddOs<A>>, accumulate: (a: T, ...args: A) => T, merge: (...args: [T | N, T]) => T) => DeltaAccumulator<D, AddO<T>, Ctx>;
|
|
15
|
+
export declare const $countDict: <D extends O, K extends string = string, C = unknown>(expr: Expr<AddO<K>, D, C>) => DeltaAccumulator<D, AddO<PRRec<K, number>>, C>;
|
|
16
|
+
export declare const $countDictArray: <D extends O, K extends string = string, C = unknown>(expr: Expr<AddO<K[]>, D, C>) => DeltaAccumulator<D, AddO<PRRec<K, number>>, C>;
|
|
17
|
+
export declare const $pushDict: <D extends O, V, C = unknown>(key: Expr<string, D, C>, value: Expr<AddO<V>, D, C>) => DeltaAccumulator<D, O<{
|
|
18
|
+
[x: string]: O<{
|
|
19
|
+
0: import("../..").Arr<AddO<V>>;
|
|
20
|
+
1: import("../..").Arr<AddO<V>>;
|
|
21
|
+
}> | undefined;
|
|
22
|
+
}>, C>;
|
|
23
|
+
export declare const $keys: <D extends O, K extends string = string, C = unknown>(expr: Expr<AddO<PRRec<K, number>>, D, C>) => Expr<AddO<K[]>, D, C>;
|
|
24
|
+
export declare const $entries: <D extends O, V, C = unknown>(expr: Expr<AddO<PushDict<V>>, D, C>) => Expr<AddO<{
|
|
25
|
+
k: string;
|
|
26
|
+
v: V;
|
|
27
|
+
}[]>, D, C>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { IdHKT, OPick, RWCollection, Timestamp } from '../../types';
|
|
2
|
+
import type { doc, ID, N, O, rawItem, Rec, Replace, RORec, StrKey } from '../../types/json';
|
|
3
|
+
import { type ExprsExact } from '../expression/concat';
|
|
4
|
+
import type { Delta, Expr, IsDeleted, Model, RawStages, StreamRunnerParam, TS } from '../types';
|
|
5
|
+
import { type Exact } from '../utils/map-object';
|
|
6
|
+
type OutInputE<T, E, A = T | null> = ID & Rec<'after', A> & E;
|
|
7
|
+
type Allowed<K extends string> = Exclude<K, keyof (TS & ID)>;
|
|
8
|
+
export type Patch<V, KK extends StrKey<V> = StrKey<V>> = ((OPick<V, Allowed<KK>> & ID) | (Rec<Allowed<KK>, N> & ID)) & TS;
|
|
9
|
+
type TakeDoc<V, E = ID, KK extends StrKey<V> = StrKey<V>> = OPick<V, Allowed<KK>> & E;
|
|
10
|
+
type ND = {
|
|
11
|
+
readonly deletedAt?: null;
|
|
12
|
+
};
|
|
13
|
+
type SafeE<E> = Omit<E, `$${string}` | keyof ID>;
|
|
14
|
+
type Args<P, Out> = [added: Expr<P, unknown, {
|
|
15
|
+
new: P;
|
|
16
|
+
}>, old: Expr<Out, Out>];
|
|
17
|
+
type Result<P> = Expr<P, unknown, {
|
|
18
|
+
new: P;
|
|
19
|
+
}>;
|
|
20
|
+
type Update<P, Out> = (...args: Args<P, Out>) => Result<P>;
|
|
21
|
+
type UpdateF<P, Out> = <K extends keyof IsDeleted>(...args: Args<Replace<P, RORec<K, Timestamp>>, Out>) => Result<Replace<P, RORec<K, Timestamp>>>;
|
|
22
|
+
export declare const getSubsetMatchForExt: <Out extends Model, P extends Model, E extends Record<keyof E, rawItem>>(ext: Exact<E, IdHKT>) => null | Expr<boolean, Rec<"old" | "merged", Out | Replace<Out, P>>>;
|
|
23
|
+
export declare const getWhenMatchedForMerge: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert", update: Update<Replace<P, RORec<K, Timestamp>>, Out>, canWrite: Expr<boolean, Rec<"old" | "merged", Out | Replace<Out, P>>> | null) => RawStages<O, Out, Out | Replace<Out, P>, RORec<"new", Replace<P, RORec<K, Timestamp>>>>;
|
|
24
|
+
export declare const getWhenMatched: <Out extends Model, P extends Model>(whenNotMatched: "discard" | "fail" | "insert", canWrite: Expr<boolean, Rec<"old" | "merged", Out | Replace<Out, P>>> | null) => RawStages<O, Rec<"old" | "merged", Out | Replace<Out, P>>, Out | Replace<Out, P>>;
|
|
25
|
+
type MergeCollection<V extends O, Out extends Model> = {
|
|
26
|
+
coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
|
|
27
|
+
whenNotMatched: 'discard';
|
|
28
|
+
} | {
|
|
29
|
+
coll: RWCollection<Out | Replace<Out, Patch<V>>, Out>;
|
|
30
|
+
whenNotMatched: 'fail';
|
|
31
|
+
};
|
|
32
|
+
type MergeUpdate<V, Out> = UpdateF<((OPick<V, Allowed<StrKey<V>>> & ID) | (Rec<Allowed<StrKey<V>>, N> & ID)) & TS, Out>;
|
|
33
|
+
export declare const $mergeId: <V extends O>() => <SourcePart extends doc, Out extends Model, E = unknown, EEE extends RORec<string, rawItem> = {}>(out: MergeCollection<V, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, id: Expr<string, OutInputE<TakeDoc<V>, E, null>>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<OutInputE<SourcePart, E>, "out">;
|
|
34
|
+
export declare const $simpleMergePart: <V extends O>() => <Source extends doc, Out extends Model, EEE extends RORec<string, rawItem>>(out: MergeCollection<V, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Source, "out">;
|
|
35
|
+
export declare const $simpleMerge: <V extends O>() => <Source extends doc, Out extends Model>(out: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, whenNotMatched?: "fail" | "discard", update?: MergeUpdate<V, Out>) => StreamRunnerParam<Source, "out">;
|
|
36
|
+
export declare const $mergePart: <V extends O>() => <Out extends Model, SourcePart extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Delta<SourcePart>, "out">;
|
|
37
|
+
export declare const $merge: <V extends O>() => <Out extends Model, SourcePart extends doc>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Delta<SourcePart>, "out">;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IdHKT, Replace, RWCollection } from '../../types';
|
|
2
|
+
import type { ID, O, RORec, doc, rawItem } from '../../types/json';
|
|
3
|
+
import { type ExprsExact } from '../expression/concat';
|
|
4
|
+
import type { Del, Delta, Expr, StreamRunnerParam, TS } from '../types';
|
|
5
|
+
import { type Exact } from '../utils/map-object';
|
|
6
|
+
type ND = {
|
|
7
|
+
readonly deletedAt?: null;
|
|
8
|
+
};
|
|
9
|
+
type SafeE<E> = Omit<E, `$${string}` | keyof ID>;
|
|
10
|
+
export type Merge<T extends doc, E> = Omit<SafeE<E>, keyof (ND & TS)> & ((T & ND & TS) | Del);
|
|
11
|
+
type ExprP<P> = Expr<P, unknown, {
|
|
12
|
+
new: P;
|
|
13
|
+
}>;
|
|
14
|
+
type Update<P, Out> = (added: ExprP<P>, old: Expr<Out, Out>) => ExprP<P>;
|
|
15
|
+
export declare const $insertX: <T extends doc, D extends O, EEE extends RORec<string, rawItem>>(out: RWCollection<Merge<T, EEE>>, expr: Expr<T, D>, map: (x: Expr<T & ND & TS & Omit<SafeE<EEE>, keyof (ND & TS)>, D>) => Expr<Merge<T, EEE>, D>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, extExpr: ExprsExact<Omit<SafeE<EEE>, keyof (ND & TS)>, unknown>, update?: Update<Replace<Merge<T, EEE>, {}>, Merge<T, EEE>>) => StreamRunnerParam<D, "out">;
|
|
16
|
+
export declare const $simpleInsert: <T extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Merge<T, EEE>>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>) => StreamRunnerParam<T, "out">;
|
|
17
|
+
export declare const $insertPart: <T extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Merge<T, EEE>>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>) => StreamRunnerParam<Delta<T>, "out">;
|
|
18
|
+
export declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RWCollection, WriteonlyCollection } from '../../../types';
|
|
2
|
+
import type { AsLiteral, ID, O, Rec, doc, notArr } from '../../../types/json';
|
|
3
|
+
import { type ExprsExact } from '../../expression/concat';
|
|
4
|
+
import type { Delta, DeltaAccumulators, Expr, StreamRunnerParam, TS } from '../../types';
|
|
5
|
+
import type { MergeInto } from '../out';
|
|
6
|
+
import { type Extra, type IdAndTsKeys, type Loose, type MergedInput, type Strict, type V_Grp } from './utils/sub-merge';
|
|
7
|
+
type Denied<GID = never> = keyof (TS & ID) | GID;
|
|
8
|
+
type GI<GG> = Exclude<GG, keyof TS>;
|
|
9
|
+
export type GroupMergeOut<Grp extends notArr, V extends O, GG extends string, EE = {}, Out extends Loose<Grp, V, GG> = Loose<Grp, V, GG>> = MergeInto<Strict<Grp, V, GG, EE>, Out, WriteonlyCollection<MergedInput<Out, V, Grp, GG, EE>>>;
|
|
10
|
+
export type GroupMergeCollection<WhenNotMatched extends MergeInto<never, never>['whenNotMatched'], Grp extends notArr, V extends O, GG extends string, EE = {}, Out extends Loose<Grp, V, GG> = Loose<Grp, V, GG>> = (GroupMergeOut<Grp, V, GG, EE, Out> & {
|
|
11
|
+
whenNotMatched: WhenNotMatched;
|
|
12
|
+
})['into'];
|
|
13
|
+
export 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: GroupMergeOut<Grp, V, GG, EE, Out>, gid: AsLiteral<GI<GG>>, extra: ExprsExact<Extra<EE, V, GG>, V_Grp<V, GG, Grp>>, idPrefix?: string) => StreamRunnerParam<Delta<T>, "out">;
|
|
14
|
+
export type GroupIdCollection<V extends O, EE = {}, Out extends Loose<string, V, '_id'> = Loose<string, V, '_id'>> = RWCollection<MergedInput<Out, V, string, '_id', EE>, Out>;
|
|
15
|
+
export 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: GroupIdCollection<V, EE, Out>, extra: ExprsExact<Omit<EE, IdAndTsKeys | keyof Omit<V, IdAndTsKeys>>, doc & Omit<V, IdAndTsKeys>>) => StreamRunnerParam<Delta<T>, "out">;
|
|
16
|
+
export type GroupCollection<Grp extends notArr, V extends O, EE = {}, Out extends Loose<Grp, V, '_grp'> = Loose<Grp, V, '_grp'>> = RWCollection<MergedInput<Out, V, Grp, '_grp', EE> | Strict<Grp, V, '_grp', EE>, Out>;
|
|
17
|
+
export 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: GroupCollection<Grp, V, 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">;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { O, RORec, Rec } from '../../../../types';
|
|
2
|
+
import { type ExprsExact } from '../../../expression/concat';
|
|
3
|
+
import type { Delta, Expr, RawStages } from '../../../types';
|
|
4
|
+
import type { DeltaAccumulators } from '../../../types/accumulator';
|
|
5
|
+
export type WithItem<V, Grp> = Rec<'_id', Grp> & Rec<'item', O<V>>;
|
|
6
|
+
export declare const subGroup: <T extends O, Grp, V extends O, GID extends string>(id: Expr<Grp, T>, args: DeltaAccumulators<T, V>, addGrp: <D extends Rec<"_id", Grp>>(src: ExprsExact<V, D>) => ExprsExact<RORec<GID, Grp> & V, D>) => RawStages<unknown, Delta<T>, Rec<GID, Grp> & V>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AsLiteral, ID, O, Rec, Replace, WriteonlyCollection, notArr } from '../../../../types';
|
|
2
|
+
import { type ExprsExact } from '../../../expression/concat';
|
|
3
|
+
import type { Model, RawStages, TS } from '../../../types';
|
|
4
|
+
import type { DeltaAccumulators } from '../../../types/accumulator';
|
|
5
|
+
import { type MergeInto } from '../../out';
|
|
6
|
+
type GI<GG> = Exclude<GG, keyof TS>;
|
|
7
|
+
export type IdAndTsKeys = keyof (TS & ID);
|
|
8
|
+
type V<VV, GG extends string> = Omit<VV, IdAndTsKeys | GI<GG>>;
|
|
9
|
+
export type Prepare<Grp, GG extends string> = TS & ID & Rec<GI<GG>, Grp>;
|
|
10
|
+
type Par<T> = {
|
|
11
|
+
[P in keyof T]?: T[P] | null;
|
|
12
|
+
};
|
|
13
|
+
export type Loose<Grp, VV, GG extends string> = Prepare<Grp, GG> & Par<V<VV, GG>>;
|
|
14
|
+
export type Strict<Grp, VV, GG extends string, EE> = Prepare<Grp, GG> & V<VV, GG> & Omit<EE, IdAndTsKeys | GI<GG> | keyof V<VV, GG>>;
|
|
15
|
+
export type V_Grp<VV, GG extends string, Grp> = Rec<GI<GG>, Grp> & V<VV, GG>;
|
|
16
|
+
export type Extra<EE, VV, GG extends string> = Omit<EE, IdAndTsKeys | GI<GG> | keyof V<VV, GG>>;
|
|
17
|
+
type OrReplace<T, V> = T | Replace<T, V>;
|
|
18
|
+
export type MergedInput<Out, VV, Grp, GG extends string, EE> = OrReplace<Replace<Replace<Out, V<VV, GG>>, Extra<EE, VV, GG>> & Model, TS & ID & V_Grp<VV, GG, Grp> & Extra<EE, VV, GG>>;
|
|
19
|
+
export declare const subMerge: <T extends O, Grp extends notArr, VV extends O, GG extends string, EE = {}, Out extends Loose<Grp, VV, GG> = Loose<Grp, VV, GG>>(args: DeltaAccumulators<T, V<VV, GG>>, out: MergeInto<Strict<Grp, VV, GG, EE>, Out, WriteonlyCollection<MergedInput<Out, VV, Grp, GG, EE>>>, gid: AsLiteral<GI<GG>>, extra: ExprsExact<Extra<EE, VV, GG>, V_Grp<VV, GG, Grp>>, idPrefix: string, first: boolean) => RawStages<unknown, V_Grp<VV, GG, Grp>, "out">;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { emptyDelta } from './prefix';
|
|
2
|
+
export * from './group';
|
|
3
|
+
export * from './lookup';
|
|
4
|
+
export * from './match';
|
|
5
|
+
export * from './set';
|
|
6
|
+
export * from './unwind';
|
|
7
|
+
export * from './$merge';
|
|
8
|
+
export * from './$upsert';
|
|
9
|
+
export * from './out';
|
|
10
|
+
export { $group_ } from './mongo-stages';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Arr, AsLiteral, ID, N, O, Rec, doc, rawItem } from '../../../types';
|
|
2
|
+
import { Field } from '../../field';
|
|
3
|
+
import type { BA, Before, Delta, RawStages, TStages, UBefore } from '../../types';
|
|
4
|
+
import { type JoinId } from '../unwind';
|
|
5
|
+
type s = string;
|
|
6
|
+
type Both<K1 extends s, LE, KK2 extends s, RE, N1 extends null = never, N2 extends null = never> = Delta<Rec<K1, LE | N1> & Rec<Exclude<KK2, BA | K1>, RE | N2> & ID>;
|
|
7
|
+
export declare const $lookupDelta: <LQ extends O, LE extends LQ & doc, RQ extends O, RE extends RQ & doc, BRB extends UBefore<RQ>, RS extends UBefore<RQ>, S extends rawItem, K1 extends s, KK2 extends s, N1 extends null = never, N2 extends null = never>({ field1, field2 }: {
|
|
8
|
+
field1: Field<LQ, S | N | Arr<S>>;
|
|
9
|
+
field2: Field<RQ, S | N | Arr<S>>;
|
|
10
|
+
}, { coll, exec, input }: TStages<RS, UBefore<RQ>, BRB, Before<RE>>, k1: AsLiteral<K1>, k2: AsLiteral<Exclude<KK2, BA | K1>>, k: JoinId<K1, Exclude<KK2, BA | K1>>, includeNull1?: N1, includeNull2?: N2) => RawStages<unknown, Delta<LE>, Both<K1, LE, KK2, RE, N1, N2>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { App, Arr, AsLiteral, HKT, ID, O, Rec, rawItem } from '../../../types';
|
|
2
|
+
import { type Field } from '../../field';
|
|
3
|
+
import type { Before, RawStages, TStages, UBefore } from '../../types';
|
|
4
|
+
import { type JoinId } from '../unwind';
|
|
5
|
+
type s = string;
|
|
6
|
+
export declare const $lookupRaw: <LQ extends O, LE extends LQ & ID, RQ extends O, RE extends RQ & ID, BRB extends Before<RQ>, RS extends UBefore<RQ>, S extends rawItem, As extends s, Null extends null = never>({ field1, field2 }: {
|
|
7
|
+
field1: Field<LQ, S | Arr<S>>;
|
|
8
|
+
field2: Field<RQ, S | Arr<S>>;
|
|
9
|
+
}, { coll, exec, input }: TStages<RS, Before<RQ>, BRB, Before<RE>>, k2: AsLiteral<As>, k: JoinId<"left", "right">, includeNull?: Null) => <F extends HKT<O, O>>(f: <T extends O>() => Field<App<F, T>, T>) => RawStages<App<F, LQ>, App<F, LE>, App<F, LE & Rec<As, RE | Null> & ID>>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type AsLiteral, type O, type RORec, type doc, type notArr, type Arr, type N } from '../../../types';
|
|
2
|
+
import { type Field } from '../../field';
|
|
3
|
+
import type { SnapshotStream, SnapshotStreamExecutionResult } from '../../types/stream';
|
|
4
|
+
type Params<As extends string, LQ extends O, RQ extends O, RE extends RQ, S extends notArr> = {
|
|
5
|
+
from: SnapshotStreamExecutionResult<RQ, RE>;
|
|
6
|
+
as: AsLiteral<As>;
|
|
7
|
+
} & ({
|
|
8
|
+
to: 'one';
|
|
9
|
+
localField: Field<LQ, string | N>;
|
|
10
|
+
foreignField?: never;
|
|
11
|
+
middle?: never;
|
|
12
|
+
} | {
|
|
13
|
+
to: 'many';
|
|
14
|
+
middle: string;
|
|
15
|
+
localField: Field<LQ, S | Arr<S>>;
|
|
16
|
+
foreignField: Field<RQ, S | Arr<S>>;
|
|
17
|
+
});
|
|
18
|
+
export declare const $lookup: <As extends string, LQ extends doc, RQ extends doc, RE extends RQ & doc, S extends notArr>(p: Params<As, LQ, RQ, RE, S>) => <LE extends LQ>(l: SnapshotStream<LQ, LE>) => SnapshotStream<LQ, LE & RORec<As, RE>>;
|
|
19
|
+
export declare const $outerLookup: <As extends string, LQ extends doc, RQ extends doc, RE extends RQ & doc, S extends notArr>(p: Params<As, LQ, RQ, RE, S>) => <LE extends LQ>(l: SnapshotStream<LQ, LE>) => SnapshotStream<LQ, LE & RORec<As, RE | null>>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { doc } from '../../../types';
|
|
2
|
+
import type { Delta, Expr, RawStages } from '../../types';
|
|
3
|
+
export declare const $matchDelta: <T extends doc>(query: Expr<boolean, T>) => RawStages<unknown, Delta<T>, Delta<T>, unknown, number>;
|
|
4
|
+
export declare const matchDelta: <D>() => RawStages<unknown, Delta<D | null>, Delta<D>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Arr, O, Rec } from '../../types';
|
|
2
|
+
import type { Accumulators, Expr, LookupArgs, Query, RawStages } from '../types';
|
|
3
|
+
import type { Updater } from '../update/updater';
|
|
4
|
+
export * from './raws';
|
|
5
|
+
type s = string;
|
|
6
|
+
export declare const $match_: <T extends O, C = unknown>(query?: Query<T, C>) => RawStages<O<T>, T, T, C>;
|
|
7
|
+
export declare const $set_: <Q, T extends Q & O, V extends Q & O, C = unknown>(updater: Updater<T, T, V, C>) => RawStages<O<Q>, T, V, C, 1>;
|
|
8
|
+
export declare const $replaceWith_: <T extends O, V extends O, C = unknown>(expr: Expr<V, T, C>) => RawStages<O, T, V, C, 1>;
|
|
9
|
+
export declare const $unwind_: <T extends O, K extends s, U, Null extends null = never>(k: K, includeNull?: Null) => RawStages<O<T>, T & Rec<K, Arr<U>>, T & Rec<K, Null | U>>;
|
|
10
|
+
export declare const $group_: <V extends O>() => <ID, T extends O, C = unknown>(id: Expr<ID, T, C>, args: Accumulators<T, V, C>) => RawStages<O, T, Rec<"_id", ID> & V, C, 1>;
|
|
11
|
+
export declare const $documents_: <T extends O, C>(docs: Expr<Arr<T>, unknown, C>) => RawStages<unknown, null, T, C, 1>;
|
|
12
|
+
export declare const $project_: <T extends O, K extends import("../..").StrKey<T>>(projection: import("../utils").ExactKeys<K>) => RawStages<T, T, T, unknown, 1>;
|
|
13
|
+
export declare const $simpleLookup_: <T extends O, U extends O, R, K extends s, Ctx, C = unknown, S = string>(args: LookupArgs<T, U, R, K, Ctx, C, S>) => RawStages<O<T>, T, T & Rec<K, Arr<U>>, C, 1>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { O, RWCollection, ReadonlyCollection, Replace, jsonItem } from '../../types';
|
|
2
|
+
import type { ExprsExact } from '../expression/concat';
|
|
3
|
+
import { type Field } from '../field';
|
|
4
|
+
import type { RawStages } from '../types';
|
|
5
|
+
export type MergeInto<T extends O, Out extends O, E = unknown> = {
|
|
6
|
+
whenNotMatched: 'insert';
|
|
7
|
+
into: RWCollection<T, Out> & E;
|
|
8
|
+
} | {
|
|
9
|
+
whenNotMatched: 'discard' | 'fail';
|
|
10
|
+
into: ReadonlyCollection<Out> & E;
|
|
11
|
+
};
|
|
12
|
+
export type MergeArgs<T extends O, Out extends O, Ctx, In extends O> = {
|
|
13
|
+
on: Field<T, jsonItem> & Field<Out, jsonItem>;
|
|
14
|
+
} & MergeInto<T, Out> & (({
|
|
15
|
+
stages?: never;
|
|
16
|
+
} & ({
|
|
17
|
+
whenMatched: 'keepExisting' | 'fail';
|
|
18
|
+
} | {
|
|
19
|
+
whenMatched: 'replace';
|
|
20
|
+
into: RWCollection<T, Out>;
|
|
21
|
+
} | {
|
|
22
|
+
whenMatched: 'merge';
|
|
23
|
+
into: RWCollection<Replace<Out, T>, Out>;
|
|
24
|
+
})) | {
|
|
25
|
+
stages: true;
|
|
26
|
+
into: RWCollection<In, Out>;
|
|
27
|
+
whenMatched: RawStages<unknown, Out, In, {
|
|
28
|
+
new: T;
|
|
29
|
+
}>;
|
|
30
|
+
} | {
|
|
31
|
+
stages: 'ctx';
|
|
32
|
+
vars: ExprsExact<Ctx, T>;
|
|
33
|
+
into: RWCollection<In, Out>;
|
|
34
|
+
whenMatched: RawStages<unknown, Out, In, Ctx>;
|
|
35
|
+
});
|
|
36
|
+
export declare const $merge_: <T extends O, Out extends O = T, Ctx = unknown, In extends O = Out>({ into, on, whenNotMatched, ...notMatched }: MergeArgs<T, Out, Ctx, In>) => RawStages<unknown, T, "out", unknown, number>;
|
|
37
|
+
export declare const $merge2: <T extends O, Out extends O = T, Ctx = unknown, In extends O = Out>(args: MergeArgs<T, Out, Ctx, In>) => RawStages<unknown, T, "out", unknown, number>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { App, HKT, O2, O3, O, RawObj } from '../../types';
|
|
2
|
+
import type { Delta, DeltaStages, FRawStages, RawStages, Stream, TStages } from '../types';
|
|
3
|
+
import type { Equal } from '../utils/guard';
|
|
4
|
+
type n = number;
|
|
5
|
+
export declare const asStages: <Q, T extends Q, V extends Q, C = unknown, M extends n = number>(x: readonly RawObj[]) => RawStages<Q, T, V, C, M>;
|
|
6
|
+
export declare const same: <T extends Dom, V extends Dom, F extends HKT<Dom, Q>, Dom = unknown, Q = unknown, C = unknown, M extends n = number>(_: Equal<Dom, T, V>) => RawStages<Q, App<F, T>, App<F, V>, C, M>;
|
|
7
|
+
export declare const concatStages: <Q, T extends Q, V extends Q, W extends Q, C, M extends n = number>(part1: RawStages<Q, T, V, C, M>, part2: RawStages<Q, V, W, C, M>) => RawStages<Q, T, W, C, M>;
|
|
8
|
+
export declare const concatFStages: <Q, T extends Q & O, V extends Q & O, W extends Q & O, C, M extends n = number>(part1: FRawStages<Q, T, V, C, M>, part2: FRawStages<Q, V, W, C, M>) => FRawStages<Q, T, W, C, M>;
|
|
9
|
+
export declare const concatDelta: <Q extends O, T extends Q, V extends Q, W extends Q>(part1: DeltaStages<Q, T, V>, part2: DeltaStages<Q, V, W>) => DeltaStages<Q, T, W>;
|
|
10
|
+
export type Concat<out Q, in T extends Q, out V extends Q, in out C, in out M extends n = n> = {
|
|
11
|
+
with: <Q2, W extends Q2>(extra: RawStages<Q | Q2, V, W, C, M>) => Concat<Q | Q2, T, W, C, M>;
|
|
12
|
+
stages: RawStages<Q, T, V, C, M>;
|
|
13
|
+
};
|
|
14
|
+
type FConcat<out Q, in T extends Q & O, out V extends Q & O, in out C, in out M extends n = n> = {
|
|
15
|
+
with: <Q2, W extends Q2 & O>(extra: FRawStages<Q | Q2, V, W, C, M>) => FConcat<Q | Q2, T, W, C, M>;
|
|
16
|
+
stages: FRawStages<Q, T, V, C, M>;
|
|
17
|
+
};
|
|
18
|
+
export type DeltaPipe<Q extends O, T extends Q, F extends HKT<O2>, G extends HKT<O3>> = {
|
|
19
|
+
with: <Q2 extends O, V extends Q2>(map: (a: Stream<Q, T, F, G>) => Stream<Q | Q2, V, F, G>) => DeltaPipe<Q | Q2, V, F, G>;
|
|
20
|
+
then: <Q2 extends O, V extends Q2>(next: App<G, [Q2 | T, T, V]>) => DeltaPipe<Q | Q2, V, F, G>;
|
|
21
|
+
get: () => App<F, [Q, T]>;
|
|
22
|
+
};
|
|
23
|
+
export declare const pipe: <Q extends O, S extends Q, T extends Q, F extends HKT<O2>, G extends HKT<O3>>(stream: Stream<Q, S, F, G>, s: App<G, [Q, S, T]>, concat: <Q_1 extends O, T_1 extends Q_1, V extends Q_1, W extends Q_1>(part1: App<G, [Q_1, T_1, V]>, part2: App<G, [Q_1, V, W]>) => App<G, [Q_1, T_1, W]>, empty: <T_2 extends Q>() => App<G, [Q, T_2, T_2]>) => DeltaPipe<Q, T, F, G>;
|
|
24
|
+
type Link = <T, C = unknown, M extends n = n>() => Concat<T, T, T, C, M>;
|
|
25
|
+
type FLink = <T extends O, C = unknown, M extends n = n>() => FConcat<T, T, T, C, M>;
|
|
26
|
+
export declare const link: Link;
|
|
27
|
+
export declare const flink: FLink;
|
|
28
|
+
export declare const emptyDelta: <T extends O>() => {
|
|
29
|
+
delta: RawStages<Delta<T>, Delta<T>, Delta<T>, unknown, number>;
|
|
30
|
+
raw: <F extends HKT<O>>() => RawStages<App<F, T>, App<F, T>, App<F, T>, unknown, number>;
|
|
31
|
+
};
|
|
32
|
+
export declare const concatTStages: <S, Q, B extends Q, T extends Q, V extends Q>({ coll, exec, input }: TStages<S, Q, B, T>, stages: RawStages<Q, T, V>) => TStages<S, Q, B, V>;
|
|
33
|
+
export {};
|