1 import Base 2 import ./execution_save_plan.bend as Plan 3 import ./execution_save_layout_field.bend as Field 4 import ./execution_save_data.bend as Saved 5 import ./execution_composer_layout.bend as Layout 6 import ./owner_product.bend as Product 7 import ./persistence_declaration.bend as Decl 8 import ./decode_data.bend as D 9 import ./execution_resource_policy.bend as Policy 10 11 def retained(-Q:Type,-Owner:Type,recipe:Q,result:Owner & Saved.Fields) -> Q & (Owner & Saved.Fields):(recipe,result) 12 def pair_returned(-LQ:Type,-RQ:Type,-LO:Type,-RO:Type,leftRecipe:LQ,leftOwner:LO,leftFields:Saved.Fields,result:RQ & (RO & Saved.Fields)) -> Product.Owner & (Product.Owner & Saved.Fields): 13 match result: 14 case (rightRecipe,(rightOwner,rightFields)):(Product.Owner{leftRecipe,rightRecipe},(Product.Owner{leftOwner,rightOwner},Saved.join(leftFields,rightFields))) 15 def pair_left(-LQ:Type,-RQ:Type,-LO:Type,-RO:Type,right:RQ -> RO -> RQ & (RO & Saved.Fields),rightRecipe:RQ,rightOwner:RO,result:LQ & (LO & Saved.Fields)) -> Product.Owner & (Product.Owner & Saved.Fields): 16 match result: 17 case (leftRecipe,(leftOwner,Saved.Fields{values,Some{error}})):(Product.Owner{leftRecipe,rightRecipe},(Product.Owner{leftOwner,rightOwner},Saved.Fields{values,Some{error}})) 18 case (leftRecipe,(leftOwner,Saved.Fields{values,None{}})):pair_returned(LQ,RQ,LO,RO,leftRecipe,leftOwner,Saved.Fields{values,None{}},right(rightRecipe,rightOwner)) 19 def pair(-LQ:Type,-RQ:Type,-LO:Type,-RO:Type,left:LQ -> LO -> LQ & (LO & Saved.Fields),right:RQ -> RO -> RQ & (RO & Saved.Fields),recipes:Product.Owner,owners:Product.Owner) -> Product.Owner & (Product.Owner & Saved.Fields): 20 match recipes owners: 21 case Product.Owner{lq,rq} Product.Owner{lo,ro}:pair_left(LQ,RQ,LO,RO,right,rq,ro,left(lq,lo)) 22 def component_pair(-LQ:Type,-RQ:Type,-LO:Type,-RO:Type,left:LQ -> U32 -> LO -> LQ & (LO & Saved.Fields),right:RQ -> U32 -> RO -> RQ & (RO & Saved.Fields),recipes:Product.Owner,+id:U32,owners:Product.Owner) -> Product.Owner & (Product.Owner & Saved.Fields): 23 pair(LQ,RQ,LO,RO,lq => lo => left(lq,id,lo),rq => ro => right(rq,id,ro),recipes,owners) 24 def component_constructed(~S:Data,-P:Type,-V:Data,-refresh:P -> P & V,+key:String,project:P -> P & D.Raw,access:Policy.Policy,declaration:Decl.Constructed,id:U32,owner:Layout.columns(~S,Plan.layout(Plan.Constructed{P,V,refresh,key,project,access}))) -> Decl.Constructed & (Layout.columns(~S,Plan.layout(Plan.Constructed{P,V,refresh,key,project,access})) & Saved.Fields): 25 match declaration: 26 case Decl.Constructed{+codec}:retained(Decl.Constructed,Layout.columns(~S,Plan.layout(Plan.Constructed{P,V,refresh,key,project,access})),Decl.Constructed{codec},Field.component(S,P,V,key,Plan.layout(Plan.Constructed{P,V,refresh,key,project,access}),Field.Constructed{codec},project,owner,id)) 27 def resource_constructed(~S:Data,-P:Type,-V:Data,-refresh:P -> P & V,+key:String,project:P -> P & D.Raw,access:Policy.Policy,declaration:Decl.Constructed,owner:Layout.resources(~S,Plan.layout(Plan.Constructed{P,V,refresh,key,project,access}))) -> Decl.Constructed & (Layout.resources(~S,Plan.layout(Plan.Constructed{P,V,refresh,key,project,access})) & Saved.Fields): 28 match declaration: 29 case Decl.Constructed{+codec}:retained(Decl.Constructed,Layout.resources(~S,Plan.layout(Plan.Constructed{P,V,refresh,key,project,access})),Decl.Constructed{codec},Field.resource(S,P,V,key,Plan.layout(Plan.Constructed{P,V,refresh,key,project,access}),Field.Constructed{codec},project,owner)) 30 def components(~S:Data,plan:Plan.Plan) -> Plan.Recipes(~S,plan) -> U32 -> Layout.columns(~S,Plan.layout(plan)) -> Plan.Recipes(~S,plan) & (Layout.columns(~S,Plan.layout(plan)) & Saved.Fields): 31 match plan: 32 case Plan.Empty{}:recipe => id => owner => (recipe,(owner,Saved.empty())) 33 case Plan.Plain{P,V,refresh,key,_}:declaration => id => owner => retained(Plan.Recipes(~S,plan),Layout.columns(~S,Plan.layout(plan)),declaration,Field.component(S,P,V,key,Plan.layout(plan),Field.Plain{},owner => (owner,D.Missing{}),owner,id)) 34 case Plan.Transient{P,V,refresh,key,_}:declaration => id => owner => retained(Plan.Recipes(~S,plan),Layout.columns(~S,Plan.layout(plan)),declaration,Field.component(S,P,V,key,Plan.layout(plan),Field.Transient{},owner => (owner,D.Missing{}),owner,id)) 35 case Plan.Constructed{P,V,refresh,key,project,access}:declaration => id => owner => component_constructed(~S,P,V,refresh,key,project,access,declaration,id,owner) 36 case Plan.Pair{left,right}:recipe => id => owner => component_pair(Plan.Recipes(~S,left),Plan.Recipes(~S,right),Layout.columns(~S,Plan.layout(left)),Layout.columns(~S,Plan.layout(right)),components(~S,left),components(~S,right),recipe,id,owner) 37 def resources(~S:Data,plan:Plan.Plan) -> Plan.Recipes(~S,plan) -> Layout.resources(~S,Plan.layout(plan)) -> Plan.Recipes(~S,plan) & (Layout.resources(~S,Plan.layout(plan)) & Saved.Fields): 38 match plan: 39 case Plan.Empty{}:recipe => owner => (recipe,(owner,Saved.empty())) 40 case Plan.Plain{P,V,refresh,key,_}:declaration => owner => retained(Plan.Recipes(~S,plan),Layout.resources(~S,Plan.layout(plan)),declaration,Field.resource(S,P,V,key,Plan.layout(plan),Field.Plain{},owner => (owner,D.Missing{}),owner)) 41 case Plan.Transient{P,V,refresh,key,_}:declaration => owner => retained(Plan.Recipes(~S,plan),Layout.resources(~S,Plan.layout(plan)),declaration,Field.resource(S,P,V,key,Plan.layout(plan),Field.Transient{},owner => (owner,D.Missing{}),owner)) 42 case Plan.Constructed{P,V,refresh,key,project,access}:declaration => owner => resource_constructed(~S,P,V,refresh,key,project,access,declaration,owner) 43 case Plan.Pair{left,right}:recipe => owner => pair(Plan.Recipes(~S,left),Plan.Recipes(~S,right),Layout.resources(~S,Plan.layout(left)),Layout.resources(~S,Plan.layout(right)),resources(~S,left),resources(~S,right),recipe,owner)