Canonical specification¶
The canonical specification is the stable JSON boundary for Hakowan figures. See the schema guide for format semantics, resolver rules, versioning, and complete examples.
Public functions¶
Convert a runtime Layer or Figure into a canonical specification.
Source code in hakowan/spec/codec.py
Build a runtime Layer or Figure from a canonical specification.
Source code in hakowan/spec/codec.py
Parse canonical JSON and build a runtime layer tree.
Source code in hakowan/spec/codec.py
Load a specification and resolve relative resources beside its file.
Source code in hakowan/spec/codec.py
Return the documented canonical Hakowan JSON Schema.
Source code in hakowan/spec/model.py
Atomically patch a runtime Layer or Figure through its canonical form.
In-memory meshes and callable references are rebound automatically. Explicit identifier and resolver hooks support references introduced by a patch. Schema validation always runs; semantic validation runs by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Layer | Figure
|
Runtime Layer or Figure to patch without mutation. |
required |
operations
|
Iterable[PatchOperation | Mapping[str, Any]]
|
Ordered add, remove, or replace operations. |
required |
data_ids
|
DataIds | None
|
Optional stable IDs for existing in-memory meshes. |
None
|
function_ids
|
FunctionIds | None
|
Optional stable IDs for existing callables. |
None
|
data_resolver
|
DataResolver | None
|
Resolver for new external data IDs. |
None
|
function_resolver
|
FunctionResolver | None
|
Resolver for new external function IDs. |
None
|
base_dir
|
str | Path | None
|
Base directory for relative resource paths. |
None
|
backend
|
BackendName | None
|
Backend used by semantic validation. |
None
|
strict
|
bool
|
Promote backend degradations to semantic errors. |
False
|
semantic
|
bool
|
Run semantic and compile validation when true. |
True
|
Returns:
| Type | Description |
|---|---|
Layer | Figure
|
A reconstructed Layer or Figure containing all patch operations. |
Raises:
| Type | Description |
|---|---|
PatchError
|
If conversion, an operation, schema validation, or semantic validation fails. |
Source code in hakowan/spec/patch.py
Apply atomic JSON Pointer operations and validate the resulting schema.
Supported operations are add, remove, and replace. All
operations run against a private deep copy; failure leaves spec and
supplied values unchanged. - appends to an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
FigureSpec | Mapping[str, Any]
|
Immutable FigureSpec or a canonical specification mapping. |
required |
operations
|
Iterable[PatchOperation | Mapping[str, Any]]
|
Ordered patch operations using RFC 6901 pointer paths. |
required |
Returns:
| Type | Description |
|---|---|
FigureSpec
|
A newly validated immutable FigureSpec. |
Raises:
| Type | Description |
|---|---|
PatchError
|
If an operation or final schema is invalid. |
Source code in hakowan/spec/patch.py
Root model¶
Bases: SpecModel
Canonical versioned Hakowan visualization specification.
Source code in hakowan/spec/model.py
to_dict()
¶
Return the complete JSON-safe document, including defaults and nulls.
to_json(*, indent=2, canonical=False)
¶
Serialize with sorted keys and optional canonical compact formatting.
Source code in hakowan/spec/model.py
save(path, *, indent=2)
¶
Write the specification as UTF-8 JSON followed by a newline.
from_json(text)
classmethod
¶
load(path)
classmethod
¶
Boundary errors¶
Bases: ValueError
Raised when a patch operation, schema, or semantic check fails.
Source code in hakowan/spec/patch.py
__init__(failure, *, validation_report=None)
¶
Initialize an error with its structured failure and validation report.
Source code in hakowan/spec/patch.py
Machine-readable cause of a rejected atomic patch.
Source code in hakowan/spec/patch.py
to_dict()
¶
Return this failure as a JSON-safe mapping.
Expression compiler¶
Compile a safe one-argument expression into a callable.
Available names are value and vector aliases x, y, z.
Allowed functions are abs, min, max, isfinite, and norm.