snapshot_schema.bend
bendvy-ecs-core@0.1.0.1 · 40 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.1/snapshot_leaf.bend as Leaf
3import bendvy-ecs-core@0.1.0.1/persistence_declaration.bend as Decl
4import bendvy-ecs-core@0.1.0.1/decode_data.bend as D
5import bendvy-ecs-core@0.1.0.1/schema_fragments.bend as Fragment
6import bendvy-ecs-core@0.1.0.1/column.bend as Col
7import bendvy-ecs-core@0.1.0.1/ordinary_declaration.bend as Canonical
8import bendvy-ecs-core@0.1.0.1/owner_product.bend as Product
9import bendvy-ecs-core@0.1.0.1/ordinary_schema.bend as Ordinary
10
11# The same schema factory derives ordinary inventory, physical product and save
12# eligibility/closed traversal. Runtime recipes live in the leaf owners.
13type Schema<-S:Data,-C:Type,-R:Type,-eligible:Bool,-components:U32 -> C -> C & List<&2,D.Field>,-resources:R -> R & List<&2,D.Field>> is Data:
14 Schema{ordinary:Ordinary.Schema<S,C,R>}
15def unit_component(id:U32,value:Unit) -> Unit & List<&2,D.Field>:
16 (value,[])
17def unit_resource(value:Unit) -> Unit & List<&2,D.Field>:
18 (value,[])
19def plain_component_fields(~S:Data,~P:Type,id:U32,value:Col.Column<S,P>) -> Col.Column<S,P> & List<&2,D.Field>:
20 (value,[])
21def entry(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>,kind:Fragment.RegistryKind) -> Fragment.Entry<S>:
22 +key=Canonical.key(~S,~P,identity)
23 Fragment.Entry{kind,key,key}
24def component(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>,~project:P -> P & D.Raw) -> Schema<S,Leaf.Component<S,P,identity,project>,Unit,True{},Leaf.component_fields(~S,~P,~identity,~project),unit_resource>:
25 Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Component{})]}}
26def transient_component(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>) -> Schema<S,Leaf.TransientComponent<S,P,identity>,Unit,True{},Leaf.transient_component_fields(~S,~P,~identity),unit_resource>:
27 Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Component{})]}}
28def plain_component(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>) -> Schema<S,Col.Column<S,P>,Unit,False{},plain_component_fields(~S,~P),unit_resource>:
29 Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Component{})]}}
30def resource(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>,~project:P -> P & D.Raw) -> Schema<S,Unit,Leaf.Resource<S,P,identity,project>,True{},unit_component,Leaf.resource_fields(~S,~P,~identity,~project)>:
31 Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Resource{})]}}
32def transient_resource(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>) -> Schema<S,Unit,Leaf.TransientResource<S,P,identity>,True{},unit_component,Leaf.transient_resource_fields(~S,~P,~identity)>:
33 Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Resource{})]}}
34def plain_resource_fields(~P:Type,value:P) -> P & List<&2,D.Field>:
35 (value,[])
36def plain_resource(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>) -> Schema<S,Unit,P,False{},unit_component,plain_resource_fields(~P)>:
37 Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Resource{})]}}
38def inventory(~S:Data,~C:Type,~R:Type,~eligible:Bool,~components:U32 -> C -> C & List<&2,D.Field>,~resources:R -> R & List<&2,D.Field>,schema:Schema<S,C,R,eligible,components,resources>) -> Ordinary.Schema<S,C,R>:
39 match schema:
40 case Schema{ordinary}:ordinary