open-index/open-npm huggingface dataset:
npm package: @nest-otel/k8s
Description: OpenTelemetry integration for NestJS with Kubernetes support
Author: little-thing
Latest version: 1.0.2-beta.3

# NestJS OpenTelemetry 自动注入模块

这是一个用于 NestJS 框架的 OpenTelemetry 自动注入模块，它可以自动为你的应用添加分布式追踪能力，无需手动修改大量代码。

[English Documentation](./README.md)

## 特性

- 🚀 自动注入追踪功能到 NestJS 应用的各个层面
- 🎯 支持多种注入器，覆盖常见场景：
  - Controller 注入器
  - Provider 注入器
  - Middleware 注入器
  - Guard 注入器
  - Interceptor 注入器
  - Pipe 注入器
  - Schedule 注入器
  - TypeORM 注入器
  - Logger 注入器
- 📊 自动收集关键性能指标
- 🔍 详细的追踪信息，包括：
  - 模块名称
  - 控制器名称
  - 方法名称
  - 数据库操作
  - 中间件执行
  - 守卫验证
  - 拦截器处理
  - 管道转换
  - 定时任务执行

## 安装

```bash
npm install @nest-otel/k8s
# 或
pnpm add @nest-otel/k8s
# 或
yarn add @nest-otel/k8s
```

## 快速开始

1. 在你的 NestJS 应用的 `app.module.ts` 中导入 OpenTelemetryModule：

```typescript
import { OpenTelemetryModule } from '@nest-otel/k8s';

@Module({
  imports: [
    OpenTelemetryModule.forRoot({
      // 可选配置
    }),
  ],
})
export class AppModule {}
```

2. 使用异步配置（可选）：

```typescript
import { OpenTelemetryModule } from '@nest-otel/k8s';

@Module({
  imports: [
    OpenTelemetryModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => ({
        // 异步配置选项
      }),
    }),
  ],
})
export class AppModule {}
```

## 装饰器使用

### @Trace 装饰器

你可以使用 `@Trace` 装饰器来手动标记需要追踪的方法：

```typescript
import { Trace } from '@nest-otel/k8s';

@Injectable()
export class UserService {
  @Trace('get-user-by-id')
  async getUserById(id: string) {
    // 方法实现
  }
}
```

### TracePlain 装饰器

用于普通类方法的追踪：

```typescript
import { TracePlain } from '@nest-otel/k8s';

@TracePlain()
class MyClass {
  myMethod() {
    // 方法实现
  }
}
```

## 配置选项

```typescript
interface OpenTelemetryModuleOptions {
  autoInjectors?: Type<any>[]; // 自定义注入器
  injectorsConfig?: Record<string, any>; // 注入器配置
}
```

### TypeORM 配置示例

```typescript
OpenTelemetryModule.forRoot({
  injectorsConfig: {
    TypeormInjector: {
      collectParameters: true, // 收集SQL参数
    },
  },
});
```

## 自定义注入器

你可以创建自己的注入器来扩展功能：

```typescript
@Injectable()
export class CustomInjector extends BaseInjector {
  inject(): void {
    // 实现注入逻辑
  }
}

// 在模块配置中使用
OpenTelemetryModule.forRoot({
  autoInjectors: [CustomInjector],
});
```

## 注意事项

- 确保在应用启动前配置 OpenTelemetry
- TypeORM 注入器需要 TypeORM 包的支持
- 建议在生产环境中谨慎使用参数收集功能，可能会影响性能

## 许可证

MIT

## 贡献指南

欢迎提交 Issue 和 Pull Request！
npm package: @nest-pkgz/nest-swagger-split
Description: Split Swagger documentation to multiple files
Author: Eyal Levin
Latest version: 1.0.4

# Nest Swagger Split
### Split swagger documentation into multiple files.


Installation
------------
### NPM
```shell
npm install @nest-pkgz/nest-swagger-split --save
```

Quick Start
------------
```typescript
    // main.ts
    const document = SwaggerModule.createDocument(app, config);
    const {withoutTagInput,withTagSplit} = splitSwaggerDocument(document);
    
    // app.controller.ts
    @Get()
    @ApiInternal()
    getHello(): string {
        return this.appService.getHello();
    }
```

