55
66import { APIGateway } from 'aws-sdk'
77import { RestApi , Stages } from 'aws-sdk/clients/apigateway'
8- import globals from '../extensionGlobals'
9-
10- export class ApiGatewayClient {
11- public constructor ( public readonly regionCode : string ) { }
12-
13- public async * getResourcesForApi ( apiId : string ) : AsyncIterableIterator < APIGateway . Resource > {
14- const client = await this . createSdkClient ( )
8+ import { ClientWrapper } from './clientWrapper'
9+ import {
10+ APIGatewayClient as ApiGatewayClientSDK ,
11+ GetResourcesCommand ,
12+ GetResourcesRequest ,
13+ GetRestApisCommand ,
14+ GetStagesCommand ,
15+ Resource ,
16+ Resources ,
17+ RestApis ,
18+ TestInvokeMethodCommand ,
19+ TestInvokeMethodRequest ,
20+ TestInvokeMethodResponse ,
21+ } from '@aws-sdk/client-api-gateway'
22+
23+ export class ApiGatewayClient extends ClientWrapper < ApiGatewayClientSDK > {
24+ public constructor ( regionCode : string ) {
25+ super ( regionCode , ApiGatewayClientSDK )
26+ }
1527
16- const request : APIGateway . GetResourcesRequest = {
28+ public async * getResourcesForApi ( apiId : string ) : AsyncIterableIterator < Resource > {
29+ const request : GetResourcesRequest = {
1730 restApiId : apiId ,
1831 }
1932
2033 do {
21- const response : APIGateway . Resources = await client . getResources ( request ) . promise ( )
34+ const response : Resources = await this . makeRequest ( GetResourcesCommand , request )
2235
2336 if ( response . items !== undefined && response . items . length > 0 ) {
2437 yield * response . items
@@ -29,22 +42,16 @@ export class ApiGatewayClient {
2942 }
3043
3144 public async getStages ( apiId : string ) : Promise < Stages > {
32- const client = await this . createSdkClient ( )
33-
34- const request : APIGateway . GetResourcesRequest = {
45+ return this . makeRequest ( GetStagesCommand , {
3546 restApiId : apiId ,
36- }
37-
38- return client . getStages ( request ) . promise ( )
47+ } )
3948 }
4049
4150 public async * listApis ( ) : AsyncIterableIterator < RestApi > {
42- const client = await this . createSdkClient ( )
43-
4451 const request : APIGateway . GetRestApisRequest = { }
4552
4653 do {
47- const response : APIGateway . RestApis = await client . getRestApis ( request ) . promise ( )
54+ const response : RestApis = await this . makeRequest ( GetRestApisCommand , request )
4855
4956 if ( response . items !== undefined && response . items . length > 0 ) {
5057 yield * response . items
@@ -60,9 +67,8 @@ export class ApiGatewayClient {
6067 method : string ,
6168 body : string ,
6269 pathWithQueryString : string | undefined
63- ) : Promise < APIGateway . TestInvokeMethodResponse > {
64- const client = await this . createSdkClient ( )
65- const request : APIGateway . TestInvokeMethodRequest = {
70+ ) : Promise < TestInvokeMethodResponse > {
71+ const request : TestInvokeMethodRequest = {
6672 restApiId : apiId ,
6773 resourceId : resourceId ,
6874 httpMethod : method ,
@@ -72,10 +78,6 @@ export class ApiGatewayClient {
7278 request . pathWithQueryString = pathWithQueryString
7379 }
7480
75- return await client . testInvokeMethod ( request ) . promise ( )
76- }
77-
78- private async createSdkClient ( ) : Promise < APIGateway > {
79- return await globals . sdkClientBuilder . createAwsService ( APIGateway , undefined , this . regionCode )
81+ return this . makeRequest ( TestInvokeMethodCommand , request )
8082 }
8183}
0 commit comments