ReadonlyactionsReadonlyapplyApply a remotely-originated transaction envelope to the database. Used
by sync services to feed in inbound commits and transients. Does not
fire observe.envelopes.
ReadonlyarchetypesReadonlycancelCancel a previously-applied transient envelope by its compound
(userId, id) key. Used by sync services to forward server-broadcast
cancellations.
ReadonlycomponentReadonlycomputedReadonlyconcurrencyThe concurrency strategy the database was created with. Sync services
read concurrency.userId to recover the peer identifier and check
concurrency.deferredCommit to confirm the database is in the
appropriate mode for multi-peer operation.
ReadonlyindexesLookup handles for the indexes declared by plugins on this database.
Each key in IX becomes a Database.Index.Handle whose method shape
is narrowed by the declared key tuple and unique flag.
The handles are also the implementation path used by db.select /
db.observe.select when a where / order matches a declared
index — call sites do not need to be aware of which index served
the query, but the same handle is what runs underneath.
ReadonlyobserveReadonlycomponents: { readonly [K in string]: Observe<void> }Readonlyenvelopes: Observe<Fires once for every locally-initiated envelope produced by the
transaction wrappers (db.transactions.X(args)). Replays inside the
reconciler and inbound db.apply() calls do NOT fire it. The
intent reflects the wrapper's decision regardless of whether the
envelope was applied locally as an intermediate step (deferred-commit / sync
mode) or as a commit (local-only mode).
Sync services route forwarding by intent:
"commit" → propose to the server (reliable)"intermediate" → relay to peers (lossy)"cancel" → cancel a pending intermediate step (reliable)Readonlyresources: { readonly [K in string]: Observe<R[K]> }Readonlytransactions: Observe<TransactionResult<C>>Reactive entity count for the same query as observe.select — emits a number and
allocates no entity array, re-emitting only when the count changes. Prefer this over
observe.select(...).length for membership/count-driven computeds.
Optionaloptions: EntitySelectOptions<C, Pick<C & RequiredComponents, T>>OptionalminArchetype: ReadonlyArchetype<T> | Archetype<T, never>Optionaloptions: EntitySelectOptions<C, Pick<C & RequiredComponents, T>>ReadonlyresetWipes all entities and resets all resources to their plugin defaults, preserving database identity (observers, transaction wrappers, sync options stay intact). Equivalent in observable state to a freshly constructed Database with the same plugin.
O(num_archetypes + num_resources) — does not walk individual entities. Clears any in-flight reconciler transient queue.
ReadonlyresourcesOptional ReadonlyschemaOptional observable of the service's schema (its authored contract), which may change at runtime as the service's discoverable interface evolves.
Optional ReadonlyserviceReadonlyservicesReadonlysystemReadonlyfunctions: { readonly [K in string]: null | SystemFunction }System create() return value, or null when create() returns void. Key is always present.
Readonlyorder: readonly (readonly string[])[]Tier order for execution. Looser type allows extended dbs to be assignable to base.
ReadonlytransactionsReadonlyversionThe current schema version — entries.length - 1 when a version upgrader is
configured, else 0. Stamped into the save metadata of every toData
(per persisted quadrant) and read back on load. Never an ECS component/resource.
Count the entities select would return for the same arguments — without building
an entity array. With no where filter it sums matched archetype row counts
(O(matched archetypes)); order is ignored (irrelevant to a count).
Optionaloptions: EntitySelectOptions<Reactive derivation. compute runs against a read-only projection of this
database (Database.Read — value / index / resource reads only; no
observers, writes, or table access). The derive records exactly the reads
it performs and re-emits when any could have changed: the initial value on
subscribe, then at most once per committed transaction (synchronously at
the commit boundary), structurally deduplicated so an unchanged result
never re-notifies.
The callback receives Database.Read<this>, so an intersection database
resolves to the merged read surface — consumers never need to cast.
derive with a fixed record of external inputs — arbitrary Observe<T>
values that do NOT live in the ECS (e.g. observables exposed by services).
Their CURRENT values are injected as the second callback argument, keyed the
same as inputs and unwrapped (Observe<U> → U); the first argument stays
the read projection, so a body can fold external values and ECS reads into
one synchronous expression.
The inputs are subscribed once, at the root (not read dynamically inside the body), so the set is fixed for the life of the derive. The derive recomputes when any input emits OR an ECS read it recorded could have changed; like Observe.fromProperties, the first value is withheld until every input has produced one. Anything dynamic — an input set that depends on data, or an input whose arguments come from an ECS read — composes with Observe.withSwitch / Observe.fromKeys around the derive.
Load a snapshot. Async because a configured version handler may be async
(e.g. it lazy-import()s migration code); with no handler it still resolves
after the synchronous load completes. toData stays synchronous — only the
load path can await a handler.
Resolves with a FromDataResult: { loaded: true } when the data was
loaded (possibly migrated), or { loaded: false, currentVersion, schemaVersions }
when a persisted quadrant was saved at a version newer than this app — the live
database is left untouched. Rejection is data, not a throw, so a UI can branch on
it (e.g. prompt "please update").
Optionalscope: PersistenceScopeConform the database's DATA to a target plugin's schema, dropping every component and resource the plugin does not declare (its imports/extends are already flattened in). An entity keeping at least one declared component migrates to its reduced archetype; an entity whose every component is foreign — including a foreign resource singleton — is removed.
Prunes DATA only, in place: the emptied foreign archetypes and their unused
schemas are left as inert residue and shed on the next fromData (which
skips empty archetypes and adopts only schemas the restored data uses), so
no snapshot round-trip carries them forever. Call when quiescent (no
in-flight transient); any pending transient is cleared, as with reset.
Returns the same database instance retyped to the target plugin's schema
(Database.FromPlugin<P>), so a wider database narrows to the pruned schema
at the type level. Foreign behavior (transactions/systems the original
plugin declared) still exists at runtime but is no longer in the type.
Optionaloptions: ArchetypeQueryOptions<C, PK>Read exactly the components of archetype. A membership GATE: returns
null unless the entity is a superset of archetype. The result is
narrowed to the archetype's own row — reading a component outside
archetype off the result is a compile error (use a wider archetype, the
component-list overload, or read(entity)).
Read a chosen subset of an entity's components.
A pure PROJECTION, not a membership gate: returns null only when the
entity does not exist. A requested component the entity does not have
comes back absent — the field stays optional in the result, exactly as
from the full read(entity).
Prefer this over read(entity) when only a few fields are needed: it
names the exact components touched, so db.derive can scope its
recompute to just those fields instead of the whole entity. id is not a
readable component (you already hold it); the element type is inferred as
a literal union.
Optionaloptions: EntitySelectOptions<Serialize the store to a plain snapshot. When copy is true the snapshot
is detached from the live store (column/entity buffers are copied) so it
remains valid after subsequent mutations; otherwise it references live
buffers and is only valid until the next mutation. See Database.toData()
for the bug this copy flag addresses for transient-bearing strategies.
options.scope selects which persistent quadrants to emit; omit for all.
Optionaloptions: { scope?: PersistenceScope }
A service is an object that provides functionality to an application. Services are never dependent upon user interface components. Services come in several varieties:
A service's shape can be described by a
Schema(an object schema whose property schemas describe each member). The schema is authored beside the service (e.g.MyService.schema) and validated withIsValidWithCompleteSchema; a factory may also expose it at runtime via the optionalschemaslot for introspection. It isObserve<Schema>— observable — because a service's discoverable interface can change at runtime (e.g. once an iframe-projected service loads and reveals a different surface). BothserviceNameandschemaare base-Servicemetadata, so they are excluded fromAsyncDataService.IsValid(which is whyschemaneed not beData) and reserved as member names. Seeasync-data-service/is-valid-with-*-schema.ts.