module import * as DynamoDB from 'aws-sdk/clients/dynamodb' ; import { promiseTap } from '../../helper/promise-tap.function' ; import { Logger } from '../../logger/logger' ; import { fromDb } from '../../mapper/mapper' ; import { Attributes } from '../../mapper/type/attribute.type' ; import { ModelConstructor } from '../../model/model-constructor' ; import { Omit } from '../../model/omit.type' ; import { DynamoDbWrapper } from '../dynamo-db-wrapper' ; import { and } from '../expression/logical-operator/public.api' ; 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 { StandardRequest } from './standard.request' ; type WriteResponse < O extends DynamoDB . DeleteItemOutput | DynamoDB . PutItemOutput | DynamoDB . UpdateItemOutput , T > = Omit < O , 'Attributes' > ; /**
 * abstract class for all basic write request classes (DeleteItem, PutItem, UpdateItem
 */ export abstract class WriteRequest < T , T2 , I extends DynamoDB . DeleteItemInput | DynamoDB . PutItemInput | DynamoDB . UpdateItemInput , O extends DynamoDB . DeleteItemOutput | DynamoDB . PutItemOutput | DynamoDB . UpdateItemOutput , R extends WriteRequest < T , T2 , I , O , R > > extends StandardRequest < T , T2 , I , R > { protected abstract readonly logger : Logger ; protected constructor ( dynamoDBWrapper , modelClazz ) { super ( dynamoDBWrapper , modelClazz ) ; } protected abstract doRequest ( params ) ; /**
     * return item collection metrics.
     */ returnItemCollectionMetrics ( returnItemCollectionMetrics ) { this . params . ReturnItemCollectionMetrics = returnItemCollectionMetrics ; return this ; } param attributePath onlyIfAttribute < K extends keyof T > ( attributePath ) ; onlyIfAttribute ( attributePath ) ; onlyIfAttribute < K extends keyof T > ( attributePath ) { return addCondition < this , T , any > ( 'ConditionExpression' , attributePath , < any > this , this . metadata ) ; } example example onlyIf ( ... conditionDefFns ) { const condition = and ( ... conditionDefFns ) ( undefined , this . metadata ) ; addExpression ( 'ConditionExpression' , condition , this . params ) ; return this ; } returns { void } exec ( ) { return this . execFullResponse ( ) . then ( ( r ) => ( < any > r ) . Item ) ; } /**
     * execute request and return the full response
     */ execFullResponse ( ) { this . logger . debug ( 'request' , this . params ) ; return this . doRequest ( this . params ) . then ( promiseTap ( ( response ) => this . logger . debug ( 'response' , response ) ) ) . then ( ( resp ) => { const attrs = resp . Attributes ; delete resp . Attributes ; const r = < WriteResponse < O , T > > resp ; if ( typeof attrs === 'object' && attrs !== null ) { ; ( < any > r ) . Item = fromDb ( < Attributes < T > > attrs , this . modelClazz ) ; } return r ; } ) . then ( promiseTap ( ( resp ) => this . logger . debug ( 'mapped response' , resp ) ) ) ; } /**
     * execute request without parsing (mapping) the response attributes to js objects
     */ execNoMap ( ) { this . logger . debug ( 'request' , this . params ) ; return this . doRequest ( this . params ) . then ( promiseTap ( ( response ) => this . logger . debug ( 'response' , response ) ) ) ; } }