holosphere 1.0.7 → 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 CHANGED
@@ -1,206 +1,331 @@
1
1
  # HoloSphere
2
2
 
3
- HoloSphere is a decentralized geospatial data management system that combines hierarchical hexagonal tiling (H3) with distributed data storage (GunDB) and AI-powered processing of information.
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
- ## Features
5
+ ## What is a Holon?
6
6
 
7
- - **Hierarchical Spatial Data**: Uses Uber's H3 spatial indexing system for efficient geospatial data organization
8
- - **Decentralized Storage**: Built on GunDB for peer-to-peer data storage and synchronization
9
- - **Schema Validation**: JSON Schema validation for data integrity
10
- - **AI Processing**: Extensible AI-powered content analysis and summarization across hexagonal regions
11
- - **Voting System**: Built-in delegation and voting mechanisms for collaborative decision-making
12
- - **Multi-scale Operations**: Automatic content propagation across different spatial resolutions
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:
13
8
 
14
- ## License
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)
13
+
14
+ ### Holonic Architecture
15
15
 
16
- GNU Lesser General Public License v3.0 (LGPL-3.0)
16
+ HoloSphere implements holonic architecture in two ways:
17
17
 
18
- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
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
19
24
 
20
- This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
25
+ // Get entire hierarchy
26
+ const scales = sphere.getHolonScalespace(holon); // All containing holons
27
+ ```
28
+
29
+ #### 2. Data Organization
30
+ ```javascript
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
+ });
21
37
 
22
- You should have received a copy of the GNU Lesser General Public License along with this library; if not, see <https://www.gnu.org/licenses/>.
38
+ await sphere.put(holon, 'social', {
39
+ id: 'event-001',
40
+ type: 'gathering',
41
+ participants: 50
42
+ });
43
+ ```
23
44
 
24
- ### Key Points of LGPL-3.0
45
+ ### Use Cases
25
46
 
26
- - You can use this library in proprietary applications
27
- - Any modifications to the library itself must be distributed under LGPL
28
- - Applications that use the library don't have to be LGPL
29
- - If you modify the library, you must make the source code available
30
- - You must provide a way for users to relink with a modified version of the library
47
+ 1. **Localized Structures**
48
+ - Local environmental monitoring
49
+ - Community event coordination
50
+ - Neighborhood resource sharing
51
+ - Municipal service management
31
52
 
32
- ## Dependencies
53
+ ```javascript
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
+ ```
33
69
 
34
- ### Core Dependencies
35
- - **h3-js**: Uber's H3 geospatial indexing system
36
- - **gun**: Decentralized graph database
37
- - **ajv**: JSON Schema validation
38
- - **lodash**: Utility functions
70
+ 2. **Delocalized Structures**
71
+ - Regional data aggregation
72
+ - Cross-boundary collaboration
73
+ - Distributed decision making
74
+ - Resource flow tracking
39
75
 
40
- ### Optional Dependencies
41
- - **langchain**: AI/LLM integration framework
42
- - **openai**: OpenAI API client (optional)
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
+ }
92
+ ```
93
+
94
+ 3. **Hybrid Structures**
95
+ - Adaptive governance systems
96
+ - Scalable social networks
97
+ - Emergency response coordination
98
+ - Supply chain management
99
+
100
+ ```javascript
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
+ ```
122
+
123
+ ### Key Benefits
43
124
 
44
- ## Getting Started
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
130
+
131
+ ## Installation
45
132
 
46
133
  ```bash
47
134
  npm install holosphere
48
135
  ```
49
136
 
50
- ## Basic Usage
137
+ ## Quick Start
51
138
 
