ordinary_check_relation.bend
bendvy-ecs-core@0.1.0.1 · 39 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.1/ordinary_check_declaration.bend as D
3import bendvy-ecs-core@0.1.0.1/ordinary_inspector_relation.bend as Decl
4import bendvy-ecs-core@0.1.0.1/ordinary_check_query.bend as CQ
5import bendvy-ecs-core@0.1.0.1/relation_types.bend as G
6import bendvy-ecs-core@0.1.0.1/relation_query.bend as RQ
7import bendvy-ecs-core@0.1.0.1/relation_commands.bend as A
8import bendvy-ecs-core@0.1.0.1/check.bend as K
9import bendvy-ecs-core@0.1.0.1/inspector_query.bend as Query
10import bendvy-ecs-core@0.1.0.1/inspector_query_projection.bend as Select
11
12# All metadata comes from the same closed operational declaration.
13def kind(value:G.RelationKind) -> D.RelationKind:
14 match value:
15 case G.Ordinary{}:D.Ordinary{}
16 case G.Hierarchy{}:D.Hierarchy{}
17def identity(~S:Data,value:G.Descriptor<S>) -> D.RelationIdentity:
18 match value:
19 case G.Descriptor{id,name,inverseName,relationKind}:D.RelationIdentity{id,name,inverseName,kind(relationKind)}
20def category(value:D.RelationIdentity,mode:Decl.Mode) -> D.Category:
21 match mode:
22 case Decl.RequiredOut{key}:D.Relation{value,D.Outgoing{},D.RelationRequired{},Some{key}}
23 case Decl.OptionalOut{key}:D.Relation{value,D.Outgoing{},D.RelationOptional{},Some{key}}
24 case Decl.PresentOut{}:D.Relation{value,D.Outgoing{},D.RelationPresent{},None{}}
25 case Decl.AbsentOut{}:D.Relation{value,D.Outgoing{},D.RelationAbsent{},None{}}
26 case Decl.RequiredIn{key}:D.Relation{value,D.Incoming{},D.RelationRequired{},Some{key}}
27 case Decl.OptionalIn{key}:D.Relation{value,D.Incoming{},D.RelationOptional{},Some{key}}
28 case Decl.PresentIn{}:D.Relation{value,D.Incoming{},D.RelationPresent{},None{}}
29 case Decl.AbsentIn{}:D.Relation{value,D.Incoming{},D.RelationAbsent{},None{}}
30def use_named(value:D.RelationIdentity,mode:Decl.Mode) -> D.Use:
31 match value:
32 case D.RelationIdentity{id,+name,inverseName,kind}:D.Use{category(D.RelationIdentity{id,name,inverseName,kind},mode),name,D.Read{},False{}}
33def use(~S:Data,value:Decl.Declaration<S>) -> D.Use:
34 match value:
35 case Decl.Declaration{source,mode}:use_named(identity(~S,Decl.descriptor(~S,source)),mode)
36# Structural graph storage is already present in A.Store. No extra World-owned
37# parameter is admitted here; required relation clauses retain row membership.
38def declaration(~S:Data,~C:Type,~R:Type,~E:Data,~V:Data,~component:CQ.Selection<K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,S,V>,~relation:Decl.Declaration<S>) -> D.Declaration<S,A.Store<S,C>,R,A.Notice<S,E>,CQ.Ops(~S,~Select.Product<V,List<&2,RQ.Cell<S>>>)>:
39 D.Declaration{K.Plan{D.provided(~S,~A.Store<S,C>,~R,~A.Notice<S,E>),CQ.Read{Decl.condition(~S,~C,~R,~E,~V,~CQ.selected(~K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,~S,~V,component),~relation)}},List.append(&2,D.Use,CQ.uses(~K.Frame<S,A.Store<S,C>,R,A.Notice<S,E>>,~S,~V,component),[use(~S,relation)])}