# @coryfoundation/translink

> Link your nodes simple without the need for queues and intermediate servers!

Latest version **1.3.7** (published 2022-03-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @coryfoundation/translink
pnpm add @coryfoundation/translink
yarn add @coryfoundation/translink
bun add @coryfoundation/translink
```

## 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.3.7 |
| Published | 2022-03-04 |
| First published | 2022-01-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 40.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | cory.foundation |
| Maintainers | srngmw |
| Keywords | p2p, dht, decentralized, hyperswarm, hypercore |

## Links

- npm: https://www.npmjs.com/package/@coryfoundation/translink
- Repository: https://github.com/coryfoundation/translink
- Issues: https://github.com/coryfoundation/translink/issues
- npm.io page: https://npm.io/package/@coryfoundation/translink

## Dependencies (3)

- [bluebird](https://npm.io/package/bluebird.md) ^3.7.2
- [msgpack5](https://npm.io/package/msgpack5.md) ^5.3.2
- [hyperswarm](https://npm.io/package/hyperswarm.md) ^3.0.2

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.3.7 (latest) — 2022-03-04
- 1.3.6 — 2022-03-04
- 1.3.5 — 2022-02-23
- 1.3.4 — 2022-02-23
- 1.3.3 — 2022-02-23
- 1.3.2 — 2022-02-23
- 1.3.0 — 2022-02-23
- 1.2.3 — 2022-02-22
- 1.2.2 — 2022-02-22
- 1.2.1 — 2022-02-09
- 1.2.0 — 2022-02-08
- 1.1.9 — 2022-02-03
- 1.1.8 — 2022-01-17
- 1.1.7 — 2022-01-17
- 1.1.6 — 2022-01-17
- … 8 more at https://npm.io/package/@coryfoundation/translink/versions

## README

# translink ![GitHub Repo stars](https://img.shields.io/github/stars/coryfoundation/translink)

A high-level API for connecting nodes together using **P2P** and **DHT** without using message brokers, queues and intermediate servers.

All messages are encrypted with **end-to-end encryption** (more: https://hypercore-protocol.org)


## Installation
```
npm install @coryfoundation/translink
```

```js
import Translink from '@coryfoundation/translink'

const bridge = new Translink(options)

// Subscriptions here

bridge.connect()
  .then(() => console.log('Connected'))
  .catch((e) => console.error('Connection error', e))

```

## Options

#### `namespace (string)`
Namespace for recognition on the network. Must be the same on all nodes.
* **Required:** `true`

#### `nodeID (string)`
Node identifier. Must be unique.
* **Required:** `false`
* **Default:** `random string`

#### `log (boolean)`
Determines whether to write module messages to the console.
* **Required:** `false`
* **Default:** `true`

#### `logger (console-like class)`
Allows you to set your console-like class for logging.
* **Required:** `false`
* **Default:** `console`

#### `encoding (string)`
The encoding that should be used to encode and decode messages. **utf8** is currently supported only.
* **Required:** `false`
* **Default:** `utf8`

#### `requestTimeout (number)`
Timeout for the request, after which Error will be thrown on the sender's side. In milliseconds.
* **Required:** `false`
* **Default:** `10000`

#### `heartbeatInterval (number)`
The interval after which the heartbeat will be sent to other nodes.
* **Required:** `false`
* **Default:** `5000`

#### `heartbeatTimeout (number)`
Timeout, after which the node will be removed from the list of available nodes.
* **Required:** `false`
* **Default:** `10000`

#### `maxClientConnections (number)`
Maximum client connections to be allowed.
* **Required:** `false`
* **Default:** `Infinity`

#### `maxServerConnections (number)`
Maximum server connections to be allowed.
* **Required:** `false`
* **Default:** `Infinity`

#### `maxPeers (number)`
Maximum peers to be allowed.
* **Required:** `false`
* **Default:** `Infinity`

#### `maxParallel (number)`
Maximum parallel connections to be allowed.
* **Required:** `false`
* **Default:** `Infinity`

#### `broadcastReqConcurrency (number)`
Request concurrency for **broadcastReq()** method
* **Required:** `false`
* **Default:** `5`

#### `broadcastReqTimeout (number)`
Request timeout for **broadcastReq()** method
* **Required:** `false`
* **Default:** `1000`

#### `waitForPeer (boolean)`
Do we need to wait for the connection of the peer
* **Required:** `false`
* **Default:** `true`

## Usage
### Request
#### Subscribe
```js
bridge.subscribeReq('my.request', async (data) => {
  // Something to do with data
  return { hello: 'world' }
})
```
#### Send
```js
bridge.get('my.request', { something: 'data' })
.then((response) => {
  // Something to do with response
}).catch((error) => {
  console.error('Error', error)
})
```

### Event
#### Subscribe
```js
bridge.subscribe('my.event', async (data) => {
  // Something to do with data
})
```
#### Send
```js
bridge.emit('my.event', { world: 'hello' })
```

### Broadcast
#### Request
##### No all node responses needed
```js
bridge.broadcastReq('my.request', { world: 'hello' })
.then((results) => {
  // results is array with all responses
}).catch((error) => {
  console.error('Error', error)
})
```

#### Event
##### With same event subscription
```js
bridge.broadcast('my.event', { world: 'hello' })
```

##### All nodes
```js
bridge.broadcastToAllNodes('my.event', { world: 'hello' })
```

## Replic nodes
You can duplicate nodes with the same subscriptions an infinite number of times. Translink will send a message to a random available suitable node.

## License
MIT

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