<commit_before>const IndexerEngine = require('@cardstack/server/indexer-engine');

module.exports = async function addRecords(records) {
  let stub = new StubIndexer();
  let engine = new IndexerEngine([stub]);
  stub.records = records;
  await engine.update({ realTime: true });
};

class StubIndexer {
  constructor() {
    this.records = [];
  }
  async branches() {
    return ['master'];
  }
  async beginUpdate() {
    return new StubUpdater(this);
  }
}

class StubUpdater {
  constructor(source) {
    this.source = source;
    this.name = 'stub';
  }
  async mappings() {
    return {};
  }
  async updateSchema(/* meta, hints, ops */) {
  }
  async updateContent(meta, hints, ops) {
    for (let record of this.source.records) {
      await ops.save(record.type, record.id, record);
    }
  }
}<commit_msg>test support for emitting schema records<commit_after>const IndexerEngine = require('@cardstack/server/indexer-engine');
const Searcher = require('@cardstack/elasticsearch/searcher');
const Schema = require('@cardstack/server/schema');
const Plugins = require('@cardstack/server/plugins');

module.exports = async function addRecords(records) {
  let plugins = await Plugins.load();
  let stub = new StubIndexer();
  let engine = new IndexerEngine([stub], new Searcher(), plugins);
  let schemaTypes = Schema.ownTypes();
  for (let record of records) {
    if (schemaTypes.indexOf(record.type)) {
      stub.schemaRecords.push(record);
    } else {
      stub.records.push(record);
    }
  }
  await engine.update({ realTime: true });
};

class StubIndexer {
  constructor() {
    this.records = [];
    this.schemaRecords = [];
  }
  async branches() {
    return ['master'];
  }
  async beginUpdate() {
    return new StubUpdater(this);
  }
}

class StubUpdater {
  constructor(source) {
    this.source = source;
    this.name = 'stub';
  }
  async updateSchema(meta, hints, ops) {
    for (let record of this.source.schemaRecords) {
      await ops.save(record.type, record.id, record);
    }
  }
  async updateContent(meta, hints, ops) {
    for (let record of this.source.records) {
      await ops.save(record.type, record.id, record);
    }
  }
}
{'fraction_non_alphanumeric': 0.14101382488479264, 'fraction_numerical': 0.0, 'mean_word_length': 3.504149377593361, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4423501', 'n_tokens_mistral': 689, 'n_tokens_neox': 699, 'n_words': 162}