<commit_before>// @flow
import {
  observable,
  action,
  ObservableMap,
  computed,
  runInAction,
  toJS
} from 'mobx'
import Collection from './Collection'
import { uniqueId, isString, debounce } from 'lodash'
import apiClient from './apiClient'
import Request from './Request'
import ErrorObject from './ErrorObject'
import type {
  OptimisticId,
  Id,
  Label,
  DestroyOptions,
  SaveOptions,
  CreateOptions
} from './types'

export default class Model {
  @observable request: ?Request = null
  @observable error: ?ErrorObject = null
  attributes: ObservableMap

  optimisticId: OptimisticId = uniqueId('i_')
  collection: ?Collection<*> = null

  constructor (attributes: { [key: string]: any } = {}) {
    this.attributes = observable.map(attributes)
  }

  /**
   * Returns a JSON representation
   * of the model
   */
  toJS () {
    return toJS(this.attributes)
  }

  /**
   * Determine what attribute do you use
   * as a primary id
   *
   * @abstract
   */
  get primaryKey (): string {
    return 'id'
  }

  /**
   * Return the base url used in
   * the `url` method
   *
   * @abstract
   */
  urlRoot () {
    throw new Error('`url` method not implemented')
  }

  /**
   * Return the url for this given REST resource
   */<commit_msg>It's preferable to override urlRoot() instead of url()<commit_after>// @flow
import {
  observable,
  action,
  ObservableMap,
  computed,
  runInAction,
  toJS
} from 'mobx'
import Collection from './Collection'
import { uniqueId, isString, debounce } from 'lodash'
import apiClient from './apiClient'
import Request from './Request'
import ErrorObject from './ErrorObject'
import type {
  OptimisticId,
  Id,
  Label,
  DestroyOptions,
  SaveOptions,
  CreateOptions
} from './types'

export default class Model {
  @observable request: ?Request = null
  @observable error: ?ErrorObject = null
  attributes: ObservableMap

  optimisticId: OptimisticId = uniqueId('i_')
  collection: ?Collection<*> = null

  constructor (attributes: { [key: string]: any } = {}) {
    this.attributes = observable.map(attributes)
  }

  /**
   * Returns a JSON representation
   * of the model
   */
  toJS () {
    return toJS(this.attributes)
  }

  /**
   * Determine what attribute do you use
   * as a primary id
   *
   * @abstract
   */
  get primaryKey (): string {
    return 'id'
  }

  /**
   * Return the base url used in
   * the `url` method
   *
   * @abstract
   */
  urlRoot () {
    throw new Error('`urlRoot` method not implemented')
  }

  /**
   * Return the url for this given REST resource
   */
{'fraction_non_alphanumeric': 0.11753221397891449, 'fraction_numerical': 0.0, 'mean_word_length': 3.0156739811912225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6558859', 'n_tokens_mistral': 809, 'n_tokens_neox': 792, 'n_words': 249}