@globalart/nestjs-fastify 1.0.11

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,3 @@
1
+ export declare const UploadedFiles: (...dataOrPipes: unknown[]) => ParameterDecorator;
2
+ export declare const UploadedFile: (...dataOrPipes: unknown[]) => ParameterDecorator;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,mDASzB,CAAC;AAEF,eAAO,MAAM,YAAY,mDAWxB,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UploadedFile = exports.UploadedFiles = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.UploadedFiles = (0, common_1.createParamDecorator)((_data, ctx) => {
6
+ const req = ctx.switchToHttp().getRequest();
7
+ const allFiles = [];
8
+ Object.values(req.storedFiles).forEach((files) => {
9
+ allFiles.push(...files);
10
+ });
11
+ return allFiles;
12
+ });
13
+ exports.UploadedFile = (0, common_1.createParamDecorator)((fieldName, ctx) => {
14
+ const req = ctx.switchToHttp().getRequest();
15
+ if (typeof fieldName === "string") {
16
+ const files = req.storedFiles[fieldName];
17
+ return files && files.length > 0 ? files[0] : null;
18
+ }
19
+ return req.storedFiles;
20
+ });
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAG3D,QAAA,aAAa,GAAG,IAAA,6BAAoB,EAC/C,CAAC,KAAc,EAAE,GAAqB,EAAE,EAAE;IACxC,MAAM,GAAG,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAA4B,CAAC;IACtE,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAC7C,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QAC/C,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC,CACF,CAAC;AAEW,QAAA,YAAY,GAAG,IAAA,6BAAoB,EAC9C,CAAC,SAA2B,EAAE,GAAqB,EAAE,EAAE;IACrD,MAAM,GAAG,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAA4B,CAAC;IAEtE,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QACzC,OAAO,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrD,CAAC;IAED,OAAO,GAAG,CAAC,WAAW,CAAC;AACzB,CAAC,CACF,CAAC"}
@@ -0,0 +1,41 @@
1
+ import "@fastify/cookie";
2
+
3
+ declare global {
4
+ namespace Storage {
5
+ interface MultipartFile {
6
+ buffer: Buffer;
7
+ filename: string;
8
+ size: number;
9
+ mimetype: string;
10
+ fieldname: string;
11
+ }
12
+ }
13
+ }
14
+
15
+ declare module "fastify" {
16
+ interface FastifyRequest {
17
+ cookies: { [cookieName: string]: string | undefined };
18
+ storedFiles: Record<string, Storage.MultipartFile[]>;
19
+ body: unknown;
20
+ }
21
+
22
+ interface FastifyReply {
23
+ setCookie(
24
+ name: string,
25
+ value: string,
26
+ options?: import("@fastify/cookie").CookieSerializeOptions,
27
+ ): FastifyReply;
28
+
29
+ clearCookie(
30
+ name: string,
31
+ options?: import("@fastify/cookie").CookieSerializeOptions,
32
+ ): FastifyReply;
33
+
34
+ unsignCookie(value: string): import("@fastify/cookie").UnsignResult;
35
+ }
36
+
37
+ interface FastifyInstance {
38
+ parseCookie(cookieHeader: string): { [key: string]: string };
39
+ unsignCookie(value: string): import("@fastify/cookie").UnsignResult;
40
+ }
41
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./decorators";
2
+ export * from "./types";
3
+ export * from "./interceptors";
4
+ export * from "./model";
5
+ export * from "./utils";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./decorators"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./interceptors"), exports);
20
+ __exportStar(require("./model"), exports);
21
+ __exportStar(require("./utils"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,0CAAwB;AACxB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB"}
@@ -0,0 +1,4 @@
1
+ import { NestInterceptor, Type } from "@nestjs/common";
2
+ import { MultipartOptions } from "../model";
3
+ export declare function MultipartInterceptor(options?: MultipartOptions): Type<NestInterceptor>;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interceptors/index.ts"],"names":[],"mappings":"AACA,OAAO,EAML,eAAe,EACf,IAAI,EACL,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,gBAAqB,GAC7B,IAAI,CAAC,eAAe,CAAC,CAyCvB"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultipartInterceptor = MultipartInterceptor;
4
+ const common_1 = require("@nestjs/common");
5
+ const utils_1 = require("../utils");
6
+ function MultipartInterceptor(options = {}) {
7
+ class MixinInterceptor {
8
+ async intercept(context, next) {
9
+ const req = context.switchToHttp().getRequest();
10
+ if (!req.isMultipart())
11
+ throw new common_1.HttpException("The request should be a form-data", common_1.HttpStatus.BAD_REQUEST);
12
+ const files = {};
13
+ const body = {};
14
+ for await (const part of req.parts()) {
15
+ if (part.type !== "file") {
16
+ body[part.fieldname] = part.value;
17
+ continue;
18
+ }
19
+ const file = await (0, utils_1.getFileFromPart)(part);
20
+ const validationResult = (0, utils_1.validateFile)(file, options);
21
+ if (validationResult)
22
+ throw new common_1.HttpException(validationResult, common_1.HttpStatus.UNPROCESSABLE_ENTITY);
23
+ files[part.fieldname] = files[part.fieldname] || [];
24
+ files[part.fieldname].push(file);
25
+ }
26
+ req.storedFiles = files;
27
+ req.body = body;
28
+ return next.handle();
29
+ }
30
+ }
31
+ return (0, common_1.mixin)(MixinInterceptor);
32
+ }
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interceptors/index.ts"],"names":[],"mappings":";;AAeA,oDA2CC;AAzDD,2CAQwB;AAIxB,oCAAyD;AAEzD,SAAgB,oBAAoB,CAClC,UAA4B,EAAE;IAE9B,MAAM,gBAAgB;QACpB,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;YAEjB,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAA4B,CAAC;YAE1E,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;gBACpB,MAAM,IAAI,sBAAa,CACrB,mCAAmC,EACnC,mBAAU,CAAC,WAAW,CACvB,CAAC;YAEJ,MAAM,KAAK,GAA0B,EAAE,CAAC;YACxC,MAAM,IAAI,GAAwB,EAAE,CAAC;YACrC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC;gBACrC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;oBACzB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAI,IAAuB,CAAC,KAAK,CAAC;oBACtD,SAAS;gBACX,CAAC;gBACD,MAAM,IAAI,GAAG,MAAM,IAAA,uBAAe,EAAC,IAAI,CAAC,CAAC;gBACzC,MAAM,gBAAgB,GAAG,IAAA,oBAAY,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBAErD,IAAI,gBAAgB;oBAClB,MAAM,IAAI,sBAAa,CACrB,gBAAgB,EAChB,mBAAU,CAAC,oBAAoB,CAChC,CAAC;gBAEJ,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;gBACpD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC;YACD,GAAG,CAAC,WAAW,GAAG,KAAK,CAAC;YACxB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAEhB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;KACF;IAED,OAAO,IAAA,cAAK,EAAC,gBAAgB,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare class MultipartOptions {
2
+ maxFileSize?: number | undefined;
3
+ fileType?: (string | RegExp) | undefined;
4
+ constructor(maxFileSize?: number | undefined, fileType?: (string | RegExp) | undefined);
5
+ }
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAAA,qBAAa,gBAAgB;IAElB,WAAW,CAAC,EAAE,MAAM;IACpB,QAAQ,CAAC,GAAE,MAAM,GAAG,MAAM;gBAD1B,WAAW,CAAC,EAAE,MAAM,YAAA,EACpB,QAAQ,CAAC,GAAE,MAAM,GAAG,MAAM,aAAA;CAEpC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultipartOptions = void 0;
4
+ class MultipartOptions {
5
+ constructor(maxFileSize, fileType) {
6
+ this.maxFileSize = maxFileSize;
7
+ this.fileType = fileType;
8
+ }
9
+ }
10
+ exports.MultipartOptions = MultipartOptions;
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":";;;AAAA,MAAa,gBAAgB;IAC3B,YACS,WAAoB,EACpB,QAA0B;QAD1B,gBAAW,GAAX,WAAW,CAAS;QACpB,aAAQ,GAAR,QAAQ,CAAkB;IAChC,CAAC;CACL;AALD,4CAKC"}
@@ -0,0 +1,3 @@
1
+ export type MultiPartFile<T extends string> = Storage.MultipartFile;
2
+ export type MultiPartFiles<T extends string> = Storage.MultipartFile[];
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC;AACpE,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { MultipartFile } from "@fastify/multipart";
2
+ import { MultipartOptions } from "../model";
3
+ export declare const getFileFromPart: (part: MultipartFile) => Promise<Storage.MultipartFile>;
4
+ export declare const validateFile: (file: Storage.MultipartFile, options: MultipartOptions) => string | void;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,eAAO,MAAM,eAAe,GAC1B,MAAM,aAAa,KAClB,OAAO,CAAC,OAAO,CAAC,aAAa,CAS/B,CAAC;AAEF,eAAO,MAAM,YAAY,GACvB,MAAM,OAAO,CAAC,aAAa,EAC3B,SAAS,gBAAgB,KACxB,MAAM,GAAG,IAaX,CAAC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateFile = exports.getFileFromPart = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const getFileFromPart = async (part) => {
6
+ const buffer = await part.toBuffer();
7
+ return {
8
+ buffer,
9
+ size: buffer.byteLength,
10
+ filename: part.filename,
11
+ mimetype: part.mimetype,
12
+ fieldname: part.fieldname,
13
+ };
14
+ };
15
+ exports.getFileFromPart = getFileFromPart;
16
+ const validateFile = (file, options) => {
17
+ const validators = [];
18
+ if (options.maxFileSize)
19
+ validators.push(new common_1.MaxFileSizeValidator({ maxSize: options.maxFileSize }));
20
+ if (options.fileType)
21
+ validators.push(new common_1.FileTypeValidator({ fileType: options.fileType }));
22
+ for (const validator of validators) {
23
+ if (validator.isValid(file))
24
+ continue;
25
+ return validator.buildErrorMessage(file);
26
+ }
27
+ };
28
+ exports.validateFile = validateFile;
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AACA,2CAIwB;AAGjB,MAAM,eAAe,GAAG,KAAK,EAClC,IAAmB,EACa,EAAE;IAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;IACrC,OAAO;QACL,MAAM;QACN,IAAI,EAAE,MAAM,CAAC,UAAU;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,eAAe,mBAW1B;AAEK,MAAM,YAAY,GAAG,CAC1B,IAA2B,EAC3B,OAAyB,EACV,EAAE;IACjB,MAAM,UAAU,GAAoB,EAAE,CAAC;IAEvC,IAAI,OAAO,CAAC,WAAW;QACrB,UAAU,CAAC,IAAI,CAAC,IAAI,6BAAoB,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAC9E,IAAI,OAAO,CAAC,QAAQ;QAClB,UAAU,CAAC,IAAI,CAAC,IAAI,0BAAiB,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAEzE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,SAAS;QAEtC,OAAO,SAAS,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC,CAAC;AAhBW,QAAA,YAAY,gBAgBvB"}
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@globalart/nestjs-fastify",
3
+ "version": "1.0.11",
4
+ "description": "A fastify for NestJS",
5
+ "author": {
6
+ "name": "GlobalArt, Inc"
7
+ },
8
+ "license": "MIT",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "require": "./dist/index.js",
19
+ "import": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ }
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/GlobalArtInc/nestjs-toolkit.git#main"
26
+ },
27
+ "keywords": [
28
+ "nestjs",
29
+ "fastify"
30
+ ],
31
+ "scripts": {
32
+ "format": "prettier --write \"**/*.ts\"",
33
+ "test": "jest --runInBand --passWithNoTests",
34
+ "test:cov": "jest --coverage --passWithNoTests",
35
+ "coveralls": "yarn run test:cov --coverageReporters=text-lcov | coveralls",
36
+ "build": "rm -rf ./dist && tsc && cp src/globals.d.ts dist/",
37
+ "build:watch": "tsc --watch",
38
+ "prepublishOnly": "npm run build",
39
+ "publish:dev": "npm publish --access public --tag dev",
40
+ "publish:npm": "release-it"
41
+ },
42
+ "dependencies": {
43
+ "@fastify/cookie": "11.0.2",
44
+ "@fastify/multipart": "9.0.3",
45
+ "@nestjs/common": "^11.1.6",
46
+ "@nestjs/core": "^11.1.6",
47
+ "@nestjs/microservices": "11.1.6",
48
+ "@nestjs/platform-fastify": "11.1.6",
49
+ "@nestjs/swagger": "^11.2.0",
50
+ "@nestjs/testing": "^11.1.6",
51
+ "@nestjs/typeorm": "^11.0.0",
52
+ "fastify": "^5.5.0"
53
+ },
54
+ "devDependencies": {
55
+ "@types/jest": "^30.0.0",
56
+ "@types/node": "^24.3.0",
57
+ "coveralls": "^3.1.1",
58
+ "jest": "^30.0.3",
59
+ "prettier": "^3.6.2",
60
+ "reflect-metadata": "^0.2.2",
61
+ "release-it": "19.0.4",
62
+ "rxjs": "^7.8.2",
63
+ "ts-jest": "^29.4.0",
64
+ "ts-node": "^10.9.2",
65
+ "typescript": "^5.9.2"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public"
69
+ }
70
+ }