check_document_rules), full-document validation
against an effective schema, and the conservative narrowing comparison two schemas are
compared with. RecordValidator is the public face over these validators for a caller
with no store bound. Depends only on the standard library, jsonschema/referencing, the
kit’s JSON Schema rules and the contract’s states models.
RecordValidator
tai42_skeleton.states.schema.RecordValidator
validate per document. The schema is
checked once at construction by the same rules a declaration is (object-rooted, at least
one property, and check_document_rules), and refused loudly with
SchemaValidationError; the compiled validator is
then reused for every document. A by-id schema is resolved by the caller first.
Members
validate
tai42_skeleton.states.schema.RecordValidator.validate
data misfits the schema, ordered by JSON path; fits when there is none.
A non-object data raises ValueValidationError.
Parameters
check_document_rules
tai42_skeleton.states.schema.check_document_rules
check_schema_rules with
Draft202012Validator): the meta-schema, compiling pattern and
patternProperties regexes, finite numbers, one resource (no root $id naming a
meta-schema, no $id below the root, unique anchor names, and, under a root $id, no
$dynamicAnchor below the root whose name the meta-schema subschema a reference reaches binds
dynamically or the reference names), every reference
resolving inside the schema or into a meta-schema (none is fetched), every pointer indexing an
array with an RFC 6901 index, and no cycle of references that never descends into the
document. On top of them, a
states document is one draft 2020-12 dialect without dynamic references: a $schema naming
another dialect, or a $dynamicRef, anywhere among the subschemas validation evaluates
(evaluated_subschemas: under every applicator
and at every reference target, whatever form the reference takes) is refused. subject
opens the message ("state schema", a template’s value-schema place). Every refusal raises
SchemaValidationError.
Parameters
iter_refs
tai42_skeleton.states.schema.iter_refs
$ref string of every node of the schema document’s schema_nodes.
Parameters
schema_nodes
tai42_skeleton.states.schema.schema_nodes
root’s subschemas and every node a #/… pointer ref among them reaches, each once.
root’s subschemas (_subschemas), closed over the target of every #/… pointer
ref among them (an absolute ref is not followed): jsonschema evaluates a pointer’s target as a
schema wherever it sits (under an unknown or a data keyword too) and follows the refs inside
it, so the target’s subschemas join the set, to a fixpoint (a node already in the set is not
walked again, so cyclic refs end). Each pointer is resolved against root; one that does
not resolve raises SchemaValidationError. A target outside the subschema positions —
which root’s own check_schema does not cover — is checked once as a draft 2020-12
schema, so the walk stays linear in the schema’s size and its ref count.
Parameters
Composing attached fragments into the effective schema.
Each attachment’s substituted (and, when the template traces,
_trace-stamped) fragment
is placed into a base schema at its path, refusing collisions and overlapping attach paths.
A fragment placed at a path has its # and #/… references rebased to that path, so
they keep resolving against the fragment; a fragment attached at the root merges its
properties, required and $defs into the root and may carry no other validating
root keyword, nor a pointer reference outside its properties and $defs. The
composed schema is checked by the declaration rules before it is returned.
compose_effective_schema
tai42_skeleton.states.templates.compose.compose_effective_schema
(template, path, parameters): the template’s fragment is
substituted with defaults overlaid by parameters (an unsupplied no-default
marker is a loud refusal), _trace-stamped when the template traces, and placed at
path — creating intermediate {"type": "object", "properties": {}} levels. At a
non-empty path every # / #/… $ref in the fragment is rebased to the placement
pointer (#/properties/<seg>/…), so it resolves inside the fragment as it did alone;
#anchor refs are left as they are. At the root path the fragment’s root type must
be object; its properties, required and $defs are merged into the base
root, its annotation keywords are dropped, and any other root keyword is refused, as is a
# / #/… ref outside the fragment’s properties and $defs. An attachment
path that collides with an existing base property, a root $defs key that collides with
the base’s, a root type, keyword or ref that cannot be merged, or an attach path
overlapping another attachment’s path, is refused with
AttachConflictError. A fragment its parameters leave
malformed is refused with SchemaValidationError
naming the template. The composed schema satisfies the declaration rules (object-rooted, at
least one property, a valid draft 2020-12 schema, no $schema naming another dialect, every
$ref local and resolvable, no $dynamicRef, no root $id naming a meta-schema, no
$id below the root, unique $anchor / $dynamicAnchor names, under a root $id no
$dynamicAnchor below the root whose name the meta-schema subschema a reference reaches binds
dynamically or the reference names, every pointer’s array index an RFC 6901 index, no cycle of
references that never descends into the document), raising
SchemaValidationError otherwise.
Parameters
The platform state-template document parser and validator.
Parses a raw JSON document into a
StateTemplate:
the document’s shape (every section, the name law, no key outside the platform set) is the
contract’s StateTemplateDocument; this module adds the
rules that span sections or need jq — parameter markers against declared parameters, the
fragment as an object schema, each parameter and declarations schema as a schema whose
references resolve inside it, regime and program paths inside the fragment, program names and
params as jq identifiers, and every inline jq body compiling. A consumer keeps its own documents
beside the template under its own kind (validated through its registered attach validator).
DECLARATIONS_CHECK_VARIABLES
tai42_skeleton.states.templates.validate.DECLARATIONS_CHECK_VARIABLES
RECONCILE_JQ_VARIABLES
tai42_skeleton.states.templates.validate.RECONCILE_JQ_VARIABLES
validate_template
tai42_skeleton.states.templates.validate.validate_template
StateTemplate.
The document must carry kind == "state-template" and a dict fragment schema (a by-id
fragment is resolved by the caller first) and parse as a
StateTemplateDocument; then a no-default parameter
must appear as a marker and every marker names a declared parameter, each parameter and
declarations schema is a valid schema whose references resolve inside it, the defaults-substituted
fragment passes _validate_schema, regime and update-program paths lie inside the fragment
("*" only over items/additionalProperties), program names and params are jq
identifiers, and every inline jq body compiles (a by-id body is rendered and compiled at the
save door). Raises TemplateValidationError on the first
violation.
Parameters

