@@ -2260,6 +2260,7 @@ Documents.prototype.suggest = function suggestDocuments() {
2260
2260
* defaultMetadata and transform.
2261
2261
* @method documents#writeAll
2262
2262
* @since 2.8.0
2263
+ * @param {stream } [stream] - stream containing the input.
2263
2264
* @param {object } [options] - Configures the write operation.
2264
2265
* @param {function(progress, documents) } [onBatchSuccess] - A callback that can notify other systems about batches
2265
2266
* written successfully.
@@ -2275,18 +2276,17 @@ Documents.prototype.suggest = function suggestDocuments() {
2275
2276
* @returns {stream.Writable } - a stream.Writable in object mode that receives document descriptor input from the
2276
2277
* application for writing to the database.
2277
2278
*/
2278
- Documents . prototype . writeAll = function writeAllDocuments ( options ) {
2279
+ Documents . prototype . writeAll = function writeAllDocuments ( stream , options ) {
2279
2280
return writeAllDocumentsImpl . call (
2280
- this , options
2281
+ this , stream , options
2281
2282
) ;
2282
2283
} ;
2283
- function writeAllDocumentsImpl ( jobOptions ) {
2284
+ function writeAllDocumentsImpl ( inputStream , jobOptions ) {
2284
2285
2285
2286
let path = '/v1/internal/forestinfo' ;
2286
2287
let connectionParams = this . client . getConnectionParams ( ) ;
2287
2288
let requestOptions = mlutil . copyProperties ( connectionParams ) ;
2288
2289
2289
- let inputStream = new stream . PassThrough ( { objectMode : true } ) ;
2290
2290
requestOptions . method = 'GET' ;
2291
2291
requestOptions . headers = {
2292
2292
'Accept' : 'application/json' ,
@@ -2345,7 +2345,7 @@ function writeAllDocumentsImpl(jobOptions) {
2345
2345
2346
2346
function finishWriter ( jobState ) {
2347
2347
jobState . requesterCount -- ;
2348
- if ( jobState . requesterCount == = 0 ) {
2348
+ if ( jobState . requesterCount < = 0 ) {
2349
2349
if ( jobState . jobOptions . onCompletion ) {
2350
2350
const summary = {
2351
2351
docsWrittenSuccessfully : jobState . docsWrittenSuccessfully ,
@@ -2380,6 +2380,7 @@ function onWriteAllInit(output) {
2380
2380
}
2381
2381
}
2382
2382
jobState . startTime = Date . now ( ) ;
2383
+ jobState . requesterCount = 0 ;
2383
2384
for ( let i = 0 ; i < maxRequesters ; i ++ ) {
2384
2385
jobState . requesterCount ++ ;
2385
2386
onWriteAllDocs ( jobState , i ) ;
@@ -2765,6 +2766,7 @@ function urisOutputTransform(headers, data) {
2765
2766
* concurrentRequests, categories, transform, onInitialTimestamp, outputStreamType and consistentSnapshot.
2766
2767
* @method documents#readAll
2767
2768
* @since 2.9.0
2769
+ * @param {stream } [stream] - stream containing the input uris.
2768
2770
* @param {object } [options] - Configures the readAll operation.
2769
2771
* @param {function(summary) } [onCompletion] - A callback that receives a summary of the results.
2770
2772
* @param {function(progress, uris, error) } [onBatchError] - A callback that responds to any error while reading a
@@ -2791,13 +2793,14 @@ function urisOutputTransform(headers, data) {
2791
2793
* object mode (for arrays of strings) and returns document descriptors with the content and/or document uri as output to
2792
2794
* the application in object mode.
2793
2795
*/
2794
- Documents . prototype . readAll = function readAllDocuments ( options ) {
2796
+ Documents . prototype . readAll = function readAllDocuments ( stream , options ) {
2797
+
2795
2798
return readAllDocumentsImpl . call (
2796
- this , options
2799
+ this , stream , options
2797
2800
) ;
2798
2801
} ;
2799
2802
2800
- function readAllDocumentsImpl ( jobOptions ) {
2803
+ function readAllDocumentsImpl ( inputStream , jobOptions ) {
2801
2804
2802
2805
let path = '/v1/internal/forestinfo' ;
2803
2806
let connectionParams = this . client . getConnectionParams ( ) ;
@@ -2829,8 +2832,7 @@ function readAllDocumentsImpl(jobOptions) {
2829
2832
throw new Error ( 'Invalid value for inputKind. Value must be array or string.' ) ;
2830
2833
}
2831
2834
}
2832
-
2833
- jobState . inputStream = new stream . PassThrough ( { objectMode : true } ) ;
2835
+ jobState . inputStream = inputStream ?inputStream :new stream . PassThrough ( { objectMode : true } ) ;
2834
2836
2835
2837
if ( jobState . jobOptions . outputStreamType ) {
2836
2838
readableObjectMode = jobState . jobOptions . outputStreamType . toString ( ) . toLowerCase ( ) ;
@@ -3242,7 +3244,7 @@ function queryToReadAllDocumentsImpl(query,jobOptions){
3242
3244
if ( ! pipelined ) {
3243
3245
pipelined = true ;
3244
3246
3245
- const readAllStream = readAllDocumentsImpl . call ( docInstance , readAllJobOptions ) ;
3247
+ const readAllStream = readAllDocumentsImpl . call ( docInstance , null , readAllJobOptions ) ;
3246
3248
readAllStream . on ( 'error' , function ( err ) {
3247
3249
queryToReadAllResultStream . emit ( err ) ;
3248
3250
} ) ;
@@ -3353,7 +3355,8 @@ function copyConstraints(suggestConstraints, searchConstraints) {
3353
3355
* The options include onCompletion, batchSize, onBatchError, inputKind, concurrentRequests, transform, onBatchSuccess
3354
3356
* and transformStrategy.
3355
3357
* @method documents#transformAll
3356
- * @since 2.10.0
3358
+ * @since 3.0.0
3359
+ * @param {stream } [stream] - stream containing the input.
3357
3360
* @param {object } [options] - Configures the transformAll operation.
3358
3361
* @param {function(summary) } [onCompletion] - A callback that receives a summary of the results.
3359
3362
* @param {function(progress, uris, error) } [onBatchError] - A callback that responds to any error while transforming a
@@ -3375,13 +3378,13 @@ function copyConstraints(suggestConstraints, searchConstraints) {
3375
3378
* @returns {stream.Writable } - returns a writable stream that takes the document uris of the database documents to be
3376
3379
* transformed.
3377
3380
*/
3378
- Documents . prototype . transformAll = function transformAllDocuments ( options ) {
3381
+ Documents . prototype . transformAll = function transformAllDocuments ( stream , options ) {
3379
3382
return transformAllDocumentsImpl . call (
3380
- this , options
3383
+ this , stream , options
3381
3384
) ;
3382
3385
} ;
3383
3386
3384
- function transformAllDocumentsImpl ( jobOptions ) {
3387
+ function transformAllDocumentsImpl ( inputStream , jobOptions ) {
3385
3388
let path = '/v1/internal/forestinfo' ;
3386
3389
let connectionParams = this . client . getConnectionParams ( ) ;
3387
3390
let requestOptions = mlutil . copyProperties ( connectionParams ) ;
@@ -3403,7 +3406,7 @@ function transformAllDocumentsImpl(jobOptions){
3403
3406
docsFailedToBeTransformed : 0 ,
3404
3407
jobOptions : ( jobOptions ) ? mlutil . copyProperties ( jobOptions ) :{ }
3405
3408
} ;
3406
-
3409
+ jobState . stream = inputStream ? inputStream : new stream . PassThrough ( { objectMode : true } ) ;
3407
3410
if ( ! jobState . jobOptions . transform ) {
3408
3411
throw new Error ( 'transform name needed while using transformAll api' ) ;
3409
3412
}
@@ -3416,12 +3419,9 @@ function transformAllDocumentsImpl(jobOptions){
3416
3419
if ( inputKindValue === 'array' && jobState . jobOptions . batchSize ) {
3417
3420
throw new Error ( 'batchSize not expected when inputKind is array.' ) ;
3418
3421
}
3419
- jobState . stream = ( inputKindValue === 'string' ) ? new stream . PassThrough ( ) :
3420
- new stream . PassThrough ( { objectMode : true } ) ;
3421
3422
jobState . inputKindValue = inputKindValue ;
3422
3423
}
3423
3424
else {
3424
- jobState . stream = new stream . PassThrough ( { objectMode : true } ) ;
3425
3425
jobState . inputKindValue = 'string' ;
3426
3426
}
3427
3427
@@ -3674,7 +3674,7 @@ function finishTransformAll(jobState) {
3674
3674
* The queryToTransformAll is a convenience function that combines the queryAll and transformAll operations.
3675
3675
* The transform used to configure the documents must be installed on the server beforehand.
3676
3676
* @method documents#queryToTransformAll
3677
- * @since 2.10 .0
3677
+ * @since 3.0 .0
3678
3678
* @param {ctsQuery } query - A query built by the ctsQueryBuilder.
3679
3679
* @param {object } [options] - Configures the queryToTransformAll operation.
3680
3680
* @param {boolean|DatabaseClient.timestamp } [consistentSnapshot] - Controls whether to get an immutable view of the result set.
@@ -3765,7 +3765,7 @@ function queryToTransformAllDocumentsImpl(query, jobOptions){
3765
3765
queryAllStream . on ( 'data' , function ( item ) {
3766
3766
if ( ! pipelined ) {
3767
3767
pipelined = true ;
3768
- const transformAllStream = transformAllDocumentsImpl . call ( docInstance , transformAllJobOptions ) ;
3768
+ const transformAllStream = transformAllDocumentsImpl . call ( docInstance , null , transformAllJobOptions ) ;
3769
3769
3770
3770
queryAllStream . on ( 'error' , function ( err ) {
3771
3771
transformAllStream . emit ( err ) ;
@@ -3779,7 +3779,8 @@ function queryToTransformAllDocumentsImpl(query, jobOptions){
3779
3779
/**
3780
3780
* The removeAllUris function deletes a set of documents from the database.
3781
3781
* @method documents#removeAllUris
3782
- * @since 2.10.0
3782
+ * @since 3.0.0
3783
+ * @param {stream } [stream] - stream containing the input uris.
3783
3784
* @param {object } [options] - Configures the removeAllUris operation.
3784
3785
* @param {function(summary) } [onCompletion] - A callback that receives a summary of the results.
3785
3786
* @param {function(progress, uris, error) } [onBatchError] - A callback that responds to any error while transforming a
@@ -3795,13 +3796,13 @@ function queryToTransformAllDocumentsImpl(query, jobOptions){
3795
3796
* @returns {stream.Writable } - a stream.Writable that receives document URI input from the application in string mode
3796
3797
* or (for arrays of strings) object mode.
3797
3798
*/
3798
- Documents . prototype . removeAllUris = function removeAllUrisDocuments ( options ) {
3799
+ Documents . prototype . removeAllUris = function removeAllUrisDocuments ( stream , options ) {
3799
3800
return removeAllUrisDocumentsImpl . call (
3800
- this , options
3801
+ this , stream , options
3801
3802
) ;
3802
3803
} ;
3803
3804
3804
- function removeAllUrisDocumentsImpl ( jobOptions ) {
3805
+ function removeAllUrisDocumentsImpl ( inputStream , jobOptions ) {
3805
3806
let path = '/v1/internal/forestinfo' ;
3806
3807
let connectionParams = this . client . getConnectionParams ( ) ;
3807
3808
let requestOptions = mlutil . copyProperties ( connectionParams ) ;
@@ -3823,7 +3824,7 @@ function removeAllUrisDocumentsImpl(jobOptions){
3823
3824
docsFailedToBeRemoved : 0 ,
3824
3825
jobOptions : ( jobOptions ) ? mlutil . copyProperties ( jobOptions ) :{ }
3825
3826
} ;
3826
-
3827
+ jobState . stream = inputStream ? inputStream : new stream . PassThrough ( { objectMode : true } ) ;
3827
3828
if ( jobState . jobOptions . inputKind ) {
3828
3829
const inputKindValue = jobState . jobOptions . inputKind . toString ( ) . toLowerCase ( ) ;
3829
3830
if ( ! new Set ( [ 'string' , 'array' ] ) . has ( inputKindValue ) ) {
@@ -3832,12 +3833,9 @@ function removeAllUrisDocumentsImpl(jobOptions){
3832
3833
if ( inputKindValue === 'array' && jobState . jobOptions . batchSize ) {
3833
3834
throw new Error ( 'batchSize not expected when inputKind is array.' ) ;
3834
3835
}
3835
- jobState . stream = ( inputKindValue === 'string' ) ? new stream . PassThrough ( ) :
3836
- new stream . PassThrough ( { objectMode : true } ) ;
3837
3836
jobState . inputKindValue = inputKindValue ;
3838
3837
}
3839
3838
else {
3840
- jobState . stream = new stream . PassThrough ( { objectMode : true } ) ;
3841
3839
jobState . inputKindValue = 'string' ;
3842
3840
}
3843
3841
@@ -4049,7 +4047,7 @@ function removeDocs(jobState, removeBatchArray, writerId){
4049
4047
/**
4050
4048
* The queryToRemoveAll is a convenience function that combines the queryAll and removeAllUris operations.
4051
4049
* @method documents#queryToRemoveAll
4052
- * @since 2.10 .0
4050
+ * @since 3.0 .0
4053
4051
* @param {ctsQuery } query - A query built by the ctsQueryBuilder.
4054
4052
* @param {object } [options] - Configures the queryToRemoveAll operation.
4055
4053
* @param {boolean|DatabaseClient.timestamp } [consistentSnapshot] - Controls whether to get an immutable view of the result set.
@@ -4129,7 +4127,7 @@ function queryToRemoveAllDocumentsImpl(query, jobOptions){
4129
4127
queryAllStream . on ( 'data' , function ( item ) {
4130
4128
if ( ! pipelined ) {
4131
4129
pipelined = true ;
4132
- const removeAllStream = removeAllUrisDocumentsImpl . call ( docInstance , removeAllJobOptions ) ;
4130
+ const removeAllStream = removeAllUrisDocumentsImpl . call ( docInstance , null , removeAllJobOptions ) ;
4133
4131
4134
4132
queryAllStream . on ( 'error' , function ( err ) {
4135
4133
removeAllStream . emit ( err ) ;
0 commit comments