Skip to content

Started Adding Type Definitions #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as v1 from "./v1/index";
export { v1 }
export default v1;
54 changes: 54 additions & 0 deletions lib/v1/driver.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 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<Connection>;
protected _createSession(connectionPromise: PromiseLike<Connection>, 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;
}

declare class _ConnectionStreamObserver<T> extends StreamObserver<T> {
constructor(driver: Driver, conn: Connection);

onError(error: Error): void;
onCompleted(message: any): void;
}

export { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions }

export default Driver;
18 changes: 18 additions & 0 deletions lib/v1/error.d.ts
Original file line number Diff line number Diff line change
@@ -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,
}
68 changes: 68 additions & 0 deletions lib/v1/graph-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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
}
88 changes: 88 additions & 0 deletions lib/v1/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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 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";

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;
Driver: Driver;
AuthCredentials: AuthCredentials;
ConfigurationOptions: ConfigurationOptions;
Session: Session;
};

export {
driver,
int,
isInt,
integer,
Neo4jError,
auth,
types,
session,
error,
AuthCredentials,
Session,
ConfigurationOptions,
}

export default forExport;
84 changes: 84 additions & 0 deletions lib/v1/integer.d.ts
Original file line number Diff line number Diff line change
@@ -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;
41 changes: 41 additions & 0 deletions lib/v1/internal/connector.d.ts
Original file line number Diff line number Diff line change
@@ -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,
}
14 changes: 14 additions & 0 deletions lib/v1/internal/pool.d.ts
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 14 additions & 0 deletions lib/v1/internal/round-robin-array.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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;
Loading