@pkcprotocol/pkc-js 0.0.11

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 (843) hide show
  1. package/LICENSE +339 -0
  2. package/README.md +1663 -0
  3. package/dist/browser/challenges.d.ts +1 -0
  4. package/dist/browser/challenges.js +2 -0
  5. package/dist/browser/challenges.js.map +1 -0
  6. package/dist/browser/clients/base-client-manager.d.ts +126 -0
  7. package/dist/browser/clients/base-client-manager.js +673 -0
  8. package/dist/browser/clients/base-client-manager.js.map +1 -0
  9. package/dist/browser/clients/name-resolver-client.d.ts +8 -0
  10. package/dist/browser/clients/name-resolver-client.js +10 -0
  11. package/dist/browser/clients/name-resolver-client.js.map +1 -0
  12. package/dist/browser/clients/pkc-typed-emitter.d.ts +9 -0
  13. package/dist/browser/clients/pkc-typed-emitter.js +52 -0
  14. package/dist/browser/clients/pkc-typed-emitter.js.map +1 -0
  15. package/dist/browser/clients/rpc-client/decode-rpc-response-util.d.ts +8 -0
  16. package/dist/browser/clients/rpc-client/decode-rpc-response-util.js +53 -0
  17. package/dist/browser/clients/rpc-client/decode-rpc-response-util.js.map +1 -0
  18. package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +68 -0
  19. package/dist/browser/clients/rpc-client/pkc-rpc-client.js +404 -0
  20. package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -0
  21. package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +147 -0
  22. package/dist/browser/clients/rpc-client/rpc-schema-util.js +11 -0
  23. package/dist/browser/clients/rpc-client/rpc-schema-util.js.map +1 -0
  24. package/dist/browser/clients/rpc-client/schema.d.ts +433 -0
  25. package/dist/browser/clients/rpc-client/schema.js +49 -0
  26. package/dist/browser/clients/rpc-client/schema.js.map +1 -0
  27. package/dist/browser/clients/rpc-client/types.d.ts +8 -0
  28. package/dist/browser/clients/rpc-client/types.js +2 -0
  29. package/dist/browser/clients/rpc-client/types.js.map +1 -0
  30. package/dist/browser/community/community-client-manager.d.ts +60 -0
  31. package/dist/browser/community/community-client-manager.js +717 -0
  32. package/dist/browser/community/community-client-manager.js.map +1 -0
  33. package/dist/browser/community/community-clients.d.ts +18 -0
  34. package/dist/browser/community/community-clients.js +12 -0
  35. package/dist/browser/community/community-clients.js.map +1 -0
  36. package/dist/browser/community/community-wire.d.ts +20 -0
  37. package/dist/browser/community/community-wire.js +38 -0
  38. package/dist/browser/community/community-wire.js.map +1 -0
  39. package/dist/browser/community/remote-community.d.ts +110 -0
  40. package/dist/browser/community/remote-community.js +555 -0
  41. package/dist/browser/community/remote-community.js.map +1 -0
  42. package/dist/browser/community/rpc-local-community.d.ts +41 -0
  43. package/dist/browser/community/rpc-local-community.js +289 -0
  44. package/dist/browser/community/rpc-local-community.js.map +1 -0
  45. package/dist/browser/community/rpc-remote-community.d.ts +18 -0
  46. package/dist/browser/community/rpc-remote-community.js +286 -0
  47. package/dist/browser/community/rpc-remote-community.js.map +1 -0
  48. package/dist/browser/community/schema.d.ts +4217 -0
  49. package/dist/browser/community/schema.js +289 -0
  50. package/dist/browser/community/schema.js.map +1 -0
  51. package/dist/browser/community/types.d.ts +135 -0
  52. package/dist/browser/community/types.js +2 -0
  53. package/dist/browser/community/types.js.map +1 -0
  54. package/dist/browser/constants.d.ts +6 -0
  55. package/dist/browser/constants.js +9 -0
  56. package/dist/browser/constants.js.map +1 -0
  57. package/dist/browser/decorator-util.d.ts +1 -0
  58. package/dist/browser/decorator-util.js +35 -0
  59. package/dist/browser/decorator-util.js.map +1 -0
  60. package/dist/browser/errors.d.ts +343 -0
  61. package/dist/browser/errors.js +358 -0
  62. package/dist/browser/errors.js.map +1 -0
  63. package/dist/browser/general-util/limited-set.d.ts +15 -0
  64. package/dist/browser/general-util/limited-set.js +66 -0
  65. package/dist/browser/general-util/limited-set.js.map +1 -0
  66. package/dist/browser/generated-version.d.ts +1 -0
  67. package/dist/browser/generated-version.js +3 -0
  68. package/dist/browser/generated-version.js.map +1 -0
  69. package/dist/browser/generic-state-client.d.ts +6 -0
  70. package/dist/browser/generic-state-client.js +11 -0
  71. package/dist/browser/generic-state-client.js.map +1 -0
  72. package/dist/browser/helia/helia-for-pkc.d.ts +3 -0
  73. package/dist/browser/helia/helia-for-pkc.js +255 -0
  74. package/dist/browser/helia/helia-for-pkc.js.map +1 -0
  75. package/dist/browser/helia/ipns-over-pubsub-with-fetch.d.ts +36 -0
  76. package/dist/browser/helia/ipns-over-pubsub-with-fetch.js +229 -0
  77. package/dist/browser/helia/ipns-over-pubsub-with-fetch.js.map +1 -0
  78. package/dist/browser/helia/libp2pjsClient.d.ts +27 -0
  79. package/dist/browser/helia/libp2pjsClient.js +15 -0
  80. package/dist/browser/helia/libp2pjsClient.js.map +1 -0
  81. package/dist/browser/helia/types.d.ts +19 -0
  82. package/dist/browser/helia/types.js +2 -0
  83. package/dist/browser/helia/types.js.map +1 -0
  84. package/dist/browser/helia/util.d.ts +13 -0
  85. package/dist/browser/helia/util.js +98 -0
  86. package/dist/browser/helia/util.js.map +1 -0
  87. package/dist/browser/index.d.ts +244 -0
  88. package/dist/browser/index.js +36 -0
  89. package/dist/browser/index.js.map +1 -0
  90. package/dist/browser/logger.d.ts +12 -0
  91. package/dist/browser/logger.js +11 -0
  92. package/dist/browser/logger.js.map +1 -0
  93. package/dist/browser/pages/pages-client-manager.d.ts +159 -0
  94. package/dist/browser/pages/pages-client-manager.js +334 -0
  95. package/dist/browser/pages/pages-client-manager.js.map +1 -0
  96. package/dist/browser/pages/pages-clients.d.ts +11 -0
  97. package/dist/browser/pages/pages-clients.js +10 -0
  98. package/dist/browser/pages/pages-clients.js.map +1 -0
  99. package/dist/browser/pages/pages.d.ts +107 -0
  100. package/dist/browser/pages/pages.js +262 -0
  101. package/dist/browser/pages/pages.js.map +1 -0
  102. package/dist/browser/pages/schema-util.d.ts +3 -0
  103. package/dist/browser/pages/schema-util.js +3 -0
  104. package/dist/browser/pages/schema-util.js.map +1 -0
  105. package/dist/browser/pages/schema.d.ts +719 -0
  106. package/dist/browser/pages/schema.js +32 -0
  107. package/dist/browser/pages/schema.js.map +1 -0
  108. package/dist/browser/pages/types.d.ts +44 -0
  109. package/dist/browser/pages/types.js +2 -0
  110. package/dist/browser/pages/types.js.map +1 -0
  111. package/dist/browser/pages/util.d.ts +56 -0
  112. package/dist/browser/pages/util.js +446 -0
  113. package/dist/browser/pages/util.js.map +1 -0
  114. package/dist/browser/pkc/pkc-client-manager.d.ts +44 -0
  115. package/dist/browser/pkc/pkc-client-manager.js +156 -0
  116. package/dist/browser/pkc/pkc-client-manager.js.map +1 -0
  117. package/dist/browser/pkc/pkc-clients.d.ts +11 -0
  118. package/dist/browser/pkc/pkc-clients.js +8 -0
  119. package/dist/browser/pkc/pkc-clients.js.map +1 -0
  120. package/dist/browser/pkc/pkc-with-rpc-client.d.ts +19 -0
  121. package/dist/browser/pkc/pkc-with-rpc-client.js +128 -0
  122. package/dist/browser/pkc/pkc-with-rpc-client.js.map +1 -0
  123. package/dist/browser/pkc/pkc.d.ts +137 -0
  124. package/dist/browser/pkc/pkc.js +888 -0
  125. package/dist/browser/pkc/pkc.js.map +1 -0
  126. package/dist/browser/pkc/tracked-instance-registry-util.d.ts +44 -0
  127. package/dist/browser/pkc/tracked-instance-registry-util.js +106 -0
  128. package/dist/browser/pkc/tracked-instance-registry-util.js.map +1 -0
  129. package/dist/browser/pkc/tracked-instance-registry.d.ts +18 -0
  130. package/dist/browser/pkc/tracked-instance-registry.js +134 -0
  131. package/dist/browser/pkc/tracked-instance-registry.js.map +1 -0
  132. package/dist/browser/pkc-error.d.ts +65 -0
  133. package/dist/browser/pkc-error.js +137 -0
  134. package/dist/browser/pkc-error.js.map +1 -0
  135. package/dist/browser/publications/comment/comment-client-manager.d.ts +86 -0
  136. package/dist/browser/publications/comment/comment-client-manager.js +908 -0
  137. package/dist/browser/publications/comment/comment-client-manager.js.map +1 -0
  138. package/dist/browser/publications/comment/comment-clients.d.ts +19 -0
  139. package/dist/browser/publications/comment/comment-clients.js +12 -0
  140. package/dist/browser/publications/comment/comment-clients.js.map +1 -0
  141. package/dist/browser/publications/comment/comment-util.d.ts +10 -0
  142. package/dist/browser/publications/comment/comment-util.js +202 -0
  143. package/dist/browser/publications/comment/comment-util.js.map +1 -0
  144. package/dist/browser/publications/comment/comment.d.ts +147 -0
  145. package/dist/browser/publications/comment/comment.js +1044 -0
  146. package/dist/browser/publications/comment/comment.js.map +1 -0
  147. package/dist/browser/publications/comment/schema.d.ts +1237 -0
  148. package/dist/browser/publications/comment/schema.js +184 -0
  149. package/dist/browser/publications/comment/schema.js.map +1 -0
  150. package/dist/browser/publications/comment/types.d.ts +100 -0
  151. package/dist/browser/publications/comment/types.js +2 -0
  152. package/dist/browser/publications/comment/types.js.map +1 -0
  153. package/dist/browser/publications/comment-edit/comment-edit.d.ts +41 -0
  154. package/dist/browser/publications/comment-edit/comment-edit.js +63 -0
  155. package/dist/browser/publications/comment-edit/comment-edit.js.map +1 -0
  156. package/dist/browser/publications/comment-edit/schema.d.ts +295 -0
  157. package/dist/browser/publications/comment-edit/schema.js +55 -0
  158. package/dist/browser/publications/comment-edit/schema.js.map +1 -0
  159. package/dist/browser/publications/comment-edit/types.d.ts +25 -0
  160. package/dist/browser/publications/comment-edit/types.js +2 -0
  161. package/dist/browser/publications/comment-edit/types.js.map +1 -0
  162. package/dist/browser/publications/comment-moderation/comment-moderation.d.ts +36 -0
  163. package/dist/browser/publications/comment-moderation/comment-moderation.js +53 -0
  164. package/dist/browser/publications/comment-moderation/comment-moderation.js.map +1 -0
  165. package/dist/browser/publications/comment-moderation/schema.d.ts +315 -0
  166. package/dist/browser/publications/comment-moderation/schema.js +62 -0
  167. package/dist/browser/publications/comment-moderation/schema.js.map +1 -0
  168. package/dist/browser/publications/comment-moderation/types.d.ts +22 -0
  169. package/dist/browser/publications/comment-moderation/types.js +2 -0
  170. package/dist/browser/publications/comment-moderation/types.js.map +1 -0
  171. package/dist/browser/publications/community-edit/community-edit.d.ts +35 -0
  172. package/dist/browser/publications/community-edit/community-edit.js +50 -0
  173. package/dist/browser/publications/community-edit/community-edit.js.map +1 -0
  174. package/dist/browser/publications/community-edit/schema.d.ts +467 -0
  175. package/dist/browser/publications/community-edit/schema.js +36 -0
  176. package/dist/browser/publications/community-edit/schema.js.map +1 -0
  177. package/dist/browser/publications/community-edit/types.d.ts +19 -0
  178. package/dist/browser/publications/community-edit/types.js +2 -0
  179. package/dist/browser/publications/community-edit/types.js.map +1 -0
  180. package/dist/browser/publications/publication-author.d.ts +22 -0
  181. package/dist/browser/publications/publication-author.js +66 -0
  182. package/dist/browser/publications/publication-author.js.map +1 -0
  183. package/dist/browser/publications/publication-client-manager.d.ts +62 -0
  184. package/dist/browser/publications/publication-client-manager.js +257 -0
  185. package/dist/browser/publications/publication-client-manager.js.map +1 -0
  186. package/dist/browser/publications/publication-clients.d.ts +19 -0
  187. package/dist/browser/publications/publication-clients.js +12 -0
  188. package/dist/browser/publications/publication-clients.js.map +1 -0
  189. package/dist/browser/publications/publication-community.d.ts +55 -0
  190. package/dist/browser/publications/publication-community.js +87 -0
  191. package/dist/browser/publications/publication-community.js.map +1 -0
  192. package/dist/browser/publications/publication.d.ts +120 -0
  193. package/dist/browser/publications/publication.js +950 -0
  194. package/dist/browser/publications/publication.js.map +1 -0
  195. package/dist/browser/publications/types.d.ts +26 -0
  196. package/dist/browser/publications/types.js +2 -0
  197. package/dist/browser/publications/types.js.map +1 -0
  198. package/dist/browser/publications/vote/schema.d.ts +150 -0
  199. package/dist/browser/publications/vote/schema.js +44 -0
  200. package/dist/browser/publications/vote/schema.js.map +1 -0
  201. package/dist/browser/publications/vote/types.d.ts +21 -0
  202. package/dist/browser/publications/vote/types.js +2 -0
  203. package/dist/browser/publications/vote/types.js.map +1 -0
  204. package/dist/browser/publications/vote/vote.d.ts +36 -0
  205. package/dist/browser/publications/vote/vote.js +49 -0
  206. package/dist/browser/publications/vote/vote.js.map +1 -0
  207. package/dist/browser/pubsub-messages/schema.d.ts +964 -0
  208. package/dist/browser/pubsub-messages/schema.js +98 -0
  209. package/dist/browser/pubsub-messages/schema.js.map +1 -0
  210. package/dist/browser/pubsub-messages/types.d.ts +81 -0
  211. package/dist/browser/pubsub-messages/types.js +2 -0
  212. package/dist/browser/pubsub-messages/types.js.map +1 -0
  213. package/dist/browser/rpc/src/index.d.ts +483 -0
  214. package/dist/browser/rpc/src/index.js +1267 -0
  215. package/dist/browser/rpc/src/index.js.map +1 -0
  216. package/dist/browser/rpc/src/json-rpc-util.d.ts +1 -0
  217. package/dist/browser/rpc/src/json-rpc-util.js +19 -0
  218. package/dist/browser/rpc/src/json-rpc-util.js.map +1 -0
  219. package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +132 -0
  220. package/dist/browser/rpc/src/lib/pkc-js/index.js +29 -0
  221. package/dist/browser/rpc/src/lib/pkc-js/index.js.map +1 -0
  222. package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.d.ts +1 -0
  223. package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.js +472 -0
  224. package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.js.map +1 -0
  225. package/dist/browser/rpc/src/schema.d.ts +843 -0
  226. package/dist/browser/rpc/src/schema.js +28 -0
  227. package/dist/browser/rpc/src/schema.js.map +1 -0
  228. package/dist/browser/rpc/src/types.d.ts +24 -0
  229. package/dist/browser/rpc/src/types.js +2 -0
  230. package/dist/browser/rpc/src/types.js.map +1 -0
  231. package/dist/browser/rpc/src/utils.d.ts +7 -0
  232. package/dist/browser/rpc/src/utils.js +58 -0
  233. package/dist/browser/rpc/src/utils.js.map +1 -0
  234. package/dist/browser/runtime/browser/community/challenges/index.d.ts +6 -0
  235. package/dist/browser/runtime/browser/community/challenges/index.js +7 -0
  236. package/dist/browser/runtime/browser/community/challenges/index.js.map +1 -0
  237. package/dist/browser/runtime/browser/community/local-community.d.ts +3 -0
  238. package/dist/browser/runtime/browser/community/local-community.js +6 -0
  239. package/dist/browser/runtime/browser/community/local-community.js.map +1 -0
  240. package/dist/browser/runtime/browser/db-handler.d.ts +4 -0
  241. package/dist/browser/runtime/browser/db-handler.js +8 -0
  242. package/dist/browser/runtime/browser/db-handler.js.map +1 -0
  243. package/dist/browser/runtime/browser/localforage-lru.d.ts +15 -0
  244. package/dist/browser/runtime/browser/localforage-lru.js +140 -0
  245. package/dist/browser/runtime/browser/localforage-lru.js.map +1 -0
  246. package/dist/browser/runtime/browser/lru-storage.d.ts +14 -0
  247. package/dist/browser/runtime/browser/lru-storage.js +34 -0
  248. package/dist/browser/runtime/browser/lru-storage.js.map +1 -0
  249. package/dist/browser/runtime/browser/native-functions.d.ts +3 -0
  250. package/dist/browser/runtime/browser/native-functions.js +6 -0
  251. package/dist/browser/runtime/browser/native-functions.js.map +1 -0
  252. package/dist/browser/runtime/browser/polyfill.d.ts +3 -0
  253. package/dist/browser/runtime/browser/polyfill.js +37 -0
  254. package/dist/browser/runtime/browser/polyfill.js.map +1 -0
  255. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +1 -0
  256. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +4 -0
  257. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  258. package/dist/browser/runtime/browser/storage.d.ts +13 -0
  259. package/dist/browser/runtime/browser/storage.js +37 -0
  260. package/dist/browser/runtime/browser/storage.js.map +1 -0
  261. package/dist/browser/runtime/browser/util.d.ts +14 -0
  262. package/dist/browser/runtime/browser/util.js +61 -0
  263. package/dist/browser/runtime/browser/util.js.map +1 -0
  264. package/dist/browser/runtime/node/address-rewriter-db.d.ts +31 -0
  265. package/dist/browser/runtime/node/address-rewriter-db.js +156 -0
  266. package/dist/browser/runtime/node/address-rewriter-db.js.map +1 -0
  267. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.d.ts +45 -0
  268. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js +493 -0
  269. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js.map +1 -0
  270. package/dist/browser/runtime/node/community/challenges/exclude/exclude.d.ts +8 -0
  271. package/dist/browser/runtime/node/community/challenges/exclude/exclude.js +280 -0
  272. package/dist/browser/runtime/node/community/challenges/exclude/exclude.js.map +1 -0
  273. package/dist/browser/runtime/node/community/challenges/exclude/index.d.ts +3 -0
  274. package/dist/browser/runtime/node/community/challenges/exclude/index.js +4 -0
  275. package/dist/browser/runtime/node/community/challenges/exclude/index.js.map +1 -0
  276. package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.d.ts +5 -0
  277. package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.js +127 -0
  278. package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.js.map +1 -0
  279. package/dist/browser/runtime/node/community/challenges/exclude/utils.d.ts +13 -0
  280. package/dist/browser/runtime/node/community/challenges/exclude/utils.js +52 -0
  281. package/dist/browser/runtime/node/community/challenges/exclude/utils.js.map +1 -0
  282. package/dist/browser/runtime/node/community/challenges/index.d.ts +32 -0
  283. package/dist/browser/runtime/node/community/challenges/index.js +307 -0
  284. package/dist/browser/runtime/node/community/challenges/index.js.map +1 -0
  285. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.d.ts +5 -0
  286. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.js +118 -0
  287. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.js.map +1 -0
  288. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.d.ts +5 -0
  289. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.js +26 -0
  290. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.js.map +1 -0
  291. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.d.ts +5 -0
  292. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.js +135 -0
  293. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.js.map +1 -0
  294. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.d.ts +5 -0
  295. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.js +66 -0
  296. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.js.map +1 -0
  297. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.d.ts +5 -0
  298. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.js +61 -0
  299. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.js.map +1 -0
  300. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.d.ts +5 -0
  301. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.js +118 -0
  302. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.js.map +1 -0
  303. package/dist/browser/runtime/node/community/db-handler-types.d.ts +19 -0
  304. package/dist/browser/runtime/node/community/db-handler-types.js +2 -0
  305. package/dist/browser/runtime/node/community/db-handler-types.js.map +1 -0
  306. package/dist/browser/runtime/node/community/db-handler.d.ts +226 -0
  307. package/dist/browser/runtime/node/community/db-handler.js +2462 -0
  308. package/dist/browser/runtime/node/community/db-handler.js.map +1 -0
  309. package/dist/browser/runtime/node/community/db-row-parser.d.ts +19 -0
  310. package/dist/browser/runtime/node/community/db-row-parser.js +40 -0
  311. package/dist/browser/runtime/node/community/db-row-parser.js.map +1 -0
  312. package/dist/browser/runtime/node/community/keyv-better-sqlite3.d.ts +68 -0
  313. package/dist/browser/runtime/node/community/keyv-better-sqlite3.js +251 -0
  314. package/dist/browser/runtime/node/community/keyv-better-sqlite3.js.map +1 -0
  315. package/dist/browser/runtime/node/community/local-community.d.ts +129 -0
  316. package/dist/browser/runtime/node/community/local-community.js +2978 -0
  317. package/dist/browser/runtime/node/community/local-community.js.map +1 -0
  318. package/dist/browser/runtime/node/community/page-generator.d.ts +433 -0
  319. package/dist/browser/runtime/node/community/page-generator.js +441 -0
  320. package/dist/browser/runtime/node/community/page-generator.js.map +1 -0
  321. package/dist/browser/runtime/node/lru-storage.d.ts +14 -0
  322. package/dist/browser/runtime/node/lru-storage.js +40 -0
  323. package/dist/browser/runtime/node/lru-storage.js.map +1 -0
  324. package/dist/browser/runtime/node/native-functions.d.ts +3 -0
  325. package/dist/browser/runtime/node/native-functions.js +7 -0
  326. package/dist/browser/runtime/node/native-functions.js.map +1 -0
  327. package/dist/browser/runtime/node/polyfill.d.ts +3 -0
  328. package/dist/browser/runtime/node/polyfill.js +20 -0
  329. package/dist/browser/runtime/node/polyfill.js.map +1 -0
  330. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +4 -0
  331. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js +240 -0
  332. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  333. package/dist/browser/runtime/node/sqlite-lru-cache.d.ts +52 -0
  334. package/dist/browser/runtime/node/sqlite-lru-cache.js +127 -0
  335. package/dist/browser/runtime/node/sqlite-lru-cache.js.map +1 -0
  336. package/dist/browser/runtime/node/storage.d.ts +14 -0
  337. package/dist/browser/runtime/node/storage.js +52 -0
  338. package/dist/browser/runtime/node/storage.js.map +1 -0
  339. package/dist/browser/runtime/node/test/helpers/hanging-runner.d.ts +1 -0
  340. package/dist/browser/runtime/node/test/helpers/hanging-runner.js +157 -0
  341. package/dist/browser/runtime/node/test/helpers/hanging-runner.js.map +1 -0
  342. package/dist/browser/runtime/node/test/helpers/run-hanging-node.d.ts +7 -0
  343. package/dist/browser/runtime/node/test/helpers/run-hanging-node.js +68 -0
  344. package/dist/browser/runtime/node/test/helpers/run-hanging-node.js.map +1 -0
  345. package/dist/browser/runtime/node/test/mock-http-router.d.ts +54 -0
  346. package/dist/browser/runtime/node/test/mock-http-router.js +397 -0
  347. package/dist/browser/runtime/node/test/mock-http-router.js.map +1 -0
  348. package/dist/browser/runtime/node/util.d.ts +43 -0
  349. package/dist/browser/runtime/node/util.js +384 -0
  350. package/dist/browser/runtime/node/util.js.map +1 -0
  351. package/dist/browser/schema/schema-util.d.ts +2751 -0
  352. package/dist/browser/schema/schema-util.js +562 -0
  353. package/dist/browser/schema/schema-util.js.map +1 -0
  354. package/dist/browser/schema/schema.d.ts +237 -0
  355. package/dist/browser/schema/schema.js +128 -0
  356. package/dist/browser/schema/schema.js.map +1 -0
  357. package/dist/browser/schema.d.ts +1142 -0
  358. package/dist/browser/schema.js +104 -0
  359. package/dist/browser/schema.js.map +1 -0
  360. package/dist/browser/signer/constants.d.ts +2 -0
  361. package/dist/browser/signer/constants.js +3 -0
  362. package/dist/browser/signer/constants.js.map +1 -0
  363. package/dist/browser/signer/encryption.d.ts +21 -0
  364. package/dist/browser/signer/encryption.js +122 -0
  365. package/dist/browser/signer/encryption.js.map +1 -0
  366. package/dist/browser/signer/index.d.ts +21 -0
  367. package/dist/browser/signer/index.js +49 -0
  368. package/dist/browser/signer/index.js.map +1 -0
  369. package/dist/browser/signer/signatures.d.ts +200 -0
  370. package/dist/browser/signer/signatures.js +594 -0
  371. package/dist/browser/signer/signatures.js.map +1 -0
  372. package/dist/browser/signer/types.d.ts +20 -0
  373. package/dist/browser/signer/types.js +2 -0
  374. package/dist/browser/signer/types.js.map +1 -0
  375. package/dist/browser/signer/util.d.ts +14 -0
  376. package/dist/browser/signer/util.js +156 -0
  377. package/dist/browser/signer/util.js.map +1 -0
  378. package/dist/browser/stats.d.ts +15 -0
  379. package/dist/browser/stats.js +64 -0
  380. package/dist/browser/stats.js.map +1 -0
  381. package/dist/browser/test/mock-ipfs-client.d.ts +34 -0
  382. package/dist/browser/test/mock-ipfs-client.js +208 -0
  383. package/dist/browser/test/mock-ipfs-client.js.map +1 -0
  384. package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.d.ts +8 -0
  385. package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js +21 -0
  386. package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js.map +1 -0
  387. package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.d.ts +8 -0
  388. package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.js +19 -0
  389. package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.js.map +1 -0
  390. package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.d.ts +8 -0
  391. package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.js +22 -0
  392. package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.js.map +1 -0
  393. package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.d.ts +8 -0
  394. package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.js +23 -0
  395. package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.js.map +1 -0
  396. package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.d.ts +8 -0
  397. package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.js +21 -0
  398. package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.js.map +1 -0
  399. package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.d.ts +7 -0
  400. package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.js +15 -0
  401. package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.js.map +1 -0
  402. package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.d.ts +30 -0
  403. package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.js +46 -0
  404. package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.js.map +1 -0
  405. package/dist/browser/test/test-util.d.ts +1019 -0
  406. package/dist/browser/test/test-util.js +1886 -0
  407. package/dist/browser/test/test-util.js.map +1 -0
  408. package/dist/browser/types.d.ts +165 -0
  409. package/dist/browser/types.js +2 -0
  410. package/dist/browser/types.js.map +1 -0
  411. package/dist/browser/util/inflight-fetch-manager.d.ts +11 -0
  412. package/dist/browser/util/inflight-fetch-manager.js +41 -0
  413. package/dist/browser/util/inflight-fetch-manager.js.map +1 -0
  414. package/dist/browser/util.d.ts +120 -0
  415. package/dist/browser/util.js +816 -0
  416. package/dist/browser/util.js.map +1 -0
  417. package/dist/browser/version.d.ts +7 -0
  418. package/dist/browser/version.js +12 -0
  419. package/dist/browser/version.js.map +1 -0
  420. package/dist/browser/zod-error-map.d.ts +1 -0
  421. package/dist/browser/zod-error-map.js +10 -0
  422. package/dist/browser/zod-error-map.js.map +1 -0
  423. package/dist/node/challenges.d.ts +1 -0
  424. package/dist/node/challenges.js +2 -0
  425. package/dist/node/challenges.js.map +1 -0
  426. package/dist/node/clients/base-client-manager.d.ts +126 -0
  427. package/dist/node/clients/base-client-manager.js +673 -0
  428. package/dist/node/clients/base-client-manager.js.map +1 -0
  429. package/dist/node/clients/name-resolver-client.d.ts +8 -0
  430. package/dist/node/clients/name-resolver-client.js +10 -0
  431. package/dist/node/clients/name-resolver-client.js.map +1 -0
  432. package/dist/node/clients/pkc-typed-emitter.d.ts +9 -0
  433. package/dist/node/clients/pkc-typed-emitter.js +52 -0
  434. package/dist/node/clients/pkc-typed-emitter.js.map +1 -0
  435. package/dist/node/clients/rpc-client/decode-rpc-response-util.d.ts +8 -0
  436. package/dist/node/clients/rpc-client/decode-rpc-response-util.js +53 -0
  437. package/dist/node/clients/rpc-client/decode-rpc-response-util.js.map +1 -0
  438. package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +68 -0
  439. package/dist/node/clients/rpc-client/pkc-rpc-client.js +404 -0
  440. package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -0
  441. package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +147 -0
  442. package/dist/node/clients/rpc-client/rpc-schema-util.js +11 -0
  443. package/dist/node/clients/rpc-client/rpc-schema-util.js.map +1 -0
  444. package/dist/node/clients/rpc-client/schema.d.ts +433 -0
  445. package/dist/node/clients/rpc-client/schema.js +49 -0
  446. package/dist/node/clients/rpc-client/schema.js.map +1 -0
  447. package/dist/node/clients/rpc-client/types.d.ts +8 -0
  448. package/dist/node/clients/rpc-client/types.js +2 -0
  449. package/dist/node/clients/rpc-client/types.js.map +1 -0
  450. package/dist/node/community/community-client-manager.d.ts +60 -0
  451. package/dist/node/community/community-client-manager.js +717 -0
  452. package/dist/node/community/community-client-manager.js.map +1 -0
  453. package/dist/node/community/community-clients.d.ts +18 -0
  454. package/dist/node/community/community-clients.js +12 -0
  455. package/dist/node/community/community-clients.js.map +1 -0
  456. package/dist/node/community/community-wire.d.ts +20 -0
  457. package/dist/node/community/community-wire.js +38 -0
  458. package/dist/node/community/community-wire.js.map +1 -0
  459. package/dist/node/community/remote-community.d.ts +110 -0
  460. package/dist/node/community/remote-community.js +555 -0
  461. package/dist/node/community/remote-community.js.map +1 -0
  462. package/dist/node/community/rpc-local-community.d.ts +41 -0
  463. package/dist/node/community/rpc-local-community.js +289 -0
  464. package/dist/node/community/rpc-local-community.js.map +1 -0
  465. package/dist/node/community/rpc-remote-community.d.ts +18 -0
  466. package/dist/node/community/rpc-remote-community.js +286 -0
  467. package/dist/node/community/rpc-remote-community.js.map +1 -0
  468. package/dist/node/community/schema.d.ts +4217 -0
  469. package/dist/node/community/schema.js +289 -0
  470. package/dist/node/community/schema.js.map +1 -0
  471. package/dist/node/community/types.d.ts +135 -0
  472. package/dist/node/community/types.js +2 -0
  473. package/dist/node/community/types.js.map +1 -0
  474. package/dist/node/constants.d.ts +6 -0
  475. package/dist/node/constants.js +9 -0
  476. package/dist/node/constants.js.map +1 -0
  477. package/dist/node/decorator-util.d.ts +1 -0
  478. package/dist/node/decorator-util.js +35 -0
  479. package/dist/node/decorator-util.js.map +1 -0
  480. package/dist/node/errors.d.ts +343 -0
  481. package/dist/node/errors.js +358 -0
  482. package/dist/node/errors.js.map +1 -0
  483. package/dist/node/general-util/limited-set.d.ts +15 -0
  484. package/dist/node/general-util/limited-set.js +66 -0
  485. package/dist/node/general-util/limited-set.js.map +1 -0
  486. package/dist/node/generated-version.d.ts +1 -0
  487. package/dist/node/generated-version.js +3 -0
  488. package/dist/node/generated-version.js.map +1 -0
  489. package/dist/node/generic-state-client.d.ts +6 -0
  490. package/dist/node/generic-state-client.js +11 -0
  491. package/dist/node/generic-state-client.js.map +1 -0
  492. package/dist/node/helia/helia-for-pkc.d.ts +3 -0
  493. package/dist/node/helia/helia-for-pkc.js +255 -0
  494. package/dist/node/helia/helia-for-pkc.js.map +1 -0
  495. package/dist/node/helia/ipns-over-pubsub-with-fetch.d.ts +36 -0
  496. package/dist/node/helia/ipns-over-pubsub-with-fetch.js +229 -0
  497. package/dist/node/helia/ipns-over-pubsub-with-fetch.js.map +1 -0
  498. package/dist/node/helia/libp2pjsClient.d.ts +27 -0
  499. package/dist/node/helia/libp2pjsClient.js +15 -0
  500. package/dist/node/helia/libp2pjsClient.js.map +1 -0
  501. package/dist/node/helia/types.d.ts +19 -0
  502. package/dist/node/helia/types.js +2 -0
  503. package/dist/node/helia/types.js.map +1 -0
  504. package/dist/node/helia/util.d.ts +13 -0
  505. package/dist/node/helia/util.js +98 -0
  506. package/dist/node/helia/util.js.map +1 -0
  507. package/dist/node/index.d.ts +244 -0
  508. package/dist/node/index.js +36 -0
  509. package/dist/node/index.js.map +1 -0
  510. package/dist/node/logger.d.ts +12 -0
  511. package/dist/node/logger.js +11 -0
  512. package/dist/node/logger.js.map +1 -0
  513. package/dist/node/pages/pages-client-manager.d.ts +159 -0
  514. package/dist/node/pages/pages-client-manager.js +334 -0
  515. package/dist/node/pages/pages-client-manager.js.map +1 -0
  516. package/dist/node/pages/pages-clients.d.ts +11 -0
  517. package/dist/node/pages/pages-clients.js +10 -0
  518. package/dist/node/pages/pages-clients.js.map +1 -0
  519. package/dist/node/pages/pages.d.ts +107 -0
  520. package/dist/node/pages/pages.js +262 -0
  521. package/dist/node/pages/pages.js.map +1 -0
  522. package/dist/node/pages/schema-util.d.ts +3 -0
  523. package/dist/node/pages/schema-util.js +3 -0
  524. package/dist/node/pages/schema-util.js.map +1 -0
  525. package/dist/node/pages/schema.d.ts +719 -0
  526. package/dist/node/pages/schema.js +32 -0
  527. package/dist/node/pages/schema.js.map +1 -0
  528. package/dist/node/pages/types.d.ts +44 -0
  529. package/dist/node/pages/types.js +2 -0
  530. package/dist/node/pages/types.js.map +1 -0
  531. package/dist/node/pages/util.d.ts +56 -0
  532. package/dist/node/pages/util.js +446 -0
  533. package/dist/node/pages/util.js.map +1 -0
  534. package/dist/node/pkc/pkc-client-manager.d.ts +44 -0
  535. package/dist/node/pkc/pkc-client-manager.js +156 -0
  536. package/dist/node/pkc/pkc-client-manager.js.map +1 -0
  537. package/dist/node/pkc/pkc-clients.d.ts +11 -0
  538. package/dist/node/pkc/pkc-clients.js +8 -0
  539. package/dist/node/pkc/pkc-clients.js.map +1 -0
  540. package/dist/node/pkc/pkc-with-rpc-client.d.ts +19 -0
  541. package/dist/node/pkc/pkc-with-rpc-client.js +128 -0
  542. package/dist/node/pkc/pkc-with-rpc-client.js.map +1 -0
  543. package/dist/node/pkc/pkc.d.ts +137 -0
  544. package/dist/node/pkc/pkc.js +888 -0
  545. package/dist/node/pkc/pkc.js.map +1 -0
  546. package/dist/node/pkc/tracked-instance-registry-util.d.ts +44 -0
  547. package/dist/node/pkc/tracked-instance-registry-util.js +106 -0
  548. package/dist/node/pkc/tracked-instance-registry-util.js.map +1 -0
  549. package/dist/node/pkc/tracked-instance-registry.d.ts +18 -0
  550. package/dist/node/pkc/tracked-instance-registry.js +134 -0
  551. package/dist/node/pkc/tracked-instance-registry.js.map +1 -0
  552. package/dist/node/pkc-error.d.ts +65 -0
  553. package/dist/node/pkc-error.js +137 -0
  554. package/dist/node/pkc-error.js.map +1 -0
  555. package/dist/node/publications/comment/comment-client-manager.d.ts +86 -0
  556. package/dist/node/publications/comment/comment-client-manager.js +908 -0
  557. package/dist/node/publications/comment/comment-client-manager.js.map +1 -0
  558. package/dist/node/publications/comment/comment-clients.d.ts +19 -0
  559. package/dist/node/publications/comment/comment-clients.js +12 -0
  560. package/dist/node/publications/comment/comment-clients.js.map +1 -0
  561. package/dist/node/publications/comment/comment-util.d.ts +10 -0
  562. package/dist/node/publications/comment/comment-util.js +202 -0
  563. package/dist/node/publications/comment/comment-util.js.map +1 -0
  564. package/dist/node/publications/comment/comment.d.ts +147 -0
  565. package/dist/node/publications/comment/comment.js +1044 -0
  566. package/dist/node/publications/comment/comment.js.map +1 -0
  567. package/dist/node/publications/comment/schema.d.ts +1237 -0
  568. package/dist/node/publications/comment/schema.js +184 -0
  569. package/dist/node/publications/comment/schema.js.map +1 -0
  570. package/dist/node/publications/comment/types.d.ts +100 -0
  571. package/dist/node/publications/comment/types.js +2 -0
  572. package/dist/node/publications/comment/types.js.map +1 -0
  573. package/dist/node/publications/comment-edit/comment-edit.d.ts +41 -0
  574. package/dist/node/publications/comment-edit/comment-edit.js +63 -0
  575. package/dist/node/publications/comment-edit/comment-edit.js.map +1 -0
  576. package/dist/node/publications/comment-edit/schema.d.ts +295 -0
  577. package/dist/node/publications/comment-edit/schema.js +55 -0
  578. package/dist/node/publications/comment-edit/schema.js.map +1 -0
  579. package/dist/node/publications/comment-edit/types.d.ts +25 -0
  580. package/dist/node/publications/comment-edit/types.js +2 -0
  581. package/dist/node/publications/comment-edit/types.js.map +1 -0
  582. package/dist/node/publications/comment-moderation/comment-moderation.d.ts +36 -0
  583. package/dist/node/publications/comment-moderation/comment-moderation.js +53 -0
  584. package/dist/node/publications/comment-moderation/comment-moderation.js.map +1 -0
  585. package/dist/node/publications/comment-moderation/schema.d.ts +315 -0
  586. package/dist/node/publications/comment-moderation/schema.js +62 -0
  587. package/dist/node/publications/comment-moderation/schema.js.map +1 -0
  588. package/dist/node/publications/comment-moderation/types.d.ts +22 -0
  589. package/dist/node/publications/comment-moderation/types.js +2 -0
  590. package/dist/node/publications/comment-moderation/types.js.map +1 -0
  591. package/dist/node/publications/community-edit/community-edit.d.ts +35 -0
  592. package/dist/node/publications/community-edit/community-edit.js +50 -0
  593. package/dist/node/publications/community-edit/community-edit.js.map +1 -0
  594. package/dist/node/publications/community-edit/schema.d.ts +467 -0
  595. package/dist/node/publications/community-edit/schema.js +36 -0
  596. package/dist/node/publications/community-edit/schema.js.map +1 -0
  597. package/dist/node/publications/community-edit/types.d.ts +19 -0
  598. package/dist/node/publications/community-edit/types.js +2 -0
  599. package/dist/node/publications/community-edit/types.js.map +1 -0
  600. package/dist/node/publications/publication-author.d.ts +22 -0
  601. package/dist/node/publications/publication-author.js +66 -0
  602. package/dist/node/publications/publication-author.js.map +1 -0
  603. package/dist/node/publications/publication-client-manager.d.ts +62 -0
  604. package/dist/node/publications/publication-client-manager.js +257 -0
  605. package/dist/node/publications/publication-client-manager.js.map +1 -0
  606. package/dist/node/publications/publication-clients.d.ts +19 -0
  607. package/dist/node/publications/publication-clients.js +12 -0
  608. package/dist/node/publications/publication-clients.js.map +1 -0
  609. package/dist/node/publications/publication-community.d.ts +55 -0
  610. package/dist/node/publications/publication-community.js +87 -0
  611. package/dist/node/publications/publication-community.js.map +1 -0
  612. package/dist/node/publications/publication.d.ts +120 -0
  613. package/dist/node/publications/publication.js +950 -0
  614. package/dist/node/publications/publication.js.map +1 -0
  615. package/dist/node/publications/types.d.ts +26 -0
  616. package/dist/node/publications/types.js +2 -0
  617. package/dist/node/publications/types.js.map +1 -0
  618. package/dist/node/publications/vote/schema.d.ts +150 -0
  619. package/dist/node/publications/vote/schema.js +44 -0
  620. package/dist/node/publications/vote/schema.js.map +1 -0
  621. package/dist/node/publications/vote/types.d.ts +21 -0
  622. package/dist/node/publications/vote/types.js +2 -0
  623. package/dist/node/publications/vote/types.js.map +1 -0
  624. package/dist/node/publications/vote/vote.d.ts +36 -0
  625. package/dist/node/publications/vote/vote.js +49 -0
  626. package/dist/node/publications/vote/vote.js.map +1 -0
  627. package/dist/node/pubsub-messages/schema.d.ts +964 -0
  628. package/dist/node/pubsub-messages/schema.js +98 -0
  629. package/dist/node/pubsub-messages/schema.js.map +1 -0
  630. package/dist/node/pubsub-messages/types.d.ts +81 -0
  631. package/dist/node/pubsub-messages/types.js +2 -0
  632. package/dist/node/pubsub-messages/types.js.map +1 -0
  633. package/dist/node/rpc/src/index.d.ts +483 -0
  634. package/dist/node/rpc/src/index.js +1267 -0
  635. package/dist/node/rpc/src/index.js.map +1 -0
  636. package/dist/node/rpc/src/json-rpc-util.d.ts +1 -0
  637. package/dist/node/rpc/src/json-rpc-util.js +19 -0
  638. package/dist/node/rpc/src/json-rpc-util.js.map +1 -0
  639. package/dist/node/rpc/src/lib/pkc-js/index.d.ts +132 -0
  640. package/dist/node/rpc/src/lib/pkc-js/index.js +29 -0
  641. package/dist/node/rpc/src/lib/pkc-js/index.js.map +1 -0
  642. package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.d.ts +1 -0
  643. package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.js +472 -0
  644. package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.js.map +1 -0
  645. package/dist/node/rpc/src/schema.d.ts +843 -0
  646. package/dist/node/rpc/src/schema.js +28 -0
  647. package/dist/node/rpc/src/schema.js.map +1 -0
  648. package/dist/node/rpc/src/types.d.ts +24 -0
  649. package/dist/node/rpc/src/types.js +2 -0
  650. package/dist/node/rpc/src/types.js.map +1 -0
  651. package/dist/node/rpc/src/utils.d.ts +7 -0
  652. package/dist/node/rpc/src/utils.js +58 -0
  653. package/dist/node/rpc/src/utils.js.map +1 -0
  654. package/dist/node/runtime/browser/community/challenges/index.d.ts +6 -0
  655. package/dist/node/runtime/browser/community/challenges/index.js +7 -0
  656. package/dist/node/runtime/browser/community/challenges/index.js.map +1 -0
  657. package/dist/node/runtime/browser/community/local-community.d.ts +3 -0
  658. package/dist/node/runtime/browser/community/local-community.js +6 -0
  659. package/dist/node/runtime/browser/community/local-community.js.map +1 -0
  660. package/dist/node/runtime/browser/db-handler.d.ts +4 -0
  661. package/dist/node/runtime/browser/db-handler.js +8 -0
  662. package/dist/node/runtime/browser/db-handler.js.map +1 -0
  663. package/dist/node/runtime/browser/localforage-lru.d.ts +15 -0
  664. package/dist/node/runtime/browser/localforage-lru.js +140 -0
  665. package/dist/node/runtime/browser/localforage-lru.js.map +1 -0
  666. package/dist/node/runtime/browser/lru-storage.d.ts +14 -0
  667. package/dist/node/runtime/browser/lru-storage.js +34 -0
  668. package/dist/node/runtime/browser/lru-storage.js.map +1 -0
  669. package/dist/node/runtime/browser/native-functions.d.ts +3 -0
  670. package/dist/node/runtime/browser/native-functions.js +6 -0
  671. package/dist/node/runtime/browser/native-functions.js.map +1 -0
  672. package/dist/node/runtime/browser/polyfill.d.ts +3 -0
  673. package/dist/node/runtime/browser/polyfill.js +37 -0
  674. package/dist/node/runtime/browser/polyfill.js.map +1 -0
  675. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +1 -0
  676. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +4 -0
  677. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  678. package/dist/node/runtime/browser/storage.d.ts +13 -0
  679. package/dist/node/runtime/browser/storage.js +37 -0
  680. package/dist/node/runtime/browser/storage.js.map +1 -0
  681. package/dist/node/runtime/browser/util.d.ts +14 -0
  682. package/dist/node/runtime/browser/util.js +61 -0
  683. package/dist/node/runtime/browser/util.js.map +1 -0
  684. package/dist/node/runtime/node/address-rewriter-db.d.ts +31 -0
  685. package/dist/node/runtime/node/address-rewriter-db.js +156 -0
  686. package/dist/node/runtime/node/address-rewriter-db.js.map +1 -0
  687. package/dist/node/runtime/node/addresses-rewriter-proxy-server.d.ts +45 -0
  688. package/dist/node/runtime/node/addresses-rewriter-proxy-server.js +493 -0
  689. package/dist/node/runtime/node/addresses-rewriter-proxy-server.js.map +1 -0
  690. package/dist/node/runtime/node/community/challenges/exclude/exclude.d.ts +8 -0
  691. package/dist/node/runtime/node/community/challenges/exclude/exclude.js +280 -0
  692. package/dist/node/runtime/node/community/challenges/exclude/exclude.js.map +1 -0
  693. package/dist/node/runtime/node/community/challenges/exclude/index.d.ts +3 -0
  694. package/dist/node/runtime/node/community/challenges/exclude/index.js +4 -0
  695. package/dist/node/runtime/node/community/challenges/exclude/index.js.map +1 -0
  696. package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.d.ts +5 -0
  697. package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.js +127 -0
  698. package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.js.map +1 -0
  699. package/dist/node/runtime/node/community/challenges/exclude/utils.d.ts +13 -0
  700. package/dist/node/runtime/node/community/challenges/exclude/utils.js +52 -0
  701. package/dist/node/runtime/node/community/challenges/exclude/utils.js.map +1 -0
  702. package/dist/node/runtime/node/community/challenges/index.d.ts +32 -0
  703. package/dist/node/runtime/node/community/challenges/index.js +307 -0
  704. package/dist/node/runtime/node/community/challenges/index.js.map +1 -0
  705. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.d.ts +5 -0
  706. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.js +118 -0
  707. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.js.map +1 -0
  708. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.d.ts +5 -0
  709. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.js +26 -0
  710. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.js.map +1 -0
  711. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.d.ts +5 -0
  712. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.js +135 -0
  713. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.js.map +1 -0
  714. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.d.ts +5 -0
  715. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.js +66 -0
  716. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.js.map +1 -0
  717. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.d.ts +5 -0
  718. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.js +61 -0
  719. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.js.map +1 -0
  720. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.d.ts +5 -0
  721. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.js +118 -0
  722. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.js.map +1 -0
  723. package/dist/node/runtime/node/community/db-handler-types.d.ts +19 -0
  724. package/dist/node/runtime/node/community/db-handler-types.js +2 -0
  725. package/dist/node/runtime/node/community/db-handler-types.js.map +1 -0
  726. package/dist/node/runtime/node/community/db-handler.d.ts +226 -0
  727. package/dist/node/runtime/node/community/db-handler.js +2462 -0
  728. package/dist/node/runtime/node/community/db-handler.js.map +1 -0
  729. package/dist/node/runtime/node/community/db-row-parser.d.ts +19 -0
  730. package/dist/node/runtime/node/community/db-row-parser.js +40 -0
  731. package/dist/node/runtime/node/community/db-row-parser.js.map +1 -0
  732. package/dist/node/runtime/node/community/keyv-better-sqlite3.d.ts +68 -0
  733. package/dist/node/runtime/node/community/keyv-better-sqlite3.js +251 -0
  734. package/dist/node/runtime/node/community/keyv-better-sqlite3.js.map +1 -0
  735. package/dist/node/runtime/node/community/local-community.d.ts +129 -0
  736. package/dist/node/runtime/node/community/local-community.js +2978 -0
  737. package/dist/node/runtime/node/community/local-community.js.map +1 -0
  738. package/dist/node/runtime/node/community/page-generator.d.ts +433 -0
  739. package/dist/node/runtime/node/community/page-generator.js +441 -0
  740. package/dist/node/runtime/node/community/page-generator.js.map +1 -0
  741. package/dist/node/runtime/node/lru-storage.d.ts +14 -0
  742. package/dist/node/runtime/node/lru-storage.js +40 -0
  743. package/dist/node/runtime/node/lru-storage.js.map +1 -0
  744. package/dist/node/runtime/node/native-functions.d.ts +3 -0
  745. package/dist/node/runtime/node/native-functions.js +7 -0
  746. package/dist/node/runtime/node/native-functions.js.map +1 -0
  747. package/dist/node/runtime/node/polyfill.d.ts +3 -0
  748. package/dist/node/runtime/node/polyfill.js +20 -0
  749. package/dist/node/runtime/node/polyfill.js.map +1 -0
  750. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +4 -0
  751. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js +240 -0
  752. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  753. package/dist/node/runtime/node/sqlite-lru-cache.d.ts +52 -0
  754. package/dist/node/runtime/node/sqlite-lru-cache.js +127 -0
  755. package/dist/node/runtime/node/sqlite-lru-cache.js.map +1 -0
  756. package/dist/node/runtime/node/storage.d.ts +14 -0
  757. package/dist/node/runtime/node/storage.js +52 -0
  758. package/dist/node/runtime/node/storage.js.map +1 -0
  759. package/dist/node/runtime/node/test/helpers/hanging-runner.d.ts +1 -0
  760. package/dist/node/runtime/node/test/helpers/hanging-runner.js +157 -0
  761. package/dist/node/runtime/node/test/helpers/hanging-runner.js.map +1 -0
  762. package/dist/node/runtime/node/test/helpers/run-hanging-node.d.ts +7 -0
  763. package/dist/node/runtime/node/test/helpers/run-hanging-node.js +68 -0
  764. package/dist/node/runtime/node/test/helpers/run-hanging-node.js.map +1 -0
  765. package/dist/node/runtime/node/test/mock-http-router.d.ts +54 -0
  766. package/dist/node/runtime/node/test/mock-http-router.js +397 -0
  767. package/dist/node/runtime/node/test/mock-http-router.js.map +1 -0
  768. package/dist/node/runtime/node/util.d.ts +43 -0
  769. package/dist/node/runtime/node/util.js +384 -0
  770. package/dist/node/runtime/node/util.js.map +1 -0
  771. package/dist/node/schema/schema-util.d.ts +2751 -0
  772. package/dist/node/schema/schema-util.js +562 -0
  773. package/dist/node/schema/schema-util.js.map +1 -0
  774. package/dist/node/schema/schema.d.ts +237 -0
  775. package/dist/node/schema/schema.js +128 -0
  776. package/dist/node/schema/schema.js.map +1 -0
  777. package/dist/node/schema.d.ts +1142 -0
  778. package/dist/node/schema.js +104 -0
  779. package/dist/node/schema.js.map +1 -0
  780. package/dist/node/signer/constants.d.ts +2 -0
  781. package/dist/node/signer/constants.js +3 -0
  782. package/dist/node/signer/constants.js.map +1 -0
  783. package/dist/node/signer/encryption.d.ts +21 -0
  784. package/dist/node/signer/encryption.js +122 -0
  785. package/dist/node/signer/encryption.js.map +1 -0
  786. package/dist/node/signer/index.d.ts +21 -0
  787. package/dist/node/signer/index.js +49 -0
  788. package/dist/node/signer/index.js.map +1 -0
  789. package/dist/node/signer/signatures.d.ts +200 -0
  790. package/dist/node/signer/signatures.js +594 -0
  791. package/dist/node/signer/signatures.js.map +1 -0
  792. package/dist/node/signer/types.d.ts +20 -0
  793. package/dist/node/signer/types.js +2 -0
  794. package/dist/node/signer/types.js.map +1 -0
  795. package/dist/node/signer/util.d.ts +14 -0
  796. package/dist/node/signer/util.js +156 -0
  797. package/dist/node/signer/util.js.map +1 -0
  798. package/dist/node/stats.d.ts +15 -0
  799. package/dist/node/stats.js +64 -0
  800. package/dist/node/stats.js.map +1 -0
  801. package/dist/node/test/mock-ipfs-client.d.ts +34 -0
  802. package/dist/node/test/mock-ipfs-client.js +208 -0
  803. package/dist/node/test/mock-ipfs-client.js.map +1 -0
  804. package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.d.ts +8 -0
  805. package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js +21 -0
  806. package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js.map +1 -0
  807. package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.d.ts +8 -0
  808. package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.js +19 -0
  809. package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.js.map +1 -0
  810. package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.d.ts +8 -0
  811. package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.js +22 -0
  812. package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.js.map +1 -0
  813. package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.d.ts +8 -0
  814. package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.js +23 -0
  815. package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.js.map +1 -0
  816. package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.d.ts +8 -0
  817. package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.js +21 -0
  818. package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.js.map +1 -0
  819. package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.d.ts +7 -0
  820. package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.js +15 -0
  821. package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.js.map +1 -0
  822. package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.d.ts +30 -0
  823. package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.js +46 -0
  824. package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.js.map +1 -0
  825. package/dist/node/test/test-util.d.ts +1019 -0
  826. package/dist/node/test/test-util.js +1886 -0
  827. package/dist/node/test/test-util.js.map +1 -0
  828. package/dist/node/types.d.ts +165 -0
  829. package/dist/node/types.js +2 -0
  830. package/dist/node/types.js.map +1 -0
  831. package/dist/node/util/inflight-fetch-manager.d.ts +11 -0
  832. package/dist/node/util/inflight-fetch-manager.js +41 -0
  833. package/dist/node/util/inflight-fetch-manager.js.map +1 -0
  834. package/dist/node/util.d.ts +120 -0
  835. package/dist/node/util.js +816 -0
  836. package/dist/node/util.js.map +1 -0
  837. package/dist/node/version.d.ts +7 -0
  838. package/dist/node/version.js +12 -0
  839. package/dist/node/version.js.map +1 -0
  840. package/dist/node/zod-error-map.d.ts +1 -0
  841. package/dist/node/zod-error-map.js +10 -0
  842. package/dist/node/zod-error-map.js.map +1 -0
  843. package/package.json +212 -0
