holosphere 2.0.0-alpha8 → 2.0.0-alpha9
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/CHANGELOG.md +446 -0
- package/FEATURES.md +431 -0
- package/LICENSE +29 -166
- package/LICENSE-AGPL.md +180 -0
- package/dist/cdn/holosphere.min.js +55 -0
- package/dist/cdn/holosphere.min.js.map +1 -0
- package/dist/cjs/holosphere.cjs +1 -1
- package/dist/esm/holosphere.js +1 -1
- package/dist/{index-CKffQDmQ.cjs → index-DDGt_V9o.cjs} +2 -2
- package/dist/{index-CKffQDmQ.cjs.map → index-DDGt_V9o.cjs.map} +1 -1
- package/dist/{index-4XHHKe6S.js → index-DJXftyvB.js} +1905 -337
- package/dist/index-DJXftyvB.js.map +1 -0
- package/dist/{index-Dz5kOZMI.cjs → index-DMbdcMtK.cjs} +17 -4
- package/dist/index-DMbdcMtK.cjs.map +1 -0
- package/dist/{index-BjP1TXGz.js → index-DeZ1xz_s.js} +2 -2
- package/dist/{index-BjP1TXGz.js.map → index-DeZ1xz_s.js.map} +1 -1
- package/dist/{indexeddb-storage-lExjjFlV.js → indexeddb-storage-BFt6hMeF.js} +48 -4
- package/dist/indexeddb-storage-BFt6hMeF.js.map +1 -0
- package/dist/{indexeddb-storage-DD7EFBVc.cjs → indexeddb-storage-BK5tv4Sh.cjs} +2 -2
- package/dist/indexeddb-storage-BK5tv4Sh.cjs.map +1 -0
- package/dist/{memory-storage-C68adso2.js → memory-storage-C9HuoL2E.js} +44 -4
- package/dist/memory-storage-C9HuoL2E.js.map +1 -0
- package/dist/{memory-storage-DD_6yyXT.cjs → memory-storage-Dao7jfYG.cjs} +2 -2
- package/dist/memory-storage-Dao7jfYG.cjs.map +1 -0
- package/dist/{secp256k1-DYELiqgx.cjs → secp256k1-BbKzbLtD.cjs} +2 -2
- package/dist/{secp256k1-DYELiqgx.cjs.map → secp256k1-BbKzbLtD.cjs.map} +1 -1
- package/dist/{secp256k1-OM8siPyy.js → secp256k1-CreY7Pcl.js} +2 -2
- package/dist/{secp256k1-OM8siPyy.js.map → secp256k1-CreY7Pcl.js.map} +1 -1
- package/docs/api/ai_aggregation.js.html +333 -0
- package/docs/api/ai_breakdown.js.html +524 -0
- package/docs/api/ai_classifier.js.html +231 -0
- package/docs/api/ai_council.js.html +246 -0
- package/docs/api/ai_embeddings.js.html +304 -0
- package/docs/api/ai_federation-ai.js.html +338 -0
- package/docs/api/ai_h3-ai.js.html +970 -0
- package/docs/api/ai_index.js.html +124 -0
- package/docs/api/ai_json-ops.js.html +241 -0
- package/docs/api/ai_llm-service.js.html +239 -0
- package/docs/api/ai_nl-query.js.html +236 -0
- package/docs/api/ai_relationships.js.html +367 -0
- package/docs/api/ai_schema-extractor.js.html +235 -0
- package/docs/api/ai_spatial.js.html +307 -0
- package/docs/api/ai_tts.js.html +214 -0
- package/docs/api/content_social-protocols.js.html +180 -0
- package/docs/api/core_holosphere.js.html +757 -0
- package/docs/api/crypto_nostr-utils.js.html +306 -0
- package/docs/api/crypto_secp256k1.js.html +267 -0
- package/docs/api/data/search.json +1 -0
- package/docs/api/federation_discovery.js.html +337 -0
- package/docs/api/federation_handshake.js.html +478 -0
- package/docs/api/federation_hologram.js.html +1053 -0
- package/docs/api/federation_registry.js.html +389 -0
- package/docs/api/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/api/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/api/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/api/global.html +3 -0
- package/docs/api/hierarchical_upcast.js.html +128 -0
- package/docs/api/index.html +265 -0
- package/docs/api/index.js.html +1868 -0
- package/docs/api/lib_ai-methods.js.html +660 -0
- package/docs/api/lib_contract-methods.js.html +445 -0
- package/docs/api/lib_errors.js.html +56 -0
- package/docs/api/lib_federation-methods.js.html +348 -0
- package/docs/api/lib_index.js.html +33 -0
- package/docs/api/module-ai.html +5 -0
- package/docs/api/module-ai_aggregation-SmartAggregation.html +6 -0
- package/docs/api/module-ai_aggregation.SmartAggregation.html +3 -0
- package/docs/api/module-ai_aggregation.html +3 -0
- package/docs/api/module-ai_breakdown-TaskBreakdown.html +5 -0
- package/docs/api/module-ai_breakdown.TaskBreakdown.html +3 -0
- package/docs/api/module-ai_breakdown.html +3 -0
- package/docs/api/module-ai_classifier-Classifier.html +6 -0
- package/docs/api/module-ai_classifier.Classifier.html +3 -0
- package/docs/api/module-ai_classifier.html +3 -0
- package/docs/api/module-ai_council-Council.html +6 -0
- package/docs/api/module-ai_council.Council.html +3 -0
- package/docs/api/module-ai_council.html +3 -0
- package/docs/api/module-ai_embeddings-Embeddings.html +5 -0
- package/docs/api/module-ai_embeddings.Embeddings.html +3 -0
- package/docs/api/module-ai_embeddings.html +3 -0
- package/docs/api/module-ai_federation-ai-FederationAdvisor.html +6 -0
- package/docs/api/module-ai_federation-ai.FederationAdvisor.html +3 -0
- package/docs/api/module-ai_federation-ai.html +3 -0
- package/docs/api/module-ai_h3-ai-H3AI.html +6 -0
- package/docs/api/module-ai_h3-ai.H3AI.html +3 -0
- package/docs/api/module-ai_h3-ai.html +3 -0
- package/docs/api/module-ai_json-ops-JSONOps.html +5 -0
- package/docs/api/module-ai_json-ops.JSONOps.html +3 -0
- package/docs/api/module-ai_json-ops.html +3 -0
- package/docs/api/module-ai_llm-service-LLMService.html +5 -0
- package/docs/api/module-ai_llm-service.LLMService.html +3 -0
- package/docs/api/module-ai_llm-service.html +3 -0
- package/docs/api/module-ai_nl-query-NLQuery.html +5 -0
- package/docs/api/module-ai_nl-query.NLQuery.html +3 -0
- package/docs/api/module-ai_nl-query.html +3 -0
- package/docs/api/module-ai_relationships-RelationshipDiscovery.html +6 -0
- package/docs/api/module-ai_relationships.RelationshipDiscovery.html +3 -0
- package/docs/api/module-ai_relationships.html +3 -0
- package/docs/api/module-ai_schema-extractor-SchemaExtractor.html +5 -0
- package/docs/api/module-ai_schema-extractor.SchemaExtractor.html +3 -0
- package/docs/api/module-ai_schema-extractor.html +3 -0
- package/docs/api/module-ai_spatial-SpatialAnalysis.html +6 -0
- package/docs/api/module-ai_spatial.SpatialAnalysis.html +3 -0
- package/docs/api/module-ai_spatial.html +3 -0
- package/docs/api/module-ai_tts-TTS.html +5 -0
- package/docs/api/module-ai_tts.TTS.html +3 -0
- package/docs/api/module-ai_tts.html +3 -0
- package/docs/api/module-content_social-protocols.html +3 -0
- package/docs/api/module-core_holosphere-HoloSphere.html +6 -0
- package/docs/api/module-core_holosphere.HoloSphere.html +3 -0
- package/docs/api/module-core_holosphere.html +3 -0
- package/docs/api/module-crypto_nostr-utils.html +3 -0
- package/docs/api/module-crypto_secp256k1.html +3 -0
- package/docs/api/module-federation_hologram.html +3 -0
- package/docs/api/module-hierarchical_upcast.html +3 -0
- package/docs/api/module-holosphere-HoloSphereBase.html +3 -0
- package/docs/api/module-holosphere.html +3 -0
- package/docs/api/module-lib_ai-methods.html +3 -0
- package/docs/api/module-lib_contract-methods.html +3 -0
- package/docs/api/module-lib_errors-AuthorizationError.html +3 -0
- package/docs/api/module-lib_errors-ValidationError.html +3 -0
- package/docs/api/module-lib_errors.AuthorizationError.html +3 -0
- package/docs/api/module-lib_errors.ValidationError.html +3 -0
- package/docs/api/module-lib_errors.html +3 -0
- package/docs/api/module-lib_federation-methods.html +3 -0
- package/docs/api/module-lib_index.html +3 -0
- package/docs/api/module-schema_validator-ValidationError.html +3 -0
- package/docs/api/module-schema_validator.ValidationError.html +3 -0
- package/docs/api/module-schema_validator.html +3 -0
- package/docs/api/module-spatial_h3-operations.html +4 -0
- package/docs/api/module-storage_backend-factory.BackendFactory.html +3 -0
- package/docs/api/module-storage_backend-factory.html +3 -0
- package/docs/api/module-storage_backend-interface-StorageBackend.html +3 -0
- package/docs/api/module-storage_backend-interface.StorageBackend.html +3 -0
- package/docs/api/module-storage_backend-interface.html +3 -0
- package/docs/api/module-storage_backends_activitypub-backend-ActivityPubBackend.html +7 -0
- package/docs/api/module-storage_backends_activitypub-backend.ActivityPubBackend.html +3 -0
- package/docs/api/module-storage_backends_activitypub-backend.html +3 -0
- package/docs/api/module-storage_backends_activitypub_server-ActivityPubServer.html +8 -0
- package/docs/api/module-storage_backends_activitypub_server.ActivityPubServer.html +3 -0
- package/docs/api/module-storage_backends_activitypub_server.html +3 -0
- package/docs/api/module-storage_backends_gundb-backend-GunDBBackend.html +7 -0
- package/docs/api/module-storage_backends_gundb-backend.GunDBBackend.html +3 -0
- package/docs/api/module-storage_backends_gundb-backend.html +3 -0
- package/docs/api/module-storage_backends_nostr-backend-NostrBackend.html +8 -0
- package/docs/api/module-storage_backends_nostr-backend.NostrBackend.html +3 -0
- package/docs/api/module-storage_backends_nostr-backend.html +3 -0
- package/docs/api/module-storage_filesystem-storage-FileSystemStorage.html +5 -0
- package/docs/api/module-storage_filesystem-storage-browser-FileSystemStorage.html +3 -0
- package/docs/api/module-storage_filesystem-storage-browser.FileSystemStorage.html +3 -0
- package/docs/api/module-storage_filesystem-storage-browser.html +3 -0
- package/docs/api/module-storage_filesystem-storage.FileSystemStorage.html +3 -0
- package/docs/api/module-storage_filesystem-storage.html +3 -0
- package/docs/api/module-storage_global-tables.html +3 -0
- package/docs/api/module-storage_gun-async.html +3 -0
- package/docs/api/module-storage_gun-auth-GunAuth.html +5 -0
- package/docs/api/module-storage_gun-auth.GunAuth.html +3 -0
- package/docs/api/module-storage_gun-auth.html +3 -0
- package/docs/api/module-storage_gun-federation.html +3 -0
- package/docs/api/module-storage_gun-references-GunReferenceHandler.html +5 -0
- package/docs/api/module-storage_gun-references.GunReferenceHandler.html +3 -0
- package/docs/api/module-storage_gun-references.html +3 -0
- package/docs/api/module-storage_gun-schema-GunSchemaValidator.html +5 -0
- package/docs/api/module-storage_gun-schema.GunSchemaValidator.html +3 -0
- package/docs/api/module-storage_gun-schema.html +3 -0
- package/docs/api/module-storage_gun-wrapper.html +11 -0
- package/docs/api/module-storage_indexeddb-storage-IndexedDBStorage.html +5 -0
- package/docs/api/module-storage_indexeddb-storage.IndexedDBStorage.html +3 -0
- package/docs/api/module-storage_indexeddb-storage.html +3 -0
- package/docs/api/module-storage_key-storage-simple.html +3 -0
- package/docs/api/module-storage_key-storage.html +4 -0
- package/docs/api/module-storage_memory-storage-MemoryStorage.html +5 -0
- package/docs/api/module-storage_memory-storage.MemoryStorage.html +3 -0
- package/docs/api/module-storage_memory-storage.html +3 -0
- package/docs/api/module-storage_migration-MigrationTool.html +6 -0
- package/docs/api/module-storage_migration.MigrationTool.html +3 -0
- package/docs/api/module-storage_migration.html +3 -0
- package/docs/api/module-storage_nostr-async.html +18 -0
- package/docs/api/module-storage_nostr-client-LRUCache.html +3 -0
- package/docs/api/module-storage_nostr-client-NostrClient.html +7 -0
- package/docs/api/module-storage_nostr-client.NostrClient.html +15 -0
- package/docs/api/module-storage_nostr-client.html +6 -0
- package/docs/api/module-storage_nostr-wrapper.html +3 -0
- package/docs/api/module-storage_outbox-queue-OutboxQueue.html +4 -0
- package/docs/api/module-storage_outbox-queue.OutboxQueue.html +3 -0
- package/docs/api/module-storage_outbox-queue.html +3 -0
- package/docs/api/module-storage_persistent-storage-PersistentStorage.html +3 -0
- package/docs/api/module-storage_persistent-storage.html +4 -0
- package/docs/api/module-storage_sync-service-SyncService.html +5 -0
- package/docs/api/module-storage_sync-service.SyncService.html +3 -0
- package/docs/api/module-storage_sync-service.html +3 -0
- package/docs/api/module-storage_unified-storage.html +3 -0
- package/docs/api/module-subscriptions_manager.SubscriptionRegistry.html +3 -0
- package/docs/api/module-subscriptions_manager.html +3 -0
- package/docs/api/schema_validator.js.html +113 -0
- package/docs/api/scripts/core.js +726 -0
- package/docs/api/scripts/core.min.js +23 -0
- package/docs/api/scripts/resize.js +90 -0
- package/docs/api/scripts/search.js +265 -0
- package/docs/api/scripts/search.min.js +6 -0
- package/docs/api/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/api/scripts/third-party/fuse.js +9 -0
- package/docs/api/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/api/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/api/scripts/third-party/hljs-original.js +5171 -0
- package/docs/api/scripts/third-party/hljs.js +1 -0
- package/docs/api/scripts/third-party/popper.js +5 -0
- package/docs/api/scripts/third-party/tippy.js +1 -0
- package/docs/api/scripts/third-party/tocbot.js +672 -0
- package/docs/api/scripts/third-party/tocbot.min.js +1 -0
- package/docs/api/spatial_h3-operations.js.html +129 -0
- package/docs/api/storage_backend-factory.js.html +133 -0
- package/docs/api/storage_backend-interface.js.html +164 -0
- package/docs/api/storage_backends_activitypub-backend.js.html +298 -0
- package/docs/api/storage_backends_activitypub_server.js.html +678 -0
- package/docs/api/storage_backends_gundb-backend.js.html +878 -0
- package/docs/api/storage_backends_nostr-backend.js.html +254 -0
- package/docs/api/storage_filesystem-storage-browser.js.html +83 -0
- package/docs/api/storage_filesystem-storage.js.html +207 -0
- package/docs/api/storage_global-tables.js.html +116 -0
- package/docs/api/storage_gun-async.js.html +344 -0
- package/docs/api/storage_gun-auth.js.html +376 -0
- package/docs/api/storage_gun-federation.js.html +788 -0
- package/docs/api/storage_gun-references.js.html +212 -0
- package/docs/api/storage_gun-schema.js.html +309 -0
- package/docs/api/storage_gun-wrapper.js.html +645 -0
- package/docs/api/storage_indexeddb-storage.js.html +224 -0
- package/docs/api/storage_key-storage-simple.js.html +102 -0
- package/docs/api/storage_key-storage.js.html +171 -0
- package/docs/api/storage_memory-storage.js.html +128 -0
- package/docs/api/storage_migration.js.html +354 -0
- package/docs/api/storage_nostr-async.js.html +1076 -0
- package/docs/api/storage_nostr-client.js.html +1598 -0
- package/docs/api/storage_nostr-wrapper.js.html +218 -0
- package/docs/api/storage_outbox-queue.js.html +248 -0
- package/docs/api/storage_persistent-storage.js.html +160 -0
- package/docs/api/storage_sync-service.js.html +201 -0
- package/docs/api/storage_unified-storage.js.html +157 -0
- package/docs/api/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/api/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/api/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/api/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/api/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/api/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/api/subscriptions_manager.js.html +162 -0
- package/jsdoc.json +26 -0
- package/package.json +14 -3
- package/src/ai/aggregation.js +13 -2
- package/src/ai/breakdown.js +12 -2
- package/src/ai/classifier.js +14 -3
- package/src/ai/council.js +22 -7
- package/src/ai/embeddings.js +37 -15
- package/src/ai/federation-ai.js +13 -2
- package/src/ai/h3-ai.js +14 -2
- package/src/ai/index.js +16 -7
- package/src/ai/json-ops.js +18 -5
- package/src/ai/llm-service.js +62 -31
- package/src/ai/nl-query.js +12 -2
- package/src/ai/relationships.js +13 -2
- package/src/ai/schema-extractor.js +24 -10
- package/src/ai/spatial.js +13 -2
- package/src/ai/tts.js +25 -8
- package/src/content/social-protocols.js +34 -25
- package/src/contracts/chain-manager.js +68 -40
- package/src/contracts/deployer.js +70 -42
- package/src/contracts/event-listener.js +61 -29
- package/src/contracts/holon-contracts.js +46 -31
- package/src/contracts/index.js +5 -6
- package/src/contracts/networks.js +19 -14
- package/src/contracts/operations.js +58 -41
- package/src/contracts/queries.js +54 -20
- package/src/core/holosphere.js +35 -6
- package/src/crypto/nostr-utils.js +82 -76
- package/src/crypto/secp256k1.js +7 -2
- package/src/federation/handshake.js +7 -7
- package/src/federation/hologram.js +9 -1
- package/src/hierarchical/upcast.js +34 -20
- package/src/index.js +655 -5
- package/src/lib/ai-methods.js +352 -3
- package/src/lib/contract-methods.js +152 -3
- package/src/lib/errors.js +31 -1
- package/src/lib/federation-methods.js +110 -3
- package/src/lib/index.js +9 -5
- package/src/schema/validator.js +22 -3
- package/src/spatial/h3-operations.js +17 -1
- package/src/storage/backend-factory.js +7 -2
- package/src/storage/backend-interface.js +21 -2
- package/src/storage/backends/activitypub/server.js +25 -3
- package/src/storage/backends/activitypub-backend.js +25 -2
- package/src/storage/backends/gundb-backend.js +29 -2
- package/src/storage/backends/nostr-backend.js +116 -1
- package/src/storage/filesystem-storage-browser.js +42 -2
- package/src/storage/filesystem-storage.js +72 -5
- package/src/storage/global-tables.js +7 -2
- package/src/storage/gun-async.js +20 -11
- package/src/storage/gun-auth.js +15 -4
- package/src/storage/gun-federation.js +14 -5
- package/src/storage/gun-references.js +16 -5
- package/src/storage/gun-schema.js +25 -10
- package/src/storage/gun-wrapper.js +99 -36
- package/src/storage/indexeddb-storage.js +65 -4
- package/src/storage/key-storage-simple.js +32 -9
- package/src/storage/key-storage.js +45 -13
- package/src/storage/memory-storage.js +65 -4
- package/src/storage/migration.js +20 -7
- package/src/storage/nostr-async.js +157 -67
- package/src/storage/nostr-client.js +173 -49
- package/src/storage/nostr-wrapper.js +6 -2
- package/src/storage/outbox-queue.js +55 -18
- package/src/storage/persistent-storage.js +56 -13
- package/src/storage/sync-service.js +51 -17
- package/src/storage/unified-storage.js +7 -2
- package/src/subscriptions/manager.js +33 -16
- package/dist/index-4XHHKe6S.js.map +0 -1
- package/dist/index-Dz5kOZMI.cjs.map +0 -1
- package/dist/indexeddb-storage-DD7EFBVc.cjs.map +0 -1
- package/dist/indexeddb-storage-lExjjFlV.js.map +0 -1
- package/dist/memory-storage-C68adso2.js.map +0 -1
- package/dist/memory-storage-DD_6yyXT.cjs.map +0 -1
- /package/{cleanup-test-data.js → scripts/cleanup-test-data.js} +0 -0
- /package/{test-ai-real-api.js → scripts/test-ai-real-api.js} +0 -0
package/src/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HoloSphere - Holonic Geospatial Communication Infrastructure
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview HoloSphere - Holonic Geospatial Communication Infrastructure
|
|
3
|
+
*
|
|
4
|
+
* This is the main entry point for the HoloSphere library, providing a comprehensive
|
|
5
|
+
* distributed P2P geospatial communication system. It combines H3 hexagonal indexing
|
|
6
|
+
* for spatial organization, Nostr protocol for distributed storage, smart contracts
|
|
7
|
+
* for fund distribution, and AI services for intelligent data processing.
|
|
8
|
+
*
|
|
9
|
+
* @module holosphere
|
|
10
|
+
* @author HoloSphere Team
|
|
11
|
+
* @license MIT
|
|
4
12
|
*/
|
|
5
13
|
|
|
6
14
|
import { HoloSphere as HoloSphereCore } from './core/holosphere.js';
|
|
@@ -51,16 +59,36 @@ import { withFederationMethods } from './lib/federation-methods.js';
|
|
|
51
59
|
import { AuthorizationError } from './lib/errors.js';
|
|
52
60
|
|
|
53
61
|
/**
|
|
54
|
-
* Base HoloSphere class with core data operations
|
|
62
|
+
* Base HoloSphere class with core data operations.
|
|
63
|
+
* Extends HoloSphereCore with schema validation, caching, subscriptions, and AI capabilities.
|
|
64
|
+
*
|
|
65
|
+
* @class HoloSphereBase
|
|
66
|
+
* @extends HoloSphereCore
|
|
55
67
|
*/
|
|
56
68
|
class HoloSphereBase extends HoloSphereCore {
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new HoloSphereBase instance.
|
|
71
|
+
*
|
|
72
|
+
* @param {Object} config - Configuration options
|
|
73
|
+
* @param {string} config.appName - Application namespace for data isolation
|
|
74
|
+
* @param {string} [config.backend='nostr'] - Storage backend type ('nostr', 'gundb', 'activitypub')
|
|
75
|
+
* @param {string[]} [config.relays] - Nostr relay URLs for distributed storage
|
|
76
|
+
* @param {string} [config.openaiKey] - OpenAI API key for AI services
|
|
77
|
+
* @param {Object} [config.aiOptions] - AI service configuration
|
|
78
|
+
* @param {string} [config.aiOptions.model] - OpenAI model to use
|
|
79
|
+
* @param {number} [config.aiOptions.temperature] - Temperature for AI responses
|
|
80
|
+
*/
|
|
57
81
|
constructor(config) {
|
|
58
82
|
super(config);
|
|
83
|
+
/** @type {Map<string, {schema: Object, strict: boolean, timestamp: number}>} */
|
|
59
84
|
this.schemas = new Map();
|
|
85
|
+
/** @type {Map<string, any>} */
|
|
60
86
|
this._cache = new Map();
|
|
87
|
+
/** @type {subscriptions.SubscriptionRegistry} */
|
|
61
88
|
this.subscriptionRegistry = new subscriptions.SubscriptionRegistry();
|
|
62
89
|
|
|
63
90
|
// Initialize AI services if openaiKey is provided or OPENAI_API_KEY env var is set
|
|
91
|
+
/** @type {Object|null} */
|
|
64
92
|
this._ai = null;
|
|
65
93
|
const openaiKey = config.openaiKey || this._getEnv('OPENAI_API_KEY');
|
|
66
94
|
if (openaiKey) {
|
|
@@ -73,9 +101,17 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
73
101
|
}
|
|
74
102
|
|
|
75
103
|
// Contracts module (lazy initialized)
|
|
104
|
+
/** @type {Object|null} */
|
|
76
105
|
this._contracts = null;
|
|
77
106
|
}
|
|
78
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Gets an environment variable value (Node.js only).
|
|
110
|
+
*
|
|
111
|
+
* @private
|
|
112
|
+
* @param {string} name - Environment variable name
|
|
113
|
+
* @returns {string|undefined} Environment variable value or undefined
|
|
114
|
+
*/
|
|
79
115
|
_getEnv(name) {
|
|
80
116
|
if (typeof process !== 'undefined' && process.env) {
|
|
81
117
|
return process.env[name];
|
|
@@ -83,12 +119,28 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
83
119
|
return undefined;
|
|
84
120
|
}
|
|
85
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Parses a string value to a float.
|
|
124
|
+
*
|
|
125
|
+
* @private
|
|
126
|
+
* @param {string|undefined|null} value - Value to parse
|
|
127
|
+
* @returns {number|undefined} Parsed float or undefined if invalid
|
|
128
|
+
*/
|
|
86
129
|
_parseFloat(value) {
|
|
87
130
|
if (value === undefined || value === null) return undefined;
|
|
88
131
|
const parsed = parseFloat(value);
|
|
89
132
|
return isNaN(parsed) ? undefined : parsed;
|
|
90
133
|
}
|
|
91
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Initializes AI services with the provided API key.
|
|
137
|
+
*
|
|
138
|
+
* @private
|
|
139
|
+
* @param {string} apiKey - OpenAI API key
|
|
140
|
+
* @param {Object} [options={}] - AI configuration options
|
|
141
|
+
* @param {string} [options.model] - OpenAI model to use
|
|
142
|
+
* @param {number} [options.temperature] - Temperature for AI responses
|
|
143
|
+
*/
|
|
92
144
|
_initializeAI(apiKey, options = {}) {
|
|
93
145
|
const llmOptions = {
|
|
94
146
|
...options.llm,
|
|
@@ -119,33 +171,87 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
119
171
|
this._ai.h3ai = new H3AI(this._ai.llm, this);
|
|
120
172
|
}
|
|
121
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Checks if AI services are initialized.
|
|
176
|
+
*
|
|
177
|
+
* @returns {boolean} True if AI services are available
|
|
178
|
+
*/
|
|
122
179
|
hasAI() {
|
|
123
180
|
return this._ai !== null;
|
|
124
181
|
}
|
|
125
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Gets the initialized AI services object.
|
|
185
|
+
*
|
|
186
|
+
* @returns {Object|null} AI services object containing llm, embeddings, etc., or null if not initialized
|
|
187
|
+
*/
|
|
126
188
|
getAIServices() {
|
|
127
189
|
return this._ai;
|
|
128
190
|
}
|
|
129
191
|
|
|
130
192
|
// === Spatial Operations ===
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Converts geographic coordinates to an H3 holon ID.
|
|
196
|
+
*
|
|
197
|
+
* @param {number} lat - Latitude (-90 to 90)
|
|
198
|
+
* @param {number} lng - Longitude (-180 to 180)
|
|
199
|
+
* @param {number} resolution - H3 resolution level (0-15)
|
|
200
|
+
* @returns {Promise<string>} H3 cell ID representing the holon
|
|
201
|
+
*/
|
|
131
202
|
async toHolon(lat, lng, resolution) {
|
|
132
203
|
return spatial.toHolon(lat, lng, resolution);
|
|
133
204
|
}
|
|
134
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Gets all parent holons at higher resolutions.
|
|
208
|
+
*
|
|
209
|
+
* @param {string} holonId - H3 cell ID
|
|
210
|
+
* @param {number} [maxResolution] - Maximum resolution to traverse up to
|
|
211
|
+
* @returns {Promise<string[]>} Array of parent H3 cell IDs
|
|
212
|
+
*/
|
|
135
213
|
async getParents(holonId, maxResolution) {
|
|
136
214
|
return spatial.getParents(holonId, maxResolution);
|
|
137
215
|
}
|
|
138
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Gets all child holons at the next resolution level.
|
|
219
|
+
*
|
|
220
|
+
* @param {string} holonId - H3 cell ID
|
|
221
|
+
* @returns {Promise<string[]>} Array of child H3 cell IDs
|
|
222
|
+
*/
|
|
139
223
|
async getChildren(holonId) {
|
|
140
224
|
return spatial.getChildren(holonId);
|
|
141
225
|
}
|
|
142
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Validates if a string is a valid H3 cell ID.
|
|
229
|
+
*
|
|
230
|
+
* @param {string} holonId - String to validate
|
|
231
|
+
* @returns {boolean} True if valid H3 cell ID
|
|
232
|
+
*/
|
|
143
233
|
isValidH3(holonId) {
|
|
144
234
|
return spatial.isValidH3(holonId);
|
|
145
235
|
}
|
|
146
236
|
|
|
147
237
|
// === Data Operations ===
|
|
148
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Writes data to a specific holon and lens.
|
|
241
|
+
*
|
|
242
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
243
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
244
|
+
* @param {Object} data - Data object to write (must have or will be assigned an id)
|
|
245
|
+
* @param {Object} [options={}] - Write options
|
|
246
|
+
* @param {string} [options.capabilityToken] - Capability token for authorization
|
|
247
|
+
* @param {boolean} [options.validate=true] - Whether to validate against schema
|
|
248
|
+
* @param {boolean} [options.strict] - Override schema strict mode
|
|
249
|
+
* @param {boolean} [options.autoPropagate=true] - Whether to propagate to federated holons
|
|
250
|
+
* @param {Object} [options.propagationOptions] - Options for propagation
|
|
251
|
+
* @returns {Promise<boolean>} True if write succeeded
|
|
252
|
+
* @throws {ValidationError} If holonId, lensName, or data is invalid
|
|
253
|
+
* @throws {AuthorizationError} If capability token is invalid
|
|
254
|
+
*/
|
|
149
255
|
async write(holonId, lensName, data, options = {}) {
|
|
150
256
|
if (!holonId || typeof holonId !== 'string') {
|
|
151
257
|
throw new ValidationError('ValidationError: holonId must be a non-empty string');
|
|
@@ -265,6 +371,15 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
265
371
|
return true;
|
|
266
372
|
}
|
|
267
373
|
|
|
374
|
+
/**
|
|
375
|
+
* Recursively resolves holograms (references) to their source data.
|
|
376
|
+
* Handles circular reference detection and local overrides.
|
|
377
|
+
*
|
|
378
|
+
* @private
|
|
379
|
+
* @param {Object|Array|null} data - Data that may contain holograms
|
|
380
|
+
* @param {Set<string>} [visited=new Set()] - Set of visited paths for circular detection
|
|
381
|
+
* @returns {Promise<Object|Array|null>} Resolved data with holograms replaced by source data
|
|
382
|
+
*/
|
|
268
383
|
async _resolveHolograms(data, visited = new Set()) {
|
|
269
384
|
if (!data) return data;
|
|
270
385
|
|
|
@@ -357,6 +472,19 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
357
472
|
return data;
|
|
358
473
|
}
|
|
359
474
|
|
|
475
|
+
/**
|
|
476
|
+
* Reads data from a specific holon and lens.
|
|
477
|
+
*
|
|
478
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
479
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
480
|
+
* @param {string|null} [dataId=null] - Specific data ID, or null to read all
|
|
481
|
+
* @param {Object} [options={}] - Read options
|
|
482
|
+
* @param {string} [options.capabilityToken] - Capability token for authorization
|
|
483
|
+
* @param {boolean} [options.resolveHolograms=true] - Whether to resolve hologram references
|
|
484
|
+
* @returns {Promise<Object|Array|null>} Data object, array of objects, or null if not found
|
|
485
|
+
* @throws {ValidationError} If holonId or lensName is invalid
|
|
486
|
+
* @throws {AuthorizationError} If capability token is invalid
|
|
487
|
+
*/
|
|
360
488
|
async read(holonId, lensName, dataId = null, options = {}) {
|
|
361
489
|
if (!holonId || typeof holonId !== 'string') {
|
|
362
490
|
throw new ValidationError('ValidationError: holonId must be a non-empty string');
|
|
@@ -402,6 +530,21 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
402
530
|
return result;
|
|
403
531
|
}
|
|
404
532
|
|
|
533
|
+
/**
|
|
534
|
+
* Updates existing data in a specific holon and lens.
|
|
535
|
+
*
|
|
536
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
537
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
538
|
+
* @param {string} dataId - ID of the data to update
|
|
539
|
+
* @param {Object} updates - Object containing fields to update
|
|
540
|
+
* @param {Object} [options={}] - Update options
|
|
541
|
+
* @param {string} [options.capabilityToken] - Capability token for authorization
|
|
542
|
+
* @param {boolean} [options.validate=true] - Whether to validate against schema
|
|
543
|
+
* @param {boolean} [options.strict] - Override schema strict mode
|
|
544
|
+
* @returns {Promise<boolean>} True if update succeeded, false if data not found
|
|
545
|
+
* @throws {ValidationError} If holonId, lensName, dataId, or updates is invalid
|
|
546
|
+
* @throws {AuthorizationError} If capability token is invalid
|
|
547
|
+
*/
|
|
405
548
|
async update(holonId, lensName, dataId, updates, options = {}) {
|
|
406
549
|
if (!holonId || typeof holonId !== 'string') {
|
|
407
550
|
throw new ValidationError('ValidationError: holonId must be a non-empty string');
|
|
@@ -463,6 +606,18 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
463
606
|
return true;
|
|
464
607
|
}
|
|
465
608
|
|
|
609
|
+
/**
|
|
610
|
+
* Deletes data from a specific holon and lens.
|
|
611
|
+
*
|
|
612
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
613
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
614
|
+
* @param {string} dataId - ID of the data to delete
|
|
615
|
+
* @param {Object} [options={}] - Delete options
|
|
616
|
+
* @param {string} [options.capabilityToken] - Capability token for authorization
|
|
617
|
+
* @returns {Promise<boolean>} True if deletion succeeded, false if data not found
|
|
618
|
+
* @throws {ValidationError} If holonId, lensName, or dataId is invalid
|
|
619
|
+
* @throws {AuthorizationError} If not owner and no valid capability token
|
|
620
|
+
*/
|
|
466
621
|
async delete(holonId, lensName, dataId, options = {}) {
|
|
467
622
|
if (!holonId || typeof holonId !== 'string') {
|
|
468
623
|
throw new ValidationError('ValidationError: holonId must be a non-empty string');
|
|
@@ -514,41 +669,108 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
514
669
|
}
|
|
515
670
|
|
|
516
671
|
// === Global Tables ===
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Writes data to a global table (not holon-specific).
|
|
675
|
+
*
|
|
676
|
+
* @param {string} table - Name of the global table
|
|
677
|
+
* @param {Object} data - Data object to write (must have an id field)
|
|
678
|
+
* @returns {Promise<boolean>} True if write succeeded
|
|
679
|
+
*/
|
|
517
680
|
async writeGlobal(table, data) {
|
|
518
681
|
return globalTables.writeGlobal(this.client, this.config.appName, table, data);
|
|
519
682
|
}
|
|
520
683
|
|
|
684
|
+
/**
|
|
685
|
+
* Reads data from a global table.
|
|
686
|
+
*
|
|
687
|
+
* @param {string} table - Name of the global table
|
|
688
|
+
* @param {string|null} [key=null] - Specific key to read, or null to read all
|
|
689
|
+
* @returns {Promise<Object|Array|null>} Data object, array of objects, or null
|
|
690
|
+
*/
|
|
521
691
|
async readGlobal(table, key = null) {
|
|
522
692
|
return globalTables.readGlobal(this.client, this.config.appName, table, key);
|
|
523
693
|
}
|
|
524
694
|
|
|
695
|
+
/**
|
|
696
|
+
* Updates data in a global table.
|
|
697
|
+
*
|
|
698
|
+
* @param {string} table - Name of the global table
|
|
699
|
+
* @param {string} key - Key of the data to update
|
|
700
|
+
* @param {Object} updates - Object containing fields to update
|
|
701
|
+
* @returns {Promise<boolean>} True if update succeeded
|
|
702
|
+
*/
|
|
525
703
|
async updateGlobal(table, key, updates) {
|
|
526
704
|
return globalTables.updateGlobal(this.client, this.config.appName, table, key, updates);
|
|
527
705
|
}
|
|
528
706
|
|
|
707
|
+
/**
|
|
708
|
+
* Deletes data from a global table.
|
|
709
|
+
*
|
|
710
|
+
* @param {string} table - Name of the global table
|
|
711
|
+
* @param {string} key - Key of the data to delete
|
|
712
|
+
* @returns {Promise<boolean>} True if deletion succeeded
|
|
713
|
+
*/
|
|
529
714
|
async deleteGlobal(table, key) {
|
|
530
715
|
return globalTables.deleteGlobal(this.client, this.config.appName, table, key);
|
|
531
716
|
}
|
|
532
717
|
|
|
718
|
+
/**
|
|
719
|
+
* Gets all data from a global table.
|
|
720
|
+
*
|
|
721
|
+
* @param {string} table - Name of the global table
|
|
722
|
+
* @returns {Promise<Array>} Array of all data objects in the table
|
|
723
|
+
*/
|
|
533
724
|
async getAllGlobal(table) {
|
|
534
725
|
return globalTables.getAllGlobal(this.client, this.config.appName, table);
|
|
535
726
|
}
|
|
536
727
|
|
|
728
|
+
/**
|
|
729
|
+
* Deletes all data from a global table.
|
|
730
|
+
*
|
|
731
|
+
* @param {string} table - Name of the global table
|
|
732
|
+
* @returns {Promise<boolean>} True if deletion succeeded
|
|
733
|
+
*/
|
|
537
734
|
async deleteAllGlobal(table) {
|
|
538
735
|
return globalTables.deleteAllGlobal(this.client, this.config.appName, table);
|
|
539
736
|
}
|
|
540
737
|
|
|
541
738
|
// === Batch Operations ===
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Gets all data from a specific holon and lens.
|
|
742
|
+
*
|
|
743
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
744
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
745
|
+
* @returns {Promise<Array|null>} Array of data objects or null
|
|
746
|
+
*/
|
|
542
747
|
async getAll(holonId, lensName) {
|
|
543
748
|
return this.read(holonId, lensName, null);
|
|
544
749
|
}
|
|
545
750
|
|
|
751
|
+
/**
|
|
752
|
+
* Deletes all data from a specific holon and lens.
|
|
753
|
+
*
|
|
754
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
755
|
+
* @param {string} lensName - Name of the lens (data category)
|
|
756
|
+
* @returns {Promise<boolean>} True if deletion succeeded
|
|
757
|
+
*/
|
|
546
758
|
async deleteAll(holonId, lensName) {
|
|
547
759
|
const path = storage.buildPath(this.config.appName, holonId, lensName);
|
|
548
760
|
return storage.deleteAll(this.client, path);
|
|
549
761
|
}
|
|
550
762
|
|
|
551
763
|
// === Schema Operations ===
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Sets a JSON Schema for validating data in a specific lens.
|
|
767
|
+
*
|
|
768
|
+
* @param {string} lensName - Name of the lens to associate the schema with
|
|
769
|
+
* @param {Object|string} schemaInput - JSON Schema object or URI reference
|
|
770
|
+
* @param {boolean} [strict=false] - If true, validation will reject additional properties
|
|
771
|
+
* @returns {Promise<void>}
|
|
772
|
+
* @throws {ValidationError} If lensName is invalid or schema format is invalid
|
|
773
|
+
*/
|
|
552
774
|
async setSchema(lensName, schemaInput, strict = false) {
|
|
553
775
|
if (!lensName || typeof lensName !== 'string') {
|
|
554
776
|
throw new ValidationError('ValidationError: lensName must be a non-empty string');
|
|
@@ -586,17 +808,44 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
586
808
|
this.schemas.set(lensName, { schema: schemaObj, strict, timestamp: Date.now() });
|
|
587
809
|
}
|
|
588
810
|
|
|
811
|
+
/**
|
|
812
|
+
* Gets the JSON Schema for a specific lens.
|
|
813
|
+
*
|
|
814
|
+
* @param {string} lensName - Name of the lens
|
|
815
|
+
* @returns {Promise<Object|null>} The schema object or null if not set
|
|
816
|
+
*/
|
|
589
817
|
async getSchema(lensName) {
|
|
590
818
|
const schemaObj = this.schemas.get(lensName);
|
|
591
819
|
return schemaObj ? schemaObj.schema : null;
|
|
592
820
|
}
|
|
593
821
|
|
|
822
|
+
/**
|
|
823
|
+
* Clears the JSON Schema for a specific lens.
|
|
824
|
+
*
|
|
825
|
+
* @param {string} lensName - Name of the lens
|
|
826
|
+
* @returns {Promise<void>}
|
|
827
|
+
*/
|
|
594
828
|
async clearSchema(lensName) {
|
|
595
829
|
this.schemas.delete(lensName);
|
|
596
830
|
// Returns undefined for contract compliance
|
|
597
831
|
}
|
|
598
832
|
|
|
599
833
|
// === Federation Operations ===
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Sets up federation between two holons for a specific lens.
|
|
837
|
+
* Federation enables data sharing and synchronization between holons.
|
|
838
|
+
*
|
|
839
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
840
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
841
|
+
* @param {string} lensName - Name of the lens to federate
|
|
842
|
+
* @param {Object} [options={}] - Federation options
|
|
843
|
+
* @param {string} [options.direction='outbound'] - Direction: 'inbound', 'outbound', or 'bidirectional'
|
|
844
|
+
* @param {string} [options.mode='reference'] - Mode: 'reference' (hologram) or 'copy'
|
|
845
|
+
* @param {Function} [options.filter] - Filter function to select which data to federate
|
|
846
|
+
* @returns {Promise<boolean>} True if federation was set up successfully
|
|
847
|
+
* @throws {Error} If trying to federate a holon with itself or invalid direction
|
|
848
|
+
*/
|
|
600
849
|
async federate(sourceHolon, targetHolon, lensName, options = {}) {
|
|
601
850
|
const { direction = 'outbound', mode = 'reference', filter = null } = options;
|
|
602
851
|
|
|
@@ -630,6 +879,18 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
630
879
|
return true;
|
|
631
880
|
}
|
|
632
881
|
|
|
882
|
+
/**
|
|
883
|
+
* Propagates existing data from one holon to another.
|
|
884
|
+
*
|
|
885
|
+
* @private
|
|
886
|
+
* @param {string} fromHolon - Source holon H3 cell ID
|
|
887
|
+
* @param {string} toHolon - Target holon H3 cell ID
|
|
888
|
+
* @param {string} lensName - Name of the lens
|
|
889
|
+
* @param {Object} [options={}] - Propagation options
|
|
890
|
+
* @param {string} [options.mode='reference'] - Mode: 'reference' or 'copy'
|
|
891
|
+
* @param {Function} [options.filter] - Filter function to select data
|
|
892
|
+
* @returns {Promise<void>}
|
|
893
|
+
*/
|
|
633
894
|
async _propagateExistingData(fromHolon, toHolon, lensName, options = {}) {
|
|
634
895
|
const { mode = 'reference', filter = null } = options;
|
|
635
896
|
const existingData = await this.read(fromHolon, lensName, null, { resolveHolograms: false });
|
|
@@ -653,6 +914,15 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
653
914
|
}
|
|
654
915
|
}
|
|
655
916
|
|
|
917
|
+
/**
|
|
918
|
+
* Gets federated data from a holon, optionally resolving holograms.
|
|
919
|
+
*
|
|
920
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
921
|
+
* @param {string} lensName - Name of the lens
|
|
922
|
+
* @param {Object} [options={}] - Options
|
|
923
|
+
* @param {boolean} [options.resolveHolograms=true] - Whether to resolve hologram references
|
|
924
|
+
* @returns {Promise<Array|null>} Array of data objects or null
|
|
925
|
+
*/
|
|
656
926
|
async getFederatedData(holonId, lensName, options = {}) {
|
|
657
927
|
const { resolveHolograms = true } = options;
|
|
658
928
|
const path = storage.buildPath(this.config.appName, holonId, lensName);
|
|
@@ -664,6 +934,14 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
664
934
|
return this._resolveHolograms(data);
|
|
665
935
|
}
|
|
666
936
|
|
|
937
|
+
/**
|
|
938
|
+
* Removes federation between two holons for a specific lens.
|
|
939
|
+
*
|
|
940
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
941
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
942
|
+
* @param {string} lensName - Name of the lens
|
|
943
|
+
* @returns {Promise<boolean>} Always returns true (idempotent operation)
|
|
944
|
+
*/
|
|
667
945
|
async unfederate(sourceHolon, targetHolon, lensName) {
|
|
668
946
|
// Remove federation config for this relationship - idempotent
|
|
669
947
|
const configPath = storage.buildPath(this.config.appName, sourceHolon, lensName, '_federation');
|
|
@@ -675,6 +953,15 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
675
953
|
return true;
|
|
676
954
|
}
|
|
677
955
|
|
|
956
|
+
/**
|
|
957
|
+
* Updates local override values on a hologram.
|
|
958
|
+
*
|
|
959
|
+
* @param {string} holonId - H3 cell ID where the hologram exists
|
|
960
|
+
* @param {string} lensName - Name of the lens
|
|
961
|
+
* @param {string} dataId - ID of the hologram
|
|
962
|
+
* @param {Object} overrides - Object containing local override values
|
|
963
|
+
* @returns {Promise<boolean>} True if update succeeded
|
|
964
|
+
*/
|
|
678
965
|
async updateHologramOverrides(holonId, lensName, dataId, overrides) {
|
|
679
966
|
return federation.updateHologramOverrides(
|
|
680
967
|
this.client,
|
|
@@ -686,6 +973,15 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
686
973
|
);
|
|
687
974
|
}
|
|
688
975
|
|
|
976
|
+
/**
|
|
977
|
+
* Creates a hologram (reference) object structure.
|
|
978
|
+
*
|
|
979
|
+
* @param {string} sourceHolon - Source holon H3 cell ID where the original data lives
|
|
980
|
+
* @param {string} lensName - Name of the lens
|
|
981
|
+
* @param {Object} data - Data object containing the id to reference
|
|
982
|
+
* @param {string} [targetHolon=null] - Target holon for the hologram, defaults to sourceHolon
|
|
983
|
+
* @returns {Object} Hologram object structure
|
|
984
|
+
*/
|
|
689
985
|
createHologram(sourceHolon, lensName, data, targetHolon = null) {
|
|
690
986
|
return federation.createHologram(
|
|
691
987
|
sourceHolon,
|
|
@@ -696,6 +992,14 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
696
992
|
);
|
|
697
993
|
}
|
|
698
994
|
|
|
995
|
+
/**
|
|
996
|
+
* Gets all active holograms (references) pointing to a specific data item.
|
|
997
|
+
*
|
|
998
|
+
* @param {string} holonId - H3 cell ID of the source holon
|
|
999
|
+
* @param {string} lensName - Name of the lens
|
|
1000
|
+
* @param {string} dataId - ID of the source data
|
|
1001
|
+
* @returns {Promise<Array>} Array of active hologram references
|
|
1002
|
+
*/
|
|
699
1003
|
async getActiveHolograms(holonId, lensName, dataId) {
|
|
700
1004
|
// Read the source data and return its activeHolograms list
|
|
701
1005
|
const path = storage.buildPath(this.config.appName, holonId, lensName, dataId);
|
|
@@ -706,6 +1010,15 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
706
1010
|
return sourceData._meta.activeHolograms;
|
|
707
1011
|
}
|
|
708
1012
|
|
|
1013
|
+
/**
|
|
1014
|
+
* Removes an active hologram reference from a source data item.
|
|
1015
|
+
*
|
|
1016
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
1017
|
+
* @param {string} lensName - Name of the lens
|
|
1018
|
+
* @param {string} dataId - ID of the source data
|
|
1019
|
+
* @param {string} targetHolon - Target holon where the hologram exists
|
|
1020
|
+
* @returns {Promise<boolean>} True if removal succeeded
|
|
1021
|
+
*/
|
|
709
1022
|
async removeActiveHologram(sourceHolon, lensName, dataId, targetHolon) {
|
|
710
1023
|
return federation.removeActiveHologram(
|
|
711
1024
|
this.client,
|
|
@@ -717,6 +1030,15 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
717
1030
|
);
|
|
718
1031
|
}
|
|
719
1032
|
|
|
1033
|
+
/**
|
|
1034
|
+
* Deletes a hologram and cleans up its references.
|
|
1035
|
+
*
|
|
1036
|
+
* @param {string} holonId - H3 cell ID where the hologram exists
|
|
1037
|
+
* @param {string} lensName - Name of the lens
|
|
1038
|
+
* @param {string} dataId - ID of the hologram to delete
|
|
1039
|
+
* @param {Object} [options={}] - Delete options
|
|
1040
|
+
* @returns {Promise<boolean>} True if deletion succeeded
|
|
1041
|
+
*/
|
|
720
1042
|
async deleteHologram(holonId, lensName, dataId, options = {}) {
|
|
721
1043
|
return federation.deleteHologram(
|
|
722
1044
|
this.client,
|
|
@@ -728,6 +1050,17 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
728
1050
|
);
|
|
729
1051
|
}
|
|
730
1052
|
|
|
1053
|
+
/**
|
|
1054
|
+
* Propagates data from source holon to target holon.
|
|
1055
|
+
*
|
|
1056
|
+
* @param {Object} data - Data to propagate
|
|
1057
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
1058
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
1059
|
+
* @param {string} lensName - Name of the lens
|
|
1060
|
+
* @param {Object} [options={}] - Propagation options
|
|
1061
|
+
* @param {string} [options.mode='reference'] - Mode: 'reference' creates hologram, 'copy' duplicates data
|
|
1062
|
+
* @returns {Promise<Object>} Result of propagation
|
|
1063
|
+
*/
|
|
731
1064
|
async propagateData(data, sourceHolon, targetHolon, lensName, options = {}) {
|
|
732
1065
|
// Extract mode from options, default to 'reference' for hologram creation
|
|
733
1066
|
const mode = options.mode || 'reference';
|
|
@@ -742,22 +1075,55 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
742
1075
|
);
|
|
743
1076
|
}
|
|
744
1077
|
|
|
1078
|
+
/**
|
|
1079
|
+
* Resolves a hologram to its source data.
|
|
1080
|
+
*
|
|
1081
|
+
* @param {Object} hologram - Hologram object to resolve
|
|
1082
|
+
* @param {Object} [options={}] - Resolution options
|
|
1083
|
+
* @returns {Promise<Object|null>} Resolved data or null if source not found
|
|
1084
|
+
*/
|
|
745
1085
|
async resolveHologram(hologram, options = {}) {
|
|
746
1086
|
return federation.resolveHologram(this.client, hologram, new Set(), [], { ...options, appname: this.config.appName });
|
|
747
1087
|
}
|
|
748
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* Checks if an object is a hologram (unresolved reference).
|
|
1091
|
+
*
|
|
1092
|
+
* @param {Object} data - Data object to check
|
|
1093
|
+
* @returns {boolean} True if the object is a hologram
|
|
1094
|
+
*/
|
|
749
1095
|
isHologram(data) {
|
|
750
1096
|
return federation.isHologram(data);
|
|
751
1097
|
}
|
|
752
1098
|
|
|
1099
|
+
/**
|
|
1100
|
+
* Checks if an object is a resolved hologram (has _hologram metadata).
|
|
1101
|
+
*
|
|
1102
|
+
* @param {Object} data - Data object to check
|
|
1103
|
+
* @returns {boolean} True if the object is a resolved hologram
|
|
1104
|
+
*/
|
|
753
1105
|
isResolvedHologram(data) {
|
|
754
1106
|
return federation.isResolvedHologram(data);
|
|
755
1107
|
}
|
|
756
1108
|
|
|
1109
|
+
/**
|
|
1110
|
+
* Gets the source information from a hologram or resolved hologram.
|
|
1111
|
+
*
|
|
1112
|
+
* @param {Object} data - Hologram or resolved hologram object
|
|
1113
|
+
* @returns {Object|null} Source information or null
|
|
1114
|
+
*/
|
|
757
1115
|
getHologramSource(data) {
|
|
758
1116
|
return federation.getHologramSource(data);
|
|
759
1117
|
}
|
|
760
1118
|
|
|
1119
|
+
/**
|
|
1120
|
+
* Cleans up circular hologram references in a holon.
|
|
1121
|
+
*
|
|
1122
|
+
* @param {string} holonId - H3 cell ID of the holon
|
|
1123
|
+
* @param {string} lensName - Name of the lens
|
|
1124
|
+
* @param {Object} [options={}] - Cleanup options
|
|
1125
|
+
* @returns {Promise<Object>} Cleanup results
|
|
1126
|
+
*/
|
|
761
1127
|
async cleanupCircularHolograms(holonId, lensName, options = {}) {
|
|
762
1128
|
return federation.cleanupCircularHolograms(
|
|
763
1129
|
this.client,
|
|
@@ -768,6 +1134,15 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
768
1134
|
);
|
|
769
1135
|
}
|
|
770
1136
|
|
|
1137
|
+
/**
|
|
1138
|
+
* Cleans up circular hologram references for specific data IDs.
|
|
1139
|
+
*
|
|
1140
|
+
* @param {string} holonId - H3 cell ID of the holon
|
|
1141
|
+
* @param {string} lensName - Name of the lens
|
|
1142
|
+
* @param {string[]} dataIds - Array of data IDs to check
|
|
1143
|
+
* @param {Object} [options={}] - Cleanup options
|
|
1144
|
+
* @returns {Promise<Object>} Cleanup results
|
|
1145
|
+
*/
|
|
771
1146
|
async cleanupCircularHologramsByIds(holonId, lensName, dataIds, options = {}) {
|
|
772
1147
|
return federation.cleanupCircularHologramsByIds(
|
|
773
1148
|
this.client,
|
|
@@ -779,6 +1154,17 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
779
1154
|
);
|
|
780
1155
|
}
|
|
781
1156
|
|
|
1157
|
+
/**
|
|
1158
|
+
* Propagates data to all federated holons.
|
|
1159
|
+
*
|
|
1160
|
+
* @param {string} holonId - Source holon H3 cell ID
|
|
1161
|
+
* @param {string} lensName - Name of the lens
|
|
1162
|
+
* @param {Object} data - Data to propagate
|
|
1163
|
+
* @param {Object} [options={}] - Propagation options
|
|
1164
|
+
* @param {boolean} [options.useHolograms=true] - Whether to create holograms
|
|
1165
|
+
* @param {boolean} [options.resolveExisting=true] - Whether to resolve existing data
|
|
1166
|
+
* @returns {Promise<Array|undefined>} Array of propagation results or undefined if no targets
|
|
1167
|
+
*/
|
|
782
1168
|
async propagate(holonId, lensName, data, options = {}) {
|
|
783
1169
|
const federationData = await this.getFederation(holonId);
|
|
784
1170
|
// getFederation returns an object with federated array, not an array directly
|
|
@@ -802,6 +1188,13 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
802
1188
|
return results;
|
|
803
1189
|
}
|
|
804
1190
|
|
|
1191
|
+
/**
|
|
1192
|
+
* Gets the federation configuration for a holon.
|
|
1193
|
+
*
|
|
1194
|
+
* @param {string} holonId - H3 cell ID of the holon
|
|
1195
|
+
* @returns {Promise<Object|null>} Federation configuration object or null
|
|
1196
|
+
* @throws {Error} If holonId is not provided
|
|
1197
|
+
*/
|
|
805
1198
|
async getFederation(holonId) {
|
|
806
1199
|
if (!holonId) {
|
|
807
1200
|
throw new Error('getFederation: Missing holon ID');
|
|
@@ -822,8 +1215,22 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
822
1215
|
return data;
|
|
823
1216
|
}
|
|
824
1217
|
|
|
1218
|
+
/**
|
|
1219
|
+
* Establishes a holon-level federation relationship.
|
|
1220
|
+
*
|
|
1221
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
1222
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
1223
|
+
* @param {Object} [options={}] - Federation options
|
|
1224
|
+
* @param {Object} [options.lensConfig] - Lens configuration for federation
|
|
1225
|
+
* @param {string[]} [options.lensConfig.inbound] - Lenses for inbound federation
|
|
1226
|
+
* @param {string[]} [options.lensConfig.outbound] - Lenses for outbound federation
|
|
1227
|
+
* @param {string} [options.partnerName] - Human-readable name for the partner holon
|
|
1228
|
+
* @param {boolean} [options.skipPropagation=false] - Skip propagating existing data
|
|
1229
|
+
* @returns {Promise<boolean>} True if federation was established
|
|
1230
|
+
* @throws {Error} If trying to federate a holon with itself
|
|
1231
|
+
*/
|
|
825
1232
|
async federateHolon(sourceHolon, targetHolon, options = {}) {
|
|
826
|
-
const { lensConfig = { inbound: [], outbound: [] }, partnerName = null } = options;
|
|
1233
|
+
const { lensConfig = { inbound: [], outbound: [] }, partnerName = null, skipPropagation = false } = options;
|
|
827
1234
|
|
|
828
1235
|
if (sourceHolon === targetHolon) {
|
|
829
1236
|
throw new Error('Cannot federate a holon with itself');
|
|
@@ -880,7 +1287,8 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
880
1287
|
const success = await this.writeGlobal('federation', federationData);
|
|
881
1288
|
this.clearCache('federation');
|
|
882
1289
|
|
|
883
|
-
if
|
|
1290
|
+
// Only propagate existing data if skipPropagation is false
|
|
1291
|
+
if (success && !skipPropagation) {
|
|
884
1292
|
for (const lens of (lensConfig.inbound || [])) {
|
|
885
1293
|
await this.federate(targetHolon, sourceHolon, lens, { direction: 'outbound', mode: 'reference' });
|
|
886
1294
|
}
|
|
@@ -892,6 +1300,13 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
892
1300
|
return success;
|
|
893
1301
|
}
|
|
894
1302
|
|
|
1303
|
+
/**
|
|
1304
|
+
* Removes a holon-level federation relationship.
|
|
1305
|
+
*
|
|
1306
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
1307
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
1308
|
+
* @returns {Promise<boolean>} True if unfederation succeeded, false if no federation existed
|
|
1309
|
+
*/
|
|
895
1310
|
async unfederateHolon(sourceHolon, targetHolon) {
|
|
896
1311
|
const federationData = await this.readGlobal('federation', sourceHolon);
|
|
897
1312
|
if (!federationData) return false;
|
|
@@ -921,6 +1336,13 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
921
1336
|
return success;
|
|
922
1337
|
}
|
|
923
1338
|
|
|
1339
|
+
/**
|
|
1340
|
+
* Gets the federation configuration between two holons.
|
|
1341
|
+
*
|
|
1342
|
+
* @param {string} sourceHolon - Source holon H3 cell ID
|
|
1343
|
+
* @param {string} targetHolon - Target holon H3 cell ID
|
|
1344
|
+
* @returns {Promise<Object|null>} Lens configuration or null
|
|
1345
|
+
*/
|
|
924
1346
|
async getFederatedConfig(sourceHolon, targetHolon) {
|
|
925
1347
|
const federationData = await this.readGlobal('federation', sourceHolon);
|
|
926
1348
|
if (!federationData || !federationData.lensConfig) return null;
|
|
@@ -928,11 +1350,33 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
928
1350
|
}
|
|
929
1351
|
|
|
930
1352
|
// === Hierarchical Operations ===
|
|
1353
|
+
|
|
1354
|
+
/**
|
|
1355
|
+
* Performs hierarchical upcast aggregation.
|
|
1356
|
+
* Aggregates data from child holons up to parent holons in the H3 hierarchy.
|
|
1357
|
+
*
|
|
1358
|
+
* @param {string} holonId - Starting holon H3 cell ID
|
|
1359
|
+
* @param {string} lensName - Name of the lens
|
|
1360
|
+
* @param {string} dataId - ID of the data to upcast
|
|
1361
|
+
* @param {Object} [options={}] - Upcast options
|
|
1362
|
+
* @returns {Promise<Object>} Aggregation result
|
|
1363
|
+
*/
|
|
931
1364
|
async upcast(holonId, lensName, dataId, options = {}) {
|
|
932
1365
|
return hierarchical.upcast(this, holonId, lensName, dataId, options);
|
|
933
1366
|
}
|
|
934
1367
|
|
|
935
1368
|
// === Subscriptions ===
|
|
1369
|
+
|
|
1370
|
+
/**
|
|
1371
|
+
* Subscribes to real-time updates for a holon and lens.
|
|
1372
|
+
*
|
|
1373
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1374
|
+
* @param {string} lensName - Name of the lens
|
|
1375
|
+
* @param {Function} callback - Callback function called with updated data
|
|
1376
|
+
* @param {Object} [options={}] - Subscription options
|
|
1377
|
+
* @returns {{unsubscribe: Function}} Subscription object with unsubscribe method
|
|
1378
|
+
* @throws {TypeError} If callback is not a function
|
|
1379
|
+
*/
|
|
936
1380
|
subscribe(holonId, lensName, callback, options = {}) {
|
|
937
1381
|
if (typeof callback !== 'function') {
|
|
938
1382
|
throw new TypeError('callback must be a function');
|
|
@@ -967,6 +1411,15 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
967
1411
|
};
|
|
968
1412
|
}
|
|
969
1413
|
|
|
1414
|
+
/**
|
|
1415
|
+
* Subscribes to real-time updates for a global table.
|
|
1416
|
+
*
|
|
1417
|
+
* @param {string} table - Name of the global table
|
|
1418
|
+
* @param {string} key - Key to subscribe to
|
|
1419
|
+
* @param {Function} callback - Callback function called with updated data
|
|
1420
|
+
* @param {Object} [options={}] - Subscription options
|
|
1421
|
+
* @returns {Promise<{unsubscribe: Function}>} Subscription object
|
|
1422
|
+
*/
|
|
970
1423
|
async subscribeGlobal(table, key, callback, options = {}) {
|
|
971
1424
|
return globalTables.subscribeGlobal(
|
|
972
1425
|
this.client,
|
|
@@ -979,27 +1432,78 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
979
1432
|
}
|
|
980
1433
|
|
|
981
1434
|
// === Crypto Operations ===
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* Derives a public key from a private key.
|
|
1438
|
+
*
|
|
1439
|
+
* @param {string} privateKey - Hex-encoded private key
|
|
1440
|
+
* @returns {Promise<string>} Hex-encoded public key
|
|
1441
|
+
*/
|
|
982
1442
|
async getPublicKey(privateKey) {
|
|
983
1443
|
return crypto.getPublicKey(privateKey);
|
|
984
1444
|
}
|
|
985
1445
|
|
|
1446
|
+
/**
|
|
1447
|
+
* Signs content with a private key.
|
|
1448
|
+
*
|
|
1449
|
+
* @param {string|Object} content - Content to sign
|
|
1450
|
+
* @param {string} privateKey - Hex-encoded private key
|
|
1451
|
+
* @returns {Promise<string>} Hex-encoded signature
|
|
1452
|
+
*/
|
|
986
1453
|
async sign(content, privateKey) {
|
|
987
1454
|
return crypto.sign(content, privateKey);
|
|
988
1455
|
}
|
|
989
1456
|
|
|
1457
|
+
/**
|
|
1458
|
+
* Verifies a signature against content and public key.
|
|
1459
|
+
*
|
|
1460
|
+
* @param {string|Object} content - Original content
|
|
1461
|
+
* @param {string} signature - Hex-encoded signature
|
|
1462
|
+
* @param {string} publicKey - Hex-encoded public key
|
|
1463
|
+
* @returns {Promise<boolean>} True if signature is valid
|
|
1464
|
+
*/
|
|
990
1465
|
async verify(content, signature, publicKey) {
|
|
991
1466
|
return crypto.verify(content, signature, publicKey);
|
|
992
1467
|
}
|
|
993
1468
|
|
|
1469
|
+
/**
|
|
1470
|
+
* Issues a capability token for authorization.
|
|
1471
|
+
*
|
|
1472
|
+
* @param {string[]} permissions - Array of permissions ('read', 'write', 'delete')
|
|
1473
|
+
* @param {Object} scope - Scope of the capability (holonId, lensName, etc.)
|
|
1474
|
+
* @param {string} recipient - Public key of the recipient
|
|
1475
|
+
* @param {Object} [options] - Additional options
|
|
1476
|
+
* @returns {Promise<string>} Signed capability token
|
|
1477
|
+
*/
|
|
994
1478
|
async issueCapability(permissions, scope, recipient, options) {
|
|
995
1479
|
return crypto.issueCapability(permissions, scope, recipient, options);
|
|
996
1480
|
}
|
|
997
1481
|
|
|
1482
|
+
/**
|
|
1483
|
+
* Verifies a capability token.
|
|
1484
|
+
*
|
|
1485
|
+
* @param {string} token - Capability token to verify
|
|
1486
|
+
* @param {string} requiredPermission - Required permission to check
|
|
1487
|
+
* @param {Object} scope - Scope to verify against
|
|
1488
|
+
* @returns {Promise<boolean>} True if token is valid and has required permission
|
|
1489
|
+
*/
|
|
998
1490
|
async verifyCapability(token, requiredPermission, scope) {
|
|
999
1491
|
return crypto.verifyCapability(token, requiredPermission, scope);
|
|
1000
1492
|
}
|
|
1001
1493
|
|
|
1002
1494
|
// === Social Protocol Operations ===
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* Publishes a Nostr event to a holon.
|
|
1498
|
+
*
|
|
1499
|
+
* @param {Object} event - Nostr event object
|
|
1500
|
+
* @param {number} event.kind - Event kind
|
|
1501
|
+
* @param {string} event.content - Event content
|
|
1502
|
+
* @param {Array} [event.tags] - Event tags
|
|
1503
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1504
|
+
* @param {string} [lensName='social'] - Name of the lens
|
|
1505
|
+
* @returns {Promise<boolean>} True if publish succeeded
|
|
1506
|
+
*/
|
|
1003
1507
|
async publishNostr(event, holonId, lensName = 'social') {
|
|
1004
1508
|
// Validate Nostr event format
|
|
1005
1509
|
social.validateNostrEvent(event, true, true); // partial=true, throwOnError=true
|
|
@@ -1021,6 +1525,16 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
1021
1525
|
return true;
|
|
1022
1526
|
}
|
|
1023
1527
|
|
|
1528
|
+
/**
|
|
1529
|
+
* Publishes an ActivityPub object to a holon.
|
|
1530
|
+
*
|
|
1531
|
+
* @param {Object} object - ActivityPub object
|
|
1532
|
+
* @param {string} object.type - ActivityPub type (Note, Article, etc.)
|
|
1533
|
+
* @param {string} [object.actor] - Actor ID (defaults to client public key)
|
|
1534
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1535
|
+
* @param {string} [lensName='social'] - Name of the lens
|
|
1536
|
+
* @returns {Promise<boolean>} True if publish succeeded
|
|
1537
|
+
*/
|
|
1024
1538
|
async publishActivityPub(object, holonId, lensName = 'social') {
|
|
1025
1539
|
// Validate ActivityPub object format
|
|
1026
1540
|
social.validateActivityPubObject(object, true); // throwOnError=true
|
|
@@ -1032,6 +1546,18 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
1032
1546
|
return this.write(holonId, lensName, activity);
|
|
1033
1547
|
}
|
|
1034
1548
|
|
|
1549
|
+
/**
|
|
1550
|
+
* Queries social protocol data from a holon.
|
|
1551
|
+
*
|
|
1552
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1553
|
+
* @param {Object} [options={}] - Query options
|
|
1554
|
+
* @param {string} [options.lens='social'] - Name of the lens
|
|
1555
|
+
* @param {string} [options.protocol] - Filter by protocol ('nostr', 'activitypub', 'all')
|
|
1556
|
+
* @param {string} [options.type] - Filter by content type
|
|
1557
|
+
* @param {number} [options.since] - Filter events after this timestamp
|
|
1558
|
+
* @param {number} [options.until] - Filter events before this timestamp
|
|
1559
|
+
* @returns {Promise<Array>} Array of matching social items
|
|
1560
|
+
*/
|
|
1035
1561
|
async querySocial(holonId, options = {}) {
|
|
1036
1562
|
const lensName = options.lens || 'social';
|
|
1037
1563
|
const data = await this.read(holonId, lensName);
|
|
@@ -1049,6 +1575,19 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
1049
1575
|
});
|
|
1050
1576
|
}
|
|
1051
1577
|
|
|
1578
|
+
/**
|
|
1579
|
+
* Verifies a Nostr event signature.
|
|
1580
|
+
*
|
|
1581
|
+
* @param {Object} event - Nostr event to verify
|
|
1582
|
+
* @param {string} event.id - Event ID
|
|
1583
|
+
* @param {string} event.pubkey - Author public key
|
|
1584
|
+
* @param {number} event.created_at - Creation timestamp
|
|
1585
|
+
* @param {number} event.kind - Event kind
|
|
1586
|
+
* @param {Array} event.tags - Event tags
|
|
1587
|
+
* @param {string} event.content - Event content
|
|
1588
|
+
* @param {string} event.sig - Event signature
|
|
1589
|
+
* @returns {Promise<boolean>} True if event signature is valid
|
|
1590
|
+
*/
|
|
1052
1591
|
async verifyNostrEvent(event) {
|
|
1053
1592
|
// Extract only standard Nostr event fields for verification
|
|
1054
1593
|
// (nostr-tools can't serialize events with extra properties like 'protocol')
|
|
@@ -1058,6 +1597,19 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
1058
1597
|
}
|
|
1059
1598
|
|
|
1060
1599
|
// === Metrics ===
|
|
1600
|
+
|
|
1601
|
+
/**
|
|
1602
|
+
* Gets performance metrics for this HoloSphere instance.
|
|
1603
|
+
*
|
|
1604
|
+
* @returns {Object} Metrics object
|
|
1605
|
+
* @returns {number} return.reads - Number of read operations
|
|
1606
|
+
* @returns {number} return.writes - Number of write operations
|
|
1607
|
+
* @returns {number} return.deletes - Number of delete operations
|
|
1608
|
+
* @returns {number} return.federations - Number of federation operations
|
|
1609
|
+
* @returns {number} return.subscriptions - Number of active subscriptions
|
|
1610
|
+
* @returns {number} return.avgReadTime - Average read time in milliseconds
|
|
1611
|
+
* @returns {number} return.avgWriteTime - Average write time in milliseconds
|
|
1612
|
+
*/
|
|
1061
1613
|
metrics() {
|
|
1062
1614
|
const reads = this._metrics.reads || 0;
|
|
1063
1615
|
const writes = this._metrics.writes || 0;
|
|
@@ -1076,59 +1628,157 @@ class HoloSphereBase extends HoloSphereCore {
|
|
|
1076
1628
|
}
|
|
1077
1629
|
|
|
1078
1630
|
// === Aliases ===
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* Alias for {@link HoloSphereBase#write}.
|
|
1634
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1635
|
+
* @param {string} lensName - Name of the lens
|
|
1636
|
+
* @param {Object} data - Data to write
|
|
1637
|
+
* @param {Object} [options] - Write options
|
|
1638
|
+
* @returns {Promise<boolean>}
|
|
1639
|
+
*/
|
|
1079
1640
|
async put(holonId, lensName, data, options = {}) {
|
|
1080
1641
|
return this.write(holonId, lensName, data, options);
|
|
1081
1642
|
}
|
|
1082
1643
|
|
|
1644
|
+
/**
|
|
1645
|
+
* Alias for {@link HoloSphereBase#read}.
|
|
1646
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1647
|
+
* @param {string} lensName - Name of the lens
|
|
1648
|
+
* @param {string|null} [dataId] - Specific data ID or null
|
|
1649
|
+
* @param {Object} [options] - Read options
|
|
1650
|
+
* @returns {Promise<Object|Array|null>}
|
|
1651
|
+
*/
|
|
1083
1652
|
async get(holonId, lensName, dataId = null, options = {}) {
|
|
1084
1653
|
return this.read(holonId, lensName, dataId, options);
|
|
1085
1654
|
}
|
|
1086
1655
|
|
|
1656
|
+
/**
|
|
1657
|
+
* Alias for {@link HoloSphereBase#delete}.
|
|
1658
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1659
|
+
* @param {string} lensName - Name of the lens
|
|
1660
|
+
* @param {string} dataId - Data ID to delete
|
|
1661
|
+
* @param {Object} [options] - Delete options
|
|
1662
|
+
* @returns {Promise<boolean>}
|
|
1663
|
+
*/
|
|
1087
1664
|
async remove(holonId, lensName, dataId, options = {}) {
|
|
1088
1665
|
return this.delete(holonId, lensName, dataId, options);
|
|
1089
1666
|
}
|
|
1090
1667
|
|
|
1668
|
+
/**
|
|
1669
|
+
* Alias for {@link HoloSphereBase#writeGlobal}.
|
|
1670
|
+
* @param {string} table - Global table name
|
|
1671
|
+
* @param {Object} data - Data to write
|
|
1672
|
+
* @returns {Promise<boolean>}
|
|
1673
|
+
*/
|
|
1091
1674
|
async putGlobal(table, data) {
|
|
1092
1675
|
return this.writeGlobal(table, data);
|
|
1093
1676
|
}
|
|
1094
1677
|
|
|
1678
|
+
/**
|
|
1679
|
+
* Alias for {@link HoloSphereBase#readGlobal}.
|
|
1680
|
+
* @param {string} table - Global table name
|
|
1681
|
+
* @param {string|null} [key] - Key to read
|
|
1682
|
+
* @returns {Promise<Object|Array|null>}
|
|
1683
|
+
*/
|
|
1095
1684
|
async getGlobal(table, key = null) {
|
|
1096
1685
|
return this.readGlobal(table, key);
|
|
1097
1686
|
}
|
|
1098
1687
|
|
|
1688
|
+
/**
|
|
1689
|
+
* Alias for {@link HoloSphereBase#deleteGlobal}.
|
|
1690
|
+
* @param {string} table - Global table name
|
|
1691
|
+
* @param {string} key - Key to delete
|
|
1692
|
+
* @returns {Promise<boolean>}
|
|
1693
|
+
*/
|
|
1099
1694
|
async removeGlobal(table, key) {
|
|
1100
1695
|
return this.deleteGlobal(table, key);
|
|
1101
1696
|
}
|
|
1102
1697
|
|
|
1698
|
+
/**
|
|
1699
|
+
* Alias for {@link HoloSphereBase#setSchema}.
|
|
1700
|
+
* @param {string} lensName - Lens name
|
|
1701
|
+
* @param {Object|string} schemaObj - Schema object or URI
|
|
1702
|
+
* @param {boolean} [strict] - Strict mode
|
|
1703
|
+
* @returns {Promise<void>}
|
|
1704
|
+
*/
|
|
1103
1705
|
async defineSchema(lensName, schemaObj, strict = false) {
|
|
1104
1706
|
return this.setSchema(lensName, schemaObj, strict);
|
|
1105
1707
|
}
|
|
1106
1708
|
|
|
1709
|
+
/**
|
|
1710
|
+
* Alias for {@link HoloSphereBase#getSchema}.
|
|
1711
|
+
* @param {string} lensName - Lens name
|
|
1712
|
+
* @returns {Promise<Object|null>}
|
|
1713
|
+
*/
|
|
1107
1714
|
async fetchSchema(lensName) {
|
|
1108
1715
|
return this.getSchema(lensName);
|
|
1109
1716
|
}
|
|
1110
1717
|
|
|
1718
|
+
/**
|
|
1719
|
+
* Alias for {@link HoloSphereBase#clearSchema}.
|
|
1720
|
+
* @param {string} lensName - Lens name
|
|
1721
|
+
* @returns {Promise<void>}
|
|
1722
|
+
*/
|
|
1111
1723
|
async removeSchema(lensName) {
|
|
1112
1724
|
return this.clearSchema(lensName);
|
|
1113
1725
|
}
|
|
1114
1726
|
|
|
1727
|
+
/**
|
|
1728
|
+
* Alias for {@link HoloSphereBase#write}.
|
|
1729
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1730
|
+
* @param {string} lensName - Name of the lens
|
|
1731
|
+
* @param {Object} data - Data to write
|
|
1732
|
+
* @param {Object} [options] - Write options
|
|
1733
|
+
* @returns {Promise<boolean>}
|
|
1734
|
+
*/
|
|
1115
1735
|
async store(holonId, lensName, data, options = {}) {
|
|
1116
1736
|
return this.write(holonId, lensName, data, options);
|
|
1117
1737
|
}
|
|
1118
1738
|
|
|
1739
|
+
/**
|
|
1740
|
+
* Alias for {@link HoloSphereBase#read}.
|
|
1741
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1742
|
+
* @param {string} lensName - Name of the lens
|
|
1743
|
+
* @param {string|null} [dataId] - Specific data ID or null
|
|
1744
|
+
* @param {Object} [options] - Read options
|
|
1745
|
+
* @returns {Promise<Object|Array|null>}
|
|
1746
|
+
*/
|
|
1119
1747
|
async fetch(holonId, lensName, dataId = null, options = {}) {
|
|
1120
1748
|
return this.read(holonId, lensName, dataId, options);
|
|
1121
1749
|
}
|
|
1122
1750
|
|
|
1751
|
+
/**
|
|
1752
|
+
* Alias for {@link HoloSphereBase#write}.
|
|
1753
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1754
|
+
* @param {string} lensName - Name of the lens
|
|
1755
|
+
* @param {Object} data - Data to write
|
|
1756
|
+
* @param {Object} [options] - Write options
|
|
1757
|
+
* @returns {Promise<boolean>}
|
|
1758
|
+
*/
|
|
1123
1759
|
async save(holonId, lensName, data, options = {}) {
|
|
1124
1760
|
return this.write(holonId, lensName, data, options);
|
|
1125
1761
|
}
|
|
1126
1762
|
|
|
1763
|
+
/**
|
|
1764
|
+
* Alias for {@link HoloSphereBase#read}.
|
|
1765
|
+
* @param {string} holonId - H3 cell ID for the holon
|
|
1766
|
+
* @param {string} lensName - Name of the lens
|
|
1767
|
+
* @param {string|null} [dataId] - Specific data ID or null
|
|
1768
|
+
* @param {Object} [options] - Read options
|
|
1769
|
+
* @returns {Promise<Object|Array|null>}
|
|
1770
|
+
*/
|
|
1127
1771
|
async load(holonId, lensName, dataId = null, options = {}) {
|
|
1128
1772
|
return this.read(holonId, lensName, dataId, options);
|
|
1129
1773
|
}
|
|
1130
1774
|
|
|
1131
1775
|
// === Cache ===
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* Clears the internal cache.
|
|
1779
|
+
*
|
|
1780
|
+
* @param {string|null} [pattern=null] - If provided, only clear cache entries matching this pattern
|
|
1781
|
+
*/
|
|
1132
1782
|
clearCache(pattern = null) {
|
|
1133
1783
|
if (pattern) {
|
|
1134
1784
|
for (const key of this._cache.keys()) {
|