@pkcprotocol/pkc-js 0.0.141 → 0.0.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +1 -0
  2. package/dist/browser/clients/base-client-manager.js +6 -1
  3. package/dist/browser/clients/base-client-manager.js.map +1 -1
  4. package/dist/browser/clients/rpc-client/pkc-rpc-client.js +15 -8
  5. package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
  6. package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +2 -0
  7. package/dist/browser/clients/rpc-client/schema.d.ts +2 -0
  8. package/dist/browser/community/rpc-local-community.d.ts +12 -1
  9. package/dist/browser/community/rpc-local-community.js +133 -10
  10. package/dist/browser/community/rpc-local-community.js.map +1 -1
  11. package/dist/browser/community/schema.d.ts +19 -0
  12. package/dist/browser/community/schema.js +7 -3
  13. package/dist/browser/community/schema.js.map +1 -1
  14. package/dist/browser/generated-version.d.ts +1 -1
  15. package/dist/browser/generated-version.js +1 -1
  16. package/dist/browser/helia/helia-for-pkc.js +18 -1
  17. package/dist/browser/helia/helia-for-pkc.js.map +1 -1
  18. package/dist/browser/index-with-compile-cache.d.ts +2 -0
  19. package/dist/browser/index.d.ts +4 -0
  20. package/dist/browser/object-key-util.js +5 -1
  21. package/dist/browser/object-key-util.js.map +1 -1
  22. package/dist/browser/pages/pages-client-manager.d.ts +1 -0
  23. package/dist/browser/pages/pages-client-manager.js +22 -5
  24. package/dist/browser/pages/pages-client-manager.js.map +1 -1
  25. package/dist/browser/pages/pkc-js-page-sorts/top.js +2 -1
  26. package/dist/browser/pages/pkc-js-page-sorts/top.js.map +1 -1
  27. package/dist/browser/pages/schema.js +3 -1
  28. package/dist/browser/pages/schema.js.map +1 -1
  29. package/dist/browser/pkc/pkc-with-rpc-client.js +9 -5
  30. package/dist/browser/pkc/pkc-with-rpc-client.js.map +1 -1
  31. package/dist/browser/pkc/pkc.d.ts +4 -1
  32. package/dist/browser/pkc/pkc.js +6 -5
  33. package/dist/browser/pkc/pkc.js.map +1 -1
  34. package/dist/browser/publications/comment/comment-client-manager.js +11 -11
  35. package/dist/browser/publications/comment/comment-client-manager.js.map +1 -1
  36. package/dist/browser/publications/comment/comment.js +2 -0
  37. package/dist/browser/publications/comment/comment.js.map +1 -1
  38. package/dist/browser/publications/community-edit/schema.d.ts +8 -0
  39. package/dist/browser/publications/publication-client-manager.js +7 -1
  40. package/dist/browser/publications/publication-client-manager.js.map +1 -1
  41. package/dist/browser/publications/publication.d.ts +7 -0
  42. package/dist/browser/publications/publication.js +88 -24
  43. package/dist/browser/publications/publication.js.map +1 -1
  44. package/dist/browser/pubsub-messages/schema.d.ts +4 -0
  45. package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +2 -0
  46. package/dist/browser/rpc/src/schema.d.ts +12 -0
  47. package/dist/browser/runtime/node/community/db-handler.d.ts +3 -0
  48. package/dist/browser/runtime/node/community/db-handler.js +22 -4
  49. package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
  50. package/dist/browser/runtime/node/community/local-community/comment-updates.d.ts +1 -0
  51. package/dist/browser/runtime/node/community/local-community/comment-updates.js +70 -19
  52. package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
  53. package/dist/browser/runtime/node/community/local-community/post-updates-bucket.d.ts +14 -0
  54. package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js +206 -0
  55. package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js.map +1 -0
  56. package/dist/browser/runtime/node/community/local-community.d.ts +1 -0
  57. package/dist/browser/runtime/node/community/local-community.js +4 -0
  58. package/dist/browser/runtime/node/community/local-community.js.map +1 -1
  59. package/dist/browser/runtime/node/community/page-sorts/index.js +10 -10
  60. package/dist/browser/runtime/node/community/page-sorts/index.js.map +1 -1
  61. package/dist/browser/schema/schema-util.d.ts +8 -0
  62. package/dist/browser/schema.d.ts +16 -0
  63. package/dist/browser/test/mock-ipfs-client.js +10 -4
  64. package/dist/browser/test/mock-ipfs-client.js.map +1 -1
  65. package/dist/browser/util.d.ts +5 -0
  66. package/dist/browser/util.js +52 -5
  67. package/dist/browser/util.js.map +1 -1
  68. package/dist/bundled/bundle-manifest.json +165 -123
  69. package/dist/bundled/challenges.js +1 -1
  70. package/dist/bundled/chunks/{helia-for-pkc-C3zShnXN.js → helia-for-pkc-DpsMZzv8.js} +41 -34
  71. package/dist/bundled/chunks/{local-community-PFaUvMFo.js → local-community-BglT8AUy.js} +284 -47
  72. package/dist/bundled/chunks/{local-community-DMklqSLp.js → local-community-DEaDtekb.js} +1 -1
  73. package/dist/bundled/chunks/{node-CGmAA0az.js → node-Tkx_TCqE.js} +84 -34
  74. package/dist/bundled/chunks/{page-sort-scoring-Bz65Z28_.js → page-sort-scoring-DY7SvqJA.js} +1 -1
  75. package/dist/bundled/chunks/{rpc-local-community-Dq_6nnU1.js → rpc-local-community-Br_xomgn.js} +128 -20
  76. package/dist/bundled/chunks/src-ABfmT8J2.js +2323 -0
  77. package/dist/bundled/chunks/src-BC60-Q7v.js +2 -0
  78. package/dist/bundled/chunks/src-BHqirG63.js +2 -0
  79. package/dist/bundled/chunks/{src-BggJ_InF.js → src-Bj5iE3qB.js} +2 -1999
  80. package/dist/bundled/chunks/src-CNab3O7M.js +2001 -0
  81. package/dist/bundled/chunks/{src-BsiPSkhv.js → src-ltPxiZKf.js} +1312 -3632
  82. package/dist/bundled/chunks/{util-C6YaxADn.js → util-C5RiQF_G.js} +59 -10
  83. package/dist/bundled/chunks/{util-CzoLr9RY.js → util-DIkZirPy.js} +1 -1
  84. package/dist/bundled/chunks/{validate-package-factories-DMzx5r6y.js → validate-package-factories-DnW2JiL5.js} +2 -2
  85. package/dist/bundled/index.js +1 -1
  86. package/dist/bundled/page-sorts.js +1 -1
  87. package/dist/bundled/rpc/src/index.js +4 -4
  88. package/dist/node/clients/base-client-manager.js +6 -1
  89. package/dist/node/clients/base-client-manager.js.map +1 -1
  90. package/dist/node/clients/rpc-client/pkc-rpc-client.js +15 -8
  91. package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
  92. package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +2 -0
  93. package/dist/node/clients/rpc-client/schema.d.ts +2 -0
  94. package/dist/node/community/rpc-local-community.d.ts +12 -1
  95. package/dist/node/community/rpc-local-community.js +133 -10
  96. package/dist/node/community/rpc-local-community.js.map +1 -1
  97. package/dist/node/community/schema.d.ts +19 -0
  98. package/dist/node/community/schema.js +7 -3
  99. package/dist/node/community/schema.js.map +1 -1
  100. package/dist/node/generated-version.d.ts +1 -1
  101. package/dist/node/generated-version.js +1 -1
  102. package/dist/node/helia/helia-for-pkc.js +18 -1
  103. package/dist/node/helia/helia-for-pkc.js.map +1 -1
  104. package/dist/node/index-with-compile-cache.d.ts +2 -0
  105. package/dist/node/index.d.ts +4 -0
  106. package/dist/node/object-key-util.js +5 -1
  107. package/dist/node/object-key-util.js.map +1 -1
  108. package/dist/node/pages/pages-client-manager.d.ts +1 -0
  109. package/dist/node/pages/pages-client-manager.js +22 -5
  110. package/dist/node/pages/pages-client-manager.js.map +1 -1
  111. package/dist/node/pages/pkc-js-page-sorts/top.js +2 -1
  112. package/dist/node/pages/pkc-js-page-sorts/top.js.map +1 -1
  113. package/dist/node/pages/schema.js +3 -1
  114. package/dist/node/pages/schema.js.map +1 -1
  115. package/dist/node/pkc/pkc-with-rpc-client.js +9 -5
  116. package/dist/node/pkc/pkc-with-rpc-client.js.map +1 -1
  117. package/dist/node/pkc/pkc.d.ts +4 -1
  118. package/dist/node/pkc/pkc.js +6 -5
  119. package/dist/node/pkc/pkc.js.map +1 -1
  120. package/dist/node/publications/comment/comment-client-manager.js +11 -11
  121. package/dist/node/publications/comment/comment-client-manager.js.map +1 -1
  122. package/dist/node/publications/comment/comment.js +2 -0
  123. package/dist/node/publications/comment/comment.js.map +1 -1
  124. package/dist/node/publications/community-edit/schema.d.ts +8 -0
  125. package/dist/node/publications/publication-client-manager.js +7 -1
  126. package/dist/node/publications/publication-client-manager.js.map +1 -1
  127. package/dist/node/publications/publication.d.ts +7 -0
  128. package/dist/node/publications/publication.js +88 -24
  129. package/dist/node/publications/publication.js.map +1 -1
  130. package/dist/node/pubsub-messages/schema.d.ts +4 -0
  131. package/dist/node/rpc/src/lib/pkc-js/index.d.ts +2 -0
  132. package/dist/node/rpc/src/schema.d.ts +12 -0
  133. package/dist/node/runtime/node/community/db-handler.d.ts +3 -0
  134. package/dist/node/runtime/node/community/db-handler.js +22 -4
  135. package/dist/node/runtime/node/community/db-handler.js.map +1 -1
  136. package/dist/node/runtime/node/community/local-community/comment-updates.d.ts +1 -0
  137. package/dist/node/runtime/node/community/local-community/comment-updates.js +70 -19
  138. package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
  139. package/dist/node/runtime/node/community/local-community/post-updates-bucket.d.ts +14 -0
  140. package/dist/node/runtime/node/community/local-community/post-updates-bucket.js +206 -0
  141. package/dist/node/runtime/node/community/local-community/post-updates-bucket.js.map +1 -0
  142. package/dist/node/runtime/node/community/local-community.d.ts +1 -0
  143. package/dist/node/runtime/node/community/local-community.js +4 -0
  144. package/dist/node/runtime/node/community/local-community.js.map +1 -1
  145. package/dist/node/runtime/node/community/page-sorts/index.js +10 -10
  146. package/dist/node/runtime/node/community/page-sorts/index.js.map +1 -1
  147. package/dist/node/schema/schema-util.d.ts +8 -0
  148. package/dist/node/schema.d.ts +16 -0
  149. package/dist/node/test/mock-ipfs-client.js +10 -4
  150. package/dist/node/test/mock-ipfs-client.js.map +1 -1
  151. package/dist/node/util.d.ts +5 -0
  152. package/dist/node/util.js +52 -5
  153. package/dist/node/util.js.map +1 -1
  154. package/package.json +4 -1
