All files / src/processors Processor.js

100% Statements 12/12
100% Branches 12/12
100% Functions 6/6
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83                            35x         24x             35x 35x 35x   2x                   7x                       1x               1x               1x               1x         10x  
"use strict";
 
/**
 * A Processor
 */
class Processor
{
  /**
   * Construct a new Processor
   *
   * @param {object} [config={}] configuration; see properties
   */
  constructor(config = {}, type = undefined, bind = [])
  {
    for (let property in config)
    {
      /**
       * @private
       */
      this[property] = config[property];
    }
    /**
     * Type of index.
     * These are usually predefined values. Filled in by class.
     * @type {string}
     */
    this.type = this.type || type;
    this.bind = this.bind || bind;
    if (!this.type || !this.bind || this.bind.length === 0)
    {
      throw new Error('Type or bind not specified');
    }
  }
 
  /**
   * Dump current index state.
   * @return {object}
   */
  async state()
  {
    return {
      type: this.type,
      bind: this.bind,
    };
  }
 
 
  /**
   * for classes with bind 'add'
   */
  async addDocuments(system, documentIndices, documents)
  {
    throw new Error('abstract method not implemented');
  }
 
  /**
   * for classes with bind 'remove'
   */
  async removeDocuments(system, documentIndices)
  {
    throw new Error('abstract method not implemented');
  }
 
  /**
   * for classes with bind 'query'
   */
  async processQuery(system, query)
  {
    throw new Error('abstract method not implemented');
  }
 
  /**
   * for classes with bind 'results'
   */
  async processResults(system, query, results)
  {
    throw new Error('abstract method not implemented');
  }
 
}
 
module.exports = Processor;