# @egfn/doc-sync

> DocSync is a library that leverages Typescript and Pouchdb/CouchDB to enforce a sychronized document model between the browser and Node.js.

Latest version **1.0.2** (published 2019-12-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @egfn/doc-sync
pnpm add @egfn/doc-sync
yarn add @egfn/doc-sync
bun add @egfn/doc-sync
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-12-31 |
| First published | 2019-12-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 730.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | armin-th |

## Links

- npm: https://www.npmjs.com/package/@egfn/doc-sync
- Repository: https://github.com/eigenfunctor/doc-sync
- npm.io page: https://npm.io/package/@egfn/doc-sync

## Dependencies (6)

- [uuid](https://npm.io/package/uuid.md) ^3.3.3
- [ramda](https://npm.io/package/ramda.md) ^0.26.1
- [pouchdb](https://npm.io/package/pouchdb.md) ^7.1.1
- [pouchdb-find](https://npm.io/package/pouchdb-find.md) ^7.1.1
- [pouchdb-validation](https://npm.io/package/pouchdb-validation.md) ^4.2.0
- [pouchdb-adapter-memory](https://npm.io/package/pouchdb-adapter-memory.md) ^7.1.1

## Recent versions

- 1.0.2 (latest) — 2019-12-31
- 1.0.1 — 2019-12-24
- 1.0.0 — 2019-12-24

## README

# DocSync

DocSync is a library that leverages Typescript and Pouchdb/CouchDB to enforce a sychronized document model between the browser and Node.js.

To learn how to use DocSync, read the documentation [here](https://eigenfunctor.io/doc-sync).

### Installation
```
# with npm
npm install @egfn/doc-sync

# with yarn
yarn add @egfn/doc-sync
```

### Usage
```typescript
import * as DS from "@egfn/doc-sync";
import PouchDB = require("pouchdb");

DS.setupPlugins(PouchDB)

async function main() {
  interface Post {
    body: string;
    reply: Post;
  }

  function PostSpec(): DS.ValidationSpec<Post> {
    return {
      type: "post",
      schema: {
        body: {
          required: true,
          validations: [
            (lib, body) =>
              lib.failIf(
                body.length > 10,
                "Post must be at most 10 characters"
              )
          ]
        },
        reply: {
          spec: PostSpec
        }
      }
    };
  }

  const db = new PouchDB(`test_db`, { adapter: "memory"  });

  // @ts-ignore
  db.installValidationMethods(); // required for local validation

  await DS.defineOnly(db, PostSpec);

  const root = DS.usePathHandle(db, PostSpec, ["feed"]);

  await root
    .then(_ => _.create())
    .then(_ => _.path.reply())
    .then(_ => _.create());

  const list = await root
    .then(_ => _.list())
    .then(_ => Promise.all(_.map(h => h.resolve())));

  const replyList = await root
    .then(_ => _.find())
    .then(_ => _ && _.path.reply())
    .then(_ => _ && _.list())
    .then(_ => _ && Promise.all(_.map(h => h.resolve())))

  console.log(list)
  console.log(replyList)
}

main();
```

### API Reference
See [here](https://eigenfunctor.io/doc-sync/globals.html).

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