@awesome-ecs/abstract 0.32.1 → 0.34.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 (38) hide show
  1. package/README.md +119 -125
  2. package/dist/components/index.cjs.map +1 -1
  3. package/dist/components/index.d.cts +2 -2
  4. package/dist/components/index.d.mts +2 -2
  5. package/dist/components/index.mjs.map +1 -1
  6. package/dist/entities/index.cjs +5 -19
  7. package/dist/entities/index.cjs.map +1 -1
  8. package/dist/entities/index.d.cts +3 -3
  9. package/dist/entities/index.d.mts +3 -3
  10. package/dist/entities/index.mjs +5 -20
  11. package/dist/entities/index.mjs.map +1 -1
  12. package/dist/factories/index.cjs.map +1 -1
  13. package/dist/factories/index.d.cts +2 -2
  14. package/dist/factories/index.d.mts +2 -2
  15. package/dist/factories/index.mjs.map +1 -1
  16. package/dist/{index-CeqaKmWR.d.mts → index-B3DqdxE6.d.mts} +11 -11
  17. package/dist/{index-vpjRaGIC.d.mts → index-BanhgPCc.d.mts} +103 -262
  18. package/dist/{index-BD7sDB60.d.mts → index-BivyWazf.d.cts} +257 -407
  19. package/dist/{index-BOsrKTWm.d.cts → index-CSaKdQe-.d.cts} +103 -262
  20. package/dist/{index-BJFNTFDd.d.cts → index-DGyDijY7.d.mts} +257 -407
  21. package/dist/{index-C5nragoq.d.cts → index-DMZSrHoB.d.cts} +141 -100
  22. package/dist/{index-BlP67nCr.d.mts → index-Dbwzlrgp.d.mts} +141 -100
  23. package/dist/{index-DMTkNY1e.d.cts → index-aVjnG975.d.cts} +11 -11
  24. package/dist/pipelines/index.d.cts +2 -2
  25. package/dist/pipelines/index.d.mts +2 -2
  26. package/dist/systems/index.cjs +8 -5
  27. package/dist/systems/index.cjs.map +1 -1
  28. package/dist/systems/index.d.cts +90 -2
  29. package/dist/systems/index.d.mts +90 -2
  30. package/dist/systems/index.mjs +8 -5
  31. package/dist/systems/index.mjs.map +1 -1
  32. package/dist/{types-Bbmnq4ni.d.cts → types-BaCGIrym.d.cts} +19 -4
  33. package/dist/{types-C1ojaDL4.d.mts → types-BaCGIrym.d.mts} +19 -4
  34. package/dist/utils/index.cjs.map +1 -1
  35. package/dist/utils/index.d.cts +2 -2
  36. package/dist/utils/index.d.mts +2 -2
  37. package/dist/utils/index.mjs.map +1 -1
  38. package/package.json +2 -2
@@ -1,8 +1,46 @@
1
- import { _ as ConfigRecord, a as IEntity, c as IEntityProxy, f as ComponentTypeUid, i as EntityUid, l as IEntityProxyRepository, o as IEntityModel, r as EntityTypeUid, s as EntityProxy } from "./index-BlP67nCr.mjs";
2
- import { r as Immutable } from "./types-C1ojaDL4.mjs";
3
- import { c as IEntitySnapshot, d as EntityEventSubscriptionOptions, f as EntityEventUid, g as IEventData, o as IEntityUpdate, p as IEntityEvent, v as IEntityConfigSnapshot } from "./index-vpjRaGIC.mjs";
4
- import { c as IMiddleware, l as IPipelineContext, o as IPipeline, u as PipelineRuntime } from "./index-CeqaKmWR.mjs";
1
+ import { T as ConfigRecord, a as IEntityProxy, b as ComponentTypeUid, f as IEntity, h as IEntitySpec, i as EntityProxyManyLookup, n as EntityProxy, p as IEntityModel, r as EntityProxyLookup, u as EntityTypeUid } from "./index-DMZSrHoB.cjs";
2
+ import { r as Immutable } from "./types-BaCGIrym.cjs";
3
+ import { b as IEntityConfigSnapshot, c as IEntityUpdate, g as IEntityEvent, h as EntityEventUid, m as EntityEventSubscriptionOptions, u as IEntitySnapshot, y as IEventData } from "./index-CSaKdQe-.cjs";
4
+ import { c as IMiddleware, l as IPipelineContext, o as IPipeline, u as PipelineDispatch } from "./index-aVjnG975.cjs";
5
5
 
6
+ //#region src/utils/dispatch-sequential.d.ts
7
+ /**
8
+ * Executes a function for each item in an iterable, sequentially.
9
+ *
10
+ * Uses a sync fast-path: iterates synchronously until the first Promise is
11
+ * encountered, then switches to async for the remainder. If no item produces
12
+ * a Promise, the entire call stays synchronous with zero async overhead.
13
+ *
14
+ * @param items - The iterable to iterate over.
15
+ * @param fn - The function to call for each item. May return void or a Promise.
16
+ * @returns void if all calls were synchronous, or a Promise if any were async.
17
+ */
18
+ declare function dispatchSequential<T>(items: Iterable<T>, fn: (item: T) => void | Promise<void>): void | Promise<void>;
19
+ //#endregion
20
+ //#region src/utils/json-serializer.d.ts
21
+ /**
22
+ * Custom JSON serialization and deserialization interface.
23
+ * Allows different serialization strategies for handling complex types.
24
+ * Used for entity snapshots, events, and any data needing JSON conversion.
25
+ */
26
+ interface IJsonSerializer {
27
+ /**
28
+ * Converts an object to a serializable JSON representation.
29
+ * Handles types that don't serialize naturally (dates, maps, custom objects, etc.).
30
+ * @param value - The object to serialize.
31
+ * @returns A JSON-serializable representation.
32
+ */
33
+ serializeCustom(value: object): string;
34
+ /**
35
+ * Converts a JSON string back to its original object type.
36
+ * Reconstructs complex types from their serialized form.
37
+ * @template TObject - The target object type.
38
+ * @param text - The JSON string to deserialize.
39
+ * @returns The deserialized object of the specified type.
40
+ */
41
+ parseCustom<TObject>(text: string): TObject;
42
+ }
43
+ //#endregion
6
44
  //#region src/utils/logger.d.ts
