import Base import ./change_tick.bend as Tick import ./world.bend as W import ./event_runtime.bend as Ev import ./machine_stream.bend as St import ./relation_commands.bend as A import ./capabilities.bend as Cap import ./inspector_stream_frame.bend as F # Declares a named transition-log projection. K and the resource lens take # determine the stream; name is presentation metadata, not access validation. type Declaration R & St.Stream> is Data: Declaration{name:String} # Detached Data observation of a machine transition stream, not its owner. type TransitionLog is Data: TransitionLog{stream:St.Stream} 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: (world,stream)=observed (F.Frame{Ev.Runtime{world,namespace,batches,positions,nextReader,tick,frameStart,boundary,capacity,dropped},cursor},TransitionLog{stream}) # Observe the stream through the trusted resource lens and return the runtime # in an Inspector frame. Preserve event batches, reader positions and cursor. # The lens must return the resource owner with the intended stream observation. 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: match runtime: 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)) # Read the declared resource stream without executing a transition or advancing # an event reader. Return the affine frame and its detached transition log. 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: match frame: case F.Frame{runtime,cursor}:from_runtime(~S,~K,~V,~C,~R,~E,~take,cursor,runtime) # Build a read capability using the declaration's typed resource lens. The # declaration name does not select a different stream or enforce lens behavior. def inspect(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & St.Stream,~declaration:Declaration) -> Cap.ValueRead,TransitionLog>: Cap.ValueRead{read(~S,~K,~V,~C,~R,~E,~take)}