Skip to content

Commit 68cbf8b

Browse files
authored
Merge pull request #251 from lutovich/type-definitions
TypeScript declaration files
2 parents b0ccd38 + 0a52c19 commit 68cbf8b

28 files changed

+1722
-5
lines changed

gulpfile.babel.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var os = require('os');
4747
var file = require('gulp-file');
4848
var semver = require('semver');
4949
var sharedNeo4j = require('./test/internal/shared-neo4j').default;
50+
var ts = require('gulp-typescript');
5051

5152
/**
5253
* Useful to investigate resource leaks in tests. Enable to see active sockets and file handles after the 'test' task.
@@ -154,8 +155,8 @@ gulp.task('install-driver-into-sandbox', ['nodejs'], function(){
154155
.pipe(install());
155156
});
156157

157-
gulp.task('test', function(cb){
158-
runSequence('test-nodejs', 'test-browser', 'run-tck', function (err) {
158+
gulp.task('test', function (cb) {
159+
runSequence('run-ts-declaration-tests', 'test-nodejs', 'test-browser', 'run-tck', function (err) {
159160
if (err) {
160161
var exitCode = 2;
161162
console.log('[FAIL] test task failed - exiting with code ' + exitCode);
@@ -256,6 +257,29 @@ gulp.task('run-stress-tests', function () {
256257
})).on('end', logActiveNodeHandles);
257258
});
258259

260+
gulp.task('run-ts-declaration-tests', function () {
261+
var failed = false;
262+
263+
return gulp.src(['test/types/**/*', 'types/**/*'], {base: '.'})
264+
.pipe(ts({
265+
module: 'es6',
266+
target: 'es6',
267+
noImplicitAny: true,
268+
noImplicitReturns: true,
269+
strictNullChecks: true,
270+
}))
271+
.on('error', function () {
272+
failed = true;
273+
})
274+
.on('finish', function () {
275+
if (failed) {
276+
console.log('[ERROR] TypeScript declarations contain errors. Exiting...');
277+
process.exit(1);
278+
}
279+
})
280+
.pipe(gulp.dest('build/test/types'));
281+
});
282+
259283
function logActiveNodeHandles() {
260284
if (enableActiveNodeHandlesLogging) {
261285
console.log('-- Active NodeJS handles START\n', process._getActiveHandles(), '\n-- Active NodeJS handles END');

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
"stop-neo4j": "gulp stop-neo4j",
1717
"run-stress-tests": "gulp run-stress-tests",
1818
"run-tck": "gulp run-tck",
19+
"run-ts-declaration-tests": "gulp run-ts-declaration-tests",
1920
"docs": "esdoc -c esdoc.json",
2021
"versionRelease": "gulp set --version $VERSION && npm version $VERSION --no-git-tag-version"
2122
},
2223
"main": "lib/index.js",
24+
"types": "types/index.d.ts",
2325
"devDependencies": {
2426
"async": "^2.4.0",
2527
"babel-core": "^6.17.0",
@@ -47,6 +49,7 @@
4749
"gulp-jasmine-browser": "^0.2.3",
4850
"gulp-replace": "^0.5.4",
4951
"gulp-shell": "^0.4.3",
52+
"gulp-typescript": "^3.1.7",
5053
"gulp-uglify": "^1.4.2",
5154
"gulp-util": "^3.0.6",
5255
"gulp-watch": "^4.3.5",
@@ -61,6 +64,7 @@
6164
"semver": "^5.3.0",
6265
"through2": "~2.0.0",
6366
"tmp": "0.0.31",
67+
"typescript": "^2.3.4",
6468
"vinyl-buffer": "^1.0.0",
6569
"vinyl-source-stream": "^1.1.0"
6670
},

src/v1/graph-types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* limitations under the License.
1818
*/
1919

20+
import Integer from './integer';
21+
2022
/**
2123
* Class for Node Type.
2224
*/

src/v1/record.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ class Record {
4949
* Create a new record object.
5050
* @constructor
5151
* @access private
52-
* @param {Object} keys An array of field keys, in the order the fields appear
53-
* in the record
54-
* @param {Object} fields An array of field values
52+
* @param {string[]} keys An array of field keys, in the order the fields appear in the record
53+
* @param {Array} fields An array of field values
5554
* @param {Object} fieldLookup An object of fieldName -> value index, used to map
5655
* field names to values. If this is null, one will be
5756
* generated.

test/types/index.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (c) 2002-2017 "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+
20+
import neo4j from "../../types/index";
21+
import {Driver} from "../../types/v1/driver";
22+
import Integer from "../../types/v1/integer";
23+
import {Neo4jError} from "../../types/v1/error";
24+
25+
const driver1: Driver = neo4j.driver("bolt+routing://localhost");
26+
const driver2: Driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "password"));
27+
28+
const readSession = driver1.session(neo4j.session.READ);
29+
const writeSession = driver1.session(neo4j.session.WRITE);
30+
31+
const int1: Integer = neo4j.int(42);
32+
const int2: Integer = neo4j.int("42");
33+
const int3: Integer = neo4j.int(neo4j.int(42));
34+
const int4: Integer = neo4j.int({low: 1, high: 1});
35+
36+
const isInt1: boolean = neo4j.isInt({});
37+
const isInt2: boolean = neo4j.isInt(neo4j.int("42"));
38+
39+
const serviceUnavailable: string = neo4j.error.SERVICE_UNAVAILABLE;
40+
const sessionExpired: string = neo4j.error.SESSION_EXPIRED;
41+
const protocolError: string = neo4j.error.PROTOCOL_ERROR;
42+
43+
const error1: Neo4jError = new neo4j.Neo4jError("Error message");
44+
const error2: Neo4jError = new neo4j.Neo4jError("Error message", "Error code");

