open-index/open-npm huggingface dataset:
npm package: @leocode/better-axios-error
Description: Enhance your axios errors in a simple way
Latest version: 2.0.0

# better-axios-errors

Enhance your axios errors in a simple way

Typical axios error looks like this:

```
Error: Request failed with status code 404
  at createError (/home/leocode/Leocode/better-axios-error/node_modules/axios/lib/core/createError.js:16:15)
  at settle (/home/leocode/Leocode/better-axios-error/node_modules/axios/lib/core/settle.js:17:12)
  at IncomingMessage.handleStreamEnd (/home/leocode/Leocode/better-axios-error/node_modules/axios/lib/adapters/http.js:244:11)
  at IncomingMessage.emit (events.js:327:22)
  at endReadableNT (internal/streams/readable.js:1327:12)
  at processTicksAndRejections (internal/process/task_queues.js:80:21)
```

Without any useful information about where in the code the error happened.

After adding simple

```
const axios = enhanceAxios(Axios.create())
```

Calling axios with errors results in

```
Error: Request failed with status code 404
    at createError (/home/leocode/Leocode/better-axios-error/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/home/leocode/Leocode/better-axios-error/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/home/leocode/Leocode/better-axios-error/node_modules/axios/lib/adapters/http.js:244:11)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Thrown at:
    at async hahaNobodyWillSeeMe (/home/leocode/Leocode/better-axios-error/tests/test.js:6:3)
    at async /home/leocode/Leocode/better-axios-error/tests/test.js:16:3
```

So the stack trace of code that caused a problem is included, and we see that `hahaNobodyWillSeeMe` method was responsible!

## Installation

`yarn add @leocode/better-axios-errors axios`

or

`npm install --save @leocode/better-axios-errors axios`

## Usage

Instead of importing axios directly from library,
create a file, that will export enhanced one!

```js
import axios from 'axios';
import { enhanceAxios } from '@leocode/better-axios-errors';

export const enhancedAxios = enhanceAxios(axios.create());
```

Now you can use `enhancedAxios` as normal axios instance.

Also, if you want to import enhanced axios instance, you can do it directly:

```js
import { axios } from '@leocode/better-axios-errors';
```
npm package: @leocode/eslint-config
Description: ## Installation
Latest version: 2.0.0

# LEOCODE's ESLint config

## Installation

1. Install all peer dependencies. You can use your favourite tool or just type:

```
For React:

yarn add --dev eslint@8 @typescript-eslint/eslint-plugin@5 @typescript-eslint/parser@5 eslint-plugin-react@7.27.0 eslint-plugin-react-hooks@4.3.0 typescript@4

For Node:

yarn add --dev eslint@8 @typescript-eslint/eslint-plugin@5 @typescript-eslint/parser@5 typescript@4
```

2. Install package with configuration:

```
yarn add --dev @leocode/eslint-config
```

## Usage

For node put this in `.eslintrc.js` file:

```js
module.exports = {
  extends: ['@leocode/eslint-config/node'],
};
```

For React put this in `.eslintrc.js` file:

```js
module.exports = {
  extends: ['@leocode/eslint-config/react'],
};
```

## License

MIT
npm package: @leocode/nest-tx-core
Description: This is the core package for nest-tx. It provides interfaces that are then implemented in a specific adapter. To see how to use nest-tx, consult the documentation of one of the adapters.
Author: Tymoteusz Dzienniak
Latest version: 1.0.1

# next-tx-core

This is the core package for nest-tx. It provides interfaces that are then implemented in a specific adapter. To see how
to use nest-tx, consult the documentation of one of the adapters.
npm package: @leocode/nest-tx-knex
Description: A Knex connector for next-tx.
Author: Tymoteusz Dzienniak
Latest version: 1.0.1

# nest-tx-knex

A Knex connector for next-tx.

## Installation

Yarn:

```
yarn add next-tx-core nest-tx-knex
```

NPM:

```
npm install next-tx-core nest-tx-knex
```

## Usage

Initialize the module first. Here we are using `nestjs-knex` packed to initialize Knex connection:

