Skip to content

Commit 7cce621

Browse files
committed
Fix TypeScript exports for classes
They were previously exported in a way that did not allow user code to create instances using `new`. For example: ```typescript const date = new neo4j.types.Date(1, 2, 3); ``` did not compile. Added tests for all types exported from `neo4j.types` object.
1 parent 0d259a1 commit 7cce621

File tree

2 files changed

+80
-24
lines changed

2 files changed

+80
-24
lines changed

test/types/index.test.ts

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,83 @@
1818
*/
1919

2020
import neo4j from "../../types/index";
21-
import {Driver} from "../../types/v1/driver";
22-
import Integer from "../../types/v1/integer";
23-
import {Neo4jError} from "../../types/v1/error";
2421

25-
const driver1: Driver = neo4j.driver("bolt+routing://localhost");
26-
const driver2: Driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "password"));
22+
const driver1: neo4j.Driver = neo4j.driver("bolt+routing://localhost");
23+
const driver2: neo4j.Driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "password"));
24+
25+
const sessionModeRead: string = neo4j.session.READ;
26+
const sessionModeWrite: string = neo4j.session.WRITE;
2727

2828
const readSession = driver1.session(neo4j.session.READ);
2929
const writeSession = driver1.session(neo4j.session.WRITE);
3030

31-
const int1: Integer = neo4j.int(42);
32-
const int2: Integer = neo4j.int("42");
33-
const int3: Integer = neo4j.int(neo4j.int(42));
34-
const int4: Integer = neo4j.int({low: 1, high: 1});
31+
const int1: neo4j.Integer = neo4j.int(42);
32+
const int2: neo4j.Integer = neo4j.int("42");
33+
const int3: neo4j.Integer = neo4j.int(neo4j.int(42));
34+
const int4: neo4j.Integer = neo4j.int({low: 1, high: 1});
3535

3636
const isInt1: boolean = neo4j.isInt({});
3737
const isInt2: boolean = neo4j.isInt(neo4j.int("42"));
3838

39+
const toNumber1: number = neo4j.integer.toNumber(1);
40+
const toNumber2: number = neo4j.integer.toNumber("1");
41+
const toNumber3: number = neo4j.integer.toNumber({high: 0, low: 0});
42+
const toNumber4: number = neo4j.integer.toNumber(int1);
43+
44+
const toString1: string = neo4j.integer.toString(1);
45+
const toString2: string = neo4j.integer.toString("1");
46+
const toString3: string = neo4j.integer.toString({high: 0, low: 0});
47+
const toString4: string = neo4j.integer.toString(int1);
48+
49+
const inSafeRange1: boolean = neo4j.integer.inSafeRange(1);
50+
const inSafeRange2: boolean = neo4j.integer.inSafeRange("1");
51+
const inSafeRange3: boolean = neo4j.integer.inSafeRange({high: 0, low: 0});
52+
const inSafeRange4: boolean = neo4j.integer.inSafeRange(int1);
53+
54+
const isPoint1: boolean = neo4j.spatial.isPoint({});
55+
const isPoint2: boolean = neo4j.isPoint({});
56+
57+
const isDuration1: boolean = neo4j.temporal.isDuration({});
58+
const isDuration2: boolean = neo4j.isDuration({});
59+
60+
const isLocalTime1: boolean = neo4j.temporal.isLocalTime({});
61+
const isLocalTime2: boolean = neo4j.isLocalTime({});
62+
63+
const isTime1: boolean = neo4j.temporal.isTime({});
64+
const isTime2: boolean = neo4j.isTime({});
65+
66+
const isDate1: boolean = neo4j.temporal.isDate({});
67+
const isDate2: boolean = neo4j.isDate({});
68+
69+
const isLocalDateTime1: boolean = neo4j.temporal.isLocalDateTime({});
70+
const isLocalDateTime2: boolean = neo4j.isLocalDateTime({});
71+
72+
const isDateTime1: boolean = neo4j.temporal.isDateTime({});
73+
const isDateTime2: boolean = neo4j.isDateTime({});
74+
3975
const serviceUnavailable: string = neo4j.error.SERVICE_UNAVAILABLE;
4076
const sessionExpired: string = neo4j.error.SESSION_EXPIRED;
4177
const protocolError: string = neo4j.error.PROTOCOL_ERROR;
4278

43-
const error1: Neo4jError = new neo4j.Neo4jError("Error message");
44-
const error2: Neo4jError = new neo4j.Neo4jError("Error message", "Error code");
79+
const error1: neo4j.Neo4jError = new neo4j.Neo4jError("Error message");
80+
const error2: neo4j.Neo4jError = new neo4j.Neo4jError("Error message", "Error code");
81+
82+
const node: neo4j.Node = new neo4j.types.Node(int1, [], {});
83+
const relationship: neo4j.Relationship = new neo4j.types.Relationship(int1, int1, int1, "", {});
84+
const unboundRelationship: neo4j.UnboundRelationship = new neo4j.types.UnboundRelationship(int1, "", {});
85+
const pathSegment: neo4j.PathSegment = new neo4j.types.PathSegment(node, relationship, node);
86+
const path: neo4j.Path = new neo4j.types.Path(node, node, []);
87+
const result: neo4j.Result = readSession.run("");
88+
89+
result.then(value => {
90+
const resultSummary: neo4j.ResultSummary = value.summary;
91+
});
92+
93+
const record: neo4j.Record = new neo4j.types.Record([], [], {});
94+
const point: neo4j.Point = new neo4j.types.Point(int1, 1, 2, 3);
95+
const duration: neo4j.Duration = new neo4j.types.Duration(int1, int1, int1, int1);
96+
const localTime: neo4j.LocalTime = new neo4j.types.LocalTime(int1, int1, int1, int1);
97+
const time: neo4j.Time = new neo4j.types.Time(int1, int1, int1, int1, int1);
98+
const date: neo4j.Date = new neo4j.types.Date(int1, int1, int1);
99+
const localDateTime: neo4j.LocalDateTime = new neo4j.types.LocalDateTime(int1, int1, int1, int1, int1, int1, int1);
100+
const dateTime: neo4j.DateTime = new neo4j.types.DateTime(int1, int1, int1, int1, int1, int1, int1, int1);

types/v1/index.d.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ declare function driver(url: string,
4949
config?: Config): Driver;
5050

5151
declare const types: {
52-
Node: Node;
53-
Relationship: Relationship;
54-
UnboundRelationship: UnboundRelationship;
55-
PathSegment: PathSegment;
56-
Path: Path;
52+
Node: typeof Node;
53+
Relationship: typeof Relationship;
54+
UnboundRelationship: typeof UnboundRelationship;
55+
PathSegment: typeof PathSegment;
56+
Path: typeof Path;
5757
Result: Result;
5858
ResultSummary: ResultSummary;
59-
Record: Record;
60-
Point: Point;
61-
Duration: Duration;
62-
LocalTime: LocalTime;
63-
Time: Time;
64-
Date: Date;
65-
LocalDateTime: LocalDateTime;
66-
DateTime: DateTime;
59+
Record: typeof Record;
60+
Point: typeof Point;
61+
Duration: typeof Duration;
62+
LocalTime: typeof LocalTime;
63+
Time: typeof Time;
64+
Date: typeof Date;
65+
LocalDateTime: typeof LocalDateTime;
66+
DateTime: typeof DateTime;
6767
};
6868

6969
declare const session: {

0 commit comments

Comments
 (0)