inspector_transition_projection.bend

bendvy-ecs-core@0.1.0.0 · 34 lines · 0 definitions

1import Base
2import bendvy-ecs-core@0.1.0.0/change_tick.bend as Tick
3import bendvy-ecs-core@0.1.0.0/world.bend as W
4import bendvy-ecs-core@0.1.0.0/event_runtime.bend as Ev
5import bendvy-ecs-core@0.1.0.0/machine_stream.bend as St
6import bendvy-ecs-core@0.1.0.0/relation_commands.bend as A
7import bendvy-ecs-core@0.1.0.0/capabilities.bend as Cap
8import bendvy-ecs-core@0.1.0.0/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.
12type Declaration<S:Data,K:Data,V:Data,R:Type,-take:R -> R & St.Stream<V>> is Data:
13  Declaration{name:String}
14# Detached Data observation of a machine transition stream, not its owner.
15type TransitionLog<S:Data,K:Data,V:Data> is Data:
16  TransitionLog{stream:St.Stream<V>}
17def 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<A.Notice<S,E>>>,positions:List<&2,Ev.Position>,nextReader:U32,tick:Nat,frameStart:Nat,boundary:Nat,capacity:Nat,dropped:Nat,observed:W.World<S,C,R,A.Notice<S,E>> & St.Stream<V>) -> F.Frame<S,C,R,E> & TransitionLog<S,K,V>:
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.
23def from_runtime(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & St.Stream<V>,cursor:Maybe<&2,Tick.Tick>,runtime:Ev.Runtime<S,C,R,A.Notice<S,E>>) -> F.Frame<S,C,R,E> & TransitionLog<S,K,V>:
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<S,E>,~St.Stream<V>,~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.
28def read(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & St.Stream<V>,frame:F.Frame<S,C,R,E>) -> F.Frame<S,C,R,E> & TransitionLog<S,K,V>:
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.
33def inspect(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & St.Stream<V>,~declaration:Declaration<S,K,V,R,take>) -> Cap.ValueRead<F.Frame<S,C,R,E>,TransitionLog<S,K,V>>:
34  Cap.ValueRead{read(~S,~K,~V,~C,~R,~E,~take)}