Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestKit: add spatial type support to backend #1227

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions packages/testkit-backend/src/cypher-native-binders.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const WGS_84_2D_CRS_CODE = BigInt(4326)
const CARTESIAN_2D_CRS_CODE = BigInt(7203)

const WGS_84_3D_CRS_CODE = BigInt(4979)
const CARTESIAN_3D_CRS_CODE = BigInt(9157)

export default function CypherNativeBinders (neo4j) {
function valueResponse (name, value) {
return { name: name, data: { value: value } }
return { name, data: { value } }
}
function objectToCypher (obj) {
return objectMapper(obj, nativeToCypher)
Expand Down Expand Up @@ -124,7 +129,8 @@ export default function CypherNativeBinders (neo4j) {
month: x.month,
day: x.day
})
} else if (neo4j.isDateTime(x) || neo4j.isLocalDateTime(x)) {
}
if (neo4j.isDateTime(x) || neo4j.isLocalDateTime(x)) {
return structResponse('CypherDateTime', {
year: x.year,
month: x.month,
Expand All @@ -136,15 +142,17 @@ export default function CypherNativeBinders (neo4j) {
utc_offset_s: x.timeZoneOffsetSeconds || (x.timeZoneId == null ? undefined : 0),
timezone_id: x.timeZoneId
})
} else if (neo4j.isTime(x) || neo4j.isLocalTime(x)) {
}
if (neo4j.isTime(x) || neo4j.isLocalTime(x)) {
return structResponse('CypherTime', {
hour: x.hour,
minute: x.minute,
second: x.second,
nanosecond: x.nanosecond,
utc_offset_s: x.timeZoneOffsetSeconds
})
} else if (neo4j.isDuration(x)) {
}
if (neo4j.isDuration(x)) {
return structResponse('CypherDuration', {
months: x.months,
days: x.days,
Expand All @@ -153,6 +161,21 @@ export default function CypherNativeBinders (neo4j) {
})
}

if (x instanceof neo4j.types.Point) {
let system = 'unknown'
if (x.srid === WGS_84_2D_CRS_CODE || x.srid === WGS_84_3D_CRS_CODE) {
system = 'wgs84'
} else if (x.srid === CARTESIAN_2D_CRS_CODE || x.srid === CARTESIAN_3D_CRS_CODE) {
system = 'cartesian'
}
return structResponse('CypherPoint', {
system,
x: x.x,
y: x.y,
z: x.z == null ? undefined : x.z
})
}

// If all failed, interpret as a map
const map = {}
for (const [key, value] of Object.entries(x)) {
Expand Down Expand Up @@ -246,6 +269,21 @@ export default function CypherNativeBinders (neo4j) {
acc[key] = cypherToNative(val)
return acc
}, {})
case 'CypherPoint':
if (data.system === 'wgs84') {
if (data.z != null) {
return new neo4j.Point(WGS_84_3D_CRS_CODE, data.x, data.y, data.z)
} else {
return new neo4j.Point(WGS_84_2D_CRS_CODE, data.x, data.y)
}
} else if (data.system === 'cartesian') {
if (data.z != null) {
return new neo4j.Point(CARTESIAN_3D_CRS_CODE, data.x, data.y, data.z)
} else {
return new neo4j.Point(CARTESIAN_2D_CRS_CODE, data.x, data.y)
}
}
throw new Error(`Unknown Point system '${data.system}'`)
}
console.log(`Type ${name} is not handle by cypherToNative`, c)
const err = 'Unable to convert ' + c + ' to native type'
Expand Down
1 change: 1 addition & 0 deletions packages/testkit-backend/src/feature/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const features = [
'Feature:API:SSLConfig',
'Feature:API:SSLSchemes',
'Feature:API:Type.Temporal',
'Feature:API:Type.Spatial',
'AuthorizationExpiredTreatment',
'ConfHint:connection.recv_timeout_seconds',
'Feature:Impersonation',
Expand Down