Node JS version

This commit is contained in:
Aravind142857
2023-06-09 20:08:47 -05:00
parent 8983f0dd80
commit a8b8883b11
894 changed files with 152408 additions and 73 deletions

View File

@@ -0,0 +1,78 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
/**
* Creates a new Aggregate.
* @classdesc Describes a CQL aggregate.
* @alias module:metadata~Aggregate
* @constructor
*/
function Aggregate() {
/**
* Name of the aggregate.
* @type {String}
*/
this.name = null;
/**
* Name of the keyspace where the aggregate is declared.
*/
this.keyspaceName = null;
/**
* Signature of the aggregate.
* @type {Array.<String>}
*/
this.signature = null;
/**
* List of the CQL aggregate argument types.
* @type {Array.<{code, info}>}
*/
this.argumentTypes = null;
/**
* State Function.
* @type {String}
*/
this.stateFunction = null;
/**
* State Type.
* @type {{code, info}}
*/
this.stateType = null;
/**
* Final Function.
* @type {String}
*/
this.finalFunction = null;
this.initConditionRaw = null;
/**
* Initial state value of this aggregate.
* @type {String}
*/
this.initCondition = null;
/**
* Type of the return value.
* @type {{code: number, info: (Object|Array|null)}}
*/
this.returnType = null;
/**
* Indicates whether or not this aggregate is deterministic. This means that
* given a particular input, the aggregate will always produce the same output.
* @type {Boolean}
*/
this.deterministic = null;
}
module.exports = Aggregate;

View File

@@ -0,0 +1,114 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const util = require('util');
const errors = require('../errors');
/**
* Represents the state of a {@link Client}.
* <p>
* Exposes information on the connections maintained by a Client at a specific time.
* </p>
* @alias module:metadata~ClientState
* @constructor
*/
class ClientState {
/**
* Creates a new instance of <code>ClientState</code>.
* @param {Array<Host>} hosts
* @param {Object.<String, Number>} openConnections
* @param {Object.<String, Number>} inFlightQueries
*/
constructor(hosts, openConnections, inFlightQueries) {
this._hosts = hosts;
this._openConnections = openConnections;
this._inFlightQueries = inFlightQueries;
}
/**
* Get an array of hosts to which the client is connected to.
* @return {Array<Host>}
*/
getConnectedHosts() {
return this._hosts;
}
/**
* Gets the amount of open connections to a given host.
* @param {Host} host
* @return {Number}
*/
getOpenConnections(host) {
if (!host) {
throw new errors.ArgumentError('Host is not defined');
}
return this._openConnections[host.address] || 0;
}
/**
* Gets the amount of queries that are currently being executed through a given host.
* <p>
* This corresponds to the number of queries that have been sent by the Client to server Host on one of its connections
* but haven't yet obtained a response.
* </p>
* @param {Host} host
* @return {Number}
*/
getInFlightQueries(host) {
if (!host) {
throw new errors.ArgumentError('Host is not defined');
}
return this._inFlightQueries[host.address] || 0;
}
/**
* Returns the string representation of the instance.
*/
toString() {
return util.format('{"hosts": %j, "openConnections": %j, "inFlightQueries": %j}',
this._hosts.map(function (h) { return h.address; }), this._openConnections, this._inFlightQueries);
}
/**
* Creates a new instance from the provided client.
* @param {Client} client
* @internal
* @ignore
*/
static from(client) {
const openConnections = {};
const inFlightQueries = {};
const hostArray = [];
client.hosts.forEach(host => {
if (host.pool.connections.length === 0) {
return;
}
hostArray.push(host);
openConnections[host.address] = host.pool.connections.length;
inFlightQueries[host.address] = host.getInFlight();
});
return new ClientState(hostArray, openConnections, inFlightQueries);
}
}
module.exports = ClientState;

View File

