import Base import ./clock_state.bend as Clock import ./deferred_command.bend as Deferred import entity_key.bend as Key import entity_allocator.bend as Alloc import ./world.bend as W import ./ordinary_schema.bend as Schema import ./schema_fragments.bend as Fragment import ./ordinary_app_schema.bend as SchemaApp import ./ordinary_app_composer.bend as Build import ./ordinary_app_registration_fields.bend as Records import ./ordinary_app_observation_data.bend as DTO import ./ordinary_app_recipe.bend as Tree import ./ordinary_schema_dump.bend as Provision import ./ordinary_dump_filter.bend as Filter import ./ordinary_dump_eligibility.bend as Eligible import ./ordinary_dump_render.bend as Render # Ordinary provisioning generates the erased presence/presentation operations. # The schema is retained once; forged raw index bridges remain trusted setup. # Schema-backed dump wrapper retaining the registered App and all affine owners. # count/components/resources are advanced erased presence/presentation adapters # generated by ordinary provisioning. Raw forged bridges and opaque presenters # remain trusted; their signatures alone do not prove owner identity or purity. type Application -> W.World & DTO.Observation,-fold:H -> H & List<&2,Records.Fields>,-count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,-components:C -> U32 -> C & List<&2,Maybe<&2,String>>,-resources:R -> R & List<&2,Maybe<&2,String>>> is Type: Application{schema:Schema.Schema,app:Build.Registered,H,Rows,observe,fold>} # Detached presentation result: alive counts all currently live handles before # filtering; rows contains selected entities and resources is a separate view. # Strings are descriptions, not payload owners or a restorable save/checkpoint. type Dump is Data: Dump{alive:U32,rows:List<&2,Filter.Row>,resources:List<&2,Filter.Value>} # Advanced attachment of a retained schema and registered App to its generated # dump operations. Does not register systems, enable debug or inspect payloads. def attached(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Records.Fields>,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,schema:Schema.Schema,app:Build.Registered,H,Rows,observe,fold>) -> Application: Application{schema,app} # Set the underlying App debug flag, returning schema, World and registration # owners. This changes observation enablement, not gameplay execution authority. def enabled(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Records.Fields>,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,value:Application,flag:Bool) -> Application: match value: case Application{schema,Build.Registered{world,owners,recipe,_}}:Application{schema,Build.Registered{world,owners,recipe,flag}} # Delegate World creation through the retained schema and factory, returning # the schema with the actual Creation result. Refusal retains its owned creation # inputs under SchemaApp.create; this does not attach a registered dump App. def create(~S:Data,~C:Type,~R:Type,~E:Data,~empty:Unit -> C,schema:Schema.Schema,factory:W.Factory,resource:R) -> Schema.Schema & W.Creation: SchemaApp.create(~S,~C,~R,~E,~empty,schema,factory,resource) def resource_returned(~S:Data,~C:Type,~R:Type,~E:Data,namespace:U32,allocator:Alloc.Allocator,store:C,events:List<&2,E>,pending:List>>,registrations:List<&2,W.RegistrationMeta>,nextSystemId:U32,clock:Clock.State,result:R & List<&2,Maybe<&2,String>>) -> W.World & List<&2,Maybe<&2,String>>: match result: case (resource,slots):(W.World{namespace,allocator,store,resource,events,pending,registrations,nextSystemId,clock},slots) def resource_world(~S:Data,~C:Type,~R:Type,~E:Data,~read:R -> R & List<&2,Maybe<&2,String>>,world:W.World) -> W.World & List<&2,Maybe<&2,String>>: match world: case W.World{namespace,allocator,store,resource,events,pending,registrations,nextSystemId,clock}:resource_returned(~S,~C,~R,~E,namespace,allocator,store,events,pending,registrations,nextSystemId,clock,read(resource)) def finished(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Records.Fields>,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,+schema:Schema.Schema,owners:H,recipe:Tree.Recipe,Rows,observe>,alive:U32,rows:List<&2,Filter.Row>,result:W.World & List<&2,Maybe<&2,String>>) -> Application & Maybe<&2,Dump>: match result: case (world,slots):(Application{schema,Build.Registered{world,owners,recipe,True{}}},Some{Dump{alive,rows,Render.resources(~S,List.zip(&2,Fragment.Entry,&2,Maybe<&2,String>,Fragment.bare_entries(~S,Schema.entries(~S,~C,~R,schema)),slots))}}) def rendered(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Records.Fields>,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,schema:Schema.Schema,owners:H,recipe:Tree.Recipe,Rows,observe>,alive:U32,result:W.World & List<&2,Filter.Row>) -> Application & Maybe<&2,Dump>: match result: case (world,rows):finished(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~count,~components,~resources,schema,owners,recipe,alive,rows,resource_world(~S,~C,~R,~E,~resources,world)) def selected(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Records.Fields>,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,+schema:Schema.Schema,owners:H,recipe:Tree.Recipe,Rows,observe>,alive:U32,result:W.World & List<&2,W.Handle>) -> Application & Maybe<&2,Dump>: match result: case (world,handles):rendered(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~count,~components,~resources,schema,owners,recipe,alive,W.with_store(~S,~C,~R,~E,~List<&2,Filter.Row>,store => Render.rows(~S,~C,~components,handles,Schema.entries(~S,~C,~R,schema),store),world)) def handled(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Records.Fields>,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,+schema:Schema.Schema,owners:H,recipe:Tree.Recipe,Rows,observe>,ids:Maybe<&2,List<&2,Key.Key>>,required:List<&2,Filter.Component>,limit:Maybe<&2,Nat>,result:W.World & List<&2,W.Handle>) -> Application & Maybe<&2,Dump>: match result: case (world,+handles):selected(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~count,~components,~resources,schema,owners,recipe,U32.from_nat(List.length(&2,W.Handle,handles)),W.with_store(~S,~C,~R,~E,~List<&2,W.Handle>,store => Eligible.scan(~S,~C,~count,handles,Schema.entries(~S,~C,~R,schema),ids,required,limit,store),world)) def scanned(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Records.Fields>,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,+schema:Schema.Schema,owners:H,recipe:Tree.Recipe,Rows,observe>,criteria:Filter.Filter,result:W.World & List<&2,W.Handle>) -> Application & Maybe<&2,Dump>: match criteria: case Filter.Filter{ids,required,limit}:handled(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~count,~components,~resources,schema,owners,recipe,ids,required,limit,result) # Return the App and optional filtered dump. Disabled returns None before handle # scanning or presentation. Enabled scans live handles in their existing order; # entity keys and required component tokens are conjunctive, and the Nat limit # counts accepted rows before component rendering. Resources are rendered apart # from entity filters, including when the entity limit is zero. # All projections return their actual storage/resource owners. This does not run # systems, advance readers, flush commands or apply a structural barrier. Opaque # presenter behavior remains trusted rather than universally proven noninterfering. # See docs/parity/debug.md, ordinary filtered dump acceptance and retained consumer. def snapshot(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Records.Fields>,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,criteria:Filter.Filter,value:Application) -> Application & Maybe<&2,Dump>: match value: case Application{schema,Build.Registered{world,owners,recipe,False{}}}:(Application{schema,Build.Registered{world,owners,recipe,False{}}},None{}) case Application{schema,Build.Registered{world,owners,recipe,True{}}}:scanned(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~count,~components,~resources,schema,owners,recipe,criteria,W.handles(~S,~C,~R,~E,world)) def schema_returned(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Records.Fields>,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,result:Application & Maybe<&2,Dump>) -> SchemaApp.Application & Maybe<&2,Dump>: match result: case (Application{schema,app},view):(SchemaApp.Application{schema,app},view) # Schema-App adapter for snapshot with the same generated operations and filter # semantics, returning the SchemaApp wrapper and optional detached dump. Preserve # the generated provisioning functions; no second handwritten key list is needed. def schema_snapshot(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World -> W.World & DTO.Observation,~fold:H -> H & List<&2,Records.Fields>,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,criteria:Filter.Filter,value:SchemaApp.Application) -> SchemaApp.Application & Maybe<&2,Dump>: match value: case SchemaApp.Application{schema,app}:schema_returned(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~count,~components,~resources,snapshot(~S,~C,~R,~E,~H,~Rows,~observe,~fold,~count,~components,~resources,criteria,Application{schema,app}))