7
45
  /**
8
46
  * Logger interface for debug and diagnostic output.
@@ -78,6 +116,103 @@ interface ILoggerOptions {
78
116
  enabled: Map<LogLevel, boolean>;
79
117
  }
80
118
  //#endregion
119
+ //#region src/utils/performance.d.ts
120
+ type TickMetricEntry = {
121
+ name: string;
122
+ category: string;
123
+ totalMs: number;
124
+ count: number;
125
+ };
126
+ type TickSnapshot = {
127
+ tickIndex: number;
128
+ tickDurationMs: number;
129
+ fps: number;
130
+ queueSize: number;
131
+ timestamp: number;
132
+ metrics: TickMetricEntry[];
133
+ render?: RenderSnapshot;
134
+ };
135
+ type RenderSnapshot = {
136
+ frameTimeMs: number;
137
+ renderTimeMs: number;
138
+ gpuFrameTimeMs: number;
139
+ drawCalls: number;
140
+ activeMeshesEvalMs: number;
141
+ cameraRenderMs: number;
142
+ totalVertices: number;
143
+ activeIndices: number;
144
+ };
145
+ type MiddlewareMetricsSummary = {
146
+ name: string;
147
+ category: PipelineCategoryName;
148
+ count: number;
149
+ totalMs: number;
150
+ avgMs: number;
151
+ minMs: number;
152
+ maxMs: number;
153
+ lastMs: number;
154
+ };
155
+ //#endregion
156
+ //#region src/utils/performance-timer.d.ts
157
+ /**
158
+ * Unique identifier for a timer instance.
159
+ */
160
+ type PerformanceTimerUid = number;
161
+ /**
162
+ * Options for identifying and categorizing performance metrics.
163
+ * Used by pipeline factories and performance decorators.
164
+ */
165
+ type PerformanceMetricOptions = {
166
+ name?: string;
167
+ category?: string;
168
+ };
169
+ /**
170
+ * Record of a completed timer measurement.
171
+ * Captures timing information for performance analysis and profiling.
172
+ */
173
+ interface PerformanceTimeEntry {
174
+ /**
175
+ * The name identifying this timer.
176
+ */
177
+ name: string;
178
+ /**
179
+ * The category of this metric (e.g. 'module', 'runtime', 'system').
180
+ */
181
+ category?: string;
182
+ /**
183
+ * Timestamp in milliseconds when the timer started.
184
+ */
185
+ startedAt: number;
186
+ /**
187
+ * Timestamp in milliseconds when the timer ended.
188
+ */
189
+ endedAt?: number;
190
+ /**
191
+ * Duration in milliseconds that elapsed.
192
+ */
193
+ msPassed?: number;
194
+ }
195
+ /**
196
+ * Interface for measuring operation duration.
197
+ * Provides start/stop functionality for performance profiling.
198
+ * Used throughout the system to collect timing metrics.
199
+ */
200
+ interface IPerformanceTimer {
201
+ /**
202
+ * Starts a new timer.
203
+ * @param name - Label for this timer (used in results).
204
+ * @param category - Optional category for grouping metrics.
205
+ * @returns A unique identifier for this timer instance.
206
+ */
207
+ startTimer(name: string, category?: string): PerformanceTimerUid;
208
+ /**
209
+ * Stops a timer and returns the recorded metrics.
210
+ * @param timerUid - The timer identifier returned by startTimer.
211
+ * @returns Complete timing entry with start, end, and duration.
212
+ */
213
+ endTimer(timerUid: PerformanceTimerUid): PerformanceTimeEntry;
214
+ }
215
+ //#endregion
81
216
  //#region src/systems/pipeline/system-context-config.d.ts
82
217
  /**
83
218
  * Config-specific API for the current system execution.
@@ -142,14 +277,25 @@ type MiddlewareRegistryReadonly = ReadonlyMap<SystemMiddlewareName, SystemModule
142
277
  * @template TEntity - The entity type this middleware handles.
143
278
  */
144
279
  type ISystemMiddleware<TEntity extends IEntity> = IMiddleware<ISystemContext<TEntity>>;
280
+ /**
281
+ * Event-routed middleware. Unlike normal system middleware, event middleware is
282
+ * invoked once per matching event instance and receives that event explicitly.
283
+ */
284
+ interface ISystemEventMiddleware<TEntity extends IEntity, TEventData extends IEventData = IEventData> {
285
+ readonly name?: string;
286
+ shouldRun?(context: ISystemContext<TEntity>, event: IEntityEvent<TEventData>): boolean;
287
+ action(context: ISystemContext<TEntity>, event: IEntityEvent<TEventData>): void | Promise<void>;
288
+ cleanup?(context: ISystemContext<TEntity>): void | Promise<void>;
289
+ }
145
290
  //#endregion
146
291
  //#region src/systems/pipeline/system-context-control.d.ts
292
+ interface SystemContextControlTarget {
293
+ readonly name?: string;
294
+ }
147
295
  declare enum SystemContextControlState {
148
296
  none = "none",
149
297
  enableCurrentSystem = "enableCurrentSystem",
150
- disableCurrentSystem = "disableCurrentSystem",
151
- enableCurrentModule = "enableCurrentModule",
152
- disableCurrentModule = "disableCurrentModule"
298
+ disableCurrentSystem = "disableCurrentSystem"
153
299
  }
