-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1227 from opencomponents/domain-validators-ts
Refactor some validators and domain files to TS
- Loading branch information
Showing
13 changed files
with
173 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import semver from 'semver'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
|
||
const packageInfo = fs.readJSONSync( | ||
path.join(__dirname, '..', '..', '..', '..', 'package.json') | ||
); | ||
|
||
type OkResult = { isValid: true }; | ||
type ErrorResult = { | ||
isValid: false; | ||
error: { | ||
suggestedVersion: string; | ||
registryNodeVersion: string; | ||
cliNodeVersion: string; | ||
code: string; | ||
}; | ||
}; | ||
type Result = OkResult | ErrorResult; | ||
|
||
export default function nodeVersion( | ||
userAgent: string, | ||
nodeVersion: string | ||
): Result { | ||
const baseError = ( | ||
opts: Partial<ErrorResult['error']> = {} | ||
): ErrorResult => ({ | ||
isValid: false, | ||
error: { | ||
suggestedVersion: packageInfo.engines.node || '*', | ||
registryNodeVersion: nodeVersion, | ||
cliNodeVersion: '', | ||
code: '', | ||
...opts | ||
} | ||
}); | ||
|
||
if (!userAgent) { | ||
return baseError({ code: 'empty' }); | ||
} | ||
|
||
const matchVersion = /.*\/v([\w|.]+)-.*/.exec(userAgent); | ||
if (!matchVersion) { | ||
return baseError({ | ||
code: 'not_valid', | ||
cliNodeVersion: 'not-valid' | ||
}); | ||
} | ||
|
||
const cliNodeVersion = matchVersion[1]; | ||
if (!semver.satisfies(cliNodeVersion, packageInfo.engines.node)) { | ||
return baseError({ | ||
code: 'not_matching', | ||
cliNodeVersion | ||
}); | ||
} | ||
|
||
return { isValid: true }; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import semver from 'semver'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
|
||
const packageInfo = fs.readJSONSync( | ||
path.join(__dirname, '..', '..', '..', '..', 'package.json') | ||
); | ||
|
||
type OkResult = { isValid: true }; | ||
type ErrorResult = { | ||
isValid: false; | ||
error: { | ||
suggestedVersion: string; | ||
registryVersion: string; | ||
cliVersion: string; | ||
code: string; | ||
}; | ||
}; | ||
type Result = OkResult | ErrorResult; | ||
|
||
export default function ocCliVersion(userAgent: string): Result { | ||
const baseError = ( | ||
opts: Partial<ErrorResult['error']> = {} | ||
): ErrorResult => ({ | ||
isValid: false, | ||
error: { | ||
suggestedVersion: `${semver.major(packageInfo.version)}.${semver.minor( | ||
packageInfo.version | ||
)}.X`, | ||
registryVersion: packageInfo.version, | ||
cliVersion: '', | ||
code: '', | ||
...opts | ||
} | ||
}); | ||
|
||
if (!userAgent) { | ||
return baseError({ code: 'empty' }); | ||
} | ||
|
||
const matchVersion = /oc-cli-([\w|.]+).*/.exec(userAgent); | ||
if (!matchVersion) { | ||
return baseError({ code: 'not_valid', cliVersion: 'not_valid' }); | ||
} | ||
|
||
const cliVersion = matchVersion[1]; | ||
if (semver.lt(cliVersion, packageInfo.version)) { | ||
return baseError({ code: 'old_version', cliVersion }); | ||
} | ||
|
||
return { isValid: true }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters