@omegup/msync 0.0.15 → 0.0.17

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 (89) hide show
  1. package/index.d.ts +21 -8
  2. package/index.esm.js +103 -3
  3. package/index.js +103 -2
  4. package/lib/accumulators/index.d.ts +10 -0
  5. package/lib/aggregate/$merge.d.ts +10 -0
  6. package/lib/aggregate/$upsert.d.ts +9 -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 +15 -0
  11. package/lib/aggregate/index.d.ts +8 -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 +11 -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 +34 -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 +12 -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 +5 -0
  28. package/lib/boot/boot-simpl.d.ts +14 -0
  29. package/lib/boot/boot.d.ts +36 -0
  30. package/lib/boot/index.d.ts +2 -0
  31. package/lib/expression/arith.d.ts +26 -0
  32. package/lib/expression/array.d.ts +25 -0
  33. package/lib/expression/concat.d.ts +30 -0
  34. package/lib/expression/date.d.ts +17 -0
  35. package/lib/expression/expr-base.d.ts +5 -0
  36. package/lib/expression/index.d.ts +7 -0
  37. package/lib/expression/logic.d.ts +22 -0
  38. package/lib/expression/range.d.ts +6 -0
  39. package/lib/expression/val.d.ts +25 -0
  40. package/lib/field/field.d.ts +25 -0
  41. package/lib/field/index.d.ts +1 -0
  42. package/lib/machine.d.ts +9 -0
  43. package/lib/predicate/$eq.d.ts +13 -0
  44. package/lib/predicate/$expr.d.ts +3 -0
  45. package/lib/predicate/$in.d.ts +2 -0
  46. package/lib/predicate/index.d.ts +3 -0
  47. package/lib/predicate/utils.d.ts +5 -0
  48. package/lib/query/index.d.ts +1 -0
  49. package/lib/query/logic.d.ts +11 -0
  50. package/lib/stream/aggregate.d.ts +7 -0
  51. package/lib/types/accumulator.d.ts +30 -0
  52. package/lib/types/aggregate.d.ts +9 -0
  53. package/lib/types/expr.d.ts +27 -0
  54. package/lib/types/extern.d.ts +3 -0
  55. package/lib/types/index.d.ts +8 -0
  56. package/lib/types/lookup.d.ts +19 -0
  57. package/lib/types/machine.d.ts +17 -0
  58. package/lib/types/predicate.d.ts +14 -0
  59. package/lib/types/query.d.ts +12 -0
  60. package/lib/types/stream.d.ts +67 -0
  61. package/lib/update/index.d.ts +1 -0
  62. package/lib/update/updater.d.ts +19 -0
  63. package/lib/utils/before.d.ts +3 -0
  64. package/lib/utils/coll.d.ts +5 -0
  65. package/lib/utils/db-indexes.d.ts +4 -0
  66. package/lib/utils/guard.d.ts +18 -0
  67. package/lib/utils/index.d.ts +3 -0
  68. package/lib/utils/json.d.ts +9 -0
  69. package/lib/utils/log.d.ts +1 -0
  70. package/lib/utils/map-object.d.ts +41 -0
  71. package/lib/utils/merge/combiners.d.ts +6 -0
  72. package/lib/utils/merge/index.d.ts +2 -0
  73. package/lib/utils/merge/merge.d.ts +7 -0
  74. package/lib/utils/merge/next-winner.d.ts +3 -0
  75. package/lib/utils/merge/types.d.ts +19 -0
  76. package/lib/utils/merge/utils.d.ts +4 -0
  77. package/lib/utils/tear-down.d.ts +2 -0
  78. package/lib/watch.d.ts +15 -0
  79. package/package.json +1 -1
  80. package/test/mongodb.d.ts +9 -0
  81. package/test/uri.d.ts +1 -0
  82. package/types/class.d.ts +1 -0
  83. package/types/extern.d.ts +3 -0
  84. package/types/global.d.ts +44 -0
  85. package/types/hkt.d.ts +56 -0
  86. package/types/index.d.ts +6 -0
  87. package/types/json.d.ts +54 -0
  88. package/types/mongo.d.ts +24 -0
  89. package/types/view.d.ts +35 -0