@@ -0,0 +1,173 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const util = require('util');
const events = require('events');
/**
* Creates a new instance of DataCollection
* @param {String} name Name of the data object.
* @classdesc Describes a table or a view
* @alias module:metadata~DataCollection
* @constructor
* @abstract
*/
function DataCollection(name) {
events.EventEmitter.call(this);
this.setMaxListeners(0);
//private
Object.defineProperty(this, 'loading', { value: false, enumerable: false, writable: true });
Object.defineProperty(this, 'loaded', { value: false, enumerable: false, writable: true });
/**
* Name of the object
* @type {String}
*/
this.name = name;
/**
* False-positive probability for SSTable Bloom filters.
* @type {number}
*/
this.bloomFilterFalsePositiveChance = 0;
/**
* Level of caching: all, keys_only, rows_only, none
* @type {String}
*/
this.caching = null;
/**
* A human readable comment describing the table.
* @type {String}
*/
this.comment = null;
/**
* Specifies the time to wait before garbage collecting tombstones (deletion markers)
* @type {number}
*/
this.gcGraceSeconds = 0;
/**
* Compaction strategy class used for the table.
* @type {String}
*/
this.compactionClass = null;
/**
* Associative-array containing the compaction options keys and values.
* @type {Object}
*/
this.compactionOptions = null;
/**
* Associative-array containing the compression options.
* @type {Object}
*/
this.compression = null;
/**
* Specifies the probability of read repairs being invoked over all replicas in the current data center.
* @type {number}
*/
this.localReadRepairChance = 0;
/**
* Specifies the probability with which read repairs should be invoked on non-quorum reads. The value must be
* between 0 and 1.
* @type {number}
*/
this.readRepairChance = 0;
/**
* An associative Array containing extra metadata for the table.
* <p>
* For Apache Cassandra versions prior to 3.0.0, this method always returns <code>null</code>.
* </p>
* @type {Object}
*/
this.extensions = null;
/**
* When compression is enabled, this option defines the probability
* with which checksums for compressed blocks are checked during reads.
* The default value for this options is 1.0 (always check).
* <p>
* For Apache Cassandra versions prior to 3.0.0, this method always returns <code>null</code>.
* </p>
* @type {Number|null}
*/
this.crcCheckChance = null;
/**
* Whether the populate I/O cache on flush is set on this table.
* @type {Boolean}
*/
this.populateCacheOnFlush = false;
/**
* Returns the default TTL for this table.
* @type {Number}
*/
this.defaultTtl = 0;
/**
* * Returns the speculative retry option for this table.
* @type {String}
*/
this.speculativeRetry = 'NONE';
/**
* Returns the minimum index interval option for this table.
* <p>
* Note: this option is available in Apache Cassandra 2.1 and above, and will return <code>null</code> for
* earlier versions.
* </p>
* @type {Number|null}
*/
this.minIndexInterval = 128;
/**
* Returns the maximum index interval option for this table.
* <p>
* Note: this option is available in Apache Cassandra 2.1 and above, and will return <code>null</code> for
* earlier versions.
* </p>
* @type {Number|null}
*/
this.maxIndexInterval = 2048;
/**
* Array describing the table columns.
* @type {Array}
*/
this.columns = null;
/**
* An associative Array of columns by name.
* @type {Object}
*/
this.columnsByName = null;
/**
* Array describing the columns that are part of the partition key.
* @type {Array}
*/
this.partitionKeys = [];
/**
* Array describing the columns that form the clustering key.
* @type {Array}
*/
this.clusteringKeys = [];
/**
* Array describing the clustering order of the columns in the same order as the clusteringKeys.
* @type {Array}
*/
this.clusteringOrder = [];
/**
* An associative Array containing nodesync options for this table.
* <p>
* For DSE versions prior to 6.0.0, this method always returns {@code null}. If nodesync
* was not explicitly configured for this table this method will also return {@code null}.
* </p>
* @type {Object}
*/
this.nodesync = null;
}
util.inherits(DataCollection, events.EventEmitter);
module.exports = DataCollection;

View File

