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 )
1
6
2
7
export default function CypherNativeBinders ( neo4j ) {
3
8
function valueResponse ( name , value ) {
4
- return { name : name , data : { value : value } }
9
+ return { name, data : { value } }
5
10
}
6
11
function objectToCypher ( obj ) {
7
12
return objectMapper ( obj , nativeToCypher )
@@ -124,7 +129,8 @@ export default function CypherNativeBinders (neo4j) {
124
129
month : x . month ,
125
130
day : x . day
126
131
} )
127
- } else if ( neo4j . isDateTime ( x ) || neo4j . isLocalDateTime ( x ) ) {
132
+ }
133
+ if ( neo4j . isDateTime ( x ) || neo4j . isLocalDateTime ( x ) ) {
128
134
return structResponse ( 'CypherDateTime' , {
129
135
year : x . year ,
130
136
month : x . month ,
@@ -136,15 +142,17 @@ export default function CypherNativeBinders (neo4j) {
136
142
utc_offset_s : x . timeZoneOffsetSeconds || ( x . timeZoneId == null ? undefined : 0 ) ,
137
143
timezone_id : x . timeZoneId
138
144
} )
139
- } else if ( neo4j . isTime ( x ) || neo4j . isLocalTime ( x ) ) {
145
+ }
146
+ if ( neo4j . isTime ( x ) || neo4j . isLocalTime ( x ) ) {
140
147
return structResponse ( 'CypherTime' , {
141
148
hour : x . hour ,
142
149
minute : x . minute ,
143
150
second : x . second ,
144
151
nanosecond : x . nanosecond ,
145
152
utc_offset_s : x . timeZoneOffsetSeconds
146
153
} )
147
- } else if ( neo4j . isDuration ( x ) ) {
154
+ }
155
+ if ( neo4j . isDuration ( x ) ) {
148
156
return structResponse ( 'CypherDuration' , {
149
157
months : x . months ,
150
158
days : x . days ,
@@ -153,6 +161,21 @@ export default function CypherNativeBinders (neo4j) {
153
161
} )
154
162
}
155
163
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
+
156
179
// If all failed, interpret as a map
157
180
const map = { }
158
181
for ( const [ key , value ] of Object . entries ( x ) ) {
@@ -246,6 +269,21 @@ export default function CypherNativeBinders (neo4j) {
246
269
acc [ key ] = cypherToNative ( val )
247
270
return acc
248
271
} , { } )
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 } '` )
249
287
}
250
288
console . log ( `Type ${ name } is not handle by cypherToNative` , c )
251
289
const err = 'Unable to convert ' + c + ' to native type'
0 commit comments