ANW-43 CLI: add a query subcommand writing the /query JSON offline
The README claims the query engine is available offline, but only the merge half was: no subcommand produced the path / frontmatter / last_modified / etag / size projection that GET /query returns. `anwesen query` takes the same --vault and --query flags as merge and writes that document to stdout, compact, one line. src/merge.rs becomes src/oneshot.rs and holds both: one parse-and-load path, so the two subcommands cannot drift in grammar or in how strictly they read a vault. cli.rs shares one VaultQueryArgs between them for the same reason. rfc3339_z moves from http.rs to query.rs, next to the projection whose timestamp dialect it is. Assumed a trailing newline on stdout is wanted here even though merge writes none: the JSON body is one line for jq and shell pipelines, and the newline terminates it rather than joining the document. Flag if wrong. The hurl harness now compares `anwesen query` against GET /query on the fixture vault for four queries before running the suite, so a drift between the two surfaces fails CI.
This commit is contained in:
parent
30bca24b5c
commit
6e07bff08a
9 changed files with 489 additions and 228 deletions
10
src/http.rs
10
src/http.rs
|
|
@ -22,7 +22,7 @@ use axum::http::{HeaderMap, HeaderValue, StatusCode};
|
|||
use axum::middleware::{Next, from_fn, from_fn_with_state};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::routing::get;
|
||||
use chrono::{DateTime, SecondsFormat, Utc};
|
||||
use chrono::{DateTime, Utc};
|
||||
use http_body::Body as _;
|
||||
use hydra::Process;
|
||||
use serde::Serialize;
|
||||
|
|
@ -32,17 +32,11 @@ use std::path::PathBuf;
|
|||
|
||||
use crate::app::RestartCounters;
|
||||
use crate::health::HealthState;
|
||||
use crate::query::rfc3339_z;
|
||||
use crate::store::NoteStore;
|
||||
use crate::telemetry::{self, Telemetry, TraceHeaders};
|
||||
use crate::vault::{Note, frontmatter_to_json};
|
||||
|
||||
/// Canonical RFC 3339 form with a `Z` suffix -- the shape the User Manual
|
||||
/// example uses for `last_modified`. Centralized here so every HTTP
|
||||
/// `last_modified` field stays in the same dialect.
|
||||
fn rfc3339_z(dt: DateTime<Utc>) -> String {
|
||||
dt.to_rfc3339_opts(SecondsFormat::Secs, true)
|
||||
}
|
||||
|
||||
/// Shared state injected into every handler.
|
||||
#[derive(Clone)]
|
||||
pub struct HttpState {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue