ordinary_app_schedule_access.bend

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

1import Base
2import bendvy-ecs-core@0.1.0.1/world.bend as W
3import bendvy-ecs-core@0.1.0.1/ordinary_app_schedule.bend as Schedule
4import bendvy-ecs-core@0.1.0.1/ordinary_app_schema.bend as SchemaApp
5import bendvy-ecs-core@0.1.0.1/ordinary_app_composer.bend as Build
6import bendvy-ecs-core@0.1.0.1/ordinary_schema.bend as Schema
7import bendvy-ecs-core@0.1.0.1/ordinary_app_recipe.bend as Tree
8import bendvy-ecs-core@0.1.0.1/ordinary_app_observation_data.bend as DTO
9import bendvy-ecs-core@0.1.0.1/ordinary_app_registration_fields.bend as Fields
10import bendvy-ecs-core@0.1.0.1/ordinary_app_access.bend as Access
11import bendvy-ecs-core@0.1.0.1/schedule.bend as Sch
12import bendvy-ecs-core@0.1.0.1/schedule_provision.bend as SP
13# Retained operational Plan selects actual registry identity; no parallel catalog.
14# Detached grouped declared accesses for the retained schedule's actual
15# namespace/name. This is a diagnostic index, not a runtime grant or payload view.
16type Index is Data:
17  Index{namespace:U32,name:String,entries:List<&2,Access.Entry>}
18def selected(~S:Data,found:Bool,record:Fields.Fields<S>,rest:List<&2,Fields.Fields<S>>) -> List<&2,Fields.Fields<S>>:
19  match found:
20    case True{}:record <> rest
21    case False{}:rest
22def identified(~S:Data,namespace:U32,id:U32,+record:Fields.Fields<S>,rest:List<&2,Fields.Fields<S>>) -> List<&2,Fields.Fields<S>>:
23  match record:
24    case Fields.Fields{otherNamespace,otherId,_,_,_,_,_,_}:selected(~S,Bool.and(U32.is_eq(namespace,otherNamespace),U32.is_eq(id,otherId)),record,rest)
25def matching(~S:Data,+namespace:U32,+id:U32,records:List<&2,Fields.Fields<S>>) -> List<&2,Fields.Fields<S>>:
26  match records:
27    case []:[]
28    case +record <> rest:identified(~S,namespace,id,record,matching(~S,namespace,id,rest))
29def step(~S:Data,namespace:U32,records:List<&2,Fields.Fields<S>>,planned:Schedule.PlannedStep<S>) -> List<&2,Fields.Fields<S>>:
30  match planned:
31    case Schedule.PlannedStep{Sch.System{id,_},_}:matching(~S,namespace,id,records)
32    case _ :[]
33# Advanced metadata selector: keep registration fields matching each System
34# placement's exact namespace/id in step order; phase/barrier entries add no fields.
35# No unmatched registration is invented and no capability is derived from strings.
36def placed(~S:Data,steps:List<&2,Schedule.PlannedStep<S>>,+namespace:U32,+records:List<&2,Fields.Fields<S>>) -> List<&2,Fields.Fields<S>>:
37  match steps:
38    case []:[]
39    case first <> rest:List.append(&2,Fields.Fields<S>,step(~S,namespace,records,first),placed(~S,rest,namespace,records))
40def folded(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Fields.Fields<S>>,schema:Schema.Schema<S,C,R>,world:W.World<S,C,R,E>,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,+plan:SP.Plan<S>,+namespace:U32,+name:String,steps:List<&2,Sch.Step>,needs:List<&2,SP.Requirement<S>>,result:H & List<&2,Fields.Fields<S>>) -> Schedule.Application<S,C,R,E,H,Rows,observe,fold> & Maybe<&2,Index>:
41  match result:
42    case (owners,records):(Schedule.Application{SchemaApp.Application{schema,Build.Registered{world,owners,recipe,True{}}},plan,namespace,name,steps,needs},Some{Index{namespace,name,Access.grouped(Access.fields(~S,placed(~S,Schedule.planned(~S,plan),namespace,records)),[])}})
43# Return the same scheduled App and optional grouped declared-access index.
44# Disabled returns None before folding owners; enabled selects fields using the
45# retained operational plan. Does not run systems, inspect payloads, advance
46# readers or apply pending commands; arbitrary fold adapters remain trusted.
47def index(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Fields.Fields<S>>,value:Schedule.Application<S,C,R,E,H,Rows,observe,fold>) -> Schedule.Application<S,C,R,E,H,Rows,observe,fold> & Maybe<&2,Index>:
48  match value:
49    case Schedule.Application{SchemaApp.Application{schema,Build.Registered{world,owners,recipe,False{}}},plan,namespace,name,steps,needs}:(Schedule.Application{SchemaApp.Application{schema,Build.Registered{world,owners,recipe,False{}}},plan,namespace,name,steps,needs},None{})
50    case Schedule.Application{SchemaApp.Application{schema,Build.Registered{world,owners,recipe,True{}}},plan,namespace,name,steps,needs}:folded(~S,~C,~R,~E,~H,~Rows,~observe,~fold,schema,world,recipe,plan,namespace,name,steps,needs,fold(owners))