# json-patch-ot-agent

> OT Agent/Queue for JSON-Patch OT - makes sure that your JSON Patches (RFC6902) gets transformed and applied in correct order

Latest version **2.0.0-rc.1** (published 2019-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-patch-ot-agent
pnpm add json-patch-ot-agent
yarn add json-patch-ot-agent
bun add json-patch-ot-agent
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0-rc.1 |
| Published | 2019-08-15 |
| First published | 2017-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 0.4.0 |
| Dependencies | 1 |
| Unpacked size | 37.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Tomek Wytrebowicz |
| Maintainers | alshakero, tomalec, warpech |
| Keywords | jsonpatch, json-patch, OT, versioned-json-patch, json, queue |

## Links

- npm: https://www.npmjs.com/package/json-patch-ot-agent
- Repository: https://github.com/Palindrom/JSON-Patch-OT-agent
- Issues: https://github.com/Palindrom/JSON-Patch-OT-agent/issues
- npm.io page: https://npm.io/package/json-patch-ot-agent

## Dependencies (1)

- [json-patch-queue](https://npm.io/package/json-patch-queue.md) >=3.0.0-rc.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.0-rc.1 (latest) — 2019-08-15
- 2.0.0-rc.0 — 2017-10-04
- 1.1.2 — 2017-03-10
- 1.1.0 — 2017-03-09

## README

# JSON-Patch-OT-Agent
> Makes your JSON Patch application sequential

[![Build Status](https://travis-ci.org/Palindrom/JSON-Patch-OT-agent.svg?branch=master)](https://travis-ci.org/Palindrom/JSON-Patch-OT-agent)

Implements a queue of JSON Patches, based on [Versioned JSON Patch](https://github.com/tomalec/Versioned-JSON-Patch) convention, that will resolve a problem of sequential application of JSON Patches.

## Demo
[Full Versioned JSON Patch + OT visualization](http://tomalec.github.io/PuppetJs-operational-transformation/visualization.html)

Specific visualization will come soon.


## Install

Install the component using NPM

```sh
$ npm install json-patch-ot-agent --save
```

Or

Install the component using [Bower](http://bower.io/):

```sh
$ bower install json-patch-ot-agent --save
```

Or [download as ZIP](https://github.com/Palindrom/JSON-Patch-OT-Agent/archive/master.zip).

## Usage

```javascript
var targetObject = {};
// create queue
var myQueue = new new JSONPatchOTAgent(targetObject,
                jsonpatchTransform,
                ['/localVersion', '/remoteVersion'],
                jsonpatch
             );
// to compose versioned JSON Patch, to be send somewhere?
var versionedPatchToBeSent = myQueue.send(regularPatch);
// to apply/queue/transform received versioned JSON Patch
myQueue.receive(receivedVersionedPatch);
```

## Requirements

Agent requires a specific `transform` function (as a first argument), if you do not have your own, we advise you [JSON-Patch-OT](https://github.com/Palindrom/JSON-Patch-OT) (`bower install json-patch-ot`).
You will also need function to apply JSON Patch, we suggest [fast JSON Patch](https://github.com/Starcounter-Jack/JSON-Patch) (`bower install fast-json-patch`).

## Methods

Name      | Arguments                     | Default | Description
---       | ---                           | ---     | ---
`send`    | *JSONPatch* sequence          |         | Changes given JSON Patch to Versioned JSON Patch
`receive` | *VersionedJSONPatch* sequence |         | Versioned JSON Patch to be queued and applied
`JSONPatchQueue`  | *Object* obj          |         | Target object where patches are applied
__  | *Function* transform |         |  `function(patch, againstPatch_es)` function to transform given JSON Patch against others
__  |*Array* *JSONPointer* [localVersionPath, remoteVersionPath] |         | Paths where to store the versions
  __             | *Function* apply     |         | `function(object, patch)` function to apply JSON Patch, must return the final state of the object
 __                 | *Boolean* purist     | `false` | set to `true` to enable pure/unoptimized Versioned JSON Patch convention

## Properties

Name      | Type                          | Description
---       | ---                           | ---
`obj`     |  *`Object`* obj               | Target object where patches are applied
`waiting` | *Array* *JSONPatch*           | Array of JSON Patches waiting in queue
`localVersion` | *Number*           | local version
`remoteVersion` | *Number*           | acknowledged remote version
`ackLocalVersion` | *Number*           | local version that is for sure acknowledged by remote

## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -m 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## History

For detailed changelog, check [Releases](https://github.com/Palindrom/JSON-Patch-OT-Agent/releases).

## License

MIT

## See also
- [fast JSON Patch](https://github.com/Starcounter-Jack/JSON-Patch)
- [JSON Patch Queue](https://github.com/Palindrom/JSON-Patch-Queue)
- [JSON Patch OT](https://github.com/Palindrom/JSON-Patch-OT)
- ...putting it all together: [Palindrom](https://github.com/Palindrom/Palindrom)

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