1717 * limitations under the License.
1818 */
1919
20+ const IDENTIFIER_PROPERTY_ATTRIBUTES = {
21+ value : true ,
22+ enumerable : false ,
23+ configurable : false ,
24+ writable : false
25+ }
26+
27+ const NODE_IDENTIFIER_PROPERTY = '__isNode__'
28+ const RELATIONSHIP_IDENTIFIER_PROPERTY = '__isRelationship__'
29+ const UNBOUND_RELATIONSHIP_IDENTIFIER_PROPERTY = '__isUnboundRelationship__'
30+ const PATH_IDENTIFIER_PROPERTY = '__isPath__'
31+ const PATH_SEGMENT_IDENTIFIER_PROPERTY = '__isPathSegment__'
32+
33+ function hasIdentifierProperty ( obj , property ) {
34+ return ( obj && obj [ property ] ) === true
35+ }
36+
2037/**
2138 * Class for Node Type.
2239 */
@@ -54,7 +71,7 @@ class Node {
5471 for ( let i = 0 ; i < this . labels . length ; i ++ ) {
5572 s += ':' + this . labels [ i ]
5673 }
57- let keys = Object . keys ( this . properties )
74+ const keys = Object . keys ( this . properties )
5875 if ( keys . length > 0 ) {
5976 s += ' {'
6077 for ( let i = 0 ; i < keys . length ; i ++ ) {
@@ -68,6 +85,21 @@ class Node {
6885 }
6986}
7087
88+ Object . defineProperty (
89+ Node . prototype ,
90+ NODE_IDENTIFIER_PROPERTY ,
91+ IDENTIFIER_PROPERTY_ATTRIBUTES
92+ )
93+
94+ /**
95+ * Test if given object is an instance of {@link Node} class.
96+ * @param {Object } obj the object to test.
97+ * @return {boolean } `true` if given object is a {@link Node}, `false` otherwise.
98+ */
99+ function isNode ( obj ) {
100+ return hasIdentifierProperty ( obj , NODE_IDENTIFIER_PROPERTY )
101+ }
102+
71103/**
72104 * Class for Relationship Type.
73105 */
@@ -114,7 +146,7 @@ class Relationship {
114146 */
115147 toString ( ) {
116148 let s = '(' + this . start + ')-[:' + this . type
117- let keys = Object . keys ( this . properties )
149+ const keys = Object . keys ( this . properties )
118150 if ( keys . length > 0 ) {
119151 s += ' {'
120152 for ( let i = 0 ; i < keys . length ; i ++ ) {
@@ -128,6 +160,21 @@ class Relationship {
128160 }
129161}
130162
163+ Object . defineProperty (
164+ Relationship . prototype ,
165+ RELATIONSHIP_IDENTIFIER_PROPERTY ,
166+ IDENTIFIER_PROPERTY_ATTRIBUTES
167+ )
168+
169+ /**
170+ * Test if given object is an instance of {@link Relationship} class.
171+ * @param {Object } obj the object to test.
172+ * @return {boolean } `true` if given object is a {@link Relationship}, `false` otherwise.
173+ */
174+ function isRelationship ( obj ) {
175+ return hasIdentifierProperty ( obj , RELATIONSHIP_IDENTIFIER_PROPERTY )
176+ }
177+
131178/**
132179 * Class for UnboundRelationship Type.
133180 * @access private
@@ -181,7 +228,7 @@ class UnboundRelationship {
181228 */
182229 toString ( ) {
183230 let s = '-[:' + this . type
184- let keys = Object . keys ( this . properties )
231+ const keys = Object . keys ( this . properties )
185232 if ( keys . length > 0 ) {
186233 s += ' {'
187234 for ( let i = 0 ; i < keys . length ; i ++ ) {
@@ -195,6 +242,21 @@ class UnboundRelationship {
195242 }
196243}
197244
245+ Object . defineProperty (
246+ UnboundRelationship . prototype ,
247+ UNBOUND_RELATIONSHIP_IDENTIFIER_PROPERTY ,
248+ IDENTIFIER_PROPERTY_ATTRIBUTES
249+ )
250+
251+ /**
252+ * Test if given object is an instance of {@link UnboundRelationship} class.
253+ * @param {Object } obj the object to test.
254+ * @return {boolean } `true` if given object is a {@link UnboundRelationship}, `false` otherwise.
255+ */
256+ function isUnboundRelationship ( obj ) {
257+ return hasIdentifierProperty ( obj , UNBOUNT_RELATIONSHIP_IDENTIFIER_PROPERTY )
258+ }
259+
198260/**
199261 * Class for PathSegment Type.
200262 */
@@ -225,6 +287,21 @@ class PathSegment {
225287 }
226288}
227289
290+ Object . defineProperty (
291+ PathSegment . prototype ,
292+ PATH_SEGMENT_IDENTIFIER_PROPERTY ,
293+ IDENTIFIER_PROPERTY_ATTRIBUTES
294+ )
295+
296+ /**
297+ * Test if given object is an instance of {@link PathSegment} class.
298+ * @param {Object } obj the object to test.
299+ * @return {boolean } `true` if given object is a {@link PathSegment}, `false` otherwise.
300+ */
301+ function isPathSegment ( obj ) {
302+ return hasIdentifierProperty ( obj , PATH_SEGMENT_IDENTIFIER_PROPERTY )
303+ }
304+
228305/**
229306 * Class for Path Type.
230307 */
@@ -260,4 +337,30 @@ class Path {
260337 }
261338}
262339
263- export { Node , Relationship , UnboundRelationship , Path , PathSegment }
340+ Object . defineProperty (
341+ Path . prototype ,
342+ PATH_IDENTIFIER_PROPERTY ,
343+ IDENTIFIER_PROPERTY_ATTRIBUTES
344+ )
345+
346+ /**
347+ * Test if given object is an instance of {@link Path} class.
348+ * @param {Object } obj the object to test.
349+ * @return {boolean } `true` if given object is a {@link Path}, `false` otherwise.
350+ */
351+ function isPath ( obj ) {
352+ return hasIdentifierProperty ( obj , PATH_IDENTIFIER_PROPERTY )
353+ }
354+
355+ export {
356+ Node ,
357+ isNode ,
358+ Relationship ,
359+ isRelationship ,
360+ UnboundRelationship ,
361+ isUnboundRelationship ,
362+ Path ,
363+ isPath ,
364+ PathSegment ,
365+ isPathSegment
366+ }
0 commit comments