UNPKG

dynamodb-toolbox

Version:

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

25 lines (24 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformPaths = void 0; const index_js_1 = require("../../../errors/index.js"); const index_js_2 = require("../../../schema/actions/finder/index.js"); const deduper_js_1 = require("../../../schema/actions/utils/deduper.js"); const transformPaths = (schema, paths, { strict = true } = {}) => { const transformedPaths = new deduper_js_1.Deduper({ serializer: value => value }); const finder = new index_js_2.Finder(schema); for (const attributePath of paths) { const subSchemas = finder.search(attributePath); if (subSchemas.length === 0 && strict) { throw new index_js_1.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; }; exports.transformPaths = transformPaths;