@omegup/msync 0.1.7 → 0.1.9

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.
Files changed (92) hide show
  1. package/index.d.ts +33 -23
  2. package/index.esm.js +63 -75
  3. package/index.js +63 -74
  4. package/lib/accumulators/index.d.ts +10 -0
  5. package/lib/aggregate/$merge.d.ts +27 -0
  6. package/lib/aggregate/$upsert.d.ts +15 -0
  7. package/lib/aggregate/group/$group-merge.d.ts +12 -0
  8. package/lib/aggregate/group/index.d.ts +2 -0
  9. package/lib/aggregate/group/utils/sub-group.d.ts +6 -0
  10. package/lib/aggregate/group/utils/sub-merge.d.ts +18 -0
  11. package/lib/aggregate/index.d.ts +9 -0
  12. package/lib/aggregate/lookup/$lookup-delta.d.ts +10 -0
  13. package/lib/aggregate/lookup/$lookup-raw.d.ts +9 -0
  14. package/lib/aggregate/lookup/index.d.ts +12 -0
  15. package/lib/aggregate/match/$match-delta.d.ts +3 -0
  16. package/lib/aggregate/match/$match.d.ts +3 -0
  17. package/lib/aggregate/match/index.d.ts +2 -0
  18. package/lib/aggregate/mongo-stages.d.ts +13 -0
  19. package/lib/aggregate/out.d.ts +37 -0
  20. package/lib/aggregate/prefix.d.ts +33 -0
  21. package/lib/aggregate/raws.d.ts +17 -0
  22. package/lib/aggregate/set/$replace-with-each.d.ts +13 -0
  23. package/lib/aggregate/set/$set-delta.d.ts +5 -0
  24. package/lib/aggregate/set/$set.d.ts +6 -0
  25. package/lib/aggregate/set/index.d.ts +1 -0
  26. package/lib/aggregate/unwind/$unwind-delta.d.ts +5 -0
  27. package/lib/aggregate/unwind/index.d.ts +6 -0
  28. package/lib/boot/boot-simpl.d.ts +14 -0
  29. package/lib/boot/boot-utils.d.ts +26 -0
  30. package/lib/boot/boot.d.ts +16 -0
  31. package/lib/boot/first-stages.d.ts +12 -0
  32. package/lib/boot/index.d.ts +3 -0
  33. package/lib/boot/single.d.ts +11 -0
  34. package/lib/expression/arith.d.ts +32 -0
  35. package/lib/expression/array.d.ts +30 -0
  36. package/lib/expression/concat.d.ts +34 -0
  37. package/lib/expression/date.d.ts +17 -0
  38. package/lib/expression/expr-base.d.ts +5 -0
  39. package/lib/expression/index.d.ts +7 -0
  40. package/lib/expression/logic.d.ts +23 -0
  41. package/lib/expression/range.d.ts +11 -0
  42. package/lib/expression/val.d.ts +25 -0
  43. package/lib/field/field.d.ts +25 -0
  44. package/lib/field/index.d.ts +1 -0
  45. package/lib/machine.d.ts +9 -0
  46. package/lib/predicate/$eq.d.ts +24 -0
  47. package/lib/predicate/$expr.d.ts +3 -0
  48. package/lib/predicate/$in.d.ts +2 -0
  49. package/lib/predicate/index.d.ts +3 -0
  50. package/lib/predicate/utils.d.ts +5 -0
  51. package/lib/query/index.d.ts +1 -0
  52. package/lib/query/logic.d.ts +11 -0
  53. package/lib/stream/aggregate.d.ts +7 -0
  54. package/lib/types/accumulator.d.ts +30 -0
  55. package/lib/types/aggregate.d.ts +9 -0
  56. package/lib/types/expr.d.ts +27 -0
  57. package/lib/types/extern.d.ts +3 -0
  58. package/lib/types/index.d.ts +8 -0
  59. package/lib/types/lookup.d.ts +19 -0
  60. package/lib/types/machine.d.ts +17 -0
  61. package/lib/types/predicate.d.ts +11 -0
  62. package/lib/types/query.d.ts +12 -0
  63. package/lib/types/stream.d.ts +71 -0
  64. package/lib/update/index.d.ts +1 -0
  65. package/lib/update/updater.d.ts +19 -0
  66. package/lib/utils/before.d.ts +3 -0
  67. package/lib/utils/coll.d.ts +5 -0
  68. package/lib/utils/db-indexes.d.ts +4 -0
  69. package/lib/utils/guard.d.ts +19 -0
  70. package/lib/utils/index.d.ts +4 -0
  71. package/lib/utils/json.d.ts +9 -0
  72. package/lib/utils/log.d.ts +1 -0
  73. package/lib/utils/map-object.d.ts +41 -0
  74. package/lib/utils/merge/combiners.d.ts +6 -0
  75. package/lib/utils/merge/index.d.ts +2 -0
  76. package/lib/utils/merge/merge.d.ts +7 -0
  77. package/lib/utils/merge/next-winner.d.ts +3 -0
  78. package/lib/utils/merge/types.d.ts +19 -0
  79. package/lib/utils/merge/utils.d.ts +4 -0
  80. package/lib/utils/tear-down.d.ts +2 -0
  81. package/lib/watch.d.ts +15 -0
  82. package/package.json +1 -1
  83. package/test/mongodb.d.ts +9 -0
  84. package/test/uri.d.ts +1 -0
  85. package/types/class.d.ts +1 -0
  86. package/types/extern.d.ts +3 -0
  87. package/types/global.d.ts +50 -0
  88. package/types/hkt.d.ts +56 -0
  89. package/types/index.d.ts +6 -0
  90. package/types/json.d.ts +54 -0
  91. package/types/mongo.d.ts +24 -0
  92. package/types/view.d.ts +35 -0
