@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.
Files changed (153) hide show
  1. package/batch/index.d.ts +3 -3
  2. package/batch/index.d.ts.map +1 -1
  3. package/client.d.ts +6 -5
  4. package/client.d.ts.map +1 -1
  5. package/client.js +7 -7
  6. package/client.js.map +1 -1
  7. package/cql_gen/create_table.d.ts +1 -1
  8. package/cql_gen/create_table.d.ts.map +1 -1
  9. package/document/index.d.ts +3 -3
  10. package/document/index.d.ts.map +1 -1
  11. package/driver/LICENSE.txt +177 -0
  12. package/driver/NOTICE.txt +67 -0
  13. package/driver/auth/index.d.ts +37 -0
  14. package/driver/auth/index.js +37 -0
  15. package/driver/auth/no-auth-provider.js +73 -0
  16. package/driver/auth/plain-text-auth-provider.js +81 -0
  17. package/driver/auth/provider.js +77 -0
  18. package/driver/client-options.js +442 -0
  19. package/driver/client.js +1267 -0
  20. package/driver/concurrent/index.d.ts +49 -0
  21. package/driver/concurrent/index.js +366 -0
  22. package/driver/connection.js +1034 -0
  23. package/driver/control-connection.js +1282 -0
  24. package/driver/encoder.js +2316 -0
  25. package/driver/errors.js +223 -0
  26. package/driver/execution-options.js +612 -0
  27. package/driver/execution-profile.js +274 -0
  28. package/driver/host-connection-pool.js +587 -0
  29. package/driver/host.js +699 -0
  30. package/driver/index.d.ts +387 -0
  31. package/driver/index.js +81 -0
  32. package/driver/mapping/cache.js +214 -0
  33. package/driver/mapping/doc-info-adapter.js +171 -0
  34. package/driver/mapping/index.d.ts +219 -0
  35. package/driver/mapping/index.js +57 -0
  36. package/driver/mapping/mapper.js +225 -0
  37. package/driver/mapping/mapping-handler.js +641 -0
  38. package/driver/mapping/model-batch-item.js +215 -0
  39. package/driver/mapping/model-batch-mapper.js +141 -0
  40. package/driver/mapping/model-mapper.js +315 -0
  41. package/driver/mapping/model-mapping-info.js +225 -0
  42. package/driver/mapping/object-selector.js +417 -0
  43. package/driver/mapping/q.js +156 -0
  44. package/driver/mapping/query-generator.js +556 -0
  45. package/driver/mapping/result-mapper.js +123 -0
  46. package/driver/mapping/result.js +139 -0
  47. package/driver/mapping/table-mappings.js +133 -0
  48. package/driver/mapping/tree.js +160 -0
  49. package/driver/metadata/aggregate.js +79 -0
  50. package/driver/metadata/client-state.js +119 -0
  51. package/driver/metadata/data-collection.js +182 -0
  52. package/driver/metadata/event-debouncer.js +174 -0
  53. package/driver/metadata/index.d.ts +276 -0
  54. package/driver/metadata/index.js +1156 -0
  55. package/driver/metadata/materialized-view.js +49 -0
  56. package/driver/metadata/schema-function.js +98 -0
  57. package/driver/metadata/schema-index.js +166 -0
  58. package/driver/metadata/schema-parser.js +1399 -0
  59. package/driver/metadata/table-metadata.js +77 -0
  60. package/driver/operation-state.js +206 -0
  61. package/driver/policies/address-resolution.js +145 -0
  62. package/driver/policies/index.d.ts +241 -0
  63. package/driver/policies/index.js +110 -0
  64. package/driver/policies/load-balancing.js +970 -0
  65. package/driver/policies/reconnection.js +166 -0
  66. package/driver/policies/retry.js +326 -0
  67. package/driver/policies/speculative-execution.js +150 -0
  68. package/driver/policies/timestamp-generation.js +176 -0
  69. package/driver/prepare-handler.js +347 -0
  70. package/driver/promise-utils.js +191 -0
  71. package/driver/readers.js +624 -0
  72. package/driver/request-execution.js +644 -0
  73. package/driver/request-handler.js +332 -0
  74. package/driver/requests.js +618 -0
  75. package/driver/stream-id-stack.js +209 -0
  76. package/driver/streams.js +745 -0
  77. package/driver/token.js +325 -0
  78. package/driver/tokenizer.js +631 -0
  79. package/driver/types/big-decimal.js +282 -0
  80. package/driver/types/duration.js +576 -0
  81. package/driver/types/index.d.ts +486 -0
  82. package/driver/types/index.js +733 -0
  83. package/driver/types/inet-address.js +262 -0
  84. package/driver/types/integer.js +818 -0
  85. package/driver/types/local-date.js +280 -0
  86. package/driver/types/local-time.js +299 -0
  87. package/driver/types/mutable-long.js +385 -0
  88. package/driver/types/protocol-version.js +391 -0
  89. package/driver/types/result-set.js +287 -0
  90. package/driver/types/result-stream.js +164 -0
  91. package/driver/types/row.js +85 -0
  92. package/driver/types/time-uuid.js +414 -0
  93. package/driver/types/tuple.js +103 -0
  94. package/driver/types/uuid.js +160 -0
  95. package/driver/types/vector.js +130 -0
  96. package/driver/types/version-number.js +153 -0
  97. package/driver/utils.js +1485 -0
  98. package/driver/writers.js +350 -0
  99. package/global.d.ts +1 -1
  100. package/global.d.ts.map +1 -1
  101. package/index.d.ts +6 -6
  102. package/index.d.ts.map +1 -1
  103. package/index.js +6 -6
  104. package/index.js.map +1 -1
  105. package/migrate/index.d.ts +1 -1
  106. package/migrate/index.d.ts.map +1 -1
  107. package/migrate/index.js +1 -1
  108. package/migrate/index.js.map +1 -1
  109. package/model/index.d.ts +6 -6
  110. package/model/index.d.ts.map +1 -1
  111. package/model/index.js +10 -10
  112. package/model/index.js.map +1 -1
  113. package/operations/countAll.d.ts +1 -1
  114. package/operations/countAll.d.ts.map +1 -1
  115. package/operations/delete.d.ts +3 -4
  116. package/operations/delete.d.ts.map +1 -1
  117. package/operations/delete.js +1 -1
  118. package/operations/delete.js.map +1 -1
  119. package/operations/find.d.ts +2 -2
  120. package/operations/find.d.ts.map +1 -1
  121. package/operations/find.js +1 -1
  122. package/operations/find.js.map +1 -1
  123. package/operations/findOne.d.ts +2 -2
  124. package/operations/findOne.d.ts.map +1 -1
  125. package/operations/findOne.js +1 -1
  126. package/operations/findOne.js.map +1 -1
  127. package/operations/insert.d.ts +3 -3
  128. package/operations/insert.d.ts.map +1 -1
  129. package/operations/insert.js +2 -2
  130. package/operations/insert.js.map +1 -1
  131. package/operations/sync.d.ts +1 -1
  132. package/operations/sync.d.ts.map +1 -1
  133. package/operations/sync.js +1 -1
  134. package/operations/sync.js.map +1 -1
  135. package/operations/tableExists.d.ts +1 -1
  136. package/operations/tableExists.d.ts.map +1 -1
  137. package/operations/update.d.ts +3 -3
  138. package/operations/update.d.ts.map +1 -1
  139. package/operations/update.js +2 -2
  140. package/operations/update.js.map +1 -1
  141. package/package.json +4 -12
  142. package/schema/index.d.ts +1 -1
  143. package/schema/index.d.ts.map +1 -1
  144. package/types.d.ts +4 -4
  145. package/types.d.ts.map +1 -1
  146. package/utils/queryParser.d.ts +1 -1
  147. package/utils/queryParser.d.ts.map +1 -1
  148. package/utils/queryParser.js +1 -1
  149. package/utils/queryParser.js.map +1 -1
  150. package/utils/typeChecker.d.ts +1 -1
  151. package/utils/typeChecker.d.ts.map +1 -1
  152. package/utils/typeChecker.js +1 -1
  153. package/utils/typeChecker.js.map +1 -1
