isTimeseriesIndex.js 507 B

12345678910111213141516
  1. 'use strict';
  2. /**
  3. * Returns `true` if the given index matches the schema's `timestamps` options
  4. */
  5. module.exports = function isTimeseriesIndex(dbIndex, schemaOptions) {
  6. if (schemaOptions.timeseries == null) {
  7. return false;
  8. }
  9. const { timeField, metaField } = schemaOptions.timeseries;
  10. if (typeof timeField !== 'string' || typeof metaField !== 'string') {
  11. return false;
  12. }
  13. return Object.keys(dbIndex.key).length === 2 && dbIndex.key[timeField] === 1 && dbIndex.key[metaField] === 1;
  14. };