Skip to content

v0.7.0

Choose a tag to compare

@github-actions github-actions released this 04 Dec 17:20
6da4ea8

Claims with values, server logic in the client's transaction, refusals in the app's words, open tabs that survive deploys, and connections no slow download can hold. Two breaking changes, in the claims API and the client; the session's claims changed shape in the protocol, so update clients and server together.

Breaking changes

  • Claims hold values and are declared in the schema. createSchema(models, { claims: { staff: claim.boolean(), currentTeam: claim.idOf("team") } }) (also fromPrisma(datamodel, { claims })); the session callback sets claims: { staff, currentTeam }; rules read $.claims.staff and compare columns with $.claims.currentTeam. declareClaim, $staff(…) grants and db.$session.hasClaim are removed; read db.$session.claims.<name>. The protocol's session claims is now a map. Swift: db.session.isGranted(_:), value(of:), values(of:).
  • db.$viewerId replaces db.$session.viewerId.

Features

  • Server logic in the same transaction:
    • createEngine({ transaction }), with prismaTransaction(prisma, …) from @clientdb/prisma (Prisma 5, 6 and 7), writes a device's change in a transaction you open;
    • beforeCommit(writes, $) sees every row it wrote and can write more, or refuse;
    • $.afterCommit(work) runs after the commit.
  • Refusals in your words:
    • createEngine({ messages: defineMessages(schema, { conflict, forbidden, fallback }) }) words what devices are told;
    • duplicates are matched by unique key through Postgres's catalog;
    • TransactionRejected(code, message) refuses from beforeCommit with your message;
    • composite unique keys come from the unique model option or Prisma's @@unique.
  • Deploys and open tabs:
    • clients and server exchange per-model hashes, and the server sends each client only the models it knows;
    • db.$version is "current", "updateAvailable" (the server only added models; the client keeps working) or "reloadRequired" (a model it uses changed: writes throw and onReloadRequired asks to reload);
    • Swift: db.version and SyncOptions(onReloadRequired:);
    • the deploy docs now run setup when the new release starts serving, not in the build.
  • fromPrisma:
    • sync: [...] lists the models that sync, and syncAuthModels replaces include;
    • models.<Model>.unique declares keys schema.prisma can't;
    • the types now refuse everything startup refuses, including fields of schema.prisma that can't sync and calls without options.
  • validate is typed by model.
  • onError on the fetch and Next.js handlers and on createSyncServer.
  • The permission helpers on $ can be destructured without lint errors.

Fixes

  • Slow or abandoned downloads hold no database connection:
    • a bootstrap reads each page in its own short transaction;
    • a pull commits before it sends;
    • a stream whose device takes nothing for 60 s is ended (downloadIdleTimeoutMs);
    • the Node server no longer leaks close listeners.
  • indexedDb() storage can't hang:
    • opening, loading and writing time out after 10 s;
    • a load that can't read what is stored downloads afresh;
    • other tabs' upgrades and deletes never block.
  • The capture trigger ignores updates that change only columns that don't sync.
  • npx clientdb setup explains a missing generated module, the usual monorepo mistake.

Published to npm