1 import Base 2 import ./owned_event_log.bend as Log 3 import ./event_stream.bend as Stream 4 import ./event_publication.bend as Publication 5 import ./owner_product.bend as Product 6 7 # Trusted raw descriptor. Ordinary leaf/both derive complete matching log/stream trees. 8 type Catalog List<&2,E> -> Logs & Receipt,-drain:Logs -> Logs & Receipt,-clear:F -> F> is Data:Catalog{} 9 def leaf_clear(~S:Data,stream:Stream.Stream) -> Stream.Stream: 10 match stream: 11 case Stream.Stream{domain,batches,positions,nextReader,frameStart,boundary,capacity,dropped}:Stream.Stream{domain,[],positions,nextReader,frameStart,boundary,capacity,dropped} 12 def leaf(~S:Data,~P:Type) -> Catalog,Stream.Stream,List>,Log.retain(~P),Log.drain(~P),leaf_clear(~S)>:Catalog{} 13 def joined(~LA:Type,~LB:Type,~RA:Type,~RB:Type,first:LA & RA,second:LB & RB) -> Product.Owner & Product.Owner: 14 (first,receiptA)=first 15 (second,receiptB)=second 16 (Product.Owner{first,second},Product.Owner{receiptA,receiptB}) 17 def 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,records:List<&2,Publication.Publication>) -> Product.Owner & Product.Owner: 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))) 22 def pair_drain(~LA:Type,~LB:Type,~RA:Type,~RB:Type,~drainA:LA -> LA & RA,~drainB:LB -> LB & RB,logs:Product.Owner) -> Product.Owner & Product.Owner: 23 match logs: 24 case Product.Owner{first,second}:joined(~LA,~LB,~RA,~RB,drainA(first),drainB(second)) 25 def pair_clear(~FA:Type,~FB:Type,~clearA:FA -> FA,~clearB:FB -> FB,family:Product.Owner) -> Product.Owner: 26 match family: 27 case Product.Owner{first,second}:Product.Owner{clearA(first),clearB(second)} 28 def 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,~rightCatalog:Catalog) -> Catalog,Product.Owner,Product.Owner,Product.Owner,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{}