check_relation_projection.bend
bendvy-ecs-core@0.1.0.1 · 54 lines · 0 definitions
1import Base
2import inspector_query_projection.bend as Select
3import inspector_query.bend as Query
4import inspector_query_frame_world.bend as Traverse
5import check.bend as K
6import world.bend as W
7import relation_types.bend as G
8import relation_commands.bend as A
9import 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.
13def graph_joined(~S:Data,~C:Type,~R:Type,~E:Data,observed:W.World<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>) -> K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>:
14 (world,graph)=observed
15 (K.Frame{world},graph)
16def graph(~S:Data,~C:Type,~R:Type,~E:Data,frame:K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>) -> K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>:
17 match frame:
18 case K.Frame{world}:graph_joined(~S,~C,~R,~E,W.with_store(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~G.Graph<S>,RQ.graph_read(~S,~C),world))
19def accepted(~S:Data,observed:Bool & RQ.Row<S,Unit>) -> Bool:
20 (selected,row)=observed
21 selected
22def cells(~S:Data,observed:Bool & RQ.Row<S,Unit>) -> List<&2,RQ.Cell<S>>:
23 match observed:
24 case (_,RQ.Row{_,items,_}):items
25def matched(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec<S>,target:W.Handle<S>,observed:K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>) -> K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & Bool:
26 (frame,graph)=observed
27 (frame,accepted(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{})))
28def matches(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec<S>,frame:K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,target:W.Handle<S>) -> K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & Bool:
29 matched(~S,~C,~R,~E,~spec,target,graph(~S,~C,~R,~E,frame))
30def projected(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec<S>,target:W.Handle<S>,observed:K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>) -> K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & List<&2,RQ.Cell<S>>:
31 (frame,graph)=observed
32 (frame,cells(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{})))
33def project(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec<S>,frame:K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,target:W.Handle<S>) -> K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & List<&2,RQ.Cell<S>>:
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.
37def matched_runtime(~S:Data,~C:Type,~R:Type,~E:Data,spec:RQ.Spec<S>,target:W.Handle<S>,observed:K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>) -> K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & Bool:
38 (frame,graph)=observed
39 (frame,accepted(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{})))
40def matches_runtime(~S:Data,~C:Type,~R:Type,~E:Data,spec:RQ.Spec<S>,frame:K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,target:W.Handle<S>) -> K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & Bool:
41 matched_runtime(~S,~C,~R,~E,spec,target,graph(~S,~C,~R,~E,frame))
42def projected_runtime(~S:Data,~C:Type,~R:Type,~E:Data,spec:RQ.Spec<S>,target:W.Handle<S>,observed:K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & G.Graph<S>) -> K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & List<&2,RQ.Cell<S>>:
43 (frame,graph)=observed
44 (frame,cells(~S,RQ.spec_rows(~S,~Unit,spec,graph,target,Unit{})))
45def project_runtime(~S:Data,~C:Type,~R:Type,~E:Data,spec:RQ.Spec<S>,frame:K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,target:W.Handle<S>) -> K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>> & List<&2,RQ.Cell<S>>:
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.
49def relations(~S:Data,~C:Type,~R:Type,~E:Data,~spec:RQ.Spec<S>) -> Select.DeclaredSelection<K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,S,List<&2,RQ.Cell<S>>>:
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.
53def grant(~S:Data,~C:Type,~R:Type,~E:Data,~V:Data,~component:Select.DeclaredSelection<K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,S,V>,~spec:RQ.Spec<S>) -> Query.ComposedReadQuery<K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,S,Select.Product<V,List<&2,RQ.Cell<S>>>>:
54 Query.grant_composed_runtime(~K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,~S,~V,~List<&2,RQ.Cell<S>>,~RQ.Spec<S>,~component,~Traverse.check_world(~S,~A.Store<S,C>,~R,~A.Notice<S,E>),~matches_runtime(~S,~C,~R,~E),~project_runtime(~S,~C,~R,~E),spec)