<commit_before>import { Record, NormalizedData, PlainItem } from '../../data/Contract'
import Model from '../../model/Model'
import Repo, { Relation as Load } from '../../repo/Repo'
import Relation from './Relation'

export default class HasOne extends Relation {
  /**
   * The related model.
   */
  related: typeof Model

  /**
   * The foregin key of the related model.
   */
  foreignKey: string

  /**
   * The local key of the model.
   */
  localKey: string

  /**
   * Create a new has one instance.
   */
  constructor (model: typeof Model, related: typeof Model | string, foreignKey: string, localKey: string) {
    super(model)

    this.related = this.model.relation(related)
    this.foreignKey = foreignKey
    this.localKey = localKey
  }

  /**
   * Normalize the given value. This method is called during data normalization
   * to generate appropriate value to be saved to Vuex Store.
   */
  normalize (value: any): any {
    return value === undefined || Array.isArray(value) ? null : value
  }

  /**
   * Transform the given data to an appropriate value to be used for
   * model instantiation.
   */
  fill (value: any): any {
    return value && typeof value === 'object' ? value : null
  }

  /**
   * Attach the relational key to the given record.
   */
  attach (key: any, record: Record, data: NormalizedData): void {
    const related = data[this.related.entity]

    if (!related || !related[key] || related[this.foreignKey] !== undefined) {
      return
    }

    if (!record[this.localKey]) {
      record[this.localKey] = record.$id
    }

    related[key][this.foreignKey] = record[this.localKey]
  }

  /**
   * Load the has one relationship for the record.
   */
  load (repo: Repo, record: Record, relation: Load): PlainItem {
    const query = new Repo(repo.state, this.related.entity, false)
<commit_msg>Fix linter error<commit_after>import { Record, NormalizedData, PlainItem } from '../../data/Contract'
import Model from '../../model/Model'
import Repo, { Relation as Load } from '../../repo/Repo'
import Relation from './Relation'

export default class HasOne extends Relation {
  /**
   * The related model.
   */
  related: typeof Model

  /**
   * The foregin key of the related model.
   */
  foreignKey: string

  /**
   * The local key of the model.
   */
  localKey: string

  /**
   * Create a new has one instance.
   */
  constructor (model: typeof Model, related: typeof Model | string, foreignKey: string, localKey: string) {
    super(model)

    this.related = this.model.relation(related)
    this.foreignKey = foreignKey
    this.localKey = localKey
  }

  /**
   * Normalize the given value. This method is called during data normalization
   * to generate appropriate value to be saved to Vuex Store.
   */
  normalize (value: any): any {
    return value === undefined || Array.isArray(value) ? null : value
  }

  /**
   * Transform the given data to an appropriate value to be used for
   * model instantiation.
   */
  fill (value: any): any {
    return value && typeof value === 'object' ? value : null
  }

  /**
   * Attach the relational key to the given record.
   */
  attach (key: any, record: Record, data: NormalizedData): void {
    const related = data[this.related.entity]

    if (related && related[key] && related[key][this.foreignKey] !== undefined) {
      return
    }

    if (!record[this.localKey]) {
      record[this.localKey] = record.$id
    }

    related[key][this.foreignKey] = record[this.localKey]
  }

  /**
   * Load the has one relationship for the record.
   */
  load (repo: Repo, record: Record, relation: Load): PlainItem {
    const query = new Repo(repo.state, this.related.entity, false)

{'fraction_non_alphanumeric': 0.12554112554112554, 'fraction_numerical': 0.0, 'mean_word_length': 2.8231644260599795, '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': '954380', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1086, 'n_words': 370}