TypeScript SDK
TypeScript SDK for building client applications that connect to EvidentSource servers.
Status: Stable
SDK Components
Section titled “SDK Components”| Component | Description |
|---|---|
| @evidentsource/core | Core library: identifiers, events, selectors, constraints |
| @evidentsource/client | Client library: gRPC connectivity to EvidentSource servers |
Requirements
Section titled “Requirements”- Node.js 20.0 or later
- pnpm 9.0 or later
- Protocol Buffers compiler (
protoc) for proto generation
Installation
Section titled “Installation”# Install from source (development)git clone https://github.com/evidentsystems/evidentsource-sdks.gitcd evidentsource-sdks/typescriptpnpm installpnpm buildQuick Start
Section titled “Quick Start”import { EvidentSource, databaseName, stateViewName, stateChangeName, jsonCommandRequest, stateViewContentAsJson, DatabaseError,} from "@evidentsource/client";
// Connect to serverconst es = EvidentSource.connect("http://localhost:50051");
// Create database if neededconst dbName = databaseName("my-database");try { await es.createDatabase(dbName);} catch (e) { if (e instanceof DatabaseError && e.code === "ALREADY_EXISTS") { // Already exists, that's fine } else { throw e; }}
// Get connectionconst conn = await es.connectDatabase(dbName);
// Execute a state changeconst db = await conn.executeStateChange( stateChangeName("create-todo"), 1, jsonCommandRequest({ todoId: "123", title: "Buy milk", effectiveTimestamp: new Date().toISOString(), }));
// Query a state viewconst view = await db.viewState(stateViewName("todo-list"), 1);const todos = stateViewContentAsJson<{ todos: Todo[] }>(view);
// Clean upawait conn.close();es.close();Features
Section titled “Features”Branded Types
Section titled “Branded Types”Type-safe identifiers with runtime validation:
import { databaseName, streamName, stateViewName } from "@evidentsource/core";
const dbName = databaseName("my-database"); // Validated at runtimeconst viewName = stateViewName("account-summary");Composable Selectors
Section titled “Composable Selectors”Build event selectors with a fluent API:
import { EventSelector, streamName, eventType } from "@evidentsource/core";
const selector = EventSelector.and( EventSelector.streamEquals(streamName("accounts")), EventSelector.typeStartsWith(eventType("com.example.")));Connection Management
Section titled “Connection Management”Automatic subscription and reconnection:
const conn = await es.connectDatabase(dbName);
// Connection maintains a live subscription to the database// Automatically reconnects on connection loss
// Get the latest database stateconst db = await conn.latestDatabase();console.log(`Current revision: ${db.revision}`);Examples
Section titled “Examples”| Example | Description |
|---|---|
| TodoMVC | Server-side rendered todo app with HTMX |
| Savings Account | REST API for banking operations |
Project Structure
Section titled “Project Structure”typescript/├── packages/│ ├── evidentsource-core/ # Foundation types (no dependencies)│ └── evidentsource-client/ # gRPC client└── examples/ ├── todomvc/ # Server-rendered todo app └── savings-account/ # Banking REST APIDevelopment
Section titled “Development”# Install dependenciespnpm install
# Build all packagespnpm build
# Run testspnpm test
# Type checkpnpm lintAPI Reference
Section titled “API Reference”API documentation will be available on npm when packages are published.
Next Steps
Section titled “Next Steps”- Getting Started - Build your first EvidentSource application
- State Views - Learn about view materialization
- Bi-Temporal Queries - Query historical state