Skip to main content

Crate osproxy_rewrite

Crate osproxy_rewrite 

Source
Expand description

Body and query transforms.

Pure transforms with no network or placement lookup: scalar extraction from a document body, document-_id construction, and tenancy-field inject/strip. Held to the highest coverage bar including branch coverage (docs/09).

This crate deliberately depends only on osproxy_core and serde_json: it speaks in primitives (paths, names, JSON values), and the tenancy adapter (osproxy-tenancy) translates SPI rule types into these calls. That keeps the transforms a small, exhaustively testable leaf of the dependency graph.

M2 adds query-DSL filter wrapping (wrap_query, docs/04 §4) and the logical↔physical id mapping for by-id reads. Bulk NDJSON demux (docs/04 §3) lands in M3 alongside its endpoint.

Structs§

BulkItem
One parsed bulk operation: its action, the optional explicit _index/_id/ routing from the action line, and the source document (if any).
MgetItem
One parsed multi-get fetch: the optional explicit _index (else the URL default), the document _id, and the optional routing.
MsearchItem
One parsed multi-search request: the optional explicit index from the header line (else the URL default), and the raw query body line.
ParsedAction
A bulk action line parsed once: its verb plus the _index/_id/routing metadata. The streaming demux parses each action line a single time into this, uses ParsedAction::has_source to decide whether a source line follows before framing the next line, then ParsedAction::into_item to finalize the op — so the action line’s JSON is never parsed twice (ADR-014 stage 4). The buffered parse_bulk already parses each line once.

Enums§

BulkAction
The action of a bulk operation, mirroring OpenSearch’s verbs.
RewriteError
A failure applying a body transform.

Functions§

construct_id
Expands template against the resolved partition and the document doc.
construct_id_bytes
Expands template against the resolved partition and the raw document body, reading {body.<path>} scalars straight from the bytes, without parsing body into a Value (ADR-014). The byte-level twin of construct_id for the streaming write path.
extract_scalar
Follows segments into doc and returns the leaf as a string, if the leaf is a scalar (string, number, or bool).
inject_fields
Inserts each (name, value) into the top-level object of doc.
inject_fields_bytes
Splices fields into the top level of the JSON object in body, returning the new bytes, without parsing body into a Value or re-serializing it (ADR-014). The body is scanned once for its top-level keys (to reject a spoofed reserved field) and the injected fields are written right after the opening {; the rest of the document is copied verbatim. The byte-level twin of inject_fields for the streaming write path.
inject_update
Injects the tenancy fields into the doc and upsert sub-objects of an _update body (docs/04 §3).
map_logical_to_physical
Maps a client-supplied logical id to the physical id stored in OpenSearch, by substituting it for the template’s single {body.<path>} placeholder and expanding {partition} (docs/04 §5).
map_physical_to_logical
Maps a physical id back to the client-facing logical id, the inverse of map_logical_to_physical, by stripping the template’s literal frame.
parse_bulk
Parses an NDJSON _bulk body into its ordered operations.
parse_bulk_action
Parses one bulk action line into a ParsedAction — its verb and metadata — without consuming the source line, the per-op entry point for the streaming demux (ADR-014 stage 4). Validates the single-key {verb: {…}} shape like parse_bulk.
parse_mget
Parses an _mget body into its ordered fetches.
parse_msearch
Parses an _msearch NDJSON body into its ordered searches.
strip_fields
Removes each named field from the top-level object of doc, if present.
validate_json
Validates that body is a single well-formed JSON document, allocating nothing, for the verbatim write path, which forwards the body unchanged but must still reject malformed input.
wrap_query
Wraps the query of a client search body so every match is additionally constrained by filter term(s) the client cannot remove.