Skip to main content

Module batch

Module batch 

Source
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§

BatchItemError
Public, safe-to-expose shape of a per-item failure. Mirrors crate::CoolErrorResponse without the optional details field — batch callers asking for per-item detail can repeat the operation singly against the failed item to get the full error envelope.
BatchItemResult
Per-item result inside a BatchResponse. The index is the item’s position in the original request, so clients can pair results with inputs even after server-side reordering (e.g. parallel batch_get fetches in the future).
BatchRequest
Wire envelope for POST /<model>/batch-* request bodies. Holds the items in a single field so the envelope can grow (e.g. a future client_request_id) without breaking deserialization.
BatchResponse
Wire envelope returned by every batch route. Always 200 OK at the HTTP layer; inspect summary.err (or scan results) to surface per-item failures to the user.
BatchSummary
Summary counts attached to every BatchResponse so callers can branch on aggregate status without scanning the result list.

Enums§

BatchItemStatus
Either a successful per-item outcome (Ok) or a per-item failure (Error). Serializes as a tagged enum with the discriminant in status:

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::Validation on the outer Result when exceeded. The cap is identical for all five batch operations; deviating per-op would invite footguns where batch_get accepts a list that batch_create of 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.