@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.
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 +11 -12
  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,123 @@
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 vm from "vm"
20
+ import utils from "../utils.js"
21
+ import types from "../types/index.js"
22
+
23
+ /**
24
+ * @ignore
25
+ */
26
+ class ResultMapper {
27
+ /**
28
+ * Gets a generated function to adapt the row to a document.
29
+ * @param {ModelMappingInfo} info
30
+ * @param {ResultSet} rs
31
+ * @returns {Function}
32
+ */
33
+ static getSelectAdapter(info, rs) {
34
+ const columns = rs.columns
35
+ if (!columns) {
36
+ throw new Error("Expected ROWS result obtained VOID")
37
+ }
38
+
39
+ let scriptText =
40
+ "(function rowAdapter(row, info) {\n" +
41
+ " const item = info.newInstance();\n"
42
+
43
+ for (const c of columns) {
44
+ scriptText += ` item['${info.getPropertyName(c.name)}'] = `
45
+
46
+ if (!info.getToModelFn(c.name)) {
47
+ scriptText += `row['${c.name}'];\n`
48
+ } else {
49
+ scriptText += `info.getToModelFn('${c.name}')(row['${c.name}']);\n`
50
+ }
51
+ }
52
+
53
+ scriptText += " return item;\n})"
54
+
55
+ const script = new vm.Script(scriptText, {
56
+ filename: "gen-result-mapper",
57
+ })
58
+ return script.runInThisContext()
59
+ }
60
+
61
+ /**
62
+ * Gets a function used to adapt VOID results or conditional updates.
63
+ * @param {ResultSet} rs
64
+ * @returns {Function}
65
+ */
66
+ static getMutationAdapter(rs) {
67
+ if (rs.columns === null) {
68
+ // VOID result
69
+ return utils.noop
70
+ }
71
+
72
+ if (
73
+ rs.columns.length === 1 &&
74
+ rs.columns[0].name === "[applied]" &&
75
+ rs.columns[0].type.code === types.dataTypes.boolean
76
+ ) {
77
+ return utils.noop
78
+ }
79
+
80
+ return ResultMapper._getConditionalRowAdapter(rs)
81
+ }
82
+
83
+ static _getConditionalRowAdapter(rs) {
84
+ return function conditionalRowAdapter(row, info) {
85
+ const item = info.newInstance()
86
+
87
+ // Skip the first column ("[applied]")
88
+ for (let i = 1; i < rs.columns.length; i++) {
89
+ const c = rs.columns[i]
90
+ item[info.getPropertyName(c.name)] = row[c.name]
91
+ }
92
+
93
+ return item
94
+ }
95
+ }
96
+
97
+ /**
98
+ * @param {ModelMappingInfo} info
99
+ * @param {ResultSet} rs
100
+ * @returns {{canCache: Boolean, fn: Function}}
101
+ */
102
+ static getCustomQueryAdapter(info, rs) {
103
+ if (rs.columns === null || rs.columns.length === 0) {
104
+ // VOID result
105
+ return { canCache: true, fn: utils.noop }
106
+ }
107
+
108
+ if (
109
+ rs.columns[0].name === "[applied]" &&
110
+ rs.columns[0].type.code === types.dataTypes.boolean
111
+ ) {
112
+ // Conditional update results adapter functions should not be cached
113
+ return {
114
+ canCache: false,
115
+ fn: ResultMapper._getConditionalRowAdapter(rs),
116
+ }
117
+ }
118
+
119
+ return { canCache: true, fn: ResultMapper.getSelectAdapter(info, rs) }
120
+ }
121
+ }
122
+
123
+ export default ResultMapper
@@ -0,0 +1,139 @@
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
+ const inspectMethod = util.inspect.custom || "inspect"
22
+
23
+ /**
24
+ * Represents the result of an execution as an iterable of objects in the Mapper.
25
+ * @alias module:mapping~Result
26
+ */
27
+ class Result {
28
+ /**
29
+ * Creates a new instance of Result.
30
+ * @param {ResultSet} rs
31
+ * @param {ModelMappingInfo} info
32
+ * @param {Function} rowAdapter
33
+ */
34
+ constructor(rs, info, rowAdapter) {
35
+ this._rs = rs
36
+ this._info = info
37
+ this._rowAdapter = rowAdapter
38
+
39
+ /**
40
+ * When there is a single cell containing the result of the a LWT operation, hide the result from the user.
41
+ * @private
42
+ */
43
+ this._isEmptyLwt =
44
+ rs.columns !== null &&
45
+ rs.columns.length === 1 &&
46
+ this._rs.rowLength === 1 &&
47
+ rs.columns[0].name === "[applied]"
48
+
49
+ /**
50
+ * Gets the amount of the documents contained in this Result instance.
51
+ * <p>
52
+ * When the results are paged, it returns the length of the current paged results not the total amount of
53
+ * rows in the table matching the query.
54
+ * </p>
55
+ * @type {Number}
56
+ */
57
+ this.length = this._isEmptyLwt ? 0 : rs.rowLength || 0
58
+
59
+ /**
60
+ * A string token representing the current page state of query.
61
+ * <p>
62
+ * When provided, it can be used in the following executions to continue paging and retrieve the remained of the
63
+ * result for the query.
64
+ * </p>
65
+ * @type {String}
66
+ * @default null
67
+ */
68
+ this.pageState = rs.pageState
69
+ }
70
+
71
+ /**
72
+ * When this instance is the result of a conditional update query, it returns whether it was successful.
73
+ * Otherwise, it returns <code>true</code>.
74
+ * <p>
75
+ * For consistency, this method always returns <code>true</code> for non-conditional queries (although there is
76
+ * no reason to call the method in that case). This is also the case for conditional DDL statements
77
+ * (CREATE KEYSPACE... IF NOT EXISTS, CREATE TABLE... IF NOT EXISTS), for which the server doesn't return
78
+ * information whether it was applied or not.
79
+ * </p>
80
+ */
81
+ wasApplied() {
82
+ return this._rs.wasApplied()
83
+ }
84
+
85
+ /**
86
+ * Gets the first document in this result or null when the result is empty.
87
+ */
88
+ first() {
89
+ if (!this._rs.rowLength || this._isEmptyLwt) {
90
+ return null
91
+ }
92
+ return this._rowAdapter(this._rs.rows[0], this._info)
93
+ }
94
+
95
+ /**
96
+ * Returns a new Iterator object that contains the document values.
97
+ */
98
+ *[Symbol.iterator]() {
99
+ if (this._isEmptyLwt) {
100
+ // Empty iterator
101
+ return
102
+ }
103
+
104
+ for (let i = 0; i < this._rs.rows.length; i++) {
105
+ yield this._rowAdapter(this._rs.rows[i], this._info)
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Converts the current instance to an Array of documents.
111
+ * @return {Array<Object>}
112
+ */
113
+ toArray() {
114
+ if (this._isEmptyLwt || !this._rs.rows) {
115
+ return utils.emptyArray
116
+ }
117
+
118
+ return this._rs.rows.map((row) => this._rowAdapter(row, this._info))
119
+ }
120
+
121
+ /**
122
+ * Executes a provided function once per result element.
123
+ * @param {Function} callback Function to execute for each element, taking two arguments: currentValue and index.
124
+ * @param {Object} [thisArg] Value to use as <code>this</code> when executing callback.
125
+ */
126
+ forEach(callback, thisArg) {
127
+ let index = 0
128
+ thisArg = thisArg || this
129
+ for (const doc of this) {
130
+ callback.call(thisArg, doc, index++)
131
+ }
132
+ }
133
+
134
+ [inspectMethod]() {
135
+ return this.toArray()
136
+ }
137
+ }
138
+
139
+ export default Result
@@ -0,0 +1,133 @@
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
+ /**
20
+ * Contains a set of methods to represent a row into a document and a document into a row.
21
+ * @alias module:mapping~TableMappings
22
+ * @interface
23
+ */
24
+ class TableMappings {
25
+ /**
26
+ * Method that is called by the mapper to create the instance of the document.
27
+ * @return {Object}
28
+ */
29
+ newObjectInstance() {
30
+ return {}
31
+ }
32
+
33
+ /**
34
+ * Gets the name of the column based on the document property name.
35
+ * @param {String} propName The name of the property.
36
+ * @returns {String}
37
+ */
38
+ getColumnName(propName) {
39
+ return propName
40
+ }
41
+
42
+ /**
43
+ * Gets the name of the document property based on the column name.
44
+ * @param {String} columnName The name of the column.
45
+ * @returns {String}
46
+ */
47
+ getPropertyName(columnName) {
48
+ return columnName
49
+ }
50
+ }
51
+
52
+ /**
53
+ * A [TableMappings]{@link module:mapping~TableMappings} implementation that converts CQL column names in all-lowercase
54
+ * identifiers with underscores (snake case) to camel case (initial lowercase letter) property names.
55
+ * <p>
56
+ * The conversion is performed without any checks for the source format, you should make sure that the source
57
+ * format is snake case for CQL identifiers and camel case for properties.
58
+ * </p>
59
+ * @alias module:mapping~UnderscoreCqlToCamelCaseMappings
60
+ * @implements {module:mapping~TableMappings}
61
+ */
62
+ class UnderscoreCqlToCamelCaseMappings extends TableMappings {
63
+ /**
64
+ * Creates a new instance of {@link UnderscoreCqlToCamelCaseMappings}
65
+ */
66
+ constructor() {
67
+ super()
68
+ }
69
+
70
+ /**
71
+ * Converts a property name in camel case to snake case.
72
+ * @param {String} propName Name of the property to convert to snake case.
73
+ * @return {String}
74
+ */
75
+ getColumnName(propName) {
76
+ return propName
77
+ .replace(
78
+ /[a-z][A-Z]/g,
79
+ (match, offset) => match.charAt(0) + "_" + match.charAt(1),
80
+ )
81
+ .toLowerCase()
82
+ }
83
+
84
+ /**
85
+ * Converts a column name in snake case to camel case.
86
+ * @param {String} columnName The column name to convert to camel case.
87
+ * @return {String}
88
+ */
89
+ getPropertyName(columnName) {
90
+ return columnName.replace(/_[a-z]/g, (match, offset) =>
91
+ offset === 0 ? match : match.substr(1).toUpperCase(),
92
+ )
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Default implementation of [TableMappings]{@link module:mapping~TableMappings} that doesn't perform any conversion.
98
+ * @alias module:mapping~DefaultTableMappings
99
+ * @implements {module:mapping~TableMappings}
100
+ */
101
+ class DefaultTableMappings extends TableMappings {
102
+ /**
103
+ * Creates a new instance of {@link DefaultTableMappings}.
104
+ */
105
+ constructor() {
106
+ super()
107
+ }
108
+
109
+ /** @override */
110
+ getColumnName(propName) {
111
+ return super.getColumnName(propName)
112
+ }
113
+
114
+ /** @override */
115
+ getPropertyName(columnName) {
116
+ return super.getPropertyName(columnName)
117
+ }
118
+
119
+ /**
120
+ * Creates a new object instance, using object initializer.
121
+ */
122
+ newObjectInstance() {
123
+ return super.newObjectInstance()
124
+ }
125
+ }
126
+
127
+ export { TableMappings, UnderscoreCqlToCamelCaseMappings, DefaultTableMappings }
128
+
129
+ export default {
130
+ TableMappings,
131
+ UnderscoreCqlToCamelCaseMappings,
132
+ DefaultTableMappings,
133
+ }
@@ -0,0 +1,160 @@
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 EventEmitter from "events"
20
+
21
+ /**
22
+ * Represents a tree node where the key is composed by 1 or more strings.
23
+ * @ignore
24
+ */
25
+ class Node extends EventEmitter {
26
+ /**
27
+ * Creates a new instance of {@link Node}.
28
+ * @param {Array<String>} key
29
+ * @param {Object} value
30
+ * @param {Array} [edges]
31
+ */
32
+ constructor(key, value, edges) {
33
+ super()
34
+ this.key = key
35
+ this.value = value
36
+ this.edges = edges || []
37
+ }
38
+ }
39
+
40
+ /**
41
+ * A radix tree where each node contains a key, a value and edges.
42
+ * @ignore
43
+ */
44
+ class Tree extends Node {
45
+ constructor() {
46
+ super([], null)
47
+ this.length = 0
48
+ }
49
+
50
+ /**
51
+ * Gets the existing item in the tree or creates a new one with the value provided by valueHandler
52
+ * @param {Iterator} keyIterator
53
+ * @param {Function} valueHandler
54
+ * @return {Object}
55
+ */
56
+ getOrCreate(keyIterator, valueHandler) {
57
+ if (typeof keyIterator.next !== "function") {
58
+ keyIterator = keyIterator[Symbol.iterator]()
59
+ }
60
+ let node = this
61
+ let isMatch = false
62
+ let item = keyIterator.next()
63
+ while (true) {
64
+ let newBranch
65
+ // Check node keys at position 1 and above
66
+ for (let i = 1; i < node.key.length; i++) {
67
+ if (item.done || node.key[i] !== item.value) {
68
+ // We should branch out
69
+ newBranch = this._createBranch(
70
+ node,
71
+ i,
72
+ item.done,
73
+ valueHandler,
74
+ )
75
+ break
76
+ }
77
+ item = keyIterator.next()
78
+ }
79
+
80
+ if (item.done) {
81
+ isMatch = true
82
+ break
83
+ }
84
+
85
+ if (newBranch !== undefined) {
86
+ break
87
+ }
88
+
89
+ const edges = node.edges
90
+ let nextNode
91
+ for (let i = 0; i < edges.length; i++) {
92
+ const e = edges[i]
93
+ if (e.key[0] === item.value) {
94
+ // its a match
95
+ nextNode = e
96
+ item = keyIterator.next()
97
+ break
98
+ }
99
+ }
100
+
101
+ if (nextNode === undefined) {
102
+ // Current node is the root for a new leaf
103
+ break
104
+ } else {
105
+ node = nextNode
106
+ }
107
+ }
108
+
109
+ if (!isMatch) {
110
+ // Create using "node" as the root
111
+ const value = valueHandler()
112
+ node.edges.push(
113
+ new Node(iteratorToArray(item.value, keyIterator), value),
114
+ )
115
+ this._onItemAdded()
116
+ return value
117
+ }
118
+ if (node.value === null && node.edges.length > 0) {
119
+ node.value = valueHandler()
120
+ }
121
+ return node.value
122
+ }
123
+
124
+ _createBranch(node, index, useNewValue, valueHandler) {
125
+ const newBranch = new Node(
126
+ node.key.slice(index),
127
+ node.value,
128
+ node.edges,
129
+ )
130
+ node.key = node.key.slice(0, index)
131
+ node.edges = [newBranch]
132
+ if (useNewValue) {
133
+ // The previous node value has moved to a leaf
134
+ // The node containing the new leaf should use the new value
135
+ node.value = valueHandler()
136
+ this._onItemAdded()
137
+ } else {
138
+ // Clear the value as it was copied in the branch
139
+ node.value = null
140
+ }
141
+ return newBranch
142
+ }
143
+
144
+ _onItemAdded() {
145
+ this.length++
146
+ this.emit("add", this.length)
147
+ }
148
+ }
149
+
150
+ function iteratorToArray(value, iterator) {
151
+ const values = [value]
152
+ let item = iterator.next()
153
+ while (!item.done) {
154
+ values.push(item.value)
155
+ item = iterator.next()
156
+ }
157
+ return values
158
+ }
159
+
160
+ export default Tree
@@ -0,0 +1,79 @@
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
+ /**
20
+ * Creates a new Aggregate.
21
+ * @classdesc Describes a CQL aggregate.
22
+ * @alias module:metadata~Aggregate
23
+ * @constructor
24
+ */
25
+ function Aggregate() {
26
+ /**
27
+ * Name of the aggregate.
28
+ * @type {String}
29
+ */
30
+ this.name = null
31
+ /**
32
+ * Name of the keyspace where the aggregate is declared.
33
+ */
34
+ this.keyspaceName = null
35
+ /**
36
+ * Signature of the aggregate.
37
+ * @type {Array.<String>}
38
+ */
39
+ this.signature = null
40
+ /**
41
+ * List of the CQL aggregate argument types.
42
+ * @type {Array.<{code, info}>}
43
+ */
44
+ this.argumentTypes = null
45
+ /**
46
+ * State Function.
47
+ * @type {String}
48
+ */
49
+ this.stateFunction = null
50
+ /**
51
+ * State Type.
52
+ * @type {{code, info}}
53
+ */
54
+ this.stateType = null
55
+ /**
56
+ * Final Function.
57
+ * @type {String}
58
+ */
59
+ this.finalFunction = null
60
+ this.initConditionRaw = null
61
+ /**
62
+ * Initial state value of this aggregate.
63
+ * @type {String}
64
+ */
65
+ this.initCondition = null
66
+ /**
67
+ * Type of the return value.
68
+ * @type {{code: number, info: (Object|Array|null)}}
69
+ */
70
+ this.returnType = null
71
+ /**
72
+ * Indicates whether or not this aggregate is deterministic. This means that
73
+ * given a particular input, the aggregate will always produce the same output.
74
+ * @type {Boolean}
75
+ */
76
+ this.deterministic = null
77
+ }
78
+
79
+ export default Aggregate