Skip to content

Commit 496a968

Browse files
authored
Merge pull request #279 from lutovich/1.4-driver-callbacks-ts
Add TS declaration for driver callbacks
2 parents 6b5d6f2 + a07e2d2 commit 496a968

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

test/types/v1/driver.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Driver, {
2929
} from "../../../types/v1/driver";
3030
import {Parameters} from "../../../types/v1/statement-runner";
3131
import Session from "../../../types/v1/session";
32+
import {Neo4jError} from "../../../types/v1/error";
3233

3334
const dummy: any = null;
3435

@@ -85,3 +86,15 @@ session1.run("RETURN 1").then(result => {
8586
});
8687

8788
const close: void = driver.close();
89+
90+
driver.onCompleted = (metadata: { server: string }) => {
91+
console.log(metadata.server);
92+
};
93+
94+
driver.onCompleted({server: "Neo4j/3.2.0"});
95+
96+
driver.onError = (error: Neo4jError) => {
97+
console.log(error);
98+
};
99+
100+
driver.onError(new Neo4jError("message", "code"));

types/v1/driver.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import Session from "./session";
2121
import {Parameters} from "./statement-runner";
22+
import {Neo4jError} from "./error";
2223

2324
declare interface AuthToken {
2425
scheme: string;
@@ -57,6 +58,9 @@ declare interface Driver {
5758
session(mode?: SessionMode, bookmark?: string): Session;
5859

5960
close(): void;
61+
62+
onCompleted?: (metadata: { server: string }) => void;
63+
onError?: (error: Neo4jError) => void;
6064
}
6165

6266
export {Driver, READ, WRITE, AuthToken, Config, EncryptionLevel, TrustStrategy, LoadBalancingStrategy, SessionMode}

0 commit comments

Comments
 (0)