owned_event_family_catalog.bend
bendvy-ecs-core@0.1.0.0 · 28 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.0/owned_event_log.bend as Log
3import bendvy-ecs-core@0.1.0.0/event_stream.bend as Stream
4import bendvy-ecs-core@0.1.0.0/event_publication.bend as Publication
5import bendvy-ecs-core@0.1.0.0/owner_product.bend as Product
6
7# Trusted raw descriptor. Ordinary leaf/both derive complete matching log/stream trees.
8type Catalog<E:Data,Logs:Type,F:Type,Receipt:Type,-retain:Logs -> List<&2,E> -> Logs & Receipt,-drain:Logs -> Logs & Receipt,-clear:F -> F> is Data:Catalog{}
9def leaf_clear(~S:Data,stream:Stream.Stream<S,Nat>) -> Stream.Stream<S,Nat>:
10 match stream:
11 case Stream.Stream{domain,batches,positions,nextReader,frameStart,boundary,capacity,dropped}:Stream.Stream{domain,[],positions,nextReader,frameStart,boundary,capacity,dropped}
12def leaf(~S:Data,~P:Type) -> Catalog<Nat,Log.Log<P>,Stream.Stream<S,Nat>,List<Log.Row<P>>,Log.retain(~P),Log.drain(~P),leaf_clear(~S)>:Catalog{}
13def joined(~LA:Type,~LB:Type,~RA:Type,~RB:Type,first:LA & RA,second:LB & RB) -> Product.Owner<LA,LB> & Product.Owner<RA,RB>:
14 (first,receiptA)=first
15 (second,receiptB)=second
16 (Product.Owner{first,second},Product.Owner{receiptA,receiptB})
17def pair_retain(~EA:Data,~EB:Data,~LA:Type,~LB:Type,~RA:Type,~RB:Type,~retainA:LA -> List<&2,EA> -> LA & RA,~retainB:LB -> List<&2,EB> -> LB & RB,logs:Product.Owner<LA,LB>,records:List<&2,Publication.Publication<EA,EB>>) -> Product.Owner<LA,LB> & Product.Owner<RA,RB>:
18 match logs:
19 case Product.Owner{first,second}:
20 +shared=records
21 joined(~LA,~LB,~RA,~RB,retainA(first,Publication.first_values(~EA,~EB,shared)),retainB(second,Publication.second_values(~EA,~EB,shared)))
22def pair_drain(~LA:Type,~LB:Type,~RA:Type,~RB:Type,~drainA:LA -> LA & RA,~drainB:LB -> LB & RB,logs:Product.Owner<LA,LB>) -> Product.Owner<LA,LB> & Product.Owner<RA,RB>:
23 match logs:
24 case Product.Owner{first,second}:joined(~LA,~LB,~RA,~RB,drainA(first),drainB(second))
25def pair_clear(~FA:Type,~FB:Type,~clearA:FA -> FA,~clearB:FB -> FB,family:Product.Owner<FA,FB>) -> Product.Owner<FA,FB>:
26 match family:
27 case Product.Owner{first,second}:Product.Owner{clearA(first),clearB(second)}
28def both(~EA:Data,~LA:Type,~FA:Type,~RA:Type,~retainA:LA -> List<&2,EA> -> LA & RA,~drainA:LA -> LA & RA,~clearA:FA -> FA,~EB:Data,~LB:Type,~FB:Type,~RB:Type,~retainB:LB -> List<&2,EB> -> LB & RB,~drainB:LB -> LB & RB,~clearB:FB -> FB,~leftCatalog:Catalog<EA,LA,FA,RA,retainA,drainA,clearA>,~rightCatalog:Catalog<EB,LB,FB,RB,retainB,drainB,clearB>) -> Catalog<Publication.Publication<EA,EB>,Product.Owner<LA,LB>,Product.Owner<FA,FB>,Product.Owner<RA,RB>,pair_retain(~EA,~EB,~LA,~LB,~RA,~RB,~retainA,~retainB),pair_drain(~LA,~LB,~RA,~RB,~drainA,~drainB),pair_clear(~FA,~FB,~clearA,~clearB)>:Catalog{}