@omegup/msync 0.1.27 → 0.1.28
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 +684 -13
- package/index.esm.js +11 -20
- package/index.js +11 -20
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,13 +1,684 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { Timestamp, Filter, UpdateFilter, BSON, Db, Collection, IndexSpecification, CreateIndexesOptions, OptionalUnlessRequiredId, MongoClient as MongoClient$1 } from 'mongodb';
|
|
2
|
+
export { Collection, Timestamp } from 'mongodb';
|
|
3
|
+
|
|
4
|
+
declare const Type: unique symbol;
|
|
5
|
+
|
|
6
|
+
type U = undefined;
|
|
7
|
+
type N = null | U;
|
|
8
|
+
type jsonPrim = number | null | string | boolean | Timestamp | Date;
|
|
9
|
+
type notObj = jsonPrim | U;
|
|
10
|
+
type notArr = notObj | O;
|
|
11
|
+
type jsonItem = unknown;
|
|
12
|
+
type rawItem = jsonPrim | raw | U;
|
|
13
|
+
type Undef<I extends N> = I | (I extends never ? I : notObj);
|
|
14
|
+
declare const object: unique symbol;
|
|
15
|
+
declare const array$1: unique symbol;
|
|
16
|
+
type A = {
|
|
17
|
+
[Type]: typeof array$1;
|
|
18
|
+
};
|
|
19
|
+
type Arr<T, N extends number = number> = A & {
|
|
20
|
+
readonly [_ in N]: T;
|
|
21
|
+
};
|
|
22
|
+
type Obj = {
|
|
23
|
+
[Type]: typeof object;
|
|
24
|
+
};
|
|
25
|
+
type O<T = unknown> = Obj & T;
|
|
26
|
+
type RORec<K extends keyof never, T = unknown> = {
|
|
27
|
+
readonly [P in K]: T;
|
|
28
|
+
};
|
|
29
|
+
type Rec<K extends string, T = unknown> = O<RORec<K, T>>;
|
|
30
|
+
type O2 = readonly [O, O];
|
|
31
|
+
type O3 = readonly [O, O, O];
|
|
32
|
+
type ID = {
|
|
33
|
+
readonly _id: string;
|
|
34
|
+
};
|
|
35
|
+
type doc = O & ID;
|
|
36
|
+
interface RawObj {
|
|
37
|
+
readonly [_: string]: rawItem | U;
|
|
38
|
+
}
|
|
39
|
+
type raw = readonly rawItem[] | RawObj;
|
|
40
|
+
type StrKey<T> = string & keyof T;
|
|
41
|
+
type Replace<R, V> = Omit<R, StrKey<V>> & V & O;
|
|
42
|
+
type AsLiteral<T extends keyof any | boolean, V = NoUnion<T>> = T extends keyof any ? {} extends {
|
|
43
|
+
[K in T]: 1;
|
|
44
|
+
} ? never : V : V;
|
|
45
|
+
type NoUnion<T, V = T> = T extends unknown ? ([V] extends [T] ? T : never) : never;
|
|
46
|
+
|
|
47
|
+
type HasJob = {
|
|
48
|
+
job: object | undefined;
|
|
49
|
+
};
|
|
50
|
+
type Runner<T, Info extends HasJob> = Iterator<T, Info>;
|
|
51
|
+
type NextFrame<T, Info> = PromiseLike<Frame<T, Info>>;
|
|
52
|
+
type Frame<T, Info> = {
|
|
53
|
+
data: T;
|
|
54
|
+
info: Info;
|
|
55
|
+
cont: Iterator<T, Info>;
|
|
56
|
+
};
|
|
57
|
+
type IteratorResult<out T, out Info> = {
|
|
58
|
+
next: NextFrame<T, Info>;
|
|
59
|
+
stop: Iterator<T, Info>;
|
|
60
|
+
clear: () => Promise<unknown>;
|
|
61
|
+
};
|
|
62
|
+
type Iterator<out T, out Info> = () => IteratorResult<T, Info>;
|
|
63
|
+
|
|
64
|
+
declare const PredicateRaw: unique symbol;
|
|
65
|
+
type PredicateRaw = RawObj & {
|
|
66
|
+
[Type]?(x: typeof PredicateRaw): void;
|
|
67
|
+
};
|
|
68
|
+
declare const Predicate: unique symbol;
|
|
69
|
+
interface Predicate<in V> {
|
|
70
|
+
[Type]?(x: typeof Predicate, _: V): void;
|
|
71
|
+
raw: PredicateRaw;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare class Field<in R, out V, in C = unknown> {
|
|
75
|
+
private field;
|
|
76
|
+
private raw;
|
|
77
|
+
private concat;
|
|
78
|
+
has<R extends O>(this: Field<R, V>, p: Predicate<V>): Query<R, C>;
|
|
79
|
+
has<R extends O, V>(this: Field<R, Arr<V>>, p: Predicate<V>): Query<R, C>;
|
|
80
|
+
private constructor();
|
|
81
|
+
static root: <T extends O>() => Field<T, T, unknown>;
|
|
82
|
+
static ctx: <T>() => <K extends string>(k: K) => Field<unknown, T, RORec<K, T>>;
|
|
83
|
+
of<V, K extends keyof V, _ extends 0 = 0>(this: Field<R, Arr<V>, C>, k: AsLiteral<K>): Field<R, Arr<V[K]>, C>;
|
|
84
|
+
of<V, K extends keyof V, _ extends 1 = 1>(this: Field<R, O<V>, C>, k: K): Field<R, V[K], C>;
|
|
85
|
+
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>;
|
|
86
|
+
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>;
|
|
87
|
+
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>;
|
|
88
|
+
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>;
|
|
89
|
+
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>;
|
|
90
|
+
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>;
|
|
91
|
+
str(this: Field<R, V>): string;
|
|
92
|
+
private exprRaw;
|
|
93
|
+
expr<R, V, C = unknown>(this: Field<R, V, C>): Expr<V, R, C>;
|
|
94
|
+
}
|
|
95
|
+
declare const root: <T extends O>() => Field<T, T, unknown>;
|
|
96
|
+
declare const ctx: <T>() => <K extends string>(k: K) => Field<unknown, T, RORec<K, T>>;
|
|
97
|
+
|
|
98
|
+
declare const QueryRaw: unique symbol;
|
|
99
|
+
type QueryRaw<T, C = unknown> = RawObj & {
|
|
100
|
+
[Type]?(x: typeof QueryRaw, y: T, c: C): void;
|
|
101
|
+
};
|
|
102
|
+
declare const Query: unique symbol;
|
|
103
|
+
type Query<in T extends O, in C = unknown> = {
|
|
104
|
+
[Type]?(x: typeof Query, y: T, c: C): void;
|
|
105
|
+
raw: <DeltaT extends O>(f: Field<DeltaT, T>) => QueryRaw<DeltaT, C>;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
declare const RawStage$1: unique symbol;
|
|
109
|
+
type RawArr = readonly RawObj[];
|
|
110
|
+
interface RawStages<out Q, in S extends Q, out R extends Q, in C = unknown, out M = number> extends RawArr {
|
|
111
|
+
[Type]?(_: typeof RawStage$1, source: S, ctx: C, q: Q): readonly [typeof RawStage$1, R, M, Q];
|
|
112
|
+
}
|
|
113
|
+
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>;
|
|
114
|
+
type DeltaStages<out Q, in S extends Q & O, out R extends Q & O, in C = unknown> = {
|
|
115
|
+
delta: RawStages<unknown, Delta<S>, Delta<R>, C>;
|
|
116
|
+
raw: FRawStages<Q, S, R, C>;
|
|
117
|
+
};
|
|
118
|
+
type LinStages<out Q, in S extends Q, out R extends Q, in C = unknown> = {
|
|
119
|
+
lin: RawStages<Q, S, R, C, 1>;
|
|
120
|
+
};
|
|
121
|
+
type TStages<in out S, out Q, in out B extends Q, out R extends Q, M extends number = number> = {
|
|
122
|
+
coll: ReadonlyCollection<S>;
|
|
123
|
+
input: RawStages<unknown, S, B, unknown, M>;
|
|
124
|
+
exec: RawStages<Q, B, R, unknown, M>;
|
|
125
|
+
};
|
|
126
|
+
type Stages<out Q, out R extends Q, out SDom> = <E>(consume: <S extends SDom, B extends Q>(value: TStages<S, Q, B, R>) => E) => E;
|
|
127
|
+
type Actions<W> = {
|
|
128
|
+
updateMany: [Filter<W>, UpdateFilter<W> | BSON.Document[]];
|
|
129
|
+
deleteMany: [Filter<W>];
|
|
130
|
+
};
|
|
131
|
+
type TeardownRecord<W, M extends keyof Actions<W>> = {
|
|
132
|
+
collection: WriteonlyCollection<W>;
|
|
133
|
+
method: M;
|
|
134
|
+
params: Actions<W>[M];
|
|
135
|
+
};
|
|
136
|
+
type StreamRunnerParam<in V, out Result> = {
|
|
137
|
+
raw: (first: boolean) => RawStages<unknown, V, Result>;
|
|
138
|
+
teardown: <R>(consume: <W, M extends keyof Actions<W>>(x: TeardownRecord<W, M>) => R) => R;
|
|
139
|
+
};
|
|
140
|
+
type StreamRunner<out V> = <Result>(input: StreamRunnerParam<V, Result>, setup?: () => Promise<void>) => Runner<readonly Result[], HasJob>;
|
|
141
|
+
type SimpleStreamExecutionResult<out Q, out V extends Q> = {
|
|
142
|
+
readonly out: StreamRunner<V>;
|
|
143
|
+
};
|
|
144
|
+
type SnapshotStreamExecutionResult<out Q, out V extends Q> = {
|
|
145
|
+
readonly out: StreamRunner<Delta<V>>;
|
|
146
|
+
readonly stages: Stages<Before<Q>, Before<V>, UBefore<Q>>;
|
|
147
|
+
};
|
|
148
|
+
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]>;
|
|
149
|
+
type TS = {
|
|
150
|
+
readonly touchedAt: Timestamp;
|
|
151
|
+
};
|
|
152
|
+
type IsDeleted = {
|
|
153
|
+
readonly deletedAt: Timestamp;
|
|
154
|
+
};
|
|
155
|
+
type DDel = IsDeleted & ID & TS;
|
|
156
|
+
type Del = O<DDel>;
|
|
157
|
+
type DeletedAt = {
|
|
158
|
+
readonly deletedAt?: Timestamp | null | undefined;
|
|
159
|
+
};
|
|
160
|
+
type D = O<DeletedAt & ID>;
|
|
161
|
+
type Model = D & TS;
|
|
162
|
+
type BA = 'before' | 'after';
|
|
163
|
+
type PreDelta<T, K extends BA = BA, E = unknown> = Rec<K, T> & E;
|
|
164
|
+
type Delta<T, K extends BA = BA, E = ID> = PreDelta<T | null, K, E>;
|
|
165
|
+
type Before<T> = PreDelta<T, 'before'>;
|
|
166
|
+
type UBefore<T> = O & Partial<Delta<T | null, 'before'>>;
|
|
167
|
+
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>;
|
|
168
|
+
|
|
169
|
+
declare const ExprRaw: unique symbol;
|
|
170
|
+
type ExprRaw<out T, in Doc, in Ctx = unknown> = {
|
|
171
|
+
[Type]?(x: typeof ExprRaw): void;
|
|
172
|
+
[ExprRaw]?(doc: Doc, ctx: Ctx): T;
|
|
173
|
+
get: () => rawItem;
|
|
174
|
+
};
|
|
175
|
+
declare const Expr: unique symbol;
|
|
176
|
+
type Expr<out T, in Doc, in Ctx = unknown> = {
|
|
177
|
+
[Type]?(x: typeof Expr): void;
|
|
178
|
+
[Expr]?(doc: Doc, ctx: Ctx): T;
|
|
179
|
+
raw: {
|
|
180
|
+
<DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, Doc | Undef<I>, C>): ExprRaw<T | I, DeltaD, Ctx & C>;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
type BoolExpr<in D1, in D2, in Ctx = unknown> = {
|
|
184
|
+
[Type]?(x: typeof Expr): void;
|
|
185
|
+
[Expr](doc: D1, ctx: Ctx): true;
|
|
186
|
+
[Expr](doc: D2, ctx: Ctx): false;
|
|
187
|
+
raw: {
|
|
188
|
+
<DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, D1 | D2 | Undef<I>, C>): ExprRaw<boolean, DeltaD, Ctx & C>;
|
|
189
|
+
<DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, D1 | Undef<I>, C>): ExprRaw<true, DeltaD, Ctx & C>;
|
|
190
|
+
<DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, D2 | Undef<I>, C>): ExprRaw<false, DeltaD, Ctx & C>;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
type ExactPart<T, F extends HKT<T[StrKey<T>]>> = MapOPart<T, MappedHKT<T, F>>;
|
|
195
|
+
type ExactKeys<K extends string> = Exact<RORec<K, 1>, IdHKT>;
|
|
196
|
+
type MapO<T, F extends HKT<StrKey<T>>> = MapOPart<T, F> & {
|
|
197
|
+
readonly [P: string]: readonly [StrKey<T>, unknown];
|
|
198
|
+
};
|
|
199
|
+
type MapOPart<T, F extends HKT<StrKey<T>>, K extends keyof T = StrKey<T>> = {
|
|
200
|
+
readonly [P in K]: readonly [P, App<F, P & string>];
|
|
201
|
+
};
|
|
202
|
+
type Exact<T, F extends HKT<T[StrKey<T>]>> = MapO<T, MappedHKT<T, F>>;
|
|
203
|
+
interface MappedHKT<T, F extends HKT<T[StrKey<T>]>> extends HKT<StrKey<T>> {
|
|
204
|
+
readonly out: App<F, T[I<StrKey<T>, this>]>;
|
|
205
|
+
}
|
|
206
|
+
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>>> {
|
|
207
|
+
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>>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
declare const AccumulatorRaw: unique symbol;
|
|
211
|
+
interface AccumulatorRaw<in Doc, out T, in C = unknown> extends RawObj {
|
|
212
|
+
[Type](_: typeof AccumulatorRaw, source: Doc, ctx: C): readonly [typeof AccumulatorRaw, T];
|
|
213
|
+
}
|
|
214
|
+
interface AccumulatorHKT<T, C = unknown> extends HKT<unknown> {
|
|
215
|
+
readonly out: Accumulator<T, I<unknown, this>, C>;
|
|
216
|
+
}
|
|
217
|
+
type Accumulators<T, V extends RORec<string, jsonItem>, C = unknown> = Exact<V, AccumulatorHKT<T, C>>;
|
|
218
|
+
interface DeltaAccumulatorHKT<T, C = unknown> extends HKT<unknown> {
|
|
219
|
+
readonly out: DeltaAccumulator<T, I<unknown, this>, C>;
|
|
220
|
+
}
|
|
221
|
+
type DeltaAccumulators<T, V extends RORec<string, jsonItem>, C = unknown> = Exact<V, DeltaAccumulatorHKT<T, C>>;
|
|
222
|
+
declare const Accumulator: unique symbol;
|
|
223
|
+
type Accumulator<in Doc, out T, in Ctx = unknown> = {
|
|
224
|
+
[Type]?(_: typeof Accumulator): typeof Accumulator;
|
|
225
|
+
raw: {
|
|
226
|
+
<DeltaD extends O, I extends U>(f: Field<DeltaD, Doc | Undef<I>>): AccumulatorRaw<T | I, DeltaD, Ctx>;
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
type Part<Doc> = Rec<'v', Doc> & RORec<'old', boolean>;
|
|
230
|
+
type DeltaAccumulator<in out Doc, in out T, in out Ctx = unknown> = {
|
|
231
|
+
group: Accumulator<Part<Doc>, T, Ctx>;
|
|
232
|
+
merge: <D, C = Ctx>(a: Expr<T | N, D, C>, b: Expr<T, D, C>) => Expr<T, D, C>;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
declare const concat: {
|
|
236
|
+
<D, C>(...expr: Expr<string, D, C>[]): Expr<string, D, C>;
|
|
237
|
+
<D, C>(...expr: Expr<string | N, D, C>[]): Expr<string | N, D, C>;
|
|
238
|
+
};
|
|
239
|
+
declare const regex: <D, C>(expr: Expr<string, D, C>, regex: Expr<string, D, C>, options?: Expr<string, D, C>) => Expr<boolean, D, C>;
|
|
240
|
+
declare const str: <D, C>(expr: Expr<unknown, D, C>) => Expr<string, D, C>;
|
|
241
|
+
declare const toInt: <D, C>(expr: Expr<unknown, D, C>) => Expr<number, D, C>;
|
|
242
|
+
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>;
|
|
243
|
+
type Exprs<out T, in D, in C = unknown> = {
|
|
244
|
+
readonly [K in StrKey<T>]: Expr<T[K], D, C>;
|
|
245
|
+
};
|
|
246
|
+
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>;
|
|
247
|
+
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>];
|
|
248
|
+
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>>>;
|
|
249
|
+
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>;
|
|
250
|
+
type ExprsPart<T, D, C> = ExactPart<T, ExprHKT<D, C>>;
|
|
251
|
+
interface ExprHKT<D, C = unknown, F extends HKT = IdHKT> extends HKT<unknown> {
|
|
252
|
+
readonly out: Expr<App<F, I<unknown, this>>, D, C>;
|
|
253
|
+
}
|
|
254
|
+
type ExprsExact<T, D, C = unknown, F extends HKT = IdHKT> = Exact<T, ExprHKT<D, C, F>>;
|
|
255
|
+
interface ExprsExactHKT<E, D, C = unknown, F extends HKT = IdHKT> extends HKT {
|
|
256
|
+
readonly out: ExprsExact<E & I<unknown, this>, D, C, F>;
|
|
257
|
+
}
|
|
258
|
+
declare const pair: <T, D, C, P extends StrKey<T>>(k: P, v: Expr<T[P], D, C>) => ExprsExact<T, D, C>[P];
|
|
259
|
+
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>;
|
|
260
|
+
declare const field: <T extends object, D, C = unknown>(exprs: ExprsExact<T, D, C>) => Expr<O<T>, D, C>;
|
|
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
|
+
|
|
277
|
+
declare const RawStage: unique symbol;
|
|
278
|
+
declare module 'mongodb' {
|
|
279
|
+
interface Collection<TSchema extends BSON.Document = BSON.Document> {
|
|
280
|
+
[RawStage]: {
|
|
281
|
+
(_: 2): TSchema;
|
|
282
|
+
(_: 1, x: TSchema): TSchema;
|
|
283
|
+
};
|
|
284
|
+
s: {
|
|
285
|
+
db: Db;
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
interface Db {
|
|
289
|
+
s: {
|
|
290
|
+
client?: MongoClient;
|
|
291
|
+
};
|
|
292
|
+
client: MongoClient;
|
|
293
|
+
}
|
|
294
|
+
interface Timestamp {
|
|
295
|
+
toExtendedJSON(): BSON.TimestampExtended;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
interface CommonCollection {
|
|
300
|
+
readonly s: {
|
|
301
|
+
readonly db: Db;
|
|
302
|
+
};
|
|
303
|
+
collectionName: string;
|
|
304
|
+
namespace: string;
|
|
305
|
+
dbName: string;
|
|
306
|
+
createIndex: Collection['createIndex'];
|
|
307
|
+
}
|
|
308
|
+
interface ReadonlyCollection<out Out> extends CommonCollection {
|
|
309
|
+
[RawStage](_: 2): Out;
|
|
310
|
+
}
|
|
311
|
+
interface WriteonlyCollection<in R> extends CommonCollection {
|
|
312
|
+
[RawStage]: {
|
|
313
|
+
(_: 1, x: R): unknown;
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
interface RWCollection<in R extends O, out Out extends O = R> extends CommonCollection {
|
|
317
|
+
[RawStage](_: 2): Out;
|
|
318
|
+
[RawStage](_: 1, x: R): unknown;
|
|
319
|
+
}
|
|
320
|
+
type OPick<V, K extends StrKey<V>, E extends StrKey<V> = never> = O & Pick<V, K | E>;
|
|
321
|
+
type OPickD<V extends Model, K extends StrKey<V>> = OPick<V, K, 'deletedAt' | '_id'>;
|
|
322
|
+
type View<V extends Model, K extends StrKey<V>> = {
|
|
323
|
+
collection: ReadonlyCollection<V | Del>;
|
|
324
|
+
projection: ExactKeys<K> | null;
|
|
325
|
+
match?: Expr<boolean, OPickD<V, K>>;
|
|
326
|
+
hardMatch?: Query<V>;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
declare const val: <T extends rawItem>(val: T) => Expr<T, unknown>;
|
|
330
|
+
declare const current: Expr<Timestamp, unknown>;
|
|
331
|
+
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>;
|
|
332
|
+
declare const nil: Expr<null, unknown>;
|
|
333
|
+
declare const $getField: {
|
|
334
|
+
<T, K extends StrKey<T>, D, C = unknown>(expr: Expr<T, D, C>, field: K): Expr<T[K], D, C>;
|
|
335
|
+
<T, K extends StrKey<T>, D, C = unknown>(expr: Expr<T | N, D, C>, field: K): Expr<T[K] | null, D, C>;
|
|
336
|
+
};
|
|
337
|
+
type NoRaw<T> = T extends Arr<infer U> ? NoRaw<U>[] : T extends readonly unknown[] ? {
|
|
338
|
+
[K in keyof T]: NoRaw<T[K]>;
|
|
339
|
+
} : T extends O ? {
|
|
340
|
+
[K in StrKey<T>]: NoRaw<T[K]>;
|
|
341
|
+
} : T;
|
|
342
|
+
type RONoRaw<T> = T extends Arr<infer U> ? readonly RONoRaw<U>[] : T extends readonly unknown[] ? {
|
|
343
|
+
readonly [K in keyof T]: RONoRaw<T[K]>;
|
|
344
|
+
} : T extends O ? {
|
|
345
|
+
readonly [K in StrKey<T>]: RONoRaw<T[K]>;
|
|
346
|
+
} : T;
|
|
347
|
+
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>;
|
|
348
|
+
declare const rand: () => string;
|
|
349
|
+
declare const $rand: Expr<string, unknown, unknown>;
|
|
350
|
+
|
|
351
|
+
declare const $sum: <D extends O, C = unknown>(expr: Expr<number | N, D, C>) => DeltaAccumulator<D, number, C>;
|
|
352
|
+
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>;
|
|
353
|
+
declare const $countDict: <D extends O, C = unknown>(expr: Expr<string, D, C>) => DeltaAccumulator<D, Rec<string, number>, C>;
|
|
354
|
+
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>;
|
|
355
|
+
declare const $keys: <D extends O, C = unknown>(expr: Expr<Rec<string, number>, D, C>) => Expr<Arr<string>, D, C>;
|
|
356
|
+
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>;
|
|
357
|
+
|
|
358
|
+
type MergeInto<T extends O, Out extends O, E = unknown> = {
|
|
359
|
+
whenNotMatched: 'insert';
|
|
360
|
+
into: RWCollection<T, Out> & E;
|
|
361
|
+
} | {
|
|
362
|
+
whenNotMatched: 'discard' | 'fail';
|
|
363
|
+
into: ReadonlyCollection<Out> & E;
|
|
364
|
+
};
|
|
365
|
+
type MergeArgs<T extends O, Out extends O, Ctx, In extends O> = {
|
|
366
|
+
on: Field<T, jsonItem> & Field<Out, jsonItem>;
|
|
367
|
+
} & MergeInto<T, Out> & (({
|
|
368
|
+
stages?: never;
|
|
369
|
+
} & ({
|
|
370
|
+
whenMatched: 'keepExisting' | 'fail';
|
|
371
|
+
} | {
|
|
372
|
+
whenMatched: 'replace';
|
|
373
|
+
into: RWCollection<T, Out>;
|
|
374
|
+
} | {
|
|
375
|
+
whenMatched: 'merge';
|
|
376
|
+
into: RWCollection<Replace<Out, T>, Out>;
|
|
377
|
+
})) | {
|
|
378
|
+
stages: true;
|
|
379
|
+
into: RWCollection<In, Out>;
|
|
380
|
+
whenMatched: RawStages<unknown, Out, In, {
|
|
381
|
+
new: T;
|
|
382
|
+
}>;
|
|
383
|
+
} | {
|
|
384
|
+
stages: 'ctx';
|
|
385
|
+
vars: ExprsExact<Ctx, T>;
|
|
386
|
+
into: RWCollection<In, Out>;
|
|
387
|
+
whenMatched: RawStages<unknown, Out, In, Ctx>;
|
|
388
|
+
});
|
|
389
|
+
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>;
|
|
390
|
+
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>;
|
|
391
|
+
|
|
392
|
+
type GI$1<GG> = Exclude<GG, keyof TS>;
|
|
393
|
+
type IdAndTsKeys = keyof (TS & ID);
|
|
394
|
+
type V<VV, GG extends string> = Omit<VV, IdAndTsKeys | GI$1<GG>>;
|
|
395
|
+
type Prepare<Grp, GG extends string> = TS & ID & Rec<GI$1<GG>, Grp>;
|
|
396
|
+
type Par<T> = {
|
|
397
|
+
[P in keyof T]?: T[P] | null;
|
|
398
|
+
};
|
|
399
|
+
type Loose<Grp, VV, GG extends string> = Prepare<Grp, GG> & Par<V<VV, GG>>;
|
|
400
|
+
type Strict<Grp, VV, GG extends string, EE> = Prepare<Grp, GG> & V<VV, GG> & Omit<EE, IdAndTsKeys | GI$1<GG> | keyof V<VV, GG>>;
|
|
401
|
+
type V_Grp<VV, GG extends string, Grp> = Rec<GI$1<GG>, Grp> & V<VV, GG>;
|
|
402
|
+
type Extra<EE, VV, GG extends string> = Omit<EE, IdAndTsKeys | GI$1<GG> | keyof V<VV, GG>>;
|
|
403
|
+
type OrReplace<T, V> = T | Replace<T, V>;
|
|
404
|
+
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>>;
|
|
405
|
+
|
|
406
|
+
type Denied<GID = never> = keyof (TS & ID) | GID;
|
|
407
|
+
type GI<GG> = Exclude<GG, keyof TS>;
|
|
408
|
+
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">;
|
|
409
|
+
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">;
|
|
410
|
+
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">;
|
|
411
|
+
|
|
412
|
+
type Params<As extends string, LQ extends O, RQ extends O, RE extends RQ, S extends notArr> = {
|
|
413
|
+
localField: Field<LQ, S>;
|
|
414
|
+
foreignField: Field<RQ, S>;
|
|
415
|
+
from: SnapshotStreamExecutionResult<RQ, RE>;
|
|
416
|
+
as: AsLiteral<As>;
|
|
417
|
+
};
|
|
418
|
+
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>>;
|
|
419
|
+
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>>;
|
|
420
|
+
|
|
421
|
+
declare const $matchDelta: <T extends doc>(query: Expr<boolean, T>) => RawStages<unknown, Delta<T>, Delta<T>, unknown, number>;
|
|
422
|
+
|
|
423
|
+
declare const $match: <T extends doc>(query: Expr<boolean, T>) => DeltaStages<T, T, T>;
|
|
424
|
+
|
|
425
|
+
declare const Updater: unique symbol;
|
|
426
|
+
type Updater<in R, in T, out V, in C = unknown> = {
|
|
427
|
+
[Type]?(x: typeof Updater, r: R, t: T, c: C): V;
|
|
428
|
+
readonly raw: <D extends O>(f: Field<D, R | N>) => readonly (readonly [string, rawItem])[];
|
|
429
|
+
};
|
|
430
|
+
interface UpdaterHKT<R, Old, V, C, K extends keyof Old = keyof Old, V2 extends V = V> extends HKT<StrKey<V>> {
|
|
431
|
+
readonly out: Updater<R, Get<Old, I<StrKey<V>, this>, K>, V2[I<StrKey<V>, this>], C>;
|
|
432
|
+
}
|
|
433
|
+
type Get<T, P extends string, K extends keyof T = never> = P extends K ? T[P] : P extends keyof T ? T[P] : undefined;
|
|
434
|
+
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>;
|
|
435
|
+
declare const to: <R, V, C = unknown, T = unknown>(expr: Expr<V, R, C>) => Updater<R, T, V, C>;
|
|
436
|
+
|
|
437
|
+
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>;
|
|
438
|
+
declare const $replaceWith: <T extends O, V extends O>(expr: Expr<V, T>) => DeltaStages<O, T, V> & LinStages<O, T, V>;
|
|
439
|
+
|
|
440
|
+
type s$1 = string;
|
|
441
|
+
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>>;
|
|
442
|
+
|
|
443
|
+
type s = string;
|
|
444
|
+
type TOf<TT, K extends string> = doc & Omit<TT, K>;
|
|
445
|
+
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>>;
|
|
446
|
+
|
|
447
|
+
type OutInputE<T, E, A = T | null> = ID & Rec<'after', A> & E;
|
|
448
|
+
type Allowed$2<K extends string> = Exclude<K, keyof (TS & ID)>;
|
|
449
|
+
type Patch<V, KK extends StrKey<V> = StrKey<V>> = ((OPick<V, Allowed$2<KK>> & ID) | (Rec<Allowed$2<KK>, N> & ID)) & TS;
|
|
450
|
+
type TakeDoc<V, E = ID, KK extends StrKey<V> = StrKey<V>> = OPick<V, Allowed$2<KK>> & E;
|
|
451
|
+
type ND$1 = {
|
|
452
|
+
readonly deletedAt?: null;
|
|
453
|
+
};
|
|
454
|
+
type SafeE$1<E> = Omit<E, `$${string}` | keyof ID>;
|
|
455
|
+
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>>>>;
|
|
456
|
+
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>>;
|
|
457
|
+
type MergeCollection<V extends O, Out extends Model> = {
|
|
458
|
+
coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
|
|
459
|
+
whenNotMatched: 'discard';
|
|
460
|
+
} | {
|
|
461
|
+
coll: RWCollection<Out | Replace<Out, Patch<V>>, Out>;
|
|
462
|
+
whenNotMatched: 'fail';
|
|
463
|
+
};
|
|
464
|
+
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">;
|
|
465
|
+
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">;
|
|
466
|
+
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">;
|
|
467
|
+
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">;
|
|
468
|
+
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">;
|
|
469
|
+
|
|
470
|
+
type ND = {
|
|
471
|
+
readonly deletedAt?: null;
|
|
472
|
+
};
|
|
473
|
+
type SafeE<E> = Omit<E, `$${string}` | keyof ID>;
|
|
474
|
+
type Merge<T extends doc, E> = Omit<SafeE<E>, keyof (ND & TS)> & ((T & ND & TS) | Del);
|
|
475
|
+
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">;
|
|
476
|
+
declare const $simpleInsert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<T, "out">;
|
|
477
|
+
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">;
|
|
478
|
+
declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
|
|
479
|
+
|
|
480
|
+
declare const log: (...args: unknown[]) => void;
|
|
481
|
+
|
|
482
|
+
declare const createIndex: (collection: {
|
|
483
|
+
readonly createIndex: Collection["createIndex"];
|
|
484
|
+
collectionName: string;
|
|
485
|
+
}, indexSpec: IndexSpecification, op?: CreateIndexesOptions) => Promise<void>;
|
|
486
|
+
|
|
487
|
+
declare const noop: () => void;
|
|
488
|
+
declare const map1: <K extends string, Im>(k: AsLiteral<K>, to: Im) => { readonly [P in K]: [P, Im]; } & {
|
|
489
|
+
readonly [_: string]: [K, Im];
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
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>;
|
|
493
|
+
|
|
494
|
+
type DeltaPipe<Q extends O, T extends Q, F extends HKT<O2>, G extends HKT<O3>> = {
|
|
495
|
+
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>;
|
|
496
|
+
then: <Q2 extends O, V extends Q2>(next: App<G, [Q2 | T, T, V]>) => DeltaPipe<Q | Q2, V, F, G>;
|
|
497
|
+
get: () => App<F, [Q, T]>;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
type AllowedPick$1<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed$1<K>>;
|
|
501
|
+
type Allowed$1<K> = Exclude<K, 'deletedAt' | '_id'>;
|
|
502
|
+
|
|
503
|
+
interface SnapshotStreamHKT extends HKT<O2> {
|
|
504
|
+
readonly out: SnapshotStreamExecutionResult<I<O2, this>[0], I<O2, this>[1]>;
|
|
505
|
+
}
|
|
506
|
+
interface DeltaHKT extends HKT<O3> {
|
|
507
|
+
readonly out: DeltaStages<I<O3, this>[0], I<O3, this>[1], I<O3, this>[2]>;
|
|
508
|
+
}
|
|
509
|
+
declare const staging: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed$1<KK>> & {
|
|
510
|
+
needs?: Partial<Record<KK, 0 | 1>>;
|
|
511
|
+
}, streamName: string, skip?: boolean, after?: () => Promise<void>) => DeltaPipe<AllowedPick$1<V, KK>, AllowedPick$1<V, KK>, SnapshotStreamHKT, DeltaHKT>;
|
|
512
|
+
|
|
513
|
+
type Allowed<K> = Exclude<K, 'deletedAt' | '_id'>;
|
|
514
|
+
type AllowedPick<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed<K>>;
|
|
515
|
+
interface StreamRunnerHKT extends HKT<O2> {
|
|
516
|
+
readonly out: SimpleStreamExecutionResult<I<O2, this>[0], I<O2, this>[1]>;
|
|
517
|
+
}
|
|
518
|
+
interface StagesHKT extends HKT<O3> {
|
|
519
|
+
readonly out: RORec<'lin', RawStages<I<O3, this>[0], I<O3, this>[1], I<O3, this>[2], unknown, 1>>;
|
|
520
|
+
}
|
|
521
|
+
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>;
|
|
522
|
+
|
|
523
|
+
type SingleResult<out Result> = <Result2>(finalInput: RawStages<unknown, Result, Result2>) => Stages<unknown, Result2, unknown>;
|
|
524
|
+
interface SnapshotStreamHKT2 extends HKT<O2> {
|
|
525
|
+
readonly out: SingleResult<I<O2, this>[1]>;
|
|
526
|
+
}
|
|
527
|
+
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>;
|
|
528
|
+
|
|
529
|
+
declare const max: <D, C>(...expr: Expr<number, D, C>[]) => Expr<number, D, C>;
|
|
530
|
+
declare const lt: {
|
|
531
|
+
<D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
|
|
532
|
+
<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
|
|
533
|
+
};
|
|
534
|
+
declare const gt: {
|
|
535
|
+
<D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
|
|
536
|
+
<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
|
|
537
|
+
};
|
|
538
|
+
declare const lte: {
|
|
539
|
+
<D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
|
|
540
|
+
<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
|
|
541
|
+
};
|
|
542
|
+
declare const gte: {
|
|
543
|
+
<D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
|
|
544
|
+
<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
|
|
545
|
+
};
|
|
546
|
+
type Num = number | null | undefined;
|
|
547
|
+
declare function subtract<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
|
|
548
|
+
declare function subtract<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
|
|
549
|
+
declare function add<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
|
|
550
|
+
declare function add<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
|
|
551
|
+
declare function divide<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
|
|
552
|
+
declare function divide<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
|
|
553
|
+
declare function multiply<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
|
|
554
|
+
declare function multiply<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
|
|
555
|
+
declare function floor<D, C>(expr: Expr<number, D, C>): Expr<number, D, C>;
|
|
556
|
+
declare function floor<D, C>(expr: Expr<Num, D, C>): Expr<Num, D, C>;
|
|
557
|
+
declare function ceil<D, C>(expr: Expr<number, D, C>): Expr<number, D, C>;
|
|
558
|
+
declare function ceil<D, C>(expr: Expr<Num, D, C>): Expr<Num, D, C>;
|
|
559
|
+
|
|
560
|
+
declare const size: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<number, D, C>;
|
|
561
|
+
declare const filterDefined: <T, D, C = unknown>(expr: Expr<Arr<T | N>, D, C>) => Expr<Arr<T>, D, C>;
|
|
562
|
+
declare const filter: <T, D, K extends string, C = unknown>({ as, cond, expr, limit, }: {
|
|
563
|
+
expr: Expr<Arr<T>, D, C>;
|
|
564
|
+
as: K;
|
|
565
|
+
cond: Expr<unknown, D, C & RORec<K, T>>;
|
|
566
|
+
limit?: Expr<number, D, C>;
|
|
567
|
+
}) => Expr<Arr<T>, D, C>;
|
|
568
|
+
declare const sortArray: <T, D, C, K extends keyof T>({ sortBy, expr, order, }: {
|
|
569
|
+
expr: Expr<Arr<T>, D, C>;
|
|
570
|
+
sortBy: K;
|
|
571
|
+
order?: 1 | -1;
|
|
572
|
+
}) => Expr<Arr<T>, D, C>;
|
|
573
|
+
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>;
|
|
574
|
+
declare const inArray: <T, D, C>(item: Expr<T, D, C>, expr: Expr<Arr<T>, D, C>) => Expr<boolean, D, C>;
|
|
575
|
+
declare const array: <T, D, C = unknown>(...exprs: Expr<T, D, C>[]) => Expr<Arr<T>, D, C>;
|
|
576
|
+
declare const concatArray: <T, D, C>(...exprs: Expr<Arr<T>, D, C>[]) => Expr<Arr<T>, D, C>;
|
|
577
|
+
declare const first: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>;
|
|
578
|
+
declare const firstSure: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T, D, C>;
|
|
579
|
+
declare const last: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>;
|
|
580
|
+
type NullToOBJ<N extends null> = N extends null ? O : N;
|
|
581
|
+
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>;
|
|
582
|
+
declare const anyElementTrue: <D, C = unknown>(expr: Expr<Arr<boolean>, D, C>) => Expr<boolean, D, C>;
|
|
583
|
+
type Reduce<T, V> = RORec<'value', V> & RORec<'this', T>;
|
|
584
|
+
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>;
|
|
585
|
+
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>;
|
|
586
|
+
declare const except: <T, D, C>(a: Expr<Arr<T>, D, C>, b: Expr<Arr<T>, D, C>) => Expr<Arr<T>, D, C>;
|
|
587
|
+
|
|
588
|
+
declare const dayAndMonthPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
|
|
589
|
+
declare const now: <D, C>() => Expr<Date, D, C>;
|
|
590
|
+
declare const monthPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
|
|
591
|
+
declare const weekPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
|
|
592
|
+
declare const year: <D, C>(date: Expr<Date, D, C>) => Expr<number, D, C>;
|
|
593
|
+
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>;
|
|
594
|
+
declare const maxDate: <D, C>(expr: Expr<Arr<Date>, D, C>) => Expr<Date, D, C>;
|
|
595
|
+
declare const minDate: <D, C>(expr: Expr<Arr<Date>, D, C>) => Expr<Date, D, C>;
|
|
596
|
+
declare const datePart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
|
|
597
|
+
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>;
|
|
598
|
+
declare const dateDiff: <D, C>({ end, unit, start, }: {
|
|
599
|
+
start: Expr<Date, D, C>;
|
|
600
|
+
end: Expr<Date, D, C>;
|
|
601
|
+
unit: Expr<"week" | "day" | "month" | "year", D, C>;
|
|
602
|
+
}) => Expr<number, D, C>;
|
|
603
|
+
|
|
604
|
+
declare const ite: {
|
|
605
|
+
<T, D, C = unknown>(cond: Expr<unknown, D, C>, then: Expr<T, D, C>, orelse: Expr<T, D, C>): Expr<T, D, C>;
|
|
606
|
+
<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>;
|
|
607
|
+
};
|
|
608
|
+
declare const and: <D, C = unknown>(...expr: Expr<boolean, D, C>[]) => Expr<boolean, D, C>;
|
|
609
|
+
declare const or: <D, C = unknown>(...expr: Expr<boolean, D, C>[]) => Expr<boolean, D, C>;
|
|
610
|
+
declare const not: <D, C = unknown>(expr: Expr<boolean, D, C>) => Expr<boolean, D, C>;
|
|
611
|
+
declare const eq: <T, D, C = unknown>(a: Expr<T, D, C>) => (b: Expr<T, D, C>) => Expr<boolean, D, C>;
|
|
612
|
+
declare const sub: <T, D, Ctx, P extends O>(a: Expr<T, D, Ctx>, f: Field<P, D, Ctx>) => Expr<T, P, Ctx>;
|
|
613
|
+
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>;
|
|
614
|
+
declare const ne: <T, D, C>(a: Expr<T, D, C>) => <K>(b: Expr<K, D, C>) => Expr<boolean, D, C>;
|
|
615
|
+
declare const notNull: <T, D, C>(a: Expr<T, D, C>) => Expr<boolean, D, C>;
|
|
616
|
+
declare const $ifNull: <R, D, C>(...expr: [...Expr<R | null | undefined, D, C>[], Expr<R, D, C>]) => Expr<R, D, C>;
|
|
617
|
+
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>;
|
|
618
|
+
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>;
|
|
619
|
+
declare const setField: <K extends string, T, V, D, C>({ field, input, value, }: {
|
|
620
|
+
field: Expr<K, D, C>;
|
|
621
|
+
input: Expr<T, D, C>;
|
|
622
|
+
value: Expr<V, D, C>;
|
|
623
|
+
}) => Expr<T & Record<K, V>, D, C>;
|
|
624
|
+
|
|
625
|
+
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>;
|
|
626
|
+
declare const $map0: <K extends string, T, R, D, C>({ as, expr, input, }: {
|
|
627
|
+
input: Expr<Arr<T>, D, C>;
|
|
628
|
+
as: K;
|
|
629
|
+
expr: Expr<R, D, RORec<K, T> & C>;
|
|
630
|
+
}) => Expr<Arr<R>, D, C>;
|
|
631
|
+
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>;
|
|
632
|
+
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>;
|
|
633
|
+
|
|
634
|
+
declare class Machine<Result = unknown> {
|
|
635
|
+
private sources;
|
|
636
|
+
constructor(root?: Iterator<Result, HasJob>);
|
|
637
|
+
add(x: Iterator<Result, HasJob>): void;
|
|
638
|
+
runner(): Iterator<Result, HasJob>;
|
|
639
|
+
start(cb?: (info: HasJob) => void | boolean): Promise<never>;
|
|
640
|
+
}
|
|
641
|
+
declare const wrap: <Result>(root: Machine<Result>) => Machine<Result>;
|
|
642
|
+
|
|
643
|
+
declare const $eq: <T extends unknown>(operand: rawItem & T) => Predicate<T>;
|
|
644
|
+
declare const $ne: <T extends unknown>(operand: rawItem & T) => Predicate<T>;
|
|
645
|
+
type Numeric = number | Timestamp | Date;
|
|
646
|
+
declare const comp: <D2 extends Numeric = Numeric>(op: "$gt" | "$gte" | "$lt" | "$lte") => <T extends Numeric>(operand: rawItem & D2) => Predicate<D2>;
|
|
647
|
+
declare const $gt: <T extends Numeric>(operand: rawItem & Numeric) => Predicate<Numeric>;
|
|
648
|
+
declare const $gtTs: <T extends Numeric>(operand: rawItem & Timestamp) => Predicate<Timestamp>;
|
|
649
|
+
declare const $gteTs: <T extends Numeric>(operand: rawItem & Timestamp) => Predicate<Timestamp>;
|
|
650
|
+
declare const $lt: <T extends Numeric>(operand: rawItem & number) => Predicate<number>;
|
|
651
|
+
declare const dateLt: <T extends Numeric>(operand: rawItem & Date) => Predicate<Date>;
|
|
652
|
+
declare const $gte: <T extends Numeric>(operand: rawItem & number) => Predicate<number>;
|
|
653
|
+
declare const $lte: <T extends Numeric>(operand: rawItem & number) => Predicate<number>;
|
|
654
|
+
type MongoTypes = {
|
|
655
|
+
number: number;
|
|
656
|
+
array: readonly rawItem[];
|
|
657
|
+
string: string;
|
|
658
|
+
object: RawObj;
|
|
659
|
+
[i: number]: unknown;
|
|
660
|
+
};
|
|
661
|
+
type MongoTypeNames = keyof MongoTypes;
|
|
662
|
+
declare const $type: <T extends keyof MongoTypes>(operand: rawItem & readonly T[]) => Predicate<N | MongoTypes[T]>;
|
|
663
|
+
declare const $exists: <T extends keyof MongoTypes>(operand: rawItem & boolean) => Predicate<unknown>;
|
|
664
|
+
|
|
665
|
+
declare const $expr: <D extends O, C>(expr: Expr<boolean, D, C>) => Query<D, C>;
|
|
666
|
+
|
|
667
|
+
declare const $in: <T extends unknown>(operand: rawItem & readonly T[]) => Predicate<T>;
|
|
668
|
+
declare const $nin: <T extends unknown>(operand: rawItem & readonly T[]) => Predicate<T>;
|
|
669
|
+
|
|
670
|
+
type Many<T> = readonly (T | N)[];
|
|
671
|
+
type Combiner = {
|
|
672
|
+
<T extends O, C = unknown>(first: Query<T, C>, ...args: Many<Query<T, C>>): Query<T, C>;
|
|
673
|
+
<T extends O, C = unknown>(...args: Many<Query<T, C>>): Query<T, C> | undefined;
|
|
674
|
+
};
|
|
675
|
+
declare const $and: Combiner;
|
|
676
|
+
declare const $nor: Combiner;
|
|
677
|
+
declare const $or: Combiner;
|
|
678
|
+
|
|
679
|
+
declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Promise<Document>;
|
|
680
|
+
declare const prepare: (testName?: string) => Promise<MongoClient$1>;
|
|
681
|
+
declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
|
|
682
|
+
|
|
683
|
+
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, Expr, Field, Machine, Type, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
|
|
684
|
+
export type { Accumulators, Arr, AsLiteral, Delta, DeltaAccumulator, DeltaAccumulators, ExactKeys, ExprHKT, Exprs, ExprsExact, ExprsExactHKT, ExprsPart, ID, Loose, Merge, MergeArgs, MergeInto, MergeMapOArgs, Model, MongoTypeNames, N, NoRaw, NullToOBJ, O, OPick, OPickD, Patch, RONoRaw, RORec, RawStages, Rec, Replace, SnapshotStreamExecutionResult, StrKey, Strict, TS, WriteonlyCollection, doc, jsonPrim, notArr };
|
package/index.esm.js
CHANGED
|
@@ -1272,7 +1272,7 @@ const createIndex = async (collection, indexSpec, op) => {
|
|
|
1272
1272
|
};
|
|
1273
1273
|
const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
1274
1274
|
const log = () => { };
|
|
1275
|
-
log('Creating index', { collection: collection.collectionName
|
|
1275
|
+
log('Creating index', { collection: collection.collectionName});
|
|
1276
1276
|
while (true) {
|
|
1277
1277
|
try {
|
|
1278
1278
|
await collection.createIndex(indexSpec, options);
|
|
@@ -1280,7 +1280,7 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1280
1280
|
}
|
|
1281
1281
|
catch (e) {
|
|
1282
1282
|
if ([85, 276].includes(e.code)) {
|
|
1283
|
-
log('Index created with different name', e.code, { collection: collection.collectionName
|
|
1283
|
+
log('Index created with different name', e.code, { collection: collection.collectionName});
|
|
1284
1284
|
break;
|
|
1285
1285
|
}
|
|
1286
1286
|
if (e.code == 12587) {
|
|
@@ -1288,11 +1288,7 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1288
1288
|
continue;
|
|
1289
1289
|
}
|
|
1290
1290
|
log('Error creating index', {
|
|
1291
|
-
collection: collection.collectionName
|
|
1292
|
-
indexSpec,
|
|
1293
|
-
options,
|
|
1294
|
-
error: e,
|
|
1295
|
-
});
|
|
1291
|
+
collection: collection.collectionName});
|
|
1296
1292
|
console.error('Error creating index', e);
|
|
1297
1293
|
throw e;
|
|
1298
1294
|
}
|
|
@@ -1370,7 +1366,7 @@ const firstWorksMerge = (iters) => {
|
|
|
1370
1366
|
const sources = { ...results };
|
|
1371
1367
|
return mergeIterators({
|
|
1372
1368
|
sources,
|
|
1373
|
-
interrupt: key =>
|
|
1369
|
+
interrupt: key => false,
|
|
1374
1370
|
hooks: {
|
|
1375
1371
|
start: (frame, result) => {
|
|
1376
1372
|
if (!frame.info.job)
|
|
@@ -1569,14 +1565,18 @@ const aggregate = (db, streamName, input, snapshot = true, start = Date.now()) =
|
|
|
1569
1565
|
};
|
|
1570
1566
|
log('exec', streamName, req);
|
|
1571
1567
|
const start2 = Date.now();
|
|
1572
|
-
return db
|
|
1568
|
+
return db
|
|
1569
|
+
.then(d => d.command(req))
|
|
1570
|
+
.then(result => {
|
|
1573
1571
|
log('prepare', streamName, Date.now() - start);
|
|
1574
1572
|
log('prepare2', streamName, start2 - start);
|
|
1575
1573
|
const r = result;
|
|
1576
1574
|
log('execed', streamName, (replace) => replace(JSON.stringify(req).replaceAll('"$$CLUSTER_TIME"', JSON.stringify(r.cursor.atClusterTime))), result, 'took', Date.now() - start);
|
|
1577
1575
|
return r;
|
|
1578
|
-
}, err => {
|
|
1576
|
+
}, async (err) => {
|
|
1579
1577
|
log('err', req, err);
|
|
1578
|
+
console.error(err);
|
|
1579
|
+
await new Promise(() => { });
|
|
1580
1580
|
throw new Error(err);
|
|
1581
1581
|
});
|
|
1582
1582
|
});
|
|
@@ -1718,16 +1718,7 @@ const loop = async (db) => {
|
|
|
1718
1718
|
}
|
|
1719
1719
|
continue;
|
|
1720
1720
|
}
|
|
1721
|
-
const
|
|
1722
|
-
return arr.reduce((acc, x) => {
|
|
1723
|
-
const k = fn(x);
|
|
1724
|
-
if (!acc[k])
|
|
1725
|
-
acc[k] = [];
|
|
1726
|
-
acc[k].push(x);
|
|
1727
|
-
return acc;
|
|
1728
|
-
}, {});
|
|
1729
|
-
};
|
|
1730
|
-
const groups = groupBy(events.filter(e => e.changeTouched), ev => ev.doc.ns);
|
|
1721
|
+
const groups = Object.groupBy(events.filter(e => e.changeTouched), ev => ev.doc.ns);
|
|
1731
1722
|
for (const [ns, evs] of Object.entries(groups)) {
|
|
1732
1723
|
if (!evs)
|
|
1733
1724
|
continue;
|
package/index.js
CHANGED
|
@@ -1274,7 +1274,7 @@ const createIndex = async (collection, indexSpec, op) => {
|
|
|
1274
1274
|
};
|
|
1275
1275
|
const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
1276
1276
|
const log = () => { };
|
|
1277
|
-
log('Creating index', { collection: collection.collectionName
|
|
1277
|
+
log('Creating index', { collection: collection.collectionName});
|
|
1278
1278
|
while (true) {
|
|
1279
1279
|
try {
|
|
1280
1280
|
await collection.createIndex(indexSpec, options);
|
|
@@ -1282,7 +1282,7 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1282
1282
|
}
|
|
1283
1283
|
catch (e) {
|
|
1284
1284
|
if ([85, 276].includes(e.code)) {
|
|
1285
|
-
log('Index created with different name', e.code, { collection: collection.collectionName
|
|
1285
|
+
log('Index created with different name', e.code, { collection: collection.collectionName});
|
|
1286
1286
|
break;
|
|
1287
1287
|
}
|
|
1288
1288
|
if (e.code == 12587) {
|
|
@@ -1290,11 +1290,7 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1290
1290
|
continue;
|
|
1291
1291
|
}
|
|
1292
1292
|
log('Error creating index', {
|
|
1293
|
-
collection: collection.collectionName
|
|
1294
|
-
indexSpec,
|
|
1295
|
-
options,
|
|
1296
|
-
error: e,
|
|
1297
|
-
});
|
|
1293
|
+
collection: collection.collectionName});
|
|
1298
1294
|
console.error('Error creating index', e);
|
|
1299
1295
|
throw e;
|
|
1300
1296
|
}
|
|
@@ -1372,7 +1368,7 @@ const firstWorksMerge = (iters) => {
|
|
|
1372
1368
|
const sources = { ...results };
|
|
1373
1369
|
return mergeIterators({
|
|
1374
1370
|
sources,
|
|
1375
|
-
interrupt: key =>
|
|
1371
|
+
interrupt: key => false,
|
|
1376
1372
|
hooks: {
|
|
1377
1373
|
start: (frame, result) => {
|
|
1378
1374
|
if (!frame.info.job)
|
|
@@ -1571,14 +1567,18 @@ const aggregate = (db, streamName, input, snapshot = true, start = Date.now()) =
|
|
|
1571
1567
|
};
|
|
1572
1568
|
log('exec', streamName, req);
|
|
1573
1569
|
const start2 = Date.now();
|
|
1574
|
-
return db
|
|
1570
|
+
return db
|
|
1571
|
+
.then(d => d.command(req))
|
|
1572
|
+
.then(result => {
|
|
1575
1573
|
log('prepare', streamName, Date.now() - start);
|
|
1576
1574
|
log('prepare2', streamName, start2 - start);
|
|
1577
1575
|
const r = result;
|
|
1578
1576
|
log('execed', streamName, (replace) => replace(JSON.stringify(req).replaceAll('"$$CLUSTER_TIME"', JSON.stringify(r.cursor.atClusterTime))), result, 'took', Date.now() - start);
|
|
1579
1577
|
return r;
|
|
1580
|
-
}, err => {
|
|
1578
|
+
}, async (err) => {
|
|
1581
1579
|
log('err', req, err);
|
|
1580
|
+
console.error(err);
|
|
1581
|
+
await new Promise(() => { });
|
|
1582
1582
|
throw new Error(err);
|
|
1583
1583
|
});
|
|
1584
1584
|
});
|
|
@@ -1720,16 +1720,7 @@ const loop = async (db) => {
|
|
|
1720
1720
|
}
|
|
1721
1721
|
continue;
|
|
1722
1722
|
}
|
|
1723
|
-
const
|
|
1724
|
-
return arr.reduce((acc, x) => {
|
|
1725
|
-
const k = fn(x);
|
|
1726
|
-
if (!acc[k])
|
|
1727
|
-
acc[k] = [];
|
|
1728
|
-
acc[k].push(x);
|
|
1729
|
-
return acc;
|
|
1730
|
-
}, {});
|
|
1731
|
-
};
|
|
1732
|
-
const groups = groupBy(events.filter(e => e.changeTouched), ev => ev.doc.ns);
|
|
1723
|
+
const groups = Object.groupBy(events.filter(e => e.changeTouched), ev => ev.doc.ns);
|
|
1733
1724
|
for (const [ns, evs] of Object.entries(groups)) {
|
|
1734
1725
|
if (!evs)
|
|
1735
1726
|
continue;
|