package/index.d.ts CHANGED
@@ -106,13 +106,15 @@ type Stream<out Q extends O, in out T extends Q, in out F extends HKT<[O, O]>, i
106
106
  type TS = {
107
107
  readonly touchedAt: Timestamp;
108
108
  };
109
- type DDel = {
109
+ type IsDeleted = {
110
110
  readonly deletedAt: Timestamp;
111
- } & ID & TS;
111
+ };
112
+ type DDel = IsDeleted & ID & TS;
112
113
  type Del = O<DDel>;
113
- type D = O<{
114
+ type DeletedAt = {
114
115
  readonly deletedAt?: Timestamp | null | undefined;
115
- } & ID>;
116
+ };
117
+ type D = O<DeletedAt & ID>;
116
118
  type Model = D & TS;
117
119
  type BA = 'before' | 'after';
118
120
  type PreDelta<T, K extends BA = BA, E = unknown> = Rec<K, T> & E;
@@ -431,7 +433,7 @@ type MergeArgs<T extends O, Out extends O, Ctx, In extends O> = {
431
433
  stages: true;
432
434
  into: RWCollection<In, Out>;
433
435
  whenMatched: RawStages<unknown, Out, In, {
434
- new: In;
436
+ new: T;
435
437
  }>;
436
438
  } | {
437
439
  stages: 'ctx';
@@ -503,11 +505,19 @@ type ND$1 = {
503
505
  readonly deletedAt?: null;
504
506
  };
505
507
  type SafeE$1<E> = Omit<E, `$${string}` | keyof ID>;
506
- declare const $mergeId: <V extends O>() => <SourcePart extends doc, Out extends doc, E = unknown, EEE extends RORec<string, rawItem> = {}>(out: RWCollection<Out | Replace<Out, Patch<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>, whenNotMatched: "fail" | "discard") => StreamRunnerParam<OutInputE<SourcePart, E>, "out">;
507
- declare const $simpleMergePart: <V extends O>() => <Source extends doc, Out extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, whenNotMatched: "fail" | "discard", ext: Exact<Omit<SafeE$1<EEE>, keyof (ND$1 & TS)>, IdHKT>) => StreamRunnerParam<Source, "out">;
508
- declare const $simpleMerge: <V extends O>() => <Source extends doc, Out extends doc>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, whenNotMatched?: "fail" | "discard") => StreamRunnerParam<Source, "out">;
509
- declare const $mergePart: <V extends O>() => <Out extends doc, 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>, whenNotMatched?: "fail" | "discard") => StreamRunnerParam<Delta<SourcePart>, "out">;
510
- declare const $merge: <V extends O>() => <Out extends doc, SourcePart extends doc>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, whenNotMatched?: "fail" | "discard") => StreamRunnerParam<Delta<SourcePart>, "out">;
508
+ declare const getWhenMatched: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert") => RawStages<O, Out, Out | Replace<Out, P>, RORec<"new", Replace<P, RORec<K, Timestamp>>>>;
509
+ type MergeCollection<V extends O, Out extends Model> = {
510
+ coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
511
+ whenNotMatched: 'discard';
512
+ } | {
513
+ coll: RWCollection<Out | Replace<Out, Patch<V>>, Out>;
514
+ whenNotMatched: 'fail';
515
+ };
516
+ 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>) => StreamRunnerParam<OutInputE<SourcePart, E>, "out">;
517
+ 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>) => StreamRunnerParam<Source, "out">;
518
+ 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") => StreamRunnerParam<Source, "out">;
519
+ 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>) => StreamRunnerParam<Delta<SourcePart>, "out">;
520
+ 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>) => StreamRunnerParam<Delta<SourcePart>, "out">;
511
521
 
