-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathsdk-info.ts
48 lines (43 loc) · 1.47 KB
/
sdk-info.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Normalize a service name from:
*
* - A full SDKv3 package name
* - A partial SDKv3 package name
* - An SDKv2 constructor name
*
* To a partial SDKv3 package name.
*/
export function normalizeServiceName(service: string) {
service = service.toLowerCase(); // Lowercase
service = service.replace(/^@aws-sdk\/client-/, ''); // Strip the start of a V3 package name
service = v2ToV3Mapping()?.[service] ?? service; // Optionally map v2 name -> v3 name
return service;
}
/**
* Normalize an action name from:
*
* - camelCase SDKv2 method name
* - PascalCase API name
* - SDKv3 command class name
*
* To a PascalCase API name.
*/
export function normalizeActionName(v3Service: string, action: string) {
if (action.charAt(0).toLowerCase() === action.charAt(0)) {
return action.charAt(0).toUpperCase() + action.slice(1);
}
// If the given word is in the APIs ending in 'Command' for this service,
// return as is. Otherwise, return with a potential 'Command' suffix stripped.
if (v3Metadata()[v3Service]?.commands?.includes(action)) {
return action;
}
return action.replace(/Command$/, '');
}
function v2ToV3Mapping(): Record<string, string> {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require('./sdk-v2-to-v3.json');
}
function v3Metadata(): Record<string, { iamPrefix?: string; commands?: string[] }> {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require('./sdk-v3-metadata.json');
}