Skip to content

cgtype

cgtype #

The root of every CaptureGraph type.

A CGType is the Python handle for a captured value's type, and it is type-first: the class is the source of truth. A type knows how to

  • read and write its values on disk — load(base) / store(base, value), where base is a path without the type's own suffix (each type appends its .json / .heic / folder), and
  • describe its own structure as wire JSON — schema() — from which a type can be rebuilt (from_schema, in serialize).

Composite types implement these by recursing into their children; scalars are the end of the road. There is no second, parallel decoder: the type system is the reader. The extension point that keeps the scalar set open — the wire-name registry, and the is_keyable / is_storable predicates over these types — lives in core.registry.

CGType #

Base of every CaptureGraph type. The class is the type; instances are values.

Source code in capturegraph-lib/capturegraph/types/cgtype.py
class CGType:
    """Base of every CaptureGraph type. The class is the type; instances are values."""

    __slots__ = ()

    # ``storable``: has a place on disk — false only for ``Path``/``Void``, which
    # are addresses and side effects, never stored composite children. (Keyability
    # is carried by the ``Keyable`` mixin, not a base flag, so the mixin's value
    # is not shadowed by ``CGType`` sitting earlier in a scalar's MRO.)
    storable: ClassVar[bool] = True

    @classmethod
    def schema(cls) -> dict[str, JSONValue]:
        """This type's structural wire form (the schema of its values)."""
        raise NotImplementedError(f"{cls.__name__} has no wire form")

    @classmethod
    def load(cls, base: Path) -> object:
        """Read the value rooted at ``base`` from disk."""
        raise NotImplementedError(f"{cls.__name__} cannot load")

    @classmethod
    def store(cls, base: Path, value: object) -> None:
        """Write ``value`` rooted at ``base`` to disk."""
        raise NotImplementedError(f"{cls.__name__} cannot store")

load(base) classmethod #

Read the value rooted at base from disk.

Source code in capturegraph-lib/capturegraph/types/cgtype.py
@classmethod
def load(cls, base: Path) -> object:
    """Read the value rooted at ``base`` from disk."""
    raise NotImplementedError(f"{cls.__name__} cannot load")

schema() classmethod #

This type's structural wire form (the schema of its values).

Source code in capturegraph-lib/capturegraph/types/cgtype.py
@classmethod
def schema(cls) -> dict[str, JSONValue]:
    """This type's structural wire form (the schema of its values)."""
    raise NotImplementedError(f"{cls.__name__} has no wire form")

store(base, value) classmethod #

Write value rooted at base to disk.

Source code in capturegraph-lib/capturegraph/types/cgtype.py
@classmethod
def store(cls, base: Path, value: object) -> None:
    """Write ``value`` rooted at ``base`` to disk."""
    raise NotImplementedError(f"{cls.__name__} cannot store")