@omegup/msync 0.1.37 → 0.1.39
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 +23 -10
- package/index.esm.js +18 -17
- package/index.js +18 -17
- package/lib/accumulators/index.d.ts +10 -0
- package/lib/aggregate/$merge.d.ts +37 -0
- package/lib/aggregate/$upsert.d.ts +19 -0
- package/lib/aggregate/group/$group-merge.d.ts +12 -0
- package/lib/aggregate/group/index.d.ts +2 -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 +9 -0
- package/lib/aggregate/lookup/$lookup-delta.d.ts +10 -0
- package/lib/aggregate/lookup/$lookup-raw.d.ts +9 -0
- package/lib/aggregate/lookup/index.d.ts +12 -0
- package/lib/aggregate/match/$match-delta.d.ts +3 -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 +6 -0
- package/lib/aggregate/set/index.d.ts +1 -0
- package/lib/aggregate/unwind/$unwind-delta.d.ts +5 -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 +32 -0
- package/lib/expression/array.d.ts +30 -0
- package/lib/expression/concat.d.ts +36 -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 +23 -0
- package/lib/expression/range.d.ts +11 -0
- package/lib/expression/val.d.ts +25 -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 +30 -0
- package/lib/types/aggregate.d.ts +9 -0
- package/lib/types/expr.d.ts +27 -0
- package/lib/types/extern.d.ts +3 -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 +71 -0
- package/lib/update/index.d.ts +1 -0
- package/lib/update/updater.d.ts +19 -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 +19 -0
- package/lib/utils/index.d.ts +4 -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 +3 -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
|
@@ -120,7 +120,7 @@ type LinStages<out Q, in S extends Q, out R extends Q, in C = unknown> = {
|
|
|
120
120
|
};
|
|
121
121
|
type TStages<in out S, out Q, in out B extends Q, out R extends Q, M extends number = number> = {
|
|
122
122
|
coll: ReadonlyCollection<S>;
|
|
123
|
-
input: RawStages<unknown, S, B, unknown, M>;
|
|
123
|
+
input: RawStages<unknown, S, S & B, unknown, M>;
|
|
124
124
|
exec: RawStages<Q, B, R, unknown, M>;
|
|
125
125
|
};
|
|
126
126
|
type Stages<out Q, out R extends Q, out SDom> = <E>(consume: <S extends SDom, B extends Q>(value: TStages<S, Q, B, R>) => E) => E;
|
|
@@ -412,8 +412,8 @@ declare const $groupId: <T extends O, V extends O, EE = {}, Out extends Loose<st
|
|
|
412
412
|
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<MergedInput<Out, V, Grp, "_grp", EE> | 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">;
|
|
413
413
|
|
|
414
414
|
type Params<As extends string, LQ extends O, RQ extends O, RE extends RQ, S extends notArr> = {
|
|
415
|
-
localField: Field<LQ, S
|
|
416
|
-
foreignField: Field<RQ, S
|
|
415
|
+
localField: Field<LQ, S | Arr<S>>;
|
|
416
|
+
foreignField: Field<RQ, S | Arr<S>>;
|
|
417
417
|
from: SnapshotStreamExecutionResult<RQ, RE>;
|
|
418
418
|
as: AsLiteral<As>;
|
|
419
419
|
};
|
|
@@ -454,7 +454,15 @@ type ND$1 = {
|
|
|
454
454
|
readonly deletedAt?: null;
|
|
455
455
|
};
|
|
456
456
|
type SafeE$1<E> = Omit<E, `$${string}` | keyof ID>;
|
|
457
|
-
|
|
457
|
+
type Args<P, Out> = [added: Expr<P, unknown, {
|
|
458
|
+
new: P;
|
|
459
|
+
}>, old: Expr<Out, Out>];
|
|
460
|
+
type Result<P> = Expr<P, unknown, {
|
|
461
|
+
new: P;
|
|
462
|
+
}>;
|
|
463
|
+
type Update$1<P, Out> = (...args: Args<P, Out>) => Result<P>;
|
|
464
|
+
type UpdateF<P, Out> = <K extends keyof IsDeleted>(...args: Args<Replace<P, RORec<K, Timestamp>>, Out>) => Result<Replace<P, RORec<K, Timestamp>>>;
|
|
465
|
+
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>) => RawStages<O, Out, Out | Replace<Out, P>, RORec<"new", Replace<P, RORec<K, Timestamp>>>>;
|
|
458
466
|
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>>;
|
|
459
467
|
type MergeCollection<V extends O, Out extends Model> = {
|
|
460
468
|
coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
|
|
@@ -463,18 +471,23 @@ type MergeCollection<V extends O, Out extends Model> = {
|
|
|
463
471
|
coll: RWCollection<Out | Replace<Out, Patch<V>>, Out>;
|
|
464
472
|
whenNotMatched: 'fail';
|
|
465
473
|
};
|
|
466
|
-
|
|
467
|
-
declare const $
|
|
468
|
-
declare const $
|
|
469
|
-
declare const $
|
|
470
|
-
declare const $
|
|
474
|
+
type MergeUpdate<V, Out> = UpdateF<((OPick<V, Allowed$2<StrKey<V>>> & ID) | (Rec<Allowed$2<StrKey<V>>, N> & ID)) & TS, Out>;
|
|
475
|
+
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$1<EEE>, keyof (ND$1 & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<OutInputE<SourcePart, E>, "out">;
|
|
476
|
+
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$1<EEE>, keyof (ND$1 & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Source, "out">;
|
|
477
|
+
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">;
|
|
478
|
+
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$1<EEE>, keyof (ND$1 & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Delta<SourcePart>, "out">;
|
|
479
|
+
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">;
|
|
471
480
|
|
|
472
481
|
type ND = {
|
|
473
482
|
readonly deletedAt?: null;
|
|
474
483
|
};
|
|
475
484
|
type SafeE<E> = Omit<E, `$${string}` | keyof ID>;
|
|
476
485
|
type Merge<T extends doc, E> = Omit<SafeE<E>, keyof (ND & TS)> & ((T & ND & TS) | Del);
|
|
477
|
-
|
|
486
|
+
type ExprP<P> = Expr<P, unknown, {
|
|
487
|
+
new: P;
|
|
488
|
+
}>;
|
|
489
|
+
type Update<P, Out> = (added: ExprP<P>, old: Expr<Out, Out>) => ExprP<P>;
|
|
490
|
+
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">;
|
|
478
491
|
declare const $simpleInsert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<T, "out">;
|
|
479
492
|
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">;
|
|
480
493
|
declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
|
package/index.esm.js
CHANGED
|
@@ -514,6 +514,7 @@ const $group1 = (id, args) => (f) => asStages([
|
|
|
514
514
|
const rawVars = (vars, f) => mapExactToObject(vars, v => v.raw(f).get());
|
|
515
515
|
const $simpleLookup1 = (args) => f => {
|
|
516
516
|
const { coll, k, vars, fields, ...etc } = args;
|
|
517
|
+
const letVars = rawVars(vars, f());
|
|
517
518
|
return asStages([
|
|
518
519
|
{
|
|
519
520
|
$lookup: {
|
|
@@ -523,7 +524,7 @@ const $simpleLookup1 = (args) => f => {
|
|
|
523
524
|
foreignField: root().with(fields.foreign).str(),
|
|
524
525
|
}),
|
|
525
526
|
as: f().of(k).str(),
|
|
526
|
-
let:
|
|
527
|
+
...(Object.keys(letVars).length > 0 && { let: letVars }),
|
|
527
528
|
...etc,
|
|
528
529
|
},
|
|
529
530
|
},
|
|
@@ -844,13 +845,13 @@ const $merge_ = ({ into, on, whenNotMatched, ...notMatched }) => asStages([
|
|
|
844
845
|
]);
|
|
845
846
|
const $merge2 = (args) => $merge_(args);
|
|
846
847
|
|
|
847
|
-
const getWhenMatchedForMerge = (whenNotMatched) => {
|
|
848
|
+
const getWhenMatchedForMerge = (whenNotMatched, update) => {
|
|
848
849
|
const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
|
|
849
850
|
const newOrOld = whenNotMatched ===
|
|
850
851
|
'insert'
|
|
851
852
|
? ctx()('new')
|
|
852
853
|
: root();
|
|
853
|
-
const merged = mergeObjects(root().expr(), ctx()('new').expr(), field({
|
|
854
|
+
const merged = mergeObjects(root().expr(), update(ctx()('new').expr(), root().expr()), field({
|
|
854
855
|
deletedAt: ['deletedAt', orNull(newOrOld.of('deletedAt').expr())],
|
|
855
856
|
}));
|
|
856
857
|
return link()
|
|
@@ -869,7 +870,7 @@ const getWhenMatched = (whenNotMatched) => {
|
|
|
869
870
|
const same = eq(preMergeOld)(root().of('merged').expr());
|
|
870
871
|
return link().with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
|
|
871
872
|
};
|
|
872
|
-
const $mergeX = (out, keys, f, map, ext) => {
|
|
873
|
+
const $mergeX = (out, keys, f, map, ext, update) => {
|
|
873
874
|
const patch = mapExact(keys, v => sub(v, f));
|
|
874
875
|
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
875
876
|
const setDeleted = out.whenNotMatched === 'discard';
|
|
@@ -887,14 +888,14 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
887
888
|
on: root().of('_id'),
|
|
888
889
|
whenNotMatched: 'insert',
|
|
889
890
|
stages: true,
|
|
890
|
-
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
891
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
|
|
891
892
|
})).stages
|
|
892
893
|
: link().with($merge_({
|
|
893
894
|
into: out.coll,
|
|
894
895
|
on: root().of('_id'),
|
|
895
896
|
whenNotMatched: 'fail',
|
|
896
897
|
stages: true,
|
|
897
|
-
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
898
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
|
|
898
899
|
})).stages;
|
|
899
900
|
const teardown = (coll) => ({
|
|
900
901
|
collection: coll,
|
|
@@ -911,22 +912,22 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
911
912
|
return {
|
|
912
913
|
raw: (first) => link().with($replaceWith_(replacer)).with(sss)
|
|
913
914
|
.stages,
|
|
914
|
-
teardown: c =>
|
|
915
|
+
teardown: c => c(teardown(out.coll)),
|
|
915
916
|
};
|
|
916
917
|
};
|
|
917
|
-
const $mergeId = () => (out, keys, id, ext) => {
|
|
918
|
+
const $mergeId = () => (out, keys, id, ext, update = x => x) => {
|
|
918
919
|
const omRORec = omitRORec();
|
|
919
920
|
return $mergeX(out, keys, root().of('after'), or => {
|
|
920
921
|
return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
|
|
921
922
|
_id: ['_id', id],
|
|
922
923
|
touchedAt: ['touchedAt', current],
|
|
923
924
|
}))), or);
|
|
924
|
-
}, ext);
|
|
925
|
+
}, ext, update);
|
|
925
926
|
};
|
|
926
|
-
const $simpleMergePart = () => (out, keys, ext) => $mergeX(out, keys, root(), id$1, ext);
|
|
927
|
-
const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {});
|
|
928
|
-
const $mergePart = () => (out, keys, ext) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext);
|
|
929
|
-
const $merge = () => (out, keys) => $mergePart()(out, keys, {});
|
|
927
|
+
const $simpleMergePart = () => (out, keys, ext, update = x => x) => $mergeX(out, keys, root(), id$1, ext, update);
|
|
928
|
+
const $simpleMerge = () => (out, keys, whenNotMatched = 'fail', update = x => x) => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {}, update);
|
|
929
|
+
const $mergePart = () => (out, keys, ext, update = x => x) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext, update);
|
|
930
|
+
const $merge = () => (out, keys, update = x => x) => $mergePart()(out, keys, {}, update);
|
|
930
931
|
const assertNotNull$1 = (expr) => expr;
|
|
931
932
|
|
|
932
933
|
const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
@@ -1271,10 +1272,10 @@ const $lookupRaw = ({ field1, field2 }, { coll, exec, input }, k2, k, includeNul
|
|
|
1271
1272
|
.with($simpleLookup1({
|
|
1272
1273
|
coll,
|
|
1273
1274
|
k: k2,
|
|
1274
|
-
|
|
1275
|
+
fields: { local: field1, foreign: root().of('before').with(field2) },
|
|
1276
|
+
vars: {},
|
|
1275
1277
|
pipeline: link()
|
|
1276
1278
|
.with(input)
|
|
1277
|
-
.with($match_($expr(eq(ctx()('local').expr())(root().of('before').with(field2).expr()))))
|
|
1278
1279
|
.with(exec)
|
|
1279
1280
|
.with($replaceWith_(root().of('before').expr())).stages,
|
|
1280
1281
|
})(f))
|
|
@@ -1562,7 +1563,7 @@ const $replaceWith = (expr) => ({
|
|
|
1562
1563
|
lin: $replaceWith_(expr),
|
|
1563
1564
|
});
|
|
1564
1565
|
|
|
1565
|
-
const $insertX = (out, expr, map, ext, extExpr) => {
|
|
1566
|
+
const $insertX = (out, expr, map, ext, extExpr, update = x => x) => {
|
|
1566
1567
|
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
1567
1568
|
return {
|
|
1568
1569
|
teardown: c => c({
|
|
@@ -1581,7 +1582,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
|
|
|
1581
1582
|
into: out,
|
|
1582
1583
|
on: root().of('_id'),
|
|
1583
1584
|
stages: true,
|
|
1584
|
-
whenMatched: getWhenMatchedForMerge('insert'),
|
|
1585
|
+
whenMatched: getWhenMatchedForMerge('insert', update),
|
|
1585
1586
|
whenNotMatched: 'insert',
|
|
1586
1587
|
})).stages;
|
|
1587
1588
|
},
|
package/index.js
CHANGED
|
@@ -516,6 +516,7 @@ const $group1 = (id, args) => (f) => asStages([
|
|
|
516
516
|
const rawVars = (vars, f) => mapExactToObject(vars, v => v.raw(f).get());
|
|
517
517
|
const $simpleLookup1 = (args) => f => {
|
|
518
518
|
const { coll, k, vars, fields, ...etc } = args;
|
|
519
|
+
const letVars = rawVars(vars, f());
|
|
519
520
|
return asStages([
|
|
520
521
|
{
|
|
521
522
|
$lookup: {
|
|
@@ -525,7 +526,7 @@ const $simpleLookup1 = (args) => f => {
|
|
|
525
526
|
foreignField: root().with(fields.foreign).str(),
|
|
526
527
|
}),
|
|
527
528
|
as: f().of(k).str(),
|
|
528
|
-
let:
|
|
529
|
+
...(Object.keys(letVars).length > 0 && { let: letVars }),
|
|
529
530
|
...etc,
|
|
530
531
|
},
|
|
531
532
|
},
|
|
@@ -846,13 +847,13 @@ const $merge_ = ({ into, on, whenNotMatched, ...notMatched }) => asStages([
|
|
|
846
847
|
]);
|
|
847
848
|
const $merge2 = (args) => $merge_(args);
|
|
848
849
|
|
|
849
|
-
const getWhenMatchedForMerge = (whenNotMatched) => {
|
|
850
|
+
const getWhenMatchedForMerge = (whenNotMatched, update) => {
|
|
850
851
|
const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
|
|
851
852
|
const newOrOld = whenNotMatched ===
|
|
852
853
|
'insert'
|
|
853
854
|
? ctx()('new')
|
|
854
855
|
: root();
|
|
855
|
-
const merged = mergeObjects(root().expr(), ctx()('new').expr(), field({
|
|
856
|
+
const merged = mergeObjects(root().expr(), update(ctx()('new').expr(), root().expr()), field({
|
|
856
857
|
deletedAt: ['deletedAt', orNull(newOrOld.of('deletedAt').expr())],
|
|
857
858
|
}));
|
|
858
859
|
return link()
|
|
@@ -871,7 +872,7 @@ const getWhenMatched = (whenNotMatched) => {
|
|
|
871
872
|
const same = eq(preMergeOld)(root().of('merged').expr());
|
|
872
873
|
return link().with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
|
|
873
874
|
};
|
|
874
|
-
const $mergeX = (out, keys, f, map, ext) => {
|
|
875
|
+
const $mergeX = (out, keys, f, map, ext, update) => {
|
|
875
876
|
const patch = mapExact(keys, v => sub(v, f));
|
|
876
877
|
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
877
878
|
const setDeleted = out.whenNotMatched === 'discard';
|
|
@@ -889,14 +890,14 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
889
890
|
on: root().of('_id'),
|
|
890
891
|
whenNotMatched: 'insert',
|
|
891
892
|
stages: true,
|
|
892
|
-
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
893
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
|
|
893
894
|
})).stages
|
|
894
895
|
: link().with($merge_({
|
|
895
896
|
into: out.coll,
|
|
896
897
|
on: root().of('_id'),
|
|
897
898
|
whenNotMatched: 'fail',
|
|
898
899
|
stages: true,
|
|
899
|
-
whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
|
|
900
|
+
whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
|
|
900
901
|
})).stages;
|
|
901
902
|
const teardown = (coll) => ({
|
|
902
903
|
collection: coll,
|
|
@@ -913,22 +914,22 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
913
914
|
return {
|
|
914
915
|
raw: (first) => link().with($replaceWith_(replacer)).with(sss)
|
|
915
916
|
.stages,
|
|
916
|
-
teardown: c =>
|
|
917
|
+
teardown: c => c(teardown(out.coll)),
|
|
917
918
|
};
|
|
918
919
|
};
|
|
919
|
-
const $mergeId = () => (out, keys, id, ext) => {
|
|
920
|
+
const $mergeId = () => (out, keys, id, ext, update = x => x) => {
|
|
920
921
|
const omRORec = omitRORec();
|
|
921
922
|
return $mergeX(out, keys, root().of('after'), or => {
|
|
922
923
|
return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
|
|
923
924
|
_id: ['_id', id],
|
|
924
925
|
touchedAt: ['touchedAt', current],
|
|
925
926
|
}))), or);
|
|
926
|
-
}, ext);
|
|
927
|
+
}, ext, update);
|
|
927
928
|
};
|
|
928
|
-
const $simpleMergePart = () => (out, keys, ext) => $mergeX(out, keys, root(), id$1, ext);
|
|
929
|
-
const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {});
|
|
930
|
-
const $mergePart = () => (out, keys, ext) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext);
|
|
931
|
-
const $merge = () => (out, keys) => $mergePart()(out, keys, {});
|
|
929
|
+
const $simpleMergePart = () => (out, keys, ext, update = x => x) => $mergeX(out, keys, root(), id$1, ext, update);
|
|
930
|
+
const $simpleMerge = () => (out, keys, whenNotMatched = 'fail', update = x => x) => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {}, update);
|
|
931
|
+
const $mergePart = () => (out, keys, ext, update = x => x) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext, update);
|
|
932
|
+
const $merge = () => (out, keys, update = x => x) => $mergePart()(out, keys, {}, update);
|
|
932
933
|
const assertNotNull$1 = (expr) => expr;
|
|
933
934
|
|
|
934
935
|
const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
@@ -1273,10 +1274,10 @@ const $lookupRaw = ({ field1, field2 }, { coll, exec, input }, k2, k, includeNul
|
|
|
1273
1274
|
.with($simpleLookup1({
|
|
1274
1275
|
coll,
|
|
1275
1276
|
k: k2,
|
|
1276
|
-
|
|
1277
|
+
fields: { local: field1, foreign: root().of('before').with(field2) },
|
|
1278
|
+
vars: {},
|
|
1277
1279
|
pipeline: link()
|
|
1278
1280
|
.with(input)
|
|
1279
|
-
.with($match_($expr(eq(ctx()('local').expr())(root().of('before').with(field2).expr()))))
|
|
1280
1281
|
.with(exec)
|
|
1281
1282
|
.with($replaceWith_(root().of('before').expr())).stages,
|
|
1282
1283
|
})(f))
|
|
@@ -1564,7 +1565,7 @@ const $replaceWith = (expr) => ({
|
|
|
1564
1565
|
lin: $replaceWith_(expr),
|
|
1565
1566
|
});
|
|
1566
1567
|
|
|
1567
|
-
const $insertX = (out, expr, map, ext, extExpr) => {
|
|
1568
|
+
const $insertX = (out, expr, map, ext, extExpr, update = x => x) => {
|
|
1568
1569
|
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
1569
1570
|
return {
|
|
1570
1571
|
teardown: c => c({
|
|
@@ -1583,7 +1584,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
|
|
|
1583
1584
|
into: out,
|
|
1584
1585
|
on: root().of('_id'),
|
|
1585
1586
|
stages: true,
|
|
1586
|
-
whenMatched: getWhenMatchedForMerge('insert'),
|
|
1587
|
+
whenMatched: getWhenMatchedForMerge('insert', update),
|
|
1587
1588
|
whenNotMatched: 'insert',
|
|
1588
1589
|
})).stages;
|
|
1589
1590
|
},
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AppMap, Arr, N, O, Rec } from '../../types';
|
|
2
|
+
import type { ExprHKT } from '../expression/concat';
|
|
3
|
+
import { type NoRaw } from '../expression/val';
|
|
4
|
+
import type { DeltaAccumulator, Expr, Part } from '../types';
|
|
5
|
+
export declare const $sum: <D extends O, C = unknown>(expr: Expr<number | N, D, C>) => DeltaAccumulator<D, number, C>;
|
|
6
|
+
export declare const $accumulator: <D, T, Ctx, A extends readonly unknown[]>(init: () => NoRaw<T>, accumulateArgs: AppMap<ExprHKT<Part<D>, Ctx>, A>, accumulate: (a: NoRaw<T>, ...args: NoRaw<A>) => NoRaw<T>, merge: (...args: NoRaw<[T | N, T]>) => NoRaw<T>) => DeltaAccumulator<D, T, Ctx>;
|
|
7
|
+
export declare const $countDict: <D extends O, C = unknown>(expr: Expr<string, D, C>) => DeltaAccumulator<D, Rec<string, number>, C>;
|
|
8
|
+
export declare const $pushDict: <D extends O, V, C = unknown>(key: Expr<string, D, C>, value: Expr<V, D, C>) => DeltaAccumulator<D, Rec<string, Rec<"0" | "1", Arr<V>>>, C>;
|
|
9
|
+
export declare const $keys: <D extends O, C = unknown>(expr: Expr<Rec<string, number>, D, C>) => Expr<Arr<string>, D, C>;
|
|
10
|
+
export declare const $entries: <D extends O, V, C = unknown>(expr: Expr<Rec<string, Rec<"1" | "0", Arr<V>>>, D, C>) => Expr<Arr<Rec<"k", string> & Rec<"v", V>>, D, C>;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 getWhenMatchedForMerge: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert", update: Update<Replace<P, RORec<K, Timestamp>>, Out>) => RawStages<O, Out, Out | Replace<Out, P>, RORec<"new", Replace<P, RORec<K, Timestamp>>>>;
|
|
23
|
+
export 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>>;
|
|
24
|
+
type MergeCollection<V extends O, Out extends Model> = {
|
|
25
|
+
coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
|
|
26
|
+
whenNotMatched: 'discard';
|
|
27
|
+
} | {
|
|
28
|
+
coll: RWCollection<Out | Replace<Out, Patch<V>>, Out>;
|
|
29
|
+
whenNotMatched: 'fail';
|
|
30
|
+
};
|
|
31
|
+
type MergeUpdate<V, Out> = UpdateF<((OPick<V, Allowed<StrKey<V>>> & ID) | (Rec<Allowed<StrKey<V>>, N> & ID)) & TS, Out>;
|
|
32
|
+
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">;
|
|
33
|
+
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">;
|
|
34
|
+
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">;
|
|
35
|
+
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">;
|
|
36
|
+
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">;
|
|
37
|
+
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>(out: RWCollection<Merge<T, {}>>) => 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,12 @@
|
|
|
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 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<MergedInput<Out, V, Grp, GG, EE>>>, gid: AsLiteral<GI<GG>>, extra: ExprsExact<Extra<EE, V, GG>, V_Grp<V, GG, Grp>>, idPrefix?: string) => StreamRunnerParam<Delta<T>, "out">;
|
|
10
|
+
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: RWCollection<MergedInput<Out, V, string, "_id", EE>, Out>, extra: ExprsExact<Omit<EE, IdAndTsKeys | keyof Omit<V, IdAndTsKeys>>, doc & Omit<V, IdAndTsKeys>>) => StreamRunnerParam<Delta<T>, "out">;
|
|
11
|
+
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: RWCollection<MergedInput<Out, V, Grp, "_grp", EE> | 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">;
|
|
12
|
+
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
|
+
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
|
+
type s = string;
|
|
5
|
+
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>;
|
|
6
|
+
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 }: {
|
|
7
|
+
field1: Field<LQ, S | N | Arr<S>>;
|
|
8
|
+
field2: Field<RQ, S | N | Arr<S>>;
|
|
9
|
+
}, { coll, exec, input }: TStages<RS, UBefore<RQ>, BRB, Before<RE>>, k1: AsLiteral<K1>, k2: AsLiteral<Exclude<KK2, BA | K1>>, k: ([N1] extends [never] ? K1 : never) | ([N2] extends [never] ? Exclude<KK2, BA | K1> : never) | false, includeNull1?: N1, includeNull2?: N2) => RawStages<unknown, Delta<LE>, Both<K1, LE, KK2, RE, N1, N2>>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { App, Arr, AsLiteral, HKT, ID, O, Rec } from '../../../types';
|
|
2
|
+
import { type Field } from '../../field';
|
|
3
|
+
import type { Before, RawStages, TStages, UBefore } from '../../types';
|
|
4
|
+
type s = string;
|
|
5
|
+
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, As extends s, Null extends null = never>({ field1, field2 }: {
|
|
6
|
+
field1: Field<LQ, S | Arr<S>>;
|
|
7
|
+
field2: Field<RQ, S | Arr<S>>;
|
|
8
|
+
}, { coll, exec, input }: TStages<RS, Before<RQ>, BRB, Before<RE>>, k2: AsLiteral<As>, k: "left", 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> & ID>>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type AsLiteral, type O, type RORec, type doc, type notArr, type Arr } 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
|
+
localField: Field<LQ, S | Arr<S>>;
|
|
6
|
+
foreignField: Field<RQ, S | Arr<S>>;
|
|
7
|
+
from: SnapshotStreamExecutionResult<RQ, RE>;
|
|
8
|
+
as: AsLiteral<As>;
|
|
9
|
+
};
|
|
10
|
+
export declare const $lookup: <As extends string, LQ extends doc, RQ extends O, 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>>;
|
|
11
|
+
export declare const $outerLookup: <As extends string, LQ extends doc, RQ extends O, 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>>;
|
|
12
|
+
export {};
|
|
@@ -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_: <Q, T extends Q & 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 {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { App, Arr, ConstHKT, HKT, O, Rec, StrKey, rawItem } from '../../types';
|
|
2
|
+
import type { ExprsExact } from '../expression/concat';
|
|
3
|
+
import { type Field } from '../field';
|
|
4
|
+
import type { Accumulators, Expr, FRawStages, LookupArgs, Query, RawStages } from '../types';
|
|
5
|
+
import type { Updater } from '../update/updater';
|
|
6
|
+
import { type ExactKeys } from '../utils/map-object';
|
|
7
|
+
type s = string;
|
|
8
|
+
export declare const $match1: <T extends O, C = unknown>(query?: Query<T, C>) => FRawStages<T, T, T, C>;
|
|
9
|
+
export declare const $set1: <Q, T extends Q & O, V extends Q & O, C = unknown>(updater: Updater<T, T, V, C>) => FRawStages<Q, T, V, C, 1>;
|
|
10
|
+
export declare const $project1: <T extends O, K extends StrKey<T>>(projection: ExactKeys<K>) => RawStages<T, T, T, unknown, 1>;
|
|
11
|
+
export declare const $replaceWith1: <T extends O, V extends O, C = unknown>(expr: Expr<V, T, C>) => FRawStages<O, T, V, C, 1>;
|
|
12
|
+
export declare const $unwind1: <T extends O, K extends s, R, Null extends null = never>(k: K, includeNull?: Null) => FRawStages<T, T & Rec<K, Arr<R>>, T & Rec<K, R | Null>>;
|
|
13
|
+
export declare const $group1: <T extends O, ID, V extends O, C>(id: Expr<ID, T, C>, args: Accumulators<T, V, C>) => <F extends HKT<O, O>>(f: <T_1 extends O>() => Field<App<F, T_1>, T_1>) => RawStages<O, App<F, T>, Rec<"_id", ID> & V, C, 1>;
|
|
14
|
+
export declare const $documents1: <Q extends O, T extends Q & O, C>(docs: Expr<Arr<T>, unknown, C>) => <F extends HKT<O, O>>(f: <T_1 extends O>() => Field<App<F, T_1>, T_1>) => RawStages<unknown, null, App<F, T>, C, 1>;
|
|
15
|
+
export declare const rawVars: <T, Ctx, C, V extends O>(vars: ExprsExact<Ctx, T, C>, f: Field<V, T, unknown>) => import("../utils/map-object").ExactPart1<Ctx, ConstHKT<rawItem, unknown>>;
|
|
16
|
+
export declare const $simpleLookup1: <T extends O, U extends O, R, K extends s, Ctx, C = unknown, S = string>(args: LookupArgs<T, U, R, K, Ctx, C, S>) => FRawStages<T, T, T & Rec<K, Arr<U>>, C, 1>;
|
|
17
|
+
export {};
|