Skip to content

Using the TypeScript SDK

@cratebase/client is the first-party TypeScript SDK — a typed client covering records, auth, realtime, files, batch, admin, and Cratebase’s AI/queue/presence value-adds:

Terminal window
bun add @cratebase/client
import { createClient } from "@cratebase/client";
const cb = createClient("http://localhost:8090");
const posts = await cb.collection("posts").list({ filter: "published = true" });
const unsubscribe = await cb.collection("posts").subscribe("*", (e) => console.log(e.action, e.record));

list/fullList/first/one all take a single options object (page, perPage, sort, filter, expand, fields, skipTotal, signal) rather than positional arguments. Build filter strings with the exported filter` ` tagged template to get automatic quoting/escaping instead of hand-rolling them:

import { filter } from "@cratebase/client";
const posts = await cb.collection("posts").list({
filter: filter`published = ${true} && author = ${userId}`,
});

For SSR frameworks (TanStack Start, Next.js, SvelteKit), construct a fresh client per request and attach the incoming request’s cookie directly:

import { createClient } from "@cratebase/client";
const cb = createClient(process.env.CRATEBASE_URL, {
cookie: getCookie("cb_session"),
});
const posts = await cb.collection("posts").list();
setCookie("cb_session", cb.auth.exportCookie());

No auto-cancellation to disable. PocketBase’s SDK auto-cancels a same-key in-flight request — a de-duplication behavior meant for client-side UI that requires explicitly opting out (autoCancellation(false)) in every server context, since two independent incoming requests can look like the same repeated call. @cratebase/client has no such behavior: callers pass an AbortSignal when they want cancellation, so there is nothing to disable here.

Staying on the official pocketbase npm package instead? Cratebase’s API is wire-compatible with it — see PocketBase SDK interop.