open-index/open-npm huggingface dataset:
npm package: @pythiacorporation/rpc-core
Description: Core components for type-safe inter-process communication
Latest version: 1.0.4

# @wexond/rpc-core

Core components for type-safe communication.

[![NPM](https://img.shields.io/npm/v/@wexond/rpc-core.svg?style=flat-square)](https://www.npmjs.com/package/@wexond/rpc-core)
[![NPM](https://img.shields.io/npm/dm/@wexond/rpc-core?style=flat-square)](https://www.npmjs.com/package/@wexond/rpc-core)

## Installation

```bash
$ npm install --save @wexond/rpc-core
```

## Usage

This package is meant to provide bare-metal components for building custom type-safe communication for everything.

## Documentation

WIP
npm package: @pythiacorporation/rpc-electron
Description: Type-safe inter-process communication for Electron
Latest version: 1.0.4

# @wexond/rpc-electron

Type-safe communication between Electron processes.
No more remembering IPC channel names, parameters order and their types.

[![NPM](https://img.shields.io/npm/v/@wexond/rpc-electron.svg?style=flat-square)](https://www.npmjs.com/package/@wexond/rpc-electron)
[![NPM](https://img.shields.io/npm/dm/@wexond/rpc-electron?style=flat-square)](https://www.npmjs.com/package/@wexond/rpc-electron)

## Installation

```bash
$ npm install --save @wexond/rpc-electron @wexond/rpc-core
```

## Quick start

Here's an example of communication from the renderer process to the main process:

- Create a file that is imported in both main and renderer processes, for example `ping-pong.ts`:

```ts
import { RendererToMainChannel } from '@wexond/rpc-electron';

export interface PingPongService {
  ping(): string;
}

export const pingPongChannel = new RendererToMainChannel<PingPongService>(
  'ping-pong',
);
```

- Code for the renderer process:

```ts
import { ipcRenderer } from 'electron';
import { pingPongChannel } from './ping-pong';

const pingPongService = pingPongChannel.getInvoker();

(async () => {
  // Equivalent of |ipcRenderer.invoke|
  console.log(await pingPongService.ping()); // Prints `pong`.
})();
```

- Code for the main process:

```ts
import { RpcMainHandler } from '@wexond/rpc-electron';
import { PingPongService, pingPongChannel } from './ping-pong';

// Equivalent of |ipcMain.handle|
class PingPongHandler implements RpcMainHandler<PingPongService> {
  ping(): string {
    return 'pong';
  }
}

pingPongChannel.getReceiver().handler = new PingPongHandler();
```

### More examples

- [Renderer to Main](examples/renderer-to-main)

## Documentation

WIP
npm package: @pythiacorporation/rpc-node
Description: Type-safe communication between message ports from Node.js worker_threads module
Latest version: 1.0.4

# @wexond/rpc-node

Type-safe communication between message ports from Node.js worker_threads module.

[![NPM](https://img.shields.io/npm/v/@wexond/rpc-node.svg?style=flat-square)](https://www.npmjs.com/package/@wexond/rpc-node)
[![NPM](https://img.shields.io/npm/dm/@wexond/rpc-node?style=flat-square)](https://www.npmjs.com/package/@wexond/rpc-node)

## Installation

```bash
$ npm install --save @wexond/rpc-node @wexond/rpc-core
```

## Quick start

Here's an example of communication from the main thread to a `worker_thread`:

- Create a file that is imported in both the `worker_thread` and the main thread, for example `ping-pong.ts`:

```ts
import { WorkerChannel } from '@wexond/rpc-node';

export interface PingPongService {
  ping(): string;
}

export const pingPongChannel = new WorkerChannel<PingPongService>('ping-pong');
```

- Code for your `worker_thread`:

```ts
import { RpcWorkerHandler } from '@wexond/rpc-node';
import { PingPongService, pingPongChannel } from './ping-pong';

class PingPongHandler implements RpcWorkerHandler<PingPongService> {
  // Equivalent of |parentPort.on('message')|
  ping(): string {
    return 'pong';
  }
}

// |parentPort| is the default value for the |messagePort| parameter in |getReceiver|.
pingPongChannel.getReceiver().handler = new PingPongHandler();
```

- Code for the main thread:

```ts
import { resolve } from 'path';
import { Worker } from 'worker_threads';

import { pingPongChannel } from './ping-pong';

const worker = new Worker('path/to/worker.js');
const pingPongService = pingPongChannel.getInvoker(worker);

(async () => {
  console.log(await pingPongService.ping()); // Prints `pong`.
})();
```

### More examples

- [Main to Worker](examples/main-to-worker)

## Documentation

WIP