diff --git a/src/http-connection/query.codec.ts b/src/http-connection/query.codec.ts index b706d7a..3cec923 100644 --- a/src/http-connection/query.codec.ts +++ b/src/http-connection/query.codec.ts @@ -23,7 +23,7 @@ type RawQueryValueTypes = 'Null' | 'Boolean' | 'Integer' | 'Float' | 'String' | 'Duration' | 'Point' | 'Base64' | 'Map' | 'List' | 'Node' | 'Relationship' | 'Path' -type PointShape = { srid: number, x: string, y: string, z?: string } +type PointShape = { coordinates: [number, number, number?], crs: { srid: number } } type NodeShape = { _element_id: string, _labels: string[], _properties?: Record} type RelationshipShape = { _element_id: string, _start_node_element_id: string, _end_node_element_id: string, _type: string, _properties?: Record } type PathShape = (RawQueryRelationship | RawQueryNode)[] @@ -426,10 +426,8 @@ export class QueryResponseCodec { _decodePoint(value: PointShape): Point { return new Point( - this._normalizeInteger(int(value.srid)), - this._decodeFloat(value.x), - this._decodeFloat(value.y), - value.z != null ? this._decodeFloat(value.z) : undefined + this._normalizeInteger(int(value.crs.srid)), + ...value.coordinates ) } @@ -577,10 +575,14 @@ export class QueryRequestCodec { return this._encodeValue(Array.from(value)) } else if (isPoint(value)) { return { $type: 'Point', _value: { - srid: int(value.srid).toNumber(), - x: value.x.toString(), - y: value.y.toString(), - z: value.z?.toString() + crs: { + srid: int(value.srid).toNumber(), + }, + coordinates: [ + value.x, + value.y, + value.z + ].filter(v => v != null) as [number, number, number?] }} } else if (isDuration(value)) { return { $type: 'Duration', _value: value.toString()} diff --git a/test/integration/minimum.test.ts b/test/integration/minimum.test.ts index 010d782..7240e15 100644 --- a/test/integration/minimum.test.ts +++ b/test/integration/minimum.test.ts @@ -172,6 +172,21 @@ describe('minimum requirement', () => { } }) + it.each([ + ['CARTESIAN Point 2D', 'point({x: 2.3, y: 4.5})', new Point(int(7203), 2.3, 4.5)], + ['CARTESIAN Point 3D', 'point({x: 2.3, y: 4.5, z:7.5})', new Point(int(9157), 2.3, 4.5, 7.5)], + ['WGS Point 2D', 'point({longitude: 12.78, latitude: 56.7})', new Point(int(4326), 12.78, 56.7)], + ['WGS Point 3D', 'point({longitude: 12.78, latitude: 56.7, height: 120.57})', new Point(int(4979), 12.78, 56.7, 120.57)] + ])('should be able to echo "%s" (%s)', async (_, statement, expectedOutput) => { + const session = wrapper.session({ database: config.database }) + try { + const { records: [first] } = await session.run(`RETURN ${statement} as output`) + expect(first.get('output')).toEqual(expectedOutput) + } finally { + await session.close() + } + }) + function v(value: T, mapper: (value: T)=> K = (v) => v as unknown as K): [T, K] { return [value, mapper(value)] }