```typescript
import { Module } from '@nestjs/common';
import { getKnexConnectionToken, KnexModule } from 'nestjs-knex';
import { TransactionManager } from '@leocode/nest-tx-core';
import { KnexTransactionManagerModule, getKnexTransactionFromTransaction } from '@leocode/nest-tx-knex';

@Module({
  imports: [
    KnexModule.forRoot({
      config: {
        client: 'pg',
        connection: {
          host: 'localhost',
          port: 5432,
          user: 'postgres',
          password: 'secret',
          database: 'postgres',
        },
      },
    }),
    KnexTransactionManagerModule.forRoot({
      // we need to provide a connection token
      // so the TX manager can get a Knex connection from the DI container
      getConnectionToken: () => {
        return getKnexConnectionToken('');
      },
    }),
  ],
})
class AppModule {}
```

Then you can use it in your services:

```typescript
import { Injectable } from '@nestjs/common';
import { InjectTransactionManager, TransactionManager } from '@leocode/nest-tx-core';
import { getKnexTransactionFromTransaction } from '@leocode/nest-tx-knex';

@Injectable()
class CatsService {
  constructor(
    @InjectTransactionManager() private readonly transactionManager: TransactionManager,
  ) {}

  public async save() {
    await this.transactionManager.withTransaction(async tx => {
      const knexTrx = getKnexTransactionFromTransaction(tx);

      await knexTrx.raw('select 1 + 1');
    });
  }
}
```
npm package: @leocode/nest-tx-kysely
Description: A Kysely connector for next-tx.
Author: Tymoteusz Dzienniak
Latest version: 1.0.0

# nest-tx-kysely

A Kysely connector for next-tx.

## Installation

Yarn:

```
yarn add next-tx-core nest-tx-kysely kysely
```

NPM:

```
npm install next-tx-core nest-tx-kysely kysely
```

## Usage

Initialize the module first. Here we are using custom module for creating Kysely instance:

```typescript
import { Module } from '@nestjs/common';
import { TransactionManager } from '@leocode/nest-tx-core';
import { KyselyTransactionManagerModule } from '@leocode/nest-tx-kysely';

@Module({})
export class KyselyModule {
  public static forRoot(options: { name: string; }): DynamicModule {
    const providers = [{
      provide: options.name,
      useFactory: () => {
        return new Kysely<unknown>({
          dialect: new PostgresDialect({
            pool: new Pool({
              host: 'localhost',
              port: 5432,
              user: 'postgres',
              password: 'secret',
              database: 'postgres',
            })
          })
        })
      },
    }];

    return {
      module: KyselyModule,
      providers: providers,
      exports: providers,
      global: true,
    }
  }
}

const KYSELY_INSTANCE_NAME = 'kysely__default';

@Module({
  imports: [
    KyselyModule.forRoot({
      name: KYSELY_INSTANCE_NAME,
    }),
    KyselyTransactionManagerModule.forRoot({
      // we need to provide an instance token
      // so the TX manager can get a Kysely instance from the DI container
      getInstanceToken: () => {
        return KYSELY_INSTANCE_NAME;
      },
    }),
  ],
})
class AppModule {}
```

Then you can use it in your services:

```typescript
import { Injectable } from '@nestjs/common';
import { InjectTransactionManager, TransactionManager } from '@leocode/nest-tx-core';

interface TestTable {
  id: number;
}

interface Database {
  test: TestTable;
}

@Injectable()
class CatsService {
  constructor(
    @InjectTransactionManager() private readonly transactionManager: TransactionManager,
  ) {
  }

  public async save() {
    await this.transactionManager.withTransaction(async tx => {
      const kyselyTrx = tx.getKyselyTransaction<Database>();

      await kyselyTrx.selectFrom('test').selectAll().execute();
    });
  }
}
```
npm package: @leocode/nest-tx-typeorm
Description: A TypeORM connector for next-tx.
Author: Tymoteusz Dzienniak
Latest version: 2.0.0

# nest-tx-typeorm

A TypeORM connector for next-tx.

## Installation

Yarn:

```
yarn add next-tx-core nest-tx-typeorm
```

NPM:

```
npm install next-tx-core nest-tx-typeorm
```

