-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-nested-json.ts
More file actions
65 lines (56 loc) · 1.78 KB
/
test-nested-json.ts
File metadata and controls
65 lines (56 loc) · 1.78 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bun
import { EAVStore, jsonEntityFacts, flatten } from '../src/eav-engine.js';
// Create deeply nested test data
const nestedData = [
{
data: [
{
resource: {
id: 1,
name: "Test Resource",
attributes: {
price: 99.99,
category: "test",
tags: ["deep", "nested", "data"]
}
}
},
{
resource: {
id: 2,
name: "Another Resource",
attributes: {
price: 49.99,
category: "demo",
tags: ["json", "structure"]
}
}
}
]
}
];
console.log('🔍 Testing nested JSON flattening\n');
// Test the flattening function directly
console.log('📊 Direct flattening test:');
const flattened = Array.from(flatten(nestedData[0]));
flattened.forEach(([path, value]) => {
console.log(` ${path} = ${value}`);
});
// Test EAV store ingestion
console.log('\n📊 EAV store test:');
const store = new EAVStore();
// Create entity from nested data
const facts = jsonEntityFacts('test:1', nestedData[0], 'test');
store.addFacts(facts);
console.log(` Added ${facts.length} facts`);
console.log(' All facts:');
store.getAllFacts().forEach(fact => {
console.log(` ${fact.e} | ${fact.a} | ${fact.v}`);
});
// Show catalog
console.log('\n📊 Catalog:');
store.getCatalog().forEach(entry => {
console.log(` ${entry.attribute} (${entry.type}, ${entry.cardinality})`);
console.log(` Examples: ${entry.examples.slice(0, 3).join(', ')}`);
});
console.log('\n✅ Test completed');