nostrbasedocs
Start building
Guide
.md

Validate records

import { z } from "zod";
import { createClient, zodTable, type InferDatabase } from "nostrbase";

const schema = {
  todos: zodTable(z.object({ title: z.string(), done: z.boolean() }), {
    indexes: ["done"],
  }),
};
type Database = InferDatabase<typeof schema>;
const db = createClient<Database>({ namespace: "my-app", relays, schema });

zodTable() validates public and private writes and decoded records. It uses safeParse() as a check; Zod transforms, defaults, and coercions do not change stored data. Validate the exact JSON object you intend to store. defineTable() and defineSchema() are type helpers for custom validators. A supplied schema registry must list every table you use.

Invalid incoming records are excluded from table results. The signed event can remain in the cache for inspection or migration. Schemas do not enforce relay policy or stop another client from publishing invalid data.

Search guides, API methods, and protocols.