holosphere 1.1.6 → 1.1.7
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/FEDERATION.md +108 -160
- package/README.md +140 -0
- package/examples/README-environmental.md +158 -0
- package/examples/environmentalData.js +380 -0
- package/examples/federation.js +154 -0
- package/examples/queryEnvironmentalData.js +147 -0
- package/examples/references.js +177 -0
- package/federation.js +637 -372
- package/holosphere.d.ts +445 -20
- package/holosphere.js +343 -126
- package/package.json +1 -1
- package/services/environmentalApi.js +162 -0
- package/services/{environmentalApitest.js → environmentalApi.test.js} +0 -6
- package/test/ai.test.js +2 -2
- package/test/delete.test.js +225 -0
- package/test/federation.test.js +50 -2
- /package/test/{holonauth.test.js → auth.test.js} +0 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import HoloSphere from './holosphere.js';
|
|
2
|
+
|
|
3
|
+
async function testReferenceFederation() {
|
|
4
|
+
console.log('Starting reference federation test...');
|
|
5
|
+
const holoSphere = new HoloSphere('test-references');
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const space1 = 'ref-test-space1';
|
|
9
|
+
const space2 = 'ref-test-space2';
|
|
10
|
+
|
|
11
|
+
// Step 1: Create federation with bidirectional notify settings
|
|
12
|
+
console.log('Step 1: Creating federation between spaces...');
|
|
13
|
+
await holoSphere.federate(space1, space2);
|
|
14
|
+
|
|
15
|
+
// Also federate from space2 to space1 for testing getFederated
|
|
16
|
+
await holoSphere.federate(space2, space1);
|
|
17
|
+
|
|
18
|
+
// Step 2: Verify federation is set up properly
|
|
19
|
+
const fedInfo = await holoSphere.getFederation(space1);
|
|
20
|
+
console.log('Federation info for space1:', fedInfo);
|
|
21
|
+
|
|
22
|
+
const fedInfo2 = await holoSphere.getFederation(space2);
|
|
23
|
+
console.log('Federation info for space2:', fedInfo2);
|
|
24
|
+
|
|
25
|
+
// Step 3: Create test data
|
|
26
|
+
console.log('Step 3: Creating test data...');
|
|
27
|
+
const testData = {
|
|
28
|
+
id: 'ref-test-item',
|
|
29
|
+
title: 'Reference Test',
|
|
30
|
+
value: 200,
|
|
31
|
+
tags: ['test', 'reference']
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Store data in space1
|
|
35
|
+
await holoSphere.put(space1, 'items', testData);
|
|
36
|
+
|
|
37
|
+
// Step 4: Propagate using references
|
|
38
|
+
console.log('Step 4: Propagating with soul references...');
|
|
39
|
+
const propResult = await holoSphere.propagate(space1, 'items', testData, {
|
|
40
|
+
useReferences: true
|
|
41
|
+
});
|
|
42
|
+
console.log('Propagation result:', propResult);
|
|
43
|
+
|
|
44
|
+
// Allow time for propagation
|
|
45
|
+
console.log('Waiting for propagation...');
|
|
46
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
47
|
+
|
|
48
|
+
// Step 5: Verify that the data in space2 is a soul reference
|
|
49
|
+
console.log('Step 5: Verifying soul reference was created...');
|
|
50
|
+
const rawRef = await holoSphere.get(space2, 'items', 'ref-test-item', null, {
|
|
51
|
+
resolveReferences: false
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
console.log('Raw reference data:', rawRef);
|
|
55
|
+
console.log('Is soul reference:', !!rawRef?.soul);
|
|
56
|
+
|
|
57
|
+
if (rawRef?.soul) {
|
|
58
|
+
const soulParts = rawRef.soul.split('/');
|
|
59
|
+
console.log('Soul parts:', soulParts);
|
|
60
|
+
console.log('Soul refers to:', {
|
|
61
|
+
app: soulParts[0],
|
|
62
|
+
holon: soulParts[1],
|
|
63
|
+
lens: soulParts[2],
|
|
64
|
+
key: soulParts[3]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Step 6: Verify reference resolution works
|
|
69
|
+
console.log('Step 6: Verifying reference resolution...');
|
|
70
|
+
const resolvedData = await holoSphere.get(space2, 'items', 'ref-test-item');
|
|
71
|
+
console.log('Resolved data:', resolvedData);
|
|
72
|
+
|
|
73
|
+
// Step 7: Update the original data
|
|
74
|
+
console.log('Step 7: Updating original data...');
|
|
75
|
+
const updatedData = {
|
|
76
|
+
...testData,
|
|
77
|
+
value: 300,
|
|
78
|
+
updated: true
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
await holoSphere.put(space1, 'items', updatedData);
|
|
82
|
+
|
|
83
|
+
// Allow time for update to propagate
|
|
84
|
+
console.log('Waiting for update...');
|
|
85
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
86
|
+
|
|
87
|
+
// Step 8: Verify update is reflected through the reference
|
|
88
|
+
console.log('Step 8: Verifying update is reflected in reference...');
|
|
89
|
+
const reResolvedData = await holoSphere.get(space2, 'items', 'ref-test-item');
|
|
90
|
+
console.log('Re-resolved data after update:', reResolvedData);
|
|
91
|
+
|
|
92
|
+
// Step 9: Update directly through origin holon
|
|
93
|
+
console.log('Step 9: Updating through the origin holon...');
|
|
94
|
+
const originData = await holoSphere.get(space1, 'items', 'ref-test-item');
|
|
95
|
+
|
|
96
|
+
const finalUpdate = {
|
|
97
|
+
...originData,
|
|
98
|
+
value: 400,
|
|
99
|
+
finalUpdate: true
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
await holoSphere.put(space1, 'items', finalUpdate);
|
|
103
|
+
|
|
104
|
+
// Allow time for update to propagate
|
|
105
|
+
console.log('Waiting for update to propagate...');
|
|
106
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
107
|
+
|
|
108
|
+
// Step 10: Verify update is visible through the reference
|
|
109
|
+
console.log('Step 10: Verifying update is visible through the reference...');
|
|
110
|
+
const originalAfterUpdate = await holoSphere.get(space1, 'items', 'ref-test-item');
|
|
111
|
+
console.log('Original data after update:', originalAfterUpdate);
|
|
112
|
+
|
|
113
|
+
const refAfterUpdate = await holoSphere.get(space2, 'items', 'ref-test-item');
|
|
114
|
+
console.log('Reference resolved data after update:', refAfterUpdate);
|
|
115
|
+
|
|
116
|
+
// Step 11: Test manual soul reference resolution
|
|
117
|
+
console.log('Step 11: Testing manual soul reference resolution...');
|
|
118
|
+
|
|
119
|
+
// Check what getAll returns
|
|
120
|
+
console.log('Raw references from getAll in space2:');
|
|
121
|
+
const allItems = await holoSphere.getAll(space2, 'items');
|
|
122
|
+
console.log('getAll results:', allItems);
|
|
123
|
+
|
|
124
|
+
if (allItems.length > 0 && allItems[0].soul) {
|
|
125
|
+
console.log('Found a soul reference, resolving it manually:');
|
|
126
|
+
const soulParts = allItems[0].soul.split('/');
|
|
127
|
+
|
|
128
|
+
const originHolon = soulParts[1];
|
|
129
|
+
const originLens = soulParts[2];
|
|
130
|
+
const originKey = soulParts[3];
|
|
131
|
+
|
|
132
|
+
console.log(`Soul path components: holon=${originHolon}, lens=${originLens}, key=${originKey}`);
|
|
133
|
+
|
|
134
|
+
const originalData = await holoSphere.get(
|
|
135
|
+
originHolon,
|
|
136
|
+
originLens,
|
|
137
|
+
originKey,
|
|
138
|
+
null,
|
|
139
|
+
{ resolveReferences: false }
|
|
140
|
+
);
|
|
141
|
+
console.log('Manually resolved reference data:', originalData);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Test getFederated with soul references
|
|
145
|
+
console.log('\nTesting getFederated with soul references:');
|
|
146
|
+
const federatedData = await holoSphere.getFederated(space2, 'items', {
|
|
147
|
+
resolveReferences: true,
|
|
148
|
+
idField: 'id'
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
console.log('getFederated results length:', federatedData.length);
|
|
152
|
+
|
|
153
|
+
// Find the item by ID
|
|
154
|
+
const federatedItem = federatedData.find(item => item.id === 'ref-test-item');
|
|
155
|
+
console.log('Found federated item by ID:', federatedItem);
|
|
156
|
+
|
|
157
|
+
// Check if federated data correctly resolves soul references
|
|
158
|
+
if (federatedItem && federatedItem.value === 400 && federatedItem.finalUpdate) {
|
|
159
|
+
console.log('SUCCESS: getFederated correctly resolved the soul reference!');
|
|
160
|
+
} else {
|
|
161
|
+
console.log('WARNING: getFederated may not be resolving soul references properly');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Step 12: Clean up
|
|
165
|
+
console.log('Step 12: Cleaning up...');
|
|
166
|
+
await holoSphere.unfederate(space1, space2);
|
|
167
|
+
await holoSphere.unfederate(space2, space1);
|
|
168
|
+
|
|
169
|
+
console.log('Test completed successfully!');
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.error('Error in test:', error);
|
|
172
|
+
} finally {
|
|
173
|
+
await holoSphere.close();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
testReferenceFederation().catch(console.error);
|