Skip to content

Commit bd972b6

Browse files
1pxoneArtemiy Vereshchinskiy
authored and
Artemiy Vereshchinskiy
committed
adds optional generic parameter to Node and Relationship
1 parent 57925ef commit bd972b6

File tree

1 file changed

+53
-15
lines changed

1 file changed

+53
-15
lines changed

test/types/graph-types.test.ts

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,54 +32,92 @@ import {
3232
isUnboundRelationship
3333
} from 'neo4j-driver-core'
3434

35-
const node1: Node = new Node(int(1), ['Person', 'Employee'], { name: 'Alice' })
35+
type NodeProperties = { name: string }
36+
type RelationshipProperties = { since: number }
37+
38+
const node1: Node<Integer, NodeProperties> = new Node(
39+
int(1),
40+
['Person', 'Employee'],
41+
{ name: 'Alice' }
42+
)
3643
const node1String: string = node1.toString()
3744
const node1Id: Integer = node1.identity
3845
const node1Labels: string[] = node1.labels
39-
const node1Props: object = node1.properties
46+
const node1Props: NodeProperties = node1.properties
47+
const node1PropertyName: string = node1.properties.name
4048
const isNode1: boolean = node1 instanceof Node
4149
const isNode1B: boolean = isNode(node1)
4250

43-
const node2: Node<number> = new Node(2, ['Person', 'Employee'], {
44-
name: 'Alice'
45-
})
51+
const node2: Node<number, NodeProperties> = new Node(
52+
2,
53+
['Person', 'Employee'],
54+
{
55+
name: 'Alice'
56+
}
57+
)
4658
const node2Id: number = node2.identity
59+
const node2Props: NodeProperties = node2.properties
60+
const node2PropertyName: string = node2.properties.name
4761

48-
const rel1: Relationship = new Relationship(int(1), int(2), int(3), 'KNOWS', {
49-
since: 12345
50-
})
62+
const rel1: Relationship<Integer, RelationshipProperties> = new Relationship(
63+
int(1),
64+
int(2),
65+
int(3),
66+
'KNOWS',
67+
{
68+
since: 12345
69+
}
70+
)
5171
const rel1String: string = rel1.toString()
5272
const rel1Id: Integer = rel1.identity
5373
const rel1Start: Integer = rel1.start
5474
const rel1End: Integer = rel1.end
5575
const rel1Type: string = rel1.type
56-
const rel1Props: object = rel1.properties
76+
const rel1Props: RelationshipProperties = rel1.properties
77+
const rel1PropertySince: number = rel1.properties.since
5778
const isRel1: boolean = rel1 instanceof Relationship
5879
const isRel1B: boolean = isRelationship(rel1)
5980

60-
const rel2: UnboundRelationship = new UnboundRelationship(int(1), 'KNOWS', {
81+
const rel2: UnboundRelationship<
82+
Integer,
83+
RelationshipProperties
84+
> = new UnboundRelationship(int(1), 'KNOWS', {
6185
since: 12345
6286
})
6387
const rel2String: string = rel2.toString()
6488
const rel3: Relationship = rel2.bind(int(1), int(2))
6589
const rel2Id: Integer = rel2.identity
6690
const rel2Type: string = rel2.type
67-
const rel2Props: object = rel2.properties
91+
const rel2Props: RelationshipProperties = rel2.properties
92+
const rel2PropertySince: number = rel2.properties.since
6893
const isRel2: boolean = rel2 instanceof UnboundRelationship
6994
const isRel2B: boolean = isUnboundRelationship(rel2)
7095

71-
const rel4: Relationship<number> = new Relationship(2, 3, 4, 'KNOWS', {
72-
since: 12345
73-
})
96+
const rel4: Relationship<number, RelationshipProperties> = new Relationship(
97+
2,
98+
3,
99+
4,
100+
'KNOWS',
101+
{
102+
since: 12345
103+
}
104+
)
74105
const rel4Id: number = rel4.identity
75106
const rel4Start: number = rel4.start
76107
const rel4End: number = rel4.end
77108
const isRel4: boolean = rel4 instanceof Relationship
109+
const rel4Props: RelationshipProperties = rel4.properties
110+
const rel4PropertySince: number = rel4.properties.since
78111

79-
const rel5: UnboundRelationship<number> = new UnboundRelationship(5, 'KNOWS', {
112+
const rel5: UnboundRelationship<
113+
number,
114+
RelationshipProperties
115+
> = new UnboundRelationship(5, 'KNOWS', {
80116
since: 12345
81117
})
82118
const rel5Id: number = rel5.identity
119+
const rel5Props: RelationshipProperties = rel5.properties
120+
const rel5PropertySince: number = rel5.properties.since
83121
const rel6 = rel5.bind(24, 42)
84122
const rel6Id: number = rel6.identity
85123
const rel6Start: number = rel6.start

0 commit comments

Comments
 (0)