<commit_before># Dad
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]

Composable data stores for node.js and the browser. Dad's small ~300 SLOC
codebase implements only methods that are common in most datastores. This
includes models, validation and persistance.

No assumptions about your backend are made. Through adapters you can
synchronize your data with any backend. Official adapters are a WIP.

## Installation
````bash
$ npm i --save dad
````

## Overview
````js
var store = require('dad');
var books = store('books');

// attributes
books
  .settings({baseUrl: 'api.mysite.com/books'})
  .schema({
    title: {type: 'string', required: true},
    author: {type: 'string', required: true},
    pages: {type: 'number'}
  });

// transactions
books.add({title: 'Ferrets', author: 'Tobi', pages: 12});
books.update({cid: 0, title: 'Lizards', author: 'Tobi', pages: 12});
````

#### Functions
|__initialize__|__validate__        |__transact__|__persist__|
|--------------|--------------------|------------|-----------|
|`.schema()`   |`.validate()`       |`.add()`    |`.push()`  |
|`.settings()` |`.allAccountedFor()`|`.get()`    |`.fetch()` |
|`.adapters()` |                    |`.update()` |           |
|              |                    |`.remove()` |           |

#### Events
|__change__ |__sync__  |
|-----------|----------|
|`.add()`   |`.push()` |
|`.get()`   |`.fetch()`|
|`.update()`|          |

## API
#### dad()
Create a named store. Takes a `{String} name` as an argument.
````js
var store = require('dad');
var books = store('books');
var chapters = store('chapters');
````

#### .schema()
Define the schema for the store. Takes an `{Object} schema` as an argument.
````js
books
  .schema({
    title: {type: 'string', required: true},
    author: {type: 'string', required: true},
    pages: {type: 'number'}
  });
````

#### .settings()
Define settings to be used. Settings can be used to store synchronization
url's and auth tokens. Takes an `{Object} opts` as an argument.
````js
books.settings({baseUrl: 'api.mysite.com/books'});
````

#### .validate()
Validate a value against a key in the schema. Takes a `{String} key` and a
`{String} value` as arguments.
```js
books.validate('name', 'Tobi');
```

#### .allAccountedFor()
Check if an object accounts for all properties demanded by the schema. Takes
an `{Object} record` as an argument.
```js
books.allAccountedFor({foo: 'bar', baz: 'bin'});
```

### Transactions
#### .add()
Save a record or an array of records to the store. Records get a `{Number} cid`
assigned automatically. Emits an add event when completed. Takes an
`{Object} record` or an array of records as an argument.
````js
chapters.add([
  {name: 'chapter 1', pages: 2},
  {name: 'chapter 2', pages: 6},
  {name: 'chapter 3', pages: 4}
]);

books.add({
  title: 'Fatherly jokes',
  author: 'Tobi',
  pages: 12,
  chapters: [0]
});
````

#### .get()
Get a record from the store at cid. Takes a `{Number} cid` as an argument.
````js
var fatherlyJokes = books.get(0);
// -> {
//      cid: 0,
//      title: 'Fatherly jokes',
//      author: 'Tobi',
//      pages: 12,
//      chapters: [{
//        cid: 0,
//        name: 'chapter 1',
//        pages: 2
//      }]
//    };
````

#### .update()
Update a record with a cid. Emits an update event when completed. Takes an
`{Object} record` as an argument. If the record has no cid provided, an error
will be thrown.
````js
chapters.update({
  cid: 4,
  title: 'Fatherly jokes',
  author: 'Tobi',
  pages: 12,
  chapters: [0]
});
````

#### .remove()
Remove a record from the store at cid. Emits a remove event when completed.
Takes a `{Number} cid` as an argument.
````js
chapters.remove(2);
````

### Persistance
#### .push()
Persist the record changes to the backend. Can be provided with optional HTTP
headers. Emits a push event when completed, else it emits an error event.
Takes an optional `{Object} configuration` as an argument.
````js
books.push();

books.push({
  API_KEY: 'mysecretkey',
  ANOTHER_HEADER: 'some value'
});
````

#### .fetch() [wip]
Fetch records from the server over HTTP. Can be provided with optional HTTP
headers. Emits a fetch event when completed, else it emits an error event.
Takes an optional `{Object} configuration` as an argument.
````js
books.fetch();

books.fetch({
  API_KEY: 'mysecretkey',
  ANOTHER_HEADER: 'some value'
});
````

