<commit_before>import { retrieveData, searchData } from '../network'
import Book from './../../books/Book/book'

/**
 * Retrieve Book data for specified AMId and bookId
 * @param {number} AMId - Asset Manager ID of the Asset
 * @param {string} [bookId] - ID of the Book
 * @param {function} callback - Called with two arguments (error, result) on completion
 */
export function retrieve({AMId, resourceId, token}, callback) {
  const params = {
    AMaaSClass: 'books',
    AMId,
    resourceId,
    token
  }
  let handleFullfilled = result => {
    if (!Array.isArray(result)) {
      callback(null, _parseBook(result))
      return
    }
    const books = result.map(book => {
      return _parseBook(book)
    })
    if (typeof callback === 'function') {
      callback(null, books)
    } else {
      return books
    }
  }
  let promise = retrieveData(params).then(handleFullfilled)
  if (typeof callback !== 'function') {
    // return promise if callback is not provided
    return promise
  }
  promise.catch(error => callback(error))
}

export function search({queryKey, queryValue, token}, callback) {
  const params = {
    AMaaSClass: 'books',
    queryKey,
    queryValue,
    token
  }
  let handleFullfilled = result => {
    const books = result.map((book) => {
      return _parseBook(book)
    })
    if (typeof callback === 'function') {
      callback(null, books)
    } else {
      return books
    }
  }
  let promise = searchData(params).then(handleFullfilled)
  if (typeof callback !== 'function') {
    // return promise if callback is not provided
    return promise
  }
  promise.catch(error => callback(error))
}

export function _parseBook(object) {
  return new Book({
    assetManagerId: object.asset_manager_id,
    bookId: object.book_id,
    bookStatus: object.book_status,<commit_msg>Use inline handler<commit_after>import { retrieveData, searchData } from '../network'
import Book from './../../books/Book/book'

/**
 * Retrieve Book data for specified AMId and bookId
 * @param {number} AMId - Asset Manager ID of the Asset
 * @param {string} [bookId] - ID of the Book
 * @param {function} callback - Called with two arguments (error, result) on completion
 */
export function retrieve({AMId, resourceId, token}, callback) {
  const params = {
    AMaaSClass: 'books',
    AMId,
    resourceId,
    token
  }
  let promise = retrieveData(params).then(result => {
    if (!Array.isArray(result)) {
      callback(null, _parseBook(result))
      return
    }
    const books = result.map(book => {
      return _parseBook(book)
    })
    if (typeof callback === 'function') {
      callback(null, books)
    } else {
      return books
    }
  })
  if (typeof callback !== 'function') {
    // return promise if callback is not provided
    return promise
  }
  promise.catch(error => callback(error))
}

export function search({queryKey, queryValue, token}, callback) {
  const params = {
    AMaaSClass: 'books',
    queryKey,
    queryValue,
    token
  }
  let promise = searchData(params).then(result => {
    const books = result.map((book) => {
      return _parseBook(book)
    })
    if (typeof callback === 'function') {
      callback(null, books)
    } else {
      return books
    }
  })
  if (typeof callback !== 'function') {
    // return promise if callback is not provided
    return promise
  }
  promise.catch(error => callback(error))
}

export function _parseBook(object) {
  return new Book({
    assetManagerId: object.asset_manager_id,
    bookId: object.book_id,
    bookStatus: object.book_status,
{'fraction_non_alphanumeric': 0.1229301150715689, 'fraction_numerical': 0.0, 'mean_word_length': 3.0180383314543406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2817219', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1054, 'n_words': 309}