Skip to content

Commit 57925ef

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

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

core/src/graph-types.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { stringify } from './json'
2121

2222
type StandardDate = Date
2323
type NumberOrInteger = number | Integer | bigint
24+
type Properties = { [key: string]: any }
2425

2526
const IDENTIFIER_PROPERTY_ATTRIBUTES = {
2627
value: true,
@@ -43,18 +44,18 @@ function hasIdentifierProperty(obj: any, property: string): boolean {
4344
/**
4445
* Class for Node Type.
4546
*/
46-
class Node<T extends NumberOrInteger = Integer> {
47+
class Node<T extends NumberOrInteger = Integer, P extends Properties = Properties> {
4748
identity: T
4849
labels: string[]
49-
properties: any
50+
properties: P
5051
/**
5152
* @constructor
5253
* @protected
5354
* @param {Integer|number} identity - Unique identity
5455
* @param {Array<string>} labels - Array for all labels
55-
* @param {Object} properties - Map with node properties
56+
* @param {Properties} properties - Map with node properties
5657
*/
57-
constructor(identity: T, labels: string[], properties: any) {
58+
constructor(identity: T, labels: string[], properties: P) {
5859
/**
5960
* Identity of the node.
6061
* @type {Integer|number}
@@ -67,7 +68,7 @@ class Node<T extends NumberOrInteger = Integer> {
6768
this.labels = labels
6869
/**
6970
* Properties of the node.
70-
* @type {Object}
71+
* @type {Properties}
7172
*/
7273
this.properties = properties
7374
}
@@ -112,12 +113,12 @@ function isNode(obj: object): boolean {
112113
/**
113114
* Class for Relationship Type.
114115
*/
115-
class Relationship<T extends NumberOrInteger = Integer> {
116+
class Relationship<T extends NumberOrInteger = Integer, P extends Properties = Properties> {
116117
identity: T
117118
start: T
118119
end: T
119120
type: string
120-
properties: any
121+
properties: P
121122

122123
/**
123124
* @constructor
@@ -126,9 +127,9 @@ class Relationship<T extends NumberOrInteger = Integer> {
126127
* @param {Integer|number} start - Identity of start Node
127128
* @param {Integer|number} end - Identity of end Node
128129
* @param {string} type - Relationship type
129-
* @param {Object} properties - Map with relationship properties
130+
* @param {Properties} properties - Map with relationship properties
130131
*/
131-
constructor(identity: T, start: T, end: T, type: string, properties: any) {
132+
constructor(identity: T, start: T, end: T, type: string, properties: P) {
132133
/**
133134
* Identity of the relationship.
134135
* @type {Integer|number}
@@ -151,7 +152,7 @@ class Relationship<T extends NumberOrInteger = Integer> {
151152
this.type = type
152153
/**
153154
* Properties of the relationship.
154-
* @type {Object}
155+
* @type {Properties}
155156
*/
156157
this.properties = properties
157158
}
@@ -194,17 +195,17 @@ function isRelationship(obj: object): boolean {
194195
* Class for UnboundRelationship Type.
195196
* @access private
196197
*/
197-
class UnboundRelationship<T extends NumberOrInteger = Integer> {
198+
class UnboundRelationship<T extends NumberOrInteger = Integer, P extends Properties = Properties> {
198199
identity: T
199200
type: string
200-
properties: any
201+
properties: P
201202

202203
/**
203204
* @constructor
204205
* @protected
205206
* @param {Integer|number} identity - Unique identity
206207
* @param {string} type - Relationship type
207-
* @param {Object} properties - Map with relationship properties
208+
* @param {Properties} properties - Map with relationship properties
208209
*/
209210
constructor(identity: T, type: string, properties: any) {
210211
/**
@@ -219,7 +220,7 @@ class UnboundRelationship<T extends NumberOrInteger = Integer> {
219220
this.type = type
220221
/**
221222
* Properties of the relationship.
222-
* @type {Object}
223+
* @type {Properties}
223224
*/
224225
this.properties = properties
225226
}

0 commit comments

Comments
 (0)