UNPKG

ottoman

Version:
40 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractIndexFieldNames = void 0; const jp_parse_1 = require("../../../utils/jp-parse"); const path_to_n1ql_1 = require("../../../utils/path-to-n1ql"); const ottoman_errors_1 = require("../../../exceptions/ottoman-errors"); const extractIndexFieldNames = (gsi) => { const fieldNames = []; for (let j = 0; j < gsi.fields.length; ++j) { const path = (0, jp_parse_1.jpParse)(gsi.fields[j]); let wildCardAt = -1; for (let k = 0; k < path.length; ++k) { if (path[k].operation === 'subscript' && path[k].expression.type === 'wildcard') { if (wildCardAt !== -1) { throw new ottoman_errors_1.BuildIndexQueryError('Cannot create an index with more than one wildcard in path'); } wildCardAt = k; } } if (wildCardAt === -1) { fieldNames.push((0, path_to_n1ql_1.pathToN1QL)(path)); } else { const pathBefore = path.slice(0, wildCardAt); const pathAfter = path.slice(wildCardAt + 1); let objTarget = (0, path_to_n1ql_1.pathToN1QL)(pathAfter); if (objTarget !== '') { objTarget = 'v.' + objTarget; } else { objTarget = 'v'; } const arrTarget = (0, path_to_n1ql_1.pathToN1QL)(pathBefore); fieldNames.push(`DISTINCT ARRAY ${objTarget} FOR v IN ${arrTarget} END`); } } return fieldNames; }; exports.extractIndexFieldNames = extractIndexFieldNames; //# sourceMappingURL=extract-index-field-names.js.map