open-index/open-npm huggingface dataset:
npm package: @soketi/routing
Description: `@soketi/routing` is a package that contains the routing logic for the soketipfs server, as well as the logic for handling custom events in the network.
Latest version: 0.1.4

# @soketi/routing

`@soketi/routing` is a package that contains the routing logic for the soketipfs server, as well as the logic for handling custom events in the network.

## Usage

### Generic Router

The `GenericRouter` class is used to handle custom events in the network. It's a generic implementation that can be used to handle any type of events.

```ts
import { GenericRouter } from '@soketi/routing';

const router = new GenericRouter();

router.registerHandler('some-event', async (data) => {
  console.log(data);
});

router.handle('some-event', 'Hello world!');
```

The `registerHandler` and `handle` accept any number of arguments, which are passed to the handler.

```ts
router.registerHandler('add', async (a, b) => {
  return a + b;
});

const result = await router.handle('add', 1, 2);
```

### Websockets Router

The `WebsocketsRouter` class is used to handle custom events in the network, but it's specifically designed to work with the WebSockets server by adding some specific events.

```ts
import { Connection } from '@soketi/connections';
import { WebsocketsRouter } from '@soketi/routing';

const router = new WebsocketsRouter();

// 1. New connection
router.onNewConnection(async (conn: Connection) => {
  // ...
});

await router.handleNewConnection(conn);

// 2. Connection closed
router.onConnectionClosed(async (conn: Connection) => {
  // ...
});

await router.handleConnectionClosed(conn);

// 3. Message handling
router.onMessage(async (conn: Connection, message: any) => {
  // ...
});

await router.handleMessage(conn, 'hello');

// 4. Error handling
router.onError(async (conn: Connection, error: any) => {
  // ...
});

await router.handleError(conn, 'hello');

// 5. Custom handlers
// Built on top of the GenericRouter, it can handle custom events.
router.registerHandler('some-event', async (data) => {
  console.log(data);
});

router.handle('some-event', 'Hello world!');
```

## Development

This library was generated with [Nx](https://nx.dev).

### Building

Run `nx build routing` to build the library.

### Running unit tests

Run `nx test routing` to execute the unit tests via [Vitest](https://vitest.dev/).

---
npm package: @soketi/utils
Description: `@soketi/utils` is a package that contains utility functions used across the packages.
Latest version: 0.1.4

# @soketi/utils

`@soketi/utils` is a package that contains utility functions used across the packages.

## Development

This library was generated with [Nx](https://nx.dev).

### Building

Run `nx build utils` to build the library.

### Running unit tests

Run `nx test utils` to execute the unit tests via [Vitest](https://vitest.dev/).

---