@pkcprotocol/pkc-js 0.0.127 → 0.0.128

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 (47) hide show
  1. package/dist/browser/clients/base-client-manager.d.ts +8 -0
  2. package/dist/browser/clients/base-client-manager.js +39 -2
  3. package/dist/browser/clients/base-client-manager.js.map +1 -1
  4. package/dist/browser/community/community-client-manager.js +2 -1
  5. package/dist/browser/community/community-client-manager.js.map +1 -1
  6. package/dist/browser/generated-version.d.ts +1 -1
  7. package/dist/browser/generated-version.js +1 -1
  8. package/dist/browser/helia/helia-for-pkc.js +88 -22
  9. package/dist/browser/helia/helia-for-pkc.js.map +1 -1
  10. package/dist/browser/helia/types.d.ts +4 -1
  11. package/dist/browser/publications/comment/comment-client-manager.d.ts +5 -2
  12. package/dist/browser/publications/comment/comment-client-manager.js +104 -40
  13. package/dist/browser/publications/comment/comment-client-manager.js.map +1 -1
  14. package/dist/browser/publications/comment/comment.d.ts +4 -0
  15. package/dist/browser/publications/comment/comment.js +4 -0
  16. package/dist/browser/publications/comment/comment.js.map +1 -1
  17. package/dist/bundled/bundle-manifest.json +52 -52
  18. package/dist/bundled/challenges.js +1 -1
  19. package/dist/bundled/chunks/{helia-for-pkc-BsXEDYPa.js → helia-for-pkc-6kkeZX1a.js} +96 -42
  20. package/dist/bundled/chunks/{local-community-WFQoW5aC.js → local-community-B79BAYRo.js} +3 -3
  21. package/dist/bundled/chunks/{local-community-FekHR-fd.js → local-community-BST1U_f3.js} +1 -1
  22. package/dist/bundled/chunks/{node-pIjburtc.js → node-BEH8NA_I.js} +108 -32
  23. package/dist/bundled/chunks/{page-sort-scoring-Civ7TOoF.js → page-sort-scoring-2FkqYYNf.js} +1 -1
  24. package/dist/bundled/chunks/{rpc-local-community-BqP9g2Rk.js → rpc-local-community-SmLDPm1j.js} +35 -5
  25. package/dist/bundled/chunks/{util-VrWyIc1x.js → util-LwSS90AE.js} +1 -1
  26. package/dist/bundled/chunks/{util-D5Y6i3Nn.js → util-jyIDYw_Q.js} +1 -1
  27. package/dist/bundled/chunks/{validate-package-factories-CJgjDTZC.js → validate-package-factories-_KKnb8At.js} +2 -2
  28. package/dist/bundled/index.js +1 -1
  29. package/dist/bundled/page-sorts.js +1 -1
  30. package/dist/bundled/rpc/src/index.js +4 -4
  31. package/dist/node/clients/base-client-manager.d.ts +8 -0
  32. package/dist/node/clients/base-client-manager.js +39 -2
  33. package/dist/node/clients/base-client-manager.js.map +1 -1
  34. package/dist/node/community/community-client-manager.js +2 -1
  35. package/dist/node/community/community-client-manager.js.map +1 -1
  36. package/dist/node/generated-version.d.ts +1 -1
  37. package/dist/node/generated-version.js +1 -1
  38. package/dist/node/helia/helia-for-pkc.js +88 -22
  39. package/dist/node/helia/helia-for-pkc.js.map +1 -1
  40. package/dist/node/helia/types.d.ts +4 -1
  41. package/dist/node/publications/comment/comment-client-manager.d.ts +5 -2
  42. package/dist/node/publications/comment/comment-client-manager.js +104 -40
  43. package/dist/node/publications/comment/comment-client-manager.js.map +1 -1
  44. package/dist/node/publications/comment/comment.d.ts +4 -0
  45. package/dist/node/publications/comment/comment.js +4 -0
  46. package/dist/node/publications/comment/comment.js.map +1 -1
  47. package/package.json +1 -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, It as ChallengeVerificationMessageSchema, J as removeUndefinedValuesRecursively, Jt as version_default, Lr as PKCError, Mr as FailedToFetchCommentIpfsFromGatewaysError, Mt as ChallengeMessageSchema, Nn as CommentIpfsSchema, Nr as FailedToFetchCommentUpdateFromGatewaysError, Ot as TimeoutError, Pt as ChallengeRequestMessageSchema, Q as retryKuboIpfsAdd, Rn as CommentUpdateForChallengeVerificationSchema, Rr as messages, Sr as e$1, St as trackUpdatingComment, T as ipnsNameToIpnsOverPubsubTopic, Tt as untrackUpdatingComment, U as rejectWhenCommunityStopsOrAborts, Vn as CommentUpdateSchema, 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, ht as listStartedCommunities, i as calculateStringSizeSameAsIpfsAddCidV0, it as throwIfAbortSignalAborted, jr as require_retry, 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, t as areEquivalentCommunityAddresses, tt as shortifyCid, u as createAbortError, vr as n$1, vt as refreshTrackedCommentAliases, wn as isStringDomain, wr as r, x as getPostUpdateTimestampRange, xn as PubsubTopicSchema, xr as e, zr as logger_default } from "./util-VrWyIc1x.js";
