TypeScript Quickstart
Installation
Section titled “Installation”npm install @hypermeshdb/clientRequires Node.js 18+ (for native fetch) or any modern browser.
Connect to a running server
Section titled “Connect to a running server”import { HyperMeshClient } from "@hypermeshdb/client";
const db = new HyperMeshClient({ baseUrl: "http://localhost:8000", apiKey: "hmdb_yoursecretkey", // omit if HMDB_AUTH_DISABLED=1});Basic operations
Section titled “Basic operations”const result = await db.execute( "MATCH HYPEREDGE (he:CoProximity) " + "WHERE he.event_ts >= $start AND he.event_ts <= $end RETURN *", { start: 1000, end: 2000 });console.log(`${result.num_tuples} hyperedges`);console.log(result.query_plan?.strategy); // TPI_BUCKET_PUSHDOWNInsert
Section titled “Insert”await db.insert({ event_ts: 1000, members: [1, 2, 3], weight: 0.95, formation: "delta",});Range query (optimised)
Section titled “Range query (optimised)”const range = await db.queryRange(1000, 2000, "CoProximity");for (const he of range.hyperedges) { console.log(he.event_ts, he.members);}Node lookup
Section titled “Node lookup”const result = await db.queryNode(42, "CoProximity");console.log(`Node 42 appears in ${result.num_tuples} hyperedges`);Atomic batch
Section titled “Atomic batch”const batch = await db.batch([{ type: "insert", event_ts: 100, members: [1, 2] }, { type: "insert", event_ts: 101, members: [2, 3] }, { type: "query", cypher: "MATCH HYPEREDGE (he:CoProximity) RETURN *" },]);
if (!batch.committed) { throw new Error(`Batch failed: ${batch.error}`);}console.log(`${batch.ops_success}/${batch.ops_total} ops succeeded`);Analytics
Section titled “Analytics”const pr = await db.analytics("CoProximity", "pagerank");const sg = await db.analytics("CoProximity", "spectral_gap");const sadj = await db.analytics("CoProximity", "s_adjacency", { s: 2 });
console.log(pr.result); // { "1": 0.23, "2": 0.31, ... }Error handling
Section titled “Error handling”import { HyperMeshError } from "@hypermeshdb/client";
try { await db.getTable("NonExistent");} catch (err) { if (err instanceof HyperMeshError) { console.error(`${err.statusCode}: ${err.message}`); }}Health & monitoring
Section titled “Health & monitoring”// Kubernetes liveness / readiness probes (no auth required)const live = await db.live(); // { status: "live" }const ready = await db.ready(); // { status: "ready" }
// Full statsconst stats = await db.health();console.log(stats.total_records, stats.wal_pending);Browser usage
Section titled “Browser usage”<script type="module">import { HyperMeshClient } from "https://unpkg.com/@hypermeshdb/client/dist/index.esm.js";
const db = new HyperMeshClient({ baseUrl: "https://your-server.example.com" });const health = await db.health();console.log(health.status);</script>