@tsed/platform-multer 8.11.1 → 8.12.0-rc.1

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 (46) hide show
  1. package/lib/esm/adapters/express/MulterModule.js +0 -1
  2. package/lib/esm/adapters/fastify/MulterModule.js +0 -1
  3. package/lib/esm/adapters/koa/MulterModule.js +0 -1
  4. package/lib/esm/common/constants/constants.js +0 -1
  5. package/lib/esm/common/decorators/multerFileSize.js +0 -1
  6. package/lib/esm/common/decorators/multerOptions.js +0 -1
  7. package/lib/esm/common/decorators/multipartFile.js +0 -1
  8. package/lib/esm/common/errors/MulterException.js +0 -1
  9. package/lib/esm/common/index.js +0 -1
  10. package/lib/esm/common/interfaces/PlatformMulterSettings.js +0 -1
  11. package/lib/esm/common/middlewares/PlatformMulterMiddleware.js +0 -1
  12. package/lib/esm/index.js +0 -1
  13. package/package.json +10 -7
  14. package/.barrelsby.json +0 -5
  15. package/lib/esm/adapters/express/MulterModule.js.map +0 -1
  16. package/lib/esm/adapters/fastify/MulterModule.js.map +0 -1
  17. package/lib/esm/adapters/koa/MulterModule.js.map +0 -1
  18. package/lib/esm/common/constants/constants.js.map +0 -1
  19. package/lib/esm/common/decorators/multerFileSize.js.map +0 -1
  20. package/lib/esm/common/decorators/multerOptions.js.map +0 -1
  21. package/lib/esm/common/decorators/multipartFile.js.map +0 -1
  22. package/lib/esm/common/errors/MulterException.js.map +0 -1
  23. package/lib/esm/common/index.js.map +0 -1
  24. package/lib/esm/common/interfaces/PlatformMulterSettings.js.map +0 -1
  25. package/lib/esm/common/middlewares/PlatformMulterMiddleware.js.map +0 -1
  26. package/lib/esm/index.js.map +0 -1
  27. package/src/adapters/express/MulterModule.integration.spec.ts +0 -19
  28. package/src/adapters/express/MulterModule.ts +0 -40
  29. package/src/adapters/fastify/MulterModule.integration.spec.ts +0 -19
  30. package/src/adapters/fastify/MulterModule.ts +0 -77
  31. package/src/adapters/koa/MulterModule.integration.spec.ts +0 -19
  32. package/src/adapters/koa/MulterModule.ts +0 -73
  33. package/src/common/constants/constants.ts +0 -10
  34. package/src/common/decorators/multerFileSize.spec.ts +0 -22
  35. package/src/common/decorators/multerFileSize.ts +0 -32
  36. package/src/common/decorators/multerOptions.spec.ts +0 -21
  37. package/src/common/decorators/multerOptions.ts +0 -53
  38. package/src/common/decorators/multipartFile.spec.ts +0 -260
  39. package/src/common/decorators/multipartFile.ts +0 -91
  40. package/src/common/errors/MulterException.ts +0 -20
  41. package/src/common/index.ts +0 -10
  42. package/src/common/interfaces/PlatformMulterSettings.ts +0 -45
  43. package/src/common/middlewares/PlatformMulterMiddleware.spec.ts +0 -98
  44. package/src/common/middlewares/PlatformMulterMiddleware.ts +0 -46
  45. package/src/index.ts +0 -1
  46. package/vitest.config.mts +0 -21
@@ -27,4 +27,3 @@ async function factory() {
27
27
  };
28
28
  }
29
29
  injectable(MULTER_MODULE).asyncFactory(factory).token();
30
- //# sourceMappingURL=MulterModule.js.map
@@ -51,4 +51,3 @@ injectable(MULTER_MODULE)
51
51
  plugins: [multerPlugin]
52
52
  })
53
53
  .token();
54
- //# sourceMappingURL=MulterModule.js.map
@@ -54,4 +54,3 @@ async function factory() {
54
54
  };
55
55
  }
56
56
  injectable(MULTER_MODULE).asyncFactory(factory).token();
57
- //# sourceMappingURL=MulterModule.js.map
@@ -1,3 +1,2 @@
1
1
  export const MULTER_MODULE = Symbol.for("MULTER_MODULE");
2
2
  export const PLATFORM_MULTER_OPTIONS = Symbol.for("PLATFORM_MULTER_OPTIONS");
3
- //# sourceMappingURL=constants.js.map
@@ -29,4 +29,3 @@ import { MulterOptions } from "./multerOptions.js";
29
29
  export function MulterFileSize(fileSize) {
30
30
  return MulterOptions({ limits: { fileSize } });
31
31
  }
32
- //# sourceMappingURL=multerFileSize.js.map
@@ -47,4 +47,3 @@ export function MulterOptions(options) {
47
47
  return descriptor;
48
48
  };
49
49
  }
50
- //# sourceMappingURL=multerOptions.js.map
@@ -74,4 +74,3 @@ export function MultipartFile(name, maxCount) {
74
74
  decorators(...args);
75
75
  };
76
76
  }
77
- //# sourceMappingURL=multipartFile.js.map
@@ -14,4 +14,3 @@ export class MulterException extends BadRequest {
14
14
  this.name = er.code;
15
15
  }
16
16
  }
17
- //# sourceMappingURL=MulterException.js.map
@@ -8,4 +8,3 @@ export * from "./decorators/multipartFile.js";
8
8
  export * from "./errors/MulterException.js";
