import Base import ./world.bend as W import ./check.bend as K import ./capabilities.bend as Cap import ./ordinary_schema.bend as Schema import ./ordinary_optional_resource.bend as O import ./optional_resource_binding.bend as B import ./owner_product.bend as Product # Metadata belongs to the same operational read; no caller-authored access list. type ComponentSelection is Data: Required{} Optional{} With{} Without{} type RelationKind is Data: Ordinary{} Hierarchy{} type RelationDirection is Data: Outgoing{} Incoming{} type RelationSelection is Data: RelationRequired{} RelationOptional{} RelationPresent{} RelationAbsent{} type RelationIdentity is Data: RelationIdentity{id:U32,name:String,inverseName:String,kind:RelationKind} type Category is Data: Resource{} Component{selection:ComponentSelection} Machine{} Relation{identity:RelationIdentity,direction:RelationDirection,selection:RelationSelection,cellKey:Maybe<&2,String>} type Mode is Data:Read{} type Use is Data:Use{category:Category,key:String,mode:Mode,required:Bool} type Declaration<-S:Data,-C:Type,-R:Type,-E:Data,-Ops:Type -> Type> is Type: Declaration{plan:K.Plan,uses:List<&2,Use>} type ResourceRead<-S:Data,-P:Type,-identity:Schema.Resource,-H:Type,-V:Data> is Type: ResourceRead{read:Cap.ValueRead>} def Ops(~S:Data,~P:Type,~identity:Schema.Resource,~V:Data,H:Type) -> Type:ResourceRead def read_field(~S:Data,~P:Type,~identity:Schema.Resource,~H:Type,~V:Data,value:ResourceRead) -> H -> H & Maybe<&2,V>: match value: case ResourceRead{read}:Cap.value_read_field(~H,~Maybe<&2,V>,read) def read(~S:Data,~P:Type,~identity:Schema.Resource,~H:Type,~V:Data,~value:ResourceRead,owner:H) -> H & Maybe<&2,V>: read_field(~S,~P,~identity,~H,~V,value)(owner) def provided(~S:Data,~C:Type,~R:Type,~E:Data,world:W.World) -> W.World & List<&2,String>:(world,[]) def optional_resource(~S:Data,~C:Type,~R:Type,~E:Data,~P:Type,~Rest:Type,~V:Data,~identity:Schema.Resource,~lens:Product.Lens,Rest>,~binding:B.Binding,~view:P -> P & V) -> Declaration: Declaration{K.Plan{provided(~S,~C,~R,~E),ResourceRead{O.condition(~S,~C,~R,~E,~P,~Rest,~V,~identity,~lens,~view,~O.Declaration{})}},[Use{Resource{},Schema.resource_key(~S,~P,identity),Read{},False{}}]} def required_resource(~S:Data,~C:Type,~R:Type,~E:Data,~P:Type,~Rest:Type,~V:Data,~identity:Schema.Resource,~lens:Product.Lens,Rest>,~binding:B.Binding,~view:P -> P & V) -> Declaration: Declaration{K.Plan{O.required(~S,~C,~R,~E,~P,~Rest,~V,~identity,~lens,~view,~O.Declaration{}),ResourceRead{O.condition(~S,~C,~R,~E,~P,~Rest,~V,~identity,~lens,~view,~O.Declaration{})}},[Use{Resource{},Schema.resource_key(~S,~P,identity),Read{},True{}}]} def plan(~S:Data,~C:Type,~R:Type,~E:Data,~Ops:Type -> Type,value:Declaration) -> K.Plan: match value: case Declaration{plan,_}:plan def uses(~S:Data,~C:Type,~R:Type,~E:Data,~Ops:Type -> Type,value:Declaration) -> List<&2,Use>: match value: case Declaration{_,uses}:uses # A single reached predicate may request several declared reads. Validation # threads the original World in authored order and retains each returned name. def PairOps(~L:Type -> Type,~R:Type -> Type,H:Type) -> Type:Cap.Bundle def required_join(~S:Data,~C:Type,~R:Type,~E:Data,before:List<&2,String>,observed:W.World & List<&2,String>) -> W.World & List<&2,String>: match observed: case (world,after):(world,List.append(&2,String,before,after)) def required_right(~S:Data,~C:Type,~R:Type,~E:Data,~right:W.World -> W.World & List<&2,String>,observed:W.World & List<&2,String>) -> W.World & List<&2,String>: match observed: case (world,before):required_join(~S,~C,~R,~E,before,right(world)) def required_pair(~S:Data,~C:Type,~R:Type,~E:Data,~left:W.World -> W.World & List<&2,String>,~right:W.World -> W.World & List<&2,String>,world:W.World) -> W.World & List<&2,String>:required_right(~S,~C,~R,~E,~right,left(world)) def both(~S:Data,~C:Type,~R:Type,~E:Data,~LOps:Type -> Type,~ROps:Type -> Type,~left:Declaration,~right:Declaration) -> Declaration: Declaration{K.Plan{required_pair(~S,~C,~R,~E,~K.required_field(~S,~C,~R,~E,~LOps,plan(~S,~C,~R,~E,~LOps,left)),~K.required_field(~S,~C,~R,~E,~ROps,plan(~S,~C,~R,~E,~ROps,right))),Cap.Bundle{K.caps_field(~S,~C,~R,~E,~LOps,plan(~S,~C,~R,~E,~LOps,left)),K.caps_field(~S,~C,~R,~E,~ROps,plan(~S,~C,~R,~E,~ROps,right))}},List.append(&2,Use,uses(~S,~C,~R,~E,~LOps,left),uses(~S,~C,~R,~E,~ROps,right))}