Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-monorepo",
"version": "0.9.78",
"version": "0.9.79",
"private": true,
"scripts": {
"build": "pnpm -r run build",
Expand Down
2 changes: 1 addition & 1 deletion packages/data-ai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-ai",
"version": "0.9.78",
"version": "0.9.79",
"description": "Cross-agent architecture skills for @adobe/data — installable as a Claude Code plugin or copied into any Agent-Skills-compatible agent (Cursor, Codex).",
"type": "module",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-gpu-samples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-gpu-samples",
"version": "0.9.78",
"version": "0.9.79",
"description": "WebGPU samples built on @adobe/data-gpu",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-gpu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-gpu",
"version": "0.9.78",
"version": "0.9.79",
"description": "Adobe data WebGPU plugins and types for graphics and compute",
"type": "module",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-lit-tictactoe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-lit-tictactoe",
"version": "0.9.78",
"version": "0.9.79",
"description": "Tic-Tac-Toe sample - Lit web components with @adobe/data-lit and AgenticService",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-lit-todo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-lit-todo",
"version": "0.9.78",
"version": "0.9.79",
"description": "Todo sample app demonstrating @adobe/data with Lit",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-lit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-lit",
"version": "0.9.78",
"version": "0.9.79",
"description": "Adobe data Lit bindings - hooks, elements, decorators",
"type": "module",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-p2p-tictactoe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-p2p-tictactoe",
"version": "0.9.78",
"version": "0.9.79",
"description": "Serverless P2P tic-tac-toe — WebRTC DataChannel + @adobe/data-sync",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-persistence/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-persistence",
"version": "0.9.78",
"version": "0.9.79",
"description": "Worker-based incremental persistence layer for @adobe/data ECS over OPFS (browser) and node:fs (server).",
"type": "module",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-react-hello/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-react-hello",
"version": "0.9.78",
"version": "0.9.79",
"description": "Hello World sample - click counter using @adobe/data-react",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-react-pixie/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-react-pixie",
"version": "0.9.78",
"version": "0.9.79",
"description": "PixiJS React sample - ECS sprites (bunny, fox) with @adobe/data-react",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-react",
"version": "0.9.78",
"version": "0.9.79",
"description": "Adobe data React bindings — hooks and context for ECS database",
"type": "module",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-solid-dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-solid-dashboard",
"version": "0.9.78",
"version": "0.9.79",
"description": "Mini dashboard sample — multiple components sharing one @adobe/data ECS database with SolidJS",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-solid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-solid",
"version": "0.9.78",
"version": "0.9.79",
"description": "Adobe data SolidJS bindings — context and provider for ECS database",
"type": "module",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-sync/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data-sync",
"version": "0.9.78",
"version": "0.9.79",
"description": "Multi-user real-time synchronisation for @adobe/data ECS — server, client, and in-process loopback.",
"type": "module",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/data",
"version": "0.9.78",
"version": "0.9.79",
"description": "Adobe data oriented programming library",
"type": "module",
"sideEffects": false,
Expand Down
22 changes: 22 additions & 0 deletions packages/data/src/ecs/archetype/archetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ export interface Archetype<C extends RequiredComponents = RequiredComponents> ex
fromData: (data: unknown) => void
}

/**
* Write-only handle over a *family* of archetypes that share a component set but
* differ by the value of one or more `partition` components. `insert` reads the
* partition value(s) from the row, resolves (creating on first use) the concrete
* child archetype for that value, and inserts there.
*
* A family has no single dense column view, so — unlike {@link Archetype} — a
* Router exposes no `columns`, `rowCount`, or iteration. Read a family through
* `queryArchetypes` (optionally filtered by partition value), or narrow to one
* concrete member by supplying the value to `ensureArchetype`.
*
* `insert` is deliberately signature-identical to {@link Archetype.insert}: a
* discriminated `Archetype<C> | Router<C>` (produced when the requested keys are
* not statically known to include/exclude a partition component) therefore still
* permits `.insert` with no narrowing — only dense column access requires having
* resolved to a concrete {@link Archetype}.
*/
export interface Router<C extends RequiredComponents = RequiredComponents> {
readonly components: ComponentSet<StringKeyof<C>>;
insert: <T extends EntityInsertValues<C>>(rowData: Exact<EntityInsertValues<C>, T>) => Entity;
}

