Skip to content

Commit 80de7e8

Browse files
committed
Test driver TS declarations
1 parent 84adaad commit 80de7e8

File tree

9 files changed

+98
-15
lines changed

9 files changed

+98
-15
lines changed

test/types/v1/driver.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 Driver, {
21+
AuthToken,
22+
Config,
23+
EncryptionLevel,
24+
READ,
25+
SessionMode,
26+
TrustStrategy,
27+
WRITE
28+
} from "../../../types/v1/driver";
29+
import {Parameters} from "../../../types/v1/statement-runner";
30+
import Session from "../../../types/v1/session";
31+
32+
const dummy: any = null;
33+
34+
const authToken: AuthToken = dummy;
35+
const scheme: string = authToken.scheme;
36+
const principal: string = authToken.principal;
37+
const credentials: string = authToken.credentials;
38+
const realm1: undefined = <undefined>authToken.realm;
39+
const realm2: string = <string>authToken.realm;
40+
const parameters1: undefined = <undefined>authToken.parameters;
41+
const parameters2: { [key: string]: any } = <{ [key: string]: any }>authToken.parameters;
42+
const parameters3: Parameters = <Parameters>authToken.parameters;
43+
44+
const encryptionLevel: EncryptionLevel = dummy;
45+
const encryptionLevelStr: string = encryptionLevel;
46+
47+
const trustStrategy: TrustStrategy = dummy;
48+
const trustStrategyStr: string = trustStrategy;
49+
50+
const config: Config = dummy;
51+
const encrypted: undefined | boolean | EncryptionLevel = config.encrypted;
52+
const trust: undefined | TrustStrategy = config.trust;
53+
const trustedCertificates: undefined | string[] = config.trustedCertificates;
54+
const knownHosts: undefined | string = config.knownHosts;
55+
const connectionPoolSize: undefined | number = config.connectionPoolSize;
56+
const maxTransactionRetryTime: undefined | number = config.maxTransactionRetryTime;
57+
58+
const sessionMode: SessionMode = dummy;
59+
const sessionModeStr: string = sessionMode;
60+
61+
const readMode1: SessionMode = READ;
62+
const readMode2: string = READ;
63+
64+
const writeMode1: SessionMode = WRITE;
65+
const writeMode2: string = WRITE;
66+
67+
const driver: Driver = dummy;
68+
69+
const session1: Session = driver.session();
70+
const session2: Session = driver.session("READ");
71+
const session3: Session = driver.session(READ);
72+
const session4: Session = driver.session("WRITE");
73+
const session5: Session = driver.session(WRITE);
74+
const session6: Session = driver.session(READ, "bookmark1");
75+
const session7: Session = driver.session(WRITE, "bookmark2");
76+
77+
session1.run("RETURN 1").then(result => {
78+
session1.close();
79+
result.records.forEach(record => {
80+
console.log(record);
81+
});
82+
});
83+
84+
const close: void = driver.close();

test/types/v1/result-summary.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const code: string = notification.code;
7272
const title: string = notification.title;
7373
const description: string = notification.description;
7474
const severity: string = notification.severity;
75-
const position1: {} = notification.position;
75+
const position1: NotificationPosition | {} = notification.position;
7676
const position2: NotificationPosition = <NotificationPosition>notification.position;
7777
const offset: number = position2.offset;
7878
const line: number = position2.line;

test/types/v1/session.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ const dummy: any = null;
2828
const session: Session = dummy;
2929

3030
const tx: Transaction = session.beginTransaction();
31-
const bookmarkNull: null = <null>session.lastBookmark();
32-
const bookmark: string = <string>session.lastBookmark();
31+
const bookmark: null | string = <null>session.lastBookmark();
3332

3433
const promise1: Promise<number> = session.readTransaction((tx: Transaction) => {
3534
return 10;

types/v1/driver.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@
2020
import Session from "./session";
2121
import {Parameters} from "./statement-runner";
2222

23-
interface AuthToken {
23+
declare interface AuthToken {
2424
scheme: string;
2525
principal: string;
2626
credentials: string;
2727
realm?: string;
2828
parameters?: Parameters;
2929
}
3030

31-
type EncryptionLevel = "ENCRYPTION_ON" | "ENCRYPTION_OFF";
32-
type TrustStrategy =
31+
declare type EncryptionLevel = "ENCRYPTION_ON" | "ENCRYPTION_OFF";
32+
declare type TrustStrategy =
3333
"TRUST_ALL_CERTIFICATES" |
3434
"TRUST_ON_FIRST_USE" |
3535
"TRUST_SIGNED_CERTIFICATES" |
3636
"TRUST_CUSTOM_CA_SIGNED_CERTIFICATES" |
3737
"TRUST_SYSTEM_CA_SIGNED_CERTIFICATES";
3838

39-
interface Config {
39+
declare interface Config {
4040
encrypted?: boolean | EncryptionLevel;
4141
trust?: TrustStrategy;
4242
trustedCertificates?: string[];
@@ -45,7 +45,7 @@ interface Config {
4545
maxTransactionRetryTime?: number;
4646
}
4747

48-
type SessionMode = "READ" | "WRITE";
48+
declare type SessionMode = "READ" | "WRITE";
4949

5050
declare const READ: SessionMode;
5151
declare const WRITE: SessionMode;
@@ -56,6 +56,6 @@ declare interface Driver {
5656
close(): void;
5757
}
5858

59-
export {Driver, READ, WRITE, AuthToken, Config}
59+
export {Driver, READ, WRITE, AuthToken, Config, EncryptionLevel, TrustStrategy, SessionMode}
6060

6161
export default Driver;

types/v1/record.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20-
type Visitor = (value: any, key: string, record: Record) => void;
20+
declare type Visitor = (value: any, key: string, record: Record) => void;
2121

2222
declare class Record {
2323
keys: string[];

types/v1/result-summary.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ declare interface StatementStatistic {
7777
constraintsRemoved(): number;
7878
}
7979

80-
type NotificationPosition = { offset: number; line: number; column: number; }
80+
declare type NotificationPosition = { offset: number; line: number; column: number; }
8181

8282
declare interface Notification {
8383
code: string;

types/v1/result.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import ResultSummary from "./result-summary";
2121
import Record from "./record";
2222

23-
type StatementResult = {
23+
declare type StatementResult = {
2424
records: Record[];
2525
summary: ResultSummary;
2626
}
2727

28-
type Observer = {
28+
declare type Observer = {
2929
onNext?(record: Record): void;
3030
onCompleted?(summary: ResultSummary): void;
3131
onError?(error: Error): void;

types/v1/session.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import Transaction from "./transaction";
2121
import StatementRunner from "./statement-runner";
2222

23-
type TransactionWork<T> = (tx: Transaction) => T | Promise<T>;
23+
declare type TransactionWork<T> = (tx: Transaction) => T | Promise<T>;
2424

2525
declare interface Session extends StatementRunner {
2626
beginTransaction(): Transaction;

types/v1/statement-runner.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import Result from "./result";
2121

22-
type Parameters = { [key: string]: any };
22+
declare type Parameters = { [key: string]: any };
2323

2424
declare interface StatementRunner {
2525
run(statement: string, parameters?: Parameters): Result;

0 commit comments

Comments
 (0)