File tree Expand file tree Collapse file tree 5 files changed +22
-16
lines changed
src/registry/domain/validators Expand file tree Collapse file tree 5 files changed +22
-16
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ interface ValidationResult {
30
30
export default function componentParameters (
31
31
requestParameters : Dictionary < string | number | boolean > ,
32
32
expectedParameters : Dictionary < OcParameter > = { }
33
- ) {
33
+ ) : ValidationResult {
34
34
const result : ValidationResult = { isValid : true , errors : { } } ;
35
35
const mandatoryParameters : string [ ] = [ ] ;
36
36
@@ -45,6 +45,7 @@ export default function componentParameters(
45
45
for ( const mandatoryParameterName of mandatoryParameters ) {
46
46
if (
47
47
typeof requestParameters === 'object' &&
48
+ // eslint-disable-next-line no-prototype-builtins
48
49
! requestParameters . hasOwnProperty ( mandatoryParameterName )
49
50
) {
50
51
if ( ! result . errors . mandatory ) {
@@ -62,6 +63,7 @@ export default function componentParameters(
62
63
) ) {
63
64
if (
64
65
typeof expectedParameters === 'object' &&
66
+ // eslint-disable-next-line no-prototype-builtins
65
67
expectedParameters . hasOwnProperty ( requestParameterName )
66
68
) {
67
69
const expectedType = expectedParameters [ requestParameterName ] . type ;
Original file line number Diff line number Diff line change @@ -9,10 +9,8 @@ import registryConfigurationValidator from './registry-configuration';
9
9
import uploadedPackageValidator from './uploaded-package' ;
10
10
import nodeVersionValidator from './node-version' ;
11
11
12
- export function validateComponentName ( componentName : string ) {
13
- return (
14
- ! / [ ^ a - z A - Z 0 - 9 \- \_ ] / . test ( componentName ) && componentName !== '_package'
15
- ) ;
12
+ export function validateComponentName ( componentName : string ) : boolean {
13
+ return ! / [ ^ a - z A - Z 0 - 9 \- _ ] / . test ( componentName ) && componentName !== '_package' ;
16
14
}
17
15
export const validateComponentParameters = componentParametersValidator ;
18
16
export const validateNodeVersion = nodeVersionValidator ;
@@ -21,6 +19,6 @@ export const validatePackage = uploadedPackageValidator;
21
19
export const validatePackageJson = packageJsonValidator ;
22
20
export const validatePluginsRequirements = pluginsRequirementsValidator ;
23
21
export const validateRegistryConfiguration = registryConfigurationValidator ;
24
- export function validateVersion ( version : string ) {
22
+ export function validateVersion ( version : string ) : boolean {
25
23
return ! ! semver . valid ( version ) ;
26
24
}
Original file line number Diff line number Diff line change @@ -7,13 +7,19 @@ type ValidationResult =
7
7
| { isValid : false ; missing : string [ ] } ;
8
8
9
9
export default function pluginsRequirements (
10
- componentRequirements : string [ ] ,
10
+ componentRequirements :
11
+ | Record < string , ( ...args : unknown [ ] ) => unknown >
12
+ | string [ ]
13
+ | null
14
+ | undefined ,
11
15
registryPlugins : Config [ 'plugins' ]
12
16
) : ValidationResult {
13
- const result = { isValid : true } ;
14
17
const missing : string [ ] = [ ] ;
18
+ const requiredPlugins = Array . isArray ( componentRequirements )
19
+ ? componentRequirements
20
+ : Object . keys ( componentRequirements || { } ) ;
15
21
16
- for ( const requiredPlugin of componentRequirements || [ ] ) {
22
+ for ( const requiredPlugin of requiredPlugins ) {
17
23
if (
18
24
! registryPlugins ||
19
25
! Object . keys ( registryPlugins ) . includes ( requiredPlugin )
Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ import { Config } from '../../../types';
4
4
5
5
type ValidationResult = { isValid : true } | { isValid : false ; message : string } ;
6
6
7
- export default function registryConfiguration ( conf : Config ) : ValidationResult {
7
+ export default function registryConfiguration (
8
+ conf : Partial < Config >
9
+ ) : ValidationResult {
8
10
const returnError = ( message : string ) : ValidationResult => {
9
11
return {
10
12
isValid : false ,
@@ -69,10 +71,10 @@ export default function registryConfiguration(conf: Config): ValidationResult {
69
71
) ;
70
72
}
71
73
72
- if ( route . route . indexOf ( prefix ) === 0 ) {
74
+ if ( route . route . indexOf ( prefix || '' ) === 0 ) {
73
75
return returnError (
74
76
strings . errors . registry . CONFIGURATION_ROUTES_ROUTE_CONTAINS_PREFIX (
75
- prefix
77
+ prefix || ''
76
78
)
77
79
) ;
78
80
}
Original file line number Diff line number Diff line change 1
- import _ from 'lodash' ;
2
-
3
1
type ValidationResponse =
4
2
| {
5
3
isValid : true ;
@@ -16,7 +14,7 @@ export default function uploadedPackage(
16
14
[ fieldname : string ] : Express . Multer . File [ ] ;
17
15
}
18
16
) : ValidationResponse {
19
- const returnError = function ( message ) : ValidationResponse {
17
+ const returnError = function ( message ?: string ) : ValidationResponse {
20
18
return {
21
19
isValid : false ,
22
20
message : message || 'uploaded package is not valid'
@@ -31,7 +29,7 @@ export default function uploadedPackage(
31
29
return returnError ( 'not_valid' ) ;
32
30
}
33
31
34
- const file = input [ 0 ] ;
32
+ const file : Express . Multer . File = ( input as any ) [ 0 ] ;
35
33
const validTypes = [ 'application/gzip' , 'application/octet-stream' ] ;
36
34
37
35
if (
You can’t perform that action at this time.
0 commit comments