@@ -0,0 +1,274 @@
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 utils from "./utils.js"
20
+ import types from "./types/index.js"
21
+ import promiseUtils from "./promise-utils.js"
22
+
23
+ /**
24
+ * Creates a new instance of {@link ExecutionProfile}.
25
+ * @classdesc
26
+ * Represents a set configurations to be used in a statement execution to be used for a single {@link Client} instance.
27
+ * <p>
28
+ * An {@link ExecutionProfile} instance should not be shared across different {@link Client} instances.
29
+ * </p>
30
+ * @param {String} name Name of the execution profile.
31
+ * <p>
32
+ * Use <code>'default'</code> to specify that the new instance should be the default {@link ExecutionProfile} if no
33
+ * profile is specified in the execution.
34
+ * </p>
35
+ * @param {Object} [options] Profile options, when any of the options is not specified the {@link Client} will the use
36
+ * the ones defined in the default profile.
37
+ * @param {Number} [options.consistency] The consistency level to use for this profile.
38
+ * @param {LoadBalancingPolicy} [options.loadBalancing] The load-balancing policy to use for this profile.
39
+ * @param {Number} [options.readTimeout] The client per-host request timeout to use for this profile.
40
+ * @param {RetryPolicy} [options.retry] The retry policy to use for this profile.
41
+ * @param {Number} [options.serialConsistency] The serial consistency level to use for this profile.
42
+ * @param {Object} [options.graphOptions]
43
+ * @param {String} [options.graphOptions.language] The graph language to use for graph queries.
44
+ * <p>
45
+ * Note that this setting should normally be <code>undefined</code> or set by a utility method and it's not expected
46
+ * to be defined manually by the user.
47
+ * </p>
48
+ * @param {String} [options.graphOptions.results] The protocol to use for serializing and deserializing graph results.
49
+ * <p>
50
+ * Note that this setting should normally be <code>undefined</code> or set by a utility method and it's not expected
51
+ * to be defined manually by the user.
52
+ * </p>
53
+ * @param {String} [options.graphOptions.name] The graph name to use for graph queries.
54
+ * @param {Number} [options.graphOptions.readConsistency] The consistency level to use for graph read queries.
55
+ * @param {String} [options.graphOptions.source] The graph traversal source name to use for graph queries.
56
+ * @param {Number} [options.graphOptions.writeConsistency] The consistency level to use for graph write queries.
57
+ * @param {LoadBalancingPolicy} [options.loadBalancing] The load-balancing policy to use for this profile.
58
+ * @param {Number} [options.readTimeout] The client per-host request timeout to use for this profile.
59
+ * @param {RetryPolicy} [options.retry] The retry policy to use for this profile.
60
+ * @param {Number} [options.serialConsistency] The serial consistency level to use for this profile.
61
+ * @example
62
+ * const { Client, ExecutionProfile } = require('cassandra-driver');
63
+ * const client = new Client({
64
+ * contactPoints: ['host1', 'host2'],
65
+ * profiles: [
66
+ * new ExecutionProfile('metrics-oltp', {
67
+ * consistency: consistency.localQuorum,
68
+ * retry: myRetryPolicy
69
+ * })
70
+ * ]
71
+ * });
72
+ *
73
+ * client.execute(query, params, { executionProfile: 'metrics-oltp' }, callback);
74
+ * @constructor
75
+ */
76
+ function ExecutionProfile(name, options) {
77
+ if (typeof name !== "string") {
78
+ throw new TypeError("Execution profile name must be a string")
79
+ }
80
+ options = options || utils.emptyObject
81
+ const graphOptions = options.graphOptions || utils.emptyObject
82
+ /**
83
+ * Name of the execution profile.
84
+ * @type {String}
85
+ */
86
+ this.name = name
87
+ /**
88
+ * Consistency level.
89
+ * @type {Number}
90
+ */
91
+ this.consistency = options.consistency
92
+ /**
93
+ * Load-balancing policy
94
+ * @type {LoadBalancingPolicy}
95
+ */
96
+ this.loadBalancing = options.loadBalancing
97
+ /**
98
+ * Client read timeout.
99
+ * @type {Number}
100
+ */
101
+ this.readTimeout = options.readTimeout
102
+ /**
103
+ * Retry policy.
104
+ * @type {RetryPolicy}
105
+ */
106
+ this.retry = options.retry
107
+ /**
108
+ * Serial consistency level.
109
+ * @type {Number}
110
+ */
111
+ this.serialConsistency = options.serialConsistency
112
+ /**
113
+ * The graph options for this profile.
114
+ * @type {Object}
115
+ * @property {String} language The graph language.
116
+ * @property {String} name The graph name.
117
+ * @property {String} readConsistency The consistency to use for graph write queries.
118
+ * @property {String} source The graph traversal source.
119
+ * @property {String} writeConsistency The consistency to use for graph write queries.
120
+ */
121
+ this.graphOptions = {
122
+ language: graphOptions.language,
123
+ results: graphOptions.results,
124
+ name: graphOptions.name,
125
+ readConsistency: graphOptions.readConsistency,
126
+ source: graphOptions.source,
127
+ writeConsistency: graphOptions.writeConsistency,
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Contains the logic to handle the different execution profiles of a {@link Client}.
133
+ * @ignore
134
+ */
135
+ class ProfileManager {
136
+ /**
137
+ * @param {ClientOptions} options
138
+ */
139
+ constructor(options) {
140
+ this._profiles = options.profiles || []
141
+ this._defaultConfiguredRetryPolicy = undefined
142
+ this._setDefault(options)
143
+ // A array of unique load balancing policies
144
+ this._loadBalancingPolicies = []
145
+ // A dictionary of name keys and profile values
146
+ this._profilesMap = {}
147
+ // A dictionary of name keys and custom payload dictionaries as values
148
+ this._customPayloadCache = {}
149
+ // A dictionary of name keys and graph options as values
150
+ this._graphOptionsCache = {}
151
+ this._profiles.forEach(function (p) {
152
+ this._profilesMap[p.name] = p
153
+ // Set required properties
154
+ p.loadBalancing =
155
+ p.loadBalancing || this._defaultProfile.loadBalancing
156
+ // Using array indexOf is not very efficient (O(n)) but the amount of profiles should be limited
157
+ // and a handful of load-balancing policies (no hashcode for load-Balancing policies)
158
+ if (this._loadBalancingPolicies.indexOf(p.loadBalancing) === -1) {
159
+ this._loadBalancingPolicies.push(p.loadBalancing)
160
+ }
161
+ return p
162
+ }, this)
163
+ }
164
+
165
+ /**
166
+ * @param {Client} client
167
+ * @param {HostMap} hosts
168
+ */
169
+ async init(client, hosts) {
170
+ for (const lbp of this._loadBalancingPolicies) {
171
+ await promiseUtils.fromCallback((callback) =>
172
+ lbp.init(client, hosts, callback),
173
+ )
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Uses the load-balancing policies to get the relative distance to the host and return the closest one.
179
+ * @param {Host} host
180
+ */
181
+ getDistance(host) {
182
+ let distance = types.distance.ignored
183
+ // this is performance critical: we can't use any other language features than for-loop :(
184
+ for (let i = 0; i < this._loadBalancingPolicies.length; i++) {
185
+ const d = this._loadBalancingPolicies[i].getDistance(host)
186
+ if (d < distance) {
187
+ distance = d
188
+ if (distance === types.distance.local) {
189
+ break
190
+ }
191
+ }
192
+ }
193
+
194
+ host.setDistance(distance)
195
+ return distance
196
+ }
197
+
198
+ /**
199
+ * @param {String|ExecutionProfile} name
200
+ * @returns {ExecutionProfile|undefined} It returns the execution profile by name or the default profile when name is
201
+ * undefined. It returns undefined when the profile does not exist.
202
+ */
203
+ getProfile(name) {
204
+ if (name instanceof ExecutionProfile) {
205
+ return name
206
+ }
207
+ return this._profilesMap[name || "default"]
208
+ }
209
+
210
+ /** @returns {ExecutionProfile} */
211
+ getDefault() {
212
+ return this._defaultProfile
213
+ }
214
+
215
+ /** @returns {LoadBalancingPolicy} */
216
+ getDefaultLoadBalancing() {
217
+ return this._defaultProfile.loadBalancing
218
+ }
219
+
220
+ /**
221
+ * Gets the cached default graph options for a given profile. If it doesn't exist, it creates new options using the
222
+ * handler and inserts it into the cache
223
+ * @param {ExecutionProfile} profile
224
+ * @param {Function} createHandler
225
+ */
226
+ getOrCreateGraphOptions(profile, createHandler) {
227
+ let graphOptions = this._graphOptionsCache[profile.name]
228
+ if (!graphOptions) {
229
+ graphOptions = this._graphOptionsCache[profile.name] =
230
+ createHandler()
231
+ }
232
+ return graphOptions
233
+ }
234
+
235
+ /**
236
+ * @private
237
+ * @param {ClientOptions} options
238
+ */
239
+ _setDefault(options) {
240
+ this._defaultProfile = this._profiles.filter(function (p) {
241
+ return p.name === "default"
242
+ })[0]
243
+ if (!this._defaultProfile) {
244
+ this._profiles.push(
245
+ (this._defaultProfile = new ExecutionProfile("default")),
246
+ )
247
+ }
248
+
249
+ // Store the default configured retry policy
250
+ this._defaultConfiguredRetryPolicy = this._defaultProfile.retry
251
+
252
+ // Set the required properties
253
+ this._defaultProfile.loadBalancing =
254
+ this._defaultProfile.loadBalancing || options.policies.loadBalancing
255
+ this._defaultProfile.retry =
256
+ this._defaultProfile.retry || options.policies.retry
257
+ }
258
+
259
+ /**
260
+ * Gets all the execution profiles currently defined.
261
+ * @returns {Array.<ExecutionProfile>}
262
+ */
263
+ getAll() {
264
+ return this._profiles
265
+ }
266
+
267
+ getDefaultConfiguredRetryPolicy() {
268
+ return this._defaultConfiguredRetryPolicy
269
+ }
270
+ }
271
+
272
+ export { ProfileManager, ExecutionProfile }
273
+
274
+ export default { ProfileManager, ExecutionProfile }