forked from eclipsesource/jsonforms-react-seed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze-configs.ts
39 lines (31 loc) · 1.09 KB
/
analyze-configs.ts
1
2
3
4
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
import fs from 'fs';
const analyzeConfigs = () => {
const rawData = fs.readFileSync('./configurations.json', 'utf-8');
const data = JSON.parse(rawData);
const items = data.Items || [];
const fieldInventory: Record<string, Set<string>> = {};
const analyzeObject = (obj: Record<string, any>, prefix = '') => {
Object.keys(obj).forEach(key => {
const field = prefix ? `${prefix}.${key}` : key;
const value = obj[key];
const type = Array.isArray(value) ? 'array' : typeof value;
if (!fieldInventory[field]) {
fieldInventory[field] = new Set();
}
fieldInventory[field].add(type);
if (type === 'object' && value !== null) {
analyzeObject(value, field);
}
});
};
items.forEach((item: any) => {
const configData = JSON.parse(item.config_data.S); // Adjust based on DynamoDB structure
analyzeObject(configData);
});
// Print the inventory
console.log('Field Inventory:');
Object.keys(fieldInventory).forEach(field => {
console.log(`${field}: [${[...fieldInventory[field]].join(', ')}]`);
});
};
analyzeConfigs();