512
522
  type ND = {
513
523
  readonly deletedAt?: null;
@@ -519,6 +529,17 @@ declare const $simpleInsert: <T extends doc>(out: RWCollection<Merge<T, {}>>) =>
519
529
  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">;
520
530
  declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
521
531
 
532
+ declare const log: (...args: unknown[]) => void;
533
+
534
+ declare const createIndex: (collection: {
535
+ readonly createIndex: Collection["createIndex"];
536
+ }, indexSpec: IndexSpecification, options?: CreateIndexesOptions) => Promise<void>;
537
+
538
+ declare const noop: () => void;
539
+ declare const map1: <K extends string, Im>(k: AsLiteral<K>, to: Im) => { readonly [P in K]: [P, Im]; } & {
540
+ readonly [_: string]: [K, Im];
541
+ };
542
+
522
543
  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>;
523
544
 
524
545
  type DeltaPipe<Q extends O, T extends Q, F extends HKT<O2>, G extends HKT<O3>> = {
@@ -608,7 +629,7 @@ declare const first: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>
608
629
  declare const firstSure: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T, D, C>;
609
630
  declare const last: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>;
610
631
  type NullToOBJ<N extends null> = N extends null ? O : N;
611
- declare const mergeObjects: <T1, T2, D, C = unknown, N extends null = never>(exprs_0: Expr<T1 | N, D, C>, exprs_1: Expr<T2, D, C>) => Expr<(T1 | NullToOBJ<N>) & T2, D, C>;
632
+ declare const mergeObjects: <T1, T2, D, C = unknown, N extends null = never>(...exprs: readonly [Expr<T1 | N, D, C>, ...[...Expr<T1 | T2 | N, D, C>[], Expr<T2, D, C>]]) => Expr<(T1 | NullToOBJ<N>) & T2, D, C>;
612
633
  declare const anyElementTrue: <D, C = unknown>(expr: Expr<Arr<boolean>, D, C>) => Expr<boolean, D, C>;
613
634
  type Reduce<T, V> = RORec<'value', V> & RORec<'this', T>;
614
635
  declare const $reduce: <T, V, D, C>(input: Expr<Arr<T>, D, C>, initialValue: Expr<V, D, C>, inExpr: Expr<V, D, C & Reduce<T, V>>) => Expr<V, D, C>;
@@ -706,19 +727,8 @@ declare const $and: Combiner;
706
727
  declare const $nor: Combiner;
707
728
  declare const $or: Combiner;
708
729
 
709
- declare const log: (...args: unknown[]) => void;
710
-
711
- declare const createIndex: (collection: {
712
- readonly createIndex: Collection["createIndex"];
713
- }, indexSpec: IndexSpecification, options?: CreateIndexesOptions) => Promise<void>;
714
-
715
- declare const noop: () => void;
716
- declare const map1: <K extends string, Im>(k: AsLiteral<K>, to: Im) => { readonly [P in K]: [P, Im]; } & {
717
- readonly [_: string]: [K, Im];
718
- };
719
-
720
730
  declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Promise<Document>;
721
731
  declare const prepare: (testName?: string) => Promise<MongoClient$1>;
722
732
  declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
723
733
 
724
- export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type MongoTypeNames, type N, type NoRaw, type NullToOBJ, type O, type OPick, type OPickD, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, type jsonItem, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, type notArr, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
734
+ export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, type ExactKeys, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type MongoTypeNames, type N, type NoRaw, type NullToOBJ, type O, type OPick, type OPickD, type Patch, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, getWhenMatched, gt, gte, inArray, isArray, ite, type jsonPrim, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, type notArr, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
package/index.esm.js CHANGED
@@ -1365,84 +1365,88 @@ const $replaceWith = (expr) => ({
1365
1365
  lin: $replaceWith_(expr),
1366
1366
  });
1367
1367
 
1368
- const $mergeX = (out, keys, f, map, whenNotMatched = 'fail', ext) => {
1368
+ const getWhenMatched = (whenNotMatched) => {
1369
+ const setDeleted = whenNotMatched === 'discard';
1370
+ const orNull = (e) => (setDeleted ? $ifNull(e, nil) : e);
1371
+ const preMergeOld = setDeleted
1372
+ ? mergeObjects(root().of('old').expr(), field({
1373
+ deletedAt: ['deletedAt', orNull(root().of('old').of('deletedAt').expr())],
1374
+ touchedAt: ['touchedAt', root().of('merged').of('touchedAt').expr()],
1375
+ }))
1376
+ : root().of('old').expr();
1377
+ const same = eq(preMergeOld)(root().of('merged').expr());
1378
+ const newOrOld = whenNotMatched ===
1379
+ 'insert'
1380
+ ? ctx()('new')
1381
+ : root();
1382
+ const merged = mergeObjects(root().expr(), ctx()('new').expr(), field({
1383
+ deletedAt: ['deletedAt', orNull(newOrOld.of('deletedAt').expr())],
1384
+ }));
1385
+ return link()
1386
+ .with($replaceWith_(field({
1387
+ old: ['old', root().expr()],
1388
+ merged: ['merged', merged],
1389
+ })))
1390
+ .with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
1391
+ };
1392
+ const $mergeX = (out, keys, f, map, ext) => {
1369
1393
  const patch = mapExact(keys, v => sub(v, f));
1370
1394
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
1371
- const setDeleted = whenNotMatched === 'discard';
1395
+ const setDeleted = out.whenNotMatched === 'discard';
1372
1396
  const replacer = map(field(omitPick().backward(spread(patch, {
1373
1397
  _id: ['_id', f.of('_id').expr()],
1374
1398
  touchedAt: ['touchedAt', current],
1375
- deletedAt: [setDeleted ? 'deletedAt' : 'touchedAt', current],
1376
1399
  }))));
1377
- return {
1378
- raw: (first) => link()
1379
- .with($replaceWith_(replacer))
1400
+ const sss = setDeleted
1401
+ ? link()
1402
+ .with($set_(set()({
1403
+ deletedAt: ['deletedAt', to(current)],
1404
+ })))
1380
1405
  .with($merge_({
1381
- into: out,
1406
+ into: out.coll,
1407
+ on: root().of('_id'),
1408
+ whenNotMatched: 'insert',
1409
+ stages: true,
1410
+ whenMatched: getWhenMatched(out.whenNotMatched),
1411
+ })).stages
1412
+ : link().with($merge_({
1413
+ into: out.coll,
1382
1414
  on: root().of('_id'),
1383
- whenNotMatched: whenNotMatched === 'fail' ? 'fail' : 'insert',
1415
+ whenNotMatched: 'fail',
1384
1416
  stages: true,
1385
- whenMatched: asStages([
1417
+ whenMatched: getWhenMatched(out.whenNotMatched),
1418
+ })).stages;
1419
+ const teardown = (coll) => ({
1420
+ collection: coll,
1421
+ method: 'updateMany',
1422
+ params: [
1423
+ filter,
1424
+ [
1386
1425
  {
1387
- $replaceWith: {
1388
- old: '$$ROOT',
1389
- merged: {
1390
- $mergeObjects: [
1391
- '$$ROOT',
1392
- '$$new',
1393
- ...(setDeleted ? [{ deletedAt: { $ifNull: ['$deletedAt', null] } }] : []),
1394
- ],
1395
- },
1396
- },
1426
+ $unset: Object.keys(mapExactToObject(keys, () => 1)),
1397
1427
  },
1398
- {
1399
- $replaceWith: {
1400
- $cond: {
1401
- if: {
1402
- $eq: [
1403
- {
1404
- $mergeObjects: [
1405
- '$old',
1406
- { deletedAt: { $ifNull: ['$old.deletedAt', null] } },
1407
- ],
1408
- },
1409
- { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] },
1410
- ],
1411
- },
1412
- then: '$old',
1413
- else: '$merged',
1414
- },
1415
- },
1416
- },
1417
- ]),
1418
- })).stages,
1419
- teardown: c => c({
1420
- collection: out,
1421
- method: 'updateMany',
1422
- params: [
1423
- filter,
1424
- [
1425
- {
1426
- $unset: Object.keys(mapExactToObject(keys, () => 1)),
1427
- },
1428
- ],
1429
1428
  ],
1430
- }),
1429
+ ],
1430
+ });
1431
+ return {
1432
+ raw: (first) => link().with($replaceWith_(replacer)).with(sss)
1433
+ .stages,
1434
+ teardown: c => (setDeleted ? c(teardown(out.coll)) : c(teardown(out.coll))),
1431
1435
  };
1432
1436
  };
1433
- const $mergeId = () => (out, keys, id, ext, whenNotMatched) => {
1437
+ const $mergeId = () => (out, keys, id, ext) => {
1434
1438
  const omRORec = omitRORec();
1435
1439
  return $mergeX(out, keys, root().of('after'), or => {
1436
1440
  return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
1437
1441
  _id: ['_id', id],
1438
1442
  touchedAt: ['touchedAt', current],
1439
1443
  }))), or);
