ds_common_placeholder_py_lib.validate¶
File: validate.py
Region: ds-common-placeholder-py-lib
Description¶
Static checks without runtime data (contract §3, §4, §5).
Attributes¶
read by the engine before |
Functions¶
|
Check every placeholder in a JSON value: syntax, known functions, |
Module Contents¶
- ds_common_placeholder_py_lib.validate.PROTECTED¶
read by the engine before anything is resolved, so a placeholder there would stay as text. Only outside a
settingskey: under one, whatever its value, these are ordinary keys.- Type:
The keys
validate()protects by default
- ds_common_placeholder_py_lib.validate.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][source]¶
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
standarddefinitions:legacyones are not validstandard. Whether a definition isstandardis 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, andversion) outside asettingskey 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.- Parameters:
value – Any JSON value.
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.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 callget_secretorsecret(sql_secret).protected – The protected keys,
PROTECTEDby 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.functions – A service’s own functions, as given to its
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).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.