test/types/v1/driver.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright (c) 2002-2017 "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+
20+
import Driver, {
21+
AuthToken,
22+
Config,
23+
EncryptionLevel,
24+
READ,
25+
SessionMode,
26+
TrustStrategy,
27+
WRITE
28+
} from "../../../types/v1/driver";
29+
import {Parameters} from "../../../types/v1/statement-runner";
30+
import Session from "../../../types/v1/session";
31+
32+
const dummy: any = null;
33+
34+
const authToken: AuthToken = dummy;
35+
const scheme: string = authToken.scheme;
36+
const principal: string = authToken.principal;
37+
const credentials: string = authToken.credentials;
38+
const realm1: undefined = <undefined>authToken.realm;
39+
const realm2: string = <string>authToken.realm;
40+
const parameters1: undefined = <undefined>authToken.parameters;
41+
const parameters2: { [key: string]: any } = <{ [key: string]: any }>authToken.parameters;
42+
const parameters3: Parameters = <Parameters>authToken.parameters;
43+
44+
const encryptionLevel: EncryptionLevel = dummy;
45+
const encryptionLevelStr: string = encryptionLevel;
46+
47+
const trustStrategy: TrustStrategy = dummy;
48+
const trustStrategyStr: string = trustStrategy;
49+
50+
const config: Config = dummy;
51+
const encrypted: undefined | boolean | EncryptionLevel = config.encrypted;
52+
const trust: undefined | TrustStrategy = config.trust;
53+
const trustedCertificates: undefined | string[] = config.trustedCertificates;
54+
const knownHosts: undefined | string = config.knownHosts;
55+
const connectionPoolSize: undefined | number = config.connectionPoolSize;
56+
const maxTransactionRetryTime: undefined | number = config.maxTransactionRetryTime;
57+
58+
const sessionMode: SessionMode = dummy;
59+
const sessionModeStr: string = sessionMode;
60+
61+
const readMode1: SessionMode = READ;
62+
const readMode2: string = READ;
63+
64+
const writeMode1: SessionMode = WRITE;
65+
const writeMode2: string = WRITE;
66+
67+
const driver: Driver = dummy;
68+
69+
const session1: Session = driver.session();
70+
const session2: Session = driver.session("READ");
71+
const session3: Session = driver.session(READ);
72+
const session4: Session = driver.session("WRITE");
73+
const session5: Session = driver.session(WRITE);
74+
const session6: Session = driver.session(READ, "bookmark1");
75+
const session7: Session = driver.session(WRITE, "bookmark2");
76+
77+
session1.run("RETURN 1").then(result => {
78+
session1.close();
79+
result.records.forEach(record => {
80+
console.log(record);
81+
});
82+
});
83+
84+
const close: void = driver.close();

test/types/v1/error.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2002-2017 "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+
20+
import {Neo4jError, newError, PROTOCOL_ERROR, SERVICE_UNAVAILABLE, SESSION_EXPIRED} from "../../../types/v1/error";
21+
22+
const serviceUnavailable: string = SERVICE_UNAVAILABLE;
23+
const sessionExpired: string = SESSION_EXPIRED;
24+
const protocolError: string = PROTOCOL_ERROR;
25+
26+
const error1: Neo4jError = new Neo4jError("Message");
27+
const error2: Neo4jError = new Neo4jError("Message", "Code");
28+
29+
const error3: Neo4jError = newError("Message");
30+
const error4: Neo4jError = newError("Message", "Code");

