@oasys/oecs 0.3.1 → 0.5.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 (324) hide show
  1. package/CHANGELOG.md +553 -0
  2. package/README.md +207 -267
  3. package/dist/core/ecs/access_check.d.cts +77 -0
  4. package/dist/core/ecs/access_check.d.ts +77 -0
  5. package/dist/core/ecs/access_check.d.ts.map +1 -0
  6. package/dist/core/ecs/archetype.d.cts +486 -0
  7. package/dist/core/ecs/archetype.d.ts +486 -0
  8. package/dist/core/ecs/archetype.d.ts.map +1 -0
  9. package/dist/core/ecs/archetype_graph.d.cts +96 -0
  10. package/dist/core/ecs/archetype_graph.d.ts +96 -0
  11. package/dist/core/ecs/archetype_graph.d.ts.map +1 -0
  12. package/dist/core/ecs/builtin_relations.d.cts +43 -0
  13. package/dist/core/ecs/builtin_relations.d.ts +43 -0
  14. package/dist/core/ecs/builtin_relations.d.ts.map +1 -0
  15. package/dist/core/ecs/command_log.d.cts +116 -0
  16. package/dist/core/ecs/command_log.d.ts +116 -0
  17. package/dist/core/ecs/command_log.d.ts.map +1 -0
  18. package/dist/core/ecs/component.d.cts +176 -0
  19. package/dist/core/ecs/component.d.ts +176 -0
  20. package/dist/core/ecs/component.d.ts.map +1 -0
  21. package/dist/core/ecs/compute_backend.d.cts +37 -0
  22. package/dist/core/ecs/compute_backend.d.ts +37 -0
  23. package/dist/core/ecs/compute_backend.d.ts.map +1 -0
  24. package/dist/core/ecs/debug_names.d.cts +7 -0
  25. package/dist/core/ecs/debug_names.d.ts +7 -0
  26. package/dist/core/ecs/debug_names.d.ts.map +1 -0
  27. package/dist/core/ecs/deferred_commands.d.cts +55 -0
  28. package/dist/core/ecs/deferred_commands.d.ts +55 -0
  29. package/dist/core/ecs/deferred_commands.d.ts.map +1 -0
  30. package/dist/core/ecs/dispatch_trace.d.cts +93 -0
  31. package/dist/core/ecs/dispatch_trace.d.ts +93 -0
  32. package/dist/core/ecs/dispatch_trace.d.ts.map +1 -0
  33. package/dist/core/ecs/ecs.d.cts +562 -0
  34. package/dist/core/ecs/ecs.d.ts +562 -0
  35. package/dist/core/ecs/ecs.d.ts.map +1 -0
  36. package/dist/core/ecs/ecs_memory.d.cts +179 -0
  37. package/dist/core/ecs/ecs_memory.d.ts +179 -0
  38. package/dist/core/ecs/ecs_memory.d.ts.map +1 -0
  39. package/dist/core/ecs/entity.d.cts +34 -0
  40. package/dist/core/ecs/entity.d.ts +34 -0
  41. package/dist/core/ecs/entity.d.ts.map +1 -0
  42. package/dist/core/ecs/entity_allocator.d.cts +59 -0
  43. package/dist/core/ecs/entity_allocator.d.ts +59 -0
  44. package/dist/core/ecs/entity_allocator.d.ts.map +1 -0
  45. package/dist/core/ecs/event.d.cts +79 -0
  46. package/dist/core/ecs/event.d.ts +79 -0
  47. package/dist/core/ecs/event.d.ts.map +1 -0
  48. package/dist/core/ecs/event_registry.d.cts +22 -0
  49. package/dist/core/ecs/event_registry.d.ts +22 -0
  50. package/dist/core/ecs/event_registry.d.ts.map +1 -0
  51. package/dist/core/ecs/facades.d.cts +158 -0
  52. package/dist/core/ecs/facades.d.ts +158 -0
  53. package/dist/core/ecs/facades.d.ts.map +1 -0
  54. package/dist/core/ecs/frame_stepper.d.cts +58 -0
  55. package/dist/core/ecs/frame_stepper.d.ts +58 -0
  56. package/dist/core/ecs/frame_stepper.d.ts.map +1 -0
  57. package/dist/core/ecs/frame_trace.d.cts +133 -0
  58. package/dist/core/ecs/frame_trace.d.ts +133 -0
  59. package/dist/core/ecs/frame_trace.d.ts.map +1 -0
  60. package/dist/core/ecs/host_commands.d.cts +274 -0
  61. package/dist/core/ecs/host_commands.d.ts +274 -0
  62. package/dist/core/ecs/host_commands.d.ts.map +1 -0
  63. package/dist/core/ecs/index.d.cts +46 -0
  64. package/dist/core/ecs/index.d.ts +46 -0
  65. package/dist/core/ecs/index.d.ts.map +1 -0
  66. package/dist/core/ecs/observer.d.cts +173 -0
  67. package/dist/core/ecs/observer.d.ts +173 -0
  68. package/dist/core/ecs/observer.d.ts.map +1 -0
  69. package/dist/core/ecs/query.d.cts +718 -0
  70. package/dist/core/ecs/query.d.ts +718 -0
  71. package/dist/core/ecs/query.d.ts.map +1 -0
  72. package/dist/core/ecs/ref.d.cts +31 -0
  73. package/dist/core/ecs/ref.d.ts +31 -0
  74. package/dist/core/ecs/ref.d.ts.map +1 -0
  75. package/dist/core/ecs/relation.d.cts +243 -0
  76. package/dist/core/ecs/relation.d.ts +243 -0
  77. package/dist/core/ecs/relation.d.ts.map +1 -0
  78. package/dist/core/ecs/relation_service.d.cts +235 -0
  79. package/dist/core/ecs/relation_service.d.ts +235 -0
  80. package/dist/core/ecs/relation_service.d.ts.map +1 -0
  81. package/dist/core/ecs/resource.d.cts +53 -0
  82. package/dist/core/ecs/resource.d.ts +53 -0
  83. package/dist/core/ecs/resource.d.ts.map +1 -0
  84. package/dist/core/ecs/resource_registry.d.cts +20 -0
  85. package/dist/core/ecs/resource_registry.d.ts +20 -0
  86. package/dist/core/ecs/resource_registry.d.ts.map +1 -0
  87. package/dist/core/ecs/resume.d.cts +85 -0
  88. package/dist/core/ecs/resume.d.ts +85 -0
  89. package/dist/core/ecs/resume.d.ts.map +1 -0
  90. package/dist/core/ecs/run_condition.d.cts +81 -0
  91. package/dist/core/ecs/run_condition.d.ts +81 -0
  92. package/dist/core/ecs/run_condition.d.ts.map +1 -0
  93. package/dist/core/ecs/schedule.d.cts +142 -0
  94. package/dist/core/ecs/schedule.d.ts +142 -0
  95. package/dist/core/ecs/schedule.d.ts.map +1 -0
  96. package/dist/core/ecs/snapshot_service.d.cts +94 -0
  97. package/dist/core/ecs/snapshot_service.d.ts +94 -0
  98. package/dist/core/ecs/snapshot_service.d.ts.map +1 -0
  99. package/dist/core/ecs/sparse_store.d.cts +110 -0
  100. package/dist/core/ecs/sparse_store.d.ts +110 -0
  101. package/dist/core/ecs/sparse_store.d.ts.map +1 -0
  102. package/dist/core/ecs/store.d.cts +950 -0
  103. package/dist/core/ecs/store.d.ts +950 -0
  104. package/dist/core/ecs/store.d.ts.map +1 -0
  105. package/dist/core/ecs/store_layout_listener.d.cts +23 -0
  106. package/dist/core/ecs/store_layout_listener.d.ts +23 -0
  107. package/dist/core/ecs/store_layout_listener.d.ts.map +1 -0
  108. package/dist/core/ecs/system.d.cts +250 -0
  109. package/dist/core/ecs/system.d.ts +250 -0
  110. package/dist/core/ecs/system.d.ts.map +1 -0
  111. package/dist/core/ecs/utils/arrays.d.cts +7 -0
  112. package/dist/{utils → core/ecs/utils}/arrays.d.ts +2 -1
  113. package/dist/core/ecs/utils/arrays.d.ts.map +1 -0
  114. package/dist/core/ecs/utils/constants.d.ts +12 -0
  115. package/dist/core/ecs/utils/constants.d.ts.map +1 -0
  116. package/dist/core/ecs/utils/error.d.cts +61 -0
  117. package/dist/core/ecs/utils/error.d.ts +61 -0
  118. package/dist/core/ecs/utils/error.d.ts.map +1 -0
  119. package/dist/core/store/action_ring.d.cts +136 -0
  120. package/dist/core/store/action_ring.d.ts +136 -0
  121. package/dist/core/store/action_ring.d.ts.map +1 -0
  122. package/dist/core/store/allocator.d.cts +238 -0
  123. package/dist/core/store/allocator.d.ts +238 -0
  124. package/dist/core/store/allocator.d.ts.map +1 -0
  125. package/dist/core/store/buffer_backed_column.d.cts +69 -0
  126. package/dist/core/store/buffer_backed_column.d.ts +69 -0
  127. package/dist/core/store/buffer_backed_column.d.ts.map +1 -0
  128. package/dist/core/store/column_store.d.cts +273 -0
  129. package/dist/core/store/column_store.d.ts +273 -0
  130. package/dist/core/store/column_store.d.ts.map +1 -0
  131. package/dist/core/store/command_dispatch.d.cts +52 -0
  132. package/dist/core/store/command_dispatch.d.ts +52 -0
  133. package/dist/core/store/command_dispatch.d.ts.map +1 -0
  134. package/dist/core/store/command_ring.d.cts +107 -0
  135. package/dist/core/store/command_ring.d.ts +107 -0
  136. package/dist/core/store/command_ring.d.ts.map +1 -0
  137. package/dist/core/store/descriptor.d.cts +80 -0
  138. package/dist/core/store/descriptor.d.ts +80 -0
  139. package/dist/core/store/descriptor.d.ts.map +1 -0
  140. package/dist/core/store/entity_index.d.cts +108 -0
  141. package/dist/core/store/entity_index.d.ts +108 -0
  142. package/dist/core/store/entity_index.d.ts.map +1 -0
  143. package/dist/core/store/event_ring.d.cts +95 -0
  144. package/dist/core/store/event_ring.d.ts +95 -0
  145. package/dist/core/store/event_ring.d.ts.map +1 -0
  146. package/dist/core/store/extend.d.cts +39 -0
  147. package/dist/core/store/extend.d.ts +39 -0
  148. package/dist/core/store/extend.d.ts.map +1 -0
  149. package/dist/core/store/grow.d.cts +34 -0
  150. package/dist/core/store/grow.d.ts +34 -0
  151. package/dist/core/store/grow.d.ts.map +1 -0
  152. package/dist/core/store/header.d.cts +64 -0
  153. package/dist/core/store/header.d.ts +64 -0
  154. package/dist/core/store/header.d.ts.map +1 -0
  155. package/dist/core/store/index.d.cts +17 -0
  156. package/dist/core/store/index.d.ts +17 -0
  157. package/dist/core/store/index.d.ts.map +1 -0
  158. package/dist/core/store/layout_ops.d.cts +152 -0
  159. package/dist/core/store/layout_ops.d.ts +152 -0
  160. package/dist/core/store/layout_ops.d.ts.map +1 -0
  161. package/dist/core/store/region_table.d.cts +74 -0
  162. package/dist/core/store/region_table.d.ts +74 -0
  163. package/dist/core/store/region_table.d.ts.map +1 -0
  164. package/dist/core/store/snapshot.d.cts +43 -0
  165. package/dist/core/store/snapshot.d.ts +43 -0
  166. package/dist/core/store/snapshot.d.ts.map +1 -0
  167. package/dist/core/store/state_hash.d.cts +38 -0
  168. package/dist/core/store/state_hash.d.ts +38 -0
  169. package/dist/core/store/state_hash.d.ts.map +1 -0
  170. package/dist/core/store/store_regions.d.cts +38 -0
  171. package/dist/core/store/store_regions.d.ts +38 -0
  172. package/dist/core/store/store_regions.d.ts.map +1 -0
  173. package/dist/core/store/vendored_abi/abi.d.cts +43 -0
  174. package/dist/core/store/vendored_abi/abi.d.ts +43 -0
  175. package/dist/core/store/vendored_abi/abi.d.ts.map +1 -0
  176. package/dist/dev_flag.d.cts +17 -0
  177. package/dist/dev_flag.d.ts +17 -0
  178. package/dist/dev_flag.d.ts.map +1 -0
  179. package/dist/extensions/editor/editor.d.cts +170 -0
  180. package/dist/extensions/editor/editor.d.ts +170 -0
  181. package/dist/extensions/editor/editor.d.ts.map +1 -0
  182. package/dist/extensions/editor/field_handle.d.cts +40 -0
  183. package/dist/extensions/editor/field_handle.d.ts +40 -0
  184. package/dist/extensions/editor/field_handle.d.ts.map +1 -0
  185. package/dist/extensions/editor/index.cjs +1 -0
  186. package/dist/extensions/editor/index.d.cts +21 -0
  187. package/dist/extensions/editor/index.d.ts +21 -0
  188. package/dist/extensions/editor/index.d.ts.map +1 -0
  189. package/dist/extensions/editor/index.js +237 -0
  190. package/dist/extensions/reactive/ecs_sync.d.cts +214 -0
  191. package/dist/extensions/reactive/ecs_sync.d.ts +214 -0
  192. package/dist/extensions/reactive/ecs_sync.d.ts.map +1 -0
  193. package/dist/extensions/reactive/index.cjs +1 -0
  194. package/dist/extensions/reactive/index.d.cts +23 -0
  195. package/dist/extensions/reactive/index.d.ts +23 -0
  196. package/dist/extensions/reactive/index.d.ts.map +1 -0
  197. package/dist/extensions/reactive/index.js +215 -0
  198. package/dist/extensions/solid/index.cjs +1 -0
  199. package/dist/extensions/solid/index.d.cts +6 -0
  200. package/dist/extensions/solid/index.d.ts +6 -0
  201. package/dist/extensions/solid/index.d.ts.map +1 -0
  202. package/dist/extensions/solid/index.js +36 -0
  203. package/dist/extensions/solid/kernel_solid.d.cts +45 -0
  204. package/dist/extensions/solid/kernel_solid.d.ts +45 -0
  205. package/dist/extensions/solid/kernel_solid.d.ts.map +1 -0
  206. package/dist/host_commands-BF8QMi3c.cjs +1 -0
  207. package/dist/host_commands-i4cAeyL5.js +2318 -0
  208. package/dist/index.cjs +1 -1
  209. package/dist/index.d.cts +66 -0
  210. package/dist/index.d.ts +65 -12
  211. package/dist/index.d.ts.map +1 -1
  212. package/dist/index.js +7080 -1289
  213. package/dist/internal.cjs +2 -0
  214. package/dist/internal.d.cts +20 -0
  215. package/dist/internal.d.ts +20 -0
  216. package/dist/internal.d.ts.map +1 -0
  217. package/dist/internal.js +141 -0
  218. package/dist/interop-CT-REx0W.cjs +1 -0
  219. package/dist/interop-CcY6ASQc.js +18 -0
  220. package/dist/kernel-DgyrLFjW.js +227 -0
  221. package/dist/kernel-yWV3XnAb.cjs +1 -0
  222. package/dist/primitives.cjs +1 -0
  223. package/dist/primitives.d.cts +18 -0
  224. package/dist/primitives.d.ts +18 -0
  225. package/dist/primitives.d.ts.map +1 -0
  226. package/dist/primitives.js +45 -0
  227. package/dist/reactive/array.d.cts +24 -0
  228. package/dist/reactive/array.d.ts +24 -0
  229. package/dist/reactive/array.d.ts.map +1 -0
  230. package/dist/reactive/index.cjs +1 -0
  231. package/dist/reactive/index.d.cts +11 -0
  232. package/dist/reactive/index.d.ts +11 -0
  233. package/dist/reactive/index.d.ts.map +1 -0
  234. package/dist/reactive/index.js +18 -0
  235. package/dist/reactive/interop.d.cts +19 -0
  236. package/dist/reactive/interop.d.ts +19 -0
  237. package/dist/reactive/interop.d.ts.map +1 -0
  238. package/dist/reactive/kernel.d.cts +73 -0
  239. package/dist/reactive/kernel.d.ts +73 -0
  240. package/dist/reactive/kernel.d.ts.map +1 -0
  241. package/dist/reactive/map.d.cts +16 -0
  242. package/dist/reactive/map.d.ts +16 -0
  243. package/dist/reactive/map.d.ts.map +1 -0
  244. package/dist/reactive/shallow.d.cts +11 -0
  245. package/dist/reactive/shallow.d.ts +11 -0
  246. package/dist/reactive/shallow.d.ts.map +1 -0
  247. package/dist/reactive/struct.d.cts +10 -0
  248. package/dist/reactive/struct.d.ts +10 -0
  249. package/dist/reactive/struct.d.ts.map +1 -0
  250. package/dist/shallow-DQ8aG51_.cjs +1 -0
  251. package/dist/shallow-DfnAm9vG.js +150 -0
  252. package/dist/shared-BU1Cd40h.js +103 -0
  253. package/dist/shared-BymrGTyR.cjs +1 -0
  254. package/dist/shared.cjs +1 -0
  255. package/dist/shared.d.cts +22 -0
  256. package/dist/shared.d.ts +22 -0
  257. package/dist/shared.d.ts.map +1 -0
  258. package/dist/shared.js +7 -0
  259. package/dist/topological_sort-BDvEyb9W.cjs +1 -0
  260. package/dist/topological_sort-DK6EjpWa.js +135 -0
  261. package/dist/type_primitives/assertions.d.cts +32 -0
  262. package/dist/type_primitives/assertions.d.ts +25 -9
  263. package/dist/type_primitives/assertions.d.ts.map +1 -1
  264. package/dist/type_primitives/binary_heap/binary_heap.d.cts +37 -0
  265. package/dist/type_primitives/binary_heap/binary_heap.d.ts +6 -2
  266. package/dist/type_primitives/binary_heap/binary_heap.d.ts.map +1 -1
  267. package/dist/type_primitives/bitset/bitset.d.cts +54 -0
  268. package/dist/type_primitives/bitset/bitset.d.ts +16 -4
  269. package/dist/type_primitives/bitset/bitset.d.ts.map +1 -1
  270. package/dist/type_primitives/brand.d.cts +23 -0
  271. package/dist/type_primitives/brand.d.ts +6 -1
  272. package/dist/type_primitives/brand.d.ts.map +1 -1
  273. package/dist/type_primitives/error.d.cts +16 -0
  274. package/dist/type_primitives/error.d.ts +8 -3
  275. package/dist/type_primitives/error.d.ts.map +1 -1
  276. package/dist/type_primitives/index.d.cts +13 -0
  277. package/dist/type_primitives/index.d.ts +12 -9
  278. package/dist/type_primitives/index.d.ts.map +1 -1
  279. package/dist/type_primitives/sparse_map/sparse_map.d.cts +30 -0
  280. package/dist/type_primitives/sparse_map/sparse_map.d.ts +7 -3
  281. package/dist/type_primitives/sparse_map/sparse_map.d.ts.map +1 -1
  282. package/dist/type_primitives/sparse_set/sparse_set.d.cts +28 -0
  283. package/dist/type_primitives/sparse_set/sparse_set.d.ts +4 -0
  284. package/dist/type_primitives/sparse_set/sparse_set.d.ts.map +1 -1
  285. package/dist/type_primitives/topological_sort/topological_sort.d.cts +29 -0
  286. package/dist/type_primitives/topological_sort/topological_sort.d.ts +7 -3
  287. package/dist/type_primitives/topological_sort/topological_sort.d.ts.map +1 -1
  288. package/dist/type_primitives/typed_arrays/typed_arrays.d.cts +127 -0
  289. package/dist/type_primitives/typed_arrays/typed_arrays.d.ts +53 -16
  290. package/dist/type_primitives/typed_arrays/typed_arrays.d.ts.map +1 -1
  291. package/dist/typed_arrays-BcXcnzB4.js +258 -0
  292. package/dist/typed_arrays-D3NmwtCG.cjs +1 -0
  293. package/dist/utils/error.d.cts +6 -0
  294. package/dist/utils/error.d.ts +2 -20
  295. package/dist/utils/error.d.ts.map +1 -1
  296. package/dist/version.d.cts +10 -0
  297. package/dist/version.d.ts +10 -0
  298. package/dist/version.d.ts.map +1 -0
  299. package/package.json +115 -5
  300. package/dist/archetype.d.ts +0 -108
  301. package/dist/archetype.d.ts.map +0 -1
  302. package/dist/component.d.ts +0 -45
  303. package/dist/component.d.ts.map +0 -1
  304. package/dist/ecs.d.ts +0 -104
  305. package/dist/ecs.d.ts.map +0 -1
  306. package/dist/entity.d.ts +0 -11
  307. package/dist/entity.d.ts.map +0 -1
  308. package/dist/event.d.ts +0 -30
  309. package/dist/event.d.ts.map +0 -1
  310. package/dist/query.d.ts +0 -94
  311. package/dist/query.d.ts.map +0 -1
  312. package/dist/ref.d.ts +0 -23
  313. package/dist/ref.d.ts.map +0 -1
  314. package/dist/resource.d.ts +0 -23
  315. package/dist/resource.d.ts.map +0 -1
  316. package/dist/schedule.d.ts +0 -45
  317. package/dist/schedule.d.ts.map +0 -1
  318. package/dist/store.d.ts +0 -118
  319. package/dist/store.d.ts.map +0 -1
  320. package/dist/system.d.ts +0 -16
  321. package/dist/system.d.ts.map +0 -1
  322. package/dist/utils/arrays.d.ts.map +0 -1
  323. package/dist/utils/constants.d.ts.map +0 -1
  324. /package/dist/{utils/constants.d.ts → core/ecs/utils/constants.d.cts} +0 -0
