@pkcprotocol/pkc-js 0.0.133 → 0.0.135
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +12 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js +138 -37
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/browser/errors.d.ts +2 -0
- package/dist/browser/errors.js +2 -0
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/schema.d.ts +4 -0
- package/dist/browser/publications/comment/schema.js +2 -1
- package/dist/browser/publications/comment/schema.js.map +1 -1
- package/dist/browser/runtime/node/community/db-handler.js +44 -91
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/browser/runtime/node/community/page-generator.d.ts +2 -0
- package/dist/browser/runtime/node/community/page-generator.js +3 -2
- package/dist/browser/runtime/node/community/page-generator.js.map +1 -1
- package/dist/browser/runtime/node/util.d.ts +1 -0
- package/dist/browser/runtime/node/util.js +3 -2
- package/dist/browser/runtime/node/util.js.map +1 -1
- package/dist/browser/signer/signatures.js +6 -1
- package/dist/browser/signer/signatures.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +46 -46
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-B6cVl9Fj.js → helia-for-pkc-DldRnBHX.js} +33 -33
- package/dist/bundled/chunks/{local-community-CEsw9IC3.js → local-community-9i6vs_-P.js} +1 -1
- package/dist/bundled/chunks/{local-community-JxRohlLp.js → local-community-BjljrKks.js} +83 -127
- package/dist/bundled/chunks/{node-DsWFSaNV.js → node-BNoBGxyk.js} +117 -38
- package/dist/bundled/chunks/{page-sort-scoring-iqMGLuRC.js → page-sort-scoring-BCqpbgnJ.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-jndojGZl.js → rpc-local-community-CuL4H_vR.js} +9 -6
- package/dist/bundled/chunks/{util-CYgZRMVL.js → util-D104b59J.js} +1 -1
- package/dist/bundled/chunks/{util-Bna9pur0.js → util-TZLcBbZd.js} +5 -2
- package/dist/bundled/chunks/{validate-package-factories-FeyM9Tw1.js → validate-package-factories-DGlKaHzi.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/rpc-client/pkc-rpc-client.d.ts +12 -0
- package/dist/node/clients/rpc-client/pkc-rpc-client.js +138 -37
- package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/node/errors.d.ts +2 -0
- package/dist/node/errors.js +2 -0
- package/dist/node/errors.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/schema.d.ts +4 -0
- package/dist/node/publications/comment/schema.js +2 -1
- package/dist/node/publications/comment/schema.js.map +1 -1
- package/dist/node/runtime/node/community/db-handler.js +44 -91
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.js +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/node/runtime/node/community/page-generator.d.ts +2 -0
- package/dist/node/runtime/node/community/page-generator.js +3 -2
- package/dist/node/runtime/node/community/page-generator.js.map +1 -1
- package/dist/node/runtime/node/util.d.ts +1 -0
- package/dist/node/runtime/node/util.js +3 -2
- package/dist/node/runtime/node/util.js.map +1 -1
- package/dist/node/signer/signatures.js +6 -1
- package/dist/node/signer/signatures.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { i as __toESM } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $ as retryKuboIpfsAddAndProvide, $n as CommentEditsTableRowSchema, At as ChallengeAnswerMessageSchema, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Ct as trackUpdatingCommunity, Dt as require_sha256, En as VotePubsubReservedFields, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeMfsFilesSafely, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, Jt as version_default, Lr as PKCError, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, On as VoteTablesRowSchema, Or as t$4, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Rr as messages, Sr as e, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Tr as t$3, Vn as CommentUpdateTableRowSchema, W as removeBlocksFromKuboNode, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Z as retryKuboBlockPutPinAndProvidePubsubTopic, Zn as CommentEditReservedFields, _ as genToArray, _r as t$7, at as timestamp, b as getIpnsRecordInLocalKuboNode, br as t$6, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeysDeep, dt as findStartedCommunity, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as n$3, hr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as require_retry, kr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as writeKuboFilesWithTimeout, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, nt as sleepUntilTimeoutOrAbort, o as calculateUnixFsDagSizeCidV0, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, q as removeNullUndefinedValues, r as calculateIpfsCidV0, rt as statMfsPathSafely, s as contentContainsMarkdownAudio, st as withSortedKeys, ti as ZodError, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$2, wr as r$1, wt as untrackStartedCommunity, xr as e$1, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$5, z as pubsubTopicToDhtKey, zn as CommentUpdateSchema, zr as logger_default, zt as DecryptedChallengeRequestPublicationSchema } from "./util-
|
|
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 { $ as retryKuboIpfsAddAndProvide, $n as CommentEditsTableRowSchema, At as ChallengeAnswerMessageSchema, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Ct as trackUpdatingCommunity, Dt as require_sha256, En as VotePubsubReservedFields, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeMfsFilesSafely, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, Jt as version_default, Lr as PKCError, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, On as VoteTablesRowSchema, Or as t$4, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Rr as messages, Sr as e, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Tr as t$3, Vn as CommentUpdateTableRowSchema, W as removeBlocksFromKuboNode, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Z as retryKuboBlockPutPinAndProvidePubsubTopic, Zn as CommentEditReservedFields, _ as genToArray, _r as t$7, at as timestamp, b as getIpnsRecordInLocalKuboNode, br as t$6, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeysDeep, dt as findStartedCommunity, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as n$3, hr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as require_retry, kr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as writeKuboFilesWithTimeout, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, nt as sleepUntilTimeoutOrAbort, o as calculateUnixFsDagSizeCidV0, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, q as removeNullUndefinedValues, r as calculateIpfsCidV0, rt as statMfsPathSafely, s as contentContainsMarkdownAudio, st as withSortedKeys, ti as ZodError, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$2, wr as r$1, wt as untrackStartedCommunity, xr as e$1, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$5, z as pubsubTopicToDhtKey, zn as CommentUpdateSchema, zr as logger_default, zt as DecryptedChallengeRequestPublicationSchema } from "./util-TZLcBbZd.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-CuL4H_vR.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-BCqpbgnJ.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
|
}
|
|
@@ -772,6 +772,7 @@ var PageGenerator = class {
|
|
|
772
772
|
});
|
|
773
773
|
return;
|
|
774
774
|
}
|
|
775
|
+
const flatSortNames = sorts.filter((sort) => sort.flat).map((sort) => sort.sortName);
|
|
775
776
|
const everyPreloadedIsSingleChunk = preloaded.length > 0 && preloaded.every(({ chunks }) => chunks.length === 1);
|
|
776
777
|
const skippingOtherSortsIsSound = nonPreloaded.length === 0 || preloaded.every(({ holdsWholeSet }) => holdsWholeSet);
|
|
777
778
|
if (everyPreloadedIsSingleChunk && skippingOtherSortsIsSound) {
|
|
@@ -779,7 +780,8 @@ var PageGenerator = class {
|
|
|
779
780
|
for (const { sort, chunks } of preloaded) singlePreloadedPage[sort.sortName] = { comments: source.resolve(chunks[0]) };
|
|
780
781
|
return {
|
|
781
782
|
singlePreloadedPage,
|
|
782
|
-
failedSorts
|
|
783
|
+
failedSorts,
|
|
784
|
+
flatSortNames
|
|
783
785
|
};
|
|
784
786
|
}
|
|
785
787
|
const budget = new PageBytesBudget(serializedEntryCacheBudgetBytes());
|
|
@@ -802,7 +804,8 @@ var PageGenerator = class {
|
|
|
802
804
|
if (!generatedPages) return void 0;
|
|
803
805
|
return {
|
|
804
806
|
...generatedPages,
|
|
805
|
-
failedSorts
|
|
807
|
+
failedSorts,
|
|
808
|
+
flatSortNames
|
|
806
809
|
};
|
|
807
810
|
}
|
|
808
811
|
_generationResToPages(res) {
|
|
@@ -1704,9 +1707,9 @@ var DbHandler = class {
|
|
|
1704
1707
|
if (needToMigrate) {
|
|
1705
1708
|
if (dbExistsAlready && currentDbVersion > 0) {
|
|
1706
1709
|
this.destoryConnection();
|
|
1707
|
-
backupDbPath = path
|
|
1708
|
-
log(`Copying db ${path
|
|
1709
|
-
if (!fs$1.existsSync(path
|
|
1710
|
+
backupDbPath = path.join(path.dirname(dbPath), ".backup_before_migration", `${path.basename(dbPath)}.${currentDbVersion}.${timestamp()}`);
|
|
1711
|
+
log(`Copying db ${path.basename(dbPath)} to ${backupDbPath} before migration`);
|
|
1712
|
+
if (!fs$1.existsSync(path.dirname(backupDbPath))) await fs$1.promises.mkdir(path.dirname(backupDbPath), { recursive: true });
|
|
1710
1713
|
const sourceDb = new Database(dbPath, { fileMustExist: true });
|
|
1711
1714
|
await sourceDb.backup(backupDbPath);
|
|
1712
1715
|
sourceDb.close();
|
|
@@ -2307,66 +2310,56 @@ var DbHandler = class {
|
|
|
2307
2310
|
`;
|
|
2308
2311
|
return this._prepareCached(queryStr).raw(true).all(...params).map(mapper.map);
|
|
2309
2312
|
}
|
|
2310
|
-
_assembleReplyTrees(
|
|
2313
|
+
_assembleReplyTrees(entries) {
|
|
2311
2314
|
const parsedByCid = /* @__PURE__ */ new Map();
|
|
2312
|
-
const
|
|
2313
|
-
for (const { entry, parent } of items) {
|
|
2315
|
+
for (const entry of entries) {
|
|
2314
2316
|
const cid = entry.commentUpdate.cid;
|
|
2315
|
-
if (parsedByCid.has(cid))
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
if (resolvedReplies) return withSortedKeys({
|
|
2324
|
-
...rest,
|
|
2325
|
-
replies: resolvedReplies
|
|
2326
|
-
});
|
|
2327
|
-
if (dbReplies) {
|
|
2328
|
-
const pageCids = {};
|
|
2329
|
-
for (const sortName of Object.keys(dbReplies).sort()) {
|
|
2330
|
-
const sortEntry = dbReplies[sortName];
|
|
2317
|
+
if (!parsedByCid.has(cid)) parsedByCid.set(cid, entry);
|
|
2318
|
+
}
|
|
2319
|
+
const wireRepliesOf = (dbReplies) => {
|
|
2320
|
+
const pages = {};
|
|
2321
|
+
const pageCids = {};
|
|
2322
|
+
for (const sortName of Object.keys(dbReplies).sort()) {
|
|
2323
|
+
const sortEntry = dbReplies[sortName];
|
|
2324
|
+
if (!sortEntry?.commentCids) {
|
|
2331
2325
|
if (sortEntry?.allPageCids?.[0]) pageCids[sortName] = sortEntry.allPageCids[0];
|
|
2326
|
+
continue;
|
|
2332
2327
|
}
|
|
2333
|
-
if (Object.keys(pageCids).length > 0) return withSortedKeys({
|
|
2334
|
-
...rest,
|
|
2335
|
-
replies: {
|
|
2336
|
-
pageCids,
|
|
2337
|
-
pages: {}
|
|
2338
|
-
}
|
|
2339
|
-
});
|
|
2340
|
-
}
|
|
2341
|
-
return rest;
|
|
2342
|
-
};
|
|
2343
|
-
const attachReplies = (cid) => {
|
|
2344
|
-
const children = childrenByParent.get(cid);
|
|
2345
|
-
if (!children?.size) return void 0;
|
|
2346
|
-
const parentDbReplies = parsedByCid.get(cid)?.commentUpdate.replies;
|
|
2347
|
-
const pages = {};
|
|
2348
|
-
for (const sortName of Object.keys(parentDbReplies ?? {}).sort()) {
|
|
2349
|
-
const sortEntry = parentDbReplies[sortName];
|
|
2350
|
-
if (!sortEntry?.commentCids) continue;
|
|
2351
2328
|
const comments = [];
|
|
2352
2329
|
for (const childCid of sortEntry.commentCids) {
|
|
2353
|
-
const child =
|
|
2330
|
+
const child = parsedByCid.get(childCid);
|
|
2354
2331
|
if (child) comments.push({
|
|
2355
2332
|
comment: child.comment,
|
|
2356
|
-
commentUpdate:
|
|
2333
|
+
commentUpdate: sortEntry.flat ? withoutReplies(child.commentUpdate) : withWireReplies(child.commentUpdate)
|
|
2357
2334
|
});
|
|
2358
2335
|
}
|
|
2359
|
-
|
|
2336
|
+
const nextCid = sortEntry.allPageCids?.[0] ?? sortEntry.nextCid;
|
|
2337
|
+
pages[sortName] = {
|
|
2338
|
+
comments,
|
|
2339
|
+
...nextCid ? { nextCid } : {}
|
|
2340
|
+
};
|
|
2360
2341
|
}
|
|
2361
|
-
|
|
2362
|
-
|
|
2342
|
+
const hasPageCids = Object.keys(pageCids).length > 0;
|
|
2343
|
+
if (!hasPageCids && Object.keys(pages).length === 0) return void 0;
|
|
2344
|
+
return {
|
|
2345
|
+
...hasPageCids ? { pageCids } : {},
|
|
2346
|
+
pages
|
|
2347
|
+
};
|
|
2363
2348
|
};
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2349
|
+
const withoutReplies = (commentUpdate) => {
|
|
2350
|
+
const { replies: _dbReplies, ...rest } = commentUpdate;
|
|
2351
|
+
return rest;
|
|
2352
|
+
};
|
|
2353
|
+
const withWireReplies = (commentUpdate) => {
|
|
2354
|
+
const dbReplies = commentUpdate.replies;
|
|
2355
|
+
const replies = dbReplies && wireRepliesOf(dbReplies);
|
|
2356
|
+
const rest = withoutReplies(commentUpdate);
|
|
2357
|
+
return replies ? withSortedKeys({
|
|
2358
|
+
...rest,
|
|
2359
|
+
replies
|
|
2360
|
+
}) : rest;
|
|
2369
2361
|
};
|
|
2362
|
+
return { withWireReplies };
|
|
2370
2363
|
}
|
|
2371
2364
|
queryPageCommentsWithResolvedReplies(options) {
|
|
2372
2365
|
return this.resolveRepliesCidRefsForEntries(this.queryPageComments(options));
|
|
@@ -2397,10 +2390,7 @@ var DbHandler = class {
|
|
|
2397
2390
|
resolveRepliesCidRefsForEntries(entries) {
|
|
2398
2391
|
const withReplies = entries.filter((entry) => this._entryHasDbReplies(entry));
|
|
2399
2392
|
if (withReplies.length === 0) return entries;
|
|
2400
|
-
const trees = withReplies.every((entry) => entry.comment.depth === 0) ? this._assembleReplyTrees(this.queryRepliesUnderPosts(withReplies.map((entry) => entry.commentUpdate.cid))
|
|
2401
|
-
entry,
|
|
2402
|
-
parent: entry.comment.parentCid
|
|
2403
|
-
}))) : this._assembleReplyTreesFromCidRefs(withReplies);
|
|
2393
|
+
const trees = withReplies.every((entry) => entry.comment.depth === 0) ? this._assembleReplyTrees(this.queryRepliesUnderPosts(withReplies.map((entry) => entry.commentUpdate.cid))) : this._assembleReplyTreesFromCidRefs(withReplies);
|
|
2404
2394
|
return this._rebuildEntriesFromTrees(entries, trees);
|
|
2405
2395
|
}
|
|
2406
2396
|
_assembleReplyTreesFromCidRefs(entries) {
|
|
@@ -2427,52 +2417,17 @@ var DbHandler = class {
|
|
|
2427
2417
|
`, (row) => level.push(mapper.map(row)), true);
|
|
2428
2418
|
for (const entry of level) {
|
|
2429
2419
|
seen.add(entry.commentUpdate.cid);
|
|
2430
|
-
items.push(
|
|
2431
|
-
entry,
|
|
2432
|
-
parent: entry.comment.parentCid
|
|
2433
|
-
});
|
|
2420
|
+
items.push(entry);
|
|
2434
2421
|
}
|
|
2435
2422
|
frontier = listedChildren(level);
|
|
2436
2423
|
}
|
|
2437
2424
|
return this._assembleReplyTrees(items);
|
|
2438
2425
|
}
|
|
2439
|
-
_rebuildEntriesFromTrees(entries, {
|
|
2440
|
-
return entries.map((entry) => {
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
const resolvedPageCids = {};
|
|
2445
|
-
for (const sortName of Object.keys(replies).sort()) {
|
|
2446
|
-
const sortEntry = replies[sortName];
|
|
2447
|
-
if (sortEntry?.commentCids) {
|
|
2448
|
-
const resolvedComments = [];
|
|
2449
|
-
for (const cid of sortEntry.commentCids) {
|
|
2450
|
-
const child = parsedByCid.get(cid);
|
|
2451
|
-
if (child) resolvedComments.push({
|
|
2452
|
-
comment: child.comment,
|
|
2453
|
-
commentUpdate: buildWireCommentUpdate(child.commentUpdate, attachReplies(cid))
|
|
2454
|
-
});
|
|
2455
|
-
}
|
|
2456
|
-
const nextCidForSort = sortEntry.allPageCids?.[0] ?? sortEntry.nextCid;
|
|
2457
|
-
resolvedPages[sortName] = {
|
|
2458
|
-
comments: resolvedComments,
|
|
2459
|
-
...nextCidForSort ? { nextCid: nextCidForSort } : {}
|
|
2460
|
-
};
|
|
2461
|
-
}
|
|
2462
|
-
if (sortEntry?.allPageCids?.[0]) resolvedPageCids[sortName] = sortEntry.allPageCids[0];
|
|
2463
|
-
}
|
|
2464
|
-
const { replies: _dbReplies, ...entryCommentUpdateRest } = entry.commentUpdate;
|
|
2465
|
-
return {
|
|
2466
|
-
...entry,
|
|
2467
|
-
commentUpdate: withSortedKeys({
|
|
2468
|
-
...entryCommentUpdateRest,
|
|
2469
|
-
replies: {
|
|
2470
|
-
...Object.keys(resolvedPageCids).length > 0 ? { pageCids: resolvedPageCids } : {},
|
|
2471
|
-
pages: resolvedPages
|
|
2472
|
-
}
|
|
2473
|
-
})
|
|
2474
|
-
};
|
|
2475
|
-
});
|
|
2426
|
+
_rebuildEntriesFromTrees(entries, { withWireReplies }) {
|
|
2427
|
+
return entries.map((entry) => this._entryHasDbReplies(entry) ? {
|
|
2428
|
+
...entry,
|
|
2429
|
+
commentUpdate: withWireReplies(entry.commentUpdate)
|
|
2430
|
+
} : entry);
|
|
2476
2431
|
}
|
|
2477
2432
|
queryCommentAndCommentUpdateByCids(cids, opts) {
|
|
2478
2433
|
if (cids.length === 0) return [];
|
|
@@ -3805,10 +3760,10 @@ var DbHandler = class {
|
|
|
3805
3760
|
if (this._db || this._keyv) await this.destoryConnection();
|
|
3806
3761
|
this._transactionDepth = 0;
|
|
3807
3762
|
const dataPath = this._community._pkc.dataPath;
|
|
3808
|
-
const oldPathString = path
|
|
3809
|
-
const newPathString = path
|
|
3810
|
-
await fs$1.promises.mkdir(path
|
|
3811
|
-
await fs$1.promises.mkdir(path
|
|
3763
|
+
const oldPathString = path.join(dataPath, "communities", oldDbName);
|
|
3764
|
+
const newPathString = path.join(dataPath, "communities", newDbName);
|
|
3765
|
+
await fs$1.promises.mkdir(path.dirname(oldPathString), { recursive: true });
|
|
3766
|
+
await fs$1.promises.mkdir(path.dirname(newPathString), { recursive: true });
|
|
3812
3767
|
try {
|
|
3813
3768
|
if (!fs$1.existsSync(oldPathString)) log(`Old DB file ${oldPathString} does not exist. Cannot backup/rename.`);
|
|
3814
3769
|
else {
|
|
@@ -3830,8 +3785,8 @@ var DbHandler = class {
|
|
|
3830
3785
|
}
|
|
3831
3786
|
async lockCommunityStart(communityAddress = this._community.address) {
|
|
3832
3787
|
const log = logger_default("pkc-js:local-community:db-handler:lock:start");
|
|
3833
|
-
const lockfilePath = path
|
|
3834
|
-
const communityDbPath = path
|
|
3788
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
3789
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
3835
3790
|
try {
|
|
3836
3791
|
await import_src.default.lock(communityDbPath, {
|
|
3837
3792
|
lockfilePath,
|
|
@@ -3852,8 +3807,8 @@ var DbHandler = class {
|
|
|
3852
3807
|
async unlockCommunityStart(communityAddress = this._community.address) {
|
|
3853
3808
|
const log = logger_default("pkc-js:local-community:db-handler:unlock:start");
|
|
3854
3809
|
log.trace(`Attempting to unlock the start of community (${communityAddress})`);
|
|
3855
|
-
const lockfilePath = path
|
|
3856
|
-
const communityDbPath = path
|
|
3810
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
3811
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
3857
3812
|
if (!fs$1.existsSync(lockfilePath) || !fs$1.existsSync(communityDbPath)) return;
|
|
3858
3813
|
try {
|
|
3859
3814
|
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
@@ -3871,8 +3826,8 @@ var DbHandler = class {
|
|
|
3871
3826
|
}
|
|
3872
3827
|
async lockCommunityState() {
|
|
3873
3828
|
const log = logger_default("pkc-js:local-community:db-handler:lock:lockCommunityState");
|
|
3874
|
-
const lockfilePath = path
|
|
3875
|
-
const communityDbPath = path
|
|
3829
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
3830
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
3876
3831
|
try {
|
|
3877
3832
|
await import_src.default.lock(communityDbPath, {
|
|
3878
3833
|
lockfilePath,
|
|
@@ -3889,8 +3844,8 @@ var DbHandler = class {
|
|
|
3889
3844
|
}
|
|
3890
3845
|
async unlockCommunityState() {
|
|
3891
3846
|
const log = logger_default("pkc-js:local-community:db-handler:lock:unlockCommunityState");
|
|
3892
|
-
const lockfilePath = path
|
|
3893
|
-
const communityDbPath = path
|
|
3847
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
3848
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
3894
3849
|
if (!fs$1.existsSync(lockfilePath)) return;
|
|
3895
3850
|
try {
|
|
3896
3851
|
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
@@ -3900,7 +3855,7 @@ var DbHandler = class {
|
|
|
3900
3855
|
}
|
|
3901
3856
|
}
|
|
3902
3857
|
communityDbExists() {
|
|
3903
|
-
const communityDbPath = path
|
|
3858
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
3904
3859
|
return fs$1.existsSync(communityDbPath);
|
|
3905
3860
|
}
|
|
3906
3861
|
markCommentsAsPublishedToPostUpdates(commentCids) {
|
|
@@ -4144,7 +4099,8 @@ async function calculateNewCommentUpdate(opts) {
|
|
|
4144
4099
|
...newCommentUpdate,
|
|
4145
4100
|
replies: deriveDbReplies({
|
|
4146
4101
|
replies: newCommentUpdate.replies,
|
|
4147
|
-
allPageCids
|
|
4102
|
+
allPageCids,
|
|
4103
|
+
flatSortNames: generatedRepliesPages?.flatSortNames
|
|
4148
4104
|
}),
|
|
4149
4105
|
postUpdatesBucket: newPostUpdateBucket,
|
|
4150
4106
|
publishedToPostUpdatesMFS: false,
|
|
@@ -6912,10 +6868,10 @@ async function restoreCommunityAfterFailedRename({ community, oldAddress, newAdd
|
|
|
6912
6868
|
}
|
|
6913
6869
|
}
|
|
6914
6870
|
async function removePartialDbCopy({ community, oldAddress, newAddress, log }) {
|
|
6915
|
-
const communitiesPath =
|
|
6916
|
-
if (!fs.existsSync(
|
|
6871
|
+
const communitiesPath = Path.join(community._pkc.dataPath, "communities");
|
|
6872
|
+
if (!fs.existsSync(Path.join(communitiesPath, oldAddress))) return;
|
|
6917
6873
|
try {
|
|
6918
|
-
await fs.promises.rm(
|
|
6874
|
+
await fs.promises.rm(Path.join(communitiesPath, newAddress), { force: true });
|
|
6919
6875
|
} catch (e) {
|
|
6920
6876
|
log.error(`Failed to remove the partial DB copy of community (${oldAddress}) at ${newAddress}`, e);
|
|
6921
6877
|
}
|
|
@@ -7059,11 +7015,11 @@ async function edit(community, newCommunityOptions) {
|
|
|
7059
7015
|
const EXPORTS_KEY = STORAGE_KEYS[STORAGE_KEYS.EXPORTS];
|
|
7060
7016
|
function defaultExportPathFor(community, exportId) {
|
|
7061
7017
|
if (typeof community._pkc.dataPath !== "string") throw new PKCError("ERR_DATA_PATH_IS_NOT_DEFINED", { communityAddress: community.address });
|
|
7062
|
-
return
|
|
7018
|
+
return Path.join(community._pkc.dataPath, "exports", `${exportId}.sqlite`);
|
|
7063
7019
|
}
|
|
7064
7020
|
function sourceDbPathFor(community) {
|
|
7065
7021
|
if (typeof community._pkc.dataPath !== "string") throw new PKCError("ERR_DATA_PATH_IS_NOT_DEFINED", { communityAddress: community.address });
|
|
7066
|
-
return
|
|
7022
|
+
return Path.join(community._pkc.dataPath, "communities", community.address);
|
|
7067
7023
|
}
|
|
7068
7024
|
async function persistExports(community) {
|
|
7069
7025
|
if (!community._dbHandler) return;
|
|
@@ -7139,9 +7095,9 @@ async function runExportTask(community, exportId, opts) {
|
|
|
7139
7095
|
async function exportCommunityEmbedded(community, options = {}) {
|
|
7140
7096
|
if (options.signal?.aborted) throw options.signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
7141
7097
|
const exportId = v4();
|
|
7142
|
-
const destPath = options.exportPath ?
|
|
7098
|
+
const destPath = options.exportPath ? Path.resolve(options.exportPath) : defaultExportPathFor(community, exportId);
|
|
7143
7099
|
const includePrivateKey = options.includePrivateKey === true;
|
|
7144
|
-
if (
|
|
7100
|
+
if (Path.resolve(destPath) === Path.resolve(sourceDbPathFor(community))) throw new PKCError("ERR_EXPORT_PATH_TARGETS_LIVE_DB", {
|
|
7145
7101
|
communityAddress: community.address,
|
|
7146
7102
|
exportPath: destPath
|
|
7147
7103
|
});
|