Skip to content

Commit 3a432ca

Browse files
committed
Merge pull request neo4j#42 from neo4j/1.0-record
1.0 record
2 parents c4b33ef + 0f559ef commit 3a432ca

29 files changed

+970
-163
lines changed

esdoc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"source": "./src",
33
"destination": "./docs/build",
44
"includes": ["\\.js$"],
5-
"excludes": ["external"],
5+
"excludes": ["external", "internal"],
66
"package": "./package.json",
77
"title": "Neo4j Bolt Driver for Javascript",
88
"unexportIdentifier": true,

examples/neo4j.html

+11-6
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
padding: 0 2px;
9494
}
9595
</style>
96-
<script src="../lib/browser/neo4j-web.min.js"></script>
96+
<script src="../lib/browser/neo4j-web.js"></script>
9797
</head>
9898
<body>
9999

@@ -131,7 +131,11 @@ <h1>Cypher Runner for New Remoting</h1>
131131
</div>
132132

133133
<script>
134-
var driver = neo4j.driver("bolt+ws://localhost");
134+
var authToken = neo4j.v1.auth.basic("neo4j", "neo4j");
135+
console.log(authToken);
136+
var driver = neo4j.v1.driver("bolt://localhost", authToken, {
137+
encrypted:true
138+
});
135139
var session = driver.session();
136140

