@adobe/data 0.9.81 → 0.9.83

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 (64) hide show
  1. package/dist/ecs/archetype/archetype.d.ts +23 -0
  2. package/dist/ecs/archetype/archetype.js.map +1 -1
  3. package/dist/ecs/database/create-plugin.d.ts +2 -1
  4. package/dist/ecs/database/create-plugin.js.map +1 -1
  5. package/dist/ecs/database/database-read.type-test.js +25 -0
  6. package/dist/ecs/database/database-read.type-test.js.map +1 -1
  7. package/dist/ecs/database/database.d.ts +26 -7
  8. package/dist/ecs/database/database.js.map +1 -1
  9. package/dist/ecs/database/database.partition.test.d.ts +1 -0
  10. package/dist/ecs/database/database.partition.test.js +45 -0
  11. package/dist/ecs/database/database.partition.test.js.map +1 -0
  12. package/dist/ecs/database/database.partition.type-test.d.ts +1 -0
  13. package/dist/ecs/database/database.partition.type-test.js +41 -0
  14. package/dist/ecs/database/database.partition.type-test.js.map +1 -0
  15. package/dist/ecs/database/deep-extends-chain.type-test.d.ts +255 -255
  16. package/dist/ecs/database/index.d.ts +0 -1
  17. package/dist/ecs/database/index.js +0 -1
  18. package/dist/ecs/database/index.js.map +1 -1
  19. package/dist/ecs/database/observe-derive.d.ts +4 -1
  20. package/dist/ecs/database/observe-derive.js +66 -35
  21. package/dist/ecs/database/observe-derive.js.map +1 -1
  22. package/dist/ecs/database/observe-derive.test.js +124 -0
  23. package/dist/ecs/database/observe-derive.test.js.map +1 -1
  24. package/dist/ecs/database/observed/observed-database.d.ts +3 -0
  25. package/dist/ecs/database/transactional-store/transactional-store.d.ts +6 -5
  26. package/dist/ecs/store/core/core.d.ts +33 -8
  27. package/dist/ecs/store/core/create-core.d.ts +12 -2
  28. package/dist/ecs/store/core/create-core.js +141 -22
  29. package/dist/ecs/store/core/create-core.js.map +1 -1
  30. package/dist/ecs/store/core/create-core.partition.test.d.ts +1 -0
  31. package/dist/ecs/store/core/create-core.partition.test.js +229 -0
  32. package/dist/ecs/store/core/create-core.partition.test.js.map +1 -0
  33. package/dist/ecs/store/core/select-entities.js +87 -21
  34. package/dist/ecs/store/core/select-entities.js.map +1 -1
  35. package/dist/ecs/store/core/select-entities.partition.test.d.ts +1 -0
  36. package/dist/ecs/store/core/select-entities.partition.test.js +93 -0
  37. package/dist/ecs/store/core/select-entities.partition.test.js.map +1 -0
  38. package/dist/ecs/store/entity-select-options.d.ts +5 -1
  39. package/dist/ecs/store/partition.d.ts +63 -0
  40. package/dist/ecs/store/partition.js +3 -0
  41. package/dist/ecs/store/partition.js.map +1 -0
  42. package/dist/ecs/store/partition.type-test.d.ts +1 -0
  43. package/dist/ecs/store/partition.type-test.js +15 -0
  44. package/dist/ecs/store/partition.type-test.js.map +1 -0
  45. package/dist/ecs/store/public/create-store.d.ts +3 -1
  46. package/dist/ecs/store/public/create-store.js +19 -50
  47. package/dist/ecs/store/public/create-store.js.map +1 -1
  48. package/dist/ecs/store/public/create-store.partition.test.d.ts +1 -0
  49. package/dist/ecs/store/public/create-store.partition.test.js +111 -0
  50. package/dist/ecs/store/public/create-store.partition.test.js.map +1 -0
  51. package/dist/ecs/store/public/create-store.partition.type-test.d.ts +1 -0
  52. package/dist/ecs/store/public/create-store.partition.type-test.js +61 -0
  53. package/dist/ecs/store/public/create-store.partition.type-test.js.map +1 -0
  54. package/dist/ecs/store/store.d.ts +15 -10
  55. package/dist/ecs/store/store.js.map +1 -1
  56. package/dist/ecs/store/transaction-functions.d.ts +3 -3
  57. package/dist/schema/schema.d.ts +1 -0
  58. package/dist/tsconfig.tsbuildinfo +1 -1
  59. package/package.json +1 -1
  60. package/references/data-lit/package.json +1 -1
  61. package/references/data-lit-tictactoe/package.json +1 -1
  62. package/references/data-react/package.json +1 -1
  63. package/references/data-react-hello/package.json +1 -1
  64. package/references/data-react-pixie/package.json +1 -1