@@ -0,0 +1,274 @@
1
+ import { ComponentDef, ComponentSchema, CompleteFieldValues, FieldValues } from './component.js';
2
+ import { ECS } from './ecs.js';
3
+ import { EntityID } from './entity.js';
4
+ import { SystemContext } from './query.js';
5
+ import { SCHEDULE } from './schedule.js';
6
+ import { PayloadCodec } from '../store/index.js';
7
+ /** One component to attach to a freshly spawned entity. `values` are required
8
+ * and complete as a *strictness* choice, not a runtime need: since #716 every
9
+ * attach path (deferred included — `writeFields`'s `?? 0`) zero-fills omitted
10
+ * fields, same as templates. A host command is a reified, replayable record,
11
+ * so it carries explicit intent for every field rather than relying on the
12
+ * zero-fill; a tag component takes `{}`. Build type-safely with `spawnEntry`. */
13
+ export interface SpawnEntry {
14
+ readonly def: ComponentDef;
15
+ readonly values: FieldValues<ComponentSchema>;
16
+ }
17
+ /** Extracts the schema out of a `ComponentDef` handle. */
18
+ type SchemaOf<D extends ComponentDef> = D extends ComponentDef<infer S> ? S : ComponentSchema;
19
+ /** One schema-checked spawn entry: `values` is complete for its own def (see
20
+ * the `SpawnEntry` doc — explicit intent per field, though the attach path
21
+ * zero-fills since #716), and a tag takes exactly `{}`. */
22
+ export type SpawnEntryFor<D extends ComponentDef> = {
23
+ readonly def: D;
24
+ readonly values: CompleteFieldValues<SchemaOf<D>>;
25
+ };
26
+ /** The entries tuple for `HostCommandQueue.spawn` — each element's `values` is
27
+ * checked against its own `def`'s schema. Unlike `TemplateEntries` (which
28
+ * stays `Partial` — a template is a reusable default set), a host command
29
+ * demands complete values: it is a reified, replayable record, so every
30
+ * field is explicit even though the attach path would zero-fill (#716). */
31
+ export type SpawnEntries<Defs extends readonly ComponentDef[]> = readonly [
32
+ ...{
33
+ [K in keyof Defs]: SpawnEntryFor<Defs[K]>;
34
+ }
35
+ ];
36
+ /** Type-checked `SpawnEntry` constructor — keeps `values` aligned to `def`'s
37
+ * schema at the call site even though the stored entry is schema-erased. */
38
+ export declare function spawnEntry<S extends ComponentSchema>(def: ComponentDef<S>, values: CompleteFieldValues<S>): SpawnEntry;
39
+ /**
40
+ * A single world mutation, as plain data. Every transport (typed queue today, a
41
+ * SAB ring codec tomorrow) and every consumer (editor undo, record/replay)
42
+ * speaks this one vocabulary, applied by the one `applyHostCommand` dispatch.
43
+ *
44
+ * Component fields are `string` / `def: ComponentDef` (schema-erased) so the
45
+ * union stays flat; the typed `HostCommandQueue` methods preserve type-safety at
46
+ * the enqueue site. `applyHostCommand` re-applies them through `SystemContext`,
47
+ * which type-checks because `ComponentDef` defaults its schema to
48
+ * `ComponentSchema` (whose `keyof` is `string`).
49
+ */
50
+ export type HostCommand = {
51
+ readonly kind: "spawn";
52
+ readonly components: readonly SpawnEntry[];
53
+ /** Fired with the new id once the spawn applies (the id only exists
54
+ * after the deferred create) — lets a producer/editor learn it. */
55
+ readonly onSpawned?: (eid: EntityID) => void;
56
+ } | {
57
+ readonly kind: "despawn";
58
+ readonly eid: EntityID;
59
+ } | {
60
+ readonly kind: "add_component";
61
+ readonly eid: EntityID;
62
+ readonly def: ComponentDef;
63
+ readonly values: FieldValues<ComponentSchema>;
64
+ } | {
65
+ readonly kind: "remove_component";
66
+ readonly eid: EntityID;
67
+ readonly def: ComponentDef;
68
+ } | {
69
+ readonly kind: "set_field";
70
+ readonly eid: EntityID;
71
+ readonly def: ComponentDef;
72
+ readonly field: string;
73
+ readonly value: number;
74
+ } | {
75
+ readonly kind: "disable";
76
+ readonly eid: EntityID;
77
+ } | {
78
+ readonly kind: "enable";
79
+ readonly eid: EntityID;
80
+ };
81
+ /**
82
+ * THE ONE APPLY DISPATCH. Maps a `HostCommand` onto `SystemContext` ops. Only
83
+ * ever called from inside the blessed apply system, which holds the `ctx` and is
84
+ * `exclusive` (full access). Structural changes (`spawn`/`despawn`/component
85
+ * add-remove) are deferred to the phase flush, exactly like a normal system's;
86
+ * `setField` is immediate and bumps the change-tick. Returns the new entity for
87
+ * `spawn`, otherwise `undefined`.
88
+ *
89
+ * That immediate/deferred split is a sharp edge: a `setField` targeting a
90
+ * component the entity does NOT yet have — because an `addComponent`/`spawn`
91
+ * enqueued in the SAME drain is still pending its flush — would otherwise fail
92
+ * deep in `getColumn` with an opaque "component not registered". The `DEV`
93
+ * guard below turns that into an actionable message. The fix is structural, not a
94
+ * retry: pass the value in `addComponent`/`spawnEntry` (which carries complete
95
+ * field values), or issue the `setField` on a later frame.
96
+ */
97
+ export declare function applyHostCommand(ctx: SystemContext, cmd: HostCommand): EntityID | undefined;
98
+ /**
99
+ * The host-facing write handle. Mutating methods ENQUEUE (off-schedule, pure);
100
+ * nothing reaches the world until the apply system drains it at the next
101
+ * schedule head. Mirrors Bevy's `Commands` ergonomics over the flat `HostCommand`
102
+ * vocabulary. The returned-from-`installHostCommandSeam` instance is the
103
+ * write counterpart to the reactive bridge's returned `reactiveMap`.
104
+ */
105
+ export declare class HostCommandQueue {
106
+ private readonly queued;
107
+ /** Spawn an entity carrying `components`. `onSpawned` receives the new id
108
+ * once the spawn applies. Each entry's `values` is checked against its own
109
+ * `def`'s schema (`SpawnEntries`); the stored command stays schema-erased. */
110
+ spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (eid: EntityID) => void): void;
111
+ despawn(eid: EntityID): void;
112
+ addComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): void;
113
+ removeComponent(eid: EntityID, def: ComponentDef): void;
114
+ /** Set `field` of `def` on `eid`. Applied IMMEDIATELY at the drain, unlike the
115
+ * deferred structural ops — so `def` must already be on `eid`. Do NOT
116
+ * `addComponent`/`spawn` `def` and `setField` it in the same frame: the add is
117
+ * still pending its flush when the immediate set runs (carry the value in
118
+ * `addComponent`/`spawnEntry` instead). `applyHostCommand` throws an
119
+ * actionable error in `DEV` if you do. */
120
+ setField<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): void;
121
+ disable(eid: EntityID): void;
122
+ enable(eid: EntityID): void;
123
+ /** Enqueue a pre-built command. The path for a SAB-ring codec, an editor's
124
+ * reified inverse, or a replay log — all of which produce `HostCommand` data
125
+ * directly rather than calling the typed sugar above. */
126
+ push(cmd: HostCommand): void;
127
+ /** Commands buffered but not yet applied. */
128
+ pending(): number;
129
+ /** Drop every buffered command without applying it (M15) — e.g. abandoning
130
+ * queued edits on a scene unload. Returns how many were dropped. Does not
131
+ * touch commands already drained into the world. */
132
+ clear(): number;
133
+ /**
134
+ * Apply and clear every buffered command. Called by the blessed apply system
135
+ * inside its schedule span; not part of the host-facing surface. Returns the
136
+ * count applied.
137
+ *
138
+ * `tap`, when present, is invoked with each command in apply order just before
139
+ * it is applied — the record/replay hook ({@link HostCommandRecorder}). It is
140
+ * an OPT-IN observer: the tap-free path keeps the original tight loop, so an
141
+ * un-recorded drain pays nothing (#702).
142
+ */
143
+ drain(ctx: SystemContext, tap?: (cmd: HostCommand) => void): number;
144
+ }
145
+ /** Bytes of the payload region inside one `command_ring` slot (15). The slot's
146
+ * leading byte is the opCode; `COMMAND_RING_SLOT_BYTES` (16) is the whole slot. */
147
+ export declare const HOST_COMMAND_PAYLOAD_BYTES: number;
148
+ /**
149
+ * Ring codec for a `setField` on a FIXED `(def, field)`. The component + field
150
+ * are bound INTO the codec, not carried in the bytes — the consumer-owned-codec
151
+ * rule (mirroring `command_dispatch`): the engine ships the mechanism, a
152
+ * consumer's codec knows which component+field an opcode means.
153
+ *
154
+ * Payload (15 B): `[ eid: u32 LE @0 ][ value: f64 LE @4 ][ _reserved: 3 B @12 ]`
155
+ *
156
+ * `value` rides as `f64` (covers every numeric column type losslessly within
157
+ * range); the trailing 3 bytes stay zero. Packing the id as `u32` is what makes
158
+ * `setField` fit the 15-byte slot.
159
+ */
160
+ export declare function ringSetFieldCodec<S extends ComponentSchema>(def: ComponentDef<S>, field: string & keyof S): PayloadCodec<HostCommand>;
161
+ /** Ring codec for `despawn` — `[ eid: u32 LE @0 ]`, trailing 11 B reserved-zero. */
162
+ export declare function ringDespawnCodec(): PayloadCodec<HostCommand>;
163
+ /** Ring codec for `disable` — `[ eid: u32 LE @0 ]`, trailing 11 B reserved-zero. */
164
+ export declare function ringDisableCodec(): PayloadCodec<HostCommand>;
165
+ /** Ring codec for `enable` — `[ eid: u32 LE @0 ]`, trailing 11 B reserved-zero. */
166
+ export declare function ringEnableCodec(): PayloadCodec<HostCommand>;
167
+ /**
168
+ * Ring codec for `removeComponent` of a FIXED `def` — `[ eid: u32 LE @0 ]`, the
169
+ * component bound into the codec (consumer-owned-codec rule). `spawn` /
170
+ * `addComponent` are deliberately absent: they carry component field values
171
+ * that don't fit the 15-byte slot generically, so they stay typed-transport-only
172
+ * (the prototype's finding — the in-process queue has no width limit).
173
+ */
174
+ export declare function ringRemoveComponentCodec(def: ComponentDef): PayloadCodec<HostCommand>;
175
+ /** A ctx-aware applier for one ring opcode: runs on the system `ctx` (which the
176
+ * apply system holds) with the raw 15-byte payload. `tap`, when present, is the
177
+ * record/replay hook (#702) — a generic, `onCommand`-bound applier decodes the
178
+ * slot to a `HostCommand` and feeds it to `tap` before applying, so ring-sourced
179
+ * commands land in the same log as typed-queue ones. A raw `on` applier (a
180
+ * consumer's own non-`HostCommand` op, e.g. the game's `spawn_unit`) has no
181
+ * `HostCommand` to surface and simply ignores `tap`. */
182
+ export type RingCommandApplier = (ctx: SystemContext, payload: Uint8Array, tap?: (cmd: HostCommand) => void) => void;
183
+ /**
184
+ * Drains the SAB `command_ring` as the second host-command transport, dispatching
185
+ * each opcode to a bound applier. Two binding styles:
186
+ *
187
+ * - `onCommand(op, codec)` — decode the slot to a `HostCommand` and run it
188
+ * through the ONE `applyHostCommand` (the same dispatch the typed queue
189
+ * uses). This is the generic cross-thread / wire host-write path.
190
+ * - `on(op, applier)` — a raw ctx-aware handler for a consumer's OWN ring ops
191
+ * that aren't generic host commands (e.g. the game's `spawn_unit`, which runs
192
+ * a BFS placement + game spawn). Same drain, same ring: the "one bus".
193
+ *
194
+ * Opcodes + codecs are CONSUMER-supplied — the engine ships the mechanism and the
195
+ * `ring_*_codec` factories, never the opcode numbers (mirrors `command_dispatch`).
196
+ *
197
+ * Exactly ONE dispatcher should drain a given ring — a second drain would consume
198
+ * the first's slots. The in-process apply system passes its dispatcher via
199
+ * `installHostCommandSeam({ ring })`; a system that owns a timing-coupled drain
200
+ * point (e.g. `wave_spawn`, which must drain between the spatial-index build and
201
+ * the flow-field rebuild) constructs one and calls `drain` itself.
202
+ */
203
+ export declare class HostCommandDispatcher {
204
+ private readonly appliers;
205
+ /** Bind a raw ctx-aware applier to `opCode`. Re-binding replaces. */
206
+ on(opCode: number, applier: RingCommandApplier): this;
207
+ /** Unbind `opCode` (M15). Returns whether a binding was removed; subsequent
208
+ * slots carrying it hit the unknown-opcode path. */
209
+ off(opCode: number): boolean;
210
+ /** Bind a `HostCommand` codec to `opCode`: each matching slot is decoded and
211
+ * run through `applyHostCommand` — the SAME dispatch the typed queue uses.
212
+ * A drain-time `tap` (record/replay, #702) sees the decoded command before it
213
+ * applies, so ring-sourced commands share one log with the typed transport. */
214
+ onCommand(opCode: number, codec: PayloadCodec<HostCommand>): this;
215
+ /** Drain every pending slot, dispatching each to its bound applier. Unbound
216
+ * opcodes are skipped (the read head still advances — matching
217
+ * `drainCommandRing` / `CommandDispatcher`). Returns slots drained. `tap`,
218
+ * when present, is forwarded to each applier as the record/replay hook (#702);
219
+ * only `onCommand`-bound (generic `HostCommand`) opcodes surface to it. */
220
+ drain(ctx: SystemContext, view: DataView, ringOff: number, tap?: (cmd: HostCommand) => void): number;
221
+ }
222
+ /**
223
+ * A per-tick sink the apply system feeds drained commands into — the record side
224
+ * of record/replay (#702). Declared structurally HERE (not imported from
225
+ * `command_log.ts`) so the seam needs no dependency on the recorder: the one-way
226
+ * edge is `command_log` → `host_commands`, never back. {@link HostCommandRecorder}
227
+ * is the in-tree implementation.
228
+ *
229
+ * The protocol the apply system follows: at each UPDATE-phase drain it calls
230
+ * `openTick(tick, dt)` to open that tick's bucket; STARTUP-phase drains skip
231
+ * `openTick`, so seed-time commands land in the recorder's startup bucket. Then
232
+ * every applied command (both transports) is handed to `record`.
233
+ */
234
+ export interface HostCommandSink {
235
+ /** Open (or reuse) the bucket for update `tick` with its `dt`. Multiple drains
236
+ * in one tick (several update phases) reuse the one bucket. */
237
+ openTick(tick: number, dt: number): void;
238
+ /** Record one applied command, in apply order. Pre-bound so it can be passed
239
+ * straight as a drain `tap` without per-tick closure allocation. */
240
+ readonly record: (cmd: HostCommand) => void;
241
+ }
242
+ /** Options for {@link installHostCommandSeam}. */
243
+ export interface HostCommandSeamOptions {
244
+ /** Schedule phases whose head drains the queue. Default
245
+ * `[PRE_STARTUP, PRE_UPDATE]` — seed-time edits plus every frame. */
246
+ readonly schedules?: readonly SCHEDULE[];
247
+ /** Apply-system name (diagnostics). Default `"host_command_apply"`. */
248
+ readonly name?: string;
249
+ /** When provided, the apply system ALSO drains the world's SAB `command_ring`
250
+ * through this dispatcher at each schedule head — the cross-thread / wire
251
+ * transport, resolving to the same `applyHostCommand` as the typed queue.
252
+ * The ECS `Store` always allocates a ring; if one is somehow absent
253
+ * (`command_ring_off === 0`) the ring drain is a no-op. Bind opcodes with the
254
+ * `ring_*_codec` factories, or `dispatcher.on` for a consumer's own ops. */
255
+ readonly ring?: HostCommandDispatcher;
256
+ /** When provided, every command the apply system drains — from BOTH transports
257
+ * (typed queue + `onCommand`-bound ring ops) — is logged into this sink,
258
+ * tagged with the tick + `dt`, for record/replay (#702). Off by default: an
259
+ * un-recorded seam keeps the original tap-free drain and pays nothing.
260
+ * {@link HostCommandRecorder} is the in-tree sink; replay it with
261
+ * `replayCommandLog`. */
262
+ readonly recorder?: HostCommandSink;
263
+ }
264
+ /**
265
+ * Tear down a seam installed by {@link installHostCommandSeam} (M15): removes
266
+ * its apply systems from the world's schedule and clears any still-buffered
267
+ * commands. The queue itself stays usable as a buffer, but nothing drains it
268
+ * until a new seam is installed. No-op (returns `false`) if `queue` was not
269
+ * produced by `installHostCommandSeam` on this world.
270
+ */
271
+ export declare function uninstallHostCommandSeam(ecs: ECS, queue: HostCommandQueue): boolean;
272
+ export declare function installHostCommandSeam(ecs: ECS, opts?: HostCommandSeamOptions): HostCommandQueue;
273
+ export {};
274
+ //# sourceMappingURL=host_commands.d.ts.map
@@ -0,0 +1 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,aAAa,EAClB,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,MAAM,EACf,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,GAC9B,MAAM;CAOT;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,eAAe;IAC/B;mEAC+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC;wEACoE;IACpE,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,CAAC;CAC5C;AAUD,kDAAkD;AAClD,MAAM,WAAW,sBAAsB;IACtC;yEACqE;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;IACzC,uEAAuE;IACvE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;gFAK4E;IAC5E,QAAQ,CAAC,IAAI,CAAC,EAAE,qBAAqB,CAAC;IACtC;;;;;6BAKyB;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;CACpC;AAoBD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAOnF;AAED,wBAAgB,sBAAsB,CACrC,GAAG,EAAE,GAAG,EACR,IAAI,CAAC,EAAE,sBAAsB,GAC3B,gBAAgB,CA2DlB"}
@@ -0,0 +1,46 @@
1
+ export { ECS, type ECSOptions } from './ecs.cjs';
2
+ export type { ECSRelations, ECSEvents, ECSResources, ECSSnapshots } from './facades.cjs';
3
+ export { resolveECSMemory, DEFAULT_ECS_CAP_BYTES, BUDGET_GROWTH_HEADROOM, BUDGET_DEFAULT_BYTES_PER_ENTITY, BUDGET_DEFAULT_ARCHETYPES, type ECSMemoryOptions, type ResolvedECSMemory, type ECSMemoryCapContext, type EntityBudget, type WasmMemoryArm } from './ecs_memory.cjs';
4
+ export type { Template, TemplateEntry, TemplateEntries, TemplateOverrides } from './store.cjs';
5
+ export type { StoreLayoutListener } from './store_layout_listener.cjs';
6
+ export type { ComputeBackend, BackendSystemHandle } from './compute_backend.cjs';
7
+ export { SCHEDULE, type SystemEntry, type SystemOrdering, type SystemOrderingTarget, systemSet, type SystemSet, type SystemSetConfig } from './schedule.cjs';
8
+ export { type RunCondition, type ConditionContext, runIfResourceEq, runEveryNTicks, runIfAnyMatch, not, allOf, anyOf } from './run_condition.cjs';
9
+ export { SystemContext } from './query.cjs';
10
+ export type { SystemFn, SystemConfig, SystemDescriptor, SystemAccessConfig, SystemAccessDeclaration, SystemTransition } from './system.cjs';
11
+ export type { SystemAccess, DeclaredAccess, TypedSystemConfig, DeclaredRead, DeclaredWrite, DeclaredAdd, DeclaredRemove, DeclaredSparseRead, DeclaredSparseWrite, DeclaredRelationRead, DeclaredRelationWrite, DeclaredResourceRead, DeclaredResourceWrite, DespawnArg, DenseAccessDecl, SpawnsAccessDecl, DespawnsAccessDecl, TransitionsAccessDecl, SparseAccessDecl, RelationsAccessDecl, ResourcesAccessDecl } from './system.cjs';
12
+ export type { DeclaredBundleOrDef } from './query.cjs';
13
+ export { accessCheck } from './access_check.cjs';
14
+ export type { ObserverConfig, ObserverHandle, ObserverFn, ArchetypeObserverFn, StructuralObserverConfig, EntitySetObserverConfig, ArchetypeSetObserverConfig } from './observer.cjs';
15
+ export { installHostCommandSeam, uninstallHostCommandSeam, applyHostCommand, HostCommandQueue, HostCommandDispatcher, spawnEntry, ringSetFieldCodec, ringDespawnCodec, ringDisableCodec, ringEnableCodec, ringRemoveComponentCodec, HOST_COMMAND_PAYLOAD_BYTES } from './host_commands.cjs';
16
+ export type { HostCommand, SpawnEntry, SpawnEntryFor, SpawnEntries, HostCommandSeamOptions, HostCommandSink, RingCommandApplier } from './host_commands.cjs';
17
+ export { HostCommandRecorder, serializeCommandLog, deserializeCommandLog, replayCommandLog } from './command_log.cjs';
18
+ export type { CommandLog, RecordedTick, ReplayResult, ReplayOptions } from './command_log.cjs';
19
+ export { FrameTraceRecorder } from './frame_trace.cjs';
20
+ export type { FrameTraceSink, FrameTrace, FrameTraceEvent, StructuralOp, ObserverOp } from './frame_trace.cjs';
21
+ export { FrameStepper } from './frame_stepper.cjs';
22
+ export type { FrameStepperOptions } from './frame_stepper.cjs';
23
+ export { ECSRestoreError, ECS_SNAPSHOT_VERSION } from './resume.cjs';
24
+ export type { ComponentRef, ReadonlyComponentRef } from './ref.cjs';
25
+ export { Query, QueryBuilder, ChangedQuery, HIERARCHY_UNBOUNDED } from './query.cjs';
26
+ export type { HierarchyTerm } from './query.cjs';
27
+ export { ChunkColumns, Commands } from './query.cjs';
28
+ export type { ArchetypeView, ArchetypeID } from './archetype.cjs';
29
+ export type { EntityID, ReadonlyEntityIdArray } from './entity.cjs';
30
+ export { getEntityIndex } from './entity.cjs';
31
+ export { createEntityId, getEntityGeneration, MAX_INDEX, MAX_GENERATION, MAX_LIVE_GENERATION, RETIRED_GENERATION, MAX_ENTITY_ID } from './entity.cjs';
32
+ export type { ComponentDef, ComponentHandle, ComponentRegisterOptions, ComponentSchema, SchemaOf, DeclaredQueryTerm, FieldValues, CompleteFieldValues, ValuesArg, AttachValuesArg, TagToTypedArray, ColumnsForSchema, MutableColumnsForSchema, ReadonlyColumn, ReadonlyUint32Array } from './component.cjs';
33
+ export { bundle } from './component.cjs';
34
+ export type { Bundle, BundleOrDef } from './component.cjs';
35
+ export type { SparseComponentDef, SparseComponentID, SparseSchemaOf } from './sparse_store.cjs';
36
+ export { SparseRestoreError } from './sparse_store.cjs';
37
+ export type { RelationDef, RelationID, RelationCardinality, RelationOptions, OnDeleteTarget } from './relation.cjs';
38
+ export { ANY_RELATION } from './relation.cjs';
39
+ export { registerIsA, registerChildOf, type BuiltinRelationOptions } from './builtin_relations.cjs';
40
+ export type { EventReader, EventKey, EventSchema, EventShape, EventFieldsCover, EmptyEventSchema, SignalKey } from './event.cjs';
41
+ export { eventKey, signalKey } from './event.cjs';
42
+ export type { ResourceKey, ResourceValueOf } from './resource.cjs';
43
+ export { resourceKey } from './resource.cjs';
44
+ export { dispatchTrace, type DispatchTraceSnapshot, type DispatchTraceEntry } from './dispatch_trace.cjs';
45
+ export { ECSError, ECS_ERROR, isEcsError } from './utils/error.cjs';
46
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,46 @@
1
+ export { ECS, type ECSOptions } from './ecs.js';
2
+ export type { ECSRelations, ECSEvents, ECSResources, ECSSnapshots } from './facades.js';
3
+ export { resolveECSMemory, DEFAULT_ECS_CAP_BYTES, BUDGET_GROWTH_HEADROOM, BUDGET_DEFAULT_BYTES_PER_ENTITY, BUDGET_DEFAULT_ARCHETYPES, type ECSMemoryOptions, type ResolvedECSMemory, type ECSMemoryCapContext, type EntityBudget, type WasmMemoryArm } from './ecs_memory.js';
4
+ export type { Template, TemplateEntry, TemplateEntries, TemplateOverrides } from './store.js';
5
+ export type { StoreLayoutListener } from './store_layout_listener.js';
6
+ export type { ComputeBackend, BackendSystemHandle } from './compute_backend.js';
7
+ export { SCHEDULE, type SystemEntry, type SystemOrdering, type SystemOrderingTarget, systemSet, type SystemSet, type SystemSetConfig } from './schedule.js';
8
+ export { type RunCondition, type ConditionContext, runIfResourceEq, runEveryNTicks, runIfAnyMatch, not, allOf, anyOf } from './run_condition.js';
9
+ export { SystemContext } from './query.js';
10
+ export type { SystemFn, SystemConfig, SystemDescriptor, SystemAccessConfig, SystemAccessDeclaration, SystemTransition } from './system.js';
11
+ export type { SystemAccess, DeclaredAccess, TypedSystemConfig, DeclaredRead, DeclaredWrite, DeclaredAdd, DeclaredRemove, DeclaredSparseRead, DeclaredSparseWrite, DeclaredRelationRead, DeclaredRelationWrite, DeclaredResourceRead, DeclaredResourceWrite, DespawnArg, DenseAccessDecl, SpawnsAccessDecl, DespawnsAccessDecl, TransitionsAccessDecl, SparseAccessDecl, RelationsAccessDecl, ResourcesAccessDecl } from './system.js';
12
+ export type { DeclaredBundleOrDef } from './query.js';
13
+ export { accessCheck } from './access_check.js';
14
+ export type { ObserverConfig, ObserverHandle, ObserverFn, ArchetypeObserverFn, StructuralObserverConfig, EntitySetObserverConfig, ArchetypeSetObserverConfig } from './observer.js';
15
+ export { installHostCommandSeam, uninstallHostCommandSeam, applyHostCommand, HostCommandQueue, HostCommandDispatcher, spawnEntry, ringSetFieldCodec, ringDespawnCodec, ringDisableCodec, ringEnableCodec, ringRemoveComponentCodec, HOST_COMMAND_PAYLOAD_BYTES } from './host_commands.js';
16
+ export type { HostCommand, SpawnEntry, SpawnEntryFor, SpawnEntries, HostCommandSeamOptions, HostCommandSink, RingCommandApplier } from './host_commands.js';
17
+ export { HostCommandRecorder, serializeCommandLog, deserializeCommandLog, replayCommandLog } from './command_log.js';
18
+ export type { CommandLog, RecordedTick, ReplayResult, ReplayOptions } from './command_log.js';
19
+ export { FrameTraceRecorder } from './frame_trace.js';
20
+ export type { FrameTraceSink, FrameTrace, FrameTraceEvent, StructuralOp, ObserverOp } from './frame_trace.js';
21
+ export { FrameStepper } from './frame_stepper.js';
22
+ export type { FrameStepperOptions } from './frame_stepper.js';
23
+ export { ECSRestoreError, ECS_SNAPSHOT_VERSION } from './resume.js';
24
+ export type { ComponentRef, ReadonlyComponentRef } from './ref.js';
25
+ export { Query, QueryBuilder, ChangedQuery, HIERARCHY_UNBOUNDED } from './query.js';
26
+ export type { HierarchyTerm } from './query.js';
27
+ export { ChunkColumns, Commands } from './query.js';
28
+ export type { ArchetypeView, ArchetypeID } from './archetype.js';
29
+ export type { EntityID, ReadonlyEntityIdArray } from './entity.js';
30
+ export { getEntityIndex } from './entity.js';
31
+ export { createEntityId, getEntityGeneration, MAX_INDEX, MAX_GENERATION, MAX_LIVE_GENERATION, RETIRED_GENERATION, MAX_ENTITY_ID } from './entity.js';
32
+ export type { ComponentDef, ComponentHandle, ComponentRegisterOptions, ComponentSchema, SchemaOf, DeclaredQueryTerm, FieldValues, CompleteFieldValues, ValuesArg, AttachValuesArg, TagToTypedArray, ColumnsForSchema, MutableColumnsForSchema, ReadonlyColumn, ReadonlyUint32Array } from './component.js';
33
+ export { bundle } from './component.js';
34
+ export type { Bundle, BundleOrDef } from './component.js';
35
+ export type { SparseComponentDef, SparseComponentID, SparseSchemaOf } from './sparse_store.js';
36
+ export { SparseRestoreError } from './sparse_store.js';
37
+ export type { RelationDef, RelationID, RelationCardinality, RelationOptions, OnDeleteTarget } from './relation.js';
38
+ export { ANY_RELATION } from './relation.js';
39
+ export { registerIsA, registerChildOf, type BuiltinRelationOptions } from './builtin_relations.js';
40
+ export type { EventReader, EventKey, EventSchema, EventShape, EventFieldsCover, EmptyEventSchema, SignalKey } from './event.js';
41
+ export { eventKey, signalKey } from './event.js';
42
+ export type { ResourceKey, ResourceValueOf } from './resource.js';
43
+ export { resourceKey } from './resource.js';
44
+ export { dispatchTrace, type DispatchTraceSnapshot, type DispatchTraceEntry } from './dispatch_trace.js';
45
+ export { ECSError, ECS_ERROR, isEcsError } from './utils/error.js';
46
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/ecs/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAC;AAI7C,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAMrF,OAAO,EACN,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,+BAA+B,EAC/B,yBAAyB,EACzB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,MAAM,cAAc,CAAC;AAItB,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAM3F,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CA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EntityID } from './entity.cjs';
4
+ import { FrameTraceSink } from './frame_trace.cjs';
5
+ import { SystemContext } from './query.cjs';
6
+ import { StructuralObserverEvents } from './store.cjs';
7
+ import { SystemAccessDeclaration, SystemDescriptor } from './system.cjs';
8
+ /** What the observer registry needs from `Store` — the typed seam replacing
9
+ * bare underscore-convention reach-through (M1). `Store` implements this; the
10
+ * registry holds only this view, so the compiler bounds what observer dispatch
11
+ * can touch. Underscore names are kept so `Store`'s members stay one
12
+ * declaration (they read as "internal" at every other call site). */
13
+ export interface ObserverHost {
14
+ /** Current change tick — read for onSet baselines. */
15
+ readonly _tick: number;
16
+ /** Dev-only frame-trace sink (`null` when unset; always null in prod). */
17
+ readonly _trace: FrameTraceSink | null;
18
+ /** Sync a component's observation flags (add/remove/disable/enable/dirty). */
19
+ _configureComponentObservation(cid: number, hasAdd: boolean, hasRem: boolean, hasDisable: boolean, hasEnable: boolean, trackDirty: boolean): void;
20
+ /** Drain the per-entity onSet dirty list for `cid` (clears marks). */
21
+ _takeDirty(cid: number): EntityID[];
22
+ /** Visit archetypes whose `cid` column changed since `baseline`, in
23
+ * canonical (creation-id) order. */
24
+ _forEachChangedArchetype(cid: number, baseline: number, cb: (arch: ArchetypeView) => void): void;
25
+ /** Every live entity currently holding `cid` (dispose-on-disable sweep). */
26
+ _collectEntitiesWithComponent(cid: number): EntityID[];
27
+ isAlive(id: EntityID): boolean;
28
+ isDisabled(id: EntityID): boolean;
29
+ hasComponent(entityId: EntityID, def: ComponentHandle): boolean;
30
+ }
31
+ /** Per-entity observer callback (onAdd / onRemove / onDisable / onEnable, and
32
+ * per-entity onSet). */
33
+ export type ObserverFn = (eid: EntityID, ctx: SystemContext) => void;
34
+ /** Archetype-granular onSet callback — fires once per changed archetype-column;
35
+ * the consumer iterates `arch.entityCount` rows itself. */
36
+ export type ArchetypeObserverFn = (arch: ArchetypeView, ctx: SystemContext) => void;
37
+ /** Fields common to every observer registration. `access` drives both the
38
+ * dev-mode `accessCheck` and the access-topological firing order; it is merged
39
+ * over an all-empty declaration, so a caller spells out only what it touches. */
40
+ interface ObserverConfigBase {
41
+ onAdd?: ObserverFn;
42
+ onRemove?: ObserverFn;
43
+ /** Fires when an entity carrying this component is *disabled* (#577) — at the
44
+ * deferred toggle drain, once per net transition (ADR-0023). Mirrors `onRemove`:
45
+ * a disable is a soft remove of the whole mask from default queries. An immediate
46
+ * host-side `ecs.disable()` does not fire (like immediate `addComponent`). */
47
+ onDisable?: ObserverFn;
48
+ /** Fires when an entity carrying this component is *enabled* (#577), symmetric
49
+ * with `onDisable` / `onAdd`. */
50
+ onEnable?: ObserverFn;
51
+ /** Access surface the callbacks touch (reads / writes / spawns / …). Partial:
52
+ * merged over `_INTERNAL_EMPTY_ACCESS`. Undeclared access throws in `DEV`. */
53
+ access?: Partial<SystemAccessDeclaration>;
54
+ /** flecs-style replay of current matches on registration (onAdd only — seeds the
55
+ * *enabled* members; a disabled entity is simply absent, matching default-query
56
+ * semantics), for order-independence of register-vs-spawn. */
57
+ yieldExisting?: boolean;
58
+ /** Diagnostic label for this observer, surfaced by the frame-trace seam
59
+ * (ADR-0030) as the `observer_fired.observer` field — the same role a system's
60
+ * `name` plays. Optional and observe-only: it never touches `stateHash` or
61
+ * dispatch. Defaults to `observer(<component debug name>)` when the component
62
+ * was registered with a name, else `observer(<cid>)`. */
63
+ name?: string;
64
+ }
65
+ /** Per-entity onSet: `onSet(eid, ctx)` fires once per changed entity, drained
66
+ * from the opt-in per-row dirty list (registering this enables dirty tracking
67
+ * for the component — the ADR-0012 list + dedup bit). */
68
+ export interface EntitySetObserverConfig extends ObserverConfigBase {
69
+ onSet: ObserverFn;
70
+ granularity: "entity";
71
+ }
72
+ /** Archetype-granular onSet (default): `onSet(arch, ctx)` fires once per
73
+ * changed archetype-column (the change tick), in canonical archetype order. Free
74
+ * write path. */
75
+ export interface ArchetypeSetObserverConfig extends ObserverConfigBase {
76
+ onSet: ArchetypeObserverFn;
77
+ granularity?: "archetype";
78
+ }
79
+ /** Structural-only observer — no onSet. */
80
+ export interface StructuralObserverConfig extends ObserverConfigBase {
81
+ onSet?: undefined;
82
+ granularity?: undefined;
83
+ }
84
+ export type ObserverConfig = StructuralObserverConfig | EntitySetObserverConfig | ArchetypeSetObserverConfig;
85
+ export interface ObserverHandle {
86
+ dispose(): void;
87
+ /** `using h = ecs.observe(C, {...})` — explicit-resource-management sugar
88
+ * over {@link dispose} (TC39 `Symbol.dispose`). */
89
+ [Symbol.dispose](): void;
90
+ }
91
+ /**
92
+ * Registry of component observers. Owned by `ECS`; the `Store` calls back into
93
+ * `dispatchStructural` between fixed-point rounds during `flushStructural`,
94
+ * and `ECS.update` calls `dispatchSet` at the post-update detection point.
95
+ */
96
+ export declare class ObserverRegistry {
97
+ private readonly store;
98
+ private readonly ctx;
99
+ private readonly entries;
100
+ /** ComponentID → its observers (structural + onSet). */
101
+ private readonly byCid;
102
+ /** Cached access-topological order; invalidated on register / dispose. */
103
+ private _topo;
104
+ private readonly _addBuckets;
105
+ private readonly _remBuckets;
106
+ private readonly _disBuckets;
107
+ private readonly _enaBuckets;
108
+ private readonly _radixOut;
109
+ private readonly _radixC0;
110
+ private readonly _radixC1;
111
+ private readonly _setDrainCache;
112
+ constructor(store: ObserverHost, ctx: SystemContext);
113
+ get count(): number;
114
+ /** The synthesized `SystemDescriptor`s of every registered observer, in
115
+ * registration order (`dispose()` splices entries out, so none are stale).
116
+ * Fed into the `startup()` archetype-prewarm closure so an observer's declared
117
+ * `spawns` / `transitions` create their target archetypes eagerly, exactly as a
118
+ * system's do (#768). Without this an observer-spawned/-transitioned archetype
119
+ * first-touches lazily mid-tick — the one asymmetry left in the otherwise
120
+ * uniform "no lazy archetypes" prewarm. */
121
+ descriptors(): SystemDescriptor[];
122
+ register(def: ComponentHandle, config: ObserverConfig): ObserverHandle;
123
+ private _dispose;
124
+ /** Recompute the component's hot-path observation flags from its live
125
+ * observers and push them to the store (which owns the flags + fast-path
126
+ * counters). */
127
+ private _reconfigureComponent;
128
+ private getTopo;
129
+ /**
130
+ * Fire onAdd / onRemove / onDisable / onEnable for one fixed-point round's
131
+ * effective events, in canonical order: access-topological across observers,
132
+ * entity-id order (radix) within each observer. Called by
133
+ * `Store.flushStructural` after the batch commits; observer callbacks may
134
+ * enqueue further structural ops (or toggles) onto the deferred buffers (the
135
+ * store loops until quiescent).
136
+ *
137
+ * The events arrive as flat `(comp, eid)` parallel arrays collected during the
138
+ * flush; we bucket by component once (O(K)), then walk observers in topo order
139
+ * so a producer's writes are visible to a consumer (glitch-free). A round
140
+ * carries either structural (add/rem) OR toggle (dis/ena) events, never both —
141
+ * toggles drain only once add/remove/destroy are quiescent (`flushStructural`)
142
+ * — but we bucket all four uniformly; the empty pairs are no-ops. Within an
143
+ * observer the fire order is remove, add, disable, enable (the "leaving" edges
144
+ * before the "entering" edges).
145
+ */
146
+ dispatchStructural(ev: StructuralObserverEvents): void;
147
+ /** Radix-sort `eids` by entity index (canonical within-observer order), then
148
+ * fire `fn` per entity under the observer's access scope. */
149
+ private _fireEach;
150
+ private _bucket;
151
+ private _clearBuckets;
152
+ /**
153
+ * Fire onSet observers for the current tick, in canonical order. Per-entity
154
+ * onSet drains the opt-in dirty list (once per changed entity); archetype-
155
+ * granular onSet scans the change tick (once per changed archetype-column).
156
+ * Called by `ECS.update` after all phases, with `tick === store._tick`.
157
+ */
158
+ dispatchSet(tick: number): void;
159
+ private _dispatchSetEntity;
160
+ private _dispatchSetArch;
161
+ private _yieldExisting;
162
+ }
163
+ /**
164
+ * O(K) LSD radix sort of entity ids by their 20-bit dense index (two 10-bit
165
+ * passes), in place. This is the canonical within-observer order — *never* a
166
+ * comparator `Array.sort`, which the bench measured at 2–4× the entire flush
167
+ * (`observer_dispatch_probe.ts`). Distinct live entities have distinct indices,
168
+ * so index order is a total canonical order. `out` is scratch (grown to length);
169
+ * `c0` / `c1` are 1024-entry histograms (reused).
170
+ */
171
+ export declare function radixSortByIndex(eids: number[], out: number[], c0: Int32Array, c1: Int32Array): void;
172
+ export {};
173
+ //# sourceMappingURL=observer.d.ts.map