1 import Base 2 import decode_construction.bend as Constructor 3 import ordinary_declaration.bend as Identity 4 import decode_data.bend as D 5 import bundle_construction.bend as Build 6 import 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. 13 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: 14 match observed: 15 case (factory,result): (restore(factory,rest),result) 16 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: 17 match observed: 18 case (factory,rest): restored(~Ctx,~Factory,~Rest,~I,~P,~Error,~restore,rest,request(factory,input)) 19 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: 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. 23 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>: 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. 28 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>: 29 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)