import Base import ./snapshot_leaf.bend as Leaf import ./persistence_declaration.bend as Decl import ./decode_data.bend as D import ./schema_fragments.bend as Fragment import ./column.bend as Col import ./ordinary_declaration.bend as Canonical import ./owner_product.bend as Product import ./ordinary_schema.bend as Ordinary # The same schema factory derives ordinary inventory, physical product and save # eligibility/closed traversal. Runtime recipes live in the leaf owners. type 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: Schema{ordinary:Ordinary.Schema} def unit_component(id:U32,value:Unit) -> Unit & List<&2,D.Field>: (value,[]) def unit_resource(value:Unit) -> Unit & List<&2,D.Field>: (value,[]) def plain_component_fields(~S:Data,~P:Type,id:U32,value:Col.Column) -> Col.Column & List<&2,D.Field>: (value,[]) def entry(~S:Data,~P:Type,~identity:Canonical.Declaration,kind:Fragment.RegistryKind) -> Fragment.Entry: +key=Canonical.key(~S,~P,identity) Fragment.Entry{kind,key,key} def component(~S:Data,~P:Type,~identity:Canonical.Declaration,~project:P -> P & D.Raw) -> Schema,Unit,True{},Leaf.component_fields(~S,~P,~identity,~project),unit_resource>: Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Component{})]}} def transient_component(~S:Data,~P:Type,~identity:Canonical.Declaration) -> Schema,Unit,True{},Leaf.transient_component_fields(~S,~P,~identity),unit_resource>: Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Component{})]}} def plain_component(~S:Data,~P:Type,~identity:Canonical.Declaration) -> Schema,Unit,False{},plain_component_fields(~S,~P),unit_resource>: Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Component{})]}} def resource(~S:Data,~P:Type,~identity:Canonical.Declaration,~project:P -> P & D.Raw) -> Schema,True{},unit_component,Leaf.resource_fields(~S,~P,~identity,~project)>: Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Resource{})]}} def transient_resource(~S:Data,~P:Type,~identity:Canonical.Declaration) -> Schema,True{},unit_component,Leaf.transient_resource_fields(~S,~P,~identity)>: Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Resource{})]}} def plain_resource_fields(~P:Type,value:P) -> P & List<&2,D.Field>: (value,[]) def plain_resource(~S:Data,~P:Type,~identity:Canonical.Declaration) -> Schema: Schema{Ordinary.Schema{[entry(~S,~P,~identity,Fragment.Resource{})]}} def 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) -> Ordinary.Schema: match schema: case Schema{ordinary}:ordinary