@kiyasov/platform-hono 1.5.3 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +9 -0
- package/Readme.md +58 -25
- package/benchmarks/benchmark.mjs +12 -12
- package/dist/cjs/src/multer/storage/memory-storage.d.ts +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/multer/storage/memory-storage.d.ts +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +40 -29
package/Readme.md
CHANGED
|
@@ -1,40 +1,55 @@
|
|
|
1
|
-
# Hono NestJS Adapter
|
|
1
|
+
# 🚀 Hono NestJS Adapter
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://www.npmjs.com/package/@kiyasov/platform-hono)
|
|
3
|
+
<div align="center">
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@kiyasov/platform-hono)
|
|
6
|
+
[](https://www.npmjs.com/package/@kiyasov/platform-hono)
|
|
7
|
+
[](https://github.com/kiyasov/platform-hono/blob/main/LICENSE)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
**Use [Hono](https://hono.dev/) with [NestJS](https://nestjs.com/)**
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
</div>
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
---
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
## 📦 Installation
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
```shell
|
|
17
|
+
```bash
|
|
19
18
|
npm install @kiyasov/platform-hono
|
|
20
|
-
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```bash
|
|
21
22
|
yarn add @kiyasov/platform-hono
|
|
22
23
|
```
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
```bash
|
|
26
|
+
pnpm add @kiyasov/platform-hono
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun add @kiyasov/platform-hono
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## ⚡ Quick Start
|
|
25
34
|
|
|
26
35
|
```typescript
|
|
27
|
-
import { NestFactory } from
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
AppModule,
|
|
33
|
-
|
|
34
|
-
);
|
|
36
|
+
import { NestFactory } from '@nestjs/core';
|
|
37
|
+
import { HonoAdapter } from '@kiyasov/platform-hono';
|
|
38
|
+
import { AppModule } from './app.module';
|
|
39
|
+
|
|
40
|
+
async function bootstrap() {
|
|
41
|
+
const app = await NestFactory.create(AppModule, new HonoAdapter());
|
|
42
|
+
|
|
43
|
+
await app.listen(3000);
|
|
44
|
+
console.log(`Application is running on: ${await app.getUrl()}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
bootstrap();
|
|
35
48
|
```
|
|
36
49
|
|
|
37
|
-
|
|
50
|
+
## 🎯 Usage Examples
|
|
51
|
+
|
|
52
|
+
### Exception Filter with HonoAdapter
|
|
38
53
|
|
|
39
54
|
```typescript
|
|
40
55
|
import {
|
|
@@ -43,8 +58,8 @@ import {
|
|
|
43
58
|
ArgumentsHost,
|
|
44
59
|
HttpException,
|
|
45
60
|
HttpStatus,
|
|
46
|
-
} from
|
|
47
|
-
import { HttpAdapterHost } from
|
|
61
|
+
} from '@nestjs/common';
|
|
62
|
+
import { HttpAdapterHost } from '@nestjs/core';
|
|
48
63
|
|
|
49
64
|
@Catch()
|
|
50
65
|
export class AllExceptionsFilter implements ExceptionFilter {
|
|
@@ -52,7 +67,6 @@ export class AllExceptionsFilter implements ExceptionFilter {
|
|
|
52
67
|
|
|
53
68
|
catch(exception: unknown, host: ArgumentsHost): void {
|
|
54
69
|
const { httpAdapter } = this.httpAdapterHost;
|
|
55
|
-
|
|
56
70
|
const ctx = host.switchToHttp();
|
|
57
71
|
|
|
58
72
|
const httpStatus =
|
|
@@ -70,3 +84,22 @@ export class AllExceptionsFilter implements ExceptionFilter {
|
|
|
70
84
|
}
|
|
71
85
|
}
|
|
72
86
|
```
|
|
87
|
+
|
|
88
|
+
## 📚 Documentation
|
|
89
|
+
|
|
90
|
+
For more examples and detailed documentation, check out the [example](./example) directory.
|
|
91
|
+
|
|
92
|
+
## 🤝 Contributing
|
|
93
|
+
|
|
94
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
95
|
+
|
|
96
|
+
## 📄 License
|
|
97
|
+
|
|
98
|
+
MIT © [Islam Kiiasov](https://github.com/kiyasov)
|
|
99
|
+
|
|
100
|
+
## 🔗 Links
|
|
101
|
+
|
|
102
|
+
- [NPM Package](https://www.npmjs.com/package/@kiyasov/platform-hono)
|
|
103
|
+
- [GitHub Repository](https://github.com/kiyasov/platform-hono)
|
|
104
|
+
- [Hono Framework](https://hono.dev/)
|
|
105
|
+
- [NestJS Framework](https://nestjs.com/)
|
package/benchmarks/benchmark.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import autocannon from
|
|
2
|
-
import { PassThrough } from
|
|
1
|
+
import autocannon from 'autocannon';
|
|
2
|
+
import { PassThrough } from 'stream';
|
|
3
3
|
|
|
4
4
|
// Example base64-encoded image (black square 100x100 pixels)
|
|
5
5
|
const base64Content =
|
|
6
|
-
|
|
6
|
+
'iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAABmJLR0QA/wD/AP+gvaeTAAAAJ0lEQVR4nO3BAQEAAACCIP+vbkhAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwH8GAAF3Xq9HAAAAAElFTkSuQmCC';
|
|
7
7
|
|
|
8
8
|
// Create the request body with the base64 string
|
|
9
9
|
const formData = `--boundary
|
|
@@ -15,8 +15,8 @@ ${base64Content}
|
|
|
15
15
|
|
|
16
16
|
// Set up headers
|
|
17
17
|
const headers = {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
'Content-Type': 'multipart/form-data; boundary=boundary',
|
|
19
|
+
'Content-Length': Buffer.byteLength(formData),
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const pass = new PassThrough();
|
|
@@ -24,12 +24,12 @@ pass.end(formData);
|
|
|
24
24
|
|
|
25
25
|
const chunks = [];
|
|
26
26
|
|
|
27
|
-
pass.on(
|
|
28
|
-
pass.on(
|
|
27
|
+
pass.on('data', (chunk) => chunks.push(chunk));
|
|
28
|
+
pass.on('end', () => {
|
|
29
29
|
const formBuffer = Buffer.concat(chunks);
|
|
30
30
|
const instance = autocannon({
|
|
31
|
-
url:
|
|
32
|
-
method:
|
|
31
|
+
url: 'http://localhost:3000/uploadFile',
|
|
32
|
+
method: 'POST',
|
|
33
33
|
headers: headers,
|
|
34
34
|
body: formBuffer,
|
|
35
35
|
connections: 200,
|
|
@@ -39,13 +39,13 @@ pass.on("end", () => {
|
|
|
39
39
|
|
|
40
40
|
autocannon.track(instance, { renderProgressBar: true });
|
|
41
41
|
|
|
42
|
-
process.once(
|
|
42
|
+
process.once('SIGINT', () => {
|
|
43
43
|
instance.stop();
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
pass.on(
|
|
48
|
-
console.error(
|
|
47
|
+
pass.on('error', (err) => {
|
|
48
|
+
console.error('Error reading data from the stream', err);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
pass.resume();
|
|
@@ -12,7 +12,7 @@ export declare class MemoryStorage implements Storage<MemoryStorageFile> {
|
|
|
12
12
|
mimetype: string;
|
|
13
13
|
fieldname: string;
|
|
14
14
|
originalFilename: string;
|
|
15
|
-
stream: () => ReadableStream<Uint8Array<
|
|
15
|
+
stream: () => ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
16
16
|
lastModified: number;
|
|
17
17
|
}>;
|
|
18
18
|
removeFile(file: MemoryStorageFile): Promise<void>;
|