1
- import jscodeshift , {
2
- type Identifier ,
3
- type TSFunctionType ,
4
- type TSQualifiedName ,
5
- type TSTypeReference ,
6
- } from "jscodeshift" ;
1
+ import jscodeshift from "jscodeshift" ;
7
2
8
3
import { getTypesSource } from "./getTypesSource" ;
9
4
@@ -23,58 +18,58 @@ export const getClientReqRespTypesMap = async (
23
18
if ( classMethod . key . name === "constructor" ) return ;
24
19
if ( classMethod . key . name . startsWith ( "waitFor" ) ) return ;
25
20
26
- const classMethodKeyName = ( classMethod . key as Identifier ) . name ;
21
+ const classMethodKeyName = classMethod . key . name ;
27
22
const commandName = classMethodKeyName . charAt ( 0 ) . toUpperCase ( ) + classMethodKeyName . slice ( 1 ) ;
28
23
29
24
if ( classMethod . params . length !== 2 ) return ;
30
25
if ( classMethod . params [ 0 ] . type !== "Identifier" ) return ;
31
26
if ( classMethod . params [ 0 ] . name !== "params" ) return ;
32
27
33
- const params = classMethod . params [ 0 ] as Identifier ;
28
+ const params = classMethod . params [ 0 ] ;
34
29
35
30
if ( ! params . typeAnnotation ) return ;
36
31
if ( ! params . typeAnnotation . typeAnnotation ) return ;
37
32
if ( params . typeAnnotation . typeAnnotation . type !== "TSTypeReference" ) return ;
38
- const paramsTypeRef = params . typeAnnotation . typeAnnotation as TSTypeReference ;
33
+ const paramsTypeRef = params . typeAnnotation . typeAnnotation ;
39
34
40
35
if ( ! paramsTypeRef . typeName ) return ;
41
36
if ( paramsTypeRef . typeName . type !== "TSQualifiedName" ) return ;
42
- const paramsTypeRefName = paramsTypeRef . typeName as TSQualifiedName ;
37
+ const paramsTypeRefName = paramsTypeRef . typeName ;
43
38
44
39
if ( ! paramsTypeRefName . right ) return ;
45
40
if ( paramsTypeRefName . right . type !== "Identifier" ) return ;
46
- const paramsTypeName = paramsTypeRefName . right as Identifier ;
41
+ const paramsTypeName = paramsTypeRefName . right ;
47
42
const requestTypeName = paramsTypeName . name ;
48
43
49
44
clientTypesMap [ requestTypeName ] = `${ commandName } CommandInput` ;
50
45
51
46
if ( classMethod . params [ 1 ] . type !== "Identifier" ) return ;
52
47
if ( classMethod . params [ 1 ] . name !== "callback" ) return ;
53
- const callback = classMethod . params [ 1 ] as Identifier ;
48
+ const callback = classMethod . params [ 1 ] ;
54
49
55
50
if ( ! callback . typeAnnotation ) return ;
56
51
if ( ! callback . typeAnnotation . typeAnnotation ) return ;
57
52
if ( callback . typeAnnotation . typeAnnotation . type !== "TSFunctionType" ) return ;
58
- const callbackTypeRef = callback . typeAnnotation . typeAnnotation as TSFunctionType ;
53
+ const callbackTypeRef = callback . typeAnnotation . typeAnnotation ;
59
54
60
55
if ( ! callbackTypeRef . parameters ) return ;
61
56
if ( callbackTypeRef . parameters . length !== 2 ) return ;
62
57
if ( callbackTypeRef . parameters [ 1 ] . type !== "Identifier" ) return ;
63
- const responseType = callbackTypeRef . parameters [ 1 ] as Identifier ;
58
+ const responseType = callbackTypeRef . parameters [ 1 ] ;
64
59
65
60
if ( ! responseType . typeAnnotation ) return ;
66
61
if ( responseType . typeAnnotation . type !== "TSTypeAnnotation" ) return ;
67
62
if ( ! responseType . typeAnnotation . typeAnnotation ) return ;
68
63
if ( responseType . typeAnnotation . typeAnnotation . type !== "TSTypeReference" ) return ;
69
- const responseTypeRef = responseType . typeAnnotation . typeAnnotation as TSTypeReference ;
64
+ const responseTypeRef = responseType . typeAnnotation . typeAnnotation ;
70
65
71
66
if ( ! responseTypeRef . typeName ) return ;
72
67
if ( responseTypeRef . typeName . type !== "TSQualifiedName" ) return ;
73
- const responseTypeRefName = responseTypeRef . typeName as TSQualifiedName ;
68
+ const responseTypeRefName = responseTypeRef . typeName ;
74
69
75
70
if ( ! responseTypeRefName . right ) return ;
76
71
if ( responseTypeRefName . right . type !== "Identifier" ) return ;
77
- const responseTypeName = ( responseTypeRefName . right as Identifier ) . name ;
72
+ const responseTypeName = responseTypeRefName . right . name ;
78
73
79
74
clientTypesMap [ responseTypeName ] = `${ commandName } CommandOutput` ;
80
75
} ) ;
0 commit comments