## References
- [Issues](https://github.com/yoshuawuyts/dad/issues)
- [Pull Requests](https://github.com/yoshuawuyts/dad/pulls)

## License
[MIT](https://tldrlegal.com/license/mit-license) © [<NAME>](yoshuawuyts.com)

[npm-image]: https://img.shields.io/npm/v/dad.svg?style=flat-square
[npm-url]: https://npmjs.org/package/dad
[travis-image]: https://img.shields.io/travis/yoshuawuyts/dad.svg?style=flat-square
[travis-url]: https://travis-ci.org/yoshuawuyts/dad
[coveralls-image]: https://img.shields.io/coveralls/yoshuawuyts/dad.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/yoshuawuyts/dad?branch=master<commit_msg>readme: update<commit_after># Dad
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]

Composable data stores for node.js and the browser. Dad's small ~300 SLOC
codebase implements only methods that are common in most datastores. This
includes models, validation and persistance.

No assumptions about your backend are made. Through adapters you can
synchronize your data with any backend. Official adapters are a WIP.

## Installation
````bash
$ npm i --save dad
````

## Overview
````js
var store = require('dad');
var books = store('books');

// attributes
books
  .settings({baseUrl: 'api.mysite.com/books'})
  .schema({
    title: {type: 'string', required: true},
    author: {type: 'string', required: true},
    pages: {type: 'number'}
  });

// transactions
books.add({title: 'Ferrets', author: 'Tobi', pages: 12});
books.update({cid: 0, title: 'Lizards', author: 'Tobi', pages: 12});
````
#### Events
|__change__ |__sync__  |
|-----------|----------|
|`.add()`   |`.push()` |
|`.get()`   |`.fetch()`|
|`.update()`|          |

## API
#### dad(name)
Create a named store.
````js
var store = require('dad');
var books = store('books');
var chapters = store('chapters');
````

#### .schema(schema)
Define the schema for the store.
````js
books
  .schema({
    title: {type: 'string', required: true},
    author: {type: 'string', required: true},
    pages: {type: 'number'}
  });
````

#### .settings(opts)
Define settings to be used. Settings can be used to store synchronization
url's and auth tokens.
````js
books.settings({baseUrl: 'api.mysite.com/books'});
````

#### .validate(key, value)
Validate a value against a key in the schema.
```js
books.validate('name', 'Tobi');
```

#### .allAccountedFor(record)
Check if an object accounts for all properties demanded by the schema.
```js
books.allAccountedFor({foo: 'bar', baz: 'bin'});
```

### Transactions
#### .add(record)
Save a record or an array of records to the store.
````js
chapters.add([
  {name: 'chapter 1', pages: 2},
  {name: 'chapter 2', pages: 6},
  {name: 'chapter 3', pages: 4}
]);

books.add({
  title: 'Fatherly jokes',
  author: 'Tobi',
  pages: 12,
  chapters: [0]
});
````

#### .get(cid)
Get a record from the store at cid.
````js
var fatherlyJokes = books.get(0);
// -> {
//      cid: 0,
//      title: 'Fatherly jokes',
//      author: 'Tobi',
//      pages: 12,
//      chapters: [{
//        cid: 0,
//        name: 'chapter 1',
//        pages: 2
//      }]
//    };
````

#### .update(record)
Update a record with a cid. Emits an update event when completed. If the record has no cid provided, an error
will be thrown.
````js
chapters.update({
  cid: 4,
  title: 'Fatherly jokes',
  author: 'Tobi',
  pages: 12,
  chapters: [0]
});
````

#### .remove(cid)
Remove a record from the store at cid.
````js
chapters.remove(2);
````

### Persistance
#### .push([config])
Persist the record changes to the backend. Can be provided with optional HTTP
headers. Emits a push event when completed, else it emits an error event.
````js
books.push();

books.push({
  API_KEY: 'mysecretkey',
  ANOTHER_HEADER: 'some value'
});
````

#### .fetch([configuration]) [wip]
Fetch records from the server over HTTP. Can be provided with optional HTTP
headers. Emits a fetch event when completed, else it emits an error event.
````js
books.fetch();

books.fetch({
  API_KEY: 'mysecretkey',
  ANOTHER_HEADER: 'some value'
});
````

## References
- [Issues](https://github.com/yoshuawuyts/dad/issues)
- [Pull Requests](https://github.com/yoshuawuyts/dad/pulls)

## License
[MIT](https://tldrlegal.com/license/mit-license) © [<NAME>](yoshuawuyts.com)

[npm-image]: https://img.shields.io/npm/v/dad.svg?style=flat-square
[npm-url]: https://npmjs.org/package/dad
[travis-image]: https://img.shields.io/travis/yoshuawuyts/dad.svg?style=flat-square
[travis-url]: https://travis-ci.org/yoshuawuyts/dad
[coveralls-image]: https://img.shields.io/coveralls/yoshuawuyts/dad.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/yoshuawuyts/dad?branch=master
{'fraction_non_alphanumeric': 0.195690030474532, 'fraction_numerical': 0.006312581628210709, 'mean_word_length': 3.6644670050761423, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5054238', 'n_tokens_mistral': 3271, 'n_tokens_neox': 3069, 'n_words': 948}