@lite-fsm/core 2.0.5 → 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 +0 -6
- package/dist/actor.d.ts +0 -6
- 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 +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1 -1
- package/dist/interfaces.d.cts +40 -19
- package/dist/interfaces.d.ts +40 -19
- 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/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/types.d.cts
CHANGED
|
@@ -15,9 +15,14 @@ export type FSMEventMeta = {
|
|
|
15
15
|
senderGroupId?: string;
|
|
16
16
|
senderGroupTag?: string;
|
|
17
17
|
};
|
|
18
|
-
export type
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
export type CoreActionMeta = FSMEventMeta;
|
|
19
|
+
export type ManagerAction<P extends AnyEvent, Meta extends object = CoreActionMeta> = P & {
|
|
20
|
+
meta?: Meta;
|
|
21
|
+
};
|
|
22
|
+
type DeepReadonly<Value> = Value extends (...args: any[]) => unknown ? Value : Value extends object ? {
|
|
23
|
+
readonly [Key in keyof Value]: DeepReadonly<Value[Key]>;
|
|
24
|
+
} : Value;
|
|
25
|
+
export type ReadonlyManagerAction<Events extends AnyEvent, Meta extends object = CoreActionMeta> = DeepReadonly<ManagerAction<Events, Meta>>;
|
|
21
26
|
export type ActorMeta = {
|
|
22
27
|
actorId: string;
|
|
23
28
|
groupId: string;
|
|
@@ -99,14 +104,14 @@ export type HydrateAction<S extends MachineStore> = {
|
|
|
99
104
|
};
|
|
100
105
|
};
|
|
101
106
|
export type ManagerCommitAction<S extends MachineStore, P extends AnyEvent = AnyEvent> = P | HydrateAction<S>;
|
|
102
|
-
export type MiddlewareApi<S, P extends AnyEvent = AnyEvent> = {
|
|
107
|
+
export type MiddlewareApi<S, P extends AnyEvent = AnyEvent, Meta extends object = CoreActionMeta> = {
|
|
103
108
|
getState: () => S;
|
|
104
|
-
transition: (action: ManagerAction<P>) => ManagerAction<P>;
|
|
105
|
-
replaceReducer: (cb: (reducer: Reducer<S, ManagerAction<P>>) => Reducer<S, ManagerAction<P>>) => void;
|
|
109
|
+
transition: (action: ManagerAction<P, Meta>) => ManagerAction<P, Meta>;
|
|
110
|
+
replaceReducer: (cb: (reducer: Reducer<S, ManagerAction<P, Meta>>) => Reducer<S, ManagerAction<P, Meta>>) => void;
|
|
106
111
|
onTransition: (cb: (prevState: S, currentState: S, action: ManagerCommitAction<MachineStore, AnyEvent>) => void) => () => void;
|
|
107
|
-
condition: (predicate: (a: ManagerAction<P>) => boolean) => Promise<boolean>;
|
|
112
|
+
condition: (predicate: (a: ManagerAction<P, Meta>) => boolean) => Promise<boolean>;
|
|
108
113
|
};
|
|
109
|
-
export type Middleware<S = unknown, P extends AnyEvent = AnyEvent> = (api: MiddlewareApi<S, P>) => (next: (action: ManagerAction<P>) => ManagerAction<P>) => (action: ManagerAction<P>) => ManagerAction<P>;
|
|
114
|
+
export type Middleware<S = unknown, P extends AnyEvent = AnyEvent, Meta extends object = CoreActionMeta> = (api: MiddlewareApi<S, P, Meta>) => (next: (action: ManagerAction<P, Meta>) => ManagerAction<P, Meta>) => (action: ManagerAction<P, Meta>) => ManagerAction<P, Meta>;
|
|
110
115
|
export type GenericMiddleware = <S, P extends AnyEvent>(api: MiddlewareApi<S, P>) => (next: (action: P) => P) => (action: P) => P;
|
|
111
116
|
export type VoidReducerMiddleware = GenericMiddleware & {
|
|
112
117
|
__liteFsmAllowVoidReducer: true;
|
|
@@ -148,7 +153,9 @@ export type ActorDefaultDeps<N extends SType, C extends object, P extends AnyEve
|
|
|
148
153
|
};
|
|
149
154
|
export type MachineEffect<N extends SType = WILDCARD, C extends object = Record<string, never>, P extends AnyEvent = AnyEvent, D extends AnyRecord = {}> = (deps: D & (HasLiteralInit<C> extends true ? ActorDefaultDeps<N, C, P> : DefaultDeps<N, C, P>)) => Promise<void> | void;
|
|
150
155
|
export type EffectStateName<C extends object> = HasLiteralInit<C> extends true ? ActorPublicState<C> | WILDCARD : StateName<C> | WILDCARD;
|
|
156
|
+
type CoreStorageKind = "instance";
|
|
151
157
|
type BaseMachineConfig<C extends object, T extends AnyRecord, P extends AnyEvent, D extends AnyRecord> = {
|
|
158
|
+
storage?: CoreStorageKind;
|
|
152
159
|
config: C;
|
|
153
160
|
initialState: StateName<C>;
|
|
154
161
|
initialContext: T;
|
|
@@ -177,6 +184,7 @@ type ActorPersistenceConfig<C extends object, T extends AnyRecord, Snapshot> = {
|
|
|
177
184
|
});
|
|
178
185
|
export type MachineConfig<C extends object, T extends AnyRecord, P extends AnyEvent, D extends AnyRecord = {}, Snapshot = HasLiteralInit<C> extends true ? DefaultActorSnapshot<C, T> : StateType<C, T>> = BaseMachineConfig<C, T, P, D> & (HasLiteralInit<C> extends true ? ActorPersistenceConfig<C, T, Snapshot> : DomainPersistenceConfig<C, T, Snapshot>);
|
|
179
186
|
type AnyMachineConfig = {
|
|
187
|
+
storage?: unknown;
|
|
180
188
|
config: object;
|
|
181
189
|
initialState: string;
|
|
182
190
|
initialContext: AnyRecord;
|
|
@@ -192,13 +200,25 @@ export type IsActorTemplate<M> = M extends {
|
|
|
192
200
|
config: infer C extends object;
|
|
193
201
|
} ? HasLiteralInit<C> : false;
|
|
194
202
|
type ActorRuntimeRecord<C extends object, T extends AnyRecord> = Record<string, PublicActorSlice<C, T>>;
|
|
195
|
-
export type
|
|
203
|
+
export type MachineRuntimeMetadata<M> = M extends {
|
|
204
|
+
readonly __liteFsmRuntime?: infer Metadata;
|
|
205
|
+
} ? NonNullable<Metadata> : {};
|
|
206
|
+
export type MachineResultMetadata<M> = MachineRuntimeMetadata<M> extends {
|
|
207
|
+
readonly resultMetadata: infer Metadata;
|
|
208
|
+
} ? Metadata : {};
|
|
209
|
+
type MachinePublicStateOverride<M> = MachineRuntimeMetadata<M> extends {
|
|
210
|
+
readonly publicState: infer PublicState;
|
|
211
|
+
} ? PublicState : never;
|
|
212
|
+
type DefaultMachineSliceState<M> = M extends {
|
|
196
213
|
config: infer C extends object;
|
|
197
214
|
initialContext: infer T extends AnyRecord;
|
|
198
215
|
} ? IsActorTemplate<M> extends true ? ActorRuntimeRecord<C, T> : {
|
|
199
216
|
state: StateName<C>;
|
|
200
217
|
context: T;
|
|
201
218
|
} : never;
|
|
219
|
+
export type MachineSliceState<M> = [
|
|
220
|
+
MachinePublicStateOverride<M>
|
|
221
|
+
] extends [never] ? DefaultMachineSliceState<M> : MachinePublicStateOverride<M>;
|
|
202
222
|
export type MachinesState<S extends MachineStore> = {
|
|
203
223
|
[key in keyof S]: MachineSliceState<S[key]>;
|
|
204
224
|
};
|
|
@@ -254,12 +274,14 @@ export type MachineManagerSnapshot<S extends MachineStore> = {
|
|
|
254
274
|
machines: Partial<{
|
|
255
275
|
[key in SnapshotMachineKey<S>]: SnapshotForMachine<S[key]>;
|
|
256
276
|
}>;
|
|
277
|
+
storage?: Record<string, unknown>;
|
|
257
278
|
};
|
|
258
279
|
export type MachineManagerDehydratedSnapshot<S extends MachineStore, K extends SnapshotMachineKey<S> = SnapshotMachineKey<S>> = {
|
|
259
280
|
schemaVersion?: number;
|
|
260
281
|
machines: {
|
|
261
282
|
[key in K]: SnapshotForMachine<S[key]>;
|
|
262
283
|
};
|
|
284
|
+
storage?: Record<string, unknown>;
|
|
263
285
|
};
|
|
264
286
|
export type MachineManagerDehydrateResult<S extends MachineStore, Keys extends ReadonlyArray<SnapshotMachineKey<S>>> = number extends Keys["length"] ? MachineManagerSnapshot<S> : MachineManagerDehydratedSnapshot<S, Keys[number]>;
|
|
265
287
|
export type MachineManagerRuntimeSnapshot<S extends MachineStore> = {
|
|
@@ -270,17 +292,20 @@ export type MachineManagerRuntimeSnapshot<S extends MachineStore> = {
|
|
|
270
292
|
};
|
|
271
293
|
export type DehydrateOptions<S extends MachineStore, K extends SnapshotMachineKey<S> = SnapshotMachineKey<S>> = {
|
|
272
294
|
machines?: ReadonlyArray<K>;
|
|
295
|
+
storage?: readonly string[];
|
|
273
296
|
};
|
|
274
297
|
export type MachineManagerDehydrateFn<S extends MachineStore> = {
|
|
275
298
|
(opts?: {
|
|
276
299
|
machines?: undefined;
|
|
300
|
+
storage?: readonly string[];
|
|
277
301
|
}): MachineManagerDehydratedSnapshot<S>;
|
|
278
302
|
<const Keys extends ReadonlyArray<SnapshotMachineKey<S>>>(opts: {
|
|
279
303
|
machines: Keys;
|
|
304
|
+
storage?: readonly string[];
|
|
280
305
|
}): MachineManagerDehydrateResult<S, Keys>;
|
|
281
306
|
(opts: DehydrateOptions<S>): MachineManagerSnapshot<S>;
|
|
282
307
|
};
|
|
283
|
-
export type TransitionSubscriber<S extends MachineStore, P extends AnyEvent = AnyEvent> = (prevState: MachinesState<S>, currentState: MachinesState<S>, action: ManagerCommitAction<S, ManagerAction<P>>) => void;
|
|
308
|
+
export type TransitionSubscriber<S extends MachineStore, P extends AnyEvent = AnyEvent, Meta extends object = CoreActionMeta> = (prevState: MachinesState<S>, currentState: MachinesState<S>, action: ManagerCommitAction<S, ManagerAction<P, Meta>>) => void;
|
|
284
309
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
285
310
|
type NoPayload = {
|
|
286
311
|
readonly __liteFsmNoPayload: never;
|