@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.
- package/LICENSE +21 -0
- package/PERFORMANCE.md +537 -0
- package/README.md +395 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -0
- package/dist/internal.d.cts +5 -0
- package/dist/internal.d.ts +5 -0
- package/dist/machine-extension.d.cts +153 -0
- package/dist/machine-extension.d.ts +153 -0
- package/dist/plugin.d.cts +32 -0
- package/dist/plugin.d.ts +32 -0
- package/dist/react/index.d.cts +11 -0
- package/dist/react/index.d.ts +11 -0
- package/dist/react.cjs +1 -0
- package/dist/react.js +1 -0
- package/dist/runtime/access.d.cts +72 -0
- package/dist/runtime/access.d.ts +72 -0
- package/dist/runtime/columns.d.cts +11 -0
- package/dist/runtime/columns.d.ts +11 -0
- package/dist/runtime/compile.d.cts +68 -0
- package/dist/runtime/compile.d.ts +68 -0
- package/dist/runtime/effects.d.cts +26 -0
- package/dist/runtime/effects.d.ts +26 -0
- package/dist/runtime/lifecycle.d.cts +10 -0
- package/dist/runtime/lifecycle.d.ts +10 -0
- package/dist/runtime/mutation-snapshot.d.cts +41 -0
- package/dist/runtime/mutation-snapshot.d.ts +41 -0
- package/dist/runtime/react.d.cts +29 -0
- package/dist/runtime/react.d.ts +29 -0
- package/dist/runtime/reactions.d.cts +15 -0
- package/dist/runtime/reactions.d.ts +15 -0
- package/dist/runtime/reduce-batch.d.cts +6 -0
- package/dist/runtime/reduce-batch.d.ts +6 -0
- package/dist/runtime/reduce-despawn.d.cts +7 -0
- package/dist/runtime/reduce-despawn.d.ts +7 -0
- package/dist/runtime/reduce-post-process.d.cts +35 -0
- package/dist/runtime/reduce-post-process.d.ts +35 -0
- package/dist/runtime/reduce-shared.d.cts +34 -0
- package/dist/runtime/reduce-shared.d.ts +34 -0
- package/dist/runtime/reduce-spawn.d.cts +5 -0
- package/dist/runtime/reduce-spawn.d.ts +5 -0
- package/dist/runtime/reduce-transitions.d.cts +11 -0
- package/dist/runtime/reduce-transitions.d.ts +11 -0
- package/dist/runtime/reduce.d.cts +5 -0
- package/dist/runtime/reduce.d.ts +5 -0
- package/dist/runtime/routing.d.cts +11 -0
- package/dist/runtime/routing.d.ts +11 -0
- package/dist/runtime/runtime-index.d.cts +23 -0
- package/dist/runtime/runtime-index.d.ts +23 -0
- package/dist/runtime/snapshot-export.d.cts +12 -0
- package/dist/runtime/snapshot-export.d.ts +12 -0
- package/dist/runtime/snapshot-import.d.cts +5 -0
- package/dist/runtime/snapshot-import.d.ts +5 -0
- package/dist/runtime/snapshot-types.d.cts +56 -0
- package/dist/runtime/snapshot-types.d.ts +56 -0
- package/dist/runtime/snapshot.d.cts +15 -0
- package/dist/runtime/snapshot.d.ts +15 -0
- package/dist/runtime/spawn-commit.d.cts +10 -0
- package/dist/runtime/spawn-commit.d.ts +10 -0
- package/dist/runtime/state.d.cts +15 -0
- package/dist/runtime/state.d.ts +15 -0
- package/dist/runtime/storage.d.cts +19 -0
- package/dist/runtime/storage.d.ts +19 -0
- package/dist/runtime/store-types.d.cts +81 -0
- package/dist/runtime/store-types.d.ts +81 -0
- package/dist/runtime/transaction.d.cts +104 -0
- package/dist/runtime/transaction.d.ts +104 -0
- package/dist/runtime/transitionTrace.d.cts +19 -0
- package/dist/runtime/transitionTrace.d.ts +19 -0
- package/dist/schema.d.cts +90 -0
- package/dist/schema.d.ts +90 -0
- package/dist/spawn.d.cts +56 -0
- package/dist/spawn.d.ts +56 -0
- package/package.json +90 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { MachineStore } from "@lite-fsm/core";
|
|
2
|
+
import type { EntityIndex } from "../plugin";
|
|
3
|
+
import type { EntityAccess } from "./access";
|
|
4
|
+
import type { EntityTemplateMetadata } from "./compile";
|
|
5
|
+
import type { EntityReactRuntime } from "./react";
|
|
6
|
+
export type EntityPublicStateSlice = {
|
|
7
|
+
readonly storage: "entity";
|
|
8
|
+
readonly version: number;
|
|
9
|
+
readonly count: number;
|
|
10
|
+
readonly capacity: number;
|
|
11
|
+
};
|
|
12
|
+
export type EntityColumn = Float32Array | Int16Array | Int32Array | Uint8Array | string[];
|
|
13
|
+
export type EntityStore = {
|
|
14
|
+
count: number;
|
|
15
|
+
capacity: number;
|
|
16
|
+
ids: string[];
|
|
17
|
+
indexById: Record<string, EntityIndex>;
|
|
18
|
+
alive: Uint8Array;
|
|
19
|
+
generation: Uint32Array;
|
|
20
|
+
groupTagByIndex: string[];
|
|
21
|
+
entitiesByGroupTag: Record<string, EntityIndex[]>;
|
|
22
|
+
groupTagPosition: Int32Array;
|
|
23
|
+
freeList: EntityIndex[];
|
|
24
|
+
version: number;
|
|
25
|
+
};
|
|
26
|
+
export type EntityActorRowRef = {
|
|
27
|
+
readonly store: ColumnarActorStore;
|
|
28
|
+
readonly entity: EntityIndex;
|
|
29
|
+
readonly groupTag: string;
|
|
30
|
+
entityRowsPosition: number;
|
|
31
|
+
groupRowsPosition: number;
|
|
32
|
+
};
|
|
33
|
+
export type ColumnarActorStore = {
|
|
34
|
+
readonly storeId: number;
|
|
35
|
+
readonly templateKey: string;
|
|
36
|
+
readonly metadata: EntityTemplateMetadata;
|
|
37
|
+
capacity: number;
|
|
38
|
+
count: number;
|
|
39
|
+
version: number;
|
|
40
|
+
presence: Uint8Array;
|
|
41
|
+
stateCode: Int16Array;
|
|
42
|
+
prevStateCode: Int16Array;
|
|
43
|
+
rowVersion: Uint32Array;
|
|
44
|
+
stateBuckets: EntityIndex[][];
|
|
45
|
+
statePosition: Int32Array;
|
|
46
|
+
acceptedScratch: EntityIndex[];
|
|
47
|
+
defaultTransitionSourceStateScratch: number[];
|
|
48
|
+
pendingPrevStateCodeSync: EntityIndex[];
|
|
49
|
+
pendingPrevStateCodeSyncMark: Uint32Array;
|
|
50
|
+
pendingPrevStateCodeSyncToken: number;
|
|
51
|
+
routingScratchVersion: number;
|
|
52
|
+
acceptStateBucketsByEventCode: EntityIndex[][][];
|
|
53
|
+
columns: Record<string, EntityColumn>;
|
|
54
|
+
resources: Record<string, unknown>;
|
|
55
|
+
resourceViews: Record<string, unknown>;
|
|
56
|
+
reducerSelf: EntityReducerSelfCache;
|
|
57
|
+
publicSlice: EntityPublicStateSlice;
|
|
58
|
+
};
|
|
59
|
+
export type EntityReducerSelfCache = Record<string, unknown> & {
|
|
60
|
+
indices: readonly EntityIndex[];
|
|
61
|
+
readonly states: EntityTemplateMetadata["stateCodeByName"];
|
|
62
|
+
presence: Uint8Array;
|
|
63
|
+
stateCode: Int16Array;
|
|
64
|
+
prevStateCode: Int16Array;
|
|
65
|
+
rowVersion: Uint32Array;
|
|
66
|
+
has(entity: EntityIndex): boolean;
|
|
67
|
+
entityId(entity: EntityIndex): string;
|
|
68
|
+
};
|
|
69
|
+
export type EntityRuntimeState = {
|
|
70
|
+
readonly entityStore: EntityStore;
|
|
71
|
+
readonly actorStores: Record<string, ColumnarActorStore>;
|
|
72
|
+
readonly actorStoresById: ColumnarActorStore[];
|
|
73
|
+
readonly eventCodeByType: Readonly<Record<string, number>>;
|
|
74
|
+
readonly eventTypesByCode: readonly string[];
|
|
75
|
+
readonly templatesByEventCode: readonly (readonly ColumnarActorStore[])[];
|
|
76
|
+
actorRowsByEntity: EntityActorRowRef[][];
|
|
77
|
+
actorRowsByGroupTag: Record<string, EntityActorRowRef[]>;
|
|
78
|
+
routingScratchVersion: number;
|
|
79
|
+
readonly access: EntityAccess<MachineStore>;
|
|
80
|
+
react?: EntityReactRuntime;
|
|
81
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { AnyEvent, ReadonlyManagerAction } from "@lite-fsm/core";
|
|
2
|
+
import type { EntityIndex } from "../plugin";
|
|
3
|
+
import type { EntitySpawnDescriptor } from "../spawn";
|
|
4
|
+
import type { ColumnarActorStore, EntityActorRowRef, EntityRuntimeState } from "./state";
|
|
5
|
+
type RuntimeCarrier = {
|
|
6
|
+
readonly runtime: Map<string, unknown>;
|
|
7
|
+
};
|
|
8
|
+
export type StagedActorSpawn = {
|
|
9
|
+
readonly templateKey: string;
|
|
10
|
+
readonly payload: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
export type StagedEntitySpawn = {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly groupTag: string;
|
|
15
|
+
readonly actors: readonly StagedActorSpawn[];
|
|
16
|
+
};
|
|
17
|
+
export type EntityDispatchTransaction = {
|
|
18
|
+
readonly runtime: EntityRuntimeState;
|
|
19
|
+
stagedSpawns: readonly StagedEntitySpawn[];
|
|
20
|
+
scheduledDespawns: EntityIndex[];
|
|
21
|
+
despawnScheduled: Uint8Array;
|
|
22
|
+
despawnRowHints: EntityDespawnRowHint[];
|
|
23
|
+
terminalRows: EntityActorTerminalRow[];
|
|
24
|
+
effectBatches: EntityEffectBatch[];
|
|
25
|
+
reactionBatches: EntityReactionBatch[];
|
|
26
|
+
};
|
|
27
|
+
export type EntityDespawnRowHint = {
|
|
28
|
+
readonly storeId: number;
|
|
29
|
+
readonly entity: EntityIndex;
|
|
30
|
+
readonly bucketStateCode: number;
|
|
31
|
+
};
|
|
32
|
+
export type EntityActorTerminalRow = {
|
|
33
|
+
readonly store: ColumnarActorStore;
|
|
34
|
+
readonly entity: EntityIndex;
|
|
35
|
+
};
|
|
36
|
+
export type EntityCleanupRemovalBatch = {
|
|
37
|
+
readonly store: ColumnarActorStore;
|
|
38
|
+
readonly rows: EntityActorRowRef[];
|
|
39
|
+
readonly bucketStateCodes: Array<number | undefined>;
|
|
40
|
+
bucketStateCodesActive: boolean;
|
|
41
|
+
};
|
|
42
|
+
export type EntityCleanupLifecycleBatch = {
|
|
43
|
+
readonly store: ColumnarActorStore;
|
|
44
|
+
readonly indices: EntityIndex[];
|
|
45
|
+
};
|
|
46
|
+
export type EntityCleanupScratch = {
|
|
47
|
+
readonly entities: EntityIndex[];
|
|
48
|
+
readonly removalBatchesByStoreId: Array<EntityCleanupRemovalBatch | undefined>;
|
|
49
|
+
readonly removalTouchedStoreIds: number[];
|
|
50
|
+
readonly lifecycleBatchesByStoreId: Array<EntityCleanupLifecycleBatch | undefined>;
|
|
51
|
+
readonly lifecycleTouchedStoreIds: number[];
|
|
52
|
+
};
|
|
53
|
+
export type EntityEffectBatch = {
|
|
54
|
+
readonly store: ColumnarActorStore;
|
|
55
|
+
readonly stateCode: number;
|
|
56
|
+
readonly indices: readonly EntityIndex[];
|
|
57
|
+
readonly capturedEntries?: readonly CapturedEntityScopeEntry[];
|
|
58
|
+
readonly storeVersion?: number;
|
|
59
|
+
readonly entityStoreVersion?: number;
|
|
60
|
+
};
|
|
61
|
+
export type EntityReactionBatch = {
|
|
62
|
+
readonly store: ColumnarActorStore;
|
|
63
|
+
readonly eventCode: number;
|
|
64
|
+
readonly ownership: EntityReactionBatchOwnership;
|
|
65
|
+
readonly indices: readonly EntityIndex[];
|
|
66
|
+
};
|
|
67
|
+
export type CapturedEntityScopeEntry = {
|
|
68
|
+
readonly entity: EntityIndex;
|
|
69
|
+
readonly generation: number;
|
|
70
|
+
readonly id: string;
|
|
71
|
+
};
|
|
72
|
+
type ExplicitDespawnRequest = {
|
|
73
|
+
readonly mode: "ids";
|
|
74
|
+
readonly ids: readonly string[];
|
|
75
|
+
} | {
|
|
76
|
+
readonly mode: "scope";
|
|
77
|
+
readonly entries: readonly CapturedEntityScopeEntry[];
|
|
78
|
+
};
|
|
79
|
+
export type EntityReactionBatchOwnership = "borrowed" | "owned";
|
|
80
|
+
type ScheduleEntityReactionBatchOptions = {
|
|
81
|
+
readonly ownership?: EntityReactionBatchOwnership;
|
|
82
|
+
};
|
|
83
|
+
export declare const ENTITY_DESPAWN_ACTION_TYPE = "LITE_FSM_ENTITY_DESPAWN";
|
|
84
|
+
export declare const createEntityDespawnOptions: (request: ExplicitDespawnRequest) => object;
|
|
85
|
+
export declare const prepareEntityTransaction: (carrier: RuntimeCarrier, runtime: EntityRuntimeState) => EntityDispatchTransaction;
|
|
86
|
+
export declare const getEntityTransaction: (carrier: RuntimeCarrier) => EntityDispatchTransaction | undefined;
|
|
87
|
+
export declare const stageSpawnAction: (carrier: RuntimeCarrier & {
|
|
88
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
89
|
+
readonly skipDelivery: boolean;
|
|
90
|
+
}, spawn: EntitySpawnDescriptor) => void;
|
|
91
|
+
export declare const getStagedSpawns: (carrier: RuntimeCarrier) => readonly StagedEntitySpawn[];
|
|
92
|
+
export declare const scheduleEntityDespawn: (transaction: EntityDispatchTransaction, entity: EntityIndex) => boolean;
|
|
93
|
+
export declare const scheduleDespawnRowHint: (transaction: EntityDispatchTransaction, store: ColumnarActorStore, entity: EntityIndex, bucketStateCode: number) => boolean;
|
|
94
|
+
export declare const getDespawnRowHintBucketStateCode: (transaction: EntityDispatchTransaction, storeId: number, entity: EntityIndex) => number | undefined;
|
|
95
|
+
export declare const clearDespawnRowHints: (transaction: EntityDispatchTransaction) => void;
|
|
96
|
+
export declare const consumeScheduledDespawns: (transaction: EntityDispatchTransaction) => readonly EntityIndex[];
|
|
97
|
+
export declare const beginEntityCleanupScratch: (transaction: EntityDispatchTransaction) => EntityCleanupScratch;
|
|
98
|
+
export declare const finishEntityCleanupScratch: (transaction: EntityDispatchTransaction, cleanup: EntityCleanupScratch) => void;
|
|
99
|
+
export declare const appendCleanupRemovalRow: (cleanup: EntityCleanupScratch, store: ColumnarActorStore, row: EntityActorRowRef, bucketStateCode: number | undefined) => void;
|
|
100
|
+
export declare const appendCleanupLifecycleIndex: (cleanup: EntityCleanupScratch, store: ColumnarActorStore, entity: EntityIndex) => void;
|
|
101
|
+
export declare const scheduleEntityEffectBatch: (transaction: EntityDispatchTransaction | undefined, store: ColumnarActorStore, stateCode: number, indices: readonly EntityIndex[], capturedEntries?: readonly CapturedEntityScopeEntry[]) => void;
|
|
102
|
+
export declare const createEntityReactionBatch: (transaction: EntityDispatchTransaction | undefined, store: ColumnarActorStore, eventCode: number | undefined, indices: readonly EntityIndex[], options?: ScheduleEntityReactionBatchOptions) => EntityReactionBatch | undefined;
|
|
103
|
+
export declare const scheduleEntityReactionBatch: (transaction: EntityDispatchTransaction | undefined, store: ColumnarActorStore, eventCode: number | undefined, indices: readonly EntityIndex[], options?: ScheduleEntityReactionBatchOptions) => void;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { AnyEvent, ReadonlyManagerAction } from "@lite-fsm/core";
|
|
2
|
+
import type { EntityIndex } from "../plugin";
|
|
3
|
+
import type { EntitySpawnDescriptor } from "../spawn";
|
|
4
|
+
import type { ColumnarActorStore, EntityActorRowRef, EntityRuntimeState } from "./state";
|
|
5
|
+
type RuntimeCarrier = {
|
|
6
|
+
readonly runtime: Map<string, unknown>;
|
|
7
|
+
};
|
|
8
|
+
export type StagedActorSpawn = {
|
|
9
|
+
readonly templateKey: string;
|
|
10
|
+
readonly payload: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
export type StagedEntitySpawn = {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly groupTag: string;
|
|
15
|
+
readonly actors: readonly StagedActorSpawn[];
|
|
16
|
+
};
|
|
17
|
+
export type EntityDispatchTransaction = {
|
|
18
|
+
readonly runtime: EntityRuntimeState;
|
|
19
|
+
stagedSpawns: readonly StagedEntitySpawn[];
|
|
20
|
+
scheduledDespawns: EntityIndex[];
|
|
21
|
+
despawnScheduled: Uint8Array;
|
|
22
|
+
despawnRowHints: EntityDespawnRowHint[];
|
|
23
|
+
terminalRows: EntityActorTerminalRow[];
|
|
24
|
+
effectBatches: EntityEffectBatch[];
|
|
25
|
+
reactionBatches: EntityReactionBatch[];
|
|
26
|
+
};
|
|
27
|
+
export type EntityDespawnRowHint = {
|
|
28
|
+
readonly storeId: number;
|
|
29
|
+
readonly entity: EntityIndex;
|
|
30
|
+
readonly bucketStateCode: number;
|
|
31
|
+
};
|
|
32
|
+
export type EntityActorTerminalRow = {
|
|
33
|
+
readonly store: ColumnarActorStore;
|
|
34
|
+
readonly entity: EntityIndex;
|
|
35
|
+
};
|
|
36
|
+
export type EntityCleanupRemovalBatch = {
|
|
37
|
+
readonly store: ColumnarActorStore;
|
|
38
|
+
readonly rows: EntityActorRowRef[];
|
|
39
|
+
readonly bucketStateCodes: Array<number | undefined>;
|
|
40
|
+
bucketStateCodesActive: boolean;
|
|
41
|
+
};
|
|
42
|
+
export type EntityCleanupLifecycleBatch = {
|
|
43
|
+
readonly store: ColumnarActorStore;
|
|
44
|
+
readonly indices: EntityIndex[];
|
|
45
|
+
};
|
|
46
|
+
export type EntityCleanupScratch = {
|
|
47
|
+
readonly entities: EntityIndex[];
|
|
48
|
+
readonly removalBatchesByStoreId: Array<EntityCleanupRemovalBatch | undefined>;
|
|
49
|
+
readonly removalTouchedStoreIds: number[];
|
|
50
|
+
readonly lifecycleBatchesByStoreId: Array<EntityCleanupLifecycleBatch | undefined>;
|
|
51
|
+
readonly lifecycleTouchedStoreIds: number[];
|
|
52
|
+
};
|
|
53
|
+
export type EntityEffectBatch = {
|
|
54
|
+
readonly store: ColumnarActorStore;
|
|
55
|
+
readonly stateCode: number;
|
|
56
|
+
readonly indices: readonly EntityIndex[];
|
|
57
|
+
readonly capturedEntries?: readonly CapturedEntityScopeEntry[];
|
|
58
|
+
readonly storeVersion?: number;
|
|
59
|
+
readonly entityStoreVersion?: number;
|
|
60
|
+
};
|
|
61
|
+
export type EntityReactionBatch = {
|
|
62
|
+
readonly store: ColumnarActorStore;
|
|
63
|
+
readonly eventCode: number;
|
|
64
|
+
readonly ownership: EntityReactionBatchOwnership;
|
|
65
|
+
readonly indices: readonly EntityIndex[];
|
|
66
|
+
};
|
|
67
|
+
export type CapturedEntityScopeEntry = {
|
|
68
|
+
readonly entity: EntityIndex;
|
|
69
|
+
readonly generation: number;
|
|
70
|
+
readonly id: string;
|
|
71
|
+
};
|
|
72
|
+
type ExplicitDespawnRequest = {
|
|
73
|
+
readonly mode: "ids";
|
|
74
|
+
readonly ids: readonly string[];
|
|
75
|
+
} | {
|
|
76
|
+
readonly mode: "scope";
|
|
77
|
+
readonly entries: readonly CapturedEntityScopeEntry[];
|
|
78
|
+
};
|
|
79
|
+
export type EntityReactionBatchOwnership = "borrowed" | "owned";
|
|
80
|
+
type ScheduleEntityReactionBatchOptions = {
|
|
81
|
+
readonly ownership?: EntityReactionBatchOwnership;
|
|
82
|
+
};
|
|
83
|
+
export declare const ENTITY_DESPAWN_ACTION_TYPE = "LITE_FSM_ENTITY_DESPAWN";
|
|
84
|
+
export declare const createEntityDespawnOptions: (request: ExplicitDespawnRequest) => object;
|
|
85
|
+
export declare const prepareEntityTransaction: (carrier: RuntimeCarrier, runtime: EntityRuntimeState) => EntityDispatchTransaction;
|
|
86
|
+
export declare const getEntityTransaction: (carrier: RuntimeCarrier) => EntityDispatchTransaction | undefined;
|
|
87
|
+
export declare const stageSpawnAction: (carrier: RuntimeCarrier & {
|
|
88
|
+
readonly action: ReadonlyManagerAction<AnyEvent>;
|
|
89
|
+
readonly skipDelivery: boolean;
|
|
90
|
+
}, spawn: EntitySpawnDescriptor) => void;
|
|
91
|
+
export declare const getStagedSpawns: (carrier: RuntimeCarrier) => readonly StagedEntitySpawn[];
|
|
92
|
+
export declare const scheduleEntityDespawn: (transaction: EntityDispatchTransaction, entity: EntityIndex) => boolean;
|
|
93
|
+
export declare const scheduleDespawnRowHint: (transaction: EntityDispatchTransaction, store: ColumnarActorStore, entity: EntityIndex, bucketStateCode: number) => boolean;
|
|
94
|
+
export declare const getDespawnRowHintBucketStateCode: (transaction: EntityDispatchTransaction, storeId: number, entity: EntityIndex) => number | undefined;
|
|
95
|
+
export declare const clearDespawnRowHints: (transaction: EntityDispatchTransaction) => void;
|
|
96
|
+
export declare const consumeScheduledDespawns: (transaction: EntityDispatchTransaction) => readonly EntityIndex[];
|
|
97
|
+
export declare const beginEntityCleanupScratch: (transaction: EntityDispatchTransaction) => EntityCleanupScratch;
|
|
98
|
+
export declare const finishEntityCleanupScratch: (transaction: EntityDispatchTransaction, cleanup: EntityCleanupScratch) => void;
|
|
99
|
+
export declare const appendCleanupRemovalRow: (cleanup: EntityCleanupScratch, store: ColumnarActorStore, row: EntityActorRowRef, bucketStateCode: number | undefined) => void;
|
|
100
|
+
export declare const appendCleanupLifecycleIndex: (cleanup: EntityCleanupScratch, store: ColumnarActorStore, entity: EntityIndex) => void;
|
|
101
|
+
export declare const scheduleEntityEffectBatch: (transaction: EntityDispatchTransaction | undefined, store: ColumnarActorStore, stateCode: number, indices: readonly EntityIndex[], capturedEntries?: readonly CapturedEntityScopeEntry[]) => void;
|
|
102
|
+
export declare const createEntityReactionBatch: (transaction: EntityDispatchTransaction | undefined, store: ColumnarActorStore, eventCode: number | undefined, indices: readonly EntityIndex[], options?: ScheduleEntityReactionBatchOptions) => EntityReactionBatch | undefined;
|
|
103
|
+
export declare const scheduleEntityReactionBatch: (transaction: EntityDispatchTransaction | undefined, store: ColumnarActorStore, eventCode: number | undefined, indices: readonly EntityIndex[], options?: ScheduleEntityReactionBatchOptions) => void;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type RuntimeCarrier = {
|
|
2
|
+
readonly runtime: Map<string, unknown>;
|
|
3
|
+
};
|
|
4
|
+
type EntityTransitionTracePhaseMetadata = {
|
|
5
|
+
readonly runtimeKind?: string;
|
|
6
|
+
};
|
|
7
|
+
export type EntityTransitionTraceSession = {
|
|
8
|
+
readonly depth: number;
|
|
9
|
+
now(): number;
|
|
10
|
+
record(key: string, startedAt: number, metadata?: EntityTransitionTracePhaseMetadata): void;
|
|
11
|
+
count(key: string, value?: number): void;
|
|
12
|
+
finish(status: "ok" | "error"): void;
|
|
13
|
+
};
|
|
14
|
+
export declare const readEntityTransitionTraceSession: (carrier: RuntimeCarrier) => EntityTransitionTraceSession | undefined;
|
|
15
|
+
export declare const recordEntityTracePhase: (trace: EntityTransitionTraceSession | undefined, key: string, startedAt: number | undefined) => void;
|
|
16
|
+
export declare const recordEntityTraceCounter: (trace: EntityTransitionTraceSession | undefined, key: string, value?: number) => void;
|
|
17
|
+
export declare const tracePhase: <T>(trace: EntityTransitionTraceSession | undefined, key: string, fn: () => T) => T;
|
|
18
|
+
export declare const traceDispatchPhase: <T>(carrier: RuntimeCarrier, key: string, fn: () => T) => T;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type RuntimeCarrier = {
|
|
2
|
+
readonly runtime: Map<string, unknown>;
|
|
3
|
+
};
|
|
4
|
+
type EntityTransitionTracePhaseMetadata = {
|
|
5
|
+
readonly runtimeKind?: string;
|
|
6
|
+
};
|
|
7
|
+
export type EntityTransitionTraceSession = {
|
|
8
|
+
readonly depth: number;
|
|
9
|
+
now(): number;
|
|
10
|
+
record(key: string, startedAt: number, metadata?: EntityTransitionTracePhaseMetadata): void;
|
|
11
|
+
count(key: string, value?: number): void;
|
|
12
|
+
finish(status: "ok" | "error"): void;
|
|
13
|
+
};
|
|
14
|
+
export declare const readEntityTransitionTraceSession: (carrier: RuntimeCarrier) => EntityTransitionTraceSession | undefined;
|
|
15
|
+
export declare const recordEntityTracePhase: (trace: EntityTransitionTraceSession | undefined, key: string, startedAt: number | undefined) => void;
|
|
16
|
+
export declare const recordEntityTraceCounter: (trace: EntityTransitionTraceSession | undefined, key: string, value?: number) => void;
|
|
17
|
+
export declare const tracePhase: <T>(trace: EntityTransitionTraceSession | undefined, key: string, fn: () => T) => T;
|
|
18
|
+
export declare const traceDispatchPhase: <T>(carrier: RuntimeCarrier, key: string, fn: () => T) => T;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export declare const descriptorMarker: unique symbol;
|
|
2
|
+
export declare const resourceDescriptorMarker: unique symbol;
|
|
3
|
+
type NumericDescriptorKind = "f32" | "i16" | "i32" | "u8";
|
|
4
|
+
type DescriptorKind = NumericDescriptorKind | "string";
|
|
5
|
+
type DescriptorDefault = number | string;
|
|
6
|
+
type ColumnForKind<Kind extends DescriptorKind> = Kind extends "f32" ? Float32Array : Kind extends "i16" ? Int16Array : Kind extends "i32" ? Int32Array : Kind extends "u8" ? Uint8Array : readonly string[];
|
|
7
|
+
type ValueForKind<Kind extends DescriptorKind> = Kind extends NumericDescriptorKind ? number : string;
|
|
8
|
+
type DescriptorOptions<Value extends DescriptorDefault> = {
|
|
9
|
+
readonly default?: Value;
|
|
10
|
+
};
|
|
11
|
+
type EntityDescriptorBase<Value, Column, Spawn> = {
|
|
12
|
+
readonly [descriptorMarker]: true;
|
|
13
|
+
readonly valueType?: Value;
|
|
14
|
+
readonly columnType?: Column;
|
|
15
|
+
readonly spawnType?: Spawn;
|
|
16
|
+
};
|
|
17
|
+
type EntityScalarDescriptor<Kind extends DescriptorKind> = EntityDescriptorBase<ValueForKind<Kind>, ColumnForKind<Kind>, ValueForKind<Kind>> & {
|
|
18
|
+
readonly kind: Kind;
|
|
19
|
+
readonly default?: ValueForKind<Kind>;
|
|
20
|
+
};
|
|
21
|
+
type EntityOptionalDescriptor<Inner extends EntityScalarDescriptor<DescriptorKind>> = EntityDescriptorBase<never, never, DescriptorSpawnValue<Inner> | null> & {
|
|
22
|
+
readonly kind: "optional";
|
|
23
|
+
readonly inner: Inner;
|
|
24
|
+
};
|
|
25
|
+
export type EntityResourceDescriptor<Owner, View, Exposed extends boolean> = {
|
|
26
|
+
readonly [resourceDescriptorMarker]: true;
|
|
27
|
+
readonly kind: "resource";
|
|
28
|
+
readonly factory: () => Owner;
|
|
29
|
+
readonly exposed: Exposed;
|
|
30
|
+
readonly ownerType?: Owner;
|
|
31
|
+
readonly viewType?: View;
|
|
32
|
+
} & (Exposed extends true ? {
|
|
33
|
+
readonly expose: (resource: Owner) => View;
|
|
34
|
+
} : {
|
|
35
|
+
readonly expose?: undefined;
|
|
36
|
+
});
|
|
37
|
+
export type EntityDescriptor = EntityScalarDescriptor<DescriptorKind>;
|
|
38
|
+
export type AnyEntityResourceDescriptor = EntityResourceDescriptor<any, any, false> | EntityResourceDescriptor<any, any, true>;
|
|
39
|
+
export type EntityContextDescriptor = EntityDescriptor | AnyEntityResourceDescriptor;
|
|
40
|
+
export type EntitySpawnDescriptor = EntityDescriptor | EntityOptionalDescriptor<EntityDescriptor>;
|
|
41
|
+
export type EntityColumnSchema = Readonly<Record<string, EntityDescriptor>>;
|
|
42
|
+
export type EntityContextSchema = Readonly<Record<string, EntityContextDescriptor>>;
|
|
43
|
+
export type EntityResourceSchema = Readonly<Record<string, AnyEntityResourceDescriptor>>;
|
|
44
|
+
export type EntitySpawnSchema = Readonly<Record<string, EntitySpawnDescriptor>>;
|
|
45
|
+
type DescriptorValue<Descriptor> = Descriptor extends {
|
|
46
|
+
readonly valueType?: infer Value;
|
|
47
|
+
} ? Value : never;
|
|
48
|
+
type DescriptorColumn<Descriptor> = Descriptor extends {
|
|
49
|
+
readonly columnType?: infer Column;
|
|
50
|
+
} ? Column : never;
|
|
51
|
+
type DescriptorSpawnValue<Descriptor> = Descriptor extends {
|
|
52
|
+
readonly spawnType?: infer Spawn;
|
|
53
|
+
} ? Spawn : never;
|
|
54
|
+
export declare const f32: (opts?: DescriptorOptions<number>) => EntityScalarDescriptor<"f32">;
|
|
55
|
+
export declare const i16: (opts?: DescriptorOptions<number>) => EntityScalarDescriptor<"i16">;
|
|
56
|
+
export declare const i32: (opts?: DescriptorOptions<number>) => EntityScalarDescriptor<"i32">;
|
|
57
|
+
export declare const u8: (opts?: DescriptorOptions<number>) => EntityScalarDescriptor<"u8">;
|
|
58
|
+
export declare const string: (opts?: DescriptorOptions<string>) => EntityScalarDescriptor<"string">;
|
|
59
|
+
export declare const optional: <Inner extends EntityDescriptor>(inner: Inner) => EntityOptionalDescriptor<Inner>;
|
|
60
|
+
export declare function resource<Owner>(factory: () => Owner): EntityResourceDescriptor<Owner, never, false>;
|
|
61
|
+
export declare function resource<Owner, View>(factory: () => Owner, expose: (resource: Owner) => View): EntityResourceDescriptor<Owner, View, true>;
|
|
62
|
+
export declare const isEntityResourceDescriptor: (value: unknown) => value is AnyEntityResourceDescriptor;
|
|
63
|
+
export declare const validateEntitySchema: (machineKey: string, path: "initialContext" | "spawnSchema", schema: unknown) => void;
|
|
64
|
+
type EntitySchemaColumnKey<Schema extends EntityContextSchema> = string extends keyof Schema ? string : {
|
|
65
|
+
readonly [Field in keyof Schema]: Schema[Field] extends EntityDescriptor ? Field : never;
|
|
66
|
+
}[keyof Schema];
|
|
67
|
+
type EntitySchemaResourceOwnerKey<Schema extends EntityContextSchema> = string extends keyof Schema ? never : {
|
|
68
|
+
readonly [Field in keyof Schema]: Schema[Field] extends EntityResourceDescriptor<any, any, boolean> ? Field : never;
|
|
69
|
+
}[keyof Schema];
|
|
70
|
+
type EntitySchemaResourceExposedKey<Schema extends EntityContextSchema> = string extends keyof Schema ? never : {
|
|
71
|
+
readonly [Field in keyof Schema]: Schema[Field] extends EntityResourceDescriptor<any, any, true> ? Field : never;
|
|
72
|
+
}[keyof Schema];
|
|
73
|
+
type ResourceOwner<Descriptor> = Descriptor extends EntityResourceDescriptor<infer Owner, any, boolean> ? Owner : never;
|
|
74
|
+
type ResourceView<Descriptor> = Descriptor extends EntityResourceDescriptor<any, infer View, true> ? View : never;
|
|
75
|
+
export type EntitySchemaValue<Schema extends EntityContextSchema> = {
|
|
76
|
+
readonly [Field in EntitySchemaColumnKey<Schema>]: DescriptorValue<Schema[Field]>;
|
|
77
|
+
};
|
|
78
|
+
export type EntitySchemaColumns<Schema extends EntityContextSchema> = {
|
|
79
|
+
readonly [Field in EntitySchemaColumnKey<Schema>]: DescriptorColumn<Schema[Field]>;
|
|
80
|
+
};
|
|
81
|
+
export type EntitySchemaResourceOwners<Schema extends EntityContextSchema> = {
|
|
82
|
+
readonly [Field in EntitySchemaResourceOwnerKey<Schema>]: ResourceOwner<Schema[Field]>;
|
|
83
|
+
};
|
|
84
|
+
export type EntitySchemaResourceViews<Schema extends EntityContextSchema> = {
|
|
85
|
+
readonly [Field in EntitySchemaResourceExposedKey<Schema>]: ResourceView<Schema[Field]>;
|
|
86
|
+
};
|
|
87
|
+
export type EntitySpawnPayload<Schema extends EntitySpawnSchema> = {
|
|
88
|
+
readonly [Field in keyof Schema]: DescriptorSpawnValue<Schema[Field]>;
|
|
89
|
+
};
|
|
90
|
+
export {};
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export declare const descriptorMarker: unique symbol;
|
|
2
|
+
export declare const resourceDescriptorMarker: unique symbol;
|
|
3
|
+
type NumericDescriptorKind = "f32" | "i16" | "i32" | "u8";
|
|
4
|
+
type DescriptorKind = NumericDescriptorKind | "string";
|
|
5
|
+
type DescriptorDefault = number | string;
|
|
6
|
+
type ColumnForKind<Kind extends DescriptorKind> = Kind extends "f32" ? Float32Array : Kind extends "i16" ? Int16Array : Kind extends "i32" ? Int32Array : Kind extends "u8" ? Uint8Array : readonly string[];
|
|
7
|
+
type ValueForKind<Kind extends DescriptorKind> = Kind extends NumericDescriptorKind ? number : string;
|
|
8
|
+
type DescriptorOptions<Value extends DescriptorDefault> = {
|
|
9
|
+
readonly default?: Value;
|
|
10
|
+
};
|
|
11
|
+
type EntityDescriptorBase<Value, Column, Spawn> = {
|
|
12
|
+
readonly [descriptorMarker]: true;
|
|
13
|
+
readonly valueType?: Value;
|
|
14
|
+
readonly columnType?: Column;
|
|
15
|
+
readonly spawnType?: Spawn;
|
|
16
|
+
};
|
|
17
|
+
type EntityScalarDescriptor<Kind extends DescriptorKind> = EntityDescriptorBase<ValueForKind<Kind>, ColumnForKind<Kind>, ValueForKind<Kind>> & {
|
|
18
|
+
readonly kind: Kind;
|
|
19
|
+
readonly default?: ValueForKind<Kind>;
|
|
20
|
+
};
|
|
21
|
+
type EntityOptionalDescriptor<Inner extends EntityScalarDescriptor<DescriptorKind>> = EntityDescriptorBase<never, never, DescriptorSpawnValue<Inner> | null> & {
|
|
22
|
+
readonly kind: "optional";
|
|
23
|
+
readonly inner: Inner;
|
|
24
|
+
};
|
|
25
|
+
export type EntityResourceDescriptor<Owner, View, Exposed extends boolean> = {
|
|
26
|
+
readonly [resourceDescriptorMarker]: true;
|
|
27
|
+
readonly kind: "resource";
|
|
28
|
+
readonly factory: () => Owner;
|
|
29
|
+
readonly exposed: Exposed;
|
|
30
|
+
readonly ownerType?: Owner;
|
|
31
|
+
readonly viewType?: View;
|
|
32
|
+
} & (Exposed extends true ? {
|
|
33
|
+
readonly expose: (resource: Owner) => View;
|
|
34
|
+
} : {
|
|
35
|
+
readonly expose?: undefined;
|
|
36
|
+
});
|
|
37
|
+
export type EntityDescriptor = EntityScalarDescriptor<DescriptorKind>;
|
|
38
|
+
export type AnyEntityResourceDescriptor = EntityResourceDescriptor<any, any, false> | EntityResourceDescriptor<any, any, true>;
|
|
39
|
+
export type EntityContextDescriptor = EntityDescriptor | AnyEntityResourceDescriptor;
|
|
40
|
+
export type EntitySpawnDescriptor = EntityDescriptor | EntityOptionalDescriptor<EntityDescriptor>;
|
|
41
|
+
export type EntityColumnSchema = Readonly<Record<string, EntityDescriptor>>;
|
|
42
|
+
export type EntityContextSchema = Readonly<Record<string, EntityContextDescriptor>>;
|
|
43
|
+
export type EntityResourceSchema = Readonly<Record<string, AnyEntityResourceDescriptor>>;
|
|
44
|
+
export type EntitySpawnSchema = Readonly<Record<string, EntitySpawnDescriptor>>;
|
|
45
|
+
type DescriptorValue<Descriptor> = Descriptor extends {
|
|
46
|
+
readonly valueType?: infer Value;
|
|
47
|
+
} ? Value : never;
|
|
48
|
+
type DescriptorColumn<Descriptor> = Descriptor extends {
|
|
49
|
+
readonly columnType?: infer Column;
|
|
50
|
+
} ? Column : never;
|
|
51
|
+
type DescriptorSpawnValue<Descriptor> = Descriptor extends {
|
|
52
|
+
readonly spawnType?: infer Spawn;
|
|
53
|
+
} ? Spawn : never;
|
|
54
|
+
export declare const f32: (opts?: DescriptorOptions<number>) => EntityScalarDescriptor<"f32">;
|
|
55
|
+
export declare const i16: (opts?: DescriptorOptions<number>) => EntityScalarDescriptor<"i16">;
|
|
56
|
+
export declare const i32: (opts?: DescriptorOptions<number>) => EntityScalarDescriptor<"i32">;
|
|
57
|
+
export declare const u8: (opts?: DescriptorOptions<number>) => EntityScalarDescriptor<"u8">;
|
|
58
|
+
export declare const string: (opts?: DescriptorOptions<string>) => EntityScalarDescriptor<"string">;
|
|
59
|
+
export declare const optional: <Inner extends EntityDescriptor>(inner: Inner) => EntityOptionalDescriptor<Inner>;
|
|
60
|
+
export declare function resource<Owner>(factory: () => Owner): EntityResourceDescriptor<Owner, never, false>;
|
|
61
|
+
export declare function resource<Owner, View>(factory: () => Owner, expose: (resource: Owner) => View): EntityResourceDescriptor<Owner, View, true>;
|
|
62
|
+
export declare const isEntityResourceDescriptor: (value: unknown) => value is AnyEntityResourceDescriptor;
|
|
63
|
+
export declare const validateEntitySchema: (machineKey: string, path: "initialContext" | "spawnSchema", schema: unknown) => void;
|
|
64
|
+
type EntitySchemaColumnKey<Schema extends EntityContextSchema> = string extends keyof Schema ? string : {
|
|
65
|
+
readonly [Field in keyof Schema]: Schema[Field] extends EntityDescriptor ? Field : never;
|
|
66
|
+
}[keyof Schema];
|
|
67
|
+
type EntitySchemaResourceOwnerKey<Schema extends EntityContextSchema> = string extends keyof Schema ? never : {
|
|
68
|
+
readonly [Field in keyof Schema]: Schema[Field] extends EntityResourceDescriptor<any, any, boolean> ? Field : never;
|
|
69
|
+
}[keyof Schema];
|
|
70
|
+
type EntitySchemaResourceExposedKey<Schema extends EntityContextSchema> = string extends keyof Schema ? never : {
|
|
71
|
+
readonly [Field in keyof Schema]: Schema[Field] extends EntityResourceDescriptor<any, any, true> ? Field : never;
|
|
72
|
+
}[keyof Schema];
|
|
73
|
+
type ResourceOwner<Descriptor> = Descriptor extends EntityResourceDescriptor<infer Owner, any, boolean> ? Owner : never;
|
|
74
|
+
type ResourceView<Descriptor> = Descriptor extends EntityResourceDescriptor<any, infer View, true> ? View : never;
|
|
75
|
+
export type EntitySchemaValue<Schema extends EntityContextSchema> = {
|
|
76
|
+
readonly [Field in EntitySchemaColumnKey<Schema>]: DescriptorValue<Schema[Field]>;
|
|
77
|
+
};
|
|
78
|
+
export type EntitySchemaColumns<Schema extends EntityContextSchema> = {
|
|
79
|
+
readonly [Field in EntitySchemaColumnKey<Schema>]: DescriptorColumn<Schema[Field]>;
|
|
80
|
+
};
|
|
81
|
+
export type EntitySchemaResourceOwners<Schema extends EntityContextSchema> = {
|
|
82
|
+
readonly [Field in EntitySchemaResourceOwnerKey<Schema>]: ResourceOwner<Schema[Field]>;
|
|
83
|
+
};
|
|
84
|
+
export type EntitySchemaResourceViews<Schema extends EntityContextSchema> = {
|
|
85
|
+
readonly [Field in EntitySchemaResourceExposedKey<Schema>]: ResourceView<Schema[Field]>;
|
|
86
|
+
};
|
|
87
|
+
export type EntitySpawnPayload<Schema extends EntitySpawnSchema> = {
|
|
88
|
+
readonly [Field in keyof Schema]: DescriptorSpawnValue<Schema[Field]>;
|
|
89
|
+
};
|
|
90
|
+
export {};
|
package/dist/spawn.d.cts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AnyEvent, MachineStore } from "@lite-fsm/core";
|
|
2
|
+
import type { EntitySpawnPayload, EntitySpawnSchema } from "./schema";
|
|
3
|
+
declare const spawnEventMarker: unique symbol;
|
|
4
|
+
declare const entitySpawnMarker: unique symbol;
|
|
5
|
+
export type SpawnEventDescriptor<Payload> = {
|
|
6
|
+
readonly [spawnEventMarker]: true;
|
|
7
|
+
readonly payloadType?: Payload;
|
|
8
|
+
};
|
|
9
|
+
type SpawnEventPayload<Descriptor> = Descriptor extends {
|
|
10
|
+
readonly payloadType?: infer Payload;
|
|
11
|
+
} ? Payload : never;
|
|
12
|
+
export type SpawnEventsConfig = Readonly<Record<string, SpawnEventDescriptor<unknown>>>;
|
|
13
|
+
export type SpawnEventsFrom<SpawnEvents extends SpawnEventsConfig> = {
|
|
14
|
+
readonly [Type in keyof SpawnEvents & string]: {
|
|
15
|
+
readonly type: Type;
|
|
16
|
+
readonly payload: SpawnEventPayload<SpawnEvents[Type]>;
|
|
17
|
+
};
|
|
18
|
+
}[keyof SpawnEvents & string];
|
|
19
|
+
type EntityActorMachine = {
|
|
20
|
+
readonly storage: "entity";
|
|
21
|
+
readonly spawnSchema: EntitySpawnSchema;
|
|
22
|
+
};
|
|
23
|
+
type EntityActorKey<Machines extends MachineStore> = {
|
|
24
|
+
readonly [Key in keyof Machines]: Machines[Key] extends EntityActorMachine ? Key : never;
|
|
25
|
+
}[keyof Machines] & string;
|
|
26
|
+
type EntityActorSpawnSchema<Machines extends MachineStore, Key extends EntityActorKey<Machines>> = Machines[Key] extends {
|
|
27
|
+
readonly spawnSchema: infer SpawnSchema extends EntitySpawnSchema;
|
|
28
|
+
} ? SpawnSchema : never;
|
|
29
|
+
type EntitySpawnActors<Machines extends MachineStore> = Partial<{
|
|
30
|
+
readonly [Key in EntityActorKey<Machines>]: EntitySpawnPayload<EntityActorSpawnSchema<Machines, Key>>;
|
|
31
|
+
}>;
|
|
32
|
+
export type EntitySpawnSpec<Machines extends MachineStore = MachineStore> = {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly groupTag: string;
|
|
35
|
+
readonly actors: EntitySpawnActors<Machines>;
|
|
36
|
+
};
|
|
37
|
+
type EntitySpawnRecipeResult<Machines extends MachineStore> = EntitySpawnSpec<Machines> | readonly EntitySpawnSpec<Machines>[];
|
|
38
|
+
export type EntitySpawnRecipes<Machines extends MachineStore, SpawnEvents extends SpawnEventsConfig> = {
|
|
39
|
+
readonly [Type in keyof SpawnEvents & string]: (payload: SpawnEventPayload<SpawnEvents[Type]>) => EntitySpawnRecipeResult<Machines>;
|
|
40
|
+
};
|
|
41
|
+
export type EntitySpawnDescriptor<SpawnEvents extends SpawnEventsConfig = SpawnEventsConfig, Machines extends MachineStore = MachineStore> = {
|
|
42
|
+
readonly [entitySpawnMarker]: true;
|
|
43
|
+
readonly spawnEvents: SpawnEvents;
|
|
44
|
+
readonly recipes: EntitySpawnRecipes<Machines, SpawnEvents>;
|
|
45
|
+
};
|
|
46
|
+
export type EntitySpawnEvents<Spawn> = Spawn extends EntitySpawnDescriptor<infer SpawnEvents, any> ? SpawnEvents : never;
|
|
47
|
+
export type EntitySpawnPluginEvents<Spawn> = SpawnEventsFrom<EntitySpawnEvents<Spawn>>;
|
|
48
|
+
export type AnyEntitySpawnDescriptor = EntitySpawnDescriptor<any, any>;
|
|
49
|
+
export declare const spawnEvent: <Payload>() => SpawnEventDescriptor<Payload>;
|
|
50
|
+
export declare const defineSpawnEvents: <const SpawnEvents extends SpawnEventsConfig>(events: SpawnEvents) => SpawnEvents;
|
|
51
|
+
export declare const defineEntitySpawn: <const Machines extends MachineStore, const SpawnEvents extends SpawnEventsConfig>(_machines: Machines, spawnEvents: SpawnEvents) => (recipes: EntitySpawnRecipes<Machines, SpawnEvents>) => EntitySpawnDescriptor<SpawnEvents, Machines>;
|
|
52
|
+
export declare const isEntitySpawnDescriptor: (value: unknown) => value is AnyEntitySpawnDescriptor;
|
|
53
|
+
export declare function assertEntitySpawnDescriptor(value: unknown): asserts value is AnyEntitySpawnDescriptor;
|
|
54
|
+
export declare const hasSpawnRecipe: (spawn: AnyEntitySpawnDescriptor, type: string) => boolean;
|
|
55
|
+
export declare const runSpawnRecipe: (spawn: AnyEntitySpawnDescriptor, action: AnyEvent) => EntitySpawnRecipeResult<MachineStore>;
|
|
56
|
+
export {};
|
package/dist/spawn.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AnyEvent, MachineStore } from "@lite-fsm/core";
|
|
2
|
+
import type { EntitySpawnPayload, EntitySpawnSchema } from "./schema";
|
|
3
|
+
declare const spawnEventMarker: unique symbol;
|
|
4
|
+
declare const entitySpawnMarker: unique symbol;
|
|
5
|
+
export type SpawnEventDescriptor<Payload> = {
|
|
6
|
+
readonly [spawnEventMarker]: true;
|
|
7
|
+
readonly payloadType?: Payload;
|
|
8
|
+
};
|
|
9
|
+
type SpawnEventPayload<Descriptor> = Descriptor extends {
|
|
10
|
+
readonly payloadType?: infer Payload;
|
|
11
|
+
} ? Payload : never;
|
|
12
|
+
export type SpawnEventsConfig = Readonly<Record<string, SpawnEventDescriptor<unknown>>>;
|
|
13
|
+
export type SpawnEventsFrom<SpawnEvents extends SpawnEventsConfig> = {
|
|
14
|
+
readonly [Type in keyof SpawnEvents & string]: {
|
|
15
|
+
readonly type: Type;
|
|
16
|
+
readonly payload: SpawnEventPayload<SpawnEvents[Type]>;
|
|
17
|
+
};
|
|
18
|
+
}[keyof SpawnEvents & string];
|
|
19
|
+
type EntityActorMachine = {
|
|
20
|
+
readonly storage: "entity";
|
|
21
|
+
readonly spawnSchema: EntitySpawnSchema;
|
|
22
|
+
};
|
|
23
|
+
type EntityActorKey<Machines extends MachineStore> = {
|
|
24
|
+
readonly [Key in keyof Machines]: Machines[Key] extends EntityActorMachine ? Key : never;
|
|
25
|
+
}[keyof Machines] & string;
|
|
26
|
+
type EntityActorSpawnSchema<Machines extends MachineStore, Key extends EntityActorKey<Machines>> = Machines[Key] extends {
|
|
27
|
+
readonly spawnSchema: infer SpawnSchema extends EntitySpawnSchema;
|
|
28
|
+
} ? SpawnSchema : never;
|
|
29
|
+
type EntitySpawnActors<Machines extends MachineStore> = Partial<{
|
|
30
|
+
readonly [Key in EntityActorKey<Machines>]: EntitySpawnPayload<EntityActorSpawnSchema<Machines, Key>>;
|
|
31
|
+
}>;
|
|
32
|
+
export type EntitySpawnSpec<Machines extends MachineStore = MachineStore> = {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly groupTag: string;
|
|
35
|
+
readonly actors: EntitySpawnActors<Machines>;
|
|
36
|
+
};
|
|
37
|
+
type EntitySpawnRecipeResult<Machines extends MachineStore> = EntitySpawnSpec<Machines> | readonly EntitySpawnSpec<Machines>[];
|
|
38
|
+
export type EntitySpawnRecipes<Machines extends MachineStore, SpawnEvents extends SpawnEventsConfig> = {
|
|
39
|
+
readonly [Type in keyof SpawnEvents & string]: (payload: SpawnEventPayload<SpawnEvents[Type]>) => EntitySpawnRecipeResult<Machines>;
|
|
40
|
+
};
|
|
41
|
+
export type EntitySpawnDescriptor<SpawnEvents extends SpawnEventsConfig = SpawnEventsConfig, Machines extends MachineStore = MachineStore> = {
|
|
42
|
+
readonly [entitySpawnMarker]: true;
|
|
43
|
+
readonly spawnEvents: SpawnEvents;
|
|
44
|
+
readonly recipes: EntitySpawnRecipes<Machines, SpawnEvents>;
|
|
45
|
+
};
|
|
46
|
+
export type EntitySpawnEvents<Spawn> = Spawn extends EntitySpawnDescriptor<infer SpawnEvents, any> ? SpawnEvents : never;
|
|
47
|
+
export type EntitySpawnPluginEvents<Spawn> = SpawnEventsFrom<EntitySpawnEvents<Spawn>>;
|
|
48
|
+
export type AnyEntitySpawnDescriptor = EntitySpawnDescriptor<any, any>;
|
|
49
|
+
export declare const spawnEvent: <Payload>() => SpawnEventDescriptor<Payload>;
|
|
50
|
+
export declare const defineSpawnEvents: <const SpawnEvents extends SpawnEventsConfig>(events: SpawnEvents) => SpawnEvents;
|
|
51
|
+
export declare const defineEntitySpawn: <const Machines extends MachineStore, const SpawnEvents extends SpawnEventsConfig>(_machines: Machines, spawnEvents: SpawnEvents) => (recipes: EntitySpawnRecipes<Machines, SpawnEvents>) => EntitySpawnDescriptor<SpawnEvents, Machines>;
|
|
52
|
+
export declare const isEntitySpawnDescriptor: (value: unknown) => value is AnyEntitySpawnDescriptor;
|
|
53
|
+
export declare function assertEntitySpawnDescriptor(value: unknown): asserts value is AnyEntitySpawnDescriptor;
|
|
54
|
+
export declare const hasSpawnRecipe: (spawn: AnyEntitySpawnDescriptor, type: string) => boolean;
|
|
55
|
+
export declare const runSpawnRecipe: (spawn: AnyEntitySpawnDescriptor, action: AnyEvent) => EntitySpawnRecipeResult<MachineStore>;
|
|
56
|
+
export {};
|