@@ -1,7 +1,7 @@
1
1
  import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { $ as retryKuboIpfsAddAndProvide, At as ChallengeAnswerMessageSchema, C as hideClassPrivateProps, D as isIpfsCid, Dt as require_sha256, E as isAbortError, Et as untrackUpdatingCommunity, H as rejectWhenAbortSignalFires, Hr as setErrorMap, In as CommentUpdateForChallengeVerificationSchema, It as ChallengeVerificationMessageSchema, J as removeUndefinedValuesRecursively, Jt as version_default, Lr as PKCError, Mr as FailedToFetchCommentIpfsFromGatewaysError, Mt as ChallengeMessageSchema, Nr as FailedToFetchCommentUpdateFromGatewaysError, Ot as TimeoutError, Pt as ChallengeRequestMessageSchema, Q as retryKuboIpfsAdd, Rr as messages, Sr as e$1, St as trackUpdatingComment, T as ipnsNameToIpnsOverPubsubTopic, Tt as untrackUpdatingComment, U as rejectWhenCommunityStopsOrAborts, X as resolveWhenPredicateIsTrue, Y as replaceXWithY, _t as listUpdatingCommunities, a as calculateStringSizeSameAsIpfsAddCidV0Sync, at as timestamp, br as t$1, cn as CommunityAnchorSchema, d as deepMergeRuntimeFields, dt as findStartedCommunity, et as shortifyAddress, ft as findUpdatingComment, gr as n$2, gt as listUpdatingComments, hr as isStringDomain, ht as listStartedCommunities, i as calculateStringSizeSameAsIpfsAddCidV0, it as throwIfAbortSignalAborted, jn as CommentIpfsSchema, jr as require_retry$1, k as isIpns, kt as pTimeout, ni as en_default, nt as sleepUntilTimeoutOrAbort, ot as waitForUpdateInCommunityInstanceWithErrorAndTimeout, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, tt as shortifyCid, u as createAbortError, vr as n$1, vt as refreshTrackedCommentAliases, wr as r, x as getPostUpdateTimestampRange, xn as PubsubTopicSchema, xr as e, zn as CommentUpdateSchema, zr as logger_default } from "./util-C6YaxADn.js";
