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.
Files changed (418) hide show
  1. package/CHANGELOG.md +473 -0
  2. package/FEATURES.md +431 -0
  3. package/LICENSE +29 -42
  4. package/LICENSE-AGPL.md +180 -0
  5. package/README.md +97 -16
  6. package/dist/2019-D2OG2idw.js +6680 -0
  7. package/dist/2019-D2OG2idw.js.map +1 -0
  8. package/dist/2019-EION3wKo.cjs +8 -0
  9. package/dist/2019-EION3wKo.cjs.map +1 -0
  10. package/dist/_commonjsHelpers-C37NGDzP.cjs +2 -0
  11. package/dist/_commonjsHelpers-C37NGDzP.cjs.map +1 -0
  12. package/dist/_commonjsHelpers-CUmg6egw.js +7 -0
  13. package/dist/_commonjsHelpers-CUmg6egw.js.map +1 -0
  14. package/dist/browser-BSniCNqO.js +3058 -0
  15. package/dist/browser-BSniCNqO.js.map +1 -0
  16. package/dist/browser-Cq59Ij19.cjs +2 -0
  17. package/dist/browser-Cq59Ij19.cjs.map +1 -0
  18. package/dist/cdn/holosphere.min.js +55 -0
  19. package/dist/cdn/holosphere.min.js.map +1 -0
  20. package/dist/cjs/holosphere.cjs +2 -0
  21. package/dist/cjs/holosphere.cjs.map +1 -0
  22. package/dist/esm/holosphere.js +53 -0
  23. package/dist/esm/holosphere.js.map +1 -0
  24. package/dist/index-DDGt_V9o.cjs +12 -0
  25. package/dist/index-DDGt_V9o.cjs.map +1 -0
  26. package/dist/index-DJXftyvB.js +39841 -0
  27. package/dist/index-DJXftyvB.js.map +1 -0
  28. package/dist/index-DMbdcMtK.cjs +18 -0
  29. package/dist/index-DMbdcMtK.cjs.map +1 -0
  30. package/dist/index-DeZ1xz_s.js +15104 -0
  31. package/dist/index-DeZ1xz_s.js.map +1 -0
  32. package/dist/indexeddb-storage-BFt6hMeF.js +176 -0
  33. package/dist/indexeddb-storage-BFt6hMeF.js.map +1 -0
  34. package/dist/indexeddb-storage-BK5tv4Sh.cjs +2 -0
  35. package/dist/indexeddb-storage-BK5tv4Sh.cjs.map +1 -0
  36. package/dist/memory-storage-C9HuoL2E.js +91 -0
  37. package/dist/memory-storage-C9HuoL2E.js.map +1 -0
  38. package/dist/memory-storage-Dao7jfYG.cjs +2 -0
  39. package/dist/memory-storage-Dao7jfYG.cjs.map +1 -0
  40. package/dist/secp256k1-BbKzbLtD.cjs +12 -0
  41. package/dist/secp256k1-BbKzbLtD.cjs.map +1 -0
  42. package/dist/secp256k1-CreY7Pcl.js +1890 -0
  43. package/dist/secp256k1-CreY7Pcl.js.map +1 -0
  44. package/docs/CONTRACTS.md +797 -0
  45. package/docs/FOSDEM_PROPOSAL.md +388 -0
  46. package/docs/LOCALFIRST.md +266 -0
  47. package/docs/api/ai_aggregation.js.html +333 -0
  48. package/docs/api/ai_breakdown.js.html +524 -0
  49. package/docs/api/ai_classifier.js.html +231 -0
  50. package/docs/api/ai_council.js.html +246 -0
  51. package/docs/api/ai_embeddings.js.html +304 -0
  52. package/docs/api/ai_federation-ai.js.html +338 -0
  53. package/docs/api/ai_h3-ai.js.html +970 -0
  54. package/docs/api/ai_index.js.html +124 -0
  55. package/docs/api/ai_json-ops.js.html +241 -0
  56. package/docs/api/ai_llm-service.js.html +239 -0
  57. package/docs/api/ai_nl-query.js.html +236 -0
  58. package/docs/api/ai_relationships.js.html +367 -0
  59. package/docs/api/ai_schema-extractor.js.html +235 -0
  60. package/docs/api/ai_spatial.js.html +307 -0
  61. package/docs/api/ai_tts.js.html +214 -0
  62. package/docs/api/content_social-protocols.js.html +180 -0
  63. package/docs/api/core_holosphere.js.html +757 -0
  64. package/docs/api/crypto_nostr-utils.js.html +306 -0
  65. package/docs/api/crypto_secp256k1.js.html +267 -0
  66. package/docs/api/data/search.json +1 -0
  67. package/docs/api/federation_discovery.js.html +337 -0
  68. package/docs/api/federation_handshake.js.html +478 -0
  69. package/docs/api/federation_hologram.js.html +1053 -0
  70. package/docs/api/federation_registry.js.html +389 -0
  71. package/docs/api/fonts/Inconsolata-Regular.ttf +0 -0
  72. package/docs/api/fonts/OpenSans-Regular.ttf +0 -0
  73. package/docs/api/fonts/WorkSans-Bold.ttf +0 -0
  74. package/docs/api/global.html +3 -0
  75. package/docs/api/hierarchical_upcast.js.html +128 -0
  76. package/docs/api/index.html +265 -0
  77. package/docs/api/index.js.html +1868 -0
  78. package/docs/api/lib_ai-methods.js.html +660 -0
  79. package/docs/api/lib_contract-methods.js.html +445 -0
  80. package/docs/api/lib_errors.js.html +56 -0
  81. package/docs/api/lib_federation-methods.js.html +348 -0
  82. package/docs/api/lib_index.js.html +33 -0
  83. package/docs/api/module-ai.html +5 -0
  84. package/docs/api/module-ai_aggregation-SmartAggregation.html +6 -0
  85. package/docs/api/module-ai_aggregation.SmartAggregation.html +3 -0
  86. package/docs/api/module-ai_aggregation.html +3 -0
  87. package/docs/api/module-ai_breakdown-TaskBreakdown.html +5 -0
  88. package/docs/api/module-ai_breakdown.TaskBreakdown.html +3 -0
  89. package/docs/api/module-ai_breakdown.html +3 -0
  90. package/docs/api/module-ai_classifier-Classifier.html +6 -0
  91. package/docs/api/module-ai_classifier.Classifier.html +3 -0
  92. package/docs/api/module-ai_classifier.html +3 -0
  93. package/docs/api/module-ai_council-Council.html +6 -0
  94. package/docs/api/module-ai_council.Council.html +3 -0
  95. package/docs/api/module-ai_council.html +3 -0
  96. package/docs/api/module-ai_embeddings-Embeddings.html +5 -0
  97. package/docs/api/module-ai_embeddings.Embeddings.html +3 -0
  98. package/docs/api/module-ai_embeddings.html +3 -0
  99. package/docs/api/module-ai_federation-ai-FederationAdvisor.html +6 -0
  100. package/docs/api/module-ai_federation-ai.FederationAdvisor.html +3 -0
  101. package/docs/api/module-ai_federation-ai.html +3 -0
  102. package/docs/api/module-ai_h3-ai-H3AI.html +6 -0
  103. package/docs/api/module-ai_h3-ai.H3AI.html +3 -0
  104. package/docs/api/module-ai_h3-ai.html +3 -0
  105. package/docs/api/module-ai_json-ops-JSONOps.html +5 -0
  106. package/docs/api/module-ai_json-ops.JSONOps.html +3 -0
  107. package/docs/api/module-ai_json-ops.html +3 -0
  108. package/docs/api/module-ai_llm-service-LLMService.html +5 -0
  109. package/docs/api/module-ai_llm-service.LLMService.html +3 -0
  110. package/docs/api/module-ai_llm-service.html +3 -0
  111. package/docs/api/module-ai_nl-query-NLQuery.html +5 -0
  112. package/docs/api/module-ai_nl-query.NLQuery.html +3 -0
  113. package/docs/api/module-ai_nl-query.html +3 -0
  114. package/docs/api/module-ai_relationships-RelationshipDiscovery.html +6 -0
  115. package/docs/api/module-ai_relationships.RelationshipDiscovery.html +3 -0
  116. package/docs/api/module-ai_relationships.html +3 -0
  117. package/docs/api/module-ai_schema-extractor-SchemaExtractor.html +5 -0
  118. package/docs/api/module-ai_schema-extractor.SchemaExtractor.html +3 -0
  119. package/docs/api/module-ai_schema-extractor.html +3 -0
  120. package/docs/api/module-ai_spatial-SpatialAnalysis.html +6 -0
  121. package/docs/api/module-ai_spatial.SpatialAnalysis.html +3 -0
  122. package/docs/api/module-ai_spatial.html +3 -0
  123. package/docs/api/module-ai_tts-TTS.html +5 -0
  124. package/docs/api/module-ai_tts.TTS.html +3 -0
  125. package/docs/api/module-ai_tts.html +3 -0
  126. package/docs/api/module-content_social-protocols.html +3 -0
  127. package/docs/api/module-core_holosphere-HoloSphere.html +6 -0
  128. package/docs/api/module-core_holosphere.HoloSphere.html +3 -0
  129. package/docs/api/module-core_holosphere.html +3 -0
  130. package/docs/api/module-crypto_nostr-utils.html +3 -0
  131. package/docs/api/module-crypto_secp256k1.html +3 -0
  132. package/docs/api/module-federation_hologram.html +3 -0
  133. package/docs/api/module-hierarchical_upcast.html +3 -0
  134. package/docs/api/module-holosphere-HoloSphereBase.html +3 -0
  135. package/docs/api/module-holosphere.html +3 -0
  136. package/docs/api/module-lib_ai-methods.html +3 -0
  137. package/docs/api/module-lib_contract-methods.html +3 -0
  138. package/docs/api/module-lib_errors-AuthorizationError.html +3 -0
  139. package/docs/api/module-lib_errors-ValidationError.html +3 -0
  140. package/docs/api/module-lib_errors.AuthorizationError.html +3 -0
  141. package/docs/api/module-lib_errors.ValidationError.html +3 -0
  142. package/docs/api/module-lib_errors.html +3 -0
  143. package/docs/api/module-lib_federation-methods.html +3 -0
  144. package/docs/api/module-lib_index.html +3 -0
  145. package/docs/api/module-schema_validator-ValidationError.html +3 -0
  146. package/docs/api/module-schema_validator.ValidationError.html +3 -0
  147. package/docs/api/module-schema_validator.html +3 -0
  148. package/docs/api/module-spatial_h3-operations.html +4 -0
  149. package/docs/api/module-storage_backend-factory.BackendFactory.html +3 -0
  150. package/docs/api/module-storage_backend-factory.html +3 -0
  151. package/docs/api/module-storage_backend-interface-StorageBackend.html +3 -0
  152. package/docs/api/module-storage_backend-interface.StorageBackend.html +3 -0
  153. package/docs/api/module-storage_backend-interface.html +3 -0
  154. package/docs/api/module-storage_backends_activitypub-backend-ActivityPubBackend.html +7 -0
  155. package/docs/api/module-storage_backends_activitypub-backend.ActivityPubBackend.html +3 -0
  156. package/docs/api/module-storage_backends_activitypub-backend.html +3 -0
  157. package/docs/api/module-storage_backends_activitypub_server-ActivityPubServer.html +8 -0
  158. package/docs/api/module-storage_backends_activitypub_server.ActivityPubServer.html +3 -0
  159. package/docs/api/module-storage_backends_activitypub_server.html +3 -0
  160. package/docs/api/module-storage_backends_gundb-backend-GunDBBackend.html +7 -0
  161. package/docs/api/module-storage_backends_gundb-backend.GunDBBackend.html +3 -0
  162. package/docs/api/module-storage_backends_gundb-backend.html +3 -0
  163. package/docs/api/module-storage_backends_nostr-backend-NostrBackend.html +8 -0
  164. package/docs/api/module-storage_backends_nostr-backend.NostrBackend.html +3 -0
  165. package/docs/api/module-storage_backends_nostr-backend.html +3 -0
  166. package/docs/api/module-storage_filesystem-storage-FileSystemStorage.html +5 -0
  167. package/docs/api/module-storage_filesystem-storage-browser-FileSystemStorage.html +3 -0
  168. package/docs/api/module-storage_filesystem-storage-browser.FileSystemStorage.html +3 -0
  169. package/docs/api/module-storage_filesystem-storage-browser.html +3 -0
  170. package/docs/api/module-storage_filesystem-storage.FileSystemStorage.html +3 -0
  171. package/docs/api/module-storage_filesystem-storage.html +3 -0
  172. package/docs/api/module-storage_global-tables.html +3 -0
  173. package/docs/api/module-storage_gun-async.html +3 -0
  174. package/docs/api/module-storage_gun-auth-GunAuth.html +5 -0
  175. package/docs/api/module-storage_gun-auth.GunAuth.html +3 -0
  176. package/docs/api/module-storage_gun-auth.html +3 -0
  177. package/docs/api/module-storage_gun-federation.html +3 -0
  178. package/docs/api/module-storage_gun-references-GunReferenceHandler.html +5 -0
  179. package/docs/api/module-storage_gun-references.GunReferenceHandler.html +3 -0
  180. package/docs/api/module-storage_gun-references.html +3 -0
  181. package/docs/api/module-storage_gun-schema-GunSchemaValidator.html +5 -0
  182. package/docs/api/module-storage_gun-schema.GunSchemaValidator.html +3 -0
  183. package/docs/api/module-storage_gun-schema.html +3 -0
  184. package/docs/api/module-storage_gun-wrapper.html +11 -0
  185. package/docs/api/module-storage_indexeddb-storage-IndexedDBStorage.html +5 -0
  186. package/docs/api/module-storage_indexeddb-storage.IndexedDBStorage.html +3 -0
  187. package/docs/api/module-storage_indexeddb-storage.html +3 -0
  188. package/docs/api/module-storage_key-storage-simple.html +3 -0
  189. package/docs/api/module-storage_key-storage.html +4 -0
  190. package/docs/api/module-storage_memory-storage-MemoryStorage.html +5 -0
  191. package/docs/api/module-storage_memory-storage.MemoryStorage.html +3 -0
  192. package/docs/api/module-storage_memory-storage.html +3 -0
  193. package/docs/api/module-storage_migration-MigrationTool.html +6 -0
  194. package/docs/api/module-storage_migration.MigrationTool.html +3 -0
  195. package/docs/api/module-storage_migration.html +3 -0
  196. package/docs/api/module-storage_nostr-async.html +18 -0
  197. package/docs/api/module-storage_nostr-client-LRUCache.html +3 -0
  198. package/docs/api/module-storage_nostr-client-NostrClient.html +7 -0
  199. package/docs/api/module-storage_nostr-client.NostrClient.html +15 -0
  200. package/docs/api/module-storage_nostr-client.html +6 -0
  201. package/docs/api/module-storage_nostr-wrapper.html +3 -0
  202. package/docs/api/module-storage_outbox-queue-OutboxQueue.html +4 -0
  203. package/docs/api/module-storage_outbox-queue.OutboxQueue.html +3 -0
  204. package/docs/api/module-storage_outbox-queue.html +3 -0
  205. package/docs/api/module-storage_persistent-storage-PersistentStorage.html +3 -0
  206. package/docs/api/module-storage_persistent-storage.html +4 -0
  207. package/docs/api/module-storage_sync-service-SyncService.html +5 -0
  208. package/docs/api/module-storage_sync-service.SyncService.html +3 -0
  209. package/docs/api/module-storage_sync-service.html +3 -0
  210. package/docs/api/module-storage_unified-storage.html +3 -0
  211. package/docs/api/module-subscriptions_manager.SubscriptionRegistry.html +3 -0
  212. package/docs/api/module-subscriptions_manager.html +3 -0
  213. package/docs/api/schema_validator.js.html +113 -0
  214. package/docs/api/scripts/core.js +726 -0
  215. package/docs/api/scripts/core.min.js +23 -0
  216. package/docs/api/scripts/resize.js +90 -0
  217. package/docs/api/scripts/search.js +265 -0
  218. package/docs/api/scripts/search.min.js +6 -0
  219. package/docs/api/scripts/third-party/Apache-License-2.0.txt +202 -0
  220. package/docs/api/scripts/third-party/fuse.js +9 -0
  221. package/docs/api/scripts/third-party/hljs-line-num-original.js +369 -0
  222. package/docs/api/scripts/third-party/hljs-line-num.js +1 -0
  223. package/docs/api/scripts/third-party/hljs-original.js +5171 -0
  224. package/docs/api/scripts/third-party/hljs.js +1 -0
  225. package/docs/api/scripts/third-party/popper.js +5 -0
  226. package/docs/api/scripts/third-party/tippy.js +1 -0
  227. package/docs/api/scripts/third-party/tocbot.js +672 -0
  228. package/docs/api/scripts/third-party/tocbot.min.js +1 -0
  229. package/docs/api/spatial_h3-operations.js.html +129 -0
  230. package/docs/api/storage_backend-factory.js.html +133 -0
  231. package/docs/api/storage_backend-interface.js.html +164 -0
  232. package/docs/api/storage_backends_activitypub-backend.js.html +298 -0
  233. package/docs/api/storage_backends_activitypub_server.js.html +678 -0
  234. package/docs/api/storage_backends_gundb-backend.js.html +878 -0
  235. package/docs/api/storage_backends_nostr-backend.js.html +254 -0
  236. package/docs/api/storage_filesystem-storage-browser.js.html +83 -0
  237. package/docs/api/storage_filesystem-storage.js.html +207 -0
  238. package/docs/api/storage_global-tables.js.html +116 -0
  239. package/docs/api/storage_gun-async.js.html +344 -0
  240. package/docs/api/storage_gun-auth.js.html +376 -0
  241. package/docs/api/storage_gun-federation.js.html +788 -0
  242. package/docs/api/storage_gun-references.js.html +212 -0
  243. package/docs/api/storage_gun-schema.js.html +309 -0
  244. package/docs/api/storage_gun-wrapper.js.html +645 -0
  245. package/docs/api/storage_indexeddb-storage.js.html +224 -0
  246. package/docs/api/storage_key-storage-simple.js.html +102 -0
  247. package/docs/api/storage_key-storage.js.html +171 -0
  248. package/docs/api/storage_memory-storage.js.html +128 -0
  249. package/docs/api/storage_migration.js.html +354 -0
  250. package/docs/api/storage_nostr-async.js.html +1076 -0
  251. package/docs/api/storage_nostr-client.js.html +1598 -0
  252. package/docs/api/storage_nostr-wrapper.js.html +218 -0
  253. package/docs/api/storage_outbox-queue.js.html +248 -0
  254. package/docs/api/storage_persistent-storage.js.html +160 -0
  255. package/docs/api/storage_sync-service.js.html +201 -0
  256. package/docs/api/storage_unified-storage.js.html +157 -0
  257. package/docs/api/styles/clean-jsdoc-theme-base.css +1159 -0
  258. package/docs/api/styles/clean-jsdoc-theme-dark.css +412 -0
  259. package/docs/api/styles/clean-jsdoc-theme-light.css +482 -0
  260. package/docs/api/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  261. package/docs/api/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  262. package/docs/api/styles/clean-jsdoc-theme.min.css +1 -0
  263. package/docs/api/subscriptions_manager.js.html +162 -0
  264. package/docs/contracts/api-interface.md +793 -0
  265. package/docs/data-model.md +476 -0
  266. package/docs/gun-async-usage.md +338 -0
  267. package/docs/plan.md +349 -0
  268. package/docs/quickstart.md +674 -0
  269. package/docs/research.md +362 -0
  270. package/docs/spec.md +244 -0
  271. package/docs/storage-backends.md +326 -0
  272. package/docs/tasks.md +947 -0
  273. package/examples/demo.html +47 -0
  274. package/examples/holosphere-widget.js +1242 -0
  275. package/examples/widget-demo.html +274 -0
  276. package/examples/widget.html +703 -0
  277. package/jsdoc.json +26 -0
  278. package/package.json +25 -7
  279. package/src/ai/aggregation.js +13 -2
  280. package/src/ai/breakdown.js +12 -2
  281. package/src/ai/classifier.js +14 -3
  282. package/src/ai/council.js +22 -7
  283. package/src/ai/embeddings.js +37 -15
  284. package/src/ai/federation-ai.js +13 -2
  285. package/src/ai/h3-ai.js +14 -2
  286. package/src/ai/index.js +16 -7
  287. package/src/ai/json-ops.js +18 -5
  288. package/src/ai/llm-service.js +62 -31
  289. package/src/ai/nl-query.js +12 -2
  290. package/src/ai/relationships.js +13 -2
  291. package/src/ai/schema-extractor.js +24 -10
  292. package/src/ai/spatial.js +13 -2
  293. package/src/ai/tts.js +25 -8
  294. package/src/cdn-entry.js +22 -0
  295. package/src/content/social-protocols.js +34 -25
  296. package/src/contracts/abis/Appreciative.json +1280 -0
  297. package/src/contracts/abis/AppreciativeFactory.json +101 -0
  298. package/src/contracts/abis/Bundle.json +1438 -0
  299. package/src/contracts/abis/BundleFactory.json +106 -0
  300. package/src/contracts/abis/Holon.json +881 -0
  301. package/src/contracts/abis/Holons.json +330 -0
  302. package/src/contracts/abis/Managed.json +1262 -0
  303. package/src/contracts/abis/ManagedFactory.json +149 -0
  304. package/src/contracts/abis/Membrane.json +261 -0
  305. package/src/contracts/abis/Splitter.json +1624 -0
  306. package/src/contracts/abis/SplitterFactory.json +220 -0
  307. package/src/contracts/abis/TestToken.json +321 -0
  308. package/src/contracts/abis/Zoned.json +1461 -0
  309. package/src/contracts/abis/ZonedFactory.json +154 -0
  310. package/src/contracts/chain-manager.js +403 -0
  311. package/src/contracts/deployer.js +500 -0
  312. package/src/contracts/event-listener.js +539 -0
  313. package/src/contracts/holon-contracts.js +359 -0
  314. package/src/contracts/index.js +82 -0
  315. package/src/contracts/networks.js +229 -0
  316. package/src/contracts/operations.js +687 -0
  317. package/src/contracts/queries.js +638 -0
  318. package/src/core/holosphere.js +487 -6
  319. package/src/crypto/nostr-utils.js +303 -0
  320. package/src/crypto/secp256k1.js +7 -2
  321. package/src/federation/handshake.js +475 -0
  322. package/src/federation/hologram.js +117 -3
  323. package/src/hierarchical/upcast.js +40 -25
  324. package/src/index.js +1501 -1909
  325. package/src/lib/ai-methods.js +657 -0
  326. package/src/lib/contract-methods.js +442 -0
  327. package/src/lib/errors.js +53 -0
  328. package/src/lib/federation-methods.js +345 -0
  329. package/src/lib/index.js +30 -0
  330. package/src/schema/validator.js +22 -3
  331. package/src/spatial/h3-operations.js +19 -3
  332. package/src/storage/backend-factory.js +7 -2
  333. package/src/storage/backend-interface.js +21 -2
  334. package/src/storage/backends/activitypub/server.js +25 -3
  335. package/src/storage/backends/activitypub-backend.js +25 -2
  336. package/src/storage/backends/gundb-backend.js +692 -50
  337. package/src/storage/backends/nostr-backend.js +116 -1
  338. package/src/storage/filesystem-storage-browser.js +42 -2
  339. package/src/storage/filesystem-storage.js +72 -5
  340. package/src/storage/global-tables.js +35 -3
  341. package/src/storage/gun-async.js +75 -15
  342. package/src/storage/gun-auth.js +373 -0
  343. package/src/storage/gun-federation.js +785 -0
  344. package/src/storage/gun-references.js +209 -0
  345. package/src/storage/gun-schema.js +306 -0
  346. package/src/storage/gun-wrapper.js +475 -54
  347. package/src/storage/indexeddb-storage.js +112 -13
  348. package/src/storage/key-storage-simple.js +32 -9
  349. package/src/storage/key-storage.js +45 -13
  350. package/src/storage/memory-storage.js +68 -2
  351. package/src/storage/migration.js +20 -7
  352. package/src/storage/nostr-async.js +412 -122
  353. package/src/storage/nostr-client.js +749 -76
  354. package/src/storage/nostr-wrapper.js +6 -2
  355. package/src/storage/outbox-queue.js +55 -18
  356. package/src/storage/persistent-storage.js +62 -14
  357. package/src/storage/sync-service.js +51 -17
  358. package/src/storage/unified-storage.js +154 -0
  359. package/src/subscriptions/manager.js +34 -17
  360. package/types/index.d.ts +133 -0
  361. package/vite.config.cdn.js +60 -0
  362. package/tests/unit/ai/aggregation.test.js +0 -295
  363. package/tests/unit/ai/breakdown.test.js +0 -446
  364. package/tests/unit/ai/classifier.test.js +0 -294
  365. package/tests/unit/ai/council.test.js +0 -262
  366. package/tests/unit/ai/embeddings.test.js +0 -384
  367. package/tests/unit/ai/federation-ai.test.js +0 -344
  368. package/tests/unit/ai/h3-ai.test.js +0 -458
  369. package/tests/unit/ai/index.test.js +0 -304
  370. package/tests/unit/ai/json-ops.test.js +0 -307
  371. package/tests/unit/ai/llm-service.test.js +0 -390
  372. package/tests/unit/ai/nl-query.test.js +0 -383
  373. package/tests/unit/ai/relationships.test.js +0 -311
  374. package/tests/unit/ai/schema-extractor.test.js +0 -384
  375. package/tests/unit/ai/spatial.test.js +0 -279
  376. package/tests/unit/ai/tts.test.js +0 -279
  377. package/tests/unit/content.test.js +0 -332
  378. package/tests/unit/contract/core.test.js +0 -88
  379. package/tests/unit/contract/crypto.test.js +0 -198
  380. package/tests/unit/contract/data.test.js +0 -223
  381. package/tests/unit/contract/federation.test.js +0 -181
  382. package/tests/unit/contract/hierarchical.test.js +0 -113
  383. package/tests/unit/contract/schema.test.js +0 -114
  384. package/tests/unit/contract/social.test.js +0 -217
  385. package/tests/unit/contract/spatial.test.js +0 -110
  386. package/tests/unit/contract/subscriptions.test.js +0 -128
  387. package/tests/unit/contract/utils.test.js +0 -159
  388. package/tests/unit/core.test.js +0 -152
  389. package/tests/unit/crypto.test.js +0 -328
  390. package/tests/unit/federation.test.js +0 -234
  391. package/tests/unit/gun-async.test.js +0 -252
  392. package/tests/unit/hierarchical.test.js +0 -399
  393. package/tests/unit/integration/scenario-01-geographic-storage.test.js +0 -74
  394. package/tests/unit/integration/scenario-02-federation.test.js +0 -76
  395. package/tests/unit/integration/scenario-03-subscriptions.test.js +0 -102
  396. package/tests/unit/integration/scenario-04-validation.test.js +0 -129
  397. package/tests/unit/integration/scenario-05-hierarchy.test.js +0 -125
  398. package/tests/unit/integration/scenario-06-social.test.js +0 -135
  399. package/tests/unit/integration/scenario-07-persistence.test.js +0 -130
  400. package/tests/unit/integration/scenario-08-authorization.test.js +0 -161
  401. package/tests/unit/integration/scenario-09-cross-dimensional.test.js +0 -139
  402. package/tests/unit/integration/scenario-10-cross-holosphere-capabilities.test.js +0 -357
  403. package/tests/unit/integration/scenario-11-cross-holosphere-federation.test.js +0 -410
  404. package/tests/unit/integration/scenario-12-capability-federated-read.test.js +0 -719
  405. package/tests/unit/performance/benchmark.test.js +0 -85
  406. package/tests/unit/schema.test.js +0 -213
  407. package/tests/unit/spatial.test.js +0 -158
  408. package/tests/unit/storage.test.js +0 -195
  409. package/tests/unit/subscriptions.test.js +0 -328
  410. package/tests/unit/test-data-permanence-debug.js +0 -197
  411. package/tests/unit/test-data-permanence.js +0 -340
  412. package/tests/unit/test-key-persistence-fixed.js +0 -148
  413. package/tests/unit/test-key-persistence.js +0 -172
  414. package/tests/unit/test-relay-permanence.js +0 -376
  415. package/tests/unit/test-second-node.js +0 -95
  416. package/tests/unit/test-simple-write.js +0 -89
  417. /package/{cleanup-test-data.js → scripts/cleanup-test-data.js} +0 -0
  418. /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
