@adobe/data 0.9.7 → 0.9.11

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 (310) hide show
  1. package/data.d.ts +1 -1
  2. package/ecs/database/combine-plugins.d.ts +14 -7
  3. package/ecs/database/combine-plugins.js +6 -3
  4. package/ecs/database/combine-plugins.js.map +1 -1
  5. package/ecs/database/create-plugin.d.ts +37 -17
  6. package/ecs/database/create-plugin.js +3 -30
  7. package/ecs/database/create-plugin.js.map +1 -1
  8. package/ecs/database/create-plugin.test.js +55 -0
  9. package/ecs/database/create-plugin.test.js.map +1 -1
  10. package/ecs/database/create-plugin.type-test.js +157 -0
  11. package/ecs/database/create-plugin.type-test.js.map +1 -1
  12. package/ecs/database/database-schema/create-database-schema.js +3 -3
  13. package/ecs/database/database-schema/create-database-schema.js.map +1 -1
  14. package/ecs/database/database.d.ts +43 -5
  15. package/ecs/database/database.js.map +1 -1
  16. package/ecs/database/observe-dependent-value.test.js +39 -31
  17. package/ecs/database/observe-dependent-value.test.js.map +1 -1
  18. package/ecs/database/observe-select-entities.performance.test.js +30 -31
  19. package/ecs/database/observe-select-entities.performance.test.js.map +1 -1
  20. package/ecs/database/observe-select-entities.test.js +30 -31
  21. package/ecs/database/observe-select-entities.test.js.map +1 -1
  22. package/ecs/database/observed/create-observed-database.js +7 -0
  23. package/ecs/database/observed/create-observed-database.js.map +1 -1
  24. package/ecs/database/public/create-database.d.ts +5 -34
  25. package/ecs/database/public/create-database.js +68 -131
  26. package/ecs/database/public/create-database.js.map +1 -1
  27. package/ecs/database/public/create-database.test.js +324 -62
  28. package/ecs/database/public/create-database.test.js.map +1 -1
  29. package/ecs/database/transactional-store/create-transactional-store.js +16 -1
  30. package/ecs/database/transactional-store/create-transactional-store.js.map +1 -1
  31. package/ecs/plugins/scheduler/scheduler.d.ts +2 -2
  32. package/ecs/plugins/scheduler/scheduler.js +2 -2
  33. package/ecs/plugins/scheduler/scheduler.js.map +1 -1
  34. package/ecs/undo-redo-service/create-undo-redo-service.test.js +22 -23
  35. package/ecs/undo-redo-service/create-undo-redo-service.test.js.map +1 -1
  36. package/package.json +6 -24
  37. package/service/async-data-service/create-lazy.d.ts +40 -0
  38. package/service/async-data-service/create-lazy.js +194 -0
  39. package/service/async-data-service/create-lazy.js.map +1 -0
  40. package/service/async-data-service/create-lazy.test.js +477 -0
  41. package/service/async-data-service/create-lazy.test.js.map +1 -0
  42. package/service/async-data-service/example.d.ts +60 -0
  43. package/service/async-data-service/example.js +35 -0
  44. package/service/async-data-service/example.js.map +1 -0
  45. package/service/async-data-service/index.d.ts +1 -0
  46. package/service/async-data-service/index.js +3 -0
  47. package/service/async-data-service/index.js.map +1 -0
  48. package/service/{is-data-service.d.ts → async-data-service/is-valid.d.ts} +4 -4
  49. package/{lit/hooks/component/component.js → service/async-data-service/is-valid.js} +1 -1
  50. package/service/async-data-service/is-valid.js.map +1 -0
  51. package/service/async-data-service/public.d.ts +2 -0
  52. package/service/async-data-service/public.js +4 -0
  53. package/service/async-data-service/public.js.map +1 -0
  54. package/service/index.d.ts +1 -1
  55. package/service/index.js +1 -0
  56. package/service/index.js.map +1 -1
  57. package/tsconfig.tsbuildinfo +1 -1
  58. package/ecs/database/combine-plugins-test.d.ts +0 -39
  59. package/ecs/database/combine-plugins-test.js +0 -3
  60. package/ecs/database/combine-plugins-test.js.map +0 -1
  61. package/ecs/database/create-plugin-cryos-pattern.test.d.ts +0 -3
  62. package/ecs/database/create-plugin-cryos-pattern.test.js +0 -83
  63. package/ecs/database/create-plugin-cryos-pattern.test.js.map +0 -1
  64. package/ecs/database/create-plugin-graphics.test.d.ts +0 -93
  65. package/ecs/database/create-plugin-graphics.test.js +0 -135
  66. package/ecs/database/create-plugin-graphics.test.js.map +0 -1
  67. package/ecs/database/create-plugin-type.type-test.js +0 -563
  68. package/ecs/database/create-plugin-type.type-test.js.map +0 -1
  69. package/ecs/database/create-plugin-type.type.test.d.ts +0 -1
  70. package/ecs/database/create-plugin-type.type.test.js +0 -563
  71. package/ecs/database/create-plugin-type.type.test.js.map +0 -1
  72. package/ecs/database/experimental-action-types.d.ts +0 -1
  73. package/ecs/database/experimental-action-types.js +0 -275
  74. package/ecs/database/experimental-action-types.js.map +0 -1
  75. package/ecs/database/from-plugin.type-test.d.ts +0 -1
  76. package/ecs/database/from-plugin.type-test.js +0 -180
  77. package/ecs/database/from-plugin.type-test.js.map +0 -1
  78. package/ecs/database/plugin-types.d.ts +0 -1
  79. package/ecs/database/plugin-types.js +0 -5
  80. package/ecs/database/plugin-types.js.map +0 -1
  81. package/ecs/database/type-investigation.test.d.ts +0 -1
  82. package/ecs/database/type-investigation.test.js +0 -54
  83. package/ecs/database/type-investigation.test.js.map +0 -1
  84. package/lit/decorators/apply-decorator.d.ts +0 -1
  85. package/lit/decorators/apply-decorator.js +0 -19
  86. package/lit/decorators/apply-decorator.js.map +0 -1
  87. package/lit/decorators/apply-service-decorators.d.ts +0 -1
  88. package/lit/decorators/apply-service-decorators.js +0 -13
  89. package/lit/decorators/apply-service-decorators.js.map +0 -1
  90. package/lit/decorators/index.d.ts +0 -3
  91. package/lit/decorators/index.js +0 -5
  92. package/lit/decorators/index.js.map +0 -1
  93. package/lit/decorators/require-service.d.ts +0 -1
  94. package/lit/decorators/require-service.js +0 -14
  95. package/lit/decorators/require-service.js.map +0 -1
  96. package/lit/elements/application-element.d.ts +0 -9
  97. package/lit/elements/application-element.js +0 -42
  98. package/lit/elements/application-element.js.map +0 -1
  99. package/lit/elements/application-host.d.ts +0 -16
  100. package/lit/elements/application-host.js +0 -39
  101. package/lit/elements/application-host.js.map +0 -1
  102. package/lit/elements/database-element.d.ts +0 -10
  103. package/lit/elements/database-element.js +0 -40
  104. package/lit/elements/database-element.js.map +0 -1
  105. package/lit/elements/index.d.ts +0 -3
  106. package/lit/elements/index.js +0 -5
  107. package/lit/elements/index.js.map +0 -1
  108. package/lit/functions/index.d.ts +0 -1
  109. package/lit/functions/index.js +0 -3
  110. package/lit/functions/index.js.map +0 -1
  111. package/lit/functions/iterate-self-and-ancestors.d.ts +0 -1
  112. package/lit/functions/iterate-self-and-ancestors.js +0 -24
  113. package/lit/functions/iterate-self-and-ancestors.js.map +0 -1
  114. package/lit/hooks/attach-decorator.d.ts +0 -4
  115. package/lit/hooks/attach-decorator.js +0 -26
  116. package/lit/hooks/attach-decorator.js.map +0 -1
  117. package/lit/hooks/component/component.d.ts +0 -10
  118. package/lit/hooks/component/component.js.map +0 -1
  119. package/lit/hooks/component/stack.d.ts +0 -6
  120. package/lit/hooks/component/stack.js +0 -16
  121. package/lit/hooks/component/stack.js.map +0 -1
  122. package/lit/hooks/index.d.ts +0 -19
  123. package/lit/hooks/index.js +0 -21
  124. package/lit/hooks/index.js.map +0 -1
  125. package/lit/hooks/use-connected.d.ts +0 -2
  126. package/lit/hooks/use-connected.js +0 -32
  127. package/lit/hooks/use-connected.js.map +0 -1
  128. package/lit/hooks/use-debounce.d.ts +0 -8
  129. package/lit/hooks/use-debounce.js +0 -21
  130. package/lit/hooks/use-debounce.js.map +0 -1
  131. package/lit/hooks/use-drag-observe.d.ts +0 -25
  132. package/lit/hooks/use-drag-observe.js +0 -35
  133. package/lit/hooks/use-drag-observe.js.map +0 -1
  134. package/lit/hooks/use-drag-transaction.d.ts +0 -7
  135. package/lit/hooks/use-drag-transaction.js +0 -35
  136. package/lit/hooks/use-drag-transaction.js.map +0 -1
  137. package/lit/hooks/use-draggable.d.ts +0 -15
  138. package/lit/hooks/use-draggable.js +0 -96
  139. package/lit/hooks/use-draggable.js.map +0 -1
  140. package/lit/hooks/use-effect.d.ts +0 -3
  141. package/lit/hooks/use-effect.js +0 -14
  142. package/lit/hooks/use-effect.js.map +0 -1
  143. package/lit/hooks/use-element.d.ts +0 -7
  144. package/lit/hooks/use-element.js +0 -67
  145. package/lit/hooks/use-element.js.map +0 -1
  146. package/lit/hooks/use-memo.d.ts +0 -1
  147. package/lit/hooks/use-memo.js +0 -13
  148. package/lit/hooks/use-memo.js.map +0 -1
  149. package/lit/hooks/use-observable-values.d.ts +0 -4
  150. package/lit/hooks/use-observable-values.js +0 -9
  151. package/lit/hooks/use-observable-values.js.map +0 -1
  152. package/lit/hooks/use-observable.d.ts +0 -2
  153. package/lit/hooks/use-observable.js +0 -13
  154. package/lit/hooks/use-observable.js.map +0 -1
  155. package/lit/hooks/use-ref.d.ts +0 -3
  156. package/lit/hooks/use-ref.js +0 -7
  157. package/lit/hooks/use-ref.js.map +0 -1
  158. package/lit/hooks/use-resize-observer.d.ts +0 -12
  159. package/lit/hooks/use-resize-observer.js +0 -23
  160. package/lit/hooks/use-resize-observer.js.map +0 -1
  161. package/lit/hooks/use-state.d.ts +0 -2
  162. package/lit/hooks/use-state.js +0 -15
  163. package/lit/hooks/use-state.js.map +0 -1
  164. package/lit/hooks/use-updated.d.ts +0 -4
  165. package/lit/hooks/use-updated.js +0 -40
  166. package/lit/hooks/use-updated.js.map +0 -1
  167. package/lit/hooks/use-window-event.d.ts +0 -1
  168. package/lit/hooks/use-window-event.js +0 -11
  169. package/lit/hooks/use-window-event.js.map +0 -1
  170. package/lit/hooks/with-hooks.d.ts +0 -2
  171. package/lit/hooks/with-hooks.js +0 -16
  172. package/lit/hooks/with-hooks.js.map +0 -1
  173. package/lit/index.d.ts +0 -4
  174. package/lit/index.js +0 -5
  175. package/lit/index.js.map +0 -1
  176. package/normalize.test.d.ts +0 -1
  177. package/normalize.test.js +0 -28
  178. package/normalize.test.js.map +0 -1
  179. package/samples/index.d.ts +0 -13
  180. package/samples/index.js +0 -7
  181. package/samples/index.js.map +0 -1
  182. package/samples/todo/elements/todo-list/todo-list-presentation.d.ts +0 -8
  183. package/samples/todo/elements/todo-list/todo-list-presentation.js +0 -12
  184. package/samples/todo/elements/todo-list/todo-list-presentation.js.map +0 -1
  185. package/samples/todo/elements/todo-list/todo-list.css.d.ts +0 -1
  186. package/samples/todo/elements/todo-list/todo-list.css.js +0 -11
  187. package/samples/todo/elements/todo-list/todo-list.css.js.map +0 -1
  188. package/samples/todo/elements/todo-list/todo-list.d.ts +0 -12
  189. package/samples/todo/elements/todo-list/todo-list.js +0 -44
  190. package/samples/todo/elements/todo-list/todo-list.js.map +0 -1
  191. package/samples/todo/elements/todo-row/index.d.ts +0 -1
  192. package/samples/todo/elements/todo-row/index.js +0 -3
  193. package/samples/todo/elements/todo-row/index.js.map +0 -1
  194. package/samples/todo/elements/todo-row/todo-row-presentation.d.ts +0 -18
  195. package/samples/todo/elements/todo-row/todo-row-presentation.js +0 -50
  196. package/samples/todo/elements/todo-row/todo-row-presentation.js.map +0 -1
  197. package/samples/todo/elements/todo-row/todo-row.css.d.ts +0 -1
  198. package/samples/todo/elements/todo-row/todo-row.css.js +0 -49
  199. package/samples/todo/elements/todo-row/todo-row.css.js.map +0 -1
  200. package/samples/todo/elements/todo-row/todo-row.d.ts +0 -14
  201. package/samples/todo/elements/todo-row/todo-row.js +0 -44
  202. package/samples/todo/elements/todo-row/todo-row.js.map +0 -1
  203. package/samples/todo/elements/todo-toolbar/index.d.ts +0 -1
  204. package/samples/todo/elements/todo-toolbar/index.js +0 -3
  205. package/samples/todo/elements/todo-toolbar/index.js.map +0 -1
  206. package/samples/todo/elements/todo-toolbar/todo-toolbar-presentation.d.ts +0 -22
  207. package/samples/todo/elements/todo-toolbar/todo-toolbar-presentation.js +0 -41
  208. package/samples/todo/elements/todo-toolbar/todo-toolbar-presentation.js.map +0 -1
  209. package/samples/todo/elements/todo-toolbar/todo-toolbar.css.d.ts +0 -1
  210. package/samples/todo/elements/todo-toolbar/todo-toolbar.css.js +0 -34
  211. package/samples/todo/elements/todo-toolbar/todo-toolbar.css.js.map +0 -1
  212. package/samples/todo/elements/todo-toolbar/todo-toolbar.d.ts +0 -11
  213. package/samples/todo/elements/todo-toolbar/todo-toolbar.js +0 -61
  214. package/samples/todo/elements/todo-toolbar/todo-toolbar.js.map +0 -1
  215. package/samples/todo/elements/todo-undo-redo/index.d.ts +0 -1
  216. package/samples/todo/elements/todo-undo-redo/index.js +0 -3
  217. package/samples/todo/elements/todo-undo-redo/index.js.map +0 -1
  218. package/samples/todo/elements/todo-undo-redo/todo-undo-redo-presentation.d.ts +0 -17
  219. package/samples/todo/elements/todo-undo-redo/todo-undo-redo-presentation.js +0 -29
  220. package/samples/todo/elements/todo-undo-redo/todo-undo-redo-presentation.js.map +0 -1
  221. package/samples/todo/elements/todo-undo-redo/todo-undo-redo.css.d.ts +0 -1
  222. package/samples/todo/elements/todo-undo-redo/todo-undo-redo.css.js +0 -12
  223. package/samples/todo/elements/todo-undo-redo/todo-undo-redo.css.js.map +0 -1
  224. package/samples/todo/elements/todo-undo-redo/todo-undo-redo.d.ts +0 -11
  225. package/samples/todo/elements/todo-undo-redo/todo-undo-redo.js +0 -36
  226. package/samples/todo/elements/todo-undo-redo/todo-undo-redo.js.map +0 -1
  227. package/samples/todo/services/dependent-state-service/create-dependent-state-service.d.ts +0 -6
  228. package/samples/todo/services/dependent-state-service/create-dependent-state-service.js +0 -5
  229. package/samples/todo/services/dependent-state-service/create-dependent-state-service.js.map +0 -1
  230. package/samples/todo/services/dependent-state-service/dependent-state/all-todos.d.ts +0 -2
  231. package/samples/todo/services/dependent-state-service/dependent-state/all-todos.js +0 -2
  232. package/samples/todo/services/dependent-state-service/dependent-state/all-todos.js.map +0 -1
  233. package/samples/todo/services/dependent-state-service/dependent-state/complete-todos.d.ts +0 -2
  234. package/samples/todo/services/dependent-state-service/dependent-state/complete-todos.js +0 -2
  235. package/samples/todo/services/dependent-state-service/dependent-state/complete-todos.js.map +0 -1
  236. package/samples/todo/services/dependent-state-service/dependent-state/incomplete-todos.d.ts +0 -2
  237. package/samples/todo/services/dependent-state-service/dependent-state/incomplete-todos.js +0 -2
  238. package/samples/todo/services/dependent-state-service/dependent-state/incomplete-todos.js.map +0 -1
  239. package/samples/todo/services/dependent-state-service/dependent-state/index.d.ts +0 -3
  240. package/samples/todo/services/dependent-state-service/dependent-state/index.js +0 -5
  241. package/samples/todo/services/dependent-state-service/dependent-state/index.js.map +0 -1
  242. package/samples/todo/services/dependent-state-service/dependent-state-service.d.ts +0 -2
  243. package/samples/todo/services/dependent-state-service/dependent-state-service.js +0 -2
  244. package/samples/todo/services/dependent-state-service/dependent-state-service.js.map +0 -1
  245. package/samples/todo/services/main-service/create-main-service.d.ts +0 -8
  246. package/samples/todo/services/main-service/create-main-service.js +0 -39
  247. package/samples/todo/services/main-service/create-main-service.js.map +0 -1
  248. package/samples/todo/services/main-service/todo-main-service.d.ts +0 -18
  249. package/samples/todo/services/main-service/todo-main-service.js +0 -2
  250. package/samples/todo/services/main-service/todo-main-service.js.map +0 -1
  251. package/samples/todo/services/state-service/create-todo-database.d.ts +0 -37
  252. package/samples/todo/services/state-service/create-todo-database.js +0 -10
  253. package/samples/todo/services/state-service/create-todo-database.js.map +0 -1
  254. package/samples/todo/services/state-service/create-todo-store.d.ts +0 -37
  255. package/samples/todo/services/state-service/create-todo-store.js +0 -24
  256. package/samples/todo/services/state-service/create-todo-store.js.map +0 -1
  257. package/samples/todo/services/state-service/todo-state-service.d.ts +0 -5
  258. package/samples/todo/services/state-service/todo-state-service.js +0 -2
  259. package/samples/todo/services/state-service/todo-state-service.js.map +0 -1
  260. package/samples/todo/services/state-service/transactions/create-bulk-todos.d.ts +0 -2
  261. package/samples/todo/services/state-service/transactions/create-bulk-todos.js +0 -10
  262. package/samples/todo/services/state-service/transactions/create-bulk-todos.js.map +0 -1
  263. package/samples/todo/services/state-service/transactions/create-todo.d.ts +0 -5
  264. package/samples/todo/services/state-service/transactions/create-todo.js +0 -13
  265. package/samples/todo/services/state-service/transactions/create-todo.js.map +0 -1
  266. package/samples/todo/services/state-service/transactions/create-todo.test.d.ts +0 -1
  267. package/samples/todo/services/state-service/transactions/create-todo.test.js +0 -16
  268. package/samples/todo/services/state-service/transactions/create-todo.test.js.map +0 -1
  269. package/samples/todo/services/state-service/transactions/delete-all-todos.d.ts +0 -2
  270. package/samples/todo/services/state-service/transactions/delete-all-todos.js +0 -16
  271. package/samples/todo/services/state-service/transactions/delete-all-todos.js.map +0 -1
  272. package/samples/todo/services/state-service/transactions/delete-todo.d.ts +0 -3
  273. package/samples/todo/services/state-service/transactions/delete-todo.js +0 -8
  274. package/samples/todo/services/state-service/transactions/delete-todo.js.map +0 -1
  275. package/samples/todo/services/state-service/transactions/delete-todo.test.d.ts +0 -1
  276. package/samples/todo/services/state-service/transactions/delete-todo.test.js +0 -24
  277. package/samples/todo/services/state-service/transactions/delete-todo.test.js.map +0 -1
  278. package/samples/todo/services/state-service/transactions/drag-todo.d.ts +0 -7
  279. package/samples/todo/services/state-service/transactions/drag-todo.js +0 -17
  280. package/samples/todo/services/state-service/transactions/drag-todo.js.map +0 -1
  281. package/samples/todo/services/state-service/transactions/index.d.ts +0 -6
  282. package/samples/todo/services/state-service/transactions/index.js +0 -9
  283. package/samples/todo/services/state-service/transactions/index.js.map +0 -1
  284. package/samples/todo/services/state-service/transactions/reorder-todos.d.ts +0 -6
  285. package/samples/todo/services/state-service/transactions/reorder-todos.js +0 -11
  286. package/samples/todo/services/state-service/transactions/reorder-todos.js.map +0 -1
  287. package/samples/todo/services/state-service/transactions/toggle-complete.d.ts +0 -3
  288. package/samples/todo/services/state-service/transactions/toggle-complete.js +0 -11
  289. package/samples/todo/services/state-service/transactions/toggle-complete.js.map +0 -1
  290. package/samples/todo/services/state-service/transactions/toggle-complete.test.d.ts +0 -1
  291. package/samples/todo/services/state-service/transactions/toggle-complete.test.js +0 -65
  292. package/samples/todo/services/state-service/transactions/toggle-complete.test.js.map +0 -1
  293. package/samples/todo/todo-element.d.ts +0 -4
  294. package/samples/todo/todo-element.js +0 -4
  295. package/samples/todo/todo-element.js.map +0 -1
  296. package/samples/todo/todo-host.d.ts +0 -8
  297. package/samples/todo/todo-host.js +0 -35
  298. package/samples/todo/todo-host.js.map +0 -1
  299. package/samples/todo/todo-main-element.d.ts +0 -10
  300. package/samples/todo/todo-main-element.js +0 -47
  301. package/samples/todo/todo-main-element.js.map +0 -1
  302. package/samples/todo/todo-sample.d.ts +0 -3
  303. package/samples/todo/todo-sample.js +0 -19
  304. package/samples/todo/todo-sample.js.map +0 -1
  305. package/service/is-data-service.js +0 -2
  306. package/service/is-data-service.js.map +0 -1
  307. package/typed-buffer/public.d.ts +0 -2
  308. package/typed-buffer/public.js +0 -4
  309. package/typed-buffer/public.js.map +0 -1
  310. /package/{ecs/database/create-plugin-type.type-test.d.ts → service/async-data-service/create-lazy.test.d.ts} +0 -0
