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.
Files changed (321) 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-CKffQDmQ.cjs → index-DDGt_V9o.cjs} +2 -2
  10. package/dist/{index-CKffQDmQ.cjs.map → index-DDGt_V9o.cjs.map} +1 -1
  11. package/dist/{index-4XHHKe6S.js → index-DJXftyvB.js} +1905 -337
  12. package/dist/index-DJXftyvB.js.map +1 -0
  13. package/dist/{index-Dz5kOZMI.cjs → index-DMbdcMtK.cjs} +17 -4
  14. package/dist/index-DMbdcMtK.cjs.map +1 -0
  15. package/dist/{index-BjP1TXGz.js → index-DeZ1xz_s.js} +2 -2
  16. package/dist/{index-BjP1TXGz.js.map → index-DeZ1xz_s.js.map} +1 -1
  17. package/dist/{indexeddb-storage-lExjjFlV.js → indexeddb-storage-BFt6hMeF.js} +48 -4
  18. package/dist/indexeddb-storage-BFt6hMeF.js.map +1 -0
  19. package/dist/{indexeddb-storage-DD7EFBVc.cjs → indexeddb-storage-BK5tv4Sh.cjs} +2 -2
  20. package/dist/indexeddb-storage-BK5tv4Sh.cjs.map +1 -0
  21. package/dist/{memory-storage-C68adso2.js → memory-storage-C9HuoL2E.js} +44 -4
  22. package/dist/memory-storage-C9HuoL2E.js.map +1 -0
  23. package/dist/{memory-storage-DD_6yyXT.cjs → memory-storage-Dao7jfYG.cjs} +2 -2
  24. package/dist/memory-storage-Dao7jfYG.cjs.map +1 -0
  25. package/dist/{secp256k1-DYELiqgx.cjs → secp256k1-BbKzbLtD.cjs} +2 -2
  26. package/dist/{secp256k1-DYELiqgx.cjs.map → secp256k1-BbKzbLtD.cjs.map} +1 -1
  27. package/dist/{secp256k1-OM8siPyy.js → secp256k1-CreY7Pcl.js} +2 -2
  28. package/dist/{secp256k1-OM8siPyy.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/jsdoc.json +26 -0
  247. package/package.json +14 -3
  248. package/src/ai/aggregation.js +13 -2
  249. package/src/ai/breakdown.js +12 -2
  250. package/src/ai/classifier.js +14 -3
  251. package/src/ai/council.js +22 -7
  252. package/src/ai/embeddings.js +37 -15
  253. package/src/ai/federation-ai.js +13 -2
  254. package/src/ai/h3-ai.js +14 -2
  255. package/src/ai/index.js +16 -7
  256. package/src/ai/json-ops.js +18 -5
  257. package/src/ai/llm-service.js +62 -31
  258. package/src/ai/nl-query.js +12 -2
  259. package/src/ai/relationships.js +13 -2
  260. package/src/ai/schema-extractor.js +24 -10
  261. package/src/ai/spatial.js +13 -2
  262. package/src/ai/tts.js +25 -8
  263. package/src/content/social-protocols.js +34 -25
  264. package/src/contracts/chain-manager.js +68 -40
  265. package/src/contracts/deployer.js +70 -42
  266. package/src/contracts/event-listener.js +61 -29
  267. package/src/contracts/holon-contracts.js +46 -31
  268. package/src/contracts/index.js +5 -6
  269. package/src/contracts/networks.js +19 -14
  270. package/src/contracts/operations.js +58 -41
  271. package/src/contracts/queries.js +54 -20
  272. package/src/core/holosphere.js +35 -6
  273. package/src/crypto/nostr-utils.js +82 -76
  274. package/src/crypto/secp256k1.js +7 -2
  275. package/src/federation/handshake.js +7 -7
  276. package/src/federation/hologram.js +9 -1
  277. package/src/hierarchical/upcast.js +34 -20
  278. package/src/index.js +655 -5
  279. package/src/lib/ai-methods.js +352 -3
  280. package/src/lib/contract-methods.js +152 -3
  281. package/src/lib/errors.js +31 -1
  282. package/src/lib/federation-methods.js +110 -3
  283. package/src/lib/index.js +9 -5
  284. package/src/schema/validator.js +22 -3
  285. package/src/spatial/h3-operations.js +17 -1
  286. package/src/storage/backend-factory.js +7 -2
  287. package/src/storage/backend-interface.js +21 -2
  288. package/src/storage/backends/activitypub/server.js +25 -3
  289. package/src/storage/backends/activitypub-backend.js +25 -2
  290. package/src/storage/backends/gundb-backend.js +29 -2
  291. package/src/storage/backends/nostr-backend.js +116 -1
  292. package/src/storage/filesystem-storage-browser.js +42 -2
  293. package/src/storage/filesystem-storage.js +72 -5
  294. package/src/storage/global-tables.js +7 -2
  295. package/src/storage/gun-async.js +20 -11
  296. package/src/storage/gun-auth.js +15 -4
  297. package/src/storage/gun-federation.js +14 -5
  298. package/src/storage/gun-references.js +16 -5
  299. package/src/storage/gun-schema.js +25 -10
  300. package/src/storage/gun-wrapper.js +99 -36
  301. package/src/storage/indexeddb-storage.js +65 -4
  302. package/src/storage/key-storage-simple.js +32 -9
  303. package/src/storage/key-storage.js +45 -13
  304. package/src/storage/memory-storage.js +65 -4
  305. package/src/storage/migration.js +20 -7
  306. package/src/storage/nostr-async.js +157 -67
  307. package/src/storage/nostr-client.js +173 -49
  308. package/src/storage/nostr-wrapper.js +6 -2
  309. package/src/storage/outbox-queue.js +55 -18
  310. package/src/storage/persistent-storage.js +56 -13
  311. package/src/storage/sync-service.js +51 -17
  312. package/src/storage/unified-storage.js +7 -2
  313. package/src/subscriptions/manager.js +33 -16
  314. package/dist/index-4XHHKe6S.js.map +0 -1
  315. package/dist/index-Dz5kOZMI.cjs.map +0 -1
  316. package/dist/indexeddb-storage-DD7EFBVc.cjs.map +0 -1
  317. package/dist/indexeddb-storage-lExjjFlV.js.map +0 -1
  318. package/dist/memory-storage-C68adso2.js.map +0 -1
  319. package/dist/memory-storage-DD_6yyXT.cjs.map +0 -1
  320. /package/{cleanup-test-data.js → scripts/cleanup-test-data.js} +0 -0
  321. /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
- * Ported from holosphere/federation.js to work with the GunDBBackend
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 (default: true)
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
- * Schemas are stored in the global 'schemas' table
6
- * Validation uses AJV (Another JSON Schema Validator) with JSON Schema 2019
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
- // Default meta-schema for validating schema definitions
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
- * @param {Object} options - Validator options
32
- * @param {boolean} options.strict - Whether to enforce strict validation (default: false)
33
- * @param {number} options.cacheMaxAge - Schema cache TTL in ms (default: 3600000 = 1 hour)
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
- * Handles path construction and CRUD operations
4
- * Note: GunDB doesn't handle nested objects well, so we store data as JSON strings
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
- * Stores data as raw JSON string for compatibility with holosphere original
78
- * This matches the format used in holosphere v1 for better interoperability
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<boolean>} Success indicator
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
- * First gets the count of expected items, then collects until count is reached
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 (default 5000)
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
- * Global tables are app-wide data not tied to specific holons (e.g., schemas, federation)
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<boolean>} Success indicator
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
- * Uses same approach as readAll
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 (default: 2000)
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
- * Provides persistent storage with good performance
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
- * @param {string} prefix
81
- * @returns {Promise<any[]>}
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
- * NOTE: This only works in Node.js, not browsers
6
- * For browsers, keys are managed in localStorage
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);