bundle_canonical_construction.bend

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

1import Base
2import decode_construction.bend as Constructor
3import ordinary_declaration.bend as Identity
4import decode_data.bend as D
5import bundle_construction.bend as Build
6import bundle_pack.bend as Pack
7
8# An ordinary schema context owns its constructor factories and other owners.
9# Both factory and rest return through the authored lenses; neither is copied.
10# Canonical decode-construction.request/fallible_request satisfy this request
11# shape. Error remains the caller's selected Data type, including their distinct
12# validation/constructor errors. This introduces no default retry or inverse.
13def restored(~Ctx:Type,~Factory:Type,~Rest:Type,~I:Type,~P:Type,~Error:Data,~restore:Factory -> Rest -> Ctx,rest:Rest,observed:Factory & Build.Construction<I,P,Error>) -> Ctx & Build.Construction<I,P,Error>:
14  match observed:
15    case (factory,result): (restore(factory,rest),result)
16def projected(~Ctx:Type,~Factory:Type,~Rest:Type,~I:Type,~P:Type,~Error:Data,~restore:Factory -> Rest -> Ctx,~request:Factory -> I -> Factory & Build.Construction<I,P,Error>,input:I,observed:Factory & Rest) -> Ctx & Build.Construction<I,P,Error>:
17  match observed:
18    case (factory,rest): restored(~Ctx,~Factory,~Rest,~I,~P,~Error,~restore,rest,request(factory,input))
19def head(~Ctx:Type,~Factory:Type,~Rest:Type,~I:Type,~P:Type,~Error:Data,~project:Ctx -> Factory & Rest,~restore:Factory -> Rest -> Ctx,~request:Factory -> I -> Factory & Build.Construction<I,P,Error>,ctx:Ctx,input:I) -> Ctx & Build.Construction<I,P,Error>:
20  projected(~Ctx,~Factory,~Rest,~I,~P,~Error,~restore,~request,input,project(ctx))
21# Tail is arbitrary Type. The caller recursively supplies another stage or the
22# existing terminal; this is not an unrolled family-count-specific bundle API.
23def stage(~Ctx:Type,~Factory:Type,~Rest:Type,~I:Type,~P:Type,~TR:Type,~TC:Type,~Error:Data,~project:Ctx -> Factory & Rest,~restore:Factory -> Rest -> Ctx,~request:Factory -> I -> Factory & Build.Construction<I,P,Error>,~tail:Ctx -> TR -> Build.Staged<Ctx,TR,TC,Error>,ctx:Ctx,input:Pack.Pack<I,TR>) -> Build.Staged<Ctx,Pack.Pack<I,TR>,Pack.Pack<P,TC>,Error>:
24  Build.stage(~Ctx,~I,~P,~TR,~TC,~Error,~head(~Ctx,~Factory,~Rest,~I,~P,~Error,~project,~restore,~request),~tail,ctx,input)
25
26# Actual canonical factory request, with retained runtime input codec and nominal
27# declaration. Custom constructor errors remain distinct from validation errors.
28def canonical_stage(~S:Data,~Ctx:Type,~Rest:Type,~I:Type,~P:Type,~TR:Type,~TC:Type,~Custom:Data,~identity:Identity.Declaration<S,P>,~project:P -> P & D.Raw,~incoming:I -> I & D.Raw,~build:I -> D.Raw -> Build.Construction<I,P,Custom>,~take:Ctx -> Constructor.FallibleFactory<S,I,P,Custom,identity,project,incoming,build> & Rest,~put:Constructor.FallibleFactory<S,I,P,Custom,identity,project,incoming,build> -> Rest -> Ctx,~tail:Ctx -> TR -> Build.Staged<Ctx,TR,TC,Constructor.Error<Custom>>,ctx:Ctx,input:Pack.Pack<I,TR>) -> Build.Staged<Ctx,Pack.Pack<I,TR>,Pack.Pack<P,TC>,Constructor.Error<Custom>>:
29  stage(~Ctx,~Constructor.FallibleFactory<S,I,P,Custom,identity,project,incoming,build>,~Rest,~I,~P,~TR,~TC,~Constructor.Error<Custom>,~take,~put,~(factory => input => Constructor.fallible_request(~S,~I,~P,~Custom,~identity,~project,~incoming,~build,factory,input)),~tail,ctx,input)