<commit_before>/* @flow */

const autoBind = require('auto-bind')
const CozyClient = require('cozy-client-js').Client
const _ = require('lodash')
const path = require('path')

const Config = require('../config')
const { FILES_DOCTYPE, FILE_TYPE } = require('./constants')
const { dropSpecialDocs, jsonApiToRemoteDoc, keepFiles, parentDirIds } = require('./document')
const logger = require('../logger')
const { composeAsync } = require('../utils/func')

const { posix } = path

/*::
import type { Readable } from 'stream'
import type { RemoteDoc, RemoteDeletion } from './document'
import type { Warning } from './warning'
*/

const log = logger({
  component: 'RemoteCozy'
})

function DirectoryNotFound (path/*: string */, cozyURL/*: string */) {
  this.name = 'DirectoryNotFound'
  this.message = `Directory ${path} was not found on Cozy ${cozyURL}`
  this.stack = (new Error()).stack
}

// A remote Cozy instance.
//
// This class wraps cozy-client-js to:
//
// - deal with parsing and errors
// - provide custom functions (that may eventually be merged into the lib)
//
class RemoteCozy {
  /*::
  url: string
  client: CozyClient
  */

  constructor (config/*: Config */) {
    this.url = config.cozyUrl
    this.client = new CozyClient({
      cozyURL: this.url,
      oauth: {
        clientParams: Config.client,
        storage: Config
      }
    })

    autoBind(this)

    // Aliases:<commit_msg>core/remote/cozy: Please Babel don't make typos work...<commit_after>/* @flow */

const autoBind = require('auto-bind')
const CozyClient = require('cozy-client-js').Client
const _ = require('lodash')
const path = require('path')

const Config = require('../config')
const { FILES_DOCTYPE, FILE_TYPE } = require('./constants')
const { dropSpecialDocs, jsonApiToRemoteDoc, keepFiles, parentDirIds } = require('./document')
const logger = require('../logger')
const { composeAsync } = require('../utils/func')

const { posix } = path

/*::
import type { Readable } from 'stream'
import type { RemoteDoc, RemoteDeletion } from './document'
import type { Warning } from './warning'
*/

const log = logger({
  component: 'RemoteCozy'
})

function DirectoryNotFound (path/*: string */, cozyURL/*: string */) {
  this.name = 'DirectoryNotFound'
  this.message = `Directory ${path} was not found on Cozy ${cozyURL}`
  this.stack = (new Error()).stack
}

// A remote Cozy instance.
//
// This class wraps cozy-client-js to:
//
// - deal with parsing and errors
// - provide custom functions (that may eventually be merged into the lib)
//
class RemoteCozy {
  /*::
  url: string
  client: CozyClient
  */

  constructor (config/*: Config */) {
    this.url = config.cozyUrl
    this.client = new CozyClient({
      cozyURL: this.url,
      oauth: {
        clientParams: Config.client,
        storage: config
      }
    })

    autoBind(this)

    // Aliases:
{'fraction_non_alphanumeric': 0.1520979020979021, 'fraction_numerical': 0.0, 'mean_word_length': 3.308734939759036, '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': '4076421', 'n_tokens_mistral': 894, 'n_tokens_neox': 868, 'n_words': 253}