@omegup/msync 0.1.27 → 0.1.29
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 +685 -13
- package/index.esm.js +31 -28
- package/index.js +31 -27
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,13 +1,685 @@
|
|
|
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 afterWriteTime: Expr<Timestamp, unknown>;
|
|
331
|
+
declare const current: Expr<Timestamp, unknown>;
|
|
332
|
+
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>;
|
|
333
|
+
declare const nil: Expr<null, unknown>;
|
|
334
|
+
declare const $getField: {
|
|
335
|
+
<T, K extends StrKey<T>, D, C = unknown>(expr: Expr<T, D, C>, field: K): Expr<T[K], D, C>;
|
|
336
|
+
<T, K extends StrKey<T>, D, C = unknown>(expr: Expr<T | N, D, C>, field: K): Expr<T[K] | null, D, C>;
|
|
337
|
+
};
|
|
338
|
+
type NoRaw<T> = T extends Arr<infer U> ? NoRaw<U>[] : T extends readonly unknown[] ? {
|
|
339
|
+
[K in keyof T]: NoRaw<T[K]>;
|
|
340
|
+
} : T extends O ? {
|
|
341
|
+
[K in StrKey<T>]: NoRaw<T[K]>;
|
|
342
|
+
} : T;
|
|
343
|
+
type RONoRaw<T> = T extends Arr<infer U> ? readonly RONoRaw<U>[] : T extends readonly unknown[] ? {
|
|
344
|
+
readonly [K in keyof T]: RONoRaw<T[K]>;
|
|
345
|
+
} : T extends O ? {
|
|
346
|
+
readonly [K in StrKey<T>]: RONoRaw<T[K]>;
|
|
347
|
+
} : T;
|
|
348
|
+
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>;
|
|
349
|
+
declare const rand: () => string;
|
|
350
|
+
declare const $rand: Expr<string, unknown, unknown>;
|
|
351
|
+
|
|
352
|
+
declare const $sum: <D extends O, C = unknown>(expr: Expr<number | N, D, C>) => DeltaAccumulator<D, number, C>;
|
|
353
|
+
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>;
|
|
354
|
+
declare const $countDict: <D extends O, C = unknown>(expr: Expr<string, D, C>) => DeltaAccumulator<D, Rec<string, number>, C>;
|
|
355
|
+
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>;
|
|
356
|
+
declare const $keys: <D extends O, C = unknown>(expr: Expr<Rec<string, number>, D, C>) => Expr<Arr<string>, D, C>;
|
|
357
|
+
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>;
|
|
358
|
+
|
|
359
|
+
type MergeInto<T extends O, Out extends O, E = unknown> = {
|
|
360
|
+
whenNotMatched: 'insert';
|
|
361
|
+
into: RWCollection<T, Out> & E;
|
|
362
|
+
} | {
|
|
363
|
+
whenNotMatched: 'discard' | 'fail';
|
|
364
|
+
into: ReadonlyCollection<Out> & E;
|
|
365
|
+
};
|
|
366
|
+
type MergeArgs<T extends O, Out extends O, Ctx, In extends O> = {
|
|
367
|
+
on: Field<T, jsonItem> & Field<Out, jsonItem>;
|
|
368
|
+
} & MergeInto<T, Out> & (({
|
|
369
|
+
stages?: never;
|
|
370
|
+
} & ({
|
|
371
|
+
whenMatched: 'keepExisting' | 'fail';
|
|
372
|
+
} | {
|
|
373
|
+
whenMatched: 'replace';
|
|
374
|
+
into: RWCollection<T, Out>;
|
|
375
|
+
} | {
|
|
376
|
+
whenMatched: 'merge';
|
|
377
|
+
into: RWCollection<Replace<Out, T>, Out>;
|
|
378
|
+
})) | {
|
|
379
|
+
stages: true;
|
|
380
|
+
into: RWCollection<In, Out>;
|
|
381
|
+
whenMatched: RawStages<unknown, Out, In, {
|
|
382
|
+
new: T;
|
|
383
|
+
}>;
|
|
384
|
+
} | {
|
|
385
|
+
stages: 'ctx';
|
|
386
|
+
vars: ExprsExact<Ctx, T>;
|
|
387
|
+
into: RWCollection<In, Out>;
|
|
388
|
+
whenMatched: RawStages<unknown, Out, In, Ctx>;
|
|
389
|
+
});
|
|
390
|
+
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>;
|
|
391
|
+
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>;
|
|
392
|
+
|
|
393
|
+
type GI$1<GG> = Exclude<GG, keyof TS>;
|
|
394
|
+
type IdAndTsKeys = keyof (TS & ID);
|
|
395
|
+
type V<VV, GG extends string> = Omit<VV, IdAndTsKeys | GI$1<GG>>;
|
|
396
|
+
type Prepare<Grp, GG extends string> = TS & ID & Rec<GI$1<GG>, Grp>;
|
|
397
|
+
type Par<T> = {
|
|
398
|
+
[P in keyof T]?: T[P] | null;
|
|
399
|
+
};
|
|
400
|
+
type Loose<Grp, VV, GG extends string> = Prepare<Grp, GG> & Par<V<VV, GG>>;
|
|
401
|
+
type Strict<Grp, VV, GG extends string, EE> = Prepare<Grp, GG> & V<VV, GG> & Omit<EE, IdAndTsKeys | GI$1<GG> | keyof V<VV, GG>>;
|
|
402
|
+
type V_Grp<VV, GG extends string, Grp> = Rec<GI$1<GG>, Grp> & V<VV, GG>;
|
|
403
|
+
type Extra<EE, VV, GG extends string> = Omit<EE, IdAndTsKeys | GI$1<GG> | keyof V<VV, GG>>;
|
|
404
|
+
type OrReplace<T, V> = T | Replace<T, V>;
|
|
405
|
+
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>>;
|
|
406
|
+
|
|
407
|
+
type Denied<GID = never> = keyof (TS & ID) | GID;
|
|
408
|
+
type GI<GG> = Exclude<GG, keyof TS>;
|
|
409
|
+
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">;
|
|
410
|
+
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">;
|
|
411
|
+
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">;
|
|
412
|
+
|
|
413
|
+
type Params<As extends string, LQ extends O, RQ extends O, RE extends RQ, S extends notArr> = {
|
|
414
|
+
localField: Field<LQ, S>;
|
|
415
|
+
foreignField: Field<RQ, S>;
|
|
416
|
+
from: SnapshotStreamExecutionResult<RQ, RE>;
|
|
417
|
+
as: AsLiteral<As>;
|
|
418
|
+
};
|
|
419
|
+
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>>;
|
|
420
|
+
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>>;
|
|
421
|
+
|
|
422
|
+
declare const $matchDelta: <T extends doc>(query: Expr<boolean, T>) => RawStages<unknown, Delta<T>, Delta<T>, unknown, number>;
|
|
423
|
+
|
|
424
|
+
declare const $match: <T extends doc>(query: Expr<boolean, T>) => DeltaStages<T, T, T>;
|
|
425
|
+
|
|
426
|
+
declare const Updater: unique symbol;
|
|
427
|
+
type Updater<in R, in T, out V, in C = unknown> = {
|
|
428
|
+
[Type]?(x: typeof Updater, r: R, t: T, c: C): V;
|
|
429
|
+
readonly raw: <D extends O>(f: Field<D, R | N>) => readonly (readonly [string, rawItem])[];
|
|
430
|
+
};
|
|
431
|
+
interface UpdaterHKT<R, Old, V, C, K extends keyof Old = keyof Old, V2 extends V = V> extends HKT<StrKey<V>> {
|
|
432
|
+
readonly out: Updater<R, Get<Old, I<StrKey<V>, this>, K>, V2[I<StrKey<V>, this>], C>;
|
|
433
|
+
}
|
|
434
|
+
type Get<T, P extends string, K extends keyof T = never> = P extends K ? T[P] : P extends keyof T ? T[P] : undefined;
|
|
435
|
+
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>;
|
|
436
|
+
declare const to: <R, V, C = unknown, T = unknown>(expr: Expr<V, R, C>) => Updater<R, T, V, C>;
|
|
437
|
+
|
|
438
|
+
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>;
|
|
439
|
+
declare const $replaceWith: <T extends O, V extends O>(expr: Expr<V, T>) => DeltaStages<O, T, V> & LinStages<O, T, V>;
|
|
440
|
+
|
|
441
|
+
type s$1 = string;
|
|
442
|
+
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>>;
|
|
443
|
+
|
|
444
|
+
type s = string;
|
|
445
|
+
type TOf<TT, K extends string> = doc & Omit<TT, K>;
|
|
446
|
+
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>>;
|
|
447
|
+
|
|
448
|
+
type OutInputE<T, E, A = T | null> = ID & Rec<'after', A> & E;
|
|
449
|
+
type Allowed$2<K extends string> = Exclude<K, keyof (TS & ID)>;
|
|
450
|
+
type Patch<V, KK extends StrKey<V> = StrKey<V>> = ((OPick<V, Allowed$2<KK>> & ID) | (Rec<Allowed$2<KK>, N> & ID)) & TS;
|
|
451
|
+
type TakeDoc<V, E = ID, KK extends StrKey<V> = StrKey<V>> = OPick<V, Allowed$2<KK>> & E;
|
|
452
|
+
type ND$1 = {
|
|
453
|
+
readonly deletedAt?: null;
|
|
454
|
+
};
|
|
455
|
+
type SafeE$1<E> = Omit<E, `$${string}` | keyof ID>;
|
|
456
|
+
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>>>>;
|
|
457
|
+
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>>;
|
|
458
|
+
type MergeCollection<V extends O, Out extends Model> = {
|
|
459
|
+
coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
|
|
460
|
+
whenNotMatched: 'discard';
|
|
461
|
+
} | {
|
|
462
|
+
coll: RWCollection<Out | Replace<Out, Patch<V>>, Out>;
|
|
463
|
+
whenNotMatched: 'fail';
|
|
464
|
+
};
|
|
465
|
+
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">;
|
|
466
|
+
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">;
|
|
467
|
+
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">;
|
|
468
|
+
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">;
|
|
469
|
+
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">;
|
|
470
|
+
|
|
471
|
+
type ND = {
|
|
472
|
+
readonly deletedAt?: null;
|
|
473
|
+
};
|
|
474
|
+
type SafeE<E> = Omit<E, `$${string}` | keyof ID>;
|
|
475
|
+
type Merge<T extends doc, E> = Omit<SafeE<E>, keyof (ND & TS)> & ((T & ND & TS) | Del);
|
|
476
|
+
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">;
|
|
477
|
+
declare const $simpleInsert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<T, "out">;
|
|
478
|
+
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">;
|
|
479
|
+
declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
|
|
480
|
+
|
|
481
|
+
declare const log: (...args: unknown[]) => void;
|
|
482
|
+
|
|
483
|
+
declare const createIndex: (collection: {
|
|
484
|
+
readonly createIndex: Collection["createIndex"];
|
|
485
|
+
collectionName: string;
|
|
486
|
+
}, indexSpec: IndexSpecification, op?: CreateIndexesOptions) => Promise<void>;
|
|
487
|
+
|
|
488
|
+
declare const noop: () => void;
|
|
489
|
+
declare const map1: <K extends string, Im>(k: AsLiteral<K>, to: Im) => { readonly [P in K]: [P, Im]; } & {
|
|
490
|
+
readonly [_: string]: [K, Im];
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
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>;
|
|
494
|
+
|
|
495
|
+
type DeltaPipe<Q extends O, T extends Q, F extends HKT<O2>, G extends HKT<O3>> = {
|
|
496
|
+
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>;
|
|
497
|
+
then: <Q2 extends O, V extends Q2>(next: App<G, [Q2 | T, T, V]>) => DeltaPipe<Q | Q2, V, F, G>;
|
|
498
|
+
get: () => App<F, [Q, T]>;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
type AllowedPick$1<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed$1<K>>;
|
|
502
|
+
type Allowed$1<K> = Exclude<K, 'deletedAt' | '_id'>;
|
|
503
|
+
|
|
504
|
+
interface SnapshotStreamHKT extends HKT<O2> {
|
|
505
|
+
readonly out: SnapshotStreamExecutionResult<I<O2, this>[0], I<O2, this>[1]>;
|
|
506
|
+
}
|
|
507
|
+
interface DeltaHKT extends HKT<O3> {
|
|
508
|
+
readonly out: DeltaStages<I<O3, this>[0], I<O3, this>[1], I<O3, this>[2]>;
|
|
509
|
+
}
|
|
510
|
+
declare const staging: <V extends Model, KK extends StrKey<V>>(view: View<V, Allowed$1<KK>> & {
|
|
511
|
+
needs?: Partial<Record<KK, 0 | 1>>;
|
|
512
|
+
}, streamName: string, skip?: boolean, after?: () => Promise<void>) => DeltaPipe<AllowedPick$1<V, KK>, AllowedPick$1<V, KK>, SnapshotStreamHKT, DeltaHKT>;
|
|
513
|
+
|
|
514
|
+
type Allowed<K> = Exclude<K, 'deletedAt' | '_id'>;
|
|
515
|
+
type AllowedPick<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed<K>>;
|
|
516
|
+
interface StreamRunnerHKT extends HKT<O2> {
|
|
517
|
+
readonly out: SimpleStreamExecutionResult<I<O2, this>[0], I<O2, this>[1]>;
|
|
518
|
+
}
|
|
519
|
+
interface StagesHKT extends HKT<O3> {
|
|
520
|
+
readonly out: RORec<'lin', RawStages<I<O3, this>[0], I<O3, this>[1], I<O3, this>[2], unknown, 1>>;
|
|
521
|
+
}
|
|
522
|
+
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>;
|
|
523
|
+
|
|
524
|
+
type SingleResult<out Result> = <Result2>(finalInput: RawStages<unknown, Result, Result2>) => Stages<unknown, Result2, unknown>;
|
|
525
|
+
interface SnapshotStreamHKT2 extends HKT<O2> {
|
|
526
|
+
readonly out: SingleResult<I<O2, this>[1]>;
|
|
527
|
+
}
|
|
528
|
+
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>;
|
|
529
|
+
|
|
530
|
+
declare const max: <D, C>(...expr: Expr<number, D, C>[]) => Expr<number, D, C>;
|
|
531
|
+
declare const lt: {
|
|
532
|
+
<D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
|
|
533
|
+
<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
|
|
534
|
+
};
|
|
535
|
+
declare const gt: {
|
|
536
|
+
<D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
|
|
537
|
+
<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
|
|
538
|
+
};
|
|
539
|
+
declare const lte: {
|
|
540
|
+
<D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
|
|
541
|
+
<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
|
|
542
|
+
};
|
|
543
|
+
declare const gte: {
|
|
544
|
+
<D, C>(...expr: [Expr<Date, D, C>, Expr<Date, D, C>]): Expr<boolean, D, C>;
|
|
545
|
+
<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<boolean, D, C>;
|
|
546
|
+
};
|
|
547
|
+
type Num = number | null | undefined;
|
|
548
|
+
declare function subtract<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
|
|
549
|
+
declare function subtract<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
|
|
550
|
+
declare function add<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
|
|
551
|
+
declare function add<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
|
|
552
|
+
declare function divide<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
|
|
553
|
+
declare function divide<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
|
|
554
|
+
declare function multiply<D, C>(...expr: [Expr<number, D, C>, Expr<number, D, C>]): Expr<number, D, C>;
|
|
555
|
+
declare function multiply<D, C>(...expr: [Expr<Num, D, C>, Expr<Num, D, C>]): Expr<Num, D, C>;
|
|
556
|
+
declare function floor<D, C>(expr: Expr<number, D, C>): Expr<number, D, C>;
|
|
557
|
+
declare function floor<D, C>(expr: Expr<Num, D, C>): Expr<Num, D, C>;
|
|
558
|
+
declare function ceil<D, C>(expr: Expr<number, D, C>): Expr<number, D, C>;
|
|
559
|
+
declare function ceil<D, C>(expr: Expr<Num, D, C>): Expr<Num, D, C>;
|
|
560
|
+
|
|
561
|
+
declare const size: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<number, D, C>;
|
|
562
|
+
declare const filterDefined: <T, D, C = unknown>(expr: Expr<Arr<T | N>, D, C>) => Expr<Arr<T>, D, C>;
|
|
563
|
+
declare const filter: <T, D, K extends string, C = unknown>({ as, cond, expr, limit, }: {
|
|
564
|
+
expr: Expr<Arr<T>, D, C>;
|
|
565
|
+
as: K;
|
|
566
|
+
cond: Expr<unknown, D, C & RORec<K, T>>;
|
|
567
|
+
limit?: Expr<number, D, C>;
|
|
568
|
+
}) => Expr<Arr<T>, D, C>;
|
|
569
|
+
declare const sortArray: <T, D, C, K extends keyof T>({ sortBy, expr, order, }: {
|
|
570
|
+
expr: Expr<Arr<T>, D, C>;
|
|
571
|
+
sortBy: K;
|
|
572
|
+
order?: 1 | -1;
|
|
573
|
+
}) => Expr<Arr<T>, D, C>;
|
|
574
|
+
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>;
|
|
575
|
+
declare const inArray: <T, D, C>(item: Expr<T, D, C>, expr: Expr<Arr<T>, D, C>) => Expr<boolean, D, C>;
|
|
576
|
+
declare const array: <T, D, C = unknown>(...exprs: Expr<T, D, C>[]) => Expr<Arr<T>, D, C>;
|
|
577
|
+
declare const concatArray: <T, D, C>(...exprs: Expr<Arr<T>, D, C>[]) => Expr<Arr<T>, D, C>;
|
|
578
|
+
declare const first: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>;
|
|
579
|
+
declare const firstSure: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T, D, C>;
|
|
580
|
+
declare const last: <T, D, C>(expr: Expr<Arr<T>, D, C>) => Expr<T | null, D, C>;
|
|
581
|
+
type NullToOBJ<N extends null> = N extends null ? O : N;
|
|
582
|
+
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>;
|
|
583
|
+
declare const anyElementTrue: <D, C = unknown>(expr: Expr<Arr<boolean>, D, C>) => Expr<boolean, D, C>;
|
|
584
|
+
type Reduce<T, V> = RORec<'value', V> & RORec<'this', T>;
|
|
585
|
+
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>;
|
|
586
|
+
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>;
|
|
587
|
+
declare const except: <T, D, C>(a: Expr<Arr<T>, D, C>, b: Expr<Arr<T>, D, C>) => Expr<Arr<T>, D, C>;
|
|
588
|
+
|
|
589
|
+
declare const dayAndMonthPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
|
|
590
|
+
declare const now: <D, C>() => Expr<Date, D, C>;
|
|
591
|
+
declare const monthPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
|
|
592
|
+
declare const weekPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
|
|
593
|
+
declare const year: <D, C>(date: Expr<Date, D, C>) => Expr<number, D, C>;
|
|
594
|
+
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>;
|
|
595
|
+
declare const maxDate: <D, C>(expr: Expr<Arr<Date>, D, C>) => Expr<Date, D, C>;
|
|
596
|
+
declare const minDate: <D, C>(expr: Expr<Arr<Date>, D, C>) => Expr<Date, D, C>;
|
|
597
|
+
declare const datePart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
|
|
598
|
+
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>;
|
|
599
|
+
declare const dateDiff: <D, C>({ end, unit, start, }: {
|
|
600
|
+
start: Expr<Date, D, C>;
|
|
601
|
+
end: Expr<Date, D, C>;
|
|
602
|
+
unit: Expr<"week" | "day" | "month" | "year", D, C>;
|
|
603
|
+
}) => Expr<number, D, C>;
|
|
604
|
+
|
|
605
|
+
declare const ite: {
|
|
606
|
+
<T, D, C = unknown>(cond: Expr<unknown, D, C>, then: Expr<T, D, C>, orelse: Expr<T, D, C>): Expr<T, D, C>;
|
|
607
|
+
<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>;
|
|
608
|
+
};
|
|
609
|
+
declare const and: <D, C = unknown>(...expr: Expr<boolean, D, C>[]) => Expr<boolean, D, C>;
|
|
610
|
+
declare const or: <D, C = unknown>(...expr: Expr<boolean, D, C>[]) => Expr<boolean, D, C>;
|
|
611
|
+
declare const not: <D, C = unknown>(expr: Expr<boolean, D, C>) => Expr<boolean, D, C>;
|
|
612
|
+
declare const eq: <T, D, C = unknown>(a: Expr<T, D, C>) => (b: Expr<T, D, C>) => Expr<boolean, D, C>;
|
|
613
|
+
declare const sub: <T, D, Ctx, P extends O>(a: Expr<T, D, Ctx>, f: Field<P, D, Ctx>) => Expr<T, P, Ctx>;
|
|
614
|
+
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>;
|
|
615
|
+
declare const ne: <T, D, C>(a: Expr<T, D, C>) => <K>(b: Expr<K, D, C>) => Expr<boolean, D, C>;
|
|
616
|
+
declare const notNull: <T, D, C>(a: Expr<T, D, C>) => Expr<boolean, D, C>;
|
|
617
|
+
declare const $ifNull: <R, D, C>(...expr: [...Expr<R | null | undefined, D, C>[], Expr<R, D, C>]) => Expr<R, D, C>;
|
|
618
|
+
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>;
|
|
619
|
+
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>;
|
|
620
|
+
declare const setField: <K extends string, T, V, D, C>({ field, input, value, }: {
|
|
621
|
+
field: Expr<K, D, C>;
|
|
622
|
+
input: Expr<T, D, C>;
|
|
623
|
+
value: Expr<V, D, C>;
|
|
624
|
+
}) => Expr<T & Record<K, V>, D, C>;
|
|
625
|
+
|
|
626
|
+
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>;
|
|
627
|
+
declare const $map0: <K extends string, T, R, D, C>({ as, expr, input, }: {
|
|
628
|
+
input: Expr<Arr<T>, D, C>;
|
|
629
|
+
as: K;
|
|
630
|
+
expr: Expr<R, D, RORec<K, T> & C>;
|
|
631
|
+
}) => Expr<Arr<R>, D, C>;
|
|
632
|
+
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>;
|
|
633
|
+
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>;
|
|
634
|
+
|
|
635
|
+
declare class Machine<Result = unknown> {
|
|
636
|
+
private sources;
|
|
637
|
+
constructor(root?: Iterator<Result, HasJob>);
|
|
638
|
+
add(x: Iterator<Result, HasJob>): void;
|
|
639
|
+
runner(): Iterator<Result, HasJob>;
|
|
640
|
+
start(cb?: (info: HasJob) => void | boolean): Promise<never>;
|
|
641
|
+
}
|
|
642
|
+
declare const wrap: <Result>(root: Machine<Result>) => Machine<Result>;
|
|
643
|
+
|
|
644
|
+
declare const $eq: <T extends unknown>(operand: rawItem & T) => Predicate<T>;
|
|
645
|
+
declare const $ne: <T extends unknown>(operand: rawItem & T) => Predicate<T>;
|
|
646
|
+
type Numeric = number | Timestamp | Date;
|
|
647
|
+
declare const comp: <D2 extends Numeric = Numeric>(op: "$gt" | "$gte" | "$lt" | "$lte") => <T extends Numeric>(operand: rawItem & D2) => Predicate<D2>;
|
|
648
|
+
declare const $gt: <T extends Numeric>(operand: rawItem & Numeric) => Predicate<Numeric>;
|
|
649
|
+
declare const $gtTs: <T extends Numeric>(operand: rawItem & Timestamp) => Predicate<Timestamp>;
|
|
650
|
+
declare const $gteTs: <T extends Numeric>(operand: rawItem & Timestamp) => Predicate<Timestamp>;
|
|
651
|
+
declare const $lt: <T extends Numeric>(operand: rawItem & number) => Predicate<number>;
|
|
652
|
+
declare const dateLt: <T extends Numeric>(operand: rawItem & Date) => Predicate<Date>;
|
|
653
|
+
declare const $gte: <T extends Numeric>(operand: rawItem & number) => Predicate<number>;
|
|
654
|
+
declare const $lte: <T extends Numeric>(operand: rawItem & number) => Predicate<number>;
|
|
655
|
+
type MongoTypes = {
|
|
656
|
+
number: number;
|
|
657
|
+
array: readonly rawItem[];
|
|
658
|
+
string: string;
|
|
659
|
+
object: RawObj;
|
|
660
|
+
[i: number]: unknown;
|
|
661
|
+
};
|
|
662
|
+
type MongoTypeNames = keyof MongoTypes;
|
|
663
|
+
declare const $type: <T extends keyof MongoTypes>(operand: rawItem & readonly T[]) => Predicate<N | MongoTypes[T]>;
|
|
664
|
+
declare const $exists: <T extends keyof MongoTypes>(operand: rawItem & boolean) => Predicate<unknown>;
|
|
665
|
+
|
|
666
|
+
declare const $expr: <D extends O, C>(expr: Expr<boolean, D, C>) => Query<D, C>;
|
|
667
|
+
|
|
668
|
+
declare const $in: <T extends unknown>(operand: rawItem & readonly T[]) => Predicate<T>;
|
|
669
|
+
declare const $nin: <T extends unknown>(operand: rawItem & readonly T[]) => Predicate<T>;
|
|
670
|
+
|
|
671
|
+
type Many<T> = readonly (T | N)[];
|
|
672
|
+
type Combiner = {
|
|
673
|
+
<T extends O, C = unknown>(first: Query<T, C>, ...args: Many<Query<T, C>>): Query<T, C>;
|
|
674
|
+
<T extends O, C = unknown>(...args: Many<Query<T, C>>): Query<T, C> | undefined;
|
|
675
|
+
};
|
|
676
|
+
declare const $and: Combiner;
|
|
677
|
+
declare const $nor: Combiner;
|
|
678
|
+
declare const $or: Combiner;
|
|
679
|
+
|
|
680
|
+
declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Promise<Document>;
|
|
681
|
+
declare const prepare: (testName?: string) => Promise<MongoClient$1>;
|
|
682
|
+
declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
|
|
683
|
+
|
|
684
|
+
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, afterWriteTime, 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 };
|
|
685
|
+
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
|
@@ -81,9 +81,12 @@ const val = (val) => asExpr({
|
|
|
81
81
|
? { $literal: val }
|
|
82
82
|
: val),
|
|
83
83
|
});
|
|
84
|
-
const
|
|
84
|
+
const afterWriteTime = asExpr({
|
|
85
85
|
raw: () => asExprRaw(new Timestamp(0xffffffffffffffffn)),
|
|
86
86
|
});
|
|
87
|
+
const current = asExpr({
|
|
88
|
+
raw: () => asExprRaw('$$CLUSTER_TIME'),
|
|
89
|
+
});
|
|
87
90
|
const $let = (vars, inExpr) => asExpr({
|
|
88
91
|
raw: f => asExprRaw({
|
|
89
92
|
$let: {
|
|
@@ -842,7 +845,7 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
842
845
|
const setDeleted = out.whenNotMatched === 'discard';
|
|
843
846
|
const replacer = map(field(omitPick().backward(spread(patch, {
|
|
844
847
|
_id: ['_id', f.of('_id').expr()],
|
|
845
|
-
touchedAt: ['touchedAt',
|
|
848
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
846
849
|
}))));
|
|
847
850
|
const sss = setDeleted
|
|
848
851
|
? link()
|
|
@@ -886,7 +889,7 @@ const $mergeId = () => (out, keys, id, ext) => {
|
|
|
886
889
|
return $mergeX(out, keys, root().of('after'), or => {
|
|
887
890
|
return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
|
|
888
891
|
_id: ['_id', id],
|
|
889
|
-
touchedAt: ['touchedAt',
|
|
892
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
890
893
|
}))), or);
|
|
891
894
|
}, ext);
|
|
892
895
|
};
|
|
@@ -908,7 +911,7 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
908
911
|
const mapId = (k, v) => map1(k, v);
|
|
909
912
|
const F1 = {
|
|
910
913
|
_id: ['_id', to(idPrefix ? concat$1(val(idPrefix), $rand) : $rand)],
|
|
911
|
-
touchedAt: ['touchedAt', to(
|
|
914
|
+
touchedAt: ['touchedAt', to(afterWriteTime)],
|
|
912
915
|
};
|
|
913
916
|
const F2 = mapId(gid, to(gidPath));
|
|
914
917
|
const addExtraAndMerge = {
|
|
@@ -918,7 +921,8 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
918
921
|
};
|
|
919
922
|
const addTSAndExtra = {
|
|
920
923
|
...mapExact0(e, to),
|
|
921
|
-
|
|
924
|
+
...(out.whenNotMatched === 'insert' ? { deletedAt: ['deletedAt', to(nil)] } : {}),
|
|
925
|
+
touchedAt: ['touchedAt', to(afterWriteTime)],
|
|
922
926
|
};
|
|
923
927
|
const updater = set()(addTSAndExtra);
|
|
924
928
|
const whenMatched = getWhenMatched(out.whenNotMatched);
|
|
@@ -1272,7 +1276,7 @@ const createIndex = async (collection, indexSpec, op) => {
|
|
|
1272
1276
|
};
|
|
1273
1277
|
const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
1274
1278
|
const log = () => { };
|
|
1275
|
-
log('Creating index', { collection: collection.collectionName
|
|
1279
|
+
log('Creating index', { collection: collection.collectionName});
|
|
1276
1280
|
while (true) {
|
|
1277
1281
|
try {
|
|
1278
1282
|
await collection.createIndex(indexSpec, options);
|
|
@@ -1280,7 +1284,8 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1280
1284
|
}
|
|
1281
1285
|
catch (e) {
|
|
1282
1286
|
if ([85, 276].includes(e.code)) {
|
|
1283
|
-
log('Index created with different name', e.code, {
|
|
1287
|
+
log('Index created with different name', e.code, {
|
|
1288
|
+
collection: collection.collectionName});
|
|
1284
1289
|
break;
|
|
1285
1290
|
}
|
|
1286
1291
|
if (e.code == 12587) {
|
|
@@ -1288,17 +1293,18 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1288
1293
|
continue;
|
|
1289
1294
|
}
|
|
1290
1295
|
log('Error creating index', {
|
|
1291
|
-
collection: collection.collectionName
|
|
1292
|
-
indexSpec,
|
|
1293
|
-
options,
|
|
1294
|
-
error: e,
|
|
1295
|
-
});
|
|
1296
|
+
collection: collection.collectionName});
|
|
1296
1297
|
console.error('Error creating index', e);
|
|
1297
1298
|
throw e;
|
|
1298
1299
|
}
|
|
1299
1300
|
break;
|
|
1300
1301
|
}
|
|
1301
1302
|
};
|
|
1303
|
+
const ensureCollection = async (db, collectionName) => {
|
|
1304
|
+
if (!(await db.listCollections({ name: collectionName }, { nameOnly: true }).next())) {
|
|
1305
|
+
await db.createCollection(collectionName);
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1302
1308
|
|
|
1303
1309
|
const patch = ({ ...x }, k, v) => {
|
|
1304
1310
|
delete x[k];
|
|
@@ -1370,7 +1376,7 @@ const firstWorksMerge = (iters) => {
|
|
|
1370
1376
|
const sources = { ...results };
|
|
1371
1377
|
return mergeIterators({
|
|
1372
1378
|
sources,
|
|
1373
|
-
interrupt: key =>
|
|
1379
|
+
interrupt: key => false,
|
|
1374
1380
|
hooks: {
|
|
1375
1381
|
start: (frame, result) => {
|
|
1376
1382
|
if (!frame.info.job)
|
|
@@ -1534,7 +1540,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
|
|
|
1534
1540
|
raw: () => {
|
|
1535
1541
|
const replacer = map(mergeObjects(expr, field(mergeExpr(extExpr, {
|
|
1536
1542
|
deletedAt: ['deletedAt', nil],
|
|
1537
|
-
touchedAt: ['touchedAt',
|
|
1543
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
1538
1544
|
}))));
|
|
1539
1545
|
return link()
|
|
1540
1546
|
.with($replaceWith_(replacer))
|
|
@@ -1554,7 +1560,7 @@ const $insertPart = (out, ext) => {
|
|
|
1554
1560
|
return $insertX(out, assertNotNull(root().of('after').expr()), x => ite(eq(root().of('after').expr())(nil), field(mergeExpr(translateOmit().forward(extExpr), {
|
|
1555
1561
|
deletedAt: ['deletedAt', current],
|
|
1556
1562
|
_id: ['_id', assertNotNull(root().of('before').of('_id').expr())],
|
|
1557
|
-
touchedAt: ['touchedAt',
|
|
1563
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
1558
1564
|
})), x), ext, extExpr);
|
|
1559
1565
|
};
|
|
1560
1566
|
const $insert = (out) => $insertPart(out, {});
|
|
@@ -1569,14 +1575,18 @@ const aggregate = (db, streamName, input, snapshot = true, start = Date.now()) =
|
|
|
1569
1575
|
};
|
|
1570
1576
|
log('exec', streamName, req);
|
|
1571
1577
|
const start2 = Date.now();
|
|
1572
|
-
return db
|
|
1578
|
+
return db
|
|
1579
|
+
.then(d => d.command(req))
|
|
1580
|
+
.then(result => {
|
|
1573
1581
|
log('prepare', streamName, Date.now() - start);
|
|
1574
1582
|
log('prepare2', streamName, start2 - start);
|
|
1575
1583
|
const r = result;
|
|
1576
1584
|
log('execed', streamName, (replace) => replace(JSON.stringify(req).replaceAll('"$$CLUSTER_TIME"', JSON.stringify(r.cursor.atClusterTime))), result, 'took', Date.now() - start);
|
|
1577
1585
|
return r;
|
|
1578
|
-
}, err => {
|
|
1586
|
+
}, async (err) => {
|
|
1579
1587
|
log('err', req, err);
|
|
1588
|
+
console.error(err);
|
|
1589
|
+
await new Promise(() => { });
|
|
1580
1590
|
throw new Error(err);
|
|
1581
1591
|
});
|
|
1582
1592
|
});
|
|
@@ -1718,16 +1728,7 @@ const loop = async (db) => {
|
|
|
1718
1728
|
}
|
|
1719
1729
|
continue;
|
|
1720
1730
|
}
|
|
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);
|
|
1731
|
+
const groups = Object.groupBy(events.filter(e => e.changeTouched), ev => ev.doc.ns);
|
|
1731
1732
|
for (const [ns, evs] of Object.entries(groups)) {
|
|
1732
1733
|
if (!evs)
|
|
1733
1734
|
continue;
|
|
@@ -1976,6 +1977,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
1976
1977
|
partialFilterExpression: { updated: true, after: null, before: null },
|
|
1977
1978
|
name: 'updated_nulls_' + new UUID().toString('base64'),
|
|
1978
1979
|
});
|
|
1980
|
+
await ensureCollection(db, coll);
|
|
1979
1981
|
await db.command({
|
|
1980
1982
|
collMod: coll,
|
|
1981
1983
|
changeStreamPreAndPostImages: { enabled: true },
|
|
@@ -2157,6 +2159,7 @@ const executes$1 = (view, input, streamName, needs) => {
|
|
|
2157
2159
|
const stop = withStop(step0);
|
|
2158
2160
|
const step1 = async () => {
|
|
2159
2161
|
log('creating indexes');
|
|
2162
|
+
await ensureCollection(db, coll);
|
|
2160
2163
|
await db.command({
|
|
2161
2164
|
collMod: coll,
|
|
2162
2165
|
changeStreamPreAndPostImages: { enabled: true },
|
|
@@ -2247,4 +2250,4 @@ const executes = (view, input, needs) => {
|
|
|
2247
2250
|
};
|
|
2248
2251
|
const single = (view, needs = {}) => pipe(input => executes(view, input, needs), emptyDelta(), concatDelta, emptyDelta);
|
|
2249
2252
|
|
|
2250
|
-
export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, getWhenMatched, 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 };
|
|
2253
|
+
export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, afterWriteTime, and, anyElementTrue, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, getWhenMatched, 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 };
|
package/index.js
CHANGED
|
@@ -83,9 +83,12 @@ const val = (val) => asExpr({
|
|
|
83
83
|
? { $literal: val }
|
|
84
84
|
: val),
|
|
85
85
|
});
|
|
86
|
-
const
|
|
86
|
+
const afterWriteTime = asExpr({
|
|
87
87
|
raw: () => asExprRaw(new mongodb.Timestamp(0xffffffffffffffffn)),
|
|
88
88
|
});
|
|
89
|
+
const current = asExpr({
|
|
90
|
+
raw: () => asExprRaw('$$CLUSTER_TIME'),
|
|
91
|
+
});
|
|
89
92
|
const $let = (vars, inExpr) => asExpr({
|
|
90
93
|
raw: f => asExprRaw({
|
|
91
94
|
$let: {
|
|
@@ -844,7 +847,7 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
844
847
|
const setDeleted = out.whenNotMatched === 'discard';
|
|
845
848
|
const replacer = map(field(omitPick().backward(spread(patch, {
|
|
846
849
|
_id: ['_id', f.of('_id').expr()],
|
|
847
|
-
touchedAt: ['touchedAt',
|
|
850
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
848
851
|
}))));
|
|
849
852
|
const sss = setDeleted
|
|
850
853
|
? link()
|
|
@@ -888,7 +891,7 @@ const $mergeId = () => (out, keys, id, ext) => {
|
|
|
888
891
|
return $mergeX(out, keys, root().of('after'), or => {
|
|
889
892
|
return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
|
|
890
893
|
_id: ['_id', id],
|
|
891
|
-
touchedAt: ['touchedAt',
|
|
894
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
892
895
|
}))), or);
|
|
893
896
|
}, ext);
|
|
894
897
|
};
|
|
@@ -910,7 +913,7 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
910
913
|
const mapId = (k, v) => map1(k, v);
|
|
911
914
|
const F1 = {
|
|
912
915
|
_id: ['_id', to(idPrefix ? concat$1(val(idPrefix), $rand) : $rand)],
|
|
913
|
-
touchedAt: ['touchedAt', to(
|
|
916
|
+
touchedAt: ['touchedAt', to(afterWriteTime)],
|
|
914
917
|
};
|
|
915
918
|
const F2 = mapId(gid, to(gidPath));
|
|
916
919
|
const addExtraAndMerge = {
|
|
@@ -920,7 +923,8 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
920
923
|
};
|
|
921
924
|
const addTSAndExtra = {
|
|
922
925
|
...mapExact0(e, to),
|
|
923
|
-
|
|
926
|
+
...(out.whenNotMatched === 'insert' ? { deletedAt: ['deletedAt', to(nil)] } : {}),
|
|
927
|
+
touchedAt: ['touchedAt', to(afterWriteTime)],
|
|
924
928
|
};
|
|
925
929
|
const updater = set()(addTSAndExtra);
|
|
926
930
|
const whenMatched = getWhenMatched(out.whenNotMatched);
|
|
@@ -1274,7 +1278,7 @@ const createIndex = async (collection, indexSpec, op) => {
|
|
|
1274
1278
|
};
|
|
1275
1279
|
const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
1276
1280
|
const log = () => { };
|
|
1277
|
-
log('Creating index', { collection: collection.collectionName
|
|
1281
|
+
log('Creating index', { collection: collection.collectionName});
|
|
1278
1282
|
while (true) {
|
|
1279
1283
|
try {
|
|
1280
1284
|
await collection.createIndex(indexSpec, options);
|
|
@@ -1282,7 +1286,8 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1282
1286
|
}
|
|
1283
1287
|
catch (e) {
|
|
1284
1288
|
if ([85, 276].includes(e.code)) {
|
|
1285
|
-
log('Index created with different name', e.code, {
|
|
1289
|
+
log('Index created with different name', e.code, {
|
|
1290
|
+
collection: collection.collectionName});
|
|
1286
1291
|
break;
|
|
1287
1292
|
}
|
|
1288
1293
|
if (e.code == 12587) {
|
|
@@ -1290,17 +1295,18 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1290
1295
|
continue;
|
|
1291
1296
|
}
|
|
1292
1297
|
log('Error creating index', {
|
|
1293
|
-
collection: collection.collectionName
|
|
1294
|
-
indexSpec,
|
|
1295
|
-
options,
|
|
1296
|
-
error: e,
|
|
1297
|
-
});
|
|
1298
|
+
collection: collection.collectionName});
|
|
1298
1299
|
console.error('Error creating index', e);
|
|
1299
1300
|
throw e;
|
|
1300
1301
|
}
|
|
1301
1302
|
break;
|
|
1302
1303
|
}
|
|
1303
1304
|
};
|
|
1305
|
+
const ensureCollection = async (db, collectionName) => {
|
|
1306
|
+
if (!(await db.listCollections({ name: collectionName }, { nameOnly: true }).next())) {
|
|
1307
|
+
await db.createCollection(collectionName);
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1304
1310
|
|
|
1305
1311
|
const patch = ({ ...x }, k, v) => {
|
|
1306
1312
|
delete x[k];
|
|
@@ -1372,7 +1378,7 @@ const firstWorksMerge = (iters) => {
|
|
|
1372
1378
|
const sources = { ...results };
|
|
1373
1379
|
return mergeIterators({
|
|
1374
1380
|
sources,
|
|
1375
|
-
interrupt: key =>
|
|
1381
|
+
interrupt: key => false,
|
|
1376
1382
|
hooks: {
|
|
1377
1383
|
start: (frame, result) => {
|
|
1378
1384
|
if (!frame.info.job)
|
|
@@ -1536,7 +1542,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
|
|
|
1536
1542
|
raw: () => {
|
|
1537
1543
|
const replacer = map(mergeObjects(expr, field(mergeExpr(extExpr, {
|
|
1538
1544
|
deletedAt: ['deletedAt', nil],
|
|
1539
|
-
touchedAt: ['touchedAt',
|
|
1545
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
1540
1546
|
}))));
|
|
1541
1547
|
return link()
|
|
1542
1548
|
.with($replaceWith_(replacer))
|
|
@@ -1556,7 +1562,7 @@ const $insertPart = (out, ext) => {
|
|
|
1556
1562
|
return $insertX(out, assertNotNull(root().of('after').expr()), x => ite(eq(root().of('after').expr())(nil), field(mergeExpr(translateOmit().forward(extExpr), {
|
|
1557
1563
|
deletedAt: ['deletedAt', current],
|
|
1558
1564
|
_id: ['_id', assertNotNull(root().of('before').of('_id').expr())],
|
|
1559
|
-
touchedAt: ['touchedAt',
|
|
1565
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
1560
1566
|
})), x), ext, extExpr);
|
|
1561
1567
|
};
|
|
1562
1568
|
const $insert = (out) => $insertPart(out, {});
|
|
@@ -1571,14 +1577,18 @@ const aggregate = (db, streamName, input, snapshot = true, start = Date.now()) =
|
|
|
1571
1577
|
};
|
|
1572
1578
|
log('exec', streamName, req);
|
|
1573
1579
|
const start2 = Date.now();
|
|
1574
|
-
return db
|
|
1580
|
+
return db
|
|
1581
|
+
.then(d => d.command(req))
|
|
1582
|
+
.then(result => {
|
|
1575
1583
|
log('prepare', streamName, Date.now() - start);
|
|
1576
1584
|
log('prepare2', streamName, start2 - start);
|
|
1577
1585
|
const r = result;
|
|
1578
1586
|
log('execed', streamName, (replace) => replace(JSON.stringify(req).replaceAll('"$$CLUSTER_TIME"', JSON.stringify(r.cursor.atClusterTime))), result, 'took', Date.now() - start);
|
|
1579
1587
|
return r;
|
|
1580
|
-
}, err => {
|
|
1588
|
+
}, async (err) => {
|
|
1581
1589
|
log('err', req, err);
|
|
1590
|
+
console.error(err);
|
|
1591
|
+
await new Promise(() => { });
|
|
1582
1592
|
throw new Error(err);
|
|
1583
1593
|
});
|
|
1584
1594
|
});
|
|
@@ -1720,16 +1730,7 @@ const loop = async (db) => {
|
|
|
1720
1730
|
}
|
|
1721
1731
|
continue;
|
|
1722
1732
|
}
|
|
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);
|
|
1733
|
+
const groups = Object.groupBy(events.filter(e => e.changeTouched), ev => ev.doc.ns);
|
|
1733
1734
|
for (const [ns, evs] of Object.entries(groups)) {
|
|
1734
1735
|
if (!evs)
|
|
1735
1736
|
continue;
|
|
@@ -1978,6 +1979,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
1978
1979
|
partialFilterExpression: { updated: true, after: null, before: null },
|
|
1979
1980
|
name: 'updated_nulls_' + new mongodb.UUID().toString('base64'),
|
|
1980
1981
|
});
|
|
1982
|
+
await ensureCollection(db, coll);
|
|
1981
1983
|
await db.command({
|
|
1982
1984
|
collMod: coll,
|
|
1983
1985
|
changeStreamPreAndPostImages: { enabled: true },
|
|
@@ -2159,6 +2161,7 @@ const executes$1 = (view, input, streamName, needs) => {
|
|
|
2159
2161
|
const stop = withStop(step0);
|
|
2160
2162
|
const step1 = async () => {
|
|
2161
2163
|
log('creating indexes');
|
|
2164
|
+
await ensureCollection(db, coll);
|
|
2162
2165
|
await db.command({
|
|
2163
2166
|
collMod: coll,
|
|
2164
2167
|
changeStreamPreAndPostImages: { enabled: true },
|
|
@@ -2305,6 +2308,7 @@ exports.$unwindDelta = $unwindDelta;
|
|
|
2305
2308
|
exports.Field = Field;
|
|
2306
2309
|
exports.Machine = Machine;
|
|
2307
2310
|
exports.add = add;
|
|
2311
|
+
exports.afterWriteTime = afterWriteTime;
|
|
2308
2312
|
exports.and = and;
|
|
2309
2313
|
exports.anyElementTrue = anyElementTrue;
|
|
2310
2314
|
exports.array = array;
|