Skip to content

Commit a07e2d2

Browse files
committed
Add TS declaration for driver callbacks
Commit adds `Driver.onCompleted` and `Driver.onError` callbacks to the TypeScript declaration.
1 parent 238f73e commit a07e2d2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

test/types/v1/driver.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Driver, {
2828
} from "../../../types/v1/driver";
2929
import {Parameters} from "../../../types/v1/statement-runner";
3030
import Session from "../../../types/v1/session";
31+
import {Neo4jError} from "../../../types/v1/error";
3132

3233
const dummy: any = null;
3334

@@ -82,3 +83,15 @@ session1.run("RETURN 1").then(result => {
8283
});
8384

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

types/v1/driver.d.ts

Lines changed: 4 additions & 0 deletions
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;
@@ -54,6 +55,9 @@ declare interface Driver {
5455
session(mode?: SessionMode, bookmark?: string): Session;
5556

5657
close(): void;
58+
59+
onCompleted?: (metadata: { server: string }) => void;
60+
onError?: (error: Neo4jError) => void;
5761
}
5862

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

0 commit comments

Comments
 (0)