@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,1044 @@
1
+ import retry from "retry";
2
+ import { createAbortError, deepMergeRuntimeFields, hideClassPrivateProps, isAbortError, retryKuboIpfsAdd, shortifyCid } from "../../util.js";
3
+ import Publication from "../publication.js";
4
+ import { getCommunityAddressFromRecord } from "../publication-community.js";
5
+ import Logger from "../../logger.js";
6
+ import { signComment, verifyCommentIpfs, verifyCommentPubsubMessage, verifyCommentUpdate } from "../../signer/signatures.js";
7
+ import assert from "assert";
8
+ import { FailedToFetchCommentIpfsFromGatewaysError, PKCError } from "../../pkc-error.js";
9
+ import * as remeda from "remeda";
10
+ import { of as calculateIpfsHash } from "typestub-ipfs-only-hash";
11
+ import { RepliesPages } from "../../pages/pages.js";
12
+ import { findCommentInPageInstanceRecursively, parseRawPages } from "../../pages/util.js";
13
+ import { CommentIpfsSchema, CommentUpdateForChallengeVerificationSchema, CommentUpdateSchema } from "./schema.js";
14
+ import { parseRpcCommentEventWithPKCErrorIfItFails, parseRpcCommentUpdateEventWithPKCErrorIfItFails } from "../../schema/schema-util.js";
15
+ import { CommentClientsManager } from "./comment-client-manager.js";
16
+ import { CID } from "kubo-rpc-client";
17
+ import { getAuthorDomainFromRuntime } from "../publication-author.js";
18
+ import { sha256 } from "js-sha256";
19
+ import { findStartedCommunity, findUpdatingComment, findUpdatingCommunity, listStartedCommunities, listUpdatingComments, listUpdatingCommunities, refreshTrackedCommentAliases, trackUpdatingComment, untrackUpdatingComment } from "../../pkc/tracked-instance-registry-util.js";
20
+ export class Comment extends Publication {
21
+ constructor(pkc) {
22
+ super(pkc);
23
+ // private
24
+ this.raw = {};
25
+ this._commentUpdateIpfsPath = undefined; // its IPFS path derived from community.postUpdates.
26
+ this._invalidCommentUpdateMfsPaths = new Set();
27
+ this._commentIpfsloadingOperation = undefined;
28
+ this._updateRpcSubscriptionId = undefined;
29
+ this._stopAbortController = undefined;
30
+ this._numOfListenersForUpdatingInstance = 0;
31
+ this._updatingCommentInstance = undefined; // the comment instance we're mirroing
32
+ this._setUpdatingStateWithEmissionIfNewState("stopped");
33
+ // these functions might get separated from their `this` when used
34
+ this.publish = this.publish.bind(this);
35
+ this.update = this.update.bind(this);
36
+ this.stop = this.stop.bind(this);
37
+ this.replies = new RepliesPages({
38
+ pages: {},
39
+ pageCids: {},
40
+ pkc: this._pkc,
41
+ community: { address: this.communityAddress },
42
+ parentComment: this
43
+ });
44
+ hideClassPrivateProps(this);
45
+ }
46
+ _initClients() {
47
+ this._clientsManager = new CommentClientsManager(this);
48
+ this.clients = this._clientsManager.clients;
49
+ }
50
+ _createStopAbortController() {
51
+ if (!this._stopAbortController || this._stopAbortController.signal.aborted)
52
+ this._stopAbortController = new AbortController();
53
+ return this._stopAbortController;
54
+ }
55
+ _getStopAbortSignal() {
56
+ return this._stopAbortController?.signal;
57
+ }
58
+ _isStopAbortRequested() {
59
+ return Boolean(this._stopAbortController?.signal.aborted);
60
+ }
61
+ _abortStopOperations(reason) {
62
+ if (!this._stopAbortController || this._stopAbortController.signal.aborted)
63
+ return;
64
+ this._stopAbortController.abort(createAbortError(reason));
65
+ }
66
+ _clearStopAbortController() {
67
+ this._stopAbortController = undefined;
68
+ }
69
+ _initUnsignedLocalProps(opts) {
70
+ super._initUnsignedLocalProps(opts);
71
+ const o = opts.unsignedOptions;
72
+ this.title = o.title;
73
+ this.content = o.content;
74
+ this.parentCid = o.parentCid;
75
+ this.link = o.link;
76
+ this.linkWidth = o.linkWidth;
77
+ this.linkHeight = o.linkHeight;
78
+ this.linkHtmlTagName = o.linkHtmlTagName;
79
+ this.spoiler = o.spoiler;
80
+ this.nsfw = o.nsfw;
81
+ this.flairs = o.flairs;
82
+ this.quotedCids = o.quotedCids;
83
+ }
84
+ _initLocalProps(props) {
85
+ this._initPubsubMessageProps(props.comment);
86
+ this.challengeRequest = props.challengeRequest;
87
+ this.signer = props.signer;
88
+ }
89
+ async _signPublicationOptionsToPublish(cleanedPublication) {
90
+ return signComment({ comment: cleanedPublication, pkc: this._pkc });
91
+ }
92
+ _initPubsubMessageProps(props) {
93
+ this.raw.pubsubMessageToPublish = props;
94
+ this._initProps(props);
95
+ }
96
+ _initIpfsProps(props) {
97
+ const log = Logger("pkc-js:comment:_initIpfsProps");
98
+ // we're loading remote CommentIpfs
99
+ this.raw.comment = props;
100
+ this._initProps(props);
101
+ const unknownProps = remeda.difference(remeda.keys.strict(props), remeda.keys.strict(CommentIpfsSchema.shape));
102
+ if (unknownProps.length > 0) {
103
+ log("Found unknown props on loaded CommentIpfs", unknownProps, "Will set them on the Comment instance");
104
+ Object.assign(this, remeda.pick(props, unknownProps));
105
+ }
106
+ this._setAuthorNameResolvedFromCache();
107
+ }
108
+ _setAuthorNameResolvedFromCache() {
109
+ const domain = getAuthorDomainFromRuntime(this.author);
110
+ if (!domain)
111
+ return; // no domain → nameResolved stays undefined
112
+ const cached = this._pkc._memCaches.nameResolvedCache.get(sha256(domain + this.signature.publicKey));
113
+ if (typeof cached === "boolean")
114
+ this.author.nameResolved = cached;
115
+ }
116
+ _copyNameResolvedFromComment(sourceComment) {
117
+ if (typeof sourceComment?.author?.nameResolved === "boolean")
118
+ this.author.nameResolved = sourceComment.author.nameResolved;
119
+ }
120
+ _resolveAuthorNamesInBackground() {
121
+ if (!this._pkc.resolveAuthorNames)
122
+ return;
123
+ // Collect comment's own author if nameResolved is not yet set
124
+ const domain = getAuthorDomainFromRuntime(this.author);
125
+ const ownAuthor = domain && typeof this.author.nameResolved !== "boolean"
126
+ ? [{ authorName: domain, signaturePublicKey: this.signature.publicKey }]
127
+ : [];
128
+ // Collect page comment authors from replies that still need resolution
129
+ const replyAuthors = [];
130
+ if (this.replies?.pages) {
131
+ for (const page of Object.values(this.replies.pages)) {
132
+ if (!page)
133
+ continue;
134
+ for (const comment of page.comments) {
135
+ const commentDomain = getAuthorDomainFromRuntime(comment.author);
136
+ if (commentDomain && typeof comment.author.nameResolved !== "boolean") {
137
+ replyAuthors.push({ authorName: commentDomain, signaturePublicKey: comment.signature.publicKey });
138
+ }
139
+ }
140
+ }
141
+ }
142
+ if (ownAuthor.length === 0 && replyAuthors.length === 0)
143
+ return;
144
+ const previousNameResolved = this.author.nameResolved;
145
+ const onResolved = () => {
146
+ this._setAuthorNameResolvedFromCache();
147
+ if (this.replies?.pages) {
148
+ for (const page of Object.values(this.replies.pages)) {
149
+ if (page)
150
+ this.replies._applyNameResolvedCacheToPage(page);
151
+ }
152
+ }
153
+ // Only emit update if this comment's own author.nameResolved changed
154
+ if (this.author.nameResolved !== previousNameResolved) {
155
+ this.emit("update", this);
156
+ }
157
+ };
158
+ const abortSignal = this._getStopAbortSignal();
159
+ // Resolve comment's own author through this._clientsManager (triggers state changes on the comment)
160
+ if (ownAuthor.length > 0) {
161
+ this._clientsManager.resolveAuthorNamesInBackground({ authors: ownAuthor, onResolved, abortSignal });
162
+ }
163
+ // Resolve reply page authors through pkc-level manager (no state changes on this comment)
164
+ if (replyAuthors.length > 0) {
165
+ this._pkc._clientsManager.resolveAuthorNamesInBackground({ authors: replyAuthors, onResolved, abortSignal });
166
+ }
167
+ }
168
+ _initProps(props) {
169
+ // Initializing CommentPubsubMessage
170
+ super._initBaseRemoteProps(props);
171
+ this.content = props.content;
172
+ this.flairs = props.flairs;
173
+ this.link = props.link;
174
+ this.linkHeight = props.linkHeight;
175
+ this.linkWidth = props.linkWidth;
176
+ this.parentCid = props.parentCid;
177
+ this.spoiler = props.spoiler;
178
+ this.nsfw = props.nsfw;
179
+ this.title = props.title;
180
+ this.linkHtmlTagName = props.linkHtmlTagName;
181
+ this.quotedCids = props.quotedCids;
182
+ // Initializing Comment Ipfs props
183
+ if ("depth" in props && typeof props.depth === "number") {
184
+ this.depth = props.depth;
185
+ const postCid = props.postCid ? props.postCid : this.cid && this.depth === 0 ? this.cid : undefined;
186
+ if (!postCid)
187
+ throw Error("There is no way to set comment.postCid");
188
+ this.postCid = postCid;
189
+ this.previousCid = props.previousCid;
190
+ this.thumbnailUrl = props.thumbnailUrl;
191
+ this.thumbnailUrlHeight = props.thumbnailUrlHeight;
192
+ this.thumbnailUrlWidth = props.thumbnailUrlWidth;
193
+ this.pseudonymityMode = props.pseudonymityMode;
194
+ }
195
+ }
196
+ _initCommentUpdate(props, community) {
197
+ const log = Logger("pkc-js:comment:_initCommentUpdate");
198
+ if ("depth" in props) {
199
+ // CommentWithinPageJson — no extra setup needed
200
+ }
201
+ else {
202
+ // CommentUpdate
203
+ this.raw.commentUpdate = props;
204
+ const unknownProps = remeda.difference(remeda.keys.strict(props), remeda.keys.strict(CommentUpdateSchema.shape));
205
+ if (unknownProps.length > 0) {
206
+ log("Found unknown props on CommentUpdate record", unknownProps, "Will set them on Comment instance");
207
+ Object.assign(this, remeda.pick(props, unknownProps));
208
+ }
209
+ }
210
+ this.upvoteCount = props.upvoteCount;
211
+ this.downvoteCount = props.downvoteCount;
212
+ this.replyCount = props.replyCount;
213
+ this.childCount = props.childCount;
214
+ this.updatedAt = props.updatedAt;
215
+ this.deleted = props.edit?.deleted;
216
+ this.pinned = props.pinned;
217
+ this.locked = props.locked;
218
+ this.archived = props.archived;
219
+ this.removed = props.removed;
220
+ this.reason = props.reason;
221
+ this.edit = props.edit;
222
+ this.protocolVersion = props.protocolVersion;
223
+ // Merge props from original comment and CommentUpdate
224
+ this.spoiler =
225
+ typeof props.spoiler === "boolean"
226
+ ? props.spoiler
227
+ : typeof props.edit?.spoiler === "boolean"
228
+ ? props.edit?.spoiler
229
+ : this.spoiler;
230
+ this.nsfw = typeof props.nsfw === "boolean" ? props.nsfw : typeof props.edit?.nsfw === "boolean" ? props.edit?.nsfw : this.nsfw;
231
+ if (props.author)
232
+ Object.assign(this.author, props.author);
233
+ if (props.edit?.content)
234
+ this.content = props.edit.content;
235
+ // TODO flairs merging strategy will likely change — currently first-defined wins (mod > author edit > existing)
236
+ this.flairs = props.flairs || props.edit?.flairs || this.flairs;
237
+ this.author.flairs = props.author?.community?.flairs || props.edit?.author?.flairs || this.author?.flairs;
238
+ this.lastChildCid = props.lastChildCid;
239
+ this.lastReplyTimestamp = props.lastReplyTimestamp;
240
+ this._updateRepliesPostsInstance(props.replies, community);
241
+ if (typeof this.pendingApproval === "boolean" || "pendingApproval" in props)
242
+ this.pendingApproval = Boolean("pendingApproval" in props && props.pendingApproval); // revert pendingApproval if we just received a CommentUpdate
243
+ else if ("approved" in props && typeof props.approved === "boolean") {
244
+ this.pendingApproval = false; // we received either a rejection or acceptance
245
+ }
246
+ this.approved = props.approved;
247
+ this.number = props.number;
248
+ this.postNumber = props.postNumber;
249
+ this._setAuthorNameResolvedFromCache();
250
+ }
251
+ _updateRepliesPostsInstance(newReplies, community) {
252
+ assert(this.cid, "Can't update comment.replies without comment.cid being defined");
253
+ const log = Logger("pkc-js:comment:_updateRepliesPostsInstanceIfNeeded");
254
+ const communitySignature = community?.signature || this.replies._community.signature;
255
+ const repliesCreationTimestamp = this.updatedAt;
256
+ if (typeof repliesCreationTimestamp !== "number")
257
+ throw Error("comment.updatedAt should be defined when updating replies");
258
+ this.replies._community.signature = communitySignature;
259
+ const repliesCommunity = { address: this.communityAddress, signature: communitySignature };
260
+ if (!newReplies) {
261
+ this.replies.resetPages();
262
+ }
263
+ else if (!("pages" in newReplies) && newReplies.pageCids) {
264
+ // only pageCids is provided
265
+ this.replies.updateProps({
266
+ community: repliesCommunity,
267
+ pageCids: newReplies.pageCids,
268
+ pages: {}
269
+ });
270
+ }
271
+ else if (!newReplies.pageCids && "pages" in newReplies && newReplies.pages) {
272
+ // only pages is provided
273
+ this.replies.updateProps({
274
+ ...parseRawPages(newReplies),
275
+ community: this.replies._community,
276
+ pageCids: {}
277
+ });
278
+ }
279
+ else if ("pages" in newReplies && newReplies.pages && "pageCids" in newReplies && newReplies.pageCids) {
280
+ // both pageCids and pages are provided
281
+ const shouldUpdateReplies = !remeda.isDeepEqual(this.replies.pageCids, newReplies.pageCids);
282
+ if (shouldUpdateReplies) {
283
+ log.trace(`Updating the props of comment instance (${this.cid}) replies`);
284
+ const parsedPages = (parseRawPages(newReplies));
285
+ this.replies.updateProps({
286
+ ...parsedPages,
287
+ community: repliesCommunity,
288
+ pageCids: newReplies.pageCids
289
+ });
290
+ }
291
+ }
292
+ }
293
+ async _verifyChallengeVerificationCommentProps(decryptedVerification) {
294
+ const log = Logger("pkc-js:comment:publish:_verifyChallengeVerificationCommentProps");
295
+ if (!this.raw.pubsubMessageToPublish)
296
+ throw Error("comment._pubsubMsgToPublish should be defined at this point");
297
+ // verify that the community did not change any props that we published
298
+ const keysToCompare = remeda.keys.strict(remeda.omit(this.raw.pubsubMessageToPublish, ["signature", "author"])); // we're omitting these two because that would fail because of anonymity features in community
299
+ const pubsubMsgFromCommentIpfs = remeda.pick(decryptedVerification.comment, keysToCompare);
300
+ const pubsubMsgFromPublishedPubsubMsg = remeda.pick(this.raw.pubsubMessageToPublish, keysToCompare);
301
+ if (!remeda.isDeepEqual(pubsubMsgFromCommentIpfs, pubsubMsgFromPublishedPubsubMsg)) {
302
+ const error = new PKCError("ERR_COMMUNITY_CHANGED_COMMENT_PUBSUB_PUBLICATION_PROPS", {
303
+ pubsubMsgFromSub: pubsubMsgFromCommentIpfs,
304
+ originalPubsubMsg: this.raw.pubsubMessageToPublish
305
+ });
306
+ log.error(error);
307
+ this.emit("error", error);
308
+ return error;
309
+ }
310
+ const calculatedCid = await calculateIpfsHash(JSON.stringify(decryptedVerification.comment));
311
+ const postCid = decryptedVerification.comment.postCid || (decryptedVerification.comment.depth === 0 ? calculatedCid : undefined);
312
+ if (!postCid) {
313
+ throw Error("Unable to calculate postCid after receiving challengeVerification for comment. This is either a critical error in pkc-js or the community did not include postCid in replies");
314
+ }
315
+ const commentIpfsValidity = await verifyCommentIpfs({
316
+ comment: decryptedVerification.comment,
317
+ resolveAuthorNames: this._pkc.resolveAuthorNames,
318
+ clientsManager: this._clientsManager,
319
+ calculatedCommentCid: calculatedCid
320
+ });
321
+ if (!commentIpfsValidity.valid) {
322
+ const error = new PKCError("ERR_COMMUNITY_SENT_CHALLENGE_VERIFICATION_WITH_INVALID_COMMENT", {
323
+ reason: commentIpfsValidity.reason,
324
+ decryptedChallengeVerification: decryptedVerification
325
+ });
326
+ log.error(error);
327
+ this.emit("error", error);
328
+ return error;
329
+ }
330
+ const commentUpdateValidity = await verifyCommentUpdate({
331
+ update: decryptedVerification.commentUpdate,
332
+ clientsManager: this._clientsManager,
333
+ comment: { ...decryptedVerification.comment, cid: calculatedCid, postCid },
334
+ community: this._community,
335
+ resolveAuthorNames: this._pkc.resolveAuthorNames,
336
+ validateUpdateSignature: true,
337
+ validatePages: true
338
+ });
339
+ if (!commentUpdateValidity.valid) {
340
+ const error = new PKCError("ERR_COMMUNITY_SENT_CHALLENGE_VERIFICATION_WITH_INVALID_COMMENTUPDATE", {
341
+ reason: commentUpdateValidity.reason,
342
+ decryptedChallengeVerification: decryptedVerification
343
+ });
344
+ log.error(error);
345
+ this.emit("error", error);
346
+ return error;
347
+ }
348
+ if (calculatedCid !== decryptedVerification.commentUpdate.cid) {
349
+ const error = new PKCError("ERR_COMMUNITY_SENT_CHALLENGE_VERIFICATION_WITH_INVALID_CID", {
350
+ cidSentBySub: decryptedVerification.commentUpdate.cid,
351
+ calculatedCid,
352
+ decryptedChallengeVerification: decryptedVerification
353
+ });
354
+ log.error(error);
355
+ this.emit("error", error);
356
+ return error;
357
+ }
358
+ }
359
+ async _addOwnCommentToIpfsIfConnectedToIpfsClient(decryptedVerification) {
360
+ // Will add and pin our own comment to IPFS
361
+ // only if we're connected to kubo or helia/libp2p
362
+ const log = Logger("pkc-js:comment:publish:_addOwnCommentToIpfsIfConnectedToIpfsClient");
363
+ if (!this.raw.comment)
364
+ throw Error("comment.raw.commentIpfs should be defined after challenge verification");
365
+ if (Object.keys(this._pkc.clients.kuboRpcClients).length === 0) {
366
+ log("No kubo rpc client found, will not add newly published comment", this.cid, "to ipfs");
367
+ return;
368
+ }
369
+ if (decryptedVerification.commentUpdate.pendingApproval) {
370
+ log("comment is pending approval, we're not gonna add it to IPFS node for now", this.cid);
371
+ return;
372
+ }
373
+ if (decryptedVerification.comment.signature.publicKey !== this.raw.pubsubMessageToPublish?.signature?.publicKey) {
374
+ log("We received a CommentIpfs whose publicKey is different than the one we published. We're gonna assume it's annoymized and skip adding to IPFS");
375
+ return;
376
+ }
377
+ const kuboRpcClient = this._clientsManager.getDefaultKuboRpcClient();
378
+ // use p-retry here, 3 times maybe?
379
+ const addRes = await retryKuboIpfsAdd({
380
+ ipfsClient: kuboRpcClient._client,
381
+ log: Logger("pkc-js:comment:publish:_addOwnCommentToIpfsIfConnectedToIpfsClient"),
382
+ content: JSON.stringify(this.raw.comment),
383
+ options: { pin: true }
384
+ });
385
+ if (!addRes.cid.equals(CID.parse(decryptedVerification.commentUpdate.cid)))
386
+ throw new PKCError("ERR_ADDED_COMMENT_IPFS_TO_IPFS_BUT_GOT_DIFFERENT_CID", {
387
+ addedCidToIpfs: addRes.cid,
388
+ expectedCidString: decryptedVerification.commentUpdate.cid,
389
+ expectedCid: CID.parse(decryptedVerification.commentUpdate.cid)
390
+ });
391
+ else
392
+ log("Added the file of comment ipfs", this.cid, "to IPFS network successfully");
393
+ }
394
+ _initCommentUpdateFromChallengeVerificationProps(commentUpdate) {
395
+ this.raw.commentUpdateFromChallengeVerification = commentUpdate;
396
+ if (commentUpdate.author)
397
+ Object.assign(this.author, commentUpdate.author);
398
+ this.protocolVersion = commentUpdate.protocolVersion;
399
+ if ("pendingApproval" in commentUpdate)
400
+ this.pendingApproval = commentUpdate.pendingApproval;
401
+ else
402
+ this.pendingApproval = false;
403
+ this.number = commentUpdate.number;
404
+ this.postNumber = commentUpdate.postNumber;
405
+ }
406
+ async _updateCommentPropsFromDecryptedChallengeVerification(decryptedVerification) {
407
+ const log = Logger("pkc-js:comment:publish:_updateCommentPropsFromDecryptedChallengeVerification");
408
+ this.setCid(decryptedVerification.commentUpdate.cid);
409
+ this._initIpfsProps(decryptedVerification.comment);
410
+ this._initCommentUpdateFromChallengeVerificationProps(decryptedVerification.commentUpdate);
411
+ // handle extra props here
412
+ const unknownProps = remeda.difference(remeda.keys.strict(decryptedVerification.commentUpdate), remeda.keys.strict(CommentUpdateForChallengeVerificationSchema.shape));
413
+ if (unknownProps.length > 0) {
414
+ log("Found unknown props on decryptedVerification.commentUpdate record", unknownProps, "Will set them on Comment instance");
415
+ Object.assign(this, remeda.pick(decryptedVerification.commentUpdate, unknownProps));
416
+ }
417
+ this.emit("update", this);
418
+ // RPC clients rely on the server for name resolution (sent via runtimeFields)
419
+ if (!this._pkc._pkcRpcClient) {
420
+ this._resolveAuthorNamesInBackground();
421
+ }
422
+ }
423
+ async _verifyDecryptedChallengeVerificationAndUpdateCommentProps(decryptedVerification) {
424
+ // We're gonna update Comment instance with DecryptedChallengeVerification.{comment, commentUpdate}
425
+ const log = Logger("pkc-js:comment:publish:_verifyDecryptedChallengeVerificationAndUpdateCommentProps");
426
+ log("Received update props from community after succcessful challenge exchange. Will attempt to validate if not connected to RPC", decryptedVerification);
427
+ if (!this._pkc._pkcRpcClient) {
428
+ // no need to validate if RPC
429
+ const errorInVerificationProps = await this._verifyChallengeVerificationCommentProps(decryptedVerification);
430
+ if (errorInVerificationProps)
431
+ return;
432
+ }
433
+ await this._updateCommentPropsFromDecryptedChallengeVerification(decryptedVerification);
434
+ // Add the comment to IPFS network in the background
435
+ if (Object.keys(this._pkc.clients.kuboRpcClients).length > 0 || Object.keys(this._pkc.clients.libp2pJsClients).length > 0)
436
+ this._addOwnCommentToIpfsIfConnectedToIpfsClient(decryptedVerification).catch((err) => log.error(`Failed to add the file of comment ipfs`, this.cid, "to ipfs network due to error", err));
437
+ }
438
+ getType() {
439
+ return "comment";
440
+ }
441
+ setCid(newCid) {
442
+ this.cid = newCid;
443
+ this.shortCid = shortifyCid(this.cid);
444
+ refreshTrackedCommentAliases(this._pkc, this);
445
+ }
446
+ setCommunityAddress(newCommunityAddress) {
447
+ super.setCommunityAddress(newCommunityAddress);
448
+ this.replies._community.address = newCommunityAddress;
449
+ }
450
+ _isCommentIpfsErrorRetriable(err) {
451
+ if (!(err instanceof PKCError))
452
+ return false; // If it's not a recognizable error, then we throw to notify the user
453
+ if (err.code === "ERR_COMMENT_IPFS_SIGNATURE_IS_INVALID" ||
454
+ err.code === "ERR_INVALID_COMMENT_IPFS_SCHEMA" ||
455
+ err.code === "ERR_CALCULATED_CID_DOES_NOT_MATCH" ||
456
+ err.code === "ERR_OVER_DOWNLOAD_LIMIT" ||
457
+ err.code === "ERR_INVALID_JSON" ||
458
+ err.code === "ERR_COMMENT_IPFS_COMMUNITY_ADDRESS_MISMATCH")
459
+ return false; // These errors means there's a problem with the record itself, not the loading
460
+ if (err instanceof FailedToFetchCommentIpfsFromGatewaysError) {
461
+ // If all gateway errors are due to the ipfs record itself, then it's a non-retriable error
462
+ for (const gatewayError of Object.values(err.details.gatewayToError))
463
+ if (this._isCommentIpfsErrorRetriable(gatewayError))
464
+ return true; // if there's at least one gateway whose error is not due to the record
465
+ return false; // if all gateways have issues with the record validity itself, then we stop fetching
466
+ }
467
+ return true;
468
+ }
469
+ async _retryLoadingCommentIpfs(cid, log) {
470
+ return new Promise((resolve) => {
471
+ this._commentIpfsloadingOperation.attempt(async (curAttempt) => {
472
+ if (this.raw.comment)
473
+ return resolve(this.raw.comment);
474
+ log.trace(`Retrying to load comment ipfs (${this.cid}) for the ${curAttempt}th time`);
475
+ try {
476
+ const commentInPage = this._clientsManager._findCommentInPagesOfUpdatingCommentsOrCommunity();
477
+ if (commentInPage) {
478
+ resolve(commentInPage.comment);
479
+ }
480
+ else {
481
+ this._setUpdatingStateWithEmissionIfNewState("fetching-ipfs");
482
+ const res = await this._clientsManager.fetchAndVerifyCommentCid(cid);
483
+ resolve(res);
484
+ }
485
+ }
486
+ catch (e) {
487
+ const error = e;
488
+ if (error.name === "AbortError")
489
+ return resolve(error);
490
+ if (error instanceof PKCError && error.details)
491
+ error.details = { ...error.details, commentCid: this.cid, retryCount: curAttempt };
492
+ if (this._isCommentIpfsErrorRetriable(error)) {
493
+ log.error(`Error on loading comment ipfs (${this.cid}) for the ${curAttempt}th time`, error);
494
+ this._changeCommentStateEmitEventEmitStateChangeEvent({
495
+ newUpdatingState: "waiting-retry",
496
+ event: { name: "error", args: [error] }
497
+ });
498
+ if (curAttempt === 1 && this.communityAddress) {
499
+ log("Failed the first time in loading comment", this.cid, "will try to load from community pages");
500
+ // if we fail for second time, start trying to find CommentIpfs using pages instead of comment.cid
501
+ await this._clientsManager._fetchCommentIpfsFromPages();
502
+ }
503
+ this._commentIpfsloadingOperation.retry(e);
504
+ }
505
+ else {
506
+ // a non retriable error
507
+ return resolve(e);
508
+ }
509
+ }
510
+ });
511
+ });
512
+ }
513
+ async _attemptToFetchCommentIpfsIfNeeded(log) {
514
+ if (this.cid && !this.raw.comment) {
515
+ // User may have attempted to call pkc.createComment({cid}).update
516
+ const newCommentIpfsOrNonRetriableError = await this._retryLoadingCommentIpfs(this.cid, log); // Will keep retrying to load until comment.stop() is called
517
+ if (newCommentIpfsOrNonRetriableError instanceof Error) {
518
+ if (isAbortError(newCommentIpfsOrNonRetriableError) && (this.state === "stopped" || this._isStopAbortRequested()))
519
+ return;
520
+ // This is a non-retriable error, it should stop the comment from updating
521
+ log.error(`Encountered a non retriable error while loading CommentIpfs (${this.cid}), will stop the update loop`, newCommentIpfsOrNonRetriableError);
522
+ // We can't proceed with an invalid CommentIpfs, so we're stopping the update loop and emitting an error event for the user
523
+ await this._stopUpdateLoop();
524
+ this._changeCommentStateEmitEventEmitStateChangeEvent({
525
+ newUpdatingState: "failed",
526
+ newState: "stopped",
527
+ event: { name: "error", args: [newCommentIpfsOrNonRetriableError] }
528
+ });
529
+ return;
530
+ }
531
+ else {
532
+ log(`Loaded the CommentIpfs props of cid (${this.cid}) correctly, updating the instance props`);
533
+ this._initIpfsProps(newCommentIpfsOrNonRetriableError);
534
+ this._changeCommentStateEmitEventEmitStateChangeEvent({
535
+ newUpdatingState: "succeeded",
536
+ event: { name: "update", args: [this] }
537
+ });
538
+ this._resolveAuthorNamesInBackground();
539
+ }
540
+ }
541
+ }
542
+ async _attemptInfintelyToLoadCommentIpfs() {
543
+ const log = Logger("pkc-js:comment:update:attemptInfintelyToLoadCommentIpfs");
544
+ this._commentIpfsloadingOperation = retry.operation({ forever: true, factor: 2 });
545
+ await this._attemptToFetchCommentIpfsIfNeeded(log);
546
+ await this._commentIpfsloadingOperation.stop();
547
+ }
548
+ async startCommentUpdateCommunitySubscription() {
549
+ const log = Logger("pkc-js:comment:update:startCommentUpdateCommunitySubscription");
550
+ if (this.state === "stopped")
551
+ return; // we may have called stop() before reaching comment update subscription and after loading commentipfs
552
+ if (this.depth === 0) {
553
+ if (!this._communityForUpdating)
554
+ this._communityForUpdating = await this._clientsManager._createCommunityInstanceWithStateTranslation();
555
+ if (this.state !== "updating")
556
+ return; // there are cases where stop() is called in parallel
557
+ if (this._communityForUpdating.community.state === "stopped") {
558
+ await this._communityForUpdating.community.update(); // BUG: calling this resets this._communityForUpdating to undefined
559
+ }
560
+ if (this.state !== "updating")
561
+ return; // there are cases where stop() is called in parallel
562
+ if (this._communityForUpdating.community.raw.communityIpfs)
563
+ await this._communityForUpdating.update(this._communityForUpdating.community);
564
+ }
565
+ else {
566
+ if (!this._postForUpdating)
567
+ this._postForUpdating = await this._clientsManager._createPostInstanceWithStateTranslation();
568
+ if (this.state !== "updating")
569
+ return; // there are cases where stop() is called in parallel
570
+ if (this._postForUpdating.comment.state === "stopped") {
571
+ await this._postForUpdating.comment.update();
572
+ }
573
+ if (this.state !== "updating")
574
+ return; // there are cases where stop() is called in parallel
575
+ if (this._postForUpdating.comment.raw.commentUpdate)
576
+ await this._postForUpdating.update(this._postForUpdating.comment);
577
+ }
578
+ }
579
+ async loadCommentIpfsAndStartCommentUpdateSubscription() {
580
+ const log = Logger("pkc-js:update:loadCommentIpfsAndStartCommentUpdateSubscription");
581
+ this._createStopAbortController();
582
+ await this._attemptInfintelyToLoadCommentIpfs();
583
+ if (!this.raw.comment) {
584
+ if (this.state === "stopped" || this._isStopAbortRequested())
585
+ return;
586
+ throw Error("Failed to load comment ipfs, user needs to check error event");
587
+ }
588
+ try {
589
+ await this.startCommentUpdateCommunitySubscription(); // can only proceed if commentIpfs has been loaded successfully
590
+ }
591
+ catch (e) {
592
+ if (isAbortError(e) && (this.state === "stopped" || this._isStopAbortRequested()))
593
+ return;
594
+ log.error("Failed to start comment update subscription to community", e);
595
+ }
596
+ }
597
+ _setUpdatingStateNoEmission(newState) {
598
+ if (newState === this._updatingState)
599
+ return;
600
+ this._updatingState = newState;
601
+ }
602
+ get updatingState() {
603
+ if (this._updatingCommentInstance) {
604
+ const mirroredComment = this._updatingCommentInstance.comment;
605
+ if (mirroredComment === this)
606
+ return this._updatingState; // prevent self-mirroring recursion
607
+ return mirroredComment.updatingState;
608
+ }
609
+ return this._updatingState;
610
+ }
611
+ _changeCommentStateEmitEventEmitStateChangeEvent(opts) {
612
+ // this code block is only called on a comment whose update loop is already started
613
+ // never called in a comment that's mirroring a comment with an update loop
614
+ const shouldEmitStateChange = opts.newState && opts.newState !== this.state;
615
+ const shouldEmitUpdatingStateChange = opts.newUpdatingState && opts.newUpdatingState !== this._updatingState;
616
+ if (opts.newState)
617
+ this._setStateNoEmission(opts.newState);
618
+ if (opts.newUpdatingState)
619
+ this._setUpdatingStateNoEmission(opts.newUpdatingState);
620
+ this.emit(opts.event.name, ...opts.event.args);
621
+ if (shouldEmitStateChange)
622
+ this.emit("statechange", this.state);
623
+ if (shouldEmitUpdatingStateChange)
624
+ this.emit("updatingstatechange", this.updatingState);
625
+ }
626
+ _setUpdatingStateWithEmissionIfNewState(newState) {
627
+ if (newState === this._updatingState)
628
+ return;
629
+ this._updatingState = newState;
630
+ this.emit("updatingstatechange", this._updatingState);
631
+ }
632
+ _setRpcClientState(newState) {
633
+ const currentRpcUrl = remeda.keys.strict(this.clients.pkcRpcClients)[0];
634
+ if (newState === this.clients.pkcRpcClients[currentRpcUrl].state)
635
+ return;
636
+ this.clients.pkcRpcClients[currentRpcUrl].state = newState;
637
+ this.clients.pkcRpcClients[currentRpcUrl].emit("statechange", newState);
638
+ }
639
+ _updateRpcClientStateFromUpdatingState(updatingState) {
640
+ // We're deriving the the rpc state from publishing state
641
+ const mapper = {
642
+ failed: "stopped",
643
+ succeeded: "stopped",
644
+ "fetching-ipfs": "fetching-ipfs",
645
+ "waiting-retry": "stopped",
646
+ "fetching-community-ipfs": "fetching-community-ipfs",
647
+ "fetching-community-ipns": "fetching-community-ipns",
648
+ "fetching-update-ipfs": "fetching-update-ipfs",
649
+ "resolving-author-name": "resolving-author-name",
650
+ "resolving-community-name": "resolving-community-name",
651
+ stopped: "stopped"
652
+ };
653
+ const rpcState = mapper[updatingState] || updatingState; // in case rpc server transmits unknown prop, just use it as is
654
+ this._setRpcClientState(rpcState);
655
+ }
656
+ _isRetriableLoadingError(err) {
657
+ // Critical Errors for now are:
658
+ // Invalid signature of CommentIpfs
659
+ // CommentUpdate will always be retried when a new community update is loaded
660
+ if (this.raw.comment)
661
+ return true; // if we already loaded CommentIpfs, we should always retry loading CommentUpdate
662
+ else
663
+ return this._isCommentIpfsErrorRetriable(err);
664
+ }
665
+ _handleCommentEventFromRpc(args) {
666
+ const log = Logger("pkc-js:comment:_handleCommentEventFromRpc");
667
+ let parsed;
668
+ try {
669
+ parsed = parseRpcCommentEventWithPKCErrorIfItFails(args.params.result);
670
+ }
671
+ catch (e) {
672
+ log.error("Failed to parse the rpc comment event of", this.cid, e);
673
+ this.emit("error", e);
674
+ throw e;
675
+ }
676
+ log(`Received new CommentIpfs (${this.cid}) from RPC`);
677
+ this._initIpfsProps(parsed.comment);
678
+ if (parsed.runtimeFields)
679
+ deepMergeRuntimeFields(this, parsed.runtimeFields);
680
+ this.emit("update", this);
681
+ }
682
+ _handleUpdateEventFromRpc(args) {
683
+ const log = Logger("pkc-js:comment:_handleUpdateEventFromRpc");
684
+ let parsed;
685
+ try {
686
+ parsed = parseRpcCommentUpdateEventWithPKCErrorIfItFails(args.params.result);
687
+ }
688
+ catch (e) {
689
+ log.error("Failed to parse the rpc update event of", this.cid, e);
690
+ this.emit("error", e);
691
+ throw e;
692
+ }
693
+ const newUpdate = parsed.commentUpdate;
694
+ if ((this.updatedAt || 0) <= newUpdate.updatedAt) {
695
+ log(`Received new CommentUpdate (${this.cid}) from RPC`);
696
+ this._initCommentUpdate(newUpdate);
697
+ if (parsed.runtimeFields) {
698
+ this.raw.runtimeFieldsFromRpc = parsed.runtimeFields;
699
+ deepMergeRuntimeFields(this, parsed.runtimeFields);
700
+ }
701
+ this.emit("update", this);
702
+ // RPC clients rely on the server for name resolution (sent via runtimeFields);
703
+ // client-side resolution would incorrectly set nameResolved=false since nameResolvers is undefined
704
+ if (!this._pkc._pkcRpcClient) {
705
+ this._resolveAuthorNamesInBackground();
706
+ }
707
+ }
708
+ }
709
+ _handleRuntimeUpdateEventFromRpc(args) {
710
+ const runtimeFields = args.params.result;
711
+ if (runtimeFields) {
712
+ deepMergeRuntimeFields(this, runtimeFields);
713
+ }
714
+ this.emit("update", this);
715
+ }
716
+ _handleUpdatingStateChangeFromRpc(args) {
717
+ const updateState = args.params.result.state; // optimistic, rpc server could transmit an updating state that is not known to us
718
+ this._setUpdatingStateWithEmissionIfNewState(updateState);
719
+ this._updateRpcClientStateFromUpdatingState(updateState);
720
+ }
721
+ _handleStateChangeFromRpc(args) {
722
+ const commentState = args.params.result.state;
723
+ this._setStateWithEmission(commentState);
724
+ }
725
+ async _handleErrorEventFromRpc(args) {
726
+ const log = Logger("pkc-js:comment:update:_handleErrorEventFromRpc");
727
+ const err = args.params.result;
728
+ log("Received 'error' event from RPC", err);
729
+ if (err.details?.newUpdatingState)
730
+ this._setUpdatingStateNoEmission(err.details.newUpdatingState);
731
+ if (!this._isRetriableLoadingError(err)) {
732
+ log.error("The RPC transmitted a non retriable error", "for comment", this.cid, "will clean up the subscription", err);
733
+ this._changeCommentStateEmitEventEmitStateChangeEvent({
734
+ newUpdatingState: "failed",
735
+ newState: "stopped",
736
+ event: { name: "error", args: [err] }
737
+ });
738
+ await this._stopUpdateLoop();
739
+ }
740
+ else
741
+ this.emit("error", err);
742
+ }
743
+ async _updateViaRpc() {
744
+ const log = Logger("pkc-js:comment:update:_updateViaRpc");
745
+ const rpcUrl = this._pkc.pkcRpcClientsOptions[0];
746
+ if (!rpcUrl)
747
+ throw Error("Failed to get rpc url");
748
+ if (!this.cid)
749
+ throw Error("Can't start updating comment without defining this.cid");
750
+ try {
751
+ this._updateRpcSubscriptionId = await this._pkc._pkcRpcClient.commentUpdateSubscribe({
752
+ cid: this.cid,
753
+ raw: this.raw,
754
+ communityAddress: this.communityAddress,
755
+ parentCid: this.parentCid,
756
+ postCid: this.postCid
757
+ });
758
+ }
759
+ catch (e) {
760
+ log.error("Failed to receive commentUpdate from RPC due to error", e);
761
+ await this._stopUpdateLoop();
762
+ this._setStateWithEmission("stopped");
763
+ this._setUpdatingStateWithEmissionIfNewState("failed");
764
+ throw e;
765
+ }
766
+ this._setStateWithEmission("updating");
767
+ this._pkc
768
+ ._pkcRpcClient.getSubscription(this._updateRpcSubscriptionId)
769
+ .on("update", this._handleUpdateEventFromRpc.bind(this))
770
+ .on("comment", this._handleCommentEventFromRpc.bind(this))
771
+ .on("runtimeupdate", this._handleRuntimeUpdateEventFromRpc.bind(this))
772
+ .on("updatingstatechange", this._handleUpdatingStateChangeFromRpc.bind(this))
773
+ .on("statechange", this._handleStateChangeFromRpc.bind(this))
774
+ .on("error", this._handleErrorEventFromRpc.bind(this));
775
+ this._pkc._pkcRpcClient.emitAllPendingMessages(this._updateRpcSubscriptionId);
776
+ }
777
+ _useUpdatePropsFromUpdatingStartedCommunityIfPossible() {
778
+ if (!this.cid)
779
+ throw Error("Need to have comment.cid defined");
780
+ if (!this.communityAddress) {
781
+ // try to find cid in all _updatingCommunities
782
+ for (const updatingCommunity of [...listUpdatingCommunities(this._pkc), ...listStartedCommunities(this._pkc)]) {
783
+ const commentInCommunityPosts = findCommentInPageInstanceRecursively(updatingCommunity.posts, this.cid);
784
+ if (commentInCommunityPosts) {
785
+ const addr = getCommunityAddressFromRecord(commentInCommunityPosts.comment);
786
+ if (addr)
787
+ this.setCommunityAddress(addr);
788
+ break;
789
+ }
790
+ }
791
+ if (!this.communityAddress)
792
+ return;
793
+ }
794
+ const updatingCommunityInstance = findUpdatingCommunity(this._pkc, { address: this.communityAddress }) ||
795
+ this._communityForUpdating?.community ||
796
+ findStartedCommunity(this._pkc, { address: this.communityAddress });
797
+ if (updatingCommunityInstance?.raw?.communityIpfs && this.cid) {
798
+ const commentInCommunityPosts = findCommentInPageInstanceRecursively(updatingCommunityInstance.posts, this.cid);
799
+ if (commentInCommunityPosts) {
800
+ if (!this.raw.comment) {
801
+ this._initIpfsProps(commentInCommunityPosts.comment);
802
+ this.emit("update", this);
803
+ // Don't call _resolveAuthorNamesInBackground() here — this runs during createComment()
804
+ // before the stop abort controller exists. Resolution is handled by the update loop.
805
+ }
806
+ if ((this.updatedAt || 0) < commentInCommunityPosts.commentUpdate.updatedAt) {
807
+ this._initCommentUpdate(commentInCommunityPosts.commentUpdate, updatingCommunityInstance.raw.communityIpfs);
808
+ this.emit("update", this);
809
+ }
810
+ }
811
+ }
812
+ }
813
+ _useUpdatePropsFromUpdatingCommentIfPossible() {
814
+ if (!this.cid)
815
+ throw Error("should have cid at this point");
816
+ const updatingCommentInstance = findUpdatingComment(this._pkc, { cid: this.cid }) || this._updatingCommentInstance?.comment;
817
+ if (updatingCommentInstance) {
818
+ // TODO maybe we should just copy props with Object.assign? not sure
819
+ if (!this.raw.comment && updatingCommentInstance.raw.comment) {
820
+ this._initIpfsProps(updatingCommentInstance.raw.comment);
821
+ this._copyNameResolvedFromComment(updatingCommentInstance);
822
+ this.emit("update", this);
823
+ // Don't call _resolveAuthorNamesInBackground() here — the updating instance already handles resolution.
824
+ // This mirroring comment copies results via _copyNameResolvedFromComment.
825
+ }
826
+ if (updatingCommentInstance.raw.commentUpdate && (this.updatedAt || 0) < updatingCommentInstance.raw.commentUpdate.updatedAt) {
827
+ this._initCommentUpdate(updatingCommentInstance.raw.commentUpdate, updatingCommentInstance._communityForUpdating?.community?.raw.communityIpfs);
828
+ this._commentUpdateIpfsPath = updatingCommentInstance._commentUpdateIpfsPath;
829
+ this._copyNameResolvedFromComment(updatingCommentInstance);
830
+ if (updatingCommentInstance.raw.runtimeFieldsFromRpc)
831
+ deepMergeRuntimeFields(this, updatingCommentInstance.raw.runtimeFieldsFromRpc);
832
+ this.emit("update", this);
833
+ }
834
+ // Propagate nameResolved changes even when neither CommentIpfs nor CommentUpdate
835
+ // triggered a copy — background resolution can complete between those events
836
+ if (this.raw.comment) {
837
+ const prevNameResolved = this.author.nameResolved;
838
+ this._copyNameResolvedFromComment(updatingCommentInstance);
839
+ if (this.author.nameResolved !== prevNameResolved) {
840
+ this.emit("update", this);
841
+ }
842
+ }
843
+ }
844
+ else {
845
+ const ancestorAndUpdatingCids = [
846
+ this.postCid,
847
+ this.parentCid,
848
+ ...listUpdatingComments(this._pkc).map((comment) => comment.cid)
849
+ ];
850
+ for (const ancestorCid of ancestorAndUpdatingCids) {
851
+ if (!ancestorCid)
852
+ continue;
853
+ const updatingCommentInstanceOfAncestor = findUpdatingComment(this._pkc, { cid: ancestorCid });
854
+ if (updatingCommentInstanceOfAncestor) {
855
+ const commentInAncestor = findCommentInPageInstanceRecursively(updatingCommentInstanceOfAncestor.replies, this.cid);
856
+ if (commentInAncestor) {
857
+ if (!this.raw.comment) {
858
+ this._initIpfsProps(commentInAncestor.comment);
859
+ this.emit("update", this);
860
+ }
861
+ if ((this.updatedAt || 0) < commentInAncestor.commentUpdate.updatedAt) {
862
+ this._initCommentUpdate(commentInAncestor.commentUpdate, findUpdatingCommunity(this._pkc, { address: this.communityAddress })?.raw?.communityIpfs);
863
+ this.emit("update", this);
864
+ }
865
+ break; // if we found it once we won't be finding it in other comments
866
+ }
867
+ }
868
+ }
869
+ }
870
+ }
871
+ _useUpdatingCommentFromPKC(updatingCommentInstance) {
872
+ if (updatingCommentInstance === this)
873
+ return; // don't mirror to itself; prevents recursive events
874
+ this._updatingCommentInstance = {
875
+ comment: updatingCommentInstance,
876
+ statechange: async (newState) => {
877
+ if (newState === "stopped" && this.state === "updating")
878
+ // pkc._updatingComments[this.cid].stop() has been called
879
+ await this.stop();
880
+ },
881
+ update: () => this._useUpdatePropsFromUpdatingCommentIfPossible(),
882
+ updatingstatechange: (newState) => this.emit("updatingstatechange", newState),
883
+ error: async (err) => {
884
+ if (!this._isRetriableLoadingError(err)) {
885
+ this._changeCommentStateEmitEventEmitStateChangeEvent({
886
+ newUpdatingState: "failed",
887
+ newState: "stopped",
888
+ event: { name: "error", args: [err] }
889
+ });
890
+ await this._stopUpdateLoop();
891
+ }
892
+ else
893
+ this.emit("error", err);
894
+ }
895
+ };
896
+ updatingCommentInstance.on("update", this._updatingCommentInstance.update);
897
+ updatingCommentInstance.on("error", this._updatingCommentInstance.error);
898
+ updatingCommentInstance.on("updatingstatechange", this._updatingCommentInstance.updatingstatechange);
899
+ updatingCommentInstance.on("statechange", this._updatingCommentInstance.statechange);
900
+ const clientKeys = remeda.keys.strict(this.clients);
901
+ for (const clientType of clientKeys)
902
+ if (this.clients[clientType])
903
+ for (const clientUrl of Object.keys(this.clients[clientType]))
904
+ this.clients[clientType][clientUrl].mirror(updatingCommentInstance.clients[clientType][clientUrl]);
905
+ updatingCommentInstance._numOfListenersForUpdatingInstance++;
906
+ this._useUpdatePropsFromUpdatingCommentIfPossible();
907
+ }
908
+ async _setUpNewUpdatingCommentInstance() {
909
+ // create a new pkc._updatingComments[this.cid]
910
+ const log = Logger("pkc-js:comment:update:_setUpNewUpdatingCommentInstance");
911
+ const updatingCommentInstance = await this._pkc.createComment(this);
912
+ trackUpdatingComment(this._pkc, updatingCommentInstance);
913
+ this._useUpdatingCommentFromPKC(updatingCommentInstance);
914
+ updatingCommentInstance._setStateWithEmission("updating");
915
+ if (this._pkc._pkcRpcClient) {
916
+ await updatingCommentInstance._updateViaRpc();
917
+ }
918
+ else {
919
+ updatingCommentInstance
920
+ .loadCommentIpfsAndStartCommentUpdateSubscription()
921
+ .catch((e) => log.error("Failed to update comment", e));
922
+ }
923
+ }
924
+ async update() {
925
+ const log = Logger("pkc-js:comment:update");
926
+ if (this.state === "updating")
927
+ return; // Do nothing if it's already updating
928
+ if (!this.cid)
929
+ throw Error("Can't call comment.update() without defining cid");
930
+ this._setStateWithEmission("updating");
931
+ const existingUpdatingComment = findUpdatingComment(this._pkc, { cid: this.cid });
932
+ if (existingUpdatingComment) {
933
+ if (existingUpdatingComment === this) {
934
+ // This instance is already tracked; start the update loop without mirroring to itself
935
+ if (this._pkc._pkcRpcClient) {
936
+ await this._updateViaRpc();
937
+ }
938
+ else {
939
+ this.loadCommentIpfsAndStartCommentUpdateSubscription().catch((e) => log.error("Failed to update comment", e));
940
+ }
941
+ }
942
+ else
943
+ this._useUpdatingCommentFromPKC(existingUpdatingComment); // this comment instance will be mirroring this._pkc._updatingComments[this.cid]
944
+ }
945
+ else
946
+ await this._setUpNewUpdatingCommentInstance(); // Create a this._pkc._updatingComments[this.cid], then mirror it
947
+ if (this.raw.comment || this.raw.commentUpdate)
948
+ this.emit("update", this);
949
+ }
950
+ async _stopUpdateLoop() {
951
+ const log = Logger("pkc-js:comment:update:_stopUpdateLoop");
952
+ if (!this.cid)
953
+ return;
954
+ this._commentIpfsloadingOperation?.stop();
955
+ if (this._updateRpcSubscriptionId) {
956
+ try {
957
+ await this._pkc._pkcRpcClient.unsubscribe(this._updateRpcSubscriptionId);
958
+ }
959
+ catch (e) {
960
+ log.error("Failed to unsubscribe from commentUpdate", e);
961
+ }
962
+ this._updateRpcSubscriptionId = undefined;
963
+ this._setRpcClientState("stopped");
964
+ untrackUpdatingComment(this._pkc, this);
965
+ }
966
+ // what if it didn't have enough time to set up _communityForUpdating and _postForUpdating? These are defined after loading CommentIpfs
967
+ if (!this._postForUpdating &&
968
+ !this._communityForUpdating &&
969
+ !this._updatingCommentInstance &&
970
+ findUpdatingComment(this._pkc, { cid: this.cid }) === this) {
971
+ // comment.stop got called before updating community or post instance was created
972
+ untrackUpdatingComment(this._pkc, this);
973
+ }
974
+ // clean up _communityForUpdating subscriptions
975
+ if (this._communityForUpdating) {
976
+ // this post instance is pkc._updatingComments[cid] and it's updating
977
+ await this._clientsManager.cleanUpUpdatingCommunityInstance();
978
+ this._communityForUpdating = undefined;
979
+ untrackUpdatingComment(this._pkc, this);
980
+ this._invalidCommentUpdateMfsPaths.clear();
981
+ }
982
+ if (this._postForUpdating) {
983
+ // this reply instance is subscribed to an updating post
984
+ await this._clientsManager.cleanUpUpdatingPostInstance();
985
+ this._postForUpdating = undefined;
986
+ untrackUpdatingComment(this._pkc, this);
987
+ }
988
+ if (this._updatingCommentInstance) {
989
+ // this post|reply instance is subscribed to pkc._updatingComments[cid]
990
+ this._updatingState = this._updatingCommentInstance.comment.updatingState; // need to capture the last updating state before stopping
991
+ this._updatingCommentInstance.comment.removeListener("statechange", this._updatingCommentInstance.statechange);
992
+ this._updatingCommentInstance.comment.removeListener("updatingstatechange", this._updatingCommentInstance.updatingstatechange);
993
+ this._updatingCommentInstance.comment.removeListener("update", this._updatingCommentInstance.update);
994
+ this._updatingCommentInstance.comment.removeListener("error", this._updatingCommentInstance.error);
995
+ const clientKeys = remeda.keys.strict(this.clients);
996
+ for (const clientType of clientKeys)
997
+ if (this.clients[clientType])
998
+ for (const clientUrl of Object.keys(this.clients[clientType]))
999
+ this.clients[clientType][clientUrl].unmirror();
1000
+ this._updatingCommentInstance.comment._numOfListenersForUpdatingInstance--;
1001
+ if (this._updatingCommentInstance.comment._numOfListenersForUpdatingInstance === 0 &&
1002
+ this._updatingCommentInstance.comment.state !== "stopped") {
1003
+ log("Cleaning up pkc._updatingComments", this.cid, "There are no comments using it for updates");
1004
+ await this._updatingCommentInstance.comment.stop();
1005
+ }
1006
+ else if (this._updatingCommentInstance.comment._numOfListenersForUpdatingInstance === 0 &&
1007
+ this._updatingCommentInstance.comment.state === "stopped" &&
1008
+ findUpdatingComment(this._pkc, { cid: this.cid }) === this._updatingCommentInstance.comment) {
1009
+ // No listeners left and the updating comment is already stopped; remove the stale entry
1010
+ untrackUpdatingComment(this._pkc, this._updatingCommentInstance.comment);
1011
+ }
1012
+ this._updatingCommentInstance = undefined;
1013
+ }
1014
+ this._clearStopAbortController();
1015
+ }
1016
+ async stop() {
1017
+ this._abortStopOperations(`Aborting comment operations for ${this.cid || this.author?.address || "comment"} because comment.stop() was called`);
1018
+ if (this.state === "publishing")
1019
+ await super.stop();
1020
+ this._setStateWithEmission("stopped");
1021
+ await this._stopUpdateLoop();
1022
+ this.replies._stop();
1023
+ this._setUpdatingStateWithEmissionIfNewState("stopped");
1024
+ }
1025
+ async _validateSignatureHook() {
1026
+ const stopAbortController = this._createStopAbortController();
1027
+ const commentObj = JSON.parse(JSON.stringify(this.raw.pubsubMessageToPublish)); // Stringify so it resembles messages from pubsub
1028
+ try {
1029
+ const signatureValidity = await verifyCommentPubsubMessage({
1030
+ comment: commentObj,
1031
+ resolveAuthorNames: this._pkc.resolveAuthorNames,
1032
+ clientsManager: this._clientsManager,
1033
+ abortSignal: stopAbortController.signal
1034
+ });
1035
+ if (!signatureValidity.valid)
1036
+ throw new PKCError("ERR_SIGNATURE_IS_INVALID", { signatureValidity });
1037
+ }
1038
+ finally {
1039
+ if (this.state !== "updating")
1040
+ this._clearStopAbortController();
1041
+ }
1042
+ }
1043
+ }
1044
+ //# sourceMappingURL=comment.js.map