~/bend-docscommunity

ordinary_app_machine_handler.bend source

ordinary_app_machine_handler.bend on the hub · documented module

import Baseimport ./change_tick.bend as Tickimport ./world.bend as Wimport ./system.bend as Sysimport ./machine.bend as Mimport ./machine_handlers.bend as Himport ./machine_handler_bundle.bend as Bimport ./ordinary_machine_handler_bundle.bend as Operationimport ./ordinary_machine_schedule.bend as Ordinaryimport ./schedule.bend as Sch# Detached handler selector/requirements and actual registry metadata for display.# Does not own a handler, grant capabilities or duplicate Local/capture state.type EntryView<S:Data,K:Data,V:Data,Q:Data> is Data:  EntryView{selector:B.Selector<S,K,V>,requirements:List<&2,Q>,namespace:U32,entryId:U32,id:U32,name:String,access:List<&2,String>,cursor:Maybe<&2,Tick.Tick>}# Detached marker schedule phases and ordered handler entry views.type Description<S:Data,K:Data,V:Data,Q:Data> is Data:  Description{namespace:U32,name:String,steps:List<&2,Sch.Step>,entries:List<&2,EntryView<S,K,V,Q>>}# Affine World, handler bundle and extra owners with declaration/debug. Recovering# retains an existing MarkerResult rather than silently starting another marker.type Application<S:Data,K:Data,V:Data,Q:Data,C:Type,R:Type,E:Data,-runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,Extra:Type> is Type:  Application{world:W.World<S,C,R,E>,bundle:B.Bundle<S,K,V,Q,C,R,E,runner>,declaration:Ordinary.Declaration<S>,extra:Extra,debug:Bool}  Recovering{result:Operation.MarkerResult<S,K,V,Q,C,R,E,runner>,declaration:Ordinary.Declaration<S>,extra:Extra,debug:Bool}def entries_returned(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,+selector:B.Selector<S,K,V>,+requirements:List<&2,Q>,+namespace:U32,+entryId:U32,+id:U32,+name:String,+access:List<&2,String>,+cursor:Maybe<&2,Tick.Tick>,result:List<&1,B.Scheduled<S,K,V,Q,C,R,E,runner>> & List<&2,EntryView<S,K,V,Q>>) -> List<&1,B.Scheduled<S,K,V,Q,C,R,E,runner>> & List<&2,EntryView<S,K,V,Q>>:  (rest,views)=result  (B.Scheduled{selector,requirements,H.Entry{entryId,Sys.Registry{namespace,id,name,access,cursor}}} <> rest,EntryView{selector,requirements,namespace,entryId,id,name,access,cursor} <> views)# Describe scheduled handlers in list order while returning all actual owners.# Detached selector/requirements/registry fields do not execute handlers or prove# that requirements are satisfied. This advanced helper has no debug bypass.def entries(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,items:List<&1,B.Scheduled<S,K,V,Q,C,R,E,runner>>) -> List<&1,B.Scheduled<S,K,V,Q,C,R,E,runner>> & List<&2,EntryView<S,K,V,Q>>:  match items:    case []:([],[])    case B.Scheduled{selector,requirements,H.Entry{entryId,Sys.Registry{namespace,id,name,access,cursor}}} <> rest:entries_returned(~S,~K,~V,~Q,~C,~R,~E,~runner,selector,requirements,namespace,entryId,id,name,access,cursor,entries(~S,~K,~V,~Q,~C,~R,~E,~runner,rest))# Retain supplied actual World/bundle/extra owners as an App with debug off.# No preflight, phase execution or payload cleanup occurs at binding.def bind(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~Extra:Type,world:W.World<S,C,R,E>,bundle:B.Bundle<S,K,V,Q,C,R,E,runner>,declaration:Ordinary.Declaration<S>,extra:Extra) -> Application<S,K,V,Q,C,R,E,runner,Extra>:  Application{world,bundle,declaration,extra,False{}}# Change only observation enablement, retaining normal or recovering owner state.def enabled(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~Extra:Type,app:Application<S,K,V,Q,C,R,E,runner,Extra>,debug:Bool) -> Application<S,K,V,Q,C,R,E,runner,Extra>:  match app:    case Application{world,bundle,declaration,extra,_}:Application{world,bundle,declaration,extra,debug}    case Recovering{result,declaration,extra,_}:Recovering{result,declaration,extra,debug}def described(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~Extra:Type,world:W.World<S,C,R,E>,+namespace:U32,+name:String,extra:Extra,result:List<&1,B.Scheduled<S,K,V,Q,C,R,E,runner>> & List<&2,EntryView<S,K,V,Q>>) -> Application<S,K,V,Q,C,R,E,runner,Extra> & Maybe<&2,Description<S,K,V,Q>>:  (items,views)=result  (Application{world,B.Bundle{namespace,items},Ordinary.Declaration{name},extra,True{}},Some{Description{namespace,name,Ordinary.steps(),views}})# Describe normal enabled App entries, returning all actual handler owners.# Disabled or Recovering returns None without entry derivation; does not run# handlers, apply queued transitions or validate requirements.def snapshot(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~Extra:Type,app:Application<S,K,V,Q,C,R,E,runner,Extra>) -> Application<S,K,V,Q,C,R,E,runner,Extra> & Maybe<&2,Description<S,K,V,Q>>:  match app:    case Application{world,B.Bundle{namespace,items},Ordinary.Declaration{name},extra,True{}}:described(~S,~K,~V,~Q,~C,~R,~E,~runner,~Extra,world,namespace,name,extra,entries(~S,~K,~V,~Q,~C,~R,~E,~runner,items))    case app:(app,None{})# Retained marker result plus original declaration, extra owners and debug.# Inspect its BundleResult for status rather than inferring success from observations.type RunResult<S:Data,K:Data,V:Data,Q:Data,C:Type,R:Type,E:Data,-runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,Extra:Type> is Type:  RunResult{result:Operation.MarkerResult<S,K,V,Q,C,R,E,runner>,declaration:Ordinary.Declaration<S>,extra:Extra,debug:Bool}# Normal App executes ordinary marker preflight/barrier/phase machinery. Recovering# passes through its retained result without rerun. Returned marker keeps actual# owners; exit/transition failure leaves retryable pending work, while enter failure# retains committed current/publication. No schedule-wide transaction is added.def run_app(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~take:W.World<S,C,R,E> -> W.World<S,C,R,E> & M.Slot<S,K,V>,~put:W.World<S,C,R,E> -> M.Slot<S,K,V> -> W.World<S,C,R,E>,~publish:W.World<S,C,R,E> -> M.Transition<V> -> W.World<S,C,R,E>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World<S,C,R,E> -> Q -> W.World<S,C,R,E> & Bool,~frame:W.World<S,C,R,E> -> W.World<S,C,R,E>,~Extra:Type,app:Application<S,K,V,Q,C,R,E,runner,Extra>) -> RunResult<S,K,V,Q,C,R,E,runner,Extra>:  match app:    case Recovering{result,declaration,extra,debug}:RunResult{result,declaration,extra,debug}    case Application{world,bundle,+declaration,extra,debug}:RunResult{Operation.run(~S,~K,~V,~Q,~C,~R,~E,~runner,~take,~put,~publish,~same,~requirement_same,~has,~frame,declaration,bundle,world),declaration,extra,debug}