@@ -4,7 +4,7 @@ import { Database } from "../database.js";
4
4
  import { createReconcilingDatabase } from "../reconciling/create-reconciling-database.js";
5
5
  import { Store } from "../../store/index.js";
6
6
  import { F32 } from "../../../math/f32/index.js";
7
- import { toPromise } from "../../../observe/to-promise.js";
7
+ import { Observe } from "../../../observe/index.js";
8
8
  import { createUndoRedoService } from "../../undo-redo-service/create-undo-redo-service.js";
9
9
  import { applyOperations } from "../transactional-store/apply-operations.js";
10
10
  // Test schemas
@@ -31,21 +31,22 @@ const nameSchema = {
31
31
  type: "string",
32
32
  maxLength: 50,
33
33
  };
34
+ const storeSchema = {
35
+ components: { position: positionSchema, health: healthSchema, name: nameSchema },
36
+ resources: {
37
+ time: { default: { delta: 0.016, elapsed: 0 } },
38
+ generating: { type: "boolean", default: false }
39
+ },
40
+ archetypes: {
41
+ Position: ["position"],
42
+ Health: ["health"],
43
+ PositionHealth: ["position", "health"],
44
+ PositionName: ["position", "name"],
45
+ Full: ["position", "health", "name"],
46
+ }
47
+ };
34
48
  const createStoreConfig = () => {
35
- const baseStore = Store.create({
36
- components: { position: positionSchema, health: healthSchema, name: nameSchema },
37
- resources: {
38
- time: { default: { delta: 0.016, elapsed: 0 } },
39
- generating: { type: "boolean", default: false }
40
- },
41
- archetypes: {
42
- Position: ["position"],
43
- Health: ["health"],
44
- PositionHealth: ["position", "health"],
45
- PositionName: ["position", "name"],
46
- Full: ["position", "health", "name"],
47
- }
48
- });
49
+ const baseStore = Store.create(storeSchema);
49
50
  const actions = {
50
51
  createPositionEntity(t, args) {
51
52
  return t.archetypes.Position.insert(args);
@@ -87,11 +88,19 @@ const createStoreConfig = () => {
87
88
  }
88
89
  }
89
90
  };
90
- return { baseStore, actions };
91
+ return { baseStore, actions, storeSchema };
91
92
  };
