dynamodb-doc-client-utils.js
function getItem(tableName, key, opts, desc, context) {
  try {
    const params = {
      TableName: tableName,
      Key: key
    };
    if (opts) merge(opts, params, mergeOpts);

    if (context.traceEnabled) context.trace(`Loading ${desc} from ${tableName} using params (${JSON.stringify(params)})`);

    return context.dynamoDBDocClient.get(params).promise()
      .then(result => {
        if (context.traceEnabled) context.trace(`Loaded ${desc} from ${tableName} - result (${JSON.stringify(result)})`);
        if (result && typeof result === 'object') {
          return result;
        }
        throw new TypeError(`Unexpected result from get ${desc} from ${tableName} - result (${JSON.stringify(result)})`);
      })
      .catch(err => {
        context.error(`Failed to load ${desc} from ${tableName}`, err);
        throw err;
      });

  } catch (err) {
    context.error(`Failed to load ${desc} from ${tableName}`, err);
    return Promise.reject(err);
  }
}
function getItem(tableName, key, opts, desc, context) {
  try {
    const params = {
      TableName: tableName,
      Key: key
    };
    if (opts) merge(opts, params, mergeOpts);

    if (context.traceEnabled) context.trace(`Loading ${desc} from ${tableName} using params (${JSON.stringify(params)})`);

    return context.dynamoDBDocClient.get(params).promise()
      .then(result => {
        if (context.traceEnabled) context.trace(`Loaded ${desc} from ${tableName} - result (${JSON.stringify(result)})`);
        if (result && typeof result === 'object') {
          return result;
        }
        throw new TypeError(`Unexpected result from get ${desc} from ${tableName} - result (${JSON.stringify(result)})`);
      })
      .catch(err => {
        context.error(`Failed to load ${desc} from ${tableName}`, err);
        throw err;
      });

  } catch (err) {
    context.error(`Failed to load ${desc} from ${tableName}`, err);
    return Promise.reject(err);
  }
}
function getItem ( tableName , key , opts , desc , context ) { try { const params = { TableName : tableName , Key : key } ; if ( opts ) merge ( opts , params , mergeOpts ) ; if ( context . traceEnabled ) context . trace ( ` ${ desc } ${ tableName } ${ JSON . stringify ( params ) } ` ) ; return context . dynamoDBDocClient . get ( params ) . promise ( ) . then ( result => { if ( context . traceEnabled ) context . trace ( ` ${ desc } ${ tableName } ${ JSON . stringify ( result ) } ` ) ; if ( result && typeof result === 'object' ) { return result ; } throw new TypeError ( ` ${ desc } ${ tableName } ${ JSON . stringify ( result ) } ` ) ; } ) . catch ( err => { context . error ( ` ${ desc } ${ tableName } ` , err ) ; throw err ; } ) ; } catch ( err ) { context . error ( ` ${ desc } ${ tableName } ` , err ) ; return Promise . reject ( err ) ; } }
Gets the item with the given key from the named DynamoDB table.
@param {string} tableName - the name of the DynamoDB table from which to load
@param {K} key - the key of the item to get
@param {DynamoGetOpts|undefined} [opts] - optional DynamoDB `get` parameter options to use
@param {string} desc - a description of the item being requested for logging purposes
@param {StandardContext} context - the context to use
@return {Promise.<DynamoGetResult.<I>>} a promise that will resolve with the result or reject with an error
@template I,K
Gets the item with the given key from the named DynamoDB table .