ottoman
Version:
Ottoman Couchbase ODM
31 lines • 1.24 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.jpParse = void 0;
const jsonpath_1 = __importDefault(require("jsonpath"));
const jpParse = (pathStr) => {
// Temporary fix until we have our own parser.
const dollarKey = 'SUPERWACKYDOLLARKEY';
const path = jsonpath_1.default.parse(pathStr.replace('$', dollarKey));
for (let i = 0; i < path.length; ++i) {
const pathPart = path[i];
if (pathPart.scope !== 'child') {
throw new Error('Expected child selectors only.');
}
if (pathPart.operation !== 'member' && pathPart.operation !== 'subscript') {
throw new Error('Expected member and subscript selectors only.');
}
if (pathPart.expression.type === 'wildcard') {
delete pathPart.expression.value;
}
if (pathPart.expression.value) {
pathPart.expression.value = pathPart.expression.value.replace(dollarKey, '$');
}
delete pathPart.scope;
}
return path;
};
exports.jpParse = jpParse;
//# sourceMappingURL=jp-parse.js.map