@nest-omni/core 4.1.3-12 → 4.1.3-14

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 (72) hide show
  1. package/cache/dependencies/db.dependency.d.ts +55 -6
  2. package/cache/dependencies/db.dependency.js +64 -13
  3. package/common/boilerplate.polyfill.js +1 -1
  4. package/file-upload/decorators/column.decorator.d.ts +151 -0
  5. package/file-upload/decorators/column.decorator.js +273 -0
  6. package/file-upload/decorators/csv-data.decorator.d.ts +17 -31
  7. package/file-upload/decorators/csv-data.decorator.js +45 -91
  8. package/file-upload/decorators/csv-import.decorator.d.ts +34 -0
  9. package/file-upload/decorators/csv-import.decorator.js +24 -0
  10. package/file-upload/decorators/examples/column-mapping.example.d.ts +76 -0
  11. package/file-upload/decorators/examples/column-mapping.example.js +122 -0
  12. package/file-upload/decorators/excel-data.decorator.d.ts +15 -29
  13. package/file-upload/decorators/excel-data.decorator.js +42 -82
  14. package/file-upload/decorators/index.d.ts +3 -2
  15. package/file-upload/decorators/index.js +20 -2
  16. package/file-upload/decorators/validate-data.decorator.d.ts +91 -0
  17. package/file-upload/decorators/validate-data.decorator.js +39 -0
  18. package/file-upload/dto/update-file.dto.d.ts +0 -1
  19. package/file-upload/dto/update-file.dto.js +0 -4
  20. package/file-upload/entities/file-metadata.entity.d.ts +6 -3
  21. package/file-upload/entities/file-metadata.entity.js +2 -10
  22. package/file-upload/entities/file.entity.d.ts +3 -18
  23. package/file-upload/entities/file.entity.js +0 -34
  24. package/file-upload/file-upload.module.d.ts +1 -1
  25. package/file-upload/file-upload.module.js +44 -16
  26. package/file-upload/index.d.ts +13 -2
  27. package/file-upload/index.js +21 -3
  28. package/file-upload/interceptors/file-upload.interceptor.d.ts +61 -8
  29. package/file-upload/interceptors/file-upload.interceptor.js +417 -257
  30. package/file-upload/interfaces/file-processor.interface.d.ts +93 -0
  31. package/file-upload/interfaces/file-processor.interface.js +2 -0
  32. package/file-upload/interfaces/file-upload-options.interface.d.ts +3 -46
  33. package/file-upload/interfaces/file-upload-options.interface.js +3 -0
  34. package/file-upload/interfaces/processor-options.interface.d.ts +102 -0
  35. package/file-upload/interfaces/processor-options.interface.js +2 -0
  36. package/file-upload/processors/csv.processor.d.ts +98 -0
  37. package/file-upload/processors/csv.processor.js +391 -0
  38. package/file-upload/processors/excel.processor.d.ts +130 -0
  39. package/file-upload/processors/excel.processor.js +547 -0
  40. package/file-upload/processors/image.processor.d.ts +199 -0
  41. package/file-upload/processors/image.processor.js +377 -0
  42. package/file-upload/services/file.service.d.ts +3 -0
  43. package/file-upload/services/file.service.js +39 -10
  44. package/file-upload/services/malicious-file-detector.service.d.ts +29 -3
  45. package/file-upload/services/malicious-file-detector.service.js +256 -57
  46. package/file-upload/utils/dynamic-import.util.d.ts +6 -2
  47. package/file-upload/utils/dynamic-import.util.js +17 -5
  48. package/http-client/decorators/http-client.decorators.d.ts +4 -2
  49. package/http-client/decorators/http-client.decorators.js +2 -1
  50. package/http-client/entities/http-log.entity.js +1 -9
  51. package/http-client/examples/proxy-from-environment.example.d.ts +133 -0
  52. package/http-client/examples/proxy-from-environment.example.js +410 -0
  53. package/http-client/http-client.module.js +65 -6
  54. package/http-client/interfaces/http-client-config.interface.d.ts +6 -0
  55. package/http-client/services/http-client.service.d.ts +8 -0
  56. package/http-client/services/http-client.service.js +61 -17
  57. package/http-client/services/logging.service.d.ts +1 -1
  58. package/http-client/services/logging.service.js +74 -58
  59. package/http-client/utils/index.d.ts +1 -0
  60. package/http-client/utils/index.js +1 -0
  61. package/http-client/utils/proxy-environment.util.d.ts +42 -0
  62. package/http-client/utils/proxy-environment.util.js +148 -0
  63. package/package.json +9 -5
  64. package/shared/service-registry.module.js +18 -0
  65. package/transaction/data-source.util.d.ts +142 -0
  66. package/transaction/data-source.util.js +330 -0
  67. package/transaction/index.d.ts +1 -0
  68. package/transaction/index.js +12 -1
  69. package/validators/is-exists.validator.d.ts +19 -2
  70. package/validators/is-exists.validator.js +27 -2
  71. package/validators/is-unique.validator.d.ts +12 -1
  72. package/validators/is-unique.validator.js +26 -1