93
+ function createTestPlugin() {
94
+ const { actions, storeSchema } = createStoreConfig();
95
+ return Database.Plugin.create({
96
+ components: storeSchema.components,
97
+ resources: storeSchema.resources,
98
+ archetypes: storeSchema.archetypes,
99
+ transactions: actions,
100
+ });
101
+ }
92
102
  function createTestDatabase() {
93
- const { baseStore, actions } = createStoreConfig();
94
- return Database.create(baseStore, actions);
103
+ return Database.create(createTestPlugin());
95
104
  }
96
105
  describe("createDatabase", () => {
97
106
  it("should apply committed entries in arrival order, ignoring commit time", () => {
@@ -712,7 +721,7 @@ describe("createDatabase", () => {
712
721
  expect(promise).toBeInstanceOf(Promise);
713
722
  const result = await promise;
714
723
  expect(result).toBe(-1);
715
- const generating = await toPromise(store.observe.resources.generating);
724
+ const generating = await Observe.toPromise(store.observe.resources.generating);
716
725
  expect(generating).toBe(false);
717
726
  });
718
727
  });
@@ -725,13 +734,18 @@ describe("createDatabase", () => {
725
734
  // Clear any initial calls
726
735
  observer.mockClear();
727
736
  // Create a no-op transaction (doesn't modify anything)
728
- const { baseStore, actions } = createStoreConfig();
729
- const database = Database.create(baseStore, {
730
- ...actions,
731
- noOpTransaction(t, _args) {
732
- // This transaction does nothing
733
- }
734
- });
737
+ const { actions, storeSchema } = createStoreConfig();
738
+ const database = Database.create(Database.Plugin.create({
739
+ components: storeSchema.components,
740
+ resources: storeSchema.resources,
741
+ archetypes: storeSchema.archetypes,
742
+ transactions: {
743
+ ...actions,
744
+ noOpTransaction(t, _args) {
745
+ // This transaction does nothing
746
+ }
747
+ },
748
+ }));
735
749
  const positionObserver = vi.fn();
736
750
  const unsub = database.observe.components.position(positionObserver);
737
751
  positionObserver.mockClear();
@@ -744,22 +758,27 @@ describe("createDatabase", () => {
744
758
  it("should not add no-op actions to the undo stack", async () => {
745
759
  const store = createTestDatabase();
746
760
  // Create database with undo-redo service
747
- const { baseStore, actions } = createStoreConfig();
748
- const database = Database.create(baseStore, {
749
- ...actions,
750
- noOpTransaction(t, _args) {
751
- t.undoable = { coalesce: false };
752
- // This transaction does nothing
761
+ const { actions, storeSchema } = createStoreConfig();
762
+ const database = Database.create(Database.Plugin.create({
763
+ components: storeSchema.components,
764
+ resources: storeSchema.resources,
765
+ archetypes: storeSchema.archetypes,
766
+ transactions: {
767
+ ...actions,
768
+ noOpTransaction(t, _args) {
769
+ t.undoable = { coalesce: false };
770
+ // This transaction does nothing
771
+ },
772
+ applyOperations(t, operations) {
773
+ applyOperations(t, operations);
774
+ }
753
775
  },
754
- applyOperations(t, operations) {
755
- applyOperations(t, operations);
756
- }
757
- });
776
+ }));
758
777
  const undoRedo = createUndoRedoService(database);
759
778
  // Execute the no-op transaction
760
779
  database.transactions.noOpTransaction({});
761
780
  // Verify the undo stack is empty (need to await the observable)
762
- const undoStack = await toPromise(undoRedo.undoStack);
781
+ const undoStack = await Observe.toPromise(undoRedo.undoStack);
763
782
  expect(undoStack).toHaveLength(0);
764
783
  });
765
784
  it("should emit a transaction that makes changes", () => {
@@ -774,27 +793,31 @@ describe("createDatabase", () => {
774
793
  unsubscribe();
775
794
  });
776
795
  it("should detect true no-op when transaction reads but doesn't modify", async () => {
777
- const { baseStore, actions } = createStoreConfig();
778
- const database = Database.create(baseStore, {
779
- ...actions,
780
- readOnlyTransaction(t, args) {
781
- t.undoable = { coalesce: false };
782
- // Just read the entity but don't modify it
783
- const current = t.read(args.entity);
784
- // Do nothing with the data - this is a true no-op
796
+ const { actions, storeSchema } = createStoreConfig();
797
+ const database = Database.create(Database.Plugin.create({
798
+ components: storeSchema.components,
799
+ resources: storeSchema.resources,
800
+ archetypes: storeSchema.archetypes,
801
+ transactions: {
802
+ ...actions,
803
+ readOnlyTransaction(t, args) {
804
+ t.undoable = { coalesce: false };
805
+ const current = t.read(args.entity);
806
+ void current;
807
+ },
808
+ applyOperations(t, operations) {
809
+ applyOperations(t, operations);
810
+ }
785
811
  },
786
- applyOperations(t, operations) {
787
- applyOperations(t, operations);
788
- }
789
- });
812
+ }));
790
813
  // Create an entity
791
814
  const entity = database.transactions.createPositionEntity({ position: { x: 1, y: 2, z: 3 } });
792
815
  const undoRedo = createUndoRedoService(database);
793
- const initialStackLength = (await toPromise(undoRedo.undoStack)).length;
816
+ const initialStackLength = (await Observe.toPromise(undoRedo.undoStack)).length;
794
817
  // Execute read-only transaction (true no-op)
795
818
  database.transactions.readOnlyTransaction({ entity });
796
819
  // Verify no new undo entry was added
797
- const finalStackLength = (await toPromise(undoRedo.undoStack)).length;
820
+ const finalStackLength = (await Observe.toPromise(undoRedo.undoStack)).length;
798
821
  expect(finalStackLength).toBe(initialStackLength);
799
822
  });
800
823
  });
@@ -804,24 +827,25 @@ describe("createDatabase", () => {
804
827
  expect(extended).toBe(database);
805
828
  });
806
829
  it("should return the same instance when extended with systems", () => {
807
- // Create a database with initial systems
808
- const { baseStore, actions } = createStoreConfig();
830
+ const { actions, storeSchema } = createStoreConfig();
809
831
  const systemOneCalled = vi.fn();
810
- const database = Database.create(baseStore, actions, {
811
- systemOne: {
812
- create: (db) => {
813
- return () => {
814
- systemOneCalled();
815
- };
832
+ const database = Database.create(Database.Plugin.create({
833
+ components: storeSchema.components,
834
+ resources: storeSchema.resources,
835
+ archetypes: storeSchema.archetypes,
836
+ transactions: actions,
837
+ systems: {
838
+ systemOne: {
839
+ create: (_db) => () => systemOneCalled(),
816
840
  }
817
- }
818
- });
841
+ },
842
+ }));
819
843
  // Extend with a plugin that includes a new system
820
844
  const systemTwoCalled = vi.fn();
821
845
  const extensionPlugin = Database.Plugin.create({
822
846
  systems: {
823
847
  systemTwo: {
824
- create: (db) => {
848
+ create: (_db) => {
825
849
  return () => {
826
850
  systemTwoCalled();
827
851
  };
@@ -836,6 +860,244 @@ describe("createDatabase", () => {
836
860
  expect(extended.system.functions.systemOne).toBeDefined();
837
861
  expect(extended.system.functions.systemTwo).toBeDefined();
838
862
  });
863
+ describe("services", () => {
864
+ it("should initialize services immediately when extending with a plugin", () => {
865
+ const database = createTestDatabase();
866
+ const authPlugin = Database.Plugin.create({
867
+ services: {
868
+ auth: (_db) => ({ token: 'test-token', isAuthenticated: true }),
869
+ },
870
+ });
871
+ const extended = database.extend(authPlugin);
872
+ // Services should be immediately available
873
+ expect(extended.services.auth).toBeDefined();
874
+ expect(extended.services.auth.token).toBe('test-token');
875
+ expect(extended.services.auth.isAuthenticated).toBe(true);
876
+ });
877
+ it("should initialize services in correct order when extending with dependent services", () => {
878
+ const initializationOrder = [];
879
+ const database = createTestDatabase();
880
+ // Base plugin with a config service
881
+ const basePlugin = Database.Plugin.create({
882
+ services: {
883
+ config: (_db) => {
884
+ initializationOrder.push('config');
885
+ return { apiUrl: 'https://api.example.com' };
886
+ },
887
+ },
888
+ });
889
+ // Extended plugin with auth service that depends on config
890
+ const authPlugin = Database.Plugin.create({
891
+ extends: basePlugin,
892
+ services: {
893
+ auth: (db) => {
894
+ initializationOrder.push('auth');
895
+ // Auth service depends on config service from base plugin
896
+ const apiUrl = db.services.config.apiUrl;
897
+ return { token: 'test-token', apiUrl };
898
+ },
899
+ },
900
+ });
901
+ const extended = database.extend(authPlugin);
902
+ // Verify initialization order: base services first, then extended
903
+ expect(initializationOrder).toEqual(['config', 'auth']);
904
+ // Both services should be available
905
+ expect(extended.services.config).toBeDefined();
906
+ expect(extended.services.config.apiUrl).toBe('https://api.example.com');
907
+ expect(extended.services.auth).toBeDefined();
908
+ expect(extended.services.auth.token).toBe('test-token');
909
+ expect(extended.services.auth.apiUrl).toBe('https://api.example.com');
910
+ });
911
+ it("should initialize services in correct order with multiple levels of extension", () => {
912
+ const initializationOrder = [];
913
+ const database = createTestDatabase();
914
+ // Level 1: Environment service
915
+ const envPlugin = Database.Plugin.create({
916
+ services: {
917
+ env: (_db) => {
918
+ initializationOrder.push('env');
919
+ return { isDev: true, apiBase: 'https://dev.api.example.com' };
920
+ },
921
+ },
922
+ });
923
+ // Level 2: Config service depends on env
924
+ const configPlugin = Database.Plugin.create({
925
+ extends: envPlugin,
926
+ services: {
927
+ config: (db) => {
928
+ initializationOrder.push('config');
929
+ return {
930
+ apiUrl: `${db.services.env.apiBase}/v1`,
931
+ debug: db.services.env.isDev,
932
+ };
933
+ },
934
+ },
935
+ });
936
+ // Level 3: Auth service depends on config
937
+ const authPlugin = Database.Plugin.create({
938
+ extends: configPlugin,
939
+ services: {
940
+ auth: (db) => {
941
+ initializationOrder.push('auth');
942
+ return {
943
+ token: 'test-token',
944
+ endpoint: `${db.services.config.apiUrl}/auth`,
945
+ };
946
+ },
947
+ },
948
+ });
949
+ const extended = database.extend(authPlugin);
950
+ // Verify initialization order: env -> config -> auth
951
+ expect(initializationOrder).toEqual(['env', 'config', 'auth']);
952
+ // All services should be available with correct values
953
+ expect(extended.services.env.isDev).toBe(true);
954
+ expect(extended.services.config.apiUrl).toBe('https://dev.api.example.com/v1');
955
+ expect(extended.services.auth.endpoint).toBe('https://dev.api.example.com/v1/auth');
956
+ });
957
+ it("should make services available immediately after extend returns", () => {
958
+ const database = createTestDatabase();
959
+ const plugin = Database.Plugin.create({
960
+ services: {
961
+ logger: (_db) => ({
962
+ log: (msg) => console.log(msg),
963
+ level: 'info',
964
+ }),
965
+ analytics: (_db) => ({
966
+ track: (event) => { },
967
+ userId: 'test-user',
968
+ }),
969
+ },
970
+ });
971
+ const extended = database.extend(plugin);
972
+ expect(extended.services.logger).toBeDefined();
973
+ expect(extended.services.analytics).toBeDefined();
974
+ });
975
+ });
976
+ describe("computed", () => {
977
+ it("should initialize computed values when extending with a plugin", () => {
978
+ const database = createTestDatabase();
979
+ const plugin = Database.Plugin.create({
980
+ components: {},
981
+ resources: {},
982
+ archetypes: {},
983
+ computed: {
984
+ count: (_db) => Observe.fromConstant(10),
985
+ label: (_db) => Observe.fromConstant("test"),
986
+ },
987
+ transactions: {},
988
+ actions: {},
989
+ systems: {},
990
+ });
991
+ const extended = database.extend(plugin);
992
+ expect(extended.computed).toBeDefined();
993
+ expect(extended.computed.count).toBeDefined();
994
+ expect(extended.computed.label).toBeDefined();
995
+ expect(typeof extended.computed.count).toBe("function");
996
+ expect(typeof extended.computed.label).toBe("function");
997
+ const unsubCount = extended.computed.count((v) => expect(v).toBe(10));
998
+ const unsubLabel = extended.computed.label((v) => expect(v).toBe("test"));
999
+ unsubCount();
1000
+ unsubLabel();
1001
+ });
1002
+ it("should initialize computed when creating database from plugin", () => {
1003
+ const plugin = Database.Plugin.create({
1004
+ components: { x: { type: "number" } },
1005
+ resources: {},
1006
+ archetypes: {},
1007
+ computed: {
1008
+ sum: (_db) => Observe.fromConstant(100),
1009
+ },
1010
+ transactions: {},
1011
+ actions: {},
1012
+ systems: {},
1013
+ });
1014
+ const db = Database.create(plugin);
1015
+ expect(db.computed).toBeDefined();
1016
+ expect(db.computed.sum).toBeDefined();
1017
+ let received;
1018
+ const unsub = db.computed.sum((v) => { received = v; });
1019
+ expect(received).toBe(100);
1020
+ unsub();
1021
+ });
1022
+ it("should initialize computed in order when extending with base and extended plugin", () => {
1023
+ const database = createTestDatabase();
1024
+ const basePlugin = Database.Plugin.create({
1025
+ components: {},
1026
+ resources: {},
1027
+ archetypes: {},
1028
+ computed: {
1029
+ baseValue: (_db) => Observe.fromConstant(1),
1030
+ },
1031
+ transactions: {},
1032
+ actions: {},
1033
+ systems: {},
1034
+ });
1035
+ const extendedPlugin = Database.Plugin.create({
1036
+ extends: basePlugin,
1037
+ components: {},
1038
+ resources: {},
1039
+ archetypes: {},
1040
+ computed: {
1041
+ derived: (_db) => Observe.fromConstant(2),
1042
+ },
1043
+ transactions: {},
1044
+ actions: {},
1045
+ systems: {},
1046
+ });
1047
+ const extended = database.extend(extendedPlugin);
1048
+ expect(extended.computed.baseValue).toBeDefined();
1049
+ expect(extended.computed.derived).toBeDefined();
1050
+ extended.computed.baseValue((v) => expect(v).toBe(1));
1051
+ extended.computed.derived((v) => expect(v).toBe(2));
1052
+ });
1053
+ });
1054
+ describe("system create and assign", () => {
1055
+ it("should create and assign each system once when creating database from plugin (no double create from create then extend)", () => {
1056
+ let createCallCount = 0;
1057
+ const plugin = Database.Plugin.create({
1058
+ components: { x: { type: "number" } },
1059
+ resources: {},
1060
+ archetypes: {},
1061
+ transactions: {},
1062
+ actions: {},
1063
+ systems: {
1064
+ init: {
1065
+ create: (_db) => {
1066
+ createCallCount += 1;
1067
+ return () => { };
1068
+ },
1069
+ },
1070
+ },
1071
+ });
1072
+ const db = Database.create(plugin);
1073
+ expect(createCallCount).toBe(1);
1074
+ expect(typeof db.system.functions.init).toBe("function");
1075
+ });
1076
+ it("services are created and available before system create() runs", () => {
1077
+ let serviceSeenInSystemCreate = undefined;
1078
+ const plugin = Database.Plugin.create({
1079
+ services: {
1080
+ config: (db) => ({ apiUrl: "https://api.example.com" }),
1081
+ },
1082
+ components: {},
1083
+ resources: {},
1084
+ archetypes: {},
1085
+ transactions: {},
1086
+ actions: {},
1087
+ systems: {
1088
+ init: {
1089
+ create: (db) => {
1090
+ serviceSeenInSystemCreate = db.services.config;
1091
+ return () => { };
1092
+ },
1093
+ },
1094
+ },
1095
+ });
1096
+ Database.create(plugin);
1097
+ expect(serviceSeenInSystemCreate).toBeDefined();
1098
+ expect(serviceSeenInSystemCreate.apiUrl).toBe("https://api.example.com");
1099
+ });
1100
+ });
839
1101
  });
840
1102
  describe("database.transactions", () => {
841
1103
  it("should execute transactions directly", () => {