import Base import ./change_tick.bend as Tick import ./reader_parameter.bend as RP import ./ordinary_query_observable.bend as Observable import ./ordinary_query_declaration.bend as Query import ./compose.bend as FrameQuery import ./inspector.bend as Inspector import ./inspector_query.bend as InspectQuery import ./world.bend as W import ./relation_commands.bend as Notice import ./event_notice_runtime.bend as Mixed import ./event_family_routing.bend as Route # Query rows are detached Data values; the shared route context retains the # sole World and its affine event/relation history. type Rows is Data: Rows{rows:List<&2,InspectQuery.ProjectedRow>} def rows_observed(~S:Data,~Store:Type,~R:Type,~P:Data,~V:Data,observed:Inspector.Frame> & List<&2,InspectQuery.ProjectedRow>) -> W.World> & (Unit & (Rows & Unit)): match observed: case (Inspector.Frame{world,_},rows):(world,(Unit{},(Rows{rows},Unit{}))) def validate_context(~S:Data,~Store:Type,~R:Type,~P:Data,~F:Type,~H:Type,~Ops:Type,~V:Data,~declaration:Observable.Declaration>,Ops,Inspector.Frame>,V>,context:Route.Runtime,Mixed.State>,owner:Unit) -> Route.Runtime,Mixed.State> & (Unit & Bool): match context: case Route.Runtime{world,state,tick}:(Route.Runtime{world,state,tick},(owner,True{})) def with_query_rows(~S:Data,~Store:Type,~R:Type,~P:Data,~F:Type,~H:Type,~Ops:Type,~V:Data,state:Mixed.State,tick:Nat,observed:W.World> & (Unit & (Rows & Unit))) -> Route.Runtime,Mixed.State> & (Unit & (Rows & Unit)): match observed: case (world,(owner,(rows,delta))):(Route.Runtime{world,state,tick},(owner,(rows,delta))) def prepare_context(~S:Data,~Store:Type,~R:Type,~P:Data,~F:Type,~H:Type,~Ops:Type,~V:Data,~declaration:Observable.Declaration>,Ops,Inspector.Frame>,V>,context:Route.Runtime,Mixed.State>,+cursor:Maybe<&2,Tick.Tick>,owner:Unit) -> Route.Runtime,Mixed.State> & (Unit & (Rows & Unit)): match context: case Route.Runtime{world,state,tick}:with_query_rows(~S,~Store,~R,~P,~F,~H,~Ops,~V,state,tick,rows_observed(~S,~Store,~R,~P,~V,InspectQuery.each_composed(~Inspector.Frame>,~S,~V,Observable.inspect_query(~S,~Store,~R,~Notice.Notice,~FrameQuery.Frame>,~Ops,~V,~declaration),Inspector.Frame{world,cursor}))) def commit_context(~Context:Type,context:Context,owner:Unit,delta:Unit,+cursor:Tick.Tick) -> Context & Unit: (context,owner) # Query projection retains no private cursor or shared-history membership. # Disposal consumes its Unit owner while preserving the sole affine context. def release_context(~Context:Type,context:Context,owner:Unit) -> Context: context def access_clauses(~S:Data,clauses:List<&2,Query.Clause>) -> List<&2,String>: match clauses: case []:[] case Query.Clause{name,_} <> rest:name <> access_clauses(~S,rest) def access_of(~S:Data,~Store:Type,~R:Type,~P:Data,~Ops:Type,~V:Data,declaration:Observable.Declaration>,Ops,Inspector.Frame>,V>) -> List<&2,String>: access_clauses(~S,Query.clauses(~S,~FrameQuery.Frame>,~Ops,Observable.operational(~S,~FrameQuery.Frame>,~Ops,~Inspector.Frame>,~V,declaration))) def from_observable(~S:Data,~Store:Type,~R:Type,~P:Data,~F:Type,~H:Type,~Ops:Type,~V:Data,~declaration:Observable.Declaration>,Ops,Inspector.Frame>,V>) -> RP.Param,Mixed.State>,Unit,Rows,Unit,validate_context(~S,~Store,~R,~P,~F,~H,~Ops,~V,~declaration),prepare_context(~S,~Store,~R,~P,~F,~H,~Ops,~V,~declaration),commit_context(~Route.Runtime,Mixed.State>),release_context(~Route.Runtime,Mixed.State>)>: RP.make(~Route.Runtime,Mixed.State>,~Unit,~Rows,~Unit,~validate_context(~S,~Store,~R,~P,~F,~H,~Ops,~V,~declaration),~prepare_context(~S,~Store,~R,~P,~F,~H,~Ops,~V,~declaration),~commit_context(~Route.Runtime,Mixed.State>),~release_context(~Route.Runtime,Mixed.State>),access_of(~S,~Store,~R,~P,~Ops,~V,declaration))