@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,326 @@
|
|
|
1
|
+
import type { LiteFsmStorageRuntimeDefinition } from "./pluginStorage";
|
|
2
|
+
import type { AnyEvent, DehydrateOptions, HydrateStrategy, MachinesState, MachineStore, ManagerAction, ReadonlyManagerAction } from "./types";
|
|
3
|
+
type TypeOnlyDependentObjectField = (...args: any[]) => object;
|
|
4
|
+
type TypeOnlyDependentPublicStateField = (...args: any[]) => unknown;
|
|
5
|
+
declare const storageDependentFieldMarker: unique symbol;
|
|
6
|
+
export type StorageDependentTypeLambda = {
|
|
7
|
+
readonly input: object;
|
|
8
|
+
readonly type: unknown;
|
|
9
|
+
};
|
|
10
|
+
export type StorageDependentField<Lambda extends StorageDependentTypeLambda> = {
|
|
11
|
+
readonly [storageDependentFieldMarker]: Lambda;
|
|
12
|
+
};
|
|
13
|
+
export type StorageRuntimeExtension = {
|
|
14
|
+
readonly input?: object;
|
|
15
|
+
readonly internalEvents?: AnyEvent;
|
|
16
|
+
readonly observedEvents?: AnyEvent;
|
|
17
|
+
readonly routeMeta?: object;
|
|
18
|
+
readonly reducerContext?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
19
|
+
readonly effectDeps?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
20
|
+
readonly reactionDeps?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
21
|
+
readonly resultMetadata?: object | TypeOnlyDependentObjectField;
|
|
22
|
+
readonly publicState?: unknown | TypeOnlyDependentPublicStateField;
|
|
23
|
+
readonly runtimeState?: unknown;
|
|
24
|
+
readonly templateData?: unknown;
|
|
25
|
+
readonly snapshotData?: unknown;
|
|
26
|
+
readonly invocation?: unknown;
|
|
27
|
+
readonly identity?: Readonly<Record<string, unknown>>;
|
|
28
|
+
};
|
|
29
|
+
export type StorageMachineTypingExtension = {
|
|
30
|
+
readonly storage?: string;
|
|
31
|
+
readonly input?: object;
|
|
32
|
+
readonly internalEvents?: AnyEvent;
|
|
33
|
+
readonly reducerContext?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
34
|
+
readonly effectDeps?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
35
|
+
readonly reactionDeps?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
36
|
+
readonly resultMetadata?: object | TypeOnlyDependentObjectField;
|
|
37
|
+
readonly publicState?: unknown | TypeOnlyDependentPublicStateField;
|
|
38
|
+
};
|
|
39
|
+
export type StorageTemplate<TemplateData = unknown> = {
|
|
40
|
+
readonly key: string;
|
|
41
|
+
readonly kind: string;
|
|
42
|
+
readonly data?: TemplateData;
|
|
43
|
+
};
|
|
44
|
+
export type StorageManagerContext<Events extends AnyEvent = AnyEvent> = {
|
|
45
|
+
getState(): MachinesState<MachineStore>;
|
|
46
|
+
transition(action: ManagerAction<Events>, options?: unknown): ManagerAction<Events>;
|
|
47
|
+
onTransition(cb: (prevState: MachinesState<MachineStore>, currentState: MachinesState<MachineStore>, action: ReadonlyManagerAction<Events> | {
|
|
48
|
+
readonly type: string;
|
|
49
|
+
readonly payload?: unknown;
|
|
50
|
+
}) => void): () => void;
|
|
51
|
+
getDependencies(): Record<string, unknown>;
|
|
52
|
+
};
|
|
53
|
+
type StorageRuntimeState = unknown;
|
|
54
|
+
type StorageEffectInvocation = unknown;
|
|
55
|
+
export type StorageActionStageResult = void | {
|
|
56
|
+
readonly type: "replace";
|
|
57
|
+
readonly action: ManagerAction<AnyEvent>;
|
|
58
|
+
} | {
|
|
59
|
+
readonly type: "drop";
|
|
60
|
+
};
|
|
61
|
+
export type StoragePrepareActionResult = StorageActionStageResult;
|
|
62
|
+
export type StorageReduceResult = void | {
|
|
63
|
+
readonly type: "skip";
|
|
64
|
+
};
|
|
65
|
+
export type StorageHydrateResult = {
|
|
66
|
+
readonly nextState: Record<string, unknown>;
|
|
67
|
+
readonly changed: boolean;
|
|
68
|
+
};
|
|
69
|
+
type StorageDispatchRoute = {
|
|
70
|
+
readonly scope: "actor";
|
|
71
|
+
readonly key: "actorId";
|
|
72
|
+
readonly targetSet: string[];
|
|
73
|
+
} | {
|
|
74
|
+
readonly scope: "plugin";
|
|
75
|
+
readonly key: string;
|
|
76
|
+
readonly targetSet: string[];
|
|
77
|
+
} | {
|
|
78
|
+
readonly scope: "group";
|
|
79
|
+
readonly key: "groupId";
|
|
80
|
+
readonly targetSet: string[];
|
|
81
|
+
} | {
|
|
82
|
+
readonly scope: "tag";
|
|
83
|
+
readonly key: "groupTag";
|
|
84
|
+
readonly targetSet: string[];
|
|
85
|
+
} | {
|
|
86
|
+
readonly scope: "unscoped";
|
|
87
|
+
readonly key: undefined;
|
|
88
|
+
readonly targetSet: [];
|
|
89
|
+
};
|
|
90
|
+
type StorageDispatchContext = {
|
|
91
|
+
readonly options: unknown;
|
|
92
|
+
readonly runtime: Map<string, unknown>;
|
|
93
|
+
readonly route: StorageDispatchRoute;
|
|
94
|
+
readonly prevState: Record<string, unknown>;
|
|
95
|
+
nextState: Record<string, unknown>;
|
|
96
|
+
readonly skipDelivery: boolean;
|
|
97
|
+
reportError(error: unknown): void;
|
|
98
|
+
};
|
|
99
|
+
type ValidateTemplateContext = {
|
|
100
|
+
readonly key: string;
|
|
101
|
+
readonly machine: MachineStore[string];
|
|
102
|
+
readonly storageKind: string;
|
|
103
|
+
};
|
|
104
|
+
type CompileTemplateContext = ValidateTemplateContext;
|
|
105
|
+
type CreateRuntimeStateContext = {
|
|
106
|
+
readonly templates: readonly StorageTemplate[];
|
|
107
|
+
readonly manager: StorageManagerContext;
|
|
108
|
+
};
|
|
109
|
+
type CreatePublicInitialStateContext = {
|
|
110
|
+
readonly template: StorageTemplate;
|
|
111
|
+
readonly state: StorageRuntimeState;
|
|
112
|
+
};
|
|
113
|
+
type ActionAwareStorageContext = {
|
|
114
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
115
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
116
|
+
readonly state: StorageRuntimeState;
|
|
117
|
+
readonly dispatch: StorageDispatchContext;
|
|
118
|
+
};
|
|
119
|
+
type StoragePrepareActionContextBase = ActionAwareStorageContext & {
|
|
120
|
+
readonly options: unknown;
|
|
121
|
+
readonly manager: StorageManagerContext;
|
|
122
|
+
};
|
|
123
|
+
type StorageBeforeReduceContextBase = ActionAwareStorageContext & {
|
|
124
|
+
readonly manager: StorageManagerContext;
|
|
125
|
+
};
|
|
126
|
+
type AcceptsEventContext = ActionAwareStorageContext & {
|
|
127
|
+
readonly template: StorageTemplate;
|
|
128
|
+
};
|
|
129
|
+
type StorageReduceContextBase = ActionAwareStorageContext & {
|
|
130
|
+
readonly template: StorageTemplate;
|
|
131
|
+
readonly manager: StorageManagerContext;
|
|
132
|
+
};
|
|
133
|
+
type StorageReduceBucketContextBase = ActionAwareStorageContext & {
|
|
134
|
+
readonly templates: readonly StorageTemplate[];
|
|
135
|
+
readonly manager: StorageManagerContext;
|
|
136
|
+
};
|
|
137
|
+
type StorageCommitContextBase = ActionAwareStorageContext & {
|
|
138
|
+
readonly manager: StorageManagerContext;
|
|
139
|
+
};
|
|
140
|
+
type StorageConditionContextBase = {
|
|
141
|
+
readonly predicate: (action: ReadonlyManagerAction<AnyEvent>) => boolean;
|
|
142
|
+
readonly state: StorageRuntimeState;
|
|
143
|
+
readonly manager: StorageManagerContext;
|
|
144
|
+
};
|
|
145
|
+
type ResolveEffectInvocationsContext = ActionAwareStorageContext & {
|
|
146
|
+
readonly manager: StorageManagerContext;
|
|
147
|
+
};
|
|
148
|
+
type StorageEffectInvocationContextBase = ActionAwareStorageContext & {
|
|
149
|
+
readonly invocation: StorageEffectInvocation;
|
|
150
|
+
readonly manager: StorageManagerContext;
|
|
151
|
+
};
|
|
152
|
+
type StorageDehydrateContextBase = {
|
|
153
|
+
readonly state: StorageRuntimeState;
|
|
154
|
+
readonly manager: StorageManagerContext;
|
|
155
|
+
readonly rootState: Record<string, unknown>;
|
|
156
|
+
readonly options: DehydrateOptions<MachineStore> | undefined;
|
|
157
|
+
};
|
|
158
|
+
type StorageDehydrateResultBase = {
|
|
159
|
+
readonly machines?: Record<string, unknown>;
|
|
160
|
+
readonly snapshot?: unknown;
|
|
161
|
+
};
|
|
162
|
+
type StorageHydrateContextBase = {
|
|
163
|
+
readonly state: StorageRuntimeState;
|
|
164
|
+
readonly manager: StorageManagerContext;
|
|
165
|
+
readonly machines: Readonly<Record<string, unknown>>;
|
|
166
|
+
readonly snapshot: unknown | undefined;
|
|
167
|
+
readonly baseState: Record<string, unknown>;
|
|
168
|
+
readonly strategy: HydrateStrategy;
|
|
169
|
+
readonly source: "hydrate" | "opts.snapshot";
|
|
170
|
+
readonly mode: "preview" | "commit" | "init";
|
|
171
|
+
};
|
|
172
|
+
type ResolveIdentityContext = {
|
|
173
|
+
readonly state: StorageRuntimeState;
|
|
174
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
175
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
176
|
+
};
|
|
177
|
+
type StorageReactionContextBase = ActionAwareStorageContext & {
|
|
178
|
+
readonly manager: StorageManagerContext;
|
|
179
|
+
};
|
|
180
|
+
type MachineFacingStorageExtensionKey = "input" | "internalEvents" | "reducerContext" | "effectDeps" | "reactionDeps" | "resultMetadata" | "publicState";
|
|
181
|
+
export type RejectUnknownMachineExtensionKeys<Extension extends object> = {
|
|
182
|
+
readonly [Key in Exclude<keyof Extension, keyof StorageRuntimeExtension>]-?: never;
|
|
183
|
+
};
|
|
184
|
+
type StorageMachineFacingExtension<Extension extends StorageRuntimeExtension> = Pick<Extension, Extract<keyof Extension, MachineFacingStorageExtensionKey>>;
|
|
185
|
+
type ExtensionTemplateMachine<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
186
|
+
readonly input?: infer Input extends object;
|
|
187
|
+
} ? MachineStore[string] & Input : MachineStore[string];
|
|
188
|
+
type ExtensionTemplateData<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
189
|
+
readonly templateData?: infer TemplateData;
|
|
190
|
+
} ? TemplateData : unknown;
|
|
191
|
+
type ExtensionRuntimeState<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
192
|
+
readonly runtimeState?: infer RuntimeState;
|
|
193
|
+
} ? RuntimeState : unknown;
|
|
194
|
+
type ExtensionPublicState<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
195
|
+
readonly publicState?: infer PublicState;
|
|
196
|
+
} ? PublicState extends (...args: any[]) => infer Result ? Result : PublicState : unknown;
|
|
197
|
+
type ExtensionSnapshotData<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
198
|
+
readonly snapshotData?: infer SnapshotData;
|
|
199
|
+
} ? SnapshotData : unknown;
|
|
200
|
+
type ExtensionInvocation<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
201
|
+
readonly invocation?: infer Invocation;
|
|
202
|
+
} ? Invocation : unknown;
|
|
203
|
+
type ExtensionIdentity<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
204
|
+
readonly identity?: infer Identity;
|
|
205
|
+
} ? Identity extends Readonly<Record<string, unknown>> ? Identity : Readonly<Record<string, unknown>> : Readonly<Record<string, unknown>>;
|
|
206
|
+
type ExtensionObservedEvents<Extension extends StorageRuntimeExtension> = "observedEvents" extends keyof Extension ? Extension extends {
|
|
207
|
+
readonly observedEvents?: infer Events extends AnyEvent;
|
|
208
|
+
} ? Events : AnyEvent : AnyEvent;
|
|
209
|
+
type ExtensionRouteMeta<Extension extends StorageRuntimeExtension> = "routeMeta" extends keyof Extension ? NonNullable<Extension["routeMeta"]> extends object ? NonNullable<Extension["routeMeta"]> : never : never;
|
|
210
|
+
export type StorageRouteMetaKeys<Extension extends StorageRuntimeExtension> = [ExtensionRouteMeta<Extension>] extends [
|
|
211
|
+
never
|
|
212
|
+
] ? readonly string[] : readonly (keyof ExtensionRouteMeta<Extension> & string)[];
|
|
213
|
+
export type StorageRequiredRouteMetaForKeys<Extension extends StorageRuntimeExtension, RouteMetaKeys> = [
|
|
214
|
+
ExtensionRouteMeta<Extension>
|
|
215
|
+
] extends [never] ? {} : RouteMetaKeys extends readonly (keyof ExtensionRouteMeta<Extension> & string)[] ? Pick<ExtensionRouteMeta<Extension>, RouteMetaKeys[number]> : {};
|
|
216
|
+
type WithObservedAction<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "action" | "originalAction"> & {
|
|
217
|
+
readonly action: ReadonlyManagerAction<ExtensionObservedEvents<Extension>>;
|
|
218
|
+
readonly originalAction: ReadonlyManagerAction<ExtensionObservedEvents<Extension>>;
|
|
219
|
+
};
|
|
220
|
+
type WithObservedManager<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "manager"> & {
|
|
221
|
+
readonly manager: StorageManagerContext<ExtensionObservedEvents<Extension>>;
|
|
222
|
+
};
|
|
223
|
+
type WithObservedPredicate<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "predicate"> & {
|
|
224
|
+
readonly predicate: (action: ReadonlyManagerAction<ExtensionObservedEvents<Extension>>) => boolean;
|
|
225
|
+
};
|
|
226
|
+
type WithRuntimeState<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "state"> & {
|
|
227
|
+
readonly state: ExtensionRuntimeState<Extension>;
|
|
228
|
+
};
|
|
229
|
+
type WithRuntimeTemplate<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "template" | "state"> & {
|
|
230
|
+
readonly template: StorageTemplate<ExtensionTemplateData<Extension>>;
|
|
231
|
+
readonly state: ExtensionRuntimeState<Extension>;
|
|
232
|
+
};
|
|
233
|
+
type WithRuntimeTemplates<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "templates" | "state"> & {
|
|
234
|
+
readonly templates: readonly StorageTemplate<ExtensionTemplateData<Extension>>[];
|
|
235
|
+
readonly state: ExtensionRuntimeState<Extension>;
|
|
236
|
+
};
|
|
237
|
+
export type StorageValidateTemplateContext<Kind extends string, Extension extends StorageRuntimeExtension> = Omit<ValidateTemplateContext, "machine" | "storageKind"> & {
|
|
238
|
+
readonly storageKind: Kind;
|
|
239
|
+
readonly machine: ExtensionTemplateMachine<Extension>;
|
|
240
|
+
};
|
|
241
|
+
export type StorageCompileTemplateContext<Kind extends string, Extension extends StorageRuntimeExtension> = Omit<CompileTemplateContext, "machine" | "storageKind"> & {
|
|
242
|
+
readonly storageKind: Kind;
|
|
243
|
+
readonly machine: ExtensionTemplateMachine<Extension>;
|
|
244
|
+
};
|
|
245
|
+
export type StorageCreateRuntimeStateContext<Extension extends StorageRuntimeExtension> = Omit<WithObservedManager<CreateRuntimeStateContext, Extension>, "templates"> & {
|
|
246
|
+
readonly templates: readonly StorageTemplate<ExtensionTemplateData<Extension>>[];
|
|
247
|
+
};
|
|
248
|
+
export type StorageCreatePublicInitialStateContext<Extension extends StorageRuntimeExtension> = WithRuntimeTemplate<CreatePublicInitialStateContext, Extension>;
|
|
249
|
+
export type StoragePrepareActionContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedAction<StoragePrepareActionContextBase, Extension>, Extension>, Extension>;
|
|
250
|
+
export type StorageBeforeReduceContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedAction<StorageBeforeReduceContextBase, Extension>, Extension>, Extension>;
|
|
251
|
+
export type StorageAcceptsEventContext<Extension extends StorageRuntimeExtension> = WithRuntimeTemplate<WithObservedAction<AcceptsEventContext, Extension>, Extension>;
|
|
252
|
+
export type StorageReduceContext<Extension extends StorageRuntimeExtension> = WithRuntimeTemplate<WithObservedManager<WithObservedAction<StorageReduceContextBase, Extension>, Extension>, Extension>;
|
|
253
|
+
export type StorageReduceBucketContext<Extension extends StorageRuntimeExtension> = WithRuntimeTemplates<WithObservedManager<WithObservedAction<StorageReduceBucketContextBase, Extension>, Extension>, Extension>;
|
|
254
|
+
export type StorageCommitContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedAction<StorageCommitContextBase, Extension>, Extension>, Extension>;
|
|
255
|
+
export type StorageConditionContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedPredicate<StorageConditionContextBase, Extension>, Extension>, Extension>;
|
|
256
|
+
export type StorageResolveEffectInvocationsContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedAction<ResolveEffectInvocationsContext, Extension>, Extension>, Extension>;
|
|
257
|
+
export type StorageEffectInvocationContext<Extension extends StorageRuntimeExtension> = Omit<WithRuntimeState<WithObservedManager<WithObservedAction<StorageEffectInvocationContextBase, Extension>, Extension>, Extension>, "invocation"> & {
|
|
258
|
+
readonly invocation: ExtensionInvocation<Extension>;
|
|
259
|
+
};
|
|
260
|
+
export type StorageDehydrateContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<StorageDehydrateContextBase, Extension>, Extension>;
|
|
261
|
+
export type StorageHydrateContext<Extension extends StorageRuntimeExtension> = Omit<WithRuntimeState<WithObservedManager<StorageHydrateContextBase, Extension>, Extension>, "snapshot"> & {
|
|
262
|
+
readonly snapshot: ExtensionSnapshotData<Extension> | undefined;
|
|
263
|
+
};
|
|
264
|
+
export type StorageIdentityContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedAction<ResolveIdentityContext, Extension>, Extension>;
|
|
265
|
+
export type StorageReactionContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedAction<StorageReactionContextBase, Extension>, Extension>, Extension>;
|
|
266
|
+
export type StorageCompileTemplateResult<TemplateData = unknown> = void | {
|
|
267
|
+
readonly data?: TemplateData;
|
|
268
|
+
readonly key?: never;
|
|
269
|
+
readonly kind?: never;
|
|
270
|
+
};
|
|
271
|
+
export type StorageDehydrateResult<Extension extends StorageRuntimeExtension> = Omit<StorageDehydrateResultBase, "snapshot"> & {
|
|
272
|
+
readonly snapshot?: ExtensionSnapshotData<Extension>;
|
|
273
|
+
};
|
|
274
|
+
type PluginStorageEffectsRuntime<Extension extends StorageRuntimeExtension> = {
|
|
275
|
+
condition?(ctx: StorageConditionContext<Extension>): Promise<boolean>;
|
|
276
|
+
resolveInvocations(ctx: StorageResolveEffectInvocationsContext<Extension>): readonly ExtensionInvocation<Extension>[];
|
|
277
|
+
invoke(ctx: StorageEffectInvocationContext<Extension>): void;
|
|
278
|
+
};
|
|
279
|
+
type PluginStorageSnapshotRuntime<Extension extends StorageRuntimeExtension> = {
|
|
280
|
+
dehydrate(ctx: StorageDehydrateContext<Extension>): StorageDehydrateResult<Extension>;
|
|
281
|
+
hydrate(ctx: StorageHydrateContext<Extension>): StorageHydrateResult;
|
|
282
|
+
};
|
|
283
|
+
type PluginStorageIdentityRuntime<Extension extends StorageRuntimeExtension> = {
|
|
284
|
+
resolve(ctx: StorageIdentityContext<Extension>): ExtensionIdentity<Extension> | undefined;
|
|
285
|
+
};
|
|
286
|
+
type PluginStorageReactionRuntime<Extension extends StorageRuntimeExtension> = {
|
|
287
|
+
run(ctx: StorageReactionContext<Extension>): void;
|
|
288
|
+
};
|
|
289
|
+
type PluginStorageRuntimeBase<Kind extends string, Extension extends StorageRuntimeExtension, RouteMetaKeys extends StorageRouteMetaKeys<Extension> | undefined> = {
|
|
290
|
+
readonly kind: Kind;
|
|
291
|
+
readonly routeMetaKeys?: RouteMetaKeys;
|
|
292
|
+
validateTemplate(ctx: StorageValidateTemplateContext<Kind, Extension>): void;
|
|
293
|
+
compileTemplate(ctx: StorageCompileTemplateContext<Kind, Extension>): StorageCompileTemplateResult<ExtensionTemplateData<Extension>>;
|
|
294
|
+
createRuntimeState(ctx: StorageCreateRuntimeStateContext<Extension>): ExtensionRuntimeState<Extension>;
|
|
295
|
+
createPublicInitialState(ctx: StorageCreatePublicInitialStateContext<Extension>): ExtensionPublicState<Extension>;
|
|
296
|
+
prepareAction?(ctx: StoragePrepareActionContext<Extension>): StoragePrepareActionResult;
|
|
297
|
+
beforeReduce?(ctx: StorageBeforeReduceContext<Extension>): StorageActionStageResult;
|
|
298
|
+
commit(ctx: StorageCommitContext<Extension>): void;
|
|
299
|
+
readonly effects?: PluginStorageEffectsRuntime<Extension>;
|
|
300
|
+
readonly snapshot?: PluginStorageSnapshotRuntime<Extension>;
|
|
301
|
+
readonly identity?: PluginStorageIdentityRuntime<Extension>;
|
|
302
|
+
readonly reactions?: PluginStorageReactionRuntime<Extension>;
|
|
303
|
+
};
|
|
304
|
+
type PluginTemplateStorageRuntime<Kind extends string, Extension extends StorageRuntimeExtension, RouteMetaKeys extends StorageRouteMetaKeys<Extension> | undefined> = PluginStorageRuntimeBase<Kind, Extension, RouteMetaKeys> & {
|
|
305
|
+
readonly reduceScope?: "template";
|
|
306
|
+
acceptsEvent(ctx: StorageAcceptsEventContext<Extension>): boolean;
|
|
307
|
+
reduce(ctx: StorageReduceContext<Extension>): StorageReduceResult;
|
|
308
|
+
readonly reduceBucket?: never;
|
|
309
|
+
};
|
|
310
|
+
type PluginBucketStorageRuntime<Kind extends string, Extension extends StorageRuntimeExtension, RouteMetaKeys extends StorageRouteMetaKeys<Extension> | undefined> = PluginStorageRuntimeBase<Kind, Extension, RouteMetaKeys> & {
|
|
311
|
+
readonly reduceScope: "bucket";
|
|
312
|
+
reduceBucket(ctx: StorageReduceBucketContext<Extension>): StorageReduceResult;
|
|
313
|
+
readonly acceptsEvent?: never;
|
|
314
|
+
readonly reduce?: never;
|
|
315
|
+
};
|
|
316
|
+
export type PluginStorageRuntime<Kind extends string, Extension extends StorageRuntimeExtension, RouteMetaKeys extends StorageRouteMetaKeys<Extension> | undefined = StorageRouteMetaKeys<Extension> | undefined> = PluginTemplateStorageRuntime<Kind, Extension, RouteMetaKeys> | PluginBucketStorageRuntime<Kind, Extension, RouteMetaKeys>;
|
|
317
|
+
type Prettify<Value> = {
|
|
318
|
+
[Key in keyof Value]: Value[Key];
|
|
319
|
+
};
|
|
320
|
+
export type StorageMachineExtension<Kind extends string, Extension extends StorageRuntimeExtension> = Prettify<StorageMachineFacingExtension<Extension> & {
|
|
321
|
+
readonly storage: Kind;
|
|
322
|
+
}>;
|
|
323
|
+
export type StorageRuntimeBuilder<Extension extends StorageRuntimeExtension> = {
|
|
324
|
+
create<const Kind extends string, const RouteMetaKeys extends StorageRouteMetaKeys<Extension> | undefined = undefined>(definition: PluginStorageRuntime<Kind, Extension, RouteMetaKeys> & RejectUnknownMachineExtensionKeys<Extension>): LiteFsmStorageRuntimeDefinition<Kind, StorageMachineExtension<Kind, Extension>, StorageRequiredRouteMetaForKeys<Extension, RouteMetaKeys>>;
|
|
325
|
+
};
|
|
326
|
+
export {};
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import type { LiteFsmStorageRuntimeDefinition } from "./pluginStorage";
|
|
2
|
+
import type { AnyEvent, DehydrateOptions, HydrateStrategy, MachinesState, MachineStore, ManagerAction, ReadonlyManagerAction } from "./types";
|
|
3
|
+
type TypeOnlyDependentObjectField = (...args: any[]) => object;
|
|
4
|
+
type TypeOnlyDependentPublicStateField = (...args: any[]) => unknown;
|
|
5
|
+
declare const storageDependentFieldMarker: unique symbol;
|
|
6
|
+
export type StorageDependentTypeLambda = {
|
|
7
|
+
readonly input: object;
|
|
8
|
+
readonly type: unknown;
|
|
9
|
+
};
|
|
10
|
+
export type StorageDependentField<Lambda extends StorageDependentTypeLambda> = {
|
|
11
|
+
readonly [storageDependentFieldMarker]: Lambda;
|
|
12
|
+
};
|
|
13
|
+
export type StorageRuntimeExtension = {
|
|
14
|
+
readonly input?: object;
|
|
15
|
+
readonly internalEvents?: AnyEvent;
|
|
16
|
+
readonly observedEvents?: AnyEvent;
|
|
17
|
+
readonly routeMeta?: object;
|
|
18
|
+
readonly reducerContext?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
19
|
+
readonly effectDeps?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
20
|
+
readonly reactionDeps?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
21
|
+
readonly resultMetadata?: object | TypeOnlyDependentObjectField;
|
|
22
|
+
readonly publicState?: unknown | TypeOnlyDependentPublicStateField;
|
|
23
|
+
readonly runtimeState?: unknown;
|
|
24
|
+
readonly templateData?: unknown;
|
|
25
|
+
readonly snapshotData?: unknown;
|
|
26
|
+
readonly invocation?: unknown;
|
|
27
|
+
readonly identity?: Readonly<Record<string, unknown>>;
|
|
28
|
+
};
|
|
29
|
+
export type StorageMachineTypingExtension = {
|
|
30
|
+
readonly storage?: string;
|
|
31
|
+
readonly input?: object;
|
|
32
|
+
readonly internalEvents?: AnyEvent;
|
|
33
|
+
readonly reducerContext?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
34
|
+
readonly effectDeps?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
35
|
+
readonly reactionDeps?: object | TypeOnlyDependentObjectField | StorageDependentField<StorageDependentTypeLambda>;
|
|
36
|
+
readonly resultMetadata?: object | TypeOnlyDependentObjectField;
|
|
37
|
+
readonly publicState?: unknown | TypeOnlyDependentPublicStateField;
|
|
38
|
+
};
|
|
39
|
+
export type StorageTemplate<TemplateData = unknown> = {
|
|
40
|
+
readonly key: string;
|
|
41
|
+
readonly kind: string;
|
|
42
|
+
readonly data?: TemplateData;
|
|
43
|
+
};
|
|
44
|
+
export type StorageManagerContext<Events extends AnyEvent = AnyEvent> = {
|
|
45
|
+
getState(): MachinesState<MachineStore>;
|
|
46
|
+
transition(action: ManagerAction<Events>, options?: unknown): ManagerAction<Events>;
|
|
47
|
+
onTransition(cb: (prevState: MachinesState<MachineStore>, currentState: MachinesState<MachineStore>, action: ReadonlyManagerAction<Events> | {
|
|
48
|
+
readonly type: string;
|
|
49
|
+
readonly payload?: unknown;
|
|
50
|
+
}) => void): () => void;
|
|
51
|
+
getDependencies(): Record<string, unknown>;
|
|
52
|
+
};
|
|
53
|
+
type StorageRuntimeState = unknown;
|
|
54
|
+
type StorageEffectInvocation = unknown;
|
|
55
|
+
export type StorageActionStageResult = void | {
|
|
56
|
+
readonly type: "replace";
|
|
57
|
+
readonly action: ManagerAction<AnyEvent>;
|
|
58
|
+
} | {
|
|
59
|
+
readonly type: "drop";
|
|
60
|
+
};
|
|
61
|
+
export type StoragePrepareActionResult = StorageActionStageResult;
|
|
62
|
+
export type StorageReduceResult = void | {
|
|
63
|
+
readonly type: "skip";
|
|
64
|
+
};
|
|
65
|
+
export type StorageHydrateResult = {
|
|
66
|
+
readonly nextState: Record<string, unknown>;
|
|
67
|
+
readonly changed: boolean;
|
|
68
|
+
};
|
|
69
|
+
type StorageDispatchRoute = {
|
|
70
|
+
readonly scope: "actor";
|
|
71
|
+
readonly key: "actorId";
|
|
72
|
+
readonly targetSet: string[];
|
|
73
|
+
} | {
|
|
74
|
+
readonly scope: "plugin";
|
|
75
|
+
readonly key: string;
|
|
76
|
+
readonly targetSet: string[];
|
|
77
|
+
} | {
|
|
78
|
+
readonly scope: "group";
|
|
79
|
+
readonly key: "groupId";
|
|
80
|
+
readonly targetSet: string[];
|
|
81
|
+
} | {
|
|
82
|
+
readonly scope: "tag";
|
|
83
|
+
readonly key: "groupTag";
|
|
84
|
+
readonly targetSet: string[];
|
|
85
|
+
} | {
|
|
86
|
+
readonly scope: "unscoped";
|
|
87
|
+
readonly key: undefined;
|
|
88
|
+
readonly targetSet: [];
|
|
89
|
+
};
|
|
90
|
+
type StorageDispatchContext = {
|
|
91
|
+
readonly options: unknown;
|
|
92
|
+
readonly runtime: Map<string, unknown>;
|
|
93
|
+
readonly route: StorageDispatchRoute;
|
|
94
|
+
readonly prevState: Record<string, unknown>;
|
|
95
|
+
nextState: Record<string, unknown>;
|
|
96
|
+
readonly skipDelivery: boolean;
|
|
97
|
+
reportError(error: unknown): void;
|
|
98
|
+
};
|
|
99
|
+
type ValidateTemplateContext = {
|
|
100
|
+
readonly key: string;
|
|
101
|
+
readonly machine: MachineStore[string];
|
|
102
|
+
readonly storageKind: string;
|
|
103
|
+
};
|
|
104
|
+
type CompileTemplateContext = ValidateTemplateContext;
|
|
105
|
+
type CreateRuntimeStateContext = {
|
|
106
|
+
readonly templates: readonly StorageTemplate[];
|
|
107
|
+
readonly manager: StorageManagerContext;
|
|
108
|
+
};
|
|
109
|
+
type CreatePublicInitialStateContext = {
|
|
110
|
+
readonly template: StorageTemplate;
|
|
111
|
+
readonly state: StorageRuntimeState;
|
|
112
|
+
};
|
|
113
|
+
type ActionAwareStorageContext = {
|
|
114
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
115
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
116
|
+
readonly state: StorageRuntimeState;
|
|
117
|
+
readonly dispatch: StorageDispatchContext;
|
|
118
|
+
};
|
|
119
|
+
type StoragePrepareActionContextBase = ActionAwareStorageContext & {
|
|
120
|
+
readonly options: unknown;
|
|
121
|
+
readonly manager: StorageManagerContext;
|
|
122
|
+
};
|
|
123
|
+
type StorageBeforeReduceContextBase = ActionAwareStorageContext & {
|
|
124
|
+
readonly manager: StorageManagerContext;
|
|
125
|
+
};
|
|
126
|
+
type AcceptsEventContext = ActionAwareStorageContext & {
|
|
127
|
+
readonly template: StorageTemplate;
|
|
128
|
+
};
|
|
129
|
+
type StorageReduceContextBase = ActionAwareStorageContext & {
|
|
130
|
+
readonly template: StorageTemplate;
|
|
131
|
+
readonly manager: StorageManagerContext;
|
|
132
|
+
};
|
|
133
|
+
type StorageReduceBucketContextBase = ActionAwareStorageContext & {
|
|
134
|
+
readonly templates: readonly StorageTemplate[];
|
|
135
|
+
readonly manager: StorageManagerContext;
|
|
136
|
+
};
|
|
137
|
+
type StorageCommitContextBase = ActionAwareStorageContext & {
|
|
138
|
+
readonly manager: StorageManagerContext;
|
|
139
|
+
};
|
|
140
|
+
type StorageConditionContextBase = {
|
|
141
|
+
readonly predicate: (action: ReadonlyManagerAction<AnyEvent>) => boolean;
|
|
142
|
+
readonly state: StorageRuntimeState;
|
|
143
|
+
readonly manager: StorageManagerContext;
|
|
144
|
+
};
|
|
145
|
+
type ResolveEffectInvocationsContext = ActionAwareStorageContext & {
|
|
146
|
+
readonly manager: StorageManagerContext;
|
|
147
|
+
};
|
|
148
|
+
type StorageEffectInvocationContextBase = ActionAwareStorageContext & {
|
|
149
|
+
readonly invocation: StorageEffectInvocation;
|
|
150
|
+
readonly manager: StorageManagerContext;
|
|
151
|
+
};
|
|
152
|
+
type StorageDehydrateContextBase = {
|
|
153
|
+
readonly state: StorageRuntimeState;
|
|
154
|
+
readonly manager: StorageManagerContext;
|
|
155
|
+
readonly rootState: Record<string, unknown>;
|
|
156
|
+
readonly options: DehydrateOptions<MachineStore> | undefined;
|
|
157
|
+
};
|
|
158
|
+
type StorageDehydrateResultBase = {
|
|
159
|
+
readonly machines?: Record<string, unknown>;
|
|
160
|
+
readonly snapshot?: unknown;
|
|
161
|
+
};
|
|
162
|
+
type StorageHydrateContextBase = {
|
|
163
|
+
readonly state: StorageRuntimeState;
|
|
164
|
+
readonly manager: StorageManagerContext;
|
|
165
|
+
readonly machines: Readonly<Record<string, unknown>>;
|
|
166
|
+
readonly snapshot: unknown | undefined;
|
|
167
|
+
readonly baseState: Record<string, unknown>;
|
|
168
|
+
readonly strategy: HydrateStrategy;
|
|
169
|
+
readonly source: "hydrate" | "opts.snapshot";
|
|
170
|
+
readonly mode: "preview" | "commit" | "init";
|
|
171
|
+
};
|
|
172
|
+
type ResolveIdentityContext = {
|
|
173
|
+
readonly state: StorageRuntimeState;
|
|
174
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
175
|
+
readonly originalAction: ReadonlyManagerAction<AnyEvent>;
|
|
176
|
+
};
|
|
177
|
+
type StorageReactionContextBase = ActionAwareStorageContext & {
|
|
178
|
+
readonly manager: StorageManagerContext;
|
|
179
|
+
};
|
|
180
|
+
type MachineFacingStorageExtensionKey = "input" | "internalEvents" | "reducerContext" | "effectDeps" | "reactionDeps" | "resultMetadata" | "publicState";
|
|
181
|
+
export type RejectUnknownMachineExtensionKeys<Extension extends object> = {
|
|
182
|
+
readonly [Key in Exclude<keyof Extension, keyof StorageRuntimeExtension>]-?: never;
|
|
183
|
+
};
|
|
184
|
+
type StorageMachineFacingExtension<Extension extends StorageRuntimeExtension> = Pick<Extension, Extract<keyof Extension, MachineFacingStorageExtensionKey>>;
|
|
185
|
+
type ExtensionTemplateMachine<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
186
|
+
readonly input?: infer Input extends object;
|
|
187
|
+
} ? MachineStore[string] & Input : MachineStore[string];
|
|
188
|
+
type ExtensionTemplateData<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
189
|
+
readonly templateData?: infer TemplateData;
|
|
190
|
+
} ? TemplateData : unknown;
|
|
191
|
+
type ExtensionRuntimeState<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
192
|
+
readonly runtimeState?: infer RuntimeState;
|
|
193
|
+
} ? RuntimeState : unknown;
|
|
194
|
+
type ExtensionPublicState<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
195
|
+
readonly publicState?: infer PublicState;
|
|
196
|
+
} ? PublicState extends (...args: any[]) => infer Result ? Result : PublicState : unknown;
|
|
197
|
+
type ExtensionSnapshotData<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
198
|
+
readonly snapshotData?: infer SnapshotData;
|
|
199
|
+
} ? SnapshotData : unknown;
|
|
200
|
+
type ExtensionInvocation<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
201
|
+
readonly invocation?: infer Invocation;
|
|
202
|
+
} ? Invocation : unknown;
|
|
203
|
+
type ExtensionIdentity<Extension extends StorageRuntimeExtension> = Extension extends {
|
|
204
|
+
readonly identity?: infer Identity;
|
|
205
|
+
} ? Identity extends Readonly<Record<string, unknown>> ? Identity : Readonly<Record<string, unknown>> : Readonly<Record<string, unknown>>;
|
|
206
|
+
type ExtensionObservedEvents<Extension extends StorageRuntimeExtension> = "observedEvents" extends keyof Extension ? Extension extends {
|
|
207
|
+
readonly observedEvents?: infer Events extends AnyEvent;
|
|
208
|
+
} ? Events : AnyEvent : AnyEvent;
|
|
209
|
+
type ExtensionRouteMeta<Extension extends StorageRuntimeExtension> = "routeMeta" extends keyof Extension ? NonNullable<Extension["routeMeta"]> extends object ? NonNullable<Extension["routeMeta"]> : never : never;
|
|
210
|
+
export type StorageRouteMetaKeys<Extension extends StorageRuntimeExtension> = [ExtensionRouteMeta<Extension>] extends [
|
|
211
|
+
never
|
|
212
|
+
] ? readonly string[] : readonly (keyof ExtensionRouteMeta<Extension> & string)[];
|
|
213
|
+
export type StorageRequiredRouteMetaForKeys<Extension extends StorageRuntimeExtension, RouteMetaKeys> = [
|
|
214
|
+
ExtensionRouteMeta<Extension>
|
|
215
|
+
] extends [never] ? {} : RouteMetaKeys extends readonly (keyof ExtensionRouteMeta<Extension> & string)[] ? Pick<ExtensionRouteMeta<Extension>, RouteMetaKeys[number]> : {};
|
|
216
|
+
type WithObservedAction<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "action" | "originalAction"> & {
|
|
217
|
+
readonly action: ReadonlyManagerAction<ExtensionObservedEvents<Extension>>;
|
|
218
|
+
readonly originalAction: ReadonlyManagerAction<ExtensionObservedEvents<Extension>>;
|
|
219
|
+
};
|
|
220
|
+
type WithObservedManager<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "manager"> & {
|
|
221
|
+
readonly manager: StorageManagerContext<ExtensionObservedEvents<Extension>>;
|
|
222
|
+
};
|
|
223
|
+
type WithObservedPredicate<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "predicate"> & {
|
|
224
|
+
readonly predicate: (action: ReadonlyManagerAction<ExtensionObservedEvents<Extension>>) => boolean;
|
|
225
|
+
};
|
|
226
|
+
type WithRuntimeState<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "state"> & {
|
|
227
|
+
readonly state: ExtensionRuntimeState<Extension>;
|
|
228
|
+
};
|
|
229
|
+
type WithRuntimeTemplate<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "template" | "state"> & {
|
|
230
|
+
readonly template: StorageTemplate<ExtensionTemplateData<Extension>>;
|
|
231
|
+
readonly state: ExtensionRuntimeState<Extension>;
|
|
232
|
+
};
|
|
233
|
+
type WithRuntimeTemplates<Context, Extension extends StorageRuntimeExtension> = Omit<Context, "templates" | "state"> & {
|
|
234
|
+
readonly templates: readonly StorageTemplate<ExtensionTemplateData<Extension>>[];
|
|
235
|
+
readonly state: ExtensionRuntimeState<Extension>;
|
|
236
|
+
};
|
|
237
|
+
export type StorageValidateTemplateContext<Kind extends string, Extension extends StorageRuntimeExtension> = Omit<ValidateTemplateContext, "machine" | "storageKind"> & {
|
|
238
|
+
readonly storageKind: Kind;
|
|
239
|
+
readonly machine: ExtensionTemplateMachine<Extension>;
|
|
240
|
+
};
|
|
241
|
+
export type StorageCompileTemplateContext<Kind extends string, Extension extends StorageRuntimeExtension> = Omit<CompileTemplateContext, "machine" | "storageKind"> & {
|
|
242
|
+
readonly storageKind: Kind;
|
|
243
|
+
readonly machine: ExtensionTemplateMachine<Extension>;
|
|
244
|
+
};
|
|
245
|
+
export type StorageCreateRuntimeStateContext<Extension extends StorageRuntimeExtension> = Omit<WithObservedManager<CreateRuntimeStateContext, Extension>, "templates"> & {
|
|
246
|
+
readonly templates: readonly StorageTemplate<ExtensionTemplateData<Extension>>[];
|
|
247
|
+
};
|
|
248
|
+
export type StorageCreatePublicInitialStateContext<Extension extends StorageRuntimeExtension> = WithRuntimeTemplate<CreatePublicInitialStateContext, Extension>;
|
|
249
|
+
export type StoragePrepareActionContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedAction<StoragePrepareActionContextBase, Extension>, Extension>, Extension>;
|
|
250
|
+
export type StorageBeforeReduceContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedAction<StorageBeforeReduceContextBase, Extension>, Extension>, Extension>;
|
|
251
|
+
export type StorageAcceptsEventContext<Extension extends StorageRuntimeExtension> = WithRuntimeTemplate<WithObservedAction<AcceptsEventContext, Extension>, Extension>;
|
|
252
|
+
export type StorageReduceContext<Extension extends StorageRuntimeExtension> = WithRuntimeTemplate<WithObservedManager<WithObservedAction<StorageReduceContextBase, Extension>, Extension>, Extension>;
|
|
253
|
+
export type StorageReduceBucketContext<Extension extends StorageRuntimeExtension> = WithRuntimeTemplates<WithObservedManager<WithObservedAction<StorageReduceBucketContextBase, Extension>, Extension>, Extension>;
|
|
254
|
+
export type StorageCommitContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedAction<StorageCommitContextBase, Extension>, Extension>, Extension>;
|
|
255
|
+
export type StorageConditionContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedPredicate<StorageConditionContextBase, Extension>, Extension>, Extension>;
|
|
256
|
+
export type StorageResolveEffectInvocationsContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedAction<ResolveEffectInvocationsContext, Extension>, Extension>, Extension>;
|
|
257
|
+
export type StorageEffectInvocationContext<Extension extends StorageRuntimeExtension> = Omit<WithRuntimeState<WithObservedManager<WithObservedAction<StorageEffectInvocationContextBase, Extension>, Extension>, Extension>, "invocation"> & {
|
|
258
|
+
readonly invocation: ExtensionInvocation<Extension>;
|
|
259
|
+
};
|
|
260
|
+
export type StorageDehydrateContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<StorageDehydrateContextBase, Extension>, Extension>;
|
|
261
|
+
export type StorageHydrateContext<Extension extends StorageRuntimeExtension> = Omit<WithRuntimeState<WithObservedManager<StorageHydrateContextBase, Extension>, Extension>, "snapshot"> & {
|
|
262
|
+
readonly snapshot: ExtensionSnapshotData<Extension> | undefined;
|
|
263
|
+
};
|
|
264
|
+
export type StorageIdentityContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedAction<ResolveIdentityContext, Extension>, Extension>;
|
|
265
|
+
export type StorageReactionContext<Extension extends StorageRuntimeExtension> = WithRuntimeState<WithObservedManager<WithObservedAction<StorageReactionContextBase, Extension>, Extension>, Extension>;
|
|
266
|
+
export type StorageCompileTemplateResult<TemplateData = unknown> = void | {
|
|
267
|
+
readonly data?: TemplateData;
|
|
268
|
+
readonly key?: never;
|
|
269
|
+
readonly kind?: never;
|
|
270
|
+
};
|
|
271
|
+
export type StorageDehydrateResult<Extension extends StorageRuntimeExtension> = Omit<StorageDehydrateResultBase, "snapshot"> & {
|
|
272
|
+
readonly snapshot?: ExtensionSnapshotData<Extension>;
|
|
273
|
+
};
|
|
274
|
+
type PluginStorageEffectsRuntime<Extension extends StorageRuntimeExtension> = {
|
|
275
|
+
condition?(ctx: StorageConditionContext<Extension>): Promise<boolean>;
|
|
276
|
+
resolveInvocations(ctx: StorageResolveEffectInvocationsContext<Extension>): readonly ExtensionInvocation<Extension>[];
|
|
277
|
+
invoke(ctx: StorageEffectInvocationContext<Extension>): void;
|
|
278
|
+
};
|
|
279
|
+
type PluginStorageSnapshotRuntime<Extension extends StorageRuntimeExtension> = {
|
|
280
|
+
dehydrate(ctx: StorageDehydrateContext<Extension>): StorageDehydrateResult<Extension>;
|
|
281
|
+
hydrate(ctx: StorageHydrateContext<Extension>): StorageHydrateResult;
|
|
282
|
+
};
|
|
283
|
+
type PluginStorageIdentityRuntime<Extension extends StorageRuntimeExtension> = {
|
|
284
|
+
resolve(ctx: StorageIdentityContext<Extension>): ExtensionIdentity<Extension> | undefined;
|
|
285
|
+
};
|
|
286
|
+
type PluginStorageReactionRuntime<Extension extends StorageRuntimeExtension> = {
|
|
287
|
+
run(ctx: StorageReactionContext<Extension>): void;
|
|
288
|
+
};
|
|
289
|
+
type PluginStorageRuntimeBase<Kind extends string, Extension extends StorageRuntimeExtension, RouteMetaKeys extends StorageRouteMetaKeys<Extension> | undefined> = {
|
|
290
|
+
readonly kind: Kind;
|
|
291
|
+
readonly routeMetaKeys?: RouteMetaKeys;
|
|
292
|
+
validateTemplate(ctx: StorageValidateTemplateContext<Kind, Extension>): void;
|
|
293
|
+
compileTemplate(ctx: StorageCompileTemplateContext<Kind, Extension>): StorageCompileTemplateResult<ExtensionTemplateData<Extension>>;
|
|
294
|
+
createRuntimeState(ctx: StorageCreateRuntimeStateContext<Extension>): ExtensionRuntimeState<Extension>;
|
|
295
|
+
createPublicInitialState(ctx: StorageCreatePublicInitialStateContext<Extension>): ExtensionPublicState<Extension>;
|
|
296
|
+
prepareAction?(ctx: StoragePrepareActionContext<Extension>): StoragePrepareActionResult;
|
|
297
|
+
beforeReduce?(ctx: StorageBeforeReduceContext<Extension>): StorageActionStageResult;
|
|
298
|
+
commit(ctx: StorageCommitContext<Extension>): void;
|
|
299
|
+
readonly effects?: PluginStorageEffectsRuntime<Extension>;
|
|
300
|
+
readonly snapshot?: PluginStorageSnapshotRuntime<Extension>;
|
|
301
|
+
readonly identity?: PluginStorageIdentityRuntime<Extension>;
|
|
302
|
+
readonly reactions?: PluginStorageReactionRuntime<Extension>;
|
|
303
|
+
};
|
|
304
|
+
type PluginTemplateStorageRuntime<Kind extends string, Extension extends StorageRuntimeExtension, RouteMetaKeys extends StorageRouteMetaKeys<Extension> | undefined> = PluginStorageRuntimeBase<Kind, Extension, RouteMetaKeys> & {
|
|
305
|
+
readonly reduceScope?: "template";
|
|
306
|
+
acceptsEvent(ctx: StorageAcceptsEventContext<Extension>): boolean;
|
|
307
|
+
reduce(ctx: StorageReduceContext<Extension>): StorageReduceResult;
|
|
308
|
+
readonly reduceBucket?: never;
|
|
309
|
+
};
|
|
310
|
+
type PluginBucketStorageRuntime<Kind extends string, Extension extends StorageRuntimeExtension, RouteMetaKeys extends StorageRouteMetaKeys<Extension> | undefined> = PluginStorageRuntimeBase<Kind, Extension, RouteMetaKeys> & {
|
|
311
|
+
readonly reduceScope: "bucket";
|
|
312
|
+
reduceBucket(ctx: StorageReduceBucketContext<Extension>): StorageReduceResult;
|
|
313
|
+
readonly acceptsEvent?: never;
|
|
314
|
+
readonly reduce?: never;
|
|
315
|
+
};
|
|
316
|
+
export type PluginStorageRuntime<Kind extends string, Extension extends StorageRuntimeExtension, RouteMetaKeys extends StorageRouteMetaKeys<Extension> | undefined = StorageRouteMetaKeys<Extension> | undefined> = PluginTemplateStorageRuntime<Kind, Extension, RouteMetaKeys> | PluginBucketStorageRuntime<Kind, Extension, RouteMetaKeys>;
|
|
317
|
+
type Prettify<Value> = {
|
|
318
|
+
[Key in keyof Value]: Value[Key];
|
|
319
|
+
};
|
|
320
|
+
export type StorageMachineExtension<Kind extends string, Extension extends StorageRuntimeExtension> = Prettify<StorageMachineFacingExtension<Extension> & {
|
|
321
|
+
readonly storage: Kind;
|
|
322
|
+
}>;
|
|
323
|
+
export type StorageRuntimeBuilder<Extension extends StorageRuntimeExtension> = {
|
|
324
|
+
create<const Kind extends string, const RouteMetaKeys extends StorageRouteMetaKeys<Extension> | undefined = undefined>(definition: PluginStorageRuntime<Kind, Extension, RouteMetaKeys> & RejectUnknownMachineExtensionKeys<Extension>): LiteFsmStorageRuntimeDefinition<Kind, StorageMachineExtension<Kind, Extension>, StorageRequiredRouteMetaForKeys<Extension, RouteMetaKeys>>;
|
|
325
|
+
};
|
|
326
|
+
export {};
|