Expand description
TypeScript code generation from parsed Cap’n Proto schemas.
Generates:
capnp.ts— Wire format runtime (CapnpMessageBuilder + CapnpReader){service}.ts— Per-service interfaces, builders, parsers, clientsindex.ts— Re-exports
Modules§
- builders 🔒
- Generate TypeScript request builder functions.
- client 🔒
- Generate TypeScript client classes and scoped client factories.
- interfaces 🔒
- Generate TypeScript interfaces from Cap’n Proto struct and enum definitions.
- message 🔒
- Generates the
capnp.tsshared runtime. - parsers 🔒
- Generate TypeScript response parser functions.
Structs§
- Type
Script Backend - TypeScript code generation backend.
Functions§
- bool_
bit_ 🔒index - Return the bit index for a Bool field.
- capnp_
to_ 🔒ts_ type - Map a Cap’n Proto type name to a TypeScript type.
- data_
byte_ 🔒offset - Compute the byte offset for a data-section field based on its type and slot_offset.
- default_
value_ 🔒expr - Return the default TS expression for a Cap’n Proto type (used for optional field coalescing).
- emit_
enum_ 🔒getter_ expr - Return a TypeScript expression that reads a UInt16 ordinal and maps it to a string enum.
- emit_
enum_ 🔒setter - Emit a
setUint16call that converts a TypeScript string enum to its wire ordinal. - emit_
union_ 🔒alias - Emit a typed discriminated-union alias: one arm per union variant (data
type mirroring the parser output) plus the parser’s
unknowndefault arm, with any non-union fields shared into every arm. Shared by the interface emitter (input aliases) and the parser result aliases. - emits_
union_ 🔒alias truewhen the emitted TypeScript forsdmust be a discriminated-union alias rather than a named-fields-only interface.- enum_
ordinal_ 🔒array - Build a TypeScript array literal from an enum’s variants (camelCase names as strings).
- extract_
list_ 🔒inner_ type - Extract the inner type name from a
List(Foo)type string. ReturnsNonefor non-list types. - generate_
all - Generate all output files from parsed schemas using the given backend.
- generate_
index 🔒 - Generate index.ts with re-exports.
- generate_
service_ 🔒file - Generate a single TypeScript file for a schema.
- getter_
method 🔒 - Return the TypeScript getter method name on
CapnpReader/StructReader. - group_
arm_ 🔒leaves - If union field
ufof structsdis an inlinegrouparm, return its leaf fields (from the structuredunion_armsview).Nonefor Void/single-type arms. - group_
arm_ 🔒type_ name - Name of the synthesized TypeScript interface for a group arm, e.g. the
dropOldestarm ofOverflowPolicy→OverflowPolicyDropOldest. - is_
data_ 🔒scalar - Check if a capnp type is a simple scalar (data section, not pointer).
- is_
primitive 🔒 - Check if a capnp type name is a primitive (not a struct reference).
- is_
referenced_ 🔒data_ type truewhen structnameis referenced as a field, union-arm, group-leaf, or list element type anywhere in the schema.- is_
service_ 🔒envelope truewhensdis a service or scoped request/response envelope — a struct with dedicated builder/parse paths (builders.rs, scoped response parsing) that never constructs or narrows the object type. Envelopes keep their legacy named-fields-only interface; every other union-having struct referenced as a data type must carry its union in the emitted type or the generated serializer/parser shapes disagree (#1616).- list_
getter_ 🔒method - Return the TypeScript getter method name for a
List(<inner>)field. Mirrorslist_setter_method— see its docs. - list_
setter_ 🔒method - Return the TypeScript setter method name for a
List(<inner>)field, given the inner element type name (e.g."Int64","Bool","Text","Data"). - nested_
list_ 🔒getter_ method - Return the TypeScript getter method name for a
List(List(<inner>))field. Mirrorsnested_list_setter_method— see its docs. - nested_
list_ 🔒setter_ method - Return the TypeScript setter method name for a
List(List(<inner>))field, given the doubly-nested (innermost) element type name — e.g."Float32"for theembeddings: List(List(Float32))shape used byinference.capnp/model.capnp. - scan_
exported_ 🔒names - Scan the literal top-level exported symbol names out of generated TS source.
- setter_
method 🔒 - Return the TypeScript setter method name on
CapnpMessageBuilder/StructBuilder. - shared_
union_ 🔒fields - Shared named-field fragments for a union-having struct’s discriminated
aliases. One
name: typeentry per non-union field, with the same nullability rule the parser result aliases use, so the input alias and the*Resultalias stay structurally identical. - union_
arm_ 🔒data_ type - The
data:TypeScript type for one arm of structsd’s discriminated union. - union_
variant_ 🔒data_ type - Map a union-member field to the TypeScript type carried in the
dataslot.