## Usage

Initialize the module first. Here we are using `@nestjs/typeorm` package to initialize a TypeORM connection:

```typescript
import { Module } from '@nestjs/common';
import { getDataSourceToken, TypeOrmModule } from '@nestjs/typeorm';
import { TransactionManager } from '@leocode/nest-tx-core';
import { TypeORMTransactionManagerModule } from '@leocode/nest-tx-typeorm';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'postgres',
      password: 'secret',
      database: 'postgres',
      entities: [TestEntitySchema],
    }),
    TypeORMTransactionManagerModule.forRoot({
      getDataSourceToken: () => getDataSourceToken(),
    }),
  ],
})
class AppModule {}
```

Then you can use it in your services:

```typescript

import { Injectable, Module } from '@nestjs/common';
import { InjectTransactionManager, TransactionManager } from '@leocode/nest-tx-core';
import {
  getEntityManagerFromTypeORMTransaction,
  TypeORMTransactionManagerModule
} from '@leocode/nest-tx-typeorm';

@Injectable()
class CatsService {
  constructor(
    @InjectTransactionManager() private readonly transactionManager: TransactionManager,
  ) {}

  public async save() {
    await this.transactionManager.withTransaction(async tx => {
      const manager = tx.getEntityManager();

      const qb = await manager
        .createQueryBuilder()
        .select('id')
        .from('cats')
        .getRawMany();
    });
  }
}
```

If you have multiple named TypeORM connections, you can provide an instance of the transaction manager for each of them:

```typescript
@Module({
  imports: [
    // default
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'postgres',
      password: 'secret',
      database: 'postgres',
      entities: [TestEntitySchema],
    }),
    // named 'secondConnection'
    TypeOrmModule.forRoot({
      name: 'secondConnection',
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'postgres',
      password: 'secret',
      database: 'postgres',
      entities: [TestEntitySchema],
    }),
    // tx manager for the default connection
    TypeORMTransactionManagerModule.forRoot({
      getDataSourceToken: () => getDataSourceToken(),
    }),
    // tx manager for the 'secondConnection' connection
    TypeORMTransactionManagerModule.forRoot({
      getDataSourceToken: () => getDataSourceToken('secondConnection'),
      name: 'secondConnection'
    }),
  ],
})
class AppModule {}
```

Then in the service, you need to use the connection name in the injection decorator:

```typescript
@Injectable()
class CatsService {
  constructor(
    @InjectTransactionManager('secondConnection') private readonly transactionManager: TransactionManager,
  ) {}
}
```
npm package: @leocode/rabbitmq-defgen
Description: CLI tool for generating rabbitmq definitions in various format (JSON, Terraform resources) directly out of application code.
Latest version: 0.1.1

# rabbitmq-defgen

CLI tool for generating rabbitmq definitions in various format (JSON, Terraform resources) directly out of application code.

Currently it supports only NestJS and requires specific decorators.

## Installation

`yarn add --dev @leocode/rabbitmq-defgen`

(it can be also installed globally and/or with `npm`)

## Usage

### Quick reference

Terraform output:

`yarn rabbitmq-defgen --vhost dev -o terraform -i ./dist/app.module.js > rabbitmq.tf`

JSON output:

`yarn rabbitmq-defgen --vhost dev --username rabbitmq --password rabbitmq -o json -i ./dist/app.module.js > rabbitmq.tf`

### Parameters

parameter | required | description
--- | --- | ---
--vhost | [x] | vhost parameter for which definitions will be generated
-o / --output | [x] | (terraform/json) determines export style
-i / --input | [x] | path to file with **build** root application NestJS module. **Expected to export named AppModule variable**
--username | json | username for vhost admin user
--password | json | password for vhost admin user

### Output

Everything is printed into `stdout` so can be saved in a file or used in a script

### Decorators

`rabbitmq-defgen` is able to build all queues by detecting certain decorators (which play nicely with other @leocode libraries).