@@ -0,0 +1,164 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const util = require('util');
const utils = require('../utils');
const promiseUtils = require('../promise-utils');
const _queueOverflowThreshold = 1000;
/**
* Debounce protocol events by acting on those events with a sliding delay.
* @ignore
* @constructor
*/
class EventDebouncer {
/**
* Creates a new instance of the event debouncer.
* @param {Number} delay
* @param {Function} logger
*/
constructor(delay, logger) {
this._delay = delay;
this._logger = logger;
this._queue = null;
this._timeout = null;
}
/**
* Adds a new event to the queue and moves the delay.
* @param {{ handler: Function, all: boolean|undefined, keyspace: String|undefined,
* cqlObject: String|null|undefined }} event
* @param {Boolean} processNow
* @returns {Promise}
*/
eventReceived(event, processNow) {
return new Promise((resolve, reject) => {
event.callback = promiseUtils.getCallback(resolve, reject);
this._queue = this._queue || { callbacks: [], keyspaces: {} };
const delay = !processNow ? this._delay : 0;
if (event.all) {
// when an event marked with all is received, it supersedes all the rest of events
// a full update (hosts + keyspaces + tokens) is going to be made
this._queue.mainEvent = event;
}
if (this._queue.callbacks.length === _queueOverflowThreshold) {
// warn once
this._logger('warn', util.format('Event debouncer queue exceeded %d events', _queueOverflowThreshold));
}
this._queue.callbacks.push(event.callback);
if (this._queue.mainEvent) {
// a full refresh is scheduled and the callback was added, nothing else to do.
return this._slideDelay(delay);
}
// Insert at keyspace level
let keyspaceEvents = this._queue.keyspaces[event.keyspace];
if (!keyspaceEvents) {
keyspaceEvents = this._queue.keyspaces[event.keyspace] = { events: [] };
}
if (event.cqlObject === undefined) {
// a full refresh of the keyspace, supersedes all child keyspace events
keyspaceEvents.mainEvent = event;
}
keyspaceEvents.events.push(event);
this._slideDelay(delay);
});
}
/**
* @param {Number} delay
* @private
* */
_slideDelay(delay) {
const self = this;
function process() {
const q = self._queue;
self._queue = null;
self._timeout = null;
processQueue(q);
}
if (delay === 0) {
// no delay, process immediately
if (this._timeout) {
clearTimeout(this._timeout);
}
return process();
}
const previousTimeout = this._timeout;
// Add the new timeout before removing the previous one performs better
this._timeout = setTimeout(process, delay);
if (previousTimeout) {
clearTimeout(previousTimeout);
}
}
/**
* Clears the timeout and invokes all pending callback.
*/
shutdown() {
if (!this._queue) {
return;
}
this._queue.callbacks.forEach(function (cb) {
cb();
});
this._queue = null;
clearTimeout(this._timeout);
this._timeout = null;
}
}
/**
* @param {{callbacks: Array, keyspaces: Object, mainEvent: Object}} q
* @private
*/
function processQueue (q) {
if (q.mainEvent) {
// refresh all by invoking 1 handler and invoke all pending callbacks
return promiseUtils.toCallback(q.mainEvent.handler(), (err) => {
for (let i = 0; i < q.callbacks.length; i++) {
q.callbacks[i](err);
}
});
}
utils.each(Object.keys(q.keyspaces), function eachKeyspace(name, next) {
const keyspaceEvents = q.keyspaces[name];
if (keyspaceEvents.mainEvent) {
// refresh a keyspace
return promiseUtils.toCallback(keyspaceEvents.mainEvent.handler(), function mainEventCallback(err) {
for (let i = 0; i < keyspaceEvents.events.length; i++) {
keyspaceEvents.events[i].callback(err);
}
next();
});
}
// deal with individual handlers and callbacks
keyspaceEvents.events.forEach(event => {
// sync handlers
event.handler();
event.callback();
});
next();
});
}
module.exports = EventDebouncer;