@@ -0,0 +1,111 @@
1
+ // © 2026 Adobe. MIT License. See /LICENSE for details.
2
+ import { describe, it, expect } from "vitest";
3
+ import { createStore } from "./create-store.js";
4
+ import { constBufferType } from "../../../typed-buffer/create-const-buffer.js";
5
+ // `cell` partitions; `name` is uniquely indexed. `as const` preserves the
6
+ // `partition: true` literal (so the store is typed with the discrimination) and
7
+ // the index declaration (so `store.indexes.byName` is typed).
8
+ const schema = {
9
+ components: {
10
+ cell: { type: "integer", partition: true },
11
+ name: { type: "string" },
12
+ },
13
+ resources: {},
14
+ archetypes: { Spatial: ["cell", "name"] },
15
+ indexes: { byName: { key: "name", unique: true } },
16
+ };
17
+ const makeStore = () => createStore(schema);
18
+ describe("Store partition integration", () => {
19
+ it("dynamically extends with a partition component AFTER creation; N values → N archetypes, each with a const column", () => {
20
+ // Start with an empty store, then extend — exercises live (post-construction)
21
+ // partition detection, not the schema passed at creation.
22
+ const store = createStore().extend(schema);
23
+ // The dynamically-added partitioned archetype is a Router (no dense view).
24
+ const spatial = store.archetypes.Spatial;
25
+ expect("columns" in spatial).toBe(false);
26
+ // Insert N entities with N distinct partition values.
27
+ const N = 5;
28
+ const entities = Array.from({ length: N }, (_, i) => spatial.insert({ cell: i, name: `e${i}` }));
29
+ // Query the archetypes — exactly N, one per distinct value.
30
+ const archetypes = store.queryArchetypes(["cell", "name"]);
31
+ expect(archetypes.length).toBe(N);
32
+ // Every distinct value lives in its own archetype, and each still carries
33
+ // a named `cell` column that is a const typed buffer (zero per-row bytes).
34
+ const valuesSeen = new Set();
35
+ for (const arch of archetypes) {
36
+ expect(arch.rowCount).toBe(1);
37
+ const cellColumn = arch.columns.cell;
38
+ expect(cellColumn.type).toBe(constBufferType);
39
+ expect(cellColumn.typedArrayElementSizeInBytes).toBe(0);
40
+ valuesSeen.add(cellColumn.get(0));
41
+ }
42
+ expect([...valuesSeen].sort((a, b) => a - b)).toEqual([0, 1, 2, 3, 4]);
43
+ // The index (also added dynamically) resolves each routed entity.
44
+ for (let i = 0; i < N; i++) {
45
+ expect(store.indexes.byName.get({ name: `e${i}` })).toBe(entities[i]);
46
+ }
47
+ });
48
+ it("store.archetypes.<PartitionedName> is a Proxy-free Router that routes inserts", () => {
49
+ const store = makeStore();
50
+ const spatial = store.archetypes.Spatial;
51
+ expect(typeof spatial.insert).toBe("function");
52
+ expect("columns" in spatial).toBe(false); // a family has no dense view
53
+ const a = spatial.insert({ cell: 1, name: "a" });
54
+ const b = spatial.insert({ cell: 2, name: "b" });
55
+ expect(store.locate(a).archetype).not.toBe(store.locate(b).archetype);
56
+ expect(store.get(a, "cell")).toBe(1);
57
+ expect(store.get(b, "cell")).toBe(2);
58
+ });
59
+ it("maintains indexes on routed inserts (find across value-children)", () => {
60
+ const store = makeStore();
61
+ const spatial = store.archetypes.Spatial;
62
+ const a = spatial.insert({ cell: 1, name: "alice" });
63
+ const b = spatial.insert({ cell: 2, name: "bob" });
64
+ expect(store.indexes.byName.get({ name: "alice" })).toBe(a);
65
+ expect(store.indexes.byName.get({ name: "bob" })).toBe(b);
66
+ });
67
+ it("enforces a unique index across different value-children, atomically", () => {
68
+ const store = makeStore();
69
+ const spatial = store.archetypes.Spatial;
70
+ const first = spatial.insert({ cell: 1, name: "dup" });
71
+ // Same name, different cell → different archetype, still a unique conflict.
72
+ expect(() => spatial.insert({ cell: 2, name: "dup" })).toThrow(/[Uu]nique/);
73
+ // The original row is intact (atomic — no partial mutation).
74
+ expect(store.indexes.byName.get({ name: "dup" })).toBe(first);
75
+ });
76
+ it("queryArchetypes `where` filters value-children at the store layer", () => {
77
+ const store = makeStore();
78
+ const spatial = store.archetypes.Spatial;
79
+ spatial.insert({ cell: 1, name: "a" });
80
+ spatial.insert({ cell: 2, name: "b" });
81
+ spatial.insert({ cell: 2, name: "c" });
82
+ const cell2 = store.queryArchetypes(["cell", "name"], { where: { cell: 2 } });
83
+ expect(cell2.length).toBe(1);
84
+ expect(cell2[0].rowCount).toBe(2);
85
+ });
86
+ it("store.ensureArchetype routes (no value) and resolves concrete (with value)", () => {
87
+ const store = makeStore();
88
+ const router = store.ensureArchetype(["id", "cell", "name"]);
89
+ expect("columns" in router).toBe(false);
90
+ router.insert({ cell: 5, name: "x" });
91
+ const concrete = store.ensureArchetype(["id", "cell", "name"], { cell: 5 });
92
+ expect(concrete.columns).toBeDefined();
93
+ expect(concrete.rowCount).toBe(1);
94
+ });
95
+ it("index find works when inserting via the concrete-child path too", () => {
96
+ const store = makeStore();
97
+ const concrete = store.ensureArchetype(["id", "cell", "name"], { cell: 9 });
98
+ const e = concrete.insert({ cell: 9, name: "zed" });
99
+ expect(store.indexes.byName.get({ name: "zed" })).toBe(e);
100
+ });
101
+ it("index updates when a partition-value change migrates an entity", () => {
102
+ const store = makeStore();
103
+ const spatial = store.archetypes.Spatial;
104
+ const e = spatial.insert({ cell: 1, name: "mover" });
105
+ store.update(e, { cell: 2 });
106
+ // Entity moved value-children; the name index still resolves it.
107
+ expect(store.get(e, "cell")).toBe(2);
108
+ expect(store.indexes.byName.get({ name: "mover" })).toBe(e);
109
+ });
110
+ });
111
+ //# sourceMappingURL=create-store.partition.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-store.partition.test.js","sourceRoot":"","sources":["../../../../src/ecs/store/public/create-store.partition.test.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAE/E,0EAA0E;AAC1E,gFAAgF;AAChF,8DAA8D;AAC9D,MAAM,MAAM,GAAG;IACX,UAAU,EAAE;QACR,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE;QAC1C,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC3B;IACD,SAAS,EAAE,EAAE;IACb,UAAU,EAAE,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;IACzC,OAAO,EAAE,EAAE,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,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE;QACtE,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC;QACzC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QACrD,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;QAC7B,iEAAiE;QACjE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,61 @@
1
+ // © 2026 Adobe. MIT License. See /LICENSE for details.
2
+ //
3
+ // Compile-time (red/green) verification of the partition public surface on
4
+ // `Store` — discrimination of `store.archetypes.<Name>` and `ensureArchetype`,
5
+ // and the partition-keyed `queryArchetypes` where. Bodies live in never-called
6
+ // functions so the file type-checks without executing.
7
+ import { createStore } from "./create-store.js";
8
+ // store.archetypes.<Name> — discriminated per declared name
9
+ function _archetypesMap() {
10
+ // A partitioned named archetype is a Router — write via insert, no dense view.
11
+ store.archetypes.Spatial.insert({ cell: 1, position: 2 });
12
+ // @ts-expect-error - Spatial is a partition family (Router), not a concrete Archetype
13
+ store.archetypes.Spatial.columns;
14
+ // @ts-expect-error - a Router has no rowCount
15
+ store.archetypes.Spatial.rowCount;
16
+ // A non-partitioned named archetype is a concrete Archetype.
17
+ store.archetypes.Mob.columns;
18
+ store.archetypes.Mob.rowCount;
19
+ store.archetypes.Mob.insert({ position: 1, health: 100 });
20
+ }
21
+ // store.ensureArchetype(keys, values?) — discriminated
22
+ function _ensureArchetype() {
23
+ // Partition key present, no value → Router (insert only).
24
+ const router = store.ensureArchetype(["id", "cell", "position"]);
25
+ router.insert({ cell: 1, position: 2 });
26
+ // @ts-expect-error - a partition family (Router) has no columns
27
+ router.columns;
28
+ // Partition value supplied → concrete Archetype (dense access).
29
+ const concrete = store.ensureArchetype(["id", "cell", "position"], { cell: 7 });
30
+ concrete.columns;
31
+ concrete.rowCount;
32
+ // No partition component in the set → concrete Archetype.
33
+ const plain = store.ensureArchetype(["id", "position"]);
34
+ plain.columns;
35
+ // @ts-expect-error - partition value must match the component's type (cell is number)
36
+ store.ensureArchetype(["id", "cell", "position"], { cell: "nope" });
37
+ }
38
+ // queryArchetypes where — keyed to partition components only
39
+ function _queryWhere() {
40
+ store.queryArchetypes(["cell", "position"], { where: { cell: 7 } });
41
+ // @ts-expect-error - `position` is not a partition component; not archetype-decidable
42
+ store.queryArchetypes(["cell", "position"], { where: { position: 1 } });
43
+ // @ts-expect-error - partition where value must match the component type (cell is number)
44
+ store.queryArchetypes(["cell"], { where: { cell: "x" } });
45
+ }
46
+ // createStore return threads PK (inference, not just Store.FromSchema)
47
+ function _inferenceCheck() {
48
+ const s = createStore({
49
+ components: {
50
+ cell: { type: "integer", partition: true },
51
+ position: { type: "number" },
52
+ },
53
+ resources: {},
54
+ archetypes: { Spatial: ["cell", "position"] },
55
+ });
56
+ s.archetypes.Spatial.insert({ cell: 1, position: 2 });
57
+ // @ts-expect-error - inferred Spatial is a Router (partition family), no columns
58
+ s.archetypes.Spatial.columns;
59
+ return s;
60
+ }
61
+ //# sourceMappingURL=create-store.partition.type-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-store.partition.type-test.js","sourceRoot":"","sources":["../../../../src/ecs/store/public/create-store.partition.type-test.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,+EAA+E;AAC/E,+EAA+E;AAC/E,uDAAuD;AAGvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAmBhD,4DAA4D;AAC5D,SAAS,cAAc;IACnB,+EAA+E;IAC/E,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1D,sFAAsF;IACtF,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC;IACjC,8CAA8C;IAC9C,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC;IAElC,6DAA6D;IAC7D,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC;IAC7B,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC9B,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,uDAAuD;AACvD,SAAS,gBAAgB;IACrB,0DAA0D;IAC1D,MAAM,MAAM,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACjE,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IACxC,gEAAgE;IAChE,MAAM,CAAC,OAAO,CAAC;IAEf,gEAAgE;IAChE,MAAM,QAAQ,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,EAAE,IAA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I,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IACtD,iFAAiF;IACjF,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC;IAC7B,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -6,6 +6,7 @@ import { IntersectTuple, Simplify, StringKeyof } from "../../types/types.js";
6
6
  import { Components } from "./components.js";
