@omegup/msync 0.1.24 → 0.1.26

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 CHANGED
@@ -1,738 +1,13 @@
1
- import { Timestamp, Filter, UpdateFilter, BSON, MaxKey, Db, Collection, IndexSpecification, CreateIndexesOptions, MongoClient as MongoClient$1, OptionalUnlessRequiredId } from 'mongodb';
2
- export { Collection, Timestamp } from 'mongodb';
3
-
4
- type HasJob = {
5
- job: object | undefined;
6
- };
7
- type Runner<T, Info extends HasJob> = Iterator<T, Info>;
8
- type NextFrame<T, Info> = PromiseLike<Frame<T, Info>>;
9
- type Frame<T, Info> = {
10
- data: T;
11
- info: Info;
12
- cont: Iterator<T, Info>;
13
- };
14
- type IteratorResult<out T, out Info> = {
15
- next: NextFrame<T, Info>;
16
- stop: Iterator<T, Info>;
17
- clear: () => Promise<unknown>;
18
- };
19
- type Iterator<out T, out Info> = () => IteratorResult<T, Info>;
20
-
21
- declare const PredicateRaw: unique symbol;
22
- type PredicateRaw = RawObj & {
23
- [Type]?(x: typeof PredicateRaw): void;
24
- };
25
- declare const Predicate: unique symbol;
26
- interface Predicate<in V> {
27
- [Type]?(x: typeof Predicate, _: V): void;
28
- raw: PredicateRaw;
29
- }
30
-
31
- declare class Field<in R, out V, in C = unknown> {
32
- private field;
33
- private raw;
34
- private concat;
35
- has<R extends O>(this: Field<R, V>, p: Predicate<V>): Query<R, C>;
36
- has<R extends O, V>(this: Field<R, Arr<V>>, p: Predicate<V>): Query<R, C>;
37
- private constructor();
38
- static root: <T extends O>() => Field<T, T, unknown>;
39
- static ctx: <T>() => <K extends string>(k: K) => Field<unknown, T, RORec<K, T>>;
40
- of<V, K extends keyof V, _ extends 0 = 0>(this: Field<R, Arr<V>, C>, k: AsLiteral<K>): Field<R, Arr<V[K]>, C>;
41
- of<V, K extends keyof V, _ extends 1 = 1>(this: Field<R, O<V>, C>, k: K): Field<R, V[K], C>;
42
- of<V, K extends keyof V, I extends N = never, _ extends 2 = 2>(this: Field<R, Arr<V> | Undef<I>, C>, k: K): Field<R, Arr<V[K]> | I, C>;
43
- of<V, K extends keyof V, I extends N = never, _ extends 3 = 3>(this: Field<R, O<V> | Undef<I>, C>, k: K): Field<R, V[K] | I, C>;
44
- with<V, W, C2 = unknown, _ extends 0 = 0>(this: Field<R, O<V>, C>, k: Field<O<V>, W, C2>): Field<R, W, C & C2>;
45
- with<V, W, C2 = unknown, _ extends 1 = 1>(this: Field<R, Arr<V>, C>, k: Field<O<V>, Arr<W> | O<W>, C2>): Field<R, Arr<W>, C & C2>;
46
- with<V, W, I extends N = never, C2 = unknown, _ extends 2 = 2>(this: Field<R, O<V> | Undef<I>, C>, k: Field<O<V>, W, C2>): Field<R, W | I, C & C2>;
47
- with<V, W, I extends N = never, C2 = unknown, _ extends 3 = 3>(this: Field<R, Arr<V> | Undef<I>, C>, k: Field<O<V>, Arr<W> | O<W>, C2>): Field<R, Arr<W> | I, C & C2>;
48
- str(this: Field<R, V>): string;
49
- private exprRaw;
50
- expr<R, V, C = unknown>(this: Field<R, V, C>): Expr<V, R, C>;
51
- }
52
- declare const root: <T extends O>() => Field<T, T, unknown>;
53
- declare const ctx: <T>() => <K extends string>(k: K) => Field<unknown, T, RORec<K, T>>;
54
-
55
- declare const QueryRaw: unique symbol;
56
- type QueryRaw<T, C = unknown> = RawObj & {
57
- [Type]?(x: typeof QueryRaw, y: T, c: C): void;
58
- };
59
- declare const Query: unique symbol;
60
- type Query<in T extends O, in C = unknown> = {
61
- [Type]?(x: typeof Query, y: T, c: C): void;
62
- raw: <DeltaT extends O>(f: Field<DeltaT, T>) => QueryRaw<DeltaT, C>;
63
- };
64
-
65
- declare const RawStage$1: unique symbol;
66
- type RawArr = readonly RawObj[];
67
- interface RawStages<out Q, in S extends Q, out R extends Q, in C = unknown, out M = number> extends RawArr {
68
- [Type]?(_: typeof RawStage$1, source: S, ctx: C, q: Q): readonly [typeof RawStage$1, R, M, Q];
69
- }
70
- type FRawStages<out Q, in S extends Q & O, out R extends Q & O, in C = unknown, out M extends number = number> = <F extends HKT<O, O>>(f: <T extends O>() => Field<App<F, T>, T>) => RawStages<App<F, Q & O>, App<F, S>, App<F, R>, C, M>;
71
- type DeltaStages<out Q, in S extends Q & O, out R extends Q & O, in C = unknown> = {
72
- delta: RawStages<unknown, Delta<S>, Delta<R>, C>;
73
- raw: FRawStages<Q, S, R, C>;
74
- };
75
- type LinStages<out Q, in S extends Q, out R extends Q, in C = unknown> = {
76
- lin: RawStages<Q, S, R, C, 1>;
77
- };
78
- type TStages<in out S, out Q, in out B extends Q, out R extends Q, M extends number = number> = {
79
- coll: ReadonlyCollection<S>;
80
- input: RawStages<unknown, S, B, unknown, M>;
81
- exec: RawStages<Q, B, R, unknown, M>;
82
- };
83
- 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;
84
- type Actions<W> = {
85
- updateMany: [Filter<W>, UpdateFilter<W> | BSON.Document[]];
86
- deleteMany: [Filter<W>];
87
- };
88
- type TeardownRecord<W, M extends keyof Actions<W>> = {
89
- collection: WriteonlyCollection<W>;
90
- method: M;
91
- params: Actions<W>[M];
92
- };
93
- type StreamRunnerParam<in V, out Result> = {
94
- raw: (first: boolean) => RawStages<unknown, V, Result>;
95
- teardown: <R>(consume: <W, M extends keyof Actions<W>>(x: TeardownRecord<W, M>) => R) => R;
96
- };
97
- type StreamRunner<out V> = <Result>(input: StreamRunnerParam<V, Result>, setup?: () => Promise<void>) => Runner<readonly Result[], HasJob>;
98
- type SimpleStreamExecutionResult<out Q, out V extends Q> = {
99
- readonly out: StreamRunner<V>;
100
- };
101
- type SnapshotStreamExecutionResult<out Q, out V extends Q> = {
102
- readonly out: StreamRunner<Delta<V>>;
103
- readonly stages: Stages<Before<Q>, Before<V>, UBefore<Q>>;
104
- };
105
- type Stream<out Q extends O, in out T extends Q, in out F extends HKT<[O, O]>, in out G extends HKT<[O, O, O]>> = <Q2 extends O, Result extends Q2>(input: App<G, [Q2 | T, T, Result]>) => App<F, [Q | Q2, Result]>;
106
- type TS = {
107
- readonly touchedAt: Timestamp;
108
- };
109
- type IsDeleted = {
110
- readonly deletedAt: Timestamp;
111
- };
112
- type DDel = IsDeleted & ID & TS;
113
- type Del = O<DDel>;
114
- type DeletedAt = {
115
- readonly deletedAt?: Timestamp | null | undefined;
116
- };
117
- type D = O<DeletedAt & ID>;
118
- type Model = D & TS;
119
- type BA = 'before' | 'after';
120
- type PreDelta<T, K extends BA = BA, E = unknown> = Rec<K, T> & E;
121
- type Delta<T, K extends BA = BA, E = ID> = PreDelta<T | null, K, E>;
122
- type Before<T> = PreDelta<T, 'before'>;
123
- type UBefore<T> = O & Partial<Delta<T | null, 'before'>>;
124
- type SnapshotStream<out Q extends O, in out T extends Q> = <Q2 extends O, Result extends Q2>(input: DeltaStages<Q2 | T, T, Result>) => SnapshotStreamExecutionResult<Q | Q2, Result>;
125
-
126
- declare const ExprRaw: unique symbol;
127
- type ExprRaw<out T, in Doc, in Ctx = unknown> = {
128
- [Type]?(x: typeof ExprRaw): void;
129
- [ExprRaw]?(doc: Doc, ctx: Ctx): T;
130
- get: () => rawItem;
131
- };
132
- declare const Expr: unique symbol;
133
- type Expr<out T, in Doc, in Ctx = unknown> = {
134
- [Type]?(x: typeof Expr): void;
135
- [Expr]?(doc: Doc, ctx: Ctx): T;
136
- raw: {
137
- <DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, Doc | Undef<I>, C>): ExprRaw<T | I, DeltaD, Ctx & C>;
138
- };
139
- };
140
- type BoolExpr<in D1, in D2, in Ctx = unknown> = {
141
- [Type]?(x: typeof Expr): void;
142
- [Expr](doc: D1, ctx: Ctx): true;
143
- [Expr](doc: D2, ctx: Ctx): false;
144
- raw: {
145
- <DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, D1 | D2 | Undef<I>, C>): ExprRaw<boolean, DeltaD, Ctx & C>;
146
- <DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, D1 | Undef<I>, C>): ExprRaw<true, DeltaD, Ctx & C>;
147
- <DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, D2 | Undef<I>, C>): ExprRaw<false, DeltaD, Ctx & C>;
148
- };
149
- };
150
-
151
- type ExactPart<T, F extends HKT<T[StrKey<T>]>> = MapOPart<T, MappedHKT<T, F>>;
152
- type ExactKeys<K extends string> = Exact<RORec<K, 1>, IdHKT>;
153
- type MapO<T, F extends HKT<StrKey<T>>> = MapOPart<T, F> & {
154
- readonly [P: string]: readonly [StrKey<T>, unknown];
155
- };
156
- type MapOPart<T, F extends HKT<StrKey<T>>, K extends keyof T = StrKey<T>> = {
157
- readonly [P in K]: readonly [P, App<F, P & string>];
158
- };
159
- type Exact<T, F extends HKT<T[StrKey<T>]>> = MapO<T, MappedHKT<T, F>>;
160
- interface MappedHKT<T, F extends HKT<T[StrKey<T>]>> extends HKT<StrKey<T>> {
161
- readonly out: App<F, T[I<StrKey<T>, this>]>;
162
- }
163
- interface MergeHKT<T, V, F1 extends HKT<StrKey<Omit<T, No>>>, F2 extends HKT<StrKey<V>>, No extends keyof V = never> extends HKT<StrKey<V & Omit<T, No>>> {
164
- readonly out: I<StrKey<V & Omit<T, No>>, this> extends StrKey<V> ? App<F2, I<StrKey<V>, this>> : App<F1, I<StrKey<Omit<T, No>>, this>>;
165
- }
166
-
167
- declare const AccumulatorRaw: unique symbol;
168
- interface AccumulatorRaw<in Doc, out T, in C = unknown> extends RawObj {
169
- [Type](_: typeof AccumulatorRaw, source: Doc, ctx: C): readonly [typeof AccumulatorRaw, T];
170
- }
171
- interface AccumulatorHKT<T, C = unknown> extends HKT<unknown> {
172
- readonly out: Accumulator<T, I<unknown, this>, C>;
173
- }
174
- type Accumulators<T, V extends RORec<string, jsonItem>, C = unknown> = Exact<V, AccumulatorHKT<T, C>>;
175
- interface DeltaAccumulatorHKT<T, C = unknown> extends HKT<unknown> {
176
- readonly out: DeltaAccumulator<T, I<unknown, this>, C>;
177
- }
178
- type DeltaAccumulators<T, V extends RORec<string, jsonItem>, C = unknown> = Exact<V, DeltaAccumulatorHKT<T, C>>;
179
- declare const Accumulator: unique symbol;
180
- type Accumulator<in Doc, out T, in Ctx = unknown> = {
181
- [Type]?(_: typeof Accumulator): typeof Accumulator;
182
- raw: {
183
- <DeltaD extends O, I extends U>(f: Field<DeltaD, Doc | Undef<I>>): AccumulatorRaw<T | I, DeltaD, Ctx>;
184
- };
185
- };
186
- type Part<Doc> = Rec<'v', Doc> & RORec<'old', boolean>;
187
- type DeltaAccumulator<in out Doc, in out T, in out Ctx = unknown> = {
188
- group: Accumulator<Part<Doc>, T, Ctx>;
189
- merge: <D, C = Ctx>(a: Expr<T | N, D, C>, b: Expr<T, D, C>) => Expr<T, D, C>;
190
- };
191
-
192
- declare const concat: {
193
- <D, C>(...expr: Expr<string, D, C>[]): Expr<string, D, C>;
194
- <D, C>(...expr: Expr<string | N, D, C>[]): Expr<string | N, D, C>;
195
- };
196
- declare const regex: <D, C>(expr: Expr<string, D, C>, regex: Expr<string, D, C>, options?: Expr<string, D, C>) => Expr<boolean, D, C>;
197
- declare const str: <D, C>(expr: Expr<unknown, D, C>) => Expr<string, D, C>;
198
- declare const toInt: <D, C>(expr: Expr<unknown, D, C>) => Expr<number, D, C>;
199
- declare const fieldM: <M extends RORec<Dom, Ref>, T extends RORec<Ref, unknown>, D, Dom extends string = StrKey<M>, Ref extends string = StrKey<T>, C = unknown>(expr: { readonly [K in Ref]: Expr<T[K], D, C>; }, m: Pick<M, Dom>) => Expr<O<{ readonly [K in Dom]: T[M[K]]; }>, D, C>;
200
- type Exprs<out T, in D, in C = unknown> = {
201
- readonly [K in StrKey<T>]: Expr<T[K], D, C>;
202
- };
203
- declare const mergeExact: <T1, T2, F extends HKT<T1[StrKey<T1>] | T2[StrKey<T2>]>, E = unknown>(exprsExact1: Exact<Omit<T1, keyof T2>, F>, exprsExact2: Exact<T2, F>) => Exact<T2 & Omit<T1, keyof T2> & Pick<E, symbol & keyof E>, F>;
204
- type MergeMapOArgs<T1, T2, F1 extends HKT<StrKey<Omit<T1, StrKey<T2>>>>, F2 extends HKT<StrKey<T2>>> = readonly [MapO<Omit<T1, StrKey<T2>>, F1>, MapO<T2, F2>];
205
- declare const mergeExact0: <T1, T2, F1 extends HKT<StrKey<Omit<T1, StrKey<T2>>>>, F2 extends HKT<StrKey<T2>>, E = unknown>(exprsExact1: MapO<Omit<T1, StrKey<T2>>, F1>, exprsExact2: MapO<T2, F2>) => MapO<T2 & Omit<T1, StrKey<T2>> & Pick<E, symbol & keyof E>, MergeHKT<T1, T2, F1, F2, StrKey<T2>>>;
206
- declare const mergeExpr: <T1, T2, D, C = unknown, E = unknown>(exprs_0: Exact<Omit<T1, keyof T2>, ExprHKT<D, C, IdHKT<unknown>>>, exprs_1: Exact<T2, ExprHKT<D, C, IdHKT<unknown>>>) => ExprsExact<T2 & Omit<T1, keyof T2> & Pick<E, symbol & keyof E>, D, C>;
207
- type ExprsPart<T, D, C> = ExactPart<T, ExprHKT<D, C>>;
208
- interface ExprHKT<D, C = unknown, F extends HKT = IdHKT> extends HKT<unknown> {
209
- readonly out: Expr<App<F, I<unknown, this>>, D, C>;
210
- }
211
- type ExprsExact<T, D, C = unknown, F extends HKT = IdHKT> = Exact<T, ExprHKT<D, C, F>>;
212
- interface ExprsExactHKT<E, D, C = unknown, F extends HKT = IdHKT> extends HKT {
213
- readonly out: ExprsExact<E & I<unknown, this>, D, C, F>;
214
- }
215
- declare const pair: <T, D, C, P extends StrKey<T>>(k: P, v: Expr<T[P], D, C>) => ExprsExact<T, D, C>[P];
216
- declare const fieldF: <F extends HKT>() => <T extends object, D, C = unknown>(exprs: ExprsExact<T, D, C, F>) => Expr<O<{ [K in keyof T]: App<F, T[K]>; }>, D, C>;
217
- declare const field: <T extends object, D, C = unknown>(exprs: ExprsExact<T, D, C>) => Expr<O<T>, D, C>;
218
-
219
- declare const Type: unique symbol;
220
-
221
- type U = undefined;
222
- type N = null | U;
223
- type jsonPrim = number | null | string | boolean | Timestamp | MaxKey | Date;
224
- type notObj = jsonPrim | U;
225
- type notArr = notObj | O;
226
- type jsonItem = unknown;
227
- type rawItem = jsonPrim | raw | U;
228
- type Undef<I extends N> = I | (I extends never ? I : notObj);
229
- declare const object: unique symbol;
230
- declare const array$1: unique symbol;
231
- type A = {
232
- [Type]: typeof array$1;
233
- };
234
- type Arr<T, N extends number = number> = A & {
235
- readonly [_ in N]: T;
236
- };
237
- type Obj = {
238
- [Type]: typeof object;
239
- };
240
- type O<T = unknown> = Obj & T;
241
- type RORec<K extends keyof never, T = unknown> = {
242
- readonly [P in K]: T;
243
- };
244
- type Rec<K extends string, T = unknown> = O<RORec<K, T>>;
245
- type O2 = readonly [O, O];
246
- type O3 = readonly [O, O, O];
247
- type ID = {
248
- readonly _id: string;
249
- };
250
- type doc = O & ID;
251
- interface RawObj {
252
- readonly [_: string]: rawItem | U;
253
- }
254
- type raw = readonly rawItem[] | RawObj;
255
- type StrKey<T> = string & keyof T;
256
- type Replace<R, V> = Omit<R, StrKey<V>> & V & O;
257
- type AsLiteral<T extends keyof any | boolean, V = NoUnion<T>> = T extends keyof any ? {} extends {
258
- [K in T]: 1;
259
- } ? never : V : V;
260
- type NoUnion<T, V = T> = T extends unknown ? ([V] extends [T] ? T : never) : never;
261
-
262
- interface HKT<in Dom = unknown, out Im = unknown> {
263
- readonly in: (x: Dom) => void;
264
- readonly out: Im;
265
- }
266
- type App<F extends HKT<X>, X> = (F & {
267
- readonly in: (x: X) => void;
268
- })['out'];
269
- type I<Dom, F extends HKT<Dom>> = F['in'] extends (x: infer X extends Dom) => void ? X : never;
270
- interface IdHKT<Dom = unknown> extends HKT<Dom> {
271
- readonly out: I<Dom, this>;
272
- }
273
- type AppMap<F extends HKT<Dom>, X extends readonly Dom[], Dom = unknown> = readonly App<F, Dom>[] & {
274
- [I in keyof X]: App<F, X[I]>;
275
- };
276
- type AppMapRW<F extends HKT<Dom>, X extends readonly Dom[], Dom = unknown> = App<F, Dom>[] & {
277
- [I in keyof X]: App<F, X[I]>;
278
- };
279
- interface PromiseHKT<Dom = unknown> extends HKT<Dom> {
280
- readonly out: PromiseLike<I<Dom, this>>;
281
- }
282
-
283
- type AsNum<R> = R extends `${infer A extends number}` ? A : never;
284
- type GetDom<Dom = unknown> = readonly [readonly Dom[], keyof any];
285
- declare global {
286
- type Entry<T, K extends keyof T = keyof T> = readonly [string, T[string & K]] & {
287
- [k in K]: readonly [string & k, T[k]];
288
- }[K];
289
- interface ObjectConstructor {
290
- entries<T, _ = 0>(object?: T): readonly Entry<T>[];
291
- fromEntries<T, _ = 0>(entries: readonly Entry<T>[]): T;
292
- keys<T, _ extends 1>(obj: T): readonly StrKey<T>[];
293
- }
294
- interface ReadonlyArray<T> {
295
- includes<T, V extends T>(this: ReadonlyArray<V>, item: T, fromIndex?: number): item is V;
296
- map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[];
297
- map<K extends string, T extends RORec<K>, U extends RORec<K>, _ extends 2 = 2>(this: readonly Entry<T, K>[], callbackfn: <P extends K>(value: [P, T[P]], index: number, array: this) => readonly [P, U[P]], thisArg?: any): readonly Entry<U, K>[];
298
- map<V extends ReadonlyArray<unknown>, F extends HKT<unknown>, G extends HKT<unknown>, _ extends 1 = 1>(this: AppMap<F, V>, callbackfn: <I extends keyof V>(value: App<F, V[I]>, index: AsNum<I>, array: V) => App<G, V[I]>, thisArg?: any): AppMapRW<G, V>;
299
- reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
300
- reduce<V extends ReadonlyArray<unknown>, F extends HKT, U>(this: AppMap<F, V>, callbackfn: <I extends keyof V>(previousValue: U, currentValue: App<F, V[I]>, currentIndex: AsNum<I>, array: V) => U, initialValue: U): U;
301
- map<V extends ReadonlyArray<Dom>, F extends HKT<Dom>, G extends HKT<GetDom<Dom>>, Dom = unknown, _ extends 0 = 0>(this: AppMap<F, V, Dom>, callbackfn: <I extends keyof V>(value: App<F, V[I] & Dom>, index: AsNum<I>, array: V) => App<G, [V, I]>, thisArg?: any): AppMapRW<G, {
302
- [I in keyof V]: [V, I];
303
- }, GetDom<Dom>>;
304
- }
305
- interface Array<T> extends ReadonlyArray<T> {
306
- includes<T, V extends T>(this: ReadonlyArray<V>, item: T, fromIndex?: number): item is V;
307
- map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[];
308
- map<K extends string, T extends RORec<K>, U extends RORec<K>, _ extends 2 = 2>(this: readonly Entry<T, K>[], callbackfn: <P extends K>(value: [P, T[P]], index: number, array: this) => readonly [P, U[P]], thisArg?: any): readonly Entry<U, K>[];
309
- map<V extends ReadonlyArray<unknown>, F extends HKT<unknown>, G extends HKT<unknown>, _ extends 1 = 1>(this: AppMap<F, V>, callbackfn: <I extends keyof V>(value: App<F, V[I]>, index: AsNum<I>, array: V) => App<G, V[I]>, thisArg?: any): AppMapRW<G, V>;
310
- reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
311
- reduce<V extends ReadonlyArray<unknown>, F extends HKT, U>(this: AppMap<F, V>, callbackfn: <I extends keyof V>(previousValue: U, currentValue: App<F, V[I]>, currentIndex: AsNum<I>, array: V) => U, initialValue: U): U;
312
- map<V extends ReadonlyArray<Dom>, F extends HKT<Dom>, G extends HKT<GetDom<Dom>>, Dom = unknown, _ extends 0 = 0>(this: AppMap<F, V, Dom>, callbackfn: <I extends keyof V>(value: App<F, V[I] & Dom>, index: AsNum<I>, array: V) => App<G, [V, I]>, thisArg?: any): AppMapRW<G, {
313
- [I in keyof V]: [V, I];
314
- }, GetDom<Dom>>;
315
- }
316
- interface PromiseConstructor {
317
- all<T extends readonly unknown[] | []>(values: AppMap<PromiseHKT, T>): Promise<T>;
318
- race<T extends readonly unknown[] | [], _ extends 0 = 0>(values: AppMap<PromiseHKT, T>): Promise<T[number]>;
319
- all<T extends readonly unknown[] | []>(values: T): Promise<{
320
- -readonly [P in keyof T]: Awaited<T[P]>;
321
- }>;
322
- race<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
323
- }
324
- }
325
- declare module 'synchronous-promise' {
326
- interface SynchronousPromiseConstructor {
327
- any<T extends readonly unknown[] | [], _ extends 0 = 0>(values: AppMap<PromiseHKT, T>): SynchronousPromise<T[number]>;
328
- any<T extends readonly unknown[] | []>(values: T): SynchronousPromise<Awaited<T[number]>>;
329
- }
330
- }
331
-
332
- declare const RawStage: unique symbol;
333
- declare module 'mongodb' {
334
- interface Collection<TSchema extends BSON.Document = BSON.Document> {
335
- [RawStage]: {
336
- (_: 2): TSchema;
337
- (_: 1, x: TSchema): TSchema;
338
- };
339
- s: {
340
- db: Db;
341
- };
342
- }
343
- interface Db {
344
- s: {
345
- client?: MongoClient;
346
- };
347
- client: MongoClient;
348
- }
349
- interface Timestamp {
350
- toExtendedJSON(): BSON.TimestampExtended;
351
- }
352
- }
353
-
354
- interface CommonCollection {
355
- readonly s: {
356
- readonly db: Db;
357
- };
358
- collectionName: string;
359
- namespace: string;
360
- dbName: string;
361
- createIndex: Collection['createIndex'];
362
- }
363
- interface ReadonlyCollection<out Out> extends CommonCollection {
364
- [RawStage](_: 2): Out;
365
- }
366
- interface WriteonlyCollection<in R> extends CommonCollection {
367
- [RawStage]: {
368
- (_: 1, x: R): unknown;
369
- };
370
- }
371
- interface RWCollection<in R extends O, out Out extends O = R> extends CommonCollection {
372
- [RawStage](_: 2): Out;
373
- [RawStage](_: 1, x: R): unknown;
374
- }
375
- type OPick<V, K extends StrKey<V>, E extends StrKey<V> = never> = O & Pick<V, K | E>;
376
- type OPickD<V extends Model, K extends StrKey<V>> = OPick<V, K, 'deletedAt' | '_id'>;
377
- type View<V extends Model, K extends StrKey<V>> = {
378
- collection: ReadonlyCollection<V | Del>;
379
- projection: ExactKeys<K> | null;
380
- match?: Expr<boolean, OPickD<V, K>>;
381
- hardMatch?: Query<V>;
382
- };
383
-
384
- declare const val: <T extends rawItem>(val: T) => Expr<T, unknown>;
385
- declare const current: Expr<Timestamp, unknown>;
386
- declare const $let: <T, D, C, V extends RORec<string, jsonItem>>(vars: ExprsExact<V, D, C>, inExpr: Expr<T, D, C & V>) => Expr<T, D, C>;
387
- declare const nil: Expr<null, unknown>;
388
- declare const $getField: {
389
- <T, K extends StrKey<T>, D, C = unknown>(expr: Expr<T, D, C>, field: K): Expr<T[K], D, C>;
390
- <T, K extends StrKey<T>, D, C = unknown>(expr: Expr<T | N, D, C>, field: K): Expr<T[K] | null, D, C>;
391
- };
392
- type NoRaw<T> = T extends Arr<infer U> ? NoRaw<U>[] : T extends readonly unknown[] ? {
393
- [K in keyof T]: NoRaw<T[K]>;
394
- } : T extends O ? {
395
- [K in StrKey<T>]: NoRaw<T[K]>;
396
- } : T;
397
- type RONoRaw<T> = T extends Arr<infer U> ? readonly RONoRaw<U>[] : T extends readonly unknown[] ? {
398
- readonly [K in keyof T]: RONoRaw<T[K]>;
399
- } : T extends O ? {
400
- readonly [K in StrKey<T>]: RONoRaw<T[K]>;
401
- } : T;
402
- declare const func: <T extends jsonItem, A extends readonly jsonItem[], D, C = unknown>(f: (...args: NoRaw<A>) => RONoRaw<T>, ...args: { [X in keyof A]: Expr<A[X], D, C>; }) => Expr<T, D, C>;
403
- declare const rand: () => string;
404
- declare const $rand: Expr<string, unknown, unknown>;
405
-
406
- declare const $sum: <D extends O, C = unknown>(expr: Expr<number | N, D, C>) => DeltaAccumulator<D, number, C>;
407
- 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>;
408
- declare const $countDict: <D extends O, C = unknown>(expr: Expr<string, D, C>) => DeltaAccumulator<D, Rec<string, number>, C>;
409
- 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>;
410
- declare const $keys: <D extends O, C = unknown>(expr: Expr<Rec<string, number>, D, C>) => Expr<Arr<string>, D, C>;
411
- 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>;
412
-
413
- type MergeInto<T extends O, Out extends O, E = unknown> = {
414
- whenNotMatched: 'insert';
415
- into: RWCollection<T, Out> & E;
416
- } | {
417
- whenNotMatched: 'discard' | 'fail';
418
- into: ReadonlyCollection<Out> & E;
419
- };
420
- type MergeArgs<T extends O, Out extends O, Ctx, In extends O> = {
421
- on: Field<T, jsonItem> & Field<Out, jsonItem>;
422
- } & MergeInto<T, Out> & (({
423
- stages?: never;
424
- } & ({
425
- whenMatched: 'keepExisting' | 'fail';
426
- } | {
427
- whenMatched: 'replace';
428
- into: RWCollection<T, Out>;
429
- } | {
430
- whenMatched: 'merge';
431
- into: RWCollection<Replace<Out, T>, Out>;
432
- })) | {
433
- stages: true;
434
- into: RWCollection<In, Out>;
435
- whenMatched: RawStages<unknown, Out, In, {
436
- new: T;
437
- }>;
438
- } | {
439
- stages: 'ctx';
440
- vars: ExprsExact<Ctx, T>;
441
- into: RWCollection<In, Out>;
442
- whenMatched: RawStages<unknown, Out, In, Ctx>;
443
- });
444
- 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>;
445
- 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>;
446
-
447
- type GI$1<GG> = Exclude<GG, keyof TS>;
448
- type IdAndTsKeys = keyof (TS & ID);
449
- type V<VV, GG extends string> = Omit<VV, IdAndTsKeys | GI$1<GG>>;
450
- type Prepare<Grp, GG extends string> = TS & ID & Rec<GI$1<GG>, Grp>;
451
- type Par<T> = {
452
- [P in keyof T]?: T[P] | null;
453
- };
454
- type Loose<Grp, VV, GG extends string> = Prepare<Grp, GG> & Par<V<VV, GG>>;
455
- type Strict<Grp, VV, GG extends string, EE> = Prepare<Grp, GG> & V<VV, GG> & Omit<EE, IdAndTsKeys | GI$1<GG> | keyof V<VV, GG>>;
456
- type V_Grp<VV, GG extends string, Grp> = Rec<GI$1<GG>, Grp> & V<VV, GG>;
457
- type Extra<EE, VV, GG extends string> = Omit<EE, IdAndTsKeys | GI$1<GG> | keyof V<VV, GG>>;
458
- type OrReplace<T, V> = T | Replace<T, V>;
459
- 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>>;
460
-
461
- type Denied<GID = never> = keyof (TS & ID) | GID;
462
- type GI<GG> = Exclude<GG, keyof TS>;
463
- 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">;
464
- 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">;
465
- 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">;
466
-
467
- type Params<As extends string, LQ extends O, RQ extends O, RE extends RQ, S extends notArr> = {
468
- localField: Field<LQ, S>;
469
- foreignField: Field<RQ, S>;
470
- from: SnapshotStreamExecutionResult<RQ, RE>;
471
- as: AsLiteral<As>;
472
- };
473
- 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>>;
474
- 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>>;
475
-
476
- declare const $matchDelta: <T extends doc>(query: Expr<boolean, T>) => RawStages<unknown, Delta<T>, Delta<T>, unknown, number>;
477
-
478
- declare const $match: <T extends doc>(query: Expr<boolean, T>) => DeltaStages<T, T, T>;
479
-
480
- declare const Updater: unique symbol;
481
- type Updater<in R, in T, out V, in C = unknown> = {
482
- [Type]?(x: typeof Updater, r: R, t: T, c: C): V;
483
- readonly raw: <D extends O>(f: Field<D, R | N>) => readonly (readonly [string, rawItem])[];
484
- };
485
- interface UpdaterHKT<R, Old, V, C, K extends keyof Old = keyof Old, V2 extends V = V> extends HKT<StrKey<V>> {
486
- readonly out: Updater<R, Get<Old, I<StrKey<V>, this>, K>, V2[I<StrKey<V>, this>], C>;
487
- }
488
- type Get<T, P extends string, K extends keyof T = never> = P extends K ? T[P] : P extends keyof T ? T[P] : undefined;
489
- declare const set: <V>() => <R, Old extends notArr, C = unknown, K extends keyof Old = never>(fields: MapO<V, UpdaterHKT<R, Old, V, C, K>>) => Updater<R, Old, O & Omit<Old, StrKey<V>> & V, C> & Updater<R, Arr<Old>, Arr<Omit<Old, StrKey<V>> & V>, C>;
490
- declare const to: <R, V, C = unknown, T = unknown>(expr: Expr<V, R, C>) => Updater<R, T, V, C>;
491
-
492
- 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>;
493
- declare const $replaceWith: <T extends O, V extends O>(expr: Expr<V, T>) => DeltaStages<O, T, V> & LinStages<O, T, V>;
494
-
495
- type s$1 = string;
496
- declare const $unwindDelta: <K1 extends s$1, T extends doc, K2 extends s$1, U extends doc, N1 extends null = never, N2 extends null = never>(k1: AsLiteral<K1>, k2: AsLiteral<K2>, k: K1 | K2 | false, middle?: string, includeNull1?: N1, includeNull2?: N2) => RawStages<Delta<Rec<K1, T | N1>>, Delta<Rec<K1, T | N1> & Rec<K2, Arr<U>>>, Delta<Rec<K1, T | N1> & Rec<K2, U | N2> & ID>>;
497
-
498
- type s = string;
499
- type TOf<TT, K extends string> = doc & Omit<TT, K>;
500
- declare const $unwind: <TT extends O, K extends s, U extends doc>(k: AsLiteral<K>, dict: RORec<K, "key"> & RORec<"_id", "id">, middle?: string) => DeltaStages<O, TOf<TT, K> & Rec<K, Arr<U>>, TOf<TT, K> & Rec<K, U>>;
501
-
502
- type OutInputE<T, E, A = T | null> = ID & Rec<'after', A> & E;
503
- type Allowed$2<K extends string> = Exclude<K, keyof (TS & ID)>;
504
- type Patch<V, KK extends StrKey<V> = StrKey<V>> = ((OPick<V, Allowed$2<KK>> & ID) | (Rec<Allowed$2<KK>, N> & ID)) & TS;
505
- type TakeDoc<V, E = ID, KK extends StrKey<V> = StrKey<V>> = OPick<V, Allowed$2<KK>> & E;
506
- type ND$1 = {
507
- readonly deletedAt?: null;
508
- };
509
- type SafeE$1<E> = Omit<E, `$${string}` | keyof ID>;
510
- declare const getWhenMatchedForMerge: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert") => RawStages<O, Out, Out | Replace<Out, P>, RORec<"new", Replace<P, RORec<K, Timestamp>>>>;
511
- declare const getWhenMatched: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert") => RawStages<O, Rec<"old" | "merged", Out | Replace<Out, P>>, Out | Replace<Out, P>>;
512
- type MergeCollection<V extends O, Out extends Model> = {
513
- coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
514
- whenNotMatched: 'discard';
515
- } | {
516
- coll: RWCollection<Out | Replace<Out, Patch<V>>, Out>;
517
- whenNotMatched: 'fail';
518
- };
519
- 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">;
520
- 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">;
521
- 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">;
522
- 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">;
523
- 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">;
524
-
525
- type ND = {
526
- readonly deletedAt?: null;
527
- };
528
- type SafeE<E> = Omit<E, `$${string}` | keyof ID>;
529
- type Merge<T extends doc, E> = Omit<SafeE<E>, keyof (ND & TS)> & ((T & ND & TS) | Del);
530
- 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">;
531
- declare const $simpleInsert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<T, "out">;
532
- 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">;
533
- declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
534
-
535
- declare const log: (...args: unknown[]) => void;
536
-
537
- declare const createIndex: (collection: {
538
- readonly createIndex: Collection["createIndex"];
539
- collectionName: string;
540
- }, indexSpec: IndexSpecification, op?: CreateIndexesOptions) => Promise<void>;
541
-
542
- declare const noop: () => void;
543
- declare const map1: <K extends string, Im>(k: AsLiteral<K>, to: Im) => { readonly [P in K]: [P, Im]; } & {
544
- readonly [_: string]: [K, Im];
545
- };
546
-
547
- 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>;
548
-
549
- type DeltaPipe<Q extends O, T extends Q, F extends HKT<O2>, G extends HKT<O3>> = {
550
- 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>;
551
- then: <Q2 extends O, V extends Q2>(next: App<G, [Q2 | T, T, V]>) => DeltaPipe<Q | Q2, V, F, G>;
552
- get: () => App<F, [Q, T]>;
553
- };
554
-
555
- type AllowedPick$1<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed$1<K>>;
556
- type Allowed$1<K> = Exclude<K, 'deletedAt' | '_id'>;
557
-
558
- interface SnapshotStreamHKT extends HKT<O2> {
559
- readonly out: SnapshotStreamExecutionResult<I<O2, this>[0], I<O2, this>[1]>;
560
- }
561
- interface DeltaHKT extends HKT<O3> {
562
- readonly out: DeltaStages<I<O3, this>[0], I<O3, this>[1], I<O3, this>[2]>;
563
- }
564
- declare const staging: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed$1<KK>> & {
565
- needs?: Partial<Record<KK, 0 | 1>>;
566
- }, streamName: string, skip?: boolean, after?: () => Promise<void>) => DeltaPipe<AllowedPick$1<V, KK>, AllowedPick$1<V, KK>, SnapshotStreamHKT, DeltaHKT>;
567
-
568
- type Allowed<K> = Exclude<K, 'deletedAt' | '_id'>;
569
- type AllowedPick<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed<K>>;
570
- interface StreamRunnerHKT extends HKT<O2> {
571
- readonly out: SimpleStreamExecutionResult<I<O2, this>[0], I<O2, this>[1]>;
572
- }
573
- interface StagesHKT extends HKT<O3> {
574
- readonly out: RORec<'lin', RawStages<I<O3, this>[0], I<O3, this>[1], I<O3, this>[2], unknown, 1>>;
575
- }
576
- declare const from: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed<KK>>, streamName: string, needs?: Partial<Record<KK, 0 | 1>>) => DeltaPipe<AllowedPick<V, KK>, AllowedPick<V, KK>, StreamRunnerHKT, StagesHKT>;
577
-
578
- type SingleResult<out Result> = <Result2>(finalInput: RawStages<unknown, Result, Result2>) => Stages<unknown, Result2, unknown>;
579
- interface SnapshotStreamHKT2 extends HKT<O2> {
580
- readonly out: SingleResult<I<O2, this>[1]>;
581
- }
582
- declare const single: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed$1<KK>>, needs?: Partial<Record<KK, 0 | 1>>) => DeltaPipe<AllowedPick$1<V, KK>, AllowedPick$1<V, KK>, SnapshotStreamHKT2, DeltaHKT>;
583
-
584
- declare const max: <D, C>(...expr: Expr<number, D, C>[]) => Expr<number, D, C>;
585
- declare const lt: {
586
- <D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
587
- <D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
588
- };
589
- declare const gt: {
590
- <D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
591
- <D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
592
- };
593
- declare const lte: {
594
- <D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
595
- <D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
596
- };
597
- declare const gte: {
598
- <D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
599
- <D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
600
- };
601
- type Num = number | null | undefined;
602
- declare function subtract<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
603
- declare function subtract<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
604
- declare function add<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
605
- declare function add<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
606
- declare function divide<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
607
- declare function divide<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
608
- declare function multiply<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
609
- declare function multiply<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
610
- declare function floor<D, C>(expr: Expr<number, D, C>): Expr<number, D, C>;
611
- declare function floor<D, C>(expr: Expr<Num, D, C>): Expr<Num, D, C>;
612
- declare function ceil<D, C>(expr: Expr<number, D, C>): Expr<number, D, C>;
613
- declare function ceil<D, C>(expr: Expr<Num, D, C>): Expr<Num, D, C>;
614
-
615
- declare const size: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<number, D, C>;
616
- declare const filterDefined: <T, D, C = unknown>(expr: Expr<Arr<T | N>, D, C>) => Expr<Arr<T>, D, C>;
617
- declare const filter: <T, D, K extends string, C = unknown>({ as, cond, expr, limit, }: {
618
- expr: Expr<Arr<T>, D, C>;
619
- as: K;
620
- cond: Expr<unknown, D, C & RORec<K, T>>;
621
- limit?: Expr<number, D, C>;
622
- }) => Expr<Arr<T>, D, C>;
623
- declare const sortArray: <T, D, C, K extends keyof T>({ sortBy, expr, order, }: {
624
- expr: Expr<Arr<T>, D, C>;
625
- sortBy: K;
626
- order?: 1 | -1;
627
- }) => Expr<Arr<T>, D, C>;
628
- declare const isArray: <T extends notArr, D, C, F extends HKT<T | Arr<T>>>(expr: Expr<T | Arr<T>, D & (App<F, T> | App<F, Arr<T>>), C>) => BoolExpr<D & App<F, Arr<T>>, D & App<F, T>, C>;
629
- declare const inArray: <T, D, C>(item: Expr<T, D, C>, expr: Expr<Arr<T>, D, C>) => Expr<boolean, D, C>;
630
- declare const array: <T, D, C = unknown>(...exprs: Expr<T, D, C>[]) => Expr<Arr<T>, D, C>;
631
- declare const concatArray: <T, D, C>(...exprs: Expr<Arr<T>, D, C>[]) => Expr<Arr<T>, D, C>;
632
- declare const first: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>;
633
- declare const firstSure: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T, D, C>;
634
- declare const last: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>;
635
- type NullToOBJ<N extends null> = N extends null ? O : N;
636
- 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>;
637
- declare const anyElementTrue: <D, C = unknown>(expr: Expr<Arr<boolean>, D, C>) => Expr<boolean, D, C>;
638
- type Reduce<T, V> = RORec<'value', V> & RORec<'this', T>;
639
- 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>;
640
- declare const slice: <T, D, C>(array: Expr<Arr<T>, D, C>, start: Expr<number, D, C>, end: Expr<number, D, C>) => Expr<Arr<T>, D, C>;
641
- declare const except: <T, D, C>(a: Expr<Arr<T>, D, C>, b: Expr<Arr<T>, D, C>) => Expr<Arr<T>, D, C>;
642
-
643
- declare const dayAndMonthPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
644
- declare const now: <D, C>() => Expr<Date, D, C>;
645
- declare const monthPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
646
- declare const weekPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
647
- declare const year: <D, C>(date: Expr<Date, D, C>) => Expr<number, D, C>;
648
- declare const dateAdd: <D, C>(date: Expr<Date, D, C>, amount: Expr<number, D, C>, unit: Expr<"year" | "week" | "month" | "day" | "hour" | "minute" | "second", D, C>) => Expr<Date, D, C>;
649
- declare const maxDate: <D, C>(expr: Expr<Arr<Date>, D, C>) => Expr<Date, D, C>;
650
- declare const minDate: <D, C>(expr: Expr<Arr<Date>, D, C>) => Expr<Date, D, C>;
651
- declare const datePart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
652
- declare const startOf: <D, C>(startDate: Expr<Date, D, C>, freq: Expr<"week" | "day" | "month" | "year", D, C>, offset: Expr<number, D, C>) => Expr<Date, D, C>;
653
- declare const dateDiff: <D, C>({ end, unit, start, }: {
654
- start: Expr<Date, D, C>;
655
- end: Expr<Date, D, C>;
656
- unit: Expr<"week" | "day" | "month" | "year", D, C>;
657
- }) => Expr<number, D, C>;
658
-
659
- declare const ite: {
660
- <T, D, C = unknown>(cond: Expr<unknown, D, C>, then: Expr<T, D, C>, orelse: Expr<T, D, C>): Expr<T, D, C>;
661
- <T, R1, R2, F extends HKT<R1 | R2>, C = unknown>(cond: BoolExpr<App<F, R1>, App<F, R2>, C>, then: Expr<T, App<F, R1>, C>, orelse: Expr<T, App<F, R2>, C>): Expr<T, App<F, R1 | R2>, C>;
662
- };
663
- declare const and: <D, C = unknown>(...expr: Expr<boolean, D, C>[]) => Expr<boolean, D, C>;
664
- declare const or: <D, C = unknown>(...expr: Expr<boolean, D, C>[]) => Expr<boolean, D, C>;
665
- declare const not: <D, C = unknown>(expr: Expr<boolean, D, C>) => Expr<boolean, D, C>;
666
- declare const eq: <T, D, C = unknown>(a: Expr<T, D, C>) => (b: Expr<T, D, C>) => Expr<boolean, D, C>;
667
- declare const sub: <T, D, Ctx, P extends O>(a: Expr<T, D, Ctx>, f: Field<P, D, Ctx>) => Expr<T, P, Ctx>;
668
- declare const eqTyped: <T1 extends Dom, T2 extends Dom, F extends HKT<Dom>, C = unknown, Dom = unknown>(a: Expr<T1 | T2, App<F, T1 | T2>, C>, b: Expr<T1, App<F, T1 | T2>, C>) => BoolExpr<App<F, T1>, App<F, T2>, C>;
669
- declare const ne: <T, D, C>(a: Expr<T, D, C>) => <K>(b: Expr<K, D, C>) => Expr<boolean, D, C>;
670
- declare const notNull: <T, D, C>(a: Expr<T, D, C>) => Expr<boolean, D, C>;
671
- declare const $ifNull: <R, D, C>(...expr: [...Expr<R | null | undefined, D, C>[], Expr<R, D, C>]) => Expr<R, D, C>;
672
- declare const exprMapVal: <K extends string, T extends Partial<Record<K, rawItem>>, D, C>(expr: Expr<K, D, C>, map: { readonly [P in K]: Expr<T[P], D, C>; }, or?: Expr<T[K], D, C>) => Expr<T[K & keyof T], D, C>;
673
- declare const mapVal: <K extends string, T extends Partial<Record<K, rawItem>>, D, C>(expr: Expr<K, D, C>, map: T, or: T[K & keyof T]) => Expr<T[K & keyof T], D, C>;
674
- declare const setField: <K extends string, T, V, D, C>({ field, input, value, }: {
675
- field: Expr<K, D, C>;
676
- input: Expr<T, D, C>;
677
- value: Expr<V, D, C>;
678
- }) => Expr<T & Record<K, V>, D, C>;
679
-
680
- declare const range: <D, C>(start: Expr<number, D, C>, end: Expr<number, D, C>, step?: Expr<number, D, C>) => Expr<Arr<number>, D, C>;
681
- declare const $map0: <K extends string, T, R, D, C>({ as, expr, input, }: {
682
- input: Expr<Arr<T>, D, C>;
683
- as: K;
684
- expr: Expr<R, D, RORec<K, T> & C>;
685
- }) => Expr<Arr<R>, D, C>;
686
- declare const $map1: <T, R, D, C>(ex: Expr<Arr<T>, D, C>, map: (i: Field<unknown, T, RORec<"item", T>>) => Expr<R, D, RORec<"item", T> & C>) => Expr<Arr<R>, D, C>;
687
- declare const $map: <T, R, D, C = unknown>(ex: Expr<Arr<T>, D, C>, map: (i: Expr<T, D, RORec<"item", T>>) => Expr<R, D, RORec<"item", T> & C>) => Expr<Arr<R>, D, C>;
688
-
689
- declare class Machine<Result = unknown> {
690
- private sources;
691
- constructor(root?: Iterator<Result, HasJob>);
692
- add(x: Iterator<Result, HasJob>): void;
693
- runner(): Iterator<Result, HasJob>;
694
- start(cb?: (info: HasJob) => void | boolean): Promise<never>;
695
- }
696
- declare const wrap: <Result>(root: Machine<Result>) => Machine<Result>;
697
-
698
- declare const $eq: <T extends unknown>(operand: rawItem & T) => Predicate<T>;
699
- declare const $ne: <T extends unknown>(operand: rawItem & T) => Predicate<T>;
700
- type Numeric = number | Timestamp | Date;
701
- declare const comp: <D2 extends Numeric = Numeric>(op: "$lt" | "$lte" | "$gt" | "$gte") => <T extends Numeric>(operand: rawItem & D2) => Predicate<D2>;
702
- declare const $gt: <T extends Numeric>(operand: rawItem & Numeric) => Predicate<Numeric>;
703
- declare const $gtTs: <T extends Numeric>(operand: rawItem & Timestamp) => Predicate<Timestamp>;
704
- declare const $gteTs: <T extends Numeric>(operand: rawItem & Timestamp) => Predicate<Timestamp>;
705
- declare const $lt: <T extends Numeric>(operand: rawItem & number) => Predicate<number>;
706
- declare const dateLt: <T extends Numeric>(operand: rawItem & Date) => Predicate<Date>;
707
- declare const $gte: <T extends Numeric>(operand: rawItem & number) => Predicate<number>;
708
- declare const $lte: <T extends Numeric>(operand: rawItem & number) => Predicate<number>;
709
- type MongoTypes = {
710
- number: number;
711
- array: readonly rawItem[];
712
- string: string;
713
- object: RawObj;
714
- [i: number]: unknown;
715
- };
716
- type MongoTypeNames = keyof MongoTypes;
717
- declare const $type: <T extends keyof MongoTypes>(operand: rawItem & readonly T[]) => Predicate<N | MongoTypes[T]>;
718
- declare const $exists: <T extends keyof MongoTypes>(operand: rawItem & boolean) => Predicate<unknown>;
719
-
720
- declare const $expr: <D extends O, C>(expr: Expr<boolean, D, C>) => Query<D, C>;
721
-
722
- declare const $in: <T extends unknown>(operand: rawItem & readonly T[]) => Predicate<T>;
723
- declare const $nin: <T extends unknown>(operand: rawItem & readonly T[]) => Predicate<T>;
724
-
725
- type Many<T> = readonly (T | N)[];
726
- type Combiner = {
727
- <T extends O, C = unknown>(first: Query<T, C>, ...args: Many<Query<T, C>>): Query<T, C>;
728
- <T extends O, C = unknown>(...args: Many<Query<T, C>>): Query<T, C> | undefined;
729
- };
730
- declare const $and: Combiner;
731
- declare const $nor: Combiner;
732
- declare const $or: Combiner;
733
-
734
- declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Promise<Document>;
735
- declare const prepare: (testName?: string) => Promise<MongoClient$1>;
736
- declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
737
-
738
- export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, type ExactKeys, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type MongoTypeNames, type N, type NoRaw, type NullToOBJ, type O, type OPick, type OPickD, type Patch, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, type jsonPrim, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, type notArr, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
1
+ export * from './lib/accumulators';
2
+ export * from './lib/aggregate';
3
+ export * from './lib/boot';
4
+ export * from './lib/expression';
5
+ export * from './lib/field';
6
+ export * from './lib/update';
7
+ export * from './lib/machine';
8
+ export * from './lib/predicate';
9
+ export * from './lib/query';
10
+ export * from './lib/utils';
11
+ export * from './lib/types/extern';
12
+ export * from './types/extern';
13
+ export { enablePreAndPostImages, prepare, makeCol } from './test/mongodb';
package/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { MaxKey, UUID, MongoClient } from 'mongodb';
1
+ import { Timestamp, UUID, MongoClient } from 'mongodb';
2
2
  import crypto$1 from 'crypto';
