UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

32 lines (31 loc) 1.3 kB
import { DynamoDBToolboxError } from '../errors/index.js'; export const selectOptions = [ 'ALL_ATTRIBUTES', 'ALL_PROJECTED_ATTRIBUTES', 'COUNT', 'SPECIFIC_ATTRIBUTES' ]; export const selectOptionsSet = new Set(selectOptions); export const parseSelectOption = (select, { index, attributes } = {}) => { if (!selectOptionsSet.has(select)) { throw new DynamoDBToolboxError('options.invalidSelectOption', { message: `Invalid select option: '${String(select)}'. 'select' must be one of: ${[ ...selectOptionsSet ].join(', ')}.`, payload: { select } }); } if (select === 'ALL_PROJECTED_ATTRIBUTES' && index === undefined) { throw new DynamoDBToolboxError('options.invalidSelectOption', { message: `Invalid select option: '${String(select)}'. Please provide an 'index' option.`, payload: { select } }); } if (attributes !== undefined && select !== 'SPECIFIC_ATTRIBUTES') { throw new DynamoDBToolboxError('options.invalidSelectOption', { message: `Invalid select option: '${String(select)}'. Select must be 'SPECIFIC_ATTRIBUTES' if a filter expression has been provided.`, payload: { select } }); } return select; };