33 LogicalResourceId ,
44 NextToken ,
55} from 'aws-sdk/clients/cloudformation' ;
6+ import { allArgsConstructor , builder } from 'tombok' ;
7+
68
79export type Optional < T > = T | undefined | null ;
810
@@ -11,46 +13,46 @@ export interface Callable<R extends Array<any>, T> {
1113}
1214
1315export enum Action {
14- Create = " CREATE" ,
15- Read = " READ" ,
16- Update = " UPDATE" ,
17- Delete = " DELETE" ,
18- List = " LIST" ,
16+ Create = ' CREATE' ,
17+ Read = ' READ' ,
18+ Update = ' UPDATE' ,
19+ Delete = ' DELETE' ,
20+ List = ' LIST' ,
1921}
2022
2123export enum StandardUnit {
22- Count = " Count" ,
23- Milliseconds = " Milliseconds" ,
24+ Count = ' Count' ,
25+ Milliseconds = ' Milliseconds' ,
2426}
2527
2628export enum MetricTypes {
27- HandlerException = " HandlerException" ,
28- HandlerInvocationCount = " HandlerInvocationCount" ,
29- HandlerInvocationDuration = " HandlerInvocationDuration" ,
29+ HandlerException = ' HandlerException' ,
30+ HandlerInvocationCount = ' HandlerInvocationCount' ,
31+ HandlerInvocationDuration = ' HandlerInvocationDuration' ,
3032}
3133
3234export enum OperationStatus {
33- Pending = " PENDING" ,
34- InProgress = " IN_PROGRESS" ,
35- Success = " SUCCESS" ,
36- Failed = " FAILED" ,
35+ Pending = ' PENDING' ,
36+ InProgress = ' IN_PROGRESS' ,
37+ Success = ' SUCCESS' ,
38+ Failed = ' FAILED' ,
3739}
3840
3941export enum HandlerErrorCode {
40- NotUpdatable = " NotUpdatable" ,
41- InvalidRequest = " InvalidRequest" ,
42- AccessDenied = " AccessDenied" ,
43- InvalidCredentials = " InvalidCredentials" ,
44- AlreadyExists = " AlreadyExists" ,
45- NotFound = " NotFound" ,
46- ResourceConflict = " ResourceConflict" ,
47- Throttling = " Throttling" ,
48- ServiceLimitExceeded = " ServiceLimitExceeded" ,
49- NotStabilized = " NotStabilized" ,
50- GeneralServiceException = " GeneralServiceException" ,
51- ServiceInternalError = " ServiceInternalError" ,
52- NetworkFailure = " NetworkFailure" ,
53- InternalFailure = " InternalFailure" ,
42+ NotUpdatable = ' NotUpdatable' ,
43+ InvalidRequest = ' InvalidRequest' ,
44+ AccessDenied = ' AccessDenied' ,
45+ InvalidCredentials = ' InvalidCredentials' ,
46+ AlreadyExists = ' AlreadyExists' ,
47+ NotFound = ' NotFound' ,
48+ ResourceConflict = ' ResourceConflict' ,
49+ Throttling = ' Throttling' ,
50+ ServiceLimitExceeded = ' ServiceLimitExceeded' ,
51+ NotStabilized = ' NotStabilized' ,
52+ GeneralServiceException = ' GeneralServiceException' ,
53+ ServiceInternalError = ' ServiceInternalError' ,
54+ NetworkFailure = ' NetworkFailure' ,
55+ InternalFailure = ' InternalFailure' ,
5456}
5557
5658export interface Credentials {
@@ -59,27 +61,59 @@ export interface Credentials {
5961 sessionToken : string ;
6062}
6163
62- export interface RequestContext < CallbackT > {
64+ export interface RequestContext < T > {
6365 invocation : number ;
64- callbackContext : CallbackT ;
66+ callbackContext : T ;
6567 cloudWatchEventsRuleName : string ;
6668 cloudWatchEventsTargetId : string ;
6769}
6870
69- export interface BaseResourceModel {
70- serialize ( ) : Map < string , any > ;
71- deserialize ( ) : BaseResourceModel ;
71+ @builder
72+ @allArgsConstructor
73+ export class BaseResourceModel {
74+ [ 'constructor' ] : typeof BaseResourceModel ;
75+ protected static readonly TYPE_NAME ?: string ;
76+
77+ constructor ( ...args : any [ ] ) { }
78+ public static builder ( ) { }
79+
80+ public getTypeName ( ) : string {
81+ return Object . getPrototypeOf ( this ) . constructor . TYPE_NAME ;
82+ }
83+
84+ public serialize ( ) : Map < string , any > {
85+ const data : Map < string , any > = new Map < string , any > ( Object . entries ( this ) ) ;
86+ data . forEach ( ( value : any , key : string ) => {
87+ if ( value == null ) {
88+ data . delete ( key ) ;
89+ }
90+ } ) ;
91+ return data ;
92+ }
93+
94+ public static deserialize ( jsonData : Object ) : ThisType < BaseResourceModel > {
95+ return new this ( new Map < string , any > ( Object . entries ( jsonData ) ) ) ;
96+ }
97+
98+ public toObject ( ) : Object {
99+ // @ts -ignore
100+ const obj = Object . fromEntries ( this . serialize ( ) . entries ( ) ) ;
101+ return obj ;
102+ }
72103}
73104
74- export interface BaseResourceHandlerRequest < T extends BaseResourceModel > {
75- clientRequestToken : ClientRequestToken ;
76- desiredResourceState ?: T ;
77- previousResourceState ?: T ;
78- logicalResourceIdentifier ?: LogicalResourceId ;
79- nextToken ?: NextToken ;
105+ @allArgsConstructor
106+ export class BaseResourceHandlerRequest < T extends BaseResourceModel > {
107+ public clientRequestToken : ClientRequestToken ;
108+ public desiredResourceState ?: T ;
109+ public previousResourceState ?: T ;
110+ public logicalResourceIdentifier ?: LogicalResourceId ;
111+ public nextToken ?: NextToken ;
112+
113+ constructor ( ...args : any [ ] ) { }
80114}
81115
82- export interface Response < T > {
116+ export interface CfnResponse < T > {
83117 bearerToken : string ;
84118 errorCode ?: HandlerErrorCode ;
85119 operationStatus : OperationStatus ;
0 commit comments