Skip to main content

metaxy_cli/
lib.rs

1//! CLI tool for the [metaxy](https://github.com/misha-mad/metaxy) project.
2//!
3//! Scans Rust lambda source files for `#[rpc_query]` / `#[rpc_mutation]`
4//! functions and `#[derive(Serialize)]` types, then generates TypeScript type
5//! definitions and a fully typed RPC client.
6//!
7//! # Binary
8//!
9//! The installed binary is called `metaxy` and provides three subcommands:
10//!
11//! - **`metaxy scan`** — parse a directory and print discovered procedures as
12//!   human-readable text plus a JSON manifest.
13//! - **`metaxy generate`** — produce `rpc-types.ts` (interfaces + `Procedures`
14//!   type) and `rpc-client.ts` (typed `RpcClient` + `createRpcClient` factory).
15//! - **`metaxy watch`** — same as `generate`, but re-runs automatically whenever
16//!   a `.rs` file changes (configurable debounce).
17//!
18//! # Architecture
19//!
20//! ```text
21//! ┌─────────────┐  scan   ┌──────────┐  codegen  ┌─────────────────────────┐
22//! │  api/*.rs   │ ──────► │ Manifest │ ────────► │ rpc-types.ts            │
23//! │  attributes │  (syn)  │          │ (fmt)     │ rpc-client.ts           │
24//! └─────────────┘         └──────────┘           │ rpc.{svelte,react,…}.ts │
25//!                                                └─────────────────────────┘
26//! ```
27//!
28//! - [`parser`] — walks the source directory, parses each `.rs` file with
29//!   `syn`, and builds a [`model::Manifest`].
30//! - [`codegen::typescript`] — converts the manifest into a `rpc-types.ts`
31//!   file with TypeScript interfaces, enum types, and a `Procedures` map.
32//! - [`codegen::client`] — converts the manifest into a `rpc-client.ts` file
33//!   with a typed `RpcClient` interface and `createRpcClient` factory.
34//! - [`codegen::svelte`] — Svelte 5 reactive wrappers (`createQuery`, `createMutation`).
35//! - [`codegen::react`] — React hooks (`useQuery`, `useMutation`).
36//! - [`codegen::vue`] — Vue 3 Composition API (`useQuery`, `useMutation`).
37//! - [`codegen::solid`] — SolidJS reactive primitives (`createQuery`, `createMutation`).
38//! - [`watch`] — wraps `generate` in a file-watcher loop with debouncing.
39
40pub mod codegen;
41pub mod commands;
42pub mod config;
43pub mod model;
44pub mod parser;
45pub mod watch;