UNPKG

couchbase-index-manager

Version:
105 lines 3.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IndexValidators = void 0; const tslib_1 = require("tslib"); const lodash_1 = tslib_1.__importDefault(require("lodash")); /** * Validators for the incoming index properties. */ exports.IndexValidators = { is_primary: function (val) { if (val !== undefined && !lodash_1.default.isBoolean(val)) { throw new Error('is_primary must be a boolean'); } }, index_key: function (val) { if (val === undefined) { return; } if (!lodash_1.default.isArrayLike(val)) { val = [val]; } for (const v of val) { if (!lodash_1.default.isString(v)) { throw new Error('index_key must be a string or array of strings'); } } }, condition: function (val) { if (val !== undefined && !lodash_1.default.isString(val)) { throw new Error('condition must be a string'); } }, partition: function (val) { if (val === undefined) { return; } if (!val.exprs || !lodash_1.default.isObjectLike(val.exprs)) { throw new Error('Invalid partition'); } lodash_1.default.forOwn(val.exprs, (v) => { if (!lodash_1.default.isString(v)) { throw new Error('Invalid partition'); } }); }, nodes: function (val) { if (val !== undefined) { if (!lodash_1.default.isArray(val)) { throw new Error('nodes must be an array of strings'); } val.forEach((v) => { if (!lodash_1.default.isString(v)) { throw new Error('nodes must be an array of strings'); } }); } }, manual_replica: function (val) { if (val !== undefined && !lodash_1.default.isBoolean(val)) { throw new Error('manual_replica must be a boolean'); } }, num_replica: function (val) { if (val !== undefined && !lodash_1.default.isNumber(val)) { throw new Error('num_replica must be a number'); } }, retain_deleted_xattr: function (val) { if (val !== undefined && !lodash_1.default.isBoolean(val)) { throw new Error('retain_deleted_xattr must be a boolean'); } }, lifecycle: function (val) { if (val !== undefined && !lodash_1.default.isObjectLike(val)) { throw new Error('lifecycle is invalid'); } }, post_validate: function () { var _a; if (!this.is_primary) { const isDrop = this.lifecycle && this.lifecycle.drop; if (!isDrop && (!this.index_key || this.index_key.length === 0)) { throw new Error('index_key must include at least one key'); } } else { if (this.index_key && this.index_key.length > 0) { throw new Error('index_key is not allowed for a primary index'); } if (this.condition) { throw new Error('condition is not allowed for a primary index'); } } if (this.partition && this.manual_replica) { throw new Error('manual_replica is not supported on partioned indexes'); } if (!this.partition && this.nodes) { // Validate nodes and num_replica values if (this.nodes.length !== ((_a = this.num_replica) !== null && _a !== void 0 ? _a : 0) + 1) { throw new Error('mismatch between num_replica and nodes'); } } }, }; //# sourceMappingURL=index-validation.js.map