@tc-libs/file 0.9.0

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 (56) hide show
  1. package/README.md +11 -0
  2. package/package.json +11 -0
  3. package/src/constants/file.constant.d.ts +2 -0
  4. package/src/constants/file.constant.js +6 -0
  5. package/src/constants/file.constant.js.map +1 -0
  6. package/src/constants/index.d.ts +1 -0
  7. package/src/constants/index.js +5 -0
  8. package/src/constants/index.js.map +1 -0
  9. package/src/decorators/file.decorator.d.ts +5 -0
  10. package/src/decorators/file.decorator.js +30 -0
  11. package/src/decorators/file.decorator.js.map +1 -0
  12. package/src/dtos/file.multiple.dto.d.ts +3 -0
  13. package/src/dtos/file.multiple.dto.js +13 -0
  14. package/src/dtos/file.multiple.dto.js.map +1 -0
  15. package/src/dtos/file.single.dto.d.ts +3 -0
  16. package/src/dtos/file.single.dto.js +13 -0
  17. package/src/dtos/file.single.dto.js.map +1 -0
  18. package/src/dtos/index.d.ts +2 -0
  19. package/src/dtos/index.js +6 -0
  20. package/src/dtos/index.js.map +1 -0
  21. package/src/file.module.options.d.ts +23 -0
  22. package/src/file.module.options.js +5 -0
  23. package/src/file.module.options.js.map +1 -0
  24. package/src/index.d.ts +4 -0
  25. package/src/index.js +8 -0
  26. package/src/index.js.map +1 -0
  27. package/src/interceptors/file.custom-max-files.interceptor.d.ts +8 -0
  28. package/src/interceptors/file.custom-max-files.interceptor.js +28 -0
  29. package/src/interceptors/file.custom-max-files.interceptor.js.map +1 -0
  30. package/src/interceptors/file.custom-max-size.interceptor.d.ts +8 -0
  31. package/src/interceptors/file.custom-max-size.interceptor.js +28 -0
  32. package/src/interceptors/file.custom-max-size.interceptor.js.map +1 -0
  33. package/src/interceptors/index.d.ts +2 -0
  34. package/src/interceptors/index.js +6 -0
  35. package/src/interceptors/index.js.map +1 -0
  36. package/src/pipes/file.extract.pipe.d.ts +0 -0
  37. package/src/pipes/file.extract.pipe.js +48 -0
  38. package/src/pipes/file.extract.pipe.js.map +1 -0
  39. package/src/pipes/file.max-files.pipe.d.ts +44 -0
  40. package/src/pipes/file.max-files.pipe.js +125 -0
  41. package/src/pipes/file.max-files.pipe.js.map +1 -0
  42. package/src/pipes/file.required.pipe.d.ts +6 -0
  43. package/src/pipes/file.required.pipe.js +23 -0
  44. package/src/pipes/file.required.pipe.js.map +1 -0
  45. package/src/pipes/file.size.pipe.d.ts +58 -0
  46. package/src/pipes/file.size.pipe.js +203 -0
  47. package/src/pipes/file.size.pipe.js.map +1 -0
  48. package/src/pipes/file.type.pipe.d.ts +22 -0
  49. package/src/pipes/file.type.pipe.js +130 -0
  50. package/src/pipes/file.type.pipe.js.map +1 -0
  51. package/src/pipes/file.validation.pipe.d.ts +0 -0
  52. package/src/pipes/file.validation.pipe.js +98 -0
  53. package/src/pipes/file.validation.pipe.js.map +1 -0
  54. package/src/pipes/index.d.ts +4 -0
  55. package/src/pipes/index.js +10 -0
  56. package/src/pipes/index.js.map +1 -0
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # file
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build file` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test file` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@tc-libs/file",
3
+ "version": "0.9.0",
4
+ "dependencies": {
5
+ "tslib": "^2.3.0"
6
+ },
7
+ "type": "commonjs",
8
+ "main": "./src/index.js",
9
+ "typings": "./src/index.d.ts",
10
+ "types": "./src/index.d.ts"
11
+ }
@@ -0,0 +1,2 @@
1
+ export declare const FILE_CUSTOM_MAX_SIZE_META_KEY = "FileCustomMaxSizeMetaKey";
2
+ export declare const FILE_CUSTOM_MAX_FILES_META_KEY = "FileCustomMaxFilesMetaKey";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FILE_CUSTOM_MAX_FILES_META_KEY = exports.FILE_CUSTOM_MAX_SIZE_META_KEY = void 0;
4
+ exports.FILE_CUSTOM_MAX_SIZE_META_KEY = 'FileCustomMaxSizeMetaKey';
5
+ exports.FILE_CUSTOM_MAX_FILES_META_KEY = 'FileCustomMaxFilesMetaKey';
6
+ //# sourceMappingURL=file.constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.constant.js","sourceRoot":"","sources":["../../../../../packages/file/src/constants/file.constant.ts"],"names":[],"mappings":";;;AAAa,QAAA,6BAA6B,GAAG,0BAA0B,CAAC;AAC3D,QAAA,8BAA8B,GAAG,2BAA2B,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './file.constant';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./file.constant"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/file/src/constants/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC"}
@@ -0,0 +1,5 @@
1
+ export declare function UploadFileSingle(field: string): MethodDecorator;
2
+ export declare function UploadFileMultiple(field: string): MethodDecorator;
3
+ export declare function FileCustomMaxFile(customMaxFiles: number): MethodDecorator;
4
+ export declare function FileCustomMaxSize(customMaxSize: string): MethodDecorator;
5
+ export declare const FilePartNumber: () => ParameterDecorator;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilePartNumber = void 0;
4
+ exports.UploadFileSingle = UploadFileSingle;
5
+ exports.UploadFileMultiple = UploadFileMultiple;
6
+ exports.FileCustomMaxFile = FileCustomMaxFile;
7
+ exports.FileCustomMaxSize = FileCustomMaxSize;
8
+ const common_1 = require("@nestjs/common");
9
+ const platform_express_1 = require("@nestjs/platform-express");
10
+ const constants_1 = require("../constants");
11
+ const file_custom_max_files_interceptor_1 = require("../interceptors/file.custom-max-files.interceptor");
12
+ const file_custom_max_size_interceptor_1 = require("../interceptors/file.custom-max-size.interceptor");
13
+ function UploadFileSingle(field) {
14
+ return (0, common_1.applyDecorators)((0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)(field)));
15
+ }
16
+ function UploadFileMultiple(field) {
17
+ return (0, common_1.applyDecorators)((0, common_1.UseInterceptors)((0, platform_express_1.FilesInterceptor)(field)));
18
+ }
19
+ function FileCustomMaxFile(customMaxFiles) {
20
+ return (0, common_1.applyDecorators)((0, common_1.UseInterceptors)(file_custom_max_files_interceptor_1.FileCustomMaxFilesInterceptor), (0, common_1.SetMetadata)(constants_1.FILE_CUSTOM_MAX_FILES_META_KEY, customMaxFiles));
21
+ }
22
+ function FileCustomMaxSize(customMaxSize) {
23
+ return (0, common_1.applyDecorators)((0, common_1.UseInterceptors)(file_custom_max_size_interceptor_1.FileCustomMaxSizeInterceptor), (0, common_1.SetMetadata)(constants_1.FILE_CUSTOM_MAX_SIZE_META_KEY, customMaxSize));
24
+ }
25
+ exports.FilePartNumber = (0, common_1.createParamDecorator)((data, ctx) => {
26
+ const request = ctx.switchToHttp().getRequest();
27
+ const { headers } = request;
28
+ return headers['x-part-number'] ? Number(headers['x-part-number']) : 0;
29
+ });
30
+ //# sourceMappingURL=file.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.decorator.js","sourceRoot":"","sources":["../../../../../packages/file/src/decorators/file.decorator.ts"],"names":[],"mappings":";;;AAgBA,4CAEC;AAED,gDAEC;AAED,8CAKC;AAED,8CAKC;AApCD,2CAMwB;AACxB,+DAA6E;AAC7E,4CAGsB;AAEtB,yGAAkG;AAClG,uGAAgG;AAEhG,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,OAAO,IAAA,wBAAe,EAAC,IAAA,wBAAe,EAAC,IAAA,kCAAe,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAa;IAC9C,OAAO,IAAA,wBAAe,EAAC,IAAA,wBAAe,EAAC,IAAA,mCAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,SAAgB,iBAAiB,CAAC,cAAsB;IACtD,OAAO,IAAA,wBAAe,EACpB,IAAA,wBAAe,EAAC,iEAA6B,CAAC,EAC9C,IAAA,oBAAW,EAAC,0CAA8B,EAAE,cAAc,CAAC,CAC5D,CAAC;AACJ,CAAC;AAED,SAAgB,iBAAiB,CAAC,aAAqB;IACrD,OAAO,IAAA,wBAAe,EACpB,IAAA,wBAAe,EAAC,+DAA4B,CAAC,EAC7C,IAAA,oBAAW,EAAC,yCAA6B,EAAE,aAAa,CAAC,CAC1D,CAAC;AACJ,CAAC;AAEY,QAAA,cAAc,GAA6B,IAAA,6BAAoB,EAC1E,CAAC,IAAY,EAAE,GAAqB,EAAU,EAAE;IAC9C,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAiB,CAAC;IAC/D,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,OAAO,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC,CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare class FileMultipleDto {
2
+ files: any[];
3
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileMultipleDto = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const swagger_1 = require("@nestjs/swagger");
6
+ class FileMultipleDto {
7
+ }
8
+ exports.FileMultipleDto = FileMultipleDto;
9
+ tslib_1.__decorate([
10
+ (0, swagger_1.ApiProperty)({ type: 'array', items: { type: 'string', format: 'binary' } }),
11
+ tslib_1.__metadata("design:type", Array)
12
+ ], FileMultipleDto.prototype, "files", void 0);
13
+ //# sourceMappingURL=file.multiple.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.multiple.dto.js","sourceRoot":"","sources":["../../../../../packages/file/src/dtos/file.multiple.dto.ts"],"names":[],"mappings":";;;;AAAA,6CAA8C;AAE9C,MAAa,eAAe;CAG3B;AAHD,0CAGC;AADC;IADC,IAAA,qBAAW,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC;;8CAC/D"}
@@ -0,0 +1,3 @@
1
+ export declare class FileSingleDto {
2
+ file: any;
3
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileSingleDto = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const swagger_1 = require("@nestjs/swagger");
6
+ class FileSingleDto {
7
+ }
8
+ exports.FileSingleDto = FileSingleDto;
9
+ tslib_1.__decorate([
10
+ (0, swagger_1.ApiProperty)({ type: 'string', format: 'binary' }),
11
+ tslib_1.__metadata("design:type", Object)
12
+ ], FileSingleDto.prototype, "file", void 0);
13
+ //# sourceMappingURL=file.single.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.single.dto.js","sourceRoot":"","sources":["../../../../../packages/file/src/dtos/file.single.dto.ts"],"names":[],"mappings":";;;;AAAA,6CAA8C;AAE9C,MAAa,aAAa;CAGzB;AAHD,sCAGC;AADC;IADC,IAAA,qBAAW,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;;2CACxC"}
@@ -0,0 +1,2 @@
1
+ export * from './file.multiple.dto';
2
+ export * from './file.single.dto';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./file.multiple.dto"), exports);
5
+ tslib_1.__exportStar(require("./file.single.dto"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/file/src/dtos/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC;AACpC,4DAAkC"}
@@ -0,0 +1,23 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ import { FactoryProvider } from '@nestjs/common/interfaces/modules/provider.interface';
3
+ export declare const FILE_MODULE_CONFIG_OPTIONS = "FILE_MODULE_CONFIG_OPTIONS";
4
+ export interface FileModuleOptions {
5
+ image: {
6
+ maxFiles: number;
7
+ maxFileSize: number;
8
+ };
9
+ excel: {
10
+ maxFiles: number;
11
+ maxFileSize: number;
12
+ };
13
+ audio: {
14
+ maxFiles: number;
15
+ maxFileSize: number;
16
+ };
17
+ video: {
18
+ maxFiles: number;
19
+ maxFileSize: number;
20
+ };
21
+ }
22
+ type FileModuleAsyncOptions = Pick<ModuleMetadata, 'imports'> & Pick<FactoryProvider<FileModuleOptions>, 'useFactory' | 'inject'>;
23
+ export default FileModuleAsyncOptions;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FILE_MODULE_CONFIG_OPTIONS = void 0;
4
+ exports.FILE_MODULE_CONFIG_OPTIONS = 'FILE_MODULE_CONFIG_OPTIONS';
5
+ //# sourceMappingURL=file.module.options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.module.options.js","sourceRoot":"","sources":["../../../../packages/file/src/file.module.options.ts"],"names":[],"mappings":";;;AAGa,QAAA,0BAA0B,GAAG,4BAA4B,CAAC"}
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './constants';
2
+ export * from './dtos';
3
+ export * from './pipes';
4
+ export * from './interceptors';
package/src/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./constants"), exports);
5
+ tslib_1.__exportStar(require("./dtos"), exports);
6
+ tslib_1.__exportStar(require("./pipes"), exports);
7
+ tslib_1.__exportStar(require("./interceptors"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/file/src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,iDAAuB;AACvB,kDAAwB;AACxB,yDAA+B"}
@@ -0,0 +1,8 @@
1
+ import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
2
+ import { Observable } from 'rxjs';
3
+ import { Reflector } from '@nestjs/core';
4
+ export declare class FileCustomMaxFilesInterceptor implements NestInterceptor<any> {
5
+ private readonly reflector;
6
+ constructor(reflector: Reflector);
7
+ intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<void>>;
8
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileCustomMaxFilesInterceptor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const core_1 = require("@nestjs/core");
7
+ const constants_1 = require("../constants");
8
+ let FileCustomMaxFilesInterceptor = class FileCustomMaxFilesInterceptor {
9
+ constructor(reflector) {
10
+ this.reflector = reflector;
11
+ }
12
+ async intercept(context, next) {
13
+ if (context.getType() === 'http') {
14
+ const ctx = context.switchToHttp();
15
+ const request = ctx.getRequest();
16
+ const maxFiles = this.reflector.get(constants_1.FILE_CUSTOM_MAX_FILES_META_KEY, context.getHandler());
17
+ request.__customMaxFiles = maxFiles;
18
+ return next.handle();
19
+ }
20
+ return next.handle();
21
+ }
22
+ };
23
+ exports.FileCustomMaxFilesInterceptor = FileCustomMaxFilesInterceptor;
24
+ exports.FileCustomMaxFilesInterceptor = FileCustomMaxFilesInterceptor = tslib_1.__decorate([
25
+ (0, common_1.Injectable)(),
26
+ tslib_1.__metadata("design:paramtypes", [core_1.Reflector])
27
+ ], FileCustomMaxFilesInterceptor);
28
+ //# sourceMappingURL=file.custom-max-files.interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.custom-max-files.interceptor.js","sourceRoot":"","sources":["../../../../../packages/file/src/interceptors/file.custom-max-files.interceptor.ts"],"names":[],"mappings":";;;;AAAA,2CAKwB;AAGxB,uCAAyC;AACzC,4CAA8D;AAGvD,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IACxC,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAErD,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;QAEjB,IAAI,OAAO,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;YACjC,MAAM,GAAG,GAAsB,OAAO,CAAC,YAAY,EAAE,CAAC;YACtD,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC;YAEjC,MAAM,QAAQ,GAAW,IAAI,CAAC,SAAS,CAAC,GAAG,CACzC,0CAA8B,EAC9B,OAAO,CAAC,UAAU,EAAE,CACrB,CAAC;YACF,OAAO,CAAC,gBAAgB,GAAG,QAAQ,CAAC;YAEpC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF,CAAA;AAtBY,sEAA6B;wCAA7B,6BAA6B;IADzC,IAAA,mBAAU,GAAE;6CAE6B,gBAAS;GADtC,6BAA6B,CAsBzC"}
@@ -0,0 +1,8 @@
1
+ import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
2
+ import { Observable } from 'rxjs';
3
+ import { Reflector } from '@nestjs/core';
4
+ export declare class FileCustomMaxSizeInterceptor implements NestInterceptor<any> {
5
+ private readonly reflector;
6
+ constructor(reflector: Reflector);
7
+ intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<void>>;
8
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileCustomMaxSizeInterceptor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const core_1 = require("@nestjs/core");
7
+ const constants_1 = require("../constants");
8
+ let FileCustomMaxSizeInterceptor = class FileCustomMaxSizeInterceptor {
9
+ constructor(reflector) {
10
+ this.reflector = reflector;
11
+ }
12
+ async intercept(context, next) {
13
+ if (context.getType() === 'http') {
14
+ const ctx = context.switchToHttp();
15
+ const request = ctx.getRequest();
16
+ const customSize = this.reflector.get(constants_1.FILE_CUSTOM_MAX_SIZE_META_KEY, context.getHandler());
17
+ request.__customMaxFileSize = customSize;
18
+ return next.handle();
19
+ }
20
+ return next.handle();
21
+ }
22
+ };
23
+ exports.FileCustomMaxSizeInterceptor = FileCustomMaxSizeInterceptor;
24
+ exports.FileCustomMaxSizeInterceptor = FileCustomMaxSizeInterceptor = tslib_1.__decorate([
25
+ (0, common_1.Injectable)(),
26
+ tslib_1.__metadata("design:paramtypes", [core_1.Reflector])
27
+ ], FileCustomMaxSizeInterceptor);
28
+ //# sourceMappingURL=file.custom-max-size.interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.custom-max-size.interceptor.js","sourceRoot":"","sources":["../../../../../packages/file/src/interceptors/file.custom-max-size.interceptor.ts"],"names":[],"mappings":";;;;AAAA,2CAKwB;AAGxB,uCAAyC;AACzC,4CAA6D;AAGtD,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IACvC,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAErD,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;QAEjB,IAAI,OAAO,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;YACjC,MAAM,GAAG,GAAsB,OAAO,CAAC,YAAY,EAAE,CAAC;YACtD,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC;YAEjC,MAAM,UAAU,GAAW,IAAI,CAAC,SAAS,CAAC,GAAG,CAC3C,yCAA6B,EAC7B,OAAO,CAAC,UAAU,EAAE,CACrB,CAAC;YACF,OAAO,CAAC,mBAAmB,GAAG,UAAU,CAAC;YAEzC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF,CAAA;AAtBY,oEAA4B;uCAA5B,4BAA4B;IADxC,IAAA,mBAAU,GAAE;6CAE6B,gBAAS;GADtC,4BAA4B,CAsBxC"}
@@ -0,0 +1,2 @@
1
+ export * from './file.custom-max-files.interceptor';
2
+ export * from './file.custom-max-size.interceptor';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./file.custom-max-files.interceptor"), exports);
5
+ tslib_1.__exportStar(require("./file.custom-max-size.interceptor"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/file/src/interceptors/index.ts"],"names":[],"mappings":";;;AAAA,8EAAoD;AACpD,6EAAmD"}
File without changes
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ // import { Injectable } from '@nestjs/common';
3
+ // import { PipeTransform } from '@nestjs/common/interfaces';
4
+ // import { ENUM_FILE_EXCEL_MIME } from '../constants';
5
+ // import { IFile, IFileExtract } from '../interfaces/file.interface';
6
+ // import { Api415UnsupportedMediaTypeError } from '@tc-libs/errors';
7
+ // import { FileHandlerService } from '../../../file-handler/src/services/file-handler.service';
8
+ // // only for excel
9
+ // @Injectable()
10
+ // export class FileExtractPipe implements PipeTransform {
11
+ // constructor(private readonly _file: FileHandlerService) {}
12
+ // async transform(
13
+ // value: IFile | IFile[],
14
+ // ): Promise<IFileExtract | IFileExtract[]> {
15
+ // if (!value) {
16
+ // return;
17
+ // }
18
+ // if (Array.isArray(value)) {
19
+ // const extracts: IFileExtract[] = [];
20
+ // for (const val of value) {
21
+ // await this.validate(val.mimetype);
22
+ // const extract: IFileExtract = await this.extract(val);
23
+ // extracts.push(extract);
24
+ // }
25
+ // return extracts;
26
+ // }
27
+ // const file: IFile = value as IFile;
28
+ // await this.validate(file.mimetype);
29
+ // return this.extract(file);
30
+ // }
31
+ // async validate(mimetype: string): Promise<void> {
32
+ // if (
33
+ // !Object.values(ENUM_FILE_EXCEL_MIME).find(
34
+ // (val) => val === mimetype.toLowerCase(),
35
+ // )
36
+ // ) {
37
+ // throw new Api415UnsupportedMediaTypeError({ mediaType: mimetype });
38
+ // }
39
+ // }
40
+ // async extract(value: IFile): Promise<IFileExtract> {
41
+ // const extract = this._file.readExcelFromBuffer(value.buffer);
42
+ // return {
43
+ // ...value,
44
+ // extract,
45
+ // };
46
+ // }
47
+ // }
48
+ //# sourceMappingURL=file.extract.pipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.extract.pipe.js","sourceRoot":"","sources":["../../../../../packages/file/src/pipes/file.extract.pipe.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,6DAA6D;AAC7D,uDAAuD;AACvD,sEAAsE;AACtE,qEAAqE;AACrE,gGAAgG;AAEhG,oBAAoB;AACpB,gBAAgB;AAChB,0DAA0D;AAC1D,+DAA+D;AAE/D,qBAAqB;AACrB,8BAA8B;AAC9B,gDAAgD;AAChD,oBAAoB;AACpB,gBAAgB;AAChB,QAAQ;AAER,kCAAkC;AAClC,6CAA6C;AAE7C,mCAAmC;AACnC,6CAA6C;AAE7C,iEAAiE;AACjE,kCAAkC;AAClC,UAAU;AAEV,yBAAyB;AACzB,QAAQ;AAER,0CAA0C;AAC1C,0CAA0C;AAE1C,iCAAiC;AACjC,MAAM;AAEN,sDAAsD;AACtD,WAAW;AACX,mDAAmD;AACnD,mDAAmD;AACnD,UAAU;AACV,UAAU;AACV,4EAA4E;AAC5E,QAAQ;AACR,MAAM;AAEN,yDAAyD;AACzD,oEAAoE;AAEpE,eAAe;AACf,kBAAkB;AAClB,iBAAiB;AACjB,SAAS;AACT,MAAM;AACN,IAAI"}
@@ -0,0 +1,44 @@
1
+ import { PipeTransform } from '@nestjs/common';
2
+ import { Request } from 'express';
3
+ import { FileModuleOptions } from '../file.module.options';
4
+ import { IFile } from '@tc-libs/file-handler';
5
+ export declare class FileMaxFilesImagePipe implements PipeTransform {
6
+ private readonly _options;
7
+ private readonly request;
8
+ private readonly maxFile;
9
+ constructor(_options: FileModuleOptions, request: Request & {
10
+ __customMaxFiles: number;
11
+ });
12
+ transform(value: IFile[]): Promise<IFile[]>;
13
+ validate(value: IFile[]): Promise<void>;
14
+ }
15
+ export declare class FileMaxFilesExcelPipe implements PipeTransform {
16
+ private readonly request;
17
+ private readonly _options;
18
+ private readonly maxFile;
19
+ constructor(request: Request & {
20
+ __customMaxFiles: number;
21
+ }, _options: FileModuleOptions);
22
+ transform(value: IFile[]): Promise<IFile[]>;
23
+ validate(value: IFile[]): Promise<void>;
24
+ }
25
+ export declare class FileMaxFilesVideoPipe implements PipeTransform {
26
+ private readonly request;
27
+ private readonly _options;
28
+ private readonly maxFile;
29
+ constructor(request: Request & {
30
+ __customMaxFiles: number;
31
+ }, _options: FileModuleOptions);
32
+ transform(value: IFile[]): Promise<IFile[]>;
33
+ validate(value: IFile[]): Promise<void>;
34
+ }
35
+ export declare class FileMaxFilesAudioPipe implements PipeTransform {
36
+ private readonly request;
37
+ private readonly _options;
38
+ private readonly maxFile;
39
+ constructor(request: Request & {
40
+ __customMaxFiles: number;
41
+ }, _options: FileModuleOptions);
42
+ transform(value: IFile[]): Promise<IFile[]>;
43
+ validate(value: IFile[]): Promise<void>;
44
+ }
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileMaxFilesAudioPipe = exports.FileMaxFilesVideoPipe = exports.FileMaxFilesExcelPipe = exports.FileMaxFilesImagePipe = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const core_1 = require("@nestjs/core");
7
+ const errors_1 = require("@tc-libs/errors");
8
+ const file_module_options_1 = require("../file.module.options");
9
+ // only for multiple upload
10
+ let FileMaxFilesImagePipe = class FileMaxFilesImagePipe {
11
+ constructor(_options, request) {
12
+ this._options = _options;
13
+ this.request = request;
14
+ this.maxFile = this._options.image.maxFiles;
15
+ }
16
+ async transform(value) {
17
+ if (!value) {
18
+ return value;
19
+ }
20
+ await this.validate(value);
21
+ return value;
22
+ }
23
+ async validate(value) {
24
+ const maxFiles = this.request.__customMaxFiles ?? this.maxFile;
25
+ if (value.length > maxFiles) {
26
+ throw new errors_1.Api422MaxFilesError({
27
+ got: value.length,
28
+ max: maxFiles,
29
+ });
30
+ }
31
+ return;
32
+ }
33
+ };
34
+ exports.FileMaxFilesImagePipe = FileMaxFilesImagePipe;
35
+ exports.FileMaxFilesImagePipe = FileMaxFilesImagePipe = tslib_1.__decorate([
36
+ (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
37
+ tslib_1.__param(0, (0, common_1.Inject)(file_module_options_1.FILE_MODULE_CONFIG_OPTIONS)),
38
+ tslib_1.__param(1, (0, common_1.Inject)(core_1.REQUEST)),
39
+ tslib_1.__metadata("design:paramtypes", [Object, Object])
40
+ ], FileMaxFilesImagePipe);
41
+ let FileMaxFilesExcelPipe = class FileMaxFilesExcelPipe {
42
+ constructor(request, _options) {
43
+ this.request = request;
44
+ this._options = _options;
45
+ this.maxFile = this._options.excel.maxFiles;
46
+ }
47
+ async transform(value) {
48
+ await this.validate(value);
49
+ return value;
50
+ }
51
+ async validate(value) {
52
+ const maxFiles = this.request.__customMaxFiles ?? this.maxFile;
53
+ if (value.length > maxFiles) {
54
+ throw new errors_1.Api422MaxFilesError({
55
+ got: value.length,
56
+ max: maxFiles,
57
+ });
58
+ }
59
+ return;
60
+ }
61
+ };
62
+ exports.FileMaxFilesExcelPipe = FileMaxFilesExcelPipe;
63
+ exports.FileMaxFilesExcelPipe = FileMaxFilesExcelPipe = tslib_1.__decorate([
64
+ (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
65
+ tslib_1.__param(0, (0, common_1.Inject)(core_1.REQUEST)),
66
+ tslib_1.__param(1, (0, common_1.Inject)(file_module_options_1.FILE_MODULE_CONFIG_OPTIONS)),
67
+ tslib_1.__metadata("design:paramtypes", [Object, Object])
68
+ ], FileMaxFilesExcelPipe);
69
+ let FileMaxFilesVideoPipe = class FileMaxFilesVideoPipe {
70
+ constructor(request, _options) {
71
+ this.request = request;
72
+ this._options = _options;
73
+ this.maxFile = this._options.video.maxFiles;
74
+ }
75
+ async transform(value) {
76
+ await this.validate(value);
77
+ return value;
78
+ }
79
+ async validate(value) {
80
+ const maxFiles = this.request.__customMaxFiles ?? this.maxFile;
81
+ if (value.length > maxFiles) {
82
+ throw new errors_1.Api422MaxFilesError({
83
+ got: value.length,
84
+ max: maxFiles,
85
+ });
86
+ }
87
+ return;
88
+ }
89
+ };
90
+ exports.FileMaxFilesVideoPipe = FileMaxFilesVideoPipe;
91
+ exports.FileMaxFilesVideoPipe = FileMaxFilesVideoPipe = tslib_1.__decorate([
92
+ (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
93
+ tslib_1.__param(0, (0, common_1.Inject)(core_1.REQUEST)),
94
+ tslib_1.__param(1, (0, common_1.Inject)(file_module_options_1.FILE_MODULE_CONFIG_OPTIONS)),
95
+ tslib_1.__metadata("design:paramtypes", [Object, Object])
96
+ ], FileMaxFilesVideoPipe);
97
+ let FileMaxFilesAudioPipe = class FileMaxFilesAudioPipe {
98
+ constructor(request, _options) {
99
+ this.request = request;
100
+ this._options = _options;
101
+ this.maxFile = this._options.audio.maxFiles;
102
+ }
103
+ async transform(value) {
104
+ await this.validate(value);
105
+ return value;
106
+ }
107
+ async validate(value) {
108
+ const maxFiles = this.request.__customMaxFiles ?? this.maxFile;
109
+ if (value.length > maxFiles) {
110
+ throw new errors_1.Api422MaxFilesError({
111
+ got: value.length,
112
+ max: maxFiles,
113
+ });
114
+ }
115
+ return;
116
+ }
117
+ };
118
+ exports.FileMaxFilesAudioPipe = FileMaxFilesAudioPipe;
119
+ exports.FileMaxFilesAudioPipe = FileMaxFilesAudioPipe = tslib_1.__decorate([
120
+ (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
121
+ tslib_1.__param(0, (0, common_1.Inject)(core_1.REQUEST)),
122
+ tslib_1.__param(1, (0, common_1.Inject)(file_module_options_1.FILE_MODULE_CONFIG_OPTIONS)),
123
+ tslib_1.__metadata("design:paramtypes", [Object, Object])
124
+ ], FileMaxFilesAudioPipe);
125
+ //# sourceMappingURL=file.max-files.pipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.max-files.pipe.js","sourceRoot":"","sources":["../../../../../packages/file/src/pipes/file.max-files.pipe.ts"],"names":[],"mappings":";;;;AAAA,2CAA0E;AAC1E,uCAAuC;AAEvC,4CAAsD;AACtD,gEAGgC;AAGhC,2BAA2B;AAGpB,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAGhC,YAEmB,QAA2B,EAE3B,OAA+C;QAF/C,aAAQ,GAAR,QAAQ,CAAmB;QAE3B,YAAO,GAAP,OAAO,CAAwC;QAEhE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,KAAc;QAC5B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAE3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAc;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,IAAI,IAAI,CAAC,OAAO,CAAC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,CAAmB;QAE5C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,KAAc;QAC5B,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAE3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAc;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,IAAI,IAAI,CAAC,OAAO,CAAC;QAE/D,IAAI,KAAK,CAAC,MAAM,GAAG,QAAQ,EAAE,CAAC;YAC5B,MAAM,IAAI,4BAAmB,CAAC;gBAC5B,GAAG,EAAE,KAAK,CAAC,MAAM;gBACjB,GAAG,EAAE,QAAQ;aACd,CAAC,CAAC;QACL,CAAC;QAED,OAAO;IACT,CAAC;CACF,CAAA;AA9BY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,OAAO,EAAE,CAAC;IAKhC,mBAAA,IAAA,eAAM,EAAC,cAAO,CAAC,CAAA;IAEf,mBAAA,IAAA,eAAM,EAAC,gDAA0B,CAAC,CAAA;;GAN1B,qBAAqB,CA8BjC"}
@@ -0,0 +1,6 @@
1
+ import { PipeTransform } from '@nestjs/common';
2
+ import { IFile } from '@tc-libs/file-handler';
3
+ export declare class FileRequiredPipe implements PipeTransform {
4
+ transform(value: IFile | IFile[]): IFile | IFile[];
5
+ validate(value: IFile | IFile[]): void;
6
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileRequiredPipe = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const errors_1 = require("@tc-libs/errors");
6
+ const common_1 = require("@nestjs/common");
7
+ let FileRequiredPipe = class FileRequiredPipe {
8
+ transform(value) {
9
+ this.validate(value);
10
+ return value;
11
+ }
12
+ validate(value) {
13
+ if (!value || (Array.isArray(value) && value.length === 0)) {
14
+ throw new errors_1.Api422FileNeededError();
15
+ }
16
+ return;
17
+ }
18
+ };
19
+ exports.FileRequiredPipe = FileRequiredPipe;
20
+ exports.FileRequiredPipe = FileRequiredPipe = tslib_1.__decorate([
21
+ (0, common_1.Injectable)()
22
+ ], FileRequiredPipe);
23
+ //# sourceMappingURL=file.required.pipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.required.pipe.js","sourceRoot":"","sources":["../../../../../packages/file/src/pipes/file.required.pipe.ts"],"names":[],"mappings":";;;;AAAA,4CAAwD;AACxD,2CAA2D;AAIpD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,SAAS,CAAC,KAAsB;QAC9B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,QAAQ,CAAC,KAAsB;QAC7B,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC;YAC3D,MAAM,IAAI,8BAAqB,EAAE,CAAC;QACpC,CAAC;QAED,OAAO;IACT,CAAC;CACF,CAAA;AAbY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;GACA,gBAAgB,CAa5B"}
@@ -0,0 +1,58 @@
1
+ import { PipeTransform } from '@nestjs/common';
2
+ import { FileHandlerService, IFile } from '@tc-libs/file-handler';
3
+ import { FileModuleOptions } from '../file.module.options';
4
+ export declare class FileSizeImagePipe implements PipeTransform {
5
+ private readonly request;
6
+ private readonly _options;
7
+ private readonly _file;
8
+ private readonly maxSize;
9
+ constructor(request: Request & {
10
+ __customMaxFileSize: string;
11
+ }, _options: FileModuleOptions, _file: FileHandlerService);
12
+ transform(value: IFile | IFile[]): IFile | IFile[] | undefined;
13
+ validate(size: number): void;
14
+ }
15
+ export declare class FileSizeExcelPipe implements PipeTransform {
16
+ private readonly request;
17
+ private readonly _options;
18
+ private readonly _file;
19
+ private readonly maxSize;
20
+ constructor(request: Request & {
21
+ __customMaxFileSize: string;
22
+ }, _options: FileModuleOptions, _file: FileHandlerService);
23
+ transform(value: IFile | IFile[]): Promise<IFile | IFile[]>;
24
+ validate(size: number): Promise<void>;
25
+ }
26
+ export declare class FileSizeVideoPipe implements PipeTransform {
27
+ private readonly request;
28
+ private readonly _options;
29
+ private readonly _file;
30
+ private readonly maxSize;
31
+ constructor(request: Request & {
32
+ __customMaxFileSize: string;
33
+ }, _options: FileModuleOptions, _file: FileHandlerService);
34
+ transform(value: IFile | IFile[]): Promise<IFile | IFile[]>;
35
+ validate(size: number): Promise<void>;
36
+ }
37
+ export declare class FileSizeAudioPipe implements PipeTransform {
38
+ private readonly request;
39
+ private readonly _options;
40
+ private readonly _file;
41
+ private readonly maxSize;
42
+ constructor(request: Request & {
43
+ __customMaxFileSize: string;
44
+ }, _options: FileModuleOptions, _file: FileHandlerService);
45
+ transform(value: IFile | IFile[]): Promise<IFile | IFile[]>;
46
+ validate(size: number): Promise<void>;
47
+ }
48
+ export declare class FileSizeVideoAudioTextPipe implements PipeTransform {
49
+ private readonly request;
50
+ private readonly _options;
51
+ private readonly _file;
52
+ private readonly maxSize;
53
+ constructor(request: Request & {
54
+ __customMaxFileSize: string;
55
+ }, _options: FileModuleOptions, _file: FileHandlerService);
56
+ transform(value: IFile | IFile[]): Promise<IFile | IFile[]>;
57
+ validate(size: number): Promise<void>;
58
+ }
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileSizeVideoAudioTextPipe = exports.FileSizeAudioPipe = exports.FileSizeVideoPipe = exports.FileSizeExcelPipe = exports.FileSizeImagePipe = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const core_1 = require("@nestjs/core");
7
+ const errors_1 = require("@tc-libs/errors");
8
+ const file_handler_1 = require("@tc-libs/file-handler");
9
+ const file_module_options_1 = require("../file.module.options");
10
+ let FileSizeImagePipe = class FileSizeImagePipe {
11
+ constructor(request, _options, _file) {
12
+ this.request = request;
13
+ this._options = _options;
14
+ this._file = _file;
15
+ this.maxSize = this._options.image.maxFileSize;
16
+ }
17
+ transform(value) {
18
+ if (!value) {
19
+ return undefined;
20
+ }
21
+ if (Array.isArray(value)) {
22
+ for (const val of value) {
23
+ this.validate(val.size);
24
+ }
25
+ return value;
26
+ }
27
+ const file = value;
28
+ this.validate(file.size);
29
+ return value;
30
+ }
31
+ validate(size) {
32
+ const maxSizeInBytes = this.request.__customMaxFileSize
33
+ ? this._file.convertToBytes(this.request.__customMaxFileSize)
34
+ : this.maxSize;
35
+ if (size > maxSizeInBytes) {
36
+ throw new errors_1.Api413PayloadTooLargeError({
37
+ got: size,
38
+ max: maxSizeInBytes,
39
+ });
40
+ }
41
+ return;
42
+ }
43
+ };
44
+ exports.FileSizeImagePipe = FileSizeImagePipe;
45
+ exports.FileSizeImagePipe = FileSizeImagePipe = tslib_1.__decorate([
46
+ (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
47
+ tslib_1.__param(0, (0, common_1.Inject)(core_1.REQUEST)),
48
+ tslib_1.__param(1, (0, common_1.Inject)(file_module_options_1.FILE_MODULE_CONFIG_OPTIONS)),
49
+ tslib_1.__metadata("design:paramtypes", [Object, Object, file_handler_1.FileHandlerService])
50
+ ], FileSizeImagePipe);
51
+ let FileSizeExcelPipe = class FileSizeExcelPipe {
52
+ constructor(request, _options, _file) {
53
+ this.request = request;
54
+ this._options = _options;
55
+ this._file = _file;
56
+ this.maxSize = this._options.excel.maxFileSize;
57
+ }
58
+ async transform(value) {
59
+ if (Array.isArray(value)) {
60
+ for (const val of value) {
61
+ await this.validate(val.size);
62
+ }
63
+ return value;
64
+ }
65
+ const file = value;
66
+ await this.validate(file.size);
67
+ return value;
68
+ }
69
+ async validate(size) {
70
+ const maxSizeInBytes = this.request.__customMaxFileSize
71
+ ? this._file.convertToBytes(this.request.__customMaxFileSize)
72
+ : this.maxSize;
73
+ if (size > maxSizeInBytes) {
74
+ throw new errors_1.Api413PayloadTooLargeError({
75
+ got: size,
76
+ max: maxSizeInBytes,
77
+ });
78
+ }
79
+ return;
80
+ }
81
+ };
82
+ exports.FileSizeExcelPipe = FileSizeExcelPipe;
83
+ exports.FileSizeExcelPipe = FileSizeExcelPipe = tslib_1.__decorate([
84
+ (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
85
+ tslib_1.__param(0, (0, common_1.Inject)(core_1.REQUEST)),
86
+ tslib_1.__param(1, (0, common_1.Inject)(file_module_options_1.FILE_MODULE_CONFIG_OPTIONS)),
87
+ tslib_1.__metadata("design:paramtypes", [Object, Object, file_handler_1.FileHandlerService])
88
+ ], FileSizeExcelPipe);
89
+ let FileSizeVideoPipe = class FileSizeVideoPipe {
90
+ constructor(request, _options, _file) {
91
+ this.request = request;
92
+ this._options = _options;
93
+ this._file = _file;
94
+ this.maxSize = this._options.video.maxFileSize;
95
+ }
96
+ async transform(value) {
97
+ if (Array.isArray(value)) {
98
+ for (const val of value) {
99
+ await this.validate(val.size);
100
+ }
101
+ return value;
102
+ }
103
+ const file = value;
104
+ await this.validate(file.size);
105
+ return value;
106
+ }
107
+ async validate(size) {
108
+ const maxSizeInBytes = this.request.__customMaxFileSize
109
+ ? this._file.convertToBytes(this.request.__customMaxFileSize)
110
+ : this.maxSize;
111
+ if (size > maxSizeInBytes) {
112
+ throw new errors_1.Api413PayloadTooLargeError({
113
+ got: size,
114
+ max: maxSizeInBytes,
115
+ });
116
+ }
117
+ return;
118
+ }
119
+ };
120
+ exports.FileSizeVideoPipe = FileSizeVideoPipe;
121
+ exports.FileSizeVideoPipe = FileSizeVideoPipe = tslib_1.__decorate([
122
+ (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
123
+ tslib_1.__param(0, (0, common_1.Inject)(core_1.REQUEST)),
124
+ tslib_1.__param(1, (0, common_1.Inject)(file_module_options_1.FILE_MODULE_CONFIG_OPTIONS)),
125
+ tslib_1.__metadata("design:paramtypes", [Object, Object, file_handler_1.FileHandlerService])
126
+ ], FileSizeVideoPipe);
127
+ let FileSizeAudioPipe = class FileSizeAudioPipe {
128
+ constructor(request, _options, _file) {
129
+ this.request = request;
130
+ this._options = _options;
131
+ this._file = _file;
132
+ this.maxSize = this._options.audio.maxFileSize;
133
+ }
134
+ async transform(value) {
135
+ if (Array.isArray(value)) {
136
+ for (const val of value) {
137
+ await this.validate(val.size);
138
+ }
139
+ return value;
140
+ }
141
+ const file = value;
142
+ await this.validate(file.size);
143
+ return value;
144
+ }
145
+ async validate(size) {
146
+ const maxSizeInBytes = this.request.__customMaxFileSize
147
+ ? this._file.convertToBytes(this.request.__customMaxFileSize)
148
+ : this.maxSize;
149
+ if (size > maxSizeInBytes) {
150
+ throw new errors_1.Api413PayloadTooLargeError({
151
+ got: size,
152
+ max: maxSizeInBytes,
153
+ });
154
+ }
155
+ return;
156
+ }
157
+ };
158
+ exports.FileSizeAudioPipe = FileSizeAudioPipe;
159
+ exports.FileSizeAudioPipe = FileSizeAudioPipe = tslib_1.__decorate([
160
+ (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
161
+ tslib_1.__param(0, (0, common_1.Inject)(core_1.REQUEST)),
162
+ tslib_1.__param(1, (0, common_1.Inject)(file_module_options_1.FILE_MODULE_CONFIG_OPTIONS)),
163
+ tslib_1.__metadata("design:paramtypes", [Object, Object, file_handler_1.FileHandlerService])
164
+ ], FileSizeAudioPipe);
165
+ let FileSizeVideoAudioTextPipe = class FileSizeVideoAudioTextPipe {
166
+ constructor(request, _options, _file) {
167
+ this.request = request;
168
+ this._options = _options;
169
+ this._file = _file;
170
+ this.maxSize = this._options.video.maxFileSize;
171
+ }
172
+ async transform(value) {
173
+ if (Array.isArray(value)) {
174
+ for (const val of value) {
175
+ await this.validate(val.size);
176
+ }
177
+ return value;
178
+ }
179
+ const file = value;
180
+ await this.validate(file.size);
181
+ return value;
182
+ }
183
+ async validate(size) {
184
+ const maxSizeInBytes = this.request.__customMaxFileSize
185
+ ? this._file.convertToBytes(this.request.__customMaxFileSize)
186
+ : this.maxSize;
187
+ if (size > maxSizeInBytes) {
188
+ throw new errors_1.Api413PayloadTooLargeError({
189
+ got: size,
190
+ max: maxSizeInBytes,
191
+ });
192
+ }
193
+ return;
194
+ }
195
+ };
196
+ exports.FileSizeVideoAudioTextPipe = FileSizeVideoAudioTextPipe;
197
+ exports.FileSizeVideoAudioTextPipe = FileSizeVideoAudioTextPipe = tslib_1.__decorate([
198
+ (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
199
+ tslib_1.__param(0, (0, common_1.Inject)(core_1.REQUEST)),
200
+ tslib_1.__param(1, (0, common_1.Inject)(file_module_options_1.FILE_MODULE_CONFIG_OPTIONS)),
201
+ tslib_1.__metadata("design:paramtypes", [Object, Object, file_handler_1.FileHandlerService])
202
+ ], FileSizeVideoAudioTextPipe);
203
+ //# sourceMappingURL=file.size.pipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.size.pipe.js","sourceRoot":"","sources":["../../../../../packages/file/src/pipes/file.size.pipe.ts"],"names":[],"mappings":";;;;AAAA,2CAA0E;AAC1E,uCAAuC;AACvC,4CAA6D;AAC7D,wDAAkE;AAClE,gEAGgC;AAGzB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAG5B,YAEmB,OAAkD,EAElD,QAA2B,EAC3B,KAAyB;QAHzB,YAAO,GAAP,OAAO,CAA2C;QAElD,aAAQ,GAAR,QAAQ,CAAmB;QAC3B,UAAK,GAAL,KAAK,CAAoB;QAE1C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC;IACjD,CAAC;IAED,SAAS,CAAC,KAAsB;QAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,I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,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,OAAO,EAAE,CAAC;IAKhC,mBAAA,IAAA,eAAM,EAAC,cAAO,CAAC,CAAA;IAEf,mBAAA,IAAA,eAAM,EAAC,gDAA0B,CAAC,CAAA;6DAEX,iCAAkB;GARjC,0BAA0B,CA0CtC"}
@@ -0,0 +1,22 @@
1
+ import { PipeTransform } from '@nestjs/common';
2
+ import { IFile } from '@tc-libs/file-handler';
3
+ export declare class FileTypeImagePipe implements PipeTransform {
4
+ transform(value: IFile | IFile[]): IFile | IFile[] | undefined;
5
+ validate(mimetype: string): void;
6
+ }
7
+ export declare class FileTypeVideoPipe implements PipeTransform {
8
+ transform(value: IFile | IFile[]): Promise<IFile | IFile[]>;
9
+ validate(mimetype: string): Promise<void>;
10
+ }
11
+ export declare class FileTypeAudioPipe implements PipeTransform {
12
+ transform(value: IFile | IFile[]): Promise<IFile | IFile[]>;
13
+ validate(mimetype: string): Promise<void>;
14
+ }
15
+ export declare class FileTypeVideoAudioTextPipe implements PipeTransform {
16
+ transform(value: IFile | IFile[]): Promise<IFile | IFile[]>;
17
+ validate(mimetype: string): Promise<void>;
18
+ }
19
+ export declare class FileTypeExcelPipe implements PipeTransform {
20
+ transform(value: IFile | IFile[]): Promise<IFile | IFile[]>;
21
+ validate(mimetype: string): Promise<void>;
22
+ }
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileTypeExcelPipe = exports.FileTypeVideoAudioTextPipe = exports.FileTypeAudioPipe = exports.FileTypeVideoPipe = exports.FileTypeImagePipe = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const constant_1 = require("@tc-libs/constant");
7
+ const errors_1 = require("@tc-libs/errors");
8
+ let FileTypeImagePipe = class FileTypeImagePipe {
9
+ transform(value) {
10
+ if (!value) {
11
+ return undefined;
12
+ }
13
+ if (Array.isArray(value)) {
14
+ for (const val of value) {
15
+ this.validate(val.mimetype);
16
+ }
17
+ return value;
18
+ }
19
+ const file = value;
20
+ this.validate(file.mimetype);
21
+ return value;
22
+ }
23
+ validate(mimetype) {
24
+ if (!Object.values(constant_1.ENUM_FILE_IMAGE_MIME).find((val) => val === mimetype.toLowerCase())) {
25
+ throw new errors_1.Api415UnsupportedMediaTypeError({ mediaType: mimetype });
26
+ }
27
+ return;
28
+ }
29
+ };
30
+ exports.FileTypeImagePipe = FileTypeImagePipe;
31
+ exports.FileTypeImagePipe = FileTypeImagePipe = tslib_1.__decorate([
32
+ (0, common_1.Injectable)()
33
+ ], FileTypeImagePipe);
34
+ let FileTypeVideoPipe = class FileTypeVideoPipe {
35
+ async transform(value) {
36
+ if (Array.isArray(value)) {
37
+ for (const val of value) {
38
+ await this.validate(val.mimetype);
39
+ }
40
+ return value;
41
+ }
42
+ const file = value;
43
+ await this.validate(file.mimetype);
44
+ return value;
45
+ }
46
+ async validate(mimetype) {
47
+ if (!Object.values(constant_1.ENUM_FILE_VIDEO_MIME).find((val) => val === mimetype.toLowerCase())) {
48
+ throw new errors_1.Api415UnsupportedMediaTypeError({ mediaType: mimetype });
49
+ }
50
+ return;
51
+ }
52
+ };
53
+ exports.FileTypeVideoPipe = FileTypeVideoPipe;
54
+ exports.FileTypeVideoPipe = FileTypeVideoPipe = tslib_1.__decorate([
55
+ (0, common_1.Injectable)()
56
+ ], FileTypeVideoPipe);
57
+ let FileTypeAudioPipe = class FileTypeAudioPipe {
58
+ async transform(value) {
59
+ if (Array.isArray(value)) {
60
+ for (const val of value) {
61
+ await this.validate(val.mimetype);
62
+ }
63
+ return value;
64
+ }
65
+ const file = value;
66
+ await this.validate(file.mimetype);
67
+ return value;
68
+ }
69
+ async validate(mimetype) {
70
+ if (!Object.values(constant_1.ENUM_FILE_AUDIO_MIME).find((val) => val === mimetype.toLowerCase())) {
71
+ throw new errors_1.Api415UnsupportedMediaTypeError({ mediaType: mimetype });
72
+ }
73
+ return;
74
+ }
75
+ };
76
+ exports.FileTypeAudioPipe = FileTypeAudioPipe;
77
+ exports.FileTypeAudioPipe = FileTypeAudioPipe = tslib_1.__decorate([
78
+ (0, common_1.Injectable)()
79
+ ], FileTypeAudioPipe);
80
+ let FileTypeVideoAudioTextPipe = class FileTypeVideoAudioTextPipe {
81
+ async transform(value) {
82
+ if (Array.isArray(value)) {
83
+ for (const val of value) {
84
+ await this.validate(val.mimetype);
85
+ }
86
+ return value;
87
+ }
88
+ const file = value;
89
+ await this.validate(file.mimetype);
90
+ return value;
91
+ }
92
+ async validate(mimetype) {
93
+ if (![
94
+ ...Object.values(constant_1.ENUM_FILE_VIDEO_MIME),
95
+ ...Object.values(constant_1.ENUM_FILE_AUDIO_MIME),
96
+ ...Object.values(constant_1.ENUM_FILE_TEXT_MIME),
97
+ ].find((val) => val === mimetype.toLowerCase())) {
98
+ throw new errors_1.Api415UnsupportedMediaTypeError({ mediaType: mimetype });
99
+ }
100
+ return;
101
+ }
102
+ };
103
+ exports.FileTypeVideoAudioTextPipe = FileTypeVideoAudioTextPipe;
104
+ exports.FileTypeVideoAudioTextPipe = FileTypeVideoAudioTextPipe = tslib_1.__decorate([
105
+ (0, common_1.Injectable)()
106
+ ], FileTypeVideoAudioTextPipe);
107
+ let FileTypeExcelPipe = class FileTypeExcelPipe {
108
+ async transform(value) {
109
+ if (Array.isArray(value)) {
110
+ for (const val of value) {
111
+ await this.validate(val.mimetype);
112
+ }
113
+ return value;
114
+ }
115
+ const file = value;
116
+ await this.validate(file.mimetype);
117
+ return value;
118
+ }
119
+ async validate(mimetype) {
120
+ if (!Object.values(constant_1.ENUM_FILE_EXCEL_MIME).find((val) => val === mimetype.toLowerCase())) {
121
+ throw new errors_1.Api415UnsupportedMediaTypeError({ mediaType: mimetype });
122
+ }
123
+ return;
124
+ }
125
+ };
126
+ exports.FileTypeExcelPipe = FileTypeExcelPipe;
127
+ exports.FileTypeExcelPipe = FileTypeExcelPipe = tslib_1.__decorate([
128
+ (0, common_1.Injectable)()
129
+ ], FileTypeExcelPipe);
130
+ //# sourceMappingURL=file.type.pipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.type.pipe.js","sourceRoot":"","sources":["../../../../../packages/file/src/pipes/file.type.pipe.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAC3D,gDAM2B;AAC3B,4CAAkE;AAI3D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,SAAS,CAAC,KAAsB;QAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;gBACxB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC9B,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,IAAI,GAAG,KAAc,CAAC;QAC5B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE7B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,QAAQ,CAAC,QAAgB;QACvB,IACE,CAAC,MAAM,CAAC,MAAM,CAAC,+BAAoB,CAAC,CAAC,IAAI,CACvC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,WAAW,EAAE,CACxC,EACD,CAAC;YACD,MAAM,IAAI,wCAA+B,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,OAAO;IACT,CAAC;CACF,CAAA;AA/BY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;GACA,iBAAiB,CA+B7B;AAGM,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,KAAK,CAAC,SAAS,CAAC,KAAsB;QACpC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC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BAAU,GAAE;GACA,0BAA0B,CA6BtC;AAGM,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,KAAK,CAAC,SAAS,CAAC,KAAsB;QACpC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;gBACxB,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACpC,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,IAAI,GAAU,KAAc,CAAC;QACnC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEnC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,QAAgB;QAC7B,IACE,CAAC,MAAM,CAAC,MAAM,CAAC,+BAAoB,CAAC,CAAC,IAAI,CACvC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,WAAW,EAAE,CACxC,EACD,CAAC;YACD,MAAM,IAAI,wCAA+B,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,OAAO;IACT,CAAC;CACF,CAAA;AA3BY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;GACA,iBAAiB,CA2B7B"}
File without changes
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ // import { Injectable } from '@nestjs/common';
3
+ // import { PipeTransform } from '@nestjs/common/interfaces';
4
+ // import { validate, ValidationError } from 'class-validator';
5
+ // import { ClassConstructor, plainToInstance } from 'class-transformer';
6
+ // import {
7
+ // Api415UnsupportedMediaTypeError,
8
+ // Api422FileNeedExtractFirstError,
9
+ // Api422ValidationError,
10
+ // IValidationErrorImport,
11
+ // } from '@tc-libs/errors';
12
+ // import { ENUM_FILE_EXCEL_MIME } from '../constants';
13
+ // import { IFileExtract } from '../interfaces/file.interface';
14
+ // // only for excel
15
+ // // must use after FileExtractPipe
16
+ // @Injectable()
17
+ // export class FileValidationPipe<T> implements PipeTransform {
18
+ // constructor(private readonly dto: ClassConstructor<T>) {}
19
+ // async transform(
20
+ // value: IFileExtract<T> | IFileExtract<T>[],
21
+ // ): Promise<IFileExtract<T> | IFileExtract<T>[]> {
22
+ // if (!value) {
23
+ // return;
24
+ // }
25
+ // if (Array.isArray(value)) {
26
+ // const classTransforms: IFileExtract<T>[] = [];
27
+ // for (const val of value) {
28
+ // await this.validate(val);
29
+ // const classTransform: T[] = await this.transformExtract(
30
+ // this.dto,
31
+ // val.extract,
32
+ // );
33
+ // await this.validateExtract(classTransform, val.filename);
34
+ // const classTransformMerge: IFileExtract<T> = await this.transformMerge(
35
+ // val,
36
+ // classTransform,
37
+ // );
38
+ // classTransforms.push(classTransformMerge);
39
+ // }
40
+ // return classTransforms;
41
+ // }
42
+ // const file: IFileExtract<T> = value as IFileExtract<T>;
43
+ // await this.validate(file);
44
+ // const classTransform: T[] = await this.transformExtract(
45
+ // this.dto,
46
+ // file.extract,
47
+ // );
48
+ // await this.validateExtract(classTransform, file.filename);
49
+ // return this.transformMerge(value, classTransform);
50
+ // }
51
+ // async transformMerge(
52
+ // value: IFileExtract,
53
+ // classTransform: T[],
54
+ // ): Promise<IFileExtract<T>> {
55
+ // return {
56
+ // ...value,
57
+ // dto: classTransform,
58
+ // };
59
+ // }
60
+ // async transformExtract(
61
+ // classDtos: ClassConstructor<T>,
62
+ // extract: Record<string, any>[],
63
+ // ): Promise<T[]> {
64
+ // return plainToInstance(classDtos, extract);
65
+ // }
66
+ // async validate(value: IFileExtract): Promise<void> {
67
+ // if (
68
+ // !Object.values(ENUM_FILE_EXCEL_MIME).find(
69
+ // (val) => val === value.mimetype.toLowerCase(),
70
+ // )
71
+ // ) {
72
+ // throw new Api415UnsupportedMediaTypeError({ mediaType: value.mimetype });
73
+ // } else if (!value.extract) {
74
+ // throw new Api422FileNeedExtractFirstError();
75
+ // }
76
+ // return;
77
+ // }
78
+ // async validateExtract(classTransform: T[], filename: string): Promise<void> {
79
+ // const errors: IValidationErrorImport[] = [];
80
+ // for (const [index, clsTransform] of classTransform.entries()) {
81
+ // const validator: ValidationError[] = await validate(
82
+ // clsTransform as Record<string, any>,
83
+ // );
84
+ // if (validator.length > 0) {
85
+ // errors.push({
86
+ // row: index,
87
+ // file: filename,
88
+ // errors: validator,
89
+ // });
90
+ // }
91
+ // }
92
+ // if (errors.length > 0) {
93
+ // throw new Api422ValidationError(errors);
94
+ // }
95
+ // return;
96
+ // }
97
+ // }
98
+ //# sourceMappingURL=file.validation.pipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.validation.pipe.js","sourceRoot":"","sources":["../../../../../packages/file/src/pipes/file.validation.pipe.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,6DAA6D;AAC7D,+DAA+D;AAC/D,yEAAyE;AACzE,WAAW;AACX,qCAAqC;AACrC,qCAAqC;AACrC,2BAA2B;AAC3B,4BAA4B;AAC5B,4BAA4B;AAC5B,uDAAuD;AACvD,+DAA+D;AAE/D,oBAAoB;AACpB,oCAAoC;AACpC,gBAAgB;AAChB,gEAAgE;AAChE,8DAA8D;AAE9D,qBAAqB;AACrB,kDAAkD;AAClD,sDAAsD;AACtD,oBAAoB;AACpB,gBAAgB;AAChB,QAAQ;AAER,kCAAkC;AAClC,uDAAuD;AACvD,mCAAmC;AACnC,oCAAoC;AAEpC,mEAAmE;AACnE,sBAAsB;AACtB,yBAAyB;AACzB,aAAa;AAEb,oEAAoE;AAEpE,kFAAkF;AAClF,iBAAiB;AACjB,4BAA4B;AAC5B,aAAa;AACb,qDAAqD;AACrD,UAAU;AAEV,gCAAgC;AAChC,QAAQ;AAER,8DAA8D;AAC9D,iCAAiC;AAEjC,+DAA+D;AAC/D,kBAAkB;AAClB,sBAAsB;AACtB,SAAS;AAET,iEAAiE;AAEjE,yDAAyD;AACzD,MAAM;AAEN,0BAA0B;AAC1B,2BAA2B;AAC3B,2BAA2B;AAC3B,kCAAkC;AAClC,eAAe;AACf,kBAAkB;AAClB,6BAA6B;AAC7B,SAAS;AACT,MAAM;AAEN,4BAA4B;AAC5B,sCAAsC;AACtC,sCAAsC;AACtC,sBAAsB;AACtB,kDAAkD;AAClD,MAAM;AAEN,yDAAyD;AACzD,WAAW;AACX,mDAAmD;AACnD,yDAAyD;AACzD,UAAU;AACV,UAAU;AACV,kFAAkF;AAClF,mCAAmC;AACnC,qDAAqD;AACrD,QAAQ;AAER,cAAc;AACd,MAAM;AAEN,kFAAkF;AAClF,mDAAmD;AACnD,sEAAsE;AACtE,6DAA6D;AAC7D,+CAA+C;AAC/C,WAAW;AACX,oCAAoC;AACpC,wBAAwB;AACxB,wBAAwB;AACxB,4BAA4B;AAC5B,+BAA+B;AAC/B,cAAc;AACd,UAAU;AACV,QAAQ;AAER,+BAA+B;AAC/B,iDAAiD;AACjD,QAAQ;AAER,cAAc;AACd,MAAM;AACN,IAAI"}
@@ -0,0 +1,4 @@
1
+ export * from './file.max-files.pipe';
2
+ export * from './file.required.pipe';
3
+ export * from './file.size.pipe';
4
+ export * from './file.type.pipe';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ // export * from './file.extract.pipe';
5
+ tslib_1.__exportStar(require("./file.max-files.pipe"), exports);
6
+ tslib_1.__exportStar(require("./file.required.pipe"), exports);
7
+ tslib_1.__exportStar(require("./file.size.pipe"), exports);
8
+ tslib_1.__exportStar(require("./file.type.pipe"), exports);
9
+ // export * from './file.validation.pipe';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/file/src/pipes/index.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,gEAAsC;AACtC,+DAAqC;AACrC,2DAAiC;AACjC,2DAAiC;AACjC,0CAA0C"}