1 import Base 2 import inspector_query_projection.bend as Select 3 import inspector_query.bend as Query 4 import inspector_query_frame_world.bend as Traverse 5 import check.bend as K 6 import world.bend as W 7 import relation_types.bend as G 8 import relation_commands.bend as A 9 import relation_query.bend as RQ 10 11 # Actual cursor-free Check Frame. Graph is detached Data; 12 # Store components/resources remain arbitrary affine Type owners. 13 def graph_joined(~S:Data,~C:Type,~R:Type,~E:Data,observed:W.World,R,A.Notice> & G.Graph) -> K.Frame,R,A.Notice> & G.Graph: 14 (world,graph)=observed 15 (K.Frame{world},graph) 16 def graph(~S:Data,~C:Type,~R:Type,~E:Data,frame:K.Frame,R,A.Notice>) -> K.Frame,R,A.Notice> & G.Graph: 17 match frame: 18 case K.Frame{world}:graph_joined(~S,~C,~R,~E,W.with_store(~S,~A.Store,~R,~A.Notice,~G.Graph,RQ.graph_read(~S,~C),world)) 19 def accepted(~S:Data,observed:Bool & RQ.Row) -> Bool: 20 (selected,row)=observed 21 selected 22 def cells(~S:Data,observed:Bool & RQ.Row) -> List<&2,RQ.Cell>: 23 match observed: 24 case (_,RQ.Row{_,items,_}):items 25 def matched(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec,target:W.Handle,observed:K.Frame,R,A.Notice> & G.Graph) -> K.Frame,R,A.Notice> & Bool: 26 (frame,graph)=observed 27 (frame,accepted(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{}))) 28 def matches(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec,frame:K.Frame,R,A.Notice>,target:W.Handle) -> K.Frame,R,A.Notice> & Bool: 29 matched(~S,~C,~R,~E,~spec,target,graph(~S,~C,~R,~E,frame)) 30 def projected(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec,target:W.Handle,observed:K.Frame,R,A.Notice> & G.Graph) -> K.Frame,R,A.Notice> & List<&2,RQ.Cell>: 31 (frame,graph)=observed 32 (frame,cells(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{}))) 33 def project(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec,frame:K.Frame,R,A.Notice>,target:W.Handle) -> K.Frame,R,A.Notice> & List<&2,RQ.Cell>: 34 projected(~S,~C,~R,~E,~spec,target,graph(~S,~C,~R,~E,frame)) 35 # Runtime-data counterparts let composed query kernels share code across 36 # immutable relation specs without changing graph access or row semantics. 37 def matched_runtime(~S:Data,~C:Type,~R:Type,~E:Data,spec:RQ.Spec,target:W.Handle,observed:K.Frame,R,A.Notice> & G.Graph) -> K.Frame,R,A.Notice> & Bool: 38 (frame,graph)=observed 39 (frame,accepted(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{}))) 40 def matches_runtime(~S:Data,~C:Type,~R:Type,~E:Data,spec:RQ.Spec,frame:K.Frame,R,A.Notice>,target:W.Handle) -> K.Frame,R,A.Notice> & Bool: 41 matched_runtime(~S,~C,~R,~E,spec,target,graph(~S,~C,~R,~E,frame)) 42 def projected_runtime(~S:Data,~C:Type,~R:Type,~E:Data,spec:RQ.Spec,target:W.Handle,observed:K.Frame,R,A.Notice> & G.Graph) -> K.Frame,R,A.Notice> & List<&2,RQ.Cell>: 43 (frame,graph)=observed 44 (frame,cells(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{}))) 45 def project_runtime(~S:Data,~C:Type,~R:Type,~E:Data,spec:RQ.Spec,frame:K.Frame,R,A.Notice>,target:W.Handle) -> K.Frame,R,A.Notice> & List<&2,RQ.Cell>: 46 projected_runtime(~S,~C,~R,~E,spec,target,graph(~S,~C,~R,~E,frame)) 47 # Closed relation requirement list supports both directions, required/optional, 48 # presence/absence filters and every declared projection key/order unchanged. 49 def relations(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec) -> Select.DeclaredSelection,R,A.Notice>,S,List<&2,RQ.Cell>>: 50 Select.DeclaredSelection{matches(~S,~C,~R,~E,~spec),project(~S,~C,~R,~E,~spec)} 51 # Recursive Product/map component providers are reused, not reimplemented. 52 # Query.grant performs World namespace/liveness checks before public lookup. 53 def grant(~S:Data,~C:Type,~R:Type,~E:Data,~V:Data,~component:Select.DeclaredSelection,R,A.Notice>,S,V>,~spec:RQ.Spec) -> Query.ComposedReadQuery,R,A.Notice>,S,Select.Product>>>: 54 Query.grant_composed_runtime(~K.Frame,R,A.Notice>,~S,~V,~List<&2,RQ.Cell>,~RQ.Spec,~component,~Traverse.check_world(~S,~A.Store,~R,~A.Notice),~matches_runtime(~S,~C,~R,~E),~project_runtime(~S,~C,~R,~E),spec)