# pear-rpc

> RPC for Pear

Latest version **0.0.7** (published 2024-03-13) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install pear-rpc
pnpm add pear-rpc
yarn add pear-rpc
bun add pear-rpc
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2024-03-13 |
| First published | 2024-02-28 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 30.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Holepunch |
| Maintainers | davidmarkclements |

## Links

- npm: https://www.npmjs.com/package/pear-rpc
- Repository: https://github.com/holepunchto/pear-rpc
- Homepage: https://github.com/holepunchto/pear-rpc#readme
- Issues: https://github.com/holepunchto/pear-rpc/issues
- npm.io page: https://npm.io/package/pear-rpc

## Dependencies (10)

- [fs](https://npm.io/package/fs.md) npm:bare-node-fs
- [path](https://npm.io/package/path.md) npm:bare-node-path
- [bare-fs](https://npm.io/package/bare-fs.md) ^2.2.1
- [streamx](https://npm.io/package/streamx.md) ^2.16.1
- [bare-path](https://npm.io/package/bare-path.md) ^2.1.0
- [bare-pipe](https://npm.io/package/bare-pipe.md) ^2.0.4
- [which-runtime](https://npm.io/package/which-runtime.md) ^1.2.0
- [ready-resource](https://npm.io/package/ready-resource.md) ^1.0.3
- [tiny-buffer-rpc](https://npm.io/package/tiny-buffer-rpc.md) ^2.0.1
- [fs-native-extensions](https://npm.io/package/fs-native-extensions.md) ^1.2.7

## Recent versions

- 0.0.7 (latest) — 2024-03-13
- 0.0.6 — 2024-03-12
- 0.0.5 — 2024-03-01
- 0.0.4 — 2024-03-01
- 0.0.3 — 2024-03-01
- 0.0.2 — 2024-03-01
- 0.0.1 — 2024-02-28
- 0.0.0 — 2024-02-28

## README

# `pear-rpc`

RPC for Pear

```
npm install pear-rpc
```

## API 

```js
const RPC = require('pear-rpc')
```

```js
import RPC from 'pear-rpc'
```

### `const rpc = new RPC(opts)`

Accepts a transport stream and creates an instance that can handle both incoming Remote Procedure Calls (RPCs) and generates corresponding instance methods for outgoing RPCs.

**Options**

* `stream` `<Duplex>` - the transport stream
* `methods` `<Array... String|{ name: <String>, stream: <Boolean(false)>, send: <Boolean(false)> }>` - an index of method descriptions. The order of methods (and their settings) must be consistent across all RPC instances using the same method set. The index of a method in the array is that methods uint identifier. `['myMethod']` and `[{name: 'myMethod'}]` are equivalent. Generated methods default to being request-based (`stream:false` and `send:false`). Setting `send: true` will generate a fire-and-forget method. Setting `stream: true` will generate a method that returns a [Streamx][https://github.com/mafintosh/streamx] stream response. For more complex cases, the `api` option can be used to wrap define the instance method.
* `api` `{ [name]: (method) => (params) => <Stream|Promise|Any> }` - Define outgoing methods on the RPC instance. Property names on the `api` object matching names in the `methods` array will be used to generate instance methods if provided. A [tiny-buffer-rpc](https://github.com/holepunchto/tiny-buffer-rpc/) `method` object will be passed. Call any/all of `method.request` `method.send` or `method.createRequestStream` and make any other calls or alterations as needed.
* `handlers` - `{ [name]: (params) => <Stream|Promise|Any> }` - Handle incoming calls. Property names on the `handlers` object matching names in the `methods` array passed the incoming `params` object. It is up to the handler to return the correct response for that method. 


## License

Apache-2.0

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