API reference

Vennbase

MethodDescription
new Vennbase({ schema, appBaseUrl? })Create a Vennbase instance. Pass appBaseUrl so share links point back to your app.
getSession()Check whether the current browser already has a Puter session.
signIn()Start the Puter sign-in flow. Call this from a user gesture such as a button click.
ensureReady()Explicitly await authentication and provisioning before mutations. Most useful in imperative startup flows and before imperative writes.
whoAmI()Returns { username } for the signed-in Puter user.
create(collection, fields, options?)Create a row optimistically and return a MutationReceipt<RowHandle> immediately. Pass { in: parent } for child rows, where parent can be a RowHandle or RowRef; for collections declared as in: ["user"], omitting in uses the current signed-in user's built-in user row. Most apps use .value; await .committed when you need remote confirmation.
update(collection, row, fields)Merge field updates onto a row optimistically and return a MutationReceipt<RowHandle> immediately. row can be a RowHandle or RowRef.
getRow(row)Fetch a row by typed reference.
query(collection, options)Load rows under a parent, with optional index, order, and limit. For collections declared as in: ["user"], omitting in uses the current signed-in user's built-in user row.
watchQuery(collection, options, callbacks)Subscribe to repeated query refreshes via callbacks.onChange. For collections declared as in: ["user"], omitting in uses the current signed-in user's built-in user row. Returns a handle with .disconnect().
createInviteToken(row)Generate a new invite token for a row and return a MutationReceipt<InviteToken>. Most apps can use .value immediately.
getExistingInviteToken(row)Return the existing token if one exists, or null.
createShareLink(row, token)Build a shareable URL containing a serialized row ref and token.
parseInvite(input)Parse an invite URL into { ref, inviteToken? }.
acceptInvite(input)Join a row via invite URL or parsed invite object, and return its handle. Invite joins become direct "editor" members by default.
saveRow(key, row)Persist one current row for the signed-in user under your app-defined key.
openSavedRow(key)Re-open the saved row for the signed-in user, or null.
clearSavedRow(key)Remove the saved row for the signed-in user.
listMembers(row)Returns string[] of all member usernames.
listDirectMembers(row)Returns { username, role }[] for direct members.
listEffectiveMembers(row)Returns resolved membership including grants inherited from parents.
addMember(row, username, role)Grant a user access and return a MutationReceipt<void>. Roles: "editor" and "viewer". "editor" can update fields, manage members, manage parents, and send CRDT messages; "viewer" is read-only.
removeMember(row, username)Revoke a user's access and return a MutationReceipt<void>.
addParent(child, parent)Link a row to an additional parent after creation and return a MutationReceipt<void>.
removeParent(child, parent)Unlink a row from a parent and return a MutationReceipt<void>.
listParents(child)Returns all parent references for a row.
connectCrdt(row, callbacks)Bridge a CRDT onto the row's message stream. Returns a CrdtConnection.

RowHandle

MemberDescription
.fieldsCurrent field snapshot, typed from your schema. Treat it as read-only; the object is replaced when fields change.
.collectionThe collection this row belongs to.
.refPortable RowRef object for persistence, invites, ref-typed fields, and reopening the row later.
.id / .ownerRow identity metadata.
.refresh()Re-fetch fields from the server. Resolves to the latest field snapshot.
.connectCrdt(callbacks)Shorthand for db.connectCrdt(row, callbacks).
.in.add(parent) / .in.remove(parent) / .in.list()Manage parent links.
.members.add(username, { role }) / .members.remove(username) / .members.list()Manage membership.

MutationReceipt<T>

MemberDescription
.valueThe optimistic value available immediately. For create and update, this is the RowHandle.
.committedPromise that resolves to the final value once the write is confirmed remotely. Rejects if the write fails.
.statusCurrent write status: "pending", "committed", or "failed".
.errorThe rejection reason after a failed write. Otherwise undefined.