@kiyasov/platform-hono 1.3.4 → 1.3.6

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.
Files changed (49) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/dist/cjs/src/adapters/hono-adapter.js +3 -1
  3. package/dist/cjs/src/adapters/hono-adapter.js.map +1 -1
  4. package/dist/cjs/src/drivers/graphQLUpload/processRequest.js +7 -1
  5. package/dist/cjs/src/drivers/graphQLUpload/processRequest.js.map +1 -1
  6. package/dist/cjs/src/multer/multipart/handlers/any-files.d.ts +3 -3
  7. package/dist/cjs/src/multer/multipart/handlers/any-files.js +1 -1
  8. package/dist/cjs/src/multer/multipart/handlers/any-files.js.map +1 -1
  9. package/dist/cjs/src/multer/multipart/handlers/file-fields.d.ts +4 -4
  10. package/dist/cjs/src/multer/multipart/handlers/file-fields.js +1 -1
  11. package/dist/cjs/src/multer/multipart/handlers/file-fields.js.map +1 -1
  12. package/dist/cjs/src/multer/multipart/handlers/multiple-files.d.ts +3 -3
  13. package/dist/cjs/src/multer/multipart/handlers/multiple-files.js +1 -1
  14. package/dist/cjs/src/multer/multipart/handlers/multiple-files.js.map +1 -1
  15. package/dist/cjs/src/multer/multipart/handlers/single-file.d.ts +3 -3
  16. package/dist/cjs/src/multer/multipart/handlers/single-file.js +1 -1
  17. package/dist/cjs/src/multer/multipart/handlers/single-file.js.map +1 -1
  18. package/dist/cjs/src/multer/multipart/request.d.ts +1 -3
  19. package/dist/cjs/src/multer/multipart/request.js +4 -4
  20. package/dist/cjs/src/multer/multipart/request.js.map +1 -1
  21. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  22. package/dist/esm/src/adapters/hono-adapter.js +3 -1
  23. package/dist/esm/src/adapters/hono-adapter.js.map +1 -1
  24. package/dist/esm/src/drivers/graphQLUpload/processRequest.js +7 -1
  25. package/dist/esm/src/drivers/graphQLUpload/processRequest.js.map +1 -1
  26. package/dist/esm/src/multer/multipart/handlers/any-files.d.ts +3 -3
  27. package/dist/esm/src/multer/multipart/handlers/any-files.js +4 -4
  28. package/dist/esm/src/multer/multipart/handlers/any-files.js.map +1 -1
  29. package/dist/esm/src/multer/multipart/handlers/file-fields.d.ts +4 -4
  30. package/dist/esm/src/multer/multipart/handlers/file-fields.js +5 -5
  31. package/dist/esm/src/multer/multipart/handlers/file-fields.js.map +1 -1
  32. package/dist/esm/src/multer/multipart/handlers/multiple-files.d.ts +3 -3
  33. package/dist/esm/src/multer/multipart/handlers/multiple-files.js +5 -5
  34. package/dist/esm/src/multer/multipart/handlers/multiple-files.js.map +1 -1
  35. package/dist/esm/src/multer/multipart/handlers/single-file.d.ts +3 -3
  36. package/dist/esm/src/multer/multipart/handlers/single-file.js +4 -4
  37. package/dist/esm/src/multer/multipart/handlers/single-file.js.map +1 -1
  38. package/dist/esm/src/multer/multipart/request.d.ts +1 -3
  39. package/dist/esm/src/multer/multipart/request.js +4 -4
  40. package/dist/esm/src/multer/multipart/request.js.map +1 -1
  41. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  42. package/package.json +1 -1
  43. package/src/adapters/hono-adapter.ts +3 -1
  44. package/src/drivers/graphQLUpload/processRequest.ts +8 -1
  45. package/src/multer/multipart/handlers/any-files.ts +7 -7
  46. package/src/multer/multipart/handlers/file-fields.ts +12 -12
  47. package/src/multer/multipart/handlers/multiple-files.ts +10 -10
  48. package/src/multer/multipart/handlers/single-file.ts +9 -9
  49. package/src/multer/multipart/request.ts +4 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiyasov/platform-hono",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "repository": {
@@ -251,7 +251,9 @@ export class HonoAdapter extends AbstractHttpAdapter<
251
251
  contentType?.startsWith("multipart/form-data") ||
252
252
  contentType?.startsWith("application/x-www-form-urlencoded")