package/index.d.ts CHANGED
@@ -96,6 +96,9 @@ type StreamRunnerParam<in V, out Result> = {
96
96
  teardown: <R>(consume: <W, M extends keyof Actions<W>>(x: TeardownRecord<W, M>) => R) => R;
97
97
  };
98
98
  type StreamRunner<out V> = <Result>(input: StreamRunnerParam<V, Result>) => Runner<readonly Result[], HasJob>;
99
+ type SimpleStreamExecutionResult<out Q, out V extends Q> = {
100
+ readonly out: StreamRunner<V>;
101
+ };
99
102
  type SnapshotStreamExecutionResult<out Q, out V extends Q> = {
100
103
  readonly out: StreamRunner<Delta<V>>;
101
104
  readonly stages: Stages<Before<Q>, Before<V>, UBefore<Q>>;
@@ -475,10 +478,10 @@ type s = string;
475
478
  declare const $unwind: <T extends doc, K extends s, U extends doc>(k: AsLiteral<K>, dict: RORec<K, "key">) => DeltaStages<O, T & Rec<K, Arr<U>>, T & Rec<K, U>>;
476
479
 
477
480
  type OutInputE<T, E, A = T | null> = ID & Rec<'after', A> & E;
478
- type Allowed$1<K extends string> = Exclude<K, keyof (TS & ID)>;
479
- type Patch<V, KK extends StrKey<V>> = ((OPick<V, Allowed$1<KK>> & ID) | (Rec<Allowed$1<KK>, N> & ID)) & TS;
480
- declare const $simpleMerge: <V extends Model & ID>() => <KK extends StrKey<V>, Out extends doc>(out: RWCollection<Out | Replace<Out, Patch<V, KK>>, Out>, keys: ExactKeys<Allowed$1<KK>>) => StreamRunnerParam<OutInputE<OPick<V, Allowed$1<KK>> & ID, unknown>, "out">;
481
- declare const $merge: <V extends Model & ID>() => <KK extends StrKey<V>, Out extends doc>(out: RWCollection<Out | Replace<Out, Patch<V, KK>>, Out>, keys: ExactKeys<Allowed$1<KK>>) => StreamRunnerParam<Delta<OPick<V, Allowed$1<KK>> & ID>, "out">;
481
+ type Allowed$2<K extends string> = Exclude<K, keyof (TS & ID)>;
482
+ type Patch<V, KK extends StrKey<V>> = ((OPick<V, Allowed$2<KK>> & ID) | (Rec<Allowed$2<KK>, N> & ID)) & TS;
483
+ declare const $simpleMerge: <V extends Model & ID>() => <KK extends StrKey<V>, Out extends doc>(out: RWCollection<Out | Replace<Out, Patch<V, KK>>, Out>, keys: ExactKeys<Allowed$2<KK>>) => StreamRunnerParam<OutInputE<OPick<V, Allowed$2<KK>> & ID, unknown>, "out">;
484
+ declare const $merge: <V extends Model & ID>() => <KK extends StrKey<V>, Out extends doc>(out: RWCollection<Out | Replace<Out, Patch<V, KK>>, Out>, keys: ExactKeys<Allowed$2<KK>>) => StreamRunnerParam<Delta<OPick<V, Allowed$2<KK>> & ID>, "out">;
482
485
 
483
486
  type ND = {
484
487
  readonly deletedAt?: null;
@@ -492,15 +495,25 @@ type DeltaPipe<Q extends O, T extends Q, F extends HKT<O2>, G extends HKT<O3>> =
492
495
  get: () => App<F, [Q, T]>;
493
496
  };
494
497
 
495
- type Allowed<K> = Exclude<K, 'deletedAt' | '_id'>;
496
- type AllowedPick<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed<K>>;
498
+ type Allowed$1<K> = Exclude<K, 'deletedAt' | '_id'>;
499
+ type AllowedPick$1<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed$1<K>>;
497
500
  interface SnapshotStreamHKT extends HKT<O2> {
498
501
  readonly out: SnapshotStreamExecutionResult<I<O2, this>[0], I<O2, this>[1]>;
499
502
  }
500
503
  interface DeltaHKT extends HKT<O3> {
501
504
  readonly out: DeltaStages<I<O3, this>[0], I<O3, this>[1], I<O3, this>[2]>;
502
505
  }
503
- declare const staging: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed<KK>>, streamName: string) => DeltaPipe<AllowedPick<V, KK>, AllowedPick<V, KK>, SnapshotStreamHKT, DeltaHKT>;
506
+ declare const staging: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed$1<KK>>, streamName: string) => DeltaPipe<AllowedPick$1<V, KK>, AllowedPick$1<V, KK>, SnapshotStreamHKT, DeltaHKT>;
507
+
508
+ type Allowed<K> = Exclude<K, 'deletedAt' | '_id'>;
509
+ type AllowedPick<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed<K>>;
510
+ interface StreamRunnerHKT extends HKT<O2> {
511
+ readonly out: SimpleStreamExecutionResult<I<O2, this>[0], I<O2, this>[1]>;
512
+ }
513
+ interface StagesHKT extends HKT<O3> {
514
+ readonly out: RORec<'lin', RawStages<I<O3, this>[0], I<O3, this>[1], I<O3, this>[2], unknown, 1>>;
515
+ }
516
+ declare const from: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed<KK>>, streamName: string) => DeltaPipe<AllowedPick<V, KK>, AllowedPick<V, KK>, StreamRunnerHKT, StagesHKT>;
504
517
 
