hydra-kernel-0.18.0: src/main/haskell/Hydra/Core/Diff.hs
-- Note: this is an automatically generated file. Do not edit.
-- | A generic, domain-agnostic framework for diffs, patches, and migrations over any 'type'/'value' grammar (hydra.core.model.Type/Term, property-graph types, RDF shapes, ...). Fully parameterized: no Type/Term/Name/step type is hardcoded. Type parameters: a = the thing being edited (a type or a value); t = a 'type' type; v = a value/instance type; s = a step into a value; n = a name/key. Fill and Migrator hold host functions and are runtime-only (not serialized).
module Hydra.Core.Diff where
import qualified Hydra.Core.Model as Model
import Prelude hiding (Enum, Ordering, decodeFloat, encodeFloat, fail, lines, map, pure, sum, unlines)
import qualified Data.Scientific as Sci
import Data.Void
import qualified Data.Map as M
-- | A base-relative edit (delta) transforming a value into a new value. Applied forward against a base; a symmetric before/after 'diff' is derived from (base, Edit), not stored here. Canonical by construction: descend carries single-step StepEdits, so there is exactly one encoding of any change.
data Edit a s =
-- | Leave this position unchanged
EditRetain |
-- | Set this position to the given value (upsert: prior presence is irrelevant)
EditSet a |
-- | Remove this position (valid only at a removable position, e.g. a record field or collection element)
EditDelete |
-- | Edit specific immediate children, one StepEdit per changed step
EditDescend [StepEdit a s]
deriving (Eq, Ord, Read, Show)
_Edit = Model.Name "hydra.core.diff.Edit"
_Edit_retain = Model.Name "retain"
_Edit_set = Model.Name "set"
_Edit_delete = Model.Name "delete"
_Edit_descend = Model.Name "descend"
-- | A user's answer to a hole. RUNTIME-ONLY (holds a host function; not serialized). fillNow supplies the value here (a constant is a function ignoring its input); defer leaves the hole open for an enclosing context to supply.
data Fill v =
-- | Fill the hole here: a function from the old value (context) to the filled value
FillFillNow (v -> v) |
-- | Leave the hole open, to be supplied by an enclosing context where this value is embedded
FillDefer
_Fill = Model.Name "hydra.core.diff.Fill"
_Fill_fillNow = Model.Name "fillNow"
_Fill_defer = Model.Name "defer"
-- | A demand the migration cannot satisfy from the old value alone: at a value-path, a value of the given 'type' must be supplied.
data Hole t s =
Hole {
-- | The value-path (sequence of steps) to the position needing a value
holePath :: [s],
-- | The 'type' a fill must produce at this hole
holeType :: t}
deriving (Eq, Ord, Read, Show)
_Hole = Model.Name "hydra.core.diff.Hole"
_Hole_path = Model.Name "path"
_Hole_type = Model.Name "type"
-- | A value supplied for a residual (deferred) hole, identified by its path (engine-internal)
data HoleFiller v s =
HoleFiller {
-- | The path of the residual hole being supplied
holeFillerPath :: [s],
-- | The value supplied for that hole
holeFillerValue :: v}
deriving (Eq, Ord, Read, Show)
_HoleFiller = Model.Name "hydra.core.diff.HoleFiller"
_HoleFiller_path = Model.Name "path"
_HoleFiller_value = Model.Name "value"
-- | A validation-time failure: the user's fills do not correctly answer the plan's holes
data InvalidFillError t v s =
-- | A fillNow produced a value that does not inhabit the hole's type
InvalidFillErrorIllTyped (Hole t s) |
-- | A hole received no fill
InvalidFillErrorMissingFill (Hole t s) |
-- | A surplus fill at this index, with no hole to answer
InvalidFillErrorExtraFill Int
deriving (Eq, Ord, Read, Show)
_InvalidFillError = Model.Name "hydra.core.diff.InvalidFillError"
_InvalidFillError_illTyped = Model.Name "illTyped"
_InvalidFillError_missingFill = Model.Name "missingFill"
_InvalidFillError_extraFill = Model.Name "extraFill"
-- | An application-time failure: a specific instance could not be migrated by a valid Migrator
data MigrationError t v s =
-- | The input value is not a valid instance of the old type
MigrationErrorNotAnInstance v |
-- | A value failed a narrowing conversion (e.g. numeric overflow); fail-fast rather than truncate
MigrationErrorOutOfRange v |
-- | An instance of a removed union variant whose handler is reject
MigrationErrorRejectedVariant v |
-- | A fill or resolver produced a value that does not inhabit the hole's type
MigrationErrorIllTypedResult (Mistyped t v) |
-- | A deferred hole reached application time still unanswered
MigrationErrorUnfilledHole (Hole t s)
deriving (Eq, Ord, Read, Show)
_MigrationError = Model.Name "hydra.core.diff.MigrationError"
_MigrationError_notAnInstance = Model.Name "notAnInstance"
_MigrationError_outOfRange = Model.Name "outOfRange"
_MigrationError_rejectedVariant = Model.Name "rejectedVariant"
_MigrationError_illTypedResult = Model.Name "illTypedResult"
_MigrationError_unfilledHole = Model.Name "unfilledHole"
-- | The result of diffing two schemas: the per-type edits (which drive the transform) bundled with the ordered holes the user must answer. Supplied once to constructMigrator so the diff is never re-passed.
data MigrationPlan n t s =
MigrationPlan {
-- | The schema diff: an edit per changed type, keyed by type name
migrationPlanEdits :: (M.Map n (Edit t s)),
-- | The ordered holes across all changed types, for the user to answer
migrationPlanHoles :: [SchemaHole n t s]}
deriving (Eq, Ord, Read, Show)
_MigrationPlan = Model.Name "hydra.core.diff.MigrationPlan"
_MigrationPlan_edits = Model.Name "edits"
_MigrationPlan_holes = Model.Name "holes"
-- | A constructed instance migrator. RUNTIME-ONLY (apply is a host function; not serialized). Carries the residual (deferred) holes an enclosing context must supply, and applies to a value given values for those residual holes.
data Migrator t v s =
Migrator {
-- | Deferred holes that an enclosing context must supply when composing this migrator
migratorResidualHoles :: [Hole t s],
-- | Migrate a value, given values for the residual holes; fails with a MigrationError per instance
migratorApply :: ([HoleFiller v s] -> v -> Either (MigrationError t v s) v)}
_Migrator = Model.Name "hydra.core.diff.Migrator"
_Migrator_residualHoles = Model.Name "residualHoles"
_Migrator_apply = Model.Name "apply"
-- | A value together with the 'type' it failed to inhabit
data Mistyped t v =
Mistyped {
-- | The offending value
mistypedValue :: v,
-- | The type the value did not inhabit
mistypedType :: t}
deriving (Eq, Ord, Read, Show)
_Mistyped = Model.Name "hydra.core.diff.Mistyped"
_Mistyped_value = Model.Name "value"
_Mistyped_type = Model.Name "type"
-- | A hole located within a named type of a schema. A type with several holes yields several SchemaHoles sharing a typeName.
data SchemaHole n t s =
SchemaHole {
-- | The name of the type (a schema entry) containing this hole
schemaHoleTypeName :: n,
-- | The hole within that type
schemaHoleHole :: (Hole t s)}
deriving (Eq, Ord, Read, Show)
_SchemaHole = Model.Name "hydra.core.diff.SchemaHole"
_SchemaHole_typeName = Model.Name "typeName"
_SchemaHole_hole = Model.Name "hole"
-- | An edit applied at a single immediate step of a value
data StepEdit a s =
StepEdit {
-- | The immediate step to descend into
stepEditStep :: s,
-- | The edit to apply at that step
stepEditEdit :: (Edit a s)}
deriving (Eq, Ord, Read, Show)
_StepEdit = Model.Name "hydra.core.diff.StepEdit"
_StepEdit_step = Model.Name "step"
_StepEdit_edit = Model.Name "edit"