brainy/docs/guides
David Snelling fd5edb5a13 feat: brain.onChange — the in-process change feed for every committed mutation
Subscribe once and receive one post-commit event per affected record for
EVERY canonical write, regardless of origin: direct calls, batch methods,
transact(), imports, and Virtual Filesystem writes all funnel through the
same commit points the feed is emitted from. This is the authoritative
in-process signal for live UIs, cache invalidation, and realtime sync layers
that forward it over their own transports.

Architecture — the post-commit dual of the ifRev precommit hook: mutation
methods hand lightweight event descriptors to the commit seam
(persistSingleOp / transact's plan), which stamps the committed
{generation, timestamp}, enriches entity deletes with the record's LAST
committed state from the commit's own before-images (free — Model B reads
them anyway; removeMany's id-only deletes gain full payloads this way), and
emits only after the commit succeeds — a losing CAS or rejected batch never
announces anything. Dispatch is a microtask FIFO after the mutex releases:
commit-ordered, a slow listener never delays a write, a throwing listener is
logged and isolated, and with no subscribers the write path constructs no
events at all. Single-point emission was chosen over per-method hooks
because the aggregation-hook pattern demonstrably drifted (relation ops and
removeMany were silently missing from it).

Coverage: add/update/remove (+ cascade unrelate per deleted relationship),
relate (both edges when bidirectional)/unrelate/updateRelation, per-item
events for addMany/updateMany/relateMany/removeMany, per-item events sharing
one generation for transact(), and transitively imports + VFS. clear() and
restore() — wholesale raw-state operations outside the per-record commit
path — emit a single store-level event meaning "refetch everything".
brain.close() drops all listeners.

New module src/events/changeFeed.ts (BrainyChangeEvent + ChangeFeed,
exported from the package root); guide docs/guides/reacting-to-changes.md.
Integration suite pins the contract: per-op payload fidelity, delete
last-state payloads, batch per-item emission, one-generation transact
batches, VFS-origin events, CAS-loser silence, ordering, listener isolation,
unsubscribe, and store-level events.
2026-07-10 11:24:31 -07:00
..
aggregation.md docs: rename the native provider to @soulcraft/cor across public docs and JSDoc 2026-07-02 15:11:41 -07:00
enterprise-for-everyone.md docs: rename the native provider to @soulcraft/cor across public docs and JSDoc 2026-07-02 15:11:41 -07:00
export-and-import.md refactor(8.0): rename BackupData → PortableGraph (the type is interchange, not a backup) 2026-06-19 12:37:23 -07:00
find-limits.md feat(8.0): API simplification — remove neural()/Db.search, one storage path key, integration→0 2026-06-20 13:31:11 -07:00
framework-integration.md feat(8.0): API simplification — remove neural()/Db.search, one storage path key, integration→0 2026-06-20 13:31:11 -07:00
import-anything.md feat(8.0): API simplification — remove neural()/Db.search, one storage path key, integration→0 2026-06-20 13:31:11 -07:00
import-flow.md feat(8.0): API simplification — remove neural()/Db.search, one storage path key, integration→0 2026-06-20 13:31:11 -07:00
import-progress-examples.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
import-progress-implementation.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
import-quick-reference.md chore(8.0): final pre-RC1 sweep — API consistency, named errors, orphans, zero-cast codebase 2026-06-11 14:51:00 -07:00
inspection.md feat(8.0): API simplification — remove neural()/Db.search, one storage path key, integration→0 2026-06-20 13:31:11 -07:00
installation.md docs: rename the native provider to @soulcraft/cor across public docs and JSDoc 2026-07-02 15:11:41 -07:00
migrating-to-v4.md chore(8.0): final pre-RC1 sweep — API consistency, named errors, orphans, zero-cast codebase 2026-06-11 14:51:00 -07:00
MIGRATING_TO_V5.11.md feat: enforce data/metadata separation, numeric range queries, improved docs 2026-02-09 12:07:54 -08:00
migration-3.36.0.md feat: implement always-adaptive caching with getCacheStats monitoring 2025-10-10 14:09:30 -07:00
model-loading.md chore(8.0): modernize toolchain + position Bun as a runtime 2026-07-01 09:16:46 -07:00
natural-language.md feat: v5.1.0 - VFS auto-initialization and complete API documentation 2025-11-02 10:58:52 -08:00
nextjs-integration.md feat: enhance framework integration and simplify codebase 2025-09-15 14:54:13 -07:00
optimistic-concurrency.md docs(8.0): consistency-model concept + snapshots guide — Db API replaces branching docs 2026-06-11 08:37:26 -07:00
quick-start.md docs(8.0): correct public docs to the real 8.0 API + honest perf claims 2026-06-29 10:03:02 -07:00
reacting-to-changes.md feat: brain.onChange — the in-process change feed for every committed mutation 2026-07-10 11:24:31 -07:00
schema-migrations.md refactor(8.0)!: remove orphaned zero-config subsystem + dead cloud/progressive-init storage vestige 2026-06-15 11:11:21 -07:00
snapshots-and-time-travel.md feat(8.0): Model-B per-write generation-stamping + adaptive retention knob 2026-06-22 15:19:58 -07:00
standard-import-progress.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
storage-adapters.md feat(8.0): API simplification — remove neural()/Db.search, one storage path key, integration→0 2026-06-20 13:31:11 -07:00
streaming-imports.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
subtypes-and-facets.md docs: rename the native provider to @soulcraft/cor across public docs and JSDoc 2026-07-02 15:11:41 -07:00
upgrading-7-to-8.md fix: recover VFS content blobs stranded by a 7→8 upgrade, in place on open 2026-07-07 12:23:36 -07:00
vue-integration.md refactor(8.0)!: remove orphaned zero-config subsystem + dead cloud/progressive-init storage vestige 2026-06-15 11:11:21 -07:00