1 import Base 2 import bundle_batch.bend as BT 3 import bundle_construction.bend as CS 4 import world.bend as W 5 import schema_fragments.bend as SF 6 7 type Input is Type: 8 Input{target:W.Handle,raw:Raw} 9 type Refusal is Data: 10 ConstructionRefused{positions:List<&2,Maybe<&2,Error>>} 11 EntityRefused{error:W.WorldError} 12 DeclarationRefused{error:SF.Error} 13 type Output is Type: 14 Accepted{} 15 Refused{raw:Raw,error:Refusal} 16 type Owner is Type: 17 Owner{batch:BT.Batch,context:Context} 18 def inserted(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Error:Data,~unpack:Packet -> Raw,context:Context,result:BT.Inserted) -> Owner & Output: 19 match result: 20 case BT.Inserted{batch}: (Owner{batch,context},Accepted{}) 21 case BT.Refused{batch,packet,error}: (Owner{batch,context},Refused{unpack(packet),EntityRefused{error}}) 22 def constructed(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,batch:BT.Batch,target:W.Handle,result:CS.Staged) -> Owner & Output: 23 match result: 24 case CS.Failed{context,raw,positions}: (Owner{batch,context},Refused{raw,ConstructionRefused{positions}}) 25 case CS.Valid{context,cooked,undo,positions}: inserted(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Error,~unpack,context,BT.insert(~S,~Store,~R,~E,~Packet,batch,target,pack(cooked,undo))) 26 def request(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~construct:Context -> Raw -> CS.Staged,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,owner:Owner,input:Input) -> Owner & Output: 27 match owner input: 28 case Owner{batch,context} Input{target,raw}: constructed(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Cooked,~Error,~pack,~unpack,batch,target,construct(context,raw))