9
9
  export * from "./interfaces/PlatformMulterSettings.js";
10
10
  export * from "./middlewares/PlatformMulterMiddleware.js";
11
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=PlatformMulterSettings.js.map
@@ -37,4 +37,3 @@ __decorate([
37
37
  __metadata("design:returntype", Promise)
38
38
  ], PlatformMulterMiddleware.prototype, "use", null);
39
39
  injectable(PlatformMulterMiddleware).type(ProviderType.MIDDLEWARE).priority(-10);
40
- //# sourceMappingURL=PlatformMulterMiddleware.js.map
package/lib/esm/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export * from "./common/index.js";
2
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/platform-multer",
3
3
  "description": "Multer adapter package for Ts.ED framework",
4
4
  "type": "module",
5
- "version": "8.11.1",
5
+ "version": "8.12.0-rc.1",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -59,12 +59,12 @@
59
59
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/platform/platform-multer",
60
60
  "repository": "https://github.com/tsedio/tsed",
61
61
  "devDependencies": {
62
- "@tsed/barrels": "8.11.1",
63
- "@tsed/core": "8.11.1",
64
- "@tsed/di": "8.11.1",
65
- "@tsed/platform-middlewares": "8.11.1",
66
- "@tsed/platform-params": "8.11.1",
67
- "@tsed/typescript": "8.11.1",
62
+ "@tsed/barrels": "8.12.0-rc.1",
63
+ "@tsed/core": "8.12.0-rc.1",
64
+ "@tsed/di": "8.12.0-rc.1",
65
+ "@tsed/platform-middlewares": "8.12.0-rc.1",
66
+ "@tsed/platform-params": "8.12.0-rc.1",
67
+ "@tsed/typescript": "8.12.0-rc.1",
68
68
  "eslint": "9.12.0",
69
69
  "typescript": "5.4.5",
70
70
  "vitest": "3.1.4"
@@ -105,5 +105,8 @@
105
105
  "@tsed/schema": {
106
106
  "optional": false
107
107
  }
108
+ },
109
+ "publishConfig": {
110
+ "tag": "rc"
108
111
  }
109
112
  }
