From eee0d2ad9fbf8c8402dbb344c647321d39cf1a63 Mon Sep 17 00:00:00 2001 From: Tim Hope Date: Fri, 30 Dec 2016 02:35:30 +1100 Subject: [PATCH 1/6] 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 c205d570e..77b66ea17 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,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 a2259c35a..ac9bc8545 100644 --- a/src/v1/index.js +++ b/src/v1/index.js @@ -165,6 +165,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 2c8252c90fb874d471009b9a0a1bbcb9dab0efab Mon Sep 17 00:00:00 2001 From: Tim Hope Date: Fri, 30 Dec 2016 03:02:39 +1100 Subject: [PATCH 2/6] 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 ac9bc8545..a2259c35a 100644 --- a/src/v1/index.js +++ b/src/v1/index.js @@ -165,6 +165,6 @@ export { auth, types, session, - error, + error } export default forExport From ef8b1ddc0ef29a1a1ec3b366a475333eb84a2f5f Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Fri, 3 Feb 2017 11:10:56 -0200 Subject: [PATCH 3/6] 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 77b66ea17..d2d845fea 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,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 df1613f4b1e7b713518324d6a648daf7fa1e2e0a Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Sun, 5 Feb 2017 15:39:12 -0300 Subject: [PATCH 4/6] 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 f2874034a46497c4082485551bfb1ecd1de06292 Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Sun, 5 Feb 2017 15:43:49 -0300 Subject: [PATCH 5/6] 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 d576571a64b747ee46c676848f19a5600f767ba5 Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Sun, 5 Feb 2017 17:59:07 -0200 Subject: [PATCH 6/6] 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;