diff --git a/src/browser/components/ManualLink.tsx b/src/browser/components/ManualLink.tsx index 1d35c623c6..0baae463a6 100644 --- a/src/browser/components/ManualLink.tsx +++ b/src/browser/components/ManualLink.tsx @@ -24,7 +24,10 @@ import semver from 'semver' import { DrawerExternalLink } from './drawer/drawer-styled' import { formatDocVersion } from 'browser/modules/Sidebar/docsUtils' import { GlobalState } from 'project-root/src/shared/globalState' -import { getRawVersion } from 'shared/modules/dbMeta/dbMetaDuck' +import { + getCleanedVersion, + getRawVersion +} from 'shared/modules/dbMeta/dbMetaDuck' const oldPages: { [key: string]: { oldPage: string; oldContent: string } } = { '/administration/indexes-for-search-performance/': { @@ -63,12 +66,8 @@ const isPageOld = ( ) => { if (chapter !== 'cypher-manual' || !oldPages[page] || !neo4jVersion) return false - const cleanedVersion = semver.clean(neo4jVersion, true) - return ( - cleanedVersion && - semver.valid(cleanedVersion) && - semver.satisfies(cleanedVersion, '<4.0.0-alpha.1') - ) + const cleanedVersion = getCleanedVersion(neo4jVersion) + return cleanedVersion && semver.satisfies(cleanedVersion, '<4.0.0-alpha.1') } const isPageNew = ( @@ -77,11 +76,9 @@ const isPageNew = ( neo4jVersion: string | null ) => { if (chapter !== 'cypher-manual' || !newPages[page]) return false - const cleanedVersion = semver.clean(neo4jVersion || '', true) + const cleanedVersion = getCleanedVersion(neo4jVersion) return ( - (cleanedVersion && - semver.valid(cleanedVersion) && - semver.satisfies(cleanedVersion, '>=4.3')) || + (cleanedVersion && semver.satisfies(cleanedVersion, '>=4.3')) || neo4jVersion === null ) } diff --git a/src/browser/components/VersionConditionalDoc.tsx b/src/browser/components/VersionConditionalDoc.tsx index 10155095d1..d99f99daff 100644 --- a/src/browser/components/VersionConditionalDoc.tsx +++ b/src/browser/components/VersionConditionalDoc.tsx @@ -22,7 +22,10 @@ import { connect } from 'react-redux' import semver from 'semver' import { GlobalState } from 'project-root/src/shared/globalState' -import { getRawVersion } from 'shared/modules/dbMeta/dbMetaDuck' +import { + getCleanedVersion, + getRawVersion +} from 'shared/modules/dbMeta/dbMetaDuck' export type VersionConditionalDocProps = { versionCondition: string @@ -36,12 +39,10 @@ export function VersionConditionalDoc({ neo4jVersion, includeCurrent = false }: VersionConditionalDocProps): JSX.Element { - const cleanedVersion = semver.clean(neo4jVersion || '', true) + const cleanedVersion = getCleanedVersion(neo4jVersion) if ( (includeCurrent && neo4jVersion === null) || - (cleanedVersion && - semver.valid(cleanedVersion) && - semver.satisfies(cleanedVersion, versionCondition)) + (cleanedVersion && semver.satisfies(cleanedVersion, versionCondition)) ) { return <>{children} } else { diff --git a/src/browser/modules/Stream/SchemaFrame.tsx b/src/browser/modules/Stream/SchemaFrame.tsx index 1f4cbf3914..81740878ee 100644 --- a/src/browser/modules/Stream/SchemaFrame.tsx +++ b/src/browser/modules/Stream/SchemaFrame.tsx @@ -36,7 +36,10 @@ import Directives from 'browser-components/Directives' import { GlobalState } from 'project-root/src/shared/globalState' import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata' import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck' -import { getSemanticVersion } from 'shared/modules/dbMeta/dbMetaDuck' +import { + getCleanedVersion, + getSemanticVersion +} from 'shared/modules/dbMeta/dbMetaDuck' type IndexesProps = { indexes: any @@ -246,11 +249,10 @@ export class SchemaFrame extends Component { render(): JSX.Element { const { neo4jVersion } = this.props const { indexes, constraints } = this.state - const cleanedVersion = semver.clean(neo4jVersion || '', true) + const cleanedVersion = + typeof neo4jVersion === 'string' ? getCleanedVersion(neo4jVersion) : null const schemaCommand = - cleanedVersion && - semver.valid(cleanedVersion) && - semver.satisfies(cleanedVersion, '<=3.4.*') + cleanedVersion && semver.satisfies(cleanedVersion, '<=3.4.*') ? 'CALL db.schema()' : 'CALL db.schema.visualization' diff --git a/src/shared/modules/dbMeta/dbMetaDuck.ts b/src/shared/modules/dbMeta/dbMetaDuck.ts index 42c6a706f6..a5a1184d25 100644 --- a/src/shared/modules/dbMeta/dbMetaDuck.ts +++ b/src/shared/modules/dbMeta/dbMetaDuck.ts @@ -19,7 +19,7 @@ */ import { uniq } from 'lodash-es' import { QueryResult } from 'neo4j-driver' -import { SemVer, clean, coerce, gte } from 'semver' +import { SemVer, clean, coerce, gte, valid } from 'semver' import { isConfigValFalsy } from 'services/bolt/boltHelpers' import { GlobalState } from 'shared/globalState' import { APP_START } from 'shared/modules/app/appDuck' @@ -270,9 +270,18 @@ export function getUniqueDatbases(state: GlobalState): Database[] { export const getRawVersion = (state: GlobalState): string | null => (state[NAME] || {}).server ? (state[NAME] || {}).server.version : null + export const getSemanticVersion = (state: GlobalState): SemVer | null => coerce(clean(getRawVersion(state) || '', true)) +export const getCleanedVersion = (version: string | null): string | null => { + const cleanedVersion = clean(version || '', true) + if (valid(cleanedVersion)) { + return cleanedVersion + } + return null +} + export const supportsMultiDb = (state: GlobalState): boolean => { const version = getSemanticVersion(state) return version ? gte(version, FIRST_MULTI_DB_SUPPORT) : false diff --git a/src/shared/modules/dbMeta/utils.ts b/src/shared/modules/dbMeta/utils.ts index 4e387bc492..f2be4448e9 100644 --- a/src/shared/modules/dbMeta/utils.ts +++ b/src/shared/modules/dbMeta/utils.ts @@ -21,7 +21,11 @@ import { Integer, QueryResult } from 'neo4j-driver' import semver from 'semver' import { guessSemverVersion } from '../features/featureDuck.utils' -import { TrialStatus, VERSION_FOR_EDITOR_HISTORY_SETTING } from './dbMetaDuck' +import { + getCleanedVersion, + TrialStatus, + VERSION_FOR_EDITOR_HISTORY_SETTING +} from './dbMetaDuck' type ServerInfo = { version: string | null @@ -52,7 +56,7 @@ export function extractServerInfo(res: QueryResult): ServerInfo { } // Some aura servers self report versions that need coercing (eg. 3.5 or 4.3-aura) - if (!semver.valid(semver.clean(serverInfo.version || '', true))) { + if (!getCleanedVersion(serverInfo.version)) { serverInfo.version = guessSemverVersion(serverInfo.version) } @@ -113,10 +117,9 @@ export const extractTrialStatusOld = (res: QueryResult): TrialStatus => { export const versionHasEditorHistorySetting = (version: string | null) => { if (!version) return false - const cleanedVersion = semver.clean(version, true) + const cleanedVersion = getCleanedVersion(version) return ( cleanedVersion && - semver.valid(cleanedVersion) && semver.gte(cleanedVersion, VERSION_FOR_EDITOR_HISTORY_SETTING) ) } diff --git a/src/shared/modules/features/featureDuck.utils.ts b/src/shared/modules/features/featureDuck.utils.ts index 46cd400d87..8246624242 100644 --- a/src/shared/modules/features/featureDuck.utils.ts +++ b/src/shared/modules/features/featureDuck.utils.ts @@ -18,14 +18,15 @@ * along with this program. If not, see . */ import semver from 'semver' +import { getCleanedVersion } from '../dbMeta/dbMetaDuck' export const guessSemverVersion = (versionString: string | null) => { if (!versionString) { return null } const cleanedVersion = - typeof versionString === 'string' ? semver.clean(versionString, true) : null - if (semver.valid(cleanedVersion)) { + typeof versionString === 'string' ? getCleanedVersion(versionString) : null + if (cleanedVersion) { return cleanedVersion }