1440
- }, whenNotMatched, ext);
1444
+ }, ext);
1441
1445
  };
1442
- const $simpleMergePart = () => (out, keys, whenNotMatched, ext) => $mergeX(out, keys, root(), id$1, whenNotMatched, ext);
1443
- const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX(out, keys, root(), id$1, whenNotMatched, {});
1444
- const $mergePart = () => (out, keys, ext, whenNotMatched = 'fail') => $mergeId()(out, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext, whenNotMatched);
1445
- const $merge = () => (out, keys, whenNotMatched = 'fail') => $mergePart()(out, keys, {}, whenNotMatched);
1446
+ const $simpleMergePart = () => (out, keys, ext) => $mergeX(out, keys, root(), id$1, ext);
1447
+ const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {});
1448
+ const $mergePart = () => (out, keys, ext) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext);
1449
+ const $merge = () => (out, keys) => $mergePart()(out, keys, {});
1446
1450
  const assertNotNull$1 = (expr) => expr;
1447
1451
 
1448
1452
  const $insertX = (out, expr, map, ext, extExpr) => {
@@ -1467,23 +1471,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
1467
1471
  into: out,
1468
1472
  on: root().of('_id'),
1469
1473
  stages: true,
1470
- whenMatched: asStages([
1471
- { $replaceWith: { old: '$$ROOT', merged: { $mergeObjects: ['$$ROOT', '$$new'] } } },
1472
- {
1473
- $replaceWith: {
1474
- $cond: {
1475
- if: {
1476
- $eq: [
1477
- '$old',
1478
- { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] },
1479
- ],
1480
- },
1481
- then: '$old',
1482
- else: '$merged',
1483
- },
1484
- },
1485
- },
1486
- ]),
1474
+ whenMatched: getWhenMatched('insert'),
1487
1475
  whenNotMatched: 'insert',
