Skip to content

TypeScript declaration files #251

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 18 commits into from
Jun 22, 2017
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
28 changes: 26 additions & 2 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var os = require('os');
var file = require('gulp-file');
var semver = require('semver');
var sharedNeo4j = require('./test/internal/shared-neo4j').default;
var ts = require('gulp-typescript');

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

gulp.task('test', function(cb){
runSequence('test-nodejs', 'test-browser', 'run-tck', function (err) {
gulp.task('test', function (cb) {
runSequence('run-ts-declaration-tests', 'test-nodejs', 'test-browser', 'run-tck', function (err) {
if (err) {
var exitCode = 2;
console.log('[FAIL] test task failed - exiting with code ' + exitCode);
Expand Down Expand Up @@ -256,6 +257,29 @@ gulp.task('run-stress-tests', function () {
})).on('end', logActiveNodeHandles);
});

gulp.task('run-ts-declaration-tests', function () {
var failed = false;

return gulp.src(['test/types/**/*', 'types/**/*'], {base: '.'})
.pipe(ts({
module: 'es6',
target: 'es6',
noImplicitAny: true,
noImplicitReturns: true,
strictNullChecks: true,
}))
.on('error', function () {
failed = true;
})
.on('finish', function () {
if (failed) {
console.log('[ERROR] TypeScript declarations contain errors. Exiting...');
process.exit(1);
}
})
.pipe(gulp.dest('build/test/types'));
});

function logActiveNodeHandles() {
if (enableActiveNodeHandlesLogging) {
console.log('-- Active NodeJS handles START\n', process._getActiveHandles(), '\n-- Active NodeJS handles END');
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
"stop-neo4j": "gulp stop-neo4j",
"run-stress-tests": "gulp run-stress-tests",
"run-tck": "gulp run-tck",
"run-ts-declaration-tests": "gulp run-ts-declaration-tests",
"docs": "esdoc -c esdoc.json",
"versionRelease": "gulp set --version $VERSION && npm version $VERSION --no-git-tag-version"
},
"main": "lib/index.js",
"types": "types/index.d.ts",
"devDependencies": {
"async": "^2.4.0",
"babel-core": "^6.17.0",
Expand Down Expand Up @@ -47,6 +49,7 @@
"gulp-jasmine-browser": "^0.2.3",
"gulp-replace": "^0.5.4",
"gulp-shell": "^0.4.3",
"gulp-typescript": "^3.1.7",
"gulp-uglify": "^1.4.2",
"gulp-util": "^3.0.6",
"gulp-watch": "^4.3.5",
Expand All @@ -61,6 +64,7 @@
"semver": "^5.3.0",
"through2": "~2.0.0",
"tmp": "0.0.31",
"typescript": "^2.3.4",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
Expand Down
2 changes: 2 additions & 0 deletions src/v1/graph-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* limitations under the License.
*/

import Integer from './integer';

/**
* Class for Node Type.
*/
Expand Down
5 changes: 2 additions & 3 deletions src/v1/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ class Record {
* Create a new record object.
* @constructor
* @access private
* @param {Object} keys An array of field keys, in the order the fields appear
* in the record
* @param {Object} fields An array of field values
* @param {string[]} keys An array of field keys, in the order the fields appear in the record
* @param {Array} fields An array of field values
* @param {Object} fieldLookup An object of fieldName -> value index, used to map
* field names to values. If this is null, one will be
* generated.
Expand Down
44 changes: 44 additions & 0 deletions test/types/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import neo4j from "../../types/index";
import {Driver} from "../../types/v1/driver";
import Integer from "../../types/v1/integer";
import {Neo4jError} from "../../types/v1/error";

const driver1: Driver = neo4j.driver("bolt+routing://localhost");
const driver2: Driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "password"));

const readSession = driver1.session(neo4j.session.READ);
const writeSession = driver1.session(neo4j.session.WRITE);

const int1: Integer = neo4j.int(42);
const int2: Integer = neo4j.int("42");
const int3: Integer = neo4j.int(neo4j.int(42));
const int4: Integer = neo4j.int({low: 1, high: 1});

const isInt1: boolean = neo4j.isInt({});
const isInt2: boolean = neo4j.isInt(neo4j.int("42"));

const serviceUnavailable: string = neo4j.error.SERVICE_UNAVAILABLE;
const sessionExpired: string = neo4j.error.SESSION_EXPIRED;
const protocolError: string = neo4j.error.PROTOCOL_ERROR;

const error1: Neo4jError = new neo4j.Neo4jError("Error message");
const error2: Neo4jError = new neo4j.Neo4jError("Error message", "Error code");
84 changes: 84 additions & 0 deletions test/types/v1/driver.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import Driver, {
AuthToken,
Config,
EncryptionLevel,
READ,
SessionMode,
TrustStrategy,
WRITE
} from "../../../types/v1/driver";
import {Parameters} from "../../../types/v1/statement-runner";
import Session from "../../../types/v1/session";

const dummy: any = null;

const authToken: AuthToken = dummy;
const scheme: string = authToken.scheme;
const principal: string = authToken.principal;
const credentials: string = authToken.credentials;
const realm1: undefined = <undefined>authToken.realm;
const realm2: string = <string>authToken.realm;
const parameters1: undefined = <undefined>authToken.parameters;
const parameters2: { [key: string]: any } = <{ [key: string]: any }>authToken.parameters;
const parameters3: Parameters = <Parameters>authToken.parameters;

const encryptionLevel: EncryptionLevel = dummy;
const encryptionLevelStr: string = encryptionLevel;

const trustStrategy: TrustStrategy = dummy;
const trustStrategyStr: string = trustStrategy;

const config: Config = dummy;
const encrypted: undefined | boolean | EncryptionLevel = config.encrypted;
const trust: undefined | TrustStrategy = config.trust;
const trustedCertificates: undefined | string[] = config.trustedCertificates;
const knownHosts: undefined | string = config.knownHosts;
const connectionPoolSize: undefined | number = config.connectionPoolSize;
const maxTransactionRetryTime: undefined | number = config.maxTransactionRetryTime;

const sessionMode: SessionMode = dummy;
const sessionModeStr: string = sessionMode;

const readMode1: SessionMode = READ;
const readMode2: string = READ;

const writeMode1: SessionMode = WRITE;
const writeMode2: string = WRITE;

const driver: Driver = dummy;

const session1: Session = driver.session();
const session2: Session = driver.session("READ");
const session3: Session = driver.session(READ);
const session4: Session = driver.session("WRITE");
const session5: Session = driver.session(WRITE);
const session6: Session = driver.session(READ, "bookmark1");
const session7: Session = driver.session(WRITE, "bookmark2");

session1.run("RETURN 1").then(result => {
session1.close();
result.records.forEach(record => {
console.log(record);
});
});

const close: void = driver.close();
30 changes: 30 additions & 0 deletions test/types/v1/error.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {Neo4jError, newError, PROTOCOL_ERROR, SERVICE_UNAVAILABLE, SESSION_EXPIRED} from "../../../types/v1/error";

const serviceUnavailable: string = SERVICE_UNAVAILABLE;
const sessionExpired: string = SESSION_EXPIRED;
const protocolError: string = PROTOCOL_ERROR;

const error1: Neo4jError = new Neo4jError("Message");
const error2: Neo4jError = new Neo4jError("Message", "Code");

const error3: Neo4jError = newError("Message");
const error4: Neo4jError = newError("Message", "Code");
53 changes: 53 additions & 0 deletions test/types/v1/graph-types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {Node, Path, PathSegment, Relationship, UnboundRelationship} from "../../../types/v1/graph-types";
import Integer, {int} from "../../../types/v1/integer";

const node1: Node = new Node(int(1), ["Person", "Employee"], {name: "Alice"});
const node1String: string = node1.toString();
const node1Id: Integer = node1.identity;
const node1Labels: string[] = node1.labels;
const node1Props: object = node1.properties;

const rel1: Relationship = new Relationship(int(1), int(2), int(3), "KNOWS", {since: 12345});
const rel1String: string = rel1.toString();
const rel1Id: Integer = rel1.identity;
const rel1Start: Integer = rel1.start;
const rel1End: Integer = rel1.end;
const rel1Type: string = rel1.type;
const rel1Props: object = rel1.properties;

const rel2: UnboundRelationship = new UnboundRelationship(int(1), "KNOWS", {since: 12345});
const rel2String: string = rel2.toString();
const rel3: Relationship = rel2.bind(int(1), int(2));
const rel2Id: Integer = rel2.identity;
const rel2Type: string = rel2.type;
const rel2Props: object = rel2.properties;

const pathSegment1: PathSegment = new PathSegment(node1, rel1, node1);
const pathSegment1Start: Node = pathSegment1.start;
const pathSegment1Rel: Relationship = pathSegment1.rel;
const pathSegment1End: Node = pathSegment1.end;

const path1: Path = new Path(node1, node1, [pathSegment1]);
const path1Start: Node = path1.start;
const path1End: Node = path1.end;
const path1Segments: PathSegment[] = path1.segments;
const path1Length: number = path1.length;
65 changes: 65 additions & 0 deletions test/types/v1/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import v1, {auth, AuthToken, Config, driver, error, session} from "../../../types/v1/index";

import Driver from "../../../types/v1/driver";

const dummy: any = null;

const config: Config = dummy;

const basicAuthToken1: AuthToken = auth.basic("neo4j", "password");
const basicAuthToken2: AuthToken = auth.basic("neo4j", "password", "realm");

const kerberosAuthToken1: AuthToken = auth.kerberos("base64EncodedTicket");

const customAuthToken1: AuthToken = auth.custom("neo4j", "password", "realm", "scheme");
const customAuthToken2: AuthToken = auth.custom("neo4j", "password", "realm", "scheme", {"key": "value"});

const basicAuthToken3: AuthToken = v1.auth.basic("neo4j", "password");
const basicAuthToken4: AuthToken = v1.auth.basic("neo4j", "password", "realm");

const kerberosAuthToken2: AuthToken = v1.auth.kerberos("base64EncodedTicket");

const customAuthToken3: AuthToken = v1.auth.custom("neo4j", "password", "realm", "scheme");
const customAuthToken4: AuthToken = v1.auth.custom("neo4j", "password", "realm", "scheme", {"key": "value"});

const driver1: Driver = driver("bolt://localhost:7687");
const driver2: Driver = driver("bolt://localhost:7687", basicAuthToken1);
const driver3: Driver = driver("bolt://localhost:7687", basicAuthToken1, config);

const driver4: Driver = v1.driver("bolt://localhost:7687");
const driver5: Driver = v1.driver("bolt://localhost:7687", basicAuthToken1);
const driver6: Driver = v1.driver("bolt://localhost:7687", basicAuthToken1, config);

const readMode1: string = session.READ;
const writeMode1: string = session.WRITE;

const readMode2: string = v1.session.READ;
const writeMode2: string = v1.session.WRITE;

const serviceUnavailable1: string = error.SERVICE_UNAVAILABLE;
const sessionExpired1: string = error.SESSION_EXPIRED;
const protocolError1: string = error.PROTOCOL_ERROR;

const serviceUnavailable2: string = v1.error.SERVICE_UNAVAILABLE;
const sessionExpired2: string = v1.error.SESSION_EXPIRED;
const protocolError2: string = v1.error.PROTOCOL_ERROR;

Loading