1 import Base 2 import ./clock_state.bend as Clock 3 import ./deferred_command.bend as Deferred 4 import entity_key.bend as Key 5 import entity_allocator.bend as Alloc 6 import ./world.bend as W 7 import ./ordinary_schema.bend as Schema 8 import ./schema_fragments.bend as Fragment 9 import ./ordinary_app_schema.bend as SchemaApp 10 import ./ordinary_app_composer.bend as Build 11 import ./ordinary_app_registration_fields.bend as Records 12 import ./ordinary_app_observation_data.bend as DTO 13 import ./ordinary_app_recipe.bend as Tree 14 import ./ordinary_schema_dump.bend as Provision 15 import ./ordinary_dump_filter.bend as Filter 16 import ./ordinary_dump_eligibility.bend as Eligible 17 import ./ordinary_dump_render.bend as Render 18 # Ordinary provisioning generates the erased presence/presentation operations. 19 # The schema is retained once; forged raw index bridges remain trusted setup. 20 # Schema-backed dump wrapper retaining the registered App and all affine owners. 21 # count/components/resources are advanced erased presence/presentation adapters 22 # generated by ordinary provisioning. Raw forged bridges and opaque presenters 23 # remain trusted; their signatures alone do not prove owner identity or purity. 24 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: 25 Application{schema:Schema.Schema,app:Build.Registered,H,Rows,observe,fold>} 26 # Detached presentation result: alive counts all currently live handles before 27 # filtering; rows contains selected entities and resources is a separate view. 28 # Strings are descriptions, not payload owners or a restorable save/checkpoint. 29 type Dump is Data: 30 Dump{alive:U32,rows:List<&2,Filter.Row>,resources:List<&2,Filter.Value>} 31 # Advanced attachment of a retained schema and registered App to its generated 32 # dump operations. Does not register systems, enable debug or inspect payloads. 33 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: 34 Application{schema,app} 35 # Set the underlying App debug flag, returning schema, World and registration 36 # owners. This changes observation enablement, not gameplay execution authority. 37 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: 38 match value: 39 case Application{schema,Build.Registered{world,owners,recipe,_}}:Application{schema,Build.Registered{world,owners,recipe,flag}} 40 # Delegate World creation through the retained schema and factory, returning 41 # the schema with the actual Creation result. Refusal retains its owned creation 42 # inputs under SchemaApp.create; this does not attach a registered dump App. 43 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: 44 SchemaApp.create(~S,~C,~R,~E,~empty,schema,factory,resource) 45 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>>: 46 match result: 47 case (resource,slots):(W.World{namespace,allocator,store,resource,events,pending,registrations,nextSystemId,clock},slots) 48 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>>: 49 match world: 50 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)) 51 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>: 52 match result: 53 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))}}) 54 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>: 55 match result: 56 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)) 57 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>: 58 match result: 59 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)) 60 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>: 61 match result: 62 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)) 63 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>: 64 match criteria: 65 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) 66 # Return the App and optional filtered dump. Disabled returns None before handle 67 # scanning or presentation. Enabled scans live handles in their existing order; 68 # entity keys and required component tokens are conjunctive, and the Nat limit 69 # counts accepted rows before component rendering. Resources are rendered apart 70 # from entity filters, including when the entity limit is zero. 71 # All projections return their actual storage/resource owners. This does not run 72 # systems, advance readers, flush commands or apply a structural barrier. Opaque 73 # presenter behavior remains trusted rather than universally proven noninterfering. 74 # See docs/parity/debug.md, ordinary filtered dump acceptance and retained consumer. 75 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>: 76 match value: 77 case Application{schema,Build.Registered{world,owners,recipe,False{}}}:(Application{schema,Build.Registered{world,owners,recipe,False{}}},None{}) 78 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)) 79 80 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>: 81 match result: 82 case (Application{schema,app},view):(SchemaApp.Application{schema,app},view) 83 # Schema-App adapter for snapshot with the same generated operations and filter 84 # semantics, returning the SchemaApp wrapper and optional detached dump. Preserve 85 # the generated provisioning functions; no second handwritten key list is needed. 86 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>: 87 match value: 88 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}))