ordinary_app_schema.bend

bendvy-ecs-core@0.1.0.0 · 43 lines · 0 definitions

1import Base
2import bendvy-ecs-core@0.1.0.0/world.bend as W
3import bendvy-ecs-core@0.1.0.0/ordinary_schema.bend as Schema
4import bendvy-ecs-core@0.1.0.0/schema_fragments.bend as Fragment
5import bendvy-ecs-core@0.1.0.0/ordinary_app_composer.bend as Build
6import bendvy-ecs-core@0.1.0.0/ordinary_app_registration_fields.bend as Records
7import bendvy-ecs-core@0.1.0.0/ordinary_app_observation_data.bend as DTO
8# Retain the ordinary schema itself, never an extra debug declaration.
9# Schema-scoped App retaining the ordinary schema and registered owner
10# collection. Construct via attached; raw fields remain trusted setup and
11# cannot replace runtime namespace/registration validation.
12type Application<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>>> is Type:
13  Application{schema:Schema.Schema<S,C,R>,app:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,observe,fold>}
14# Detached ordinary schema entries and registered application observations.
15# This enabled-debug view contains no live owners and is not a restorable
16# runtime checkpoint or a replacement for typed registration authority.
17type Description<S:Data,Rows:Data> is Data:
18  Description{schema:List<&2,Fragment.Entry<S>>,registered:DTO.Product<List<&2,DTO.Binding<S>>,DTO.Observation<Rows>>}
19# Pair a matching schema with registered World/system owners. Does not
20# validate raw metadata/storage consistency, execute systems or build a schedule.
21def attached(~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>>,schema:Schema.Schema<S,C,R>,app:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,observe,fold>) -> Application<S,C,R,E,Owners,Rows,observe,fold>:
22  Application{schema,app}
23# Toggle declaration-derived debug observation, returning the retained App.
24# Does not immediately invoke folds or World projections.
25def enabled(~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>>,value:Application<S,C,R,E,Owners,Rows,observe,fold>,flag:Bool) -> Application<S,C,R,E,Owners,Rows,observe,fold>:
26  match value:
27    case Application{schema,app}:Application{schema,Build.enabled(~S,~W.World<S,C,R,E>,~Owners,~Rows,~observe,~fold,app,flag)}
28def observed(~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>>,+schema:Schema.Schema<S,C,R>,result:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,observe,fold> & Maybe<&2,DTO.Product<List<&2,DTO.Binding<S>>,DTO.Observation<Rows>>>) -> Application<S,C,R,E,Owners,Rows,observe,fold> & Maybe<&2,Description<S,Rows>>:
29  match result:
30    case (app,None{}):(Application{schema,app},None{})
31    case (app,Some{view}):(Application{schema,app},Some{Description{Schema.entries(~S,~C,~R,schema),view}})
32# Return App and Some schema/registration observation when enabled, or
33# None when disabled. Uses existing owner-threading folds/projections; does not
34# run systems or consume their reader cursors. Not a restorable World save.
35def snapshot(~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>>,value:Application<S,C,R,E,Owners,Rows,observe,fold>) -> Application<S,C,R,E,Owners,Rows,observe,fold> & Maybe<&2,Description<S,Rows>>:
36  match value:
37    case Application{schema,app}:observed(~S,~C,~R,~E,~Owners,~Rows,~observe,~fold,schema,Build.snapshot(~S,~W.World<S,C,R,E>,~Owners,~Rows,~observe,~fold,app))
38# Schema is part of ordinary typed setup; World factory/refusal contracts unchanged.
39# Trusted factory-based World creation returning schema and Creation.
40# Actual empty storage comes from the supplied callback; refusal retains the
41# caller resource owner. Prefer world-io.create for independent IO namespaces.
42def create(~S:Data,~C:Type,~R:Type,~E:Data,~empty:Unit -> C,schema:Schema.Schema<S,C,R>,factory:W.Factory,resource:R) -> Schema.Schema<S,C,R> & W.Creation<S,C,R,E>:
43  (schema,W.create(~S,~C,~R,~E,~empty,factory,resource))