Skip to content

v0.6.0

Choose a tag to compare

@github-actions github-actions released this 03 Dec 22:28
264545f

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-sql prints the SQL for a migration of your own (then use setup: "verify", which answers 503 NotMigrated until the database matches). npx clientdb-prisma models / triggers, the Clientdb* Prisma models, the clientdb_* 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. Keep setup: "auto", or add a migration from clientdb setup --print-sql and use setup: "verify".

  • Every write syncs. Prisma, raw SQL, other services and cascades all sync; a statement over bulkRows rows (default 1,000) or a TRUNCATE is logged as one invalidation. engine.changed(), engine.reconcile(), engine.resync(), engine.uncaptured(), the warnUntracked handler option and resyncInvalidateThreshold are removed.

  • Tokens instead of groups. Viewers hold tokens (user|<id>, team.member|<teamId>, claim:staff|*). db.$groups is db.$tokens, and the onAccessRemoved hook receives tokens. 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, plan and invalidate actions, POST /revalidate, chunked /partial, interest by hash (interestHash, interestChange, interestUnknown) and replays. QueryRequest.where is a list of clauses ({ or } alternatives).

  • Swift implements protocol v3 (ClientDBCore passes every conformance vector). The per-model LoadMode is ModelLoad; the client's LoadMode is lazy, schema or all. 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-level load and forceSync permissions (NotAllowed, 403).
  • where takes or alternatives, 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.
  • fromPrisma refuses implicit many-to-many relations with guidance.
  • clientdb migrate / setup load 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).

Published to npm