@awesome-ecs/abstract 0.33.0 → 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 (36) hide show
  1. package/README.md +119 -124
  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 +4 -0
  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 +4 -1
  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 +1 -1
  14. package/dist/factories/index.d.mts +1 -1
  15. package/dist/factories/index.mjs.map +1 -1
  16. package/dist/{index-DXbpfhHa.d.mts → index-B3DqdxE6.d.mts} +2 -2
  17. package/dist/{index--9JJtMKF.d.mts → index-BanhgPCc.d.mts} +34 -22
  18. package/dist/{index-CPGVaS-_.d.cts → index-BivyWazf.d.cts} +183 -172
  19. package/dist/{index-0hg5PXZe.d.cts → index-CSaKdQe-.d.cts} +34 -22
  20. package/dist/{index-BOS-47DQ.d.mts → index-DGyDijY7.d.mts} +183 -172
  21. package/dist/{index-HeCQLTSE.d.cts → index-DMZSrHoB.d.cts} +134 -101
  22. package/dist/{index-Tznk33g6.d.mts → index-Dbwzlrgp.d.mts} +134 -101
  23. package/dist/{index-Bl7Cf9gi.d.cts → index-aVjnG975.d.cts} +2 -2
  24. package/dist/pipelines/index.d.cts +1 -1
  25. package/dist/pipelines/index.d.mts +1 -1
  26. package/dist/systems/index.cjs.map +1 -1
  27. package/dist/systems/index.d.cts +11 -5
  28. package/dist/systems/index.d.mts +11 -5
  29. package/dist/systems/index.mjs.map +1 -1
  30. package/dist/{types-COxeVghs.d.cts → types-BaCGIrym.d.cts} +1 -1
  31. package/dist/{types-UnqKSA14.d.mts → types-BaCGIrym.d.mts} +1 -1
  32. package/dist/utils/index.cjs.map +1 -1
  33. package/dist/utils/index.d.cts +2 -2
  34. package/dist/utils/index.d.mts +2 -2
  35. package/dist/utils/index.mjs.map +1 -1
  36. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- import { r as Immutable } from "./types-COxeVghs.cjs";
1
+ import { r as Immutable } from "./types-BaCGIrym.cjs";
2
2
 
3
3
  //#region src/components/config.d.ts
4
4
  /**
@@ -120,6 +120,117 @@ interface IComponentWithConfig<TConfig extends ConfigRecord> extends IComponent
120
120
  readonly config: TConfig;
121
121
  }
122
122
  //#endregion
123
+ //#region src/components/identity-component.d.ts
124
+ /**
125
+ * The `BasicComponentType` enum defines the types of basic components available.
126
+ */
127
+ declare enum BasicComponentType {
128
+ identity = "identity"
129
+ }
130
+ /**
131
+ * The mandatory metadata component for every entity.
132
+ * Contains core information that defines what an entity is and when it was last updated.
133
+ * This component is immutable after creation and uniquely identifies each entity.
134
+ *
135
+ * @template TModel - The entity model type containing initialization data.
136
+ */
137
+ interface IdentityComponent<TModel extends IEntityModel> extends IComponent {
138
+ /**
139
+ * The entity type classification.
140
+ * Categorizes entities into logical types, allowing systems to selectively operate on specific entity categories.
141
+ */
142
+ readonly entityType: EntityTypeUid;
143
+ /**
144
+ * The initialization model for this entity.
145
+ * Provides the minimal data structure used when the entity was first created.
146
+ * Serves as a reference point for the entity's initial configuration.
147
+ *
148
+ * @type {Immutable<TModel>}
149
+ */
150
+ readonly model: Immutable<TModel>;
151
+ /**
152
+ * The proxy for this entity, derived from `entityType` and `model.uid`.
153
+ */
154
+ readonly proxy: IEntityProxy;
155
+ /**
156
+ * The timestamp of the entity's last system update.
157
+ * Useful for calculating elapsed time (delta time) between consecutive updates.
158
+ * Helps systems make time-aware decisions.
159
+ *
160
+ * @type {Date | undefined}
161
+ */
162
+ readonly lastUpdated?: Date;
163
+ }
164
+ //#endregion
165
+ //#region src/entities/entity.d.ts
166
+ /**
167
+ * Represents the unique identifier for an entity type.
168
+ * Can be either a string or a number.
169
+ */
170
+ type EntityTypeUid = string | number;
171
+ /**
172
+ * Represents the unique identifier for an entity.
173
+ * Can be either a string or a number.
174
+ */
175
+ type EntityUid = string | number;
176
+ /**
177
+ * Represents the core identification and initialization data for an entity.
178
+ * @template TProxyTypes - A readonly array of entity type IDs that must be provided as proxies when creating an entity.
179
+ * Use `[]` for concrete models without creation-time proxies.
180
+ * Omit the generic only for broad infrastructure APIs that accept any model.
181
+ */
182
+ type IEntityModel<TProxyTypes extends readonly EntityTypeUid[] | void = void> = {
183
+ /**
184
+ * The unique identifier for this entity instance.
185
+ */
186
+ readonly uid: EntityUid;
187
+ /**
188
+ * The scope this entity belongs to.
189
+ * Automatically set by the framework — scopeRoot entities generate a UUID,
190
+ * child entities inherit from their parent via addEntity().
191
+ */
192
+ readonly scopeId?: string;
193
+ } & ([TProxyTypes] extends [void] ? {
194
+ readonly proxies?: Readonly<Record<EntityTypeUid, IEntityProxy>>;
195
+ } : TProxyTypes extends readonly [] ? {
196
+ readonly proxies?: Readonly<Record<EntityTypeUid, never>>;
197
+ } : TProxyTypes extends readonly EntityTypeUid[] ? {
198
+ readonly proxies: RequiredProxies<TProxyTypes>;
199
+ } : never);
200
+ declare const EntityModelType: unique symbol;
201
+ interface IEntityModelRef<TModel extends IEntityModel> {
202
+ readonly [EntityModelType]?: TModel;
203
+ }
204
+ /**
205
+ * Extract the model type carried by an entity's identity component.
206
+ */
207
+ type ModelOf<TEntity> = TEntity extends IEntityModelRef<infer TModel> ? TModel : IEntityModel;
208
+ /**
209
+ * Base entity contract.
210
+ *
211
+ * Concrete entity types extend this interface and declare their own component and proxy
212
+ * members directly, for example `readonly terrain: TerrainComponent` or
213
+ * `readonly gridProxy: EntityProxy<GridEntity>`.
214
+ */
215
+ interface IEntity {
216
+ /**
217
+ * The identity component containing core entity metadata and initialization information.
218
+ * Every entity has exactly one identity component that persists for the entity's lifetime.
219
+ */
220
+ readonly identity: Readonly<IdentityComponent<ModelOf<this>>>;
221
+ }
222
+ /**
223
+ * Entity contract carrying the concrete model type for `ModelOf<TEntity>` inference.
224
+ */
225
+ interface IEntityWith<TModel extends IEntityModel> extends IEntity, IEntityModelRef<TModel> {}
226
+ /**
227
+ * Runtime entity spec consumed by dispatchers.
228
+ */
229
+ type IEntitySpec<TEntity extends IEntity> = {
230
+ readonly type: EntityTypeUid;
231
+ readonly init: (model: ModelOf<TEntity>) => TEntity;
232
+ };
233
+ //#endregion
123
234
  //#region src/entities/entity-proxies.d.ts
