decode_fallible_constructed_resource.bend

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

1import Base
2import decode_construction.bend as Constructor
3import decode_validated_resource.bend as Resource
4import ordinary_declaration.bend as Identity
5import decode_data.bend as D
6import bundle_construction.bend as Build
7import capabilities.bend as Cap
8
9type Error<Custom:Data> is Data:Construction{error:Constructor.Error<Custom>} Admission{error:D.Error}
10type Output<I:Type,R:Type,Custom:Data> is Type:
11  Replaced{canonical:D.Raw,undo:R -> I}
12  Refused{owner:I,error:Error<Custom>}
13def returned(~I:Type,~R:Type,~Custom:Data,~H:Type,undo:R -> I,result:H & Resource.Output<R>) -> H & Output<I,R,Custom>:
14  match result:
15    case (ctx,Resource.Replaced{canonical}):(ctx,Replaced{canonical,undo})
16    case (ctx,Resource.Refused{owner,error}):(ctx,Refused{undo(owner),Admission{error}})
17def constructed(~I:Type,~R:Type,~Custom:Data,~H:Type,~request:Cap.OwnedRequest<H,R,Resource.Output<R>>,ctx:H,value:Build.Construction<I,R,Constructor.Error<Custom>>) -> H & Output<I,R,Custom>:
18  match value:
19    case Build.Invalid{owner,error}:(ctx,Refused{owner,Construction{error}})
20    case Build.Constructed{owner,undo}:returned(~I,~R,~Custom,~H,undo,Cap.owned_request(~H,~R,~Resource.Output<R>,~request,ctx,owner))
21def apply(~S:Data,~I:Type,~R:Type,~Custom:Data,~identity:Identity.Declaration<S,R>,~project:R -> R & D.Raw,~incoming:I -> I & D.Raw,~build:I -> D.Raw -> Build.Construction<I,R,Custom>,~factory:Constructor.FallibleFactory<S,I,R,Custom,identity,project,incoming,build>,~H:Type,~request:Cap.OwnedRequest<H,R,Resource.Output<R>>,ctx:H,input:I) -> H & Output<I,R,Custom>:
22  constructed(~I,~R,~Custom,~H,~request,ctx,Constructor.fallible_construct(~S,~I,~R,~Custom,~identity,~project,~incoming,~build,factory,input))
23def grant(~S:Data,~I:Type,~R:Type,~Custom:Data,~identity:Identity.Declaration<S,R>,~project:R -> R & D.Raw,~incoming:I -> I & D.Raw,~build:I -> D.Raw -> Build.Construction<I,R,Custom>,~factory:Constructor.FallibleFactory<S,I,R,Custom,identity,project,incoming,build>,~H:Type,~request:Cap.OwnedRequest<H,R,Resource.Output<R>>) -> Cap.OwnedRequest<H,I,Output<I,R,Custom>>:
24  Cap.OwnedRequest{ctx => input => apply(~S,~I,~R,~Custom,~identity,~project,~incoming,~build,~factory,~H,~request,ctx,input)}