Models / Mapping
AttributeMapping
- class teksi_hooks.models.mapping.AttributeMapping(canonical_class_id, canonical_attr_id, foreign_key=None, values=<factory>, value_list=None)[source]
Map one source-model attribute to one canonical target attribute.
Declarative attribute mappings intentionally support one canonical target. A source attribute requiring multiple canonical effects must use a function mapping instead.
- Parameters:
canonical_class_id (str)
canonical_attr_id (str)
foreign_key (ForeignKeyMapping | None)
values (Mapping[str, ValueMapping])
value_list (ValueListMapping | None)
Fields
canonical_class_idType:
strCanonical class identifier containing the target attribute.
canonical_attr_idType:
strCanonical attribute identifier receiving the mapped source value.
foreign_keyType:
ForeignKeyMapping | NoneOptional reference metadata used when the canonical target attribute stores a foreign-key reference.
valuesType:
Mapping[str, ValueMapping]Optional static value mappings keyed by source-model value.
value_listType:
ValueListMapping | NoneOptional database-backed value-list translation. The source value is matched using the configured mapping attribute and translated to the configured canonical value attribute.
ClassMapping
- class teksi_hooks.models.mapping.ClassMapping(canonical_class_id=None, identity=None, identities=<factory>, attributes=<factory>, relations=<factory>, localisations=<factory>, function=None)[source]
Map one source-model class to the canonical internal model.
A class may use either a class-level function mapping or declarative attribute mappings. Function-backed mappings return a complete JSONB effect document.
- Parameters:
canonical_class_id (str | None)
identity (CanonicalIdentityMapping | None)
identities (Mapping[str, CanonicalIdentityMapping | None])
attributes (Mapping[str, AttributeMapping])
relations (Mapping[str, RelationMapping])
localisations (Mapping[str, str])
function (FunctionMapping | None)
- property is_function_backed: bool
Return whether the class uses a database projection function.
- property is_attribute_backed: bool
Return whether the class declares attribute mappings.
Fields
canonical_class_idType:
str | NoneOptional primary canonical class identifier represented by the source class. This may be omitted for function-backed or extension-only mappings.
identityType:
CanonicalIdentityMapping | NoneOptional primary identity override for the class. Missing source or canonical identity attributes are inherited from the model defaults during mapping resolution.
identitiesType:
Mapping[str, CanonicalIdentityMapping | None]Identity mappings keyed by canonical target class. A null mapping declares the target class while inheriting the complete model-default identity. A partial mapping may override the canonical or source identity attribute.
attributesType:
Mapping[str, AttributeMapping]Declarative attribute mappings keyed by source runtime attribute identifier. For ili2pg imports this is the actual SQLAlchemy or ili2pg column name, which may differ from the original INTERLIS attribute name.
relationsType:
Mapping[str, RelationMapping]Class-specific canonical relation mappings keyed by stable canonical relation identifier. These mappings override model-default relations with the same identifier.
localisationsType:
Mapping[str, str]Exact source-model class identifiers keyed by source language. Values are executable model identifiers rather than translated display labels.
functionType:
FunctionMapping | NoneOptional database-backed class projection function. The function receives configured source-row values and returns the complete canonical JSONB effect document.
ForeignKeyMapping
- class teksi_hooks.models.mapping.ForeignKeyMapping(referenced_class_id, referenced_attribute_id='obj_id')[source]
Describe the canonical object referenced by a mapped attribute.
This is used when the mapped canonical attribute stores a reference rather than a literal value.
- Parameters:
referenced_class_id (str)
referenced_attribute_id (str)
Fields
referenced_class_idType:
strCanonical identifier of the referenced class. Corresponds to a class or table in the internal semantic model.
referenced_attribute_idType:
strCanonical identifier of the referenced attribute. Defaults to the canonical object identifier obj_id.
FunctionMapping
- class teksi_hooks.models.mapping.FunctionMapping(schema, name, parameters=<factory>)[source]
Describe a database-backed mapping function.
Function mappings handle source classes whose canonical effects cannot be represented by one-to-one attribute mappings.
The configured function receives values from the source row and returns a complete canonical JSONB effect document. The result is authoritative and must not be supplemented with declarative attribute mappings.
- Parameters:
schema (str)
name (str)
parameters (Mapping[str, str])
Fields
schemaType:
strDatabase schema containing the mapping function. Example: tww_app.
nameType:
strDatabase function name implementing the mapping. Example: fct_agxx_gepknoten_mapping_jsonb.
parametersType:
Mapping[str, str]Function parameter mappings keyed by database function parameter name. Values identify source-row expressions or source-model attributes. The special value $row passes the complete source row.
MappingDefaults
- class teksi_hooks.models.mapping.MappingDefaults(identity=<factory>, identities=<factory>, attributes=<factory>, relations=<factory>, inherit_from=None)[source]
Define mappings inherited by classes in one source model.
- Parameters:
identity (CanonicalIdentityMapping)
identities (Mapping[str, CanonicalIdentityMapping])
attributes (Mapping[str, AttributeMapping])
relations (Mapping[str, RelationMapping])
inherit_from (str | None)
Fields
identityType:
CanonicalIdentityMappingDefault source-to-canonical identity mapping. Class-level target identities may override either attribute.
identitiesType:
Mapping[str, CanonicalIdentityMapping]Default identity mappings keyed by canonical target class. An identity describes how effects address a target row and does not independently require that row to exist.
attributesType:
Mapping[str, AttributeMapping]Default attribute mappings keyed by source-model runtime attribute identifier. A default mapping applies to a class only when that source class defines the source attribute.
relationsType:
Mapping[str, RelationMapping]Default canonical relation mappings keyed by stable canonical relation identifier.
inherit_fromType:
str | NoneOptional source-model mapping identifier inherited by this model. Inherited defaults are resolved before local overrides. Mapping inheritance must be acyclic.
ModelMapping
- class teksi_hooks.models.mapping.ModelMapping(defaults=<factory>, classes=<factory>, is_ssot=False, languages=<factory>)[source]
Describe how one source model maps to the canonical internal model.
Source class, attribute and relation identifiers are scoped to this model and may be localized. Canonical class, attribute, relation and value identifiers remain independent of the source-model language.
- Parameters:
defaults (MappingDefaults)
classes (Mapping[str, ClassMapping])
is_ssot (bool)
languages (frozenset[str])
Fields
defaultsType:
MappingDefaultsDefault identities, attributes and relations inherited by classes in this source model.
classesType:
Mapping[str, ClassMapping]Class mappings keyed by source-model class identifier or stable mapping identifier, according to the selected source-model mapping contract.
is_ssotType:
boolWhether this model mapping describes a canonical single-source-of-truth model.
languagesType:
frozenset[str]Source languages explicitly supported by this model mapping. An unavailable requested language must not be silently replaced by another language.
ModelMappings
- class teksi_hooks.models.mapping.ModelMappings(models=<factory>)[source]
Contain explicit mappings for all configured source models.
- Parameters:
models (Mapping[str, ModelMapping])
Fields
modelsType:
Mapping[str, ModelMapping]Model mappings keyed by stable source-model mapping identifier. Example identifiers include agxx, sia405_abwasser, dss and vsa_kek.
RelationContext
- class teksi_hooks.models.mapping.RelationContext(relation, class_mapping)[source]
Provide runtime context for one mapped relation.
The context links a concrete SQLAlchemy ORM relation with the resolved semantic class mapping used by the diff and validation pipeline.
- Parameters:
relation (type)
class_mapping (ClassMapping)
Fields
relationType:
typeSQLAlchemy ORM relation generated for the source model.
class_mappingType:
ClassMappingResolved mapping for the source-model class represented by the ORM relation.
RelationMapping
- class teksi_hooks.models.mapping.RelationMapping(referenced_class_id, referenced_attribute_id='obj_id', localisations=<factory>)[source]
Map a canonical relation to a localized source-model relation.
Canonical relation and target identifiers remain independent of the source-model language. Localized identifiers are exact executable source-model element identifiers and are not display labels.
- Parameters:
referenced_class_id (str)
referenced_attribute_id (str)
localisations (Mapping[str, str])
Fields
referenced_class_idType:
strCanonical identifier of the class referenced by the relation. Example: organisation.
referenced_attribute_idType:
strCanonical identifier of the referenced target attribute. Defaults to obj_id.
localisationsType:
Mapping[str, str]Exact source-model relation identifiers keyed by source language. Example: {‘de’: ‘DatenbewirtschafterRef’}.
ValueListMapping
- class teksi_hooks.models.mapping.ValueListMapping(relation, mapping_attribute, value_attribute='code')[source]
Describe a database-backed source-to-canonical value translation.
- Parameters:
relation (str)
mapping_attribute (str)
value_attribute (str)
Fields
relationType:
strQualified database relation used for value translation. Example: tww_vl.measure_category_import_rel_agxx.
mapping_attributeType:
strRelation attribute matched against the submitted source-model value. Example: value_de.
value_attributeType:
strRelation attribute containing the resulting canonical value. Defaults to code.
ValueMapping
- class teksi_hooks.models.mapping.ValueMapping(canonical_value_id, value)[source]
Map one source-model value to a canonical internal value.
- Parameters:
canonical_value_id (int)
value (str)
Fields
canonical_value_idType:
intCanonical value identifier. Corresponds to a value-list code or database value identifier.
valueType:
strSource-model value mapped to the canonical value. For a single-source-of-truth model, this may be the canonical English value associated with the canonical code.