persistence_declaration.bend
bendvy-ecs-core@0.1.0.3 · 43 lines · 13 definitions
1import Base
2import bendvy-ecs-core@0.1.0.3/decode_data.bend as D
3import bendvy-ecs-core@0.1.0.3/decode_capabilities.bend as Public
4import bendvy-ecs-core@0.1.0.3/decode.bend as Complete
5import bendvy-ecs-core@0.1.0.3/ordinary_declaration.bend as Canonical
6
7
8
9type Plain<-S:Data,-P:Type,-identity:Canonical.Declaration<S,P>> is Data:
10 Plain{}
11type Transient<-S:Data,-P:Type,-identity:Canonical.Declaration<S,P>> is Data:
12 Transient{}
13type Constructed<-S:Data,-P:Type,-identity:Canonical.Declaration<S,P>,-project:P -> P & D.Raw> is Data:
14 Constructed{codec:D.Codec}
15def plain(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>) -> Plain<S,P,identity>:
16 Plain{}
17def transient(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>) -> Transient<S,P,identity>:
18 Transient{}
19def constructed(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>,~project:P -> P & D.Raw,codec:D.Codec) -> Constructed<S,P,identity,project>:
20 Constructed{codec}
21def codec(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>,~project:P -> P & D.Raw,declaration:Constructed<S,P,identity,project>) -> D.Codec:
22 match declaration:
23 case Constructed{codec}:codec
24
25
26
27def validate(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>,~project:P -> P & D.Raw,declaration:Constructed<S,P,identity,project>,owner:P) -> D.Receipt<P>:
28 Complete.decode_owner(~P,~project,codec(~S,~P,~identity,~project,declaration),owner)
29def prepare(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>,~project:P -> P & D.Raw,+declaration:Constructed<S,P,identity,project>,owner:P) -> Constructed<S,P,identity,project> & D.Receipt<P>:
30 (declaration,validate(~S,~P,~identity,~project,declaration,owner))
31
32
33
34type Context<-S:Data,-P:Type,-identity:Canonical.Declaration<S,P>,-project:P -> P & D.Raw> is Type:
35 Context{declaration:Constructed<S,P,identity,project>,retained:List<P>}
36def decode(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>,~project:P -> P & D.Raw,context:Context<S,P,identity,project>,owner:P) -> Context<S,P,identity,project> & D.Receipt<P>:
37 match context:
38 case Context{+declaration,retained}:(Context{declaration,retained},validate(~S,~P,~identity,~project,declaration,owner))
39def admit(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>,~project:P -> P & D.Raw,context:Context<S,P,identity,project>,receipt:D.Receipt<P>) -> Context<S,P,identity,project> & D.Checked:
40 match context receipt:
41 case Context{declaration,retained} D.Receipt{owner,checked}:(Context{declaration,owner <> retained},checked)
42def request(~S:Data,~P:Type,~identity:Canonical.Declaration<S,P>,~project:P -> P & D.Raw,context:Context<S,P,identity,project>,owner:P) -> Context<S,P,identity,project> & D.Checked:
43 Public.request(~P,~Context<S,P,identity,project>,~D.Checked,~decode(~S,~P,~identity,~project),~admit(~S,~P,~identity,~project),context,owner)