@pkcprotocol/pkc-js 0.0.141 → 0.0.143
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 +1 -0
- package/dist/browser/clients/base-client-manager.js +6 -1
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js +15 -8
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +2 -0
- package/dist/browser/clients/rpc-client/schema.d.ts +2 -0
- package/dist/browser/community/rpc-local-community.d.ts +12 -1
- package/dist/browser/community/rpc-local-community.js +133 -10
- package/dist/browser/community/rpc-local-community.js.map +1 -1
- package/dist/browser/community/schema.d.ts +19 -0
- package/dist/browser/community/schema.js +7 -3
- package/dist/browser/community/schema.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/helia/helia-for-pkc.js +18 -1
- package/dist/browser/helia/helia-for-pkc.js.map +1 -1
- package/dist/browser/index-with-compile-cache.d.ts +2 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/object-key-util.js +5 -1
- package/dist/browser/object-key-util.js.map +1 -1
- package/dist/browser/pages/pages-client-manager.d.ts +1 -0
- package/dist/browser/pages/pages-client-manager.js +22 -5
- package/dist/browser/pages/pages-client-manager.js.map +1 -1
- package/dist/browser/pages/pkc-js-page-sorts/top.js +2 -1
- package/dist/browser/pages/pkc-js-page-sorts/top.js.map +1 -1
- package/dist/browser/pages/schema.js +3 -1
- package/dist/browser/pages/schema.js.map +1 -1
- package/dist/browser/pkc/pkc-with-rpc-client.js +9 -5
- package/dist/browser/pkc/pkc-with-rpc-client.js.map +1 -1
- package/dist/browser/pkc/pkc.d.ts +4 -1
- package/dist/browser/pkc/pkc.js +6 -5
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/publications/comment/comment-client-manager.js +11 -11
- package/dist/browser/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/browser/publications/comment/comment.js +2 -0
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/publications/community-edit/schema.d.ts +8 -0
- package/dist/browser/publications/publication-client-manager.js +7 -1
- package/dist/browser/publications/publication-client-manager.js.map +1 -1
- package/dist/browser/publications/publication.d.ts +7 -0
- package/dist/browser/publications/publication.js +88 -24
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/pubsub-messages/schema.d.ts +4 -0
- package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +2 -0
- package/dist/browser/rpc/src/schema.d.ts +12 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +3 -0
- package/dist/browser/runtime/node/community/db-handler.js +22 -4
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +70 -19
- package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.d.ts +14 -0
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js +206 -0
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community.js +4 -0
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/community/page-sorts/index.js +10 -10
- package/dist/browser/runtime/node/community/page-sorts/index.js.map +1 -1
- package/dist/browser/schema/schema-util.d.ts +8 -0
- package/dist/browser/schema.d.ts +16 -0
- package/dist/browser/test/mock-ipfs-client.js +10 -4
- package/dist/browser/test/mock-ipfs-client.js.map +1 -1
- package/dist/browser/util.d.ts +5 -0
- package/dist/browser/util.js +52 -5
- package/dist/browser/util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +165 -123
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-C3zShnXN.js → helia-for-pkc-DpsMZzv8.js} +41 -34
- package/dist/bundled/chunks/{local-community-PFaUvMFo.js → local-community-BglT8AUy.js} +284 -47
- package/dist/bundled/chunks/{local-community-DMklqSLp.js → local-community-DEaDtekb.js} +1 -1
- package/dist/bundled/chunks/{node-CGmAA0az.js → node-Tkx_TCqE.js} +84 -34
- package/dist/bundled/chunks/{page-sort-scoring-Bz65Z28_.js → page-sort-scoring-DY7SvqJA.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-Dq_6nnU1.js → rpc-local-community-Br_xomgn.js} +128 -20
- package/dist/bundled/chunks/src-ABfmT8J2.js +2323 -0
- package/dist/bundled/chunks/src-BC60-Q7v.js +2 -0
- package/dist/bundled/chunks/src-BHqirG63.js +2 -0
- package/dist/bundled/chunks/{src-BggJ_InF.js → src-Bj5iE3qB.js} +2 -1999
- package/dist/bundled/chunks/src-CNab3O7M.js +2001 -0
- package/dist/bundled/chunks/{src-BsiPSkhv.js → src-ltPxiZKf.js} +1312 -3632
- package/dist/bundled/chunks/{util-C6YaxADn.js → util-C5RiQF_G.js} +59 -10
- package/dist/bundled/chunks/{util-CzoLr9RY.js → util-DIkZirPy.js} +1 -1
- package/dist/bundled/chunks/{validate-package-factories-DMzx5r6y.js → validate-package-factories-DnW2JiL5.js} +2 -2
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/page-sorts.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/clients/base-client-manager.js +6 -1
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/clients/rpc-client/pkc-rpc-client.js +15 -8
- package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +2 -0
- package/dist/node/clients/rpc-client/schema.d.ts +2 -0
- package/dist/node/community/rpc-local-community.d.ts +12 -1
- package/dist/node/community/rpc-local-community.js +133 -10
- package/dist/node/community/rpc-local-community.js.map +1 -1
- package/dist/node/community/schema.d.ts +19 -0
- package/dist/node/community/schema.js +7 -3
- package/dist/node/community/schema.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/helia/helia-for-pkc.js +18 -1
- package/dist/node/helia/helia-for-pkc.js.map +1 -1
- package/dist/node/index-with-compile-cache.d.ts +2 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/object-key-util.js +5 -1
- package/dist/node/object-key-util.js.map +1 -1
- package/dist/node/pages/pages-client-manager.d.ts +1 -0
- package/dist/node/pages/pages-client-manager.js +22 -5
- package/dist/node/pages/pages-client-manager.js.map +1 -1
- package/dist/node/pages/pkc-js-page-sorts/top.js +2 -1
- package/dist/node/pages/pkc-js-page-sorts/top.js.map +1 -1
- package/dist/node/pages/schema.js +3 -1
- package/dist/node/pages/schema.js.map +1 -1
- package/dist/node/pkc/pkc-with-rpc-client.js +9 -5
- package/dist/node/pkc/pkc-with-rpc-client.js.map +1 -1
- package/dist/node/pkc/pkc.d.ts +4 -1
- package/dist/node/pkc/pkc.js +6 -5
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/publications/comment/comment-client-manager.js +11 -11
- package/dist/node/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/node/publications/comment/comment.js +2 -0
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/publications/community-edit/schema.d.ts +8 -0
- package/dist/node/publications/publication-client-manager.js +7 -1
- package/dist/node/publications/publication-client-manager.js.map +1 -1
- package/dist/node/publications/publication.d.ts +7 -0
- package/dist/node/publications/publication.js +88 -24
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/pubsub-messages/schema.d.ts +4 -0
- package/dist/node/rpc/src/lib/pkc-js/index.d.ts +2 -0
- package/dist/node/rpc/src/schema.d.ts +12 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +3 -0
- package/dist/node/runtime/node/community/db-handler.js +22 -4
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community/comment-updates.js +70 -19
- package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.d.ts +14 -0
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.js +206 -0
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.js.map +1 -0
- package/dist/node/runtime/node/community/local-community.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community.js +4 -0
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/community/page-sorts/index.js +10 -10
- package/dist/node/runtime/node/community/page-sorts/index.js.map +1 -1
- package/dist/node/schema/schema-util.d.ts +8 -0
- package/dist/node/schema.d.ts +16 -0
- package/dist/node/test/mock-ipfs-client.js +10 -4
- package/dist/node/test/mock-ipfs-client.js.map +1 -1
- package/dist/node/util.d.ts +5 -0
- package/dist/node/util.js +52 -5
- package/dist/node/util.js.map +1 -1
- package/package.json +4 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { i as __toESM } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $ as
|
|
3
|
-
import { $ as createSchemaRowParser, An as verifyChallengeAnswer, Bn as verifyCommunityEdit, Br as t$8, Cr as getThumbnailPropsOfLink, Dr as moveCommunityDbToDeletedDirectory, Dt as parseJsonWithPKCErrorIfFails, En as signCommunity, Fn as verifyCommentIpfs, Fr as isCommunityStartLocked, Gr as stringify, Hn as verifyVote, Hr as n$4, In as verifyCommentModeration, Ir as require_src, Kn as getAuthorNameFromWire, Ln as verifyCommentPubsubMessage, Lr as t$10, Mn as verifyChallengeRequest, Mr as findCommunitiesEntry, N as MAX_PAGE_SIZE_BYTES, Or as refreshCommunitiesList, Pn as verifyCommentEdit, Q as collectSchemaRowCoercions, Qn as effectiveMaxCrosspostDepth, Rn as verifyCommentUpdate, Rr as t$11, S as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, Sn as signCommentEdit, Tn as signCommentUpdateForChallengeVerification, Un as buildRuntimeAuthor, Vr as n$5, W as pLimit, Wn as cleanWireAuthor, Wr as t$9, X as coerceSchemaRowBoolean, Xr as STORAGE_KEYS, Z as coerceSchemaRowJson, Zn as crosspostChainDepthUpTo, Zr as require_lodash_merge, _ as createAuthorIdentityMatcher, _r as deriveCommentIpfsFromCommentTableRow, a as generatePagesReportingFailedSorts, ar as encode, b as KeyvBetterSqlite3, bn as signChallengeVerification, c as resolvePageSortsOrThrow, cn as SignerWithPublicKeyAddress, cr as getPKCAddressFromPublicKey, d as getChallengeVerification, dr as BackupAbortError, dt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, f as getCommunityChallengeFromCommunityChallengeSettings, fn as decryptEd25519AesGcmPublicKeyBuffer, fr as backupCommunityDb, g as authorNameResolveFailureReason, gn as cleanUpBeforePublishing, gr as deleteOldCommunityInWindows, h as authorIdentityMatcherForRequest, hn as _validateSignatureOfPKCRecord, i as derivePublicPageSorts, ir as decode, j as iterateOverPageCidsToFindAllCids, kr as resolveDbPostsCidRefs, lr as getPKCAddressFromPublicKeySync, m as pkcJsChallenges, mn as encryptEd25519AesGcmPublicKeyBuffer, mr as calculateInlineRepliesBudget, nr as getCommunityPublicKeyFromWire, o as loadPageSortsForStartedCommunity, p as loadChallengeFileFromCommunityChallengeSettings, pr as calculateExpectedSignatureSize, pt as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, r as computePageSortsFingerprint, s as lookupPageSortFactories, sr as getIpfsKeyFromPrivateKey, t as RpcLocalCommunity, tr as getCommunityNameFromWire, u as deriveCommunityChallengesOrThrow, ur as getPublicKeyFromPrivateKey, v as TrackedInstanceRegistry, vn as signChallengeMessage, vr as deriveDbPosts, w as TIMEFRAMES_TO_SECONDS, wn as signCommentUpdate, wr as importSignerIntoKuboNode, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, xn as signComment, xr as getDefaultCommunityDbConfig, y as LRUCache, yr as deriveDbReplies, zn as verifyCommunity, zr as r$2 } from "./rpc-local-community-
|
|
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 { Ar as t$2, At as pTimeout, B as pubsubTopicToDhtKey, Bn as CommentUpdateSchema, Br as logger_default, Bt as DecryptedChallengeRequestPublicationSchema, C as hideClassPrivateProps, Cr as e, Dn as VotePubsubReservedFields, Dt as untrackUpdatingCommunity, En as VotePubsubMessagePublicationSchema, Er as t$3, F as isLinkOfVideo, Ft as ChallengeRequestMessageSchema, G as removeBlocksFromKuboNode, Hn as CommentUpdateTableRowSchema, I as isLinkValid, J as removeNullUndefinedValues, K as removeMfsFilesSafely, Lt as ChallengeVerificationMessageSchema, M as isLinkOfAudio, Mn as CommentIpfsSchema, Mr as require_retry, N as isLinkOfImage, Nn as CommentPubsubMessageReservedFields, Nt as ChallengeMessageSchema, Ot as require_sha256, P as isLinkOfMedia, Q as retryKuboBlockPutPinAndProvidePubsubTopic, Qn as CommentEditReservedFields, Rr as PKCError, Sr as e$1, St as trackStartedCommunity, T as ipnsNameToIpnsOverPubsubTopic, Tr as r$1, Tt as untrackStartedCommunity, Un as CommentsTableRowSchema, Vt as DecryptedChallengeRequestSchema, Xn as CommentEditPubsubMessagePublicationSchema, Yt as version_default, Zn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Zt as CommunityEditPublicationPubsubReservedFields, _ as genToArray, _r as n$3, an as CommentModerationsTableRowSchema, ar as AuthorReservedFields, b as getIpnsRecordInLocalKuboNode, br as t$5, c as contentContainsMarkdownImages, ct as withSortedKeys, dt as findCommunityInRegistry, er as CommentEditsTableRowSchema, et as retryKuboIpfsAddAndProvide, f as derivePublicationFromChallengeRequest, ft as findStartedCommunity, g as findMalformedUnicodeString, gr as isStringDomain, hn as CommunitySignedPropertyNames, i as calculateStringSizeSameAsIpfsAddCidV0, it as statMfsPathSafely, j as isLinkOfAnimatedImage, jt as ChallengeAnswerMessageSchema, kn as VoteTablesRowSchema, kr as t$4, l as contentContainsMarkdownVideos, lt as withSortedKeysDeep, mn as CommunityIpfsSchema, mt as findUpdatingCommunity, ni as ZodError, nn as CommentModerationPubsubMessagePublicationSchema, o as calculateUnixFsDagSizeCidV0, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, r as calculateIpfsCidV0, rn as CommentModerationReservedFields, rt as sleepUntilTimeoutOrAbort, s as contentContainsMarkdownAudio, ut as writeKuboFilesWithTimeout, v as getEquivalentCommunityAddresses, vr as t$7, wt as trackUpdatingCommunity, xr as t$6, xt as syncCommunityRegistryEntry, y as getErrorCodeFromMessage, yr as n$2, zr as messages } from "./util-C5RiQF_G.js";
|
|
3
|
+
import { $ as createSchemaRowParser, An as verifyChallengeAnswer, Bn as verifyCommunityEdit, Br as t$8, Cr as getThumbnailPropsOfLink, Dr as moveCommunityDbToDeletedDirectory, Dt as parseJsonWithPKCErrorIfFails, En as signCommunity, Fn as verifyCommentIpfs, Fr as isCommunityStartLocked, Gr as stringify, Hn as verifyVote, Hr as n$4, In as verifyCommentModeration, Ir as require_src, Kn as getAuthorNameFromWire, Ln as verifyCommentPubsubMessage, Lr as t$10, Mn as verifyChallengeRequest, Mr as findCommunitiesEntry, N as MAX_PAGE_SIZE_BYTES, Or as refreshCommunitiesList, Pn as verifyCommentEdit, Q as collectSchemaRowCoercions, Qn as effectiveMaxCrosspostDepth, Rn as verifyCommentUpdate, Rr as t$11, S as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, Sn as signCommentEdit, Tn as signCommentUpdateForChallengeVerification, Un as buildRuntimeAuthor, Vr as n$5, W as pLimit, Wn as cleanWireAuthor, Wr as t$9, X as coerceSchemaRowBoolean, Xr as STORAGE_KEYS, Z as coerceSchemaRowJson, Zn as crosspostChainDepthUpTo, Zr as require_lodash_merge, _ as createAuthorIdentityMatcher, _r as deriveCommentIpfsFromCommentTableRow, a as generatePagesReportingFailedSorts, ar as encode, b as KeyvBetterSqlite3, bn as signChallengeVerification, c as resolvePageSortsOrThrow, cn as SignerWithPublicKeyAddress, cr as getPKCAddressFromPublicKey, d as getChallengeVerification, dr as BackupAbortError, dt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, f as getCommunityChallengeFromCommunityChallengeSettings, fn as decryptEd25519AesGcmPublicKeyBuffer, fr as backupCommunityDb, g as authorNameResolveFailureReason, gn as cleanUpBeforePublishing, gr as deleteOldCommunityInWindows, h as authorIdentityMatcherForRequest, hn as _validateSignatureOfPKCRecord, i as derivePublicPageSorts, ir as decode, j as iterateOverPageCidsToFindAllCids, kr as resolveDbPostsCidRefs, lr as getPKCAddressFromPublicKeySync, m as pkcJsChallenges, mn as encryptEd25519AesGcmPublicKeyBuffer, mr as calculateInlineRepliesBudget, nr as getCommunityPublicKeyFromWire, o as loadPageSortsForStartedCommunity, p as loadChallengeFileFromCommunityChallengeSettings, pr as calculateExpectedSignatureSize, pt as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, r as computePageSortsFingerprint, s as lookupPageSortFactories, sr as getIpfsKeyFromPrivateKey, t as RpcLocalCommunity, tr as getCommunityNameFromWire, u as deriveCommunityChallengesOrThrow, ur as getPublicKeyFromPrivateKey, v as TrackedInstanceRegistry, vn as signChallengeMessage, vr as deriveDbPosts, w as TIMEFRAMES_TO_SECONDS, wn as signCommentUpdate, wr as importSignerIntoKuboNode, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, xn as signComment, xr as getDefaultCommunityDbConfig, y as LRUCache, yr as deriveDbReplies, zn as verifyCommunity, zr as r$2 } from "./rpc-local-community-Br_xomgn.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-DY7SvqJA.js";
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
-
import
|
|
6
|
+
import Path from "node:path";
|
|
7
7
|
import os from "os";
|
|
8
8
|
import fs, { existsSync, promises } from "node:fs";
|
|
9
|
-
import path
|
|
9
|
+
import path from "path";
|
|
10
10
|
import assert from "assert";
|
|
11
11
|
import { Buffer as Buffer$1 } from "buffer";
|
|
12
12
|
import fs$1 from "fs";
|
|
@@ -315,15 +315,15 @@ async function throwIfChallengeSettingsAreInvalid({ challengeSettings, pkc, comm
|
|
|
315
315
|
const processStartedCommunities = new TrackedInstanceRegistry();
|
|
316
316
|
function normalizeRegistryDataPath(dataPath) {
|
|
317
317
|
if (dataPath === void 0) return void 0;
|
|
318
|
-
const resolved = path
|
|
318
|
+
const resolved = path.resolve(dataPath);
|
|
319
319
|
let existing = resolved;
|
|
320
320
|
let tail = "";
|
|
321
321
|
while (true) try {
|
|
322
|
-
return path
|
|
322
|
+
return path.join(fs$1.realpathSync.native(existing), tail);
|
|
323
323
|
} catch {
|
|
324
|
-
const parent = path
|
|
324
|
+
const parent = path.dirname(existing);
|
|
325
325
|
if (parent === existing) return resolved;
|
|
326
|
-
tail = path
|
|
326
|
+
tail = path.join(path.basename(existing), tail);
|
|
327
327
|
existing = parent;
|
|
328
328
|
}
|
|
329
329
|
}
|
|
@@ -1337,7 +1337,8 @@ function createPositionalCommentRowMapper(cols) {
|
|
|
1337
1337
|
var import_src = /* @__PURE__ */ __toESM(require_src(), 1);
|
|
1338
1338
|
const createCommunityAuthorMemo = () => ({
|
|
1339
1339
|
writeGeneration: -1,
|
|
1340
|
-
authors: /* @__PURE__ */ new Map()
|
|
1340
|
+
authors: /* @__PURE__ */ new Map(),
|
|
1341
|
+
expandedAddresses: /* @__PURE__ */ new Map()
|
|
1341
1342
|
});
|
|
1342
1343
|
const COMMENTS_TO_UPDATE_TEMP_TABLE = "temp.commentsToUpdate";
|
|
1343
1344
|
const TABLES = Object.freeze({
|
|
@@ -1722,9 +1723,9 @@ var DbHandler = class {
|
|
|
1722
1723
|
if (needToMigrate) {
|
|
1723
1724
|
if (dbExistsAlready && currentDbVersion > 0) {
|
|
1724
1725
|
this.destoryConnection();
|
|
1725
|
-
backupDbPath = path
|
|
1726
|
-
log(`Copying db ${path
|
|
1727
|
-
if (!fs$1.existsSync(path
|
|
1726
|
+
backupDbPath = path.join(path.dirname(dbPath), ".backup_before_migration", `${path.basename(dbPath)}.${currentDbVersion}.${timestamp()}`);
|
|
1727
|
+
log(`Copying db ${path.basename(dbPath)} to ${backupDbPath} before migration`);
|
|
1728
|
+
if (!fs$1.existsSync(path.dirname(backupDbPath))) await fs$1.promises.mkdir(path.dirname(backupDbPath), { recursive: true });
|
|
1728
1729
|
const sourceDb = new Database(dbPath, { fileMustExist: true });
|
|
1729
1730
|
await sourceDb.backup(backupDbPath);
|
|
1730
1731
|
sourceDb.close();
|
|
@@ -2976,7 +2977,7 @@ var DbHandler = class {
|
|
|
2976
2977
|
queryPostsWithOutdatedBuckets(buckets) {
|
|
2977
2978
|
const currentTimestampSeconds = timestamp();
|
|
2978
2979
|
const maxBucket = Math.max(...buckets);
|
|
2979
|
-
const caseClauses = buckets.sort((a, b) => a - b).map((bucket) => `WHEN (
|
|
2980
|
+
const caseClauses = buckets.sort((a, b) => a - b).map((bucket) => `WHEN (? - c.timestamp) <= ${bucket} THEN ${bucket}`).join(" ");
|
|
2980
2981
|
const { clause: addrClause, params: addrParams } = this._communityIdentityClause("c");
|
|
2981
2982
|
const query = `
|
|
2982
2983
|
WITH post_data AS (
|
|
@@ -2989,7 +2990,7 @@ var DbHandler = class {
|
|
|
2989
2990
|
) SELECT cid, timestamp, current_bucket AS currentBucket, new_bucket AS newBucket
|
|
2990
2991
|
FROM post_data WHERE current_bucket != new_bucket
|
|
2991
2992
|
`;
|
|
2992
|
-
return this._prepareCached(query).all(...addrParams, maxBucket);
|
|
2993
|
+
return this._prepareCached(query).all(...buckets.map(() => currentTimestampSeconds), ...addrParams, maxBucket);
|
|
2993
2994
|
}
|
|
2994
2995
|
queryLatestAuthorEdit(cid, authorSignerAddress) {
|
|
2995
2996
|
const row = this._db.prepare(`
|
|
@@ -3402,11 +3403,19 @@ var DbHandler = class {
|
|
|
3402
3403
|
_queryCommunityAuthorsForCommentUpdates(entries, memo) {
|
|
3403
3404
|
if (memo.writeGeneration !== this._publicationWriteGeneration) {
|
|
3404
3405
|
memo.authors.clear();
|
|
3406
|
+
memo.expandedAddresses.clear();
|
|
3405
3407
|
memo.writeGeneration = this._publicationWriteGeneration;
|
|
3406
3408
|
}
|
|
3407
3409
|
const aliasByCid = this._queryPseudonymityAliasesByCommentCids(entries.map((entry) => entry.comment.cid));
|
|
3408
3410
|
const plainAddresses = [...new Set(entries.filter((entry) => !aliasByCid.has(entry.comment.cid)).map((entry) => entry.comment.authorSignerAddress))];
|
|
3409
|
-
const
|
|
3411
|
+
const addressesToExpand = plainAddresses.filter((address) => !memo.expandedAddresses.has(address));
|
|
3412
|
+
if (addressesToExpand.length > 0) for (const [address, addressSet] of this._queryAliasExpandedAddressSets(addressesToExpand)) memo.expandedAddresses.set(address, addressSet);
|
|
3413
|
+
const expanded = /* @__PURE__ */ new Map();
|
|
3414
|
+
for (const address of plainAddresses) {
|
|
3415
|
+
const addressSet = memo.expandedAddresses.get(address);
|
|
3416
|
+
if (!addressSet) throw Error(`Alias expansion of author ${address} missing from the cycle's memo`);
|
|
3417
|
+
expanded.set(address, addressSet);
|
|
3418
|
+
}
|
|
3410
3419
|
const keyOf = (karma, modEdit, domain) => `${[...karma].sort().join(",")}|${[...modEdit].sort().join(",")}|${domain ?? ""}`;
|
|
3411
3420
|
const needByCid = /* @__PURE__ */ new Map();
|
|
3412
3421
|
for (const { comment, authorDomain } of entries) {
|
|
@@ -3775,10 +3784,10 @@ var DbHandler = class {
|
|
|
3775
3784
|
if (this._db || this._keyv) await this.destoryConnection();
|
|
3776
3785
|
this._transactionDepth = 0;
|
|
3777
3786
|
const dataPath = this._community._pkc.dataPath;
|
|
3778
|
-
const oldPathString = path
|
|
3779
|
-
const newPathString = path
|
|
3780
|
-
await fs$1.promises.mkdir(path
|
|
3781
|
-
await fs$1.promises.mkdir(path
|
|
3787
|
+
const oldPathString = path.join(dataPath, "communities", oldDbName);
|
|
3788
|
+
const newPathString = path.join(dataPath, "communities", newDbName);
|
|
3789
|
+
await fs$1.promises.mkdir(path.dirname(oldPathString), { recursive: true });
|
|
3790
|
+
await fs$1.promises.mkdir(path.dirname(newPathString), { recursive: true });
|
|
3782
3791
|
try {
|
|
3783
3792
|
if (!fs$1.existsSync(oldPathString)) log(`Old DB file ${oldPathString} does not exist. Cannot backup/rename.`);
|
|
3784
3793
|
else {
|
|
@@ -3800,8 +3809,8 @@ var DbHandler = class {
|
|
|
3800
3809
|
}
|
|
3801
3810
|
async lockCommunityStart(communityAddress = this._community.address) {
|
|
3802
3811
|
const log = logger_default("pkc-js:local-community:db-handler:lock:start");
|
|
3803
|
-
const lockfilePath = path
|
|
3804
|
-
const communityDbPath = path
|
|
3812
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
3813
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
3805
3814
|
try {
|
|
3806
3815
|
await import_src.default.lock(communityDbPath, {
|
|
3807
3816
|
lockfilePath,
|
|
@@ -3822,8 +3831,8 @@ var DbHandler = class {
|
|
|
3822
3831
|
async unlockCommunityStart(communityAddress = this._community.address) {
|
|
3823
3832
|
const log = logger_default("pkc-js:local-community:db-handler:unlock:start");
|
|
3824
3833
|
log.trace(`Attempting to unlock the start of community (${communityAddress})`);
|
|
3825
|
-
const lockfilePath = path
|
|
3826
|
-
const communityDbPath = path
|
|
3834
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
3835
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
3827
3836
|
if (!fs$1.existsSync(lockfilePath) || !fs$1.existsSync(communityDbPath)) return;
|
|
3828
3837
|
try {
|
|
3829
3838
|
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
@@ -3841,8 +3850,8 @@ var DbHandler = class {
|
|
|
3841
3850
|
}
|
|
3842
3851
|
async lockCommunityState() {
|
|
3843
3852
|
const log = logger_default("pkc-js:local-community:db-handler:lock:lockCommunityState");
|
|
3844
|
-
const lockfilePath = path
|
|
3845
|
-
const communityDbPath = path
|
|
3853
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
3854
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
3846
3855
|
try {
|
|
3847
3856
|
await import_src.default.lock(communityDbPath, {
|
|
3848
3857
|
lockfilePath,
|
|
@@ -3859,8 +3868,8 @@ var DbHandler = class {
|
|
|
3859
3868
|
}
|
|
3860
3869
|
async unlockCommunityState() {
|
|
3861
3870
|
const log = logger_default("pkc-js:local-community:db-handler:lock:unlockCommunityState");
|
|
3862
|
-
const lockfilePath = path
|
|
3863
|
-
const communityDbPath = path
|
|
3871
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
3872
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
3864
3873
|
if (!fs$1.existsSync(lockfilePath)) return;
|
|
3865
3874
|
try {
|
|
3866
3875
|
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
@@ -3870,7 +3879,7 @@ var DbHandler = class {
|
|
|
3870
3879
|
}
|
|
3871
3880
|
}
|
|
3872
3881
|
communityDbExists() {
|
|
3873
|
-
const communityDbPath = path
|
|
3882
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
3874
3883
|
return fs$1.existsSync(communityDbPath);
|
|
3875
3884
|
}
|
|
3876
3885
|
markCommentsAsPublishedToPostUpdates(commentCids) {
|
|
@@ -4041,7 +4050,200 @@ var DbHandler = class {
|
|
|
4041
4050
|
}
|
|
4042
4051
|
};
|
|
4043
4052
|
//#endregion
|
|
4053
|
+
//#region dist/node/runtime/node/community/local-community/post-updates-bucket.js
|
|
4054
|
+
const MFS_OP_TIMEOUT_MS = 600 * 1e3;
|
|
4055
|
+
const MFS_SHARD_SPLIT_THRESHOLD_BYTES = 256 * 1024;
|
|
4056
|
+
const POST_UPDATES_BUCKET_NEXT_SUFFIX = ".next";
|
|
4057
|
+
const isAbsentPathError = (error) => error instanceof Error && error.message.includes("file does not exist");
|
|
4058
|
+
async function statMfsPathOrUndefined(kuboRpcClient, path, log) {
|
|
4059
|
+
try {
|
|
4060
|
+
return await statMfsPathSafely({
|
|
4061
|
+
kuboRpcClient,
|
|
4062
|
+
path,
|
|
4063
|
+
log
|
|
4064
|
+
});
|
|
4065
|
+
} catch (error) {
|
|
4066
|
+
if (isAbsentPathError(error)) return void 0;
|
|
4067
|
+
throw error;
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
async function listUnixFsDirectoryLinks(kubo, directoryCid) {
|
|
4071
|
+
const { UnixFS } = await import("./src-BC60-Q7v.js");
|
|
4072
|
+
const links = [];
|
|
4073
|
+
const walk = async (cid) => {
|
|
4074
|
+
const node = (await kubo.dag.get(cid, { timeout: MFS_OP_TIMEOUT_MS })).value;
|
|
4075
|
+
if (!isPbNode(node)) throw Error(`Expected a dag-pb directory node at ${cid.toString()}`);
|
|
4076
|
+
const unixfs = UnixFS.unmarshal(node.Data);
|
|
4077
|
+
if (unixfs.type === "hamt-sharded-directory") {
|
|
4078
|
+
const prefixLength = Math.max(1, Math.ceil(Math.log2(Number(unixfs.fanout ?? 256)) / 4));
|
|
4079
|
+
for (const link of node.Links) if (link.Name.length === prefixLength) await walk(link.Hash);
|
|
4080
|
+
else links.push({
|
|
4081
|
+
name: link.Name.slice(prefixLength),
|
|
4082
|
+
cid: link.Hash,
|
|
4083
|
+
size: BigInt(link.Tsize ?? 0)
|
|
4084
|
+
});
|
|
4085
|
+
} else if (unixfs.type === "directory") for (const link of node.Links) links.push({
|
|
4086
|
+
name: link.Name,
|
|
4087
|
+
cid: link.Hash,
|
|
4088
|
+
size: BigInt(link.Tsize ?? 0)
|
|
4089
|
+
});
|
|
4090
|
+
else throw Error(`Expected a UnixFS directory at ${cid.toString()}, got ${unixfs.type}`);
|
|
4091
|
+
};
|
|
4092
|
+
await walk(directoryCid);
|
|
4093
|
+
return links;
|
|
4094
|
+
}
|
|
4095
|
+
function isPbNode(value) {
|
|
4096
|
+
if (typeof value !== "object" || value === null) return false;
|
|
4097
|
+
const node = value;
|
|
4098
|
+
return node.Data instanceof Uint8Array && Array.isArray(node.Links) && node.Links.every((link) => typeof link?.Name === "string" && (link.Tsize === void 0 || typeof link.Tsize === "number") && link.Hash instanceof CID);
|
|
4099
|
+
}
|
|
4100
|
+
async function buildPostUpdatesBucketDag({ existingLinks, changedPosts }) {
|
|
4101
|
+
const { importer } = await import("./src-Bj5iE3qB.js");
|
|
4102
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
4103
|
+
const blockstore = { put: async (cid, bytes) => {
|
|
4104
|
+
blocks.set(cid.toString(), {
|
|
4105
|
+
cid,
|
|
4106
|
+
bytes
|
|
4107
|
+
});
|
|
4108
|
+
return cid;
|
|
4109
|
+
} };
|
|
4110
|
+
const layoutOptions = {
|
|
4111
|
+
profile: "unixfs-v0-2015",
|
|
4112
|
+
cidVersion: 0,
|
|
4113
|
+
rawLeaves: false,
|
|
4114
|
+
reduceSingleLeafToSelf: true,
|
|
4115
|
+
shardSplitThresholdBytes: MFS_SHARD_SPLIT_THRESHOLD_BYTES
|
|
4116
|
+
};
|
|
4117
|
+
const postDirectoryLinks = /* @__PURE__ */ new Map();
|
|
4118
|
+
for await (const entry of importer(changedPosts.map((post) => ({
|
|
4119
|
+
path: `${post.postCid}/update`,
|
|
4120
|
+
content: post.updateFileBytes
|
|
4121
|
+
})), blockstore, {
|
|
4122
|
+
...layoutOptions,
|
|
4123
|
+
wrapWithDirectory: false
|
|
4124
|
+
})) if (entry.path && !entry.path.includes("/")) postDirectoryLinks.set(entry.path, {
|
|
4125
|
+
name: entry.path,
|
|
4126
|
+
cid: entry.cid,
|
|
4127
|
+
size: entry.size
|
|
4128
|
+
});
|
|
4129
|
+
if (postDirectoryLinks.size !== changedPosts.length) throw Error(`Built ${postDirectoryLinks.size} post directories for ${changedPosts.length} changed posts`);
|
|
4130
|
+
const bucketName = "bucket";
|
|
4131
|
+
const knownLinks = /* @__PURE__ */ new Map();
|
|
4132
|
+
for (const link of existingLinks) knownLinks.set(`${bucketName}/${link.name}`, link);
|
|
4133
|
+
for (const link of postDirectoryLinks.values()) knownLinks.set(`${bucketName}/${link.name}`, link);
|
|
4134
|
+
let root;
|
|
4135
|
+
for await (const entry of importer([...knownLinks.keys()].map((path) => ({
|
|
4136
|
+
path,
|
|
4137
|
+
content: new Uint8Array(0)
|
|
4138
|
+
})), blockstore, {
|
|
4139
|
+
...layoutOptions,
|
|
4140
|
+
wrapWithDirectory: false,
|
|
4141
|
+
fileBuilder: async (file) => {
|
|
4142
|
+
for await (const chunk of file.content);
|
|
4143
|
+
const link = file.path ? knownLinks.get(file.path) : void 0;
|
|
4144
|
+
if (!link) throw Error(`No known link for bucket entry ${file.path}`);
|
|
4145
|
+
return {
|
|
4146
|
+
cid: link.cid,
|
|
4147
|
+
size: link.size,
|
|
4148
|
+
path: file.path
|
|
4149
|
+
};
|
|
4150
|
+
}
|
|
4151
|
+
})) if (entry.path === bucketName) root = entry.cid;
|
|
4152
|
+
if (!root) throw Error("The rebuilt postUpdates bucket has no root");
|
|
4153
|
+
return {
|
|
4154
|
+
root,
|
|
4155
|
+
blocks: [...blocks.values()]
|
|
4156
|
+
};
|
|
4157
|
+
}
|
|
4158
|
+
async function encodeCarV1(root, blocks) {
|
|
4159
|
+
const dagCbor = await import("./src-BHqirG63.js");
|
|
4160
|
+
const varint = (value) => {
|
|
4161
|
+
const out = [];
|
|
4162
|
+
while (value >= 128) {
|
|
4163
|
+
out.push(value & 127 | 128);
|
|
4164
|
+
value = Math.floor(value / 128);
|
|
4165
|
+
}
|
|
4166
|
+
out.push(value);
|
|
4167
|
+
return Uint8Array.from(out);
|
|
4168
|
+
};
|
|
4169
|
+
const header = dagCbor.encode({
|
|
4170
|
+
roots: [root],
|
|
4171
|
+
version: 1
|
|
4172
|
+
});
|
|
4173
|
+
const parts = [varint(header.length), header];
|
|
4174
|
+
for (const { cid, bytes } of blocks) parts.push(varint(cid.bytes.length + bytes.length), cid.bytes, bytes);
|
|
4175
|
+
const car = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
4176
|
+
let offset = 0;
|
|
4177
|
+
for (const part of parts) {
|
|
4178
|
+
car.set(part, offset);
|
|
4179
|
+
offset += part.length;
|
|
4180
|
+
}
|
|
4181
|
+
return car;
|
|
4182
|
+
}
|
|
4183
|
+
async function recoverInterruptedBucketSwap(kuboRpcClient, bucketPath, log) {
|
|
4184
|
+
const kubo = kuboRpcClient._client;
|
|
4185
|
+
const nextPath = bucketPath + POST_UPDATES_BUCKET_NEXT_SUFFIX;
|
|
4186
|
+
const next = await statMfsPathOrUndefined(kuboRpcClient, nextPath, log);
|
|
4187
|
+
let live = await statMfsPathOrUndefined(kuboRpcClient, bucketPath, log);
|
|
4188
|
+
if (next) {
|
|
4189
|
+
if (live) {
|
|
4190
|
+
log(`Discarding the stale rebuilt bucket ${nextPath} left by an interrupted swap`);
|
|
4191
|
+
await kubo.files.rm(nextPath, {
|
|
4192
|
+
recursive: true,
|
|
4193
|
+
timeout: MFS_OP_TIMEOUT_MS
|
|
4194
|
+
});
|
|
4195
|
+
} else {
|
|
4196
|
+
log(`Finishing the interrupted swap of ${nextPath} into ${bucketPath}`);
|
|
4197
|
+
await kubo.files.mv(nextPath, bucketPath, {
|
|
4198
|
+
flush: true,
|
|
4199
|
+
timeout: MFS_OP_TIMEOUT_MS
|
|
4200
|
+
});
|
|
4201
|
+
live = next;
|
|
4202
|
+
}
|
|
4203
|
+
await kubo.pin.rm(next.cid, { timeout: MFS_OP_TIMEOUT_MS }).catch(() => void 0);
|
|
4204
|
+
}
|
|
4205
|
+
return live;
|
|
4206
|
+
}
|
|
4207
|
+
async function rebuildPostUpdatesBucket({ community, bucketPath, posts }) {
|
|
4208
|
+
const log = logger_default("pkc-js:local-community:sync:rebuildPostUpdatesBucket");
|
|
4209
|
+
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
4210
|
+
const kubo = kuboRpcClient._client;
|
|
4211
|
+
const nextPath = bucketPath + POST_UPDATES_BUCKET_NEXT_SUFFIX;
|
|
4212
|
+
const live = await recoverInterruptedBucketSwap(kuboRpcClient, bucketPath, log);
|
|
4213
|
+
const changedPostCids = new Set(posts.map((post) => post.postCid));
|
|
4214
|
+
const existingLinks = live ? (await listUnixFsDirectoryLinks(kubo, live.cid)).filter((link) => !changedPostCids.has(link.name) && community._dbHandler.commentExistsInDb(link.name)) : [];
|
|
4215
|
+
const { root, blocks } = await buildPostUpdatesBucketDag({
|
|
4216
|
+
existingLinks,
|
|
4217
|
+
changedPosts: posts
|
|
4218
|
+
});
|
|
4219
|
+
const car = await encodeCarV1(root, blocks);
|
|
4220
|
+
for await (const result of kubo.dag.import([car], {
|
|
4221
|
+
pinRoots: true,
|
|
4222
|
+
timeout: MFS_OP_TIMEOUT_MS
|
|
4223
|
+
})) if (result.root.pinErrorMsg) throw Error(`Failed to pin the rebuilt bucket ${root.toString()}: ${result.root.pinErrorMsg}`);
|
|
4224
|
+
log(`Built bucket ${bucketPath} in node: ${posts.length} posts written, ${existingLinks.length} kept, ${blocks.length} new blocks (${car.length} bytes), root ${root.toString()}`);
|
|
4225
|
+
try {
|
|
4226
|
+
await kubo.files.cp(`/ipfs/${root.toString()}`, nextPath, {
|
|
4227
|
+
parents: true,
|
|
4228
|
+
flush: true,
|
|
4229
|
+
timeout: MFS_OP_TIMEOUT_MS
|
|
4230
|
+
});
|
|
4231
|
+
if (live) await kubo.files.rm(bucketPath, {
|
|
4232
|
+
recursive: true,
|
|
4233
|
+
timeout: MFS_OP_TIMEOUT_MS
|
|
4234
|
+
});
|
|
4235
|
+
await kubo.files.mv(nextPath, bucketPath, {
|
|
4236
|
+
flush: true,
|
|
4237
|
+
timeout: MFS_OP_TIMEOUT_MS
|
|
4238
|
+
});
|
|
4239
|
+
} finally {
|
|
4240
|
+
await kubo.pin.rm(root, { timeout: MFS_OP_TIMEOUT_MS }).catch((error) => log.error(`Failed to unpin the rebuilt bucket root ${root.toString()}`, error));
|
|
4241
|
+
}
|
|
4242
|
+
return { keptPostCids: existingLinks.map((link) => link.name) };
|
|
4243
|
+
}
|
|
4244
|
+
//#endregion
|
|
4044
4245
|
//#region dist/node/runtime/node/community/local-community/comment-updates.js
|
|
4246
|
+
const textEncoder = new TextEncoder();
|
|
4045
4247
|
const NO_POST_UPDATES_TO_PUBLISH_ERROR = "No comment updates of posts to publish to postUpdates directory. This is a critical bug";
|
|
4046
4248
|
function communityChallengePubsubTopic(community) {
|
|
4047
4249
|
return community.pubsubTopic || community.signer?.address;
|
|
@@ -4050,11 +4252,16 @@ function challengeExchangePubsubTopic(community) {
|
|
|
4050
4252
|
if (community.settings?.disablePubsubChallengeExchange) return void 0;
|
|
4051
4253
|
return communityChallengePubsubTopic(community);
|
|
4052
4254
|
}
|
|
4053
|
-
function
|
|
4255
|
+
function calculateLocalMfsPathForPostUpdatesBucket(community, timestampRange) {
|
|
4054
4256
|
return [
|
|
4055
4257
|
"/" + community.address,
|
|
4056
4258
|
"postUpdates",
|
|
4057
|
-
timestampRange
|
|
4259
|
+
timestampRange
|
|
4260
|
+
].join("/");
|
|
4261
|
+
}
|
|
4262
|
+
function calculateLocalMfsPathForCommentUpdate(community, postDbComment, timestampRange) {
|
|
4263
|
+
return [
|
|
4264
|
+
calculateLocalMfsPathForPostUpdatesBucket(community, timestampRange),
|
|
4058
4265
|
postDbComment.cid,
|
|
4059
4266
|
"update"
|
|
4060
4267
|
].join("/");
|
|
@@ -4191,11 +4398,40 @@ async function writePostUpdatesToMfs(community, postCommentUpdateRows) {
|
|
|
4191
4398
|
const purgedMidSyncCount = postCommentUpdateRows.length - liveCommentUpdates.length;
|
|
4192
4399
|
if (purgedMidSyncCount > 0) log(`Skipping ${purgedMidSyncCount} post CommentUpdate(s) for community ${community.address} whose comment was purged mid-sync`);
|
|
4193
4400
|
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
4194
|
-
|
|
4401
|
+
await rmUnneededMfsPaths(community);
|
|
4195
4402
|
let postUpdatesDirectoryCid;
|
|
4403
|
+
const rowsByBucketPath = /* @__PURE__ */ new Map();
|
|
4404
|
+
for (const row of liveCommentUpdates) {
|
|
4405
|
+
const bucket = row.newCommentUpdateToWriteToDb.postUpdatesBucket;
|
|
4406
|
+
if (typeof bucket !== "number") throw Error(`Post ${row.newCommentUpdate.cid} has a postUpdates MFS path but no bucket`);
|
|
4407
|
+
const bucketPath = calculateLocalMfsPathForPostUpdatesBucket(community, bucket);
|
|
4408
|
+
const bucketRows = rowsByBucketPath.get(bucketPath);
|
|
4409
|
+
if (bucketRows) bucketRows.push(row);
|
|
4410
|
+
else rowsByBucketPath.set(bucketPath, [row]);
|
|
4411
|
+
}
|
|
4412
|
+
const rowsToWriteOneByOne = [];
|
|
4413
|
+
const keptPostsByRebuiltBucket = [];
|
|
4414
|
+
for (const [bucketPath, rows] of rowsByBucketPath) {
|
|
4415
|
+
if (rows.length < community._postUpdatesNodeBuiltBucketMinPosts) {
|
|
4416
|
+
rowsToWriteOneByOne.push(...rows);
|
|
4417
|
+
continue;
|
|
4418
|
+
}
|
|
4419
|
+
const { keptPostCids } = await rebuildPostUpdatesBucket({
|
|
4420
|
+
community,
|
|
4421
|
+
bucketPath,
|
|
4422
|
+
posts: rows.map((row) => ({
|
|
4423
|
+
postCid: row.newCommentUpdate.cid,
|
|
4424
|
+
updateFileBytes: textEncoder.encode(stringify(row.newCommentUpdate))
|
|
4425
|
+
}))
|
|
4426
|
+
});
|
|
4427
|
+
keptPostsByRebuiltBucket.push({
|
|
4428
|
+
bucketPath,
|
|
4429
|
+
keptPostCids
|
|
4430
|
+
});
|
|
4431
|
+
}
|
|
4196
4432
|
const BATCH_SIZE = 50;
|
|
4197
|
-
for (let index = 0; index <
|
|
4198
|
-
const batch =
|
|
4433
|
+
for (let index = 0; index < rowsToWriteOneByOne.length; index += BATCH_SIZE) {
|
|
4434
|
+
const batch = rowsToWriteOneByOne.slice(index, index + BATCH_SIZE);
|
|
4199
4435
|
await Promise.all(batch.map(async (row) => {
|
|
4200
4436
|
const { localMfsPath, newCommentUpdate } = row;
|
|
4201
4437
|
const content = stringify(newCommentUpdate);
|
|
@@ -4208,17 +4444,17 @@ async function writePostUpdatesToMfs(community, postCommentUpdateRows) {
|
|
|
4208
4444
|
create: true,
|
|
4209
4445
|
truncate: true,
|
|
4210
4446
|
parents: true,
|
|
4211
|
-
flush:
|
|
4447
|
+
flush: false
|
|
4212
4448
|
}
|
|
4213
4449
|
});
|
|
4214
|
-
removedMfsPaths.push(localMfsPath);
|
|
4215
4450
|
}));
|
|
4216
4451
|
postUpdatesDirectoryCid = await kuboRpc._client.files.flush(postUpdatesDirectory);
|
|
4217
4452
|
}
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4453
|
+
if (rowsToWriteOneByOne.length === 0 && keptPostsByRebuiltBucket.length > 0) postUpdatesDirectoryCid = await kuboRpc._client.files.flush(postUpdatesDirectory);
|
|
4454
|
+
const mfsPathsPurgedDuringWrites = [...liveCommentUpdates.filter((row) => !community._dbHandler.commentExistsInDb(row.newCommentUpdate.cid)).map((row) => row.localMfsPath), ...keptPostsByRebuiltBucket.flatMap(({ bucketPath, keptPostCids }) => keptPostCids.filter((postCid) => !community._dbHandler.commentExistsInDb(postCid)).map((postCid) => `${bucketPath}/${postCid}`))];
|
|
4455
|
+
if (mfsPathsPurgedDuringWrites.length > 0) {
|
|
4456
|
+
log(`${mfsPathsPurgedDuringWrites.length} post CommentUpdate(s) of community ${community.address} were purged during the MFS writes. Removing their MFS entries`);
|
|
4457
|
+
for (const mfsPath of mfsPathsPurgedDuringWrites) community._mfsPathsToRemove.add(mfsPath);
|
|
4222
4458
|
await rmUnneededMfsPaths(community);
|
|
4223
4459
|
postUpdatesDirectoryCid = await kuboRpc._client.files.flush(postUpdatesDirectory);
|
|
4224
4460
|
}
|
|
@@ -6883,10 +7119,10 @@ async function restoreCommunityAfterFailedRename({ community, oldAddress, newAdd
|
|
|
6883
7119
|
}
|
|
6884
7120
|
}
|
|
6885
7121
|
async function removePartialDbCopy({ community, oldAddress, newAddress, log }) {
|
|
6886
|
-
const communitiesPath =
|
|
6887
|
-
if (!fs.existsSync(
|
|
7122
|
+
const communitiesPath = Path.join(community._pkc.dataPath, "communities");
|
|
7123
|
+
if (!fs.existsSync(Path.join(communitiesPath, oldAddress))) return;
|
|
6888
7124
|
try {
|
|
6889
|
-
await fs.promises.rm(
|
|
7125
|
+
await fs.promises.rm(Path.join(communitiesPath, newAddress), { force: true });
|
|
6890
7126
|
} catch (e) {
|
|
6891
7127
|
log.error(`Failed to remove the partial DB copy of community (${oldAddress}) at ${newAddress}`, e);
|
|
6892
7128
|
}
|
|
@@ -7030,11 +7266,11 @@ async function edit(community, newCommunityOptions) {
|
|
|
7030
7266
|
const EXPORTS_KEY = STORAGE_KEYS[STORAGE_KEYS.EXPORTS];
|
|
7031
7267
|
function defaultExportPathFor(community, exportId) {
|
|
7032
7268
|
if (typeof community._pkc.dataPath !== "string") throw new PKCError("ERR_DATA_PATH_IS_NOT_DEFINED", { communityAddress: community.address });
|
|
7033
|
-
return
|
|
7269
|
+
return Path.join(community._pkc.dataPath, "exports", `${exportId}.sqlite`);
|
|
7034
7270
|
}
|
|
7035
7271
|
function sourceDbPathFor(community) {
|
|
7036
7272
|
if (typeof community._pkc.dataPath !== "string") throw new PKCError("ERR_DATA_PATH_IS_NOT_DEFINED", { communityAddress: community.address });
|
|
7037
|
-
return
|
|
7273
|
+
return Path.join(community._pkc.dataPath, "communities", community.address);
|
|
7038
7274
|
}
|
|
7039
7275
|
async function persistExports(community) {
|
|
7040
7276
|
if (!community._dbHandler) return;
|
|
@@ -7110,9 +7346,9 @@ async function runExportTask(community, exportId, opts) {
|
|
|
7110
7346
|
async function exportCommunityEmbedded(community, options = {}) {
|
|
7111
7347
|
if (options.signal?.aborted) throw options.signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
7112
7348
|
const exportId = v4();
|
|
7113
|
-
const destPath = options.exportPath ?
|
|
7349
|
+
const destPath = options.exportPath ? Path.resolve(options.exportPath) : defaultExportPathFor(community, exportId);
|
|
7114
7350
|
const includePrivateKey = options.includePrivateKey === true;
|
|
7115
|
-
if (
|
|
7351
|
+
if (Path.resolve(destPath) === Path.resolve(sourceDbPathFor(community))) throw new PKCError("ERR_EXPORT_PATH_TARGETS_LIVE_DB", {
|
|
7116
7352
|
communityAddress: community.address,
|
|
7117
7353
|
exportPath: destPath
|
|
7118
7354
|
});
|
|
@@ -7234,6 +7470,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7234
7470
|
2592e3,
|
|
7235
7471
|
31536e5
|
|
7236
7472
|
];
|
|
7473
|
+
this._postUpdatesNodeBuiltBucketMinPosts = 200;
|
|
7237
7474
|
this._defaultCommunityChallenges = generateDefaultChallenges();
|
|
7238
7475
|
this._challengeExchangesFromLocalPublishers = {};
|
|
7239
7476
|
this._inFlightPublicationExchanges = /* @__PURE__ */ new Map();
|
|
@@ -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-BglT8AUy.js";
|
|
2
2
|
export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
|