@jarenjs/linq 0.34.0
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/README.md +63 -0
- package/docs/LINQ-FORMAT.md +382 -0
- package/package.json +53 -0
- package/src/async.js +599 -0
- package/src/concurrency.js +213 -0
- package/src/document.js +212 -0
- package/src/errors.js +94 -0
- package/src/expression.js +320 -0
- package/src/index.js +14 -0
- package/src/provider.js +166 -0
- package/src/sequence.js +543 -0
- package/src/sources.js +98 -0
- package/types/index.d.ts +430 -0
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-authored declarations for @jarenjs/linq — the deliberate type
|
|
3
|
+
* surface (hand-authored declarations chosen over emitting them from
|
|
4
|
+
* JSDoc): the implementation stays plain JSDoc'd JavaScript, and this
|
|
5
|
+
* file is the public type contract. The anti-drift
|
|
6
|
+
* rule: every claim here has a runtime twin in `test/linq/types.test.js`
|
|
7
|
+
* and a compile-level pin in `test/consumer/types.ts`.
|
|
8
|
+
*
|
|
9
|
+
* THE LINE (also in the README): the common path is precisely typed;
|
|
10
|
+
* the exotic path is honestly `unknown`; nothing is ever a WRONG type.
|
|
11
|
+
* Constructs beyond inference degrade to `UnknownExpr`/`unknown`, by
|
|
12
|
+
* name, never to a lie.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The nominal date-time brand: annotate a model property as `DateTime`
|
|
17
|
+
* and the date operators (`year()`, `month()`, `day()`, `epoch()`)
|
|
18
|
+
* become available on its expression without making EVERY string a
|
|
19
|
+
* date. Purely a type-level marker — the runtime value is a plain
|
|
20
|
+
* RFC 3339 string; there is no constructor and no runtime cost.
|
|
21
|
+
*/
|
|
22
|
+
export type DateTime = string & { readonly __jarenTag: 'date-time' };
|
|
23
|
+
|
|
24
|
+
/** The phantom carrier every expression type extends: `__value` never
|
|
25
|
+
* exists at runtime; it lets projections infer their unwrapped shape. */
|
|
26
|
+
export interface ExprBase<V> {
|
|
27
|
+
readonly __value?: V;
|
|
28
|
+
/** `$exists` — the expression yields at least one item. */
|
|
29
|
+
exists(): BoolExpr;
|
|
30
|
+
/** `$empty` — the expression yields no items. */
|
|
31
|
+
isEmpty(): BoolExpr;
|
|
32
|
+
/** Dynamic member lookup (`$get`, or a bracketed path segment):
|
|
33
|
+
* the escape for non-identifier keys and method-name collisions. */
|
|
34
|
+
get(name: string | number): UnknownExpr;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Equality over the exact operand family; `null` compares per the
|
|
38
|
+
* documented empty/absent semantics. */
|
|
39
|
+
interface EqExpr<V> {
|
|
40
|
+
eq(value: V | ExprBase<V> | null): BoolExpr;
|
|
41
|
+
ne(value: V | ExprBase<V> | null): BoolExpr;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface BoolExpr extends ExprBase<boolean>, EqExpr<boolean> {
|
|
45
|
+
and(other: boolean | BoolExpr): BoolExpr;
|
|
46
|
+
or(other: boolean | BoolExpr): BoolExpr;
|
|
47
|
+
not(): BoolExpr;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface NumberExpr extends ExprBase<number>, EqExpr<number> {
|
|
51
|
+
lt(value: number | NumberExpr): BoolExpr;
|
|
52
|
+
le(value: number | NumberExpr): BoolExpr;
|
|
53
|
+
gt(value: number | NumberExpr): BoolExpr;
|
|
54
|
+
ge(value: number | NumberExpr): BoolExpr;
|
|
55
|
+
add(value: number | NumberExpr): NumberExpr;
|
|
56
|
+
sub(value: number | NumberExpr): NumberExpr;
|
|
57
|
+
mul(value: number | NumberExpr): NumberExpr;
|
|
58
|
+
div(value: number | NumberExpr): NumberExpr;
|
|
59
|
+
idiv(value: number | NumberExpr): NumberExpr;
|
|
60
|
+
mod(value: number | NumberExpr): NumberExpr;
|
|
61
|
+
neg(): NumberExpr;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface StringExpr extends ExprBase<string>, EqExpr<string> {
|
|
65
|
+
lt(value: string | StringExpr): BoolExpr;
|
|
66
|
+
le(value: string | StringExpr): BoolExpr;
|
|
67
|
+
gt(value: string | StringExpr): BoolExpr;
|
|
68
|
+
ge(value: string | StringExpr): BoolExpr;
|
|
69
|
+
startsWith(value: string | StringExpr): BoolExpr;
|
|
70
|
+
endsWith(value: string | StringExpr): BoolExpr;
|
|
71
|
+
contains(value: string | StringExpr): BoolExpr;
|
|
72
|
+
/** I-Regexp (RFC 9485) full match. */
|
|
73
|
+
matches(pattern: string): BoolExpr;
|
|
74
|
+
upper(): StringExpr;
|
|
75
|
+
lower(): StringExpr;
|
|
76
|
+
length(): NumberExpr;
|
|
77
|
+
concat(value: string | StringExpr): StringExpr;
|
|
78
|
+
substring(start: number, length?: number): StringExpr;
|
|
79
|
+
replace(pattern: string, replacement: string): StringExpr;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A `DateTime`-branded string: the string surface plus the date
|
|
83
|
+
* component operators. */
|
|
84
|
+
export interface DateTimeExpr extends ExprBase<DateTime> {
|
|
85
|
+
eq(value: string | DateTimeExpr | null): BoolExpr;
|
|
86
|
+
ne(value: string | DateTimeExpr | null): BoolExpr;
|
|
87
|
+
lt(value: string | DateTimeExpr): BoolExpr;
|
|
88
|
+
le(value: string | DateTimeExpr): BoolExpr;
|
|
89
|
+
gt(value: string | DateTimeExpr): BoolExpr;
|
|
90
|
+
ge(value: string | DateTimeExpr): BoolExpr;
|
|
91
|
+
year(): NumberExpr;
|
|
92
|
+
month(): NumberExpr;
|
|
93
|
+
day(): NumberExpr;
|
|
94
|
+
/** Epoch milliseconds (`$epoch`). */
|
|
95
|
+
epoch(): NumberExpr;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface ArrayExpr<E> extends ExprBase<E[]> {
|
|
99
|
+
eq(value: readonly E[] | ArrayExpr<E> | null): BoolExpr;
|
|
100
|
+
ne(value: readonly E[] | ArrayExpr<E> | null): BoolExpr;
|
|
101
|
+
/** Fan the elements out (`[*]`) — a MANY-cardinality expression the
|
|
102
|
+
* aggregates apply to (`u.tags.all().count()`). */
|
|
103
|
+
all(): Expr<E> & AggregatableExpr;
|
|
104
|
+
/** The element at a 0-based index; negative counts from the end. */
|
|
105
|
+
at(index: number): Expr<E>;
|
|
106
|
+
/** `$count` over the fanned elements requires `all()` first; this
|
|
107
|
+
* counts the ARRAY as one item — see the format doc. */
|
|
108
|
+
count(): NumberExpr;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Aggregates available on any expression (a fanned path, a group). */
|
|
112
|
+
export interface AggregatableExpr {
|
|
113
|
+
count(): NumberExpr;
|
|
114
|
+
sum(): NumberExpr;
|
|
115
|
+
avg(): NumberExpr;
|
|
116
|
+
min(): UnknownExpr;
|
|
117
|
+
max(): UnknownExpr;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** An object's expression: exactly its properties, recursively typed —
|
|
121
|
+
* which is what makes a misspelled member a compile error. */
|
|
122
|
+
export type ObjectExpr<T> = ExprBase<T> & EqExpr<T> & {
|
|
123
|
+
readonly [K in keyof T & string]-?: Expr<NonNullable<T[K]>>;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** The honest top: everything is available, nothing is precise. Used
|
|
127
|
+
* where inference ends (dynamic `get`, post-operator members, unknown
|
|
128
|
+
* elements) — wide, never wrong. */
|
|
129
|
+
export interface UnknownExpr extends ExprBase<unknown>, AggregatableExpr {
|
|
130
|
+
eq(value: unknown): BoolExpr;
|
|
131
|
+
ne(value: unknown): BoolExpr;
|
|
132
|
+
lt(value: unknown): BoolExpr;
|
|
133
|
+
le(value: unknown): BoolExpr;
|
|
134
|
+
gt(value: unknown): BoolExpr;
|
|
135
|
+
ge(value: unknown): BoolExpr;
|
|
136
|
+
and(other: unknown): BoolExpr;
|
|
137
|
+
or(other: unknown): BoolExpr;
|
|
138
|
+
not(): BoolExpr;
|
|
139
|
+
add(value: unknown): UnknownExpr;
|
|
140
|
+
sub(value: unknown): UnknownExpr;
|
|
141
|
+
mul(value: unknown): UnknownExpr;
|
|
142
|
+
div(value: unknown): UnknownExpr;
|
|
143
|
+
idiv(value: unknown): UnknownExpr;
|
|
144
|
+
mod(value: unknown): UnknownExpr;
|
|
145
|
+
neg(): UnknownExpr;
|
|
146
|
+
startsWith(value: unknown): BoolExpr;
|
|
147
|
+
endsWith(value: unknown): BoolExpr;
|
|
148
|
+
contains(value: unknown): BoolExpr;
|
|
149
|
+
matches(pattern: string): BoolExpr;
|
|
150
|
+
upper(): UnknownExpr;
|
|
151
|
+
lower(): UnknownExpr;
|
|
152
|
+
length(): NumberExpr;
|
|
153
|
+
concat(value: unknown): UnknownExpr;
|
|
154
|
+
substring(start: number, length?: number): UnknownExpr;
|
|
155
|
+
replace(pattern: string, replacement: string): UnknownExpr;
|
|
156
|
+
year(): NumberExpr;
|
|
157
|
+
month(): NumberExpr;
|
|
158
|
+
day(): NumberExpr;
|
|
159
|
+
epoch(): NumberExpr;
|
|
160
|
+
all(): UnknownExpr;
|
|
161
|
+
at(index: number): UnknownExpr;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Value type → expression type. Order matters: the DateTime brand is
|
|
165
|
+
* a string subtype and must match first. */
|
|
166
|
+
export type Expr<T> =
|
|
167
|
+
[T] extends [DateTime] ? DateTimeExpr :
|
|
168
|
+
[T] extends [string] ? StringExpr :
|
|
169
|
+
[T] extends [number] ? NumberExpr :
|
|
170
|
+
[T] extends [boolean] ? BoolExpr :
|
|
171
|
+
[T] extends [readonly (infer E)[]] ? ArrayExpr<E> :
|
|
172
|
+
[T] extends [object] ? ObjectExpr<T> :
|
|
173
|
+
UnknownExpr;
|
|
174
|
+
|
|
175
|
+
/** The parameters proxy: exactly the declared names, each typed. */
|
|
176
|
+
export type ParamsExpr<P> = {
|
|
177
|
+
readonly [K in keyof P & string]-?: Expr<NonNullable<P[K]>>;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** Unwrap a captured projection back to its VALUE shape: expressions
|
|
181
|
+
* by their phantom, object/array literals recursively, literals as
|
|
182
|
+
* themselves. */
|
|
183
|
+
export type Unwrap<R> =
|
|
184
|
+
R extends ExprBase<infer V> ? V :
|
|
185
|
+
R extends readonly (infer E)[] ? Unwrap<E>[] :
|
|
186
|
+
R extends object ? { [K in keyof R]: Unwrap<R[K]> } :
|
|
187
|
+
R;
|
|
188
|
+
|
|
189
|
+
/** A multi-item projection flattens (`selectMany`). */
|
|
190
|
+
type Element<V> = V extends readonly (infer E)[] ? E : V;
|
|
191
|
+
|
|
192
|
+
/** Any expression-ish callback result the runtime accepts. */
|
|
193
|
+
type ExprResult = ExprBase<unknown> | object | string | number | boolean | null;
|
|
194
|
+
|
|
195
|
+
export interface OrderOptions {
|
|
196
|
+
/** `$empty` — where empty keys sort: `'least'` (default) or `'greatest'`. */
|
|
197
|
+
empty?: 'least' | 'greatest';
|
|
198
|
+
/** `$collation` — a registered collation name. */
|
|
199
|
+
collation?: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** The provider contract (D2): any object exposing
|
|
203
|
+
* `execute(document, options)`. The document arrives whole; the return
|
|
204
|
+
* value uses the engine's result mapping. */
|
|
205
|
+
export interface Provider {
|
|
206
|
+
execute(document: unknown, options: { externals: Record<string, unknown> }): unknown;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface LinqOptions {
|
|
210
|
+
/** Enables `ofType`/`cast` (schema operators); e.g.
|
|
211
|
+
* `createTypeTestCompiler()` from `@jarenjs/validate/query`. */
|
|
212
|
+
compileTypeTest?: (schema: unknown, docPath: string) => (value: unknown) => boolean;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface Explanation {
|
|
216
|
+
document: unknown;
|
|
217
|
+
externals: string[];
|
|
218
|
+
dependencies: {
|
|
219
|
+
readonly externals: readonly string[];
|
|
220
|
+
readonly operators: readonly string[];
|
|
221
|
+
readonly functions: readonly string[];
|
|
222
|
+
readonly collations: readonly string[];
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** The deferred, immutable sequence of `T` with declared params `P`. */
|
|
227
|
+
export class Sequence<T = unknown, P = {}> {
|
|
228
|
+
private constructor();
|
|
229
|
+
|
|
230
|
+
where(predicate: (it: Expr<T>, p: ParamsExpr<P>) => BoolExpr | boolean): Sequence<T, P>;
|
|
231
|
+
select<R extends ExprResult>(projection: (it: Expr<T>, p: ParamsExpr<P>) => R): Sequence<Unwrap<R>, P>;
|
|
232
|
+
selectMany<R extends ExprResult>(selector: (it: Expr<T>, p: ParamsExpr<P>) => R): Sequence<Element<Unwrap<R>>, P>;
|
|
233
|
+
|
|
234
|
+
orderBy(key: (it: Expr<T>, p: ParamsExpr<P>) => ExprResult, options?: OrderOptions): Sequence<T, P>;
|
|
235
|
+
orderByDescending(key: (it: Expr<T>, p: ParamsExpr<P>) => ExprResult, options?: OrderOptions): Sequence<T, P>;
|
|
236
|
+
thenBy(key: (it: Expr<T>, p: ParamsExpr<P>) => ExprResult, options?: OrderOptions): Sequence<T, P>;
|
|
237
|
+
thenByDescending(key: (it: Expr<T>, p: ParamsExpr<P>) => ExprResult, options?: OrderOptions): Sequence<T, P>;
|
|
238
|
+
|
|
239
|
+
groupBy<R extends ExprResult>(key: (it: Expr<T>, p: ParamsExpr<P>) => R):
|
|
240
|
+
Sequence<{ key: Unwrap<R> | null, items: T[] }, P>;
|
|
241
|
+
|
|
242
|
+
join<U, R extends ExprResult>(
|
|
243
|
+
inner: Sequence<U, any>,
|
|
244
|
+
outerKey: (it: Expr<T>, p: ParamsExpr<P>) => ExprResult,
|
|
245
|
+
innerKey: (it: Expr<U>, p: ParamsExpr<P>) => ExprResult,
|
|
246
|
+
result: (outer: Expr<T>, inner: Expr<U>, p: ParamsExpr<P>) => R,
|
|
247
|
+
): Sequence<Unwrap<R>, P>;
|
|
248
|
+
|
|
249
|
+
groupJoin<U, R extends ExprResult>(
|
|
250
|
+
inner: Sequence<U, any>,
|
|
251
|
+
outerKey: (it: Expr<T>, p: ParamsExpr<P>) => ExprResult,
|
|
252
|
+
innerKey: (it: Expr<U>, p: ParamsExpr<P>) => ExprResult,
|
|
253
|
+
result: (outer: Expr<T>, group: ArrayExpr<U> & AggregatableExpr, p: ParamsExpr<P>) => R,
|
|
254
|
+
): Sequence<Unwrap<R>, P>;
|
|
255
|
+
|
|
256
|
+
/** The seeded fold; the sequence of exactly one accumulated value. */
|
|
257
|
+
aggregate<A>(seed: A, step: (acc: Expr<A>, it: Expr<T>, p: ParamsExpr<P>) => ExprResult): Sequence<A, P>;
|
|
258
|
+
|
|
259
|
+
skip(count: number): Sequence<T, P>;
|
|
260
|
+
take(count: number): Sequence<T, P>;
|
|
261
|
+
distinct(): Sequence<T, P>;
|
|
262
|
+
reverse(): Sequence<T, P>;
|
|
263
|
+
concat(other: Sequence<T, any> | readonly T[]): Sequence<T, P>;
|
|
264
|
+
defaultIfEmpty(fallback?: T | null): Sequence<T | null, P>;
|
|
265
|
+
|
|
266
|
+
/** Keep items the schema accepts. `S` is caller-asserted (a JSON
|
|
267
|
+
* Schema is not a TypeScript type); the default is honest `unknown`. */
|
|
268
|
+
ofType<S = unknown>(schema: object): Sequence<S, P>;
|
|
269
|
+
cast<S = unknown>(schema: object): Sequence<S, P>;
|
|
270
|
+
|
|
271
|
+
/** Recorded unsupported: throws `JL0006`. */
|
|
272
|
+
zip(...args: never[]): never;
|
|
273
|
+
|
|
274
|
+
params<Q extends Record<string, unknown>>(bindings: Q): Sequence<T, P & Q>;
|
|
275
|
+
|
|
276
|
+
toDocument(): unknown;
|
|
277
|
+
explain(): Explanation;
|
|
278
|
+
|
|
279
|
+
toArray(): T[];
|
|
280
|
+
[Symbol.iterator](): Iterator<T>;
|
|
281
|
+
|
|
282
|
+
first(): T;
|
|
283
|
+
firstOrDefault(): T | undefined;
|
|
284
|
+
firstOrDefault<D>(defaultValue: D): T | D;
|
|
285
|
+
single(): T;
|
|
286
|
+
singleOrDefault(): T | undefined;
|
|
287
|
+
singleOrDefault<D>(defaultValue: D): T | D;
|
|
288
|
+
last(): T;
|
|
289
|
+
lastOrDefault(): T | undefined;
|
|
290
|
+
lastOrDefault<D>(defaultValue: D): T | D;
|
|
291
|
+
elementAt(index: number): T;
|
|
292
|
+
elementAtOrDefault(index: number): T | undefined;
|
|
293
|
+
elementAtOrDefault<D>(index: number, defaultValue: D): T | D;
|
|
294
|
+
|
|
295
|
+
count(): number;
|
|
296
|
+
sum(): number;
|
|
297
|
+
average(): number;
|
|
298
|
+
/** Numbers yield a number; strings a string (the operand family). */
|
|
299
|
+
min(): T extends string ? string : number;
|
|
300
|
+
max(): T extends string ? string : number;
|
|
301
|
+
|
|
302
|
+
any(predicate?: (it: Expr<T>, p: ParamsExpr<P>) => BoolExpr | boolean): boolean;
|
|
303
|
+
all(predicate: (it: Expr<T>, p: ParamsExpr<P>) => BoolExpr | boolean): boolean;
|
|
304
|
+
|
|
305
|
+
/** Cross into the async surface (LINQ-FORMAT.md §11): the sync chain
|
|
306
|
+
* becomes the pushed prefix; the element re-types to the callback's
|
|
307
|
+
* RESOLVED type. */
|
|
308
|
+
mapAsync<R>(fn: (item: T, signal: AbortSignal) => R, options: MapAsyncOptions):
|
|
309
|
+
AsyncSequence<Awaited<R>, P>;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function from<T>(source: Iterable<T>, options?: LinqOptions): Sequence<T, {}>;
|
|
313
|
+
export function from<T = unknown>(source: Provider, options?: LinqOptions): Sequence<T, {}>;
|
|
314
|
+
|
|
315
|
+
export function fromDocument<T = unknown>(
|
|
316
|
+
source: Iterable<unknown> | Provider,
|
|
317
|
+
document: unknown,
|
|
318
|
+
options?: LinqOptions,
|
|
319
|
+
): Sequence<T, {}>;
|
|
320
|
+
|
|
321
|
+
/** The runtime code table, synced to LINQ-FORMAT.md §9 by a test. */
|
|
322
|
+
export const LINQ_CODES: Readonly<Record<string, string>>;
|
|
323
|
+
|
|
324
|
+
export class LinqBuildError extends Error {
|
|
325
|
+
readonly code: string;
|
|
326
|
+
readonly reason: string;
|
|
327
|
+
readonly docPath: string | undefined;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export class LinqRuntimeError extends Error {
|
|
331
|
+
readonly code: string;
|
|
332
|
+
readonly reason: string;
|
|
333
|
+
readonly docPath: string | undefined;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// ————— The asynchronous surface (LINQ-FORMAT.md §§10–12) —————
|
|
337
|
+
|
|
338
|
+
export interface MapAsyncOptions {
|
|
339
|
+
/** REQUIRED: the in-flight bound (a positive integer, `JL0005`
|
|
340
|
+
* otherwise) — there is no unbounded default. */
|
|
341
|
+
concurrency: number;
|
|
342
|
+
/** The `createTaskEffect` vocabulary; default `'parallel'`. */
|
|
343
|
+
mode?: 'parallel' | 'concat' | 'switch' | 'exhaust';
|
|
344
|
+
/** Source order (default) versus completion order. */
|
|
345
|
+
ordered?: boolean;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export interface AsyncExplanation {
|
|
349
|
+
barriers: { operator: string, reason: string }[];
|
|
350
|
+
/** Present when the chain is document-representable (no mapAsync). */
|
|
351
|
+
document?: unknown;
|
|
352
|
+
/** Present when a mapAsync splits the chain. */
|
|
353
|
+
split?: { pushed: unknown, residual: string[] };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** The cursor shape (§12): an async iterator by another name. */
|
|
357
|
+
export interface AsyncCursor<T = unknown> {
|
|
358
|
+
next(): Promise<IteratorResult<T>>;
|
|
359
|
+
return?(): Promise<IteratorResult<T>>;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** The deferred async sequence: the same operator surface, promise
|
|
363
|
+
* terminals, streaming semantics per §10. */
|
|
364
|
+
export class AsyncSequence<T = unknown, P = {}> {
|
|
365
|
+
private constructor();
|
|
366
|
+
|
|
367
|
+
where(predicate: (it: Expr<T>, p: ParamsExpr<P>) => BoolExpr | boolean): AsyncSequence<T, P>;
|
|
368
|
+
select<R extends ExprResult>(projection: (it: Expr<T>, p: ParamsExpr<P>) => R): AsyncSequence<Unwrap<R>, P>;
|
|
369
|
+
selectMany<R extends ExprResult>(selector: (it: Expr<T>, p: ParamsExpr<P>) => R): AsyncSequence<Element<Unwrap<R>>, P>;
|
|
370
|
+
orderBy(key: (it: Expr<T>, p: ParamsExpr<P>) => ExprResult, options?: OrderOptions): AsyncSequence<T, P>;
|
|
371
|
+
orderByDescending(key: (it: Expr<T>, p: ParamsExpr<P>) => ExprResult, options?: OrderOptions): AsyncSequence<T, P>;
|
|
372
|
+
thenBy(key: (it: Expr<T>, p: ParamsExpr<P>) => ExprResult, options?: OrderOptions): AsyncSequence<T, P>;
|
|
373
|
+
thenByDescending(key: (it: Expr<T>, p: ParamsExpr<P>) => ExprResult, options?: OrderOptions): AsyncSequence<T, P>;
|
|
374
|
+
groupBy<R extends ExprResult>(key: (it: Expr<T>, p: ParamsExpr<P>) => R):
|
|
375
|
+
AsyncSequence<{ key: Unwrap<R> | null, items: T[] }, P>;
|
|
376
|
+
aggregate<A>(seed: A, step: (acc: Expr<A>, it: Expr<T>, p: ParamsExpr<P>) => ExprResult): AsyncSequence<A, P>;
|
|
377
|
+
skip(count: number): AsyncSequence<T, P>;
|
|
378
|
+
take(count: number): AsyncSequence<T, P>;
|
|
379
|
+
distinct(): AsyncSequence<T, P>;
|
|
380
|
+
reverse(): AsyncSequence<T, P>;
|
|
381
|
+
/** Only a CONSTANT array can join an async stream (§10). */
|
|
382
|
+
concat(other: readonly T[]): AsyncSequence<T, P>;
|
|
383
|
+
defaultIfEmpty(fallback?: T | null): AsyncSequence<T | null, P>;
|
|
384
|
+
ofType<S = unknown>(schema: object): AsyncSequence<S, P>;
|
|
385
|
+
cast<S = unknown>(schema: object): AsyncSequence<S, P>;
|
|
386
|
+
zip(...args: never[]): never;
|
|
387
|
+
params<Q extends Record<string, unknown>>(bindings: Q): AsyncSequence<T, P & Q>;
|
|
388
|
+
|
|
389
|
+
/** The bounded-concurrency boundary (§11): re-types the element to
|
|
390
|
+
* the callback's RESOLVED type. */
|
|
391
|
+
mapAsync<R>(fn: (item: T, signal: AbortSignal) => R, options: MapAsyncOptions):
|
|
392
|
+
AsyncSequence<Awaited<R>, P>;
|
|
393
|
+
|
|
394
|
+
toDocument(): unknown;
|
|
395
|
+
explain(): AsyncExplanation;
|
|
396
|
+
|
|
397
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
398
|
+
toArray(): Promise<T[]>;
|
|
399
|
+
first(): Promise<T>;
|
|
400
|
+
firstOrDefault(): Promise<T | undefined>;
|
|
401
|
+
firstOrDefault<D>(defaultValue: D): Promise<T | D>;
|
|
402
|
+
single(): Promise<T>;
|
|
403
|
+
singleOrDefault(): Promise<T | undefined>;
|
|
404
|
+
singleOrDefault<D>(defaultValue: D): Promise<T | D>;
|
|
405
|
+
last(): Promise<T>;
|
|
406
|
+
lastOrDefault(): Promise<T | undefined>;
|
|
407
|
+
lastOrDefault<D>(defaultValue: D): Promise<T | D>;
|
|
408
|
+
elementAt(index: number): Promise<T>;
|
|
409
|
+
elementAtOrDefault(index: number): Promise<T | undefined>;
|
|
410
|
+
elementAtOrDefault<D>(index: number, defaultValue: D): Promise<T | D>;
|
|
411
|
+
count(): Promise<number>;
|
|
412
|
+
sum(): Promise<number>;
|
|
413
|
+
average(): Promise<number>;
|
|
414
|
+
min(): Promise<T extends string ? string : number>;
|
|
415
|
+
max(): Promise<T extends string ? string : number>;
|
|
416
|
+
any(predicate?: (it: Expr<T>, p: ParamsExpr<P>) => BoolExpr | boolean): Promise<boolean>;
|
|
417
|
+
all(predicate: (it: Expr<T>, p: ParamsExpr<P>) => BoolExpr | boolean): Promise<boolean>;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export function fromAsync<T>(
|
|
421
|
+
source: AsyncIterable<T> | Iterable<T> | AsyncCursor<T>,
|
|
422
|
+
options?: LinqOptions,
|
|
423
|
+
): AsyncSequence<T, {}>;
|
|
424
|
+
|
|
425
|
+
/** The push→pull adapter for feed/end readers (§12). */
|
|
426
|
+
export function createPushQueue<T = unknown>(options?: { highWaterMark?: number }): {
|
|
427
|
+
feed(value: T): boolean;
|
|
428
|
+
end(error?: unknown): void;
|
|
429
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
430
|
+
};
|