Skip to content

Commit 29c5116

Browse files
authored
Export isNode, isRelationship, isPath, isPathSegment and isUnboundedRelationship function (#1040)
This functions were not exposed before. Exposing these functions give more power to the user introspect the values in the records. Example: ```typescript import neo4j from 'neo4j-driver' neo4j.isNode({}) // should return false neo4j.graph.isNode({}) // should return false ```
1 parent 02f024e commit 29c5116

File tree

7 files changed

+335
-3
lines changed

7 files changed

+335
-3
lines changed

packages/neo4j-driver-deno/lib/mod.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ import {
4040
isDuration,
4141
isLocalDateTime,
4242
isLocalTime,
43+
isNode,
44+
isPath,
45+
isPathSegment,
46+
isRelationship,
4347
isTime,
48+
isUnboundRelationship,
4449
LocalDateTime,
4550
LocalTime,
4651
Time,
@@ -413,6 +418,17 @@ const temporal = {
413418
isDateTime
414419
}
415420

421+
/**
422+
* Object containing functions to work with graph types, like {@link Node} or {@link Relationship}.
423+
*/
424+
const graph = {
425+
isNode,
426+
isPath,
427+
isPathSegment,
428+
isRelationship,
429+
isUnboundRelationship
430+
}
431+
416432
/**
417433
* @private
418434
*/
@@ -428,6 +444,11 @@ const forExport = {
428444
isDate,
429445
isLocalDateTime,
430446
isDateTime,
447+
isNode,
448+
isPath,
449+
isPathSegment,
450+
isRelationship,
451+
isUnboundRelationship,
431452
integer,
432453
Neo4jError,
433454
isRetriableError,
@@ -436,6 +457,7 @@ const forExport = {
436457
types,
437458
session,
438459
error,
460+
graph,
439461
spatial,
440462
temporal,
441463
Driver,
@@ -481,6 +503,11 @@ export {
481503
isDate,
482504
isLocalDateTime,
483505
isDateTime,
506+
isNode,
507+
isPath,
508+
isPathSegment,
509+
isRelationship,
510+
isUnboundRelationship,
484511
integer,
485512
Neo4jError,
486513
isRetriableError,
@@ -489,6 +516,7 @@ export {
489516
types,
490517
session,
491518
error,
519+
graph,
492520
spatial,
493521
temporal,
494522
Driver,

packages/neo4j-driver-lite/src/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ import {
4040
isDuration,
4141
isLocalDateTime,
4242
isLocalTime,
43+
isNode,
44+
isPath,
45+
isPathSegment,
46+
isRelationship,
4347
isTime,
48+
isUnboundRelationship,
4449
LocalDateTime,
4550
LocalTime,
4651
Time,
@@ -412,6 +417,17 @@ const temporal = {
412417
isDateTime
413418
}
414419

420+
/**
421+
* Object containing functions to work with graph types, like {@link Node} or {@link Relationship}.
422+
*/
423+
const graph = {
424+
isNode,
425+
isPath,
426+
isPathSegment,
427+
isRelationship,
428+
isUnboundRelationship
429+
}
430+
415431
/**
416432
* @private
417433
*/
@@ -427,6 +443,11 @@ const forExport = {
427443
isDate,
428444
isLocalDateTime,
429445
isDateTime,
446+
isNode,
447+
isPath,
448+
isPathSegment,
449+
isRelationship,
450+
isUnboundRelationship,
430451
integer,
431452
Neo4jError,
432453
isRetriableError,
@@ -435,6 +456,7 @@ const forExport = {
435456
types,
436457
session,
437458
error,
459+
graph,
438460
spatial,
439461
temporal,
440462
Driver,
@@ -480,6 +502,11 @@ export {
480502
isDate,
481503
isLocalDateTime,
482504
isDateTime,
505+
isNode,
506+
isPath,
507+
isPathSegment,
508+
isRelationship,
509+
isUnboundRelationship,
483510
integer,
484511
Neo4jError,
485512
isRetriableError,
@@ -488,6 +515,7 @@ export {
488515
types,
489516
session,
490517
error,
518+
graph,
491519
spatial,
492520
temporal,
493521
Driver,

packages/neo4j-driver-lite/test/unit/index.test.ts

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ import neo4j, {
5050
Date,
5151
LocalDateTime,
5252
DateTime,
53-
BookmarkManager
53+
BookmarkManager,
54+
graph,
55+
isNode,
56+
isRelationship,
57+
isPath,
58+
isPathSegment,
59+
isUnboundRelationship
5460
} from '../../'
5561

5662
describe('index', () => {
@@ -301,4 +307,100 @@ describe('index', () => {
301307
const date: DateTime<number> = new DateTime(1, 2, 3, 3, 5, 6, 6, 5)
302308
expect(date).toBeDefined()
303309
})
310+
311+
it('should export isNode', () => {
312+
const node = new Node(int(123), ['abc'], [1])
313+
314+
expect(isNode(node)).toBe(true)
315+
})
316+
317+
it('should export graph.isNode', () => {
318+
const node = new Node(int(123), ['abc'], [1])
319+
320+
expect(graph.isNode(node)).toBe(true)
321+
})
322+
323+
it('should export isRelationship', () => {
324+
const rel = new Relationship(
325+
int(123),
326+
int(1),
327+
int(1),
328+
'rel',
329+
{}
330+
)
331+
332+
expect(isRelationship(rel)).toBe(true)
333+
})
334+
335+
it('should export graph.isRelationship', () => {
336+
const rel = new Relationship(
337+
int(123),
338+
int(1),
339+
int(1),
340+
'rel',
341+
{}
342+
)
343+
344+
expect(graph.isRelationship(rel)).toBe(true)
345+
})
346+
347+
it('should export isUnboundRelationship', () => {
348+
const rel = new UnboundRelationship(
349+
int(123),
350+
'rel',
351+
{}
352+
)
353+
354+
expect(isUnboundRelationship(rel)).toBe(true)
355+
})
356+
357+
it('should export graph.isUnboundRelationship', () => {
358+
const rel = new UnboundRelationship(
359+
int(123),
360+
'rel',
361+
{}
362+
)
363+
364+
expect(graph.isUnboundRelationship(rel)).toBe(true)
365+
})
366+
367+
it('should export isPath', () => {
368+
const path = new Path(
369+
new Node(int(1), ['a'], ['1']),
370+
new Node(int(1), ['a'], ['1']),
371+
[]
372+
)
373+
374+
expect(isPath(path)).toBe(true)
375+
})
376+
377+
it('should export graph.isPath', () => {
378+
const path = new Path(
379+
new Node(int(1), ['a'], ['1']),
380+
new Node(int(1), ['a'], ['1']),
381+
[]
382+
)
383+
384+
expect(graph.isPath(path)).toBe(true)
385+
})
386+
387+
it('should export isPathSegment', () => {
388+
const pathSeg = new PathSegment(
389+
new Node(int(1), ['a'], ['1']),
390+
new Relationship(int(123), int(1), int(1), 'rel', {}),
391+
new Node(int(1), ['a'], ['1'])
392+
)
393+
394+
expect(isPathSegment(pathSeg)).toBe(true)
395+
})
396+
397+
it('should export graph.isPath', () => {
398+
const pathSeg = new PathSegment(
399+
new Node(int(1), ['a'], ['1']),
400+
new Relationship(int(123), int(1), int(1), 'rel', {}),
401+
new Node(int(1), ['a'], ['1'])
402+
)
403+
404+
expect(graph.isPathSegment(pathSeg)).toBe(true)
405+
})
304406
})

packages/neo4j-driver/src/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ import {
4040
isDuration,
4141
isLocalDateTime,
4242
isLocalTime,
43+
isNode,
44+
isPath,
45+
isPathSegment,
46+
isRelationship,
4347
isTime,
48+
isUnboundRelationship,
4449
LocalDateTime,
4550
LocalTime,
4651
Time,
@@ -401,6 +406,17 @@ const temporal = {
401406
isDateTime
402407
}
403408

409+
/**
410+
* Object containing functions to work with graph types, like {@link Node} or {@link Relationship}.
411+
*/
412+
const graph = {
413+
isNode,
414+
isPath,
415+
isPathSegment,
416+
isRelationship,
417+
isUnboundRelationship
418+
}
419+
404420
/**
405421
* @private
406422
*/
@@ -416,6 +432,11 @@ const forExport = {
416432
isDate,
417433
isLocalDateTime,
418434
isDateTime,
435+
isNode,
436+
isPath,
437+
isPathSegment,
438+
isRelationship,
439+
isUnboundRelationship,
419440
integer,
420441
Neo4jError,
421442
isRetryableError,
@@ -424,6 +445,7 @@ const forExport = {
424445
types,
425446
session,
426447
error,
448+
graph,
427449
spatial,
428450
temporal,
429451
Driver,
@@ -470,6 +492,11 @@ export {
470492
isDate,
471493
isLocalDateTime,
472494
isDateTime,
495+
isNode,
496+
isPath,
497+
isPathSegment,
498+
isRelationship,
499+
isUnboundRelationship,
473500
integer,
474501
Neo4jError,
475502
isRetryableError,
@@ -478,6 +505,7 @@ export {
478505
types,
479506
session,
480507
error,
508+
graph,
481509
spatial,
482510
temporal,
483511
Driver,

0 commit comments

Comments
 (0)