@pkcprotocol/pkc-js 0.0.119 → 0.0.120
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 +2 -2
- package/dist/browser/community/community-client-manager.js +8 -2
- package/dist/browser/community/community-client-manager.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/pages/page-sort-options.d.ts +1 -0
- package/dist/browser/pages/page-sort-options.js +7 -6
- package/dist/browser/pages/page-sort-options.js.map +1 -1
- package/dist/browser/pages/page-sort-scoring.d.ts +5 -1
- package/dist/browser/pages/page-sort-scoring.js +23 -13
- package/dist/browser/pages/page-sort-scoring.js.map +1 -1
- package/dist/browser/pages/types.d.ts +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/publication.d.ts +2 -0
- package/dist/browser/publications/publication.js +24 -1
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/rpc/src/index.d.ts +4 -0
- package/dist/browser/rpc/src/index.js +74 -19
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/runtime/node/community/db-handler.d.ts +2 -2
- package/dist/browser/runtime/node/community/db-handler.js +42 -58
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/editing.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community/editing.js +25 -4
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +7 -4
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +17 -4
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/publication-validation.js +4 -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 +4 -1
- package/dist/browser/runtime/node/community/local-community.js +12 -1
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/community/page-generator.d.ts +0 -1
- package/dist/browser/runtime/node/community/page-generator.js.map +1 -1
- package/dist/browser/runtime/node/community/page-sorts/index.js +22 -4
- package/dist/browser/runtime/node/community/page-sorts/index.js.map +1 -1
- package/dist/browser/runtime/node/util.d.ts +4 -1
- package/dist/browser/runtime/node/util.js +41 -24
- package/dist/browser/runtime/node/util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +40 -40
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-Cr90E9ul.js → helia-for-pkc-Dk9JTeUn.js} +33 -33
- package/dist/bundled/chunks/{local-community-DngOEreY.js → local-community-BbJyIuOc.js} +118 -101
- package/dist/bundled/chunks/{local-community-B-UbNa-z.js → local-community-BkZDlh4z.js} +1 -1
- package/dist/bundled/chunks/{node-BHLzTAo9.js → node-CsHuIZmP.js} +21 -5
- package/dist/bundled/chunks/{page-sort-scoring-Drqxj8Pi.js → page-sort-scoring-B2iu-tyC.js} +11 -7
- package/dist/bundled/chunks/{rpc-local-community-_ooAoNPM.js → rpc-local-community-DMDs0XGh.js} +60 -27
- package/dist/bundled/chunks/{util-B-JWgzlN.js → util-CXxGmK2P.js} +3 -1
- package/dist/bundled/chunks/{util-DX2ZJtU4.js → util-_DJ6MgmW.js} +1 -1
- package/dist/bundled/chunks/{validate-package-factories-BSmEBl_0.js → validate-package-factories-BpJjVrRb.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 +56 -19
- package/dist/node/community/community-client-manager.js +8 -2
- package/dist/node/community/community-client-manager.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/pages/page-sort-options.d.ts +1 -0
- package/dist/node/pages/page-sort-options.js +7 -6
- package/dist/node/pages/page-sort-options.js.map +1 -1
- package/dist/node/pages/page-sort-scoring.d.ts +5 -1
- package/dist/node/pages/page-sort-scoring.js +23 -13
- package/dist/node/pages/page-sort-scoring.js.map +1 -1
- package/dist/node/pages/types.d.ts +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/publication.d.ts +2 -0
- package/dist/node/publications/publication.js +24 -1
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/rpc/src/index.d.ts +4 -0
- package/dist/node/rpc/src/index.js +74 -19
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/runtime/node/community/db-handler.d.ts +2 -2
- package/dist/node/runtime/node/community/db-handler.js +42 -58
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/editing.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community/editing.js +25 -4
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +7 -4
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +17 -4
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/publication-validation.js +4 -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 +4 -1
- package/dist/node/runtime/node/community/local-community.js +12 -1
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/community/page-generator.d.ts +0 -1
- package/dist/node/runtime/node/community/page-generator.js.map +1 -1
- package/dist/node/runtime/node/community/page-sorts/index.js +22 -4
- package/dist/node/runtime/node/community/page-sorts/index.js.map +1 -1
- package/dist/node/runtime/node/util.d.ts +4 -1
- package/dist/node/runtime/node/util.js +41 -24
- package/dist/node/runtime/node/util.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $t as CommentModerationPubsubMessagePublicationSchema, A as isLinkOfAnimatedImage, An as CommentIpfsSchema, Ar as PKCError, At as ChallengeMessageSchema, Bn as CommentUpdateTableRowSchema, Dn as VoteTablesRowSchema, Dt as pTimeout, F as isLinkValid, Gr as ZodError, Jn as CommentEditPubsubMessagePublicationSchema, Jt as CommunityEditPublicationPubsubReservedFields, K as removeNullUndefinedValues, Kt as version_default, Lt as DecryptedChallengeRequestPublicationSchema, M as isLinkOfImage, Mr as logger_default, Mt as ChallengeRequestMessageSchema, N as isLinkOfMedia, Ot as ChallengeAnswerMessageSchema, P as isLinkOfVideo, Pt as ChallengeVerificationMessageSchema, Q as retryKuboIpfsAddAndProvide, Qn as CommentEditsTableRowSchema, R as pubsubTopicToDhtKey, Rn as CommentUpdateSchema, Rt as DecryptedChallengeRequestSchema, S as hideClassPrivateProps, Sr as t$2, St as untrackStartedCommunity, Tn as VotePubsubReservedFields, Tt as require_sha256, U as removeBlocksFromKuboNode, Vn as CommentsTableRowSchema, W as removeMfsFilesSafely, X as retryKuboBlockPutPinAndProvidePubsubTopic, Xn as CommentEditReservedFields, Yn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, _ as getEquivalentCommunityAddresses, _r as r$1, a as calculateUnixFsDagSizeCidV0, c as contentContainsMarkdownVideos, ct as writeKuboFilesWithTimeout, d as derivePublicationFromChallengeRequest, dn as CommunityIpfsSchema, dr as n$2, en as CommentModerationReservedFields, f as doesDomainAddressHaveCapitalLetter, fn as CommunitySignedPropertyNames, fr as t$5, ft as findUpdatingCommunity, g as genToArray, h as findMalformedUnicodeString, hr as e, i as calculateStringSizeSameAsIpfsAddCidV0, it as timestamp, j as isLinkOfAudio, jn as CommentPubsubMessageReservedFields, jr as messages, lr as n$3, lt as findCommunityInRegistry, mr as e$1, nn as CommentModerationsTableRowSchema, nr as AuthorReservedFields, nt as statMfsPathSafely, o as contentContainsMarkdownAudio, ot as withSortedKeys, pr as t$6, r as calculateIpfsCidV0, s as contentContainsMarkdownImages, st as withSortedKeysDeep, t as areEquivalentCommunityAddresses, tt as sleepUntilTimeoutOrAbort, ur as t$7, ut as findStartedCommunity, v as getErrorCodeFromMessage, vr as t$3, vt as syncCommunityRegistryEntry, w as ipnsNameToIpnsOverPubsubTopic, wn as VotePubsubMessagePublicationSchema, wr as require_retry, wt as untrackUpdatingCommunity, xn as isStringDomain, xr as t$4, xt as trackUpdatingCommunity, y as getIpnsRecordInLocalKuboNode, yt as trackStartedCommunity } from "./util-
|
|
3
|
-
import { $n as backupCommunityDb, An as verifyCommunity,
|
|
4
|
-
import { a as scorePageCommentsWithFile, i as partitionPageCommentsForSort, n as filterRepliesForPageSort, o as stripRepliesFromPageComment, r as orderPageCommentsByScore, t as createDescendantsLookup } from "./page-sort-scoring-
|
|
2
|
+
import { $t as CommentModerationPubsubMessagePublicationSchema, A as isLinkOfAnimatedImage, An as CommentIpfsSchema, Ar as PKCError, At as ChallengeMessageSchema, Bn as CommentUpdateTableRowSchema, Dn as VoteTablesRowSchema, Dt as pTimeout, F as isLinkValid, Gr as ZodError, Jn as CommentEditPubsubMessagePublicationSchema, Jt as CommunityEditPublicationPubsubReservedFields, K as removeNullUndefinedValues, Kt as version_default, Lt as DecryptedChallengeRequestPublicationSchema, M as isLinkOfImage, Mr as logger_default, Mt as ChallengeRequestMessageSchema, N as isLinkOfMedia, Ot as ChallengeAnswerMessageSchema, P as isLinkOfVideo, Pt as ChallengeVerificationMessageSchema, Q as retryKuboIpfsAddAndProvide, Qn as CommentEditsTableRowSchema, R as pubsubTopicToDhtKey, Rn as CommentUpdateSchema, Rt as DecryptedChallengeRequestSchema, S as hideClassPrivateProps, Sr as t$2, St as untrackStartedCommunity, Tn as VotePubsubReservedFields, Tt as require_sha256, U as removeBlocksFromKuboNode, Vn as CommentsTableRowSchema, W as removeMfsFilesSafely, X as retryKuboBlockPutPinAndProvidePubsubTopic, Xn as CommentEditReservedFields, Yn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, _ as getEquivalentCommunityAddresses, _r as r$1, a as calculateUnixFsDagSizeCidV0, c as contentContainsMarkdownVideos, ct as writeKuboFilesWithTimeout, d as derivePublicationFromChallengeRequest, dn as CommunityIpfsSchema, dr as n$2, en as CommentModerationReservedFields, f as doesDomainAddressHaveCapitalLetter, fn as CommunitySignedPropertyNames, fr as t$5, ft as findUpdatingCommunity, g as genToArray, h as findMalformedUnicodeString, hr as e, i as calculateStringSizeSameAsIpfsAddCidV0, it as timestamp, j as isLinkOfAudio, jn as CommentPubsubMessageReservedFields, jr as messages, lr as n$3, lt as findCommunityInRegistry, mr as e$1, nn as CommentModerationsTableRowSchema, nr as AuthorReservedFields, nt as statMfsPathSafely, o as contentContainsMarkdownAudio, ot as withSortedKeys, pr as t$6, r as calculateIpfsCidV0, s as contentContainsMarkdownImages, st as withSortedKeysDeep, t as areEquivalentCommunityAddresses, tt as sleepUntilTimeoutOrAbort, ur as t$7, ut as findStartedCommunity, v as getErrorCodeFromMessage, vr as t$3, vt as syncCommunityRegistryEntry, w as ipnsNameToIpnsOverPubsubTopic, wn as VotePubsubMessagePublicationSchema, wr as require_retry, wt as untrackUpdatingCommunity, xn as isStringDomain, xr as t$4, xt as trackUpdatingCommunity, y as getIpnsRecordInLocalKuboNode, yt as trackStartedCommunity } from "./util-CXxGmK2P.js";
|
|
3
|
+
import { $n as backupCommunityDb, An as verifyCommunity, Cn as verifyChallengeRequest, Cr as n$4, Dn as verifyCommentModeration, En as verifyCommentIpfs, Er as stringify, Gn as decode, Hn as getCommunityNameFromWire, In as getAuthorNameFromWire, Jn as getIpfsKeyFromPrivateKey, Kn as encode, Mn as verifyVote, Mr as require_lodash_merge, Nn as buildRuntimeAuthor, On as verifyCommentPubsubMessage, Pn as cleanWireAuthor, Q as createSchemaRowParser, Qn as BackupAbortError, Rn as crosspostChainDepthUpTo, S as KeyvBetterSqlite3, Sr as n$5, St as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Tn as verifyCommentEdit, Tr as t$9, Tt as parseJsonWithPKCErrorIfFails, U as pLimit, Un as getCommunityPublicKeyFromWire, X as coerceSchemaRowJson, Xn as getPKCAddressFromPublicKeySync, Y as coerceSchemaRowBoolean, Yn as getPKCAddressFromPublicKey, Z as collectSchemaRowCoercions, Zn as getPublicKeyFromPrivateKey, _ as createAuthorIdentityMatcher, _n as signCommentUpdateForChallengeVerification, a as generatePagesReportingFailedSorts, ar as deriveDbPosts, br as r$2, c as resolvePageSortsOrThrow, cn as cleanUpBeforePublishing, d as getChallengeVerification, en as SignerWithPublicKeyAddress, er as calculateExpectedSignatureSize, f as getCommunityChallengeFromCommunityChallengeSettings, fn as signChallengeVerification, ft as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, g as authorNameResolveFailureReason, gn as signCommentUpdate, h as authorIdentityMatcherForRequest, hr as resolveDbPostsCidRefs, i as derivePublicPageSorts, in as decryptEd25519AesGcmPublicKeyBuffer, ir as deriveCommentIpfsFromCommentTableRow, j as iterateOverPageCidsToFindAllCids, jn as verifyCommunityEdit, jr as STORAGE_KEYS, kn as verifyCommentUpdate, lr as getThumbnailPropsOfLink, m as pkcJsChallenges, mn as signCommentEdit, mr as refreshCommunitiesList, o as loadPageSortsForStartedCommunity, on as encryptEd25519AesGcmPublicKeyBuffer, or as deriveDbReplies, p as loadChallengeFileFromCommunityChallengeSettings, pn as signComment, pr as moveCommunityDbToDeletedDirectory, r as computePageSortsFingerprint, rr as deleteOldCommunityInWindows, s as lookupPageSortFactories, sn as _validateSignatureOfPKCRecord, sr as getDefaultCommunityDbConfig, t as RpcLocalCommunity, tr as calculateInlineRepliesBudget, u as deriveCommunityChallengesOrThrow, un as signChallengeMessage, ur as importSignerIntoKuboNode, ut as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, v as TrackedInstanceRegistry, vn as signCommunity, vr as t$10, w as TIMEFRAMES_TO_SECONDS, x as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, xn as verifyChallengeAnswer, xr as t$8, y as LRUCache, yr as t$11, zn as effectiveMaxCrosspostDepth } from "./rpc-local-community-DMDs0XGh.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-B2iu-tyC.js";
|
|
5
5
|
import { randomFillSync, randomUUID } from "node:crypto";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
-
import
|
|
7
|
+
import Path from "node:path";
|
|
8
8
|
import os from "os";
|
|
9
9
|
import { existsSync, promises } from "node:fs";
|
|
10
|
-
import path
|
|
10
|
+
import path from "path";
|
|
11
11
|
import assert from "assert";
|
|
12
12
|
import { Buffer as Buffer$1 } from "buffer";
|
|
13
13
|
import fs from "fs";
|
|
@@ -1692,15 +1692,15 @@ async function throwIfChallengeSettingsAreInvalid({ challengeSettings, pkc, comm
|
|
|
1692
1692
|
const processStartedCommunities = new TrackedInstanceRegistry();
|
|
1693
1693
|
function normalizeRegistryDataPath(dataPath) {
|
|
1694
1694
|
if (dataPath === void 0) return void 0;
|
|
1695
|
-
const resolved = path
|
|
1695
|
+
const resolved = path.resolve(dataPath);
|
|
1696
1696
|
let existing = resolved;
|
|
1697
1697
|
let tail = "";
|
|
1698
1698
|
while (true) try {
|
|
1699
|
-
return path
|
|
1699
|
+
return path.join(fs.realpathSync.native(existing), tail);
|
|
1700
1700
|
} catch {
|
|
1701
|
-
const parent = path
|
|
1701
|
+
const parent = path.dirname(existing);
|
|
1702
1702
|
if (parent === existing) return resolved;
|
|
1703
|
-
tail = path
|
|
1703
|
+
tail = path.join(path.basename(existing), tail);
|
|
1704
1704
|
existing = parent;
|
|
1705
1705
|
}
|
|
1706
1706
|
}
|
|
@@ -3081,9 +3081,9 @@ var DbHandler = class {
|
|
|
3081
3081
|
if (needToMigrate) {
|
|
3082
3082
|
if (dbExistsAlready && currentDbVersion > 0) {
|
|
3083
3083
|
this.destoryConnection();
|
|
3084
|
-
backupDbPath = path
|
|
3085
|
-
log(`Copying db ${path
|
|
3086
|
-
if (!fs.existsSync(path
|
|
3084
|
+
backupDbPath = path.join(path.dirname(dbPath), ".backup_before_migration", `${path.basename(dbPath)}.${currentDbVersion}.${timestamp()}`);
|
|
3085
|
+
log(`Copying db ${path.basename(dbPath)} to ${backupDbPath} before migration`);
|
|
3086
|
+
if (!fs.existsSync(path.dirname(backupDbPath))) await fs.promises.mkdir(path.dirname(backupDbPath), { recursive: true });
|
|
3087
3087
|
const sourceDb = new Database(dbPath, { fileMustExist: true });
|
|
3088
3088
|
await sourceDb.backup(backupDbPath);
|
|
3089
3089
|
sourceDb.close();
|
|
@@ -3607,57 +3607,47 @@ var DbHandler = class {
|
|
|
3607
3607
|
_pendingApprovalClause(alias) {
|
|
3608
3608
|
return `(${alias}.pendingApproval IS NULL OR ${alias}.pendingApproval != 1)`;
|
|
3609
3609
|
}
|
|
3610
|
-
|
|
3610
|
+
_communityIdentityClause(alias) {
|
|
3611
3611
|
const address = this._community.address;
|
|
3612
|
-
const addresses = getEquivalentCommunityAddresses(address);
|
|
3613
3612
|
if (isStringDomain(address)) {
|
|
3614
|
-
const
|
|
3613
|
+
const names = getEquivalentCommunityAddresses(address);
|
|
3615
3614
|
return {
|
|
3616
|
-
clause: `(${alias}.communityName
|
|
3617
|
-
params:
|
|
3615
|
+
clause: `(${alias}.communityName IS NULL OR ${alias}.communityName IN (${names.map(() => "?").join(", ")}))`,
|
|
3616
|
+
params: names
|
|
3618
3617
|
};
|
|
3619
|
-
}
|
|
3620
|
-
|
|
3618
|
+
}
|
|
3619
|
+
return {
|
|
3620
|
+
clause: `(${alias}.communityPublicKey IS NULL OR ${alias}.communityPublicKey = ?)`,
|
|
3621
3621
|
params: [address]
|
|
3622
3622
|
};
|
|
3623
3623
|
}
|
|
3624
|
-
|
|
3624
|
+
_communityIdentityClauseNamed(alias, paramPrefix) {
|
|
3625
3625
|
const address = this._community.address;
|
|
3626
|
-
const addresses = getEquivalentCommunityAddresses(address);
|
|
3627
3626
|
if (isStringDomain(address)) {
|
|
3628
3627
|
const params = {};
|
|
3629
|
-
const namePlaceholders = [];
|
|
3630
|
-
const keyPlaceholders = [];
|
|
3631
|
-
addresses.forEach((addr, i) => {
|
|
3632
|
-
const nameParam = `${paramPrefix}CommunityName${i}`;
|
|
3633
|
-
const keyParam = `${paramPrefix}CommunityKey${i}`;
|
|
3634
|
-
params[nameParam] = addr;
|
|
3635
|
-
params[keyParam] = addr;
|
|
3636
|
-
namePlaceholders.push(`:${nameParam}`);
|
|
3637
|
-
keyPlaceholders.push(`:${keyParam}`);
|
|
3638
|
-
});
|
|
3639
3628
|
return {
|
|
3640
|
-
clause: `(${alias}.communityName
|
|
3629
|
+
clause: `(${alias}.communityName IS NULL OR ${alias}.communityName IN (${getEquivalentCommunityAddresses(address).map((name, i) => {
|
|
3630
|
+
const paramName = `${paramPrefix}CommunityName${i}`;
|
|
3631
|
+
params[paramName] = name;
|
|
3632
|
+
return `:${paramName}`;
|
|
3633
|
+
}).join(", ")}))`,
|
|
3641
3634
|
params
|
|
3642
3635
|
};
|
|
3643
|
-
} else {
|
|
3644
|
-
const paramName = `${paramPrefix}CommunityKey`;
|
|
3645
|
-
return {
|
|
3646
|
-
clause: `${alias}.communityPublicKey = :${paramName}`,
|
|
3647
|
-
params: { [paramName]: address }
|
|
3648
|
-
};
|
|
3649
3636
|
}
|
|
3637
|
+
const paramName = `${paramPrefix}CommunityKey`;
|
|
3638
|
+
return {
|
|
3639
|
+
clause: `(${alias}.communityPublicKey IS NULL OR ${alias}.communityPublicKey = :${paramName})`,
|
|
3640
|
+
params: { [paramName]: address }
|
|
3641
|
+
};
|
|
3650
3642
|
}
|
|
3651
3643
|
_buildPageQueryParts(options) {
|
|
3652
3644
|
const commentsTable = TABLES.COMMENTS;
|
|
3653
3645
|
const commentUpdatesTable = TABLES.COMMENT_UPDATES;
|
|
3654
3646
|
const whereClauses = [`${commentsTable}.parentCid = ?`];
|
|
3655
3647
|
const params = [options.parentCid];
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
params.push(...addrParams);
|
|
3660
|
-
}
|
|
3648
|
+
const { clause: identityClause, params: identityParams } = this._communityIdentityClause(commentsTable);
|
|
3649
|
+
whereClauses.push(identityClause);
|
|
3650
|
+
params.push(...identityParams);
|
|
3661
3651
|
if (options.excludeCommentPendingApproval) whereClauses.push(this._pendingApprovalClause(commentsTable));
|
|
3662
3652
|
if (options.excludeRemovedComments) whereClauses.push(this._removedClause(commentUpdatesTable));
|
|
3663
3653
|
if (options.excludeDeletedComments) whereClauses.push(this._deletedFromUpdatesClause(commentUpdatesTable));
|
|
@@ -3887,14 +3877,12 @@ var DbHandler = class {
|
|
|
3887
3877
|
const commentsAlias = "comments";
|
|
3888
3878
|
const commentUpdatesAlias = "c_updates";
|
|
3889
3879
|
const deletedLookupAlias = "d";
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
params.push(...recAddrParams);
|
|
3897
|
-
}
|
|
3880
|
+
const { clause: baseIdentityClause, params: baseIdentityParams } = this._communityIdentityClause(commentsAlias);
|
|
3881
|
+
baseFilterClauses.push(baseIdentityClause);
|
|
3882
|
+
params.push(...baseIdentityParams);
|
|
3883
|
+
const { clause: recursiveIdentityClause, params: recursiveIdentityParams } = this._communityIdentityClause(commentsAlias);
|
|
3884
|
+
recursiveFilterClauses.push(recursiveIdentityClause);
|
|
3885
|
+
params.push(...recursiveIdentityParams);
|
|
3898
3886
|
if (options.excludeCommentPendingApproval) {
|
|
3899
3887
|
const clause = this._pendingApprovalClause(commentsAlias);
|
|
3900
3888
|
baseFilterClauses.push(clause);
|
|
@@ -4046,7 +4034,7 @@ var DbHandler = class {
|
|
|
4046
4034
|
_collectCommentsToBeUpdated() {
|
|
4047
4035
|
const windowed = this._buildWindowedReplySortArms(timestamp());
|
|
4048
4036
|
const notPending = (alias) => `(${alias}.pendingApproval IS NULL OR ${alias}.pendingApproval != 1)`;
|
|
4049
|
-
const countedChildAddress = this.
|
|
4037
|
+
const countedChildAddress = this._communityIdentityClauseNamed("c", "countedChild");
|
|
4050
4038
|
const countedChild = `
|
|
4051
4039
|
FROM ${TABLES.COMMENTS} c
|
|
4052
4040
|
JOIN ${TABLES.COMMENT_UPDATES} cu_child ON c.cid = cu_child.cid
|
|
@@ -4186,8 +4174,8 @@ var DbHandler = class {
|
|
|
4186
4174
|
}
|
|
4187
4175
|
queryCommunityStats() {
|
|
4188
4176
|
const now = timestamp();
|
|
4189
|
-
const { clause: commentAddrClause, params: commentAddrParams } = this.
|
|
4190
|
-
const { clause: votesAddrClause, params: votesAddrParams } = this.
|
|
4177
|
+
const { clause: commentAddrClause, params: commentAddrParams } = this._communityIdentityClauseNamed("comments", "statsComments");
|
|
4178
|
+
const { clause: votesAddrClause, params: votesAddrParams } = this._communityIdentityClauseNamed("comments_for_votes", "statsVotes");
|
|
4191
4179
|
const removedCommentsClause = this._removedClause("cu_comments");
|
|
4192
4180
|
const deletedCommentsClause = this._deletedFromUpdatesClause("cu_comments");
|
|
4193
4181
|
const removedVotesClause = this._removedClause("cu_votes");
|
|
@@ -4328,7 +4316,7 @@ var DbHandler = class {
|
|
|
4328
4316
|
}
|
|
4329
4317
|
queryFirstCommentWithDepth(commentDepth) {
|
|
4330
4318
|
if (!Number.isInteger(commentDepth) || commentDepth < 0) throw new Error("commentDepth must be a non-negative integer");
|
|
4331
|
-
const { clause: addrClause, params: addrParams } = this.
|
|
4319
|
+
const { clause: addrClause, params: addrParams } = this._communityIdentityClauseNamed("c", "firstComment");
|
|
4332
4320
|
const exactDepthRow = this._db.prepare(`SELECT c.* FROM ${TABLES.COMMENTS} c
|
|
4333
4321
|
LEFT JOIN ${TABLES.COMMENT_UPDATES} cu ON cu.cid = c.cid
|
|
4334
4322
|
WHERE ${addrClause}
|
|
@@ -4396,7 +4384,7 @@ var DbHandler = class {
|
|
|
4396
4384
|
const currentTimestampSeconds = timestamp();
|
|
4397
4385
|
const maxBucket = Math.max(...buckets);
|
|
4398
4386
|
const caseClauses = buckets.sort((a, b) => a - b).map((bucket) => `WHEN (${currentTimestampSeconds} - c.timestamp) <= ${bucket} THEN ${bucket}`).join(" ");
|
|
4399
|
-
const { clause: addrClause, params: addrParams } = this.
|
|
4387
|
+
const { clause: addrClause, params: addrParams } = this._communityIdentityClause("c");
|
|
4400
4388
|
const query = `
|
|
4401
4389
|
WITH post_data AS (
|
|
4402
4390
|
SELECT c.cid, c.timestamp, cu.postUpdatesBucket AS current_bucket,
|
|
@@ -4669,7 +4657,7 @@ var DbHandler = class {
|
|
|
4669
4657
|
}
|
|
4670
4658
|
_queryReplyCountsByParentCids(parentCids) {
|
|
4671
4659
|
const result = /* @__PURE__ */ new Map();
|
|
4672
|
-
const { clause: addrClause, params: addrParams } = this.
|
|
4660
|
+
const { clause: addrClause, params: addrParams } = this._communityIdentityClause("c");
|
|
4673
4661
|
const present = this._replyWalkPresentExpression();
|
|
4674
4662
|
const deletedLookup = `(SELECT cid, json_extract(edit, '$.deleted') AS deleted_flag FROM ${TABLES.COMMENT_UPDATES})`;
|
|
4675
4663
|
for (const { placeholders, params } of this._cidChunks(parentCids, addrParams.length * 2)) {
|
|
@@ -4696,7 +4684,7 @@ var DbHandler = class {
|
|
|
4696
4684
|
}
|
|
4697
4685
|
_queryLastReplyTimestampsByParentCids(parentCids) {
|
|
4698
4686
|
const result = /* @__PURE__ */ new Map();
|
|
4699
|
-
const { clause: addrClause, params: addrParams } = this.
|
|
4687
|
+
const { clause: addrClause, params: addrParams } = this._communityIdentityClause("c");
|
|
4700
4688
|
const walked = `${addrClause} AND (c.pendingApproval IS NULL OR c.pendingApproval != 1)`;
|
|
4701
4689
|
const present = this._replyWalkPresentExpression();
|
|
4702
4690
|
const deletedLookup = `(SELECT cid, json_extract(edit, '$.deleted') AS deleted_flag FROM ${TABLES.COMMENT_UPDATES})`;
|
|
@@ -4720,7 +4708,7 @@ var DbHandler = class {
|
|
|
4720
4708
|
}
|
|
4721
4709
|
_queryLastChildCidsByParentCids(parentCids) {
|
|
4722
4710
|
const result = /* @__PURE__ */ new Map();
|
|
4723
|
-
const { clause: addrClause, params: addrParams } = this.
|
|
4711
|
+
const { clause: addrClause, params: addrParams } = this._communityIdentityClause("c");
|
|
4724
4712
|
for (const { placeholders, params } of this._cidChunks(parentCids, addrParams.length)) {
|
|
4725
4713
|
const rows = this._prepareCached(`SELECT c.parentCid AS parentCid, c.cid AS cid, MAX(c.rowid) AS lastRowid FROM ${TABLES.COMMENTS} c
|
|
4726
4714
|
INNER JOIN ${TABLES.COMMENT_UPDATES} cu ON cu.cid = c.cid
|
|
@@ -5194,10 +5182,10 @@ var DbHandler = class {
|
|
|
5194
5182
|
if (this._db || this._keyv) await this.destoryConnection();
|
|
5195
5183
|
this._transactionDepth = 0;
|
|
5196
5184
|
const dataPath = this._community._pkc.dataPath;
|
|
5197
|
-
const oldPathString = path
|
|
5198
|
-
const newPathString = path
|
|
5199
|
-
await fs.promises.mkdir(path
|
|
5200
|
-
await fs.promises.mkdir(path
|
|
5185
|
+
const oldPathString = path.join(dataPath, "communities", oldDbName);
|
|
5186
|
+
const newPathString = path.join(dataPath, "communities", newDbName);
|
|
5187
|
+
await fs.promises.mkdir(path.dirname(oldPathString), { recursive: true });
|
|
5188
|
+
await fs.promises.mkdir(path.dirname(newPathString), { recursive: true });
|
|
5201
5189
|
try {
|
|
5202
5190
|
if (!fs.existsSync(oldPathString)) log(`Old DB file ${oldPathString} does not exist. Cannot backup/rename.`);
|
|
5203
5191
|
else {
|
|
@@ -5219,8 +5207,8 @@ var DbHandler = class {
|
|
|
5219
5207
|
}
|
|
5220
5208
|
async lockCommunityStart(communityAddress = this._community.address) {
|
|
5221
5209
|
const log = logger_default("pkc-js:local-community:db-handler:lock:start");
|
|
5222
|
-
const lockfilePath = path
|
|
5223
|
-
const communityDbPath = path
|
|
5210
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5211
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5224
5212
|
try {
|
|
5225
5213
|
await import_src.default.lock(communityDbPath, {
|
|
5226
5214
|
lockfilePath,
|
|
@@ -5241,8 +5229,8 @@ var DbHandler = class {
|
|
|
5241
5229
|
async unlockCommunityStart(communityAddress = this._community.address) {
|
|
5242
5230
|
const log = logger_default("pkc-js:local-community:db-handler:unlock:start");
|
|
5243
5231
|
log.trace(`Attempting to unlock the start of community (${communityAddress})`);
|
|
5244
|
-
const lockfilePath = path
|
|
5245
|
-
const communityDbPath = path
|
|
5232
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5233
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5246
5234
|
if (!fs.existsSync(lockfilePath) || !fs.existsSync(communityDbPath)) return;
|
|
5247
5235
|
try {
|
|
5248
5236
|
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
@@ -5253,8 +5241,8 @@ var DbHandler = class {
|
|
|
5253
5241
|
}
|
|
5254
5242
|
}
|
|
5255
5243
|
async isCommunityStartLocked(communityAddress = this._community.address) {
|
|
5256
|
-
const lockfilePath = path
|
|
5257
|
-
const communityDbPath = path
|
|
5244
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5245
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5258
5246
|
return await import_src.default.check(communityDbPath, {
|
|
5259
5247
|
lockfilePath,
|
|
5260
5248
|
realpath: false,
|
|
@@ -5263,8 +5251,8 @@ var DbHandler = class {
|
|
|
5263
5251
|
}
|
|
5264
5252
|
async lockCommunityState() {
|
|
5265
5253
|
const log = logger_default("pkc-js:local-community:db-handler:lock:lockCommunityState");
|
|
5266
|
-
const lockfilePath = path
|
|
5267
|
-
const communityDbPath = path
|
|
5254
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
5255
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5268
5256
|
try {
|
|
5269
5257
|
await import_src.default.lock(communityDbPath, {
|
|
5270
5258
|
lockfilePath,
|
|
@@ -5281,8 +5269,8 @@ var DbHandler = class {
|
|
|
5281
5269
|
}
|
|
5282
5270
|
async unlockCommunityState() {
|
|
5283
5271
|
const log = logger_default("pkc-js:local-community:db-handler:lock:unlockCommunityState");
|
|
5284
|
-
const lockfilePath = path
|
|
5285
|
-
const communityDbPath = path
|
|
5272
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
5273
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5286
5274
|
if (!fs.existsSync(lockfilePath)) return;
|
|
5287
5275
|
try {
|
|
5288
5276
|
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
@@ -5292,7 +5280,7 @@ var DbHandler = class {
|
|
|
5292
5280
|
}
|
|
5293
5281
|
}
|
|
5294
5282
|
communityDbExists() {
|
|
5295
|
-
const communityDbPath = path
|
|
5283
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5296
5284
|
return fs.existsSync(communityDbPath);
|
|
5297
5285
|
}
|
|
5298
5286
|
markCommentsAsPublishedToPostUpdates(commentCids) {
|
|
@@ -5347,11 +5335,9 @@ var DbHandler = class {
|
|
|
5347
5335
|
const mapper = this._pageEntryMapper(pageOptions.commentUpdateFieldsToExclude);
|
|
5348
5336
|
const params = {};
|
|
5349
5337
|
const postsWhereClauses = ["c.depth = 0"];
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
Object.assign(params, addrParams);
|
|
5354
|
-
}
|
|
5338
|
+
const { clause: identityClause, params: identityParams } = this._communityIdentityClauseNamed("c", "asPosts");
|
|
5339
|
+
postsWhereClauses.push(identityClause);
|
|
5340
|
+
Object.assign(params, identityParams);
|
|
5355
5341
|
if (pageOptions.excludeRemovedComments) postsWhereClauses.push(this._removedClause("cu"));
|
|
5356
5342
|
if (pageOptions.excludeDeletedComments) postsWhereClauses.push(this._deletedFromUpdatesClause("cu"));
|
|
5357
5343
|
if (pageOptions.excludeCommentPendingApproval) postsWhereClauses.push(this._pendingApprovalClause("c"));
|
|
@@ -6559,6 +6545,7 @@ async function checkWireFormatAndCommunityAuthor(community, publication, log, au
|
|
|
6559
6545
|
}
|
|
6560
6546
|
const pubCommunityName = getCommunityNameFromWire(publication);
|
|
6561
6547
|
if (pubCommunityName && pubCommunityName !== community.address) return messages.ERR_PUBLICATION_INVALID_COMMUNITY_NAME;
|
|
6548
|
+
if (!pubCommunityName && isStringDomain(community.address)) return messages.ERR_PUBLICATION_MISSING_COMMUNITY_NAME;
|
|
6562
6549
|
if (publication.timestamp <= timestamp() - 300 || publication.timestamp >= timestamp() + 300) return messages.ERR_PUBLICATION_TIMESTAMP_IS_NOT_IN_PROPER_RANGE;
|
|
6563
6550
|
if (typeof authorCommunity?.banExpiresAt === "number" && authorCommunity.banExpiresAt > timestamp()) return messages.ERR_AUTHOR_IS_BANNED;
|
|
6564
6551
|
}
|
|
@@ -7405,7 +7392,7 @@ function calculateLatestUpdateTrigger(community) {
|
|
|
7405
7392
|
const lastPublishTooOld = (community.updatedAt || 0) < timestamp() - 900;
|
|
7406
7393
|
const lastPostCidChanged = community.lastPostCid !== community._dbHandler.queryLatestPostCid()?.cid;
|
|
7407
7394
|
const lastCommentCidChanged = community.lastCommentCid !== community._dbHandler.queryLatestCommentCid()?.cid;
|
|
7408
|
-
|
|
7395
|
+
if (!community._communityUpdateTrigger && (lastPublishTooOld || community._pendingEditProps.length > 0 || community._blocksToRm.length > 0 || lastCommentCidChanged || lastPostCidChanged)) community._communityUpdateTrigger = true;
|
|
7409
7396
|
}
|
|
7410
7397
|
function requireCommunityUpdateIfModQueueChanged(community) {
|
|
7411
7398
|
const combinedHashOfAllQueuedComments = community._dbHandler.queryCombinedHashOfPendingComments();
|
|
@@ -7746,28 +7733,34 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
7746
7733
|
const shouldStopPublishLoop = () => {
|
|
7747
7734
|
return community.state !== "started" || community._stopHasBeenCalled && (community._pendingEditProps.length === 0 || syncFailedSinceStop);
|
|
7748
7735
|
};
|
|
7749
|
-
const waitUntilNextSync = async () => {
|
|
7736
|
+
const waitUntilNextSync = async ({ lastSyncFailed }) => {
|
|
7750
7737
|
const doneWithLoopTime = Date.now();
|
|
7738
|
+
if (lastSyncFailed) calculateLatestUpdateTrigger(community);
|
|
7739
|
+
const triggerGenerationAfterFailure = community._updateTriggerGeneration;
|
|
7751
7740
|
await new Promise((resolve) => {
|
|
7752
7741
|
const checkInterval = setInterval(() => {
|
|
7753
7742
|
const syncIntervalMsPassedSinceDoneWithLoop = Date.now() - doneWithLoopTime >= syncIntervalMs;
|
|
7754
7743
|
calculateLatestUpdateTrigger(community);
|
|
7755
|
-
if (community._communityUpdateTrigger || shouldStopPublishLoop() || syncIntervalMsPassedSinceDoneWithLoop) {
|
|
7744
|
+
if ((lastSyncFailed ? community._updateTriggerGeneration !== triggerGenerationAfterFailure : community._communityUpdateTrigger) || shouldStopPublishLoop() || syncIntervalMsPassedSinceDoneWithLoop) {
|
|
7756
7745
|
clearInterval(checkInterval);
|
|
7757
7746
|
resolve(1);
|
|
7758
7747
|
}
|
|
7759
7748
|
}, 100);
|
|
7760
7749
|
});
|
|
7761
7750
|
};
|
|
7762
|
-
while (!shouldStopPublishLoop())
|
|
7763
|
-
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
7751
|
+
while (!shouldStopPublishLoop()) {
|
|
7752
|
+
let lastSyncFailed = false;
|
|
7753
|
+
try {
|
|
7754
|
+
await syncIpnsWithDb(community);
|
|
7755
|
+
await reprovideOnAddressChangeIfDue(community).catch((e) => log.error("Failed to re-provide connection CIDs on address change", e));
|
|
7756
|
+
await reprovideAnchorRecordIfDue(community).catch((e) => log.error("Failed to re-provide the anchor record", e));
|
|
7757
|
+
} catch (e) {
|
|
7758
|
+
lastSyncFailed = true;
|
|
7759
|
+
if (community._stopHasBeenCalled) syncFailedSinceStop = true;
|
|
7760
|
+
community.emit("error", e);
|
|
7761
|
+
} finally {
|
|
7762
|
+
await waitUntilNextSync({ lastSyncFailed });
|
|
7763
|
+
}
|
|
7771
7764
|
}
|
|
7772
7765
|
log("Stopping the publishing loop of community", community.address);
|
|
7773
7766
|
}
|
|
@@ -8146,6 +8139,7 @@ async function deleteCommunity(community) {
|
|
|
8146
8139
|
community._dbHandler.destoryConnection();
|
|
8147
8140
|
}
|
|
8148
8141
|
await moveCommunityDbToDeletedDirectory(community.address, community._pkc);
|
|
8142
|
+
refreshCommunitiesList(community._pkc);
|
|
8149
8143
|
log(`Deleted community (${community.address}) successfully`);
|
|
8150
8144
|
}
|
|
8151
8145
|
//#endregion
|
|
@@ -8240,6 +8234,23 @@ async function validateNewAddressBeforeEditing(community, newAddress, log) {
|
|
|
8240
8234
|
community.emit("error", err);
|
|
8241
8235
|
});
|
|
8242
8236
|
}
|
|
8237
|
+
function deriveNameAndAddressEdit(community, editOptions) {
|
|
8238
|
+
const hasName = "name" in editOptions;
|
|
8239
|
+
const hasAddress = typeof editOptions.address === "string";
|
|
8240
|
+
if (!hasName && !hasAddress) return editOptions;
|
|
8241
|
+
const addressFromName = hasName ? editOptions.name ?? communityIdentityPublicKey(community) : void 0;
|
|
8242
|
+
if (hasAddress && hasName && editOptions.address !== addressFromName) throw new PKCError("ERR_COMMUNITY_EDIT_NAME_AND_ADDRESS_MISMATCH", {
|
|
8243
|
+
name: editOptions.name,
|
|
8244
|
+
address: editOptions.address,
|
|
8245
|
+
communityAddress: community.address
|
|
8246
|
+
});
|
|
8247
|
+
const address = hasAddress ? editOptions.address : addressFromName;
|
|
8248
|
+
return {
|
|
8249
|
+
...editOptions,
|
|
8250
|
+
address,
|
|
8251
|
+
name: isStringDomain(address) ? address : void 0
|
|
8252
|
+
};
|
|
8253
|
+
}
|
|
8243
8254
|
async function editPropsOnStartedCommunity(community, parsedEditOptions, pagesEdit) {
|
|
8244
8255
|
const log = logger_default("pkc-js:local-community:start:editPropsOnStartedCommunity");
|
|
8245
8256
|
const oldAddress = t$9(community.address);
|
|
@@ -8248,6 +8259,7 @@ async function editPropsOnStartedCommunity(community, parsedEditOptions, pagesEd
|
|
|
8248
8259
|
log(`Attempting to edit community.address from ${oldAddress} to ${parsedEditOptions.address}. We will stop community first`);
|
|
8249
8260
|
await community.stop();
|
|
8250
8261
|
await community._dbHandler.changeDbFilename(oldAddress, parsedEditOptions.address);
|
|
8262
|
+
refreshCommunitiesList(community._pkc);
|
|
8251
8263
|
community.setAddress(parsedEditOptions.address);
|
|
8252
8264
|
await community._dbHandler.initDbIfNeeded();
|
|
8253
8265
|
await community.start();
|
|
@@ -8290,6 +8302,7 @@ async function editPropsOnNotStartedCommunity(community, parsedEditOptions, page
|
|
|
8290
8302
|
await movePostUpdatesFolderToNewAddress(community, community.address, parsedEditOptions.address);
|
|
8291
8303
|
community._dbHandler.destoryConnection();
|
|
8292
8304
|
await community._dbHandler.changeDbFilename(community.address, parsedEditOptions.address);
|
|
8305
|
+
refreshCommunitiesList(community._pkc);
|
|
8293
8306
|
await community._dbHandler.initDbIfNeeded();
|
|
8294
8307
|
community.setAddress(parsedEditOptions.address);
|
|
8295
8308
|
}
|
|
@@ -8321,11 +8334,7 @@ async function edit(community, newCommunityOptions) {
|
|
|
8321
8334
|
dataPath: community._pkc.dataPath
|
|
8322
8335
|
});
|
|
8323
8336
|
}
|
|
8324
|
-
const
|
|
8325
|
-
const editWithDerivedName = typeof parsedEditOptions.address === "string" && isStringDomain(parsedEditOptions.address) ? {
|
|
8326
|
-
...parsedEditOptions,
|
|
8327
|
-
name: parsedEditOptions.address
|
|
8328
|
-
} : parsedEditOptions;
|
|
8337
|
+
const editWithDerivedName = deriveNameAndAddressEdit(community, parseCommunityEditOptionsSchemaWithPKCErrorIfItFails(newCommunityOptions));
|
|
8329
8338
|
const pagesEdit = editWithDerivedName?.settings ? await parsePagesToEdit(community, editWithDerivedName.settings) : void 0;
|
|
8330
8339
|
const newInternalProps = {
|
|
8331
8340
|
...editWithDerivedName.roles ? { roles: await parseRolesToEdit(community, editWithDerivedName.roles) } : void 0,
|
|
@@ -8348,11 +8357,11 @@ async function edit(community, newCommunityOptions) {
|
|
|
8348
8357
|
const EXPORTS_KEY = STORAGE_KEYS[STORAGE_KEYS.EXPORTS];
|
|
8349
8358
|
function defaultExportPathFor(community, exportId) {
|
|
8350
8359
|
if (typeof community._pkc.dataPath !== "string") throw new PKCError("ERR_DATA_PATH_IS_NOT_DEFINED", { communityAddress: community.address });
|
|
8351
|
-
return
|
|
8360
|
+
return Path.join(community._pkc.dataPath, "exports", `${exportId}.sqlite`);
|
|
8352
8361
|
}
|
|
8353
8362
|
function sourceDbPathFor(community) {
|
|
8354
8363
|
if (typeof community._pkc.dataPath !== "string") throw new PKCError("ERR_DATA_PATH_IS_NOT_DEFINED", { communityAddress: community.address });
|
|
8355
|
-
return
|
|
8364
|
+
return Path.join(community._pkc.dataPath, "communities", community.address);
|
|
8356
8365
|
}
|
|
8357
8366
|
async function persistExports(community) {
|
|
8358
8367
|
if (!community._dbHandler) return;
|
|
@@ -8428,9 +8437,9 @@ async function runExportTask(community, exportId, opts) {
|
|
|
8428
8437
|
async function exportCommunityEmbedded(community, options = {}) {
|
|
8429
8438
|
if (options.signal?.aborted) throw options.signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
8430
8439
|
const exportId = v4();
|
|
8431
|
-
const destPath = options.exportPath ?
|
|
8440
|
+
const destPath = options.exportPath ? Path.resolve(options.exportPath) : defaultExportPathFor(community, exportId);
|
|
8432
8441
|
const includePrivateKey = options.includePrivateKey === true;
|
|
8433
|
-
if (
|
|
8442
|
+
if (Path.resolve(destPath) === Path.resolve(sourceDbPathFor(community))) throw new PKCError("ERR_EXPORT_PATH_TARGETS_LIVE_DB", {
|
|
8434
8443
|
communityAddress: community.address,
|
|
8435
8444
|
exportPath: destPath
|
|
8436
8445
|
});
|
|
@@ -8536,6 +8545,13 @@ async function loadAndPruneExportsFromKeyv(community) {
|
|
|
8536
8545
|
//#endregion
|
|
8537
8546
|
//#region dist/node/runtime/node/community/local-community.js
|
|
8538
8547
|
var LocalCommunity = class extends RpcLocalCommunity {
|
|
8548
|
+
get _communityUpdateTrigger() {
|
|
8549
|
+
return this._communityUpdateTriggerValue;
|
|
8550
|
+
}
|
|
8551
|
+
set _communityUpdateTrigger(value) {
|
|
8552
|
+
if (value) this._updateTriggerGeneration++;
|
|
8553
|
+
this._communityUpdateTriggerValue = value;
|
|
8554
|
+
}
|
|
8539
8555
|
constructor(pkc) {
|
|
8540
8556
|
super(pkc);
|
|
8541
8557
|
this.raw = {};
|
|
@@ -8552,7 +8568,8 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8552
8568
|
this._challengeExchangeTtlMs = CHALLENGE_EXCHANGE_TTL_MS;
|
|
8553
8569
|
this._cidsToUnPin = /* @__PURE__ */ new Set();
|
|
8554
8570
|
this._mfsPathsToRemove = /* @__PURE__ */ new Set();
|
|
8555
|
-
this.
|
|
8571
|
+
this._communityUpdateTriggerValue = false;
|
|
8572
|
+
this._updateTriggerGeneration = 0;
|
|
8556
8573
|
this._combinedHashOfPendingCommentsCids = (0, import_sha256.sha256)("");
|
|
8557
8574
|
this._pageSorts = void 0;
|
|
8558
8575
|
this._pageSortFactories = void 0;
|
|
@@ -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-BbJyIuOc.js";
|
|
2
2
|
export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $ as shortifyAddress, An as CommentIpfsSchema, Ar as PKCError, At as ChallengeMessageSchema, Ct as untrackUpdatingComment, Dt as pTimeout, E as isIpfsCid, Er as FailedToFetchCommentUpdateFromGatewaysError, Et as TimeoutError, Fn as CommentUpdateForChallengeVerificationSchema, Fr as setErrorMap, H as rejectWhenCommunityStopsOrAborts, J as replaceXWithY, Jr as stringifyPrimitive, Kr as joinValues, Kt as version_default, Mr as logger_default, Mt as ChallengeRequestMessageSchema, O as isIpns, Ot as ChallengeAnswerMessageSchema, Pt as ChallengeVerificationMessageSchema, Rn as CommentUpdateSchema, S as hideClassPrivateProps, T as isAbortError, Tr as FailedToFetchCommentIpfsFromGatewaysError, Tt as require_sha256, V as rejectWhenAbortSignalFires, Y as resolveWhenPredicateIsTrue, Z as retryKuboIpfsAdd, _r as r, at as waitForUpdateInCommunityInstanceWithErrorAndTimeout, b as getPostUpdateTimestampRange, bt as trackUpdatingComment, dn as CommunityIpfsSchema, dr as n$1, dt as findUpdatingComment, et as shortifyCid, f as doesDomainAddressHaveCapitalLetter, ft as findUpdatingCommunity, gt as refreshTrackedCommentAliases, hr as e$1, ht as listUpdatingCommunities, it as timestamp, jr as messages, l as createAbortError, lr as n$2, mr as e, mt as listUpdatingComments, on as CommunityAnchorSchema, pr as t$1, pt as listStartedCommunities, q as removeUndefinedValuesRecursively, qr as parsedType, rt as throwIfAbortSignalAborted, t as areEquivalentCommunityAddresses, tt as sleepUntilTimeoutOrAbort, u as deepMergeRuntimeFields, ut as findStartedCommunity, w as ipnsNameToIpnsOverPubsubTopic, wr as require_retry, wt as untrackUpdatingCommunity, xn as isStringDomain, yn as PubsubTopicSchema } from "./util-
|
|
3
|
-
import { $ as parseCidStringSchemaWithPKCErrorIfItFails, $t as require_lib$1, A as findCommentInParsedPages, B as InflightFetchManager, Bn as buildRuntimeCommunityFields, Bt as RpcExportCommunityModLogsParamSchema, C as RepliesPages,
|
|
4
|
-
import { s as getHeliaDebugContext } from "./util-
|
|
2
|
+
import { $ as shortifyAddress, An as CommentIpfsSchema, Ar as PKCError, At as ChallengeMessageSchema, Ct as untrackUpdatingComment, Dt as pTimeout, E as isIpfsCid, Er as FailedToFetchCommentUpdateFromGatewaysError, Et as TimeoutError, Fn as CommentUpdateForChallengeVerificationSchema, Fr as setErrorMap, H as rejectWhenCommunityStopsOrAborts, J as replaceXWithY, Jr as stringifyPrimitive, Kr as joinValues, Kt as version_default, Mr as logger_default, Mt as ChallengeRequestMessageSchema, O as isIpns, Ot as ChallengeAnswerMessageSchema, Pt as ChallengeVerificationMessageSchema, Rn as CommentUpdateSchema, S as hideClassPrivateProps, T as isAbortError, Tr as FailedToFetchCommentIpfsFromGatewaysError, Tt as require_sha256, V as rejectWhenAbortSignalFires, Y as resolveWhenPredicateIsTrue, Z as retryKuboIpfsAdd, _r as r, at as waitForUpdateInCommunityInstanceWithErrorAndTimeout, b as getPostUpdateTimestampRange, bt as trackUpdatingComment, dn as CommunityIpfsSchema, dr as n$1, dt as findUpdatingComment, et as shortifyCid, f as doesDomainAddressHaveCapitalLetter, ft as findUpdatingCommunity, gt as refreshTrackedCommentAliases, hr as e$1, ht as listUpdatingCommunities, it as timestamp, jr as messages, l as createAbortError, lr as n$2, mr as e, mt as listUpdatingComments, on as CommunityAnchorSchema, pr as t$1, pt as listStartedCommunities, q as removeUndefinedValuesRecursively, qr as parsedType, rt as throwIfAbortSignalAborted, t as areEquivalentCommunityAddresses, tt as sleepUntilTimeoutOrAbort, u as deepMergeRuntimeFields, ut as findStartedCommunity, w as ipnsNameToIpnsOverPubsubTopic, wr as require_retry, wt as untrackUpdatingCommunity, xn as isStringDomain, yn as PubsubTopicSchema } from "./util-CXxGmK2P.js";
|
|
3
|
+
import { $ as parseCidStringSchemaWithPKCErrorIfItFails, $t as require_lib$1, A as findCommentInParsedPages, Ar as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, B as InflightFetchManager, Bn as buildRuntimeCommunityFields, Bt as RpcExportCommunityModLogsParamSchema, C as RepliesPages, Ct as parseDecryptedChallengeVerification, D as extractCommunityRuntimeFieldsFromParsedPages, Dn as verifyCommentModeration, Dr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, Dt as parseRpcCommentEventWithPKCErrorIfItFails, En as verifyCommentIpfs, Et as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, F as collectCrosspostAuthorsToResolve, Fn as getAuthorNameFromRuntime, Ft as RpcCidParamSchema, G as decodeRpcChallengeAnswerPubsubMsg, Gn as decode, Gt as RpcFetchCidResultSchema, Hn as getCommunityNameFromWire, Ht as RpcExportCommunityParamSchema, It as RpcCommentRepliesPageParamSchema, J as decodeRpcChallengeVerificationPubsubMsg, Jt as RpcPublishedAnchorRecordResultSchema, K as decodeRpcChallengePubsubMsg, Kt as RpcPublishAnchorRecordParamSchema, L as stripNameResolvedFromCrosspost, Ln as normalizeCreatePublicationAuthor, Lt as RpcCommunityIdentifierParamSchema, M as parseRawPages, Mn as verifyVote, Mt as RpcAnchorPublishPreparationResultSchema, N as applyNameResolvedCacheToCrosspost, Nn as buildRuntimeAuthor, Nr as nativeFunctions$2, Nt as RpcAuthorNameParamSchema, O as findCommentInPageInstance, On as verifyCommentPubsubMessage, Or as NAME_RESOLVED_FALSE_TTL_MS, Ot as parseRpcCommentUpdateEventWithPKCErrorIfItFails, P as cloneCrosspostForRuntime, Pn as cleanWireAuthor, Pr as require_undici, Pt as RpcCancelExportParamSchema, Qt as RpcUnsubscribeParamSchema, R as PKCClientsManager, Rt as RpcCommunityPageParamSchema, S as KeyvBetterSqlite3, Sn as verifyChallengeMessage, Sr as n$3, St as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Tn as verifyCommentEdit, Tr as t$4, Tt as parseJsonWithPKCErrorIfFails, Un as getCommunityPublicKeyFromWire, Ut as RpcExportCommunityResultSchema, V as InflightResourceTypes, Vn as getCommunityAddressFromRecord, Vt as RpcExportCommunityModLogsResultSchema, W as PKCTypedEmitter, Wn as normalizeCommunityInputFromCommunity, Wt as RpcFetchCidParamSchema, Xn as getPKCAddressFromPublicKeySync, Xt as RpcSubscriptionIdResultSchema, Yt as RpcResolveAuthorNameResultSchema, Zt as RpcSuccessResultSchema, _r as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, an as encryptEd25519AesGcm, at as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, b as RemoteCommunity, bn as signVote, bt as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, cn as cleanUpBeforePublishing, cr as getDefaultDataPath, ct as parseCommunityAddressWithPKCErrorIfItFails, dn as signChallengeRequest, dr as listCommunitiesSync, dt as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, fr as monitorCommunitiesDirectory, gr as setNativeFunctions$1, gt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, hn as signCommentModeration, ht as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, jn as verifyCommunityEdit, jt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, k as findCommentInPageInstanceRecursively, kn as verifyCommentUpdate, kr as NAME_RESOLVED_TRUE_TTL_MS, kt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, l as pkcJsPageSorts, ln as signChallengeAnswer, m as pkcJsChallenges, mn as signCommentEdit, mt as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as createAnchorIpnsRecord$1, nr as createKuboRpcClient, nt as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, ot as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, pn as signComment, pt as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, q as decodeRpcChallengeRequestPubsubMsg, qn as getBufferedPKCAddressFromPublicKey, qt as RpcPublishChallengeAnswersParamSchema, rn as decryptEd25519AesGcm, rt as parseCommentIpfsSchemaWithPKCErrorIfItFails, st as parseCommentUpdateSchemaWithPKCErrorIfItFails, t as RpcLocalCommunity, tn as createSigner, v as TrackedInstanceRegistry, vr as t$5, wn as verifyChallengeVerification, wr as t$2, wt as parseDecryptedChallengeWithPKCErrorIfItFails, xr as t$3, xt as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, y as LRUCache, yn as signCommunityEdit, yt as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, z as GenericStateClient, zt as RpcEditCommunityParamSchema } from "./rpc-local-community-DMDs0XGh.js";
|
|
4
|
+
import { s as getHeliaDebugContext } from "./util-_DJ6MgmW.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import assert from "assert";
|
|
7
7
|
import fs from "fs";
|
|
@@ -376,6 +376,7 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
376
376
|
super();
|
|
377
377
|
this.raw = {};
|
|
378
378
|
this._community = void 0;
|
|
379
|
+
this._signedWithKnownCommunityFields = void 0;
|
|
379
380
|
this._challengeExchanges = {};
|
|
380
381
|
this._rpcPublishSubscriptionId = void 0;
|
|
381
382
|
this._pkc = pkc;
|
|
@@ -461,10 +462,19 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
461
462
|
}
|
|
462
463
|
async _signPublicationWithKnownCommunityFieldsIfAvailable() {
|
|
463
464
|
if (!this.communityPublicKey || this.raw.pubsubMessageToPublish || !this.raw.unsignedPublicationOptions) return;
|
|
465
|
+
const unsignedOptions = this.raw.unsignedPublicationOptions;
|
|
464
466
|
await this._signPublication({ communityFields: {
|
|
465
467
|
communityPublicKey: this.communityPublicKey,
|
|
466
468
|
...this.communityName ? { communityName: this.communityName } : {}
|
|
467
469
|
} });
|
|
470
|
+
if (this.raw.pubsubMessageToPublish) this._signedWithKnownCommunityFields = {
|
|
471
|
+
message: this.raw.pubsubMessageToPublish,
|
|
472
|
+
unsignedOptions
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
_isSignedWithoutTheLoadedCommunityName() {
|
|
476
|
+
const signed = this._signedWithKnownCommunityFields;
|
|
477
|
+
return Boolean(signed && this.raw.pubsubMessageToPublish === signed.message && this._community?.name && !getCommunityNameFromWire(signed.message));
|
|
468
478
|
}
|
|
469
479
|
async _validateSignatureHook() {}
|
|
470
480
|
async _verifyDecryptedChallengeVerificationAndUpdateCommentProps(decryptedVerification) {
|
|
@@ -1280,6 +1290,12 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
1280
1290
|
this._setStateWithEmission("publishing");
|
|
1281
1291
|
await this._initCommunity();
|
|
1282
1292
|
if (this.raw.unsignedPublicationOptions && !this.raw.pubsubMessageToPublish) await this._signPublicationWithCommunityFields();
|
|
1293
|
+
else if (this._isSignedWithoutTheLoadedCommunityName()) {
|
|
1294
|
+
log(`Re-signing the ${this.getType()} with the name of community ${this._community.name}; it was created with only the community's key`);
|
|
1295
|
+
this.raw.unsignedPublicationOptions = this._signedWithKnownCommunityFields.unsignedOptions;
|
|
1296
|
+
this._signedWithKnownCommunityFields = void 0;
|
|
1297
|
+
await this._signPublicationWithCommunityFields();
|
|
1298
|
+
}
|
|
1283
1299
|
await this._validateSignatureHook();
|
|
1284
1300
|
if (this._pkc._pkcRpcClient) return this._publishWithRpc();
|
|
1285
1301
|
const options = { acceptedChallengeTypes: [] };
|
|
@@ -8370,7 +8386,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
8370
8386
|
this.clients.libp2pJsClients = {};
|
|
8371
8387
|
if (!this.libp2pJsClientsOptions) return;
|
|
8372
8388
|
if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
|
|
8373
|
-
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-
|
|
8389
|
+
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-Dk9JTeUn.js");
|
|
8374
8390
|
for (const clientOptions of this.libp2pJsClientsOptions) {
|
|
8375
8391
|
const heliaNode = await createLibp2pJsClientOrUseExistingOne({
|
|
8376
8392
|
...clientOptions,
|
|
@@ -8649,7 +8665,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
8649
8665
|
const log = logger_default("pkc-js:pkc:createLocalCommunity");
|
|
8650
8666
|
log.trace("Received community options to create a local community instance:", options);
|
|
8651
8667
|
if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
|
|
8652
|
-
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-
|
|
8668
|
+
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-BkZDlh4z.js");
|
|
8653
8669
|
const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
|
|
8654
8670
|
const community = new LocalCommunity(this);
|
|
8655
8671
|
if (isLocalCommunity) {
|