154
300
  /**
155
301
  * Interface for controlling the execution of systems and modules within a system context.
@@ -165,13 +311,13 @@ interface ISystemContextControl {
165
311
  */
166
312
  enableCurrentSystem(): void;
167
313
  /**
168
- * Disables the current module for the current entity.
314
+ * Disables a module for the current entity.
169
315
  */
170
- disableCurrentModule(): void;
316
+ disableModule(name: SystemModuleName): void;
171
317
  /**
172
- * Re-enables the current module for the current entity.
318
+ * Re-enables a module for the current entity.
173
319
  */
174
- enableCurrentModule(): void;
320
+ enableModule(name: SystemModuleName): void;
175
321
  }
176
322
  /**
177
323
  * Extended system context interface that includes control state for middleware to manage system and module execution.
@@ -187,33 +333,32 @@ interface ISystemContextControlState extends ISystemContextControl {
187
333
  * @param middleware - The middleware to check for disabled state.
188
334
  * @returns True if the specified middleware is currently disabled, false otherwise.
189
335
  */
190
- isMiddlewareDisabled(middleware: ISystemMiddleware<IEntity>): boolean;
336
+ isMiddlewareDisabled(middleware: SystemContextControlTarget): boolean;
191
337
  /**
192
338
  * Disables a specific middleware in the context.
193
339
  * @param middleware - The middleware to disable.
194
340
  */
195
- disableMiddleware(middleware: ISystemMiddleware<IEntity>): void;
341
+ disableMiddleware(middleware: SystemContextControlTarget): void;
196
342
  /**
197
343
  * Enables a specific middleware in the context.
198
344
  * @param middleware - The middleware to enable.
199
345
  */
200
- enableMiddleware(middleware: ISystemMiddleware<IEntity>): void;
346
+ enableMiddleware(middleware: SystemContextControlTarget): void;
201
347
  /**
202
- * Disables an entire module of middleware in the context.
203
- * @param middleware - A middleware from the module to disable.
348
+ * Registers an event subscription owned by a module. This is runtime-only state:
349
+ * disabling the module should also detach its event subscriptions.
204
350
  */
205
- disableModule(middleware: ISystemMiddleware<IEntity>): void;
351
+ registerModuleEvent(moduleName: SystemModuleName, eventUid: EntityEventUid, options?: EntityEventSubscriptionOptions): void;
206
352
  /**
207
- * Enables an entire module of middleware in the context.
208
- * @param middleware - A middleware from the module to enable.
353
+ * Clears all runtime-owned module event subscriptions for the current entity.
209
354
  */
210
- enableModule(middleware: ISystemMiddleware<IEntity>): void;
355
+ clearModuleEvents(): void;
211
356
  }
212
357
  //#endregion
213
358
  //#region src/systems/pipeline/system-context-events.d.ts
214
359
  /**
215
360
  * System context API for event-driven entity communication.
216
- * Allows middleware to dispatch events, manage subscriptions, and query event state.
361
+ * System middleware can dispatch events, while subscriptions are owned by the runtime.
217
362
  * Events enable decoupled communication between distant or unrelated entities.
218
363
  */
