# @webwallet/graphstore

> Graph database queries and connection handling.

Latest version **0.3.4** (published 2020-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @webwallet/graphstore
pnpm add @webwallet/graphstore
yarn add @webwallet/graphstore
bun add @webwallet/graphstore
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.4 |
| Published | 2020-02-21 |
| First published | 2017-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | webwallet.org |
| Maintainers | webwallet |
| Keywords | transactions, clearing, graph, neo4j |

## Links

- npm: https://www.npmjs.com/package/@webwallet/graphstore
- Repository: https://github.com/webwallet/graphstore
- Homepage: https://github.com/webwallet/graphstore#readme
- Issues: https://github.com/webwallet/graphstore/issues
- npm.io page: https://npm.io/package/@webwallet/graphstore

## Dependencies (2)

- [neo4j-driver](https://npm.io/package/neo4j-driver.md) ^1.7.6
- [require-directory](https://npm.io/package/require-directory.md) ^2.1.1

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 0.3.4 (latest) — 2020-02-21
- 0.3.3 — 2020-02-19
- 0.3.2 — 2020-02-03
- 1.0.3 — 2019-12-02
- 1.0.2 — 2019-11-13
- 1.0.1 — 2019-10-18
- 1.0.0 — 2019-10-15
- 0.3.1 — 2019-05-22
- 0.3.0 — 2019-02-17
- 0.2.1 — 2018-09-23
- 0.2.0 — 2018-07-06
- 0.1.1 — 2017-07-11
- 0.1.0 — 2017-07-10

## README

# WebWallet Graphstore
Transaction clearing microservice for the WebWallet API.

## Contents
- Graph Database
- Data Modeling
- Query Design

## Graph Database
### Neo4j
  - **Cypher**

## Data Modeling

### Nodes
Labels: `IOU`, `Address`, `Currency`, `Transaction`, `Outputs`.

  - **IOU**
  - **Address**
  - **Currency**
  - **Transaction**  
A transaction is a document, not an operation. Inserting a `Transaction` node is not equivalent to executing a transaction, which involves creating other nodes and relationships as well.
    - **Outputs**

### Relationships
Types: `Funds`, `Spends`, `Points`.

  - **Clearing**
    - **IOUs**
    - **Outputs**
  - **Indexing**
    - **Outputs**

### Constraints
  Nodes with `Address` labels must satisfy the `id` property uniqueness constraint. Since `Transaction` nodes will be retrieved through traversals starting at `Address` nodes using their `Outputs` node (manual index), no constraint is imposed on `Transaction` node IDs in order to prevent a potentially large index from being created automatically by the database.
  ```
  CREATE CONSTRAINT ON (address:Address) ASSERT address.id IS UNIQUE
  ```
  Since uniqueness contraints cannot be created on relationships, `CREATE UNIQUE` must be used in combination with previous checks in order to manually enforce unique relationships on nodes.
  ```
  ...
  WHERE NOT (txo)<-[:Spends {id:0}]-()
  CREATE UNIQUE (txo)<-[s:Spends {id: 0}]-(txn)
  ...
  ```
  Relationships with `Spends` labels should satisfy the `id` property existence constraint [enterprise edition feature]. Since `Transaction` documents contain outputs that can be referenced by subsequent transactions for clearing purposes, every `Transaction` that `Spends` another `Transaction` must specify which output it is referencing/spending.
  ```
  CREATE CONSTRAINT ON ()-[output:Spends]-() ASSERT exists(output.id)
  ```

## Query Design

### Clearing
  - **Output Spending**
  ```
  MATCH (txo:Transaction)
  WHERE txo.id = {transactionId}
  SET txo.lock = true
  WITH txo
  WHERE NOT (txo)<-[:Spends {id:{outputId}}]-()
  CREATE UNIQUE (txo)<-[:Spends {id: {outputId}}]-(txn:Transaction)
  REMOVE txo.lock
  RETURN txo, txn
  ```

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