inspector_relation_projection.bend
bendvy-ecs-core@0.1.0.1 · 55 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.1/change_tick.bend as Tick
3import inspector_query_projection.bend as Select
4import inspector_query.bend as Query
5import inspector_query_frame_world.bend as Traverse
6import inspector.bend as I
7import world.bend as W
8import relation_types.bend as G
9import relation_commands.bend as A
10import 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.
14def 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>:
15 (world,graph)=observed
16 (I.Frame{world,cursor},graph)
17def 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>:
18 match frame:
19 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))
20def accepted(~S:Data,observed:Bool & RQ.Row<S,Unit>) -> Bool:
21 (selected,row)=observed
22 selected
23def cells(~S:Data,observed:Bool & RQ.Row<S,Unit>) -> List<&2,RQ.Cell<S>>:
24 match observed:
25 case (_,RQ.Row{_,items,_}):items
26def 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:
27 (frame,graph)=observed
28 (frame,accepted(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{})))
29def 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:
30 matched(~S,~C,~R,~E,~spec,target,graph(~S,~C,~R,~E,frame))
31def 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>>:
32 (frame,graph)=observed
33 (frame,cells(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{})))
34def 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>>:
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.
38def 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:
39 (frame,graph)=observed
40 (frame,accepted(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{})))
41def 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:
42 matched_runtime(~S,~C,~R,~E,spec,target,graph(~S,~C,~R,~E,frame))
43def 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>>:
44 (frame,graph)=observed
45 (frame,cells(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{})))
46def 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>>:
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.
50def 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>>>:
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.
54def 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>>>>:
55 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)