3
- import { $n as buildRuntimeCommunityFields, $t as RpcPublishCommunityListParamSchema, A as findCommentInParsedPages, Ar as setNativeFunctions$1, At as parseRpcCommentUpdateEventWithPKCErrorIfItFails, B as GenericStateClient, Bn as verifyCommunityEdit, Br as t$3, Bt as RpcCommunityIdentifierParamSchema, C as RepliesPages, Cn as signCommentModeration, Ct as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, D as extractCommunityRuntimeFieldsFromParsedPages, Dn as signCommunityEdit, Dt as parseJsonWithPKCErrorIfFails, Er as monitorCommunitiesDirectory, Et as parseDecryptedChallengeWithPKCErrorIfItFails, F as cloneCrosspostForRuntime, Fn as verifyCommentIpfs, Ft as RpcAuthorNameParamSchema, G as PKCTypedEmitter, Gn as getAuthorNameFromRuntime, Gt as RpcExportCommunityParamSchema, H as InflightResourceTypes, Hn as verifyVote, Ht as RpcEditCommunityParamSchema, I as collectCrosspostAuthorsToResolve, In as verifyCommentModeration, It as RpcCancelExportParamSchema, J as decodeRpcChallengeRequestPubsubMsg, Jn as CreateCommunityListWithCidOptionsSchema, Jr as NAME_RESOLVED_TRUE_TTL_MS, Jt as RpcFetchCidResultSchema, K as decodeRpcChallengeAnswerPubsubMsg, Kn as getAuthorNameFromWire, Kr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, Kt as RpcExportCommunityResultSchema, Ln as verifyCommentPubsubMessage, Lr as t$5, Lt as RpcCidParamSchema, M as parseRawPages, Mr as findCommunitiesEntry, Nn as verifyChallengeVerification, Nr as toCommunitiesEntry, Nt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, O as findCommentInPageInstance, On as signCommunityList, Ot as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, P as applyNameResolvedCacheToCrosspost, Pn as verifyCommentEdit, Pt as RpcAnchorPublishPreparationResultSchema, Qr as nativeFunctions$2, Qt as RpcPublishChallengeAnswersParamSchema, R as stripNameResolvedFromCrosspost, Rn as verifyCommentUpdate, Rt as RpcCommentRepliesPageParamSchema, Sn as signCommentEdit, Sr as getDefaultDataPath, St as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, Tr as listCommunitiesSync, Tt as parseDecryptedChallengeVerification, Un as buildRuntimeAuthor, Ur as t$2, Ut as RpcExportCommunityModLogsParamSchema, V as InflightFetchManager, Vn as verifyCommunityList, Vr as n$3, Vt as RpcCommunityPageParamSchema, Wn as cleanWireAuthor, Wr as t$4, Wt as RpcExportCommunityModLogsResultSchema, Xn as MAX_COMMUNITY_LIST_SIZE_BYTES, Xt as RpcFetchCommunityListResultSchema, Y as decodeRpcChallengeVerificationPubsubMsg, Yn as CreateNewCommunityListOptionsSchema, Yr as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, Yt as RpcFetchCommunityListParamSchema, Zt as RpcPublishAnchorRecordParamSchema, _n as signChallengeAnswer, _t as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, an as RpcUnsubscribeParamSchema, b as KeyvBetterSqlite3, br as findLocalCommunityAddress, ct as parseCommentUpdateSchemaWithPKCErrorIfItFails, dn as decryptEd25519AesGcm, en as RpcPublishCommunityListResultSchema, er as getCommunityAddressFromRecord, et as parseCidStringSchemaWithPKCErrorIfItFails, ft as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, gn as cleanUpBeforePublishing, gt as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, hr as createKuboRpcClient, ht as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, in as RpcSuccessResultSchema, ir as decode, it as parseCommentIpfsSchemaWithPKCErrorIfItFails, jn as verifyChallengeMessage, jr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, jt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, k as findCommentInPageInstanceRecursively, kn as signVote, kt as parseRpcCommentEventWithPKCErrorIfItFails, l as pkcJsPageSorts, ln as createSigner, lr as getPKCAddressFromPublicKeySync, lt as parseCommunityAddressWithPKCErrorIfItFails, m as pkcJsChallenges, mt as parseCommunityListSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as RpcResolveAuthorNameResultSchema, nr as getCommunityPublicKeyFromWire, on as findCommunityRecordNameMismatch, or as getBufferedPKCAddressFromPublicKey, ot as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, pn as encryptEd25519AesGcm, q as decodeRpcChallengePubsubMsg, qn as normalizeCreatePublicationAuthor, qr as NAME_RESOLVED_FALSE_TTL_MS, qt as RpcFetchCidParamSchema, rn as RpcSubscriptionIdResultSchema, rr as normalizeCommunityInputFromCommunity, rt as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, sn as require_lib$1, st as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, t as RpcLocalCommunity, tn as RpcPublishedAnchorRecordResultSchema, tr as getCommunityNameFromWire, un as createAnchorIpnsRecord$1, v as TrackedInstanceRegistry, vt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, x as RemoteCommunity, xn as signComment, xt as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, y as LRUCache, yn as signChallengeRequest, z as PKCClientsManager, zt as RpcCommunitiesChangeEventResultSchema } from "./rpc-local-community-Dq_6nnU1.js";
4
- import { s as getHeliaDebugContext } from "./util-CzoLr9RY.js";
2
+ import { $ as retryKuboIpfsAdd, At as pTimeout, Bn as CommentUpdateSchema, Br as logger_default, C as hideClassPrivateProps, Cr as e$1, Ct as trackUpdatingComment, D as isIpfsCid, Dt as untrackUpdatingCommunity, E as isAbortError, Et as untrackUpdatingComment, Ft as ChallengeRequestMessageSchema, Ln as CommentUpdateForChallengeVerificationSchema, Lt as ChallengeVerificationMessageSchema, Mn as CommentIpfsSchema, Mr as require_retry$1, Nr as FailedToFetchCommentIpfsFromGatewaysError, Nt as ChallengeMessageSchema, Ot as require_sha256, Pr as FailedToFetchCommentUpdateFromGatewaysError, Rr as PKCError, Sn as PubsubTopicSchema, Sr as e, T as ipnsNameToIpnsOverPubsubTopic, Tr as r, U as rejectWhenAbortSignalFires, Ur as setErrorMap, W as rejectWhenCommunityStopsOrAborts, X as replaceXWithY, Y as removeUndefinedValuesRecursively, Yt as version_default, Z as resolveWhenPredicateIsTrue, _r as n$2, _t as listUpdatingComments, a as calculateStringSizeSameAsIpfsAddCidV0Sync, at as throwIfAbortSignalAborted, d as deepMergeRuntimeFields, et as retryKuboIpfsAddAndProvide, ft as findStartedCommunity, gr as isStringDomain, gt as listStartedCommunities, i as calculateStringSizeSameAsIpfsAddCidV0, jt as ChallengeAnswerMessageSchema, k as isIpns, kt as TimeoutError, ln as CommunityAnchorSchema, mn as CommunityIpfsSchema, mt as findUpdatingCommunity, nt as shortifyCid, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pt as findUpdatingComment, r as calculateIpfsCidV0, ri as en_default, rt as sleepUntilTimeoutOrAbort, st as waitForUpdateInCommunityInstanceWithErrorAndTimeout, tt as shortifyAddress, u as createAbortError, vt as listUpdatingCommunities, x as getPostUpdateTimestampRange, xr as t$1, yr as n$1, yt as refreshTrackedCommentAliases, z as linkAbortSignals, zr as messages } from "./util-C5RiQF_G.js";
3
+ import { $n as buildRuntimeCommunityFields, $t as RpcPublishCommunityListParamSchema, A as findCommentInParsedPages, Ar as setNativeFunctions$1, At as parseRpcCommentUpdateEventWithPKCErrorIfItFails, B as GenericStateClient, Bn as verifyCommunityEdit, Br as t$3, Bt as RpcCommunityIdentifierParamSchema, C as RepliesPages, Cn as signCommentModeration, Ct as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, D as extractCommunityRuntimeFieldsFromParsedPages, Dn as signCommunityEdit, Dt as parseJsonWithPKCErrorIfFails, Er as monitorCommunitiesDirectory, Et as parseDecryptedChallengeWithPKCErrorIfItFails, F as cloneCrosspostForRuntime, Fn as verifyCommentIpfs, Ft as RpcAuthorNameParamSchema, G as PKCTypedEmitter, Gn as getAuthorNameFromRuntime, Gt as RpcExportCommunityParamSchema, H as InflightResourceTypes, Hn as verifyVote, Ht as RpcEditCommunityParamSchema, I as collectCrosspostAuthorsToResolve, In as verifyCommentModeration, It as RpcCancelExportParamSchema, J as decodeRpcChallengeRequestPubsubMsg, Jn as CreateCommunityListWithCidOptionsSchema, Jr as NAME_RESOLVED_TRUE_TTL_MS, Jt as RpcFetchCidResultSchema, K as decodeRpcChallengeAnswerPubsubMsg, Kn as getAuthorNameFromWire, Kr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, Kt as RpcExportCommunityResultSchema, Ln as verifyCommentPubsubMessage, Lr as t$5, Lt as RpcCidParamSchema, M as parseRawPages, Mr as findCommunitiesEntry, Nn as verifyChallengeVerification, Nr as toCommunitiesEntry, Nt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, O as findCommentInPageInstance, On as signCommunityList, Ot as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, P as applyNameResolvedCacheToCrosspost, Pn as verifyCommentEdit, Pt as RpcAnchorPublishPreparationResultSchema, Qr as nativeFunctions$2, Qt as RpcPublishChallengeAnswersParamSchema, R as stripNameResolvedFromCrosspost, Rn as verifyCommentUpdate, Rt as RpcCommentRepliesPageParamSchema, Sn as signCommentEdit, Sr as getDefaultDataPath, St as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, Tr as listCommunitiesSync, Tt as parseDecryptedChallengeVerification, Un as buildRuntimeAuthor, Ur as t$2, Ut as RpcExportCommunityModLogsParamSchema, V as InflightFetchManager, Vn as verifyCommunityList, Vr as n$3, Vt as RpcCommunityPageParamSchema, Wn as cleanWireAuthor, Wr as t$4, Wt as RpcExportCommunityModLogsResultSchema, Xn as MAX_COMMUNITY_LIST_SIZE_BYTES, Xt as RpcFetchCommunityListResultSchema, Y as decodeRpcChallengeVerificationPubsubMsg, Yn as CreateNewCommunityListOptionsSchema, Yr as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, Yt as RpcFetchCommunityListParamSchema, Zt as RpcPublishAnchorRecordParamSchema, _n as signChallengeAnswer, _t as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, an as RpcUnsubscribeParamSchema, b as KeyvBetterSqlite3, br as findLocalCommunityAddress, ct as parseCommentUpdateSchemaWithPKCErrorIfItFails, dn as decryptEd25519AesGcm, en as RpcPublishCommunityListResultSchema, er as getCommunityAddressFromRecord, et as parseCidStringSchemaWithPKCErrorIfItFails, ft as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, gn as cleanUpBeforePublishing, gt as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, hr as createKuboRpcClient, ht as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, in as RpcSuccessResultSchema, ir as decode, it as parseCommentIpfsSchemaWithPKCErrorIfItFails, jn as verifyChallengeMessage, jr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, jt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, k as findCommentInPageInstanceRecursively, kn as signVote, kt as parseRpcCommentEventWithPKCErrorIfItFails, l as pkcJsPageSorts, ln as createSigner, lr as getPKCAddressFromPublicKeySync, lt as parseCommunityAddressWithPKCErrorIfItFails, m as pkcJsChallenges, mt as parseCommunityListSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as RpcResolveAuthorNameResultSchema, nr as getCommunityPublicKeyFromWire, on as findCommunityRecordNameMismatch, or as getBufferedPKCAddressFromPublicKey, ot as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, pn as encryptEd25519AesGcm, q as decodeRpcChallengePubsubMsg, qn as normalizeCreatePublicationAuthor, qr as NAME_RESOLVED_FALSE_TTL_MS, qt as RpcFetchCidParamSchema, rn as RpcSubscriptionIdResultSchema, rr as normalizeCommunityInputFromCommunity, rt as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, sn as require_lib$1, st as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, t as RpcLocalCommunity, tn as RpcPublishedAnchorRecordResultSchema, tr as getCommunityNameFromWire, un as createAnchorIpnsRecord$1, v as TrackedInstanceRegistry, vt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, x as RemoteCommunity, xn as signComment, xt as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, y as LRUCache, yn as signChallengeRequest, z as PKCClientsManager, zt as RpcCommunitiesChangeEventResultSchema } from "./rpc-local-community-Br_xomgn.js";
4
+ import { s as getHeliaDebugContext } from "./util-DIkZirPy.js";
5
5
  import path from "path";
6
6
  import assert from "assert";
7
7
  import fs from "fs";
@@ -27353,13 +27353,15 @@ var PublicationClientsManager = class extends PKCClientsManager {
27353
27353
  communityPublicKey: updatingCommunityInstance.community.publicKey
27354
27354
  });
27355
27355
  if (nameMismatch) throw nameMismatch;
27356
- return {
27356
+ const communityForPublishing = {
27357
27357
  address: updatingCommunityInstance.community.address,
27358
27358
  publicKey: updatingCommunityInstance.community.publicKey,
27359
27359
  name: updatingCommunityInstance.community.name,
27360
27360
  encryption: communityIpfs.encryption,
27361
27361
  pubsubTopic: communityIpfs.pubsubTopic
27362
27362
  };
27363
+ this._pkc._memCaches.communityForPublishing.set(this._publication.communityAddress, communityForPublishing);
27364
+ return communityForPublishing;
27363
27365
  }
27364
27366
  };
27365
27367
  //#endregion
@@ -27497,6 +27499,7 @@ var Publication = class extends import_lib.TypedEmitter {
27497
27499
  args: [verification, this instanceof Comment && verification.comment ? this : void 0]
27498
27500
  }
27499
27501
  });