211
node_modules/cassandra-driver/lib/metadata/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,211 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { types } from '../types';
import { EmptyCallback, Host, token, ValueCallback } from '../../';
import dataTypes = types.dataTypes;
import Uuid = types.Uuid;
import InetAddress = types.InetAddress;
export namespace metadata {
interface Aggregate {
argumentTypes: Array<{ code: dataTypes, info: any }>;
finalFunction: string;
initCondition: string;
keyspaceName: string;
returnType: string;
signature: string[];
stateFunction: string;
stateType: string;
}
interface ClientState {
getConnectedHosts(): Host[];
getInFlightQueries(host: Host): number;
getOpenConnections(host: Host): number;
toString(): string;
}
interface DataTypeInfo {
code: dataTypes;
info: string | DataTypeInfo | DataTypeInfo[];
options: {
frozen: boolean;
reversed: boolean;
};
}
interface ColumnInfo {
name: string;
type: DataTypeInfo;
}
enum IndexKind {
custom = 0,
keys,
composites
}
interface Index {
kind: IndexKind;
name: string;
options: object;
target: string;
isCompositesKind(): boolean;
isCustomKind(): boolean;
isKeysKind(): boolean;
}
interface DataCollection {
bloomFilterFalsePositiveChance: number;
caching: string;
clusteringKeys: ColumnInfo[];
clusteringOrder: string[];
columns: ColumnInfo[];
columnsByName: { [key: string]: ColumnInfo };
comment: string;
compactionClass: string;
compactionOptions: { [option: string]: any; };
compression: {
class?: string;
[option: string]: any;
};
crcCheckChange?: number;
defaultTtl: number;
extensions: { [option: string]: any; };
gcGraceSeconds: number;
localReadRepairChance: number;
maxIndexInterval?: number;
minIndexInterval?: number;
name: string;
partitionKeys: ColumnInfo[];
populateCacheOnFlush: boolean;
readRepairChance: number;
speculativeRetry: string;
}
interface MaterializedView extends DataCollection {
tableName: string;
whereClause: string;
includeAllColumns: boolean;
}
interface TableMetadata extends DataCollection {
indexes: Index[];
indexInterval?: number;
isCompact: boolean;
memtableFlushPeriod: number;
replicateOnWrite: boolean;
cdc?: boolean;
virtual: boolean;
}
interface QueryTrace {
requestType: string;
coordinator: InetAddress;
parameters: { [key: string]: any };
startedAt: number | types.Long;
duration: number;
clientAddress: string;
events: Array<{ id: Uuid; activity: any; source: any; elapsed: any; thread: any }>;
}
interface SchemaFunction {
argumentNames: string[];
argumentTypes: Array<{ code: dataTypes, info: any }>;
body: string;
calledOnNullInput: boolean;
keyspaceName: string;
language: string;
name: string;
returnType: string;
signature: string[];
}
interface Udt {
name: string;
fields: ColumnInfo[]
}
interface Metadata {
keyspaces: { [name: string]: { name: string, strategy: string }};
clearPrepared(): void;
getAggregate(keyspaceName: string, name: string, signature: string[] | Array<{ code: number, info: any }>, callback: ValueCallback<Aggregate>): void;
getAggregate(keyspaceName: string, name: string, signature: string[] | Array<{ code: number, info: any }>): Promise<Aggregate>;
getAggregates(keyspaceName: string, name: string, callback: ValueCallback<Aggregate[]>): void;
getAggregates(keyspaceName: string, name: string): Promise<Aggregate[]>;
getFunction(keyspaceName: string, name: string, signature: string[] | Array<{ code: number, info: any }>, callback: ValueCallback<SchemaFunction>): void;
getFunction(keyspaceName: string, name: string, signature: string[] | Array<{ code: number, info: any }>): Promise<SchemaFunction>;
getFunctions(keyspaceName: string, name: string, callback: ValueCallback<SchemaFunction[]>): void;
getFunctions(keyspaceName: string, name: string): Promise<SchemaFunction[]>;
getMaterializedView(keyspaceName: string, name: string, callback: ValueCallback<MaterializedView>): void;
getMaterializedView(keyspaceName: string, name: string, callback: EmptyCallback): Promise<MaterializedView>;
getReplicas(keyspaceName: string, token: Buffer | token.Token | token.TokenRange): Host[];
getTable(keyspaceName: string, name: string, callback: ValueCallback<TableMetadata>): void;
getTable(keyspaceName: string, name: string): Promise<TableMetadata>;
getTokenRanges(): Set<token.TokenRange>;
getTokenRangesForHost(keyspaceName: string, host: Host): Set<token.TokenRange> | null;
getTrace(traceId: Uuid, consistency: types.consistencies, callback: ValueCallback<QueryTrace>): void;
getTrace(traceId: Uuid, consistency: types.consistencies): Promise<QueryTrace>;
getTrace(traceId: Uuid, callback: ValueCallback<QueryTrace>): void;
getTrace(traceId: Uuid): Promise<QueryTrace>;
getUdt(keyspaceName: string, name: string, callback: ValueCallback<Udt>): void;
getUdt(keyspaceName: string, name: string): Promise<Udt>;
newToken(components: Buffer[] | Buffer | string): token.Token;
newTokenRange(start: token.Token, end: token.Token): token.TokenRange;
refreshKeyspace(name: string, callback: EmptyCallback): void;
refreshKeyspace(name: string): Promise<void>;
refreshKeyspaces(waitReconnect: boolean, callback: EmptyCallback): void;
refreshKeyspaces(waitReconnect?: boolean): Promise<void>;
refreshKeyspaces(callback: EmptyCallback): void;
}
}