505
518
  declare const max: <D, C>(...expr: Expr<number, D, C>[]) => Expr<number, D, C>;
506
519
  declare const lt: <D, C>(expr_0: Expr<number, D, C>, expr_1: Expr<number, D, C>) => Expr<boolean, D, C>;
@@ -641,4 +654,4 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
641
654
  declare const prepare: (testName?: string) => Promise<MongoClient$1>;
642
655
  declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
643
656
 
644
- export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $simpleMerge, $sum, $unwind, $unwindDelta, $upsert, 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 N, type NoRaw, 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, 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, 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, type notArr, notNull, now, or, pair, prepare, rand, range, root, set, setField, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
657
+ export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $simpleMerge, $sum, $unwind, $unwindDelta, $upsert, 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 N, type NoRaw, 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, 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, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, type notArr, notNull, now, or, pair, prepare, rand, range, root, set, setField, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
package/index.esm.js CHANGED
@@ -1183,7 +1183,7 @@ const actions = {
1183
1183
  updateMany: (c, args) => c.updateMany(...args),
1184
1184
  };
1185
1185
  const streamNames = {};
1186
- const executes = (view, input, streamName) => {
1186
+ const executes$1 = (view, input, streamName) => {
1187
1187
  const hash = crypto$1
1188
1188
  .createHash('md5')
1189
1189
  .update(new Error().stack + '')
@@ -1349,7 +1349,107 @@ const executes = (view, input, streamName) => {
1349
1349
  out: run,
1350
1350
  };
1351
1351
  };
1352
- const staging = (view, streamName) => pipe(input => executes(view, input, streamName), emptyDelta(), concatDelta, emptyDelta);
1352
+ const staging = (view, streamName) => pipe(input => executes$1(view, input, streamName), emptyDelta(), concatDelta, emptyDelta);
1353
+
1354
+ const executes = (view, input, streamName) => {
1355
+ const hash = crypto$1
1356
+ .createHash('md5')
1357
+ .update(new Error().stack + '')
1358
+ .digest('base64url');
1359
+ if (!streamNames[streamName])
1360
+ streamNames[streamName] = hash;
1361
+ else if (streamNames[streamName] != hash)
1362
+ throw new Error('streamName already used');
1363
+ const { collection, projection, hardMatch, match } = view;
1364
+ const job = {};
1365
+ const db = collection.s.db, coll = collection.collectionName;
1366
+ db.command({
1367
+ collMod: coll,
1368
+ changeStreamPreAndPostImages: { enabled: true },
1369
+ });
1370
+ createIndex(collection, { touchedAt: 1 }, {
1371
+ partialFilterExpression: { deletedAt: { $eq: null } },
1372
+ name: 'touchedAt_' + new UUID().toString('base64'),
1373
+ });
1374
+ const last = db.collection('__last');
1375
+ const projectInput = $project_(spread(projection, {
1376
+ deletedAt: ['deletedAt', 1],
1377
+ _id: ['_id', 1],
1378
+ }));
1379
+ const notDeleted = root().of('deletedAt').has($eq(null));
1380
+ const run = (finalInput) => {
1381
+ const clear = async () => { };
1382
+ const withStop = (next, tr) => {
1383
+ return addTeardown(() => ({ stop, next: next(), clear }), tr);
1384
+ };
1385
+ const next = (next, debug, tr) => ({
1386
+ cont: withStop(next, tr),
1387
+ data: [],
1388
+ info: { job, debug },
1389
+ });
1390
+ const data = {
1391
+ input: input,
1392
+ finalInputFirst: finalInput.raw(true),
1393
+ finalInput: finalInput.raw(false),
1394
+ teardown: finalInput.teardown((x) => ({
1395
+ collection: x.collection.collectionName,
1396
+ method: x.method,
1397
+ params: x.params,
1398
+ })),
1399
+ };
1400
+ const step0 = () => Promise.resolve(next(step1, 'get last update'));
1401
+ const stop = withStop(step0);
1402
+ const step1 = () => Promise.all([
1403
+ last.findOne({ _id: streamName, data }),
1404
+ last.findOne({ _id: streamName }),
1405
+ ]).then(ts => next(step2_5(ts), 'handle teardown'));
1406
+ const step2_5 = ([same, exists]) => async () => {
1407
+ const handleTeardown = async (last) => {
1408
+ const { collection: c, method: m, params: p } = last.data.teardown;
1409
+ const { collection, method, params } = {
1410
+ collection: db.collection(c),
1411
+ method: m,
1412
+ params: p,
1413
+ };
1414
+ await actions[method](collection, params);
1415
+ };
1416
+ if (exists && !same)
1417
+ await handleTeardown(exists);
1418
+ return next(step4(same), 'clone into new collection');
1419
+ };
1420
+ const makeStream = (startAt) => makeWatchStream(db, view, startAt);
1421
+ const step4 = (lastTS) => async () => {
1422
+ const hardQuery = $and(lastTS && root().of('touchedAt').has($gteTs(lastTS.ts)), hardMatch, notDeleted, match && $expr(match));
1423
+ const aggResult = await aggregate(c => c({
1424
+ coll: collection,
1425
+ input: link()
1426
+ .with($match_(hardQuery))
1427
+ .with(projectInput)
1428
+ .with(input)
1429
+ .with(finalInput.raw(lastTS === null)).stages,
1430
+ }));
1431
+ const stream = makeStream(aggResult.cursor.atClusterTime);
1432
+ return next(step7({ aggResult, result: aggResult, stream }), 'update __last', () => stream.close());
1433
+ };
1434
+ const step7 = (l) => async () => {
1435
+ await last.updateOne({ _id: streamName }, { $set: { ts: l.result.cursor.atClusterTime, data } }, { upsert: true });
1436
+ return step8(l);
1437
+ };
1438
+ const step8 = (l) => {
1439
+ return {
1440
+ data: l.aggResult.cursor.firstBatch,
1441
+ info: { job: undefined, debug: 'wait for change' },
1442
+ cont: withStop(() => l.stream.tryNext().then(doc => (doc ? next(step1, 'restart') : step8(l)))),
1443
+ };
1444
+ };
1445
+ return stop;
1446
+ };
1447
+ return {
1448
+ out: run,
1449
+ };
1450
+ };
1451
+ const emptyLin = () => ({ lin: link().stages });
1452
+ const from = (view, streamName) => pipe(input => executes(view, input.lin, streamName), { lin: link().stages }, ({ lin: a }, { lin: b }) => ({ lin: concatStages(a, b) }), emptyLin);
1353
1453
 
1354
1454
  const dayAndMonthPart = (date) => asExpr({
1355
1455
  raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%m-%d' } }),
@@ -1629,4 +1729,4 @@ const makeCol = async (docs, database, name) => {
1629
1729
  }
1630
1730
  };
1631
1731
 
1632
- export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $simpleMerge, $sum, $unwind, $unwindDelta, $upsert, Field, Machine, add, and, 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, 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, notNull, now, or, pair, prepare, rand, range, root, set, setField, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
1732
+ export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $simpleMerge, $sum, $unwind, $unwindDelta, $upsert, Field, Machine, add, and, 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, notNull, now, or, pair, prepare, rand, range, root, set, setField, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
package/index.js CHANGED
@@ -1185,7 +1185,7 @@ const actions = {
1185
1185
  updateMany: (c, args) => c.updateMany(...args),
1186
1186
  };
1187
1187
  const streamNames = {};
1188
- const executes = (view, input, streamName) => {
1188
+ const executes$1 = (view, input, streamName) => {
1189
1189
  const hash = crypto$1
1190
1190
  .createHash('md5')
1191
1191
  .update(new Error().stack + '')
@@ -1351,7 +1351,107 @@ const executes = (view, input, streamName) => {
1351
1351
  out: run,
1352
1352
  };
1353
1353
  };
1354
- const staging = (view, streamName) => pipe(input => executes(view, input, streamName), emptyDelta(), concatDelta, emptyDelta);
1354
+ const staging = (view, streamName) => pipe(input => executes$1(view, input, streamName), emptyDelta(), concatDelta, emptyDelta);
1355
+
1356
+ const executes = (view, input, streamName) => {
1357
+ const hash = crypto$1
1358
+ .createHash('md5')
1359
+ .update(new Error().stack + '')
1360
+ .digest('base64url');
1361
+ if (!streamNames[streamName])
1362
+ streamNames[streamName] = hash;
1363
+ else if (streamNames[streamName] != hash)
1364
+ throw new Error('streamName already used');
1365
+ const { collection, projection, hardMatch, match } = view;
1366
+ const job = {};
1367
+ const db = collection.s.db, coll = collection.collectionName;
1368
+ db.command({
1369
+ collMod: coll,
1370
+ changeStreamPreAndPostImages: { enabled: true },
1371
+ });
1372
+ createIndex(collection, { touchedAt: 1 }, {
1373
+ partialFilterExpression: { deletedAt: { $eq: null } },
1374
+ name: 'touchedAt_' + new mongodb.UUID().toString('base64'),
1375
+ });
1376
+ const last = db.collection('__last');
1377
+ const projectInput = $project_(spread(projection, {
1378
+ deletedAt: ['deletedAt', 1],
1379
+ _id: ['_id', 1],
1380
+ }));
1381
+ const notDeleted = root().of('deletedAt').has($eq(null));
1382
+ const run = (finalInput) => {
1383
+ const clear = async () => { };
1384
+ const withStop = (next, tr) => {
1385
+ return addTeardown(() => ({ stop, next: next(), clear }), tr);
1386
+ };
1387
+ const next = (next, debug, tr) => ({
1388
+ cont: withStop(next, tr),
1389
+ data: [],
1390
+ info: { job, debug },
1391
+ });
1392
+ const data = {
1393
+ input: input,
1394
+ finalInputFirst: finalInput.raw(true),
1395
+ finalInput: finalInput.raw(false),
1396
+ teardown: finalInput.teardown((x) => ({
1397
+ collection: x.collection.collectionName,
1398
+ method: x.method,
1399
+ params: x.params,
1400
+ })),
1401
+ };
1402
+ const step0 = () => Promise.resolve(next(step1, 'get last update'));
1403
+ const stop = withStop(step0);
1404
+ const step1 = () => Promise.all([
1405
+ last.findOne({ _id: streamName, data }),
1406
+ last.findOne({ _id: streamName }),
1407
+ ]).then(ts => next(step2_5(ts), 'handle teardown'));
1408
+ const step2_5 = ([same, exists]) => async () => {
1409
+ const handleTeardown = async (last) => {
1410
+ const { collection: c, method: m, params: p } = last.data.teardown;
1411
+ const { collection, method, params } = {
1412
+ collection: db.collection(c),
1413
+ method: m,
1414
+ params: p,
1415
+ };
1416
+ await actions[method](collection, params);
1417
+ };
1418
+ if (exists && !same)
1419
+ await handleTeardown(exists);
1420
+ return next(step4(same), 'clone into new collection');
1421
+ };
1422
+ const makeStream = (startAt) => makeWatchStream(db, view, startAt);
1423
+ const step4 = (lastTS) => async () => {
1424
+ const hardQuery = $and(lastTS && root().of('touchedAt').has($gteTs(lastTS.ts)), hardMatch, notDeleted, match && $expr(match));
1425
+ const aggResult = await aggregate(c => c({
1426
+ coll: collection,
1427
+ input: link()
1428
+ .with($match_(hardQuery))
1429
+ .with(projectInput)
1430
+ .with(input)
1431
+ .with(finalInput.raw(lastTS === null)).stages,
1432
+ }));
1433
+ const stream = makeStream(aggResult.cursor.atClusterTime);
1434
+ return next(step7({ aggResult, result: aggResult, stream }), 'update __last', () => stream.close());
1435
+ };
1436
+ const step7 = (l) => async () => {
1437
+ await last.updateOne({ _id: streamName }, { $set: { ts: l.result.cursor.atClusterTime, data } }, { upsert: true });
1438
+ return step8(l);
1439
+ };
1440
+ const step8 = (l) => {
1441
+ return {
1442
+ data: l.aggResult.cursor.firstBatch,
1443
+ info: { job: undefined, debug: 'wait for change' },
1444
+ cont: withStop(() => l.stream.tryNext().then(doc => (doc ? next(step1, 'restart') : step8(l)))),
1445
+ };
1446
+ };
1447
+ return stop;
1448
+ };
1449
+ return {
1450
+ out: run,
1451
+ };
1452
+ };
1453
+ const emptyLin = () => ({ lin: link().stages });
1454
+ const from = (view, streamName) => pipe(input => executes(view, input.lin, streamName), { lin: link().stages }, ({ lin: a }, { lin: b }) => ({ lin: concatStages(a, b) }), emptyLin);
1355
1455
 
1356
1456
  const dayAndMonthPart = (date) => asExpr({
1357
1457
  raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%m-%d' } }),
@@ -1702,6 +1802,7 @@ exports.filterDefined = filterDefined;
1702
1802
  exports.first = first$1;
1703
1803
  exports.firstSure = firstSure;
1704
1804
  exports.floor = floor;
1805
+ exports.from = from;
1705
1806
  exports.func = func;
1706
1807
  exports.gt = gt;
1707
1808
  exports.gte = gte;
@@ -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,10 @@
1
+ import type { OPick, RWCollection } from '../../types';
2
+ import type { ID, N, Rec, Replace, StrKey, doc } from '../../types/json';
3
+ import type { Delta, Model, StreamRunnerParam, TS } from '../types';
4
+ import { type ExactKeys } from '../utils/map-object';
5
+ type OutInputE<T, E, A = T | null> = ID & Rec<'after', A> & E;
6
+ type Allowed<K extends string> = Exclude<K, keyof (TS & ID)>;
7
+ type Patch<V, KK extends StrKey<V>> = ((OPick<V, Allowed<KK>> & ID) | (Rec<Allowed<KK>, N> & ID)) & TS;
8
+ export declare const $simpleMerge: <V extends Model & ID>() => <KK extends StrKey<V>, Out extends doc>(out: RWCollection<Out | Replace<Out, Patch<V, KK>>, Out>, keys: ExactKeys<Allowed<KK>>) => StreamRunnerParam<OutInputE<OPick<V, Allowed<KK>> & ID, unknown>, "out">;
9
+ export declare const $merge: <V extends Model & ID>() => <KK extends StrKey<V>, Out extends doc>(out: RWCollection<Out | Replace<Out, Patch<V, KK>>, Out>, keys: ExactKeys<Allowed<KK>>) => StreamRunnerParam<Delta<OPick<V, Allowed<KK>> & ID>, "out">;
10
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { RWCollection } from '../../types';
2
+ import type { ID, doc } from '../../types/json';
3
+ import type { Del, Delta, StreamRunnerParam, TS } from '../types';
4
+ type ND = {
5
+ readonly deletedAt?: null;
6
+ };
7
+ export type Merge<T extends ID> = (T & ND & TS) | Del;
8
+ export declare const $upsert: <T extends doc>(out: RWCollection<Merge<T>>) => StreamRunnerParam<Delta<T>, "out">;
9
+ 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" | keyof Omit<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,15 @@
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
+ export type Loose<Grp, VV, GG extends string> = Prepare<Grp, GG> & Partial<V<VV, GG>>;
11
+ export type Strict<Grp, VV, GG extends string, EE> = Prepare<Grp, GG> & V<VV, GG> & Omit<EE, IdAndTsKeys | GI<GG> | keyof V<VV, GG>>;
12
+ export type V_Grp<VV, GG extends string, Grp> = Rec<GI<GG>, Grp> & V<VV, GG>;
13
+ export type Extra<EE, VV, GG extends string> = Omit<EE, IdAndTsKeys | GI<GG> | keyof V<VV, GG>>;
14
+ 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">;
15
+ export {};
@@ -0,0 +1,8 @@
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';
@@ -0,0 +1,10 @@
1
+ import type { AsLiteral, ID, N, O, Rec } 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> = Delta<Rec<K1, LE> & Rec<Exclude<KK2, BA | K1>, RE> & ID>;
6
+ export declare const $lookupDelta: <LQ extends O, LE extends LQ & O, RQ extends O, RE extends RQ, BRB extends UBefore<RQ>, RS extends UBefore<RQ>, S, K1 extends s, KK2 extends s>({ 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: K1 | Exclude<KK2, BA | K1> | false) => RawStages<unknown, Delta<LE>, Both<K1, LE, KK2, RE>>;
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>({ 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" | "right" | false) => <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,11 @@
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 {};
@@ -0,0 +1,3 @@
1
+ import type { doc } from '../../../types';
2
+ import type { Delta, Expr } from '../../types';
3
+ export declare const $matchDelta: <T extends doc>(query: Expr<boolean, T>) => import("../../types").RawStages<unknown, Delta<T>, Delta<T>, unknown, number>;
@@ -0,0 +1,3 @@
1
+ import type { doc } from '../../../types';
2
+ import type { DeltaStages, Expr } from '../../types';
3
+ export declare const $match: <T extends doc>(query: Expr<boolean, T>) => DeltaStages<T, T, T>;
@@ -0,0 +1,2 @@
1
+ export { $matchDelta } from './$match-delta';
2
+ export { $match } from './$match';
@@ -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>(k: K) => RawStages<O<T>, T & Rec<K, Arr<U>>, T & Rec<K, 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/map-object").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,34 @@
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>;
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?: undefined;
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
+ } | {
29
+ stages: 'ctx';
30
+ vars: ExprsExact<Ctx, T>;
31
+ into: RWCollection<In, Out>;
32
+ whenMatched: RawStages<unknown, Out, In, Ctx>;
33
+ });
34
+ 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>;
@@ -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
+ 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>(k: K) => FRawStages<T, T & Rec<K, Arr<R>>, T & Rec<K, R>>;
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 {};
@@ -0,0 +1,12 @@
1
+ import type { ConstHKT, HKT, I, N, O, RORec, Rec, jsonItem } from '../../../types';
2
+ import type { BA, Delta, Expr, FRawStages, RawStages } from '../../types';
3
+ import { type Updater } from '../../update/updater';
4
+ import { type MapK } from '../../utils/map-object';
5
+ export interface ParDeltaHKT<K extends BA, T extends jsonItem, E> extends HKT<jsonItem> {
6
+ readonly out: RORec<K, I<jsonItem, this>> & Delta<T> & E;
7
+ }
8
+ type Delta2<T extends jsonItem, BA2 extends string> = Delta<T> & Partial<RORec<BA2, T | null>>;
9
+ export declare const $setEach1: <T extends jsonItem, V extends jsonItem, BA2 extends string, E = unknown, C = unknown>(updater: (k: BA) => Updater<Delta<T> & Partial<RORec<BA2, T | null>> & E, T | N, V | null, C>, dict: MapK<BA2, ConstHKT<BA>>) => FRawStages<unknown, Delta2<T, BA2> & E, Rec<BA2, V | null> & Omit<Delta<T> & E, BA2>, C, 1>;
10
+ export declare const $setEach: <T extends O, V extends jsonItem, BA2 extends string, E = unknown, C = unknown>(updater: (k: BA) => Updater<Delta<T> & E, T | N, V | null, C>, dict: MapK<BA2, ConstHKT<BA>>) => RawStages<unknown, Delta2<T, BA2> & E, Rec<BA2, V | null> & Omit<Delta<T> & E, BA2>, C, 1>;
11
+ export declare const $replaceWithEach: <T extends O, V extends jsonItem, E = unknown>(expr: <K extends BA>(field: K) => Expr<V | null, Rec<K, T> & Delta<T> & E>) => RawStages<unknown, Delta<T> & E, Delta<V> & Omit<E, BA>>;
12
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { O, jsonItem } from '../../../types';
2
+ import type { Delta, Expr, RawStages } from '../../types';
3
+ import { type Updater } from '../../update/updater';
4
+ export declare const $replaceWithDelta: <T extends O, V extends jsonItem>(expr: Expr<V, T>) => RawStages<unknown, Delta<T>, Delta<V>>;
5
+ export declare const $setDelta: <T extends O, V extends O, C = unknown>(updater: Updater<T, T, V, C>) => RawStages<unknown, Delta<T>, Delta<V>, C, number>;
@@ -0,0 +1,6 @@
1
+ import type { O, Replace } from '../../../types';
2
+ import type { DeltaStages, Expr, LinStages } from '../../types';
3
+ import { type UpdaterHKT } from '../../update/updater';
4
+ import type { MapO } from '../../utils/map-object';
5
+ export declare const $set: <V extends O>() => <R extends O, C = unknown>(fields: MapO<V, UpdaterHKT<R, R, V, C>>) => DeltaStages<O, R, Replace<R, V>, C> & LinStages<O, R, Replace<R, V>, C>;
6
+ export declare const $replaceWith: <T extends O, V extends O>(expr: Expr<V, T>) => DeltaStages<O, T, V> & LinStages<O, T, V>;
@@ -0,0 +1 @@
1
+ export { $replaceWith, $set } from './$set';
@@ -0,0 +1,5 @@
1
+ import type { Arr, AsLiteral, ID, Rec, doc } from '../../../types';
2
+ import type { Delta, RawStages } from '../../types';
3
+ type s = string;
4
+ export declare const $unwindDelta: <K1 extends s, T extends doc, K2 extends s, U extends doc>(k1: AsLiteral<K1>, k2: AsLiteral<K2>, k: K1 | K2 | false) => RawStages<Delta<Rec<K1, T>>, Delta<Rec<K1, T> & Rec<K2, Arr<U>>>, Delta<Rec<K1, T> & Rec<K2, U> & ID>>;
5
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Arr, AsLiteral, doc, O, Rec, RORec } from '../../../types';
2
+ import type { DeltaStages } from '../../types';
3
+ export { $unwindDelta } from './$unwind-delta';
4
+ type s = string;
5
+ export declare const $unwind: <T extends doc, K extends s, U extends doc>(k: AsLiteral<K>, dict: RORec<K, "key">) => DeltaStages<O, T & Rec<K, Arr<U>>, T & Rec<K, U>>;