We do not provide decorators (yet, probably, see [issue](https://github.com/leocode/rabbitmq-defgen/issues/1) for more info).
You can just copy them from the file: [readme-decorators.ts](./readme-decorators.ts).

Relation between decorators is outlined on the diagram:

![](./plan.png)

Decorators described in the file also specify related metadata interfaces.
Upon them you can build logic for communicating with rabbitmq, or just create one provider with all decorators.

Remember, that all classes with decorators should be imported (as provider) somewhere in NestJS dependency tree relative to root module that you require in CLI.

### Caveats

`rabbitmq-defgen` basically requires the code, which executes it. If your code has any immediate side-effects **they will be executed**.

This can lead to some errors, like missing environment variables. It's up to user to create side-effects free code or provide any required variables.
npm package: @leocode/rxstores-react
Description: React binding for Leocode's RxStores lib
Author: LeoCode
Latest version: 0.0.6

# React bindings for RxStores

## Installation

### npm
```
npm i @leocode/rxstores @leocode/rxstores-react
```

### Yarn
```
yarn add @leocode/rxstores @leocode/rxstores-react
```

## Usage

> Info: This README assumes that you already know how to use RxStores.

```typescript
// stores/some.store.ts

import { Store } from '@leocode/rxstores';

export interface SomeModel { name: string; }

export class SomeStore extends Store<SomeModel> {
  ...

  updateModel() { ... }
}
```

### React Hooks (function components only)

```typescript
// components/SomeComponent.tsx

import React from 'react';

import { useStore } from '@leocode/rxstores-react';

import { SomeStore } from '../stores/some.store';

const SomeComponent: React.FC = () => {
  const [data, methods] = useStore(SomeStore);

  return (
    <p>{data.name}</p>
    <button onClick={methods.updateModel}>Update</button>
  );
}
```

### HOC (both class and function components)

> This is not done yet.
npm package: @leocode/sequential-events
Description: **Library for NestJS**
Author: Leocode
Latest version: 2.1.1

# sequential-events

**Library for NestJS**

Sequential events allows to separate contexts with events,
that (in opposite to https://docs.nestjs.com/recipes/cqrs) are evaluated sequentially (with optional transaction object passed around).

It is used to call actions from many domains, that together form one transaction.
If implementing process manager is overkill for you, `sequential-events` may be enough.

## Use cases

1. Process management (creating new tenant in application requiring creating entities in various domains)

## Requirements

Install peer dependencies (or not, if you already have them - if you are using Nest.js you probably already have them)

`yarn add @nestjs/common @nestjs/core reflect-metadata`

`npm install --save @nestjs/common @nestjs/core reflect-metadata`

## Installation

`yarn add @leocode/sequential-events`

`npm install --save @leocode/sequential-events`

## Usage

1. Import `SequentialEventsModule` into core application module
2. Import `SequentialEventBus` into module, that is going to publish event
3. Create event (see below)
4. Create listener (see below)
5. Publish event (see below)

### Creating event

Event needs to implement interface `IEvent` and it should be a class:

```ts
import { IEvent } from '@leocode/sequential-events';

export class TenantCreated implements IEvent {

  constructor (public tenantId: string) {};
}
```

### Creating listener

1. Create class which serves as a handler:

```ts
import { SequentialEventListener } from '@leocode/sequential-events';
import { ISequentialEventListener } from '@leocode/sequential-events';

@SequentialEventListener(TenantCreated)
export class CreateOnboarding implements ISequentialEventListener<TenantCreated, Transaction> {
  public constructor(
    private onboardingFacade: OnboardingFacade,
  ) {}

  public async handle(event: TenantCreated, tx: Transaction | null): Promise<void> {
    const tenantId = event.tenantId;

    await this.onboardingFacade.createAdminOnboarding({
      tenantId,
    }, tx);
  }
}
```

2. Add handler as module's provider

### Publish event

```ts
import { SequentialEventBus } from '@leocode/sequential-events';

@Injectable()
export class TenantService {
  public constructor (
    private sequentialEventBus: SequentialEventBus,
  ) {}

  public async createTenant(...) {
    const transaction = ...;

    const tenantId = ...;
    const user = await this.createUser(..., transaction);

    await this.sequentialEventBus.publishAll([
      new TenantCreated(tenantId)
    ], transaction);

    return user;
  }
}
```