1- import { AWSError , CredentialProviderChain , Request , Service } from 'aws-sdk' ;
21import { ConfigurationOptions } from 'aws-sdk/lib/config' ;
3- import { Credentials , CredentialsOptions } from 'aws-sdk/lib/credentials' ;
4- import { ServiceConfigurationOptions } from 'aws-sdk/lib/service' ;
2+ import { CredentialsOptions } from 'aws-sdk/lib/credentials' ;
53import * as Aws from 'aws-sdk/clients/all' ;
64import { NextToken } from 'aws-sdk/clients/cloudformation' ;
75import { allArgsConstructor , builder , IBuilder } from 'tombok' ;
86
97import {
108 BaseResourceHandlerRequest ,
119 BaseResourceModel ,
12- Callable ,
1310 HandlerErrorCode ,
14- Newable ,
1511 OperationStatus ,
1612} from './interface' ;
1713
1814
1915type ClientMap = typeof Aws ;
2016type Client = InstanceType < ClientMap [ keyof ClientMap ] > ;
21- type ClientType < T = ClientMap > = T [ keyof T ] extends Service ? never : T [ keyof T ] ;
22-
23- // type Async<T> = T extends AsyncGenerator<infer R> ? AsyncGenerator<R> : T extends Generator<infer R> ? AsyncGenerator<R> : T extends Promise<infer R> ? Promise<R> : Promise<T>;
24-
25- // type ProxyModule<M> = {
26- // [K in keyof M]: M[K] extends (...args: infer A) => infer R ? (...args: A) => Async<R> : never;
27- // };
28-
29- // type Callback<D> = (err: AWSError | undefined, data: D) => void;
30-
31- // interface AWSRequestMethod<P, D> {
32- // (params: P, callback?: Callback<D>): Request<D, AWSError>;
33- // (callback?: Callback<D>): Request<D, AWSError>;
34- // }
35-
36- // export type CapturedAWSClient<C extends AWSClient> = {
37- // [K in keyof C]: C[K] extends AWSRequestMethod<infer P, infer D>
38- // ? AWSRequestMethod<P, D>
39- // : C[K];
40- // };
41-
42- // export type CapturedAWS<T = ClientMap> = {
43- // [K in keyof T]: T[K] extends AWSClient ? CapturedAWSClient<T[K]> : T[K];
44- // };
45-
46- // export function captureAWSClient<C extends AWSClient>(
47- // client: C
48- // ): CapturedAWSClient<C>;
49- // export function captureAWS(awssdk: ClientMap): CapturedAWS;
50-
51- // type Clients = { [K in keyof AwsClientMap]?: AwsClientMap[K] extends Service ? never : AwsClientMap[K] };
52-
53- class SessionCredentialsProvider {
54-
55- private awsSessionCredentials : Credentials ;
56-
57- public get ( ) : Credentials {
58- return this . awsSessionCredentials ;
59- }
60-
61- public setCredentials ( credentials : CredentialsOptions ) : void {
62- this . awsSessionCredentials = new Credentials ( credentials ) ;
63- }
64- }
6517
6618export class SessionProxy {
6719
@@ -75,37 +27,7 @@ export class SessionProxy {
7527 ...this . options ,
7628 ...options ,
7729 } ) ;
78- return service ; //this.promisifyReturn(service);
79- }
80-
81- // private createService<T extends ClientMap, K extends keyof T>(client: Newable<T[K]>, options: ServiceConfigurationOptions): InstanceType<ClientType> {
82- // // const clients: { [K in keyof ClientMap]?: ClientMap[K] } = Aws;
83- // // const name: T;
84-
85- // return new client();
86- // }
87-
88- // Wraps an Aws endpoint instance so that you don’t always have to chain `.promise()` onto every function
89- public promisifyReturn ( obj : any ) : ProxyConstructor {
90- return new Proxy ( obj , {
91- get ( target , propertyKey ) {
92- const property = target [ propertyKey ] ;
93-
94- if ( typeof property === "function" ) {
95- return function ( ...args : any [ ] ) {
96- const result = property . apply ( this , args ) ;
97-
98- if ( result instanceof Request ) {
99- return result . promise ( ) ;
100- } else {
101- return result ;
102- }
103- }
104- } else {
105- return property ;
106- }
107- } ,
108- } ) ;
30+ return service ;
10931 }
11032
11133 public static getSession ( credentials ?: CredentialsOptions , region ?: string ) : SessionProxy | null {
@@ -152,7 +74,7 @@ export class ProgressEvent<R extends BaseResourceModel = BaseResourceModel, T =
15274 * A callback will be scheduled with an initial delay of no less than the number
15375 * of seconds specified in the progress event.
15476 */
155- public callbackDelaySeconds : number ;
77+ public callbackDelaySeconds : number = 0 ;
15678
15779 /**
15880 * The output resource instance populated by a READ for synchronous results and
@@ -176,7 +98,6 @@ export class ProgressEvent<R extends BaseResourceModel = BaseResourceModel, T =
17698
17799 public serialize (
178100 toTesponse : boolean = false , bearerToken ?: string
179- // ): Record<string, any> {
180101 ) : Map < string , any > {
181102 // To match Java serialization, which drops `null` values, and the
182103 // contract tests currently expect this also.
@@ -226,14 +147,33 @@ export class ProgressEvent<R extends BaseResourceModel = BaseResourceModel, T =
226147 /**
227148 * Convenience method for constructing IN_PROGRESS response
228149 */
229- public static progress ( model : any , cxt : any ) : ProgressEvent {
230- const event = ProgressEvent . builder ( )
231- . callbackContext ( cxt )
232- . resourceModel ( model )
233- . status ( OperationStatus . InProgress )
234- . build ( ) ;
150+ public static progress ( model ?: any , ctx ?: any ) : ProgressEvent {
151+ const progress = ProgressEvent . builder ( )
152+ . status ( OperationStatus . InProgress ) ;
153+ if ( ctx ) {
154+ progress . callbackContext ( ctx ) ;
155+ }
156+ if ( model ) {
157+ progress . resourceModel ( model ) ;
158+ }
159+ const event = progress . build ( ) ;
160+ return event ;
161+ }
162+
163+ /**
164+ * Convenience method for constructing a SUCCESS response
165+ */
166+ public static success ( model ?: any , ctx ?: any ) : ProgressEvent {
167+ const event = ProgressEvent . progress ( model , ctx ) ;
168+ event . status = OperationStatus . Success ;
235169 return event ;
236170 }
171+
172+ public toObject ( ) : Object {
173+ // @ts -ignore
174+ const obj : Object = Object . fromEntries ( this . serialize ( ) . entries ( ) ) ;
175+ return obj ;
176+ }
237177}
238178
239179/**
0 commit comments