citum_server/lib.rs
1/*
2SPDX-License-Identifier: MIT OR Apache-2.0
3SPDX-FileCopyrightText: © 2023-2026 Bruce D'Arcus and Citum contributors
4*/
5
6//! Citum JSON-RPC server.
7//!
8//! `citum-server` runs `citum-engine` behind a process boundary for clients
9//! that need a standalone renderer instead of linking the engine directly.
10//! The crate supports stdio JSON-RPC in every build and an axum HTTP transport
11//! through the default-on `http` feature. Both transports expose the same
12//! JSON-RPC method surface; only the framing changes.
13//!
14//! ## Methods
15//!
16//! | Method | Required params | Optional params | Result |
17//! |---|---|---|---|
18//! | `render_citation` | `style_path`, `refs`, `citation` | `output_format`, `inject_ast_indices` | rendered citation string |
19//! | `render_bibliography` | `style_path`, `refs` | `output_format`, `inject_ast_indices` | rendered bibliography object |
20//! | `validate_style` | `style_path` | none | validation object |
21//! | `format_document` | `style`, `refs`, `citations` | `output_format`, `locale`, `document_options` | `{formatted_citations, bibliography, warnings}` |
22//! | `open_session` ¹ | `style` | `style_overrides`, `locale`, `output_format`, `document_options` | `{session_id}` |
23//! | `put_references` ¹ | `refs` | `session_id` | `{}` |
24//! | `insert_citations_batch` ¹ | `citations` | `session_id` | session mutation result |
25//! | `insert_citation` ¹ | `citation` | `session_id`, `position` | session mutation result |
26//! | `update_citation` ¹ | `citation_id`, `citation` | `session_id`, `position` | session mutation result |
27//! | `delete_citation` ¹ | `citation_id` | `session_id` | session mutation result |
28//! | `preview_citation` ¹ | `items` | `session_id`, `position` | preview result |
29//! | `get_citations` ¹ | — | `session_id` | `{formatted_citations}` |
30//! | `get_bibliography` ¹ | — | `session_id` | `{bibliography}` |
31//! | `close_session` ¹ | — | `session_id` | `{}` |
32//!
33//! ¹ Requires the `session` feature (default-on). `session_id` is optional in
34//! stdio (omit it or pass `"default"`) and required in HTTP. Session mutation
35//! methods return `{formatted_citations, bibliography, warnings}`.
36//!
37//! `refs` in `render_citation` and `render_bibliography` is an inline JSON map
38//! of native Citum reference objects. `refs` in `format_document` accepts
39//! `citum-engine`'s tagged [`citum_engine::RefsInput`] shape, including local
40//! bibliography paths, inline YAML, inline JSON, and legacy bare JSON maps.
41//! Dates are EDTF strings such as `"1988"`, not CSL-JSON `date-parts` objects.
42//!
43//! `render_citation`, `render_bibliography`, and `validate_style` accept
44//! `style_path`, a string path to a local Citum YAML style. `format_document`
45//! and the session methods accept the richer `style` object, for example
46//! `{ "kind": "path", "value": "styles/embedded/apa-7th.yaml" }`.
47//!
48//! See [`rpc`] for the request envelope and stdio transport details.
49#![cfg_attr(feature = "http", doc = "See [`http`] for the default HTTP transport.")]
50#![cfg_attr(
51 not(feature = "http"),
52 doc = "The HTTP transport is unavailable in this build because the `http` feature is disabled."
53)]
54//!
55//! ## Features
56//!
57//! - `session`: stateful session API (`open_session`, `insert_citation`, etc.); enabled by default.
58//! - `async`: Tokio runtime support used by HTTP transport.
59//! - `http`: axum HTTP transport; enabled by default and implies `async`.
60//! - `schema`: `/rpc/schema` plus schema derivations.
61//! - `schema-types`: schema derivations without the HTTP schema endpoint.
62
63/// Server error types and conversions.
64pub mod error;
65/// JSON-RPC request handling and stdio transport.
66pub mod rpc;
67
68#[cfg(feature = "http")]
69/// Default HTTP transport built on axum.
70pub mod http;
71
72pub use error::ServerError;
73pub use rpc::dispatch;