124
235
  /**
125
236
  * Represents a reference (pointer) to another entity.
@@ -139,11 +250,13 @@ interface IEntityProxy {
139
250
  }
140
251
  /**
141
252
  * A typed variant of `IEntityProxy` that carries compile-time type information.
142
- * This allows IDEs to provide better type inference and type-checking when working with entity relationships.
253
+ * This allows IDEs to infer the entity type when resolving a proxy through a repository.
143
254
  *
144
255
  * @template TEntity - The specific entity type that this proxy references.
145
256
  */
146
257
  interface EntityProxy<TEntity extends IEntity> extends IEntityProxy {}
258
+ type EntityProxyLookup<TEntity extends IEntity = IEntity> = EntityTypeUid | EntityProxy<TEntity>;
259
+ type EntityProxyManyLookup<TEntity extends IEntity = IEntity> = EntityProxyLookup<TEntity>;
147
260
  /**
148
261
  * A helper type to create a typed entity proxy.
149
262
  */
@@ -152,9 +265,9 @@ type TypedEntityProxy<T extends EntityTypeUid> = {
152
265
  entityUid: EntityUid;
153
266
  };
154
267
  /**
155
- * A mapped type that transforms an array of EntityType into an array of TypedEntityProxy.
268
+ * A model-level record of required entity proxies, keyed by entity type.
156
269
  */
157
- type RequiredProxies<TProxyTypes extends readonly EntityTypeUid[]> = [...{ [I in keyof TProxyTypes]: TypedEntityProxy<TProxyTypes[I]> }, ...IEntityProxy[]];
270
+ type RequiredProxies<TProxyTypes extends readonly EntityTypeUid[]> = { readonly [TType in TProxyTypes[number]]: TypedEntityProxy<TType> };
158
271
  /**
159
272
  * Extracts the union of EntityTypeUid values declared as required proxies on an entity model.
160
273
  * Resolves to `never` if the model declares no required proxies, which makes proxy lookups
@@ -162,7 +275,7 @@ type RequiredProxies<TProxyTypes extends readonly EntityTypeUid[]> = [...{ [I in
162
275
  *
163
276
  * @template TModel - The entity model to inspect.
164
277
  */
165
- type ProxyTypesOf<TModel> = TModel extends IEntityModel<infer P> ? P[number] : never;
278
+ type ProxyTypesOf<TModel> = TModel extends IEntityModel<infer P> ? P extends readonly EntityTypeUid[] ? P[number] : never : never;
166
279
  /**
167
280
  * Central registry for managing entity-to-entity relationships through proxies.
168
281
  * Maintains bidirectional proxy links, ensuring consistency across all entity references.
@@ -204,20 +317,20 @@ interface IEntityProxyRepository {
204
317
  * @param targetType - The entity type of the target proxy to retrieve.
205
318
  * @returns The entity proxy, or null if not found.
206
319
  */
207
- get(source: IEntityProxy, targetType: EntityTypeUid): IEntityProxy | null;
320
+ getProxy<TEntity extends IEntity = IEntity>(source: IEntityProxy, targetType: EntityTypeUid): EntityProxy<TEntity> | null;
208
321
  /**
209
322
  * Retrieves all proxies of a specific type for a source entity.
210
323
  * @param source - The proxy of the source entity.
211
324
  * @param targetType - The entity type of the target proxies to retrieve.
212
325
  * @returns A readonly array of entity proxies.
213
326
  */
214
- getMany(source: IEntityProxy, targetType: EntityTypeUid): Readonly<IEntityProxy[]>;
327
+ getProxies<TEntity extends IEntity = IEntity>(source: IEntityProxy, targetType: EntityTypeUid): Readonly<EntityProxy<TEntity>[]>;
215
328
  /**
216
329
  * Retrieves all proxies for a source entity.
217
330
  * @param source - The proxy of the source entity.
218
331
  * @returns A readonly map of entity type UIDs to an array of their proxies.
219
332
  */
220
- getAll(source: IEntityProxy): ReadonlyMap<EntityTypeUid, Readonly<IEntityProxy[]>>;
333
+ getAllProxies(source: IEntityProxy): ReadonlyMap<EntityTypeUid, Readonly<IEntityProxy[]>>;
221
334
  /**
222
335
  * Registers an entity as a scoped proxy, making it resolvable by any entity in the same scope.
223
336
  * Only entity types marked as scopeRoot or scopedProxy should be registered.
@@ -231,7 +344,7 @@ interface IEntityProxyRepository {
231
344
  * @param entityType - The entity type to resolve.
232
345
  * @returns The scoped proxy, or null if none exists.
233
346
  */
