holosphere 2.0.0-alpha7 → 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.
Files changed (327) hide show
  1. package/CHANGELOG.md +446 -0
  2. package/FEATURES.md +431 -0
  3. package/LICENSE +29 -166
  4. package/LICENSE-AGPL.md +180 -0
  5. package/dist/cdn/holosphere.min.js +55 -0
  6. package/dist/cdn/holosphere.min.js.map +1 -0
  7. package/dist/cjs/holosphere.cjs +1 -1
  8. package/dist/esm/holosphere.js +1 -1
  9. package/dist/{index-C-IlLYlk.cjs → index-DDGt_V9o.cjs} +2 -2
  10. package/dist/{index-C-IlLYlk.cjs.map → index-DDGt_V9o.cjs.map} +1 -1
  11. package/dist/{index-d6f4RJBM.js → index-DJXftyvB.js} +2253 -387
  12. package/dist/index-DJXftyvB.js.map +1 -0
  13. package/dist/index-DMbdcMtK.cjs +18 -0
  14. package/dist/index-DMbdcMtK.cjs.map +1 -0
  15. package/dist/{index-jmTHEbR2.js → index-DeZ1xz_s.js} +2 -2
  16. package/dist/{index-jmTHEbR2.js.map → index-DeZ1xz_s.js.map} +1 -1
  17. package/dist/{indexeddb-storage-D8kOl0oK.js → indexeddb-storage-BFt6hMeF.js} +48 -4
  18. package/dist/indexeddb-storage-BFt6hMeF.js.map +1 -0
  19. package/dist/{indexeddb-storage-a8GipaDr.cjs → indexeddb-storage-BK5tv4Sh.cjs} +2 -2
  20. package/dist/indexeddb-storage-BK5tv4Sh.cjs.map +1 -0
  21. package/dist/{memory-storage-DBQK622V.js → memory-storage-C9HuoL2E.js} +44 -4
  22. package/dist/memory-storage-C9HuoL2E.js.map +1 -0
  23. package/dist/{memory-storage-gfRovk2O.cjs → memory-storage-Dao7jfYG.cjs} +2 -2
  24. package/dist/memory-storage-Dao7jfYG.cjs.map +1 -0
  25. package/dist/{secp256k1-BCAPF45D.cjs → secp256k1-BbKzbLtD.cjs} +2 -2
  26. package/dist/{secp256k1-BCAPF45D.cjs.map → secp256k1-BbKzbLtD.cjs.map} +1 -1
  27. package/dist/{secp256k1-DYm_CMqW.js → secp256k1-CreY7Pcl.js} +2 -2
  28. package/dist/{secp256k1-DYm_CMqW.js.map → secp256k1-CreY7Pcl.js.map} +1 -1
  29. package/docs/api/ai_aggregation.js.html +333 -0
  30. package/docs/api/ai_breakdown.js.html +524 -0
  31. package/docs/api/ai_classifier.js.html +231 -0
  32. package/docs/api/ai_council.js.html +246 -0
  33. package/docs/api/ai_embeddings.js.html +304 -0
  34. package/docs/api/ai_federation-ai.js.html +338 -0
  35. package/docs/api/ai_h3-ai.js.html +970 -0
  36. package/docs/api/ai_index.js.html +124 -0
  37. package/docs/api/ai_json-ops.js.html +241 -0
  38. package/docs/api/ai_llm-service.js.html +239 -0
  39. package/docs/api/ai_nl-query.js.html +236 -0
  40. package/docs/api/ai_relationships.js.html +367 -0
  41. package/docs/api/ai_schema-extractor.js.html +235 -0
  42. package/docs/api/ai_spatial.js.html +307 -0
  43. package/docs/api/ai_tts.js.html +214 -0
  44. package/docs/api/content_social-protocols.js.html +180 -0
  45. package/docs/api/core_holosphere.js.html +757 -0
  46. package/docs/api/crypto_nostr-utils.js.html +306 -0
  47. package/docs/api/crypto_secp256k1.js.html +267 -0
  48. package/docs/api/data/search.json +1 -0
  49. package/docs/api/federation_discovery.js.html +337 -0
  50. package/docs/api/federation_handshake.js.html +478 -0
  51. package/docs/api/federation_hologram.js.html +1053 -0
  52. package/docs/api/federation_registry.js.html +389 -0
  53. package/docs/api/fonts/Inconsolata-Regular.ttf +0 -0
  54. package/docs/api/fonts/OpenSans-Regular.ttf +0 -0
  55. package/docs/api/fonts/WorkSans-Bold.ttf +0 -0
  56. package/docs/api/global.html +3 -0
  57. package/docs/api/hierarchical_upcast.js.html +128 -0
  58. package/docs/api/index.html +265 -0
  59. package/docs/api/index.js.html +1868 -0
  60. package/docs/api/lib_ai-methods.js.html +660 -0
  61. package/docs/api/lib_contract-methods.js.html +445 -0
  62. package/docs/api/lib_errors.js.html +56 -0
  63. package/docs/api/lib_federation-methods.js.html +348 -0
  64. package/docs/api/lib_index.js.html +33 -0
  65. package/docs/api/module-ai.html +5 -0
  66. package/docs/api/module-ai_aggregation-SmartAggregation.html +6 -0
  67. package/docs/api/module-ai_aggregation.SmartAggregation.html +3 -0
  68. package/docs/api/module-ai_aggregation.html +3 -0
  69. package/docs/api/module-ai_breakdown-TaskBreakdown.html +5 -0
  70. package/docs/api/module-ai_breakdown.TaskBreakdown.html +3 -0
  71. package/docs/api/module-ai_breakdown.html +3 -0
  72. package/docs/api/module-ai_classifier-Classifier.html +6 -0
  73. package/docs/api/module-ai_classifier.Classifier.html +3 -0
  74. package/docs/api/module-ai_classifier.html +3 -0
  75. package/docs/api/module-ai_council-Council.html +6 -0
  76. package/docs/api/module-ai_council.Council.html +3 -0
  77. package/docs/api/module-ai_council.html +3 -0
  78. package/docs/api/module-ai_embeddings-Embeddings.html +5 -0
  79. package/docs/api/module-ai_embeddings.Embeddings.html +3 -0
  80. package/docs/api/module-ai_embeddings.html +3 -0
  81. package/docs/api/module-ai_federation-ai-FederationAdvisor.html +6 -0
  82. package/docs/api/module-ai_federation-ai.FederationAdvisor.html +3 -0
  83. package/docs/api/module-ai_federation-ai.html +3 -0
  84. package/docs/api/module-ai_h3-ai-H3AI.html +6 -0
  85. package/docs/api/module-ai_h3-ai.H3AI.html +3 -0
  86. package/docs/api/module-ai_h3-ai.html +3 -0
  87. package/docs/api/module-ai_json-ops-JSONOps.html +5 -0
  88. package/docs/api/module-ai_json-ops.JSONOps.html +3 -0
  89. package/docs/api/module-ai_json-ops.html +3 -0
  90. package/docs/api/module-ai_llm-service-LLMService.html +5 -0
  91. package/docs/api/module-ai_llm-service.LLMService.html +3 -0
  92. package/docs/api/module-ai_llm-service.html +3 -0
  93. package/docs/api/module-ai_nl-query-NLQuery.html +5 -0
  94. package/docs/api/module-ai_nl-query.NLQuery.html +3 -0
  95. package/docs/api/module-ai_nl-query.html +3 -0
  96. package/docs/api/module-ai_relationships-RelationshipDiscovery.html +6 -0
  97. package/docs/api/module-ai_relationships.RelationshipDiscovery.html +3 -0
  98. package/docs/api/module-ai_relationships.html +3 -0
  99. package/docs/api/module-ai_schema-extractor-SchemaExtractor.html +5 -0
  100. package/docs/api/module-ai_schema-extractor.SchemaExtractor.html +3 -0
  101. package/docs/api/module-ai_schema-extractor.html +3 -0
  102. package/docs/api/module-ai_spatial-SpatialAnalysis.html +6 -0
  103. package/docs/api/module-ai_spatial.SpatialAnalysis.html +3 -0
  104. package/docs/api/module-ai_spatial.html +3 -0
  105. package/docs/api/module-ai_tts-TTS.html +5 -0
  106. package/docs/api/module-ai_tts.TTS.html +3 -0
  107. package/docs/api/module-ai_tts.html +3 -0
  108. package/docs/api/module-content_social-protocols.html +3 -0
  109. package/docs/api/module-core_holosphere-HoloSphere.html +6 -0
  110. package/docs/api/module-core_holosphere.HoloSphere.html +3 -0
  111. package/docs/api/module-core_holosphere.html +3 -0
  112. package/docs/api/module-crypto_nostr-utils.html +3 -0
  113. package/docs/api/module-crypto_secp256k1.html +3 -0
  114. package/docs/api/module-federation_hologram.html +3 -0
  115. package/docs/api/module-hierarchical_upcast.html +3 -0
  116. package/docs/api/module-holosphere-HoloSphereBase.html +3 -0
  117. package/docs/api/module-holosphere.html +3 -0
  118. package/docs/api/module-lib_ai-methods.html +3 -0
  119. package/docs/api/module-lib_contract-methods.html +3 -0
  120. package/docs/api/module-lib_errors-AuthorizationError.html +3 -0
  121. package/docs/api/module-lib_errors-ValidationError.html +3 -0
  122. package/docs/api/module-lib_errors.AuthorizationError.html +3 -0
  123. package/docs/api/module-lib_errors.ValidationError.html +3 -0
  124. package/docs/api/module-lib_errors.html +3 -0
  125. package/docs/api/module-lib_federation-methods.html +3 -0
  126. package/docs/api/module-lib_index.html +3 -0
  127. package/docs/api/module-schema_validator-ValidationError.html +3 -0
  128. package/docs/api/module-schema_validator.ValidationError.html +3 -0
  129. package/docs/api/module-schema_validator.html +3 -0
  130. package/docs/api/module-spatial_h3-operations.html +4 -0
  131. package/docs/api/module-storage_backend-factory.BackendFactory.html +3 -0
  132. package/docs/api/module-storage_backend-factory.html +3 -0
  133. package/docs/api/module-storage_backend-interface-StorageBackend.html +3 -0
  134. package/docs/api/module-storage_backend-interface.StorageBackend.html +3 -0
  135. package/docs/api/module-storage_backend-interface.html +3 -0
  136. package/docs/api/module-storage_backends_activitypub-backend-ActivityPubBackend.html +7 -0
  137. package/docs/api/module-storage_backends_activitypub-backend.ActivityPubBackend.html +3 -0
  138. package/docs/api/module-storage_backends_activitypub-backend.html +3 -0
  139. package/docs/api/module-storage_backends_activitypub_server-ActivityPubServer.html +8 -0
  140. package/docs/api/module-storage_backends_activitypub_server.ActivityPubServer.html +3 -0
  141. package/docs/api/module-storage_backends_activitypub_server.html +3 -0
  142. package/docs/api/module-storage_backends_gundb-backend-GunDBBackend.html +7 -0
  143. package/docs/api/module-storage_backends_gundb-backend.GunDBBackend.html +3 -0
  144. package/docs/api/module-storage_backends_gundb-backend.html +3 -0
  145. package/docs/api/module-storage_backends_nostr-backend-NostrBackend.html +8 -0
  146. package/docs/api/module-storage_backends_nostr-backend.NostrBackend.html +3 -0
  147. package/docs/api/module-storage_backends_nostr-backend.html +3 -0
  148. package/docs/api/module-storage_filesystem-storage-FileSystemStorage.html +5 -0
  149. package/docs/api/module-storage_filesystem-storage-browser-FileSystemStorage.html +3 -0
  150. package/docs/api/module-storage_filesystem-storage-browser.FileSystemStorage.html +3 -0
  151. package/docs/api/module-storage_filesystem-storage-browser.html +3 -0
  152. package/docs/api/module-storage_filesystem-storage.FileSystemStorage.html +3 -0
  153. package/docs/api/module-storage_filesystem-storage.html +3 -0
  154. package/docs/api/module-storage_global-tables.html +3 -0
  155. package/docs/api/module-storage_gun-async.html +3 -0
  156. package/docs/api/module-storage_gun-auth-GunAuth.html +5 -0
  157. package/docs/api/module-storage_gun-auth.GunAuth.html +3 -0
  158. package/docs/api/module-storage_gun-auth.html +3 -0
  159. package/docs/api/module-storage_gun-federation.html +3 -0
  160. package/docs/api/module-storage_gun-references-GunReferenceHandler.html +5 -0
  161. package/docs/api/module-storage_gun-references.GunReferenceHandler.html +3 -0
  162. package/docs/api/module-storage_gun-references.html +3 -0
  163. package/docs/api/module-storage_gun-schema-GunSchemaValidator.html +5 -0
  164. package/docs/api/module-storage_gun-schema.GunSchemaValidator.html +3 -0
  165. package/docs/api/module-storage_gun-schema.html +3 -0
  166. package/docs/api/module-storage_gun-wrapper.html +11 -0
  167. package/docs/api/module-storage_indexeddb-storage-IndexedDBStorage.html +5 -0
  168. package/docs/api/module-storage_indexeddb-storage.IndexedDBStorage.html +3 -0
  169. package/docs/api/module-storage_indexeddb-storage.html +3 -0
  170. package/docs/api/module-storage_key-storage-simple.html +3 -0
  171. package/docs/api/module-storage_key-storage.html +4 -0
  172. package/docs/api/module-storage_memory-storage-MemoryStorage.html +5 -0
  173. package/docs/api/module-storage_memory-storage.MemoryStorage.html +3 -0
  174. package/docs/api/module-storage_memory-storage.html +3 -0
  175. package/docs/api/module-storage_migration-MigrationTool.html +6 -0
  176. package/docs/api/module-storage_migration.MigrationTool.html +3 -0
  177. package/docs/api/module-storage_migration.html +3 -0
  178. package/docs/api/module-storage_nostr-async.html +18 -0
  179. package/docs/api/module-storage_nostr-client-LRUCache.html +3 -0
  180. package/docs/api/module-storage_nostr-client-NostrClient.html +7 -0
  181. package/docs/api/module-storage_nostr-client.NostrClient.html +15 -0
  182. package/docs/api/module-storage_nostr-client.html +6 -0
  183. package/docs/api/module-storage_nostr-wrapper.html +3 -0
  184. package/docs/api/module-storage_outbox-queue-OutboxQueue.html +4 -0
  185. package/docs/api/module-storage_outbox-queue.OutboxQueue.html +3 -0
  186. package/docs/api/module-storage_outbox-queue.html +3 -0
  187. package/docs/api/module-storage_persistent-storage-PersistentStorage.html +3 -0
  188. package/docs/api/module-storage_persistent-storage.html +4 -0
  189. package/docs/api/module-storage_sync-service-SyncService.html +5 -0
  190. package/docs/api/module-storage_sync-service.SyncService.html +3 -0
  191. package/docs/api/module-storage_sync-service.html +3 -0
  192. package/docs/api/module-storage_unified-storage.html +3 -0
  193. package/docs/api/module-subscriptions_manager.SubscriptionRegistry.html +3 -0
  194. package/docs/api/module-subscriptions_manager.html +3 -0
  195. package/docs/api/schema_validator.js.html +113 -0
  196. package/docs/api/scripts/core.js +726 -0
  197. package/docs/api/scripts/core.min.js +23 -0
  198. package/docs/api/scripts/resize.js +90 -0
  199. package/docs/api/scripts/search.js +265 -0
  200. package/docs/api/scripts/search.min.js +6 -0
  201. package/docs/api/scripts/third-party/Apache-License-2.0.txt +202 -0
  202. package/docs/api/scripts/third-party/fuse.js +9 -0
  203. package/docs/api/scripts/third-party/hljs-line-num-original.js +369 -0
  204. package/docs/api/scripts/third-party/hljs-line-num.js +1 -0
  205. package/docs/api/scripts/third-party/hljs-original.js +5171 -0
  206. package/docs/api/scripts/third-party/hljs.js +1 -0
  207. package/docs/api/scripts/third-party/popper.js +5 -0
  208. package/docs/api/scripts/third-party/tippy.js +1 -0
  209. package/docs/api/scripts/third-party/tocbot.js +672 -0
  210. package/docs/api/scripts/third-party/tocbot.min.js +1 -0
  211. package/docs/api/spatial_h3-operations.js.html +129 -0
  212. package/docs/api/storage_backend-factory.js.html +133 -0
  213. package/docs/api/storage_backend-interface.js.html +164 -0
  214. package/docs/api/storage_backends_activitypub-backend.js.html +298 -0
  215. package/docs/api/storage_backends_activitypub_server.js.html +678 -0
  216. package/docs/api/storage_backends_gundb-backend.js.html +878 -0
  217. package/docs/api/storage_backends_nostr-backend.js.html +254 -0
  218. package/docs/api/storage_filesystem-storage-browser.js.html +83 -0
  219. package/docs/api/storage_filesystem-storage.js.html +207 -0
  220. package/docs/api/storage_global-tables.js.html +116 -0
  221. package/docs/api/storage_gun-async.js.html +344 -0
  222. package/docs/api/storage_gun-auth.js.html +376 -0
  223. package/docs/api/storage_gun-federation.js.html +788 -0
  224. package/docs/api/storage_gun-references.js.html +212 -0
  225. package/docs/api/storage_gun-schema.js.html +309 -0
  226. package/docs/api/storage_gun-wrapper.js.html +645 -0
  227. package/docs/api/storage_indexeddb-storage.js.html +224 -0
  228. package/docs/api/storage_key-storage-simple.js.html +102 -0
  229. package/docs/api/storage_key-storage.js.html +171 -0
  230. package/docs/api/storage_memory-storage.js.html +128 -0
  231. package/docs/api/storage_migration.js.html +354 -0
  232. package/docs/api/storage_nostr-async.js.html +1076 -0
  233. package/docs/api/storage_nostr-client.js.html +1598 -0
  234. package/docs/api/storage_nostr-wrapper.js.html +218 -0
  235. package/docs/api/storage_outbox-queue.js.html +248 -0
  236. package/docs/api/storage_persistent-storage.js.html +160 -0
  237. package/docs/api/storage_sync-service.js.html +201 -0
  238. package/docs/api/storage_unified-storage.js.html +157 -0
  239. package/docs/api/styles/clean-jsdoc-theme-base.css +1159 -0
  240. package/docs/api/styles/clean-jsdoc-theme-dark.css +412 -0
  241. package/docs/api/styles/clean-jsdoc-theme-light.css +482 -0
  242. package/docs/api/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  243. package/docs/api/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  244. package/docs/api/styles/clean-jsdoc-theme.min.css +1 -0
  245. package/docs/api/subscriptions_manager.js.html +162 -0
  246. package/examples/holosphere-widget.js +1242 -0
  247. package/examples/widget-demo.html +274 -0
  248. package/examples/widget.html +703 -0
  249. package/jsdoc.json +26 -0
  250. package/package.json +16 -3
  251. package/src/ai/aggregation.js +13 -2
  252. package/src/ai/breakdown.js +12 -2
  253. package/src/ai/classifier.js +14 -3
  254. package/src/ai/council.js +22 -7
  255. package/src/ai/embeddings.js +37 -15
  256. package/src/ai/federation-ai.js +13 -2
  257. package/src/ai/h3-ai.js +14 -2
  258. package/src/ai/index.js +16 -7
  259. package/src/ai/json-ops.js +18 -5
  260. package/src/ai/llm-service.js +62 -31
  261. package/src/ai/nl-query.js +12 -2
  262. package/src/ai/relationships.js +13 -2
  263. package/src/ai/schema-extractor.js +24 -10
  264. package/src/ai/spatial.js +13 -2
  265. package/src/ai/tts.js +25 -8
  266. package/src/cdn-entry.js +22 -0
  267. package/src/content/social-protocols.js +34 -25
  268. package/src/contracts/chain-manager.js +68 -40
  269. package/src/contracts/deployer.js +70 -42
  270. package/src/contracts/event-listener.js +61 -29
  271. package/src/contracts/holon-contracts.js +46 -31
  272. package/src/contracts/index.js +5 -6
  273. package/src/contracts/networks.js +19 -14
  274. package/src/contracts/operations.js +58 -41
  275. package/src/contracts/queries.js +70 -21
  276. package/src/core/holosphere.js +37 -8
  277. package/src/crypto/nostr-utils.js +105 -65
  278. package/src/crypto/secp256k1.js +7 -2
  279. package/src/federation/handshake.js +23 -11
  280. package/src/federation/hologram.js +9 -1
  281. package/src/hierarchical/upcast.js +34 -20
  282. package/src/index.js +671 -7
  283. package/src/lib/ai-methods.js +352 -3
  284. package/src/lib/contract-methods.js +152 -3
  285. package/src/lib/errors.js +31 -1
  286. package/src/lib/federation-methods.js +110 -3
  287. package/src/lib/index.js +9 -5
  288. package/src/schema/validator.js +22 -3
  289. package/src/spatial/h3-operations.js +17 -1
  290. package/src/storage/backend-factory.js +7 -2
  291. package/src/storage/backend-interface.js +21 -2
  292. package/src/storage/backends/activitypub/server.js +25 -3
  293. package/src/storage/backends/activitypub-backend.js +25 -2
  294. package/src/storage/backends/gundb-backend.js +322 -11
  295. package/src/storage/backends/nostr-backend.js +116 -1
  296. package/src/storage/filesystem-storage-browser.js +42 -2
  297. package/src/storage/filesystem-storage.js +72 -5
  298. package/src/storage/global-tables.js +7 -2
  299. package/src/storage/gun-async.js +20 -11
  300. package/src/storage/gun-auth.js +15 -4
  301. package/src/storage/gun-federation.js +14 -5
  302. package/src/storage/gun-references.js +16 -5
  303. package/src/storage/gun-schema.js +25 -10
  304. package/src/storage/gun-wrapper.js +160 -49
  305. package/src/storage/indexeddb-storage.js +65 -4
  306. package/src/storage/key-storage-simple.js +32 -9
  307. package/src/storage/key-storage.js +45 -13
  308. package/src/storage/memory-storage.js +65 -4
  309. package/src/storage/migration.js +20 -7
  310. package/src/storage/nostr-async.js +195 -90
  311. package/src/storage/nostr-client.js +173 -49
  312. package/src/storage/nostr-wrapper.js +6 -2
  313. package/src/storage/outbox-queue.js +55 -18
  314. package/src/storage/persistent-storage.js +56 -13
  315. package/src/storage/sync-service.js +51 -17
  316. package/src/storage/unified-storage.js +38 -3
  317. package/src/subscriptions/manager.js +33 -16
  318. package/vite.config.cdn.js +60 -0
  319. package/dist/index-Bvwyvd0T.cjs +0 -5
  320. package/dist/index-Bvwyvd0T.cjs.map +0 -1
  321. package/dist/index-d6f4RJBM.js.map +0 -1
  322. package/dist/indexeddb-storage-D8kOl0oK.js.map +0 -1
  323. package/dist/indexeddb-storage-a8GipaDr.cjs.map +0 -1
  324. package/dist/memory-storage-DBQK622V.js.map +0 -1
  325. package/dist/memory-storage-gfRovk2O.cjs.map +0 -1
  326. /package/{cleanup-test-data.js → scripts/cleanup-test-data.js} +0 -0
  327. /package/{test-ai-real-api.js → scripts/test-ai-real-api.js} +0 -0
