~/bend-docscommunity

ordinary_app_linked_cleanup.bend source

ordinary_app_linked_cleanup.bend on the hub · documented module

import Baseimport ./deferred_command.bend as Deferredimport ./trace_facts.bend as TraceFactsimport ./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_app_relation.bend as Relationimport ./relation_failure_reader.bend as Ordimport ./relation_types.bend as Gimport ./relation_commands.bend as Aimport ./relation_cleanup.bend as Cleanupimport ./world.bend as Wimport ./transaction.bend as Timport ./commands.bend as Cmd# Trusted setup captures component-binding-derived clear and declaration installs.# This wrapper cannot infer declarations from an arbitrary existing App recipe.type Installed<S:Data,C:Type,R:Type,E:Data,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>>,-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>> is Type:  Installed{app:Build.Registered<S,Relation.World(~S,~C,~R,~E),Owners,Rows,observe,fold>}def descriptors(~S:Data,declarations:List<&2,Ord.Declaration<S>>) -> List<&2,G.Descriptor<S>>:  match declarations:    case []:[]    case Ord.Declaration{descriptor} <> rest:descriptor <> descriptors(~S,rest)def empty(~S:Data,~C:Type,~R:Type,~E:Data,~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>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,app:Build.Registered<S,Relation.World(~S,~C,~R,~E),Owners,Rows,observe,fold>) -> Installed<S,C,R,E,Owners,Rows,observe,fold,[],clear,record>:  Installed{app}def install_relation(~S:Data,~C:Type,~R:Type,~E:Data,~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>>,~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>,~declaration:Ord.Declaration<S>,installed:Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>) -> Installed<S,C,R,E,Owners,Relation.ObservedRows(~S,~Rows),Tree.observe_pair(~Relation.World(~S,~C,~R,~E),~Rows,~Relation.View<S>,~observe,~Relation.observe(~S,~C,~R,~E,~declaration,~Relation.builtin_row(~S))),fold,List.append(&2,Ord.Declaration<S>,declarations,[declaration]),clear,record>:  match installed:    case Installed{app}:Installed{Relation.install(~S,~C,~R,~E,~declaration,~Owners,~Rows,~observe,~fold,app)}def result(~S:Data,~C:Type,~R:Type,~E:Data,result:Cleanup.CleanupResult<S,C,R,E>) -> Relation.World(~S,~C,~R,~E):  match result:    case Cleanup.Complete{world}:world    case Cleanup.Incomplete{world,frames}:W.event_publish(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,world,[A.CleanupPaused{frames}])def apply(~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>,world:Relation.World(~S,~C,~R,~E),handle:W.Handle<S>) -> Relation.World(~S,~C,~R,~E):  result(~S,~C,~R,~E,Cleanup.automatic(~S,~C,~R,~E,~clear,~record,world,handle,descriptors(~S,declarations)))def checked(~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>,allowed:Bool,world:Relation.World(~S,~C,~R,~E),undo:List<(Relation.World(~S,~C,~R,~E) -> Relation.World(~S,~C,~R,~E))>,commands:List<Deferred.Command<Relation.World(~S,~C,~R,~E)>>,events:List<&2,A.Notice<S,E>>,trace:TraceFacts.State,handle:W.Handle<S>) -> T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>> & A.QueueStatus:  match allowed:    case False{}:(T.Tx{world,undo,commands,events,trace},A.MissingEntity{})    case True{}:(T.Tx{world,undo,Deferred.Raw{(world => apply(~S,~C,~R,~E,~declarations,~clear,~record,world,handle))} <> commands,events,trace},A.Queued{})def validated(~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>,handle:W.Handle<S>,undo:List<(Relation.World(~S,~C,~R,~E) -> Relation.World(~S,~C,~R,~E))>,commands:List<Deferred.Command<Relation.World(~S,~C,~R,~E)>>,events:List<&2,A.Notice<S,E>>,trace:TraceFacts.State,seen:Relation.World(~S,~C,~R,~E) & Bool) -> T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>> & A.QueueStatus:  match seen:    case (world,allowed):checked(~S,~C,~R,~E,~declarations,~clear,~record,allowed,world,undo,commands,events,trace,handle)def queue(~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:  match tx:    case T.Tx{world,undo,commands,events,trace}:validated(~S,~C,~R,~E,~declarations,~clear,~record,handle,undo,commands,events,trace,W.valid(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,world,handle))def returned(~S:Data,~C:Type,~R:Type,~E:Data,~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>>,~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>,~Error:Data,owners:Owners,recipe:Tree.Recipe<Relation.World(~S,~C,~R,~E),Rows,observe>,debug:Bool,status:A.QueueStatus,seen:T.Returned<Relation.World(~S,~C,~R,~E),Error>) -> Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record> & DTO.Product<A.QueueStatus,T.Outcome<Error>>:  match seen:    case T.Returned{world,outcome}:(Installed{Build.Registered{world,owners,recipe,debug}},DTO.Product{status,outcome})def queued(~S:Data,~C:Type,~R:Type,~E:Data,~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>>,~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>,~Error:Data,owners:Owners,recipe:Tree.Recipe<Relation.World(~S,~C,~R,~E),Rows,observe>,debug:Bool,outcome:T.Outcome<Error>,seen:T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>> & A.QueueStatus) -> Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record> & DTO.Product<A.QueueStatus,T.Outcome<Error>>:  match seen:    case (tx,status):returned(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,~declarations,~clear,~record,~Error,owners,recipe,debug,status,Cmd.tx_finish(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~Error,tx,outcome))def cleanup_app(~S:Data,~C:Type,~R:Type,~E:Data,~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>>,~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>,~Error:Data,installed:Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,handle:W.Handle<S>,outcome:T.Outcome<Error>) -> Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record> & DTO.Product<A.QueueStatus,T.Outcome<Error>>:  match installed:    case Installed{Build.Registered{world,owners,recipe,debug}}:queued(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,~declarations,~clear,~record,~Error,owners,recipe,debug,outcome,queue(~S,~C,~R,~E,~declarations,~clear,~record,T.begin(~Relation.World(~S,~C,~R,~E),~A.Notice<S,E>,world),handle))def barrier_app(~S:Data,~C:Type,~R:Type,~E:Data,~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>>,~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>,installed:Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>) -> Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>:  match installed:    case Installed{Build.Registered{world,owners,recipe,debug}}:Installed{Build.Registered{W.barrier(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,world),owners,recipe,debug}}def snapshot_returned(~S:Data,~C:Type,~R:Type,~E:Data,~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>>,~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>,seen:Build.Registered<S,Relation.World(~S,~C,~R,~E),Owners,Rows,observe,fold> & Maybe<&2,DTO.Product<List<&2,DTO.Binding<S>>,DTO.Observation<Rows>>>) -> Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record> & Maybe<&2,DTO.Product<List<&2,DTO.Binding<S>>,DTO.Observation<Rows>>>:  match seen:    case (app,view):(Installed{app},view)def snapshot_app(~S:Data,~C:Type,~R:Type,~E:Data,~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>>,~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>,installed:Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,flag:Bool) -> Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record> & Maybe<&2,DTO.Product<List<&2,DTO.Binding<S>>,DTO.Observation<Rows>>>:  match installed:    case Installed{app}:snapshot_returned(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,~declarations,~clear,~record,Build.snapshot(~S,~Relation.World(~S,~C,~R,~E),~Owners,~Rows,~observe,~fold,Build.enabled(~S,~Relation.World(~S,~C,~R,~E),~Owners,~Rows,~observe,~fold,app,flag)))