27502
+ this._unregisterFromPkcOncePublishWorkSettles();
27500
27503
  if (this._rpcPublishSubscriptionId) {
27501
27504
  const subscriptionId = this._rpcPublishSubscriptionId;
27502
27505
  this._rpcPublishSubscriptionId = void 0;
@@ -27863,17 +27866,39 @@ var Publication = class extends import_lib.TypedEmitter {
27863
27866
  _getCommunityFetchAbortSignal() {
27864
27867
  if (!this._communityFetchAbortSignal) {
27865
27868
  this._communityFetchAbortController = new AbortController();
27866
- this._communityFetchAbortSignal = AbortSignal.any([this._communityFetchAbortController.signal, this._pkc._getDestroyAbortSignal()]);
27869
+ this._communityFetchAbortSignal = this._communityFetchAbortController.signal;
27867
27870
  }
27868
27871
  return this._communityFetchAbortSignal;
27869
27872
  }
27873
+ async _cancelBackgroundCommunityRefresh() {
27874
+ this._communityFetchAbortController?.abort(new PKCError("ERR_GET_COMMUNITY_ABORTED", {
27875
+ publicationType: this.getType(),
27876
+ communityAddress: this.communityAddress
27877
+ }));
27878
+ if (this._backgroundCommunityRefresh) await this._backgroundCommunityRefresh;
27879
+ this._resetCommunityFetchAbortSignal();
27880
+ }
27870
27881
  _resetCommunityFetchAbortSignal() {
27871
27882
  this._communityFetchAbortController = void 0;
27872
27883
  this._communityFetchAbortSignal = void 0;
27873
27884
  }
27885
+ _beginPublishRun() {
27886
+ this._publishRunAbortController = new AbortController();
27887
+ this._publishRunWaitSignal = this._publishRunAbortController.signal;
27888
+ }
27889
+ _getPublishRunWaitSignal() {
27890
+ if (!this._publishRunWaitSignal) this._beginPublishRun();
27891
+ return this._publishRunWaitSignal;
27892
+ }
27893
+ _isPublishRunOver(runSignal) {
27894
+ return this._pkc.destroyed || runSignal.aborted;
27895
+ }
27874
27896
  _getCommunityCache() {
27875
- const cached = this._pkc._memCaches.communityForPublishing.get(this.communityAddress, { allowStale: true });
27876
- if (cached) return cached;
27897
+ const cache = this._pkc._memCaches.communityForPublishing;
27898
+ if (cache.has(this.communityAddress)) return cache.get(this.communityAddress);
27899
+ return this._getCommunityFromLiveInstance() ?? cache.get(this.communityAddress, { allowStale: true });
27900
+ }
27901
+ _getCommunityFromLiveInstance() {
27877
27902
  const subInstance = findUpdatingCommunity(this._pkc, {
27878
27903
  publicKey: this.communityPublicKey,
27879
27904
  name: this.communityName
@@ -27899,12 +27924,21 @@ var Publication = class extends import_lib.TypedEmitter {
27899
27924
  const log = logger_default("pkc-js:publish:_fetchCommunityForPublishing");
27900
27925
  const cachedCommunity = this._getCommunityCache();
27901
27926
  if (cachedCommunity) {
27902
- if (!this._pkc._memCaches.communityForPublishing.has(this.communityAddress)) {
27927
+ if (!(this._pkc._memCaches.communityForPublishing.has(this.communityAddress) || this._getCommunityFromLiveInstance() !== void 0)) {
27903
27928
  log("The cache of community is stale, we will use the cached and update in the background");
27904
27929
  const refresh = this._pkc.getCommunity({
27905
27930
  publicKey: this.communityPublicKey,
27906
27931
  name: this.communityName,
27907
27932
  abortSignal: this._getCommunityFetchAbortSignal()
27933
+ }).then((community) => {
27934
+ const record = community.raw.communityIpfs;
27935
+ if (record && community.publicKey) this._pkc._memCaches.communityForPublishing.set(this.communityAddress, {
27936
+ address: community.address,
27937
+ publicKey: community.publicKey,
27938
+ name: community.name,
27939
+ encryption: record.encryption,
27940
+ pubsubTopic: record.pubsubTopic
27941
+ });
27908
27942
  }).catch((e) => {
27909
27943
  if (e?.code === "ERR_GET_COMMUNITY_ABORTED") log("Stopped the background refresh of the community cache", this.communityAddress);
27910
27944
  else {
@@ -27958,6 +27992,7 @@ var Publication = class extends import_lib.TypedEmitter {
27958
27992
  }
27959
27993
  async _postSucessOrFailurePublishing() {
27960
27994
  const log = logger_default("pkc-js:publication:_postSucessOrFailurePublishing");
27995
+ this._publishRunAbortController?.abort();
27961
27996
  this._unregisterFromPkcOncePublishWorkSettles();
27962
27997
  this._setStateWithEmission("stopped");
27963
27998
  if (this._rpcPublishSubscriptionId) {
@@ -28150,8 +28185,9 @@ var Publication = class extends import_lib.TypedEmitter {
28150
28185
  return contexts;
28151
28186
  }
28152
28187
  async _handleNotReceivingResponseToChallengeRequest({ providers, currentPubsubProviderIndex, acceptedChallengeTypes }) {
28153
- await sleepUntilTimeoutOrAbort(this._publishToDifferentProviderThresholdSeconds * 1e3, this._pkc._getDestroyAbortSignal());
28154
- if (this._pkc.destroyed) return;
28188
+ const runSignal = this._getPublishRunWaitSignal();
28189
+ await sleepUntilTimeoutOrAbort(this._publishToDifferentProviderThresholdSeconds * 1e3, runSignal);
28190
+ if (this._isPublishRunOver(runSignal)) return;
28155
28191
  if (this._didWeReceiveChallengeOrChallengeVerification()) return;
28156
28192
  const currentPubsubProvider = providers[currentPubsubProviderIndex];
28157
28193
  this._pkc._stats.recordGatewayFailure(currentPubsubProvider, "pubsub-publish");
@@ -28183,6 +28219,7 @@ var Publication = class extends import_lib.TypedEmitter {
28183
28219
  currentPubsubProviderIndex += 1;
28184
28220
  while (!this._didWeReceiveChallengeOrChallengeVerification() && currentPubsubProviderIndex < providers.length) {
28185
28221
  const providerUrl = providers[currentPubsubProviderIndex];
28222
+ if (this._isPublishRunOver(runSignal)) return;
28186
28223
  const challengeRequest = await this._generateChallengeRequestToPublish(providerUrl, acceptedChallengeTypes);
28187
28224
  this._updatePublishingStateWithEmission("publishing-challenge-request");
28188
28225
  this._updatePubsubState("subscribing-pubsub", providerUrl);
@@ -28206,11 +28243,11 @@ var Publication = class extends import_lib.TypedEmitter {
28206
28243
  }
28207
28244
  log(`Published a challenge request of publication`, this.getType(), "with provider", providerUrl);
28208
28245
  this.emit("challengerequest", decryptedRequest);
28209
- if (currentPubsubProviderIndex !== providers.length) await sleepUntilTimeoutOrAbort(this._publishToDifferentProviderThresholdSeconds * 1e3, this._pkc._getDestroyAbortSignal());
28210
- if (this._pkc.destroyed) return;
28246
+ if (currentPubsubProviderIndex !== providers.length) await sleepUntilTimeoutOrAbort(this._publishToDifferentProviderThresholdSeconds * 1e3, runSignal);
28247
+ if (this._isPublishRunOver(runSignal)) return;
28211
28248
  }
28212
- await sleepUntilTimeoutOrAbort(this._setProviderFailureThresholdSeconds * 1e3, this._pkc._getDestroyAbortSignal());
28213
- if (this._pkc.destroyed) return;
28249
+ await sleepUntilTimeoutOrAbort(this._setProviderFailureThresholdSeconds * 1e3, runSignal);
28250
+ if (this._isPublishRunOver(runSignal)) return;
28214
28251
  if (this.state === "stopped") return;
28215
28252
  if (this._didWeReceiveChallengeOrChallengeVerification()) {
28216
28253
  log(`Received a challenge or challenge verification while waiting for retried providers, will keep the exchange alive`);
@@ -28278,11 +28315,13 @@ var Publication = class extends import_lib.TypedEmitter {
28278
28315
  async publish() {
28279
28316
  this._validatePublicationFields();
28280
28317
  if (this._getCommunityFetchAbortSignal().aborted) this._resetCommunityFetchAbortSignal();
28318
+ this._beginPublishRun();
28281
28319
  this._pkc._publishingPublications.add(this);
28282
28320
  try {
28283
28321
  return await this._publishAfterRegistering();
28284
28322
  } catch (e) {
28285
28323
  this._unregisterFromPkcOncePublishWorkSettles();
28324
+ this._publishRunAbortController?.abort();
28286
28325
  throw e;
28287
28326
  }
28288
28327
  }
@@ -28564,10 +28603,7 @@ var CommentClientsManager = class extends PublicationClientsManager {
28564
28603
  this._freshHandlerAbortController = new AbortController();
28565
28604
  }
28566
28605
  _combinedAbortSignalForRetry() {
28567
- const signals = [this._comment._getStopAbortSignal(), this._freshHandlerAbortController?.signal].filter((s) => Boolean(s));
28568
- if (signals.length === 0) return void 0;
28569
- if (signals.length === 1) return signals[0];
28570
- return AbortSignal.any(signals);
28606
+ return linkAbortSignals([this._comment._getStopAbortSignal(), this._freshHandlerAbortController?.signal]);
28571
28607
  }
28572
28608
  _initKuboRpcClients() {
28573
28609
  if (this._pkc.clients.kuboRpcClients) for (const ipfsUrl of t$1(this._pkc.clients.kuboRpcClients)) this.clients.kuboRpcClients = {
@@ -28883,7 +28919,8 @@ var CommentClientsManager = class extends PublicationClientsManager {
28883
28919
  if (typeof postTimestamp !== "number") throw Error("Post timestamp is not defined by the time we're fetching from postUpdates");
28884
28920
  const timestampRanges = getPostUpdateTimestampRange(subIpfs.postUpdates, postTimestamp);
28885
28921
  if (timestampRanges.length === 0) throw Error("Post has no timestamp range bucket");
28886
- const abortSignal = this._combinedAbortSignalForRetry();
28922
+ const linkedAbortSignal = this._combinedAbortSignalForRetry();
28923
+ const abortSignal = linkedAbortSignal.signal;
28887
28924
  let newCommentUpdate;
28888
28925
  try {
28889
28926
  if (Object.keys(this._pkc.clients.kuboRpcClients).length > 0 || Object.keys(this._pkc.clients.libp2pJsClients).length > 0) newCommentUpdate = await this._fetchPostCommentUpdateIpfsP2P(subIpfs, timestampRanges, log, abortSignal);
@@ -28912,6 +28949,8 @@ var CommentClientsManager = class extends PublicationClientsManager {
28912
28949
  }
28913
28950
  }
28914
28951
  return;
28952
+ } finally {
28953
+ linkedAbortSignal.dispose();
28915
28954
  }
28916
28955
  if (newCommentUpdate) this._useLoadedCommentUpdateIfNewInfo(newCommentUpdate, subIpfs, log);
28917
28956
  else if (newCommentUpdate === void 0) {
@@ -30309,6 +30348,7 @@ var Comment = class extends Publication {
30309
30348
  async stop() {
30310
30349
  this._abortStopOperations(`Aborting comment operations for ${this.cid || this.author?.address || "comment"} because comment.stop() was called`);
30311
30350
  if (this.state === "publishing") await super.stop();
30351
+ else await this._cancelBackgroundCommunityRefresh();
30312
30352
  this._setStateWithEmission("stopped");
30313
30353
  await this._stopUpdateLoop();
30314
30354
  this.replies._stop();
@@ -30781,12 +30821,15 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
30781
30821
  const serverSubscriptionId = this._serverIdByLocalId.get(subscriptionId) ?? subscriptionId;
30782
30822
  this._resubscribeCalls.delete(subscriptionId);
30783
30823
  this._publishSubscriptionIds.delete(subscriptionId);
30784
- if (liveOnServer) await this._webSocketClient.call("unsubscribe", [{ subscriptionId: serverSubscriptionId }]);
30785
- this._serverIdByLocalId.delete(subscriptionId);
30786
- this._localIdByServerId.delete(serverSubscriptionId);
30787
- if (this._subscriptionEvents[subscriptionId]) this._subscriptionEvents[subscriptionId].removeAllListeners();
30788
- delete this._subscriptionEvents[subscriptionId];
30789
- delete this._pendingSubscriptionMsgs[subscriptionId];
30824
+ try {
30825
+ if (liveOnServer) await this._webSocketClient.call("unsubscribe", [{ subscriptionId: serverSubscriptionId }]);
30826
+ } finally {
30827
+ this._serverIdByLocalId.delete(subscriptionId);
30828
+ this._localIdByServerId.delete(serverSubscriptionId);
30829
+ if (this._subscriptionEvents[subscriptionId]) this._subscriptionEvents[subscriptionId].removeAllListeners();
30830
+ delete this._subscriptionEvents[subscriptionId];
30831
+ delete this._pendingSubscriptionMsgs[subscriptionId];
30832
+ }
30790
30833
  }
30791
30834
  _attachNotificationHandler() {
30792
30835
  const socket = this._webSocketClient.socket;
@@ -35902,7 +35945,7 @@ var PKC$1 = class extends PKCTypedEmitter {
35902
35945
  this.clients.libp2pJsClients = {};
35903
35946
  if (!this.libp2pJsClientsOptions) return;
35904
35947
  if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
35905
- const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-C3zShnXN.js");
35948
+ const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-DpsMZzv8.js");
35906
35949
  for (const clientOptions of this.libp2pJsClientsOptions) {
35907
35950
  const heliaNode = await createLibp2pJsClientOrUseExistingOne({
35908
35951
  ...clientOptions,
@@ -36267,7 +36310,7 @@ var PKC$1 = class extends PKCTypedEmitter {
36267
36310
  const log = logger_default("pkc-js:pkc:createLocalCommunity");
36268
36311
  log.trace("Received community options to create a local community instance:", options);
36269
36312
  if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
36270
- const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-DMklqSLp.js");
36313
+ const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-DEaDtekb.js");
36271
36314
  const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
36272
36315
  const community = new LocalCommunity(this);
36273
36316
  if (isLocalCommunity) {
@@ -36635,8 +36678,11 @@ var PKC$1 = class extends PKCTypedEmitter {
36635
36678
  return this._destroyAbortController.signal;
36636
36679
  }
36637
36680
  _combineWithDestroyAbortSignal(abortSignal) {
36638
- const destroySignal = this._getDestroyAbortSignal();
36639
- return abortSignal ? AbortSignal.any([abortSignal, destroySignal]) : destroySignal;
36681
+ const linked = linkAbortSignals([abortSignal, this._getDestroyAbortSignal()]);
36682
+ return {
36683
+ signal: linked.signal,
36684
+ dispose: linked.dispose
36685
+ };
36640
36686
  }
36641
36687
  async destroy() {
36642
36688
  const log = logger_default("pkc-js:pkc:destroy");
@@ -36790,8 +36836,9 @@ var PKCWithRpcClient = class extends PKC$1 {
36790
36836
  async getComment(getCommentArgs) {
36791
36837
  const { abortSignal, ...cidArgs } = getCommentArgs;
36792
36838
  const parsedArgs = parseRpcCidParam(cidArgs);
36839
+ const combined = this._combineWithDestroyAbortSignal(abortSignal);
36793
36840
  const cancellation = rejectWhenAbortSignalFires({
36794
- abortSignal: this._combineWithDestroyAbortSignal(abortSignal),
36841
+ abortSignal: combined.signal,
36795
36842
  error: () => new PKCError("ERR_GET_COMMENT_ABORTED", {
36796
36843
  getCommentArgs: parsedArgs,
36797
36844
  abortReason: abortSignal?.reason
@@ -36802,6 +36849,7 @@ var PKCWithRpcClient = class extends PKC$1 {
36802
36849
  commentIpfs = await Promise.race([this._pkcRpcClient.getComment(parsedArgs), cancellation.promise]);
36803
36850
  } finally {
36804
36851
  cancellation.cleanup();
36852
+ combined.dispose();
36805
36853
  }
36806
36854
  return this.createComment({
36807
36855
  ...parsedArgs,
@@ -36837,7 +36885,7 @@ var PKCWithRpcClient = class extends PKC$1 {
36837
36885
  if (rawRecord) if ("community" in rawRecord) community.initRpcInternalCommunityAfterFirstUpdateNoMerge(rawRecord);
36838
36886
  else community.initRpcInternalCommunityBeforeFirstUpdateNoMerge(rawRecord);
36839
36887
  if (jsonified.raw) Object.assign(community.raw, jsonified.raw);
36840
- await community._attachExportsSubscription();
36888
+ await community._loadExportsSnapshot();
36841
36889
  return community;
36842
36890
  } else if (isCommunityRpcLocal) {
36843
36891
  const community = new RpcLocalCommunity(this);
@@ -36845,9 +36893,10 @@ var PKCWithRpcClient = class extends PKC$1 {
36845
36893
  const updatePromise = new Promise((resolve) => community.once("update", resolve));
36846
36894
  let error;
36847
36895
  const errorPromise = new Promise((resolve) => community.once("error", (err) => resolve(error = err)));
36896
+ const combined = this._combineWithDestroyAbortSignal(opts?.abortSignal);
36848
36897
  const cancellation = rejectWhenCommunityStopsOrAborts({
36849
36898
  community,
36850
- abortSignal: this._combineWithDestroyAbortSignal(opts?.abortSignal)
36899
+ abortSignal: combined.signal
36851
36900
  });
36852
36901
  try {
36853
36902
  await Promise.race([community._createAndSubscribeToNewUpdatingCommunity(community), cancellation.promise]);
@@ -36862,10 +36911,11 @@ var PKCWithRpcClient = class extends PKC$1 {
36862
36911
  throw e;
36863
36912
  } finally {
36864
36913
  cancellation.cleanup();
36914
+ combined.dispose();
36865
36915
  }
36866
36916
  await community.stop();
36867
36917
  if (error) throw error;
36868
- await community._attachExportsSubscription();
36918
+ await community._loadExportsSnapshot();
36869
36919
  return community;
36870
36920
  } else {
36871
36921
  log.trace("Creating a remote RPC community instance with address", effectiveAddress);
@@ -36885,7 +36935,7 @@ var PKCWithRpcClient = class extends PKC$1 {
36885
36935
  await community.initRpcInternalCommunityBeforeFirstUpdateNoMerge(communityPropsAfterCreation);
36886
36936
  community.emit("update", community);
36887
36937
  await this._awaitCommunitiesToIncludeCommunity(communityPropsAfterCreation.localCommunity.address);
36888
- await community._attachExportsSubscription();
36938
+ await community._loadExportsSnapshot();
36889
36939
  return community;
36890
36940
  } else throw Error("Failed to create community rpc instance, are you sure you provided the correct args?");
36891
36941
  }
@@ -1,4 +1,4 @@
1
- import { bn as PageSortFileSchema, hr as isStringDomain, v as getEquivalentCommunityAddresses } from "./util-C6YaxADn.js";
1
+ import { gr as isStringDomain, v as getEquivalentCommunityAddresses, xn as PageSortFileSchema } from "./util-C5RiQF_G.js";
2
2
  //#region dist/node/pages/page-sort-scoring.js
3
3
  function validatePageSortFile(rawFile) {
4
4
  const validated = PageSortFileSchema.parse(rawFile);
@@ -1,7 +1,7 @@
1
1
  import { i as __toESM, n as __exportAll, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { $r as string, $t as CreateCommunityEditPublicationOptionsWithRefinementSchema, A as isIpnsPath, An as CommentIpfsReservedFields, Ar as e$4, Bn as CommentUpdateSignedPropertyNames, Br as require_supports_color, C as hideClassPrivateProps, Cn as CreateVoteUserOptionsWithRefinementSchema, Cr as t$11, Ct as trackUpdatingCommunity, D as isIpfsCid, Dn as VoteSignedPropertyNames, Dr as r$7, Dt as require_sha256$1, E as isAbortError, Er as n$8, Et as untrackUpdatingCommunity, Fn as CommentUpdateChallengeReservedFieldNames, Fr as FailedToFetchGenericIpfsFromGatewaysError, Ft as ChallengeRequestMessageSignedPropertyNames, Gn as ModQueuePageIpfsSchema, Gr as boolean, Gt as PKCParsedOptionsSchema, Ht as DecryptedChallengeVerificationSchema, Ir as FailedToFetchPageIpfsFromGatewaysError, Jn as CommentEditChallengeRequestToEncryptSchema, Jr as looseObject, K as removeNullUndefinedEmptyObjectsValuesRecursively, Kn as PageIpfsSchema, Kr as custom, Kt as PKCUserOptionBaseSchema, L as isRequestPubsubPublicationOfPost, Ln as CommentUpdateForChallengeVerificationSignedPropertyNames, Lr as PKCError, Lt as ChallengeVerificationMessageSignedPropertyNames, Mr as FailedToFetchCommentIpfsFromGatewaysError, Nn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Nr as FailedToFetchCommentUpdateFromGatewaysError, Nt as ChallengeMessageSignedPropertyNames, O as isIpfsPath, Or as t$10, Pn as CommentSignedPropertyNames, Pr as FailedToFetchCommunityFromGatewaysError, Qn as CommentEditSignedPropertyNames, Qr as record, Qt as CommunityEditPubsubMessagePublicationSchema, R as isRequestPubsubPublicationOfReply, Rn as CommentUpdateReservedFields, Rr as messages, Rt as DecryptedChallengeAnswerSchema, S as hasTransientNetworkErrorCode, Sn as RpcRemoteCommunityUpdateEventResultSchema, Sr as e$5, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Tr as t$12, Un as CreateCommentOptionsWithRefinementSchema, Ur as _enum, Ut as NameResolveCacheOptionsSchema, V as raceAgainstAbort, Vr as require_ms$1, Vt as DecryptedChallengeSchema, Wn as GetPageParamSchema, Wr as array, Wt as NameResolverSerializedSchema, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xr as object, Yr as number, Yt as CommunityEditPublicationChallengeRequestToEncryptSchema, Zr as preprocess, Zt as CommunityEditPublicationSignedPropertyNames, _n as CreateRpcCommunityFunctionArgumentSchema, an as CreateCommentModerationOptionsWithRefinementSchema, ar as ChallengeAnswersSchema, at as timestamp, bn as PageSortFileSchema, br as t$13, cr as CommunityAddressSchema, d as deepMergeRuntimeFields, dn as CommunityExportRecordsSchema, dr as JsonSignatureSchema, dt as findStartedCommunity, ei as union, en as CommentModerationChallengeRequestToEncryptSchema, er as CreateCommentEditOptionsWithRefinementSchema, et as shortifyAddress, f as derivePublicationFromChallengeRequest, fn as CommunityIpfsReservedFields, fr as PKCTimestampSchema, gn as CreateRemoteCommunityFunctionArgumentSchema, gr as n$9, h as fetchAndValidateIpnsRecordFromGateway, hn as CreateNewLocalCommunityUserOptionsSchema, hr as isStringDomain, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as throwIfAbortSignalAborted, jn as CommentIpfsSchema, jr as require_retry$2, jt as ChallengeAnswerMessageSignedPropertyNames, k as isIpns, kn as CommentChallengeRequestToEncryptSchema, kr as t$9, kt as pTimeout, ln as CommunityChallengeSettingSchema, lr as CommunityAuthorChallengeReservedFieldNames, m as extractNetworkErrorDetails, mn as CommunitySignedPropertyNames, mr as areEquivalentNames, mt as forgetTrackedUpdatingCommunityName, nr as AuthorCommentIpfsReservedFields, nt as sleepUntilTimeoutOrAbort, on as ChallengeFileFactorySchema, or as CidPathSchema, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pr as ProtocolVersionSchema, pt as findUpdatingCommunity, qn as isReservedObjectKey, qr as literal, qt as PKCUserOptionsSchema, r as calculateIpfsCidV0, rn as CommentModerationSignedPropertyNames, rr as AuthorPubsubSchema, sn as ChallengeFileSchema, sr as CidStringSchema, t as areEquivalentCommunityAddresses, tn as CommentModerationPubsubMessagePublicationSchema, tr as AuthorAddressSchema, tt as shortifyCid, u as createAbortError, un as CommunityEditOptionsSchema, ur as CreateSignerSchema, vn as ExportCommunityModLogsOptionsSchema, vr as n$10, w as interruptibleSleep, wn as VoteChallengeRequestToEncryptSchema, wr as r$8, wt as untrackStartedCommunity, xr as e$6, xt as trackStartedCommunity, yn as PageSortFileFactorySchema, yt as refreshTrackedCommunityAliases, z as pubsubTopicToDhtKey, zn as CommentUpdateSchema, zr as logger_default } from "./util-C6YaxADn.js";
2
+ import { $n as CommentEditSignedPropertyNames, $r as record, $t as CommunityEditPubsubMessagePublicationSchema, A as isIpnsPath, An as CommentChallengeRequestToEncryptSchema, Ar as t$9, At as pTimeout, B as pubsubTopicToDhtKey, Bn as CommentUpdateSchema, Br as logger_default, C as hideClassPrivateProps, Cn as RpcRemoteCommunityUpdateEventResultSchema, Cr as e$5, D as isIpfsCid, Dr as n$8, Dt as untrackUpdatingCommunity, E as isAbortError, En as VotePubsubMessagePublicationSchema, Er as t$12, Fn as CommentSignedPropertyNames, Fr as FailedToFetchCommunityFromGatewaysError, Gn as GetPageParamSchema, Gr as array, Gt as NameResolverSerializedSchema, H as raceAgainstAbort, Hr as require_ms$1, Ht as DecryptedChallengeSchema, In as CommentUpdateChallengeReservedFieldNames, Ir as FailedToFetchGenericIpfsFromGatewaysError, It as ChallengeRequestMessageSignedPropertyNames, Jn as isReservedObjectKey, Jr as literal, Jt as PKCUserOptionsSchema, Kn as ModQueuePageIpfsSchema, Kr as boolean, Kt as PKCParsedOptionsSchema, L as isRequestPubsubPublicationOfPost, Lr as FailedToFetchPageIpfsFromGatewaysError, Mn as CommentIpfsSchema, Mr as require_retry$2, Mt as ChallengeAnswerMessageSignedPropertyNames, Nr as FailedToFetchCommentIpfsFromGatewaysError, O as isIpfsPath, On as VoteSignedPropertyNames, Or as r$7, Ot as require_sha256$1, Pn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Pr as FailedToFetchCommentUpdateFromGatewaysError, Pt as ChallengeMessageSignedPropertyNames, Qr as preprocess, Qt as CommunityEditPublicationSignedPropertyNames, R as isRequestPubsubPublicationOfReply, Rn as CommentUpdateForChallengeVerificationSignedPropertyNames, Rr as PKCError, Rt as ChallengeVerificationMessageSignedPropertyNames, S as hasTransientNetworkErrorCode, Sr as e$6, St as trackStartedCommunity, T as ipnsNameToIpnsOverPubsubTopic, Tn as VoteChallengeRequestToEncryptSchema, Tr as r$8, Tt as untrackStartedCommunity, Ut as DecryptedChallengeVerificationSchema, Vn as CommentUpdateSignedPropertyNames, Vr as require_supports_color, Wn as CreateCommentOptionsWithRefinementSchema, Wr as _enum, Wt as NameResolveCacheOptionsSchema, Xr as number, Xt as CommunityEditPublicationChallengeRequestToEncryptSchema, Yn as CommentEditChallengeRequestToEncryptSchema, Yr as looseObject, Zn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Zr as object, _n as CreateRemoteCommunityFunctionArgumentSchema, _r as n$9, an as CommentModerationsTableRowSchema, ar as AuthorReservedFields, at as throwIfAbortSignalAborted, bn as PageSortFileFactorySchema, bt as refreshTrackedCommunityAliases, cn as ChallengeFileSchema, cr as CidStringSchema, d as deepMergeRuntimeFields, dn as CommunityEditOptionsSchema, dr as CreateSignerSchema, ei as string, en as CreateCommunityEditPublicationOptionsWithRefinementSchema, f as derivePublicationFromChallengeRequest, fn as CommunityExportRecordsSchema, fr as JsonSignatureSchema, ft as findStartedCommunity, gn as CreateNewLocalCommunityUserOptionsSchema, gr as isStringDomain, h as fetchAndValidateIpnsRecordFromGateway, hn as CommunitySignedPropertyNames, hr as areEquivalentNames, ht as forgetTrackedUpdatingCommunityName, in as CommentModerationSignedPropertyNames, ir as AuthorPubsubSchema, jn as CommentIpfsReservedFields, jr as e$4, k as isIpns, kr as t$10, lr as CommunityAddressSchema, m as extractNetworkErrorDetails, mn as CommunityIpfsSchema, mr as ProtocolVersionSchema, mt as findUpdatingCommunity, nn as CommentModerationPubsubMessagePublicationSchema, nr as AuthorAddressSchema, nt as shortifyCid, on as CreateCommentModerationOptionsWithRefinementSchema, or as ChallengeAnswersSchema, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsReservedFields, pr as PKCTimestampSchema, q as removeNullUndefinedEmptyObjectsValuesRecursively, qn as PageIpfsSchema, qr as custom, qt as PKCUserOptionBaseSchema, r as calculateIpfsCidV0, rr as AuthorCommentIpfsReservedFields, rt as sleepUntilTimeoutOrAbort, sn as ChallengeFileFactorySchema, sr as CidPathSchema, t as areEquivalentCommunityAddresses, ti as union, tn as CommentModerationChallengeRequestToEncryptSchema, tr as CreateCommentEditOptionsWithRefinementSchema, tt as shortifyAddress, u as createAbortError, un as CommunityChallengeSettingSchema, ur as CommunityAuthorChallengeReservedFieldNames, vn as CreateRpcCommunityFunctionArgumentSchema, w as interruptibleSleep, wn as CreateVoteUserOptionsWithRefinementSchema, wr as t$11, wt as trackUpdatingCommunity, xn as PageSortFileSchema, xr as t$13, yn as ExportCommunityModLogsOptionsSchema, yr as n$10, z as linkAbortSignals, zn as CommentUpdateReservedFields, zr as messages, zt as DecryptedChallengeAnswerSchema } from "./util-C5RiQF_G.js";
3
3
  import { t as all } from "./src-CYIMjhjK.js";
4
- import { s as validatePageSortFile } from "./page-sort-scoring-Bz65Z28_.js";
4
+ import { s as validatePageSortFile } from "./page-sort-scoring-DY7SvqJA.js";
5
5
  import { createHash } from "node:crypto";
6
6
  import { pathToFileURL } from "node:url";
7
7
  import dns from "node:dns";
@@ -118106,7 +118106,7 @@ async function moveCommunityDbToDeletedDirectory(communityAddress, pkc) {
118106
118106
  }
118107
118107
  async function createKuboRpcClient(kuboRpcClientOptions) {
118108
118108
  logger_default("pkc-js:pkc:createKuboRpcClient").trace("Creating a new kubo client on node with options", kuboRpcClientOptions);
118109
- const { create: CreateKuboRpcClient } = await import("./src-BsiPSkhv.js");
118109
+ const { create: CreateKuboRpcClient } = await import("./src-ltPxiZKf.js");
118110
118110
  const Agent$2 = typeof kuboRpcClientOptions.url === "string" && kuboRpcClientOptions.url.startsWith("https") || kuboRpcClientOptions?.protocol === "https" || kuboRpcClientOptions.url instanceof URL && kuboRpcClientOptions?.url?.protocol === "https:" || kuboRpcClientOptions.url?.toString()?.includes("https") ? Agent : Agent$1;
118111
118111
  const onehourMs = 1e3 * 60 * 60;
118112
118112
  return CreateKuboRpcClient({
@@ -148259,7 +148259,8 @@ var BaseClientsManager = class BaseClientsManager {
148259
148259
  }
148260
148260
  }
148261
148261
  async pubsubUnsubscribe(pubsubTopic, handler) {
148262
- for (const pubsubProviderUrl of t$13(this._pkc.clients.pubsubKuboRpcClients)) try {
148262
+ const libp2pJsProvidersWithTopic = t$13(this._pkc.clients.libp2pJsClients).filter((key) => this.pubsubProviderSubscriptions[key]?.includes(pubsubTopic));
148263
+ for (const pubsubProviderUrl of [...t$13(this._pkc.clients.pubsubKuboRpcClients), ...libp2pJsProvidersWithTopic]) try {
148263
148264
  await this.pubsubUnsubscribeOnProvider(pubsubTopic, pubsubProviderUrl, handler);
148264
148265
  } catch (e) {
148265
148266
  await this._pkc._stats.recordGatewayFailure(pubsubProviderUrl, "pubsub-unsubscribe");
@@ -149782,10 +149783,24 @@ var BasePagesClientsManager = class extends BaseClientsManager {
149782
149783
  const isFirstPage = Object.values(this._pages.pageCids).includes(pageCid) || e$5(this._pages.pageCids);
149783
149784
  const pageMaxSize = opts.pageMaxSize ? opts.pageMaxSize : this._pkc._memCaches.pagesMaxSize.get(this._calculatePageMaxSizeCacheKey(pageCid)) ? this._pkc._memCaches.pagesMaxSize.get(this._calculatePageMaxSizeCacheKey(pageCid)) : isFirstPage ? 1024 * 1024 : void 0;
149784
149785
  if (!pageMaxSize) throw Error("Failed to calculate max page size. Is this page cid under the correct community/comment?");
149785
- const destroySignal = this._pkc._getDestroyAbortSignal();
149786
- const signals = [opts.abortSignal, destroySignal].filter((s) => Boolean(s));
149787
- const combinedSignal = signals.length === 1 ? signals[0] : AbortSignal.any(signals);
149788
- throwIfAbortSignalAborted(combinedSignal);
149786
+ const linked = linkAbortSignals([opts.abortSignal, this._pkc._getDestroyAbortSignal()]);
149787
+ const combinedSignal = linked.signal;
149788
+ try {
149789
+ throwIfAbortSignalAborted(combinedSignal);
149790
+ return await this._fetchPageAfterSignalCombined({
149791
+ pageCid,
149792
+ log,
149793
+ pageMaxSize,
149794
+ isFirstPage,
149795
+ sortTypesFromPageCids,
149796
+ sortTypesFromMemcache,
149797
+ combinedSignal
149798
+ });
149799
+ } finally {
149800
+ linked.dispose();
149801
+ }
149802
+ }
149803
+ async _fetchPageAfterSignalCombined({ pageCid, log, pageMaxSize, isFirstPage, sortTypesFromPageCids, sortTypesFromMemcache, combinedSignal }) {
149789
149804
  let result;
149790
149805
  try {
149791
149806
  if (this._pkc._pkcRpcClient) result = await this._fetchPageWithRpc({
@@ -155371,6 +155386,7 @@ function computePageSortsFingerprint({ pagesSettings, resolved, factories }) {
155371
155386
  }) ?? "");
155372
155387
  }
155373
155388
  const describePageSort = (pageSortSettings) => pageSortSettings.name || pageSortSettings.path || "unknown page sort";
155389
+ const resolveSortName = ({ pageSortSettings, file }) => pageSortSettings.sortName ?? file.sortName;
155374
155390
  async function loadPageSortFile({ pageSortSettings, pkc }) {
155375
155391
  let factory;
155376
155392
  try {
@@ -155415,11 +155431,15 @@ function withoutRemovedPageSortSettingOptions(pageSortSettings) {
155415
155431
  };
155416
155432
  }
155417
155433
  function resolveOneEntry({ pageSortSettings, file, scope, pageSortIndex }) {
155434
+ const sortName = resolveSortName({
155435
+ pageSortSettings,
155436
+ file
155437
+ });
155418
155438
  const baseDetails = {
155419
155439
  scope,
155420
155440
  pageSortIndex,
155421
155441
  pageSortName: describePageSort(pageSortSettings),
155422
- sortName: file.sortName
155442
+ sortName
155423
155443
  };
155424
155444
  const entryOptions = pageSortSettings.options ?? {};
155425
155445
  if (file.scope && file.scope !== scope) return { error: new PKCError("ERR_PAGE_SORT_SCOPE_MISMATCH", {
@@ -155476,7 +155496,7 @@ function resolveOneEntry({ pageSortSettings, file, scope, pageSortIndex }) {
155476
155496
  }
155477
155497
  return { resolved: {
155478
155498
  ...reserved,
155479
- sortName: file.sortName,
155499
+ sortName,
155480
155500
  scope,
155481
155501
  file,
155482
155502
  settings: pageSortSettings,
@@ -155512,7 +155532,11 @@ async function resolvePageSortsAndCollectFailures({ pagesSettings, pkc, tolerate
155512
155532
  });
155513
155533
  continue;
155514
155534
  }
155515
- if (seenSortNames.has(file.sortName)) {
155535
+ const sortName = resolveSortName({
155536
+ pageSortSettings,
155537
+ file
155538
+ });
155539
+ if (seenSortNames.has(sortName)) {
155516
155540
  failures.push({
155517
155541
  scope,
155518
155542
  pageSortIndex,
@@ -155521,12 +155545,12 @@ async function resolvePageSortsAndCollectFailures({ pagesSettings, pkc, tolerate
155521
155545
  scope,
155522
155546
  pageSortIndex,
155523
155547
  pageSortName,
155524
- sortName: file.sortName
155548
+ sortName
155525
155549
  })
155526
155550
  });
155527
155551
  continue;
155528
155552
  }
155529
- seenSortNames.add(file.sortName);
155553
+ seenSortNames.add(sortName);
155530
155554
  const result = resolveOneEntry({
155531
155555
  pageSortSettings,
155532
155556
  file,
@@ -155910,12 +155934,19 @@ function cloneExportRecord(record) {
155910
155934
  ...record.error ? { error: { ...record.error } } : {}
155911
155935
  };
155912
155936
  }
155937
+ function isTerminalExportRecord(record) {
155938
+ return record.progress === 1 || Boolean(record.error);
155939
+ }
155913
155940
  var RpcLocalCommunity = class extends RpcRemoteCommunity {
155914
155941
  constructor(pkc) {
155915
155942
  super(pkc);
155916
155943
  this.raw = {};
155917
155944
  this._startRpcSubscriptionId = void 0;
155918
155945
  this._exportsSubscriptionId = void 0;
155946
+ this._exportsSubscriptionManaged = false;
155947
+ this._exportsSubscriptionSyncQueue = Promise.resolve();
155948
+ this._pendingExportCalls = 0;
155949
+ this._inFlightExportIds = /* @__PURE__ */ new Set();
155919
155950
  this._exportsCache = [];
155920
155951
  this._exportSignalDetachers = /* @__PURE__ */ new Map();
155921
155952
  this.started = false;
@@ -155926,6 +155957,13 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
155926
155957
  this.on("update", () => {
155927
155958
  this.editable = t$2(this, t$13(CommunityEditOptionsSchema.shape));
155928
155959
  });
155960
+ this.on("statechange", () => this._scheduleExportsSubscriptionSync());
155961
+ const emitter = this;
155962
+ const onListenerChange = (eventName) => {
155963
+ if (eventName === "exportschange") this._scheduleExportsSubscriptionSync();
155964
+ };
155965
+ emitter.on("newListener", onListenerChange);
155966
+ emitter.on("removeListener", onListenerChange);
155929
155967
  hideClassPrivateProps(this);
155930
155968
  }
155931
155969
  toJSONInternalRpcAfterFirstUpdate() {
@@ -156116,6 +156154,7 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
156116
156154
  this._setRpcClientStateWithEmission("stopped");
156117
156155
  this.started = false;
156118
156156
  untrackStartedCommunity(this._pkc, this);
156157
+ await this._releaseExportsSubscriptionIfUnneeded();
156119
156158
  }
156120
156159
  async prepareAnchorPublish() {
156121
156160
  return this._pkc._pkcRpcClient.prepareAnchorPublish({
@@ -156133,6 +156172,17 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
156133
156172
  return result;
156134
156173
  }
156135
156174
  async stop() {
156175
+ await this._stopRunOrUpdate();
156176
+ await this._releaseExportsSubscriptionIfUnneeded();
156177
+ }
156178
+ async _releaseExportsSubscriptionIfUnneeded() {
156179
+ try {
156180
+ await this._syncExportsSubscription();
156181
+ } catch (e) {
156182
+ logger_default("pkc-js:rpc-local-community:exports").error("Failed to sync the exports subscription on stop", this.address, e);
156183
+ }
156184
+ }
156185
+ async _stopRunOrUpdate() {
156136
156186
  this.posts._stop();
156137
156187
  if (this.state === "updating") return super.stop();
156138
156188
  else if (this.state === "started") {
@@ -156188,12 +156238,24 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
156188
156238
  async export(options = {}) {
156189
156239
  if (options.exportPath !== void 0) throw new PKCError("ERR_EXPORT_PATH_NOT_SUPPORTED_OVER_RPC", { address: this.address });
156190
156240
  if (options.signal?.aborted) throw options.signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
156191
- const { exportId } = await this._pkc._pkcRpcClient.exportCommunity({
156192
- name: this.name,
156193
- publicKey: this.publicKey,
156194
- includePrivateKey: options.includePrivateKey
156195
- });
156196
- if (options.signal) {
156241
+ this._pendingExportCalls++;
156242
+ let exportId;
156243
+ let alreadyTerminal = false;
156244
+ try {
156245
+ await this._syncExportsSubscription();
156246
+ ({exportId} = await this._pkc._pkcRpcClient.exportCommunity({
156247
+ name: this.name,
156248
+ publicKey: this.publicKey,
156249
+ includePrivateKey: options.includePrivateKey
156250
+ }));
156251
+ const knownRecord = this._exportsCache.find((rec) => rec.exportId === exportId);
156252
+ alreadyTerminal = knownRecord !== void 0 && isTerminalExportRecord(knownRecord);
156253
+ if (!alreadyTerminal) this._inFlightExportIds.add(exportId);
156254
+ } finally {
156255
+ this._pendingExportCalls--;
156256
+ this._scheduleExportsSubscriptionSync();
156257
+ }
156258
+ if (options.signal && !alreadyTerminal) {
156197
156259
  const userSignal = options.signal;
156198
156260
  const onAbort = () => {
156199
156261
  this._pkc._pkcRpcClient.cancelExport({ exportId }).catch((e) => {
@@ -156215,6 +156277,38 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
156215
156277
  ...opts
156216
156278
  });
156217
156279
  }
156280
+ async _loadExportsSnapshot() {
156281
+ this._exportsSubscriptionManaged = true;
156282
+ await this._syncExportsSubscription({ loadSnapshot: true });
156283
+ }
156284
+ _needsLiveExports() {
156285
+ if (this._pkc.destroyed) return false;
156286
+ return this.state !== "stopped" || this._pendingExportCalls > 0 || this._inFlightExportIds.size > 0 || this.listenerCount("exportschange") > 0;
156287
+ }
156288
+ _syncExportsSubscription(opts) {
156289
+ const run = async () => {
156290
+ if (!this._exportsSubscriptionManaged) return;
156291
+ if ((this._needsLiveExports() || opts?.loadSnapshot) && this._exportsSubscriptionId === void 0 && !this._pkc.destroyed) await this._attachExportsSubscription();
156292
+ if (!this._needsLiveExports() && this._exportsSubscriptionId !== void 0) await this._detachExportsSubscription();
156293
+ };
156294
+ const result = this._exportsSubscriptionSyncQueue.then(run);
156295
+ this._exportsSubscriptionSyncQueue = result.catch(() => void 0);
156296
+ return result;
156297
+ }
156298
+ _scheduleExportsSubscriptionSync() {
156299
+ if (!this._exportsSubscriptionManaged) return;
156300
+ this._syncExportsSubscription().catch((e) => logger_default("pkc-js:rpc-local-community:exports").error("Failed to sync the exports subscription", this.address, e));
156301
+ }
156302
+ async _detachExportsSubscription() {
156303
+ const subscriptionId = this._exportsSubscriptionId;
156304
+ this._exportsSubscriptionId = void 0;
156305
+ if (subscriptionId === void 0) return;
156306
+ try {
156307
+ await this._pkc._pkcRpcClient.unsubscribe(subscriptionId);
156308
+ } catch (e) {
156309
+ logger_default("pkc-js:rpc-local-community:exports").error("Failed to unsubscribe from exportsSubscribe", this.address, e);
156310
+ }
156311
+ }
156218
156312
  async _attachExportsSubscription() {
156219
156313
  if (this._exportsSubscriptionId !== void 0) return;
156220
156314
  if (!this._pkc._pkcRpcClient) return;
@@ -156246,7 +156340,12 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
156246
156340
  }
156247
156341
  });
156248
156342
  this._pkc._pkcRpcClient.emitAllPendingMessages(subscriptionId);
156249
- await initialReceived;
156343
+ try {
156344
+ await initialReceived;
156345
+ } catch (e) {
156346
+ if (this._exportsSubscriptionId === subscriptionId) await this._detachExportsSubscription();
156347
+ throw e;
156348
+ }
156250
156349
  }
156251
156350
  _absorbExportRecords(wireRecords) {
156252
156351
  const httpOrigin = this._pkc._pkcRpcClient.rpcHttpOrigin;
@@ -156264,7 +156363,16 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
156264
156363
  this._exportSignalDetachers.delete(rec.exportId);
156265
156364
  }
156266
156365
  }
156366
+ let inFlightChanged = false;
156367
+ for (const exportId of [...this._inFlightExportIds]) {
156368
+ const rec = wireRecords.find((r) => r.exportId === exportId);
156369
+ if (!rec || isTerminalExportRecord(rec)) {
156370
+ this._inFlightExportIds.delete(exportId);
156371
+ inFlightChanged = true;
156372
+ }
156373
+ }
156267
156374
  this.emit("exportschange", this._exportsCache.map(cloneExportRecord));
156375
+ if (inFlightChanged) this._scheduleExportsSubscriptionSync();
156268
156376
  }
156269
156377
  async delete() {
156270
156378
  const startedCommunity = findStartedCommunity(this._pkc, {