@@ -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 = {
@@ -1,6 +1,11 @@
1
1
  /**
2
- * Unified Storage Adapter
3
- * Routes storage operations to the correct backend (nostr or gundb)
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
4
9
  */
5
10
 
6
11
  import * as nostrWrapper from './nostr-wrapper.js';
@@ -27,7 +32,11 @@ export function buildPath(appName, holonId, lensName, key = null) {
27
32
  * @returns {Promise<boolean>} Success indicator
28
33
  */
29
34
  export async function write(client, path, data) {
30
- // Check if this is a GunDB client
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)
31
40
  if (client.gun) {
32
41
  return gunWrapper.write(client.gun, path, data);
33
42
  }
@@ -43,6 +52,11 @@ export async function write(client, path, data) {
43
52
  * @returns {Promise<Object|null>} Data or null
44
53
  */
45
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
46
60
  if (client.gun) {
47
61
  return gunWrapper.read(client.gun, path);
48
62
  }
@@ -57,6 +71,11 @@ export async function read(client, path, options = {}) {
57
71
  * @returns {Promise<Object[]>} Array of data objects
58
72
  */
59
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
60
79
  if (client.gun) {
61
80
  return gunWrapper.readAll(client.gun, path);
62
81
  }
@@ -71,6 +90,11 @@ export async function readAll(client, path, options = {}) {
71
90
  * @returns {Promise<boolean>} Success indicator
72
91
  */
73
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
74
98
  if (client.gun) {
75
99
  return gunWrapper.update(client.gun, path, updates);
76
100
  }
@@ -84,6 +108,11 @@ export async function update(client, path, updates) {
84
108
  * @returns {Promise<boolean>} Success indicator
85
109
  */
86
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
87
116
  if (client.gun) {
88
117
  return gunWrapper.deleteData(client.gun, path);
89
118
  }
@@ -97,6 +126,7 @@ export async function deleteData(client, path) {
97
126
  * @returns {Promise<Object>} Deletion results
98
127
  */
99
128
  export async function deleteAll(client, path) {
129
+ // Fallback to direct gunWrapper (deleteAll not typically in client interface)
100
130
  if (client.gun) {
101
131
  return gunWrapper.deleteAll(client.gun, path);
102
132
  }
@@ -112,6 +142,11 @@ export async function deleteAll(client, path) {
112
142
  * @returns {Object} Subscription with unsubscribe method
113
143
  */
114
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
115
150
  if (client.gun) {
116
151
  return gunWrapper.subscribe(client.gun, path, callback, options);
117
152
  }
@@ -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
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;
@@ -0,0 +1,60 @@
1
+ import { defineConfig } from 'vite';
2
+ import { resolve } from 'path';
3
+
4
+ /**
5
+ * CDN Build Configuration
6
+ * Creates a self-contained bundle for browser usage via CDN
7
+ * All dependencies are bundled (no externals)
8
+ */
9
+ export default defineConfig({
10
+ build: {
11
+ target: 'es2020',
12
+ outDir: 'dist/cdn',
13
+ lib: {
14
+ entry: resolve(__dirname, 'src/cdn-entry.js'),
15
+ name: 'HoloSphere',
16
+ formats: ['iife'],
17
+ fileName: () => 'holosphere.min.js',
18
+ },
19
+ rollupOptions: {
20
+ // Bundle all dependencies for CDN
21
+ external: [],
22
+ output: {
23
+ // Use default export so HoloSphere is directly accessible
24
+ exports: 'default',
25
+ // Extend window with all exports
26
+ extend: true,
27
+ // Provide globals for any remaining externals
28
+ globals: {},
29
+ // Inline dynamic imports
30
+ inlineDynamicImports: true,
31
+ },
32
+ },
33
+ sourcemap: true,
34
+ minify: 'terser',
35
+ terserOptions: {
36
+ compress: {
37
+ drop_console: false,
38
+ passes: 2,
39
+ },
40
+ mangle: {
41
+ safari10: true,
42
+ },
43
+ },
44
+ // Increase chunk size warning limit for CDN bundle
45
+ chunkSizeWarningLimit: 2000,
46
+ },
47
+ resolve: {
48
+ alias: [
49
+ {
50
+ find: './filesystem-storage.js',
51
+ replacement: resolve(__dirname, 'src/storage/filesystem-storage-browser.js'),
52
+ },
53
+ ],
54
+ },
55
+ define: {
56
+ 'process.versions.node': JSON.stringify(undefined),
57
+ 'process.env.NODE_ENV': JSON.stringify('production'),
58
+ 'global': 'globalThis',
59
+ },
60
+ });