253
253
  ) {
254
- (ctx.req as any).body = await ctx.req.parseBody();
254
+ (ctx.req as any).body = await ctx.req.parseBody({
255
+ all: true,
256
+ });
255
257
  } else if (
256
258
  contentType?.startsWith("application/json") ||
257
259
  contentType?.startsWith("text/plain")
@@ -25,12 +25,19 @@ export async function processRequest(
25
25
  Readable.from(buffer).pipe(capacitor);
26
26
 
27
27
  const upload = new Upload();
28
+
28
29
  upload.file = {
29
30
  filename: file.name,
30
31
  mimetype: file.type,
31
32
  fieldName,
32
33
  encoding: "7bit",
33
- createReadStream: (options) => capacitor.createReadStream(options),
34
+ createReadStream: (options) => {
35
+ const stream = capacitor.createReadStream(options);
36
+ stream.on("close", () => {
37
+ capacitor.release();
38
+ });
39
+ return stream;
40
+ },
34
41
  capacitor,
35
42
  };
36
43
  upload.resolve(upload.file);
@@ -1,14 +1,14 @@
1
- import { UploadOptions } from '../options';
2
- import { StorageFile } from '../../storage';
3
- import { THonoRequest, getParts } from '../request';
4
- import { removeStorageFiles } from '../file';
5
- import { filterUpload } from '../filter';
1
+ import { UploadOptions } from "../options";
2
+ import { StorageFile } from "../../storage";
3
+ import { THonoRequest, getParts } from "../request";
4
+ import { removeStorageFiles } from "../file";
5
+ import { filterUpload } from "../filter";
6
6
 
7
7
  export const handleMultipartAnyFiles = async (
8
8
  req: THonoRequest,
9
- options: UploadOptions,
9
+ options: UploadOptions
10
10
  ) => {
11
- const parts = await getParts(req, options);
11
+ const parts = getParts(req, options);
12
12
 
13
13
  const body: Record<string, any> = {};
14
14
 
@@ -1,11 +1,11 @@
1
- import { BadRequestException } from '@nestjs/common';
1
+ import { BadRequestException } from "@nestjs/common";
2
2
 
3
- import { UploadOptions } from '../options';
4
- import { StorageFile } from '../../storage/storage';
5
- import { THonoRequest, getParts } from '../request';
6
- import { removeStorageFiles } from '../file';
7
- import { filterUpload } from '../filter';
8
- import { HonoRequest } from 'hono';
3
+ import { UploadOptions } from "../options";
4
+ import { StorageFile } from "../../storage/storage";
5
+ import { THonoRequest, getParts } from "../request";
6
+ import { removeStorageFiles } from "../file";
7
+ import { filterUpload } from "../filter";
8
+ import { HonoRequest } from "hono";
9
9
 
10
10
  export interface UploadField {
11
11
  /**
@@ -18,7 +18,7 @@ export interface UploadField {
18
18
  maxCount?: number;
19
19
  }
20
20
 
21
- export type UploadFieldMapEntry = Required<Pick<UploadField, 'maxCount'>>;
21
+ export type UploadFieldMapEntry = Required<Pick<UploadField, "maxCount">>;
22
22
 
23
23
  export const uploadFieldsToMap = (uploadFields: UploadField[]) => {
24
24
  const map = new Map<string, UploadFieldMapEntry>();
@@ -33,9 +33,9 @@ export const uploadFieldsToMap = (uploadFields: UploadField[]) => {
33
33
  export const handleMultipartFileFields = async (
34
34
  req: THonoRequest,
35
35
  fieldsMap: Map<string, UploadFieldMapEntry>,
36
- options: UploadOptions,
36
+ options: UploadOptions
37
37
  ) => {
38
- const parts = await getParts(req, options);
38
+ const parts = getParts(req, options);
39
39
  const body: Record<string, any> = {};
40
40
 
41
41
  const files: Record<string, StorageFile[]> = {};
@@ -56,7 +56,7 @@ export const handleMultipartFileFields = async (
56
56
 
57
57
  if (fieldOptions == null) {
58
58
  throw new BadRequestException(
59
- `Field ${fieldName} doesn't accept files`,
59
+ `Field ${fieldName} doesn't accept files`
60
60
  );
61
61
  }
62
62
 
@@ -66,7 +66,7 @@ export const handleMultipartFileFields = async (
66
66
 
67
67
  if (files[fieldName].length + 1 > fieldOptions.maxCount) {
68
68
  throw new BadRequestException(
69
- `Field ${fieldName} accepts max ${fieldOptions.maxCount} files`,
69
+ `Field ${fieldName} accepts max ${fieldOptions.maxCount} files`
70
70
  );
71
71
  }
72
72
 
@@ -1,18 +1,18 @@
1
- import { BadRequestException } from '@nestjs/common';
1
+ import { BadRequestException } from "@nestjs/common";
2
2
 
3
- import { UploadOptions } from '../options';
4
- import { StorageFile } from '../../storage';
5
- import { removeStorageFiles } from '../file';
6
- import { THonoRequest, getParts } from '../request';
7
- import { filterUpload } from '../filter';
3
+ import { UploadOptions } from "../options";
4
+ import { StorageFile } from "../../storage";
5
+ import { removeStorageFiles } from "../file";
6
+ import { THonoRequest, getParts } from "../request";
7
+ import { filterUpload } from "../filter";
8
8
 
9
9
  export const handleMultipartMultipleFiles = async (
10
10
  req: THonoRequest,
11
11
  fieldname: string,
12
12
  maxCount: number,
13
- options: UploadOptions,
13
+ options: UploadOptions
14
14
  ) => {
15
- const parts = await getParts(req, options);
15
+ const parts = getParts(req, options);
16
16
  const body: Record<string, any> = {};
17
17
 
18
18
  const files: StorageFile[] = [];
@@ -30,13 +30,13 @@ export const handleMultipartMultipleFiles = async (
30
30
 
31
31
  if (partFieldName !== fieldname) {
32
32
  throw new BadRequestException(
33
- `Field ${partFieldName} doesn't accept files`,
33
+ `Field ${partFieldName} doesn't accept files`
34
34
  );
35
35
  }
36
36
 
37
37
  if (files.length + 1 > maxCount) {
38
38
  throw new BadRequestException(
39
- `Field ${partFieldName} accepts max ${maxCount} files`,
39
+ `Field ${partFieldName} accepts max ${maxCount} files`
40
40
  );
41
41
  }
42
42
 
@@ -1,16 +1,16 @@
1
- import { BadRequestException } from '@nestjs/common';
1
+ import { BadRequestException } from "@nestjs/common";
2
2
 
3
- import { UploadOptions } from '../options';
4
- import { StorageFile } from '../../storage';
5
- import { THonoRequest, getParts } from '../request';
6
- import { filterUpload } from '../filter';
3
+ import { UploadOptions } from "../options";
4
+ import { StorageFile } from "../../storage";
5
+ import { THonoRequest, getParts } from "../request";
6
+ import { filterUpload } from "../filter";
7
7
 
8
8
  export const handleMultipartSingleFile = async (
9
9
  req: THonoRequest,
10
10
  fieldname: string,
11
- options: UploadOptions,
11
+ options: UploadOptions
12
12
  ) => {
13
- const parts = await getParts(req, options);
13
+ const parts = getParts(req, options);
14
14
  const body: Record<string, any> = {};
15
15
 
16
16
  let file: StorageFile | undefined = undefined;
@@ -29,11 +29,11 @@ export const handleMultipartSingleFile = async (
29
29
 
30
30
  if (partFieldName !== fieldname) {
31
31
  throw new BadRequestException(
32
- `Field ${partFieldName} doesn't accept file`,
32
+ `Field ${partFieldName} doesn't accept file`
33
33
  );
34
34
  } else if (file != null) {
35
35
  throw new BadRequestException(
36
- `Field ${fieldname} accepts only one file`,
36
+ `Field ${fieldname} accepts only one file`
37
37
  );
38
38
  }
39
39
 
@@ -19,10 +19,10 @@ export const getMultipartRequest = (ctx: HttpArgumentsHost) => {
19
19
  return req;
20
20
  };
21
21
 
22
- export const getParts = async (req: THonoRequest, options: UploadOptions) => {
23
- const files = await req.parseBody({ all: true });
22
+ export const getParts = (req: THonoRequest, options: UploadOptions) => {
23
+ const parts = req.body;
24
24
 
25
- for (const [key, file] of Object.entries(files)) {
25
+ for (const [key, file] of Object.entries(parts)) {
26
26
  if (
27
27
  file instanceof File &&
28
28
  options?.limits?.fileSize &&
@@ -34,7 +34,7 @@ export const getParts = async (req: THonoRequest, options: UploadOptions) => {
34
34
  }
35
35
  }
36
36
 
37
- return files;
37
+ return parts;
38
38
  };
39
39
 
40
40
  export type MultipartsIterator = AsyncIterableIterator<MultipartFile>;