import Base import ./feature.bend as F import ./component.bend as C import ./schema_fragments.bend as SF import ./capabilities.bend as Cap # Trusted schema author closes the getter; universal gameplay receives only H. def read(-H:Type,-V:Data,cap:Cap.Read,ctx:H) -> H & C.Access: match cap: case Cap.Read{get}: get(ctx) def provide(~Ctx:Type,~V:Data,~get:Ctx -> Ctx & C.Access,~body:@-H:Type -> Cap.Read -> H -> H & C.Access,ctx:Ctx) -> Ctx & C.Access: body(Ctx,Cap.Read{get},ctx) # Exact repeated descriptors collapse in access scope; conflicts remain validation errors. def scope_keep(~S:Data,present:Bool,item:SF.Entry,rest:List<&2,SF.Entry>) -> List<&2,SF.Entry>: match present: case True{}: rest case False{}: Con{item,rest} def scope_seen(~S:Data,items:List<&2,SF.Entry>,+seen:List<&2,SF.Entry>) -> List<&2,SF.Entry>: match items: case Nil{}: Nil{} case +item <> rest: scope_keep(~S,SF.descriptor_present(~S,seen,item),item,scope_seen(~S,rest,Con{item,seen})) def scope_unique(~S:Data,items:List<&2,SF.Entry>) -> List<&2,SF.Entry>: scope_seen(~S,items,Nil{}) # Authoring boundary: actual declared scope checked before closed construction. def bind_feature(~S:Data,~Owners:Type,~Output:Type,~build:Owners -> Output,definition:F.Definition,required:List<&2,SF.Entry>,owners:Owners) -> SF.Bound: SF.bind_declared(~S,~Owners,~Output,~build,SF.Fragment{scope_unique(~S,F.visibility(~S,F.definition_tree(~S,definition))),owners},required) def write(-H:Type,-C:Type,-V:Data,cap:Cap.Write,ctx:H,value:C) -> H: match cap: case Cap.Write{_,set}: set(ctx,value) def action(-H:Type,cap:Cap.Action,ctx:H) -> H: match cap: case Cap.Action{run}: run(ctx) def provide_action(~Ctx:Type,~run:Ctx -> Ctx,~body:@-H:Type -> Cap.Action -> H -> H,ctx:Ctx) -> Ctx: body(Ctx,Cap.Action{run},ctx)