Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

TypeScript SDK reference

The TypeScript SDK is published as @panproto/core. It wraps the WASM build of panproto with a fluent, handle-based API.

Installation

npm install @panproto/core
# or
pnpm add @panproto/core
# or
yarn add @panproto/core

Node 20+ is required. Browser builds are supported via the same package; a bundler with WASM support is needed.

Initialization

import { Panproto } from '@panproto/core';

const p = await Panproto.init();

Panproto.init() loads the WASM module, sets up the slab allocator behind the boundary, and returns the top-level handle. All subsequent calls go through it.

Surface

The SDK exposes (selected; see bindings/typescript/src/index.ts for the full list):

Object / functionPurpose
PanprotoTop-level handle. init(), protocol(name), migration(src, tgt), parseJson(schema, json), toJson(schema, instance), convert(data, { from, to, defaults? }), compose(m1, m2), composeLenses(l1, l2), checkExistence(src, tgt, builder), diffFull(old, new).
ProtocolA loaded protocol. .name, .schema() returns a SchemaBuilder.
SchemaBuilderFluent builder. .vertex(name, kind), .edge(src, tgt, kind, opts), .build() returns BuiltSchema.
BuiltSchemaA built schema. .vertices, .edges, .protocol.
InstanceA parsed data record. .toJson(), .validate().
MigrationBuilderBuilder. .map(srcVertex, tgtVertex), .mapEdge(srcEdge, tgtEdge), .resolve(...), .compile() returns CompiledMigration.
CompiledMigrationA migration that is a lens. .lift(record) returns LiftResult { data, _rawBytes? }; .get(record) returns GetResult { view, complement }; .put(view, complement) returns LiftResult.
LensHandleA free-standing protolens chain. .get(bytes), .put(view, complement), .checkLaws(instance) returns LawCheckResult { holds, violation }; .checkGetPut, .checkPutGet for individual laws; .toJson().
FullDiffReport / CompatReportReturned by Panproto.diffFull(old, new). Call .classify(protocol) on the diff to get a CompatReport with classification of fully-compatible / backward-compatible / breaking.
executeQuery(query, instance, wasm)Standalone query function. The query is InstanceQuery { anchor, predicate?, projection?, path?, groupBy?, limit? }; the predicate is an Expr object, not a source string.
parseExpr, evalExpr, formatExpr, ExprBuilderExpression-language entry points.
IoRegistryMulti-protocol parse/emit registry.
Repositorypanproto-vcs repository handle.
DataSetHandleData-versioning handle.

Full API documentation, including every method signature and parameter, lives in the TypeDoc output:

The package source is at bindings/typescript/.

Boundary characteristics

The SDK is a thin layer over panproto-wasm. Data crossing the boundary is encoded with MessagePack, and live values on the Rust side are referenced from JavaScript through opaque integer handles allocated from a slab. Object identity is preserved across calls, so storing handles in JavaScript data structures is safe.

See also