Skip to content

1.0 record #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion esdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"source": "./src",
"destination": "./docs/build",
"includes": ["\\.js$"],
"excludes": ["external"],
"excludes": ["external", "internal"],
"package": "./package.json",
"title": "Neo4j Bolt Driver for Javascript",
"unexportIdentifier": true,
Expand Down
17 changes: 11 additions & 6 deletions examples/neo4j.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
padding: 0 2px;
}
</style>
<script src="../lib/browser/neo4j-web.min.js"></script>
<script src="../lib/browser/neo4j-web.js"></script>
</head>
<body>

Expand Down Expand Up @@ -131,7 +131,11 @@ <h1>Cypher Runner for New Remoting</h1>
</div>

<script>
var driver = neo4j.driver("bolt+ws://localhost");
var authToken = neo4j.v1.auth.basic("neo4j", "neo4j");
console.log(authToken);
var driver = neo4j.v1.driver("bolt://localhost", authToken, {
encrypted:true
});
var session = driver.session();

function run() {
Expand All @@ -143,13 +147,14 @@ <h1>Cypher Runner for New Remoting</h1>
onNext: function(record) {
// On receipt of RECORD
var tr = document.createElement("tr");
for(var i in record) {
record.forEach( function( value ) {
var td = document.createElement("td");
td.appendChild(document.createTextNode(record[i]));
td.appendChild(document.createTextNode(value));
tr.appendChild(td);
}
});
table.appendChild(tr);
}, onCompleted: function(metadata) {
},
onCompleted: function(metadata) {

}
});
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ gulp.task('download-tck', function() {
gulp.task('run-tck', ['download-tck', 'nodejs'], function() {
return gulp.src(featureHome + "/*").pipe(cucumber({
'steps': 'test/v1/tck/steps/*.js',
'format': 'pretty',
'format': 'summary',
'tags' : ['~@in_dev', '~@db']
}));
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"babelify": "^6.3.0",
"browserify": "^11.0.0",
"esdoc": "^0.4.0",
"esdoc-importpath-plugin": "0.0.1",
"glob": "^5.0.14",
"gulp": "^3.9.0",
"gulp-babel": "^5.2.1",
Expand Down
102 changes: 91 additions & 11 deletions src/v1/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,35 @@ import Session from './session';
import {Pool} from './internal/pool';
import {connect} from "./internal/connector";
import StreamObserver from './internal/stream-observer';
import {VERSION} from '../version';

/**
* A Driver instance is used for mananging {@link Session}s.
* @access public
*/
* A driver maintains one or more {@link Session sessions} with a remote
* Neo4j instance. Through the {@link Session sessions} you can send statements
* and retrieve results from the database.
*
* Drivers are reasonably expensive to create - you should strive to keep one
* driver instance around per Neo4j Instance you connect to.
*
* @access public
*/
class Driver {
/**
* You should not be calling this directly, instead use {@link driver}.
* @constructor
* @param {string} url
* @param {string} userAgent
* @param {Object} token
* @param {Object} config
* @access private
*/
constructor(url, userAgent, token) {
constructor(url, userAgent = 'neo4j-javascript/0.0', token = {}, config = {}) {
this._url = url;
this._userAgent = userAgent || 'neo4j-javascript/0.0';
this._userAgent = userAgent;
this._openSessions = {};
this._sessionIdGenerator = 0;
this._token = token || {};
this._token = token;
this._config = config;
this._pool = new Pool(
this._createConnection.bind(this),
this._destroyConnection.bind(this),
Expand All @@ -54,7 +65,7 @@ class Driver {
_createConnection( release ) {
let sessionId = this._sessionIdGenerator++;
let streamObserver = new _ConnectionStreamObserver(this);
let conn = connect(this._url);
let conn = connect(this._url, this._config);
conn.initialize(this._userAgent, this._token, streamObserver);
conn._id = sessionId;
conn._release = () => release(conn);
Expand Down Expand Up @@ -83,7 +94,16 @@ class Driver {
}

/**
* Create and return new session
* Acquire a session to communicate with the database. The driver maintains
* a pool of sessions, so calling this method is normally cheap because you
* will be pulling a session out of the common pool.
*
* This comes with some responsibility - make sure you always call
* {@link Session#close()} when you are done using a session, and likewise,
* make sure you don't close your session before you are done using it. Once
* it is returned to the pool, the session will be reset to a clean state and
* made available for others to use.
*
* @return {Session} new session.
*/
session() {
Expand Down Expand Up @@ -111,8 +131,9 @@ class Driver {
}

/**
* Close sessions connections
* @return
* Close all open sessions and other associated resources. You should
* make sure to use this when you are done with this driver instance.
* @return undefined
*/
close() {
for (let sessionId in this._openSessions) {
Expand Down Expand Up @@ -141,4 +162,63 @@ class _ConnectionStreamObserver extends StreamObserver {
}
}

export default Driver
let USER_AGENT = "neo4j-javascript/" + VERSION;

/**
* Construct a new Neo4j Driver. This is your main entry point for this
* library.
*
* ## Configuration
*
* This function optionally takes a configuration argument. Available configuration
* options are as follows:
*
* {
* // Enable TLS encryption. This is on by default in modern NodeJS installs,
* // but off by default in the Web Bundle and old (<=1.0.0) NodeJS installs
* // due to technical limitations on those platforms.
* encrypted: true|false,
*
* // Trust strategy to use if encryption is enabled. There is no mode to disable
* // trust other than disabling encryption altogether. The reason for
* // this is that if you don't know who you are talking to, it is easy for an
* // attacker to hijack your encrypted connection, rendering encryption pointless.
* //
* // TRUST_ON_FIRST_USE is the default for modern NodeJS deployments, and works
* // similarly to how `ssl` works - the first time we connect to a new host,
* // we remember the certificate they use. If the certificate ever changes, we
* // assume it is an attempt to hijack the connection and require manual intervention.
* // This means that by default, connections "just work" while still giving you
* // good encrypted protection.
* //
* // TRUST_SIGNED_CERTIFICATES is the classic approach to trust verification -
* // whenever we establish an encrypted connection, we ensure the host is using
* // an encryption certificate that is in, or is signed by, a certificate listed
* // as trusted. In the web bundle, this list of trusted certificates is maintained
* // by the web browser. In NodeJS, you configure the list with the next config option.
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES",
*
* // List of one or more paths to trusted encryption certificates. This only
* // works in the NodeJS bundle, and only matters if you use "TRUST_SIGNED_CERTIFICATES".
* // The certificate files should be in regular X.509 PEM format.
* // For instance, ['./trusted.pem']
* trustedCertificates: [],
*
* // Path to a file where the driver saves hosts it has seen in the past, this is
* // very similar to the ssl tool's known_hosts file. Each time we connect to a
* // new host, a hash of their certificate is stored along with the domain name and
* // port, and this is then used to verify the host certificate does not change.
* // This setting has no effect unless TRUST_ON_FIRST_USE is enabled.
* knownHosts:"~/.neo4j/known_hosts",
* }
*
* @param {string} url The URL for the Neo4j database, for instance "bolt://localhost"
* @param {Map<String,String>} authToken Authentication credentials. See {@link auth} for helpers.
* @param {Object} config Configuration object. See the configuration section above for details.
* @returns {Driver}
*/
function driver(url, authToken, config={}) {
return new Driver(url, USER_AGENT, authToken, config);
}

export {Driver, driver}
4 changes: 2 additions & 2 deletions src/v1/graph-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Relationship {
}

toString() {
let s = "(" + this.start.split('/')[1] + ")-[:" + this.type;
let s = "(" + this.start + ")-[:" + this.type;
let keys = Object.keys(this.properties);
if (keys.length > 0) {
s += " {";
Expand All @@ -83,7 +83,7 @@ class Relationship {
}
s += "}";
}
s += "]->(" + this.end.split('/')[1] + ")";
s += "]->(" + this.end + ")";
return s;
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
*/

import {int, isInt} from './integer';
import Driver from './driver';
import {VERSION} from '../version';
import {driver} from './driver';
import {Node, Relationship, UnboundRelationship, PathSegment, Path} from './graph-types'

let USER_AGENT = "neo4j-javascript/" + VERSION;

export default {
driver: (url, token) => new Driver(url, USER_AGENT, token),
driver,
int,
isInt,
auth: {
Expand Down
18 changes: 9 additions & 9 deletions src/v1/internal/buf.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class HeapBuffer extends BaseBuffer {
let copy = new HeapBuffer(length);
for (var i = 0; i < length; i++) {
copy.putUInt8( i, this.getUInt8( i + start ) );
};
}
return copy;
}
}
Expand All @@ -414,7 +414,7 @@ class HeapBuffer extends BaseBuffer {
}

/**
* Represents a view of slice of another buffer.
* Represents a view as slice of another buffer.
* @access private
*/
class SliceBuffer extends BaseBuffer {
Expand Down Expand Up @@ -486,7 +486,7 @@ class CombinedBuffer extends BaseBuffer {
} else {
return buffer.getInt8(position);
}
};
}
}

getFloat64 ( position ) {
Expand Down Expand Up @@ -561,12 +561,12 @@ try {
} catch(e) {}

/**
* Allocate a new buffer using whatever mechanism is most sensible for the
* current platform
* @access private
* @param {Integer} size
* @return new buffer
*/
* Allocate a new buffer using whatever mechanism is most sensible for the
* current platform
* @access private
* @param {Integer} size
* @return new buffer
*/
function alloc (size) {
return new _DefaultBuffer(size);
}
Expand Down
Loading