ordinary_app_stream.bend
bendvy-ecs-core@0.1.0.0 · 79 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/event_runtime.bend as Ev
4import bendvy-ecs-core@0.1.0.0/relation_commands.bend as A
5import bendvy-ecs-core@0.1.0.0/capabilities.bend as Cap
6import bendvy-ecs-core@0.1.0.0/inspector_stream_frame.bend as F
7import bendvy-ecs-core@0.1.0.0/inspector_transition_projection.bend as T
8import bendvy-ecs-core@0.1.0.0/inspector_failure_projection.bend as Fail
9import bendvy-ecs-core@0.1.0.0/machine_stream.bend as St
10
11# Detached machine transition log and declaration-scoped relation failure view.
12# Does not contain mutable World ownership or a new reader acknowledgement.
13type Values<S:Data,K:Data,V:Data,E:Data> is Data:
14 Values{transitions:T.TransitionLog<S,K,V>,failures:Fail.FailureView<S,E>}
15# Detached transition name plus projected stream values, not a restorable save.
16type Description<S:Data,K:Data,V:Data,E:Data> is Data:
17 Description{name:String,values:Values<S,K,V,E>}
18# Project the authored transition declaration name without reading runtime state.
19def transition_name(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & St.Stream<V>,declaration:T.Declaration<S,K,V,R,take>) -> String:
20 match declaration:
21 case T.Declaration{name}:name
22# Actual event Runtime and heterogeneous owners with a separate U32 observation
23# cursor/debug flag. Transition/failure declarations index the available views;
24# raw projection adapters remain trusted. This is not a second stream registry.
25type Application<S:Data,K:Data,V:Data,C:Type,R:Type,E:Data,H:Type,-take:R -> R & St.Stream<V>,-transition:T.Declaration<S,K,V,R,take>,-failure:Fail.Declaration<S>> is Type:
26 Application{runtime:Ev.Runtime<S,C,R,A.Notice<S,E>>,owners:H,cursor:Maybe<&2,Tick.Tick>,debug:Bool}
27def failure_done(~S:Data,~K:Data,~V:Data,~E:Data,~H:Type,transitions:T.TransitionLog<S,K,V>,returned:H & Fail.FailureView<S,E>) -> H & Values<S,K,V,E>:
28 (owner,failures)=returned
29 (owner,Values{transitions,failures})
30def transition_done(~S:Data,~K:Data,~V:Data,~E:Data,~H:Type,~grant:Cap.ValueRead<H,Fail.FailureView<S,E>>,returned:H & T.TransitionLog<S,K,V>) -> H & Values<S,K,V,E>:
31 (owner,transitions)=returned
32 failure_done(~S,~K,~V,~E,~H,transitions,Cap.value_read(~H,~Fail.FailureView<S,E>,~grant,owner))
33def transition_grant(~S:Data,~K:Data,~V:Data,~E:Data,~H:Type,grants:Cap.ValueRead<H,T.TransitionLog<S,K,V>> & Cap.ValueRead<H,Fail.FailureView<S,E>>) -> Cap.ValueRead<H,T.TransitionLog<S,K,V>>:
34 (transition,_)=grants
35 transition
36def failure_grant(~S:Data,~K:Data,~V:Data,~E:Data,~H:Type,grants:Cap.ValueRead<H,T.TransitionLog<S,K,V>> & Cap.ValueRead<H,Fail.FailureView<S,E>>) -> Cap.ValueRead<H,Fail.FailureView<S,E>>:
37 (_,failure)=grants
38 failure
39def selected(~S:Data,~K:Data,~V:Data,~E:Data,~H:Type,~grants:Cap.ValueRead<H,T.TransitionLog<S,K,V>> & Cap.ValueRead<H,Fail.FailureView<S,E>>,args:Unit,owner:H) -> H & Values<S,K,V,E>:
40 transition_done(~S,~K,~V,~E,~H,~failure_grant(~S,~K,~V,~E,~H,grants),Cap.value_read(~H,~T.TransitionLog<S,K,V>,~transition_grant(~S,~K,~V,~E,~H,grants),owner))
41# Retain the actual runtime/owners and supplied observation cursor with debug off.
42# Does not register a reader, synchronize publications or advance the cursor.
43def bind(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~H:Type,~take:R -> R & St.Stream<V>,~transition:T.Declaration<S,K,V,R,take>,~failure:Fail.Declaration<S>,runtime:Ev.Runtime<S,C,R,A.Notice<S,E>>,owners:H,cursor:Maybe<&2,Tick.Tick>) -> Application<S,K,V,C,R,E,H,take,transition,failure>:
44 Application{runtime,owners,cursor,False{}}
45def read_finished(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~H:Type,~take:R -> R & St.Stream<V>,~transition:T.Declaration<S,K,V,R,take>,~failure:Fail.Declaration<S>,owners:H,debug:Bool,returned:F.Frame<S,C,R,E> & Values<S,K,V,E>) -> Application<S,K,V,C,R,E,H,take,transition,failure> & Values<S,K,V,E>:
46 match returned:
47 case (F.Frame{runtime,cursor},values):(Application{runtime,owners,cursor,debug},values)
48# Read transition projection then selected relation failures through confined
49# inspector grants, returning actual runtime/owners and detached Values. This entry
50# is explicit reading regardless of debug flag; it preserves the supplied cursor
51# and does not advance/acknowledge event readers or change retention boundaries.
52# The transition resource projector must return its actual resource owner.
53def read_app(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~H:Type,~take:R -> R & St.Stream<V>,~transition:T.Declaration<S,K,V,R,take>,~failure:Fail.Declaration<S>,app:Application<S,K,V,C,R,E,H,take,transition,failure>) -> Application<S,K,V,C,R,E,H,take,transition,failure> & Values<S,K,V,E>:
54 match app:
55 case Application{runtime,owners,cursor,debug}:read_finished(~S,~K,~V,~C,~R,~E,~H,~take,~transition,~failure,owners,debug,Cap.invoke(~(Owner => Cap.ValueRead<Owner,T.TransitionLog<S,K,V>> & Cap.ValueRead<Owner,Fail.FailureView<S,E>>),~Unit,~Values<S,K,V,E>,~selected(~S,~K,~V,~E),~F.Frame<S,C,R,E>,~(T.inspect(~S,~K,~V,~C,~R,~E,~take,~transition),Fail.inspect(~S,~C,~R,~E,~failure)),Unit{},F.Frame{runtime,cursor}))
56# Set observation enablement, retaining runtime, owners and cursor unchanged.
57def enabled(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~H:Type,~take:R -> R & St.Stream<V>,~transition:T.Declaration<S,K,V,R,take>,~failure:Fail.Declaration<S>,app:Application<S,K,V,C,R,E,H,take,transition,failure>,flag:Bool) -> Application<S,K,V,C,R,E,H,take,transition,failure>:
58 match app:
59 case Application{runtime,owners,cursor,_}:Application{runtime,owners,cursor,flag}
60def snapshot_read(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~H:Type,~take:R -> R & St.Stream<V>,~transition:T.Declaration<S,K,V,R,take>,~failure:Fail.Declaration<S>,returned:Application<S,K,V,C,R,E,H,take,transition,failure> & Values<S,K,V,E>) -> Application<S,K,V,C,R,E,H,take,transition,failure> & Maybe<&2,Description<S,K,V,E>>:
61 (app,values)=returned
62 (app,Some{Description{transition_name(~S,~K,~V,~R,~take,transition),values}})
63# Return App and optional stream Description. Disabled returns None before either
64# projection. Enabled uses read_app without advancing cursor, running gameplay or
65# flushing commands. Failure view filters its declaration relation, not all shared
66# Notice payloads. See inspector-transition/failure-projection.bend.
67def snapshot(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~H:Type,~take:R -> R & St.Stream<V>,~transition:T.Declaration<S,K,V,R,take>,~failure:Fail.Declaration<S>,app:Application<S,K,V,C,R,E,H,take,transition,failure>) -> Application<S,K,V,C,R,E,H,take,transition,failure> & Maybe<&2,Description<S,K,V,E>>:
68 match app:
69 case Application{runtime,owners,cursor,False{}}:(Application{runtime,owners,cursor,False{}},None{})
70 case Application{runtime,owners,cursor,True{}}:snapshot_read(~S,~K,~V,~C,~R,~E,~H,~take,~transition,~failure,read_app(~S,~K,~V,~C,~R,~E,~H,~take,~transition,~failure,Application{runtime,owners,cursor,True{}}))
71def with_runtime_finished(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~H:Type,~take:R -> R & St.Stream<V>,~transition:T.Declaration<S,K,V,R,take>,~failure:Fail.Declaration<S>,~O:Type,owners:H,cursor:Maybe<&2,Tick.Tick>,debug:Bool,returned:Ev.Runtime<S,C,R,A.Notice<S,E>> & O) -> Application<S,K,V,C,R,E,H,take,transition,failure> & O:
72 (runtime,out)=returned
73 (Application{runtime,owners,cursor,debug},out)
74# Advanced effect adapter threading actual Runtime and returning Out while retaining
75# App owners/cursor/debug. The effect chooses any synchronization/frame changes;
76# this wrapper supplies no transaction, implicit acknowledgement or cleanup.
77def with_runtime(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~H:Type,~take:R -> R & St.Stream<V>,~transition:T.Declaration<S,K,V,R,take>,~failure:Fail.Declaration<S>,~O:Type,effect:Ev.Runtime<S,C,R,A.Notice<S,E>> -> Ev.Runtime<S,C,R,A.Notice<S,E>> & O,app:Application<S,K,V,C,R,E,H,take,transition,failure>) -> Application<S,K,V,C,R,E,H,take,transition,failure> & O:
78 match app:
79 case Application{runtime,owners,cursor,debug}:with_runtime_finished(~S,~K,~V,~C,~R,~E,~H,~take,~transition,~failure,~O,owners,cursor,debug,effect(runtime))