<commit_before>'use strict';

const {
  camelize,
  pluralize,
} = require('inflection');

const {
  assign,
  difference,
  drop,
  filter,
  first,
  includes,
  isArray,
  isNil,
  isNumber,
  isObject,
  keys,
  last,
  map,
  mapValues,
  omit,
  orderBy,
  pick,
  take,
  union,
  uniq,
  values,
  without,
  xor,
} = require('lodash');


module.exports = class NextModel {
  // Static properties
  // - must be inherited
  static get modelName() {
    throw new Error(`static getter 'modelName' needs to be present`);
  }

  static get schema() {
    throw new Error(`static getter 'schema' needs to be present`);
  }

  static get connector() {
    throw new Error(`static getter 'connector' needs to be present for queries`);
  }

  // - optional
  static get identifier() {
    return 'id';
  }

  static get tableName() {
    let tableName = camelize(pluralize(this.modelName), true)
    try {
      tableName = this.connector.tableName(this.modelName);
    } finally {
      return tableName;
    }
  }

  static get attrAccessors() {
    return [];
  }

  static get belongsTo() {
    return {};
  }

  static get hasMany() {
    return {};
  }

  static get hasOne() {
    return {};
  }

  static get cacheData() {
    return true;
  }

  static get defaultScope() {
    return undefined;
  }

  static get defaultOrder() {
    return undefined;
  }

  // - computed
  static get keys() {
    return this.__keys || (this.__keys = union(this.attrAccessors, keys(this.fetchSchema())));
  }

  static get databaseKeys() {
    return without(keys(this.fetchSchema()), this.identifier);
  }

  static get all() {
    let promise;
    if (this.hasCache('all')) {
      promise = Promise.resolve(this.getCache('all'));
    } else {
      promise = this.connector.all(this)
      if (this.cacheData)
        promise = promise.then(data => this.setCache('all', data));
    }
    return promise.then(result => map(result, (attr) => new this(attr)));
  }

  static get first() {
    let promise;
    if (this.hasCache('first')) {
      promise = Promise.resolve(this.getCache('first'));
    } else {
      promise = this.connector.first(this)
      if (this.cacheData)
        promise = promise.then(data => this.setCache('first', data));
    }
    return promise.then(attributes => (attributes && new this(attributes)));
  }

  static get last() {
    let promise;
    if (this.hasCache('last')) {
      promise = Promise.resolve(this.getCache('last'));
    } else {
      promise = this.connector.last(this)
      if (this.cacheData)
        promise = promise.then(data => this.setCache('last', data));
    }
    return promise.then(attributes => (attributes && new this(attributes)));
  }

  static get count() {
    let scope = this
    if (this._skip) scope = this.unskip()
    if (this._limit) scope = this.unlimit();
    if (this.hasCache('count')) {
      return Promise.resolve(this.getCache('count'));
    } else {
      let promise = this.connector.count(this)
      if (this.cacheData)
        promise = promise.then(data => this.setCache('count', data));
      return promise;
    }
  }

  static get model() {
    return this.withScope(undefined).order(undefined);
  }

  static get withoutScope() {
    return this.withScope(undefined);
  }

  static get unorder() {
    return this.order(undefined);
  }

  static get reload() {
    const klass = class extends this {};
    klass.cache = undefined;
    return klass;
  }

  // Static functions

  static hasCache(queryType) {
    return !!(this.cacheData && this.cache && !isNil(this.cache[queryType]));
  }

  static getCache(queryType) {
    return this.cache && this.cache[queryType];
  }

  static setCache(queryType, value) {
    this.cache = this.cache || {};
    return this.cache[queryType] = value;
  }

  static build(attrs) {
    if (attrs && !isNil(attrs[this.identifier])) {<commit_msg>Fixed linting errors<commit_after>'use strict';

const {
  camelize,
  pluralize,
} = require('inflection');

const {
  assign,
  difference,
  drop,
  filter,
  first,
  includes,
  isArray,
  isNil,
  isNumber,
  isObject,
  keys,
  last,
  map,
  mapValues,
  omit,
  orderBy,
  pick,
  take,
  union,
  uniq,
  values,
  without,
  xor,
} = require('lodash');


module.exports = class NextModel {
  // Static properties
  // - must be inherited
  static get modelName() {
    throw new Error(`static getter 'modelName' needs to be present`);
  }

  static get schema() {
    throw new Error(`static getter 'schema' needs to be present`);
  }

  static get connector() {
    throw new Error(`static getter 'connector' needs to be present for queries`);
  }

  // - optional
  static get identifier() {
    return 'id';
  }

  static get tableName() {
    let tableName = camelize(pluralize(this.modelName), true)
    try {
      tableName = this.connector.tableName(this.modelName);
    } finally {
      return tableName;
    }
  }

  static get attrAccessors() {
    return [];
  }

  static get belongsTo() {
    return {};
  }

  static get hasMany() {
    return {};
  }

  static get hasOne() {
    return {};
  }

  static get cacheData() {
    return true;
  }

  static get defaultScope() {
    return undefined;
  }

  static get defaultOrder() {
    return undefined;
  }

  // - computed
  static get keys() {
    return this.__keys || (this.__keys = union(this.attrAccessors, keys(this.fetchSchema())));
  }

  static get databaseKeys() {
    return without(keys(this.fetchSchema()), this.identifier);
  }

  static get all() {
    let promise;
    if (this.hasCache('all')) {
      promise = Promise.resolve(this.getCache('all'));
    } else {
      promise = this.connector.all(this)
      if (this.cacheData)
        promise = promise.then(data => this.setCache('all', data));
    }
    return promise.then(result => map(result, (attr) => new this(attr)));
  }

  static get first() {
    let promise;
    if (this.hasCache('first')) {
      promise = Promise.resolve(this.getCache('first'));
    } else {
      promise = this.connector.first(this)
      if (this.cacheData)
        promise = promise.then(data => this.setCache('first', data));
    }
    return promise.then(attributes => (attributes && new this(attributes)));
  }

  static get last() {
    let promise;
    if (this.hasCache('last')) {
      promise = Promise.resolve(this.getCache('last'));
    } else {
      promise = this.connector.last(this)
      if (this.cacheData)
        promise = promise.then(data => this.setCache('last', data));
    }
    return promise.then(attributes => (attributes && new this(attributes)));
  }

  static get count() {
    let scope = this
    if (this._skip) scope = this.unskip()
    if (this._limit) scope = this.unlimit();
    if (this.hasCache('count')) {
      return Promise.resolve(this.getCache('count'));
    } else {
      let promise = this.connector.count(this)
      if (this.cacheData)
        promise = promise.then(data => this.setCache('count', data));
      return promise;
    }
  }

  static get model() {
    return this.withScope(undefined).order(undefined);
  }

  static get withoutScope() {
    return this.withScope(undefined);
  }

  static get unorder() {
    return this.order(undefined);
  }

  static get reload() {
    const klass = class extends this {};
    klass.cache = undefined;
    return klass;
  }

  // Static functions

  static hasCache(queryType) {
    return !!(this.cacheData && this.cache && !isNil(this.cache[queryType]));
  }

  static getCache(queryType) {
    return this.cache && this.cache[queryType];
  }

  static setCache(queryType, value) {
    this.cache = this.cache || {};
    this.cache[queryType] = value;
    return value;
  }

  static build(attrs) {
    if (attrs && !isNil(attrs[this.identifier])) {
{'fraction_non_alphanumeric': 0.14162371134020618, 'fraction_numerical': 0.0, 'mean_word_length': 2.8193897637795278, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4572767', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2444, 'n_words': 593}