@soda-gql/common 0.0.9 → 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.
- package/README.md +121 -0
- package/dist/canonical-id-BFcryTw5.cjs +2 -1
- package/dist/canonical-id-BFcryTw5.cjs.map +1 -0
- package/dist/{canonical-id/index.cjs → canonical-id.cjs} +2 -2
- package/dist/{canonical-id/index.d.cts → canonical-id.d.cts} +1 -1
- package/dist/{canonical-id/index.d.mts → canonical-id.d.mts} +1 -1
- package/dist/{canonical-id/index.mjs → canonical-id.mjs} +2 -2
- package/dist/index-DaAp2rNj.d.cts.map +1 -1
- package/dist/index.cjs +265 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +216 -1
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +216 -1
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +256 -1
- package/dist/index.mjs.map +1 -0
- package/dist/portable-C_7gJWmz.cjs +2 -1
- package/dist/portable-C_7gJWmz.cjs.map +1 -0
- package/dist/portable-Dbo3u2CQ.mjs.map +1 -1
- package/dist/{portable/index.cjs → portable.cjs} +1 -1
- package/dist/{portable/index.d.cts → portable.d.cts} +1 -1
- package/dist/{portable/index.d.mts → portable.d.mts} +1 -1
- package/dist/{portable/index.mjs → portable.mjs} +1 -1
- package/dist/utils-CmLf7LU5.cjs +2 -1
- package/dist/utils-CmLf7LU5.cjs.map +1 -0
- package/dist/{utils/index.cjs → utils.cjs} +1 -1
- package/dist/{utils/index.d.cts → utils.d.cts} +1 -1
- package/dist/{utils/index.d.mts → utils.d.mts} +1 -1
- package/dist/{utils/index.mjs → utils.mjs} +1 -1
- package/dist/zod-CynYgOoN.cjs +2 -1
- package/dist/zod-CynYgOoN.cjs.map +1 -0
- package/dist/zod.cjs +3 -0
- package/dist/zod.d.cts +2 -0
- package/dist/zod.d.mts +2 -0
- package/dist/zod.mjs +3 -0
- package/package.json +49 -26
- package/dist/zod/index.cjs +0 -3
- package/dist/zod/index.d.cts +0 -2
- package/dist/zod/index.d.mts +0 -2
- package/dist/zod/index.mjs +0 -3
package/dist/index.d.cts
CHANGED
|
@@ -2,4 +2,219 @@ import { a as createCanonicalTracker, c as CanonicalId, i as buildAstPath, l as
|
|
|
2
2
|
import { a as resetPortableForTests, c as HashAlgorithm, d as createPortableHasher, f as getPortableHasher, g as getPortableFS, h as createPortableFS, i as once, l as PortableHasher, m as __resetPortableFSForTests, n as SpawnResult, o as runtime, p as PortableFS, r as spawn, s as generateId, t as SpawnOptions, u as __resetPortableHasherForTests } from "./index-DaAp2rNj.cjs";
|
|
3
3
|
import { a as resolveRelativeImportWithExistenceCheck, i as normalizePath, n as isExternalSpecifier, o as resolveRelativeImportWithReferences, r as isRelativeSpecifier, s as cachedFn, t as MODULE_EXTENSION_CANDIDATES } from "./index-LaXfl_e_.cjs";
|
|
4
4
|
import { n as ShapeFor, r as defineSchemaFor, t as SchemaFor } from "./index-LHYortIn.cjs";
|
|
5
|
-
|
|
5
|
+
import { Result } from "neverthrow";
|
|
6
|
+
|
|
7
|
+
//#region packages/common/src/scheduler/types.d.ts
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base class for all effects.
|
|
11
|
+
* Effects encapsulate both the data and the execution logic.
|
|
12
|
+
*
|
|
13
|
+
* @template TResult - The type of value this effect produces when executed
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* function* myGenerator() {
|
|
18
|
+
* const value = yield* new PureEffect(42).run();
|
|
19
|
+
* return value; // 42
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare abstract class Effect<TResult = unknown> {
|
|
24
|
+
/**
|
|
25
|
+
* Execute the effect synchronously and return the result.
|
|
26
|
+
*/
|
|
27
|
+
executeSync(): TResult;
|
|
28
|
+
/**
|
|
29
|
+
* Execute the effect asynchronously and return the result.
|
|
30
|
+
*/
|
|
31
|
+
executeAsync(): Promise<TResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Returns a generator that yields this effect and returns the result.
|
|
34
|
+
* Enables the `yield*` pattern for cleaner effect handling.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const value = yield* effect.run();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
run(): Generator<Effect<TResult>, TResult, EffectReturn>;
|
|
42
|
+
/**
|
|
43
|
+
* Internal synchronous execution logic.
|
|
44
|
+
* Subclasses must implement this method.
|
|
45
|
+
*/
|
|
46
|
+
protected abstract _executeSync(): TResult;
|
|
47
|
+
/**
|
|
48
|
+
* Internal asynchronous execution logic.
|
|
49
|
+
* Subclasses must implement this method.
|
|
50
|
+
*/
|
|
51
|
+
protected abstract _executeAsync(): Promise<TResult>;
|
|
52
|
+
}
|
|
53
|
+
declare const EFFECT_RETURN: unique symbol;
|
|
54
|
+
declare class EffectReturn<TResult = unknown> {
|
|
55
|
+
private readonly [EFFECT_RETURN];
|
|
56
|
+
private constructor();
|
|
57
|
+
static wrap<TResult>(value: TResult): EffectReturn<TResult>;
|
|
58
|
+
static unwrap<TResult>(value: EffectReturn<TResult>): TResult;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Extract the result type from an Effect.
|
|
62
|
+
*/
|
|
63
|
+
type EffectResult<E> = E extends Effect<infer T> ? T : never;
|
|
64
|
+
/**
|
|
65
|
+
* Generator type that yields Effects.
|
|
66
|
+
*/
|
|
67
|
+
type EffectGenerator<TReturn> = Generator<Effect, TReturn, EffectReturn>;
|
|
68
|
+
/**
|
|
69
|
+
* Generator function type that creates an EffectGenerator.
|
|
70
|
+
*/
|
|
71
|
+
type EffectGeneratorFn<TReturn> = () => EffectGenerator<TReturn>;
|
|
72
|
+
/**
|
|
73
|
+
* Error type for scheduler operations.
|
|
74
|
+
*/
|
|
75
|
+
type SchedulerError = {
|
|
76
|
+
readonly kind: "scheduler-error";
|
|
77
|
+
readonly message: string;
|
|
78
|
+
readonly cause?: unknown;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Create a SchedulerError.
|
|
82
|
+
*/
|
|
83
|
+
declare const createSchedulerError: (message: string, cause?: unknown) => SchedulerError;
|
|
84
|
+
/**
|
|
85
|
+
* Synchronous scheduler interface.
|
|
86
|
+
* Throws if an async-only effect (defer, yield) is encountered.
|
|
87
|
+
*/
|
|
88
|
+
interface SyncScheduler {
|
|
89
|
+
run<TReturn>(generatorFn: EffectGeneratorFn<TReturn>): Result<TReturn, SchedulerError>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Asynchronous scheduler interface.
|
|
93
|
+
* Handles all effect types including defer, yield, and parallel.
|
|
94
|
+
*/
|
|
95
|
+
interface AsyncScheduler {
|
|
96
|
+
run<TReturn>(generatorFn: EffectGeneratorFn<TReturn>): Promise<Result<TReturn, SchedulerError>>;
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region packages/common/src/scheduler/async-scheduler.d.ts
|
|
100
|
+
/**
|
|
101
|
+
* Create an asynchronous scheduler.
|
|
102
|
+
*
|
|
103
|
+
* This scheduler can handle all effect types including defer and yield.
|
|
104
|
+
* Parallel effects are executed concurrently using Promise.all.
|
|
105
|
+
*
|
|
106
|
+
* @returns An AsyncScheduler instance
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* const scheduler = createAsyncScheduler();
|
|
110
|
+
* const result = await scheduler.run(function* () {
|
|
111
|
+
* const data = yield* new DeferEffect(fetch('/api/data').then(r => r.json())).run();
|
|
112
|
+
* yield* new YieldEffect().run(); // Yield to event loop
|
|
113
|
+
* return data;
|
|
114
|
+
* });
|
|
115
|
+
*/
|
|
116
|
+
declare const createAsyncScheduler: () => AsyncScheduler;
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region packages/common/src/scheduler/effect.d.ts
|
|
119
|
+
/**
|
|
120
|
+
* Pure effect - returns a value immediately.
|
|
121
|
+
* Works in both sync and async schedulers.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const result = yield* new PureEffect(42).run(); // 42
|
|
125
|
+
*/
|
|
126
|
+
declare class PureEffect<T> extends Effect<T> {
|
|
127
|
+
readonly pureValue: T;
|
|
128
|
+
constructor(pureValue: T);
|
|
129
|
+
protected _executeSync(): T;
|
|
130
|
+
protected _executeAsync(): Promise<T>;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Defer effect - wraps a Promise for async execution.
|
|
134
|
+
* Only works in async schedulers; throws in sync schedulers.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* const data = yield* new DeferEffect(fetch('/api/data').then(r => r.json())).run();
|
|
138
|
+
*/
|
|
139
|
+
declare class DeferEffect<T> extends Effect<T> {
|
|
140
|
+
readonly promise: Promise<T>;
|
|
141
|
+
constructor(promise: Promise<T>);
|
|
142
|
+
protected _executeSync(): T;
|
|
143
|
+
protected _executeAsync(): Promise<T>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Parallel effect - executes multiple effects concurrently.
|
|
147
|
+
* In sync schedulers, effects are executed sequentially.
|
|
148
|
+
* In async schedulers, effects are executed with Promise.all.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* const results = yield* new ParallelEffect([new PureEffect(1), new PureEffect(2)]).run(); // [1, 2]
|
|
152
|
+
*/
|
|
153
|
+
declare class ParallelEffect extends Effect<readonly unknown[]> {
|
|
154
|
+
readonly effects: readonly Effect<unknown>[];
|
|
155
|
+
constructor(effects: readonly Effect<unknown>[]);
|
|
156
|
+
protected _executeSync(): readonly unknown[];
|
|
157
|
+
protected _executeAsync(): Promise<readonly unknown[]>;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Yield effect - yields control back to the event loop.
|
|
161
|
+
* This helps prevent blocking the event loop in long-running operations.
|
|
162
|
+
* Only works in async schedulers; throws in sync schedulers.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* for (let i = 0; i < 10000; i++) {
|
|
166
|
+
* doWork(i);
|
|
167
|
+
* if (i % 100 === 0) {
|
|
168
|
+
* yield* new YieldEffect().run();
|
|
169
|
+
* }
|
|
170
|
+
* }
|
|
171
|
+
*/
|
|
172
|
+
declare class YieldEffect extends Effect<void> {
|
|
173
|
+
protected _executeSync(): void;
|
|
174
|
+
protected _executeAsync(): Promise<void>;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Effect factory namespace for convenience.
|
|
178
|
+
* Provides static methods to create effects.
|
|
179
|
+
*/
|
|
180
|
+
declare const Effects: {
|
|
181
|
+
/**
|
|
182
|
+
* Create a pure effect that returns a value immediately.
|
|
183
|
+
*/
|
|
184
|
+
readonly pure: <T>(value: T) => PureEffect<T>;
|
|
185
|
+
/**
|
|
186
|
+
* Create a defer effect that wraps a Promise.
|
|
187
|
+
*/
|
|
188
|
+
readonly defer: <T>(promise: Promise<T>) => DeferEffect<T>;
|
|
189
|
+
/**
|
|
190
|
+
* Create a parallel effect that executes multiple effects concurrently.
|
|
191
|
+
*/
|
|
192
|
+
readonly parallel: (effects: readonly Effect<unknown>[]) => ParallelEffect;
|
|
193
|
+
/**
|
|
194
|
+
* Create a yield effect that returns control to the event loop.
|
|
195
|
+
*/
|
|
196
|
+
readonly yield: () => YieldEffect;
|
|
197
|
+
};
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region packages/common/src/scheduler/sync-scheduler.d.ts
|
|
200
|
+
/**
|
|
201
|
+
* Create a synchronous scheduler.
|
|
202
|
+
*
|
|
203
|
+
* This scheduler executes generators synchronously.
|
|
204
|
+
* It throws an error if an async-only effect (defer, yield) is encountered.
|
|
205
|
+
*
|
|
206
|
+
* @returns A SyncScheduler instance
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* const scheduler = createSyncScheduler();
|
|
210
|
+
* const result = scheduler.run(function* () {
|
|
211
|
+
* const a = yield* new PureEffect(1).run();
|
|
212
|
+
* const b = yield* new PureEffect(2).run();
|
|
213
|
+
* return a + b;
|
|
214
|
+
* });
|
|
215
|
+
* // result = ok(3)
|
|
216
|
+
*/
|
|
217
|
+
declare const createSyncScheduler: () => SyncScheduler;
|
|
218
|
+
//#endregion
|
|
219
|
+
export { type AsyncScheduler, CanonicalId, CanonicalIdSchema, CanonicalPathTracker, DeferEffect, Effect, type EffectGenerator, type EffectGeneratorFn, type EffectResult, Effects, HashAlgorithm, MODULE_EXTENSION_CANDIDATES, ParallelEffect, PortableFS, PortableHasher, PureEffect, type SchedulerError, SchemaFor, ScopeFrame, ScopeHandle, ShapeFor, SpawnOptions, SpawnResult, type SyncScheduler, YieldEffect, __resetPortableFSForTests, __resetPortableHasherForTests, buildAstPath, cachedFn, createAsyncScheduler, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker, createPortableFS, createPortableHasher, createSchedulerError, createSyncScheduler, defineSchemaFor, generateId, getPortableFS, getPortableHasher, isExternalSpecifier, isRelativeSpecifier, normalizePath, once, resetPortableForTests, resolveRelativeImportWithExistenceCheck, resolveRelativeImportWithReferences, runtime, spawn };
|
|
220
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/scheduler/types.ts","../src/scheduler/async-scheduler.ts","../src/scheduler/effect.ts","../src/scheduler/sync-scheduler.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;AAgBA;;;;;;;;AAwBU,uBAxBY,MAwBZ,CAAA,UAAA,OAAA,CAAA,CAAA;EAQ2B;;;EAMQ,WAAA,CAAA,CAAA,EAlC5B,OAkC4B;EAGvC;AACN;;EAO8B,YAAA,CAAA,CAAA,EAtCN,OAsCM,CAtCE,OAsCF,CAAA;EAAuB;;;;;;AAYrD;AAKA;;EAAyD,GAAA,CAAA,CAAA,EA1C/C,SA0C+C,CA1CrC,MA0CqC,CA1C9B,OA0C8B,CAAA,EA1CpB,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,CAAA;;6BEpC7B;;ADhEnC;;;;ACXa,cA0FA,OA1FU,EAAA;EAAmB;;;EAKd,SAAA,IAAA,EAAA,CAAA,CAAA,CAAA,CAAA,KAAA,EAyFT,CAzFS,EAAA,GAyFL,UAzFK,CAyFM,CAzFN,CAAA;EAIS;;;EATI,SAAA,KAAA,EAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EAmGnB,OAnGmB,CAmGX,CAnGW,CAAA,EAAA,GAmGN,WAnGM,CAmGM,CAnGN,CAAA;EAqB5B;;;EACmB,SAAA,QAAA,EAAA,CAAA,OAAA,EAAA,SAkFD,MAlFC,CAAA,OAAA,CAAA,EAAA,EAAA,GAkFmB,cAlFnB;EAAQ;;;EAQH,SAAA,KAAA,EAAA,GAAA,GA+ExB,WA/EwB;CAAR;;;;;;;;;AFvB7B;;;;;;;;;;;AAsCsC,cGjCzB,mBHiCyB,EAAA,GAAA,GGjCC,aHiCD"}
|
package/dist/index.d.mts
CHANGED
|
@@ -2,4 +2,219 @@ import { a as createCanonicalTracker, c as CanonicalId, i as buildAstPath, l as
|
|
|
2
2
|
import { a as resetPortableForTests, c as HashAlgorithm, d as createPortableHasher, f as getPortableHasher, g as getPortableFS, h as createPortableFS, i as once, l as PortableHasher, m as __resetPortableFSForTests, n as SpawnResult, o as runtime, p as PortableFS, r as spawn, s as generateId, t as SpawnOptions, u as __resetPortableHasherForTests } from "./index-BedBpKbv.mjs";
|
|
3
3
|
import { a as resolveRelativeImportWithExistenceCheck, i as normalizePath, n as isExternalSpecifier, o as resolveRelativeImportWithReferences, r as isRelativeSpecifier, s as cachedFn, t as MODULE_EXTENSION_CANDIDATES } from "./index-Dv8spPt0.mjs";
|
|
4
4
|
import { n as ShapeFor, r as defineSchemaFor, t as SchemaFor } from "./index-Dit86qkX.mjs";
|
|
5
|
-
|
|
5
|
+
import { Result } from "neverthrow";
|
|
6
|
+
|
|
7
|
+
//#region packages/common/src/scheduler/types.d.ts
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base class for all effects.
|
|
11
|
+
* Effects encapsulate both the data and the execution logic.
|
|
12
|
+
*
|
|
13
|
+
* @template TResult - The type of value this effect produces when executed
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* function* myGenerator() {
|
|
18
|
+
* const value = yield* new PureEffect(42).run();
|
|
19
|
+
* return value; // 42
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare abstract class Effect<TResult = unknown> {
|
|
24
|
+
/**
|
|
25
|
+
* Execute the effect synchronously and return the result.
|
|
26
|
+
*/
|
|
27
|
+
executeSync(): TResult;
|
|
28
|
+
/**
|
|
29
|
+
* Execute the effect asynchronously and return the result.
|
|
30
|
+
*/
|
|
31
|
+
executeAsync(): Promise<TResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Returns a generator that yields this effect and returns the result.
|
|
34
|
+
* Enables the `yield*` pattern for cleaner effect handling.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const value = yield* effect.run();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
run(): Generator<Effect<TResult>, TResult, EffectReturn>;
|
|
42
|
+
/**
|
|
43
|
+
* Internal synchronous execution logic.
|
|
44
|
+
* Subclasses must implement this method.
|
|
45
|
+
*/
|
|
46
|
+
protected abstract _executeSync(): TResult;
|
|
47
|
+
/**
|
|
48
|
+
* Internal asynchronous execution logic.
|
|
49
|
+
* Subclasses must implement this method.
|
|
50
|
+
*/
|
|
51
|
+
protected abstract _executeAsync(): Promise<TResult>;
|
|
52
|
+
}
|
|
53
|
+
declare const EFFECT_RETURN: unique symbol;
|
|
54
|
+
declare class EffectReturn<TResult = unknown> {
|
|
55
|
+
private readonly [EFFECT_RETURN];
|
|
56
|
+
private constructor();
|
|
57
|
+
static wrap<TResult>(value: TResult): EffectReturn<TResult>;
|
|
58
|
+
static unwrap<TResult>(value: EffectReturn<TResult>): TResult;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Extract the result type from an Effect.
|
|
62
|
+
*/
|
|
63
|
+
type EffectResult<E> = E extends Effect<infer T> ? T : never;
|
|
64
|
+
/**
|
|
65
|
+
* Generator type that yields Effects.
|
|
66
|
+
*/
|
|
67
|
+
type EffectGenerator<TReturn> = Generator<Effect, TReturn, EffectReturn>;
|
|
68
|
+
/**
|
|
69
|
+
* Generator function type that creates an EffectGenerator.
|
|
70
|
+
*/
|
|
71
|
+
type EffectGeneratorFn<TReturn> = () => EffectGenerator<TReturn>;
|
|
72
|
+
/**
|
|
73
|
+
* Error type for scheduler operations.
|
|
74
|
+
*/
|
|
75
|
+
type SchedulerError = {
|
|
76
|
+
readonly kind: "scheduler-error";
|
|
77
|
+
readonly message: string;
|
|
78
|
+
readonly cause?: unknown;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Create a SchedulerError.
|
|
82
|
+
*/
|
|
83
|
+
declare const createSchedulerError: (message: string, cause?: unknown) => SchedulerError;
|
|
84
|
+
/**
|
|
85
|
+
* Synchronous scheduler interface.
|
|
86
|
+
* Throws if an async-only effect (defer, yield) is encountered.
|
|
87
|
+
*/
|
|
88
|
+
interface SyncScheduler {
|
|
89
|
+
run<TReturn>(generatorFn: EffectGeneratorFn<TReturn>): Result<TReturn, SchedulerError>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Asynchronous scheduler interface.
|
|
93
|
+
* Handles all effect types including defer, yield, and parallel.
|
|
94
|
+
*/
|
|
95
|
+
interface AsyncScheduler {
|
|
96
|
+
run<TReturn>(generatorFn: EffectGeneratorFn<TReturn>): Promise<Result<TReturn, SchedulerError>>;
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region packages/common/src/scheduler/async-scheduler.d.ts
|
|
100
|
+
/**
|
|
101
|
+
* Create an asynchronous scheduler.
|
|
102
|
+
*
|
|
103
|
+
* This scheduler can handle all effect types including defer and yield.
|
|
104
|
+
* Parallel effects are executed concurrently using Promise.all.
|
|
105
|
+
*
|
|
106
|
+
* @returns An AsyncScheduler instance
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* const scheduler = createAsyncScheduler();
|
|
110
|
+
* const result = await scheduler.run(function* () {
|
|
111
|
+
* const data = yield* new DeferEffect(fetch('/api/data').then(r => r.json())).run();
|
|
112
|
+
* yield* new YieldEffect().run(); // Yield to event loop
|
|
113
|
+
* return data;
|
|
114
|
+
* });
|
|
115
|
+
*/
|
|
116
|
+
declare const createAsyncScheduler: () => AsyncScheduler;
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region packages/common/src/scheduler/effect.d.ts
|
|
119
|
+
/**
|
|
120
|
+
* Pure effect - returns a value immediately.
|
|
121
|
+
* Works in both sync and async schedulers.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const result = yield* new PureEffect(42).run(); // 42
|
|
125
|
+
*/
|
|
126
|
+
declare class PureEffect<T> extends Effect<T> {
|
|
127
|
+
readonly pureValue: T;
|
|
128
|
+
constructor(pureValue: T);
|
|
129
|
+
protected _executeSync(): T;
|
|
130
|
+
protected _executeAsync(): Promise<T>;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Defer effect - wraps a Promise for async execution.
|
|
134
|
+
* Only works in async schedulers; throws in sync schedulers.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* const data = yield* new DeferEffect(fetch('/api/data').then(r => r.json())).run();
|
|
138
|
+
*/
|
|
139
|
+
declare class DeferEffect<T> extends Effect<T> {
|
|
140
|
+
readonly promise: Promise<T>;
|
|
141
|
+
constructor(promise: Promise<T>);
|
|
142
|
+
protected _executeSync(): T;
|
|
143
|
+
protected _executeAsync(): Promise<T>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Parallel effect - executes multiple effects concurrently.
|
|
147
|
+
* In sync schedulers, effects are executed sequentially.
|
|
148
|
+
* In async schedulers, effects are executed with Promise.all.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* const results = yield* new ParallelEffect([new PureEffect(1), new PureEffect(2)]).run(); // [1, 2]
|
|
152
|
+
*/
|
|
153
|
+
declare class ParallelEffect extends Effect<readonly unknown[]> {
|
|
154
|
+
readonly effects: readonly Effect<unknown>[];
|
|
155
|
+
constructor(effects: readonly Effect<unknown>[]);
|
|
156
|
+
protected _executeSync(): readonly unknown[];
|
|
157
|
+
protected _executeAsync(): Promise<readonly unknown[]>;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Yield effect - yields control back to the event loop.
|
|
161
|
+
* This helps prevent blocking the event loop in long-running operations.
|
|
162
|
+
* Only works in async schedulers; throws in sync schedulers.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* for (let i = 0; i < 10000; i++) {
|
|
166
|
+
* doWork(i);
|
|
167
|
+
* if (i % 100 === 0) {
|
|
168
|
+
* yield* new YieldEffect().run();
|
|
169
|
+
* }
|
|
170
|
+
* }
|
|
171
|
+
*/
|
|
172
|
+
declare class YieldEffect extends Effect<void> {
|
|
173
|
+
protected _executeSync(): void;
|
|
174
|
+
protected _executeAsync(): Promise<void>;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Effect factory namespace for convenience.
|
|
178
|
+
* Provides static methods to create effects.
|
|
179
|
+
*/
|
|
180
|
+
declare const Effects: {
|
|
181
|
+
/**
|
|
182
|
+
* Create a pure effect that returns a value immediately.
|
|
183
|
+
*/
|
|
184
|
+
readonly pure: <T>(value: T) => PureEffect<T>;
|
|
185
|
+
/**
|
|
186
|
+
* Create a defer effect that wraps a Promise.
|
|
187
|
+
*/
|
|
188
|
+
readonly defer: <T>(promise: Promise<T>) => DeferEffect<T>;
|
|
189
|
+
/**
|
|
190
|
+
* Create a parallel effect that executes multiple effects concurrently.
|
|
191
|
+
*/
|
|
192
|
+
readonly parallel: (effects: readonly Effect<unknown>[]) => ParallelEffect;
|
|
193
|
+
/**
|
|
194
|
+
* Create a yield effect that returns control to the event loop.
|
|
195
|
+
*/
|
|
196
|
+
readonly yield: () => YieldEffect;
|
|
197
|
+
};
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region packages/common/src/scheduler/sync-scheduler.d.ts
|
|
200
|
+
/**
|
|
201
|
+
* Create a synchronous scheduler.
|
|
202
|
+
*
|
|
203
|
+
* This scheduler executes generators synchronously.
|
|
204
|
+
* It throws an error if an async-only effect (defer, yield) is encountered.
|
|
205
|
+
*
|
|
206
|
+
* @returns A SyncScheduler instance
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* const scheduler = createSyncScheduler();
|
|
210
|
+
* const result = scheduler.run(function* () {
|
|
211
|
+
* const a = yield* new PureEffect(1).run();
|
|
212
|
+
* const b = yield* new PureEffect(2).run();
|
|
213
|
+
* return a + b;
|
|
214
|
+
* });
|
|
215
|
+
* // result = ok(3)
|
|
216
|
+
*/
|
|
217
|
+
declare const createSyncScheduler: () => SyncScheduler;
|
|
218
|
+
//#endregion
|
|
219
|
+
export { type AsyncScheduler, CanonicalId, CanonicalIdSchema, CanonicalPathTracker, DeferEffect, Effect, type EffectGenerator, type EffectGeneratorFn, type EffectResult, Effects, HashAlgorithm, MODULE_EXTENSION_CANDIDATES, ParallelEffect, PortableFS, PortableHasher, PureEffect, type SchedulerError, SchemaFor, ScopeFrame, ScopeHandle, ShapeFor, SpawnOptions, SpawnResult, type SyncScheduler, YieldEffect, __resetPortableFSForTests, __resetPortableHasherForTests, buildAstPath, cachedFn, createAsyncScheduler, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker, createPortableFS, createPortableHasher, createSchedulerError, createSyncScheduler, defineSchemaFor, generateId, getPortableFS, getPortableHasher, isExternalSpecifier, isRelativeSpecifier, normalizePath, once, resetPortableForTests, resolveRelativeImportWithExistenceCheck, resolveRelativeImportWithReferences, runtime, spawn };
|
|
220
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/scheduler/types.ts","../src/scheduler/async-scheduler.ts","../src/scheduler/effect.ts","../src/scheduler/sync-scheduler.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;AAgBA;;;;;;;;AAwBU,uBAxBY,MAwBZ,CAAA,UAAA,OAAA,CAAA,CAAA;EAQ2B;;;EAMQ,WAAA,CAAA,CAAA,EAlC5B,OAkC4B;EAGvC;AACN;;EAO8B,YAAA,CAAA,CAAA,EAtCN,OAsCM,CAtCE,OAsCF,CAAA;EAAuB;;;;;;AAYrD;AAKA;;EAAyD,GAAA,CAAA,CAAA,EA1C/C,SA0C+C,CA1CrC,MA0CqC,CA1C9B,OA0C8B,CAAA,EA1CpB,OA0CoB,EA1CX,YA0CW,CAAA;EAAS;;;AAKlE;EAKY,mBAAc,YAAA,CAAA,CAAA,EA5CW,OA4CX;EASb;AAUb;;;EACgE,mBAAA,aAAA,CAAA,CAAA,EA1D1B,OA0D0B,CA1DlB,OA0DkB,CAAA;;cAvD1D,aAuDmD,EAAA,OAAA,MAAA;AAAM,cAtDlD,YAsDkD,CAAA,UAAA,OAAA,CAAA,CAAA;EAO9C,kBA5DG,aAAA;EA6D0B,QAAA,WAAA,CAAA;EAAlB,OAAA,IAAA,CAAA,OAAA,CAAA,CAAA,KAAA,EAvDE,OAuDF,CAAA,EAvDY,YAuDZ,CAvDyB,OAuDzB,CAAA;EAA4C,OAAA,MAAA,CAAA,OAAA,CAAA,CAAA,KAAA,EAnDxC,YAmDwC,CAnD3B,OAmD2B,CAAA,CAAA,EAnDhB,OAmDgB;;;;;KA3C5D,kBAAkB,UAAU;;;ACzDxC;KD8DY,2BAA2B,UAAU,QAAQ,SAAS;;;AEzElE;AAA0C,KF8E9B,iBE9E8B,CAAA,OAAA,CAAA,GAAA,GAAA,GF8EK,eE9EL,CF8EqB,OE9ErB,CAAA;;;;AASL,KF0EzB,cAAA,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