1 import Base 2 import ./ordinary_event_family.bend as Family 3 import ./event_family_runtime.bend as FamilyRuntime 4 import ./world.bend as W 5 import ./ordinary_schema.bend as Schema 6 import ./ordinary_app_schema.bend as SchemaApp 7 import ./ordinary_app_composer.bend as Build 8 import ./ordinary_app_recipe.bend as Tree 9 import ./ordinary_app_registration_fields.bend as Records 10 import ./ordinary_app_observation_data.bend as DTO 11 import ./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. 17 type Application -> W.World & DTO.Observation,-fold:Owners -> Owners & List<&2,Records.Fields>> is Type: 18 Application{schema:Schema.Schema,runtime:Route.Runtime,owners:Owners,recipe:Tree.Recipe,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. 21 def attached(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,family:F,tick:Nat,value:SchemaApp.Application) -> Application: 22 match value: 23 case SchemaApp.Application{schema,Build.Registered{world,owners,recipe,debug}}:Application{schema,Route.Runtime{world,family,tick},owners,recipe,debug} 24 def returned(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~Out:Type,family:F,tick:Nat,result:SchemaApp.Application & Out) -> Application & 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. 30 def with_previous(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,~Out:Type,action:SchemaApp.Application -> SchemaApp.Application & Out,value:Application) -> Application & 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. 36 def snapshot(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,value:Application) -> Application & Maybe<&2,SchemaApp.Description>: 37 with_previous(~S,~C,~R,~P,~F,~Owners,~Rows,~observe,~fold,~Maybe<&2,SchemaApp.Description>,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. 41 def 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 -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,provision:Family.Provision,events:EventOwners,capacity:Nat,value:SchemaApp.Application) -> Application,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. 45 def enabled(~S:Data,~C:Type,~R:Type,~P:Data,~F:Type,~Owners:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,value:Application,flag:Bool) -> Application: 46 match value: 47 case Application{schema,runtime,owners,recipe,_}:Application{schema,runtime,owners,recipe,flag} 48 def 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 -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,schema:Schema.Schema,owners:Owners,recipe:Tree.Recipe,Rows,observe>,debug:Bool,result:Route.Runtime> & Maybe<&2,List<&2,String>>) -> Application,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. 54 def 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 -> W.World & DTO.Observation,~fold:Owners -> Owners & List<&2,Records.Fields>,value:Application,Owners,Rows,observe,fold>) -> Application,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))