@pkcprotocol/pkc-js 0.0.133 → 0.0.135

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 (64) hide show
  1. package/README.md +19 -0
  2. package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +12 -0
  3. package/dist/browser/clients/rpc-client/pkc-rpc-client.js +138 -37
  4. package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
  5. package/dist/browser/errors.d.ts +2 -0
  6. package/dist/browser/errors.js +2 -0
  7. package/dist/browser/errors.js.map +1 -1
  8. package/dist/browser/generated-version.d.ts +1 -1
  9. package/dist/browser/generated-version.js +1 -1
  10. package/dist/browser/pkc-error.d.ts +1 -1
  11. package/dist/browser/publications/comment/schema.d.ts +4 -0
  12. package/dist/browser/publications/comment/schema.js +2 -1
  13. package/dist/browser/publications/comment/schema.js.map +1 -1
  14. package/dist/browser/runtime/node/community/db-handler.js +44 -91
  15. package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
  16. package/dist/browser/runtime/node/community/local-community/comment-updates.js +1 -1
  17. package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
  18. package/dist/browser/runtime/node/community/page-generator.d.ts +2 -0
  19. package/dist/browser/runtime/node/community/page-generator.js +3 -2
  20. package/dist/browser/runtime/node/community/page-generator.js.map +1 -1
  21. package/dist/browser/runtime/node/util.d.ts +1 -0
  22. package/dist/browser/runtime/node/util.js +3 -2
  23. package/dist/browser/runtime/node/util.js.map +1 -1
  24. package/dist/browser/signer/signatures.js +6 -1
  25. package/dist/browser/signer/signatures.js.map +1 -1
  26. package/dist/bundled/bundle-manifest.json +46 -46
  27. package/dist/bundled/challenges.js +1 -1
  28. package/dist/bundled/chunks/{helia-for-pkc-B6cVl9Fj.js → helia-for-pkc-DldRnBHX.js} +33 -33
  29. package/dist/bundled/chunks/{local-community-CEsw9IC3.js → local-community-9i6vs_-P.js} +1 -1
  30. package/dist/bundled/chunks/{local-community-JxRohlLp.js → local-community-BjljrKks.js} +83 -127
  31. package/dist/bundled/chunks/{node-DsWFSaNV.js → node-BNoBGxyk.js} +117 -38
  32. package/dist/bundled/chunks/{page-sort-scoring-iqMGLuRC.js → page-sort-scoring-BCqpbgnJ.js} +1 -1
  33. package/dist/bundled/chunks/{rpc-local-community-jndojGZl.js → rpc-local-community-CuL4H_vR.js} +9 -6
  34. package/dist/bundled/chunks/{util-CYgZRMVL.js → util-D104b59J.js} +1 -1
  35. package/dist/bundled/chunks/{util-Bna9pur0.js → util-TZLcBbZd.js} +5 -2
  36. package/dist/bundled/chunks/{validate-package-factories-FeyM9Tw1.js → validate-package-factories-DGlKaHzi.js} +2 -2
  37. package/dist/bundled/index.js +1 -1
  38. package/dist/bundled/page-sorts.js +1 -1
  39. package/dist/bundled/rpc/src/index.js +4 -4
  40. package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +12 -0
  41. package/dist/node/clients/rpc-client/pkc-rpc-client.js +138 -37
  42. package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
  43. package/dist/node/errors.d.ts +2 -0
  44. package/dist/node/errors.js +2 -0
  45. package/dist/node/errors.js.map +1 -1
  46. package/dist/node/generated-version.d.ts +1 -1
  47. package/dist/node/generated-version.js +1 -1
  48. package/dist/node/pkc-error.d.ts +1 -1
  49. package/dist/node/publications/comment/schema.d.ts +4 -0
  50. package/dist/node/publications/comment/schema.js +2 -1
  51. package/dist/node/publications/comment/schema.js.map +1 -1
  52. package/dist/node/runtime/node/community/db-handler.js +44 -91
  53. package/dist/node/runtime/node/community/db-handler.js.map +1 -1
  54. package/dist/node/runtime/node/community/local-community/comment-updates.js +1 -1
  55. package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
  56. package/dist/node/runtime/node/community/page-generator.d.ts +2 -0
  57. package/dist/node/runtime/node/community/page-generator.js +3 -2
  58. package/dist/node/runtime/node/community/page-generator.js.map +1 -1
  59. package/dist/node/runtime/node/util.d.ts +1 -0
  60. package/dist/node/runtime/node/util.js +3 -2
  61. package/dist/node/runtime/node/util.js.map +1 -1
  62. package/dist/node/signer/signatures.js +6 -1
  63. package/dist/node/signer/signatures.js.map +1 -1
  64. 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, In as CommentUpdateForChallengeVerificationSchema, It as ChallengeVerificationMessageSchema, J as removeUndefinedValuesRecursively, Jt as version_default, Lr as PKCError, Mr as FailedToFetchCommentIpfsFromGatewaysError, Mt as ChallengeMessageSchema, Nr as FailedToFetchCommentUpdateFromGatewaysError, Ot as TimeoutError, Pt as ChallengeRequestMessageSchema, Q as retryKuboIpfsAdd, Rr as messages, Sr as e$1, St as trackUpdatingComment, T as ipnsNameToIpnsOverPubsubTopic, Tt as untrackUpdatingComment, U as rejectWhenCommunityStopsOrAborts, X as resolveWhenPredicateIsTrue, Y as replaceXWithY, _t as listUpdatingCommunities, a as calculateStringSizeSameAsIpfsAddCidV0Sync, at as timestamp, br as t$1, cn as CommunityAnchorSchema, d as deepMergeRuntimeFields, dt as findStartedCommunity, et as shortifyAddress, ft as findUpdatingComment, gr as n$2, gt as listUpdatingComments, hr as isStringDomain, ht as listStartedCommunities, i as calculateStringSizeSameAsIpfsAddCidV0, it as throwIfAbortSignalAborted, jn as CommentIpfsSchema, jr as require_retry$1, k as isIpns, kt as pTimeout, ni as en_default, nt as sleepUntilTimeoutOrAbort, ot as waitForUpdateInCommunityInstanceWithErrorAndTimeout, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, tt as shortifyCid, u as createAbortError, vr as n$1, vt as refreshTrackedCommentAliases, wr as r, x as getPostUpdateTimestampRange, xn as PubsubTopicSchema, xr as e, zn as CommentUpdateSchema, zr as logger_default } from "./util-Bna9pur0.js";