1024
node_modules/cassandra-driver/lib/metadata/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const util = require('util');
const DataCollection = require('./data-collection');
/**
* Creates a new MaterializedView.
* @param {String} name Name of the View.
* @classdesc Describes a CQL materialized view.
* @alias module:metadata~MaterializedView
* @augments {module:metadata~DataCollection}
* @constructor
*/
function MaterializedView(name) {
DataCollection.call(this, name);
/**
* Name of the table.
* @type {String}
*/
this.tableName = null;
/**
* View where clause.
* @type {String}
*/
this.whereClause = null;
/**
* Determines if all the table columns where are included in the view.
* @type {boolean}
*/
this.includeAllColumns = false;
}
util.inherits(MaterializedView, DataCollection);
module.exports = MaterializedView;

View File

@@ -0,0 +1,97 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
/**
* Creates a new SchemaFunction.
* @classdesc Describes a CQL function.
* @alias module:metadata~SchemaFunction
* @constructor
*/
function SchemaFunction() {
/**
* Name of the cql function.
* @type {String}
*/
this.name = null;
/**
* Name of the keyspace where the cql function is declared.
*/
this.keyspaceName = null;
/**
* Signature of the function.
* @type {Array.<String>}
*/
this.signature = null;
/**
* List of the function argument names.
* @type {Array.<String>}
*/
this.argumentNames = null;
/**
* List of the function argument types.
* @type {Array.<{code, info}>}
*/
this.argumentTypes = null;
/**
* Body of the function.
* @type {String}
*/
this.body = null;
/**
* Determines if the function is called when the input is null.
* @type {Boolean}
*/
this.calledOnNullInput = null;
/**
* Name of the programming language, for example: java, javascript, ...
* @type {String}
*/
this.language = null;
/**
* Type of the return value.
* @type {{code: number, info: (Object|Array|null)}}
*/
this.returnType = null;
/**
* Indicates whether or not this function is deterministic. This means that
* given a particular input, the function will always produce the same output.
* @type {Boolean}
*/
this.deterministic = null;
/**
* Indicates whether or not this function is monotonic on all of its
* arguments. This means that it is either entirely non-increasing or
* non-decreasing. Even if the function is not monotonic on all of its
* arguments, it's possible to specify that it is monotonic on one of
* its arguments, meaning that partial applications of the function over
* that argument will be monotonic.
*
* Monotonicity is required to use the function in a GROUP BY clause.
* @type {Boolean}
*/
this.monotonic = null;
/**
* The argument names that the function is monotonic on.
*
* If {@link monotonic} is true, this will return all argument names.
* Otherwise, this will return either one argument or an empty array.
* @type {Array.<String>}
*/
this.monotonicOn = null;
}
module.exports = SchemaFunction;

View File

