@lite-fsm/entities 0.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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/PERFORMANCE.md +537 -0
  3. package/README.md +395 -0
  4. package/dist/index.cjs +1 -0
  5. package/dist/index.d.cts +8 -0
  6. package/dist/index.d.ts +8 -0
  7. package/dist/index.js +1 -0
  8. package/dist/internal.d.cts +5 -0
  9. package/dist/internal.d.ts +5 -0
  10. package/dist/machine-extension.d.cts +153 -0
  11. package/dist/machine-extension.d.ts +153 -0
  12. package/dist/plugin.d.cts +32 -0
  13. package/dist/plugin.d.ts +32 -0
  14. package/dist/react/index.d.cts +11 -0
  15. package/dist/react/index.d.ts +11 -0
  16. package/dist/react.cjs +1 -0
  17. package/dist/react.js +1 -0
  18. package/dist/runtime/access.d.cts +72 -0
  19. package/dist/runtime/access.d.ts +72 -0
  20. package/dist/runtime/columns.d.cts +11 -0
  21. package/dist/runtime/columns.d.ts +11 -0
  22. package/dist/runtime/compile.d.cts +68 -0
  23. package/dist/runtime/compile.d.ts +68 -0
  24. package/dist/runtime/effects.d.cts +26 -0
  25. package/dist/runtime/effects.d.ts +26 -0
  26. package/dist/runtime/lifecycle.d.cts +10 -0
  27. package/dist/runtime/lifecycle.d.ts +10 -0
  28. package/dist/runtime/mutation-snapshot.d.cts +41 -0
  29. package/dist/runtime/mutation-snapshot.d.ts +41 -0
  30. package/dist/runtime/react.d.cts +29 -0
  31. package/dist/runtime/react.d.ts +29 -0
  32. package/dist/runtime/reactions.d.cts +15 -0
  33. package/dist/runtime/reactions.d.ts +15 -0
  34. package/dist/runtime/reduce-batch.d.cts +6 -0
  35. package/dist/runtime/reduce-batch.d.ts +6 -0
  36. package/dist/runtime/reduce-despawn.d.cts +7 -0
  37. package/dist/runtime/reduce-despawn.d.ts +7 -0
  38. package/dist/runtime/reduce-post-process.d.cts +35 -0
  39. package/dist/runtime/reduce-post-process.d.ts +35 -0
  40. package/dist/runtime/reduce-shared.d.cts +34 -0
  41. package/dist/runtime/reduce-shared.d.ts +34 -0
  42. package/dist/runtime/reduce-spawn.d.cts +5 -0
  43. package/dist/runtime/reduce-spawn.d.ts +5 -0
  44. package/dist/runtime/reduce-transitions.d.cts +11 -0
  45. package/dist/runtime/reduce-transitions.d.ts +11 -0
  46. package/dist/runtime/reduce.d.cts +5 -0
  47. package/dist/runtime/reduce.d.ts +5 -0
  48. package/dist/runtime/routing.d.cts +11 -0
  49. package/dist/runtime/routing.d.ts +11 -0
  50. package/dist/runtime/runtime-index.d.cts +23 -0
  51. package/dist/runtime/runtime-index.d.ts +23 -0
  52. package/dist/runtime/snapshot-export.d.cts +12 -0
  53. package/dist/runtime/snapshot-export.d.ts +12 -0
  54. package/dist/runtime/snapshot-import.d.cts +5 -0
  55. package/dist/runtime/snapshot-import.d.ts +5 -0
  56. package/dist/runtime/snapshot-types.d.cts +56 -0
  57. package/dist/runtime/snapshot-types.d.ts +56 -0
  58. package/dist/runtime/snapshot.d.cts +15 -0
  59. package/dist/runtime/snapshot.d.ts +15 -0
  60. package/dist/runtime/spawn-commit.d.cts +10 -0
  61. package/dist/runtime/spawn-commit.d.ts +10 -0
  62. package/dist/runtime/state.d.cts +15 -0
  63. package/dist/runtime/state.d.ts +15 -0
  64. package/dist/runtime/storage.d.cts +19 -0
  65. package/dist/runtime/storage.d.ts +19 -0
  66. package/dist/runtime/store-types.d.cts +81 -0
  67. package/dist/runtime/store-types.d.ts +81 -0
  68. package/dist/runtime/transaction.d.cts +104 -0
  69. package/dist/runtime/transaction.d.ts +104 -0
  70. package/dist/runtime/transitionTrace.d.cts +19 -0
  71. package/dist/runtime/transitionTrace.d.ts +19 -0
  72. package/dist/schema.d.cts +90 -0
  73. package/dist/schema.d.ts +90 -0
  74. package/dist/spawn.d.cts +56 -0
  75. package/dist/spawn.d.ts +56 -0
  76. package/package.json +90 -0
