@liuhange/dsh-data-inventory 1.0.0 → 2.0.2
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 +59 -143
- package/lib/invariant.js +4 -5
- package/lib/types/assetListGenerator.d.ts +2 -2
- package/lib/types/directoryScanner.d.ts +1 -1
- package/lib/types/valueAssessor.d.ts +1 -1
- package/package.json +10 -5
package/lib/index.js
CHANGED
|
@@ -1,144 +1,60 @@
|
|
|
1
|
-
import { defineTool } from
|
|
2
|
-
import * as fs from
|
|
3
|
-
import * as path from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
stars: rules.defaultValue.score,
|
|
60
|
-
label: rules.defaultValue.label,
|
|
61
|
-
recommendation: rules.defaultValue.recommendation
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region lib/types/assetListGenerator.js
|
|
67
|
-
var AssetListGenerator = class {
|
|
68
|
-
generate(files, valueAssessor, valueRules) {
|
|
69
|
-
return files.map((file) => {
|
|
70
|
-
const assessment = valueAssessor.assess(file.fileName, valueRules);
|
|
71
|
-
return {
|
|
72
|
-
fileName: file.fileName,
|
|
73
|
-
size: this.humanReadableSize(file.size),
|
|
74
|
-
type: file.format,
|
|
75
|
-
valueAssessment: assessment.label,
|
|
76
|
-
description: assessment.recommendation
|
|
77
|
-
};
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
humanReadableSize(bytes) {
|
|
81
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
82
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
83
|
-
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
84
|
-
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region lib/types/index.js
|
|
89
|
-
const name = "data-inventory";
|
|
90
|
-
const inject = ["tools"];
|
|
91
|
-
function apply(ctx) {
|
|
92
|
-
const loader = new BusinessRulesLoader();
|
|
93
|
-
const reportGenerator = new ReportGenerator();
|
|
94
|
-
const pathValidator = new PathValidator();
|
|
95
|
-
const auditLogger = new AuditLogger();
|
|
96
|
-
const directoryScanner = new DirectoryScanner();
|
|
97
|
-
const valueAssessor = new ValueAssessor();
|
|
98
|
-
const assetListGenerator = new AssetListGenerator();
|
|
99
|
-
ctx.tools.register(defineTool({
|
|
100
|
-
name: "inventory_data",
|
|
101
|
-
description: "盘点数据资产,生成资产清单和价值评估",
|
|
102
|
-
parameters: { directory: {
|
|
103
|
-
type: "string",
|
|
104
|
-
required: true,
|
|
105
|
-
description: "待盘点的目录路径"
|
|
106
|
-
} },
|
|
107
|
-
output: {
|
|
108
|
-
schema: { type: "string" },
|
|
109
|
-
render: (_args, value) => [{
|
|
110
|
-
type: "text",
|
|
111
|
-
text: value
|
|
112
|
-
}]
|
|
113
|
-
},
|
|
114
|
-
async execute(args) {
|
|
115
|
-
const { config } = loader.load();
|
|
116
|
-
const workingDir = process.cwd();
|
|
117
|
-
try {
|
|
118
|
-
pathValidator.validateDirectory(args.directory, workingDir);
|
|
119
|
-
} catch {
|
|
120
|
-
return `错误:路径不合法 - ${args.directory}`;
|
|
121
|
-
}
|
|
122
|
-
const dir = path.resolve(args.directory);
|
|
123
|
-
if (!fs.existsSync(dir)) return `错误:目录不存在 - ${dir}`;
|
|
124
|
-
const scanResult = directoryScanner.scan(dir);
|
|
125
|
-
const assetItems = assetListGenerator.generate(scanResult.files, valueAssessor, config.valueAssessment);
|
|
126
|
-
const report = reportGenerator.generateInventoryReport({
|
|
127
|
-
directory: dir,
|
|
128
|
-
fileCount: scanResult.files.length,
|
|
129
|
-
assetItems
|
|
130
|
-
});
|
|
131
|
-
auditLogger.log({
|
|
132
|
-
pluginName: "data-inventory",
|
|
133
|
-
operation: "inventory_data",
|
|
134
|
-
inputPath: dir,
|
|
135
|
-
outputPath: "-",
|
|
136
|
-
result: "SUCCESS"
|
|
137
|
-
});
|
|
138
|
-
return report;
|
|
139
|
-
}
|
|
140
|
-
}));
|
|
141
|
-
console.log("[data-inventory] 盘点插件已加载");
|
|
1
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { BusinessRulesLoader, ReportGenerator, PathValidator, AuditLogger, } from '@liuhange/dsh-data-asset-shared';
|
|
5
|
+
import { DirectoryScanner } from './directoryScanner.js';
|
|
6
|
+
import { ValueAssessor } from './valueAssessor.js';
|
|
7
|
+
import { AssetListGenerator } from './assetListGenerator.js';
|
|
8
|
+
export const name = 'data-inventory';
|
|
9
|
+
export const inject = ['tools'];
|
|
10
|
+
export function apply(ctx) {
|
|
11
|
+
const loader = new BusinessRulesLoader();
|
|
12
|
+
const reportGenerator = new ReportGenerator();
|
|
13
|
+
const pathValidator = new PathValidator();
|
|
14
|
+
const auditLogger = new AuditLogger();
|
|
15
|
+
const directoryScanner = new DirectoryScanner();
|
|
16
|
+
const valueAssessor = new ValueAssessor();
|
|
17
|
+
const assetListGenerator = new AssetListGenerator();
|
|
18
|
+
ctx.tools.register(defineTool({
|
|
19
|
+
name: 'inventory_data',
|
|
20
|
+
description: '盘点数据资产,生成资产清单和价值评估',
|
|
21
|
+
parameters: {
|
|
22
|
+
directory: { type: 'string', required: true, description: '待盘点的目录路径' },
|
|
23
|
+
},
|
|
24
|
+
output: {
|
|
25
|
+
schema: { type: 'string' },
|
|
26
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
27
|
+
},
|
|
28
|
+
async execute(args) {
|
|
29
|
+
const { config } = loader.load();
|
|
30
|
+
const workingDir = process.cwd();
|
|
31
|
+
try {
|
|
32
|
+
pathValidator.validateDirectory(args.directory, workingDir);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return `错误:路径不合法 - ${args.directory}`;
|
|
36
|
+
}
|
|
37
|
+
const dir = path.resolve(args.directory);
|
|
38
|
+
if (!fs.existsSync(dir)) {
|
|
39
|
+
return `错误:目录不存在 - ${dir}`;
|
|
40
|
+
}
|
|
41
|
+
const scanResult = directoryScanner.scan(dir);
|
|
42
|
+
const assetItems = assetListGenerator.generate(scanResult.files, valueAssessor, config.valueAssessment);
|
|
43
|
+
const report = reportGenerator.generateInventoryReport({
|
|
44
|
+
directory: dir,
|
|
45
|
+
fileCount: scanResult.files.length,
|
|
46
|
+
assetItems,
|
|
47
|
+
});
|
|
48
|
+
auditLogger.log({
|
|
49
|
+
pluginName: 'data-inventory',
|
|
50
|
+
operation: 'inventory_data',
|
|
51
|
+
inputPath: dir,
|
|
52
|
+
outputPath: '-',
|
|
53
|
+
result: 'SUCCESS',
|
|
54
|
+
});
|
|
55
|
+
return report;
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
58
|
+
console.log('[data-inventory] 盘点插件已加载');
|
|
142
59
|
}
|
|
143
|
-
//#
|
|
144
|
-
export { apply, inject, name };
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
package/lib/invariant.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#
|
|
5
|
-
export { install, invariant };
|
|
1
|
+
export const invariant = 'data-inventory';
|
|
2
|
+
export function install() {
|
|
3
|
+
}
|
|
4
|
+
//# sourceMappingURL=invariant.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AssetItem, DataFile } from '@
|
|
1
|
+
import type { AssetItem, DataFile } from '@liuhange/dsh-data-asset-shared';
|
|
2
2
|
import type { ValueAssessor } from './valueAssessor.js';
|
|
3
3
|
export declare class AssetListGenerator {
|
|
4
|
-
generate(files: DataFile[], valueAssessor: ValueAssessor, valueRules: import('@
|
|
4
|
+
generate(files: DataFile[], valueAssessor: ValueAssessor, valueRules: import('@liuhange/dsh-data-asset-shared').ValueAssessmentRules): AssetItem[];
|
|
5
5
|
humanReadableSize(bytes: number): string;
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=assetListGenerator.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liuhange/dsh-data-inventory",
|
|
3
3
|
"description": "Data inventory plugin: directory scanning, value assessment, asset list generation",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.2",
|
|
5
5
|
"publishConfig": { "access": "public" },
|
|
6
|
-
"repository": { "type": "git", "url": "git+https://github.com/
|
|
6
|
+
"repository": { "type": "git", "url": "git+https://github.com/liuhange789/data-asset-inspector.git", "directory": "packages/data-asset/data-inventory" },
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"types": "lib/types/index.d.ts",
|
|
@@ -15,9 +15,14 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": ["lib/index.js", "lib/invariant.js", "lib/types/**/*.d.ts"],
|
|
17
17
|
"license": "MIT",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"build": "tsc"
|
|
22
|
+
},
|
|
18
23
|
"peerDependencies": {
|
|
19
|
-
"@deepseek-ai/cordis": "^0.
|
|
20
|
-
"@deepseek-ai/dsh-tools": "
|
|
21
|
-
"@liuhange/dsh-data-asset-shared": "^
|
|
24
|
+
"@deepseek-ai/cordis": "^4.0.0",
|
|
25
|
+
"@deepseek-ai/dsh-tools": "0.0.1-rc.1",
|
|
26
|
+
"@liuhange/dsh-data-asset-shared": "^2.0.0"
|
|
22
27
|
}
|
|
23
28
|
}
|