@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,282 @@
|
|
|
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 Integer from "./integer.js"
|
|
19
|
+
import utils from "../utils.js"
|
|
20
|
+
|
|
21
|
+
/** @module types */
|
|
22
|
+
/**
|
|
23
|
+
* Constructs an immutable arbitrary-precision signed decimal number.
|
|
24
|
+
* A <code>BigDecimal</code> consists of an [arbitrary precision integer]{@link module:types~Integer}
|
|
25
|
+
* <i>unscaled value</i> and a 32-bit integer <i>scale</i>. If zero
|
|
26
|
+
* or positive, the scale is the number of digits to the right of the
|
|
27
|
+
* decimal point. If negative, the unscaled value of the number is
|
|
28
|
+
* multiplied by ten to the power of the negation of the scale. The
|
|
29
|
+
* value of the number represented by the <code>BigDecimal</code> is
|
|
30
|
+
* therefore <tt>(unscaledValue × 10<sup>-scale</sup>)</tt>.
|
|
31
|
+
* @class
|
|
32
|
+
* @classdesc The <code>BigDecimal</code> class provides operations for
|
|
33
|
+
* arithmetic, scale manipulation, rounding, comparison and
|
|
34
|
+
* format conversion. The {@link #toString} method provides a
|
|
35
|
+
* canonical representation of a <code>BigDecimal</code>.
|
|
36
|
+
* @param {Integer|Number} unscaledValue The integer part of the decimal.
|
|
37
|
+
* @param {Number} scale The scale of the decimal.
|
|
38
|
+
* @constructor
|
|
39
|
+
*/
|
|
40
|
+
function BigDecimal(unscaledValue, scale) {
|
|
41
|
+
if (typeof unscaledValue === "number") {
|
|
42
|
+
unscaledValue = Integer.fromNumber(unscaledValue)
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @type {Integer}
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
this._intVal = unscaledValue
|
|
49
|
+
/**
|
|
50
|
+
* @type {Number}
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
this._scale = scale
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the BigDecimal representation of a buffer composed of the scale (int32BE) and the unsigned value (varint BE)
|
|
58
|
+
* @param {Buffer} buf
|
|
59
|
+
* @returns {BigDecimal}
|
|
60
|
+
*/
|
|
61
|
+
BigDecimal.fromBuffer = function (buf) {
|
|
62
|
+
const scale = buf.readInt32BE(0)
|
|
63
|
+
const unscaledValue = Integer.fromBuffer(buf.slice(4))
|
|
64
|
+
return new BigDecimal(unscaledValue, scale)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns a buffer representation composed of the scale as a BE int 32 and the unsigned value as a BE varint
|
|
69
|
+
* @param {BigDecimal} value
|
|
70
|
+
* @returns {Buffer}
|
|
71
|
+
*/
|
|
72
|
+
BigDecimal.toBuffer = function (value) {
|
|
73
|
+
const unscaledValueBuffer = Integer.toBuffer(value._intVal)
|
|
74
|
+
const scaleBuffer = utils.allocBufferUnsafe(4)
|
|
75
|
+
scaleBuffer.writeInt32BE(value._scale, 0)
|
|
76
|
+
return Buffer.concat(
|
|
77
|
+
[scaleBuffer, unscaledValueBuffer],
|
|
78
|
+
scaleBuffer.length + unscaledValueBuffer.length,
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Returns a BigDecimal representation of the string
|
|
84
|
+
* @param {String} value
|
|
85
|
+
* @returns {BigDecimal}
|
|
86
|
+
*/
|
|
87
|
+
BigDecimal.fromString = function (value) {
|
|
88
|
+
if (!value) {
|
|
89
|
+
throw new TypeError("Invalid null or undefined value")
|
|
90
|
+
}
|
|
91
|
+
value = value.trim()
|
|
92
|
+
const scaleIndex = value.indexOf(".")
|
|
93
|
+
let scale = 0
|
|
94
|
+
if (scaleIndex >= 0) {
|
|
95
|
+
scale = value.length - 1 - scaleIndex
|
|
96
|
+
value = value.substr(0, scaleIndex) + value.substr(scaleIndex + 1)
|
|
97
|
+
}
|
|
98
|
+
return new BigDecimal(Integer.fromString(value), scale)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Returns a BigDecimal representation of the Number
|
|
103
|
+
* @param {Number} value
|
|
104
|
+
* @returns {BigDecimal}
|
|
105
|
+
*/
|
|
106
|
+
BigDecimal.fromNumber = function (value) {
|
|
107
|
+
if (isNaN(value)) {
|
|
108
|
+
return new BigDecimal(Integer.ZERO, 0)
|
|
109
|
+
}
|
|
110
|
+
let textValue = value.toString()
|
|
111
|
+
if (textValue.indexOf("e") >= 0) {
|
|
112
|
+
//get until scale 20
|
|
113
|
+
textValue = value.toFixed(20)
|
|
114
|
+
}
|
|
115
|
+
return BigDecimal.fromString(textValue)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Returns true if the value of the BigDecimal instance and other are the same
|
|
120
|
+
* @param {BigDecimal} other
|
|
121
|
+
* @returns {Boolean}
|
|
122
|
+
*/
|
|
123
|
+
BigDecimal.prototype.equals = function (other) {
|
|
124
|
+
return other instanceof BigDecimal && this.compare(other) === 0
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
BigDecimal.prototype.inspect = function () {
|
|
128
|
+
return this.constructor.name + ": " + this.toString()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @param {BigDecimal} other
|
|
133
|
+
* @returns {boolean}
|
|
134
|
+
*/
|
|
135
|
+
BigDecimal.prototype.notEquals = function (other) {
|
|
136
|
+
return !this.equals(other)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Compares this BigDecimal with the given one.
|
|
141
|
+
* @param {BigDecimal} other Integer to compare against.
|
|
142
|
+
* @return {number} 0 if they are the same, 1 if the this is greater, and -1
|
|
143
|
+
* if the given one is greater.
|
|
144
|
+
*/
|
|
145
|
+
BigDecimal.prototype.compare = function (other) {
|
|
146
|
+
const diff = this.subtract(other)
|
|
147
|
+
if (diff.isNegative()) {
|
|
148
|
+
return -1
|
|
149
|
+
}
|
|
150
|
+
if (diff.isZero()) {
|
|
151
|
+
return 0
|
|
152
|
+
}
|
|
153
|
+
return +1
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Returns the difference of this and the given BigDecimal.
|
|
158
|
+
* @param {BigDecimal} other The BigDecimal to subtract from this.
|
|
159
|
+
* @return {!BigDecimal} The BigDecimal result.
|
|
160
|
+
*/
|
|
161
|
+
BigDecimal.prototype.subtract = function (other) {
|
|
162
|
+
const first = this
|
|
163
|
+
if (first._scale === other._scale) {
|
|
164
|
+
return new BigDecimal(
|
|
165
|
+
first._intVal.subtract(other._intVal),
|
|
166
|
+
first._scale,
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
let diffScale
|
|
170
|
+
let unscaledValue
|
|
171
|
+
if (first._scale < other._scale) {
|
|
172
|
+
//The scale of this is lower
|
|
173
|
+
diffScale = other._scale - first._scale
|
|
174
|
+
//multiple this unScaledValue to compare in the same scale
|
|
175
|
+
unscaledValue = first._intVal
|
|
176
|
+
.multiply(Integer.fromNumber(Math.pow(10, diffScale)))
|
|
177
|
+
.subtract(other._intVal)
|
|
178
|
+
return new BigDecimal(unscaledValue, other._scale)
|
|
179
|
+
}
|
|
180
|
+
//The scale of this is higher
|
|
181
|
+
diffScale = first._scale - other._scale
|
|
182
|
+
//multiple this unScaledValue to compare in the same scale
|
|
183
|
+
unscaledValue = first._intVal.subtract(
|
|
184
|
+
other._intVal.multiply(Integer.fromNumber(Math.pow(10, diffScale))),
|
|
185
|
+
)
|
|
186
|
+
return new BigDecimal(unscaledValue, first._scale)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Returns the sum of this and the given <code>BigDecimal</code>.
|
|
191
|
+
* @param {BigDecimal} other The BigDecimal to sum to this.
|
|
192
|
+
* @return {!BigDecimal} The BigDecimal result.
|
|
193
|
+
*/
|
|
194
|
+
BigDecimal.prototype.add = function (other) {
|
|
195
|
+
const first = this
|
|
196
|
+
if (first._scale === other._scale) {
|
|
197
|
+
return new BigDecimal(first._intVal.add(other._intVal), first._scale)
|
|
198
|
+
}
|
|
199
|
+
let diffScale
|
|
200
|
+
let unscaledValue
|
|
201
|
+
if (first._scale < other._scale) {
|
|
202
|
+
//The scale of this is lower
|
|
203
|
+
diffScale = other._scale - first._scale
|
|
204
|
+
//multiple this unScaledValue to compare in the same scale
|
|
205
|
+
unscaledValue = first._intVal
|
|
206
|
+
.multiply(Integer.fromNumber(Math.pow(10, diffScale)))
|
|
207
|
+
.add(other._intVal)
|
|
208
|
+
return new BigDecimal(unscaledValue, other._scale)
|
|
209
|
+
}
|
|
210
|
+
//The scale of this is higher
|
|
211
|
+
diffScale = first._scale - other._scale
|
|
212
|
+
//multiple this unScaledValue to compare in the same scale
|
|
213
|
+
unscaledValue = first._intVal.add(
|
|
214
|
+
other._intVal.multiply(Integer.fromNumber(Math.pow(10, diffScale))),
|
|
215
|
+
)
|
|
216
|
+
return new BigDecimal(unscaledValue, first._scale)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Returns true if the current instance is greater than the other
|
|
221
|
+
* @param {BigDecimal} other
|
|
222
|
+
* @returns {boolean}
|
|
223
|
+
*/
|
|
224
|
+
BigDecimal.prototype.greaterThan = function (other) {
|
|
225
|
+
return this.compare(other) === 1
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** @return {boolean} Whether this value is negative. */
|
|
229
|
+
BigDecimal.prototype.isNegative = function () {
|
|
230
|
+
return this._intVal.isNegative()
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** @return {boolean} Whether this value is zero. */
|
|
234
|
+
BigDecimal.prototype.isZero = function () {
|
|
235
|
+
return this._intVal.isZero()
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Returns the string representation of this <code>BigDecimal</code>
|
|
240
|
+
* @returns {string}
|
|
241
|
+
*/
|
|
242
|
+
BigDecimal.prototype.toString = function () {
|
|
243
|
+
let intString = this._intVal.toString()
|
|
244
|
+
if (this._scale === 0) {
|
|
245
|
+
return intString
|
|
246
|
+
}
|
|
247
|
+
let signSymbol = ""
|
|
248
|
+
if (intString.charAt(0) === "-") {
|
|
249
|
+
signSymbol = "-"
|
|
250
|
+
intString = intString.substr(1)
|
|
251
|
+
}
|
|
252
|
+
let separatorIndex = intString.length - this._scale
|
|
253
|
+
if (separatorIndex <= 0) {
|
|
254
|
+
//add zeros at the beginning, plus an additional zero
|
|
255
|
+
intString = utils.stringRepeat("0", -separatorIndex + 1) + intString
|
|
256
|
+
separatorIndex = intString.length - this._scale
|
|
257
|
+
}
|
|
258
|
+
return (
|
|
259
|
+
signSymbol +
|
|
260
|
+
intString.substr(0, separatorIndex) +
|
|
261
|
+
"." +
|
|
262
|
+
intString.substr(separatorIndex)
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Returns a Number representation of this <code>BigDecimal</code>.
|
|
268
|
+
* @returns {Number}
|
|
269
|
+
*/
|
|
270
|
+
BigDecimal.prototype.toNumber = function () {
|
|
271
|
+
return parseFloat(this.toString())
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Returns the string representation.
|
|
276
|
+
* Method used by the native JSON.stringify() to serialize this instance.
|
|
277
|
+
*/
|
|
278
|
+
BigDecimal.prototype.toJSON = function () {
|
|
279
|
+
return this.toString()
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export default BigDecimal
|