@tsed/platform-multer 8.7.0 → 8.8.0-beta.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.
@@ -0,0 +1,54 @@
1
+ import { promisify } from "node:util";
2
+ import { injectable } from "@tsed/di";
3
+ import fp from "fastify-plugin";
4
+ import { MULTER_MODULE } from "../../common/index.js";
5
+ const kMultipart = Symbol("multipart");
6
+ function setMultipart(req, _payload, done) {
7
+ // nothing to do, it will be done by multer in beforeHandler method
8
+ req[kMultipart] = true;
9
+ done(null);
10
+ }
11
+ function fastifyMulter(fastify, _options, next) {
12
+ fastify.addContentTypeParser("multipart/form-data", setMultipart);
13
+ next();
14
+ }
15
+ const multerPlugin = fp(fastifyMulter, {
16
+ fastify: ">= 5.0.0",
17
+ name: "fastify-multer"
18
+ });
19
+ async function factory() {
20
+ const { default: multer } = await import("multer");
21
+ return {
22
+ multer,
23
+ get(options) {
24
+ const instance = multer(options);
25
+ const makePromise = (multer, name) => {
26
+ // istanbul ignore next
27
+ if (!multer[name])
28
+ return;
29
+ const fn = multer[name];
30
+ multer[name] = function apply(...args) {
31
+ const middleware = Reflect.apply(fn, this, args);
32
+ return async (req, res) => {
33
+ await promisify(middleware)(req.raw, res.raw);
34
+ req.files = req.raw.files;
35
+ req.body = req.raw.body;
36
+ };
37
+ };
38
+ };
39
+ makePromise(instance, "any");
40
+ makePromise(instance, "array");
41
+ makePromise(instance, "fields");
42
+ makePromise(instance, "none");
43
+ makePromise(instance, "single");
44
+ return instance;
45
+ }
46
+ };
47
+ }
48
+ injectable(MULTER_MODULE)
49
+ .asyncFactory(factory)
50
+ .configuration({
51
+ plugins: [multerPlugin]
52
+ })
53
+ .token();
54
+ //# sourceMappingURL=MulterModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MulterModule.js","sourceRoot":"","sources":["../../../../src/adapters/fastify/MulterModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,W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,EAAE,GAAmB,EAAE,GAAiB,EAAE,EAAE;wBACtD,MAAM,SAAS,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;wBAC9C,GAAG,CAAC,KAAK,GAAI,GAAG,CAAC,GAAW,CAAC,KAAK,CAAC;wBACnC,GAAG,CAAC,IAAI,GAAI,GAAG,CAAC,GAAW,CAAC,IAAI,CAAC;oBACnC,CAAC,CAAC;gBACJ,CAAC,CAAC;YACJ,CAAC,CAAC;YAEF,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAC7B,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC/B,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAChC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC9B,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAEhC,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,UAAU,CAAC,aAAa,CAAC;KACtB,YAAY,CAAC,OAAO,CAAC;KACrB,aAAa,CAAC;IACb,OAAO,EAAE,CAAC,YAAY,CAAC;CACxB,CAAC;KACD,KAAK,EAAE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type PlatformMulterFile } from "../../common/index.js";
2
+ declare const kMultipart: unique symbol;
3
+ declare module "fastify" {
4
+ interface FastifyRequest {
5
+ files?: {
6
+ [key: string]: PlatformMulterFile | PlatformMulterFile[];
7
+ };
8
+ [kMultipart]: boolean;
9
+ }
10
+ }
11
+ export {};
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.7.0",
5
+ "version": "8.8.0-beta.1",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -25,6 +25,12 @@
25
25
  "types": "./lib/types/adapters/koa/MulterModule.d.ts",
26
26
  "import": "./lib/esm/adapters/koa/MulterModule.js",
27
27
  "default": "./lib/esm/adapters/koa/MulterModule.js"
28
+ },
29
+ "./fastify": {
30
+ "tsed-source": "./src/adapters/fastify/MulterModule.ts",
31
+ "types": "./lib/types/adapters/fastify/MulterModule.d.ts",
32
+ "import": "./lib/esm/adapters/fastify/MulterModule.js",
33
+ "default": "./lib/esm/adapters/fastify/MulterModule.js"
28
34
  }
29
35
  },
30
36
  "scripts": {
@@ -53,11 +59,11 @@
53
59
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/platform/platform-multer",
54
60
  "repository": "https://github.com/tsedio/tsed",
55
61
  "devDependencies": {
56
- "@tsed/barrels": "8.7.0",
57
- "@tsed/core": "8.7.0",
58
- "@tsed/di": "8.7.0",
59
- "@tsed/platform-middlewares": "8.7.0",
60
- "@tsed/typescript": "8.7.0",
62
+ "@tsed/barrels": "8.8.0-beta.1",
63
+ "@tsed/core": "8.8.0-beta.1",
64
+ "@tsed/di": "8.8.0-beta.1",
65
+ "@tsed/platform-middlewares": "8.8.0-beta.1",
66
+ "@tsed/typescript": "8.8.0-beta.1",
61
67
  "eslint": "9.12.0",
62
68
  "typescript": "5.4.5",
63
69
  "vitest": "3.0.9"
@@ -67,13 +73,13 @@
67
73
  "tslib": "2.7.0"
68
74
  },
69
75
  "peerDependencies": {
70
- "@tsed/core": ">=8.7.0",
71
- "@tsed/di": ">=8.7.0",
72
- "@tsed/json-mapper": ">=8.7.0",
76
+ "@tsed/core": ">=8.8.0-beta.1",
77
+ "@tsed/di": ">=8.8.0-beta.1",
78
+ "@tsed/json-mapper": ">=8.8.0-beta.1",
73
79
  "@tsed/logger": ">=7.0.1",
74
- "@tsed/openspec": ">=8.7.0",
75
- "@tsed/platform-middlewares": ">=8.7.0",
76
- "@tsed/schema": ">=8.7.0",
80
+ "@tsed/openspec": ">=8.8.0-beta.1",
81
+ "@tsed/platform-middlewares": ">=8.8.0-beta.1",
82
+ "@tsed/schema": ">=8.8.0-beta.1",
77
83
  "cross-env": "7.0.3"
78
84
  },
79
85
  "peerDependenciesMeta": {
@@ -98,5 +104,8 @@
98
104
  "@tsed/schema": {
99
105
  "optional": false
100
106
  }
107
+ },
108
+ "publishConfig": {
109
+ "tag": "beta"
101
110
  }
102
111
  }
@@ -0,0 +1,19 @@
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
+ });
@@ -0,0 +1,19 @@
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
+ });
@@ -0,0 +1,77 @@
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();
@@ -0,0 +1,19 @@
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
+ });
package/vitest.config.mts CHANGED
@@ -18,4 +18,4 @@ export default defineConfig(
18
18
  }
19
19
  }
20
20
  }
21
- );
21
+ );