# autocouch

> This package combines the CRDT capacities of Automerge with the replication features of CouchDB. It focuses on an object oriented code style.

Latest version **1.0.1** (published 2020-04-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install autocouch
pnpm add autocouch
yarn add autocouch
bun add autocouch
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-04-10 |
| First published | 2020-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 43.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Pascal Grosch |
| Maintainers | tronso |
| Keywords | crdt, replication, database |

## Links

- npm: https://www.npmjs.com/package/autocouch
- Repository: https://github.com/WoelkiM/AutoCouch
- Homepage: https://github.com/WoelkiM/AutoCouch#README.md
- Issues: https://github.com/WoelkiM/AutoCouch/issues
- npm.io page: https://npm.io/package/autocouch

## Dependencies (7)

- [uuid](https://npm.io/package/uuid.md) ^3.4.0
- [pouchdb](https://npm.io/package/pouchdb.md) ^7.1.1
- [automerge](https://npm.io/package/automerge.md) ^0.12.1
- [cross-env](https://npm.io/package/cross-env.md) ^7.0.0
- [@types/node](https://npm.io/package/@types/node.md) ^13.1.8
- [@types/uuid](https://npm.io/package/@types/uuid.md) ^3.4.6
- [@types/pouchdb](https://npm.io/package/@types/pouchdb.md) ^6.4.0

## Recent versions

- 1.0.1 (latest) — 2020-04-10
- 1.0.0 — 2020-04-10

## README

# AutoCouch

AutoCouch is a TypeScript framework to create object-oriented CRDTs that supports a simple way of distribution.

## Usage

To use AutoCouch in your project add it by installing it via npm:

```
npm i autocouch
```

### Creating Your Own CRDT

To define CRDTs the following steps are necessary:
1. Define the user data in pure JSON that should be contained in the CRDT.
2. Define the object-oriented interface of the CRDT.
3. Extend ``AutoCouchCRDT``.
4. Use the ``change`` function with the fitting callback to implement your interface and mutate your user data.
5. Use ``CRDTFactory.registerType(...)`` to pass the correct parameters to the constructor to create and load your object.

### Handling External Updates

When an update on an object was caused by another node the local replications are notified.
To handle the update one can register handlers via the ``AutoCouchCRDT.on(...)`` function.
If a handler is not needed anymore it can be removed via ``AutoCouchCRDT.off(...)``.

### Using the Database and ObjectRegistry

In some special cases like an object-oriented container CRDT manually using the ``ObjectRegistry`` and ``Database`` might be helpful.
``Database`` is a simplified wrapper of a [PouchDB](https://pouchdb.com/api.html) that allows getting and putting documents.
It can be used to save special documents of your application under a globally known ID.

``ObjectRegistry`` is a simple registry and cache that stores an object under its ID and loads it from the database if it is not found.
It can be used to reference objects from a CRDT container.

### Example Usage

An example of how the framework is integrated in a React based web-app can be found at [Polly](https://github.com/WoelkiM/Polly_React_Example_AutoCouch).

---
_Source: https://npm.io/package/autocouch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
