loom.core.command

class loom.core.command.Command[source]

Bases: Struct

Base for all command structs.

class loom.core.command.CommandAdapter(*args, **kwargs)[source]

Bases: Protocol[RawT]

Contract for compiling a Command into a transport-specific schema and parsing raw input into a Command instance.

Implementations translate the Command (single source of truth) into validation schemas for specific transports (Pydantic, Avro, msgspec, etc.).

Parameters:

RawT – The raw input type the adapter accepts (e.g. dict, bytes).

compile_schema(command_cls)[source]

Compile a Command class into a transport-specific validation schema.

Parameters:

command_cls (type) – The Command subclass to compile.

Returns:

A transport-specific schema type derived from the Command.

Return type:

type

parse(command_cls, raw)[source]

Parse raw input into a Command instance with field tracking.

Parameters:
  • command_cls (type) – The Command subclass to instantiate.

  • raw (RawT) – The raw input data.

Returns:

A tuple of (command_instance, fields_set) where fields_set contains the names of fields present in the raw input.

Return type:

tuple[Any, frozenset[str]]

class loom.core.command.CommandField(calculated=False, internal=False, patch=False, default=UNSET)[source]

Bases: object

Metadata descriptor for command fields.

Parameters:
  • calculated (bool) – Field is computed by the engine, not user-supplied.

  • internal (bool) – Field is set by infrastructure, not user-supplied.

  • patch (bool) – Field supports patch semantics (missing vs explicit null/value).

  • default (Any) – Optional field default.

loom.core.command.get_calculated_fields(cls)[source]

Return CommandField descriptors marked as calculated.

Parameters:

cls (type) – A Command subclass.

Returns:

Mapping of field name to CommandField metadata.

Return type:

dict[str, CommandField]

loom.core.command.get_command_fields(cls)[source]

Return all CommandField descriptors declared on a command class.

Parameters:

cls (type) – A Command subclass.

Returns:

Mapping of field name to CommandField metadata.

Return type:

dict[str, CommandField]

loom.core.command.get_input_fields(cls)[source]

Return CommandField descriptors that are user-supplied.

Excludes fields marked as internal or calculated.

Parameters:

cls (type) – A Command subclass.

Returns:

Mapping of field name to CommandField metadata.

Return type:

dict[str, CommandField]

loom.core.command.get_internal_fields(cls)[source]

Return CommandField descriptors marked as internal.

Parameters:

cls (type) – A Command subclass.

Returns:

Mapping of field name to CommandField metadata.

Return type:

dict[str, CommandField]

loom.core.command.get_patch_fields(cls)[source]

Return CommandField descriptors marked as patch.

Parameters:

cls (type)

Return type:

dict[str, CommandField]

loom.core.command.is_patch_command(cls)[source]

Return whether the command class is a patch command.

Parameters:

cls (type) – A Command subclass.

Returns:

True when at least one command field is marked as patch.

Return type:

bool