<commit_before>import DebugPort from './debug-port';

import { A } from 'ember-debug/utils/ember/array';
import { computed, set } from 'ember-debug/utils/ember/object';
import { alias } from 'ember-debug/utils/ember/object/computed';
import { guidFor } from 'ember-debug/utils/ember/object/internals';

export default DebugPort.extend({
  init() {
    this._super();
    this.sentTypes = {};
    this.sentRecords = {};
  },

  releaseTypesMethod: null,
  releaseRecordsMethod: null,

  /* eslint-disable ember/no-side-effects */
  adapter: computed('namespace.owner', function () {
    const owner = this.get('namespace.owner');

    // dataAdapter:main is deprecated
    let adapter =
      this._resolve('data-adapter:main') && owner.lookup('data-adapter:main');
    // column limit is now supported at the inspector level
    if (adapter) {
      set(adapter, 'attributeLimit', 100);
      return adapter;
    }

    return null;
  }),
  /* eslint-enable ember/no-side-effects */

  _resolve(name) {
    const owner = this.get('namespace.owner');

    return owner.resolveRegistration(name);
  },

  namespace: null,

  port: alias('namespace.port'),
  objectInspector: alias('namespace.objectInspector'),

  portNamespace: 'data',

  modelTypesAdded(types) {
    let typesToSend;
    typesToSend = types.map((type) => this.wrapType(type));
    this.sendMessage('modelTypesAdded', {
      modelTypes: typesToSend,
    });
  },

  modelTypesUpdated(types) {
    let typesToSend = types.map((type) => this.wrapType(type));
    this.sendMessage('modelTypesUpdated', {
      modelTypes: typesToSend,
    });
  },

  wrapType(type) {
    const objectId = guidFor(type.object);
    this.sentTypes[objectId] = type;

    return {
      columns: type.columns,
      count: type.count,
      name: type.name,
      objectId,
    };
  },

  recordsAdded(recordsReceived) {
    let records = recordsReceived.map((record) => this.wrapRecord(record));
    this.sendMessage('recordsAdded', { records });
  },

  recordsUpdated(recordsReceived) {
    let records = recordsReceived.map((record) => this.wrapRecord(record));
    this.sendMessage('recordsUpdated', { records });
  },

  recordsRemoved(index, count) {
    this.sendMessage('recordsRemoved', { index, count });
  },

  wrapRecord(record) {
    const objectId = guidFor(record.object);
    let columnValues = {};
    let searchKeywords = [];
    this.sentRecords[objectId] = record;
    // make objects clonable
    for (let i in record.columnValues) {
      columnValues[i] = this.objectInspector.inspect(record.columnValues[i]);
    }
    // make sure keywords can be searched and clonable
    searchKeywords = A(record.searchKeywords).filter(
      (keyword) => typeof keyword === 'string' || typeof keyword === 'number'
    );
    return {
      columnValues,
      searchKeywords,
      filterValues: record.filterValues,
      color: record.color,
      objectId,
    };
  },

  releaseTypes() {
    if (this.releaseTypesMethod) {
      this.releaseTypesMethod();
      this.releaseTypesMethod = null;
      this.sentTypes = {};
    }
  },

  releaseRecords() {
    if (this.releaseRecordsMethod) {
      this.releaseRecordsMethod();
      this.releaseRecordsMethod = null;
      this.sentRecords = {};
    }
  },

  willDestroy() {
    this._super();
    this.releaseRecords();
    this.releaseTypes();
  },

  messages: {
    checkAdapter() {
      this.sendMessage('hasAdapter', { hasAdapter: !!this.adapter });
    },

    getModelTypes() {
      this.releaseTypes();
      this.releaseTypesMethod = this.adapter.watchModelTypes(
        (types) => {
          this.modelTypesAdded(types);
        },
        (types) => {
          this.modelTypesUpdated(types);
        }
      );
    },

    releaseModelTypes() {
      this.releaseTypes();
    },

    getRecords(message) {
      const type = this.sentTypes[message.objectId];
      this.releaseRecords();

      let typeOrName;
      if (this.get('adapter.acceptsModelName')) {
        // Ember >= 1.3
        typeOrName = type.name;
      }

      let releaseMethod = this.adapter.watchRecords(
        typeOrName,
        (recordsReceived) => {
          this.recordsAdded(recordsReceived);
        },
        (recordsUpdated) => {
          this.recordsUpdated(recordsUpdated);
        },
        (...args) => {
          this.recordsRemoved(...args);
        }
      );
      this.releaseRecordsMethod = releaseMethod;
    },
<commit_msg>[bug] data tab does not load if there are not models (#2186)<commit_after>import DebugPort from './debug-port';

import { A } from 'ember-debug/utils/ember/array';
import { computed, set } from 'ember-debug/utils/ember/object';
import { alias } from 'ember-debug/utils/ember/object/computed';
import { guidFor } from 'ember-debug/utils/ember/object/internals';

export default DebugPort.extend({
  init() {
    this._super();
    this.sentTypes = {};
    this.sentRecords = {};
  },

  releaseTypesMethod: null,
  releaseRecordsMethod: null,

  /* eslint-disable ember/no-side-effects */
  adapter: computed('namespace.owner', function () {
    const owner = this.get('namespace.owner');

    // dataAdapter:main is deprecated
    let adapter =
      this._resolve('data-adapter:main') && owner.lookup('data-adapter:main');
    // column limit is now supported at the inspector level
    if (adapter) {
      set(adapter, 'attributeLimit', 100);
      return adapter;
    }

    return null;
  }),
  /* eslint-enable ember/no-side-effects */

  _resolve(name) {
    const owner = this.get('namespace.owner');

    return owner.resolveRegistration(name);
  },

  namespace: null,

  port: alias('namespace.port'),
  objectInspector: alias('namespace.objectInspector'),

  portNamespace: 'data',

  modelTypesAdded(types) {
    let typesToSend;
    typesToSend = types.map((type) => this.wrapType(type));
    this.sendMessage('modelTypesAdded', {
      modelTypes: typesToSend,
    });
  },

  modelTypesUpdated(types) {
    let typesToSend = types.map((type) => this.wrapType(type));
    this.sendMessage('modelTypesUpdated', {
      modelTypes: typesToSend,
    });
  },

  wrapType(type) {
    const objectId = guidFor(type.object);
    this.sentTypes[objectId] = type;

    return {
      columns: type.columns,
      count: type.count,
      name: type.name,
      objectId,
    };
  },

  recordsAdded(recordsReceived) {
    let records = recordsReceived.map((record) => this.wrapRecord(record));
    this.sendMessage('recordsAdded', { records });
  },

  recordsUpdated(recordsReceived) {
    let records = recordsReceived.map((record) => this.wrapRecord(record));
    this.sendMessage('recordsUpdated', { records });
  },

  recordsRemoved(index, count) {
    this.sendMessage('recordsRemoved', { index, count });
  },

  wrapRecord(record) {
    const objectId = guidFor(record.object);
    let columnValues = {};
    let searchKeywords = [];
    this.sentRecords[objectId] = record;
    // make objects clonable
    for (let i in record.columnValues) {
      columnValues[i] = this.objectInspector.inspect(record.columnValues[i]);
    }
    // make sure keywords can be searched and clonable
    searchKeywords = A(record.searchKeywords).filter(
      (keyword) => typeof keyword === 'string' || typeof keyword === 'number'
    );
    return {
      columnValues,
      searchKeywords,
      filterValues: record.filterValues,
      color: record.color,
      objectId,
    };
  },

  releaseTypes() {
    if (this.releaseTypesMethod) {
      this.releaseTypesMethod();
      this.releaseTypesMethod = null;
      this.sentTypes = {};
    }
  },

  releaseRecords() {
    if (this.releaseRecordsMethod) {
      this.releaseRecordsMethod();
      this.releaseRecordsMethod = null;
      this.sentRecords = {};
    }
  },

  willDestroy() {
    this._super();
    this.releaseRecords();
    this.releaseTypes();
  },

  messages: {
    checkAdapter() {
      this.sendMessage('hasAdapter', { hasAdapter: !!this.adapter });
    },

    getModelTypes() {
      this.modelTypesAdded([]);
      this.releaseTypes();
      this.releaseTypesMethod = this.adapter.watchModelTypes(
        (types) => {
          this.modelTypesAdded(types);
        },
        (types) => {
          this.modelTypesUpdated(types);
        }
      );
    },

    releaseModelTypes() {
      this.releaseTypes();
    },

    getRecords(message) {
      const type = this.sentTypes[message.objectId];
      this.releaseRecords();

      let typeOrName;
      if (this.get('adapter.acceptsModelName')) {
        // Ember >= 1.3
        typeOrName = type.name;
      }

      this.recordsAdded([]);
      let releaseMethod = this.adapter.watchRecords(
        typeOrName,
        (recordsReceived) => {
          this.recordsAdded(recordsReceived);
        },
        (recordsUpdated) => {
          this.recordsUpdated(recordsUpdated);
        },
        (...args) => {
          this.recordsRemoved(...args);
        }
      );
      this.releaseRecordsMethod = releaseMethod;
    },

{'fraction_non_alphanumeric': 0.14027500554446662, 'fraction_numerical': 0.0015524506542470614, 'mean_word_length': 2.7736401673640168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '4978706', 'n_tokens_mistral': 2701, 'n_tokens_neox': 2623, 'n_words': 481}