ds_common_placeholder_py_lib.validate ===================================== .. py:module:: ds_common_placeholder_py_lib.validate .. autoapi-nested-parse:: **File:** ``validate.py`` **Region:** ``ds-common-placeholder-py-lib`` Description ----------- Static checks without runtime data (contract §3, §4, §5). Attributes ---------- .. autoapisummary:: ds_common_placeholder_py_lib.validate.PROTECTED Functions --------- .. autoapisummary:: ds_common_placeholder_py_lib.validate.validate Module Contents --------------- .. py:data:: PROTECTED read by the engine before anything is resolved, so a placeholder there would stay as text. Only outside a ``settings`` key: under one, whatever its value, these are ordinary keys. :type: The keys :func:`validate` protects by default .. py:function:: validate(value: Any, *, verbatim: ds_common_placeholder_py_lib.resolve.Paths = (), sql: ds_common_placeholder_py_lib.resolve.Paths = (), protected: collections.abc.Collection[str] = PROTECTED, functions: collections.abc.Mapping[str, collections.abc.Callable[..., Any]] | collections.abc.Collection[str] = ()) -> list[ds_common_placeholder_py_lib.errors.PlaceholderError] Check every placeholder in a JSON value: syntax, known functions, argument counts, and literal arguments (contract §3, §5). Namespaces are not checked: which ones exist depends on the context a service builds. Call it only on ``standard`` definitions: ``legacy`` ones are not valid ``standard``. Whether a definition is ``standard`` is the service's call (``settings.placeholder_dialect``, or always for pipelines). Pass the whole definition, in one call: the protected keys (by default ``id``, ``name``, ``type``, and ``version``) outside a ``settings`` key must not contain ``@{`` at all (``protected_field``), and only the whole definition shows which keys those are. Everything that depends on runtime data (missing values, secrets, SQL literal positions) is checked when it is resolved. :param value: Any JSON value. :param verbatim: Paths to values taken as written, such as a script's code: not parsed, so ``@{`` there is text. Each is a dotted string written like a reference, ``tasks.0.settings.'a.b'``, or a list of keys, ``["tasks", 0, "settings", "a.b"]`` (use that for keys that come from data), from the root of *value*. A path that is not in *value* is ignored, so a wrong path means the value is parsed as usual. Protected fields are still checked inside them. :param sql: Paths to SQL text, as for a context's ``sql``: written like *verbatim*. The text must be a string, a placeholder in it must stand where a SQL literal can (``sql_position``), and none may call ``get_secret`` or ``secret`` (``sql_secret``). :param protected: The protected keys, :data:`PROTECTED` by default. Extend it (``PROTECTED | {"slug"}``) or replace it; ``()`` turns the check off, for definitions without such keys. Every validator of the same definitions must use the same keys. :param functions: A service's own functions, as given to its :class:`~ds_common_placeholder_py_lib.context.Context`: their argument counts are checked too. Or just their names, where the functions are not at hand: then any argument count passes. :returns: Every error found, in document order. Empty if the value is valid. :raises TypeError: If *verbatim* is a single string or holds something that is not a path, or *protected* is not a collection of strings (``None``, a single string, or an iterator are refused). :raises ValueError: If a *verbatim* path is not a path, *protected* includes ``settings``, or a function name is not one or is a built-in one.