holosphere 1.0.8 → 1.1.0
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/README.md +268 -113
- package/holosphere.d.ts +23 -24
- package/holosphere.js +483 -317
- package/package.json +1 -1
- package/test/holosphere.test.js +224 -109
package/README.md
CHANGED
|
@@ -1,176 +1,331 @@
|
|
|
1
1
|
# HoloSphere
|
|
2
2
|
|
|
3
|
-
HoloSphere is a
|
|
3
|
+
HoloSphere is a JavaScript library that provides a spatial data management system using H3 geospatial indexing and GunDB for distributed storage. It enables you to store, validate, and retrieve data organized by geographic location using holonic principles.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install holosphere
|
|
9
|
-
```
|
|
5
|
+
## What is a Holon?
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
A holon (from Greek 'holos' meaning whole, with suffix 'on' meaning part) is simultaneously a whole and a part. In HoloSphere, holons are implemented as hierarchical geographic cells that can:
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
1. Act as autonomous units (storing their own data)
|
|
10
|
+
2. Be part of larger holons (through H3's hierarchical structure)
|
|
11
|
+
3. Contain smaller holons (through subdivision)
|
|
12
|
+
4. Interact with peer holons (through the distributed network)
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
const holo = new HoloSphere('my-app');
|
|
14
|
+
### Holonic Architecture
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
const holoAI = new HoloSphere('my-app', 'your-openai-key');
|
|
21
|
-
```
|
|
16
|
+
HoloSphere implements holonic architecture in two ways:
|
|
22
17
|
|
|
23
|
-
|
|
18
|
+
#### 1. Spatial Hierarchy
|
|
19
|
+
```javascript
|
|
20
|
+
// Get holons at different scales for a location
|
|
21
|
+
const holon = await sphere.getHolon(lat, lng, 7); // City level
|
|
22
|
+
const parent = h3.cellToParent(holon, 6); // Region level
|
|
23
|
+
const children = h3.cellToChildren(holon, 8); // Neighborhood level
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
// Get entire hierarchy
|
|
26
|
+
const scales = sphere.getHolonScalespace(holon); // All containing holons
|
|
27
|
+
```
|
|
26
28
|
|
|
29
|
+
#### 2. Data Organization
|
|
27
30
|
```javascript
|
|
28
|
-
//
|
|
29
|
-
await
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// Store data in different aspects (lenses) of a holon
|
|
32
|
+
await sphere.put(holon, 'environment', {
|
|
33
|
+
id: 'air-001',
|
|
34
|
+
temperature: 22.5,
|
|
35
|
+
humidity: 65
|
|
36
|
+
});
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
await sphere.put(holon, 'social', {
|
|
39
|
+
id: 'event-001',
|
|
40
|
+
type: 'gathering',
|
|
41
|
+
participants: 50
|
|
42
|
+
});
|
|
36
43
|
```
|
|
37
44
|
|
|
38
|
-
###
|
|
45
|
+
### Use Cases
|
|
46
|
+
|
|
47
|
+
1. **Localized Structures**
|
|
48
|
+
- Local environmental monitoring
|
|
49
|
+
- Community event coordination
|
|
50
|
+
- Neighborhood resource sharing
|
|
51
|
+
- Municipal service management
|
|
39
52
|
|
|
40
53
|
```javascript
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
// Example: Local air quality monitoring
|
|
55
|
+
async function monitorLocalAir(lat, lng) {
|
|
56
|
+
const neighborhood = await sphere.getHolon(lat, lng, 9);
|
|
57
|
+
|
|
58
|
+
// Store reading
|
|
59
|
+
await sphere.put(neighborhood, 'air-quality', {
|
|
60
|
+
id: `reading-${Date.now()}`,
|
|
61
|
+
pm25: 12.5,
|
|
62
|
+
timestamp: Date.now()
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Get local trends
|
|
66
|
+
const readings = await sphere.getAll(neighborhood, 'air-quality');
|
|
67
|
+
}
|
|
68
|
+
```
|
|
50
69
|
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
2. **Delocalized Structures**
|
|
71
|
+
- Regional data aggregation
|
|
72
|
+
- Cross-boundary collaboration
|
|
73
|
+
- Distributed decision making
|
|
74
|
+
- Resource flow tracking
|
|
53
75
|
|
|
54
|
-
|
|
55
|
-
|
|
76
|
+
```javascript
|
|
77
|
+
// Example: Regional resource coordination
|
|
78
|
+
async function coordinateResources(region) {
|
|
79
|
+
// Get all sub-holons
|
|
80
|
+
const localities = h3.cellToChildren(region, h3.getResolution(region) + 1);
|
|
81
|
+
|
|
82
|
+
// Gather resource data from each locality
|
|
83
|
+
const resources = await Promise.all(
|
|
84
|
+
localities.map(async locality => {
|
|
85
|
+
return sphere.getAll(locality, 'resources');
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Compute summaries for parent holon
|
|
90
|
+
await sphere.compute(region, 'resources', 'summarize');
|
|
91
|
+
}
|
|
56
92
|
```
|
|
57
93
|
|
|
58
|
-
|
|
94
|
+
3. **Hybrid Structures**
|
|
95
|
+
- Adaptive governance systems
|
|
96
|
+
- Scalable social networks
|
|
97
|
+
- Emergency response coordination
|
|
98
|
+
- Supply chain management
|
|
59
99
|
|
|
60
100
|
```javascript
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
101
|
+
// Example: Emergency response system
|
|
102
|
+
async function coordinateEmergency(incident) {
|
|
103
|
+
const epicenter = await sphere.getHolon(incident.lat, incident.lng, 8);
|
|
104
|
+
const region = h3.cellToParent(epicenter, 6);
|
|
105
|
+
|
|
106
|
+
// Local response
|
|
107
|
+
await sphere.put(epicenter, 'emergencies', {
|
|
108
|
+
id: incident.id,
|
|
109
|
+
type: incident.type,
|
|
110
|
+
severity: incident.severity
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Regional coordination
|
|
114
|
+
const nearbyResources = await sphere.getAll(region, 'resources');
|
|
115
|
+
|
|
116
|
+
// Subscribe to updates
|
|
117
|
+
sphere.subscribe(epicenter, 'emergencies', (data) => {
|
|
118
|
+
updateResponsePlan(data);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
```
|
|
66
122
|
|
|
67
|
-
|
|
68
|
-
const allSettings = await holo.getGlobalData('settings');
|
|
123
|
+
### Key Benefits
|
|
69
124
|
|
|
70
|
-
|
|
71
|
-
|
|
125
|
+
1. **Scalability**: Holons can be nested infinitely, allowing systems to scale organically
|
|
126
|
+
2. **Autonomy**: Each holon manages its own data while participating in larger structures
|
|
127
|
+
3. **Flexibility**: Systems can be organized both hierarchically and peer-to-peer
|
|
128
|
+
4. **Resilience**: Distributed storage ensures no single point of failure
|
|
129
|
+
5. **Adaptability**: Structures can evolve based on changing needs
|
|
72
130
|
|
|
73
|
-
|
|
74
|
-
|
|
131
|
+
## Installation
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
npm install holosphere
|
|
75
135
|
```
|
|
76
136
|
|
|
77
|
-
|
|
137
|
+
## Quick Start
|
|
78
138
|
|
|
79
139
|
```javascript
|
|
80
|
-
|
|
81
|
-
await holo.putHexData('hex123', 'observations', {
|
|
82
|
-
id: 'obs1',
|
|
83
|
-
data: 'value'
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// Get all data from a hex/lens
|
|
87
|
-
const data = await holo.getHexData('hex123', 'observations');
|
|
140
|
+
import HoloSphere from 'holosphere';
|
|
88
141
|
|
|
89
|
-
//
|
|
90
|
-
const
|
|
142
|
+
// Initialize HoloSphere
|
|
143
|
+
const sphere = new HoloSphere('my-app');
|
|
144
|
+
|
|
145
|
+
// Store data at a location
|
|
146
|
+
const holon = await sphere.getHolon(40.7128, -74.0060, 7); // NYC at resolution 7
|
|
147
|
+
await sphere.put(holon, 'observations', {
|
|
148
|
+
id: 'obs-001',
|
|
149
|
+
temperature: 22.5,
|
|
150
|
+
timestamp: Date.now()
|
|
151
|
+
});
|
|
152
|
+
```
|
|
91
153
|
|
|
92
|
-
|
|
93
|
-
const node = await holo.getHexNode('hex123', 'observations', 'obs1');
|
|
154
|
+
## Real-World Examples
|
|
94
155
|
|
|
95
|
-
|
|
96
|
-
await holo.deleteHexData('hex123', 'observations', 'obs1');
|
|
156
|
+
### Environmental Monitoring System
|
|
97
157
|
|
|
98
|
-
|
|
99
|
-
|
|
158
|
+
```javascript
|
|
159
|
+
// Define a schema for temperature readings
|
|
160
|
+
const tempSchema = {
|
|
161
|
+
type: 'object',
|
|
162
|
+
properties: {
|
|
163
|
+
id: { type: 'string' },
|
|
164
|
+
temperature: { type: 'number' },
|
|
165
|
+
humidity: { type: 'number' },
|
|
166
|
+
timestamp: { type: 'number' }
|
|
167
|
+
},
|
|
168
|
+
required: ['id', 'temperature', 'timestamp']
|
|
169
|
+
};
|
|
100
170
|
|
|
101
|
-
//
|
|
102
|
-
|
|
171
|
+
// Set up the system
|
|
172
|
+
const sphere = new HoloSphere('env-monitor', true); // strict mode enabled
|
|
173
|
+
await sphere.setSchema('temperature', tempSchema);
|
|
174
|
+
|
|
175
|
+
// Store a reading
|
|
176
|
+
async function storeReading(lat, lng, temp, humidity) {
|
|
177
|
+
const holon = await sphere.getHolon(lat, lng, 8);
|
|
178
|
+
const reading = {
|
|
179
|
+
id: `temp-${Date.now()}`,
|
|
180
|
+
temperature: temp,
|
|
181
|
+
humidity: humidity,
|
|
182
|
+
timestamp: Date.now()
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
return sphere.put(holon, 'temperature', reading);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Get all readings for an area
|
|
189
|
+
async function getAreaReadings(lat, lng) {
|
|
190
|
+
const holon = await sphere.getHolon(lat, lng, 8);
|
|
191
|
+
return sphere.getAll(holon, 'temperature');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Monitor an area for new readings
|
|
195
|
+
function monitorArea(lat, lng, callback) {
|
|
196
|
+
const holon = sphere.getHolon(lat, lng, 8);
|
|
197
|
+
sphere.subscribe(holon, 'temperature', callback);
|
|
198
|
+
}
|
|
103
199
|
```
|
|
104
200
|
|
|
105
|
-
###
|
|
201
|
+
### Location-Based Content System
|
|
106
202
|
|
|
107
203
|
```javascript
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
id: 'secret1',
|
|
111
|
-
data: 'sensitive'
|
|
112
|
-
}, true, 'encryption-key');
|
|
204
|
+
// Initialize with AI capabilities for content summarization
|
|
205
|
+
const sphere = new HoloSphere('local-content', false, 'your-openai-key');
|
|
113
206
|
|
|
114
|
-
//
|
|
115
|
-
const
|
|
207
|
+
// Define content schema
|
|
208
|
+
const contentSchema = {
|
|
209
|
+
type: 'object',
|
|
210
|
+
properties: {
|
|
211
|
+
id: { type: 'string' },
|
|
212
|
+
title: { type: 'string' },
|
|
213
|
+
content: { type: 'string' },
|
|
214
|
+
author: { type: 'string' },
|
|
215
|
+
timestamp: { type: 'number' }
|
|
216
|
+
},
|
|
217
|
+
required: ['id', 'title', 'content', 'author']
|
|
218
|
+
};
|
|
116
219
|
|
|
117
|
-
|
|
118
|
-
|
|
220
|
+
await sphere.setSchema('articles', contentSchema);
|
|
221
|
+
|
|
222
|
+
// Post content for a location
|
|
223
|
+
async function postLocalContent(lat, lng, title, content, author) {
|
|
224
|
+
const holon = await sphere.getHolon(lat, lng, 7);
|
|
225
|
+
const article = {
|
|
226
|
+
id: `article-${Date.now()}`,
|
|
227
|
+
title,
|
|
228
|
+
content,
|
|
229
|
+
author,
|
|
230
|
+
timestamp: Date.now()
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
await sphere.put(holon, 'articles', article);
|
|
234
|
+
|
|
235
|
+
// Generate summaries for parent areas
|
|
236
|
+
await sphere.compute(holon, 'articles', 'summarize');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Get content for multiple zoom levels
|
|
240
|
+
async function getAreaContent(lat, lng) {
|
|
241
|
+
const holon = await sphere.getHolon(lat, lng, 7);
|
|
242
|
+
const scales = sphere.getHolonScalespace(holon);
|
|
243
|
+
|
|
244
|
+
const content = {};
|
|
245
|
+
for (const scale of scales) {
|
|
246
|
+
content[scale] = await sphere.getAll(scale, 'articles');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return content;
|
|
250
|
+
}
|
|
119
251
|
```
|
|
120
252
|
|
|
121
|
-
###
|
|
253
|
+
### Data Validation Example
|
|
122
254
|
|
|
123
255
|
```javascript
|
|
124
|
-
//
|
|
125
|
-
const
|
|
256
|
+
// Strict validation with custom schema
|
|
257
|
+
const sphere = new HoloSphere('validated-data', true);
|
|
126
258
|
|
|
127
|
-
|
|
128
|
-
|
|
259
|
+
const measurementSchema = {
|
|
260
|
+
type: 'object',
|
|
261
|
+
properties: {
|
|
262
|
+
id: { type: 'string' },
|
|
263
|
+
value: { type: 'number' },
|
|
264
|
+
unit: { type: 'string' },
|
|
265
|
+
accuracy: { type: 'number' },
|
|
266
|
+
timestamp: { type: 'number' }
|
|
267
|
+
},
|
|
268
|
+
required: ['id', 'value', 'unit'],
|
|
269
|
+
additionalProperties: false
|
|
270
|
+
};
|
|
129
271
|
|
|
130
|
-
|
|
131
|
-
const parents = holo.getHexScalespace('hex123');
|
|
272
|
+
await sphere.setSchema('measurements', measurementSchema);
|
|
132
273
|
|
|
133
|
-
//
|
|
134
|
-
await
|
|
274
|
+
// This will succeed
|
|
275
|
+
await sphere.put(holon, 'measurements', {
|
|
276
|
+
id: 'measure-1',
|
|
277
|
+
value: 42.5,
|
|
278
|
+
unit: 'celsius',
|
|
279
|
+
accuracy: 0.1,
|
|
280
|
+
timestamp: Date.now()
|
|
281
|
+
});
|
|
135
282
|
|
|
136
|
-
//
|
|
137
|
-
await
|
|
283
|
+
// This will fail due to schema validation
|
|
284
|
+
await sphere.put(holon, 'measurements', {
|
|
285
|
+
id: 'measure-2',
|
|
286
|
+
value: "invalid", // wrong type
|
|
287
|
+
extra: "field" // not allowed
|
|
288
|
+
});
|
|
138
289
|
```
|
|
139
290
|
|
|
140
|
-
|
|
291
|
+
## API Reference
|
|
141
292
|
|
|
293
|
+
### Constructor
|
|
142
294
|
```javascript
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
295
|
+
new HoloSphere(
|
|
296
|
+
appName, // String: Namespace for your application
|
|
297
|
+
strict, // Boolean: Enable strict schema validation (default: false)
|
|
298
|
+
openaikey // String: Optional OpenAI API key for AI features
|
|
299
|
+
)
|
|
148
300
|
```
|
|
149
301
|
|
|
150
|
-
###
|
|
302
|
+
### Core Methods
|
|
151
303
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
304
|
+
- `async getHolon(lat, lng, resolution)` - Get H3 index for coordinates
|
|
305
|
+
- `async put(holon, lens, data)` - Store data
|
|
306
|
+
- `async get(holon, lens, key)` - Retrieve specific data
|
|
307
|
+
- `async getAll(holon, lens)` - Retrieve all data
|
|
308
|
+
- `async delete(holon, lens, key)` - Delete specific data
|
|
309
|
+
- `async deleteAll(holon, lens)` - Delete all data
|
|
310
|
+
- `async setSchema(lens, schema)` - Set JSON schema for validation
|
|
311
|
+
- `async getSchema(lens)` - Get current schema
|
|
312
|
+
- `subscribe(holon, lens, callback)` - Listen for changes
|
|
155
313
|
|
|
156
|
-
|
|
157
|
-
const results = holo.aggregateVotes(hexId, topic);
|
|
314
|
+
## Storage Architecture
|
|
158
315
|
|
|
159
|
-
|
|
160
|
-
|
|
316
|
+
Data in HoloSphere is organized by:
|
|
317
|
+
- **Holons**: H3 geographic indexes
|
|
318
|
+
- **Lenses**: Data categories/types
|
|
319
|
+
- **Items**: Individual data entries with unique IDs
|
|
161
320
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
321
|
+
## Dependencies
|
|
322
|
+
|
|
323
|
+
- h3-js: Uber's H3 geospatial indexing
|
|
324
|
+
- gun: Decentralized database
|
|
325
|
+
- ajv: JSON Schema validation
|
|
326
|
+
- openai: AI capabilities (optional)
|
|
165
327
|
|
|
166
328
|
## License
|
|
167
329
|
|
|
168
330
|
GPL-3.0-or-later
|
|
169
331
|
|
|
170
|
-
## Dependencies
|
|
171
|
-
|
|
172
|
-
- h3-js: Uber's H3 geospatial indexing system
|
|
173
|
-
- gun: Decentralized graph database
|
|
174
|
-
- ajv: JSON Schema validation
|
|
175
|
-
- openai: OpenAI API client (optional)
|
|
176
|
-
|
package/holosphere.d.ts
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
declare module 'holosphere' {
|
|
2
2
|
export default class HoloSphere {
|
|
3
|
-
constructor(appName: string, openaikey?: string | null);
|
|
4
|
-
|
|
3
|
+
constructor(appName: string, strict?: boolean | null, openaikey?: string | null);
|
|
4
|
+
|
|
5
5
|
// User Management
|
|
6
6
|
createUser(username: string, password: string): Promise<object>;
|
|
7
7
|
login(username: string, password: string): Promise<object>;
|
|
8
8
|
logout(): Promise<void>;
|
|
9
9
|
|
|
10
10
|
// Schema Operations
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
setSchema(lens: string, schema: object): Promise<void>;
|
|
12
|
+
getSchema(lens: string): Promise<object | null>;
|
|
13
13
|
|
|
14
14
|
// Encryption Operations
|
|
15
15
|
encrypt(data: any, secret: string): Promise<string>;
|
|
16
16
|
decrypt(encryptedData: string, secret: string): Promise<any>;
|
|
17
17
|
|
|
18
|
-
// Global Data Operations
|
|
19
|
-
putGlobalData(tableName: string, data: object): Promise<void>;
|
|
20
|
-
getGlobalData(tableName: string): Promise<object | null>;
|
|
21
|
-
getGlobalDataKey(tableName: string, key: string): Promise<object | null>;
|
|
22
|
-
deleteGlobalData(tableName: string): Promise<void>;
|
|
23
|
-
|
|
24
18
|
// Hex Data Operations
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
put(holon: string, lens: string, content: object, encrypt?: boolean, secret?: string | null): Promise<void>;
|
|
20
|
+
get(holon: string, lens: string, key: string): Promise<any | null>;
|
|
21
|
+
delete(holon: string, lens: string, contentId: string): Promise<void>;
|
|
22
|
+
getAll(holon: string, lens: string, secret?: string | null): Promise<Array<any>>;
|
|
23
|
+
deleteAll(holon: string, lens: string): Promise<void>;
|
|
24
|
+
|
|
25
|
+
// Node Operations
|
|
26
|
+
putNode(holon: string, lens: string, node: object): Promise<void>;
|
|
27
|
+
getNode(holon: string, lens: string, key: string): Promise<any>;
|
|
28
|
+
deleteNode(holon: string, lens: string, key: string): Promise<void>;
|
|
29
|
+
|
|
30
|
+
// Global Data Operations
|
|
31
|
+
putGlobal(tableName: string, data: object): Promise<void>;
|
|
32
|
+
getGlobal(tableName: string, key: string): Promise<object | null>;
|
|
33
|
+
deleteGlobal(tableName: string, key: string): Promise<void>;
|
|
34
|
+
getAllGlobal(tableName: string): Promise<object | null>;
|
|
35
|
+
deleteAllGlobal(tableName: string): Promise<void>;
|
|
32
36
|
|
|
33
37
|
// Geospatial Operations
|
|
34
38
|
getHex(lat: number, lng: number, resolution: number): Promise<string>;
|
|
@@ -38,12 +42,7 @@ declare module 'holosphere' {
|
|
|
38
42
|
upcast(hex: string, lens: string, content: any): Promise<any>;
|
|
39
43
|
|
|
40
44
|
// Subscription
|
|
41
|
-
subscribe(
|
|
42
|
-
|
|
43
|
-
// Voting System
|
|
44
|
-
getFinalVote(userId: string, topic: string, votes: object, visited?: Set<string>): string | null;
|
|
45
|
-
aggregateVotes(hexId: string, topic: string): object;
|
|
46
|
-
delegateVote(userId: string, topic: string, delegateTo: string): Promise<void>;
|
|
47
|
-
vote(userId: string, hexId: string, topic: string, vote: string): Promise<void>;
|
|
45
|
+
subscribe(holon: string, lens: string, callback: (data: any, key: string) => void): void;
|
|
46
|
+
subscribeGlobal(tableName: string, callback: (data: any, key: string) => void): void;
|
|
48
47
|
}
|
|
49
48
|
}
|