1- import   aws   =  require ( "aws-sdk" ) ; 
2- import  { DocumentClient }  from  "aws-sdk/lib/ dynamodb/document_client " ; 
1+ 
2+ import  {   DynamoDBDocumentClient ,   PutCommand ,   GetCommand ,   ScanCommand ,   DeleteCommand ,   ScanCommandInput   }  from  "@ aws-sdk/lib- dynamodb" ; 
33import  { StorageService }  from  "./storageService" ; 
4- import  { ScanInput }  from  "aws-sdk/clients/dynamodb" ; 
54import  { Pet }  from  "../models/pet" ; 
65
76export  class  DynamoDBStorageService  implements  StorageService  { 
87
98  constructor ( private  readonly  tableName : string , 
10-               private  readonly  docClient : DocumentClient   =   new   aws . DynamoDB . DocumentClient ( ) )  { 
9+               private  readonly  docClient : DynamoDBDocumentClient )  { 
1110  } 
1211
1312  public  async  getPet ( id : string ) : Promise < Pet  |  null >  { 
1413
1514    try  { 
16-       const  data  =  await  this . docClient . get ( { 
15+       const  data  =  await  this . docClient . send ( new   GetCommand ( { 
1716        TableName : this . tableName , 
1817        Key : { id} , 
1918        ConsistentRead : true , 
20-       } ) . promise ( ) ; 
19+       } ) ) ; 
2120      if  ( data  &&  data . Item )  { 
2221        return  data . Item  as  Pet ; 
2322      } 
@@ -30,10 +29,10 @@ export class DynamoDBStorageService implements StorageService {
3029
3130  public  async  savePet ( pet : Pet ) : Promise < void >  { 
3231    try  { 
33-       await  this . docClient . put ( { 
32+       await  this . docClient . send ( new   PutCommand ( { 
3433        TableName : this . tableName , 
3534        Item : pet , 
36-       } ) . promise ( ) ; 
35+       } ) ) ; 
3736    }  catch  ( ex )  { 
3837      console . warn ( "Error saving entry" ,  ex ) ; 
3938      throw  ex ; 
@@ -45,11 +44,11 @@ export class DynamoDBStorageService implements StorageService {
4544
4645      const  result : Pet [ ]  =  [ ] ; 
4746
48-       const  params : ScanInput  =  { TableName : this . tableName } ; 
47+       const  params : ScanCommandInput  =  { TableName : this . tableName } ; 
4948
5049      while  ( true )  { 
5150
52-         const  data  =  await  this . docClient . scan ( params ) . promise ( ) ; 
51+         const  data  =  await  this . docClient . send ( new   ScanCommand ( params ) ) ; 
5352        result . push ( ...data . Items  as  Pet [ ] ) ; 
5453
5554        if  ( ! data . LastEvaluatedKey )  { 
@@ -70,7 +69,7 @@ export class DynamoDBStorageService implements StorageService {
7069
7170  public  async  deletePet ( id : string ) : Promise < void >  { 
7271    try  { 
73-       await  this . docClient . delete ( { TableName : this . tableName ,  Key : { id} } ) . promise ( ) ; 
72+       await  this . docClient . send ( new   DeleteCommand ( { TableName : this . tableName ,  Key : { id} } ) ) ; 
7473    }  catch  ( ex )  { 
7574      console . warn ( "Error deleting entry" ,  ex ) ; 
7675      throw  ex ; 
0 commit comments