Skip to content

Commit a050859

Browse files
committed
Merge pull request neo4j#18 from pontusmelke/versioned-api
Add version to API
2 parents 6e6162f + 51ce70f commit a050859

32 files changed

+50
-48
lines changed

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Note: This is in active development, the API is not stable. Please try it out an
77
## Include module in Node.js application
88

99
```javascript
10-
var neo4j = require('neo4j');
10+
var neo4j = require('neo4j').v1;
1111
```
1212

1313
## Include in web browser
@@ -71,37 +71,37 @@ session.run(statement.join(' '), params)
7171

7272
## Building
7373

74-
npm install
74+
npm install
7575
npm build
7676

77-
This produces browser-compatible standalone files under `lib/browser` and a Node.js module version under `lib/`.
77+
This produces browser-compatible standalone files under `lib/browser` and a Node.js module version under `lib/`.
7878
See files under `examples/` on how to use.
7979

8080
## Testing
8181

8282
./runTests.sh
8383

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

8787
### Testing on windows
88-
Running tests on windows requires PhantomJS installed and its bin folder added in windows system variable `Path`.
89-
To run the same test suite, run `.\runTest.ps1` instead in powershell with admin right.
90-
The admin right is required to start/stop Neo4j properly as a system service.
88+
Running tests on windows requires PhantomJS installed and its bin folder added in windows system variable `Path`.
89+
To run the same test suite, run `.\runTest.ps1` instead in powershell with admin right.
90+
The admin right is required to start/stop Neo4j properly as a system service.
9191
While there is no need to grab admin right if you are running tests against an existing Neo4j server using `npm test`.
9292

9393
## A note on numbers and the Integer type
94-
For this driver to fully map to the Neo4j type system handling of 64-bits Integers is needed.
95-
Javascript can saftely represent numbers between `-(2`<sup>`53`</sup>` - 1)` and `(2`<sup>`53`</sup>` - 1)`.
96-
Therefore, an Integer type is introduced.
94+
For this driver to fully map to the Neo4j type system handling of 64-bits Integers is needed.
95+
Javascript can saftely represent numbers between `-(2`<sup>`53`</sup>` - 1)` and `(2`<sup>`53`</sup>` - 1)`.
96+
Therefore, an Integer type is introduced.
9797

9898
### Write integers
99-
Number written directly e.g. `session.run("CREATE (n:Node {age: {age}})", {age: 22})` will be of type `Float` in Neo4j.
100-
To write the `age` as an integer the `neo4j.int` method should be used.
99+
Number written directly e.g. `session.run("CREATE (n:Node {age: {age}})", {age: 22})` will be of type `Float` in Neo4j.
100+
To write the `age` as an integer the `neo4j.int` method should be used.
101101
E.g. `session.run("CREATE (n:Node {age: {age}})", {age: neo4j.int(22)})`.
102102

103103
### Read integers
104-
To get the value of a from Neo4j received integer, the safeast way would be to use the `.toString()` method on
105-
an Integer object.
106-
E.g. `console.log(result.age.toString())`.
104+
To get the value of a from Neo4j received integer, the safeast way would be to use the `.toString()` method on
105+
an Integer object.
106+
E.g. `console.log(result.age.toString())`.
107107
To check if a variable is of the Integer type, the method `neo4j.isInt(variable)` can be used.

src/neo4j.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
* limitations under the License.
1818
*/
1919

20-
import {int, isInt} from './integer';
21-
import Driver from './driver';
20+
import {int, isInt} from './v1/integer';
21+
import Driver from './v1/driver';
2222

2323
let USER_AGENT = "neo4j-javascript/0.0";
2424

2525
export default {
26-
driver: (url) => new Driver( url, USER_AGENT ),
27-
int: int,
28-
isInt: isInt
26+
v1: {
27+
driver: (url) => new Driver(url, USER_AGENT),
28+
int: int,
29+
isInt: isInt
30+
}
2931
}

