holosphere 1.1.0 → 1.1.1
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/holosphere.d.ts +43 -48
- package/holosphere.js +248 -120
- package/package.json +4 -2
package/holosphere.d.ts
CHANGED
|
@@ -1,48 +1,43 @@
|
|
|
1
|
-
declare
|
|
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
|
-
// 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;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
declare class HoloSphere {
|
|
2
|
+
private appname;
|
|
3
|
+
private strict;
|
|
4
|
+
private validator;
|
|
5
|
+
private gun;
|
|
6
|
+
private openai?;
|
|
7
|
+
/**
|
|
8
|
+
* Initializes a new instance of the HoloSphere class.
|
|
9
|
+
* @param {string} appname - The name of the application.
|
|
10
|
+
* @param {boolean} strict - Whether to enforce strict schema validation.
|
|
11
|
+
* @param {string|null} openaikey - The OpenAI API key.
|
|
12
|
+
*/
|
|
13
|
+
constructor(appname: string, strict?: boolean, openaikey?: string | null);
|
|
14
|
+
setSchema(lens: string, schema: object): Promise<boolean>;
|
|
15
|
+
getSchema(lens: string): Promise<object | null>;
|
|
16
|
+
put(holon: string, lens: string, data: object): Promise<boolean>;
|
|
17
|
+
get(holon: string, lens: string, key: string): Promise<any | null>;
|
|
18
|
+
getAll(holon: string, lens: string): Promise<Array<any>>;
|
|
19
|
+
delete(holon: string, lens: string, key: string): Promise<void>;
|
|
20
|
+
deleteAll(holon: string, lens: string): Promise<boolean>;
|
|
21
|
+
putNode(holon: string, lens: string, node: object): Promise<boolean>;
|
|
22
|
+
getNode(holon: string, lens: string, key: string): Promise<any | null>;
|
|
23
|
+
deleteNode(holon: string, lens: string, key: string): Promise<boolean>;
|
|
24
|
+
putGlobal(tableName: string, data: object): Promise<void>;
|
|
25
|
+
getGlobal(tableName: string, key: string): Promise<object | null>;
|
|
26
|
+
getAllGlobal(tableName: string): Promise<object | null>;
|
|
27
|
+
deleteGlobal(tableName: string, key: string): Promise<void>;
|
|
28
|
+
deleteAllGlobal(tableName: string): Promise<void>;
|
|
29
|
+
getHolon(lat: number, lng: number, resolution: number): Promise<string>;
|
|
30
|
+
getScalespace(lat: number, lng: number): string[];
|
|
31
|
+
getHolonScalespace(holon: string): string[];
|
|
32
|
+
compute(holon: string, lens: string, operation: string): Promise<void>;
|
|
33
|
+
private parse;
|
|
34
|
+
subscribe(holon: string, lens: string, callback: (data: any, key: string) => void): void;
|
|
35
|
+
subscribeGlobal(tableName: string, callback: (data: any, key: string) => void): void;
|
|
36
|
+
/**
|
|
37
|
+
* Summarizes provided history text using OpenAI.
|
|
38
|
+
* @param {string} history - The history text to summarize.
|
|
39
|
+
* @returns {Promise<string>} - The summarized text.
|
|
40
|
+
*/
|
|
41
|
+
private summarize;
|
|
42
|
+
}
|
|
43
|
+
export default HoloSphere;
|
package/holosphere.js
CHANGED
|
@@ -3,6 +3,7 @@ import OpenAI from 'openai';
|
|
|
3
3
|
import Gun from 'gun'
|
|
4
4
|
import Ajv2019 from 'ajv/dist/2019.js'
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
class HoloSphere {
|
|
7
8
|
/**
|
|
8
9
|
* Initializes a new instance of the HoloSphere class.
|
|
@@ -13,13 +14,13 @@ class HoloSphere {
|
|
|
13
14
|
constructor(appname, strict = false, openaikey = null) {
|
|
14
15
|
this.appname = appname
|
|
15
16
|
this.strict = strict;
|
|
16
|
-
this.validator = new Ajv2019({
|
|
17
|
+
this.validator = new Ajv2019({
|
|
17
18
|
allErrors: true,
|
|
18
19
|
strict: false, // Keep this false to avoid Ajv strict mode issues
|
|
19
20
|
validateSchema: true // Always validate schemas
|
|
20
21
|
});
|
|
21
22
|
this.gun = Gun({
|
|
22
|
-
peers: ['
|
|
23
|
+
peers: ['https://gun.holons.io', 'https://59.src.eco/gun'],
|
|
23
24
|
axe: false,
|
|
24
25
|
// uuid: (content) => { // generate a unique id for each node
|
|
25
26
|
// console.log('uuid', content);
|
|
@@ -61,7 +62,7 @@ class HoloSphere {
|
|
|
61
62
|
required: ['type', 'properties'],
|
|
62
63
|
properties: {
|
|
63
64
|
type: { type: 'string' },
|
|
64
|
-
properties: {
|
|
65
|
+
properties: {
|
|
65
66
|
type: 'object',
|
|
66
67
|
additionalProperties: {
|
|
67
68
|
type: 'object',
|
|
@@ -142,16 +143,16 @@ class HoloSphere {
|
|
|
142
143
|
resolve(null);
|
|
143
144
|
return;
|
|
144
145
|
}
|
|
145
|
-
|
|
146
|
+
|
|
146
147
|
try {
|
|
147
148
|
// If data is already a string, parse it
|
|
148
149
|
if (typeof data === 'string') {
|
|
149
150
|
resolve(JSON.parse(data));
|
|
150
|
-
}
|
|
151
|
+
}
|
|
151
152
|
// If data is an object with a string value (GunDB format)
|
|
152
153
|
else if (typeof data === 'object' && data !== null) {
|
|
153
|
-
const schemaStr = Object.values(data).find(v =>
|
|
154
|
-
typeof v === 'string' && v.includes('"type":'));
|
|
154
|
+
const schemaStr = Object.values(data).find(v =>
|
|
155
|
+
typeof v === 'string' && v.includes('"type":'));
|
|
155
156
|
if (schemaStr) {
|
|
156
157
|
resolve(JSON.parse(schemaStr));
|
|
157
158
|
} else {
|
|
@@ -210,7 +211,7 @@ class HoloSphere {
|
|
|
210
211
|
return new Promise((resolve) => {
|
|
211
212
|
try {
|
|
212
213
|
const payload = JSON.stringify(data);
|
|
213
|
-
|
|
214
|
+
|
|
214
215
|
this.gun.get(this.appname)
|
|
215
216
|
.get(holon)
|
|
216
217
|
.get(lens)
|
|
@@ -251,7 +252,7 @@ class HoloSphere {
|
|
|
251
252
|
return new Promise((resolve) => {
|
|
252
253
|
let output = [];
|
|
253
254
|
let counter = 0;
|
|
254
|
-
|
|
255
|
+
|
|
255
256
|
this.gun.get(this.appname).get(holon).get(lens).once((data, key) => {
|
|
256
257
|
if (!data) {
|
|
257
258
|
resolve(output);
|
|
@@ -259,13 +260,12 @@ class HoloSphere {
|
|
|
259
260
|
}
|
|
260
261
|
|
|
261
262
|
const mapLength = Object.keys(data).length - 1;
|
|
262
|
-
|
|
263
|
+
|
|
263
264
|
this.gun.get(this.appname).get(holon).get(lens).map().once(async (itemdata, key) => {
|
|
264
265
|
counter += 1;
|
|
265
266
|
if (itemdata) {
|
|
266
267
|
try {
|
|
267
|
-
const parsed =
|
|
268
|
-
|
|
268
|
+
const parsed = await this.parse(itemdata);
|
|
269
269
|
if (schema) {
|
|
270
270
|
const valid = this.validator.validate(schema, parsed);
|
|
271
271
|
if (valid) {
|
|
@@ -296,6 +296,65 @@ class HoloSphere {
|
|
|
296
296
|
});
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
+
/**
|
|
300
|
+
* Parses data from GunDB, handling various data formats and references.
|
|
301
|
+
* @param {*} data - The data to parse, could be a string, object, or GunDB reference.
|
|
302
|
+
* @returns {Promise<object>} - The parsed data.
|
|
303
|
+
*/
|
|
304
|
+
async parse(rawData) {
|
|
305
|
+
let parsedData = {};
|
|
306
|
+
if (rawData.soul) {
|
|
307
|
+
console.log('Parsing link:', rawData.soul);
|
|
308
|
+
this.getNodeRef(rawData.soul).once (data => {return JSON.parse(data)});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (typeof rawData === 'object' && rawData !== null) {
|
|
312
|
+
if (rawData._ && rawData._["#"]) {
|
|
313
|
+
console.log('Parsing object reference:', rawData._['#']);
|
|
314
|
+
// If the data is a reference, fetch the actual content
|
|
315
|
+
let pathParts = rawData._['#'].split('/');
|
|
316
|
+
let hexId = pathParts[1];
|
|
317
|
+
let lensId = pathParts[2];
|
|
318
|
+
let dataKey = pathParts[3];
|
|
319
|
+
parsedData = await this.get(hexId, lensId, dataKey);
|
|
320
|
+
} else if (rawData._ && rawData._['>']) {
|
|
321
|
+
console.log('Parsing objectnode:', rawData._['>']);
|
|
322
|
+
// This might be a GunDB node, try to get its value
|
|
323
|
+
const nodeValue = Object.values(rawData).find(v => typeof v !== 'object' && v !== '_');
|
|
324
|
+
if (nodeValue) {
|
|
325
|
+
try {
|
|
326
|
+
parsedData = JSON.parse(nodeValue);
|
|
327
|
+
} catch (e) {
|
|
328
|
+
console.log('Invalid JSON in node value:', nodeValue);
|
|
329
|
+
parsedData = nodeValue; // return the raw data
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
console.log('Unable to parse GunDB node:', rawData);
|
|
333
|
+
parsedData = rawData; // return the original data
|
|
334
|
+
}
|
|
335
|
+
} else {
|
|
336
|
+
// Treat it as object data
|
|
337
|
+
console.log('Parsing object data:', rawData);
|
|
338
|
+
parsedData = rawData;
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
// If it's not an object, try parsing it as JSON
|
|
342
|
+
try {
|
|
343
|
+
parsedData = JSON.parse(rawData);
|
|
344
|
+
//if the data has a soul, return the soul node
|
|
345
|
+
if (parsedData.soul) {
|
|
346
|
+
console.log('Parsing link:', parsedData.soul);
|
|
347
|
+
parsedData = await this.get(parsedData.soul.split('/')[1], parsedData.soul.split('/')[2], parsedData.soul.split('/')[3]);
|
|
348
|
+
}
|
|
349
|
+
} catch (e) {
|
|
350
|
+
console.log('Failed to parse, returning raw data', e);
|
|
351
|
+
parsedData = rawData; // return the raw data
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return parsedData;
|
|
356
|
+
}
|
|
357
|
+
|
|
299
358
|
/**
|
|
300
359
|
* Retrieves a specific key from the specified holon and lens.
|
|
301
360
|
* @param {string} holon - The holon identifier.
|
|
@@ -322,17 +381,17 @@ class HoloSphere {
|
|
|
322
381
|
.get(holon)
|
|
323
382
|
.get(lens)
|
|
324
383
|
.get(key)
|
|
325
|
-
.once((data) => {
|
|
384
|
+
.once((data,key) => {
|
|
326
385
|
clearTimeout(timeout);
|
|
327
|
-
|
|
386
|
+
|
|
328
387
|
if (!data) {
|
|
329
388
|
resolve(null);
|
|
330
389
|
return;
|
|
331
390
|
}
|
|
332
391
|
|
|
333
392
|
try {
|
|
334
|
-
const parsed =
|
|
335
|
-
|
|
393
|
+
const parsed = this.parse(data);
|
|
394
|
+
|
|
336
395
|
// Validate against schema if one exists
|
|
337
396
|
if (schema) {
|
|
338
397
|
const valid = this.validator.validate(schema, parsed);
|
|
@@ -344,7 +403,6 @@ class HoloSphere {
|
|
|
344
403
|
}
|
|
345
404
|
}
|
|
346
405
|
}
|
|
347
|
-
|
|
348
406
|
resolve(parsed);
|
|
349
407
|
} catch (error) {
|
|
350
408
|
console.error('Error parsing data:', error);
|
|
@@ -360,17 +418,17 @@ class HoloSphere {
|
|
|
360
418
|
* @param {string} lens - The lens from which to delete the key.
|
|
361
419
|
* @param {string} key - The specific key to delete.
|
|
362
420
|
*/
|
|
363
|
-
async delete
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
});
|
|
421
|
+
async delete(holon, lens, key) {
|
|
422
|
+
return new Promise((resolve, reject) => {
|
|
423
|
+
this.gun.get(this.appname).get(holon).get(lens).get(key).put(null, ack => {
|
|
424
|
+
if (ack.err) {
|
|
425
|
+
resolve(ack.err);
|
|
426
|
+
} else {
|
|
427
|
+
resolve(ack.ok);
|
|
428
|
+
}
|
|
372
429
|
});
|
|
373
|
-
}
|
|
430
|
+
});
|
|
431
|
+
}
|
|
374
432
|
|
|
375
433
|
/**
|
|
376
434
|
* Deletes all keys from a given holon and lens.
|
|
@@ -386,7 +444,7 @@ class HoloSphere {
|
|
|
386
444
|
|
|
387
445
|
return new Promise((resolve) => {
|
|
388
446
|
let deletionPromises = [];
|
|
389
|
-
|
|
447
|
+
|
|
390
448
|
// First get all the data to find keys to delete
|
|
391
449
|
this.gun.get(this.appname).get(holon).get(lens).once((data) => {
|
|
392
450
|
if (!data) {
|
|
@@ -396,7 +454,7 @@ class HoloSphere {
|
|
|
396
454
|
|
|
397
455
|
// Get all keys except Gun's metadata key '_'
|
|
398
456
|
const keys = Object.keys(data).filter(key => key !== '_');
|
|
399
|
-
|
|
457
|
+
|
|
400
458
|
// Create deletion promises for each key
|
|
401
459
|
keys.forEach(key => {
|
|
402
460
|
deletionPromises.push(
|
|
@@ -432,8 +490,17 @@ class HoloSphere {
|
|
|
432
490
|
* @param {object} node - The node to store.
|
|
433
491
|
*/
|
|
434
492
|
async putNode(holon, lens, node) {
|
|
435
|
-
|
|
436
|
-
|
|
493
|
+
return new Promise((resolve) => {
|
|
494
|
+
this.gun.get(this.appname).get(holon).get(lens).put(node, ack => {
|
|
495
|
+
if (ack.err) {
|
|
496
|
+
console.error("Error adding data to GunDB:", ack.err);
|
|
497
|
+
resolve(false);
|
|
498
|
+
} else {
|
|
499
|
+
resolve(true);
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
}
|
|
437
504
|
|
|
438
505
|
/**
|
|
439
506
|
* Retrieves a specific gun node from the specified holon and lens.
|
|
@@ -442,27 +509,26 @@ class HoloSphere {
|
|
|
442
509
|
* @param {string} key - The specific key to retrieve.
|
|
443
510
|
* @returns {Promise<object|null>} - The retrieved node or null if not found.
|
|
444
511
|
*/
|
|
445
|
-
|
|
512
|
+
getNode(holon, lens, key) {
|
|
446
513
|
if (!holon || !lens || !key) {
|
|
447
514
|
console.error('getNode: Missing required parameters');
|
|
448
515
|
return null;
|
|
449
516
|
}
|
|
450
517
|
|
|
451
|
-
return
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}, 5000);
|
|
518
|
+
return this.gun.get(this.appname)
|
|
519
|
+
.get(holon)
|
|
520
|
+
.get(lens)
|
|
521
|
+
.get(key)
|
|
456
522
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
});
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
getNodeRef(soul) {
|
|
526
|
+
const parts = soul.split('/');
|
|
527
|
+
let ref = this.gun.get(this.appname);
|
|
528
|
+
parts.forEach(part => {
|
|
529
|
+
ref = ref.get(part);
|
|
465
530
|
});
|
|
531
|
+
return ref;
|
|
466
532
|
}
|
|
467
533
|
|
|
468
534
|
/**
|
|
@@ -503,32 +569,32 @@ class HoloSphere {
|
|
|
503
569
|
*/
|
|
504
570
|
async putGlobal(tableName, data) {
|
|
505
571
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
572
|
+
return new Promise((resolve, reject) => {
|
|
573
|
+
if (!tableName || !data) {
|
|
574
|
+
reject(new Error('Table name and data are required'));
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
511
577
|
|
|
512
578
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
579
|
+
if (data.id) {
|
|
580
|
+
this.gun.get(this.appname).get(tableName).get(data.id).put(JSON.stringify(data), ack => {
|
|
581
|
+
if (ack.err) {
|
|
582
|
+
reject(new Error(ack.err));
|
|
583
|
+
} else {
|
|
584
|
+
resolve();
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
} else {
|
|
588
|
+
this.gun.get(this.appname).get(tableName).put(JSON.stringify(data), ack => {
|
|
589
|
+
if (ack.err) {
|
|
590
|
+
reject(new Error(ack.err));
|
|
591
|
+
} else {
|
|
592
|
+
resolve();
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}
|
|
532
598
|
|
|
533
599
|
/**
|
|
534
600
|
* Retrieves a specific key from a global table.
|
|
@@ -537,21 +603,21 @@ class HoloSphere {
|
|
|
537
603
|
* @returns {Promise<object|null>} - The parsed data for the key or null if not found.
|
|
538
604
|
*/
|
|
539
605
|
async getGlobal(tableName, key) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
});
|
|
606
|
+
return new Promise((resolve) => {
|
|
607
|
+
this.gun.get(this.appname).get(tableName).get(key).once((data) => {
|
|
608
|
+
if (!data) {
|
|
609
|
+
resolve(null);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
try {
|
|
613
|
+
const parsed = this.parse(data);
|
|
614
|
+
resolve(parsed);
|
|
615
|
+
} catch (e) {
|
|
616
|
+
resolve(null);
|
|
617
|
+
}
|
|
553
618
|
});
|
|
554
|
-
}
|
|
619
|
+
});
|
|
620
|
+
}
|
|
555
621
|
|
|
556
622
|
|
|
557
623
|
|
|
@@ -560,31 +626,91 @@ class HoloSphere {
|
|
|
560
626
|
* @param {string} tableName - The table name to retrieve data from.
|
|
561
627
|
* @returns {Promise<object|null>} - The parsed data from the table or null if not found.
|
|
562
628
|
*/
|
|
563
|
-
async getAllGlobal(tableName) {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
629
|
+
// async getAllGlobal(tableName) {
|
|
630
|
+
// return new Promise(async (resolve, reject) => {
|
|
631
|
+
// let output = []
|
|
632
|
+
// let counter = 0
|
|
633
|
+
// this.gun.get(this.appname).get(tableName.toString()).once((data, key) => {
|
|
634
|
+
// if (data) {
|
|
635
|
+
// const maplenght = Object.keys(data).length - 1
|
|
636
|
+
// this.gun.get(this.appname).get(tableName.toString()).map().once(async (itemdata, key) => {
|
|
637
|
+
|
|
638
|
+
// counter += 1
|
|
639
|
+
// if (itemdata) {
|
|
640
|
+
// let parsed = await this.parse(itemdata)
|
|
641
|
+
// output.push(parsed);
|
|
642
|
+
// console.log('getAllGlobal: parsed: ', parsed)
|
|
643
|
+
// }
|
|
644
|
+
|
|
645
|
+
// if (counter == maplenght) {
|
|
646
|
+
// resolve(output);
|
|
647
|
+
|
|
648
|
+
// }
|
|
649
|
+
// }
|
|
650
|
+
// );
|
|
651
|
+
// } else resolve(output)
|
|
652
|
+
// })
|
|
653
|
+
// }
|
|
654
|
+
// )
|
|
655
|
+
// }
|
|
656
|
+
async getAllGlobal(lens) {
|
|
657
|
+
if ( !lens) {
|
|
658
|
+
console.error('getAll: Missing required parameters:', { lens });
|
|
659
|
+
return [];
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const schema = await this.getSchema(lens);
|
|
663
|
+
if (!schema && this.strict) {
|
|
664
|
+
console.error('getAll: Schema required in strict mode for lens:', lens);
|
|
665
|
+
return [];
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
return new Promise((resolve) => {
|
|
669
|
+
let output = [];
|
|
670
|
+
let counter = 0;
|
|
671
|
+
|
|
672
|
+
this.gun.get(this.appname).get(lens).once((data, key) => {
|
|
673
|
+
if (!data) {
|
|
674
|
+
resolve(output);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
const mapLength = Object.keys(data).length - 1;
|
|
679
|
+
|
|
680
|
+
this.gun.get(this.appname).get(lens).map().once(async (itemdata, key) => {
|
|
681
|
+
counter += 1;
|
|
682
|
+
if (itemdata) {
|
|
683
|
+
try {
|
|
684
|
+
const parsed = await this.parse(itemdata);
|
|
685
|
+
if (schema) {
|
|
686
|
+
const valid = this.validator.validate(schema, parsed);
|
|
687
|
+
if (valid) {
|
|
688
|
+
output.push(parsed);
|
|
689
|
+
} else if (this.strict) {
|
|
690
|
+
console.warn('Invalid data removed:', key, this.validator.errors);
|
|
691
|
+
await this.delete(holon, lens, key);
|
|
692
|
+
} else {
|
|
693
|
+
console.warn('Invalid data found:', key, this.validator.errors);
|
|
694
|
+
output.push(parsed);
|
|
695
|
+
}
|
|
696
|
+
} else {
|
|
574
697
|
output.push(parsed);
|
|
575
698
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
699
|
+
} catch (error) {
|
|
700
|
+
console.error('Error parsing data:', error);
|
|
701
|
+
if (this.strict) {
|
|
702
|
+
await this.delete(holon, lens, key);
|
|
579
703
|
}
|
|
580
704
|
}
|
|
581
|
-
|
|
582
|
-
} else resolve(output)
|
|
583
|
-
})
|
|
584
|
-
}
|
|
585
|
-
)
|
|
586
|
-
}
|
|
705
|
+
}
|
|
587
706
|
|
|
707
|
+
if (counter === mapLength) {
|
|
708
|
+
resolve(output);
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
});
|
|
713
|
+
}
|
|
588
714
|
/**
|
|
589
715
|
* Deletes a specific key from a global table.
|
|
590
716
|
* @param {string} tableName - The table name to delete from.
|
|
@@ -592,8 +718,8 @@ class HoloSphere {
|
|
|
592
718
|
* @returns {Promise<void>}
|
|
593
719
|
*/
|
|
594
720
|
async deleteGlobal(tableName, key) {
|
|
595
|
-
|
|
596
|
-
|
|
721
|
+
await this.gun.get(this.appname).get(tableName).get(key).put(null)
|
|
722
|
+
}
|
|
597
723
|
|
|
598
724
|
/**
|
|
599
725
|
* Deletes an entire global table.
|
|
@@ -601,16 +727,17 @@ class HoloSphere {
|
|
|
601
727
|
* @returns {Promise<void>}
|
|
602
728
|
*/
|
|
603
729
|
async deleteAllGlobal(tableName) {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
this.gun.get(this.appname).get(tableName).
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
});
|
|
613
|
-
}
|
|
730
|
+
// return new Promise((resolve) => {
|
|
731
|
+
this.gun.get(this.appname).get(tableName).map().once( (data, key)=> {
|
|
732
|
+
this.gun.get(this.appname).get(tableName).get(key).put(null)
|
|
733
|
+
})
|
|
734
|
+
this.gun.get(this.appname).get(tableName).put(null, ack => {
|
|
735
|
+
console.log('deleteAllGlobal: ack: ', ack)
|
|
736
|
+
})
|
|
737
|
+
// resolve();
|
|
738
|
+
//});
|
|
739
|
+
// });
|
|
740
|
+
}
|
|
614
741
|
|
|
615
742
|
// ================================ COMPUTE FUNCTIONS ================================
|
|
616
743
|
/**
|
|
@@ -621,8 +748,8 @@ class HoloSphere {
|
|
|
621
748
|
*/
|
|
622
749
|
async compute(holon, lens, operation) {
|
|
623
750
|
|
|
624
|
-
|
|
625
|
-
|
|
751
|
+
let res = h3.getResolution(holon);
|
|
752
|
+
if (res < 1 || res > 15) return;
|
|
626
753
|
console.log(res)
|
|
627
754
|
let parent = h3.cellToParent(holon, res - 1);
|
|
628
755
|
let siblings = h3.cellToChildren(parent, res);
|
|
@@ -802,9 +929,10 @@ class HoloSphere {
|
|
|
802
929
|
* @param {string} lens - The lens to subscribe to.
|
|
803
930
|
* @param {function} callback - The callback to execute on changes.
|
|
804
931
|
*/
|
|
805
|
-
subscribe(holon, lens, callback) {
|
|
806
|
-
this.gun.get(this.appname).get(holon).get(lens).map().on((data, key) => {
|
|
807
|
-
|
|
932
|
+
async subscribe(holon, lens, callback) {
|
|
933
|
+
this.gun.get(this.appname).get(holon).get(lens).map().on(async (data, key) => {
|
|
934
|
+
if (data)
|
|
935
|
+
callback( await this.parse(data), key)
|
|
808
936
|
})
|
|
809
937
|
}
|
|
810
938
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "holosphere",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Holonic Geospatial Communication Infrastructure",
|
|
5
5
|
"main": "holosphere.js",
|
|
6
6
|
"types": "holosphere.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
9
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
10
|
+
"build": "",
|
|
11
|
+
"prepare": "npm run build"
|
|
10
12
|
},
|
|
11
13
|
"author": "Roberto Valenti",
|
|
12
14
|
"license": "GPL-3.0-or-later",
|