@pkcprotocol/pkc-js 0.0.106 → 0.0.108
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/README.md +16 -0
- package/dist/browser/clients/base-client-manager.d.ts +1 -1
- package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +16 -0
- package/dist/browser/clients/rpc-client/schema.d.ts +16 -0
- package/dist/browser/community/remote-community.d.ts +1 -0
- package/dist/browser/community/remote-community.js +1 -0
- package/dist/browser/community/remote-community.js.map +1 -1
- package/dist/browser/community/rpc-local-community.js +13 -0
- package/dist/browser/community/rpc-local-community.js.map +1 -1
- package/dist/browser/community/rpc-remote-community.js +19 -7
- package/dist/browser/community/rpc-remote-community.js.map +1 -1
- package/dist/browser/community/schema.d.ts +1369 -1
- package/dist/browser/community/schema.js +90 -4
- package/dist/browser/community/schema.js.map +1 -1
- package/dist/browser/community/types.d.ts +13 -2
- package/dist/browser/constants.d.ts +1 -0
- package/dist/browser/constants.js +6 -0
- package/dist/browser/constants.js.map +1 -1
- package/dist/browser/errors.d.ts +16 -1
- package/dist/browser/errors.js +16 -0
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/helia/helia-for-pkc.js +78 -11
- package/dist/browser/helia/helia-for-pkc.js.map +1 -1
- package/dist/browser/helia/util.d.ts +23 -1
- package/dist/browser/helia/util.js +52 -5
- package/dist/browser/helia/util.js.map +1 -1
- package/dist/browser/index-with-compile-cache.d.ts +559 -0
- package/dist/browser/index.d.ts +1120 -0
- package/dist/browser/index.js +5 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/logger.js +10 -1
- package/dist/browser/logger.js.map +1 -1
- package/dist/browser/object-key-util.d.ts +2 -0
- package/dist/browser/object-key-util.js +12 -0
- package/dist/browser/object-key-util.js.map +1 -0
- package/dist/browser/pages/page-sort-options.d.ts +14 -0
- package/dist/browser/pages/page-sort-options.js +92 -0
- package/dist/browser/pages/page-sort-options.js.map +1 -0
- package/dist/browser/pages/page-sort-scoring.d.ts +35 -0
- package/dist/browser/pages/page-sort-scoring.js +124 -0
- package/dist/browser/pages/page-sort-scoring.js.map +1 -0
- package/dist/browser/pages/pages-client-manager.d.ts +1 -0
- package/dist/browser/pages/pages-client-manager.js +16 -4
- package/dist/browser/pages/pages-client-manager.js.map +1 -1
- package/dist/browser/pages/pkc-js-page-sorts/active.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/active.js +15 -0
- package/dist/browser/pages/pkc-js-page-sorts/active.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/best.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/best.js +10 -0
- package/dist/browser/pages/pkc-js-page-sorts/best.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/controversial.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/controversial.js +10 -0
- package/dist/browser/pages/pkc-js-page-sorts/controversial.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/hot.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/hot.js +10 -0
- package/dist/browser/pages/pkc-js-page-sorts/hot.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/index.d.ts +2 -0
- package/dist/browser/pages/pkc-js-page-sorts/index.js +37 -0
- package/dist/browser/pages/pkc-js-page-sorts/index.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/new-flat.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/new-flat.js +12 -0
- package/dist/browser/pages/pkc-js-page-sorts/new-flat.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/new.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/new.js +10 -0
- package/dist/browser/pages/pkc-js-page-sorts/new.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/old-flat.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/old-flat.js +12 -0
- package/dist/browser/pages/pkc-js-page-sorts/old-flat.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/old.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/old.js +10 -0
- package/dist/browser/pages/pkc-js-page-sorts/old.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-all.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-all.js +10 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-all.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-day.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-day.js +11 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-day.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-hour.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-hour.js +11 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-hour.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-month.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-month.js +11 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-month.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-week.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-week.js +11 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-week.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-year.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-year.js +11 -0
- package/dist/browser/pages/pkc-js-page-sorts/top-year.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/top.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/top.js +12 -0
- package/dist/browser/pages/pkc-js-page-sorts/top.js.map +1 -0
- package/dist/browser/pages/pkc-js-page-sorts/util.d.ts +3 -0
- package/dist/browser/pages/pkc-js-page-sorts/util.js +7 -0
- package/dist/browser/pages/pkc-js-page-sorts/util.js.map +1 -0
- package/dist/browser/pages/schema.d.ts +1 -0
- package/dist/browser/pages/schema.js +10 -3
- package/dist/browser/pages/schema.js.map +1 -1
- package/dist/browser/pages/types.d.ts +8 -0
- package/dist/browser/pages/util.d.ts +2 -1
- package/dist/browser/pages/util.js +11 -10
- package/dist/browser/pages/util.js.map +1 -1
- package/dist/browser/pkc/pkc.d.ts +2 -1
- package/dist/browser/pkc/pkc.js +2 -1
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/comment-client-manager.d.ts +2 -2
- package/dist/browser/publications/comment/comment-client-manager.js +3 -1
- package/dist/browser/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/browser/publications/comment/comment.js +6 -3
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/publications/community-edit/schema.d.ts +64 -0
- package/dist/browser/pubsub-messages/schema.d.ts +32 -0
- package/dist/browser/rpc/src/index.js +14 -1
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +559 -0
- package/dist/browser/rpc/src/schema.d.ts +3371 -0
- package/dist/browser/rpc/src/schema.js +6 -2
- package/dist/browser/rpc/src/schema.js.map +1 -1
- package/dist/browser/runtime/browser/community/page-sorts/index.d.ts +1 -0
- package/dist/browser/runtime/browser/community/page-sorts/index.js +6 -0
- package/dist/browser/runtime/browser/community/page-sorts/index.js.map +1 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +78 -20
- package/dist/browser/runtime/node/community/db-handler.js +1151 -734
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/db-row-parser.d.ts +13 -0
- package/dist/browser/runtime/node/community/db-row-parser.js +58 -1
- package/dist/browser/runtime/node/community/db-row-parser.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/cleanup.js +23 -10
- package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.d.ts +12 -2
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +101 -70
- package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/db-state.js +8 -0
- package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/editing.d.ts +9 -2
- package/dist/browser/runtime/node/community/local-community/editing.js +32 -5
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.d.ts +2 -2
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +49 -27
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +49 -18
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +5 -1
- package/dist/browser/runtime/node/community/local-community.js +13 -1
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/community/page-generator.d.ts +44 -413
- package/dist/browser/runtime/node/community/page-generator.js +531 -308
- package/dist/browser/runtime/node/community/page-generator.js.map +1 -1
- package/dist/browser/runtime/node/community/page-sorts/index.d.ts +64 -0
- package/dist/browser/runtime/node/community/page-sorts/index.js +264 -0
- package/dist/browser/runtime/node/community/page-sorts/index.js.map +1 -0
- package/dist/browser/runtime/node/util.js +1 -1
- package/dist/browser/runtime/node/util.js.map +1 -1
- package/dist/browser/schema/schema-util.d.ts +142 -1
- package/dist/browser/schema/schema-util.js +11 -0
- package/dist/browser/schema/schema-util.js.map +1 -1
- package/dist/browser/schema/schema.js +1 -1
- package/dist/browser/schema/schema.js.map +1 -1
- package/dist/browser/schema.d.ts +4469 -0
- package/dist/browser/schema.js +2 -1
- package/dist/browser/schema.js.map +1 -1
- package/dist/browser/signer/signatures.d.ts +1 -1
- package/dist/browser/signer/signatures.js +45 -1
- package/dist/browser/signer/signatures.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +63 -0
- package/dist/browser/test/test-util.js +66 -11
- package/dist/browser/test/test-util.js.map +1 -1
- package/dist/browser/util.d.ts +4 -0
- package/dist/browser/util.js +93 -1
- package/dist/browser/util.js.map +1 -1
- package/dist/browser/version.js +1 -1
- package/dist/bundled/bundle-manifest.json +229 -205
- package/dist/bundled/chunks/{helia-for-pkc-qvcQHRw5.js → helia-for-pkc-BY1wF9W8.js} +91 -48
- package/dist/bundled/chunks/{local-community-BVWWQKxg.js → local-community-B6i3MUzw.js} +1 -1
- package/dist/bundled/chunks/{local-community-DhiNmK3L.js → local-community-Dm02mfn3.js} +6719 -6055
- package/dist/bundled/chunks/{node-D8vvnh-6.js → node-B8rEQ_rA.js} +1208 -17
- package/dist/bundled/chunks/{rpc-local-community-Bmt73MTy.js → rpc-local-community-DHS2R2Vk.js} +13693 -14182
- package/dist/bundled/chunks/{util-DUR-gvDQ.js → util-B-wz3mKY.js} +32 -2
- package/dist/bundled/chunks/{schema-B4n6Xctr.js → util-C6zDjhpr.js} +755 -602
- package/dist/bundled/index.js +2 -2
- package/dist/bundled/rpc/src/index.js +22 -9
- package/dist/node/clients/base-client-manager.d.ts +1 -1
- package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +16 -0
- package/dist/node/clients/rpc-client/schema.d.ts +16 -0
- package/dist/node/community/remote-community.d.ts +1 -0
- package/dist/node/community/remote-community.js +1 -0
- package/dist/node/community/remote-community.js.map +1 -1
- package/dist/node/community/rpc-local-community.js +13 -0
- package/dist/node/community/rpc-local-community.js.map +1 -1
- package/dist/node/community/rpc-remote-community.js +19 -7
- package/dist/node/community/rpc-remote-community.js.map +1 -1
- package/dist/node/community/schema.d.ts +1369 -1
- package/dist/node/community/schema.js +90 -4
- package/dist/node/community/schema.js.map +1 -1
- package/dist/node/community/types.d.ts +13 -2
- package/dist/node/constants.d.ts +1 -0
- package/dist/node/constants.js +6 -0
- package/dist/node/constants.js.map +1 -1
- package/dist/node/errors.d.ts +16 -1
- package/dist/node/errors.js +16 -0
- package/dist/node/errors.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/helia/helia-for-pkc.js +78 -11
- package/dist/node/helia/helia-for-pkc.js.map +1 -1
- package/dist/node/helia/util.d.ts +23 -1
- package/dist/node/helia/util.js +52 -5
- package/dist/node/helia/util.js.map +1 -1
- package/dist/node/index-with-compile-cache.d.ts +559 -0
- package/dist/node/index.d.ts +1120 -0
- package/dist/node/index.js +5 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/logger.js +10 -1
- package/dist/node/logger.js.map +1 -1
- package/dist/node/object-key-util.d.ts +2 -0
- package/dist/node/object-key-util.js +12 -0
- package/dist/node/object-key-util.js.map +1 -0
- package/dist/node/pages/page-sort-options.d.ts +14 -0
- package/dist/node/pages/page-sort-options.js +92 -0
- package/dist/node/pages/page-sort-options.js.map +1 -0
- package/dist/node/pages/page-sort-scoring.d.ts +35 -0
- package/dist/node/pages/page-sort-scoring.js +124 -0
- package/dist/node/pages/page-sort-scoring.js.map +1 -0
- package/dist/node/pages/pages-client-manager.d.ts +1 -0
- package/dist/node/pages/pages-client-manager.js +16 -4
- package/dist/node/pages/pages-client-manager.js.map +1 -1
- package/dist/node/pages/pkc-js-page-sorts/active.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/active.js +15 -0
- package/dist/node/pages/pkc-js-page-sorts/active.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/best.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/best.js +10 -0
- package/dist/node/pages/pkc-js-page-sorts/best.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/controversial.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/controversial.js +10 -0
- package/dist/node/pages/pkc-js-page-sorts/controversial.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/hot.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/hot.js +10 -0
- package/dist/node/pages/pkc-js-page-sorts/hot.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/index.d.ts +2 -0
- package/dist/node/pages/pkc-js-page-sorts/index.js +37 -0
- package/dist/node/pages/pkc-js-page-sorts/index.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/new-flat.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/new-flat.js +12 -0
- package/dist/node/pages/pkc-js-page-sorts/new-flat.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/new.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/new.js +10 -0
- package/dist/node/pages/pkc-js-page-sorts/new.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/old-flat.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/old-flat.js +12 -0
- package/dist/node/pages/pkc-js-page-sorts/old-flat.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/old.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/old.js +10 -0
- package/dist/node/pages/pkc-js-page-sorts/old.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/top-all.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/top-all.js +10 -0
- package/dist/node/pages/pkc-js-page-sorts/top-all.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/top-day.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/top-day.js +11 -0
- package/dist/node/pages/pkc-js-page-sorts/top-day.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/top-hour.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/top-hour.js +11 -0
- package/dist/node/pages/pkc-js-page-sorts/top-hour.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/top-month.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/top-month.js +11 -0
- package/dist/node/pages/pkc-js-page-sorts/top-month.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/top-week.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/top-week.js +11 -0
- package/dist/node/pages/pkc-js-page-sorts/top-week.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/top-year.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/top-year.js +11 -0
- package/dist/node/pages/pkc-js-page-sorts/top-year.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/top.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/top.js +12 -0
- package/dist/node/pages/pkc-js-page-sorts/top.js.map +1 -0
- package/dist/node/pages/pkc-js-page-sorts/util.d.ts +3 -0
- package/dist/node/pages/pkc-js-page-sorts/util.js +7 -0
- package/dist/node/pages/pkc-js-page-sorts/util.js.map +1 -0
- package/dist/node/pages/schema.d.ts +1 -0
- package/dist/node/pages/schema.js +10 -3
- package/dist/node/pages/schema.js.map +1 -1
- package/dist/node/pages/types.d.ts +8 -0
- package/dist/node/pages/util.d.ts +2 -1
- package/dist/node/pages/util.js +11 -10
- package/dist/node/pages/util.js.map +1 -1
- package/dist/node/pkc/pkc.d.ts +2 -1
- package/dist/node/pkc/pkc.js +2 -1
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/comment-client-manager.d.ts +2 -2
- package/dist/node/publications/comment/comment-client-manager.js +3 -1
- package/dist/node/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/node/publications/comment/comment.js +6 -3
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/publications/community-edit/schema.d.ts +64 -0
- package/dist/node/pubsub-messages/schema.d.ts +32 -0
- package/dist/node/rpc/src/index.js +14 -1
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/rpc/src/lib/pkc-js/index.d.ts +559 -0
- package/dist/node/rpc/src/schema.d.ts +3371 -0
- package/dist/node/rpc/src/schema.js +6 -2
- package/dist/node/rpc/src/schema.js.map +1 -1
- package/dist/node/runtime/browser/community/page-sorts/index.d.ts +1 -0
- package/dist/node/runtime/browser/community/page-sorts/index.js +6 -0
- package/dist/node/runtime/browser/community/page-sorts/index.js.map +1 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +78 -20
- package/dist/node/runtime/node/community/db-handler.js +1151 -734
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/db-row-parser.d.ts +13 -0
- package/dist/node/runtime/node/community/db-row-parser.js +58 -1
- package/dist/node/runtime/node/community/db-row-parser.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/cleanup.js +23 -10
- package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.d.ts +12 -2
- package/dist/node/runtime/node/community/local-community/comment-updates.js +101 -70
- package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/db-state.js +8 -0
- package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/editing.d.ts +9 -2
- package/dist/node/runtime/node/community/local-community/editing.js +32 -5
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.d.ts +2 -2
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +49 -27
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.js +49 -18
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +5 -1
- package/dist/node/runtime/node/community/local-community.js +13 -1
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/community/page-generator.d.ts +44 -413
- package/dist/node/runtime/node/community/page-generator.js +531 -308
- package/dist/node/runtime/node/community/page-generator.js.map +1 -1
- package/dist/node/runtime/node/community/page-sorts/index.d.ts +64 -0
- package/dist/node/runtime/node/community/page-sorts/index.js +264 -0
- package/dist/node/runtime/node/community/page-sorts/index.js.map +1 -0
- package/dist/node/runtime/node/util.js +1 -1
- package/dist/node/runtime/node/util.js.map +1 -1
- package/dist/node/schema/schema-util.d.ts +142 -1
- package/dist/node/schema/schema-util.js +11 -0
- package/dist/node/schema/schema-util.js.map +1 -1
- package/dist/node/schema/schema.js +1 -1
- package/dist/node/schema/schema.js.map +1 -1
- package/dist/node/schema.d.ts +4469 -0
- package/dist/node/schema.js +2 -1
- package/dist/node/schema.js.map +1 -1
- package/dist/node/signer/signatures.d.ts +1 -1
- package/dist/node/signer/signatures.js +45 -1
- package/dist/node/signer/signatures.js.map +1 -1
- package/dist/node/test/test-util.d.ts +63 -0
- package/dist/node/test/test-util.js +66 -11
- package/dist/node/test/test-util.js.map +1 -1
- package/dist/node/util.d.ts +4 -0
- package/dist/node/util.js +93 -1
- package/dist/node/util.js.map +1 -1
- package/dist/node/version.js +1 -1
- package/package.json +2 -2
- package/dist/bundled/chunks/{src-Dz9wtvrK.js → src-B07ldGHS.js} +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import {
|
|
3
|
-
import { $ as
|
|
4
|
-
import {
|
|
2
|
+
import { $ as shortifyAddress, An as CommentIpfsSchema, Ar as PKCError, At as ChallengeMessageSchema, Ct as untrackUpdatingComment, Dt as pTimeout, E as isIpfsCid, Er as FailedToFetchCommentUpdateFromGatewaysError, Et as TimeoutError, Fn as CommentUpdateForChallengeVerificationSchema, Fr as setErrorMap, H as rejectWhenCommunityStopsOrAborts, J as replaceXWithY, Jr as stringifyPrimitive, Kr as joinValues, Kt as version_default, Mr as logger_default, Mt as ChallengeRequestMessageSchema, O as isIpns, Ot as ChallengeAnswerMessageSchema, Pt as ChallengeVerificationMessageSchema, Rn as CommentUpdateSchema, S as hideClassPrivateProps, T as isAbortError, Tr as FailedToFetchCommentIpfsFromGatewaysError, Tt as require_sha256, V as rejectWhenAbortSignalFires, Y as resolveWhenPredicateIsTrue, Z as retryKuboIpfsAdd, _r as r, at as waitForUpdateInCommunityInstanceWithErrorAndTimeout, b as getPostUpdateTimestampRange, bt as trackUpdatingComment, dn as CommunityIpfsSchema, dr as n$1, dt as findUpdatingComment, et as shortifyCid, f as doesDomainAddressHaveCapitalLetter, ft as findUpdatingCommunity, gt as refreshTrackedCommentAliases, hr as e$1, ht as listUpdatingCommunities, it as timestamp, jr as messages, l as createAbortError, lr as n$2, mr as e, mt as listUpdatingComments, on as CommunityAnchorSchema, pr as t$1, pt as listStartedCommunities, q as removeUndefinedValuesRecursively, qr as parsedType, rt as throwIfAbortSignalAborted, t as areEquivalentCommunityAddresses, tt as sleepUntilTimeoutOrAbort, u as deepMergeRuntimeFields, ut as findStartedCommunity, w as ipnsNameToIpnsOverPubsubTopic, wr as require_retry, wt as untrackUpdatingCommunity, xn as isStringDomain, yn as PubsubTopicSchema } from "./util-C6zDjhpr.js";
|
|
3
|
+
import { $n as getPKCAddressFromPublicKeySync, $t as RpcSubscriptionIdResultSchema, A as extractCommunityRuntimeFieldsFromParsedPages, An as verifyCommentModeration, Ar as NAME_RESOLVED_FALSE_TTL_MS, At as parseRpcCommentEventWithPKCErrorIfItFails, B as stripNameResolvedFromCrosspost, Bn as normalizeCreatePublicationAuthor, Bt as RpcCommunityIdentifierParamSchema, C as RemoteCommunity, Cn as signVote, Cr as t$3, Ct as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, Dn as verifyChallengeVerification, Dr as t$4, Dt as parseDecryptedChallengeWithPKCErrorIfItFails, E as RepliesPages, Er as t$2, Et as parseDecryptedChallengeVerification, F as parseRawPages, Fn as verifyVote, Fr as nativeFunctions$2, Ft as RpcAnchorPublishPreparationResultSchema, Gn as getCommunityNameFromWire, Gt as RpcExportCommunityParamSchema, H as GenericStateClient, Ht as RpcEditCommunityParamSchema, I as applyNameResolvedCacheToCrosspost, In as buildRuntimeAuthor, Ir as require_undici, It as RpcAuthorNameParamSchema, J as decodeRpcChallengeAnswerPubsubMsg, Jn as decode, Jt as RpcFetchCidResultSchema, Kn as getCommunityPublicKeyFromWire, Kt as RpcExportCommunityResultSchema, L as cloneCrosspostForRuntime, Ln as cleanWireAuthor, Lt as RpcCancelExportParamSchema, M as findCommentInPageInstanceRecursively, Mn as verifyCommentUpdate, Mr as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, Mt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, N as findCommentInParsedPages, On as verifyCommentEdit, Ot as parseJsonWithPKCErrorIfFails, Pn as verifyCommunityEdit, Pt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, Qt as RpcResolveAuthorNameResultSchema, R as collectCrosspostAuthorsToResolve, Rn as getAuthorNameFromRuntime, Rt as RpcCidParamSchema, S as LRUCache, Sn as signCommunityEdit, St as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, T as KeyvBetterSqlite3, Tn as verifyChallengeMessage, Tt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, U as InflightFetchManager, Un as buildRuntimeCommunityFields, Ut as RpcExportCommunityModLogsParamSchema, V as PKCClientsManager, Vt as RpcCommunityPageParamSchema, W as InflightResourceTypes, Wn as getCommunityAddressFromRecord, Wt as RpcExportCommunityModLogsResultSchema, X as decodeRpcChallengeRequestPubsubMsg, Xn as getBufferedPKCAddressFromPublicKey, Xt as RpcPublishChallengeAnswersParamSchema, Y as decodeRpcChallengePubsubMsg, Yt as RpcPublishAnchorRecordParamSchema, Z as decodeRpcChallengeVerificationPubsubMsg, Zt as RpcPublishedAnchorRecordResultSchema, _ as pkcJsChallenges, _n as signCommentEdit, _t as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, an as createAnchorIpnsRecord$1, ar as createKuboRpcClient, at as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, br as t$5, cn as encryptEd25519AesGcm, ct as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, dn as cleanUpBeforePublishing, dr as getDefaultDataPath, dt as parseCommunityAddressWithPKCErrorIfItFails, en as RpcSuccessResultSchema, fn as signChallengeAnswer, gn as signComment, gt as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, hr as monitorCommunitiesDirectory, in as createSigner, j as findCommentInPageInstance, jn as verifyCommentPubsubMessage, jr as NAME_RESOLVED_TRUE_TTL_MS, jt as parseRpcCommentUpdateEventWithPKCErrorIfItFails, kn as verifyCommentIpfs, kr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, kt as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, lt as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, mn as signChallengeRequest, mr as listCommunitiesSync, mt as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as require_lib$1, nt as parseCidStringSchemaWithPKCErrorIfItFails, on as decryptEd25519AesGcm, ot as parseCommentIpfsSchemaWithPKCErrorIfItFails, q as PKCTypedEmitter, qn as normalizeCommunityInputFromCommunity, qt as RpcFetchCidParamSchema, s as pkcJsPageSorts, t as RpcLocalCommunity, tn as RpcUnsubscribeParamSchema, ut as parseCommentUpdateSchemaWithPKCErrorIfItFails, vn as signCommentModeration, vr as setNativeFunctions$1, vt as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, wr as n$3, wt as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, x as TrackedInstanceRegistry, yr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, yt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, zt as RpcCommentRepliesPageParamSchema } from "./rpc-local-community-DHS2R2Vk.js";
|
|
4
|
+
import { s as getHeliaDebugContext } from "./util-B-wz3mKY.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import assert from "assert";
|
|
7
7
|
import fs from "fs";
|
|
@@ -149,9 +149,228 @@ function t(...t) {
|
|
|
149
149
|
}
|
|
150
150
|
const n = (e, t) => [...e].sort(t);
|
|
151
151
|
//#endregion
|
|
152
|
-
//#region dist/node/publications/publication.js
|
|
152
|
+
//#region dist/node/publications/publication-clients.js
|
|
153
153
|
var import_retry = /* @__PURE__ */ __toESM(require_retry(), 1);
|
|
154
154
|
var import_lib = require_lib$1();
|
|
155
|
+
var PublicationKuboRpcClient = class extends GenericStateClient {};
|
|
156
|
+
var PublicationKuboPubsubClient = class extends GenericStateClient {};
|
|
157
|
+
var PublicationPKCRpcStateClient = class extends GenericStateClient {};
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region dist/node/publications/publication-client-manager.js
|
|
160
|
+
var PublicationClientsManager = class extends PKCClientsManager {
|
|
161
|
+
constructor(publication) {
|
|
162
|
+
super(publication._pkc);
|
|
163
|
+
this._communityForUpdating = void 0;
|
|
164
|
+
this._publication = publication;
|
|
165
|
+
this._initPKCRpcClients();
|
|
166
|
+
this.handleErrorEventFromCommunity = this.handleErrorEventFromCommunity.bind(this);
|
|
167
|
+
this.handleIpfsGatewayCommunityState = this.handleIpfsGatewayCommunityState.bind(this);
|
|
168
|
+
this.handleUpdateEventFromCommunity = this.handleUpdateEventFromCommunity.bind(this);
|
|
169
|
+
this.handleUpdatingStateChangeEventFromCommunity = this.handleUpdatingStateChangeEventFromCommunity.bind(this);
|
|
170
|
+
}
|
|
171
|
+
_initKuboRpcClients() {
|
|
172
|
+
if (this._pkc.clients.kuboRpcClients) for (const ipfsUrl of t$1(this._pkc.clients.kuboRpcClients)) this.clients.kuboRpcClients = {
|
|
173
|
+
...this.clients.kuboRpcClients,
|
|
174
|
+
[ipfsUrl]: new PublicationKuboRpcClient("stopped")
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
_initPubsubKuboRpcClients() {
|
|
178
|
+
for (const pubsubUrl of t$1(this._pkc.clients.pubsubKuboRpcClients)) this.clients.pubsubKuboRpcClients = {
|
|
179
|
+
...this.clients.pubsubKuboRpcClients,
|
|
180
|
+
[pubsubUrl]: new PublicationKuboPubsubClient("stopped")
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
_initPKCRpcClients() {
|
|
184
|
+
for (const rpcUrl of t$1(this._pkc.clients.pkcRpcClients)) this.clients.pkcRpcClients = {
|
|
185
|
+
...this.clients.pkcRpcClients,
|
|
186
|
+
[rpcUrl]: new PublicationPKCRpcStateClient("stopped")
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
emitError(e) {
|
|
190
|
+
this._publication.emit("error", e);
|
|
191
|
+
}
|
|
192
|
+
updateKuboRpcState(newState, kuboRpcClientUrl) {
|
|
193
|
+
super.updateKuboRpcState(newState, kuboRpcClientUrl);
|
|
194
|
+
}
|
|
195
|
+
updateKuboRpcPubsubState(newState, pubsubProvider) {
|
|
196
|
+
super.updateKuboRpcPubsubState(newState, pubsubProvider);
|
|
197
|
+
}
|
|
198
|
+
updateGatewayState(newState, gateway) {
|
|
199
|
+
super.updateGatewayState(newState, gateway);
|
|
200
|
+
}
|
|
201
|
+
_translateCommunityUpdatingStateToPublishingState(newUpdatingState) {
|
|
202
|
+
const translatedState = {
|
|
203
|
+
failed: "failed",
|
|
204
|
+
"fetching-ipfs": "fetching-community-ipfs",
|
|
205
|
+
"fetching-ipns": "fetching-community-ipns",
|
|
206
|
+
"resolving-name": "resolving-community-name"
|
|
207
|
+
}[newUpdatingState];
|
|
208
|
+
if (translatedState) this._publication._updatePublishingStateWithEmission(translatedState);
|
|
209
|
+
}
|
|
210
|
+
handleUpdatingStateChangeEventFromCommunity(newUpdatingState) {
|
|
211
|
+
this._translateCommunityUpdatingStateToPublishingState(newUpdatingState);
|
|
212
|
+
}
|
|
213
|
+
handleUpdateEventFromCommunity(community) {}
|
|
214
|
+
handleErrorEventFromCommunity(err) {}
|
|
215
|
+
handleIpfsGatewayCommunityState(communityNewGatewayState, gatewayUrl) {
|
|
216
|
+
this.updateGatewayState(communityNewGatewayState === "fetching-ipns" ? "fetching-community-ipns" : communityNewGatewayState, gatewayUrl);
|
|
217
|
+
}
|
|
218
|
+
handleNameResolverCommunityState(communityNewResolverState, resolverKey) {
|
|
219
|
+
if (communityNewResolverState === "resolving-author-name") return;
|
|
220
|
+
this.updateNameResolverState(communityNewResolverState, resolverKey);
|
|
221
|
+
}
|
|
222
|
+
handleKuboRpcCommunityState(communityNewKuboRpcState, kuboRpcUrl) {
|
|
223
|
+
const translatedState = {
|
|
224
|
+
"fetching-ipns": "fetching-community-ipns",
|
|
225
|
+
"fetching-ipfs": "fetching-community-ipfs",
|
|
226
|
+
stopped: "stopped",
|
|
227
|
+
"publishing-ipns": void 0
|
|
228
|
+
}[communityNewKuboRpcState];
|
|
229
|
+
if (translatedState) this.updateKuboRpcState(translatedState, kuboRpcUrl);
|
|
230
|
+
}
|
|
231
|
+
handleLibp2pJsClientCommunityState(communityNewLibp2pJsState, libp2pJsClientKey) {
|
|
232
|
+
const translatedState = {
|
|
233
|
+
"fetching-ipns": "fetching-community-ipns",
|
|
234
|
+
"fetching-ipfs": "fetching-community-ipfs",
|
|
235
|
+
stopped: "stopped",
|
|
236
|
+
"publishing-ipns": void 0,
|
|
237
|
+
"waiting-challenge-answers": void 0,
|
|
238
|
+
"waiting-challenge-requests": void 0,
|
|
239
|
+
"publishing-challenge": void 0,
|
|
240
|
+
"publishing-challenge-verification": void 0
|
|
241
|
+
}[communityNewLibp2pJsState];
|
|
242
|
+
if (translatedState) this.updateLibp2pJsClientState(translatedState, libp2pJsClientKey);
|
|
243
|
+
}
|
|
244
|
+
async _createCommunityInstanceWithStateTranslation() {
|
|
245
|
+
const directCommunityInstance = findUpdatingCommunity(this._pkc, {
|
|
246
|
+
publicKey: this._publication.communityPublicKey,
|
|
247
|
+
name: this._publication.communityName
|
|
248
|
+
}) || findStartedCommunity(this._pkc, {
|
|
249
|
+
publicKey: this._publication.communityPublicKey,
|
|
250
|
+
name: this._publication.communityName
|
|
251
|
+
});
|
|
252
|
+
const community = directCommunityInstance || await this._pkc.createCommunity({
|
|
253
|
+
name: this._publication.communityName,
|
|
254
|
+
publicKey: this._publication.communityPublicKey
|
|
255
|
+
}, { abortSignal: this._publication._getCommunityFetchAbortSignal() });
|
|
256
|
+
this._communityForUpdating = {
|
|
257
|
+
community,
|
|
258
|
+
error: this.handleErrorEventFromCommunity.bind(this),
|
|
259
|
+
update: this.handleUpdateEventFromCommunity.bind(this),
|
|
260
|
+
updatingstatechange: this.handleUpdatingStateChangeEventFromCommunity.bind(this)
|
|
261
|
+
};
|
|
262
|
+
if (this._communityForUpdating.community.clients.ipfsGateways && Object.keys(this._communityForUpdating.community.clients.ipfsGateways).length > 0) {
|
|
263
|
+
const ipfsGatewayListeners = {};
|
|
264
|
+
for (const gatewayUrl of Object.keys(this._communityForUpdating.community.clients.ipfsGateways)) {
|
|
265
|
+
const ipfsStateListener = (communityNewIpfsState) => this.handleIpfsGatewayCommunityState(communityNewIpfsState, gatewayUrl);
|
|
266
|
+
this._communityForUpdating.community.clients.ipfsGateways[gatewayUrl].on("statechange", ipfsStateListener);
|
|
267
|
+
ipfsGatewayListeners[gatewayUrl] = ipfsStateListener;
|
|
268
|
+
}
|
|
269
|
+
this._communityForUpdating.ipfsGatewayListeners = ipfsGatewayListeners;
|
|
270
|
+
}
|
|
271
|
+
if (this._communityForUpdating.community.clients.kuboRpcClients && Object.keys(this._communityForUpdating.community.clients.kuboRpcClients).length > 0) {
|
|
272
|
+
const kuboRpcListeners = {};
|
|
273
|
+
for (const kuboRpcUrl of Object.keys(this._communityForUpdating.community.clients.kuboRpcClients)) {
|
|
274
|
+
const kuboRpcStateListener = (communityNewKuboRpcState) => this.handleKuboRpcCommunityState(communityNewKuboRpcState, kuboRpcUrl);
|
|
275
|
+
this._communityForUpdating.community.clients.kuboRpcClients[kuboRpcUrl].on("statechange", kuboRpcStateListener);
|
|
276
|
+
kuboRpcListeners[kuboRpcUrl] = kuboRpcStateListener;
|
|
277
|
+
}
|
|
278
|
+
this._communityForUpdating.kuboRpcListeners = kuboRpcListeners;
|
|
279
|
+
}
|
|
280
|
+
if (this._communityForUpdating.community.clients.libp2pJsClients && Object.keys(this._communityForUpdating.community.clients.libp2pJsClients).length > 0) {
|
|
281
|
+
const libp2pJsListeners = {};
|
|
282
|
+
for (const libp2pJsClientKey of Object.keys(this._communityForUpdating.community.clients.libp2pJsClients)) {
|
|
283
|
+
const libp2pJsClientStateListener = (communityNewLibp2pJsState) => this.handleLibp2pJsClientCommunityState(communityNewLibp2pJsState, libp2pJsClientKey);
|
|
284
|
+
this._communityForUpdating.community.clients.libp2pJsClients[libp2pJsClientKey].on("statechange", libp2pJsClientStateListener);
|
|
285
|
+
libp2pJsListeners[libp2pJsClientKey] = libp2pJsClientStateListener;
|
|
286
|
+
}
|
|
287
|
+
this._communityForUpdating.libp2pJsListeners = libp2pJsListeners;
|
|
288
|
+
}
|
|
289
|
+
if (this._communityForUpdating.community.clients.nameResolvers && Object.keys(this._communityForUpdating.community.clients.nameResolvers).length > 0) {
|
|
290
|
+
const nameResolverListeners = {};
|
|
291
|
+
for (const resolverKey of Object.keys(this._communityForUpdating.community.clients.nameResolvers)) {
|
|
292
|
+
const resolverStateListener = (communityNewResolverState) => this.handleNameResolverCommunityState(communityNewResolverState, resolverKey);
|
|
293
|
+
this._communityForUpdating.community.clients.nameResolvers[resolverKey].on("statechange", resolverStateListener);
|
|
294
|
+
nameResolverListeners[resolverKey] = resolverStateListener;
|
|
295
|
+
}
|
|
296
|
+
this._communityForUpdating.nameResolverListeners = nameResolverListeners;
|
|
297
|
+
}
|
|
298
|
+
this._communityForUpdating.community.on("update", this._communityForUpdating.update);
|
|
299
|
+
this._communityForUpdating.community.on("updatingstatechange", this._communityForUpdating.updatingstatechange);
|
|
300
|
+
this._communityForUpdating.community.on("error", this._communityForUpdating.error);
|
|
301
|
+
if (directCommunityInstance) directCommunityInstance._numOfListenersForUpdatingInstance++;
|
|
302
|
+
return this._communityForUpdating;
|
|
303
|
+
}
|
|
304
|
+
async cleanUpUpdatingCommunityInstance() {
|
|
305
|
+
if (!this._communityForUpdating) throw Error("Need to define communityForUpdating first");
|
|
306
|
+
if (this._communityForUpdating.ipfsGatewayListeners) for (const gatewayUrl of Object.keys(this._communityForUpdating.ipfsGatewayListeners)) {
|
|
307
|
+
this._communityForUpdating.community.clients.ipfsGateways[gatewayUrl].removeListener("statechange", this._communityForUpdating.ipfsGatewayListeners[gatewayUrl]);
|
|
308
|
+
this.updateGatewayState("stopped", gatewayUrl);
|
|
309
|
+
}
|
|
310
|
+
if (this._communityForUpdating.kuboRpcListeners) for (const kuboRpcUrl of Object.keys(this._communityForUpdating.kuboRpcListeners)) {
|
|
311
|
+
this._communityForUpdating.community.clients.kuboRpcClients[kuboRpcUrl].removeListener("statechange", this._communityForUpdating.kuboRpcListeners[kuboRpcUrl]);
|
|
312
|
+
this.updateKuboRpcState("stopped", kuboRpcUrl);
|
|
313
|
+
}
|
|
314
|
+
if (this._communityForUpdating.libp2pJsListeners) for (const libp2pJsClientKey of Object.keys(this._communityForUpdating.libp2pJsListeners)) {
|
|
315
|
+
this._communityForUpdating.community.clients.libp2pJsClients[libp2pJsClientKey].removeListener("statechange", this._communityForUpdating.libp2pJsListeners[libp2pJsClientKey]);
|
|
316
|
+
this.updateLibp2pJsClientState("stopped", libp2pJsClientKey);
|
|
317
|
+
}
|
|
318
|
+
if (this._communityForUpdating.nameResolverListeners) for (const resolverKey of Object.keys(this._communityForUpdating.nameResolverListeners)) {
|
|
319
|
+
this._communityForUpdating.community.clients.nameResolvers[resolverKey].removeListener("statechange", this._communityForUpdating.nameResolverListeners[resolverKey]);
|
|
320
|
+
this.updateNameResolverState("stopped", resolverKey);
|
|
321
|
+
}
|
|
322
|
+
this._communityForUpdating.community.removeListener("updatingstatechange", this._communityForUpdating.updatingstatechange);
|
|
323
|
+
this._communityForUpdating.community.removeListener("error", this._communityForUpdating.error);
|
|
324
|
+
this._communityForUpdating.community.removeListener("update", this._communityForUpdating.update);
|
|
325
|
+
if (this._communityForUpdating.community._updatingCommunityInstanceWithListeners) await this._communityForUpdating.community.stop();
|
|
326
|
+
else {
|
|
327
|
+
this._communityForUpdating.community._numOfListenersForUpdatingInstance--;
|
|
328
|
+
if (this._communityForUpdating.community._numOfListenersForUpdatingInstance <= 0 && this._communityForUpdating.community.state === "updating") {
|
|
329
|
+
untrackUpdatingCommunity(this._pkc, this._communityForUpdating.community);
|
|
330
|
+
await this._communityForUpdating.community.stop();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
this._communityForUpdating = void 0;
|
|
334
|
+
}
|
|
335
|
+
async fetchCommunityForPublishingWithCacheGuard() {
|
|
336
|
+
return this._loadCommunityForPublishingFromNetwork();
|
|
337
|
+
}
|
|
338
|
+
async _loadCommunityForPublishingFromNetwork() {
|
|
339
|
+
const updatingCommunityInstance = await this._createCommunityInstanceWithStateTranslation();
|
|
340
|
+
let communityIpfs;
|
|
341
|
+
if (!updatingCommunityInstance.community.raw.communityIpfs) {
|
|
342
|
+
const timeoutMs = this._pkc._timeouts["community-ipns"];
|
|
343
|
+
try {
|
|
344
|
+
await waitForUpdateInCommunityInstanceWithErrorAndTimeout({
|
|
345
|
+
community: updatingCommunityInstance.community,
|
|
346
|
+
timeoutMs,
|
|
347
|
+
abortSignal: this._publication._getCommunityFetchAbortSignal()
|
|
348
|
+
});
|
|
349
|
+
communityIpfs = updatingCommunityInstance.community.raw.communityIpfs;
|
|
350
|
+
} catch (e) {
|
|
351
|
+
await this.cleanUpUpdatingCommunityInstance();
|
|
352
|
+
throw e;
|
|
353
|
+
}
|
|
354
|
+
await this.cleanUpUpdatingCommunityInstance();
|
|
355
|
+
} else {
|
|
356
|
+
communityIpfs = updatingCommunityInstance.community.raw.communityIpfs;
|
|
357
|
+
await this.cleanUpUpdatingCommunityInstance();
|
|
358
|
+
}
|
|
359
|
+
if (!communityIpfs) throw new PKCError("ERR_GET_COMMUNITY_TIMED_OUT", {
|
|
360
|
+
communityAddress: updatingCommunityInstance.community.address,
|
|
361
|
+
timeoutMs: this._pkc._timeouts["community-ipns"]
|
|
362
|
+
});
|
|
363
|
+
return {
|
|
364
|
+
address: updatingCommunityInstance.community.address,
|
|
365
|
+
publicKey: updatingCommunityInstance.community.publicKey,
|
|
366
|
+
name: updatingCommunityInstance.community.name,
|
|
367
|
+
encryption: communityIpfs.encryption,
|
|
368
|
+
pubsubTopic: communityIpfs.pubsubTopic
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region dist/node/publications/publication.js
|
|
155
374
|
var Publication = class extends import_lib.TypedEmitter {
|
|
156
375
|
constructor(pkc) {
|
|
157
376
|
super();
|
|
@@ -1140,6 +1359,968 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
1140
1359
|
}
|
|
1141
1360
|
};
|
|
1142
1361
|
//#endregion
|
|
1362
|
+
//#region dist/node/publications/comment/comment-clients.js
|
|
1363
|
+
var CommentLibp2pJsClient = class extends GenericStateClient {};
|
|
1364
|
+
var CommentKuboRpcClient = class extends GenericStateClient {};
|
|
1365
|
+
var CommentPKCRpcStateClient = class extends GenericStateClient {};
|
|
1366
|
+
//#endregion
|
|
1367
|
+
//#region dist/node/publications/comment/comment-util.js
|
|
1368
|
+
async function loadAllPagesUnderCommunityToFindComment(opts) {
|
|
1369
|
+
const { commentCidToFind, community, signal, postCid, parentCid } = opts;
|
|
1370
|
+
if (!commentCidToFind) throw Error("commentCidToFind should be defined");
|
|
1371
|
+
const log = logger_default("pkc-js:comment:loadAllPagesUnderCommunityToFindComment");
|
|
1372
|
+
const queue = [];
|
|
1373
|
+
const queued = /* @__PURE__ */ new Map();
|
|
1374
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1375
|
+
const parentCommentCache = /* @__PURE__ */ new Map();
|
|
1376
|
+
const resetTraversalState = () => {
|
|
1377
|
+
queue.length = 0;
|
|
1378
|
+
queued.clear();
|
|
1379
|
+
visited.clear();
|
|
1380
|
+
};
|
|
1381
|
+
const getParentCommentInstance = (parentCid) => {
|
|
1382
|
+
let existing = parentCommentCache.get(parentCid);
|
|
1383
|
+
if (!existing) {
|
|
1384
|
+
existing = community._pkc.getComment({ cid: parentCid });
|
|
1385
|
+
parentCommentCache.set(parentCid, existing);
|
|
1386
|
+
}
|
|
1387
|
+
return existing;
|
|
1388
|
+
};
|
|
1389
|
+
const throwIfAborted = () => {
|
|
1390
|
+
if (!signal?.aborted) return;
|
|
1391
|
+
const abortErr = /* @__PURE__ */ new Error("Aborted");
|
|
1392
|
+
abortErr.name = "AbortError";
|
|
1393
|
+
throw abortErr;
|
|
1394
|
+
};
|
|
1395
|
+
const normalizePage = (page) => {
|
|
1396
|
+
if ("comments" in page && page.comments.length > 0 && "raw" in page.comments[0]) return {
|
|
1397
|
+
comments: page.comments.map((comment) => comment.raw),
|
|
1398
|
+
nextCid: page.nextCid
|
|
1399
|
+
};
|
|
1400
|
+
return page;
|
|
1401
|
+
};
|
|
1402
|
+
const getPageKey = (cid, source, parentCommentCid) => `${source}:${parentCommentCid || ""}:${cid}`;
|
|
1403
|
+
const enqueue = (cid, source, parentCommentCid) => {
|
|
1404
|
+
if (typeof cid !== "string" || cid.length === 0) return;
|
|
1405
|
+
const key = getPageKey(cid, source, parentCommentCid);
|
|
1406
|
+
if (visited.has(key)) return;
|
|
1407
|
+
if (queued.get(key)) return;
|
|
1408
|
+
const entry = {
|
|
1409
|
+
cid,
|
|
1410
|
+
source,
|
|
1411
|
+
parentCommentCid
|
|
1412
|
+
};
|
|
1413
|
+
queued.set(key, entry);
|
|
1414
|
+
queue.push(entry);
|
|
1415
|
+
};
|
|
1416
|
+
const fetchPage = async (cid, source, parentCommentCid) => {
|
|
1417
|
+
throwIfAborted();
|
|
1418
|
+
if (source === "posts") try {
|
|
1419
|
+
return await community.posts.getPage({ cid });
|
|
1420
|
+
} catch (err) {
|
|
1421
|
+
log.trace("posts.getPage failed", {
|
|
1422
|
+
cid,
|
|
1423
|
+
err
|
|
1424
|
+
});
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
else {
|
|
1428
|
+
if (!parentCommentCid) return void 0;
|
|
1429
|
+
try {
|
|
1430
|
+
return await (await getParentCommentInstance(parentCommentCid)).replies.getPage({ cid });
|
|
1431
|
+
} catch (err) {
|
|
1432
|
+
log.trace("replies.getPage failed", {
|
|
1433
|
+
cid,
|
|
1434
|
+
parentCommentCid,
|
|
1435
|
+
err
|
|
1436
|
+
});
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
const processReplies = async (replies, parentCommentCid) => {
|
|
1442
|
+
throwIfAborted();
|
|
1443
|
+
if (!replies) return void 0;
|
|
1444
|
+
if (replies.pages) for (const page of Object.values(replies.pages)) {
|
|
1445
|
+
if (!page) continue;
|
|
1446
|
+
const comment = await processPage(page, "replies", parentCommentCid);
|
|
1447
|
+
if (comment) return comment;
|
|
1448
|
+
}
|
|
1449
|
+
if (replies.pageCids) enqueue(replies.pageCids.new || Object.values(replies.pageCids)[0], "replies", parentCommentCid);
|
|
1450
|
+
};
|
|
1451
|
+
const processPage = async (page, source, parentCommentCid) => {
|
|
1452
|
+
throwIfAborted();
|
|
1453
|
+
const pageIpfs = normalizePage(page);
|
|
1454
|
+
for (const pageComment of pageIpfs.comments) {
|
|
1455
|
+
if (pageComment.commentUpdate.cid === commentCidToFind) return pageComment;
|
|
1456
|
+
const childComment = await processReplies(pageComment.commentUpdate.replies, pageComment.commentUpdate.cid);
|
|
1457
|
+
if (childComment) return childComment;
|
|
1458
|
+
}
|
|
1459
|
+
if (pageIpfs.nextCid) enqueue(pageIpfs.nextCid, source, parentCommentCid);
|
|
1460
|
+
};
|
|
1461
|
+
const drainQueue = async (processPageFunc) => {
|
|
1462
|
+
while (queue.length) {
|
|
1463
|
+
throwIfAborted();
|
|
1464
|
+
const { cid, source, parentCommentCid } = queue.shift();
|
|
1465
|
+
const pageKey = getPageKey(cid, source, parentCommentCid);
|
|
1466
|
+
queued.delete(pageKey);
|
|
1467
|
+
if (visited.has(pageKey)) continue;
|
|
1468
|
+
visited.add(pageKey);
|
|
1469
|
+
const page = await fetchPage(cid, source, parentCommentCid);
|
|
1470
|
+
if (!page) continue;
|
|
1471
|
+
const foundComment = await processPageFunc(page, source, parentCommentCid);
|
|
1472
|
+
if (foundComment) return foundComment;
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
const processPageForCidOnly = (targetCid) => async (page, source, _parentCommentCid) => {
|
|
1476
|
+
throwIfAborted();
|
|
1477
|
+
const pageIpfs = normalizePage(page);
|
|
1478
|
+
for (const pageComment of pageIpfs.comments) if (pageComment.commentUpdate.cid === targetCid) return pageComment;
|
|
1479
|
+
if (pageIpfs.nextCid) enqueue(pageIpfs.nextCid, source);
|
|
1480
|
+
};
|
|
1481
|
+
const findPostCommentInCommunity = async (targetPostCid) => {
|
|
1482
|
+
const processPostPage = processPageForCidOnly(targetPostCid);
|
|
1483
|
+
for (const page of Object.values(community.posts.pages || {})) {
|
|
1484
|
+
if (!page) continue;
|
|
1485
|
+
const comment = await processPostPage(page, "posts");
|
|
1486
|
+
if (comment) return comment;
|
|
1487
|
+
}
|
|
1488
|
+
enqueue(community.posts.pageCids?.new || Object.values(community.posts.pageCids || {}).find((cid) => typeof cid === "string"), "posts");
|
|
1489
|
+
const foundFromQueue = await drainQueue(processPostPage);
|
|
1490
|
+
if (foundFromQueue) return foundFromQueue;
|
|
1491
|
+
};
|
|
1492
|
+
const searchUnderParent = async (parentCommentCid) => {
|
|
1493
|
+
resetTraversalState();
|
|
1494
|
+
try {
|
|
1495
|
+
const foundFromReplies = await processReplies((await getParentCommentInstance(parentCommentCid)).replies, parentCommentCid);
|
|
1496
|
+
if (foundFromReplies) return foundFromReplies;
|
|
1497
|
+
const foundFromQueue = await drainQueue(processPage);
|
|
1498
|
+
if (foundFromQueue) return foundFromQueue;
|
|
1499
|
+
} catch (err) {
|
|
1500
|
+
log.trace("searchUnderParent failed", {
|
|
1501
|
+
parentCommentCid,
|
|
1502
|
+
err
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
const searchUnderPost = async (postCidToSearch) => {
|
|
1507
|
+
resetTraversalState();
|
|
1508
|
+
const postComment = await findPostCommentInCommunity(postCidToSearch);
|
|
1509
|
+
if (!postComment) return void 0;
|
|
1510
|
+
if (postComment.commentUpdate.cid === commentCidToFind) return postComment;
|
|
1511
|
+
resetTraversalState();
|
|
1512
|
+
const foundFromReplies = await processReplies(postComment.commentUpdate.replies, postCidToSearch);
|
|
1513
|
+
if (foundFromReplies) return foundFromReplies;
|
|
1514
|
+
return await drainQueue(processPage);
|
|
1515
|
+
};
|
|
1516
|
+
if (parentCid) {
|
|
1517
|
+
const foundFromParent = await searchUnderParent(parentCid);
|
|
1518
|
+
if (foundFromParent) return foundFromParent;
|
|
1519
|
+
}
|
|
1520
|
+
if (postCid) {
|
|
1521
|
+
const foundFromPost = await searchUnderPost(postCid);
|
|
1522
|
+
if (foundFromPost) return foundFromPost;
|
|
1523
|
+
}
|
|
1524
|
+
resetTraversalState();
|
|
1525
|
+
for (const page of Object.values(community.posts.pages || {})) {
|
|
1526
|
+
if (!page) continue;
|
|
1527
|
+
const comment = await processPage(page, "posts");
|
|
1528
|
+
if (comment) return comment;
|
|
1529
|
+
}
|
|
1530
|
+
enqueue(community.posts.pageCids?.new || Object.values(community.posts.pageCids || {}).find((cid) => typeof cid === "string"), "posts");
|
|
1531
|
+
return await drainQueue(processPage);
|
|
1532
|
+
}
|
|
1533
|
+
//#endregion
|
|
1534
|
+
//#region dist/node/publications/comment/comment-client-manager.js
|
|
1535
|
+
const fetchCommentLogger = logger_default("pkc-js:comment:client-manager:fetchAndVerifyCommentCid");
|
|
1536
|
+
var CommentClientsManager = class extends PublicationClientsManager {
|
|
1537
|
+
constructor(comment) {
|
|
1538
|
+
super(comment);
|
|
1539
|
+
this._postForUpdating = void 0;
|
|
1540
|
+
this._comment = comment;
|
|
1541
|
+
this._fetchingUpdateForReplyUsingPageCidsPromise = void 0;
|
|
1542
|
+
this._parentFirstPageCidsAlreadyLoaded = /* @__PURE__ */ new Set();
|
|
1543
|
+
hideClassPrivateProps(this);
|
|
1544
|
+
}
|
|
1545
|
+
_resetFreshHandlerAbortController() {
|
|
1546
|
+
if (this._freshHandlerAbortController) this._freshHandlerAbortController.abort();
|
|
1547
|
+
this._freshHandlerAbortController = new AbortController();
|
|
1548
|
+
}
|
|
1549
|
+
_combinedAbortSignalForRetry() {
|
|
1550
|
+
const signals = [this._comment._getStopAbortSignal(), this._freshHandlerAbortController?.signal].filter((s) => Boolean(s));
|
|
1551
|
+
if (signals.length === 0) return void 0;
|
|
1552
|
+
if (signals.length === 1) return signals[0];
|
|
1553
|
+
return AbortSignal.any(signals);
|
|
1554
|
+
}
|
|
1555
|
+
_initKuboRpcClients() {
|
|
1556
|
+
if (this._pkc.clients.kuboRpcClients) for (const ipfsUrl of t$1(this._pkc.clients.kuboRpcClients)) this.clients.kuboRpcClients = {
|
|
1557
|
+
...this.clients.kuboRpcClients,
|
|
1558
|
+
[ipfsUrl]: new CommentKuboRpcClient("stopped")
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
_initLibp2pJsClients() {
|
|
1562
|
+
for (const libp2pJsClientKey of t$1(this._pkc.clients.libp2pJsClients)) this.clients.libp2pJsClients = {
|
|
1563
|
+
...this.clients.libp2pJsClients,
|
|
1564
|
+
[libp2pJsClientKey]: new CommentLibp2pJsClient("stopped")
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
_initPKCRpcClients() {
|
|
1568
|
+
for (const rpcUrl of t$1(this._pkc.clients.pkcRpcClients)) this.clients.pkcRpcClients = {
|
|
1569
|
+
...this.clients.pkcRpcClients,
|
|
1570
|
+
[rpcUrl]: new CommentPKCRpcStateClient("stopped")
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
updateLibp2pJsClientState(newState, libp2pJsClientKey) {
|
|
1574
|
+
super.updateLibp2pJsClientState(newState, libp2pJsClientKey);
|
|
1575
|
+
}
|
|
1576
|
+
updateKuboRpcState(newState, kuboRpcClientUrl) {
|
|
1577
|
+
super.updateKuboRpcState(newState, kuboRpcClientUrl);
|
|
1578
|
+
}
|
|
1579
|
+
updateGatewayState(newState, ipfsGatewayClientUrl) {
|
|
1580
|
+
super.updateGatewayState(newState, ipfsGatewayClientUrl);
|
|
1581
|
+
}
|
|
1582
|
+
updateKuboRpcPubsubState(newState, pubsubKuboRpcClientUrl) {
|
|
1583
|
+
super.updateKuboRpcPubsubState(newState, pubsubKuboRpcClientUrl);
|
|
1584
|
+
}
|
|
1585
|
+
preResolveNameResolver(opts) {
|
|
1586
|
+
super.preResolveNameResolver(opts);
|
|
1587
|
+
if (this._comment.state === "updating") this._comment._setUpdatingStateWithEmissionIfNewState("resolving-author-name");
|
|
1588
|
+
}
|
|
1589
|
+
_calculatePathForPostCommentUpdate(folderCid, postCid) {
|
|
1590
|
+
return `${folderCid}/` + postCid + "/update";
|
|
1591
|
+
}
|
|
1592
|
+
_bitswapSessionSeedScopeIpnsPubsubTopic() {
|
|
1593
|
+
if (this._communityForUpdating?.community?.ipnsPubsubTopic) return this._communityForUpdating.community.ipnsPubsubTopic;
|
|
1594
|
+
const communityAddress = this._comment.communityAddress;
|
|
1595
|
+
if (communityAddress && isIpns(communityAddress)) return ipnsNameToIpnsOverPubsubTopic(communityAddress);
|
|
1596
|
+
}
|
|
1597
|
+
_updateKuboRpcClientOrHeliaState(newState, kuboRpcOrHelia) {
|
|
1598
|
+
if ("_helia" in kuboRpcOrHelia) this.updateLibp2pJsClientState(newState, kuboRpcOrHelia._libp2pJsClientsOptions.key);
|
|
1599
|
+
else this.updateKuboRpcState(newState, kuboRpcOrHelia.url);
|
|
1600
|
+
}
|
|
1601
|
+
async _fetchPostCommentUpdateIpfsP2P(subIpns, timestampRanges, log) {
|
|
1602
|
+
const attemptedPathsToLoadErrors = {};
|
|
1603
|
+
const kuboRpcOrHelia = this.getDefaultKuboRpcClientOrHelia();
|
|
1604
|
+
if (timestampRanges.some((timestampRange) => {
|
|
1605
|
+
if (!this._comment._commentUpdateIpfsPath) return false;
|
|
1606
|
+
return subIpns.postUpdates[timestampRange] === this._comment._commentUpdateIpfsPath.split("/")[0];
|
|
1607
|
+
})) {
|
|
1608
|
+
log("Comment", this._comment.cid, "last post update range has same folder cid", this._comment._commentUpdateIpfsPath, "will be skipping loading CommentUpdate");
|
|
1609
|
+
return;
|
|
1610
|
+
}
|
|
1611
|
+
this._comment._setUpdatingStateWithEmissionIfNewState("fetching-update-ipfs");
|
|
1612
|
+
for (const timestampRange of timestampRanges) {
|
|
1613
|
+
const folderCid = subIpns.postUpdates[timestampRange];
|
|
1614
|
+
const path = this._calculatePathForPostCommentUpdate(folderCid, this._comment.postCid);
|
|
1615
|
+
this._updateKuboRpcClientOrHeliaState("fetching-update-ipfs", kuboRpcOrHelia);
|
|
1616
|
+
let res;
|
|
1617
|
+
const commentUpdateTimeoutMs = this._pkc._timeouts["comment-update-ipfs"];
|
|
1618
|
+
const abortSignal = this._combinedAbortSignalForRetry();
|
|
1619
|
+
try {
|
|
1620
|
+
res = await this._retryTransientP2PFetch(() => this._fetchCidP2P(path, {
|
|
1621
|
+
maxFileSizeBytes: MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE,
|
|
1622
|
+
timeoutMs: commentUpdateTimeoutMs,
|
|
1623
|
+
abortSignal,
|
|
1624
|
+
bitswapSessionSeedScopeIpnsPubsubTopic: this._bitswapSessionSeedScopeIpnsPubsubTopic()
|
|
1625
|
+
}), {
|
|
1626
|
+
abortSignal,
|
|
1627
|
+
log,
|
|
1628
|
+
context: `post-update ${path}`
|
|
1629
|
+
});
|
|
1630
|
+
} catch (e) {
|
|
1631
|
+
log.trace(`Failed to fetch CommentUpdate from path (${path}) with IPFS P2P. Trying the next timestamp range`);
|
|
1632
|
+
attemptedPathsToLoadErrors[path] = e;
|
|
1633
|
+
continue;
|
|
1634
|
+
} finally {
|
|
1635
|
+
this._updateKuboRpcClientOrHeliaState("stopped", kuboRpcOrHelia);
|
|
1636
|
+
}
|
|
1637
|
+
try {
|
|
1638
|
+
const commentUpdate = parseCommentUpdateSchemaWithPKCErrorIfItFails(parseJsonWithPKCErrorIfFails(res));
|
|
1639
|
+
await this._throwIfCommentUpdateHasInvalidSignature(commentUpdate, subIpns);
|
|
1640
|
+
if (commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) return {
|
|
1641
|
+
commentUpdate,
|
|
1642
|
+
commentUpdateIpfsPath: path
|
|
1643
|
+
};
|
|
1644
|
+
else return void 0;
|
|
1645
|
+
} catch (e) {
|
|
1646
|
+
this._comment._invalidCommentUpdateMfsPaths.add(path);
|
|
1647
|
+
if (e instanceof PKCError) e.details = {
|
|
1648
|
+
...e.details,
|
|
1649
|
+
commentUpdatePath: path,
|
|
1650
|
+
postCid: this._comment.cid
|
|
1651
|
+
};
|
|
1652
|
+
throw e;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
throw new PKCError("ERR_FAILED_TO_FETCH_COMMENT_UPDATE_FROM_ALL_POST_UPDATES_RANGES", {
|
|
1656
|
+
timestampRanges,
|
|
1657
|
+
attemptedPathsToLoadErrors,
|
|
1658
|
+
postCid: this._comment.cid,
|
|
1659
|
+
commentDepth: this._comment.depth
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
_shouldWeFetchCommentUpdateFromNextTimestamp(err) {
|
|
1663
|
+
if (!(err instanceof PKCError)) return false;
|
|
1664
|
+
if (err.code === "ERR_COMMENT_UPDATE_SIGNATURE_IS_INVALID" || err.code === "ERR_INVALID_COMMENT_UPDATE_SCHEMA" || err.code === "ERR_OVER_DOWNLOAD_LIMIT" || err.code === "ERR_INVALID_JSON") return false;
|
|
1665
|
+
if (err instanceof FailedToFetchCommentUpdateFromGatewaysError) {
|
|
1666
|
+
for (const gatewayError of Object.values(err.details.gatewayToError)) if (this._shouldWeFetchCommentUpdateFromNextTimestamp(gatewayError)) return true;
|
|
1667
|
+
return false;
|
|
1668
|
+
}
|
|
1669
|
+
return true;
|
|
1670
|
+
}
|
|
1671
|
+
async _throwIfCommentUpdateHasInvalidSignature(commentUpdate, communityIpfs) {
|
|
1672
|
+
if (!this._comment.raw.comment) throw Error("Can't validate comment update when CommentIpfs hasn't been loaded");
|
|
1673
|
+
if (!this._comment.cid) throw Error("can't validate comment update when cid is not defined");
|
|
1674
|
+
if (!this._comment.postCid) throw Error("can't validate comment update when postCid is not defined");
|
|
1675
|
+
const verifyOptions = {
|
|
1676
|
+
update: commentUpdate,
|
|
1677
|
+
resolveAuthorNames: this._pkc.resolveAuthorNames,
|
|
1678
|
+
clientsManager: this,
|
|
1679
|
+
community: {
|
|
1680
|
+
publicKey: getPKCAddressFromPublicKeySync(communityIpfs.signature.publicKey),
|
|
1681
|
+
name: communityIpfs.name,
|
|
1682
|
+
signature: communityIpfs.signature
|
|
1683
|
+
},
|
|
1684
|
+
comment: {
|
|
1685
|
+
...this._comment.raw.comment,
|
|
1686
|
+
cid: this._comment.cid,
|
|
1687
|
+
postCid: this._comment.postCid
|
|
1688
|
+
},
|
|
1689
|
+
validatePages: this._pkc.validatePages,
|
|
1690
|
+
validateUpdateSignature: true,
|
|
1691
|
+
abortSignal: this._comment._getStopAbortSignal()
|
|
1692
|
+
};
|
|
1693
|
+
const signatureValidity = await verifyCommentUpdate(verifyOptions);
|
|
1694
|
+
if (!signatureValidity.valid) throw new PKCError("ERR_COMMENT_UPDATE_SIGNATURE_IS_INVALID", {
|
|
1695
|
+
signatureValidity,
|
|
1696
|
+
verifyOptions
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
async _fetchPostCommentUpdateFromGateways(subIpns, timestampRanges, log) {
|
|
1700
|
+
if (timestampRanges.some((timestampRange) => {
|
|
1701
|
+
if (!this._comment._commentUpdateIpfsPath) return false;
|
|
1702
|
+
return subIpns.postUpdates[timestampRange] === this._comment._commentUpdateIpfsPath.split("/")[0];
|
|
1703
|
+
})) {
|
|
1704
|
+
log("Comment", this._comment.cid, "last post update range has same folder cid", this._comment._commentUpdateIpfsPath, "will be skipping loading CommentUpdate");
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1707
|
+
const attemptedPathsToLoadErrors = {};
|
|
1708
|
+
let commentUpdate;
|
|
1709
|
+
const validateCommentFromGateway = async (res) => {
|
|
1710
|
+
if (typeof res.resText !== "string") throw Error("Gateway response has no body");
|
|
1711
|
+
const commentUpdateBeforeSignature = parseCommentUpdateSchemaWithPKCErrorIfItFails(parseJsonWithPKCErrorIfFails(res.resText));
|
|
1712
|
+
await this._throwIfCommentUpdateHasInvalidSignature(commentUpdateBeforeSignature, subIpns);
|
|
1713
|
+
commentUpdate = commentUpdateBeforeSignature;
|
|
1714
|
+
};
|
|
1715
|
+
this._comment._setUpdatingStateWithEmissionIfNewState("fetching-update-ipfs");
|
|
1716
|
+
for (const timestampRange of timestampRanges) {
|
|
1717
|
+
const folderCid = subIpns.postUpdates[timestampRange];
|
|
1718
|
+
const path = this._calculatePathForPostCommentUpdate(folderCid, this._comment.postCid);
|
|
1719
|
+
try {
|
|
1720
|
+
await this.fetchFromMultipleGateways({
|
|
1721
|
+
recordIpfsType: "ipfs",
|
|
1722
|
+
root: folderCid,
|
|
1723
|
+
path: path.replace(`${folderCid}/`, ""),
|
|
1724
|
+
recordPKCType: "comment-update",
|
|
1725
|
+
validateGatewayResponseFunc: validateCommentFromGateway,
|
|
1726
|
+
log,
|
|
1727
|
+
maxFileSizeBytes: MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE,
|
|
1728
|
+
timeoutMs: this._pkc._timeouts["comment-update-ipfs"],
|
|
1729
|
+
abortSignal: this._comment._getStopAbortSignal()
|
|
1730
|
+
});
|
|
1731
|
+
if (!commentUpdate) throw Error("Failed to load comment update from gateways. This is a critical logic error");
|
|
1732
|
+
if (commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) return {
|
|
1733
|
+
commentUpdate,
|
|
1734
|
+
commentUpdateIpfsPath: path
|
|
1735
|
+
};
|
|
1736
|
+
else return void 0;
|
|
1737
|
+
} catch (e) {
|
|
1738
|
+
if (this._shouldWeFetchCommentUpdateFromNextTimestamp(e)) {
|
|
1739
|
+
attemptedPathsToLoadErrors[path] = e;
|
|
1740
|
+
log.trace(`Failed to fetch CommentUpdate from path (${path}) from gateways. Trying the next timestamp range`);
|
|
1741
|
+
continue;
|
|
1742
|
+
} else {
|
|
1743
|
+
this._comment._invalidCommentUpdateMfsPaths.add(path);
|
|
1744
|
+
throw e;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
throw new PKCError("ERR_FAILED_TO_FETCH_COMMENT_UPDATE_FROM_ALL_POST_UPDATES_RANGES", {
|
|
1749
|
+
timestampRanges,
|
|
1750
|
+
attemptedPathsToLoadErrors,
|
|
1751
|
+
commentCid: this._comment.cid,
|
|
1752
|
+
commentDepth: this._comment.depth
|
|
1753
|
+
});
|
|
1754
|
+
}
|
|
1755
|
+
_useLoadedCommentUpdateIfNewInfo(loadedCommentUpdate, community, log) {
|
|
1756
|
+
if ((this._comment.raw.commentUpdate?.updatedAt || 0) < loadedCommentUpdate.commentUpdate.updatedAt) {
|
|
1757
|
+
log(`${this._comment.depth === 0 ? "Post" : "Reply"} (${this._comment.cid}) received a new CommentUpdate`);
|
|
1758
|
+
this._comment._initCommentUpdate(loadedCommentUpdate.commentUpdate, community);
|
|
1759
|
+
if ("commentUpdateIpfsPath" in loadedCommentUpdate) this._comment._commentUpdateIpfsPath = loadedCommentUpdate.commentUpdateIpfsPath;
|
|
1760
|
+
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
1761
|
+
newUpdatingState: "succeeded",
|
|
1762
|
+
event: {
|
|
1763
|
+
name: "update",
|
|
1764
|
+
args: [this._comment]
|
|
1765
|
+
}
|
|
1766
|
+
});
|
|
1767
|
+
return true;
|
|
1768
|
+
} else return false;
|
|
1769
|
+
}
|
|
1770
|
+
async useCommunityPostUpdatesToFetchCommentUpdateForPost(subIpfs) {
|
|
1771
|
+
const log = logger_default("pkc-js:comment:useCommunityPostUpdatesToFetchCommentUpdate");
|
|
1772
|
+
if (!subIpfs.postUpdates) throw new PKCError("ERR_COMMUNITY_HAS_NO_POST_UPDATES", {
|
|
1773
|
+
subIpfs,
|
|
1774
|
+
postCid: this._comment.cid
|
|
1775
|
+
});
|
|
1776
|
+
if (!this._comment.postCid) throw Error("comment.postCid needs to be defined to fetch comment update");
|
|
1777
|
+
const postTimestamp = this._comment.timestamp;
|
|
1778
|
+
if (typeof postTimestamp !== "number") throw Error("Post timestamp is not defined by the time we're fetching from postUpdates");
|
|
1779
|
+
const timestampRanges = getPostUpdateTimestampRange(subIpfs.postUpdates, postTimestamp);
|
|
1780
|
+
if (timestampRanges.length === 0) throw Error("Post has no timestamp range bucket");
|
|
1781
|
+
let newCommentUpdate;
|
|
1782
|
+
try {
|
|
1783
|
+
if (Object.keys(this._pkc.clients.kuboRpcClients).length > 0 || Object.keys(this._pkc.clients.libp2pJsClients).length > 0) newCommentUpdate = await this._fetchPostCommentUpdateIpfsP2P(subIpfs, timestampRanges, log);
|
|
1784
|
+
else newCommentUpdate = await this._fetchPostCommentUpdateFromGateways(subIpfs, timestampRanges, log);
|
|
1785
|
+
} catch (e) {
|
|
1786
|
+
if (e instanceof Error) {
|
|
1787
|
+
if (isAbortError(e)) return;
|
|
1788
|
+
if (this._shouldWeFetchCommentUpdateFromNextTimestamp(e)) {
|
|
1789
|
+
log.trace(`Post`, this._comment.cid, "Failed to load CommentUpdate. Will retry later", e);
|
|
1790
|
+
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
1791
|
+
newUpdatingState: "waiting-retry",
|
|
1792
|
+
event: {
|
|
1793
|
+
name: "error",
|
|
1794
|
+
args: [e]
|
|
1795
|
+
}
|
|
1796
|
+
});
|
|
1797
|
+
} else {
|
|
1798
|
+
log.error("Received a non retriable error when attempting to load post commentUpdate. Will be emitting error", this._comment.cid, e);
|
|
1799
|
+
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
1800
|
+
newUpdatingState: "failed",
|
|
1801
|
+
event: {
|
|
1802
|
+
name: "error",
|
|
1803
|
+
args: [e]
|
|
1804
|
+
}
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
if (newCommentUpdate) this._useLoadedCommentUpdateIfNewInfo(newCommentUpdate, subIpfs, log);
|
|
1811
|
+
else if (newCommentUpdate === void 0) {
|
|
1812
|
+
log.trace(`Comment`, this._comment.cid, "loaded an old comment update. Ignoring it");
|
|
1813
|
+
this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
async _fetchRawCommentCidIpfsP2P(cid) {
|
|
1817
|
+
const kuboRpcOrHelia = this.getDefaultKuboRpcClientOrHelia();
|
|
1818
|
+
this._updateKuboRpcClientOrHeliaState("fetching-ipfs", kuboRpcOrHelia);
|
|
1819
|
+
let commentRawString;
|
|
1820
|
+
const commentTimeoutMs = this._pkc._timeouts["comment-ipfs"];
|
|
1821
|
+
try {
|
|
1822
|
+
commentRawString = await this._fetchCidP2P(cid, {
|
|
1823
|
+
maxFileSizeBytes: 1024 * 1024,
|
|
1824
|
+
timeoutMs: commentTimeoutMs,
|
|
1825
|
+
abortSignal: this._comment._getStopAbortSignal(),
|
|
1826
|
+
bitswapSessionSeedScopeIpnsPubsubTopic: this._bitswapSessionSeedScopeIpnsPubsubTopic()
|
|
1827
|
+
});
|
|
1828
|
+
} catch (e) {
|
|
1829
|
+
e.details = {
|
|
1830
|
+
...e.details,
|
|
1831
|
+
commentCid: cid,
|
|
1832
|
+
commentTimeoutMs
|
|
1833
|
+
};
|
|
1834
|
+
throw e;
|
|
1835
|
+
} finally {
|
|
1836
|
+
this._updateKuboRpcClientOrHeliaState("stopped", kuboRpcOrHelia);
|
|
1837
|
+
}
|
|
1838
|
+
return commentRawString;
|
|
1839
|
+
}
|
|
1840
|
+
async _fetchCommentIpfsFromGateways(parentCid) {
|
|
1841
|
+
const log = logger_default("pkc-js:comment:client-manager:_fetchCommentIpfsFromGateways");
|
|
1842
|
+
return (await this.fetchFromMultipleGateways({
|
|
1843
|
+
recordIpfsType: "ipfs",
|
|
1844
|
+
recordPKCType: "comment",
|
|
1845
|
+
root: parentCid,
|
|
1846
|
+
validateGatewayResponseFunc: async () => {},
|
|
1847
|
+
log,
|
|
1848
|
+
maxFileSizeBytes: 1024 * 1024,
|
|
1849
|
+
timeoutMs: this._pkc._timeouts["comment-ipfs"],
|
|
1850
|
+
abortSignal: this._comment._getStopAbortSignal()
|
|
1851
|
+
})).resText;
|
|
1852
|
+
}
|
|
1853
|
+
async _throwIfCommentIpfsIsInvalid(commentIpfs, commentCid) {
|
|
1854
|
+
const verificationOpts = {
|
|
1855
|
+
comment: commentIpfs,
|
|
1856
|
+
resolveAuthorNames: this._pkc.resolveAuthorNames,
|
|
1857
|
+
clientsManager: this,
|
|
1858
|
+
calculatedCommentCid: commentCid,
|
|
1859
|
+
communityPublicKeyFromInstance: this._comment.communityPublicKey,
|
|
1860
|
+
communityNameFromInstance: this._comment.communityName,
|
|
1861
|
+
abortSignal: this._comment._getStopAbortSignal()
|
|
1862
|
+
};
|
|
1863
|
+
const commentIpfsValidation = await verifyCommentIpfs(verificationOpts);
|
|
1864
|
+
if (!commentIpfsValidation.valid) throw new PKCError("ERR_COMMENT_IPFS_SIGNATURE_IS_INVALID", {
|
|
1865
|
+
commentIpfsValidation,
|
|
1866
|
+
verificationOpts
|
|
1867
|
+
});
|
|
1868
|
+
}
|
|
1869
|
+
async _fetchCommentIpfsFromPages() {
|
|
1870
|
+
if (!this._comment.communityAddress) throw Error("Comment communityAddress should be defined");
|
|
1871
|
+
if (!this._comment.cid) throw Error("Comment cid should be defined");
|
|
1872
|
+
const community = await this._pkc.createCommunity({
|
|
1873
|
+
name: this._comment.communityName,
|
|
1874
|
+
publicKey: this._comment.communityPublicKey
|
|
1875
|
+
});
|
|
1876
|
+
const abortController = new AbortController();
|
|
1877
|
+
const abortIfNeeded = async () => {
|
|
1878
|
+
if (!abortController.signal.aborted) abortController.abort();
|
|
1879
|
+
if (community.state === "updating") await community.stop();
|
|
1880
|
+
};
|
|
1881
|
+
const onCommentUpdate = async () => {
|
|
1882
|
+
if (this._comment.raw.comment) await abortIfNeeded();
|
|
1883
|
+
};
|
|
1884
|
+
const onStateChange = async (newState) => {
|
|
1885
|
+
if (newState === "stopped") await abortIfNeeded();
|
|
1886
|
+
};
|
|
1887
|
+
this._comment.on("update", onCommentUpdate);
|
|
1888
|
+
this._comment.on("statechange", onStateChange);
|
|
1889
|
+
if (this._comment.state === "stopped" || this._pkc.destroyed) return;
|
|
1890
|
+
try {
|
|
1891
|
+
if (abortController.signal.aborted) return;
|
|
1892
|
+
await community.update();
|
|
1893
|
+
await new Promise((resolve, reject) => {
|
|
1894
|
+
const abortError = () => {
|
|
1895
|
+
const error = /* @__PURE__ */ new Error("The operation was aborted");
|
|
1896
|
+
error.name = "AbortError";
|
|
1897
|
+
return error;
|
|
1898
|
+
};
|
|
1899
|
+
const cleanup = () => {
|
|
1900
|
+
community.removeListener("update", onUpdate);
|
|
1901
|
+
abortController.signal.removeEventListener("abort", onAbort);
|
|
1902
|
+
};
|
|
1903
|
+
const onAbort = () => {
|
|
1904
|
+
cleanup();
|
|
1905
|
+
reject(abortError());
|
|
1906
|
+
};
|
|
1907
|
+
const onUpdate = async () => {
|
|
1908
|
+
try {
|
|
1909
|
+
if (typeof community.updatedAt === "number") {
|
|
1910
|
+
cleanup();
|
|
1911
|
+
resolve();
|
|
1912
|
+
}
|
|
1913
|
+
} catch (error) {
|
|
1914
|
+
cleanup();
|
|
1915
|
+
reject(error);
|
|
1916
|
+
}
|
|
1917
|
+
};
|
|
1918
|
+
if (abortController.signal.aborted) {
|
|
1919
|
+
reject(abortError());
|
|
1920
|
+
return;
|
|
1921
|
+
}
|
|
1922
|
+
abortController.signal.addEventListener("abort", onAbort);
|
|
1923
|
+
community.on("update", onUpdate);
|
|
1924
|
+
onUpdate();
|
|
1925
|
+
});
|
|
1926
|
+
await community.stop();
|
|
1927
|
+
const commentAfterSearchingAllPages = await loadAllPagesUnderCommunityToFindComment({
|
|
1928
|
+
community,
|
|
1929
|
+
commentCidToFind: this._comment.cid,
|
|
1930
|
+
postCid: this._comment.postCid,
|
|
1931
|
+
parentCid: this._comment.parentCid,
|
|
1932
|
+
signal: abortController.signal
|
|
1933
|
+
});
|
|
1934
|
+
if (commentAfterSearchingAllPages) {
|
|
1935
|
+
if (!this._comment.raw.comment) {
|
|
1936
|
+
this._comment._initIpfsProps(commentAfterSearchingAllPages.comment);
|
|
1937
|
+
this._comment.emit("update", this._comment);
|
|
1938
|
+
}
|
|
1939
|
+
if ((this._comment.updatedAt || 0) < commentAfterSearchingAllPages.commentUpdate.updatedAt) this._comment._initCommentUpdate(commentAfterSearchingAllPages.commentUpdate, community.raw.communityIpfs);
|
|
1940
|
+
}
|
|
1941
|
+
} catch (err) {
|
|
1942
|
+
if (err?.name !== "AbortError") throw err;
|
|
1943
|
+
} finally {
|
|
1944
|
+
this._comment.removeListener("update", onCommentUpdate);
|
|
1945
|
+
this._comment.removeListener("statechange", onStateChange);
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
async fetchAndVerifyCommentCid(cid) {
|
|
1949
|
+
const cachedComment = this._pkc._memCaches.commentIpfs.get(cid);
|
|
1950
|
+
if (cachedComment) {
|
|
1951
|
+
fetchCommentLogger.trace("Serving comment CID from cache", cid);
|
|
1952
|
+
return t$4(cachedComment);
|
|
1953
|
+
}
|
|
1954
|
+
const verifiedComment = await this._pkc._inflightFetchManager.withResource(InflightResourceTypes.COMMENT_IPFS, cid, async () => {
|
|
1955
|
+
fetchCommentLogger.trace("Fetching comment CID", cid);
|
|
1956
|
+
let commentRawString;
|
|
1957
|
+
if (Object.keys(this._pkc.clients.kuboRpcClients).length > 0 || Object.keys(this._pkc.clients.libp2pJsClients).length > 0) commentRawString = await this._fetchRawCommentCidIpfsP2P(cid);
|
|
1958
|
+
else commentRawString = await this._fetchCommentIpfsFromGateways(cid);
|
|
1959
|
+
const commentIpfs = parseCommentIpfsSchemaWithPKCErrorIfItFails(parseJsonWithPKCErrorIfFails(commentRawString));
|
|
1960
|
+
await this._throwIfCommentIpfsIsInvalid(commentIpfs, cid);
|
|
1961
|
+
return commentIpfs;
|
|
1962
|
+
});
|
|
1963
|
+
this._pkc._memCaches.commentIpfs.set(cid, verifiedComment);
|
|
1964
|
+
return verifiedComment;
|
|
1965
|
+
}
|
|
1966
|
+
_isPublishing() {
|
|
1967
|
+
return this._comment.state === "publishing";
|
|
1968
|
+
}
|
|
1969
|
+
_findCommentInPagesOfUpdatingCommentsOrCommunity(opts) {
|
|
1970
|
+
if (typeof this._comment.cid !== "string") throw Error("Need to have defined cid");
|
|
1971
|
+
let updateFromCommunity;
|
|
1972
|
+
if (this._comment.communityPublicKey || this._comment.communityName) {
|
|
1973
|
+
const community = findStartedCommunity(this._pkc, {
|
|
1974
|
+
publicKey: this._comment.communityPublicKey,
|
|
1975
|
+
name: this._comment.communityName
|
|
1976
|
+
}) || findUpdatingCommunity(this._pkc, {
|
|
1977
|
+
publicKey: this._comment.communityPublicKey,
|
|
1978
|
+
name: this._comment.communityName
|
|
1979
|
+
}) || opts?.community;
|
|
1980
|
+
if (community) updateFromCommunity = findCommentInPageInstanceRecursively(community.posts, this._comment.cid);
|
|
1981
|
+
} else {
|
|
1982
|
+
for (const community of [...listStartedCommunities(this._pkc), ...listUpdatingCommunities(this._pkc)]) {
|
|
1983
|
+
updateFromCommunity = findCommentInPageInstanceRecursively(community.posts, this._comment.cid);
|
|
1984
|
+
if (updateFromCommunity) break;
|
|
1985
|
+
}
|
|
1986
|
+
if (!updateFromCommunity && opts?.community) updateFromCommunity = findCommentInPageInstanceRecursively(opts.community.posts, this._comment.cid);
|
|
1987
|
+
}
|
|
1988
|
+
const post = this._comment.postCid ? findUpdatingComment(this._pkc, { cid: this._comment.postCid }) : opts?.post;
|
|
1989
|
+
let updateFromPost;
|
|
1990
|
+
if (post) updateFromPost = findCommentInPageInstanceRecursively(post.replies, this._comment.cid);
|
|
1991
|
+
const parent = this._comment.parentCid ? opts?.parent || findUpdatingComment(this._pkc, { cid: this._comment.parentCid }) : void 0;
|
|
1992
|
+
let updateFromParent;
|
|
1993
|
+
if (parent) updateFromParent = parent.replies && findCommentInPageInstance(parent.replies, this._comment.cid);
|
|
1994
|
+
return [
|
|
1995
|
+
updateFromCommunity,
|
|
1996
|
+
updateFromPost,
|
|
1997
|
+
updateFromParent
|
|
1998
|
+
].filter((update) => !!update).sort((a, b) => b.commentUpdate.updatedAt - a.commentUpdate.updatedAt)[0];
|
|
1999
|
+
}
|
|
2000
|
+
async handleUpdateEventFromCommunity(community) {
|
|
2001
|
+
const log = logger_default("pkc-js:comment:update");
|
|
2002
|
+
if (!this._comment.cid) {
|
|
2003
|
+
log("comment.cid is not defined because comment is publishing, waiting until cid is defined");
|
|
2004
|
+
return;
|
|
2005
|
+
}
|
|
2006
|
+
if (this._comment.state === "stopped") {
|
|
2007
|
+
await this._comment.stop();
|
|
2008
|
+
return;
|
|
2009
|
+
}
|
|
2010
|
+
if (!community.raw.communityIpfs) {
|
|
2011
|
+
log("community.raw.communityIpfs is undefined (likely key migration in progress), skipping this update");
|
|
2012
|
+
return;
|
|
2013
|
+
}
|
|
2014
|
+
this._resetFreshHandlerAbortController();
|
|
2015
|
+
if (!this._pkc._pkcRpcClient) this._comment._resolveAuthorNamesInBackground();
|
|
2016
|
+
const postInUpdatingCommunity = this._findCommentInPagesOfUpdatingCommentsOrCommunity({ community });
|
|
2017
|
+
if (postInUpdatingCommunity && postInUpdatingCommunity.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) {
|
|
2018
|
+
const log = logger_default("pkc-js:comment:update:handleUpdateEventFromCommunity:find-comment-update-in-updating-community-or-comments-pages");
|
|
2019
|
+
this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: postInUpdatingCommunity.commentUpdate }, community.raw.communityIpfs, log);
|
|
2020
|
+
} else try {
|
|
2021
|
+
await this.useCommunityPostUpdatesToFetchCommentUpdateForPost(community.raw.communityIpfs);
|
|
2022
|
+
} catch (e) {
|
|
2023
|
+
if (isAbortError(e)) return;
|
|
2024
|
+
log.error("Failed to use community update to fetch new CommentUpdate", e);
|
|
2025
|
+
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
2026
|
+
newUpdatingState: "failed",
|
|
2027
|
+
event: {
|
|
2028
|
+
name: "error",
|
|
2029
|
+
args: [e]
|
|
2030
|
+
}
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
_chooseWhichPagesBasedOnParentAndReplyTimestamp(parentCommentTimestamp) {
|
|
2035
|
+
const replyTimestamp = this._comment.timestamp;
|
|
2036
|
+
const currentTime = Math.floor(Date.now() / 1e3);
|
|
2037
|
+
const replyTimelineSpan = currentTime - parentCommentTimestamp;
|
|
2038
|
+
return (currentTime - Math.max(replyTimestamp, parentCommentTimestamp)) / replyTimelineSpan < .5 ? "new" : "old";
|
|
2039
|
+
}
|
|
2040
|
+
async usePageCidsOfParentToFetchCommentUpdateForReply(postCommentInstance, communityWithSignature) {
|
|
2041
|
+
const log = logger_default("pkc-js:comment:update:usePageCidsOfParentToFetchCommentUpdateForReply");
|
|
2042
|
+
if (!this._comment.cid) throw Error("comment.cid needs to be defined to fetch comment update of reply");
|
|
2043
|
+
if (!this._comment.parentCid) throw Error("comment.parentCid needs to be defined to fetch comment update of reply");
|
|
2044
|
+
const parentCommentInstance = postCommentInstance.cid === this._comment.parentCid ? postCommentInstance : await this._pkc.createComment({ cid: this._comment.parentCid });
|
|
2045
|
+
let startedUpdatingParentComment = false;
|
|
2046
|
+
if (parentCommentInstance.state === "stopped") {
|
|
2047
|
+
await parentCommentInstance.update();
|
|
2048
|
+
startedUpdatingParentComment = true;
|
|
2049
|
+
}
|
|
2050
|
+
await resolveWhenPredicateIsTrue({
|
|
2051
|
+
toUpdate: parentCommentInstance,
|
|
2052
|
+
predicate: () => typeof parentCommentInstance.updatedAt === "number"
|
|
2053
|
+
});
|
|
2054
|
+
if (startedUpdatingParentComment) await parentCommentInstance.stop();
|
|
2055
|
+
if (parentCommentInstance.updatedAt < this._comment.timestamp) return;
|
|
2056
|
+
const replyInPreloadedParentPages = parentCommentInstance.replies && findCommentInPageInstance(parentCommentInstance.replies, this._comment.cid);
|
|
2057
|
+
if (replyInPreloadedParentPages && replyInPreloadedParentPages.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) {
|
|
2058
|
+
this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: replyInPreloadedParentPages.commentUpdate }, communityWithSignature, log);
|
|
2059
|
+
return;
|
|
2060
|
+
}
|
|
2061
|
+
if (Object.keys(parentCommentInstance.replies.pageCids).length === 0) {
|
|
2062
|
+
if (replyInPreloadedParentPages) {
|
|
2063
|
+
log("Parent comment", this._comment.parentCid, "has no pageCids but reply", this._comment.cid, "found in preloaded pages - using it");
|
|
2064
|
+
this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: replyInPreloadedParentPages.commentUpdate }, communityWithSignature, log);
|
|
2065
|
+
return;
|
|
2066
|
+
}
|
|
2067
|
+
log("Parent comment", this._comment.parentCid, "of reply", this._comment.cid, "does not have any pageCids and reply not in preloaded pages, will wait until another update event by post");
|
|
2068
|
+
this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
|
|
2069
|
+
return;
|
|
2070
|
+
}
|
|
2071
|
+
const pageSortName = this._chooseWhichPagesBasedOnParentAndReplyTimestamp(parentCommentInstance.timestamp);
|
|
2072
|
+
let curPageCid = parentCommentInstance.replies.pageCids[pageSortName];
|
|
2073
|
+
if (!curPageCid) throw Error("Parent comment does not have any new or old pages");
|
|
2074
|
+
if (this._parentFirstPageCidsAlreadyLoaded.has(curPageCid)) {
|
|
2075
|
+
log(`Reply`, this._comment.cid, `:SKIPPING: Page CID ${curPageCid} already loaded parent page cid`);
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2078
|
+
this._comment._setUpdatingStateWithEmissionIfNewState("fetching-update-ipfs");
|
|
2079
|
+
let newCommentUpdate;
|
|
2080
|
+
const pageCidsSearchedForNewUpdate = [];
|
|
2081
|
+
let replyFoundWithoutNewerUpdate = false;
|
|
2082
|
+
while (curPageCid && !newCommentUpdate) {
|
|
2083
|
+
let pageLoaded;
|
|
2084
|
+
try {
|
|
2085
|
+
pageLoaded = await parentCommentInstance.replies.getPage({ cid: curPageCid });
|
|
2086
|
+
} catch (e) {
|
|
2087
|
+
if (isAbortError(e)) throw e;
|
|
2088
|
+
pageCidsSearchedForNewUpdate.push({
|
|
2089
|
+
pageCid: curPageCid,
|
|
2090
|
+
error: e
|
|
2091
|
+
});
|
|
2092
|
+
break;
|
|
2093
|
+
}
|
|
2094
|
+
if (pageCidsSearchedForNewUpdate.length === 0) this._parentFirstPageCidsAlreadyLoaded.add(curPageCid);
|
|
2095
|
+
const replyWithinParentPage = findCommentInParsedPages(pageLoaded, this._comment.cid)?.raw;
|
|
2096
|
+
const replyWithinUpdatingPages = this._findCommentInPagesOfUpdatingCommentsOrCommunity({ parent: parentCommentInstance });
|
|
2097
|
+
pageCidsSearchedForNewUpdate.push({
|
|
2098
|
+
pageCid: curPageCid,
|
|
2099
|
+
replyWithinParentPage: Boolean(replyWithinParentPage),
|
|
2100
|
+
replyWithinUpdatingPages: Boolean(replyWithinUpdatingPages)
|
|
2101
|
+
});
|
|
2102
|
+
if (replyWithinParentPage) {
|
|
2103
|
+
if (replyWithinParentPage.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) newCommentUpdate = replyWithinParentPage;
|
|
2104
|
+
else replyFoundWithoutNewerUpdate = true;
|
|
2105
|
+
break;
|
|
2106
|
+
} else if (replyWithinUpdatingPages) if (replyWithinUpdatingPages.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) newCommentUpdate = replyWithinUpdatingPages;
|
|
2107
|
+
else replyFoundWithoutNewerUpdate = true;
|
|
2108
|
+
if (pageSortName === "new" && pageLoaded.comments.find((comment) => comment.timestamp < this._comment.timestamp)) {
|
|
2109
|
+
log("Reply", this._comment.cid, "we found a comment in the page that is older than our reply, stopping search for new comment update");
|
|
2110
|
+
break;
|
|
2111
|
+
} else if (pageSortName === "old" && pageLoaded.comments.find((comment) => comment.timestamp > this._comment.timestamp)) {
|
|
2112
|
+
log("Reply", this._comment.cid, "we found a comment in the page that is newer than our reply, stopping search for old comment update");
|
|
2113
|
+
break;
|
|
2114
|
+
}
|
|
2115
|
+
curPageCid = pageLoaded.nextCid;
|
|
2116
|
+
}
|
|
2117
|
+
log("Searched for new comment update of comment", this._comment.cid, "in the following pageCids of page sort", pageSortName, "of parent comment:", parentCommentInstance.cid, pageCidsSearchedForNewUpdate, "and found", newCommentUpdate ? "a new comment update" : "no new comment update");
|
|
2118
|
+
if (newCommentUpdate) this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: newCommentUpdate.commentUpdate }, communityWithSignature, log);
|
|
2119
|
+
else if (!replyFoundWithoutNewerUpdate) throw new PKCError("ERR_FAILED_TO_FIND_REPLY_COMMENT_UPDATE_WITHIN_PARENT_COMMENT_PAGE_CIDS", {
|
|
2120
|
+
replyCid: this._comment.cid,
|
|
2121
|
+
parentCommentCid: parentCommentInstance.cid,
|
|
2122
|
+
pageSortName,
|
|
2123
|
+
pageCidsSearchedForNewUpdate
|
|
2124
|
+
});
|
|
2125
|
+
}
|
|
2126
|
+
async handleErrorEventFromCommunity(error) {
|
|
2127
|
+
if (this._comment.state === "publishing") return super.handleErrorEventFromCommunity(error);
|
|
2128
|
+
else if (this._communityForUpdating?.community?.updatingState === "failed") {
|
|
2129
|
+
logger_default("pkc-js:comment:update").error(this._comment.depth === 0 ? "Post" : "Reply", this._comment.cid, "received a non retriable error from its community instance. Will stop comment updating", error);
|
|
2130
|
+
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
2131
|
+
newUpdatingState: "failed",
|
|
2132
|
+
event: {
|
|
2133
|
+
name: "error",
|
|
2134
|
+
args: [error]
|
|
2135
|
+
}
|
|
2136
|
+
});
|
|
2137
|
+
await this._comment.stop();
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
handleIpfsGatewayCommunityState(communityNewGatewayState, gatewayUrl) {
|
|
2141
|
+
if (this._comment.state === "publishing") return super.handleIpfsGatewayCommunityState(communityNewGatewayState, gatewayUrl);
|
|
2142
|
+
else if (communityNewGatewayState === "fetching-ipns") this.updateGatewayState("fetching-community-ipns", gatewayUrl);
|
|
2143
|
+
}
|
|
2144
|
+
_translateCommunityUpdatingStateToCommentUpdatingState(newCommunityUpdatingState) {
|
|
2145
|
+
const translatedCommentUpdatingState = {
|
|
2146
|
+
failed: "failed",
|
|
2147
|
+
"fetching-ipfs": "fetching-community-ipfs",
|
|
2148
|
+
"fetching-ipns": "fetching-community-ipns",
|
|
2149
|
+
"resolving-name": "resolving-community-name",
|
|
2150
|
+
"waiting-retry": "waiting-retry",
|
|
2151
|
+
stopped: "stopped",
|
|
2152
|
+
succeeded: void 0,
|
|
2153
|
+
"publishing-ipns": void 0
|
|
2154
|
+
}[newCommunityUpdatingState];
|
|
2155
|
+
if (translatedCommentUpdatingState) this._comment._setUpdatingStateWithEmissionIfNewState(translatedCommentUpdatingState);
|
|
2156
|
+
}
|
|
2157
|
+
handleUpdatingStateChangeEventFromCommunity(newCommunityUpdatingState) {
|
|
2158
|
+
if (this._comment.state === "publishing") return super.handleUpdatingStateChangeEventFromCommunity(newCommunityUpdatingState);
|
|
2159
|
+
if (this._comment.updatingState === "fetching-update-ipfs") return;
|
|
2160
|
+
this._translateCommunityUpdatingStateToCommentUpdatingState(newCommunityUpdatingState);
|
|
2161
|
+
}
|
|
2162
|
+
handleErrorEventFromPost(error) {
|
|
2163
|
+
this._comment.emit("error", error);
|
|
2164
|
+
}
|
|
2165
|
+
handleUpdatingStateChangeEventFromPost(newState) {
|
|
2166
|
+
const replyState = {
|
|
2167
|
+
failed: "failed",
|
|
2168
|
+
"fetching-community-ipfs": "fetching-community-ipfs",
|
|
2169
|
+
"fetching-community-ipns": "fetching-community-ipns",
|
|
2170
|
+
"resolving-community-name": "resolving-community-name",
|
|
2171
|
+
"waiting-retry": "waiting-retry",
|
|
2172
|
+
stopped: void 0,
|
|
2173
|
+
succeeded: void 0,
|
|
2174
|
+
"fetching-ipfs": void 0,
|
|
2175
|
+
"resolving-author-name": void 0,
|
|
2176
|
+
"fetching-update-ipfs": void 0
|
|
2177
|
+
}[newState];
|
|
2178
|
+
if (replyState) if (this._fetchingUpdateForReplyUsingPageCidsPromise) this._fetchingUpdateForReplyUsingPageCidsPromise.then(() => this._comment._setUpdatingStateWithEmissionIfNewState(replyState));
|
|
2179
|
+
else this._comment._setUpdatingStateWithEmissionIfNewState(replyState);
|
|
2180
|
+
}
|
|
2181
|
+
_handleIpfsGatewayPostState(newState, gatewayUrl) {
|
|
2182
|
+
this.updateGatewayState(newState, gatewayUrl);
|
|
2183
|
+
}
|
|
2184
|
+
_handleKuboRpcPostState(newState, kuboRpcUrl) {
|
|
2185
|
+
this.updateKuboRpcState(newState, kuboRpcUrl);
|
|
2186
|
+
}
|
|
2187
|
+
_handleLibp2pJsClientPostState(newState, libp2pJsClientKey) {
|
|
2188
|
+
this.updateLibp2pJsClientState(newState, libp2pJsClientKey);
|
|
2189
|
+
}
|
|
2190
|
+
_handleNameResolverPostState(newState, resolverKey) {
|
|
2191
|
+
if (newState === "resolving-author-name") return;
|
|
2192
|
+
this.updateNameResolverState(newState, resolverKey);
|
|
2193
|
+
}
|
|
2194
|
+
async handleUpdateEventFromPostToFetchReplyCommentUpdate(postInstance) {
|
|
2195
|
+
if (!this._comment.cid) throw Error("comment.cid should be defined");
|
|
2196
|
+
const log = logger_default("pkc-js:comment:update:handleUpdateEventFromPost");
|
|
2197
|
+
log("Received update event from post", postInstance.cid, "for reply", this._comment.cid, "with depth", this._comment.depth);
|
|
2198
|
+
this._resetFreshHandlerAbortController();
|
|
2199
|
+
if (!this._pkc._pkcRpcClient) this._comment._resolveAuthorNamesInBackground();
|
|
2200
|
+
if (Object.keys(postInstance.replies.pageCids).length === 0 && Object.keys(postInstance.replies.pages).length === 0) {
|
|
2201
|
+
log("Post", postInstance.cid, "has no replies, therefore reply", this._comment.cid, "will wait until another update event by post");
|
|
2202
|
+
this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
|
|
2203
|
+
return;
|
|
2204
|
+
}
|
|
2205
|
+
const replyInPage = this._findCommentInPagesOfUpdatingCommentsOrCommunity({ post: postInstance });
|
|
2206
|
+
const updatingCommunity = findUpdatingCommunity(this._pkc, {
|
|
2207
|
+
publicKey: postInstance.communityPublicKey,
|
|
2208
|
+
name: postInstance.communityName
|
|
2209
|
+
});
|
|
2210
|
+
const startedCommunity = findStartedCommunity(this._pkc, {
|
|
2211
|
+
publicKey: postInstance.communityPublicKey,
|
|
2212
|
+
name: postInstance.communityName
|
|
2213
|
+
});
|
|
2214
|
+
const repliesCommunity = updatingCommunity?.raw?.communityIpfs || startedCommunity?.raw?.communityIpfs || postInstance.replies._community;
|
|
2215
|
+
if (!repliesCommunity.signature) throw Error("repliesCommunity.signature needs to be defined to fetch comment update of reply");
|
|
2216
|
+
if (replyInPage && !this._comment.raw.comment) {
|
|
2217
|
+
this._comment._initIpfsProps(replyInPage.comment);
|
|
2218
|
+
this._comment.emit("update", this._comment);
|
|
2219
|
+
}
|
|
2220
|
+
if (replyInPage && replyInPage.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) {
|
|
2221
|
+
const log = logger_default("pkc-js:comment:update:handleUpdateEventFromPostToFetchReplyCommentUpdate:find-comment-update-in-updating-community-or-comments-pages");
|
|
2222
|
+
this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: replyInPage.commentUpdate }, repliesCommunity, log);
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
2225
|
+
if (this._fetchingUpdateForReplyUsingPageCidsPromise) await this._fetchingUpdateForReplyUsingPageCidsPromise;
|
|
2226
|
+
this._fetchingUpdateForReplyUsingPageCidsPromise = this.usePageCidsOfParentToFetchCommentUpdateForReply(postInstance, repliesCommunity).catch((error) => {
|
|
2227
|
+
if (isAbortError(error)) return;
|
|
2228
|
+
log.error("Failed to fetch reply commentUpdate update from parent pages", error);
|
|
2229
|
+
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
2230
|
+
newUpdatingState: "failed",
|
|
2231
|
+
event: {
|
|
2232
|
+
name: "error",
|
|
2233
|
+
args: [error]
|
|
2234
|
+
}
|
|
2235
|
+
});
|
|
2236
|
+
}).finally(() => {
|
|
2237
|
+
this._fetchingUpdateForReplyUsingPageCidsPromise = void 0;
|
|
2238
|
+
});
|
|
2239
|
+
await this._fetchingUpdateForReplyUsingPageCidsPromise;
|
|
2240
|
+
this._fetchingUpdateForReplyUsingPageCidsPromise = void 0;
|
|
2241
|
+
}
|
|
2242
|
+
async _createPostInstanceWithStateTranslation() {
|
|
2243
|
+
if (!this._comment.postCid) throw Error("comment.postCid needs to be defined to fetch comment update of reply");
|
|
2244
|
+
const post = findUpdatingComment(this._pkc, { cid: this._comment.postCid }) || await this._pkc.createComment({ cid: this._comment.postCid });
|
|
2245
|
+
this._postForUpdating = {
|
|
2246
|
+
comment: post,
|
|
2247
|
+
error: this.handleErrorEventFromPost.bind(this),
|
|
2248
|
+
update: this.handleUpdateEventFromPostToFetchReplyCommentUpdate.bind(this),
|
|
2249
|
+
updatingstatechange: this.handleUpdatingStateChangeEventFromPost.bind(this)
|
|
2250
|
+
};
|
|
2251
|
+
if (this._postForUpdating.comment.clients.ipfsGateways && Object.keys(this._postForUpdating.comment.clients.ipfsGateways).length > 0) {
|
|
2252
|
+
const ipfsGatewayListeners = {};
|
|
2253
|
+
for (const gatewayUrl of Object.keys(this._postForUpdating.comment.clients.ipfsGateways)) {
|
|
2254
|
+
const ipfsStateListener = (postNewIpfsState) => this._handleIpfsGatewayPostState(postNewIpfsState, gatewayUrl);
|
|
2255
|
+
this._postForUpdating.comment.clients.ipfsGateways[gatewayUrl].on("statechange", ipfsStateListener);
|
|
2256
|
+
ipfsGatewayListeners[gatewayUrl] = ipfsStateListener;
|
|
2257
|
+
}
|
|
2258
|
+
this._postForUpdating.ipfsGatewayListeners = ipfsGatewayListeners;
|
|
2259
|
+
}
|
|
2260
|
+
if (this._postForUpdating.comment.clients.kuboRpcClients && Object.keys(this._postForUpdating.comment.clients.kuboRpcClients).length > 0) {
|
|
2261
|
+
const kuboRpcListeners = {};
|
|
2262
|
+
for (const kuboRpcUrl of Object.keys(this._postForUpdating.comment.clients.kuboRpcClients)) {
|
|
2263
|
+
const kuboRpcStateListener = (postNewKuboRpcState) => this._handleKuboRpcPostState(postNewKuboRpcState, kuboRpcUrl);
|
|
2264
|
+
this._postForUpdating.comment.clients.kuboRpcClients[kuboRpcUrl].on("statechange", kuboRpcStateListener);
|
|
2265
|
+
kuboRpcListeners[kuboRpcUrl] = kuboRpcStateListener;
|
|
2266
|
+
}
|
|
2267
|
+
this._postForUpdating.kuboRpcListeners = kuboRpcListeners;
|
|
2268
|
+
}
|
|
2269
|
+
if (this._postForUpdating.comment.clients.libp2pJsClients && Object.keys(this._postForUpdating.comment.clients.libp2pJsClients).length > 0) {
|
|
2270
|
+
const libp2pJsClientListeners = {};
|
|
2271
|
+
for (const libp2pJsClientKey of Object.keys(this._postForUpdating.comment.clients.libp2pJsClients)) {
|
|
2272
|
+
const libp2pJsStateListener = (postNewLibp2pJsState) => this._handleLibp2pJsClientPostState(postNewLibp2pJsState, libp2pJsClientKey);
|
|
2273
|
+
this._postForUpdating.comment.clients.libp2pJsClients[libp2pJsClientKey].on("statechange", libp2pJsStateListener);
|
|
2274
|
+
libp2pJsClientListeners[libp2pJsClientKey] = libp2pJsStateListener;
|
|
2275
|
+
}
|
|
2276
|
+
this._postForUpdating.libp2pJsClientListeners = libp2pJsClientListeners;
|
|
2277
|
+
}
|
|
2278
|
+
if (this._postForUpdating.comment.clients.nameResolvers && Object.keys(this._postForUpdating.comment.clients.nameResolvers).length > 0) {
|
|
2279
|
+
const nameResolverListeners = {};
|
|
2280
|
+
for (const resolverKey of Object.keys(this._postForUpdating.comment.clients.nameResolvers)) {
|
|
2281
|
+
const resolverStateListener = (postNewResolverState) => this._handleNameResolverPostState(postNewResolverState, resolverKey);
|
|
2282
|
+
this._postForUpdating.comment.clients.nameResolvers[resolverKey].on("statechange", resolverStateListener);
|
|
2283
|
+
nameResolverListeners[resolverKey] = resolverStateListener;
|
|
2284
|
+
}
|
|
2285
|
+
this._postForUpdating.nameResolverListeners = nameResolverListeners;
|
|
2286
|
+
}
|
|
2287
|
+
this._postForUpdating.comment.on("update", this._postForUpdating.update);
|
|
2288
|
+
this._postForUpdating.comment.on("updatingstatechange", this._postForUpdating.updatingstatechange);
|
|
2289
|
+
this._postForUpdating.comment.on("error", this._postForUpdating.error);
|
|
2290
|
+
this._postForUpdating.comment._numOfListenersForUpdatingInstance++;
|
|
2291
|
+
return this._postForUpdating;
|
|
2292
|
+
}
|
|
2293
|
+
async cleanUpUpdatingPostInstance() {
|
|
2294
|
+
if (!this._postForUpdating) return;
|
|
2295
|
+
if (this._postForUpdating.ipfsGatewayListeners) for (const gatewayUrl of Object.keys(this._postForUpdating.ipfsGatewayListeners)) {
|
|
2296
|
+
this._postForUpdating.comment.clients.ipfsGateways[gatewayUrl].removeListener("statechange", this._postForUpdating.ipfsGatewayListeners[gatewayUrl]);
|
|
2297
|
+
this.updateGatewayState("stopped", gatewayUrl);
|
|
2298
|
+
}
|
|
2299
|
+
if (this._postForUpdating.kuboRpcListeners) for (const kuboRpcUrl of Object.keys(this._postForUpdating.kuboRpcListeners)) {
|
|
2300
|
+
this._postForUpdating.comment.clients.kuboRpcClients[kuboRpcUrl].removeListener("statechange", this._postForUpdating.kuboRpcListeners[kuboRpcUrl]);
|
|
2301
|
+
this.updateKuboRpcState("stopped", kuboRpcUrl);
|
|
2302
|
+
}
|
|
2303
|
+
if (this._postForUpdating.libp2pJsClientListeners) for (const libp2pJsClientKey of Object.keys(this._postForUpdating.libp2pJsClientListeners)) {
|
|
2304
|
+
this._postForUpdating.comment.clients.libp2pJsClients[libp2pJsClientKey].removeListener("statechange", this._postForUpdating.libp2pJsClientListeners[libp2pJsClientKey]);
|
|
2305
|
+
this.updateLibp2pJsClientState("stopped", libp2pJsClientKey);
|
|
2306
|
+
}
|
|
2307
|
+
if (this._postForUpdating.nameResolverListeners) for (const resolverKey of Object.keys(this._postForUpdating.nameResolverListeners)) {
|
|
2308
|
+
this._postForUpdating.comment.clients.nameResolvers[resolverKey].removeListener("statechange", this._postForUpdating.nameResolverListeners[resolverKey]);
|
|
2309
|
+
this.updateNameResolverState("stopped", resolverKey);
|
|
2310
|
+
}
|
|
2311
|
+
this._postForUpdating.comment.removeListener("updatingstatechange", this._postForUpdating.updatingstatechange);
|
|
2312
|
+
this._postForUpdating.comment.removeListener("error", this._postForUpdating.error);
|
|
2313
|
+
this._postForUpdating.comment.removeListener("update", this._postForUpdating.update);
|
|
2314
|
+
const postForUpdating = this._postForUpdating.comment;
|
|
2315
|
+
postForUpdating._numOfListenersForUpdatingInstance--;
|
|
2316
|
+
if (postForUpdating._updatingCommentInstance) await postForUpdating.stop();
|
|
2317
|
+
else if (postForUpdating._numOfListenersForUpdatingInstance === 0 && postForUpdating.state !== "stopped") await postForUpdating.stop();
|
|
2318
|
+
else if (postForUpdating._numOfListenersForUpdatingInstance === 0 && postForUpdating.state === "stopped" && postForUpdating.cid && findUpdatingComment(this._pkc, { cid: postForUpdating.cid }) === postForUpdating) untrackUpdatingComment(this._pkc, postForUpdating);
|
|
2319
|
+
this._parentFirstPageCidsAlreadyLoaded.clear();
|
|
2320
|
+
this._postForUpdating = void 0;
|
|
2321
|
+
}
|
|
2322
|
+
};
|
|
2323
|
+
//#endregion
|
|
1143
2324
|
//#region dist/node/publications/comment/comment.js
|
|
1144
2325
|
var import_sha256 = require_sha256();
|
|
1145
2326
|
var Comment = class extends Publication {
|
|
@@ -1227,7 +2408,7 @@ var Comment = class extends Publication {
|
|
|
1227
2408
|
this._initProps(props);
|
|
1228
2409
|
const unknownProps = r(t$1(props), t$1(CommentIpfsSchema.shape));
|
|
1229
2410
|
if (unknownProps.length > 0) {
|
|
1230
|
-
const unknownPropsWithValues = t$
|
|
2411
|
+
const unknownPropsWithValues = t$5(props, unknownProps);
|
|
1231
2412
|
log(`Found unknown props on loaded CommentIpfs (cid: ${this.cid})`, unknownPropsWithValues, "Full props:", props, "Will set them on the Comment instance");
|
|
1232
2413
|
Object.assign(this, unknownPropsWithValues);
|
|
1233
2414
|
}
|
|
@@ -1323,7 +2504,7 @@ var Comment = class extends Publication {
|
|
|
1323
2504
|
const unknownProps = r(t$1(props), t$1(CommentUpdateSchema.shape));
|
|
1324
2505
|
if (unknownProps.length > 0) {
|
|
1325
2506
|
log("Found unknown props on CommentUpdate record", unknownProps, "Will set them on Comment instance");
|
|
1326
|
-
Object.assign(this, t$
|
|
2507
|
+
Object.assign(this, t$5(props, unknownProps));
|
|
1327
2508
|
}
|
|
1328
2509
|
}
|
|
1329
2510
|
this.upvoteCount = props.upvoteCount;
|
|
@@ -1393,8 +2574,8 @@ var Comment = class extends Publication {
|
|
|
1393
2574
|
const log = logger_default("pkc-js:comment:publish:_verifyChallengeVerificationCommentProps");
|
|
1394
2575
|
if (!this.raw.pubsubMessageToPublish) throw Error("comment._pubsubMsgToPublish should be defined at this point");
|
|
1395
2576
|
const keysToCompare = t$1(n$1(this.raw.pubsubMessageToPublish, ["signature", "author"]));
|
|
1396
|
-
const pubsubMsgFromCommentIpfs = t$
|
|
1397
|
-
if (!t$3(pubsubMsgFromCommentIpfs, t$
|
|
2577
|
+
const pubsubMsgFromCommentIpfs = t$5(decryptedVerification.comment, keysToCompare);
|
|
2578
|
+
if (!t$3(pubsubMsgFromCommentIpfs, t$5(this.raw.pubsubMessageToPublish, keysToCompare))) {
|
|
1398
2579
|
const error = new PKCError("ERR_COMMUNITY_CHANGED_COMMENT_PUBSUB_PUBLICATION_PROPS", {
|
|
1399
2580
|
pubsubMsgFromSub: pubsubMsgFromCommentIpfs,
|
|
1400
2581
|
originalPubsubMsg: this.raw.pubsubMessageToPublish
|
|
@@ -1499,7 +2680,7 @@ var Comment = class extends Publication {
|
|
|
1499
2680
|
const unknownProps = r(t$1(decryptedVerification.commentUpdate), t$1(CommentUpdateForChallengeVerificationSchema.shape));
|
|
1500
2681
|
if (unknownProps.length > 0) {
|
|
1501
2682
|
log("Found unknown props on decryptedVerification.commentUpdate record", unknownProps, "Will set them on Comment instance");
|
|
1502
|
-
Object.assign(this, t$
|
|
2683
|
+
Object.assign(this, t$5(decryptedVerification.commentUpdate, unknownProps));
|
|
1503
2684
|
}
|
|
1504
2685
|
this.emit("update", this);
|
|
1505
2686
|
if (!this._pkc._pkcRpcClient) this._resolveAuthorNamesInBackground();
|
|
@@ -1771,7 +2952,6 @@ var Comment = class extends Publication {
|
|
|
1771
2952
|
const log = logger_default("pkc-js:comment:update:_handleErrorEventFromRpc");
|
|
1772
2953
|
const err = args.params.result;
|
|
1773
2954
|
log("Received 'error' event from RPC", err);
|
|
1774
|
-
if (err.details?.newUpdatingState) this._setUpdatingStateNoEmission(err.details.newUpdatingState);
|
|
1775
2955
|
if (!this._isRetriableLoadingError(err)) {
|
|
1776
2956
|
log.error("The RPC transmitted a non retriable error", "for comment", this.cid, "will clean up the subscription", err);
|
|
1777
2957
|
this._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
@@ -1783,7 +2963,13 @@ var Comment = class extends Publication {
|
|
|
1783
2963
|
}
|
|
1784
2964
|
});
|
|
1785
2965
|
await this._stopUpdateLoop();
|
|
1786
|
-
} else this.
|
|
2966
|
+
} else this._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
2967
|
+
newUpdatingState: err.details?.newUpdatingState,
|
|
2968
|
+
event: {
|
|
2969
|
+
name: "error",
|
|
2970
|
+
args: [err]
|
|
2971
|
+
}
|
|
2972
|
+
});
|
|
1787
2973
|
}
|
|
1788
2974
|
async _updateViaRpc() {
|
|
1789
2975
|
const log = logger_default("pkc-js:comment:update:_updateViaRpc");
|
|
@@ -6989,7 +8175,10 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
6989
8175
|
this.validatePages = this.parsedPKCOptions.validatePages;
|
|
6990
8176
|
this.userAgent = this.parsedPKCOptions.userAgent;
|
|
6991
8177
|
this.httpRoutersOptions = this.parsedPKCOptions.httpRoutersOptions;
|
|
6992
|
-
this.settings = {
|
|
8178
|
+
this.settings = {
|
|
8179
|
+
challenges: this.parsedPKCOptions.challenges,
|
|
8180
|
+
pageSorts: this.parsedPKCOptions.pageSorts
|
|
8181
|
+
};
|
|
6993
8182
|
this.nameResolvers = this.pkcRpcClientsOptions ? void 0 : this.parsedPKCOptions.nameResolvers;
|
|
6994
8183
|
this.on("communitieschange", (newCommunities) => {
|
|
6995
8184
|
this.communities = newCommunities;
|
|
@@ -7065,7 +8254,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
7065
8254
|
this.clients.libp2pJsClients = {};
|
|
7066
8255
|
if (!this.libp2pJsClientsOptions) return;
|
|
7067
8256
|
if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
|
|
7068
|
-
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-
|
|
8257
|
+
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-BY1wF9W8.js");
|
|
7069
8258
|
for (const clientOptions of this.libp2pJsClientsOptions) {
|
|
7070
8259
|
const heliaNode = await createLibp2pJsClientOrUseExistingOne({
|
|
7071
8260
|
...clientOptions,
|
|
@@ -7186,7 +8375,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
7186
8375
|
}
|
|
7187
8376
|
}
|
|
7188
8377
|
async _initMissingFieldsOfPublicationBeforeSigning(pubOptions, log) {
|
|
7189
|
-
const finalOptions = t$
|
|
8378
|
+
const finalOptions = t$4(pubOptions);
|
|
7190
8379
|
if (!finalOptions.signer) throw Error("User did not provide a signer to create a local publication");
|
|
7191
8380
|
let cleanedAuthor = cleanWireAuthor(normalizeCreatePublicationAuthor(finalOptions.author));
|
|
7192
8381
|
if (cleanedAuthor) {
|
|
@@ -7307,7 +8496,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
7307
8496
|
}
|
|
7308
8497
|
if (!community.raw.communityIpfs) {
|
|
7309
8498
|
if (options.signature) {
|
|
7310
|
-
const resParseCommunityIpfs = CommunityIpfsSchema.loose().safeParse(t$
|
|
8499
|
+
const resParseCommunityIpfs = CommunityIpfsSchema.loose().safeParse(t$5(options, [...options.signature.signedPropertyNames, "signature"]));
|
|
7311
8500
|
if (resParseCommunityIpfs.success) {
|
|
7312
8501
|
const cleanedRecord = removeUndefinedValuesRecursively(resParseCommunityIpfs.data);
|
|
7313
8502
|
await community.initCommunityIpfsPropsNoMerge(cleanedRecord);
|
|
@@ -7344,7 +8533,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
7344
8533
|
const log = logger_default("pkc-js:pkc:createLocalCommunity");
|
|
7345
8534
|
log.trace("Received community options to create a local community instance:", options);
|
|
7346
8535
|
if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
|
|
7347
|
-
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-
|
|
8536
|
+
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-B6i3MUzw.js");
|
|
7348
8537
|
const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
|
|
7349
8538
|
const community = new LocalCommunity(this);
|
|
7350
8539
|
if (isLocalCommunity) {
|
|
@@ -7917,12 +9106,14 @@ PKC.nativeFunctions = {
|
|
|
7917
9106
|
PKC.getShortCid = getShortCidValue;
|
|
7918
9107
|
PKC.getShortAddress = getShortAddressValue;
|
|
7919
9108
|
PKC.challenges = pkcJsChallenges;
|
|
9109
|
+
PKC.pageSorts = pkcJsPageSorts;
|
|
7920
9110
|
PKC.createAnchorIpnsRecord = createAnchorIpnsRecord$1;
|
|
7921
9111
|
const setNativeFunctions = PKC.setNativeFunctions;
|
|
7922
9112
|
const nativeFunctions = PKC.nativeFunctions;
|
|
7923
9113
|
const getShortCid = PKC.getShortCid;
|
|
7924
9114
|
const getShortAddress = PKC.getShortAddress;
|
|
7925
9115
|
const challenges = PKC.challenges;
|
|
9116
|
+
const pageSorts = PKC.pageSorts;
|
|
7926
9117
|
const createAnchorIpnsRecord = PKC.createAnchorIpnsRecord;
|
|
7927
9118
|
//#endregion
|
|
7928
|
-
export {
|
|
9119
|
+
export { parseRpcExportCommunityParam as _, getShortCid as a, parseRpcUnsubscribeParam as b, setNativeFunctions as c, parseRpcCidParam as d, parseRpcCommentRepliesPageParam as f, parseRpcExportCommunityModLogsParam as g, parseRpcEditCommunityParam as h, getShortAddress as i, parseRpcAuthorNameParam as l, parseRpcCommunityPageParam as m, challenges as n, nativeFunctions as o, parseRpcCommunityIdentifierParam as p, createAnchorIpnsRecord as r, pageSorts as s, PKC as t, parseRpcCancelExportParam as u, parseRpcPublishAnchorRecordParam as v, parseRpcPublishChallengeAnswersParam as y };
|