bundle_requests.bend
bendvy-ecs-core@0.1.0.0 · 34 lines · 0 definitions
1import Base
2import bundle_insert_adapter.bend as AD
3import bundle_construction.bend as CS
4import bundle_batch.bend as BT
5import world.bend as W
6
7# Additive command route: nominal public handles remain fixed before abstract H.
8type Operation<S:Data> is Data:
9 Spawn{}
10 Insert{target:W.Handle<S>}
11type Input<S:Data,Raw:Type> is Type:
12 Input{operation:Operation<S>,raw:Raw}
13type Output<S:Data,Raw:Type,Error:Data> is Type:
14 Accepted{target:W.Handle<S>,spawned:Bool}
15 Refused{raw:Raw,error:AD.Refusal<Error>}
16def inserted(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Error:Data,~unpack:Packet -> Raw,context:Context,target:W.Handle<S>,result:BT.Inserted<S,Store,R,E,Packet>) -> AD.Owner<S,Store,R,E,Packet,Context> & Output<S,Raw,Error>:
17 match result:
18 case BT.Inserted{batch}: (AD.Owner{batch,context},Accepted{target,False{}})
19 case BT.Refused{batch,packet,error}: (AD.Owner{batch,context},Refused{unpack(packet),AD.EntityRefused{error}})
20def spawned(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Error:Data,~unpack:Packet -> Raw,context:Context,result:BT.Spawned<S,Store,R,E,Packet>) -> AD.Owner<S,Store,R,E,Packet,Context> & Output<S,Raw,Error>:
21 match result:
22 case BT.Spawned{batch,target}: (AD.Owner{batch,context},Accepted{target,True{}})
23 case BT.SpawnRefused{batch,packet,error}: (AD.Owner{batch,context},Refused{unpack(packet),AD.EntityRefused{error}})
24def enqueue(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Error:Data,~unpack:Packet -> Raw,batch:BT.Batch<S,Store,R,E,Packet>,context:Context,operation:Operation<S>,packet:Packet) -> AD.Owner<S,Store,R,E,Packet,Context> & Output<S,Raw,Error>:
25 match operation:
26 case Spawn{}: spawned(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Error,~unpack,context,BT.spawn(~S,~Store,~R,~E,~Packet,batch,packet))
27 case Insert{+target}: inserted(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Error,~unpack,context,target,BT.insert(~S,~Store,~R,~E,~Packet,batch,target,packet))
28def 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<S,Store,R,E,Packet>,operation:Operation<S>,result:CS.Staged<Context,Raw,Cooked,Error>) -> AD.Owner<S,Store,R,E,Packet,Context> & Output<S,Raw,Error>:
29 match result:
30 case CS.Failed{context,raw,positions}: (AD.Owner{batch,context},Refused{raw,AD.ConstructionRefused{positions}})
31 case CS.Valid{context,cooked,undo,positions}: enqueue(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Error,~unpack,batch,context,operation,pack(cooked,undo))
32def request(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~construct:Context -> Raw -> CS.Staged<Context,Raw,Cooked,Error>,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,owner:AD.Owner<S,Store,R,E,Packet,Context>,input:Input<S,Raw>) -> AD.Owner<S,Store,R,E,Packet,Context> & Output<S,Raw,Error>:
33 match owner input:
34 case AD.Owner{batch,context} Input{operation,raw}: constructed(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Cooked,~Error,~pack,~unpack,batch,operation,construct(context,raw))