tyneq 1.0.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/LICENSE +21 -0
- package/README.md +319 -0
- package/dist/Lazy.cjs +762 -0
- package/dist/Lazy.cjs.map +1 -0
- package/dist/Lazy.js +691 -0
- package/dist/Lazy.js.map +1 -0
- package/dist/TyneqCachedTerminalOperator.cjs +4950 -0
- package/dist/TyneqCachedTerminalOperator.cjs.map +1 -0
- package/dist/TyneqCachedTerminalOperator.d.cts +724 -0
- package/dist/TyneqCachedTerminalOperator.d.cts.map +1 -0
- package/dist/TyneqCachedTerminalOperator.d.ts +724 -0
- package/dist/TyneqCachedTerminalOperator.d.ts.map +1 -0
- package/dist/TyneqCachedTerminalOperator.js +4741 -0
- package/dist/TyneqCachedTerminalOperator.js.map +1 -0
- package/dist/ValidationBuilder.cjs +80 -0
- package/dist/ValidationBuilder.cjs.map +1 -0
- package/dist/ValidationBuilder.d.cts +319 -0
- package/dist/ValidationBuilder.d.cts.map +1 -0
- package/dist/ValidationBuilder.d.ts +319 -0
- package/dist/ValidationBuilder.d.ts.map +1 -0
- package/dist/ValidationBuilder.js +69 -0
- package/dist/ValidationBuilder.js.map +1 -0
- package/dist/core.d.cts +1393 -0
- package/dist/core.d.cts.map +1 -0
- package/dist/core.d.ts +1393 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/index.cjs +863 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1038 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +1038 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +809 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/index.cjs +24 -0
- package/dist/plugin/index.d.cts +89 -0
- package/dist/plugin/index.d.cts.map +1 -0
- package/dist/plugin/index.d.ts +89 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +2 -0
- package/dist/utility/index.cjs +9 -0
- package/dist/utility/index.d.cts +2 -0
- package/dist/utility/index.d.ts +2 -0
- package/dist/utility/index.js +3 -0
- package/package.json +96 -0
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
import { L as Constructor, M as tyneqQueryNode, S as TyneqEnumerableBase, T as QueryPlanNode, Z as Nullable, _ as TyneqCachedSequence, a as Enumerator, b as TyneqSequence, i as Enumerable, m as OrderedEnumerable, n as CachedEnumerable, o as EnumeratorFactory, p as OperatorSource, r as Comparer, t as CacheResult, tt as BaseEnumerableSorter, y as TyneqOrderedSequence } from "./core.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugin/decorators/operator.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Class decorator that registers a `TyneqEnumerator` subclass as an operator on every sequence.
|
|
6
|
+
*
|
|
7
|
+
* Validation runs eagerly at the call site, before the lazy enumerator is created.
|
|
8
|
+
*
|
|
9
|
+
* @param name - Method name to expose on every sequence.
|
|
10
|
+
* @param category - Operator kind (`"streaming"` | `"buffer"`).
|
|
11
|
+
* @param validate - Optional eager validation function for user-supplied arguments.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { operator, TyneqEnumerator } from "tyneq/plugin";
|
|
16
|
+
* import type { Enumerator } from "tyneq";
|
|
17
|
+
*
|
|
18
|
+
* @operator<[predicate: (item: unknown) => boolean]>("myFilter", "streaming", (predicate) => {
|
|
19
|
+
* if (typeof predicate !== "function") throw new Error("predicate must be a function");
|
|
20
|
+
* })
|
|
21
|
+
* class MyFilterEnumerator<T> extends TyneqEnumerator<T> {
|
|
22
|
+
* public constructor(source: Enumerator<T>, private readonly predicate: (item: T) => boolean) {
|
|
23
|
+
* super(source);
|
|
24
|
+
* }
|
|
25
|
+
* protected handleNext(): IteratorResult<T> {
|
|
26
|
+
* while (true) {
|
|
27
|
+
* const next = this.sourceEnumerator.next();
|
|
28
|
+
* if (next.done || this.predicate(next.value)) return next;
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @group Decorators
|
|
35
|
+
*/
|
|
36
|
+
declare function operator<TArgs extends unknown[] = never>(name: string, category: "streaming" | "buffer", validate?: (...args: TArgs) => void): <TClass extends new (...args: any[]) => any>(target: TClass, _context: ClassDecoratorContext) => TClass;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/plugin/decorators/orderedOperator.d.ts
|
|
39
|
+
/**
|
|
40
|
+
* Class decorator that registers a `TyneqOrderedEnumerator` subclass as an operator
|
|
41
|
+
* available only on ordered sequences.
|
|
42
|
+
*
|
|
43
|
+
* The enumerator constructor receives the full `TyneqOrderedEnumerable` as its first
|
|
44
|
+
* argument (not just an `Enumerator<T>`).
|
|
45
|
+
*
|
|
46
|
+
* @param name - Method name to expose on ordered sequences.
|
|
47
|
+
* @param category - Operator kind (`"streaming"` | `"buffer"`).
|
|
48
|
+
* @param validate - Optional eager validation function for user-supplied arguments.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { orderedOperator, TyneqOrderedEnumerator } from "tyneq/plugin";
|
|
53
|
+
*
|
|
54
|
+
* @orderedOperator("myThenBy", "buffer", (keySelector) => {
|
|
55
|
+
* if (typeof keySelector !== "function") throw new Error("keySelector must be a function");
|
|
56
|
+
* })
|
|
57
|
+
* class MyThenByEnumerator<T> extends TyneqOrderedEnumerator<T> {
|
|
58
|
+
* private readonly iter: Enumerator<T>;
|
|
59
|
+
* public constructor(source: OrderedEnumerable<T>, private readonly keySelector: (item: T) => unknown) {
|
|
60
|
+
* super(source);
|
|
61
|
+
* this.iter = this.orderedSource.getEnumerator();
|
|
62
|
+
* }
|
|
63
|
+
* protected handleNext(): IteratorResult<T> {
|
|
64
|
+
* // this.orderedSource gives access to the full OrderedEnumerable
|
|
65
|
+
* return this.iter.next();
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @group Decorators
|
|
71
|
+
*/
|
|
72
|
+
declare function orderedOperator<TArgs extends unknown[] = never>(name: string, category: "streaming" | "buffer", validate?: (...args: TArgs) => void): <TClass extends Constructor<any>>(target: TClass, _context: ClassDecoratorContext<TClass>) => TClass;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/plugin/decorators/cachedOperator.d.ts
|
|
75
|
+
/**
|
|
76
|
+
* Class decorator that registers a `TyneqCachedEnumerator` subclass as an operator
|
|
77
|
+
* available only on cached sequences.
|
|
78
|
+
*
|
|
79
|
+
* The enumerator constructor receives the full `TyneqCachedEnumerable` as its first
|
|
80
|
+
* argument (not just an `Enumerator<T>`).
|
|
81
|
+
*
|
|
82
|
+
* @param name - Method name to expose on cached sequences.
|
|
83
|
+
* @param category - Operator kind (`"streaming"` | `"buffer"`).
|
|
84
|
+
* @param validate - Optional eager validation function for user-supplied arguments.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { cachedOperator, TyneqCachedEnumerator } from "tyneq/plugin";
|
|
89
|
+
*
|
|
90
|
+
* @cachedOperator("myRefresh", "buffer")
|
|
91
|
+
* class MyRefreshEnumerator<T> extends TyneqCachedEnumerator<T> {
|
|
92
|
+
* private readonly iter: Enumerator<T>;
|
|
93
|
+
* public constructor(source: CachedEnumerable<T>) {
|
|
94
|
+
* super(source);
|
|
95
|
+
* this.iter = this.cachedSource.getEnumerator();
|
|
96
|
+
* }
|
|
97
|
+
* protected handleNext(): IteratorResult<T> {
|
|
98
|
+
* // this.cachedSource gives access to the full CachedEnumerable
|
|
99
|
+
* return this.iter.next();
|
|
100
|
+
* }
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @group Decorators
|
|
105
|
+
*/
|
|
106
|
+
declare function cachedOperator<TArgs extends unknown[] = never>(name: string, category: "streaming" | "buffer", validate?: (...args: TArgs) => void): <TClass extends Constructor<any>>(target: TClass, _context: ClassDecoratorContext<TClass>) => TClass;
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/plugin/decorators/terminal.d.ts
|
|
109
|
+
/**
|
|
110
|
+
* Class decorator that registers a class as a terminal operator.
|
|
111
|
+
*
|
|
112
|
+
* The class must have a `process()` method returning the result.
|
|
113
|
+
* Validation runs eagerly at the call site before the class is instantiated.
|
|
114
|
+
*
|
|
115
|
+
* @param name - Method name to expose on every sequence.
|
|
116
|
+
* @param validate - Optional eager validation function for user-supplied arguments.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { terminal } from "tyneq/plugin";
|
|
121
|
+
* import { TyneqTerminalOperator } from "tyneq/plugin";
|
|
122
|
+
* import type { Enumerable } from "tyneq";
|
|
123
|
+
*
|
|
124
|
+
* @terminal("product")
|
|
125
|
+
* class ProductOperator extends TyneqTerminalOperator<number, number> {
|
|
126
|
+
* public process(): number {
|
|
127
|
+
* let result = 1;
|
|
128
|
+
* for (const item of this.source) result *= item;
|
|
129
|
+
* return result;
|
|
130
|
+
* }
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @group Decorators
|
|
135
|
+
*/
|
|
136
|
+
declare function terminal<TArgs extends unknown[] = never>(name: string, validate?: (...args: TArgs) => void): <TClass extends new (...args: any[]) => {
|
|
137
|
+
process(): unknown;
|
|
138
|
+
}>(target: TClass, _context: ClassDecoratorContext) => TClass;
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/plugin/decorators/orderedTerminal.d.ts
|
|
141
|
+
/**
|
|
142
|
+
* Class decorator that registers a `TyneqOrderedTerminalOperator` subclass as a terminal
|
|
143
|
+
* operator available only on ordered sequences.
|
|
144
|
+
*
|
|
145
|
+
* The class constructor receives the full `OrderedEnumerable` as its first argument,
|
|
146
|
+
* giving access to ordered-sequence members (comparers, parent chain, etc.).
|
|
147
|
+
*
|
|
148
|
+
* @param name - Method name to expose on ordered sequences.
|
|
149
|
+
* @param validate - Optional eager validation function for user-supplied arguments.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* @orderedTerminal("isSorted")
|
|
154
|
+
* class IsSortedOperator<T> extends TyneqOrderedTerminalOperator<T, boolean> {
|
|
155
|
+
* process(): boolean {
|
|
156
|
+
* const items = [...this.source];
|
|
157
|
+
* for (let i = 1; i < items.length; i++) {
|
|
158
|
+
* if (this.source.comparer(items[i - 1], items[i]) > 0) return false;
|
|
159
|
+
* }
|
|
160
|
+
* return true;
|
|
161
|
+
* }
|
|
162
|
+
* }
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @group Decorators
|
|
166
|
+
*/
|
|
167
|
+
declare function orderedTerminal<TArgs extends unknown[] = never>(name: string, validate?: (...args: TArgs) => void): <TClass extends Constructor<{
|
|
168
|
+
process(): unknown;
|
|
169
|
+
}>>(target: TClass, _context: ClassDecoratorContext<TClass>) => TClass;
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/plugin/decorators/cachedTerminal.d.ts
|
|
172
|
+
/**
|
|
173
|
+
* Class decorator that registers a `TyneqCachedTerminalOperator` subclass as a terminal
|
|
174
|
+
* operator available only on cached sequences.
|
|
175
|
+
*
|
|
176
|
+
* The class constructor receives the full `CachedEnumerable` as its first argument,
|
|
177
|
+
* giving access to cached-sequence members (`refresh()`, internal cache, etc.).
|
|
178
|
+
*
|
|
179
|
+
* @param name - Method name to expose on cached sequences.
|
|
180
|
+
* @param validate - Optional eager validation function for user-supplied arguments.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* @cachedTerminal("cacheSize")
|
|
185
|
+
* class CacheSizeOperator<T> extends TyneqCachedTerminalOperator<T, number> {
|
|
186
|
+
* process(): number {
|
|
187
|
+
* return [...this.source].length;
|
|
188
|
+
* }
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @group Decorators
|
|
193
|
+
*/
|
|
194
|
+
declare function cachedTerminal<TArgs extends unknown[] = never>(name: string, validate?: (...args: TArgs) => void): <TClass extends Constructor<{
|
|
195
|
+
process(): unknown;
|
|
196
|
+
}>>(target: TClass, _context: ClassDecoratorContext<TClass>) => TClass;
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/plugin/registration/createOperator.d.ts
|
|
199
|
+
/**
|
|
200
|
+
* Registers a streaming or buffering operator using a factory function.
|
|
201
|
+
*
|
|
202
|
+
* Use this when the operator requires a class-level enumerator with custom state
|
|
203
|
+
* but you want to avoid writing the decorator boilerplate. For simpler generator-based
|
|
204
|
+
* operators, prefer {@link createGeneratorOperator}.
|
|
205
|
+
*
|
|
206
|
+
* @param config.name - Method name to expose on every sequence.
|
|
207
|
+
* @param config.category - `"streaming"` or `"buffer"`.
|
|
208
|
+
* @param config.factory - Returns an `EnumeratorFactory` given the source and arguments.
|
|
209
|
+
* @param config.validate - Optional eager validation for user-supplied arguments.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* import { createOperator } from "tyneq/plugin";
|
|
214
|
+
* import type { Enumerator } from "tyneq";
|
|
215
|
+
*
|
|
216
|
+
* createOperator({
|
|
217
|
+
* name: "everyOther",
|
|
218
|
+
* category: "streaming",
|
|
219
|
+
* factory: <T>(source: Enumerable<T>) => ({
|
|
220
|
+
* getEnumerator(): Enumerator<T> {
|
|
221
|
+
* let skip = false;
|
|
222
|
+
* const iter = source[Symbol.iterator]();
|
|
223
|
+
* return {
|
|
224
|
+
* next(): IteratorResult<T> {
|
|
225
|
+
* while (true) {
|
|
226
|
+
* const r = iter.next();
|
|
227
|
+
* if (r.done) return r;
|
|
228
|
+
* if (!skip) { skip = true; return r; }
|
|
229
|
+
* skip = false;
|
|
230
|
+
* }
|
|
231
|
+
* }
|
|
232
|
+
* };
|
|
233
|
+
* }
|
|
234
|
+
* })
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @group Factory Functions
|
|
239
|
+
*/
|
|
240
|
+
declare function createOperator<TSource, TArgs extends unknown[], TResult>(config: {
|
|
241
|
+
name: string;
|
|
242
|
+
category: "streaming" | "buffer";
|
|
243
|
+
factory: (source: Enumerable<TSource>, ...args: TArgs) => EnumeratorFactory<TResult>;
|
|
244
|
+
validate?: (...args: NoInfer<TArgs>) => void;
|
|
245
|
+
source?: OperatorSource;
|
|
246
|
+
}): void;
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/plugin/registration/createGeneratorOperator.d.ts
|
|
249
|
+
/**
|
|
250
|
+
* Registers an operator using a generator function.
|
|
251
|
+
*
|
|
252
|
+
* The generator receives the source as an `Iterable<T>` and any user arguments.
|
|
253
|
+
* This is the simplest functional registration path and works for both streaming
|
|
254
|
+
* and buffering use cases:
|
|
255
|
+
*
|
|
256
|
+
* - **Streaming**: yield elements one at a time as they arrive. The downstream
|
|
257
|
+
* sequence only pulls the next element when needed.
|
|
258
|
+
* - **Buffering**: collect all input first, then yield the transformed output.
|
|
259
|
+
* Pass `category: "buffer"` to tell the query plan that this operator
|
|
260
|
+
* materialises the entire upstream before yielding.
|
|
261
|
+
*
|
|
262
|
+
* For class-based enumerators with custom stateful logic, prefer {@link createOperator}.
|
|
263
|
+
*
|
|
264
|
+
* @param config.name - Method name to expose on every sequence.
|
|
265
|
+
* @param config.category - `"streaming"` (default) or `"buffer"`.
|
|
266
|
+
* @param config.generator - Generator that yields transformed elements from `source`.
|
|
267
|
+
* @param config.validate - Optional eager validation for user-supplied arguments.
|
|
268
|
+
*
|
|
269
|
+
* @example Streaming - yield elements lazily one at a time:
|
|
270
|
+
* ```ts
|
|
271
|
+
* import { createGeneratorOperator } from "tyneq/plugin";
|
|
272
|
+
*
|
|
273
|
+
* createGeneratorOperator({
|
|
274
|
+
* name: "everyOther",
|
|
275
|
+
* *generator(source) {
|
|
276
|
+
* let skip = false;
|
|
277
|
+
* for (const item of source) {
|
|
278
|
+
* if (!skip) yield item;
|
|
279
|
+
* skip = !skip;
|
|
280
|
+
* }
|
|
281
|
+
* }
|
|
282
|
+
* });
|
|
283
|
+
* ```
|
|
284
|
+
*
|
|
285
|
+
* @example Buffering - materialise the entire input first, then yield results:
|
|
286
|
+
* ```ts
|
|
287
|
+
* import { createGeneratorOperator } from "tyneq/plugin";
|
|
288
|
+
*
|
|
289
|
+
* createGeneratorOperator({
|
|
290
|
+
* name: "sortedBy",
|
|
291
|
+
* category: "buffer",
|
|
292
|
+
* *generator(source, keyFn: (x: number) => number) {
|
|
293
|
+
* const items = [...source].sort((a, b) => keyFn(a) - keyFn(b));
|
|
294
|
+
* for (const item of items) yield item;
|
|
295
|
+
* }
|
|
296
|
+
* });
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @group Factory Functions
|
|
300
|
+
*/
|
|
301
|
+
declare function createGeneratorOperator<TSource, TArgs extends unknown[], TResult>(config: {
|
|
302
|
+
name: string;
|
|
303
|
+
category?: "streaming" | "buffer";
|
|
304
|
+
generator: (source: Iterable<TSource>, ...args: TArgs) => IterableIterator<TResult>;
|
|
305
|
+
validate?: (...args: NoInfer<TArgs>) => void;
|
|
306
|
+
source?: OperatorSource;
|
|
307
|
+
}): void;
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/core/ordering/TyneqOrderedEnumerable.d.ts
|
|
310
|
+
/**
|
|
311
|
+
* Concrete implementation of {@link TyneqOrderedSequence}.
|
|
312
|
+
*
|
|
313
|
+
* @remarks
|
|
314
|
+
* Created by `orderBy` and `orderByDescending`. Chains to a parent `TyneqOrderedEnumerable`
|
|
315
|
+
* via `thenBy` / `thenByDescending` to build a multi-key sorter.
|
|
316
|
+
*
|
|
317
|
+
* @internal
|
|
318
|
+
*/
|
|
319
|
+
declare class TyneqOrderedEnumerable<TSource, TKey> extends TyneqEnumerableBase<TSource> implements TyneqOrderedSequence<TSource> {
|
|
320
|
+
private readonly keySelector;
|
|
321
|
+
private readonly comparer;
|
|
322
|
+
private readonly descending;
|
|
323
|
+
readonly source: TyneqSequence<TSource>;
|
|
324
|
+
readonly parent: Nullable<OrderedEnumerable<TSource>>;
|
|
325
|
+
readonly [tyneqQueryNode]: Nullable<QueryPlanNode>;
|
|
326
|
+
constructor(source: TyneqSequence<TSource>, keySelector: (item: TSource) => TKey, comparer: Comparer<TKey>, descending: boolean, parent?: OrderedEnumerable<TSource>, node?: Nullable<QueryPlanNode>);
|
|
327
|
+
asc(): TyneqOrderedSequence<TSource>;
|
|
328
|
+
desc(): TyneqOrderedSequence<TSource>;
|
|
329
|
+
getEnumerator(): Enumerator<TSource>;
|
|
330
|
+
getSorter(next: Nullable<BaseEnumerableSorter<TSource>>): BaseEnumerableSorter<TSource>;
|
|
331
|
+
thenBy<UKey>(keySelector: (item: TSource) => UKey, comparer?: Comparer<UKey>): TyneqOrderedSequence<TSource>;
|
|
332
|
+
thenByDescending<UKey>(keySelector: (item: TSource) => UKey, comparer?: Comparer<UKey>): TyneqOrderedSequence<TSource>;
|
|
333
|
+
protected createEnumerable<TResult>(factory: EnumeratorFactory<TResult>, node: Nullable<QueryPlanNode>): TyneqSequence<TResult>;
|
|
334
|
+
protected createOrderedEnumerable<TKey>(keySelector: (x: TSource) => TKey, comparer: Comparer<TKey>, descending: boolean, node: Nullable<QueryPlanNode>): TyneqOrderedSequence<TSource>;
|
|
335
|
+
protected createCachedEnumerable(source: TyneqSequence<TSource>, node: Nullable<QueryPlanNode>): TyneqCachedSequence<TSource>;
|
|
336
|
+
}
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/plugin/registration/createOrderedOperator.d.ts
|
|
339
|
+
/**
|
|
340
|
+
* Registers a factory function as an operator available only on ordered sequences,
|
|
341
|
+
* where the factory fully controls the return type.
|
|
342
|
+
*
|
|
343
|
+
* Use this when the operator must return a `TyneqOrderedSequence` (e.g. a `thenBy` variant).
|
|
344
|
+
* The factory receives the ordered source and a query plan node. It is responsible for
|
|
345
|
+
* constructing and returning the result sequence - typically by instantiating
|
|
346
|
+
* `TyneqOrderedEnumerable` directly.
|
|
347
|
+
*
|
|
348
|
+
* For operators that return a plain sequence from an enumerator class, use `@orderedOperator`.
|
|
349
|
+
*
|
|
350
|
+
* @param config.name - Method name to expose on ordered sequences.
|
|
351
|
+
* @param config.category - Operator kind (`"streaming"` | `"buffer"`).
|
|
352
|
+
* @param config.factory - Constructs the result sequence from `(source, node, ...userArgs)`.
|
|
353
|
+
* @param config.validate - Optional eager validation function for user-supplied arguments.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* createOrderedOperator({
|
|
358
|
+
* name: "thenByLocale",
|
|
359
|
+
* category: "buffer",
|
|
360
|
+
* factory: (source, node, locale: string, keySelector: (item: unknown) => string) =>
|
|
361
|
+
* new TyneqOrderedEnumerable(
|
|
362
|
+
* source.source,
|
|
363
|
+
* keySelector,
|
|
364
|
+
* (a, b) => a.localeCompare(b, locale),
|
|
365
|
+
* false,
|
|
366
|
+
* source,
|
|
367
|
+
* node
|
|
368
|
+
* ),
|
|
369
|
+
* validate: (locale, keySelector) => {
|
|
370
|
+
* if (typeof locale !== "string") throw new Error("locale must be a string");
|
|
371
|
+
* if (typeof keySelector !== "function") throw new Error("keySelector must be a function");
|
|
372
|
+
* }
|
|
373
|
+
* });
|
|
374
|
+
* ```
|
|
375
|
+
*
|
|
376
|
+
* @group Factory Functions
|
|
377
|
+
*/
|
|
378
|
+
declare function createOrderedOperator<TSource, TArgs extends unknown[]>(config: {
|
|
379
|
+
name: string;
|
|
380
|
+
category: "streaming" | "buffer";
|
|
381
|
+
factory: (source: TyneqOrderedEnumerable<TSource, unknown>, node: QueryPlanNode, ...args: TArgs) => TyneqOrderedSequence<TSource>;
|
|
382
|
+
validate?: (...args: NoInfer<TArgs>) => void;
|
|
383
|
+
source?: OperatorSource;
|
|
384
|
+
}): void;
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/core/TyneqCachedEnumerable.d.ts
|
|
387
|
+
/**
|
|
388
|
+
* Concrete implementation of {@link TyneqCachedSequence} - caches elements incrementally.
|
|
389
|
+
*
|
|
390
|
+
* @remarks
|
|
391
|
+
* Created by `memoize()`. On the first iteration the source is enumerated one element at a time
|
|
392
|
+
* and each element is appended to an internal array. Subsequent iterations replay the cache;
|
|
393
|
+
* the source is not re-enumerated. Call `refresh()` to clear the cache and start over.
|
|
394
|
+
*
|
|
395
|
+
* @internal
|
|
396
|
+
*/
|
|
397
|
+
declare class TyneqCachedEnumerable<TSource> extends TyneqEnumerableBase<TSource> implements TyneqCachedSequence<TSource>, CachedEnumerable<TSource> {
|
|
398
|
+
private source;
|
|
399
|
+
private cache;
|
|
400
|
+
private done;
|
|
401
|
+
private sourceEnumerator;
|
|
402
|
+
readonly [tyneqQueryNode]: Nullable<QueryPlanNode>;
|
|
403
|
+
constructor(source: TyneqSequence<TSource>, node?: Nullable<QueryPlanNode>);
|
|
404
|
+
getEnumerator(): Enumerator<TSource>;
|
|
405
|
+
refresh(): TyneqCachedSequence<TSource>;
|
|
406
|
+
tryGetAtFromCache(index: number): CacheResult<TSource>;
|
|
407
|
+
protected createEnumerable<TResult>(factory: EnumeratorFactory<TResult>, node: Nullable<QueryPlanNode>): TyneqSequence<TResult>;
|
|
408
|
+
protected createOrderedEnumerable<TKey>(keySelector: (x: TSource) => TKey, comparer: Comparer<TKey>, descending: boolean, node: Nullable<QueryPlanNode>): TyneqOrderedSequence<TSource>;
|
|
409
|
+
protected createCachedEnumerable(source: TyneqSequence<TSource>, node: Nullable<QueryPlanNode>): TyneqCachedSequence<TSource>;
|
|
410
|
+
}
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/plugin/registration/createCachedOperator.d.ts
|
|
413
|
+
/**
|
|
414
|
+
* Registers a factory function as an operator available only on cached sequences,
|
|
415
|
+
* where the factory fully controls the return type.
|
|
416
|
+
*
|
|
417
|
+
* Use this when the operator must return a `TyneqCachedSequence`. The factory
|
|
418
|
+
* receives the cached source and a query plan node. It is responsible for
|
|
419
|
+
* constructing and returning the result sequence.
|
|
420
|
+
*
|
|
421
|
+
* For operators that return a plain sequence from an enumerator class, use `@cachedOperator`.
|
|
422
|
+
*
|
|
423
|
+
* @param config.name - Method name to expose on cached sequences.
|
|
424
|
+
* @param config.category - Operator kind (`"streaming"` | `"buffer"`).
|
|
425
|
+
* @param config.factory - Constructs the result sequence from `(source, node, ...userArgs)`.
|
|
426
|
+
* @param config.validate - Optional eager validation function for user-supplied arguments.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```ts
|
|
430
|
+
* createCachedOperator({
|
|
431
|
+
* name: "refreshWith",
|
|
432
|
+
* category: "buffer",
|
|
433
|
+
* factory: (source, node, newSource: Iterable<unknown>) => {
|
|
434
|
+
* const seq = tyneqFrom(newSource);
|
|
435
|
+
* return new TyneqCachedEnumerable(seq, node);
|
|
436
|
+
* },
|
|
437
|
+
* validate: (newSource) => {
|
|
438
|
+
* if (newSource == null) throw new Error("newSource must not be null");
|
|
439
|
+
* }
|
|
440
|
+
* });
|
|
441
|
+
* ```
|
|
442
|
+
*
|
|
443
|
+
* @group Factory Functions
|
|
444
|
+
*/
|
|
445
|
+
declare function createCachedOperator<TSource, TArgs extends unknown[]>(config: {
|
|
446
|
+
name: string;
|
|
447
|
+
category: "streaming" | "buffer";
|
|
448
|
+
factory: (source: TyneqCachedEnumerable<TSource>, node: QueryPlanNode, ...args: TArgs) => TyneqCachedSequence<TSource>;
|
|
449
|
+
validate?: (...args: NoInfer<TArgs>) => void;
|
|
450
|
+
source?: OperatorSource;
|
|
451
|
+
}): void;
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/plugin/registration/createTerminalOperator.d.ts
|
|
454
|
+
/**
|
|
455
|
+
* Registers a terminal operator using a plain function.
|
|
456
|
+
*
|
|
457
|
+
* The simplest registration API for terminal operators.
|
|
458
|
+
* `execute` receives the full source sequence and any user arguments and returns a concrete value.
|
|
459
|
+
*
|
|
460
|
+
* @param config.name - Method name to expose on every sequence.
|
|
461
|
+
* @param config.execute - Function that consumes the source and returns a result.
|
|
462
|
+
* @param config.validate - Optional eager validation for user-supplied arguments.
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```ts
|
|
466
|
+
* import { createTerminalOperator } from "tyneq/plugin";
|
|
467
|
+
*
|
|
468
|
+
* createTerminalOperator({
|
|
469
|
+
* name: "product",
|
|
470
|
+
* execute(source: Iterable<number>): number {
|
|
471
|
+
* let result = 1;
|
|
472
|
+
* for (const item of source) result *= item;
|
|
473
|
+
* return result;
|
|
474
|
+
* }
|
|
475
|
+
* });
|
|
476
|
+
* ```
|
|
477
|
+
*
|
|
478
|
+
* @group Factory Functions
|
|
479
|
+
*/
|
|
480
|
+
declare function createTerminalOperator<TSource, TArgs extends unknown[], TResult>(config: {
|
|
481
|
+
name: string;
|
|
482
|
+
execute: (source: Enumerable<TSource>, ...args: TArgs) => TResult;
|
|
483
|
+
validate?: (...args: NoInfer<TArgs>) => void;
|
|
484
|
+
source?: OperatorSource;
|
|
485
|
+
}): void;
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/plugin/registration/createOrderedTerminalOperator.d.ts
|
|
488
|
+
/**
|
|
489
|
+
* Registers a terminal operator available only on ordered sequences.
|
|
490
|
+
*
|
|
491
|
+
* The `execute` function receives the full `OrderedEnumerable` as its first argument,
|
|
492
|
+
* giving access to ordered-sequence members (comparers, parent chain, etc.).
|
|
493
|
+
*
|
|
494
|
+
* @param config.name - Method name to expose on ordered sequences.
|
|
495
|
+
* @param config.execute - Function that consumes the ordered source and returns a result.
|
|
496
|
+
* @param config.validate - Optional eager validation for user-supplied arguments.
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```ts
|
|
500
|
+
* createOrderedTerminalOperator({
|
|
501
|
+
* name: "isSorted",
|
|
502
|
+
* execute(source: OrderedEnumerable<number>): boolean {
|
|
503
|
+
* const items = [...source];
|
|
504
|
+
* for (let i = 1; i < items.length; i++) {
|
|
505
|
+
* if (items[i - 1] > items[i]) return false;
|
|
506
|
+
* }
|
|
507
|
+
* return true;
|
|
508
|
+
* }
|
|
509
|
+
* });
|
|
510
|
+
* ```
|
|
511
|
+
*
|
|
512
|
+
* @group Factory Functions
|
|
513
|
+
*/
|
|
514
|
+
declare function createOrderedTerminalOperator<TSource, TArgs extends unknown[], TResult>(config: {
|
|
515
|
+
name: string;
|
|
516
|
+
execute: (source: OrderedEnumerable<TSource>, ...args: TArgs) => TResult;
|
|
517
|
+
validate?: (...args: NoInfer<TArgs>) => void;
|
|
518
|
+
source?: OperatorSource;
|
|
519
|
+
}): void;
|
|
520
|
+
//#endregion
|
|
521
|
+
//#region src/plugin/registration/createCachedTerminalOperator.d.ts
|
|
522
|
+
/**
|
|
523
|
+
* Registers a terminal operator available only on cached sequences.
|
|
524
|
+
*
|
|
525
|
+
* The `execute` function receives the full `CachedEnumerable` as its first argument,
|
|
526
|
+
* giving access to cached-sequence members (`refresh()`, internal cache, etc.).
|
|
527
|
+
*
|
|
528
|
+
* @param config.name - Method name to expose on cached sequences.
|
|
529
|
+
* @param config.execute - Function that consumes the cached source and returns a result.
|
|
530
|
+
* @param config.validate - Optional eager validation for user-supplied arguments.
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```ts
|
|
534
|
+
* createCachedTerminalOperator({
|
|
535
|
+
* name: "cacheSize",
|
|
536
|
+
* execute(source: CachedEnumerable<unknown>): number {
|
|
537
|
+
* return [...source].length;
|
|
538
|
+
* }
|
|
539
|
+
* });
|
|
540
|
+
* ```
|
|
541
|
+
*
|
|
542
|
+
* @group Factory Functions
|
|
543
|
+
*/
|
|
544
|
+
declare function createCachedTerminalOperator<TSource, TArgs extends unknown[], TResult>(config: {
|
|
545
|
+
name: string;
|
|
546
|
+
execute: (source: CachedEnumerable<TSource>, ...args: TArgs) => TResult;
|
|
547
|
+
validate?: (...args: NoInfer<TArgs>) => void;
|
|
548
|
+
source?: OperatorSource;
|
|
549
|
+
}): void;
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/core/enumerators/TyneqBaseEnumerator.d.ts
|
|
552
|
+
/**
|
|
553
|
+
* Abstract base class implementing the pull-iterator lifecycle for all Tyneq enumerators.
|
|
554
|
+
*
|
|
555
|
+
* @remarks
|
|
556
|
+
* State machine:
|
|
557
|
+
* - `next()` calls `initialize()` on the first invocation, then delegates to `handleNext()`.
|
|
558
|
+
* - When `handleNext()` returns `{ done: true }`, `dispose()` is called then the enumerator marks itself completed.
|
|
559
|
+
* - `doneWithYield(value)` emits one final element, calls `dispose()`, then marks completed.
|
|
560
|
+
* - `earlyComplete()` calls `dispose()` and marks completed without yielding.
|
|
561
|
+
* - `return()` triggers early termination: calls `dispose()` then marks completed. Idempotent.
|
|
562
|
+
* - Once completed, all `next()` calls return `{ done: true }` without re-invoking `handleNext()`.
|
|
563
|
+
*
|
|
564
|
+
* Subclasses must implement `handleNext()`. Override `initialize()`, `disposeSource()`, and
|
|
565
|
+
* `disposeAdditional()` as needed.
|
|
566
|
+
*
|
|
567
|
+
* @typeParam TInput - Source element type.
|
|
568
|
+
* @typeParam TOutput - Output element type (defaults to `TInput`).
|
|
569
|
+
* @group Plugin
|
|
570
|
+
*/
|
|
571
|
+
declare abstract class TyneqBaseEnumerator<TInput, TOutput = TInput> implements Enumerator<TOutput> {
|
|
572
|
+
private _initialized;
|
|
573
|
+
private _completed;
|
|
574
|
+
constructor();
|
|
575
|
+
/** Advances the iterator, calling `initialize()` on first call. Idempotent after completion. */
|
|
576
|
+
next(): IteratorResult<TOutput>;
|
|
577
|
+
/** Terminates iteration early, disposes resources, and marks completed. Idempotent. */
|
|
578
|
+
return(value?: unknown): IteratorResult<TOutput>;
|
|
579
|
+
/** Called once before the first `handleNext()` invocation. Override to set up state. */
|
|
580
|
+
protected initialize(): void;
|
|
581
|
+
/** Wraps `value` in a non-done `IteratorResult`. */
|
|
582
|
+
protected yield(value: TOutput): IteratorResult<TOutput>;
|
|
583
|
+
/** Returns a done `IteratorResult`. */
|
|
584
|
+
protected done(): IteratorResult<TOutput>;
|
|
585
|
+
/**
|
|
586
|
+
* Marks the enumerator completed and yields `value` as the final element.
|
|
587
|
+
*
|
|
588
|
+
* @remarks
|
|
589
|
+
* Use when the last element must be emitted together with completion in one step.
|
|
590
|
+
*/
|
|
591
|
+
protected doneWithYield(value: TOutput): IteratorResult<TOutput>;
|
|
592
|
+
/**
|
|
593
|
+
* Disposes resources, marks completed, and returns a done result.
|
|
594
|
+
*
|
|
595
|
+
* @remarks
|
|
596
|
+
* Use inside `handleNext()` to terminate iteration before the source is exhausted.
|
|
597
|
+
*/
|
|
598
|
+
protected earlyComplete(reason?: unknown): IteratorResult<TOutput>;
|
|
599
|
+
/** Calls `disposeSource()` then `disposeAdditional()`. */
|
|
600
|
+
protected dispose(value?: unknown): void;
|
|
601
|
+
/** Override to dispose the upstream source enumerator. */
|
|
602
|
+
protected disposeSource(): void;
|
|
603
|
+
/**
|
|
604
|
+
* Override to release any additional resources.
|
|
605
|
+
*
|
|
606
|
+
* @remarks
|
|
607
|
+
* Called after `disposeSource()`. `value` is the return value passed to `return()`.
|
|
608
|
+
* Must be idempotent and must not throw.
|
|
609
|
+
*/
|
|
610
|
+
protected disposeAdditional(_value?: unknown): void;
|
|
611
|
+
/** Produces the next element. Return `{ done: true }` to signal exhaustion. */
|
|
612
|
+
protected abstract handleNext(): IteratorResult<TOutput>;
|
|
613
|
+
}
|
|
614
|
+
//#endregion
|
|
615
|
+
//#region src/core/enumerators/TyneqEnumerator.d.ts
|
|
616
|
+
/**
|
|
617
|
+
* Base class for all pipeline operator enumerators (streaming and buffering).
|
|
618
|
+
*
|
|
619
|
+
* @remarks
|
|
620
|
+
* Extends {@link TyneqBaseEnumerator} with a typed source enumerator.
|
|
621
|
+
* Override `initialize()` to buffer or prepare state before the first `handleNext()`.
|
|
622
|
+
* Override `disposeAdditional()` to release resources beyond the source enumerator.
|
|
623
|
+
*
|
|
624
|
+
* @typeParam TInput - Source element type.
|
|
625
|
+
* @typeParam TOutput - Output element type (defaults to `TInput`).
|
|
626
|
+
* @group Plugin
|
|
627
|
+
*/
|
|
628
|
+
declare abstract class TyneqEnumerator<TInput, TOutput = TInput> extends TyneqBaseEnumerator<TInput, TOutput> {
|
|
629
|
+
protected readonly sourceEnumerator: Enumerator<TInput>;
|
|
630
|
+
private sourceDisposed;
|
|
631
|
+
constructor(sourceEnumerator: Enumerator<TInput>);
|
|
632
|
+
protected disposeSource(): void;
|
|
633
|
+
}
|
|
634
|
+
//#endregion
|
|
635
|
+
//#region src/core/enumerators/TyneqOrderedEnumerator.d.ts
|
|
636
|
+
/**
|
|
637
|
+
* Base class for enumerators that need the full ordered sequence (not just an Enumerator<T>).
|
|
638
|
+
* Lifecycle of the source is owned by the sequence, not the enumerator.
|
|
639
|
+
*
|
|
640
|
+
* @group Plugin
|
|
641
|
+
* @internal
|
|
642
|
+
*/
|
|
643
|
+
declare abstract class TyneqOrderedEnumerator<TSource> extends TyneqBaseEnumerator<TSource> {
|
|
644
|
+
protected readonly orderedSource: OrderedEnumerable<TSource>;
|
|
645
|
+
constructor(orderedSource: OrderedEnumerable<TSource>);
|
|
646
|
+
protected disposeSource(): void;
|
|
647
|
+
}
|
|
648
|
+
//#endregion
|
|
649
|
+
//#region src/core/enumerators/TyneqCachedEnumerator.d.ts
|
|
650
|
+
/**
|
|
651
|
+
* Base class for enumerators that need the full cached sequence (not just an Enumerator<T>).
|
|
652
|
+
* Lifecycle of the source is owned by the sequence, not the enumerator.
|
|
653
|
+
*
|
|
654
|
+
* @group Plugin
|
|
655
|
+
* @internal
|
|
656
|
+
*/
|
|
657
|
+
declare abstract class TyneqCachedEnumerator<TSource> extends TyneqBaseEnumerator<TSource> {
|
|
658
|
+
protected readonly cachedSource: CachedEnumerable<TSource>;
|
|
659
|
+
constructor(cachedSource: CachedEnumerable<TSource>);
|
|
660
|
+
protected disposeSource(): void;
|
|
661
|
+
}
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/core/terminal/TyneqTerminalOperator.d.ts
|
|
664
|
+
/**
|
|
665
|
+
* Abstract base for all terminal operators.
|
|
666
|
+
*
|
|
667
|
+
* @remarks
|
|
668
|
+
* Terminal operators consume a sequence and return a concrete value.
|
|
669
|
+
* Subclasses implement `process()` which enumerates `this.source` and returns the result.
|
|
670
|
+
* Register with `@terminal` or `createTerminalOperator`.
|
|
671
|
+
*
|
|
672
|
+
* @typeParam TSource - Element type of the source sequence.
|
|
673
|
+
* @typeParam TResult - The return type of `process()`.
|
|
674
|
+
* @group Plugin
|
|
675
|
+
*/
|
|
676
|
+
declare abstract class TyneqTerminalOperator<TSource, TResult = TSource> {
|
|
677
|
+
protected readonly source: Enumerable<TSource>;
|
|
678
|
+
constructor(source: Enumerable<TSource>);
|
|
679
|
+
/** Executes the terminal operation and returns the result. */
|
|
680
|
+
abstract process(): TResult;
|
|
681
|
+
}
|
|
682
|
+
//#endregion
|
|
683
|
+
//#region src/core/terminal/TyneqOrderedTerminalOperator.d.ts
|
|
684
|
+
/**
|
|
685
|
+
* Abstract base for terminal operators that require a fully ordered sequence.
|
|
686
|
+
*
|
|
687
|
+
* @remarks
|
|
688
|
+
* Use this when your terminal operator needs access to ordered-sequence members
|
|
689
|
+
* (comparers, parent chain, etc.). Register with `@orderedTerminal` or
|
|
690
|
+
* `createOrderedTerminalOperator`.
|
|
691
|
+
*
|
|
692
|
+
* @typeParam TSource - Element type of the source sequence.
|
|
693
|
+
* @typeParam TResult - The return type of `process()`.
|
|
694
|
+
* @group Plugin
|
|
695
|
+
*/
|
|
696
|
+
declare abstract class TyneqOrderedTerminalOperator<TSource, TResult = TSource> {
|
|
697
|
+
protected readonly source: OrderedEnumerable<TSource>;
|
|
698
|
+
constructor(source: OrderedEnumerable<TSource>);
|
|
699
|
+
/** Executes the terminal operation and returns the result. */
|
|
700
|
+
abstract process(): TResult;
|
|
701
|
+
}
|
|
702
|
+
//#endregion
|
|
703
|
+
//#region src/core/terminal/TyneqCachedTerminalOperator.d.ts
|
|
704
|
+
/**
|
|
705
|
+
* Abstract base for terminal operators that require a fully cached sequence.
|
|
706
|
+
*
|
|
707
|
+
* @remarks
|
|
708
|
+
* Use this when your terminal operator needs access to cached-sequence members
|
|
709
|
+
* (the internal cache, `refresh()`, etc.). Register with `@cachedTerminal` or
|
|
710
|
+
* `createCachedTerminalOperator`.
|
|
711
|
+
*
|
|
712
|
+
* @typeParam TSource - Element type of the source sequence.
|
|
713
|
+
* @typeParam TResult - The return type of `process()`.
|
|
714
|
+
* @group Plugin
|
|
715
|
+
*/
|
|
716
|
+
declare abstract class TyneqCachedTerminalOperator<TSource, TResult = TSource> {
|
|
717
|
+
protected readonly source: CachedEnumerable<TSource>;
|
|
718
|
+
constructor(source: CachedEnumerable<TSource>);
|
|
719
|
+
/** Executes the terminal operation and returns the result. */
|
|
720
|
+
abstract process(): TResult;
|
|
721
|
+
}
|
|
722
|
+
//#endregion
|
|
723
|
+
export { operator as S, cachedTerminal as _, TyneqOrderedEnumerator as a, cachedOperator as b, createCachedTerminalOperator as c, createCachedOperator as d, TyneqCachedEnumerable as f, createOperator as g, createGeneratorOperator as h, TyneqCachedEnumerator as i, createOrderedTerminalOperator as l, TyneqOrderedEnumerable as m, TyneqOrderedTerminalOperator as n, TyneqEnumerator as o, createOrderedOperator as p, TyneqTerminalOperator as r, TyneqBaseEnumerator as s, TyneqCachedTerminalOperator as t, createTerminalOperator as u, orderedTerminal as v, orderedOperator as x, terminal as y };
|
|
724
|
+
//# sourceMappingURL=TyneqCachedTerminalOperator.d.cts.map
|