Skip to content

Commit

Permalink
fixing the schema type error
Browse files Browse the repository at this point in the history
  • Loading branch information
nnecla committed Dec 17, 2024
1 parent c7a9499 commit d52890e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
19 changes: 8 additions & 11 deletions src/browser/components/ManualLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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/': {
Expand Down Expand Up @@ -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 = (
Expand All @@ -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
)
}
Expand Down
11 changes: 6 additions & 5 deletions src/browser/components/VersionConditionalDoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions src/browser/modules/Stream/SchemaFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -246,11 +249,10 @@ export class SchemaFrame extends Component<any, SchemaFrameState> {
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'

Expand Down
11 changes: 10 additions & 1 deletion src/shared/modules/dbMeta/dbMetaDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/shared/modules/dbMeta/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
)
}
5 changes: 3 additions & 2 deletions src/shared/modules/features/featureDuck.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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
}

Expand Down

0 comments on commit d52890e

Please sign in to comment.