@@ -7,13 +7,12 @@ import { StartingWithOptions } from "../IDocumentSession";
77import { StreamCommand } from "../../Commands/StreamCommand" ;
88import { TypeUtil } from "../../../Utility/TypeUtil" ;
99import { StreamResultResponse } from "../../Commands/StreamResultResponse" ;
10- import { streamValues } from "stream-json/streamers/StreamValues" ;
11- import { ignore } from "stream-json/filters/Ignore" ;
12- import { RavenCommandResponsePipeline } from "../../../Http/RavenCommandResponsePipeline" ;
1310import { getDocumentResultsAsObjects } from "../../../Mapping/Json/Streams/Pipelines" ;
14- import { TransformKeysJsonStream } from "../../../Mapping/Json/Streams/TransformKeysJsonStream" ;
15- import { getTransformJsonKeysProfile } from "../../../Mapping/Json/Streams/TransformJsonKeysProfiles" ;
1611import { StringBuilder } from "../../../Utility/StringBuilder" ;
12+ import { ObjectUtil } from "../../../Utility/ObjectUtil" ;
13+ import { RavenCommandResponsePipeline } from "../../../Http/RavenCommandResponsePipeline" ;
14+ import { ignore } from "stream-json/filters/Ignore" ;
15+ import { streamValues } from "stream-json/streamers/StreamValues" ;
1716
1817export class StreamOperation {
1918 private readonly _session : InMemoryDocumentSessionOperations ;
@@ -50,7 +49,9 @@ export class StreamOperation {
5049 }
5150
5251 private _createRequestForIdPrefix ( idPrefix : string , opts : StartingWithOptions ) : StreamCommand {
53- const sb = new StringBuilder ( "streams/docs?" ) ;
52+ const format = this . _session . conventions . useJsonlStreaming ? 'jsonl' : 'json' ;
53+
54+ const sb = new StringBuilder ( `streams/docs?format=${ format } &` ) ;
5455 if ( idPrefix ) {
5556 sb . append ( "startsWith=" )
5657 . append ( encodeURIComponent ( idPrefix ) ) . append ( "&" ) ;
@@ -89,25 +90,34 @@ export class StreamOperation {
8990 throwError ( "IndexDoesNotExistException" , "The index does not exists, failed to stream results." ) ;
9091 }
9192
92- const result = getDocumentResultsAsObjects ( this . _session . conventions ) . stream ( response . stream ) ;
93-
93+ const result = getDocumentResultsAsObjects ( this . _session . conventions , ! ! this . _isQueryStream )
94+ . stream ( response . stream ) ;
95+
9496 if ( this . _isQueryStream ) {
95- RavenCommandResponsePipeline . create ( )
96- . parseJsonAsync ( [
97+ const pipeline = RavenCommandResponsePipeline . create < object [ ] > ( ) ;
98+
99+ this . _session . conventions . useJsonlStreaming
100+ ? pipeline . parseJsonlAsync ( 'Stats' )
101+ : pipeline . parseJsonAsync ( [
97102 ignore ( { filter : / ^ R e s u l t s | I n c l u d e s $ / } ) ,
98- new TransformKeysJsonStream ( getTransformJsonKeysProfile ( "CommandResponsePayload" ) ) ,
99103 streamValues ( )
100- ] )
101- . stream ( response . stream )
104+ ] ) ;
105+
106+ pipeline . stream ( response . stream )
102107 . on ( "error" , err => result . emit ( "error" , err ) )
103108 . on ( "data" , data => {
109+ const rawWithCamel = ObjectUtil . transformObjectKeys ( data [ "value" ] , {
110+ defaultTransform : "camel"
111+ } ) ;
112+
104113 const statsResult =
105114 this . _session . conventions . objectMapper
106- . fromObjectLiteral ( data [ "value" ] , {
115+ . fromObjectLiteral ( rawWithCamel , {
107116 nestedTypes : {
108117 indexTimestamp : "date"
109118 }
110119 } ) ;
120+
111121 result . emit ( "stats" , statsResult ) ;
112122 } ) ;
113123 }
0 commit comments