@lite-fsm/core 2.0.4 → 2.1.0-alpha.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/dist/MachineManager.d.cts +1 -3
- package/dist/MachineManager.d.ts +1 -3
- package/dist/actor.d.cts +1 -7
- package/dist/actor.d.ts +1 -7
- package/dist/actorEffects.d.cts +2 -0
- package/dist/actorEffects.d.ts +2 -0
- package/dist/createMachine.d.cts +3 -34
- package/dist/createMachine.d.ts +3 -34
- package/dist/createMachine.types.d.cts +166 -0
- package/dist/createMachine.types.d.ts +166 -0
- package/dist/hydration.d.cts +2 -1
- package/dist/hydration.d.ts +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +1 -1
- package/dist/interfaces.d.cts +40 -19
- package/dist/interfaces.d.ts +40 -19
- package/dist/internal.d.cts +0 -1
- package/dist/internal.d.ts +0 -1
- package/dist/managerNormalize.d.cts +9 -2
- package/dist/managerNormalize.d.ts +9 -2
- package/dist/plugin.d.cts +81 -0
- package/dist/plugin.d.ts +81 -0
- package/dist/pluginHelpers.d.cts +68 -0
- package/dist/pluginHelpers.d.ts +68 -0
- package/dist/pluginNormalize.d.cts +16 -0
- package/dist/pluginNormalize.d.ts +16 -0
- package/dist/pluginStorage.d.cts +20 -0
- package/dist/pluginStorage.d.ts +20 -0
- package/dist/pluginStorageNormalize.d.cts +3 -0
- package/dist/pluginStorageNormalize.d.ts +3 -0
- package/dist/pluginStorageTypes.d.cts +326 -0
- package/dist/pluginStorageTypes.d.ts +326 -0
- package/dist/pluginTypes.d.cts +102 -0
- package/dist/pluginTypes.d.ts +102 -0
- package/dist/runtime/defaultPreset.d.cts +2 -0
- package/dist/runtime/defaultPreset.d.ts +2 -0
- package/dist/runtime/instance/manager.d.cts +37 -0
- package/dist/runtime/instance/manager.d.ts +37 -0
- package/dist/runtime/instance/plugin.d.cts +3 -0
- package/dist/runtime/instance/plugin.d.ts +3 -0
- package/dist/runtime/instance/storage.d.cts +3 -0
- package/dist/runtime/instance/storage.d.ts +3 -0
- package/dist/runtime/kernel/actionView.d.cts +2 -0
- package/dist/runtime/kernel/actionView.d.ts +2 -0
- package/dist/runtime/kernel/bucketRuntime.d.cts +34 -0
- package/dist/runtime/kernel/bucketRuntime.d.ts +34 -0
- package/dist/runtime/kernel/callbackValidation.d.cts +11 -0
- package/dist/runtime/kernel/callbackValidation.d.ts +11 -0
- package/dist/runtime/kernel/createMachineManagerFactory.d.cts +13 -0
- package/dist/runtime/kernel/createMachineManagerFactory.d.ts +13 -0
- package/dist/runtime/kernel/registry.d.cts +23 -0
- package/dist/runtime/kernel/registry.d.ts +23 -0
- package/dist/runtime/kernel/routing.d.cts +33 -0
- package/dist/runtime/kernel/routing.d.ts +33 -0
- package/dist/runtime/kernel/snapshot.d.cts +26 -0
- package/dist/runtime/kernel/snapshot.d.ts +26 -0
- package/dist/runtime/kernel/storage.d.cts +226 -0
- package/dist/runtime/kernel/storage.d.ts +226 -0
- package/dist/runtime/kernel/transitionGuard.d.cts +4 -0
- package/dist/runtime/kernel/transitionGuard.d.ts +4 -0
- package/dist/runtime/kernel/transitionTrace.d.cts +40 -0
- package/dist/runtime/kernel/transitionTrace.d.ts +40 -0
- package/dist/sidecar.d.cts +2 -2
- package/dist/sidecar.d.ts +2 -2
- package/dist/types.d.cts +35 -10
- package/dist/types.d.ts +35 -10
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { MachineManagerOptions } from "../../interfaces";
|
|
2
|
+
import type { ManagerRuntimeContext as PublicManagerRuntimeContext, ScopedInvocationContext } from "../../plugin";
|
|
3
|
+
import type { StorageActionStageResult as PublicStorageActionStageResult, StorageDehydrateResult as PublicStorageDehydrateResult, StorageHydrateResult as PublicStorageHydrateResult, StoragePrepareActionResult as PublicStoragePrepareActionResult, StorageReduceResult as PublicStorageReduceResult, StorageRuntimeExtension as PublicStorageRuntimeExtension } from "../../pluginStorageTypes";
|
|
4
|
+
import type { AnyEvent, DehydrateOptions, HydrateStrategy, MachinesState, MachineStore, ManagerAction, ReadonlyManagerAction } from "../../types";
|
|
5
|
+
import type { RouteConstraint, RoutingRuntime } from "./routing";
|
|
6
|
+
export type StorageRuntimeState = unknown;
|
|
7
|
+
export type RuntimeIdentity = Readonly<Record<string, unknown>>;
|
|
8
|
+
export type StorageEffectInvocation = unknown;
|
|
9
|
+
export type StorageActionStageResult = PublicStorageActionStageResult;
|
|
10
|
+
export type StorageReduceResult = PublicStorageReduceResult;
|
|
11
|
+
export type ValidateTemplateContext = {
|
|
12
|
+
readonly key: string;
|
|
13
|
+
readonly machine: MachineStore[string];
|
|
14
|
+
readonly storageKind: string;
|
|
15
|
+
};
|
|
16
|
+
export type CompileTemplateContext = ValidateTemplateContext;
|
|
17
|
+
export type CompiledStorageTemplate = {
|
|
18
|
+
readonly key: string;
|
|
19
|
+
readonly kind: string;
|
|
20
|
+
readonly data?: unknown;
|
|
21
|
+
};
|
|
22
|
+
export type CreateRuntimeStateContext = {
|
|
23
|
+
readonly templates: readonly CompiledStorageTemplate[];
|
|
24
|
+
readonly manager: ManagerRuntimeContext;
|
|
25
|
+
};
|
|
26
|
+
export type CreatePublicInitialStateContext = {
|
|
27
|
+
readonly template: CompiledStorageTemplate;
|
|
28
|
+
readonly state: StorageRuntimeState;
|
|
29
|
+
};
|
|
30
|
+
export type AcceptsEventContext = {
|
|
31
|
+
readonly template: CompiledStorageTemplate;
|
|
32
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
33
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
34
|
+
readonly state: StorageRuntimeState;
|
|
35
|
+
readonly dispatch: StorageDispatchContext;
|
|
36
|
+
};
|
|
37
|
+
export type StorageReduceContext = {
|
|
38
|
+
readonly template: CompiledStorageTemplate;
|
|
39
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
40
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
41
|
+
readonly state: StorageRuntimeState;
|
|
42
|
+
readonly manager: ManagerRuntimeContext;
|
|
43
|
+
readonly dispatch: StorageDispatchContext;
|
|
44
|
+
};
|
|
45
|
+
export type StorageBeforeReduceContext = {
|
|
46
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
47
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
48
|
+
readonly state: StorageRuntimeState;
|
|
49
|
+
readonly manager: ManagerRuntimeContext;
|
|
50
|
+
readonly dispatch: StorageDispatchContext;
|
|
51
|
+
};
|
|
52
|
+
export type StorageReduceBucketContext = {
|
|
53
|
+
readonly templates: readonly CompiledStorageTemplate[];
|
|
54
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
55
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
56
|
+
readonly state: StorageRuntimeState;
|
|
57
|
+
readonly manager: ManagerRuntimeContext;
|
|
58
|
+
readonly dispatch: StorageDispatchContext;
|
|
59
|
+
};
|
|
60
|
+
export type StorageCommitContext = {
|
|
61
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
62
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
63
|
+
readonly state: StorageRuntimeState;
|
|
64
|
+
readonly manager: ManagerRuntimeContext;
|
|
65
|
+
readonly dispatch: StorageDispatchContext;
|
|
66
|
+
};
|
|
67
|
+
export type ResolveEffectInvocationsContext = {
|
|
68
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
69
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
70
|
+
readonly state: StorageRuntimeState;
|
|
71
|
+
readonly manager: ManagerRuntimeContext;
|
|
72
|
+
readonly dispatch: StorageDispatchContext;
|
|
73
|
+
};
|
|
74
|
+
export type StorageEffectInvocationContext = {
|
|
75
|
+
readonly invocation: StorageEffectInvocation;
|
|
76
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
77
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
78
|
+
readonly state: StorageRuntimeState;
|
|
79
|
+
readonly manager: ManagerRuntimeContext;
|
|
80
|
+
readonly dispatch: StorageDispatchContext;
|
|
81
|
+
};
|
|
82
|
+
export type StorageConditionContext = {
|
|
83
|
+
readonly predicate: (action: ReadonlyManagerAction<AnyEvent>) => boolean;
|
|
84
|
+
readonly state: StorageRuntimeState;
|
|
85
|
+
readonly manager: ManagerRuntimeContext;
|
|
86
|
+
};
|
|
87
|
+
export type StorageDehydrateContext = {
|
|
88
|
+
readonly state: StorageRuntimeState;
|
|
89
|
+
readonly manager: ManagerRuntimeContext;
|
|
90
|
+
readonly rootState: Record<string, unknown>;
|
|
91
|
+
readonly options: DehydrateOptions<MachineStore> | undefined;
|
|
92
|
+
};
|
|
93
|
+
export type StorageHydrateContext = {
|
|
94
|
+
readonly state: StorageRuntimeState;
|
|
95
|
+
readonly manager: ManagerRuntimeContext;
|
|
96
|
+
readonly machines: Readonly<Record<string, unknown>>;
|
|
97
|
+
readonly snapshot: unknown | undefined;
|
|
98
|
+
readonly baseState: Record<string, unknown>;
|
|
99
|
+
readonly strategy: HydrateStrategy;
|
|
100
|
+
readonly source: "hydrate" | "opts.snapshot";
|
|
101
|
+
readonly mode: "preview" | "commit" | "init";
|
|
102
|
+
};
|
|
103
|
+
export type ResolveIdentityContext = {
|
|
104
|
+
readonly state: StorageRuntimeState;
|
|
105
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
106
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
107
|
+
};
|
|
108
|
+
export type StorageReactionContext = {
|
|
109
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
110
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
111
|
+
readonly state: StorageRuntimeState;
|
|
112
|
+
readonly manager: ManagerRuntimeContext;
|
|
113
|
+
readonly dispatch: StorageDispatchContext;
|
|
114
|
+
};
|
|
115
|
+
export type StoragePrepareActionContext = {
|
|
116
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
117
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
118
|
+
readonly options: unknown;
|
|
119
|
+
readonly state: StorageRuntimeState;
|
|
120
|
+
readonly manager: ManagerRuntimeContext;
|
|
121
|
+
readonly dispatch: StorageDispatchContext;
|
|
122
|
+
};
|
|
123
|
+
export type StoragePrepareActionResult = PublicStoragePrepareActionResult;
|
|
124
|
+
export type StorageHydrateResult = PublicStorageHydrateResult;
|
|
125
|
+
export type StorageDehydrateResult = PublicStorageDehydrateResult<PublicStorageRuntimeExtension>;
|
|
126
|
+
export type StorageDispatchContext = {
|
|
127
|
+
readonly options: unknown;
|
|
128
|
+
readonly runtime: Map<string, unknown>;
|
|
129
|
+
readonly route: RouteConstraint;
|
|
130
|
+
readonly prevState: Record<string, unknown>;
|
|
131
|
+
nextState: Record<string, unknown>;
|
|
132
|
+
readonly skipDelivery: boolean;
|
|
133
|
+
reportError(error: unknown): void;
|
|
134
|
+
};
|
|
135
|
+
export type StorageDispatchOutcome = {
|
|
136
|
+
readonly type: "active";
|
|
137
|
+
} | {
|
|
138
|
+
readonly type: "drop";
|
|
139
|
+
readonly action: ManagerAction<AnyEvent>;
|
|
140
|
+
};
|
|
141
|
+
export type StorageDispatchLifecycleContext = {
|
|
142
|
+
readonly originalAction: ManagerAction<AnyEvent>;
|
|
143
|
+
action: ManagerAction<AnyEvent>;
|
|
144
|
+
skipDelivery: boolean;
|
|
145
|
+
route: RouteConstraint;
|
|
146
|
+
prevState: Record<string, unknown>;
|
|
147
|
+
nextState: Record<string, unknown>;
|
|
148
|
+
nextCalled: boolean;
|
|
149
|
+
outcome: StorageDispatchOutcome;
|
|
150
|
+
touched: Set<string>;
|
|
151
|
+
readonly dispatch: StorageDispatchContext;
|
|
152
|
+
};
|
|
153
|
+
export type DispatchSlot<T> = {
|
|
154
|
+
readonly key: string;
|
|
155
|
+
get(dispatch: StorageDispatchContext): T | undefined;
|
|
156
|
+
set(dispatch: StorageDispatchContext, value: T): void;
|
|
157
|
+
};
|
|
158
|
+
export declare const createDispatchSlot: <T>(key: string) => DispatchSlot<T>;
|
|
159
|
+
export type ManagerRuntimeContext<Events extends AnyEvent = AnyEvent, S extends MachineStore = MachineStore> = PublicManagerRuntimeContext<Events, S> & {
|
|
160
|
+
readonly config: S;
|
|
161
|
+
readonly options: MachineManagerOptions<any, any, any> | undefined;
|
|
162
|
+
readonly schemaVersion: number | undefined;
|
|
163
|
+
readonly routing: RoutingRuntime;
|
|
164
|
+
getState(): MachinesState<S>;
|
|
165
|
+
transition(action: ManagerAction<Events>, options?: unknown): ManagerAction<Events>;
|
|
166
|
+
onTransition(cb: (prevState: MachinesState<S>, currentState: MachinesState<S>, action: ReadonlyManagerAction<Events> | {
|
|
167
|
+
readonly type: string;
|
|
168
|
+
readonly payload?: unknown;
|
|
169
|
+
}) => void): () => void;
|
|
170
|
+
getDependencies(): Record<string, unknown>;
|
|
171
|
+
createScopedDeps(baseDeps: Record<string, unknown>, ctx: ScopedInvocationContext): Record<string, unknown>;
|
|
172
|
+
};
|
|
173
|
+
export type StorageRouteMetaDependencyKeys = readonly string[];
|
|
174
|
+
export type StorageRuntimeBase = {
|
|
175
|
+
readonly kind: string;
|
|
176
|
+
readonly routeMetaKeys?: StorageRouteMetaDependencyKeys;
|
|
177
|
+
validateTemplate(ctx: ValidateTemplateContext): void;
|
|
178
|
+
compileTemplate(ctx: CompileTemplateContext): CompiledStorageTemplate;
|
|
179
|
+
createRuntimeState(ctx: CreateRuntimeStateContext): StorageRuntimeState;
|
|
180
|
+
createPublicInitialState(ctx: CreatePublicInitialStateContext): unknown;
|
|
181
|
+
prepareAction?(ctx: StoragePrepareActionContext): StoragePrepareActionResult;
|
|
182
|
+
beforeReduce?(ctx: StorageBeforeReduceContext): StorageActionStageResult;
|
|
183
|
+
commit(ctx: StorageCommitContext): void;
|
|
184
|
+
};
|
|
185
|
+
export type TemplateStorageRuntime = StorageRuntimeBase & {
|
|
186
|
+
readonly reduceScope?: "template";
|
|
187
|
+
acceptsEvent(ctx: AcceptsEventContext): boolean;
|
|
188
|
+
reduce(ctx: StorageReduceContext): StorageReduceResult;
|
|
189
|
+
readonly reduceBucket?: never;
|
|
190
|
+
};
|
|
191
|
+
export type BucketStorageRuntime = StorageRuntimeBase & {
|
|
192
|
+
readonly reduceScope: "bucket";
|
|
193
|
+
reduceBucket(ctx: StorageReduceBucketContext): StorageReduceResult;
|
|
194
|
+
readonly acceptsEvent?: never;
|
|
195
|
+
readonly reduce?: never;
|
|
196
|
+
};
|
|
197
|
+
export type StorageEffectsRuntime = {
|
|
198
|
+
condition?(ctx: StorageConditionContext): Promise<boolean>;
|
|
199
|
+
resolveInvocations(ctx: ResolveEffectInvocationsContext): readonly StorageEffectInvocation[];
|
|
200
|
+
invoke(ctx: StorageEffectInvocationContext): void;
|
|
201
|
+
};
|
|
202
|
+
export type StorageSnapshotRuntime = {
|
|
203
|
+
dehydrate(ctx: StorageDehydrateContext): StorageDehydrateResult;
|
|
204
|
+
hydrate(ctx: StorageHydrateContext): StorageHydrateResult;
|
|
205
|
+
};
|
|
206
|
+
export type StorageIdentityRuntime = {
|
|
207
|
+
resolve(ctx: ResolveIdentityContext): RuntimeIdentity | undefined;
|
|
208
|
+
};
|
|
209
|
+
export type StorageReactionRuntime = {
|
|
210
|
+
run(ctx: StorageReactionContext): void;
|
|
211
|
+
};
|
|
212
|
+
export type StorageRuntime = (TemplateStorageRuntime | BucketStorageRuntime) & {
|
|
213
|
+
readonly effects?: StorageEffectsRuntime;
|
|
214
|
+
readonly snapshot?: StorageSnapshotRuntime;
|
|
215
|
+
readonly identity?: StorageIdentityRuntime;
|
|
216
|
+
readonly reactions?: StorageReactionRuntime;
|
|
217
|
+
};
|
|
218
|
+
export type StorageRegistry = {
|
|
219
|
+
register(kind: string, runtime: StorageRuntime, owner: string): void;
|
|
220
|
+
get(kind: string): StorageRuntime | undefined;
|
|
221
|
+
};
|
|
222
|
+
export type RuntimeStorageEntry = {
|
|
223
|
+
readonly kind: string;
|
|
224
|
+
readonly runtime: StorageRuntime;
|
|
225
|
+
};
|
|
226
|
+
export declare const compileStorageTemplates: (machines: MachineStore, machineKeys: readonly string[], storage: StorageRegistry, defaultStorageKind: string) => CompiledStorageTemplate[];
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { MachineManagerOptions } from "../../interfaces";
|
|
2
|
+
import type { ManagerRuntimeContext as PublicManagerRuntimeContext, ScopedInvocationContext } from "../../plugin";
|
|
3
|
+
import type { StorageActionStageResult as PublicStorageActionStageResult, StorageDehydrateResult as PublicStorageDehydrateResult, StorageHydrateResult as PublicStorageHydrateResult, StoragePrepareActionResult as PublicStoragePrepareActionResult, StorageReduceResult as PublicStorageReduceResult, StorageRuntimeExtension as PublicStorageRuntimeExtension } from "../../pluginStorageTypes";
|
|
4
|
+
import type { AnyEvent, DehydrateOptions, HydrateStrategy, MachinesState, MachineStore, ManagerAction, ReadonlyManagerAction } from "../../types";
|
|
5
|
+
import type { RouteConstraint, RoutingRuntime } from "./routing";
|
|
6
|
+
export type StorageRuntimeState = unknown;
|
|
7
|
+
export type RuntimeIdentity = Readonly<Record<string, unknown>>;
|
|
8
|
+
export type StorageEffectInvocation = unknown;
|
|
9
|
+
export type StorageActionStageResult = PublicStorageActionStageResult;
|
|
10
|
+
export type StorageReduceResult = PublicStorageReduceResult;
|
|
11
|
+
export type ValidateTemplateContext = {
|
|
12
|
+
readonly key: string;
|
|
13
|
+
readonly machine: MachineStore[string];
|
|
14
|
+
readonly storageKind: string;
|
|
15
|
+
};
|
|
16
|
+
export type CompileTemplateContext = ValidateTemplateContext;
|
|
17
|
+
export type CompiledStorageTemplate = {
|
|
18
|
+
readonly key: string;
|
|
19
|
+
readonly kind: string;
|
|
20
|
+
readonly data?: unknown;
|
|
21
|
+
};
|
|
22
|
+
export type CreateRuntimeStateContext = {
|
|
23
|
+
readonly templates: readonly CompiledStorageTemplate[];
|
|
24
|
+
readonly manager: ManagerRuntimeContext;
|
|
25
|
+
};
|
|
26
|
+
export type CreatePublicInitialStateContext = {
|
|
27
|
+
readonly template: CompiledStorageTemplate;
|
|
28
|
+
readonly state: StorageRuntimeState;
|
|
29
|
+
};
|
|
30
|
+
export type AcceptsEventContext = {
|
|
31
|
+
readonly template: CompiledStorageTemplate;
|
|
32
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
33
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
34
|
+
readonly state: StorageRuntimeState;
|
|
35
|
+
readonly dispatch: StorageDispatchContext;
|
|
36
|
+
};
|
|
37
|
+
export type StorageReduceContext = {
|
|
38
|
+
readonly template: CompiledStorageTemplate;
|
|
39
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
40
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
41
|
+
readonly state: StorageRuntimeState;
|
|
42
|
+
readonly manager: ManagerRuntimeContext;
|
|
43
|
+
readonly dispatch: StorageDispatchContext;
|
|
44
|
+
};
|
|
45
|
+
export type StorageBeforeReduceContext = {
|
|
46
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
47
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
48
|
+
readonly state: StorageRuntimeState;
|
|
49
|
+
readonly manager: ManagerRuntimeContext;
|
|
50
|
+
readonly dispatch: StorageDispatchContext;
|
|
51
|
+
};
|
|
52
|
+
export type StorageReduceBucketContext = {
|
|
53
|
+
readonly templates: readonly CompiledStorageTemplate[];
|
|
54
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
55
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
56
|
+
readonly state: StorageRuntimeState;
|
|
57
|
+
readonly manager: ManagerRuntimeContext;
|
|
58
|
+
readonly dispatch: StorageDispatchContext;
|
|
59
|
+
};
|
|
60
|
+
export type StorageCommitContext = {
|
|
61
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
62
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
63
|
+
readonly state: StorageRuntimeState;
|
|
64
|
+
readonly manager: ManagerRuntimeContext;
|
|
65
|
+
readonly dispatch: StorageDispatchContext;
|
|
66
|
+
};
|
|
67
|
+
export type ResolveEffectInvocationsContext = {
|
|
68
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
69
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
70
|
+
readonly state: StorageRuntimeState;
|
|
71
|
+
readonly manager: ManagerRuntimeContext;
|
|
72
|
+
readonly dispatch: StorageDispatchContext;
|
|
73
|
+
};
|
|
74
|
+
export type StorageEffectInvocationContext = {
|
|
75
|
+
readonly invocation: StorageEffectInvocation;
|
|
76
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
77
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
78
|
+
readonly state: StorageRuntimeState;
|
|
79
|
+
readonly manager: ManagerRuntimeContext;
|
|
80
|
+
readonly dispatch: StorageDispatchContext;
|
|
81
|
+
};
|
|
82
|
+
export type StorageConditionContext = {
|
|
83
|
+
readonly predicate: (action: ReadonlyManagerAction<AnyEvent>) => boolean;
|
|
84
|
+
readonly state: StorageRuntimeState;
|
|
85
|
+
readonly manager: ManagerRuntimeContext;
|
|
86
|
+
};
|
|
87
|
+
export type StorageDehydrateContext = {
|
|
88
|
+
readonly state: StorageRuntimeState;
|
|
89
|
+
readonly manager: ManagerRuntimeContext;
|
|
90
|
+
readonly rootState: Record<string, unknown>;
|
|
91
|
+
readonly options: DehydrateOptions<MachineStore> | undefined;
|
|
92
|
+
};
|
|
93
|
+
export type StorageHydrateContext = {
|
|
94
|
+
readonly state: StorageRuntimeState;
|
|
95
|
+
readonly manager: ManagerRuntimeContext;
|
|
96
|
+
readonly machines: Readonly<Record<string, unknown>>;
|
|
97
|
+
readonly snapshot: unknown | undefined;
|
|
98
|
+
readonly baseState: Record<string, unknown>;
|
|
99
|
+
readonly strategy: HydrateStrategy;
|
|
100
|
+
readonly source: "hydrate" | "opts.snapshot";
|
|
101
|
+
readonly mode: "preview" | "commit" | "init";
|
|
102
|
+
};
|
|
103
|
+
export type ResolveIdentityContext = {
|
|
104
|
+
readonly state: StorageRuntimeState;
|
|
105
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
106
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
107
|
+
};
|
|
108
|
+
export type StorageReactionContext = {
|
|
109
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
110
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
111
|
+
readonly state: StorageRuntimeState;
|
|
112
|
+
readonly manager: ManagerRuntimeContext;
|
|
113
|
+
readonly dispatch: StorageDispatchContext;
|
|
114
|
+
};
|
|
115
|
+
export type StoragePrepareActionContext = {
|
|
116
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
117
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
118
|
+
readonly options: unknown;
|
|
119
|
+
readonly state: StorageRuntimeState;
|
|
120
|
+
readonly manager: ManagerRuntimeContext;
|
|
121
|
+
readonly dispatch: StorageDispatchContext;
|
|
122
|
+
};
|
|
123
|
+
export type StoragePrepareActionResult = PublicStoragePrepareActionResult;
|
|
124
|
+
export type StorageHydrateResult = PublicStorageHydrateResult;
|
|
125
|
+
export type StorageDehydrateResult = PublicStorageDehydrateResult<PublicStorageRuntimeExtension>;
|
|
126
|
+
export type StorageDispatchContext = {
|
|
127
|
+
readonly options: unknown;
|
|
128
|
+
readonly runtime: Map<string, unknown>;
|
|
129
|
+
readonly route: RouteConstraint;
|
|
130
|
+
readonly prevState: Record<string, unknown>;
|
|
131
|
+
nextState: Record<string, unknown>;
|
|
132
|
+
readonly skipDelivery: boolean;
|
|
133
|
+
reportError(error: unknown): void;
|
|
134
|
+
};
|
|
135
|
+
export type StorageDispatchOutcome = {
|
|
136
|
+
readonly type: "active";
|
|
137
|
+
} | {
|
|
138
|
+
readonly type: "drop";
|
|
139
|
+
readonly action: ManagerAction<AnyEvent>;
|
|
140
|
+
};
|
|
141
|
+
export type StorageDispatchLifecycleContext = {
|
|
142
|
+
readonly originalAction: ManagerAction<AnyEvent>;
|
|
143
|
+
action: ManagerAction<AnyEvent>;
|
|
144
|
+
skipDelivery: boolean;
|
|
145
|
+
route: RouteConstraint;
|
|
146
|
+
prevState: Record<string, unknown>;
|
|
147
|
+
nextState: Record<string, unknown>;
|
|
148
|
+
nextCalled: boolean;
|
|
149
|
+
outcome: StorageDispatchOutcome;
|
|
150
|
+
touched: Set<string>;
|
|
151
|
+
readonly dispatch: StorageDispatchContext;
|
|
152
|
+
};
|
|
153
|
+
export type DispatchSlot<T> = {
|
|
154
|
+
readonly key: string;
|
|
155
|
+
get(dispatch: StorageDispatchContext): T | undefined;
|
|
156
|
+
set(dispatch: StorageDispatchContext, value: T): void;
|
|
157
|
+
};
|
|
158
|
+
export declare const createDispatchSlot: <T>(key: string) => DispatchSlot<T>;
|
|
159
|
+
export type ManagerRuntimeContext<Events extends AnyEvent = AnyEvent, S extends MachineStore = MachineStore> = PublicManagerRuntimeContext<Events, S> & {
|
|
160
|
+
readonly config: S;
|
|
161
|
+
readonly options: MachineManagerOptions<any, any, any> | undefined;
|
|
162
|
+
readonly schemaVersion: number | undefined;
|
|
163
|
+
readonly routing: RoutingRuntime;
|
|
164
|
+
getState(): MachinesState<S>;
|
|
165
|
+
transition(action: ManagerAction<Events>, options?: unknown): ManagerAction<Events>;
|
|
166
|
+
onTransition(cb: (prevState: MachinesState<S>, currentState: MachinesState<S>, action: ReadonlyManagerAction<Events> | {
|
|
167
|
+
readonly type: string;
|
|
168
|
+
readonly payload?: unknown;
|
|
169
|
+
}) => void): () => void;
|
|
170
|
+
getDependencies(): Record<string, unknown>;
|
|
171
|
+
createScopedDeps(baseDeps: Record<string, unknown>, ctx: ScopedInvocationContext): Record<string, unknown>;
|
|
172
|
+
};
|
|
173
|
+
export type StorageRouteMetaDependencyKeys = readonly string[];
|
|
174
|
+
export type StorageRuntimeBase = {
|
|
175
|
+
readonly kind: string;
|
|
176
|
+
readonly routeMetaKeys?: StorageRouteMetaDependencyKeys;
|
|
177
|
+
validateTemplate(ctx: ValidateTemplateContext): void;
|
|
178
|
+
compileTemplate(ctx: CompileTemplateContext): CompiledStorageTemplate;
|
|
179
|
+
createRuntimeState(ctx: CreateRuntimeStateContext): StorageRuntimeState;
|
|
180
|
+
createPublicInitialState(ctx: CreatePublicInitialStateContext): unknown;
|
|
181
|
+
prepareAction?(ctx: StoragePrepareActionContext): StoragePrepareActionResult;
|
|
182
|
+
beforeReduce?(ctx: StorageBeforeReduceContext): StorageActionStageResult;
|
|
183
|
+
commit(ctx: StorageCommitContext): void;
|
|
184
|
+
};
|
|
185
|
+
export type TemplateStorageRuntime = StorageRuntimeBase & {
|
|
186
|
+
readonly reduceScope?: "template";
|
|
187
|
+
acceptsEvent(ctx: AcceptsEventContext): boolean;
|
|
188
|
+
reduce(ctx: StorageReduceContext): StorageReduceResult;
|
|
189
|
+
readonly reduceBucket?: never;
|
|
190
|
+
};
|
|
191
|
+
export type BucketStorageRuntime = StorageRuntimeBase & {
|
|
192
|
+
readonly reduceScope: "bucket";
|
|
193
|
+
reduceBucket(ctx: StorageReduceBucketContext): StorageReduceResult;
|
|
194
|
+
readonly acceptsEvent?: never;
|
|
195
|
+
readonly reduce?: never;
|
|
196
|
+
};
|
|
197
|
+
export type StorageEffectsRuntime = {
|
|
198
|
+
condition?(ctx: StorageConditionContext): Promise<boolean>;
|
|
199
|
+
resolveInvocations(ctx: ResolveEffectInvocationsContext): readonly StorageEffectInvocation[];
|
|
200
|
+
invoke(ctx: StorageEffectInvocationContext): void;
|
|
201
|
+
};
|
|
202
|
+
export type StorageSnapshotRuntime = {
|
|
203
|
+
dehydrate(ctx: StorageDehydrateContext): StorageDehydrateResult;
|
|
204
|
+
hydrate(ctx: StorageHydrateContext): StorageHydrateResult;
|
|
205
|
+
};
|
|
206
|
+
export type StorageIdentityRuntime = {
|
|
207
|
+
resolve(ctx: ResolveIdentityContext): RuntimeIdentity | undefined;
|
|
208
|
+
};
|
|
209
|
+
export type StorageReactionRuntime = {
|
|
210
|
+
run(ctx: StorageReactionContext): void;
|
|
211
|
+
};
|
|
212
|
+
export type StorageRuntime = (TemplateStorageRuntime | BucketStorageRuntime) & {
|
|
213
|
+
readonly effects?: StorageEffectsRuntime;
|
|
214
|
+
readonly snapshot?: StorageSnapshotRuntime;
|
|
215
|
+
readonly identity?: StorageIdentityRuntime;
|
|
216
|
+
readonly reactions?: StorageReactionRuntime;
|
|
217
|
+
};
|
|
218
|
+
export type StorageRegistry = {
|
|
219
|
+
register(kind: string, runtime: StorageRuntime, owner: string): void;
|
|
220
|
+
get(kind: string): StorageRuntime | undefined;
|
|
221
|
+
};
|
|
222
|
+
export type RuntimeStorageEntry = {
|
|
223
|
+
readonly kind: string;
|
|
224
|
+
readonly runtime: StorageRuntime;
|
|
225
|
+
};
|
|
226
|
+
export declare const compileStorageTemplates: (machines: MachineStore, machineKeys: readonly string[], storage: StorageRegistry, defaultStorageKind: string) => CompiledStorageTemplate[];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DispatchHookPhase } from "../../pluginTypes";
|
|
2
|
+
export type TransitionGuardPhase = "storage.prepareAction" | "storage.beforeReduce" | "storage.acceptsEvent" | "storage.reduce" | "storage.reduceBucket" | "storage.commit" | "storage.reactions" | "plugin.intercept" | `hook.${DispatchHookPhase}`;
|
|
3
|
+
export type GuardedCallbackRunner = <Result>(phase: TransitionGuardPhase, run: () => Result) => Result;
|
|
4
|
+
export declare const throwTransitionGuardError: (phase: TransitionGuardPhase) => never;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DispatchHookPhase } from "../../pluginTypes";
|
|
2
|
+
export type TransitionGuardPhase = "storage.prepareAction" | "storage.beforeReduce" | "storage.acceptsEvent" | "storage.reduce" | "storage.reduceBucket" | "storage.commit" | "storage.reactions" | "plugin.intercept" | `hook.${DispatchHookPhase}`;
|
|
3
|
+
export type GuardedCallbackRunner = <Result>(phase: TransitionGuardPhase, run: () => Result) => Result;
|
|
4
|
+
export declare const throwTransitionGuardError: (phase: TransitionGuardPhase) => never;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { StorageDispatchContext } from "./storage";
|
|
2
|
+
export declare const TRANSITION_TRACE_COLLECTOR_SYMBOL: unique symbol;
|
|
3
|
+
export declare const TRANSITION_TRACE_RUNTIME_KEY = "@lite-fsm/core/transition-trace";
|
|
4
|
+
export type TransitionTraceStatus = "ok" | "error";
|
|
5
|
+
export type TransitionTracePhaseMetadata = {
|
|
6
|
+
readonly runtimeKind?: string;
|
|
7
|
+
};
|
|
8
|
+
export type TransitionTracePhaseRecord = {
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly durationMs: number;
|
|
11
|
+
readonly runtimeKind?: string;
|
|
12
|
+
};
|
|
13
|
+
export type TransitionTraceCounterRecord = {
|
|
14
|
+
readonly key: string;
|
|
15
|
+
readonly value: number;
|
|
16
|
+
};
|
|
17
|
+
export type TransitionTraceRecord = {
|
|
18
|
+
readonly actionType: string | undefined;
|
|
19
|
+
readonly depth: number;
|
|
20
|
+
readonly status: TransitionTraceStatus;
|
|
21
|
+
readonly phases: readonly TransitionTracePhaseRecord[];
|
|
22
|
+
readonly counters: readonly TransitionTraceCounterRecord[];
|
|
23
|
+
};
|
|
24
|
+
export type TransitionTraceCollector = {
|
|
25
|
+
readonly records: TransitionTraceRecord[];
|
|
26
|
+
};
|
|
27
|
+
export type TransitionTraceSession = {
|
|
28
|
+
readonly depth: number;
|
|
29
|
+
now(): number;
|
|
30
|
+
record(key: string, startedAt: number, metadata?: TransitionTracePhaseMetadata): void;
|
|
31
|
+
count(key: string, value?: number): void;
|
|
32
|
+
finish(status: TransitionTraceStatus): void;
|
|
33
|
+
};
|
|
34
|
+
export declare const createTransitionTraceSession: (actionType: string | undefined) => TransitionTraceSession | undefined;
|
|
35
|
+
export type TraceSpanRunner = <T>(key: string, run: () => T) => T;
|
|
36
|
+
export declare const createTraceSpanRunner: (session: TransitionTraceSession | undefined) => TraceSpanRunner;
|
|
37
|
+
export type BucketTraceRunner = <T>(phase: string, runtimeKind: string, run: () => T) => T;
|
|
38
|
+
export declare const createBucketTraceRunner: (session: TransitionTraceSession | undefined) => BucketTraceRunner;
|
|
39
|
+
export declare const attachTransitionTraceSession: (dispatch: StorageDispatchContext, session: TransitionTraceSession | undefined) => void;
|
|
40
|
+
export declare const readTransitionTraceSession: (dispatch: StorageDispatchContext) => TransitionTraceSession | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { StorageDispatchContext } from "./storage";
|
|
2
|
+
export declare const TRANSITION_TRACE_COLLECTOR_SYMBOL: unique symbol;
|
|
3
|
+
export declare const TRANSITION_TRACE_RUNTIME_KEY = "@lite-fsm/core/transition-trace";
|
|
4
|
+
export type TransitionTraceStatus = "ok" | "error";
|
|
5
|
+
export type TransitionTracePhaseMetadata = {
|
|
6
|
+
readonly runtimeKind?: string;
|
|
7
|
+
};
|
|
8
|
+
export type TransitionTracePhaseRecord = {
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly durationMs: number;
|
|
11
|
+
readonly runtimeKind?: string;
|
|
12
|
+
};
|
|
13
|
+
export type TransitionTraceCounterRecord = {
|
|
14
|
+
readonly key: string;
|
|
15
|
+
readonly value: number;
|
|
16
|
+
};
|
|
17
|
+
export type TransitionTraceRecord = {
|
|
18
|
+
readonly actionType: string | undefined;
|
|
19
|
+
readonly depth: number;
|
|
20
|
+
readonly status: TransitionTraceStatus;
|
|
21
|
+
readonly phases: readonly TransitionTracePhaseRecord[];
|
|
22
|
+
readonly counters: readonly TransitionTraceCounterRecord[];
|
|
23
|
+
};
|
|
24
|
+
export type TransitionTraceCollector = {
|
|
25
|
+
readonly records: TransitionTraceRecord[];
|
|
26
|
+
};
|
|
27
|
+
export type TransitionTraceSession = {
|
|
28
|
+
readonly depth: number;
|
|
29
|
+
now(): number;
|
|
30
|
+
record(key: string, startedAt: number, metadata?: TransitionTracePhaseMetadata): void;
|
|
31
|
+
count(key: string, value?: number): void;
|
|
32
|
+
finish(status: TransitionTraceStatus): void;
|
|
33
|
+
};
|
|
34
|
+
export declare const createTransitionTraceSession: (actionType: string | undefined) => TransitionTraceSession | undefined;
|
|
35
|
+
export type TraceSpanRunner = <T>(key: string, run: () => T) => T;
|
|
36
|
+
export declare const createTraceSpanRunner: (session: TransitionTraceSession | undefined) => TraceSpanRunner;
|
|
37
|
+
export type BucketTraceRunner = <T>(phase: string, runtimeKind: string, run: () => T) => T;
|
|
38
|
+
export declare const createBucketTraceRunner: (session: TransitionTraceSession | undefined) => BucketTraceRunner;
|
|
39
|
+
export declare const attachTransitionTraceSession: (dispatch: StorageDispatchContext, session: TransitionTraceSession | undefined) => void;
|
|
40
|
+
export declare const readTransitionTraceSession: (dispatch: StorageDispatchContext) => TransitionTraceSession | undefined;
|
package/dist/sidecar.d.cts
CHANGED
|
@@ -15,7 +15,7 @@ export type ReplacementReconcilePlan = {
|
|
|
15
15
|
nextCounters: Counters;
|
|
16
16
|
canonicalActorRecords: Map<string, ActorRecord>;
|
|
17
17
|
actorsToCleanup: ActorRuntime[];
|
|
18
|
-
touchedTemplateKeys: string[];
|
|
18
|
+
touchedTemplateKeys: readonly string[];
|
|
19
19
|
};
|
|
20
20
|
export type SidecarValidationDeps = {
|
|
21
21
|
actorTemplateKeys: readonly string[];
|
|
@@ -34,7 +34,7 @@ type IndexBundle = {
|
|
|
34
34
|
export declare const addActorToGroupIndexes: (indexes: IndexBundle, actor: ActorRuntime) => void;
|
|
35
35
|
export declare const removeActorFromGroupIndexes: (sidecar: SidecarState, actor: ActorRuntime) => void;
|
|
36
36
|
export declare const cleanupDisposedActor: (actor: ActorRuntime) => void;
|
|
37
|
-
export declare const buildReplacementReconcilePlan: (sidecar: SidecarState, deps: SidecarValidationDeps, changedTemplateKeys: string[], nextRoot: RootStateView) => ReplacementReconcilePlan;
|
|
37
|
+
export declare const buildReplacementReconcilePlan: (sidecar: SidecarState, deps: SidecarValidationDeps, changedTemplateKeys: readonly string[], nextRoot: RootStateView) => ReplacementReconcilePlan;
|
|
38
38
|
export declare const canonicalizeEmptyActorRecords: <S extends RootStateView>(state: S, templateKeys: Iterable<string>) => S;
|
|
39
39
|
export declare const commitDispatchSidecar: <S extends RootStateView>(sidecar: SidecarState, ctx: DispatchContext, nextState: S) => S;
|
|
40
40
|
export declare const commitReplacementSidecar: <S extends RootStateView>(sidecar: SidecarState, plan: ReplacementReconcilePlan, nextState: S) => S;
|
package/dist/sidecar.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type ReplacementReconcilePlan = {
|
|
|
15
15
|
nextCounters: Counters;
|
|
16
16
|
canonicalActorRecords: Map<string, ActorRecord>;
|
|
17
17
|
actorsToCleanup: ActorRuntime[];
|
|
18
|
-
touchedTemplateKeys: string[];
|
|
18
|
+
touchedTemplateKeys: readonly string[];
|
|
19
19
|
};
|
|
20
20
|
export type SidecarValidationDeps = {
|
|
21
21
|
actorTemplateKeys: readonly string[];
|
|
@@ -34,7 +34,7 @@ type IndexBundle = {
|
|
|
34
34
|
export declare const addActorToGroupIndexes: (indexes: IndexBundle, actor: ActorRuntime) => void;
|
|
35
35
|
export declare const removeActorFromGroupIndexes: (sidecar: SidecarState, actor: ActorRuntime) => void;
|
|
36
36
|
export declare const cleanupDisposedActor: (actor: ActorRuntime) => void;
|
|
37
|
-
export declare const buildReplacementReconcilePlan: (sidecar: SidecarState, deps: SidecarValidationDeps, changedTemplateKeys: string[], nextRoot: RootStateView) => ReplacementReconcilePlan;
|
|
37
|
+
export declare const buildReplacementReconcilePlan: (sidecar: SidecarState, deps: SidecarValidationDeps, changedTemplateKeys: readonly string[], nextRoot: RootStateView) => ReplacementReconcilePlan;
|
|
38
38
|
export declare const canonicalizeEmptyActorRecords: <S extends RootStateView>(state: S, templateKeys: Iterable<string>) => S;
|
|
39
39
|
export declare const commitDispatchSidecar: <S extends RootStateView>(sidecar: SidecarState, ctx: DispatchContext, nextState: S) => S;
|
|
40
40
|
export declare const commitReplacementSidecar: <S extends RootStateView>(sidecar: SidecarState, plan: ReplacementReconcilePlan, nextState: S) => S;
|