decode_validated_resource.bend

bendvy-ecs-core@0.1.0.1 · 21 lines · 0 definitions

1import Base
2import decode_frame.bend as F
3import ordinary_declaration.bend as Identity
4import persistence_declaration.bend as Decl
5import decode_data.bend as D
6import capabilities.bend as Cap
7
8type Output<R:Type> is Type:
9  Replaced{canonical:D.Raw}
10  Refused{owner:R,error:D.Error}
11def replaced(~S:Data,~C:Type,~R:Type,~E:Data,~P:Type,~Q:Type,~identity:Identity.Declaration<S,P>,~project:P -> P & D.Raw,canonical:D.Raw,result:F.Frame<S,C,R,E,P,Q,identity,project> & Unit) -> F.Frame<S,C,R,E,P,Q,identity,project> & Output<R>:
12  match result:
13    case (frame,_):(frame,Replaced{canonical})
14def checked(~S:Data,~C:Type,~R:Type,~E:Data,~P:Type,~Q:Type,~identity:Identity.Declaration<S,P>,~project:P -> P & D.Raw,frame:F.Frame<S,C,R,E,P,Q,identity,project>,receipt:D.Receipt<R>) -> F.Frame<S,C,R,E,P,Q,identity,project> & Output<R>:
15  match receipt:
16    case D.Receipt{owner,D.Rejected{error}}:(frame,Refused{owner,error})
17    case D.Receipt{owner,D.Accepted{canonical}}:replaced(~S,~C,~R,~E,~P,~Q,~identity,~project,canonical,F.resource_set(~S,~C,~R,~E,~P,~Q,~identity,~project,frame,owner))
18def request(~S:Data,~C:Type,~R:Type,~E:Data,~P:Type,~Q:Type,~identity:Identity.Declaration<S,P>,~project:P -> P & D.Raw,~resource_identity:Identity.Declaration<S,R>,~resource_project:R -> R & D.Raw,declaration:Decl.Constructed<S,R,resource_identity,resource_project>,frame:F.Frame<S,C,R,E,P,Q,identity,project>,replacement:R) -> F.Frame<S,C,R,E,P,Q,identity,project> & Output<R>:
19  checked(~S,~C,~R,~E,~P,~Q,~identity,~project,frame,Decl.validate(~S,~R,~resource_identity,~resource_project,declaration,replacement))
20def grant(~S:Data,~C:Type,~R:Type,~E:Data,~P:Type,~Q:Type,~identity:Identity.Declaration<S,P>,~project:P -> P & D.Raw,~resource_identity:Identity.Declaration<S,R>,~resource_project:R -> R & D.Raw,~declaration:Decl.Constructed<S,R,resource_identity,resource_project>) -> Cap.OwnedRequest<F.Frame<S,C,R,E,P,Q,identity,project>,R,Output<R>>:
21  Cap.OwnedRequest{frame => replacement => request(~S,~C,~R,~E,~P,~Q,~identity,~project,~resource_identity,~resource_project,declaration,frame,replacement)}