diff --git a/packages/query-tools/src/data-transforms/record-to-string.ts b/packages/query-tools/src/data-transforms/record-to-string.ts index cc88e68f3..51da5a082 100644 --- a/packages/query-tools/src/data-transforms/record-to-string.ts +++ b/packages/query-tools/src/data-transforms/record-to-string.ts @@ -12,9 +12,11 @@ import { } from '../types/cypher-data-types'; import { formatFloat } from './format-float'; -const spacialFormat = (p: Point): string => { - const zString = p.z !== undefined ? `, z:${p.z}` : ''; - return `point({srid:${p.srid.toString()}, x:${p.x}, y:${p.y}${zString}})`; +export const spacialFormat = (p: Point): string => { + const zString = p.z !== undefined ? `, z:${formatFloat(p.z)}` : ''; + return `point({srid:${p.srid.toString()}, x:${formatFloat( + p.x, + )}, y:${formatFloat(p.y)}${zString}})`; }; export function propertyToString( @@ -29,14 +31,16 @@ export function propertyToString( if (property === null) { return 'null'; } - if (typeof property === 'boolean') { - return property.toString(); - } - if (isInt(property)) { + if ( + typeof property === 'boolean' || + isInt(property) || + typeof property === 'bigint' || + isCypherTemporalType(property) + ) { return property.toString(); } - if (typeof property === 'bigint') { - return property.toString(); + if (isPoint(property)) { + spacialFormat(property); } if (typeof property === 'number') { return formatFloat(property); @@ -53,14 +57,6 @@ export function propertyToString( return 'ByteArray'; } - if (isCypherTemporalType(property)) { - return property.toString(); - } - - if (isPoint(property)) { - return spacialFormat(property); - } - // This case shouldn't be used, but added as a fallback return String(property); } diff --git a/packages/query-tools/src/index.ts b/packages/query-tools/src/index.ts index 87929433a..7f7a84ad8 100644 --- a/packages/query-tools/src/index.ts +++ b/packages/query-tools/src/index.ts @@ -11,7 +11,10 @@ export { getPropertyTypeDisplayName, } from './data-transforms/cypher-type-names'; export type { CypherDataTypeName } from './data-transforms/cypher-type-names'; -export { cypherDataToString } from './data-transforms/record-to-string'; +export { + cypherDataToString, + spacialFormat, +} from './data-transforms/record-to-string'; export type { CypherProperty } from './data-types/cypher-data-types'; export type { ConnectedMetadataPoller as CypherMetadataPoller, diff --git a/packages/vscode-extension/src/typeUtils.ts b/packages/vscode-extension/src/typeUtils.ts index 3209da146..fff993655 100644 --- a/packages/vscode-extension/src/typeUtils.ts +++ b/packages/vscode-extension/src/typeUtils.ts @@ -11,9 +11,11 @@ import { isInt, isLocalDateTime, isLocalTime, + isPoint, isTime, } from 'neo4j-driver'; import { isDate } from 'util/types'; +import { spacialFormat } from '@neo4j-cypher/query-tools'; // eslint-disable-next-line @typescript-eslint/no-explicit-any export function toNativeTypes(properties: Record) { @@ -46,6 +48,8 @@ function valueToNativeType(value: unknown) { isDuration(value) ) { value = value.toString(); + } else if (isPoint(value)) { + value = spacialFormat(value); } else if ( typeof value === 'object' && value !== undefined &&