import 'reflect-metadata' ; import { ClientRequestToken , LogGroupName , LogicalResourceId , NextToken , } from 'aws-sdk/clients/cloudformation' ; import { Service } from 'aws-sdk/lib/service' ; import { classToPlain , ClassTransformOptions , Exclude , Expose , plainToClass , } from 'class-transformer' ; export type Optional < T > = T | undefined | null ; export type Dict < T = any > = Record < string , T > ; export type Constructor < T = { } > = new ( ... args ) => T ; export type integer = bigint ; export type InstanceProperties < T extends object = Service , C extends Constructor < T > = Constructor < T > > = keyof InstanceType < C > ; export type ServiceProperties < S extends Service = Service , C extends Constructor < S > = Constructor < S > > = Exclude < InstanceProperties < S , C > , InstanceProperties < Service , Constructor < Service > > > ; export type OverloadedArguments < T > = T extends { ( ... args ) : any ; ( params , callback ) : any ; ( callback ) : any ; } ? P : T extends { ( params , callback ) : any ; ( callback ) : any ; } ? P : T extends ( params : infer P , callback : any ) => any ? P : any ; export type OverloadedReturnType < T > = T extends { ( ... args ) : any ; ( params , callback ) : infer R ; ( callback ) : any ; } ? R : T extends { ( params , callback ) : infer R ; ( callback ) : any ; } ? R : T extends ( callback : any ) => infer R ? R : any ; export interface Callable < R extends Array < any > , T > { ( ... args ) : T ; } interface Integer extends BigInt { /**
     * Defines the default JSON representation of
     * Integer (BigInt) to be a number.
     */ toJSON ( ) : number ; /** Returns the primitive value of the specified object. */ valueOf ( ) : integer ; } interface IntegerConstructor extends BigIntConstructor { ( value ? ) : integer ; readonly prototype : Integer ; param value isSafeInteger ( value ) : boolean ; } /**
 * Wrapper with additional JSON serialization for bigint type
 */ export const Integer = new Proxy ( BigInt , { apply ( target , _thisArg , argArray ? ) { target . prototype . toJSON = function ( ) : number { return Number ( this . valueOf ( ) ) ; } ; const isSafeInteger = ( value ) : boolean => { if ( value && ( value < BigInt ( Number . MIN_SAFE_INTEGER ) || value > BigInt ( Number . MAX_SAFE_INTEGER ) ) ) { return false ; } return true ; } ; target . isSafeInteger = isSafeInteger ; const value = target ( ... argArray ) ; if ( value && ! isSafeInteger ( value ) ) { throw new RangeError ( `Value is not a safe integer: ${ value . toString ( ) }` ) ; } return value ; } , } ) as IntegerConstructor ; export enum Action { Create = 'CREATE' , Read = 'READ' , Update = 'UPDATE' , Delete = 'DELETE' , List = 'LIST' } export enum StandardUnit { Count = 'Count' , Milliseconds = 'Milliseconds' } export enum MetricTypes { HandlerException = 'HandlerException' , HandlerInvocationCount = 'HandlerInvocationCount' , HandlerInvocationDuration = 'HandlerInvocationDuration' } export enum OperationStatus { Pending = 'PENDING' , InProgress = 'IN_PROGRESS' , Success = 'SUCCESS' , Failed = 'FAILED' } export enum HandlerErrorCode { NotUpdatable = 'NotUpdatable' , InvalidRequest = 'InvalidRequest' , AccessDenied = 'AccessDenied' , InvalidCredentials = 'InvalidCredentials' , AlreadyExists = 'AlreadyExists' , NotFound = 'NotFound' , ResourceConflict = 'ResourceConflict' , Throttling = 'Throttling' , ServiceLimitExceeded = 'ServiceLimitExceeded' , NotStabilized = 'NotStabilized' , GeneralServiceException = 'GeneralServiceException' , ServiceInternalError = 'ServiceInternalError' , NetworkFailure = 'NetworkFailure' , InternalFailure = 'InternalFailure' } export interface Credentials { accessKeyId : string ; secretAccessKey : string ; sessionToken : string ; } /**
 * Base class for data transfer objects that will contain
 * serialization and deserialization mechanisms.
 */ export abstract class BaseDto { constructor ( partial ? ) { if ( partial ) { Object . assign ( this , partial ) ; } } @ Exclude ( ) static serializer = { classToPlain , plainToClass , } ; @ Exclude ( ) public serialize ( removeNull = true ) { const data = JSON . parse ( JSON . stringify ( classToPlain ( this ) ) ) ; if ( removeNull ) { for ( const key in data ) { const value = data [ key ] ; if ( value == null ) { delete data [ key ] ; } } } return data ; } public static deserialize < T extends BaseDto > ( this , jsonData , options = { } ) { if ( jsonData == null ) { return null ; } return plainToClass ( this , jsonData , { enableImplicitConversion : false , excludeExtraneousValues : true , ... options , } ) ; } @ Exclude ( ) public toJSON ( key ? ) { return this . serialize ( ) ; } } export interface RequestContext < T > { invocation : number ; callbackContext : T ; cloudWatchEventsRuleName : string ; cloudWatchEventsTargetId : string ; } export class BaseModel extends BaseDto { [ 'constructor' ] : typeof BaseModel ; @ Exclude ( ) protected static readonly TYPE_NAME ? : string ; @ Exclude ( ) public getTypeName ( ) { return Object . getPrototypeOf ( this ) . constructor . TYPE_NAME ; } } export class TestEvent extends BaseDto { @ Expose ( ) credentials : Credentials ; @ Expose ( ) action : Action ; @ Expose ( ) request : Dict ; @ Expose ( ) callbackContext : Dict ; @ Expose ( ) region ? : string ; } export class RequestData < T = Dict > extends BaseDto { @ Expose ( ) resourceProperties : T ; @ Expose ( ) providerLogGroupName ? : LogGroupName ; @ Expose ( ) logicalResourceId ? : LogicalResourceId ; @ Expose ( ) systemTags ? : Dict < string > ; @ Expose ( ) stackTags ? : Dict < string > ; @ Expose ( ) callerCredentials ? : Credentials ; @ Expose ( ) providerCredentials ? : Credentials ; @ Expose ( ) previousResourceProperties ? : T ; @ Expose ( ) previousStackTags ? : Dict < string > ; } export class HandlerRequest < ResourceT = Dict , CallbackT = Dict > extends BaseDto { @ Expose ( ) action : Action ; @ Expose ( ) awsAccountId : string ; @ Expose ( ) bearerToken : string ; @ Expose ( ) region : string ; @ Expose ( ) requestData : RequestData < ResourceT > ; @ Expose ( ) responseEndpoint ? : string ; @ Expose ( ) stackId ? : string ; @ Expose ( ) resourceType ? : string ; @ Expose ( ) resourceTypeVersion ? : string ; @ Expose ( ) callbackContext ? : CallbackT ; @ Expose ( ) nextToken ? : NextToken ; @ Expose ( ) requestContext ? : RequestContext < CallbackT > ; } export class BaseResourceHandlerRequest < T extends BaseModel > extends BaseDto { @ Expose ( ) clientRequestToken : ClientRequestToken ; @ Expose ( ) desiredResourceState ? : T ; @ Expose ( ) previousResourceState ? : T ; @ Expose ( ) desiredResourceTags : Dict < string > ; @ Expose ( ) previousResourceTags : Dict < string > ; @ Expose ( ) systemTags : Dict < string > ; @ Expose ( ) awsAccountId : string ; @ Expose ( ) awsPartition : string ; @ Expose ( ) logicalResourceIdentifier ? : LogicalResourceId ; @ Expose ( ) nextToken ? : NextToken ; @ Expose ( ) region : string ; } export class UnmodeledRequest extends BaseResourceHandlerRequest < BaseModel > { @ Exclude ( ) public static fromUnmodeled ( obj ) { return UnmodeledRequest . deserialize ( obj ) ; } @ Exclude ( ) public static getPartition ( region ) { if ( ! region ) { return null ; } if ( region . startsWith ( 'cn' ) ) { return 'aws-cn' ; } if ( region . startsWith ( 'us-gov' ) ) { return 'aws-gov' ; } return 'aws' ; } @ Exclude ( ) public toModeled < T extends BaseModel = BaseModel > ( modelTypeReference ) { const request = BaseResourceHandlerRequest . deserialize < BaseResourceHandlerRequest < T > > ( { clientRequestToken : this . clientRequestToken , desiredResourceTags : this . desiredResourceTags , previousResourceTags : this . previousResourceTags , systemTags : this . systemTags , awsAccountId : this . awsAccountId , logicalResourceIdentifier : this . logicalResourceIdentifier , nextToken : this . nextToken , region : this . region , awsPartition : UnmodeledRequest . getPartition ( this . region ) , } ) ; request . desiredResourceState = modelTypeReference . deserialize ( this . desiredResourceState || { } ) ; request . previousResourceState = modelTypeReference . deserialize ( this . previousResourceState || { } ) ; return request ; } } export interface CfnResponse < T extends BaseModel > { errorCode ? : HandlerErrorCode ; status : OperationStatus ; message : string ; resourceModel ? : T ; resourceModels ? : T [ ] ; nextToken ? : NextToken ; } export interface LambdaContext { functionName ? : string ; functionVersion ? : string ; invokedFunctionArn ? : string ; memoryLimitInMB ? : number ; awsRequestId ? : string ; callbackWaitsForEmptyEventLoop ? : boolean ; getRemainingTimeInMillis ( ) : number ; }