UNPKG

mongodb-data-service

Version:
92 lines 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getIndexCardinality = getIndexCardinality; exports.getIndexProperties = getIndexProperties; exports.getIndexType = getIndexType; exports.createIndexDefinition = createIndexDefinition; function getIndexCardinality(index) { const isSingleTextIndex = !!index.extra.textIndexVersion && index.fields.length === 2 && Object.keys(index.extra.weights).length === 1; if (isSingleTextIndex) { return 'single'; } return index.fields.length === 1 ? 'single' : 'compound'; } function getIndexProperties(index) { const properties = []; if (index.name === '_id_' || !!index.extra.unique) { properties.push('unique'); } if (index.extra.sparse) { properties.push('sparse'); } if (index.extra.partialFilterExpression) { properties.push('partial'); } if (Number(index.extra.expireAfterSeconds) > -1) { properties.push('ttl'); } if (index.extra.collation) { properties.push('collation'); } return properties; } function getIndexType(index) { const keyNames = Object.keys(index.key); const keyValues = Object.values(index.key); if (!!index.extra['2dsphereIndexVersion'] || keyValues.includes('2d') || keyValues.includes('geoHaystack')) { return 'geospatial'; } if (keyValues.includes('hashed')) { return 'hashed'; } if (index.extra.textIndexVersion) { return 'text'; } // Columnstore is before wildcard as it is a special case of wildcard. if (keyValues.includes('columnstore')) { return 'columnstore'; } if (keyNames.some((k) => { return k === '$**' || String(k).includes('.$**'); })) { return 'wildcard'; } if (index.extra.clustered) { return 'clustered'; } return 'regular'; } function createIndexDefinition(ns, { name, key, v, ...extra }, indexStats, indexSize, maxSize, buildProgress) { indexStats ??= { name, usageHost: '', usageSince: new Date(0), }; indexSize ??= 0; maxSize ??= 0; const index = { ns, name, key, version: v ?? 1, fields: Object.entries(key).map(([field, value]) => { return { field, value }; }), extra: extra, }; return { ...index, ...indexStats, type: getIndexType(index), cardinality: getIndexCardinality(index), properties: getIndexProperties(index), size: indexSize, relativeSize: (indexSize / maxSize) * 100, buildProgress: buildProgress ?? 0, }; } //# sourceMappingURL=index-detail-helper.js.map