@@ -0,0 +1,149 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const util = require('util');
const utils = require('../utils');
const types = require('../types');
/** @private */
const kind = {
custom: 0,
keys: 1,
composites: 2
};
/**
* Creates a new Index instance.
* @classdesc Describes a CQL index.
* @param {String} name
* @param {String} target
* @param {Number|String} kind
* @param {Object} options
* @alias module:metadata~Index
* @constructor
*/
function Index(name, target, kind, options) {
/**
* Name of the index.
* @type {String}
*/
this.name = name;
/**
* Target of the index.
* @type {String}
*/
this.target = target;
/**
* A numeric value representing index kind (0: custom, 1: keys, 2: composite);
* @type {Number}
*/
this.kind = typeof kind === 'string' ? getKindByName(kind) : kind;
/**
* An associative array containing the index options
* @type {Object}
*/
this.options = options;
}
/**
* Determines if the index is of composites kind
* @returns {Boolean}
*/
Index.prototype.isCompositesKind = function () {
return this.kind === kind.composites;
};
/**
* Determines if the index is of keys kind
* @returns {Boolean}
*/
Index.prototype.isKeysKind = function () {
return this.kind === kind.keys;
};
/**
* Determines if the index is of custom kind
* @returns {Boolean}
*/
Index.prototype.isCustomKind = function () {
return this.kind === kind.custom;
};
/**
* Parses Index information from rows in the 'system_schema.indexes' table
* @deprecated It will be removed in the next major version.
* @param {Array.<Row>} indexRows
* @returns {Array.<Index>}
*/
Index.fromRows = function (indexRows) {
if (!indexRows || indexRows.length === 0) {
return utils.emptyArray;
}
return indexRows.map(function (row) {
const options = row['options'];
return new Index(row['index_name'], options['target'], getKindByName(row['kind']), options);
});
};
/**
* Parses Index information from rows in the legacy 'system.schema_columns' table.
* @deprecated It will be removed in the next major version.
* @param {Array.<Row>} columnRows
* @param {Object.<String, {name, type}>} columnsByName
* @returns {Array.<Index>}
*/
Index.fromColumnRows = function (columnRows, columnsByName) {
const result = [];
for (let i = 0; i < columnRows.length; i++) {
const row = columnRows[i];
const indexName = row['index_name'];
if (!indexName) {
continue;
}
const c = columnsByName[row['column_name']];
let target;
const options = JSON.parse(row['index_options']);
if (options !== null && options['index_keys'] !== undefined) {
target = util.format("keys(%s)", c.name);
}
else if (options !== null && options['index_keys_and_values'] !== undefined) {
target = util.format("entries(%s)", c.name);
}
else if (c.type.options.frozen && (c.type.code === types.dataTypes.map || c.type.code === types.dataTypes.list ||
c.type.code === types.dataTypes.set)) {
target = util.format("full(%s)", c.name);
}
else {
target = c.name;
}
result.push(new Index(indexName, target, getKindByName(row['index_type']), options));
}
return result;
};
/**
* Gets the number representing the kind based on the name
* @param {String} name
* @returns {Number}
* @private
*/
function getKindByName(name) {
if (!name) {
return kind.custom;
}
return kind[name.toLowerCase()];
}
module.exports = Index;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,77 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const util = require('util');
const DataCollection = require('./data-collection');
/**
* Creates a new instance of TableMetadata
* @classdesc Describes a table
* @param {String} name Name of the Table
* @augments {module:metadata~DataCollection}
* @alias module:metadata~TableMetadata
* @constructor
*/
function TableMetadata(name) {
DataCollection.call(this, name);
/**
* Applies only to counter tables.
* When set to true, replicates writes to all affected replicas regardless of the consistency level specified by
* the client for a write request. For counter tables, this should always be set to true.
* @type {Boolean}
*/
this.replicateOnWrite = true;
/**
* Returns the memtable flush period (in milliseconds) option for this table.
* @type {Number}
*/
this.memtableFlushPeriod = 0;
/**
* Returns the index interval option for this table.
* <p>
* Note: this option is only available in Apache Cassandra 2.0. It is deprecated in Apache Cassandra 2.1 and
* above, and will therefore return <code>null</code> for 2.1 nodes.
* </p>
* @type {Number|null}
*/
this.indexInterval = null;
/**
* Determines whether the table uses the COMPACT STORAGE option.
* @type {Boolean}
*/
this.isCompact = false;
/**
*
* @type {Array.<Index>}
*/
this.indexes = null;
/**
* Determines whether the Change Data Capture (CDC) flag is set for the table.
* @type {Boolean|null}
*/
this.cdc = null;
/**
* Determines whether the table is a virtual table or not.
* @type {Boolean}
*/
this.virtual = false;
}
util.inherits(TableMetadata, DataCollection);
module.exports = TableMetadata;