holosphere 2.0.0-alpha0 → 2.0.0-alpha10
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 +473 -0
- package/FEATURES.md +431 -0
- package/LICENSE +29 -42
- package/LICENSE-AGPL.md +180 -0
- package/README.md +97 -16
- package/dist/2019-D2OG2idw.js +6680 -0
- package/dist/2019-D2OG2idw.js.map +1 -0
- package/dist/2019-EION3wKo.cjs +8 -0
- package/dist/2019-EION3wKo.cjs.map +1 -0
- package/dist/_commonjsHelpers-C37NGDzP.cjs +2 -0
- package/dist/_commonjsHelpers-C37NGDzP.cjs.map +1 -0
- package/dist/_commonjsHelpers-CUmg6egw.js +7 -0
- package/dist/_commonjsHelpers-CUmg6egw.js.map +1 -0
- package/dist/browser-BSniCNqO.js +3058 -0
- package/dist/browser-BSniCNqO.js.map +1 -0
- package/dist/browser-Cq59Ij19.cjs +2 -0
- package/dist/browser-Cq59Ij19.cjs.map +1 -0
- package/dist/cdn/holosphere.min.js +55 -0
- package/dist/cdn/holosphere.min.js.map +1 -0
- package/dist/cjs/holosphere.cjs +2 -0
- package/dist/cjs/holosphere.cjs.map +1 -0
- package/dist/esm/holosphere.js +53 -0
- package/dist/esm/holosphere.js.map +1 -0
- package/dist/index-DDGt_V9o.cjs +12 -0
- package/dist/index-DDGt_V9o.cjs.map +1 -0
- package/dist/index-DJXftyvB.js +39841 -0
- package/dist/index-DJXftyvB.js.map +1 -0
- package/dist/index-DMbdcMtK.cjs +18 -0
- package/dist/index-DMbdcMtK.cjs.map +1 -0
- package/dist/index-DeZ1xz_s.js +15104 -0
- package/dist/index-DeZ1xz_s.js.map +1 -0
- package/dist/indexeddb-storage-BFt6hMeF.js +176 -0
- package/dist/indexeddb-storage-BFt6hMeF.js.map +1 -0
- package/dist/indexeddb-storage-BK5tv4Sh.cjs +2 -0
- package/dist/indexeddb-storage-BK5tv4Sh.cjs.map +1 -0
- package/dist/memory-storage-C9HuoL2E.js +91 -0
- package/dist/memory-storage-C9HuoL2E.js.map +1 -0
- package/dist/memory-storage-Dao7jfYG.cjs +2 -0
- package/dist/memory-storage-Dao7jfYG.cjs.map +1 -0
- package/dist/secp256k1-BbKzbLtD.cjs +12 -0
- package/dist/secp256k1-BbKzbLtD.cjs.map +1 -0
- package/dist/secp256k1-CreY7Pcl.js +1890 -0
- package/dist/secp256k1-CreY7Pcl.js.map +1 -0
- package/docs/CONTRACTS.md +797 -0
- package/docs/FOSDEM_PROPOSAL.md +388 -0
- package/docs/LOCALFIRST.md +266 -0
- 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/docs/contracts/api-interface.md +793 -0
- package/docs/data-model.md +476 -0
- package/docs/gun-async-usage.md +338 -0
- package/docs/plan.md +349 -0
- package/docs/quickstart.md +674 -0
- package/docs/research.md +362 -0
- package/docs/spec.md +244 -0
- package/docs/storage-backends.md +326 -0
- package/docs/tasks.md +947 -0
- package/examples/demo.html +47 -0
- package/examples/holosphere-widget.js +1242 -0
- package/examples/widget-demo.html +274 -0
- package/examples/widget.html +703 -0
- package/jsdoc.json +26 -0
- package/package.json +25 -7
- 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/cdn-entry.js +22 -0
- package/src/content/social-protocols.js +34 -25
- package/src/contracts/abis/Appreciative.json +1280 -0
- package/src/contracts/abis/AppreciativeFactory.json +101 -0
- package/src/contracts/abis/Bundle.json +1438 -0
- package/src/contracts/abis/BundleFactory.json +106 -0
- package/src/contracts/abis/Holon.json +881 -0
- package/src/contracts/abis/Holons.json +330 -0
- package/src/contracts/abis/Managed.json +1262 -0
- package/src/contracts/abis/ManagedFactory.json +149 -0
- package/src/contracts/abis/Membrane.json +261 -0
- package/src/contracts/abis/Splitter.json +1624 -0
- package/src/contracts/abis/SplitterFactory.json +220 -0
- package/src/contracts/abis/TestToken.json +321 -0
- package/src/contracts/abis/Zoned.json +1461 -0
- package/src/contracts/abis/ZonedFactory.json +154 -0
- package/src/contracts/chain-manager.js +403 -0
- package/src/contracts/deployer.js +500 -0
- package/src/contracts/event-listener.js +539 -0
- package/src/contracts/holon-contracts.js +359 -0
- package/src/contracts/index.js +82 -0
- package/src/contracts/networks.js +229 -0
- package/src/contracts/operations.js +687 -0
- package/src/contracts/queries.js +638 -0
- package/src/core/holosphere.js +487 -6
- package/src/crypto/nostr-utils.js +303 -0
- package/src/crypto/secp256k1.js +7 -2
- package/src/federation/handshake.js +475 -0
- package/src/federation/hologram.js +117 -3
- package/src/hierarchical/upcast.js +40 -25
- package/src/index.js +1501 -1909
- package/src/lib/ai-methods.js +657 -0
- package/src/lib/contract-methods.js +442 -0
- package/src/lib/errors.js +53 -0
- package/src/lib/federation-methods.js +345 -0
- package/src/lib/index.js +30 -0
- package/src/schema/validator.js +22 -3
- package/src/spatial/h3-operations.js +19 -3
- 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 +692 -50
- 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 +35 -3
- package/src/storage/gun-async.js +75 -15
- package/src/storage/gun-auth.js +373 -0
- package/src/storage/gun-federation.js +785 -0
- package/src/storage/gun-references.js +209 -0
- package/src/storage/gun-schema.js +306 -0
- package/src/storage/gun-wrapper.js +475 -54
- package/src/storage/indexeddb-storage.js +112 -13
- package/src/storage/key-storage-simple.js +32 -9
- package/src/storage/key-storage.js +45 -13
- package/src/storage/memory-storage.js +68 -2
- package/src/storage/migration.js +20 -7
- package/src/storage/nostr-async.js +412 -122
- package/src/storage/nostr-client.js +749 -76
- package/src/storage/nostr-wrapper.js +6 -2
- package/src/storage/outbox-queue.js +55 -18
- package/src/storage/persistent-storage.js +62 -14
- package/src/storage/sync-service.js +51 -17
- package/src/storage/unified-storage.js +154 -0
- package/src/subscriptions/manager.js +34 -17
- package/types/index.d.ts +133 -0
- package/vite.config.cdn.js +60 -0
- package/tests/unit/ai/aggregation.test.js +0 -295
- package/tests/unit/ai/breakdown.test.js +0 -446
- package/tests/unit/ai/classifier.test.js +0 -294
- package/tests/unit/ai/council.test.js +0 -262
- package/tests/unit/ai/embeddings.test.js +0 -384
- package/tests/unit/ai/federation-ai.test.js +0 -344
- package/tests/unit/ai/h3-ai.test.js +0 -458
- package/tests/unit/ai/index.test.js +0 -304
- package/tests/unit/ai/json-ops.test.js +0 -307
- package/tests/unit/ai/llm-service.test.js +0 -390
- package/tests/unit/ai/nl-query.test.js +0 -383
- package/tests/unit/ai/relationships.test.js +0 -311
- package/tests/unit/ai/schema-extractor.test.js +0 -384
- package/tests/unit/ai/spatial.test.js +0 -279
- package/tests/unit/ai/tts.test.js +0 -279
- package/tests/unit/content.test.js +0 -332
- package/tests/unit/contract/core.test.js +0 -88
- package/tests/unit/contract/crypto.test.js +0 -198
- package/tests/unit/contract/data.test.js +0 -223
- package/tests/unit/contract/federation.test.js +0 -181
- package/tests/unit/contract/hierarchical.test.js +0 -113
- package/tests/unit/contract/schema.test.js +0 -114
- package/tests/unit/contract/social.test.js +0 -217
- package/tests/unit/contract/spatial.test.js +0 -110
- package/tests/unit/contract/subscriptions.test.js +0 -128
- package/tests/unit/contract/utils.test.js +0 -159
- package/tests/unit/core.test.js +0 -152
- package/tests/unit/crypto.test.js +0 -328
- package/tests/unit/federation.test.js +0 -234
- package/tests/unit/gun-async.test.js +0 -252
- package/tests/unit/hierarchical.test.js +0 -399
- package/tests/unit/integration/scenario-01-geographic-storage.test.js +0 -74
- package/tests/unit/integration/scenario-02-federation.test.js +0 -76
- package/tests/unit/integration/scenario-03-subscriptions.test.js +0 -102
- package/tests/unit/integration/scenario-04-validation.test.js +0 -129
- package/tests/unit/integration/scenario-05-hierarchy.test.js +0 -125
- package/tests/unit/integration/scenario-06-social.test.js +0 -135
- package/tests/unit/integration/scenario-07-persistence.test.js +0 -130
- package/tests/unit/integration/scenario-08-authorization.test.js +0 -161
- package/tests/unit/integration/scenario-09-cross-dimensional.test.js +0 -139
- package/tests/unit/integration/scenario-10-cross-holosphere-capabilities.test.js +0 -357
- package/tests/unit/integration/scenario-11-cross-holosphere-federation.test.js +0 -410
- package/tests/unit/integration/scenario-12-capability-federated-read.test.js +0 -719
- package/tests/unit/performance/benchmark.test.js +0 -85
- package/tests/unit/schema.test.js +0 -213
- package/tests/unit/spatial.test.js +0 -158
- package/tests/unit/storage.test.js +0 -195
- package/tests/unit/subscriptions.test.js +0 -328
- package/tests/unit/test-data-permanence-debug.js +0 -197
- package/tests/unit/test-data-permanence.js +0 -340
- package/tests/unit/test-key-persistence-fixed.js +0 -148
- package/tests/unit/test-key-persistence.js +0 -172
- package/tests/unit/test-relay-permanence.js +0 -376
- package/tests/unit/test-second-node.js +0 -95
- package/tests/unit/test-simple-write.js +0 -89
- /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
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Nostr Storage Wrapper
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview Nostr Storage Wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Drop-in replacement for gun-wrapper.js providing the same API.
|
|
4
5
|
* Handles path construction and CRUD operations using Nostr relays
|
|
6
|
+
* for distributed P2P storage.
|
|
7
|
+
*
|
|
8
|
+
* @module storage/nostr-wrapper
|
|
5
9
|
*/
|
|
6
10
|
|
|
7
11
|
import {
|
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OutboxQueue - Persistent queue for reliable relay delivery
|
|
2
|
+
* @fileoverview OutboxQueue - Persistent queue for reliable relay delivery.
|
|
3
3
|
*
|
|
4
4
|
* Implements guaranteed delivery with exponential backoff retry.
|
|
5
5
|
* Events are persisted to local storage and retried until delivered
|
|
6
6
|
* or max retries exceeded.
|
|
7
|
+
*
|
|
8
|
+
* @module storage/outbox-queue
|
|
7
9
|
*/
|
|
8
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Persistent queue for reliable event delivery to Nostr relays.
|
|
13
|
+
*
|
|
14
|
+
* Features:
|
|
15
|
+
* - Exponential backoff retry with jitter
|
|
16
|
+
* - Persistent storage across restarts
|
|
17
|
+
* - Automatic purging of old failed events
|
|
18
|
+
* - Queue statistics and monitoring
|
|
19
|
+
*
|
|
20
|
+
* @class OutboxQueue
|
|
21
|
+
* @example
|
|
22
|
+
* const queue = new OutboxQueue(storage, { maxRetries: 5 });
|
|
23
|
+
* await queue.enqueue(signedEvent, ['wss://relay1.com', 'wss://relay2.com']);
|
|
24
|
+
*/
|
|
9
25
|
export class OutboxQueue {
|
|
10
26
|
/**
|
|
27
|
+
* Create a new OutboxQueue.
|
|
28
|
+
*
|
|
11
29
|
* @param {Object} persistentStorage - Storage adapter (IndexedDB/FileSystem)
|
|
12
|
-
* @param {Object} options - Configuration options
|
|
13
|
-
* @param {number} options.maxRetries - Max retry attempts
|
|
14
|
-
* @param {number} options.baseDelay - Base delay in ms
|
|
15
|
-
* @param {number} options.maxDelay - Max delay cap in ms (
|
|
16
|
-
* @param {number} options.failedTTL - TTL for failed events in ms (
|
|
30
|
+
* @param {Object} [options={}] - Configuration options
|
|
31
|
+
* @param {number} [options.maxRetries=5] - Max retry attempts
|
|
32
|
+
* @param {number} [options.baseDelay=1000] - Base delay in ms
|
|
33
|
+
* @param {number} [options.maxDelay=60000] - Max delay cap in ms (1 minute)
|
|
34
|
+
* @param {number} [options.failedTTL=86400000] - TTL for failed events in ms (24 hours)
|
|
17
35
|
*/
|
|
18
36
|
constructor(persistentStorage, options = {}) {
|
|
19
37
|
this.storage = persistentStorage;
|
|
@@ -25,10 +43,11 @@ export class OutboxQueue {
|
|
|
25
43
|
}
|
|
26
44
|
|
|
27
45
|
/**
|
|
28
|
-
* Add an event to the outbox queue
|
|
46
|
+
* Add an event to the outbox queue.
|
|
47
|
+
*
|
|
29
48
|
* @param {Object} event - Signed Nostr event
|
|
30
49
|
* @param {string[]} relays - Target relay URLs
|
|
31
|
-
* @returns {Promise<Object>} Queue entry
|
|
50
|
+
* @returns {Promise<Object>} Queue entry with metadata
|
|
32
51
|
*/
|
|
33
52
|
async enqueue(event, relays) {
|
|
34
53
|
const entry = {
|
|
@@ -48,9 +67,13 @@ export class OutboxQueue {
|
|
|
48
67
|
}
|
|
49
68
|
|
|
50
69
|
/**
|
|
51
|
-
* Mark an event as sent
|
|
70
|
+
* Mark an event as sent.
|
|
71
|
+
*
|
|
72
|
+
* Removes from queue if at least one relay accepted, otherwise schedules retry.
|
|
73
|
+
*
|
|
52
74
|
* @param {string} eventId - Event ID
|
|
53
75
|
* @param {string[]} successfulRelays - Relays that accepted the event
|
|
76
|
+
* @returns {Promise<void>}
|
|
54
77
|
*/
|
|
55
78
|
async markSent(eventId, successfulRelays) {
|
|
56
79
|
const key = `${this.queuePrefix}${eventId}`;
|
|
@@ -67,8 +90,14 @@ export class OutboxQueue {
|
|
|
67
90
|
}
|
|
68
91
|
|
|
69
92
|
/**
|
|
70
|
-
* Schedule a retry with exponential backoff
|
|
93
|
+
* Schedule a retry with exponential backoff.
|
|
94
|
+
*
|
|
95
|
+
* Uses exponential backoff with jitter. Marks as failed if max retries exceeded.
|
|
96
|
+
*
|
|
71
97
|
* @private
|
|
98
|
+
* @param {string} key - Storage key
|
|
99
|
+
* @param {Object} entry - Queue entry
|
|
100
|
+
* @returns {Promise<void>}
|
|
72
101
|
*/
|
|
73
102
|
async _scheduleRetry(key, entry) {
|
|
74
103
|
entry.retries++;
|
|
@@ -90,7 +119,8 @@ export class OutboxQueue {
|
|
|
90
119
|
}
|
|
91
120
|
|
|
92
121
|
/**
|
|
93
|
-
* Get all pending events ready for retry
|
|
122
|
+
* Get all pending events ready for retry.
|
|
123
|
+
*
|
|
94
124
|
* @returns {Promise<Object[]>} Pending queue entries sorted by creation time
|
|
95
125
|
*/
|
|
96
126
|
async getPendingEvents() {
|
|
@@ -103,7 +133,8 @@ export class OutboxQueue {
|
|
|
103
133
|
}
|
|
104
134
|
|
|
105
135
|
/**
|
|
106
|
-
* Get all failed events (exceeded max retries)
|
|
136
|
+
* Get all failed events (exceeded max retries).
|
|
137
|
+
*
|
|
107
138
|
* @returns {Promise<Object[]>} Failed queue entries
|
|
108
139
|
*/
|
|
109
140
|
async getFailedEvents() {
|
|
@@ -112,8 +143,9 @@ export class OutboxQueue {
|
|
|
112
143
|
}
|
|
113
144
|
|
|
114
145
|
/**
|
|
115
|
-
* Get queue statistics
|
|
116
|
-
*
|
|
146
|
+
* Get queue statistics.
|
|
147
|
+
*
|
|
148
|
+
* @returns {Promise<Object>} Stats object with total, pending, failed counts and oldest timestamps
|
|
117
149
|
*/
|
|
118
150
|
async getStats() {
|
|
119
151
|
const allEntries = await this.storage.getAll(this.queuePrefix);
|
|
@@ -146,8 +178,9 @@ export class OutboxQueue {
|
|
|
146
178
|
}
|
|
147
179
|
|
|
148
180
|
/**
|
|
149
|
-
* Purge failed events older than maxAge
|
|
150
|
-
*
|
|
181
|
+
* Purge failed events older than maxAge.
|
|
182
|
+
*
|
|
183
|
+
* @param {number} [maxAge] - Max age in ms (defaults to failedTTL)
|
|
151
184
|
* @returns {Promise<number>} Number of entries purged
|
|
152
185
|
*/
|
|
153
186
|
async purgeOldFailed(maxAge = this.failedTTL) {
|
|
@@ -166,7 +199,8 @@ export class OutboxQueue {
|
|
|
166
199
|
}
|
|
167
200
|
|
|
168
201
|
/**
|
|
169
|
-
* Clear all entries from the queue
|
|
202
|
+
* Clear all entries from the queue.
|
|
203
|
+
*
|
|
170
204
|
* @returns {Promise<number>} Number of entries cleared
|
|
171
205
|
*/
|
|
172
206
|
async clear() {
|
|
@@ -184,7 +218,10 @@ export class OutboxQueue {
|
|
|
184
218
|
}
|
|
185
219
|
|
|
186
220
|
/**
|
|
187
|
-
* Manually retry a failed event
|
|
221
|
+
* Manually retry a failed event.
|
|
222
|
+
*
|
|
223
|
+
* Resets retry counter and status to allow manual retry of a failed event.
|
|
224
|
+
*
|
|
188
225
|
* @param {string} eventId - Event ID to retry
|
|
189
226
|
* @returns {Promise<Object|null>} Updated entry or null if not found
|
|
190
227
|
*/
|
|
@@ -1,64 +1,102 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Persistent Storage Interface
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview Persistent Storage Interface.
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified API for local persistence across browser and Node.js.
|
|
5
|
+
* Automatically selects the appropriate storage backend:
|
|
6
|
+
* - IndexedDB in browsers
|
|
7
|
+
* - Filesystem in Node.js
|
|
8
|
+
* - Memory fallback if neither available
|
|
9
|
+
*
|
|
10
|
+
* @module storage/persistent-storage
|
|
4
11
|
*/
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
|
-
* Base class for persistent storage adapters
|
|
14
|
+
* Base class for persistent storage adapters.
|
|
15
|
+
*
|
|
16
|
+
* All storage implementations must extend this class and implement all methods.
|
|
17
|
+
*
|
|
18
|
+
* @class PersistentStorage
|
|
19
|
+
* @abstract
|
|
8
20
|
*/
|
|
9
21
|
class PersistentStorage {
|
|
10
22
|
/**
|
|
11
|
-
* Initialize storage
|
|
23
|
+
* Initialize storage with namespace.
|
|
24
|
+
*
|
|
25
|
+
* @abstract
|
|
12
26
|
* @param {string} namespace - Storage namespace (appName)
|
|
27
|
+
* @returns {Promise<void>}
|
|
28
|
+
* @throws {Error} Must be implemented by subclass
|
|
13
29
|
*/
|
|
14
30
|
async init(namespace) {
|
|
15
31
|
throw new Error('init() must be implemented by subclass');
|
|
16
32
|
}
|
|
17
33
|
|
|
18
34
|
/**
|
|
19
|
-
* Store event
|
|
35
|
+
* Store event.
|
|
36
|
+
*
|
|
37
|
+
* @abstract
|
|
20
38
|
* @param {string} key - Event ID or d-tag
|
|
21
39
|
* @param {Object} event - Nostr event
|
|
40
|
+
* @returns {Promise<void>}
|
|
41
|
+
* @throws {Error} Must be implemented by subclass
|
|
22
42
|
*/
|
|
23
43
|
async put(key, event) {
|
|
24
44
|
throw new Error('put() must be implemented by subclass');
|
|
25
45
|
}
|
|
26
46
|
|
|
27
47
|
/**
|
|
28
|
-
* Retrieve event
|
|
48
|
+
* Retrieve event.
|
|
49
|
+
*
|
|
50
|
+
* @abstract
|
|
29
51
|
* @param {string} key - Event ID or d-tag
|
|
30
52
|
* @returns {Promise<Object|null>} Event or null
|
|
53
|
+
* @throws {Error} Must be implemented by subclass
|
|
31
54
|
*/
|
|
32
55
|
async get(key) {
|
|
33
56
|
throw new Error('get() must be implemented by subclass');
|
|
34
57
|
}
|
|
35
58
|
|
|
36
59
|
/**
|
|
37
|
-
* Get all events matching prefix
|
|
60
|
+
* Get all events matching prefix.
|
|
61
|
+
*
|
|
62
|
+
* @abstract
|
|
38
63
|
* @param {string} prefix - Key prefix
|
|
39
|
-
* @returns {Promise<
|
|
64
|
+
* @returns {Promise<any[]>} Array of events
|
|
65
|
+
* @throws {Error} Must be implemented by subclass
|
|
40
66
|
*/
|
|
41
67
|
async getAll(prefix) {
|
|
42
68
|
throw new Error('getAll() must be implemented by subclass');
|
|
43
69
|
}
|
|
44
70
|
|
|
45
71
|
/**
|
|
46
|
-
* Delete event
|
|
72
|
+
* Delete event.
|
|
73
|
+
*
|
|
74
|
+
* @abstract
|
|
47
75
|
* @param {string} key - Event ID or d-tag
|
|
76
|
+
* @returns {Promise<void>}
|
|
77
|
+
* @throws {Error} Must be implemented by subclass
|
|
48
78
|
*/
|
|
49
79
|
async delete(key) {
|
|
50
80
|
throw new Error('delete() must be implemented by subclass');
|
|
51
81
|
}
|
|
52
82
|
|
|
53
83
|
/**
|
|
54
|
-
* Clear all data in namespace
|
|
84
|
+
* Clear all data in namespace.
|
|
85
|
+
*
|
|
86
|
+
* @abstract
|
|
87
|
+
* @returns {Promise<void>}
|
|
88
|
+
* @throws {Error} Must be implemented by subclass
|
|
55
89
|
*/
|
|
56
90
|
async clear() {
|
|
57
91
|
throw new Error('clear() must be implemented by subclass');
|
|
58
92
|
}
|
|
59
93
|
|
|
60
94
|
/**
|
|
61
|
-
* Close storage
|
|
95
|
+
* Close storage connection.
|
|
96
|
+
*
|
|
97
|
+
* @abstract
|
|
98
|
+
* @returns {Promise<void>}
|
|
99
|
+
* @throws {Error} Must be implemented by subclass
|
|
62
100
|
*/
|
|
63
101
|
async close() {
|
|
64
102
|
throw new Error('close() must be implemented by subclass');
|
|
@@ -66,10 +104,20 @@ class PersistentStorage {
|
|
|
66
104
|
}
|
|
67
105
|
|
|
68
106
|
/**
|
|
69
|
-
* Detect environment and return appropriate storage adapter
|
|
107
|
+
* Detect environment and return appropriate storage adapter.
|
|
108
|
+
*
|
|
109
|
+
* Automatically creates:
|
|
110
|
+
* - IndexedDBStorage in browsers
|
|
111
|
+
* - FileSystemStorage in Node.js
|
|
112
|
+
* - MemoryStorage as fallback
|
|
113
|
+
*
|
|
70
114
|
* @param {string} namespace - Storage namespace
|
|
71
|
-
* @param {Object} options - Storage options
|
|
72
|
-
* @
|
|
115
|
+
* @param {Object} [options={}] - Storage options
|
|
116
|
+
* @param {string} [options.dataDir] - Custom data directory (Node.js only)
|
|
117
|
+
* @returns {Promise<PersistentStorage>} Initialized storage instance
|
|
118
|
+
* @example
|
|
119
|
+
* const storage = await createPersistentStorage('myapp');
|
|
120
|
+
* await storage.put('key1', { id: 'event1', data: 'test' });
|
|
73
121
|
*/
|
|
74
122
|
async function createPersistentStorage(namespace, options = {}) {
|
|
75
123
|
// Detect environment
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SyncService - Background service for reliable sync
|
|
2
|
+
* @fileoverview SyncService - Background service for reliable sync.
|
|
3
3
|
*
|
|
4
4
|
* Periodically processes the outbox queue to retry failed deliveries
|
|
5
5
|
* and purge old failed events.
|
|
6
|
+
*
|
|
7
|
+
* @module storage/sync-service
|
|
6
8
|
*/
|
|
7
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Background service for reliable event synchronization.
|
|
12
|
+
*
|
|
13
|
+
* Runs on a periodic interval to:
|
|
14
|
+
* - Retry pending events in the outbox queue
|
|
15
|
+
* - Purge old failed events (24 hour TTL)
|
|
16
|
+
* - Provide sync statistics
|
|
17
|
+
*
|
|
18
|
+
* @class SyncService
|
|
19
|
+
* @example
|
|
20
|
+
* const sync = new SyncService(client, { interval: 10000, autoStart: true });
|
|
21
|
+
* const stats = await sync.getStats();
|
|
22
|
+
* console.log('Pending events:', stats.queue.pending);
|
|
23
|
+
*/
|
|
8
24
|
export class SyncService {
|
|
9
25
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
26
|
+
* Create a new SyncService.
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} client - NostrClient instance with outboxQueue
|
|
29
|
+
* @param {Object} [options={}] - Configuration options
|
|
30
|
+
* @param {number} [options.interval=10000] - Sync interval in ms (10 seconds)
|
|
31
|
+
* @param {boolean} [options.autoStart=false] - Start automatically
|
|
14
32
|
*/
|
|
15
33
|
constructor(client, options = {}) {
|
|
16
34
|
this.client = client;
|
|
@@ -25,7 +43,9 @@ export class SyncService {
|
|
|
25
43
|
}
|
|
26
44
|
|
|
27
45
|
/**
|
|
28
|
-
* Start the background sync service
|
|
46
|
+
* Start the background sync service.
|
|
47
|
+
*
|
|
48
|
+
* @returns {void}
|
|
29
49
|
*/
|
|
30
50
|
start() {
|
|
31
51
|
if (this.running) return;
|
|
@@ -34,7 +54,9 @@ export class SyncService {
|
|
|
34
54
|
}
|
|
35
55
|
|
|
36
56
|
/**
|
|
37
|
-
* Stop the background sync service
|
|
57
|
+
* Stop the background sync service.
|
|
58
|
+
*
|
|
59
|
+
* @returns {void}
|
|
38
60
|
*/
|
|
39
61
|
stop() {
|
|
40
62
|
this.running = false;
|
|
@@ -45,24 +67,30 @@ export class SyncService {
|
|
|
45
67
|
}
|
|
46
68
|
|
|
47
69
|
/**
|
|
48
|
-
* Check if the service is running
|
|
49
|
-
*
|
|
70
|
+
* Check if the service is running.
|
|
71
|
+
*
|
|
72
|
+
* @returns {boolean} True if service is running
|
|
50
73
|
*/
|
|
51
74
|
isRunning() {
|
|
52
75
|
return this.running;
|
|
53
76
|
}
|
|
54
77
|
|
|
55
78
|
/**
|
|
56
|
-
* Force an immediate sync
|
|
57
|
-
*
|
|
79
|
+
* Force an immediate sync.
|
|
80
|
+
*
|
|
81
|
+
* Useful for testing or manual trigger.
|
|
82
|
+
*
|
|
83
|
+
* @returns {Promise<Object>} Sync result with processed, succeeded, failed, purged counts
|
|
58
84
|
*/
|
|
59
85
|
async syncNow() {
|
|
60
86
|
return this._processOutbox();
|
|
61
87
|
}
|
|
62
88
|
|
|
63
89
|
/**
|
|
64
|
-
* Schedule the next run
|
|
90
|
+
* Schedule the next run.
|
|
91
|
+
*
|
|
65
92
|
* @private
|
|
93
|
+
* @returns {void}
|
|
66
94
|
*/
|
|
67
95
|
_scheduleNextRun() {
|
|
68
96
|
if (!this.running) return;
|
|
@@ -73,8 +101,10 @@ export class SyncService {
|
|
|
73
101
|
}
|
|
74
102
|
|
|
75
103
|
/**
|
|
76
|
-
* Main loop iteration
|
|
104
|
+
* Main loop iteration.
|
|
105
|
+
*
|
|
77
106
|
* @private
|
|
107
|
+
* @returns {Promise<void>}
|
|
78
108
|
*/
|
|
79
109
|
async _runLoop() {
|
|
80
110
|
if (!this.running) return;
|
|
@@ -90,9 +120,12 @@ export class SyncService {
|
|
|
90
120
|
}
|
|
91
121
|
|
|
92
122
|
/**
|
|
93
|
-
* Process pending events in the outbox
|
|
123
|
+
* Process pending events in the outbox.
|
|
124
|
+
*
|
|
125
|
+
* Retries pending events and purges old failed events.
|
|
126
|
+
*
|
|
94
127
|
* @private
|
|
95
|
-
* @returns {Promise<Object>} Processing result
|
|
128
|
+
* @returns {Promise<Object>} Processing result with counts
|
|
96
129
|
*/
|
|
97
130
|
async _processOutbox() {
|
|
98
131
|
// Prevent concurrent processing
|
|
@@ -145,8 +178,9 @@ export class SyncService {
|
|
|
145
178
|
}
|
|
146
179
|
|
|
147
180
|
/**
|
|
148
|
-
* Get sync service statistics
|
|
149
|
-
*
|
|
181
|
+
* Get sync service statistics.
|
|
182
|
+
*
|
|
183
|
+
* @returns {Promise<Object>} Stats including running status, interval, and queue status
|
|
150
184
|
*/
|
|
151
185
|
async getStats() {
|
|
152
186
|
const stats = {
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Unified Storage Adapter.
|
|
3
|
+
*
|
|
4
|
+
* Routes storage operations to the correct backend (Nostr or GunDB).
|
|
5
|
+
* Provides a consistent API for reading, writing, updating, and deleting
|
|
6
|
+
* data across different storage backends.
|
|
7
|
+
*
|
|
8
|
+
* @module storage/unified-storage
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as nostrWrapper from './nostr-wrapper.js';
|
|
12
|
+
import * as gunWrapper from './gun-wrapper.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Build path from components
|
|
16
|
+
* @param {string} appName - Application namespace
|
|
17
|
+
* @param {string} holonId - Holon identifier
|
|
18
|
+
* @param {string} lensName - Lens name
|
|
19
|
+
* @param {string} [key] - Optional data key
|
|
20
|
+
* @returns {string} Constructed path
|
|
21
|
+
*/
|
|
22
|
+
export function buildPath(appName, holonId, lensName, key = null) {
|
|
23
|
+
// Both backends use the same path format
|
|
24
|
+
return nostrWrapper.buildPath(appName, holonId, lensName, key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Write data to storage
|
|
29
|
+
* @param {Object} client - Client instance (nostr client or gun-compatible client)
|
|
30
|
+
* @param {string} path - Storage path
|
|
31
|
+
* @param {Object} data - Data to write
|
|
32
|
+
* @returns {Promise<boolean>} Success indicator
|
|
33
|
+
*/
|
|
34
|
+
export async function write(client, path, data) {
|
|
35
|
+
// Check if this is a GunDB client with backend methods (preferred - has write cache)
|
|
36
|
+
if (client.write && client.gun) {
|
|
37
|
+
return client.write(path, data);
|
|
38
|
+
}
|
|
39
|
+
// Fallback to direct gunWrapper (no write cache)
|
|
40
|
+
if (client.gun) {
|
|
41
|
+
return gunWrapper.write(client.gun, path, data);
|
|
42
|
+
}
|
|
43
|
+
// Default to Nostr
|
|
44
|
+
return nostrWrapper.write(client, path, data);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Read data from storage
|
|
49
|
+
* @param {Object} client - Client instance
|
|
50
|
+
* @param {string} path - Storage path
|
|
51
|
+
* @param {Object} [options] - Read options
|
|
52
|
+
* @returns {Promise<Object|null>} Data or null
|
|
53
|
+
*/
|
|
54
|
+
export async function read(client, path, options = {}) {
|
|
55
|
+
// Check if this is a GunDB client with backend methods (preferred - has write cache)
|
|
56
|
+
if (client.read && client.gun) {
|
|
57
|
+
return client.read(path, options);
|
|
58
|
+
}
|
|
59
|
+
// Fallback to direct gunWrapper
|
|
60
|
+
if (client.gun) {
|
|
61
|
+
return gunWrapper.read(client.gun, path);
|
|
62
|
+
}
|
|
63
|
+
return nostrWrapper.read(client, path, options);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Read all data under a path prefix
|
|
68
|
+
* @param {Object} client - Client instance
|
|
69
|
+
* @param {string} path - Path prefix
|
|
70
|
+
* @param {Object} [options] - Query options
|
|
71
|
+
* @returns {Promise<Object[]>} Array of data objects
|
|
72
|
+
*/
|
|
73
|
+
export async function readAll(client, path, options = {}) {
|
|
74
|
+
// Check if this is a GunDB client with backend methods (preferred - has write cache)
|
|
75
|
+
if (client.readAll && client.gun) {
|
|
76
|
+
return client.readAll(path, options);
|
|
77
|
+
}
|
|
78
|
+
// Fallback to direct gunWrapper
|
|
79
|
+
if (client.gun) {
|
|
80
|
+
return gunWrapper.readAll(client.gun, path);
|
|
81
|
+
}
|
|
82
|
+
return nostrWrapper.readAll(client, path, options);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Update data (merge fields)
|
|
87
|
+
* @param {Object} client - Client instance
|
|
88
|
+
* @param {string} path - Storage path
|
|
89
|
+
* @param {Object} updates - Fields to update
|
|
90
|
+
* @returns {Promise<boolean>} Success indicator
|
|
91
|
+
*/
|
|
92
|
+
export async function update(client, path, updates) {
|
|
93
|
+
// Check if this is a GunDB client with backend methods (preferred - has write cache)
|
|
94
|
+
if (client.update && client.gun) {
|
|
95
|
+
return client.update(path, updates);
|
|
96
|
+
}
|
|
97
|
+
// Fallback to direct gunWrapper
|
|
98
|
+
if (client.gun) {
|
|
99
|
+
return gunWrapper.update(client.gun, path, updates);
|
|
100
|
+
}
|
|
101
|
+
return nostrWrapper.update(client, path, updates);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Delete data at path
|
|
106
|
+
* @param {Object} client - Client instance
|
|
107
|
+
* @param {string} path - Storage path
|
|
108
|
+
* @returns {Promise<boolean>} Success indicator
|
|
109
|
+
*/
|
|
110
|
+
export async function deleteData(client, path) {
|
|
111
|
+
// Check if this is a GunDB client with backend methods (preferred - has write cache)
|
|
112
|
+
if (client.delete && client.gun) {
|
|
113
|
+
return client.delete(path);
|
|
114
|
+
}
|
|
115
|
+
// Fallback to direct gunWrapper
|
|
116
|
+
if (client.gun) {
|
|
117
|
+
return gunWrapper.deleteData(client.gun, path);
|
|
118
|
+
}
|
|
119
|
+
return nostrWrapper.deleteData(client, path);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Delete all data under path prefix
|
|
124
|
+
* @param {Object} client - Client instance
|
|
125
|
+
* @param {string} path - Path prefix
|
|
126
|
+
* @returns {Promise<Object>} Deletion results
|
|
127
|
+
*/
|
|
128
|
+
export async function deleteAll(client, path) {
|
|
129
|
+
// Fallback to direct gunWrapper (deleteAll not typically in client interface)
|
|
130
|
+
if (client.gun) {
|
|
131
|
+
return gunWrapper.deleteAll(client.gun, path);
|
|
132
|
+
}
|
|
133
|
+
return nostrWrapper.deleteAll(client, path);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Subscribe to data changes
|
|
138
|
+
* @param {Object} client - Client instance
|
|
139
|
+
* @param {string} path - Path or path prefix
|
|
140
|
+
* @param {Function} callback - Called on changes
|
|
141
|
+
* @param {Object} [options] - Subscription options
|
|
142
|
+
* @returns {Object} Subscription with unsubscribe method
|
|
143
|
+
*/
|
|
144
|
+
export function subscribe(client, path, callback, options = {}) {
|
|
145
|
+
// Check if this is a GunDB client with backend methods
|
|
146
|
+
if (client.subscribe && client.gun) {
|
|
147
|
+
return client.subscribe(path, callback, options);
|
|
148
|
+
}
|
|
149
|
+
// Fallback to direct gunWrapper
|
|
150
|
+
if (client.gun) {
|
|
151
|
+
return gunWrapper.subscribe(client.gun, path, callback, options);
|
|
152
|
+
}
|
|
153
|
+
return nostrWrapper.subscribe(client, path, callback, options);
|
|
154
|
+
}
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Real-time
|
|
2
|
+
* @fileoverview Real-time subscription management with throttling, filtering, and hologram resolution.
|
|
3
|
+
* Provides subscription utilities for real-time data updates from the unified storage layer.
|
|
4
|
+
* @module subscriptions/manager
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
|
-
import { subscribe } from '../storage/
|
|
7
|
+
import { subscribe } from '../storage/unified-storage.js';
|
|
6
8
|
import { resolveHologram } from '../federation/hologram.js';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
|
-
* Create subscription with throttle and filter
|
|
11
|
+
* Create subscription with throttle and filter support.
|
|
12
|
+
* Manages real-time data updates with deduplication, hologram resolution, and filtering capabilities.
|
|
10
13
|
* @param {Object} client - Nostr client instance
|
|
11
|
-
* @param {string} path - Path to subscribe to
|
|
12
|
-
* @param {Function} callback - Callback function
|
|
13
|
-
* @param {Object} options - Subscription options
|
|
14
|
-
* @param {number} options.throttle - Throttle interval in
|
|
15
|
-
* @param {Function} options.filter - Filter predicate
|
|
16
|
-
* @param {boolean} options.includeFederated - Include federated data
|
|
17
|
-
* @param {boolean} options.triggerInitial - Trigger callback with initial data
|
|
18
|
-
* @param {boolean} options.
|
|
19
|
-
* @
|
|
14
|
+
* @param {string} path - Path to subscribe to (app/holon/lens/data)
|
|
15
|
+
* @param {Function} callback - Callback function invoked with (data, key)
|
|
16
|
+
* @param {Object} [options={}] - Subscription options
|
|
17
|
+
* @param {number} [options.throttle=0] - Throttle interval in milliseconds
|
|
18
|
+
* @param {Function} [options.filter=null] - Filter predicate function (data, key) => boolean
|
|
19
|
+
* @param {boolean} [options.includeFederated=false] - Include federated data
|
|
20
|
+
* @param {boolean} [options.triggerInitial=false] - Trigger callback with initial data
|
|
21
|
+
* @param {boolean} [options.realtimeOnly=true] - Only subscribe to new events
|
|
22
|
+
* @param {boolean} [options.resolveHolograms=true] - Resolve holograms before callback
|
|
23
|
+
* @returns {Promise<Object>} Subscription object with path and unsubscribe method
|
|
20
24
|
*/
|
|
21
25
|
export async function createSubscription(client, path, callback, options = {}) {
|
|
22
26
|
const { throttle = 0, filter = null, includeFederated = false, triggerInitial = false, realtimeOnly = true, resolveHolograms = true } = options;
|
|
@@ -98,22 +102,34 @@ export async function createSubscription(client, path, callback, options = {}) {
|
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
/**
|
|
101
|
-
*
|
|
105
|
+
* Registry for tracking and managing multiple active subscriptions.
|
|
106
|
+
* Provides centralized subscription lifecycle management with batch operations.
|
|
102
107
|
*/
|
|
103
108
|
export class SubscriptionRegistry {
|
|
109
|
+
/**
|
|
110
|
+
* Create a new subscription registry.
|
|
111
|
+
*/
|
|
104
112
|
constructor() {
|
|
113
|
+
/**
|
|
114
|
+
* Map of subscription ID to subscription object
|
|
115
|
+
* @type {Map<string, Object>}
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
105
118
|
this.subscriptions = new Map();
|
|
106
119
|
}
|
|
107
120
|
|
|
108
121
|
/**
|
|
109
|
-
* Register a subscription
|
|
122
|
+
* Register a subscription by ID.
|
|
123
|
+
* @param {string} id - Unique subscription identifier
|
|
124
|
+
* @param {Object} subscription - Subscription object with unsubscribe method
|
|
110
125
|
*/
|
|
111
126
|
register(id, subscription) {
|
|
112
127
|
this.subscriptions.set(id, subscription);
|
|
113
128
|
}
|
|
114
129
|
|
|
115
130
|
/**
|
|
116
|
-
* Unregister a subscription
|
|
131
|
+
* Unregister and unsubscribe a subscription by ID.
|
|
132
|
+
* @param {string} id - Subscription identifier to remove
|
|
117
133
|
*/
|
|
118
134
|
unregister(id) {
|
|
119
135
|
const subscription = this.subscriptions.get(id);
|
|
@@ -124,7 +140,7 @@ export class SubscriptionRegistry {
|
|
|
124
140
|
}
|
|
125
141
|
|
|
126
142
|
/**
|
|
127
|
-
* Unsubscribe all
|
|
143
|
+
* Unsubscribe all registered subscriptions and clear the registry.
|
|
128
144
|
*/
|
|
129
145
|
unsubscribeAll() {
|
|
130
146
|
for (const [id, subscription] of this.subscriptions) {
|
|
@@ -134,7 +150,8 @@ export class SubscriptionRegistry {
|
|
|
134
150
|
}
|
|
135
151
|
|
|
136
152
|
/**
|
|
137
|
-
* Get active
|
|
153
|
+
* Get the count of active subscriptions.
|
|
154
|
+
* @returns {number} Number of active subscriptions
|
|
138
155
|
*/
|
|
139
156
|
count() {
|
|
140
157
|
return this.subscriptions.size;
|