@ragestudio/scylla-odm 0.22.1 → 0.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/batch/index.d.ts +3 -3
- package/batch/index.d.ts.map +1 -1
- package/batch/index.js +2 -6
- package/batch/index.js.map +1 -1
- package/client.d.ts +6 -5
- package/client.d.ts.map +1 -1
- package/client.js +26 -33
- package/client.js.map +1 -1
- package/cql_gen/create_keyspace.js +1 -4
- package/cql_gen/create_keyspace.js.map +1 -1
- package/cql_gen/create_table.d.ts +1 -1
- package/cql_gen/create_table.d.ts.map +1 -1
- package/cql_gen/create_table.js +1 -4
- package/cql_gen/create_table.js.map +1 -1
- package/document/index.d.ts +3 -3
- package/document/index.d.ts.map +1 -1
- package/document/index.js +2 -6
- package/document/index.js.map +1 -1
- package/driver/LICENSE.txt +177 -0
- package/driver/NOTICE.txt +67 -0
- package/driver/auth/index.d.ts +37 -0
- package/driver/auth/index.js +37 -0
- package/driver/auth/no-auth-provider.js +73 -0
- package/driver/auth/plain-text-auth-provider.js +81 -0
- package/driver/auth/provider.js +77 -0
- package/driver/client-options.js +442 -0
- package/driver/client.js +1267 -0
- package/driver/concurrent/index.d.ts +49 -0
- package/driver/concurrent/index.js +366 -0
- package/driver/connection.js +1034 -0
- package/driver/control-connection.js +1282 -0
- package/driver/encoder.js +2316 -0
- package/driver/errors.js +223 -0
- package/driver/execution-options.js +612 -0
- package/driver/execution-profile.js +274 -0
- package/driver/host-connection-pool.js +587 -0
- package/driver/host.js +699 -0
- package/driver/index.d.ts +387 -0
- package/driver/index.js +81 -0
- package/driver/mapping/cache.js +214 -0
- package/driver/mapping/doc-info-adapter.js +171 -0
- package/driver/mapping/index.d.ts +219 -0
- package/driver/mapping/index.js +57 -0
- package/driver/mapping/mapper.js +225 -0
- package/driver/mapping/mapping-handler.js +641 -0
- package/driver/mapping/model-batch-item.js +215 -0
- package/driver/mapping/model-batch-mapper.js +141 -0
- package/driver/mapping/model-mapper.js +315 -0
- package/driver/mapping/model-mapping-info.js +225 -0
- package/driver/mapping/object-selector.js +417 -0
- package/driver/mapping/q.js +156 -0
- package/driver/mapping/query-generator.js +556 -0
- package/driver/mapping/result-mapper.js +123 -0
- package/driver/mapping/result.js +139 -0
- package/driver/mapping/table-mappings.js +133 -0
- package/driver/mapping/tree.js +160 -0
- package/driver/metadata/aggregate.js +79 -0
- package/driver/metadata/client-state.js +119 -0
- package/driver/metadata/data-collection.js +182 -0
- package/driver/metadata/event-debouncer.js +174 -0
- package/driver/metadata/index.d.ts +276 -0
- package/driver/metadata/index.js +1156 -0
- package/driver/metadata/materialized-view.js +49 -0
- package/driver/metadata/schema-function.js +98 -0
- package/driver/metadata/schema-index.js +166 -0
- package/driver/metadata/schema-parser.js +1399 -0
- package/driver/metadata/table-metadata.js +77 -0
- package/driver/operation-state.js +206 -0
- package/driver/policies/address-resolution.js +145 -0
- package/driver/policies/index.d.ts +241 -0
- package/driver/policies/index.js +110 -0
- package/driver/policies/load-balancing.js +970 -0
- package/driver/policies/reconnection.js +166 -0
- package/driver/policies/retry.js +326 -0
- package/driver/policies/speculative-execution.js +150 -0
- package/driver/policies/timestamp-generation.js +176 -0
- package/driver/prepare-handler.js +347 -0
- package/driver/promise-utils.js +191 -0
- package/driver/readers.js +624 -0
- package/driver/request-execution.js +644 -0
- package/driver/request-handler.js +332 -0
- package/driver/requests.js +618 -0
- package/driver/stream-id-stack.js +209 -0
- package/driver/streams.js +745 -0
- package/driver/token.js +325 -0
- package/driver/tokenizer.js +631 -0
- package/driver/types/big-decimal.js +282 -0
- package/driver/types/duration.js +576 -0
- package/driver/types/index.d.ts +486 -0
- package/driver/types/index.js +733 -0
- package/driver/types/inet-address.js +262 -0
- package/driver/types/integer.js +818 -0
- package/driver/types/local-date.js +280 -0
- package/driver/types/local-time.js +299 -0
- package/driver/types/mutable-long.js +385 -0
- package/driver/types/protocol-version.js +391 -0
- package/driver/types/result-set.js +287 -0
- package/driver/types/result-stream.js +164 -0
- package/driver/types/row.js +85 -0
- package/driver/types/time-uuid.js +414 -0
- package/driver/types/tuple.js +103 -0
- package/driver/types/uuid.js +160 -0
- package/driver/types/vector.js +130 -0
- package/driver/types/version-number.js +153 -0
- package/driver/utils.js +1485 -0
- package/driver/writers.js +350 -0
- package/global.d.ts +1 -1
- package/global.d.ts.map +1 -1
- package/global.js +1 -2
- package/index.d.ts +6 -6
- package/index.d.ts.map +1 -1
- package/index.js +8 -19
- package/index.js.map +1 -1
- package/logger/index.js +2 -6
- package/logger/index.js.map +1 -1
- package/migrate/index.d.ts +1 -1
- package/migrate/index.d.ts.map +1 -1
- package/migrate/index.js +10 -53
- package/migrate/index.js.map +1 -1
- package/model/index.d.ts +6 -6
- package/model/index.d.ts.map +1 -1
- package/model/index.js +21 -28
- package/model/index.js.map +1 -1
- package/operations/countAll.d.ts +1 -1
- package/operations/countAll.d.ts.map +1 -1
- package/operations/countAll.js +1 -4
- package/operations/countAll.js.map +1 -1
- package/operations/delete.d.ts +3 -4
- package/operations/delete.d.ts.map +1 -1
- package/operations/delete.js +3 -9
- package/operations/delete.js.map +1 -1
- package/operations/find.d.ts +2 -2
- package/operations/find.d.ts.map +1 -1
- package/operations/find.js +3 -9
- package/operations/find.js.map +1 -1
- package/operations/findOne.d.ts +2 -2
- package/operations/findOne.d.ts.map +1 -1
- package/operations/findOne.js +3 -9
- package/operations/findOne.js.map +1 -1
- package/operations/insert.d.ts +3 -3
- package/operations/insert.d.ts.map +1 -1
- package/operations/insert.js +5 -11
- package/operations/insert.js.map +1 -1
- package/operations/sync.d.ts +1 -1
- package/operations/sync.d.ts.map +1 -1
- package/operations/sync.js +3 -9
- package/operations/sync.js.map +1 -1
- package/operations/tableExists.d.ts +1 -1
- package/operations/tableExists.d.ts.map +1 -1
- package/operations/tableExists.js +1 -4
- package/operations/tableExists.js.map +1 -1
- package/operations/update.d.ts +3 -3
- package/operations/update.d.ts.map +1 -1
- package/operations/update.js +5 -11
- package/operations/update.js.map +1 -1
- package/package.json +4 -12
- package/schema/index.d.ts +1 -1
- package/schema/index.d.ts.map +1 -1
- package/schema/index.js +2 -6
- package/schema/index.js.map +1 -1
- package/types.d.ts +4 -4
- package/types.d.ts.map +1 -1
- package/types.js +3 -7
- package/types.js.map +1 -1
- package/utils/buildMapper.js +1 -3
- package/utils/buildMapper.js.map +1 -1
- package/utils/delay.js +2 -5
- package/utils/delay.js.map +1 -1
- package/utils/fillDefaults.js +1 -4
- package/utils/fillDefaults.js.map +1 -1
- package/utils/isPlainObject.js +1 -3
- package/utils/isPlainObject.js.map +1 -1
- package/utils/loadModels.js +7 -45
- package/utils/loadModels.js.map +1 -1
- package/utils/queryParser.d.ts +1 -1
- package/utils/queryParser.d.ts.map +1 -1
- package/utils/queryParser.js +7 -15
- package/utils/queryParser.js.map +1 -1
- package/utils/typeChecker.d.ts +1 -1
- package/utils/typeChecker.d.ts.map +1 -1
- package/utils/typeChecker.js +5 -11
- package/utils/typeChecker.js.map +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { Client } from ".."
|
|
20
|
+
import { Readable } from "stream"
|
|
21
|
+
|
|
22
|
+
export namespace concurrent {
|
|
23
|
+
interface ResultSetGroup {
|
|
24
|
+
errors: Error[]
|
|
25
|
+
resultItems: any[]
|
|
26
|
+
totalExecuted: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Options = {
|
|
30
|
+
collectResults?: boolean
|
|
31
|
+
concurrencyLevel?: number
|
|
32
|
+
executionProfile?: string
|
|
33
|
+
maxErrors?: number
|
|
34
|
+
raiseOnFirstError?: boolean
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function executeConcurrent(
|
|
38
|
+
client: Client,
|
|
39
|
+
query: string,
|
|
40
|
+
parameters: any[][] | Readable,
|
|
41
|
+
options?: Options,
|
|
42
|
+
): Promise<ResultSetGroup>
|
|
43
|
+
|
|
44
|
+
function executeConcurrent(
|
|
45
|
+
client: Client,
|
|
46
|
+
queries: Array<{ query: string; params: any[] }>,
|
|
47
|
+
options?: Options,
|
|
48
|
+
): Promise<ResultSetGroup>
|
|
49
|
+
}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { Stream } from "stream"
|
|
20
|
+
import utils from "../utils.js"
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Utilities for concurrent query execution with the DataStax Node Driver.
|
|
24
|
+
* @module concurrent
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Executes multiple queries concurrently at the defined concurrency level.
|
|
29
|
+
* @static
|
|
30
|
+
* @param {Client} client The {@link Client} instance.
|
|
31
|
+
* @param {String|Array<{query, params}>} query The query to execute per each parameter item.
|
|
32
|
+
* @param {Array<Array>|Stream|Object} parameters An {@link Array} or a readable {@link Stream} composed of {@link Array}
|
|
33
|
+
* items representing each individual set of parameters. Per each item in the {@link Array} or {@link Stream}, an
|
|
34
|
+
* execution is going to be made.
|
|
35
|
+
* @param {Object} [options] The execution options.
|
|
36
|
+
* @param {String} [options.executionProfile] The execution profile to be used.
|
|
37
|
+
* @param {Number} [options.concurrencyLevel=100] The concurrency level to determine the maximum amount of in-flight
|
|
38
|
+
* operations at any given time
|
|
39
|
+
* @param {Boolean} [options.raiseOnFirstError=true] Determines whether execution should stop after the first failed
|
|
40
|
+
* execution and the corresponding exception will be raised.
|
|
41
|
+
* @param {Boolean} [options.collectResults=false] Determines whether each individual
|
|
42
|
+
* [ResultSet]{@link module:types~ResultSet} instance should be collected in the grouped result.
|
|
43
|
+
* @param {Number} [options.maxErrors=100] The maximum amount of errors to be collected before ignoring the rest of
|
|
44
|
+
* the error results.
|
|
45
|
+
* @returns {Promise<ResultSetGroup>} A <code>Promise</code> of {@link ResultSetGroup} that is resolved when all the
|
|
46
|
+
* executions completed and it's rejected when <code>raiseOnFirstError</code> is <code>true</code> and there is one
|
|
47
|
+
* or more failures.
|
|
48
|
+
* @example <caption>Using a fixed query and an Array of Arrays as parameters</caption>
|
|
49
|
+
* const query = 'INSERT INTO table1 (id, value) VALUES (?, ?)';
|
|
50
|
+
* const parameters = [[1, 'a'], [2, 'b'], [3, 'c'], ]; // ...
|
|
51
|
+
* const result = await executeConcurrent(client, query, parameters);
|
|
52
|
+
* @example <caption>Using a fixed query and a readable stream</caption>
|
|
53
|
+
* const stream = csvStream.pipe(transformLineToArrayStream);
|
|
54
|
+
* const result = await executeConcurrent(client, query, stream);
|
|
55
|
+
* @example <caption>Using a different queries</caption>
|
|
56
|
+
* const queryAndParameters = [
|
|
57
|
+
* { query: 'INSERT INTO videos (id, name, user_id) VALUES (?, ?, ?)',
|
|
58
|
+
* params: [ id, name, userId ] },
|
|
59
|
+
* { query: 'INSERT INTO user_videos (user_id, id, name) VALUES (?, ?, ?)',
|
|
60
|
+
* params: [ userId, id, name ] },
|
|
61
|
+
* { query: 'INSERT INTO latest_videos (id, name, user_id) VALUES (?, ?, ?)',
|
|
62
|
+
* params: [ id, name, userId ] },
|
|
63
|
+
* ];
|
|
64
|
+
*
|
|
65
|
+
* const result = await executeConcurrent(client, queryAndParameters);
|
|
66
|
+
*/
|
|
67
|
+
function executeConcurrent(client, query, parameters, options) {
|
|
68
|
+
if (!client) {
|
|
69
|
+
throw new TypeError("Client instance is not defined")
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (typeof query === "string") {
|
|
73
|
+
if (Array.isArray(parameters)) {
|
|
74
|
+
return new ArrayBasedExecutor(
|
|
75
|
+
client,
|
|
76
|
+
query,
|
|
77
|
+
parameters,
|
|
78
|
+
options,
|
|
79
|
+
).execute()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (parameters instanceof Stream) {
|
|
83
|
+
return new StreamBasedExecutor(
|
|
84
|
+
client,
|
|
85
|
+
query,
|
|
86
|
+
parameters,
|
|
87
|
+
options,
|
|
88
|
+
).execute()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
throw new TypeError(
|
|
92
|
+
"parameters should be an Array or a Stream instance",
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (Array.isArray(query)) {
|
|
97
|
+
options = parameters
|
|
98
|
+
return new ArrayBasedExecutor(client, null, query, options).execute()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
throw new TypeError(
|
|
102
|
+
"A string query or query and parameters array should be provided",
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Wraps the functionality to execute given an Array.
|
|
108
|
+
* @ignore
|
|
109
|
+
*/
|
|
110
|
+
class ArrayBasedExecutor {
|
|
111
|
+
/**
|
|
112
|
+
* @param {Client} client
|
|
113
|
+
* @param {String} query
|
|
114
|
+
* @param {Array<Array>|Array<{query, params}>} parameters
|
|
115
|
+
* @param {Object} [options] The execution options.
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
constructor(client, query, parameters, options) {
|
|
119
|
+
this._client = client
|
|
120
|
+
this._query = query
|
|
121
|
+
this._parameters = parameters
|
|
122
|
+
options = options || utils.emptyObject
|
|
123
|
+
this._raiseOnFirstError = options.raiseOnFirstError !== false
|
|
124
|
+
this._concurrencyLevel = Math.min(
|
|
125
|
+
options.concurrencyLevel || 100,
|
|
126
|
+
this._parameters.length,
|
|
127
|
+
)
|
|
128
|
+
this._queryOptions = {
|
|
129
|
+
prepare: true,
|
|
130
|
+
executionProfile: options.executionProfile,
|
|
131
|
+
}
|
|
132
|
+
this._result = new ResultSetGroup(options)
|
|
133
|
+
this._stop = false
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
execute() {
|
|
137
|
+
const promises = new Array(this._concurrencyLevel)
|
|
138
|
+
|
|
139
|
+
for (let i = 0; i < this._concurrencyLevel; i++) {
|
|
140
|
+
promises[i] = this._executeOneAtATime(i, 0)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return Promise.all(promises).then(() => this._result)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
_executeOneAtATime(initialIndex, iteration) {
|
|
147
|
+
const index = initialIndex + this._concurrencyLevel * iteration
|
|
148
|
+
|
|
149
|
+
if (index >= this._parameters.length || this._stop) {
|
|
150
|
+
return Promise.resolve()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const item = this._parameters[index]
|
|
154
|
+
let query
|
|
155
|
+
let params
|
|
156
|
+
|
|
157
|
+
if (this._query === null) {
|
|
158
|
+
query = item.query
|
|
159
|
+
params = item.params
|
|
160
|
+
} else {
|
|
161
|
+
query = this._query
|
|
162
|
+
params = item
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return this._client
|
|
166
|
+
.execute(query, params, this._queryOptions)
|
|
167
|
+
.then((rs) => this._result.setResultItem(index, rs))
|
|
168
|
+
.catch((err) => this._setError(index, err))
|
|
169
|
+
.then(() => this._executeOneAtATime(initialIndex, iteration + 1))
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
_setError(index, err) {
|
|
173
|
+
this._result.setError(index, err)
|
|
174
|
+
|
|
175
|
+
if (this._raiseOnFirstError) {
|
|
176
|
+
this._stop = true
|
|
177
|
+
throw err
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Wraps the functionality to execute given a Stream.
|
|
184
|
+
* @ignore
|
|
185
|
+
*/
|
|
186
|
+
class StreamBasedExecutor {
|
|
187
|
+
/**
|
|
188
|
+
* @param {Client} client
|
|
189
|
+
* @param {String} query
|
|
190
|
+
* @param {Stream} stream
|
|
191
|
+
* @param {Object} [options] The execution options.
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
constructor(client, query, stream, options) {
|
|
195
|
+
this._client = client
|
|
196
|
+
this._query = query
|
|
197
|
+
this._stream = stream
|
|
198
|
+
options = options || utils.emptyObject
|
|
199
|
+
this._raiseOnFirstError = options.raiseOnFirstError !== false
|
|
200
|
+
this._concurrencyLevel = options.concurrencyLevel || 100
|
|
201
|
+
this._queryOptions = {
|
|
202
|
+
prepare: true,
|
|
203
|
+
executionProfile: options.executionProfile,
|
|
204
|
+
}
|
|
205
|
+
this._inFlight = 0
|
|
206
|
+
this._index = 0
|
|
207
|
+
this._result = new ResultSetGroup(options)
|
|
208
|
+
this._resolveCallback = null
|
|
209
|
+
this._rejectCallback = null
|
|
210
|
+
this._readEnded = false
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
execute() {
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
this._resolveCallback = resolve
|
|
216
|
+
this._rejectCallback = reject
|
|
217
|
+
|
|
218
|
+
this._stream
|
|
219
|
+
.on("data", (params) => this._executeOne(params))
|
|
220
|
+
.on("error", (err) => this._setReadEnded(err))
|
|
221
|
+
.on("end", () => this._setReadEnded())
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
_executeOne(params) {
|
|
226
|
+
if (!Array.isArray(params)) {
|
|
227
|
+
return this._setReadEnded(
|
|
228
|
+
new TypeError(
|
|
229
|
+
"Stream should be in objectMode and should emit Array instances",
|
|
230
|
+
),
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (this._readEnded) {
|
|
235
|
+
// Read ended abruptly because of incorrect format or error event being emitted.
|
|
236
|
+
// We shouldn't consider additional items.
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const index = this._index++
|
|
241
|
+
this._inFlight++
|
|
242
|
+
|
|
243
|
+
this._client
|
|
244
|
+
.execute(this._query, params, this._queryOptions)
|
|
245
|
+
.then((rs) => {
|
|
246
|
+
this._result.setResultItem(index, rs)
|
|
247
|
+
this._inFlight--
|
|
248
|
+
})
|
|
249
|
+
.catch((err) => {
|
|
250
|
+
this._inFlight--
|
|
251
|
+
this._setError(index, err)
|
|
252
|
+
})
|
|
253
|
+
.then(() => {
|
|
254
|
+
if (this._stream.isPaused()) {
|
|
255
|
+
this._stream.resume()
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (this._readEnded && this._inFlight === 0) {
|
|
259
|
+
// When read ended and there are no more in-flight requests
|
|
260
|
+
// We yield the result to the user.
|
|
261
|
+
// It could have ended prematurely when there is a read error
|
|
262
|
+
// or there was an execution error and raiseOnFirstError is true
|
|
263
|
+
// In that case, calling the resolve callback has no effect
|
|
264
|
+
this._resolveCallback(this._result)
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
if (this._inFlight >= this._concurrencyLevel) {
|
|
269
|
+
this._stream.pause()
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Marks the stream read process as ended.
|
|
275
|
+
* @param {Error} [err] The stream read error.
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
_setReadEnded(err) {
|
|
279
|
+
if (!this._readEnded) {
|
|
280
|
+
this._readEnded = true
|
|
281
|
+
|
|
282
|
+
if (err) {
|
|
283
|
+
// There was an error while reading from the input stream.
|
|
284
|
+
// This should be surfaced as a failure
|
|
285
|
+
this._rejectCallback(err)
|
|
286
|
+
} else if (this._inFlight === 0) {
|
|
287
|
+
// Ended signaled and there are no more pending messages.
|
|
288
|
+
this._resolveCallback(this._result)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
_setError(index, err) {
|
|
294
|
+
this._result.setError(index, err)
|
|
295
|
+
|
|
296
|
+
if (this._raiseOnFirstError) {
|
|
297
|
+
this._readEnded = true
|
|
298
|
+
this._rejectCallback(err)
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Represents results from different related executions.
|
|
305
|
+
*/
|
|
306
|
+
class ResultSetGroup {
|
|
307
|
+
/**
|
|
308
|
+
* Creates a new instance of {@link ResultSetGroup}.
|
|
309
|
+
* @ignore
|
|
310
|
+
*/
|
|
311
|
+
constructor(options) {
|
|
312
|
+
this._collectResults = options.collectResults
|
|
313
|
+
this._maxErrors = options.maxErrors || 100
|
|
314
|
+
this.totalExecuted = 0
|
|
315
|
+
this.errors = []
|
|
316
|
+
|
|
317
|
+
if (this._collectResults) {
|
|
318
|
+
/**
|
|
319
|
+
* Gets an {@link Array} containing the [ResultSet]{@link module:types~ResultSet} instances from each execution.
|
|
320
|
+
* <p>
|
|
321
|
+
* Note that when <code>collectResults</code> is set to <code>false</code>, accessing this property will
|
|
322
|
+
* throw an error.
|
|
323
|
+
* </p>
|
|
324
|
+
* @type {Array}
|
|
325
|
+
*/
|
|
326
|
+
this.resultItems = []
|
|
327
|
+
} else {
|
|
328
|
+
Object.defineProperty(this, "resultItems", {
|
|
329
|
+
enumerable: false,
|
|
330
|
+
get: () => {
|
|
331
|
+
throw new Error(
|
|
332
|
+
"Property resultItems can not be accessed when collectResults is set to false",
|
|
333
|
+
)
|
|
334
|
+
},
|
|
335
|
+
})
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** @ignore */
|
|
340
|
+
setResultItem(index, rs) {
|
|
341
|
+
this.totalExecuted++
|
|
342
|
+
|
|
343
|
+
if (this._collectResults) {
|
|
344
|
+
this.resultItems[index] = rs
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Internal method to set the error of an execution.
|
|
350
|
+
* @ignore
|
|
351
|
+
*/
|
|
352
|
+
setError(index, err) {
|
|
353
|
+
this.totalExecuted++
|
|
354
|
+
|
|
355
|
+
if (this.errors.length < this._maxErrors) {
|
|
356
|
+
this.errors.push(err)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (this._collectResults) {
|
|
360
|
+
this.resultItems[index] = err
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export { executeConcurrent, ResultSetGroup }
|
|
366
|
+
export default { executeConcurrent, ResultSetGroup }
|