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'; user: 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)
UserId branded type
types.ts defines a branded UserId:
type UserId = string & { readonly __brand: unique symbol };
function UserId(value: string): UserId;Use this in service pipelines when you want stricter domain typing.
KalamDataType
KalamDataType mirrors the server’s canonical column type enum and schema
metadata. The SDK supports both scalar and parameterized variants:
| KalamDB type | TypeScript metadata value | Query row wire value |
|---|---|---|
BOOLEAN | 'Boolean' | boolean |
INT | 'Int' | number |
SMALLINT | 'SmallInt' | number |
BIGINT | 'BigInt' | string for Int64 precision |
DOUBLE | 'Double' | number |
FLOAT | 'Float' | number |
TEXT | 'Text' | string |
TIMESTAMP | 'Timestamp' | numeric timestamp or ISO string |
DATE | 'Date' | Date32 day offset or ISO date |
DATETIME | 'DateTime' | numeric timestamp or ISO string |
TIME | 'Time' | microseconds since midnight or time string |
JSON | 'Json' | JSON value |
BYTES | 'Bytes' | byte-number array |
EMBEDDING(n) | { Embedding: n } | number array |
UUID | 'Uuid' | UUID string |
DECIMAL(p,s) | { Decimal: { precision, scale } } | exact decimal string |
FILE | 'File' | FILE reference JSON |
Use KalamCellValue accessors for row reads and @kalamdb/orm for Drizzle
column generation from this metadata.
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 | null
row.total.asDecimal(); // exact string | 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';