@@ -0,0 +1,93 @@
1
+ import { FileEntity } from './file-entity.interface';
2
+ import { ProcessOptions, ProcessResult } from './processor-options.interface';
3
+ /**
4
+ * 文件处理器基础接口
5
+ */
6
+ export interface IFileProcessor {
7
+ /** 处理器名称 */
8
+ readonly name: string;
9
+ /** 支持的MIME类型 */
10
+ readonly supportedTypes: string[];
11
+ /**
12
+ * 验证文件是否可以被此处理器处理
13
+ * @param buffer 文件缓冲区
14
+ * @returns 是否支持
15
+ */
16
+ validate(buffer: Buffer): Promise<boolean>;
17
+ /**
18
+ * 处理文件
19
+ * @param file 文件实体
20
+ * @param options 处理选项
21
+ * @returns 处理结果
22
+ */
23
+ process(file: FileEntity, options: ProcessOptions): Promise<ProcessResult>;
24
+ /**
25
+ * 获取处理器信息(可选)
26
+ */
27
+ getInfo?(): ProcessorInfo;
28
+ /**
29
+ * 清理资源(可选)
30
+ */
31
+ cleanup?(): Promise<void>;
32
+ /**
33
+ * 健康检查(可选)
34
+ */
35
+ healthCheck?(): Promise<boolean>;
36
+ }
37
+ /**
38
+ * 处理器信息
39
+ */
40
+ export interface ProcessorInfo {
41
+ /** 处理器名称 */
42
+ name: string;
43
+ /** 处理器版本 */
44
+ version: string;
45
+ /** 处理器描述 */
46
+ description: string;
47
+ /** 支持的文件类型 */
48
+ supportedTypes: string[];
49
+ /** 支持的文件扩展名 */
50
+ supportedExtensions: string[];
51
+ /** 处理器能力 */
52
+ capabilities: ProcessorCapabilities;
53
+ /** 性能指标 */
54
+ performance?: {
55
+ /** 最大文件大小(字节) */
56
+ maxFileSize?: number;
57
+ /** 平均处理时间(毫秒/MB) */
58
+ avgProcessTime?: number;
59
+ /** 内存使用量(MB) */
60
+ memoryUsage?: number;
61
+ };
62
+ /** 配置选项 */
63
+ configOptions?: Record<string, {
64
+ type: string;
65
+ description: string;
66
+ required?: boolean;
67
+ default?: any;
68
+ enum?: any[];
69
+ }>;
70
+ }
71
+ /**
72
+ * 处理器能力
73
+ */
74
+ export interface ProcessorCapabilities {
75
+ /** 是否支持读取 */
76
+ read: boolean;
77
+ /** 是否支持写入 */
78
+ write: boolean;
79
+ /** 是否支持转换 */
80
+ transform: boolean;
81
+ /** 是否支持批量处理 */
82
+ batch: boolean;
83
+ /** 是否支持流式处理 */
84
+ stream: boolean;
85
+ /** 是否支持实时处理 */
86
+ realtime: boolean;
87
+ /** 是否支持并行处理 */
88
+ parallel: boolean;
89
+ /** 是否支持压缩 */
90
+ compress: boolean;
91
+ /** 是否支持加密 */
92
+ encrypt: boolean;
93
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -46,6 +46,8 @@ export interface FileUploadOptions {
46
46
  name: string;
47
47
  options?: any;
48
48
  };
49
+ /** 处理器选项(会与 processor.options 合并) */
50
+ processorOptions?: any;
49
51
  /** 存储提供者: 'local' | 's3' | 'oss' | 'minio' */
50
52
  storage?: string;
51
53
  /** 自定义存储路径 */
@@ -62,7 +64,7 @@ export interface UploadContext {
62
64
  /** 共享数据 */
63
65
  shared: Record<string, any>;
64
66
  /** 获取处理器 */
65
- getProcessor(name: string): IFileProcessor | null;
67
+ getProcessor(name: string): any | null;
66
68
  /** 保存文件元数据 */
67
69
  saveMetadata(fileId: string, metadata: any): Promise<void>;
68
70
  /** 获取当前用户 */
@@ -70,48 +72,3 @@ export interface UploadContext {
70
72
  /** 获取请求对象 */
71
73
  getRequest(): Request;
72
74
  }
73
- /**
74
- * 文件处理器接口
75
- */
76
- export interface IFileProcessor {
77
- /** 处理器名称 */
78
- name: string;
79
- /** 支持的文件类型 */
80
- supports: Array<FileType | string>;
81
- /** 处理文件 */
82
- process(file: Express.Multer.File, options?: any): Promise<any>;
83
- /** 验证文件(可选) */
84
- validate?(file: Express.Multer.File): Promise<boolean>;
85
- }
86
- /**
87
- * Excel 数据配置
88
- */
89
- export interface ExcelDataOptions {
90
- /** 工作表索引,默认 0 */
91
- sheetIndex?: number;
92
- /** 开始行,默认 1(跳过表头) */
93
- startRow?: number;
94
- /** 最大行数 */
95
- maxRows?: number;
96
- /** 解析前验证 */
97
- validateBeforeParse?: boolean;
98
- /** 遇到错误停止 */
99
- stopOnError?: boolean;
100
- }
101
- /**
102
- * CSV 数据配置
103
- */
104
- export interface CsvDataOptions {
105
- /** 分隔符,默认 ',' */
106
- delimiter?: ',' | ';' | '\t' | string;
107
- /** 引号字符,默认 '"' */
108
- quote?: string;
109
- /** 转义字符,默认 '"' */
110
- escape?: string;
111
- /** 跳过空行 */
112
- skipEmptyLines?: boolean;
113
- /** 跳过表头 */
114
- skipHeader?: boolean;
115
- /** 编码,默认 'utf8' */
116
- encoding?: 'utf8' | 'gbk' | 'gb2312' | string;
117
- }
@@ -1,2 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ // 注意:IFileProcessor 已移至 file-processor.interface.ts,避免重复定义
4
+ // 注意:ExcelDataOptions 已移至 excel-import.decorator.ts,避免重复定义
5
+ // 注意:CsvDataOptions 已移至 csv-import.decorator.ts,避免重复定义
@@ -0,0 +1,102 @@
1
+ /**
2
+ * 处理器通用选项
3
+ */
4
+ export interface ProcessOptions {
5
+ /** 文件存储路径或标识 */
6
+ storageKey?: string;
7
+ /** 是否异步处理 */
8
+ async?: boolean;
9
+ /** 超时时间(毫秒) */
10
+ timeout?: number;
11
+ /** 处理优先级 */
12
+ priority?: 'low' | 'normal' | 'high' | 'urgent';
13
+ /** 重试次数 */
14
+ retries?: number;
15
+ /** 是否保存中间结果 */
16
+ saveIntermediate?: boolean;
17
+ /** 处理标签 */
18
+ tags?: string[];
19
+ /** 处理完成后是否删除原文件 */
20
+ deleteAfterProcess?: boolean;
21
+ }
22
+ /**
23
+ * 处理器通用结果
24
+ */
25
+ export interface ProcessResult {
26
+ /** 是否成功 */
27
+ success: boolean;
28
+ /** 处理后的数据 */
29
+ data?: any;
30
+ /** 错误信息 */
31
+ error?: Error;
32
+ /**
33
+ * 要保存到 file_metadata 表的元数据
34
+ * 处理器可以通过返回这个字段来指定要保存的内容
35
+ * 如果不设置,将保存整个 result 对象
36
+ *
37
+ * @example
38
+ * // Excel/CSV 处理器示例
39
+ * return {
40
+ * success: true,
41
+ * data: parsedData,
42
+ * metadata: {
43
+ * data: parsedData,
44
+ * headers: ['col1', 'col2'],
45
+ * rowCount: 100,
46
+ * columnCount: 5,
47
+ * successCount: 98,
48
+ * errorCount: 2,
49
+ * }
50
+ * };
51
+ *
52
+ * @example
53
+ * // PDF 处理器示例
54
+ * return {
55
+ * success: true,
56
+ * data: extractedText,
57
+ * metadata: {
58
+ * text: extractedText,
59
+ * pageCount: 10,
60
+ * wordCount: 5000,
61
+ * language: 'en',
62
+ * }
63
+ * };
64
+ */
65
+ metadata?: Record<string, any>;
66
+ /** 其他元数据(旧字段,建议使用 metadata 字段) */
67
+ metadata_legacy?: {
68
+ /** 处理耗时(毫秒) */
69
+ duration?: number;
70
+ /** 处理器名称 */
71
+ processor?: string;
72
+ /** 处理时间 */
73
+ processedAt?: Date;
74
+ /** 文件大小 */
75
+ fileSize?: number;
76
+ /** 其他元数据 */
77
+ [key: string]: any;
78
+ };
79
+ /** 额外信息 */
80
+ extras?: {
81
+ /** 警告信息 */
82
+ warnings?: string[];
83
+ /** 建议操作 */
84
+ suggestions?: string[];
85
+ /** 关联的文件ID */
86
+ relatedFiles?: string[];
87
+ /** 处理日志 */
88
+ logs?: Array<{
89
+ timestamp: Date;
90
+ level: 'debug' | 'info' | 'warn' | 'error';
91
+ message: string;
92
+ data?: any;
93
+ }>;
94
+ /** 性能指标 */
95
+ metrics?: {
96
+ memoryUsage?: number;
97
+ cpuUsage?: number;
98
+ throughput?: number;
99
+ [key: string]: number;
100
+ };
101
+ };
102
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,98 @@
1
+ import { FileEntity } from '../interfaces';
2
+ import { IFileProcessor, ProcessorInfo } from '../interfaces/file-processor.interface';
3
+ import { ProcessOptions, ProcessResult } from '../interfaces/processor-options.interface';
4
+ /**
5
+ * CSV 处理器配置
6
+ */
7
+ export interface CsvProcessorOptions extends ProcessOptions {
8
+ /** 字段分隔符 */
9
+ delimiter?: string;
10
+ /** 引号字符 */
11
+ quote?: string;
12
+ /** 转义字符 */
13
+ escape?: string;
14
+ /** 是否有标题行 */
15
+ headers?: boolean;
16
+ /** 跳过空行数 */
17
+ skipLines?: number;
18
+ /** 跳过空字段 */
19
+ skipEmpty?: boolean;
20
+ /** 严格模式(字段数必须一致) */
21
+ strict?: boolean;
22
+ /** 修剪字段值 */
23
+ trim?: boolean;
24
+ /** 最大行数 */
25
+ maxRows?: number;
26
+ /** 编码 */
27
+ encoding?: string;
28
+ /** DTO类(用于装饰器映射) */
29
+ dto?: new () => any;
30
+ /** 是否使用装饰器映射 */
31
+ useDecorators?: boolean;
32
+ /** 是否将解析结果存入 file_metadata */
33
+ saveToMetadata?: boolean;
34
+ /** 元数据存储键名 */
35
+ metadataKey?: string;
36
+ }
37
+ /**
38
+ * CSV 处理结果
39
+ */
40
+ export interface CsvProcessResult extends ProcessResult {
41
+ /** CSV 数据 */
42
+ data: any[];
43
+ /** 表头(如果有) */
44
+ headers?: string[];
45
+ /** 行数 */
46
+ rowCount: number;
47
+ /** 列数 */
48
+ columnCount: number;
49
+ /** 错误信息 */
50
+ errors?: {
51
+ row: number;
52
+ errors: string[];
53
+ data: any;
54
+ }[];
55
+ /** 成功的行数 */
56
+ successCount?: number;
57
+ /** 失败的行数 */
58
+ errorCount?: number;
59
+ /** 原始数据(用于调试) */
60
+ rawRecords?: any[];
61
+ /** 是否已保存到元数据 */
62
+ savedToMetadata?: boolean;
63
+ /** 元数据存储键名 */
64
+ metadataKey?: string;
65
+ }
66
+ /**
67
+ * CSV 文件处理器
68
+ * 解析 CSV 文件并转换为 JSON 格式,支持装饰器映射
69
+ */
70
+ export declare class CsvProcessor implements IFileProcessor {
71
+ readonly name = "csv";
72
+ readonly supportedTypes: string[];
73
+ private readonly logger;
74
+ /**
75
+ * 验证是否为 CSV 文件
76
+ */
77
+ validate(buffer: Buffer): Promise<boolean>;
78
+ /**
79
+ * 处理CSV文件(流式处理优化版)
80
+ */
81
+ process(file: FileEntity, options?: CsvProcessorOptions): Promise<CsvProcessResult>;
82
+ /**
83
+ * 使用装饰器处理单行数据
84
+ */
85
+ private processRowWithDecorators;
86
+ /**
87
+ * 获取处理器信息
88
+ */
89
+ getInfo(): ProcessorInfo;
90
+ /**
91
+ * 健康检查
92
+ */
93
+ healthCheck(): Promise<boolean>;
94
+ /**
95
+ * 清理资源
96
+ */
97
+ cleanup(): Promise<void>;
98
+ }