1488
1476
  })).stages;
1489
1477
  },
@@ -2007,4 +1995,4 @@ const makeCol = async (docs, database, name) => {
2007
1995
  }
2008
1996
  };
2009
1997
 
2010
- export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
1998
+ export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, getWhenMatched, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
package/index.js CHANGED
@@ -1367,84 +1367,88 @@ const $replaceWith = (expr) => ({
1367
1367
  lin: $replaceWith_(expr),
1368
1368
  });
1369
1369
 
1370
- const $mergeX = (out, keys, f, map, whenNotMatched = 'fail', ext) => {
1370
+ const getWhenMatched = (whenNotMatched) => {
1371
+ const setDeleted = whenNotMatched === 'discard';
1372
+ const orNull = (e) => (setDeleted ? $ifNull(e, nil) : e);
1373
+ const preMergeOld = setDeleted
1374
+ ? mergeObjects(root().of('old').expr(), field({
1375
+ deletedAt: ['deletedAt', orNull(root().of('old').of('deletedAt').expr())],
1376
+ touchedAt: ['touchedAt', root().of('merged').of('touchedAt').expr()],
1377
+ }))
1378
+ : root().of('old').expr();
1379
+ const same = eq(preMergeOld)(root().of('merged').expr());
1380
+ const newOrOld = whenNotMatched ===
1381
+ 'insert'
1382
+ ? ctx()('new')
1383
+ : root();
1384
+ const merged = mergeObjects(root().expr(), ctx()('new').expr(), field({
1385
+ deletedAt: ['deletedAt', orNull(newOrOld.of('deletedAt').expr())],
1386
+ }));
1387
+ return link()
1388
+ .with($replaceWith_(field({
1389
+ old: ['old', root().expr()],
1390
+ merged: ['merged', merged],
1391
+ })))
1392
+ .with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
1393
+ };
1394
+ const $mergeX = (out, keys, f, map, ext) => {
1371
1395
  const patch = mapExact(keys, v => sub(v, f));
1372
1396
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
1373
- const setDeleted = whenNotMatched === 'discard';
1397
+ const setDeleted = out.whenNotMatched === 'discard';
1374
1398
  const replacer = map(field(omitPick().backward(spread(patch, {
1375
1399
  _id: ['_id', f.of('_id').expr()],
1376
1400
  touchedAt: ['touchedAt', current],
1377
- deletedAt: [setDeleted ? 'deletedAt' : 'touchedAt', current],
1378
1401
  }))));
1379
- return {
1380
- raw: (first) => link()
1381
- .with($replaceWith_(replacer))
1402
+ const sss = setDeleted
1403
+ ? link()
1404
+ .with($set_(set()({
1405
+ deletedAt: ['deletedAt', to(current)],
1406
+ })))
1382
1407
  .with($merge_({
1383
- into: out,
1408
+ into: out.coll,
1409
+ on: root().of('_id'),
1410
+ whenNotMatched: 'insert',
1411
+ stages: true,
1412
+ whenMatched: getWhenMatched(out.whenNotMatched),
1413
+ })).stages
1414
+ : link().with($merge_({
1415
+ into: out.coll,
1384
1416
  on: root().of('_id'),
1385
- whenNotMatched: whenNotMatched === 'fail' ? 'fail' : 'insert',
1417
+ whenNotMatched: 'fail',
1386
1418
  stages: true,
1387
- whenMatched: asStages([
1419
+ whenMatched: getWhenMatched(out.whenNotMatched),
1420
+ })).stages;
1421
+ const teardown = (coll) => ({
1422
+ collection: coll,
1423
+ method: 'updateMany',
1424
+ params: [
1425
+ filter,
1426
+ [
1388
1427
  {
1389
- $replaceWith: {
1390
- old: '$$ROOT',
1391
- merged: {
1392
- $mergeObjects: [
1393
- '$$ROOT',
1394
- '$$new',
1395
- ...(setDeleted ? [{ deletedAt: { $ifNull: ['$deletedAt', null] } }] : []),
1396
- ],
1397
- },
1398
- },
1428
+ $unset: Object.keys(mapExactToObject(keys, () => 1)),
1399
1429
  },
1400
- {
1401
- $replaceWith: {
1402
- $cond: {
1403
- if: {
1404
- $eq: [
1405
- {
1406
- $mergeObjects: [
1407
- '$old',
1408
- { deletedAt: { $ifNull: ['$old.deletedAt', null] } },
1409
- ],
1410
- },
1411
- { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] },
1412
- ],
1413
- },
1414
- then: '$old',
1415
- else: '$merged',
1416
- },
1417
- },
1418
- },
1419
- ]),
1420
- })).stages,
1421
- teardown: c => c({
1422
- collection: out,
1423
- method: 'updateMany',
1424
- params: [
1425
- filter,
1426
- [
1427
- {
1428
- $unset: Object.keys(mapExactToObject(keys, () => 1)),
1429
- },
1430
- ],
1431
1430
  ],
1432
- }),
1431
+ ],
1432
+ });
1433
+ return {
1434
+ raw: (first) => link().with($replaceWith_(replacer)).with(sss)
1435
+ .stages,
1436
+ teardown: c => (setDeleted ? c(teardown(out.coll)) : c(teardown(out.coll))),
1433
1437
  };
