toondb
v1.0.0
Published
Official JavaScript SDK for TOONDB service layer
Maintainers
Readme
toondb
Official JavaScript SDK for communicating with a TOONDB instance.
Overview
toondb provides a clean client for:
- service health checks
- collection management
- CRUD operations
- schema updates
- TOON dumps
- bridge-compatible action execution
TOONDB Instance Setup
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.
Requirements
- Node.js
>=18
Installation
npm install toondbQuick Start
import { 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);Configuration
Explicit configuration
const client = new ToonDBClient({
baseUrl: "https://example.toondb.io",
username: "amit",
password: "amit098",
timeoutMs: 30000, // optional
});Environment fallback
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();API Reference
Health
health()
Collection operations
createCollection(collection, schema)updateCollectionSchema(collection, schema)dump(collection)-> returns TOON string
Document operations
insert(collection, doc)find(collection, filter?)update(collection, filter, patch)delete(collection, filter)
Bridge-compatible operations
bridge(request)execute(action, payload?)shutdown()
Supported bridge actions:
create_collectioninsertupdateupdate_schemafinddeletedumpshutdown
Usage Example (CRUD)
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);Error Handling
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);
}
}Development
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
Contributing
Please see:
