@pkcprotocol/pkc-js 0.0.146 → 0.0.147
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -55
- package/dist/browser/clients/base-client-manager.js +14 -2
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/errors.d.ts +3 -0
- package/dist/browser/errors.js +3 -0
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/comment-client-manager.d.ts +15 -3
- package/dist/browser/publications/comment/comment-client-manager.js +221 -10
- package/dist/browser/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/browser/publications/comment/comment.js +1 -0
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/runtime/node/community/db-handler.d.ts +5 -1
- package/dist/browser/runtime/node/community/db-handler.js +64 -12
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/db-state.js +95 -13
- package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/editing.js +92 -22
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.d.ts +2 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +72 -20
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community.js +3 -0
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/util.d.ts +9 -0
- package/dist/browser/runtime/node/util.js +141 -25
- package/dist/browser/runtime/node/util.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +7 -1
- package/dist/browser/test/test-util.js +45 -16
- package/dist/browser/test/test-util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +47 -47
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-PaZmkxgn.js → helia-for-pkc-jM3y3OXF.js} +2 -2
- package/dist/bundled/chunks/{local-community-BY1ouP1-.js → local-community-5X7bvOoN.js} +247 -52
- package/dist/bundled/chunks/{local-community-CeuVhBBn.js → local-community-P9e5jksW.js} +1 -1
- package/dist/bundled/chunks/{node-BXilwSVE.js → node-By3og2hw.js} +162 -16
- package/dist/bundled/chunks/{page-sort-scoring-DgSzIxmE.js → page-sort-scoring-DwYGP_0d.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-BK_HGb_u.js → rpc-local-community-WnhiTbxm.js} +122 -29
- package/dist/bundled/chunks/{util-DRSzW-LU.js → util-7QtFMzpc.js} +1 -1
- package/dist/bundled/chunks/{util-Bnqvxk-6.js → util-DMr7Hj-w.js} +4 -1
- package/dist/bundled/chunks/{validate-package-factories-MG5ehoSU.js → validate-package-factories-TwRblx9f.js} +2 -2
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/page-sorts.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/clients/base-client-manager.js +14 -2
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/errors.d.ts +3 -0
- package/dist/node/errors.js +3 -0
- package/dist/node/errors.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/comment-client-manager.d.ts +15 -3
- package/dist/node/publications/comment/comment-client-manager.js +221 -10
- package/dist/node/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/node/publications/comment/comment.js +1 -0
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/runtime/node/community/db-handler.d.ts +5 -1
- package/dist/node/runtime/node/community/db-handler.js +64 -12
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/db-state.js +95 -13
- package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/editing.js +92 -22
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.d.ts +2 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.js +72 -20
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community.js +3 -0
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/util.d.ts +9 -0
- package/dist/node/runtime/node/util.js +141 -25
- package/dist/node/runtime/node/util.js.map +1 -1
- package/dist/node/test/test-util.d.ts +7 -1
- package/dist/node/test/test-util.js +45 -16
- package/dist/node/test/test-util.js.map +1 -1
- 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 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-
|
|
3
|
-
import { $n as buildRuntimeCommunityFields, $t as RpcPublishCommunityListParamSchema, A as findCommentInParsedPages,
|
|
4
|
-
import { s as getHeliaDebugContext } from "./util-
|
|
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, Lr as FailedToFetchPageIpfsFromGatewaysError, 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-DMr7Hj-w.js";
|
|
3
|
+
import { $n as buildRuntimeCommunityFields, $t as RpcPublishCommunityListParamSchema, A as findCommentInParsedPages, At as parseRpcCommentUpdateEventWithPKCErrorIfItFails, B as GenericStateClient, Bn as verifyCommunityEdit, Bt as RpcCommunityIdentifierParamSchema, C as RepliesPages, Cn as signCommentModeration, Cr as getDefaultDataPath, Ct as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, D as extractCommunityRuntimeFieldsFromParsedPages, Dn as signCommunityEdit, Dr as monitorCommunitiesDirectory, Dt as parseJsonWithPKCErrorIfFails, Er as listCommunitiesSync, Et as parseDecryptedChallengeWithPKCErrorIfItFails, F as cloneCrosspostForRuntime, Fn as verifyCommentIpfs, Fr as toCommunitiesEntry, Ft as RpcAuthorNameParamSchema, G as PKCTypedEmitter, Gn as getAuthorNameFromRuntime, Gr as t$2, Gt as RpcExportCommunityParamSchema, H as InflightResourceTypes, Hn as verifyVote, Hr as t$3, Ht as RpcEditCommunityParamSchema, I as collectCrosspostAuthorsToResolve, In as verifyCommentModeration, It as RpcCancelExportParamSchema, J as decodeRpcChallengeRequestPubsubMsg, Jn as CreateCommunityListWithCidOptionsSchema, Jr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, Jt as RpcFetchCidResultSchema, K as decodeRpcChallengeAnswerPubsubMsg, Kn as getAuthorNameFromWire, Kr as t$4, Kt as RpcExportCommunityResultSchema, Ln as verifyCommentPubsubMessage, Lt as RpcCidParamSchema, M as parseRawPages, Mr as setNativeFunctions$1, Nn as verifyChallengeVerification, Nr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, Nt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, O as findCommentInPageInstance, On as signCommunityList, Ot as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, P as applyNameResolvedCacheToCrosspost, Pn as verifyCommentEdit, Pr as findCommunitiesEntry, Pt as RpcAnchorPublishPreparationResultSchema, Qt as RpcPublishChallengeAnswersParamSchema, R as stripNameResolvedFromCrosspost, Rn as verifyCommentUpdate, Rt as RpcCommentRepliesPageParamSchema, Sn as signCommentEdit, St as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, Tt as parseDecryptedChallengeVerification, Un as buildRuntimeAuthor, Ur as n$3, Ut as RpcExportCommunityModLogsParamSchema, V as InflightFetchManager, Vn as verifyCommunityList, Vt as RpcCommunityPageParamSchema, Wn as cleanWireAuthor, Wt as RpcExportCommunityModLogsResultSchema, Xn as MAX_COMMUNITY_LIST_SIZE_BYTES, Xr as NAME_RESOLVED_TRUE_TTL_MS, Xt as RpcFetchCommunityListResultSchema, Y as decodeRpcChallengeVerificationPubsubMsg, Yn as CreateNewCommunityListOptionsSchema, Yr as NAME_RESOLVED_FALSE_TTL_MS, Yt as RpcFetchCommunityListParamSchema, Zr as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, Zt as RpcPublishAnchorRecordParamSchema, _n as signChallengeAnswer, _t as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, an as RpcUnsubscribeParamSchema, b as KeyvBetterSqlite3, br as findLocalCommunityAddress, ct as parseCommentUpdateSchemaWithPKCErrorIfItFails, dn as decryptEd25519AesGcm, ei as nativeFunctions$2, 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, 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, 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, zr as t$5, zt as RpcCommunitiesChangeEventResultSchema } from "./rpc-local-community-WnhiTbxm.js";
|
|
4
|
+
import { s as getHeliaDebugContext } from "./util-7QtFMzpc.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import assert from "assert";
|
|
7
7
|
import fs from "fs";
|
|
@@ -28599,10 +28599,34 @@ async function loadAllPagesUnderCommunityToFindComment(opts) {
|
|
|
28599
28599
|
//#endregion
|
|
28600
28600
|
//#region dist/node/publications/comment/comment-client-manager.js
|
|
28601
28601
|
const fetchCommentLogger = logger_default("pkc-js:comment:client-manager:fetchAndVerifyCommentCid");
|
|
28602
|
+
const TRANSIENT_FETCH_RETRY_MIN_DELAY_MS = 1e3;
|
|
28603
|
+
const TRANSIENT_FETCH_RETRY_MAX_DELAY_MS = 3e4;
|
|
28604
|
+
const PARENT_PAGE_ERROR_CODES_NOT_WORTH_A_RETRY = new Set([
|
|
28605
|
+
"ERR_REPLIES_PAGE_IS_INVALID",
|
|
28606
|
+
"ERR_POSTS_PAGE_IS_INVALID",
|
|
28607
|
+
"ERR_PAGE_SIGNATURE_IS_INVALID",
|
|
28608
|
+
"ERR_PAGE_COMMENT_IS_INVALID",
|
|
28609
|
+
"ERR_INVALID_PAGE_IPFS_SCHEMA",
|
|
28610
|
+
"ERR_CALCULATED_CID_DOES_NOT_MATCH",
|
|
28611
|
+
"ERR_OVER_DOWNLOAD_LIMIT",
|
|
28612
|
+
"ERR_INVALID_JSON"
|
|
28613
|
+
]);
|
|
28614
|
+
function isParentPageFetchErrorWorthARetry(err) {
|
|
28615
|
+
if (!(err instanceof PKCError)) return false;
|
|
28616
|
+
if (PARENT_PAGE_ERROR_CODES_NOT_WORTH_A_RETRY.has(err.code)) return false;
|
|
28617
|
+
if (err instanceof FailedToFetchPageIpfsFromGatewaysError) {
|
|
28618
|
+
for (const gatewayError of Object.values(err.details.gatewayToError)) if (isParentPageFetchErrorWorthARetry(gatewayError)) return true;
|
|
28619
|
+
return false;
|
|
28620
|
+
}
|
|
28621
|
+
return true;
|
|
28622
|
+
}
|
|
28623
|
+
const POST_NOT_IN_POST_UPDATES = "post-not-in-post-updates";
|
|
28602
28624
|
var CommentClientsManager = class extends PublicationClientsManager {
|
|
28603
28625
|
constructor(comment) {
|
|
28604
28626
|
super(comment);
|
|
28605
28627
|
this._postForUpdating = void 0;
|
|
28628
|
+
this._transientFetchRetry = { attempts: 0 };
|
|
28629
|
+
this._commentUpdateLookupsStarted = 0;
|
|
28606
28630
|
this._comment = comment;
|
|
28607
28631
|
this._fetchingUpdateForReplyUsingPageCidsPromise = void 0;
|
|
28608
28632
|
this._parentFirstPageCidsAlreadyLoaded = /* @__PURE__ */ new Set();
|
|
@@ -28612,6 +28636,28 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
28612
28636
|
if (this._freshHandlerAbortController) this._freshHandlerAbortController.abort();
|
|
28613
28637
|
this._freshHandlerAbortController = new AbortController();
|
|
28614
28638
|
}
|
|
28639
|
+
_cancelTransientFetchRetry() {
|
|
28640
|
+
clearTimeout(this._transientFetchRetry.timer);
|
|
28641
|
+
this._transientFetchRetry = { attempts: 0 };
|
|
28642
|
+
}
|
|
28643
|
+
_dropPendingTransientFetchRetry() {
|
|
28644
|
+
clearTimeout(this._transientFetchRetry.timer);
|
|
28645
|
+
this._transientFetchRetry.timer = void 0;
|
|
28646
|
+
}
|
|
28647
|
+
_scheduleTransientFetchRetry(lookup, log) {
|
|
28648
|
+
clearTimeout(this._transientFetchRetry.timer);
|
|
28649
|
+
const delayMs = Math.min(TRANSIENT_FETCH_RETRY_MIN_DELAY_MS * 2 ** this._transientFetchRetry.attempts, TRANSIENT_FETCH_RETRY_MAX_DELAY_MS);
|
|
28650
|
+
this._transientFetchRetry.attempts++;
|
|
28651
|
+
log.trace("Comment", this._comment.cid, "will retry its CommentUpdate lookup in", delayMs, "ms");
|
|
28652
|
+
const timer = setTimeout(() => {
|
|
28653
|
+
if (this._transientFetchRetry.timer !== timer) return;
|
|
28654
|
+
this._transientFetchRetry.timer = void 0;
|
|
28655
|
+
if (this._comment.state !== "updating") return;
|
|
28656
|
+
lookup().catch((error) => log.error("Comment", this._comment.cid, "failed to retry its CommentUpdate lookup", error));
|
|
28657
|
+
}, delayMs);
|
|
28658
|
+
if (typeof timer === "object" && "unref" in timer) timer.unref();
|
|
28659
|
+
this._transientFetchRetry.timer = timer;
|
|
28660
|
+
}
|
|
28615
28661
|
_combinedAbortSignalForRetry() {
|
|
28616
28662
|
return linkAbortSignals([this._comment._getStopAbortSignal(), this._freshHandlerAbortController?.signal]);
|
|
28617
28663
|
}
|
|
@@ -28725,6 +28771,7 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
28725
28771
|
}
|
|
28726
28772
|
async _fetchPostCommentUpdateIpfsP2P(subIpns, timestampRanges, log, abortSignal) {
|
|
28727
28773
|
const attemptedPathsToLoadErrors = {};
|
|
28774
|
+
const pathsNotInTheirFolder = [];
|
|
28728
28775
|
const kuboRpcOrHelia = this.getDefaultKuboRpcClientOrHelia();
|
|
28729
28776
|
for (const timestampRange of timestampRanges) {
|
|
28730
28777
|
const folderCid = subIpns.postUpdates[timestampRange];
|
|
@@ -28735,6 +28782,11 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
28735
28782
|
judgedLookup = await this._isPostUpdateFileAlreadyJudged(folderCid, path, log, abortSignal);
|
|
28736
28783
|
} catch (e) {
|
|
28737
28784
|
throwIfAbortSignalAborted(abortSignal);
|
|
28785
|
+
if (e instanceof PKCError && e.code === "ERR_IPFS_PATH_NOT_IN_FOLDER") {
|
|
28786
|
+
log.trace("Post", this._comment.cid, "has no CommentUpdate at", path, "trying the next timestamp range");
|
|
28787
|
+
pathsNotInTheirFolder.push(path);
|
|
28788
|
+
continue;
|
|
28789
|
+
}
|
|
28738
28790
|
log.trace(`Timed out resolving CommentUpdate path (${path}) with IPFS P2P. Trying the next timestamp range`);
|
|
28739
28791
|
attemptedPathsToLoadErrors[path] = e;
|
|
28740
28792
|
continue;
|
|
@@ -28762,6 +28814,15 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
28762
28814
|
});
|
|
28763
28815
|
} catch (e) {
|
|
28764
28816
|
throwIfAbortSignalAborted(abortSignal);
|
|
28817
|
+
if (e instanceof PKCError && !this._shouldWeFetchCommentUpdateFromNextTimestamp(e)) {
|
|
28818
|
+
this._comment._invalidCommentUpdateMfsPaths.add(path);
|
|
28819
|
+
e.details = {
|
|
28820
|
+
...e.details,
|
|
28821
|
+
commentUpdatePath: path,
|
|
28822
|
+
postCid: this._comment.cid
|
|
28823
|
+
};
|
|
28824
|
+
throw e;
|
|
28825
|
+
}
|
|
28765
28826
|
log.trace(`Failed to fetch CommentUpdate from path (${path}) with IPFS P2P. Trying the next timestamp range`);
|
|
28766
28827
|
attemptedPathsToLoadErrors[path] = e;
|
|
28767
28828
|
continue;
|
|
@@ -28797,13 +28858,23 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
28797
28858
|
throw e;
|
|
28798
28859
|
}
|
|
28799
28860
|
}
|
|
28861
|
+
if (pathsNotInTheirFolder.length === timestampRanges.length) return POST_NOT_IN_POST_UPDATES;
|
|
28800
28862
|
throw new PKCError("ERR_FAILED_TO_FETCH_COMMENT_UPDATE_FROM_ALL_POST_UPDATES_RANGES", {
|
|
28801
28863
|
timestampRanges,
|
|
28802
28864
|
attemptedPathsToLoadErrors,
|
|
28865
|
+
pathsNotInTheirFolder,
|
|
28803
28866
|
postCid: this._comment.cid,
|
|
28804
28867
|
commentDepth: this._comment.depth
|
|
28805
28868
|
});
|
|
28806
28869
|
}
|
|
28870
|
+
_didEveryGatewayAnswerNotFound(err) {
|
|
28871
|
+
if (!(err instanceof FailedToFetchCommentUpdateFromGatewaysError)) return false;
|
|
28872
|
+
const gatewayUrls = Object.keys(this._pkc.clients.ipfsGateways);
|
|
28873
|
+
return gatewayUrls.length > 0 && gatewayUrls.every((gatewayUrl) => {
|
|
28874
|
+
const gatewayError = err.details.gatewayToError[gatewayUrl];
|
|
28875
|
+
return gatewayError?.code === "ERR_FAILED_TO_FETCH_IPFS_VIA_GATEWAY" && gatewayError.details?.status === 404;
|
|
28876
|
+
});
|
|
28877
|
+
}
|
|
28807
28878
|
_shouldWeFetchCommentUpdateFromNextTimestamp(err) {
|
|
28808
28879
|
if (!(err instanceof PKCError)) return false;
|
|
28809
28880
|
if (err.code === "ERR_COMMENT_UPDATE_SIGNATURE_IS_INVALID" || err.code === "ERR_INVALID_COMMENT_UPDATE_SCHEMA" || err.code === "ERR_OVER_DOWNLOAD_LIMIT" || err.code === "ERR_INVALID_JSON") return false;
|
|
@@ -28843,6 +28914,7 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
28843
28914
|
}
|
|
28844
28915
|
async _fetchPostCommentUpdateFromGateways(subIpns, timestampRanges, log, abortSignal) {
|
|
28845
28916
|
const attemptedPathsToLoadErrors = {};
|
|
28917
|
+
const pathsNotInTheirFolder = [];
|
|
28846
28918
|
let commentUpdate;
|
|
28847
28919
|
const validateCommentFromGateway = async (res) => {
|
|
28848
28920
|
if (typeof res.resText !== "string") throw Error("Gateway response has no body");
|
|
@@ -28886,6 +28958,11 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
28886
28958
|
return;
|
|
28887
28959
|
} catch (e) {
|
|
28888
28960
|
throwIfAbortSignalAborted(abortSignal);
|
|
28961
|
+
if (this._didEveryGatewayAnswerNotFound(e)) {
|
|
28962
|
+
log.trace("Post", this._comment.cid, "has no CommentUpdate at", path, "trying the next timestamp range");
|
|
28963
|
+
pathsNotInTheirFolder.push(path);
|
|
28964
|
+
continue;
|
|
28965
|
+
}
|
|
28889
28966
|
if (this._shouldWeFetchCommentUpdateFromNextTimestamp(e)) {
|
|
28890
28967
|
attemptedPathsToLoadErrors[path] = e;
|
|
28891
28968
|
log.trace(`Failed to fetch CommentUpdate from path (${path}) from gateways. Trying the next timestamp range`);
|
|
@@ -28896,9 +28973,11 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
28896
28973
|
}
|
|
28897
28974
|
}
|
|
28898
28975
|
}
|
|
28976
|
+
if (pathsNotInTheirFolder.length === timestampRanges.length) return POST_NOT_IN_POST_UPDATES;
|
|
28899
28977
|
throw new PKCError("ERR_FAILED_TO_FETCH_COMMENT_UPDATE_FROM_ALL_POST_UPDATES_RANGES", {
|
|
28900
28978
|
timestampRanges,
|
|
28901
28979
|
attemptedPathsToLoadErrors,
|
|
28980
|
+
pathsNotInTheirFolder,
|
|
28902
28981
|
commentCid: this._comment.cid,
|
|
28903
28982
|
commentDepth: this._comment.depth
|
|
28904
28983
|
});
|
|
@@ -28947,6 +29026,7 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
28947
29026
|
args: [e]
|
|
28948
29027
|
}
|
|
28949
29028
|
});
|
|
29029
|
+
return "fetch-failed";
|
|
28950
29030
|
} else {
|
|
28951
29031
|
log.error("Received a non retriable error when attempting to load post commentUpdate. Will be emitting error", this._comment.cid, e);
|
|
28952
29032
|
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
@@ -28962,7 +29042,10 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
28962
29042
|
} finally {
|
|
28963
29043
|
linkedAbortSignal.dispose();
|
|
28964
29044
|
}
|
|
28965
|
-
if (newCommentUpdate
|
|
29045
|
+
if (newCommentUpdate === POST_NOT_IN_POST_UPDATES) {
|
|
29046
|
+
log("Post", this._comment.cid, "is not under the postUpdates of this community record");
|
|
29047
|
+
this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
|
|
29048
|
+
} else if (newCommentUpdate) this._useLoadedCommentUpdateIfNewInfo(newCommentUpdate, subIpfs, log);
|
|
28966
29049
|
else if (newCommentUpdate === void 0) {
|
|
28967
29050
|
log.trace(`Comment`, this._comment.cid, "has no newer CommentUpdate under postUpdates");
|
|
28968
29051
|
this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
|
|
@@ -29154,6 +29237,14 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
29154
29237
|
].filter((update) => !!update).sort((a, b) => b.commentUpdate.updatedAt - a.commentUpdate.updatedAt)[0];
|
|
29155
29238
|
}
|
|
29156
29239
|
async handleUpdateEventFromCommunity(community) {
|
|
29240
|
+
this._dropPendingTransientFetchRetry();
|
|
29241
|
+
const lookup = ++this._commentUpdateLookupsStarted;
|
|
29242
|
+
const fetchFailed = await this._fetchPostCommentUpdateOnCommunityRecord(community);
|
|
29243
|
+
if (lookup !== this._commentUpdateLookupsStarted) return;
|
|
29244
|
+
if (fetchFailed) this._scheduleTransientFetchRetry(() => this.handleUpdateEventFromCommunity(community), logger_default("pkc-js:comment:update"));
|
|
29245
|
+
else if (this._transientFetchRetry.timer === void 0) this._transientFetchRetry.attempts = 0;
|
|
29246
|
+
}
|
|
29247
|
+
async _fetchPostCommentUpdateOnCommunityRecord(community) {
|
|
29157
29248
|
const log = logger_default("pkc-js:comment:update");
|
|
29158
29249
|
if (!this._comment.cid) {
|
|
29159
29250
|
log("comment.cid is not defined because comment is publishing, waiting until cid is defined");
|
|
@@ -29178,9 +29269,14 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
29178
29269
|
log.trace("Comment", this._comment.cid, "is current with the record's pages, nothing to fetch from postUpdates");
|
|
29179
29270
|
this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
|
|
29180
29271
|
} else try {
|
|
29181
|
-
await this.useCommunityPostUpdatesToFetchCommentUpdateForPost(community.raw.communityIpfs);
|
|
29272
|
+
return await this.useCommunityPostUpdatesToFetchCommentUpdateForPost(community.raw.communityIpfs) === "fetch-failed";
|
|
29182
29273
|
} catch (e) {
|
|
29183
29274
|
if (isAbortError(e)) return;
|
|
29275
|
+
if (e instanceof PKCError && e.code === "ERR_COMMUNITY_HAS_NO_POST_UPDATES") {
|
|
29276
|
+
log("Post", this._comment.cid, "can't fetch its CommentUpdate, the community record has no postUpdates yet");
|
|
29277
|
+
this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
|
|
29278
|
+
return;
|
|
29279
|
+
}
|
|
29184
29280
|
log.error("Failed to use community update to fetch new CommentUpdate", e);
|
|
29185
29281
|
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
29186
29282
|
newUpdatingState: "failed",
|
|
@@ -29229,8 +29325,24 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
29229
29325
|
return;
|
|
29230
29326
|
}
|
|
29231
29327
|
const pageSortName = this._chooseWhichPagesBasedOnParentAndReplyTimestamp(parentCommentInstance.timestamp);
|
|
29232
|
-
|
|
29233
|
-
if (!
|
|
29328
|
+
const firstPageCid = parentCommentInstance.replies.pageCids[pageSortName];
|
|
29329
|
+
if (!firstPageCid) {
|
|
29330
|
+
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
29331
|
+
newUpdatingState: "waiting-retry",
|
|
29332
|
+
event: {
|
|
29333
|
+
name: "error",
|
|
29334
|
+
args: [new PKCError("ERR_FAILED_TO_FIND_REPLY_COMMENT_UPDATE_WITHIN_PARENT_COMMENT_PAGE_CIDS", {
|
|
29335
|
+
replyCid: this._comment.cid,
|
|
29336
|
+
parentCommentCid: parentCommentInstance.cid,
|
|
29337
|
+
pageSortName,
|
|
29338
|
+
reason: "sort-not-in-page-cids",
|
|
29339
|
+
parentPageCids: parentCommentInstance.replies.pageCids
|
|
29340
|
+
})]
|
|
29341
|
+
}
|
|
29342
|
+
});
|
|
29343
|
+
return;
|
|
29344
|
+
}
|
|
29345
|
+
let curPageCid = firstPageCid;
|
|
29234
29346
|
if (this._parentFirstPageCidsAlreadyLoaded.has(curPageCid)) {
|
|
29235
29347
|
log(`Reply`, this._comment.cid, `:SKIPPING: Page CID ${curPageCid} already loaded parent page cid`);
|
|
29236
29348
|
return;
|
|
@@ -29251,7 +29363,6 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
29251
29363
|
});
|
|
29252
29364
|
break;
|
|
29253
29365
|
}
|
|
29254
|
-
if (pageCidsSearchedForNewUpdate.length === 0) this._parentFirstPageCidsAlreadyLoaded.add(curPageCid);
|
|
29255
29366
|
const replyWithinParentPage = findCommentInParsedPages(pageLoaded, this._comment.cid)?.raw;
|
|
29256
29367
|
const replyWithinUpdatingPages = this._findCommentInPagesOfUpdatingCommentsOrCommunity({ parent: parentCommentInstance });
|
|
29257
29368
|
pageCidsSearchedForNewUpdate.push({
|
|
@@ -29275,13 +29386,20 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
29275
29386
|
curPageCid = pageLoaded.nextCid;
|
|
29276
29387
|
}
|
|
29277
29388
|
log("Searched for new comment update of comment", this._comment.cid, "in the following pageCids of page sort", pageSortName, "of parent comment:", parentCommentInstance.cid, pageCidsSearchedForNewUpdate, "and found", newCommentUpdate ? "a new comment update" : "no new comment update");
|
|
29389
|
+
const pageFetchError = pageCidsSearchedForNewUpdate.find((searched) => searched.error)?.error;
|
|
29390
|
+
const pageFetchFailed = pageFetchError !== void 0 && isParentPageFetchErrorWorthARetry(pageFetchError);
|
|
29391
|
+
if (!pageFetchFailed) this._parentFirstPageCidsAlreadyLoaded.add(firstPageCid);
|
|
29278
29392
|
if (newCommentUpdate) this._useLoadedCommentUpdateIfNewInfo({ commentUpdate: newCommentUpdate.commentUpdate }, communityWithSignature, log);
|
|
29279
|
-
else if (!replyFoundWithoutNewerUpdate
|
|
29280
|
-
|
|
29281
|
-
|
|
29282
|
-
|
|
29283
|
-
|
|
29284
|
-
|
|
29393
|
+
else if (!replyFoundWithoutNewerUpdate || pageFetchError) {
|
|
29394
|
+
const reason = pageFetchFailed ? "page-fetch-failed" : pageFetchError ? "page-invalid" : "reply-not-in-pages";
|
|
29395
|
+
throw new PKCError("ERR_FAILED_TO_FIND_REPLY_COMMENT_UPDATE_WITHIN_PARENT_COMMENT_PAGE_CIDS", {
|
|
29396
|
+
replyCid: this._comment.cid,
|
|
29397
|
+
parentCommentCid: parentCommentInstance.cid,
|
|
29398
|
+
pageSortName,
|
|
29399
|
+
reason,
|
|
29400
|
+
pageCidsSearchedForNewUpdate
|
|
29401
|
+
});
|
|
29402
|
+
}
|
|
29285
29403
|
}
|
|
29286
29404
|
async handleErrorEventFromCommunity(error) {
|
|
29287
29405
|
if (this._comment.state === "publishing") return super.handleErrorEventFromCommunity(error);
|
|
@@ -29352,6 +29470,14 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
29352
29470
|
this.updateNameResolverState(newState, resolverKey);
|
|
29353
29471
|
}
|
|
29354
29472
|
async handleUpdateEventFromPostToFetchReplyCommentUpdate(postInstance) {
|
|
29473
|
+
this._dropPendingTransientFetchRetry();
|
|
29474
|
+
const lookup = ++this._commentUpdateLookupsStarted;
|
|
29475
|
+
const fetchFailed = await this._fetchReplyCommentUpdateOnPostUpdate(postInstance);
|
|
29476
|
+
if (lookup !== this._commentUpdateLookupsStarted) return;
|
|
29477
|
+
if (fetchFailed) this._scheduleTransientFetchRetry(() => this.handleUpdateEventFromPostToFetchReplyCommentUpdate(postInstance), logger_default("pkc-js:comment:update"));
|
|
29478
|
+
else if (this._transientFetchRetry.timer === void 0) this._transientFetchRetry.attempts = 0;
|
|
29479
|
+
}
|
|
29480
|
+
async _fetchReplyCommentUpdateOnPostUpdate(postInstance) {
|
|
29355
29481
|
if (!this._comment.cid) throw Error("comment.cid should be defined");
|
|
29356
29482
|
const log = logger_default("pkc-js:comment:update:handleUpdateEventFromPost");
|
|
29357
29483
|
log("Received update event from post", postInstance.cid, "for reply", this._comment.cid, "with depth", this._comment.depth);
|
|
@@ -29383,9 +29509,27 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
29383
29509
|
return;
|
|
29384
29510
|
}
|
|
29385
29511
|
if (this._fetchingUpdateForReplyUsingPageCidsPromise) await this._fetchingUpdateForReplyUsingPageCidsPromise;
|
|
29512
|
+
let fetchFailed = false;
|
|
29386
29513
|
this._fetchingUpdateForReplyUsingPageCidsPromise = this.usePageCidsOfParentToFetchCommentUpdateForReply(postInstance, repliesCommunity).catch((error) => {
|
|
29387
29514
|
if (isAbortError(error)) return;
|
|
29515
|
+
const reason = error instanceof PKCError && error.code === "ERR_FAILED_TO_FIND_REPLY_COMMENT_UPDATE_WITHIN_PARENT_COMMENT_PAGE_CIDS" ? error.details.reason : void 0;
|
|
29516
|
+
if (reason === "reply-not-in-pages") {
|
|
29517
|
+
log("Reply", this._comment.cid, "is not in its parent's pages yet", error.details);
|
|
29518
|
+
this._comment._setUpdatingStateWithEmissionIfNewState("waiting-retry");
|
|
29519
|
+
return;
|
|
29520
|
+
}
|
|
29388
29521
|
log.error("Failed to fetch reply commentUpdate update from parent pages", error);
|
|
29522
|
+
if (reason === "page-fetch-failed") {
|
|
29523
|
+
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
29524
|
+
newUpdatingState: "waiting-retry",
|
|
29525
|
+
event: {
|
|
29526
|
+
name: "error",
|
|
29527
|
+
args: [error]
|
|
29528
|
+
}
|
|
29529
|
+
});
|
|
29530
|
+
fetchFailed = true;
|
|
29531
|
+
return;
|
|
29532
|
+
}
|
|
29389
29533
|
this._comment._changeCommentStateEmitEventEmitStateChangeEvent({
|
|
29390
29534
|
newUpdatingState: "failed",
|
|
29391
29535
|
event: {
|
|
@@ -29398,6 +29542,7 @@ var CommentClientsManager = class extends PublicationClientsManager {
|
|
|
29398
29542
|
});
|
|
29399
29543
|
await this._fetchingUpdateForReplyUsingPageCidsPromise;
|
|
29400
29544
|
this._fetchingUpdateForReplyUsingPageCidsPromise = void 0;
|
|
29545
|
+
return fetchFailed;
|
|
29401
29546
|
}
|
|
29402
29547
|
async _createPostInstanceWithStateTranslation() {
|
|
29403
29548
|
if (!this._comment.postCid) throw Error("comment.postCid needs to be defined to fetch comment update of reply");
|
|
@@ -30316,6 +30461,7 @@ var Comment = class extends Publication {
|
|
|
30316
30461
|
const log = logger_default("pkc-js:comment:update:_stopUpdateLoop");
|
|
30317
30462
|
if (!this.cid) return;
|
|
30318
30463
|
this._commentIpfsloadingOperation?.stop();
|
|
30464
|
+
this._clientsManager._cancelTransientFetchRetry();
|
|
30319
30465
|
if (this._updateRpcSubscriptionId) {
|
|
30320
30466
|
const subscriptionId = this._updateRpcSubscriptionId;
|
|
30321
30467
|
this._updateRpcSubscriptionId = void 0;
|
|
@@ -35956,7 +36102,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
35956
36102
|
this.clients.libp2pJsClients = {};
|
|
35957
36103
|
if (!this.libp2pJsClientsOptions) return;
|
|
35958
36104
|
if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
|
|
35959
|
-
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-
|
|
36105
|
+
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-jM3y3OXF.js");
|
|
35960
36106
|
for (const clientOptions of this.libp2pJsClientsOptions) {
|
|
35961
36107
|
const heliaNode = await createLibp2pJsClientOrUseExistingOne({
|
|
35962
36108
|
...clientOptions,
|
|
@@ -36323,7 +36469,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
36323
36469
|
const log = logger_default("pkc-js:pkc:createLocalCommunity");
|
|
36324
36470
|
log.trace("Received community options to create a local community instance:", options);
|
|
36325
36471
|
if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
|
|
36326
|
-
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-
|
|
36472
|
+
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-P9e5jksW.js");
|
|
36327
36473
|
const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
|
|
36328
36474
|
const community = new LocalCommunity(this);
|
|
36329
36475
|
if (isLocalCommunity) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { gr as isStringDomain, v as getEquivalentCommunityAddresses, xn as PageSortFileSchema } from "./util-
|
|
1
|
+
import { gr as isStringDomain, v as getEquivalentCommunityAddresses, xn as PageSortFileSchema } from "./util-DMr7Hj-w.js";
|
|
2
2
|
//#region dist/node/pages/page-sort-scoring.js
|
|
3
3
|
function validatePageSortFile(rawFile) {
|
|
4
4
|
const validated = PageSortFileSchema.parse(rawFile);
|