<commit_before>```
 __      __            __                               __                     ___      
/\ \  __/\ \          /\ \__                           /\ \                   /\_ \     
\ \ \/\ \ \ \     __  \ \ ,_\    __   _ __   __  __  __\ \ \___      __     __\//\ \    
 \ \ \ \ \ \ \  /'__`\ \ \ \/  /'__`\/\`'__\/\ \/\ \/\ \\ \  _ `\  /'__`\ /'__`\\ \ \   
  \ \ \_/ \_\ \/\ \L\.\_\ \ \_/\  __/\ \ \/ \ \ \_/ \_/ \\ \ \ \ \/\  __//\  __/ \_\ \_
   \ `\___x___/\ \__/.\_\\ \__\ \____\\ \_\  \ \___x___/' \ \_\ \_\ \____\ \____\/\____\
    '\/__//__/  \/__/\/_/ \/__/\/____/ \/_/   \/__//__/    \/_/\/_/\/____/\/____/\/____/

```

# Waterwheel

A generic JavaScript helper library to query and manipulate Drupal 8 via core REST

[![Build Status](https://travis-ci.org/acquia/waterwheel.svg?branch=master)](https://travis-ci.org/acquia/waterwheel) [![Coverage Status](https://coveralls.io/repos/github/acquia/waterwheel/badge.svg?branch=master)](https://coveralls.io/github/acquia/waterwheel?branch=master)

---

## Setup

Install development dependencies.

```
npm i
```

Run tests and check coverage.

```
npm t
```

Build a browser version.

```
npm run build
```

## Dependencies

Ensure that you have set up cross-origin resource sharing on your Drupal site to enable Waterwheel to perform necessary tasks. Instructions for [Apache](http://enable-cors.org/server_apache.html) or [Nginx](http://enable-cors.org/server_nginx.html).

The majority of the functionality in Waterwheel is dependent on the [Waterwheel-Drupal module](https://www.drupal.org/project/waterwheel). Please install and enable this module in your Drupal site before attempting to use the functionality offered in this library.

## Documentation

### Require `waterwheel` in either a server or browser environment.

```javascript
// Server
const Waterwheel = require('waterwheel');
const waterwheel = new Waterwheel('http://test.dev', {username: 'admin', 'password': '<PASSWORD>'});

// Browser
const waterwheel = new window.Waterwheel('http://test.dev', {username: 'admin', 'password': '<PASSWORD>'});
```

Waterwheel when instantiated accepts two arguments
  - `base`: The base path for your Drupal instance. All request paths will be built from this base
  - `credentials`: An object containing the `username` and `password` used to authenticate with Drupal.

### Populate `waterwheel` resources

**This must be done before any subsequent API calls**. Without this call, only the [Entity Query](#entity-query) functionality will be available.

```javascript
waterwheel.populateResources()
  .then(res => {
    /*
    [ 'comment',
    'file',
    'menu',<commit_msg>Add specifics for use in browser<commit_after>```
 __      __            __                               __                     ___      
/\ \  __/\ \          /\ \__                           /\ \                   /\_ \     
\ \ \/\ \ \ \     __  \ \ ,_\    __   _ __   __  __  __\ \ \___      __     __\//\ \    
 \ \ \ \ \ \ \  /'__`\ \ \ \/  /'__`\/\`'__\/\ \/\ \/\ \\ \  _ `\  /'__`\ /'__`\\ \ \   
  \ \ \_/ \_\ \/\ \L\.\_\ \ \_/\  __/\ \ \/ \ \ \_/ \_/ \\ \ \ \ \/\  __//\  __/ \_\ \_
   \ `\___x___/\ \__/.\_\\ \__\ \____\\ \_\  \ \___x___/' \ \_\ \_\ \____\ \____\/\____\
    '\/__//__/  \/__/\/_/ \/__/\/____/ \/_/   \/__//__/    \/_/\/_/\/____/\/____/\/____/

```

# Waterwheel

A generic JavaScript helper library to query and manipulate Drupal 8 via core REST

[![Build Status](https://travis-ci.org/acquia/waterwheel.svg?branch=master)](https://travis-ci.org/acquia/waterwheel) [![Coverage Status](https://coveralls.io/repos/github/acquia/waterwheel/badge.svg?branch=master)](https://coveralls.io/github/acquia/waterwheel?branch=master)

---

## Setup

Install development dependencies.

```
npm i
```

Run tests and check coverage.

```
npm t
```

Build a browser version.

```
npm run build
```

## Dependencies

Ensure that you have set up cross-origin resource sharing on your Drupal site to enable Waterwheel to perform necessary tasks. Instructions for [Apache](http://enable-cors.org/server_apache.html) or [Nginx](http://enable-cors.org/server_nginx.html).

The majority of the functionality in Waterwheel is dependent on the [Waterwheel-Drupal module](https://www.drupal.org/project/waterwheel). Please install and enable this module in your Drupal site before attempting to use the functionality offered in this library.

## Documentation

### Require `waterwheel` in either a server or browser environment.

```javascript
// Server
const Waterwheel = require('waterwheel');
const waterwheel = new Waterwheel('http://test.dev', {username: 'admin', 'password': '<PASSWORD>'});

// Browser
import '../../path/to/node_modules/waterwheel/dist/waterwheel.js'
const waterwheel = new window.Waterwheel('http://test.dev', {username: 'admin', 'password': '<PASSWORD>'});
// Or use Webpack's ProvidePlugin to expose Waterwheel globally.
```

Waterwheel when instantiated accepts two arguments
  - `base`: The base path for your Drupal instance. All request paths will be built from this base
  - `credentials`: An object containing the `username` and `password` used to authenticate with Drupal.

### Populate `waterwheel` resources

**This must be done before any subsequent API calls**. Without this call, only the [Entity Query](#entity-query) functionality will be available.

```javascript
waterwheel.populateResources()
  .then(res => {
    /*
    [ 'comment',
    'file',
    'menu',
{'fraction_non_alphanumeric': 0.17283046503112412, 'fraction_numerical': 0.0003661662394727206, 'mean_word_length': 2.2673444976076556, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1386156', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1691, 'n_words': 412}