ai-database 0.0.0-development → 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 (79) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/.turbo/turbo-test.log +102 -0
  3. package/README.md +402 -47
  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 +54 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +79 -0
  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 -23
  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/LICENSE +0 -21
  72. package/dist/types/database.d.ts +0 -46
  73. package/dist/types/document.d.ts +0 -15
  74. package/dist/types/index.d.ts +0 -5
  75. package/dist/types/mdxdb/embedding.d.ts +0 -7
  76. package/dist/types/mdxdb/types.d.ts +0 -59
  77. package/dist/types/synthetic.d.ts +0 -9
  78. package/dist/types/tools.d.ts +0 -10
  79. package/dist/types/vector.d.ts +0 -16
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Durable Promise - Promise-like wrapper around database Actions
3
+ *
4
+ * Time is an implementation detail. Whether an operation takes 10ms or 10 hours,
5
+ * the same code works. The DurablePromise persists its state as an Action,
6
+ * allowing crash recovery, observability, and time-agnostic execution.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import type { Action, MemoryProvider } from './memory-provider.js';
11
+ /**
12
+ * Execution priority tiers
13
+ *
14
+ * - priority: Pay more for immediate execution (fastest, highest cost)
15
+ * - standard: Normal price/latency tradeoff (default)
16
+ * - flex: Discount for variable latency (cost savings)
17
+ * - batch: Maximum discount, 24h SLA (50% savings)
18
+ */
19
+ export type ExecutionPriority = 'priority' | 'standard' | 'flex' | 'batch';
20
+ /**
21
+ * Options for creating a DurablePromise
22
+ */
23
+ export interface DurablePromiseOptions<T = unknown> {
24
+ /** Method identifier (e.g., 'ai.generate', 'db.get', 'api.fetch') */
25
+ method: string;
26
+ /** Arguments passed to the method */
27
+ args?: unknown[];
28
+ /** The executor function that performs the actual work */
29
+ executor: () => Promise<T>;
30
+ /** Execution priority tier (defaults to context or 'standard') */
31
+ priority?: ExecutionPriority;
32
+ /** Concurrency key for queue grouping */
33
+ concurrencyKey?: string;
34
+ /** Defer execution until this time (for batch windows) */
35
+ deferUntil?: Date;
36
+ /** Action IDs this promise depends on (must complete first) */
37
+ dependsOn?: string[];
38
+ /** Actor identifier (who initiated this operation) */
39
+ actor?: string;
40
+ /** Additional metadata */
41
+ meta?: Record<string, unknown>;
42
+ /** Provider instance (if not using context) */
43
+ provider?: MemoryProvider;
44
+ }
45
+ /**
46
+ * Result of DurablePromise resolution
47
+ */
48
+ export interface DurablePromiseResult<T> {
49
+ /** The resolved value */
50
+ value: T;
51
+ /** The underlying Action record */
52
+ action: Action;
53
+ /** Total execution time in ms */
54
+ duration: number;
55
+ }
56
+ interface ExecutionContext {
57
+ priority: ExecutionPriority;
58
+ provider?: MemoryProvider;
59
+ concurrencyKey?: string;
60
+ actor?: string;
61
+ batchWindow?: number;
62
+ onFlush?: () => Promise<void>;
63
+ }
64
+ /**
65
+ * Get the current execution context
66
+ */
67
+ export declare function getCurrentContext(): ExecutionContext | undefined;
68
+ /**
69
+ * Run code within an execution context
70
+ */
71
+ export declare function withContext<T>(context: Partial<ExecutionContext>, fn: () => Promise<T>): Promise<T>;
72
+ /**
73
+ * Set global default context
74
+ */
75
+ export declare function setDefaultContext(context: Partial<ExecutionContext>): void;
76
+ /** Symbol to identify DurablePromise instances */
77
+ export declare const DURABLE_PROMISE_SYMBOL: unique symbol;
78
+ /**
79
+ * A Promise-like class that persists its state as an Action
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const promise = new DurablePromise({
84
+ * method: 'ai.generate',
85
+ * args: [{ prompt: 'Hello' }],
86
+ * executor: async () => await ai.generate({ prompt: 'Hello' }),
87
+ * priority: 'batch',
88
+ * })
89
+ *
90
+ * // Access the underlying action
91
+ * console.log(promise.actionId)
92
+ *
93
+ * // Await like a normal promise
94
+ * const result = await promise
95
+ * ```
96
+ */
97
+ export declare class DurablePromise<T> implements PromiseLike<T> {
98
+ readonly [DURABLE_PROMISE_SYMBOL] = true;
99
+ /** The Action ID backing this promise */
100
+ readonly actionId: string;
101
+ /** The method being executed */
102
+ readonly method: string;
103
+ /** The execution priority */
104
+ readonly priority: ExecutionPriority;
105
+ /** Dependencies that must complete first */
106
+ readonly dependsOn: string[];
107
+ private readonly state;
108
+ private action;
109
+ private provider;
110
+ private executor;
111
+ private startTime;
112
+ constructor(options: DurablePromiseOptions<T>);
113
+ private initializeAction;
114
+ private parseActionVerb;
115
+ private waitForDependencies;
116
+ private execute;
117
+ private executeDirectly;
118
+ private resolve;
119
+ private reject;
120
+ /**
121
+ * Implement PromiseLike interface
122
+ */
123
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
124
+ /**
125
+ * Catch handler
126
+ */
127
+ catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
128
+ /**
129
+ * Finally handler
130
+ */
131
+ finally(onfinally?: (() => void) | null): Promise<T>;
132
+ /**
133
+ * Get the current status
134
+ */
135
+ get status(): Action['status'];
136
+ /**
137
+ * Get the underlying Action (if available)
138
+ */
139
+ getAction(): Promise<Action | null>;
140
+ /**
141
+ * Get the result with full metadata
142
+ */
143
+ getResult(): Promise<DurablePromiseResult<T>>;
144
+ /**
145
+ * Cancel the promise if still pending
146
+ */
147
+ cancel(): Promise<void>;
148
+ /**
149
+ * Retry a failed promise
150
+ */
151
+ retry(): Promise<this>;
152
+ }
153
+ /**
154
+ * Check if a value is a DurablePromise
155
+ */
156
+ export declare function isDurablePromise(value: unknown): value is DurablePromise<unknown>;
157
+ /**
158
+ * Create a durable promise from an executor function
159
+ */
160
+ export declare function durable<T>(method: string, executor: () => Promise<T>, options?: Omit<DurablePromiseOptions<T>, 'method' | 'executor'>): DurablePromise<T>;
161
+ /**
162
+ * Get the global batch scheduler
163
+ */
164
+ export declare function getBatchScheduler(): BatchScheduler | null;
165
+ /**
166
+ * Set the global batch scheduler
167
+ */
168
+ export declare function setBatchScheduler(scheduler: BatchScheduler | null): void;
169
+ /**
170
+ * Interface for batch scheduling
171
+ * Full implementation is in execution-queue.ts
172
+ */
173
+ export interface BatchScheduler {
174
+ /** Add a promise to the batch queue */
175
+ enqueue(promise: DurablePromise<unknown>): void;
176
+ /** Flush all pending batches */
177
+ flush(): Promise<void>;
178
+ /** Get count of pending promises */
179
+ readonly pending: number;
180
+ }
181
+ export {};
182
+ //# sourceMappingURL=durable-promise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-promise.d.ts","sourceRoot":"","sources":["../src/durable-promise.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAMlE;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAA;AAE1E;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC,GAAG,OAAO;IAChD,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAA;IAEd,qCAAqC;IACrC,IAAI,CAAC,EAAE,OAAO,EAAE,C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C,OAAO,CAAC,GAAG,IAAI,CAAA;IAE/C,gCAAgC;IAChC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAEtB,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB"}
@@ -0,0 +1,409 @@
1
+ /**
2
+ * Durable Promise - Promise-like wrapper around database Actions
3
+ *
4
+ * Time is an implementation detail. Whether an operation takes 10ms or 10 hours,
5
+ * the same code works. The DurablePromise persists its state as an Action,
6
+ * allowing crash recovery, observability, and time-agnostic execution.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ const contextStack = [];
11
+ /**
12
+ * Get the current execution context
13
+ */
14
+ export function getCurrentContext() {
15
+ return contextStack[contextStack.length - 1];
16
+ }
17
+ /**
18
+ * Run code within an execution context
19
+ */
20
+ export async function withContext(context, fn) {
21
+ const parent = getCurrentContext();
22
+ const merged = {
23
+ priority: context.priority ?? parent?.priority ?? 'standard',
24
+ provider: context.provider ?? parent?.provider,
25
+ concurrencyKey: context.concurrencyKey ?? parent?.concurrencyKey,
26
+ actor: context.actor ?? parent?.actor,
27
+ batchWindow: context.batchWindow ?? parent?.batchWindow,
28
+ onFlush: context.onFlush ?? parent?.onFlush,
29
+ };
30
+ contextStack.push(merged);
31
+ try {
32
+ return await fn();
33
+ }
34
+ finally {
35
+ contextStack.pop();
36
+ }
37
+ }
38
+ /**
39
+ * Set global default context
40
+ */
41
+ export function setDefaultContext(context) {
42
+ if (contextStack.length === 0) {
43
+ contextStack.push({
44
+ priority: context.priority ?? 'standard',
45
+ provider: context.provider,
46
+ concurrencyKey: context.concurrencyKey,
47
+ actor: context.actor,
48
+ batchWindow: context.batchWindow,
49
+ onFlush: context.onFlush,
50
+ });
51
+ }
52
+ else {
53
+ Object.assign(contextStack[0], context);
54
+ }
55
+ }
56
+ // =============================================================================
57
+ // DurablePromise Class
58
+ // =============================================================================
59
+ /** Symbol to identify DurablePromise instances */
60
+ export const DURABLE_PROMISE_SYMBOL = Symbol.for('ai-database.DurablePromise');
61
+ /**
62
+ * A Promise-like class that persists its state as an Action
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const promise = new DurablePromise({
67
+ * method: 'ai.generate',
68
+ * args: [{ prompt: 'Hello' }],
69
+ * executor: async () => await ai.generate({ prompt: 'Hello' }),
70
+ * priority: 'batch',
71
+ * })
72
+ *
73
+ * // Access the underlying action
74
+ * console.log(promise.actionId)
75
+ *
76
+ * // Await like a normal promise
77
+ * const result = await promise
78
+ * ```
79
+ */
80
+ export class DurablePromise {
81
+ [DURABLE_PROMISE_SYMBOL] = true;
82
+ /** The Action ID backing this promise */
83
+ actionId;
84
+ /** The method being executed */
85
+ method;
86
+ /** The execution priority */
87
+ priority;
88
+ /** Dependencies that must complete first */
89
+ dependsOn;
90
+ state = {
91
+ status: 'pending',
92
+ resolvers: [],
93
+ };
94
+ action = null;
95
+ provider = null;
96
+ executor = null;
97
+ startTime = Date.now();
98
+ constructor(options) {
99
+ const context = getCurrentContext();
100
+ this.method = options.method;
101
+ this.priority = options.priority ?? context?.priority ?? 'standard';
102
+ this.dependsOn = options.dependsOn ?? [];
103
+ this.provider = options.provider ?? context?.provider ?? null;
104
+ this.executor = options.executor;
105
+ this.actionId = crypto.randomUUID();
106
+ // Create the action immediately if we have a provider
107
+ if (this.provider) {
108
+ this.initializeAction(options);
109
+ }
110
+ else {
111
+ // Defer action creation but start execution
112
+ this.executeDirectly();
113
+ }
114
+ }
115
+ async initializeAction(options) {
116
+ if (!this.provider)
117
+ return;
118
+ try {
119
+ // Create the action record
120
+ this.action = await this.provider.createAction({
121
+ actor: options.actor ?? getCurrentContext()?.actor ?? 'system',
122
+ action: this.parseActionVerb(this.method),
123
+ object: this.method,
124
+ objectData: {
125
+ method: this.method,
126
+ args: options.args,
127
+ priority: this.priority,
128
+ concurrencyKey: options.concurrencyKey,
129
+ deferUntil: options.deferUntil?.toISOString(),
130
+ dependsOn: this.dependsOn,
131
+ },
132
+ meta: options.meta,
133
+ });
134
+ this.action.id = this.actionId;
135
+ // Check if we should defer execution
136
+ if (this.priority === 'batch') {
137
+ // Register with the batch scheduler instead of executing immediately
138
+ const scheduler = getBatchScheduler();
139
+ if (scheduler) {
140
+ scheduler.enqueue(this);
141
+ return;
142
+ }
143
+ }
144
+ // Check dependencies
145
+ if (this.dependsOn.length > 0) {
146
+ await this.waitForDependencies();
147
+ }
148
+ // Execute
149
+ await this.execute();
150
+ }
151
+ catch (error) {
152
+ this.reject(error);
153
+ }
154
+ }
155
+ parseActionVerb(method) {
156
+ // Extract verb from method like 'ai.generate' -> 'generate'
157
+ const parts = method.split('.');
158
+ return parts[parts.length - 1] || 'process';
159
+ }
160
+ async waitForDependencies() {
161
+ if (!this.provider || this.dependsOn.length === 0)
162
+ return;
163
+ // Poll for dependency completion
164
+ const checkInterval = 100; // ms
165
+ const maxWait = 24 * 60 * 60 * 1000; // 24 hours
166
+ const startWait = Date.now();
167
+ while (Date.now() - startWait < maxWait) {
168
+ const pending = await this.provider.listActions({
169
+ status: 'pending',
170
+ });
171
+ const active = await this.provider.listActions({
172
+ status: 'active',
173
+ });
174
+ const blockedBy = [...pending, ...active]
175
+ .filter((a) => this.dependsOn.includes(a.id))
176
+ .map((a) => a.id);
177
+ if (blockedBy.length === 0) {
178
+ // All dependencies resolved
179
+ return;
180
+ }
181
+ // Wait before checking again
182
+ await new Promise((resolve) => setTimeout(resolve, checkInterval));
183
+ }
184
+ throw new Error(`Timeout waiting for dependencies: ${this.dependsOn.join(', ')}`);
185
+ }
186
+ async execute() {
187
+ if (!this.executor) {
188
+ throw new Error('No executor provided');
189
+ }
190
+ try {
191
+ // Mark as active
192
+ if (this.provider && this.action) {
193
+ await this.provider.updateAction(this.actionId, { status: 'active' });
194
+ }
195
+ // Execute the actual work
196
+ const result = await this.executor();
197
+ // Mark as completed
198
+ if (this.provider && this.action) {
199
+ await this.provider.updateAction(this.actionId, {
200
+ status: 'completed',
201
+ result: { value: result },
202
+ });
203
+ }
204
+ this.resolve(result);
205
+ }
206
+ catch (error) {
207
+ // Mark as failed
208
+ if (this.provider && this.action) {
209
+ await this.provider.updateAction(this.actionId, {
210
+ status: 'failed',
211
+ error: error.message,
212
+ });
213
+ }
214
+ this.reject(error);
215
+ }
216
+ }
217
+ async executeDirectly() {
218
+ if (!this.executor) {
219
+ throw new Error('No executor provided');
220
+ }
221
+ try {
222
+ const result = await this.executor();
223
+ this.resolve(result);
224
+ }
225
+ catch (error) {
226
+ this.reject(error);
227
+ }
228
+ }
229
+ resolve(value) {
230
+ if (this.state.status !== 'pending')
231
+ return;
232
+ this.state.status = 'resolved';
233
+ this.state.value = value;
234
+ for (const { resolve } of this.state.resolvers) {
235
+ resolve(value);
236
+ }
237
+ this.state.resolvers = [];
238
+ }
239
+ reject(error) {
240
+ if (this.state.status !== 'pending')
241
+ return;
242
+ this.state.status = 'rejected';
243
+ this.state.error = error;
244
+ for (const { reject } of this.state.resolvers) {
245
+ reject(error);
246
+ }
247
+ this.state.resolvers = [];
248
+ }
249
+ /**
250
+ * Implement PromiseLike interface
251
+ */
252
+ then(onfulfilled, onrejected) {
253
+ return new Promise((resolve, reject) => {
254
+ const handleResolve = (value) => {
255
+ if (onfulfilled) {
256
+ try {
257
+ resolve(onfulfilled(value));
258
+ }
259
+ catch (e) {
260
+ reject(e);
261
+ }
262
+ }
263
+ else {
264
+ resolve(value);
265
+ }
266
+ };
267
+ const handleReject = (error) => {
268
+ if (onrejected) {
269
+ try {
270
+ resolve(onrejected(error));
271
+ }
272
+ catch (e) {
273
+ reject(e);
274
+ }
275
+ }
276
+ else {
277
+ reject(error);
278
+ }
279
+ };
280
+ if (this.state.status === 'resolved') {
281
+ handleResolve(this.state.value);
282
+ }
283
+ else if (this.state.status === 'rejected') {
284
+ handleReject(this.state.error);
285
+ }
286
+ else {
287
+ this.state.resolvers.push({
288
+ resolve: handleResolve,
289
+ reject: handleReject,
290
+ });
291
+ }
292
+ });
293
+ }
294
+ /**
295
+ * Catch handler
296
+ */
297
+ catch(onrejected) {
298
+ return this.then(null, onrejected);
299
+ }
300
+ /**
301
+ * Finally handler
302
+ */
303
+ finally(onfinally) {
304
+ return this.then((value) => {
305
+ onfinally?.();
306
+ return value;
307
+ }, (reason) => {
308
+ onfinally?.();
309
+ throw reason;
310
+ });
311
+ }
312
+ /**
313
+ * Get the current status
314
+ */
315
+ get status() {
316
+ if (this.action)
317
+ return this.action.status;
318
+ if (this.state.status === 'resolved')
319
+ return 'completed';
320
+ if (this.state.status === 'rejected')
321
+ return 'failed';
322
+ return 'pending';
323
+ }
324
+ /**
325
+ * Get the underlying Action (if available)
326
+ */
327
+ async getAction() {
328
+ if (this.action)
329
+ return this.action;
330
+ if (!this.provider)
331
+ return null;
332
+ return this.provider.getAction(this.actionId);
333
+ }
334
+ /**
335
+ * Get the result with full metadata
336
+ */
337
+ async getResult() {
338
+ const value = await this;
339
+ const action = await this.getAction();
340
+ return {
341
+ value,
342
+ action: action,
343
+ duration: Date.now() - this.startTime,
344
+ };
345
+ }
346
+ /**
347
+ * Cancel the promise if still pending
348
+ */
349
+ async cancel() {
350
+ if (this.state.status !== 'pending') {
351
+ throw new Error('Cannot cancel a resolved or rejected promise');
352
+ }
353
+ if (this.provider) {
354
+ await this.provider.cancelAction(this.actionId);
355
+ }
356
+ this.reject(new Error('Promise cancelled'));
357
+ }
358
+ /**
359
+ * Retry a failed promise
360
+ */
361
+ async retry() {
362
+ if (this.state.status !== 'rejected') {
363
+ throw new Error('Can only retry failed promises');
364
+ }
365
+ if (this.provider) {
366
+ await this.provider.retryAction(this.actionId);
367
+ }
368
+ // Re-execute
369
+ this.state.status = 'pending';
370
+ await this.execute();
371
+ return this;
372
+ }
373
+ }
374
+ /**
375
+ * Check if a value is a DurablePromise
376
+ */
377
+ export function isDurablePromise(value) {
378
+ return (typeof value === 'object' &&
379
+ value !== null &&
380
+ DURABLE_PROMISE_SYMBOL in value &&
381
+ value[DURABLE_PROMISE_SYMBOL] === true);
382
+ }
383
+ /**
384
+ * Create a durable promise from an executor function
385
+ */
386
+ export function durable(method, executor, options) {
387
+ return new DurablePromise({
388
+ method,
389
+ executor,
390
+ ...options,
391
+ });
392
+ }
393
+ // =============================================================================
394
+ // Batch Scheduler Singleton
395
+ // =============================================================================
396
+ let batchScheduler = null;
397
+ /**
398
+ * Get the global batch scheduler
399
+ */
400
+ export function getBatchScheduler() {
401
+ return batchScheduler;
402
+ }
403
+ /**
404
+ * Set the global batch scheduler
405
+ */
406
+ export function setBatchScheduler(scheduler) {
407
+ batchScheduler = scheduler;
408
+ }
409
+ //# sourceMappingURL=durable-promise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-promise.js","sourceRoot":"","sources":["../src/durable-promise.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA2FH,MAAM,YAAY,GAAuB,EAAE,CAAA;AAE3C;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAkC,EAClC,EAAoB;IAEpB,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAA;IAClC,MAAM,MAAM,GAAqB;QAC/B,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,MAAM,EAAE,QAAQ,IAAI,UAAU;QAC5D,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,MAAM,EAAE,QAAQ;QAC9C,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,MAAM,EAAE,cAAc;QAChE,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,MAAM,EAAE,KAAK;QACrC,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,MAAM,EAAE,WAAW;QACvD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,MAAM,EAAE,OAAO;KAC5C,CAAA;IAED,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACzB,IAAI,CAAC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