3
3
  import { canonicalize } from 'json-canonicalize';
4
4
  import { SynchronousPromise } from 'synchronous-promise';
@@ -82,7 +82,7 @@ const val = (val) => asExpr({
82
82
  : val),
83
83
  });
84
84
  const current = asExpr({
85
- raw: () => asExprRaw(new MaxKey()),
85
+ raw: () => asExprRaw(new Timestamp(0xffffffffffffffffn)),
86
86
  });
87
87
  const $let = (vars, inExpr) => asExpr({
88
88
  raw: f => asExprRaw({
@@ -1599,6 +1599,8 @@ const addTeardown = (it, tr) => {
1599
1599
  };
1600
1600
 
1601
1601
  const sleep = (ms) => new Promise(r => setTimeout(r, ms));
1602
+ const maxTimestamp = new Timestamp(0xffffffffffffffffn);
1603
+ const isMax = (x) => x instanceof Timestamp && x.equals(maxTimestamp);
1602
1604
  const getCurrentTimestamp = async (db) => {
1603
1605
  const adminDb = db.admin();
1604
1606
  const serverStatus = await adminDb.command({ serverStatus: 1 });
@@ -1641,7 +1643,7 @@ async function* tailOplog(db, opts) {
1641
1643
  if (doc.op === 'i' || '_id' in doc.o) {
1642
1644
  const fields = new Set(Object.keys(doc.o));
1643
1645
  fields.delete('_id');
1644
- yield { fields, doc, changeTouched: doc.o['touchedAt'] instanceof MaxKey };
1646
+ yield { fields, doc, changeTouched: isMax(doc.o['touchedAt']) };
1645
1647
  }
1646
1648
  else {
1647
1649
  let changeTouched = false;
@@ -1653,7 +1655,7 @@ async function* tailOplog(db, opts) {
1653
1655
  for (const updateOp in diff) {
1654
1656
  if (['u', 'i', 'd'].includes(updateOp)) {
1655
1657
  updatedFields.push(...Object.keys(diff[updateOp]));
1656
- if (diff[updateOp]['touchedAt'] instanceof MaxKey) {
1658
+ if (isMax(diff[updateOp]['touchedAt'])) {
1657
1659
  changeTouched = true;
1658
1660
  }
1659
1661
  }
@@ -1767,7 +1769,7 @@ const makeWatchStream = async ({ collection, projection: p, hardMatch: m }, stre
1767
1769
  const { db } = collection.s;
1768
1770
  await (maxKeysRemoved ??= Promise.all((await db.listCollections({}, { nameOnly: true }).toArray()).map(x => void db
1769
1771
  .collection(x.name)
1770
- .updateMany({ touchedAt: new MaxKey() }, [{ $set: { touchedAt: '$$CLUSTER_TIME' } }]))).then(() => { }));
1772
+ .updateMany({ touchedAt: maxTimestamp }, [{ $set: { touchedAt: '$$CLUSTER_TIME' } }]))).then(() => { }));
1771
1773
  const projection = { ...(p ? mapExactToObject(p, v => v) : {}), deletedAt: 1 };
1772
1774
  let resolve = (_) => { };
1773
1775
  const promise = new Promise(r => (resolve = r));
@@ -2002,20 +2004,20 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
2002
2004
  whenMatched: link().with($replaceWith_(ite(eq(root().of('before').expr())(ctx()('new').of('after').expr()), root().expr(), mergeObjects(root().expr(), ctx()('new').expr())))).stages,
2003
2005
  whenNotMatched: 'insert',
2004
2006
  })).stages;
2007
+ const stream = await makeStream();
2005
2008
  const r = await aggregate(pdb, streamName, c => c({ coll: collection, input: cloneIntoNew }));
2006
2009
  const start = Date.now();
2007
2010
  const res = await snapshotCollection.deleteMany({ updated: true, after: null, before: null });
2008
2011
  log('deleting from cloned into new collection', Date.now() - start, res, `db['${snapshotCollection.collectionName}'].deleteMany({ updated: true, after: null, before: null })`);
2009
- return next(step4({ result: r, ts: lastTS?.ts }), 'run the aggregation');
2012
+ return next(step4({ result: r, ts: lastTS?.ts, stream }), 'run the aggregation');
2010
2013
  };
2011
2014
  const makeStream = () => makeWatchStream(view, streamName);
2012
- const step4 = ({ result, ts }) => async () => {
2015
+ const step4 = ({ result, ts, stream }) => async () => {
2013
2016
  const start = Date.now();
2014
2017
  log('snapshot', streamName, 'ensure before null', Date.now() - start);
2015
2018
  const first = ts === undefined;
2016
2019
  const stages = finalInput.raw(first);
2017
2020
  await last.updateOne({ _id: streamName }, { $set: { job: 1 } }, { upsert: true });
2018
- const stream = await makeStream();
2019
2021
  const nextRes = stream.tryNext();
2020
2022
  const aggResult = await aggregate(pdb, streamName, c => c({
2021
2023
  coll: snapshotCollection,
package/index.js CHANGED
@@ -84,7 +84,7 @@ const val = (val) => asExpr({
84
84
  : val),
85
85
  });
86
86
  const current = asExpr({
87
- raw: () => asExprRaw(new mongodb.MaxKey()),
87
+ raw: () => asExprRaw(new mongodb.Timestamp(0xffffffffffffffffn)),
88
88
  });
89
89
  const $let = (vars, inExpr) => asExpr({
90
90
  raw: f => asExprRaw({
@@ -1601,6 +1601,8 @@ const addTeardown = (it, tr) => {
1601
1601
  };
1602
1602
 
1603
1603
  const sleep = (ms) => new Promise(r => setTimeout(r, ms));
1604
+ const maxTimestamp = new mongodb.Timestamp(0xffffffffffffffffn);
1605
+ const isMax = (x) => x instanceof mongodb.Timestamp && x.equals(maxTimestamp);
1604
1606
  const getCurrentTimestamp = async (db) => {
1605
1607
  const adminDb = db.admin();
1606
1608
  const serverStatus = await adminDb.command({ serverStatus: 1 });
@@ -1643,7 +1645,7 @@ async function* tailOplog(db, opts) {
1643
1645
  if (doc.op === 'i' || '_id' in doc.o) {
1644
1646
  const fields = new Set(Object.keys(doc.o));
1645
1647
  fields.delete('_id');
1646
- yield { fields, doc, changeTouched: doc.o['touchedAt'] instanceof mongodb.MaxKey };
1648
+ yield { fields, doc, changeTouched: isMax(doc.o['touchedAt']) };
1647
1649
  }
1648
1650
  else {
1649
1651
  let changeTouched = false;
@@ -1655,7 +1657,7 @@ async function* tailOplog(db, opts) {
1655
1657
  for (const updateOp in diff) {
1656
1658
  if (['u', 'i', 'd'].includes(updateOp)) {
1657
1659
  updatedFields.push(...Object.keys(diff[updateOp]));
1658
- if (diff[updateOp]['touchedAt'] instanceof mongodb.MaxKey) {
1660
+ if (isMax(diff[updateOp]['touchedAt'])) {
1659
1661
  changeTouched = true;
1660
1662
  }
1661
1663
  }
@@ -1769,7 +1771,7 @@ const makeWatchStream = async ({ collection, projection: p, hardMatch: m }, stre
1769
1771
  const { db } = collection.s;
1770
1772
  await (maxKeysRemoved ??= Promise.all((await db.listCollections({}, { nameOnly: true }).toArray()).map(x => void db
1771
1773
  .collection(x.name)
1772
- .updateMany({ touchedAt: new mongodb.MaxKey() }, [{ $set: { touchedAt: '$$CLUSTER_TIME' } }]))).then(() => { }));
1774
+ .updateMany({ touchedAt: maxTimestamp }, [{ $set: { touchedAt: '$$CLUSTER_TIME' } }]))).then(() => { }));
1773
1775
  const projection = { ...(p ? mapExactToObject(p, v => v) : {}), deletedAt: 1 };
1774
1776
  let resolve = (_) => { };
1775
1777
  const promise = new Promise(r => (resolve = r));
@@ -2004,20 +2006,20 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
2004
2006
  whenMatched: link().with($replaceWith_(ite(eq(root().of('before').expr())(ctx()('new').of('after').expr()), root().expr(), mergeObjects(root().expr(), ctx()('new').expr())))).stages,
2005
2007
  whenNotMatched: 'insert',
2006
2008
  })).stages;
2009
+ const stream = await makeStream();
2007
2010
  const r = await aggregate(pdb, streamName, c => c({ coll: collection, input: cloneIntoNew }));
2008
2011
  const start = Date.now();
2009
2012
  const res = await snapshotCollection.deleteMany({ updated: true, after: null, before: null });
2010
2013
  log('deleting from cloned into new collection', Date.now() - start, res, `db['${snapshotCollection.collectionName}'].deleteMany({ updated: true, after: null, before: null })`);
2011
- return next(step4({ result: r, ts: lastTS?.ts }), 'run the aggregation');
2014
+ return next(step4({ result: r, ts: lastTS?.ts, stream }), 'run the aggregation');
2012
2015
  };
2013
2016
  const makeStream = () => makeWatchStream(view, streamName);
2014
- const step4 = ({ result, ts }) => async () => {
2017
+ const step4 = ({ result, ts, stream }) => async () => {
2015
2018
  const start = Date.now();
2016
2019
  log('snapshot', streamName, 'ensure before null', Date.now() - start);
2017
2020
  const first = ts === undefined;
2018
2021
  const stages = finalInput.raw(first);
2019
2022
  await last.updateOne({ _id: streamName }, { $set: { job: 1 } }, { upsert: true });
2020
- const stream = await makeStream();
2021
2023
  const nextRes = stream.tryNext();
2022
2024
  const aggResult = await aggregate(pdb, streamName, c => c({
2023
2025
  coll: snapshotCollection,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "index.esm.js",
4
4
  "typings": "index.d.ts",
5
5
  "name": "@omegup/msync",
6
- "version": "0.1.24",
6
+ "version": "0.1.26",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",