dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
23 lines (22 loc) • 1.19 kB
JavaScript
import { DynamoDBToolboxError } from '../../../../../errors/index.js';
import { isObject } from '../../../../../utils/validation/isObject.js';
import { isString } from '../../../../../utils/validation/isString.js';
export const getComparedSubSchemas = (schemaFinder, comparedValue, transform) => isObject(comparedValue) &&
'attr' in comparedValue &&
isString(comparedValue.attr) &&
/**
* @debt v3 "Adding this check as syntax can conflict with `any` attribute w. object values. Rework syntax to { attr: 'path', eqAttr: 'otherPath' } to disambiguate"
*/
transform !== true
? schemaFinder.search(comparedValue.attr)
: undefined;
export const joinDedupedConditions = (dedupedConditions, attributePath) => {
const [conditionsHead, ...conditionsTail] = dedupedConditions.values;
if (conditionsHead === undefined) {
throw new DynamoDBToolboxError('actions.invalidExpressionAttributePath', {
message: `Unable to match expression attribute path with schema: ${attributePath}`,
payload: { attributePath }
});
}
return conditionsTail.length > 0 ? { or: [conditionsHead, ...conditionsTail] } : conditionsHead;
};