dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
37 lines (36 loc) • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformBeginsWithCondition = void 0;
const index_js_1 = require("../../../../../schema/actions/finder/index.js");
const deduper_js_1 = require("../../../../../schema/actions/utils/deduper.js");
const parser_js_1 = require("../../../parse/parser.js");
const utils_js_1 = require("./utils.js");
const transformBeginsWithCondition = (schema, condition) => {
const conditions = new deduper_js_1.Deduper();
const schemaFinder = new index_js_1.Finder(schema);
const { beginsWith: formattedBeginsWith, transform } = condition;
const attributePath = condition.attr;
const subSchemas = schemaFinder.search(attributePath);
const comparedSubSchemas = (0, utils_js_1.getComparedSubSchemas)(schemaFinder, formattedBeginsWith, transform);
for (const subSchema of subSchemas) {
const path = subSchema.transformedPath.strPath;
if (comparedSubSchemas !== undefined) {
for (const comparedSubSchema of comparedSubSchemas) {
const beginsWith = { attr: comparedSubSchema.transformedPath.strPath };
conditions.push({ attr: path, beginsWith });
}
}
else {
const valueSchema = subSchema.schema;
const valueParser = new parser_js_1.Parser(valueSchema);
try {
const beginsWith = valueParser.parse(formattedBeginsWith, { fill: false, transform });
conditions.push({ attr: path, beginsWith });
// eslint-disable-next-line no-empty
}
catch { }
}
}
return (0, utils_js_1.joinDedupedConditions)(conditions, attributePath);
};
exports.transformBeginsWithCondition = transformBeginsWithCondition;