@tarangdb/sdk
v1.0.0-alpha.4
Published
Type-safe TarangDB client for generated project schemas.
Downloads
37
Maintainers
Readme
@tarangdb/sdk
Type-safe JavaScript/TypeScript client for TarangDB generated APIs.
Install
Most projects should let the CLI install the SDK and related runtime packages:
npx @tarangdb/cli initManual install is still supported:
npm install @tarangdb/sdkUsage
Generate the project client with @tarangdb/cli, then import the ready-to-use tarang client:
import { tarang } from "./src/tarang.generated.js";
const customers = await tarang.table("customers").list();
await tarang.table("customers").create({
fullName: "Ada Lovelace",
email: "[email protected]",
});JavaScript projects can use the generated CommonJS client:
const { tarang } = require("./src/tarang.generated.js");
async function main() {
const customers = await tarang.table("customers").list();
console.log(customers.data);
}
main().catch(console.error);If you prefer manual construction, the client still reads TARANG_API_KEY, TARANG_PROJECT_ID, and TARANG_BASE_URL from process.env:
import { TarangClient } from "@tarangdb/sdk";
import type { TarangSchema } from "./src/tarang.generated.js";
const tarang = new TarangClient<TarangSchema>();Configuration
TarangClient accepts:
apiKey: Tarang API key. Falls back toTARANG_API_KEY.projectId: Tarang project UUID. Falls back toTARANG_PROJECT_ID.baseUrl: Tarang API base URL. Falls back toTARANG_BASE_URLorhttps://api.tarangdb.com.fetch: optional custom fetch implementation for tests, serverless runtimes, or polyfills.timeoutMs: request timeout in milliseconds. Defaults to30000.headers: extra headers for each request.
API
client.table("customers").list(options);
client.table("customers").get(rowId);
client.table("customers").create(input);
client.table("customers").update(rowId, patch);
client.table("customers").delete(rowId);API errors throw TarangError with code, status, and optional details.
Status
This is an alpha release. Public API names may still change before stable.
