haive.core.schema.compatibility.protocolsΒΆ

from typing import Any. Protocol definitions for extending the schema compatibility system.

ClassesΒΆ

AsyncConverter

Protocol for async converters.

CompatibilityPlugin

Protocol for compatibility checker plugins.

ConversionStrategy

Protocol for conversion strategies.

ExampleFieldResolver

Example field resolver using similarity matching.

ExampleTypeInspector

Example type inspector for custom types.

FieldResolver

Protocol for resolving field mappings.

FieldTransformer

Protocol for field transformation functions.

PluginManager

Manages plugins for the compatibility system.

SchemaConvertible

Protocol for objects that can be converted to/from schemas.

SchemaEvolution

Protocol for schema evolution/migration.

SchemaRegistry

Protocol for schema registries.

SchemaValidator

Protocol for schema validators.

TypeInspector

Protocol for custom type inspection.

FunctionsΒΆ

compatibility_plugin([priority])

Decorator to register a compatibility plugin.

converter_plugin(cls)

Decorator to register a converter plugin.

validator_plugin(cls)

Decorator to register a validator plugin.

Module ContentsΒΆ

class haive.core.schema.compatibility.protocols.AsyncConverter[source]ΒΆ

Bases: Protocol

Protocol for async converters.

async aconvert(value, context)[source]ΒΆ

Async conversion.

Parameters:
Return type:

Any

property supports_sync: boolΒΆ

Whether sync conversion is also supported.

Return type:

bool

class haive.core.schema.compatibility.protocols.CompatibilityPlugin[source]ΒΆ

Bases: Protocol

Protocol for compatibility checker plugins.

check_compatibility(source_type, target_type)[source]ΒΆ

Check compatibility between types.

Parameters:
Return type:

haive.core.schema.compatibility.types.CompatibilityLevel | None

enhance_report(report, source, target)[source]ΒΆ

Enhance compatibility report with additional info.

Parameters:
Return type:

None

property name: strΒΆ

Plugin name.

Return type:

str

property priority: intΒΆ

Plugin priority (higher = runs first).

Return type:

int

class haive.core.schema.compatibility.protocols.ConversionStrategy[source]ΒΆ

Bases: Protocol

Protocol for conversion strategies.

can_convert(source, target)[source]ΒΆ

Check if strategy can handle conversion.

Parameters:
Return type:

bool

convert(value, source_type, target_type, context)[source]ΒΆ

Perform conversion.

Parameters:
Return type:

Any

property name: strΒΆ

Strategy name.

Return type:

str

class haive.core.schema.compatibility.protocols.ExampleFieldResolver[source]ΒΆ

Example field resolver using similarity matching.

resolve_field(source_fields, target_field)[source]ΒΆ

Resolve by name similarity.

Parameters:
Return type:

str | None

suggest_mapping(source_schema, target_schema)[source]ΒΆ

Suggest mappings for all fields.

Parameters:
Return type:

dict[str, str]

class haive.core.schema.compatibility.protocols.ExampleTypeInspector[source]ΒΆ

Example type inspector for custom types.

can_inspect(type_hint)[source]ΒΆ

Check if type has custom metadata.

Parameters:

type_hint (type)

Return type:

bool

extract_constraints(type_hint)[source]ΒΆ

Extract validation constraints.

Parameters:

type_hint (type)

Return type:

dict[str, Any]

inspect(type_hint)[source]ΒΆ

Extract custom metadata.

Parameters:

type_hint (type)

Return type:

dict[str, Any]

class haive.core.schema.compatibility.protocols.FieldResolver[source]ΒΆ

Bases: Protocol

Protocol for resolving field mappings.

resolve_field(source_fields, target_field)[source]ΒΆ

Resolve source field for a target field.

Parameters:
Return type:

str | None

suggest_mapping(source_schema, target_schema)[source]ΒΆ

Suggest field mappings.

Parameters:
Return type:

dict[str, str]

class haive.core.schema.compatibility.protocols.FieldTransformer[source]ΒΆ

Bases: Protocol

Protocol for field transformation functions.

class haive.core.schema.compatibility.protocols.PluginManager[source]ΒΆ

Manages plugins for the compatibility system.

Init .

Returns:

Add return description]

Return type:

