1+ const WGS_84_2D_CRS_CODE = BigInt ( 4326 )
2+ const CARTESIAN_2D_CRS_CODE = BigInt ( 7203 )
3+
4+ const WGS_84_3D_CRS_CODE = BigInt ( 4979 )
5+ const CARTESIAN_3D_CRS_CODE = BigInt ( 9157 )
16
27export default function CypherNativeBinders ( neo4j ) {
38 function valueResponse ( name , value ) {
4- return { name : name , data : { value : value } }
9+ return { name, data : { value } }
510 }
611 function objectToCypher ( obj ) {
712 return objectMapper ( obj , nativeToCypher )
@@ -124,7 +129,8 @@ export default function CypherNativeBinders (neo4j) {
124129 month : x . month ,
125130 day : x . day
126131 } )
127- } else if ( neo4j . isDateTime ( x ) || neo4j . isLocalDateTime ( x ) ) {
132+ }
133+ if ( neo4j . isDateTime ( x ) || neo4j . isLocalDateTime ( x ) ) {
128134 return structResponse ( 'CypherDateTime' , {
129135 year : x . year ,
130136 month : x . month ,
@@ -136,15 +142,17 @@ export default function CypherNativeBinders (neo4j) {
136142 utc_offset_s : x . timeZoneOffsetSeconds || ( x . timeZoneId == null ? undefined : 0 ) ,
137143 timezone_id : x . timeZoneId
138144 } )
139- } else if ( neo4j . isTime ( x ) || neo4j . isLocalTime ( x ) ) {
145+ }
146+ if ( neo4j . isTime ( x ) || neo4j . isLocalTime ( x ) ) {
140147 return structResponse ( 'CypherTime' , {
141148 hour : x . hour ,
142149 minute : x . minute ,
143150 second : x . second ,
144151 nanosecond : x . nanosecond ,
145152 utc_offset_s : x . timeZoneOffsetSeconds
146153 } )
147- } else if ( neo4j . isDuration ( x ) ) {
154+ }
155+ if ( neo4j . isDuration ( x ) ) {
148156 return structResponse ( 'CypherDuration' , {
149157 months : x . months ,
150158 days : x . days ,
@@ -153,6 +161,21 @@ export default function CypherNativeBinders (neo4j) {
153161 } )
154162 }
155163
164+ if ( x instanceof neo4j . types . Point ) {
165+ let system = 'unknown'
166+ if ( x . srid === WGS_84_2D_CRS_CODE || x . srid === WGS_84_3D_CRS_CODE ) {
167+ system = 'wgs84'
168+ } else if ( x . srid === CARTESIAN_2D_CRS_CODE || x . srid === CARTESIAN_3D_CRS_CODE ) {
169+ system = 'cartesian'
170+ }
171+ return structResponse ( 'CypherPoint' , {
172+ system,
173+ x : x . x ,
174+ y : x . y ,
175+ z : x . z == null ? undefined : x . z
176+ } )
177+ }
178+
156179 // If all failed, interpret as a map
157180 const map = { }
158181 for ( const [ key , value ] of Object . entries ( x ) ) {
@@ -246,6 +269,21 @@ export default function CypherNativeBinders (neo4j) {
246269 acc [ key ] = cypherToNative ( val )
247270 return acc
248271 } , { } )
272+ case 'CypherPoint' :
273+ if ( data . system === 'wgs84' ) {
274+ if ( data . z != null ) {
275+ return new neo4j . Point ( WGS_84_3D_CRS_CODE , data . x , data . y , data . z )
276+ } else {
277+ return new neo4j . Point ( WGS_84_2D_CRS_CODE , data . x , data . y )
278+ }
279+ } else if ( data . system === 'cartesian' ) {
280+ if ( data . z != null ) {
281+ return new neo4j . Point ( CARTESIAN_3D_CRS_CODE , data . x , data . y , data . z )
282+ } else {
283+ return new neo4j . Point ( CARTESIAN_2D_CRS_CODE , data . x , data . y )
284+ }
285+ }
286+ throw new Error ( `Unknown Point system '${ data . system } '` )
249287 }
250288 console . log ( `Type ${ name } is not handle by cypherToNative` , c )
251289 const err = 'Unable to convert ' + c + ' to native type'
0 commit comments