3
- import { $n as buildRuntimeCommunityFields, $t as RpcPublishCommunityListParamSchema, A as findCommentInParsedPages, Ar as setNativeFunctions$1, At as parseRpcCommentUpdateEventWithPKCErrorIfItFails, B as GenericStateClient, Bn as verifyCommunityEdit, Br as t$3, Bt as RpcCommunityIdentifierParamSchema, C as RepliesPages, Cn as signCommentModeration, Ct as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, D as extractCommunityRuntimeFieldsFromParsedPages, Dn as signCommunityEdit, Dt as parseJsonWithPKCErrorIfFails, Er as monitorCommunitiesDirectory, Et as parseDecryptedChallengeWithPKCErrorIfItFails, F as cloneCrosspostForRuntime, Fn as verifyCommentIpfs, Ft as RpcAuthorNameParamSchema, G as PKCTypedEmitter, Gn as getAuthorNameFromRuntime, Gt as RpcExportCommunityParamSchema, H as InflightResourceTypes, Hn as verifyVote, Ht as RpcEditCommunityParamSchema, I as collectCrosspostAuthorsToResolve, In as verifyCommentModeration, It as RpcCancelExportParamSchema, J as decodeRpcChallengeRequestPubsubMsg, Jn as CreateCommunityListWithCidOptionsSchema, Jr as NAME_RESOLVED_TRUE_TTL_MS, Jt as RpcFetchCidResultSchema, K as decodeRpcChallengeAnswerPubsubMsg, Kn as getAuthorNameFromWire, Kr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, Kt as RpcExportCommunityResultSchema, Ln as verifyCommentPubsubMessage, Lr as t$5, Lt as RpcCidParamSchema, M as parseRawPages, Mr as findCommunitiesEntry, Nn as verifyChallengeVerification, Nr as toCommunitiesEntry, Nt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, O as findCommentInPageInstance, On as signCommunityList, Ot as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, P as applyNameResolvedCacheToCrosspost, Pn as verifyCommentEdit, Pt as RpcAnchorPublishPreparationResultSchema, Qr as nativeFunctions$2, Qt as RpcPublishChallengeAnswersParamSchema, R as stripNameResolvedFromCrosspost, Rn as verifyCommentUpdate, Rt as RpcCommentRepliesPageParamSchema, Sn as signCommentEdit, Sr as getDefaultDataPath, St as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, Tr as listCommunitiesSync, Tt as parseDecryptedChallengeVerification, Un as buildRuntimeAuthor, Ur as t$2, Ut as RpcExportCommunityModLogsParamSchema, V as InflightFetchManager, Vn as verifyCommunityList, Vr as n$3, Vt as RpcCommunityPageParamSchema, Wn as cleanWireAuthor, Wr as t$4, Wt as RpcExportCommunityModLogsResultSchema, Xn as MAX_COMMUNITY_LIST_SIZE_BYTES, Xt as RpcFetchCommunityListResultSchema, Y as decodeRpcChallengeVerificationPubsubMsg, Yn as CreateNewCommunityListOptionsSchema, Yr as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, Yt as RpcFetchCommunityListParamSchema, Zt as RpcPublishAnchorRecordParamSchema, _n as signChallengeAnswer, _t as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, an as RpcUnsubscribeParamSchema, b as KeyvBetterSqlite3, br as findLocalCommunityAddress, ct as parseCommentUpdateSchemaWithPKCErrorIfItFails, dn as decryptEd25519AesGcm, en as RpcPublishCommunityListResultSchema, er as getCommunityAddressFromRecord, et as parseCidStringSchemaWithPKCErrorIfItFails, ft as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, gn as cleanUpBeforePublishing, gt as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, hr as createKuboRpcClient, ht as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, in as RpcSuccessResultSchema, ir as decode, it as parseCommentIpfsSchemaWithPKCErrorIfItFails, jn as verifyChallengeMessage, jr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, jt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, k as findCommentInPageInstanceRecursively, kn as signVote, kt as parseRpcCommentEventWithPKCErrorIfItFails, l as pkcJsPageSorts, ln as createSigner, lr as getPKCAddressFromPublicKeySync, lt as parseCommunityAddressWithPKCErrorIfItFails, m as pkcJsChallenges, mt as parseCommunityListSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as RpcResolveAuthorNameResultSchema, nr as getCommunityPublicKeyFromWire, on as findCommunityRecordNameMismatch, or as getBufferedPKCAddressFromPublicKey, ot as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, pn as encryptEd25519AesGcm, q as decodeRpcChallengePubsubMsg, qn as normalizeCreatePublicationAuthor, qr as NAME_RESOLVED_FALSE_TTL_MS, qt as RpcFetchCidParamSchema, rn as RpcSubscriptionIdResultSchema, rr as normalizeCommunityInputFromCommunity, rt as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, sn as require_lib$1, st as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, t as RpcLocalCommunity, tn as RpcPublishedAnchorRecordResultSchema, tr as getCommunityNameFromWire, un as createAnchorIpnsRecord$1, v as TrackedInstanceRegistry, vt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, x as RemoteCommunity, xn as signComment, xt as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, y as LRUCache, yn as signChallengeRequest, z as PKCClientsManager, zt as RpcCommunitiesChangeEventResultSchema } from "./rpc-local-community-jndojGZl.js";
4
- import { s as getHeliaDebugContext } from "./util-CYgZRMVL.js";
2
+ import { $ as retryKuboIpfsAddAndProvide, At as ChallengeAnswerMessageSchema, C as hideClassPrivateProps, D as isIpfsCid, Dt as require_sha256, E as isAbortError, Et as untrackUpdatingCommunity, H as rejectWhenAbortSignalFires, Hr as setErrorMap, In as CommentUpdateForChallengeVerificationSchema, It as ChallengeVerificationMessageSchema, J as removeUndefinedValuesRecursively, Jt as version_default, Lr as PKCError, Mr as FailedToFetchCommentIpfsFromGatewaysError, Mt as ChallengeMessageSchema, Nr as FailedToFetchCommentUpdateFromGatewaysError, Ot as TimeoutError, Pt as ChallengeRequestMessageSchema, Q as retryKuboIpfsAdd, Rr as messages, Sr as e$1, St as trackUpdatingComment, T as ipnsNameToIpnsOverPubsubTopic, Tt as untrackUpdatingComment, U as rejectWhenCommunityStopsOrAborts, X as resolveWhenPredicateIsTrue, Y as replaceXWithY, _t as listUpdatingCommunities, a as calculateStringSizeSameAsIpfsAddCidV0Sync, at as timestamp, br as t$1, cn as CommunityAnchorSchema, d as deepMergeRuntimeFields, dt as findStartedCommunity, et as shortifyAddress, ft as findUpdatingComment, gr as n$2, gt as listUpdatingComments, hr as isStringDomain, ht as listStartedCommunities, i as calculateStringSizeSameAsIpfsAddCidV0, it as throwIfAbortSignalAborted, jn as CommentIpfsSchema, jr as require_retry$1, k as isIpns, kt as pTimeout, ni as en_default, nt as sleepUntilTimeoutOrAbort, ot as waitForUpdateInCommunityInstanceWithErrorAndTimeout, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, tt as shortifyCid, u as createAbortError, vr as n$1, vt as refreshTrackedCommentAliases, wr as r, x as getPostUpdateTimestampRange, xn as PubsubTopicSchema, xr as e, zn as CommentUpdateSchema, zr as logger_default } from "./util-TZLcBbZd.js";
3
+ import { $n as buildRuntimeCommunityFields, $t as RpcPublishCommunityListParamSchema, A as findCommentInParsedPages, Ar as setNativeFunctions$1, At as parseRpcCommentUpdateEventWithPKCErrorIfItFails, B as GenericStateClient, Bn as verifyCommunityEdit, Br as t$3, Bt as RpcCommunityIdentifierParamSchema, C as RepliesPages, Cn as signCommentModeration, Ct as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, D as extractCommunityRuntimeFieldsFromParsedPages, Dn as signCommunityEdit, Dt as parseJsonWithPKCErrorIfFails, Er as monitorCommunitiesDirectory, Et as parseDecryptedChallengeWithPKCErrorIfItFails, F as cloneCrosspostForRuntime, Fn as verifyCommentIpfs, Ft as RpcAuthorNameParamSchema, G as PKCTypedEmitter, Gn as getAuthorNameFromRuntime, Gt as RpcExportCommunityParamSchema, H as InflightResourceTypes, Hn as verifyVote, Ht as RpcEditCommunityParamSchema, I as collectCrosspostAuthorsToResolve, In as verifyCommentModeration, It as RpcCancelExportParamSchema, J as decodeRpcChallengeRequestPubsubMsg, Jn as CreateCommunityListWithCidOptionsSchema, Jr as NAME_RESOLVED_TRUE_TTL_MS, Jt as RpcFetchCidResultSchema, K as decodeRpcChallengeAnswerPubsubMsg, Kn as getAuthorNameFromWire, Kr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, Kt as RpcExportCommunityResultSchema, Ln as verifyCommentPubsubMessage, Lr as t$5, Lt as RpcCidParamSchema, M as parseRawPages, Mr as findCommunitiesEntry, Nn as verifyChallengeVerification, Nr as toCommunitiesEntry, Nt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, O as findCommentInPageInstance, On as signCommunityList, Ot as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, P as applyNameResolvedCacheToCrosspost, Pn as verifyCommentEdit, Pt as RpcAnchorPublishPreparationResultSchema, Qr as nativeFunctions$2, Qt as RpcPublishChallengeAnswersParamSchema, R as stripNameResolvedFromCrosspost, Rn as verifyCommentUpdate, Rt as RpcCommentRepliesPageParamSchema, Sn as signCommentEdit, Sr as getDefaultDataPath, St as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, Tr as listCommunitiesSync, Tt as parseDecryptedChallengeVerification, Un as buildRuntimeAuthor, Ur as t$2, Ut as RpcExportCommunityModLogsParamSchema, V as InflightFetchManager, Vn as verifyCommunityList, Vr as n$3, Vt as RpcCommunityPageParamSchema, Wn as cleanWireAuthor, Wr as t$4, Wt as RpcExportCommunityModLogsResultSchema, Xn as MAX_COMMUNITY_LIST_SIZE_BYTES, Xt as RpcFetchCommunityListResultSchema, Y as decodeRpcChallengeVerificationPubsubMsg, Yn as CreateNewCommunityListOptionsSchema, Yr as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, Yt as RpcFetchCommunityListParamSchema, Zt as RpcPublishAnchorRecordParamSchema, _n as signChallengeAnswer, _t as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, an as RpcUnsubscribeParamSchema, b as KeyvBetterSqlite3, br as findLocalCommunityAddress, ct as parseCommentUpdateSchemaWithPKCErrorIfItFails, dn as decryptEd25519AesGcm, en as RpcPublishCommunityListResultSchema, er as getCommunityAddressFromRecord, et as parseCidStringSchemaWithPKCErrorIfItFails, ft as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, gn as cleanUpBeforePublishing, gt as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, hr as createKuboRpcClient, ht as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, in as RpcSuccessResultSchema, ir as decode, it as parseCommentIpfsSchemaWithPKCErrorIfItFails, jn as verifyChallengeMessage, jr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, jt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, k as findCommentInPageInstanceRecursively, kn as signVote, kt as parseRpcCommentEventWithPKCErrorIfItFails, l as pkcJsPageSorts, ln as createSigner, lr as getPKCAddressFromPublicKeySync, lt as parseCommunityAddressWithPKCErrorIfItFails, m as pkcJsChallenges, mt as parseCommunityListSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as RpcResolveAuthorNameResultSchema, nr as getCommunityPublicKeyFromWire, on as findCommunityRecordNameMismatch, or as getBufferedPKCAddressFromPublicKey, ot as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, pn as encryptEd25519AesGcm, q as decodeRpcChallengePubsubMsg, qn as normalizeCreatePublicationAuthor, qr as NAME_RESOLVED_FALSE_TTL_MS, qt as RpcFetchCidParamSchema, rn as RpcSubscriptionIdResultSchema, rr as normalizeCommunityInputFromCommunity, rt as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, sn as require_lib$1, st as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, t as RpcLocalCommunity, tn as RpcPublishedAnchorRecordResultSchema, tr as getCommunityNameFromWire, un as createAnchorIpnsRecord$1, v as TrackedInstanceRegistry, vt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, x as RemoteCommunity, xn as signComment, xt as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, y as LRUCache, yn as signChallengeRequest, z as PKCClientsManager, zt as RpcCommunitiesChangeEventResultSchema } from "./rpc-local-community-CuL4H_vR.js";
4
+ import { s as getHeliaDebugContext } from "./util-D104b59J.js";
5
5
  import path from "path";
