import Base import ./change_tick.bend as Tick import inspector_query_projection.bend as Select import inspector_query.bend as Query import inspector_query_frame_world.bend as Traverse import inspector.bend as I import world.bend as W import relation_types.bend as G import relation_commands.bend as A import relation_query.bend as RQ # Real Inspector Frame, not a fabricated transaction. Graph is detached Data; # Store components/resources remain arbitrary affine Type owners. 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: (world,graph)=observed (I.Frame{world,cursor},graph) def graph(~S:Data,~C:Type,~R:Type,~E:Data,frame:I.Frame,R,A.Notice>) -> I.Frame,R,A.Notice> & G.Graph: match frame: 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)) def accepted(~S:Data,observed:Bool & RQ.Row) -> Bool: (selected,row)=observed selected def cells(~S:Data,observed:Bool & RQ.Row) -> List<&2,RQ.Cell>: match observed: case (_,RQ.Row{_,items,_}):items 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: (frame,graph)=observed (frame,accepted(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{}))) 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: matched(~S,~C,~R,~E,~spec,target,graph(~S,~C,~R,~E,frame)) 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>: (frame,graph)=observed (frame,cells(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{}))) 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>: projected(~S,~C,~R,~E,~spec,target,graph(~S,~C,~R,~E,frame)) # Runtime-data counterparts let composed query kernels share code across # immutable relation specs without changing graph access or row semantics. 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: (frame,graph)=observed (frame,accepted(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{}))) 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: matched_runtime(~S,~C,~R,~E,spec,target,graph(~S,~C,~R,~E,frame)) 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>: (frame,graph)=observed (frame,cells(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{}))) 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>: projected_runtime(~S,~C,~R,~E,spec,target,graph(~S,~C,~R,~E,frame)) # Closed relation requirement list supports both directions, required/optional, # presence/absence filters and every declared projection key/order unchanged. def relations(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec) -> Select.DeclaredSelection,R,A.Notice>,S,List<&2,RQ.Cell>>: Select.DeclaredSelection{matches(~S,~C,~R,~E,~spec),project(~S,~C,~R,~E,~spec)} # Recursive Product/map component providers are reused, not reimplemented. # Query.grant_composed performs World namespace/liveness checks before public lookup. 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>>>: 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)