atproto_codegen

Alpha. Pre-1.0 and evolving alongside at-record; expect breaking changes between 0.x releases.

Generate Gleam types, JSON codecs, and a typed XRPC client from atproto lexicon files. Parses through the full-fidelity atproto_lexicon AST, lowers to a codegen-friendly view, and runs a small plugin pipeline (types, decode-json, optional xrpc-client) over it. Unsupported defs are reported and skipped, never emitted wrong.

Usage

gleam run -m atproto_codegen -- <lexicons_dir> <out_dir> <out_module> <nsid_prefix>[,...] [client_module]
# types + codecs only:
gleam run -m atproto_codegen -- ./lexicons ./src/my_app/gen my_app/gen com.example.myapp.,com.atproto.
# additionally generate a typed XRPC client module:
gleam run -m atproto_codegen -- ./lexicons ./src/my_app/gen my_app/gen com.example.myapp.,com.atproto. client

Generated blob fields use atproto/blob from atproto_client, so projects consuming generated code with blobs need that dependency.

Lexicon coverage

record and object defs for codecs; query and procedure defs for the client plugin (subscriptions are skipped). Refs resolve across lexicons (a bare NSID ref points at that lexicon's main def). knownValues string sets map to plain String; unknown round-trips through a Dynamic passthrough.