-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-nested-access.ts
More file actions
97 lines (80 loc) · 2.63 KB
/
test-nested-access.ts
File metadata and controls
97 lines (80 loc) · 2.63 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bun
/**
* Test nested object access fix
*/
import { EAVStore, jsonEntityFacts } from '../src/eav-engine.js';
import { EQLSProcessor } from '../src/query/eqls-parser.js';
import { DatalogEvaluator } from '../src/query/datalog-evaluator.js';
// Simple test data with nested objects
const testData = [
{
type: 'user',
id: '1',
name: 'Alice',
metadata: {
preferences: {
theme: 'dark',
language: 'en'
},
profile: {
bio: 'Software engineer',
location: 'NYC'
}
}
},
{
type: 'user',
id: '2',
name: 'Bob',
metadata: {
preferences: {
theme: 'light',
language: 'es'
},
profile: {
bio: 'Designer',
location: 'LA'
}
}
}
];
async function testNestedAccess() {
console.log('🧪 Testing nested object access...');
// Initialize store
const store = new EAVStore();
const allFacts: any[] = [];
testData.forEach(entity => {
const entityId = `${entity.type}:${entity.id}`;
const facts = jsonEntityFacts(entityId, entity, entity.type);
allFacts.push(...facts);
});
store.addFacts(allFacts);
console.log(`✅ Store initialized with ${store.getStats().totalFacts} facts`);
// Test nested queries
const testQueries = [
'FIND user AS ?u WHERE ?u.metadata.preferences.theme = "dark" RETURN ?u.name',
'FIND user AS ?u WHERE ?u.metadata.profile.location = "NYC" RETURN ?u.name',
'FIND user AS ?u RETURN ?u.name, ?u.metadata.preferences.theme'
];
const processor = new EQLSProcessor();
const evaluator = new DatalogEvaluator(store);
for (const query of testQueries) {
console.log(`\n📝 Testing: ${query}`);
try {
const result = processor.process(query);
if (result.errors?.length > 0) {
console.log(`❌ Parse error: ${result.errors[0]?.message}`);
continue;
}
console.log('✅ Query parsed successfully');
const queryResult = evaluator.evaluate(result.query!);
console.log(`📊 Found ${queryResult.bindings.length} results`);
if (queryResult.bindings.length > 0) {
console.log('Sample result:', queryResult.bindings[0]);
}
} catch (error) {
console.log(`❌ Error: ${error instanceof Error ? error.message : String(error)}`);
}
}
}
testNestedAccess().catch(console.error);