Socket
Socket
Sign inDemoInstall

dse-driver

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dse-driver - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

.travis.yml

10

CHANGELOG.md
# ChangeLog - DataStax Enterprise Node.js Driver
## 1.1.0
2016-11-18
### Improvements
- [NODEJS-316] - Implement fromString() method for geotypes
- [NODEJS-317] - Support bytecode-json decoding in the DSE Driver
- [NODEJS-318] - Include graph language in the Execution Profiles
## 1.0.4

@@ -4,0 +14,0 @@

4

index.js

@@ -13,5 +13,3 @@ /**

geometry: require('./lib/geometry'),
graph: {
GraphResultSet: require('./lib/graph/result-set')
},
graph: require('./lib/graph'),
//export cassandra driver modules

@@ -18,0 +16,0 @@ Encoder: cassandra.Encoder,

@@ -17,2 +17,6 @@ /**

var policies = require('./policies');
var graphLanguageBytecode = 'bytecode-json';
var graphLanguageGroovyString = 'gremlin-groovy';
/**

@@ -58,3 +62,3 @@ * Creates a new {@link Client} instance.

this._graphOptions = utils.extend({
language: 'gremlin-groovy',
language: graphLanguageGroovyString,
source: 'g',

@@ -69,2 +73,3 @@ readTimeout: 0,

}
this._graphSONReader = new encoderExtensions.GraphSONReader();
}

@@ -203,3 +208,3 @@

* @param {Object} parameters
* @param {QueryOptions} options
* @param {GraphQueryOptions} options
* @param {Function} callback

@@ -209,2 +214,3 @@ * @private

Client.prototype._executeGraphQuery = function (query, parameters, options, callback) {
var self = this;
this.execute(query, parameters, options, function (err, result) {

@@ -214,3 +220,9 @@ if (err) {

}
callback(null, new GraphResultSet(result));
var rowParser = null;
if (options.graphLanguage === graphLanguageBytecode) {
rowParser = function graphSONRowParser(row) {
return self._graphSONReader.read(JSON.parse(row['gremlin'])['result']);
};
}
callback(null, new GraphResultSet(result, rowParser));
});

@@ -277,2 +289,3 @@ };

options = utils.extend({
graphLanguage: defaultGraphOptions.graphLanguage,
graphSource: defaultGraphOptions.graphSource,

@@ -317,5 +330,6 @@ readTimeout: defaultGraphOptions.readTimeout,

customPayload: {
'graph-language': utf8Buffer(baseOptions.language),
'graph-language': utf8Buffer(profileOptions.language || baseOptions.language),
'graph-source': utf8Buffer(profileOptions.source || baseOptions.source)
},
graphLanguage: profileOptions.language || baseOptions.language,
graphSource: profileOptions.source || baseOptions.source

@@ -322,0 +336,0 @@ };

@@ -8,3 +8,5 @@ /**

'use strict';
var cassandra = require('cassandra-driver');
var util = require('util');
var Geometry = require('./geometry/geometry');

@@ -14,2 +16,8 @@ var Point = require('./geometry/point');

var LineString = require('./geometry/line-string');
var graphModule = require('./graph/');
var Edge = graphModule.Edge;
var Path = graphModule.Path;
var Property = graphModule.Property;
var Vertex = graphModule.Vertex;
var VertexProperty = graphModule.VertexProperty;

@@ -22,2 +30,5 @@ var dseDecoders = {

var graphSONTypeKey = '@type';
var graphSONValueKey = '@value';
/**

@@ -92,3 +103,223 @@ * @param {Encoder} EncoderConstructor

/**
* GraphSON2 Reader
* @constructor
*/
function GraphSONReader() {
var deserializerConstructors = [
VertexDeserializer,
EdgeDeserializer,
VertexPropertyDeserializer,
PropertyDeserializer,
PathDeserializer,
UuidDeserializer,
InstantDeserializer,
LongDeserializer,
BigDecimalDeserializer,
BigIntegerDeserializer,
InetAddressDeserializer,
BlobDeserializer,
PointDeserializer,
LineStringDeserializer,
PolygonDeserializer
];
this._deserializers = {};
deserializerConstructors.forEach(function (C) {
var s = new C();
s.reader = this;
this._deserializers[s.key] = s;
}, this);
}
GraphSONReader.prototype.read = function (obj) {
if (obj === undefined) {
return undefined;
}
if (Array.isArray(obj)) {
return obj.map(function mapEach(item) {
return this.read(item);
}, this);
}
var type = obj[graphSONTypeKey];
if (type) {
var d = this._deserializers[type];
if (d) {
// Use type serializer
return d.deserialize(obj);
}
return obj[graphSONValueKey];
}
if (obj && typeof obj === 'object' && obj.constructor === Object) {
return this._deserializeObject(obj);
}
// Default (for boolean, number and other scalars)
return obj;
};
GraphSONReader.prototype._deserializeObject = function (obj) {
var keys = Object.keys(obj);
var result = {};
for (var i = 0; i < keys.length; i++) {
result[keys[i]] = this.read(obj[keys[i]]);
}
return result;
};
function VertexDeserializer() {
this.key = 'g:Vertex';
}
VertexDeserializer.prototype.deserialize = function (obj) {
var value = obj[graphSONValueKey];
return new Vertex(this.reader.read(value['id']), value['label'], this.reader.read(value['properties']));
};
function VertexPropertyDeserializer() {
this.key = 'g:VertexProperty';
}
VertexPropertyDeserializer.prototype.deserialize = function (obj) {
var value = obj[graphSONValueKey];
return new VertexProperty(
this.reader.read(value['id']),
value['label'],
this.reader.read(value['value']),
this.reader.read(value['properties']));
};
function PropertyDeserializer() {
this.key = 'g:Property';
}
PropertyDeserializer.prototype.deserialize = function (obj) {
var value = obj[graphSONValueKey];
return new Property(
value['key'],
this.reader.read(value['value']));
};
function EdgeDeserializer() {
this.key = 'g:Edge';
}
EdgeDeserializer.prototype.deserialize = function (obj) {
var value = obj[graphSONValueKey];
return new Edge(
this.reader.read(value['id']),
this.reader.read(value['outV']),
value['outVLabel'],
value['label'],
this.reader.read(value['inV']),
value['inVLabel'],
this.reader.read(value['properties'])
);
};
function PathDeserializer() {
this.key = 'g:Path'
}
PathDeserializer.prototype.deserialize = function (obj) {
var value = obj[graphSONValueKey];
var objects = value['objects'].map(function objectMapItem(o) {
return this.reader.read(o);
}, this);
return new Path(this.reader.read(value['labels']), objects);
};
/**
* Uses toString() instance method and fromString() static method to serialize and deserialize the value.
* @param {String} key
* @param {Function} targetType
* @constructor
* @abstract
*/
function StringBasedDeserializer(key, targetType) {
if (!key) {
throw new Error('Deserializer must provide a type key');
}
if (!targetType) {
throw new Error('Deserializer must provide a target type');
}
this.key = key;
this.targetType = targetType;
}
StringBasedDeserializer.prototype.deserialize = function (obj) {
var value = obj[graphSONValueKey];
if (typeof value !== 'string') {
value = value.toString();
}
return this.targetType.fromString(value);
};
function UuidDeserializer() {
StringBasedDeserializer.call(this, 'g:UUID', cassandra.types.Uuid);
}
util.inherits(UuidDeserializer, StringBasedDeserializer);
function LongDeserializer() {
StringBasedDeserializer.call(this, 'g:Int64', cassandra.types.Long);
}
util.inherits(LongDeserializer, StringBasedDeserializer);
function BigDecimalDeserializer() {
StringBasedDeserializer.call(this, 'gx:BigDecimal', cassandra.types.BigDecimal);
}
util.inherits(BigDecimalDeserializer, StringBasedDeserializer);
function BigIntegerDeserializer() {
StringBasedDeserializer.call(this, 'gx:BigInteger', cassandra.types.Integer);
}
util.inherits(BigIntegerDeserializer, StringBasedDeserializer);
function InetAddressDeserializer() {
StringBasedDeserializer.call(this, 'gx:InetAddress', cassandra.types.InetAddress);
}
util.inherits(InetAddressDeserializer, StringBasedDeserializer);
function InstantDeserializer() {
StringBasedDeserializer.call(this, 'gx:Instant', Date);
}
util.inherits(InstantDeserializer, StringBasedDeserializer);
InstantDeserializer.prototype.deserialize = function (obj) {
return new Date(obj[graphSONValueKey]);
};
function BlobDeserializer() {
StringBasedDeserializer.call(this, 'dse:Blob', Buffer);
}
util.inherits(BlobDeserializer, StringBasedDeserializer);
BlobDeserializer.prototype.deserialize = function (obj) {
return new Buffer(obj[graphSONValueKey], 'base64');
};
function PointDeserializer() {
StringBasedDeserializer.call(this, 'dse:Point', Point);
}
util.inherits(PointDeserializer, StringBasedDeserializer);
function LineStringDeserializer() {
StringBasedDeserializer.call(this, 'dse:LineString', LineString);
}
util.inherits(LineStringDeserializer, StringBasedDeserializer);
function PolygonDeserializer() {
StringBasedDeserializer.call(this, 'dse:Polygon', Polygon);
}
util.inherits(PolygonDeserializer, StringBasedDeserializer);
exports.GraphSONReader = GraphSONReader;
exports.register = register;

