dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
36 lines (35 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.expressPaths = void 0;
const isNumber_js_1 = require("../../../utils/validation/isNumber.js");
const path_js_1 = require("../utils/path.js");
const expressPaths = (paths) => {
let ProjectionExpression = '';
const ExpressionAttributeNames = {};
const tokens = {};
let cursor = 1;
paths.forEach((path, index) => {
if (index > 0) {
ProjectionExpression += ', ';
}
new path_js_1.Path(path).arrayPath.forEach((pathPart, index) => {
if ((0, isNumber_js_1.isNumber)(pathPart)) {
ProjectionExpression += `[${pathPart}]`;
return;
}
let token = tokens[pathPart];
if (token === undefined) {
token = `#p_${cursor}`;
tokens[pathPart] = token;
ExpressionAttributeNames[token] = pathPart;
cursor++;
}
if (index > 0) {
ProjectionExpression += '.';
}
ProjectionExpression += token;
});
});
return { ProjectionExpression, ExpressionAttributeNames };
};
exports.expressPaths = expressPaths;