#![deny(missing_docs)]
mod admin;
mod asyncwrite;
mod bulk;
mod bulkline;
mod bulkprep;
mod cursor;
mod dbq;
mod endpoints;
mod error;
mod mget;
mod msearch;
mod observe;
mod passthrough;
mod pipeline;
mod pit;
mod plan;
mod read;
mod retry;
mod search_scan;
mod search_stream;
pub use admin::AdminPolicy;
pub use asyncwrite::{
op_id_for, unsupported_async, valid_op_id, NoQueue, QueueError, QueuedWrite, WriteMode,
WriteQueue,
};
pub use error::RequestError;
pub use passthrough::PassthroughPolicy;
pub use pipeline::{Pipeline, PipelineResponse};
pub use plan::build_write_batch;
pub use retry::RetryPolicy;
pub use search_stream::StreamSearch;
#[doc(hidden)]
pub mod bench_support {
use osproxy_core::FieldName;
use osproxy_spi::{DocIdRule, IdTemplate};
use crate::read::{shape_hits, ReadShape};
use crate::search_scan::{HitShaper, SearchHitsScanner};
fn shape() -> ReadShape {
ReadShape {
inject_names: vec![FieldName::from("_tenant")],
id_rule: Some(
DocIdRule::new(IdTemplate::new("{partition}:{body.id}")).with_routing(true),
),
}
}
#[must_use]
pub fn response(n_hits: usize, agg_bytes: usize) -> Vec<u8> {
let mut s = String::from(r#"{"took":5,"hits":{"total":{"value":"#);
s.push_str(&n_hits.to_string());
s.push_str(r#"},"hits":["#);
for i in 0..n_hits {
if i > 0 {
s.push(',');
}
s.push_str(r#"{"_index":"shared","_id":"acme:"#);
s.push_str(&i.to_string());
s.push_str(r#"","_routing":"acme","_source":{"_tenant":"acme","msg":"record number "#);
s.push_str(&i.to_string());
s.push_str(r#""}}"#);
}
s.push_str(r#"]},"aggregations":{"blob":""#);
s.push_str(&"x".repeat(agg_bytes));
s.push_str(r#""}}"#);
s.into_bytes()
}
#[must_use]
pub fn buffered(body: &[u8]) -> Vec<u8> {
shape_hits(body, "orders", "acme", &shape()).unwrap_or_default()
}
#[must_use]
pub fn streaming(body: &[u8]) -> Vec<u8> {
let shaper = HitShaper {
logical_index: "orders".to_owned(),
partition: "acme".to_owned(),
shape: shape(),
};
let mut scanner = SearchHitsScanner::new(shaper);
let mut out = scanner.feed(body);
out.extend(scanner.finish());
out
}
}