@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,733 @@
|
|
|
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
|
+
import util from "util"
|
|
19
|
+
|
|
20
|
+
import errors from "../errors.js"
|
|
21
|
+
import TimeUuid from "./time-uuid.js"
|
|
22
|
+
import Uuid from "./uuid.js"
|
|
23
|
+
import protocolVersion from "./protocol-version.js"
|
|
24
|
+
import utils from "../utils.js"
|
|
25
|
+
import BigDecimal from "./big-decimal.js"
|
|
26
|
+
import Duration from "./duration.js"
|
|
27
|
+
import InetAddress from "./inet-address.js"
|
|
28
|
+
import Integer from "./integer.js"
|
|
29
|
+
import LocalDate from "./local-date.js"
|
|
30
|
+
import LocalTime from "./local-time.js"
|
|
31
|
+
import ResultSet from "./result-set.js"
|
|
32
|
+
import ResultStream from "./result-stream.js"
|
|
33
|
+
import Row from "./row.js"
|
|
34
|
+
import Tuple from "./tuple.js"
|
|
35
|
+
import Vector from "./vector.js"
|
|
36
|
+
|
|
37
|
+
/** @module types */
|
|
38
|
+
/**
|
|
39
|
+
* Long constructor, wrapper of the internal library used: {@link https://github.com/dcodeIO/long Long}.
|
|
40
|
+
* @constructor
|
|
41
|
+
*/
|
|
42
|
+
import Long from "long"
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Consistency levels
|
|
46
|
+
* @type {Object}
|
|
47
|
+
* @property {Number} any Writing: A write must be written to at least one node. If all replica nodes for the given row key are down, the write can still succeed after a hinted handoff has been written. If all replica nodes are down at write time, an ANY write is not readable until the replica nodes for that row have recovered.
|
|
48
|
+
* @property {Number} one Returns a response from the closest replica, as determined by the snitch.
|
|
49
|
+
* @property {Number} two Returns the most recent data from two of the closest replicas.
|
|
50
|
+
* @property {Number} three Returns the most recent data from three of the closest replicas.
|
|
51
|
+
* @property {Number} quorum Reading: Returns the record with the most recent timestamp after a quorum of replicas has responded regardless of data center. Writing: A write must be written to the commit log and memory table on a quorum of replica nodes.
|
|
52
|
+
* @property {Number} all Reading: Returns the record with the most recent timestamp after all replicas have responded. The read operation will fail if a replica does not respond. Writing: A write must be written to the commit log and memory table on all replica nodes in the cluster for that row.
|
|
53
|
+
* @property {Number} localQuorum Reading: Returns the record with the most recent timestamp once a quorum of replicas in the current data center as the coordinator node has reported. Writing: A write must be written to the commit log and memory table on a quorum of replica nodes in the same data center as the coordinator node. Avoids latency of inter-data center communication.
|
|
54
|
+
* @property {Number} eachQuorum Reading: Returns the record once a quorum of replicas in each data center of the cluster has responded. Writing: Strong consistency. A write must be written to the commit log and memtable on a quorum of replica nodes in all data centers.
|
|
55
|
+
* @property {Number} serial Achieves linearizable consistency for lightweight transactions by preventing unconditional updates.
|
|
56
|
+
* @property {Number} localSerial Same as serial but confined to the data center. A write must be written conditionally to the commit log and memtable on a quorum of replica nodes in the same data center.
|
|
57
|
+
* @property {Number} localOne Similar to One but only within the DC the coordinator is in.
|
|
58
|
+
*/
|
|
59
|
+
const consistencies = {
|
|
60
|
+
any: 0x00,
|
|
61
|
+
one: 0x01,
|
|
62
|
+
two: 0x02,
|
|
63
|
+
three: 0x03,
|
|
64
|
+
quorum: 0x04,
|
|
65
|
+
all: 0x05,
|
|
66
|
+
localQuorum: 0x06,
|
|
67
|
+
eachQuorum: 0x07,
|
|
68
|
+
serial: 0x08,
|
|
69
|
+
localSerial: 0x09,
|
|
70
|
+
localOne: 0x0a,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Mapping of consistency level codes to their string representation.
|
|
75
|
+
* @type {Object}
|
|
76
|
+
*/
|
|
77
|
+
const consistencyToString = {}
|
|
78
|
+
consistencyToString[consistencies.any] = "ANY"
|
|
79
|
+
consistencyToString[consistencies.one] = "ONE"
|
|
80
|
+
consistencyToString[consistencies.two] = "TWO"
|
|
81
|
+
consistencyToString[consistencies.three] = "THREE"
|
|
82
|
+
consistencyToString[consistencies.quorum] = "QUORUM"
|
|
83
|
+
consistencyToString[consistencies.all] = "ALL"
|
|
84
|
+
consistencyToString[consistencies.localQuorum] = "LOCAL_QUORUM"
|
|
85
|
+
consistencyToString[consistencies.eachQuorum] = "EACH_QUORUM"
|
|
86
|
+
consistencyToString[consistencies.serial] = "SERIAL"
|
|
87
|
+
consistencyToString[consistencies.localSerial] = "LOCAL_SERIAL"
|
|
88
|
+
consistencyToString[consistencies.localOne] = "LOCAL_ONE"
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* CQL data types
|
|
92
|
+
* @type {Object}
|
|
93
|
+
* @property {Number} custom A custom type.
|
|
94
|
+
* @property {Number} ascii ASCII character string.
|
|
95
|
+
* @property {Number} bigint 64-bit signed long.
|
|
96
|
+
* @property {Number} blob Arbitrary bytes (no validation).
|
|
97
|
+
* @property {Number} boolean true or false.
|
|
98
|
+
* @property {Number} counter Counter column (64-bit signed value).
|
|
99
|
+
* @property {Number} decimal Variable-precision decimal.
|
|
100
|
+
* @property {Number} double 64-bit IEEE-754 floating point.
|
|
101
|
+
* @property {Number} float 32-bit IEEE-754 floating point.
|
|
102
|
+
* @property {Number} int 32-bit signed integer.
|
|
103
|
+
* @property {Number} text UTF8 encoded string.
|
|
104
|
+
* @property {Number} timestamp A timestamp.
|
|
105
|
+
* @property {Number} uuid Type 1 or type 4 UUID.
|
|
106
|
+
* @property {Number} varchar UTF8 encoded string.
|
|
107
|
+
* @property {Number} varint Arbitrary-precision integer.
|
|
108
|
+
* @property {Number} timeuuid Type 1 UUID.
|
|
109
|
+
* @property {Number} inet An IP address. It can be either 4 bytes long (IPv4) or 16 bytes long (IPv6).
|
|
110
|
+
* @property {Number} date A date without a time-zone in the ISO-8601 calendar system.
|
|
111
|
+
* @property {Number} time A value representing the time portion of the day.
|
|
112
|
+
* @property {Number} smallint 16-bit two's complement integer.
|
|
113
|
+
* @property {Number} tinyint 8-bit two's complement integer.
|
|
114
|
+
* @property {Number} list A collection of elements.
|
|
115
|
+
* @property {Number} map Key/value pairs.
|
|
116
|
+
* @property {Number} set A collection that contains no duplicate elements.
|
|
117
|
+
* @property {Number} udt User-defined type.
|
|
118
|
+
* @property {Number} tuple A sequence of values.
|
|
119
|
+
*/
|
|
120
|
+
const dataTypes = {
|
|
121
|
+
custom: 0x0000,
|
|
122
|
+
ascii: 0x0001,
|
|
123
|
+
bigint: 0x0002,
|
|
124
|
+
blob: 0x0003,
|
|
125
|
+
boolean: 0x0004,
|
|
126
|
+
counter: 0x0005,
|
|
127
|
+
decimal: 0x0006,
|
|
128
|
+
double: 0x0007,
|
|
129
|
+
float: 0x0008,
|
|
130
|
+
int: 0x0009,
|
|
131
|
+
text: 0x000a,
|
|
132
|
+
timestamp: 0x000b,
|
|
133
|
+
uuid: 0x000c,
|
|
134
|
+
varchar: 0x000d,
|
|
135
|
+
varint: 0x000e,
|
|
136
|
+
timeuuid: 0x000f,
|
|
137
|
+
inet: 0x0010,
|
|
138
|
+
date: 0x0011,
|
|
139
|
+
time: 0x0012,
|
|
140
|
+
smallint: 0x0013,
|
|
141
|
+
tinyint: 0x0014,
|
|
142
|
+
duration: 0x0015,
|
|
143
|
+
list: 0x0020,
|
|
144
|
+
map: 0x0021,
|
|
145
|
+
set: 0x0022,
|
|
146
|
+
udt: 0x0030,
|
|
147
|
+
tuple: 0x0031,
|
|
148
|
+
/**
|
|
149
|
+
* Returns the typeInfo of a given type name
|
|
150
|
+
* @param {string} name
|
|
151
|
+
*/
|
|
152
|
+
getByName: function (name) {
|
|
153
|
+
name = name.toLowerCase()
|
|
154
|
+
if (name.indexOf("<") > 0) {
|
|
155
|
+
const listMatches = /^(list|set)<(.+)>$/.exec(name)
|
|
156
|
+
if (listMatches) {
|
|
157
|
+
return {
|
|
158
|
+
code: this[listMatches[1]],
|
|
159
|
+
info: this.getByName(listMatches[2]),
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const mapMatches = /^(map)< *(.+) *, *(.+)>$/.exec(name)
|
|
163
|
+
if (mapMatches) {
|
|
164
|
+
return {
|
|
165
|
+
code: this[mapMatches[1]],
|
|
166
|
+
info: [
|
|
167
|
+
this.getByName(mapMatches[2]),
|
|
168
|
+
this.getByName(mapMatches[3]),
|
|
169
|
+
],
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const udtMatches = /^(udt)<(.+)>$/.exec(name)
|
|
173
|
+
if (udtMatches) {
|
|
174
|
+
//udt name as raw string
|
|
175
|
+
return { code: this[udtMatches[1]], info: udtMatches[2] }
|
|
176
|
+
}
|
|
177
|
+
const tupleMatches = /^(tuple)<(.+)>$/.exec(name)
|
|
178
|
+
if (tupleMatches) {
|
|
179
|
+
//tuple info as an array of types
|
|
180
|
+
return {
|
|
181
|
+
code: this[tupleMatches[1]],
|
|
182
|
+
info: tupleMatches[2].split(",").map(function (x) {
|
|
183
|
+
return this.getByName(x.trim())
|
|
184
|
+
}, this),
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const vectorMatches = /^vector<\s*(.+)\s*,\s*(\d+)\s*>$/.exec(name)
|
|
188
|
+
if (vectorMatches) {
|
|
189
|
+
return {
|
|
190
|
+
code: this.custom,
|
|
191
|
+
customTypeName: "vector",
|
|
192
|
+
info: [
|
|
193
|
+
this.getByName(vectorMatches[1]),
|
|
194
|
+
parseInt(vectorMatches[2], 10),
|
|
195
|
+
],
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const typeInfo = { code: this[name] }
|
|
200
|
+
if (typeof typeInfo.code !== "number") {
|
|
201
|
+
throw new TypeError("Data type with name " + name + " not valid")
|
|
202
|
+
}
|
|
203
|
+
return typeInfo
|
|
204
|
+
},
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Map of Data types by code
|
|
209
|
+
* @internal
|
|
210
|
+
* @private
|
|
211
|
+
* @type {Record<number, string>}
|
|
212
|
+
*/
|
|
213
|
+
const _dataTypesByCode = (function () {
|
|
214
|
+
/**@type {Record<number, string>} */
|
|
215
|
+
const result = {}
|
|
216
|
+
for (const key in dataTypes) {
|
|
217
|
+
if (!dataTypes.hasOwnProperty(key)) {
|
|
218
|
+
continue
|
|
219
|
+
}
|
|
220
|
+
const val = dataTypes[key]
|
|
221
|
+
if (typeof val !== "number") {
|
|
222
|
+
continue
|
|
223
|
+
}
|
|
224
|
+
result[val] = key
|
|
225
|
+
}
|
|
226
|
+
return result
|
|
227
|
+
})()
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Represents the distance of Cassandra node as assigned by a LoadBalancingPolicy relatively to the driver instance.
|
|
231
|
+
* @type {Object}
|
|
232
|
+
* @property {Number} local A local node.
|
|
233
|
+
* @property {Number} remote A remote node.
|
|
234
|
+
* @property {Number} ignored A node that is meant to be ignored.
|
|
235
|
+
*/
|
|
236
|
+
const distance = {
|
|
237
|
+
local: 0,
|
|
238
|
+
remote: 1,
|
|
239
|
+
ignored: 2,
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* An integer byte that distinguish the actual message from and to Cassandra
|
|
244
|
+
* @internal
|
|
245
|
+
* @ignore
|
|
246
|
+
*/
|
|
247
|
+
const opcodes = {
|
|
248
|
+
error: 0x00,
|
|
249
|
+
startup: 0x01,
|
|
250
|
+
ready: 0x02,
|
|
251
|
+
authenticate: 0x03,
|
|
252
|
+
credentials: 0x04,
|
|
253
|
+
options: 0x05,
|
|
254
|
+
supported: 0x06,
|
|
255
|
+
query: 0x07,
|
|
256
|
+
result: 0x08,
|
|
257
|
+
prepare: 0x09,
|
|
258
|
+
execute: 0x0a,
|
|
259
|
+
register: 0x0b,
|
|
260
|
+
event: 0x0c,
|
|
261
|
+
batch: 0x0d,
|
|
262
|
+
authChallenge: 0x0e,
|
|
263
|
+
authResponse: 0x0f,
|
|
264
|
+
authSuccess: 0x10,
|
|
265
|
+
cancel: 0xff,
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Determines if the code is a valid opcode
|
|
269
|
+
*/
|
|
270
|
+
isInRange: function (code) {
|
|
271
|
+
return code > this.error && code > this.event
|
|
272
|
+
},
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Event types from Cassandra
|
|
277
|
+
* @type {{topologyChange: string, statusChange: string, schemaChange: string}}
|
|
278
|
+
* @internal
|
|
279
|
+
* @ignore
|
|
280
|
+
*/
|
|
281
|
+
const protocolEvents = {
|
|
282
|
+
topologyChange: "TOPOLOGY_CHANGE",
|
|
283
|
+
statusChange: "STATUS_CHANGE",
|
|
284
|
+
schemaChange: "SCHEMA_CHANGE",
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Server error codes returned by Cassandra
|
|
289
|
+
* @type {Object}
|
|
290
|
+
* @property {Number} serverError Something unexpected happened.
|
|
291
|
+
* @property {Number} protocolError Some client message triggered a protocol violation.
|
|
292
|
+
* @property {Number} badCredentials Authentication was required and failed.
|
|
293
|
+
* @property {Number} unavailableException Raised when coordinator knows there is not enough replicas alive to perform a query with the requested consistency level.
|
|
294
|
+
* @property {Number} overloaded The request cannot be processed because the coordinator is overloaded.
|
|
295
|
+
* @property {Number} isBootstrapping The request was a read request but the coordinator node is bootstrapping.
|
|
296
|
+
* @property {Number} truncateError Error encountered during a truncate request.
|
|
297
|
+
* @property {Number} writeTimeout Timeout encountered on write query on coordinator waiting for response(s) from replicas.
|
|
298
|
+
* @property {Number} readTimeout Timeout encountered on read query on coordinator waitign for response(s) from replicas.
|
|
299
|
+
* @property {Number} readFailure A non-timeout error encountered during a read request.
|
|
300
|
+
* @property {Number} functionFailure A (user defined) function encountered during execution.
|
|
301
|
+
* @property {Number} writeFailure A non-timeout error encountered during a write request.
|
|
302
|
+
* @property {Number} syntaxError The submitted query has a syntax error.
|
|
303
|
+
* @property {Number} unauthorized The logged user doesn't have the right to perform the query.
|
|
304
|
+
* @property {Number} invalid The query is syntactically correct but invalid.
|
|
305
|
+
* @property {Number} configError The query is invalid because of some configuration issue.
|
|
306
|
+
* @property {Number} alreadyExists The query attempted to create a schema element (i.e. keyspace, table) that already exists.
|
|
307
|
+
* @property {Number} unprepared Can be thrown while a prepared statement tries to be executed if the provided statement is not known by the coordinator.
|
|
308
|
+
*/
|
|
309
|
+
const responseErrorCodes = {
|
|
310
|
+
serverError: 0x0000,
|
|
311
|
+
protocolError: 0x000a,
|
|
312
|
+
badCredentials: 0x0100,
|
|
313
|
+
unavailableException: 0x1000,
|
|
314
|
+
overloaded: 0x1001,
|
|
315
|
+
isBootstrapping: 0x1002,
|
|
316
|
+
truncateError: 0x1003,
|
|
317
|
+
writeTimeout: 0x1100,
|
|
318
|
+
readTimeout: 0x1200,
|
|
319
|
+
readFailure: 0x1300,
|
|
320
|
+
functionFailure: 0x1400,
|
|
321
|
+
writeFailure: 0x1500,
|
|
322
|
+
syntaxError: 0x2000,
|
|
323
|
+
unauthorized: 0x2100,
|
|
324
|
+
invalid: 0x2200,
|
|
325
|
+
configError: 0x2300,
|
|
326
|
+
alreadyExists: 0x2400,
|
|
327
|
+
unprepared: 0x2500,
|
|
328
|
+
clientWriteFailure: 0x8000,
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Type of result included in a response
|
|
333
|
+
* @internal
|
|
334
|
+
* @ignore
|
|
335
|
+
*/
|
|
336
|
+
const resultKind = {
|
|
337
|
+
voidResult: 0x0001,
|
|
338
|
+
rows: 0x0002,
|
|
339
|
+
setKeyspace: 0x0003,
|
|
340
|
+
prepared: 0x0004,
|
|
341
|
+
schemaChange: 0x0005,
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Message frame flags
|
|
346
|
+
* @internal
|
|
347
|
+
* @ignore
|
|
348
|
+
*/
|
|
349
|
+
const frameFlags = {
|
|
350
|
+
compression: 0x01,
|
|
351
|
+
tracing: 0x02,
|
|
352
|
+
customPayload: 0x04,
|
|
353
|
+
warning: 0x08,
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Unset representation.
|
|
358
|
+
* <p>
|
|
359
|
+
* Use this field if you want to set a parameter to <code>unset</code>. Valid for Cassandra 2.2 and above.
|
|
360
|
+
* </p>
|
|
361
|
+
*/
|
|
362
|
+
const unset = Object.freeze({ unset: true })
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* A long representing the value 1000
|
|
366
|
+
* @const
|
|
367
|
+
* @private
|
|
368
|
+
*/
|
|
369
|
+
const _longOneThousand = Long.fromInt(1000)
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Counter used to generate up to 1000 different timestamp values with the same Date
|
|
373
|
+
* @private
|
|
374
|
+
*/
|
|
375
|
+
let _timestampTicks = 0
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* <p><strong>Backward compatibility only, use [TimeUuid]{@link module:types~TimeUuid} instead</strong>.</p>
|
|
379
|
+
* Generates and returns a RFC4122 v1 (timestamp based) UUID in a string representation.
|
|
380
|
+
* @param {{msecs, node, clockseq, nsecs}} [options]
|
|
381
|
+
* @param {Buffer} [buffer]
|
|
382
|
+
* @param {Number} [offset]
|
|
383
|
+
* @deprecated Use [TimeUuid]{@link module:types~TimeUuid} instead
|
|
384
|
+
*/
|
|
385
|
+
function timeuuid(options, buffer, offset) {
|
|
386
|
+
let date
|
|
387
|
+
let ticks
|
|
388
|
+
let nodeId
|
|
389
|
+
let clockId
|
|
390
|
+
if (options) {
|
|
391
|
+
if (typeof options.msecs === "number") {
|
|
392
|
+
date = new Date(options.msecs)
|
|
393
|
+
}
|
|
394
|
+
if (options.msecs instanceof Date) {
|
|
395
|
+
date = options.msecs
|
|
396
|
+
}
|
|
397
|
+
if (Array.isArray(options.node)) {
|
|
398
|
+
nodeId = utils.allocBufferFromArray(options.node)
|
|
399
|
+
}
|
|
400
|
+
if (typeof options.clockseq === "number") {
|
|
401
|
+
clockId = utils.allocBufferUnsafe(2)
|
|
402
|
+
clockId.writeUInt16BE(options.clockseq, 0)
|
|
403
|
+
}
|
|
404
|
+
if (typeof options.nsecs === "number") {
|
|
405
|
+
ticks = options.nsecs
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const uuid = new TimeUuid(date, ticks, nodeId, clockId)
|
|
409
|
+
if (buffer instanceof Buffer) {
|
|
410
|
+
//copy the values into the buffer
|
|
411
|
+
uuid.getBuffer().copy(buffer, offset || 0)
|
|
412
|
+
return buffer
|
|
413
|
+
}
|
|
414
|
+
return uuid.toString()
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* <p><strong>Backward compatibility only, use [Uuid]{@link module:types~Uuid} class instead</strong>.</p>
|
|
419
|
+
* Generate and return a RFC4122 v4 UUID in a string representation.
|
|
420
|
+
* @deprecated Use [Uuid]{@link module:types~Uuid} class instead
|
|
421
|
+
*/
|
|
422
|
+
function uuid(options, buffer, offset) {
|
|
423
|
+
let uuid
|
|
424
|
+
if (options) {
|
|
425
|
+
if (Array.isArray(options.random)) {
|
|
426
|
+
uuid = new Uuid(utils.allocBufferFromArray(options.random))
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (!uuid) {
|
|
430
|
+
uuid = Uuid.random()
|
|
431
|
+
}
|
|
432
|
+
if (buffer instanceof Buffer) {
|
|
433
|
+
//copy the values into the buffer
|
|
434
|
+
uuid.getBuffer().copy(buffer, offset || 0)
|
|
435
|
+
return buffer
|
|
436
|
+
}
|
|
437
|
+
return uuid.toString()
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Gets the data type name for a given type definition, it may not work for udt or custom type
|
|
442
|
+
* @internal
|
|
443
|
+
* @ignore
|
|
444
|
+
* @throws {ArgumentError}
|
|
445
|
+
*/
|
|
446
|
+
function getDataTypeNameByCode(item) {
|
|
447
|
+
if (!item || typeof item.code !== "number") {
|
|
448
|
+
throw new errors.ArgumentError("Invalid signature type definition")
|
|
449
|
+
}
|
|
450
|
+
const typeName = _dataTypesByCode[item.code]
|
|
451
|
+
if (!typeName) {
|
|
452
|
+
throw new errors.ArgumentError(
|
|
453
|
+
util.format("Type with code %d not found", item.code),
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
if (!("info" in item) || !item.info) {
|
|
457
|
+
return typeName
|
|
458
|
+
}
|
|
459
|
+
// special case for vector
|
|
460
|
+
if (
|
|
461
|
+
item.code === dataTypes.custom &&
|
|
462
|
+
"customTypeName" in item &&
|
|
463
|
+
item.customTypeName === "vector"
|
|
464
|
+
) {
|
|
465
|
+
return (
|
|
466
|
+
"vector<" +
|
|
467
|
+
getDataTypeNameByCode(item.info[0]) +
|
|
468
|
+
", " +
|
|
469
|
+
item.info[1] +
|
|
470
|
+
">"
|
|
471
|
+
)
|
|
472
|
+
}
|
|
473
|
+
if (Array.isArray(item.info)) {
|
|
474
|
+
return (
|
|
475
|
+
typeName +
|
|
476
|
+
"<" +
|
|
477
|
+
item.info
|
|
478
|
+
.map(function (t) {
|
|
479
|
+
return getDataTypeNameByCode(t)
|
|
480
|
+
})
|
|
481
|
+
.join(", ") +
|
|
482
|
+
">"
|
|
483
|
+
)
|
|
484
|
+
}
|
|
485
|
+
if (typeof item.info.code === "number") {
|
|
486
|
+
return typeName + "<" + getDataTypeNameByCode(item.info) + ">"
|
|
487
|
+
}
|
|
488
|
+
if (item.code === dataTypes.udt) {
|
|
489
|
+
return /**@type {UdtColumnInfo}*/ item.info.name
|
|
490
|
+
}
|
|
491
|
+
return typeName
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
//classes
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Represents a frame header that could be used to read from a Buffer or to write to a Buffer
|
|
498
|
+
* @ignore
|
|
499
|
+
* @param {Number} version Protocol version
|
|
500
|
+
* @param {Number} flags
|
|
501
|
+
* @param {Number} streamId
|
|
502
|
+
* @param {Number} opcode
|
|
503
|
+
* @param {Number} bodyLength
|
|
504
|
+
* @constructor
|
|
505
|
+
*/
|
|
506
|
+
function FrameHeader(version, flags, streamId, opcode, bodyLength) {
|
|
507
|
+
this.version = version
|
|
508
|
+
this.flags = flags
|
|
509
|
+
this.streamId = streamId
|
|
510
|
+
this.opcode = opcode
|
|
511
|
+
this.bodyLength = bodyLength
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* The length of the header of the frame based on the protocol version
|
|
516
|
+
* @returns {Number}
|
|
517
|
+
*/
|
|
518
|
+
FrameHeader.size = function (version) {
|
|
519
|
+
if (protocolVersion.uses2BytesStreamIds(version)) {
|
|
520
|
+
return 9
|
|
521
|
+
}
|
|
522
|
+
return 8
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Gets the protocol version based on the first byte of the header
|
|
527
|
+
* @param {Buffer} buffer
|
|
528
|
+
* @returns {Number}
|
|
529
|
+
*/
|
|
530
|
+
FrameHeader.getProtocolVersion = function (buffer) {
|
|
531
|
+
return buffer[0] & 0x7f
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* @param {Buffer} buf
|
|
536
|
+
* @param {Number} [offset]
|
|
537
|
+
* @returns {FrameHeader}
|
|
538
|
+
*/
|
|
539
|
+
FrameHeader.fromBuffer = function (buf, offset) {
|
|
540
|
+
let streamId = 0
|
|
541
|
+
if (!offset) {
|
|
542
|
+
offset = 0
|
|
543
|
+
}
|
|
544
|
+
const version = buf[offset++] & 0x7f
|
|
545
|
+
const flags = buf.readUInt8(offset++)
|
|
546
|
+
if (!protocolVersion.uses2BytesStreamIds(version)) {
|
|
547
|
+
streamId = buf.readInt8(offset++)
|
|
548
|
+
} else {
|
|
549
|
+
streamId = buf.readInt16BE(offset)
|
|
550
|
+
offset += 2
|
|
551
|
+
}
|
|
552
|
+
return new FrameHeader(
|
|
553
|
+
version,
|
|
554
|
+
flags,
|
|
555
|
+
streamId,
|
|
556
|
+
buf.readUInt8(offset++),
|
|
557
|
+
buf.readUInt32BE(offset),
|
|
558
|
+
)
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** @returns {Buffer} */
|
|
562
|
+
FrameHeader.prototype.toBuffer = function () {
|
|
563
|
+
const buf = utils.allocBufferUnsafe(FrameHeader.size(this.version))
|
|
564
|
+
buf.writeUInt8(this.version, 0)
|
|
565
|
+
buf.writeUInt8(this.flags, 1)
|
|
566
|
+
let offset = 3
|
|
567
|
+
if (!protocolVersion.uses2BytesStreamIds(this.version)) {
|
|
568
|
+
buf.writeInt8(this.streamId, 2)
|
|
569
|
+
} else {
|
|
570
|
+
buf.writeInt16BE(this.streamId, 2)
|
|
571
|
+
offset = 4
|
|
572
|
+
}
|
|
573
|
+
buf.writeUInt8(this.opcode, offset++)
|
|
574
|
+
buf.writeUInt32BE(this.bodyLength, offset)
|
|
575
|
+
return buf
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Returns a long representation.
|
|
579
|
+
* Used internally for deserialization
|
|
580
|
+
*/
|
|
581
|
+
Long.fromBuffer = function (value) {
|
|
582
|
+
if (!(value instanceof Buffer)) {
|
|
583
|
+
throw new TypeError("Expected Buffer, obtained " + util.inspect(value))
|
|
584
|
+
}
|
|
585
|
+
return new Long(value.readInt32BE(4), value.readInt32BE(0))
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Returns a big-endian buffer representation of the Long instance
|
|
590
|
+
* @param {Long} value
|
|
591
|
+
*/
|
|
592
|
+
Long.toBuffer = function (value) {
|
|
593
|
+
if (!(value instanceof Long)) {
|
|
594
|
+
throw new TypeError("Expected Long, obtained " + util.inspect(value))
|
|
595
|
+
}
|
|
596
|
+
const buffer = utils.allocBufferUnsafe(8)
|
|
597
|
+
buffer.writeUInt32BE(value.getHighBitsUnsigned(), 0)
|
|
598
|
+
buffer.writeUInt32BE(value.getLowBitsUnsigned(), 4)
|
|
599
|
+
return buffer
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Provide the name of the constructor and the string representation
|
|
604
|
+
* @returns {string}
|
|
605
|
+
*/
|
|
606
|
+
Long.prototype.inspect = function () {
|
|
607
|
+
return "Long: " + this.toString()
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Returns the string representation.
|
|
612
|
+
* Method used by the native JSON.stringify() to serialize this instance
|
|
613
|
+
*/
|
|
614
|
+
Long.prototype.toJSON = function () {
|
|
615
|
+
return this.toString()
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Generates a value representing the timestamp for the query in microseconds based on the date and the microseconds provided
|
|
620
|
+
* @param {Date} [date] The date to generate the value, if not provided it will use the current date.
|
|
621
|
+
* @param {Number} [microseconds] A number from 0 to 999 used to build the microseconds part of the date.
|
|
622
|
+
* @returns {Long}
|
|
623
|
+
*/
|
|
624
|
+
function generateTimestamp(date, microseconds) {
|
|
625
|
+
if (!date) {
|
|
626
|
+
date = new Date()
|
|
627
|
+
}
|
|
628
|
+
let longMicro = Long.ZERO
|
|
629
|
+
if (
|
|
630
|
+
typeof microseconds === "number" &&
|
|
631
|
+
microseconds >= 0 &&
|
|
632
|
+
microseconds < 1000
|
|
633
|
+
) {
|
|
634
|
+
longMicro = Long.fromInt(microseconds)
|
|
635
|
+
} else {
|
|
636
|
+
if (_timestampTicks > 999) {
|
|
637
|
+
_timestampTicks = 0
|
|
638
|
+
}
|
|
639
|
+
longMicro = Long.fromInt(_timestampTicks)
|
|
640
|
+
_timestampTicks++
|
|
641
|
+
}
|
|
642
|
+
return Long.fromNumber(date.getTime())
|
|
643
|
+
.multiply(_longOneThousand)
|
|
644
|
+
.add(longMicro)
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
//error classes
|
|
648
|
+
|
|
649
|
+
/** @private */
|
|
650
|
+
function QueryParserError(e) {
|
|
651
|
+
QueryParserError.super_.call(this, e.message, this.constructor)
|
|
652
|
+
this.internalError = e
|
|
653
|
+
}
|
|
654
|
+
util.inherits(QueryParserError, errors.DriverError)
|
|
655
|
+
|
|
656
|
+
/** @private */
|
|
657
|
+
function TimeoutError(message) {
|
|
658
|
+
TimeoutError.super_.call(this, message, this.constructor)
|
|
659
|
+
this.info =
|
|
660
|
+
"Represents an error that happens when the maximum amount of time for an operation passed."
|
|
661
|
+
}
|
|
662
|
+
util.inherits(TimeoutError, errors.DriverError)
|
|
663
|
+
|
|
664
|
+
export { opcodes }
|
|
665
|
+
export { consistencies }
|
|
666
|
+
export { consistencyToString }
|
|
667
|
+
export { dataTypes }
|
|
668
|
+
export { getDataTypeNameByCode }
|
|
669
|
+
export { distance }
|
|
670
|
+
export { frameFlags }
|
|
671
|
+
export { protocolEvents }
|
|
672
|
+
export { protocolVersion }
|
|
673
|
+
export { responseErrorCodes }
|
|
674
|
+
export { resultKind }
|
|
675
|
+
export { timeuuid }
|
|
676
|
+
export { uuid }
|
|
677
|
+
export {
|
|
678
|
+
BigDecimal,
|
|
679
|
+
Duration,
|
|
680
|
+
InetAddress,
|
|
681
|
+
Integer,
|
|
682
|
+
LocalDate,
|
|
683
|
+
LocalTime,
|
|
684
|
+
ResultSet,
|
|
685
|
+
ResultStream,
|
|
686
|
+
Row,
|
|
687
|
+
Tuple,
|
|
688
|
+
Vector,
|
|
689
|
+
}
|
|
690
|
+
export { FrameHeader }
|
|
691
|
+
export { Long }
|
|
692
|
+
//export DriverError for backward-compatibility
|
|
693
|
+
export const DriverError = errors.DriverError
|
|
694
|
+
export { TimeoutError }
|
|
695
|
+
export { TimeUuid }
|
|
696
|
+
export { Uuid }
|
|
697
|
+
export { unset }
|
|
698
|
+
export { generateTimestamp }
|
|
699
|
+
|
|
700
|
+
export default {
|
|
701
|
+
opcodes,
|
|
702
|
+
consistencies,
|
|
703
|
+
consistencyToString,
|
|
704
|
+
dataTypes,
|
|
705
|
+
getDataTypeNameByCode,
|
|
706
|
+
distance,
|
|
707
|
+
frameFlags,
|
|
708
|
+
protocolEvents,
|
|
709
|
+
protocolVersion,
|
|
710
|
+
responseErrorCodes,
|
|
711
|
+
resultKind,
|
|
712
|
+
timeuuid,
|
|
713
|
+
uuid,
|
|
714
|
+
BigDecimal,
|
|
715
|
+
Duration,
|
|
716
|
+
FrameHeader,
|
|
717
|
+
InetAddress,
|
|
718
|
+
Integer,
|
|
719
|
+
LocalDate,
|
|
720
|
+
LocalTime,
|
|
721
|
+
Long,
|
|
722
|
+
ResultSet,
|
|
723
|
+
ResultStream,
|
|
724
|
+
Row,
|
|
725
|
+
DriverError,
|
|
726
|
+
TimeoutError,
|
|
727
|
+
TimeUuid,
|
|
728
|
+
Tuple,
|
|
729
|
+
Vector,
|
|
730
|
+
Uuid,
|
|
731
|
+
unset,
|
|
732
|
+
generateTimestamp,
|
|
733
|
+
}
|