@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.
- package/LICENSE +339 -0
- package/README.md +1663 -0
- package/dist/browser/challenges.d.ts +1 -0
- package/dist/browser/challenges.js +2 -0
- package/dist/browser/challenges.js.map +1 -0
- package/dist/browser/clients/base-client-manager.d.ts +126 -0
- package/dist/browser/clients/base-client-manager.js +673 -0
- package/dist/browser/clients/base-client-manager.js.map +1 -0
- package/dist/browser/clients/name-resolver-client.d.ts +8 -0
- package/dist/browser/clients/name-resolver-client.js +10 -0
- package/dist/browser/clients/name-resolver-client.js.map +1 -0
- package/dist/browser/clients/pkc-typed-emitter.d.ts +9 -0
- package/dist/browser/clients/pkc-typed-emitter.js +52 -0
- package/dist/browser/clients/pkc-typed-emitter.js.map +1 -0
- package/dist/browser/clients/rpc-client/decode-rpc-response-util.d.ts +8 -0
- package/dist/browser/clients/rpc-client/decode-rpc-response-util.js +53 -0
- package/dist/browser/clients/rpc-client/decode-rpc-response-util.js.map +1 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +68 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js +404 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -0
- package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +147 -0
- package/dist/browser/clients/rpc-client/rpc-schema-util.js +11 -0
- package/dist/browser/clients/rpc-client/rpc-schema-util.js.map +1 -0
- package/dist/browser/clients/rpc-client/schema.d.ts +433 -0
- package/dist/browser/clients/rpc-client/schema.js +49 -0
- package/dist/browser/clients/rpc-client/schema.js.map +1 -0
- package/dist/browser/clients/rpc-client/types.d.ts +8 -0
- package/dist/browser/clients/rpc-client/types.js +2 -0
- package/dist/browser/clients/rpc-client/types.js.map +1 -0
- package/dist/browser/community/community-client-manager.d.ts +60 -0
- package/dist/browser/community/community-client-manager.js +717 -0
- package/dist/browser/community/community-client-manager.js.map +1 -0
- package/dist/browser/community/community-clients.d.ts +18 -0
- package/dist/browser/community/community-clients.js +12 -0
- package/dist/browser/community/community-clients.js.map +1 -0
- package/dist/browser/community/community-wire.d.ts +20 -0
- package/dist/browser/community/community-wire.js +38 -0
- package/dist/browser/community/community-wire.js.map +1 -0
- package/dist/browser/community/remote-community.d.ts +110 -0
- package/dist/browser/community/remote-community.js +555 -0
- package/dist/browser/community/remote-community.js.map +1 -0
- package/dist/browser/community/rpc-local-community.d.ts +41 -0
- package/dist/browser/community/rpc-local-community.js +289 -0
- package/dist/browser/community/rpc-local-community.js.map +1 -0
- package/dist/browser/community/rpc-remote-community.d.ts +18 -0
- package/dist/browser/community/rpc-remote-community.js +286 -0
- package/dist/browser/community/rpc-remote-community.js.map +1 -0
- package/dist/browser/community/schema.d.ts +4217 -0
- package/dist/browser/community/schema.js +289 -0
- package/dist/browser/community/schema.js.map +1 -0
- package/dist/browser/community/types.d.ts +135 -0
- package/dist/browser/community/types.js +2 -0
- package/dist/browser/community/types.js.map +1 -0
- package/dist/browser/constants.d.ts +6 -0
- package/dist/browser/constants.js +9 -0
- package/dist/browser/constants.js.map +1 -0
- package/dist/browser/decorator-util.d.ts +1 -0
- package/dist/browser/decorator-util.js +35 -0
- package/dist/browser/decorator-util.js.map +1 -0
- package/dist/browser/errors.d.ts +343 -0
- package/dist/browser/errors.js +358 -0
- package/dist/browser/errors.js.map +1 -0
- package/dist/browser/general-util/limited-set.d.ts +15 -0
- package/dist/browser/general-util/limited-set.js +66 -0
- package/dist/browser/general-util/limited-set.js.map +1 -0
- package/dist/browser/generated-version.d.ts +1 -0
- package/dist/browser/generated-version.js +3 -0
- package/dist/browser/generated-version.js.map +1 -0
- package/dist/browser/generic-state-client.d.ts +6 -0
- package/dist/browser/generic-state-client.js +11 -0
- package/dist/browser/generic-state-client.js.map +1 -0
- package/dist/browser/helia/helia-for-pkc.d.ts +3 -0
- package/dist/browser/helia/helia-for-pkc.js +255 -0
- package/dist/browser/helia/helia-for-pkc.js.map +1 -0
- package/dist/browser/helia/ipns-over-pubsub-with-fetch.d.ts +36 -0
- package/dist/browser/helia/ipns-over-pubsub-with-fetch.js +229 -0
- package/dist/browser/helia/ipns-over-pubsub-with-fetch.js.map +1 -0
- package/dist/browser/helia/libp2pjsClient.d.ts +27 -0
- package/dist/browser/helia/libp2pjsClient.js +15 -0
- package/dist/browser/helia/libp2pjsClient.js.map +1 -0
- package/dist/browser/helia/types.d.ts +19 -0
- package/dist/browser/helia/types.js +2 -0
- package/dist/browser/helia/types.js.map +1 -0
- package/dist/browser/helia/util.d.ts +13 -0
- package/dist/browser/helia/util.js +98 -0
- package/dist/browser/helia/util.js.map +1 -0
- package/dist/browser/index.d.ts +244 -0
- package/dist/browser/index.js +36 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/logger.d.ts +12 -0
- package/dist/browser/logger.js +11 -0
- package/dist/browser/logger.js.map +1 -0
- package/dist/browser/pages/pages-client-manager.d.ts +159 -0
- package/dist/browser/pages/pages-client-manager.js +334 -0
- package/dist/browser/pages/pages-client-manager.js.map +1 -0
- package/dist/browser/pages/pages-clients.d.ts +11 -0
- package/dist/browser/pages/pages-clients.js +10 -0
- package/dist/browser/pages/pages-clients.js.map +1 -0
- package/dist/browser/pages/pages.d.ts +107 -0
- package/dist/browser/pages/pages.js +262 -0
- package/dist/browser/pages/pages.js.map +1 -0
- package/dist/browser/pages/schema-util.d.ts +3 -0
- package/dist/browser/pages/schema-util.js +3 -0
- package/dist/browser/pages/schema-util.js.map +1 -0
- package/dist/browser/pages/schema.d.ts +719 -0
- package/dist/browser/pages/schema.js +32 -0
- package/dist/browser/pages/schema.js.map +1 -0
- package/dist/browser/pages/types.d.ts +44 -0
- package/dist/browser/pages/types.js +2 -0
- package/dist/browser/pages/types.js.map +1 -0
- package/dist/browser/pages/util.d.ts +56 -0
- package/dist/browser/pages/util.js +446 -0
- package/dist/browser/pages/util.js.map +1 -0
- package/dist/browser/pkc/pkc-client-manager.d.ts +44 -0
- package/dist/browser/pkc/pkc-client-manager.js +156 -0
- package/dist/browser/pkc/pkc-client-manager.js.map +1 -0
- package/dist/browser/pkc/pkc-clients.d.ts +11 -0
- package/dist/browser/pkc/pkc-clients.js +8 -0
- package/dist/browser/pkc/pkc-clients.js.map +1 -0
- package/dist/browser/pkc/pkc-with-rpc-client.d.ts +19 -0
- package/dist/browser/pkc/pkc-with-rpc-client.js +128 -0
- package/dist/browser/pkc/pkc-with-rpc-client.js.map +1 -0
- package/dist/browser/pkc/pkc.d.ts +137 -0
- package/dist/browser/pkc/pkc.js +888 -0
- package/dist/browser/pkc/pkc.js.map +1 -0
- package/dist/browser/pkc/tracked-instance-registry-util.d.ts +44 -0
- package/dist/browser/pkc/tracked-instance-registry-util.js +106 -0
- package/dist/browser/pkc/tracked-instance-registry-util.js.map +1 -0
- package/dist/browser/pkc/tracked-instance-registry.d.ts +18 -0
- package/dist/browser/pkc/tracked-instance-registry.js +134 -0
- package/dist/browser/pkc/tracked-instance-registry.js.map +1 -0
- package/dist/browser/pkc-error.d.ts +65 -0
- package/dist/browser/pkc-error.js +137 -0
- package/dist/browser/pkc-error.js.map +1 -0
- package/dist/browser/publications/comment/comment-client-manager.d.ts +86 -0
- package/dist/browser/publications/comment/comment-client-manager.js +908 -0
- package/dist/browser/publications/comment/comment-client-manager.js.map +1 -0
- package/dist/browser/publications/comment/comment-clients.d.ts +19 -0
- package/dist/browser/publications/comment/comment-clients.js +12 -0
- package/dist/browser/publications/comment/comment-clients.js.map +1 -0
- package/dist/browser/publications/comment/comment-util.d.ts +10 -0
- package/dist/browser/publications/comment/comment-util.js +202 -0
- package/dist/browser/publications/comment/comment-util.js.map +1 -0
- package/dist/browser/publications/comment/comment.d.ts +147 -0
- package/dist/browser/publications/comment/comment.js +1044 -0
- package/dist/browser/publications/comment/comment.js.map +1 -0
- package/dist/browser/publications/comment/schema.d.ts +1237 -0
- package/dist/browser/publications/comment/schema.js +184 -0
- package/dist/browser/publications/comment/schema.js.map +1 -0
- package/dist/browser/publications/comment/types.d.ts +100 -0
- package/dist/browser/publications/comment/types.js +2 -0
- package/dist/browser/publications/comment/types.js.map +1 -0
- package/dist/browser/publications/comment-edit/comment-edit.d.ts +41 -0
- package/dist/browser/publications/comment-edit/comment-edit.js +63 -0
- package/dist/browser/publications/comment-edit/comment-edit.js.map +1 -0
- package/dist/browser/publications/comment-edit/schema.d.ts +295 -0
- package/dist/browser/publications/comment-edit/schema.js +55 -0
- package/dist/browser/publications/comment-edit/schema.js.map +1 -0
- package/dist/browser/publications/comment-edit/types.d.ts +25 -0
- package/dist/browser/publications/comment-edit/types.js +2 -0
- package/dist/browser/publications/comment-edit/types.js.map +1 -0
- package/dist/browser/publications/comment-moderation/comment-moderation.d.ts +36 -0
- package/dist/browser/publications/comment-moderation/comment-moderation.js +53 -0
- package/dist/browser/publications/comment-moderation/comment-moderation.js.map +1 -0
- package/dist/browser/publications/comment-moderation/schema.d.ts +315 -0
- package/dist/browser/publications/comment-moderation/schema.js +62 -0
- package/dist/browser/publications/comment-moderation/schema.js.map +1 -0
- package/dist/browser/publications/comment-moderation/types.d.ts +22 -0
- package/dist/browser/publications/comment-moderation/types.js +2 -0
- package/dist/browser/publications/comment-moderation/types.js.map +1 -0
- package/dist/browser/publications/community-edit/community-edit.d.ts +35 -0
- package/dist/browser/publications/community-edit/community-edit.js +50 -0
- package/dist/browser/publications/community-edit/community-edit.js.map +1 -0
- package/dist/browser/publications/community-edit/schema.d.ts +467 -0
- package/dist/browser/publications/community-edit/schema.js +36 -0
- package/dist/browser/publications/community-edit/schema.js.map +1 -0
- package/dist/browser/publications/community-edit/types.d.ts +19 -0
- package/dist/browser/publications/community-edit/types.js +2 -0
- package/dist/browser/publications/community-edit/types.js.map +1 -0
- package/dist/browser/publications/publication-author.d.ts +22 -0
- package/dist/browser/publications/publication-author.js +66 -0
- package/dist/browser/publications/publication-author.js.map +1 -0
- package/dist/browser/publications/publication-client-manager.d.ts +62 -0
- package/dist/browser/publications/publication-client-manager.js +257 -0
- package/dist/browser/publications/publication-client-manager.js.map +1 -0
- package/dist/browser/publications/publication-clients.d.ts +19 -0
- package/dist/browser/publications/publication-clients.js +12 -0
- package/dist/browser/publications/publication-clients.js.map +1 -0
- package/dist/browser/publications/publication-community.d.ts +55 -0
- package/dist/browser/publications/publication-community.js +87 -0
- package/dist/browser/publications/publication-community.js.map +1 -0
- package/dist/browser/publications/publication.d.ts +120 -0
- package/dist/browser/publications/publication.js +950 -0
- package/dist/browser/publications/publication.js.map +1 -0
- package/dist/browser/publications/types.d.ts +26 -0
- package/dist/browser/publications/types.js +2 -0
- package/dist/browser/publications/types.js.map +1 -0
- package/dist/browser/publications/vote/schema.d.ts +150 -0
- package/dist/browser/publications/vote/schema.js +44 -0
- package/dist/browser/publications/vote/schema.js.map +1 -0
- package/dist/browser/publications/vote/types.d.ts +21 -0
- package/dist/browser/publications/vote/types.js +2 -0
- package/dist/browser/publications/vote/types.js.map +1 -0
- package/dist/browser/publications/vote/vote.d.ts +36 -0
- package/dist/browser/publications/vote/vote.js +49 -0
- package/dist/browser/publications/vote/vote.js.map +1 -0
- package/dist/browser/pubsub-messages/schema.d.ts +964 -0
- package/dist/browser/pubsub-messages/schema.js +98 -0
- package/dist/browser/pubsub-messages/schema.js.map +1 -0
- package/dist/browser/pubsub-messages/types.d.ts +81 -0
- package/dist/browser/pubsub-messages/types.js +2 -0
- package/dist/browser/pubsub-messages/types.js.map +1 -0
- package/dist/browser/rpc/src/index.d.ts +483 -0
- package/dist/browser/rpc/src/index.js +1267 -0
- package/dist/browser/rpc/src/index.js.map +1 -0
- package/dist/browser/rpc/src/json-rpc-util.d.ts +1 -0
- package/dist/browser/rpc/src/json-rpc-util.js +19 -0
- package/dist/browser/rpc/src/json-rpc-util.js.map +1 -0
- package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +132 -0
- package/dist/browser/rpc/src/lib/pkc-js/index.js +29 -0
- package/dist/browser/rpc/src/lib/pkc-js/index.js.map +1 -0
- package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.d.ts +1 -0
- package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.js +472 -0
- package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.js.map +1 -0
- package/dist/browser/rpc/src/schema.d.ts +843 -0
- package/dist/browser/rpc/src/schema.js +28 -0
- package/dist/browser/rpc/src/schema.js.map +1 -0
- package/dist/browser/rpc/src/types.d.ts +24 -0
- package/dist/browser/rpc/src/types.js +2 -0
- package/dist/browser/rpc/src/types.js.map +1 -0
- package/dist/browser/rpc/src/utils.d.ts +7 -0
- package/dist/browser/rpc/src/utils.js +58 -0
- package/dist/browser/rpc/src/utils.js.map +1 -0
- package/dist/browser/runtime/browser/community/challenges/index.d.ts +6 -0
- package/dist/browser/runtime/browser/community/challenges/index.js +7 -0
- package/dist/browser/runtime/browser/community/challenges/index.js.map +1 -0
- package/dist/browser/runtime/browser/community/local-community.d.ts +3 -0
- package/dist/browser/runtime/browser/community/local-community.js +6 -0
- package/dist/browser/runtime/browser/community/local-community.js.map +1 -0
- package/dist/browser/runtime/browser/db-handler.d.ts +4 -0
- package/dist/browser/runtime/browser/db-handler.js +8 -0
- package/dist/browser/runtime/browser/db-handler.js.map +1 -0
- package/dist/browser/runtime/browser/localforage-lru.d.ts +15 -0
- package/dist/browser/runtime/browser/localforage-lru.js +140 -0
- package/dist/browser/runtime/browser/localforage-lru.js.map +1 -0
- package/dist/browser/runtime/browser/lru-storage.d.ts +14 -0
- package/dist/browser/runtime/browser/lru-storage.js +34 -0
- package/dist/browser/runtime/browser/lru-storage.js.map +1 -0
- package/dist/browser/runtime/browser/native-functions.d.ts +3 -0
- package/dist/browser/runtime/browser/native-functions.js +6 -0
- package/dist/browser/runtime/browser/native-functions.js.map +1 -0
- package/dist/browser/runtime/browser/polyfill.d.ts +3 -0
- package/dist/browser/runtime/browser/polyfill.js +37 -0
- package/dist/browser/runtime/browser/polyfill.js.map +1 -0
- package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +1 -0
- package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +4 -0
- package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
- package/dist/browser/runtime/browser/storage.d.ts +13 -0
- package/dist/browser/runtime/browser/storage.js +37 -0
- package/dist/browser/runtime/browser/storage.js.map +1 -0
- package/dist/browser/runtime/browser/util.d.ts +14 -0
- package/dist/browser/runtime/browser/util.js +61 -0
- package/dist/browser/runtime/browser/util.js.map +1 -0
- package/dist/browser/runtime/node/address-rewriter-db.d.ts +31 -0
- package/dist/browser/runtime/node/address-rewriter-db.js +156 -0
- package/dist/browser/runtime/node/address-rewriter-db.js.map +1 -0
- package/dist/browser/runtime/node/addresses-rewriter-proxy-server.d.ts +45 -0
- package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js +493 -0
- package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/exclude/exclude.d.ts +8 -0
- package/dist/browser/runtime/node/community/challenges/exclude/exclude.js +280 -0
- package/dist/browser/runtime/node/community/challenges/exclude/exclude.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/exclude/index.d.ts +3 -0
- package/dist/browser/runtime/node/community/challenges/exclude/index.js +4 -0
- package/dist/browser/runtime/node/community/challenges/exclude/index.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.js +127 -0
- package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/exclude/utils.d.ts +13 -0
- package/dist/browser/runtime/node/community/challenges/exclude/utils.js +52 -0
- package/dist/browser/runtime/node/community/challenges/exclude/utils.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/index.d.ts +32 -0
- package/dist/browser/runtime/node/community/challenges/index.js +307 -0
- package/dist/browser/runtime/node/community/challenges/index.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.js +118 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.js +26 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.js +135 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.js +66 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.js +61 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.js +118 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.js.map +1 -0
- package/dist/browser/runtime/node/community/db-handler-types.d.ts +19 -0
- package/dist/browser/runtime/node/community/db-handler-types.js +2 -0
- package/dist/browser/runtime/node/community/db-handler-types.js.map +1 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +226 -0
- package/dist/browser/runtime/node/community/db-handler.js +2462 -0
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -0
- package/dist/browser/runtime/node/community/db-row-parser.d.ts +19 -0
- package/dist/browser/runtime/node/community/db-row-parser.js +40 -0
- package/dist/browser/runtime/node/community/db-row-parser.js.map +1 -0
- package/dist/browser/runtime/node/community/keyv-better-sqlite3.d.ts +68 -0
- package/dist/browser/runtime/node/community/keyv-better-sqlite3.js +251 -0
- package/dist/browser/runtime/node/community/keyv-better-sqlite3.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community.d.ts +129 -0
- package/dist/browser/runtime/node/community/local-community.js +2978 -0
- package/dist/browser/runtime/node/community/local-community.js.map +1 -0
- package/dist/browser/runtime/node/community/page-generator.d.ts +433 -0
- package/dist/browser/runtime/node/community/page-generator.js +441 -0
- package/dist/browser/runtime/node/community/page-generator.js.map +1 -0
- package/dist/browser/runtime/node/lru-storage.d.ts +14 -0
- package/dist/browser/runtime/node/lru-storage.js +40 -0
- package/dist/browser/runtime/node/lru-storage.js.map +1 -0
- package/dist/browser/runtime/node/native-functions.d.ts +3 -0
- package/dist/browser/runtime/node/native-functions.js +7 -0
- package/dist/browser/runtime/node/native-functions.js.map +1 -0
- package/dist/browser/runtime/node/polyfill.d.ts +3 -0
- package/dist/browser/runtime/node/polyfill.js +20 -0
- package/dist/browser/runtime/node/polyfill.js.map +1 -0
- package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +4 -0
- package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js +240 -0
- package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
- package/dist/browser/runtime/node/sqlite-lru-cache.d.ts +52 -0
- package/dist/browser/runtime/node/sqlite-lru-cache.js +127 -0
- package/dist/browser/runtime/node/sqlite-lru-cache.js.map +1 -0
- package/dist/browser/runtime/node/storage.d.ts +14 -0
- package/dist/browser/runtime/node/storage.js +52 -0
- package/dist/browser/runtime/node/storage.js.map +1 -0
- package/dist/browser/runtime/node/test/helpers/hanging-runner.d.ts +1 -0
- package/dist/browser/runtime/node/test/helpers/hanging-runner.js +157 -0
- package/dist/browser/runtime/node/test/helpers/hanging-runner.js.map +1 -0
- package/dist/browser/runtime/node/test/helpers/run-hanging-node.d.ts +7 -0
- package/dist/browser/runtime/node/test/helpers/run-hanging-node.js +68 -0
- package/dist/browser/runtime/node/test/helpers/run-hanging-node.js.map +1 -0
- package/dist/browser/runtime/node/test/mock-http-router.d.ts +54 -0
- package/dist/browser/runtime/node/test/mock-http-router.js +397 -0
- package/dist/browser/runtime/node/test/mock-http-router.js.map +1 -0
- package/dist/browser/runtime/node/util.d.ts +43 -0
- package/dist/browser/runtime/node/util.js +384 -0
- package/dist/browser/runtime/node/util.js.map +1 -0
- package/dist/browser/schema/schema-util.d.ts +2751 -0
- package/dist/browser/schema/schema-util.js +562 -0
- package/dist/browser/schema/schema-util.js.map +1 -0
- package/dist/browser/schema/schema.d.ts +237 -0
- package/dist/browser/schema/schema.js +128 -0
- package/dist/browser/schema/schema.js.map +1 -0
- package/dist/browser/schema.d.ts +1142 -0
- package/dist/browser/schema.js +104 -0
- package/dist/browser/schema.js.map +1 -0
- package/dist/browser/signer/constants.d.ts +2 -0
- package/dist/browser/signer/constants.js +3 -0
- package/dist/browser/signer/constants.js.map +1 -0
- package/dist/browser/signer/encryption.d.ts +21 -0
- package/dist/browser/signer/encryption.js +122 -0
- package/dist/browser/signer/encryption.js.map +1 -0
- package/dist/browser/signer/index.d.ts +21 -0
- package/dist/browser/signer/index.js +49 -0
- package/dist/browser/signer/index.js.map +1 -0
- package/dist/browser/signer/signatures.d.ts +200 -0
- package/dist/browser/signer/signatures.js +594 -0
- package/dist/browser/signer/signatures.js.map +1 -0
- package/dist/browser/signer/types.d.ts +20 -0
- package/dist/browser/signer/types.js +2 -0
- package/dist/browser/signer/types.js.map +1 -0
- package/dist/browser/signer/util.d.ts +14 -0
- package/dist/browser/signer/util.js +156 -0
- package/dist/browser/signer/util.js.map +1 -0
- package/dist/browser/stats.d.ts +15 -0
- package/dist/browser/stats.js +64 -0
- package/dist/browser/stats.js.map +1 -0
- package/dist/browser/test/mock-ipfs-client.d.ts +34 -0
- package/dist/browser/test/mock-ipfs-client.js +208 -0
- package/dist/browser/test/mock-ipfs-client.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.d.ts +8 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js +21 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.d.ts +8 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.js +19 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.d.ts +8 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.js +22 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.d.ts +8 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.js +23 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.d.ts +8 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.js +21 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.d.ts +7 -0
- package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.js +15 -0
- package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.d.ts +30 -0
- package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.js +46 -0
- package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.js.map +1 -0
- package/dist/browser/test/test-util.d.ts +1019 -0
- package/dist/browser/test/test-util.js +1886 -0
- package/dist/browser/test/test-util.js.map +1 -0
- package/dist/browser/types.d.ts +165 -0
- package/dist/browser/types.js +2 -0
- package/dist/browser/types.js.map +1 -0
- package/dist/browser/util/inflight-fetch-manager.d.ts +11 -0
- package/dist/browser/util/inflight-fetch-manager.js +41 -0
- package/dist/browser/util/inflight-fetch-manager.js.map +1 -0
- package/dist/browser/util.d.ts +120 -0
- package/dist/browser/util.js +816 -0
- package/dist/browser/util.js.map +1 -0
- package/dist/browser/version.d.ts +7 -0
- package/dist/browser/version.js +12 -0
- package/dist/browser/version.js.map +1 -0
- package/dist/browser/zod-error-map.d.ts +1 -0
- package/dist/browser/zod-error-map.js +10 -0
- package/dist/browser/zod-error-map.js.map +1 -0
- package/dist/node/challenges.d.ts +1 -0
- package/dist/node/challenges.js +2 -0
- package/dist/node/challenges.js.map +1 -0
- package/dist/node/clients/base-client-manager.d.ts +126 -0
- package/dist/node/clients/base-client-manager.js +673 -0
- package/dist/node/clients/base-client-manager.js.map +1 -0
- package/dist/node/clients/name-resolver-client.d.ts +8 -0
- package/dist/node/clients/name-resolver-client.js +10 -0
- package/dist/node/clients/name-resolver-client.js.map +1 -0
- package/dist/node/clients/pkc-typed-emitter.d.ts +9 -0
- package/dist/node/clients/pkc-typed-emitter.js +52 -0
- package/dist/node/clients/pkc-typed-emitter.js.map +1 -0
- package/dist/node/clients/rpc-client/decode-rpc-response-util.d.ts +8 -0
- package/dist/node/clients/rpc-client/decode-rpc-response-util.js +53 -0
- package/dist/node/clients/rpc-client/decode-rpc-response-util.js.map +1 -0
- package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +68 -0
- package/dist/node/clients/rpc-client/pkc-rpc-client.js +404 -0
- package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -0
- package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +147 -0
- package/dist/node/clients/rpc-client/rpc-schema-util.js +11 -0
- package/dist/node/clients/rpc-client/rpc-schema-util.js.map +1 -0
- package/dist/node/clients/rpc-client/schema.d.ts +433 -0
- package/dist/node/clients/rpc-client/schema.js +49 -0
- package/dist/node/clients/rpc-client/schema.js.map +1 -0
- package/dist/node/clients/rpc-client/types.d.ts +8 -0
- package/dist/node/clients/rpc-client/types.js +2 -0
- package/dist/node/clients/rpc-client/types.js.map +1 -0
- package/dist/node/community/community-client-manager.d.ts +60 -0
- package/dist/node/community/community-client-manager.js +717 -0
- package/dist/node/community/community-client-manager.js.map +1 -0
- package/dist/node/community/community-clients.d.ts +18 -0
- package/dist/node/community/community-clients.js +12 -0
- package/dist/node/community/community-clients.js.map +1 -0
- package/dist/node/community/community-wire.d.ts +20 -0
- package/dist/node/community/community-wire.js +38 -0
- package/dist/node/community/community-wire.js.map +1 -0
- package/dist/node/community/remote-community.d.ts +110 -0
- package/dist/node/community/remote-community.js +555 -0
- package/dist/node/community/remote-community.js.map +1 -0
- package/dist/node/community/rpc-local-community.d.ts +41 -0
- package/dist/node/community/rpc-local-community.js +289 -0
- package/dist/node/community/rpc-local-community.js.map +1 -0
- package/dist/node/community/rpc-remote-community.d.ts +18 -0
- package/dist/node/community/rpc-remote-community.js +286 -0
- package/dist/node/community/rpc-remote-community.js.map +1 -0
- package/dist/node/community/schema.d.ts +4217 -0
- package/dist/node/community/schema.js +289 -0
- package/dist/node/community/schema.js.map +1 -0
- package/dist/node/community/types.d.ts +135 -0
- package/dist/node/community/types.js +2 -0
- package/dist/node/community/types.js.map +1 -0
- package/dist/node/constants.d.ts +6 -0
- package/dist/node/constants.js +9 -0
- package/dist/node/constants.js.map +1 -0
- package/dist/node/decorator-util.d.ts +1 -0
- package/dist/node/decorator-util.js +35 -0
- package/dist/node/decorator-util.js.map +1 -0
- package/dist/node/errors.d.ts +343 -0
- package/dist/node/errors.js +358 -0
- package/dist/node/errors.js.map +1 -0
- package/dist/node/general-util/limited-set.d.ts +15 -0
- package/dist/node/general-util/limited-set.js +66 -0
- package/dist/node/general-util/limited-set.js.map +1 -0
- package/dist/node/generated-version.d.ts +1 -0
- package/dist/node/generated-version.js +3 -0
- package/dist/node/generated-version.js.map +1 -0
- package/dist/node/generic-state-client.d.ts +6 -0
- package/dist/node/generic-state-client.js +11 -0
- package/dist/node/generic-state-client.js.map +1 -0
- package/dist/node/helia/helia-for-pkc.d.ts +3 -0
- package/dist/node/helia/helia-for-pkc.js +255 -0
- package/dist/node/helia/helia-for-pkc.js.map +1 -0
- package/dist/node/helia/ipns-over-pubsub-with-fetch.d.ts +36 -0
- package/dist/node/helia/ipns-over-pubsub-with-fetch.js +229 -0
- package/dist/node/helia/ipns-over-pubsub-with-fetch.js.map +1 -0
- package/dist/node/helia/libp2pjsClient.d.ts +27 -0
- package/dist/node/helia/libp2pjsClient.js +15 -0
- package/dist/node/helia/libp2pjsClient.js.map +1 -0
- package/dist/node/helia/types.d.ts +19 -0
- package/dist/node/helia/types.js +2 -0
- package/dist/node/helia/types.js.map +1 -0
- package/dist/node/helia/util.d.ts +13 -0
- package/dist/node/helia/util.js +98 -0
- package/dist/node/helia/util.js.map +1 -0
- package/dist/node/index.d.ts +244 -0
- package/dist/node/index.js +36 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/logger.d.ts +12 -0
- package/dist/node/logger.js +11 -0
- package/dist/node/logger.js.map +1 -0
- package/dist/node/pages/pages-client-manager.d.ts +159 -0
- package/dist/node/pages/pages-client-manager.js +334 -0
- package/dist/node/pages/pages-client-manager.js.map +1 -0
- package/dist/node/pages/pages-clients.d.ts +11 -0
- package/dist/node/pages/pages-clients.js +10 -0
- package/dist/node/pages/pages-clients.js.map +1 -0
- package/dist/node/pages/pages.d.ts +107 -0
- package/dist/node/pages/pages.js +262 -0
- package/dist/node/pages/pages.js.map +1 -0
- package/dist/node/pages/schema-util.d.ts +3 -0
- package/dist/node/pages/schema-util.js +3 -0
- package/dist/node/pages/schema-util.js.map +1 -0
- package/dist/node/pages/schema.d.ts +719 -0
- package/dist/node/pages/schema.js +32 -0
- package/dist/node/pages/schema.js.map +1 -0
- package/dist/node/pages/types.d.ts +44 -0
- package/dist/node/pages/types.js +2 -0
- package/dist/node/pages/types.js.map +1 -0
- package/dist/node/pages/util.d.ts +56 -0
- package/dist/node/pages/util.js +446 -0
- package/dist/node/pages/util.js.map +1 -0
- package/dist/node/pkc/pkc-client-manager.d.ts +44 -0
- package/dist/node/pkc/pkc-client-manager.js +156 -0
- package/dist/node/pkc/pkc-client-manager.js.map +1 -0
- package/dist/node/pkc/pkc-clients.d.ts +11 -0
- package/dist/node/pkc/pkc-clients.js +8 -0
- package/dist/node/pkc/pkc-clients.js.map +1 -0
- package/dist/node/pkc/pkc-with-rpc-client.d.ts +19 -0
- package/dist/node/pkc/pkc-with-rpc-client.js +128 -0
- package/dist/node/pkc/pkc-with-rpc-client.js.map +1 -0
- package/dist/node/pkc/pkc.d.ts +137 -0
- package/dist/node/pkc/pkc.js +888 -0
- package/dist/node/pkc/pkc.js.map +1 -0
- package/dist/node/pkc/tracked-instance-registry-util.d.ts +44 -0
- package/dist/node/pkc/tracked-instance-registry-util.js +106 -0
- package/dist/node/pkc/tracked-instance-registry-util.js.map +1 -0
- package/dist/node/pkc/tracked-instance-registry.d.ts +18 -0
- package/dist/node/pkc/tracked-instance-registry.js +134 -0
- package/dist/node/pkc/tracked-instance-registry.js.map +1 -0
- package/dist/node/pkc-error.d.ts +65 -0
- package/dist/node/pkc-error.js +137 -0
- package/dist/node/pkc-error.js.map +1 -0
- package/dist/node/publications/comment/comment-client-manager.d.ts +86 -0
- package/dist/node/publications/comment/comment-client-manager.js +908 -0
- package/dist/node/publications/comment/comment-client-manager.js.map +1 -0
- package/dist/node/publications/comment/comment-clients.d.ts +19 -0
- package/dist/node/publications/comment/comment-clients.js +12 -0
- package/dist/node/publications/comment/comment-clients.js.map +1 -0
- package/dist/node/publications/comment/comment-util.d.ts +10 -0
- package/dist/node/publications/comment/comment-util.js +202 -0
- package/dist/node/publications/comment/comment-util.js.map +1 -0
- package/dist/node/publications/comment/comment.d.ts +147 -0
- package/dist/node/publications/comment/comment.js +1044 -0
- package/dist/node/publications/comment/comment.js.map +1 -0
- package/dist/node/publications/comment/schema.d.ts +1237 -0
- package/dist/node/publications/comment/schema.js +184 -0
- package/dist/node/publications/comment/schema.js.map +1 -0
- package/dist/node/publications/comment/types.d.ts +100 -0
- package/dist/node/publications/comment/types.js +2 -0
- package/dist/node/publications/comment/types.js.map +1 -0
- package/dist/node/publications/comment-edit/comment-edit.d.ts +41 -0
- package/dist/node/publications/comment-edit/comment-edit.js +63 -0
- package/dist/node/publications/comment-edit/comment-edit.js.map +1 -0
- package/dist/node/publications/comment-edit/schema.d.ts +295 -0
- package/dist/node/publications/comment-edit/schema.js +55 -0
- package/dist/node/publications/comment-edit/schema.js.map +1 -0
- package/dist/node/publications/comment-edit/types.d.ts +25 -0
- package/dist/node/publications/comment-edit/types.js +2 -0
- package/dist/node/publications/comment-edit/types.js.map +1 -0
- package/dist/node/publications/comment-moderation/comment-moderation.d.ts +36 -0
- package/dist/node/publications/comment-moderation/comment-moderation.js +53 -0
- package/dist/node/publications/comment-moderation/comment-moderation.js.map +1 -0
- package/dist/node/publications/comment-moderation/schema.d.ts +315 -0
- package/dist/node/publications/comment-moderation/schema.js +62 -0
- package/dist/node/publications/comment-moderation/schema.js.map +1 -0
- package/dist/node/publications/comment-moderation/types.d.ts +22 -0
- package/dist/node/publications/comment-moderation/types.js +2 -0
- package/dist/node/publications/comment-moderation/types.js.map +1 -0
- package/dist/node/publications/community-edit/community-edit.d.ts +35 -0
- package/dist/node/publications/community-edit/community-edit.js +50 -0
- package/dist/node/publications/community-edit/community-edit.js.map +1 -0
- package/dist/node/publications/community-edit/schema.d.ts +467 -0
- package/dist/node/publications/community-edit/schema.js +36 -0
- package/dist/node/publications/community-edit/schema.js.map +1 -0
- package/dist/node/publications/community-edit/types.d.ts +19 -0
- package/dist/node/publications/community-edit/types.js +2 -0
- package/dist/node/publications/community-edit/types.js.map +1 -0
- package/dist/node/publications/publication-author.d.ts +22 -0
- package/dist/node/publications/publication-author.js +66 -0
- package/dist/node/publications/publication-author.js.map +1 -0
- package/dist/node/publications/publication-client-manager.d.ts +62 -0
- package/dist/node/publications/publication-client-manager.js +257 -0
- package/dist/node/publications/publication-client-manager.js.map +1 -0
- package/dist/node/publications/publication-clients.d.ts +19 -0
- package/dist/node/publications/publication-clients.js +12 -0
- package/dist/node/publications/publication-clients.js.map +1 -0
- package/dist/node/publications/publication-community.d.ts +55 -0
- package/dist/node/publications/publication-community.js +87 -0
- package/dist/node/publications/publication-community.js.map +1 -0
- package/dist/node/publications/publication.d.ts +120 -0
- package/dist/node/publications/publication.js +950 -0
- package/dist/node/publications/publication.js.map +1 -0
- package/dist/node/publications/types.d.ts +26 -0
- package/dist/node/publications/types.js +2 -0
- package/dist/node/publications/types.js.map +1 -0
- package/dist/node/publications/vote/schema.d.ts +150 -0
- package/dist/node/publications/vote/schema.js +44 -0
- package/dist/node/publications/vote/schema.js.map +1 -0
- package/dist/node/publications/vote/types.d.ts +21 -0
- package/dist/node/publications/vote/types.js +2 -0
- package/dist/node/publications/vote/types.js.map +1 -0
- package/dist/node/publications/vote/vote.d.ts +36 -0
- package/dist/node/publications/vote/vote.js +49 -0
- package/dist/node/publications/vote/vote.js.map +1 -0
- package/dist/node/pubsub-messages/schema.d.ts +964 -0
- package/dist/node/pubsub-messages/schema.js +98 -0
- package/dist/node/pubsub-messages/schema.js.map +1 -0
- package/dist/node/pubsub-messages/types.d.ts +81 -0
- package/dist/node/pubsub-messages/types.js +2 -0
- package/dist/node/pubsub-messages/types.js.map +1 -0
- package/dist/node/rpc/src/index.d.ts +483 -0
- package/dist/node/rpc/src/index.js +1267 -0
- package/dist/node/rpc/src/index.js.map +1 -0
- package/dist/node/rpc/src/json-rpc-util.d.ts +1 -0
- package/dist/node/rpc/src/json-rpc-util.js +19 -0
- package/dist/node/rpc/src/json-rpc-util.js.map +1 -0
- package/dist/node/rpc/src/lib/pkc-js/index.d.ts +132 -0
- package/dist/node/rpc/src/lib/pkc-js/index.js +29 -0
- package/dist/node/rpc/src/lib/pkc-js/index.js.map +1 -0
- package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.d.ts +1 -0
- package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.js +472 -0
- package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.js.map +1 -0
- package/dist/node/rpc/src/schema.d.ts +843 -0
- package/dist/node/rpc/src/schema.js +28 -0
- package/dist/node/rpc/src/schema.js.map +1 -0
- package/dist/node/rpc/src/types.d.ts +24 -0
- package/dist/node/rpc/src/types.js +2 -0
- package/dist/node/rpc/src/types.js.map +1 -0
- package/dist/node/rpc/src/utils.d.ts +7 -0
- package/dist/node/rpc/src/utils.js +58 -0
- package/dist/node/rpc/src/utils.js.map +1 -0
- package/dist/node/runtime/browser/community/challenges/index.d.ts +6 -0
- package/dist/node/runtime/browser/community/challenges/index.js +7 -0
- package/dist/node/runtime/browser/community/challenges/index.js.map +1 -0
- package/dist/node/runtime/browser/community/local-community.d.ts +3 -0
- package/dist/node/runtime/browser/community/local-community.js +6 -0
- package/dist/node/runtime/browser/community/local-community.js.map +1 -0
- package/dist/node/runtime/browser/db-handler.d.ts +4 -0
- package/dist/node/runtime/browser/db-handler.js +8 -0
- package/dist/node/runtime/browser/db-handler.js.map +1 -0
- package/dist/node/runtime/browser/localforage-lru.d.ts +15 -0
- package/dist/node/runtime/browser/localforage-lru.js +140 -0
- package/dist/node/runtime/browser/localforage-lru.js.map +1 -0
- package/dist/node/runtime/browser/lru-storage.d.ts +14 -0
- package/dist/node/runtime/browser/lru-storage.js +34 -0
- package/dist/node/runtime/browser/lru-storage.js.map +1 -0
- package/dist/node/runtime/browser/native-functions.d.ts +3 -0
- package/dist/node/runtime/browser/native-functions.js +6 -0
- package/dist/node/runtime/browser/native-functions.js.map +1 -0
- package/dist/node/runtime/browser/polyfill.d.ts +3 -0
- package/dist/node/runtime/browser/polyfill.js +37 -0
- package/dist/node/runtime/browser/polyfill.js.map +1 -0
- package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +1 -0
- package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +4 -0
- package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
- package/dist/node/runtime/browser/storage.d.ts +13 -0
- package/dist/node/runtime/browser/storage.js +37 -0
- package/dist/node/runtime/browser/storage.js.map +1 -0
- package/dist/node/runtime/browser/util.d.ts +14 -0
- package/dist/node/runtime/browser/util.js +61 -0
- package/dist/node/runtime/browser/util.js.map +1 -0
- package/dist/node/runtime/node/address-rewriter-db.d.ts +31 -0
- package/dist/node/runtime/node/address-rewriter-db.js +156 -0
- package/dist/node/runtime/node/address-rewriter-db.js.map +1 -0
- package/dist/node/runtime/node/addresses-rewriter-proxy-server.d.ts +45 -0
- package/dist/node/runtime/node/addresses-rewriter-proxy-server.js +493 -0
- package/dist/node/runtime/node/addresses-rewriter-proxy-server.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/exclude/exclude.d.ts +8 -0
- package/dist/node/runtime/node/community/challenges/exclude/exclude.js +280 -0
- package/dist/node/runtime/node/community/challenges/exclude/exclude.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/exclude/index.d.ts +3 -0
- package/dist/node/runtime/node/community/challenges/exclude/index.js +4 -0
- package/dist/node/runtime/node/community/challenges/exclude/index.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.js +127 -0
- package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/exclude/utils.d.ts +13 -0
- package/dist/node/runtime/node/community/challenges/exclude/utils.js +52 -0
- package/dist/node/runtime/node/community/challenges/exclude/utils.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/index.d.ts +32 -0
- package/dist/node/runtime/node/community/challenges/index.js +307 -0
- package/dist/node/runtime/node/community/challenges/index.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.js +118 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.js +26 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.js +135 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.js +66 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.js +61 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.js +118 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.js.map +1 -0
- package/dist/node/runtime/node/community/db-handler-types.d.ts +19 -0
- package/dist/node/runtime/node/community/db-handler-types.js +2 -0
- package/dist/node/runtime/node/community/db-handler-types.js.map +1 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +226 -0
- package/dist/node/runtime/node/community/db-handler.js +2462 -0
- package/dist/node/runtime/node/community/db-handler.js.map +1 -0
- package/dist/node/runtime/node/community/db-row-parser.d.ts +19 -0
- package/dist/node/runtime/node/community/db-row-parser.js +40 -0
- package/dist/node/runtime/node/community/db-row-parser.js.map +1 -0
- package/dist/node/runtime/node/community/keyv-better-sqlite3.d.ts +68 -0
- package/dist/node/runtime/node/community/keyv-better-sqlite3.js +251 -0
- package/dist/node/runtime/node/community/keyv-better-sqlite3.js.map +1 -0
- package/dist/node/runtime/node/community/local-community.d.ts +129 -0
- package/dist/node/runtime/node/community/local-community.js +2978 -0
- package/dist/node/runtime/node/community/local-community.js.map +1 -0
- package/dist/node/runtime/node/community/page-generator.d.ts +433 -0
- package/dist/node/runtime/node/community/page-generator.js +441 -0
- package/dist/node/runtime/node/community/page-generator.js.map +1 -0
- package/dist/node/runtime/node/lru-storage.d.ts +14 -0
- package/dist/node/runtime/node/lru-storage.js +40 -0
- package/dist/node/runtime/node/lru-storage.js.map +1 -0
- package/dist/node/runtime/node/native-functions.d.ts +3 -0
- package/dist/node/runtime/node/native-functions.js +7 -0
- package/dist/node/runtime/node/native-functions.js.map +1 -0
- package/dist/node/runtime/node/polyfill.d.ts +3 -0
- package/dist/node/runtime/node/polyfill.js +20 -0
- package/dist/node/runtime/node/polyfill.js.map +1 -0
- package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +4 -0
- package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js +240 -0
- package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
- package/dist/node/runtime/node/sqlite-lru-cache.d.ts +52 -0
- package/dist/node/runtime/node/sqlite-lru-cache.js +127 -0
- package/dist/node/runtime/node/sqlite-lru-cache.js.map +1 -0
- package/dist/node/runtime/node/storage.d.ts +14 -0
- package/dist/node/runtime/node/storage.js +52 -0
- package/dist/node/runtime/node/storage.js.map +1 -0
- package/dist/node/runtime/node/test/helpers/hanging-runner.d.ts +1 -0
- package/dist/node/runtime/node/test/helpers/hanging-runner.js +157 -0
- package/dist/node/runtime/node/test/helpers/hanging-runner.js.map +1 -0
- package/dist/node/runtime/node/test/helpers/run-hanging-node.d.ts +7 -0
- package/dist/node/runtime/node/test/helpers/run-hanging-node.js +68 -0
- package/dist/node/runtime/node/test/helpers/run-hanging-node.js.map +1 -0
- package/dist/node/runtime/node/test/mock-http-router.d.ts +54 -0
- package/dist/node/runtime/node/test/mock-http-router.js +397 -0
- package/dist/node/runtime/node/test/mock-http-router.js.map +1 -0
- package/dist/node/runtime/node/util.d.ts +43 -0
- package/dist/node/runtime/node/util.js +384 -0
- package/dist/node/runtime/node/util.js.map +1 -0
- package/dist/node/schema/schema-util.d.ts +2751 -0
- package/dist/node/schema/schema-util.js +562 -0
- package/dist/node/schema/schema-util.js.map +1 -0
- package/dist/node/schema/schema.d.ts +237 -0
- package/dist/node/schema/schema.js +128 -0
- package/dist/node/schema/schema.js.map +1 -0
- package/dist/node/schema.d.ts +1142 -0
- package/dist/node/schema.js +104 -0
- package/dist/node/schema.js.map +1 -0
- package/dist/node/signer/constants.d.ts +2 -0
- package/dist/node/signer/constants.js +3 -0
- package/dist/node/signer/constants.js.map +1 -0
- package/dist/node/signer/encryption.d.ts +21 -0
- package/dist/node/signer/encryption.js +122 -0
- package/dist/node/signer/encryption.js.map +1 -0
- package/dist/node/signer/index.d.ts +21 -0
- package/dist/node/signer/index.js +49 -0
- package/dist/node/signer/index.js.map +1 -0
- package/dist/node/signer/signatures.d.ts +200 -0
- package/dist/node/signer/signatures.js +594 -0
- package/dist/node/signer/signatures.js.map +1 -0
- package/dist/node/signer/types.d.ts +20 -0
- package/dist/node/signer/types.js +2 -0
- package/dist/node/signer/types.js.map +1 -0
- package/dist/node/signer/util.d.ts +14 -0
- package/dist/node/signer/util.js +156 -0
- package/dist/node/signer/util.js.map +1 -0
- package/dist/node/stats.d.ts +15 -0
- package/dist/node/stats.js +64 -0
- package/dist/node/stats.js.map +1 -0
- package/dist/node/test/mock-ipfs-client.d.ts +34 -0
- package/dist/node/test/mock-ipfs-client.js +208 -0
- package/dist/node/test/mock-ipfs-client.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.d.ts +8 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js +21 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.d.ts +8 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.js +19 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.d.ts +8 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.js +22 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.d.ts +8 -0
- package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.js +23 -0
- package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.d.ts +8 -0
- package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.js +21 -0
- package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.d.ts +7 -0
- package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.js +15 -0
- package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.d.ts +30 -0
- package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.js +46 -0
- package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.js.map +1 -0
- package/dist/node/test/test-util.d.ts +1019 -0
- package/dist/node/test/test-util.js +1886 -0
- package/dist/node/test/test-util.js.map +1 -0
- package/dist/node/types.d.ts +165 -0
- package/dist/node/types.js +2 -0
- package/dist/node/types.js.map +1 -0
- package/dist/node/util/inflight-fetch-manager.d.ts +11 -0
- package/dist/node/util/inflight-fetch-manager.js +41 -0
- package/dist/node/util/inflight-fetch-manager.js.map +1 -0
- package/dist/node/util.d.ts +120 -0
- package/dist/node/util.js +816 -0
- package/dist/node/util.js.map +1 -0
- package/dist/node/version.d.ts +7 -0
- package/dist/node/version.js +12 -0
- package/dist/node/version.js.map +1 -0
- package/dist/node/zod-error-map.d.ts +1 -0
- package/dist/node/zod-error-map.js +10 -0
- package/dist/node/zod-error-map.js.map +1 -0
- 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
|