Client Lifecycle
This page documents the lifecycle methods implemented in src/client.ts.
Construction
import { KalamDBClient, Auth } from 'kalam-link';
const client = new KalamDBClient({
url: 'http://localhost:8080',
auth: Auth.basic('root', ''),
});Validation at construction time:
urlis requiredauthis required
Initialization behavior
initialize():
- loads WASM runtime (
init(...)) - creates underlying WASM
KalamClient - picks constructor by auth type:
- basic →
new WasmClient(url, username, password) - jwt →
WasmClient.withJwt(url, token) - none →
WasmClient.anonymous(url)
- basic →
You usually don’t call it manually; most methods initialize lazily.
Connect and disconnect
await client.connect();
console.log(client.isConnected());
await client.disconnect();Notes:
connect()initializes if needed, then opens WebSocket.disconnect()also clears SDK-side subscription tracking map.
Reconnection controls
client.setAutoReconnect(true);
client.setReconnectDelay(1000, 30000);
client.setMaxReconnectAttempts(10); // 0 means infinite
console.log(client.getReconnectAttempts());
console.log(client.isReconnecting());setReconnectDelay(initial, max) is passed as BigInt to WASM.
Subscription state helpers
client.getSubscriptionCount();
client.getSubscriptions();
client.isSubscribedTo('SELECT * FROM app.messages');
client.getLastSeqId('<subscription-id>');These are SDK-level convenience methods around subscription bookkeeping.
Cleanup pattern
try {
await client.connect();
// work
} finally {
await client.unsubscribeAll();
await client.disconnect();
}Use this pattern in long-running services to avoid leaked subscriptions.
Last updated on