@@ -30,2 +30,7 @@ /**

* @param {Object} [options.graphOptions]
* @param {String} [options.graphOptions.language] The graph language to use for graph queries.
* <p>
* Note that this setting should normally be <code>undefined</code> or set by a utility method and it's not expected
* to be defined manually by the user.
* </p>
* @param {String} [options.graphOptions.name] The graph name to use for graph queries.

@@ -91,2 +96,3 @@ * @param {Number} [options.graphOptions.readConsistency] The consistency level to use for graph read queries.

* @type {Object}
* @property {String} language The graph language.
* @property {String} name The graph name.

@@ -98,2 +104,3 @@ * @property {String} readConsistency The consistency to use for graph write queries.

this.graphOptions = {
language: graphOptions.language,
name: graphOptions.name,

@@ -100,0 +107,0 @@ readConsistency: graphOptions.readConsistency,

@@ -77,2 +77,45 @@ /**

/**
* Creates a {@link LineString} instance from
* a <a href="https://en.wikipedia.org/wiki/Well-known_text">Well-known Text (WKT)</a>
* representation of a line.
* @param {String} textValue
* @returns {LineString}
*/
LineString.fromString = function (textValue) {
var wktRegex = /^LINESTRING ?\(([-0-9\. ,]+)\)+$/g;
var matches = wktRegex.exec(textValue);
if (!matches || matches.length !== 2) {
throw new TypeError('Invalid WKT: ' + textValue);
}
var points = LineString.parseSegments(matches[1]);
return new LineString(points);
};
/**
* Internal method that parses a series of WKT points.
* @param {String} textValue
* @returns {Array<Point>}
* @internal
* @ignore
*/
LineString.parseSegments = function (textValue) {
var points = [];
var pointParts = textValue.split(',');
for (var i = 0; i < pointParts.length; i++) {
var p = pointParts[i].trim();
if (p.length === 0) {
throw new TypeError('Invalid WKT segment: ' + textValue);
}
var xyText = p.split(' ').filter(function (element) {
return (element.trim().length > 0);
});
if (xyText.length !== 2) {
throw new TypeError('Invalid WKT segment: ' + textValue);
}
points.push(new Point(parseFloat(xyText[0]), parseFloat(xyText[1])));
}
return points;
};
/**
* Returns a <a href="https://en.wikipedia.org/wiki/Well-known_text#Well-known_binary">Well-known Binary</a> (WKB)

@@ -79,0 +122,0 @@ * representation of this instance.

@@ -28,2 +28,5 @@ /**

}
if (isNaN(x) || isNaN(y)) {
throw new TypeError('X and Y must be numbers');
}
/**

@@ -45,3 +48,3 @@ * Returns the X coordinate of this 2D point.

/**
* Creates a {@link LineString} instance from
* Creates a {@link Point} instance from
* a <a href="https://en.wikipedia.org/wiki/Well-known_text">Well-known Text (WKT)</a>

@@ -64,2 +67,18 @@ * representation of a 2D point.

/**
* Creates a {@link Point} instance from
* a <a href="https://en.wikipedia.org/wiki/Well-known_text">Well-known Text (WKT)</a>
* representation of a 2D point.
* @param {String} textValue
* @returns {Point}
*/
Point.fromString = function (textValue) {
var wktRegex = /^POINT\s?\(([-0-9\.]+) ([-0-9\.]+)\)$/g;
var matches = wktRegex.exec(textValue);
if (!matches || matches.length !== 3) {
throw new TypeError('2D Point WTK should contain 2 coordinates');
}
return new Point(parseFloat(matches[1]), parseFloat(matches[2]));
};
/**
* Returns a <a href="https://en.wikipedia.org/wiki/Well-known_text#Well-known_binary">Well-known Binary</a> (WKB)

@@ -66,0 +85,0 @@ * representation of this instance.

@@ -11,2 +11,3 @@ /**

var Point = require('./point');
var LineString = require('./line-string');
var os = require('os');

@@ -45,3 +46,3 @@

/**
* Creates a {@link LineString} instance from
* Creates a {@link Polygon} instance from
* a <a href="https://en.wikipedia.org/wiki/Well-known_text">Well-known Text (WKT)</a>

@@ -87,5 +88,43 @@ * representation of a polygon.

/**
* Creates a {@link Polygon} instance from
* a <a href="https://en.wikipedia.org/wiki/Well-known_text">Well-known Text (WKT)</a>
* representation of a shape.
* @param {String} textValue
* @returns {Polygon}
*/
Polygon.fromString = function (textValue) {
var wktRegex = /^POLYGON ?\((\(.*\))\)$/g;
var matches = wktRegex.exec(textValue);
function validateWkt(condition) {
if (condition) {
throw new TypeError('Invalid WKT: ' + textValue);
}
}
validateWkt(!matches || matches.length !== 2);
var ringsText = matches[1];
var ringsArray = [];
var ringStart = null;
for (var i = 0; i < ringsText.length; i++) {
var c = ringsText[i];
if (c === '(') {
validateWkt(ringStart !== null);
ringStart = i+1;
continue;
}
if (c === ')') {
validateWkt(ringStart === null);
ringsArray.push(ringsText.substring(ringStart, i));
ringStart = null;
continue;
}
validateWkt(ringStart === null && c !== ' ' && c !== ',');
}
return construct(ringsArray.map(LineString.parseSegments));
};
/**
* Creates a new instance of Polygon with each array item as a parameter
* @private
* @param {Array} argsArray
* @param {Array<Array<Point>>} argsArray
* @returns {Polygon}

@@ -92,0 +131,0 @@ */