test/types/v1/graph-types.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright (c) 2002-2017 "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+
20+
import {Node, Path, PathSegment, Relationship, UnboundRelationship} from "../../../types/v1/graph-types";
21+
import Integer, {int} from "../../../types/v1/integer";
22+
23+
const node1: Node = new Node(int(1), ["Person", "Employee"], {name: "Alice"});
24+
const node1String: string = node1.toString();
25+
const node1Id: Integer = node1.identity;
26+
const node1Labels: string[] = node1.labels;
27+
const node1Props: object = node1.properties;
28+
29+
const rel1: Relationship = new Relationship(int(1), int(2), int(3), "KNOWS", {since: 12345});
30+
const rel1String: string = rel1.toString();
31+
const rel1Id: Integer = rel1.identity;
32+
const rel1Start: Integer = rel1.start;
33+
const rel1End: Integer = rel1.end;
34+
const rel1Type: string = rel1.type;
35+
const rel1Props: object = rel1.properties;
36+
37+
const rel2: UnboundRelationship = new UnboundRelationship(int(1), "KNOWS", {since: 12345});
38+
const rel2String: string = rel2.toString();
39+
const rel3: Relationship = rel2.bind(int(1), int(2));
40+
const rel2Id: Integer = rel2.identity;
41+
const rel2Type: string = rel2.type;
42+
const rel2Props: object = rel2.properties;
43+
44+
const pathSegment1: PathSegment = new PathSegment(node1, rel1, node1);
45+
const pathSegment1Start: Node = pathSegment1.start;
46+
const pathSegment1Rel: Relationship = pathSegment1.rel;
47+
const pathSegment1End: Node = pathSegment1.end;
48+
49+
const path1: Path = new Path(node1, node1, [pathSegment1]);
50+
const path1Start: Node = path1.start;
51+
const path1End: Node = path1.end;
52+
const path1Segments: PathSegment[] = path1.segments;
53+
const path1Length: number = path1.length;

test/types/v1/index.test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright (c) 2002-2017 "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+
20+
import v1, {auth, AuthToken, Config, driver, error, session} from "../../../types/v1/index";
21+
22+
import Driver from "../../../types/v1/driver";
23+
24+
const dummy: any = null;
25+
26+
const config: Config = dummy;
27+
28+
const basicAuthToken1: AuthToken = auth.basic("neo4j", "password");
29+
const basicAuthToken2: AuthToken = auth.basic("neo4j", "password", "realm");
30+
31+
const kerberosAuthToken1: AuthToken = auth.kerberos("base64EncodedTicket");
32+
33+
const customAuthToken1: AuthToken = auth.custom("neo4j", "password", "realm", "scheme");
34+
const customAuthToken2: AuthToken = auth.custom("neo4j", "password", "realm", "scheme", {"key": "value"});
35+
36+
const basicAuthToken3: AuthToken = v1.auth.basic("neo4j", "password");
37+
const basicAuthToken4: AuthToken = v1.auth.basic("neo4j", "password", "realm");
38+
39+
const kerberosAuthToken2: AuthToken = v1.auth.kerberos("base64EncodedTicket");
40+
41+
const customAuthToken3: AuthToken = v1.auth.custom("neo4j", "password", "realm", "scheme");
42+
const customAuthToken4: AuthToken = v1.auth.custom("neo4j", "password", "realm", "scheme", {"key": "value"});
43+
44+
const driver1: Driver = driver("bolt://localhost:7687");
45+
const driver2: Driver = driver("bolt://localhost:7687", basicAuthToken1);
46+
const driver3: Driver = driver("bolt://localhost:7687", basicAuthToken1, config);
47+
48+
const driver4: Driver = v1.driver("bolt://localhost:7687");
49+
const driver5: Driver = v1.driver("bolt://localhost:7687", basicAuthToken1);
50+
const driver6: Driver = v1.driver("bolt://localhost:7687", basicAuthToken1, config);
51+
52+
const readMode1: string = session.READ;
53+
const writeMode1: string = session.WRITE;
54+
55+
const readMode2: string = v1.session.READ;
56+
const writeMode2: string = v1.session.WRITE;
57+
58+
const serviceUnavailable1: string = error.SERVICE_UNAVAILABLE;
59+
const sessionExpired1: string = error.SESSION_EXPIRED;
60+
const protocolError1: string = error.PROTOCOL_ERROR;
61+
62+
const serviceUnavailable2: string = v1.error.SERVICE_UNAVAILABLE;
63+
const sessionExpired2: string = v1.error.SESSION_EXPIRED;
64+
const protocolError2: string = v1.error.PROTOCOL_ERROR;
65+

0 commit comments

Comments
 (0)