Skip to content

Commit 600e5cf

Browse files
committed
Add documentation generation
- Update README.md - Add README.md for docs - Refactor for better structure
1 parent ce581e4 commit 600e5cf

20 files changed

+766
-175
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ pids
77
.lock-wscript
88
build
99
node_modules
10-
.idea
10+
.idea
11+
docs/build

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Neo4j Bolt Driver for JavaScript
1+
# Neo4j Bolt Driver for Javascript
22

33
An alpha-level database driver for a new Neo4j remoting protocol.
44

55
Note: This is in active development, the API is not stable. Please try it out and give us feedback, but expect things to break in the medium term!
66

7-
## Add module to Nodejs application
7+
## Add module to Node.js application
88

99
```javascript
1010
var neo4j = require('build/node/neo4j');
@@ -17,7 +17,7 @@ A global object `neo4j` will be available.
1717
<script src="build/browser/neo4j-web.min.js"></script>
1818
```
1919

20-
## Usage examples (works both in nodejs and browser environments)
20+
## Usage examples (for both Node.js and browser environments)
2121

2222
```javascript
2323
var statement = ['MERGE (alice:Person {name:{name_a},age:{age_a}})',
@@ -83,4 +83,4 @@ See files under `examples/` on how to use.
8383
./runTests.sh
8484

8585
This runs the test suite against a fresh download of Neo4j.
86-
Or `gulp test` if you already have a running version of a compatible Neo4j server running.
86+
Or `gulp test` if you already have a running version of a compatible Neo4j server.

docs/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Documentation for Neo4j Bolt Driver for Javascript
2+
The docs are generated with [esdoc](https://github.com/esdoc/esdoc), which is added
3+
as a devDependency to this project.
4+
5+
## Generate docs
6+
Execute in project root.
7+
8+
```
9+
npm install
10+
npm run docs
11+
```
12+
13+
## Read docs
14+
Point your web browser to `docs/build/index.html`.

esdoc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"source": "./lib",
3+
"destination": "./docs/build",
4+
"includes": ["\\.js$"],
5+
"excludes": ["external"],
6+
"package": "./package.json",
7+
"title": "Neo4j Bolt Driver for Javascript",
8+
"unexportIdentifier": true,
9+
"undocumentIdentifier": false,
10+
"access": ["public", "protected"]
11+
}

lib/driver.js

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,67 @@
1+
/**
2+
* Copyright (c) 2002-2015 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
120
import Session from './session';
221
import {connect} from "./internal/connector";
322

23+
/**
24+
* A Driver instance is used for mananging {@link Session}s.
25+
* @access public
26+
*/
427
class Driver {
28+
/**
29+
* @constructor
30+
* @param {string} url
31+
* @param {string} userAgent
32+
*/
533
constructor(url, userAgent) {
634
this._url = url;
7-
this.userAgent = userAgent || 'neo4j-javascript/0.0';
35+
this._userAgent = userAgent || 'neo4j-javascript/0.0';
836
this._openSessions = {};
937
this._sessionIdGenerator = 0;
1038
}
1139

40+
/**
41+
* Create and return new session
42+
* @return {Session} new session.
43+
*/
1244
session() {
13-
var sessionId = this._sessionIdGenerator++,
14-
conn = connect(this._url);
15-
conn.initialize(this.userAgent);
45+
let sessionId = this._sessionIdGenerator++;
46+
let conn = connect(this._url);
47+
conn.initialize(this._userAgent);
1648

17-
var driver = this;
18-
var session = new Session( conn, () => {
49+
let _driver = this;
50+
let _session = new Session( conn, () => {
1951
// On close of session, remove it from the list of open sessions
20-
delete driver._openSessions[sessionId];
52+
delete _driver._openSessions[sessionId];
2153
});
2254

23-
this._openSessions[sessionId] = session;
24-
return session;
55+
this._openSessions[sessionId] = _session;
56+
return _session;
2557
}
2658

59+
/**
60+
* Close sessions connections
61+
* @return
62+
*/
2763
close() {
28-
for (var sessionId in this._openSessions) {
64+
for (let sessionId in this._openSessions) {
2965
if (this._openSessions.hasOwnProperty(sessionId)) {
3066
this._openSessions[sessionId].close();
3167
}

lib/graph-types.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
1+
/**
2+
* Copyright (c) 2002-2015 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
119

20+
/**
21+
* Class for Node Type.
22+
*/
223
class Node {
24+
/**
25+
* @constructor
26+
* @param {string} identity - Unique identity
27+
* @param {Array} labels - Array for all labels
28+
* @param {Object} properties - Map with node properties
29+
*/
330
constructor(identity, labels, properties) {
431
this.identity = identity;
532
this.labels = labels;
@@ -25,7 +52,18 @@ class Node {
2552
}
2653
}
2754

55+
/**
56+
* Class for Relationship Type.
57+
*/
2858
class Relationship {
59+
/**
60+
* @constructor
61+
* @param {string} identity - Unique identity
62+
* @param {string} start - Identity of start Node
63+
* @param {string} end - Identity of end Node
64+
* @param {string} type - Relationship type
65+
* @param {Object} properties - Map with relationship properties
66+
*/
2967
constructor(identity, start, end, type, properties) {
3068
this.identity = identity;
3169
this.start = start;
@@ -50,15 +88,78 @@ class Relationship {
5088
}
5189
}
5290

91+
/**
92+
* Class for UnboundRelationship Type.
93+
*/
94+
class UnboundRelationship {
95+
/**
96+
* @constructor
97+
* @param {string} identity - Unique identity
98+
* @param {string} type - Relationship type
99+
* @param {Object} properties - Map with relationship properties
100+
*/
101+
constructor(identity, type, properties) {
102+
this.identity = identity;
103+
this.type = type;
104+
this.properties = properties;
105+
}
106+
107+
/**
108+
* Bind relationship
109+
* @param {string} start - Indentity of start node
110+
* @param {string} end - Indentity of end node
111+
* @return {Relationship} - Created relationship
112+
*/
113+
bind( start, end ) {
114+
return new Relationship(
115+
this.identity,
116+
start,
117+
end,
118+
this.type,
119+
this.properties);
120+
}
121+
122+
toString() {
123+
let s = "-[:" + this.type;
124+
let keys = Object.keys(this.properties);
125+
if (keys.length > 0) {
126+
s += " {";
127+
for(let i = 0; i < keys.length; i++) {
128+
if (i > 0) s += ",";
129+
s += keys[i] + ":" + JSON.stringify(this.properties[keys[i]]);
130+
}
131+
s += "}";
132+
}
133+
s += "]->";
134+
return s;
135+
}
136+
}
137+
138+
/**
139+
* Class for PathSegment Type.
140+
*/
53141
class PathSegment {
142+
/**
143+
* @constructor
144+
* @param {string} start - Identity of start Node
145+
* @param {Relationship} rel - Relationship segment
146+
* @param {string} end - Identity of end Node
147+
*/
54148
constructor( start, rel, end ) {
55149
this.start = start;
56150
this.relationship = rel;
57151
this.end = end;
58152
}
59153
}
60154

155+
/**
156+
* Class for Path Type.
157+
*/
61158
class Path {
159+
/**
160+
* @constructor
161+
* @param {Array} segments - Array of Segments
162+
*/
62163
constructor(segments) {
63164
this.segments = segments;
64165
this.start = segments[0].start;
@@ -70,6 +171,7 @@ class Path {
70171
export default {
71172
Node,
72173
Relationship,
174+
UnboundRelationship,
73175
Path,
74176
PathSegment
75177
}

0 commit comments

Comments
 (0)