Skip to content

fix(ecs): thread index declarations into the computed-factory db type#120

Merged
krisnye merged 1 commit into
mainfrom
krisnye/plugin-computed-indexes
Jun 8, 2026
Merged

fix(ecs): thread index declarations into the computed-factory db type#120
krisnye merged 1 commit into
mainfrom
krisnye/plugin-computed-indexes

Conversation

@krisnye

@krisnye krisnye commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

db.indexes was empty inside computed factories — computeds couldn't use any declared index.

Database is 9 type params:

Database<C, R, A, F, S, AF, SV, CV, IX extends IndexDeclarations<C>>
//        1  2  3  4  5  6   7   8   9

The actions/systems db correctly threads slot 9 (IX). But the computed-factory db is FullDBForPlugin<…>, which forwarded only slots 1–7 — so CV (8) and IX (9) fell to their defaults, leaving IX = {} and db.indexes empty.

Fix

Forward IX into slot 9 of FullDBForPlugin, supplying a placeholder for slot 8:

type FullDBForPlugin<, SVF, IX = {}> =
  Database<,
    FromServiceFactories<RemoveIndex<SVF> & XP['services']>,
    unknown,             // 8: CV — Database's own default for this slot, so a
                         //    concrete computed-values type never constrains
                         //    computed-factory inference / breaks contravariance
    IX & XP['indexes']>; // 9: IX — the missing thread

At the call sites XP is AmbientPlugin<XP, IP>, so XP['indexes'] resolves to extends-base and imports-dep indexes; the IX param adds the plugin's own locally-declared indexes. This matches the actions/systems db exactly.

Verification

  • tsc -b green; 210 index/plugin tests pass; lint clean.
  • Added regression guards in database.index.type-test.ts proving a computed factory sees its own, its extends-base, and its imports-dep indexes via db.indexes. Confirmed they fail to compile without the fix (Property '<name>' does not exist on type '{}').
  • Pure type-threading change; no runtime change.

Bump to 0.9.66.

🤖 Generated with Claude Code

FullDBForPlugin (the `db` type for computed factories) forwarded only Database
slots 1–7, so slot 9 (IX) fell back to its `{}` default and `db.indexes` was
empty inside computeds — they couldn't use any declared index. (Actions/systems
were unaffected; their db threads IX already.)

Forwards IX into slot 9, with `unknown` for slot 8 (CV) — Database's own
default for that slot — so a concrete computed-values type never constrains
computed-factory inference / breaks contravariance. At the call sites XP is
AmbientPlugin<XP, IP>, so both extends-base and imports-dep indexes flow in;
the plugin's own locally-declared indexes are threaded via the IX param too.

Adds regression guards in database.index.type-test.ts (own / extends / imports
indexes visible to computeds); verified they fail to compile without the fix.

Bump to 0.9.66.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@krisnye krisnye merged commit 6805e80 into main Jun 8, 2026
3 checks passed
@krisnye krisnye deleted the krisnye/plugin-computed-indexes branch June 8, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant