~/bend-docscommunity

ordinary_app_linked_cleanup_system.bend source

ordinary_app_linked_cleanup_system.bend on the hub · documented module

import Baseimport ./world.bend as Wimport ./ordinary_app_relation.bend as Relationimport ./relation_failure_reader.bend as Ordimport ./relation_types.bend as Gimport ./relation_commands.bend as Aimport ./ordinary_app_linked_cleanup.bend as LCimport ./transaction.bend as Timport ./commands.bend as Cmdimport ./system.bend as Sysimport ./capabilities.bend as Capimport ./ordinary_app_composer.bend as Buildimport ./ordinary_app_recipe.bend as Treeimport ./ordinary_app_observation_data.bend as DTOimport ./ordinary_app_registration_fields.bend as Fieldsimport ./ordinary_component_clear_declaration.bend as Clear# Gameplay receives an abstract affine owner and this single live operation.type Ops<-H:Type,-S:Data> is Type:  Ops{cleanup:Cap.Request<H,W.Handle<S>,A.QueueStatus>}def cleanup(-H:Type,-S:Data,caps:Ops<H,S>,owner:H,handle:W.Handle<S>) -> H & A.QueueStatus:  match caps:    case Ops{Cap.Request{request}}:request(owner,handle)def writes(keys:List<&2,String>) -> List<&2,String>:  match keys:    case []:[]    case key <> rest:String.concat([key,":write"]) <> writes(rest)def relation_accesses(~S:Data,declarations:List<&2,Ord.Declaration<S>>) -> List<&2,String>:  match declarations:    case []:[]    case Ord.Declaration{G.Descriptor{_,name,_,_}} <> rest:String.concat([name,":write"]) <> relation_accesses(~S,rest)def request(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,tx:T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>>,handle:W.Handle<S>) -> T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>> & A.QueueStatus:  LC.queue(~S,~C,~R,~E,~declarations,~clear,~record,tx,handle)def provide(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>) -> Ops<T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>>,S>:  Ops{Cap.Request{request(~S,~C,~R,~E,~declarations,~clear,~record)}}def returned(~S:Data,~C:Type,~R:Type,~E:Data,~U:Data,~Out:Data,output:Out,result:T.Returned<Relation.World(~S,~C,~R,~E),U>) -> Sys.Outcome<Relation.World(~S,~C,~R,~E),U,Out>:  match result:    case T.Returned{world,T.Success{}}:Sys.Succeeded{world,output}    case T.Returned{world,T.Failure{error}}:Sys.Failed{world,error}def invoked(~S:Data,~C:Type,~R:Type,~E:Data,~U:Data,~Out:Data,result:T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>> & (T.Outcome<U> & Out)) -> Sys.Outcome<Relation.World(~S,~C,~R,~E),U,Out>:  match result:    case (tx,(outcome,output)):returned(~S,~C,~R,~E,~U,~Out,output,Cmd.tx_finish(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~U,tx,outcome))def runner(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),world:Relation.World(~S,~C,~R,~E),args:Args) -> Sys.Outcome<Relation.World(~S,~C,~R,~E),U,Out>:  invoked(~S,~C,~R,~E,~U,~Out,body(T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>>,provide(~S,~C,~R,~E,~declarations,~clear,~record),args,T.begin(~Relation.World(~S,~C,~R,~E),~A.Notice<S,E>,world)))def Owner(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out)) -> Type:  Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>def register(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),~clearDeclaration:Clear.Declaration<S,C,A.Notice<S,E>,clear>,world:Relation.World(~S,~C,~R,~E),name:String) -> Sys.RegistrationResult<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>:  Sys.register(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~Args,~U,~Out,~runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body),world,name,List.append(&2,String,writes(Clear.keys(~S,~C,~A.Notice<S,E>,~clear,clearDeclaration)),relation_accesses(~S,declarations)))def run(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),owner:Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>,world:Relation.World(~S,~C,~R,~E),args:Args) -> Sys.RunResult<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>:  Sys.run(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~Args,~U,~Out,~runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body),owner,world,args)type Defined<-App:Type,-Registry:Type> is Type:  Defined{app:App,owner:Registry}  DefinitionRejected{app:App}type Executed<-App:Type,-Registry:Type,-Args:Data,-U:Data,-Out:Data> is Type:  Executed{app:App,owner:Registry,outcome:T.Outcome<U>,output:Maybe<&2,Out>}  RegistrationRejected{app:App,owner:Registry,args:Args}def registered_app(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),~Owners:Type,~Rows:Data,~observe:Relation.World(~S,~C,~R,~E) -> Relation.World(~S,~C,~R,~E) & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,owners:Owners,recipe:Tree.Recipe<Relation.World(~S,~C,~R,~E),Rows,observe>,debug:Bool,result:Sys.RegistrationResult<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>) -> Defined<LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>>:  match result:    case Sys.Registered{world,registry}:Defined{LC.Installed{Build.Registered{world,owners,recipe,debug}},registry}    case Sys.RegistrationFailed{world}:DefinitionRejected{LC.Installed{Build.Registered{world,owners,recipe,debug}}}def register_app(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),~Owners:Type,~Rows:Data,~observe:Relation.World(~S,~C,~R,~E) -> Relation.World(~S,~C,~R,~E) & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,~clearDeclaration:Clear.Declaration<S,C,A.Notice<S,E>,clear>,installed:LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,name:String) -> Defined<LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>>:  match installed:    case LC.Installed{Build.Registered{world,owners,recipe,debug}}:registered_app(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body,~Owners,~Rows,~observe,~fold,owners,recipe,debug,register(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body,~clearDeclaration,world,name))def executed_app(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),~Owners:Type,~Rows:Data,~observe:Relation.World(~S,~C,~R,~E) -> Relation.World(~S,~C,~R,~E) & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,owners:Owners,recipe:Tree.Recipe<Relation.World(~S,~C,~R,~E),Rows,observe>,debug:Bool,result:Sys.RunResult<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>) -> Executed<LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>,Args,U,Out>:  match result:    case Sys.Completed{registry,Sys.Succeeded{world,output}}:Executed{LC.Installed{Build.Registered{world,owners,recipe,debug}},registry,T.Success{},Some{output}}    case Sys.Completed{registry,Sys.Failed{world,error}}:Executed{LC.Installed{Build.Registered{world,owners,recipe,debug}},registry,T.Failure{error},None{}}    case Sys.RegistrationRejected{registry,world,args}:RegistrationRejected{LC.Installed{Build.Registered{world,owners,recipe,debug}},registry,args}def run_app(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),~Owners:Type,~Rows:Data,~observe:Relation.World(~S,~C,~R,~E) -> Relation.World(~S,~C,~R,~E) & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,owner:Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>,installed:LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,input:Args) -> Executed<LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>,Args,U,Out>:  match installed:    case LC.Installed{Build.Registered{world,owners,recipe,debug}}:executed_app(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body,~Owners,~Rows,~observe,~fold,owners,recipe,debug,run(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body,owner,world,input))