Contribution
------------
Want to help improve this package? We take [pull requests](https://github.com/nest-pkgz/nest-swagger-split/pulls).

Status
------------
The project is under active development.

License
------------
nest-swagger-split is [MIT licensed](LICENSE).
npm package: @nest-public/nest-redis
Description: nest.js框架Redis插件
Author: chenjunhong
Latest version: 1.0.2


[![npm version](https://badge.fury.io/js/%40nest-public%2Fnest-redis.svg)](https://badge.fury.io/js/%40nest-public%2Fnest-redis)

# nest-redis
[Nest](https://github.com/nestjs/nest) 框架Redis插件 封装了一些redis常用操作

## 安装

```bash
$ npm install @nest-public/nest-redis --save
```

## 用法
config.js 配置 具体请参考[ioredis](https://github.com/luin/ioredis) 
```javascript
// 单客户端
export const config = {
	port: 6379,
	host: 'xxx.xxxx.xxx',
	password: 'xxxxxxxxxxxxxxxxxx',
	db: 0
};

// 集群配置
export const config = {
	cluster: true,
	nodes: [
		{
			port: 6379,
			host: 'xxx.xxxx.xxx',
			password: 'xxxxxxxxxxxxxxxxxx',
			db: 0
		},
		{
			port: 6379,
			host: 'xxx.xxxx.xxx',
			password: 'xxxxxxxxxxxxxxxxxx',
			db: 0
		}
	],
	option: {
		// ioredis集群设置
	}
}
```
module.ts
```javascript
import { AppController } from './test.controller';
import { RedisModule } from '@nest-public/nest-redis';
import { config } from '../config/config.js';

@Module({
	imports: [ 
		RedisModule.forRoot(config)
	],
	controllers: [AppController],
})

export class AppModule{}
```
controller.ts
```javascript
import { Controller, Req, Post, Get, UseInterceptors, UploadedFiles } from '@nestjs/common';
import { FilesInterceptor } from '@nestjs/platform-express';
import { OSS } from '@nest-public/nest-oss';

/**
 * AppController
 * @export
 * @class AppController
 */
@Controller()
export class AppController {
	constructor(private readonly oss: OSS) {}

	/**
	 * 设置key
	 */
	@Get('setKey')
	public async setKey() {
		const result = await this.redis.set(`testkey`, 'this is a test meassage', 600); // set(key:string, data:any, ttl？:number); ttl默认3600秒 成功返回 'OK'

		return result;
	}

	/**
	 * 获取key
	 */
	@Get('getKey')
	public async getKey() {
		const result = await this.redis.get('testkey'); // get(key: string);

		return result;
	}

	/**
	 * 效验key是否存在
	 */
	@Get('exists')
	public async exists() {
		const result = await this.redis.exists('testkey'); // exists(key: string); 成功返回 1

		return result;
	}

	/**
	 * 设置到期时间
	 */
	@Get('expire')
	public async expire() {
		const result = await this.redis.expire('testkey', 5600); // expire(key: string, time: number); 成功返回 1

		return result;
	}

	/**
	 * 设置key永不过期
	 */
	@Get('persist')
	public async persist() {
		const result = await this.redis.persist('testkey'); // persist(key: string); 成功返回 1

		return result;
	}

	/**
	 * 删除key
	 */
	@Get('del')
	public async del() {
		const result = await this.redis.del('testkey'); // del(key: string); 成功返回 1

		return result;
	}
}
```

## 测试
进行单元测试前请先配置好 test.module.ts 里面的redis配置
```bash
# jest tests
$ npm run test
```
npm package: @nest-public/totp
Description: TOTP算法node.js实现，支持动态密码获取、效验，可以搭配Google Authenticator使用
Author: chenjunhong
Latest version: 1.1.3

[![npm version](https://badge.fury.io/js/%40nest-public%2Ftotp.svg)](https://badge.fury.io/js/%40nest-public%2Ftotp)

# TOTP

TOTP算法JavaScript实现，可以用于Node.js、浏览器、React Native环境，支持动态密码生成、效验, 可以搭配Google Authenticator使用


## 更新日志

* [2019.12.11] HMAC加密库由Node.js Cypto模块替换为JavaScript实现的HMACSHA1加密库，现在支持在任何JavaScript环境使用了。

## 安装

```bash
$ npm install @nest-public/totp --save
```

## 用法

```javascript
import totp from '@nest-public/totp';

// 设置密钥
const testKey = 'LFLFMU2SGVCUIUCZKBMEKRKLIQ';

// 获取6位动态密码
console.log(totp.totp(testKey));
// 返回 6位数字符串 如123456

// 效验动态密码
console.log(totp.totpVerify('123456', testKey));
// 返回 {
// 	status: true; // 验证码是否准确
// 	delta: 0; // 偏移量(1单位==30秒)
// }

```

## 测试

```bash
# jest 测试
$ npm run test
```
npm package: @nest-toolbox/bootstrap-log
Description: bootstrap log for nestjs applications
Author: bogdanlupu
Latest version: 1.8.1

# `bootstrap-log`

> get a nice bootstrap log with your configs

![alt text](https://gcdnb.pbrd.co/images/bBxdFdWEoesz.png?o=1)

## Usage

```
import { BootstrapLog } from '@nest-toolbox/bootstrap-log';

  await app.listen(port, () => {
    const { hostname, environment, database_url } = config();
    BootstrapLog({ config: { environment, hostname, package_json_body: packageBody, database_url, swagger: true } });
  });
```
npm package: @nest-toolbox/http-logger-middleware
Description: nest js http-logger-middleware
Author: bogdanlupu
Latest version: 1.8.1

# `http-logger-middleware`

## Installation

```
npm i @nest-toolbox/http-logger-middleware
```

## Usage

```
export class AppModule {
    configure(consumer: MiddlewareConsumer) {
        consumer.apply(HttpLoggerMiddleware).forRoutes({
            path: '*',
            method: RequestMethod.ALL,
        });
    }
}
```
npm package: @nest-toolbox/open-api-spec-to-ts
Description: nestjs toolbox
Author: getlarge
Latest version: 1.8.1

### Open API spec to TS

Generate Typescript interfaces and enums in a specified folder, from you Open API specifications.
Depends on [json-schema-to-typescript](https://github.com/bcherny/json-schema-to-typescript).

## Installation

```bash
npm i @nest-toolbox/open-api-spec-to-ts
```

## Usage

### Inside a module

```ts
import { generate } from '@nest-toolbox/open-api-spec-to-ts';

const openApiFilePath = './openapi.json';
const interfacesDirPath = './interfaces';

generate(openApiFilePath, interfacesDirPath);
```

### As a CLI tool

```js
import { generate, LogLevel } from '@nest-toolbox/open-api-spec-to-ts';
import { argv } from 'yargs';

const openApiFilePath = argv.openApiPath || './openapi.json';
const interfacesDirPath = argv.interfacesPath || './interfaces';
const verbosity = argv.verbosity || LogLevel.INFO;

generate(openApiFilePath, interfacesDirPath, { verbosity });
```

```bash
node ./<your-file>.js --openApiPath='./openapi.json' --interfacesPath='./interfaces'"
```
npm package: @nest-toolbox/progress-bar
Description: a simple progress bar for log running tasks
Author: bogdanlupu
Latest version: 1.8.1

# `progress-bar`

> simple progress bar

![alt-text](https://gcdnb.pbrd.co/images/JJnbF3rTUEss.png?o=1)

## Usage

```
import { ProgressBar } from '../progress-bar';

    const progressBar = new ProgressBar({ identifier: 'test', total: 10 });
    for (let i = 0; i < 10; i++) {
      progressBar.tick();
    }

```
npm package: @nest-toolbox/typeorm-upsert
Description: upsert function for typeorm
Author: bogdanlupu
Latest version: 1.8.1

# `typeorm-upsert`

## Installation

```
npm i @nest-toolbox/typeorm-upsert
```

## Usage

```
const dataTypeRepository; // typeorm repository
const bigArrayWithData = []; // this array contains existing data and new data
const conflictKey = 'unq index/key'; // you can use this function in the case you want to track collision on other key then id;

const options = { // all the options are optional
    keyNamingTransform: (k)=>k, // you can pass a callback function to change the keys in case that your having a naming convention like snake_case
    doNotUpsert: [], // array of keys that you want to ignore durning the upsert maybe a status field or something
    chunk: 1000, // by default the function chunks the array in 1000 inserts you can increase or decrease this option
    returnStatus: false, // if true, returns array of UpsertResult with status (inserted/updated) for each entity
};

const updated = await TypeOrmUpsert(dataTypeRepository, bigArrayWithData, conflictKey, {
    doNotUpsert: ['name'],
});

// With returnStatus option to get insert/update status
const results = await TypeOrmUpsert(dataTypeRepository, bigArrayWithData, conflictKey, {
    returnStatus: true,
});
// results will be an array of { entity: T, status: 'inserted' | 'updated' }
results.forEach((result) => {
    console.log(`Entity ${result.entity.id} was ${result.status}`);
});
```
npm package: @nest-toolbox/winston-logger
Description: nestjs toolbox
Author: bogdanlupu
Latest version: 1.8.1

### Winston Logger Service

NestJS LoggerService that uses Winston.

### Installation

```
npm i @nest-toolbox/winston-logger
```

### Example

You can pass any custom transports supported by Winston

```js
import { NestFactory } from '@nestjs/core';
import { WinstonLoggerService } from '@nest-toolbox/winston-logger';
import { AppModule } from './app.module';
import * as winston from 'winston';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(
    ApplicationModule,
    {
      logger: new WinstonLoggerService({
        projectName: 'project',
      }),
    },
  );

  const app = await NestFactory.create<NestExpressApplication>(
    ApplicationModule,
    {
      logger: new WinstonLoggerService({
        projectName: 'project',
        transports: [
          new winston.transports.File({
            filename: 'combined.log',
            level: 'info',
          }),
        ],
      }),
    },
  );

  await app.listen(3000);
}
bootstrap();
```

### WinstonLoggerService constructor options

```js
options: {
  projectName: string,
  transports?: any[],
  timeFormatStr?: string,
  customFormatter?: any
}
```