11// @flow
22
3- import type Command from "~/raem/command" ;
3+ import type Command , { UniversalEvent } from "~/raem/command" ;
44import { VRef } from "~/raem/ValaaReference" ;
55
66import PartitionConnection from "~/prophet/api/PartitionConnection" ;
7- import type { NarrateOptions , MediaInfo , RetrieveMediaContent } from "~/prophet/api/Prophet" ;
7+ import type { ChronicleOptions , NarrateOptions , MediaInfo , RetrieveMediaContent }
8+ from "~/prophet/api/Prophet" ;
89
910import { dumpObject , thenChainEagerly } from "~/tools" ;
1011
11- import { _connect , _narrateEventLog } from "./_connectionOps" ;
12- import { _onConfirmTruth } from "./_downstreamOps" ;
12+ import { _connect , _chronicleEventLog , _narrateEventLog } from "./_connectionOps" ;
13+ import { _createReceiveTruthBatch , _receiveTruthOf } from "./_downstreamOps" ;
1314import { _readMediaContent , _getMediaURL , _prepareBlob } from "./_mediaOps" ;
1415
1516/**
@@ -29,8 +30,7 @@ import { _readMediaContent, _getMediaURL, _prepareBlob } from "./_mediaOps";
2930export default class OraclePartitionConnection extends PartitionConnection {
3031 _lastAuthorizedEventId : number ;
3132 _downstreamTruthQueue : Object [ ] ;
32- _authorityRetrieveMediaContent : ?RetrieveMediaContent ;
33- _narrationRetrieveMediaContent : ?RetrieveMediaContent ;
33+ _retrieveMediaContentFromAuthority : ?RetrieveMediaContent ;
3434
3535 constructor ( options : Object ) {
3636 super ( options ) ;
@@ -44,7 +44,7 @@ export default class OraclePartitionConnection extends PartitionConnection {
4444 }
4545
4646 getRetrieveMediaContent ( ) {
47- return this . _narrationRetrieveMediaContent || this . _authorityRetrieveMediaContent ;
47+ return this . _retrieveMediaContentFromAuthority ;
4848 }
4949
5050 isConnected ( ) : boolean {
@@ -85,30 +85,47 @@ export default class OraclePartitionConnection extends PartitionConnection {
8585
8686 async narrateEventLog ( options : NarrateOptions = { } ) : Promise < any > {
8787 const ret = { } ;
88- const retrievals = { } ;
8988 try {
90- return await _narrateEventLog ( this , options , ret , retrievals ) ;
89+ return await _narrateEventLog ( this , options , ret ) ;
9190 } catch ( error ) {
9291 throw this . wrapErrorEvent ( error , "narrateEventLog()" ,
9392 "\n\toptions:" , ...dumpObject ( options ) ,
9493 "\n\tcurrent ret:" , ...dumpObject ( ret ) ) ;
95- } finally {
96- if ( options . retrieveMediaContent ) {
97- delete this . _narrationRetrieveMediaContent ;
98- }
9994 }
10095 }
10196
102- async _receiveTruth ( originName : string , truthEvent : UniversalEvent ) : Promise < Object > {
97+ async chronicleEventLog ( eventLog : UniversalEvent [ ] , options : ChronicleOptions = { } ) :
98+ Promise < any > {
99+ const ret = { } ;
100+ try {
101+ return await _chronicleEventLog ( this , eventLog , options , ret ) ;
102+ } catch ( error ) {
103+ throw this . wrapErrorEvent ( error , "chronicleEventLog()" ,
104+ "\n\toptions:" , ...dumpObject ( options ) ,
105+ "\n\tcurrent ret:" , ...dumpObject ( ret ) ,
106+ ) ;
107+ }
108+ }
109+
110+ createReceiveTruth ( originName : string ) {
111+ return this . _receiveTruthOf . bind ( this , { name : originName } ) ;
112+ }
113+
114+ createReceiveTruthBatch ( batchName : string ,
115+ retrieveMediaContent : Function = this . getRetrieveMediaContent ( ) ) {
116+ return _createReceiveTruthBatch ( this , batchName , retrieveMediaContent ) ;
117+ }
118+
119+ async _receiveTruthOf ( group : Object , truthEvent : UniversalEvent ) : Promise < Object > {
103120 const partitionData = truthEvent . partitions && truthEvent . partitions [ this . partitionRawId ( ) ] ;
104121 try {
105122 if ( ! partitionData ) {
106- throw new Error ( `truthEvent is missing partition info for ${ this . debugId ( ) } ` ) ;
123+ throw new Error ( `truthEvent of ' ${ group . name } ' has no partition ${ this . debugId ( ) } info ` ) ;
107124 }
108- return _onConfirmTruth ( this , originName , authorizedEvent , partitionData ) ;
125+ return _receiveTruthOf ( this , group , partitionData . eventId , truthEvent ) ;
109126 } catch ( error ) {
110- throw this . wrapErrorEvent ( error , `_receiveTruth ('${ originName } ')` ,
111- "\n\toriginName :" , originName ,
127+ throw this . wrapErrorEvent ( error , `_receiveTruthOf ('${ group . name } ')` ,
128+ "\n\tgroup :" , ... dumpObject ( group ) ,
112129 "\n\teventId:" , partitionData && partitionData . eventId ,
113130 "\n\ttruthEvent:" , ...dumpObject ( truthEvent ) ,
114131 "\n\tthis:" , ...dumpObject ( this ) ) ;
@@ -119,8 +136,7 @@ export default class OraclePartitionConnection extends PartitionConnection {
119136 return this . getScribeConnection ( ) . claimCommandEvent ( command , this . getRetrieveMediaContent ( ) ) ;
120137 }
121138
122- _preAuthorizeCommand = ( preAuthorizedEvent : Object ) =>
123- this . _receiveTruth ( "preAuthorizer" , preAuthorizedEvent )
139+ _preAuthorizeCommand = this . createReceiveTruth ( "preAuthorizer" )
124140
125141 // Coming from downstream: tries scribe first, otherwise forwards the request to authority.
126142 // In latter case forwards the result received from authority to Scribe for caching.
0 commit comments