dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
21 lines (20 loc) • 961 B
JavaScript
import { DynamoDBToolboxError } from '../../../errors/index.js';
import { Finder } from '../../../schema/actions/finder/index.js';
import { Deduper } from '../../../schema/actions/utils/deduper.js';
export const transformPaths = (schema, paths, { strict = true } = {}) => {
const transformedPaths = new Deduper({ serializer: value => value });
const finder = new Finder(schema);
for (const attributePath of paths) {
const subSchemas = finder.search(attributePath);
if (subSchemas.length === 0 && strict) {
throw new DynamoDBToolboxError('actions.invalidExpressionAttributePath', {
message: `Unable to match expression attribute path with schema: ${attributePath}`,
payload: { attributePath }
});
}
for (const subSchema of subSchemas) {
transformedPaths.push(subSchema.transformedPath.strPath);
}
}
return transformedPaths.values;
};