1 import Base 2 import ./ordinary_resource_system.bend as P 3 import ./ordinary_schema.bend as Schema 4 import ./world.bend as W 5 import ./transaction.bend as T 6 import ./capabilities.bend as Cap 7 import ./ordinary_query_declaration.bend as Query 8 # One static declaration constructs operational and owner-preserving observation routes. 9 # It carries no runtime-owned World or resource payload. 10 # App declaration for the entire Resources owner R in one schema S. 11 # Keeps operational permissions, an owner-threading Data observation and its 12 # renderer together. It contains no live World or resource instance. Choose 13 # ordinary-app-resource-field-declaration when only one product field is needed. 14 # Concrete setup: test-fixtures/public-schedules/named-app-v1/ 15 # matched-feature-v1/fixture.bend:declaration and reader_declaration. 16 type Declaration<-S:Data,-C:Type,-R:Type,-E:Data,-Ops:Type -> Type,-V:Data> is Type: 17 Declaration{ordinary:P.Declaration,E>,Ops(T.Tx,E>)>,observe:W.World -> W.World & V,render:V -> String} 18 # Operation-family alias for whole-resource read access to a Data view V. 19 # The callback receives an opaque owner H; the grant cannot replace Resources. 20 def read_ops(~V:Data,H:Type) -> Type: 21 Cap.ValueRead 22 # Operation-family alias for whole-resource read/replacement access. 23 # A write consumes a replacement R, which may contain affine Type payloads; 24 # this is not the narrower grant for replacing a single resource field. 25 def write_ops(~R:Type,~V:Data,H:Type) -> Type: 26 Cap.ValueWrite 27 # Declare read access using a schema-bound resource identity and projection. 28 # project threads R back with a Data view V; render formats that view for App 29 # observation. The returned declaration is setup data, not a live resource read. 30 # The observation path also threads the World; it does not imply that an 31 # arbitrary user projector is pure or can be undone automatically. 32 def read(~S:Data,~C:Type,~R:Type,~E:Data,~V:Data,~project:R -> R & V,~render:V -> String,identity:Schema.Resource) -> Declaration: 33 Declaration{P.read(~S,~C,~R,~E,~V,~project,identity),W.observe_resource(~S,~C,~R,~E,~V,~project),render} 34 # Declare read and whole-owner replacement access to schema resource R. 35 # Uses the same projection/rendering contract as read. Replacements made through 36 # the operational grant use the ordinary transaction journal: a failed system 37 # restores the old resource. This declaration does not execute a system or grant 38 # rollback for arbitrary host IO or effects outside those operations. 39 def write(~S:Data,~C:Type,~R:Type,~E:Data,~V:Data,~project:R -> R & V,~render:V -> String,identity:Schema.Resource) -> Declaration: 40 Declaration{P.write(~S,~C,~R,~E,~V,~project,identity),W.observe_resource(~S,~C,~R,~E,~V,~project),render} 41 # Advanced App projection: consume the declaration and return its operational 42 # resource declaration. Recreate a closed declaration when multiple projections 43 # are needed; metadata strings alone cannot substitute for the typed grant. 44 def ordinary(~S:Data,~C:Type,~R:Type,~E:Data,~Ops:Type -> Type,~V:Data,declaration:Declaration) -> P.Declaration,E>,Ops(T.Tx,E>)>: 45 match declaration: 46 case Declaration{ordinary,_,_}:ordinary 47 # Advanced App projection: consume the declaration and obtain the function 48 # World -> (World, V). The World owner is returned after the resource projection; 49 # this observer neither registers nor executes the resource system. 50 def observer(~S:Data,~C:Type,~R:Type,~E:Data,~Ops:Type -> Type,~V:Data,declaration:Declaration) -> W.World -> W.World & V: 51 match declaration: 52 case Declaration{_,observe,_}:observe 53 # Obtain the declared Data-view renderer, consuming this declaration value. 54 # Rendering is observation work and grants no access to a World or resource. 55 def presenter(~S:Data,~C:Type,~R:Type,~E:Data,~Ops:Type -> Type,~V:Data,declaration:Declaration) -> V -> String: 56 match declaration: 57 case Declaration{_,_,render}:render 58 def named(~S:Data,value:Query.Clause) -> String: 59 match value: 60 case Query.Clause{key,_}:key 61 # Return the resource access key from this declaration's operational clause. 62 # Consumes the declaration and retains its declared name, not runtime authority. 63 # Use the schema identity for access, rather than reconstructing it from this text. 64 def name(~S:Data,~C:Type,~R:Type,~E:Data,~Ops:Type -> Type,~V:Data,declaration:Declaration) -> String: 65 named(~S,P.clause(~S,~R,~T.Tx,E>,~Ops(T.Tx,E>),ordinary(~S,~C,~R,~E,~Ops,~V,declaration)))