[TODO

get_compatibility_plugins()[source]ΒΆ

Get all registered compatibility plugins.

Return type:

list[CompatibilityPlugin]

get_converters()[source]ΒΆ

Get all registered converters.

Return type:

list[ConversionStrategy]

get_inspectors()[source]ΒΆ

Get all registered inspectors.

Return type:

list[TypeInspector]

get_resolvers()[source]ΒΆ

Get all registered resolvers.

Return type:

list[FieldResolver]

get_validators()[source]ΒΆ

Get all registered validators.

Return type:

list[SchemaValidator]

register_compatibility_plugin(plugin)[source]ΒΆ

Register a compatibility plugin.

Parameters:

plugin (CompatibilityPlugin)

Return type:

None

register_converter(converter)[source]ΒΆ

Register a conversion strategy.

Parameters:

converter (ConversionStrategy)

Return type:

None

register_inspector(inspector)[source]ΒΆ

Register a type inspector.

Parameters:

inspector (TypeInspector)

Return type:

None

register_resolver(resolver)[source]ΒΆ

Register a field resolver.

Parameters:

resolver (FieldResolver)

Return type:

None

register_validator(validator)[source]ΒΆ

Register a schema validator.

Parameters:

validator (SchemaValidator)

Return type:

None

class haive.core.schema.compatibility.protocols.SchemaConvertible[source]ΒΆ

Bases: Protocol

Protocol for objects that can be converted to/from schemas.

classmethod from_schema(schema)[source]ΒΆ

Create instance from a Pydantic schema.

Parameters:

schema (type[pydantic.BaseModel])

Return type:

T

to_schema()[source]ΒΆ

Convert to a Pydantic schema.

Return type:

type[pydantic.BaseModel]

class haive.core.schema.compatibility.protocols.SchemaEvolution[source]ΒΆ

Bases: Protocol

Protocol for schema evolution/migration.

can_migrate(from_version, to_version)[source]ΒΆ

Check if migration is possible.

Parameters:
  • from_version (str)

  • to_version (str)

Return type:

bool

migrate(data, from_version, to_version)[source]ΒΆ

Migrate data between schema versions.

Parameters:
Return type:

dict[str, Any]

property version: strΒΆ

Schema version.

Return type:

str

class haive.core.schema.compatibility.protocols.SchemaRegistry[source]ΒΆ

Bases: Protocol

Protocol for schema registries.

find_compatible(target, min_score=0.7)[source]ΒΆ

Find compatible schemas with scores.

Parameters:
  • target (type[pydantic.BaseModel])

  • min_score (float)

Return type:

list[tuple[str, float]]

get(name)[source]ΒΆ

Get a schema by name.

Parameters:

name (str)

Return type:

type[pydantic.BaseModel] | None

list_schemas()[source]ΒΆ

List all registered schema names.

Return type:

list[str]

register(name, schema)[source]ΒΆ

Register a schema.

Parameters:
  • name (str)

  • schema (type[pydantic.BaseModel])

Return type:

None

class haive.core.schema.compatibility.protocols.SchemaValidator[source]ΒΆ

Bases: Protocol

Protocol for schema validators.

validate_compatibility(source, target)[source]ΒΆ

Validate compatibility between schemas.

Parameters:
Return type:

list[str]

validate_schema(schema)[source]ΒΆ

Validate a schema and return list of issues.

Parameters:

schema (haive.core.schema.compatibility.types.SchemaInfo)

Return type:

list[str]

class haive.core.schema.compatibility.protocols.TypeInspector[source]ΒΆ

Bases: Protocol

Protocol for custom type inspection.

can_inspect(type_hint)[source]ΒΆ

Check if this inspector can handle the type.

Parameters:

type_hint (type)

Return type:

bool

extract_constraints(type_hint)[source]ΒΆ

Extract validation constraints from type.

Parameters:

type_hint (type)

Return type:

dict[str, Any]

inspect(type_hint)[source]ΒΆ

Inspect the type and return metadata.

Parameters:

type_hint (type)

Return type:

dict[str, Any]

haive.core.schema.compatibility.protocols.compatibility_plugin(priority=0)[source]ΒΆ

Decorator to register a compatibility plugin.

Parameters:

priority (int)

haive.core.schema.compatibility.protocols.converter_plugin(cls)[source]ΒΆ

Decorator to register a converter plugin.

Return type:

Any

haive.core.schema.compatibility.protocols.validator_plugin(cls)[source]ΒΆ

Decorator to register a validator plugin.

Return type:

Any