6
6
  import assert from "assert";
7
7
  import fs from "fs";
@@ -30557,6 +30557,7 @@ const parseRpcExportCommunityModLogsResult = (result) => RpcExportCommunityModLo
30557
30557
  //#region dist/node/clients/rpc-client/pkc-rpc-client.js
30558
30558
  const log = logger_default("pkc-js:PKCRpcClient");
30559
30559
  const WEBSOCKET_READY_STATE_CLOSED = 3;
30560
+ const WEBSOCKET_CLOSE_NORMAL = 1e3;
30560
30561
  const DESTROY_SOCKET_CLOSE_TIMEOUT_MS = 5e3;
30561
30562
  const scheduleMacrotask = setTimeout.bind(globalThis);
30562
30563
  function isRpcSubscriptionNotification(message) {
@@ -30575,6 +30576,9 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
30575
30576
  this._resubscribeCalls = /* @__PURE__ */ new Map();
30576
30577
  this._publishSubscriptionIds = /* @__PURE__ */ new Set();
30577
30578
  this._hasConnectedBefore = false;
30579
+ this._failedReconnectAttempts = 0;
30580
+ this._callsAwaitingResponse = /* @__PURE__ */ new Set();
30581
+ this._backgroundSubscriptionsToRetry = /* @__PURE__ */ new Set();
30578
30582
  this._socketsWithNotificationHandler = /* @__PURE__ */ new WeakSet();
30579
30583
  this._reconnectBaseIntervalMs = 1e3;
30580
30584
  this._reconnectMaxIntervalMs = 3e4;
@@ -30608,7 +30612,6 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
30608
30612
  async _init() {
30609
30613
  const log = logger_default("pkc-js:pkc-rpc-client:_init");
30610
30614
  if (this._destroyRequested) return;
30611
- let lastWebsocketError;
30612
30615
  if (!(this._webSocketClient instanceof Client)) {
30613
30616
  this.setState("connecting");
30614
30617
  this._webSocketClient = new Client(this._websocketServerUrl, {
@@ -30622,42 +30625,55 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
30622
30625
  this._attachNotificationHandler();
30623
30626
  this._reconnectIntervalMs = this._reconnectBaseIntervalMs;
30624
30627
  this._webSocketClient.setReconnectInterval(this._reconnectIntervalMs);
30628
+ this._failedReconnectAttempts = 0;
30629
+ this._lastWebsocketError = void 0;
30625
30630
  const isReconnect = this._hasConnectedBefore;
30626
30631
  this._hasConnectedBefore = true;
30627
30632
  this.setState("connected");
30628
30633
  if (isReconnect) this._resubscribeAllAfterReconnect();
30634
+ this._retryBackgroundSubscriptions();
30629
30635
  });
30630
30636
  this._webSocketClient.on("error", (error) => {
30631
30637
  this._backOffReconnectInterval();
30632
- lastWebsocketError = error;
30638
+ this._lastWebsocketError = error;
30633
30639
  if (this._destroyRequested) {
30634
30640
  log("Ignoring websocket error emitted after destroy request", error);
30635
30641
  return;
30636
30642
  }
30637
30643
  if ((typeof error?.message === "string" ? error.message : "").includes("Unexpected server response: 403")) {
30638
- lastWebsocketError = new PKCError("ERR_RPC_AUTH_REQUIRED", { rpcServerUrl: this._websocketServerUrl });
30644
+ this._lastWebsocketError = new PKCError("ERR_RPC_AUTH_REQUIRED", { rpcServerUrl: this._websocketServerUrl });
30639
30645
  this._webSocketClient.setAutoReconnect(false);
30640
- this.emit("error", lastWebsocketError);
30646
+ this.emit("error", this._lastWebsocketError);
30641
30647
  this.setState("failed");
30642
30648
  return;
30643
30649
  }
30650
+ const errorToEmit = this._wrapIfFailedReconnectAttempt(error);
30644
30651
  try {
30645
- this.emit("error", error);
30652
+ this.emit("error", errorToEmit);
30646
30653
  } catch (emitError) {
30647
30654
  log.error("No listener received the RPC websocket error", this._websocketServerUrl, emitError);
30648
30655
  }
30649
30656
  });
30650
- this._webSocketClient.on("close", () => {
30657
+ this._webSocketClient.on("close", (closeCode, closeReason) => {
30651
30658
  if (!this._destroyRequested) log.error("connection with web socket has been closed", this._websocketServerUrl);
30652
30659
  this._openConnectionPromise = void 0;
30653
30660
  this.setState("stopped");
30654
- if (!this._destroyRequested) this._failPublicationsLostWithConnection();
30661
+ if (this._destroyRequested) return;
30662
+ this._lastClose = {
30663
+ closeCode,
30664
+ closeReason: String(closeReason ?? "")
30665
+ };
30666
+ this._rejectCallsLostWithConnection();
30667
+ this._failPublicationsLostWithConnection();
30668
+ if (!this._webSocketClient.willReconnect()) return;
30669
+ if (closeCode === WEBSOCKET_CLOSE_NORMAL) this._scheduleReconnectAfterCleanClose();
30670
+ this.setState("connecting");
30655
30671
  });
30656
30672
  const originalWebsocketCall = this._webSocketClient.call.bind(this._webSocketClient);
30657
30673
  this._webSocketClient.call = async (...args) => {
30658
30674
  try {
30659
30675
  await this._init();
30660
- return await pTimeout(originalWebsocketCall(...args), {
30676
+ return await pTimeout(this._rejectIfConnectionIsLost(originalWebsocketCall(...args), args[0]), {
30661
30677
  milliseconds: this._callTimeoutMs,
30662
30678
  message: new PKCError("ERR_RPC_CALL_TIMED_OUT", {
30663
30679
  rpcMethod: args[0],
@@ -30676,17 +30692,10 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
30676
30692
  };
30677
30693
  }
30678
30694
  if (this._webSocketClient.ready) return;
30679
- if (!this._openConnectionPromise) this._openConnectionPromise = pTimeout(resolveWhenPredicateIsTrue({
30680
- toUpdate: this,
30681
- predicate: () => {
30682
- if (this.state === "connected") return true;
30683
- if (lastWebsocketError instanceof PKCError) throw lastWebsocketError;
30684
- return false;
30685
- },
30686
- eventName: "statechange"
30687
- }), { milliseconds: this._timeoutSeconds * 1e3 });
30695
+ if (!this._openConnectionPromise) this._openConnectionPromise = this._waitForConnectionToOpen();
30696
+ const openConnectionPromise = this._openConnectionPromise;
30688
30697
  try {
30689
- await this._openConnectionPromise;
30698
+ await openConnectionPromise;
30690
30699
  } catch (e) {
30691
30700
  if (this._destroyRequested) {
30692
30701
  log("Aborted RPC connection before it finished opening because destroy was requested", this._websocketServerUrl);
@@ -30694,14 +30703,30 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
30694
30703
  }
30695
30704
  const err = e instanceof PKCError ? e : new PKCError("ERR_FAILED_TO_OPEN_CONNECTION_TO_RPC", {
30696
30705
  timeoutSeconds: this._timeoutSeconds,
30697
- error: lastWebsocketError,
30706
+ error: this._lastWebsocketError,
30698
30707
  rpcServerUrl: this._websocketServerUrl
30699
30708
  });
30700
- this.setState("failed");
30709
+ if (this.state !== "failed" && this._openConnectionPromise === openConnectionPromise) this._openConnectionPromise = void 0;
30701
30710
  this.emit("error", err);
30702
30711
  throw err;
30703
30712
  }
30704
30713
  }
30714
+ async _waitForConnectionToOpen() {
30715
+ let onStateChange = () => {};
30716
+ const connectionOpened = new Promise((resolve, reject) => {
30717
+ onStateChange = () => {
30718
+ if (this.state === "connected") resolve();
30719
+ else if (this._lastWebsocketError instanceof PKCError) reject(this._lastWebsocketError);
30720
+ };
30721
+ this.on("statechange", onStateChange);
30722
+ onStateChange();
30723
+ });
30724
+ try {
30725
+ await pTimeout(connectionOpened, { milliseconds: this._timeoutSeconds * 1e3 });
30726
+ } finally {
30727
+ this.removeListener("statechange", onStateChange);
30728
+ }
30729
+ }
30705
30730
  async destroy() {
30706
30731
  if (this._destroyRequested) return;
30707
30732
  this._destroyRequested = true;
@@ -30718,6 +30743,7 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
30718
30743
  }
30719
30744
  this._resubscribeCalls.clear();
30720
30745
  this._publishSubscriptionIds.clear();
30746
+ this._backgroundSubscriptionsToRetry.clear();
30721
30747
  this._serverIdByLocalId.clear();
30722
30748
  this._localIdByServerId.clear();
30723
30749
  try {
@@ -30785,6 +30811,38 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
30785
30811
  if (this._subscriptionEvents[subscriptionId].listenerCount(message.params.event) === 0) this._pendingSubscriptionMsgs[subscriptionId].push(message);
30786
30812
  else this._subscriptionEvents[subscriptionId].emit(message.params.event, message);
30787
30813
  }
30814
+ _scheduleReconnectAfterCleanClose() {
30815
+ const webSocketClient = this._webSocketClient;
30816
+ webSocketClient.reconnect_timer_id = setTimeout(() => {
30817
+ if (!this._destroyRequested && this._webSocketClient.willReconnect()) this._webSocketClient.connect();
30818
+ }, this._reconnectIntervalMs);
30819
+ }
30820
+ _wrapIfFailedReconnectAttempt(error) {
30821
+ if (!this._hasConnectedBefore || this.state === "connected") return error;
30822
+ this._failedReconnectAttempts++;
30823
+ return new PKCError("ERR_RPC_RECONNECT_FAILED", {
30824
+ rpcServerUrl: this._websocketServerUrl,
30825
+ ...this._lastClose,
30826
+ attempt: this._failedReconnectAttempts,
30827
+ nextRetryMs: this._reconnectIntervalMs,
30828
+ error: error.error ?? error
30829
+ });
30830
+ }
30831
+ _rejectIfConnectionIsLost(call, rpcMethod) {
30832
+ return new Promise((resolve, reject) => {
30833
+ const rejectWithLostConnection = () => reject(new PKCError("ERR_RPC_CONNECTION_LOST", {
30834
+ rpcMethod,
30835
+ rpcServerUrl: this._websocketServerUrl,
30836
+ ...this._lastClose
30837
+ }));
30838
+ this._callsAwaitingResponse.add(rejectWithLostConnection);
30839
+ call.then(resolve, reject).finally(() => this._callsAwaitingResponse.delete(rejectWithLostConnection));
30840
+ });
30841
+ }
30842
+ _rejectCallsLostWithConnection() {
30843
+ for (const rejectCall of this._callsAwaitingResponse) rejectCall();
30844
+ this._callsAwaitingResponse.clear();
30845
+ }
30788
30846
  _backOffReconnectInterval() {
30789
30847
  if (!(this._webSocketClient instanceof Client)) return;
30790
30848
  this._reconnectIntervalMs = Math.min(this._reconnectIntervalMs * 2, this._reconnectMaxIntervalMs);
@@ -30803,6 +30861,7 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
30803
30861
  _resubscribeAllAfterReconnect() {
30804
30862
  for (const subscriptionId of [...this._resubscribeCalls.keys()]) this._resubscribe(subscriptionId).catch((error) => {
30805
30863
  if (this._destroyRequested) return;
30864
+ if (error?.code === "ERR_RPC_CONNECTION_LOST") return;
30806
30865
  if (error?.code === "ERR_RPC_COMMUNITY_NOT_RUNNING") {
30807
30866
  log("Not re-establishing start(), the community was stopped on purpose", subscriptionId);
30808
30867
  this._resubscribeCalls.delete(subscriptionId);
@@ -30821,6 +30880,22 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
30821
30880
  } });
30822
30881
  });
30823
30882
  }
30883
+ async _runBackgroundSubscription(subscribe) {
30884
+ try {
30885
+ await subscribe();
30886
+ } catch (error) {
30887
+ if (!this._destroyRequested && this.state !== "connected") this._backgroundSubscriptionsToRetry.add(subscribe);
30888
+ throw error;
30889
+ }
30890
+ }
30891
+ _retryBackgroundSubscriptions() {
30892
+ const subscriptions = [...this._backgroundSubscriptionsToRetry];
30893
+ this._backgroundSubscriptionsToRetry.clear();
30894
+ for (const subscribe of subscriptions) this._runBackgroundSubscription(subscribe).catch((error) => {
30895
+ if (this._destroyRequested) return;
30896
+ log.error("Failed to subscribe after connecting to the RPC server", this._websocketServerUrl, error);
30897
+ });
30898
+ }
30824
30899
  async _resubscribe(subscriptionId) {
30825
30900
  const call = this._resubscribeCalls.get(subscriptionId);
30826
30901
  if (!call || this._destroyRequested) return;
@@ -31030,23 +31105,27 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
31030
31105
  return parseRpcResolveAuthorNameResult(await this._webSocketClient.call("resolveAuthorName", [resolveAuthorNameArgs]));
31031
31106
  }
31032
31107
  async initalizeCommunitieschangeEvent() {
31033
- const { subscriptionId } = await this._subscribe("communitiesSubscribe", [], "resubscribe");
31034
- this.getSubscription(subscriptionId).on("communitieschange", (res) => {
31035
- const parsed = RpcCommunitiesChangeEventResultSchema.loose().safeParse(res.params.result);
31036
- if (!parsed.success) return this.emit("error", new PKCError("ERR_INVALID_RPC_COMMUNITIES_SCHEMA", {
31037
- zodError: parsed.error,
31038
- result: res.params.result
31039
- }));
31040
- this.emit("communitieschange", { communities: parsed.data.communities.map((entry) => toCommunitiesEntry(entry)) });
31108
+ await this._runBackgroundSubscription(async () => {
31109
+ const { subscriptionId } = await this._subscribe("communitiesSubscribe", [], "resubscribe");
31110
+ this.getSubscription(subscriptionId).on("communitieschange", (res) => {
31111
+ const parsed = RpcCommunitiesChangeEventResultSchema.loose().safeParse(res.params.result);
31112
+ if (!parsed.success) return this.emit("error", new PKCError("ERR_INVALID_RPC_COMMUNITIES_SCHEMA", {
31113
+ zodError: parsed.error,
31114
+ result: res.params.result
31115
+ }));
31116
+ this.emit("communitieschange", { communities: parsed.data.communities.map((entry) => toCommunitiesEntry(entry)) });
31117
+ });
31118
+ this.emitAllPendingMessages(subscriptionId);
31041
31119
  });
31042
- this.emitAllPendingMessages(subscriptionId);
31043
31120
  }
31044
31121
  async initalizeSettingschangeEvent() {
31045
- const { subscriptionId } = await this._subscribe("settingsSubscribe", [], "resubscribe");
31046
- this.getSubscription(subscriptionId).on("settingschange", (res) => {
31047
- this.emit("settingschange", res.params.result);
31122
+ await this._runBackgroundSubscription(async () => {
31123
+ const { subscriptionId } = await this._subscribe("settingsSubscribe", [], "resubscribe");
31124
+ this.getSubscription(subscriptionId).on("settingschange", (res) => {
31125
+ this.emit("settingschange", res.params.result);
31126
+ });
31127
+ this.emitAllPendingMessages(subscriptionId);
31048
31128
  });
31049
- this.emitAllPendingMessages(subscriptionId);
31050
31129
  }
31051
31130
  async fetchCid(args) {
31052
31131
  const parsedFetchCidArgs = parseRpcFetchCidParam(args);
@@ -35823,7 +35902,7 @@ var PKC$1 = class extends PKCTypedEmitter {
35823
35902
  this.clients.libp2pJsClients = {};
35824
35903
  if (!this.libp2pJsClientsOptions) return;
35825
35904
  if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
35826
- const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-B6cVl9Fj.js");
35905
+ const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-DldRnBHX.js");
35827
35906
  for (const clientOptions of this.libp2pJsClientsOptions) {
35828
35907
  const heliaNode = await createLibp2pJsClientOrUseExistingOne({
35829
35908
  ...clientOptions,
@@ -36188,7 +36267,7 @@ var PKC$1 = class extends PKCTypedEmitter {
36188
36267
  const log = logger_default("pkc-js:pkc:createLocalCommunity");
36189
36268
  log.trace("Received community options to create a local community instance:", options);
36190
36269
  if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
36191
- const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-CEsw9IC3.js");
36270
+ const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-9i6vs_-P.js");
36192
36271
  const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
36193
36272
  const community = new LocalCommunity(this);
36194
36273
  if (isLocalCommunity) {
@@ -1,4 +1,4 @@
1
- import { bn as PageSortFileSchema, hr as isStringDomain, v as getEquivalentCommunityAddresses } from "./util-Bna9pur0.js";
1
+ import { bn as PageSortFileSchema, hr as isStringDomain, v as getEquivalentCommunityAddresses } from "./util-TZLcBbZd.js";
2
2
  //#region dist/node/pages/page-sort-scoring.js
3
3
  function validatePageSortFile(rawFile) {
4
4
  const validated = PageSortFileSchema.parse(rawFile);
@@ -1,7 +1,7 @@
1
1
  import { i as __toESM, n as __exportAll, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { $r as string, $t as CreateCommunityEditPublicationOptionsWithRefinementSchema, A as isIpnsPath, An as CommentIpfsReservedFields, Ar as e$4, Bn as CommentUpdateSignedPropertyNames, Br as require_supports_color, C as hideClassPrivateProps, Cn as CreateVoteUserOptionsWithRefinementSchema, Cr as t$11, Ct as trackUpdatingCommunity, D as isIpfsCid, Dn as VoteSignedPropertyNames, Dr as r$7, Dt as require_sha256$1, E as isAbortError, Er as n$8, Et as untrackUpdatingCommunity, Fn as CommentUpdateChallengeReservedFieldNames, Fr as FailedToFetchGenericIpfsFromGatewaysError, Ft as ChallengeRequestMessageSignedPropertyNames, Gn as ModQueuePageIpfsSchema, Gr as boolean, Gt as PKCParsedOptionsSchema, Ht as DecryptedChallengeVerificationSchema, Ir as FailedToFetchPageIpfsFromGatewaysError, Jn as CommentEditChallengeRequestToEncryptSchema, Jr as looseObject, K as removeNullUndefinedEmptyObjectsValuesRecursively, Kn as PageIpfsSchema, Kr as custom, Kt as PKCUserOptionBaseSchema, L as isRequestPubsubPublicationOfPost, Ln as CommentUpdateForChallengeVerificationSignedPropertyNames, Lr as PKCError, Lt as ChallengeVerificationMessageSignedPropertyNames, Mr as FailedToFetchCommentIpfsFromGatewaysError, Nn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Nr as FailedToFetchCommentUpdateFromGatewaysError, Nt as ChallengeMessageSignedPropertyNames, O as isIpfsPath, Or as t$10, Pn as CommentSignedPropertyNames, Pr as FailedToFetchCommunityFromGatewaysError, Qn as CommentEditSignedPropertyNames, Qr as record, Qt as CommunityEditPubsubMessagePublicationSchema, R as isRequestPubsubPublicationOfReply, Rn as CommentUpdateReservedFields, Rr as messages, Rt as DecryptedChallengeAnswerSchema, S as hasTransientNetworkErrorCode, Sn as RpcRemoteCommunityUpdateEventResultSchema, Sr as e$5, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Tr as t$12, Un as CreateCommentOptionsWithRefinementSchema, Ur as _enum, Ut as NameResolveCacheOptionsSchema, V as raceAgainstAbort, Vr as require_ms$1, Vt as DecryptedChallengeSchema, Wn as GetPageParamSchema, Wr as array, Wt as NameResolverSerializedSchema, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xr as object, Yr as number, Yt as CommunityEditPublicationChallengeRequestToEncryptSchema, Zr as preprocess, Zt as CommunityEditPublicationSignedPropertyNames, _n as CreateRpcCommunityFunctionArgumentSchema, an as CreateCommentModerationOptionsWithRefinementSchema, ar as ChallengeAnswersSchema, at as timestamp, bn as PageSortFileSchema, br as t$13, cr as CommunityAddressSchema, d as deepMergeRuntimeFields, dn as CommunityExportRecordsSchema, dr as JsonSignatureSchema, dt as findStartedCommunity, ei as union, en as CommentModerationChallengeRequestToEncryptSchema, er as CreateCommentEditOptionsWithRefinementSchema, et as shortifyAddress, f as derivePublicationFromChallengeRequest, fn as CommunityIpfsReservedFields, fr as PKCTimestampSchema, gn as CreateRemoteCommunityFunctionArgumentSchema, gr as n$9, h as fetchAndValidateIpnsRecordFromGateway, hn as CreateNewLocalCommunityUserOptionsSchema, hr as isStringDomain, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as throwIfAbortSignalAborted, jn as CommentIpfsSchema, jr as require_retry$2, jt as ChallengeAnswerMessageSignedPropertyNames, k as isIpns, kn as CommentChallengeRequestToEncryptSchema, kr as t$9, kt as pTimeout, ln as CommunityChallengeSettingSchema, lr as CommunityAuthorChallengeReservedFieldNames, m as extractNetworkErrorDetails, mn as CommunitySignedPropertyNames, mr as areEquivalentNames, mt as forgetTrackedUpdatingCommunityName, nr as AuthorCommentIpfsReservedFields, nt as sleepUntilTimeoutOrAbort, on as ChallengeFileFactorySchema, or as CidPathSchema, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pr as ProtocolVersionSchema, pt as findUpdatingCommunity, qn as isReservedObjectKey, qr as literal, qt as PKCUserOptionsSchema, r as calculateIpfsCidV0, rn as CommentModerationSignedPropertyNames, rr as AuthorPubsubSchema, sn as ChallengeFileSchema, sr as CidStringSchema, t as areEquivalentCommunityAddresses, tn as CommentModerationPubsubMessagePublicationSchema, tr as AuthorAddressSchema, tt as shortifyCid, u as createAbortError, un as CommunityEditOptionsSchema, ur as CreateSignerSchema, vn as ExportCommunityModLogsOptionsSchema, vr as n$10, w as interruptibleSleep, wn as VoteChallengeRequestToEncryptSchema, wr as r$8, wt as untrackStartedCommunity, xr as e$6, xt as trackStartedCommunity, yn as PageSortFileFactorySchema, yt as refreshTrackedCommunityAliases, z as pubsubTopicToDhtKey, zn as CommentUpdateSchema, zr as logger_default } from "./util-Bna9pur0.js";
2
+ import { $r as string, $t as CreateCommunityEditPublicationOptionsWithRefinementSchema, A as isIpnsPath, An as CommentIpfsReservedFields, Ar as e$4, Bn as CommentUpdateSignedPropertyNames, Br as require_supports_color, C as hideClassPrivateProps, Cn as CreateVoteUserOptionsWithRefinementSchema, Cr as t$11, Ct as trackUpdatingCommunity, D as isIpfsCid, Dn as VoteSignedPropertyNames, Dr as r$7, Dt as require_sha256$1, E as isAbortError, Er as n$8, Et as untrackUpdatingCommunity, Fn as CommentUpdateChallengeReservedFieldNames, Fr as FailedToFetchGenericIpfsFromGatewaysError, Ft as ChallengeRequestMessageSignedPropertyNames, Gn as ModQueuePageIpfsSchema, Gr as boolean, Gt as PKCParsedOptionsSchema, Ht as DecryptedChallengeVerificationSchema, Ir as FailedToFetchPageIpfsFromGatewaysError, Jn as CommentEditChallengeRequestToEncryptSchema, Jr as looseObject, K as removeNullUndefinedEmptyObjectsValuesRecursively, Kn as PageIpfsSchema, Kr as custom, Kt as PKCUserOptionBaseSchema, L as isRequestPubsubPublicationOfPost, Ln as CommentUpdateForChallengeVerificationSignedPropertyNames, Lr as PKCError, Lt as ChallengeVerificationMessageSignedPropertyNames, Mr as FailedToFetchCommentIpfsFromGatewaysError, Nn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Nr as FailedToFetchCommentUpdateFromGatewaysError, Nt as ChallengeMessageSignedPropertyNames, O as isIpfsPath, Or as t$10, Pn as CommentSignedPropertyNames, Pr as FailedToFetchCommunityFromGatewaysError, Qn as CommentEditSignedPropertyNames, Qr as record, Qt as CommunityEditPubsubMessagePublicationSchema, R as isRequestPubsubPublicationOfReply, Rn as CommentUpdateReservedFields, Rr as messages, Rt as DecryptedChallengeAnswerSchema, S as hasTransientNetworkErrorCode, Sn as RpcRemoteCommunityUpdateEventResultSchema, Sr as e$5, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Tr as t$12, Un as CreateCommentOptionsWithRefinementSchema, Ur as _enum, Ut as NameResolveCacheOptionsSchema, V as raceAgainstAbort, Vr as require_ms$1, Vt as DecryptedChallengeSchema, Wn as GetPageParamSchema, Wr as array, Wt as NameResolverSerializedSchema, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xr as object, Yr as number, Yt as CommunityEditPublicationChallengeRequestToEncryptSchema, Zr as preprocess, Zt as CommunityEditPublicationSignedPropertyNames, _n as CreateRpcCommunityFunctionArgumentSchema, an as CreateCommentModerationOptionsWithRefinementSchema, ar as ChallengeAnswersSchema, at as timestamp, bn as PageSortFileSchema, br as t$13, cr as CommunityAddressSchema, d as deepMergeRuntimeFields, dn as CommunityExportRecordsSchema, dr as JsonSignatureSchema, dt as findStartedCommunity, ei as union, en as CommentModerationChallengeRequestToEncryptSchema, er as CreateCommentEditOptionsWithRefinementSchema, et as shortifyAddress, f as derivePublicationFromChallengeRequest, fn as CommunityIpfsReservedFields, fr as PKCTimestampSchema, gn as CreateRemoteCommunityFunctionArgumentSchema, gr as n$9, h as fetchAndValidateIpnsRecordFromGateway, hn as CreateNewLocalCommunityUserOptionsSchema, hr as isStringDomain, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as throwIfAbortSignalAborted, jn as CommentIpfsSchema, jr as require_retry$2, jt as ChallengeAnswerMessageSignedPropertyNames, k as isIpns, kn as CommentChallengeRequestToEncryptSchema, kr as t$9, kt as pTimeout, ln as CommunityChallengeSettingSchema, lr as CommunityAuthorChallengeReservedFieldNames, m as extractNetworkErrorDetails, mn as CommunitySignedPropertyNames, mr as areEquivalentNames, mt as forgetTrackedUpdatingCommunityName, nr as AuthorCommentIpfsReservedFields, nt as sleepUntilTimeoutOrAbort, on as ChallengeFileFactorySchema, or as CidPathSchema, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pr as ProtocolVersionSchema, pt as findUpdatingCommunity, qn as isReservedObjectKey, qr as literal, qt as PKCUserOptionsSchema, r as calculateIpfsCidV0, rn as CommentModerationSignedPropertyNames, rr as AuthorPubsubSchema, sn as ChallengeFileSchema, sr as CidStringSchema, t as areEquivalentCommunityAddresses, tn as CommentModerationPubsubMessagePublicationSchema, tr as AuthorAddressSchema, tt as shortifyCid, u as createAbortError, un as CommunityEditOptionsSchema, ur as CreateSignerSchema, vn as ExportCommunityModLogsOptionsSchema, vr as n$10, w as interruptibleSleep, wn as VoteChallengeRequestToEncryptSchema, wr as r$8, wt as untrackStartedCommunity, xr as e$6, xt as trackStartedCommunity, yn as PageSortFileFactorySchema, yt as refreshTrackedCommunityAliases, z as pubsubTopicToDhtKey, zn as CommentUpdateSchema, zr as logger_default } from "./util-TZLcBbZd.js";
3
3
  import { t as all } from "./src-CYIMjhjK.js";
4
- import { s as validatePageSortFile } from "./page-sort-scoring-iqMGLuRC.js";
4
+ import { s as validatePageSortFile } from "./page-sort-scoring-BCqpbgnJ.js";
5
5
  import { createHash } from "node:crypto";
6
6
  import { pathToFileURL } from "node:url";
7
7
  import dns from "node:dns";
@@ -118207,12 +118207,13 @@ function calculateInlineRepliesBudget({ comment, commentUpdateWithoutReplies, ma
118207
118207
  return Math.max(0, Math.min(inlineBudgetFromComment, inlineBudgetFromPage));
118208
118208
  }
118209
118209
  function deriveDbReplies(opts) {
118210
- const { replies, allPageCids } = opts;
118210
+ const { replies, allPageCids, flatSortNames } = opts;
118211
118211
  if (!replies) return void 0;
118212
118212
  const result = {};
118213
118213
  if (replies.pages) for (const [sortName, page] of Object.entries(replies.pages)) result[sortName] = {
118214
118214
  commentCids: page.comments.map((c) => c.commentUpdate.cid),
118215
- ...allPageCids?.[sortName]?.length ? { allPageCids: allPageCids[sortName] } : {}
118215
+ ...allPageCids?.[sortName]?.length ? { allPageCids: allPageCids[sortName] } : {},
118216
+ ...flatSortNames?.includes(sortName) ? { flat: true } : {}
118216
118217
  };
118217
118218
  if (allPageCids) {
118218
118219
  for (const [sortName, cids] of Object.entries(allPageCids)) if (!result[sortName] && cids.length > 0) result[sortName] = { allPageCids: cids };
@@ -124255,6 +124256,8 @@ async function verifyCommentUpdate({ update, resolveAuthorNames, clientsManager,
124255
124256
  const pageCid = update.replies.pageCids?.[replySortName];
124256
124257
  const page = update.replies.pages[replySortName];
124257
124258
  if (!page) throw Error("Failed to find page to verify within comment update");
124259
+ const parentComment = page.comments.every((pageComment) => pageComment.comment.depth === comment.depth + 1) || comment.depth !== 0 ? comment : { postCid: comment.cid };
124260
+ const isFlatRepliesPage = comment.depth === 0 && page.comments.some(({ comment: entry, commentUpdate }) => entry.depth !== 1 || commentUpdate.signature.signedPropertyNames.includes("replies") && !commentUpdate.replies);
124258
124261
  const validity = await verifyPage({
124259
124262
  pageCid,
124260
124263
  page,
@@ -124262,9 +124265,9 @@ async function verifyCommentUpdate({ update, resolveAuthorNames, clientsManager,
124262
124265
  resolveAuthorNames,
124263
124266
  clientsManager,
124264
124267
  community,
124265
- parentComment: page.comments.every((pageComment) => pageComment.comment.depth === comment.depth + 1) || comment.depth !== 0 ? comment : { postCid: comment.cid },
124268
+ parentComment,
124266
124269
  validatePages,
124267
- validateUpdateSignature,
124270
+ validateUpdateSignature: validateUpdateSignature && !isFlatRepliesPage,
124268
124271
  abortSignal
124269
124272
  });
124270
124273
  if (!validity.valid) return validity;
@@ -1,4 +1,4 @@
1
- import { B as pubsubTopicToDhtKeyCid, Lr as PKCError } from "./util-Bna9pur0.js";
1
+ import { B as pubsubTopicToDhtKeyCid, Lr as PKCError } from "./util-TZLcBbZd.js";
2
2
  import { ipnsSelector } from "ipns/selector";
3
3
  import { ipnsValidator } from "ipns/validator";
4
4
  import { unmarshalIPNSRecord } from "ipns";
@@ -7268,6 +7268,8 @@ var messages;
7268
7268
  messages["ERR_RPC_CLIENT_TRYING_TO_DELETE_REMOTE_COMMUNITY"] = "RPC client is attempting to delete remote community";
7269
7269
  messages["ERR_RPC_CLIENT_TRYING_TO_USE_ANCHOR_METHOD_ON_NON_LOCAL_COMMUNITY"] = "RPC client is attempting to prepare or publish an anchor record for a community this node does not host locally";
7270
7270
  messages["ERR_RPC_PUBLICATION_LOST_WITH_CONNECTION"] = "The connection to the PKC RPC server closed while the publication was in flight. The server stopped the publication, so publish it again";
7271
+ messages["ERR_RPC_CONNECTION_LOST"] = "The connection to the PKC RPC server closed before the response to this call arrived. The server may have run the call. The client is reconnecting on its own";
7272
+ messages["ERR_RPC_RECONNECT_FAILED"] = "Failed to reconnect to the PKC RPC server. The client keeps retrying until pkc.destroy() is called";
7271
7273
  messages["ERR_RPC_CLIENT_NO_ACTIVE_PUBLISH_SUBSCRIPTION"] = "Cannot publish challenge answers over PKC RPC: there is no active publish subscription. The challenge exchange has concluded, the publication was stopped, or publish() was never called";
7272
7274
  messages["ERR_GENERIC_RPC_CLIENT_CALL_ERROR"] = "RPC client received an unknown error when executing call over websocket";
7273
7275
  messages["ERR_RPC_CALL_TIMED_OUT"] = "RPC client call timed out without receiving a response from the RPC server";
@@ -8284,7 +8286,8 @@ const CommentsTableRowSchema = CommentIpfsSchema.extend({
8284
8286
  }).strict();
8285
8287
  const DbRepliesSortEntrySchema = object({
8286
8288
  commentCids: array(CidStringSchema).optional(),
8287
- allPageCids: array(CidStringSchema).optional()
8289
+ allPageCids: array(CidStringSchema).optional(),
8290
+ flat: literal(true).optional()
8288
8291
  });
8289
8292
  const DbRepliesSchema = record(string().min(1), DbRepliesSortEntrySchema);
8290
8293
  record(string().min(1), DbRepliesSortEntrySchema);
@@ -16549,7 +16552,7 @@ const CommunityEditPublicationPubsubReservedFields = r$2([
16549
16552
  ], t$3(CommunityEditPubsubMessagePublicationSchema.shape));
16550
16553
  //#endregion
16551
16554
  //#region dist/node/generated-version.js
16552
- const version = "0.0.133";
16555
+ const version = "0.0.135";
16553
16556
  //#endregion
16554
16557
  //#region dist/node/version.js
16555
16558
  const protocolVersion = ProtocolVersionSchema.parse("1.0.0");
@@ -1,5 +1,5 @@
1
- import { Lr as PKCError, on as ChallengeFileFactorySchema, sn as ChallengeFileSchema, yn as PageSortFileFactorySchema } from "./util-Bna9pur0.js";
2
- import { s as validatePageSortFile } from "./page-sort-scoring-iqMGLuRC.js";
1
+ import { Lr as PKCError, on as ChallengeFileFactorySchema, sn as ChallengeFileSchema, yn as PageSortFileFactorySchema } from "./util-TZLcBbZd.js";
2
+ import { s as validatePageSortFile } from "./page-sort-scoring-BCqpbgnJ.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-DsWFSaNV.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-BNoBGxyk.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-FeyM9Tw1.js";
1
+ import { n as validatePageSortFileFactory } from "./chunks/validate-package-factories-DGlKaHzi.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-Bna9pur0.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-DsWFSaNV.js";
3
- import { Dt as parseJsonWithPKCErrorIfFails, E as buildPagesRuntimeFields, Gr as stringify, L as extractCrosspostRuntimeFields, Mt as parseVoteChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, Pr as toCommunitiesWireEntry, Rr as t$1, T as buildPageRuntimeFields, Tr as listCommunitiesSync, U as pRetry, Vn as verifyCommunityList, W as pLimit, Xn as MAX_COMMUNITY_LIST_SIZE_BYTES, at as parseCommentModerationChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, br as findLocalCommunityAddress, bt as parseCreatePKCWsServerOptionsSchemaWithPKCErrorIfItFails, dt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, jt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, mt as parseCommunityListSchemaWithPKCErrorIfItFails, nt as parseCommentEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, sn as require_lib, tt as parseCommentChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, ut as parseCommunityEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, yt as parseCreateNewLocalCommunityUserOptionsSchemaWithPKCErrorIfItFails } from "../../chunks/rpc-local-community-jndojGZl.js";
4
- import { t as LocalCommunity } from "../../chunks/local-community-JxRohlLp.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-TZLcBbZd.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-BNoBGxyk.js";
3
+ import { Dt as parseJsonWithPKCErrorIfFails, E as buildPagesRuntimeFields, Gr as stringify, L as extractCrosspostRuntimeFields, Mt as parseVoteChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, Pr as toCommunitiesWireEntry, Rr as t$1, T as buildPageRuntimeFields, Tr as listCommunitiesSync, U as pRetry, Vn as verifyCommunityList, W as pLimit, Xn as MAX_COMMUNITY_LIST_SIZE_BYTES, at as parseCommentModerationChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, br as findLocalCommunityAddress, bt as parseCreatePKCWsServerOptionsSchemaWithPKCErrorIfItFails, dt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, jt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, mt as parseCommunityListSchemaWithPKCErrorIfItFails, nt as parseCommentEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, sn as require_lib, tt as parseCommentChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, ut as parseCommunityEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, yt as parseCreateNewLocalCommunityUserOptionsSchemaWithPKCErrorIfItFails } from "../../chunks/rpc-local-community-CuL4H_vR.js";
4
+ import { t as LocalCommunity } from "../../chunks/local-community-BjljrKks.js";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import path from "path";
7
7
  import assert from "assert";
@@ -28,6 +28,11 @@ export default class PKCRpcClient extends TypedEmitter<PKCRpcClientEvents> {
28
28
  private _resubscribeCalls;
29
29
  private _publishSubscriptionIds;
30
30
  private _hasConnectedBefore;
31
+ private _lastClose?;
32
+ private _failedReconnectAttempts;
33
+ private _lastWebsocketError?;
34
+ private _callsAwaitingResponse;
35
+ private _backgroundSubscriptionsToRetry;
31
36
  private _socketsWithNotificationHandler;
32
37
  private _reconnectBaseIntervalMs;
33
38
  private _reconnectMaxIntervalMs;
@@ -37,6 +42,7 @@ export default class PKCRpcClient extends TypedEmitter<PKCRpcClientEvents> {
37
42
  constructor(rpcServerUrl: string);
38
43
  setState(newState: PKCRpcClient["state"]): void;
39
44
  _init(): Promise<void>;
45
+ private _waitForConnectionToOpen;
40
46
  destroy(): Promise<void>;
41
47
  private _waitForSocketClose;
42
48
  toJSON(): undefined;
@@ -44,9 +50,15 @@ export default class PKCRpcClient extends TypedEmitter<PKCRpcClientEvents> {
44
50
  unsubscribe(subscriptionId: number): Promise<void>;
45
51
  private _attachNotificationHandler;
46
52
  private _dispatchNotification;
53
+ private _scheduleReconnectAfterCleanClose;
54
+ private _wrapIfFailedReconnectAttempt;
55
+ private _rejectIfConnectionIsLost;
56
+ private _rejectCallsLostWithConnection;
47
57
  private _backOffReconnectInterval;
48
58
  private _subscribe;
49
59
  private _resubscribeAllAfterReconnect;
60
+ private _runBackgroundSubscription;
61
+ private _retryBackgroundSubscriptions;
50
62
  private _resubscribe;
51
63
  private _failPublicationsLostWithConnection;
52
64
  private _deserializeRpcError;