- * Drop-in replacement for gun-wrapper.js with same API
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 (default: 5)
14
- * @param {number} options.baseDelay - Base delay in ms (default: 1000)
15
- * @param {number} options.maxDelay - Max delay cap in ms (default: 60000)
16
- * @param {number} options.failedTTL - TTL for failed events in ms (default: 24 hours)
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 (removes from queue if successful)
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
- * @returns {Promise<Object>} Stats object
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
- * @param {number} maxAge - Max age in ms (default: 24 hours)
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
- * Provides a unified API for local persistence across browser and Node.js
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<Object[]>} Array of events
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
- * @returns {Promise<PersistentStorage>} Storage instance
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
- * @param {Object} client - NostrClient instance
11
- * @param {Object} options - Configuration options
12
- * @param {number} options.interval - Sync interval in ms (default: 10000)
13
- * @param {boolean} options.autoStart - Start automatically (default: false)
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
- * @returns {boolean}
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 (useful for testing or manual trigger)
57
- * @returns {Promise<Object>} Sync result
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
- * @returns {Promise<Object>} Stats including queue status
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 Subscription Management
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/nostr-wrapper.js';
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 ms
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 (default: false)
18
- * @param {boolean} options.resolveHolograms - Resolve holograms before callback (default: true)
19
- * @returns {Object} Subscription object with unsubscribe method
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
- * Subscription registry for tracking active subscriptions
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 subscription count
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;