@liuhange/dsh-data-asset-shared 1.0.0 → 2.0.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.
package/lib/index.js CHANGED
@@ -1,6 +1,208 @@
1
1
  import * as fs from "fs";
2
2
  import * as path from "path";
3
3
  //#region lib/types/defaultBusinessRules.js
4
+ const defaultQualityScoringConfig = {
5
+ weights: {
6
+ completeness: .25,
7
+ accuracy: .25,
8
+ consistency: .25,
9
+ timeliness: .25
10
+ },
11
+ thresholds: {
12
+ completeness: 60,
13
+ accuracy: 60,
14
+ consistency: 60,
15
+ timeliness: 60
16
+ },
17
+ completeness: { missingMarkers: [
18
+ "null",
19
+ "undefined",
20
+ "N/A",
21
+ "",
22
+ "NULL",
23
+ "NaN"
24
+ ] },
25
+ accuracy: {
26
+ formatRules: [{
27
+ fieldName: "phone",
28
+ pattern: "1[3-9]\\d{9}",
29
+ weight: .5
30
+ }, {
31
+ fieldName: "email",
32
+ pattern: "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
33
+ weight: .5
34
+ }],
35
+ domainRules: [{
36
+ fieldName: "age",
37
+ min: 0,
38
+ max: 150,
39
+ weight: .5
40
+ }, {
41
+ fieldName: "score",
42
+ min: 0,
43
+ max: 100,
44
+ weight: .5
45
+ }]
46
+ },
47
+ consistency: { crossFieldRules: [{
48
+ name: "endDateAfterStartDate",
49
+ fields: ["startDate", "endDate"],
50
+ constraint: "after"
51
+ }] },
52
+ timeliness: {
53
+ timestampField: "updatedAt",
54
+ freshnessThresholdHours: 720
55
+ }
56
+ };
57
+ const defaultLineageConfig = {
58
+ enabled: false,
59
+ storagePath: "lineage",
60
+ hashAlgorithm: "SHA-256"
61
+ };
62
+ const defaultAdvancedMaskingConfig = {
63
+ defaultAlgorithm: "hash",
64
+ fieldAlgorithms: {},
65
+ fpe: {
66
+ key: "",
67
+ radix: 10
68
+ },
69
+ kAnonymity: {
70
+ kValue: 2,
71
+ quasiIdentifiers: [
72
+ "zipCode",
73
+ "age",
74
+ "gender"
75
+ ]
76
+ },
77
+ differentialPrivacy: {
78
+ epsilon: 1,
79
+ totalBudget: 5,
80
+ sensitivity: 1
81
+ },
82
+ hash: {
83
+ algorithm: "SHA-256",
84
+ salt: ""
85
+ }
86
+ };
87
+ const defaultVisualizationConfig = {
88
+ charts: {
89
+ bar: {
90
+ enabled: true,
91
+ title: "脱敏统计"
92
+ },
93
+ comparison: {
94
+ enabled: true,
95
+ title: "清洗前后对比"
96
+ },
97
+ pie: {
98
+ enabled: true,
99
+ title: "数据资产分布"
100
+ },
101
+ radar: {
102
+ enabled: true,
103
+ title: "质量评分"
104
+ },
105
+ flowchart: {
106
+ enabled: true,
107
+ title: "血缘追踪"
108
+ }
109
+ },
110
+ layout: {
111
+ columns: 2,
112
+ responsive: true
113
+ },
114
+ colorScheme: {
115
+ primary: "#4A90D9",
116
+ secondary: "#F5A623",
117
+ success: "#7ED321",
118
+ warning: "#F8E71C",
119
+ danger: "#D0021B",
120
+ background: "#F5F5F5",
121
+ text: "#333333"
122
+ },
123
+ interactions: {
124
+ expandCollapse: true,
125
+ chartSwitch: true,
126
+ tooltip: true
127
+ },
128
+ templateVersion: "1.0"
129
+ };
130
+ const defaultSensitivityClassificationConfig = {
131
+ fieldNameRules: [
132
+ {
133
+ name: "idCard",
134
+ pattern: "id_?card|身份证|identity",
135
+ level: "Secret"
136
+ },
137
+ {
138
+ name: "phone",
139
+ pattern: "phone|手机|mobile|tel",
140
+ level: "Confidential"
141
+ },
142
+ {
143
+ name: "email",
144
+ pattern: "email|邮箱|mail",
145
+ level: "Confidential"
146
+ },
147
+ {
148
+ name: "bankCard",
149
+ pattern: "bank_?card|银行卡|account",
150
+ level: "Secret"
151
+ },
152
+ {
153
+ name: "address",
154
+ pattern: "address|地址|addr",
155
+ level: "Internal"
156
+ },
157
+ {
158
+ name: "name",
159
+ pattern: "^name$|姓名|username",
160
+ level: "Internal"
161
+ },
162
+ {
163
+ name: "public",
164
+ pattern: "status|type|category|label|tag|level",
165
+ level: "Public"
166
+ }
167
+ ],
168
+ fieldValueRules: [
169
+ {
170
+ name: "idCardValue",
171
+ pattern: "[1-9]\\d{5}(18|19|20)?\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[\\dXx]",
172
+ level: "Secret"
173
+ },
174
+ {
175
+ name: "phoneValue",
176
+ pattern: "1[3-9]\\d{9}",
177
+ level: "Confidential"
178
+ },
179
+ {
180
+ name: "emailValue",
181
+ pattern: "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
182
+ level: "Confidential"
183
+ },
184
+ {
185
+ name: "bankCardValue",
186
+ pattern: "[1-9]\\d{15,18}",
187
+ level: "Secret"
188
+ }
189
+ ],
190
+ levelMapping: {
191
+ Public: "none",
192
+ Internal: "partial",
193
+ Confidential: "full",
194
+ Secret: "encrypt"
195
+ },
196
+ defaultLevel: "Internal"
197
+ };
198
+ const defaultIncrementalSchedulingConfig = {
199
+ incrementalMode: false,
200
+ cronExpression: "0 2 * * *",
201
+ hashAlgorithm: "SHA-256",
202
+ watchDirectory: "input",
203
+ stateFilePath: "state/incremental-state.json",
204
+ lockTimeout: 3600
205
+ };
4
206
  const defaultBusinessRules = {
5
207
  version: "1.0",
6
208
  lastUpdated: "2026-08-17",
@@ -322,26 +524,26 @@ var ReportGenerator = class {
322
524
  - 原始行数:${params.originalLineCount}
323
525
  - 去重后行数:${params.originalLineCount - params.duplicateRemoved}(删除 ${params.duplicateRemoved} 行重复)
324
526
  `;
325
- if (params.standardizeApplied) report += `- 格式标准化:✅ 完成\n`;
527
+ if (params.standardizeApplied) report += "- 格式标准化:✅ 完成\n";
326
528
  report += `- 异常值检测:发现 ${params.anomalyTotalCount} 个异常\n`;
327
529
  if (params.anomalies.length > 0) {
328
530
  const anomalyText = params.anomalies.slice(0, 5).map((a) => `行${a.line}: ${a.reason}`).join(";");
329
531
  report += ` 异常详情:${anomalyText}`;
330
532
  if (params.anomalyTotalCount > 5) report += `...等${params.anomalyTotalCount}项`;
331
- report += `\n`;
533
+ report += "\n";
332
534
  }
333
535
  report += `- 输出文件:${params.outputPath}\n- 状态:✅ 完成`;
334
536
  return report;
335
537
  }
336
538
  generateInventoryReport(params) {
337
539
  let report = `【数据资产盘点报告】\n- 目录:${params.directory}\n- 发现数据文件:${params.fileCount} 个\n\n`;
338
- report += `| 文件名 | 大小 | 类型 | 价值评估 | 说明 |\n`;
339
- report += `|--------|------|------|----------|------|\n`;
540
+ report += "| 文件名 | 大小 | 类型 | 价值评估 | 说明 |\n";
541
+ report += "|--------|------|------|----------|------|\n";
340
542
  for (const item of params.assetItems) report += `| ${item.fileName} | ${item.size} | ${item.type} | ${item.valueAssessment} | ${item.description} |\n`;
341
- report += `\n---\n【建议】\n`;
342
- report += `1. 高价值数据(★★★★★)建议优先进行清洗和脱敏后交易\n`;
343
- report += `2. 低价值数据建议评估是否值得投入处理成本\n`;
344
- report += `3. 所有数据交易前必须完成合规审查\n`;
543
+ report += "\n---\n【建议】\n";
544
+ report += "1. 高价值数据(★★★★★)建议优先进行清洗和脱敏后交易\n";
545
+ report += "2. 低价值数据建议评估是否值得投入处理成本\n";
546
+ report += "3. 所有数据交易前必须完成合规审查\n";
345
547
  return report;
346
548
  }
347
549
  generatePackagingManual(params) {
@@ -412,4 +614,4 @@ var AuditLogger = class {
412
614
  }
413
615
  };
414
616
  //#endregion
415
- export { AuditLogger, BusinessRulesLoader, FileFormatAdapter, PathValidator, ReportGenerator, defaultBusinessRules };
617
+ export { AuditLogger, BusinessRulesLoader, FileFormatAdapter, PathValidator, ReportGenerator, defaultAdvancedMaskingConfig, defaultBusinessRules, defaultIncrementalSchedulingConfig, defaultLineageConfig, defaultQualityScoringConfig, defaultSensitivityClassificationConfig, defaultVisualizationConfig };
@@ -1,3 +1,140 @@
1
1
  import type { BusinessRulesConfig } from './types.js';
2
+ export declare const defaultQualityScoringConfig: {
3
+ weights: {
4
+ completeness: number;
5
+ accuracy: number;
6
+ consistency: number;
7
+ timeliness: number;
8
+ };
9
+ thresholds: {
10
+ completeness: number;
11
+ accuracy: number;
12
+ consistency: number;
13
+ timeliness: number;
14
+ };
15
+ completeness: {
16
+ missingMarkers: string[];
17
+ };
18
+ accuracy: {
19
+ formatRules: {
20
+ fieldName: string;
21
+ pattern: string;
22
+ weight: number;
23
+ }[];
24
+ domainRules: {
25
+ fieldName: string;
26
+ min: number;
27
+ max: number;
28
+ weight: number;
29
+ }[];
30
+ };
31
+ consistency: {
32
+ crossFieldRules: {
33
+ name: string;
34
+ fields: string[];
35
+ constraint: string;
36
+ }[];
37
+ };
38
+ timeliness: {
39
+ timestampField: string;
40
+ freshnessThresholdHours: number;
41
+ };
42
+ };
43
+ export declare const defaultLineageConfig: {
44
+ enabled: boolean;
45
+ storagePath: string;
46
+ hashAlgorithm: string;
47
+ };
48
+ export declare const defaultAdvancedMaskingConfig: {
49
+ defaultAlgorithm: string;
50
+ fieldAlgorithms: {};
51
+ fpe: {
52
+ key: string;
53
+ radix: number;
54
+ };
55
+ kAnonymity: {
56
+ kValue: number;
57
+ quasiIdentifiers: string[];
58
+ };
59
+ differentialPrivacy: {
60
+ epsilon: number;
61
+ totalBudget: number;
62
+ sensitivity: number;
63
+ };
64
+ hash: {
65
+ algorithm: string;
66
+ salt: string;
67
+ };
68
+ };
69
+ export declare const defaultVisualizationConfig: {
70
+ charts: {
71
+ bar: {
72
+ enabled: boolean;
73
+ title: string;
74
+ };
75
+ comparison: {
76
+ enabled: boolean;
77
+ title: string;
78
+ };
79
+ pie: {
80
+ enabled: boolean;
81
+ title: string;
82
+ };
83
+ radar: {
84
+ enabled: boolean;
85
+ title: string;
86
+ };
87
+ flowchart: {
88
+ enabled: boolean;
89
+ title: string;
90
+ };
91
+ };
92
+ layout: {
93
+ columns: number;
94
+ responsive: boolean;
95
+ };
96
+ colorScheme: {
97
+ primary: string;
98
+ secondary: string;
99
+ success: string;
100
+ warning: string;
101
+ danger: string;
102
+ background: string;
103
+ text: string;
104
+ };
105
+ interactions: {
106
+ expandCollapse: boolean;
107
+ chartSwitch: boolean;
108
+ tooltip: boolean;
109
+ };
110
+ templateVersion: string;
111
+ };
112
+ export declare const defaultSensitivityClassificationConfig: {
113
+ fieldNameRules: {
114
+ name: string;
115
+ pattern: string;
116
+ level: string;
117
+ }[];
118
+ fieldValueRules: {
119
+ name: string;
120
+ pattern: string;
121
+ level: string;
122
+ }[];
123
+ levelMapping: {
124
+ Public: string;
125
+ Internal: string;
126
+ Confidential: string;
127
+ Secret: string;
128
+ };
129
+ defaultLevel: string;
130
+ };
131
+ export declare const defaultIncrementalSchedulingConfig: {
132
+ incrementalMode: boolean;
133
+ cronExpression: string;
134
+ hashAlgorithm: string;
135
+ watchDirectory: string;
136
+ stateFilePath: string;
137
+ lockTimeout: number;
138
+ };
2
139
  export declare const defaultBusinessRules: BusinessRulesConfig;
3
140
  //# sourceMappingURL=defaultBusinessRules.d.ts.map
@@ -1,5 +1,6 @@
1
1
  export * from './types.js';
2
2
  export { defaultBusinessRules } from './defaultBusinessRules.js';
3
+ export { defaultQualityScoringConfig, defaultLineageConfig, defaultAdvancedMaskingConfig, defaultVisualizationConfig, defaultSensitivityClassificationConfig, defaultIncrementalSchedulingConfig, } from './defaultBusinessRules.js';
3
4
  export { BusinessRulesLoader } from './businessRulesLoader.js';
4
5
  export { FileFormatAdapter } from './fileFormatAdapter.js';
5
6
  export type { FileReadResult } from './fileFormatAdapter.js';
@@ -76,6 +76,12 @@ export interface BusinessRulesConfig {
76
76
  cleaningRules: CleaningRules;
77
77
  compliance: ComplianceConfig;
78
78
  packaging: PackagingRules;
79
+ qualityScoring?: QualityScoringConfig;
80
+ lineage?: LineageConfig;
81
+ advancedMasking?: AdvancedMaskingConfig;
82
+ visualization?: VisualizationConfig;
83
+ sensitivityClassification?: SensitivityClassificationConfig;
84
+ incrementalScheduling?: IncrementalSchedulingConfig;
79
85
  }
80
86
  export interface SensitiveField {
81
87
  type: SensitiveFieldType;
@@ -132,4 +138,141 @@ export interface BusinessRulesLoadResult {
132
138
  config: BusinessRulesConfig;
133
139
  status: ConfigStatus;
134
140
  }
141
+ export interface QualityScoringWeights {
142
+ completeness: number;
143
+ accuracy: number;
144
+ consistency: number;
145
+ timeliness: number;
146
+ }
147
+ export interface QualityScoringThresholds {
148
+ completeness: number;
149
+ accuracy: number;
150
+ consistency: number;
151
+ timeliness: number;
152
+ }
153
+ export interface CompletenessConfig {
154
+ missingMarkers: string[];
155
+ }
156
+ export interface FormatRule {
157
+ fieldName: string;
158
+ pattern: string;
159
+ weight: number;
160
+ }
161
+ export interface DomainRule {
162
+ fieldName: string;
163
+ min?: number;
164
+ max?: number;
165
+ allowedValues?: unknown[];
166
+ weight: number;
167
+ }
168
+ export interface AccuracyConfig {
169
+ formatRules: FormatRule[];
170
+ domainRules: DomainRule[];
171
+ }
172
+ export interface CrossFieldRule {
173
+ name: string;
174
+ fields: string[];
175
+ constraint: string;
176
+ value?: unknown;
177
+ }
178
+ export interface ConsistencyConfig {
179
+ crossFieldRules: CrossFieldRule[];
180
+ }
181
+ export interface TimelinessConfig {
182
+ timestampField: string;
183
+ freshnessThresholdHours: number;
184
+ }
185
+ export interface QualityScoringConfig {
186
+ weights: QualityScoringWeights;
187
+ thresholds: QualityScoringThresholds;
188
+ completeness: CompletenessConfig;
189
+ accuracy: AccuracyConfig;
190
+ consistency: ConsistencyConfig;
191
+ timeliness: TimelinessConfig;
192
+ }
193
+ export interface LineageConfig {
194
+ enabled: boolean;
195
+ storagePath: string;
196
+ hashAlgorithm: string;
197
+ }
198
+ export interface FpeConfig {
199
+ key: string;
200
+ radix: number;
201
+ }
202
+ export interface KAnonymityConfig {
203
+ kValue: number;
204
+ quasiIdentifiers: string[];
205
+ }
206
+ export interface DifferentialPrivacyConfig {
207
+ epsilon: number;
208
+ totalBudget: number;
209
+ sensitivity: number;
210
+ }
211
+ export interface HashMaskingConfig {
212
+ algorithm: string;
213
+ salt: string;
214
+ }
215
+ export interface AdvancedMaskingConfig {
216
+ defaultAlgorithm: string;
217
+ fieldAlgorithms: Record<string, {
218
+ algorithm: string;
219
+ }>;
220
+ fpe: FpeConfig;
221
+ kAnonymity: KAnonymityConfig;
222
+ differentialPrivacy: DifferentialPrivacyConfig;
223
+ hash: HashMaskingConfig;
224
+ }
225
+ export interface ChartConfig {
226
+ enabled: boolean;
227
+ title: string;
228
+ }
229
+ export interface VisualizationLayoutConfig {
230
+ columns: number;
231
+ responsive: boolean;
232
+ }
233
+ export interface ColorSchemeConfig {
234
+ primary: string;
235
+ secondary: string;
236
+ success: string;
237
+ warning: string;
238
+ danger: string;
239
+ background: string;
240
+ text: string;
241
+ }
242
+ export interface InteractionsConfig {
243
+ expandCollapse: boolean;
244
+ chartSwitch: boolean;
245
+ tooltip: boolean;
246
+ }
247
+ export interface VisualizationConfig {
248
+ charts: Record<string, ChartConfig>;
249
+ layout: VisualizationLayoutConfig;
250
+ colorScheme: ColorSchemeConfig;
251
+ interactions: InteractionsConfig;
252
+ templateVersion: string;
253
+ }
254
+ export interface FieldNameRule {
255
+ name: string;
256
+ pattern: string;
257
+ level: string;
258
+ }
259
+ export interface FieldValueRule {
260
+ name: string;
261
+ pattern: string;
262
+ level: string;
263
+ }
264
+ export interface SensitivityClassificationConfig {
265
+ fieldNameRules: FieldNameRule[];
266
+ fieldValueRules: FieldValueRule[];
267
+ levelMapping: Record<string, string>;
268
+ defaultLevel: string;
269
+ }
270
+ export interface IncrementalSchedulingConfig {
271
+ incrementalMode: boolean;
272
+ cronExpression: string;
273
+ hashAlgorithm: string;
274
+ watchDirectory: string;
275
+ stateFilePath: string;
276
+ lockTimeout: number;
277
+ }
135
278
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
1
  {
2
- "name": "@liuhange/dsh-data-asset-shared",
3
- "description": "Shared infrastructure for data assetization plugins: business rules loader, file format adapter, report generator, path validator, audit logger",
4
- "version": "1.0.0",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
11
- "directory": "packages/data-asset/data-asset-shared"
12
- },
13
- "type": "module",
14
- "main": "lib/index.js",
15
- "types": "lib/types/index.d.ts",
16
- "exports": {
17
- ".": {
18
- "types": "./lib/types/index.d.ts",
19
- "default": "./lib/index.js"
20
- },
21
- "./invariant": {
22
- "types": "./lib/types/invariant.d.ts",
23
- "default": "./lib/invariant.js"
24
- },
25
- "./src/*": "./src/*",
26
- "./package.json": "./package.json"
27
- },
28
- "files": [
29
- "lib/index.js",
30
- "lib/invariant.js",
31
- "lib/types/**/*.d.ts"
32
- ],
33
- "license": "MIT",
34
- "dependencies": {
35
- "csv-parse": "^5.5.0"
36
- },
37
- "peerDependencies": {
38
- "@deepseek-ai/cordis": "^0.1.0",
39
- "@deepseek-ai/dsh-tools": "^0.1.0",
40
- "@deepseek-ai/schemastery": "^0.1.0"
41
- }
2
+ "name": "@liuhange/dsh-data-asset-shared",
3
+ "description": "Shared infrastructure for data assetization plugins: business rules loader, file format adapter, report generator, path validator, audit logger",
4
+ "version": "2.0.1",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
11
+ "directory": "packages/data-asset/data-asset-shared"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./invariant": {
22
+ "types": "./lib/types/invariant.d.ts",
23
+ "default": "./lib/invariant.js"
24
+ },
25
+ "./src/*": "./src/*",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "lib/index.js",
30
+ "lib/invariant.js",
31
+ "lib/types/**/*.d.ts"
32
+ ],
33
+ "license": "MIT",
34
+ "dependencies": {
35
+ "csv-parse": "^5.5.0"
36
+ },
37
+ "peerDependencies": {
38
+ "@deepseek-ai/cordis": "^0.1.0",
39
+ "@deepseek-ai/dsh-tools": "^0.1.0",
40
+ "@deepseek-ai/schemastery": "^0.1.0"
41
+ }
42
42
  }