ordinary_app_event_family_runtime.bend
bendvy-ecs-core@0.1.0.1 · 56 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.1/ordinary_event_family.bend as Family
3import bendvy-ecs-core@0.1.0.1/event_family_runtime.bend as FamilyRuntime
4import bendvy-ecs-core@0.1.0.1/world.bend as W
5import bendvy-ecs-core@0.1.0.1/ordinary_schema.bend as Schema
6import bendvy-ecs-core@0.1.0.1/ordinary_app_schema.bend as SchemaApp
7import bendvy-ecs-core@0.1.0.1/ordinary_app_composer.bend as Build
8import bendvy-ecs-core@0.1.0.1/ordinary_app_recipe.bend as Tree
9import bendvy-ecs-core@0.1.0.1/ordinary_app_registration_fields.bend as Records
10import bendvy-ecs-core@0.1.0.1/ordinary_app_observation_data.bend as DTO
11import bendvy-ecs-core@0.1.0.1/event_family_routing.bend as Route
12# Family is retained opaquely, including actual streams, journal and reader owners.
13# Debug round-trips the sole World without synchronization, trim, frame or dispatch.
14# Ordinary schema App with one actual family runtime, World and registration
15# owners. F may contain affine streams/reader state; this wrapper does not clone
16# that state or expose it through detached observation rows.
17type Application<S:Data,C:Type,R:Type,P:Data,F:Type,Owners:Type,Rows:Data,-observe:W.World<S,C,R,P> -> W.World<S,C,R,P> & DTO.Observation<Rows>,-fold:Owners -> Owners & List<&2,Records.Fields<S>>> is Type:
18 Application{schema:Schema.Schema<S,C,R>,runtime:Route.Runtime<S,C,R,P,F>,owners:Owners,recipe:Tree.Recipe<W.World<S,C,R,P>,Rows,observe>,debug:Bool}
19# Advanced attachment of an existing runtime family and tick to a schema App.
20# Retains World/owners/recipe/debug without synchronization or frame advancement.
21def attached(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,P> -> W.World<S,C,R,P> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,family:F,tick:Nat,value:SchemaApp.Application<S,C,R,P,Owners,Rows,observe,fold>) -> Application<S,C,R,P,F,Owners,Rows,observe,fold>:
22 match value:
23 case SchemaApp.Application{schema,Build.Registered{world,owners,recipe,debug}}:Application{schema,Route.Runtime{world,family,tick},owners,recipe,debug}
24def returned(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,P> -> W.World<S,C,R,P> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,~Out:Type,family:F,tick:Nat,result:SchemaApp.Application<S,C,R,P,Owners,Rows,observe,fold> & Out) -> Application<S,C,R,P,F,Owners,Rows,observe,fold> & Out:
25 match result:
26 case (SchemaApp.Application{schema,Build.Registered{world,owners,recipe,debug}},output):(Application{schema,Route.Runtime{world,family,tick},owners,recipe,debug},output)
27# Advanced adapter temporarily exposing the schema App to an owner-returning
28# action while retaining family state and tick. It does not automatically sync
29# publications or repair arbitrary action effects; action is trusted integration.
30def with_previous(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,P> -> W.World<S,C,R,P> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,~Out:Type,action:SchemaApp.Application<S,C,R,P,Owners,Rows,observe,fold> -> SchemaApp.Application<S,C,R,P,Owners,Rows,observe,fold> & Out,value:Application<S,C,R,P,F,Owners,Rows,observe,fold>) -> Application<S,C,R,P,F,Owners,Rows,observe,fold> & Out:
31 match value:
32 case Application{schema,Route.Runtime{world,family,tick},owners,recipe,debug}:returned(~S,~C,~R,~P,~F,~Owners,~Rows,~observe,~fold,~Out,family,tick,action(SchemaApp.Application{schema,Build.Registered{world,owners,recipe,debug}}))
33# Return the App with its ordinary schema description, preserving family and tick.
34# Disabled observation bypasses fold/observe in SchemaApp.snapshot. No reader
35# acknowledgement, trim, synchronization, dispatch or structural barrier is added.
36def snapshot(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,P> -> W.World<S,C,R,P> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,value:Application<S,C,R,P,F,Owners,Rows,observe,fold>) -> Application<S,C,R,P,F,Owners,Rows,observe,fold> & Maybe<&2,SchemaApp.Description<S,Rows>>:
37 with_previous(~S,~C,~R,~P,~F,~Owners,~Rows,~observe,~fold,~Maybe<&2,SchemaApp.Description<S,Rows>>,SchemaApp.snapshot(~S,~C,~R,~P,~Owners,~Rows,~observe,~fold),value)
38# Initialize the supplied canonical family provision with capacity and actual event
39# owners, retaining the schema App World/registrations/observer/debug. This starts
40# family storage/journal state; it does not register or execute gameplay readers.
41def start(~S:Data,~C:Type,~R:Type,~P:Data,~Domains:Data,~Leaves:Type,~EventOwners:Type,~make:Domains -> Nat -> Leaves,~sync:Leaves -> Nat -> List<&2,P> -> Leaves,~frame:Leaves -> Nat -> Leaves,~retain:Leaves -> Nat -> List<&2,P> -> Leaves & List<&2,P>,~inventory:Leaves -> Leaves & List<&2,String>,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,P> -> W.World<S,C,R,P> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,provision:Family.Provision<S,P,Domains,Leaves,make,sync,frame,retain,inventory>,events:EventOwners,capacity:Nat,value:SchemaApp.Application<S,C,R,P,Owners,Rows,observe,fold>) -> Application<S,C,R,P,FamilyRuntime.State<P,Leaves,EventOwners>,Owners,Rows,observe,fold>:
42 match value:
43 case SchemaApp.Application{schema,Build.Registered{world,owners,recipe,debug}}:Application{schema,FamilyRuntime.setup(~S,~C,~R,~P,~Domains,~Leaves,~EventOwners,~make,~sync,~frame,~retain,~inventory,world,provision,events,capacity),owners,recipe,debug}
44# Set only App observation enablement, retaining runtime and all actual owners.
45def enabled(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,P> -> W.World<S,C,R,P> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,value:Application<S,C,R,P,F,Owners,Rows,observe,fold>,flag:Bool) -> Application<S,C,R,P,F,Owners,Rows,observe,fold>:
46 match value:
47 case Application{schema,runtime,owners,recipe,_}:Application{schema,runtime,owners,recipe,flag}
48def inventory_returned(~S:Data,~C:Type,~R:Type,~P:Data,~Leaves:Type,~EventOwners:Type,~inventory:Leaves -> Leaves & List<&2,String>,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,P> -> W.World<S,C,R,P> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,schema:Schema.Schema<S,C,R>,owners:Owners,recipe:Tree.Recipe<W.World<S,C,R,P>,Rows,observe>,debug:Bool,result:Route.Runtime<S,C,R,P,FamilyRuntime.State<P,Leaves,EventOwners>> & Maybe<&2,List<&2,String>>) -> Application<S,C,R,P,FamilyRuntime.State<P,Leaves,EventOwners>,Owners,Rows,observe,fold> & Maybe<&2,List<&2,String>>:
49 match result:
50 case (runtime,names):(Application{schema,runtime,owners,recipe,debug},names)
51# Return App and optional family inventory through its generated inventory adapter.
52# Disabled returns None before deriving inventory; enabled returns detached names
53# while threading actual runtime state. This is not payload reading or retention.
54def inventory(~S:Data,~C:Type,~R:Type,~P:Data,~Leaves:Type,~EventOwners:Type,~inventory:Leaves -> Leaves & List<&2,String>,~Owners:Type,~Rows:Data,~observe:W.World<S,C,R,P> -> W.World<S,C,R,P> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,value:Application<S,C,R,P,FamilyRuntime.State<P,Leaves,EventOwners>,Owners,Rows,observe,fold>) -> Application<S,C,R,P,FamilyRuntime.State<P,Leaves,EventOwners>,Owners,Rows,observe,fold> & Maybe<&2,List<&2,String>>:
55 match value:
56 case Application{schema,runtime,owners,recipe,+debug}:inventory_returned(~S,~C,~R,~P,~Leaves,~EventOwners,~inventory,~Owners,~Rows,~observe,~fold,schema,owners,recipe,debug,FamilyRuntime.inventory_enabled(~S,~C,~R,~P,~Leaves,~EventOwners,~inventory,debug,runtime))