7
7
  import { ArchetypeComponents } from "./archetype-components.js";
8
8
  import { Archetype, ReadonlyArchetype } from "../archetype/archetype.js";
9
+ import { HasPartitionKey, PartitionKeysOf, ArchetypeOrRouter } from "./partition.js";
9
10
  import { EntitySelectOptions } from "./entity-select-options.js";
10
11
  import { Undoable } from "../database/undoable.js";
11
12
  import { FromSchemas } from "../../schema/from-schemas.js";
@@ -25,14 +26,16 @@ interface BaseStore<C extends object = never> {
25
26
  */
26
27
  toData(copy?: boolean): unknown;
27
28
  }
28
- export interface ReadonlyStore<C extends Components = never, R extends ResourceComponents = never, A extends ArchetypeComponents<StringKeyof<C>> = never, IX extends IndexDeclarations<C> = {}> extends BaseStore<C>, ReadonlyCore<C> {
29
+ export interface ReadonlyStore<C extends Components = never, R extends ResourceComponents = never, A extends ArchetypeComponents<StringKeyof<C>> = never, IX extends IndexDeclarations<C> = {}, PK extends string = never> extends BaseStore<C>, ReadonlyCore<C, PK> {
29
30
  readonly resources: {
30
31
  readonly [K in StringKeyof<R>]: R[K];
31
32
  };
32
33
  readonly archetypes: {
33
- readonly [K in StringKeyof<A>]: ReadonlyArchetype<RequiredComponents & {
34
- [P in A[K][number]]: (C & RequiredComponents & OptionalComponents)[P];
35
- }>;
34
+ readonly [K in StringKeyof<A>]: ArchetypeOrRouter<HasPartitionKey<A[K][number], PK>, RequiredComponents & {
35
+ [Col in A[K][number]]: (C & RequiredComponents & OptionalComponents)[Col];
36
+ }, ReadonlyArchetype<RequiredComponents & {
37
+ [Col in A[K][number]]: (C & RequiredComponents & OptionalComponents)[Col];
38
+ }>>;
36
39
  };
37
40
  readonly indexes: {
38
41
  readonly [K in keyof IX]: Index.Handle<C, IX[K]>;
@@ -42,7 +45,7 @@ export type ToReadonlyStore<T extends Store> = T extends Store<infer C, infer R>
42
45
  /**
43
46
  * Store is the main interface for storing components, entities and resources.
44
47
  */
45
- export interface Store<C extends Components = {}, R extends ResourceComponents = {}, A extends ArchetypeComponents<StringKeyof<C>> = {}, IX extends IndexDeclarations<C> = {}> extends BaseStore<C>, Core<C> {
48
+ export interface Store<C extends Components = {}, R extends ResourceComponents = {}, A extends ArchetypeComponents<StringKeyof<C>> = {}, IX extends IndexDeclarations<C> = {}, PK extends string = never> extends BaseStore<C>, Core<C, PK> {
46
49
  /**
47
50
  * This is used when a store is used to represent a transaction.
48
51
  * For most stores, this is ignored if it is set.
@@ -52,9 +55,11 @@ export interface Store<C extends Components = {}, R extends ResourceComponents =
52
55
  -readonly [K in StringKeyof<R>]: R[K];
53
56
  };
54
57
  readonly archetypes: {
55
- -readonly [K in StringKeyof<A>]: Archetype<RequiredComponents & {
56
- [P in A[K][number]]: (C & RequiredComponents & OptionalComponents)[P];
57
- }>;
58
+ -readonly [K in StringKeyof<A>]: ArchetypeOrRouter<HasPartitionKey<A[K][number], PK>, RequiredComponents & {
59
+ [Col in A[K][number]]: (C & RequiredComponents & OptionalComponents)[Col];
60
+ }, Archetype<RequiredComponents & {
61
+ [Col in A[K][number]]: (C & RequiredComponents & OptionalComponents)[Col];
62
+ }>>;
58
63
  };
59
64
  /**
60
65
  * Index handles keyed by user-chosen name. Returned handles are the
@@ -68,7 +73,7 @@ export interface Store<C extends Components = {}, R extends ResourceComponents =
68
73
  /** Wipe all entities and reset resources to plugin defaults. O(num_archetypes + num_resources). */
69
74
  reset(): void;
70
75
  fromData(data: unknown): void;
71
- extend<S extends Store.Schema>(schema: S): S extends Store.Schema<infer XC, infer XR, infer XA, infer XIX> ? Store<C & XC, R & XR, A & XA, IX & XIX> : never;
76
+ extend<S extends Store.Schema>(schema: S): S extends Store.Schema<infer XC, infer XR, infer XA, infer XIX> ? Store<C & FromSchemas<XC>, R & FromSchemas<XR>, A & XA, IX & XIX, PK | PartitionKeysOf<XC>> : never;
72
77
  }
73
78
  export declare namespace Store {
74
79
  type Components<S extends Store> = S extends Store<infer C, infer R, infer A> ? C : never;
@@ -82,7 +87,7 @@ export declare namespace Store {
82
87
  readonly archetypes: A;
83
88
  readonly indexes?: IX;
84
89
  };
85
- type FromSchema<T> = T extends Store.Schema<infer CS, infer RS, infer A, infer IX> ? Store<FromSchemas<CS>, FromSchemas<RS>, A, IX> : never;
90
+ type FromSchema<T> = T extends Store.Schema<infer CS, infer RS, infer A, infer IX> ? Store<FromSchemas<CS>, FromSchemas<RS>, A, IX, PartitionKeysOf<CS>> : never;
86
91
  namespace Schema {
87
92
  type Intersect<T extends readonly Schema<any, any, any, any>[]> = Store.Schema<{} & IntersectTuple<{
88
93
  [K in keyof T]: T[K] extends Schema<infer C, any, any, any> ? C : never;
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/ecs/store/store.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAgEvD,2DAA2D;AAC3D,MAAM,KAAW,KAAK,CAsHrB;AAtHD,WAAiB,KAAK;IAuBlB,IAAiB,MAAM,CA4FtB;IA5FD,WAAiB,MAAM;QAsCnB;;;;;;;;;;;;;;;;;;;;;;;;;WAyBG;QACH,SAAgB,MAAM,CAOlB,MAKE,EACF,YAAgB;YAEhB,MAAM,EAAE,UAAU,GAAG,EAAE,EAAE,SAAS,GAAG,EAAE,EAAE,UAAU,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;YAClF,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;gBAC7C,OAAO;oBACH,UAAU,EAAE,EAAE,GAAG,GAAG,CAAC,UAAU,EAAE,GAAG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,SAAS,GAAG,EAAE,EAAE,UAAU,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;YAClF,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;gBAC7C,OAAO;oBACH,UAAU,EAAE,EAAE,GAAG,GAAG,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE;oBACrD,SAAS,EAAE,EAAE,GAAG,GAAG,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE;oBAClD,UAAU,EAAE,EAAE,GAAG,GAAG,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE;oBACrD,OAAO,EAAE,EAAE,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE;iBAC/C,CAAA;YACL,CAAC,EACG,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAS,CACxD,CAAC;QACN,CAAC;QA1Be,aAAM,SA0BrB,CAAA;IAEL,CAAC,EA5FgB,MAAM,GAAN,YAAM,KAAN,YAAM,QA4FtB;IAEY,YAAM,GAAG,WAAW,CAAC;AACtC,CAAC,EAtHgB,KAAK,KAAL,KAAK,QAsHrB;AAiCD,wEAAwE;AACxE,2EAA2E;AAC3E,MAAM,cAAc,GAAG;IACnB,UAAU,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAC3E,UAAU,EAAE,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE;CAC3E,CAAC"}
@@ -5,10 +5,10 @@ import { ArchetypeComponents } from "./archetype-components.js";
5
5
  import { StringKeyof } from "../../types/types.js";
6
6
  import { IndexDeclarations } from "./index-types.js";
7
7
  import type { TransactionContext } from "../database/transactional-store/transactional-store.js";
8
- export type TransactionDeclaration<C extends Components, R extends ResourceComponents, A extends ArchetypeComponents<StringKeyof<C>>, IX extends IndexDeclarations<C> = {}, Input extends any | void = any> = (t: TransactionContext<C, R, A, IX>, input: Input) => void | Entity;
8
+ export type TransactionDeclaration<C extends Components, R extends ResourceComponents, A extends ArchetypeComponents<StringKeyof<C>>, IX extends IndexDeclarations<C> = {}, PK extends string = never, Input extends any | void = any> = (t: TransactionContext<C, R, A, IX, PK>, input: Input) => void | Entity;
9
9
  export type AsyncArgsProvider<T> = () => Promise<T> | AsyncGenerator<T>;
10
- export type TransactionDeclarations<C extends Components, R extends ResourceComponents, A extends ArchetypeComponents<StringKeyof<C>>, IX extends IndexDeclarations<C> = {}> = {
11
- readonly [Q: string]: TransactionDeclaration<C, R, A, IX>;
10
+ export type TransactionDeclarations<C extends Components, R extends ResourceComponents, A extends ArchetypeComponents<StringKeyof<C>>, IX extends IndexDeclarations<C> = {}, PK extends string = never> = {
11
+ readonly [Q: string]: TransactionDeclaration<C, R, A, IX, PK>;
12
12
  };
13
13
  /**
14
14
  * Converts from TransactionDeclarations to TransactionFunctions by removing
@@ -28,6 +28,7 @@ export interface Schema {
28
28
  description?: string;
29
29
  conditionals?: readonly Conditional[];
30
30
  nonPersistent?: boolean;
31
+ partition?: boolean;
31
32
  mutable?: boolean;
32
33
  default?: any;
33
34
  precision?: 1 | 2;