1#![deny(missing_docs)]
16
17mod admin;
18mod asyncwrite;
19mod bulk;
20mod bulkprep;
21mod cursor;
22mod dbq;
23mod endpoints;
24mod error;
25mod mget;
26mod msearch;
27mod observe;
28mod passthrough;
29mod pipeline;
30mod pit;
31mod plan;
32mod read;
33mod retry;
34mod search_scan;
35mod search_stream;
36
37pub use admin::AdminPolicy;
38pub use asyncwrite::{
39 op_id_for, unsupported_async, valid_op_id, NoQueue, QueueError, QueuedWrite, WriteMode,
40 WriteQueue,
41};
42pub use error::RequestError;
43pub use passthrough::PassthroughPolicy;
44pub use pipeline::{Pipeline, PipelineResponse};
45pub use plan::build_write_batch;
46pub use retry::RetryPolicy;
47pub use search_stream::StreamSearch;
48
49#[doc(hidden)]
53pub mod bench_support {
54 use osproxy_core::FieldName;
55 use osproxy_spi::{DocIdRule, IdTemplate};
56
57 use crate::read::{shape_hits, ReadShape};
58 use crate::search_scan::{HitShaper, SearchHitsScanner};
59
60 fn shape() -> ReadShape {
63 ReadShape {
64 inject_names: vec![FieldName::from("_tenant")],
65 id_rule: Some(
66 DocIdRule::new(IdTemplate::new("{partition}:{body.id}")).with_routing(true),
67 ),
68 }
69 }
70
71 #[must_use]
75 pub fn response(n_hits: usize, agg_bytes: usize) -> Vec<u8> {
76 let mut s = String::from(r#"{"took":5,"hits":{"total":{"value":"#);
77 s.push_str(&n_hits.to_string());
78 s.push_str(r#"},"hits":["#);
79 for i in 0..n_hits {
80 if i > 0 {
81 s.push(',');
82 }
83 s.push_str(r#"{"_index":"shared","_id":"acme:"#);
84 s.push_str(&i.to_string());
85 s.push_str(r#"","_routing":"acme","_source":{"_tenant":"acme","msg":"record number "#);
86 s.push_str(&i.to_string());
87 s.push_str(r#""}}"#);
88 }
89 s.push_str(r#"]},"aggregations":{"blob":""#);
90 s.push_str(&"x".repeat(agg_bytes));
91 s.push_str(r#""}}"#);
92 s.into_bytes()
93 }
94
95 #[must_use]
98 pub fn buffered(body: &[u8]) -> Vec<u8> {
99 shape_hits(body, "orders", "acme", &shape()).unwrap_or_default()
100 }
101
102 #[must_use]
106 pub fn streaming(body: &[u8]) -> Vec<u8> {
107 let shaper = HitShaper {
108 logical_index: "orders".to_owned(),
109 partition: "acme".to_owned(),
110 shape: shape(),
111 };
112 let mut scanner = SearchHitsScanner::new(shaper);
113 let mut out = scanner.feed(body);
114 out.extend(scanner.finish());
115 out
116 }
117}