open-index/open-npm huggingface dataset:
npm package: @level-two/kafka
Description: Kafka broadcast extension for LevelTwo
Author: Corey Hart
Latest version: 2.0.0

# LevelTwo - Kafka

A message broker extension for [LevelTwo](https://www.npmjs.com/package/@level-two/core). Refer to the [Worker API](https://www.npmjs.com/package/@level-two/core#worker-api) for function definitions.

## Usage

```ts
import { createLevelTwoKafka } from "@level-two/kafka";

// Integrates RabbitMQ message broker into a LevelTwo instance
const levelTwo = createLevelTwoKafka({
  topic: "level-two-broadcast",
  clientOptions: {
    brokers: ["localhost:9092"],
  },
});

// Create a worker for getting cacheable customer objects
const worker = levelTwo.createWorker("customer", async (ids, earlyWrite) => {
  const rows = await mysql.query(
    "SELECT id, name FROM customers WHERE id IN (?)",
    [ids]
  );

  rows.forEach((row) => earlyWrite(row.id, row));
});

// Service method for getting a single customer
export async function getCustomer(id: string): Promise<Customer> {
  return await worker.get(id);
}

// Service method for getting a list of customers
export async function getCustomerList(ids: string[]): Promise<Customer[]> {
  return await worker.getMulti(ids);
}
```

## Settings

### `topic`

Topic name for sending/receiving actions

### `clientOptions`

Kafka client options

### `consumerOptions`

Consumer connection options

### `producerOptions`

Producer connection options

### `remoteCache`

LevelTwo remote cache extension

### `cacheDefaults`

LevelTwo worker cache defaults
npm package: @level-two/memcached
Description: Memcached cache extension of level two
Author: Corey Hart
Latest version: 2.0.0

# LevelTwo - Memcached

A cache extension for [LevelTwo](https://www.npmjs.com/package/@level-two/core). Refer to the [Worker API](https://www.npmjs.com/package/@level-two/core#worker-api) for function definitions.

## Usage

```ts
import { MemcachedRemoteCache } from "@level-two/memcached";
import { LevelTwo } from "@level-two/core";

// Adds memcached onto a LevelTwo instance
const levelTwo = new LevelTwo({
  remoteCache: new MemcachedRemoteCache("localhost:11211"),
});

// Create a worker for getting cacheable customer objects
const worker = levelTwo.createWorker("customer", async (ids, earlyWrite) => {
  const rows = await mysql.query(
    "SELECT id, name FROM customers WHERE id IN (?)",
    [ids]
  );

  rows.forEach((row) => earlyWrite(row.id, row));
});

// Service method for getting a single customer
export async function getCustomer(id: string): Promise<Customer> {
  return await worker.get(id);
}

// Service method for getting a list of customers
export async function getCustomerList(ids: string[]): Promise<Customer[]> {
  return await worker.getMulti(ids);
}
```

## Settings

### `cachePrefix`

String prefix to use in front of each cache key

### `clientOptions`

Configuration options for creating a new Memcached client
npm package: @level-two/rabbitmq
Description: RabbitMQ broadcast extension of level two
Author: Corey Hart
Latest version: 2.0.0

# LevelTwo - RabbitMQ

A message broker extension for [LevelTwo](https://www.npmjs.com/package/@level-two/core). Refer to the [Worker API](https://www.npmjs.com/package/@level-two/core#worker-api) for function definitions.

## Usage

```ts
import { createLevelTwoRabbitMQ } from "@level-two/rabbitmq";

// Integrates RabbitMQ message broker into a LevelTwo instance
const levelTwo = createLevelTwoRabbitMQ({
  url: "amqp://localhost:5673/",
});

// Create a worker for getting cacheable customer objects
const worker = levelTwo.createWorker("customer", async (ids, earlyWrite) => {
  const rows = await mysql.query(
    "SELECT id, name FROM customers WHERE id IN (?)",
    [ids]
  );

  rows.forEach((row) => earlyWrite(row.id, row));
});

// Service method for getting a single customer
export async function getCustomer(id: string): Promise<Customer> {
  return await worker.get(id);
}

// Service method for getting a list of customers
export async function getCustomerList(ids: string[]): Promise<Customer[]> {
  return await worker.getMulti(ids);
}
```

## Settings

### `url`

Endpoint for connecting client to

### `broadcastChannel`

Broadcast channel name for sending/receiving actions

### `consumeOptions`

Options when adding consumer listener

### `consumerExchangeOptions`

Options when declaring the consumer exchange

### `consumerQueueOptions`

Options when declaring the consumer queue

### `publishOptions`

Options when publishing a message

### `publisherExchangeOptions`

Options when declaring the publisher exchange

### `remoteCache`

LevelTwo remote cache extension

### `cacheDefaults`

LevelTwo worker cache defaults
npm package: @level-two/redis
Description: Redis message broker and cache extension of LevelTwo
Author: Corey Hart
Latest version: 2.0.0

# LevelTwo - Redis

A message broker and cache extension for [LevelTwo](https://www.npmjs.com/package/@level-two/core). Refer to the [Worker API](https://www.npmjs.com/package/@level-two/core#worker-api) for function definitions.

## Usage

```ts
import { createLevelTwoRedis } from "@level-two/redis";

// Integrates redis pubsub & cache into a LevelTwo instance
const levelTwo = createLevelTwoRedis({
  clientOptions: { url: "redis://localhost:6379" },
});

// Create a worker for getting cacheable customer objects
const worker = levelTwo.createWorker("customer", async (ids, earlyWrite) => {
  const rows = await mysql.query(
    "SELECT id, name FROM customers WHERE id IN (?)",
    [ids]
  );

  rows.forEach((row) => earlyWrite(row.id, row));
});

// Service method for getting a single customer
export async function getCustomer(id: string): Promise<Customer> {
  return await worker.get(id);
}

// Service method for getting a list of customers
export async function getCustomerList(ids: string[]): Promise<Customer[]> {
  return await worker.getMulti(ids);
}
```

## Settings

### `redis`

Existing redis client that should be used in this extension

### `clientOptions`

Configuration options for creating a new redis client

### `broadcastChannel`

Broadcast channel name for sending/receiving actions. Defaults to "level-two-broadcast"

### `cachePrefix`

String prefix to use in front of each cache key

### `cacheDisabled`

Indicates if cache should be disabled or not. Defaults to enabled

### `cacheDefaults`

LevelTwo worker cache defaults