234
- getScopedProxy(scopeId: string, entityType: EntityTypeUid): IEntityProxy | null;
347
+ getScopedProxy<TEntity extends IEntity = IEntity>(scopeId: string, entityType: EntityTypeUid): EntityProxy<TEntity> | null;
235
348
  /**
236
349
  * Removes an entity from the scoped proxy index.
237
350
  * Called during entity cleanup to unregister from scope resolution.
@@ -241,100 +354,20 @@ interface IEntityProxyRepository {
241
354
  removeScopedProxy(entity: IEntityProxy, scopeId: string): void;
242
355
  }
243
356
  //#endregion
244
- //#region src/entities/entity.d.ts
245
- /**
246
- * Represents the unique identifier for an entity type.
247
- * Can be either a string or a number.
248
- */
249
- type EntityTypeUid = string | number;
250
- /**
251
- * Represents the unique identifier for an entity.
252
- * Can be either a string or a number.
253
- */
254
- type EntityUid = string | number;
255
- /**
256
- * Represents the core identification and initialization data for an entity.
257
- * @template TProxyTypes - A readonly array of entity type IDs that must be provided as proxies when creating an entity.
258
- * When non-empty, the `proxies` property is required on the model.
259
- */
260
- type IEntityModel<TProxyTypes extends readonly EntityTypeUid[] = readonly []> = {
261
- /**
262
- * The unique identifier for this entity instance.
263
- */
264
- readonly uid: EntityUid;
265
- /**
266
- * The scope this entity belongs to.
267
- * Automatically set by the framework — scopeRoot entities generate a UUID,
268
- * child entities inherit from their parent via addEntity().
269
- */
270
- readonly scopeId?: string;
271
- } & (TProxyTypes extends readonly [] ? {
272
- readonly proxies?: RequiredProxies<TProxyTypes>;
273
- } : {
274
- readonly proxies: RequiredProxies<TProxyTypes>;
275
- });
276
- /**
277
- * The core entity interface representing a composition of components and relationships.
278
- * Entities are immutable containers that store data (components) and maintain relationships (proxies) to other entities.
279
- * State modifications occur exclusively through system operations, maintaining data integrity and enabling safe concurrent access.
280
- *
281
- * Implementations should provide strongly-typed accessors for components and proxies specific to their entity type,
282
- * enhancing IDE support and type safety without adding behavior beyond data access.
283
- */
284
- interface IEntity {
285
- /**
286
- * The set of components attached to this entity.
287
- * Components are the primary data storage mechanism, mapped by their unique type identifiers.
288
- */
289
- readonly components: ReadonlyMap<ComponentTypeUid, IComponent>;
290
- /**
291
- * The identity component containing core entity metadata and initialization information.
292
- * Every entity has exactly one identity component that persists for the entity's lifetime.
293
- */
294
- readonly identity: Readonly<IdentityComponent<IEntityModel>>;
295
- /**
296
- * A reference to this entity's own proxy.
297
- */
298
- readonly myProxy: Readonly<EntityProxy<this>>;
299
- }
300
- //#endregion
301
- //#region src/components/identity-component.d.ts
302
- /**
303
- * The `BasicComponentType` enum defines the types of basic components available.
304
- */
305
- declare enum BasicComponentType {
306
- identity = "identity"
307
- }
357
+ //#region src/components/component-repository.d.ts
308
358
  /**
309
- * The mandatory metadata component for every entity.
310
- * Contains core information that defines what an entity is and when it was last updated.
311
- * This component is immutable after creation and uniquely identifies each entity.
359
+ * The runtime source of truth for component instances, keyed by entity proxy.
312
360
  *
313
- * @template TModel - The entity model type containing initialization data.
361
+ * Generic `get<TComponent>` lets callsites narrow on demand without any global
362
+ * `ComponentTypeMap` augmentation. Most reads go through typed component fields on
363
+ * `context.entity`; direct `repository.get` is the escape hatch.
314
364
  */
