TypeScript client SDK for Fitz.
Requires Node.js 20.19 or later.
npm install @cntryl/fitzimport { Client } from "@cntryl/fitz";
const client = Client({
url: "ws://localhost:4090/ws",
tokenProvider: async () => "your-jwt-token",
reconnect: { enabled: true },
asyncHandlers: {
maxConcurrency: 32,
timeoutMs: 5000,
},
});
await client.connect();
const tx = await client.kv().begin("kv://realm/area/users", "ReadWrite");
await tx.put(new TextEncoder().encode("user-1"), new TextEncoder().encode('{"name":"Alice"}'));
await tx.commit();
await client.close();fitz-ts now supports additive observability hooks through ClientConfig.observability.
import { Client } from "@cntryl/fitz";
const client = Client({
url: "ws://localhost:4090/ws",
reconnect: { enabled: true },
observability: {
logger: {
log(level, event, fields) {
console.log(level, event, fields);
},
},
onLifecycleEvent(event) {
console.log(event.event, event.state);
},
},
});See docs/OPERATIONS.md for lifecycle events, metric names, and production guidance.
import type { StreamFilterSet } from "@cntryl/fitz";
const filter: StreamFilterSet = {
clauses: [{ kind: "Equals", value: "proj.alpha" }],
};
const records = await client.stream().read("stream://realm/app/events", 0n, 100, {
filter,
maxBytes: 64_000n,
});
const page = await client.stream().readPage("stream://realm/app/events", 0n, 100, {
filter,
maxBytes: 64_000n,
});
// read() keeps the compatibility projection and returns event records only.
// readPage() exposes synthetic filtered markers and cursor metadata.
void records;
void page.cursor.lastResourceOffset;- Different domains can operate concurrently on one client connection.
- Multiple independent KV transactions and stream sessions can also be active concurrently.
- Do not issue overlapping operations against the same KV transaction or the same stream session. Those stateful handles are intended to be used sequentially.
- Notification and RPC worker handlers run through a shared async dispatcher. Use
asyncHandlers.maxConcurrencyandasyncHandlers.timeoutMsto bound handler fan-out in production.
- WebSocket: browser and Node.js
- TCP: Node.js only
- Auto transport detection: defaults to WebSocket when the URL omits a scheme
Fast local checks:
npm ci
npm run verify:fastBroker-backed verification:
docker compose -f ../fitz-go/compose.yml up -d
npm run verify
docker compose -f ../fitz-go/compose.yml down --volumesPackage smoke verification:
npm run pack:smokeSuggested release checklist:
npm ci
npm run verify:fast
docker compose -f ../fitz-go/compose.yml up -d
npm run verify
npm run bench
docker compose -f ../fitz-go/compose.yml down --volumesTiered benchmark commands:
npm run bench:tier1
npm run bench:tier2
npm run bench:tier3
npm run bench:tier4
npm run benchRun the full suite repeatedly before relying on benchmark automation.
tier4is broader and more integration-style, so it should be stabilized over multiple executions before adding CI thresholds.
Benchmark tiers:
tier1: hot-path microbenchmarks for core frame, codec, and multiplexer/parse runtime costs.tier2: subsystem benchmarks for domain-level payload and request-encoding workloads.tier3: system benchmarks for combined protocol and client flow payloads.tier4: integration benchmarks for realistic multi-message encode and frame assembly scenarios.
The conformance harness writes JSON results to artifacts/conformance-results.json by default.
Tooling is direct:
vp checkfor combined format, lint, and type checksvp fmtfor formattingvp lintfor lintingvp testfor unit, integration, and conformance testsvp packfor JS bundle outputtscfor declaration emittscfor typechecking and declaration emit
Published artifacts are smoke-tested from the packed tarball in both ESM and CommonJS consumer fixtures before release.
src/client: public client facade and connection managementsrc/transport: WebSocket and TCP transportssrc/domains: domain clients and codecstests/unit: fast unit coveragetests/integration: broker-backed integration coveragetests/conformance: release-gate conformance suite
Broker-backed connection hardening coverage now includes automatic reconnect subscription replay and token-provider replay checks in tests/integration/connection.test.ts.
fitz-ts follows the canonical Fitz client docs in the server repo: