ordinary_schema.bend
bendvy-ecs-core@0.1.0.3 · 99 lines · 15 definitions
1import Base
2import bendvy-ecs-core@0.1.0.3/decode_data.bend as D
3import bendvy-ecs-core@0.1.0.3/persistence_declaration.bend as Persist
4import bendvy-ecs-core@0.1.0.3/owner_product.bend as Product
5import bendvy-ecs-core@0.1.0.3/ordinary_declaration.bend as Component
6import bendvy-ecs-core@0.1.0.3/column.bend as Col
7import bendvy-ecs-core@0.1.0.3/schema_fragments.bend as Fragment
8
9
10
11
12
13type Schema<-S:Data,-Store:Type,-Resources:Type> is Data:
14 Schema{entries:List<&2,Fragment.Entry<S>>}
15
16
17type Resource<-S:Data,-P:Type> is Data:
18 Resource{key:String}
19
20
21def resource(~S:Data,~P:Type,key:String) -> Resource<S,P>:
22 Resource{key}
23
24def resource_key(~S:Data,~P:Type,value:Resource<S,P>) -> String:
25 match value:
26 case Resource{key}:key
27
28
29
30def component(~S:Data,~P:Type,declaration:Component.Declaration<S,P>) -> Schema<S,Col.Column<S,P>,Unit>:
31 +key=Component.key(~S,~P,declaration)
32 Schema{[Fragment.Entry{Fragment.Component{},key,key}]}
33
34
35def resource_schema(~S:Data,~P:Type,declaration:Resource<S,P>) -> Schema<S,Unit,P>:
36 +key=resource_key(~S,~P,declaration)
37 Schema{[Fragment.Entry{Fragment.Resource{},key,key}]}
38
39def entries(~S:Data,~C:Type,~R:Type,value:Schema<S,C,R>) -> List<&2,Fragment.Entry<S>>:
40 match value:
41 case Schema{entries}:entries
42
43
44
45def product(~S:Data,~LC:Type,~LR:Type,~RC:Type,~RR:Type,left:Schema<S,LC,LR>,right:Schema<S,RC,RR>) -> Schema<S,Product.Owner<LC,RC>,Product.Owner<LR,RR>>:
46 Schema{List.append(&2,Fragment.Entry<S>,entries(~S,~LC,~LR,left),entries(~S,~RC,~RR,right))}
47
48
49
50def validate(~S:Data,~C:Type,~R:Type,value:Schema<S,C,R>) -> Fragment.Validation:
51 Fragment.validate_loop(~S,entries(~S,~C,~R,value),[])
52
53
54
55
56
57def component_plain(~S:Data,~P:Type,~identity:Component.Declaration<S,P>,extension:Persist.Plain<S,P,identity>) -> Schema<S,Col.Column<S,P>,Unit>:
58 +key=Component.key(~S,~P,identity)
59 Schema{[Fragment.Classified{Fragment.Component{},key,key,Fragment.Plain{}}]}
60
61
62
63
64
65def component_transient(~S:Data,~P:Type,~identity:Component.Declaration<S,P>,extension:Persist.Transient<S,P,identity>) -> Schema<S,Col.Column<S,P>,Unit>:
66 +key=Component.key(~S,~P,identity)
67 Schema{[Fragment.Classified{Fragment.Component{},key,key,Fragment.Transient{}}]}
68
69
70
71
72
73def component_constructed(~S:Data,~P:Type,~identity:Component.Declaration<S,P>,~project:P -> P & D.Raw,extension:Persist.Constructed<S,P,identity,project>) -> Schema<S,Col.Column<S,P>,Unit>:
74 +key=Component.key(~S,~P,identity)
75 Schema{[Fragment.Classified{Fragment.Component{},key,key,Fragment.Constructed{}}]}
76
77
78
79
80
81def resource_plain(~S:Data,~P:Type,~identity:Component.Declaration<S,P>,extension:Persist.Plain<S,P,identity>) -> Schema<S,Unit,P>:
82 +key=Component.key(~S,~P,identity)
83 Schema{[Fragment.Classified{Fragment.Resource{},key,key,Fragment.Plain{}}]}
84
85
86
87
88
89def resource_transient(~S:Data,~P:Type,~identity:Component.Declaration<S,P>,extension:Persist.Transient<S,P,identity>) -> Schema<S,Unit,P>:
90 +key=Component.key(~S,~P,identity)
91 Schema{[Fragment.Classified{Fragment.Resource{},key,key,Fragment.Transient{}}]}
92
93
94
95
96
97def resource_constructed(~S:Data,~P:Type,~identity:Component.Declaration<S,P>,~project:P -> P & D.Raw,extension:Persist.Constructed<S,P,identity,project>) -> Schema<S,Unit,P>:
98 +key=Component.key(~S,~P,identity)
99 Schema{[Fragment.Classified{Fragment.Resource{},key,key,Fragment.Constructed{}}]}