@@ -25,16 +25,15 @@ import {
2525 safetlyRemoveObjectProp ,
2626 safetlyAddObjectProp ,
2727 escapeReservedProps ,
28- unEscapeReservedProps ,
29- hasReservedProp
28+ unEscapeReservedProps
3029} from '../utils'
3130
3231export const reservedTypePropertyName = 'transport-class'
3332
3433export function toObjects ( records , converters ) {
3534 const recordValues = records . map ( record => {
3635 let out = [ ]
37- record . forEach ( ( val , key ) => out . push ( itemIntToString ( val , converters ) ) )
36+ record . forEach ( val => out . push ( itemIntToString ( val , converters ) ) )
3837 return out
3938 } )
4039 return recordValues
@@ -430,115 +429,57 @@ export const recursivelyTypeGraphItems = (item, types = neo4j.types) => {
430429 return item . map ( i => recursivelyTypeGraphItems ( i , types ) )
431430 }
432431 if ( item instanceof types . Node ) {
433- safetlyAddObjectProp ( item , reservedTypePropertyName , 'Node' )
434- item . identity = safetlyAddObjectProp (
435- item . identity ,
436- reservedTypePropertyName ,
437- 'Integer'
438- )
439- const props = recursivelyTypeGraphItems ( item . properties , types )
440- item . properties = props
441- return item
432+ const tmp = copyAndType ( item , types )
433+ safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'Node' )
434+ return tmp
442435 }
443436 if ( item instanceof types . PathSegment ) {
444- safetlyAddObjectProp ( item , reservedTypePropertyName , 'PathSegment' )
445- item . start = recursivelyTypeGraphItems ( item . start , types )
446- item . end = recursivelyTypeGraphItems ( item . end , types )
447- item . relationship = recursivelyTypeGraphItems ( item . relationship , types )
448- return item
437+ const tmp = copyAndType ( item , types )
438+ safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'PathSegment' )
439+ return tmp
449440 }
450441 if ( item instanceof types . Path ) {
451- safetlyAddObjectProp ( item , reservedTypePropertyName , 'Path' )
452- item . segments = item . segments . map ( x => recursivelyTypeGraphItems ( x , types ) )
453- item . start = ! hasReservedProp ( item . start , reservedTypePropertyName )
454- ? recursivelyTypeGraphItems ( item . start , types )
455- : item . start
456- item . end = ! hasReservedProp ( item . end , reservedTypePropertyName )
457- ? recursivelyTypeGraphItems ( item . end , types )
458- : item . end
459- return item
442+ const tmp = copyAndType ( item , types )
443+ safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'Path' )
444+ return tmp
460445 }
461446 if ( item instanceof types . Relationship ) {
462- safetlyAddObjectProp ( item , reservedTypePropertyName , 'Relationship' )
463- item . identity = safetlyAddObjectProp (
464- item . identity ,
465- reservedTypePropertyName ,
466- 'Integer'
467- )
468- item . start = safetlyAddObjectProp (
469- item . start ,
470- reservedTypePropertyName ,
471- 'Integer'
472- )
473- item . end = safetlyAddObjectProp (
474- item . end ,
475- reservedTypePropertyName ,
476- 'Integer'
477- )
478- const props = recursivelyTypeGraphItems ( item . properties , types )
479- item . properties = props
480- return item
447+ const tmp = copyAndType ( item , types )
448+ safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'Relationship' )
449+ return tmp
481450 }
482451 if ( item instanceof types . Point ) {
483- const keys = Object . keys ( item )
484- let tmp = { }
485- keys . forEach (
486- key => ( tmp [ key ] = recursivelyTypeGraphItems ( item [ key ] , types ) )
487- )
452+ const tmp = copyAndType ( item , types )
488453 safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'Point' )
489454 return tmp
490455 }
491456 if ( item instanceof types . Date ) {
492- const keys = Object . keys ( item )
493- let tmp = { }
494- keys . forEach (
495- key => ( tmp [ key ] = recursivelyTypeGraphItems ( item [ key ] , types ) )
496- )
457+ const tmp = copyAndType ( item , types )
497458 safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'Date' )
498459 return tmp
499460 }
500461 if ( item instanceof types . DateTime ) {
501- const keys = Object . keys ( item )
502- let tmp = { }
503- keys . forEach (
504- key => ( tmp [ key ] = recursivelyTypeGraphItems ( item [ key ] , types ) )
505- )
462+ const tmp = copyAndType ( item , types )
506463 safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'DateTime' )
507464 return tmp
508465 }
509466 if ( item instanceof types . Duration ) {
510- const keys = Object . keys ( item )
511- let tmp = { }
512- keys . forEach (
513- key => ( tmp [ key ] = recursivelyTypeGraphItems ( item [ key ] , types ) )
514- )
467+ const tmp = copyAndType ( item , types )
515468 safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'Duration' )
516469 return tmp
517470 }
518471 if ( item instanceof types . LocalDateTime ) {
519- const keys = Object . keys ( item )
520- let tmp = { }
521- keys . forEach (
522- key => ( tmp [ key ] = recursivelyTypeGraphItems ( item [ key ] , types ) )
523- )
472+ const tmp = copyAndType ( item , types )
524473 safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'LocalDateTime' )
525474 return tmp
526475 }
527476 if ( item instanceof types . LocalTime ) {
528- const keys = Object . keys ( item )
529- let tmp = { }
530- keys . forEach (
531- key => ( tmp [ key ] = recursivelyTypeGraphItems ( item [ key ] , types ) )
532- )
477+ const tmp = copyAndType ( item , types )
533478 safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'LocalTime' )
534479 return tmp
535480 }
536481 if ( item instanceof types . Time ) {
537- const keys = Object . keys ( item )
538- let tmp = { }
539- keys . forEach (
540- key => ( tmp [ key ] = recursivelyTypeGraphItems ( item [ key ] , types ) )
541- )
482+ const tmp = copyAndType ( item , types )
542483 safetlyAddObjectProp ( tmp , reservedTypePropertyName , 'Time' )
543484 return tmp
544485 }
@@ -557,3 +498,10 @@ export const recursivelyTypeGraphItems = (item, types = neo4j.types) => {
557498 }
558499 return item
559500}
501+
502+ function copyAndType ( any , types = neo4j . types ) {
503+ const keys = Object . keys ( any )
504+ let tmp = { }
505+ keys . forEach ( key => ( tmp [ key ] = recursivelyTypeGraphItems ( any [ key ] , types ) ) )
506+ return tmp
507+ }
0 commit comments