ai-database 0.1.0 → 0.2.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.
Files changed (72) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/.turbo/turbo-test.log +102 -0
  3. package/README.md +381 -68
  4. package/TESTING.md +410 -0
  5. package/TEST_SUMMARY.md +250 -0
  6. package/TODO.md +128 -0
  7. package/dist/ai-promise-db.d.ts +370 -0
  8. package/dist/ai-promise-db.d.ts.map +1 -0
  9. package/dist/ai-promise-db.js +839 -0
  10. package/dist/ai-promise-db.js.map +1 -0
  11. package/dist/authorization.d.ts +531 -0
  12. package/dist/authorization.d.ts.map +1 -0
  13. package/dist/authorization.js +632 -0
  14. package/dist/authorization.js.map +1 -0
  15. package/dist/durable-clickhouse.d.ts +193 -0
  16. package/dist/durable-clickhouse.d.ts.map +1 -0
  17. package/dist/durable-clickhouse.js +422 -0
  18. package/dist/durable-clickhouse.js.map +1 -0
  19. package/dist/durable-promise.d.ts +182 -0
  20. package/dist/durable-promise.d.ts.map +1 -0
  21. package/dist/durable-promise.js +409 -0
  22. package/dist/durable-promise.js.map +1 -0
  23. package/dist/execution-queue.d.ts +239 -0
  24. package/dist/execution-queue.d.ts.map +1 -0
  25. package/dist/execution-queue.js +400 -0
  26. package/dist/execution-queue.js.map +1 -0
  27. package/dist/index.d.ts +50 -191
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +79 -462
  30. package/dist/index.js.map +1 -0
  31. package/dist/linguistic.d.ts +115 -0
  32. package/dist/linguistic.d.ts.map +1 -0
  33. package/dist/linguistic.js +379 -0
  34. package/dist/linguistic.js.map +1 -0
  35. package/dist/memory-provider.d.ts +304 -0
  36. package/dist/memory-provider.d.ts.map +1 -0
  37. package/dist/memory-provider.js +785 -0
  38. package/dist/memory-provider.js.map +1 -0
  39. package/dist/schema.d.ts +899 -0
  40. package/dist/schema.d.ts.map +1 -0
  41. package/dist/schema.js +1165 -0
  42. package/dist/schema.js.map +1 -0
  43. package/dist/tests.d.ts +107 -0
  44. package/dist/tests.d.ts.map +1 -0
  45. package/dist/tests.js +568 -0
  46. package/dist/tests.js.map +1 -0
  47. package/dist/types.d.ts +972 -0
  48. package/dist/types.d.ts.map +1 -0
  49. package/dist/types.js +126 -0
  50. package/dist/types.js.map +1 -0
  51. package/package.json +37 -37
  52. package/src/ai-promise-db.ts +1243 -0
  53. package/src/authorization.ts +1102 -0
  54. package/src/durable-clickhouse.ts +596 -0
  55. package/src/durable-promise.ts +582 -0
  56. package/src/execution-queue.ts +608 -0
  57. package/src/index.test.ts +868 -0
  58. package/src/index.ts +337 -0
  59. package/src/linguistic.ts +404 -0
  60. package/src/memory-provider.test.ts +1036 -0
  61. package/src/memory-provider.ts +1119 -0
  62. package/src/schema.test.ts +1254 -0
  63. package/src/schema.ts +2296 -0
  64. package/src/tests.ts +725 -0
  65. package/src/types.ts +1177 -0
  66. package/test/README.md +153 -0
  67. package/test/edge-cases.test.ts +646 -0
  68. package/test/provider-resolution.test.ts +402 -0
  69. package/tsconfig.json +9 -0
  70. package/vitest.config.ts +19 -0
  71. package/dist/index.d.mts +0 -195
  72. package/dist/index.mjs +0 -430
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Execution Queue - Manages execution priority and batching
3
+ *
4
+ * The queue decides WHEN to execute based on priority, concurrency, and batch windows.
5
+ * Operations can be executed immediately, queued, or deferred to batch processing.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { DurablePromise, type ExecutionPriority, type BatchScheduler } from './durable-promise.js';
10
+ /**
11
+ * Configuration for the execution queue
12
+ */
13
+ export interface ExecutionQueueOptions {
14
+ /** Default execution priority */
15
+ priority?: ExecutionPriority;
16
+ /** Maximum concurrent operations per priority tier */
17
+ concurrency?: {
18
+ priority?: number;
19
+ standard?: number;
20
+ flex?: number;
21
+ batch?: number;
22
+ };
23
+ /** Batch window in milliseconds (how long to accumulate before flush) */
24
+ batchWindow?: number;
25
+ /** Maximum batch size before auto-flush */
26
+ maxBatchSize?: number;
27
+ /** Auto-flush at process exit */
28
+ flushOnExit?: boolean;
29
+ }
30
+ /**
31
+ * Stats for queue monitoring
32
+ */
33
+ export interface QueueStats {
34
+ /** Counts by priority tier */
35
+ byPriority: Record<ExecutionPriority, {
36
+ pending: number;
37
+ active: number;
38
+ completed: number;
39
+ }>;
40
+ /** Total counts */
41
+ totals: {
42
+ pending: number;
43
+ active: number;
44
+ completed: number;
45
+ failed: number;
46
+ };
47
+ /** Current batch info */
48
+ batch: {
49
+ size: number;
50
+ nextFlush: Date | null;
51
+ };
52
+ }
53
+ /**
54
+ * Batch submission result from a provider
55
+ */
56
+ export interface BatchSubmission {
57
+ /** Provider-assigned batch ID */
58
+ batchId: string;
59
+ /** Estimated completion time */
60
+ estimatedCompletion?: Date;
61
+ /** Number of requests in batch */
62
+ count: number;
63
+ }
64
+ /**
65
+ * Provider interface for batch submission
66
+ */
67
+ export interface BatchProvider {
68
+ /** Provider name */
69
+ readonly name: string;
70
+ /** Whether this provider supports batch API */
71
+ readonly supportsBatch: boolean;
72
+ /** Whether this provider supports flex tier */
73
+ readonly supportsFlex: boolean;
74
+ /** Submit a batch of requests */
75
+ submitBatch(requests: BatchRequest[]): Promise<BatchSubmission>;
76
+ /** Get batch status */
77
+ getBatchStatus(batchId: string): Promise<BatchStatus>;
78
+ /** Stream results as they complete */
79
+ streamResults(batchId: string): AsyncIterable<BatchResult>;
80
+ }
81
+ /**
82
+ * A single request in a batch
83
+ */
84
+ export interface BatchRequest {
85
+ /** Unique ID for matching results */
86
+ customId: string;
87
+ /** The action ID (for updating status) */
88
+ actionId: string;
89
+ /** Method being called */
90
+ method: string;
91
+ /** Request parameters */
92
+ params: unknown;
93
+ }
94
+ /**
95
+ * Status of a batch
96
+ */
97
+ export interface BatchStatus {
98
+ /** Batch ID */
99
+ batchId: string;
100
+ /** Current status */
101
+ status: 'validating' | 'in_progress' | 'completed' | 'failed' | 'expired' | 'cancelled';
102
+ /** Completion counts */
103
+ counts: {
104
+ total: number;
105
+ completed: number;
106
+ failed: number;
107
+ };
108
+ /** Estimated completion */
109
+ estimatedCompletion?: Date;
110
+ /** Error message if failed */
111
+ error?: string;
112
+ }
113
+ /**
114
+ * A single result from a batch
115
+ */
116
+ export interface BatchResult {
117
+ /** Custom ID matching the request */
118
+ customId: string;
119
+ /** Action ID for updating status */
120
+ actionId: string;
121
+ /** Success or failure */
122
+ status: 'success' | 'error';
123
+ /** Result data (if success) */
124
+ result?: unknown;
125
+ /** Error details (if error) */
126
+ error?: {
127
+ code: string;
128
+ message: string;
129
+ };
130
+ }
131
+ /**
132
+ * Manages execution of DurablePromises with priority-based scheduling
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * const queue = new ExecutionQueue({
137
+ * priority: 'standard',
138
+ * concurrency: { standard: 10, batch: 1000 },
139
+ * batchWindow: 60000, // 1 minute
140
+ * })
141
+ *
142
+ * // Register batch providers
143
+ * queue.registerProvider(openaiProvider)
144
+ * queue.registerProvider(claudeProvider)
145
+ *
146
+ * // Queue operations
147
+ * queue.enqueue(durablePromise)
148
+ *
149
+ * // Flush batch at end of workflow
150
+ * await queue.flush()
151
+ * ```
152
+ */
153
+ export declare class ExecutionQueue implements BatchScheduler {
154
+ private readonly semaphores;
155
+ private readonly queues;
156
+ private readonly providers;
157
+ private readonly options;
158
+ private batchTimer;
159
+ private completedCount;
160
+ private failedCount;
161
+ private isProcessing;
162
+ constructor(options?: ExecutionQueueOptions);
163
+ /**
164
+ * Register a batch provider
165
+ */
166
+ registerProvider(provider: BatchProvider): void;
167
+ /**
168
+ * Get a registered provider
169
+ */
170
+ getProvider(name: string): BatchProvider | undefined;
171
+ /**
172
+ * List registered providers
173
+ */
174
+ listProviders(): BatchProvider[];
175
+ /**
176
+ * Add a promise to the execution queue
177
+ */
178
+ enqueue(promise: DurablePromise<unknown>): void;
179
+ private startBatchTimer;
180
+ private processQueue;
181
+ /**
182
+ * Flush all pending batch operations
183
+ */
184
+ flush(): Promise<void>;
185
+ private groupByProvider;
186
+ private getProviderFromMethod;
187
+ private submitToBatchProvider;
188
+ private executeFallback;
189
+ private pollBatchCompletion;
190
+ /**
191
+ * Set the default priority for new operations
192
+ */
193
+ setPriority(priority: ExecutionPriority): void;
194
+ /**
195
+ * Set concurrency limit for a priority tier
196
+ */
197
+ setConcurrency(priority: ExecutionPriority, limit: number): void;
198
+ /**
199
+ * Set the batch window (how long to accumulate before auto-flush)
200
+ */
201
+ setBatchWindow(ms: number): void;
202
+ /**
203
+ * Set max batch size before auto-flush
204
+ */
205
+ setMaxBatchSize(size: number): void;
206
+ /**
207
+ * Get count of pending operations
208
+ */
209
+ get pending(): number;
210
+ /**
211
+ * Get count of active operations
212
+ */
213
+ get active(): number;
214
+ /**
215
+ * Get count of completed operations
216
+ */
217
+ get completed(): number;
218
+ /**
219
+ * Get full queue statistics
220
+ */
221
+ getStats(): QueueStats;
222
+ /**
223
+ * Stop the queue and clear all pending operations
224
+ */
225
+ destroy(): void;
226
+ }
227
+ /**
228
+ * Create an execution queue
229
+ */
230
+ export declare function createExecutionQueue(options?: ExecutionQueueOptions): ExecutionQueue;
231
+ /**
232
+ * Get or create the default execution queue
233
+ */
234
+ export declare function getDefaultQueue(): ExecutionQueue;
235
+ /**
236
+ * Set the default execution queue
237
+ */
238
+ export declare function setDefaultQueue(queue: ExecutionQueue | null): void;
239
+ //# sourceMappingURL=execution-queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-queue.d.ts","sourceRoot":"","sources":["../src/execution-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,cAAc,EAEd,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,sBAAsB,CAAA;AAM7B;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,iCAAiC;IACjC,QAAQ,CAAC,EAAE,iBAAiB,CAAA;IAE5B,sDAAsD;IACtD,WAAW,CAAC,EAAE;QACZ,QAAQ,CAAC,EA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;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;OAEG;IACH,QAAQ,IAAI,UAAU;IA2CtB;;OAEG;IACH,OAAO,IAAI,IAAI;CAahB;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,cAAc,CAEpF;AAQD;;GAEG;AACH,wBAAgB,eAAe,IAAI,cAAc,CAKhD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,GAAG,IAAI,CAElE"}
@@ -0,0 +1,400 @@
1
+ /**
2
+ * Execution Queue - Manages execution priority and batching
3
+ *
4
+ * The queue decides WHEN to execute based on priority, concurrency, and batch windows.
5
+ * Operations can be executed immediately, queued, or deferred to batch processing.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { Semaphore } from './memory-provider.js';
10
+ import { DurablePromise, setBatchScheduler, } from './durable-promise.js';
11
+ // =============================================================================
12
+ // ExecutionQueue Class
13
+ // =============================================================================
14
+ /**
15
+ * Manages execution of DurablePromises with priority-based scheduling
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const queue = new ExecutionQueue({
20
+ * priority: 'standard',
21
+ * concurrency: { standard: 10, batch: 1000 },
22
+ * batchWindow: 60000, // 1 minute
23
+ * })
24
+ *
25
+ * // Register batch providers
26
+ * queue.registerProvider(openaiProvider)
27
+ * queue.registerProvider(claudeProvider)
28
+ *
29
+ * // Queue operations
30
+ * queue.enqueue(durablePromise)
31
+ *
32
+ * // Flush batch at end of workflow
33
+ * await queue.flush()
34
+ * ```
35
+ */
36
+ export class ExecutionQueue {
37
+ semaphores;
38
+ queues;
39
+ providers = new Map();
40
+ options;
41
+ batchTimer = null;
42
+ completedCount = 0;
43
+ failedCount = 0;
44
+ isProcessing = false;
45
+ constructor(options = {}) {
46
+ this.options = {
47
+ priority: options.priority ?? 'standard',
48
+ concurrency: {
49
+ priority: options.concurrency?.priority ?? 50,
50
+ standard: options.concurrency?.standard ?? 20,
51
+ flex: options.concurrency?.flex ?? 10,
52
+ batch: options.concurrency?.batch ?? 1000,
53
+ },
54
+ batchWindow: options.batchWindow ?? 60000, // 1 minute default
55
+ maxBatchSize: options.maxBatchSize ?? 10000,
56
+ flushOnExit: options.flushOnExit ?? true,
57
+ };
58
+ // Initialize semaphores for each priority tier
59
+ this.semaphores = {
60
+ priority: new Semaphore(this.options.concurrency.priority),
61
+ standard: new Semaphore(this.options.concurrency.standard),
62
+ flex: new Semaphore(this.options.concurrency.flex),
63
+ batch: new Semaphore(this.options.concurrency.batch),
64
+ };
65
+ // Initialize queues
66
+ this.queues = {
67
+ priority: [],
68
+ standard: [],
69
+ flex: [],
70
+ batch: [],
71
+ };
72
+ // Register as global batch scheduler
73
+ setBatchScheduler(this);
74
+ // Setup exit handler
75
+ if (this.options.flushOnExit && typeof process !== 'undefined') {
76
+ const exitHandler = async () => {
77
+ await this.flush();
78
+ };
79
+ process.on('beforeExit', exitHandler);
80
+ process.on('SIGINT', async () => {
81
+ await exitHandler();
82
+ process.exit(0);
83
+ });
84
+ process.on('SIGTERM', async () => {
85
+ await exitHandler();
86
+ process.exit(0);
87
+ });
88
+ }
89
+ }
90
+ // ===========================================================================
91
+ // Provider Management
92
+ // ===========================================================================
93
+ /**
94
+ * Register a batch provider
95
+ */
96
+ registerProvider(provider) {
97
+ this.providers.set(provider.name, provider);
98
+ }
99
+ /**
100
+ * Get a registered provider
101
+ */
102
+ getProvider(name) {
103
+ return this.providers.get(name);
104
+ }
105
+ /**
106
+ * List registered providers
107
+ */
108
+ listProviders() {
109
+ return Array.from(this.providers.values());
110
+ }
111
+ // ===========================================================================
112
+ // Queue Operations
113
+ // ===========================================================================
114
+ /**
115
+ * Add a promise to the execution queue
116
+ */
117
+ enqueue(promise) {
118
+ const item = {
119
+ promise,
120
+ priority: promise.priority,
121
+ enqueuedAt: new Date(),
122
+ };
123
+ this.queues[promise.priority].push(item);
124
+ // For batch, start the window timer
125
+ if (promise.priority === 'batch') {
126
+ this.startBatchTimer();
127
+ // Check for auto-flush on size
128
+ if (this.queues.batch.length >= this.options.maxBatchSize) {
129
+ this.flush();
130
+ }
131
+ }
132
+ else {
133
+ // For other priorities, process immediately
134
+ this.processQueue(promise.priority);
135
+ }
136
+ }
137
+ startBatchTimer() {
138
+ if (this.batchTimer)
139
+ return;
140
+ this.batchTimer = setTimeout(async () => {
141
+ this.batchTimer = null;
142
+ await this.flush();
143
+ }, this.options.batchWindow);
144
+ }
145
+ async processQueue(priority) {
146
+ if (this.isProcessing)
147
+ return;
148
+ this.isProcessing = true;
149
+ const queue = this.queues[priority];
150
+ const semaphore = this.semaphores[priority];
151
+ try {
152
+ while (queue.length > 0) {
153
+ const item = queue.shift();
154
+ if (!item)
155
+ break;
156
+ // Run with concurrency control
157
+ // The promise will execute itself; we just track completion
158
+ semaphore.run(async () => {
159
+ try {
160
+ await item.promise;
161
+ this.completedCount++;
162
+ }
163
+ catch {
164
+ this.failedCount++;
165
+ }
166
+ });
167
+ }
168
+ }
169
+ finally {
170
+ this.isProcessing = false;
171
+ }
172
+ }
173
+ // ===========================================================================
174
+ // Batch Operations
175
+ // ===========================================================================
176
+ /**
177
+ * Flush all pending batch operations
178
+ */
179
+ async flush() {
180
+ // Clear the timer
181
+ if (this.batchTimer) {
182
+ clearTimeout(this.batchTimer);
183
+ this.batchTimer = null;
184
+ }
185
+ const batchItems = [...this.queues.batch];
186
+ this.queues.batch = [];
187
+ if (batchItems.length === 0)
188
+ return;
189
+ // Group by method/provider
190
+ const groups = this.groupByProvider(batchItems);
191
+ // Submit each group to its provider
192
+ const submissions = await Promise.all(Array.from(groups.entries()).map(async ([providerName, items]) => {
193
+ const provider = this.providers.get(providerName);
194
+ if (!provider) {
195
+ // Fallback to standard execution if no provider
196
+ return this.executeFallback(items);
197
+ }
198
+ return this.submitToBatchProvider(provider, items);
199
+ }));
200
+ // Wait for all batch results
201
+ await Promise.all(submissions.map((submission) => {
202
+ if (submission && 'batchId' in submission) {
203
+ return this.pollBatchCompletion(submission);
204
+ }
205
+ return Promise.resolve();
206
+ }));
207
+ }
208
+ groupByProvider(items) {
209
+ const groups = new Map();
210
+ for (const item of items) {
211
+ // Determine provider from method prefix
212
+ const providerName = this.getProviderFromMethod(item.promise.method);
213
+ const existing = groups.get(providerName) || [];
214
+ existing.push(item);
215
+ groups.set(providerName, existing);
216
+ }
217
+ return groups;
218
+ }
219
+ getProviderFromMethod(method) {
220
+ // Extract provider from method like 'openai.chat' -> 'openai'
221
+ const parts = method.split('.');
222
+ return parts[0] || 'default';
223
+ }
224
+ async submitToBatchProvider(provider, items) {
225
+ if (!provider.supportsBatch) {
226
+ await this.executeFallback(items);
227
+ return null;
228
+ }
229
+ const requests = items.map((item) => ({
230
+ customId: crypto.randomUUID(),
231
+ actionId: item.promise.actionId,
232
+ method: item.promise.method,
233
+ params: {}, // Would need to extract from promise
234
+ }));
235
+ try {
236
+ return await provider.submitBatch(requests);
237
+ }
238
+ catch (error) {
239
+ console.error(`Batch submission failed for ${provider.name}:`, error);
240
+ await this.executeFallback(items);
241
+ return null;
242
+ }
243
+ }
244
+ async executeFallback(items) {
245
+ // Execute as standard priority
246
+ for (const item of items) {
247
+ this.queues.standard.push(item);
248
+ }
249
+ await this.processQueue('standard');
250
+ }
251
+ async pollBatchCompletion(submission) {
252
+ // This would be implemented by the specific provider
253
+ // For now, just log
254
+ console.log(`Batch ${submission.batchId} submitted with ${submission.count} requests`);
255
+ // In production, this would poll getBatchStatus and stream results
256
+ }
257
+ // ===========================================================================
258
+ // Configuration
259
+ // ===========================================================================
260
+ /**
261
+ * Set the default priority for new operations
262
+ */
263
+ setPriority(priority) {
264
+ this.options.priority = priority;
265
+ }
266
+ /**
267
+ * Set concurrency limit for a priority tier
268
+ */
269
+ setConcurrency(priority, limit) {
270
+ this.options.concurrency[priority] = limit;
271
+ // Re-create the semaphore (existing operations continue with old limit)
272
+ this.semaphores[priority] = new Semaphore(limit);
273
+ }
274
+ /**
275
+ * Set the batch window (how long to accumulate before auto-flush)
276
+ */
277
+ setBatchWindow(ms) {
278
+ this.options.batchWindow = ms;
279
+ }
280
+ /**
281
+ * Set max batch size before auto-flush
282
+ */
283
+ setMaxBatchSize(size) {
284
+ this.options.maxBatchSize = size;
285
+ }
286
+ // ===========================================================================
287
+ // Stats
288
+ // ===========================================================================
289
+ /**
290
+ * Get count of pending operations
291
+ */
292
+ get pending() {
293
+ return (this.queues.priority.length +
294
+ this.queues.standard.length +
295
+ this.queues.flex.length +
296
+ this.queues.batch.length);
297
+ }
298
+ /**
299
+ * Get count of active operations
300
+ */
301
+ get active() {
302
+ return (this.semaphores.priority.active +
303
+ this.semaphores.standard.active +
304
+ this.semaphores.flex.active +
305
+ this.semaphores.batch.active);
306
+ }
307
+ /**
308
+ * Get count of completed operations
309
+ */
310
+ get completed() {
311
+ return this.completedCount;
312
+ }
313
+ /**
314
+ * Get full queue statistics
315
+ */
316
+ getStats() {
317
+ return {
318
+ byPriority: {
319
+ priority: {
320
+ pending: this.queues.priority.length,
321
+ active: this.semaphores.priority.active,
322
+ completed: 0, // Would need per-tier tracking
323
+ },
324
+ standard: {
325
+ pending: this.queues.standard.length,
326
+ active: this.semaphores.standard.active,
327
+ completed: 0,
328
+ },
329
+ flex: {
330
+ pending: this.queues.flex.length,
331
+ active: this.semaphores.flex.active,
332
+ completed: 0,
333
+ },
334
+ batch: {
335
+ pending: this.queues.batch.length,
336
+ active: this.semaphores.batch.active,
337
+ completed: 0,
338
+ },
339
+ },
340
+ totals: {
341
+ pending: this.pending,
342
+ active: this.active,
343
+ completed: this.completedCount,
344
+ failed: this.failedCount,
345
+ },
346
+ batch: {
347
+ size: this.queues.batch.length,
348
+ nextFlush: this.batchTimer
349
+ ? new Date(Date.now() + this.options.batchWindow)
350
+ : null,
351
+ },
352
+ };
353
+ }
354
+ // ===========================================================================
355
+ // Cleanup
356
+ // ===========================================================================
357
+ /**
358
+ * Stop the queue and clear all pending operations
359
+ */
360
+ destroy() {
361
+ if (this.batchTimer) {
362
+ clearTimeout(this.batchTimer);
363
+ this.batchTimer = null;
364
+ }
365
+ this.queues.priority = [];
366
+ this.queues.standard = [];
367
+ this.queues.flex = [];
368
+ this.queues.batch = [];
369
+ setBatchScheduler(null);
370
+ }
371
+ }
372
+ // =============================================================================
373
+ // Factory
374
+ // =============================================================================
375
+ /**
376
+ * Create an execution queue
377
+ */
378
+ export function createExecutionQueue(options) {
379
+ return new ExecutionQueue(options);
380
+ }
381
+ // =============================================================================
382
+ // Default Instance
383
+ // =============================================================================
384
+ let defaultQueue = null;
385
+ /**
386
+ * Get or create the default execution queue
387
+ */
388
+ export function getDefaultQueue() {
389
+ if (!defaultQueue) {
390
+ defaultQueue = createExecutionQueue();
391
+ }
392
+ return defaultQueue;
393
+ }
394
+ /**
395
+ * Set the default execution queue
396
+ */
397
+ export function setDefaultQueue(queue) {
398
+ defaultQueue = queue;
399
+ }
400
+ //# sourceMappingURL=execution-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-queue.js","sourceRoot":"","sources":["../src/execution-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EACL,cAAc,EACd,iBAAiB,GAGlB,MAAM,sBAAsB,CAAA;AA4I7B,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,cAAc;IACR,UAAU,CAAsC;IAChD,MAAM,CAAwC;IAC9C,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAA;IAC5C,OAAO,CAAiC;IAEjD,UAAU,GAAyC,IAAI,CAAA;IACvD,cAAc,GAAG,CAAC,CAAA;IAClB,WAAW,GAAG,CAAC,CAAA;IACf,YAAY,GAAG,KAAK,CAAA;IAE5B,YAAY,UAAiC,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG;YACb,QAAQ,EAAE,OAAO,CAAC,QA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