ordinary_app_dump.bend
1import Base
2import bendvy-ecs-core@0.1.0.0/clock_state.bend as Clock
3import bendvy-ecs-core@0.1.0.0/deferred_command.bend as Deferred
4import entity_key.bend as Key
5import entity_allocator.bend as Alloc
6import bendvy-ecs-core@0.1.0.0/world.bend as W
7import bendvy-ecs-core@0.1.0.0/ordinary_schema.bend as Schema
8import bendvy-ecs-core@0.1.0.0/schema_fragments.bend as Fragment
9import bendvy-ecs-core@0.1.0.0/ordinary_app_schema.bend as SchemaApp
10import bendvy-ecs-core@0.1.0.0/ordinary_app_composer.bend as Build
11import bendvy-ecs-core@0.1.0.0/ordinary_app_registration_fields.bend as Records
12import bendvy-ecs-core@0.1.0.0/ordinary_app_observation_data.bend as DTO
13import bendvy-ecs-core@0.1.0.0/ordinary_app_recipe.bend as Tree
14import bendvy-ecs-core@0.1.0.0/ordinary_schema_dump.bend as Provision
15import bendvy-ecs-core@0.1.0.0/ordinary_dump_filter.bend as Filter
16import bendvy-ecs-core@0.1.0.0/ordinary_dump_eligibility.bend as Eligible
17import bendvy-ecs-core@0.1.0.0/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.
24type Application<S:Data,C:Type,R:Type,E:Data,H:Type,Rows:Data,-observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,-fold:H -> H & List<&2,Records.Fields<S>>,-count:C -> List<&2,W.Handle<S>> -> 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<S,C,R>,app:Build.Registered<S,W.World<S,C,R,E>,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.
29type Dump<S:Data> is Data:
30 Dump{alive:U32,rows:List<&2,Filter.Row<S>>,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.
33def attached(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~count:C -> List<&2,W.Handle<S>> -> 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<S,C,R>,app:Build.Registered<S,W.World<S,C,R,E>,H,Rows,observe,fold>) -> Application<S,C,R,E,H,Rows,observe,fold,count,components,resources>:
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.
37def enabled(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~count:C -> List<&2,W.Handle<S>> -> 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<S,C,R,E,H,Rows,observe,fold,count,components,resources>,flag:Bool) -> Application<S,C,R,E,H,Rows,observe,fold,count,components,resources>:
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.
43def 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>:
44 SchemaApp.create(~S,~C,~R,~E,~empty,schema,factory,resource)
45def resource_returned(~S:Data,~C:Type,~R:Type,~E:Data,namespace:U32,allocator:Alloc.Allocator,store:C,events:List<&2,E>,pending:List<Deferred.Command<W.World<S,C,R,E>>>,registrations:List<&2,W.RegistrationMeta>,nextSystemId:U32,clock:Clock.State,result:R & List<&2,Maybe<&2,String>>) -> W.World<S,C,R,E> & List<&2,Maybe<&2,String>>:
46 match result:
47 case (resource,slots):(W.World{namespace,allocator,store,resource,events,pending,registrations,nextSystemId,clock},slots)
48def resource_world(~S:Data,~C:Type,~R:Type,~E:Data,~read:R -> R & List<&2,Maybe<&2,String>>,world:W.World<S,C,R,E>) -> W.World<S,C,R,E> & 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))
51def finished(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~count:C -> List<&2,W.Handle<S>> -> 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<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,alive:U32,rows:List<&2,Filter.Row<S>>,result:W.World<S,C,R,E> & List<&2,Maybe<&2,String>>) -> Application<S,C,R,E,H,Rows,observe,fold,count,components,resources> & Maybe<&2,Dump<S>>:
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<S>,&2,Maybe<&2,String>,Fragment.bare_entries(~S,Schema.entries(~S,~C,~R,schema)),slots))}})
54def rendered(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~count:C -> List<&2,W.Handle<S>> -> 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<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,alive:U32,result:W.World<S,C,R,E> & List<&2,Filter.Row<S>>) -> Application<S,C,R,E,H,Rows,observe,fold,count,components,resources> & Maybe<&2,Dump<S>>:
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))
57def selected(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~count:C -> List<&2,W.Handle<S>> -> 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<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,alive:U32,result:W.World<S,C,R,E> & List<&2,W.Handle<S>>) -> Application<S,C,R,E,H,Rows,observe,fold,count,components,resources> & Maybe<&2,Dump<S>>:
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<S>>,store => Render.rows(~S,~C,~components,handles,Schema.entries(~S,~C,~R,schema),store),world))
60def handled(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~count:C -> List<&2,W.Handle<S>> -> 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<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,ids:Maybe<&2,List<&2,Key.Key>>,required:List<&2,Filter.Component<S>>,limit:Maybe<&2,Nat>,result:W.World<S,C,R,E> & List<&2,W.Handle<S>>) -> Application<S,C,R,E,H,Rows,observe,fold,count,components,resources> & Maybe<&2,Dump<S>>:
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<S>,handles)),W.with_store(~S,~C,~R,~E,~List<&2,W.Handle<S>>,store => Eligible.scan(~S,~C,~count,handles,Schema.entries(~S,~C,~R,schema),ids,required,limit,store),world))
63def scanned(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~count:C -> List<&2,W.Handle<S>> -> 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<S,C,R>,owners:H,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,observe>,criteria:Filter.Filter<S>,result:W.World<S,C,R,E> & List<&2,W.Handle<S>>) -> Application<S,C,R,E,H,Rows,observe,fold,count,components,resources> & Maybe<&2,Dump<S>>:
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.
75def snapshot(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~count:C -> List<&2,W.Handle<S>> -> 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<S>,value:Application<S,C,R,E,H,Rows,observe,fold,count,components,resources>) -> Application<S,C,R,E,H,Rows,observe,fold,count,components,resources> & Maybe<&2,Dump<S>>:
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
80def schema_returned(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~count:C -> List<&2,W.Handle<S>> -> 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<S,C,R,E,H,Rows,observe,fold,count,components,resources> & Maybe<&2,Dump<S>>) -> SchemaApp.Application<S,C,R,E,H,Rows,observe,fold> & Maybe<&2,Dump<S>>:
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.
86def schema_snapshot(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Rows:Data,~observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:H -> H & List<&2,Records.Fields<S>>,~count:C -> List<&2,W.Handle<S>> -> 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<S>,value:SchemaApp.Application<S,C,R,E,H,Rows,observe,fold>) -> SchemaApp.Application<S,C,R,E,H,Rows,observe,fold> & Maybe<&2,Dump<S>>:
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}))