Repository navigation
v0.6.0
A new sync engine (wire protocol v3, see spec/protocol.md and spec/replica.md): no migrations, every write to a synced table syncs, access compiled into tokens and an access plan that clients evaluate, revalidation with digests instead of reloads, and lazy clients that receive only what they hold. 0.5 and 0.6 clients and servers don't talk to each other, and stored client data (IndexedDB, Swift SQLite) is fetched again once.
Breaking changes
-
No clientdb tables or models in your schema. The engine keeps its bookkeeping in its own Postgres schema,
clientdb, and installs one capture trigger per synced table when it first starts (createEngine({ setup: "auto" }), the default).npx clientdb setup <module>does it from a deploy step;--print-sqlprints the SQL for a migration of your own (then usesetup: "verify", which answers503 NotMigrateduntil the database matches).npx clientdb-prisma models/triggers, theClientdb*Prisma models, theclientdb_*tables and adopting existing rows are gone.Migrating: delete the
Clientdb*models and the clientdb trigger migrations, and drop the adoption step from your deploy. Keepsetup: "auto", or add a migration fromclientdb setup --print-sqland usesetup: "verify". -
Every write syncs. Prisma, raw SQL, other services and cascades all sync; a statement over
bulkRowsrows (default 1,000) or aTRUNCATEis logged as one invalidation.engine.changed(),engine.reconcile(),engine.resync(),engine.uncaptured(), thewarnUntrackedhandler option andresyncInvalidateThresholdare removed. -
Tokens instead of groups. Viewers hold tokens (
user|<id>,team.member|<teamId>,claim:staff|*).db.$groupsisdb.$tokens, and theonAccessRemovedhook receivestokens. Rows readable through a parent ($.canRead(row.parent)) leave the client with the parent, and answers ship the parents their rows need.$.canRead(row, { except })is removed. -
Required relations a viewer may not read. The engine warns at startup when the rules don't prove a required relation's target readable wherever its row is. Mark such relations
t.belongsTo(…).mayBeUnreadable()(fromPrisma:models.<Model>.relations.<relation>.mayBeUnreadable: true) to type them nullable on clients. -
Force sync resolves with
{ missing }and applies its answer as a revalidation. -
Protocol v3: stamps on every answer,
tokens,planandinvalidateactions,POST /revalidate, chunked/partial, interest by hash (interestHash,interestChange,interestUnknown) and replays.QueryRequest.whereis a list of clauses ({ or }alternatives). -
Swift implements protocol v3 (
ClientDBCorepasses every conformance vector). The per-modelLoadModeisModelLoad; the client'sLoadModeislazy,schemaorall. SQLite layout v3 drops older stored data.
Features
- Revalidation instead of reloads: after an invalidation, a gained token, a deploy with new rules or a pruned log, clients re-read what they hold with per-item digests; unchanged items answer
same. - Lazy clients send their interest and receive changes only for rows and collections they hold; an idle pull stays about 300 bytes at any held-row count.
entity.forceSync()/db.<model>.forceSync(ids),load: "all", and session-levelloadandforceSyncpermissions (NotAllowed, 403).wheretakesoralternatives, locally and in server queries.- Named rules that reach the viewer several ways get one token kind per way (
name#1,name#2).
Fixes
where({ id })on a lazy model loads that row, not the whole model.fromPrismarefuses implicit many-to-many relations with guidance.clientdb migrate/setupload app modules with tsconfig path aliases and extensionless imports.
Known regressions (fixes planned for 0.6.x)
- Postgres spends about 50% more CPU per write while the engine drains (0.35 vs 0.23 ms per write in
bench:triggers). - One process serves about 10,000 WebSocket clients comfortably; 20,000 saturate it. Polling costs more server CPU than in 0.5.
- Promoting, demoting or hiding a row from a client re-evaluates its whole held set (promote 132 vs 52 ms in
bench:server). - Serverless throughput with many instances draining inline is lower (667 vs 1,184 tx/s with 8 instances).