animedex.render.field_projection

--json field1,field2 field projection.

The CLI’s --json field1,field2 flag (plans/03 §9) is a post-processor over the JSON renderer’s output: it keeps only the named top-level fields. Unknown fields raise a typed ApiError so a typo at the call site is loud, not silent.

parse_field_string

animedex.render.field_projection.parse_field_string(spec: str) List[str][source]

Split a comma-separated field spec into a list of field names.

Strips whitespace, drops empty entries.

Parameters:

spec (str) – Comma-separated field spec (e.g. "id, title, episodes").

Returns:

List of field names; empty list when spec is empty.

Return type:

list of str

project_fields

animedex.render.field_projection.project_fields(payload: Dict[str, Any], fields: List[str]) Dict[str, Any][source]

Return a dict containing only fields keys from payload.

An empty fields list returns payload unchanged. An unknown field raises ApiError with reason="unknown-field" naming the offending field.

Parameters:
  • payload (dict) – A dict-shaped JSON-decoded payload.

  • fields (list of str) – Top-level field names to keep.

Returns:

The projected dict.

Return type:

dict

Raises:

ApiError – When fields names a key not present in payload.

selftest

animedex.render.field_projection.selftest() bool[source]

Smoke-test field projection.

Returns:

True on success.

Return type:

bool