inspector_relation_projection.bend source
inspector_relation_projection.bend on the hub · documented module
import Baseimport ./change_tick.bend as Tickimport inspector_query_projection.bend as Selectimport inspector_query.bend as Queryimport inspector_query_frame_world.bend as Traverseimport inspector.bend as Iimport world.bend as Wimport relation_types.bend as Gimport relation_commands.bend as Aimport 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<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>) -> I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>: (world,graph)=observed (I.Frame{world,cursor},graph)def graph(~S:Data,~C:Type,~R:Type,~E:Data,frame:I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>) -> I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>: match frame: case I.Frame{world,cursor}:graph_joined(~S,~C,~R,~E,cursor,W.with_store(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~G.Graph<S>,RQ.graph_read(~S,~C),world))def accepted(~S:Data,observed:Bool & RQ.Row<S,Unit>) -> Bool: (selected,row)=observed selecteddef cells(~S:Data,observed:Bool & RQ.Row<S,Unit>) -> List<&2,RQ.Cell<S>>: match observed: case (_,RQ.Row{_,items,_}):itemsdef matched(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec<S>,target:W.Handle<S>,observed:I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>) -> I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & 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<S>,frame:I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,target:W.Handle<S>) -> I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & 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<S>,target:W.Handle<S>,observed:I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>) -> I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & List<&2,RQ.Cell<S>>: (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<S>,frame:I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,target:W.Handle<S>) -> I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & List<&2,RQ.Cell<S>>: 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<S>,target:W.Handle<S>,observed:I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>) -> I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & 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<S>,frame:I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,target:W.Handle<S>) -> I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & 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<S>,target:W.Handle<S>,observed:I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>) -> I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & List<&2,RQ.Cell<S>>: (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<S>,frame:I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,target:W.Handle<S>) -> I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & List<&2,RQ.Cell<S>>: 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<S>) -> Select.DeclaredSelection<I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,S,List<&2,RQ.Cell<S>>>: 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<I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,S,V>,~spec:RQ.Spec<S>) -> Query.ComposedReadQuery<I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,S,Select.Product<V,List<&2,RQ.Cell<S>>>>: Query.grant_composed_runtime(~I.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,~S,~V,~List<&2,RQ.Cell<S>>,~RQ.Spec<S>,~component,~Traverse.inspect_world(~S,~A.Store<S,C>,~R,~A.Notice<S,E>),~matches_runtime(~S,~C,~R,~E),~project_runtime(~S,~C,~R,~E),spec)