3
- import { $n as getCommunityAddressFromRecord, $t as RpcPublishCommunityListResultSchema, A as findCommentInParsedPages, An as verifyChallengeMessage, Ar as t$5, At as parseRpcCommentUpdateEventWithPKCErrorIfItFails, B as GenericStateClient, Bn as verifyCommunityList, Br as NAME_RESOLVED_FALSE_TTL_MS, Bt as RpcCommunityPageParamSchema, C as RepliesPages, Cr as listCommunitiesSync, Ct as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, D as extractCommunityRuntimeFieldsFromParsedPages, Dn as signCommunityList, Dt as parseJsonWithPKCErrorIfFails, En as signCommunityEdit, Et as parseDecryptedChallengeWithPKCErrorIfItFails, F as cloneCrosspostForRuntime, Fn as verifyCommentModeration, Ft as RpcAuthorNameParamSchema, G as PKCTypedEmitter, Gn as getAuthorNameFromWire, Gr as nativeFunctions$2, Gt as RpcExportCommunityResultSchema, H as InflightResourceTypes, Hn as buildRuntimeAuthor, Hr as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, Ht as RpcExportCommunityModLogsParamSchema, I as collectCrosspostAuthorsToResolve, In as verifyCommentPubsubMessage, Ir as t$2, It as RpcCancelExportParamSchema, J as decodeRpcChallengeRequestPubsubMsg, Jn as CreateNewCommunityListOptionsSchema, Jt as RpcFetchCommunityListParamSchema, K as decodeRpcChallengeAnswerPubsubMsg, Kn as normalizeCreatePublicationAuthor, Kr as require_undici, Kt as RpcFetchCidParamSchema, Ln as verifyCommentUpdate, Lr as t$4, Lt as RpcCidParamSchema, M as parseRawPages, Mn as verifyChallengeVerification, Nn as verifyCommentEdit, Nr as t$3, Nt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, O as findCommentInPageInstance, On as signVote, Or as setNativeFunctions$1, Ot as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, P as applyNameResolvedCacheToCrosspost, Pn as verifyCommentIpfs, Pr as n$3, Pt as RpcAnchorPublishPreparationResultSchema, Qn as buildRuntimeCommunityFields, Qt as RpcPublishCommunityListParamSchema, R as stripNameResolvedFromCrosspost, Rt as RpcCommentRepliesPageParamSchema, Sn as signCommentModeration, St as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, Tt as parseDecryptedChallengeVerification, Un as cleanWireAuthor, Ut as RpcExportCommunityModLogsResultSchema, V as InflightFetchManager, Vn as verifyVote, Vr as NAME_RESOLVED_TRUE_TTL_MS, Vt as RpcEditCommunityParamSchema, Wn as getAuthorNameFromRuntime, Wt as RpcExportCommunityParamSchema, Xt as RpcPublishAnchorRecordParamSchema, Y as decodeRpcChallengeVerificationPubsubMsg, Yn as MAX_COMMUNITY_LIST_SIZE_BYTES, Yt as RpcFetchCommunityListResultSchema, Zt as RpcPublishChallengeAnswersParamSchema, _t as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, an as findCommunityRecordNameMismatch, ar as getBufferedPKCAddressFromPublicKey, b as KeyvBetterSqlite3, bn as signComment, br as getDefaultDataPath, cn as createSigner, cr as getPKCAddressFromPublicKeySync, ct as parseCommentUpdateSchemaWithPKCErrorIfItFails, en as RpcPublishedAnchorRecordResultSchema, er as getCommunityNameFromWire, et as parseCidStringSchemaWithPKCErrorIfItFails, fn as encryptEd25519AesGcm, ft as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, gn as signChallengeAnswer, gt as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, hn as cleanUpBeforePublishing, ht as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, in as RpcUnsubscribeParamSchema, it as parseCommentIpfsSchemaWithPKCErrorIfItFails, jt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, k as findCommentInPageInstanceRecursively, kr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, kt as parseRpcCommentEventWithPKCErrorIfItFails, l as pkcJsPageSorts, ln as createAnchorIpnsRecord$1, lt as parseCommunityAddressWithPKCErrorIfItFails, m as pkcJsChallenges, mr as createKuboRpcClient, mt as parseCommunityListSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as RpcSubscriptionIdResultSchema, nr as normalizeCommunityInputFromCommunity, on as require_lib$1, ot as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, q as decodeRpcChallengePubsubMsg, qn as CreateCommunityListWithCidOptionsSchema, qt as RpcFetchCidResultSchema, rn as RpcSuccessResultSchema, rr as decode, rt as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, st as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, t as RpcLocalCommunity, tn as RpcResolveAuthorNameResultSchema, tr as getCommunityPublicKeyFromWire, un as decryptEd25519AesGcm, v as TrackedInstanceRegistry, vn as signChallengeRequest, vt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, wr as monitorCommunitiesDirectory, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, x as RemoteCommunity, xn as signCommentEdit, xt as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, y as LRUCache, z as PKCClientsManager, zn as verifyCommunityEdit, zr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, zt as RpcCommunityIdentifierParamSchema } from "./rpc-local-community-BqP9g2Rk.js";
4
- import { s as getHeliaDebugContext } from "./util-D5Y6i3Nn.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, It as ChallengeVerificationMessageSchema, J as removeUndefinedValuesRecursively, Jt as version_default, Lr as PKCError, Mr as FailedToFetchCommentIpfsFromGatewaysError, Mt as ChallengeMessageSchema, Nn as CommentIpfsSchema, Nr as FailedToFetchCommentUpdateFromGatewaysError, Ot as TimeoutError, Pt as ChallengeRequestMessageSchema, Q as retryKuboIpfsAdd, Rn as CommentUpdateForChallengeVerificationSchema, Rr as messages, Sr as e$1, St as trackUpdatingComment, T as ipnsNameToIpnsOverPubsubTopic, Tt as untrackUpdatingComment, U as rejectWhenCommunityStopsOrAborts, Vn as CommentUpdateSchema, 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, ht as listStartedCommunities, i as calculateStringSizeSameAsIpfsAddCidV0, it as throwIfAbortSignalAborted, jr as require_retry, 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, t as areEquivalentCommunityAddresses, tt as shortifyCid, u as createAbortError, vr as n$1, vt as refreshTrackedCommentAliases, wn as isStringDomain, wr as r, x as getPostUpdateTimestampRange, xn as PubsubTopicSchema, xr as e, zr as logger_default } from "./util-LwSS90AE.js";
3
+ import { $n as getCommunityAddressFromRecord, $t as RpcPublishCommunityListResultSchema, A as findCommentInParsedPages, An as verifyChallengeMessage, Ar as t$5, At as parseRpcCommentUpdateEventWithPKCErrorIfItFails, B as GenericStateClient, Bn as verifyCommunityList, Br as NAME_RESOLVED_FALSE_TTL_MS, Bt as RpcCommunityPageParamSchema, C as RepliesPages, Cr as listCommunitiesSync, Ct as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, D as extractCommunityRuntimeFieldsFromParsedPages, Dn as signCommunityList, Dt as parseJsonWithPKCErrorIfFails, En as signCommunityEdit, Et as parseDecryptedChallengeWithPKCErrorIfItFails, F as cloneCrosspostForRuntime, Fn as verifyCommentModeration, Ft as RpcAuthorNameParamSchema, G as PKCTypedEmitter, Gn as getAuthorNameFromWire, Gr as nativeFunctions$2, Gt as RpcExportCommunityResultSchema, H as InflightResourceTypes, Hn as buildRuntimeAuthor, Hr as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, Ht as RpcExportCommunityModLogsParamSchema, I as collectCrosspostAuthorsToResolve, In as verifyCommentPubsubMessage, Ir as t$2, It as RpcCancelExportParamSchema, J as decodeRpcChallengeRequestPubsubMsg, Jn as CreateNewCommunityListOptionsSchema, Jt as RpcFetchCommunityListParamSchema, K as decodeRpcChallengeAnswerPubsubMsg, Kn as normalizeCreatePublicationAuthor, Kr as require_undici, Kt as RpcFetchCidParamSchema, Ln as verifyCommentUpdate, Lr as t$4, Lt as RpcCidParamSchema, M as parseRawPages, Mn as verifyChallengeVerification, Nn as verifyCommentEdit, Nr as t$3, Nt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, O as findCommentInPageInstance, On as signVote, Or as setNativeFunctions$1, Ot as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, P as applyNameResolvedCacheToCrosspost, Pn as verifyCommentIpfs, Pr as n$3, Pt as RpcAnchorPublishPreparationResultSchema, Qn as buildRuntimeCommunityFields, Qt as RpcPublishCommunityListParamSchema, R as stripNameResolvedFromCrosspost, Rt as RpcCommentRepliesPageParamSchema, Sn as signCommentModeration, St as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, Tt as parseDecryptedChallengeVerification, Un as cleanWireAuthor, Ut as RpcExportCommunityModLogsResultSchema, V as InflightFetchManager, Vn as verifyVote, Vr as NAME_RESOLVED_TRUE_TTL_MS, Vt as RpcEditCommunityParamSchema, Wn as getAuthorNameFromRuntime, Wt as RpcExportCommunityParamSchema, Xt as RpcPublishAnchorRecordParamSchema, Y as decodeRpcChallengeVerificationPubsubMsg, Yn as MAX_COMMUNITY_LIST_SIZE_BYTES, Yt as RpcFetchCommunityListResultSchema, Zt as RpcPublishChallengeAnswersParamSchema, _t as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, an as findCommunityRecordNameMismatch, ar as getBufferedPKCAddressFromPublicKey, b as KeyvBetterSqlite3, bn as signComment, br as getDefaultDataPath, cn as createSigner, cr as getPKCAddressFromPublicKeySync, ct as parseCommentUpdateSchemaWithPKCErrorIfItFails, en as RpcPublishedAnchorRecordResultSchema, er as getCommunityNameFromWire, et as parseCidStringSchemaWithPKCErrorIfItFails, fn as encryptEd25519AesGcm, ft as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, gn as signChallengeAnswer, gt as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, hn as cleanUpBeforePublishing, ht as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, in as RpcUnsubscribeParamSchema, it as parseCommentIpfsSchemaWithPKCErrorIfItFails, jt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, k as findCommentInPageInstanceRecursively, kr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, kt as parseRpcCommentEventWithPKCErrorIfItFails, l as pkcJsPageSorts, ln as createAnchorIpnsRecord$1, lt as parseCommunityAddressWithPKCErrorIfItFails, m as pkcJsChallenges, mr as createKuboRpcClient, mt as parseCommunityListSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as RpcSubscriptionIdResultSchema, nr as normalizeCommunityInputFromCommunity, on as require_lib$1, ot as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, q as decodeRpcChallengePubsubMsg, qn as CreateCommunityListWithCidOptionsSchema, qt as RpcFetchCidResultSchema, rn as RpcSuccessResultSchema, rr as decode, rt as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, st as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, t as RpcLocalCommunity, tn as RpcResolveAuthorNameResultSchema, tr as getCommunityPublicKeyFromWire, un as decryptEd25519AesGcm, v as TrackedInstanceRegistry, vn as signChallengeRequest, vt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, wr as monitorCommunitiesDirectory, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, x as RemoteCommunity, xn as signCommentEdit, xt as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, y as LRUCache, z as PKCClientsManager, zn as verifyCommunityEdit, zr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, zt as RpcCommunityIdentifierParamSchema } from "./rpc-local-community-SmLDPm1j.js";
4
+ import { s as getHeliaDebugContext } from "./util-jyIDYw_Q.js";
5
5
  import path from "path";
