@ragestudio/scylla-odm 0.22.2 → 0.22.4
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/client.d.ts +6 -5
- package/client.d.ts.map +1 -1
- package/client.js +11 -12
- package/client.js.map +1 -1
- package/cql_gen/create_table.d.ts +1 -1
- package/cql_gen/create_table.d.ts.map +1 -1
- package/document/index.d.ts +3 -3
- package/document/index.d.ts.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/index.d.ts +6 -6
- package/index.d.ts.map +1 -1
- package/index.js +6 -6
- package/index.js.map +1 -1
- package/migrate/index.d.ts +1 -1
- package/migrate/index.d.ts.map +1 -1
- package/migrate/index.js +1 -1
- 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 +10 -10
- package/model/index.js.map +1 -1
- package/operations/countAll.d.ts +1 -1
- package/operations/countAll.d.ts.map +1 -1
- package/operations/delete.d.ts +3 -4
- package/operations/delete.d.ts.map +1 -1
- package/operations/delete.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +2 -2
- 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 +1 -1
- package/operations/sync.js.map +1 -1
- package/operations/tableExists.d.ts +1 -1
- package/operations/tableExists.d.ts.map +1 -1
- package/operations/update.d.ts +3 -3
- package/operations/update.d.ts.map +1 -1
- package/operations/update.js +2 -2
- 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/types.d.ts +4 -4
- package/types.d.ts.map +1 -1
- package/utils/queryParser.d.ts +1 -1
- package/utils/queryParser.d.ts.map +1 -1
- package/utils/queryParser.js +1 -1
- 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 +1 -1
- package/utils/typeChecker.js.map +1 -1
|
@@ -0,0 +1,624 @@
|
|
|
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 util from "util"
|
|
20
|
+
import utils from "./utils.js"
|
|
21
|
+
import types from "./types/index.js"
|
|
22
|
+
import errors from "./errors.js"
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Information on the formatting of the returned rows
|
|
26
|
+
*/
|
|
27
|
+
const resultFlag = {
|
|
28
|
+
globalTablesSpec: 0x0001,
|
|
29
|
+
hasMorePages: 0x0002,
|
|
30
|
+
noMetadata: 0x0004,
|
|
31
|
+
metadataChanged: 0x0008,
|
|
32
|
+
continuousPaging: 0x40000000,
|
|
33
|
+
lastContinuousPage: 0x80000000,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// templates for derived error messages.
|
|
37
|
+
const _writeTimeoutQueryMessage =
|
|
38
|
+
"Server timeout during write query at consistency %s (%d peer(s) acknowledged the write over %d required)"
|
|
39
|
+
const _writeTimeoutBatchLogMessage =
|
|
40
|
+
"Server timeout during batchlog write at consistency %s (%d peer(s) acknowledged the write over %d required)"
|
|
41
|
+
const _writeFailureMessage =
|
|
42
|
+
"Server failure during write query at consistency %s (%d responses were required but only %d replicas responded, %d failed)"
|
|
43
|
+
const _unavailableMessage =
|
|
44
|
+
"Not enough replicas available for query at consistency %s (%d required but only %d alive)"
|
|
45
|
+
const _readTimeoutMessage =
|
|
46
|
+
"Server timeout during read query at consistency %s (%s)"
|
|
47
|
+
const _readFailureMessage =
|
|
48
|
+
"Server failure during read query at consistency %s (%d responses were required but only %d replicas responded, %d failed)"
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Buffer forward reader of CQL binary frames
|
|
52
|
+
* @param {FrameHeader} header
|
|
53
|
+
* @param {Buffer} body
|
|
54
|
+
* @param {Number} [offset]
|
|
55
|
+
*/
|
|
56
|
+
class FrameReader {
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new instance of the reader
|
|
59
|
+
* @param {FrameHeader} header
|
|
60
|
+
* @param {Buffer} body
|
|
61
|
+
* @param {Number} [offset]
|
|
62
|
+
*/
|
|
63
|
+
constructor(header, body, offset) {
|
|
64
|
+
this.header = header
|
|
65
|
+
this.opcode = header.opcode
|
|
66
|
+
this.offset = offset || 0
|
|
67
|
+
this.buf = body
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
remainingLength() {
|
|
71
|
+
return this.buf.length - this.offset
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getBuffer() {
|
|
75
|
+
return this.buf
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Slices the underlining buffer
|
|
80
|
+
* @param {Number} begin
|
|
81
|
+
* @param {Number} [end]
|
|
82
|
+
* @returns {Buffer}
|
|
83
|
+
*/
|
|
84
|
+
slice(begin, end) {
|
|
85
|
+
if (typeof end === "undefined") {
|
|
86
|
+
end = this.buf.length
|
|
87
|
+
}
|
|
88
|
+
return this.buf.slice(begin, end)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Modifies the underlying buffer, it concatenates the given buffer with the original (internalBuffer = concat(bytes, internalBuffer)
|
|
93
|
+
*/
|
|
94
|
+
unshift(bytes) {
|
|
95
|
+
if (this.offset > 0) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
"Can not modify the underlying buffer if already read",
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
this.buf = Buffer.concat(
|
|
101
|
+
[bytes, this.buf],
|
|
102
|
+
bytes.length + this.buf.length,
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Reads any number of bytes and moves the offset.
|
|
108
|
+
* if length not provided or it's larger than the remaining bytes, reads to end.
|
|
109
|
+
* @param length
|
|
110
|
+
* @returns {Buffer}
|
|
111
|
+
*/
|
|
112
|
+
read(length) {
|
|
113
|
+
let end = this.buf.length
|
|
114
|
+
if (
|
|
115
|
+
typeof length !== "undefined" &&
|
|
116
|
+
this.offset + length < this.buf.length
|
|
117
|
+
) {
|
|
118
|
+
end = this.offset + length
|
|
119
|
+
}
|
|
120
|
+
const bytes = this.slice(this.offset, end)
|
|
121
|
+
this.offset = end
|
|
122
|
+
return bytes
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Moves the reader cursor to the end
|
|
127
|
+
*/
|
|
128
|
+
toEnd() {
|
|
129
|
+
this.offset = this.buf.length
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Reads a BE Int and moves the offset
|
|
134
|
+
* @returns {Number}
|
|
135
|
+
*/
|
|
136
|
+
readInt() {
|
|
137
|
+
const result = this.buf.readInt32BE(this.offset)
|
|
138
|
+
this.offset += 4
|
|
139
|
+
return result
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** @returns {Number} */
|
|
143
|
+
readShort() {
|
|
144
|
+
const result = this.buf.readUInt16BE(this.offset)
|
|
145
|
+
this.offset += 2
|
|
146
|
+
return result
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
readByte() {
|
|
150
|
+
const result = this.buf.readUInt8(this.offset)
|
|
151
|
+
this.offset += 1
|
|
152
|
+
return result
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
readString() {
|
|
156
|
+
const length = this.readShort()
|
|
157
|
+
this.checkOffset(length)
|
|
158
|
+
const result = this.buf.toString(
|
|
159
|
+
"utf8",
|
|
160
|
+
this.offset,
|
|
161
|
+
this.offset + length,
|
|
162
|
+
)
|
|
163
|
+
this.offset += length
|
|
164
|
+
return result
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Checks that the new length to read is within the range of the buffer length. Throws a RangeError if not.
|
|
169
|
+
* @param {Number} newLength
|
|
170
|
+
*/
|
|
171
|
+
checkOffset(newLength) {
|
|
172
|
+
if (this.offset + newLength > this.buf.length) {
|
|
173
|
+
const err = new RangeError("Trying to access beyond buffer length")
|
|
174
|
+
err.expectedLength = newLength
|
|
175
|
+
throw err
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Reads a protocol string list
|
|
181
|
+
* @returns {Array}
|
|
182
|
+
*/
|
|
183
|
+
readStringList() {
|
|
184
|
+
const length = this.readShort()
|
|
185
|
+
const list = new Array(length)
|
|
186
|
+
for (let i = 0; i < length; i++) {
|
|
187
|
+
list[i] = this.readString()
|
|
188
|
+
}
|
|
189
|
+
return list
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Reads the amount of bytes that the field has and returns them (slicing them).
|
|
194
|
+
* @returns {Buffer}
|
|
195
|
+
*/
|
|
196
|
+
readBytes() {
|
|
197
|
+
const length = this.readInt()
|
|
198
|
+
if (length < 0) {
|
|
199
|
+
return null
|
|
200
|
+
}
|
|
201
|
+
this.checkOffset(length)
|
|
202
|
+
return this.read(length)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
readShortBytes() {
|
|
206
|
+
const length = this.readShort()
|
|
207
|
+
if (length < 0) {
|
|
208
|
+
return null
|
|
209
|
+
}
|
|
210
|
+
this.checkOffset(length)
|
|
211
|
+
return this.read(length)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Reads an associative array of strings as keys and bytes as values
|
|
216
|
+
* @param {Number} length
|
|
217
|
+
* @param {Function} keyFn
|
|
218
|
+
* @param {Function} valueFn
|
|
219
|
+
* @returns {Object}
|
|
220
|
+
*/
|
|
221
|
+
readMap(length, keyFn, valueFn) {
|
|
222
|
+
if (length < 0) {
|
|
223
|
+
return null
|
|
224
|
+
}
|
|
225
|
+
const map = {}
|
|
226
|
+
for (let i = 0; i < length; i++) {
|
|
227
|
+
map[keyFn.call(this)] = valueFn.call(this)
|
|
228
|
+
}
|
|
229
|
+
return map
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Reads an associative array of strings as keys and string lists as values
|
|
234
|
+
* @returns {Object}
|
|
235
|
+
*/
|
|
236
|
+
readStringMultiMap() {
|
|
237
|
+
//A [short] n, followed by n pair <k><v> where <k> is a
|
|
238
|
+
//[string] and <v> is a [string[]].
|
|
239
|
+
const length = this.readShort()
|
|
240
|
+
if (length < 0) {
|
|
241
|
+
return null
|
|
242
|
+
}
|
|
243
|
+
const map = {}
|
|
244
|
+
for (let i = 0; i < length; i++) {
|
|
245
|
+
map[this.readString()] = this.readStringList()
|
|
246
|
+
}
|
|
247
|
+
return map
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Reads a data type definition
|
|
252
|
+
* @returns {{code: Number, info: Object|null}} An array of 2 elements
|
|
253
|
+
*/
|
|
254
|
+
readType() {
|
|
255
|
+
let i
|
|
256
|
+
const type = {
|
|
257
|
+
code: this.readShort(),
|
|
258
|
+
type: null,
|
|
259
|
+
}
|
|
260
|
+
switch (type.code) {
|
|
261
|
+
case types.dataTypes.custom:
|
|
262
|
+
type.info = this.readString()
|
|
263
|
+
break
|
|
264
|
+
case types.dataTypes.list:
|
|
265
|
+
case types.dataTypes.set:
|
|
266
|
+
type.info = this.readType()
|
|
267
|
+
break
|
|
268
|
+
case types.dataTypes.map:
|
|
269
|
+
type.info = [this.readType(), this.readType()]
|
|
270
|
+
break
|
|
271
|
+
case types.dataTypes.udt:
|
|
272
|
+
type.info = {
|
|
273
|
+
keyspace: this.readString(),
|
|
274
|
+
name: this.readString(),
|
|
275
|
+
fields: new Array(this.readShort()),
|
|
276
|
+
}
|
|
277
|
+
for (i = 0; i < type.info.fields.length; i++) {
|
|
278
|
+
type.info.fields[i] = {
|
|
279
|
+
name: this.readString(),
|
|
280
|
+
type: this.readType(),
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
break
|
|
284
|
+
case types.dataTypes.tuple:
|
|
285
|
+
type.info = new Array(this.readShort())
|
|
286
|
+
for (i = 0; i < type.info.length; i++) {
|
|
287
|
+
type.info[i] = this.readType()
|
|
288
|
+
}
|
|
289
|
+
break
|
|
290
|
+
}
|
|
291
|
+
return type
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Reads an Ip address and port
|
|
296
|
+
* @returns {{address: exports.InetAddress, port: Number}}
|
|
297
|
+
*/
|
|
298
|
+
readInet() {
|
|
299
|
+
const length = this.readByte()
|
|
300
|
+
const address = this.read(length)
|
|
301
|
+
return { address: new types.InetAddress(address), port: this.readInt() }
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Reads an Ip address
|
|
306
|
+
* @returns {InetAddress}
|
|
307
|
+
*/
|
|
308
|
+
readInetAddress() {
|
|
309
|
+
const length = this.readByte()
|
|
310
|
+
return new types.InetAddress(this.read(length))
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Reads the body bytes corresponding to the flags
|
|
315
|
+
* @returns {{traceId: Uuid, warnings: Array, customPayload}}
|
|
316
|
+
* @throws {RangeError}
|
|
317
|
+
*/
|
|
318
|
+
readFlagsInfo() {
|
|
319
|
+
if (this.header.flags === 0) {
|
|
320
|
+
return utils.emptyObject
|
|
321
|
+
}
|
|
322
|
+
const result = {}
|
|
323
|
+
if (this.header.flags & types.frameFlags.tracing) {
|
|
324
|
+
this.checkOffset(16)
|
|
325
|
+
result.traceId = new types.Uuid(utils.copyBuffer(this.read(16)))
|
|
326
|
+
}
|
|
327
|
+
if (this.header.flags & types.frameFlags.warning) {
|
|
328
|
+
result.warnings = this.readStringList()
|
|
329
|
+
}
|
|
330
|
+
if (this.header.flags & types.frameFlags.customPayload) {
|
|
331
|
+
// Custom payload is a Map<string, Buffer>
|
|
332
|
+
result.customPayload = this.readMap(
|
|
333
|
+
this.readShort(),
|
|
334
|
+
this.readString,
|
|
335
|
+
this.readBytes,
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
return result
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Reads the metadata from a row or a prepared result response
|
|
343
|
+
* @param {Number} kind
|
|
344
|
+
* @returns {Object}
|
|
345
|
+
* @throws {RangeError}
|
|
346
|
+
*/
|
|
347
|
+
readMetadata(kind) {
|
|
348
|
+
let i
|
|
349
|
+
//Determines if its a prepared metadata
|
|
350
|
+
const isPrepared = kind === types.resultKind.prepared
|
|
351
|
+
const meta = {}
|
|
352
|
+
if (
|
|
353
|
+
types.protocolVersion.supportsResultMetadataId(
|
|
354
|
+
this.header.version,
|
|
355
|
+
) &&
|
|
356
|
+
isPrepared
|
|
357
|
+
) {
|
|
358
|
+
meta.resultId = utils.copyBuffer(this.readShortBytes())
|
|
359
|
+
}
|
|
360
|
+
//as used in Rows and Prepared responses
|
|
361
|
+
const flags = this.readInt()
|
|
362
|
+
const columnLength = this.readInt()
|
|
363
|
+
if (
|
|
364
|
+
types.protocolVersion.supportsPreparedPartitionKey(
|
|
365
|
+
this.header.version,
|
|
366
|
+
) &&
|
|
367
|
+
isPrepared
|
|
368
|
+
) {
|
|
369
|
+
//read the pk columns
|
|
370
|
+
meta.partitionKeys = new Array(this.readInt())
|
|
371
|
+
for (i = 0; i < meta.partitionKeys.length; i++) {
|
|
372
|
+
meta.partitionKeys[i] = this.readShort()
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (flags & resultFlag.hasMorePages) {
|
|
376
|
+
meta.pageState = utils.copyBuffer(this.readBytes())
|
|
377
|
+
}
|
|
378
|
+
if (flags & resultFlag.metadataChanged) {
|
|
379
|
+
meta.newResultId = utils.copyBuffer(this.readShortBytes())
|
|
380
|
+
}
|
|
381
|
+
if (flags & resultFlag.continuousPaging) {
|
|
382
|
+
meta.continuousPageIndex = this.readInt()
|
|
383
|
+
meta.lastContinuousPage = !!(flags & resultFlag.lastContinuousPage)
|
|
384
|
+
}
|
|
385
|
+
if (flags & resultFlag.globalTablesSpec) {
|
|
386
|
+
meta.global_tables_spec = true
|
|
387
|
+
meta.keyspace = this.readString()
|
|
388
|
+
meta.table = this.readString()
|
|
389
|
+
}
|
|
390
|
+
meta.columns = new Array(columnLength)
|
|
391
|
+
meta.columnsByName = utils.emptyObject
|
|
392
|
+
if (isPrepared) {
|
|
393
|
+
//for prepared metadata, we will need a index of the columns (param) by name
|
|
394
|
+
meta.columnsByName = {}
|
|
395
|
+
}
|
|
396
|
+
for (i = 0; i < columnLength; i++) {
|
|
397
|
+
const col = {}
|
|
398
|
+
if (!meta.global_tables_spec) {
|
|
399
|
+
col.ksname = this.readString()
|
|
400
|
+
col.tablename = this.readString()
|
|
401
|
+
}
|
|
402
|
+
col.name = this.readString()
|
|
403
|
+
col.type = this.readType()
|
|
404
|
+
meta.columns[i] = col
|
|
405
|
+
if (isPrepared) {
|
|
406
|
+
meta.columnsByName[col.name] = i
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return meta
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Reads the error from the frame
|
|
414
|
+
* @throws {RangeError}
|
|
415
|
+
* @returns {ResponseError}
|
|
416
|
+
*/
|
|
417
|
+
readError() {
|
|
418
|
+
const code = this.readInt()
|
|
419
|
+
const message = this.readString()
|
|
420
|
+
const err = new errors.ResponseError(code, message)
|
|
421
|
+
//read extra info
|
|
422
|
+
switch (code) {
|
|
423
|
+
case types.responseErrorCodes.unavailableException:
|
|
424
|
+
err.consistencies = this.readShort()
|
|
425
|
+
err.required = this.readInt()
|
|
426
|
+
err.alive = this.readInt()
|
|
427
|
+
err.message = util.format(
|
|
428
|
+
_unavailableMessage,
|
|
429
|
+
types.consistencyToString[err.consistencies],
|
|
430
|
+
err.required,
|
|
431
|
+
err.alive,
|
|
432
|
+
)
|
|
433
|
+
break
|
|
434
|
+
case types.responseErrorCodes.readTimeout:
|
|
435
|
+
case types.responseErrorCodes.readFailure:
|
|
436
|
+
err.consistencies = this.readShort()
|
|
437
|
+
err.received = this.readInt()
|
|
438
|
+
err.blockFor = this.readInt()
|
|
439
|
+
if (code === types.responseErrorCodes.readFailure) {
|
|
440
|
+
if (
|
|
441
|
+
types.protocolVersion.supportsFailureReasonMap(
|
|
442
|
+
this.header.version,
|
|
443
|
+
)
|
|
444
|
+
) {
|
|
445
|
+
err.failures = this.readInt()
|
|
446
|
+
err.reasons = this.readMap(
|
|
447
|
+
err.failures,
|
|
448
|
+
this.readInetAddress,
|
|
449
|
+
this.readShort,
|
|
450
|
+
)
|
|
451
|
+
} else {
|
|
452
|
+
err.failures = this.readInt()
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
err.isDataPresent = this.readByte()
|
|
456
|
+
if (code === types.responseErrorCodes.readTimeout) {
|
|
457
|
+
let details
|
|
458
|
+
if (err.received < err.blockFor) {
|
|
459
|
+
details = util.format(
|
|
460
|
+
"%d replica(s) responded over %d required",
|
|
461
|
+
err.received,
|
|
462
|
+
err.blockFor,
|
|
463
|
+
)
|
|
464
|
+
} else if (!err.isDataPresent) {
|
|
465
|
+
details =
|
|
466
|
+
"the replica queried for the data didn't respond"
|
|
467
|
+
} else {
|
|
468
|
+
details =
|
|
469
|
+
"timeout while waiting for repair of inconsistent replica"
|
|
470
|
+
}
|
|
471
|
+
err.message = util.format(
|
|
472
|
+
_readTimeoutMessage,
|
|
473
|
+
types.consistencyToString[err.consistencies],
|
|
474
|
+
details,
|
|
475
|
+
)
|
|
476
|
+
} else {
|
|
477
|
+
err.message = util.format(
|
|
478
|
+
_readFailureMessage,
|
|
479
|
+
types.consistencyToString[err.consistencies],
|
|
480
|
+
err.blockFor,
|
|
481
|
+
err.received,
|
|
482
|
+
err.failures,
|
|
483
|
+
)
|
|
484
|
+
}
|
|
485
|
+
break
|
|
486
|
+
case types.responseErrorCodes.writeTimeout:
|
|
487
|
+
case types.responseErrorCodes.writeFailure:
|
|
488
|
+
err.consistencies = this.readShort()
|
|
489
|
+
err.received = this.readInt()
|
|
490
|
+
err.blockFor = this.readInt()
|
|
491
|
+
if (code === types.responseErrorCodes.writeFailure) {
|
|
492
|
+
if (
|
|
493
|
+
types.protocolVersion.supportsFailureReasonMap(
|
|
494
|
+
this.header.version,
|
|
495
|
+
)
|
|
496
|
+
) {
|
|
497
|
+
err.failures = this.readInt()
|
|
498
|
+
err.reasons = this.readMap(
|
|
499
|
+
err.failures,
|
|
500
|
+
this.readInetAddress,
|
|
501
|
+
this.readShort,
|
|
502
|
+
)
|
|
503
|
+
} else {
|
|
504
|
+
err.failures = this.readInt()
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
err.writeType = this.readString()
|
|
508
|
+
if (code === types.responseErrorCodes.writeTimeout) {
|
|
509
|
+
const template =
|
|
510
|
+
err.writeType === "BATCH_LOG"
|
|
511
|
+
? _writeTimeoutBatchLogMessage
|
|
512
|
+
: _writeTimeoutQueryMessage
|
|
513
|
+
err.message = util.format(
|
|
514
|
+
template,
|
|
515
|
+
types.consistencyToString[err.consistencies],
|
|
516
|
+
err.received,
|
|
517
|
+
err.blockFor,
|
|
518
|
+
)
|
|
519
|
+
} else {
|
|
520
|
+
err.message = util.format(
|
|
521
|
+
_writeFailureMessage,
|
|
522
|
+
types.consistencyToString[err.consistencies],
|
|
523
|
+
err.blockFor,
|
|
524
|
+
err.received,
|
|
525
|
+
err.failures,
|
|
526
|
+
)
|
|
527
|
+
}
|
|
528
|
+
break
|
|
529
|
+
case types.responseErrorCodes.unprepared:
|
|
530
|
+
err.queryId = utils.copyBuffer(this.readShortBytes())
|
|
531
|
+
break
|
|
532
|
+
case types.responseErrorCodes.functionFailure:
|
|
533
|
+
err.keyspace = this.readString()
|
|
534
|
+
err.functionName = this.readString()
|
|
535
|
+
err.argTypes = this.readStringList()
|
|
536
|
+
break
|
|
537
|
+
case types.responseErrorCodes.alreadyExists: {
|
|
538
|
+
err.keyspace = this.readString()
|
|
539
|
+
const table = this.readString()
|
|
540
|
+
if (table.length > 0) {
|
|
541
|
+
err.table = table
|
|
542
|
+
}
|
|
543
|
+
break
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return err
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Reads an event from Cassandra and returns the detail
|
|
551
|
+
* @returns {{eventType: String, inet: {address: Buffer, port: Number}}, *}
|
|
552
|
+
*/
|
|
553
|
+
readEvent() {
|
|
554
|
+
const eventType = this.readString()
|
|
555
|
+
switch (eventType) {
|
|
556
|
+
case types.protocolEvents.topologyChange:
|
|
557
|
+
return {
|
|
558
|
+
added: this.readString() === "NEW_NODE",
|
|
559
|
+
inet: this.readInet(),
|
|
560
|
+
eventType: eventType,
|
|
561
|
+
}
|
|
562
|
+
case types.protocolEvents.statusChange:
|
|
563
|
+
return {
|
|
564
|
+
up: this.readString() === "UP",
|
|
565
|
+
inet: this.readInet(),
|
|
566
|
+
eventType: eventType,
|
|
567
|
+
}
|
|
568
|
+
case types.protocolEvents.schemaChange:
|
|
569
|
+
return this.parseSchemaChange()
|
|
570
|
+
}
|
|
571
|
+
//Forward compatibility
|
|
572
|
+
return { eventType: eventType }
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
parseSchemaChange() {
|
|
576
|
+
let result
|
|
577
|
+
if (
|
|
578
|
+
!types.protocolVersion.supportsSchemaChangeFullMetadata(
|
|
579
|
+
this.header.version,
|
|
580
|
+
)
|
|
581
|
+
) {
|
|
582
|
+
//v1/v2: 3 strings, the table value can be empty
|
|
583
|
+
result = {
|
|
584
|
+
eventType: types.protocolEvents.schemaChange,
|
|
585
|
+
schemaChangeType: this.readString(),
|
|
586
|
+
keyspace: this.readString(),
|
|
587
|
+
table: this.readString(),
|
|
588
|
+
}
|
|
589
|
+
result.isKeyspace = !result.table
|
|
590
|
+
return result
|
|
591
|
+
}
|
|
592
|
+
//v3+: 3 or 4 strings: change_type, target, keyspace and (table, type, functionName or aggregate)
|
|
593
|
+
result = {
|
|
594
|
+
eventType: types.protocolEvents.schemaChange,
|
|
595
|
+
schemaChangeType: this.readString(),
|
|
596
|
+
target: this.readString(),
|
|
597
|
+
keyspace: this.readString(),
|
|
598
|
+
table: null,
|
|
599
|
+
udt: null,
|
|
600
|
+
signature: null,
|
|
601
|
+
}
|
|
602
|
+
result.isKeyspace = result.target === "KEYSPACE"
|
|
603
|
+
switch (result.target) {
|
|
604
|
+
case "TABLE":
|
|
605
|
+
result.table = this.readString()
|
|
606
|
+
break
|
|
607
|
+
case "TYPE":
|
|
608
|
+
result.udt = this.readString()
|
|
609
|
+
break
|
|
610
|
+
case "FUNCTION":
|
|
611
|
+
result.functionName = this.readString()
|
|
612
|
+
result.signature = this.readStringList()
|
|
613
|
+
break
|
|
614
|
+
case "AGGREGATE":
|
|
615
|
+
result.aggregate = this.readString()
|
|
616
|
+
result.signature = this.readStringList()
|
|
617
|
+
}
|
|
618
|
+
return result
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
export { FrameReader }
|
|
623
|
+
|
|
624
|
+
export default { FrameReader }
|