holosphere 1.0.6 → 1.0.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/LICENSE ADDED
@@ -0,0 +1,56 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+
6
+ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
7
+
8
+ This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
9
+
10
+ 0. Additional Definitions.
11
+ As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
12
+
13
+ “The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
14
+
15
+ An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
16
+
17
+ A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
18
+
19
+ The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
20
+
21
+ The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
22
+
23
+ 1. Exception to Section 3 of the GNU GPL.
24
+ You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
25
+
26
+ 2. Conveying Modified Versions.
27
+ If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
28
+
29
+ a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
30
+ b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
31
+ 3. Object Code Incorporating Material from Library Header Files.
32
+ The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
33
+
34
+ a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
35
+ b) Accompany the object code with a copy of the GNU GPL and this license document.
36
+ 4. Combined Works.
37
+ You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
38
+
39
+ a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
40
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
41
+ c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
42
+ d) Do one of the following:
43
+ 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
44
+ 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
45
+ e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
46
+ 5. Combined Libraries.
47
+ You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
48
+
49
+ a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
50
+ b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
51
+ 6. Revised Versions of the GNU Lesser General Public License.
52
+ The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
53
+
54
+ Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
55
+
56
+ If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
package/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # HoloSphere
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.
4
+
5
+ ## Features
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
13
+
14
+ ## License
15
+
16
+ GNU Lesser General Public License v3.0 (LGPL-3.0)
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.
19
+
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.
21
+
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/>.
23
+
24
+ ### Key Points of LGPL-3.0
25
+
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
31
+
32
+ ## Dependencies
33
+
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
39
+
40
+ ### Optional Dependencies
41
+ - **langchain**: AI/LLM integration framework
42
+ - **openai**: OpenAI API client (optional)
43
+
44
+ ## Getting Started
45
+
46
+ ```bash
47
+ npm install holosphere
48
+ ```
49
+
50
+ ## Basic Usage
51
+
52
+ ```javascript
53
+ import { HoloSphere } from 'holosphere';
54
+
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
+ });
60
+
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: {
68
+ temperature: 22.5,
69
+ timestamp: Date.now()
70
+ }
71
+ });
72
+
73
+ // Subscribe to changes
74
+ hex.subscribe(data => {
75
+ console.log('New data:', data);
76
+ });
77
+ ```
78
+
79
+ ## Advanced Features
80
+
81
+ ### Spatial Queries
82
+
83
+ ```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
+ });
90
+
91
+ // Query data across multiple resolutions
92
+ const aggregatedData = await holo.aggregate({
93
+ hexIds: hexagons,
94
+ resolution: 7,
95
+ method: 'average'
96
+ });
97
+ ```
98
+
99
+ ### AI Processing
100
+
101
+ ```javascript
102
+ // Process content with AI
103
+ const summary = await hex.processContent({
104
+ processor: 'summarize',
105
+ options: {
106
+ maxLength: 100
107
+ }
108
+ });
109
+
110
+ // Analyze trends across regions
111
+ const analysis = await holo.analyzeRegion({
112
+ hexIds: hexagons,
113
+ timeRange: '7d',
114
+ metrics: ['sentiment', 'topics']
115
+ });
116
+ ```
117
+
118
+ ### Voting and Governance
119
+
120
+ ```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
+ }
128
+ });
129
+
130
+ // Cast a vote
131
+ await proposal.vote({
132
+ support: true,
133
+ weight: 1.0
134
+ });
135
+ ```
136
+
137
+ ## Configuration
138
+
139
+ HoloSphere can be configured with various options:
140
+
141
+ ```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);
167
+ ```
168
+
169
+ ## Documentation
170
+
171
+ For detailed documentation, please visit our [documentation site](https://docs.holons.io).
172
+
173
+ ## Contributing
174
+
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
180
+
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
193
+
194
+ ## Citation
195
+
196
+ If you use HoloSphere in your research, please cite:
197
+
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
+ ```
206
+
@@ -0,0 +1 @@
1
+
package/holosphere.js CHANGED
@@ -31,18 +31,18 @@ class HoloSphere {
31
31
  }
32
32
 
33
33
  /**
34
- * Sets the JSON schema for a specific lense.
35
- * @param {string} lense - The lense identifier.
34
+ * Sets the JSON schema for a specific lens.
35
+ * @param {string} lens - The lens identifier.
36
36
  * @param {object} schema - The JSON schema to set.
37
37
  * @returns {Promise} - Resolves when the schema is set.
38
38
  */
39
- async setSchema(lense, schema) {
39
+ async setSchema(lens, schema) {
40
40
  return new Promise((resolve, reject) => {
41
- this.gun.get(lense).get('schema').put(JSON.stringify(schema), ack => {
41
+ this.gun.get(lens).get('schema').put(JSON.stringify(schema), ack => {
42
42
  if (ack.err) {
43
43
  resolve(new Error('Failed to add schema: ' + ack.err));
44
44
  } else {
45
- console.log('Schema added successfully under lense:', lense);
45
+ console.log('Schema added successfully under lens:', lens);
46
46
  resolve(ack);
47
47
  }
48
48
  })
@@ -50,13 +50,13 @@ class HoloSphere {
50
50
  }
51
51
 
52
52
  /**
53
- * Retrieves the JSON schema for a specific lense.
54
- * @param {string} lense - The lense identifier.
53
+ * Retrieves the JSON schema for a specific lens.
54
+ * @param {string} lens - The lens identifier.
55
55
  * @returns {Promise<object|null>} - The retrieved schema or null if not found.
56
56
  */
57
- async getSchema(lense) {
57
+ async getSchema(lens) {
58
58
  return new Promise((resolve) => {
59
- this.gun.get(lense).get('schema').once(data => {
59
+ this.gun.get(lens).get('schema').once(data => {
60
60
  if (data) {
61
61
  let parsed;
62
62
  try {
@@ -82,14 +82,16 @@ class HoloSphere {
82
82
  }
83
83
 
84
84
  /**
85
- * Stores content in the specified hex and lense.
85
+ * Stores content in the specified hex and lens.
86
86
  * @param {string} hex - The hex identifier.
87
- * @param {string} lense - The lense under which to store the content.
87
+ * @param {string} lens - The lens under which to store the content.
88
88
  * @param {object} content - The content to store.
89
89
  */
90
- async put(hex, lense, content) {
91
- // Retrieve the schema for the lense
92
- let schema = await this.getSchema(lense)
90
+ async put(hex, lens, content) {
91
+ if (!hex || !lens || !content) return;
92
+ console.error('Error in put:', hex, lens, content);
93
+ // Retrieve the schema for the lens
94
+ let schema = await this.getSchema(lens)
93
95
  if (schema) {
94
96
  // Validate the content against the schema
95
97
  const valid = this.validator.validate(schema, content);
@@ -105,68 +107,92 @@ class HoloSphere {
105
107
  let noderef;
106
108
 
107
109
  if (content.id) { //use the user-defined id. Important to be able to send updates using put
108
- noderef = this.gun.get(lense).get(content.id).put(payload)
109
- this.gun.get(hex.toString()).get(lense).get(content.id).put(payload)
110
+ noderef = this.gun.get(lens).get(content.id).put(payload)
111
+ this.gun.get(hex.toString()).get(lens).get(content.id).put(payload)
110
112
  } else { // create a content-addressable reference like IPFS. Note: no updates possible using put
111
113
  const hashBuffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(payload));
112
114
  const hashArray = Array.from(new Uint8Array(hashBuffer));
113
115
  const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, "0")).join("");
114
- noderef = this.gun.get(lense).get(hashHex).put(payload)
115
- this.gun.get(hex.toString()).get(lense).get(hashHex).put(payload)
116
+ noderef = this.gun.get(lens).get(hashHex).put(payload)
117
+ this.gun.get(hex.toString()).get(lens).get(hashHex).put(payload)
116
118
  }
117
119
 
118
120
  }
119
121
 
120
- async putNode(hex, lense, node) {
121
- this.gun.get(hex).get(lense).set(node)
122
+ async putNode(hex, lens, node) {
123
+ this.gun.get(hex).get(lens).set(node)
122
124
  }
123
125
 
124
126
  async parse(data) {
125
- var parsed = {}
126
-
127
- if (data._ && data._["#"]) {
128
- // If the data is a reference, fetch the actual content
129
- let query = data._['#'].split('/')
130
- let hex = query[1]
131
- let lense = query[2]
132
- let key = query[3]
133
- parsed = await this.getKey(hex, lense, key)
134
-
135
- } else
136
-
137
- try {
138
- parsed = JSON.parse(data);
139
- } catch (e) {
140
- console.log('Invalid JSON:', data);
141
- parsed = data //return the raw data
127
+ let parsed = {};
128
+
129
+ if (typeof data === 'object' && data !== null) {
130
+ if (data._ && data._["#"]) {
131
+ // If the data is a reference, fetch the actual content
132
+ let query = data._['#'].split('/');
133
+ let hex = query[1];
134
+ let lens = query[2];
135
+ let key = query[3];
136
+ parsed = await this.getKey(hex, lens, key);
137
+ } else if (data._ && data._['>']) {
138
+ // This might be a GunDB node, try to get its value
139
+ const nodeValue = Object.values(data).find(v => typeof v !== 'object' && v !== '_');
140
+ if (nodeValue) {
141
+ try {
142
+ parsed = JSON.parse(nodeValue);
143
+ } catch (e) {
144
+ console.log('Invalid JSON in node value:', nodeValue);
145
+ parsed = nodeValue; // return the raw data
146
+ }
147
+ } else {
148
+ console.log('Unable to parse GunDB node:', data);
149
+ parsed = data; // return the original data
150
+ }
151
+ } else {
152
+ // Treat it as regular data
153
+ parsed = data;
154
+ }
155
+ } else {
156
+ // If it's not an object, try parsing it as JSON
157
+ try {
158
+ parsed = JSON.parse(data);
159
+ } catch (e) {
160
+ console.log('Invalid JSON:', data);
161
+ parsed = data; // return the raw data
162
+ }
142
163
  }
143
- return parsed
164
+
165
+ return parsed;
144
166
  }
145
167
 
146
168
  /**
147
- * Retrieves content from the specified hex and lense.
169
+ * Retrieves content from the specified hex and lens.
148
170
  * @param {string} hex - The hex identifier.
149
- * @param {string} lense - The lense from which to retrieve content.
171
+ * @param {string} lens - The lens from which to retrieve content.
150
172
  * @returns {Promise<Array<object>>} - The retrieved content.
151
173
  */
152
- async get(hex, lense) {
174
+ async get(hex, lens) {
175
+ if (!hex || !lens) {
176
+ console.log('Wrong get:', hex, lens)
177
+ return;
178
+ }
153
179
  // Wrap the GunDB operation in a promise
154
- //retrieve lense schema
155
- const schema = await this.getSchema(lense);
180
+ //retrieve lens schema
181
+ const schema = await this.getSchema(lens);
156
182
 
157
183
  if (!schema) {
158
- console.log('The schema for "' + lense + '" is not defined');
184
+ console.log('The schema for "' + lens + '" is not defined');
159
185
  // return null; // No schema found, return null if strict about it
160
186
  }
161
187
 
162
188
  return new Promise(async (resolve, reject) => {
163
189
  let output = []
164
190
  let counter = 0
165
- this.gun.get(hex.toString()).get(lense).once((data, key) => {
191
+ this.gun.get(hex.toString()).get(lens).once((data, key) => {
166
192
  if (data) {
167
193
  const maplenght = Object.keys(data).length - 1
168
194
  console.log('Map length:', maplenght)
169
- this.gun.get(hex.toString()).get(lense).map().once(async (itemdata, key) => {
195
+ this.gun.get(hex.toString()).get(lens).map().once(async (itemdata, key) => {
170
196
  counter += 1
171
197
  if (itemdata) {
172
198
  let parsed = await this.parse (itemdata)
@@ -176,7 +202,7 @@ class HoloSphere {
176
202
  let valid = this.validator.validate(schema, parsed);
177
203
  if (!valid || parsed == null || parsed == undefined) {
178
204
  console.log('Removing Invalid content:', this.validator.errors);
179
- this.gun.get(hex).get(lense).get(key).put(null);
205
+ this.gun.get(hex).get(lens).get(key).put(null);
180
206
 
181
207
  } else {
182
208
  output.push(parsed);
@@ -199,18 +225,26 @@ class HoloSphere {
199
225
  }
200
226
 
201
227
  /**
202
- * Retrieves a specific key from the specified hex and lense.
228
+ * Retrieves a specific key from the specified hex and lens.
203
229
  * @param {string} hex - The hex identifier.
204
- * @param {string} lense - The lense from which to retrieve the key.
230
+ * @param {string} lens - The lens from which to retrieve the key.
205
231
  * @param {string} key - The specific key to retrieve.
206
232
  * @returns {Promise<object|null>} - The retrieved content or null if not found.
207
233
  */
208
- async getKey(hex, lense, key) {
234
+ async getKey(hex, lens, key) {
209
235
  return new Promise((resolve) => {
210
236
  // Use Gun to get the data
211
- this.gun.get(hex).get(lense).get(key).once((data, key) => {
237
+ this.gun.get(hex).get(lens).get(key).once((data, key) => {
212
238
  if (data) {
213
- resolve(JSON.parse(data)); // Resolve the promise with the data if data is found
239
+ console.log('Data getting parsed:', data)
240
+ try {
241
+ let parsed = JSON.parse(data); // Resolve the promise with the data if data is found
242
+ resolve(parsed);
243
+ }
244
+ catch (e) {
245
+ resolve(data)
246
+ }
247
+
214
248
  } else {
215
249
  resolve(null); // Reject the promise if no data is found
216
250
  }
@@ -220,26 +254,26 @@ class HoloSphere {
220
254
  }
221
255
 
222
256
  /**
223
- * Retrieves a specific gundb node from the specified hex and lense.
257
+ * Retrieves a specific gundb node from the specified hex and lens.
224
258
  * @param {string} hex - The hex identifier.
225
- * @param {string} lense - The lense from which to retrieve the key.
259
+ * @param {string} lens - The lens from which to retrieve the key.
226
260
  * @param {string} key - The specific key to retrieve.
227
261
  * @returns {Promise<object|null>} - The retrieved content or null if not found.
228
262
  */
229
- getNode(hex, lense, key) {
263
+ getNode(hex, lens, key) {
230
264
  // Use Gun to get the data
231
- return this.gun.get(hex).get(lense).get(key)
265
+ return this.gun.get(hex).get(lens).get(key)
232
266
  }
233
267
 
234
268
 
235
269
 
236
270
  /**
237
- * Computes summaries based on the content within a hex and lense.
271
+ * Computes summaries based on the content within a hex and lens.
238
272
  * @param {string} hex - The hex identifier.
239
- * @param {string} lense - The lense to compute.
273
+ * @param {string} lens - The lens to compute.
240
274
  * @param {string} operation - The operation to perform.
241
275
  */
242
- async compute(hex, lense, operation) {
276
+ async compute(hex, lens, operation) {
243
277
 
244
278
  let res = h3.getResolution(hex);
245
279
  if (res < 1 || res > 15) return;
@@ -258,7 +292,7 @@ class HoloSphere {
258
292
  resolve(); // Resolve the promise to prevent it from hanging
259
293
  }, 1000); // Timeout of 5 seconds
260
294
 
261
- this.gun.get(siblings[i]).get(lense).map().once((data, key) => {
295
+ this.gun.get(siblings[i]).get(lens).map().once((data, key) => {
262
296
  clearTimeout(timeout); // Clear the timeout if data is received
263
297
  if (data) {
264
298
  content.push(data.content);
@@ -274,23 +308,23 @@ class HoloSphere {
274
308
  console.log('Computed:', computed)
275
309
  let node = await this.gun.get(parent + '_summary').put({ id: parent + '_summary', content: computed })
276
310
 
277
- this.put(parent, lense, node);
278
- this.compute(parent, lense, operation)
311
+ this.put(parent, lens, node);
312
+ this.compute(parent, lens, operation)
279
313
  }
280
314
 
281
315
  /**
282
- * Clears all entities under a specific hex and lense.
316
+ * Clears all entities under a specific hex and lens.
283
317
  * @param {string} hex - The hex identifier.
284
- * @param {string} lense - The lense to clear.
318
+ * @param {string} lens - The lens to clear.
285
319
  */
286
- async clearlense(hex, lense) {
320
+ async clearlens(hex, lens) {
287
321
  let entities = {};
288
322
 
289
323
  // Get list out of Gun
290
- this.gun.get(hex).get(lense).map().once((data, key) => {
324
+ this.gun.get(hex).get(lens).map().once((data, key) => {
291
325
  //entities = data;
292
326
  //const id = Object.keys(entities)[0] // since this would be in object form, you can manipulate it as you would like.
293
- this.gun.get(hex).get(lense).put({ [key]: null })
327
+ this.gun.get(hex).get(lens).put({ [key]: null })
294
328
  })
295
329
  }
296
330
 
@@ -335,21 +369,21 @@ class HoloSphere {
335
369
  /**
336
370
  * Upcasts content to parent hexagons recursively.
337
371
  * @param {string} hex - The current hex identifier.
338
- * @param {string} lense - The lense under which to upcast.
372
+ * @param {string} lens - The lens under which to upcast.
339
373
  * @param {object} content - The content to upcast.
340
374
  * @returns {Promise<object>} - The upcasted content.
341
375
  */
342
- async upcast(hex, lense, content) {
376
+ async upcast(hex, lens, content) {
343
377
  let res = h3.getResolution(hex)
344
378
  if (res == 0) {
345
- await this.putNode(hex, lense, content)
379
+ await this.putNode(hex, lens, content)
346
380
  return content
347
381
  }
348
382
  else {
349
- console.log('Upcasting ', hex, lense, content, res)
350
- await this.putNode(hex, lense, content)
383
+ console.log('Upcasting ', hex, lens, content, res)
384
+ await this.putNode(hex, lens, content)
351
385
  let parent = h3.cellToParent(hex, res - 1)
352
- return this.upcast(parent, lense, content)
386
+ return this.upcast(parent, lens, content)
353
387
  }
354
388
  }
355
389
 
@@ -417,13 +451,13 @@ class HoloSphere {
417
451
  }
418
452
 
419
453
  /**
420
- * Subscribes to changes in a specific hex and lense.
454
+ * Subscribes to changes in a specific hex and lens.
421
455
  * @param {string} hex - The hex identifier.
422
- * @param {string} lense - The lense to subscribe to.
456
+ * @param {string} lens - The lens to subscribe to.
423
457
  * @param {function} callback - The callback to execute on changes.
424
458
  */
425
- subscribe(hex, lense, callback) {
426
- this.gun.get(hex).get(lense).map().on((data, key) => {
459
+ subscribe(hex, lens, callback) {
460
+ this.gun.get(hex).get(lens).map().on((data, key) => {
427
461
  callback(data, key)
428
462
  })
429
463
  }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "holosphere",
3
- "version": "1.0.6",
4
- "description": "Holonic Geospatial Communication Infrastructure based on h3.js and gun.js",
3
+ "version": "1.0.7",
4
+ "description": "Holonic Geospatial Communication Infrastructure",
5
5
  "main": "holosphere.js",
6
+ "types": "holosphere.d.ts",
6
7
  "type": "module",
7
8
  "scripts": {
8
9
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -0,0 +1,32 @@
1
+ import HoloSphere from '../holosphere.js';
2
+
3
+ describe('HoloSphere', () => {
4
+ let holoSphere;
5
+
6
+ beforeEach(() => {
7
+ holoSphere = new HoloSphere('test-app', {
8
+ gunPeers: ['http://localhost:8765/gun'],
9
+ });
10
+ });
11
+
12
+ test('initialization', () => {
13
+ expect(holoSphere).toBeDefined();
14
+ expect(holoSphere.users).toEqual({});
15
+ expect(holoSphere.hexagonVotes).toEqual({});
16
+ });
17
+
18
+ test('voting system', async () => {
19
+ const userId = 'test-user';
20
+ const hexId = '8928308280fffff';
21
+ const topic = 'test-topic';
22
+ const vote = 'yes';
23
+
24
+ await holoSphere.initializeUser(userId);
25
+ await holoSphere.vote(userId, hexId, topic, vote);
26
+
27
+ const votes = holoSphere.aggregateVotes(hexId, topic);
28
+ expect(votes).toHaveProperty('yes', 1);
29
+ });
30
+
31
+ // Add more tests...
32
+ });