Repository navigation
v0.4.0
load: "partial" with load keys inferred from relations, a round of API fixes so each thing has one name and one shape, and helpers for plain Node.js servers (Express, Fastify, Hono). Breaking changes are listed first, each with what to change.
Breaking changes
-
load: { partial: [...] }is nowload: "partial", and every relation's foreign key is a load key. Before, a reference left out of the list was treated as fully loaded, souser.commentsreported"complete"while showing only the comments already on the device; now each parent's collection loads (and reports"partial") on its own.Migrating: replace
load: { partial: ["todoId"] }withload: "partial"(inmodel()options orfromPrisma'sload). The old shape throws with a pointer to the new one, and a partial model without a relation to a parent is rejected (use"lazy"). On your own tables (Prisma), index every foreign key of a partial model, such as@@index([authorId]).engine.partial/partialManyonly load a partial model by one of its load keys (or as a whole, for reloads afterinvalidate); loads by other fields return nothing.Model and schema hashes now cover
loadand each relation'sonDelete, so a client running an older bundle getsSchemaOutdatedafter a load-strategy change instead of showing a now-partial model as complete. Every schema hash changes once with this release, so open tabs reload when you deploy it. Migrations compare the newshapeHash(the previous formula), so stored snapshots stay valid and changing onlyloadoronDeleteneeds no migration. -
One way to keep a model on the server:
model("auditLog", { … }, { serverOnly: true }), orfromPrisma(models, { serverOnly: ["AuditLog"] }). A server-only model needs no rules, clients can't write it, and it and its relations are left out of client types, accessors and generated Swift code; rules can still read it.Removed, with errors that name the replacement:
load: "local". It was documented as "never synced", but the server accepted and fanned out its writes, required rules for it, and its collections reportedcompletewithout loading the server's rows.sync: falseon models (nowserverOnly: true).rules("model", "server-only")(mark the modelserverOnlyin the schema; rules for a server-only model now throw).
The schema IR writes
serverOnlyinstead ofsync; the Swift client still reads"sync": false. -
syncno longer means three things.fromPrisma'ssync(the secret-looking columns that may go to clients) is nownotSecret, andcreateDatabaseClient({ sync: false })(no network) is nownetwork: false; the model option becameserverOnlyearlier. The old spellings throw with the new name. -
updatedAtfields now change on every update, as documented. Declare them with the field modifierupdatedAt: t.timestamp().updatedAt()(theupdatedAtmodel option is removed and throws;fromPrismamaps@updatedAtto it). The client stamps the field at once on every update that changes another field (optimistically, and the operation carries the value), the server stamps it on updates made on the server (system writes, mutators) on engine-owned tables too, and field permissions (update.fields) never need to list it. Previously the field was only set on insert, except on Prisma tables, where clients didn't receive the new value until a reconcile.dirtyFieldsdoesn't list stamped fields. New:completeUpdatein@clientdb/core(spec/replica.md§4.1), mirrored by the Swift client. -
One name for each thing: the permission helpers
$.alland$.anyare removed in favour of$.andand$.or(they were documented as "same as"), andCollection.findById(id)(which returnednull) is nowget(id)returningundefined, the same name and convention asdb.issue.get(id). -
Owned children now inherit their parent's read access, as documented: an
owned: truechild without a read rule is readable exactly when its parent is (parent.canRead()), and strict mode no longer asks for a rule for it. Its writes still need rules; an explicitreadrule still wins.owned: { inheritAccess: false }is removed (it only switched off a set-based re-tagging optimization; give the child its own read rule instead), and so isinheritAccesson relation metadata and in the schema IR. The engine'sbulkInheritoption is now internal. -
ownedno longer silently overridesonDelete.belongsTo(…, { owned: true, onDelete })is a type error and throws (owned relations always cascade), andfromPrisma'sownedrefuses a relation whose schema.prismaonDeleteisn'tCascade, so deleting a parent with Prisma Client and with clientdb does the same thing. -
archivableis now a boolean:model("issue", { … }, { archivable: true }). Theretainsetting is gone: it was required but nothing read it (there is no purge job), so a value like"30d"silently kept archived rows forever. An object value now throws. The schema IR writes"archivable": true | false; the Swift client still reads the old object form.ArchivableOptionsis no longer exported. -
load: "onDemand"is removed: it behaved exactly likeload: "lazy", which stays. The load strategies are now"eager:critical","eager"(default),"lazy"and"partial". Using"onDemand"throws with the replacement; the Swift client reads it aslazyin older schema files. -
createSyncServerserves under/api/syncby default, the client's defaulturl, instead of/sync, so an unconfigured server and client meet. PassbasePath: "/sync"to keep the old path. It also acceptswarnUntracked, like the fetch and Next.js handlers. -
Safer token and error defaults:
- Sync tokens carry
aud: "clientdb-sync", and the handlers accept a bearer token as a sync token only with that audience, so another HS256 token signed with the same secret (another app's, or staging's) isn't one. New exports:verifySyncToken,SYNC_TOKEN_AUDIENCE. verifyJwtandverifyJwtTokenrefuse tokens without an expiry (exp), which would otherwise never expire.verifyJwt({ jwks })warns in development when noaudienceis set: without one, tokens your auth provider issued for your other apps are accepted.- In production, a failed request answers
{ error: "internal error" }instead of the error message (database errors name tables and constraints); the details are still logged.
- Sync tokens carry
Features
-
Plain Node.js servers:
createSyncServernow plugs into Express and Connect (syncServer.middleware), Fastify (app.register(syncServer.fastify)) and Hono or Bun (syncServer.fetch), andsyncServer.attachWebSocket(server)adds the realtime socket to a server you created. NewcorsandbodyLimitoptions (default 16 MiB) oncreateSyncServer,createFetchHandlerand the Next.js handler.syncServer.close()now returns a promise: it closes sockets with code 1001, refuses new ones and stops the sequencer it started. A throwingviewernow answers 500 instead of hanging the request (and crashing the process with an unhandled rejection),attachleaves other listeners' WebSocket upgrades alone, and malformed JSON bodies answer 400. Theviewercallback ofcreateSyncServeralso gets the Node request asraw. -
The schema names its viewer model:
schema(models, relations, { viewer: "member" })orfromPrisma(models, { viewer: "Member" }), defaulting to theusermodel.db.$vieweris now typed as that model's entity (it was a union of every model, sodb.$viewer?.namedidn't type-check), andcreateRules(schema)takes the viewer from the schema; an explicitcreateRules(schema, { viewer })must match it. New exports:ViewerModel,SchemaOptions;Schemahas a third type parameter and aviewerproperty. -
Less to restate in a TypeScript schema: every model gets
id: t.id()without declaring it (declaring it still works), andbelongsTonames the relation after a foreign key named…Idwhenasis left out (belongsTo(issue, "teamId", team, { inverse: "issues" })isissue.team). Other foreign keys still needas, as a type error and at runtime. -
createEngine({ permissions })takes its schema from the permissions (createRules(schema)already names it), soschemais optional. When it's passed and isn't the permissions' schema,createEnginethrows instead of compiling access for one schema and storing rows for another.EngineOptions.permissionsis now typedPermissions<S>. Docs drop the redundantschemaand, whereDATABASE_URLis the default anyway,database. -
db.$computed(fn)anddb.$effect(fn)derive values and run effects with whichever reactivity the client uses (built-in signals or MobX), so there is nocomputedto pick from the right package.mobxReactivity()no longer needs themobxmodule passed in: it uses the app'smobx(a peer dependency); passing one still works. -
createDatabaseClient(andcreateTestClient) report a type error when the classes inRegister["models"]and in themodelsoption differ. Relations returnRegister's classes whiledb.<model>returns the option's, so a class listed in only one of them used to type-check and then fail at runtime (a relation typed asTodoreturning a plain entity withouttodo.toggle()). New export:RegisterCheck. -
In development, the sync handlers warn once when
anonymousand the rules disagree: read rules use$.publicbut signed-out requests get 401, oranonymous: trueis set but no rule uses$.public.
Fixes
-
fromPrismarough edges:- Creating a row of a model whose omitted column is required without a database default is refused with a
Validationerror naming the column, instead of failing in Postgres with a 500 (ExternalModelStorage.requiredOmitted). - On the server in development,
fromPrismanotes once which columns change shape on clients:BigIntcolumns (numbers, exact up to 2^53) andcuid()/ulid()/nanoid()defaults (UUIDv7 from clients). clientdb-prisma triggersfindstriggers.sqlwhen the generator block relies on the default output.
- Creating a row of a model whose omitted column is required without a database default is refused with a
-
In development,
createEnginenow replaces its cached engine when any rule changes (write rules,update.fields,enforce,validate, explicit groups), when mutators, migrations or engine settings change, not only when read rules do.Permissionsexposes thefingerprintit uses.