mini-baas-js
v0.1.1
Published
TypeScript client for mini-baas
Readme
mini-baas-js
TypeScript SDK for mini-baas.
Usage
import { createClient } from "mini-baas-js";
const client = createClient({
url: process.env.MINI_BAAS_URL as string,
anonKey: process.env.MINI_BAAS_ANON_KEY as string,
});
await client.auth.signInWithPassword({
email: "[email protected]",
password: "secret",
captchaToken: "turnstile-token",
});
const projects = await client.from("projects").select();
const { data } = await client.auth.signInWithSSO({
providerId: "oidc-demo",
domain: "example.com",
redirectTo: "http://localhost:3000/auth/callback",
});
await client.realtime.onTable({
schema: "public",
table: "projects",
publication: "supabase_realtime",
callback: (change) => console.log(change),
});
await client.realtime.onBroadcast({
channel: "dashboard",
event: "project-feed",
self: true,
callback: ({ message }) => console.log(message),
});
await client.realtime.presence({
channel: "dashboard",
key: "user-123",
state: { email: "[email protected]" },
onSync: (state) => console.log("online:", Object.values(state).flat().length),
});GraphQL and embeddings
- GraphQL RPC (RLS-aware):
POST ${MINI_BAAS_URL}/rest/v1/rpc/graphqlwith{"query":"{ projects { id name } }","schema_name":"realty"}and headersapikey+Authorization: Bearer <token>. - Schema helpers:
graphql_schema(SDL text) andgraphql_schema_json(introspection JSON). - Embeddings: insert into
realty.embeddingsvia PostgREST and search withPOST /rest/v1/rpc/match_embeddingssendingquery_embeddingas an array andmatch_count.
Generate TypeScript types from the database
- Set
DATABASE_URL(and optionallyDB_SCHEMASandTYPES_OUT) then run:pnpm -C sdk/mini-baas-js install DATABASE_URL="postgres://postgres:postgres@localhost:5432/postgres" pnpm -C sdk/mini-baas-js gen:types - Defaults: schemas
public,auth,realty,storageand outputsrc/db.types.ts. Override the output path withTYPES_OUT=../examples/nextjs-app/app/db.types.tsto use directly in the Next.js app. - Import types:
import type { Database } from "./db.types"; type Project = Database["public"]["Tables"]["projects"]["Row"];
Run tests with pnpm test.
