@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,102 @@
|
|
|
1
|
+
import type { AnyEvent, MachinesState, MachineStore, ManagerAction, ReadonlyManagerAction } from "./types";
|
|
2
|
+
export type RouteResolverResult = string | readonly string[];
|
|
3
|
+
export type RouteResolverContext<Key extends string = string> = {
|
|
4
|
+
readonly key: Key;
|
|
5
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
6
|
+
readonly meta: Readonly<Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
export type RouteResolver<Key extends string = string> = (value: unknown, ctx: RouteResolverContext<Key>) => RouteResolverResult;
|
|
9
|
+
export type RoutingRegistry = {
|
|
10
|
+
registerRouteMeta<Key extends string>(key: Key, resolver: RouteResolver<Key>, owner?: string): void;
|
|
11
|
+
};
|
|
12
|
+
export type DispatchContext = {
|
|
13
|
+
readonly options: unknown;
|
|
14
|
+
readonly runtime: Map<string, unknown>;
|
|
15
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
16
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
17
|
+
readonly skipDelivery: boolean;
|
|
18
|
+
reportError(error: unknown): void;
|
|
19
|
+
};
|
|
20
|
+
export type ActionInterceptorResult = void | {
|
|
21
|
+
readonly action?: ManagerAction<AnyEvent>;
|
|
22
|
+
readonly skipDelivery?: boolean;
|
|
23
|
+
readonly stopInterceptors?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export type ActionInterceptor = (ctx: DispatchContext) => ActionInterceptorResult;
|
|
26
|
+
export type DispatchHook = (ctx: DispatchContext) => void;
|
|
27
|
+
export declare const DISPATCH_HOOK_PHASES: readonly ["beforeReduce", "afterReduce", "beforeCommit", "beforeSubscribers", "beforeEffects", "afterEffects"];
|
|
28
|
+
export type DispatchHookPhase = (typeof DISPATCH_HOOK_PHASES)[number];
|
|
29
|
+
export type ScopedInvocationPhase = "effect" | "reaction";
|
|
30
|
+
export type ScopedInvocationSource = {
|
|
31
|
+
readonly storage: string;
|
|
32
|
+
readonly template: string;
|
|
33
|
+
};
|
|
34
|
+
export type ScopedInvocationIndices = Readonly<Record<string, unknown>>;
|
|
35
|
+
export type ScopedInvocationContext = {
|
|
36
|
+
readonly source: ScopedInvocationSource;
|
|
37
|
+
readonly event: ReadonlyManagerAction<AnyEvent>;
|
|
38
|
+
readonly indices: ScopedInvocationIndices;
|
|
39
|
+
readonly phase: ScopedInvocationPhase;
|
|
40
|
+
readonly transition: (action: ManagerAction<AnyEvent>) => ManagerAction<AnyEvent>;
|
|
41
|
+
};
|
|
42
|
+
export declare const managerExtensionTypeMarker: unique symbol;
|
|
43
|
+
export type ManagerRuntimeContext<Events extends AnyEvent = AnyEvent, S extends MachineStore = MachineStore> = {
|
|
44
|
+
readonly config: S;
|
|
45
|
+
readonly options: unknown;
|
|
46
|
+
readonly schemaVersion: number | undefined;
|
|
47
|
+
getState(): MachinesState<S>;
|
|
48
|
+
transition(action: ManagerAction<Events>, options?: unknown): ManagerAction<Events>;
|
|
49
|
+
onTransition(cb: (prevState: MachinesState<S>, currentState: MachinesState<S>, action: ReadonlyManagerAction<Events> | {
|
|
50
|
+
readonly type: string;
|
|
51
|
+
readonly payload?: unknown;
|
|
52
|
+
}) => void): () => void;
|
|
53
|
+
getDependencies(): Record<string, unknown>;
|
|
54
|
+
};
|
|
55
|
+
export type ManagerExtensionFactory<Events extends AnyEvent = AnyEvent, Value = unknown, S extends MachineStore = MachineStore> = (ctx: ManagerRuntimeContext<Events, S>) => Value;
|
|
56
|
+
export type ManagerExtensionTypeLambda = {
|
|
57
|
+
readonly type: unknown;
|
|
58
|
+
};
|
|
59
|
+
export type ManagerExtensionType<Lambda extends ManagerExtensionTypeLambda> = {
|
|
60
|
+
readonly [managerExtensionTypeMarker]?: Lambda;
|
|
61
|
+
};
|
|
62
|
+
export type NormalizedStorageEntry = {
|
|
63
|
+
readonly owner: string;
|
|
64
|
+
readonly kind: string;
|
|
65
|
+
readonly value: unknown;
|
|
66
|
+
};
|
|
67
|
+
export type NormalizedRouteMetaEntry = {
|
|
68
|
+
readonly owner: string;
|
|
69
|
+
readonly key: string;
|
|
70
|
+
readonly resolver: RouteResolver;
|
|
71
|
+
};
|
|
72
|
+
export type NormalizedScopedFactory = (ctx: ScopedInvocationContext) => unknown;
|
|
73
|
+
export type NormalizedScopedDepsEntry = {
|
|
74
|
+
readonly owner: string;
|
|
75
|
+
readonly key: string;
|
|
76
|
+
readonly factory: NormalizedScopedFactory;
|
|
77
|
+
};
|
|
78
|
+
export type NormalizedScopedTransitionEntry = {
|
|
79
|
+
readonly owner: string;
|
|
80
|
+
readonly key: string;
|
|
81
|
+
readonly factory: NormalizedScopedFactory;
|
|
82
|
+
};
|
|
83
|
+
export type NormalizedManagerEntry = {
|
|
84
|
+
readonly owner: string;
|
|
85
|
+
readonly key: string;
|
|
86
|
+
readonly factory: ManagerExtensionFactory;
|
|
87
|
+
};
|
|
88
|
+
export type NormalizedDispatchHook = {
|
|
89
|
+
readonly owner: string;
|
|
90
|
+
readonly phase: DispatchHookPhase;
|
|
91
|
+
readonly hook: DispatchHook;
|
|
92
|
+
};
|
|
93
|
+
export type NormalizedPlugin = {
|
|
94
|
+
readonly name: string;
|
|
95
|
+
readonly storage: readonly NormalizedStorageEntry[];
|
|
96
|
+
readonly routeMeta: readonly NormalizedRouteMetaEntry[];
|
|
97
|
+
readonly scopedDeps: readonly NormalizedScopedDepsEntry[];
|
|
98
|
+
readonly scopedTransition: readonly NormalizedScopedTransitionEntry[];
|
|
99
|
+
readonly manager: readonly NormalizedManagerEntry[];
|
|
100
|
+
readonly intercept?: ActionInterceptor;
|
|
101
|
+
readonly hooks: Partial<Record<DispatchHookPhase, NormalizedDispatchHook>>;
|
|
102
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { AnyEvent, MachinesState, MachineStore, ManagerAction, ReadonlyManagerAction } from "./types";
|
|
2
|
+
export type RouteResolverResult = string | readonly string[];
|
|
3
|
+
export type RouteResolverContext<Key extends string = string> = {
|
|
4
|
+
readonly key: Key;
|
|
5
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
6
|
+
readonly meta: Readonly<Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
export type RouteResolver<Key extends string = string> = (value: unknown, ctx: RouteResolverContext<Key>) => RouteResolverResult;
|
|
9
|
+
export type RoutingRegistry = {
|
|
10
|
+
registerRouteMeta<Key extends string>(key: Key, resolver: RouteResolver<Key>, owner?: string): void;
|
|
11
|
+
};
|
|
12
|
+
export type DispatchContext = {
|
|
13
|
+
readonly options: unknown;
|
|
14
|
+
readonly runtime: Map<string, unknown>;
|
|
15
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
16
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
17
|
+
readonly skipDelivery: boolean;
|
|
18
|
+
reportError(error: unknown): void;
|
|
19
|
+
};
|
|
20
|
+
export type ActionInterceptorResult = void | {
|
|
21
|
+
readonly action?: ManagerAction<AnyEvent>;
|
|
22
|
+
readonly skipDelivery?: boolean;
|
|
23
|
+
readonly stopInterceptors?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export type ActionInterceptor = (ctx: DispatchContext) => ActionInterceptorResult;
|
|
26
|
+
export type DispatchHook = (ctx: DispatchContext) => void;
|
|
27
|
+
export declare const DISPATCH_HOOK_PHASES: readonly ["beforeReduce", "afterReduce", "beforeCommit", "beforeSubscribers", "beforeEffects", "afterEffects"];
|
|
28
|
+
export type DispatchHookPhase = (typeof DISPATCH_HOOK_PHASES)[number];
|
|
29
|
+
export type ScopedInvocationPhase = "effect" | "reaction";
|
|
30
|
+
export type ScopedInvocationSource = {
|
|
31
|
+
readonly storage: string;
|
|
32
|
+
readonly template: string;
|
|
33
|
+
};
|
|
34
|
+
export type ScopedInvocationIndices = Readonly<Record<string, unknown>>;
|
|
35
|
+
export type ScopedInvocationContext = {
|
|
36
|
+
readonly source: ScopedInvocationSource;
|
|
37
|
+
readonly event: ReadonlyManagerAction<AnyEvent>;
|
|
38
|
+
readonly indices: ScopedInvocationIndices;
|
|
39
|
+
readonly phase: ScopedInvocationPhase;
|
|
40
|
+
readonly transition: (action: ManagerAction<AnyEvent>) => ManagerAction<AnyEvent>;
|
|
41
|
+
};
|
|
42
|
+
export declare const managerExtensionTypeMarker: unique symbol;
|
|
43
|
+
export type ManagerRuntimeContext<Events extends AnyEvent = AnyEvent, S extends MachineStore = MachineStore> = {
|
|
44
|
+
readonly config: S;
|
|
45
|
+
readonly options: unknown;
|
|
46
|
+
readonly schemaVersion: number | undefined;
|
|
47
|
+
getState(): MachinesState<S>;
|
|
48
|
+
transition(action: ManagerAction<Events>, options?: unknown): ManagerAction<Events>;
|
|
49
|
+
onTransition(cb: (prevState: MachinesState<S>, currentState: MachinesState<S>, action: ReadonlyManagerAction<Events> | {
|
|
50
|
+
readonly type: string;
|
|
51
|
+
readonly payload?: unknown;
|
|
52
|
+
}) => void): () => void;
|
|
53
|
+
getDependencies(): Record<string, unknown>;
|
|
54
|
+
};
|
|
55
|
+
export type ManagerExtensionFactory<Events extends AnyEvent = AnyEvent, Value = unknown, S extends MachineStore = MachineStore> = (ctx: ManagerRuntimeContext<Events, S>) => Value;
|
|
56
|
+
export type ManagerExtensionTypeLambda = {
|
|
57
|
+
readonly type: unknown;
|
|
58
|
+
};
|
|
59
|
+
export type ManagerExtensionType<Lambda extends ManagerExtensionTypeLambda> = {
|
|
60
|
+
readonly [managerExtensionTypeMarker]?: Lambda;
|
|
61
|
+
};
|
|
62
|
+
export type NormalizedStorageEntry = {
|
|
63
|
+
readonly owner: string;
|
|
64
|
+
readonly kind: string;
|
|
65
|
+
readonly value: unknown;
|
|
66
|
+
};
|
|
67
|
+
export type NormalizedRouteMetaEntry = {
|
|
68
|
+
readonly owner: string;
|
|
69
|
+
readonly key: string;
|
|
70
|
+
readonly resolver: RouteResolver;
|
|
71
|
+
};
|
|
72
|
+
export type NormalizedScopedFactory = (ctx: ScopedInvocationContext) => unknown;
|
|
73
|
+
export type NormalizedScopedDepsEntry = {
|
|
74
|
+
readonly owner: string;
|
|
75
|
+
readonly key: string;
|
|
76
|
+
readonly factory: NormalizedScopedFactory;
|
|
77
|
+
};
|
|
78
|
+
export type NormalizedScopedTransitionEntry = {
|
|
79
|
+
readonly owner: string;
|
|
80
|
+
readonly key: string;
|
|
81
|
+
readonly factory: NormalizedScopedFactory;
|
|
82
|
+
};
|
|
83
|
+
export type NormalizedManagerEntry = {
|
|
84
|
+
readonly owner: string;
|
|
85
|
+
readonly key: string;
|
|
86
|
+
readonly factory: ManagerExtensionFactory;
|
|
87
|
+
};
|
|
88
|
+
export type NormalizedDispatchHook = {
|
|
89
|
+
readonly owner: string;
|
|
90
|
+
readonly phase: DispatchHookPhase;
|
|
91
|
+
readonly hook: DispatchHook;
|
|
92
|
+
};
|
|
93
|
+
export type NormalizedPlugin = {
|
|
94
|
+
readonly name: string;
|
|
95
|
+
readonly storage: readonly NormalizedStorageEntry[];
|
|
96
|
+
readonly routeMeta: readonly NormalizedRouteMetaEntry[];
|
|
97
|
+
readonly scopedDeps: readonly NormalizedScopedDepsEntry[];
|
|
98
|
+
readonly scopedTransition: readonly NormalizedScopedTransitionEntry[];
|
|
99
|
+
readonly manager: readonly NormalizedManagerEntry[];
|
|
100
|
+
readonly intercept?: ActionInterceptor;
|
|
101
|
+
readonly hooks: Partial<Record<DispatchHookPhase, NormalizedDispatchHook>>;
|
|
102
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ActorIdentity } from "../../actor";
|
|
2
|
+
import { type DispatchContext } from "../../dispatchContext";
|
|
3
|
+
import type { MachineEvents } from "../../interfaces";
|
|
4
|
+
import type { AnyEvent, MachineManagerSnapshot, MachinesState, MachineStore, ManagerAction } from "../../types";
|
|
5
|
+
import { type CompiledStorageTemplate, type CreateRuntimeStateContext, type ResolveEffectInvocationsContext, type ResolveIdentityContext, type StorageActionStageResult, type StorageBeforeReduceContext, type StorageCommitContext, type StorageDehydrateContext, type StorageEffectInvocationContext, type StorageHydrateContext, type StorageHydrateResult, type StoragePrepareActionContext, type StoragePrepareActionResult, type StorageReduceBucketContext, type StorageReduceResult } from "../kernel/storage";
|
|
6
|
+
type RootState<S extends MachineStore> = MachinesState<S>;
|
|
7
|
+
type Action<P extends AnyEvent> = ManagerAction<P>;
|
|
8
|
+
type InstanceEffectInvocation<S extends MachineStore, P extends AnyEvent> = {
|
|
9
|
+
readonly prevState: RootState<S>;
|
|
10
|
+
readonly currentState: RootState<S>;
|
|
11
|
+
readonly action: Action<P>;
|
|
12
|
+
readonly targets: DispatchContext<S, P>["effectsTargets"];
|
|
13
|
+
};
|
|
14
|
+
type InstanceRuntimeState<S extends MachineStore, P extends AnyEvent> = {
|
|
15
|
+
readonly initialState: RootState<S>;
|
|
16
|
+
prepareAction(ctx: StoragePrepareActionContext): StoragePrepareActionResult;
|
|
17
|
+
beforeReduce(ctx: StorageBeforeReduceContext): StorageActionStageResult;
|
|
18
|
+
reduceBucket(ctx: StorageReduceBucketContext): StorageReduceResult;
|
|
19
|
+
commit(ctx: StorageCommitContext): void;
|
|
20
|
+
condition(predicate: (action: Action<P>) => boolean): Promise<boolean>;
|
|
21
|
+
resolveEffectInvocations(ctx: ResolveEffectInvocationsContext): InstanceEffectInvocation<S, P>[];
|
|
22
|
+
invokeEffect(ctx: StorageEffectInvocationContext): void;
|
|
23
|
+
dehydrate(ctx: StorageDehydrateContext): MachineManagerSnapshot<S>;
|
|
24
|
+
hydrate(ctx: StorageHydrateContext): StorageHydrateResult;
|
|
25
|
+
resolveIdentity(ctx: ResolveIdentityContext): ActorIdentity | undefined;
|
|
26
|
+
};
|
|
27
|
+
export declare const validateInstanceTemplate: ({ key, machine }: {
|
|
28
|
+
key: string;
|
|
29
|
+
machine: MachineStore[string];
|
|
30
|
+
}) => void;
|
|
31
|
+
export declare const compileInstanceTemplate: ({ key, storageKind, }: {
|
|
32
|
+
key: string;
|
|
33
|
+
storageKind: string;
|
|
34
|
+
}) => CompiledStorageTemplate;
|
|
35
|
+
export declare const createInstanceRuntimeState: <S extends MachineStore, P extends AnyEvent = MachineEvents<S>>({ manager, templates }: CreateRuntimeStateContext) => InstanceRuntimeState<S, P>;
|
|
36
|
+
export declare const asInstanceRuntimeState: <S extends MachineStore, P extends AnyEvent>(value: unknown) => InstanceRuntimeState<S, P>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ActorIdentity } from "../../actor";
|
|
2
|
+
import { type DispatchContext } from "../../dispatchContext";
|
|
3
|
+
import type { MachineEvents } from "../../interfaces";
|
|
4
|
+
import type { AnyEvent, MachineManagerSnapshot, MachinesState, MachineStore, ManagerAction } from "../../types";
|
|
5
|
+
import { type CompiledStorageTemplate, type CreateRuntimeStateContext, type ResolveEffectInvocationsContext, type ResolveIdentityContext, type StorageActionStageResult, type StorageBeforeReduceContext, type StorageCommitContext, type StorageDehydrateContext, type StorageEffectInvocationContext, type StorageHydrateContext, type StorageHydrateResult, type StoragePrepareActionContext, type StoragePrepareActionResult, type StorageReduceBucketContext, type StorageReduceResult } from "../kernel/storage";
|
|
6
|
+
type RootState<S extends MachineStore> = MachinesState<S>;
|
|
7
|
+
type Action<P extends AnyEvent> = ManagerAction<P>;
|
|
8
|
+
type InstanceEffectInvocation<S extends MachineStore, P extends AnyEvent> = {
|
|
9
|
+
readonly prevState: RootState<S>;
|
|
10
|
+
readonly currentState: RootState<S>;
|
|
11
|
+
readonly action: Action<P>;
|
|
12
|
+
readonly targets: DispatchContext<S, P>["effectsTargets"];
|
|
13
|
+
};
|
|
14
|
+
type InstanceRuntimeState<S extends MachineStore, P extends AnyEvent> = {
|
|
15
|
+
readonly initialState: RootState<S>;
|
|
16
|
+
prepareAction(ctx: StoragePrepareActionContext): StoragePrepareActionResult;
|
|
17
|
+
beforeReduce(ctx: StorageBeforeReduceContext): StorageActionStageResult;
|
|
18
|
+
reduceBucket(ctx: StorageReduceBucketContext): StorageReduceResult;
|
|
19
|
+
commit(ctx: StorageCommitContext): void;
|
|
20
|
+
condition(predicate: (action: Action<P>) => boolean): Promise<boolean>;
|
|
21
|
+
resolveEffectInvocations(ctx: ResolveEffectInvocationsContext): InstanceEffectInvocation<S, P>[];
|
|
22
|
+
invokeEffect(ctx: StorageEffectInvocationContext): void;
|
|
23
|
+
dehydrate(ctx: StorageDehydrateContext): MachineManagerSnapshot<S>;
|
|
24
|
+
hydrate(ctx: StorageHydrateContext): StorageHydrateResult;
|
|
25
|
+
resolveIdentity(ctx: ResolveIdentityContext): ActorIdentity | undefined;
|
|
26
|
+
};
|
|
27
|
+
export declare const validateInstanceTemplate: ({ key, machine }: {
|
|
28
|
+
key: string;
|
|
29
|
+
machine: MachineStore[string];
|
|
30
|
+
}) => void;
|
|
31
|
+
export declare const compileInstanceTemplate: ({ key, storageKind, }: {
|
|
32
|
+
key: string;
|
|
33
|
+
storageKind: string;
|
|
34
|
+
}) => CompiledStorageTemplate;
|
|
35
|
+
export declare const createInstanceRuntimeState: <S extends MachineStore, P extends AnyEvent = MachineEvents<S>>({ manager, templates }: CreateRuntimeStateContext) => InstanceRuntimeState<S, P>;
|
|
36
|
+
export declare const asInstanceRuntimeState: <S extends MachineStore, P extends AnyEvent>(value: unknown) => InstanceRuntimeState<S, P>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AnyEvent, MachinesState, MachineStore, ManagerAction } from "../../types";
|
|
2
|
+
import type { RuntimeBucket } from "./snapshot";
|
|
3
|
+
import { type ManagerRuntimeContext, type StorageDispatchContext, type StorageDispatchLifecycleContext } from "./storage";
|
|
4
|
+
import type { GuardedCallbackRunner } from "./transitionGuard";
|
|
5
|
+
type Action = ManagerAction<AnyEvent>;
|
|
6
|
+
type ActionStageOutcome = {
|
|
7
|
+
readonly type: "continue";
|
|
8
|
+
readonly action: Action;
|
|
9
|
+
} | {
|
|
10
|
+
readonly type: "drop";
|
|
11
|
+
};
|
|
12
|
+
export type BucketRuntime<S extends MachineStore> = {
|
|
13
|
+
prepareAction(action: Action, options: unknown, dispatch: StorageDispatchLifecycleContext): ActionStageOutcome;
|
|
14
|
+
beforeReduce(action: Action, dispatch: StorageDispatchLifecycleContext): ActionStageOutcome;
|
|
15
|
+
reduce(action: Action, dispatch: StorageDispatchLifecycleContext): MachinesState<S>;
|
|
16
|
+
markExternallyChangedBuckets(prevState: Record<string, unknown>, nextState: Record<string, unknown>, dispatch: StorageDispatchLifecycleContext): void;
|
|
17
|
+
commit(dispatch: StorageDispatchLifecycleContext): void;
|
|
18
|
+
runReactions(action: Action, dispatch: StorageDispatchLifecycleContext): void;
|
|
19
|
+
runEffects(dispatch: StorageDispatchLifecycleContext): void;
|
|
20
|
+
condition(predicate: (action: Action) => boolean): Promise<boolean>;
|
|
21
|
+
};
|
|
22
|
+
export declare const createBucketRuntime: <S extends MachineStore>(buckets: readonly RuntimeBucket[], managerContext: ManagerRuntimeContext, resolveRoute: (action: Action) => StorageDispatchContext["route"], defaultStorageKind: string, runGuardedCallback: GuardedCallbackRunner) => BucketRuntime<S>;
|
|
23
|
+
export declare const initBucketState: <S extends MachineStore>(buckets: readonly RuntimeBucket[], bucketsByKind: ReadonlyMap<string, RuntimeBucket>, templates: readonly {
|
|
24
|
+
readonly key: string;
|
|
25
|
+
readonly kind: string;
|
|
26
|
+
}[], managerContext: ManagerRuntimeContext) => MachinesState<S>;
|
|
27
|
+
export declare const groupTemplatesByRuntime: (templates: readonly {
|
|
28
|
+
readonly key: string;
|
|
29
|
+
readonly kind: string;
|
|
30
|
+
}[], registeredRuntimes: readonly {
|
|
31
|
+
readonly kind: string;
|
|
32
|
+
readonly runtime: RuntimeBucket["runtime"];
|
|
33
|
+
}[]) => RuntimeBucket[];
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AnyEvent, MachinesState, MachineStore, ManagerAction } from "../../types";
|
|
2
|
+
import type { RuntimeBucket } from "./snapshot";
|
|
3
|
+
import { type ManagerRuntimeContext, type StorageDispatchContext, type StorageDispatchLifecycleContext } from "./storage";
|
|
4
|
+
import type { GuardedCallbackRunner } from "./transitionGuard";
|
|
5
|
+
type Action = ManagerAction<AnyEvent>;
|
|
6
|
+
type ActionStageOutcome = {
|
|
7
|
+
readonly type: "continue";
|
|
8
|
+
readonly action: Action;
|
|
9
|
+
} | {
|
|
10
|
+
readonly type: "drop";
|
|
11
|
+
};
|
|
12
|
+
export type BucketRuntime<S extends MachineStore> = {
|
|
13
|
+
prepareAction(action: Action, options: unknown, dispatch: StorageDispatchLifecycleContext): ActionStageOutcome;
|
|
14
|
+
beforeReduce(action: Action, dispatch: StorageDispatchLifecycleContext): ActionStageOutcome;
|
|
15
|
+
reduce(action: Action, dispatch: StorageDispatchLifecycleContext): MachinesState<S>;
|
|
16
|
+
markExternallyChangedBuckets(prevState: Record<string, unknown>, nextState: Record<string, unknown>, dispatch: StorageDispatchLifecycleContext): void;
|
|
17
|
+
commit(dispatch: StorageDispatchLifecycleContext): void;
|
|
18
|
+
runReactions(action: Action, dispatch: StorageDispatchLifecycleContext): void;
|
|
19
|
+
runEffects(dispatch: StorageDispatchLifecycleContext): void;
|
|
20
|
+
condition(predicate: (action: Action) => boolean): Promise<boolean>;
|
|
21
|
+
};
|
|
22
|
+
export declare const createBucketRuntime: <S extends MachineStore>(buckets: readonly RuntimeBucket[], managerContext: ManagerRuntimeContext, resolveRoute: (action: Action) => StorageDispatchContext["route"], defaultStorageKind: string, runGuardedCallback: GuardedCallbackRunner) => BucketRuntime<S>;
|
|
23
|
+
export declare const initBucketState: <S extends MachineStore>(buckets: readonly RuntimeBucket[], bucketsByKind: ReadonlyMap<string, RuntimeBucket>, templates: readonly {
|
|
24
|
+
readonly key: string;
|
|
25
|
+
readonly kind: string;
|
|
26
|
+
}[], managerContext: ManagerRuntimeContext) => MachinesState<S>;
|
|
27
|
+
export declare const groupTemplatesByRuntime: (templates: readonly {
|
|
28
|
+
readonly key: string;
|
|
29
|
+
readonly kind: string;
|
|
30
|
+
}[], registeredRuntimes: readonly {
|
|
31
|
+
readonly kind: string;
|
|
32
|
+
readonly runtime: RuntimeBucket["runtime"];
|
|
33
|
+
}[]) => RuntimeBucket[];
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ActionInterceptorResult } from "../../plugin";
|
|
2
|
+
import type { AnyEvent, ManagerAction } from "../../types";
|
|
3
|
+
import type { StorageActionStageResult, StorageReduceResult } from "./storage";
|
|
4
|
+
export declare const assertReplacementAction: (source: string, action: unknown) => ManagerAction<AnyEvent>;
|
|
5
|
+
export declare const assertStorageActionStageResult: (source: string, result: unknown) => StorageActionStageResult;
|
|
6
|
+
export declare const assertStorageReduceResult: (source: string, result: unknown) => StorageReduceResult;
|
|
7
|
+
export declare const assertStorageAcceptsEventResult: (source: string, result: unknown) => boolean;
|
|
8
|
+
export declare const assertPluginInterceptorResult: (source: string, result: unknown) => ActionInterceptorResult;
|
|
9
|
+
export declare const assertPublicCompileTemplateResult: (source: string, result: unknown) => void | {
|
|
10
|
+
readonly data?: unknown;
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ActionInterceptorResult } from "../../plugin";
|
|
2
|
+
import type { AnyEvent, ManagerAction } from "../../types";
|
|
3
|
+
import type { StorageActionStageResult, StorageReduceResult } from "./storage";
|
|
4
|
+
export declare const assertReplacementAction: (source: string, action: unknown) => ManagerAction<AnyEvent>;
|
|
5
|
+
export declare const assertStorageActionStageResult: (source: string, result: unknown) => StorageActionStageResult;
|
|
6
|
+
export declare const assertStorageReduceResult: (source: string, result: unknown) => StorageReduceResult;
|
|
7
|
+
export declare const assertStorageAcceptsEventResult: (source: string, result: unknown) => boolean;
|
|
8
|
+
export declare const assertPluginInterceptorResult: (source: string, result: unknown) => ActionInterceptorResult;
|
|
9
|
+
export declare const assertPublicCompileTemplateResult: (source: string, result: unknown) => void | {
|
|
10
|
+
readonly data?: unknown;
|
|
11
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LiteFsmPlugin, NormalizedPlugin } from "../../plugin";
|
|
2
|
+
import type { AnyEvent, MachineStore } from "../../types";
|
|
3
|
+
import type { MachineEvents, MachineManagerOptions, ManagerFromPlugins } from "../../interfaces";
|
|
4
|
+
export type RuntimePreset = {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly defaultStorageKind: string;
|
|
7
|
+
readonly plugins: readonly NormalizedPlugin[];
|
|
8
|
+
};
|
|
9
|
+
export type MachineManagerFactory = {
|
|
10
|
+
<S extends MachineStore, P extends AnyEvent = MachineEvents<S>>(config: S): ManagerFromPlugins<S, P, readonly []>;
|
|
11
|
+
<S extends MachineStore, P extends AnyEvent = MachineEvents<S>, const Plugins extends readonly LiteFsmPlugin<any, any, any>[] = readonly []>(config: S, opts: MachineManagerOptions<S, P, Plugins>): ManagerFromPlugins<S, P, Plugins>;
|
|
12
|
+
};
|
|
13
|
+
export declare const createMachineManagerFactory: (preset: RuntimePreset) => MachineManagerFactory;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LiteFsmPlugin, NormalizedPlugin } from "../../plugin";
|
|
2
|
+
import type { AnyEvent, MachineStore } from "../../types";
|
|
3
|
+
import type { MachineEvents, MachineManagerOptions, ManagerFromPlugins } from "../../interfaces";
|
|
4
|
+
export type RuntimePreset = {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly defaultStorageKind: string;
|
|
7
|
+
readonly plugins: readonly NormalizedPlugin[];
|
|
8
|
+
};
|
|
9
|
+
export type MachineManagerFactory = {
|
|
10
|
+
<S extends MachineStore, P extends AnyEvent = MachineEvents<S>>(config: S): ManagerFromPlugins<S, P, readonly []>;
|
|
11
|
+
<S extends MachineStore, P extends AnyEvent = MachineEvents<S>, const Plugins extends readonly LiteFsmPlugin<any, any, any>[] = readonly []>(config: S, opts: MachineManagerOptions<S, P, Plugins>): ManagerFromPlugins<S, P, Plugins>;
|
|
12
|
+
};
|
|
13
|
+
export declare const createMachineManagerFactory: (preset: RuntimePreset) => MachineManagerFactory;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ActionInterceptor, DispatchHook, DispatchHookPhase, ManagerRuntimeContext, NormalizedPlugin, ScopedInvocationContext } from "../../plugin";
|
|
2
|
+
import type { RuntimeStorageEntry, StorageRegistry } from "./storage";
|
|
3
|
+
export type { DispatchHookPhase };
|
|
4
|
+
export type ActionInterceptorEntry = {
|
|
5
|
+
readonly owner: string;
|
|
6
|
+
readonly intercept: ActionInterceptor;
|
|
7
|
+
};
|
|
8
|
+
type PluginRegistryOptions = {
|
|
9
|
+
readonly defaultStorageKind: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const createPluginRegistry: ({ defaultStorageKind }: PluginRegistryOptions) => {
|
|
12
|
+
defaultStorageKind: string;
|
|
13
|
+
storage: StorageRegistry;
|
|
14
|
+
routing: import("./routing").RoutingRuntime;
|
|
15
|
+
listStorageRuntimes: () => RuntimeStorageEntry[];
|
|
16
|
+
listActionInterceptors: () => readonly ActionInterceptorEntry[];
|
|
17
|
+
listDispatchHooks: (phase: DispatchHookPhase) => readonly DispatchHook[];
|
|
18
|
+
createScopedDeps(baseDeps: Record<string, unknown>, ctx: ScopedInvocationContext): Record<string, unknown>;
|
|
19
|
+
attachManagerExtensions<T extends Record<string, unknown>>(target: T, ctx: ManagerRuntimeContext): T;
|
|
20
|
+
addPlugin(plugin: NormalizedPlugin): void;
|
|
21
|
+
assertDefaultStorageRegistered(): void;
|
|
22
|
+
assertStorageRouteResolversRegistered(): void;
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ActionInterceptor, DispatchHook, DispatchHookPhase, ManagerRuntimeContext, NormalizedPlugin, ScopedInvocationContext } from "../../plugin";
|
|
2
|
+
import type { RuntimeStorageEntry, StorageRegistry } from "./storage";
|
|
3
|
+
export type { DispatchHookPhase };
|
|
4
|
+
export type ActionInterceptorEntry = {
|
|
5
|
+
readonly owner: string;
|
|
6
|
+
readonly intercept: ActionInterceptor;
|
|
7
|
+
};
|
|
8
|
+
type PluginRegistryOptions = {
|
|
9
|
+
readonly defaultStorageKind: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const createPluginRegistry: ({ defaultStorageKind }: PluginRegistryOptions) => {
|
|
12
|
+
defaultStorageKind: string;
|
|
13
|
+
storage: StorageRegistry;
|
|
14
|
+
routing: import("./routing").RoutingRuntime;
|
|
15
|
+
listStorageRuntimes: () => RuntimeStorageEntry[];
|
|
16
|
+
listActionInterceptors: () => readonly ActionInterceptorEntry[];
|
|
17
|
+
listDispatchHooks: (phase: DispatchHookPhase) => readonly DispatchHook[];
|
|
18
|
+
createScopedDeps(baseDeps: Record<string, unknown>, ctx: ScopedInvocationContext): Record<string, unknown>;
|
|
19
|
+
attachManagerExtensions<T extends Record<string, unknown>>(target: T, ctx: ManagerRuntimeContext): T;
|
|
20
|
+
addPlugin(plugin: NormalizedPlugin): void;
|
|
21
|
+
assertDefaultStorageRegistered(): void;
|
|
22
|
+
assertStorageRouteResolversRegistered(): void;
|
|
23
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RoutingRegistry } from "../../plugin";
|
|
2
|
+
import type { AnyEvent, FSMEventMeta, ManagerAction } from "../../types";
|
|
3
|
+
export type RouteConstraint = {
|
|
4
|
+
readonly scope: "actor";
|
|
5
|
+
readonly key: "actorId";
|
|
6
|
+
readonly targetSet: string[];
|
|
7
|
+
} | {
|
|
8
|
+
readonly scope: "plugin";
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly targetSet: string[];
|
|
11
|
+
} | {
|
|
12
|
+
readonly scope: "group";
|
|
13
|
+
readonly key: "groupId";
|
|
14
|
+
readonly targetSet: string[];
|
|
15
|
+
} | {
|
|
16
|
+
readonly scope: "tag";
|
|
17
|
+
readonly key: "groupTag";
|
|
18
|
+
readonly targetSet: string[];
|
|
19
|
+
} | {
|
|
20
|
+
readonly scope: "unscoped";
|
|
21
|
+
readonly key: undefined;
|
|
22
|
+
readonly targetSet: [];
|
|
23
|
+
};
|
|
24
|
+
export type RoutingRuntime = {
|
|
25
|
+
readonly registry: RoutingRegistry;
|
|
26
|
+
readonly registeredMetaKeys: readonly string[];
|
|
27
|
+
hasMetaKey(key: string): boolean;
|
|
28
|
+
stripSenderFields(meta: FSMEventMeta | undefined): FSMEventMeta;
|
|
29
|
+
stripRouting(meta: FSMEventMeta | undefined): FSMEventMeta;
|
|
30
|
+
hasRoute(meta: FSMEventMeta | undefined): boolean;
|
|
31
|
+
resolveRoute(action: ManagerAction<AnyEvent>): RouteConstraint;
|
|
32
|
+
};
|
|
33
|
+
export declare const createRoutingRuntime: () => RoutingRuntime;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RoutingRegistry } from "../../plugin";
|
|
2
|
+
import type { AnyEvent, FSMEventMeta, ManagerAction } from "../../types";
|
|
3
|
+
export type RouteConstraint = {
|
|
4
|
+
readonly scope: "actor";
|
|
5
|
+
readonly key: "actorId";
|
|
6
|
+
readonly targetSet: string[];
|
|
7
|
+
} | {
|
|
8
|
+
readonly scope: "plugin";
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly targetSet: string[];
|
|
11
|
+
} | {
|
|
12
|
+
readonly scope: "group";
|
|
13
|
+
readonly key: "groupId";
|
|
14
|
+
readonly targetSet: string[];
|
|
15
|
+
} | {
|
|
16
|
+
readonly scope: "tag";
|
|
17
|
+
readonly key: "groupTag";
|
|
18
|
+
readonly targetSet: string[];
|
|
19
|
+
} | {
|
|
20
|
+
readonly scope: "unscoped";
|
|
21
|
+
readonly key: undefined;
|
|
22
|
+
readonly targetSet: [];
|
|
23
|
+
};
|
|
24
|
+
export type RoutingRuntime = {
|
|
25
|
+
readonly registry: RoutingRegistry;
|
|
26
|
+
readonly registeredMetaKeys: readonly string[];
|
|
27
|
+
hasMetaKey(key: string): boolean;
|
|
28
|
+
stripSenderFields(meta: FSMEventMeta | undefined): FSMEventMeta;
|
|
29
|
+
stripRouting(meta: FSMEventMeta | undefined): FSMEventMeta;
|
|
30
|
+
hasRoute(meta: FSMEventMeta | undefined): boolean;
|
|
31
|
+
resolveRoute(action: ManagerAction<AnyEvent>): RouteConstraint;
|
|
32
|
+
};
|
|
33
|
+
export declare const createRoutingRuntime: () => RoutingRuntime;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DehydrateOptions, HydrateStrategy, MachineManagerSnapshot, MachinesState, MachineStore } from "../../types";
|
|
2
|
+
import type { CompiledStorageTemplate, ManagerRuntimeContext, StorageRuntime } from "./storage";
|
|
3
|
+
export type RuntimeBucket = {
|
|
4
|
+
readonly runtime: StorageRuntime;
|
|
5
|
+
readonly templates: CompiledStorageTemplate[];
|
|
6
|
+
state: unknown;
|
|
7
|
+
};
|
|
8
|
+
export type SnapshotRuntimeDeps<S extends MachineStore> = {
|
|
9
|
+
readonly config: MachineStore;
|
|
10
|
+
readonly buckets: readonly RuntimeBucket[];
|
|
11
|
+
readonly bucketsByKind: ReadonlyMap<string, RuntimeBucket>;
|
|
12
|
+
readonly templateKindByKey: ReadonlyMap<string, string>;
|
|
13
|
+
readonly defaultStorageKind: string;
|
|
14
|
+
readonly managerContext: ManagerRuntimeContext;
|
|
15
|
+
readonly getState: () => MachinesState<S>;
|
|
16
|
+
readonly getSchemaVersion: () => number | undefined;
|
|
17
|
+
};
|
|
18
|
+
type DehydrateRuntimeOptions = DehydrateOptions<MachineStore> | undefined;
|
|
19
|
+
export declare const createSnapshotRuntime: <S extends MachineStore>(deps: SnapshotRuntimeDeps<S>) => {
|
|
20
|
+
dehydrate: (options: DehydrateRuntimeOptions) => MachineManagerSnapshot<S>;
|
|
21
|
+
hydrate: (snapshot: MachineManagerSnapshot<S>, strategy: HydrateStrategy, mode: "preview" | "commit" | "init", baseState: MachinesState<S>, source: "hydrate" | "opts.snapshot") => {
|
|
22
|
+
nextState: MachinesState<S>;
|
|
23
|
+
changed: boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DehydrateOptions, HydrateStrategy, MachineManagerSnapshot, MachinesState, MachineStore } from "../../types";
|
|
2
|
+
import type { CompiledStorageTemplate, ManagerRuntimeContext, StorageRuntime } from "./storage";
|
|
3
|
+
export type RuntimeBucket = {
|
|
4
|
+
readonly runtime: StorageRuntime;
|
|
5
|
+
readonly templates: CompiledStorageTemplate[];
|
|
6
|
+
state: unknown;
|
|
7
|
+
};
|
|
8
|
+
export type SnapshotRuntimeDeps<S extends MachineStore> = {
|
|
9
|
+
readonly config: MachineStore;
|
|
10
|
+
readonly buckets: readonly RuntimeBucket[];
|
|
11
|
+
readonly bucketsByKind: ReadonlyMap<string, RuntimeBucket>;
|
|
12
|
+
readonly templateKindByKey: ReadonlyMap<string, string>;
|
|
13
|
+
readonly defaultStorageKind: string;
|
|
14
|
+
readonly managerContext: ManagerRuntimeContext;
|
|
15
|
+
readonly getState: () => MachinesState<S>;
|
|
16
|
+
readonly getSchemaVersion: () => number | undefined;
|
|
17
|
+
};
|
|
18
|
+
type DehydrateRuntimeOptions = DehydrateOptions<MachineStore> | undefined;
|
|
19
|
+
export declare const createSnapshotRuntime: <S extends MachineStore>(deps: SnapshotRuntimeDeps<S>) => {
|
|
20
|
+
dehydrate: (options: DehydrateRuntimeOptions) => MachineManagerSnapshot<S>;
|
|
21
|
+
hydrate: (snapshot: MachineManagerSnapshot<S>, strategy: HydrateStrategy, mode: "preview" | "commit" | "init", baseState: MachinesState<S>, source: "hydrate" | "opts.snapshot") => {
|
|
22
|
+
nextState: MachinesState<S>;
|
|
23
|
+
changed: boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export {};
|