import Base import bundle_batch.bend as BT import bundle_construction.bend as CS import world.bend as W import schema_fragments.bend as SF type Input is Type: Input{target:W.Handle,raw:Raw} type Refusal is Data: ConstructionRefused{positions:List<&2,Maybe<&2,Error>>} EntityRefused{error:W.WorldError} DeclarationRefused{error:SF.Error} type Output is Type: Accepted{} Refused{raw:Raw,error:Refusal} type Owner is Type: Owner{batch:BT.Batch,context:Context} 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: match result: case BT.Inserted{batch}: (Owner{batch,context},Accepted{}) case BT.Refused{batch,packet,error}: (Owner{batch,context},Refused{unpack(packet),EntityRefused{error}}) 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: match result: case CS.Failed{context,raw,positions}: (Owner{batch,context},Refused{raw,ConstructionRefused{positions}}) 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))) 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: match owner input: case Owner{batch,context} Input{target,raw}: constructed(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Cooked,~Error,~pack,~unpack,batch,target,construct(context,raw))