ordinary_app_resource_field.bend

bendvy-ecs-core@0.1.0.1 · 33 lines · 0 definitions

1import Base
2import bendvy-ecs-core@0.1.0.1/ordinary_query_declaration.bend as Query
3import bendvy-ecs-core@0.1.0.1/ordinary_app_composer.bend as Build
4import bendvy-ecs-core@0.1.0.1/ordinary_app_registration_fields.bend as Records
5import bendvy-ecs-core@0.1.0.1/ordinary_app_records.bend as Leaf
6import bendvy-ecs-core@0.1.0.1/ordinary_app_recipe.bend as Tree
7import bendvy-ecs-core@0.1.0.1/ordinary_app_resource_field_observation.bend as Leaves
8import bendvy-ecs-core@0.1.0.1/world.bend as W
9import bendvy-ecs-core@0.1.0.1/system.bend as Sys
10import bendvy-ecs-core@0.1.0.1/transaction.bend as T
11import bendvy-ecs-core@0.1.0.1/ordinary_resource_field_system.bend as P
12import bendvy-ecs-core@0.1.0.1/ordinary_app_resource_field_declaration.bend as D
13import bendvy-ecs-core@0.1.0.1/ordinary_app_observation_data.bend as DTO
14
15def field_owner(~S:Data,~C:Type,~R:Type,~E:Data,~Args:Type,~Error:Data,~Out:Type,~runner:W.World<S,C,R,E> -> Args -> Sys.Outcome<W.World<S,C,R,E>,Error,Out>,~clauses:List<&2,Query.Clause<S>>,slot:String,owner:P.Owner<S,Sys.Registry<S,C,R,E,Args,Error,Out,runner>,clauses>) -> Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,runner>> & Records.Fields<S>:
16  match owner:
17    case P.Owner{registry}:Records.field_registry(~S,~C,~R,~E,~Args,~Error,~Out,~runner,slot,clauses,registry)
18
19# The same ordinary resource declaration drives registration, observation and metadata.
20def extracted(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,~Ops:Type -> Type,~Args:Type,~Error:Data,~Out:Type,~Value:Data,~declaration:D.Declaration<S,C,R,E,Ops,Value>,~body:@-H:Type -> @-caps:Ops(H) -> Args -> H -> H & (T.Outcome<Error> & Out),~Output:Type,done:Build.Registered<S,W.World<S,C,R,E>,Owners & Leaf.Record<S,Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>>,DTO.Product<Rows,Value>,Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~Value,~observe,~Leaves.resource_observe(~S,~C,~R,~E,~Ops,~Value,~declaration)),Leaf.fold_pair(~S,~Owners,~Leaf.Record<S,Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>>,~fold,~Leaf.observed(~S,~Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>))> -> Output,failed:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,observe,fold> -> Output,world:W.World<S,C,R,E>,owners:Owners,debug:Bool,result:Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>> & Records.Fields<S>) -> Output:
21  match result:
22    case (token,fields):done(Build.appended(~S,~W.World<S,C,R,E>,~Owners,~Rows,~observe,~fold,~Leaf.Record<S,Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>>,~Value,~Leaves.resource_observe(~S,~C,~R,~E,~Ops,~Value,~declaration),~Leaf.observed(~S,~Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>),world,owners,Leaf.Record{token,fields},debug))
23def defined(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,~Ops:Type -> Type,~Args:Type,~Error:Data,~Out:Type,~Value:Data,~declaration:D.Declaration<S,C,R,E,Ops,Value>,~body:@-H:Type -> @-caps:Ops(H) -> Args -> H -> H & (T.Outcome<Error> & Out),~Output:Type,done:Build.Registered<S,W.World<S,C,R,E>,Owners & Leaf.Record<S,Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>>,DTO.Product<Rows,Value>,Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~Value,~observe,~Leaves.resource_observe(~S,~C,~R,~E,~Ops,~Value,~declaration)),Leaf.fold_pair(~S,~Owners,~Leaf.Record<S,Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>>,~fold,~Leaf.observed(~S,~Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>))> -> Output,failed:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,observe,fold> -> Output,owners:Owners,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,debug:Bool,slot:String,result:P.Defined<S,W.World<S,C,R,E>,Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>,P.clauses(~S,~T.Tx<W.World<S,C,R,E>,E>,~Ops(T.Tx<W.World<S,C,R,E>,E>),D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration))>) -> Output:
24  match result:
25    case P.Rejected{world}:failed(Build.Registered{world,owners,recipe,debug})
26    case P.Defined{world,owner}:extracted(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,~Ops,~Args,~Error,~Out,~Value,~declaration,~body,~Output,done,failed,world,owners,debug,field_owner(~S,~C,~R,~E,~Args,~Error,~Out,~P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body),~P.clauses(~S,~T.Tx<W.World<S,C,R,E>,E>,~Ops(T.Tx<W.World<S,C,R,E>,E>),D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration)),slot,owner))
27# Add a selected-resource-field system, deriving access and inspection
28# from the same declaration/binding. done receives extended registration owners;
29# failed returns the prior App shape with World/owners retained. Does not run
30# body or replace a field at registration. Raw schema lenses remain trusted.
31def register(~S:Data,~C:Type,~R:Type,~E:Data,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,~Ops:Type -> Type,~Args:Type,~Error:Data,~Out:Type,~Value:Data,~declaration:D.Declaration<S,C,R,E,Ops,Value>,~body:@-H:Type -> @-caps:Ops(H) -> Args -> H -> H & (T.Outcome<Error> & Out),~Output:Type,done:Build.Registered<S,W.World<S,C,R,E>,Owners & Leaf.Record<S,Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>>,DTO.Product<Rows,Value>,Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~Value,~observe,~Leaves.resource_observe(~S,~C,~R,~E,~Ops,~Value,~declaration)),Leaf.fold_pair(~S,~Owners,~Leaf.Record<S,Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>>,~fold,~Leaf.observed(~S,~Records.Token<Sys.Registry<S,C,R,E,Args,Error,Out,P.runner(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body)>>))> -> Output,failed:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,observe,fold> -> Output,app:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,observe,fold>,name:String,slot:String) -> Output:
32  match app:
33    case Build.Registered{world,owners,recipe,debug}:defined(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,~Ops,~Args,~Error,~Out,~Value,~declaration,~body,~Output,done,failed,owners,recipe,debug,slot,P.define(~S,~C,~R,~E,~Ops,~Args,~Error,~Out,~D.ordinary(~S,~C,~R,~E,~Ops,~Value,declaration),~body,world,name))