From d181b04328e844a436802fa5157733cf4f7d4ccd Mon Sep 17 00:00:00 2001 From: Tim Hope Date: Fri, 30 Dec 2016 02:35:30 +1100 Subject: [PATCH 01/18] Started Adding Type Definitions Covered All Externals I think. First time writing Type Definitions so anyone else feel free to take over and do a better job. --- package.json | 1 + src/index.d.ts | 3 + src/v1/driver.d.ts | 61 +++++++++++++ src/v1/error.d.ts | 15 ++++ src/v1/graph-types.d.ts | 62 +++++++++++++ src/v1/index.d.ts | 83 ++++++++++++++++++ src/v1/index.js | 2 +- src/v1/integer.d.ts | 116 +++++++++++++++++++++++++ src/v1/internal/connector.d.ts | 43 +++++++++ src/v1/internal/pool.d.ts | 12 +++ src/v1/internal/round-robin-array.d.ts | 21 +++++ src/v1/internal/stream-observer.d.ts | 5 ++ src/v1/record.d.ts | 17 ++++ src/v1/result-summary.d.ts | 101 +++++++++++++++++++++ src/v1/result.d.ts | 30 +++++++ src/v1/routing-driver.d.ts | 56 ++++++++++++ src/v1/session.d.ts | 35 ++++++++ src/v1/transaction.d.ts | 25 ++++++ src/version.d.ts | 3 + 19 files changed, 690 insertions(+), 1 deletion(-) create mode 100644 src/index.d.ts create mode 100644 src/v1/driver.d.ts create mode 100644 src/v1/error.d.ts create mode 100644 src/v1/graph-types.d.ts create mode 100644 src/v1/index.d.ts create mode 100644 src/v1/integer.d.ts create mode 100644 src/v1/internal/connector.d.ts create mode 100644 src/v1/internal/pool.d.ts create mode 100644 src/v1/internal/round-robin-array.d.ts create mode 100644 src/v1/internal/stream-observer.d.ts create mode 100644 src/v1/record.d.ts create mode 100644 src/v1/result-summary.d.ts create mode 100644 src/v1/result.d.ts create mode 100644 src/v1/routing-driver.d.ts create mode 100644 src/v1/session.d.ts create mode 100644 src/v1/transaction.d.ts create mode 100644 src/version.d.ts diff --git a/package.json b/package.json index 32b5f7dd2..ceb75cc69 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "vinyl-source-stream": "^1.1.0" }, "dependencies": { + "@types/node": "^6.0.54", "babel-runtime": "^6.18.0" } } diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 000000000..4432d08ad --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,3 @@ +import * as v1 from "./v1/index"; +export { v1 } +export default v1; diff --git a/src/v1/driver.d.ts b/src/v1/driver.d.ts new file mode 100644 index 000000000..c41dd3e21 --- /dev/null +++ b/src/v1/driver.d.ts @@ -0,0 +1,61 @@ +import { Promise } from "core-js"; + +import Session from "./session"; +import Pool from "./internal/pool"; +import Integer from "./integer"; +import { connect, Connection } from "./internal/connector"; +import StreamObserver from "./internal/stream-observer"; +import { newError, SERVICE_UNAVAILABLE } from "./error"; + +interface AuthCredentials { + scheme: string; + principal: string; + credentials: string; + realm?: string; + parameters?: {[key: string]: any}; +} + +interface ConfigurationOptions { + encrypted?: string; + trust?: string; + trustedCertificates?: any[]; + knownHosts?: string; +} + +declare type READ = "READ"; +declare type WRITE = "WRITE"; + +declare class Driver { + constructor(url: string, + userAgent: string, + token: AuthCredentials, + config: ConfigurationOptions) + + _createConnection( url: string, + release: ( url: string, conn: Connection ) => void + ): Connection; + + static _validateConnection( conn: Connection ): Boolean + + _destroyConnection( conn: Connection ): void; + + session( mode: string ): Session; + + _acquireConnection( mode: string ): Promise; + + _createSession(connectionPromise: Promise, cb: Function): Session; + + close(): void; +} + +declare class _ConnectionStreamObserver extends StreamObserver { + constructor( driver: Driver, conn: Connection ) + + onError( error: Error ): void; + + onCompleted( message: any ): void; +} + +export { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions } + +export default Driver; diff --git a/src/v1/error.d.ts b/src/v1/error.d.ts new file mode 100644 index 000000000..7ab9fb7f1 --- /dev/null +++ b/src/v1/error.d.ts @@ -0,0 +1,15 @@ +type SERVICE_UNAVAILABLE = "ServiceUnavailable"; +type SESSION_EXPIRED = "SessionExpired"; + +declare function newError( message: any, code: string ): Neo4jError; + +declare class Neo4jError extends Error { + constructor( message: any, code: string ) +} + +export { + newError, + Neo4jError, + SERVICE_UNAVAILABLE, + SESSION_EXPIRED, +} diff --git a/src/v1/graph-types.d.ts b/src/v1/graph-types.d.ts new file mode 100644 index 000000000..3f5bb3335 --- /dev/null +++ b/src/v1/graph-types.d.ts @@ -0,0 +1,62 @@ +declare class Node { + constructor(identity: string, + labels: string[], + properties: Object + ) + + toString(): string; +} + +declare class Relationship { + identity: string; + start: string; + end: string; + type: string; + properties: Object; + + constructor(identity: string, + start: string, + end: string, + type: string, + properties: Object) + + toString(): string; +} + +declare class UnboundRelationship { + identity: string; + type: string; + properties: Object; + + constructor(identity: string, + type: string, + properties: Object) + + bind( start: string, end: string ): Relationship; + + toString(): string; +} + +declare class PathSegment { + start: string; + rel: Relationship; + end: string; + + constructor(start: string, + rel: Relationship, + end: string) +} + +declare class Path { + start: Node; + end: Node; + segments: PathSegment[]; +} + +export { + Node, + Relationship, + UnboundRelationship, + Path, + PathSegment +} diff --git a/src/v1/index.d.ts b/src/v1/index.d.ts new file mode 100644 index 000000000..d924206b8 --- /dev/null +++ b/src/v1/index.d.ts @@ -0,0 +1,83 @@ +import {int, isInt, inSafeRange, toNumber, toString} from "./integer"; +import {Node, Relationship, UnboundRelationship, PathSegment, Path} from "./graph-types"; +import {Neo4jError, SERVICE_UNAVAILABLE, SESSION_EXPIRED} from "./error"; +import Result from "./result"; +import ResultSummary from "./result-summary"; +import Record from "./record"; +import {Driver, READ, WRITE, AuthCredentials, ConfigurationOptions} from "./driver"; +import RoutingDriver from "./routing-driver"; +import VERSION from "../version"; +import {parseScheme, parseUrl} from "./internal/connector"; + +declare type auth = { + basic: (username: string, + password: string, + realm?: string ) => AuthCredentials, + custom: ( principal: string, + credentials: string, + realm: string, + scheme: string, + parameters?: {[key: string]: any} ) => AuthCredentials, +}; + +declare type USER_AGENT= string; + +declare function driver(url: string, + authToken: AuthCredentials, + config: ConfigurationOptions ): Driver; + +declare type types = { + Node, + Relationship, + UnboundRelationship, + PathSegment, + Path, + Result, + ResultSummary, + Record + }; + +declare type session = { + READ, + WRITE +}; + +declare type error = { + SERVICE_UNAVAILABLE, + SESSION_EXPIRED +}; +declare type integer = { + toNumber, + toString, + inSafeRange +}; + +declare type forExport = { + driver, + int, + isInt, + integer, + Neo4jError, + auth, + types, + session, + error, + AuthCredentials, + ConfigurationOptions, +}; + +export { + driver, + int, + isInt, + integer, + Neo4jError, + auth, + types, + session, + error, + AuthCredentials, + ConfigurationOptions, +} + +export default forExport; diff --git a/src/v1/index.js b/src/v1/index.js index 948259443..572a48498 100644 --- a/src/v1/index.js +++ b/src/v1/index.js @@ -187,6 +187,6 @@ export { auth, types, session, - error + error, } export default forExport diff --git a/src/v1/integer.d.ts b/src/v1/integer.d.ts new file mode 100644 index 000000000..009100a36 --- /dev/null +++ b/src/v1/integer.d.ts @@ -0,0 +1,116 @@ +import { newError } from "./error"; + +declare class Integer { + low: number; + high: number; + + constructor( low: number, high: number ) + + inSafeRange(): boolean; + + toInt(): number; + + toNumber(): number; + + toString(): 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(val: Integer | number | string | {low: number, high: number}): Integer; + static toNumber(val: Integer | number | string | {low: number, high: number}): number; + static toString(val: Integer | number | string | {low: number, high: number}, radix?: number): Integer; + static inSafeRange(val: 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(val: 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): Integer; + +declare type TWO_PWR_16_DBL = number; +declare type TWO_PWR_24_DBL = number; +declare type TWO_PWR_32_DBL = number; +declare type TWO_PWR_64_DBL = number; +declare type TWO_PWR_63_DBL = number; +declare type TWO_PWR_24 = Integer; + +declare type INT_CACHE = Object; + +export { + int, + isInt, + inSafeRange, + toNumber, + toString +} + +export default Integer; diff --git a/src/v1/internal/connector.d.ts b/src/v1/internal/connector.d.ts new file mode 100644 index 000000000..1087b8da4 --- /dev/null +++ b/src/v1/internal/connector.d.ts @@ -0,0 +1,43 @@ +import { ConfigurationOptions } from "../driver"; + +declare class Connection { + constructor( channel: {write: Function, onMessage: Function}, url: string ) + + initialise( clientName: string, + token: any, + observer: any): void; + + run( statement: any, + params: Object, + observer: any): void; + + pullAll( observer: any ): void; + + discardAll( observer: any ): void; + + reset( observer: any ): void; + + sync(): any; + + isOpen(): boolean; + + isEncrypted(): boolean; + + close( cb: Function ): void; + + setServerVersion( version: string ): void; +} + +declare function connect( url: string, + config: ConfigurationOptions ): Connection; + +declare function parseScheme( url: string ): string; + +declare function parseUrl( url: string ): string; + +export { + connect, + Connection, + parseScheme, + parseUrl, +} diff --git a/src/v1/internal/pool.d.ts b/src/v1/internal/pool.d.ts new file mode 100644 index 000000000..6eaacdaf3 --- /dev/null +++ b/src/v1/internal/pool.d.ts @@ -0,0 +1,12 @@ +declare class Pool { + constructor( create: Function, + destroy: Function, + validate: Function, + maxIdle: number) + aquire( key: string | number ): any; + purge( key: string | number ): any; + purgeAll(): void; + has( key: string | number ): any; +} + +export default Pool; diff --git a/src/v1/internal/round-robin-array.d.ts b/src/v1/internal/round-robin-array.d.ts new file mode 100644 index 000000000..49996fcbe --- /dev/null +++ b/src/v1/internal/round-robin-array.d.ts @@ -0,0 +1,21 @@ +declare class RoundRobinArray { + constructor( items: any ) + + next(): any; + + push( elem: any ): any; + + pushAll( elem: any ): any; + + empty(): number; + + clear(): void; + + size(): number; + + toArray(): any[]; + + remove( item: any ): any; +} + +export default RoundRobinArray; diff --git a/src/v1/internal/stream-observer.d.ts b/src/v1/internal/stream-observer.d.ts new file mode 100644 index 000000000..de16a4979 --- /dev/null +++ b/src/v1/internal/stream-observer.d.ts @@ -0,0 +1,5 @@ +declare class StreamObserver { + constructor( errorTransformer: Function ) +} + +export default StreamObserver; diff --git a/src/v1/record.d.ts b/src/v1/record.d.ts new file mode 100644 index 000000000..e09380313 --- /dev/null +++ b/src/v1/record.d.ts @@ -0,0 +1,17 @@ +import { newError } from "./error"; + +declare function generateFieldLookup( keys: any ): any; + +declare class Record { + constructor(keys: Object, fields: Object, fieldLookup: Object) + + forEach( visitor ): void; + + toObject(): Object; + + get( key: string | number ): any; + + has( key: string | number ): boolean; +} + +export default Record; diff --git a/src/v1/result-summary.d.ts b/src/v1/result-summary.d.ts new file mode 100644 index 000000000..78a9435fd --- /dev/null +++ b/src/v1/result-summary.d.ts @@ -0,0 +1,101 @@ +import Integer, { int, isInt } from "./integer"; + +declare class ResultSummary { + constructor(statement: string, parameters: Object, metadata: Object) + + _buildNotifications( notifications: any ): Notification[]; + + hasPlan(): boolean; + + hasProfile(): boolean; +} + +declare class Plan { + operatorType: any; + identifiers: any; + arguments: any; + children: Plan[]; + constructor( plan: Object ) +} + +declare class ProfiledPlan { + operatorType: any; + identifiers: any; + arguments: any; + dbhits: Integer; + rows: Integer; + children: Plan[]; + constructor( plan: Object ) +} + +interface Statistics { + nodesCreated?: Integer; + nodesDeleted?: Integer; + relationshipsCreated?: Integer; + relationshipsDeleted?: Integer; + propertiesSet?: Integer; + labelsAdded?: Integer; + labelsRemoved?: Integer; + indexesAdded?: Integer; + indexesRemoved?: Integer; + constraintsAdded?: Integer; + constraintsRemoved?: Integer; +} + +declare class StatementStatistic { + _stats: Statistics; + constructor( statistics: Statistics ) + + containsUpdates(): boolean; + + nodesCreated(): Integer; + nodesDeleted(): Integer; + relationshipsCreated(): Integer; + relationshipsDeleted(): Integer; + propertiesSet(): Integer; + labelsAdded(): Integer; + labelsRemoved(): Integer; + indexesAdded(): Integer; + indexesRemoved(): Integer; + constraintsAdded(): Integer; + constraintsRemoved(): Integer; +} + +declare class Notification { + code: any; + title: string; + description: string; + severity: string; + position: any; + + constructor( notification: { + code: any, + title: string, + description: string, + severity: string, + position: any } ) + + _constructPosition( pos ): { + offset: Integer, + line: Integer, + column: Integer, + } | {} +} + +declare class ServerInfo { + address: string; + version: string; + + constructor( serverMeta: {address: string, version: string} ) +} + +declare type statementType = { + READ_ONLY: "r", + READ_WRITE: "rw", + WRITE_ONLY: "w", + SCHEMA_WRITE: "s" +}; + +export { statementType } + +export default ResultSummary; diff --git a/src/v1/result.d.ts b/src/v1/result.d.ts new file mode 100644 index 000000000..240b17e5b --- /dev/null +++ b/src/v1/result.d.ts @@ -0,0 +1,30 @@ +import Promise from "core-js"; + +import ResultSummary from "./result-summary"; +import Record from "./record"; +import StreamObserver from "./internal/stream-observer"; + +declare class Result { + _streanObserver: StreamObserver; + _p: Promise<{records: ArrayRecord, summary: any}> | null; + constructor( streamObserver: StreamObserver, + statement: any, + parameters: Object, + metaSupplier: Function) + + _createPromise(): Promise<{records: ArrayRecord, summary: any}>; + + then( onFulfilled: (result: {records: Array}) => + Promise<{records: ArrayRecord, summary: any}>, + onRejected: (error: {message: string, code: string}) => + void, + ): Promise<{records: ArrayRecord, summary: any}>; + + catch( onRejected: (error: {message: string, code: string}) => + void + ): Promise<{records: ArrayRecord, summary: any}>; + + subscribe( observer: StreamObserver ): void; +} + +export default Result; diff --git a/src/v1/routing-driver.d.ts b/src/v1/routing-driver.d.ts new file mode 100644 index 000000000..b1bce4919 --- /dev/null +++ b/src/v1/routing-driver.d.ts @@ -0,0 +1,56 @@ +import { Promise, Set } from "core-js"; +import Session from "./session"; +import { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions } from "./driver"; +import { newError, SERVICE_UNAVAILABLE, SESSION_EXPIRED } from "./error"; +import RoundRobinArray from "./internal/round-robin-array"; +import Integer, { int } from "./integer"; + +declare class RoutingDriver extends Driver { + _clusterView: ClusterView; + constructor(url: string, + userAgent: string, + token: AuthCredentials, + config: ConfigurationOptions ) + + _createSession( connectionPromise: Promise, cb: Function ): RoutingSession; + + _updatedClusterView(): Promise + + _diff( oldView: any, updatedView: any ): any; + + _acquireConnection( mode: string ): Promise; + + _forget( url: string ): void; + + static _validateConfig( config: ConfigurationOptions ): ConfigurationOptions; +} + +declare class ClusterView { + routers: RoundRobinArray; + readers: RoundRobinArray; + writers: RoundRobinArray; + _expires: Integer; + constructor( routers: RoundRobinArray, + readers: RoundRobinArray, + writers: RoundRobinArray, + expires: Integer ) + + needsUpdate(): boolean; + + all(): Set; + + remove(): void; +} + +declare class RoutingSession extends Session { + _onFailedConnection: Function; + constructor(connectionPromise: Promise, + onClose: Function, + onFailedConnection: Function) + + _onRunFailure(): Function; +} + +declare function newClusterView( session: Session ): Promise; + +export default RoutingDriver; diff --git a/src/v1/session.d.ts b/src/v1/session.d.ts new file mode 100644 index 000000000..88e0e91c5 --- /dev/null +++ b/src/v1/session.d.ts @@ -0,0 +1,35 @@ +import { Promise } from "core-js"; + +import StreamObserver from "./internal/stream-observer"; +import Result from "./result"; +import Transaction from "./transaction"; +import Integer, { int } from "./integer"; +import { newError } from "./error"; + +declare class Session { + _connectionPromise: Promise; + _onClose: Function; + _hasTx: boolean; + constructor( connectionPromise: Promise, + onClose: Function ) + + run( statement: any, parameters: Object ): Result; + + beginTransaction( bookmark: any ): Transaction; + + lastBookmark(): any; + + close( cb: () => void ): void; + + _onRunFailure(): Function; +} + +declare class _RunObserver extends StreamObserver { + constructor( onError: Function ) + + onCompleted( meta: Object ): void; + + meta(): Object; +} + +export default Session; diff --git a/src/v1/transaction.d.ts b/src/v1/transaction.d.ts new file mode 100644 index 000000000..9cc9f546d --- /dev/null +++ b/src/v1/transaction.d.ts @@ -0,0 +1,25 @@ +import { Promise } from "core-js"; +import StreamObserver from "./internal/stream-observer"; +import Result from "./result"; + +declare class Transaction { + constructor(connectionPromise: Promise, + onClose: Function, + errorTransformer: Function, + bookmark?: any, + onBookmark?: Function) + + run( statement: any, parameters: Object ): Result; + + commit(): Result; + + rollback(): Result; + + _onError(): void; +} + +declare function _runDiscardAll( msg: any, + connectionPromise: Promise, + observer: StreamObserver): Result; + +export default Transaction; diff --git a/src/version.d.ts b/src/version.d.ts new file mode 100644 index 000000000..199360e32 --- /dev/null +++ b/src/version.d.ts @@ -0,0 +1,3 @@ +declare type VERSION = string; + +export default VERSION; From d4a4458bcfd6bd3b5c0d921298887236b9d58776 Mon Sep 17 00:00:00 2001 From: Tim Hope Date: Fri, 30 Dec 2016 03:02:39 +1100 Subject: [PATCH 02/18] Removed Comma Removed a Comma that had wound up in a js file when I was first figuring everything out. --- src/v1/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v1/index.js b/src/v1/index.js index 572a48498..948259443 100644 --- a/src/v1/index.js +++ b/src/v1/index.js @@ -187,6 +187,6 @@ export { auth, types, session, - error, + error } export default forExport From 8a3dc008f5767633bee688b410aafab45527c171 Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Fri, 3 Feb 2017 11:10:56 -0200 Subject: [PATCH 03/18] needs to go inside lib or npm won't install mv command left over can't use types as variables add some missing stuff, fix implicitAny errors can't use types for vars noImplicitAny and optional parameters type safety for session.run results needs typeof in const declaration for it to work result summary members unprotect members --- {src => lib}/index.d.ts | 0 {src => lib}/v1/driver.d.ts | 43 +++---- lib/v1/error.d.ts | 18 +++ {src => lib}/v1/graph-types.d.ts | 24 ++-- lib/v1/index.d.ts | 84 +++++++++++++ lib/v1/integer.d.ts | 84 +++++++++++++ lib/v1/internal/connector.d.ts | 41 +++++++ lib/v1/internal/pool.d.ts | 14 +++ .../v1/internal/round-robin-array.d.ts | 15 +-- lib/v1/internal/stream-observer.d.ts | 7 ++ lib/v1/record.d.ts | 19 +++ {src => lib}/v1/result-summary.d.ts | 70 ++++++----- lib/v1/result.d.ts | 30 +++++ lib/v1/routing-driver.d.ts | 59 +++++++++ lib/v1/session.d.ts | 35 ++++++ lib/v1/transaction.d.ts | 27 ++++ {src => lib}/version.d.ts | 0 package.json | 1 + src/v1/error.d.ts | 15 --- src/v1/index.d.ts | 83 ------------- src/v1/integer.d.ts | 116 ------------------ src/v1/internal/connector.d.ts | 43 ------- src/v1/internal/pool.d.ts | 12 -- src/v1/internal/stream-observer.d.ts | 5 - src/v1/record.d.ts | 17 --- src/v1/result.d.ts | 30 ----- src/v1/routing-driver.d.ts | 56 --------- src/v1/session.d.ts | 35 ------ src/v1/transaction.d.ts | 25 ---- tsconfig.json | 8 ++ 30 files changed, 504 insertions(+), 512 deletions(-) rename {src => lib}/index.d.ts (100%) rename {src => lib}/v1/driver.d.ts (53%) create mode 100644 lib/v1/error.d.ts rename {src => lib}/v1/graph-types.d.ts (72%) create mode 100644 lib/v1/index.d.ts create mode 100644 lib/v1/integer.d.ts create mode 100644 lib/v1/internal/connector.d.ts create mode 100644 lib/v1/internal/pool.d.ts rename {src => lib}/v1/internal/round-robin-array.d.ts (57%) create mode 100644 lib/v1/internal/stream-observer.d.ts create mode 100644 lib/v1/record.d.ts rename {src => lib}/v1/result-summary.d.ts (51%) create mode 100644 lib/v1/result.d.ts create mode 100644 lib/v1/routing-driver.d.ts create mode 100644 lib/v1/session.d.ts create mode 100644 lib/v1/transaction.d.ts rename {src => lib}/version.d.ts (100%) delete mode 100644 src/v1/error.d.ts delete mode 100644 src/v1/index.d.ts delete mode 100644 src/v1/integer.d.ts delete mode 100644 src/v1/internal/connector.d.ts delete mode 100644 src/v1/internal/pool.d.ts delete mode 100644 src/v1/internal/stream-observer.d.ts delete mode 100644 src/v1/record.d.ts delete mode 100644 src/v1/result.d.ts delete mode 100644 src/v1/routing-driver.d.ts delete mode 100644 src/v1/session.d.ts delete mode 100644 src/v1/transaction.d.ts create mode 100644 tsconfig.json diff --git a/src/index.d.ts b/lib/index.d.ts similarity index 100% rename from src/index.d.ts rename to lib/index.d.ts diff --git a/src/v1/driver.d.ts b/lib/v1/driver.d.ts similarity index 53% rename from src/v1/driver.d.ts rename to lib/v1/driver.d.ts index c41dd3e21..231c432a8 100644 --- a/src/v1/driver.d.ts +++ b/lib/v1/driver.d.ts @@ -1,5 +1,3 @@ -import { Promise } from "core-js"; - import Session from "./session"; import Pool from "./internal/pool"; import Integer from "./integer"; @@ -12,7 +10,7 @@ interface AuthCredentials { principal: string; credentials: string; realm?: string; - parameters?: {[key: string]: any}; + parameters?: { [key: string]: any }; } interface ConfigurationOptions { @@ -22,38 +20,33 @@ interface ConfigurationOptions { knownHosts?: string; } -declare type READ = "READ"; -declare type WRITE = "WRITE"; +declare const READ: string; +declare const WRITE: string; declare class Driver { - constructor(url: string, + constructor( + url: string, userAgent: string, token: AuthCredentials, - config: ConfigurationOptions) - - _createConnection( url: string, - release: ( url: string, conn: Connection ) => void + config?: ConfigurationOptions + ); + + protected _destroyConnection(conn: Connection): void; + protected _acquireConnection(mode: string): PromiseLike; + protected _createSession(connectionPromise: PromiseLike, cb: Function): Session; + protected _createConnection(url: string, + release: (url: string, conn: Connection) => void ): Connection; - - static _validateConnection( conn: Connection ): Boolean - - _destroyConnection( conn: Connection ): void; - - session( mode: string ): Session; - - _acquireConnection( mode: string ): Promise; - - _createSession(connectionPromise: Promise, cb: Function): Session; - + static _validateConnection(conn: Connection): Boolean + session(mode?: string): Session; close(): void; } declare class _ConnectionStreamObserver extends StreamObserver { - constructor( driver: Driver, conn: Connection ) - - onError( error: Error ): void; + constructor(driver: Driver, conn: Connection); - onCompleted( message: any ): void; + onError(error: Error): void; + onCompleted(message: any): void; } export { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions } diff --git a/lib/v1/error.d.ts b/lib/v1/error.d.ts new file mode 100644 index 000000000..5c5f091a4 --- /dev/null +++ b/lib/v1/error.d.ts @@ -0,0 +1,18 @@ +declare const SERVICE_UNAVAILABLE: string; +declare const SESSION_EXPIRED: 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, +} diff --git a/src/v1/graph-types.d.ts b/lib/v1/graph-types.d.ts similarity index 72% rename from src/v1/graph-types.d.ts rename to lib/v1/graph-types.d.ts index 3f5bb3335..a3ff3b768 100644 --- a/src/v1/graph-types.d.ts +++ b/lib/v1/graph-types.d.ts @@ -1,5 +1,6 @@ declare class Node { - constructor(identity: string, + constructor( + identity: string, labels: string[], properties: Object ) @@ -14,11 +15,13 @@ declare class Relationship { type: string; properties: Object; - constructor(identity: string, + constructor( + identity: string, start: string, end: string, type: string, - properties: Object) + properties: Object + ); toString(): string; } @@ -28,12 +31,13 @@ declare class UnboundRelationship { type: string; properties: Object; - constructor(identity: string, + constructor( + identity: string, type: string, - properties: Object) - - bind( start: string, end: string ): Relationship; + properties: Object + ); + bind(start: string, end: string): Relationship; toString(): string; } @@ -42,9 +46,11 @@ declare class PathSegment { rel: Relationship; end: string; - constructor(start: string, + constructor( + start: string, rel: Relationship, - end: string) + end: string + ); } declare class Path { diff --git a/lib/v1/index.d.ts b/lib/v1/index.d.ts new file mode 100644 index 000000000..e5f432aa7 --- /dev/null +++ b/lib/v1/index.d.ts @@ -0,0 +1,84 @@ +import { int, isInt, inSafeRange, toNumber, toString } from "./integer"; +import { Node, Relationship, UnboundRelationship, PathSegment, Path } from "./graph-types"; +import { Neo4jError, SERVICE_UNAVAILABLE, SESSION_EXPIRED } from "./error"; +import Result from "./result"; +import ResultSummary from "./result-summary"; +import Record from "./record"; +import { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions } from "./driver"; +import RoutingDriver from "./routing-driver"; +import VERSION from "../version"; +import { parseScheme, parseUrl } from "./internal/connector"; + +declare const auth: { + basic: (username: string, + password: string, + realm?: string) => AuthCredentials, + custom: (principal: string, + credentials: string, + realm: string, + scheme: string, + parameters?: { [key: string]: any }) => AuthCredentials, +}; + +declare const USER_AGENT: string; + +declare function driver(url: string, + authToken: AuthCredentials, + config?: ConfigurationOptions): Driver; + +declare const types: { + Node: typeof Node; + Relationship: typeof Relationship; + UnboundRelationship: typeof UnboundRelationship; + PathSegment: typeof PathSegment; + Path: typeof Path; + Result: typeof Result; + ResultSummary: typeof 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; +}; + +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; + AuthCredentials: AuthCredentials; + ConfigurationOptions: ConfigurationOptions; +}; + +export { + driver, + int, + isInt, + integer, + Neo4jError, + auth, + types, + session, + error, + AuthCredentials, + ConfigurationOptions, +} + +export default forExport; diff --git a/lib/v1/integer.d.ts b/lib/v1/integer.d.ts new file mode 100644 index 000000000..23bd60c4e --- /dev/null +++ b/lib/v1/integer.d.ts @@ -0,0 +1,84 @@ +import { newError } from "./error"; + +declare class Integer { + low: number; + high: number; + + constructor(low: number, high: number) + + inSafeRange(): boolean; + toInt(): number; + toNumber(): number; + toString(): 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(val: Integer | number | string | { low: number, high: number }): Integer; + static toNumber(val: Integer | number | string | { low: number, high: number }): number; + static toString(val: Integer | number | string | { low: number, high: number }, radix?: number): Integer; + static inSafeRange(val: 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(val: 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): Integer; + +declare const TWO_PWR_16_DBL: number; +declare const TWO_PWR_24_DBL: number; +declare const TWO_PWR_32_DBL: number; +declare const TWO_PWR_64_DBL: number; +declare const TWO_PWR_63_DBL: number; +declare const TWO_PWR_24: Integer; + +declare const INT_CACHE: Object; + +export { + int, + isInt, + inSafeRange, + toNumber, + toString +} + +export default Integer; diff --git a/lib/v1/internal/connector.d.ts b/lib/v1/internal/connector.d.ts new file mode 100644 index 000000000..04a2f97c4 --- /dev/null +++ b/lib/v1/internal/connector.d.ts @@ -0,0 +1,41 @@ +import { ConfigurationOptions } from "../driver"; + +declare class Connection { + constructor(channel: { write: Function, onMessage: Function }, url: string); + + initialise( + clientName: string, + token: any, + observer: any + ): void; + + run( + statement: any, + params: Object, + observer: any + ): void; + + pullAll(observer: any): void; + discardAll(observer: any): void; + reset(observer: any): void; + sync(): any; + isOpen(): boolean; + isEncrypted(): boolean; + close(cb?: Function): void; + setServerVersion(version: string): void; +} + +declare function connect( + url: string, + config?: ConfigurationOptions +): Connection; + +declare function parseScheme(url: string): string; +declare function parseUrl(url: string): string; + +export { + connect, + Connection, + parseScheme, + parseUrl, +} \ No newline at end of file diff --git a/lib/v1/internal/pool.d.ts b/lib/v1/internal/pool.d.ts new file mode 100644 index 000000000..c3bf11145 --- /dev/null +++ b/lib/v1/internal/pool.d.ts @@ -0,0 +1,14 @@ +declare class Pool { + constructor( + create: Function, + destroy: Function, + validate: Function, + maxIdle: number + ); + aquire(key: string | number): any; + purge(key: string | number): any; + purgeAll(): void; + has(key: string | number): any; +} + +export default Pool; diff --git a/src/v1/internal/round-robin-array.d.ts b/lib/v1/internal/round-robin-array.d.ts similarity index 57% rename from src/v1/internal/round-robin-array.d.ts rename to lib/v1/internal/round-robin-array.d.ts index 49996fcbe..78b67e75c 100644 --- a/src/v1/internal/round-robin-array.d.ts +++ b/lib/v1/internal/round-robin-array.d.ts @@ -1,21 +1,14 @@ declare class RoundRobinArray { - constructor( items: any ) + constructor(items: any); next(): any; - - push( elem: any ): any; - - pushAll( elem: any ): any; - + push(elem: any): any; + pushAll(elem: any): any; empty(): number; - clear(): void; - size(): number; - toArray(): any[]; - - remove( item: any ): any; + remove(item: any): any; } export default RoundRobinArray; diff --git a/lib/v1/internal/stream-observer.d.ts b/lib/v1/internal/stream-observer.d.ts new file mode 100644 index 000000000..6df8197bc --- /dev/null +++ b/lib/v1/internal/stream-observer.d.ts @@ -0,0 +1,7 @@ +declare type ErrorTransformer = (err: Error) => T; + +declare class StreamObserver { + constructor(errorTransformer: ErrorTransformer); +} + +export default StreamObserver; diff --git a/lib/v1/record.d.ts b/lib/v1/record.d.ts new file mode 100644 index 000000000..3f1916e6d --- /dev/null +++ b/lib/v1/record.d.ts @@ -0,0 +1,19 @@ +declare function generateFieldLookup(keys: any): any; + +declare type Visitor = (field: string, value: T, context: Record) => void; + +declare class Record { + keys: string[]; + length: number; + _fields: string[]; + + constructor(keys: string[], fields: string[], fieldLookup: { [index: string]: string }); + + forEach(visitor: Visitor): void; + toObject(): Partial; + get(key: number): K; + get(key: K): T[K]; + has(key: string | number): boolean; +} + +export default Record; diff --git a/src/v1/result-summary.d.ts b/lib/v1/result-summary.d.ts similarity index 51% rename from src/v1/result-summary.d.ts rename to lib/v1/result-summary.d.ts index 78a9435fd..537ba2a63 100644 --- a/src/v1/result-summary.d.ts +++ b/lib/v1/result-summary.d.ts @@ -1,12 +1,22 @@ import Integer, { int, isInt } from "./integer"; declare class ResultSummary { - constructor(statement: string, parameters: Object, metadata: Object) - - _buildNotifications( notifications: any ): Notification[]; - + statement: {text: string, parameters: { [index: string]: any }}; + statementType: string; + counters: StatementStatistic; + //for backwards compatibility, remove in future version + updateStatistics: StatementStatistic; + plan: Plan; + profile: ProfiledPlan; + notifications: Notification[]; + server: ServerInfo; + resultConsumedAfter: any | undefined; + resultAvailableAfter: any | undefined; + + constructor(statement: string, parameters?: { [index: string]: any }, metadata?: { [index: string]: any }) + + protected _buildNotifications(notifications: any): Notification[]; hasPlan(): boolean; - hasProfile(): boolean; } @@ -15,7 +25,7 @@ declare class Plan { identifiers: any; arguments: any; children: Plan[]; - constructor( plan: Object ) + constructor(plan: Object) } declare class ProfiledPlan { @@ -25,7 +35,7 @@ declare class ProfiledPlan { dbhits: Integer; rows: Integer; children: Plan[]; - constructor( plan: Object ) + constructor(plan: Object) } interface Statistics { @@ -43,8 +53,9 @@ interface Statistics { } declare class StatementStatistic { - _stats: Statistics; - constructor( statistics: Statistics ) + protected _stats: Statistics; + + constructor(statistics: Statistics); containsUpdates(): boolean; @@ -61,39 +72,38 @@ declare class StatementStatistic { constraintsRemoved(): Integer; } -declare class Notification { +declare interface NotificationPosition { + offset: Integer; + line: Integer; + column: Integer; +} + +declare interface NotificationStructure { code: any; title: string; description: string; severity: string; - position: any; - - constructor( notification: { - code: any, - title: string, - description: string, - severity: string, - position: any } ) - - _constructPosition( pos ): { - offset: Integer, - line: Integer, - column: Integer, - } | {} + position: NotificationPosition; +} + +declare class Notification implements Partial { + constructor(notification: NotificationStructure); + + _constructPosition(pos: NotificationPosition): NotificationPosition; } declare class ServerInfo { address: string; version: string; - constructor( serverMeta: {address: string, version: string} ) + constructor(serverMeta: { address: string, version: string }); } -declare type statementType = { - READ_ONLY: "r", - READ_WRITE: "rw", - WRITE_ONLY: "w", - SCHEMA_WRITE: "s" +declare const statementType: { + READ_ONLY: "r"; + READ_WRITE: "rw"; + WRITE_ONLY: "w"; + SCHEMA_WRITE: "s"; }; export { statementType } diff --git a/lib/v1/result.d.ts b/lib/v1/result.d.ts new file mode 100644 index 000000000..3b19a4dc8 --- /dev/null +++ b/lib/v1/result.d.ts @@ -0,0 +1,30 @@ +import ResultSummary from "./result-summary"; +import Record from "./record"; +import StreamObserver from "./internal/stream-observer"; + +declare type ResultType = { + records: Array & T>; + summary: ResultSummary; +} + +declare type PromiseResult = PromiseLike> + +declare class Result extends Promise> { + _streanObserver: StreamObserver; + _p: PromiseResult | null; + _statement: string; + _parameters: Params; + _metaSupplier: () => any; + + constructor( + streamObserver: StreamObserver, + statement: string, + parameters?: Params, + metaSupplier?: () => any + ); + + protected _createPromise(): PromiseResult; + subscribe(observer: StreamObserver): void; +} + +export default Result; diff --git a/lib/v1/routing-driver.d.ts b/lib/v1/routing-driver.d.ts new file mode 100644 index 000000000..54c999360 --- /dev/null +++ b/lib/v1/routing-driver.d.ts @@ -0,0 +1,59 @@ +import Session from "./session"; +import { Connection } from './internal/connector'; +import { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions } from "./driver"; +import { newError, SERVICE_UNAVAILABLE, SESSION_EXPIRED } from "./error"; +import RoundRobinArray from "./internal/round-robin-array"; +import Integer, { int } from "./integer"; + +declare class RoutingDriver extends Driver { + _clusterView: ClusterView; + + constructor( + url: string, + userAgent: string, + token: AuthCredentials, + config: ConfigurationOptions + ); + + protected _createSession(connectionPromise: Promise, cb: Function): RoutingSession; + protected _updatedClusterView(): Promise; + protected _diff(oldView: any, updatedView: any): any; + protected _acquireConnection(mode: string): Promise; + protected _forget(url: string): void; + + static _validateConfig(config: ConfigurationOptions): ConfigurationOptions; +} + +declare class ClusterView { + routers: RoundRobinArray; + readers: RoundRobinArray; + writers: RoundRobinArray; + protected _expires: Integer; + + constructor( + routers: RoundRobinArray, + readers: RoundRobinArray, + writers: RoundRobinArray, + expires: Integer + ); + + needsUpdate(): boolean; + all(): Set; + remove(): void; +} + +declare class RoutingSession extends Session { + protected _onFailedConnection: Function; + + constructor( + connectionPromise: Promise, + onClose: Function, + onFailedConnection: Function + ); + + _onRunFailure(): Function; +} + +declare function newClusterView(session: Session): Promise; + +export default RoutingDriver; diff --git a/lib/v1/session.d.ts b/lib/v1/session.d.ts new file mode 100644 index 000000000..0c4cc3d55 --- /dev/null +++ b/lib/v1/session.d.ts @@ -0,0 +1,35 @@ +import { Connection } from './internal/connector' +import StreamObserver from "./internal/stream-observer"; +import Result from "./result"; +import Transaction from "./transaction"; +import Integer, { int } from "./integer"; +import { newError } from "./error"; + +declare class Session { + _connectionPromise: PromiseLike; + _onClose: Function; + _hasTx: boolean; + + constructor( + connectionPromise: PromiseLike, + onClose: Function + ); + + run(statement: string, parameters?: Params): Result; + run(statement: string): Result; + beginTransaction(bookmark?: any): Transaction; + lastBookmark(): any; + close(cb?: () => void): void; + protected _onRunFailure(): Function; +} + +declare class _RunObserver extends StreamObserver { + constructor( + onError: Function + ); + + onCompleted(meta: Object): void; + meta(): Object; +} + +export default Session; diff --git a/lib/v1/transaction.d.ts b/lib/v1/transaction.d.ts new file mode 100644 index 000000000..e5d0da0f9 --- /dev/null +++ b/lib/v1/transaction.d.ts @@ -0,0 +1,27 @@ +import { Connection } from './internal/connector' +import StreamObserver from "./internal/stream-observer"; +import Result from "./result"; + +declare class Transaction { + constructor( + connectionPromise: PromiseLike, + onClose: Function, + errorTransformer: Function, + bookmark?: any, + onBookmark?: Function + ); + + run(statement: any, parameters: Params): Result; + run(statement: any): Result; + commit(): Result; + rollback(): Result; + _onError(): void; +} + +declare function _runDiscardAll( + msg: any, + connectionPromise: PromiseLike, + observer: StreamObserver +): Result; + +export default Transaction; diff --git a/src/version.d.ts b/lib/version.d.ts similarity index 100% rename from src/version.d.ts rename to lib/version.d.ts diff --git a/package.json b/package.json index ceb75cc69..39ae32146 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0" }, + "typings": "./lib/index.d.ts", "dependencies": { "@types/node": "^6.0.54", "babel-runtime": "^6.18.0" diff --git a/src/v1/error.d.ts b/src/v1/error.d.ts deleted file mode 100644 index 7ab9fb7f1..000000000 --- a/src/v1/error.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -type SERVICE_UNAVAILABLE = "ServiceUnavailable"; -type SESSION_EXPIRED = "SessionExpired"; - -declare function newError( message: any, code: string ): Neo4jError; - -declare class Neo4jError extends Error { - constructor( message: any, code: string ) -} - -export { - newError, - Neo4jError, - SERVICE_UNAVAILABLE, - SESSION_EXPIRED, -} diff --git a/src/v1/index.d.ts b/src/v1/index.d.ts deleted file mode 100644 index d924206b8..000000000 --- a/src/v1/index.d.ts +++ /dev/null @@ -1,83 +0,0 @@ -import {int, isInt, inSafeRange, toNumber, toString} from "./integer"; -import {Node, Relationship, UnboundRelationship, PathSegment, Path} from "./graph-types"; -import {Neo4jError, SERVICE_UNAVAILABLE, SESSION_EXPIRED} from "./error"; -import Result from "./result"; -import ResultSummary from "./result-summary"; -import Record from "./record"; -import {Driver, READ, WRITE, AuthCredentials, ConfigurationOptions} from "./driver"; -import RoutingDriver from "./routing-driver"; -import VERSION from "../version"; -import {parseScheme, parseUrl} from "./internal/connector"; - -declare type auth = { - basic: (username: string, - password: string, - realm?: string ) => AuthCredentials, - custom: ( principal: string, - credentials: string, - realm: string, - scheme: string, - parameters?: {[key: string]: any} ) => AuthCredentials, -}; - -declare type USER_AGENT= string; - -declare function driver(url: string, - authToken: AuthCredentials, - config: ConfigurationOptions ): Driver; - -declare type types = { - Node, - Relationship, - UnboundRelationship, - PathSegment, - Path, - Result, - ResultSummary, - Record - }; - -declare type session = { - READ, - WRITE -}; - -declare type error = { - SERVICE_UNAVAILABLE, - SESSION_EXPIRED -}; -declare type integer = { - toNumber, - toString, - inSafeRange -}; - -declare type forExport = { - driver, - int, - isInt, - integer, - Neo4jError, - auth, - types, - session, - error, - AuthCredentials, - ConfigurationOptions, -}; - -export { - driver, - int, - isInt, - integer, - Neo4jError, - auth, - types, - session, - error, - AuthCredentials, - ConfigurationOptions, -} - -export default forExport; diff --git a/src/v1/integer.d.ts b/src/v1/integer.d.ts deleted file mode 100644 index 009100a36..000000000 --- a/src/v1/integer.d.ts +++ /dev/null @@ -1,116 +0,0 @@ -import { newError } from "./error"; - -declare class Integer { - low: number; - high: number; - - constructor( low: number, high: number ) - - inSafeRange(): boolean; - - toInt(): number; - - toNumber(): number; - - toString(): 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(val: Integer | number | string | {low: number, high: number}): Integer; - static toNumber(val: Integer | number | string | {low: number, high: number}): number; - static toString(val: Integer | number | string | {low: number, high: number}, radix?: number): Integer; - static inSafeRange(val: 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(val: 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): Integer; - -declare type TWO_PWR_16_DBL = number; -declare type TWO_PWR_24_DBL = number; -declare type TWO_PWR_32_DBL = number; -declare type TWO_PWR_64_DBL = number; -declare type TWO_PWR_63_DBL = number; -declare type TWO_PWR_24 = Integer; - -declare type INT_CACHE = Object; - -export { - int, - isInt, - inSafeRange, - toNumber, - toString -} - -export default Integer; diff --git a/src/v1/internal/connector.d.ts b/src/v1/internal/connector.d.ts deleted file mode 100644 index 1087b8da4..000000000 --- a/src/v1/internal/connector.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { ConfigurationOptions } from "../driver"; - -declare class Connection { - constructor( channel: {write: Function, onMessage: Function}, url: string ) - - initialise( clientName: string, - token: any, - observer: any): void; - - run( statement: any, - params: Object, - observer: any): void; - - pullAll( observer: any ): void; - - discardAll( observer: any ): void; - - reset( observer: any ): void; - - sync(): any; - - isOpen(): boolean; - - isEncrypted(): boolean; - - close( cb: Function ): void; - - setServerVersion( version: string ): void; -} - -declare function connect( url: string, - config: ConfigurationOptions ): Connection; - -declare function parseScheme( url: string ): string; - -declare function parseUrl( url: string ): string; - -export { - connect, - Connection, - parseScheme, - parseUrl, -} diff --git a/src/v1/internal/pool.d.ts b/src/v1/internal/pool.d.ts deleted file mode 100644 index 6eaacdaf3..000000000 --- a/src/v1/internal/pool.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -declare class Pool { - constructor( create: Function, - destroy: Function, - validate: Function, - maxIdle: number) - aquire( key: string | number ): any; - purge( key: string | number ): any; - purgeAll(): void; - has( key: string | number ): any; -} - -export default Pool; diff --git a/src/v1/internal/stream-observer.d.ts b/src/v1/internal/stream-observer.d.ts deleted file mode 100644 index de16a4979..000000000 --- a/src/v1/internal/stream-observer.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare class StreamObserver { - constructor( errorTransformer: Function ) -} - -export default StreamObserver; diff --git a/src/v1/record.d.ts b/src/v1/record.d.ts deleted file mode 100644 index e09380313..000000000 --- a/src/v1/record.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { newError } from "./error"; - -declare function generateFieldLookup( keys: any ): any; - -declare class Record { - constructor(keys: Object, fields: Object, fieldLookup: Object) - - forEach( visitor ): void; - - toObject(): Object; - - get( key: string | number ): any; - - has( key: string | number ): boolean; -} - -export default Record; diff --git a/src/v1/result.d.ts b/src/v1/result.d.ts deleted file mode 100644 index 240b17e5b..000000000 --- a/src/v1/result.d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import Promise from "core-js"; - -import ResultSummary from "./result-summary"; -import Record from "./record"; -import StreamObserver from "./internal/stream-observer"; - -declare class Result { - _streanObserver: StreamObserver; - _p: Promise<{records: ArrayRecord, summary: any}> | null; - constructor( streamObserver: StreamObserver, - statement: any, - parameters: Object, - metaSupplier: Function) - - _createPromise(): Promise<{records: ArrayRecord, summary: any}>; - - then( onFulfilled: (result: {records: Array}) => - Promise<{records: ArrayRecord, summary: any}>, - onRejected: (error: {message: string, code: string}) => - void, - ): Promise<{records: ArrayRecord, summary: any}>; - - catch( onRejected: (error: {message: string, code: string}) => - void - ): Promise<{records: ArrayRecord, summary: any}>; - - subscribe( observer: StreamObserver ): void; -} - -export default Result; diff --git a/src/v1/routing-driver.d.ts b/src/v1/routing-driver.d.ts deleted file mode 100644 index b1bce4919..000000000 --- a/src/v1/routing-driver.d.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { Promise, Set } from "core-js"; -import Session from "./session"; -import { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions } from "./driver"; -import { newError, SERVICE_UNAVAILABLE, SESSION_EXPIRED } from "./error"; -import RoundRobinArray from "./internal/round-robin-array"; -import Integer, { int } from "./integer"; - -declare class RoutingDriver extends Driver { - _clusterView: ClusterView; - constructor(url: string, - userAgent: string, - token: AuthCredentials, - config: ConfigurationOptions ) - - _createSession( connectionPromise: Promise, cb: Function ): RoutingSession; - - _updatedClusterView(): Promise - - _diff( oldView: any, updatedView: any ): any; - - _acquireConnection( mode: string ): Promise; - - _forget( url: string ): void; - - static _validateConfig( config: ConfigurationOptions ): ConfigurationOptions; -} - -declare class ClusterView { - routers: RoundRobinArray; - readers: RoundRobinArray; - writers: RoundRobinArray; - _expires: Integer; - constructor( routers: RoundRobinArray, - readers: RoundRobinArray, - writers: RoundRobinArray, - expires: Integer ) - - needsUpdate(): boolean; - - all(): Set; - - remove(): void; -} - -declare class RoutingSession extends Session { - _onFailedConnection: Function; - constructor(connectionPromise: Promise, - onClose: Function, - onFailedConnection: Function) - - _onRunFailure(): Function; -} - -declare function newClusterView( session: Session ): Promise; - -export default RoutingDriver; diff --git a/src/v1/session.d.ts b/src/v1/session.d.ts deleted file mode 100644 index 88e0e91c5..000000000 --- a/src/v1/session.d.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Promise } from "core-js"; - -import StreamObserver from "./internal/stream-observer"; -import Result from "./result"; -import Transaction from "./transaction"; -import Integer, { int } from "./integer"; -import { newError } from "./error"; - -declare class Session { - _connectionPromise: Promise; - _onClose: Function; - _hasTx: boolean; - constructor( connectionPromise: Promise, - onClose: Function ) - - run( statement: any, parameters: Object ): Result; - - beginTransaction( bookmark: any ): Transaction; - - lastBookmark(): any; - - close( cb: () => void ): void; - - _onRunFailure(): Function; -} - -declare class _RunObserver extends StreamObserver { - constructor( onError: Function ) - - onCompleted( meta: Object ): void; - - meta(): Object; -} - -export default Session; diff --git a/src/v1/transaction.d.ts b/src/v1/transaction.d.ts deleted file mode 100644 index 9cc9f546d..000000000 --- a/src/v1/transaction.d.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Promise } from "core-js"; -import StreamObserver from "./internal/stream-observer"; -import Result from "./result"; - -declare class Transaction { - constructor(connectionPromise: Promise, - onClose: Function, - errorTransformer: Function, - bookmark?: any, - onBookmark?: Function) - - run( statement: any, parameters: Object ): Result; - - commit(): Result; - - rollback(): Result; - - _onError(): void; -} - -declare function _runDiscardAll( msg: any, - connectionPromise: Promise, - observer: StreamObserver): Result; - -export default Transaction; 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 From c294ea2ebb64348989a0b0aba0ba435ec12b2c1c Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Sun, 5 Feb 2017 15:39:12 -0300 Subject: [PATCH 04/18] Update result.d.ts there's no public accessors in records member --- lib/v1/result.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/v1/result.d.ts b/lib/v1/result.d.ts index 3b19a4dc8..d42372398 100644 --- a/lib/v1/result.d.ts +++ b/lib/v1/result.d.ts @@ -3,7 +3,7 @@ import Record from "./record"; import StreamObserver from "./internal/stream-observer"; declare type ResultType = { - records: Array & T>; + records: Array>; summary: ResultSummary; } From 233869290b58311c9caddb488e6bbdd057eeadd5 Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Sun, 5 Feb 2017 15:43:49 -0300 Subject: [PATCH 05/18] Update record.d.ts _fields is wrong, it should be an array of T --- lib/v1/record.d.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/v1/record.d.ts b/lib/v1/record.d.ts index 3f1916e6d..3ab8926a4 100644 --- a/lib/v1/record.d.ts +++ b/lib/v1/record.d.ts @@ -5,14 +5,13 @@ declare type Visitor = (field: string, value: T, context: Record) => void; declare class Record { keys: string[]; length: number; - _fields: string[]; + _fields: T[]; constructor(keys: string[], fields: string[], fieldLookup: { [index: string]: string }); forEach(visitor: Visitor): void; - toObject(): Partial; - get(key: number): K; - get(key: K): T[K]; + toObject(): Partial<{ [ret: string]: T>; + get(key: string | number): K; has(key: string | number): boolean; } From d58f3d5bc48c5bef1c7a7dbbf1ed2ff3c2039807 Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Sun, 5 Feb 2017 17:59:07 -0200 Subject: [PATCH 06/18] export definitions (Driver and Session) and fix subscribe --- lib/v1/driver.d.ts | 2 +- lib/v1/error.d.ts | 2 +- lib/v1/index.d.ts | 4 ++++ lib/v1/internal/stream-observer.d.ts | 10 +++++++++- lib/v1/record.d.ts | 5 +++-- lib/v1/result-summary.d.ts | 2 +- lib/v1/result.d.ts | 8 ++++---- lib/v1/session.d.ts | 2 +- lib/v1/transaction.d.ts | 2 +- 9 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/v1/driver.d.ts b/lib/v1/driver.d.ts index 231c432a8..ca737a7bb 100644 --- a/lib/v1/driver.d.ts +++ b/lib/v1/driver.d.ts @@ -42,7 +42,7 @@ declare class Driver { close(): void; } -declare class _ConnectionStreamObserver extends StreamObserver { +declare class _ConnectionStreamObserver extends StreamObserver { constructor(driver: Driver, conn: Connection); onError(error: Error): void; diff --git a/lib/v1/error.d.ts b/lib/v1/error.d.ts index 5c5f091a4..023585aa0 100644 --- a/lib/v1/error.d.ts +++ b/lib/v1/error.d.ts @@ -7,7 +7,7 @@ declare class Neo4jError extends Error { code: string; message: string; - constructor(message: any, code: string) + constructor(message: any, code: string); } export { diff --git a/lib/v1/index.d.ts b/lib/v1/index.d.ts index e5f432aa7..e466c1064 100644 --- a/lib/v1/index.d.ts +++ b/lib/v1/index.d.ts @@ -4,6 +4,7 @@ import { Neo4jError, SERVICE_UNAVAILABLE, SESSION_EXPIRED } from "./error"; import Result from "./result"; import ResultSummary from "./result-summary"; import Record from "./record"; +import Session from './session'; import { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions } from "./driver"; import RoutingDriver from "./routing-driver"; import VERSION from "../version"; @@ -63,8 +64,10 @@ declare const forExport: { types: typeof types; session: typeof session; error: typeof error; + Driver: Driver; AuthCredentials: AuthCredentials; ConfigurationOptions: ConfigurationOptions; + Session: Session; }; export { @@ -78,6 +81,7 @@ export { session, error, AuthCredentials, + Session, ConfigurationOptions, } diff --git a/lib/v1/internal/stream-observer.d.ts b/lib/v1/internal/stream-observer.d.ts index 6df8197bc..e65fbebdd 100644 --- a/lib/v1/internal/stream-observer.d.ts +++ b/lib/v1/internal/stream-observer.d.ts @@ -1,6 +1,14 @@ +import ResultSummary from '../result-summary' + declare type ErrorTransformer = (err: Error) => T; -declare class StreamObserver { +export declare interface StreamObserverInterface { + onNext?(record: T): void; + onCompleted?(summary?: ResultSummary): void; + onError?(err: Error): void; +} + +declare class StreamObserver implements StreamObserverInterface { constructor(errorTransformer: ErrorTransformer); } diff --git a/lib/v1/record.d.ts b/lib/v1/record.d.ts index 3ab8926a4..bd0648427 100644 --- a/lib/v1/record.d.ts +++ b/lib/v1/record.d.ts @@ -10,8 +10,9 @@ declare class Record { constructor(keys: string[], fields: string[], fieldLookup: { [index: string]: string }); forEach(visitor: Visitor): void; - toObject(): Partial<{ [ret: string]: T>; - get(key: string | number): K; + toObject(): Partial<{ [ret: string]: T }>; + get(key: K): T[K]; + get(key: number): K; has(key: string | number): boolean; } diff --git a/lib/v1/result-summary.d.ts b/lib/v1/result-summary.d.ts index 537ba2a63..393fa18e3 100644 --- a/lib/v1/result-summary.d.ts +++ b/lib/v1/result-summary.d.ts @@ -1,7 +1,7 @@ import Integer, { int, isInt } from "./integer"; declare class ResultSummary { - statement: {text: string, parameters: { [index: string]: any }}; + statement: { text: string, parameters: { [index: string]: any } }; statementType: string; counters: StatementStatistic; //for backwards compatibility, remove in future version diff --git a/lib/v1/result.d.ts b/lib/v1/result.d.ts index d42372398..4b0daacb9 100644 --- a/lib/v1/result.d.ts +++ b/lib/v1/result.d.ts @@ -1,6 +1,6 @@ import ResultSummary from "./result-summary"; import Record from "./record"; -import StreamObserver from "./internal/stream-observer"; +import StreamObserver, { StreamObserverInterface } from "./internal/stream-observer"; declare type ResultType = { records: Array>; @@ -10,21 +10,21 @@ declare type ResultType = { declare type PromiseResult = PromiseLike> declare class Result extends Promise> { - _streanObserver: StreamObserver; + _streamObserver: StreamObserver; _p: PromiseResult | null; _statement: string; _parameters: Params; _metaSupplier: () => any; constructor( - streamObserver: StreamObserver, + streamObserver: StreamObserver, statement: string, parameters?: Params, metaSupplier?: () => any ); protected _createPromise(): PromiseResult; - subscribe(observer: StreamObserver): void; + subscribe(observer: StreamObserverInterface>): void; } export default Result; diff --git a/lib/v1/session.d.ts b/lib/v1/session.d.ts index 0c4cc3d55..e80e1616a 100644 --- a/lib/v1/session.d.ts +++ b/lib/v1/session.d.ts @@ -23,7 +23,7 @@ declare class Session { protected _onRunFailure(): Function; } -declare class _RunObserver extends StreamObserver { +declare class _RunObserver extends StreamObserver { constructor( onError: Function ); diff --git a/lib/v1/transaction.d.ts b/lib/v1/transaction.d.ts index e5d0da0f9..6f66bd643 100644 --- a/lib/v1/transaction.d.ts +++ b/lib/v1/transaction.d.ts @@ -21,7 +21,7 @@ declare class Transaction { declare function _runDiscardAll( msg: any, connectionPromise: PromiseLike, - observer: StreamObserver + observer: StreamObserver ): Result; export default Transaction; From c9015002febb774b968ae6d520d777ea692fa661 Mon Sep 17 00:00:00 2001 From: lutovich Date: Mon, 12 Jun 2017 22:52:35 +0200 Subject: [PATCH 07/18] Move TS definition files to a dedicated folder Commit moves all type script definition files from `lib` folder to a dedicated folder `types` located in the project root. This is cleaner because `lib` contains generated sources. --- package.json | 3 +-- {lib => types}/index.d.ts | 0 {lib => types}/v1/driver.d.ts | 0 {lib => types}/v1/error.d.ts | 0 {lib => types}/v1/graph-types.d.ts | 0 {lib => types}/v1/index.d.ts | 0 {lib => types}/v1/integer.d.ts | 0 {lib => types}/v1/internal/connector.d.ts | 0 {lib => types}/v1/internal/pool.d.ts | 0 {lib => types}/v1/internal/round-robin-array.d.ts | 0 {lib => types}/v1/internal/stream-observer.d.ts | 0 {lib => types}/v1/record.d.ts | 0 {lib => types}/v1/result-summary.d.ts | 0 {lib => types}/v1/result.d.ts | 0 {lib => types}/v1/routing-driver.d.ts | 0 {lib => types}/v1/session.d.ts | 0 {lib => types}/v1/transaction.d.ts | 0 {lib => types}/version.d.ts | 0 18 files changed, 1 insertion(+), 2 deletions(-) rename {lib => types}/index.d.ts (100%) rename {lib => types}/v1/driver.d.ts (100%) rename {lib => types}/v1/error.d.ts (100%) rename {lib => types}/v1/graph-types.d.ts (100%) rename {lib => types}/v1/index.d.ts (100%) rename {lib => types}/v1/integer.d.ts (100%) rename {lib => types}/v1/internal/connector.d.ts (100%) rename {lib => types}/v1/internal/pool.d.ts (100%) rename {lib => types}/v1/internal/round-robin-array.d.ts (100%) rename {lib => types}/v1/internal/stream-observer.d.ts (100%) rename {lib => types}/v1/record.d.ts (100%) rename {lib => types}/v1/result-summary.d.ts (100%) rename {lib => types}/v1/result.d.ts (100%) rename {lib => types}/v1/routing-driver.d.ts (100%) rename {lib => types}/v1/session.d.ts (100%) rename {lib => types}/v1/transaction.d.ts (100%) rename {lib => types}/version.d.ts (100%) diff --git a/package.json b/package.json index 39ae32146..e28238ef1 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "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", @@ -64,9 +65,7 @@ "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0" }, - "typings": "./lib/index.d.ts", "dependencies": { - "@types/node": "^6.0.54", "babel-runtime": "^6.18.0" } } diff --git a/lib/index.d.ts b/types/index.d.ts similarity index 100% rename from lib/index.d.ts rename to types/index.d.ts diff --git a/lib/v1/driver.d.ts b/types/v1/driver.d.ts similarity index 100% rename from lib/v1/driver.d.ts rename to types/v1/driver.d.ts diff --git a/lib/v1/error.d.ts b/types/v1/error.d.ts similarity index 100% rename from lib/v1/error.d.ts rename to types/v1/error.d.ts diff --git a/lib/v1/graph-types.d.ts b/types/v1/graph-types.d.ts similarity index 100% rename from lib/v1/graph-types.d.ts rename to types/v1/graph-types.d.ts diff --git a/lib/v1/index.d.ts b/types/v1/index.d.ts similarity index 100% rename from lib/v1/index.d.ts rename to types/v1/index.d.ts diff --git a/lib/v1/integer.d.ts b/types/v1/integer.d.ts similarity index 100% rename from lib/v1/integer.d.ts rename to types/v1/integer.d.ts diff --git a/lib/v1/internal/connector.d.ts b/types/v1/internal/connector.d.ts similarity index 100% rename from lib/v1/internal/connector.d.ts rename to types/v1/internal/connector.d.ts diff --git a/lib/v1/internal/pool.d.ts b/types/v1/internal/pool.d.ts similarity index 100% rename from lib/v1/internal/pool.d.ts rename to types/v1/internal/pool.d.ts diff --git a/lib/v1/internal/round-robin-array.d.ts b/types/v1/internal/round-robin-array.d.ts similarity index 100% rename from lib/v1/internal/round-robin-array.d.ts rename to types/v1/internal/round-robin-array.d.ts diff --git a/lib/v1/internal/stream-observer.d.ts b/types/v1/internal/stream-observer.d.ts similarity index 100% rename from lib/v1/internal/stream-observer.d.ts rename to types/v1/internal/stream-observer.d.ts diff --git a/lib/v1/record.d.ts b/types/v1/record.d.ts similarity index 100% rename from lib/v1/record.d.ts rename to types/v1/record.d.ts diff --git a/lib/v1/result-summary.d.ts b/types/v1/result-summary.d.ts similarity index 100% rename from lib/v1/result-summary.d.ts rename to types/v1/result-summary.d.ts diff --git a/lib/v1/result.d.ts b/types/v1/result.d.ts similarity index 100% rename from lib/v1/result.d.ts rename to types/v1/result.d.ts diff --git a/lib/v1/routing-driver.d.ts b/types/v1/routing-driver.d.ts similarity index 100% rename from lib/v1/routing-driver.d.ts rename to types/v1/routing-driver.d.ts diff --git a/lib/v1/session.d.ts b/types/v1/session.d.ts similarity index 100% rename from lib/v1/session.d.ts rename to types/v1/session.d.ts diff --git a/lib/v1/transaction.d.ts b/types/v1/transaction.d.ts similarity index 100% rename from lib/v1/transaction.d.ts rename to types/v1/transaction.d.ts diff --git a/lib/version.d.ts b/types/version.d.ts similarity index 100% rename from lib/version.d.ts rename to types/version.d.ts From 0837e5ebabef761f208328d5c050f65075d06d25 Mon Sep 17 00:00:00 2001 From: lutovich Date: Sun, 18 Jun 2017 23:22:39 +0200 Subject: [PATCH 08/18] Some cleanup of type definitions Changes include: * removed definitions for non-public classes and functions * used interfaces as much as possible to define API shapes * added super-interface `StatementRunner` for `Session` and `Transaction` to define signature of `#run()` is one place * added license headers * applied default IntelliJ code formatter --- src/v1/graph-types.js | 2 + src/v1/record.js | 5 +- types/index.d.ts | 22 +++- types/v1/driver.d.ts | 81 +++++++------- types/v1/error.d.ts | 23 +++- types/v1/graph-types.d.ts | 81 ++++++++------ types/v1/index.d.ts | 70 +++++++----- types/v1/integer.d.ts | 89 +++++++++++---- types/v1/internal/connector.d.ts | 41 ------- types/v1/internal/pool.d.ts | 14 --- types/v1/internal/round-robin-array.d.ts | 14 --- types/v1/internal/stream-observer.d.ts | 15 --- types/v1/record.d.ts | 36 ++++-- types/v1/result-summary.d.ts | 133 +++++++++++------------ types/v1/result.d.ts | 48 ++++---- types/v1/routing-driver.d.ts | 59 ---------- types/v1/session.d.ts | 60 +++++----- types/v1/statement-runner.d.ts | 30 +++++ types/v1/transaction.d.ts | 46 ++++---- types/version.d.ts | 3 - 20 files changed, 460 insertions(+), 412 deletions(-) delete mode 100644 types/v1/internal/connector.d.ts delete mode 100644 types/v1/internal/pool.d.ts delete mode 100644 types/v1/internal/round-robin-array.d.ts delete mode 100644 types/v1/internal/stream-observer.d.ts delete mode 100644 types/v1/routing-driver.d.ts create mode 100644 types/v1/statement-runner.d.ts delete mode 100644 types/version.d.ts 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/types/index.d.ts b/types/index.d.ts index 4432d08ad..c7f56413f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,3 +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 {v1} export default v1; diff --git a/types/v1/driver.d.ts b/types/v1/driver.d.ts index ca737a7bb..32ca8e7bd 100644 --- a/types/v1/driver.d.ts +++ b/types/v1/driver.d.ts @@ -1,54 +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 Pool from "./internal/pool"; -import Integer from "./integer"; -import { connect, Connection } from "./internal/connector"; -import StreamObserver from "./internal/stream-observer"; -import { newError, SERVICE_UNAVAILABLE } from "./error"; +import {Parameters} from "./statement-runner"; -interface AuthCredentials { +interface AuthToken { scheme: string; principal: string; credentials: string; realm?: string; - parameters?: { [key: string]: any }; + parameters?: Parameters; } -interface ConfigurationOptions { - encrypted?: string; - trust?: string; - trustedCertificates?: any[]; +type EncryptionLevel = "ENCRYPTION_ON" | "ENCRYPTION_OFF"; +type TrustStrategy = + "TRUST_ALL_CERTIFICATES" | + "TRUST_ON_FIRST_USE" | + "TRUST_SIGNED_CERTIFICATES" | + "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES" | + "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES"; + +interface Config { + encrypted?: boolean | EncryptionLevel; + trust?: TrustStrategy; + trustedCertificates?: string[]; knownHosts?: string; + connectionPoolSize?: number; + maxTransactionRetryTime?: number; } -declare const READ: string; -declare const WRITE: string; - -declare class Driver { - constructor( - url: string, - userAgent: string, - token: AuthCredentials, - config?: ConfigurationOptions - ); - - protected _destroyConnection(conn: Connection): void; - protected _acquireConnection(mode: string): PromiseLike; - protected _createSession(connectionPromise: PromiseLike, cb: Function): Session; - protected _createConnection(url: string, - release: (url: string, conn: Connection) => void - ): Connection; - static _validateConnection(conn: Connection): Boolean - session(mode?: string): Session; - close(): void; -} +type SessionMode = "READ" | "WRITE"; -declare class _ConnectionStreamObserver extends StreamObserver { - constructor(driver: Driver, conn: Connection); +declare const READ: SessionMode; +declare const WRITE: SessionMode; - onError(error: Error): void; - onCompleted(message: any): void; +declare interface Driver { + session(mode?: SessionMode, bookmark?: string): Session; + + close(): void; } -export { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions } +export {Driver, READ, WRITE, AuthToken, Config} export default Driver; diff --git a/types/v1/error.d.ts b/types/v1/error.d.ts index 023585aa0..26e9ba7e2 100644 --- a/types/v1/error.d.ts +++ b/types/v1/error.d.ts @@ -1,7 +1,27 @@ +/** + * 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 function newError(message: any, code?: string): Neo4jError; declare class Neo4jError extends Error { code: string; @@ -15,4 +35,5 @@ export { Neo4jError, SERVICE_UNAVAILABLE, SESSION_EXPIRED, + PROTOCOL_ERROR } diff --git a/types/v1/graph-types.d.ts b/types/v1/graph-types.d.ts index a3ff3b768..3846b3e34 100644 --- a/types/v1/graph-types.d.ts +++ b/types/v1/graph-types.d.ts @@ -1,62 +1,81 @@ +/** + * 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 { - constructor( - identity: string, - labels: string[], - properties: Object - ) + constructor(identity: Integer, + labels: string[], + properties: object) toString(): string; } declare class Relationship { - identity: string; - start: string; - end: string; + identity: Integer; + start: Integer; + end: Integer; type: string; - properties: Object; + properties: object; - constructor( - identity: string, - start: string, - end: string, - type: string, - properties: Object - ); + constructor(identity: Integer, + start: Integer, + end: Integer, + type: string, + properties: object); toString(): string; } declare class UnboundRelationship { - identity: string; + identity: Integer; type: string; - properties: Object; + properties: object; + + constructor(identity: Integer, + type: string, + properties: object); - constructor( - identity: string, - type: string, - properties: Object - ); + bind(start: Integer, end: Integer): Relationship; - bind(start: string, end: string): Relationship; toString(): string; } declare class PathSegment { - start: string; + start: Node; rel: Relationship; - end: string; + end: Node; - constructor( - start: string, - rel: Relationship, - end: string - ); + 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 { diff --git a/types/v1/index.d.ts b/types/v1/index.d.ts index e466c1064..3e5917990 100644 --- a/types/v1/index.d.ts +++ b/types/v1/index.d.ts @@ -1,40 +1,58 @@ -import { int, isInt, inSafeRange, toNumber, toString } from "./integer"; -import { Node, Relationship, UnboundRelationship, PathSegment, Path } from "./graph-types"; -import { Neo4jError, SERVICE_UNAVAILABLE, SESSION_EXPIRED } from "./error"; +/** + * 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 { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions } from "./driver"; -import RoutingDriver from "./routing-driver"; -import VERSION from "../version"; -import { parseScheme, parseUrl } from "./internal/connector"; +import Session from "./session"; +import {AuthToken, Config, Driver, READ, WRITE} from "./driver"; +import Transaction from "./transaction"; declare const auth: { basic: (username: string, - password: string, - realm?: string) => AuthCredentials, + password: string, + realm?: string) => AuthToken, + + kerberos: (base64EncodedTicket: string) => AuthToken, + custom: (principal: string, - credentials: string, - realm: string, - scheme: string, - parameters?: { [key: string]: any }) => AuthCredentials, + credentials: string, + realm: string, + scheme: string, + parameters?: { [key: string]: string }) => AuthToken, }; -declare const USER_AGENT: string; - declare function driver(url: string, - authToken: AuthCredentials, - config?: ConfigurationOptions): Driver; + authToken: AuthToken, + config?: Config): Driver; declare const types: { - Node: typeof Node; + Node: Node; Relationship: typeof Relationship; UnboundRelationship: typeof UnboundRelationship; PathSegment: typeof PathSegment; Path: typeof Path; - Result: typeof Result; - ResultSummary: typeof ResultSummary; + Result: Result; + ResultSummary: ResultSummary; Record: typeof Record; }; @@ -46,6 +64,7 @@ declare const session: { declare const error: { SERVICE_UNAVAILABLE: typeof SERVICE_UNAVAILABLE; SESSION_EXPIRED: typeof SESSION_EXPIRED; + PROTOCOL_ERROR: typeof PROTOCOL_ERROR; }; declare const integer: { @@ -65,9 +84,10 @@ declare const forExport: { session: typeof session; error: typeof error; Driver: Driver; - AuthCredentials: AuthCredentials; - ConfigurationOptions: ConfigurationOptions; + AuthToken: AuthToken; + Config: Config; Session: Session; + Transaction: Transaction; }; export { @@ -80,9 +100,9 @@ export { types, session, error, - AuthCredentials, + AuthToken, Session, - ConfigurationOptions, + Config, } export default forExport; diff --git a/types/v1/integer.d.ts b/types/v1/integer.d.ts index 23bd60c4e..243013b08 100644 --- a/types/v1/integer.d.ts +++ b/types/v1/integer.d.ts @@ -1,53 +1,109 @@ -import { newError } from "./error"; +/** + * 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) + constructor(low?: number, high?: number) inSafeRange(): boolean; + toInt(): number; + toNumber(): number; - toString(): string; + + 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 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(val: Integer | number | string | { low: number, high: number }): Integer; - static toNumber(val: Integer | number | string | { low: number, high: number }): number; - static toString(val: Integer | number | string | { low: number, high: number }, radix?: number): Integer; - static inSafeRange(val: Integer | number | string | { low: number, high: number }): boolean; + + 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; @@ -58,20 +114,15 @@ declare class Integer { static MAX_SAFE_VALUE: Integer; } -declare function int(val: Integer | number | string | { low: number, high: number }): Integer; -declare function isInt(obj: Object): boolean; +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): Integer; -declare const TWO_PWR_16_DBL: number; -declare const TWO_PWR_24_DBL: number; -declare const TWO_PWR_32_DBL: number; -declare const TWO_PWR_64_DBL: number; -declare const TWO_PWR_63_DBL: number; -declare const TWO_PWR_24: Integer; +declare function toNumber(val: Integer | number | string | { low: number, high: number }): number; -declare const INT_CACHE: Object; +declare function toString(val: Integer | number | string | { low: number, high: number }, radix?: number): Integer; export { int, diff --git a/types/v1/internal/connector.d.ts b/types/v1/internal/connector.d.ts deleted file mode 100644 index 04a2f97c4..000000000 --- a/types/v1/internal/connector.d.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { ConfigurationOptions } from "../driver"; - -declare class Connection { - constructor(channel: { write: Function, onMessage: Function }, url: string); - - initialise( - clientName: string, - token: any, - observer: any - ): void; - - run( - statement: any, - params: Object, - observer: any - ): void; - - pullAll(observer: any): void; - discardAll(observer: any): void; - reset(observer: any): void; - sync(): any; - isOpen(): boolean; - isEncrypted(): boolean; - close(cb?: Function): void; - setServerVersion(version: string): void; -} - -declare function connect( - url: string, - config?: ConfigurationOptions -): Connection; - -declare function parseScheme(url: string): string; -declare function parseUrl(url: string): string; - -export { - connect, - Connection, - parseScheme, - parseUrl, -} \ No newline at end of file diff --git a/types/v1/internal/pool.d.ts b/types/v1/internal/pool.d.ts deleted file mode 100644 index c3bf11145..000000000 --- a/types/v1/internal/pool.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -declare class Pool { - constructor( - create: Function, - destroy: Function, - validate: Function, - maxIdle: number - ); - aquire(key: string | number): any; - purge(key: string | number): any; - purgeAll(): void; - has(key: string | number): any; -} - -export default Pool; diff --git a/types/v1/internal/round-robin-array.d.ts b/types/v1/internal/round-robin-array.d.ts deleted file mode 100644 index 78b67e75c..000000000 --- a/types/v1/internal/round-robin-array.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -declare class RoundRobinArray { - constructor(items: any); - - next(): any; - push(elem: any): any; - pushAll(elem: any): any; - empty(): number; - clear(): void; - size(): number; - toArray(): any[]; - remove(item: any): any; -} - -export default RoundRobinArray; diff --git a/types/v1/internal/stream-observer.d.ts b/types/v1/internal/stream-observer.d.ts deleted file mode 100644 index e65fbebdd..000000000 --- a/types/v1/internal/stream-observer.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import ResultSummary from '../result-summary' - -declare type ErrorTransformer = (err: Error) => T; - -export declare interface StreamObserverInterface { - onNext?(record: T): void; - onCompleted?(summary?: ResultSummary): void; - onError?(err: Error): void; -} - -declare class StreamObserver implements StreamObserverInterface { - constructor(errorTransformer: ErrorTransformer); -} - -export default StreamObserver; diff --git a/types/v1/record.d.ts b/types/v1/record.d.ts index bd0648427..8e03680b2 100644 --- a/types/v1/record.d.ts +++ b/types/v1/record.d.ts @@ -1,18 +1,36 @@ -declare function generateFieldLookup(keys: any): any; +/** + * 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 = (field: string, value: T, context: Record) => void; +type Visitor = (value: any, key: string, record: Record) => void; -declare class Record { +declare class Record { keys: string[]; length: number; - _fields: T[]; - constructor(keys: string[], fields: string[], fieldLookup: { [index: string]: string }); + constructor(keys: string[], fields: any[], fieldLookup?: { [index: string]: string }); + + forEach(visitor: Visitor): void; + + toObject(): object; + + get(key: string | number): any; - forEach(visitor: Visitor): void; - toObject(): Partial<{ [ret: string]: T }>; - get(key: K): T[K]; - get(key: number): K; has(key: string | number): boolean; } diff --git a/types/v1/result-summary.d.ts b/types/v1/result-summary.d.ts index 393fa18e3..9e361af77 100644 --- a/types/v1/result-summary.d.ts +++ b/types/v1/result-summary.d.ts @@ -1,102 +1,95 @@ -import Integer, { int, isInt } from "./integer"; - -declare class ResultSummary { - statement: { text: string, parameters: { [index: string]: any } }; +/** + * 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; - //for backwards compatibility, remove in future version - updateStatistics: StatementStatistic; plan: Plan; profile: ProfiledPlan; notifications: Notification[]; server: ServerInfo; - resultConsumedAfter: any | undefined; - resultAvailableAfter: any | undefined; - - constructor(statement: string, parameters?: { [index: string]: any }, metadata?: { [index: string]: any }) + resultConsumedAfter: Integer; + resultAvailableAfter: Integer; - protected _buildNotifications(notifications: any): Notification[]; hasPlan(): boolean; + hasProfile(): boolean; } -declare class Plan { - operatorType: any; - identifiers: any; - arguments: any; +declare interface Plan { + operatorType: string; + identifiers: string[]; + arguments: { [key: string]: string }; children: Plan[]; - constructor(plan: Object) } -declare class ProfiledPlan { - operatorType: any; - identifiers: any; - arguments: any; - dbhits: Integer; - rows: Integer; - children: Plan[]; - constructor(plan: Object) +declare interface ProfiledPlan { + operatorType: string; + identifiers: string[]; + arguments: { [key: string]: string }; + dbHits: number; + rows: number; + children: ProfiledPlan[]; } -interface Statistics { - nodesCreated?: Integer; - nodesDeleted?: Integer; - relationshipsCreated?: Integer; - relationshipsDeleted?: Integer; - propertiesSet?: Integer; - labelsAdded?: Integer; - labelsRemoved?: Integer; - indexesAdded?: Integer; - indexesRemoved?: Integer; - constraintsAdded?: Integer; - constraintsRemoved?: Integer; -} +declare interface StatementStatistic { + containsUpdates(): boolean; -declare class StatementStatistic { - protected _stats: Statistics; + nodesCreated(): number; - constructor(statistics: Statistics); + nodesDeleted(): number; - containsUpdates(): boolean; + relationshipsCreated(): number; - nodesCreated(): Integer; - nodesDeleted(): Integer; - relationshipsCreated(): Integer; - relationshipsDeleted(): Integer; - propertiesSet(): Integer; - labelsAdded(): Integer; - labelsRemoved(): Integer; - indexesAdded(): Integer; - indexesRemoved(): Integer; - constraintsAdded(): Integer; - constraintsRemoved(): Integer; -} + relationshipsDeleted(): number; + + propertiesSet(): number; + + labelsAdded(): number; -declare interface NotificationPosition { - offset: Integer; - line: Integer; - column: Integer; + labelsRemoved(): number; + + indexesAdded(): number; + + indexesRemoved(): number; + + constraintsAdded(): number; + + constraintsRemoved(): number; } -declare interface NotificationStructure { - code: any; +type NotificationPosition = { offset: number; line: number; column: number; } + +declare interface Notification { + code: string; title: string; description: string; severity: string; - position: NotificationPosition; + position: NotificationPosition | {}; } -declare class Notification implements Partial { - constructor(notification: NotificationStructure); - - _constructPosition(pos: NotificationPosition): NotificationPosition; -} - -declare class ServerInfo { +declare interface ServerInfo { address: string; version: string; - - constructor(serverMeta: { address: string, version: string }); } declare const statementType: { @@ -106,6 +99,6 @@ declare const statementType: { SCHEMA_WRITE: "s"; }; -export { statementType } +export {statementType} export default ResultSummary; diff --git a/types/v1/result.d.ts b/types/v1/result.d.ts index 4b0daacb9..82ac5db2f 100644 --- a/types/v1/result.d.ts +++ b/types/v1/result.d.ts @@ -1,30 +1,38 @@ +/** + * 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"; -import StreamObserver, { StreamObserverInterface } from "./internal/stream-observer"; -declare type ResultType = { - records: Array>; +type StatementResult = { + records: Record[]; summary: ResultSummary; } -declare type PromiseResult = PromiseLike> - -declare class Result extends Promise> { - _streamObserver: StreamObserver; - _p: PromiseResult | null; - _statement: string; - _parameters: Params; - _metaSupplier: () => any; - - constructor( - streamObserver: StreamObserver, - statement: string, - parameters?: Params, - metaSupplier?: () => any - ); +type Observer = { + onNext?(record: Record): void; + onCompleted?(summary: ResultSummary): void; + onError?(error: Error): void; +} - protected _createPromise(): PromiseResult; - subscribe(observer: StreamObserverInterface>): void; +declare interface Result extends Promise { + subscribe(observer: Observer): void; } export default Result; diff --git a/types/v1/routing-driver.d.ts b/types/v1/routing-driver.d.ts deleted file mode 100644 index 54c999360..000000000 --- a/types/v1/routing-driver.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -import Session from "./session"; -import { Connection } from './internal/connector'; -import { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions } from "./driver"; -import { newError, SERVICE_UNAVAILABLE, SESSION_EXPIRED } from "./error"; -import RoundRobinArray from "./internal/round-robin-array"; -import Integer, { int } from "./integer"; - -declare class RoutingDriver extends Driver { - _clusterView: ClusterView; - - constructor( - url: string, - userAgent: string, - token: AuthCredentials, - config: ConfigurationOptions - ); - - protected _createSession(connectionPromise: Promise, cb: Function): RoutingSession; - protected _updatedClusterView(): Promise; - protected _diff(oldView: any, updatedView: any): any; - protected _acquireConnection(mode: string): Promise; - protected _forget(url: string): void; - - static _validateConfig(config: ConfigurationOptions): ConfigurationOptions; -} - -declare class ClusterView { - routers: RoundRobinArray; - readers: RoundRobinArray; - writers: RoundRobinArray; - protected _expires: Integer; - - constructor( - routers: RoundRobinArray, - readers: RoundRobinArray, - writers: RoundRobinArray, - expires: Integer - ); - - needsUpdate(): boolean; - all(): Set; - remove(): void; -} - -declare class RoutingSession extends Session { - protected _onFailedConnection: Function; - - constructor( - connectionPromise: Promise, - onClose: Function, - onFailedConnection: Function - ); - - _onRunFailure(): Function; -} - -declare function newClusterView(session: Session): Promise; - -export default RoutingDriver; diff --git a/types/v1/session.d.ts b/types/v1/session.d.ts index e80e1616a..cd0e21511 100644 --- a/types/v1/session.d.ts +++ b/types/v1/session.d.ts @@ -1,35 +1,37 @@ -import { Connection } from './internal/connector' -import StreamObserver from "./internal/stream-observer"; -import Result from "./result"; +/** + * 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 Integer, { int } from "./integer"; -import { newError } from "./error"; - -declare class Session { - _connectionPromise: PromiseLike; - _onClose: Function; - _hasTx: boolean; - - constructor( - connectionPromise: PromiseLike, - onClose: Function - ); - - run(statement: string, parameters?: Params): Result; - run(statement: string): Result; - beginTransaction(bookmark?: any): Transaction; - lastBookmark(): any; - close(cb?: () => void): void; - protected _onRunFailure(): Function; -} +import StatementRunner from "./statement-runner"; + +type TransactionWork = (tx: Transaction) => T | Promise; + +declare interface Session extends StatementRunner { + beginTransaction(): Transaction; + + lastBookmark(): string | null; + + readTransaction(work: TransactionWork): Promise; -declare class _RunObserver extends StreamObserver { - constructor( - onError: Function - ); + writeTransaction(work: TransactionWork): Promise; - onCompleted(meta: Object): void; - meta(): Object; + 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..06eb43e87 --- /dev/null +++ b/types/v1/statement-runner.d.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 Result from "./result"; + +type Parameters = { [key: string]: any }; + +declare interface StatementRunner { + run(statement: string | { text: string, parameters?: Parameters }, parameters?: Parameters): Result; +} + +export {Parameters} + +export default StatementRunner; diff --git a/types/v1/transaction.d.ts b/types/v1/transaction.d.ts index 6f66bd643..33dcf3ac0 100644 --- a/types/v1/transaction.d.ts +++ b/types/v1/transaction.d.ts @@ -1,27 +1,31 @@ -import { Connection } from './internal/connector' -import StreamObserver from "./internal/stream-observer"; +/** + * 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 class Transaction { - constructor( - connectionPromise: PromiseLike, - onClose: Function, - errorTransformer: Function, - bookmark?: any, - onBookmark?: Function - ); +declare interface Transaction extends StatementRunner { + commit(): Result; - run(statement: any, parameters: Params): Result; - run(statement: any): Result; - commit(): Result; - rollback(): Result; - _onError(): void; -} + rollback(): Result; -declare function _runDiscardAll( - msg: any, - connectionPromise: PromiseLike, - observer: StreamObserver -): Result; + isOpen(): boolean; +} export default Transaction; diff --git a/types/version.d.ts b/types/version.d.ts deleted file mode 100644 index 199360e32..000000000 --- a/types/version.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -declare type VERSION = string; - -export default VERSION; From 18997b38e020f67307b962091618232a8b67de36 Mon Sep 17 00:00:00 2001 From: lutovich Date: Mon, 19 Jun 2017 00:00:52 +0200 Subject: [PATCH 09/18] Add simple test for transaction TS definition This commit adds a first simple test for transaction class TypeScript definitions. Actual test code is not executed, it is just compiled using the TypeScript compiler to verify correctness of types. Also added npm script to run TS definition tests `test-types`. More tests will be added in subsequent commits. --- package.json | 2 ++ test/types/tsconfig.json | 14 +++++++++++ test/types/v1/transaction.test.ts | 42 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 test/types/tsconfig.json create mode 100644 test/types/v1/transaction.test.ts diff --git a/package.json b/package.json index e28238ef1..e49f5755c 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "stop-neo4j": "gulp stop-neo4j", "run-stress-tests": "gulp run-stress-tests", "run-tck": "gulp run-tck", + "test-types": "tsc -p ./test/types/tsconfig.json", "docs": "esdoc -c esdoc.json", "versionRelease": "gulp set --version $VERSION && npm version $VERSION --no-git-tag-version" }, @@ -62,6 +63,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/test/types/tsconfig.json b/test/types/tsconfig.json new file mode 100644 index 000000000..bb49661f2 --- /dev/null +++ b/test/types/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "es6", + "target": "es6", + "noImplicitAny": true, + "noImplicitReturns": true, + "strictNullChecks": true, + "outDir": "../../build/test/types" + }, + "include": [ + "v1/*.test.ts", + "../../types/**/*" + ] +} diff --git a/test/types/v1/transaction.test.ts b/test/types/v1/transaction.test.ts new file mode 100644 index 000000000..8c64222e2 --- /dev/null +++ b/test/types/v1/transaction.test.ts @@ -0,0 +1,42 @@ +/** + * 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"; + +const dummy: any = null; + +const tx: Transaction = dummy; + +const isOpen: boolean = tx.isOpen(); +console.log(isOpen); + +const runResult1 = tx.run("RETURN 1"); +runResult1.then(result => { + result.records.forEach(record => { + console.log(record); + }); +}); + +tx.commit().catch(error => { + console.log(error); +}); + +tx.rollback().catch(error => { + console.log(error); +}); From 79285522326d97bd2535349eaff1f42f8ae63947 Mon Sep 17 00:00:00 2001 From: lutovich Date: Mon, 19 Jun 2017 23:29:02 +0200 Subject: [PATCH 10/18] Test error and graph types TS declarations --- test/types/v1/error.test.ts | 30 +++++++++++++++++ test/types/v1/graph-types.test.ts | 53 +++++++++++++++++++++++++++++++ types/v1/error.d.ts | 2 +- types/v1/graph-types.d.ts | 4 +++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 test/types/v1/error.test.ts create mode 100644 test/types/v1/graph-types.test.ts 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/types/v1/error.d.ts b/types/v1/error.d.ts index 26e9ba7e2..84e885236 100644 --- a/types/v1/error.d.ts +++ b/types/v1/error.d.ts @@ -27,7 +27,7 @@ declare class Neo4jError extends Error { code: string; message: string; - constructor(message: any, code: string); + constructor(message: any, code?: string); } export { diff --git a/types/v1/graph-types.d.ts b/types/v1/graph-types.d.ts index 3846b3e34..a551af315 100644 --- a/types/v1/graph-types.d.ts +++ b/types/v1/graph-types.d.ts @@ -20,6 +20,10 @@ import Integer from "./integer"; declare class Node { + identity: Integer; + labels: string[]; + properties: object; + constructor(identity: Integer, labels: string[], properties: object) From 85a570a65cad7b029d82358e7d09d6c7664cd8bc Mon Sep 17 00:00:00 2001 From: lutovich Date: Wed, 21 Jun 2017 00:22:48 +0200 Subject: [PATCH 11/18] Test record TS declarations --- test/types/v1/record.test.ts | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/types/v1/record.test.ts 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"); From 5625f6754beb04e563dbe18997468e14e3091af9 Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 22 Jun 2017 00:26:17 +0200 Subject: [PATCH 12/18] Test integer TS declarations --- test/types/v1/integer.test.ts | 184 ++++++++++++++++++++++++++++++++++ types/v1/integer.d.ts | 2 +- 2 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 test/types/v1/integer.test.ts 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/types/v1/integer.d.ts b/types/v1/integer.d.ts index 243013b08..c686fd0bf 100644 --- a/types/v1/integer.d.ts +++ b/types/v1/integer.d.ts @@ -122,7 +122,7 @@ declare function inSafeRange(val: Integer | number | string | { low: number, hig 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): Integer; +declare function toString(val: Integer | number | string | { low: number, high: number }, radix?: number): string; export { int, From 804a3eac85e575dc2c80f1a5102ce2a5a856ec7f Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 22 Jun 2017 00:32:09 +0200 Subject: [PATCH 13/18] Test result TS declarations --- test/types/v1/result.test.ts | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/types/v1/result.test.ts 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) +}); From 3b1584f41248c82855d0c5576b610c6047593d6a Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 22 Jun 2017 00:51:55 +0200 Subject: [PATCH 14/18] Test result-summary TS declarations --- test/types/v1/result-summary.test.ts | 89 ++++++++++++++++++++++++++++ types/v1/result-summary.d.ts | 2 +- 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 test/types/v1/result-summary.test.ts diff --git a/test/types/v1/result-summary.test.ts b/test/types/v1/result-summary.test.ts new file mode 100644 index 000000000..e23ea85ff --- /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: {} = 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/types/v1/result-summary.d.ts b/types/v1/result-summary.d.ts index 9e361af77..595e66bec 100644 --- a/types/v1/result-summary.d.ts +++ b/types/v1/result-summary.d.ts @@ -99,6 +99,6 @@ declare const statementType: { SCHEMA_WRITE: "s"; }; -export {statementType} +export {statementType, Plan, ProfiledPlan, StatementStatistic, Notification, ServerInfo, NotificationPosition} export default ResultSummary; From 1ed5e0c558c5f3a8c8a848505966514111295d37 Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 22 Jun 2017 01:21:53 +0200 Subject: [PATCH 15/18] Test session TS declarations --- test/types/v1/session.test.ts | 153 ++++++++++++++++++++++++++++++ test/types/v1/transaction.test.ts | 114 ++++++++++++++++++++-- types/v1/result.d.ts | 1 + types/v1/statement-runner.d.ts | 4 +- 4 files changed, 264 insertions(+), 8 deletions(-) create mode 100644 test/types/v1/session.test.ts diff --git a/test/types/v1/session.test.ts b/test/types/v1/session.test.ts new file mode 100644 index 000000000..aa9d161e2 --- /dev/null +++ b/test/types/v1/session.test.ts @@ -0,0 +1,153 @@ +/** + * 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 bookmarkNull: null = session.lastBookmark(); +const bookmark: 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 index 8c64222e2..6629a33be 100644 --- a/test/types/v1/transaction.test.ts +++ b/test/types/v1/transaction.test.ts @@ -18,6 +18,9 @@ */ 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; @@ -26,17 +29,114 @@ const tx: Transaction = dummy; const isOpen: boolean = tx.isOpen(); console.log(isOpen); -const runResult1 = tx.run("RETURN 1"); -runResult1.then(result => { - result.records.forEach(record => { - console.log(record); - }); +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().catch(error => { +tx.commit().then((res: StatementResult) => { + console.log(res); +}).catch((error: Error) => { console.log(error); }); -tx.rollback().catch(error => { +tx.rollback().then((res: StatementResult) => { + console.log(res); +}).catch((error: Error) => { console.log(error); }); diff --git a/types/v1/result.d.ts b/types/v1/result.d.ts index 82ac5db2f..29fd6c689 100644 --- a/types/v1/result.d.ts +++ b/types/v1/result.d.ts @@ -35,4 +35,5 @@ declare interface Result extends Promise { subscribe(observer: Observer): void; } +export {StatementResult, Observer}; export default Result; diff --git a/types/v1/statement-runner.d.ts b/types/v1/statement-runner.d.ts index 06eb43e87..16ea34b7b 100644 --- a/types/v1/statement-runner.d.ts +++ b/types/v1/statement-runner.d.ts @@ -22,7 +22,9 @@ import Result from "./result"; type Parameters = { [key: string]: any }; declare interface StatementRunner { - run(statement: string | { text: string, parameters?: Parameters }, parameters?: Parameters): Result; + run(statement: string, parameters?: Parameters): Result; + + run(statement: { text: string, parameters?: Parameters }): Result; } export {Parameters} From 3b512a3d4fec9d92cf5de2d75551d920d64809df Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 22 Jun 2017 09:55:50 +0200 Subject: [PATCH 16/18] Test driver TS declarations --- test/types/v1/driver.test.ts | 84 ++++++++++++++++++++++++++++ test/types/v1/result-summary.test.ts | 2 +- test/types/v1/session.test.ts | 3 +- types/v1/driver.d.ts | 12 ++-- types/v1/record.d.ts | 2 +- types/v1/result-summary.d.ts | 2 +- types/v1/result.d.ts | 4 +- types/v1/session.d.ts | 2 +- types/v1/statement-runner.d.ts | 2 +- 9 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 test/types/v1/driver.test.ts 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/result-summary.test.ts b/test/types/v1/result-summary.test.ts index e23ea85ff..dd7d553e3 100644 --- a/test/types/v1/result-summary.test.ts +++ b/test/types/v1/result-summary.test.ts @@ -72,7 +72,7 @@ const code: string = notification.code; const title: string = notification.title; const description: string = notification.description; const severity: string = notification.severity; -const position1: {} = notification.position; +const position1: NotificationPosition | {} = notification.position; const position2: NotificationPosition = notification.position; const offset: number = position2.offset; const line: number = position2.line; diff --git a/test/types/v1/session.test.ts b/test/types/v1/session.test.ts index aa9d161e2..2f7d57a3b 100644 --- a/test/types/v1/session.test.ts +++ b/test/types/v1/session.test.ts @@ -28,8 +28,7 @@ const dummy: any = null; const session: Session = dummy; const tx: Transaction = session.beginTransaction(); -const bookmarkNull: null = session.lastBookmark(); -const bookmark: string = session.lastBookmark(); +const bookmark: null | string = session.lastBookmark(); const promise1: Promise = session.readTransaction((tx: Transaction) => { return 10; diff --git a/types/v1/driver.d.ts b/types/v1/driver.d.ts index 32ca8e7bd..c669502f3 100644 --- a/types/v1/driver.d.ts +++ b/types/v1/driver.d.ts @@ -20,7 +20,7 @@ import Session from "./session"; import {Parameters} from "./statement-runner"; -interface AuthToken { +declare interface AuthToken { scheme: string; principal: string; credentials: string; @@ -28,15 +28,15 @@ interface AuthToken { parameters?: Parameters; } -type EncryptionLevel = "ENCRYPTION_ON" | "ENCRYPTION_OFF"; -type TrustStrategy = +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"; -interface Config { +declare interface Config { encrypted?: boolean | EncryptionLevel; trust?: TrustStrategy; trustedCertificates?: string[]; @@ -45,7 +45,7 @@ interface Config { maxTransactionRetryTime?: number; } -type SessionMode = "READ" | "WRITE"; +declare type SessionMode = "READ" | "WRITE"; declare const READ: SessionMode; declare const WRITE: SessionMode; @@ -56,6 +56,6 @@ declare interface Driver { close(): void; } -export {Driver, READ, WRITE, AuthToken, Config} +export {Driver, READ, WRITE, AuthToken, Config, EncryptionLevel, TrustStrategy, SessionMode} export default Driver; diff --git a/types/v1/record.d.ts b/types/v1/record.d.ts index 8e03680b2..be4bb1f41 100644 --- a/types/v1/record.d.ts +++ b/types/v1/record.d.ts @@ -17,7 +17,7 @@ * limitations under the License. */ -type Visitor = (value: any, key: string, record: Record) => void; +declare type Visitor = (value: any, key: string, record: Record) => void; declare class Record { keys: string[]; diff --git a/types/v1/result-summary.d.ts b/types/v1/result-summary.d.ts index 595e66bec..e3164b86e 100644 --- a/types/v1/result-summary.d.ts +++ b/types/v1/result-summary.d.ts @@ -77,7 +77,7 @@ declare interface StatementStatistic { constraintsRemoved(): number; } -type NotificationPosition = { offset: number; line: number; column: number; } +declare type NotificationPosition = { offset: number; line: number; column: number; } declare interface Notification { code: string; diff --git a/types/v1/result.d.ts b/types/v1/result.d.ts index 29fd6c689..a90d4ee5b 100644 --- a/types/v1/result.d.ts +++ b/types/v1/result.d.ts @@ -20,12 +20,12 @@ import ResultSummary from "./result-summary"; import Record from "./record"; -type StatementResult = { +declare type StatementResult = { records: Record[]; summary: ResultSummary; } -type Observer = { +declare type Observer = { onNext?(record: Record): void; onCompleted?(summary: ResultSummary): void; onError?(error: Error): void; diff --git a/types/v1/session.d.ts b/types/v1/session.d.ts index cd0e21511..f6e3e35d5 100644 --- a/types/v1/session.d.ts +++ b/types/v1/session.d.ts @@ -20,7 +20,7 @@ import Transaction from "./transaction"; import StatementRunner from "./statement-runner"; -type TransactionWork = (tx: Transaction) => T | Promise; +declare type TransactionWork = (tx: Transaction) => T | Promise; declare interface Session extends StatementRunner { beginTransaction(): Transaction; diff --git a/types/v1/statement-runner.d.ts b/types/v1/statement-runner.d.ts index 16ea34b7b..76b41397c 100644 --- a/types/v1/statement-runner.d.ts +++ b/types/v1/statement-runner.d.ts @@ -19,7 +19,7 @@ import Result from "./result"; -type Parameters = { [key: string]: any }; +declare type Parameters = { [key: string]: any }; declare interface StatementRunner { run(statement: string, parameters?: Parameters): Result; From 61fde2caa89d0aae56fe6c3a503c62a257249fff Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 22 Jun 2017 14:06:11 +0200 Subject: [PATCH 17/18] Test index TS declarations --- test/types/index.test.ts | 44 +++++++++++++++++++++++++ test/types/v1/index.test.ts | 65 +++++++++++++++++++++++++++++++++++++ types/v1/index.d.ts | 7 ++-- 3 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 test/types/index.test.ts create mode 100644 test/types/v1/index.test.ts 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/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/types/v1/index.d.ts b/types/v1/index.d.ts index 3e5917990..52bd21808 100644 --- a/types/v1/index.d.ts +++ b/types/v1/index.d.ts @@ -26,6 +26,7 @@ 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, @@ -38,15 +39,15 @@ declare const auth: { credentials: string, realm: string, scheme: string, - parameters?: { [key: string]: string }) => AuthToken, + parameters?: Parameters) => AuthToken, }; declare function driver(url: string, - authToken: AuthToken, + authToken?: AuthToken, config?: Config): Driver; declare const types: { - Node: Node; + Node: typeof Node; Relationship: typeof Relationship; UnboundRelationship: typeof UnboundRelationship; PathSegment: typeof PathSegment; From 0a52c198555b00505120d04e8256ce4cbae8fc78 Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 22 Jun 2017 14:35:52 +0200 Subject: [PATCH 18/18] Made gulp run TS declaration tests And updated corresponding npm script: `run-ts-declaration-tests`. It is now part of gulp's `test` task. --- gulpfile.babel.js | 28 ++++++++++++++++++++++++++-- package.json | 3 ++- test/types/tsconfig.json | 14 -------------- 3 files changed, 28 insertions(+), 17 deletions(-) delete mode 100644 test/types/tsconfig.json 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 e49f5755c..e4e289d0e 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "stop-neo4j": "gulp stop-neo4j", "run-stress-tests": "gulp run-stress-tests", "run-tck": "gulp run-tck", - "test-types": "tsc -p ./test/types/tsconfig.json", + "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" }, @@ -49,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", diff --git a/test/types/tsconfig.json b/test/types/tsconfig.json deleted file mode 100644 index bb49661f2..000000000 --- a/test/types/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "compilerOptions": { - "module": "es6", - "target": "es6", - "noImplicitAny": true, - "noImplicitReturns": true, - "strictNullChecks": true, - "outDir": "../../build/test/types" - }, - "include": [ - "v1/*.test.ts", - "../../types/**/*" - ] -}