Expand description
Batch envelope.
tRPC-style per-item envelope for batch operations. The HTTP
response is always 200 OK carrying a BatchResponse<T>;
whole-batch infrastructure failures (bad request shape, size cap
exceeded, DB connection lost) still flow through the outer
Result<_, CoolError> and map to their usual status codes via
the standard handler.
Per-item failures (validation, policy denial, not-found, stale
if_match, PK conflict) ride inside BatchItemStatus::Error
and DO NOT abort the batch — successful items in the same request
still commit. The transactional model used by the server backends
is one outer transaction with a per-item SAVEPOINT, so failed
items leave no audit row, no event outbox entry, and no row
mutation.
Structs§
- Batch
Item Error - Public, safe-to-expose shape of a per-item failure. Mirrors
crate::CoolErrorResponsewithout the optionaldetailsfield — batch callers asking for per-item detail can repeat the operation singly against the failed item to get the full error envelope. - Batch
Item Result - Per-item result inside a
BatchResponse. Theindexis the item’s position in the original request, so clients can pair results with inputs even after server-side reordering (e.g. parallelbatch_getfetches in the future). - Batch
Request - Wire envelope for
POST /<model>/batch-*request bodies. Holds the items in a single field so the envelope can grow (e.g. a futureclient_request_id) without breaking deserialization. - Batch
Response - Wire envelope returned by every batch route. Always
200 OKat the HTTP layer; inspectsummary.err(or scanresults) to surface per-item failures to the user. - Batch
Summary - Summary counts attached to every
BatchResponseso callers can branch on aggregate status without scanning the result list.
Enums§
- Batch
Item Status - Either a successful per-item outcome (
Ok) or a per-item failure (Error). Serializes as a tagged enum with the discriminant instatus:
Constants§
- BATCH_
MAX_ ITEMS - Default upper bound on items in a single batch request. Server
backends enforce this before any SQL runs and surface
CoolError::Validationon the outerResultwhen exceeded. The cap is identical for all five batch operations; deviating per-op would invite footguns wherebatch_getaccepts a list thatbatch_createof the same length rejects.
Functions§
- find_
duplicate_ position - Detect duplicate keys in a batch input, loud-failing the whole request when found. Returns the first duplicate (by position) so the surfaced error can name a specific offending index. Linear- time, allocation-only in proportion to the input length.