1 import Base 2 import ./change_tick.bend as Tick 3 import ./reader_parameter.bend as RP 4 import ./ordinary_query_observable.bend as Observable 5 import ./ordinary_query_declaration.bend as Query 6 import ./compose.bend as FrameQuery 7 import ./inspector.bend as Inspector 8 import ./inspector_query.bend as InspectQuery 9 import ./world.bend as W 10 import ./relation_commands.bend as Notice 11 import ./event_notice_runtime.bend as Mixed 12 import ./event_family_routing.bend as Route 13 14 # Query rows are detached Data values; the shared route context retains the 15 # sole World and its affine event/relation history. 16 type Rows is Data: 17 Rows{rows:List<&2,InspectQuery.ProjectedRow>} 18 19 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)): 20 match observed: 21 case (Inspector.Frame{world,_},rows):(world,(Unit{},(Rows{rows},Unit{}))) 22 23 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): 24 match context: 25 case Route.Runtime{world,state,tick}:(Route.Runtime{world,state,tick},(owner,True{})) 26 27 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)): 28 match observed: 29 case (world,(owner,(rows,delta))):(Route.Runtime{world,state,tick},(owner,(rows,delta))) 30 31 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)): 32 match context: 33 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}))) 34 35 def commit_context(~Context:Type,context:Context,owner:Unit,delta:Unit,+cursor:Tick.Tick) -> Context & Unit: 36 (context,owner) 37 38 # Query projection retains no private cursor or shared-history membership. 39 # Disposal consumes its Unit owner while preserving the sole affine context. 40 def release_context(~Context:Type,context:Context,owner:Unit) -> Context: 41 context 42 43 def access_clauses(~S:Data,clauses:List<&2,Query.Clause>) -> List<&2,String>: 44 match clauses: 45 case []:[] 46 case Query.Clause{name,_} <> rest:name <> access_clauses(~S,rest) 47 48 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>: 49 access_clauses(~S,Query.clauses(~S,~FrameQuery.Frame>,~Ops,Observable.operational(~S,~FrameQuery.Frame>,~Ops,~Inspector.Frame>,~V,declaration))) 50 51 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>)>: 52 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))