@ragestudio/scylla-odm 0.22.2 → 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/client.d.ts +6 -5
- package/client.d.ts.map +1 -1
- package/client.js +7 -7
- 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
package/driver/token.js
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
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 types from "./types/index.js"
|
|
19
|
+
import util from "util"
|
|
20
|
+
|
|
21
|
+
const _Murmur3TokenType = types.dataTypes.getByName("bigint")
|
|
22
|
+
const _RandomTokenType = types.dataTypes.getByName("varint")
|
|
23
|
+
const _OrderedTokenType = types.dataTypes.getByName("blob")
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Represents a token on the Cassandra ring.
|
|
27
|
+
*/
|
|
28
|
+
class Token {
|
|
29
|
+
constructor(value) {
|
|
30
|
+
this._value = value
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @returns {{code: number, info: *|Object}} The type info for the
|
|
35
|
+
* type of the value of the token.
|
|
36
|
+
*/
|
|
37
|
+
getType() {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"You must implement a getType function for this Token instance",
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @returns {*} The raw value of the token.
|
|
45
|
+
*/
|
|
46
|
+
getValue() {
|
|
47
|
+
return this._value
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
toString() {
|
|
51
|
+
return this._value.toString()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns 0 if the values are equal, 1 if greater than other, -1
|
|
56
|
+
* otherwise.
|
|
57
|
+
*
|
|
58
|
+
* @param {Token} other
|
|
59
|
+
* @returns {Number}
|
|
60
|
+
*/
|
|
61
|
+
compare(other) {
|
|
62
|
+
return this._value.compare(other._value)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
equals(other) {
|
|
66
|
+
return this.compare(other) === 0
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
inspect() {
|
|
70
|
+
return this.constructor.name + " { " + this.toString() + " }"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Represents a token from a Cassandra ring where the partitioner
|
|
76
|
+
* is Murmur3Partitioner.
|
|
77
|
+
*
|
|
78
|
+
* The raw token type is a varint (represented by MutableLong).
|
|
79
|
+
*/
|
|
80
|
+
class Murmur3Token extends Token {
|
|
81
|
+
constructor(value) {
|
|
82
|
+
super(value)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getType() {
|
|
86
|
+
return _Murmur3TokenType
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Represents a token from a Cassandra ring where the partitioner
|
|
92
|
+
* is RandomPartitioner.
|
|
93
|
+
*
|
|
94
|
+
* The raw token type is a bigint (represented by Number).
|
|
95
|
+
*/
|
|
96
|
+
class RandomToken extends Token {
|
|
97
|
+
constructor(value) {
|
|
98
|
+
super(value)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getType() {
|
|
102
|
+
return _RandomTokenType
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Represents a token from a Cassandra ring where the partitioner
|
|
108
|
+
* is ByteOrderedPartitioner.
|
|
109
|
+
*
|
|
110
|
+
* The raw token type is a blob (represented by Buffer or Array).
|
|
111
|
+
*/
|
|
112
|
+
class ByteOrderedToken extends Token {
|
|
113
|
+
constructor(value) {
|
|
114
|
+
super(value)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
getType() {
|
|
118
|
+
return _OrderedTokenType
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
toString() {
|
|
122
|
+
return this._value.toString("hex").toUpperCase()
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Represents a range of tokens on a Cassandra ring.
|
|
128
|
+
*
|
|
129
|
+
* A range is start-exclusive and end-inclusive. It is empty when
|
|
130
|
+
* start and end are the same token, except if that is the minimum
|
|
131
|
+
* token, in which case the range covers the whole ring (this is
|
|
132
|
+
* consistent with the behavior of CQL range queries).
|
|
133
|
+
*
|
|
134
|
+
* Note that CQL does not handle wrapping. To query all partitions
|
|
135
|
+
* in a range, see {@link unwrap}.
|
|
136
|
+
*/
|
|
137
|
+
class TokenRange {
|
|
138
|
+
constructor(start, end, tokenizer) {
|
|
139
|
+
this.start = start
|
|
140
|
+
this.end = end
|
|
141
|
+
Object.defineProperty(this, "_tokenizer", {
|
|
142
|
+
value: tokenizer,
|
|
143
|
+
enumerable: false,
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Splits this range into a number of smaller ranges of equal "size"
|
|
149
|
+
* (referring to the number of tokens, not the actual amount of data).
|
|
150
|
+
*
|
|
151
|
+
* Splitting an empty range is not permitted. But not that, in edge
|
|
152
|
+
* cases, splitting a range might produce one or more empty ranges.
|
|
153
|
+
*
|
|
154
|
+
* @param {Number} numberOfSplits Number of splits to make.
|
|
155
|
+
* @returns {TokenRange[]} Split ranges.
|
|
156
|
+
* @throws {Error} If splitting an empty range.
|
|
157
|
+
*/
|
|
158
|
+
splitEvenly(numberOfSplits) {
|
|
159
|
+
if (numberOfSplits < 1) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
util.format(
|
|
162
|
+
"numberOfSplits (%d) must be greater than 0.",
|
|
163
|
+
numberOfSplits,
|
|
164
|
+
),
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
if (this.isEmpty()) {
|
|
168
|
+
throw new Error("Can't split empty range " + this.toString())
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const tokenRanges = []
|
|
172
|
+
const splitPoints = this._tokenizer.split(
|
|
173
|
+
this.start,
|
|
174
|
+
this.end,
|
|
175
|
+
numberOfSplits,
|
|
176
|
+
)
|
|
177
|
+
let splitStart = this.start
|
|
178
|
+
let splitEnd
|
|
179
|
+
for (
|
|
180
|
+
let splitIndex = 0;
|
|
181
|
+
splitIndex < splitPoints.length;
|
|
182
|
+
splitIndex++
|
|
183
|
+
) {
|
|
184
|
+
splitEnd = splitPoints[splitIndex]
|
|
185
|
+
tokenRanges.push(
|
|
186
|
+
new TokenRange(splitStart, splitEnd, this._tokenizer),
|
|
187
|
+
)
|
|
188
|
+
splitStart = splitEnd
|
|
189
|
+
}
|
|
190
|
+
tokenRanges.push(new TokenRange(splitStart, this.end, this._tokenizer))
|
|
191
|
+
return tokenRanges
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* A range is empty when start and end are the same token, except if
|
|
196
|
+
* that is the minimum token, in which case the range covers the
|
|
197
|
+
* whole ring. This is consistent with the behavior of CQL range
|
|
198
|
+
* queries.
|
|
199
|
+
*
|
|
200
|
+
* @returns {boolean} Whether this range is empty.
|
|
201
|
+
*/
|
|
202
|
+
isEmpty() {
|
|
203
|
+
return (
|
|
204
|
+
this.start.equals(this.end) &&
|
|
205
|
+
!this.start.equals(this._tokenizer.minToken())
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A range wraps around the end of the ring when the start token
|
|
211
|
+
* is greater than the end token and the end token is not the
|
|
212
|
+
* minimum token.
|
|
213
|
+
*
|
|
214
|
+
* @returns {boolean} Whether this range wraps around.
|
|
215
|
+
*/
|
|
216
|
+
isWrappedAround() {
|
|
217
|
+
return (
|
|
218
|
+
this.start.compare(this.end) > 0 &&
|
|
219
|
+
!this.end.equals(this._tokenizer.minToken())
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Splits this range into a list of two non-wrapping ranges.
|
|
225
|
+
*
|
|
226
|
+
* This will return the range itself if it is non-wrapped, or two
|
|
227
|
+
* ranges otherwise.
|
|
228
|
+
*
|
|
229
|
+
* This is useful for CQL range queries, which do not handle
|
|
230
|
+
* wrapping.
|
|
231
|
+
*
|
|
232
|
+
* @returns {TokenRange[]} The list of non-wrapping ranges.
|
|
233
|
+
*/
|
|
234
|
+
unwrap() {
|
|
235
|
+
if (this.isWrappedAround()) {
|
|
236
|
+
return [
|
|
237
|
+
new TokenRange(
|
|
238
|
+
this.start,
|
|
239
|
+
this._tokenizer.minToken(),
|
|
240
|
+
this._tokenizer,
|
|
241
|
+
),
|
|
242
|
+
new TokenRange(
|
|
243
|
+
this._tokenizer.minToken(),
|
|
244
|
+
this.end,
|
|
245
|
+
this._tokenizer,
|
|
246
|
+
),
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
return [this]
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Whether this range contains a given Token.
|
|
254
|
+
*
|
|
255
|
+
* @param {*} token Token to check for.
|
|
256
|
+
* @returns {boolean} Whether or not the Token is in this range.
|
|
257
|
+
*/
|
|
258
|
+
contains(token) {
|
|
259
|
+
if (this.isEmpty()) {
|
|
260
|
+
return false
|
|
261
|
+
}
|
|
262
|
+
const minToken = this._tokenizer.minToken()
|
|
263
|
+
if (this.end.equals(minToken)) {
|
|
264
|
+
if (this.start.equals(minToken)) {
|
|
265
|
+
return true // ]minToken, minToken] === full ring
|
|
266
|
+
} else if (token.equals(minToken)) {
|
|
267
|
+
return true
|
|
268
|
+
}
|
|
269
|
+
return token.compare(this.start) > 0
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const isAfterStart = token.compare(this.start) > 0
|
|
273
|
+
const isBeforeEnd = token.compare(this.end) <= 0
|
|
274
|
+
// if wrapped around ring, token is in ring if its after start or before end.
|
|
275
|
+
// otherwise, token is in ring if its after start and before end.
|
|
276
|
+
return this.isWrappedAround()
|
|
277
|
+
? isAfterStart || isBeforeEnd
|
|
278
|
+
: isAfterStart && isBeforeEnd
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Determines if the input range is equivalent to this one.
|
|
283
|
+
*
|
|
284
|
+
* @param {TokenRange} other Range to compare with.
|
|
285
|
+
* @returns {boolean} Whether or not the ranges are equal.
|
|
286
|
+
*/
|
|
287
|
+
equals(other) {
|
|
288
|
+
if (other === this) {
|
|
289
|
+
return true
|
|
290
|
+
} else if (other instanceof TokenRange) {
|
|
291
|
+
return this.compare(other) === 0
|
|
292
|
+
}
|
|
293
|
+
return false
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Returns 0 if the values are equal, otherwise compares against
|
|
298
|
+
* start, if start is equal, compares against end.
|
|
299
|
+
*
|
|
300
|
+
* @param {TokenRange} other Range to compare with.
|
|
301
|
+
* @returns {Number}
|
|
302
|
+
*/
|
|
303
|
+
compare(other) {
|
|
304
|
+
const compareStart = this.start.compare(other.start)
|
|
305
|
+
return compareStart !== 0 ? compareStart : this.end.compare(other.end)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
toString() {
|
|
309
|
+
return util.format(
|
|
310
|
+
"]%s, %s]",
|
|
311
|
+
this.start.toString(),
|
|
312
|
+
this.end.toString(),
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export { Token, TokenRange, ByteOrderedToken, Murmur3Token, RandomToken }
|
|
318
|
+
|
|
319
|
+
export default {
|
|
320
|
+
Token,
|
|
321
|
+
TokenRange,
|
|
322
|
+
ByteOrderedToken,
|
|
323
|
+
Murmur3Token,
|
|
324
|
+
RandomToken,
|
|
325
|
+
}
|