1434
1438
  };
1435
- const $mergeId = () => (out, keys, id, ext, whenNotMatched) => {
1439
+ const $mergeId = () => (out, keys, id, ext) => {
1436
1440
  const omRORec = omitRORec();
1437
1441
  return $mergeX(out, keys, root().of('after'), or => {
1438
1442
  return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
1439
1443
  _id: ['_id', id],
1440
1444
  touchedAt: ['touchedAt', current],
1441
1445
  }))), or);
1442
- }, whenNotMatched, ext);
1446
+ }, ext);
1443
1447
  };
1444
- const $simpleMergePart = () => (out, keys, whenNotMatched, ext) => $mergeX(out, keys, root(), id$1, whenNotMatched, ext);
1445
- const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX(out, keys, root(), id$1, whenNotMatched, {});
1446
- const $mergePart = () => (out, keys, ext, whenNotMatched = 'fail') => $mergeId()(out, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext, whenNotMatched);
1447
- const $merge = () => (out, keys, whenNotMatched = 'fail') => $mergePart()(out, keys, {}, whenNotMatched);
1448
+ const $simpleMergePart = () => (out, keys, ext) => $mergeX(out, keys, root(), id$1, ext);
1449
+ const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {});
1450
+ const $mergePart = () => (out, keys, ext) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext);
1451
+ const $merge = () => (out, keys) => $mergePart()(out, keys, {});
1448
1452
  const assertNotNull$1 = (expr) => expr;
