diff --git a/core/src/graph-types.ts b/core/src/graph-types.ts index 1526caac1..f40a3de69 100644 --- a/core/src/graph-types.ts +++ b/core/src/graph-types.ts @@ -21,6 +21,7 @@ import { stringify } from './json' type StandardDate = Date type NumberOrInteger = number | Integer | bigint +type Properties = { [key: string]: any } const IDENTIFIER_PROPERTY_ATTRIBUTES = { value: true, @@ -43,18 +44,18 @@ function hasIdentifierProperty(obj: any, property: string): boolean { /** * Class for Node Type. */ -class Node { +class Node { identity: T labels: string[] - properties: any + properties: P /** * @constructor * @protected * @param {Integer|number} identity - Unique identity * @param {Array} labels - Array for all labels - * @param {Object} properties - Map with node properties + * @param {Properties} properties - Map with node properties */ - constructor(identity: T, labels: string[], properties: any) { + constructor(identity: T, labels: string[], properties: P) { /** * Identity of the node. * @type {Integer|number} @@ -67,7 +68,7 @@ class Node { this.labels = labels /** * Properties of the node. - * @type {Object} + * @type {Properties} */ this.properties = properties } @@ -112,12 +113,12 @@ function isNode(obj: object): boolean { /** * Class for Relationship Type. */ -class Relationship { +class Relationship { identity: T start: T end: T type: string - properties: any + properties: P /** * @constructor @@ -126,9 +127,9 @@ class Relationship { * @param {Integer|number} start - Identity of start Node * @param {Integer|number} end - Identity of end Node * @param {string} type - Relationship type - * @param {Object} properties - Map with relationship properties + * @param {Properties} properties - Map with relationship properties */ - constructor(identity: T, start: T, end: T, type: string, properties: any) { + constructor(identity: T, start: T, end: T, type: string, properties: P) { /** * Identity of the relationship. * @type {Integer|number} @@ -151,7 +152,7 @@ class Relationship { this.type = type /** * Properties of the relationship. - * @type {Object} + * @type {Properties} */ this.properties = properties } @@ -194,17 +195,17 @@ function isRelationship(obj: object): boolean { * Class for UnboundRelationship Type. * @access private */ -class UnboundRelationship { +class UnboundRelationship { identity: T type: string - properties: any + properties: P /** * @constructor * @protected * @param {Integer|number} identity - Unique identity * @param {string} type - Relationship type - * @param {Object} properties - Map with relationship properties + * @param {Properties} properties - Map with relationship properties */ constructor(identity: T, type: string, properties: any) { /** @@ -219,7 +220,7 @@ class UnboundRelationship { this.type = type /** * Properties of the relationship. - * @type {Object} + * @type {Properties} */ this.properties = properties } diff --git a/test/types/graph-types.test.ts b/test/types/graph-types.test.ts index 78e64899d..bebf0e10f 100644 --- a/test/types/graph-types.test.ts +++ b/test/types/graph-types.test.ts @@ -45,6 +45,13 @@ const node2: Node = new Node(2, ['Person', 'Employee'], { }) const node2Id: number = node2.identity +type NodeProps = { name: string } +const node3: Node = new Node(2, ['Person', 'Employee'], { + name: 'Alice' +}) +const node3Props: NodeProps = node3.properties +const node3PropertyName: string = node3.properties.name + const rel1: Relationship = new Relationship(int(1), int(2), int(3), 'KNOWS', { since: 12345 }) @@ -86,6 +93,28 @@ const rel6Start: number = rel6.start const rel6End: number = rel6.end const isRel6: boolean = rel6 instanceof UnboundRelationship +type RelationshipProps = { since: number } +const rel7: Relationship = new Relationship( + 2, + 3, + 4, + 'KNOWS', + { + since: 12345 + } +) +const rel7Props: RelationshipProps = rel7.properties +const rel7PropertySince: number = rel7.properties.since + +const rel8: UnboundRelationship< + number, + RelationshipProps +> = new UnboundRelationship(5, 'KNOWS', { + since: 12345 +}) +const rel8Props: RelationshipProps = rel8.properties +const rel8PropertySince: number = rel8.properties.since + const pathSegment1: PathSegment = new PathSegment(node1, rel1, node1) const pathSegment1Start: Node = pathSegment1.start const pathSegment1Rel: Relationship = pathSegment1.relationship