Skip to content

Commit 8edd2f6

Browse files
committed
TS declarations support for 'disableLosslessIntegers=true'
Previously TS declaration files only allowed returned integer types to be `neo4j.Integer`. This was not compatible with newly introduced `disableLosslessIntegers` config, which makes driver always return native JS numbers. This commit allows all integer properties to either be `neo4j.Integer` or `number`. `Integer` is default. Existing TS users will not need to change their code. TS users who set 'disableLosslessIntegers=true' will have to specify generic type explicitly like `Node<number>`. Property `identity` of such node will have type `number`.
1 parent bd075b7 commit 8edd2f6

File tree

4 files changed

+77
-51
lines changed

4 files changed

+77
-51
lines changed

test/types/v1/graph-types.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const node1Id: Integer = node1.identity;
2626
const node1Labels: string[] = node1.labels;
2727
const node1Props: object = node1.properties;
2828

29+
const node2: Node<number> = new Node(2, ["Person", "Employee"], {name: "Alice"});
30+
const node2Id: number = node2.identity;
31+
2932
const rel1: Relationship = new Relationship(int(1), int(2), int(3), "KNOWS", {since: 12345});
3033
const rel1String: string = rel1.toString();
3134
const rel1Id: Integer = rel1.identity;
@@ -41,13 +44,35 @@ const rel2Id: Integer = rel2.identity;
4144
const rel2Type: string = rel2.type;
4245
const rel2Props: object = rel2.properties;
4346

47+
const rel4: Relationship<number> = new Relationship(2, 3, 4, "KNOWS", {since: 12345});
48+
const rel4Id: number = rel4.identity;
49+
const rel4Start: number = rel4.start;
50+
const rel4End: number = rel4.end;
51+
52+
const rel5: UnboundRelationship<number> = new UnboundRelationship(5, "KNOWS", {since: 12345});
53+
const rel5Id: number = rel5.identity;
54+
const rel6 = rel5.bind(24, 42);
55+
const rel6Id: number = rel6.identity;
56+
const rel6Start: number = rel6.start;
57+
const rel6End: number = rel6.end;
58+
4459
const pathSegment1: PathSegment = new PathSegment(node1, rel1, node1);
4560
const pathSegment1Start: Node = pathSegment1.start;
4661
const pathSegment1Rel: Relationship = pathSegment1.relationship;
4762
const pathSegment1End: Node = pathSegment1.end;
4863

64+
const pathSegment2: PathSegment<number> = new PathSegment(node2, rel4, node2);
65+
const pathSegment2Start: Node<number> = pathSegment2.start;
66+
const pathSegment2Rel: Relationship<number> = pathSegment2.relationship;
67+
const pathSegment2End: Node<number> = pathSegment2.end;
68+
4969
const path1: Path = new Path(node1, node1, [pathSegment1]);
5070
const path1Start: Node = path1.start;
5171
const path1End: Node = path1.end;
5272
const path1Segments: PathSegment[] = path1.segments;
5373
const path1Length: number = path1.length;
74+
75+
const path2: Path<number> = new Path(node2, node2, [pathSegment2]);
76+
const path2Start: Node<number> = path2.start;
77+
const path2End: Node<number> = path2.end;
78+
const path2Segments: PathSegment<number>[] = path2.segments;

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

+21-20
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,20 @@
1717
* limitations under the License.
1818
*/
1919

20-
import ResultSummary, {
21-
Notification,
22-
NotificationPosition,
23-
Plan,
24-
ProfiledPlan,
25-
ServerInfo,
26-
StatementStatistic
27-
} from "../../../types/v1/result-summary";
20+
import ResultSummary, {Notification, NotificationPosition, Plan, ProfiledPlan, ServerInfo, StatementStatistic} from "../../../types/v1/result-summary";
2821
import Integer from "../../../types/v1/integer";
2922

3023
const dummy: any = null;
3124

32-
const sum: ResultSummary = dummy;
25+
const sum1: ResultSummary = dummy;
3326

34-
const stmt = sum.statement;
27+
const stmt = sum1.statement;
3528
const stmtText: string = stmt.text;
3629
const stmtParams: object = stmt.parameters;
3730

38-
const str: string = sum.statementType;
31+
const str: string = sum1.statementType;
3932

40-
const counters: StatementStatistic = sum.counters;
33+
const counters: StatementStatistic = sum1.counters;
4134

4235
const containsUpdates: boolean = counters.containsUpdates();
4336
const nodesCreated: number = counters.nodesCreated();
@@ -52,21 +45,21 @@ const indexesRemoved: number = counters.indexesRemoved();
5245
const constraintsAdded: number = counters.constraintsAdded();
5346
const constraintsRemoved: number = counters.constraintsRemoved();
5447

55-
const plan: Plan = sum.plan;
48+
const plan: Plan = sum1.plan;
5649
const planOperatorType: string = plan.operatorType;
5750
const planIdentifiers: string[] = plan.identifiers;
5851
const planArguments: { [key: string]: string } = plan.arguments;
5952
const planChildren: Plan[] = plan.children;
6053

