UNPKG

dynamodb-toolbox

Version:

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

28 lines (27 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Path = void 0; const formatArrayPath_js_1 = require("./formatArrayPath.js"); const parseStringPath_js_1 = require("./parseStringPath.js"); class Path { static fromArray(arrayPath) { return new Path((0, formatArrayPath_js_1.formatArrayPath)(arrayPath), arrayPath); } constructor(strPath = '', arrayPath = (0, parseStringPath_js_1.parseStringPath)(strPath)) { this.arrayPath = arrayPath; this.strPath = (0, formatArrayPath_js_1.formatArrayPath)(this.arrayPath); } prepend(...arrayPath) { return this.prependPath(Path.fromArray(arrayPath)); } prependPath(path) { return new Path([path.strPath, this.strPath].filter(Boolean).join(this.strPath[0] !== '[' ? '.' : ''), path.arrayPath.concat(this.arrayPath)); } append(...arrayPath) { return this.appendPath(Path.fromArray(arrayPath)); } appendPath(path) { return new Path([this.strPath, path.strPath].filter(Boolean).join(path.strPath[0] !== '[' ? '.' : ''), this.arrayPath.concat(path.arrayPath)); } } exports.Path = Path;