52
139
  ```javascript
53
- import { HoloSphere } from 'holosphere';
140
+ import HoloSphere from 'holosphere';
54
141
 
55
- // Initialize HoloSphere with your configuration
56
- const holo = new HoloSphere({
57
- peers: ['http://localhost:8765/gun'],
58
- aiProvider: 'local' // or 'openai', 'azure', etc.
59
- });
142
+ // Initialize HoloSphere
143
+ const sphere = new HoloSphere('my-app');
60
144
 
61
- // Create or access a hexagonal region
62
- const hex = await holo.getHex('8928308280fffff');
63
-
64
- // Store data in the region
65
- await hex.put({
66
- type: 'observation',
67
- data: {
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',
68
149
  temperature: 22.5,
69
150
  timestamp: Date.now()
70
- }
71
- });
72
-
73
- // Subscribe to changes
74
- hex.subscribe(data => {
75
- console.log('New data:', data);
76
151
  });
77
152
  ```
78
153
 
79
- ## Advanced Features
154
+ ## Real-World Examples
80
155
 
81
- ### Spatial Queries
156
+ ### Environmental Monitoring System
82
157
 
83
158
  ```javascript
84
- // Find all hexagons within a radius
85
- const hexagons = await holo.findWithin({
86
- lat: 37.7749,
87
- lng: -122.4194,
88
- radius: 5000 // meters
89
- });
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
+ };
90
170
 
91
- // Query data across multiple resolutions
92
- const aggregatedData = await holo.aggregate({
93
- hexIds: hexagons,
94
- resolution: 7,
95
- method: 'average'
96
- });
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
+ }
97
199
  ```
98
200
 
99
- ### AI Processing
201
+ ### Location-Based Content System
100
202
 
101
203
  ```javascript
102
- // Process content with AI
103
- const summary = await hex.processContent({
104
- processor: 'summarize',
105
- options: {
106
- maxLength: 100
107
- }
108
- });
204
+ // Initialize with AI capabilities for content summarization
205
+ const sphere = new HoloSphere('local-content', false, 'your-openai-key');
206
+
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
+ };
109
219
 
110
- // Analyze trends across regions
111
- const analysis = await holo.analyzeRegion({
112
- hexIds: hexagons,
113
- timeRange: '7d',
114
- metrics: ['sentiment', 'topics']
115
- });
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
+ }
116
251
  ```
117
252
 
118
- ### Voting and Governance
253
+ ### Data Validation Example
119
254
 
120
255
  ```javascript
121
- // Create a proposal
122
- const proposal = await hex.createProposal({
123
- title: 'Update Data Schema',
124
- description: 'Add new fields for environmental metrics',
125
- changes: {
126
- schema: newSchemaDefinition
127
- }
256
+ // Strict validation with custom schema
257
+ const sphere = new HoloSphere('validated-data', true);
258
+
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
+ };
271
+
272
+ await sphere.setSchema('measurements', measurementSchema);
273
+
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()
128
281
  });
129
282
 
130
- // Cast a vote
131
- await proposal.vote({
132
- support: true,
133
- weight: 1.0
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
134
288
  });
135
289
  ```
136
290
 
137
- ## Configuration
138
-
139
- HoloSphere can be configured with various options:
291
+ ## API Reference
140
292
 
293
+ ### Constructor
141
294
  ```javascript
142
- const config = {
143
- // Network configuration
144
- peers: ['https://peer1.example.com/gun', 'https://peer2.example.com/gun'],
145
-
146
- // Storage options
147
- storage: {
148
- type: 'indexeddb',
149
- namespace: 'my-app'
150
- },
151
-
152
- // AI processing configuration
153
- ai: {
154
- provider: 'local',
155
- model: 'gpt-3.5-turbo',
156
- apiKey: process.env.AI_API_KEY
157
- },
158
-
159
- // Schema validation
160
- schema: {
161
- strict: true,
162
- customValidators: {}
163
- }
164
- };
165
-
166
- const holo = new HoloSphere(config);
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
+ )
167
300
  ```
168
301
 
169
- ## Documentation
302
+ ### Core Methods
170
303
 