61-
const profile: ProfiledPlan = sum.profile;
54+
const profile: ProfiledPlan = sum1.profile;
6255
const profileOperatorType: string = profile.operatorType;
6356
const profileIdentifiers: string[] = profile.identifiers;
6457
const profileArguments: { [key: string]: string } = profile.arguments;
6558
const profileDbHits: number = profile.dbHits;
6659
const profileRows: number = profile.rows;
6760
const profileChildren: ProfiledPlan[] = profile.children;
6861

69-
const notifications: Notification[] = sum.notifications;
62+
const notifications: Notification[] = sum1.notifications;
7063
const notification: Notification = notifications[0];
7164
const code: string = notification.code;
7265
const title: string = notification.title;
@@ -78,12 +71,20 @@ const offset: number = position2.offset;
7871
const line: number = position2.line;
7972
const column: number = position2.column;
8073

81-
const server: ServerInfo = sum.server;
74+
const server: ServerInfo = sum1.server;
8275
const address: string = server.address;
8376
const version: string = server.version;
8477

85-
const resultConsumedAfter: Integer = sum.resultConsumedAfter;
86-
const resultAvailableAfter: Integer = sum.resultAvailableAfter;
78+
const resultConsumedAfter1: Integer = sum1.resultConsumedAfter;
79+
const resultAvailableAfter1: Integer = sum1.resultAvailableAfter;
8780

88-
const hasPlan: boolean = sum.hasPlan();
89-
const hasProfile: boolean = sum.hasProfile();
81+
const hasPlan: boolean = sum1.hasPlan();
82+
const hasProfile: boolean = sum1.hasProfile();
83+
84+
const sum2: ResultSummary<number> = dummy;
85+
const resultConsumedAfter2: number = sum2.resultConsumedAfter;
86+
const resultAvailableAfter2: number = sum2.resultAvailableAfter;
87+
88+
const sum3: ResultSummary<Integer> = dummy;
89+
const resultConsumedAfter3: Integer = sum3.resultConsumedAfter;
90+
const resultAvailableAfter3: Integer = sum3.resultAvailableAfter;

types/v1/graph-types.d.ts

+28-28
Original file line numberDiff line numberDiff line change
@@ -19,67 +19,67 @@
1919

2020
import Integer from "./integer";
2121

22-
declare class Node {
23-
identity: Integer;
22+
declare class Node<T extends (Integer | number) = Integer> {
23+
identity: T;
2424
labels: string[];
2525
properties: object;
2626

27-
constructor(identity: Integer,
27+
constructor(identity: T,
2828
labels: string[],
2929
properties: object)
3030

3131
toString(): string;
3232
}
3333

34-
declare class Relationship {
35-
identity: Integer;
36-
start: Integer;
37-
end: Integer;
34+
declare class Relationship<T extends (Integer | number) = Integer> {
35+
identity: T;
36+
start: T;
37+
end: T;
3838
type: string;
3939
properties: object;
4040

41-
constructor(identity: Integer,
42-
start: Integer,
43-
end: Integer,
41+
constructor(identity: T,
42+
start: T,
43+
end: T,
4444
type: string,
4545
properties: object);
4646

4747
toString(): string;
4848
}
4949

50-
declare class UnboundRelationship {
51-
identity: Integer;
50+
declare class UnboundRelationship<T extends (Integer | number) = Integer> {
51+
identity: T;
5252
type: string;
5353
properties: object;
5454

55-
constructor(identity: Integer,
55+
constructor(identity: T,
5656
type: string,
5757
properties: object);
5858

59-
bind(start: Integer, end: Integer): Relationship;
59+
bind(start: T, end: T): Relationship<T>;
6060

6161
toString(): string;
6262
}
6363

64-
declare class PathSegment {
65-
start: Node;
66-
relationship: Relationship;
67-
end: Node;
64+
declare class PathSegment<T extends (Integer | number) = Integer> {
65+
start: Node<T>;
66+
relationship: Relationship<T>;
67+
end: Node<T>;
6868

69-
constructor(start: Node,
70-
rel: Relationship,
71-
end: Node);
69+
constructor(start: Node<T>,
70+
rel: Relationship<T>,
71+
end: Node<T>);
7272
}
7373

74-
declare class Path {
75-
start: Node;
76-
end: Node;
77-
segments: PathSegment[];
74+
declare class Path<T extends (Integer | number) = Integer> {
75+
start: Node<T>;
76+
end: Node<T>;
77+
segments: PathSegment<T>[];
7878
length: number;
7979

80-
constructor(start: Node,
81-
end: Node,
82-
segments: PathSegment[]);
80+
constructor(start: Node<T>,
81+
end: Node<T>,
82+
segments: PathSegment<T>[]);
8383
}
8484

8585
export {

types/v1/result-summary.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919

2020
import Integer from "./integer";
2121

22-
declare interface ResultSummary {
22+
declare interface ResultSummary<T extends (Integer | number) = Integer> {
2323
statement: { text: string, parameters: { [key: string]: any } };
2424
statementType: string;
2525
counters: StatementStatistic;
2626
plan: Plan;
2727
profile: ProfiledPlan;
2828
notifications: Notification[];
2929
server: ServerInfo;
30-
resultConsumedAfter: Integer;
31-
resultAvailableAfter: Integer;
30+
resultConsumedAfter: T;
31+
resultAvailableAfter: T;
3232

3333
hasPlan(): boolean;
3434

0 commit comments

Comments
 (0)