Source code for fsh_lib.filter_values
"""Body schema for the project-wide value-provider endpoint.
Carries the autocomplete query and an optional limit. The
endpoint is intentionally single-page (no cursor): autocomplete
UX narrows by typing more characters, not by paginating.
"""
from pydantic import BaseModel
_DEFAULT_LIMIT = 50
_MAX_LIMIT = 200
[docs]
class FilterValuesRequest(BaseModel):
"""Common search params used by every value-provider runner."""
search: str | None = None
limit: int | None = None
ids: dict[str, tuple[str, ...]] | None = None
"""Resolve mode: a map of field name -> the values to resolve for
that field. Returns ``{field, value, label}`` rows for exactly
those ``(field, value)`` pairs -- a label lookup for an
already-selected filter value (a default / restored filter arrives
as an id whose label only lives in the BE). Each field is matched
against only its own ids, so the keys carry the field<->id
association the flat list couldn't. Takes precedence over
``search``; an empty / absent map falls back to search / browse.
"""
[docs]
def resolved_limit(req_limit: int | None) -> int:
"""Clamp *req_limit* to ``[1, _MAX_LIMIT]`` with a sensible default."""
if req_limit is None:
return _DEFAULT_LIMIT
return max(1, min(req_limit, _MAX_LIMIT))