Skip to main content

Module ts_codegen

Module ts_codegen 

Source
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, clients
  • index.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.ts shared runtime.
parsers 🔒
Generate TypeScript response parser functions.

Structs§

TypeScriptBackend
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 setUint16 call 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 unknown default 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 🔒
true when the emitted TypeScript for sd must 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. Returns None for 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 uf of struct sd is an inline group arm, return its leaf fields (from the structured union_arms view). None for Void/single-type arms.
group_arm_type_name 🔒
Name of the synthesized TypeScript interface for a group arm, e.g. the dropOldest arm of OverflowPolicy → 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 🔒
true when struct name is referenced as a field, union-arm, group-leaf, or list element type anywhere in the schema.
is_service_envelope 🔒
true when sd is 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. Mirrors list_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. Mirrors nested_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 the embeddings: List(List(Float32)) shape used by inference.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: type entry per non-union field, with the same nullability rule the parser result aliases use, so the input alias and the *Result alias stay structurally identical.
union_arm_data_type 🔒
The data: TypeScript type for one arm of struct sd’s discriminated union.
union_variant_data_type 🔒
Map a union-member field to the TypeScript type carried in the data slot.