Skip to content

Commit 0837e5e

Browse files
committed
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
1 parent c901500 commit 0837e5e

20 files changed

+460
-412
lines changed

src/v1/graph-types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* limitations under the License.
1818
*/
1919

20+
import Integer from './integer';
21+
2022
/**
2123
* Class for Node Type.
2224
*/

src/v1/record.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ class Record {
4949
* Create a new record object.
5050
* @constructor
5151
* @access private
52-
* @param {Object} keys An array of field keys, in the order the fields appear
53-
* in the record
54-
* @param {Object} fields An array of field values
52+
* @param {string[]} keys An array of field keys, in the order the fields appear in the record
53+
* @param {Array} fields An array of field values
5554
* @param {Object} fieldLookup An object of fieldName -> value index, used to map
5655
* field names to values. If this is null, one will be
5756
* generated.

types/index.d.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/**
2+
* Copyright (c) 2002-2017 "Neo Technology,","
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
120
import * as v1 from "./v1/index";
2-
export { v1 }
21+
22+
export {v1}
323
export default v1;

types/v1/driver.d.ts

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,61 @@
1+
/**
2+
* Copyright (c) 2002-2017 "Neo Technology,","
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
120
import Session from "./session";
2-
import Pool from "./internal/pool";
3-
import Integer from "./integer";
4-
import { connect, Connection } from "./internal/connector";
5-
import StreamObserver from "./internal/stream-observer";
6-
import { newError, SERVICE_UNAVAILABLE } from "./error";
21+
import {Parameters} from "./statement-runner";
722

8-
interface AuthCredentials {
23+
interface AuthToken {
924
scheme: string;
1025
principal: string;
1126
credentials: string;
1227
realm?: string;
13-
parameters?: { [key: string]: any };
28+
parameters?: Parameters;
1429
}
1530

16-
interface ConfigurationOptions {
17-
encrypted?: string;
18-
trust?: string;
19-
trustedCertificates?: any[];
31+
type EncryptionLevel = "ENCRYPTION_ON" | "ENCRYPTION_OFF";
32+
type TrustStrategy =
33+
"TRUST_ALL_CERTIFICATES" |
34+
"TRUST_ON_FIRST_USE" |
35+
"TRUST_SIGNED_CERTIFICATES" |
36+
"TRUST_CUSTOM_CA_SIGNED_CERTIFICATES" |
37+
"TRUST_SYSTEM_CA_SIGNED_CERTIFICATES";
38+
39+
interface Config {
40+
encrypted?: boolean | EncryptionLevel;
41+
trust?: TrustStrategy;
42+
trustedCertificates?: string[];
2043
knownHosts?: string;
44+
connectionPoolSize?: number;
45+
maxTransactionRetryTime?: number;
2146
}
2247

23-
declare const READ: string;
24-
declare const WRITE: string;
25-
26-
declare class Driver {
27-
constructor(
28-
url: string,
29-
userAgent: string,
30-
token: AuthCredentials,
31-
config?: ConfigurationOptions
32-
);
33-
34-
protected _destroyConnection(conn: Connection): void;
35-
protected _acquireConnection(mode: string): PromiseLike<Connection>;
36-
protected _createSession(connectionPromise: PromiseLike<Connection>, cb: Function): Session;
37-
protected _createConnection(url: string,
38-
release: (url: string, conn: Connection) => void
39-
): Connection;
40-
static _validateConnection(conn: Connection): Boolean
41-
session(mode?: string): Session;
42-
close(): void;
43-
}
48+
type SessionMode = "READ" | "WRITE";
4449

45-
declare class _ConnectionStreamObserver<T> extends StreamObserver<T> {
46-
constructor(driver: Driver, conn: Connection);
50+
declare const READ: SessionMode;
51+
declare const WRITE: SessionMode;
4752

48-
onError(error: Error): void;
49-
onCompleted(message: any): void;
53+
declare interface Driver {
54+
session(mode?: SessionMode, bookmark?: string): Session;
55+
56+
close(): void;
5057
}
5158

52-
export { Driver, READ, WRITE, AuthCredentials, ConfigurationOptions }
59+
export {Driver, READ, WRITE, AuthToken, Config}
5360

5461
export default Driver;

types/v1/error.d.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1+
/**
2+
* Copyright (c) 2002-2017 "Neo Technology,","
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
120
declare const SERVICE_UNAVAILABLE: string;
221
declare const SESSION_EXPIRED: string;
22+
declare const PROTOCOL_ERROR: string;
323

4-
declare function newError(message: any, code: string): Neo4jError;
24+
declare function newError(message: any, code?: string): Neo4jError;
525

626
declare class Neo4jError extends Error {
727
code: string;
@@ -15,4 +35,5 @@ export {
1535
Neo4jError,
1636
SERVICE_UNAVAILABLE,
1737
SESSION_EXPIRED,
38+
PROTOCOL_ERROR
1839
}

types/v1/graph-types.d.ts

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,81 @@
1+
/**
2+
* Copyright (c) 2002-2017 "Neo Technology,","
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import Integer from "./integer";
21+
122
declare class Node {
2-
constructor(
3-
identity: string,
4-
labels: string[],
5-
properties: Object
6-
)
23+
constructor(identity: Integer,
24+
labels: string[],
25+
properties: object)
726

827
toString(): string;
928
}
1029

1130
declare class Relationship {
12-
identity: string;
13-
start: string;
14-
end: string;
31+
identity: Integer;
32+
start: Integer;
33+
end: Integer;
1534
type: string;
16-
properties: Object;
35+
properties: object;
1736

18-
constructor(
19-
identity: string,
20-
start: string,
21-
end: string,
22-
type: string,
23-
properties: Object
24-
);
37+
constructor(identity: Integer,
38+
start: Integer,
39+
end: Integer,
40+
type: string,
41+
properties: object);
2542

2643
toString(): string;
2744
}
2845

2946
declare class UnboundRelationship {
30-
identity: string;
47+
identity: Integer;
3148
type: string;
32-
properties: Object;
49+
properties: object;
50+
51+
constructor(identity: Integer,
52+
type: string,
53+
properties: object);
3354

34-
constructor(
35-
identity: string,
36-
type: string,
37-
properties: Object
38-
);
55+
bind(start: Integer, end: Integer): Relationship;
3956

40-
bind(start: string, end: string): Relationship;
4157
toString(): string;
4258
}
4359

4460
declare class PathSegment {
45-
start: string;
61+
start: Node;
4662
rel: Relationship;
47-
end: string;
63+
end: Node;
4864

49-
constructor(
50-
start: string,
51-
rel: Relationship,
52-
end: string
53-
);
65+
constructor(start: Node,
66+
rel: Relationship,
67+
end: Node);
5468
}
5569

5670
declare class Path {
5771
start: Node;
5872
end: Node;
5973
segments: PathSegment[];
74+
length: number;
75+
76+
constructor(start: Node,
77+
end: Node,
78+
segments: PathSegment[]);
6079
}
6180

6281
export {

0 commit comments

Comments
 (0)