Skip to content

Lens

pyvider.components.capabilities.lens

TODO: Add module docstring.

Classes

LensCapability

LensCapability(config: Any | None = None)

Bases: BaseCapability

Provides schema and services for enabling and configuring lens (jq) components.

Source code in pyvider/components/capabilities/lens.py
def __init__(self, config: Any | None = None) -> None:
    super().__init__(config)
    self._config = config
Functions
jq
jq(query: str, input_data: Any) -> CtyValue

Executes a JQ query and converts the raw Python result to a CtyValue.

Source code in pyvider/components/capabilities/lens.py
def jq(self, query: str, input_data: Any) -> CtyValue:
    """
    Executes a JQ query and converts the raw Python result to a CtyValue.
    """

    try:
        # THE FIX: Use the correct `compile(...).transform(...)` API.
        compiled_query = jq.compile(query)
        final_raw_result = compiled_query.transform(input_data)

        inferred_type = infer_cty_type_from_raw(final_raw_result)
        return inferred_type.validate(final_raw_result)
    except Exception as e:
        logger.error(
            "jq query execution failed",
            error=str(e),
            exc_info=True,
        )
        raise FunctionError(f"jq query failed: {e}") from e

Functions