ordinary_app_resource_declaration.bend
bendvy-ecs-core@0.1.0.0 · 65 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.0/ordinary_resource_system.bend as P
3import bendvy-ecs-core@0.1.0.0/ordinary_schema.bend as Schema
4import bendvy-ecs-core@0.1.0.0/world.bend as W
5import bendvy-ecs-core@0.1.0.0/transaction.bend as T
6import bendvy-ecs-core@0.1.0.0/capabilities.bend as Cap
7import bendvy-ecs-core@0.1.0.0/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.
16type Declaration<-S:Data,-C:Type,-R:Type,-E:Data,-Ops:Type -> Type,-V:Data> is Type:
17 Declaration{ordinary:P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,E>)>,observe:W.World<S,C,R,E> -> W.World<S,C,R,E> & 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.
20def read_ops(~V:Data,H:Type) -> Type:
21 Cap.ValueRead<H,V>
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.
25def write_ops(~R:Type,~V:Data,H:Type) -> Type:
26 Cap.ValueWrite<H,R,V>
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.
32def read(~S:Data,~C:Type,~R:Type,~E:Data,~V:Data,~project:R -> R & V,~render:V -> String,identity:Schema.Resource<S,R>) -> Declaration<S,C,R,E,read_ops(~V),V>:
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.
39def write(~S:Data,~C:Type,~R:Type,~E:Data,~V:Data,~project:R -> R & V,~render:V -> String,identity:Schema.Resource<S,R>) -> Declaration<S,C,R,E,write_ops(~R,~V),V>:
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.
44def ordinary(~S:Data,~C:Type,~R:Type,~E:Data,~Ops:Type -> Type,~V:Data,declaration:Declaration<S,C,R,E,Ops,V>) -> P.Declaration<S,R,T.Tx<W.World<S,C,R,E>,E>,Ops(T.Tx<W.World<S,C,R,E>,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.
50def observer(~S:Data,~C:Type,~R:Type,~E:Data,~Ops:Type -> Type,~V:Data,declaration:Declaration<S,C,R,E,Ops,V>) -> W.World<S,C,R,E> -> W.World<S,C,R,E> & 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.
55def presenter(~S:Data,~C:Type,~R:Type,~E:Data,~Ops:Type -> Type,~V:Data,declaration:Declaration<S,C,R,E,Ops,V>) -> V -> String:
56 match declaration:
57 case Declaration{_,_,render}:render
58def named(~S:Data,value:Query.Clause<S>) -> 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.
64def name(~S:Data,~C:Type,~R:Type,~E:Data,~Ops:Type -> Type,~V:Data,declaration:Declaration<S,C,R,E,Ops,V>) -> String:
65 named(~S,P.clause(~S,~R,~T.Tx<W.World<S,C,R,E>,E>,~Ops(T.Tx<W.World<S,C,R,E>,E>),ordinary(~S,~C,~R,~E,~Ops,~V,declaration)))