UNPKG

@env0/dynamo-easy

Version:

DynamoDB client for NodeJS and browser with a fluent api to build requests. We take care of the type mapping between JS and DynamoDB, customizable trough typescript decorators.

44 lines 1.93 kB
import { NESTED_ATTR_PATH_CAPTURED_REGEX, NESTED_ATTR_PATH_REGEX } from './attribute-names.const'; // problem: we only get the metadata from the last property -> but we need it for all properties in the chain (prop1.prop2.prop3) /** * @hidden */ export function resolveAttributeNames(attributePath, metadata) { let placeholder; // tslint:disable-next-line:no-shadowed-variable const attributeNames = {}; if (new RegExp(NESTED_ATTR_PATH_REGEX).test(attributePath)) { const regex = new RegExp(NESTED_ATTR_PATH_CAPTURED_REGEX); // nested attribute with document path (map or list) const currentPath = []; let regExpResult; const namePlaceholders = []; // tslint:disable-next-line:no-conditional-assignment while ((regExpResult = regex.exec(attributePath)) !== null) { // path part is pos 1 - full match would be 0 const pathPart = regExpResult[1]; currentPath.push(regExpResult[1]); const collectionIndex = regExpResult[2]; const propertyMetadata = metadata && metadata.forProperty(currentPath.join('.')); attributeNames[`#${pathPart}`] = propertyMetadata ? propertyMetadata.nameDb : pathPart; if (collectionIndex !== undefined) { namePlaceholders.push(`#${pathPart}[${collectionIndex}]`); } else { namePlaceholders.push(`#${pathPart}`); } } placeholder = namePlaceholders.join('.'); } else { // top level attribute const propertyMetadata = metadata && metadata.forProperty(attributePath); attributeNames[`#${attributePath}`] = propertyMetadata ? propertyMetadata.nameDb : attributePath; placeholder = `#${attributePath}`; } return { placeholder, attributeNames, }; } //# sourceMappingURL=attribute-names.function.js.map