Official JavaScript SDK for communicating with a TOONDB instance.
toondb provides a clean client for:
- service health checks
- collection management
- CRUD operations
- schema updates
- TOON dumps
- bridge-compatible action execution
To create and run a TOONDB database instance, use the main TOONDB project:
This SDK assumes you already have a running TOONDB service URL and credentials.
- Node.js
>=18
npm install toondbimport { ToonDBClient } from "toondb";
const client = new ToonDBClient({
baseUrl: "https://your-toondb-service-url",
username: "your-username",
password: "your-password",
});
const health = await client.health();
console.log(health);const client = new ToonDBClient({
baseUrl: "https://example.toondb.io",
username: "amit",
password: "amit098",
timeoutMs: 30000, // optional
});If omitted in constructor options, SDK auto-loads values from env vars:
TOONDB_URLTOONDB_USERorTOONDB_USERNAMETOONDB_PASSorTOONDB_PASSWORD
// works if env vars are set
const client = new ToonDBClient();health()
createCollection(collection, schema)updateCollectionSchema(collection, schema)dump(collection)-> returns TOON string
insert(collection, doc)find(collection, filter?)update(collection, filter, patch)delete(collection, filter)
bridge(request)execute(action, payload?)shutdown()
Supported bridge actions:
create_collectioninsertupdateupdate_schemafinddeletedumpshutdown
await client.createCollection("users", {
fields: { name: "string", age: "number", active: "boolean" },
indexed_fields: ["name"],
});
await client.insert("users", { name: "milo", age: 7, active: true });
const found = await client.find("users", {
conditions: [{ field: "name", op: "eq", value: "milo" }],
});
await client.update(
"users",
{ conditions: [{ field: "name", op: "eq", value: "milo" }] },
{ age: 8 }
);
const toonDump = await client.dump("users");
console.log(toonDump);The SDK throws typed errors:
ToonDBAuthErrorfor auth failuresToonDBResponseErrorfor API/server response failuresToonDBNetworkErrorfor transport/network failures
import { ToonDBAuthError, ToonDBNetworkError } from "toondb";
try {
await client.health();
} catch (err) {
if (err instanceof ToonDBAuthError) {
console.error("Invalid credentials");
} else if (err instanceof ToonDBNetworkError) {
console.error("Network issue");
} else {
console.error(err);
}
}Run tests:
npm testRun smoke example:
TOONDB_URL=http://127.0.0.1:6767 TOONDB_USER=amit TOONDB_PASS=amit098 npm run smokeSmoke script location:
examples/smoke.js
Please see: