Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(ecs): the instance classes are frozen, and every leak left is one boundary

yhh2b0dd7543a00
diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.json
index 461ab49ca..b7d5ce1e5 100644
--- a/docs/astro/src/data/apiStability.generated.json
+++ b/docs/astro/src/data/apiStability.generated.json
@@ -1,9 +1,9 @@
{
"note": "Generated by tools/api-stability.mjs from sdk/etc/*.api.md — do not edit.",
"counts": {
- "public": 31,
+ "public": 40,
"beta": 24,
- "experimental": 1570,
+ "experimental": 1561,
"deprecated": 1
},
"total": 1625,
@@ -80,6 +80,18 @@
"minigame"
]
},
+ {
+ "name": "CommandsInstance",
+ "kind": "class",
+ "deprecated": false,
+ "entries": [
+ "index",
+ "index.node",
+ "index.native",
+ "wechat",
+ "minigame"
+ ]
+ },
{
"name": "ComponentDef",
"kind": "interface",
@@ -104,6 +116,30 @@
"minigame"
]
},
+ {
+ "name": "Entity",
+ "kind": "type",
+ "deprecated": false,
+ "entries": [
+ "index",
+ "index.node",
+ "index.native",
+ "wechat",
+ "minigame"
+ ]
+ },
+ {
+ "name": "EntityCommands",
+ "kind": "class",
+ "deprecated": false,
+ "entries": [
+ "index",
+ "index.node",
+ "index.native",
+ "wechat",
+ "minigame"
+ ]
+ },
{
"name": "EventReaderDescriptor",
"kind": "interface",
@@ -116,6 +152,18 @@
"minigame"
]
},
+ {
+ "name": "EventReaderInstance",
+ "kind": "class",
+ "deprecated": false,
+ "entries": [
+ "index",
+ "index.node",
+ "index.native",
+ "wechat",
+ "minigame"
+ ]
+ },
{
"name": "EventWriterDescriptor",
"kind": "interface",
@@ -128,6 +176,18 @@
"minigame"
]
},
+ {
+ "name": "EventWriterInstance",
+ "kind": "class",
+ "deprecated": false,
+ "entries": [
+ "index",
+ "index.node",
+ "index.native",
+ "wechat",
+ "minigame"
+ ]
+ },
{
"name": "FieldMeta",
"kind": "interface",
@@ -260,6 +320,30 @@
"minigame"
]
},
+ {
+ "name": "QueryInstance",
+ "kind": "class",
+ "deprecated": false,
+ "entries": [
+ "index",
+ "index.node",
+ "index.native",
+ "wechat",
+ "minigame"
+ ]
+ },
+ {
+ "name": "QueryResult",
+ "kind": "type",
+ "deprecated": false,
+ "entries": [
+ "index",
+ "index.node",
+ "index.native",
+ "wechat",
+ "minigame"
+ ]
+ },
{
"name": "RemovedQueryDescriptor",
"kind": "interface",
@@ -272,6 +356,18 @@
"minigame"
]
},
+ {
+ "name": "RemovedQueryInstance",
+ "kind": "class",
+ "deprecated": false,
+ "entries": [
+ "index",
+ "index.node",
+ "index.native",
+ "wechat",
+ "minigame"
+ ]
+ },
{
"name": "Res",
"kind": "function",
@@ -308,6 +404,18 @@
"minigame"
]
},
+ {
+ "name": "ResMutInstance",
+ "kind": "class",
+ "deprecated": false,
+ "entries": [
+ "index",
+ "index.node",
+ "index.native",
+ "wechat",
+ "minigame"
+ ]
+ },
{
"name": "ResourceDef",
"kind": "interface",
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index f9683f3f2..8602fecaa 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 31 public · 17 beta · 1455 experimental · 1 deprecated
+Symbols: 40 public · 17 beta · 1446 experimental · 1 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -1758,7 +1758,7 @@ keyof ThemeColors
@internal _type: "commands"
```
-## CommandsInstance — class @experimental
+## CommandsInstance — class @public
```
despawn: (entity: Entity) => CommandsInstance
entity: (entity: Entity) => EntityCommands
@@ -2491,12 +2491,12 @@ Rectangle = 2
NativeEngineApi & Partial<NativeHeap>
```
-## Entity — type @experimental
+## Entity — type @public
```
number
```
-## EntityCommands — class @experimental
+## EntityCommands — class @public
```
finalize: () => void
id: () => Entity
@@ -2591,8 +2591,9 @@ _phantom: T | undefined
@internal _type: "event_reader"
```
-## EventReaderInstance — class @experimental
+## EventReaderInstance — class @public
```
+[Symbol.iterator]: () => Iterator<T>
isEmpty: () => boolean
toArray: () => T[]
static new <T>(bus: EventBus<T>): EventReaderInstance<T>
@@ -2619,7 +2620,7 @@ static prototype: EventRegistry
@internal _type: "event_writer"
```
-## EventWriterInstance — class @experimental
+## EventWriterInstance — class @public
```
send: (event: T) => void
static new <T>(bus: EventBus<T>): EventWriterInstance<T>
@@ -5340,9 +5341,10 @@ without: (...components: AnyComponentDef[]) => QueryBuilder<C>
@internal _without: AnyComponentDef[]
```
-## QueryInstance — class @experimental
+## QueryInstance — class @public
```
@internal resetTick: (tick: number) => void
+[Symbol.iterator]: () => Iterator<QueryResult<C>>
count: () => number
forEach: (callback: (entity: Entity, ...components: ComponentsData<C>) => void) => void
isEmpty: () => boolean
@@ -5352,7 +5354,7 @@ static new <C extends readonly QueryArg[]>(world: World, descriptor: QueryDescri
static prototype: QueryInstance<any>
```
-## QueryResult — type @experimental
+## QueryResult — type @public
```
[
Entity,
@@ -5397,9 +5399,10 @@ subscribe: (fn: (value: T) => void) => () => void
@internal _type: "removed"
```
-## RemovedQueryInstance — class @experimental
+## RemovedQueryInstance — class @public
```
@internal resetTick: (tick: number) => void
+[Symbol.iterator]: () => Iterator<Entity>
isEmpty: () => boolean
toArray: () => Entity[]
static new <T extends AnyComponentDef>(world: World, component: T, lastRunTick: number): RemovedQueryInstance<T>
@@ -5587,7 +5590,7 @@ static prototype: ReplicationServer
@internal _type: "res_mut"
```
-## ResMutInstance — class @experimental
+## ResMutInstance — class @public
```
@internal updateValue: (value: T) => void
get: () => T
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index a03151e9a..4d22b2996 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.native
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 31 public · 22 beta · 1474 experimental · 1 deprecated
+Symbols: 40 public · 22 beta · 1465 experimental · 1 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -1758,7 +1758,7 @@ keyof ThemeColors
@internal _type: "commands"
```
-## CommandsInstance — class @experimental
+## CommandsInstance — class @public
```
despawn: (entity: Entity) => CommandsInstance
entity: (entity: Entity) => EntityCommands
@@ -2499,12 +2499,12 @@ Rectangle = 2
NativeEngineApi & Partial<NativeHeap>
```
-## Entity — type @experimental
+## Entity — type @public
```
number
```
-## EntityCommands — class @experimental
+## EntityCommands — class @public
```
finalize: () => void
id: () => Entity
@@ -2599,8 +2599,9 @@ _phantom: T | undefined
@internal _type: "event_reader"
```
-## EventReaderInstance — class @experimental
+## EventReaderInstance — class @public
```
+[Symbol.iterator]: () => Iterator<T>
isEmpty: () => boolean
toArray: () => T[]
static new <T>(bus: EventBus<T>): EventReaderInstance<T>
@@ -2627,7 +2628,7 @@ static prototype: EventRegistry
@internal _type: "event_writer"
```
-## EventWriterInstance — class @experimental
+## EventWriterInstance — class @public
```
send: (event: T) => void
static new <T>(bus: EventBus<T>): EventWriterInstance<T>
@@ -5523,9 +5524,10 @@ without: (...components: AnyComponentDef[]) => QueryBuilder<C>
@internal _without: AnyComponentDef[]
```
-## QueryInstance — class @experimental
+## QueryInstance — class @public
```
@internal resetTick: (tick: number) => void
+[Symbol.iterator]: () => Iterator<QueryResult<C>>
count: () => number
forEach: (callback: (entity: Entity, ...components: ComponentsData<C>) => void) => void
isEmpty: () => boolean
@@ -5535,7 +5537,7 @@ static new <C extends readonly QueryArg[]>(world: World, descriptor: QueryDescri
static prototype: QueryInstance<any>
```
-## QueryResult — type @experimental
+## QueryResult — type @public
```
[
Entity,
@@ -5590,9 +5592,10 @@ subscribe: (fn: (value: T) => void) => () => void
@internal _type: "removed"
```
-## RemovedQueryInstance — class @experimental
+## RemovedQueryInstance — class @public
```
@internal resetTick: (tick: number) => void
+[Symbol.iterator]: () => Iterator<Entity>
isEmpty: () => boolean
toArray: () => Entity[]
static new <T extends AnyComponentDef>(world: World, component: T, lastRunTick: number): RemovedQueryInstance<T>
@@ -5780,7 +5783,7 @@ static prototype: ReplicationServer
@internal _type: "res_mut"
```
-## ResMutInstance — class @experimental
+## ResMutInstance — class @public
```
@internal updateValue: (value: T) => void
get: () => T
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index b2e965115..ffce066e7 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 31 public · 19 beta · 1454 experimental · 1 deprecated
+Symbols: 40 public · 19 beta · 1445 experimental · 1 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -1753,7 +1753,7 @@ keyof ThemeColors
@internal _type: "commands"
```
-## CommandsInstance — class @experimental
+## CommandsInstance — class @public
```
despawn: (entity: Entity) => CommandsInstance
entity: (entity: Entity) => EntityCommands
@@ -2486,12 +2486,12 @@ Rectangle = 2
NativeEngineApi & Partial<NativeHeap>
```
-## Entity — type @experimental
+## Entity — type @public
```
number
```
-## EntityCommands — class @experimental
+## EntityCommands — class @public
```
finalize: () => void
id: () => Entity
@@ -2586,8 +2586,9 @@ _phantom: T | undefined
@internal _type: "event_reader"
```
-## EventReaderInstance — class @experimental
+## EventReaderInstance — class @public
```
+[Symbol.iterator]: () => Iterator<T>
isEmpty: () => boolean
toArray: () => T[]
static new <T>(bus: EventBus<T>): EventReaderInstance<T>
@@ -2614,7 +2615,7 @@ static prototype: EventRegistry
@internal _type: "event_writer"
```
-## EventWriterInstance — class @experimental
+## EventWriterInstance — class @public
```
send: (event: T) => void
static new <T>(bus: EventBus<T>): EventWriterInstance<T>
@@ -5335,9 +5336,10 @@ without: (...components: AnyComponentDef[]) => QueryBuilder<C>
@internal _without: AnyComponentDef[]
```
-## QueryInstance — class @experimental
+## QueryInstance — class @public
```
@internal resetTick: (tick: number) => void
+[Symbol.iterator]: () => Iterator<QueryResult<C>>
count: () => number
forEach: (callback: (entity: Entity, ...components: ComponentsData<C>) => void) => void
isEmpty: () => boolean
@@ -5347,7 +5349,7 @@ static new <C extends readonly QueryArg[]>(world: World, descriptor: QueryDescri
static prototype: QueryInstance<any>
```
-## QueryResult — type @experimental
+## QueryResult — type @public
```
[
Entity,
@@ -5392,9 +5394,10 @@ subscribe: (fn: (value: T) => void) => () => void
@internal _type: "removed"
```
-## RemovedQueryInstance — class @experimental
+## RemovedQueryInstance — class @public
```
@internal resetTick: (tick: number) => void
+[Symbol.iterator]: () => Iterator<Entity>
isEmpty: () => boolean
toArray: () => Entity[]
static new <T extends AnyComponentDef>(world: World, component: T, lastRunTick: number): RemovedQueryInstance<T>
@@ -5582,7 +5585,7 @@ static prototype: ReplicationServer
@internal _type: "res_mut"
```
-## ResMutInstance — class @experimental
+## ResMutInstance — class @public
```
@internal updateValue: (value: T) => void
get: () => T
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 954341de8..96c13cad0 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/minigame
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 31 public · 17 beta · 1475 experimental · 1 deprecated
+Symbols: 40 public · 17 beta · 1466 experimental · 1 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -1753,7 +1753,7 @@ keyof ThemeColors
@internal _type: "commands"
```
-## CommandsInstance — class @experimental
+## CommandsInstance — class @public
```
despawn: (entity: Entity) => CommandsInstance
entity: (entity: Entity) => EntityCommands
@@ -2486,12 +2486,12 @@ Rectangle = 2
NativeEngineApi & Partial<NativeHeap>
```
-## Entity — type @experimental
+## Entity — type @public
```
number
```
-## EntityCommands — class @experimental
+## EntityCommands — class @public
```
finalize: () => void
id: () => Entity
@@ -2586,8 +2586,9 @@ _phantom: T | undefined
@internal _type: "event_reader"
```
-## EventReaderInstance — class @experimental
+## EventReaderInstance — class @public
```
+[Symbol.iterator]: () => Iterator<T>
isEmpty: () => boolean
toArray: () => T[]
static new <T>(bus: EventBus<T>): EventReaderInstance<T>
@@ -2614,7 +2615,7 @@ static prototype: EventRegistry
@internal _type: "event_writer"
```
-## EventWriterInstance — class @experimental
+## EventWriterInstance — class @public
```
send: (event: T) => void
static new <T>(bus: EventBus<T>): EventWriterInstance<T>
@@ -5580,9 +5581,10 @@ without: (...components: AnyComponentDef[]) => QueryBuilder<C>
@internal _without: AnyComponentDef[]
```
-## QueryInstance — class @experimental
+## QueryInstance — class @public
```
@internal resetTick: (tick: number) => void
+[Symbol.iterator]: () => Iterator<QueryResult<C>>
count: () => number
forEach: (callback: (entity: Entity, ...components: ComponentsData<C>) => void) => void
isEmpty: () => boolean
@@ -5592,7 +5594,7 @@ static new <C extends readonly QueryArg[]>(world: World, descriptor: QueryDescri
static prototype: QueryInstance<any>
```
-## QueryResult — type @experimental
+## QueryResult — type @public
```
[
Entity,
@@ -5637,9 +5639,10 @@ subscribe: (fn: (value: T) => void) => () => void
@internal _type: "removed"
```
-## RemovedQueryInstance — class @experimental
+## RemovedQueryInstance — class @public
```
@internal resetTick: (tick: number) => void
+[Symbol.iterator]: () => Iterator<Entity>
isEmpty: () => boolean
toArray: () => Entity[]
static new <T extends AnyComponentDef>(world: World, component: T, lastRunTick: number): RemovedQueryInstance<T>
@@ -5827,7 +5830,7 @@ static prototype: ReplicationServer
@internal _type: "res_mut"
```
-## ResMutInstance — class @experimental
+## ResMutInstance — class @public
```
@internal updateValue: (value: T) => void
get: () => T
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index 30e804cbe..210350398 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/wechat
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 31 public · 17 beta · 1465 experimental · 1 deprecated
+Symbols: 40 public · 17 beta · 1456 experimental · 1 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -1753,7 +1753,7 @@ keyof ThemeColors
@internal _type: "commands"
```
-## CommandsInstance — class @experimental
+## CommandsInstance — class @public
```
despawn: (entity: Entity) => CommandsInstance
entity: (entity: Entity) => EntityCommands
@@ -2486,12 +2486,12 @@ Rectangle = 2
NativeEngineApi & Partial<NativeHeap>
```
-## Entity — type @experimental
+## Entity — type @public
```
number
```
-## EntityCommands — class @experimental
+## EntityCommands — class @public
```
finalize: () => void
id: () => Entity
@@ -2586,8 +2586,9 @@ _phantom: T | undefined
@internal _type: "event_reader"
```
-## EventReaderInstance — class @experimental
+## EventReaderInstance — class @public
```
+[Symbol.iterator]: () => Iterator<T>
isEmpty: () => boolean
toArray: () => T[]
static new <T>(bus: EventBus<T>): EventReaderInstance<T>
@@ -2614,7 +2615,7 @@ static prototype: EventRegistry
@internal _type: "event_writer"
```
-## EventWriterInstance — class @experimental
+## EventWriterInstance — class @public
```
send: (event: T) => void
static new <T>(bus: EventBus<T>): EventWriterInstance<T>
@@ -5342,9 +5343,10 @@ without: (...components: AnyComponentDef[]) => QueryBuilder<C>
@internal _without: AnyComponentDef[]
```
-## QueryInstance — class @experimental
+## QueryInstance — class @public
```
@internal resetTick: (tick: number) => void
+[Symbol.iterator]: () => Iterator<QueryResult<C>>
count: () => number
forEach: (callback: (entity: Entity, ...components: ComponentsData<C>) => void) => void
isEmpty: () => boolean
@@ -5354,7 +5356,7 @@ static new <C extends readonly QueryArg[]>(world: World, descriptor: QueryDescri
static prototype: QueryInstance<any>
```
-## QueryResult — type @experimental
+## QueryResult — type @public
```
[
Entity,
@@ -5399,9 +5401,10 @@ subscribe: (fn: (value: T) => void) => () => void
@internal _type: "removed"
```
-## RemovedQueryInstance — class @experimental
+## RemovedQueryInstance — class @public
```
@internal resetTick: (tick: number) => void
+[Symbol.iterator]: () => Iterator<Entity>
isEmpty: () => boolean
toArray: () => Entity[]
static new <T extends AnyComponentDef>(world: World, component: T, lastRunTick: number): RemovedQueryInstance<T>
@@ -5589,7 +5592,7 @@ static prototype: ReplicationServer
@internal _type: "res_mut"
```
-## ResMutInstance — class @experimental
+## ResMutInstance — class @public
```
@internal updateValue: (value: T) => void
get: () => T
diff --git a/sdk/src/ecs/commands.ts b/sdk/src/ecs/commands.ts
index 7fdd7e08b..648b9a166 100644
--- a/sdk/src/ecs/commands.ts
+++ b/sdk/src/ecs/commands.ts
@@ -83,6 +83,13 @@ type Command =
// Entity Commands (Builder for spawning)
// =============================================================================
+/**
+ * One entity's share of a {@link CommandsInstance}: chain `insert`/`remove` and
+ * let the queue apply them. Asking {@link EntityCommands.id} for a spawn's
+ * entity materialises it early, because an id has to exist to be answered.
+ *
+ * @public
+ */
export class EntityCommands {
private readonly commands_: CommandsInstance;
private readonly entityRef_: { entity: Entity };
@@ -147,6 +154,13 @@ export class EntityCommands {
// Commands Instance (Runtime)
// =============================================================================
+/**
+ * The command queue a system declared with {@link Commands}. Records structural
+ * work — spawn, despawn, add or remove a component, install a resource — and
+ * applies it when the system returns, so nothing moves under a running query.
+ *
+ * @public
+ */
export class CommandsInstance {
private readonly world_: World;
private readonly resources_: ResourceStorage;
diff --git a/sdk/src/ecs/event.ts b/sdk/src/ecs/event.ts
index 75c4f9b87..5c15e6f50 100644
--- a/sdk/src/ecs/event.ts
+++ b/sdk/src/ecs/event.ts
@@ -117,6 +117,12 @@ export function EventReader<T>(event: EventDef<T>): EventReaderDescriptor<T> {
// Runtime Instances
// =============================================================================
+/**
+ * The send end of an event, as {@link EventWriter} asked for. What is sent this
+ * frame is what every reader sees next, so sending is not a call into them.
+ *
+ * @public
+ */
export class EventWriterInstance<T> {
private readonly bus_: EventBus<T>;
@@ -129,6 +135,13 @@ export class EventWriterInstance<T> {
}
}
+/**
+ * The events sent since this system last ran, as {@link EventReader} asked for.
+ * Reading does not consume: every reader of an event sees the whole frame's
+ * worth, and the buffer turns over on its own.
+ *
+ * @public
+ */
export class EventReaderInstance<T> implements Iterable<T> {
private readonly bus_: EventBus<T>;
diff --git a/sdk/src/ecs/query.ts b/sdk/src/ecs/query.ts
index f6b25581b..c0054da13 100644
--- a/sdk/src/ecs/query.ts
+++ b/sdk/src/ecs/query.ts
@@ -343,6 +343,13 @@ type ComponentsData<C extends readonly QueryArg[]> = {
[K in keyof C]: ComponentData<UnwrapQueryArg<C[K]>>;
};
+/**
+ * One step of a {@link QueryInstance}: the entity, then each requested
+ * component's data in the order it was asked for. A tuple, so destructuring it
+ * in a `for…of` is typed without annotation.
+ *
+ * @public
+ */
export type QueryResult<C extends readonly QueryArg[]> = [
Entity,
...ComponentsData<C>
@@ -352,6 +359,14 @@ export type QueryResult<C extends readonly QueryArg[]> = [
// Query Instance (Runtime)
// =============================================================================
+/**
+ * A live query, as a system body receives it. Iterate it — each step yields the
+ * entity followed by its components — or use `forEach`, `single`, `toArray`,
+ * `count` and `isEmpty`. Any {@link Mut} argument is written back and marked
+ * changed as iteration leaves each entity, so leaving the loop early is safe.
+ *
+ * @public
+ */
export class QueryInstance<C extends readonly QueryArg[]> implements Iterable<QueryResult<C>> {
private readonly world_: World;
private readonly descriptor_: QueryDescriptor<C>;
@@ -727,6 +742,13 @@ export function Removed<T extends AnyComponentDef>(component: T): RemovedQueryDe
return { _type: 'removed', _component: component };
}
+/**
+ * The entities that lost a component since this system last ran, as
+ * {@link Removed} asked for. Yields entities only — the component is gone, so
+ * there is nothing left to read from it.
+ *
+ * @public
+ */
export class RemovedQueryInstance<T extends AnyComponentDef> implements Iterable<Entity> {
private readonly world_: World;
private readonly component_: T;
diff --git a/sdk/src/ecs/resource.ts b/sdk/src/ecs/resource.ts
index b2067faef..8dd7531f8 100644
--- a/sdk/src/ecs/resource.ts
+++ b/sdk/src/ecs/resource.ts
@@ -90,6 +90,13 @@ export function ResMut<T>(resource: ResourceDef<T>): ResMutDescriptor<T> {
// Resource Instances (Runtime)
// =============================================================================
+/**
+ * Write access to a resource, as {@link ResMut} asked for. `get` reads,
+ * `set` replaces, `modify` edits in place — and both writers store the value
+ * back and bump the change tick, which is the part `Res` cannot do.
+ *
+ * @public
+ */
export class ResMutInstance<T> {
private value_: T;
private readonly setter_: (v: T) => void;
diff --git a/sdk/src/types.ts b/sdk/src/types.ts
index c07a9dbd1..cb25b056a 100644
--- a/sdk/src/types.ts
+++ b/sdk/src/types.ts
@@ -23,6 +23,8 @@
*
* The value is transported across the WASM boundary as a plain u32 and used
* directly as a Map/Set key on the JS side.
+ *
+ * @public
*/
export type Entity = number;
diff --git a/sdk/tests/ecs-vocabulary.test.ts b/sdk/tests/ecs-vocabulary.test.ts
index 8f0e4baa5..2c1c8fafd 100644
--- a/sdk/tests/ecs-vocabulary.test.ts
+++ b/sdk/tests/ecs-vocabulary.test.ts
@@ -11,7 +11,7 @@ import { describe, it, expect } from 'vitest';
import {
defineComponent, defineSystem, defineResource, defineEvent, Query, Mut, Res, ResMut,
Commands, With, Without, And, Or, Not, Added, Changed, Removed,
- EventReader, EventWriter, GetWorld, Transform,
+ EventReader, EventWriter, GetWorld, Transform, World, QueryInstance,
} from '../src/core';
import type {
AnyComponentDef, BuiltinComponentDef, ComponentDef, ComponentMetadata, FieldMeta,
@@ -20,6 +20,7 @@ import type {
ResourceDef, ResDescriptor, ResMutDescriptor, CommandsDescriptor, QueryArg,
EventReaderDescriptor, EventWriterDescriptor, GetWorldDescriptor,
SystemDef, SystemOptions, SystemParam, InferParam, InferParams,
+ Entity, QueryResult,
} from '../src/core';
const Position = defineComponent('VocabPosition', { x: 0, y: 0 });
@@ -90,6 +91,21 @@ describe('query vocabulary', () => {
expect(q._filter).toEqual({ kind: 'with', component: Position });
});
+ it('QueryResult is the entity followed by the components asked for', () => {
+ const world = new World();
+ const e = world.spawn();
+ world.insert(e, Position, { x: 3, y: 4 });
+ world.insert(e, Health, { hp: 20 });
+ const rows: QueryResult<[typeof Position, typeof Health]>[] =
+ new QueryInstance(world, Query(Position, Health)).toArray();
+ expect(rows).toHaveLength(1);
+ const [entity, position, health] = rows[0];
+ const id: Entity = entity;
+ expect(id).toBe(e);
+ expect(position).toEqual({ x: 3, y: 4 });
+ expect(health).toEqual({ hp: 20 });
+ });
+
it('FilterExpr composes and stays readable without running the query', () => {
const expr: FilterExpr = And(With(Position), Or(Without(Health), Not(With(Health))));
expect(expr.kind).toBe('and');
diff --git a/tools/api-surface.mjs b/tools/api-surface.mjs
index 0b030718a..fec1aa981 100644
--- a/tools/api-surface.mjs
+++ b/tools/api-surface.mjs
@@ -154,7 +154,10 @@ function fileLevelTier(sourceFile) {
const text = sourceFile.getFullText();
for (const range of ts.getLeadingCommentRanges(text, 0) ?? []) {
const comment = text.slice(range.pos, range.end);
- if (!comment.startsWith('/**')) continue;
+ // Every comment before the first token is "leading", so the doc on a
+ // file's first declaration is in here too. `@file` is what makes one a
+ // header, and tagging that declaration is not tagging the module.
+ if (!comment.startsWith('/**') || !/@file\b/.test(comment)) continue;
if (/^\s*\*\s*@public\b/m.test(comment)) {
const where = relative(ROOT, sourceFile.fileName).replace(/\\/g, '/');
errors.push(`R4: '${where}' claims @public in its @file header — tag the declaration, a header does not reach the .d.ts`);
@@ -204,8 +207,20 @@ function isAmbientMember(member) {
return decls.every((d) => d.getSourceFile().fileName.replace(/\\/g, '/').includes('/node_modules/'));
}
+/** A well-known symbol member — `__@iterator@16`, whose trailing id is a checker
+ * counter and therefore not stable enough to put in a snapshot. */
+const WELL_KNOWN_SYMBOL = /^__@(\w+)@\d+$/;
+
+/** `[Symbol.iterator]`, so `for…of` is part of the recorded surface. */
+function memberName(member) {
+ const wellKnown = WELL_KNOWN_SYMBOL.exec(member.escapedName?.toString() ?? '');
+ return wellKnown ? `[Symbol.${wellKnown[1]}]` : member.name;
+}
+
function isPrivateMember(member) {
- if (member.escapedName?.toString().startsWith('__')) return true;
+ const escaped = member.escapedName?.toString() ?? '';
+ if (WELL_KNOWN_SYMBOL.test(escaped)) return false;
+ if (escaped.startsWith('__')) return true;
for (const decl of member.declarations ?? []) {
if (decl.name && ts.isPrivateIdentifier(decl.name)) return true;
const mods = ts.canHaveModifiers(decl) ? ts.getModifiers(decl) : undefined;
@@ -232,7 +247,7 @@ function memberLines(type, location, owner) {
// public .d.ts unannounced. Marked here, in the shipped .d.ts, and skipped by
// the leak and baseline rules: it is present, and it promises nothing.
const mark = tagNames(member).has('internal') ? '@internal ' : '';
- lines.push(`${mark}${member.name}: ${normalizeType(checker.typeToString(memberType, location, FMT))}`);
+ lines.push(`${mark}${memberName(member)}: ${normalizeType(checker.typeToString(memberType, location, FMT))}`);
}
return lines.sort();
}
diff --git a/tools/check-freeze-bar.mjs b/tools/check-freeze-bar.mjs
index 9afa6ed0a..9ff1da22e 100644
--- a/tools/check-freeze-bar.mjs
+++ b/tools/check-freeze-bar.mjs
@@ -30,8 +30,22 @@ import { ROOT, SDK, ETC, ts, ENTRIES, createSdkProgram, leadingDoc, docProseLine
import { parseSnapshot } from './lib/apiSnapshot.mjs';
import { GOLDEN, projectDir } from './goldenProjects.mjs';
-/** Frozen symbols that cannot meet part of the bar, and why. */
-export const EXEMPT = {};
+/**
+ * Frozen symbols that cannot meet part of the bar, and why. Every one here is a
+ * class a system body is HANDED by a declared parameter, so a game never writes
+ * its name and no import list can show it — while every golden project runs one
+ * every frame. The criterion is blind to them, not unmet by them.
+ */
+const RECEIVED = 'received from a declared parameter, never imported — golden projects run it, no import list names it';
+export const EXEMPT = {
+ CommandsInstance: RECEIVED,
+ EntityCommands: RECEIVED,
+ EventReaderInstance: RECEIVED,
+ EventWriterInstance: RECEIVED,
+ QueryInstance: RECEIVED,
+ RemovedQueryInstance: RECEIVED,
+ ResMutInstance: RECEIVED,
+};
/** Snapshot kinds that a game calls at runtime; the rest are shapes. */
const VALUE_KINDS = new Set(['class', 'enum', 'function', 'const', 'value', 'namespace']);
@@ -183,8 +197,12 @@ for (const [name, kind] of [...frozen].sort()) {
failures.push({ name, say: `${missing.join(', ')}`, where });
}
-for (const [name, why] of Object.entries(EXEMPT)) {
- if (!frozen.has(name)) failures.push({ name, say: `is exempt from the freeze bar but is not @public — ${why}` });
+// Not in --why: that mode is asked about a chosen few, so every other exemption
+// would read as an inconsistency it did not ask about.
+if (!asked.length) {
+ for (const [name, why] of Object.entries(EXEMPT)) {
+ if (!frozen.has(name)) failures.push({ name, say: `is exempt from the freeze bar but is not @public — ${why}` });
+ }
}
if (asked.length) {
diff --git a/tools/check-tier-leaks.mjs b/tools/check-tier-leaks.mjs
index d8900006c..7ce411a8e 100644
--- a/tools/check-tier-leaks.mjs
+++ b/tools/check-tier-leaks.mjs
@@ -27,11 +27,15 @@ import { parseSnapshot } from './lib/apiSnapshot.mjs';
* one is the ECS vocabulary the six Wave 1 symbols are written in — descriptors,
* defs and the parameter union — none of which has been through the freeze bar.
*/
+// World carries the host's binding seam (connectCpp, getCppRegistry), so
+// freezing it would freeze that too, and 0.50 deliberately does not.
+const WORLD = 'names World, which is not frozen while it carries the host binding seam';
+
export const ACCEPTED = {
- // A game is HANDED the instance classes and never imports one, so no golden
- // import list names them and the bar cannot see them run. World is separate:
- // it carries the host's binding seam, and freezing it would freeze that.
- InferParam: 'the instance classes it resolves to, and World, are not frozen yet',
+ CommandsInstance: WORLD,
+ InferParam: WORLD,
+ QueryInstance: WORLD,
+ RemovedQueryInstance: WORLD,
};
/** Every symbol across every entry, keeping the strongest tier any entry gives it. */