module import * as DynamoDB from 'aws-sdk/clients/dynamodb' ; import { Metadata } from '../../decorator/metadata/metadata' ; import { metadataForModel } from '../../decorator/metadata/metadata-for-model.function' ; import { ModelConstructor } from '../../model/model-constructor' ; import { and } from '../expression/logical-operator/and.function' ; import { addExpression } from '../expression/param-util' ; import { addCondition } from '../expression/request-expression-builder' ; import { RequestConditionFunction , RequestConditionFunctionTyped , } from '../expression/type/condition-expression-definition-chain' ; import { ConditionExpressionDefinitionFunction } from '../expression/type/condition-expression-definition-function' ; import { getTableName } from '../get-table-name.function' ; import { ConditionalParamsHost } from '../operation-params.type' ; /**
 * Abstract base class for all transact items.
 */ export abstract class TransactBaseOperation < T , I extends DynamoDB . ConditionCheck | DynamoDB . Put | DynamoDB . Update | DynamoDB . Delete , R extends TransactBaseOperation < T , I , any > > implements ConditionalParamsHost { readonly params : I ; readonly metadata : Metadata < T > ; readonly modelClazz : ModelConstructor < T > ; abstract readonly transactItem : DynamoDB . TransactWriteItem ; protected constructor ( modelClazz ) { if ( ! modelClazz ) { throw new Error ( `please provide the model class` ) ; } this . modelClazz = modelClazz ; this . metadata = metadataForModel ( this . modelClazz ) ; if ( ! this . metadata . modelOptions ) { throw new Error ( 'the given model class has no model decorator' ) ; } this . params = < I > { TableName : getTableName ( this . metadata ) , } ; } example onlyIfAttribute < K extends keyof T > ( attributePath ) ; onlyIfAttribute ( attributePath ) ; onlyIfAttribute < K extends keyof T > ( attributePath ) { return addCondition < this , T , any > ( 'ConditionExpression' , attributePath , this , this . metadata ) ; } example onlyIf ( ... conditionDefFns ) { const condition = and ( ... conditionDefFns ) ( undefined , this . metadata ) ; addExpression ( 'ConditionExpression' , condition , this . params ) ; return this ; } /**
     * get the item attributes if the condition fails
     */ returnValuesOnConditionCheckFailure ( value ) { this . params . ReturnValuesOnConditionCheckFailure = value ; return this ; } }