@@ -0,0 +1,908 @@
1
+ import * as remeda from "remeda";
2
+ import { parseCommentIpfsSchemaWithPKCErrorIfItFails, parseCommentUpdateSchemaWithPKCErrorIfItFails, parseJsonWithPKCErrorIfFails } from "../../schema/schema-util.js";
3
+ import { FailedToFetchCommentUpdateFromGatewaysError, PKCError } from "../../pkc-error.js";
4
+ import { verifyCommentIpfs, verifyCommentUpdate } from "../../signer/signatures.js";
5
+ import Logger from "../../logger.js";
6
+ import { getPostUpdateTimestampRange, hideClassPrivateProps, isAbortError, resolveWhenPredicateIsTrue } from "../../util.js";
7
+ import { PublicationClientsManager } from "../publication-client-manager.js";
8
+ import { findCommentInPageInstance, findCommentInPageInstanceRecursively, findCommentInParsedPages } from "../../pages/util.js";
9
+ import { CommentKuboRpcClient, CommentLibp2pJsClient, CommentPKCRpcStateClient } from "./comment-clients.js";
10
+ import { InflightResourceTypes } from "../../util/inflight-fetch-manager.js";
11
+ import { loadAllPagesUnderCommunityToFindComment } from "./comment-util.js";
12
+ import { findStartedCommunity, findUpdatingComment, findUpdatingCommunity } from "../../pkc/tracked-instance-registry-util.js";
13
+ const fetchCommentLogger = Logger("pkc-js:comment:client-manager:fetchAndVerifyCommentCid");
14
+ export const MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE = 1024 * 1024;
15
+ export class CommentClientsManager extends PublicationClientsManager {
16
+ constructor(comment) {
17
+ super(comment);
18
+ this._postForUpdating = undefined;
19
+ this._comment = comment;
20
+ this._fetchingUpdateForReplyUsingPageCidsPromise = undefined;
21
+ this._parentFirstPageCidsAlreadyLoaded = new Set();
22
+ hideClassPrivateProps(this);
23
+ }
24
+ _initKuboRpcClients() {
25
+ if (this._pkc.clients.kuboRpcClients)
26
+ for (const ipfsUrl of remeda.keys.strict(this._pkc.clients.kuboRpcClients))
27
+ this.clients.kuboRpcClients = { ...this.clients.kuboRpcClients, [ipfsUrl]: new CommentKuboRpcClient("stopped") };
28
+ }
29
+ _initLibp2pJsClients() {
30
+ for (const libp2pJsClientKey of remeda.keys.strict(this._pkc.clients.libp2pJsClients))
31
+ this.clients.libp2pJsClients = { ...this.clients.libp2pJsClients, [libp2pJsClientKey]: new CommentLibp2pJsClient("stopped") };
32
+ }
33
+ _initPKCRpcClients() {
34
+ for (const rpcUrl of remeda.keys.strict(this._pkc.clients.pkcRpcClients))
35
+ this.clients.pkcRpcClients = { ...this.clients.pkcRpcClients, [rpcUrl]: new CommentPKCRpcStateClient("stopped") };
36
+ }
37
+ updateLibp2pJsClientState(newState, libp2pJsClientKey) {
38
+ super.updateLibp2pJsClientState(newState, libp2pJsClientKey);
39
+ }
40
+ updateKuboRpcState(newState, kuboRpcClientUrl) {
41
+ super.updateKuboRpcState(newState, kuboRpcClientUrl);
42
+ }
43
+ updateGatewayState(newState, ipfsGatewayClientUrl) {
44
+ super.updateGatewayState(newState, ipfsGatewayClientUrl);
45
+ }
46
+ updateKuboRpcPubsubState(newState, pubsubKuboRpcClientUrl) {
47
+ super.updateKuboRpcPubsubState(newState, pubsubKuboRpcClientUrl);
48
+ }
49
+ // Resolver methods here
50
+ preResolveNameResolver(opts) {
51
+ super.preResolveNameResolver(opts);
52
+ if (this._comment.state === "updating")
53
+ this._comment._setUpdatingStateWithEmissionIfNewState("resolving-author-name"); // Resolving for CommentIpfs and author.address is a domain
54
+ }
55
+ _calculatePathForPostCommentUpdate(folderCid, postCid) {
56
+ return `${folderCid}/` + postCid + "/update";
57
+ }
58
+ _updateKuboRpcClientOrHeliaState(newState, kuboRpcOrHelia) {
59
+ if ("_helia" in kuboRpcOrHelia)
60
+ this.updateLibp2pJsClientState(newState, kuboRpcOrHelia._libp2pJsClientsOptions.key);
61
+ else
62
+ this.updateKuboRpcState(newState, kuboRpcOrHelia.url);
63
+ }
64
+ async _fetchPostCommentUpdateIpfsP2P(subIpns, timestampRanges, log) {
65
+ // only get new CommentUpdates
66
+ // not interested in CommentUpdate we already fetched before
67
+ const attemptedPathsToLoadErrors = {};
68
+ const kuboRpcOrHelia = this.getDefaultKuboRpcClientOrHelia();
69
+ const didLastPostUpdateRangeHaveSameFolderCid = timestampRanges.some((timestampRange) => {
70
+ if (!this._comment._commentUpdateIpfsPath)
71
+ return false;
72
+ const folderCid = subIpns.postUpdates[timestampRange];
73
+ const lastFolderCid = this._comment._commentUpdateIpfsPath.split("/")[0];
74
+ return folderCid === lastFolderCid;
75
+ });
76
+ if (didLastPostUpdateRangeHaveSameFolderCid) {
77
+ log("Comment", this._comment.cid, "last post update range has same folder cid", this._comment._commentUpdateIpfsPath, "will be skipping loading CommentUpdate");
78
+ return undefined;
79
+ }
80
+ this._comment._setUpdatingStateWithEmissionIfNewState("fetching-update-ipfs");
81
+ for (const timestampRange of timestampRanges) {
82
+ const folderCid = subIpns.postUpdates[timestampRange];
83
+ const path = this._calculatePathForPostCommentUpdate(folderCid, this._comment.postCid);
84
+ this._updateKuboRpcClientOrHeliaState("fetching-update-ipfs", kuboRpcOrHelia);
85
+ let res;
86
+ const commentUpdateTimeoutMs = this._pkc._timeouts["comment-update-ipfs"];
87
+ try {
88
+ res = await this._fetchCidP2P(path, {
89
+ maxFileSizeBytes: MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE,
90
+ timeoutMs: commentUpdateTimeoutMs,
91
+ abortSignal: this._comment._getStopAbortSignal()
92
+ });
93
+ }
94
+ catch (e) {
95
+ // failed to load the record, maybe our node is offline or the content is unreachable
96
+ log.trace(`Failed to fetch CommentUpdate from path (${path}) with IPFS P2P. Trying the next timestamp range`);
97
+ attemptedPathsToLoadErrors[path] = e;
98
+ continue;
99
+ }
100
+ finally {
101
+ this._updateKuboRpcClientOrHeliaState("stopped", kuboRpcOrHelia);
102
+ }
103
+ try {
104
+ const commentUpdate = parseCommentUpdateSchemaWithPKCErrorIfItFails(parseJsonWithPKCErrorIfFails(res));
105
+ await this._throwIfCommentUpdateHasInvalidSignature(commentUpdate, subIpns);
106
+ if (commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0))
107
+ return { commentUpdate, commentUpdateIpfsPath: path };
108
+ else
109
+ return undefined;
110
+ }
111
+ catch (e) {
112
+ // there's a problem with the record itself, could be signature or schema or bad json
113
+ this._comment._invalidCommentUpdateMfsPaths.add(path);
114
+ if (e instanceof PKCError)
115
+ e.details = { ...e.details, commentUpdatePath: path, postCid: this._comment.cid };
116
+ throw e;
117
+ }
118
+ }
119
+ throw new PKCError("ERR_FAILED_TO_FETCH_COMMENT_UPDATE_FROM_ALL_POST_UPDATES_RANGES", {
120
+ timestampRanges,
121
+ attemptedPathsToLoadErrors,
122
+ postCid: this._comment.cid,
123
+ commentDepth: this._comment.depth
124
+ });
125
+ }
126
+ _shouldWeFetchCommentUpdateFromNextTimestamp(err) {
127
+ // Is there a problem with the record itself, or is this an issue with fetching?
128
+ if (!(err instanceof PKCError))
129
+ return false; // If it's not a recognizable error, then we throw to notify the user
130
+ if (err.code === "ERR_COMMENT_UPDATE_SIGNATURE_IS_INVALID" ||
131
+ err.code === "ERR_INVALID_COMMENT_UPDATE_SCHEMA" ||
132
+ err.code === "ERR_OVER_DOWNLOAD_LIMIT" ||
133
+ err.code === "ERR_INVALID_JSON")
134
+ return false; // These errors means there's a problem with the record itself, not the loading
135
+ if (err instanceof FailedToFetchCommentUpdateFromGatewaysError) {
136
+ // If all gateway errors are due to the record itself, then we throw an error and don't jump to the next timestamp
137
+ for (const gatewayError of Object.values(err.details.gatewayToError))
138
+ if (this._shouldWeFetchCommentUpdateFromNextTimestamp(gatewayError))
139
+ return true; // if there's at least one gateway whose error is not due to the record
140
+ return false; // if all gateways have issues with the record validity itself, then we stop fetching
141
+ }
142
+ return true;
143
+ }
144
+ async _throwIfCommentUpdateHasInvalidSignature(commentUpdate, communityIpfs) {
145
+ if (!this._comment.raw.comment)
146
+ throw Error("Can't validate comment update when CommentIpfs hasn't been loaded");
147
+ if (!this._comment.cid)
148
+ throw Error("can't validate comment update when cid is not defined");
149
+ if (!this._comment.postCid)
150
+ throw Error("can't validate comment update when postCid is not defined");
151
+ const verifyOptions = {
152
+ update: commentUpdate,
153
+ resolveAuthorNames: this._pkc.resolveAuthorNames,
154
+ clientsManager: this,
155
+ community: { address: this._comment.communityAddress, signature: communityIpfs.signature },
156
+ comment: { ...this._comment.raw.comment, cid: this._comment.cid, postCid: this._comment.postCid },
157
+ validatePages: this._pkc.validatePages,
158
+ validateUpdateSignature: true,
159
+ abortSignal: this._comment._getStopAbortSignal()
160
+ };
161
+ const signatureValidity = await verifyCommentUpdate(verifyOptions);
162
+ if (!signatureValidity.valid)
163
+ throw new PKCError("ERR_COMMENT_UPDATE_SIGNATURE_IS_INVALID", {
164
+ signatureValidity,
165
+ verifyOptions
166
+ });
167
+ }
168
+ async _fetchPostCommentUpdateFromGateways(subIpns, timestampRanges, log) {
169
+ const didLastPostUpdateRangeHaveSameFolderCid = timestampRanges.some((timestampRange) => {
170
+ if (!this._comment._commentUpdateIpfsPath)
171
+ return false;
172
+ const folderCid = subIpns.postUpdates[timestampRange];
173
+ const lastFolderCid = this._comment._commentUpdateIpfsPath.split("/")[0];
174
+ return folderCid === lastFolderCid;
175
+ });
176
+ if (didLastPostUpdateRangeHaveSameFolderCid) {
177
+ log("Comment", this._comment.cid, "last post update range has same folder cid", this._comment._commentUpdateIpfsPath, "will be skipping loading CommentUpdate");
178
+ return undefined;
179
+ }
180
+ const attemptedPathsToLoadErrors = {};
181
+ let commentUpdate;
182
+ const validateCommentFromGateway = async (res) => {
183
+ if (typeof res.resText !== "string")
184
+ throw Error("Gateway response has no body");
185
+ const commentUpdateBeforeSignature = parseCommentUpdateSchemaWithPKCErrorIfItFails(parseJsonWithPKCErrorIfFails(res.resText));
186
+ await this._throwIfCommentUpdateHasInvalidSignature(commentUpdateBeforeSignature, subIpns);
187
+ commentUpdate = commentUpdateBeforeSignature; // at this point, we know the gateway has provided a valid comment update and we can use it
188
+ };
189
+ this._comment._setUpdatingStateWithEmissionIfNewState("fetching-update-ipfs");
190
+ for (const timestampRange of timestampRanges) {
191
+ // We're validating schema and signature here for every gateway because it's not a regular cid whose content we can verify to match the cid
192
+ const folderCid = subIpns.postUpdates[timestampRange];
193
+ const path = this._calculatePathForPostCommentUpdate(folderCid, this._comment.postCid);
194
+ try {
195
+ // Validate the Comment Update within the gateway fetching algo
196
+ // fetchFromMultipleGateways will throw if all gateways failed to load the record
197
+ await this.fetchFromMultipleGateways({
198
+ recordIpfsType: "ipfs",
199
+ root: folderCid,
200
+ path: path.replace(`${folderCid}/`, ""),
201
+ recordPKCType: "comment-update",
202
+ validateGatewayResponseFunc: validateCommentFromGateway,
203
+ log,
204
+ maxFileSizeBytes: MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE,
205
+ timeoutMs: this._pkc._timeouts["comment-update-ipfs"],
206
+ abortSignal: this._comment._getStopAbortSignal()
207
+ });
208
+ if (!commentUpdate)
209
+ throw Error("Failed to load comment update from gateways. This is a critical logic error");
210
+ if (commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0))
211
+ return { commentUpdate, commentUpdateIpfsPath: path };
212
+ else
213
+ return undefined;
214
+ }
215
+ catch (e) {
216
+ // We need to find out if it's loading error, and if it is we just move on to the next timestamp range
217
+ // If it's a schema or signature error we should stop and throw
218
+ if (this._shouldWeFetchCommentUpdateFromNextTimestamp(e)) {
219
+ attemptedPathsToLoadErrors[path] = e;
220
+ log.trace(`Failed to fetch CommentUpdate from path (${path}) from gateways. Trying the next timestamp range`);
221
+ continue;
222
+ }
223
+ else {
224
+ // non retriable error
225
+ // a problem with the record itself, bad signature/schema/etc
226
+ this._comment._invalidCommentUpdateMfsPaths.add(path);
227
+ throw e;
228
+ }
229
+ }
230
+ }
231
+ throw new PKCError("ERR_FAILED_TO_FETCH_COMMENT_UPDATE_FROM_ALL_POST_UPDATES_RANGES", {
232
+ timestampRanges,
233
+ attemptedPathsToLoadErrors,
234
+ commentCid: this._comment.cid,
235
+ commentDepth: this._comment.depth
236
+ });
237
+ }
238
+ _useLoadedCommentUpdateIfNewInfo(loadedCommentUpdate, community, log) {
239
+ if ((this._comment.raw.commentUpdate?.updatedAt || 0) < loadedCommentUpdate.commentUpdate.updatedAt) {
240
+ log(`${this._comment.depth === 0 ? "Post" : "Reply"} (${this._comment.cid}) received a new CommentUpdate`);
241
+ this._comment._initCommentUpdate(loadedCommentUpdate.commentUpdate, community);
242
+ if ("commentUpdateIpfsPath" in loadedCommentUpdate)
243
+ this._comment._commentUpdateIpfsPath = loadedCommentUpdate.commentUpdateIpfsPath;
244
+ this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
245
+ newUpdatingState: "succeeded",
246
+ event: { name: "update", args: [this._comment] }
247
+ });
248
+ return true;
249
+ }
250
+ else
251
+ return false;
252
+ }
253
+ async useCommunityPostUpdatesToFetchCommentUpdateForPost(subIpfs) {
254
+ const log = Logger("pkc-js:comment:useCommunityPostUpdatesToFetchCommentUpdate");
255
+ if (!subIpfs.postUpdates) {
256
+ throw new PKCError("ERR_COMMUNITY_HAS_NO_POST_UPDATES", { subIpfs, postCid: this._comment.cid });
257
+ }
258
+ const postCid = this._comment.postCid;
259
+ if (!postCid)
260
+ throw Error("comment.postCid needs to be defined to fetch comment update");
261
+ const postTimestamp = this._comment.timestamp;
262
+ if (typeof postTimestamp !== "number")
263
+ throw Error("Post timestamp is not defined by the time we're fetching from postUpdates");
264
+ const timestampRanges = getPostUpdateTimestampRange(subIpfs.postUpdates, postTimestamp);
265
+ if (timestampRanges.length === 0)
266
+ throw Error("Post has no timestamp range bucket");
267
+ let newCommentUpdate;
268
+ try {
269
+ if (Object.keys(this._pkc.clients.kuboRpcClients).length > 0 || Object.keys(this._pkc.clients.libp2pJsClients).length > 0) {
270
+ newCommentUpdate = await this._fetchPostCommentUpdateIpfsP2P(subIpfs, timestampRanges, log);
271
+ }
272
+ else {
273
+ newCommentUpdate = await this._fetchPostCommentUpdateFromGateways(subIpfs, timestampRanges, log);
274
+ }
275
+ }
276
+ catch (e) {
277
+ if (e instanceof Error) {
278
+ if (isAbortError(e))
279
+ return;
280
+ if (this._shouldWeFetchCommentUpdateFromNextTimestamp(e)) {
281
+ // this is a retriable error
282
+ // could be problems loading from the network or gateways
283
+ log.trace(`Post`, this._comment.cid, "Failed to load CommentUpdate. Will retry later", e);
284
+ this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
285
+ newUpdatingState: "waiting-retry",
286
+ event: { name: "error", args: [e] }
287
+ });
288
+ }
289
+ else {
290
+ // non retriable error, problem with schema/signature
291
+ log.error("Received a non retriable error when attempting to load post commentUpdate. Will be emitting error", this._comment.cid, e);
292
+ this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
293
+ newUpdatingState: "failed",
294
+ event: { name: "error", args: [e] }
295
+ });
296
+ }
297
+ }
298
+ return;
299
+ }
300
+ if (newCommentUpdate) {
301
+ this._useLoadedCommentUpdateIfNewInfo(newCommentUpdate, subIpfs, log);
302
+ }
303
+ else if (newCommentUpdate === undefined) {
304
+ log.trace(`Comment`, this._comment.cid, "loaded an old comment update. Ignoring it");
305
+ this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
306
+ }
307
+ }
308
+ async _fetchRawCommentCidIpfsP2P(cid) {
309
+ const kuboRpcOrHelia = this.getDefaultKuboRpcClientOrHelia();
310
+ this._updateKuboRpcClientOrHeliaState("fetching-ipfs", kuboRpcOrHelia);
311
+ let commentRawString;
312
+ const commentTimeoutMs = this._pkc._timeouts["comment-ipfs"];
313
+ try {
314
+ commentRawString = await this._fetchCidP2P(cid, {
315
+ maxFileSizeBytes: 1024 * 1024,
316
+ timeoutMs: commentTimeoutMs,
317
+ abortSignal: this._comment._getStopAbortSignal()
318
+ });
319
+ }
320
+ catch (e) {
321
+ //@ts-expect-error
322
+ e.details = { ...e.details, commentCid: cid, commentTimeoutMs };
323
+ throw e;
324
+ }
325
+ finally {
326
+ this._updateKuboRpcClientOrHeliaState("stopped", kuboRpcOrHelia);
327
+ }
328
+ return commentRawString;
329
+ }
330
+ async _fetchCommentIpfsFromGateways(parentCid) {
331
+ // We only need to validate once, because with Comment Ipfs the fetchFromMultipleGateways already validates if the response is the same as its cid
332
+ const log = Logger("pkc-js:comment:client-manager:_fetchCommentIpfsFromGateways");
333
+ const res = await this.fetchFromMultipleGateways({
334
+ recordIpfsType: "ipfs",
335
+ recordPKCType: "comment",
336
+ root: parentCid,
337
+ validateGatewayResponseFunc: async () => { },
338
+ log,
339
+ maxFileSizeBytes: 1024 * 1024,
340
+ timeoutMs: this._pkc._timeouts["comment-ipfs"],
341
+ abortSignal: this._comment._getStopAbortSignal()
342
+ });
343
+ return res.resText;
344
+ }
345
+ async _throwIfCommentIpfsIsInvalid(commentIpfs, commentCid) {
346
+ // Can potentially throw if resolver if not working
347
+ const verificationOpts = {
348
+ comment: commentIpfs,
349
+ resolveAuthorNames: this._pkc.resolveAuthorNames,
350
+ clientsManager: this,
351
+ calculatedCommentCid: commentCid,
352
+ communityAddressFromInstance: this._comment.communityAddress,
353
+ abortSignal: this._comment._getStopAbortSignal()
354
+ };
355
+ const commentIpfsValidation = await verifyCommentIpfs(verificationOpts);
356
+ if (!commentIpfsValidation.valid)
357
+ throw new PKCError("ERR_COMMENT_IPFS_SIGNATURE_IS_INVALID", { commentIpfsValidation, verificationOpts });
358
+ }
359
+ async _fetchCommentIpfsFromPages() {
360
+ // this code below won't be executed by a post, and instead it will be a reply
361
+ // what do we do if we don't have parentCid?
362
+ // - download all comments under a community and look for our specific comment
363
+ if (!this._comment.communityAddress)
364
+ throw Error("Comment communityAddress should be defined");
365
+ if (!this._comment.cid)
366
+ throw Error("Comment cid should be defined");
367
+ const community = await this._pkc.createCommunity({
368
+ name: this._comment.communityName,
369
+ publicKey: this._comment.communityPublicKey,
370
+ address: this._comment.communityAddress
371
+ });
372
+ const abortController = new AbortController();
373
+ const abortIfNeeded = async () => {
374
+ if (!abortController.signal.aborted)
375
+ abortController.abort();
376
+ if (community.state === "updating")
377
+ await community.stop();
378
+ };
379
+ const onCommentUpdate = async () => {
380
+ if (this._comment.raw.comment)
381
+ await abortIfNeeded();
382
+ };
383
+ const onStateChange = async (newState) => {
384
+ if (newState === "stopped")
385
+ await abortIfNeeded();
386
+ };
387
+ this._comment.on("update", onCommentUpdate);
388
+ this._comment.on("statechange", onStateChange);
389
+ if (this._comment.state === "stopped" || this._pkc.destroyed)
390
+ return;
391
+ try {
392
+ if (abortController.signal.aborted)
393
+ return;
394
+ await community.update();
395
+ await new Promise((resolve, reject) => {
396
+ const abortError = () => {
397
+ const error = new Error("The operation was aborted");
398
+ error.name = "AbortError";
399
+ return error;
400
+ };
401
+ const cleanup = () => {
402
+ community.removeListener("update", onUpdate);
403
+ abortController.signal.removeEventListener("abort", onAbort);
404
+ };
405
+ const onAbort = () => {
406
+ cleanup();
407
+ reject(abortError());
408
+ };
409
+ const onUpdate = async () => {
410
+ try {
411
+ if (typeof community.updatedAt === "number") {
412
+ cleanup();
413
+ resolve();
414
+ }
415
+ }
416
+ catch (error) {
417
+ cleanup();
418
+ reject(error);
419
+ }
420
+ };
421
+ if (abortController.signal.aborted) {
422
+ reject(abortError());
423
+ return;
424
+ }
425
+ abortController.signal.addEventListener("abort", onAbort);
426
+ community.on("update", onUpdate);
427
+ void onUpdate();
428
+ });
429
+ await community.stop();
430
+ const commentAfterSearchingAllPages = await loadAllPagesUnderCommunityToFindComment({
431
+ community: community,
432
+ commentCidToFind: this._comment.cid,
433
+ postCid: this._comment.postCid,
434
+ parentCid: this._comment.parentCid,
435
+ signal: abortController.signal
436
+ });
437
+ if (commentAfterSearchingAllPages) {
438
+ if (!this._comment.raw.comment) {
439
+ this._comment._initIpfsProps(commentAfterSearchingAllPages.comment);
440
+ this._comment.emit("update", this._comment);
441
+ }
442
+ if ((this._comment.updatedAt || 0) < commentAfterSearchingAllPages.commentUpdate.updatedAt)
443
+ this._comment._initCommentUpdate(commentAfterSearchingAllPages.commentUpdate, community.raw.communityIpfs);
444
+ }
445
+ }
446
+ catch (err) {
447
+ if (err?.name !== "AbortError")
448
+ throw err;
449
+ }
450
+ finally {
451
+ this._comment.removeListener("update", onCommentUpdate);
452
+ this._comment.removeListener("statechange", onStateChange);
453
+ }
454
+ }
455
+ // We're gonna fetch Comment Ipfs, and verify its signature and schema
456
+ async fetchAndVerifyCommentCid(cid) {
457
+ const cachedComment = this._pkc._memCaches.commentIpfs.get(cid);
458
+ if (cachedComment) {
459
+ fetchCommentLogger.trace("Serving comment CID from cache", cid);
460
+ return remeda.clone(cachedComment);
461
+ }
462
+ const verifiedComment = await this._pkc._inflightFetchManager.withResource(InflightResourceTypes.COMMENT_IPFS, cid, async () => {
463
+ fetchCommentLogger.trace("Fetching comment CID", cid);
464
+ let commentRawString;
465
+ if (Object.keys(this._pkc.clients.kuboRpcClients).length > 0 || Object.keys(this._pkc.clients.libp2pJsClients).length > 0) {
466
+ commentRawString = await this._fetchRawCommentCidIpfsP2P(cid);
467
+ }
468
+ else
469
+ commentRawString = await this._fetchCommentIpfsFromGateways(cid);
470
+ const commentIpfs = parseCommentIpfsSchemaWithPKCErrorIfItFails(parseJsonWithPKCErrorIfFails(commentRawString)); // could throw if schema is invalid
471
+ await this._throwIfCommentIpfsIsInvalid(commentIpfs, cid);
472
+ return commentIpfs;
473
+ });
474
+ this._pkc._memCaches.commentIpfs.set(cid, verifiedComment);
475
+ return verifiedComment;
476
+ }
477
+ _isPublishing() {
478
+ return this._comment.state === "publishing";
479
+ }
480
+ _findCommentInPagesOfUpdatingCommentsOrCommunity(opts) {
481
+ // TODO rewrite this to use updating comments and community
482
+ if (typeof this._comment.cid !== "string")
483
+ throw Error("Need to have defined cid");
484
+ const community = findStartedCommunity(this._pkc, { address: this._comment.communityAddress }) ||
485
+ findUpdatingCommunity(this._pkc, { address: this._comment.communityAddress }) ||
486
+ opts?.community;
487
+ let updateFromCommunity;
488
+ if (community)
489
+ updateFromCommunity = findCommentInPageInstanceRecursively(community.posts, this._comment.cid);
490
+ const post = this._comment.postCid
491
+ ? findUpdatingComment(this._pkc, { cid: this._comment.postCid })
492
+ : opts?.post;
493
+ let updateFromPost;
494
+ if (post)
495
+ updateFromPost = findCommentInPageInstanceRecursively(post.replies, this._comment.cid);
496
+ const parent = this._comment.parentCid
497
+ ? opts?.parent || findUpdatingComment(this._pkc, { cid: this._comment.parentCid })
498
+ : undefined;
499
+ let updateFromParent;
500
+ if (parent) {
501
+ updateFromParent = parent.replies && findCommentInPageInstance(parent.replies, this._comment.cid);
502
+ }
503
+ const updates = [updateFromCommunity, updateFromPost, updateFromParent].filter((update) => !!update);
504
+ const latestUpdate = updates.sort((a, b) => b.commentUpdate.updatedAt - a.commentUpdate.updatedAt)[0];
505
+ return latestUpdate;
506
+ }
507
+ // will handling community states down here
508
+ // this is for posts with depth === 0
509
+ async handleUpdateEventFromCommunity(community) {
510
+ const log = Logger("pkc-js:comment:update");
511
+ if (!this._comment.cid) {
512
+ log("comment.cid is not defined because comment is publishing, waiting until cid is defined");
513
+ return;
514
+ }
515
+ // a new update has been emitted by community
516
+ if (this._comment.state === "stopped") {
517
+ // there are async cases where we fetch a CommunityUpdate in the background and stop() is called midway
518
+ await this._comment.stop();
519
+ return;
520
+ }
521
+ if (!community.raw.communityIpfs)
522
+ throw Error("Community IPFS should be defined when an update is emitted");
523
+ // let's try to find a CommentUpdate in community pages, or _updatingComments
524
+ // this._communityForUpdating!.community.raw.communityIpfs?.posts.
525
+ const postInUpdatingCommunity = this._findCommentInPagesOfUpdatingCommentsOrCommunity({ community });
526
+ if (postInUpdatingCommunity &&
527
+ postInUpdatingCommunity.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) {
528
+ const log = Logger("pkc-js:comment:update:handleUpdateEventFromCommunity:find-comment-update-in-updating-community-or-comments-pages");
529
+ this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: postInUpdatingCommunity.commentUpdate }, community.raw.communityIpfs, log);
530
+ }
531
+ else
532
+ try {
533
+ // this is only for posts with depth === 0
534
+ await this.useCommunityPostUpdatesToFetchCommentUpdateForPost(community.raw.communityIpfs);
535
+ }
536
+ catch (e) {
537
+ if (isAbortError(e))
538
+ return;
539
+ log.error("Failed to use community update to fetch new CommentUpdate", e);
540
+ this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
541
+ newUpdatingState: "failed",
542
+ event: { name: "error", args: [e] }
543
+ });
544
+ }
545
+ }
546
+ _chooseWhichPagesBasedOnParentAndReplyTimestamp(parentCommentTimestamp) {
547
+ // Choose which page type to search first based on our reply's timestamp
548
+ const replyTimestamp = this._comment.timestamp;
549
+ const currentTime = Math.floor(Date.now() / 1000);
550
+ // Calculate if our reply is relatively newer or older within the reply timeline
551
+ // The reply timeline spans from parentComment timestamp to current time
552
+ const replyTimelineSpan = currentTime - parentCommentTimestamp;
553
+ // Ensure our reply timestamp is at least the parentComment timestamp
554
+ const adjustedReplyTimestamp = Math.max(replyTimestamp, parentCommentTimestamp);
555
+ // Calculate how far along the timeline our reply is (0 = oldest possible, 1 = newest possible)
556
+ const replyRelativeAge = (currentTime - adjustedReplyTimestamp) / replyTimelineSpan;
557
+ // If replyRelativeAge is closer to 0, the reply is newer (less age)
558
+ // If replyRelativeAge is closer to 1, the reply is older (more age)
559
+ // So we start with 'new' pages if replyRelativeAge < 0.5
560
+ const startWithNewPages = replyRelativeAge < 0.5;
561
+ return startWithNewPages ? "new" : "old";
562
+ }
563
+ async usePageCidsOfParentToFetchCommentUpdateForReply(postCommentInstance) {
564
+ const log = Logger("pkc-js:comment:update:usePageCidsOfParentToFetchCommentUpdateForReply");
565
+ if (!this._comment.cid)
566
+ throw Error("comment.cid needs to be defined to fetch comment update of reply");
567
+ if (!this._comment.parentCid)
568
+ throw Error("comment.parentCid needs to be defined to fetch comment update of reply");
569
+ const communityWithSignature = postCommentInstance.replies._community;
570
+ if (!communityWithSignature.signature)
571
+ throw Error("comment.replies._community.signature needs to be defined to fetch comment update of reply");
572
+ const parentCommentInstance = postCommentInstance.cid === this._comment.parentCid
573
+ ? postCommentInstance
574
+ : await this._pkc.createComment({ cid: this._comment.parentCid });
575
+ let startedUpdatingParentComment = false;
576
+ if (parentCommentInstance.state === "stopped") {
577
+ await parentCommentInstance.update();
578
+ startedUpdatingParentComment = true;
579
+ }
580
+ await resolveWhenPredicateIsTrue({
581
+ toUpdate: parentCommentInstance,
582
+ predicate: () => typeof parentCommentInstance.updatedAt === "number"
583
+ });
584
+ if (startedUpdatingParentComment)
585
+ await parentCommentInstance.stop();
586
+ if (parentCommentInstance.updatedAt < this._comment.timestamp)
587
+ return; // if updatedAt is older then it doesn't include this comment yet
588
+ const replyInPreloadedParentPages = parentCommentInstance.replies && findCommentInPageInstance(parentCommentInstance.replies, this._comment.cid);
589
+ if (replyInPreloadedParentPages &&
590
+ replyInPreloadedParentPages.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) {
591
+ this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: replyInPreloadedParentPages.commentUpdate }, communityWithSignature, log);
592
+ return;
593
+ }
594
+ if (Object.keys(parentCommentInstance.replies.pageCids).length === 0) {
595
+ // Parent has no pageCids - all replies fit in preloaded pages
596
+ // If we found the reply in preloaded pages (line 675-676), use it even if not strictly "newer"
597
+ if (replyInPreloadedParentPages) {
598
+ log("Parent comment", this._comment.parentCid, "has no pageCids but reply", this._comment.cid, "found in preloaded pages - using it");
599
+ this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: replyInPreloadedParentPages.commentUpdate }, communityWithSignature, log);
600
+ return;
601
+ }
602
+ // Reply not in preloaded pages and no pageCids to search - wait for update
603
+ log("Parent comment", this._comment.parentCid, "of reply", this._comment.cid, "does not have any pageCids and reply not in preloaded pages, will wait until another update event by post");
604
+ this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
605
+ return;
606
+ }
607
+ const pageSortName = this._chooseWhichPagesBasedOnParentAndReplyTimestamp(parentCommentInstance.timestamp);
608
+ let curPageCid = parentCommentInstance.replies.pageCids[pageSortName];
609
+ if (!curPageCid)
610
+ throw Error("Parent comment does not have any new or old pages");
611
+ if (this._parentFirstPageCidsAlreadyLoaded.has(curPageCid)) {
612
+ log(`Reply`, this._comment.cid, `:SKIPPING: Page CID ${curPageCid} already loaded parent page cid`);
613
+ // we already loaded this page before and have its comment update, no need to do anything
614
+ return;
615
+ }
616
+ this._comment._setUpdatingStateWithEmissionIfNewState("fetching-update-ipfs");
617
+ let newCommentUpdate;
618
+ const pageCidsSearchedForNewUpdate = [];
619
+ let replyFoundWithoutNewerUpdate = false;
620
+ while (curPageCid && !newCommentUpdate) {
621
+ let pageLoaded;
622
+ try {
623
+ pageLoaded = await parentCommentInstance.replies.getPage({ cid: curPageCid });
624
+ }
625
+ catch (e) {
626
+ if (isAbortError(e))
627
+ throw e;
628
+ pageCidsSearchedForNewUpdate.push({ pageCid: curPageCid, error: e });
629
+ break;
630
+ }
631
+ if (pageCidsSearchedForNewUpdate.length === 0) {
632
+ this._parentFirstPageCidsAlreadyLoaded.add(curPageCid);
633
+ }
634
+ const replyWithinParentPage = findCommentInParsedPages(pageLoaded, this._comment.cid)?.raw;
635
+ const replyWithinUpdatingPages = this._findCommentInPagesOfUpdatingCommentsOrCommunity({ parent: parentCommentInstance });
636
+ pageCidsSearchedForNewUpdate.push({
637
+ pageCid: curPageCid,
638
+ replyWithinParentPage: Boolean(replyWithinParentPage),
639
+ replyWithinUpdatingPages: Boolean(replyWithinUpdatingPages)
640
+ });
641
+ if (replyWithinParentPage) {
642
+ const isNewUpdate = replyWithinParentPage.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0);
643
+ if (isNewUpdate) {
644
+ newCommentUpdate = replyWithinParentPage;
645
+ }
646
+ else {
647
+ replyFoundWithoutNewerUpdate = true;
648
+ }
649
+ break; // if we found the comment in parent pages, there's no point in continuing to look for it in updating pages
650
+ }
651
+ else if (replyWithinUpdatingPages) {
652
+ const isNewUpdate = replyWithinUpdatingPages.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0);
653
+ if (isNewUpdate)
654
+ newCommentUpdate = replyWithinUpdatingPages;
655
+ else
656
+ replyFoundWithoutNewerUpdate = true;
657
+ }
658
+ if (pageSortName === "new" && pageLoaded.comments.find((comment) => comment.timestamp < this._comment.timestamp)) {
659
+ log("Reply", this._comment.cid, "we found a comment in the page that is older than our reply, stopping search for new comment update");
660
+ break;
661
+ }
662
+ else if (pageSortName === "old" && pageLoaded.comments.find((comment) => comment.timestamp > this._comment.timestamp)) {
663
+ log("Reply", this._comment.cid, "we found a comment in the page that is newer than our reply, stopping search for old comment update");
664
+ break;
665
+ }
666
+ curPageCid = pageLoaded.nextCid;
667
+ }
668
+ log("Searched for new comment update of comment", this._comment.cid, "in the following pageCids of page sort", pageSortName, "of parent comment:", parentCommentInstance.cid, pageCidsSearchedForNewUpdate, "and found", newCommentUpdate ? "a new comment update" : "no new comment update");
669
+ if (newCommentUpdate)
670
+ this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: newCommentUpdate.commentUpdate }, communityWithSignature, log);
671
+ else if (!replyFoundWithoutNewerUpdate)
672
+ throw new PKCError("ERR_FAILED_TO_FIND_REPLY_COMMENT_UPDATE_WITHIN_PARENT_COMMENT_PAGE_CIDS", {
673
+ replyCid: this._comment.cid,
674
+ parentCommentCid: parentCommentInstance.cid,
675
+ pageSortName,
676
+ pageCidsSearchedForNewUpdate
677
+ });
678
+ }
679
+ async handleErrorEventFromCommunity(error) {
680
+ // we received a non retriable error from community instance
681
+ if (this._comment.state === "publishing")
682
+ return super.handleErrorEventFromCommunity(error);
683
+ else if (this._communityForUpdating?.community?.updatingState === "failed") {
684
+ // let's make sure
685
+ // we're updating a comment
686
+ const log = Logger("pkc-js:comment:update");
687
+ log.error(this._comment.depth === 0 ? "Post" : "Reply", this._comment.cid, "received a non retriable error from its community instance. Will stop comment updating", error);
688
+ this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
689
+ newUpdatingState: "failed",
690
+ event: { name: "error", args: [error] }
691
+ });
692
+ await this._comment.stop();
693
+ }
694
+ }
695
+ handleIpfsGatewayCommunityState(communityNewGatewayState, gatewayUrl) {
696
+ if (this._comment.state === "publishing")
697
+ return super.handleIpfsGatewayCommunityState(communityNewGatewayState, gatewayUrl);
698
+ // we're updating
699
+ else if (communityNewGatewayState === "fetching-ipns")
700
+ this.updateGatewayState("fetching-community-ipns", gatewayUrl);
701
+ }
702
+ _translateCommunityUpdatingStateToCommentUpdatingState(newCommunityUpdatingState) {
703
+ const communityUpdatingStateToCommentUpdatingState = {
704
+ failed: "failed",
705
+ "fetching-ipfs": "fetching-community-ipfs",
706
+ "fetching-ipns": "fetching-community-ipns",
707
+ "resolving-name": "resolving-community-name",
708
+ "waiting-retry": "waiting-retry",
709
+ stopped: "stopped",
710
+ succeeded: undefined,
711
+ "publishing-ipns": undefined
712
+ };
713
+ const translatedCommentUpdatingState = communityUpdatingStateToCommentUpdatingState[newCommunityUpdatingState];
714
+ if (translatedCommentUpdatingState)
715
+ this._comment._setUpdatingStateWithEmissionIfNewState(translatedCommentUpdatingState);
716
+ }
717
+ handleUpdatingStateChangeEventFromCommunity(newCommunityUpdatingState) {
718
+ if (this._comment.state === "publishing")
719
+ return super.handleUpdatingStateChangeEventFromCommunity(newCommunityUpdatingState);
720
+ if (this._comment.updatingState === "fetching-update-ipfs")
721
+ return;
722
+ this._translateCommunityUpdatingStateToCommentUpdatingState(newCommunityUpdatingState);
723
+ }
724
+ handleErrorEventFromPost(error) {
725
+ this._comment.emit("error", error);
726
+ }
727
+ handleUpdatingStateChangeEventFromPost(newState) {
728
+ const postUpdatingStateToReplyUpdatingState = {
729
+ failed: "failed",
730
+ "fetching-community-ipfs": "fetching-community-ipfs",
731
+ "fetching-community-ipns": "fetching-community-ipns",
732
+ "resolving-community-name": "resolving-community-name",
733
+ "waiting-retry": "waiting-retry",
734
+ stopped: undefined,
735
+ succeeded: undefined,
736
+ "fetching-ipfs": undefined,
737
+ "resolving-author-name": undefined,
738
+ "fetching-update-ipfs": undefined
739
+ };
740
+ const replyState = postUpdatingStateToReplyUpdatingState[newState];
741
+ if (replyState) {
742
+ if (this._fetchingUpdateForReplyUsingPageCidsPromise)
743
+ this._fetchingUpdateForReplyUsingPageCidsPromise.then(() => this._comment._setUpdatingStateWithEmissionIfNewState(replyState));
744
+ else
745
+ this._comment._setUpdatingStateWithEmissionIfNewState(replyState);
746
+ }
747
+ }
748
+ _handleIpfsGatewayPostState(newState, gatewayUrl) {
749
+ this.updateGatewayState(newState, gatewayUrl);
750
+ }
751
+ _handleKuboRpcPostState(newState, kuboRpcUrl) {
752
+ this.updateKuboRpcState(newState, kuboRpcUrl);
753
+ }
754
+ _handleLibp2pJsClientPostState(newState, libp2pJsClientKey) {
755
+ this.updateLibp2pJsClientState(newState, libp2pJsClientKey);
756
+ }
757
+ _handleNameResolverPostState(newState, resolverKey) {
758
+ // Don't forward page-author resolution states from the post — only community-name resolution is relevant
759
+ if (newState === "resolving-author-name")
760
+ return;
761
+ this.updateNameResolverState(newState, resolverKey);
762
+ }
763
+ async handleUpdateEventFromPostToFetchReplyCommentUpdate(postInstance) {
764
+ if (!this._comment.cid)
765
+ throw Error("comment.cid should be defined");
766
+ const log = Logger("pkc-js:comment:update:handleUpdateEventFromPost");
767
+ log("Received update event from post", postInstance.cid, "for reply", this._comment.cid, "with depth", this._comment.depth);
768
+ if (Object.keys(postInstance.replies.pageCids).length === 0 && Object.keys(postInstance.replies.pages).length === 0) {
769
+ log("Post", postInstance.cid, "has no replies, therefore reply", this._comment.cid, "will wait until another update event by post");
770
+ this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
771
+ return;
772
+ }
773
+ const replyInPage = this._findCommentInPagesOfUpdatingCommentsOrCommunity({ post: postInstance });
774
+ const updatingCommunity = findUpdatingCommunity(this._pkc, { address: postInstance.communityAddress });
775
+ const startedCommunity = findStartedCommunity(this._pkc, { address: postInstance.communityAddress });
776
+ const repliesCommunity = ((updatingCommunity?.raw?.communityIpfs || startedCommunity?.raw?.communityIpfs || postInstance.replies._community));
777
+ if (!repliesCommunity.signature)
778
+ throw Error("repliesCommunity.signature needs to be defined to fetch comment update of reply");
779
+ if (replyInPage && !this._comment.raw.comment) {
780
+ this._comment._initIpfsProps(replyInPage.comment);
781
+ this._comment.emit("update", this._comment);
782
+ }
783
+ if (replyInPage && replyInPage.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) {
784
+ const log = Logger("pkc-js:comment:update:handleUpdateEventFromPostToFetchReplyCommentUpdate:find-comment-update-in-updating-community-or-comments-pages");
785
+ this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: replyInPage.commentUpdate }, repliesCommunity, log);
786
+ return; // we found an update from pages, no need to do anything else
787
+ }
788
+ if (this._fetchingUpdateForReplyUsingPageCidsPromise)
789
+ await this._fetchingUpdateForReplyUsingPageCidsPromise;
790
+ this._fetchingUpdateForReplyUsingPageCidsPromise = this.usePageCidsOfParentToFetchCommentUpdateForReply(postInstance)
791
+ .catch((error) => {
792
+ if (isAbortError(error))
793
+ return;
794
+ log.error("Failed to fetch reply commentUpdate update from parent pages", error);
795
+ this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
796
+ newUpdatingState: "failed",
797
+ event: { name: "error", args: [error] }
798
+ });
799
+ })
800
+ .finally(() => {
801
+ this._fetchingUpdateForReplyUsingPageCidsPromise = undefined;
802
+ });
803
+ await this._fetchingUpdateForReplyUsingPageCidsPromise;
804
+ this._fetchingUpdateForReplyUsingPageCidsPromise = undefined;
805
+ }
806
+ async _createPostInstanceWithStateTranslation() {
807
+ // this function will be for translating between the states of the post and its clients to reply states
808
+ if (!this._comment.postCid)
809
+ throw Error("comment.postCid needs to be defined to fetch comment update of reply");
810
+ const post = findUpdatingComment(this._pkc, { cid: this._comment.postCid }) ||
811
+ (await this._pkc.createComment({ cid: this._comment.postCid }));
812
+ this._postForUpdating = {
813
+ comment: post,
814
+ error: this.handleErrorEventFromPost.bind(this),
815
+ update: this.handleUpdateEventFromPostToFetchReplyCommentUpdate.bind(this),
816
+ updatingstatechange: this.handleUpdatingStateChangeEventFromPost.bind(this)
817
+ };
818
+ if (this._postForUpdating.comment.clients.ipfsGateways &&
819
+ Object.keys(this._postForUpdating.comment.clients.ipfsGateways).length > 0) {
820
+ // we're using gateways
821
+ const ipfsGatewayListeners = {};
822
+ for (const gatewayUrl of Object.keys(this._postForUpdating.comment.clients.ipfsGateways)) {
823
+ const ipfsStateListener = (postNewIpfsState) => this._handleIpfsGatewayPostState(postNewIpfsState, gatewayUrl);
824
+ this._postForUpdating.comment.clients.ipfsGateways[gatewayUrl].on("statechange", ipfsStateListener);
825
+ ipfsGatewayListeners[gatewayUrl] = ipfsStateListener;
826
+ }
827
+ this._postForUpdating.ipfsGatewayListeners = ipfsGatewayListeners;
828
+ }
829
+ // Add Kubo RPC client state listeners
830
+ if (this._postForUpdating.comment.clients.kuboRpcClients &&
831
+ Object.keys(this._postForUpdating.comment.clients.kuboRpcClients).length > 0) {
832
+ const kuboRpcListeners = {};
833
+ for (const kuboRpcUrl of Object.keys(this._postForUpdating.comment.clients.kuboRpcClients)) {
834
+ const kuboRpcStateListener = (postNewKuboRpcState) => this._handleKuboRpcPostState(postNewKuboRpcState, kuboRpcUrl);
835
+ this._postForUpdating.comment.clients.kuboRpcClients[kuboRpcUrl].on("statechange", kuboRpcStateListener);
836
+ kuboRpcListeners[kuboRpcUrl] = kuboRpcStateListener;
837
+ }
838
+ this._postForUpdating.kuboRpcListeners = kuboRpcListeners;
839
+ }
840
+ if (this._postForUpdating.comment.clients.libp2pJsClients &&
841
+ Object.keys(this._postForUpdating.comment.clients.libp2pJsClients).length > 0) {
842
+ const libp2pJsClientListeners = {};
843
+ for (const libp2pJsClientKey of Object.keys(this._postForUpdating.comment.clients.libp2pJsClients)) {
844
+ const libp2pJsStateListener = (postNewLibp2pJsState) => this._handleLibp2pJsClientPostState(postNewLibp2pJsState, libp2pJsClientKey);
845
+ this._postForUpdating.comment.clients.libp2pJsClients[libp2pJsClientKey].on("statechange", libp2pJsStateListener);
846
+ libp2pJsClientListeners[libp2pJsClientKey] = libp2pJsStateListener;
847
+ }
848
+ this._postForUpdating.libp2pJsClientListeners = libp2pJsClientListeners;
849
+ }
850
+ // Add name resolver state listeners
851
+ if (this._postForUpdating.comment.clients.nameResolvers &&
852
+ Object.keys(this._postForUpdating.comment.clients.nameResolvers).length > 0) {
853
+ const nameResolverListeners = {};
854
+ for (const resolverKey of Object.keys(this._postForUpdating.comment.clients.nameResolvers)) {
855
+ const resolverStateListener = (postNewResolverState) => this._handleNameResolverPostState(postNewResolverState, resolverKey);
856
+ this._postForUpdating.comment.clients.nameResolvers[resolverKey].on("statechange", resolverStateListener);
857
+ nameResolverListeners[resolverKey] = resolverStateListener;
858
+ }
859
+ this._postForUpdating.nameResolverListeners = nameResolverListeners;
860
+ }
861
+ this._postForUpdating.comment.on("update", this._postForUpdating.update);
862
+ this._postForUpdating.comment.on("updatingstatechange", this._postForUpdating.updatingstatechange);
863
+ this._postForUpdating.comment.on("error", this._postForUpdating.error);
864
+ return this._postForUpdating;
865
+ }
866
+ async cleanUpUpdatingPostInstance() {
867
+ if (!this._postForUpdating)
868
+ return; // it has been cleared out somewhere else
869
+ // Clean up IPFS Gateway listeners
870
+ if (this._postForUpdating.ipfsGatewayListeners) {
871
+ for (const gatewayUrl of Object.keys(this._postForUpdating.ipfsGatewayListeners)) {
872
+ this._postForUpdating.comment.clients.ipfsGateways[gatewayUrl].removeListener("statechange", this._postForUpdating.ipfsGatewayListeners[gatewayUrl]);
873
+ this.updateGatewayState("stopped", gatewayUrl); // need to reset all gateway states
874
+ }
875
+ }
876
+ // Clean up Kubo RPC listeners
877
+ if (this._postForUpdating.kuboRpcListeners) {
878
+ for (const kuboRpcUrl of Object.keys(this._postForUpdating.kuboRpcListeners)) {
879
+ this._postForUpdating.comment.clients.kuboRpcClients[kuboRpcUrl].removeListener("statechange", this._postForUpdating.kuboRpcListeners[kuboRpcUrl]);
880
+ this.updateKuboRpcState("stopped", kuboRpcUrl); // need to reset all Kubo RPC states
881
+ }
882
+ }
883
+ // Clean up libp2pJs client listeners
884
+ if (this._postForUpdating.libp2pJsClientListeners) {
885
+ for (const libp2pJsClientKey of Object.keys(this._postForUpdating.libp2pJsClientListeners)) {
886
+ this._postForUpdating.comment.clients.libp2pJsClients[libp2pJsClientKey].removeListener("statechange", this._postForUpdating.libp2pJsClientListeners[libp2pJsClientKey]);
887
+ this.updateLibp2pJsClientState("stopped", libp2pJsClientKey); // need to reset all libp2pJs client states
888
+ }
889
+ }
890
+ // Clean up name resolver listeners
891
+ if (this._postForUpdating.nameResolverListeners) {
892
+ for (const resolverKey of Object.keys(this._postForUpdating.nameResolverListeners)) {
893
+ this._postForUpdating.comment.clients.nameResolvers[resolverKey].removeListener("statechange", this._postForUpdating.nameResolverListeners[resolverKey]);
894
+ this.updateNameResolverState("stopped", resolverKey); // need to reset all name resolver states
895
+ }
896
+ }
897
+ // Remove update event at the end
898
+ this._postForUpdating.comment.removeListener("updatingstatechange", this._postForUpdating.updatingstatechange);
899
+ this._postForUpdating.comment.removeListener("error", this._postForUpdating.error);
900
+ this._postForUpdating.comment.removeListener("update", this._postForUpdating.update);
901
+ // only stop if it's mirroring the actual comment instance updating at pkc._updatingComments
902
+ if (this._postForUpdating.comment._updatingCommentInstance)
903
+ await this._postForUpdating.comment.stop();
904
+ this._parentFirstPageCidsAlreadyLoaded.clear();
905
+ this._postForUpdating = undefined;
906
+ }
907
+ }
908
+ //# sourceMappingURL=comment-client-manager.js.map