Skip to content

Commit 92f0f87

Browse files
committed
Export isNode, isRelationship, isPath, isPathSegment and isUnboundedRelationship function (neo4j#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 55b45ce commit 92f0f87

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,
@@ -428,6 +433,17 @@ const temporal = {
428433
isDateTime
429434
}
430435

436+
/**
437+
* Object containing functions to work with graph types, like {@link Node} or {@link Relationship}.
438+
*/
439+
const graph = {
440+
isNode,
441+
isPath,
442+
isPathSegment,
443+
isRelationship,
444+
isUnboundRelationship
445+
}
446+
431447
/**
432448
* @private
433449
*/
@@ -443,6 +459,11 @@ const forExport = {
443459
isDate,
444460
isLocalDateTime,
445461
isDateTime,
462+
isNode,
463+
isPath,
464+
isPathSegment,
465+
isRelationship,
466+
isUnboundRelationship,
446467
integer,
447468
Neo4jError,
448469
isRetriableError,
@@ -451,6 +472,7 @@ const forExport = {
451472
types,
452473
session,
453474
error,
475+
graph,
454476
spatial,
455477
temporal,
456478
Driver,
@@ -496,6 +518,11 @@ export {
496518
isDate,
497519
isLocalDateTime,
498520
isDateTime,
521+
isNode,
522+
isPath,
523+
isPathSegment,
524+
isRelationship,
525+
isUnboundRelationship,
499526
integer,
500527
Neo4jError,
501528
isRetriableError,
@@ -504,6 +531,7 @@ export {
504531
types,
505532
session,
506533
error,
534+
graph,
507535
spatial,
508536
temporal,
509537
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)