219
364
  interface ISystemContextEvents {
@@ -243,56 +388,10 @@ interface ISystemContextEvents {
243
388
  * @param data - Array of event payloads to broadcast.
244
389
  */
245
390
  broadcastEvents<TEventData extends IEventData>(data: TEventData[]): void;
246
- /**
247
- * Retrieves an event from the current context by its identifier.
248
- * Useful for checking if an event was received this frame.
249
- * @param uid - The event type identifier.
250
- * @returns The event if present, undefined otherwise.
251
- */
252
- getEvent<TEventData extends IEventData>(uid: EntityEventUid): IEntityEvent<TEventData> | undefined;
253
- /**
254
- * Retrieves all events currently set on this context.
255
- * Events are cleared between frames.
256
- * @returns Array of all active events for this context.
257
- */
258
- listEvents<TEventData extends IEventData>(): IEntityEvent<TEventData>[];
259
- /**
260
- * Checks if a specific event is present in the current context.
261
- * If no uid is provided, checks if any events exist.
262
- * @param uid - Optional event type to check for. If omitted, checks for any event.
263
- * @returns True if matching event(s) found, false otherwise.
264
- */
265
- hasEvent(uid?: EntityEventUid): boolean;
266
- /**
267
- * Subscribes to events of a specific type.
268
- * The entity will be notified of matching events through the update system.
269
- * @param uid - The event type to listen for.
270
- * @param options - Optional subscription options (filter, scopeId).
271
- */
391
+ }
392
+ interface IMutableSystemContextEvents extends ISystemContextEvents {
272
393
  subscribeTo(uid: EntityEventUid, options?: EntityEventSubscriptionOptions): void;
273
- /**
274
- * Stops listening for events of a specific type.
275
- * @param uid - The event type to stop listening for.
276
- */
277
394
  unsubscribeFrom(uid: EntityEventUid): void;
278
- /**
279
- * Adds events to the current context for processing by this and downstream middleware.
280
- * @param events - Event array to add to context.
281
- */
282
- setContextEvents(events: IEntityEvent<IEventData>[]): void;
283
- /**
284
- * Adds a single event to the current context.
285
- * @param event - Event to add to context.
286
- */
287
- setContextEvent(event: IEntityEvent<IEventData>): void;
288
- /**
289
- * Removes all events from the current context.
290
- */
291
- clearContextEvents(): void;
292
- /**
293
- * Clears all event subscriptions for the current entity.
294
- */
295
- clearSubscriptions(): void;
296
395
  }
297
396
  //#endregion
298
397
  //#region src/systems/pipeline/system-context-proxies.d.ts
@@ -322,30 +421,18 @@ interface ISystemContextProxies {
322
421
  * @param proxy - The entity reference to remove.
323
422
  */
324
423
  remove(proxy: IEntityProxy): void;
325
- /**
326
- * Removes all entity references from the current entity.
327
- * Optionally filter by target entity type.
328
- * @param targetType - If provided, only removes references to entities of this type.
329
- */
330
- removeAll(targetType?: EntityTypeUid): void;
331
424
  /**
332
425
  * Retrieves a single reference of a specific entity type from the current entity.
333
426
  * @param targetType - The entity type to find.
334
427
  * @returns The first matching proxy, or null if not found.
335
428
  */
336
- get(targetType: EntityTypeUid): IEntityProxy | null;
429
+ getProxy<TEntity extends IEntity = IEntity>(targetType: EntityProxyLookup<TEntity>): EntityProxy<TEntity> | null;
337
430
  /**
338
431
  * Retrieves all references to entities of a specific type from the current entity.
339
432
  * @param targetType - The entity type to find.
340
433
  * @returns Array of matching proxies.
341
434
  */
342
- getMany(targetType: EntityTypeUid): Readonly<IEntityProxy[]>;
343
- /**
344
- * Retrieves all entity references from the current entity.
345
- * Organized by target entity type.
346
- * @returns Map of entity type to their proxies.
347
- */
348
- getAll(): ReadonlyMap<EntityTypeUid, Readonly<IEntityProxy[]>>;
435
+ getProxies<TEntity extends IEntity = IEntity>(targetType: EntityProxyManyLookup<TEntity>): Readonly<EntityProxy<TEntity>[]>;
349
436
  }
350
437
  //#endregion
351
438
  //#region src/systems/pipeline/system-context-repository.d.ts
@@ -369,7 +456,28 @@ interface ISystemContextRepository {
369
456
  * @param proxy - Reference to the entity.
370
457
  * @returns The immutable entity instance.
371
458
  */
372
- getEntity<TEntity extends IEntity>(proxy: EntityProxy<TEntity> | EntityTypeUid): Immutable<TEntity>;
459
+ getEntity<TEntity extends IEntity>(proxy: EntityProxy<TEntity> | null | undefined): TEntity | undefined;
460
+ /**
461
+ * Retrieves an entity from storage based on its type.
462
+ * @template TEntity - The expected entity type.
463
+ * @param targetType - Reference to the entity type.
464
+ * @returns The immutable entity instance.
465
+ */
466
+ getEntity<TEntity extends IEntity>(targetType: EntityProxyLookup<TEntity> | null | undefined): TEntity | undefined;
467
+ /**
468
+ * Retrieves an entity from storage based on its type or proxy.
469
+ * @template TEntity - The expected entity type.
470
+ * @param proxyOrTargetType - Reference to the entity proxy or type.
471
+ * @returns The immutable entity instance.
472
+ */
473
+ getEntity<TEntity extends IEntity>(proxy: EntityProxy<TEntity> | EntityProxyLookup<TEntity> | null | undefined): TEntity | undefined;
474
+ /**
475
+ * Retrieves all entities from the current entity's proxy relationships.
476
+ * @template TEntity - The expected entity type.
477
+ * @param targetType - Reference to the entity type.
478
+ * @returns The immutable entity instances.
479
+ */
480
+ getEntities<TEntity extends IEntity>(targetType: EntityProxyManyLookup<TEntity> | null | undefined): Readonly<TEntity[]>;
373
481
  /**
374
482
  * Enqueues an entity for update.
375
483
  * Triggers the update pipeline for the entity.
@@ -413,30 +521,6 @@ interface ISystemContextScheduler {
413
521
  hasSchedule(target?: IEntityProxy): boolean;
414
522
  }
415
523
  //#endregion
416
- //#region src/utils/json-serializer.d.ts
417
- /**
418
- * Custom JSON serialization and deserialization interface.
419
- * Allows different serialization strategies for handling complex types.
420
- * Used for entity snapshots, events, and any data needing JSON conversion.
421
- */
422
- interface IJsonSerializer {
423
- /**
424
- * Converts an object to a serializable JSON representation.
425
- * Handles types that don't serialize naturally (dates, maps, custom objects, etc.).
426
- * @param value - The object to serialize.
427
- * @returns A JSON-serializable representation.
428
- */
429
- serializeCustom(value: object): string;
430
- /**
431
- * Converts a JSON string back to its original object type.
432
- * Reconstructs complex types from their serialized form.
433
- * @template TObject - The target object type.
434
- * @param text - The JSON string to deserialize.
435
- * @returns The deserialized object of the specified type.
436
- */
437
- parseCustom<TObject>(text: string): TObject;
438
- }
439
- //#endregion
440
524
  //#region src/systems/pipeline/system-context-snapshot.d.ts
441
525
  /**
442
526
  * System context API for entity serialization and state transfer.
@@ -484,7 +568,7 @@ interface ISystemContext<TEntity extends IEntity> extends IPipelineContext {
484
568
  * Time elapsed since the last system update for this entity, in milliseconds.
485
569
  * Useful for time-based calculations and animations.
486
570
  */
487
- readonly deltaTimeMs: Immutable<number>;
571
+ readonly deltaTimeMs: number;
488
572
  /**
489
573
  * The entity currently being processed by this middleware.
490
574
  */
@@ -492,44 +576,44 @@ interface ISystemContext<TEntity extends IEntity> extends IPipelineContext {
492
576
  /**
493
577
  * Config metadata and config-update API for the current update.
494
578
  */
495
- readonly config: Immutable<ISystemContextConfigReadonly>;
579
+ readonly config: ISystemContextConfigReadonly;
496
580
  /**
497
581
  * Information about the update triggering this system execution.
498
582
  * Contains type (update/remove) and optional model/snapshot data.
499
583
  */
500
- readonly update: Immutable<IEntityUpdate>;
584
+ readonly update: IEntityUpdate;
501
585
  /**
502
- * Event system API for publishing and subscribing to entity events.
586
+ * Event system API for publishing entity events.
503
587
  */
504
- readonly events: Immutable<ISystemContextEvents>;
588
+ readonly events: ISystemContextEvents;
505
589
  /**
506
590
  * Logging interface for debug and diagnostic output.
507
591
  */
508
- readonly logger: Immutable<ILogger>;
592
+ readonly logger: ILogger;
509
593
  /**
510
594
  * Proxy management API for establishing and managing entity relationships.
511
595
  */
512
- readonly proxies: Immutable<ISystemContextProxies>;
596
+ readonly proxies: ISystemContextProxies;
513
597
  /**
514
598
  * Repository access API for querying and modifying entity storage.
515
599
  */
516
- readonly repository: Immutable<ISystemContextRepository>;
600
+ readonly repository: ISystemContextRepository;
517
601
  /**
518
602
  * Scheduling API for requesting follow-up entity updates.
519
603
  */
520
- readonly scheduler: Immutable<ISystemContextScheduler>;
604
+ readonly scheduler: ISystemContextScheduler;
521
605
  /**
522
606
  * Snapshot management API for serialization and state transfer.
523
607
  */
524
- readonly snapshot: Immutable<ISystemContextSnapshot>;
608
+ readonly snapshot: ISystemContextSnapshot;
525
609
  /**
526
610
  * Control API for enabling/disabling the current system or entire module during execution.
527
611
  */
528
- readonly systems: Immutable<ISystemContextControl>;
612
+ readonly systems: ISystemContextControl;
529
613
  /**
530
- * The per-entity runtime state and control interface for this system context.
614
+ * The per-entity dispatch state and control interface for this system context.
531
615
  */
532
- readonly runtime: PipelineRuntime;
616
+ readonly dispatch: PipelineDispatch;
533
617
  }
534
618
  //#endregion
535
619
  //#region src/systems/pipeline/system-context-mutable.d.ts
@@ -541,154 +625,15 @@ interface ISystemContext<TEntity extends IEntity> extends IPipelineContext {
541
625
  * @template TEntity - The specific entity type this context operates on.
542
626
  */
543
627
  interface IMutableSystemContext<TEntity extends IEntity> extends ISystemContext<TEntity> {
628
+ readonly events: IMutableSystemContextEvents;
544
629
  setUpdate(update: IEntityUpdate): void;
545
630
  setDeltaTime(deltaTimeMs: number): void;
546
- setRuntime(runtime: PipelineRuntime): void;
547
- }
548
- //#endregion
549
- //#region src/utils/dispatch-sequential.d.ts
550
- /**
551
- * Executes a function for each item in an iterable, sequentially.
552
- *
553
- * Uses a sync fast-path: iterates synchronously until the first Promise is
554
- * encountered, then switches to async for the remainder. If no item produces
555
- * a Promise, the entire call stays synchronous with zero async overhead.
556
- *
557
- * @param items - The iterable to iterate over.
558
- * @param fn - The function to call for each item. May return void or a Promise.
559
- * @returns void if all calls were synchronous, or a Promise if any were async.
560
- */
561
- declare function dispatchSequential<T>(items: Iterable<T>, fn: (item: T) => void | Promise<void>): void | Promise<void>;
562
- //#endregion
563
- //#region src/utils/performance.d.ts
564
- type TickMetricEntry = {
565
- name: string;
566
- category: string;
567
- totalMs: number;
568
- count: number;
569
- };
570
- type TickSnapshot = {
571
- tickIndex: number;
572
- tickDurationMs: number;
573
- fps: number;
574
- queueSize: number;
575
- timestamp: number;
576
- metrics: TickMetricEntry[];
577
- render?: RenderSnapshot;
578
- };
579
- type RenderSnapshot = {
580
- frameTimeMs: number;
581
- renderTimeMs: number;
582
- gpuFrameTimeMs: number;
583
- drawCalls: number;
584
- activeMeshesEvalMs: number;
585
- cameraRenderMs: number;
586
- totalVertices: number;
587
- activeIndices: number;
588
- };
589
- type MiddlewareMetricsSummary = {
590
- name: string;
591
- category: PipelineCategoryName;
592
- count: number;
593
- totalMs: number;
594
- avgMs: number;
595
- minMs: number;
596
- maxMs: number;
597
- lastMs: number;
598
- };
599
- //#endregion
600
- //#region src/utils/performance-timer.d.ts
601
- /**
602
- * Unique identifier for a timer instance.
603
- */
604
- type PerformanceTimerUid = number;
605
- /**
606
- * Options for identifying and categorizing performance metrics.
607
- * Used by pipeline factories and performance decorators.
608
- */
609
- type PerformanceMetricOptions = {
610
- name?: string;
611
- category?: string;
612
- };
613
- /**
614
- * Record of a completed timer measurement.
615
- * Captures timing information for performance analysis and profiling.
616
- */
617
- interface PerformanceTimeEntry {
618
- /**
619
- * The name identifying this timer.
620
- */
621
- name: string;
622
- /**
623
- * The category of this metric (e.g. 'module', 'runtime', 'system').
624
- */
625
- category?: string;
626
- /**
627
- * Timestamp in milliseconds when the timer started.
628
- */
629
- startedAt: number;
630
- /**
631
- * Timestamp in milliseconds when the timer ended.
632
- */
633
- endedAt?: number;
634
- /**
635
- * Duration in milliseconds that elapsed.
636
- */
637
- msPassed?: number;
638
- }
639
- /**
640
- * Interface for measuring operation duration.
641
- * Provides start/stop functionality for performance profiling.
642
- * Used throughout the system to collect timing metrics.
643
- */
644
- interface IPerformanceTimer {
645
- /**
646
- * Starts a new timer.
647
- * @param name - Label for this timer (used in results).
648
- * @param category - Optional category for grouping metrics.
649
- * @returns A unique identifier for this timer instance.
650
- */
651
- startTimer(name: string, category?: string): PerformanceTimerUid;
652
- /**
653
- * Stops a timer and returns the recorded metrics.
654
- * @param timerUid - The timer identifier returned by startTimer.
655
- * @returns Complete timing entry with start, end, and duration.
656
- */
657
- endTimer(timerUid: PerformanceTimerUid): PerformanceTimeEntry;
631
+ setDispatch(dispatch: PipelineDispatch): void;
658
632
  }
659
633
  //#endregion
660
634
  //#region src/factories/context-factory.d.ts
661
- /**
662
- * Creates and caches per-entity system contexts.
663
- *
664
- * On the first call for a given entity, creates a new SystemContext with all sub-contexts
665
- * (events, proxies, repository, scheduler, snapshot) bound to that entity.
666
- * Subsequent calls return the cached context. Disposal removes all cache entries for an entity.
667
- */
668
635
  interface IContextFactory {
669
- /**
670
- * Creates or retrieves the cached system context for the given entity.
671
- * On first call, creates sub-contexts bound to the entity.
672
- * On subsequent calls, returns the cached context.
673
- * @template TEntity - The entity type for which the system context is being created.
674
- * @param entity - The entity to create or retrieve the context for.
675
- * @param registry - Optional middleware registry to associate with the context for pipeline execution.
676
- * @returns The mutable system context for the entity.
677
- */
678
- getOrCreateContext<TEntity extends IEntity>(entity: Immutable<TEntity>, registry?: MiddlewareRegistryReadonly): IMutableSystemContext<TEntity>;
679
- /**
680
- * Retrieves a previously cached system context by entity UID.
681
- * @template TEntity - The entity type.
682
- * @param entityUid - The entity's unique identifier.
683
- * @returns The cached context, or undefined if not found.
684
- */
685
- getContext<TEntity extends IEntity>(entityUid: EntityUid): IMutableSystemContext<TEntity> | undefined;
686
- /**
687
- * Disposes all cached contexts for the given entity.
688
- * Removes the entity from the repository and clears all cache entries.
689
- * @param entityUid - The entity's unique identifier.
690
- */
691
- disposeEntity(entityUid: EntityUid): void;
636
+ createContext<TEntity extends IEntity>(entity: Immutable<TEntity>, registry?: MiddlewareRegistryReadonly): IMutableSystemContext<TEntity>;
692
637
  }
693
638
  //#endregion
694
639
  //#region src/factories/pipeline-factory.d.ts
@@ -749,21 +694,40 @@ declare enum SystemType {
749
694
  * Runs on entity creation and on updates that carry a config payload.
750
695
  */
751
696
  config = 1,
697
+ /**
698
+ * Event reactions routed by event uid.
699
+ * Runs after config and before update for updates carrying events.
700
+ */
701
+ event = 2,
752
702
  /**
753
703
  * Main logic and state updates for the entity.
754
704
  * Runs on every update to change entity behavior and properties.
755
705
  */
756
- update = 2,
706
+ update = 3,
757
707
  /**
758
708
  * Output and visualization operations.
759
709
  * Runs after updates to render or display the entity state.
760
710
  */
761
- render = 3,
711
+ render = 4,
762
712
  /**
763
713
  * Synchronization and persistence.
764
714
  * Runs last to synchronize state with external systems or storage.
765
715
  */
766
- sync = 4
716
+ sync = 5
717
+ }
718
+ //#endregion
719
+ //#region src/systems/module/systems-module.d.ts
720
+ /**
721
+ * Collection of pipelines for a specific entity type.
722
+ * Defines the complete system processing flow for one entity category.
723
+ *
724
+ * @template TEntity - The entity type this module processes.
725
+ */
726
+ interface ISystemsModule<TEntity extends IEntity> {
727
+ /**
728
+ * The builder instance used to construct this module.
729
+ */
730
+ readonly builder: ISystemsModuleBuilderReadonly<TEntity>;
767
731
  }
768
732
  //#endregion
769
733
  //#region src/systems/module/systems-module-builder.d.ts
@@ -776,6 +740,10 @@ interface ISystemsModuleBuilderReadonly<TEntity extends IEntity> {
776
740
  * Read-only map of system pipelines keyed by SystemType.
777
741
  */
778
742
  readonly pipelines: ReadonlyMap<SystemType, IPipeline<ISystemContext<TEntity>>>;
743
+ /**
744
+ * Event middleware keyed by event uid.
745
+ */
746
+ readonly eventMiddlewares: ReadonlyMap<EntityEventUid, ReadonlyArray<ISystemEventMiddleware<TEntity>>>;
779
747
  /**
780
748
  * Read-only registry mapping middleware names to their originating module names.
781
749
  */
@@ -785,9 +753,10 @@ interface ISystemsModuleBuilderReadonly<TEntity extends IEntity> {
785
753
  */
786
754
  readonly scopeRoot: boolean;
787
755
  /**
788
- * Whether this entity type is a scoped proxy. When initialized, the entity registers itself in the inherited scope, making it resolvable via `context.proxies.get()` by any entity in the same scope.
756
+ * Whether this entity type is a scoped proxy. When initialized, the entity registers itself in the inherited scope, making it resolvable via `context.proxies.getProxy()` by any entity in the same scope.
789
757
  */
790
758
  readonly scopedProxy: boolean;
759
+ readonly entitySpec?: IEntitySpec<TEntity>;
791
760
  }
792
761
  /**
793
762
  * Builder pattern interface for constructing system modules.
@@ -806,15 +775,30 @@ interface ISystemsModuleBuilder<TEntity extends IEntity> extends ISystemsModuleB
806
775
  * @returns This builder for method chaining.
807
776
  */
808
777
  addSystems(type: SystemType, systems: Immutable<ISystemMiddleware<TEntity>[]>): this;
778
+ /**
779
+ * Registers event-routed middleware for a specific event uid.
780
+ * Event middleware are invoked once per matching event instance.
781
+ */
782
+ addEventSystems(uid: EntityEventUid, systems: Immutable<ISystemEventMiddleware<TEntity>[]>): this;
809
783
  /**
810
784
  * Integrates an entire module's pipelines into this builder.
811
- * Allows composition of multiple modules into one.
812
- * @template TModuleEntity - The module's entity type (must extend current type).
785
+ *
786
+ * Composition is gated by structural assignability: the host's `TEntity` must extend
787
+ * the inner module's `TInner`. In other words, the host entity contract must contain
788
+ * every field the inner module reads from `context.entity`.
789
+ *
790
+ * @template TInner - The inner module's entity type; must be assignable from `TEntity`.
813
791
  * @param module - The module to integrate.
814
792
  * @param systemType - Optional specific pipeline to integrate from module. If omitted, integrates all.
815
793
  * @returns This builder for method chaining.
816
794
  */
817
- addModule<TModuleEntity extends TEntity>(module: ISystemsModule<TModuleEntity>, systemType?: SystemType): this;
795
+ addModule<TInner extends IEntity>(module: TEntity extends TInner ? ISystemsModule<TInner> : never, systemType?: SystemType): this;
796
+ /**
797
+ * Declares this module's entity creation spec. `type` carries the entity type UID;
798
+ * `init` constructs and returns the entity at first creation. The dispatcher validates
799
+ * at runtime that the returned entity's `identity.entityType` matches `type`.
800
+ */
801
+ setEntity(spec: IEntitySpec<TEntity>): this;
818
802
  /**
819
803
  * Marks this entity type as a scope root.
820
804
  * When initialized, a new scope is auto-generated and all child entities inherit it.
@@ -824,146 +808,12 @@ interface ISystemsModuleBuilder<TEntity extends IEntity> extends ISystemsModuleB
824
808
  /**
825
809
  * Marks this entity type as a scoped proxy.
826
810
  * When initialized, the entity registers itself in the inherited scope,
827
- * making it resolvable via `context.proxies.get()` by any entity in the same scope.
811
+ * making it resolvable via `context.proxies.getProxy()` by any entity in the same scope.
828
812
  * @returns This builder for method chaining.
829
813
  */
830
814
  setScopedProxy(): this;
831
815
  }
832
816
  //#endregion
833
- //#region src/systems/module/systems-module.d.ts
834
- /**
835
- * Collection of pipelines for a specific entity type.
836
- * Defines the complete system processing flow for one entity category.
837
- *
838
- * @template TEntity - The entity type this module processes.
839
- */
840
- interface ISystemsModule<TEntity extends IEntity> {
841
- /**
842
- * The builder instance used to construct this module.
843
- */
844
- readonly builder: ISystemsModuleBuilderReadonly<TEntity>;
845
- /**
846
- * Optional factory function to initialize new entity instances.
847
- * If provided, is called when a new entity of this type is created.
848
- * @param model - The initialization model.
849
- * @returns The initialized entity.
850
- */
851
- readonly initEntity?: (model: IEntityModel) => TEntity;
852
- }
853
- //#endregion
854
- //#region src/systems/module/systems-module-repository.d.ts
855
- /**
856
- * Central registry for all systems modules in the ECS.
857
- * Maintains a module for each entity type, providing access to all system pipelines.
858
- * This is the authoritative source for system module data.
859
- *
860
- * @template TEntity - The entity types managed by modules in this repository.
861
- */
862
- interface ISystemsModuleRepository {
863
- /**
864
- * The total number of modules in the repository.
865
- */
866
- readonly size: number;
867
- /**
868
- * Retrieves the module for a specific entity type.
869
- * @template TEntity - The entity type to retrieve module for.
870
- * @param type - The entity type identifier.
871
- * @returns The systems module for that entity type.
872
- */
873
- get<TEntity extends IEntity>(type: EntityTypeUid): ISystemsModule<TEntity>;
874
- /**
875
- * Registers or updates a module for an entity type.
876
- * @param type - The entity type identifier.
877
- * @param module - The systems module to register.
878
- */
879
- set(type: EntityTypeUid, module: ISystemsModule<IEntity>): void;
880
- /**
881
- * Retrieves all registered modules.
882
- * @returns A read-only map of entity type to module.
883
- */
884
- list(): ReadonlyMap<EntityTypeUid, Immutable<ISystemsModule<IEntity>>>;
885
- }
886
- //#endregion
887
- //#region src/systems/runtime/systems-runtime.d.ts
888
- /**
889
- * Executes system middleware for entities.
890
- * Processes entity updates by dispatching them through appropriate system modules.
891
- * Different implementations may use different execution strategies or optimizations.
892
- */
893
- interface ISystemsRuntime {
894
- /**
895
- * Processes a single entity update through its system pipeline.
896
- * If no update is provided, may dequeue one from an internal queue.
897
- * @param update - Optional specific update to process. If omitted, dequeues the next update.
898
- * @returns Pipeline results containing execution data and metrics.
899
- */
900
- runTick(update?: IEntityUpdate): PipelineRuntime | Promise<PipelineRuntime> | void;
901
- }
902
- //#endregion
903
- //#region src/systems/runtime/systems-runtime-context.d.ts
904
- /**
905
- * Runtime context for system pipeline execution.
906
- * Coordinates the execution of system pipelines across all entities.
907
- * Maintains state about the current entity being processed and enabled pipeline stages.
908
- *
909
- * @template TEntity - The entity type being processed.
910
- */
911
- interface ISystemsRuntimeContext<TEntity extends IEntity> extends IPipelineContext {
912
- /**
913
- * Indicates if the system pipeline should perform initialization for the current entity.
914
- */
915
- readonly shouldInitialize?: boolean;
916
- /**
917
- * Indicates if the config system phase should run for the current entity.
918
- */
919
- readonly shouldConfigure?: boolean;
920
- /**
921
- * The systems module for the current entity type.
922
- */
923
- readonly systemsModule: ISystemsModule<TEntity>;
924
- /**
925
- * The mutable system context for the current entity execution.
926
- * Provides infrastructure setters for update, delta time, and runtime state.
927
- */
928
- readonly systemContext: IMutableSystemContext<TEntity>;
929
- /**
930
- * The proxy repository for managing entity proxy relationships and scopes.
931
- */
932
- readonly proxyRepository: IEntityProxyRepository;
933
- }
934
- //#endregion
935
- //#region src/systems/runtime/systems-runtime-middleware.d.ts
936
- /**
937
- * Middleware for orchestrating system execution across entities.
938
- * Operates at the runtime level to coordinate system module pipelines.
939
- * Can influence which pipelines execute and in what order.
940
- *
941
- * @template TEntity - The entity type being processed.
942
- */
943
- type ISystemsRuntimeMiddleware<TEntity extends IEntity> = IMiddleware<ISystemsRuntimeContext<TEntity>>;
944
- //#endregion
945
- //#region src/factories/runtime-factory.d.ts
946
- /**
947
- * Creates runtime contexts and pipelines for system execution.
948
- * Provides factory methods for constructing runtime infrastructure.
949
- * Allows different runtime strategies through multiple implementations.
950
- */
951
- interface IRuntimeFactory {
952
- /**
953
- * Creates a new runtime context for system execution.
954
- * @template TEntity - The entity type for the runtime context.
955
- * @returns A new systems runtime context instance.
956
- */
957
- createRuntimeContext<TEntity extends IEntity>(): ISystemsRuntimeContext<TEntity>;
958
- /**
959
- * Creates a pipeline for systems runtime orchestration.
960
- * @template TEntity - The entity type for this runtime pipeline.
961
- * @param name - Optional name for debugging.
962
- * @returns A new runtime pipeline for system execution.
963
- */
964
- createRuntimePipeline<TEntity extends IEntity>(name?: string): IPipeline<ISystemsRuntimeContext<TEntity>>;
965
- }
966
- //#endregion
967
817
  //#region src/factories/systems-factory.d.ts
968
818
  /**
969
819
  * Creates systems module builders for constructing entity system pipelines.
@@ -980,5 +830,5 @@ interface ISystemsFactory {
980
830
  createSystemsModuleBuilder<TEntity extends IEntity>(name: string): ISystemsModuleBuilder<TEntity>;
981
831
  }
982
832
  //#endregion
983
- export { ISystemContextRepository as A, SystemModuleName as B, TickSnapshot as C, ISystemContextSnapshot as D, ISystemContext as E, SystemContextControlState as F, LogLevel as G, ISystemContextConfigReadonly as H, ISystemMiddleware as I, MiddlewareRegistry as L, ISystemContextEvents as M, ISystemContextControl as N, IJsonSerializer as O, ISystemContextControlState as P, MiddlewareRegistryReadonly as R, TickMetricEntry as S, IMutableSystemContext as T, ILogger as U, ISystemContextConfig as V, ILoggerOptions as W, PerformanceMetricOptions as _, ISystemsRuntime as a, MiddlewareMetricsSummary as b, ISystemsModuleBuilder as c, IPipelineFactory as d, PipelineCategory as f, IPerformanceTimer as g, IContextFactory as h, ISystemsRuntimeContext as i, ISystemContextProxies as j, ISystemContextScheduler as k, ISystemsModuleBuilderReadonly as l, PipelineOptions as m, IRuntimeFactory as n, ISystemsModuleRepository as o, PipelineCategoryName as p, ISystemsRuntimeMiddleware as r, ISystemsModule as s, ISystemsFactory as t, SystemType as u, PerformanceTimeEntry as v, dispatchSequential as w, RenderSnapshot as x, PerformanceTimerUid as y, SystemMiddlewareName as z };
984
- //# sourceMappingURL=index-BD7sDB60.d.mts.map
833
+ export { ISystemContextConfigReadonly as A, ILoggerOptions as B, ISystemEventMiddleware as C, SystemMiddlewareName as D, MiddlewareRegistryReadonly as E, MiddlewareMetricsSummary as F, IJsonSerializer as H, RenderSnapshot as I, TickMetricEntry as L, PerformanceMetricOptions as M, PerformanceTimeEntry as N, SystemModuleName as O, PerformanceTimerUid as P, TickSnapshot as R, SystemContextControlTarget as S, MiddlewareRegistry as T, dispatchSequential as U, LogLevel as V, IMutableSystemContextEvents as _, SystemType as a, ISystemContextControlState as b, PipelineCategoryName as c, IMutableSystemContext as d, ISystemContext as f, ISystemContextProxies as g, ISystemContextRepository as h, ISystemsModule as i, IPerformanceTimer as j, ISystemContextConfig as k, PipelineOptions as l, ISystemContextScheduler as m, ISystemsModuleBuilder as n, IPipelineFactory as o, ISystemContextSnapshot as p, ISystemsModuleBuilderReadonly as r, PipelineCategory as s, ISystemsFactory as t, IContextFactory as u, ISystemContextEvents as v, ISystemMiddleware as w, SystemContextControlState as x, ISystemContextControl as y, ILogger as z };
834
+ //# sourceMappingURL=index-BivyWazf.d.cts.map