@shipmantis/sdk
v0.1.0
Published
The typed client for Mantis: define the schema, query and write rows, live queries, files, and useQuery for React.
Maintainers
Readme
@shipmantis/sdk
The typed client for Mantis, a hosted backend your agent can't break. Define the schema in TypeScript, then query, write, subscribe and store files with types that follow it.
npm install @shipmantis/sdkDefine the schema
// mantis/schema.ts
import { defineSchema, t, table } from "@shipmantis/sdk";
export const schema = defineSchema({
todos: table({
title: t.text(),
done: t.boolean().default(false),
dueAt: t.timestamp().default("now"),
}).index("done"),
});Query and write
import { createClient } from "@shipmantis/sdk";
import { schema } from "./mantis/schema";
const mantis = createClient({
url: process.env.MANTIS_URL!,
key: process.env.MANTIS_SECRET_KEY!,
schema,
});
const todos = mantis.from("todos");
await todos.insert({ title: "Ship it" });
const open = await todos.select({
where: { done: false },
orderBy: [{ column: "dueAt", direction: "asc" }],
limit: 20,
});
await todos.update({ set: { done: true }, where: { title: "Ship it" } });
await todos.delete({ where: { done: true } });where takes a value, or { eq, ne, lt, lte, gt, gte, in }. Pass branch to
createClient to work on a branch instead of main.
Live queries
const stop = todos.live({ where: { done: false } }, {
rows: (rows) => render(rows),
error: (error) => console.error(error),
});In React:
import { useQuery } from "@shipmantis/sdk/react";
function Todos() {
const { rows, error, loading } = useQuery(mantis, "todos", { where: { done: false } });
// ...
}Files
const file = await mantis.storage.upload("avatars/me.png", blob);
const link = await mantis.storage.url(file.path);Errors
Every refusal throws a MantisError.