package/.barrelsby.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "directory": ["./src/common"],
3
- "exclude": ["**/__mock__", "**/__fixtures__", "**/__mocks__", "**/*.spec.ts", "**/getConfiguration.ts", "FakeResponse.ts"],
4
- "delete": true
5
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"MulterModule.js","sourceRoot":"","sources":["../../../../src/adapters/express/MulterModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAEpD,KAAK,UAAU,OAAO;IACpB,MAAM,EAAC,OAAO,EAAE,MAAM,EAAC,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEjD,OAAO;QACL,MAAM;QACN,GAAG,CAAC,OAAgB;YAClB,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;YAEjC,MAAM,WAAW,GAAG,CAAC,MAAW,EAAE,IAAY,EAAE,EAAE;gBAChD,uBAAuB;gBACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;oBAAE,OAAO;gBAE1B,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;gBAExB,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,IAAW;oBAC1C,MAAM,UAAU,GAAQ,OAAO,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AAC,aAAa,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/common/constants/constants.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"multerFileSize.js","sourceRoot":"","sources":["../../../../src/common/decorators/multerFileSize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,OAAO,aAAa,CAAC,EAAC,MAAM,EAAE,EAAC,QAAQ,EAAC,EAAC,CAAC,CAAC;AAC7C,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"multerOptions.js","sourceRoot":"","sources":["../../../../src/common/decorators/multerOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAGtC,OAAO,EAAC,uBAAuB,EAAC,MAAM,2BAA2B,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE;QAC1E,UAAU,CAAC,uBAAuB,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAEhF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"multipartFile.js","sourceRoot":"","sources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AuB,EAAE,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,wBAAwB,CAAC,CAAC,EACzH,QAAQ,CAAC;YACP,SAAS,EAAE,UAAU,CAAC,KAAK;YAC3B,QAAQ,EAAE,oBAAoB;YAC9B,UAAU;YACV,aAAa,EAAE,IAAI;SACpB,CAAC,CACH,CAAC;QAEF,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;IACtB,CAAC,CAAC;AACJ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"MulterException.js","sourceRoot":"","sources":["../../../../src/common/errors/MulterException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAG5C;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAG7C;;;OAGG;IACH,YAAY,EAAe;QACzB,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;IACtB,CAAC;CACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wCAAwC,CAAC;AACvD,cAAc,2CAA2C,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformMulterSettings.js","sourceRoot":"","sources":["../../../../src/common/interfaces/PlatformMulterSettings.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformMulterMiddleware.js","sourceRoot":"","sources":["../../../../src/common/middlewares/PlatformMulterMiddleware.ts"],"names":[],"mappings":";AAAA,OAAO,EA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CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -1,19 +0,0 @@
1
- import {PlatformExpress} from "@tsed/platform-express";
2
- import {PlatformTestSdk} from "@tsed/platform-test-sdk";
3
-
4
- import {rootDir, Server} from "./__mock__/Server.js";
5
-
6
- const utils = PlatformTestSdk.create({
7
- rootDir,
8
- adapter: PlatformExpress as any,
9
- server: Server,
10
- logger: {
11
- level: "off"
12
- }
13
- });
14
-
15
- describe("PlatformExpress", () => {
16
- describe("Plugin: Multer", () => {
17
- utils.test("multer");
18
- });
19
- });
@@ -1,40 +0,0 @@
1
- import {promisify} from "node:util";
2
-
3
- import {injectable} from "@tsed/di";
4
- import type {Options} from "multer";
5
-
6
- import {MULTER_MODULE} from "../../common/index.js";
7
-
8
- async function factory() {
9
- const {default: multer} = await import("multer");
10
-
11
- return {
12
- multer,
13
- get(options: Options) {
14
- const instance = multer(options);
15
-
16
- const makePromise = (multer: any, name: string) => {
17
- // istanbul ignore next
18
- if (!multer[name]) return;
19
-
20
- const fn = multer[name];
21
-
22
- multer[name] = function apply(...args: any[]) {
23
- const middleware: any = Reflect.apply(fn, this, args);
24
-
25
- return (req: any, res: any) => promisify(middleware)(req, res);
26
- };
27
- };
28
-
29
- makePromise(instance, "any");
30
- makePromise(instance, "array");
31
- makePromise(instance, "fields");
32
- makePromise(instance, "none");
33
- makePromise(instance, "single");
34
-
35
- return instance;
36
- }
37
- };
38
- }
39
-
40
- injectable(MULTER_MODULE).asyncFactory(factory).token();
@@ -1,19 +0,0 @@
1
- import {PlatformFastify} from "@tsed/platform-fastify";
2
- import {PlatformTestSdk} from "@tsed/platform-test-sdk";
3
-
4
- import {rootDir, Server} from "./__mock__/Server.js";
5
-
6
- const utils = PlatformTestSdk.create({
7
- rootDir,
8
- adapter: PlatformFastify as any,
9
- server: Server,
10
- logger: {
11
- level: "error"
12
- }
13
- });
14
-
15
- describe("PlatformFastify", () => {
16
- describe("Plugin: Multer", () => {
17
- utils.test("multer");
18
- });
19
- });
@@ -1,77 +0,0 @@
1
- import {promisify} from "node:util";
2
-
3
- import {injectable} from "@tsed/di";
4
- import type {FastifyInstance, FastifyReply, FastifyRequest} from "fastify";
5
- import fp, {type PluginMetadata} from "fastify-plugin";
6
- import type {IncomingMessage} from "http";
7
- import type {Options} from "multer";
8
-
9
- import {MULTER_MODULE, type PlatformMulterFile} from "../../common/index.js";
10
-
11
- const kMultipart = Symbol("multipart");
12
-
13
- declare module "fastify" {
14
- export interface FastifyRequest {
15
- files?: {[key: string]: PlatformMulterFile | PlatformMulterFile[]};
16
- [kMultipart]: boolean;
17
- }
18
- }
19
-
20
- function setMultipart(req: FastifyRequest, _payload: IncomingMessage, done: (err: Error | null) => void) {
21
- // nothing to do, it will be done by multer in beforeHandler method
22
- (req as any)[kMultipart] = true;
23
- done(null);
24
- }
25
-
26
- function fastifyMulter(fastify: FastifyInstance, _options: PluginMetadata, next: (err?: Error) => void) {
27
- fastify.addContentTypeParser("multipart/form-data", setMultipart);
28
- next();
29
- }
30
-
31
- const multerPlugin = fp(fastifyMulter, {
32
- fastify: ">= 5.0.0",
33
- name: "fastify-multer"
34
- });
35
-
36
- async function factory() {
37
- const {default: multer} = await import("multer");
38
-
39
- return {
40
- multer,
41
- get(options: Options) {
42
- const instance = multer(options);
43
-
44
- const makePromise = (multer: any, name: string) => {
45
- // istanbul ignore next
46
- if (!multer[name]) return;
47
-
48
- const fn = multer[name];
49
-
50
- multer[name] = function apply(...args: any[]) {
51
- const middleware: any = Reflect.apply(fn, this, args);
52
-
53
- return async (req: FastifyRequest, res: FastifyReply) => {
54
- await promisify(middleware)(req.raw, res.raw);
55
- req.files = (req.raw as any).files;
56
- req.body = (req.raw as any).body;
57
- };
58
- };
59
- };
60
-
61
- makePromise(instance, "any");
62
- makePromise(instance, "array");
63
- makePromise(instance, "fields");
64
- makePromise(instance, "none");
65
- makePromise(instance, "single");
66
-
67
- return instance;
68
- }
69
- };
70
- }
71
-
72
- injectable(MULTER_MODULE)
73
- .asyncFactory(factory)
74
- .configuration({
75
- plugins: [multerPlugin]
76
- })
77
- .token();
@@ -1,19 +0,0 @@
1
- import {PlatformKoa} from "@tsed/platform-koa";
2
- import {PlatformTestSdk} from "@tsed/platform-test-sdk";
3
-
4
- import {rootDir, Server} from "./__mock__/Server.js";
5
-
6
- const utils = PlatformTestSdk.create({
7
- rootDir,
8
- adapter: PlatformKoa as any,
9
- server: Server,
10
- logger: {
11
- level: "off"
12
- }
13
- });
14
-
15
- describe("PlatformKoa", () => {
16
- describe("Plugin: Multer", () => {
17
- utils.test("multer");
18
- });
19
- });
@@ -1,73 +0,0 @@
1
- import {promisify} from "node:util";
2
-
3
- import {injectable} from "@tsed/di";
4
- import Koa from "koa";
5
- import type {Options} from "multer";
6
-
7
- import {MULTER_MODULE} from "../../common/index.js";
8
-
9
- /**
10
- * @ignore
11
- */
12
- function createRawMiddleware(middleware: any) {
13
- return async (request: Koa.Request) => {
14
- const ctx: any = request.ctx;
15
-
16
- await middleware(ctx.req, ctx.res);
17
-
18
- const forwardKey = (key: string) => {
19
- if (ctx.req[key]) {
20
- ctx.request[key] = ctx.req[key];
21
- ctx[key] = ctx.req[key];
22
- delete ctx.req[key];
23
- }
24
- };
25
-
26
- if ("request" in ctx) {
27
- if (ctx.req.body) {
28
- ctx.request.body = ctx.req.body;
29
- delete ctx.req.body;
30
- }
31
-
32
- forwardKey("file");
33
- forwardKey("files");
34
- }
35
- };
36
- }
37
-
38
- /**
39
- * @ignore
40
- */
41
- function makePromise(multer: any, name: string) {
42
- // istanbul ignore next
43
- if (!multer[name]) return;
44
-
45
- const fn = multer[name];
46
-
47
- multer[name] = function apply(...args: any[]) {
48
- const middleware: any = Reflect.apply(fn, this, args);
49
-
50
- return createRawMiddleware(promisify(middleware));
51
- };
52
- }
53
-
54
- async function factory() {
55
- const {default: multer} = await import("multer");
56
-
57
- return {
58
- multer,
59
- get(options: Options) {
60
- const instance = multer(options);
61
-
62
- makePromise(instance, "any");
63
- makePromise(instance, "array");
64
- makePromise(instance, "fields");
65
- makePromise(instance, "none");
66
- makePromise(instance, "single");
67
-
68
- return instance;
69
- }
70
- };
71
- }
72
-
73
- injectable(MULTER_MODULE).asyncFactory(factory).token();
@@ -1,10 +0,0 @@
1
- import type {Multer, Options} from "multer";
2
-
3
- export interface MULTER_MODULE {
4
- multer: Multer;
5
-
6
- get(options: Options): Multer;
7
- }
8
-
9
- export const MULTER_MODULE = Symbol.for("MULTER_MODULE");
10
- export const PLATFORM_MULTER_OPTIONS = Symbol.for("PLATFORM_MULTER_OPTIONS");
@@ -1,22 +0,0 @@
1
- import {Store} from "@tsed/core";
2
-
3
- import {PLATFORM_MULTER_OPTIONS} from "../constants/constants.js";
4
- import {MulterFileSize} from "./multerFileSize.js";
5
-
6
- describe("MulterFileSize", () => {
7
- it("should set the file size", () => {
8
- class Test {
9
- @MulterFileSize(100)
10
- file() {}
11
- }
12
-
13
- const store = Store.fromMethod(Test, "file");
14
- expect(store.get(PLATFORM_MULTER_OPTIONS)).toEqual({
15
- options: {
16
- limits: {
17
- fileSize: 100
18
- }
19
- }
20
- });
21
- });
22
- });
@@ -1,32 +0,0 @@
1
- import {MulterOptions} from "./multerOptions.js";
2
-
3
- /**
4
- * Define file size limit.
5
- *
6
- * ```typescript
7
- * import {Post} from "@tsed/schema";
8
- * import {MulterOptions, MultipartFile} from "@tsed/platform-multer";
9
- * import {Controller} from "@tsed/di";
10
- * import {Multer} from "@types/multer";
11
- *
12
- * type MulterFile = Express.Multer.File;
13
- *
14
- * @Controller('/')
15
- * class MyCtrl {
16
- * @Post('/file2')
17
- * @MulterFileSize(1024) // (Ko). Applied for all fields
18
- * private uploadFile(@MultipartFile("file1") file: MulterFile, @MultipartFile("file2") file2: MulterFile) {
19
- *
20
- * }
21
- * }
22
- * ```
23
- *
24
- * > See the tutorial on the [multer configuration](/docs/upload-files.md).
25
- * @param fileSize
26
- * @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor}
27
- * @decorator
28
- * @multer
29
- */
30
- export function MulterFileSize(fileSize: number): MethodDecorator {
31
- return MulterOptions({limits: {fileSize}});
32
- }
@@ -1,21 +0,0 @@
1
- import {Store} from "@tsed/core";
2
-
3
- import {PLATFORM_MULTER_OPTIONS} from "../constants/constants.js";
4
- import {MulterOptions} from "./multerOptions.js";
5
-
6
- describe("@MulterOptions()", () => {
7
- it("should store metadata", () => {
8
- class Test {
9
- @MulterOptions({dest: "/"})
10
- test() {}
11
- }
12
-
13
- const store = Store.fromMethod(Test.prototype, "test");
14
-
15
- expect(store.get(PLATFORM_MULTER_OPTIONS)).toEqual({
16
- options: {
17
- dest: "/"
18
- }
19
- });
20
- });
21
- });
@@ -1,53 +0,0 @@
1
- import {StoreMerge} from "@tsed/core";
2
- import type {Options} from "multer";
3
-
4
- import {PLATFORM_MULTER_OPTIONS} from "../constants/constants.js";
5
-
6
- /**
7
- * Define multer option for all MultipartFile
8
- *
9
- * ```typescript
10
- * import {PlatformMulterFile, MultipartFile, MulterOptions} from "@tsed/platform-multer";
11
- * import {Controller} from "@tsed/di";
12
- * import {Post} from "@tsed/schema";
13
- *
14
- * @Controller('/')
15
- * class MyCtrl {
16
- * @Post('/file')
17
- * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile) {
18
- *
19
- * }
20
- *
21
- * @Post('/file')
22
- * @MulterOptions({dest: "/other-dir"})
23
- * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile) {
24
- *
25
- * }
26
- *
27
- * @Post('/file2')
28
- * @MulterOptions({dest: "/other-dir"})
29
- * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile, @MultipartFile("file2") file2: PlatformMulterFile) {
30
- *
31
- * }
32
- *
33
- * @Post('/files')
34
- * private uploadFile(@MultipartFile("file1") files: PlatformMulterFile[]) {
35
- *
36
- * }
37
- * }
38
- * ```
39
- *
40
- * See the tutorial on the [multer configuration](/docs/upload-files.md).
41
- *
42
- * @param {multer.Options} options
43
- * @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor}
44
- * @decorator
45
- * @multer
46
- */
47
- export function MulterOptions(options: Options): MethodDecorator {
48
- return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
49
- StoreMerge(PLATFORM_MULTER_OPTIONS, {options})(target, propertyKey, descriptor);
50
-
51
- return descriptor;
52
- };
53
- }
@@ -1,260 +0,0 @@
1
- import "@tsed/exceptions";
2
- import "@tsed/platform-exceptions";
3
-
4
- import {descriptorOf, Metadata, Store} from "@tsed/core";
5
- import {ParamTypes} from "@tsed/platform-params";
6
- import {getSpec, JsonParameterStore, Post, SpecTypes} from "@tsed/schema";
7
-
8
- import {PLATFORM_MULTER_OPTIONS} from "../constants/constants.js";
9
- import {MultipartFile} from "./multipartFile.js";
10
-
11
- class Test {
12
- test() {}
13
- }
14
-
15
- describe("@MultipartFile()", () => {
16
- describe("one file", () => {
17
- // WHEN
18
- class TestController {
19
- @Post("/")
20
- test(@MultipartFile("file1", 1) file: any) {}
21
- }
22
-
23
- // THEN
24
- const store = Store.fromMethod(TestController, "test");
25
- const param = JsonParameterStore.get(TestController, "test", 0);
26
-
27
- it("should set params properly", () => {
28
- expect(store.get(PLATFORM_MULTER_OPTIONS)).toEqual({
29
- fields: [
30
- {
31
- maxCount: 1,
32
- name: "file1"
33
- }
34
- ]
35
- });
36
- expect(param.expression).toEqual("file1.0");
37
- expect(param.paramType).toEqual(ParamTypes.FILES);
38
- });
39
-
40
- it("should set endpoint metadata - OS3", () => {
41
- expect(getSpec(TestController, {specType: SpecTypes.OPENAPI})).toEqual({
42
- paths: {
43
- "/": {
44
- post: {
45
- operationId: "testControllerTest",
46
- parameters: [],
47
- responses: {
48
- "400": {
49
- content: {"application/json": {schema: {$ref: "#/components/schemas/BadRequest"}}},
50
- description:
51
- "<File too long | Too many parts | Too many files | Field name too long | Field value too long | Too many fields | Unexpected field> [fieldName] Example: File too long file1"
52
- }
53
- },
54
- requestBody: {
55
- required: false,
56
- content: {
57
- "multipart/form-data": {
58
- schema: {
59
- properties: {file1: {type: "string", format: "binary"}},
60
- type: "object"
61
- }
62
- }
63
- }
64
- },
65
- tags: ["TestController"]
66
- }
67
- }
68
- },
69
- tags: [{name: "TestController"}],
70
- components: {
71
- schemas: {
72
- GenericError: {
73
- additionalProperties: true,
74
- properties: {
75
- message: {
76
- description: "An error message",
77
- minLength: 1,
78
- type: "string"
79
- },
80
- name: {
81
- description: "The error name",
82
- minLength: 1,
83
- type: "string"
84
- }
85
- },
86
- required: ["name", "message"],
87
- type: "object"
88
- },
89
- BadRequest: {
90
- type: "object",
91
- properties: {
92
- name: {
93
- type: "string",
94
- minLength: 1,
95
- description: "The error name",
96
- example: "BAD_REQUEST",
97
- default: "BAD_REQUEST"
98
- },
99
- message: {type: "string", minLength: 1, description: "An error message"},
100
- status: {type: "number", description: "The status code of the exception", example: 400, default: 400},
101
- errors: {
102
- type: "array",
103
- items: {
104
- $ref: "#/components/schemas/GenericError"
105
- },
106
- description: "A list of related errors"
107
- },
108
- stack: {
109
- type: "string",
110
- description: "The stack trace (only in development mode)"
111
- }
112
- },
113
- required: ["name", "message", "status"]
114
- }
115
- }
116
- }
117
- });
118
- });
119
- });
120
-
121
- describe("multiple file schema", () => {
122
- // WHEN
123
- class TestController {
124
- @Post("/")
125
- test(@MultipartFile("file1", 4) file: any[]) {}
126
- }
127
-
128
- // THEN
129
- const store = Store.fromMethod(TestController, "test");
130
- const param = JsonParameterStore.get(TestController, "test", 0);
131
-
132
- it("should set params properly", () => {
133
- expect(store.get(PLATFORM_MULTER_OPTIONS)).toEqual({
134
- fields: [
135
- {
136
- maxCount: 4,
137
- name: "file1"
138
- }
139
- ]
140
- });
141
- expect(param.expression).toEqual("file1");
142
- expect(param.paramType).toEqual(ParamTypes.FILES);
143
- });
144
-
145
- it("should set endpoint metadata - OS3", () => {
146
- expect(getSpec(TestController, {specType: SpecTypes.OPENAPI})).toEqual({
147
- paths: {
148
- "/": {
149
- post: {
150
- operationId: "testControllerTest",
151
- parameters: [],
152
- responses: {
153
- "400": {
154
- content: {"application/json": {schema: {$ref: "#/components/schemas/BadRequest"}}},
155
- description:
156
- "<File too long | Too many parts | Too many files | Field name too long | Field value too long | Too many fields | Unexpected field> [fieldName] Example: File too long file1"
157
- }
158
- },
159
- requestBody: {
160
- required: false,
161
- content: {
162
- "multipart/form-data": {
163
- schema: {
164
- properties: {file1: {type: "array", items: {type: "string", format: "binary"}}},
165
- type: "object"
166
- }
167
- }
168
- }
169
- },
170
- tags: ["TestController"]
171
- }
172
- }
173
- },
174
- tags: [{name: "TestController"}],
175
- components: {
176
- schemas: {
177
- GenericError: {
178
- additionalProperties: true,
179
- properties: {
180
- message: {
181
- description: "An error message",
182
- minLength: 1,
183
- type: "string"
184
- },
185
- name: {
186
- description: "The error name",
187
- minLength: 1,
188
- type: "string"
189
- }
190
- },
191
- required: ["name", "message"],
192
- type: "object"
193
- },
194
- BadRequest: {
195
- type: "object",
196
- properties: {
197
- name: {
198
- type: "string",
199
- minLength: 1,
200
- description: "The error name",
201
- example: "BAD_REQUEST",
202
- default: "BAD_REQUEST"
203
- },
204
- message: {
205
- type: "string",
206
- minLength: 1,
207
- description: "An error message"
208
- },
209
- status: {type: "number", description: "The status code of the exception", example: 400, default: 400},
210
- errors: {
211
- type: "array",
212
- items: {
213
- $ref: "#/components/schemas/GenericError"
214
- },
215
- description: "A list of related errors"
216
- },
217
- stack: {
218
- type: "string",
219
- description: "The stack trace (only in development mode)"
220
- }
221
- },
222
- required: ["name", "message", "status"]
223
- }
224
- }
225
- }
226
- });
227
- });
228
- });
229
-
230
- describe("multiple files", () => {
231
- afterAll(() => {
232
- vi.clearAllMocks();
233
- });
234
-
235
- it("should set params metadata", () => {
236
- const store = Store.from(Test.prototype, "test", descriptorOf(Test.prototype, "test"));
237
- store.delete("multipartAdded");
238
-
239
- // @ts-ignore
240
- store.delete(PLATFORM_MULTER_OPTIONS);
241
- vi.spyOn(Store, "fromMethod").mockReturnValue(store);
242
- vi.spyOn(Metadata, "getParamTypes").mockReturnValue([Array]);
243
-
244
- MultipartFile("file1", 8)(Test.prototype, "test", 0);
245
-
246
- expect(store.get(PLATFORM_MULTER_OPTIONS)).toEqual({
247
- fields: [
248
- {
249
- maxCount: 8,
250
- name: "file1"
251
- }
252
- ]
253
- });
254
-
255
- const param = JsonParameterStore.get(Test, "test", 0);
256
- expect(param.expression).toEqual("file1");
257
- expect(param.paramType).toEqual(ParamTypes.FILES);
258
- });
259
- });
260
- });
@@ -1,91 +0,0 @@
1
- import {DecoratorParameters, Metadata, StoreMerge, useDecorators, useMethodDecorators} from "@tsed/core";
2
- import {UseBefore} from "@tsed/platform-middlewares";
3
- import {ParamTypes, UseParam} from "@tsed/platform-params";
4
- import {InFile} from "@tsed/schema";
5
- import type {Field} from "multer";
6
-
7
- import {PLATFORM_MULTER_OPTIONS} from "../constants/constants.js";
8
- import type {PlatformMulterFile} from "../interfaces/PlatformMulterSettings.js";
9
- import {PlatformMulterMiddleware} from "../middlewares/PlatformMulterMiddleware.js";
10
-
11
- function mapOptions(name: string, maxCount: number | undefined): {fields: Field[]} {
12
- return {
13
- fields: [
14
- {
15
- name,
16
- maxCount
17
- }
18
- ]
19
- };
20
- }
21
-
22
- /**
23
- * Define a parameter as Multipart file.
24
- *
25
- * ```typescript
26
- * import {Post} from "@tsed/schema";
27
- * import {Controller, MulterOptions, MultipartFile} from "@tsed/platform-multer";
28
- * import {Controller} from "@tsed/di";
29
- * import {Multer} from "@types/multer";
30
- *
31
- * type MulterFile = Express.Multer.File;
32
- *
33
- * @Controller('/')
34
- * class MyCtrl {
35
- * @Post('/file')
36
- * private uploadFile(@MultipartFile("file1") file: MulterFile) {
37
- *
38
- * }
39
- *
40
- * @Post('/file')
41
- * @MulterOptions({dest: "/other-dir"})
42
- * private uploadFile(@MultipartFile("file1") file: MulterFile) {
43
- *
44
- * }
45
- *
46
- * @Post('/file2')
47
- * @MulterOptions({dest: "/other-dir"})
48
- * private uploadFile(@MultipartFile("file1") file: MulterFile, @MultipartFile("file2") file2: MulterFile) {
49
- *
50
- * }
51
- *
52
- * @Post('/files')
53
- * private uploadFile(@MultipartFile("file1") files: MulterFile[]) {
54
- *
55
- * }
56
- * }
57
- * ```
58
- *
59
- * > See the tutorial on the [multer configuration](/docs/upload-files.md).
60
- *
61
- * @param name
62
- * @param maxCount
63
- * @returns Function
64
- * @decorator
65
- * @input
66
- */
67
- export function MultipartFile(name: string, maxCount?: number): ParameterDecorator {
68
- return (...args: DecoratorParameters): void => {
69
- const [target, propertyKey, index] = args;
70
- const multiple = Metadata.getParamTypes(target, propertyKey)[index as number] === Array;
71
-
72
- name = (typeof name === "object" ? undefined : name)!;
73
-
74
- const expression = [name, !multiple && "0"].filter(Boolean).join(".");
75
-
76
- const decorators = useDecorators(
77
- InFile(name),
78
- useMethodDecorators(StoreMerge(PLATFORM_MULTER_OPTIONS, mapOptions(name, maxCount)), UseBefore(PlatformMulterMiddleware)),
79
- UseParam({
80
- paramType: ParamTypes.FILES,
81
- dataPath: "$ctx.request.files",
82
- expression,
83
- useValidation: true
84
- })
85
- );
86
-
87
- decorators(...args);
88
- };
89
- }
90
-
91
- export type MultipartFile = PlatformMulterFile;
@@ -1,20 +0,0 @@
1
- import {BadRequest} from "@tsed/exceptions";
2
- import type {MulterError} from "multer";
3
-
4
- /**
5
- * Exception thrown when a Multer error occurs during file upload operations.
6
- * Extends the BadRequest exception with Multer-specific properties.
7
- */
8
- export class MulterException extends BadRequest {
9
- origin: MulterError;
10
-
11
- /**
12
- * Creates a new MulterException
13
- * @param er - The original Multer error
14
- */
15
- constructor(er: MulterError) {
16
- super(er.message);
17
- this.origin = er;
18
- this.name = er.code;
19
- }
20
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * @file Automatically generated by @tsed/barrels.
3
- */
4
- export * from "./constants/constants.js";
5
- export * from "./decorators/multerFileSize.js";
6
- export * from "./decorators/multerOptions.js";
7
- export * from "./decorators/multipartFile.js";
8
- export * from "./errors/MulterException.js";
9
- export * from "./interfaces/PlatformMulterSettings.js";
10
- export * from "./middlewares/PlatformMulterMiddleware.js";
@@ -1,45 +0,0 @@
1
- import type {Readable} from "node:stream";
2
-
3
- import type {Field, Multer, Options} from "multer";
4
-
5
- declare global {
6
- namespace TsED {
7
- export interface Configuration {
8
- multer?: Options;
9
- }
10
- }
11
- }
12
-
13
- export type PlatformMulter = Multer;
14
- export type PlatformMulterSettings = Options;
15
- export interface PlatformMulterFile {
16
- /** Name of the form field associated with this file. */
17
- fieldname: string;
18
- /** Name of the file on the uploader's computer. */
19
- originalname: string;
20
- /**
21
- * Value of the `Content-Transfer-Encoding` header for this file.
22
- * @deprecated since July 2015
23
- * @see RFC 7578, Section 4.7
24
- */
25
- encoding: string;
26
- /** Value of the `Content-Type` header for this file. */
27
- mimetype: string;
28
- /** Size of the file in bytes. */
29
- size: number;
30
- /**
31
- * A readable stream of this file. Only available to the `_handleFile`
32
- * callback for custom `StorageEngine`s.
33
- */
34
- stream: Readable;
35
- /** `DiskStorage` only: Directory to which this file has been uploaded. */
36
- destination: string;
37
- /** `DiskStorage` only: Name of this file within `destination`. */
38
- filename: string;
39
- /** `DiskStorage` only: Full path to the uploaded file. */
40
- path: string;
41
- /** `MemoryStorage` only: A Buffer containing the entire file. */
42
- buffer: Buffer;
43
- }
44
-
45
- export type PlatformMulterField = Field;
@@ -1,98 +0,0 @@
1
- import {catchAsyncError} from "@tsed/core";
2
- import {inject, injectable} from "@tsed/di";
3
- import {Exception} from "@tsed/exceptions";
4
- import {EndpointMetadata} from "@tsed/platform-http";
5
- import {PlatformTest} from "@tsed/platform-http/testing";
6
- import {MulterError} from "multer";
7
-
8
- import {MULTER_MODULE} from "../constants/constants.js";
9
- import {MulterOptions} from "../decorators/multerOptions.js";
10
- import {MultipartFile} from "../decorators/multipartFile.js";
11
- import {PlatformMulterMiddleware} from "./PlatformMulterMiddleware.js";
12
-
13
- async function getFixture(options = {}) {
14
- class Test {
15
- @MulterOptions(options)
16
- upload(@MultipartFile("file1") file1: any) {}
17
- }
18
-
19
- const multerMiddleware = vi.fn();
20
- const multer = {
21
- fields: vi.fn().mockReturnValue(multerMiddleware)
22
- };
23
-
24
- injectable(MULTER_MODULE).factory(() => {
25
- return {
26
- get: vi.fn().mockReturnValue(multer)
27
- };
28
- });
29
-
30
- const middleware = await inject<PlatformMulterMiddleware>(PlatformMulterMiddleware);
31
- const ctx: any = PlatformTest.createRequestContext();
32
- ctx.endpoint = EndpointMetadata.get(Test, "upload");
33
-
34
- const multerModuleFactory = inject<{get: any}>(MULTER_MODULE);
35
-
36
- return {middleware, ctx, multer, multerModuleFactory, multerMiddleware};
37
- }
38
-
39
- describe("PlatformMulterMiddleware", () => {
40
- beforeEach(() =>
41
- PlatformTest.create({
42
- multer: {
43
- dest: "/dest"
44
- }
45
- })
46
- );
47
- afterEach(() => PlatformTest.reset());
48
- it("should create middleware", async () => {
49
- const {middleware, ctx, multer, multerModuleFactory, multerMiddleware} = await getFixture({});
50
-
51
- await middleware.use(ctx);
52
-
53
- expect(multerModuleFactory.get).toHaveBeenCalledWith({
54
- dest: "/dest"
55
- });
56
- expect(multer.fields).toHaveBeenCalledWith([{maxCount: undefined, name: "file1"}]);
57
- expect(multerMiddleware).toHaveBeenCalledWith(ctx.request.raw, ctx.response.raw);
58
- });
59
- it("should create middleware with storage", async () => {
60
- const {middleware, ctx, multer, multerModuleFactory, multerMiddleware} = await getFixture({
61
- storage: "storage"
62
- });
63
-
64
- await middleware.use(ctx);
65
-
66
- expect(multerModuleFactory.get).toHaveBeenCalledWith({
67
- storage: "storage"
68
- });
69
- expect(multer.fields).toHaveBeenCalledWith([{maxCount: undefined, name: "file1"}]);
70
- expect(multerMiddleware).toHaveBeenCalledWith(ctx.request.raw, ctx.response.raw);
71
- });
72
- it("should catch error with code", async () => {
73
- const {middleware, ctx, multerMiddleware} = await getFixture();
74
- const error = new MulterError("LIMIT_FILE_SIZE", "field");
75
-
76
- multerMiddleware.mockRejectedValue(error);
77
-
78
- const actualError: any | undefined = await catchAsyncError(() => middleware.use(ctx));
79
-
80
- expect(actualError).toBeInstanceOf(Exception);
81
- expect(actualError?.message).toEqual("File too large");
82
- expect(actualError?.status).toEqual(400);
83
- });
84
- it("should throw error without code", async () => {
85
- const {middleware, ctx, multerMiddleware} = await getFixture();
86
-
87
- multerMiddleware.mockRejectedValue(new Error("test"));
88
-
89
- let actualError: any;
90
- try {
91
- await middleware.use(ctx);
92
- } catch (er) {
93
- actualError = er;
94
- }
95
-
96
- expect(actualError.message).toEqual("test");
97
- });
98
- });
@@ -1,46 +0,0 @@
1
- import {constant, DIContext, inject, injectable, ProviderType} from "@tsed/di";
2
- import {MiddlewareMethods} from "@tsed/platform-middlewares";
3
- import {Context} from "@tsed/platform-params";
4
- import {JsonMethodStore} from "@tsed/schema";
5
- import type {Field, Options} from "multer";
6
-
7
- import {MULTER_MODULE, PLATFORM_MULTER_OPTIONS} from "../constants/constants.js";
8
- import {MulterException} from "../errors/MulterException.js";
9
-
10
- /**
11
- * @middleware
12
- */
13
- export class PlatformMulterMiddleware implements MiddlewareMethods {
14
- async use(@Context() ctx: DIContext & {endpoint: JsonMethodStore}) {
15
- try {
16
- const {fields, options = {}} = ctx.endpoint.get<{
17
- fields: Field[];
18
- options: Options;
19
- }>(PLATFORM_MULTER_OPTIONS);
20
-
21
- const settings: Options = {
22
- ...constant<Options>("multer", {}),
23
- ...options
24
- };
25
-
26
- /* istanbul ignore next */
27
- if (settings.storage) {
28
- settings.dest = undefined;
29
- }
30
-
31
- const {get} = await inject<Promise<MULTER_MODULE>>(MULTER_MODULE);
32
-
33
- const middleware: any = get(settings).fields(fields);
34
-
35
- return await middleware(ctx.getRequest(), ctx.getResponse());
36
- } catch (er) {
37
- if (er.code) {
38
- throw new MulterException(er);
39
- }
40
-
41
- throw er;
42
- }
43
- }
44
- }
45
-
46
- injectable(PlatformMulterMiddleware).type(ProviderType.MIDDLEWARE).priority(-10);
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./common/index.js";
package/vitest.config.mts DELETED
@@ -1,21 +0,0 @@
1
- // @ts-ignore
2
- import {presets} from "@tsed/vitest/presets";
3
- import {defineConfig} from "vitest/config";
4
-
5
- export default defineConfig(
6
- {
7
- ...presets,
8
- test: {
9
- ...presets.test,
10
- coverage: {
11
- ...presets.test.coverage,
12
- thresholds: {
13
- statements: 53.17,
14
- branches: 80,
15
- functions: 75,
16
- lines: 53.17
17
- }
18
- }
19
- }
20
- }
21
- );