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

# @meforce/rpc-core

Core components for type-safe communication.

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

## Installation

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

## Usage

This package is meant to provide bare-metal components for building custom type-safe communication for everything.
npm package: @meforce/rpc-electron
Description: Type-safe inter-process communication for Electron
Latest version: 1.0.5

# @meforce/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/@meforce/rpc-electron.svg?style=flat-square)](https://www.npmjs.com/package/@meforce/rpc-electron)
[![NPM](https://img.shields.io/npm/dm/@meforce/rpc-electron?style=flat-square)](https://www.npmjs.com/package/@meforce/rpc-electron)

## Installation

```bash
$ npm install --save @meforce/rpc-electron @meforce/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 '@meforce/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 '@meforce/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)
npm package: @meforce/rpc-node
Description: Type-safe communication between message ports from Node.js worker_threads module
Latest version: 1.0.5

# @meforce/rpc-node

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

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

## Installation

```bash
$ npm install --save @meforce/rpc-node @meforce/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 '@meforce/rpc-node';

export interface PingPongService {
  ping(): string;
}

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

- Code for your `worker_thread`:

```ts
import { RpcWorkerHandler } from '@meforce/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