@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.
- package/data.d.ts +1 -1
- package/ecs/database/combine-plugins.d.ts +14 -7
- package/ecs/database/combine-plugins.js +6 -3
- package/ecs/database/combine-plugins.js.map +1 -1
- package/ecs/database/create-plugin.d.ts +37 -17
- package/ecs/database/create-plugin.js +3 -30
- package/ecs/database/create-plugin.js.map +1 -1
- package/ecs/database/create-plugin.test.js +55 -0
- package/ecs/database/create-plugin.test.js.map +1 -1
- package/ecs/database/create-plugin.type-test.js +157 -0
- package/ecs/database/create-plugin.type-test.js.map +1 -1
- package/ecs/database/database-schema/create-database-schema.js +3 -3
- package/ecs/database/database-schema/create-database-schema.js.map +1 -1
- package/ecs/database/database.d.ts +43 -5
- package/ecs/database/database.js.map +1 -1
- package/ecs/database/observe-dependent-value.test.js +39 -31
- package/ecs/database/observe-dependent-value.test.js.map +1 -1
- package/ecs/database/observe-select-entities.performance.test.js +30 -31
- package/ecs/database/observe-select-entities.performance.test.js.map +1 -1
- package/ecs/database/observe-select-entities.test.js +30 -31
- package/ecs/database/observe-select-entities.test.js.map +1 -1
- package/ecs/database/observed/create-observed-database.js +7 -0
- package/ecs/database/observed/create-observed-database.js.map +1 -1
- package/ecs/database/public/create-database.d.ts +5 -34
- package/ecs/database/public/create-database.js +68 -131
- package/ecs/database/public/create-database.js.map +1 -1
- package/ecs/database/public/create-database.test.js +324 -62
- package/ecs/database/public/create-database.test.js.map +1 -1
- package/ecs/database/transactional-store/create-transactional-store.js +16 -1
- package/ecs/database/transactional-store/create-transactional-store.js.map +1 -1
- package/ecs/plugins/scheduler/scheduler.d.ts +2 -2
- package/ecs/plugins/scheduler/scheduler.js +2 -2
- package/ecs/plugins/scheduler/scheduler.js.map +1 -1
- package/ecs/undo-redo-service/create-undo-redo-service.test.js +22 -23
- package/ecs/undo-redo-service/create-undo-redo-service.test.js.map +1 -1
- package/package.json +6 -24
- package/service/async-data-service/create-lazy.d.ts +40 -0
- package/service/async-data-service/create-lazy.js +194 -0
- package/service/async-data-service/create-lazy.js.map +1 -0
- package/service/async-data-service/create-lazy.test.js +477 -0
- package/service/async-data-service/create-lazy.test.js.map +1 -0
- package/service/async-data-service/example.d.ts +60 -0
- package/service/async-data-service/example.js +35 -0
- package/service/async-data-service/example.js.map +1 -0
- package/service/async-data-service/index.d.ts +1 -0
- package/service/async-data-service/index.js +3 -0
- package/service/async-data-service/index.js.map +1 -0
- package/service/{is-data-service.d.ts → async-data-service/is-valid.d.ts} +4 -4
- package/{lit/hooks/component/component.js → service/async-data-service/is-valid.js} +1 -1
- package/service/async-data-service/is-valid.js.map +1 -0
- package/service/async-data-service/public.d.ts +2 -0
- package/service/async-data-service/public.js +4 -0
- package/service/async-data-service/public.js.map +1 -0
- package/service/index.d.ts +1 -1
- package/service/index.js +1 -0
- package/service/index.js.map +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/ecs/database/combine-plugins-test.d.ts +0 -39
- package/ecs/database/combine-plugins-test.js +0 -3
- package/ecs/database/combine-plugins-test.js.map +0 -1
- package/ecs/database/create-plugin-cryos-pattern.test.d.ts +0 -3
- package/ecs/database/create-plugin-cryos-pattern.test.js +0 -83
- package/ecs/database/create-plugin-cryos-pattern.test.js.map +0 -1
- package/ecs/database/create-plugin-graphics.test.d.ts +0 -93
- package/ecs/database/create-plugin-graphics.test.js +0 -135
- package/ecs/database/create-plugin-graphics.test.js.map +0 -1
- package/ecs/database/create-plugin-type.type-test.js +0 -563
- package/ecs/database/create-plugin-type.type-test.js.map +0 -1
- package/ecs/database/create-plugin-type.type.test.d.ts +0 -1
- package/ecs/database/create-plugin-type.type.test.js +0 -563
- package/ecs/database/create-plugin-type.type.test.js.map +0 -1
- package/ecs/database/experimental-action-types.d.ts +0 -1
- package/ecs/database/experimental-action-types.js +0 -275
- package/ecs/database/experimental-action-types.js.map +0 -1
- package/ecs/database/from-plugin.type-test.d.ts +0 -1
- package/ecs/database/from-plugin.type-test.js +0 -180
- package/ecs/database/from-plugin.type-test.js.map +0 -1
- package/ecs/database/plugin-types.d.ts +0 -1
- package/ecs/database/plugin-types.js +0 -5
- package/ecs/database/plugin-types.js.map +0 -1
- package/ecs/database/type-investigation.test.d.ts +0 -1
- package/ecs/database/type-investigation.test.js +0 -54
- package/ecs/database/type-investigation.test.js.map +0 -1
- package/lit/decorators/apply-decorator.d.ts +0 -1
- package/lit/decorators/apply-decorator.js +0 -19
- package/lit/decorators/apply-decorator.js.map +0 -1
- package/lit/decorators/apply-service-decorators.d.ts +0 -1
- package/lit/decorators/apply-service-decorators.js +0 -13
- package/lit/decorators/apply-service-decorators.js.map +0 -1
- package/lit/decorators/index.d.ts +0 -3
- package/lit/decorators/index.js +0 -5
- package/lit/decorators/index.js.map +0 -1
- package/lit/decorators/require-service.d.ts +0 -1
- package/lit/decorators/require-service.js +0 -14
- package/lit/decorators/require-service.js.map +0 -1
- package/lit/elements/application-element.d.ts +0 -9
- package/lit/elements/application-element.js +0 -42
- package/lit/elements/application-element.js.map +0 -1
- package/lit/elements/application-host.d.ts +0 -16
- package/lit/elements/application-host.js +0 -39
- package/lit/elements/application-host.js.map +0 -1
- package/lit/elements/database-element.d.ts +0 -10
- package/lit/elements/database-element.js +0 -40
- package/lit/elements/database-element.js.map +0 -1
- package/lit/elements/index.d.ts +0 -3
- package/lit/elements/index.js +0 -5
- package/lit/elements/index.js.map +0 -1
- package/lit/functions/index.d.ts +0 -1
- package/lit/functions/index.js +0 -3
- package/lit/functions/index.js.map +0 -1
- package/lit/functions/iterate-self-and-ancestors.d.ts +0 -1
- package/lit/functions/iterate-self-and-ancestors.js +0 -24
- package/lit/functions/iterate-self-and-ancestors.js.map +0 -1
- package/lit/hooks/attach-decorator.d.ts +0 -4
- package/lit/hooks/attach-decorator.js +0 -26
- package/lit/hooks/attach-decorator.js.map +0 -1
- package/lit/hooks/component/component.d.ts +0 -10
- package/lit/hooks/component/component.js.map +0 -1
- package/lit/hooks/component/stack.d.ts +0 -6
- package/lit/hooks/component/stack.js +0 -16
- package/lit/hooks/component/stack.js.map +0 -1
- package/lit/hooks/index.d.ts +0 -19
- package/lit/hooks/index.js +0 -21
- package/lit/hooks/index.js.map +0 -1
- package/lit/hooks/use-connected.d.ts +0 -2
- package/lit/hooks/use-connected.js +0 -32
- package/lit/hooks/use-connected.js.map +0 -1
- package/lit/hooks/use-debounce.d.ts +0 -8
- package/lit/hooks/use-debounce.js +0 -21
- package/lit/hooks/use-debounce.js.map +0 -1
- package/lit/hooks/use-drag-observe.d.ts +0 -25
- package/lit/hooks/use-drag-observe.js +0 -35
- package/lit/hooks/use-drag-observe.js.map +0 -1
- package/lit/hooks/use-drag-transaction.d.ts +0 -7
- package/lit/hooks/use-drag-transaction.js +0 -35
- package/lit/hooks/use-drag-transaction.js.map +0 -1
- package/lit/hooks/use-draggable.d.ts +0 -15
- package/lit/hooks/use-draggable.js +0 -96
- package/lit/hooks/use-draggable.js.map +0 -1
- package/lit/hooks/use-effect.d.ts +0 -3
- package/lit/hooks/use-effect.js +0 -14
- package/lit/hooks/use-effect.js.map +0 -1
- package/lit/hooks/use-element.d.ts +0 -7
- package/lit/hooks/use-element.js +0 -67
- package/lit/hooks/use-element.js.map +0 -1
- package/lit/hooks/use-memo.d.ts +0 -1
- package/lit/hooks/use-memo.js +0 -13
- package/lit/hooks/use-memo.js.map +0 -1
- package/lit/hooks/use-observable-values.d.ts +0 -4
- package/lit/hooks/use-observable-values.js +0 -9
- package/lit/hooks/use-observable-values.js.map +0 -1
- package/lit/hooks/use-observable.d.ts +0 -2
- package/lit/hooks/use-observable.js +0 -13
- package/lit/hooks/use-observable.js.map +0 -1
- package/lit/hooks/use-ref.d.ts +0 -3
- package/lit/hooks/use-ref.js +0 -7
- package/lit/hooks/use-ref.js.map +0 -1
- package/lit/hooks/use-resize-observer.d.ts +0 -12
- package/lit/hooks/use-resize-observer.js +0 -23
- package/lit/hooks/use-resize-observer.js.map +0 -1
- package/lit/hooks/use-state.d.ts +0 -2
- package/lit/hooks/use-state.js +0 -15
- package/lit/hooks/use-state.js.map +0 -1
- package/lit/hooks/use-updated.d.ts +0 -4
- package/lit/hooks/use-updated.js +0 -40
- package/lit/hooks/use-updated.js.map +0 -1
- package/lit/hooks/use-window-event.d.ts +0 -1
- package/lit/hooks/use-window-event.js +0 -11
- package/lit/hooks/use-window-event.js.map +0 -1
- package/lit/hooks/with-hooks.d.ts +0 -2
- package/lit/hooks/with-hooks.js +0 -16
- package/lit/hooks/with-hooks.js.map +0 -1
- package/lit/index.d.ts +0 -4
- package/lit/index.js +0 -5
- package/lit/index.js.map +0 -1
- package/normalize.test.d.ts +0 -1
- package/normalize.test.js +0 -28
- package/normalize.test.js.map +0 -1
- package/samples/index.d.ts +0 -13
- package/samples/index.js +0 -7
- package/samples/index.js.map +0 -1
- package/samples/todo/elements/todo-list/todo-list-presentation.d.ts +0 -8
- package/samples/todo/elements/todo-list/todo-list-presentation.js +0 -12
- package/samples/todo/elements/todo-list/todo-list-presentation.js.map +0 -1
- package/samples/todo/elements/todo-list/todo-list.css.d.ts +0 -1
- package/samples/todo/elements/todo-list/todo-list.css.js +0 -11
- package/samples/todo/elements/todo-list/todo-list.css.js.map +0 -1
- package/samples/todo/elements/todo-list/todo-list.d.ts +0 -12
- package/samples/todo/elements/todo-list/todo-list.js +0 -44
- package/samples/todo/elements/todo-list/todo-list.js.map +0 -1
- package/samples/todo/elements/todo-row/index.d.ts +0 -1
- package/samples/todo/elements/todo-row/index.js +0 -3
- package/samples/todo/elements/todo-row/index.js.map +0 -1
- package/samples/todo/elements/todo-row/todo-row-presentation.d.ts +0 -18
- package/samples/todo/elements/todo-row/todo-row-presentation.js +0 -50
- package/samples/todo/elements/todo-row/todo-row-presentation.js.map +0 -1
- package/samples/todo/elements/todo-row/todo-row.css.d.ts +0 -1
- package/samples/todo/elements/todo-row/todo-row.css.js +0 -49
- package/samples/todo/elements/todo-row/todo-row.css.js.map +0 -1
- package/samples/todo/elements/todo-row/todo-row.d.ts +0 -14
- package/samples/todo/elements/todo-row/todo-row.js +0 -44
- package/samples/todo/elements/todo-row/todo-row.js.map +0 -1
- package/samples/todo/elements/todo-toolbar/index.d.ts +0 -1
- package/samples/todo/elements/todo-toolbar/index.js +0 -3
- package/samples/todo/elements/todo-toolbar/index.js.map +0 -1
- package/samples/todo/elements/todo-toolbar/todo-toolbar-presentation.d.ts +0 -22
- package/samples/todo/elements/todo-toolbar/todo-toolbar-presentation.js +0 -41
- package/samples/todo/elements/todo-toolbar/todo-toolbar-presentation.js.map +0 -1
- package/samples/todo/elements/todo-toolbar/todo-toolbar.css.d.ts +0 -1
- package/samples/todo/elements/todo-toolbar/todo-toolbar.css.js +0 -34
- package/samples/todo/elements/todo-toolbar/todo-toolbar.css.js.map +0 -1
- package/samples/todo/elements/todo-toolbar/todo-toolbar.d.ts +0 -11
- package/samples/todo/elements/todo-toolbar/todo-toolbar.js +0 -61
- package/samples/todo/elements/todo-toolbar/todo-toolbar.js.map +0 -1
- package/samples/todo/elements/todo-undo-redo/index.d.ts +0 -1
- package/samples/todo/elements/todo-undo-redo/index.js +0 -3
- package/samples/todo/elements/todo-undo-redo/index.js.map +0 -1
- package/samples/todo/elements/todo-undo-redo/todo-undo-redo-presentation.d.ts +0 -17
- package/samples/todo/elements/todo-undo-redo/todo-undo-redo-presentation.js +0 -29
- package/samples/todo/elements/todo-undo-redo/todo-undo-redo-presentation.js.map +0 -1
- package/samples/todo/elements/todo-undo-redo/todo-undo-redo.css.d.ts +0 -1
- package/samples/todo/elements/todo-undo-redo/todo-undo-redo.css.js +0 -12
- package/samples/todo/elements/todo-undo-redo/todo-undo-redo.css.js.map +0 -1
- package/samples/todo/elements/todo-undo-redo/todo-undo-redo.d.ts +0 -11
- package/samples/todo/elements/todo-undo-redo/todo-undo-redo.js +0 -36
- package/samples/todo/elements/todo-undo-redo/todo-undo-redo.js.map +0 -1
- package/samples/todo/services/dependent-state-service/create-dependent-state-service.d.ts +0 -6
- package/samples/todo/services/dependent-state-service/create-dependent-state-service.js +0 -5
- package/samples/todo/services/dependent-state-service/create-dependent-state-service.js.map +0 -1
- package/samples/todo/services/dependent-state-service/dependent-state/all-todos.d.ts +0 -2
- package/samples/todo/services/dependent-state-service/dependent-state/all-todos.js +0 -2
- package/samples/todo/services/dependent-state-service/dependent-state/all-todos.js.map +0 -1
- package/samples/todo/services/dependent-state-service/dependent-state/complete-todos.d.ts +0 -2
- package/samples/todo/services/dependent-state-service/dependent-state/complete-todos.js +0 -2
- package/samples/todo/services/dependent-state-service/dependent-state/complete-todos.js.map +0 -1
- package/samples/todo/services/dependent-state-service/dependent-state/incomplete-todos.d.ts +0 -2
- package/samples/todo/services/dependent-state-service/dependent-state/incomplete-todos.js +0 -2
- package/samples/todo/services/dependent-state-service/dependent-state/incomplete-todos.js.map +0 -1
- package/samples/todo/services/dependent-state-service/dependent-state/index.d.ts +0 -3
- package/samples/todo/services/dependent-state-service/dependent-state/index.js +0 -5
- package/samples/todo/services/dependent-state-service/dependent-state/index.js.map +0 -1
- package/samples/todo/services/dependent-state-service/dependent-state-service.d.ts +0 -2
- package/samples/todo/services/dependent-state-service/dependent-state-service.js +0 -2
- package/samples/todo/services/dependent-state-service/dependent-state-service.js.map +0 -1
- package/samples/todo/services/main-service/create-main-service.d.ts +0 -8
- package/samples/todo/services/main-service/create-main-service.js +0 -39
- package/samples/todo/services/main-service/create-main-service.js.map +0 -1
- package/samples/todo/services/main-service/todo-main-service.d.ts +0 -18
- package/samples/todo/services/main-service/todo-main-service.js +0 -2
- package/samples/todo/services/main-service/todo-main-service.js.map +0 -1
- package/samples/todo/services/state-service/create-todo-database.d.ts +0 -37
- package/samples/todo/services/state-service/create-todo-database.js +0 -10
- package/samples/todo/services/state-service/create-todo-database.js.map +0 -1
- package/samples/todo/services/state-service/create-todo-store.d.ts +0 -37
- package/samples/todo/services/state-service/create-todo-store.js +0 -24
- package/samples/todo/services/state-service/create-todo-store.js.map +0 -1
- package/samples/todo/services/state-service/todo-state-service.d.ts +0 -5
- package/samples/todo/services/state-service/todo-state-service.js +0 -2
- package/samples/todo/services/state-service/todo-state-service.js.map +0 -1
- package/samples/todo/services/state-service/transactions/create-bulk-todos.d.ts +0 -2
- package/samples/todo/services/state-service/transactions/create-bulk-todos.js +0 -10
- package/samples/todo/services/state-service/transactions/create-bulk-todos.js.map +0 -1
- package/samples/todo/services/state-service/transactions/create-todo.d.ts +0 -5
- package/samples/todo/services/state-service/transactions/create-todo.js +0 -13
- package/samples/todo/services/state-service/transactions/create-todo.js.map +0 -1
- package/samples/todo/services/state-service/transactions/create-todo.test.d.ts +0 -1
- package/samples/todo/services/state-service/transactions/create-todo.test.js +0 -16
- package/samples/todo/services/state-service/transactions/create-todo.test.js.map +0 -1
- package/samples/todo/services/state-service/transactions/delete-all-todos.d.ts +0 -2
- package/samples/todo/services/state-service/transactions/delete-all-todos.js +0 -16
- package/samples/todo/services/state-service/transactions/delete-all-todos.js.map +0 -1
- package/samples/todo/services/state-service/transactions/delete-todo.d.ts +0 -3
- package/samples/todo/services/state-service/transactions/delete-todo.js +0 -8
- package/samples/todo/services/state-service/transactions/delete-todo.js.map +0 -1
- package/samples/todo/services/state-service/transactions/delete-todo.test.d.ts +0 -1
- package/samples/todo/services/state-service/transactions/delete-todo.test.js +0 -24
- package/samples/todo/services/state-service/transactions/delete-todo.test.js.map +0 -1
- package/samples/todo/services/state-service/transactions/drag-todo.d.ts +0 -7
- package/samples/todo/services/state-service/transactions/drag-todo.js +0 -17
- package/samples/todo/services/state-service/transactions/drag-todo.js.map +0 -1
- package/samples/todo/services/state-service/transactions/index.d.ts +0 -6
- package/samples/todo/services/state-service/transactions/index.js +0 -9
- package/samples/todo/services/state-service/transactions/index.js.map +0 -1
- package/samples/todo/services/state-service/transactions/reorder-todos.d.ts +0 -6
- package/samples/todo/services/state-service/transactions/reorder-todos.js +0 -11
- package/samples/todo/services/state-service/transactions/reorder-todos.js.map +0 -1
- package/samples/todo/services/state-service/transactions/toggle-complete.d.ts +0 -3
- package/samples/todo/services/state-service/transactions/toggle-complete.js +0 -11
- package/samples/todo/services/state-service/transactions/toggle-complete.js.map +0 -1
- package/samples/todo/services/state-service/transactions/toggle-complete.test.d.ts +0 -1
- package/samples/todo/services/state-service/transactions/toggle-complete.test.js +0 -65
- package/samples/todo/services/state-service/transactions/toggle-complete.test.js.map +0 -1
- package/samples/todo/todo-element.d.ts +0 -4
- package/samples/todo/todo-element.js +0 -4
- package/samples/todo/todo-element.js.map +0 -1
- package/samples/todo/todo-host.d.ts +0 -8
- package/samples/todo/todo-host.js +0 -35
- package/samples/todo/todo-host.js.map +0 -1
- package/samples/todo/todo-main-element.d.ts +0 -10
- package/samples/todo/todo-main-element.js +0 -47
- package/samples/todo/todo-main-element.js.map +0 -1
- package/samples/todo/todo-sample.d.ts +0 -3
- package/samples/todo/todo-sample.js +0 -19
- package/samples/todo/todo-sample.js.map +0 -1
- package/service/is-data-service.js +0 -2
- package/service/is-data-service.js.map +0 -1
- package/typed-buffer/public.d.ts +0 -2
- package/typed-buffer/public.js +0 -4
- package/typed-buffer/public.js.map +0 -1
- /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 {
|
|
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
|
-
|
|
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 {
|
|
729
|
-
const database = Database.create(
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
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 {
|
|
748
|
-
const database = Database.create(
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
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
|
-
|
|
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 {
|
|
778
|
-
const database = Database.create(
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
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
|
-
|
|
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
|
-
|
|
808
|
-
const { baseStore, actions } = createStoreConfig();
|
|
830
|
+
const { actions, storeSchema } = createStoreConfig();
|
|
809
831
|
const systemOneCalled = vi.fn();
|
|
810
|
-
const database = Database.create(
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
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: (
|
|
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", () => {
|