Source code for cadrumo.application.modelo.edit_contract
"""The publicly consumable face of the Modelo Edit Contract V1.This module carries only what a package OUTSIDE ``application.modelo``legitimately holds: the safe result receipt a guarded compare-and-swapproduces, the closed mutation family it names, the execution effect thereceipt records, and the fail-closed boundary posture all three share.The rest of the Edit Contract V1 record family -- admission, parsing,preflight, intents, addresses, refusals and capability projection -- stayspackage-internal in ``_edit_models``, because no consumer outside thepackage addresses those and publishing them would widen the contract tothe shape of its implementation rather than the shape of its use.The dependency runs one way: ``_edit_models`` imports from here. Theinternal record family references the receipt and the effect, so thereverse direction would be a cycle."""from__future__importannotationsfromdatetimeimportdatetimefromenumimportStrEnumfromtypingimportLiteralfrompydanticimportBaseModel,ConfigDict,model_validatorfrom...core.errors.hierarchyimportpydantic_validation_boundaryfrom...core.heximportHex64Strfrom...core.identity.digestimportContentDigestfrom...core.identity.hex_idsimport(CalculationRevisionId,ModeloEditBaselineId,ModeloEditMutationResultReceiptId,WorkUnitId,)from...core.time.utcimportvalidate_utc_awarefrom..operations.modelsimportOperationDefinitionId,OperationId,OperationReferencefrom..operations.registryimportOperationSchemaIdentityV1
[docs]classEditModel(BaseModel):"""The common fail-closed boundary posture for Edit Contract V1 records."""model_config=ConfigDict(strict=True,frozen=True,extra="forbid",validate_default=True)
[docs]classModeloEditMutationFamily(StrEnum):"""The closed set of edit-executed effects this V1 contract covers."""CALCULATE="calculate"RECALCULATE="recalculate"
[docs]classModeloEditExecutionEffect(StrEnum):"""The two possible outcomes of one guarded compare-and-swap execution."""UPDATED="updated"NONE="none"
[docs]classModeloEditMutationResultReceiptV1(EditModel):"""The safe domain proof co-committed with one guarded compare-and-swap edit. Carries no financial value, raw input, row content, or input digest. A matching receipt proves ``UPDATED``; a proven failed compare-and-swap proves ``NONE``. ``bucket_event_id`` is ``None`` on a duplicate-result confirmation: an identical content-addressed revision already exists, so this commit advances or confirms only the work-unit pointer and emits no fresh ``MODELO_CALCULATION_CREATED`` event to reference. It is always present when the commit created the revision. """receipt_id:ModeloEditMutationResultReceiptIdoperation_id:OperationIdmutation_family:ModeloEditMutationFamilybaseline_id:ModeloEditBaselineIdwork_unit_id:WorkUnitIdcalculation_revision_id:CalculationRevisionIdbucket_event_id:Hex64Str|Noneeffect:Literal[ModeloEditExecutionEffect.UPDATED]=ModeloEditExecutionEffect.UPDATEDcommitted_at:datetimeresult_destination:OperationReference@model_validator(mode="after")@pydantic_validation_boundarydef_require_utc_commit_time(self)->ModeloEditMutationResultReceiptV1:validate_utc_aware(self.committed_at)returnself
[docs]classModeloEditCompatibilityTupleV1(EditModel):"""Every distinct current-only version and digest axis this edit binds to. No member is collapsed into a generic shared ``version``, and a manifest version never substitutes for a definition or contract-set digest. """workspace_contract_version:Literal[1]=1edit_contract_version:Literal[1]=1operation_manifest_version:Literal[1]=1contract_set_digest:ContentDigestoperation_definition_id:OperationDefinitionIddefinition_contract_digest:ContentDigestrequest_schema:OperationSchemaIdentityV1result_schema:OperationSchemaIdentityV1observation_contract_version:Literal[1]=1review_projection_contract_version:Literal[1]|Nonereview_schema:OperationSchemaIdentityV1|Noneworkspace_refresh_target_version:Literal[1]=1workspace_refresh_target_schema:OperationSchemaIdentityV1financial_operand_protocol_version:Literal[1]=1financial_operand_schema:OperationSchemaIdentityV1@model_validator(mode="after")def_require_consistent_review_declaration(self)->ModeloEditCompatibilityTupleV1:has_version=self.review_projection_contract_versionisnotNonehas_schema=self.review_schemaisnotNoneifhas_version!=has_schema:raiseValueError("edit compatibility REVIEW axis must declare version and schema together or neither")returnself