open-index/open-npm huggingface dataset:
npm package: @honestjs/middleware
Description: Collection of middleware without dependencies for HonestJS framework
Author: Orkhan Karimov
Latest version: 1.1.3

# HonestJS - Middleware

Hono middleware adapter for HonestJS framework, providing seamless integration with all Hono's built-in middleware.

**📖 [Hono Middleware Guide](https://hono.dev/docs/guides/middleware)** | **🔧
[Built-in Middleware](https://hono.dev/docs/middleware/builtin/basic-auth)**

> ⚠️ **Documentation is not yet complete** ⚠️
>
> If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

## Installation

```bash
bun add @honestjs/middleware
```

## Basic Usage

### Method 1: HonestJS Application Configuration

```typescript
import { Application } from 'honestjs'
import { CorsMiddleware, LoggerMiddleware, SecureHeadersMiddleware } from '@honestjs/middleware'

const { hono } = await Application.create(AppModule, {
	components: {
		middleware: [
			new LoggerMiddleware(),
			new CorsMiddleware({ origin: 'https://example.com' }),
			new SecureHeadersMiddleware()
		]
	}
})
```

### Method 2: Direct Hono Registration

```typescript
import { EmojiFavicon, LoggerMiddleware } from '@honestjs/middleware'

hono.use('*', new LoggerMiddleware().use)
hono.use('*', new EmojiFavicon('🔥').use)
```

### HonoMiddleware

Wrap any Hono middleware for use with HonestJS.

```typescript
import { HonoMiddleware } from '@honestjs/middleware'
import { poweredBy } from 'hono/powered-by'
import { prettyJSON } from 'hono/pretty-json'

const { hono } = await Application.create(AppModule, {
	components: {
		middleware: [
			new HonoMiddleware(poweredBy())
			new HonoMiddleware(async (c, next) => {
				c.header('X-Custom-Header', 'Custom Value')
				await next()
			})
		]
	}
})
```

## License

MIT © [Orkhan Karimov](https://github.com/kerimovok)
npm package: @honestjs/prisma-exception-filter
Description: Prisma exception filter for HonestJS framework
Author: Orkhan Karimov
Latest version: 1.2.3

# @honestjs/prisma-exception-filter

An exception filter for `honestjs` that handles errors thrown by `Prisma Client`. It catches various `Prisma` exceptions
and formats them into standardized, user-friendly JSON error responses.

## Features

- Integrates with `honestjs` and `hono` to handle database-related errors.
- Catches specific `Prisma` errors, such as validation errors, connection errors, and known request errors.
- Maps different Prisma error codes (like `P2002` for unique constraint violations) to appropriate HTTP status codes and
  messages.
- Provides clear, structured error responses for easier debugging and client-side handling.

## Installation

```bash
npm install @honestjs/prisma-exception-filter @prisma/client
# or
yarn add @honestjs/prisma-exception-filter @prisma/client
# or
pnpm add @honestjs/prisma-exception-filter @prisma/client
```

## Usage

Register the `PrismaExceptionFilter` in your `honestjs` application. It's best to place it before your application's
main logic but after other specific filters like validation.

```typescript
import { Application } from 'honestjs'
import { PrismaClient } from '@prisma/client'
import { PrismaExceptionFilter } from '@honestjs/prisma-exception-filter'

// Method 1: Register filter globally in application configuration
const { hono } = await Application.create(AppModule, {
	components: {
		filters: [new PrismaExceptionFilter()]
	}
})

// Method 2: Use filter on specific controller
@Controller('/users')
@UseFilters(PrismaExceptionFilter)
class UsersController {
	constructor(private readonly prisma: PrismaClient) {}

	@Post()
	async createUser(@Body() body: CreateUserDto): Promise<User> {
		// The PrismaExceptionFilter will catch any Prisma errors automatically
		return await this.prisma.user.create({
			data: {
				email: body.email, // This could fail if the email is already taken
				name: body.name
			}
		})
	}
}
```

If a unique constraint violation occurs (Prisma error code `P2002`), the filter will generate a response like this:

```json
{
	"error": {
		"message": "A record with this value already exists",
		"code": "UNIQUE_CONSTRAINT_VIOLATION"
	}
}
```
npm package: @honestjs/zod-exception-filter
Description: Zod exception filter for HonestJS framework
Author: Orkhan Karimov
Latest version: 1.2.3

# @honestjs/zod-exception-filter

A validation filter for `honestjs` that integrates with `zod` to handle validation errors. It automatically captures
`ZodError` exceptions and transforms them into a structured, client-friendly JSON error response.

## Features

- Seamlessly integrates with `honestjs` and `hono`.
- Catches `ZodError` and formats it into a standardized error message.
- Provides detailed validation issues in the response body.
- Configurable HTTP status code for error responses (defaults to 400).

## Installation

```bash
npm install @honestjs/zod-exception-filter zod
# or
yarn add @honestjs/zod-exception-filter zod
# or
pnpm add @honestjs/zod-exception-filter zod
```

## Usage

To use the filter, simply add it to your `honestjs` application's `use` method. It should typically be one of the first
filters you register.

```typescript
import { Application } from 'honestjs'
import { ZodValidationFilter } from '@honestjs/zod-exception-filter'
import { z } from 'zod'

// Method 1: Register filter globally in application configuration
const { hono } = await Application.create(AppModule, {
	components: {
		filters: [new ZodValidationFilter()]
	}
})

// Method 2: Use filter on specific controller
@Controller('/users')
@UseFilters(ZodValidationFilter)
class UsersController {
	constructor(private readonly usersService: UsersService) {}

	@Post()
	async createUser(@Body() body: CreateUserDto): Promise<User> {
		// Validate with Zod - this will throw a ZodError if validation fails
		const userSchema = z.object({
			name: z.string().min(3),
			email: z.string().email()
		})

		const validatedData = userSchema.parse(body)
		return await this.usersService.create(validatedData)
	}
}
```

When the validation fails, the filter will catch the `ZodError` and produce a response similar to this:

```json
{
	"error": {
		"message": "Validation failed",
		"code": "VALIDATION_ERROR",
		"errors": [
			{
				"path": ["name"],
				"message": "String must contain at least 3 character(s)"
			}
		]
	}
}
```