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