Skip to main content

table_editor/
lib.rs

1//! A browser-based editor for a repository's JSONL tables.
2//!
3//! A repository describes its tables by implementing [`TableLogic`] once per
4//! table—parse, serialize, validate, derive, siblings, and a column
5//! [`Schema`]—and [`App`] once for the collection. [`Server`] turns that into a
6//! local HTTP server: it serves the embedded browser bundle at `/` and the
7//! editor's API under `/api`.
8//!
9//! The API is `GET /api/app` for the shell (the app's name and its tables) and
10//! three endpoints per table: `GET /api/<table>` reads, `PUT /api/<table>`
11//! writes, and `POST /api/<table>/derive` validates and derives without
12//! writing. A view is `GET /api/views/<view>`, and what one of its buttons
13//! writes is `POST /api/views/<view>/actions/<name>`. `GET /api/health` and
14//! `POST /api/shutdown` control the process. All file I/O runs here, through
15//! the [`Context`] that resolves the `Data/` directory; the browser is a thin
16//! UI that renders whatever the schema in the GET payload describes.
17//!
18//! Launching reuses an already-running server on the same port (it just opens a
19//! browser at it); `--restart` shuts the old one down first and starts fresh.
20//! The server itself runs as a detached worker process, marked by an
21//! environment variable so it serves rather than re-spawning itself.
22//!
23//! # Features
24//!
25//! `server` is on by default and is everything above. Without it the crate is
26//! the file format alone—[`jsonl`], [`ParseError`], [`ValidationError`], and
27//! [`ApiError`]—and depends on nothing but `serde` and `serde_json`, which is
28//! what a crate that only reads and writes the tables wants.
29
30mod error;
31pub mod jsonl;
32
33#[cfg(feature = "server")]
34mod context;
35#[cfg(feature = "server")]
36mod launch;
37#[cfg(feature = "server")]
38mod page;
39#[cfg(feature = "server")]
40mod probe;
41#[cfg(feature = "server")]
42mod routes;
43#[cfg(feature = "server")]
44mod schema;
45#[cfg(feature = "server")]
46mod server;
47#[cfg(feature = "server")]
48mod table;
49#[cfg(feature = "server")]
50mod view;
51
52#[cfg(all(test, feature = "server"))]
53mod fixture;
54
55pub use error::{ApiError, ParseError, ValidationError};
56
57#[cfg(feature = "server")]
58pub use context::Context;
59#[cfg(feature = "server")]
60pub use page::{
61    Button, Card, CardGroup, Detail, DetailRow, DetailSection, Field, Form, Section, Status, Tone,
62    ViewLink,
63};
64#[cfg(feature = "server")]
65pub use probe::{probe, probe_status};
66#[cfg(feature = "server")]
67pub use schema::{
68    ChipContent, Column, ColumnType, Datalist, FromRows, MapSpec, NewRow, OptionsBy, Schema,
69    SelectOption, Speak,
70};
71#[cfg(feature = "server")]
72pub use server::{Server, ServerArgs, ServerCommand};
73#[cfg(feature = "server")]
74pub use table::{App, Front, Table, TableLogic};
75#[cfg(feature = "server")]
76pub use view::{Fields, Param, View, ViewArgs, ViewData, ViewLogic};