diff --git a/gulpfile.babel.js b/gulpfile.babel.js index cdf88323a..d5ac64c9d 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -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. @@ -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); @@ -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'); diff --git a/package.json b/package.json index 32b5f7dd2..e4e289d0e 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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" }, diff --git a/src/v1/graph-types.js b/src/v1/graph-types.js index 1857832e0..4a9160d4f 100644 --- a/src/v1/graph-types.js +++ b/src/v1/graph-types.js @@ -17,6 +17,8 @@ * limitations under the License. */ +import Integer from './integer'; + /** * Class for Node Type. */ diff --git a/src/v1/record.js b/src/v1/record.js index 83a2d71f5..43626d241 100644 --- a/src/v1/record.js +++ b/src/v1/record.js @@ -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. diff --git a/test/types/index.test.ts b/test/types/index.test.ts new file mode 100644 index 000000000..73b41f736 --- /dev/null +++ b/test/types/index.test.ts @@ -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"); diff --git a/test/types/v1/driver.test.ts b/test/types/v1/driver.test.ts new file mode 100644 index 000000000..1a05f15b6 --- /dev/null +++ b/test/types/v1/driver.test.ts @@ -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 = authToken.realm; +const realm2: string = authToken.realm; +const parameters1: undefined = authToken.parameters; +const parameters2: { [key: string]: any } = <{ [key: string]: any }>authToken.parameters; +const parameters3: 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(); diff --git a/test/types/v1/error.test.ts b/test/types/v1/error.test.ts new file mode 100644 index 000000000..b51d98402 --- /dev/null +++ b/test/types/v1/error.test.ts @@ -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"); diff --git a/test/types/v1/graph-types.test.ts b/test/types/v1/graph-types.test.ts new file mode 100644 index 000000000..10e2c22b6 --- /dev/null +++ b/test/types/v1/graph-types.test.ts @@ -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; diff --git a/test/types/v1/index.test.ts b/test/types/v1/index.test.ts new file mode 100644 index 000000000..552329218 --- /dev/null +++ b/test/types/v1/index.test.ts @@ -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; + diff --git a/test/types/v1/integer.test.ts b/test/types/v1/integer.test.ts new file mode 100644 index 000000000..d52b37c0d --- /dev/null +++ b/test/types/v1/integer.test.ts @@ -0,0 +1,184 @@ +/** + * 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 Integer, {inSafeRange, int, isInt, toNumber, toString} from "../../../types/v1/integer"; + +const int1 = new Integer(); +const int2 = new Integer(1); +const int3 = new Integer(1, 2); + +const high: number = int1.high; +const low: number = int1.low; + +const safe: boolean = int1.inSafeRange(); +if (safe) { + const i: number = int1.toInt(); + console.log(i); + + const n: number = int1.toNumber(); + console.log(n) +} + +const str: string = int2.toString(16); + +const highBits: number = int3.getHighBits(); +const lowBits: number = int3.getLowBits(); +const numBitsAbs: number = int3.getNumBitsAbs(); + +const isZero: boolean = int1.isZero(); +const isNegative: boolean = int1.isNegative(); +const isPositive: boolean = int1.isPositive(); +const isOdd: boolean = int1.isOdd(); +const isEven: boolean = int1.isEven(); + +const eq1: boolean = int1.equals(int2); +const eq2: boolean = int1.equals(42); +const eq3: boolean = int1.equals("42"); + +const neq1: boolean = int1.notEquals(int2); +const neq2: boolean = int1.notEquals(42); +const neq3: boolean = int1.notEquals("42"); + +const lt1: boolean = int1.lessThan(int2); +const lt2: boolean = int1.lessThan(42); +const lt3: boolean = int1.lessThan("42"); + +const lte1: boolean = int1.lessThanOrEqual(int2); +const lte2: boolean = int1.lessThanOrEqual(42); +const lte3: boolean = int1.lessThanOrEqual("42"); + +const gt1: boolean = int1.greaterThan(int2); +const gt2: boolean = int1.greaterThan(42); +const gt3: boolean = int1.greaterThan("42"); + +const gte1: boolean = int1.greaterThanOrEqual(int2); +const gte2: boolean = int1.greaterThanOrEqual(42); +const gte3: boolean = int1.greaterThanOrEqual("42"); + +const cmp1: number = int2.compare(int3); +const cmp2: number = int2.compare(42); +const cmp3: number = int2.compare("42"); + +const negated: Integer = int3.negate(); + +const add1: Integer = int1.add(int2); +const add2: Integer = int1.add(42); +const add3: Integer = int1.add("42"); + +const subtract1: Integer = int1.subtract(int2); +const subtract2: Integer = int1.subtract(42); +const subtract3: Integer = int1.subtract("42"); + +const multiply1: Integer = int1.multiply(int2); +const multiply2: Integer = int1.multiply(42); +const multiply3: Integer = int1.multiply("42"); + +const div1: Integer = int1.div(int2); +const div2: Integer = int1.div(42); +const div3: Integer = int1.div("42"); + +const modulo1: Integer = int1.modulo(int2); +const modulo2: Integer = int1.modulo(42); +const modulo3: Integer = int1.modulo("42"); + +const not: Integer = int3.not(); + +const and1: Integer = int3.and(int2); +const and2: Integer = int3.and(42); +const and3: Integer = int3.and("42"); + +const or1: Integer = int3.or(int2); +const or2: Integer = int3.or(42); +const or3: Integer = int3.or("42"); + +const xor1: Integer = int3.xor(int2); +const xor2: Integer = int3.xor(42); +const xor3: Integer = int3.xor("42"); + +const shiftLeft: Integer = int2.shiftLeft(int1); +const shiftRight: Integer = int2.shiftRight(int1); + +const isIntegerProp: boolean = Integer.__isInteger__; +const isInteger: boolean = Integer.isInteger({}); + +const fromInt: Integer = Integer.fromInt(42); +const fromNumber: Integer = Integer.fromNumber(42); +const fromBits: Integer = Integer.fromBits(1, 2); +const fromStr1: Integer = Integer.fromString("123"); +const fromStr2: Integer = Integer.fromString("123", 10); + +const fromValue1: Integer = Integer.fromValue(int1); +const fromValue2: Integer = Integer.fromValue(42); +const fromValue3: Integer = Integer.fromValue("42"); +const fromValue4: Integer = Integer.fromValue({low: 1, high: 2}); + +const toNumber1: number = Integer.toNumber(int3); +const toNumber2: number = Integer.toNumber(42); +const toNumber3: number = Integer.toNumber("42"); +const toNumber4: number = Integer.toNumber({low: 2, high: 1}); + +const toStr1: string = Integer.toString(int3); +const toStr2: string = Integer.toString(42); +const toStr3: string = Integer.toString("42"); +const toStr4: string = Integer.toString({low: 1, high: 1}); + +const toStr5: string = Integer.toString(int3, 10); +const toStr6: string = Integer.toString(42, 2); +const toStr7: string = Integer.toString("42", 16); +const toStr8: string = Integer.toString({low: 1, high: 1}, 10); + +const inSafeRange1: boolean = Integer.inSafeRange(int3); +const inSafeRange2: boolean = Integer.inSafeRange(42); +const inSafeRange3: boolean = Integer.inSafeRange("42"); +const inSafeRange4: boolean = Integer.inSafeRange({low: 2, high: 2}); + +const zero: Integer = Integer.ZERO; +const one: Integer = Integer.ONE; +const negOne: Integer = Integer.NEG_ONE; +const max: Integer = Integer.MAX_VALUE; +const min: Integer = Integer.MIN_VALUE; +const minSafe: Integer = Integer.MIN_SAFE_VALUE; +const maxSafe: Integer = Integer.MAX_SAFE_VALUE; + +const intFunc1: Integer = int(int1); +const intFunc2: Integer = int(42); +const intFunc3: Integer = int("42"); +const intFunc4: Integer = int({low: 0, high: 1}); + +const isIntFunc: boolean = isInt({}); + +const inSafeRangeFunc1: boolean = inSafeRange(int2); +const inSafeRangeFunc2: boolean = inSafeRange(42); +const inSafeRangeFunc3: boolean = inSafeRange("42"); +const inSafeRangeFunc4: boolean = inSafeRange({low: 1, high: 1}); + +const toNumberFunc1: number = toNumber(int3); +const toNumberFunc2: number = toNumber(42); +const toNumberFunc3: number = toNumber("42"); +const toNumberFunc4: number = toNumber({low: 1, high: 1}); + +const toStringFunc1: string = toString(int3); +const toStringFunc2: string = toString(42); +const toStringFunc3: string = toString("42"); +const toStringFunc4: string = toString({low: 1, high: 1}); + +const toStringFunc5: string = toString(int3, 2); +const toStringFunc6: string = toString(42, 2); +const toStringFunc7: string = toString("42", 10); +const toStringFunc8: string = toString({low: 1, high: 1}, 16); diff --git a/test/types/v1/record.test.ts b/test/types/v1/record.test.ts new file mode 100644 index 000000000..7d2b61a88 --- /dev/null +++ b/test/types/v1/record.test.ts @@ -0,0 +1,49 @@ +/** + * 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 Record from "../../../types/v1/record"; + +const record1 = new Record(["name", "age"], ["Alice", 20]); +const record2 = new Record(["name", "age"], ["Bob", 22], {"key": "value"}); + +const record1Keys: string[] = record1.keys; +const record1Length: number = record1.length; + +const record1Object: object = record1.toObject(); + +record1.forEach(() => { +}); + +record1.forEach((value: any) => { +}); + +record1.forEach((value: any, key: string) => { +}); + +record1.forEach((value: any, key: string, record: Record) => { +}); + +const record1Has: boolean = record1.has(42); +const record2Has: boolean = record1.has("key"); + +const record1Get1: any = record1.get(42); +const record2Get1: any = record2.get("key"); + +const record1Get2: object = record1.get(42); +const record2Get2: string[] = record2.get("key"); diff --git a/test/types/v1/result-summary.test.ts b/test/types/v1/result-summary.test.ts new file mode 100644 index 000000000..dd7d553e3 --- /dev/null +++ b/test/types/v1/result-summary.test.ts @@ -0,0 +1,89 @@ +/** + * 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 ResultSummary, { + Notification, + NotificationPosition, + Plan, + ProfiledPlan, + ServerInfo, + StatementStatistic +} from "../../../types/v1/result-summary"; +import Integer from "../../../types/v1/integer"; + +const dummy: any = null; + +const sum: ResultSummary = dummy; + +const stmt = sum.statement; +const stmtText: string = stmt.text; +const stmtParams: object = stmt.parameters; + +const str: string = sum.statementType; + +const counters: StatementStatistic = sum.counters; + +const containsUpdates: boolean = counters.containsUpdates(); +const nodesCreated: number = counters.nodesCreated(); +const nodesDeleted: number = counters.nodesDeleted(); +const relationshipsCreated: number = counters.relationshipsCreated(); +const relationshipsDeleted: number = counters.relationshipsDeleted(); +const propertiesSet: number = counters.propertiesSet(); +const labelsAdded: number = counters.labelsAdded(); +const labelsRemoved: number = counters.labelsRemoved(); +const indexesAdded: number = counters.indexesAdded(); +const indexesRemoved: number = counters.indexesRemoved(); +const constraintsAdded: number = counters.constraintsAdded(); +const constraintsRemoved: number = counters.constraintsRemoved(); + +const plan: Plan = sum.plan; +const planOperatorType: string = plan.operatorType; +const planIdentifiers: string[] = plan.identifiers; +const planArguments: { [key: string]: string } = plan.arguments; +const planChildren: Plan[] = plan.children; + +const profile: ProfiledPlan = sum.profile; +const profileOperatorType: string = profile.operatorType; +const profileIdentifiers: string[] = profile.identifiers; +const profileArguments: { [key: string]: string } = profile.arguments; +const profileDbHits: number = profile.dbHits; +const profileRows: number = profile.rows; +const profileChildren: ProfiledPlan[] = profile.children; + +const notifications: Notification[] = sum.notifications; +const notification: Notification = notifications[0]; +const code: string = notification.code; +const title: string = notification.title; +const description: string = notification.description; +const severity: string = notification.severity; +const position1: NotificationPosition | {} = notification.position; +const position2: NotificationPosition = notification.position; +const offset: number = position2.offset; +const line: number = position2.line; +const column: number = position2.column; + +const server: ServerInfo = sum.server; +const address: string = server.address; +const version: string = server.version; + +const resultConsumedAfter: Integer = sum.resultConsumedAfter; +const resultAvailableAfter: Integer = sum.resultAvailableAfter; + +const hasPlan: boolean = sum.hasPlan(); +const hasProfile: boolean = sum.hasProfile(); diff --git a/test/types/v1/result.test.ts b/test/types/v1/result.test.ts new file mode 100644 index 000000000..b31d6d366 --- /dev/null +++ b/test/types/v1/result.test.ts @@ -0,0 +1,50 @@ +/** + * 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 Result from "../../../types/v1/result"; +import Record from "../../../types/v1/record"; +import ResultSummary from "../../../types/v1/result-summary"; + +const dummy: any = null; + +const res: Result = dummy; + +res.then(value => { + const records: Record[] = value.records; + const summary: ResultSummary = value.summary; +}).catch(error => { + console.log(error); +}); + +res.subscribe({}); + +res.subscribe({ + onNext: (record: Record) => console.log(record) +}); + +res.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error) +}); + +res.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error), + onCompleted: (summary: ResultSummary) => console.log(summary) +}); diff --git a/test/types/v1/session.test.ts b/test/types/v1/session.test.ts new file mode 100644 index 000000000..2f7d57a3b --- /dev/null +++ b/test/types/v1/session.test.ts @@ -0,0 +1,152 @@ +/** + * 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 Session from "../../../types/v1/session"; +import Transaction from "../../../types/v1/transaction"; +import Record from "../../../types/v1/record"; +import Result, {StatementResult} from "../../../types/v1/result"; +import ResultSummary from "../../../types/v1/result-summary"; + +const dummy: any = null; + +const session: Session = dummy; + +const tx: Transaction = session.beginTransaction(); +const bookmark: null | string = session.lastBookmark(); + +const promise1: Promise = session.readTransaction((tx: Transaction) => { + return 10; +}); + +const promise2: Promise = session.readTransaction((tx: Transaction) => { + return Promise.resolve("42") +}); + +const promise3: Promise = session.writeTransaction((tx: Transaction) => { + return 10; +}); + +const promise4: Promise = session.writeTransaction((tx: Transaction) => { + return Promise.resolve("42") +}); + +const close1: void = session.close(); +const close2: void = session.close(() => { + console.log("Session closed"); +}); + +const result1: Result = session.run("RETURN 1"); +result1.then((res: StatementResult) => { + const records: Record[] = res.records; + const summary: ResultSummary = res.summary; + console.log(records); + console.log(summary); +}).catch((error: Error) => { + console.log(error); +}); + +const result2: Result = session.run("RETURN 2"); +result2.subscribe({}); +result2.subscribe({ + onNext: (record: Record) => console.log(record) +}); +result2.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error) +}); +result2.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error), + onCompleted: (summary: ResultSummary) => console.log(summary) +}); + +const result3: Result = session.run("RETURN $value", {value: "42"}); +result3.then((res: StatementResult) => { + const records: Record[] = res.records; + const summary: ResultSummary = res.summary; + console.log(records); + console.log(summary); +}).catch((error: Error) => { + console.log(error); +}); + +const result4: Result = session.run("RETURN $value", {value: "42"}); +result4.subscribe({}); +result4.subscribe({ + onNext: (record: Record) => console.log(record) +}); +result4.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error) +}); +result4.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error), + onCompleted: (summary: ResultSummary) => console.log(summary) +}); + +const result5: Result = session.run({text: "RETURN 1"}); +result5.then((res: StatementResult) => { + const records: Record[] = res.records; + const summary: ResultSummary = res.summary; + console.log(records); + console.log(summary); +}).catch((error: Error) => { + console.log(error); +}); + +const result6: Result = session.run({text: "RETURN 1"}); +result6.subscribe({}); +result6.subscribe({ + onNext: (record: Record) => console.log(record) +}); +result6.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error) +}); +result6.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error), + onCompleted: (summary: ResultSummary) => console.log(summary) +}); + +const result7: Result = session.run({text: "RETURN $value", parameters: {value: 42}}); +result7.then((res: StatementResult) => { + const records: Record[] = res.records; + const summary: ResultSummary = res.summary; + console.log(records); + console.log(summary); +}).catch((error: Error) => { + console.log(error); +}); + +const result8: Result = session.run({text: "RETURN $value", parameters: {value: 42}}); +result8.subscribe({}); +result8.subscribe({ + onNext: (record: Record) => console.log(record) +}); +result8.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error) +}); +result8.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error), + onCompleted: (summary: ResultSummary) => console.log(summary) +}); diff --git a/test/types/v1/transaction.test.ts b/test/types/v1/transaction.test.ts new file mode 100644 index 000000000..6629a33be --- /dev/null +++ b/test/types/v1/transaction.test.ts @@ -0,0 +1,142 @@ +/** + * 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 Transaction from "../../../types/v1/transaction"; +import Record from "../../../types/v1/record"; +import Result, {StatementResult} from "../../../types/v1/result"; +import ResultSummary from "../../../types/v1/result-summary"; + +const dummy: any = null; + +const tx: Transaction = dummy; + +const isOpen: boolean = tx.isOpen(); +console.log(isOpen); + +const result1: Result = tx.run("RETURN 1"); +result1.then((res: StatementResult) => { + const records: Record[] = res.records; + const summary: ResultSummary = res.summary; + console.log(records); + console.log(summary); +}).catch((error: Error) => { + console.log(error); +}); + +const result2: Result = tx.run("RETURN 2"); +result2.subscribe({}); +result2.subscribe({ + onNext: (record: Record) => console.log(record) +}); +result2.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error) +}); +result2.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error), + onCompleted: (summary: ResultSummary) => console.log(summary) +}); + +const result3: Result = tx.run("RETURN $value", {value: "42"}); +result3.then((res: StatementResult) => { + const records: Record[] = res.records; + const summary: ResultSummary = res.summary; + console.log(records); + console.log(summary); +}).catch((error: Error) => { + console.log(error); +}); + +const result4: Result = tx.run("RETURN $value", {value: "42"}); +result4.subscribe({}); +result4.subscribe({ + onNext: (record: Record) => console.log(record) +}); +result4.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error) +}); +result4.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error), + onCompleted: (summary: ResultSummary) => console.log(summary) +}); + +const result5: Result = tx.run({text: "RETURN 1"}); +result5.then((res: StatementResult) => { + const records: Record[] = res.records; + const summary: ResultSummary = res.summary; + console.log(records); + console.log(summary); +}).catch((error: Error) => { + console.log(error); +}); + +const result6: Result = tx.run({text: "RETURN 1"}); +result6.subscribe({}); +result6.subscribe({ + onNext: (record: Record) => console.log(record) +}); +result6.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error) +}); +result6.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error), + onCompleted: (summary: ResultSummary) => console.log(summary) +}); + +const result7: Result = tx.run({text: "RETURN $value", parameters: {value: 42}}); +result7.then((res: StatementResult) => { + const records: Record[] = res.records; + const summary: ResultSummary = res.summary; + console.log(records); + console.log(summary); +}).catch((error: Error) => { + console.log(error); +}); + +const result8: Result = tx.run({text: "RETURN $value", parameters: {value: 42}}); +result8.subscribe({}); +result8.subscribe({ + onNext: (record: Record) => console.log(record) +}); +result8.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error) +}); +result8.subscribe({ + onNext: (record: Record) => console.log(record), + onError: (error: Error) => console.log(error), + onCompleted: (summary: ResultSummary) => console.log(summary) +}); + +tx.commit().then((res: StatementResult) => { + console.log(res); +}).catch((error: Error) => { + console.log(error); +}); + +tx.rollback().then((res: StatementResult) => { + console.log(res); +}).catch((error: Error) => { + console.log(error); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..a8685bde8 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "module": "es6", + "target": "es6", + "noImplicitAny": true, + "noImplicitReturns": true + } +} \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 000000000..c7f56413f --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,23 @@ +/** + * 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 * as v1 from "./v1/index"; + +export {v1} +export default v1; diff --git a/types/v1/driver.d.ts b/types/v1/driver.d.ts new file mode 100644 index 000000000..c669502f3 --- /dev/null +++ b/types/v1/driver.d.ts @@ -0,0 +1,61 @@ +/** + * 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 Session from "./session"; +import {Parameters} from "./statement-runner"; + +declare interface AuthToken { + scheme: string; + principal: string; + credentials: string; + realm?: string; + parameters?: Parameters; +} + +declare type EncryptionLevel = "ENCRYPTION_ON" | "ENCRYPTION_OFF"; +declare type TrustStrategy = + "TRUST_ALL_CERTIFICATES" | + "TRUST_ON_FIRST_USE" | + "TRUST_SIGNED_CERTIFICATES" | + "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES" | + "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES"; + +declare interface Config { + encrypted?: boolean | EncryptionLevel; + trust?: TrustStrategy; + trustedCertificates?: string[]; + knownHosts?: string; + connectionPoolSize?: number; + maxTransactionRetryTime?: number; +} + +declare type SessionMode = "READ" | "WRITE"; + +declare const READ: SessionMode; +declare const WRITE: SessionMode; + +declare interface Driver { + session(mode?: SessionMode, bookmark?: string): Session; + + close(): void; +} + +export {Driver, READ, WRITE, AuthToken, Config, EncryptionLevel, TrustStrategy, SessionMode} + +export default Driver; diff --git a/types/v1/error.d.ts b/types/v1/error.d.ts new file mode 100644 index 000000000..84e885236 --- /dev/null +++ b/types/v1/error.d.ts @@ -0,0 +1,39 @@ +/** + * 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. + */ + +declare const SERVICE_UNAVAILABLE: string; +declare const SESSION_EXPIRED: string; +declare const PROTOCOL_ERROR: string; + +declare function newError(message: any, code?: string): Neo4jError; + +declare class Neo4jError extends Error { + code: string; + message: string; + + constructor(message: any, code?: string); +} + +export { + newError, + Neo4jError, + SERVICE_UNAVAILABLE, + SESSION_EXPIRED, + PROTOCOL_ERROR +} diff --git a/types/v1/graph-types.d.ts b/types/v1/graph-types.d.ts new file mode 100644 index 000000000..a551af315 --- /dev/null +++ b/types/v1/graph-types.d.ts @@ -0,0 +1,91 @@ +/** + * 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 Integer from "./integer"; + +declare class Node { + identity: Integer; + labels: string[]; + properties: object; + + constructor(identity: Integer, + labels: string[], + properties: object) + + toString(): string; +} + +declare class Relationship { + identity: Integer; + start: Integer; + end: Integer; + type: string; + properties: object; + + constructor(identity: Integer, + start: Integer, + end: Integer, + type: string, + properties: object); + + toString(): string; +} + +declare class UnboundRelationship { + identity: Integer; + type: string; + properties: object; + + constructor(identity: Integer, + type: string, + properties: object); + + bind(start: Integer, end: Integer): Relationship; + + toString(): string; +} + +declare class PathSegment { + start: Node; + rel: Relationship; + end: Node; + + constructor(start: Node, + rel: Relationship, + end: Node); +} + +declare class Path { + start: Node; + end: Node; + segments: PathSegment[]; + length: number; + + constructor(start: Node, + end: Node, + segments: PathSegment[]); +} + +export { + Node, + Relationship, + UnboundRelationship, + Path, + PathSegment +} diff --git a/types/v1/index.d.ts b/types/v1/index.d.ts new file mode 100644 index 000000000..52bd21808 --- /dev/null +++ b/types/v1/index.d.ts @@ -0,0 +1,109 @@ +/** + * 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 {inSafeRange, int, isInt, toNumber, toString} from "./integer"; +import {Node, Path, PathSegment, Relationship, UnboundRelationship} from "./graph-types"; +import {Neo4jError, PROTOCOL_ERROR, SERVICE_UNAVAILABLE, SESSION_EXPIRED} from "./error"; +import Result from "./result"; +import ResultSummary from "./result-summary"; +import Record from "./record"; +import Session from "./session"; +import {AuthToken, Config, Driver, READ, WRITE} from "./driver"; +import Transaction from "./transaction"; +import {Parameters} from "./statement-runner"; + +declare const auth: { + basic: (username: string, + password: string, + realm?: string) => AuthToken, + + kerberos: (base64EncodedTicket: string) => AuthToken, + + custom: (principal: string, + credentials: string, + realm: string, + scheme: string, + parameters?: Parameters) => AuthToken, +}; + +declare function driver(url: string, + authToken?: AuthToken, + config?: Config): Driver; + +declare const types: { + Node: typeof Node; + Relationship: typeof Relationship; + UnboundRelationship: typeof UnboundRelationship; + PathSegment: typeof PathSegment; + Path: typeof Path; + Result: Result; + ResultSummary: ResultSummary; + Record: typeof Record; +}; + +declare const session: { + READ: typeof READ; + WRITE: typeof WRITE; +}; + +declare const error: { + SERVICE_UNAVAILABLE: typeof SERVICE_UNAVAILABLE; + SESSION_EXPIRED: typeof SESSION_EXPIRED; + PROTOCOL_ERROR: typeof PROTOCOL_ERROR; +}; + +declare const integer: { + toNumber: typeof toNumber; + toString: typeof toString; + inSafeRange: typeof inSafeRange; +}; + +declare const forExport: { + driver: typeof driver; + int: typeof int; + isInt: typeof isInt; + integer: typeof integer; + Neo4jError: typeof Neo4jError; + auth: typeof auth; + types: typeof types; + session: typeof session; + error: typeof error; + Driver: Driver; + AuthToken: AuthToken; + Config: Config; + Session: Session; + Transaction: Transaction; +}; + +export { + driver, + int, + isInt, + integer, + Neo4jError, + auth, + types, + session, + error, + AuthToken, + Session, + Config, +} + +export default forExport; diff --git a/types/v1/integer.d.ts b/types/v1/integer.d.ts new file mode 100644 index 000000000..c686fd0bf --- /dev/null +++ b/types/v1/integer.d.ts @@ -0,0 +1,135 @@ +/** + * 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. + */ + +declare class Integer { + low: number; + high: number; + + constructor(low?: number, high?: number) + + inSafeRange(): boolean; + + toInt(): number; + + toNumber(): number; + + toString(radix: number): string; + + getHighBits(): number; + + getLowBits(): number; + + getNumBitsAbs(): number; + + isZero(): boolean; + + isNegative(): boolean; + + isPositive(): boolean; + + isOdd(): boolean; + + isEven(): boolean; + + equals(other: Integer | number | string): boolean; + + notEquals(other: Integer | number | string): boolean; + + lessThan(other: Integer | number | string): boolean; + + lessThanOrEqual(other: Integer | number | string): boolean; + + greaterThan(other: Integer | number | string): boolean; + + greaterThanOrEqual(other: Integer | number | string): boolean; + + compare(other: Integer | number | string): number; + + negate(): Integer; + + add(addend: Integer | number | string): Integer; + + subtract(subtrahend: Integer | number | string): Integer; + + multiply(multiplier: Integer | number | string): Integer; + + div(divisor: Integer | number | string): Integer; + + modulo(divisor: Integer | number | string): Integer; + + not(): Integer; + + and(other: Integer | number | string): Integer; + + or(other: Integer | number | string): Integer; + + xor(other: Integer | number | string): Integer; + + shiftLeft(numBits: Integer | number): Integer; + + shiftRight(numBits: Integer | number): Integer; + + static __isInteger__: true; + + static isInteger(obj: object): boolean; + + static fromInt(value: number): Integer; + + static fromNumber(value: number): Integer; + + static fromBits(lowBits: number, highBits: number): Integer; + + static fromString(str: string, radix?: number): Integer; + + static fromValue(value: Integer | number | string | { low: number, high: number }): Integer; + + static toNumber(value: Integer | number | string | { low: number, high: number }): number; + + static toString(value: Integer | number | string | { low: number, high: number }, radix?: number): string; + + static inSafeRange(value: Integer | number | string | { low: number, high: number }): boolean; + + static ZERO: Integer; + static ONE: Integer; + static NEG_ONE: Integer; + static MAX_VALUE: Integer; + static MIN_VALUE: Integer; + static MIN_SAFE_VALUE: Integer; + static MAX_SAFE_VALUE: Integer; +} + +declare function int(value: Integer | number | string | { low: number, high: number }): Integer; + +declare function isInt(obj: object): boolean; + +declare function inSafeRange(val: Integer | number | string | { low: number, high: number }): boolean; + +declare function toNumber(val: Integer | number | string | { low: number, high: number }): number; + +declare function toString(val: Integer | number | string | { low: number, high: number }, radix?: number): string; + +export { + int, + isInt, + inSafeRange, + toNumber, + toString +} + +export default Integer; diff --git a/types/v1/record.d.ts b/types/v1/record.d.ts new file mode 100644 index 000000000..be4bb1f41 --- /dev/null +++ b/types/v1/record.d.ts @@ -0,0 +1,37 @@ +/** + * 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. + */ + +declare type Visitor = (value: any, key: string, record: Record) => void; + +declare class Record { + keys: string[]; + length: number; + + constructor(keys: string[], fields: any[], fieldLookup?: { [index: string]: string }); + + forEach(visitor: Visitor): void; + + toObject(): object; + + get(key: string | number): any; + + has(key: string | number): boolean; +} + +export default Record; diff --git a/types/v1/result-summary.d.ts b/types/v1/result-summary.d.ts new file mode 100644 index 000000000..e3164b86e --- /dev/null +++ b/types/v1/result-summary.d.ts @@ -0,0 +1,104 @@ +/** + * 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 Integer from "./integer"; + +declare interface ResultSummary { + statement: { text: string, parameters: { [key: string]: any } }; + statementType: string; + counters: StatementStatistic; + plan: Plan; + profile: ProfiledPlan; + notifications: Notification[]; + server: ServerInfo; + resultConsumedAfter: Integer; + resultAvailableAfter: Integer; + + hasPlan(): boolean; + + hasProfile(): boolean; +} + +declare interface Plan { + operatorType: string; + identifiers: string[]; + arguments: { [key: string]: string }; + children: Plan[]; +} + +declare interface ProfiledPlan { + operatorType: string; + identifiers: string[]; + arguments: { [key: string]: string }; + dbHits: number; + rows: number; + children: ProfiledPlan[]; +} + +declare interface StatementStatistic { + containsUpdates(): boolean; + + nodesCreated(): number; + + nodesDeleted(): number; + + relationshipsCreated(): number; + + relationshipsDeleted(): number; + + propertiesSet(): number; + + labelsAdded(): number; + + labelsRemoved(): number; + + indexesAdded(): number; + + indexesRemoved(): number; + + constraintsAdded(): number; + + constraintsRemoved(): number; +} + +declare type NotificationPosition = { offset: number; line: number; column: number; } + +declare interface Notification { + code: string; + title: string; + description: string; + severity: string; + position: NotificationPosition | {}; +} + +declare interface ServerInfo { + address: string; + version: string; +} + +declare const statementType: { + READ_ONLY: "r"; + READ_WRITE: "rw"; + WRITE_ONLY: "w"; + SCHEMA_WRITE: "s"; +}; + +export {statementType, Plan, ProfiledPlan, StatementStatistic, Notification, ServerInfo, NotificationPosition} + +export default ResultSummary; diff --git a/types/v1/result.d.ts b/types/v1/result.d.ts new file mode 100644 index 000000000..a90d4ee5b --- /dev/null +++ b/types/v1/result.d.ts @@ -0,0 +1,39 @@ +/** + * 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 ResultSummary from "./result-summary"; +import Record from "./record"; + +declare type StatementResult = { + records: Record[]; + summary: ResultSummary; +} + +declare type Observer = { + onNext?(record: Record): void; + onCompleted?(summary: ResultSummary): void; + onError?(error: Error): void; +} + +declare interface Result extends Promise { + subscribe(observer: Observer): void; +} + +export {StatementResult, Observer}; +export default Result; diff --git a/types/v1/session.d.ts b/types/v1/session.d.ts new file mode 100644 index 000000000..f6e3e35d5 --- /dev/null +++ b/types/v1/session.d.ts @@ -0,0 +1,37 @@ +/** + * 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 Transaction from "./transaction"; +import StatementRunner from "./statement-runner"; + +declare type TransactionWork = (tx: Transaction) => T | Promise; + +declare interface Session extends StatementRunner { + beginTransaction(): Transaction; + + lastBookmark(): string | null; + + readTransaction(work: TransactionWork): Promise; + + writeTransaction(work: TransactionWork): Promise; + + close(callback?: () => void): void; +} + +export default Session; diff --git a/types/v1/statement-runner.d.ts b/types/v1/statement-runner.d.ts new file mode 100644 index 000000000..76b41397c --- /dev/null +++ b/types/v1/statement-runner.d.ts @@ -0,0 +1,32 @@ +/** + * 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 Result from "./result"; + +declare type Parameters = { [key: string]: any }; + +declare interface StatementRunner { + run(statement: string, parameters?: Parameters): Result; + + run(statement: { text: string, parameters?: Parameters }): Result; +} + +export {Parameters} + +export default StatementRunner; diff --git a/types/v1/transaction.d.ts b/types/v1/transaction.d.ts new file mode 100644 index 000000000..33dcf3ac0 --- /dev/null +++ b/types/v1/transaction.d.ts @@ -0,0 +1,31 @@ +/** + * 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 Result from "./result"; +import StatementRunner from "./statement-runner"; + +declare interface Transaction extends StatementRunner { + commit(): Result; + + rollback(): Result; + + isOpen(): boolean; +} + +export default Transaction;