snapshot_gate.bend

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

1import Base
2import bendvy-ecs-core@0.1.0.0/ordinary_declaration.bend as C
3import bendvy-ecs-core@0.1.0.0/decode_data.bend as D
4
5# Trusted schema-author witness, not an unforgeable public constructor.
6# Decoder describes untrusted DATA validation; no implicit Raw -> P inverse.
7type Gate<-S:Data,-P:Type,-declaration:C.Declaration<S,P>> is Type:
8  Transient{}
9  Persisted{codec:D.Codec,project:P -> P & D.Raw}
10type Field is Data:
11  Omitted{name:String}
12  Saved{name:String,value:D.Raw}
13def transient(~S:Data,~P:Type,~declaration:C.Declaration<S,P>) -> Gate<S,P,declaration>:
14  Transient{}
15def persisted(~S:Data,~P:Type,~declaration:C.Declaration<S,P>,codec:D.Codec,project:P -> P & D.Raw) -> Gate<S,P,declaration>:
16  Persisted{codec,project}
17def projected(~P:Type,name:String,observed:P & D.Raw) -> P & Field:
18  match observed:
19    case (owner,value):(owner,Saved{name,value})
20# Static eligibility mirrors TS Gate: export itself does not run its decoder.
21# This low-level operation consumes Gate; snapshot-leaf reconstructs it from
22# the retained ordinary declaration for repeated owner-preserving saves.
23def export_owner(~S:Data,~P:Type,~declaration:C.Declaration<S,P>,gate:Gate<S,P,declaration>,owner:P) -> P & Field:
24  match gate:
25    case Transient{}:(owner,Omitted{C.key(~S,~P,declaration)})
26    case Persisted{_,project}:projected(~P,C.key(~S,~P,declaration),project(owner))