@actuallab/fusion 13.0.25 → 13.0.167
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/dist/index.cjs +379 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -28
- package/dist/index.d.ts +74 -28
- package/dist/index.js +370 -178
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import * as _actuallab_core from '@actuallab/core';
|
|
2
|
-
import { IResult,
|
|
2
|
+
import { IResult, Result, AsyncContext, AsyncContextKey, RetryDelaySeq, EventHandlerSet } from '@actuallab/core';
|
|
3
3
|
|
|
4
4
|
type FusionLogScope = 'Computed' | 'ComputedRegistry' | 'ComputedState' | 'ComputeFunction' | 'MutableState' | 'State' | 'UIActionTracker' | 'UIUpdateDelayer';
|
|
5
5
|
declare const getLogs: (scope: FusionLogScope) => _actuallab_core.LogScopeFns;
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Per-Computed configuration, carried by every {@link Computed} via its
|
|
9
|
+
* {@link ComputeFunction} (compute methods) or its kind's static default.
|
|
10
|
+
* The home for per-method knobs; the C# analog is `ActualLab.Fusion.ComputedOptions`.
|
|
11
|
+
*/
|
|
12
|
+
declare class ComputedOptions {
|
|
13
|
+
static default: ComputedOptions;
|
|
14
|
+
static mutableStateDefault: ComputedOptions;
|
|
15
|
+
readonly errorAutoInvalidateDelay: number;
|
|
16
|
+
constructor(overrides?: Partial<ComputedOptions>);
|
|
17
|
+
}
|
|
18
|
+
|
|
7
19
|
declare const enum ConsistencyState {
|
|
8
20
|
Computing = 0,
|
|
9
21
|
Consistent = 1,
|
|
@@ -11,20 +23,20 @@ declare const enum ConsistencyState {
|
|
|
11
23
|
}
|
|
12
24
|
/** Core Fusion abstraction — a cached computation with dependency tracking and invalidation. */
|
|
13
25
|
declare class Computed<T> implements IResult<T> {
|
|
14
|
-
/** Delay before auto-invalidating a Computed that holds an error result. 0 = disabled. */
|
|
15
|
-
static errorAutoInvalidateDelay: number;
|
|
16
26
|
/** Capture the Computed backing a computation — works with both local and RPC compute methods. */
|
|
17
27
|
static capture<T>(fn: () => T | Promise<T>): Promise<Computed<T>>;
|
|
18
28
|
readonly input: ComputedInput;
|
|
29
|
+
readonly options: ComputedOptions;
|
|
19
30
|
private _version;
|
|
20
31
|
private _state;
|
|
21
32
|
private _output;
|
|
22
33
|
private _invalidatePending;
|
|
34
|
+
private _errorTimer;
|
|
23
35
|
private _dependencies;
|
|
24
36
|
private _dependants;
|
|
25
|
-
|
|
37
|
+
private _onInvalidated;
|
|
26
38
|
readonly _renewer: (() => Computed<T> | Promise<Computed<T>>) | undefined;
|
|
27
|
-
constructor(input: ComputedInput, renewer?: () => Computed<T> | Promise<Computed<T
|
|
39
|
+
constructor(input: ComputedInput, renewer?: () => Computed<T> | Promise<Computed<T>>, options?: ComputedOptions);
|
|
28
40
|
get version(): number;
|
|
29
41
|
get output(): Result<T>;
|
|
30
42
|
get hasValue(): boolean;
|
|
@@ -34,6 +46,7 @@ declare class Computed<T> implements IResult<T> {
|
|
|
34
46
|
get valueOrUndefined(): T | undefined;
|
|
35
47
|
get state(): ConsistencyState;
|
|
36
48
|
get isConsistent(): boolean;
|
|
49
|
+
get isComputing(): boolean;
|
|
37
50
|
get dependencies(): ReadonlySet<Computed<unknown>>;
|
|
38
51
|
update(): Computed<T> | Promise<Computed<T>>;
|
|
39
52
|
protected _latest(): Computed<T> | undefined;
|
|
@@ -43,11 +56,13 @@ declare class Computed<T> implements IResult<T> {
|
|
|
43
56
|
protected _register(): void;
|
|
44
57
|
protected _unregister(): void;
|
|
45
58
|
invalidate(): void;
|
|
59
|
+
onInvalidated(handler: () => void): void;
|
|
46
60
|
whenInvalidated(abortSignal?: AbortSignal): Promise<void>;
|
|
47
61
|
addDependency(dependency: Computed<unknown>): void;
|
|
48
62
|
}
|
|
49
63
|
/** Computed variant for State types — skips registry registration since the State holds a direct reference. */
|
|
50
64
|
declare class StateBoundComputed<T> extends Computed<T> {
|
|
65
|
+
constructor(input: ComputedInput, renewer?: () => Computed<T> | Promise<Computed<T>>, options?: ComputedOptions);
|
|
51
66
|
protected _latest(): Computed<T> | undefined;
|
|
52
67
|
protected _register(): void;
|
|
53
68
|
protected _unregister(): void;
|
|
@@ -57,9 +72,11 @@ declare class StateBoundComputed<T> extends Computed<T> {
|
|
|
57
72
|
declare abstract class State<T> implements IResult<T> {
|
|
58
73
|
protected _computed: Computed<T>;
|
|
59
74
|
protected _updateIndex: number;
|
|
60
|
-
protected
|
|
75
|
+
protected _lastNonErrorComputed: Computed<T> | undefined;
|
|
61
76
|
private _whenUpdatedSource;
|
|
77
|
+
private _isDisposed;
|
|
62
78
|
get updateIndex(): number;
|
|
79
|
+
get isDisposed(): boolean;
|
|
63
80
|
get lastNonErrorValue(): T | undefined;
|
|
64
81
|
get hasValue(): boolean;
|
|
65
82
|
get hasError(): boolean;
|
|
@@ -73,10 +90,13 @@ declare abstract class State<T> implements IResult<T> {
|
|
|
73
90
|
update(): Computed<T> | Promise<Computed<T>>;
|
|
74
91
|
recompute(): Computed<T> | Promise<Computed<T>>;
|
|
75
92
|
whenInvalidated(): Promise<void>;
|
|
76
|
-
whenUpdated(): Promise<void>;
|
|
93
|
+
whenUpdated(sinceIndex?: number): Promise<void>;
|
|
77
94
|
whenFirstTimeUpdated(): Promise<void>;
|
|
78
95
|
protected _initialize(output: Result<T> | T, renewer?: () => Computed<T> | Promise<Computed<T>>): void;
|
|
96
|
+
protected _createComputed(renewer?: () => Computed<T> | Promise<Computed<T>>): Computed<T>;
|
|
79
97
|
protected _update(computed: Computed<T>, output: Result<T> | T): void;
|
|
98
|
+
protected _onDisposed(): void;
|
|
99
|
+
private static _disposedError;
|
|
80
100
|
}
|
|
81
101
|
|
|
82
102
|
declare function getInstanceId(instance: object): number;
|
|
@@ -88,14 +108,22 @@ declare function getInstanceId(instance: object): number;
|
|
|
88
108
|
type ComputedInput = string | State<any>;
|
|
89
109
|
|
|
90
110
|
declare const computeContextKey: AsyncContextKey<ComputeContext | undefined>;
|
|
91
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Tracks the currently executing (or captured) computation and captures dependencies.
|
|
113
|
+
* A context with a `computed` is a computing context (adds dependant edges); one without
|
|
114
|
+
* is a capture context (records the last captured Computed only — no edges).
|
|
115
|
+
*/
|
|
92
116
|
declare class ComputeContext {
|
|
93
|
-
readonly computed: Computed<unknown
|
|
117
|
+
readonly computed: Computed<unknown> | undefined;
|
|
118
|
+
readonly parent: ComputeContext | undefined;
|
|
94
119
|
private _isCapturing;
|
|
95
|
-
|
|
120
|
+
private _captured;
|
|
121
|
+
constructor(computed?: Computed<unknown>, parent?: ComputeContext);
|
|
96
122
|
get isCapturing(): boolean;
|
|
123
|
+
get captured(): Computed<unknown> | undefined;
|
|
97
124
|
stopCapturing(): void;
|
|
98
125
|
captureDependency(dependency: Computed<unknown>): void;
|
|
126
|
+
hasKeyInChain(key: unknown): boolean;
|
|
99
127
|
/** Resolve ComputeContext from an AsyncContext (or current). */
|
|
100
128
|
static from(ctx: AsyncContext | undefined): ComputeContext | undefined;
|
|
101
129
|
}
|
|
@@ -115,13 +143,14 @@ type ComputeFunctionImpl = (this: any, ...args: unknown[]) => unknown;
|
|
|
115
143
|
declare class ComputeFunction {
|
|
116
144
|
readonly methodName: string;
|
|
117
145
|
readonly id: string;
|
|
146
|
+
readonly options: ComputedOptions;
|
|
118
147
|
argToString: (arg: unknown) => string;
|
|
119
148
|
private _impl;
|
|
120
149
|
private _locks;
|
|
121
|
-
constructor(methodName: string, impl: ComputeFunctionImpl);
|
|
150
|
+
constructor(methodName: string, impl: ComputeFunctionImpl, options?: ComputedOptions);
|
|
122
151
|
/** Build a string key for the given instance and arguments. */
|
|
123
152
|
buildKey(instance: object, args: unknown[]): string;
|
|
124
|
-
invoke(instance: object, args: unknown[]
|
|
153
|
+
invoke(instance: object, args: unknown[]): Promise<Computed<unknown>>;
|
|
125
154
|
}
|
|
126
155
|
|
|
127
156
|
interface MethodMeta {
|
|
@@ -131,43 +160,67 @@ interface MethodMeta {
|
|
|
131
160
|
}
|
|
132
161
|
/** Read method metadata from a decorated class. */
|
|
133
162
|
declare function getMethodsMeta(cls: abstract new (...args: any[]) => any): Record<string, MethodMeta> | undefined;
|
|
134
|
-
|
|
163
|
+
interface ComputeMethodOptions extends Partial<ComputedOptions> {
|
|
164
|
+
argCount?: number;
|
|
165
|
+
}
|
|
166
|
+
type ComputeMethodDecorator<This, Args extends unknown[], Return> = (target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
|
|
167
|
+
/**
|
|
168
|
+
* Method decorator — routes a method through ComputeFunction for caching and dependency
|
|
169
|
+
* tracking. Usable bare (`@computeMethod`) or with options (`@computeMethod({ argCount })`).
|
|
170
|
+
*/
|
|
135
171
|
declare function computeMethod<This, Args extends unknown[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>): (this: This, ...args: Args) => Return;
|
|
172
|
+
declare function computeMethod<This, Args extends unknown[], Return>(options?: ComputeMethodOptions): ComputeMethodDecorator<This, Args, Return>;
|
|
136
173
|
/** Wrap a standalone function as a compute function with caching and .invalidate(). */
|
|
137
174
|
declare function wrapComputeMethod<Args extends unknown[], Return>(fn: (...args: Args) => Return): ((...args: Args) => Promise<Return>) & {
|
|
138
175
|
invalidate: (...args: Args) => void;
|
|
139
176
|
};
|
|
140
177
|
|
|
141
|
-
/** Controls when state re-computation happens after invalidation. */
|
|
142
|
-
type UpdateDelayer = (abortSignal?: AbortSignal) => Promise<void>;
|
|
143
|
-
/** Re-computes after a fixed delay
|
|
178
|
+
/** Controls when state re-computation happens after invalidation, per consecutive-error retryCount. */
|
|
179
|
+
type UpdateDelayer = (retryCount: number, abortSignal?: AbortSignal) => Promise<void>;
|
|
180
|
+
/** Re-computes after a fixed update delay, with RetryDelaySeq backoff for consecutive errors. */
|
|
144
181
|
declare class FixedDelayer {
|
|
145
182
|
static readonly zero: UpdateDelayer;
|
|
146
183
|
private static _cache;
|
|
147
184
|
static get(ms: number): UpdateDelayer;
|
|
148
185
|
readonly ms: number;
|
|
186
|
+
readonly retryDelays: RetryDelaySeq;
|
|
187
|
+
readonly minDelay: number;
|
|
149
188
|
readonly delay: UpdateDelayer;
|
|
150
|
-
constructor(ms: number);
|
|
189
|
+
constructor(ms: number, retryDelays?: RetryDelaySeq, minDelay?: number);
|
|
151
190
|
}
|
|
152
191
|
declare const defaultUpdateDelayer: UpdateDelayer;
|
|
153
192
|
|
|
154
|
-
/** Re-computes after a
|
|
193
|
+
/** Re-computes after a delay, but short-circuits while UIActionTracker enables instant updates. */
|
|
155
194
|
declare class UIUpdateDelayer {
|
|
156
195
|
private static _cache;
|
|
157
196
|
static get(ms: number): UpdateDelayer;
|
|
197
|
+
readonly ms: number;
|
|
198
|
+
readonly retryDelays: RetryDelaySeq;
|
|
199
|
+
readonly minDelay: number;
|
|
200
|
+
readonly delay: UpdateDelayer;
|
|
201
|
+
constructor(ms: number, retryDelays?: RetryDelaySeq, minDelay?: number);
|
|
202
|
+
private _delay;
|
|
158
203
|
}
|
|
159
204
|
|
|
160
205
|
/** Singleton tracking active UI commands — mirrors .NET's UIActionTracker. */
|
|
161
206
|
declare class UIActionTracker {
|
|
162
207
|
private _activeCount;
|
|
208
|
+
private _lastResultAt;
|
|
209
|
+
private _errorTimes;
|
|
163
210
|
readonly changed: EventHandlerSet<void>;
|
|
164
211
|
readonly errors: unknown[];
|
|
212
|
+
instantUpdatePeriod: number;
|
|
213
|
+
maxDuplicateRecency: number;
|
|
214
|
+
maxErrors: number;
|
|
165
215
|
get isActive(): boolean;
|
|
216
|
+
areInstantUpdatesEnabled(): boolean;
|
|
166
217
|
/** Run a command silently — errors are added to the error list but not thrown. */
|
|
167
218
|
run(fn: () => Promise<unknown>): Promise<void>;
|
|
168
219
|
/** Call a command and return the result — errors are added to the error list AND thrown. */
|
|
169
220
|
call<T>(fn: () => Promise<T>): Promise<T>;
|
|
170
221
|
dismissError(index: number): void;
|
|
222
|
+
private _onCompleted;
|
|
223
|
+
private _addError;
|
|
171
224
|
}
|
|
172
225
|
declare const uiActions: UIActionTracker;
|
|
173
226
|
|
|
@@ -185,26 +238,19 @@ declare class ComputedState<T> extends State<T> {
|
|
|
185
238
|
private _disposeController;
|
|
186
239
|
private _cancelDelaySource;
|
|
187
240
|
private _renewer;
|
|
188
|
-
private _hasOutput;
|
|
189
241
|
constructor(computer: StateComputer<T>, options?: ComputedStateOptions<T>);
|
|
190
|
-
get hasValue(): boolean;
|
|
191
|
-
get hasError(): boolean;
|
|
192
|
-
get value(): T;
|
|
193
|
-
get error(): unknown;
|
|
194
|
-
get valueOrUndefined(): T | undefined;
|
|
195
|
-
get output(): Result<T>;
|
|
196
|
-
get computed(): Computed<T>;
|
|
197
|
-
get isDisposed(): boolean;
|
|
198
242
|
dispose(): void;
|
|
199
243
|
private _updateCycle;
|
|
200
244
|
}
|
|
201
245
|
|
|
202
246
|
/** Manually-settable reactive state that can participate in the Fusion dependency graph. */
|
|
203
247
|
declare class MutableState<T> extends State<T> {
|
|
248
|
+
private _nextOutput;
|
|
204
249
|
private _renewer;
|
|
205
250
|
constructor(initialOutput: Result<T> | T);
|
|
206
251
|
use(asyncContext?: AsyncContext): T;
|
|
207
252
|
set(output: Result<T> | T): void;
|
|
253
|
+
private _wireRenewal;
|
|
208
254
|
}
|
|
209
255
|
|
|
210
|
-
export { ComputeContext, ComputeFunction, type ComputeFunctionImpl, Computed, type ComputedInput, ComputedRegistry, ComputedState, type ComputedStateOptions, ConsistencyState, FixedDelayer, type FusionLogScope, type MethodMeta, MutableState, State, StateBoundComputed, type StateComputer, UIActionTracker, UIUpdateDelayer, type UpdateDelayer, computeContextKey, computeMethod, defaultUpdateDelayer, getInstanceId, getLogs, getMethodsMeta, uiActions, wrapComputeMethod };
|
|
256
|
+
export { ComputeContext, ComputeFunction, type ComputeFunctionImpl, type ComputeMethodOptions, Computed, type ComputedInput, ComputedOptions, ComputedRegistry, ComputedState, type ComputedStateOptions, ConsistencyState, FixedDelayer, type FusionLogScope, type MethodMeta, MutableState, State, StateBoundComputed, type StateComputer, UIActionTracker, UIUpdateDelayer, type UpdateDelayer, computeContextKey, computeMethod, defaultUpdateDelayer, getInstanceId, getLogs, getMethodsMeta, uiActions, wrapComputeMethod };
|