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