1449
1453
 
1450
1454
  const $insertX = (out, expr, map, ext, extExpr) => {
@@ -1469,23 +1473,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
1469
1473
  into: out,
1470
1474
  on: root().of('_id'),
1471
1475
  stages: true,
1472
- whenMatched: asStages([
1473
- { $replaceWith: { old: '$$ROOT', merged: { $mergeObjects: ['$$ROOT', '$$new'] } } },
1474
- {
1475
- $replaceWith: {
1476
- $cond: {
1477
- if: {
1478
- $eq: [
1479
- '$old',
1480
- { $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] },
1481
- ],
1482
- },
1483
- then: '$old',
1484
- else: '$merged',
1485
- },
1486
- },
1487
- },
1488
- ]),
1476
+ whenMatched: getWhenMatched('insert'),
1489
1477
  whenNotMatched: 'insert',
1490
1478
  })).stages;
1491
1479
  },
@@ -2096,6 +2084,7 @@ exports.firstSure = firstSure;
2096
2084
  exports.floor = floor;
2097
2085
  exports.from = from;
2098
2086
  exports.func = func;
2087
+ exports.getWhenMatched = getWhenMatched;
2099
2088
  exports.gt = gt;
2100
2089
  exports.gte = gte;
2101
2090
  exports.inArray = inArray;
