1 import Base 2 import ./change_tick.bend as Tick 3 import ./world.bend as W 4 import ./event_runtime.bend as Ev 5 import ./machine_stream.bend as St 6 import ./relation_commands.bend as A 7 import ./capabilities.bend as Cap 8 import ./inspector_stream_frame.bend as F 9 10 # Declares a named transition-log projection. K and the resource lens take 11 # determine the stream; name is presentation metadata, not access validation. 12 type Declaration R & St.Stream> is Data: 13 Declaration{name:String} 14 # Detached Data observation of a machine transition stream, not its owner. 15 type TransitionLog is Data: 16 TransitionLog{stream:St.Stream} 17 def joined(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,cursor:Maybe<&2,Tick.Tick>,namespace:U32,batches:List<&2,Ev.Batch>>,positions:List<&2,Ev.Position>,nextReader:U32,tick:Nat,frameStart:Nat,boundary:Nat,capacity:Nat,dropped:Nat,observed:W.World> & St.Stream) -> F.Frame & TransitionLog: 18 (world,stream)=observed 19 (F.Frame{Ev.Runtime{world,namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped},cursor},TransitionLog{stream}) 20 # Observe the stream through the trusted resource lens and return the runtime 21 # in an Inspector frame. Preserve event batches, reader positions and cursor. 22 # The lens must return the resource owner with the intended stream observation. 23 def from_runtime(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & St.Stream,cursor:Maybe<&2,Tick.Tick>,runtime:Ev.Runtime>) -> F.Frame & TransitionLog: 24 match runtime: 25 case Ev.Runtime{world,namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped}:joined(~S,~K,~V,~C,~R,~E,cursor,namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped,W.observe_resource(~S,~C,~R,~A.Notice,~St.Stream,~take,world)) 26 # Read the declared resource stream without executing a transition or advancing 27 # an event reader. Return the affine frame and its detached transition log. 28 def read(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & St.Stream,frame:F.Frame) -> F.Frame & TransitionLog: 29 match frame: 30 case F.Frame{runtime,cursor}:from_runtime(~S,~K,~V,~C,~R,~E,~take,cursor,runtime) 31 # Build a read capability using the declaration's typed resource lens. The 32 # declaration name does not select a different stream or enforce lens behavior. 33 def inspect(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & St.Stream,~declaration:Declaration) -> Cap.ValueRead,TransitionLog>: 34 Cap.ValueRead{read(~S,~K,~V,~C,~R,~E,~take)}