import Base import ./change_tick.bend as Tick import ./restore_graph_data.bend as GraphData import ./restore_graph_validation.bend as Validation import ./restore_graph_machine.bend as Machine import ./restore_graph_world.bend as Install import ./restore_data.bend as R import ./restore_schema.bend as Schema import ./restore_public.bend as Basic import ./restore_prepare.bend as Prepare import ./restore_apply.bend as Apply import ./relation_commands.bend as Relation import ./relation_types.bend as G import ./relation_failure_reader.bend as Declaration import ./owner_product.bend as Product import ./snapshot_data.bend as Snapshot import ./world.bend as W import ./decode_data.bend as D import ./entity_key.bend as Key type Owner R.Position -> D.Field -> State & R.Dispatch,-release:State -> State,-clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,-insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,Recovery:Type,-commit:State -> State,-takeRecovery:State -> State & Recovery,-machineRead:Machines -> Machines & List<&2,D.Field>,-machineCheck:D.Field -> Machine.Dispatch,-machineClear:Machines -> Machines,-machineInstall:Machines -> List<&2,D.Field> -> Machines> is Type: Owner{basic:Basic.Owner,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema} type Error is Data: BasicError{error:R.Error} GraphError{error:GraphData.Error} type Returned is Type: Restored{world:World,owner:Owner,recovery:Recovery,bindings:List<&2,R.Binding>} Rejected{world:World,owner:Owner,recovery:Recovery,input:GraphData.Snapshot,error:Error} MissingBinding{world:World,owner:Owner,recovery:Recovery,saved:Key.Key} def owned(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,basic:Basic.Owner,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema) -> Owner: Owner{basic,relations,machines} def rejected_recovery(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,input:GraphData.Snapshot,error:Error,result:State & Recovery) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: match result: case (state,recovery):Rejected{world,Owner{Basic.Owner{schema,state},relations,machines},recovery,input,error} def reject(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,state:State,input:GraphData.Snapshot,error:Error) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: rejected_recovery(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,input,error,takeRecovery(release(state))) def finish_recovery(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,bindings:List<&2,R.Binding>,missing:Maybe<&2,Key.Key>,result:State & Recovery) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: match missing result: case None{},(state,recovery):Restored{world,Owner{Basic.Owner{schema,state},relations,machines},recovery,bindings} case Some{saved},(state,recovery):MissingBinding{world,Owner{Basic.Owner{schema,state},relations,machines},recovery,saved} def finished(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,bindings:List<&2,R.Binding>,state:State,result:Install.Installed,Product.Owner,E>>) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: match result: case Install.MissingBinding{world,saved}:finish_recovery(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,bindings,Some{saved},takeRecovery(commit(state))) case Install.Installed{world}:finish_recovery(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,bindings,None{},takeRecovery(commit(state))) def applied(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,input:GraphData.Snapshot,graph:G.Graph,fields:List<&2,D.Field>,result:Apply.ApplyResult,Product.Owner,E,State,Custom>) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: match result: case Apply.Refused{world,state,_,error}:reject(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,state,input,BasicError{error}) case Apply.Applied{world,state,+bindings}:finished(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,bindings,state,Install.install(~S,~C,~Resources,~Machines,~E,~machineClear,~machineInstall,world,graph,fields,bindings)) def machine_checked(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,~emit:R.Change -> E,+schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,state:State,+input:GraphData.Snapshot,graph:G.Graph,fields:List<&2,D.Field>,error:Maybe<&2,GraphData.Error>) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: match input error: case input Some{error}:reject(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,state,input,GraphError{error}) case GraphData.Snapshot{+basic,+relationFields,+machineFields} None{}:applied(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,GraphData.Snapshot{basic,relationFields,machineFields},graph,fields,Apply.apply(~S,~Relation.Store,~Product.Owner,~E,~State,~Custom,~release,~clear,~insert,~emit,world,R.BendvyReady{state,basic})) def graph_checked(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,~emit:R.Change -> E,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,state:State,+input:GraphData.Snapshot,result:GraphData.GraphResult) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: match input result: case input GraphData.Rejected{error}:reject(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,state,input,GraphError{error}) case GraphData.Snapshot{+basic,+relationFields,+machineFields} GraphData.Accepted{graph}:machine_checked(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,~emit,schema,relations,machines,world,state,GraphData.Snapshot{basic,relationFields,machineFields},graph,machineFields,Machine.validate(~machineCheck,machineFields)) def prepared(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,~emit:R.Change -> E,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,+relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,+input:GraphData.Snapshot,result:R.Prepared) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: match input result: case input R.Refused{state,_,error}:reject(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,state,input,BasicError{error}) case GraphData.Snapshot{Snapshot.Snapshot{+version,+floor,+entities,+resources},+relationFields,+machineFields} R.BendvyReady{state,_}:graph_checked(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,~emit,schema,relations,machines,world,state,GraphData.Snapshot{Snapshot.Snapshot{version,floor,entities,resources},relationFields,machineFields},Validation.validate(~S,relationFields,entities,relations)) def run(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,~emit:R.Change -> E,owner:Owner,world:W.World,Product.Owner,E>,+input:GraphData.Snapshot) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: match owner input: case Owner{Basic.Owner{schema,state},relations,machines} GraphData.Snapshot{+basic,+relationFields,+machineFields}:prepared(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,~emit,schema,relations,machines,world,GraphData.Snapshot{basic,relationFields,machineFields},Prepare.prepare(~State,~Custom,~stage,~release,state,basic))