@pkcprotocol/pkc-js 0.0.153 → 0.0.155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -3
- package/dist/browser/clients/rpc-client/schema.js +2 -2
- package/dist/browser/clients/rpc-client/schema.js.map +1 -1
- package/dist/browser/community/remote-community.js +8 -2
- package/dist/browser/community/remote-community.js.map +1 -1
- package/dist/browser/community/schema.js +4 -0
- package/dist/browser/community/schema.js.map +1 -1
- package/dist/browser/community-list/community-list.js +3 -2
- package/dist/browser/community-list/community-list.js.map +1 -1
- package/dist/browser/errors.d.ts +18 -2
- package/dist/browser/errors.js +18 -2
- 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/pkc.js +13 -4
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/comment.d.ts +1 -0
- package/dist/browser/publications/comment/comment.js +82 -21
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/publications/comment/crosspost-runtime.js +10 -2
- package/dist/browser/publications/comment/crosspost-runtime.js.map +1 -1
- package/dist/browser/publications/comment/schema.d.ts +1 -1
- package/dist/browser/publications/comment/schema.js +30 -1
- package/dist/browser/publications/comment/schema.js.map +1 -1
- package/dist/browser/publications/publication.d.ts +12 -1
- package/dist/browser/publications/publication.js +511 -167
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/publications/types.d.ts +1 -0
- package/dist/browser/rpc/src/index.js +15 -8
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/runtime/browser/util.d.ts +3 -1
- package/dist/browser/runtime/browser/util.js +8 -2
- package/dist/browser/runtime/browser/util.js.map +1 -1
- package/dist/browser/runtime/node/blockstore.d.ts +2 -2
- package/dist/browser/runtime/node/blockstore.js +2 -2
- package/dist/browser/runtime/node/community/challenges/validate-challenge-result.js +2 -1
- package/dist/browser/runtime/node/community/challenges/validate-challenge-result.js.map +1 -1
- package/dist/browser/runtime/node/community/communities-registry.d.ts +96 -0
- package/dist/browser/runtime/node/community/communities-registry.js +964 -0
- package/dist/browser/runtime/node/community/communities-registry.js.map +1 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +8 -7
- package/dist/browser/runtime/node/community/db-handler.js +128 -84
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/cleanup.js +62 -12
- package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/db-state.d.ts +1 -1
- package/dist/browser/runtime/node/community/local-community/db-state.js +31 -39
- package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/editing.js +84 -27
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +1 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.d.ts +0 -2
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +88 -61
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/publication-validation.d.ts +1 -2
- package/dist/browser/runtime/node/community/local-community/publication-validation.js +23 -0
- package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +6 -3
- package/dist/browser/runtime/node/community/local-community.js +16 -16
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/community/pkc-instance-lock.d.ts +17 -0
- package/dist/browser/runtime/node/community/pkc-instance-lock.js +142 -0
- package/dist/browser/runtime/node/community/pkc-instance-lock.js.map +1 -0
- package/dist/browser/runtime/node/storage.js +5 -0
- package/dist/browser/runtime/node/storage.js.map +1 -1
- package/dist/browser/runtime/node/util.d.ts +4 -6
- package/dist/browser/runtime/node/util.js +32 -270
- package/dist/browser/runtime/node/util.js.map +1 -1
- package/dist/browser/schema/schema-util.js +18 -4
- package/dist/browser/schema/schema-util.js.map +1 -1
- package/dist/browser/signer/author-wallet-proof.d.ts +19 -0
- package/dist/browser/signer/author-wallet-proof.js +89 -0
- package/dist/browser/signer/author-wallet-proof.js.map +1 -0
- package/dist/browser/signer/signatures.js +29 -0
- package/dist/browser/signer/signatures.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +12 -0
- package/dist/browser/test/test-util.js +23 -0
- package/dist/browser/test/test-util.js.map +1 -1
- package/dist/browser/unknown-props.d.ts +24 -0
- package/dist/browser/unknown-props.js +95 -0
- package/dist/browser/unknown-props.js.map +1 -0
- package/dist/browser/util.js +7 -0
- package/dist/browser/util.js.map +1 -1
- package/dist/browser/version.js +1 -1
- package/dist/bundled/bundle-manifest.json +47 -49
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-COJ3xMF9.js → helia-for-pkc-Oiy9zYBR.js} +4 -4
- package/dist/bundled/chunks/{local-community-BTx2HxIm.js → local-community-BlJfnxcr.js} +1 -1
- package/dist/bundled/chunks/{local-community-CflGu_ET.js → local-community-PMJTbzmG.js} +293 -167
- package/dist/bundled/chunks/{node-B0b6lAIX.js → node-Bf1DjAFe.js} +488 -208
- package/dist/bundled/chunks/{page-sort-scoring-DAMnUmDY.js → page-sort-scoring-DVAvzj4W.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-Cy03QajY.js → rpc-local-community-BqJ_olvR.js} +4529 -3007
- package/dist/bundled/chunks/{util-C4y8KHmp.js → util-BpiQT2hV.js} +1 -1
- package/dist/bundled/chunks/{util-D7AtfLYH.js → util-N_HlPQHv.js} +66 -18
- package/dist/bundled/chunks/{validate-package-factories-EH9ydbPR.js → validate-package-factories-DoC8xXMu.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 +15 -11
- package/dist/node/clients/rpc-client/schema.js +2 -2
- package/dist/node/clients/rpc-client/schema.js.map +1 -1
- package/dist/node/community/remote-community.js +8 -2
- package/dist/node/community/remote-community.js.map +1 -1
- package/dist/node/community/schema.js +4 -0
- package/dist/node/community/schema.js.map +1 -1
- package/dist/node/community-list/community-list.js +3 -2
- package/dist/node/community-list/community-list.js.map +1 -1
- package/dist/node/errors.d.ts +18 -2
- package/dist/node/errors.js +18 -2
- 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/pkc.js +13 -4
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/comment.d.ts +1 -0
- package/dist/node/publications/comment/comment.js +82 -21
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/publications/comment/crosspost-runtime.js +10 -2
- package/dist/node/publications/comment/crosspost-runtime.js.map +1 -1
- package/dist/node/publications/comment/schema.d.ts +1 -1
- package/dist/node/publications/comment/schema.js +30 -1
- package/dist/node/publications/comment/schema.js.map +1 -1
- package/dist/node/publications/publication.d.ts +12 -1
- package/dist/node/publications/publication.js +511 -167
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/publications/types.d.ts +1 -0
- package/dist/node/rpc/src/index.js +15 -8
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/runtime/browser/util.d.ts +3 -1
- package/dist/node/runtime/browser/util.js +8 -2
- package/dist/node/runtime/browser/util.js.map +1 -1
- package/dist/node/runtime/node/blockstore.d.ts +2 -2
- package/dist/node/runtime/node/blockstore.js +2 -2
- package/dist/node/runtime/node/community/challenges/validate-challenge-result.js +2 -1
- package/dist/node/runtime/node/community/challenges/validate-challenge-result.js.map +1 -1
- package/dist/node/runtime/node/community/communities-registry.d.ts +96 -0
- package/dist/node/runtime/node/community/communities-registry.js +964 -0
- package/dist/node/runtime/node/community/communities-registry.js.map +1 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +8 -7
- package/dist/node/runtime/node/community/db-handler.js +128 -84
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/cleanup.js +62 -12
- package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/db-state.d.ts +1 -1
- package/dist/node/runtime/node/community/local-community/db-state.js +31 -39
- package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/editing.js +84 -27
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +1 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.d.ts +0 -2
- package/dist/node/runtime/node/community/local-community/lifecycle.js +88 -61
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/publication-validation.d.ts +1 -2
- package/dist/node/runtime/node/community/local-community/publication-validation.js +23 -0
- package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +6 -3
- package/dist/node/runtime/node/community/local-community.js +16 -16
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/community/pkc-instance-lock.d.ts +17 -0
- package/dist/node/runtime/node/community/pkc-instance-lock.js +142 -0
- package/dist/node/runtime/node/community/pkc-instance-lock.js.map +1 -0
- package/dist/node/runtime/node/storage.js +5 -0
- package/dist/node/runtime/node/storage.js.map +1 -1
- package/dist/node/runtime/node/util.d.ts +4 -6
- package/dist/node/runtime/node/util.js +32 -270
- package/dist/node/runtime/node/util.js.map +1 -1
- package/dist/node/schema/schema-util.js +18 -4
- package/dist/node/schema/schema-util.js.map +1 -1
- package/dist/node/signer/author-wallet-proof.d.ts +19 -0
- package/dist/node/signer/author-wallet-proof.js +89 -0
- package/dist/node/signer/author-wallet-proof.js.map +1 -0
- package/dist/node/signer/signatures.js +29 -0
- package/dist/node/signer/signatures.js.map +1 -1
- package/dist/node/test/test-util.d.ts +12 -0
- package/dist/node/test/test-util.js +23 -0
- package/dist/node/test/test-util.js.map +1 -1
- package/dist/node/unknown-props.d.ts +24 -0
- package/dist/node/unknown-props.js +95 -0
- package/dist/node/unknown-props.js.map +1 -0
- package/dist/node/util.js +7 -0
- package/dist/node/util.js.map +1 -1
- package/dist/node/version.js +1 -1
- package/package.json +3 -3
- package/dist/browser/runtime/node/community/start-lock.d.ts +0 -8
- package/dist/browser/runtime/node/community/start-lock.js +0 -18
- package/dist/browser/runtime/node/community/start-lock.js.map +0 -1
- package/dist/node/runtime/node/community/start-lock.d.ts +0 -8
- package/dist/node/runtime/node/community/start-lock.js +0 -18
- package/dist/node/runtime/node/community/start-lock.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as __toESM } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $n as CommentEditsTableRowSchema, At as ChallengeAnswerMessageSchema, B as pubsubTopicToDhtKey, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Ct as trackUpdatingCommunity, Dt as require_sha256, En as VotePubsubReservedFields, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeBlocksFromKuboNode, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, J as removeNullUndefinedValues, Jt as version_default, K as removeMfsFilesSafely,
|
|
3
|
-
import { $ as createSchemaRowParser, $
|
|
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 { $n as CommentEditsTableRowSchema, Ar as t$4, At as ChallengeAnswerMessageSchema, B as pubsubTopicToDhtKey, Br as messages, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Cr as e$1, Ct as trackUpdatingCommunity, Dr as t$3, Dt as require_sha256, En as VotePubsubReservedFields, Er as r$1, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeBlocksFromKuboNode, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, J as removeNullUndefinedValues, Jt as version_default, K as removeMfsFilesSafely, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, Nr as require_retry, On as VoteTablesRowSchema, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Q as retryKuboBlockPutPinAndProvidePubsubTopic, Sr as t$6, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Vn as CommentUpdateTableRowSchema, Vr as logger_default, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Zn as CommentEditReservedFields, _ as genToArray, b as getIpnsRecordInLocalKuboNode, br as n$2, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeys, dt as findStartedCommunity, et as retryKuboIpfsAddAndProvide, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as statMfsPathSafely, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as withSortedKeysDeep, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, o as calculateUnixFsDagSizeCidV0, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, ri as ZodError, rt as sleepUntilTimeoutOrAbort, s as contentContainsMarkdownAudio, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$3, wr as e, wt as untrackStartedCommunity, xr as t$5, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$7, zn as CommentUpdateSchema, zr as PKCError, zt as DecryptedChallengeRequestPublicationSchema } from "./util-N_HlPQHv.js";
|
|
3
|
+
import { $ as createSchemaRowParser, $n as stringify, Ar as getThumbnailPropsOfLink, Bn as verifyCommunity, Cn as signCommentEdit, Cr as deriveCommentIpfsFromCommentTableRow, Dn as signCommunity, Dr as forgetCommunityThatFailedToBeDeleted, Dt as parseJsonWithPKCErrorIfFails, En as signCommentUpdateForChallengeVerification, Fn as verifyCommentEdit, Fr as moveCommunityDbToDeletedDirectory, Gn as forbiddenKeysOf, Hr as getCommunitiesRegistry, In as verifyCommentIpfs, Jn as buildRuntimeAuthor, Jr as t$11, Ln as verifyCommentModeration, Lr as removeFileRetryingWhileBusy, N as MAX_PAGE_SIZE_BYTES, Nn as verifyChallengeRequest, Or as getDefaultCommunityDbConfig, Q as collectSchemaRowCoercions, Qr as n$4, Rn as verifyCommentPubsubMessage, Rr as resolveDbPostsCidRefs, S as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, Sn as signComment, Sr as deleteOldCommunityInWindows, Tn as signCommentUpdate, Tr as deriveDbReplies, Un as verifyVote, Ur as markCommunityDbAsBeingWritten, Vn as verifyCommunityEdit, Vr as unregisterLocalCommunity, W as pLimit, Wr as findCommunitiesEntry, X as coerceSchemaRowBoolean, Xr as t$8, Yn as cleanWireAuthor, Yr as r$2, Z as coerceSchemaRowJson, Zn as getAuthorNameFromWire, Zr as n$5, _ as createAuthorIdentityMatcher, _n as cleanUpBeforePublishing, _r as BackupAbortError, a as generatePagesReportingFailedSorts, ai as STORAGE_KEYS, b as KeyvBetterSqlite3, br as calculateInlineRepliesBudget, c as resolvePageSortsOrThrow, cr as getCommunityPublicKeyFromWire, d as getChallengeVerification, dr as encode, dt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, ei as t$9, f as getCommunityChallengeFromCommunityChallengeSettings, g as authorNameResolveFailureReason, gn as _validateSignatureOfPKCRecord, gr as getPublicKeyFromPrivateKey, h as authorIdentityMatcherForRequest, hn as encryptEd25519AesGcmPublicKeyBuffer, hr as getPKCAddressFromPublicKeySync, i as derivePublicPageSorts, ir as effectiveMaxCrosspostDepth, j as iterateOverPageCidsToFindAllCids, jn as verifyChallengeAnswer, jr as importSignerIntoKuboNode, ln as SignerWithPublicKeyAddress, m as pkcJsChallenges, mr as getPKCAddressFromPublicKey, o as loadPageSortsForStartedCommunity, oi as require_lodash_merge, p as loadChallengeFileFromCommunityChallengeSettings, pn as decryptEd25519AesGcmPublicKeyBuffer, pr as getIpfsKeyFromPrivateKey, pt as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, qr as t$10, r as computePageSortsFingerprint, rr as crosspostChainDepthUpTo, s as lookupPageSortFactories, sn as verifyAuthorWalletEntry, sr as getCommunityNameFromWire, t as RpcLocalCommunity, u as deriveCommunityChallengesOrThrow, ur as decode, v as TrackedInstanceRegistry, vr as backupCommunityDb, w as TIMEFRAMES_TO_SECONDS, wr as deriveDbPosts, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, xn as signChallengeVerification, y as LRUCache, yn as signChallengeMessage, yr as calculateExpectedSignatureSize, zn as verifyCommentUpdate } from "./rpc-local-community-BqJ_olvR.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-DVAvzj4W.js";
|
|
5
5
|
import { c as prepare, n as decode$1, r as encode$1 } from "./src-BSYNGtIQ.js";
|
|
6
6
|
import { t as UnixFS } from "./src-CAvdjq_i.js";
|
|
7
7
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -1006,19 +1006,14 @@ async function importCommunitySignerIntoIpfsIfNeeded(community) {
|
|
|
1006
1006
|
headers: community._pkc.kuboRpcClientsOptions[0].headers
|
|
1007
1007
|
});
|
|
1008
1008
|
}
|
|
1009
|
-
|
|
1009
|
+
function getDbInternalState(community) {
|
|
1010
1010
|
const log = logger_default("pkc-js:local-community:_getDbInternalState");
|
|
1011
1011
|
if (!community._dbHandler.keyvHas(STORAGE_KEYS[STORAGE_KEYS.INTERNAL_COMMUNITY])) throw new PKCError("ERR_COMMUNITY_HAS_NO_INTERNAL_STATE", {
|
|
1012
1012
|
address: community.address,
|
|
1013
1013
|
dataPath: community._pkc.dataPath
|
|
1014
1014
|
});
|
|
1015
|
-
let lockedIt = false;
|
|
1016
1015
|
try {
|
|
1017
|
-
|
|
1018
|
-
await community._dbHandler.lockCommunityState();
|
|
1019
|
-
lockedIt = true;
|
|
1020
|
-
}
|
|
1021
|
-
const internalState = await community._dbHandler.keyvGet(STORAGE_KEYS[STORAGE_KEYS.INTERNAL_COMMUNITY]);
|
|
1016
|
+
const internalState = community._dbHandler.keyvGet(STORAGE_KEYS[STORAGE_KEYS.INTERNAL_COMMUNITY]);
|
|
1022
1017
|
if (!internalState) throw new PKCError("ERR_COMMUNITY_HAS_NO_INTERNAL_STATE", {
|
|
1023
1018
|
address: community.address,
|
|
1024
1019
|
dataPath: community._pkc.dataPath
|
|
@@ -1027,8 +1022,6 @@ async function getDbInternalState(community, lock) {
|
|
|
1027
1022
|
} catch (e) {
|
|
1028
1023
|
log.error("Failed to get community", community.address, "internal state from db", e);
|
|
1029
1024
|
throw e;
|
|
1030
|
-
} finally {
|
|
1031
|
-
if (lockedIt) await community._dbHandler.unlockCommunityState();
|
|
1032
1025
|
}
|
|
1033
1026
|
}
|
|
1034
1027
|
async function updateDbInternalState(community, propsOrBuildProps) {
|
|
@@ -1036,26 +1029,27 @@ async function updateDbInternalState(community, propsOrBuildProps) {
|
|
|
1036
1029
|
if (typeof propsOrBuildProps !== "function" && e(propsOrBuildProps)) throw Error("props to update DB internal state should not be empty");
|
|
1037
1030
|
await community._dbHandler.initDbIfNeeded();
|
|
1038
1031
|
let props = typeof propsOrBuildProps === "function" ? {} : propsOrBuildProps;
|
|
1039
|
-
let lockedIt = false;
|
|
1040
1032
|
try {
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1033
|
+
const internalStateUpdateId = v4();
|
|
1034
|
+
const mergedInternalState = community._dbHandler.runInWriteTransaction(() => {
|
|
1035
|
+
if (typeof propsOrBuildProps === "function") props = Object.assign(propsOrBuildProps(), ...community._editsStoredNotApplied);
|
|
1036
|
+
props._internalStateUpdateId = internalStateUpdateId;
|
|
1037
|
+
const internalStateBefore = community._getDbInternalState();
|
|
1038
|
+
const propsToStore = "posts" in props && props.posts ? {
|
|
1039
|
+
...props,
|
|
1040
|
+
posts: deriveDbPosts({
|
|
1041
|
+
posts: props.posts,
|
|
1042
|
+
allPageCids: community._postsAllPageCids
|
|
1043
|
+
})
|
|
1044
|
+
} : props;
|
|
1045
|
+
const merged = {
|
|
1046
|
+
...internalStateBefore,
|
|
1047
|
+
...propsToStore
|
|
1048
|
+
};
|
|
1049
|
+
community._dbHandler.keyvSet(STORAGE_KEYS[STORAGE_KEYS.INTERNAL_COMMUNITY], merged);
|
|
1050
|
+
return merged;
|
|
1051
|
+
});
|
|
1052
|
+
community._internalStateUpdateId = internalStateUpdateId;
|
|
1059
1053
|
log.trace("Updated community", community.address, "internal state in db with new props", Object.keys(props));
|
|
1060
1054
|
if (community.updateCid && community.raw.communityIpfs) community.raw.localCommunity = community.toJSONInternalRpcAfterFirstUpdate();
|
|
1061
1055
|
else if (community.settings) community.raw.localCommunity = community.toJSONInternalRpcBeforeFirstUpdate();
|
|
@@ -1063,12 +1057,10 @@ async function updateDbInternalState(community, propsOrBuildProps) {
|
|
|
1063
1057
|
} catch (e) {
|
|
1064
1058
|
log.error("Failed to update community", community.address, "internal state in db with new props", Object.keys(props), e);
|
|
1065
1059
|
throw e;
|
|
1066
|
-
} finally {
|
|
1067
|
-
if (lockedIt) await community._dbHandler.unlockCommunityState();
|
|
1068
1060
|
}
|
|
1069
1061
|
}
|
|
1070
1062
|
async function updateInstanceStateWithDbState(community) {
|
|
1071
|
-
const currentDbState =
|
|
1063
|
+
const currentDbState = community._getDbInternalState();
|
|
1072
1064
|
if ("updatedAt" in currentDbState) {
|
|
1073
1065
|
if (currentDbState.posts && !("pages" in currentDbState.posts)) if (community._dbHandler.hasCommentsAndCommentUpdatesTables()) {
|
|
1074
1066
|
const dbPosts = currentDbState.posts;
|
|
@@ -1443,7 +1435,6 @@ function createPositionalCommentRowMapper(cols) {
|
|
|
1443
1435
|
}
|
|
1444
1436
|
//#endregion
|
|
1445
1437
|
//#region dist/node/runtime/node/community/db-handler.js
|
|
1446
|
-
var import_src = /* @__PURE__ */ __toESM(require_src(), 1);
|
|
1447
1438
|
const createCommunityAuthorMemo = () => ({
|
|
1448
1439
|
writeGeneration: -1,
|
|
1449
1440
|
authors: /* @__PURE__ */ new Map(),
|
|
@@ -1469,7 +1460,7 @@ var DbHandler = class {
|
|
|
1469
1460
|
constructor(community) {
|
|
1470
1461
|
this._transactionGeneration = 0;
|
|
1471
1462
|
this._publicationWriteGeneration = 0;
|
|
1472
|
-
this.
|
|
1463
|
+
this._startLockAddress = void 0;
|
|
1473
1464
|
this._community = community;
|
|
1474
1465
|
this._transactionDepth = 0;
|
|
1475
1466
|
this._createdTables = false;
|
|
@@ -1538,7 +1529,7 @@ var DbHandler = class {
|
|
|
1538
1529
|
} catch (e) {
|
|
1539
1530
|
await this.initDbIfNeeded();
|
|
1540
1531
|
log.error(`Community (${this._community.address}) failed to create/migrate tables. Current db version (${this.getDbVersion()}), latest db version (${version_default.DB_VERSION}). Error`, e);
|
|
1541
|
-
|
|
1532
|
+
if (this._startLockAddress === void 0) this.destoryConnection();
|
|
1542
1533
|
throw e;
|
|
1543
1534
|
}
|
|
1544
1535
|
hideClassPrivateProps(this);
|
|
@@ -1568,6 +1559,13 @@ var DbHandler = class {
|
|
|
1568
1559
|
}
|
|
1569
1560
|
destoryConnection() {
|
|
1570
1561
|
const log = logger_default("pkc-js:local-community:dbHandler:destroyConnection");
|
|
1562
|
+
if (this.holdsStartLock() && this._db?.open) {
|
|
1563
|
+
const error = /* @__PURE__ */ new Error(`Refused to close the DB connection of community (${this._startLockAddress}) while it has the community started (issue #561)`);
|
|
1564
|
+
log.error(error);
|
|
1565
|
+
if (process.env["VITEST"]) throw error;
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
this._startLockAddress = void 0;
|
|
1571
1569
|
this._preparedStatements.clear();
|
|
1572
1570
|
if (this._db && this._db.open) try {
|
|
1573
1571
|
if (!this._db.readonly) this._db.exec("PRAGMA wal_checkpoint");
|
|
@@ -1836,15 +1834,10 @@ var DbHandler = class {
|
|
|
1836
1834
|
const dbExistsAlready = fs$1.existsSync(dbPath);
|
|
1837
1835
|
if (needToMigrate) {
|
|
1838
1836
|
if (dbExistsAlready && currentDbVersion > 0) {
|
|
1839
|
-
this.destoryConnection();
|
|
1840
1837
|
backupDbPath = path$1.join(path$1.dirname(dbPath), ".backup_before_migration", `${path$1.basename(dbPath)}.${currentDbVersion}.${timestamp()}`);
|
|
1841
1838
|
log(`Copying db ${path$1.basename(dbPath)} to ${backupDbPath} before migration`);
|
|
1842
1839
|
if (!fs$1.existsSync(path$1.dirname(backupDbPath))) await fs$1.promises.mkdir(path$1.dirname(backupDbPath), { recursive: true });
|
|
1843
|
-
|
|
1844
|
-
await sourceDb.backup(backupDbPath);
|
|
1845
|
-
sourceDb.close();
|
|
1846
|
-
this._db = new Database(dbPath);
|
|
1847
|
-
this._db.pragma("journal_mode = WAL");
|
|
1840
|
+
await this._db.backup(backupDbPath);
|
|
1848
1841
|
}
|
|
1849
1842
|
this._db.exec("PRAGMA foreign_keys = OFF");
|
|
1850
1843
|
for (const tableName of [
|
|
@@ -1897,6 +1890,7 @@ var DbHandler = class {
|
|
|
1897
1890
|
if (currentDbVersion < 29) this._backfillApprovedCommentNumbers();
|
|
1898
1891
|
if (currentDbVersion < 31) this._backfillTargetAuthorSignerAddress();
|
|
1899
1892
|
if (currentDbVersion < 32) this._backfillTargetAuthorDomain();
|
|
1893
|
+
if (currentDbVersion < 47) this._stripForbiddenKeysFromChallengeCommentUpdates();
|
|
1900
1894
|
this._db.exec("PRAGMA foreign_keys = ON");
|
|
1901
1895
|
this._db.pragma(`user_version = ${version_default.DB_VERSION}`);
|
|
1902
1896
|
await this.initDbIfNeeded();
|
|
@@ -1981,6 +1975,33 @@ var DbHandler = class {
|
|
|
1981
1975
|
})(moderationsToUpdate);
|
|
1982
1976
|
log(`Backfilled targetAuthorSignerAddress for ${moderationsToUpdate.length} comment moderations`);
|
|
1983
1977
|
}
|
|
1978
|
+
_stripForbiddenKeysFromChallengeCommentUpdates() {
|
|
1979
|
+
const log = logger_default("pkc-js:local-community:db-handler:_stripForbiddenKeysFromChallengeCommentUpdates");
|
|
1980
|
+
const rows = this._db.prepare(`SELECT cid, challengeCommentUpdate FROM ${TABLES.COMMENTS} WHERE challengeCommentUpdate IS NOT NULL`).all();
|
|
1981
|
+
const update = this._db.prepare(`UPDATE ${TABLES.COMMENTS} SET challengeCommentUpdate = ? WHERE cid = ?`);
|
|
1982
|
+
for (const row of rows) {
|
|
1983
|
+
let extras;
|
|
1984
|
+
try {
|
|
1985
|
+
extras = JSON.parse(row.challengeCommentUpdate);
|
|
1986
|
+
} catch {
|
|
1987
|
+
continue;
|
|
1988
|
+
}
|
|
1989
|
+
if (typeof extras !== "object" || extras === null) continue;
|
|
1990
|
+
const topLevel = forbiddenKeysOf(extras);
|
|
1991
|
+
const author = extras.author;
|
|
1992
|
+
const authorKeys = forbiddenKeysOf(author);
|
|
1993
|
+
if (topLevel.length === 0 && authorKeys.length === 0) continue;
|
|
1994
|
+
log(`Comment ${row.cid} has challenge commentUpdate keys that are no longer allowed, dropping`, [...topLevel, ...authorKeys]);
|
|
1995
|
+
const cleaned = {};
|
|
1996
|
+
for (const [key, value] of Object.entries(extras)) if (!topLevel.includes(key)) cleaned[key] = value;
|
|
1997
|
+
if (author && authorKeys.length > 0) {
|
|
1998
|
+
const cleanedAuthor = {};
|
|
1999
|
+
for (const [key, value] of Object.entries(author)) if (!authorKeys.includes(key)) cleanedAuthor[key] = value;
|
|
2000
|
+
cleaned.author = cleanedAuthor;
|
|
2001
|
+
}
|
|
2002
|
+
update.run(Object.keys(cleaned).length > 0 ? JSON.stringify(cleaned) : null, row.cid);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
1984
2005
|
_backfillTargetAuthorDomain() {
|
|
1985
2006
|
const log = logger_default("pkc-js:local-community:db-handler:_backfillTargetAuthorDomain");
|
|
1986
2007
|
const moderationsToUpdate = this._db.prepare(`
|
|
@@ -3915,6 +3936,10 @@ var DbHandler = class {
|
|
|
3915
3936
|
const newPathString = path$1.join(dataPath, "communities", newDbName);
|
|
3916
3937
|
await fs$1.promises.mkdir(path$1.dirname(oldPathString), { recursive: true });
|
|
3917
3938
|
await fs$1.promises.mkdir(path$1.dirname(newPathString), { recursive: true });
|
|
3939
|
+
const doneWritingNewDbFile = markCommunityDbAsBeingWritten({
|
|
3940
|
+
dataPath,
|
|
3941
|
+
communityAddress: newDbName
|
|
3942
|
+
});
|
|
3918
3943
|
try {
|
|
3919
3944
|
if (!fs$1.existsSync(oldPathString)) log(`Old DB file ${oldPathString} does not exist. Cannot backup/rename.`);
|
|
3920
3945
|
else {
|
|
@@ -3931,6 +3956,8 @@ var DbHandler = class {
|
|
|
3931
3956
|
} catch (error) {
|
|
3932
3957
|
log.error(`Failed to backup/rename database from ${oldPathString} to ${newPathString}: `, error);
|
|
3933
3958
|
throw error;
|
|
3959
|
+
} finally {
|
|
3960
|
+
doneWritingNewDbFile();
|
|
3934
3961
|
}
|
|
3935
3962
|
this._dbConfig = {
|
|
3936
3963
|
...this._dbConfig,
|
|
@@ -3938,84 +3965,60 @@ var DbHandler = class {
|
|
|
3938
3965
|
};
|
|
3939
3966
|
log(`Changed db path from (${oldPathString}) to (${newPathString})`);
|
|
3940
3967
|
}
|
|
3941
|
-
async lockCommunityStart(
|
|
3968
|
+
async lockCommunityStart() {
|
|
3942
3969
|
const log = logger_default("pkc-js:local-community:db-handler:lock:start");
|
|
3943
3970
|
const communityAddress = this._community.address;
|
|
3944
|
-
const
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
this._heldStartLock = void 0;
|
|
3953
|
-
log.error(`Lost the start lock of community (${communityAddress}), taken over or removed`, error);
|
|
3954
|
-
onCompromised(error);
|
|
3955
|
-
}
|
|
3956
|
-
});
|
|
3957
|
-
this._heldStartLock = startLock;
|
|
3958
|
-
log(`Locked the start of community (${communityAddress}) successfully`);
|
|
3959
|
-
} catch (e) {
|
|
3960
|
-
if (e instanceof Error && e.message === "Lock file is already being held") throw new PKCError("ERR_COMMUNITY_ALREADY_STARTED", {
|
|
3971
|
+
const dataPath = this._community._pkc.dataPath;
|
|
3972
|
+
await this.initDbIfNeeded();
|
|
3973
|
+
if (this._db.readonly) throw Error("The start of a community can't be claimed on a read-only connection to its DB");
|
|
3974
|
+
const registry = getCommunitiesRegistry(this._community._pkc);
|
|
3975
|
+
if (!registry.claimStart(communityAddress)) throw new PKCError("ERR_COMMUNITY_ALREADY_STARTED", { communityAddress });
|
|
3976
|
+
if (!fs$1.existsSync(path$1.join(dataPath, "communities", communityAddress))) {
|
|
3977
|
+
registry.unregisterCommunity(communityAddress);
|
|
3978
|
+
throw new PKCError("CAN_NOT_LOAD_LOCAL_COMMUNITY_IF_DB_DOES_NOT_EXIST", {
|
|
3961
3979
|
communityAddress,
|
|
3962
|
-
|
|
3980
|
+
dataPath
|
|
3963
3981
|
});
|
|
3964
|
-
else {
|
|
3965
|
-
log(`Error while trying to lock start of community (${communityAddress}): ${e}`);
|
|
3966
|
-
throw e;
|
|
3967
|
-
}
|
|
3968
3982
|
}
|
|
3983
|
+
this._startLockAddress = communityAddress;
|
|
3984
|
+
log(`Locked the start of community (${communityAddress}) successfully`);
|
|
3985
|
+
}
|
|
3986
|
+
holdsStartLock() {
|
|
3987
|
+
return this._startLockAddress !== void 0;
|
|
3969
3988
|
}
|
|
3970
|
-
async unlockCommunityStart(
|
|
3989
|
+
async unlockCommunityStart() {
|
|
3971
3990
|
const log = logger_default("pkc-js:local-community:db-handler:unlock:start");
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
try {
|
|
3978
|
-
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
3979
|
-
log(`Unlocked start of community (${communityAddress})`);
|
|
3980
|
-
} catch (e) {
|
|
3981
|
-
log(`Error while trying to unlock start of community (${communityAddress}): ${e}`);
|
|
3982
|
-
throw e;
|
|
3983
|
-
}
|
|
3991
|
+
const communityAddress = this._startLockAddress;
|
|
3992
|
+
if (communityAddress === void 0) return;
|
|
3993
|
+
this._startLockAddress = void 0;
|
|
3994
|
+
getCommunitiesRegistry(this._community._pkc).releaseStart(communityAddress);
|
|
3995
|
+
log(`Unlocked start of community (${communityAddress})`);
|
|
3984
3996
|
}
|
|
3985
3997
|
async isCommunityStartLocked(communityAddress = this._community.address) {
|
|
3986
|
-
return
|
|
3987
|
-
dataPath: this._community._pkc.dataPath,
|
|
3988
|
-
communityAddress
|
|
3989
|
-
});
|
|
3998
|
+
return getCommunitiesRegistry(this._community._pkc).isStarted(communityAddress);
|
|
3990
3999
|
}
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
4000
|
+
confirmCommunityStartIsStillOurs() {
|
|
4001
|
+
if (this._startLockAddress === void 0) return "owned";
|
|
4002
|
+
return getCommunitiesRegistry(this._community._pkc).confirmStart(this._startLockAddress);
|
|
4003
|
+
}
|
|
4004
|
+
runInWriteTransaction(write) {
|
|
4005
|
+
if (this._db.inTransaction) return write();
|
|
3995
4006
|
try {
|
|
3996
|
-
|
|
3997
|
-
lockfilePath,
|
|
3998
|
-
retries: 5,
|
|
3999
|
-
onCompromised: () => {}
|
|
4000
|
-
});
|
|
4007
|
+
this._db.exec("BEGIN IMMEDIATE");
|
|
4001
4008
|
} catch (e) {
|
|
4002
|
-
|
|
4003
|
-
if (e instanceof Error && e.message === "Lock file is already being held") throw new PKCError("ERR_COMMUNITY_STATE_LOCKED", {
|
|
4009
|
+
if (typeof e.code === "string" && e.code.startsWith("SQLITE_BUSY")) throw new PKCError("ERR_COMMUNITY_STATE_LOCKED", {
|
|
4004
4010
|
communityAddress: this._community.address,
|
|
4005
4011
|
error: e
|
|
4006
4012
|
});
|
|
4013
|
+
throw e;
|
|
4007
4014
|
}
|
|
4008
|
-
}
|
|
4009
|
-
async unlockCommunityState() {
|
|
4010
|
-
const log = logger_default("pkc-js:local-community:db-handler:lock:unlockCommunityState");
|
|
4011
|
-
const lockfilePath = path$1.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
4012
|
-
const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
4013
|
-
if (!fs$1.existsSync(lockfilePath)) return;
|
|
4014
4015
|
try {
|
|
4015
|
-
|
|
4016
|
+
const result = write();
|
|
4017
|
+
this._db.exec("COMMIT");
|
|
4018
|
+
return result;
|
|
4016
4019
|
} catch (e) {
|
|
4017
|
-
|
|
4018
|
-
|
|
4020
|
+
if (this._db.inTransaction) this._db.exec("ROLLBACK");
|
|
4021
|
+
throw e;
|
|
4019
4022
|
}
|
|
4020
4023
|
}
|
|
4021
4024
|
communityDbExists() {
|
|
@@ -4968,8 +4971,49 @@ async function repinCommentUpdateIfNeeded(community) {
|
|
|
4968
4971
|
community._dbHandler.forceUpdateOnAllComments();
|
|
4969
4972
|
}
|
|
4970
4973
|
const MIN_MS_BETWEEN_GC = 3600 * 1e3;
|
|
4971
|
-
const
|
|
4974
|
+
const intervalStartedAtByKuboUrl = /* @__PURE__ */ new Map();
|
|
4972
4975
|
const inFlightGcByKuboUrl = /* @__PURE__ */ new Map();
|
|
4976
|
+
const gcIntervalStorageKey = (kuboUrl) => `repoGcIntervalStartedAt:${kuboUrl}`;
|
|
4977
|
+
async function _readStoredGcIntervalStart({ community, kuboUrl, log }) {
|
|
4978
|
+
try {
|
|
4979
|
+
const stored = await community._pkc._storage.getItem(gcIntervalStorageKey(kuboUrl));
|
|
4980
|
+
return typeof stored === "number" ? stored : void 0;
|
|
4981
|
+
} catch (e) {
|
|
4982
|
+
log.error("Failed to read when the GC interval of the kubo node", kuboUrl, "started", e);
|
|
4983
|
+
return;
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4986
|
+
async function _startGcInterval({ community, kuboUrl, log }) {
|
|
4987
|
+
const now = Date.now();
|
|
4988
|
+
intervalStartedAtByKuboUrl.set(kuboUrl, now);
|
|
4989
|
+
try {
|
|
4990
|
+
await community._pkc._storage.setItem(gcIntervalStorageKey(kuboUrl), now);
|
|
4991
|
+
} catch (e) {
|
|
4992
|
+
log.error("Failed to store when the GC interval of the kubo node", kuboUrl, "started", e);
|
|
4993
|
+
}
|
|
4994
|
+
}
|
|
4995
|
+
async function _isRepoGcDue({ community, kuboUrl, log }) {
|
|
4996
|
+
const isRunning = (startedAt) => typeof startedAt === "number" && startedAt <= Date.now() && Date.now() - startedAt < MIN_MS_BETWEEN_GC;
|
|
4997
|
+
const inMemory = intervalStartedAtByKuboUrl.get(kuboUrl);
|
|
4998
|
+
if (isRunning(inMemory)) return false;
|
|
4999
|
+
const stored = await _readStoredGcIntervalStart({
|
|
5000
|
+
community,
|
|
5001
|
+
kuboUrl,
|
|
5002
|
+
log
|
|
5003
|
+
});
|
|
5004
|
+
const startedAt = typeof stored === "number" && typeof inMemory === "number" ? Math.max(stored, inMemory) : stored ?? inMemory;
|
|
5005
|
+
if (isRunning(startedAt)) {
|
|
5006
|
+
intervalStartedAtByKuboUrl.set(kuboUrl, startedAt);
|
|
5007
|
+
return false;
|
|
5008
|
+
}
|
|
5009
|
+
if (typeof startedAt === "number" && startedAt <= Date.now()) return true;
|
|
5010
|
+
await _startGcInterval({
|
|
5011
|
+
community,
|
|
5012
|
+
kuboUrl,
|
|
5013
|
+
log
|
|
5014
|
+
});
|
|
5015
|
+
return false;
|
|
5016
|
+
}
|
|
4973
5017
|
async function cleanUpIpfsRepoIfDue(community, force = false) {
|
|
4974
5018
|
const log = logger_default("pkc-js:local-community:syncIpnsWithDb:_cleanUpIpfsRepoIfDue");
|
|
4975
5019
|
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
@@ -5015,10 +5059,11 @@ function _describeReclaimedSpace({ before, after }) {
|
|
|
5015
5059
|
}
|
|
5016
5060
|
async function _runRepoGcIfDue({ community, kuboUrl, force, log }) {
|
|
5017
5061
|
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
5018
|
-
if (!force
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5062
|
+
if (!force && !await _isRepoGcDue({
|
|
5063
|
+
community,
|
|
5064
|
+
kuboUrl,
|
|
5065
|
+
log
|
|
5066
|
+
})) return;
|
|
5022
5067
|
const repoSizeBefore = await _readRepoSizeSafely({
|
|
5023
5068
|
kuboRpc,
|
|
5024
5069
|
kuboUrl,
|
|
@@ -5032,7 +5077,11 @@ async function _runRepoGcIfDue({ community, kuboUrl, force, log }) {
|
|
|
5032
5077
|
log.error("Failed to GC ipfs repo due to error", e);
|
|
5033
5078
|
return;
|
|
5034
5079
|
} finally {
|
|
5035
|
-
|
|
5080
|
+
await _startGcInterval({
|
|
5081
|
+
community,
|
|
5082
|
+
kuboUrl,
|
|
5083
|
+
log
|
|
5084
|
+
});
|
|
5036
5085
|
}
|
|
5037
5086
|
const repoSizeAfter = await _readRepoSizeSafely({
|
|
5038
5087
|
kuboRpc,
|
|
@@ -5734,6 +5783,22 @@ async function checkWireFormatAndCommunityAuthor(community, publication, log, au
|
|
|
5734
5783
|
if (publication.timestamp <= timestamp() - 300 || publication.timestamp >= timestamp() + 300) return messages.ERR_PUBLICATION_TIMESTAMP_IS_NOT_IN_PROPER_RANGE;
|
|
5735
5784
|
if (typeof authorCommunity?.banExpiresAt === "number" && authorCommunity.banExpiresAt > timestamp()) return messages.ERR_AUTHOR_IS_BANNED;
|
|
5736
5785
|
}
|
|
5786
|
+
async function checkAuthorWalletProofs(publication, log) {
|
|
5787
|
+
const wallets = publication.author?.wallets;
|
|
5788
|
+
if (!wallets) return void 0;
|
|
5789
|
+
const authorPublicKey = await getPKCAddressFromPublicKey(publication.signature.publicKey);
|
|
5790
|
+
for (const [chainTicker, entry] of Object.entries(wallets)) {
|
|
5791
|
+
const result = verifyAuthorWalletEntry({
|
|
5792
|
+
entry,
|
|
5793
|
+
authorPublicKey,
|
|
5794
|
+
nowSeconds: timestamp()
|
|
5795
|
+
});
|
|
5796
|
+
if (result.outcome === "invalid") {
|
|
5797
|
+
log("Rejecting publication: invalid author.wallets proof", chainTicker, result.reason);
|
|
5798
|
+
return `${messages.ERR_AUTHOR_WALLET_PROOF_IS_INVALID}. Chain ticker: ${chainTicker}. ${result.reason}`;
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
}
|
|
5737
5802
|
async function checkAuthorIdentity(community, publication, log) {
|
|
5738
5803
|
if (publication.author && Object.keys(publication.author).length === 0) return messages.ERR_PUBLICATION_AUTHOR_IS_AN_EMPTY_OBJECT;
|
|
5739
5804
|
if (publication.author && r$2(t$6(publication.author), AuthorReservedFields).length > 0) return messages.ERR_PUBLICATION_AUTHOR_HAS_RESERVED_FIELD;
|
|
@@ -5987,6 +6052,8 @@ async function checkPublicationValidity({ community, request, publication, autho
|
|
|
5987
6052
|
if (wireResult) return wireResult;
|
|
5988
6053
|
const authorResult = await checkAuthorIdentity(community, publication, log);
|
|
5989
6054
|
if (authorResult) return authorResult;
|
|
6055
|
+
const walletProofResult = await checkAuthorWalletProofs(publication, log);
|
|
6056
|
+
if (walletProofResult) return walletProofResult;
|
|
5990
6057
|
const parentResult = await checkParentAndPostState(community, request, publication, authorIdentityMatcher);
|
|
5991
6058
|
if (parentResult) return parentResult;
|
|
5992
6059
|
if (Buffer.byteLength(JSON.stringify(publication)) / 1e3 > 40) return messages.ERR_REQUEST_PUBLICATION_OVER_ALLOWED_SIZE;
|
|
@@ -6962,7 +7029,7 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
6962
7029
|
const log = logger_default("pkc-js:local-community:_publishLoop");
|
|
6963
7030
|
let syncFailedSinceStop = false;
|
|
6964
7031
|
const shouldStopPublishLoop = () => {
|
|
6965
|
-
return community.state !== "started" || community.
|
|
7032
|
+
return community.state !== "started" || community._stopHasBeenCalled && (community._pendingEditProps.length === 0 || syncFailedSinceStop);
|
|
6966
7033
|
};
|
|
6967
7034
|
const waitUntilNextSync = async ({ lastSyncFailed }) => {
|
|
6968
7035
|
const doneWithLoopTime = Date.now();
|
|
@@ -6980,6 +7047,21 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
6980
7047
|
});
|
|
6981
7048
|
};
|
|
6982
7049
|
while (!shouldStopPublishLoop()) {
|
|
7050
|
+
if (isCommunityStartTakenByAnotherInstance(community, log)) {
|
|
7051
|
+
const error = new PKCError("ERR_COMMUNITY_START_TAKEN_BY_ANOTHER_PKC_INSTANCE", {
|
|
7052
|
+
address: community.address,
|
|
7053
|
+
dataPath: community._pkc.dataPath
|
|
7054
|
+
});
|
|
7055
|
+
log.error(error);
|
|
7056
|
+
community._startTakenByAnotherInstance = true;
|
|
7057
|
+
try {
|
|
7058
|
+
community.emit("error", error);
|
|
7059
|
+
} catch (e) {
|
|
7060
|
+
log.error(`A listener of the error of community (${community.address}) threw, or there is none`, e);
|
|
7061
|
+
}
|
|
7062
|
+
community.stop().catch((e) => log.error(`Failed to stop community (${community.address}) after its start was taken`, e));
|
|
7063
|
+
break;
|
|
7064
|
+
}
|
|
6983
7065
|
let lastSyncFailed = false;
|
|
6984
7066
|
try {
|
|
6985
7067
|
await syncIpnsWithDb(community);
|
|
@@ -6995,6 +7077,14 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
6995
7077
|
}
|
|
6996
7078
|
log("Stopping the publishing loop of community", community.address);
|
|
6997
7079
|
}
|
|
7080
|
+
function isCommunityStartTakenByAnotherInstance(community, log) {
|
|
7081
|
+
try {
|
|
7082
|
+
return community._dbHandler.confirmCommunityStartIsStillOurs() === "taken";
|
|
7083
|
+
} catch (e) {
|
|
7084
|
+
log.error(`Failed to confirm that community (${community.address}) is still started by this PKC instance`, e);
|
|
7085
|
+
return false;
|
|
7086
|
+
}
|
|
7087
|
+
}
|
|
6998
7088
|
async function initBeforeStarting(community) {
|
|
6999
7089
|
community.protocolVersion = version_default.PROTOCOL_VERSION;
|
|
7000
7090
|
if (!community.signer?.address) throw new PKCError("ERR_COMMUNITY_SIGNER_NOT_DEFINED");
|
|
@@ -7056,6 +7146,7 @@ async function runAsStartOrUpdateInFlight({ community, setUp }) {
|
|
|
7056
7146
|
async function start(community) {
|
|
7057
7147
|
if (community.state === "updating") throw new PKCError("ERR_NEED_TO_STOP_UPDATING_COMMUNITY_BEFORE_STARTING", { address: community.address });
|
|
7058
7148
|
if (community.state === "started" || community._startOrUpdateInFlight) throw new PKCError("ERR_COMMUNITY_ALREADY_STARTED", { address: community.address });
|
|
7149
|
+
if (community._deleteInFlight) throw new PKCError("ERR_COMMUNITY_IS_BEING_DELETED", { address: community.address });
|
|
7059
7150
|
await runAsStartOrUpdateInFlight({
|
|
7060
7151
|
community,
|
|
7061
7152
|
setUp: (releaseMark) => startCommunity({
|
|
@@ -7066,7 +7157,9 @@ async function start(community) {
|
|
|
7066
7157
|
}
|
|
7067
7158
|
async function startCommunity({ community, releaseMark }) {
|
|
7068
7159
|
const log = logger_default("pkc-js:local-community:start");
|
|
7160
|
+
while (community._stoppedEditsInFlight.size > 0) await Promise.allSettled([...community._stoppedEditsInFlight]);
|
|
7069
7161
|
community._stopHasBeenCalled = false;
|
|
7162
|
+
community._startTakenByAnotherInstance = false;
|
|
7070
7163
|
community._lastProvidedBrowserDialableSelfAddrs = void 0;
|
|
7071
7164
|
community._lastAddressReprovideCheckAt = void 0;
|
|
7072
7165
|
if (!community._clientsManager.getDefaultKuboRpcClientOrHelia()) throw Error("You need to define an IPFS client in your pkc instance to be able to start a local community");
|
|
@@ -7076,9 +7169,6 @@ async function startCommunity({ community, releaseMark }) {
|
|
|
7076
7169
|
publicKey: community.publicKey,
|
|
7077
7170
|
name: community.name
|
|
7078
7171
|
}) || findProcessStartedCommunity(community)) throw new PKCError("ERR_COMMUNITY_ALREADY_STARTED", { address: community.address });
|
|
7079
|
-
community._startLockLost = false;
|
|
7080
|
-
let startLockLostDuringStart;
|
|
7081
|
-
let startFinished = false;
|
|
7082
7172
|
try {
|
|
7083
7173
|
await initBeforeStarting(community);
|
|
7084
7174
|
if (community.anchor && !getPersistedAnchorRecordBytes(community)) throw new PKCError("ERR_DELEGATED_COMMUNITY_HAS_NO_ANCHOR_RECORD", {
|
|
@@ -7091,15 +7181,7 @@ async function startCommunity({ community, releaseMark }) {
|
|
|
7091
7181
|
pkc: community._pkc,
|
|
7092
7182
|
communityAddress: community.address
|
|
7093
7183
|
});
|
|
7094
|
-
await community._dbHandler.lockCommunityStart(
|
|
7095
|
-
community._startLockLost = true;
|
|
7096
|
-
const lostLockError = new PKCError("ERR_COMMUNITY_START_LOCK_COMPROMISED", {
|
|
7097
|
-
communityAddress: community.address,
|
|
7098
|
-
error
|
|
7099
|
-
});
|
|
7100
|
-
if (startFinished) stopAfterLosingStartLock(community, lostLockError);
|
|
7101
|
-
else startLockLostDuringStart = lostLockError;
|
|
7102
|
-
} });
|
|
7184
|
+
await community._dbHandler.lockCommunityStart();
|
|
7103
7185
|
community._setState("started");
|
|
7104
7186
|
await community._updateStartedValue();
|
|
7105
7187
|
trackStartedCommunity(community._pkc, community);
|
|
@@ -7122,14 +7204,11 @@ async function startCommunity({ community, releaseMark }) {
|
|
|
7122
7204
|
community._setStartedStateWithEmission("publishing-ipns");
|
|
7123
7205
|
await community._repinCommentsIPFSIfNeeded();
|
|
7124
7206
|
await repinCommentUpdateIfNeeded(community);
|
|
7125
|
-
if (startLockLostDuringStart) throw startLockLostDuringStart;
|
|
7126
7207
|
await community._listenToIncomingRequests();
|
|
7127
7208
|
await emitChallengeSettingsValidationErrors(community, log);
|
|
7128
7209
|
community._pageSorts = void 0;
|
|
7129
7210
|
community._pageSortFactories = void 0;
|
|
7130
7211
|
await syncPageSortsWithRegistry(community);
|
|
7131
|
-
if (startLockLostDuringStart) throw startLockLostDuringStart;
|
|
7132
|
-
startFinished = true;
|
|
7133
7212
|
} catch (e) {
|
|
7134
7213
|
releaseMark();
|
|
7135
7214
|
await community.stop();
|
|
@@ -7145,12 +7224,6 @@ async function startCommunity({ community, releaseMark }) {
|
|
|
7145
7224
|
community.emit("error", err);
|
|
7146
7225
|
});
|
|
7147
7226
|
}
|
|
7148
|
-
function stopAfterLosingStartLock(community, error) {
|
|
7149
|
-
const log = logger_default("pkc-js:local-community:stopAfterLosingStartLock");
|
|
7150
|
-
if (community.state !== "started") return;
|
|
7151
|
-
if (!community._stopHasBeenCalled) community.stop().catch((e) => log.error(`Failed to stop community (${community.address}) after losing its start lock`, e));
|
|
7152
|
-
community.emit("error", error);
|
|
7153
|
-
}
|
|
7154
7227
|
async function initMirroringStartedOrUpdatingCommunity(community, startedCommunity) {
|
|
7155
7228
|
const updatingStateChangeListener = (newState) => {
|
|
7156
7229
|
community._setUpdatingStateWithEventEmissionIfNewState(newState);
|
|
@@ -7319,8 +7392,9 @@ async function stopCommunity(community) {
|
|
|
7319
7392
|
}
|
|
7320
7393
|
community._publishLoopPromise = void 0;
|
|
7321
7394
|
}
|
|
7322
|
-
|
|
7323
|
-
|
|
7395
|
+
const startTakenByAnotherInstance = community._startTakenByAnotherInstance || isCommunityStartTakenByAnotherInstance(community, log);
|
|
7396
|
+
community._startTakenByAnotherInstance = false;
|
|
7397
|
+
if (!startTakenByAnotherInstance) {
|
|
7324
7398
|
try {
|
|
7325
7399
|
await unpinStaleCids(community, { bypassGracePeriod: true });
|
|
7326
7400
|
} catch (e) {
|
|
@@ -7331,11 +7405,11 @@ async function stopCommunity(community) {
|
|
|
7331
7405
|
} catch (e) {
|
|
7332
7406
|
log.error("Failed to update db internal state before stopping", e);
|
|
7333
7407
|
}
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
}
|
|
7408
|
+
}
|
|
7409
|
+
try {
|
|
7410
|
+
await community._dbHandler.unlockCommunityStart();
|
|
7411
|
+
} catch (e) {
|
|
7412
|
+
log.error(`Failed to unlock start lock on community (${community.address})`, e);
|
|
7339
7413
|
}
|
|
7340
7414
|
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
7341
7415
|
community._setStartedStateWithEmission("stopped");
|
|
@@ -7344,7 +7418,6 @@ async function stopCommunity(community) {
|
|
|
7344
7418
|
community._duplicatePublicationAttempts?.clear();
|
|
7345
7419
|
community._inFlightPublicationExchanges.clear();
|
|
7346
7420
|
await community._dbHandler.rollbackAllTransactions();
|
|
7347
|
-
await community._dbHandler.unlockCommunityState();
|
|
7348
7421
|
await community._updateStartedValue();
|
|
7349
7422
|
community._clientsManager.updateKuboRpcState("stopped", kuboRpcClient.url);
|
|
7350
7423
|
community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("stopped");
|
|
@@ -7370,7 +7443,19 @@ async function stopCommunity(community) {
|
|
|
7370
7443
|
}
|
|
7371
7444
|
const DELETE_UNPIN_SLICE_SIZE = 5e3;
|
|
7372
7445
|
async function deleteCommunity(community) {
|
|
7446
|
+
let settle;
|
|
7447
|
+
const inFlight = new Promise((resolve) => settle = resolve);
|
|
7448
|
+
community._deleteInFlight = inFlight;
|
|
7449
|
+
try {
|
|
7450
|
+
await deleteCommunityWhileMarked(community);
|
|
7451
|
+
} finally {
|
|
7452
|
+
if (community._deleteInFlight === inFlight) community._deleteInFlight = void 0;
|
|
7453
|
+
settle();
|
|
7454
|
+
}
|
|
7455
|
+
}
|
|
7456
|
+
async function deleteCommunityWhileMarked(community) {
|
|
7373
7457
|
const log = logger_default("pkc-js:local-community:delete");
|
|
7458
|
+
while (community._startOrUpdateInFlight) await community._startOrUpdateInFlight;
|
|
7374
7459
|
log.trace(`Attempting to stop the community (${community.address}) before deleting, if needed`);
|
|
7375
7460
|
const startedCommunity = findStartedCommunity(community._pkc, {
|
|
7376
7461
|
publicKey: community.publicKey,
|
|
@@ -7439,7 +7524,11 @@ async function deleteCommunity(community) {
|
|
|
7439
7524
|
community._dbHandler.destoryConnection();
|
|
7440
7525
|
}
|
|
7441
7526
|
await moveCommunityDbToDeletedDirectory(community.address, community._pkc);
|
|
7442
|
-
|
|
7527
|
+
try {
|
|
7528
|
+
unregisterLocalCommunity(community._pkc, community.address);
|
|
7529
|
+
} catch (e) {
|
|
7530
|
+
log.error(`Failed to remove deleted community (${community.address}) from the communities registry`, e);
|
|
7531
|
+
}
|
|
7443
7532
|
log(`Deleted community (${community.address}) successfully`);
|
|
7444
7533
|
}
|
|
7445
7534
|
//#endregion
|
|
@@ -7551,8 +7640,15 @@ function deriveNameAndAddressEdit(community, editOptions) {
|
|
|
7551
7640
|
name: isStringDomain(address) ? address : void 0
|
|
7552
7641
|
};
|
|
7553
7642
|
}
|
|
7554
|
-
function listRenamedCommunityNow(community) {
|
|
7555
|
-
|
|
7643
|
+
function listRenamedCommunityNow(community, { oldAddress, newAddress }) {
|
|
7644
|
+
try {
|
|
7645
|
+
getCommunitiesRegistry(community._pkc).renameCommunity({
|
|
7646
|
+
oldAddress,
|
|
7647
|
+
newAddress
|
|
7648
|
+
});
|
|
7649
|
+
} catch (error) {
|
|
7650
|
+
logger_default("pkc-js:local-community:edit").error(`Failed to list the renamed community under its new address (${newAddress}) in the communities registry`, error);
|
|
7651
|
+
}
|
|
7556
7652
|
}
|
|
7557
7653
|
async function movePostUpdatesFolderBack({ community, oldAddress, newAddress, log }) {
|
|
7558
7654
|
try {
|
|
@@ -7641,6 +7737,7 @@ async function editPropsOnStartedCommunity(community, parsedEditOptions, pagesEd
|
|
|
7641
7737
|
const log = logger_default("pkc-js:local-community:start:editPropsOnStartedCommunity");
|
|
7642
7738
|
const oldAddress = t$9(community.address);
|
|
7643
7739
|
const uniqueEditId = (0, import_sha256.sha256)(stringify(parsedEditOptions));
|
|
7740
|
+
let storedEdit;
|
|
7644
7741
|
if (typeof parsedEditOptions.address === "string" && community.address !== parsedEditOptions.address) {
|
|
7645
7742
|
const newAddress = parsedEditOptions.address;
|
|
7646
7743
|
await validateNewAddressBeforeEditing(community, newAddress, log);
|
|
@@ -7680,7 +7777,10 @@ async function editPropsOnStartedCommunity(community, parsedEditOptions, pagesEd
|
|
|
7680
7777
|
});
|
|
7681
7778
|
throw error;
|
|
7682
7779
|
}
|
|
7683
|
-
listRenamedCommunityNow(community
|
|
7780
|
+
listRenamedCommunityNow(community, {
|
|
7781
|
+
oldAddress,
|
|
7782
|
+
newAddress
|
|
7783
|
+
});
|
|
7684
7784
|
community.setAddress(newAddress);
|
|
7685
7785
|
await community._dbHandler.initDbIfNeeded();
|
|
7686
7786
|
await updateDbInternalState(community, { ...parsedEditOptions });
|
|
@@ -7691,10 +7791,18 @@ async function editPropsOnStartedCommunity(community, parsedEditOptions, pagesEd
|
|
|
7691
7791
|
await community.start();
|
|
7692
7792
|
} else {
|
|
7693
7793
|
if (!e(parsedEditOptions)) {
|
|
7694
|
-
const
|
|
7794
|
+
const editToStore = { ...parsedEditOptions };
|
|
7795
|
+
const store = updateDbInternalState(community, () => {
|
|
7796
|
+
community._editsStoredNotApplied.add(editToStore);
|
|
7797
|
+
return { ...parsedEditOptions };
|
|
7798
|
+
});
|
|
7799
|
+
storedEdit = editToStore;
|
|
7695
7800
|
community._editStoresInFlight.add(store);
|
|
7696
7801
|
try {
|
|
7697
7802
|
await store;
|
|
7803
|
+
} catch (e) {
|
|
7804
|
+
community._editsStoredNotApplied.delete(editToStore);
|
|
7805
|
+
throw e;
|
|
7698
7806
|
} finally {
|
|
7699
7807
|
community._editStoresInFlight.delete(store);
|
|
7700
7808
|
}
|
|
@@ -7704,16 +7812,20 @@ async function editPropsOnStartedCommunity(community, parsedEditOptions, pagesEd
|
|
|
7704
7812
|
editId: uniqueEditId
|
|
7705
7813
|
});
|
|
7706
7814
|
}
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7815
|
+
try {
|
|
7816
|
+
if (community.updateCid) await community.initInternalCommunityAfterFirstUpdateNoMerge({
|
|
7817
|
+
...community.toJSONInternalAfterFirstUpdate(),
|
|
7818
|
+
...parsedEditOptions,
|
|
7819
|
+
_internalStateUpdateId: uniqueEditId
|
|
7820
|
+
});
|
|
7821
|
+
else await community.initInternalCommunityBeforeFirstUpdateNoMerge({
|
|
7822
|
+
...community.toJSONInternalBeforeFirstUpdate(),
|
|
7823
|
+
...parsedEditOptions,
|
|
7824
|
+
_internalStateUpdateId: uniqueEditId
|
|
7825
|
+
});
|
|
7826
|
+
} finally {
|
|
7827
|
+
if (storedEdit) community._editsStoredNotApplied.delete(storedEdit);
|
|
7828
|
+
}
|
|
7717
7829
|
await applyPagesEdit(community, pagesEdit);
|
|
7718
7830
|
community._communityUpdateTrigger = true;
|
|
7719
7831
|
log(`Community (${community.address}) props (${t$6(parsedEditOptions)}) has been edited. Will be including edited props in next update: `, t$10(community, t$6(parsedEditOptions)));
|
|
@@ -7725,6 +7837,17 @@ async function editPropsOnStartedCommunity(community, parsedEditOptions, pagesEd
|
|
|
7725
7837
|
return community;
|
|
7726
7838
|
}
|
|
7727
7839
|
async function editPropsOnNotStartedCommunity(community, parsedEditOptions, pagesEdit) {
|
|
7840
|
+
let settle;
|
|
7841
|
+
const inFlight = new Promise((resolve) => settle = resolve);
|
|
7842
|
+
community._stoppedEditsInFlight.add(inFlight);
|
|
7843
|
+
try {
|
|
7844
|
+
return await editPropsOnNotStartedCommunityWhileMarked(community, parsedEditOptions, pagesEdit);
|
|
7845
|
+
} finally {
|
|
7846
|
+
community._stoppedEditsInFlight.delete(inFlight);
|
|
7847
|
+
settle();
|
|
7848
|
+
}
|
|
7849
|
+
}
|
|
7850
|
+
async function editPropsOnNotStartedCommunityWhileMarked(community, parsedEditOptions, pagesEdit) {
|
|
7728
7851
|
const log = logger_default("pkc-js:local-community:edit:editPropsOnNotStartedCommunity");
|
|
7729
7852
|
const oldAddress = t$9(community.address);
|
|
7730
7853
|
await community.initDbHandlerIfNeeded();
|
|
@@ -7747,7 +7870,10 @@ async function editPropsOnNotStartedCommunity(community, parsedEditOptions, page
|
|
|
7747
7870
|
log
|
|
7748
7871
|
})).error;
|
|
7749
7872
|
}
|
|
7750
|
-
listRenamedCommunityNow(community
|
|
7873
|
+
listRenamedCommunityNow(community, {
|
|
7874
|
+
oldAddress,
|
|
7875
|
+
newAddress
|
|
7876
|
+
});
|
|
7751
7877
|
await community._dbHandler.initDbIfNeeded();
|
|
7752
7878
|
community.setAddress(parsedEditOptions.address);
|
|
7753
7879
|
}
|
|
@@ -7755,12 +7881,13 @@ async function editPropsOnNotStartedCommunity(community, parsedEditOptions, page
|
|
|
7755
7881
|
if ("updatedAt" in mergedInternalState && mergedInternalState.updatedAt) await community.initInternalCommunityAfterFirstUpdateNoMerge(mergedInternalState);
|
|
7756
7882
|
else await community.initInternalCommunityBeforeFirstUpdateNoMerge(mergedInternalState);
|
|
7757
7883
|
await applyPagesEdit(community, pagesEdit);
|
|
7758
|
-
|
|
7884
|
+
community._dbHandler.destoryConnection();
|
|
7759
7885
|
community.emit("update", community);
|
|
7760
7886
|
return community;
|
|
7761
7887
|
}
|
|
7888
|
+
const isStartInFlight = (community) => community.state === "stopped" && community._startOrUpdateInFlight !== void 0;
|
|
7762
7889
|
async function edit(community, newCommunityOptions) {
|
|
7763
|
-
while (community._stopInFlight) await community._stopInFlight;
|
|
7890
|
+
while (community._stopInFlight || isStartInFlight(community)) await (community._stopInFlight ?? community._startOrUpdateInFlight);
|
|
7764
7891
|
const startedCommunity = findStartedCommunity(community._pkc, {
|
|
7765
7892
|
publicKey: community.publicKey,
|
|
7766
7893
|
name: community.name
|
|
@@ -7773,6 +7900,7 @@ async function edit(community, newCommunityOptions) {
|
|
|
7773
7900
|
}
|
|
7774
7901
|
await community.initDbHandlerIfNeeded();
|
|
7775
7902
|
await community._updateStartedValue();
|
|
7903
|
+
if (isStartInFlight(community)) return edit(community, newCommunityOptions);
|
|
7776
7904
|
if (community.started && community.state !== "started") {
|
|
7777
7905
|
community._dbHandler.destoryConnection();
|
|
7778
7906
|
throw new PKCError("ERR_CAN_NOT_EDIT_A_LOCAL_COMMUNITY_THAT_IS_ALREADY_STARTED_IN_ANOTHER_PROCESS", {
|
|
@@ -7791,7 +7919,7 @@ async function edit(community, newCommunityOptions) {
|
|
|
7791
7919
|
...n$2(editWithDerivedName, ["roles"]),
|
|
7792
7920
|
...newInternalProps
|
|
7793
7921
|
};
|
|
7794
|
-
if (community._stopInFlight) return edit(community, newCommunityOptions);
|
|
7922
|
+
if (community._stopInFlight || isStartInFlight(community)) return edit(community, newCommunityOptions);
|
|
7795
7923
|
if (!community.started && !startedCommunity) return editPropsOnNotStartedCommunity(community, newProps, pagesEdit);
|
|
7796
7924
|
if (findStartedCommunity(community._pkc, {
|
|
7797
7925
|
publicKey: community.publicKey,
|
|
@@ -8023,12 +8151,15 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8023
8151
|
this._pageSorts = void 0;
|
|
8024
8152
|
this._pageSortFactories = void 0;
|
|
8025
8153
|
this._reportedChallengeLoadFailures = void 0;
|
|
8026
|
-
this.
|
|
8154
|
+
this._startTakenByAnotherInstance = false;
|
|
8027
8155
|
this._publishLoopPromise = void 0;
|
|
8028
8156
|
this._updateLoopPromise = void 0;
|
|
8029
8157
|
this._startOrUpdateInFlight = void 0;
|
|
8030
8158
|
this._stopInFlight = void 0;
|
|
8159
|
+
this._deleteInFlight = void 0;
|
|
8160
|
+
this._stoppedEditsInFlight = /* @__PURE__ */ new Set();
|
|
8031
8161
|
this._editStoresInFlight = /* @__PURE__ */ new Set();
|
|
8162
|
+
this._editsStoredNotApplied = /* @__PURE__ */ new Set();
|
|
8032
8163
|
this._internalStateUpdateId = "";
|
|
8033
8164
|
this._lastPubsubTopicRoutingProvideAt = void 0;
|
|
8034
8165
|
this._subscribedChallengePubsubTopic = void 0;
|
|
@@ -8131,11 +8262,6 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8131
8262
|
}
|
|
8132
8263
|
async _updateStartedValue() {
|
|
8133
8264
|
this.started = await this._dbHandler.isCommunityStartLocked(this.address);
|
|
8134
|
-
try {
|
|
8135
|
-
refreshCommunitiesList(this._pkc);
|
|
8136
|
-
} catch (e) {
|
|
8137
|
-
logger_default("pkc-js:local-community:_updateStartedValue").error("Failed to refresh pkc.communities", e);
|
|
8138
|
-
}
|
|
8139
8265
|
}
|
|
8140
8266
|
async initNewLocalCommunityPropsNoMerge(newProps) {
|
|
8141
8267
|
return initNewLocalCommunityPropsNoMerge(this, newProps);
|
|
@@ -8282,7 +8408,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8282
8408
|
try {
|
|
8283
8409
|
return { moderations: this._dbHandler.queryAllCommentModerations(opts) };
|
|
8284
8410
|
} finally {
|
|
8285
|
-
if (this.state === "stopped") this._dbHandler.destoryConnection();
|
|
8411
|
+
if (this.state === "stopped" && !this._startOrUpdateInFlight) this._dbHandler.destoryConnection();
|
|
8286
8412
|
}
|
|
8287
8413
|
}
|
|
8288
8414
|
async _cancelExport(exportId) {
|
|
@@ -8294,8 +8420,8 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8294
8420
|
async _loadExportsFromKeyv() {
|
|
8295
8421
|
return loadAndPruneExportsFromKeyv(this);
|
|
8296
8422
|
}
|
|
8297
|
-
|
|
8298
|
-
return getDbInternalState(this
|
|
8423
|
+
_getDbInternalState() {
|
|
8424
|
+
return getDbInternalState(this);
|
|
8299
8425
|
}
|
|
8300
8426
|
async _listenToIncomingRequests() {
|
|
8301
8427
|
return listenToIncomingRequests(this);
|