JavaScript / TypeScript SDK
Package @hakodb/client (hakodb/hakojs). Two layers: a high-level Firestore-shaped client (client.ts) over native FFI bindings (native.ts; koffi on Node, Bun FFI on Bun).
npm i @hakodb/client
native.ts loads the HakoDB cdylib. Resolution order: loadNativeBindings(explicitPath) → HAKODB_LIB_PATH env → ./native/<lib>. Populate it with the repo’s sync script:
# from a local core checkout (build it first: cargo build --release --features header)
.\sync-native.ps1 -CoreDir <core-checkout>
# or from a core release (pass the tag you want)
.\sync-native.ps1 -Tag <core-release-tag>
Binaries under native/ are git-ignored.
import { HakoClient } from "@hakodb/client";
const db = await HakoClient.open("./data");
await db.set("users", "1", { name: "alice", age: 30 });
const snap = await db.get("users", "1");
console.log(snap.data());
const rows = await db.collection("users")
.where("age", ">=", 18)
.orderBy("age", "desc")
.limit(50)
.get();
const unsub = db.collection("users").onSnapshot((docs) => render(docs));
Notes:
open(path, options?)loadsnative/hakodb.dll(shipped) oroptions.libraryPath/HAKODB_LIB_PATH. A failed open throws withnative.lastError().- Queries mirror Firestore spelling (
where,orderBy,limit,onSnapshot) with HakoDB operators (== != > >= < <= match matchPrefix contains startsWith in not-in array-contains array-contains-any). HakoConfigexposes durability/encryption/workers;NetSyncerandCloudSyncclasses wrap the sync planes;TransactionandWriteBatchmirror the engine.- References use
{__ref__: "collection/id"}. Graph and vector ops are on the collection;findNear()/hybridSearch()accept an optionalfiltersarray and use the canonical filtered lanes, whilefindPathsFull()/shortestPathsFull()are the canonical graph lanes. Edge indexes and tuned vector V2 parameters remain advanced APIs. - Canonical pairs:
effectiveConfig()for introspection,ensureIndexes()/dropIndexes()for schema.quiescenceStatus(),isIndexesReady(),getStats(), granularcreate*/drop*index calls,findPaths(),shortestPaths(), andQuery.getJson()are advisory-deprecated — they still work and emit a one-time warning. - Read lanes are not interchangeable.
get()returns fullHakoDocData[]and paysJSON.parse;get({ mode: "json" })is pinned-byte egress without JS objects;select(...).get()returns projected rows;getViewRows(fields)returns typed borrowed views with only the requested fields;getRaw()/viewDoc()are engine-only diagnostics whose checksums are count-only or partial. Use the document lane for application code and label diagnostic lanes explicitly in benchmarks. - Deletes are soft by default;
deleteEx(ref, force)opts into a hard delete, andrestore/restoreAvailable/deleteQueue/sweepNowwrap the retention surface on the client.
Common mistakes
- Forgetting the native library on a new machine. The npm package ships the Windows DLL; other platforms need
libraryPathpointed at a local release asset until per-platform bundles land. - Treating
onSnapshotas a query. It subscribes; the first callback is the current state, later ones are deltas. Unsubscribe when the view unmounts.