export type FromArchetype<T> =
T extends ReadonlyArchetype<infer C> ? { readonly [K in keyof C]: C[K] } :
T extends Archetype<infer C> ? { readonly [K in keyof C]: C[K] } :
Expand Down
3 changes: 2 additions & 1 deletion packages/data/src/ecs/database/create-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { ArchetypeComponents } from "../store/archetype-components.js";
import type { TransactionDeclarations, ToTransactionFunctions } from "../store/transaction-functions.js";
import type { ToActionFunctions } from "../store/action-functions.js";
import type { FromSchemas } from "../../schema/index.js";
import type { PartitionKeysOf } from "../store/partition.js";
import type { StringKeyof, NoInfer, RemoveIndex } from "../../types/types.js";
import { combinePlugins } from "./combine-plugins.js";
import { Store } from "../store/store.js";
Expand Down Expand Up @@ -189,7 +190,7 @@ export function createPlugin<
const RS extends ResourceSchemas,
const A extends ArchetypeComponents<StringKeyof<RemoveIndex<CS> & XP['components'] & IP['components']>>,
const IX extends IndexDeclarations<FromSchemas<RemoveIndex<CS> & XP['components'] & IP['components']>, RemoveIndex<A> & XP['archetypes'] & IP['archetypes']>,
const TD extends TransactionDeclarations<FromSchemas<RemoveIndex<CS> & XP['components'] & IP['components']>, FromSchemas<RemoveIndex<RS> & XP['resources'] & IP['resources']>, RemoveIndex<A> & XP['archetypes'] & IP['archetypes'], RemoveIndex<IX> & XP['indexes'] & IP['indexes']>,
const TD extends TransactionDeclarations<FromSchemas<RemoveIndex<CS> & XP['components'] & IP['components']>, FromSchemas<RemoveIndex<RS> & XP['resources'] & IP['resources']>, RemoveIndex<A> & XP['archetypes'] & IP['archetypes'], RemoveIndex<IX> & XP['indexes'] & IP['indexes'], PartitionKeysOf<RemoveIndex<CS> & XP['components'] & IP['components']>>,
const AD,
const S extends string = never,
const SVF extends ServiceFactories<Database.FromPlugin<AmbientPlugin<XP, IP>>> = {},
Expand Down
49 changes: 49 additions & 0 deletions packages/data/src/ecs/database/database.partition.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// © 2026 Adobe. MIT License. See /LICENSE for details.
import { describe, it, expect } from "vitest";
import { Database } from "./database.js";

// A plugin whose `cell` component partitions, with a unique name index. The
// transactions write through the transaction context `t`, exercising routing
// and index maintenance on the committed-transaction path.
const plugin = () => Database.Plugin.create({
components: {
cell: { type: "integer", partition: true },
name: { type: "string" },
},
archetypes: { Spatial: ["cell", "name"] },
indexes: { byName: { key: "name", unique: true } },
transactions: {
add: (t, input: { cell: number; name: string }) => t.archetypes.Spatial.insert(input),
move: (t, input: { entity: number; cell: number }) => { t.update(input.entity, { cell: input.cell }); },
},
});

describe("Database partition integration (transaction context)", () => {
it("routes t.archetypes.<PartitionedName> inserts and maintains indexes", () => {
const db = Database.create(plugin());
const a = db.transactions.add({ cell: 1, name: "alice" });
const b = db.transactions.add({ cell: 2, name: "bob" });

expect(db.indexes.byName.get({ name: "alice" })).toBe(a);
expect(db.indexes.byName.get({ name: "bob" })).toBe(b);
// Distinct cells → distinct concrete archetypes.
expect(db.locate(a)!.archetype).not.toBe(db.locate(b)!.archetype);
expect(db.get(a, "cell")).toBe(1);
});

it("migrates on a partition-value change inside a transaction; index follows", () => {
const db = Database.create(plugin());
const e = db.transactions.add({ cell: 1, name: "mover" });
db.transactions.move({ entity: e, cell: 2 });
expect(db.get(e, "cell")).toBe(2);
expect(db.indexes.byName.get({ name: "mover" })).toBe(e);
});

it("enforces a unique index across value-children inside a transaction (atomic)", () => {
const db = Database.create(plugin());
const first = db.transactions.add({ cell: 1, name: "dup" });
expect(() => db.transactions.add({ cell: 2, name: "dup" })).toThrow(/[Uu]nique/);
// Original intact — the failed transaction rolled back cleanly.
expect(db.indexes.byName.get({ name: "dup" })).toBe(first);
});
});
46 changes: 46 additions & 0 deletions packages/data/src/ecs/database/database.partition.type-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// © 2026 Adobe. MIT License. See /LICENSE for details.
//
// Compile-time (red/green) verification that the transaction context `t`
// discriminates partition archetypes — both `t.archetypes.<Name>` and
// `t.ensureArchetype`. Wrapped in a never-called function so the file
// type-checks without executing the plugin factory.

import { Database } from "./database.js";

function _transactionContextDiscrimination() {
Database.Plugin.create({
components: {
cell: { type: "integer", partition: true },
position: { type: "number" },
health: { type: "number" },
},
archetypes: {
Spatial: ["cell", "position"], // partition family
Mob: ["position", "health"], // concrete
},
transactions: {
check: (t) => {
// A partitioned named archetype is a Router on `t` — write via insert.
t.archetypes.Spatial.insert({ cell: 1, position: 2 });
// @ts-expect-error - Spatial is a partition family (Router), not a concrete Archetype
t.archetypes.Spatial.columns;

// A non-partition named archetype is a concrete Archetype on `t`.
t.archetypes.Mob.columns;
t.archetypes.Mob.insert({ position: 1, health: 100 });

// ensureArchetype on `t` discriminates just like on the store.
const router = t.ensureArchetype(["id", "cell", "position"]);
router.insert({ cell: 1, position: 2 });
// @ts-expect-error - a partition family (Router) has no columns
router.columns;

const concrete = t.ensureArchetype(["id", "cell", "position"], { cell: 7 });
concrete.columns;

// @ts-expect-error - partition value must match the component type (cell is number)
t.ensureArchetype(["id", "cell", "position"], { cell: "nope" });
},
},
});
}
9 changes: 6 additions & 3 deletions packages/data/src/ecs/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { ConcurrencyStrategy } from "./concurrency/concurrency-strategy.js"
import { observeSelectDeep as _observeSelectDeep } from "./public/observe-select-deep.js";
import { ResourceSchemas } from "../resource-schemas.js";
import { ComponentSchemas } from "../component-schemas.js";
import { PartitionKeysOf } from "../store/partition.js";
import { FromSchemas } from "../../schema/index.js";
import type {
TransactionDeclarations,
Expand Down Expand Up @@ -110,7 +111,8 @@ export interface Database<
SV = {},
CV = unknown,
IX extends IndexDeclarations<C> = {},
> extends ReadonlyStore<C, R, A, IX>, Service {
PK extends string = never,
> extends ReadonlyStore<C, R, A, IX, PK>, Service {
readonly transactions: F & Service;
readonly actions: AF & Service;
readonly services: SV;
Expand Down Expand Up @@ -247,7 +249,8 @@ export namespace Database {
ToActionFunctions<RemoveIndex<P['actions']>>,
FromServiceFactories<RemoveIndex<P['services']>>,
FromComputedFactories<RemoveIndex<P['computed']>>,
RemoveIndex<P['indexes']>
RemoveIndex<P['indexes']>,
PartitionKeysOf<RemoveIndex<P['components']>>
>;

export const create = createDatabase;
Expand Down Expand Up @@ -325,7 +328,7 @@ export namespace Database {
* another plugin's transaction declaration; `ToStore<P>` is the bare
* store type and does not include `userId`.
*/
export type ToTransactionContext<P extends Database.Plugin> = TransactionContext<FromSchemas<RemoveIndex<P['components']>>, FromSchemas<RemoveIndex<P['resources']>>, RemoveIndex<P['archetypes']>>;
export type ToTransactionContext<P extends Database.Plugin> = TransactionContext<FromSchemas<RemoveIndex<P['components']>>, FromSchemas<RemoveIndex<P['resources']>>, RemoveIndex<P['archetypes']>, RemoveIndex<P['indexes']>, PartitionKeysOf<RemoveIndex<P['components']>>>;
export type ToSystemDatabase<P extends Database.Plugin> = Database.FromPlugin<P> & {
// Systems are allowed to access the database store directly.
// This direct access will NOT trigger observable transactions.
Expand Down
1 change: 0 additions & 1 deletion packages/data/src/ecs/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export * from "./reconciling/reconciling-entry.js";
export * from "./observed/create-observed-database.js";
export * from "./observed/observed-database.js";
export * from "./database.js";
export * from "./observe-dependent-value.js";
export * from "./transactional-store/index.js";
export * from "./database-schema/index.js";
export type { Undoable } from "./undoable.js";
Expand Down
Loading