Types & Enums
@kalamdb/client exports the app-facing runtime enums and rich TypeScript types.
Runtime enums
import { MessageType, ChangeType } from '@kalamdb/client';enum MessageType {
SubscriptionAck = 'subscription_ack',
InitialDataBatch = 'initial_data_batch',
Change = 'change',
Error = 'error',
}
enum ChangeType {
Insert = 'insert',
Update = 'update',
Delete = 'delete',
}Auth types
type AuthCredentials =
| { type: 'basic'; username: string; password: string }
| { type: 'jwt'; token: string }
| { type: 'none' };ClientOptions (construction)
createClient({ ... }) accepts a ClientOptions object. Common fields:
url: string— server base URLauthProvider: () => Promise<AuthCredentials>— required auth source for the high-level clientauthProviderMaxAttempts?: number— retry attempts for transient auth-provider failuresauthProviderInitialBackoffMs?: number— initial auth-provider retry backoffauthProviderMaxBackoffMs?: number— max auth-provider retry backoffwsLazyConnect?: boolean— defaulttrue; defer the WebSocket until the first subscription/live callpingIntervalMs?: number— default5000; application-level keepalive intervaldisableCompression?: boolean— dev-only debugging (?compress=false)wasmUrl?: string | BufferSource— override WASM loadingonConnect?,onDisconnect?,onError?,onReceive?,onSend?— connection lifecycle callbackslogLevel?,logListener?— SDK logging controls
There is no high-level auth or autoConnect option on createClient(...).
createConsumerClient({ ... }) from @kalamdb/consumer accepts the same base options plus consumerWasmUrl?: string | BufferSource for worker-only WASM resolution.
Query response model
interface QueryResponse {
status: 'success' | 'error';
results?: QueryResult[];
took?: number;
error?: ErrorDetail;
}
interface QueryResult {
schema?: SchemaField[];
rows?: unknown[][];
named_rows?: Record<string, unknown>[];
row_count: number;
message?: string;
}Prefer named_rows when present. Helper methods queryOne()/queryAll() wrap those rows as RowData, while queryRows() wraps them as FILE-aware KalamRow<T> values.
Subscription and consumer types
ServerMessageSubscriptionOptionsSubscriptionCallback
The topic worker types moved into @kalamdb/consumer:
ConsumeRequestConsumeResponseConsumeMessageConsumeContextConsumerHandleAckResponse
ServerMessage from generated declarations includes:
- auth events (
auth_success,auth_error) - subscription events (
subscription_ack,initial_data_batch,change,error)
Username branded type
types.ts defines a branded Username:
type Username = string & { readonly __brand: unique symbol };
function Username(value: string): Username;Use this in service pipelines when you want stricter domain typing.
Row helper methods
Use client helpers instead of manual parsing:
const one = await client.queryOne('SELECT * FROM app.users WHERE id = $1', ['u1']);
const all = await client.queryAll('SELECT * FROM app.users');
// FILE-aware wrappers
const rows = await client.queryRows<{ id: string; avatar: unknown }>(
'SELECT id, avatar FROM app.users',
'app.users',
);
const avatar = rows[0]?.file('avatar');KalamCellValue & RowData
Every cell in a RowData row is wrapped in a KalamCellValue — a typed
accessor class that mirrors the Rust KalamCellValue newtype.
import { KalamCellValue, wrapRowMap } from '@kalamdb/client';
import type { RowData } from '@kalamdb/client';
const row: RowData = wrapRowMap({ id: '1', score: 9.5, active: true });
row.id.asString(); // "1"
row.score.asFloat(); // 9.5
row.active.asBool(); // true
row.avatar.asFile(); // FileRef | nullSee Cell Values (KalamCellValue) for the full API including all accessor methods and FILE column support.
Type-only imports
Prefer import type for large type sets in app code:
import type { QueryResponse, ServerMessage } from '@kalamdb/client';
import type { ConsumeRequest } from '@kalamdb/consumer';