Expand description
TypeScript codegen for cargo taut gen (Phase 1 + 2 error narrowing,
Phase 4 validator schemas).
Pure logic: takes an taut_rpc::ir::Ir document and renders a single
api.gen.ts source string. The CLI’s gen subcommand owns the I/O and
validator-flag parsing; this module owns the string-building.
See SPEC.md §3 (type mapping), §3.3/§4.1 (error envelope), §6 (client
API), and §7 (validation bridge). The shape of the generated client
mirrors the runtime declarations in npm/taut-rpc/src/index.ts — every
emitted procedure is a ProcedureDef<I, O, E, Kind>, and the final
Procedures type map is what createClient<Procedures> consumes.
Phase 2 additions:
- For each procedure with a non-empty error set we also emit a
Proc_<name>_Errortype alias right before itsProcedureDef. Callers import this alias to drivee.codenarrowing without touchingunknown. - We emit a runtime
procedureKindsconst (as const satisfies …) socreateClientcan dispatch query vs. mutation vs. subscription without the caller having to thread the map manually.createApidefaults to it but still lets users override viaopts.kinds.
Phase 4 additions:
- For each
TypeDefwe additionally emit a<Name>Schemaconst using the selected validator (valibotis the default,zodis opt-in). The pre-existing TS interface is preserved verbatim so callers who only want types can keep ignoring the schema. - For each procedure we emit
Proc_<name>_inputSchemaandProc_<name>_outputSchemaconstants — either an alias to an existing<Name>Schema(forNamedtypes) or an inline expression (for primitives / composites that don’t have aTypeDefof their own). - We emit a
procedureSchemasruntime map mirroringprocedureKindssocreateClientcan locate a procedure’s schemas by name.
Structs§
- Codegen
Options - Per-invocation knobs for
render_ts.
Enums§
- Validator
- Validator runtime to target in the generated client.
Functions§
- render_
ts - Render an
Irinto a singleapi.gen.tssource string. - render_
ts_ checked - Fallible variant of
render_ts.