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
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* GunDB Federation Module
|
|
3
|
-
* Provides methods for creating, managing, and using federated spaces
|
|
2
|
+
* @fileoverview GunDB Federation Module.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
4
|
+
* Provides methods for creating, managing, and using federated spaces.
|
|
5
|
+
* Supports data propagation with references for lightweight federation,
|
|
6
|
+
* aggregation across federated sources, and subscription to federated changes.
|
|
7
|
+
*
|
|
8
|
+
* Ported from holosphere/federation.js to work with the GunDBBackend.
|
|
9
|
+
*
|
|
10
|
+
* @module storage/gun-federation
|
|
6
11
|
*/
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
|
-
* Creates a federation relationship between two spaces
|
|
14
|
+
* Creates a federation relationship between two spaces.
|
|
15
|
+
*
|
|
10
16
|
* Federation is bidirectional by default, and data propagation uses soul references by default.
|
|
11
17
|
*
|
|
12
18
|
* @param {Object} backend - The GunDBBackend instance
|
|
13
19
|
* @param {string} spaceId1 - The first space ID
|
|
14
20
|
* @param {string} spaceId2 - The second space ID
|
|
15
|
-
* @param {boolean} bidirectional - Whether to set up bidirectional notifications
|
|
21
|
+
* @param {boolean} [bidirectional=true] - Whether to set up bidirectional notifications
|
|
16
22
|
* @returns {Promise<boolean>} True if federation was created successfully
|
|
23
|
+
* @throws {Error} If space IDs are missing or identical
|
|
24
|
+
* @example
|
|
25
|
+
* await federate(backend, 'space1', 'space2');
|
|
17
26
|
*/
|
|
18
27
|
export async function federate(backend, spaceId1, spaceId2, bidirectional = true) {
|
|
19
28
|
if (!spaceId1 || !spaceId2) {
|
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* GunDB Reference Handler
|
|
3
|
-
* Handles creation and resolution of data references for federation
|
|
2
|
+
* @fileoverview GunDB Reference Handler.
|
|
4
3
|
*
|
|
4
|
+
* Handles creation and resolution of data references for federation.
|
|
5
5
|
* References use a "soul" pattern: appname/holon/lens/key
|
|
6
|
-
* This allows lightweight propagation without data duplication
|
|
6
|
+
* This allows lightweight propagation without data duplication.
|
|
7
|
+
*
|
|
8
|
+
* @module storage/gun-references
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
11
|
import { read } from './gun-wrapper.js';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
* Reference handler for GunDB backend
|
|
14
|
+
* Reference handler for GunDB backend.
|
|
15
|
+
*
|
|
16
|
+
* Manages creation, detection, and resolution of data references.
|
|
17
|
+
*
|
|
18
|
+
* @class GunReferenceHandler
|
|
19
|
+
* @example
|
|
20
|
+
* const handler = new GunReferenceHandler('myapp');
|
|
21
|
+
* const ref = handler.createReference('holon1', 'items', { id: '123', name: 'Test' });
|
|
22
|
+
* const resolved = await handler.resolveReference(gun, ref);
|
|
13
23
|
*/
|
|
14
24
|
export class GunReferenceHandler {
|
|
15
25
|
/**
|
|
16
|
-
* Create a new reference handler
|
|
26
|
+
* Create a new reference handler.
|
|
27
|
+
*
|
|
17
28
|
* @param {string} appname - Application namespace
|
|
18
29
|
*/
|
|
19
30
|
constructor(appname) {
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* GunDB Schema Validator
|
|
3
|
-
* Handles JSON Schema validation for data stored in GunDB
|
|
2
|
+
* @fileoverview GunDB Schema Validator.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Handles JSON Schema validation for data stored in GunDB.
|
|
5
|
+
* Schemas are stored in the global 'schemas' table.
|
|
6
|
+
* Validation uses AJV (Another JSON Schema Validator) with JSON Schema 2019.
|
|
7
|
+
*
|
|
8
|
+
* @module storage/gun-schema
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
11
|
import { writeGlobal, readGlobal, readAllGlobal, deleteGlobal } from './gun-wrapper.js';
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Default meta-schema for validating schema definitions.
|
|
15
|
+
* @private
|
|
16
|
+
* @constant {Object}
|
|
17
|
+
*/
|
|
12
18
|
const META_SCHEMA = {
|
|
13
19
|
type: 'object',
|
|
14
20
|
required: ['type'],
|
|
@@ -23,14 +29,23 @@ const META_SCHEMA = {
|
|
|
23
29
|
};
|
|
24
30
|
|
|
25
31
|
/**
|
|
26
|
-
* Schema validator for GunDB backend
|
|
32
|
+
* Schema validator for GunDB backend.
|
|
33
|
+
*
|
|
34
|
+
* Provides JSON Schema validation with caching and lazy-loaded AJV.
|
|
35
|
+
*
|
|
36
|
+
* @class GunSchemaValidator
|
|
37
|
+
* @example
|
|
38
|
+
* const validator = new GunSchemaValidator({ strict: true });
|
|
39
|
+
* await validator.init();
|
|
40
|
+
* await validator.setSchema(gun, 'myapp', 'user', { type: 'object', properties: { name: { type: 'string' } } });
|
|
27
41
|
*/
|
|
28
42
|
export class GunSchemaValidator {
|
|
29
43
|
/**
|
|
30
|
-
* Create a new schema validator
|
|
31
|
-
*
|
|
32
|
-
* @param {
|
|
33
|
-
* @param {
|
|
44
|
+
* Create a new schema validator.
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} [options={}] - Validator options
|
|
47
|
+
* @param {boolean} [options.strict=false] - Whether to enforce strict validation
|
|
48
|
+
* @param {number} [options.cacheMaxAge=3600000] - Schema cache TTL in ms (1 hour)
|
|
34
49
|
*/
|
|
35
50
|
constructor(options = {}) {
|
|
36
51
|
this.strict = options.strict || false;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* GunDB Storage Wrapper with radisk persistence
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* @fileoverview GunDB Storage Wrapper with radisk persistence.
|
|
3
|
+
*
|
|
4
|
+
* Handles path construction and CRUD operations for GunDB storage backend.
|
|
5
|
+
* Note: GunDB doesn't handle nested objects well, so we store data as JSON strings.
|
|
6
|
+
* Provides both holon-specific paths and global table operations.
|
|
7
|
+
*
|
|
8
|
+
* @module storage/gun-wrapper
|
|
5
9
|
*/
|
|
6
10
|
|
|
7
11
|
import { gunPromise, gunPut, gunCollect } from './gun-async.js';
|
|
@@ -11,12 +15,16 @@ import { gunPromise, gunPut, gunCollect } from './gun-async.js';
|
|
|
11
15
|
// ============================================================================
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
|
-
* Build Gun path from components
|
|
18
|
+
* Build Gun path from components.
|
|
19
|
+
*
|
|
15
20
|
* @param {string} appname - Application namespace
|
|
16
21
|
* @param {string} holon - Holon ID (H3 or URI)
|
|
17
22
|
* @param {string} lens - Lens name
|
|
18
|
-
* @param {string} key - Data key (optional)
|
|
23
|
+
* @param {string} [key=null] - Data key (optional)
|
|
19
24
|
* @returns {string} Gun path
|
|
25
|
+
* @example
|
|
26
|
+
* const path = buildPath('myapp', 'holon123', 'items', 'item1');
|
|
27
|
+
* // Returns: 'myapp/holon123/items/item1'
|
|
20
28
|
*/
|
|
21
29
|
export function buildPath(appname, holon, lens, key = null) {
|
|
22
30
|
// Encode components to handle special characters
|
|
@@ -31,11 +39,15 @@ export function buildPath(appname, holon, lens, key = null) {
|
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
/**
|
|
34
|
-
* Build Gun path for global tables (app-wide data not tied to holons)
|
|
42
|
+
* Build Gun path for global tables (app-wide data not tied to holons).
|
|
43
|
+
*
|
|
35
44
|
* @param {string} appname - Application namespace
|
|
36
45
|
* @param {string} tableName - Global table name (e.g., 'schemas', 'federation')
|
|
37
|
-
* @param {string} key - Data key (optional)
|
|
46
|
+
* @param {string} [key=null] - Data key (optional)
|
|
38
47
|
* @returns {string} Gun path
|
|
48
|
+
* @example
|
|
49
|
+
* const path = buildGlobalPath('myapp', 'schemas', 'user');
|
|
50
|
+
* // Returns: 'myapp/schemas/user'
|
|
39
51
|
*/
|
|
40
52
|
export function buildGlobalPath(appname, tableName, key = null) {
|
|
41
53
|
const encodedTable = encodePathComponent(tableName);
|
|
@@ -47,17 +59,22 @@ export function buildGlobalPath(appname, tableName, key = null) {
|
|
|
47
59
|
}
|
|
48
60
|
|
|
49
61
|
/**
|
|
50
|
-
* Encode path component to handle special characters
|
|
62
|
+
* Encode path component to handle special characters.
|
|
63
|
+
*
|
|
51
64
|
* @private
|
|
65
|
+
* @param {string} component - Component to encode
|
|
66
|
+
* @returns {string} Encoded component
|
|
52
67
|
*/
|
|
53
68
|
function encodePathComponent(component) {
|
|
54
69
|
return encodeURIComponent(component).replace(/%2F/g, '/');
|
|
55
70
|
}
|
|
56
71
|
|
|
57
72
|
/**
|
|
58
|
-
* Navigate to a Gun path using chained .get() calls
|
|
73
|
+
* Navigate to a Gun path using chained .get() calls.
|
|
74
|
+
*
|
|
59
75
|
* Gun treats 'a/b/c' as a literal key, not a path.
|
|
60
76
|
* This function splits the path and chains .get() calls properly.
|
|
77
|
+
*
|
|
61
78
|
* @private
|
|
62
79
|
* @param {Object} gun - Gun instance
|
|
63
80
|
* @param {string} path - Path string like "appname/holon/lens/key"
|
|
@@ -73,24 +90,32 @@ function getGunPath(gun, path) {
|
|
|
73
90
|
}
|
|
74
91
|
|
|
75
92
|
/**
|
|
76
|
-
* Serialize data for GunDB storage
|
|
77
|
-
*
|
|
78
|
-
*
|
|
93
|
+
* Serialize data for GunDB storage.
|
|
94
|
+
*
|
|
95
|
+
* Stores data as raw JSON string for compatibility with holosphere original.
|
|
96
|
+
* This matches the format used in holosphere v1 for better interoperability.
|
|
97
|
+
*
|
|
79
98
|
* @private
|
|
99
|
+
* @param {Object} data - Data to serialize
|
|
100
|
+
* @returns {string} JSON string
|
|
80
101
|
*/
|
|
81
102
|
function serializeForGun(data) {
|
|
82
103
|
return JSON.stringify(data);
|
|
83
104
|
}
|
|
84
105
|
|
|
85
106
|
/**
|
|
86
|
-
* Deserialize data from GunDB storage
|
|
107
|
+
* Deserialize data from GunDB storage.
|
|
108
|
+
*
|
|
87
109
|
* Handles multiple formats:
|
|
88
110
|
* - Direct JSON string (holosphere original - now default)
|
|
89
111
|
* - _json wrapped format (holosphere2 legacy)
|
|
90
112
|
* - Gun internal references (_["#"])
|
|
91
113
|
* - Gun node data (_[">"])
|
|
92
114
|
* - Plain objects
|
|
115
|
+
*
|
|
93
116
|
* @private
|
|
117
|
+
* @param {*} data - Raw data from Gun
|
|
118
|
+
* @returns {Object|null} Parsed data or null
|
|
94
119
|
*/
|
|
95
120
|
function deserializeFromGun(data) {
|
|
96
121
|
if (!data) {
|
|
@@ -160,11 +185,15 @@ function deserializeFromGun(data) {
|
|
|
160
185
|
}
|
|
161
186
|
|
|
162
187
|
/**
|
|
163
|
-
* Write data to Gun with radisk persistence
|
|
188
|
+
* Write data to Gun with radisk persistence.
|
|
189
|
+
*
|
|
164
190
|
* @param {Object} gun - Gun instance
|
|
165
191
|
* @param {string} path - Gun path
|
|
166
192
|
* @param {Object} data - Data to write
|
|
167
|
-
* @returns {Promise<
|
|
193
|
+
* @returns {Promise<Object>} Success object with ok and timeout flags
|
|
194
|
+
* @example
|
|
195
|
+
* const result = await write(gun, 'myapp/holon1/items/item1', { name: 'Test' });
|
|
196
|
+
* if (result.timeout) console.warn('Write may not be persisted');
|
|
168
197
|
*/
|
|
169
198
|
export async function write(gun, path, data) {
|
|
170
199
|
try {
|
|
@@ -189,10 +218,14 @@ export async function write(gun, path, data) {
|
|
|
189
218
|
}
|
|
190
219
|
|
|
191
220
|
/**
|
|
192
|
-
* Read data from Gun
|
|
221
|
+
* Read data from Gun.
|
|
222
|
+
*
|
|
193
223
|
* @param {Object} gun - Gun instance
|
|
194
224
|
* @param {string} path - Gun path
|
|
195
|
-
* @returns {Promise<Object|null>} Data or null if not found
|
|
225
|
+
* @returns {Promise<Object|null>} Data or null if not found or deleted
|
|
226
|
+
* @example
|
|
227
|
+
* const data = await read(gun, 'myapp/holon1/items/item1');
|
|
228
|
+
* if (data) console.log(data.name);
|
|
196
229
|
*/
|
|
197
230
|
export async function read(gun, path) {
|
|
198
231
|
const parts = path.split('/').filter(p => p.length > 0);
|
|
@@ -217,12 +250,17 @@ export async function read(gun, path) {
|
|
|
217
250
|
}
|
|
218
251
|
|
|
219
252
|
/**
|
|
220
|
-
* Read all data under a path (lens query)
|
|
221
|
-
*
|
|
253
|
+
* Read all data under a path (lens query).
|
|
254
|
+
*
|
|
255
|
+
* First gets the count of expected items, then collects until count is reached.
|
|
256
|
+
*
|
|
222
257
|
* @param {Object} gun - Gun instance
|
|
223
258
|
* @param {string} path - Gun path
|
|
224
|
-
* @param {number} timeout - Maximum timeout in ms
|
|
259
|
+
* @param {number} [timeout=5000] - Maximum timeout in ms
|
|
225
260
|
* @returns {Promise<Object[]>} Array of data objects
|
|
261
|
+
* @example
|
|
262
|
+
* const items = await readAll(gun, 'myapp/holon1/items');
|
|
263
|
+
* console.log(`Found ${items.length} items`);
|
|
226
264
|
*/
|
|
227
265
|
export async function readAll(gun, path, timeout = 5000) {
|
|
228
266
|
const parts = path.split('/').filter(p => p.length > 0);
|
|
@@ -334,11 +372,14 @@ export async function readAll(gun, path, timeout = 5000) {
|
|
|
334
372
|
}
|
|
335
373
|
|
|
336
374
|
/**
|
|
337
|
-
* Update data (merge fields)
|
|
375
|
+
* Update data (merge fields).
|
|
376
|
+
*
|
|
338
377
|
* @param {Object} gun - Gun instance
|
|
339
378
|
* @param {string} path - Gun path
|
|
340
379
|
* @param {Object} updates - Fields to update
|
|
341
380
|
* @returns {Promise<boolean>} Success indicator
|
|
381
|
+
* @example
|
|
382
|
+
* const success = await update(gun, 'myapp/holon1/items/item1', { status: 'active' });
|
|
342
383
|
*/
|
|
343
384
|
export async function update(gun, path, updates) {
|
|
344
385
|
const rawData = await gunPromise(getGunPath(gun, path));
|
|
@@ -368,10 +409,13 @@ export async function update(gun, path, updates) {
|
|
|
368
409
|
}
|
|
369
410
|
|
|
370
411
|
/**
|
|
371
|
-
* Delete data (tombstone)
|
|
412
|
+
* Delete data (tombstone).
|
|
413
|
+
*
|
|
372
414
|
* @param {Object} gun - Gun instance
|
|
373
415
|
* @param {string} path - Gun path
|
|
374
416
|
* @returns {Promise<boolean>} Success indicator
|
|
417
|
+
* @example
|
|
418
|
+
* const deleted = await deleteData(gun, 'myapp/holon1/items/item1');
|
|
375
419
|
*/
|
|
376
420
|
export async function deleteData(gun, path) {
|
|
377
421
|
try {
|
|
@@ -400,7 +444,8 @@ export async function deleteData(gun, path) {
|
|
|
400
444
|
}
|
|
401
445
|
|
|
402
446
|
/**
|
|
403
|
-
* Delete all data under path prefix (tombstone)
|
|
447
|
+
* Delete all data under path prefix (tombstone).
|
|
448
|
+
*
|
|
404
449
|
* @param {Object} gun - Gun instance
|
|
405
450
|
* @param {string} path - Gun path prefix
|
|
406
451
|
* @returns {Promise<Object>} Deletion results { success: boolean, count: number }
|
|
@@ -421,13 +466,19 @@ export async function deleteAll(gun, path) {
|
|
|
421
466
|
}
|
|
422
467
|
|
|
423
468
|
/**
|
|
424
|
-
* Subscribe to data changes
|
|
469
|
+
* Subscribe to data changes.
|
|
470
|
+
*
|
|
425
471
|
* @param {Object} gun - Gun instance
|
|
426
472
|
* @param {string} path - Gun path
|
|
427
|
-
* @param {Function} callback - Called on data changes
|
|
428
|
-
* @param {Object} options - Subscription options
|
|
429
|
-
* @param {boolean} options.prefix - Subscribe to all items under path (default: auto-detect)
|
|
473
|
+
* @param {Function} callback - Called on data changes (data, key) => void
|
|
474
|
+
* @param {Object} [options={}] - Subscription options
|
|
475
|
+
* @param {boolean} [options.prefix] - Subscribe to all items under path (default: auto-detect)
|
|
430
476
|
* @returns {Object} Subscription object with unsubscribe method
|
|
477
|
+
* @example
|
|
478
|
+
* const sub = subscribe(gun, 'myapp/holon1/items', (data, key) => {
|
|
479
|
+
* console.log('Item changed:', key, data);
|
|
480
|
+
* });
|
|
481
|
+
* // Later: sub.unsubscribe();
|
|
431
482
|
*/
|
|
432
483
|
export function subscribe(gun, path, callback, options = {}) {
|
|
433
484
|
// Detect if this is a prefix subscription
|
|
@@ -484,13 +535,18 @@ export function subscribe(gun, path, callback, options = {}) {
|
|
|
484
535
|
// ============================================================================
|
|
485
536
|
|
|
486
537
|
/**
|
|
487
|
-
* Write data to a global table
|
|
488
|
-
*
|
|
538
|
+
* Write data to a global table.
|
|
539
|
+
*
|
|
540
|
+
* Global tables are app-wide data not tied to specific holons (e.g., schemas, federation).
|
|
541
|
+
*
|
|
489
542
|
* @param {Object} gun - Gun instance
|
|
490
543
|
* @param {string} appname - Application namespace
|
|
491
544
|
* @param {string} tableName - Global table name
|
|
492
545
|
* @param {Object} data - Data to write (must have 'id' field)
|
|
493
|
-
* @returns {Promise<
|
|
546
|
+
* @returns {Promise<Object>} Success object with ok and timeout flags
|
|
547
|
+
* @throws {Error} If data doesn't have an id field
|
|
548
|
+
* @example
|
|
549
|
+
* await writeGlobal(gun, 'myapp', 'schemas', { id: 'user', type: 'object' });
|
|
494
550
|
*/
|
|
495
551
|
export async function writeGlobal(gun, appname, tableName, data) {
|
|
496
552
|
if (!data || !data.id) {
|
|
@@ -502,7 +558,8 @@ export async function writeGlobal(gun, appname, tableName, data) {
|
|
|
502
558
|
}
|
|
503
559
|
|
|
504
560
|
/**
|
|
505
|
-
* Read data from a global table
|
|
561
|
+
* Read data from a global table.
|
|
562
|
+
*
|
|
506
563
|
* @param {Object} gun - Gun instance
|
|
507
564
|
* @param {string} appname - Application namespace
|
|
508
565
|
* @param {string} tableName - Global table name
|
|
@@ -515,12 +572,14 @@ export async function readGlobal(gun, appname, tableName, key) {
|
|
|
515
572
|
}
|
|
516
573
|
|
|
517
574
|
/**
|
|
518
|
-
* Read all data from a global table
|
|
519
|
-
*
|
|
575
|
+
* Read all data from a global table.
|
|
576
|
+
*
|
|
577
|
+
* Uses same approach as readAll.
|
|
578
|
+
*
|
|
520
579
|
* @param {Object} gun - Gun instance
|
|
521
580
|
* @param {string} appname - Application namespace
|
|
522
581
|
* @param {string} tableName - Global table name
|
|
523
|
-
* @param {number} timeout - Timeout in ms
|
|
582
|
+
* @param {number} [timeout=2000] - Timeout in ms
|
|
524
583
|
* @returns {Promise<Object[]>} Array of data objects
|
|
525
584
|
*/
|
|
526
585
|
export async function readAllGlobal(gun, appname, tableName, timeout = 2000) {
|
|
@@ -558,10 +617,13 @@ export async function deleteAllGlobal(gun, appname, tableName) {
|
|
|
558
617
|
// ============================================================================
|
|
559
618
|
|
|
560
619
|
/**
|
|
561
|
-
* Parse data from Gun storage, handling various formats
|
|
620
|
+
* Parse data from Gun storage, handling various formats.
|
|
621
|
+
*
|
|
622
|
+
* Handles:
|
|
562
623
|
* - JSON string in _json field
|
|
563
624
|
* - Legacy object format
|
|
564
625
|
* - Gun references
|
|
626
|
+
*
|
|
565
627
|
* @param {*} rawData - Raw data from Gun
|
|
566
628
|
* @returns {Object|null} Parsed data or null
|
|
567
629
|
*/
|
|
@@ -570,7 +632,8 @@ export function parse(rawData) {
|
|
|
570
632
|
}
|
|
571
633
|
|
|
572
634
|
/**
|
|
573
|
-
* Serialize data for Gun storage
|
|
635
|
+
* Serialize data for Gun storage.
|
|
636
|
+
*
|
|
574
637
|
* @param {Object} data - Data to serialize
|
|
575
638
|
* @returns {string} JSON string
|
|
576
639
|
*/
|
|
@@ -1,20 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* IndexedDB storage adapter for browsers
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview IndexedDB storage adapter for browsers.
|
|
3
|
+
*
|
|
4
|
+
* Provides persistent storage with good performance using browser IndexedDB.
|
|
5
|
+
* Uses B-tree indexes for efficient prefix queries.
|
|
6
|
+
*
|
|
7
|
+
* @module storage/indexeddb-storage
|
|
4
8
|
*/
|
|
5
9
|
|
|
6
10
|
import { PersistentStorage } from './persistent-storage.js';
|
|
7
11
|
|
|
12
|
+
/**
|
|
13
|
+
* IndexedDB storage adapter for browsers.
|
|
14
|
+
*
|
|
15
|
+
* Provides high-performance persistent storage using IndexedDB with efficient prefix queries.
|
|
16
|
+
*
|
|
17
|
+
* @class IndexedDBStorage
|
|
18
|
+
* @extends PersistentStorage
|
|
19
|
+
* @example
|
|
20
|
+
* const storage = new IndexedDBStorage();
|
|
21
|
+
* await storage.init('myapp');
|
|
22
|
+
* await storage.put('key1', { id: 'event1', content: 'test' });
|
|
23
|
+
*/
|
|
8
24
|
export class IndexedDBStorage extends PersistentStorage {
|
|
25
|
+
/**
|
|
26
|
+
* Create a new IndexedDBStorage instance.
|
|
27
|
+
*/
|
|
9
28
|
constructor() {
|
|
10
29
|
super();
|
|
11
30
|
/** @type {IDBDatabase|null} */
|
|
12
31
|
this.db = null;
|
|
13
32
|
/** @type {string} */
|
|
14
33
|
this.dbName = '';
|
|
34
|
+
/** @type {string} */
|
|
15
35
|
this.storeName = 'events';
|
|
16
36
|
}
|
|
17
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Initialize storage with namespace.
|
|
40
|
+
*
|
|
41
|
+
* Creates or opens the IndexedDB database and object store.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} namespace - Storage namespace
|
|
44
|
+
* @returns {Promise<void>}
|
|
45
|
+
*/
|
|
18
46
|
async init(namespace) {
|
|
19
47
|
this.dbName = `holosphere_${namespace}`;
|
|
20
48
|
|
|
@@ -41,6 +69,13 @@ export class IndexedDBStorage extends PersistentStorage {
|
|
|
41
69
|
});
|
|
42
70
|
}
|
|
43
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Store an event.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} key - Storage key
|
|
76
|
+
* @param {Object} event - Event data
|
|
77
|
+
* @returns {Promise<void>}
|
|
78
|
+
*/
|
|
44
79
|
async put(key, event) {
|
|
45
80
|
return new Promise((resolve, reject) => {
|
|
46
81
|
if (!this.db) {
|
|
@@ -57,6 +92,12 @@ export class IndexedDBStorage extends PersistentStorage {
|
|
|
57
92
|
});
|
|
58
93
|
}
|
|
59
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Retrieve an event.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} key - Storage key
|
|
99
|
+
* @returns {Promise<Object|null>} Event data or null
|
|
100
|
+
*/
|
|
60
101
|
async get(key) {
|
|
61
102
|
return new Promise((resolve, reject) => {
|
|
62
103
|
if (!this.db) {
|
|
@@ -77,8 +118,12 @@ export class IndexedDBStorage extends PersistentStorage {
|
|
|
77
118
|
}
|
|
78
119
|
|
|
79
120
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
121
|
+
* Retrieve all events matching a prefix.
|
|
122
|
+
*
|
|
123
|
+
* Uses IDBKeyRange for efficient B-tree index queries.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} prefix - Key prefix to match
|
|
126
|
+
* @returns {Promise<any[]>} Array of matching events
|
|
82
127
|
*/
|
|
83
128
|
async getAll(prefix) {
|
|
84
129
|
return new Promise((resolve, reject) => {
|
|
@@ -119,6 +164,12 @@ export class IndexedDBStorage extends PersistentStorage {
|
|
|
119
164
|
});
|
|
120
165
|
}
|
|
121
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Delete an event.
|
|
169
|
+
*
|
|
170
|
+
* @param {string} key - Storage key
|
|
171
|
+
* @returns {Promise<void>}
|
|
172
|
+
*/
|
|
122
173
|
async delete(key) {
|
|
123
174
|
return new Promise((resolve, reject) => {
|
|
124
175
|
if (!this.db) {
|
|
@@ -135,6 +186,11 @@ export class IndexedDBStorage extends PersistentStorage {
|
|
|
135
186
|
});
|
|
136
187
|
}
|
|
137
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Clear all stored events.
|
|
191
|
+
*
|
|
192
|
+
* @returns {Promise<void>}
|
|
193
|
+
*/
|
|
138
194
|
async clear() {
|
|
139
195
|
return new Promise((resolve, reject) => {
|
|
140
196
|
if (!this.db) {
|
|
@@ -151,6 +207,11 @@ export class IndexedDBStorage extends PersistentStorage {
|
|
|
151
207
|
});
|
|
152
208
|
}
|
|
153
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Close the database connection.
|
|
212
|
+
*
|
|
213
|
+
* @returns {Promise<void>}
|
|
214
|
+
*/
|
|
154
215
|
async close() {
|
|
155
216
|
if (this.db) {
|
|
156
217
|
this.db.close();
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Simple Key Storage for Node.js
|
|
3
|
-
* Basic filesystem-based key management
|
|
2
|
+
* @fileoverview Simple Key Storage for Node.js.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Basic filesystem-based key management.
|
|
5
|
+
* NOTE: This only works in Node.js, not browsers.
|
|
6
|
+
* For browsers, keys are managed in localStorage.
|
|
7
|
+
*
|
|
8
|
+
* @module storage/key-storage-simple
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
11
|
import fs from 'fs';
|
|
@@ -11,7 +13,10 @@ import path from 'path';
|
|
|
11
13
|
import os from 'os';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
|
-
* Get key storage directory
|
|
16
|
+
* Get key storage directory.
|
|
17
|
+
*
|
|
18
|
+
* @private
|
|
19
|
+
* @returns {string} Key storage directory path
|
|
15
20
|
*/
|
|
16
21
|
function getKeyDir() {
|
|
17
22
|
const configDir = process.env.XDG_CONFIG_HOME ||
|
|
@@ -23,7 +28,11 @@ function getKeyDir() {
|
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
/**
|
|
26
|
-
* Get key file path for an app
|
|
31
|
+
* Get key file path for an app.
|
|
32
|
+
*
|
|
33
|
+
* @private
|
|
34
|
+
* @param {string} appName - Application name
|
|
35
|
+
* @returns {string} Full path to key file
|
|
27
36
|
*/
|
|
28
37
|
function getKeyPath(appName) {
|
|
29
38
|
const safeName = appName.replace(/[^a-zA-Z0-9-_]/g, '_');
|
|
@@ -31,7 +40,10 @@ function getKeyPath(appName) {
|
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
/**
|
|
34
|
-
* Load private key
|
|
43
|
+
* Load private key from filesystem.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} appName - Application name
|
|
46
|
+
* @returns {string|null} Private key (hex) or null if not found
|
|
35
47
|
*/
|
|
36
48
|
export function loadKey(appName) {
|
|
37
49
|
const keyPath = getKeyPath(appName);
|
|
@@ -45,7 +57,12 @@ export function loadKey(appName) {
|
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
/**
|
|
48
|
-
* Save private key
|
|
60
|
+
* Save private key to filesystem with secure permissions.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} appName - Application name
|
|
63
|
+
* @param {string} privateKey - Private key (64-character hex string)
|
|
64
|
+
* @returns {string} Path where key was saved
|
|
65
|
+
* @throws {Error} If private key format is invalid
|
|
49
66
|
*/
|
|
50
67
|
export function saveKey(appName, privateKey) {
|
|
51
68
|
if (!/^[0-9a-f]{64}$/i.test(privateKey)) {
|
|
@@ -64,7 +81,13 @@ export function saveKey(appName, privateKey) {
|
|
|
64
81
|
}
|
|
65
82
|
|
|
66
83
|
/**
|
|
67
|
-
* Get or create key
|
|
84
|
+
* Get or create private key.
|
|
85
|
+
*
|
|
86
|
+
* Loads existing key or generates and saves a new one.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} appName - Application name
|
|
89
|
+
* @param {Function} generateFn - Function to generate new key (returns hex string)
|
|
90
|
+
* @returns {string} Private key (hex)
|
|
68
91
|
*/
|
|
69
92
|
export function getOrCreateKey(appName, generateFn) {
|
|
70
93
|
const existing = loadKey(appName);
|