1 import Base 2 import ./ordinary_app_composer.bend as Build 3 import ./ordinary_app_registration_fields.bend as Records 4 import ./ordinary_app_records.bend as Leaf 5 import ./ordinary_app_recipe.bend as Tree 6 import ./ordinary_app_observation_data.bend as DTO 7 import ./ordinary_system.bend as Ordinary 8 import ./world.bend as W 9 import ./system.bend as Sys 10 import ./check.bend as K 11 import ./ordinary_query_declaration.bend as Query 12 # Run the actual newest retained Registry. Registration refusal remains distinct 13 # from the existing runner error; no replacement error or transaction is added. 14 type Status is Data: 15 Succeeded{output:Out} 16 Failed{error:K.Error} 17 RegistrationRejected{} 18 def completed(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Data,~Out:Data,~runner:W.World -> Args -> Sys.Outcome,K.Error,Out>,result:Sys.RunResult) -> W.World & (Sys.Registry & Status): 19 match result: 20 case Sys.Completed{registry,Sys.Succeeded{world,output}}:(world,(registry,Succeeded{output})) 21 case Sys.Completed{registry,Sys.Failed{world,error}}:(world,(registry,Failed{error})) 22 case Sys.RegistrationRejected{registry,world,_}:(world,(registry,RegistrationRejected{})) 23 def repacked(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Data,~Out:Data,~runner:W.World -> Args -> Sys.Outcome,K.Error,Out>,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners & Leaf.Record>> -> (Owners & Leaf.Record>>) & List<&2,Records.Fields>,world:W.World,owners:Owners,recipe:Tree.Recipe,Rows,observe>,debug:Bool,status:Status,result:Records.Token> & Records.Fields) -> Build.Registered,Owners & Leaf.Record>>,Rows,observe,fold> & Status: 24 match result: 25 case (token,fields):(Build.Registered{world,(owners,Leaf.Record{token,fields}),recipe,debug},status) 26 def returned(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Data,~Out:Data,~runner:W.World -> Args -> Sys.Outcome,K.Error,Out>,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners & Leaf.Record>> -> (Owners & Leaf.Record>>) & List<&2,Records.Fields>,owners:Owners,recipe:Tree.Recipe,Rows,observe>,debug:Bool,slot:String,clauses:List<&2,Query.Clause>,result:W.World & (Sys.Registry & Status)) -> Build.Registered,Owners & Leaf.Record>>,Rows,observe,fold> & Status: 27 match result: 28 case (world,(registry,status)):repacked(~S,~C,~R,~E,~Args,~Out,~runner,~Owners,~Rows,~observe,~fold,world,owners,recipe,debug,status,Records.field_registry(~S,~C,~R,~E,~Args,~K.Error,~Out,~runner,slot,clauses,registry)) 29 def restored(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Data,~Out:Data,~runner:W.World -> Args -> Sys.Outcome,K.Error,Out>,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners & Leaf.Record>> -> (Owners & Leaf.Record>>) & List<&2,Records.Fields>,world:W.World,owners:Owners,recipe:Tree.Recipe,Rows,observe>,debug:Bool,args:Args,result:Ordinary.Owner>) -> Build.Registered,Owners & Leaf.Record>>,Rows,observe,fold> & Status: 30 match result: 31 case Ordinary.Owner{registry,slot,clauses}:returned(~S,~C,~R,~E,~Args,~Out,~runner,~Owners,~Rows,~observe,~fold,owners,recipe,debug,slot,clauses,completed(~S,~C,~R,~E,~Args,~Out,~runner,Sys.run(~S,~C,~R,~E,~Args,~K.Error,~Out,~runner,registry,world,args))) 32 def run_latest(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Data,~Out:Data,~runner:W.World -> Args -> Sys.Outcome,K.Error,Out>,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners & Leaf.Record>> -> (Owners & Leaf.Record>>) & List<&2,Records.Fields>,app:Build.Registered,Owners & Leaf.Record>>,Rows,observe,fold>,args:Args) -> Build.Registered,Owners & Leaf.Record>>,Rows,observe,fold> & Status: 33 match app: 34 case Build.Registered{world,(owners,Leaf.Record{token,fields}),recipe,debug}:restored(~S,~C,~R,~E,~Args,~Out,~runner,~Owners,~Rows,~observe,~fold,world,owners,recipe,debug,args,Records.restore_component(~S,~C,~R,~E,~Args,~K.Error,~Out,~runner,token,fields))