pub fn enforce_max_objects_in_set(
args: &Map<String, Value>,
max: u64,
) -> Result<(), JmapError>Expand description
Enforce RFC 8620 §5.3 maxObjectsInSet cap at the top of a /set
handler (bd:JMAP-ayoz.41.1).
Counts entries in the wire create (object), update (object), and
destroy (array) arguments. Returns the method-level error
JmapError::request_too_large (wire type: "requestTooLarge",
description: "maxObjectsInSet") when the sum exceeds max. Per
RFC 8620 §5.3 it is returned instead of the Foo/set response, so
the dispatcher emits an error invocation and later method calls
in the same request still run (bd:JMAP-yt1w.30).
Call at the top of every handle_*_set after the account_exists
gate and before any per-entry processing. A request carrying
megabytes of /set ops is rejected before the handler touches the
storage layer:
let (account_id, args) = extract_account_id(args)?;
if !backend.account_exists(caller, &account_id).await
.map_err(|e| server_fail_from_backend(&e))?
{
return Err(JmapError::account_not_found());
}
jmap_server::helpers::enforce_max_objects_in_set(
&args,
backend.max_objects_in_set(caller, &account_id),
)?;§Why this lives in the foundation
maxObjectsInSet is a RFC 8620 §5.3 base-protocol cap, not an
extension concept. Every jmap-*-server extension’s handle_*_set
needs the same check; the helper is the single source of truth so a
future revision (different error shape, additional counting rule,
alternate semantics for non-object create / update) lands in one
place instead of being propagated through 28 handler sites.
§Counting rules
createis counted asargs["create"].as_object()?.len()— missing key,null, or non-object types count as 0.updateis counted the same way (RFC 8620 §5.3updateisId[PatchObject]).destroyis counted asargs["destroy"].as_array()?.len()— missing key,null, or non-array types count as 0.
Wire-shape validation of the individual create / update /
destroy arguments belongs to the per-handler argument parsing,
not to this cap-enforcement helper. A non-object create survives
the cap check (counts as 0) and is rejected by the handler’s
downstream args.remove("create") match arm. Conversely, a
well-formed but over-limit create is rejected here before the
handler runs.
§Errors
Returns JmapError::request_too_large() with description
"maxObjectsInSet" when the sum exceeds max (RFC 8620 §5.3).