Skip to content

Commit

Permalink
Bugfix arrays of values, now converting Int to number, also changed P…
Browse files Browse the repository at this point in the history
…oint to export as GeoJSON
  • Loading branch information
huboneo committed Aug 16, 2019
1 parent 2fcfac0 commit 69f464a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 11 deletions.
37 changes: 35 additions & 2 deletions src/browser/modules/Stream/CypherFrame/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ function mapNeo4jValuesToPlainValues (values) {
}
}

if (isNeo4jValue(values)) {
return neo4jValueToPlainValue(values)
}

return reduce(
entries(values),
(agg, [key, value]) => ({
Expand All @@ -374,10 +378,39 @@ function neo4jValueToPlainValue (value) {
case neo4j.types.LocalDateTime:
case neo4j.types.LocalTime:
case neo4j.types.Time:
case neo4j.types.Point:
case neo4j.types.Integer: // not exposed in typings but still there
return value.toString()
case neo4j.types.Integer: // not exposed in typings but still there
return value.inSafeRange() ? value.toInt() : value.toNumber()
case neo4j.types.Point:
return {
type: neo4j.types.Point.name,
coordinates:
value.z !== undefined
? [value.x, value.y, value.z]
: [value.x, value.y]
}
default:
return value
}
}

/**
* checks if a value is a neo4j value
* @param value
* @return {boolean}
*/
function isNeo4jValue (value) {
switch (get(value, 'constructor')) {
case neo4j.types.Date:
case neo4j.types.DateTime:
case neo4j.types.Duration:
case neo4j.types.LocalDateTime:
case neo4j.types.LocalTime:
case neo4j.types.Time:
case neo4j.types.Point:
case neo4j.types.Integer: // not exposed in typings but still there
return true
default:
return false
}
}
57 changes: 48 additions & 9 deletions src/browser/modules/Stream/CypherFrame/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ describe('helpers', () => {
type: 'node',
labels: ['foo'],
properties: {
bar: '3'
bar: 3
}
}
}
Expand Down Expand Up @@ -861,7 +861,7 @@ describe('helpers', () => {

test('handles point values', () => {
const node = new neo4j.types.Node(1, ['foo'], {
bar: new neo4j.types.Point(1, 10, 10, 10)
bar: new neo4j.types.Point(1, 10, 5, 15)
})
const record = new neo4j.types.Record(['n'], [node])
const expected = {
Expand All @@ -870,7 +870,10 @@ describe('helpers', () => {
type: 'node',
labels: ['foo'],
properties: {
bar: 'Point{srid=1.0, x=10.0, y=10.0, z=10.0}'
bar: {
type: 'Point',
coordinates: [10, 5, 15]
}
}
}
}
Expand Down Expand Up @@ -912,7 +915,7 @@ describe('helpers', () => {
type: 'relationship',
label: 'foo',
properties: {
bar: '3'
bar: 3
}
}
}
Expand Down Expand Up @@ -1048,7 +1051,7 @@ describe('helpers', () => {

test('handles point values', () => {
const relationship = new neo4j.types.Relationship(1, 2, 3, 'foo', {
bar: new neo4j.types.Point(1, 10, 10, 10)
bar: new neo4j.types.Point(1, 10, 5, 15)
})
const record = new neo4j.types.Record(['r'], [relationship])
const expected = {
Expand All @@ -1059,7 +1062,10 @@ describe('helpers', () => {
type: 'relationship',
label: 'foo',
properties: {
bar: 'Point{srid=1.0, x=10.0, y=10.0, z=10.0}'
bar: {
type: 'Point',
coordinates: [10, 5, 15]
}
}
}
}
Expand Down Expand Up @@ -1110,7 +1116,7 @@ describe('helpers', () => {
type: 'node',
labels: ['foo'],
properties: {
bar: '3'
bar: 3
}
},
r1: {
Expand Down Expand Up @@ -1160,7 +1166,7 @@ describe('helpers', () => {
type: 'node',
labels: ['foo'],
properties: {
bar: '3'
bar: 3
}
},
end: {
Expand All @@ -1178,7 +1184,7 @@ describe('helpers', () => {
type: 'node',
labels: ['foo'],
properties: {
bar: '3'
bar: 3
}
},
relationship: {
Expand Down Expand Up @@ -1207,5 +1213,38 @@ describe('helpers', () => {
expect(recordToJSONMapper(record)).toEqual(expected)
})
})

describe('Returns of raw data', () => {
test('RETURN {...data} as foo', () => {
const record = new neo4j.types.Record(
['foo'],
[
{
data: [
new neo4j.int(1),
'car',
new neo4j.types.Point(1, 10, 5, 15),
new neo4j.types.Date(1970, 1, 1)
]
}
]
)
const expected = {
foo: {
data: [
1,
'car',
{
type: 'Point',
coordinates: [10, 5, 15]
},
'1970-01-01'
]
}
}

expect(recordToJSONMapper(record)).toEqual(expected)
})
})
})
})

0 comments on commit 69f464a

Please sign in to comment.