@pkcprotocol/pkc-js 0.0.116 → 0.0.118
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/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +16 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js +199 -43
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/browser/errors.d.ts +4 -0
- package/dist/browser/errors.js +4 -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/rpc/src/index.d.ts +5 -1
- package/dist/browser/rpc/src/index.js +28 -2
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/runtime/node/community/challenges/index.d.ts +17 -3
- package/dist/browser/runtime/node/community/challenges/index.js +58 -16
- package/dist/browser/runtime/node/community/challenges/index.js.map +1 -1
- package/dist/browser/runtime/node/community/challenges/validate-challenge-settings.js +1 -1
- package/dist/browser/runtime/node/community/challenges/validate-challenge-settings.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/challenges.js +7 -1
- package/dist/browser/runtime/node/community/local-community/challenges.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/db-state.js +5 -2
- package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/editing.js +5 -2
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +19 -4
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/registry-sync.js +20 -5
- package/dist/browser/runtime/node/community/local-community/registry-sync.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/bundled/bundle-manifest.json +40 -40
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-BvltkMx7.js → helia-for-pkc-DMzV8Gsa.js} +2 -2
- package/dist/bundled/chunks/{local-community-nSmHRx5s.js → local-community-DvEh9Nte.js} +37 -14
- package/dist/bundled/chunks/{local-community-Cm4X7RjW.js → local-community-YoJAmva8.js} +1 -1
- package/dist/bundled/chunks/{node-CaeXEQ5O.js → node-CH9-YjYa.js} +169 -53
- package/dist/bundled/chunks/{page-sort-scoring-Bj73WnwW.js → page-sort-scoring-C1XYRQ1w.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-DfJ3wj-p.js → rpc-local-community-DqKbZLIy.js} +64 -20
- package/dist/bundled/chunks/{util-DkyQHyK7.js → util-CpoO437x.js} +1 -1
- package/dist/bundled/chunks/{util-vJMTa4rC.js → util-DEmcezee.js} +5 -1
- package/dist/bundled/chunks/{validate-package-factories-tZC8XxoO.js → validate-package-factories-C9A4AtCN.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 +23 -6
- package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +16 -0
- package/dist/node/clients/rpc-client/pkc-rpc-client.js +199 -43
- package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/node/errors.d.ts +4 -0
- package/dist/node/errors.js +4 -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/rpc/src/index.d.ts +5 -1
- package/dist/node/rpc/src/index.js +28 -2
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/runtime/node/community/challenges/index.d.ts +17 -3
- package/dist/node/runtime/node/community/challenges/index.js +58 -16
- package/dist/node/runtime/node/community/challenges/index.js.map +1 -1
- package/dist/node/runtime/node/community/challenges/validate-challenge-settings.js +1 -1
- package/dist/node/runtime/node/community/challenges/validate-challenge-settings.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/challenges.js +7 -1
- package/dist/node/runtime/node/community/local-community/challenges.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/db-state.js +5 -2
- package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/editing.js +5 -2
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +19 -4
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/registry-sync.js +20 -5
- package/dist/node/runtime/node/community/local-community/registry-sync.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/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 { $t as CommentModerationPubsubMessagePublicationSchema, A as isLinkOfAnimatedImage, An as CommentIpfsSchema, Ar as PKCError, At as ChallengeMessageSchema, Bn as CommentUpdateTableRowSchema, Dn as VoteTablesRowSchema, Dt as pTimeout, F as isLinkValid, Gr as ZodError, Jn as CommentEditPubsubMessagePublicationSchema, Jt as CommunityEditPublicationPubsubReservedFields, K as removeNullUndefinedValues, Kt as version_default, Lt as DecryptedChallengeRequestPublicationSchema, M as isLinkOfImage, Mr as logger_default, Mt as ChallengeRequestMessageSchema, N as isLinkOfMedia, Ot as ChallengeAnswerMessageSchema, P as isLinkOfVideo, Pt as ChallengeVerificationMessageSchema, Q as retryKuboIpfsAddAndProvide, Qn as CommentEditsTableRowSchema, R as pubsubTopicToDhtKey, Rn as CommentUpdateSchema, Rt as DecryptedChallengeRequestSchema, S as hideClassPrivateProps, Sr as t$2, St as untrackStartedCommunity, Tn as VotePubsubReservedFields, Tt as require_sha256, U as removeBlocksFromKuboNode, Vn as CommentsTableRowSchema, W as removeMfsFilesSafely, X as retryKuboBlockPutPinAndProvidePubsubTopic, Xn as CommentEditReservedFields, Yn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, _ as getEquivalentCommunityAddresses, _r as r$1, a as calculateUnixFsDagSizeCidV0, c as contentContainsMarkdownVideos, ct as writeKuboFilesWithTimeout, d as derivePublicationFromChallengeRequest, dn as CommunityIpfsSchema, dr as n$2, en as CommentModerationReservedFields, f as doesDomainAddressHaveCapitalLetter, fn as CommunitySignedPropertyNames, fr as t$5, ft as findUpdatingCommunity, g as genToArray, h as findMalformedUnicodeString, hr as e, i as calculateStringSizeSameAsIpfsAddCidV0, it as timestamp, j as isLinkOfAudio, jn as CommentPubsubMessageReservedFields, jr as messages, lr as n$3, lt as findCommunityInRegistry, mr as e$1, nn as CommentModerationsTableRowSchema, nr as AuthorReservedFields, nt as statMfsPathSafely, o as contentContainsMarkdownAudio, ot as withSortedKeys, pr as t$6, r as calculateIpfsCidV0, s as contentContainsMarkdownImages, st as withSortedKeysDeep, t as areEquivalentCommunityAddresses, tt as sleepUntilTimeoutOrAbort, ur as t$7, ut as findStartedCommunity, v as getErrorCodeFromMessage, vr as t$3, vt as syncCommunityRegistryEntry, w as ipnsNameToIpnsOverPubsubTopic, wn as VotePubsubMessagePublicationSchema, wr as require_retry, wt as untrackUpdatingCommunity, xn as isStringDomain, xr as t$4, xt as trackUpdatingCommunity, y as getIpnsRecordInLocalKuboNode, yt as trackStartedCommunity } from "./util-
|
|
3
|
-
import { $n as
|
|
4
|
-
import { a as scorePageCommentsWithFile, i as partitionPageCommentsForSort, n as filterRepliesForPageSort, o as stripRepliesFromPageComment, r as orderPageCommentsByScore, t as createDescendantsLookup } from "./page-sort-scoring-
|
|
2
|
+
import { $t as CommentModerationPubsubMessagePublicationSchema, A as isLinkOfAnimatedImage, An as CommentIpfsSchema, Ar as PKCError, At as ChallengeMessageSchema, Bn as CommentUpdateTableRowSchema, Dn as VoteTablesRowSchema, Dt as pTimeout, F as isLinkValid, Gr as ZodError, Jn as CommentEditPubsubMessagePublicationSchema, Jt as CommunityEditPublicationPubsubReservedFields, K as removeNullUndefinedValues, Kt as version_default, Lt as DecryptedChallengeRequestPublicationSchema, M as isLinkOfImage, Mr as logger_default, Mt as ChallengeRequestMessageSchema, N as isLinkOfMedia, Ot as ChallengeAnswerMessageSchema, P as isLinkOfVideo, Pt as ChallengeVerificationMessageSchema, Q as retryKuboIpfsAddAndProvide, Qn as CommentEditsTableRowSchema, R as pubsubTopicToDhtKey, Rn as CommentUpdateSchema, Rt as DecryptedChallengeRequestSchema, S as hideClassPrivateProps, Sr as t$2, St as untrackStartedCommunity, Tn as VotePubsubReservedFields, Tt as require_sha256, U as removeBlocksFromKuboNode, Vn as CommentsTableRowSchema, W as removeMfsFilesSafely, X as retryKuboBlockPutPinAndProvidePubsubTopic, Xn as CommentEditReservedFields, Yn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, _ as getEquivalentCommunityAddresses, _r as r$1, a as calculateUnixFsDagSizeCidV0, c as contentContainsMarkdownVideos, ct as writeKuboFilesWithTimeout, d as derivePublicationFromChallengeRequest, dn as CommunityIpfsSchema, dr as n$2, en as CommentModerationReservedFields, f as doesDomainAddressHaveCapitalLetter, fn as CommunitySignedPropertyNames, fr as t$5, ft as findUpdatingCommunity, g as genToArray, h as findMalformedUnicodeString, hr as e, i as calculateStringSizeSameAsIpfsAddCidV0, it as timestamp, j as isLinkOfAudio, jn as CommentPubsubMessageReservedFields, jr as messages, lr as n$3, lt as findCommunityInRegistry, mr as e$1, nn as CommentModerationsTableRowSchema, nr as AuthorReservedFields, nt as statMfsPathSafely, o as contentContainsMarkdownAudio, ot as withSortedKeys, pr as t$6, r as calculateIpfsCidV0, s as contentContainsMarkdownImages, st as withSortedKeysDeep, t as areEquivalentCommunityAddresses, tt as sleepUntilTimeoutOrAbort, ur as t$7, ut as findStartedCommunity, v as getErrorCodeFromMessage, vr as t$3, vt as syncCommunityRegistryEntry, w as ipnsNameToIpnsOverPubsubTopic, wn as VotePubsubMessagePublicationSchema, wr as require_retry, wt as untrackUpdatingCommunity, xn as isStringDomain, xr as t$4, xt as trackUpdatingCommunity, y as getIpnsRecordInLocalKuboNode, yt as trackStartedCommunity } from "./util-DEmcezee.js";
|
|
3
|
+
import { $n as backupCommunityDb, An as verifyCommunity, Ar as STORAGE_KEYS, Cn as verifyChallengeRequest, Dn as verifyCommentModeration, En as verifyCommentIpfs, Gn as decode, Hn as getCommunityNameFromWire, In as getAuthorNameFromWire, Jn as getIpfsKeyFromPrivateKey, Kn as encode, Mn as verifyVote, Nn as buildRuntimeAuthor, On as verifyCommentPubsubMessage, Pn as cleanWireAuthor, Q as createSchemaRowParser, Qn as BackupAbortError, Rn as crosspostChainDepthUpTo, S as KeyvBetterSqlite3, Sr as n$4, St as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Tn as verifyCommentEdit, Tr as stringify, Tt as parseJsonWithPKCErrorIfFails, U as pLimit, Un as getCommunityPublicKeyFromWire, X as coerceSchemaRowJson, Xn as getPKCAddressFromPublicKeySync, Y as coerceSchemaRowBoolean, Yn as getPKCAddressFromPublicKey, Z as collectSchemaRowCoercions, Zn as getPublicKeyFromPrivateKey, _ as createAuthorIdentityMatcher, _n as signCommentUpdateForChallengeVerification, _r as t$10, a as generatePagesReportingFailedSorts, ar as deriveDbPosts, br as t$8, c as resolvePageSortsOrThrow, cn as cleanUpBeforePublishing, d as getChallengeVerification, en as SignerWithPublicKeyAddress, er as calculateExpectedSignatureSize, f as getCommunityChallengeFromCommunityChallengeSettings, fn as signChallengeVerification, ft as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, g as authorNameResolveFailureReason, gn as signCommentUpdate, h as authorIdentityMatcherForRequest, i as derivePublicPageSorts, in as decryptEd25519AesGcmPublicKeyBuffer, ir as deriveCommentIpfsFromCommentTableRow, j as iterateOverPageCidsToFindAllCids, jn as verifyCommunityEdit, jr as require_lodash_merge, kn as verifyCommentUpdate, lr as getThumbnailPropsOfLink, m as pkcJsChallenges, mn as signCommentEdit, mr as resolveDbPostsCidRefs, o as loadPageSortsForStartedCommunity, on as encryptEd25519AesGcmPublicKeyBuffer, or as deriveDbReplies, p as loadChallengeFileFromCommunityChallengeSettings, pn as signComment, pr as moveCommunityDbToDeletedDirectory, r as computePageSortsFingerprint, rr as deleteOldCommunityInWindows, s as lookupPageSortFactories, sn as _validateSignatureOfPKCRecord, sr as getDefaultCommunityDbConfig, t as RpcLocalCommunity, tr as calculateInlineRepliesBudget, u as deriveCommunityChallengesOrThrow, un as signChallengeMessage, ur as importSignerIntoKuboNode, ut as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, v as TrackedInstanceRegistry, vn as signCommunity, vr as t$11, w as TIMEFRAMES_TO_SECONDS, wr as t$9, x as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, xn as verifyChallengeAnswer, xr as n$5, y as LRUCache, yr as r$2, zn as effectiveMaxCrosspostDepth } from "./rpc-local-community-DqKbZLIy.js";
|
|
4
|
+
import { a as scorePageCommentsWithFile, i as partitionPageCommentsForSort, n as filterRepliesForPageSort, o as stripRepliesFromPageComment, r as orderPageCommentsByScore, t as createDescendantsLookup } from "./page-sort-scoring-C1XYRQ1w.js";
|
|
5
5
|
import { randomFillSync, randomUUID } from "node:crypto";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
import path from "node:path";
|
|
@@ -1660,6 +1660,7 @@ async function collectChallengeSettingsValidationFailures({ challengeSettings, p
|
|
|
1660
1660
|
challengeSettings: communityChallengeSettings,
|
|
1661
1661
|
challengeFile: await loadChallengeFileFromCommunityChallengeSettings({
|
|
1662
1662
|
communityChallengeSettings,
|
|
1663
|
+
challengeIndex,
|
|
1663
1664
|
pkc
|
|
1664
1665
|
}),
|
|
1665
1666
|
challengeIndex
|
|
@@ -2493,8 +2494,9 @@ async function createNewLocalCommunityDb(community) {
|
|
|
2493
2494
|
pkc: community._pkc,
|
|
2494
2495
|
communityAddress: community.address
|
|
2495
2496
|
});
|
|
2496
|
-
community.challenges = await Promise.all(community.settings.challenges.map(async (cs) => (await getCommunityChallengeFromCommunityChallengeSettings({
|
|
2497
|
+
community.challenges = await Promise.all(community.settings.challenges.map(async (cs, challengeIndex) => (await getCommunityChallengeFromCommunityChallengeSettings({
|
|
2497
2498
|
communityChallengeSettings: cs,
|
|
2499
|
+
challengeIndex,
|
|
2498
2500
|
pkc: community._pkc
|
|
2499
2501
|
})).communityChallenge));
|
|
2500
2502
|
community._pageSorts = await resolvePageSortsOrThrow({
|
|
@@ -5904,6 +5906,7 @@ async function purgeDisapprovedCommentsOlderThan(community) {
|
|
|
5904
5906
|
}
|
|
5905
5907
|
//#endregion
|
|
5906
5908
|
//#region dist/node/runtime/node/community/local-community/challenges.js
|
|
5909
|
+
const describeMisconfiguredChallenge = (e) => e instanceof PKCError && e.code === "ERR_CHALLENGE_NOT_REGISTERED" ? `challenge "${e.details.challengeName}" is not registered on this node` : e.message;
|
|
5907
5910
|
function cleanUpChallengeAnswerPromise(community, challengeRequestIdString) {
|
|
5908
5911
|
community._challengeAnswerPromises.delete(challengeRequestIdString);
|
|
5909
5912
|
community._challengeAnswerResolveReject.delete(challengeRequestIdString);
|
|
@@ -6335,7 +6338,7 @@ async function runChallengeExchangeIfNeeded(community, parsed, log) {
|
|
|
6335
6338
|
community.emit("error", e);
|
|
6336
6339
|
challengeVerification = {
|
|
6337
6340
|
challengeSuccess: false,
|
|
6338
|
-
reason: `One of the community challenges is misconfigured: ${e
|
|
6341
|
+
reason: `One of the community challenges is misconfigured: ${describeMisconfiguredChallenge(e)}`
|
|
6339
6342
|
};
|
|
6340
6343
|
}
|
|
6341
6344
|
return challengeVerification;
|
|
@@ -7354,14 +7357,26 @@ async function syncChallengesWithRegistry(community) {
|
|
|
7354
7357
|
if (!Array.isArray(challengeSettings)) return;
|
|
7355
7358
|
let challenges;
|
|
7356
7359
|
try {
|
|
7357
|
-
challenges = await
|
|
7358
|
-
|
|
7359
|
-
pkc: community._pkc
|
|
7360
|
-
|
|
7360
|
+
challenges = await deriveCommunityChallengesOrThrow({
|
|
7361
|
+
challengeSettings,
|
|
7362
|
+
pkc: community._pkc,
|
|
7363
|
+
communityAddress: community.address
|
|
7364
|
+
});
|
|
7361
7365
|
} catch (e) {
|
|
7362
7366
|
log.error("Could not recompute community.challenges from the registry, keeping the previous ones", community.address, e);
|
|
7367
|
+
const reported = stringify(e.details?.failures?.map((f) => [
|
|
7368
|
+
f.challengeIndex,
|
|
7369
|
+
f.challengeName,
|
|
7370
|
+
f.path,
|
|
7371
|
+
f.error.code
|
|
7372
|
+
]) ?? String(e));
|
|
7373
|
+
if (reported !== community._reportedChallengeLoadFailures) {
|
|
7374
|
+
community._reportedChallengeLoadFailures = reported;
|
|
7375
|
+
community.emit("error", e);
|
|
7376
|
+
}
|
|
7363
7377
|
return;
|
|
7364
7378
|
}
|
|
7379
|
+
community._reportedChallengeLoadFailures = void 0;
|
|
7365
7380
|
if (stringify(challenges) === stringify(community.challenges ?? null)) return;
|
|
7366
7381
|
log("community.challenges changed in the registry, republishing", community.address);
|
|
7367
7382
|
community.challenges = challenges;
|
|
@@ -7821,6 +7836,11 @@ async function start(community) {
|
|
|
7821
7836
|
anchorPublicKey: community.anchor.publicKey,
|
|
7822
7837
|
minterAddress: community.signer.address
|
|
7823
7838
|
});
|
|
7839
|
+
await deriveCommunityChallengesOrThrow({
|
|
7840
|
+
challengeSettings: community.settings?.challenges ?? [],
|
|
7841
|
+
pkc: community._pkc,
|
|
7842
|
+
communityAddress: community.address
|
|
7843
|
+
});
|
|
7824
7844
|
community._setState("started");
|
|
7825
7845
|
await community._updateStartedValue();
|
|
7826
7846
|
await community._dbHandler.lockCommunityStart();
|
|
@@ -7832,6 +7852,11 @@ async function start(community) {
|
|
|
7832
7852
|
await updateInstanceStateWithDbState(community);
|
|
7833
7853
|
await community._loadExportsFromKeyv();
|
|
7834
7854
|
await setChallengesToDefaultIfNotDefined(community, log);
|
|
7855
|
+
community.challenges = await deriveCommunityChallengesOrThrow({
|
|
7856
|
+
challengeSettings: community.settings.challenges,
|
|
7857
|
+
pkc: community._pkc,
|
|
7858
|
+
communityAddress: community.address
|
|
7859
|
+
});
|
|
7835
7860
|
await importCommunitySignerIntoIpfsIfNeeded(community);
|
|
7836
7861
|
await providePubsubTopicRoutingCidsIfNeeded(community, true);
|
|
7837
7862
|
await reprovideAnchorRecordIfNeeded(community).catch((e) => log.error("Failed to re-provide the anchor record on start", e));
|
|
@@ -7840,10 +7865,6 @@ async function start(community) {
|
|
|
7840
7865
|
await community._repinCommentsIPFSIfNeeded();
|
|
7841
7866
|
await repinCommentUpdateIfNeeded(community);
|
|
7842
7867
|
await community._listenToIncomingRequests();
|
|
7843
|
-
community.challenges = await Promise.all(community.settings.challenges.map(async (cs) => (await getCommunityChallengeFromCommunityChallengeSettings({
|
|
7844
|
-
communityChallengeSettings: cs,
|
|
7845
|
-
pkc: community._pkc
|
|
7846
|
-
})).communityChallenge));
|
|
7847
7868
|
await emitChallengeSettingsValidationErrors(community, log);
|
|
7848
7869
|
community._pageSorts = void 0;
|
|
7849
7870
|
community._pageSortFactories = void 0;
|
|
@@ -8172,8 +8193,9 @@ async function parseChallengesToEdit(community, newChallengeSettings) {
|
|
|
8172
8193
|
communityAddress: community.address
|
|
8173
8194
|
});
|
|
8174
8195
|
return {
|
|
8175
|
-
challenges: await Promise.all(newChallengeSettings.map(async (cs) => (await getCommunityChallengeFromCommunityChallengeSettings({
|
|
8196
|
+
challenges: await Promise.all(newChallengeSettings.map(async (cs, challengeIndex) => (await getCommunityChallengeFromCommunityChallengeSettings({
|
|
8176
8197
|
communityChallengeSettings: cs,
|
|
8198
|
+
challengeIndex,
|
|
8177
8199
|
pkc: community._pkc
|
|
8178
8200
|
})).communityChallenge)),
|
|
8179
8201
|
_usingDefaultChallenge: isDefaultChallengeStructure(newChallengeSettings)
|
|
@@ -8534,6 +8556,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8534
8556
|
this._combinedHashOfPendingCommentsCids = (0, import_sha256.sha256)("");
|
|
8535
8557
|
this._pageSorts = void 0;
|
|
8536
8558
|
this._pageSortFactories = void 0;
|
|
8559
|
+
this._reportedChallengeLoadFailures = void 0;
|
|
8537
8560
|
this._publishLoopPromise = void 0;
|
|
8538
8561
|
this._updateLoopPromise = void 0;
|
|
8539
8562
|
this._firstUpdateAfterStart = true;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-
|
|
1
|
+
import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-DvEh9Nte.js";
|
|
2
2
|
export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $ as shortifyAddress, An as CommentIpfsSchema, Ar as PKCError, At as ChallengeMessageSchema, Ct as untrackUpdatingComment, Dt as pTimeout, E as isIpfsCid, Er as FailedToFetchCommentUpdateFromGatewaysError, Et as TimeoutError, Fn as CommentUpdateForChallengeVerificationSchema, Fr as setErrorMap, H as rejectWhenCommunityStopsOrAborts, J as replaceXWithY, Jr as stringifyPrimitive, Kr as joinValues, Kt as version_default, Mr as logger_default, Mt as ChallengeRequestMessageSchema, O as isIpns, Ot as ChallengeAnswerMessageSchema, Pt as ChallengeVerificationMessageSchema, Rn as CommentUpdateSchema, S as hideClassPrivateProps, T as isAbortError, Tr as FailedToFetchCommentIpfsFromGatewaysError, Tt as require_sha256, V as rejectWhenAbortSignalFires, Y as resolveWhenPredicateIsTrue, Z as retryKuboIpfsAdd, _r as r, at as waitForUpdateInCommunityInstanceWithErrorAndTimeout, b as getPostUpdateTimestampRange, bt as trackUpdatingComment, dn as CommunityIpfsSchema, dr as n$1, dt as findUpdatingComment, et as shortifyCid, f as doesDomainAddressHaveCapitalLetter, ft as findUpdatingCommunity, gt as refreshTrackedCommentAliases, hr as e$1, ht as listUpdatingCommunities, it as timestamp, jr as messages, l as createAbortError, lr as n$2, mr as e, mt as listUpdatingComments, on as CommunityAnchorSchema, pr as t$1, pt as listStartedCommunities, q as removeUndefinedValuesRecursively, qr as parsedType, rt as throwIfAbortSignalAborted, t as areEquivalentCommunityAddresses, tt as sleepUntilTimeoutOrAbort, u as deepMergeRuntimeFields, ut as findStartedCommunity, w as ipnsNameToIpnsOverPubsubTopic, wr as require_retry, wt as untrackUpdatingCommunity, xn as isStringDomain, yn as PubsubTopicSchema } from "./util-
|
|
3
|
-
import {
|
|
4
|
-
import { s as getHeliaDebugContext } from "./util-
|
|
2
|
+
import { $ as shortifyAddress, An as CommentIpfsSchema, Ar as PKCError, At as ChallengeMessageSchema, Ct as untrackUpdatingComment, Dt as pTimeout, E as isIpfsCid, Er as FailedToFetchCommentUpdateFromGatewaysError, Et as TimeoutError, Fn as CommentUpdateForChallengeVerificationSchema, Fr as setErrorMap, H as rejectWhenCommunityStopsOrAborts, J as replaceXWithY, Jr as stringifyPrimitive, Kr as joinValues, Kt as version_default, Mr as logger_default, Mt as ChallengeRequestMessageSchema, O as isIpns, Ot as ChallengeAnswerMessageSchema, Pt as ChallengeVerificationMessageSchema, Rn as CommentUpdateSchema, S as hideClassPrivateProps, T as isAbortError, Tr as FailedToFetchCommentIpfsFromGatewaysError, Tt as require_sha256, V as rejectWhenAbortSignalFires, Y as resolveWhenPredicateIsTrue, Z as retryKuboIpfsAdd, _r as r, at as waitForUpdateInCommunityInstanceWithErrorAndTimeout, b as getPostUpdateTimestampRange, bt as trackUpdatingComment, dn as CommunityIpfsSchema, dr as n$1, dt as findUpdatingComment, et as shortifyCid, f as doesDomainAddressHaveCapitalLetter, ft as findUpdatingCommunity, gt as refreshTrackedCommentAliases, hr as e$1, ht as listUpdatingCommunities, it as timestamp, jr as messages, l as createAbortError, lr as n$2, mr as e, mt as listUpdatingComments, on as CommunityAnchorSchema, pr as t$1, pt as listStartedCommunities, q as removeUndefinedValuesRecursively, qr as parsedType, rt as throwIfAbortSignalAborted, t as areEquivalentCommunityAddresses, tt as sleepUntilTimeoutOrAbort, u as deepMergeRuntimeFields, ut as findStartedCommunity, w as ipnsNameToIpnsOverPubsubTopic, wr as require_retry, wt as untrackUpdatingCommunity, xn as isStringDomain, yn as PubsubTopicSchema } from "./util-DEmcezee.js";
|
|
3
|
+
import { $ as parseCidStringSchemaWithPKCErrorIfItFails, $t as require_lib$1, A as findCommentInParsedPages, B as InflightFetchManager, Bn as buildRuntimeCommunityFields, Bt as RpcExportCommunityModLogsParamSchema, C as RepliesPages, Cr as t$2, Ct as parseDecryptedChallengeVerification, D as extractCommunityRuntimeFieldsFromParsedPages, Dn as verifyCommentModeration, Dr as NAME_RESOLVED_FALSE_TTL_MS, Dt as parseRpcCommentEventWithPKCErrorIfItFails, En as verifyCommentIpfs, Er as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, Et as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, F as collectCrosspostAuthorsToResolve, Fn as getAuthorNameFromRuntime, Ft as RpcCidParamSchema, G as decodeRpcChallengeAnswerPubsubMsg, Gn as decode, Gt as RpcFetchCidResultSchema, Hn as getCommunityNameFromWire, Ht as RpcExportCommunityParamSchema, It as RpcCommentRepliesPageParamSchema, J as decodeRpcChallengeVerificationPubsubMsg, Jt as RpcPublishedAnchorRecordResultSchema, K as decodeRpcChallengePubsubMsg, Kt as RpcPublishAnchorRecordParamSchema, L as stripNameResolvedFromCrosspost, Ln as normalizeCreatePublicationAuthor, Lt as RpcCommunityIdentifierParamSchema, M as parseRawPages, Mn as verifyVote, Mr as nativeFunctions$2, Mt as RpcAnchorPublishPreparationResultSchema, N as applyNameResolvedCacheToCrosspost, Nn as buildRuntimeAuthor, Nr as require_undici, Nt as RpcAuthorNameParamSchema, O as findCommentInPageInstance, On as verifyCommentPubsubMessage, Or as NAME_RESOLVED_TRUE_TTL_MS, Ot as parseRpcCommentUpdateEventWithPKCErrorIfItFails, P as cloneCrosspostForRuntime, Pn as cleanWireAuthor, Pt as RpcCancelExportParamSchema, Qt as RpcUnsubscribeParamSchema, R as PKCClientsManager, Rt as RpcCommunityPageParamSchema, S as KeyvBetterSqlite3, Sn as verifyChallengeMessage, St as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Tn as verifyCommentEdit, Tt as parseJsonWithPKCErrorIfFails, Un as getCommunityPublicKeyFromWire, Ut as RpcExportCommunityResultSchema, V as InflightResourceTypes, Vn as getCommunityAddressFromRecord, Vt as RpcExportCommunityModLogsResultSchema, W as PKCTypedEmitter, Wn as normalizeCommunityInputFromCommunity, Wt as RpcFetchCidParamSchema, Xn as getPKCAddressFromPublicKeySync, Xt as RpcSubscriptionIdResultSchema, Yt as RpcResolveAuthorNameResultSchema, Zt as RpcSuccessResultSchema, _r as t$5, an as encryptEd25519AesGcm, at as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, b as RemoteCommunity, bn as signVote, br as t$3, bt as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, cn as cleanUpBeforePublishing, cr as getDefaultDataPath, ct as parseCommunityAddressWithPKCErrorIfItFails, dn as signChallengeRequest, dr as listCommunitiesSync, dt as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, fr as monitorCommunitiesDirectory, gr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, gt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, hn as signCommentModeration, hr as setNativeFunctions$1, ht as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, jn as verifyCommunityEdit, jt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, k as findCommentInPageInstanceRecursively, kn as verifyCommentUpdate, kr as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, kt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, l as pkcJsPageSorts, ln as signChallengeAnswer, m as pkcJsChallenges, mn as signCommentEdit, mt as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as createAnchorIpnsRecord$1, nr as createKuboRpcClient, nt as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, ot as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, pn as signComment, pt as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, q as decodeRpcChallengeRequestPubsubMsg, qn as getBufferedPKCAddressFromPublicKey, qt as RpcPublishChallengeAnswersParamSchema, rn as decryptEd25519AesGcm, rt as parseCommentIpfsSchemaWithPKCErrorIfItFails, st as parseCommentUpdateSchemaWithPKCErrorIfItFails, t as RpcLocalCommunity, tn as createSigner, v as TrackedInstanceRegistry, wn as verifyChallengeVerification, wr as t$4, wt as parseDecryptedChallengeWithPKCErrorIfItFails, xr as n$3, xt as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, y as LRUCache, yn as signCommunityEdit, yt as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, z as GenericStateClient, zt as RpcEditCommunityParamSchema } from "./rpc-local-community-DqKbZLIy.js";
|
|
4
|
+
import { s as getHeliaDebugContext } from "./util-CpoO437x.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import assert from "assert";
|
|
7
7
|
import fs from "fs";
|
|
@@ -3439,10 +3439,26 @@ const log = logger_default("pkc-js:PKCRpcClient");
|
|
|
3439
3439
|
const WEBSOCKET_READY_STATE_CLOSED = 3;
|
|
3440
3440
|
const DESTROY_SOCKET_CLOSE_TIMEOUT_MS = 5e3;
|
|
3441
3441
|
const scheduleMacrotask = setTimeout.bind(globalThis);
|
|
3442
|
+
function isRpcSubscriptionNotification(message) {
|
|
3443
|
+
if (typeof message !== "object" || message === null || !("params" in message)) return false;
|
|
3444
|
+
const params = message.params;
|
|
3445
|
+
if (typeof params !== "object" || params === null) return false;
|
|
3446
|
+
const { subscription, event } = params;
|
|
3447
|
+
return typeof subscription === "number" && subscription > 0 && typeof event === "string";
|
|
3448
|
+
}
|
|
3442
3449
|
var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
3443
3450
|
constructor(rpcServerUrl) {
|
|
3444
3451
|
super();
|
|
3445
3452
|
this._pendingSubscriptionMsgs = {};
|
|
3453
|
+
this._serverIdByLocalId = /* @__PURE__ */ new Map();
|
|
3454
|
+
this._localIdByServerId = /* @__PURE__ */ new Map();
|
|
3455
|
+
this._resubscribeCalls = /* @__PURE__ */ new Map();
|
|
3456
|
+
this._publishSubscriptionIds = /* @__PURE__ */ new Set();
|
|
3457
|
+
this._hasConnectedBefore = false;
|
|
3458
|
+
this._socketsWithNotificationHandler = /* @__PURE__ */ new WeakSet();
|
|
3459
|
+
this._reconnectBaseIntervalMs = 1e3;
|
|
3460
|
+
this._reconnectMaxIntervalMs = 3e4;
|
|
3461
|
+
this._reconnectIntervalMs = this._reconnectBaseIntervalMs;
|
|
3446
3462
|
assert(rpcServerUrl, "pkc.pkcRpcClientsOptions needs to be defined to create a new rpc client");
|
|
3447
3463
|
this._websocketServerUrl = rpcServerUrl;
|
|
3448
3464
|
this._timeoutSeconds = 20;
|
|
@@ -3475,26 +3491,24 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
3475
3491
|
let lastWebsocketError;
|
|
3476
3492
|
if (!(this._webSocketClient instanceof Client)) {
|
|
3477
3493
|
this.setState("connecting");
|
|
3478
|
-
this._webSocketClient = new Client(this._websocketServerUrl
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
const message = JSON.parse(jsonMessage);
|
|
3482
|
-
const subscriptionId = message?.params?.subscription;
|
|
3483
|
-
if (subscriptionId) {
|
|
3484
|
-
this._initSubscriptionEvent(subscriptionId);
|
|
3485
|
-
if (message?.params?.event === "error") {
|
|
3486
|
-
message.params.result = this._deserializeRpcError(message.params.result);
|
|
3487
|
-
delete message.params.result.stack;
|
|
3488
|
-
}
|
|
3489
|
-
if (this._subscriptionEvents[subscriptionId].listenerCount(message?.params?.event) === 0) this._pendingSubscriptionMsgs[subscriptionId].push(message);
|
|
3490
|
-
else this._subscriptionEvents[subscriptionId].emit(message?.params?.event, message);
|
|
3491
|
-
}
|
|
3494
|
+
this._webSocketClient = new Client(this._websocketServerUrl, {
|
|
3495
|
+
reconnect_interval: this._reconnectIntervalMs,
|
|
3496
|
+
max_reconnects: 0
|
|
3492
3497
|
});
|
|
3498
|
+
log("Created a new WebSocket instance with url " + this._websocketServerUrl);
|
|
3499
|
+
this._attachNotificationHandler();
|
|
3493
3500
|
this._webSocketClient.on("open", () => {
|
|
3494
3501
|
log("Connected to RPC server", this._websocketServerUrl);
|
|
3502
|
+
this._attachNotificationHandler();
|
|
3503
|
+
this._reconnectIntervalMs = this._reconnectBaseIntervalMs;
|
|
3504
|
+
this._webSocketClient.setReconnectInterval(this._reconnectIntervalMs);
|
|
3505
|
+
const isReconnect = this._hasConnectedBefore;
|
|
3506
|
+
this._hasConnectedBefore = true;
|
|
3495
3507
|
this.setState("connected");
|
|
3508
|
+
if (isReconnect) this._resubscribeAllAfterReconnect();
|
|
3496
3509
|
});
|
|
3497
3510
|
this._webSocketClient.on("error", (error) => {
|
|
3511
|
+
this._backOffReconnectInterval();
|
|
3498
3512
|
lastWebsocketError = error;
|
|
3499
3513
|
if (this._destroyRequested) {
|
|
3500
3514
|
log("Ignoring websocket error emitted after destroy request", error);
|
|
@@ -3507,12 +3521,17 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
3507
3521
|
this.setState("failed");
|
|
3508
3522
|
return;
|
|
3509
3523
|
}
|
|
3510
|
-
|
|
3524
|
+
try {
|
|
3525
|
+
this.emit("error", error);
|
|
3526
|
+
} catch (emitError) {
|
|
3527
|
+
log.error("No listener received the RPC websocket error", this._websocketServerUrl, emitError);
|
|
3528
|
+
}
|
|
3511
3529
|
});
|
|
3512
3530
|
this._webSocketClient.on("close", () => {
|
|
3513
3531
|
if (!this._destroyRequested) log.error("connection with web socket has been closed", this._websocketServerUrl);
|
|
3514
3532
|
this._openConnectionPromise = void 0;
|
|
3515
3533
|
this.setState("stopped");
|
|
3534
|
+
if (!this._destroyRequested) this._failPublicationsLostWithConnection();
|
|
3516
3535
|
});
|
|
3517
3536
|
const originalWebsocketCall = this._webSocketClient.call.bind(this._webSocketClient);
|
|
3518
3537
|
this._webSocketClient.call = async (...args) => {
|
|
@@ -3577,9 +3596,14 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
3577
3596
|
log.error("Failed to unsubscribe to subscription ID", subscriptionId, e);
|
|
3578
3597
|
cleanupSubscriptionLocally(subscriptionId);
|
|
3579
3598
|
}
|
|
3599
|
+
this._resubscribeCalls.clear();
|
|
3600
|
+
this._publishSubscriptionIds.clear();
|
|
3601
|
+
this._serverIdByLocalId.clear();
|
|
3602
|
+
this._localIdByServerId.clear();
|
|
3580
3603
|
try {
|
|
3581
3604
|
if (this._webSocketClient instanceof Client) {
|
|
3582
3605
|
this._webSocketClient.setAutoReconnect(false);
|
|
3606
|
+
clearTimeout(this._webSocketClient.reconnect_timer_id);
|
|
3583
3607
|
const socketClosed = this._waitForSocketClose();
|
|
3584
3608
|
this._webSocketClient.close();
|
|
3585
3609
|
await socketClosed;
|
|
@@ -3607,11 +3631,123 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
3607
3631
|
else return this._subscriptionEvents[subscriptionId];
|
|
3608
3632
|
}
|
|
3609
3633
|
async unsubscribe(subscriptionId) {
|
|
3610
|
-
|
|
3634
|
+
const liveOnServer = this.state === "connected" && (this._resubscribeCalls.has(subscriptionId) || this._publishSubscriptionIds.has(subscriptionId));
|
|
3635
|
+
const serverSubscriptionId = this._serverIdByLocalId.get(subscriptionId) ?? subscriptionId;
|
|
3636
|
+
this._resubscribeCalls.delete(subscriptionId);
|
|
3637
|
+
this._publishSubscriptionIds.delete(subscriptionId);
|
|
3638
|
+
if (liveOnServer) await this._webSocketClient.call("unsubscribe", [{ subscriptionId: serverSubscriptionId }]);
|
|
3639
|
+
this._serverIdByLocalId.delete(subscriptionId);
|
|
3640
|
+
this._localIdByServerId.delete(serverSubscriptionId);
|
|
3611
3641
|
if (this._subscriptionEvents[subscriptionId]) this._subscriptionEvents[subscriptionId].removeAllListeners();
|
|
3612
3642
|
delete this._subscriptionEvents[subscriptionId];
|
|
3613
3643
|
delete this._pendingSubscriptionMsgs[subscriptionId];
|
|
3614
3644
|
}
|
|
3645
|
+
_attachNotificationHandler() {
|
|
3646
|
+
const socket = this._webSocketClient.socket;
|
|
3647
|
+
if (!socket || this._socketsWithNotificationHandler.has(socket)) return;
|
|
3648
|
+
this._socketsWithNotificationHandler.add(socket);
|
|
3649
|
+
socket.on("message", (jsonMessage) => {
|
|
3650
|
+
const message = JSON.parse(jsonMessage);
|
|
3651
|
+
if (!isRpcSubscriptionNotification(message)) return;
|
|
3652
|
+
const serverSubscriptionId = message.params.subscription;
|
|
3653
|
+
const subscriptionId = this._localIdByServerId.get(serverSubscriptionId) ?? serverSubscriptionId;
|
|
3654
|
+
message.params.subscription = subscriptionId;
|
|
3655
|
+
this._dispatchNotification(subscriptionId, message);
|
|
3656
|
+
});
|
|
3657
|
+
}
|
|
3658
|
+
_dispatchNotification(subscriptionId, message) {
|
|
3659
|
+
this._initSubscriptionEvent(subscriptionId);
|
|
3660
|
+
if (message.params.event === "error" && !(message.params.result instanceof Error)) {
|
|
3661
|
+
const error = this._deserializeRpcError(message.params.result);
|
|
3662
|
+
delete error.stack;
|
|
3663
|
+
message.params.result = error;
|
|
3664
|
+
}
|
|
3665
|
+
if (this._subscriptionEvents[subscriptionId].listenerCount(message.params.event) === 0) this._pendingSubscriptionMsgs[subscriptionId].push(message);
|
|
3666
|
+
else this._subscriptionEvents[subscriptionId].emit(message.params.event, message);
|
|
3667
|
+
}
|
|
3668
|
+
_backOffReconnectInterval() {
|
|
3669
|
+
if (!(this._webSocketClient instanceof Client)) return;
|
|
3670
|
+
this._reconnectIntervalMs = Math.min(this._reconnectIntervalMs * 2, this._reconnectMaxIntervalMs);
|
|
3671
|
+
this._webSocketClient.setReconnectInterval(this._reconnectIntervalMs);
|
|
3672
|
+
}
|
|
3673
|
+
async _subscribe(method, params, onReconnect, resubscribeMethod = method) {
|
|
3674
|
+
const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call(method, params));
|
|
3675
|
+
this._initSubscriptionEvent(res.subscriptionId);
|
|
3676
|
+
if (onReconnect === "resubscribe") this._resubscribeCalls.set(res.subscriptionId, {
|
|
3677
|
+
method: resubscribeMethod,
|
|
3678
|
+
params
|
|
3679
|
+
});
|
|
3680
|
+
else this._publishSubscriptionIds.add(res.subscriptionId);
|
|
3681
|
+
return res;
|
|
3682
|
+
}
|
|
3683
|
+
_resubscribeAllAfterReconnect() {
|
|
3684
|
+
for (const subscriptionId of [...this._resubscribeCalls.keys()]) this._resubscribe(subscriptionId).catch((error) => {
|
|
3685
|
+
if (this._destroyRequested) return;
|
|
3686
|
+
if (error?.code === "ERR_RPC_COMMUNITY_NOT_RUNNING") {
|
|
3687
|
+
log("Not re-establishing start(), the community was stopped on purpose", subscriptionId);
|
|
3688
|
+
this._resubscribeCalls.delete(subscriptionId);
|
|
3689
|
+
this._dispatchNotification(subscriptionId, { params: {
|
|
3690
|
+
event: "startedstatechange",
|
|
3691
|
+
subscription: subscriptionId,
|
|
3692
|
+
result: { state: "stopped" }
|
|
3693
|
+
} });
|
|
3694
|
+
return;
|
|
3695
|
+
}
|
|
3696
|
+
log.error("Failed to re-subscribe after reconnecting to the RPC server", subscriptionId, error);
|
|
3697
|
+
this._dispatchNotification(subscriptionId, { params: {
|
|
3698
|
+
event: "error",
|
|
3699
|
+
subscription: subscriptionId,
|
|
3700
|
+
result: error
|
|
3701
|
+
} });
|
|
3702
|
+
});
|
|
3703
|
+
}
|
|
3704
|
+
async _resubscribe(subscriptionId) {
|
|
3705
|
+
const call = this._resubscribeCalls.get(subscriptionId);
|
|
3706
|
+
if (!call || this._destroyRequested) return;
|
|
3707
|
+
const { subscriptionId: serverSubscriptionId } = parseRpcSubscriptionIdResult(await this._webSocketClient.call(call.method, call.params));
|
|
3708
|
+
const earlyMessages = serverSubscriptionId === subscriptionId ? [] : this._pendingSubscriptionMsgs[serverSubscriptionId] ?? [];
|
|
3709
|
+
if (serverSubscriptionId !== subscriptionId) {
|
|
3710
|
+
delete this._pendingSubscriptionMsgs[serverSubscriptionId];
|
|
3711
|
+
delete this._subscriptionEvents[serverSubscriptionId];
|
|
3712
|
+
}
|
|
3713
|
+
if (this._resubscribeCalls.get(subscriptionId) !== call || this._destroyRequested) {
|
|
3714
|
+
if (!this._destroyRequested) await this._webSocketClient.call("unsubscribe", [{ subscriptionId: serverSubscriptionId }]).catch((error) => {
|
|
3715
|
+
log.error("Failed to unsubscribe a subscription re-issued after it was unsubscribed", error);
|
|
3716
|
+
});
|
|
3717
|
+
return;
|
|
3718
|
+
}
|
|
3719
|
+
const previousServerSubscriptionId = this._serverIdByLocalId.get(subscriptionId);
|
|
3720
|
+
if (previousServerSubscriptionId !== void 0) this._localIdByServerId.delete(previousServerSubscriptionId);
|
|
3721
|
+
this._serverIdByLocalId.set(subscriptionId, serverSubscriptionId);
|
|
3722
|
+
this._localIdByServerId.set(serverSubscriptionId, subscriptionId);
|
|
3723
|
+
log("Re-subscribed after reconnecting", call.method, {
|
|
3724
|
+
subscriptionId,
|
|
3725
|
+
serverSubscriptionId
|
|
3726
|
+
});
|
|
3727
|
+
for (const message of earlyMessages) {
|
|
3728
|
+
message.params.subscription = subscriptionId;
|
|
3729
|
+
this._dispatchNotification(subscriptionId, message);
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
_failPublicationsLostWithConnection() {
|
|
3733
|
+
for (const subscriptionId of [...this._publishSubscriptionIds]) {
|
|
3734
|
+
this._publishSubscriptionIds.delete(subscriptionId);
|
|
3735
|
+
const error = new PKCError("ERR_RPC_PUBLICATION_LOST_WITH_CONNECTION", {
|
|
3736
|
+
rpcServerUrl: this._websocketServerUrl,
|
|
3737
|
+
publishThrowError: true
|
|
3738
|
+
});
|
|
3739
|
+
this._dispatchNotification(subscriptionId, { params: {
|
|
3740
|
+
event: "publishingstatechange",
|
|
3741
|
+
subscription: subscriptionId,
|
|
3742
|
+
result: { state: "failed" }
|
|
3743
|
+
} });
|
|
3744
|
+
this._dispatchNotification(subscriptionId, { params: {
|
|
3745
|
+
event: "error",
|
|
3746
|
+
subscription: subscriptionId,
|
|
3747
|
+
result: error
|
|
3748
|
+
} });
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3615
3751
|
_deserializeRpcError(errorPayload) {
|
|
3616
3752
|
if (!errorPayload || typeof errorPayload !== "object") {
|
|
3617
3753
|
const genericError = /* @__PURE__ */ new Error("Received malformed RPC error payload");
|
|
@@ -3687,7 +3823,7 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
3687
3823
|
while (pendingMessages.length > 0) {
|
|
3688
3824
|
if (!shouldDeliver()) return;
|
|
3689
3825
|
const message = pendingMessages.shift();
|
|
3690
|
-
this._subscriptionEvents[subscriptionId].emit(message
|
|
3826
|
+
this._subscriptionEvents[subscriptionId].emit(message.params.event, message);
|
|
3691
3827
|
}
|
|
3692
3828
|
delete this._pendingSubscriptionMsgs[subscriptionId];
|
|
3693
3829
|
}
|
|
@@ -3717,9 +3853,7 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
3717
3853
|
}
|
|
3718
3854
|
async startCommunity(communityIdentifier) {
|
|
3719
3855
|
const parsedStartCommunityArgs = parseRpcCommunityIdentifierParam(communityIdentifier);
|
|
3720
|
-
|
|
3721
|
-
this._initSubscriptionEvent(res.subscriptionId);
|
|
3722
|
-
return res;
|
|
3856
|
+
return await this._subscribe("startCommunity", [parsedStartCommunityArgs], "resubscribe", "startedCommunitySubscribe");
|
|
3723
3857
|
}
|
|
3724
3858
|
async stopCommunity(communityIdentifier) {
|
|
3725
3859
|
const parsedStopCommunityArgs = parseRpcCommunityIdentifierParam(communityIdentifier);
|
|
@@ -3747,40 +3881,26 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
3747
3881
|
}
|
|
3748
3882
|
async communityUpdateSubscribe(communityIdentifier) {
|
|
3749
3883
|
const parsedCommunityUpdateArgs = parseRpcCommunityIdentifierParam(communityIdentifier);
|
|
3750
|
-
|
|
3751
|
-
this._initSubscriptionEvent(res.subscriptionId);
|
|
3752
|
-
return res;
|
|
3884
|
+
return await this._subscribe("communityUpdateSubscribe", [parsedCommunityUpdateArgs], "resubscribe");
|
|
3753
3885
|
}
|
|
3754
3886
|
async publishComment(commentProps) {
|
|
3755
|
-
|
|
3756
|
-
this._initSubscriptionEvent(res.subscriptionId);
|
|
3757
|
-
return res;
|
|
3887
|
+
return await this._subscribe("publishComment", [commentProps], "fail");
|
|
3758
3888
|
}
|
|
3759
3889
|
async publishCommentEdit(commentEditProps) {
|
|
3760
|
-
|
|
3761
|
-
this._initSubscriptionEvent(res.subscriptionId);
|
|
3762
|
-
return res;
|
|
3890
|
+
return await this._subscribe("publishCommentEdit", [commentEditProps], "fail");
|
|
3763
3891
|
}
|
|
3764
3892
|
async publishCommentModeration(commentModProps) {
|
|
3765
|
-
|
|
3766
|
-
this._initSubscriptionEvent(res.subscriptionId);
|
|
3767
|
-
return res;
|
|
3893
|
+
return await this._subscribe("publishCommentModeration", [commentModProps], "fail");
|
|
3768
3894
|
}
|
|
3769
3895
|
async publishVote(voteProps) {
|
|
3770
|
-
|
|
3771
|
-
this._initSubscriptionEvent(res.subscriptionId);
|
|
3772
|
-
return res;
|
|
3896
|
+
return await this._subscribe("publishVote", [voteProps], "fail");
|
|
3773
3897
|
}
|
|
3774
3898
|
async publishCommunityEdit(communityEdit) {
|
|
3775
|
-
|
|
3776
|
-
this._initSubscriptionEvent(res.subscriptionId);
|
|
3777
|
-
return res;
|
|
3899
|
+
return await this._subscribe("publishCommunityEdit", [communityEdit], "fail");
|
|
3778
3900
|
}
|
|
3779
3901
|
async commentUpdateSubscribe(args) {
|
|
3780
3902
|
const parsedCommentUpdateArgs = parseRpcCidParam(args);
|
|
3781
|
-
|
|
3782
|
-
this._initSubscriptionEvent(res.subscriptionId);
|
|
3783
|
-
return res;
|
|
3903
|
+
return await this._subscribe("commentUpdateSubscribe", [parsedCommentUpdateArgs], "resubscribe");
|
|
3784
3904
|
}
|
|
3785
3905
|
async publishChallengeAnswers(args) {
|
|
3786
3906
|
return parseRpcSuccessResult(await this._webSocketClient.call("publishChallengeAnswers", [args]));
|
|
@@ -3790,16 +3910,14 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
3790
3910
|
return parseRpcResolveAuthorNameResult(await this._webSocketClient.call("resolveAuthorName", [resolveAuthorNameArgs]));
|
|
3791
3911
|
}
|
|
3792
3912
|
async initalizeCommunitieschangeEvent() {
|
|
3793
|
-
const { subscriptionId } =
|
|
3794
|
-
this._initSubscriptionEvent(subscriptionId);
|
|
3913
|
+
const { subscriptionId } = await this._subscribe("communitiesSubscribe", [], "resubscribe");
|
|
3795
3914
|
this.getSubscription(subscriptionId).on("communitieschange", (res) => {
|
|
3796
3915
|
this.emit("communitieschange", res.params.result.communities);
|
|
3797
3916
|
});
|
|
3798
3917
|
this.emitAllPendingMessages(subscriptionId);
|
|
3799
3918
|
}
|
|
3800
3919
|
async initalizeSettingschangeEvent() {
|
|
3801
|
-
const { subscriptionId } =
|
|
3802
|
-
this._initSubscriptionEvent(subscriptionId);
|
|
3920
|
+
const { subscriptionId } = await this._subscribe("settingsSubscribe", [], "resubscribe");
|
|
3803
3921
|
this.getSubscription(subscriptionId).on("settingschange", (res) => {
|
|
3804
3922
|
this.emit("settingschange", res.params.result);
|
|
3805
3923
|
});
|
|
@@ -3830,9 +3948,7 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
3830
3948
|
}
|
|
3831
3949
|
async exportsSubscribe(args) {
|
|
3832
3950
|
const parsedArgs = parseRpcCommunityIdentifierParam(args);
|
|
3833
|
-
|
|
3834
|
-
this._initSubscriptionEvent(res.subscriptionId);
|
|
3835
|
-
return res;
|
|
3951
|
+
return await this._subscribe("exportsSubscribe", [parsedArgs], "resubscribe");
|
|
3836
3952
|
}
|
|
3837
3953
|
async cancelExport(args) {
|
|
3838
3954
|
const parsedArgs = parseRpcCancelExportParam(args);
|
|
@@ -8254,7 +8370,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
8254
8370
|
this.clients.libp2pJsClients = {};
|
|
8255
8371
|
if (!this.libp2pJsClientsOptions) return;
|
|
8256
8372
|
if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
|
|
8257
|
-
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-
|
|
8373
|
+
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-DMzV8Gsa.js");
|
|
8258
8374
|
for (const clientOptions of this.libp2pJsClientsOptions) {
|
|
8259
8375
|
const heliaNode = await createLibp2pJsClientOrUseExistingOne({
|
|
8260
8376
|
...clientOptions,
|
|
@@ -8533,7 +8649,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
8533
8649
|
const log = logger_default("pkc-js:pkc:createLocalCommunity");
|
|
8534
8650
|
log.trace("Received community options to create a local community instance:", options);
|
|
8535
8651
|
if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
|
|
8536
|
-
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-
|
|
8652
|
+
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-YoJAmva8.js");
|
|
8537
8653
|
const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
|
|
8538
8654
|
const community = new LocalCommunity(this);
|
|
8539
8655
|
if (isLocalCommunity) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as getEquivalentCommunityAddresses, vn as PageSortFileSchema } from "./util-
|
|
1
|
+
import { _ as getEquivalentCommunityAddresses, vn as PageSortFileSchema } from "./util-DEmcezee.js";
|
|
2
2
|
//#region dist/node/pages/page-sort-scoring.js
|
|
3
3
|
function validatePageSortFile(rawFile) {
|
|
4
4
|
const validated = PageSortFileSchema.parse(rawFile);
|