@camcima/finita 4.2.0 → 4.3.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/CHANGELOG.md +141 -0
- package/dist/index.cjs +144 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -10
- package/dist/index.d.ts +69 -10
- package/dist/index.js +143 -49
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -135,6 +135,8 @@ declare class State implements StateInterface {
|
|
|
135
135
|
*/
|
|
136
136
|
_initTransitions(key: InternalConstructionKey, transitions: Iterable<TransitionInterface>): void;
|
|
137
137
|
getName(): string;
|
|
138
|
+
/** Snapshot — the graph is shared by every machine built from the
|
|
139
|
+
* process, so callers must never receive the collection itself. */
|
|
138
140
|
getTransitions(): Iterable<TransitionInterface>;
|
|
139
141
|
getEventNames(): string[];
|
|
140
142
|
hasEvent(name: string): boolean;
|
|
@@ -189,7 +191,9 @@ declare class ProcessBuilder<TSubject = unknown> {
|
|
|
189
191
|
private findInitialStateName;
|
|
190
192
|
private validateTransitionEndpoints;
|
|
191
193
|
/** Transition identity: (fromState, eventName, toState). Used by both the
|
|
192
|
-
* conflict check and the build-time dedup — keep them in lockstep.
|
|
194
|
+
* conflict check and the build-time dedup — keep them in lockstep.
|
|
195
|
+
* Encoded as a JSON tuple, not a delimiter join: names may contain any
|
|
196
|
+
* character, so no delimiter can keep distinct tuples distinct. */
|
|
193
197
|
private static transitionKey;
|
|
194
198
|
private validateNoConflictingDuplicates;
|
|
195
199
|
private collectEventNamesByState;
|
|
@@ -351,8 +355,11 @@ interface StatemachineOptions<TSubject = unknown> {
|
|
|
351
355
|
* Called when an operation chained via EnqueueContext.enqueue() fails.
|
|
352
356
|
* Chained operations are not awaited by the caller whose transition
|
|
353
357
|
* enqueued them, so without this hook their errors are discarded.
|
|
354
|
-
*
|
|
355
|
-
*
|
|
358
|
+
* The hook may be async. It is not awaited, and both exceptions it throws
|
|
359
|
+
* and rejections of the promise it returns are swallowed — it must not be
|
|
360
|
+
* able to break the machine's drain loop or surface as an unhandled
|
|
361
|
+
* rejection. (The return type stays `void`, which already admits async
|
|
362
|
+
* functions, so callbacks returning incidental values keep compiling.)
|
|
356
363
|
*/
|
|
357
364
|
onChainedOperationError?: (error: unknown, info: {
|
|
358
365
|
eventName: string;
|
|
@@ -374,7 +381,8 @@ interface StatemachineOptions<TSubject = unknown> {
|
|
|
374
381
|
* release throws — including when the operation itself also failed, in
|
|
375
382
|
* which case the caller's rejection carries the operation error and the
|
|
376
383
|
* release error would otherwise be discarded. Does not change rejection
|
|
377
|
-
* behavior.
|
|
384
|
+
* behavior. The hook may be async; it is not awaited, and both exceptions
|
|
385
|
+
* it throws and rejections of the promise it returns are swallowed.
|
|
378
386
|
*/
|
|
379
387
|
onReleaseError?: (error: unknown) => void;
|
|
380
388
|
}
|
|
@@ -393,6 +401,8 @@ declare class Statemachine<TSubject = unknown> implements StatemachineInterface<
|
|
|
393
401
|
private running;
|
|
394
402
|
private idleWaiters;
|
|
395
403
|
private inSyncCallback;
|
|
404
|
+
/** Set when releasing a held lock fails; see LockOwnershipUncertainError. */
|
|
405
|
+
private ownershipUncertainty;
|
|
396
406
|
private readonly beforeObservers;
|
|
397
407
|
private readonly afterObservers;
|
|
398
408
|
private readonly onChainedOperationError?;
|
|
@@ -418,6 +428,9 @@ declare class Statemachine<TSubject = unknown> implements StatemachineInterface<
|
|
|
418
428
|
* so manual lock management keeps its existing control flow. Inspect
|
|
419
429
|
* isLockAcquired() (or the hook) to learn whether the lock was actually
|
|
420
430
|
* freed.
|
|
431
|
+
*
|
|
432
|
+
* A failed release of a held lock makes every later operation reject with
|
|
433
|
+
* LockOwnershipUncertainError; a successful call here is how to recover.
|
|
421
434
|
*/
|
|
422
435
|
releaseLock(): Promise<void>;
|
|
423
436
|
isLockAcquired(): boolean;
|
|
@@ -461,9 +474,22 @@ declare class Statemachine<TSubject = unknown> implements StatemachineInterface<
|
|
|
461
474
|
* operation also failed, the rejection carries the operation error and this
|
|
462
475
|
* hook is the only place the release error appears.
|
|
463
476
|
*
|
|
477
|
+
* A failure while the mutex claimed to hold the lock leaves ownership
|
|
478
|
+
* uncertain and blocks later operations; a success clears that state. A
|
|
479
|
+
* failed release of a lock the mutex did not claim (a defensive manual
|
|
480
|
+
* release) is still reported but changes nothing.
|
|
481
|
+
*
|
|
464
482
|
* @returns null on success, or the failure wrapped for the caller to raise.
|
|
465
483
|
*/
|
|
466
484
|
private releaseMutex;
|
|
485
|
+
/**
|
|
486
|
+
* Runs a user diagnostic hook in isolation. Neither a synchronous throw nor
|
|
487
|
+
* a rejection of a returned promise may reach the drain loop or the host:
|
|
488
|
+
* an unavailable telemetry backend must not fail an operation or, via an
|
|
489
|
+
* unhandled rejection, terminate the process. A returned promise is
|
|
490
|
+
* deliberately not awaited — a slow reporter must not stall the runner.
|
|
491
|
+
*/
|
|
492
|
+
private callDiagnosticHook;
|
|
467
493
|
private resolveEvent;
|
|
468
494
|
/**
|
|
469
495
|
* Drive transitions starting from the current state, following automatic
|
|
@@ -563,26 +589,37 @@ declare abstract class CompositeCondition<TSubject = unknown> implements Conditi
|
|
|
563
589
|
constructor(joinWord: string, condition: ConditionInterface<TSubject>);
|
|
564
590
|
protected addCondition(condition: ConditionInterface<TSubject>): this;
|
|
565
591
|
getName(): string;
|
|
566
|
-
abstract checkCondition(subject: TSubject, context: Map<string, unknown>):
|
|
592
|
+
abstract checkCondition(subject: TSubject, context: Map<string, unknown>): MaybePromise<boolean>;
|
|
593
|
+
/**
|
|
594
|
+
* Evaluates children in order, stopping at the first whose result equals
|
|
595
|
+
* `shortCircuitOn`. A child that returns a plain boolean is consumed
|
|
596
|
+
* synchronously; only a returned promise is awaited. Awaiting plain values
|
|
597
|
+
* would yield between children and end the machine's synchronous
|
|
598
|
+
* re-entrancy guard, so a re-entrant later child would deadlock instead of
|
|
599
|
+
* throwing ReentrancyError. For the same reason the composite itself
|
|
600
|
+
* returns a plain boolean when every child it evaluated did.
|
|
601
|
+
*/
|
|
602
|
+
protected evaluate(subject: TSubject, context: Map<string, unknown>, shortCircuitOn: boolean): MaybePromise<boolean>;
|
|
567
603
|
}
|
|
568
604
|
|
|
569
605
|
declare class AndComposite<TSubject = unknown> extends CompositeCondition<TSubject> {
|
|
570
606
|
constructor(condition: ConditionInterface<TSubject>);
|
|
571
607
|
addAnd(condition: ConditionInterface<TSubject>): this;
|
|
572
|
-
checkCondition(subject: TSubject, context: Map<string, unknown>):
|
|
608
|
+
checkCondition(subject: TSubject, context: Map<string, unknown>): MaybePromise<boolean>;
|
|
573
609
|
}
|
|
574
610
|
|
|
575
611
|
declare class OrComposite<TSubject = unknown> extends CompositeCondition<TSubject> {
|
|
576
612
|
constructor(condition: ConditionInterface<TSubject>);
|
|
577
613
|
addOr(condition: ConditionInterface<TSubject>): this;
|
|
578
|
-
checkCondition(subject: TSubject, context: Map<string, unknown>):
|
|
614
|
+
checkCondition(subject: TSubject, context: Map<string, unknown>): MaybePromise<boolean>;
|
|
579
615
|
}
|
|
580
616
|
|
|
581
617
|
declare class Not<TSubject = unknown> implements ConditionInterface<TSubject> {
|
|
582
618
|
private readonly condition;
|
|
583
619
|
constructor(condition: ConditionInterface<TSubject>);
|
|
584
620
|
getName(): string;
|
|
585
|
-
|
|
621
|
+
/** Stays synchronous for a synchronous child — see CompositeCondition. */
|
|
622
|
+
checkCondition(subject: TSubject, context: Map<string, unknown>): MaybePromise<boolean>;
|
|
586
623
|
}
|
|
587
624
|
|
|
588
625
|
/**
|
|
@@ -705,6 +742,11 @@ declare class LockAdapterMutex implements MutexInterface {
|
|
|
705
742
|
* pass the check and acquire twice on a non-idempotent adapter (database
|
|
706
743
|
* advisory locks, redis SET NX). The pending promise is cleared once it
|
|
707
744
|
* settles, so a failed acquire can still be retried.
|
|
745
|
+
*
|
|
746
|
+
* The clearing is attached to the attempt only after it is stored: an
|
|
747
|
+
* adapter that throws synchronously settles the attempt before the
|
|
748
|
+
* assignment would otherwise run, and clearing inside the attempt itself
|
|
749
|
+
* would then leave the rejected promise cached forever.
|
|
708
750
|
*/
|
|
709
751
|
acquireLock(): Promise<boolean>;
|
|
710
752
|
releaseLock(): Promise<boolean>;
|
|
@@ -810,7 +852,7 @@ declare class GraphBuilder {
|
|
|
810
852
|
|
|
811
853
|
declare abstract class FinitaError extends Error {
|
|
812
854
|
abstract readonly code: string;
|
|
813
|
-
constructor(message?: string);
|
|
855
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
814
856
|
}
|
|
815
857
|
|
|
816
858
|
declare class WrongEventForStateError extends FinitaError {
|
|
@@ -839,6 +881,23 @@ declare class LockCanNotBeReleasedError extends FinitaError {
|
|
|
839
881
|
constructor(message?: string);
|
|
840
882
|
}
|
|
841
883
|
|
|
884
|
+
/**
|
|
885
|
+
* A lock release failed earlier, so the machine can no longer tell whether it
|
|
886
|
+
* still holds the lock: the unlock may have taken effect remotely with its
|
|
887
|
+
* reply lost, or may never have happened. Running further operations on the
|
|
888
|
+
* old ownership flag could violate mutual exclusion, so every operation is
|
|
889
|
+
* rejected with this error until a manual Statemachine.releaseLock()
|
|
890
|
+
* succeeds.
|
|
891
|
+
*
|
|
892
|
+
* `cause` carries the release failure. When the release cannot be confirmed
|
|
893
|
+
* — typically because the lock was in fact already freed — discard the
|
|
894
|
+
* machine and build a new one from persisted state.
|
|
895
|
+
*/
|
|
896
|
+
declare class LockOwnershipUncertainError extends FinitaError {
|
|
897
|
+
readonly code = "lockOwnershipUncertain";
|
|
898
|
+
constructor(cause: unknown);
|
|
899
|
+
}
|
|
900
|
+
|
|
842
901
|
declare class DuplicateStateError extends FinitaError {
|
|
843
902
|
readonly code = "duplicateState";
|
|
844
903
|
readonly stateName: string;
|
|
@@ -933,4 +992,4 @@ declare class QueueLimitExceededError extends FinitaError {
|
|
|
933
992
|
constructor(limit: number, eventName: string | null);
|
|
934
993
|
}
|
|
935
994
|
|
|
936
|
-
export { AbstractNamedProcessDetector, ActiveTransitionFilter, type AddStateOptions, type AddTransitionOptions, type AfterTransitionObserver, type AmbiguousTransitionCandidate, AmbiguousTransitionError, AndComposite, AutomaticTransitionCycleError, type BeforeTransitionObserver, type BuildOptions, CallbackCondition, type CallbackInterface, CallbackObserver, type ConditionCallbackFn, type ConditionInterface, Contradiction, type DispatcherInterface, type DotOptions, DuplicateStateError, type DuplicateTransitionConflict, DuplicateTransitionError, type EnqueueContext, Event, type EventInterface, Factory, type FactoryInterface, type FactoryStatemachineOptions, FilterStateByEvent, FilterStateByFinalState, FilterStateByTransition, FilterTransitionByEvent, FinitaError, type Graph, GraphBuilder, type GraphDirection, type GraphEdge, type GraphNode, type GraphValidationCode, GraphValidationError, InvalidSubjectError, type LastStateHasChangedDateInterface, type LockAdapterInterface, LockAdapterMutex, LockCanNotBeAcquiredError, LockCanNotBeReleasedError, type LoggerInterface, type MaybePromise, type MermaidOptions, type Metadata, MutexFactory, type MutexFactoryInterface, type MutexInterface, type Named, Not, NullMutex, type ObservableSubject, type Observer, OnEnterObserver, OneOrNoneActiveTransition, OrComposite, Process, ProcessBuilder, type ProcessDetectorInterface, ProcessFinalizedError, type ProcessInterface, ProcessNotFoundError, type ProposedTransitionFrame, QueueLimitExceededError, ReentrancyError, ScoreTransition, SingleProcessDetector, State, type StateCollectionInterface, StateEventNotFoundError, type StateInterface, type StateNameDetectorInterface, StateNotFoundError, type StatefulInterface, StatefulStateNameDetector, StatefulStatusChanger, Statemachine, type StatemachineInterface, type StatemachineOptions, type StringConverter, Tautology, Timeout, Transition, type TransitionFrame, type TransitionInterface, TransitionLogger, type TransitionSelectorInterface, WeightTransition, type Weighted, WrongEventForStateError };
|
|
995
|
+
export { AbstractNamedProcessDetector, ActiveTransitionFilter, type AddStateOptions, type AddTransitionOptions, type AfterTransitionObserver, type AmbiguousTransitionCandidate, AmbiguousTransitionError, AndComposite, AutomaticTransitionCycleError, type BeforeTransitionObserver, type BuildOptions, CallbackCondition, type CallbackInterface, CallbackObserver, type ConditionCallbackFn, type ConditionInterface, Contradiction, type DispatcherInterface, type DotOptions, DuplicateStateError, type DuplicateTransitionConflict, DuplicateTransitionError, type EnqueueContext, Event, type EventInterface, Factory, type FactoryInterface, type FactoryStatemachineOptions, FilterStateByEvent, FilterStateByFinalState, FilterStateByTransition, FilterTransitionByEvent, FinitaError, type Graph, GraphBuilder, type GraphDirection, type GraphEdge, type GraphNode, type GraphValidationCode, GraphValidationError, InvalidSubjectError, type LastStateHasChangedDateInterface, type LockAdapterInterface, LockAdapterMutex, LockCanNotBeAcquiredError, LockCanNotBeReleasedError, LockOwnershipUncertainError, type LoggerInterface, type MaybePromise, type MermaidOptions, type Metadata, MutexFactory, type MutexFactoryInterface, type MutexInterface, type Named, Not, NullMutex, type ObservableSubject, type Observer, OnEnterObserver, OneOrNoneActiveTransition, OrComposite, Process, ProcessBuilder, type ProcessDetectorInterface, ProcessFinalizedError, type ProcessInterface, ProcessNotFoundError, type ProposedTransitionFrame, QueueLimitExceededError, ReentrancyError, ScoreTransition, SingleProcessDetector, State, type StateCollectionInterface, StateEventNotFoundError, type StateInterface, type StateNameDetectorInterface, StateNotFoundError, type StatefulInterface, StatefulStateNameDetector, StatefulStatusChanger, Statemachine, type StatemachineInterface, type StatemachineOptions, type StringConverter, Tautology, Timeout, Transition, type TransitionFrame, type TransitionInterface, TransitionLogger, type TransitionSelectorInterface, WeightTransition, type Weighted, WrongEventForStateError };
|
package/dist/index.d.ts
CHANGED
|
@@ -135,6 +135,8 @@ declare class State implements StateInterface {
|
|
|
135
135
|
*/
|
|
136
136
|
_initTransitions(key: InternalConstructionKey, transitions: Iterable<TransitionInterface>): void;
|
|
137
137
|
getName(): string;
|
|
138
|
+
/** Snapshot — the graph is shared by every machine built from the
|
|
139
|
+
* process, so callers must never receive the collection itself. */
|
|
138
140
|
getTransitions(): Iterable<TransitionInterface>;
|
|
139
141
|
getEventNames(): string[];
|
|
140
142
|
hasEvent(name: string): boolean;
|
|
@@ -189,7 +191,9 @@ declare class ProcessBuilder<TSubject = unknown> {
|
|
|
189
191
|
private findInitialStateName;
|
|
190
192
|
private validateTransitionEndpoints;
|
|
191
193
|
/** Transition identity: (fromState, eventName, toState). Used by both the
|
|
192
|
-
* conflict check and the build-time dedup — keep them in lockstep.
|
|
194
|
+
* conflict check and the build-time dedup — keep them in lockstep.
|
|
195
|
+
* Encoded as a JSON tuple, not a delimiter join: names may contain any
|
|
196
|
+
* character, so no delimiter can keep distinct tuples distinct. */
|
|
193
197
|
private static transitionKey;
|
|
194
198
|
private validateNoConflictingDuplicates;
|
|
195
199
|
private collectEventNamesByState;
|
|
@@ -351,8 +355,11 @@ interface StatemachineOptions<TSubject = unknown> {
|
|
|
351
355
|
* Called when an operation chained via EnqueueContext.enqueue() fails.
|
|
352
356
|
* Chained operations are not awaited by the caller whose transition
|
|
353
357
|
* enqueued them, so without this hook their errors are discarded.
|
|
354
|
-
*
|
|
355
|
-
*
|
|
358
|
+
* The hook may be async. It is not awaited, and both exceptions it throws
|
|
359
|
+
* and rejections of the promise it returns are swallowed — it must not be
|
|
360
|
+
* able to break the machine's drain loop or surface as an unhandled
|
|
361
|
+
* rejection. (The return type stays `void`, which already admits async
|
|
362
|
+
* functions, so callbacks returning incidental values keep compiling.)
|
|
356
363
|
*/
|
|
357
364
|
onChainedOperationError?: (error: unknown, info: {
|
|
358
365
|
eventName: string;
|
|
@@ -374,7 +381,8 @@ interface StatemachineOptions<TSubject = unknown> {
|
|
|
374
381
|
* release throws — including when the operation itself also failed, in
|
|
375
382
|
* which case the caller's rejection carries the operation error and the
|
|
376
383
|
* release error would otherwise be discarded. Does not change rejection
|
|
377
|
-
* behavior.
|
|
384
|
+
* behavior. The hook may be async; it is not awaited, and both exceptions
|
|
385
|
+
* it throws and rejections of the promise it returns are swallowed.
|
|
378
386
|
*/
|
|
379
387
|
onReleaseError?: (error: unknown) => void;
|
|
380
388
|
}
|
|
@@ -393,6 +401,8 @@ declare class Statemachine<TSubject = unknown> implements StatemachineInterface<
|
|
|
393
401
|
private running;
|
|
394
402
|
private idleWaiters;
|
|
395
403
|
private inSyncCallback;
|
|
404
|
+
/** Set when releasing a held lock fails; see LockOwnershipUncertainError. */
|
|
405
|
+
private ownershipUncertainty;
|
|
396
406
|
private readonly beforeObservers;
|
|
397
407
|
private readonly afterObservers;
|
|
398
408
|
private readonly onChainedOperationError?;
|
|
@@ -418,6 +428,9 @@ declare class Statemachine<TSubject = unknown> implements StatemachineInterface<
|
|
|
418
428
|
* so manual lock management keeps its existing control flow. Inspect
|
|
419
429
|
* isLockAcquired() (or the hook) to learn whether the lock was actually
|
|
420
430
|
* freed.
|
|
431
|
+
*
|
|
432
|
+
* A failed release of a held lock makes every later operation reject with
|
|
433
|
+
* LockOwnershipUncertainError; a successful call here is how to recover.
|
|
421
434
|
*/
|
|
422
435
|
releaseLock(): Promise<void>;
|
|
423
436
|
isLockAcquired(): boolean;
|
|
@@ -461,9 +474,22 @@ declare class Statemachine<TSubject = unknown> implements StatemachineInterface<
|
|
|
461
474
|
* operation also failed, the rejection carries the operation error and this
|
|
462
475
|
* hook is the only place the release error appears.
|
|
463
476
|
*
|
|
477
|
+
* A failure while the mutex claimed to hold the lock leaves ownership
|
|
478
|
+
* uncertain and blocks later operations; a success clears that state. A
|
|
479
|
+
* failed release of a lock the mutex did not claim (a defensive manual
|
|
480
|
+
* release) is still reported but changes nothing.
|
|
481
|
+
*
|
|
464
482
|
* @returns null on success, or the failure wrapped for the caller to raise.
|
|
465
483
|
*/
|
|
466
484
|
private releaseMutex;
|
|
485
|
+
/**
|
|
486
|
+
* Runs a user diagnostic hook in isolation. Neither a synchronous throw nor
|
|
487
|
+
* a rejection of a returned promise may reach the drain loop or the host:
|
|
488
|
+
* an unavailable telemetry backend must not fail an operation or, via an
|
|
489
|
+
* unhandled rejection, terminate the process. A returned promise is
|
|
490
|
+
* deliberately not awaited — a slow reporter must not stall the runner.
|
|
491
|
+
*/
|
|
492
|
+
private callDiagnosticHook;
|
|
467
493
|
private resolveEvent;
|
|
468
494
|
/**
|
|
469
495
|
* Drive transitions starting from the current state, following automatic
|
|
@@ -563,26 +589,37 @@ declare abstract class CompositeCondition<TSubject = unknown> implements Conditi
|
|
|
563
589
|
constructor(joinWord: string, condition: ConditionInterface<TSubject>);
|
|
564
590
|
protected addCondition(condition: ConditionInterface<TSubject>): this;
|
|
565
591
|
getName(): string;
|
|
566
|
-
abstract checkCondition(subject: TSubject, context: Map<string, unknown>):
|
|
592
|
+
abstract checkCondition(subject: TSubject, context: Map<string, unknown>): MaybePromise<boolean>;
|
|
593
|
+
/**
|
|
594
|
+
* Evaluates children in order, stopping at the first whose result equals
|
|
595
|
+
* `shortCircuitOn`. A child that returns a plain boolean is consumed
|
|
596
|
+
* synchronously; only a returned promise is awaited. Awaiting plain values
|
|
597
|
+
* would yield between children and end the machine's synchronous
|
|
598
|
+
* re-entrancy guard, so a re-entrant later child would deadlock instead of
|
|
599
|
+
* throwing ReentrancyError. For the same reason the composite itself
|
|
600
|
+
* returns a plain boolean when every child it evaluated did.
|
|
601
|
+
*/
|
|
602
|
+
protected evaluate(subject: TSubject, context: Map<string, unknown>, shortCircuitOn: boolean): MaybePromise<boolean>;
|
|
567
603
|
}
|
|
568
604
|
|
|
569
605
|
declare class AndComposite<TSubject = unknown> extends CompositeCondition<TSubject> {
|
|
570
606
|
constructor(condition: ConditionInterface<TSubject>);
|
|
571
607
|
addAnd(condition: ConditionInterface<TSubject>): this;
|
|
572
|
-
checkCondition(subject: TSubject, context: Map<string, unknown>):
|
|
608
|
+
checkCondition(subject: TSubject, context: Map<string, unknown>): MaybePromise<boolean>;
|
|
573
609
|
}
|
|
574
610
|
|
|
575
611
|
declare class OrComposite<TSubject = unknown> extends CompositeCondition<TSubject> {
|
|
576
612
|
constructor(condition: ConditionInterface<TSubject>);
|
|
577
613
|
addOr(condition: ConditionInterface<TSubject>): this;
|
|
578
|
-
checkCondition(subject: TSubject, context: Map<string, unknown>):
|
|
614
|
+
checkCondition(subject: TSubject, context: Map<string, unknown>): MaybePromise<boolean>;
|
|
579
615
|
}
|
|
580
616
|
|
|
581
617
|
declare class Not<TSubject = unknown> implements ConditionInterface<TSubject> {
|
|
582
618
|
private readonly condition;
|
|
583
619
|
constructor(condition: ConditionInterface<TSubject>);
|
|
584
620
|
getName(): string;
|
|
585
|
-
|
|
621
|
+
/** Stays synchronous for a synchronous child — see CompositeCondition. */
|
|
622
|
+
checkCondition(subject: TSubject, context: Map<string, unknown>): MaybePromise<boolean>;
|
|
586
623
|
}
|
|
587
624
|
|
|
588
625
|
/**
|
|
@@ -705,6 +742,11 @@ declare class LockAdapterMutex implements MutexInterface {
|
|
|
705
742
|
* pass the check and acquire twice on a non-idempotent adapter (database
|
|
706
743
|
* advisory locks, redis SET NX). The pending promise is cleared once it
|
|
707
744
|
* settles, so a failed acquire can still be retried.
|
|
745
|
+
*
|
|
746
|
+
* The clearing is attached to the attempt only after it is stored: an
|
|
747
|
+
* adapter that throws synchronously settles the attempt before the
|
|
748
|
+
* assignment would otherwise run, and clearing inside the attempt itself
|
|
749
|
+
* would then leave the rejected promise cached forever.
|
|
708
750
|
*/
|
|
709
751
|
acquireLock(): Promise<boolean>;
|
|
710
752
|
releaseLock(): Promise<boolean>;
|
|
@@ -810,7 +852,7 @@ declare class GraphBuilder {
|
|
|
810
852
|
|
|
811
853
|
declare abstract class FinitaError extends Error {
|
|
812
854
|
abstract readonly code: string;
|
|
813
|
-
constructor(message?: string);
|
|
855
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
814
856
|
}
|
|
815
857
|
|
|
816
858
|
declare class WrongEventForStateError extends FinitaError {
|
|
@@ -839,6 +881,23 @@ declare class LockCanNotBeReleasedError extends FinitaError {
|
|
|
839
881
|
constructor(message?: string);
|
|
840
882
|
}
|
|
841
883
|
|
|
884
|
+
/**
|
|
885
|
+
* A lock release failed earlier, so the machine can no longer tell whether it
|
|
886
|
+
* still holds the lock: the unlock may have taken effect remotely with its
|
|
887
|
+
* reply lost, or may never have happened. Running further operations on the
|
|
888
|
+
* old ownership flag could violate mutual exclusion, so every operation is
|
|
889
|
+
* rejected with this error until a manual Statemachine.releaseLock()
|
|
890
|
+
* succeeds.
|
|
891
|
+
*
|
|
892
|
+
* `cause` carries the release failure. When the release cannot be confirmed
|
|
893
|
+
* — typically because the lock was in fact already freed — discard the
|
|
894
|
+
* machine and build a new one from persisted state.
|
|
895
|
+
*/
|
|
896
|
+
declare class LockOwnershipUncertainError extends FinitaError {
|
|
897
|
+
readonly code = "lockOwnershipUncertain";
|
|
898
|
+
constructor(cause: unknown);
|
|
899
|
+
}
|
|
900
|
+
|
|
842
901
|
declare class DuplicateStateError extends FinitaError {
|
|
843
902
|
readonly code = "duplicateState";
|
|
844
903
|
readonly stateName: string;
|
|
@@ -933,4 +992,4 @@ declare class QueueLimitExceededError extends FinitaError {
|
|
|
933
992
|
constructor(limit: number, eventName: string | null);
|
|
934
993
|
}
|
|
935
994
|
|
|
936
|
-
export { AbstractNamedProcessDetector, ActiveTransitionFilter, type AddStateOptions, type AddTransitionOptions, type AfterTransitionObserver, type AmbiguousTransitionCandidate, AmbiguousTransitionError, AndComposite, AutomaticTransitionCycleError, type BeforeTransitionObserver, type BuildOptions, CallbackCondition, type CallbackInterface, CallbackObserver, type ConditionCallbackFn, type ConditionInterface, Contradiction, type DispatcherInterface, type DotOptions, DuplicateStateError, type DuplicateTransitionConflict, DuplicateTransitionError, type EnqueueContext, Event, type EventInterface, Factory, type FactoryInterface, type FactoryStatemachineOptions, FilterStateByEvent, FilterStateByFinalState, FilterStateByTransition, FilterTransitionByEvent, FinitaError, type Graph, GraphBuilder, type GraphDirection, type GraphEdge, type GraphNode, type GraphValidationCode, GraphValidationError, InvalidSubjectError, type LastStateHasChangedDateInterface, type LockAdapterInterface, LockAdapterMutex, LockCanNotBeAcquiredError, LockCanNotBeReleasedError, type LoggerInterface, type MaybePromise, type MermaidOptions, type Metadata, MutexFactory, type MutexFactoryInterface, type MutexInterface, type Named, Not, NullMutex, type ObservableSubject, type Observer, OnEnterObserver, OneOrNoneActiveTransition, OrComposite, Process, ProcessBuilder, type ProcessDetectorInterface, ProcessFinalizedError, type ProcessInterface, ProcessNotFoundError, type ProposedTransitionFrame, QueueLimitExceededError, ReentrancyError, ScoreTransition, SingleProcessDetector, State, type StateCollectionInterface, StateEventNotFoundError, type StateInterface, type StateNameDetectorInterface, StateNotFoundError, type StatefulInterface, StatefulStateNameDetector, StatefulStatusChanger, Statemachine, type StatemachineInterface, type StatemachineOptions, type StringConverter, Tautology, Timeout, Transition, type TransitionFrame, type TransitionInterface, TransitionLogger, type TransitionSelectorInterface, WeightTransition, type Weighted, WrongEventForStateError };
|
|
995
|
+
export { AbstractNamedProcessDetector, ActiveTransitionFilter, type AddStateOptions, type AddTransitionOptions, type AfterTransitionObserver, type AmbiguousTransitionCandidate, AmbiguousTransitionError, AndComposite, AutomaticTransitionCycleError, type BeforeTransitionObserver, type BuildOptions, CallbackCondition, type CallbackInterface, CallbackObserver, type ConditionCallbackFn, type ConditionInterface, Contradiction, type DispatcherInterface, type DotOptions, DuplicateStateError, type DuplicateTransitionConflict, DuplicateTransitionError, type EnqueueContext, Event, type EventInterface, Factory, type FactoryInterface, type FactoryStatemachineOptions, FilterStateByEvent, FilterStateByFinalState, FilterStateByTransition, FilterTransitionByEvent, FinitaError, type Graph, GraphBuilder, type GraphDirection, type GraphEdge, type GraphNode, type GraphValidationCode, GraphValidationError, InvalidSubjectError, type LastStateHasChangedDateInterface, type LockAdapterInterface, LockAdapterMutex, LockCanNotBeAcquiredError, LockCanNotBeReleasedError, LockOwnershipUncertainError, type LoggerInterface, type MaybePromise, type MermaidOptions, type Metadata, MutexFactory, type MutexFactoryInterface, type MutexInterface, type Named, Not, NullMutex, type ObservableSubject, type Observer, OnEnterObserver, OneOrNoneActiveTransition, OrComposite, Process, ProcessBuilder, type ProcessDetectorInterface, ProcessFinalizedError, type ProcessInterface, ProcessNotFoundError, type ProposedTransitionFrame, QueueLimitExceededError, ReentrancyError, ScoreTransition, SingleProcessDetector, State, type StateCollectionInterface, StateEventNotFoundError, type StateInterface, type StateNameDetectorInterface, StateNotFoundError, type StatefulInterface, StatefulStateNameDetector, StatefulStatusChanger, Statemachine, type StatemachineInterface, type StatemachineOptions, type StringConverter, Tautology, Timeout, Transition, type TransitionFrame, type TransitionInterface, TransitionLogger, type TransitionSelectorInterface, WeightTransition, type Weighted, WrongEventForStateError };
|