@latticexyz/recs 2.2.18-8d0ce55e964e646a1c804c401df01c4deb866f30 → 2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2

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.
@@ -0,0 +1,606 @@
1
+ import { S as Schema, M as Metadata, W as World, C as Component, E as Entity, a as ComponentValue, I as Indexer, O as OverridableComponent, b as EntitySymbol, Q as QueryFragment, c as ComponentUpdate, U as UpdateType, H as HasQueryFragment, N as NotQueryFragment, d as HasValueQueryFragment, e as NotValueQueryFragment, T as Type, P as ProxyReadQueryFragment, f as ProxyExpandQueryFragment } from './types-CAQycjNT.cjs';
2
+ export { i as AnyComponent, A as AnyComponentValue, r as ArrayType, h as ComponentWithStream, g as Components, k as EntityQueryFragment, v as EntityType, L as Layer, x as Layers, t as NumberType, p as OptionalType, y as OptionalTypes, o as Override, j as QueryFragmentType, m as QueryFragments, n as SchemaOf, l as SettingQueryFragment, V as ValueType, s as isArrayType, w as isEntityType, u as isNumberType, q as isOptionalType } from './types-CAQycjNT.cjs';
3
+ import * as rxjs from 'rxjs';
4
+ import { Observable } from 'rxjs';
5
+ import { ObservableSet } from 'mobx';
6
+ import 'type-fest';
7
+
8
+ type ComponentMutationOptions = {
9
+ /** Skip publishing this mutation to the component's update stream. Mostly used internally during initial hydration. */
10
+ skipUpdateStream?: boolean;
11
+ };
12
+ /**
13
+ * Components contain state indexed by entities and are one of the fundamental building blocks in ECS.
14
+ * Besides containing the state, components expose an rxjs update$ stream, that emits an event any time the value
15
+ * of an entity in this component is updated.
16
+ *
17
+ * @param world {@link World} object this component should be registered onto.
18
+ * @param schema {@link Schema} of component values. Uses Type enum as bridge between typescript types and javascript accessible values.
19
+ * @param options Optional: {
20
+ * id: descriptive id for this component (otherwise an autogenerated id is used),
21
+ * metadata: arbitrary metadata,
22
+ * indexed: if this flag is set, an indexer is applied to this component (see {@link createIndexer})
23
+ * }
24
+ * @returns Component object linked to the provided World
25
+ *
26
+ * @example
27
+ * ```
28
+ * const Position = defineComponent(world, { x: Type.Number, y: Type.Number }, { id: "Position" });
29
+ * ```
30
+ */
31
+ declare function defineComponent<S extends Schema, M extends Metadata, T = unknown>(world: World, schema: S, options?: {
32
+ id?: string;
33
+ metadata?: M;
34
+ indexed?: boolean;
35
+ }): Component<S, M, T>;
36
+ /**
37
+ * Set the value for a given entity in a given component.
38
+ *
39
+ * @param component {@link defineComponent Component} to be updated.
40
+ * @param entity {@link Entity} whose value in the given component should be set.
41
+ * @param value Value to set, schema must match the component schema.
42
+ *
43
+ * @example
44
+ * ```
45
+ * setComponent(Position, entity, { x: 1, y: 2 });
46
+ * ```
47
+ */
48
+ declare function setComponent<S extends Schema, T = unknown>(component: Component<S, Metadata, T>, entity: Entity, value: ComponentValue<S, T>, options?: ComponentMutationOptions): void;
49
+ /**
50
+ * Update the value for a given entity in a given component while keeping the old value of keys not included in the update.
51
+ *
52
+ * @param component {@link defineComponent Component} to be updated.
53
+ * @param entity {@link Entity} whose value in the given component should be updated.
54
+ * @param value Partial value to be set, remaining keys will be taken from the existing component value.
55
+ *
56
+ * @remarks
57
+ * This function fails silently during runtime if a partial value is set for an entity that
58
+ * does not have a component value yet, since then a partial value will be set in the component for this entity.
59
+ *
60
+ * @example
61
+ * ```
62
+ * updateComponent(Position, entity, { x: 1 });
63
+ * ```
64
+ */
65
+ declare function updateComponent<S extends Schema, T = unknown>(component: Component<S, Metadata, T>, entity: Entity, value: Partial<ComponentValue<S, T>>, initialValue?: ComponentValue<S, T>, options?: ComponentMutationOptions): void;
66
+ /**
67
+ * Remove a given entity from a given component.
68
+ *
69
+ * @param component {@link defineComponent Component} to be updated.
70
+ * @param entity {@link Entity} whose value should be removed from this component.
71
+ */
72
+ declare function removeComponent<S extends Schema, M extends Metadata, T = unknown>(component: Component<S, M, T>, entity: Entity, options?: ComponentMutationOptions): void;
73
+ /**
74
+ * Check whether a component contains a value for a given entity.
75
+ *
76
+ * @param component {@link defineComponent Component} to check whether it has a value for the given entity.
77
+ * @param entity {@link Entity} to check whether it has a value in the given component.
78
+ * @returns true if the component contains a value for the given entity, else false.
79
+ */
80
+ declare function hasComponent<S extends Schema, T = unknown>(component: Component<S, Metadata, T>, entity: Entity): boolean;
81
+ /**
82
+ * Get the value of a given entity in the given component.
83
+ * Returns undefined if no value or only a partial value is found.
84
+ *
85
+ * @param component {@link defineComponent Component} to get the value from for the given entity.
86
+ * @param entity {@link Entity} to get the value for from the given component.
87
+ * @returns Value of the given entity in the given component or undefined if no value exists.
88
+ */
89
+ declare function getComponentValue<S extends Schema, T = unknown>(component: Component<S, Metadata, T>, entity: Entity): ComponentValue<S, T> | undefined;
90
+ /**
91
+ * Get the value of a given entity in the given component.
92
+ * Throws an error if no value exists for the given entity in the given component.
93
+ *
94
+ * @param component {@link defineComponent Component} to get the value from for the given entity.
95
+ * @param entity {@link Entity} of the entity to get the value for from the given component.
96
+ * @returns Value of the given entity in the given component.
97
+ *
98
+ * @remarks
99
+ * Throws an error if no value exists in the component for the given entity.
100
+ */
101
+ declare function getComponentValueStrict<S extends Schema, T = unknown>(component: Component<S, Metadata, T>, entity: Entity): ComponentValue<S, T>;
102
+ /**
103
+ * Compare two {@link ComponentValue}s.
104
+ * `a` can be a partial component value, in which case only the keys present in `a` are compared to the corresponding keys in `b`.
105
+ *
106
+ * @param a Partial {@link ComponentValue} to compare to `b`
107
+ * @param b Component value to compare `a` to.
108
+ * @returns True if `a` equals `b` in the keys present in a or neither `a` nor `b` are defined, else false.
109
+ *
110
+ * @example
111
+ * ```
112
+ * componentValueEquals({ x: 1, y: 2 }, { x: 1, y: 3 }) // returns false because value of y doesn't match
113
+ * componentValueEquals({ x: 1 }, { x: 1, y: 3 }) // returns true because x is equal and y is not present in a
114
+ * ```
115
+ */
116
+ declare function componentValueEquals<S extends Schema, T = unknown>(a?: Partial<ComponentValue<S, T>>, b?: ComponentValue<S, T>): boolean;
117
+ /**
118
+ * Util to create a tuple of a component and value with matching schema.
119
+ * (Used to enforce Typescript type safety.)
120
+ *
121
+ * @param component {@link defineComponent Component} with {@link ComponentSchema} `S`
122
+ * @param value {@link ComponentValue} with {@link ComponentSchema} `S`
123
+ * @returns Tuple `[component, value]`
124
+ */
125
+ declare function withValue<S extends Schema, T = unknown>(component: Component<S, Metadata, T>, value: ComponentValue<S, T>): [Component<S, Metadata, T>, ComponentValue<S, T>];
126
+ /**
127
+ * Get a set of entities that have the given component value in the given component.
128
+ *
129
+ * @param component {@link defineComponent Component} to get entities with the given value from.
130
+ * @param value look for entities with this {@link ComponentValue}.
131
+ * @returns Set with {@link Entity Entities} with the given component value.
132
+ */
133
+ declare function getEntitiesWithValue<S extends Schema>(component: Component<S> | Indexer<S>, value: Partial<ComponentValue<S>>): Set<Entity>;
134
+ /**
135
+ * Get a set of all entities of the given component.
136
+ *
137
+ * @param component {@link defineComponent Component} to get all entities from
138
+ * @returns Set of all entities in the given component.
139
+ */
140
+ declare function getComponentEntities<S extends Schema, T = unknown>(component: Component<S, Metadata, T>): IterableIterator<Entity>;
141
+ /**
142
+ * An overridable component is a mirror of the source component, with functions to lazily override specific entity values.
143
+ * Lazily override means the values are not actually set to the source component, but the override is only returned if the value is read.
144
+ *
145
+ * - When an override for an entity is added to the component, the override is propagated via the component's `update$` stream.
146
+ * - While an override is set for a specific entity, no updates to the source component for this entity will be propagated to the `update$` stream.
147
+ * - When an override is removed for a specific entity and there are more overrides targeting this entity,
148
+ * the override with the highest nonce will be propagated to the `update$` stream.
149
+ * - When an override is removed for a specific entity and there are no more overrides targeting this entity,
150
+ * the non-overridden underlying component value of this entity will be propagated to the `update$` stream.
151
+ *
152
+ * @param component {@link defineComponent Component} to use as underlying source for the overridable component
153
+ * @returns overridable component
154
+ */
155
+ declare function overridableComponent<S extends Schema, M extends Metadata, T = unknown>(component: Component<S, M, T>): OverridableComponent<S, M, T>;
156
+ declare function clearLocalCache(component: Component, uniqueWorldIdentifier?: string): void;
157
+ declare function createLocalCache<S extends Schema, M extends Metadata, T = unknown>(component: Component<S, M, T>, uniqueWorldIdentifier?: string): Component<S, M, T>;
158
+
159
+ /**
160
+ * Create an indexed component from a given component.
161
+ *
162
+ * @remarks
163
+ * An indexed component keeps a "reverse mapping" from {@link ComponentValue} to the Set of {@link createEntity Entities} with this value.
164
+ * This adds a performance overhead to modifying component values and a memory overhead since in the worst case there is one
165
+ * Set per entity (if every entity has a different component value).
166
+ * In return the performance for querying for entities with a given component value is close to O(1) (instead of O(#entities) in a regular non-indexed component).
167
+ * As a rule of thumb only components that are added to many entities and are queried with {@link HasValue} a lot should be indexed (eg. the Position component).
168
+ *
169
+ * @dev This could be made more (memory) efficient by using a hash of the component value as key, but would require handling hash collisions.
170
+ *
171
+ * @param component {@link defineComponent Component} to index.
172
+ * @returns Indexed version of the component.
173
+ */
174
+ declare function createIndexer<S extends Schema, M extends Metadata, T = unknown>(component: Component<S, M, T>): Indexer<S, M, T>;
175
+
176
+ /**
177
+ * Register a new entity in the given {@link World} and initialize it with the given {@link ComponentValue}s.
178
+ *
179
+ * @param world World object this entity should be registered in.
180
+ * @param components Array of [{@link defineComponent Component}, {@link ComponentValue}] tuples to be added to this entity.
181
+ * (Use {@link withValue} to generate these tuples with type safety.)
182
+ * @param options Optional: {
183
+ * id: {@link Entity} for this entity. Use this for entities that were created outside of recs.
184
+ * idSuffix: string to be appended to the auto-generated id. Use this for improved readability. Do not use this if the `id` option is provided.
185
+ * }
186
+ * @returns index of this entity in the {@link World}. This {@link Entity} is used to refer to this entity in other recs methods (eg {@link setComponent}).
187
+ * (This is to avoid having to store strings in every component.)
188
+ */
189
+ declare function createEntity(world: World, components?: [Component, ComponentValue][], options?: {
190
+ id?: string;
191
+ } | {
192
+ idSuffix?: string;
193
+ }): Entity;
194
+ declare function getEntitySymbol(entityString: string): EntitySymbol;
195
+ /**
196
+ * Get the underlying entity string of an entity symbol.
197
+ */
198
+ declare function getEntityString(entity: EntitySymbol): Entity;
199
+
200
+ /**
201
+ * Create a system that is called on every update of the given observable.
202
+ *
203
+ * @remarks
204
+ * Advantage of using this function over directly subscribing to the RxJS observable is that the system is registered in the `world` and
205
+ * disposed when the `world` is disposed (eg. during a hot reload in development).
206
+ *
207
+ * @param world {@link World} object this system should be registered in.
208
+ * @param observable$ Observable to react to.
209
+ * @param system System function to run on updates of the `observable$`. System function gets passed the update events from the `observable$`.
210
+ */
211
+ declare function defineRxSystem<T>(world: World, observable$: Observable<T>, system: (event: T) => void): void;
212
+ /**
213
+ * Create a system that is called on every event of the given {@link defineUpdateQuery update query}.
214
+ *
215
+ * @param world {@link World} object this system should be registered in.
216
+ * @param query Update query to react to.
217
+ * @param system System function to run when the result of the given update query changes.
218
+ * @param options Optional: {
219
+ * runOnInit: if true, run this system for all entities matching the query when the system is created.
220
+ * Else only run on updates after the system is created. Default true.
221
+ * }
222
+ */
223
+ declare function defineUpdateSystem(world: World, query: QueryFragment[], system: (update: ComponentUpdate) => void, options?: {
224
+ runOnInit?: boolean;
225
+ }): void;
226
+ /**
227
+ * Create a system that is called on every event of the given {@link defineEnterQuery enter query}.
228
+ *
229
+ * @param world {@link World} object this system should be registered in.
230
+ * @param query Enter query to react to.
231
+ * @param system System function to run when the result of the given enter query changes.
232
+ * @param options Optional: {
233
+ * runOnInit: if true, run this system for all entities matching the query when the system is created.
234
+ * Else only run on updates after the system is created. Default true.
235
+ * }
236
+ */
237
+ declare function defineEnterSystem(world: World, query: QueryFragment[], system: (update: ComponentUpdate) => void, options?: {
238
+ runOnInit?: boolean;
239
+ }): void;
240
+ /**
241
+ * Create a system that is called on every event of the given {@link defineExitQuery exit query}.
242
+ *
243
+ * @param world {@link World} object this system should be registered in.
244
+ * @param query Exit query to react to.
245
+ * @param system System function to run when the result of the given exit query changes.
246
+ * @param options Optional: {
247
+ * runOnInit: if true, run this system for all entities matching the query when the system is created.
248
+ * Else only run on updates after the system is created. Default true.
249
+ * }
250
+ */
251
+ declare function defineExitSystem(world: World, query: QueryFragment[], system: (update: ComponentUpdate) => void, options?: {
252
+ runOnInit?: boolean;
253
+ }): void;
254
+ /**
255
+ * Create a system that is called on every event of the given {@link defineQuery query}.
256
+ *
257
+ * @param world {@link World} object this system should be registered in.
258
+ * @param query Query to react to.
259
+ * @param system System function to run when the result of the given query changes.
260
+ * @param options Optional: {
261
+ * runOnInit: if true, run this system for all entities matching the query when the system is created.
262
+ * Else only run on updates after the system is created. Default true.
263
+ * }
264
+ */
265
+ declare function defineSystem(world: World, query: QueryFragment[], system: (update: ComponentUpdate & {
266
+ type: UpdateType;
267
+ }) => void, options?: {
268
+ runOnInit?: boolean;
269
+ }): void;
270
+ /**
271
+ * Create a system that is called every time the given component is updated.
272
+ *
273
+ * @param world {@link World} object this system should be registered in.
274
+ * @param component Component to whose updates to react.
275
+ * @param system System function to run when the given component is updated.
276
+ * @param options Optional: {
277
+ * runOnInit: if true, run this system for all entities in the component when the system is created.
278
+ * Else only run on updates after the system is created. Default true.
279
+ * }
280
+ */
281
+ declare function defineComponentSystem<S extends Schema>(world: World, component: Component<S>, system: (update: ComponentUpdate<S>) => void, options?: {
282
+ runOnInit?: boolean;
283
+ }): void;
284
+ /**
285
+ * Create a system to synchronize updates to one component with another component.
286
+ *
287
+ * @param world {@link World} object this system should be registered in.
288
+ * @param query Result of `component` is added to all entites matching this query.
289
+ * @param component Function returning the component to be added to all entities matching the given query.
290
+ * @param value Function returning the component value to be added to all entities matching the given query.
291
+ */
292
+ declare function defineSyncSystem<T extends Schema>(world: World, query: QueryFragment[], component: (entity: Entity) => Component<T>, value: (entity: Entity) => ComponentValue<T>, options?: {
293
+ update?: boolean;
294
+ runOnInit?: boolean;
295
+ }): void;
296
+
297
+ /**
298
+ * Create a new World.
299
+ *
300
+ * @remarks
301
+ * A World is the central object of an ECS application, where all {@link defineComponent Components},
302
+ * {@link registerEntity Entities} and {@link defineSystem Systems} are registerd.
303
+ *
304
+ * @returns A new World
305
+ */
306
+ declare function createWorld(): {
307
+ registerEntity: ({ id, idSuffix }?: {
308
+ id?: string | undefined;
309
+ idSuffix?: string | undefined;
310
+ }) => Entity;
311
+ components: Component<Schema, Metadata, unknown>[];
312
+ registerComponent: (component: Component) => void;
313
+ dispose: (namespace?: string) => void;
314
+ registerDisposer: (disposer: () => void, namespace?: string) => void;
315
+ hasEntity: (entity: Entity) => boolean;
316
+ getEntities: () => IterableIterator<Entity>;
317
+ entitySymbols: Set<EntitySymbol>;
318
+ deleteEntity: (entity: Entity) => void;
319
+ };
320
+ /**
321
+ * Create a new namespace from an existing World.
322
+ * The `dispose` method of a namespaced World only calls disposers registered on this namespace.
323
+ *
324
+ * @param world World to create a new namespace for.
325
+ * @param namespace String descriptor of the new namespace.
326
+ * @returns World with a new namespace.
327
+ */
328
+ declare function namespaceWorld(world: ReturnType<typeof createWorld>, namespace: string): {
329
+ registerDisposer: (disposer: () => void) => void;
330
+ dispose: () => void;
331
+ registerEntity: ({ id, idSuffix }?: {
332
+ id?: string | undefined;
333
+ idSuffix?: string | undefined;
334
+ }) => Entity;
335
+ components: Component<Schema, Metadata, unknown>[];
336
+ registerComponent: (component: Component<Schema, Metadata, unknown>) => void;
337
+ hasEntity: (entity: Entity) => boolean;
338
+ getEntities: () => IterableIterator<Entity>;
339
+ entitySymbols: Set<EntitySymbol>;
340
+ deleteEntity: (entity: Entity) => void;
341
+ };
342
+ /**
343
+ * Get all components that have a value for the given entity.
344
+ *
345
+ * @dev Design decision: don't store a list of components for each entity but compute it dynamically when needed
346
+ * because there are less components than entities and maintaining a list of components per entity is a large overhead.
347
+ *
348
+ * @param world World object the given entity is registered on.
349
+ * @param entity {@link Entity} to get the list of components for.
350
+ * @returns Array of components that have a value for the given entity.
351
+ */
352
+ declare function getEntityComponents(world: World, entity: Entity): Component[];
353
+
354
+ /**
355
+ * Create a {@link HasQueryFragment}.
356
+ *
357
+ * @remarks
358
+ * The {@link HasQueryFragment} filters for entities that have the given component,
359
+ * independent from the component value.
360
+ *
361
+ * @example
362
+ * Query for all entities with a `Position`.
363
+ * ```
364
+ * runQuery([Has(Position)]);
365
+ * ```
366
+ *
367
+ * @param component Component this query fragment refers to.
368
+ * @returns query fragment to be used in {@link runQuery} or {@link defineQuery}.
369
+ */
370
+ declare function Has<T extends Schema>(component: Component<T>): HasQueryFragment<T>;
371
+ /**
372
+ * Create a {@link NotQueryFragment}.
373
+ *
374
+ * @remarks
375
+ * The {@link NotQueryFragment} filters for entities that don't have the given component,
376
+ * independent from the component value.
377
+ *
378
+ * @example
379
+ * Query for all entities with a `Position` that are not `Movable`.
380
+ * ```
381
+ * runQuery([Has(Position), Not(Movable)]);
382
+ * ```
383
+ *
384
+ * @param component Component this query fragment refers to.
385
+ * @returns query fragment to be used in {@link runQuery} or {@link defineQuery}.
386
+ */
387
+ declare function Not<T extends Schema>(component: Component<T>): NotQueryFragment<T>;
388
+ /**
389
+ * Create a {@link HasValueQueryFragment}.
390
+ *
391
+ * @remarks
392
+ * The {@link HasValueQueryFragment} filters for entities that have the given component
393
+ * with the given component value.
394
+ *
395
+ * @example
396
+ * Query for all entities at Position (0,0).
397
+ * ```
398
+ * runQuery([HasValue(Position, { x: 0, y: 0 })]);
399
+ * ```
400
+ *
401
+ * @param component Component this query fragment refers to.
402
+ * @param value Only include entities with this (partial) component value from the result.
403
+ * @returns query fragment to be used in {@link runQuery} or {@link defineQuery}.
404
+ */
405
+ declare function HasValue<T extends Schema>(component: Component<T>, value: Partial<ComponentValue<T>>): HasValueQueryFragment<T>;
406
+ /**
407
+ * Create a {@link NotValueQueryFragment}.
408
+ *
409
+ * @remarks
410
+ * The {@link NotValueQueryFragment} filters for entities that don't have the given component
411
+ * with the given component value.
412
+ *
413
+ * @example
414
+ * Query for all entities that have a `Position`, except for those at `Position` (0,0).
415
+ * ```
416
+ * runQuery([Has(Position), NotValue(Position, { x: 0, y: 0 })]);
417
+ * ```
418
+ *
419
+ * @param component Component this query fragment refers to.
420
+ * @param value Exclude entities with this (partial) component value from the result.
421
+ * @returns query fragment to be used in {@link runQuery} or {@link defineQuery}.
422
+ */
423
+ declare function NotValue<T extends Schema>(component: Component<T>, value: Partial<ComponentValue<T>>): NotValueQueryFragment<T>;
424
+ /**
425
+ * Create a {@link ProxyReadQueryFragment}.
426
+ *
427
+ * @remarks
428
+ * The {@link ProxyReadQueryFragment} activates the "proxy read mode" for the rest of the query.
429
+ * This means that for all remaining fragments in the query not only the entities themselves are checked, but also
430
+ * their "ancestors" up to the given `depth` on the relationship chain defined by the given `component`.
431
+ *
432
+ * @example
433
+ * Query for all entities that have a `Position` and are (directly or indirectly) owned by an entity with `Name` "Alice".
434
+ * ```
435
+ * runQuery([Has(Position), ProxyRead(OwnedByEntity, Number.MAX_SAFE_INTEGER), HasValue(Name, { name: "Alice" })]);
436
+ * ```
437
+ *
438
+ * @param component Component this query fragment refers to.
439
+ * @param depth Max depth in the relationship chain to traverse.
440
+ * @returns query fragment to be used in {@link runQuery} or {@link defineQuery}.
441
+ */
442
+ declare function ProxyRead(component: Component<{
443
+ value: Type.Entity;
444
+ }>, depth: number): ProxyReadQueryFragment;
445
+ /**
446
+ * Create a {@link ProxyExpandQueryFragment}.
447
+ *
448
+ * @remarks
449
+ * The {@link ProxyExpandQueryFragment} activates the "proxy expand mode" for the rest of the query.
450
+ * This means that for all remaining fragments in the query not only the matching entities themselves are included in the intermediate set,
451
+ * but also all their "children" down to the given `depth` on the relationship chain defined by the given `component`.
452
+ *
453
+ * @example
454
+ * Query for all entities (directly or indirectly) owned by an entity with `Name` "Alice".
455
+ * ```
456
+ * runQuery([ProxyExpand(OwnedByEntity, Number.MAX_SAFE_INTEGER), HasValue(Name, { name: "Alice" })]);
457
+ * ```
458
+ *
459
+ * @param component Component to apply this query fragment to.
460
+ * @param depth Max depth in the relationship chain to traverse.
461
+ * @returns query fragment to be used in {@link runQuery} or {@link defineQuery}.
462
+ */
463
+ declare function ProxyExpand(component: Component<{
464
+ value: Type.Entity;
465
+ }>, depth: number): ProxyExpandQueryFragment;
466
+ /**
467
+ * Recursively compute all direct and indirect child entities up to the specified depth
468
+ * down the relationship chain defined by the given component.
469
+ *
470
+ * @param entity Entity to get all child entities for up to the specified depth
471
+ * @param component Component to use for the relationship chain.
472
+ * @param depth Depth up to which the recursion should be applied.
473
+ * @returns Set of entities that are child entities of the given entity via the given component.
474
+ */
475
+ declare function getChildEntities(entity: Entity, component: Component<{
476
+ value: Type.Entity;
477
+ }>, depth: number): Set<Entity>;
478
+ /**
479
+ * Execute a list of query fragments to receive a Set of matching entities.
480
+ *
481
+ * @remarks
482
+ * The query fragments are executed from left to right and are concatenated with a logical `AND`.
483
+ * For performance reasons, the most restrictive query fragment should be first in the list of query fragments,
484
+ * in order to reduce the number of entities the next query fragment needs to be checked for.
485
+ * If no proxy fragments are used, every entity in the resulting set passes every query fragment.
486
+ * If setting fragments are used, the order of the query fragments influences the result, since settings only apply to
487
+ * fragments after the setting fragment.
488
+ *
489
+ * @param fragments Query fragments to execute.
490
+ * @param initialSet Optional: provide a Set of entities to execute the query on. If none is given, all existing entities are used for the query.
491
+ * @returns Set of entities matching the query fragments.
492
+ */
493
+ declare function runQuery(fragments: QueryFragment[], initialSet?: Set<Entity>): Set<Entity>;
494
+ /**
495
+ * Create a query object including an update$ stream and a Set of entities currently matching the query.
496
+ *
497
+ * @remarks
498
+ * `update$` stream needs to be subscribed to in order for the logic inside the stream to be executed and therefore
499
+ * in order for the `matching` set to be updated.
500
+ *
501
+ * `defineQuery` should be strongly preferred over `runQuery` if the query is used for systems or other
502
+ * use cases that repeatedly require the query result or updates to the query result. `defineQuery` does not
503
+ * reevaluate the entire query if an accessed component changes, but only performs the minimal set of checks
504
+ * on the updated entity to evaluate wether the entity still matches the query, resulting in significant performance
505
+ * advantages over `runQuery`.
506
+ *
507
+ * The query fragments are executed from left to right and are concatenated with a logical `AND`.
508
+ * For performance reasons, the most restrictive query fragment should be first in the list of query fragments,
509
+ * in order to reduce the number of entities the next query fragment needs to be checked for.
510
+ * If no proxy fragments are used, every entity in the resulting set passes every query fragment.
511
+ * If setting fragments are used, the order of the query fragments influences the result, since settings only apply to
512
+ * fragments after the setting fragment.
513
+ *
514
+ * @param fragments Query fragments to execute.
515
+ * @param options Optional: {
516
+ * runOnInit: if true, the query is executed once with `runQuery` to build an iniital Set of matching entities. If false only updates after the query was created are considered.
517
+ * initialSet: if given, this set is passed to `runOnInit` when building the initial Set of matching entities.
518
+ * }
519
+ * @returns Query object: {
520
+ * update$: RxJS stream of updates to the query result. The update contains the component update that caused the query update, as well as the {@link UpdateType update type}.
521
+ * matching: Mobx observable set of entities currently matching the query.
522
+ * }.
523
+ */
524
+ declare function defineQuery(fragments: QueryFragment[], options?: {
525
+ runOnInit?: boolean;
526
+ initialSet?: Set<Entity>;
527
+ }): {
528
+ update$: Observable<ComponentUpdate & {
529
+ type: UpdateType;
530
+ }>;
531
+ matching: ObservableSet<Entity>;
532
+ };
533
+ /**
534
+ * Define a query object that only passes update events of type {@link UpdateType}.Update to the `update$` stream.
535
+ * See {@link defineQuery} for details.
536
+ *
537
+ * @param fragments Query fragments
538
+ * @returns Stream of component updates of entities that had already matched the query
539
+ */
540
+ declare function defineUpdateQuery(fragments: QueryFragment[], options?: {
541
+ runOnInit?: boolean;
542
+ }): Observable<ComponentUpdate & {
543
+ type: UpdateType;
544
+ }>;
545
+ /**
546
+ * Define a query object that only passes update events of type {@link UpdateType}.Enter to the `update$` stream.
547
+ * See {@link defineQuery} for details.
548
+ *
549
+ * @param fragments Query fragments
550
+ * @returns Stream of component updates of entities matching the query for the first time
551
+ */
552
+ declare function defineEnterQuery(fragments: QueryFragment[], options?: {
553
+ runOnInit?: boolean;
554
+ }): Observable<ComponentUpdate>;
555
+ /**
556
+ * Define a query object that only passes update events of type {@link UpdateType}.Exit to the `update$` stream.
557
+ * See {@link defineQuery} for details.
558
+ *
559
+ * @param fragments Query fragments
560
+ * @returns Stream of component updates of entities not matching the query anymore for the first time
561
+ */
562
+ declare function defineExitQuery(fragments: QueryFragment[], options?: {
563
+ runOnInit?: boolean;
564
+ }): Observable<ComponentUpdate>;
565
+
566
+ /**
567
+ * Type guard to infer the TypeScript type of a given component update
568
+ *
569
+ * @param update Component update to infer the type of.
570
+ * @param component {@link defineComponent Component} to check whether the given update corresponds to it.
571
+ * @returns True (+ infered type for `update`) if `update` belongs to `component`. Else false.
572
+ */
573
+ declare function isComponentUpdate<S extends Schema>(update: ComponentUpdate, component: Component<S>): update is ComponentUpdate<S>;
574
+ /**
575
+ * Helper function to create a component update for the current component value of a given entity.
576
+ *
577
+ * @param entity Entity to create the component update for.
578
+ * @param component Component to create the component update for.
579
+ * @returns Component update corresponding to the given entity, the given component and the entity's current component value.
580
+ */
581
+ declare function toUpdate<S extends Schema>(entity: Entity, component: Component<S>): ComponentUpdate<S> & {
582
+ type: UpdateType;
583
+ };
584
+ /**
585
+ * Helper function to turn a stream of {@link Entity Entities} into a stream of component updates of the given component.
586
+ * @param component Component to create update stream for.
587
+ * @returns Unary function to be used with RxJS that turns stream of {@link Entity Entities} into stream of component updates.
588
+ */
589
+ declare function toUpdateStream<S extends Schema>(component: Component<S>): rxjs.UnaryFunction<rxjs.Observable<Entity>, rxjs.Observable<ComponentUpdate<S> & {
590
+ type: UpdateType;
591
+ }>>;
592
+ /**
593
+ * Helper function to check whether a given component is indexed.
594
+ * @param c
595
+ * @returns
596
+ */
597
+ declare function isIndexer<S extends Schema>(c: Component<S> | Indexer<S>): c is Indexer<S>;
598
+ /**
599
+ * Helper function to check whether a given component value is partial or full.
600
+ * @param component
601
+ * @param value
602
+ * @returns
603
+ */
604
+ declare function isFullComponentValue<S extends Schema>(component: Component<S>, value: Partial<ComponentValue<S>>): value is ComponentValue<S>;
605
+
606
+ export { Component, type ComponentMutationOptions, ComponentUpdate, ComponentValue, Entity, EntitySymbol, Has, HasQueryFragment, HasValue, HasValueQueryFragment, Indexer, Metadata, Not, NotQueryFragment, NotValue, NotValueQueryFragment, OverridableComponent, ProxyExpand, ProxyExpandQueryFragment, ProxyRead, ProxyReadQueryFragment, QueryFragment, Schema, Type, UpdateType, World, clearLocalCache, componentValueEquals, createEntity, createIndexer, createLocalCache, createWorld, defineComponent, defineComponentSystem, defineEnterQuery, defineEnterSystem, defineExitQuery, defineExitSystem, defineQuery, defineRxSystem, defineSyncSystem, defineSystem, defineUpdateQuery, defineUpdateSystem, getChildEntities, getComponentEntities, getComponentValue, getComponentValueStrict, getEntitiesWithValue, getEntityComponents, getEntityString, getEntitySymbol, hasComponent, isComponentUpdate, isFullComponentValue, isIndexer, namespaceWorld, overridableComponent, removeComponent, runQuery, setComponent, toUpdate, toUpdateStream, updateComponent, withValue };