@@ -8,7 +8,4 @@ /**

'use strict';
/**
* Graph module.
* @module graph
*/
/**
* Creates a new instance of <code>GraphResultSet</code>.

@@ -30,6 +27,7 @@ * @class

* @param {ResultSet} result
* @param {Function} [rowParser]
* @alias module:graph~GraphResultSet
* @constructor
*/
function GraphResultSet(result) {
Object.defineProperty(this, '_rows', { value: result.rows, enumerable: false, writable: false });
function GraphResultSet(result, rowParser) {
/**

@@ -46,2 +44,5 @@ * Information on the execution of a successful query:

this.info = result.info;
var rows = result.rows;
rowParser = rowParser || parsePlainJsonRow;
/**

@@ -51,74 +52,65 @@ * Gets the length of the result.

*/
this.length = this._rows ? this._rows.length : 0;
var length = this.length = result.rowLength;
/**
* A string token representing the current page state of query. It can be used in the following executions to
* continue paging and retrieve the remained of the result for the query.
* @name pageState
* @type String
* @memberof module:types~ResultSet#
* @default null
* @member {String}
*/
Object.defineProperty(this, 'pageState', { get: function () { return result.getPageState(); }, enumerable: true });
}
this.pageState = result.pageState;
/**
* Returns the first element of the result or null if the result is empty.
*/
GraphResultSet.prototype.first = function () {
if (!this.length) {
return null;
}
return parseRow(this._rows[0]);
};
/**
* Returns the first element of the result or null if the result is empty.
* @returns {Object}
*/
this.first = function first() {
if (!length) {
return null;
}
return rowParser(rows[0]);
};
/**
* Executes a provided function once per result element.
* @param {Function} callback Function to execute for each element, taking two arguments: currentValue and index.
* @param {Object} [thisArg] Value to use as <code>this</code> when executing callback.
*/
GraphResultSet.prototype.forEach = function (callback, thisArg) {
if (!this.length) {
return;
}
this._rows.forEach(function (row, i) {
return callback(parseRow(row), i);
}, thisArg);
};
/**
* Executes a provided function once per result element.
* @param {Function} callback Function to execute for each element, taking two arguments: currentValue and index.
* @param {Object} [thisArg] Value to use as <code>this</code> when executing callback.
*/
this.forEach = function forEach(callback, thisArg) {
if (!length) {
return;
}
rows.forEach(function (row, i) {
return callback(rowParser(row), i);
}, thisArg);
};
/**
* Results an Array of graph result elements (vertex, edge, scalar).
* @returns {Array}
*/
GraphResultSet.prototype.toArray = function () {
if (!this.length) {
return [];
}
return this._rows.map(parseRow);
};
/**
* Results an Array of graph result elements (vertex, edge, scalar).
* @returns {Array}
*/
this.toArray = function toArray() {
if (!length) {
return [];
}
return rows.map(rowParser);
};
/**
* Returns a new Iterator object that contains the values for each index in the result.
* @returns {{next: function}}
*/
GraphResultSet.prototype.values = function () {
if (!this.length) {
return ({
next: function () {
return { done: true }
/**
* Returns a new Iterator object that contains the values for each index in the result.
* @returns {{next: function}}
*/
this.values = function values() {
var index = 0;
return {
next: function() {
if (index < length) {
return { value: rowParser(rows[index++]), done: false };
}
else {
return { done: true };
}
}
});
}
var index = 0;
var rows = this._rows;
return {
next: function() {
if (index < rows.length) {
return { value: parseRow(rows[index++]), done: false };
}
else {
return { done: true };
}
}
};
};
};
}

@@ -129,3 +121,5 @@ //noinspection JSUnresolvedVariable

//noinspection JSUnresolvedVariable
GraphResultSet.prototype[Symbol.iterator] = GraphResultSet.prototype.values;
GraphResultSet.prototype[Symbol.iterator] = function getIterator() {
return this.values();
};
}

@@ -137,3 +131,3 @@

*/
function parseRow(row) {
function parsePlainJsonRow(row) {
return JSON.parse(row['gremlin'])['result'];

@@ -140,0 +134,0 @@ }

{
"name": "dse-driver",
"version": "1.0.4",
"version": "1.1.0",
"description": "DataStax Enterprise Node.js Driver",

@@ -21,3 +21,3 @@ "author": "DataStax",

"dependencies": {
"cassandra-driver": "^3.1.5"
"cassandra-driver": "^3.1.6"
},

@@ -45,2 +45,2 @@ "devDependencies": {

}
}
}

@@ -19,2 +19,4 @@ # DataStax Enterprise Node.js Driver

[![Build Status](https://travis-ci.org/datastax/nodejs-driver-dse.svg?branch=master)](https://travis-ci.org/datastax/nodejs-driver-dse)
## Documentation

@@ -259,3 +261,3 @@

[cassandra-driver]: https://github.com/datastax/nodejs-driver
[core-manual]: http://docs.datastax.com/en/latest-nodejs-driver/common/drivers/introduction/introArchOverview.html
[core-manual]: http://docs.datastax.com/en/developer/nodejs-driver/latest/
[iterable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable

@@ -265,4 +267,4 @@ [modern-graph]: http://tinkerpop.apache.org/docs/3.1.1-incubating/reference/#_the_graph_structure

[mailing-list]: https://groups.google.com/a/lists.datastax.com/forum/#!forum/nodejs-driver-user
[doc-index]: http://docs.datastax.com/en/latest-dse-nodejs-driver/
[api-docs]: http://docs.datastax.com/en/latest-dse-nodejs-driver-api
[faq]: http://docs.datastax.com/en/developer/nodejs-driver-dse/1.0/supplemental/faq/
[doc-index]: http://docs.datastax.com/en/developer/nodejs-driver-dse/latest/
[api-docs]: http://docs.datastax.com/en/latest-dse-nodejs-driver-api/
[faq]: http://docs.datastax.com/en/developer/nodejs-driver-dse/1.0/faq/

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc