@adobe/data 0.8.6 → 0.9.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.
- package/dist/ecs/database/calculate-system-order.d.ts +18 -0
- package/dist/ecs/database/calculate-system-order.js +113 -0
- package/dist/ecs/database/calculate-system-order.js.map +1 -0
- package/dist/ecs/database/calculate-system-order.test.d.ts +1 -0
- package/dist/ecs/database/calculate-system-order.test.js +168 -0
- package/dist/ecs/database/calculate-system-order.test.js.map +1 -0
- package/dist/ecs/database/create-plugin.d.ts +67 -0
- package/dist/ecs/database/create-plugin.js +47 -0
- package/dist/ecs/database/create-plugin.js.map +1 -0
- package/dist/ecs/database/create-plugin.test.d.ts +1 -0
- package/dist/ecs/database/create-plugin.test.js +435 -0
- package/dist/ecs/database/create-plugin.test.js.map +1 -0
- package/dist/ecs/database/database-schema/create-database-schema.d.ts +3 -3
- package/dist/ecs/database/database-schema/database-schema.d.ts +4 -3
- package/dist/ecs/database/database.d.ts +56 -18
- package/dist/ecs/database/database.js +42 -0
- package/dist/ecs/database/database.js.map +1 -1
- package/dist/ecs/database/database.test.d.ts +1 -0
- package/dist/ecs/database/database.test.js +200 -0
- package/dist/ecs/database/database.test.js.map +1 -0
- package/dist/ecs/database/observe-select-entities.test.js +3 -3
- package/dist/ecs/database/observe-select-entities.test.js.map +1 -1
- package/dist/ecs/database/observed/create-observed-database.js +6 -1
- package/dist/ecs/database/observed/create-observed-database.js.map +1 -1
- package/dist/ecs/database/observed/create-observed-database.test.js +105 -49
- package/dist/ecs/database/observed/create-observed-database.test.js.map +1 -1
- package/dist/ecs/database/observed/observed-database.d.ts +3 -0
- package/dist/ecs/database/public/create-database-from-schema.test.d.ts +1 -0
- package/dist/ecs/database/public/create-database-from-schema.test.js +153 -0
- package/dist/ecs/database/public/create-database-from-schema.test.js.map +1 -0
- package/dist/ecs/database/public/create-database.d.ts +17 -2
- package/dist/ecs/database/public/create-database.js +283 -79
- package/dist/ecs/database/public/create-database.js.map +1 -1
- package/dist/ecs/database/public/create-database.test.js +178 -47
- package/dist/ecs/database/public/create-database.test.js.map +1 -1
- package/dist/ecs/database/reconciling/create-reconciling-database.d.ts +2 -2
- package/dist/ecs/database/reconciling/create-reconciling-database.js +7 -2
- package/dist/ecs/database/reconciling/create-reconciling-database.js.map +1 -1
- package/dist/ecs/database/reconciling/create-reconciling-database.test.js +18 -9
- package/dist/ecs/database/reconciling/create-reconciling-database.test.js.map +1 -1
- package/dist/ecs/database/reconciling/reconciling-database.d.ts +5 -3
- package/dist/ecs/database/transactional-store/coalesce-actions.d.ts +16 -0
- package/dist/ecs/database/transactional-store/coalesce-actions.js +140 -0
- package/dist/ecs/database/transactional-store/coalesce-actions.js.map +1 -0
- package/dist/ecs/database/transactional-store/coalesce-actions.test.d.ts +1 -0
- package/dist/ecs/database/transactional-store/coalesce-actions.test.js +433 -0
- package/dist/ecs/database/transactional-store/coalesce-actions.test.js.map +1 -0
- package/dist/ecs/database/transactional-store/create-transactional-store.js +18 -2
- package/dist/ecs/database/transactional-store/create-transactional-store.js.map +1 -1
- package/dist/ecs/database/transactional-store/create-transactional-store.test.js +13 -3
- package/dist/ecs/database/transactional-store/create-transactional-store.test.js.map +1 -1
- package/dist/ecs/database/transactional-store/transactional-store.d.ts +2 -0
- package/dist/ecs/database/type-inference-example.d.ts +1 -0
- package/dist/ecs/database/type-inference-example.js +2 -0
- package/dist/ecs/database/type-inference-example.js.map +1 -0
- package/dist/ecs/plugins/index.d.ts +1 -0
- package/dist/ecs/plugins/index.js +23 -0
- package/dist/ecs/plugins/index.js.map +1 -0
- package/dist/ecs/plugins/scheduler/index.d.ts +1 -0
- package/dist/ecs/plugins/scheduler/index.js +23 -0
- package/dist/ecs/plugins/scheduler/index.js.map +1 -0
- package/dist/ecs/plugins/scheduler/scheduler.d.ts +8 -0
- package/dist/ecs/plugins/scheduler/scheduler.js +52 -0
- package/dist/ecs/plugins/scheduler/scheduler.js.map +1 -0
- package/dist/ecs/store/action-functions.d.ts +21 -0
- package/dist/ecs/store/action-functions.js +2 -0
- package/dist/ecs/store/action-functions.js.map +1 -0
- package/dist/ecs/store/create-store-schema-test.js +70 -8
- package/dist/ecs/store/create-store-schema-test.js.map +1 -1
- package/dist/ecs/store/public/create-store.js +9 -8
- package/dist/ecs/store/public/create-store.js.map +1 -1
- package/dist/ecs/store/public/create-store.test.js +5 -0
- package/dist/ecs/store/public/create-store.test.js.map +1 -1
- package/dist/ecs/store/store.d.ts +46 -13
- package/dist/ecs/store/store.js +35 -2
- package/dist/ecs/store/store.js.map +1 -1
- package/dist/ecs/store/store.test.d.ts +1 -0
- package/dist/ecs/store/store.test.js +211 -0
- package/dist/ecs/store/store.test.js.map +1 -0
- package/dist/ecs/undo-redo-service/create-undo-redo-service.js +1 -1
- package/dist/ecs/undo-redo-service/create-undo-redo-service.js.map +1 -1
- package/dist/lit/hooks/use-drag-transaction.d.ts +1 -1
- package/dist/samples/todo/services/main-service/todo-main-service.d.ts +1 -1
- package/dist/samples/todo/services/state-service/create-todo-database.d.ts +3 -3
- package/dist/samples/todo/services/state-service/create-todo-database.js +2 -2
- package/dist/samples/todo/services/state-service/create-todo-database.js.map +1 -1
- package/dist/samples/todo/services/state-service/create-todo-store.d.ts +1 -1
- package/dist/samples/todo/services/state-service/transactions/toggle-complete.js +1 -1
- package/dist/samples/todo/services/state-service/transactions/toggle-complete.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types.d.ts +2 -0
- package/dist/types/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
import { describe, it, expect } from "vitest";
|
|
23
|
+
import { createPlugin } from "./create-plugin.js";
|
|
24
|
+
describe("Database.Plugin.create", () => {
|
|
25
|
+
describe("single descriptor (no dependencies)", () => {
|
|
26
|
+
it("should create plugin with components, resources, and archetypes", () => {
|
|
27
|
+
const plugin = createPlugin({
|
|
28
|
+
components: {
|
|
29
|
+
velocity: { type: "number" },
|
|
30
|
+
particle: { type: "boolean" },
|
|
31
|
+
},
|
|
32
|
+
resources: {
|
|
33
|
+
mousePosition: { default: 0 },
|
|
34
|
+
fooPosition: { default: 0 },
|
|
35
|
+
},
|
|
36
|
+
archetypes: {
|
|
37
|
+
Particle: ["particle"],
|
|
38
|
+
DynamicParticle: ["particle", "velocity"],
|
|
39
|
+
},
|
|
40
|
+
systems: {
|
|
41
|
+
updateSystem: {
|
|
42
|
+
create: (db) => () => {
|
|
43
|
+
db.store.archetypes.Particle.insert({ particle: true });
|
|
44
|
+
db.archetypes.Particle.id.toString();
|
|
45
|
+
// @ts-expect-error - foo does not exist
|
|
46
|
+
db.archetypes.foo;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it("should infer db type correctly with single descriptor", () => {
|
|
53
|
+
const plugin = createPlugin({
|
|
54
|
+
resources: {
|
|
55
|
+
time: { default: 0 },
|
|
56
|
+
},
|
|
57
|
+
systems: {
|
|
58
|
+
physicsSystem: {
|
|
59
|
+
create: (db) => () => {
|
|
60
|
+
const time = db.resources.time;
|
|
61
|
+
// @ts-expect-error - this should be an error
|
|
62
|
+
const dt = db.resources.deltaTime2;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
expect(plugin).toBeDefined();
|
|
68
|
+
expect(plugin.systems).toBeDefined();
|
|
69
|
+
});
|
|
70
|
+
it("should constrain archetype references at input", () => {
|
|
71
|
+
createPlugin({
|
|
72
|
+
components: {
|
|
73
|
+
particle: { type: "boolean" },
|
|
74
|
+
},
|
|
75
|
+
archetypes: {
|
|
76
|
+
Particle: ["particle"],
|
|
77
|
+
// @ts-expect-error - DoesNotExist component does not exist
|
|
78
|
+
DoesNotExist: ["particle234"],
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
it("should constrain archetype access in systems", () => {
|
|
83
|
+
createPlugin({
|
|
84
|
+
components: {
|
|
85
|
+
particle: { type: "boolean" },
|
|
86
|
+
},
|
|
87
|
+
archetypes: {
|
|
88
|
+
Particle: ["particle"],
|
|
89
|
+
},
|
|
90
|
+
systems: {
|
|
91
|
+
testSystem: {
|
|
92
|
+
create: (db) => () => {
|
|
93
|
+
db.archetypes.Particle; // ✅ OK
|
|
94
|
+
// @ts-expect-error - foo does not exist
|
|
95
|
+
db.archetypes.foo;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
it("should constrain schedule references to dependency system names", () => {
|
|
102
|
+
const plugin = createPlugin({
|
|
103
|
+
systems: {
|
|
104
|
+
renderSystem: {
|
|
105
|
+
create: (_db) => () => { },
|
|
106
|
+
schedule: {
|
|
107
|
+
after: ["update"],
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}, [
|
|
112
|
+
createPlugin({
|
|
113
|
+
systems: {
|
|
114
|
+
update: {
|
|
115
|
+
create: (_db) => () => { }
|
|
116
|
+
},
|
|
117
|
+
render: {
|
|
118
|
+
create: (_db) => () => { }
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
]);
|
|
123
|
+
expect(plugin).toBeDefined();
|
|
124
|
+
expect(plugin.systems).toBeDefined();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
describe("with dependencies", () => {
|
|
128
|
+
it("should merge components from dependencies", () => {
|
|
129
|
+
const basePlugin = createPlugin({
|
|
130
|
+
components: {
|
|
131
|
+
position: { type: "number" },
|
|
132
|
+
health: { type: "number" }
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
const extendedPlugin = createPlugin({
|
|
136
|
+
components: {
|
|
137
|
+
velocity: { type: "number" }
|
|
138
|
+
}
|
|
139
|
+
}, [basePlugin]);
|
|
140
|
+
expect("position" in extendedPlugin.components).toBe(true);
|
|
141
|
+
expect("health" in extendedPlugin.components).toBe(true);
|
|
142
|
+
expect("velocity" in extendedPlugin.components).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
it("should merge resources from dependencies", () => {
|
|
145
|
+
const basePlugin = createPlugin({
|
|
146
|
+
resources: {
|
|
147
|
+
time: { default: 0 },
|
|
148
|
+
config: { default: "default" }
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
const extendedPlugin = createPlugin({
|
|
152
|
+
resources: {
|
|
153
|
+
delta: { default: 0 }
|
|
154
|
+
}
|
|
155
|
+
}, [basePlugin]);
|
|
156
|
+
expect("time" in extendedPlugin.resources).toBe(true);
|
|
157
|
+
expect("config" in extendedPlugin.resources).toBe(true);
|
|
158
|
+
expect("delta" in extendedPlugin.resources).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
it("should merge systems from dependencies", () => {
|
|
161
|
+
const basePlugin = createPlugin({
|
|
162
|
+
systems: {
|
|
163
|
+
inputSystem: {
|
|
164
|
+
create: (_db) => () => { }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
const extendedPlugin = createPlugin({
|
|
169
|
+
systems: {
|
|
170
|
+
renderSystem: {
|
|
171
|
+
create: (_db) => () => { }
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}, [basePlugin]);
|
|
175
|
+
expect("inputSystem" in extendedPlugin.systems).toBe(true);
|
|
176
|
+
expect("renderSystem" in extendedPlugin.systems).toBe(true);
|
|
177
|
+
});
|
|
178
|
+
it("should allow systems to access dependency resources", () => {
|
|
179
|
+
const basePlugin = createPlugin({
|
|
180
|
+
resources: {
|
|
181
|
+
time: { default: 0 }
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
const extendedPlugin = createPlugin({
|
|
185
|
+
systems: {
|
|
186
|
+
mySystem: {
|
|
187
|
+
create: (db) => () => {
|
|
188
|
+
const time = db.resources.time; // Should work!
|
|
189
|
+
expect(typeof time).toBe("number");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}, [basePlugin]);
|
|
194
|
+
expect(extendedPlugin).toBeDefined();
|
|
195
|
+
});
|
|
196
|
+
it("should allow multiple dependencies", () => {
|
|
197
|
+
const plugin1 = createPlugin({
|
|
198
|
+
components: { a: { type: "number" } }
|
|
199
|
+
});
|
|
200
|
+
const plugin2 = createPlugin({
|
|
201
|
+
components: { b: { type: "string" } }
|
|
202
|
+
});
|
|
203
|
+
const plugin3 = createPlugin({
|
|
204
|
+
components: { c: { type: "boolean" } }
|
|
205
|
+
});
|
|
206
|
+
const merged = createPlugin({
|
|
207
|
+
components: { d: { type: "number" } }
|
|
208
|
+
}, [plugin1, plugin2, plugin3]);
|
|
209
|
+
expect("a" in merged.components).toBe(true);
|
|
210
|
+
expect("b" in merged.components).toBe(true);
|
|
211
|
+
expect("c" in merged.components).toBe(true);
|
|
212
|
+
expect("d" in merged.components).toBe(true);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
describe("schedule validation", () => {
|
|
216
|
+
it("should allow valid system references in schedule", () => {
|
|
217
|
+
expect(() => {
|
|
218
|
+
createPlugin({
|
|
219
|
+
systems: {
|
|
220
|
+
system1: {
|
|
221
|
+
create: (_db) => () => { }
|
|
222
|
+
},
|
|
223
|
+
system2: {
|
|
224
|
+
create: (_db) => () => { },
|
|
225
|
+
schedule: {
|
|
226
|
+
// @ts-expect-error - system1 does not exist
|
|
227
|
+
after: ["system1"]
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}).not.toThrow();
|
|
233
|
+
});
|
|
234
|
+
it("should allow referencing dependency systems in schedule", () => {
|
|
235
|
+
const basePlugin = createPlugin({
|
|
236
|
+
systems: {
|
|
237
|
+
inputSystem: {
|
|
238
|
+
create: (_db) => () => { }
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
expect(() => {
|
|
243
|
+
createPlugin({
|
|
244
|
+
systems: {
|
|
245
|
+
renderSystem: {
|
|
246
|
+
create: (_db) => () => { },
|
|
247
|
+
schedule: {
|
|
248
|
+
after: ["inputSystem"] // Reference from dependency!
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}, [basePlugin]);
|
|
253
|
+
}).not.toThrow();
|
|
254
|
+
});
|
|
255
|
+
it("should validate across multiple dependencies", () => {
|
|
256
|
+
const plugin1 = createPlugin({
|
|
257
|
+
systems: {
|
|
258
|
+
system1: {
|
|
259
|
+
create: (_db) => () => { }
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
const plugin2 = createPlugin({
|
|
264
|
+
systems: {
|
|
265
|
+
system2: {
|
|
266
|
+
create: (_db) => () => { }
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
expect(() => {
|
|
271
|
+
createPlugin({
|
|
272
|
+
systems: {
|
|
273
|
+
system3: {
|
|
274
|
+
create: (_db) => () => { },
|
|
275
|
+
schedule: {
|
|
276
|
+
after: ["system1", "system2"] // Both from dependencies
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}, [plugin1, plugin2]);
|
|
281
|
+
}).not.toThrow();
|
|
282
|
+
});
|
|
283
|
+
it("should constrain schedule references to dependency system names", () => {
|
|
284
|
+
const basePlugin = createPlugin({
|
|
285
|
+
systems: {
|
|
286
|
+
inputSystem: {
|
|
287
|
+
create: (_db) => () => { }
|
|
288
|
+
},
|
|
289
|
+
physicsSystem: {
|
|
290
|
+
create: (_db) => () => { }
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
// ✅ VALID: referencing actual systems from dependencies (no 'as const' needed!)
|
|
295
|
+
const validPlugin = createPlugin({
|
|
296
|
+
systems: {
|
|
297
|
+
renderSystem: {
|
|
298
|
+
create: (_db) => () => { },
|
|
299
|
+
schedule: {
|
|
300
|
+
// TypeScript autocompletes: "inputSystem" | "physicsSystem"
|
|
301
|
+
after: ["inputSystem", "physicsSystem"]
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}, [basePlugin]);
|
|
306
|
+
expect(validPlugin).toBeDefined();
|
|
307
|
+
expect(validPlugin.systems).toHaveProperty("renderSystem");
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
describe("type inference edge cases", () => {
|
|
311
|
+
it("should block arbitrary property access on resources", () => {
|
|
312
|
+
const plugin = createPlugin({
|
|
313
|
+
resources: {
|
|
314
|
+
time: { default: 0 }
|
|
315
|
+
},
|
|
316
|
+
systems: {
|
|
317
|
+
testSystem: {
|
|
318
|
+
create: (db) => () => {
|
|
319
|
+
const time = db.resources.time; // OK
|
|
320
|
+
// @ts-expect-error - should error
|
|
321
|
+
const invalid = db.resources.nonExistent;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
expect(plugin).toBeDefined();
|
|
327
|
+
});
|
|
328
|
+
it("should block arbitrary property access with dependencies", () => {
|
|
329
|
+
const basePlugin = createPlugin({
|
|
330
|
+
resources: {
|
|
331
|
+
time: { default: 0 }
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
const extendedPlugin = createPlugin({
|
|
335
|
+
resources: {
|
|
336
|
+
delta: { default: 0 }
|
|
337
|
+
},
|
|
338
|
+
systems: {
|
|
339
|
+
testSystem: {
|
|
340
|
+
create: (db) => () => {
|
|
341
|
+
const time = db.resources.time; // OK - from dependency
|
|
342
|
+
const delta = db.resources.delta; // OK - from descriptor
|
|
343
|
+
// @ts-expect-error - should error
|
|
344
|
+
const invalid = db.resources.nonExistent;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}, [basePlugin]);
|
|
349
|
+
expect(extendedPlugin).toBeDefined();
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
describe("identity validation", () => {
|
|
353
|
+
it("should throw error when merging different component definitions", () => {
|
|
354
|
+
const plugin1 = createPlugin({
|
|
355
|
+
components: {
|
|
356
|
+
health: { type: "number" }
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
expect(() => {
|
|
360
|
+
createPlugin({
|
|
361
|
+
components: {
|
|
362
|
+
health: { type: "string" } // Different definition
|
|
363
|
+
}
|
|
364
|
+
}, [plugin1]);
|
|
365
|
+
}).toThrow('Plugin merge conflict: components.health must be identical (===) across plugins');
|
|
366
|
+
});
|
|
367
|
+
it("should throw error when merging different resource definitions", () => {
|
|
368
|
+
const plugin1 = createPlugin({
|
|
369
|
+
resources: {
|
|
370
|
+
score: { default: 0 }
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
expect(() => {
|
|
374
|
+
createPlugin({
|
|
375
|
+
resources: {
|
|
376
|
+
score: { default: 100 } // Different definition
|
|
377
|
+
}
|
|
378
|
+
}, [plugin1]);
|
|
379
|
+
}).toThrow('Plugin merge conflict: resources.score must be identical (===) across plugins');
|
|
380
|
+
});
|
|
381
|
+
it("should throw error when merging different archetype definitions", () => {
|
|
382
|
+
const plugin1 = createPlugin({
|
|
383
|
+
components: {
|
|
384
|
+
position: { type: "number" },
|
|
385
|
+
velocity: { type: "number" }
|
|
386
|
+
},
|
|
387
|
+
archetypes: {
|
|
388
|
+
Entity: ["position"]
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
expect(() => {
|
|
392
|
+
createPlugin({
|
|
393
|
+
archetypes: {
|
|
394
|
+
Entity: ["position", "velocity"] // Different definition
|
|
395
|
+
}
|
|
396
|
+
}, [plugin1]);
|
|
397
|
+
}).toThrow('Plugin merge conflict: archetypes.Entity must be identical (===) across plugins');
|
|
398
|
+
});
|
|
399
|
+
it("should allow same component with identical reference", () => {
|
|
400
|
+
const sharedComponent = { type: "number" };
|
|
401
|
+
const plugin1 = createPlugin({
|
|
402
|
+
components: {
|
|
403
|
+
health: sharedComponent
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
expect(() => {
|
|
407
|
+
createPlugin({
|
|
408
|
+
components: {
|
|
409
|
+
health: sharedComponent // Same reference - OK
|
|
410
|
+
}
|
|
411
|
+
}, [plugin1]);
|
|
412
|
+
}).not.toThrow();
|
|
413
|
+
});
|
|
414
|
+
it("should allow overwriting systems", () => {
|
|
415
|
+
const plugin1 = createPlugin({
|
|
416
|
+
systems: {
|
|
417
|
+
update: {
|
|
418
|
+
create: () => () => { }
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
// Should not throw - systems can be overwritten
|
|
423
|
+
expect(() => {
|
|
424
|
+
createPlugin({
|
|
425
|
+
systems: {
|
|
426
|
+
update: {
|
|
427
|
+
create: () => () => { } // Different function - OK
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}, [plugin1]);
|
|
431
|
+
}).not.toThrow();
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
//# sourceMappingURL=create-plugin.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-plugin.test.js","sourceRoot":"","sources":["../../../src/ecs/database/create-plugin.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAEX,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACpC,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;QACjD,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACvE,MAAM,MAAM,GAAG,YAAY,CAAC;gBACxB,UAAU,EAAE;oBACR,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBAC5B,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;iBAChC;gBACD,SAAS,EAAE;oBACP,aAAa,EAAE,EAAE,OAAO,EAAE,CAAW,EAAE;oBACvC,WAAW,EAAE,EAAE,OAAO,EAAE,CAAW,EAAE;iBACxC;gBACD,UAAU,EAAE;oBACR,QAAQ,EAAE,CAAC,UAAU,CAAC;oBACtB,eAAe,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC;iBAC5C;gBACD,OAAO,EAAE;oBACL,YAAY,EAAE;wBACV,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE;4BACjB,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,EA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,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,0BAA0B;yBACrD;qBACJ;iBACJ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -3,12 +3,12 @@ import { StringKeyof } from "../../../types/types.js";
|
|
|
3
3
|
import { ComponentSchemas } from "../../component-schemas.js";
|
|
4
4
|
import { ResourceSchemas } from "../../resource-schemas.js";
|
|
5
5
|
import { ArchetypeComponents } from "../../store/archetype-components.js";
|
|
6
|
-
import {
|
|
6
|
+
import type { ActionDeclarations } from "../../store/action-functions.js";
|
|
7
7
|
import { DatabaseFromSchema, DatabaseSchema } from "./database-schema.js";
|
|
8
|
-
export declare function createDatabaseSchema<const CS extends ComponentSchemas, const RS extends ResourceSchemas, const A extends ArchetypeComponents<StringKeyof<CS>>, const TD extends
|
|
8
|
+
export declare function createDatabaseSchema<const CS extends ComponentSchemas, const RS extends ResourceSchemas, const A extends ArchetypeComponents<StringKeyof<CS>>, const TD extends ActionDeclarations<FromSchemas<CS>, FromSchemas<RS>, A>>(components: CS, resources: RS, archetypes: A, transactions: TD): {
|
|
9
9
|
readonly components: CS;
|
|
10
10
|
readonly resources: RS;
|
|
11
11
|
readonly archetypes: A;
|
|
12
12
|
readonly transactions: TD;
|
|
13
13
|
};
|
|
14
|
-
export declare function createDatabaseFromSchema<const CS extends ComponentSchemas, const RS extends ResourceSchemas, const A extends ArchetypeComponents<StringKeyof<CS>>, const TD extends
|
|
14
|
+
export declare function createDatabaseFromSchema<const CS extends ComponentSchemas, const RS extends ResourceSchemas, const A extends ArchetypeComponents<StringKeyof<CS>>, const TD extends ActionDeclarations<FromSchemas<CS>, FromSchemas<RS>, A>>(schema: DatabaseSchema<CS, RS, A, TD>): DatabaseFromSchema<typeof schema>;
|
|
@@ -2,12 +2,13 @@ import { FromSchemas } from "../../../schema/from-schemas.js";
|
|
|
2
2
|
import { ComponentSchemas } from "../../component-schemas.js";
|
|
3
3
|
import { ResourceSchemas } from "../../resource-schemas.js";
|
|
4
4
|
import { StringKeyof } from "../../../types/types.js";
|
|
5
|
-
import { Database
|
|
5
|
+
import { Database } from "../database.js";
|
|
6
|
+
import type { ToActionFunctions, ActionDeclarations } from "../../store/action-functions.js";
|
|
6
7
|
import { ArchetypeComponents } from "../../store/archetype-components.js";
|
|
7
|
-
export type DatabaseSchema<CS extends ComponentSchemas, RS extends ResourceSchemas, A extends ArchetypeComponents<StringKeyof<CS>>, TD extends
|
|
8
|
+
export type DatabaseSchema<CS extends ComponentSchemas, RS extends ResourceSchemas, A extends ArchetypeComponents<StringKeyof<CS>>, TD extends ActionDeclarations<FromSchemas<CS>, FromSchemas<RS>, A>> = {
|
|
8
9
|
readonly components: CS;
|
|
9
10
|
readonly resources: RS;
|
|
10
11
|
readonly archetypes: A;
|
|
11
12
|
readonly transactions: TD;
|
|
12
13
|
};
|
|
13
|
-
export type DatabaseFromSchema<T> = T extends DatabaseSchema<infer CS, infer RS, infer A, infer TD> ? Database<FromSchemas<CS>, FromSchemas<RS>, A,
|
|
14
|
+
export type DatabaseFromSchema<T> = T extends DatabaseSchema<infer CS, infer RS, infer A, infer TD> ? Database<FromSchemas<CS>, FromSchemas<RS>, A, ToActionFunctions<TD>> : never;
|
|
@@ -5,7 +5,7 @@ import { Entity } from "../entity.js";
|
|
|
5
5
|
import { EntityReadValues } from "../store/core/index.js";
|
|
6
6
|
import { Observe } from "../../observe/index.js";
|
|
7
7
|
import { TransactionResult } from "./transactional-store/index.js";
|
|
8
|
-
import { StringKeyof } from "../../types/types.js";
|
|
8
|
+
import { IntersectTuple, NoInfer, StringKeyof } from "../../types/types.js";
|
|
9
9
|
import { Components } from "../store/components.js";
|
|
10
10
|
import { ArchetypeComponents } from "../store/archetype-components.js";
|
|
11
11
|
import { RequiredComponents } from "../required-components.js";
|
|
@@ -13,22 +13,24 @@ import { EntitySelectOptions } from "../store/entity-select-options.js";
|
|
|
13
13
|
import { Service } from "../../service/service.js";
|
|
14
14
|
import { OptionalComponents } from "../optional-components.js";
|
|
15
15
|
import { createDatabase } from "./public/create-database.js";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
import { ResourceSchemas } from "../resource-schemas.js";
|
|
17
|
+
import { ComponentSchemas } from "../component-schemas.js";
|
|
18
|
+
import { FromSchemas } from "../../schema/index.js";
|
|
19
|
+
import type { ActionDeclarations, ActionFunctions, ToActionFunctions } from "../store/action-functions.js";
|
|
20
|
+
import { createPlugin } from "./create-plugin.js";
|
|
21
|
+
type SystemFunction = () => void | Promise<void>;
|
|
22
|
+
export interface Database<C extends Components, R extends ResourceComponents, A extends ArchetypeComponents<StringKeyof<C & OptionalComponents>>, F extends ActionFunctions, S extends string = never> extends ReadonlyStore<C, R, A>, Service {
|
|
23
|
+
readonly transactions: F & Service;
|
|
24
|
+
/**
|
|
25
|
+
* Provides direct mutable access to the underlying store.
|
|
26
|
+
*/
|
|
27
|
+
readonly store: Store<C, R, A> & {
|
|
28
|
+
/**
|
|
29
|
+
* Provides fast access to the action functions without a transaction wrapper.
|
|
30
|
+
* This means any calls to them will NOT be observable or undoable.
|
|
31
|
+
*/
|
|
32
|
+
readonly actions: F;
|
|
33
|
+
};
|
|
32
34
|
readonly observe: {
|
|
33
35
|
readonly components: {
|
|
34
36
|
readonly [K in StringKeyof<C>]: Observe<void>;
|
|
@@ -44,10 +46,46 @@ export interface Database<C extends Components = never, R extends ResourceCompon
|
|
|
44
46
|
archetype(id: ArchetypeId): Observe<void>;
|
|
45
47
|
select<Include extends StringKeyof<C>, T extends Include>(include: readonly Include[] | ReadonlySet<string>, options?: EntitySelectOptions<C, Pick<C & RequiredComponents, T>>): Observe<readonly Entity[]>;
|
|
46
48
|
};
|
|
49
|
+
readonly system: {
|
|
50
|
+
readonly functions: {
|
|
51
|
+
readonly [K in S]: SystemFunction;
|
|
52
|
+
};
|
|
53
|
+
readonly order: S[][];
|
|
54
|
+
};
|
|
47
55
|
toData(): unknown;
|
|
48
56
|
fromData(data: unknown): void;
|
|
49
|
-
extend<
|
|
57
|
+
extend<P extends Database.Plugin<any, any, any, any, any>>(plugin: P): Database<C & (P extends Database.Plugin<infer XC, any, any, any, any> ? FromSchemas<XC> : never), R & (P extends Database.Plugin<any, infer XR, any, any, any> ? FromSchemas<XR> : never), A & (P extends Database.Plugin<any, any, infer XA, any, any> ? XA : never), F & (P extends Database.Plugin<any, any, any, infer XTD, any> ? ToActionFunctions<XTD> : never), S | (P extends Database.Plugin<any, any, any, any, infer XS> ? XS : never)>;
|
|
50
58
|
}
|
|
51
59
|
export declare namespace Database {
|
|
52
60
|
const create: typeof createDatabase;
|
|
61
|
+
type Plugin<CS extends ComponentSchemas = any, RS extends ResourceSchemas = any, A extends ArchetypeComponents<StringKeyof<CS & OptionalComponents>> = any, TD extends ActionDeclarations<FromSchemas<CS>, FromSchemas<RS>, any> = any, S extends string = any> = {
|
|
62
|
+
readonly components?: CS;
|
|
63
|
+
readonly resources?: RS;
|
|
64
|
+
readonly archetypes?: A;
|
|
65
|
+
readonly transactions?: TD;
|
|
66
|
+
readonly systems?: {
|
|
67
|
+
readonly [K in S]: {
|
|
68
|
+
readonly create: (db: Database<FromSchemas<CS>, FromSchemas<RS>, A, ToActionFunctions<TD>, S>) => SystemFunction;
|
|
69
|
+
readonly schedule?: {
|
|
70
|
+
readonly before?: readonly NoInfer<Exclude<S, K>>[];
|
|
71
|
+
readonly after?: readonly NoInfer<Exclude<S, K>>[];
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
namespace Plugin {
|
|
77
|
+
type Intersect<T extends readonly Plugin<any, any, any, any, any>[]> = Required<Database.Plugin<{} & IntersectTuple<{
|
|
78
|
+
[K in keyof T]: T[K] extends Plugin<infer C, any, any, any, any> ? (C extends undefined ? {} : C) : never;
|
|
79
|
+
}>, {} & IntersectTuple<{
|
|
80
|
+
[K in keyof T]: T[K] extends Plugin<any, infer R, any, any, any> ? (R extends undefined ? {} : R) : never;
|
|
81
|
+
}>, {} & IntersectTuple<{
|
|
82
|
+
[K in keyof T]: T[K] extends Plugin<any, any, infer A, any, any> ? (A extends undefined ? {} : A) : never;
|
|
83
|
+
}>, {} & IntersectTuple<{
|
|
84
|
+
[K in keyof T]: T[K] extends Plugin<any, any, any, infer TD, any> ? (TD extends undefined ? Record<never, never> : TD) : never;
|
|
85
|
+
}>, Extract<{
|
|
86
|
+
[K in keyof T]: T[K] extends Plugin<any, any, any, any, infer S> ? S : never;
|
|
87
|
+
}[number], string>>>;
|
|
88
|
+
const create: typeof createPlugin;
|
|
89
|
+
}
|
|
53
90
|
}
|
|
91
|
+
export {};
|
|
@@ -1,6 +1,48 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
1
22
|
import { createDatabase } from "./public/create-database.js";
|
|
23
|
+
import { createPlugin } from "./create-plugin.js";
|
|
2
24
|
export var Database;
|
|
3
25
|
(function (Database) {
|
|
4
26
|
Database.create = createDatabase;
|
|
27
|
+
let Plugin;
|
|
28
|
+
(function (Plugin) {
|
|
29
|
+
Plugin.create = createPlugin;
|
|
30
|
+
})(Plugin = Database.Plugin || (Database.Plugin = {}));
|
|
5
31
|
})(Database || (Database = {}));
|
|
32
|
+
// Test type inference with new overload pattern
|
|
33
|
+
const testBasePlugin = Database.Plugin.create({
|
|
34
|
+
components: {
|
|
35
|
+
position: { type: "number" },
|
|
36
|
+
health: { type: "number" }
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const testExtendedPlugin = Database.Plugin.create({
|
|
40
|
+
components: {
|
|
41
|
+
velocity: { type: "number" }
|
|
42
|
+
},
|
|
43
|
+
archetypes: {
|
|
44
|
+
DynamicEntity: ["position", "velocity"],
|
|
45
|
+
LivingEntity: ["position", "health"]
|
|
46
|
+
}
|
|
47
|
+
}, [testBasePlugin]);
|
|
6
48
|
//# sourceMappingURL=database.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../src/ecs/database/database.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../src/ecs/database/database.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAgBX,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAW7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAoDlD,MAAM,KAAW,QAAQ,CAqCxB;AArCD,WAAiB,QAAQ;IACV,eAAM,GAAG,cAAc,CAAC;IAsBrC,IAAiB,MAAM,CAYtB;IAZD,WAAiB,MAAM;QAWR,aAAM,GAAG,YAAY,CAAC;IACrC,CAAC,EAZgB,MAAM,GAAN,eAAM,KAAN,eAAM,QAYtB;AAEH,CAAC,EArCgB,QAAQ,KAAR,QAAQ,QAqCxB;AA8CD,gDAAgD;AAChD,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5C,UAAU,EAAE;QACV,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC5B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC3B;CACF,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAC/C;IACE,UAAU,EAAE;QACV,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC7B;IACD,UAAU,EAAE;QACV,aAAa,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC;QACvC,YAAY,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC;KACrC;CACF,EACD,CAAC,cAAc,CAAC,CACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|