137141
function run() {
@@ -143,13 +147,14 @@ <h1>Cypher Runner for New Remoting</h1>
143147
onNext: function(record) {
144148
// On receipt of RECORD
145149
var tr = document.createElement("tr");
146-
for(var i in record) {
150+
record.forEach( function( value ) {
147151
var td = document.createElement("td");
148-
td.appendChild(document.createTextNode(record[i]));
152+
td.appendChild(document.createTextNode(value));
149153
tr.appendChild(td);
150-
}
154+
});
151155
table.appendChild(tr);
152-
}, onCompleted: function(metadata) {
156+
},
157+
onCompleted: function(metadata) {
153158

154159
}
155160
});

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ gulp.task('download-tck', function() {
204204
gulp.task('run-tck', ['download-tck', 'nodejs'], function() {
205205
return gulp.src(featureHome + "/*").pipe(cucumber({
206206
'steps': 'test/v1/tck/steps/*.js',
207-
'format': 'pretty',
207+
'format': 'summary',
208208
'tags' : ['~@in_dev', '~@db']
209209
}));
210210
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"babelify": "^6.3.0",
2222
"browserify": "^11.0.0",
2323
"esdoc": "^0.4.0",
24+
"esdoc-importpath-plugin": "0.0.1",
2425
"glob": "^5.0.14",
2526
"gulp": "^3.9.0",
2627
"gulp-babel": "^5.2.1",

src/v1/driver.js

+91-11
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,35 @@ import Session from './session';
2121
import {Pool} from './internal/pool';
2222
import {connect} from "./internal/connector";
2323
import StreamObserver from './internal/stream-observer';
24+
import {VERSION} from '../version';
2425

2526
/**
26-
* A Driver instance is used for mananging {@link Session}s.
27-
* @access public
28-
*/
27+
* A driver maintains one or more {@link Session sessions} with a remote
28+
* Neo4j instance. Through the {@link Session sessions} you can send statements
29+
* and retrieve results from the database.
30+
*
31+
* Drivers are reasonably expensive to create - you should strive to keep one
32+
* driver instance around per Neo4j Instance you connect to.
33+
*
34+
* @access public
35+
*/
2936
class Driver {
3037
/**
38+
* You should not be calling this directly, instead use {@link driver}.
3139
* @constructor
3240
* @param {string} url
3341
* @param {string} userAgent
3442
* @param {Object} token
43+
* @param {Object} config
44+
* @access private
3545
*/
36-
constructor(url, userAgent, token) {
46+
constructor(url, userAgent = 'neo4j-javascript/0.0', token = {}, config = {}) {
3747
this._url = url;
38-
this._userAgent = userAgent || 'neo4j-javascript/0.0';
48+
this._userAgent = userAgent;
3949
this._openSessions = {};
4050
this._sessionIdGenerator = 0;
41-
this._token = token || {};
51+
this._token = token;
52+
this._config = config;
4253
this._pool = new Pool(
4354
this._createConnection.bind(this),
4455
this._destroyConnection.bind(this),
@@ -54,7 +65,7 @@ class Driver {
5465
_createConnection( release ) {
5566
let sessionId = this._sessionIdGenerator++;
5667
let streamObserver = new _ConnectionStreamObserver(this);
57-
let conn = connect(this._url);
68+
let conn = connect(this._url, this._config);
5869
conn.initialize(this._userAgent, this._token, streamObserver);
5970
conn._id = sessionId;
6071
conn._release = () => release(conn);
@@ -83,7 +94,16 @@ class Driver {
8394
}
8495

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

113133
/**
114-
* Close sessions connections
115-
* @return
134+
* Close all open sessions and other associated resources. You should
135+
* make sure to use this when you are done with this driver instance.
136+
* @return undefined
116137
*/
117138
close() {
118139
for (let sessionId in this._openSessions) {
@@ -141,4 +162,63 @@ class _ConnectionStreamObserver extends StreamObserver {
141162
}
142163
}
143164

144-
export default Driver
165+
let USER_AGENT = "neo4j-javascript/" + VERSION;
166+
167+
/**
168+
* Construct a new Neo4j Driver. This is your main entry point for this
169+
* library.
170+
*
171+
* ## Configuration
172+
*
173+
* This function optionally takes a configuration argument. Available configuration
174+
* options are as follows:
175+
*
176+
* {
177+
* // Enable TLS encryption. This is on by default in modern NodeJS installs,
178+
* // but off by default in the Web Bundle and old (<=1.0.0) NodeJS installs
179+
* // due to technical limitations on those platforms.
180+
* encrypted: true|false,
181+
*
182+
* // Trust strategy to use if encryption is enabled. There is no mode to disable
183+
* // trust other than disabling encryption altogether. The reason for
184+
* // this is that if you don't know who you are talking to, it is easy for an
185+
* // attacker to hijack your encrypted connection, rendering encryption pointless.
186+
* //
187+
* // TRUST_ON_FIRST_USE is the default for modern NodeJS deployments, and works
188+
* // similarly to how `ssl` works - the first time we connect to a new host,
189+
* // we remember the certificate they use. If the certificate ever changes, we
190+
* // assume it is an attempt to hijack the connection and require manual intervention.
191+
* // This means that by default, connections "just work" while still giving you
192+
* // good encrypted protection.
193+
* //
194+
* // TRUST_SIGNED_CERTIFICATES is the classic approach to trust verification -
195+
* // whenever we establish an encrypted connection, we ensure the host is using
196+
* // an encryption certificate that is in, or is signed by, a certificate listed
197+
* // as trusted. In the web bundle, this list of trusted certificates is maintained
198+
* // by the web browser. In NodeJS, you configure the list with the next config option.
199+
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES",
200+
*
201+
* // List of one or more paths to trusted encryption certificates. This only
202+
* // works in the NodeJS bundle, and only matters if you use "TRUST_SIGNED_CERTIFICATES".
203+
* // The certificate files should be in regular X.509 PEM format.
204+
* // For instance, ['./trusted.pem']
205+
* trustedCertificates: [],
206+
*
207+
* // Path to a file where the driver saves hosts it has seen in the past, this is
208+
* // very similar to the ssl tool's known_hosts file. Each time we connect to a
209+
* // new host, a hash of their certificate is stored along with the domain name and
210+
* // port, and this is then used to verify the host certificate does not change.
211+
* // This setting has no effect unless TRUST_ON_FIRST_USE is enabled.
212+
* knownHosts:"~/.neo4j/known_hosts",
213+
* }
214+
*
215+
* @param {string} url The URL for the Neo4j database, for instance "bolt://localhost"
216+
* @param {Map<String,String>} authToken Authentication credentials. See {@link auth} for helpers.
217+
* @param {Object} config Configuration object. See the configuration section above for details.
218+
* @returns {Driver}
219+
*/
220+
function driver(url, authToken, config={}) {
221+
return new Driver(url, USER_AGENT, authToken, config);
222+
}
223+
224+
export {Driver, driver}

src/v1/graph-types.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Relationship {
7373
}
7474

7575
toString() {
76-
let s = "(" + this.start.split('/')[1] + ")-[:" + this.type;
76+
let s = "(" + this.start + ")-[:" + this.type;
7777
let keys = Object.keys(this.properties);
7878
if (keys.length > 0) {
7979
s += " {";
@@ -83,7 +83,7 @@ class Relationship {
8383
}
8484
s += "}";
8585
}
86-
s += "]->(" + this.end.split('/')[1] + ")";
86+
s += "]->(" + this.end + ")";
8787
return s;
8888
}
8989
}

src/v1/index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
*/
1919

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

25-
let USER_AGENT = "neo4j-javascript/" + VERSION;
26-
2724
export default {
28-
driver: (url, token) => new Driver(url, USER_AGENT, token),
25+
driver,
2926
int,
3027
isInt,
3128
auth: {

src/v1/internal/buf.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class HeapBuffer extends BaseBuffer {
399399
let copy = new HeapBuffer(length);
400400
for (var i = 0; i < length; i++) {
401401
copy.putUInt8( i, this.getUInt8( i + start ) );
402-
};
402+
}
403403
return copy;
404404
}
405405
}
@@ -414,7 +414,7 @@ class HeapBuffer extends BaseBuffer {
414414
}
415415

416416
/**
417-
* Represents a view of slice of another buffer.
417+
* Represents a view as slice of another buffer.
418418
* @access private
419419
*/
420420
class SliceBuffer extends BaseBuffer {
@@ -486,7 +486,7 @@ class CombinedBuffer extends BaseBuffer {
486486
} else {
487487
return buffer.getInt8(position);
488488
}
489-
};
489+
}
490490
}
491491

492492
getFloat64 ( position ) {
@@ -561,12 +561,12 @@ try {
561561
} catch(e) {}
562562

563563
/**
564-
* Allocate a new buffer using whatever mechanism is most sensible for the
565-
* current platform
566-
* @access private
567-
* @param {Integer} size
568-
* @return new buffer
569-
*/
564+
* Allocate a new buffer using whatever mechanism is most sensible for the
565+
* current platform
566+
* @access private
567+
* @param {Integer} size
568+
* @return new buffer
569+
*/
570570
function alloc (size) {
571571
return new _DefaultBuffer(size);
572572
}

0 commit comments

Comments
 (0)