Registry / serialization / capnpc-ts

capnpc-ts

JSON →
library0.7.0jsnpmunverified

Cap'n Proto schema compiler for TypeScript, version 0.7.0. Generates TypeScript type definitions and serialization code from .capnp schema files. Requires the capnp command-line tool (C++ reference implementation). Updated irregularly; key differentiator: enables type-safe Cap'n Proto usage in TypeScript without external RPC dependencies.

npm install capnpc-ts
INSTALL
IMPORT
SIG · CAPNPC-TS
C
capnpc-ts
serializationjavascriptv0.7.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

capnpc-ts
npm install -g capnpc-ts
npm install capnpc-ts --save-dev
Package is typically installed globally to use as a CLI tool; dev dependency usage is possible but not common.
capnpc-ts as a plugin
capnpc -o ts path/to/schema.capnp
capnpc -o capnpc-ts schema.capnp
The -o option expects the plugin name without 'capnpc-' prefix; use 'ts' not the full package name.
Generated TS code
import { MyStruct } from './schema.capnp.ts'
import MyStruct from './schema.capnp.ts'
The generated file exports types as named exports; default import will fail unless explicitly set.

Install capnpc-ts globally, compile a sample .capnp schema to TypeScript, and use the generated code.

// Install the compiler globally npm install -g capnpc-ts // Create a sample schema file: example.capnp // @0xbf5147cbbecf40c1; // struct Person { // name @0 :Text; // age @1 :UInt32; // } // Compile the schema const { execSync } = require('child_process'); execSync('capnpc -o ts example.capnp', { stdio: 'inherit' }); // Use the generated code const { Person } = require('./example.capnp.ts'); const msg = new capnp.Message(); const person = msg.initRoot(Person); person.setName('Alice'); person.setAge(30); console.log(person.getName()); // 'Alice'
Debug
Known issues
gotchaMust have capnp tool installed separately; capnpc-ts does not bundle the Cap'n Proto compiler.
fix
Install capnp from https://capnproto.org/install.html or via package manager (e.g., brew install capnp on macOS).
affects: all
gotchaGenerated output file has a .ts extension appended to the original schema file, e.g., myschema.capnp.ts.
fix
Be aware that the output path includes the .capnp extension; adjust tsconfig.json if needed to include .ts files.
affects: all
gotchaPlugin name is 'ts', not 'capnpc-ts'. Using capnpc -o capnpc-ts fails.
fix
Use -o ts instead of -o capnpc-ts.
affects: all
breakingGenerated TypeScript code depends on @capnp-ts/core library for runtime support, but this may not be documented clearly.
fix
Install @capnp-ts/core as a runtime dependency: npm install @capnp-ts/core.
affects: >=0.6.0
Errors
Common errors & fixes
capnpc: Invalid option 'ts'
capnpc-ts not installed or not on PATH; capnp cannot find the plugin.
fix
Ensure capnpc-ts is installed globally: npm install -g capnpc-ts. Verify plugin is accessible.
module '...' has no exported member 'MyStruct'
Using default import when generated code uses named exports.
fix
Use named import: import { MyStruct } from './my.capnp.ts';
Cannot find module 'capnp-ts'
Missing runtime dependency @capnp-ts/core (or older capnp-ts package).
fix
Install runtime dependency: npm install @capnp-ts/core (or capnp-ts for older versions).
Upgrade
Version history
0.7.0latest on npm
Audit
Dependencies
capnprequiredRequired to compile .capnp schemas; capnpc-ts is a plugin for the capnp tool
Agent activity
47 hits · last 30 days
node
38
OpenAI (training)
1
Resources
capnpc-ts — npm install capnpc-ts · libregistry