@@ -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,27 @@
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
+ export declare const getWhenMatched: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert") => RawStages<O, Out, Out | Replace<Out, P>, RORec<"new", Replace<P, RORec<K, Timestamp>>>>;
15
+ type MergeCollection<V extends O, Out extends Model> = {
16
+ coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
17
+ whenNotMatched: 'discard';
18
+ } | {
19
+ coll: RWCollection<Out | Replace<Out, Patch<V>>, Out>;
20
+ whenNotMatched: 'fail';
21
+ };
22
+ 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>) => StreamRunnerParam<OutInputE<SourcePart, E>, "out">;
23
+ 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>) => StreamRunnerParam<Source, "out">;
24
+ 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") => StreamRunnerParam<Source, "out">;
25
+ 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>) => StreamRunnerParam<Delta<SourcePart>, "out">;
26
+ 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>) => StreamRunnerParam<Delta<SourcePart>, "out">;
27
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { IdHKT, 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
+ 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>) => StreamRunnerParam<D, "out">;
12
+ export declare const $simpleInsert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<T, "out">;
13
+ 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">;
14
+ export declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
15
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { RWCollection, WriteonlyCollection } from '../../../types';
2
+ import type { AsLiteral, ID, O, Rec, Replace, 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 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<Replace<Out, Strict<Grp, V, GG, EE>>>>, gid: AsLiteral<GI<GG>>, extra: ExprsExact<Extra<EE, V, GG>, V_Grp<V, GG, Grp>>, idPrefix?: string) => StreamRunnerParam<Delta<T>, "out">;
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<Replace<Out, Strict<string, V, "_id", EE>>, Out>, extra: ExprsExact<Omit<EE, IdAndTsKeys | keyof Omit<V, IdAndTsKeys>>, doc & Omit<V, IdAndTsKeys>>) => StreamRunnerParam<Delta<T>, "out">;
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<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,2 @@
1
+ export { $groupMerge, $groupId, $group } from './$group-merge';
2
+ export type { Loose, Strict } from './utils/sub-merge';
@@ -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,18 @@
1
+ import type { AsLiteral, ID, O, Rec, Replace, WriteonlyCollection, notArr } from '../../../../types';
2
+ import { type ExprsExact } from '../../../expression/concat';
3
+ import type { 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
+ 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<Replace<Out, Strict<Grp, VV, 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">;
18
+ export {};
@@ -0,0 +1,9 @@
1
+ export * from './group';
2
+ export * from './lookup';
3
+ export * from './match';
4
+ export * from './set';
5
+ export * from './unwind';
6
+ export * from './$merge';
7
+ export * from './$upsert';
8
+ export * from './out';
9
+ export { $group_ } from './mongo-stages';
@@ -0,0 +1,10 @@
1
+ import type { 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>;
8
+ field2: Field<RQ, S | N>;
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, AsLiteral, HKT, ID, O, Rec } from '../../../types';
2
+ import { type Field } from '../../field';
3
+ import type { Before, RawStages, TStages } 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, S, As extends s, Null extends null = never>({ field1, field2 }: {
6
+ field1: Field<LQ, S>;
7
+ field2: Field<RQ, 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, O, RORec, doc, notArr } 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>;
6
+ foreignField: Field<RQ, 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 {};