# @tangle/overwrite-fields

> a strategy for over-writing object field transformations

Latest version **2.0.3** (published 2023-04-03) · LGPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @tangle/overwrite-fields
pnpm add @tangle/overwrite-fields
yarn add @tangle/overwrite-fields
bun add @tangle/overwrite-fields
```

## 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 | 2.0.3 |
| Published | 2023-04-03 |
| First published | 2021-10-18 |
| Weekly downloads | 0 |
| License | LGPL-3.0-or-later |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 26.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mixmix |
| Maintainers | mixmix, chereseeriepa, cpilbrow |
| Keywords | tangle, strategy |

## Links

- npm: https://www.npmjs.com/package/@tangle/overwrite-fields
- Repository: https://gitlab.com/tangle-js/strategies/overwrite-fields
- Issues: https://gitlab.com/tangle-js/strategies/overwrite-fields/issues
- npm.io page: https://npm.io/package/@tangle/overwrite-fields

## Dependencies (2)

- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [is-my-json-valid](https://npm.io/package/is-my-json-valid.md) ^2.20.5

## Recent versions

- 2.0.3 (latest) — 2023-04-03
- 2.0.2 — 2023-04-03
- 2.0.1 — 2023-03-01
- 2.0.0 — 2021-12-05
- 1.0.2 — 2021-10-19
- 1.0.1 — 2021-10-19
- 1.0.0 — 2021-10-18

## README

# @tangle/overwrite-fields

This strategy can be used to handle transformations which are objects which have arbitrarily set
keys and values (potentially conforming to some pattern):

```js
const T = {
  '@mix': 'mix irving',
  '@colin': 'Colin Pilborow'
}
```

Using concat, subfields can be given new values and additional subfields can be added.
```
overwrite.concat(
  {
    '@mix': 'mixmix',
    '@colin': 'Colin Pilborow'
  },
  {
    '@mix': 'Mix Irving',
    '@cherese': 'Cherese Epinu'
  }
)
// => {
//   '@mix': 'Mix Irving',        // overwrite
//   '@colin': 'Colin Pilborow'
//   '@cherese': 'Cherese Epinu'
// }
```

The internal implementation means that once a subfield is set, it cannot be unset.
If you must erase a field you may want to allow values such as `null` and then choose to ignore that.
This strategy is noncommutative, so it conflicts if the same subfield is set to
different values in different branches. A merge is valid if it overwrites all conflicting subfields.
see tests for examples.

## API

### `Overwrite(opts) => overwrite`

`opts` *Object* (optional) can have properties:
- `opts.keyPattern` *String*
    - add a JSON-schema string pattern
    - default: `'^.+$'`
- `opts.valueSchema` *Object*
    - add a JSON-schema to validate the values which are allowed to be passed in
    - default: `{ type: 'string' }`

### `overwrite.schema`
### `overwrite.isValid`
### `overwrite.identity() => I`
### `overwrite.concat(R, S) => T`
### `overwrite.mapFromInput(input, currentTips) => T`
### `overwrite.mapToOutput(T) => state`

### `overwrite.isConflict(graph, nodeIds, field) => Boolean`
where:
- `graph` is a `@tangle/graph` instance
- `nodeIds` is an Array of nodeIds you're wanting to check for conflict
- `field` *String* contains the the data fields `node.data[field]` you're checking for conflicts

### `overwrite.isValidMerge(graph, mergeNode, field) => Boolean`

where:
- `graph` is a `@tangle/graph` instance
- `mergeNode` is the proposed merge-node
- `field` *String* contains the the data fields `node.data[field]` you're checking for merge validity

### `overwrite.merge(graph, mergeNode, field) => T`

similar to `isValidMerge`, but return a transformation, `T`
If it cannot, an error is thrown!

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