6
6
  import assert from "assert";
7
7
  import fs from "fs";
@@ -1560,24 +1560,78 @@ var CommentClientsManager = class extends PublicationClientsManager {
1560
1560
  if ("_helia" in kuboRpcOrHelia) this.updateLibp2pJsClientState(newState, kuboRpcOrHelia._libp2pJsClientsOptions.key);
1561
1561
  else this.updateKuboRpcState(newState, kuboRpcOrHelia.url);
1562
1562
  }
1563
- async _fetchPostCommentUpdateIpfsP2P(subIpns, timestampRanges, log) {
1563
+ async _isPostUpdateFileAlreadyJudged(folderCid, path, log, abortSignal) {
1564
+ const judged = this._comment._lastJudgedPostUpdate;
1565
+ if (judged?.path === path) return {
1566
+ alreadyJudged: true,
1567
+ cid: judged.cid
1568
+ };
1569
+ const cid = await this._resolveIpfsPathToCid({
1570
+ root: folderCid,
1571
+ path: path.slice(folderCid.length + 1),
1572
+ timeoutMs: this._pkc._timeouts["comment-update-ipfs"],
1573
+ abortSignal,
1574
+ log,
1575
+ bitswapSessionSeedScopeIpnsPubsubTopic: this._bitswapSessionSeedScopeIpnsPubsubTopic()
1576
+ });
1577
+ if (cid === void 0 || cid !== judged?.cid) return {
1578
+ alreadyJudged: false,
1579
+ cid
1580
+ };
1581
+ this._comment._lastJudgedPostUpdate = {
1582
+ path,
1583
+ cid
1584
+ };
1585
+ return {
1586
+ alreadyJudged: true,
1587
+ cid
1588
+ };
1589
+ }
1590
+ _markRecordPostUpdateJudgedIfItsPagesHoldTheHeldUpdate(community) {
1591
+ const record = community.raw.communityIpfs;
1592
+ const postCid = this._comment.postCid;
1593
+ const heldUpdatedAt = this._comment.raw?.commentUpdate?.updatedAt;
1594
+ if (!record?.postUpdates || !postCid || !this._comment.cid || typeof this._comment.timestamp !== "number") return false;
1595
+ const inRecordPages = findCommentInPageInstance(community.posts, this._comment.cid);
1596
+ if (!inRecordPages || inRecordPages.commentUpdate.updatedAt !== heldUpdatedAt) return false;
1597
+ const [timestampRange] = getPostUpdateTimestampRange(record.postUpdates, this._comment.timestamp);
1598
+ if (!timestampRange) return false;
1599
+ const path = this._calculatePathForPostCommentUpdate(record.postUpdates[timestampRange], postCid);
1600
+ if (this._comment._lastJudgedPostUpdate?.path !== path) this._comment._lastJudgedPostUpdate = {
1601
+ path,
1602
+ cid: void 0
1603
+ };
1604
+ return true;
1605
+ }
1606
+ _isNotNewerThanHeldCommentUpdate(commentUpdate) {
1607
+ return commentUpdate.updatedAt <= (this._comment.raw?.commentUpdate?.updatedAt || 0);
1608
+ }
1609
+ async _fetchPostCommentUpdateIpfsP2P(subIpns, timestampRanges, log, abortSignal) {
1564
1610
  const attemptedPathsToLoadErrors = {};
1565
1611
  const kuboRpcOrHelia = this.getDefaultKuboRpcClientOrHelia();
1566
- if (timestampRanges.some((timestampRange) => {
1567
- if (!this._comment._commentUpdateIpfsPath) return false;
1568
- return subIpns.postUpdates[timestampRange] === this._comment._commentUpdateIpfsPath.split("/")[0];
1569
- })) {
1570
- log("Comment", this._comment.cid, "last post update range has same folder cid", this._comment._commentUpdateIpfsPath, "will be skipping loading CommentUpdate");
1571
- return;
1572
- }
1573
- this._comment._setUpdatingStateWithEmissionIfNewState("fetching-update-ipfs");
1574
1612
  for (const timestampRange of timestampRanges) {
1575
1613
  const folderCid = subIpns.postUpdates[timestampRange];
1576
1614
  const path = this._calculatePathForPostCommentUpdate(folderCid, this._comment.postCid);
1615
+ throwIfAbortSignalAborted(abortSignal);
1616
+ let judgedLookup;
1617
+ try {
1618
+ judgedLookup = await this._isPostUpdateFileAlreadyJudged(folderCid, path, log, abortSignal);
1619
+ } catch (e) {
1620
+ throwIfAbortSignalAborted(abortSignal);
1621
+ log.trace(`Timed out resolving CommentUpdate path (${path}) with IPFS P2P. Trying the next timestamp range`);
1622
+ attemptedPathsToLoadErrors[path] = e;
1623
+ continue;
1624
+ }
1625
+ const { alreadyJudged, cid } = judgedLookup;
1626
+ throwIfAbortSignalAborted(abortSignal);
1627
+ if (alreadyJudged) {
1628
+ log.trace("Comment", this._comment.cid, "already judged the CommentUpdate at", path, "skipping it");
1629
+ return;
1630
+ }
1631
+ this._comment._setUpdatingStateWithEmissionIfNewState("fetching-update-ipfs");
1577
1632
  this._updateKuboRpcClientOrHeliaState("fetching-update-ipfs", kuboRpcOrHelia);
1578
1633
  let res;
1579
1634
  const commentUpdateTimeoutMs = this._pkc._timeouts["comment-update-ipfs"];
1580
- const abortSignal = this._combinedAbortSignalForRetry();
1581
1635
  try {
1582
1636
  res = await this._retryTransientP2PFetch(() => this._fetchCidP2P(path, {
1583
1637
  maxFileSizeBytes: MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE,
@@ -1590,6 +1644,7 @@ var CommentClientsManager = class extends PublicationClientsManager {
1590
1644
  context: `post-update ${path}`
1591
1645
  });
1592
1646
  } catch (e) {
1647
+ throwIfAbortSignalAborted(abortSignal);
1593
1648
  log.trace(`Failed to fetch CommentUpdate from path (${path}) with IPFS P2P. Trying the next timestamp range`);
1594
1649
  attemptedPathsToLoadErrors[path] = e;
1595
1650
  continue;
@@ -1598,13 +1653,23 @@ var CommentClientsManager = class extends PublicationClientsManager {
1598
1653
  }
1599
1654
  try {
1600
1655
  const commentUpdate = parseCommentUpdateSchemaWithPKCErrorIfItFails(parseJsonWithPKCErrorIfFails(res));
1656
+ if (this._isNotNewerThanHeldCommentUpdate(commentUpdate)) {
1657
+ this._comment._lastJudgedPostUpdate = {
1658
+ path,
1659
+ cid
1660
+ };
1661
+ this._logIgnoredNotNewerPostCommentUpdate(log, path, commentUpdate);
1662
+ return;
1663
+ }
1601
1664
  await this._throwIfCommentUpdateHasInvalidSignature(commentUpdate, subIpns);
1602
- if (commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) return {
1665
+ this._comment._lastJudgedPostUpdate = {
1666
+ path,
1667
+ cid
1668
+ };
1669
+ return {
1603
1670
  commentUpdate,
1604
1671
  commentUpdateIpfsPath: path
1605
1672
  };
1606
- this._logIgnoredNotNewerPostCommentUpdate(log, path, commentUpdate);
1607
- return;
1608
1673
  } catch (e) {
1609
1674
  this._comment._invalidCommentUpdateMfsPaths.add(path);
1610
1675
  if (e instanceof PKCError) e.details = {
@@ -1659,14 +1724,7 @@ var CommentClientsManager = class extends PublicationClientsManager {
1659
1724
  verifyOptions
1660
1725
  });
1661
1726
  }
1662
- async _fetchPostCommentUpdateFromGateways(subIpns, timestampRanges, log) {
1663
- if (timestampRanges.some((timestampRange) => {
1664
- if (!this._comment._commentUpdateIpfsPath) return false;
1665
- return subIpns.postUpdates[timestampRange] === this._comment._commentUpdateIpfsPath.split("/")[0];
1666
- })) {
1667
- log("Comment", this._comment.cid, "last post update range has same folder cid", this._comment._commentUpdateIpfsPath, "will be skipping loading CommentUpdate");
1668
- return;
1669
- }
1727
+ async _fetchPostCommentUpdateFromGateways(subIpns, timestampRanges, log, abortSignal) {
1670
1728
  const attemptedPathsToLoadErrors = {};
1671
1729
  let commentUpdate;
1672
1730
  const validateCommentFromGateway = async (res) => {
@@ -1675,10 +1733,17 @@ var CommentClientsManager = class extends PublicationClientsManager {
1675
1733
  await this._throwIfCommentUpdateHasInvalidSignature(commentUpdateBeforeSignature, subIpns);
1676
1734
  commentUpdate = commentUpdateBeforeSignature;
1677
1735
  };
1678
- this._comment._setUpdatingStateWithEmissionIfNewState("fetching-update-ipfs");
1679
1736
  for (const timestampRange of timestampRanges) {
1680
1737
  const folderCid = subIpns.postUpdates[timestampRange];
1681
1738
  const path = this._calculatePathForPostCommentUpdate(folderCid, this._comment.postCid);
1739
+ throwIfAbortSignalAborted(abortSignal);
1740
+ const { alreadyJudged, cid } = await this._isPostUpdateFileAlreadyJudged(folderCid, path, log, abortSignal);
1741
+ throwIfAbortSignalAborted(abortSignal);
1742
+ if (alreadyJudged) {
1743
+ log.trace("Comment", this._comment.cid, "already judged the CommentUpdate at", path, "skipping it");
1744
+ return;
1745
+ }
1746
+ this._comment._setUpdatingStateWithEmissionIfNewState("fetching-update-ipfs");
1682
1747
  try {
1683
1748
  await this.fetchFromMultipleGateways({
1684
1749
  recordIpfsType: "ipfs",
@@ -1689,16 +1754,21 @@ var CommentClientsManager = class extends PublicationClientsManager {
1689
1754
  log,
1690
1755
  maxFileSizeBytes: MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE,
1691
1756
  timeoutMs: this._pkc._timeouts["comment-update-ipfs"],
1692
- abortSignal: this._comment._getStopAbortSignal()
1757
+ abortSignal
1693
1758
  });
1694
1759
  if (!commentUpdate) throw Error("Failed to load comment update from gateways. This is a critical logic error");
1695
- if (commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) return {
1760
+ this._comment._lastJudgedPostUpdate = {
1761
+ path,
1762
+ cid
1763
+ };
1764
+ if (!this._isNotNewerThanHeldCommentUpdate(commentUpdate)) return {
1696
1765
  commentUpdate,
1697
1766
  commentUpdateIpfsPath: path
1698
1767
  };
1699
1768
  this._logIgnoredNotNewerPostCommentUpdate(log, path, commentUpdate);
1700
1769
  return;
1701
1770
  } catch (e) {
1771
+ throwIfAbortSignalAborted(abortSignal);
1702
1772
  if (this._shouldWeFetchCommentUpdateFromNextTimestamp(e)) {
1703
1773
  attemptedPathsToLoadErrors[path] = e;
1704
1774
  log.trace(`Failed to fetch CommentUpdate from path (${path}) from gateways. Trying the next timestamp range`);
@@ -1742,10 +1812,11 @@ var CommentClientsManager = class extends PublicationClientsManager {
1742
1812
  if (typeof postTimestamp !== "number") throw Error("Post timestamp is not defined by the time we're fetching from postUpdates");
1743
1813
  const timestampRanges = getPostUpdateTimestampRange(subIpfs.postUpdates, postTimestamp);
1744
1814
  if (timestampRanges.length === 0) throw Error("Post has no timestamp range bucket");
1815
+ const abortSignal = this._combinedAbortSignalForRetry();
1745
1816
  let newCommentUpdate;
1746
1817
  try {
1747
- if (Object.keys(this._pkc.clients.kuboRpcClients).length > 0 || Object.keys(this._pkc.clients.libp2pJsClients).length > 0) newCommentUpdate = await this._fetchPostCommentUpdateIpfsP2P(subIpfs, timestampRanges, log);
1748
- else newCommentUpdate = await this._fetchPostCommentUpdateFromGateways(subIpfs, timestampRanges, log);
1818
+ 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);
1819
+ else newCommentUpdate = await this._fetchPostCommentUpdateFromGateways(subIpfs, timestampRanges, log, abortSignal);
1749
1820
  } catch (e) {
1750
1821
  if (e instanceof Error) {
1751
1822
  if (isAbortError(e)) return;
@@ -1773,7 +1844,7 @@ var CommentClientsManager = class extends PublicationClientsManager {
1773
1844
  }
1774
1845
  if (newCommentUpdate) this._useLoadedCommentUpdateIfNewInfo(newCommentUpdate, subIpfs, log);
1775
1846
  else if (newCommentUpdate === void 0) {
1776
- log.trace(`Comment`, this._comment.cid, "loaded an old comment update. Ignoring it");
1847
+ log.trace(`Comment`, this._comment.cid, "has no newer CommentUpdate under postUpdates");
1777
1848
  this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
1778
1849
  }
1779
1850
  }
@@ -1981,6 +2052,10 @@ var CommentClientsManager = class extends PublicationClientsManager {
1981
2052
  if (postInUpdatingCommunity && postInUpdatingCommunity.commentUpdate.updatedAt > (this._comment.raw?.commentUpdate?.updatedAt || 0)) {
1982
2053
  const log = logger_default("pkc-js:comment:update:handleUpdateEventFromCommunity:find-comment-update-in-updating-community-or-comments-pages");
1983
2054
  this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: postInUpdatingCommunity.commentUpdate }, community.raw.communityIpfs, log);
2055
+ this._markRecordPostUpdateJudgedIfItsPagesHoldTheHeldUpdate(community);
2056
+ } else if (this._markRecordPostUpdateJudgedIfItsPagesHoldTheHeldUpdate(community)) {
2057
+ log.trace("Comment", this._comment.cid, "is current with the record's pages, nothing to fetch from postUpdates");
2058
+ this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
1984
2059
  } else try {
1985
2060
  await this.useCommunityPostUpdatesToFetchCommentUpdateForPost(community.raw.communityIpfs);
1986
2061
  } catch (e) {
@@ -2293,6 +2368,7 @@ var Comment = class extends Publication {
2293
2368
  this.raw = {};
2294
2369
  this._commentUpdateIpfsPath = void 0;
2295
2370
  this._invalidCommentUpdateMfsPaths = /* @__PURE__ */ new Set();
2371
+ this._lastJudgedPostUpdate = void 0;
2296
2372
  this._commentIpfsloadingOperation = void 0;
2297
2373
  this._updateRpcSubscriptionId = void 0;
2298
2374
  this._stopAbortController = void 0;
@@ -8669,7 +8745,7 @@ var PKC$1 = class extends PKCTypedEmitter {
8669
8745
  this.clients.libp2pJsClients = {};
8670
8746
  if (!this.libp2pJsClientsOptions) return;
8671
8747
  if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
8672
- const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-BsXEDYPa.js");
8748
+ const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-6kkeZX1a.js");
8673
8749
  for (const clientOptions of this.libp2pJsClientsOptions) {
8674
8750
  const heliaNode = await createLibp2pJsClientOrUseExistingOne({
8675
8751
  ...clientOptions,
@@ -9033,7 +9109,7 @@ var PKC$1 = class extends PKCTypedEmitter {
9033
9109
  const log = logger_default("pkc-js:pkc:createLocalCommunity");
9034
9110
  log.trace("Received community options to create a local community instance:", options);
9035
9111
  if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
9036
- const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-FekHR-fd.js");
9112
+ const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-BST1U_f3.js");
9037
9113
  const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
9038
9114
  const community = new LocalCommunity(this);
9039
9115
  if (isLocalCommunity) {
@@ -1,4 +1,4 @@
1
- import { bn as PageSortFileSchema, v as getEquivalentCommunityAddresses, wn as isStringDomain } from "./util-VrWyIc1x.js";
1
+ import { bn as PageSortFileSchema, v as getEquivalentCommunityAddresses, wn as isStringDomain } from "./util-LwSS90AE.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, Ar as e$4, Bn as CommentUpdateReservedFields, Br as require_supports_color, C as hideClassPrivateProps, Cn as areEquivalentNames, Cr as t$11, Ct as trackUpdatingCommunity, D as isIpfsCid, Dn as VotePubsubMessagePublicationSchema, Dr as r$7, Dt as require_sha256$1, E as isAbortError, En as VoteChallengeRequestToEncryptSchema, Er as n$8, Et as untrackUpdatingCommunity, Fn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Fr as FailedToFetchGenericIpfsFromGatewaysError, Ft as ChallengeRequestMessageSignedPropertyNames, Gn as CreateCommentOptionsWithRefinementSchema, Gr as boolean, Gt as PKCParsedOptionsSchema, Hn as CommentUpdateSignedPropertyNames, Ht as DecryptedChallengeVerificationSchema, In as CommentSignedPropertyNames, Ir as FailedToFetchPageIpfsFromGatewaysError, Jn as PageIpfsSchema, Jr as looseObject, K as removeNullUndefinedEmptyObjectsValuesRecursively, Kn as GetPageParamSchema, Kr as custom, Kt as PKCUserOptionBaseSchema, L as isRequestPubsubPublicationOfPost, Ln as CommentUpdateChallengeReservedFieldNames, Lr as PKCError, Lt as ChallengeVerificationMessageSignedPropertyNames, Mn as CommentIpfsReservedFields, Mr as FailedToFetchCommentIpfsFromGatewaysError, Nn as CommentIpfsSchema, Nr as FailedToFetchCommentUpdateFromGatewaysError, Nt as ChallengeMessageSignedPropertyNames, O as isIpfsPath, Or as t$10, Pr as FailedToFetchCommunityFromGatewaysError, Qn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Qr as record, Qt as CommunityEditPubsubMessagePublicationSchema, R as isRequestPubsubPublicationOfReply, Rr as messages, Rt as DecryptedChallengeAnswerSchema, S as hasTransientNetworkErrorCode, Sn as RpcRemoteCommunityUpdateEventResultSchema, Sr as e$5, T as ipnsNameToIpnsOverPubsubTopic, Tn as CreateVoteUserOptionsWithRefinementSchema, Tr as t$12, Ur as _enum, Ut as NameResolveCacheOptionsSchema, V as raceAgainstAbort, Vn as CommentUpdateSchema, Vr as require_ms$1, Vt as DecryptedChallengeSchema, Wr as array, Wt as NameResolverSerializedSchema, Xn as CommentEditChallengeRequestToEncryptSchema, Xr as object, Yn as isReservedObjectKey, Yr as number, Yt as CommunityEditPublicationChallengeRequestToEncryptSchema, Zr as preprocess, Zt as CommunityEditPublicationSignedPropertyNames, _n as CreateRpcCommunityFunctionArgumentSchema, an as CreateCommentModerationOptionsWithRefinementSchema, ar as AuthorPubsubSchema, at as timestamp, bn as PageSortFileSchema, br as t$13, cr as CidPathSchema, d as deepMergeRuntimeFields, dn as CommunityExportRecordsSchema, dr as CommunityAuthorChallengeReservedFieldNames, dt as findStartedCommunity, ei as union, en as CommentModerationChallengeRequestToEncryptSchema, er as CommentEditSignedPropertyNames, et as shortifyAddress, f as derivePublicationFromChallengeRequest, fn as CommunityIpfsReservedFields, fr as CreateSignerSchema, gn as CreateRemoteCommunityFunctionArgumentSchema, gr as n$9, h as fetchAndValidateIpnsRecordFromGateway, hn as CreateNewLocalCommunityUserOptionsSchema, hr as ProtocolVersionSchema, in as CommentModerationsTableRowSchema, ir as AuthorCommentIpfsReservedFields, it as throwIfAbortSignalAborted, jn as CommentChallengeRequestToEncryptSchema, jr as require_retry$1, jt as ChallengeAnswerMessageSignedPropertyNames, k as isIpns, kn as VoteSignedPropertyNames, kr as t$9, kt as pTimeout, ln as CommunityChallengeSettingSchema, lr as CidStringSchema, m as extractNetworkErrorDetails, mn as CommunitySignedPropertyNames, mr as PKCTimestampSchema, mt as forgetTrackedUpdatingCommunityName, nr as CreateCommentEditOptionsWithRefinementSchema, nt as sleepUntilTimeoutOrAbort, on as ChallengeFileFactorySchema, or as AuthorReservedFields, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pr as JsonSignatureSchema, pt as findUpdatingCommunity, qn as ModQueuePageIpfsSchema, qr as literal, qt as PKCUserOptionsSchema, r as calculateIpfsCidV0, rn as CommentModerationSignedPropertyNames, rr as AuthorAddressSchema, sn as ChallengeFileSchema, sr as ChallengeAnswersSchema, t as areEquivalentCommunityAddresses, tn as CommentModerationPubsubMessagePublicationSchema, tt as shortifyCid, u as createAbortError, un as CommunityEditOptionsSchema, ur as CommunityAddressSchema, vn as ExportCommunityModLogsOptionsSchema, vr as n$10, w as interruptibleSleep, wn as isStringDomain, 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 CommentUpdateForChallengeVerificationSignedPropertyNames, zr as logger_default } from "./util-VrWyIc1x.js";
2
+ import { $r as string, $t as CreateCommunityEditPublicationOptionsWithRefinementSchema, A as isIpnsPath, Ar as e$4, Bn as CommentUpdateReservedFields, Br as require_supports_color, C as hideClassPrivateProps, Cn as areEquivalentNames, Cr as t$11, Ct as trackUpdatingCommunity, D as isIpfsCid, Dn as VotePubsubMessagePublicationSchema, Dr as r$7, Dt as require_sha256$1, E as isAbortError, En as VoteChallengeRequestToEncryptSchema, Er as n$8, Et as untrackUpdatingCommunity, Fn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Fr as FailedToFetchGenericIpfsFromGatewaysError, Ft as ChallengeRequestMessageSignedPropertyNames, Gn as CreateCommentOptionsWithRefinementSchema, Gr as boolean, Gt as PKCParsedOptionsSchema, Hn as CommentUpdateSignedPropertyNames, Ht as DecryptedChallengeVerificationSchema, In as CommentSignedPropertyNames, Ir as FailedToFetchPageIpfsFromGatewaysError, Jn as PageIpfsSchema, Jr as looseObject, K as removeNullUndefinedEmptyObjectsValuesRecursively, Kn as GetPageParamSchema, Kr as custom, Kt as PKCUserOptionBaseSchema, L as isRequestPubsubPublicationOfPost, Ln as CommentUpdateChallengeReservedFieldNames, Lr as PKCError, Lt as ChallengeVerificationMessageSignedPropertyNames, Mn as CommentIpfsReservedFields, Mr as FailedToFetchCommentIpfsFromGatewaysError, Nn as CommentIpfsSchema, Nr as FailedToFetchCommentUpdateFromGatewaysError, Nt as ChallengeMessageSignedPropertyNames, O as isIpfsPath, Or as t$10, Pr as FailedToFetchCommunityFromGatewaysError, Qn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Qr as record, Qt as CommunityEditPubsubMessagePublicationSchema, R as isRequestPubsubPublicationOfReply, Rr as messages, Rt as DecryptedChallengeAnswerSchema, S as hasTransientNetworkErrorCode, Sn as RpcRemoteCommunityUpdateEventResultSchema, Sr as e$5, T as ipnsNameToIpnsOverPubsubTopic, Tn as CreateVoteUserOptionsWithRefinementSchema, Tr as t$12, Ur as _enum, Ut as NameResolveCacheOptionsSchema, V as raceAgainstAbort, Vn as CommentUpdateSchema, Vr as require_ms$1, Vt as DecryptedChallengeSchema, Wr as array, Wt as NameResolverSerializedSchema, Xn as CommentEditChallengeRequestToEncryptSchema, Xr as object, Yn as isReservedObjectKey, Yr as number, Yt as CommunityEditPublicationChallengeRequestToEncryptSchema, Zr as preprocess, Zt as CommunityEditPublicationSignedPropertyNames, _n as CreateRpcCommunityFunctionArgumentSchema, an as CreateCommentModerationOptionsWithRefinementSchema, ar as AuthorPubsubSchema, at as timestamp, bn as PageSortFileSchema, br as t$13, cr as CidPathSchema, d as deepMergeRuntimeFields, dn as CommunityExportRecordsSchema, dr as CommunityAuthorChallengeReservedFieldNames, dt as findStartedCommunity, ei as union, en as CommentModerationChallengeRequestToEncryptSchema, er as CommentEditSignedPropertyNames, et as shortifyAddress, f as derivePublicationFromChallengeRequest, fn as CommunityIpfsReservedFields, fr as CreateSignerSchema, gn as CreateRemoteCommunityFunctionArgumentSchema, gr as n$9, h as fetchAndValidateIpnsRecordFromGateway, hn as CreateNewLocalCommunityUserOptionsSchema, hr as ProtocolVersionSchema, in as CommentModerationsTableRowSchema, ir as AuthorCommentIpfsReservedFields, it as throwIfAbortSignalAborted, jn as CommentChallengeRequestToEncryptSchema, jr as require_retry$1, jt as ChallengeAnswerMessageSignedPropertyNames, k as isIpns, kn as VoteSignedPropertyNames, kr as t$9, kt as pTimeout, ln as CommunityChallengeSettingSchema, lr as CidStringSchema, m as extractNetworkErrorDetails, mn as CommunitySignedPropertyNames, mr as PKCTimestampSchema, mt as forgetTrackedUpdatingCommunityName, nr as CreateCommentEditOptionsWithRefinementSchema, nt as sleepUntilTimeoutOrAbort, on as ChallengeFileFactorySchema, or as AuthorReservedFields, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pr as JsonSignatureSchema, pt as findUpdatingCommunity, qn as ModQueuePageIpfsSchema, qr as literal, qt as PKCUserOptionsSchema, r as calculateIpfsCidV0, rn as CommentModerationSignedPropertyNames, rr as AuthorAddressSchema, sn as ChallengeFileSchema, sr as ChallengeAnswersSchema, t as areEquivalentCommunityAddresses, tn as CommentModerationPubsubMessagePublicationSchema, tt as shortifyCid, u as createAbortError, un as CommunityEditOptionsSchema, ur as CommunityAddressSchema, vn as ExportCommunityModLogsOptionsSchema, vr as n$10, w as interruptibleSleep, wn as isStringDomain, 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 CommentUpdateForChallengeVerificationSignedPropertyNames, zr as logger_default } from "./util-LwSS90AE.js";
3
3
  import { t as all } from "./src-CYIMjhjK.js";
4
- import { s as validatePageSortFile } from "./page-sort-scoring-Civ7TOoF.js";
4
+ import { s as validatePageSortFile } from "./page-sort-scoring-2FkqYYNf.js";
5
5
  import { createHash } from "node:crypto";
6
6
  import { pathToFileURL } from "node:url";
7
7
  import dns from "node:dns";
@@ -123838,12 +123838,15 @@ var BaseClientsManager = class BaseClientsManager {
123838
123838
  res,
123839
123839
  i
123840
123840
  });
123841
- })));
123841
+ }, () => {})));
123842
123842
  }
123843
123843
  async fetchFromMultipleGateways(loadOpts) {
123844
123844
  const timeoutMs = loadOpts.timeoutMs;
123845
123845
  const concurrencyLimit = 3;
123846
- const queueLimit = pLimit(concurrencyLimit);
123846
+ const queueLimit = pLimit({
123847
+ concurrency: concurrencyLimit,
123848
+ rejectOnClear: true
123849
+ });
123847
123850
  const gatewaysSorted = t$13(this._pkc.clients.ipfsGateways).length <= concurrencyLimit ? t$13(this._pkc.clients.ipfsGateways) : await this._pkc._stats.sortGatewaysAccordingToScore(loadOpts.recordIpfsType);
123848
123851
  const gatewayFetches = {};
123849
123852
  const cleanUp = () => {
@@ -123993,6 +123996,30 @@ var BaseClientsManager = class BaseClientsManager {
123993
123996
  }
123994
123997
  throw Error("Should not reach this block in resolveIpnsToCidP2P");
123995
123998
  }
123999
+ async _resolveIpfsPathToCid({ root, path, timeoutMs, abortSignal, log, bitswapSessionSeedScopeIpnsPubsubTopic }) {
124000
+ try {
124001
+ if (t$13(this._pkc.clients.kuboRpcClients).length > 0 || t$13(this._pkc.clients.libp2pJsClients).length > 0) {
124002
+ const seedScopeOptions = "_helia" in this.getDefaultKuboRpcClientOrHelia() && bitswapSessionSeedScopeIpnsPubsubTopic ? { bitswapSessionSeedScopeIpnsPubsubTopic } : void 0;
124003
+ const [, namespace, cid, ...remainder] = (await this.getIpfsClientWithKuboRpcClientFunctions().resolve(`/ipfs/${root}/${path}`, {
124004
+ timeout: timeoutMs,
124005
+ signal: abortSignal,
124006
+ ...seedScopeOptions
124007
+ })).split("/");
124008
+ if (namespace !== "ipfs" || remainder.length > 0) return void 0;
124009
+ return CID.parse(cid).toV1().toString();
124010
+ }
124011
+ return;
124012
+ } catch (e) {
124013
+ if (e instanceof PKCError && e.code === "ERR_FETCH_CID_P2P_TIMEOUT") throw e;
124014
+ if (e instanceof Error && e.name === "TimeoutError" && !abortSignal?.aborted) throw new PKCError("ERR_FETCH_CID_P2P_TIMEOUT", {
124015
+ ipfsPath: `/ipfs/${root}/${path}`,
124016
+ timeoutMs,
124017
+ error: e
124018
+ });
124019
+ log.trace("Could not resolve", `${root}/${path}`, "to a cid, the caller will fetch it", e);
124020
+ return;
124021
+ }
124022
+ }
123996
124023
  async _fetchCidP2P(cidV0, loadOpts) {
123997
124024
  const log = logger_default("pkc-js:clients-manager:_fetchCidP2P");
123998
124025
  throwIfAbortSignalAborted(loadOpts.abortSignal);
@@ -126196,7 +126223,10 @@ var CommunityClientsManager = class extends PKCClientsManager {
126196
126223
  const log = logger_default("pkc-js:community:fetchCommunityFromGateways");
126197
126224
  const concurrencyLimit = 3;
126198
126225
  const timeoutMs = this._pkc._timeouts["community-ipns"];
126199
- const queueLimit = pLimit(concurrencyLimit);
126226
+ const queueLimit = pLimit({
126227
+ concurrency: concurrencyLimit,
126228
+ rejectOnClear: true
126229
+ });
126200
126230
  const gatewaysSorted = t$13(this._pkc.clients.ipfsGateways).length <= concurrencyLimit ? t$13(this._pkc.clients.ipfsGateways) : await this._pkc._stats.sortGatewaysAccordingToScore("ipns");
126201
126231
  const gatewayFetches = {};
126202
126232
  for (const gatewayUrl of gatewaysSorted) {
@@ -16525,7 +16525,7 @@ const CommunityEditPublicationPubsubReservedFields = r$2([
16525
16525
  ], t$3(CommunityEditPubsubMessagePublicationSchema.shape));
16526
16526
  //#endregion
16527
16527
  //#region dist/node/generated-version.js
16528
- const version = "0.0.127";
16528
+ const version = "0.0.128";
16529
16529
  //#endregion
16530
16530
  //#region dist/node/version.js
16531
16531
  const protocolVersion = ProtocolVersionSchema.parse("1.0.0");
@@ -1,4 +1,4 @@
1
- import { B as pubsubTopicToDhtKeyCid, Lr as PKCError } from "./util-VrWyIc1x.js";
1
+ import { B as pubsubTopicToDhtKeyCid, Lr as PKCError } from "./util-LwSS90AE.js";
2
2
  import { ipnsSelector } from "ipns/selector";
3
3
  import { ipnsValidator } from "ipns/validator";
4
4
  import { unmarshalIPNSRecord } from "ipns";
@@ -1,5 +1,5 @@
1
- import { Lr as PKCError, on as ChallengeFileFactorySchema, sn as ChallengeFileSchema, yn as PageSortFileFactorySchema } from "./util-VrWyIc1x.js";
2
- import { s as validatePageSortFile } from "./page-sort-scoring-Civ7TOoF.js";
1
+ import { Lr as PKCError, on as ChallengeFileFactorySchema, sn as ChallengeFileSchema, yn as PageSortFileFactorySchema } from "./util-LwSS90AE.js";
2
+ import { s as validatePageSortFile } from "./page-sort-scoring-2FkqYYNf.js";
3
3
  //#region dist/node/validate-package-factories.js
4
4
  function validateChallengeFileFactory(factory, { name }) {
5
5
  try {
@@ -1,2 +1,2 @@
1
- import { a as getShortCid, c as setNativeFunctions, i as getShortAddress, n as challenges, o as nativeFunctions, r as createAnchorIpnsRecord, s as pageSorts, t as PKC } from "./chunks/node-pIjburtc.js";
1
+ import { a as getShortCid, c as setNativeFunctions, i as getShortAddress, n as challenges, o as nativeFunctions, r as createAnchorIpnsRecord, s as pageSorts, t as PKC } from "./chunks/node-BEH8NA_I.js";
2
2
  export { challenges, createAnchorIpnsRecord, PKC as default, getShortAddress, getShortCid, nativeFunctions, pageSorts, setNativeFunctions };
@@ -1,2 +1,2 @@
1
- import { n as validatePageSortFileFactory } from "./chunks/validate-package-factories-CJgjDTZC.js";
1
+ import { n as validatePageSortFileFactory } from "./chunks/validate-package-factories-_KKnb8At.js";
2
2
  export { validatePageSortFileFactory };
@@ -1,7 +1,7 @@
1
- import { $ as retryKuboIpfsAddAndProvide, C as hideClassPrivateProps, Lr as PKCError, Y as replaceXWithY, br as t, dt as findStartedCommunity, i as calculateStringSizeSameAsIpfsAddCidV0, kt as pTimeout, vr as n, zr as logger_default } from "../../chunks/util-VrWyIc1x.js";
2
- import { S as parseRpcUnsubscribeParam, _ as parseRpcExportCommunityParam, b as parseRpcPublishChallengeAnswersParam, d as parseRpcCidParam, f as parseRpcCommentRepliesPageParam, g as parseRpcExportCommunityModLogsParam, h as parseRpcEditCommunityParam, l as parseRpcAuthorNameParam, m as parseRpcCommunityPageParam, p as parseRpcCommunityIdentifierParam, t as PKC, u as parseRpcCancelExportParam, v as parseRpcFetchCommunityListParam, x as parseRpcPublishCommunityListParam, y as parseRpcPublishAnchorRecordParam } from "../../chunks/node-pIjburtc.js";
3
- import { Bn as verifyCommunityList, Dt as parseJsonWithPKCErrorIfFails, E as buildPagesRuntimeFields, L as extractCrosspostRuntimeFields, Mt as parseVoteChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, Rr as stringify, T as buildPageRuntimeFields, U as pRetry, W as pLimit, Yn as MAX_COMMUNITY_LIST_SIZE_BYTES, at as parseCommentModerationChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, bt as parseCreatePKCWsServerOptionsSchemaWithPKCErrorIfItFails, dt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, jr as t$1, jt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, mt as parseCommunityListSchemaWithPKCErrorIfItFails, nt as parseCommentEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, on as require_lib, tt as parseCommentChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, ut as parseCommunityEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, yt as parseCreateNewLocalCommunityUserOptionsSchemaWithPKCErrorIfItFails } from "../../chunks/rpc-local-community-BqP9g2Rk.js";
4
- import { t as LocalCommunity } from "../../chunks/local-community-WFQoW5aC.js";
1
+ import { $ as retryKuboIpfsAddAndProvide, C as hideClassPrivateProps, Lr as PKCError, Y as replaceXWithY, br as t, dt as findStartedCommunity, i as calculateStringSizeSameAsIpfsAddCidV0, kt as pTimeout, vr as n, zr as logger_default } from "../../chunks/util-LwSS90AE.js";
2
+ import { S as parseRpcUnsubscribeParam, _ as parseRpcExportCommunityParam, b as parseRpcPublishChallengeAnswersParam, d as parseRpcCidParam, f as parseRpcCommentRepliesPageParam, g as parseRpcExportCommunityModLogsParam, h as parseRpcEditCommunityParam, l as parseRpcAuthorNameParam, m as parseRpcCommunityPageParam, p as parseRpcCommunityIdentifierParam, t as PKC, u as parseRpcCancelExportParam, v as parseRpcFetchCommunityListParam, x as parseRpcPublishCommunityListParam, y as parseRpcPublishAnchorRecordParam } from "../../chunks/node-BEH8NA_I.js";
3
+ import { Bn as verifyCommunityList, Dt as parseJsonWithPKCErrorIfFails, E as buildPagesRuntimeFields, L as extractCrosspostRuntimeFields, Mt as parseVoteChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, Rr as stringify, T as buildPageRuntimeFields, U as pRetry, W as pLimit, Yn as MAX_COMMUNITY_LIST_SIZE_BYTES, at as parseCommentModerationChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, bt as parseCreatePKCWsServerOptionsSchemaWithPKCErrorIfItFails, dt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, jr as t$1, jt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, mt as parseCommunityListSchemaWithPKCErrorIfItFails, nt as parseCommentEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, on as require_lib, tt as parseCommentChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, ut as parseCommunityEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, yt as parseCreateNewLocalCommunityUserOptionsSchemaWithPKCErrorIfItFails } from "../../chunks/rpc-local-community-SmLDPm1j.js";
4
+ import { t as LocalCommunity } from "../../chunks/local-community-B79BAYRo.js";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import path from "path";
7
7
  import assert from "assert";
@@ -101,6 +101,14 @@ export declare class BaseClientsManager {
101
101
  cid: string;
102
102
  ipnsHops: string[];
103
103
  }>;
104
+ _resolveIpfsPathToCid({ root, path, timeoutMs, abortSignal, log, bitswapSessionSeedScopeIpnsPubsubTopic }: {
105
+ root: string;
106
+ path: string;
107
+ timeoutMs: number;
108
+ abortSignal?: AbortSignal;
109
+ log: Logger;
110
+ bitswapSessionSeedScopeIpnsPubsubTopic?: string;
111
+ }): Promise<string | undefined>;
104
112
  _fetchCidP2P(cidV0: string, loadOpts: {
105
113
  maxFileSizeBytes: number;
106
114
  timeoutMs: number;
@@ -441,12 +441,14 @@ export class BaseClientsManager {
441
441
  return new Promise((resolve) => promises.forEach((promise, i) => promise.then((res) => {
442
442
  if ("resText" in res)
443
443
  resolve({ res, i });
444
- })));
444
+ }, () => { } // a gateway cleared from the queue; the caller's allSettled accounts for it
445
+ )));
445
446
  }
446
447
  async fetchFromMultipleGateways(loadOpts) {
447
448
  const timeoutMs = loadOpts.timeoutMs;
448
449
  const concurrencyLimit = 3;
449
- const queueLimit = pLimit(concurrencyLimit);
450
+ // rejectOnClear: cleanUp clears the queue, and a cleared gateway must still settle or allSettled below never does
451
+ const queueLimit = pLimit({ concurrency: concurrencyLimit, rejectOnClear: true });
450
452
  // Only sort if we have more than 3 gateways
451
453
  const gatewaysSorted = keys(this._pkc.clients.ipfsGateways).length <= concurrencyLimit
452
454
  ? keys(this._pkc.clients.ipfsGateways)
@@ -645,6 +647,41 @@ export class BaseClientsManager {
645
647
  throw Error("Should not reach this block in resolveIpnsToCidP2P");
646
648
  }
647
649
  // TODO rename this to _fetchPathP2P
650
+ // The cid an /ipfs/ path names, as CIDv1, or undefined when it cannot be told. Files are content-addressed, so a
651
+ // caller comparing it with the cid it last fetched can skip an unchanged file without reading it (issue #312).
652
+ // Kubo and helia walk only the directory blocks on the way, which an unchanged path already has locally. Undefined
653
+ // with only gateways. Throws only ERR_FETCH_CID_P2P_TIMEOUT: the walk could not reach the path's blocks in time, and
654
+ // a fetch of the path would walk the same blocks. Any other failure is undefined, and the caller fetches anyway.
655
+ async _resolveIpfsPathToCid({ root, path, timeoutMs, abortSignal, log, bitswapSessionSeedScopeIpnsPubsubTopic }) {
656
+ try {
657
+ if (keys(this._pkc.clients.kuboRpcClients).length > 0 || keys(this._pkc.clients.libp2pJsClients).length > 0) {
658
+ const kuboRpcOrHelia = this.getDefaultKuboRpcClientOrHelia();
659
+ const seedScopeOptions = "_helia" in kuboRpcOrHelia && bitswapSessionSeedScopeIpnsPubsubTopic
660
+ ? { bitswapSessionSeedScopeIpnsPubsubTopic }
661
+ : undefined;
662
+ const resolved = await this.getIpfsClientWithKuboRpcClientFunctions().resolve(`/ipfs/${root}/${path}`, {
663
+ timeout: timeoutMs,
664
+ signal: abortSignal,
665
+ ...seedScopeOptions
666
+ });
667
+ const [, namespace, cid, ...remainder] = resolved.split("/");
668
+ if (namespace !== "ipfs" || remainder.length > 0)
669
+ return undefined;
670
+ return CID.parse(cid).toV1().toString();
671
+ }
672
+ // A gateway is not asked: its answer is not checked against the folder, so a gateway could keep a changed
673
+ // file looking unchanged and the caller would never fetch it
674
+ return undefined;
675
+ }
676
+ catch (e) {
677
+ if (e instanceof PKCError && e.code === "ERR_FETCH_CID_P2P_TIMEOUT")
678
+ throw e; // helia's own timeout
679
+ if (e instanceof Error && e.name === "TimeoutError" && !abortSignal?.aborted)
680
+ throw new PKCError("ERR_FETCH_CID_P2P_TIMEOUT", { ipfsPath: `/ipfs/${root}/${path}`, timeoutMs, error: e });
681
+ log.trace("Could not resolve", `${root}/${path}`, "to a cid, the caller will fetch it", e);
682
+ return undefined;
683
+ }
684
+ }
648
685
  async _fetchCidP2P(cidV0, loadOpts) {
649
686
  const log = Logger("pkc-js:clients-manager:_fetchCidP2P");
650
687
  throwIfAbortSignalAborted(loadOpts.abortSignal);