src/driver.js renamed to src/v1/driver.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Driver {
4949
let _driver = this;
5050
let _session = new Session( conn, () => {
5151
// On close of session, remove it from the list of open sessions
52-
delete _driver._openSessions[sessionId];
52+
delete _driver._openSessions[sessionId];
5353
});
5454

5555
this._openSessions[sessionId] = _session;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/result-summary.js renamed to src/v1/result-summary.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20-
import neo4j from './neo4j';
20+
import neo4j from './../neo4j';
2121

2222
/**
2323
* A ResultSummary instance contains structured metadata for a {Result}.
@@ -126,7 +126,7 @@ class StatementStatistics {
126126
constraintsRemoved: 0
127127
}
128128
Object.keys(statistics).forEach((index) => {
129-
let val = neo4j.isInt(statistics[index]) ? statistics[index].toInt() : statistics[index];
129+
let val = neo4j.v1.isInt(statistics[index]) ? statistics[index].toInt() : statistics[index];
130130
//To camelCase
131131
this._stats[index.replace(/(\-\w)/g, (m) => m[1].toUpperCase())] = val;
132132
});

src/result.js renamed to src/v1/result.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
19+
2020
import {ResultSummary} from './result-summary';
2121

2222
// Ensure Promise is available
File renamed without changes.

test/driver.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
20-
var neo4j = require("../lib/neo4j");
19+
20+
var neo4j = require("../lib/neo4j").v1;
2121

2222
describe('driver', function() {
2323
it('should expose sessions', function() {
@@ -31,4 +31,4 @@ describe('driver', function() {
3131
expect( session ).not.toBeNull();
3232
driver.close();
3333
});
34-
});
34+
});

test/session.test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
20-
var neo4j = require("../lib/neo4j");
19+
20+
var neo4j = require("../lib/neo4j").v1;
2121
var StatementType = require("../lib/result-summary").statementType;
2222

2323
describe('session', function() {
@@ -57,7 +57,7 @@ describe('session', function() {
5757
done();
5858
}
5959
}
60-
60+
6161
// When & Then
6262
driver.session().run( "RETURN 1.0 AS a").subscribe(new myObserver());
6363
});
@@ -102,7 +102,7 @@ describe('session', function() {
102102
var driver = neo4j.driver("bolt://localhost");
103103
// When & Then
104104
driver.session().run( "RETURN 1.0 AS a")
105-
.then(
105+
.then(
106106
function( records ) {
107107
expect( records.length ).toBe( 1 );
108108
expect( records[0]['a'] ).toBe( 1 );
@@ -142,7 +142,7 @@ describe('session', function() {
142142
expect(sum.updateStatistics.containsUpdates()).toBe(true);
143143
expect(sum.updateStatistics.nodesCreated()).toBe(1);
144144
expect(sum.statementType).toBe(StatementType.READ_WRITE);
145-
driver.close();
145+
driver.close();
146146
done();
147147
});
148148
});
@@ -162,7 +162,7 @@ describe('session', function() {
162162
expect(sum.plan.arguments.runtime).toBe('INTERPRETED');
163163
expect(sum.plan.identifiers[0]).toBe('n');
164164
expect(sum.plan.children[0].operatorType).toBe('CreateNode');
165-
driver.close();
165+
driver.close();
166166
done();
167167
});
168168
});
@@ -184,7 +184,7 @@ describe('session', function() {
184184
expect(sum.profile.children[0].operatorType).toBe('Filter');
185185
expect(sum.profile.rows).toBeGreaterThan(0);
186186
//expect(sum.profile.dbHits).toBeGreaterThan(0);
187-
driver.close();
187+
driver.close();
188188
done();
189189
});
190190
});
@@ -201,7 +201,7 @@ describe('session', function() {
201201
expect(sum.notifications[0].code).toBe("Neo.ClientNotification.Statement.CartesianProduct");
202202
expect(sum.notifications[0].title).toBe("This query builds a cartesian product between disconnected patterns.");
203203
expect(sum.notifications[0].position.column).toBeGreaterThan(0);
204-
driver.close();
204+
driver.close();
205205
done();
206206
});
207207
});

test/types.test.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
20-
var neo4j = require("../lib/neo4j");
19+
20+
var neo4j = require("../lib/neo4j").v1;
2121

2222
describe('floating point values', function() {
2323
it('should support float 1.0 ', testVal( 1 ) );
2424
it('should support float 0.0 ', testVal( 0.0 ) );
25-
it('should support pretty big float ', testVal( 3.4028235e+38 ) ); // Max 32-bit
25+
it('should support pretty big float ', testVal( 3.4028235e+38 ) ); // Max 32-bit
2626
it('should support really big float ', testVal( 1.7976931348623157e+308 ) ); // Max 64-bit
2727
it('should support pretty small float ', testVal( 1.4e-45 ) ); // Min 32-bit
2828
it('should support really small float ', testVal( 4.9e-324 ) ); // Min 64-bit
@@ -66,15 +66,15 @@ describe('node values', function() {
6666
// Given
6767
var driver = neo4j.driver("bolt://localhost");
6868
var session = driver.session();
69-
69+
7070
// When
7171
session.run("CREATE (n:User {name:'Lisa'}) RETURN n, id(n)").then(function(rs) {
7272
var node = rs[0]['n'];
7373

7474
expect( node.properties ).toEqual( { name:"Lisa" } );
7575
expect( node.labels ).toEqual( ["User"] );
7676
// expect( node.identity ).toEqual( rs[0]['id(n)'] ); // TODO
77-
driver.close();
77+
driver.close();
7878
done();
7979

8080
});
@@ -86,15 +86,15 @@ describe('relationship values', function() {
8686
// Given
8787
var driver = neo4j.driver("bolt://localhost");
8888
var session = driver.session();
89-
89+
9090
// When
9191
session.run("CREATE ()-[r:User {name:'Lisa'}]->() RETURN r, id(r)").then(function(rs) {
9292
var rel = rs[0]['r'];
9393

9494
expect( rel.properties ).toEqual( { name:"Lisa" } );
9595
expect( rel.type ).toEqual( "User" );
9696
// expect( rel.identity ).toEqual( rs[0]['id(r)'] ); // TODO
97-
driver.close();
97+
driver.close();
9898
done();
9999

100100
});
@@ -106,7 +106,7 @@ describe('path values', function() {
106106
// Given
107107
var driver = neo4j.driver("bolt://localhost");
108108
var session = driver.session();
109-
109+
110110
// When
111111
session.run("CREATE p=(:User { name:'Lisa' })<-[r:KNOWS {since:1234.0}]-() RETURN p")
112112
.then(function(rs) {
@@ -125,22 +125,22 @@ describe('path values', function() {
125125
// Which is the inverse of the relationship itself!
126126
expect( segment.relationship.properties ).toEqual( { since: 1234 } );
127127
};
128-
driver.close();
128+
driver.close();
129129
done();
130130
});
131131
});
132132
});
133133

134-
function testVal( val ) {
134+
function testVal( val ) {
135135
return function( done ) {
136136
var driver = neo4j.driver("bolt://localhost");
137137
var session = driver.session();
138138

139139
session.run("RETURN {val} as v", {val: val})
140-
.then( function( records ) {
141-
expect( records[0]['v'] ).toEqual( val );
140+
.then( function( records ) {
141+
expect( records[0]['v'] ).toEqual( val );
142142
driver.close();
143143
done();
144144
});
145145
}
146-
}
146+
}

0 commit comments

Comments
 (0)