@@ -0,0 +1,72 @@
1
+ import type { ActorPublicState, MachineStore } from "@lite-fsm/core";
2
+ import type { EntityIndex } from "../plugin";
3
+ import type { EntitySchemaResourceViews, EntitySchemaValue, EntityContextSchema } from "../schema";
4
+ import type { ColumnarActorStore, EntityRuntimeState } from "./state";
5
+ import type { CapturedEntityScopeEntry } from "./transaction";
6
+ export type ReadonlyEntityColumn<T> = {
7
+ readonly [entity: EntityIndex]: T;
8
+ };
9
+ type Prettify<Value> = {
10
+ [Key in keyof Value]: Value[Key];
11
+ } & {};
12
+ type EntityActorMachine = {
13
+ readonly storage: "entity";
14
+ readonly config: object;
15
+ readonly initialContext: EntityContextSchema;
16
+ };
17
+ export type EntityActorKey<AppMachines extends MachineStore> = {
18
+ readonly [Key in keyof AppMachines]: AppMachines[Key] extends EntityActorMachine ? Key : never;
19
+ }[keyof AppMachines] & string;
20
+ export type EntityContextFor<AppMachines extends MachineStore, Key extends EntityActorKey<AppMachines>> = EntityContextSchemaFor<AppMachines, Key> extends infer Context extends EntityContextSchema ? EntitySchemaValue<Context> : never;
21
+ type EntityContextSchemaFor<AppMachines extends MachineStore, Key extends EntityActorKey<AppMachines>> = AppMachines[Key] extends {
22
+ readonly initialContext: infer Context extends EntityContextSchema;
23
+ } ? Context : never;
24
+ export type EntityStateFor<AppMachines extends MachineStore, Key extends EntityActorKey<AppMachines>> = AppMachines[Key] extends {
25
+ readonly config: infer Config extends object;
26
+ } ? ActorPublicState<Config> : never;
27
+ type EntityActorStoreViewFor<AppMachines extends MachineStore, Key extends EntityActorKey<AppMachines>> = Prettify<{
28
+ readonly count: number;
29
+ readonly version: number;
30
+ has(entity: EntityIndex): boolean;
31
+ state(entity: EntityIndex): EntityStateFor<AppMachines, Key> | undefined;
32
+ } & {
33
+ readonly [Field in keyof EntityContextFor<AppMachines, Key>]: ReadonlyEntityColumn<EntityContextFor<AppMachines, Key>[Field]>;
34
+ } & EntitySchemaResourceViews<EntityContextSchemaFor<AppMachines, Key>>>;
35
+ export type EntityAccess<AppMachines extends MachineStore> = {
36
+ get<Key extends EntityActorKey<AppMachines>>(key: Key): EntityActorStoreViewFor<AppMachines, Key>;
37
+ maybe<Key extends EntityActorKey<AppMachines>>(key: Key): EntityActorStoreViewFor<AppMachines, Key>;
38
+ };
39
+ export type EntityAccessScope = {
40
+ readonly sourceActor: string;
41
+ readonly eventType: string;
42
+ readonly entries: readonly CapturedEntityScopeEntry[];
43
+ };
44
+ type ScopedEntitySelfOptions = {
45
+ readonly scopeName: "effect";
46
+ readonly indices: readonly EntityIndex[];
47
+ readonly entries: readonly CapturedEntityScopeEntry[];
48
+ };
49
+ export type EntityReactionScope = {
50
+ readonly indices: readonly EntityIndex[];
51
+ readonly markers: Uint32Array;
52
+ readonly generation: Uint32Array;
53
+ readonly lifetime: {
54
+ readonly token: number;
55
+ };
56
+ readonly token: number;
57
+ };
58
+ export declare const capturedEntityScopeEntryIsLive: (runtime: EntityRuntimeState, entry: CapturedEntityScopeEntry) => boolean;
59
+ export declare const rebindEntityStoreView: (store: ColumnarActorStore) => void;
60
+ export declare const createEntityAccess: (runtime: EntityRuntimeState) => EntityAccess<MachineStore>;
61
+ type ActorSelfCore = {
62
+ readonly indices: readonly EntityIndex[];
63
+ has(entity: EntityIndex): boolean;
64
+ entityId(entity: EntityIndex): string;
65
+ };
66
+ export declare const assignActorSelfFields: (self: Record<string, unknown>, store: ColumnarActorStore) => void;
67
+ export declare const createActorSelf: (store: ColumnarActorStore, core: ActorSelfCore) => Record<string, unknown>;
68
+ export declare const createScopedEntitySelf: (runtime: EntityRuntimeState, store: ColumnarActorStore, options: ScopedEntitySelfOptions) => Record<string, unknown>;
69
+ export declare const createReactionEntitySelf: (runtime: EntityRuntimeState, store: ColumnarActorStore, scope: EntityReactionScope) => Record<string, unknown>;
70
+ export declare const createReactionEntityAccess: (runtime: EntityRuntimeState) => EntityAccess<MachineStore>;
71
+ export declare const createScopedEntityAccess: (runtime: EntityRuntimeState, scope: EntityAccessScope) => EntityAccess<MachineStore>;
72
+ export {};
@@ -0,0 +1,72 @@
1
+ import type { ActorPublicState, MachineStore } from "@lite-fsm/core";
2
+ import type { EntityIndex } from "../plugin";
3
+ import type { EntitySchemaResourceViews, EntitySchemaValue, EntityContextSchema } from "../schema";
4
+ import type { ColumnarActorStore, EntityRuntimeState } from "./state";
5
+ import type { CapturedEntityScopeEntry } from "./transaction";
6
+ export type ReadonlyEntityColumn<T> = {
7
+ readonly [entity: EntityIndex]: T;
8
+ };
9
+ type Prettify<Value> = {
10
+ [Key in keyof Value]: Value[Key];
11
+ } & {};
12
+ type EntityActorMachine = {
13
+ readonly storage: "entity";
14
+ readonly config: object;
15
+ readonly initialContext: EntityContextSchema;
16
+ };
17
+ export type EntityActorKey<AppMachines extends MachineStore> = {
18
+ readonly [Key in keyof AppMachines]: AppMachines[Key] extends EntityActorMachine ? Key : never;
19
+ }[keyof AppMachines] & string;
20
+ export type EntityContextFor<AppMachines extends MachineStore, Key extends EntityActorKey<AppMachines>> = EntityContextSchemaFor<AppMachines, Key> extends infer Context extends EntityContextSchema ? EntitySchemaValue<Context> : never;
21
+ type EntityContextSchemaFor<AppMachines extends MachineStore, Key extends EntityActorKey<AppMachines>> = AppMachines[Key] extends {
22
+ readonly initialContext: infer Context extends EntityContextSchema;
23
+ } ? Context : never;
24
+ export type EntityStateFor<AppMachines extends MachineStore, Key extends EntityActorKey<AppMachines>> = AppMachines[Key] extends {
25
+ readonly config: infer Config extends object;
26
+ } ? ActorPublicState<Config> : never;
27
+ type EntityActorStoreViewFor<AppMachines extends MachineStore, Key extends EntityActorKey<AppMachines>> = Prettify<{
28
+ readonly count: number;
29
+ readonly version: number;
30
+ has(entity: EntityIndex): boolean;
31
+ state(entity: EntityIndex): EntityStateFor<AppMachines, Key> | undefined;
32
+ } & {
33
+ readonly [Field in keyof EntityContextFor<AppMachines, Key>]: ReadonlyEntityColumn<EntityContextFor<AppMachines, Key>[Field]>;
34
+ } & EntitySchemaResourceViews<EntityContextSchemaFor<AppMachines, Key>>>;
35
+ export type EntityAccess<AppMachines extends MachineStore> = {
36
+ get<Key extends EntityActorKey<AppMachines>>(key: Key): EntityActorStoreViewFor<AppMachines, Key>;
37
+ maybe<Key extends EntityActorKey<AppMachines>>(key: Key): EntityActorStoreViewFor<AppMachines, Key>;
38
+ };
39
+ export type EntityAccessScope = {
40
+ readonly sourceActor: string;
41
+ readonly eventType: string;
42
+ readonly entries: readonly CapturedEntityScopeEntry[];
43
+ };
44
+ type ScopedEntitySelfOptions = {
45
+ readonly scopeName: "effect";
46
+ readonly indices: readonly EntityIndex[];
47
+ readonly entries: readonly CapturedEntityScopeEntry[];
48
+ };
49
+ export type EntityReactionScope = {
50
+ readonly indices: readonly EntityIndex[];
51
+ readonly markers: Uint32Array;
52
+ readonly generation: Uint32Array;
53
+ readonly lifetime: {
54
+ readonly token: number;
55
+ };
56
+ readonly token: number;
57
+ };
58
+ export declare const capturedEntityScopeEntryIsLive: (runtime: EntityRuntimeState, entry: CapturedEntityScopeEntry) => boolean;
59
+ export declare const rebindEntityStoreView: (store: ColumnarActorStore) => void;
60
+ export declare const createEntityAccess: (runtime: EntityRuntimeState) => EntityAccess<MachineStore>;
61
+ type ActorSelfCore = {
62
+ readonly indices: readonly EntityIndex[];
63
+ has(entity: EntityIndex): boolean;
64
+ entityId(entity: EntityIndex): string;
65
+ };
66
+ export declare const assignActorSelfFields: (self: Record<string, unknown>, store: ColumnarActorStore) => void;
67
+ export declare const createActorSelf: (store: ColumnarActorStore, core: ActorSelfCore) => Record<string, unknown>;
68
+ export declare const createScopedEntitySelf: (runtime: EntityRuntimeState, store: ColumnarActorStore, options: ScopedEntitySelfOptions) => Record<string, unknown>;
69
+ export declare const createReactionEntitySelf: (runtime: EntityRuntimeState, store: ColumnarActorStore, scope: EntityReactionScope) => Record<string, unknown>;
70
+ export declare const createReactionEntityAccess: (runtime: EntityRuntimeState) => EntityAccess<MachineStore>;
71
+ export declare const createScopedEntityAccess: (runtime: EntityRuntimeState, scope: EntityAccessScope) => EntityAccess<MachineStore>;
72
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { EntityDescriptor } from "../schema";
2
+ import type { EntityColumn } from "./store-types";
3
+ type EntityColumnDescriptor = EntityDescriptor;
4
+ export declare const createEmptyColumn: (descriptor: EntityColumnDescriptor) => EntityColumn;
5
+ export declare const growColumn: (column: EntityColumn, descriptor: EntityColumnDescriptor, capacity: number) => EntityColumn;
6
+ export declare const growInt16: (value: Int16Array, capacity: number, fillValue?: number) => Int16Array;
7
+ export declare const growInt32: (value: Int32Array, capacity: number, fillValue?: number) => Int32Array;
8
+ export declare const growUint8: (value: Uint8Array, capacity: number) => Uint8Array;
9
+ export declare const growUint32: (value: Uint32Array, capacity: number) => Uint32Array;
10
+ export declare const getInitialColumnValue: (descriptor: EntityColumnDescriptor) => number | string;
11
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { EntityDescriptor } from "../schema";
2
+ import type { EntityColumn } from "./store-types";
3
+ type EntityColumnDescriptor = EntityDescriptor;
4
+ export declare const createEmptyColumn: (descriptor: EntityColumnDescriptor) => EntityColumn;
5
+ export declare const growColumn: (column: EntityColumn, descriptor: EntityColumnDescriptor, capacity: number) => EntityColumn;
6
+ export declare const growInt16: (value: Int16Array, capacity: number, fillValue?: number) => Int16Array;
7
+ export declare const growInt32: (value: Int32Array, capacity: number, fillValue?: number) => Int32Array;
8
+ export declare const growUint8: (value: Uint8Array, capacity: number) => Uint8Array;
9
+ export declare const growUint32: (value: Uint32Array, capacity: number) => Uint32Array;
10
+ export declare const getInitialColumnValue: (descriptor: EntityColumnDescriptor) => number | string;
11
+ export {};
@@ -0,0 +1,68 @@
1
+ import type { AnyEvent, ManagerAction } from "@lite-fsm/core";
2
+ import { type EntityColumnSchema, type EntityContextSchema, type EntityResourceSchema, type EntitySpawnSchema } from "../schema";
3
+ export declare const ENTITY_INIT_STATE = "__INIT";
4
+ export declare const ENTITY_INIT_STATE_CODE = -1;
5
+ export declare const ENTITY_RESOLVED_STATE_CODE = -2;
6
+ export declare const ENTITY_REJECTED_STATE_CODE = -3;
7
+ export declare const ENTITY_CANCELLED_STATE_CODE = -4;
8
+ export declare const ENTITY_NO_TRANSITION = -32768;
9
+ export declare const ENTITY_INVALID_TRANSITION_TARGET = -32767;
10
+ type EntityActorReducer = (state: {
11
+ readonly state: string;
12
+ readonly context: Record<string, unknown>;
13
+ }, action: ManagerAction<AnyEvent>, meta: Record<string, unknown>) => unknown;
14
+ export type EntityActorEffect = (deps: Record<string, unknown>) => unknown;
15
+ export type EntityActorReaction = (deps: Record<string, unknown>) => unknown;
16
+ export type EntityReducePlan = {
17
+ readonly eventCode: number;
18
+ readonly acceptStateCodes: readonly number[];
19
+ readonly allDefaultTransitionsIdentity: boolean;
20
+ readonly hasNonIdentityDefaultTransition: boolean;
21
+ readonly mayEnterEffectState: boolean;
22
+ readonly hasDespawnOnStates: boolean;
23
+ readonly hasReaction: boolean;
24
+ readonly mayEnterTerminalState: boolean;
25
+ readonly requiresReducerCall: boolean;
26
+ };
27
+ export type EntityTemplateMetadata = {
28
+ readonly templateKey: string;
29
+ readonly config: Record<string, Record<string, string | null | undefined> | undefined>;
30
+ readonly initialContext: EntityColumnSchema;
31
+ readonly resourceSchema: EntityResourceSchema;
32
+ readonly spawnSchema: EntitySpawnSchema;
33
+ readonly publicStates: readonly string[];
34
+ readonly stateCodeByName: Readonly<Record<string, number>>;
35
+ readonly eventTypes: readonly string[];
36
+ readonly eventAcceptMask: Uint8Array;
37
+ readonly transitionTable: Int16Array;
38
+ readonly transitionTargetByCell: Readonly<Record<number, string>>;
39
+ readonly acceptStateCodesByEventCode: readonly (readonly number[])[];
40
+ readonly stateSlotCount: number;
41
+ readonly despawnStateMask: Uint8Array;
42
+ readonly despawnLifecycleStateMask: Uint8Array;
43
+ readonly effectsByStateCode: readonly (EntityActorEffect | undefined)[];
44
+ readonly reactionsByEventType: Readonly<Record<string, EntityActorReaction>>;
45
+ readonly reactionsByEventCode: readonly (EntityActorReaction | undefined)[];
46
+ readonly reducePlansByEventCode: readonly EntityReducePlan[];
47
+ readonly reducer?: EntityActorReducer;
48
+ };
49
+ export type EntityCompiledRuntimeMetadata = {
50
+ readonly eventCodeByType: Readonly<Record<string, number>>;
51
+ readonly eventTypesByCode: readonly string[];
52
+ readonly metadataByKey: Readonly<Record<string, EntityTemplateMetadata>>;
53
+ };
54
+ export declare const isTerminalStateCode: (code: number) => boolean;
55
+ export declare const hasDespawnOnStates: (despawnStateMask: Uint8Array) => boolean;
56
+ export declare const compileEntityTemplate: (templateKey: string, machine: {
57
+ readonly config: object;
58
+ readonly initialContext: EntityContextSchema;
59
+ readonly spawnSchema: EntitySpawnSchema;
60
+ readonly despawnOn?: unknown;
61
+ readonly effects?: unknown;
62
+ readonly reactions?: unknown;
63
+ readonly reducer?: unknown;
64
+ }) => EntityTemplateMetadata;
65
+ export declare const compileEntityRuntimeMetadata: (templates: readonly EntityTemplateMetadata[]) => EntityCompiledRuntimeMetadata;
66
+ export declare const getEntityStateName: (metadata: EntityTemplateMetadata, code: number) => string | undefined;
67
+ export declare const getEntityStateCode: (metadata: EntityTemplateMetadata, state: string) => number | undefined;
68
+ export {};
@@ -0,0 +1,68 @@
1
+ import type { AnyEvent, ManagerAction } from "@lite-fsm/core";
2
+ import { type EntityColumnSchema, type EntityContextSchema, type EntityResourceSchema, type EntitySpawnSchema } from "../schema";
3
+ export declare const ENTITY_INIT_STATE = "__INIT";
4
+ export declare const ENTITY_INIT_STATE_CODE = -1;
5
+ export declare const ENTITY_RESOLVED_STATE_CODE = -2;
6
+ export declare const ENTITY_REJECTED_STATE_CODE = -3;
7
+ export declare const ENTITY_CANCELLED_STATE_CODE = -4;
8
+ export declare const ENTITY_NO_TRANSITION = -32768;
9
+ export declare const ENTITY_INVALID_TRANSITION_TARGET = -32767;
10
+ type EntityActorReducer = (state: {
11
+ readonly state: string;
12
+ readonly context: Record<string, unknown>;
13
+ }, action: ManagerAction<AnyEvent>, meta: Record<string, unknown>) => unknown;
14
+ export type EntityActorEffect = (deps: Record<string, unknown>) => unknown;
15
+ export type EntityActorReaction = (deps: Record<string, unknown>) => unknown;
16
+ export type EntityReducePlan = {
17
+ readonly eventCode: number;
18
+ readonly acceptStateCodes: readonly number[];
19
+ readonly allDefaultTransitionsIdentity: boolean;
20
+ readonly hasNonIdentityDefaultTransition: boolean;
21
+ readonly mayEnterEffectState: boolean;
22
+ readonly hasDespawnOnStates: boolean;
23
+ readonly hasReaction: boolean;
24
+ readonly mayEnterTerminalState: boolean;
25
+ readonly requiresReducerCall: boolean;
26
+ };
27
+ export type EntityTemplateMetadata = {
28
+ readonly templateKey: string;
29
+ readonly config: Record<string, Record<string, string | null | undefined> | undefined>;
30
+ readonly initialContext: EntityColumnSchema;
31
+ readonly resourceSchema: EntityResourceSchema;
32
+ readonly spawnSchema: EntitySpawnSchema;
33
+ readonly publicStates: readonly string[];
34
+ readonly stateCodeByName: Readonly<Record<string, number>>;
35
+ readonly eventTypes: readonly string[];
36
+ readonly eventAcceptMask: Uint8Array;
37
+ readonly transitionTable: Int16Array;
38
+ readonly transitionTargetByCell: Readonly<Record<number, string>>;
39
+ readonly acceptStateCodesByEventCode: readonly (readonly number[])[];
40
+ readonly stateSlotCount: number;
41
+ readonly despawnStateMask: Uint8Array;
42
+ readonly despawnLifecycleStateMask: Uint8Array;
43
+ readonly effectsByStateCode: readonly (EntityActorEffect | undefined)[];
44
+ readonly reactionsByEventType: Readonly<Record<string, EntityActorReaction>>;
45
+ readonly reactionsByEventCode: readonly (EntityActorReaction | undefined)[];
46
+ readonly reducePlansByEventCode: readonly EntityReducePlan[];
47
+ readonly reducer?: EntityActorReducer;
48
+ };
49
+ export type EntityCompiledRuntimeMetadata = {
50
+ readonly eventCodeByType: Readonly<Record<string, number>>;
51
+ readonly eventTypesByCode: readonly string[];
52
+ readonly metadataByKey: Readonly<Record<string, EntityTemplateMetadata>>;
53
+ };
54
+ export declare const isTerminalStateCode: (code: number) => boolean;
55
+ export declare const hasDespawnOnStates: (despawnStateMask: Uint8Array) => boolean;
56
+ export declare const compileEntityTemplate: (templateKey: string, machine: {
57
+ readonly config: object;
58
+ readonly initialContext: EntityContextSchema;
59
+ readonly spawnSchema: EntitySpawnSchema;
60
+ readonly despawnOn?: unknown;
61
+ readonly effects?: unknown;
62
+ readonly reactions?: unknown;
63
+ readonly reducer?: unknown;
64
+ }) => EntityTemplateMetadata;
65
+ export declare const compileEntityRuntimeMetadata: (templates: readonly EntityTemplateMetadata[]) => EntityCompiledRuntimeMetadata;
66
+ export declare const getEntityStateName: (metadata: EntityTemplateMetadata, code: number) => string | undefined;
67
+ export declare const getEntityStateCode: (metadata: EntityTemplateMetadata, state: string) => number | undefined;
68
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { AnyEvent, ReadonlyManagerAction, StorageManagerContext } from "@lite-fsm/core";
2
+ import type { EntityIndex } from "../plugin";
3
+ import { type EntityAccessScope } from "./access";
4
+ import type { EntityRuntimeState } from "./state";
5
+ export type EntityEffectInvocation = {
6
+ readonly storeKey: string;
7
+ readonly stateCode: number;
8
+ readonly indices: readonly EntityIndex[];
9
+ readonly scope: EntityAccessScope;
10
+ };
11
+ type EffectResolveContext = {
12
+ readonly action: ReadonlyManagerAction<AnyEvent>;
13
+ readonly dispatch: {
14
+ readonly runtime: Map<string, unknown>;
15
+ };
16
+ };
17
+ type EffectInvokeContext = {
18
+ readonly action: ReadonlyManagerAction<AnyEvent>;
19
+ readonly manager: StorageManagerContext<AnyEvent>;
20
+ readonly dispatch: {
21
+ reportError(error: unknown): void;
22
+ };
23
+ };
24
+ export declare const resolveEntityEffectInvocations: (runtime: EntityRuntimeState, ctx: EffectResolveContext) => readonly EntityEffectInvocation[];
25
+ export declare const invokeEntityEffect: (runtime: EntityRuntimeState, invocation: EntityEffectInvocation, ctx: EffectInvokeContext) => void;
26
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { AnyEvent, ReadonlyManagerAction, StorageManagerContext } from "@lite-fsm/core";
2
+ import type { EntityIndex } from "../plugin";
3
+ import { type EntityAccessScope } from "./access";
4
+ import type { EntityRuntimeState } from "./state";
5
+ export type EntityEffectInvocation = {
6
+ readonly storeKey: string;
7
+ readonly stateCode: number;
8
+ readonly indices: readonly EntityIndex[];
9
+ readonly scope: EntityAccessScope;
10
+ };
11
+ type EffectResolveContext = {
12
+ readonly action: ReadonlyManagerAction<AnyEvent>;
13
+ readonly dispatch: {
14
+ readonly runtime: Map<string, unknown>;
15
+ };
16
+ };
17
+ type EffectInvokeContext = {
18
+ readonly action: ReadonlyManagerAction<AnyEvent>;
19
+ readonly manager: StorageManagerContext<AnyEvent>;
20
+ readonly dispatch: {
21
+ reportError(error: unknown): void;
22
+ };
23
+ };
24
+ export declare const resolveEntityEffectInvocations: (runtime: EntityRuntimeState, ctx: EffectResolveContext) => readonly EntityEffectInvocation[];
25
+ export declare const invokeEntityEffect: (runtime: EntityRuntimeState, invocation: EntityEffectInvocation, ctx: EffectInvokeContext) => void;
26
+ export {};
@@ -0,0 +1,10 @@
1
+ export type LiteFsmEntityLifecycleEvents = {
2
+ readonly type: "ENTITY_SPAWNED";
3
+ } | {
4
+ readonly type: "ENTITY_DESPAWNED";
5
+ };
6
+ export declare const ENTITY_SPAWNED: LiteFsmEntityLifecycleEvents["type"];
7
+ export declare const ENTITY_DESPAWNED: LiteFsmEntityLifecycleEvents["type"];
8
+ export declare const isEntityLifecycleEventType: (eventType: string) => eventType is LiteFsmEntityLifecycleEvents["type"];
9
+ export declare const assertPublicEntityLifecycleDispatch: (eventType: string) => void;
10
+ export declare const assertEntityInitLifecycleConfig: (machineKey: string, config: unknown) => void;
@@ -0,0 +1,10 @@
1
+ export type LiteFsmEntityLifecycleEvents = {
2
+ readonly type: "ENTITY_SPAWNED";
3
+ } | {
4
+ readonly type: "ENTITY_DESPAWNED";
5
+ };
6
+ export declare const ENTITY_SPAWNED: LiteFsmEntityLifecycleEvents["type"];
7
+ export declare const ENTITY_DESPAWNED: LiteFsmEntityLifecycleEvents["type"];
8
+ export declare const isEntityLifecycleEventType: (eventType: string) => eventType is LiteFsmEntityLifecycleEvents["type"];
9
+ export declare const assertPublicEntityLifecycleDispatch: (eventType: string) => void;
10
+ export declare const assertEntityInitLifecycleConfig: (machineKey: string, config: unknown) => void;
@@ -0,0 +1,41 @@
1
+ import type { EntityIndex } from "../plugin";
2
+ import { type ColumnarActorStore, type EntityActorRowRef, type EntityColumn, type EntityRuntimeState } from "./state";
3
+ type EntityStoreMutationSnapshot = {
4
+ readonly count: number;
5
+ readonly capacity: number;
6
+ readonly ids: string[];
7
+ readonly indexById: Record<string, EntityIndex>;
8
+ readonly alive: Uint8Array;
9
+ readonly generation: Uint32Array;
10
+ readonly groupTagByIndex: string[];
11
+ readonly entitiesByGroupTag: Record<string, EntityIndex[]>;
12
+ readonly groupTagPosition: Int32Array;
13
+ readonly freeList: EntityIndex[];
14
+ readonly version: number;
15
+ };
16
+ type ActorStoreMutationSnapshot = {
17
+ readonly capacity: number;
18
+ readonly count: number;
19
+ readonly version: number;
20
+ readonly presence: Uint8Array;
21
+ readonly stateCode: Int16Array;
22
+ readonly prevStateCode: Int16Array;
23
+ readonly rowVersion: Uint32Array;
24
+ readonly stateBuckets: EntityIndex[][];
25
+ readonly statePosition: Int32Array;
26
+ readonly acceptedScratch: EntityIndex[];
27
+ readonly pendingPrevStateCodeSync: EntityIndex[];
28
+ readonly pendingPrevStateCodeSyncMark: Uint32Array;
29
+ readonly pendingPrevStateCodeSyncToken: number;
30
+ readonly columns: Record<string, EntityColumn>;
31
+ readonly publicSlice: ColumnarActorStore["publicSlice"];
32
+ };
33
+ type RuntimeMutationSnapshot = {
34
+ readonly entityStore: EntityStoreMutationSnapshot;
35
+ readonly actorStores: Record<string, ActorStoreMutationSnapshot>;
36
+ readonly actorRowsByEntity: EntityActorRowRef[][];
37
+ readonly actorRowsByGroupTag: Record<string, EntityActorRowRef[]>;
38
+ };
39
+ export declare const snapshotRuntimeMutation: (runtime: EntityRuntimeState) => RuntimeMutationSnapshot;
40
+ export declare const restoreRuntimeMutation: (runtime: EntityRuntimeState, snapshot: RuntimeMutationSnapshot) => void;
41
+ export {};
@@ -0,0 +1,41 @@
1
+ import type { EntityIndex } from "../plugin";
2
+ import { type ColumnarActorStore, type EntityActorRowRef, type EntityColumn, type EntityRuntimeState } from "./state";
3
+ type EntityStoreMutationSnapshot = {
4
+ readonly count: number;
5
+ readonly capacity: number;
6
+ readonly ids: string[];
7
+ readonly indexById: Record<string, EntityIndex>;
8
+ readonly alive: Uint8Array;
9
+ readonly generation: Uint32Array;
10
+ readonly groupTagByIndex: string[];
11
+ readonly entitiesByGroupTag: Record<string, EntityIndex[]>;
12
+ readonly groupTagPosition: Int32Array;
13
+ readonly freeList: EntityIndex[];
14
+ readonly version: number;
15
+ };
16
+ type ActorStoreMutationSnapshot = {
17
+ readonly capacity: number;
18
+ readonly count: number;
19
+ readonly version: number;
20
+ readonly presence: Uint8Array;
21
+ readonly stateCode: Int16Array;
22
+ readonly prevStateCode: Int16Array;
23
+ readonly rowVersion: Uint32Array;
24
+ readonly stateBuckets: EntityIndex[][];
25
+ readonly statePosition: Int32Array;
26
+ readonly acceptedScratch: EntityIndex[];
27
+ readonly pendingPrevStateCodeSync: EntityIndex[];
28
+ readonly pendingPrevStateCodeSyncMark: Uint32Array;
29
+ readonly pendingPrevStateCodeSyncToken: number;
30
+ readonly columns: Record<string, EntityColumn>;
31
+ readonly publicSlice: ColumnarActorStore["publicSlice"];
32
+ };
33
+ type RuntimeMutationSnapshot = {
34
+ readonly entityStore: EntityStoreMutationSnapshot;
35
+ readonly actorStores: Record<string, ActorStoreMutationSnapshot>;
36
+ readonly actorRowsByEntity: EntityActorRowRef[][];
37
+ readonly actorRowsByGroupTag: Record<string, EntityActorRowRef[]>;
38
+ };
39
+ export declare const snapshotRuntimeMutation: (runtime: EntityRuntimeState) => RuntimeMutationSnapshot;
40
+ export declare const restoreRuntimeMutation: (runtime: EntityRuntimeState, snapshot: RuntimeMutationSnapshot) => void;
41
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { MachineStore } from "@lite-fsm/core";
2
+ import type { EntityId } from "../plugin";
3
+ import type { EntityActorKey, EntityContextFor, EntityStateFor } from "./access";
4
+ import type { EntityRuntimeState } from "./state";
5
+ export type EntityRowSnapshot<Context, State extends string = string> = {
6
+ readonly entityId: EntityId;
7
+ readonly groupTag: string;
8
+ readonly state: State;
9
+ readonly context: Context;
10
+ };
11
+ export type EntityListOptions = {
12
+ readonly groupTag?: string;
13
+ };
14
+ export type TypedUseEntitySnapshotHook<AppMachines extends MachineStore> = <Key extends EntityActorKey<AppMachines>>(templateKey: Key, entityId: EntityId | null | undefined) => EntityRowSnapshot<EntityContextFor<AppMachines, Key>, EntityStateFor<AppMachines, Key>> | undefined;
15
+ export type TypedUseEntityCountHook<AppMachines extends MachineStore> = <Key extends EntityActorKey<AppMachines>>(templateKey: Key, options?: EntityListOptions) => number;
16
+ export type TypedUseEntityListHook<AppMachines extends MachineStore> = <Key extends EntityActorKey<AppMachines>>(templateKey: Key, options?: EntityListOptions) => readonly EntityId[];
17
+ export type EntityReadMode = {
18
+ readonly mode: "commit";
19
+ } | {
20
+ readonly mode: "preview";
21
+ readonly snapshot: unknown;
22
+ };
23
+ export type EntityReactRuntime = {
24
+ readRow(templateKey: string, entityId: EntityId | null | undefined, mode: EntityReadMode): EntityRowSnapshot<Record<string, unknown>, string> | undefined;
25
+ readCount(templateKey: string, options: EntityListOptions | undefined, mode: EntityReadMode): number;
26
+ readList(templateKey: string, options: EntityListOptions | undefined, mode: EntityReadMode): readonly EntityId[];
27
+ };
28
+ export declare const createEntityReactRuntime: (runtime: EntityRuntimeState) => EntityReactRuntime;
29
+ export type EntityHookRowSnapshot<AppMachines extends MachineStore, Key extends EntityActorKey<AppMachines>> = EntityRowSnapshot<EntityContextFor<AppMachines, Key>, EntityStateFor<AppMachines, Key>>;
@@ -0,0 +1,29 @@
1
+ import type { MachineStore } from "@lite-fsm/core";
2
+ import type { EntityId } from "../plugin";
3
+ import type { EntityActorKey, EntityContextFor, EntityStateFor } from "./access";
4
+ import type { EntityRuntimeState } from "./state";
5
+ export type EntityRowSnapshot<Context, State extends string = string> = {
6
+ readonly entityId: EntityId;
7
+ readonly groupTag: string;
8
+ readonly state: State;
9
+ readonly context: Context;
10
+ };
11
+ export type EntityListOptions = {
12
+ readonly groupTag?: string;
13
+ };
14
+ export type TypedUseEntitySnapshotHook<AppMachines extends MachineStore> = <Key extends EntityActorKey<AppMachines>>(templateKey: Key, entityId: EntityId | null | undefined) => EntityRowSnapshot<EntityContextFor<AppMachines, Key>, EntityStateFor<AppMachines, Key>> | undefined;
15
+ export type TypedUseEntityCountHook<AppMachines extends MachineStore> = <Key extends EntityActorKey<AppMachines>>(templateKey: Key, options?: EntityListOptions) => number;
16
+ export type TypedUseEntityListHook<AppMachines extends MachineStore> = <Key extends EntityActorKey<AppMachines>>(templateKey: Key, options?: EntityListOptions) => readonly EntityId[];
17
+ export type EntityReadMode = {
18
+ readonly mode: "commit";
19
+ } | {
20
+ readonly mode: "preview";
21
+ readonly snapshot: unknown;
22
+ };
23
+ export type EntityReactRuntime = {
24
+ readRow(templateKey: string, entityId: EntityId | null | undefined, mode: EntityReadMode): EntityRowSnapshot<Record<string, unknown>, string> | undefined;
25
+ readCount(templateKey: string, options: EntityListOptions | undefined, mode: EntityReadMode): number;
26
+ readList(templateKey: string, options: EntityListOptions | undefined, mode: EntityReadMode): readonly EntityId[];
27
+ };
28
+ export declare const createEntityReactRuntime: (runtime: EntityRuntimeState) => EntityReactRuntime;
29
+ export type EntityHookRowSnapshot<AppMachines extends MachineStore, Key extends EntityActorKey<AppMachines>> = EntityRowSnapshot<EntityContextFor<AppMachines, Key>, EntityStateFor<AppMachines, Key>>;
@@ -0,0 +1,15 @@
1
+ import type { AnyEvent, ReadonlyManagerAction, StorageManagerContext } from "@lite-fsm/core";
2
+ import type { EntityRuntimeState } from "./state";
3
+ import { type EntityTransitionTraceSession } from "./transitionTrace";
4
+ import { type EntityReactionBatch } from "./transaction";
5
+ type ReactionRunContext = {
6
+ readonly action: ReadonlyManagerAction<AnyEvent>;
7
+ readonly manager: Pick<StorageManagerContext<AnyEvent>, "getDependencies">;
8
+ readonly dispatch: {
9
+ readonly runtime: Map<string, unknown>;
10
+ reportError(error: unknown): void;
11
+ };
12
+ };
13
+ export declare const runEntityReactionBatches: (runtime: EntityRuntimeState, batches: readonly EntityReactionBatch[], ctx: ReactionRunContext, trace?: EntityTransitionTraceSession, phasePrefix?: string) => void;
14
+ export declare const runEntityReactions: (runtime: EntityRuntimeState, ctx: ReactionRunContext) => void;
15
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { AnyEvent, ReadonlyManagerAction, StorageManagerContext } from "@lite-fsm/core";
2
+ import type { EntityRuntimeState } from "./state";
3
+ import { type EntityTransitionTraceSession } from "./transitionTrace";
4
+ import { type EntityReactionBatch } from "./transaction";
5
+ type ReactionRunContext = {
6
+ readonly action: ReadonlyManagerAction<AnyEvent>;
7
+ readonly manager: Pick<StorageManagerContext<AnyEvent>, "getDependencies">;
8
+ readonly dispatch: {
9
+ readonly runtime: Map<string, unknown>;
10
+ reportError(error: unknown): void;
11
+ };
12
+ };
13
+ export declare const runEntityReactionBatches: (runtime: EntityRuntimeState, batches: readonly EntityReactionBatch[], ctx: ReactionRunContext, trace?: EntityTransitionTraceSession, phasePrefix?: string) => void;
14
+ export declare const runEntityReactions: (runtime: EntityRuntimeState, ctx: ReactionRunContext) => void;
15
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { EntityIndex } from "../plugin";
2
+ import { type ReduceAcceptedBatchOptions, type ReducerBatch } from "./reduce-shared";
3
+ import { type ColumnarActorStore, type EntityRuntimeState } from "./state";
4
+ import { type EntityDispatchTransaction } from "./transaction";
5
+ export declare const isSingleStateBucketReactionSource: (store: ColumnarActorStore, eventCode: number, indices: readonly EntityIndex[]) => boolean;
6
+ export declare const reduceAcceptedBatch: (runtime: EntityRuntimeState, batch: ReducerBatch, transaction: EntityDispatchTransaction | undefined, options?: ReduceAcceptedBatchOptions) => boolean;
@@ -0,0 +1,6 @@
1
+ import type { EntityIndex } from "../plugin";
2
+ import { type ReduceAcceptedBatchOptions, type ReducerBatch } from "./reduce-shared";
3
+ import { type ColumnarActorStore, type EntityRuntimeState } from "./state";
4
+ import { type EntityDispatchTransaction } from "./transaction";
5
+ export declare const isSingleStateBucketReactionSource: (store: ColumnarActorStore, eventCode: number, indices: readonly EntityIndex[]) => boolean;
6
+ export declare const reduceAcceptedBatch: (runtime: EntityRuntimeState, batch: ReducerBatch, transaction: EntityDispatchTransaction | undefined, options?: ReduceAcceptedBatchOptions) => boolean;
@@ -0,0 +1,7 @@
1
+ import { type LifecycleReactionContext } from "./reduce-shared";
2
+ import { type EntityRuntimeState } from "./state";
3
+ import { type EntityDispatchTransaction } from "./transaction";
4
+ import { type EntityTransitionTraceSession } from "./transitionTrace";
5
+ type CleanupPhaseKind = "spawn" | "public";
6
+ export declare const flushEntityLifecycleCleanup: (runtime: EntityRuntimeState, transaction: EntityDispatchTransaction | undefined, reactionContext: LifecycleReactionContext, phaseKind: CleanupPhaseKind, trace: EntityTransitionTraceSession | undefined) => boolean;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type LifecycleReactionContext } from "./reduce-shared";
2
+ import { type EntityRuntimeState } from "./state";
3
+ import { type EntityDispatchTransaction } from "./transaction";
4
+ import { type EntityTransitionTraceSession } from "./transitionTrace";
5
+ type CleanupPhaseKind = "spawn" | "public";
6
+ export declare const flushEntityLifecycleCleanup: (runtime: EntityRuntimeState, transaction: EntityDispatchTransaction | undefined, reactionContext: LifecycleReactionContext, phaseKind: CleanupPhaseKind, trace: EntityTransitionTraceSession | undefined) => boolean;
7
+ export {};
@@ -0,0 +1,35 @@
1
+ import type { EntityIndex } from "../plugin";
2
+ import { type EntityReducePlan } from "./compile";
3
+ import { type ReduceAcceptedBatchOptions } from "./reduce-shared";
4
+ import { type ColumnarActorStore } from "./state";
5
+ import { type CapturedEntityScopeEntry, type EntityDispatchTransaction } from "./transaction";
6
+ type PostProcessingFlags = {
7
+ readonly scheduleDespawnOn: boolean;
8
+ readonly scheduleEffects: boolean;
9
+ readonly collectReactionSurvivors: boolean;
10
+ readonly scheduleTerminal: boolean;
11
+ };
12
+ export type EnteredEffectRows = {
13
+ readonly indices: EntityIndex[];
14
+ readonly entries: CapturedEntityScopeEntry[];
15
+ };
16
+ export type AcceptedRowsPostProcessing = {
17
+ readonly dirtyRows: readonly EntityIndex[] | undefined;
18
+ readonly dirtyRowsPreviousStateCode: number | undefined;
19
+ readonly dirtyRowsPreviousStateCodes: readonly number[] | undefined;
20
+ readonly bulkStateTransition: BulkStateTransition | undefined;
21
+ readonly enteredByState: ReadonlyMap<number, EnteredEffectRows> | undefined;
22
+ readonly cleanupRemovesAcceptedRows: boolean;
23
+ readonly despawnOnRemovesAcceptedRows: boolean;
24
+ readonly acceptedRowsHaveFinalRemoval: boolean;
25
+ readonly reactionSurvivorRows: readonly EntityIndex[] | undefined;
26
+ };
27
+ export type BulkStateTransition = {
28
+ readonly indices: readonly EntityIndex[];
29
+ readonly previousStateCode: number;
30
+ readonly stateCode: number;
31
+ };
32
+ export declare const getPostProcessingFlags: (store: ColumnarActorStore, plan: EntityReducePlan | undefined, options: ReduceAcceptedBatchOptions) => PostProcessingFlags;
33
+ export declare const getEnteredEffectIndices: (entered: EnteredEffectRows) => readonly EntityIndex[];
34
+ export declare const postProcessAcceptedRows: (transaction: EntityDispatchTransaction | undefined, store: ColumnarActorStore, accepted: readonly EntityIndex[], flags: PostProcessingFlags, plan: EntityReducePlan | undefined, previousStateCodeForAccepted: number | undefined, knownValidStateCodeForAccepted: number | undefined, sourceStateCodesByAccepted?: readonly number[]) => AcceptedRowsPostProcessing;
35
+ export {};