171
- For detailed documentation, please visit our [documentation site](https://docs.holons.io).
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
172
313
 
173
- ## Contributing
314
+ ## Storage Architecture
174
315
 
175
- We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on:
176
- - Code of Conduct
177
- - Development setup
178
- - Testing guidelines
179
- - Pull request process
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
180
320
 
181
- ## Support
182
-
183
- - [GitHub Issues](https://github.com/liminalvillage/holosphere/issues)
184
- - [Discord Community](https://discord.gg/liminalvillage)
185
-
186
- ## Roadmap
187
-
188
- - [ ] Enhanced spatial indexing algorithms
189
- - [ ] Additional AI model integrations
190
- - [ ] Improved data replication strategies
191
- - [ ] Extended governance mechanisms
192
- - [ ] Mobile SDK development
321
+ ## Dependencies
193
322
 
194
- ## Citation
323
+ - h3-js: Uber's H3 geospatial indexing
324
+ - gun: Decentralized database
325
+ - ajv: JSON Schema validation
326
+ - openai: AI capabilities (optional)
195
327
 
196
- If you use HoloSphere in your research, please cite:
328
+ ## License
197
329
 
198
- ```bibtex
199
- @software{holosphere2024,
200
- author = {Roberto Valenti},
201
- title = {HoloSphere: Decentralized Geospatial Data Management},
202
- year = {2024},
203
- url = {https://github.com/holosphere/holosphere}
204
- }
205
- ```
330
+ GPL-3.0-or-later
206
331
 
@@ -0,0 +1,12 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "targets": {
7
+ "node": "current"
8
+ }
9
+ }
10
+ ]
11
+ ]
12
+ }
package/holosphere.d.ts CHANGED
@@ -1,22 +1,48 @@
1
1
  declare module 'holosphere' {
2
2
  export default class HoloSphere {
3
- constructor(name: string, openaikey?: string | null);
4
- subscribe(hex: string, lense: string, callback: (item: any, key: string) => void): void;
5
- put(hex: string, lense: string, content: any): Promise<void>;
6
- delete(id: string, tag: string): Promise<void>;
7
- get(hex: string, lense: string): Promise<any[]>;
8
- getKey(hex: string, lense: string, key: string): Promise<any | null>;
9
- getNode(hex: string, lense: string, key: string): Promise<any | null>;
10
- compute(hex: string, lense: string, operation: string): Promise<void>;
11
- clearlense(hex: string, lense: string): Promise<void>;
12
- summarize(history: string): Promise<string>;
13
- upcast(hex: string, lense: string, content: any): Promise<any>;
14
- updateParent(id: string, report: string): Promise<any>;
3
+ constructor(appName: string, strict?: boolean | null, openaikey?: string | null);
4
+
5
+ // User Management
6
+ createUser(username: string, password: string): Promise<object>;
7
+ login(username: string, password: string): Promise<object>;
8
+ logout(): Promise<void>;
9
+
10
+ // Schema Operations
11
+ setSchema(lens: string, schema: object): Promise<void>;
12
+ getSchema(lens: string): Promise<object | null>;
13
+
14
+ // Encryption Operations
15
+ encrypt(data: any, secret: string): Promise<string>;
16
+ decrypt(encryptedData: string, secret: string): Promise<any>;
17
+
18
+ // Hex Data Operations
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>;
36
+
37
+ // Geospatial Operations
15
38
  getHex(lat: number, lng: number, resolution: number): Promise<string>;
16
39
  getScalespace(lat: number, lng: number): string[];
17
40
  getHexScalespace(hex: string): string[];
18
- aggregateVotes(hexId: string, topic: string): object;
19
- delegateVote(userId: string, topic: string, delegateTo: string): Promise<void>;
20
- vote(userId: string, hexId: string, topic: string, vote: string): Promise<void>;
41
+ compute(hex: string, lens: string, operation: string): Promise<void>;
42
+ upcast(hex: string, lens: string, content: any): Promise<any>;
43
+
44
+ // Subscription
45
+ subscribe(holon: string, lens: string, callback: (data: any, key: string) => void): void;
46
+ subscribeGlobal(tableName: string, callback: (data: any, key: string) => void): void;
21
47
  }
22
48
  }