315
- interface IdentityComponent<TModel extends IEntityModel> extends IComponent {
316
- /**
317
- * The entity type classification.
318
- * Categorizes entities into logical types, allowing systems to selectively operate on specific entity categories.
319
- */
320
- readonly entityType: EntityTypeUid;
321
- /**
322
- * The initialization model for this entity.
323
- * Provides the minimal data structure used when the entity was first created.
324
- * Serves as a reference point for the entity's initial configuration.
325
- *
326
- * @type {Immutable<TModel>}
327
- */
328
- readonly model: Immutable<TModel>;
329
- /**
330
- * The timestamp of the entity's last system update.
331
- * Useful for calculating elapsed time (delta time) between consecutive updates.
332
- * Helps systems make time-aware decisions.
333
- *
334
- * @type {Date | undefined}
335
- */
336
- readonly lastUpdated?: Date;
365
+ interface IComponentRepository {
366
+ setMany(key: IEntityProxy, components: readonly IComponent[]): void;
367
+ get<TComponent extends IComponent = IComponent>(key: IEntityProxy, type: ComponentTypeUid): TComponent | undefined;
368
+ getAll(key: IEntityProxy): readonly IComponent[];
369
+ removeAll(key: IEntityProxy): void;
337
370
  }
338
371
  //#endregion
339
- export { ConfigOption as _, IEntity as a, IEntityProxy as c, RequiredProxies as d, TypedEntityProxy as f, ConfigCustomControlOptions as g, IComponentWithConfig as h, EntityUid as i, IEntityProxyRepository as l, IComponent as m, IdentityComponent as n, IEntityModel as o, ComponentTypeUid as p, EntityTypeUid as r, EntityProxy as s, BasicComponentType as t, ProxyTypesOf as u, ConfigRecord as v };
340
- //# sourceMappingURL=index-HeCQLTSE.d.cts.map
372
+ export { ConfigCustomControlOptions as C, IComponentWithConfig as S, ConfigRecord as T, ModelOf as _, IEntityProxy as a, ComponentTypeUid as b, RequiredProxies as c, EntityUid as d, IEntity as f, IEntityWith as g, IEntitySpec as h, EntityProxyManyLookup as i, TypedEntityProxy as l, IEntityModelRef as m, EntityProxy as n, IEntityProxyRepository as o, IEntityModel as p, EntityProxyLookup as r, ProxyTypesOf as s, IComponentRepository as t, EntityTypeUid as u, BasicComponentType as v, ConfigOption as w, IComponent as x, IdentityComponent as y };
373
+ //# sourceMappingURL=index-DMZSrHoB.d.cts.map
@@ -1,4 +1,4 @@
1
- import { r as Immutable } from "./types-UnqKSA14.mjs";
1
+ import { r as Immutable } from "./types-BaCGIrym.mjs";
2
2
 
3
3
  //#region src/components/config.d.ts
4
4
  /**
@@ -120,6 +120,117 @@ interface IComponentWithConfig<TConfig extends ConfigRecord> extends IComponent
120
120
  readonly config: TConfig;
121
121
  }
122
122
  //#endregion
123
+ //#region src/components/identity-component.d.ts
124
+ /**
125
+ * The `BasicComponentType` enum defines the types of basic components available.
126
+ */
127
+ declare enum BasicComponentType {
128
+ identity = "identity"
129
+ }
130
+ /**
131
+ * The mandatory metadata component for every entity.
132
+ * Contains core information that defines what an entity is and when it was last updated.
133
+ * This component is immutable after creation and uniquely identifies each entity.
134
+ *
135
+ * @template TModel - The entity model type containing initialization data.
136
+ */
137
+ interface IdentityComponent<TModel extends IEntityModel> extends IComponent {
138
+ /**
139
+ * The entity type classification.
140
+ * Categorizes entities into logical types, allowing systems to selectively operate on specific entity categories.
141
+ */
142
+ readonly entityType: EntityTypeUid;
143
+ /**
144
+ * The initialization model for this entity.
145
+ * Provides the minimal data structure used when the entity was first created.
146
+ * Serves as a reference point for the entity's initial configuration.
147
+ *
148
+ * @type {Immutable<TModel>}
149
+ */
150
+ readonly model: Immutable<TModel>;
151
+ /**
152
+ * The proxy for this entity, derived from `entityType` and `model.uid`.
153
+ */
154
+ readonly proxy: IEntityProxy;
155
+ /**
156
+ * The timestamp of the entity's last system update.
157
+ * Useful for calculating elapsed time (delta time) between consecutive updates.
158
+ * Helps systems make time-aware decisions.
159
+ *
160
+ * @type {Date | undefined}
161
+ */
162
+ readonly lastUpdated?: Date;
163
+ }
164
+ //#endregion
165
+ //#region src/entities/entity.d.ts
166
+ /**
167
+ * Represents the unique identifier for an entity type.
168
+ * Can be either a string or a number.
169
+ */
170
+ type EntityTypeUid = string | number;
171
+ /**
172
+ * Represents the unique identifier for an entity.
173
+ * Can be either a string or a number.
174
+ */
175
+ type EntityUid = string | number;
176
+ /**
177
+ * Represents the core identification and initialization data for an entity.
178
+ * @template TProxyTypes - A readonly array of entity type IDs that must be provided as proxies when creating an entity.
179
+ * Use `[]` for concrete models without creation-time proxies.
180
+ * Omit the generic only for broad infrastructure APIs that accept any model.
181
+ */
182
+ type IEntityModel<TProxyTypes extends readonly EntityTypeUid[] | void = void> = {
183
+ /**
184
+ * The unique identifier for this entity instance.
185
+ */
186
+ readonly uid: EntityUid;
187
+ /**
188
+ * The scope this entity belongs to.
189
+ * Automatically set by the framework — scopeRoot entities generate a UUID,
190
+ * child entities inherit from their parent via addEntity().
191
+ */
192
+ readonly scopeId?: string;
193
+ } & ([TProxyTypes] extends [void] ? {
194
+ readonly proxies?: Readonly<Record<EntityTypeUid, IEntityProxy>>;
195
+ } : TProxyTypes extends readonly [] ? {
196
+ readonly proxies?: Readonly<Record<EntityTypeUid, never>>;
197
+ } : TProxyTypes extends readonly EntityTypeUid[] ? {
198
+ readonly proxies: RequiredProxies<TProxyTypes>;
199
+ } : never);
200
+ declare const EntityModelType: unique symbol;
201
+ interface IEntityModelRef<TModel extends IEntityModel> {
202
+ readonly [EntityModelType]?: TModel;
203
+ }
204
+ /**
205
+ * Extract the model type carried by an entity's identity component.
206
+ */
207
+ type ModelOf<TEntity> = TEntity extends IEntityModelRef<infer TModel> ? TModel : IEntityModel;
208
+ /**
209
+ * Base entity contract.
210
+ *
211
+ * Concrete entity types extend this interface and declare their own component and proxy
212
+ * members directly, for example `readonly terrain: TerrainComponent` or
213
+ * `readonly gridProxy: EntityProxy<GridEntity>`.
214
+ */
215
+ interface IEntity {
216
+ /**
217
+ * The identity component containing core entity metadata and initialization information.
218
+ * Every entity has exactly one identity component that persists for the entity's lifetime.
219
+ */
220
+ readonly identity: Readonly<IdentityComponent<ModelOf<this>>>;
221
+ }
222
+ /**
223
+ * Entity contract carrying the concrete model type for `ModelOf<TEntity>` inference.
224
+ */
225
+ interface IEntityWith<TModel extends IEntityModel> extends IEntity, IEntityModelRef<TModel> {}
226
+ /**
227
+ * Runtime entity spec consumed by dispatchers.
228
+ */
229
+ type IEntitySpec<TEntity extends IEntity> = {
230
+ readonly type: EntityTypeUid;
231
+ readonly init: (model: ModelOf<TEntity>) => TEntity;
232
+ };
233
+ //#endregion
123
234
  //#region src/entities/entity-proxies.d.ts
124
235
  /**
125
236
  * Represents a reference (pointer) to another entity.
@@ -139,11 +250,13 @@ interface IEntityProxy {
139
250
  }
140
251
  /**
141
252
  * A typed variant of `IEntityProxy` that carries compile-time type information.
142
- * This allows IDEs to provide better type inference and type-checking when working with entity relationships.
253
+ * This allows IDEs to infer the entity type when resolving a proxy through a repository.
143
254
  *
144
255
  * @template TEntity - The specific entity type that this proxy references.
145
256
  */
146
257
  interface EntityProxy<TEntity extends IEntity> extends IEntityProxy {}
258
+ type EntityProxyLookup<TEntity extends IEntity = IEntity> = EntityTypeUid | EntityProxy<TEntity>;
259
+ type EntityProxyManyLookup<TEntity extends IEntity = IEntity> = EntityProxyLookup<TEntity>;
147
260
  /**
148
261
  * A helper type to create a typed entity proxy.
149
262
  */
@@ -152,9 +265,9 @@ type TypedEntityProxy<T extends EntityTypeUid> = {
152
265
  entityUid: EntityUid;
153
266
  };
154
267
  /**
155
- * A mapped type that transforms an array of EntityType into an array of TypedEntityProxy.
268
+ * A model-level record of required entity proxies, keyed by entity type.
156
269
  */
157
- type RequiredProxies<TProxyTypes extends readonly EntityTypeUid[]> = [...{ [I in keyof TProxyTypes]: TypedEntityProxy<TProxyTypes[I]> }, ...IEntityProxy[]];
270
+ type RequiredProxies<TProxyTypes extends readonly EntityTypeUid[]> = { readonly [TType in TProxyTypes[number]]: TypedEntityProxy<TType> };
158
271
  /**
159
272
  * Extracts the union of EntityTypeUid values declared as required proxies on an entity model.
160
273
  * Resolves to `never` if the model declares no required proxies, which makes proxy lookups
@@ -162,7 +275,7 @@ type RequiredProxies<TProxyTypes extends readonly EntityTypeUid[]> = [...{ [I in
162
275
  *
163
276
  * @template TModel - The entity model to inspect.
164
277
  */
165
- type ProxyTypesOf<TModel> = TModel extends IEntityModel<infer P> ? P[number] : never;
278
+ type ProxyTypesOf<TModel> = TModel extends IEntityModel<infer P> ? P extends readonly EntityTypeUid[] ? P[number] : never : never;
166
279
  /**
167
280
  * Central registry for managing entity-to-entity relationships through proxies.
168
281
  * Maintains bidirectional proxy links, ensuring consistency across all entity references.
@@ -204,20 +317,20 @@ interface IEntityProxyRepository {
204
317
  * @param targetType - The entity type of the target proxy to retrieve.
205
318
  * @returns The entity proxy, or null if not found.
206
319
  */
207
- get(source: IEntityProxy, targetType: EntityTypeUid): IEntityProxy | null;
320
+ getProxy<TEntity extends IEntity = IEntity>(source: IEntityProxy, targetType: EntityTypeUid): EntityProxy<TEntity> | null;
208
321
  /**
209
322
  * Retrieves all proxies of a specific type for a source entity.
210
323
  * @param source - The proxy of the source entity.
211
324
  * @param targetType - The entity type of the target proxies to retrieve.
212
325
  * @returns A readonly array of entity proxies.
213
326
  */
214
- getMany(source: IEntityProxy, targetType: EntityTypeUid): Readonly<IEntityProxy[]>;
327
+ getProxies<TEntity extends IEntity = IEntity>(source: IEntityProxy, targetType: EntityTypeUid): Readonly<EntityProxy<TEntity>[]>;
215
328
  /**
216
329
  * Retrieves all proxies for a source entity.
217
330
  * @param source - The proxy of the source entity.
218
331
  * @returns A readonly map of entity type UIDs to an array of their proxies.
219
332
  */
220
- getAll(source: IEntityProxy): ReadonlyMap<EntityTypeUid, Readonly<IEntityProxy[]>>;
333
+ getAllProxies(source: IEntityProxy): ReadonlyMap<EntityTypeUid, Readonly<IEntityProxy[]>>;
221
334
  /**
222
335
  * Registers an entity as a scoped proxy, making it resolvable by any entity in the same scope.
223
336
  * Only entity types marked as scopeRoot or scopedProxy should be registered.
@@ -231,7 +344,7 @@ interface IEntityProxyRepository {
231
344
  * @param entityType - The entity type to resolve.
232
345
  * @returns The scoped proxy, or null if none exists.
233
346
  */
234
- getScopedProxy(scopeId: string, entityType: EntityTypeUid): IEntityProxy | null;
347
+ getScopedProxy<TEntity extends IEntity = IEntity>(scopeId: string, entityType: EntityTypeUid): EntityProxy<TEntity> | null;
235
348
  /**
236
349
  * Removes an entity from the scoped proxy index.
237
350
  * Called during entity cleanup to unregister from scope resolution.
@@ -241,100 +354,20 @@ interface IEntityProxyRepository {
241
354
  removeScopedProxy(entity: IEntityProxy, scopeId: string): void;
242
355
  }
243
356
  //#endregion
244
- //#region src/entities/entity.d.ts
245
- /**
246
- * Represents the unique identifier for an entity type.
247
- * Can be either a string or a number.
248
- */
249
- type EntityTypeUid = string | number;
250
- /**
251
- * Represents the unique identifier for an entity.
252
- * Can be either a string or a number.
253
- */
254
- type EntityUid = string | number;
255
- /**
256
- * Represents the core identification and initialization data for an entity.
257
- * @template TProxyTypes - A readonly array of entity type IDs that must be provided as proxies when creating an entity.
258
- * When non-empty, the `proxies` property is required on the model.
259
- */
260
- type IEntityModel<TProxyTypes extends readonly EntityTypeUid[] = readonly []> = {
261
- /**
262
- * The unique identifier for this entity instance.
263
- */
264
- readonly uid: EntityUid;
265
- /**
266
- * The scope this entity belongs to.
267
- * Automatically set by the framework — scopeRoot entities generate a UUID,
268
- * child entities inherit from their parent via addEntity().
269
- */
270
- readonly scopeId?: string;
271
- } & (TProxyTypes extends readonly [] ? {
272
- readonly proxies?: RequiredProxies<TProxyTypes>;
273
- } : {
274
- readonly proxies: RequiredProxies<TProxyTypes>;
275
- });
276
- /**
277
- * The core entity interface representing a composition of components and relationships.
278
- * Entities are immutable containers that store data (components) and maintain relationships (proxies) to other entities.
279
- * State modifications occur exclusively through system operations, maintaining data integrity and enabling safe concurrent access.
280
- *
281
- * Implementations should provide strongly-typed accessors for components and proxies specific to their entity type,
282
- * enhancing IDE support and type safety without adding behavior beyond data access.
283
- */
284
- interface IEntity {
285
- /**
286
- * The set of components attached to this entity.
287
- * Components are the primary data storage mechanism, mapped by their unique type identifiers.
288
- */
289
- readonly components: ReadonlyMap<ComponentTypeUid, IComponent>;
290
- /**
291
- * The identity component containing core entity metadata and initialization information.
292
- * Every entity has exactly one identity component that persists for the entity's lifetime.
293
- */
294
- readonly identity: Readonly<IdentityComponent<IEntityModel>>;
295
- /**
296
- * A reference to this entity's own proxy.
297
- */
298
- readonly myProxy: Readonly<EntityProxy<this>>;
299
- }
300
- //#endregion
301
- //#region src/components/identity-component.d.ts
302
- /**
303
- * The `BasicComponentType` enum defines the types of basic components available.
304
- */
305
- declare enum BasicComponentType {
306
- identity = "identity"
307
- }
357
+ //#region src/components/component-repository.d.ts
308
358
  /**
309
- * The mandatory metadata component for every entity.
310
- * Contains core information that defines what an entity is and when it was last updated.
311
- * This component is immutable after creation and uniquely identifies each entity.
359
+ * The runtime source of truth for component instances, keyed by entity proxy.
312
360
  *
313
- * @template TModel - The entity model type containing initialization data.
361
+ * Generic `get<TComponent>` lets callsites narrow on demand without any global
362
+ * `ComponentTypeMap` augmentation. Most reads go through typed component fields on
363
+ * `context.entity`; direct `repository.get` is the escape hatch.
314
364
  */
315
- interface IdentityComponent<TModel extends IEntityModel> extends IComponent {
316
- /**
317
- * The entity type classification.
318
- * Categorizes entities into logical types, allowing systems to selectively operate on specific entity categories.
319
- */
320
- readonly entityType: EntityTypeUid;
321
- /**
322
- * The initialization model for this entity.
323
- * Provides the minimal data structure used when the entity was first created.
324
- * Serves as a reference point for the entity's initial configuration.
325
- *
326
- * @type {Immutable<TModel>}
327
- */
328
- readonly model: Immutable<TModel>;
329
- /**
330
- * The timestamp of the entity's last system update.
331
- * Useful for calculating elapsed time (delta time) between consecutive updates.
332
- * Helps systems make time-aware decisions.
333
- *
334
- * @type {Date | undefined}
335
- */
336
- readonly lastUpdated?: Date;
365
+ interface IComponentRepository {
366
+ setMany(key: IEntityProxy, components: readonly IComponent[]): void;
367
+ get<TComponent extends IComponent = IComponent>(key: IEntityProxy, type: ComponentTypeUid): TComponent | undefined;
368
+ getAll(key: IEntityProxy): readonly IComponent[];
369
+ removeAll(key: IEntityProxy): void;
337
370
  }
338
371
  //#endregion
339
- export { ConfigOption as _, IEntity as a, IEntityProxy as c, RequiredProxies as d, TypedEntityProxy as f, ConfigCustomControlOptions as g, IComponentWithConfig as h, EntityUid as i, IEntityProxyRepository as l, IComponent as m, IdentityComponent as n, IEntityModel as o, ComponentTypeUid as p, EntityTypeUid as r, EntityProxy as s, BasicComponentType as t, ProxyTypesOf as u, ConfigRecord as v };
340
- //# sourceMappingURL=index-Tznk33g6.d.mts.map
372
+ export { ConfigCustomControlOptions as C, IComponentWithConfig as S, ConfigRecord as T, ModelOf as _, IEntityProxy as a, ComponentTypeUid as b, RequiredProxies as c, EntityUid as d, IEntity as f, IEntityWith as g, IEntitySpec as h, EntityProxyManyLookup as i, TypedEntityProxy as l, IEntityModelRef as m, EntityProxy as n, IEntityProxyRepository as o, IEntityModel as p, EntityProxyLookup as r, ProxyTypesOf as s, IComponentRepository as t, EntityTypeUid as u, BasicComponentType as v, ConfigOption as w, IComponent as x, IdentityComponent as y };
373
+ //# sourceMappingURL=index-Dbwzlrgp.d.mts.map
@@ -1,4 +1,4 @@
1
- import { r as Immutable } from "./types-COxeVghs.cjs";
1
+ import { r as Immutable } from "./types-BaCGIrym.cjs";
2
2
 
3
3
  //#region src/pipelines/pipeline-context.d.ts
4
4
  /**
@@ -215,4 +215,4 @@ interface IPipelineRunner<TContext extends IPipelineContext> {
215
215
  }
216
216
  //#endregion
217
217
  export { IParentMiddleware as a, IMiddleware as c, IParentContext as i, IPipelineContext as l, INestedContext as n, IPipeline as o, INestedMiddleware as r, IMiddlewareRunner as s, IPipelineRunner as t, PipelineDispatch as u };
218
- //# sourceMappingURL=index-Bl7Cf9gi.d.cts.map
218
+ //# sourceMappingURL=index-aVjnG975.d.cts.map
@@ -1,2 +1,2 @@
1
- import { a as IParentMiddleware, c as IMiddleware, i as IParentContext, l as IPipelineContext, n as INestedContext, o as IPipeline, r as INestedMiddleware, s as IMiddlewareRunner, t as IPipelineRunner, u as PipelineDispatch } from "../index-Bl7Cf9gi.cjs";
1
+ import { a as IParentMiddleware, c as IMiddleware, i as IParentContext, l as IPipelineContext, n as INestedContext, o as IPipeline, r as INestedMiddleware, s as IMiddlewareRunner, t as IPipelineRunner, u as PipelineDispatch } from "../index-aVjnG975.cjs";
2
2
  export { IMiddleware, IMiddlewareRunner, INestedContext, INestedMiddleware, IParentContext, IParentMiddleware, IPipeline, IPipelineContext, IPipelineRunner, PipelineDispatch };
@@ -1,2 +1,2 @@
1
- import { a as IParentMiddleware, c as IMiddleware, i as IParentContext, l as IPipelineContext, n as INestedContext, o as IPipeline, r as INestedMiddleware, s as IMiddlewareRunner, t as IPipelineRunner, u as PipelineDispatch } from "../index-DXbpfhHa.mjs";
1
+ import { a as IParentMiddleware, c as IMiddleware, i as IParentContext, l as IPipelineContext, n as INestedContext, o as IPipeline, r as INestedMiddleware, s as IMiddlewareRunner, t as IPipelineRunner, u as PipelineDispatch } from "../index-B3DqdxE6.mjs";
2
2
  export { IMiddleware, IMiddlewareRunner, INestedContext, INestedMiddleware, IParentContext, IParentMiddleware, IPipeline, IPipelineContext, IPipelineRunner, PipelineDispatch };
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/systems/pipeline/system-context-control.ts","../../src/systems/system-type.ts"],"sourcesContent":["import type {\n EntityEventSubscriptionOptions,\n EntityEventUid\n} from '../../entities/entity-events';\nimport type { SystemModuleName } from './system-middleware';\n\nexport interface SystemContextControlTarget {\n readonly name?: string;\n}\n\nexport enum SystemContextControlState {\n none = 'none',\n enableCurrentSystem = 'enableCurrentSystem',\n disableCurrentSystem = 'disableCurrentSystem'\n}\n\n/**\n * Interface for controlling the execution of systems and modules within a system context.\n * This allows middleware to enable or disable specific systems or entire modules for the current entity.\n */\nexport interface ISystemContextControl {\n /**\n * Disables the current system for the current entity.\n */\n disableCurrentSystem(): void;\n\n /**\n * Re-enables the current system for the current entity.\n */\n enableCurrentSystem(): void;\n\n /**\n * Disables a module for the current entity.\n */\n disableModule(name: SystemModuleName): void;\n\n /**\n * Re-enables a module for the current entity.\n */\n enableModule(name: SystemModuleName): void;\n}\n\n/**\n * Extended system context interface that includes control state for middleware to manage system and module execution.\n * This allows middleware to query and modify the execution state of systems and modules during pipeline processing.\n */\nexport interface ISystemContextControlState extends ISystemContextControl {\n /**\n * Current state of system/module execution control, indicating whether the current system or module is enabled or disabled.\n */\n readonly state: SystemContextControlState;\n\n /**\n * Checks if a specific middleware is currently disabled in the context, allowing middleware to conditionally execute logic based on the enabled/disabled state of other middleware.\n * @param middleware - The middleware to check for disabled state.\n * @returns True if the specified middleware is currently disabled, false otherwise.\n */\n isMiddlewareDisabled(middleware: SystemContextControlTarget): boolean;\n\n /**\n * Disables a specific middleware in the context.\n * @param middleware - The middleware to disable.\n */\n disableMiddleware(middleware: SystemContextControlTarget): void;\n\n /**\n * Enables a specific middleware in the context.\n * @param middleware - The middleware to enable.\n */\n enableMiddleware(middleware: SystemContextControlTarget): void;\n\n /**\n * Registers an event subscription owned by a module. This is runtime-only state:\n * disabling the module should also detach its event subscriptions.\n */\n registerModuleEvent(\n moduleName: SystemModuleName,\n eventUid: EntityEventUid,\n options?: EntityEventSubscriptionOptions\n ): void;\n\n /**\n * Clears all runtime-owned module event subscriptions for the current entity.\n */\n clearModuleEvents(): void;\n}\n","/**\n * The five phases of entity system execution in each frame.\n * Each phase serves a specific purpose in the entity lifecycle and can be extended by custom system types.\n * The runtime handles each phase in order, allowing systems to perform stage-specific operations.\n */\nexport enum SystemType {\n /**\n * Initial setup and resource allocation for the entity.\n * Runs once when the entity is first created or initialized.\n */\n initialize = 0,\n\n /**\n * Config application and config-dependent resource reconciliation.\n * Runs on entity creation and on updates that carry a config payload.\n */\n config = 1,\n\n /**\n * Event reactions routed by event uid.\n * Runs after config and before update for updates carrying events.\n */\n event = 2,\n\n /**\n * Main logic and state updates for the entity.\n * Runs on every update to change entity behavior and properties.\n */\n update = 3,\n\n /**\n * Output and visualization operations.\n * Runs after updates to render or display the entity state.\n */\n render = 4,\n\n /**\n * Synchronization and persistence.\n * Runs last to synchronize state with external systems or storage.\n */\n sync = 5\n}\n"],"mappings":";;AAUA,IAAY,4BAAL,yBAAA,2BAAA;CACL,0BAAA,UAAA;CACA,0BAAA,yBAAA;CACA,0BAAA,0BAAA;;AACF,EAAA,CAAA,CAAA;;;;;;;;ACTA,IAAY,aAAL,yBAAA,YAAA;;;;;CAKL,WAAA,WAAA,gBAAA,KAAA;;;;;CAMA,WAAA,WAAA,YAAA,KAAA;;;;;CAMA,WAAA,WAAA,WAAA,KAAA;;;;;CAMA,WAAA,WAAA,YAAA,KAAA;;;;;CAMA,WAAA,WAAA,YAAA,KAAA;;;;;CAMA,WAAA,WAAA,UAAA,KAAA;;AACF,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/systems/pipeline/system-context-control.ts","../../src/systems/system-type.ts"],"sourcesContent":["import type {\r\n EntityEventSubscriptionOptions,\r\n EntityEventUid\r\n} from '../../entities/entity-events';\r\nimport type { SystemModuleName } from './system-middleware';\r\n\r\nexport interface SystemContextControlTarget {\r\n readonly name?: string;\r\n}\r\n\r\nexport enum SystemContextControlState {\r\n none = 'none',\r\n enableCurrentSystem = 'enableCurrentSystem',\r\n disableCurrentSystem = 'disableCurrentSystem'\r\n}\r\n\r\n/**\r\n * Interface for controlling the execution of systems and modules within a system context.\r\n * This allows middleware to enable or disable specific systems or entire modules for the current entity.\r\n */\r\nexport interface ISystemContextControl {\r\n /**\r\n * Disables the current system for the current entity.\r\n */\r\n disableCurrentSystem(): void;\r\n\r\n /**\r\n * Re-enables the current system for the current entity.\r\n */\r\n enableCurrentSystem(): void;\r\n\r\n /**\r\n * Disables a module for the current entity.\r\n */\r\n disableModule(name: SystemModuleName): void;\r\n\r\n /**\r\n * Re-enables a module for the current entity.\r\n */\r\n enableModule(name: SystemModuleName): void;\r\n}\r\n\r\n/**\r\n * Extended system context interface that includes control state for middleware to manage system and module execution.\r\n * This allows middleware to query and modify the execution state of systems and modules during pipeline processing.\r\n */\r\nexport interface ISystemContextControlState extends ISystemContextControl {\r\n /**\r\n * Current state of system/module execution control, indicating whether the current system or module is enabled or disabled.\r\n */\r\n readonly state: SystemContextControlState;\r\n\r\n /**\r\n * Checks if a specific middleware is currently disabled in the context, allowing middleware to conditionally execute logic based on the enabled/disabled state of other middleware.\r\n * @param middleware - The middleware to check for disabled state.\r\n * @returns True if the specified middleware is currently disabled, false otherwise.\r\n */\r\n isMiddlewareDisabled(middleware: SystemContextControlTarget): boolean;\r\n\r\n /**\r\n * Disables a specific middleware in the context.\r\n * @param middleware - The middleware to disable.\r\n */\r\n disableMiddleware(middleware: SystemContextControlTarget): void;\r\n\r\n /**\r\n * Enables a specific middleware in the context.\r\n * @param middleware - The middleware to enable.\r\n */\r\n enableMiddleware(middleware: SystemContextControlTarget): void;\r\n\r\n /**\r\n * Registers an event subscription owned by a module. This is runtime-only state:\r\n * disabling the module should also detach its event subscriptions.\r\n */\r\n registerModuleEvent(\r\n moduleName: SystemModuleName,\r\n eventUid: EntityEventUid,\r\n options?: EntityEventSubscriptionOptions\r\n ): void;\r\n\r\n /**\r\n * Clears all runtime-owned module event subscriptions for the current entity.\r\n */\r\n clearModuleEvents(): void;\r\n}\r\n","/**\n * The five phases of entity system execution in each frame.\n * Each phase serves a specific purpose in the entity lifecycle and can be extended by custom system types.\n * The runtime handles each phase in order, allowing systems to perform stage-specific operations.\n */\nexport enum SystemType {\n /**\n * Initial setup and resource allocation for the entity.\n * Runs once when the entity is first created or initialized.\n */\n initialize = 0,\n\n /**\n * Config application and config-dependent resource reconciliation.\n * Runs on entity creation and on updates that carry a config payload.\n */\n config = 1,\n\n /**\n * Event reactions routed by event uid.\n * Runs after config and before update for updates carrying events.\n */\n event = 2,\n\n /**\n * Main logic and state updates for the entity.\n * Runs on every update to change entity behavior and properties.\n */\n update = 3,\n\n /**\n * Output and visualization operations.\n * Runs after updates to render or display the entity state.\n */\n render = 4,\n\n /**\n * Synchronization and persistence.\n * Runs last to synchronize state with external systems or storage.\n */\n sync = 5\n}\n"],"mappings":";;AAUA,IAAY,4BAAL,yBAAA,2BAAA;CACL,0BAAA,UAAA;CACA,0BAAA,yBAAA;CACA,0BAAA,0BAAA;;AACF,EAAA,CAAA,CAAA;;;;;;;;ACTA,IAAY,aAAL,yBAAA,YAAA;;;;;CAKL,WAAA,WAAA,gBAAA,KAAA;;;;;CAMA,WAAA,WAAA,YAAA,KAAA;;;;;CAMA,WAAA,WAAA,WAAA,KAAA;;;;;CAMA,WAAA,WAAA,YAAA,KAAA;;;;;CAMA,WAAA,WAAA,YAAA,KAAA;;;;;CAMA,WAAA,WAAA,UAAA,KAAA;;AACF,EAAA,CAAA,CAAA"}