nori_asyncapi

AsyncAPI 3.x code generation for Gleam.

A satellite of nori: parses AsyncAPI specs, builds a codegen IR whose payload types reuse nori’s type model, and emits TypeScript clients and Gleam handler stubs.

Quick start

import nori_asyncapi

pub fn main() {
  let assert Ok(doc) = nori_asyncapi.parse_file("asyncapi.yaml")
  let spec = nori_asyncapi.build_ir(doc)
  let ts = nori_asyncapi.generate_typescript(spec)
  let gleam = nori_asyncapi.generate_gleam_handlers(spec)
}

Values

pub fn build_ir(doc: document.Document) -> ir.AsyncCodegenIR

Build the codegen IR from a parsed document.

pub fn generate_gleam_handlers(
  spec: ir.AsyncCodegenIR,
  types_module: String,
) -> String

Generate a Gleam handler-stub module. types_module is the import path of the companion module from generate_gleam_types.

pub fn generate_gleam_server(
  spec: ir.AsyncCodegenIR,
  types_module: String,
) -> String

Generate the Gleam server dispatcher — a transport-neutral runtime that decodes incoming {type, payload} frames into typed handler calls and encodes outgoing messages. types_module is the import path of the companion module from generate_gleam_types.

pub fn generate_gleam_types(spec: ir.AsyncCodegenIR) -> String

Generate a Gleam payload-types module (records/enums + JSON codecs), reusing nori’s Gleam type emitter.

pub fn generate_typescript(spec: ir.AsyncCodegenIR) -> String

Generate the neutral TypeScript client (payload types + per-channel client). No framework dependency.

pub fn generate_typescript_gateway(
  spec: ir.AsyncCodegenIR,
) -> String

Generate a gateway TypeScript client: one WebSocket multiplexing all channels via a {type,payload} envelope — the format the generated Gleam server dispatcher speaks. Use instead of generate_typescript when the server is a single /ws gateway.

pub fn generate_typescript_stores(
  spec: ir.AsyncCodegenIR,
  client_module: String,
) -> String

Generate the neutral TypeScript store layer — one useSyncExternalStore- compatible observable per subscribe message. client_module is the import path of the client module (e.g. "./client"). Imports no UI framework.

pub fn gleam_handlers_present(spec: ir.AsyncCodegenIR) -> Bool

Whether generate_gleam_handlers would produce any handler stubs. A send-only spec has none, so handlers.gleam should be skipped rather than written as an empty module (which warns on gleam build).

pub fn parse_file(
  path: String,
) -> Result(document.Document, yaml.LoadError)

Load and parse an AsyncAPI spec file (YAML or JSON, by extension).

pub fn parse_json(
  input: String,
) -> Result(document.Document, yaml.LoadError)

Parse an AsyncAPI document from a JSON string.

pub fn parse_yaml(
  input: String,
) -> Result(document.Document, yaml.LoadError)

Parse an AsyncAPI document from a YAML string.

Search Document