@pkcprotocol/pkc-js 0.0.155 → 0.0.157
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/clients/base-client-manager.js +10 -1
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/clients/shared-pubsub-topic-list.d.ts +14 -0
- package/dist/browser/clients/shared-pubsub-topic-list.js +61 -0
- package/dist/browser/clients/shared-pubsub-topic-list.js.map +1 -0
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/runtime/node/community/db-handler.d.ts +2 -0
- package/dist/browser/runtime/node/community/db-handler.js +23 -9
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.d.ts +6 -0
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +49 -10
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +102 -61
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/pubsub.js +11 -4
- package/dist/browser/runtime/node/community/local-community/pubsub.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.d.ts +22 -4
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.js +45 -9
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community.js +5 -0
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/event-loop-watch.d.ts +13 -0
- package/dist/browser/runtime/node/event-loop-watch.js +58 -0
- package/dist/browser/runtime/node/event-loop-watch.js.map +1 -0
- package/dist/bundled/bundle-manifest.json +37 -34
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-Oiy9zYBR.js → helia-for-pkc-BT2UmDem.js} +2 -2
- package/dist/bundled/chunks/{local-community-BlJfnxcr.js → local-community-BexngGU7.js} +1 -1
- package/dist/bundled/chunks/{local-community-PMJTbzmG.js → local-community-oqjqTa9T.js} +221 -71
- package/dist/bundled/chunks/{node-Bf1DjAFe.js → node-CvXtQ-4A.js} +5 -5
- package/dist/bundled/chunks/{page-sort-scoring-DVAvzj4W.js → page-sort-scoring-VN_GGInQ.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-BqJ_olvR.js → rpc-local-community-BjIHRbYy.js} +51 -4
- package/dist/bundled/chunks/{util-BpiQT2hV.js → util-Bu3ItQsN.js} +1 -1
- package/dist/bundled/chunks/{util-N_HlPQHv.js → util-DDsWXOtP.js} +1 -1
- package/dist/bundled/chunks/{validate-package-factories-DoC8xXMu.js → validate-package-factories-CmJt781W.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 +10 -1
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/clients/shared-pubsub-topic-list.d.ts +14 -0
- package/dist/node/clients/shared-pubsub-topic-list.js +61 -0
- package/dist/node/clients/shared-pubsub-topic-list.js.map +1 -0
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/runtime/node/community/db-handler.d.ts +2 -0
- package/dist/node/runtime/node/community/db-handler.js +23 -9
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.d.ts +6 -0
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +49 -10
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +102 -61
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/pubsub.js +11 -4
- package/dist/node/runtime/node/community/local-community/pubsub.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.d.ts +22 -4
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.js +45 -9
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community.js +5 -0
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/event-loop-watch.d.ts +13 -0
- package/dist/node/runtime/node/event-loop-watch.js +58 -0
- package/dist/node/runtime/node/event-loop-watch.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { i as __toESM } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $n as CommentEditsTableRowSchema, Ar as t$4, At as ChallengeAnswerMessageSchema, B as pubsubTopicToDhtKey, Br as messages, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Cr as e$1, Ct as trackUpdatingCommunity, Dr as t$3, Dt as require_sha256, En as VotePubsubReservedFields, Er as r$1, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeBlocksFromKuboNode, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, J as removeNullUndefinedValues, Jt as version_default, K as removeMfsFilesSafely, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, Nr as require_retry, On as VoteTablesRowSchema, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Q as retryKuboBlockPutPinAndProvidePubsubTopic, Sr as t$6, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Vn as CommentUpdateTableRowSchema, Vr as logger_default, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Zn as CommentEditReservedFields, _ as genToArray, b as getIpnsRecordInLocalKuboNode, br as n$2, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeys, dt as findStartedCommunity, et as retryKuboIpfsAddAndProvide, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as statMfsPathSafely, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as withSortedKeysDeep, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, o as calculateUnixFsDagSizeCidV0, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, ri as ZodError, rt as sleepUntilTimeoutOrAbort, s as contentContainsMarkdownAudio, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$3, wr as e, wt as untrackStartedCommunity, xr as t$5, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$7, zn as CommentUpdateSchema, zr as PKCError, zt as DecryptedChallengeRequestPublicationSchema } from "./util-
|
|
3
|
-
import { $ as
|
|
4
|
-
import { a as scorePageCommentsWithFile, i as partitionPageCommentsForSort, n as filterRepliesForPageSort, o as stripRepliesFromPageComment, r as orderPageCommentsByScore, t as createDescendantsLookup } from "./page-sort-scoring-
|
|
2
|
+
import { $n as CommentEditsTableRowSchema, Ar as t$4, At as ChallengeAnswerMessageSchema, B as pubsubTopicToDhtKey, Br as messages, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Cr as e$1, Ct as trackUpdatingCommunity, Dr as t$3, Dt as require_sha256, En as VotePubsubReservedFields, Er as r$1, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeBlocksFromKuboNode, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, J as removeNullUndefinedValues, Jt as version_default, K as removeMfsFilesSafely, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, Nr as require_retry, On as VoteTablesRowSchema, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Q as retryKuboBlockPutPinAndProvidePubsubTopic, Sr as t$6, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Vn as CommentUpdateTableRowSchema, Vr as logger_default, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Zn as CommentEditReservedFields, _ as genToArray, b as getIpnsRecordInLocalKuboNode, br as n$2, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeys, dt as findStartedCommunity, et as retryKuboIpfsAddAndProvide, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as statMfsPathSafely, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as withSortedKeysDeep, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, o as calculateUnixFsDagSizeCidV0, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, ri as ZodError, rt as sleepUntilTimeoutOrAbort, s as contentContainsMarkdownAudio, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$3, wr as e, wt as untrackStartedCommunity, xr as t$5, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$7, zn as CommentUpdateSchema, zr as PKCError, zt as DecryptedChallengeRequestPublicationSchema } from "./util-DDsWXOtP.js";
|
|
3
|
+
import { $ as coerceSchemaRowJson, $n as getAuthorNameFromWire, $r as n$5, Ar as getDefaultCommunityDbConfig, Bn as verifyCommentPubsubMessage, Br as resolveDbPostsCidRefs, Cn as signChallengeVerification, Dn as signCommentUpdate, Dr as deriveDbReplies, Er as deriveDbPosts, Et as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Fn as verifyChallengeRequest, Gn as verifyVote, Gr as markCommunityDbAsBeingWritten, H as listSubscribedPubsubTopicsShared, Hn as verifyCommunity, K as pLimit, Kr as findCommunitiesEntry, Ln as verifyCommentEdit, Lr as moveCommunityDbToDeletedDirectory, Mr as getThumbnailPropsOfLink, N as MAX_PAGE_SIZE_BYTES, Nn as verifyChallengeAnswer, Nr as importSignerIntoKuboNode, On as signCommentUpdateForChallengeVerification, Q as coerceSchemaRowBoolean, Qr as t$8, Rn as verifyCommentIpfs, S as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, Sr as calculateInlineRepliesBudget, Tn as signCommentEdit, Tr as deriveCommentIpfsFromCommentTableRow, Un as verifyCommunityEdit, Ur as unregisterLocalCommunity, V as SHARED_KUBO_READ_TIMEOUT_MS, Vn as verifyCommentUpdate, Wr as getCommunitiesRegistry, Xn as buildRuntimeAuthor, Xr as t$11, Yr as t$10, Zn as cleanWireAuthor, Zr as r$2, _ as createAuthorIdentityMatcher, _n as encryptEd25519AesGcmPublicKeyBuffer, _r as getPKCAddressFromPublicKeySync, a as generatePagesReportingFailedSorts, ar as crosspostChainDepthUpTo, b as KeyvBetterSqlite3, br as backupCommunityDb, c as resolvePageSortsOrThrow, ci as require_lodash_merge, d as getChallengeVerification, dn as SignerWithPublicKeyAddress, ei as n$4, et as collectSchemaRowCoercions, f as getCommunityChallengeFromCommunityChallengeSettings, fr as decode, g as authorNameResolveFailureReason, gr as getPKCAddressFromPublicKey, h as authorIdentityMatcherForRequest, hn as decryptEd25519AesGcmPublicKeyBuffer, hr as getIpfsKeyFromPrivateKey, ht as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, i as derivePublicPageSorts, j as iterateOverPageCidsToFindAllCids, kn as signCommunity, kr as forgetCommunityThatFailedToBeDeleted, kt as parseJsonWithPKCErrorIfFails, ln as verifyAuthorWalletEntry, lr as getCommunityNameFromWire, m as pkcJsChallenges, ni as t$9, o as loadPageSortsForStartedCommunity, or as effectiveMaxCrosspostDepth, p as loadChallengeFileFromCommunityChallengeSettings, pr as encode, pt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, qn as forbiddenKeysOf, r as computePageSortsFingerprint, s as lookupPageSortFactories, si as STORAGE_KEYS, t as RpcLocalCommunity, tr as stringify, tt as createSchemaRowParser, u as deriveCommunityChallengesOrThrow, ur as getCommunityPublicKeyFromWire, v as TrackedInstanceRegistry, vn as _validateSignatureOfPKCRecord, vr as getPublicKeyFromPrivateKey, w as TIMEFRAMES_TO_SECONDS, wn as signComment, wr as deleteOldCommunityInWindows, xn as signChallengeMessage, xr as calculateExpectedSignatureSize, y as LRUCache, yn as cleanUpBeforePublishing, yr as BackupAbortError, zn as verifyCommentModeration, zr as removeFileRetryingWhileBusy } from "./rpc-local-community-BjIHRbYy.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-VN_GGInQ.js";
|
|
5
5
|
import { c as prepare, n as decode$1, r as encode$1 } from "./src-BSYNGtIQ.js";
|
|
6
6
|
import { t as UnixFS } from "./src-CAvdjq_i.js";
|
|
7
|
+
import { monitorEventLoopDelay } from "node:perf_hooks";
|
|
7
8
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
9
|
import path from "node:path";
|
|
9
10
|
import os from "os";
|
|
@@ -1457,9 +1458,14 @@ function deriveAliasOriginalAuthorSignerAddress(originalAuthorPublicKey) {
|
|
|
1457
1458
|
}
|
|
1458
1459
|
}
|
|
1459
1460
|
var DbHandler = class {
|
|
1461
|
+
_notePublicationWrite() {
|
|
1462
|
+
this._publicationWriteGeneration++;
|
|
1463
|
+
if (this._community && this._readBackWithoutStoringDepth === 0) this._community._communityUpdateTrigger = true;
|
|
1464
|
+
}
|
|
1460
1465
|
constructor(community) {
|
|
1461
1466
|
this._transactionGeneration = 0;
|
|
1462
1467
|
this._publicationWriteGeneration = 0;
|
|
1468
|
+
this._readBackWithoutStoringDepth = 0;
|
|
1463
1469
|
this._startLockAddress = void 0;
|
|
1464
1470
|
this._community = community;
|
|
1465
1471
|
this._transactionDepth = 0;
|
|
@@ -1597,10 +1603,13 @@ var DbHandler = class {
|
|
|
1597
1603
|
}
|
|
1598
1604
|
readBackWithoutStoring(opts) {
|
|
1599
1605
|
this._db.exec("SAVEPOINT read_back_without_storing");
|
|
1606
|
+
this._readBackWithoutStoringDepth++;
|
|
1600
1607
|
try {
|
|
1601
1608
|
opts.write();
|
|
1602
1609
|
return opts.read();
|
|
1603
1610
|
} finally {
|
|
1611
|
+
this._readBackWithoutStoringDepth--;
|
|
1612
|
+
this._publicationWriteGeneration++;
|
|
1604
1613
|
this._db.exec("ROLLBACK TO read_back_without_storing");
|
|
1605
1614
|
this._db.exec("RELEASE read_back_without_storing");
|
|
1606
1615
|
}
|
|
@@ -2237,15 +2246,15 @@ var DbHandler = class {
|
|
|
2237
2246
|
}
|
|
2238
2247
|
}
|
|
2239
2248
|
deleteVote(authorSignerAddress, commentCid) {
|
|
2240
|
-
this.
|
|
2249
|
+
this._notePublicationWrite();
|
|
2241
2250
|
this._db.prepare(`DELETE FROM ${TABLES.VOTES} WHERE commentCid = ? AND authorSignerAddress = ?`).run(commentCid, authorSignerAddress);
|
|
2242
2251
|
}
|
|
2243
2252
|
_deleteCommentEditRow(rowid) {
|
|
2244
|
-
this.
|
|
2253
|
+
this._notePublicationWrite();
|
|
2245
2254
|
return this._db.prepare(`DELETE FROM ${TABLES.COMMENT_EDITS} WHERE rowid = ?`).run(rowid).changes > 0;
|
|
2246
2255
|
}
|
|
2247
2256
|
insertVotes(votes) {
|
|
2248
|
-
this.
|
|
2257
|
+
this._notePublicationWrite();
|
|
2249
2258
|
if (votes.length === 0) return;
|
|
2250
2259
|
const processedVotes = this._processRecordsForDbBeforeInsert(votes);
|
|
2251
2260
|
const columnNames = this._getColumnNames(TABLES.VOTES);
|
|
@@ -2269,7 +2278,7 @@ var DbHandler = class {
|
|
|
2269
2278
|
})(processedVotes);
|
|
2270
2279
|
}
|
|
2271
2280
|
insertComments(comments) {
|
|
2272
|
-
this.
|
|
2281
|
+
this._notePublicationWrite();
|
|
2273
2282
|
if (comments.length === 0) return;
|
|
2274
2283
|
const processedComments = this._processRecordsForDbBeforeInsert(comments);
|
|
2275
2284
|
const columnNames = this._getColumnNames(TABLES.COMMENTS);
|
|
@@ -2290,7 +2299,7 @@ var DbHandler = class {
|
|
|
2290
2299
|
})(processedComments);
|
|
2291
2300
|
}
|
|
2292
2301
|
insertPseudonymityAliases(aliases) {
|
|
2293
|
-
this.
|
|
2302
|
+
this._notePublicationWrite();
|
|
2294
2303
|
if (aliases.length === 0) return;
|
|
2295
2304
|
const processedAliases = this._processRecordsForDbBeforeInsert(aliases).map((alias) => ({
|
|
2296
2305
|
...alias,
|
|
@@ -2336,7 +2345,7 @@ var DbHandler = class {
|
|
|
2336
2345
|
})(processedUpdates);
|
|
2337
2346
|
}
|
|
2338
2347
|
insertCommentModerations(moderations) {
|
|
2339
|
-
this.
|
|
2348
|
+
this._notePublicationWrite();
|
|
2340
2349
|
if (moderations.length === 0) return;
|
|
2341
2350
|
const processedModerations = this._processRecordsForDbBeforeInsert(moderations);
|
|
2342
2351
|
const columnNames = this._getColumnNames(TABLES.COMMENT_MODERATIONS);
|
|
@@ -2357,7 +2366,7 @@ var DbHandler = class {
|
|
|
2357
2366
|
})(processedModerations);
|
|
2358
2367
|
}
|
|
2359
2368
|
insertCommentEdits(edits) {
|
|
2360
|
-
this.
|
|
2369
|
+
this._notePublicationWrite();
|
|
2361
2370
|
if (edits.length === 0) return;
|
|
2362
2371
|
const processedEdits = this._processRecordsForDbBeforeInsert(edits);
|
|
2363
2372
|
const columnNames = this._getColumnNames(TABLES.COMMENT_EDITS);
|
|
@@ -3157,7 +3166,7 @@ var DbHandler = class {
|
|
|
3157
3166
|
]);
|
|
3158
3167
|
}
|
|
3159
3168
|
removeCommentFromPendingApproval(comment) {
|
|
3160
|
-
this.
|
|
3169
|
+
this._notePublicationWrite();
|
|
3161
3170
|
const log = logger_default("pkc-js:local-community:db-handler:removeCommentFromPendingApproval");
|
|
3162
3171
|
const res = this._db.prepare(`UPDATE ${TABLES.COMMENTS} SET pendingApproval = 0 WHERE cid = ?`).run(comment.cid);
|
|
3163
3172
|
log.trace(`Removed pendingApproval for cid=${comment.cid}, changes=${res.changes}`);
|
|
@@ -3873,7 +3882,7 @@ var DbHandler = class {
|
|
|
3873
3882
|
return allCids;
|
|
3874
3883
|
}
|
|
3875
3884
|
purgeComment(cid, isNestedCall = false) {
|
|
3876
|
-
this.
|
|
3885
|
+
this._notePublicationWrite();
|
|
3877
3886
|
const log = logger_default("pkc-js:local-community:db-handler:purgeComment");
|
|
3878
3887
|
const purgedRecords = [];
|
|
3879
3888
|
if (!isNestedCall) this.createTransaction();
|
|
@@ -6523,22 +6532,26 @@ async function storePublication({ community, request, pendingApproval, challenge
|
|
|
6523
6532
|
}
|
|
6524
6533
|
//#endregion
|
|
6525
6534
|
//#region dist/node/runtime/node/community/local-community/pubsub.js
|
|
6535
|
+
const SHARED_TOPIC_LIST_MAX_AGE_AS_FRACTION_OF_PUBLISH_INTERVAL = 1 / 4;
|
|
6526
6536
|
async function listenToIncomingRequests(community) {
|
|
6527
6537
|
const log = logger_default("pkc-js:local-community:sync:_listenToIncomingRequests");
|
|
6528
6538
|
const topic = challengeExchangePubsubTopic(community);
|
|
6529
6539
|
const pubsubClient = topic ? community._clientsManager.getDefaultKuboPubsubClient() : community._clientsManager.getDefaultKuboPubsubClientIfAny();
|
|
6530
6540
|
if (!pubsubClient) return;
|
|
6531
|
-
const subscribedTopics = await
|
|
6541
|
+
const subscribedTopics = await listSubscribedPubsubTopicsShared({
|
|
6542
|
+
client: pubsubClient._client,
|
|
6543
|
+
maxAgeMs: community._pkc.publishInterval * SHARED_TOPIC_LIST_MAX_AGE_AS_FRACTION_OF_PUBLISH_INTERVAL
|
|
6544
|
+
});
|
|
6532
6545
|
const staleTopic = community._subscribedChallengePubsubTopic;
|
|
6533
6546
|
const unsubscribeStaleTopicIfNeeded = async (currentTopic) => {
|
|
6534
6547
|
if (!staleTopic || staleTopic === currentTopic) return;
|
|
6535
|
-
if (subscribedTopics.
|
|
6548
|
+
if (subscribedTopics.has(staleTopic)) await community._clientsManager.pubsubUnsubscribe(staleTopic, community.handleChallengeExchange);
|
|
6536
6549
|
community._subscribedChallengePubsubTopic = void 0;
|
|
6537
6550
|
log(`Stopped listening on the previous challenge exchange pubsub topic (${staleTopic})`);
|
|
6538
6551
|
};
|
|
6539
6552
|
if (!topic) {
|
|
6540
6553
|
const disabledTopic = communityChallengePubsubTopic(community);
|
|
6541
|
-
if (disabledTopic && subscribedTopics.
|
|
6554
|
+
if (disabledTopic && subscribedTopics.has(disabledTopic)) {
|
|
6542
6555
|
await community._clientsManager.pubsubUnsubscribe(disabledTopic, community.handleChallengeExchange);
|
|
6543
6556
|
if (community._subscribedChallengePubsubTopic === disabledTopic) community._subscribedChallengePubsubTopic = void 0;
|
|
6544
6557
|
log(`Challenge exchange is disabled, unsubscribed from pubsub topic (${disabledTopic})`);
|
|
@@ -6547,7 +6560,7 @@ async function listenToIncomingRequests(community) {
|
|
|
6547
6560
|
return;
|
|
6548
6561
|
}
|
|
6549
6562
|
await unsubscribeStaleTopicIfNeeded(topic);
|
|
6550
|
-
if (!subscribedTopics.
|
|
6563
|
+
if (!subscribedTopics.has(topic)) {
|
|
6551
6564
|
await community._clientsManager.pubsubUnsubscribe(topic, community.handleChallengeExchange);
|
|
6552
6565
|
await community._clientsManager.pubsubSubscribe(topic, community.handleChallengeExchange);
|
|
6553
6566
|
community._clientsManager.updateKuboRpcPubsubState("waiting-challenge-requests", pubsubClient.url);
|
|
@@ -6672,8 +6685,12 @@ async function calculateNewPostUpdates(community) {
|
|
|
6672
6685
|
if (e(postUpdates)) return void 0;
|
|
6673
6686
|
return postUpdates;
|
|
6674
6687
|
}
|
|
6688
|
+
const MAX_SECONDS_BETWEEN_COMMUNITY_RECORDS = 900;
|
|
6689
|
+
function msUntilLastPublishIsTooOld(community) {
|
|
6690
|
+
return ((community.updatedAt || 0) + MAX_SECONDS_BETWEEN_COMMUNITY_RECORDS) * 1e3 + 500 - Date.now();
|
|
6691
|
+
}
|
|
6675
6692
|
function calculateLatestUpdateTrigger(community) {
|
|
6676
|
-
const lastPublishTooOld = (community.updatedAt || 0) < timestamp() -
|
|
6693
|
+
const lastPublishTooOld = (community.updatedAt || 0) < timestamp() - MAX_SECONDS_BETWEEN_COMMUNITY_RECORDS;
|
|
6677
6694
|
const lastPostCidChanged = community.lastPostCid !== community._dbHandler.queryLatestPostCid()?.cid;
|
|
6678
6695
|
const lastCommentCidChanged = community.lastCommentCid !== community._dbHandler.queryLatestCommentCid()?.cid;
|
|
6679
6696
|
if (!community._communityUpdateTrigger && (lastPublishTooOld || community._pendingEditProps.length > 0 || community._blocksToRm.length > 0 || lastCommentCidChanged || lastPostCidChanged)) community._communityUpdateTrigger = true;
|
|
@@ -6916,23 +6933,58 @@ async function updateCommunityIpnsIfNeeded(community, cidsUpdatedInThisCycle) {
|
|
|
6916
6933
|
throw e;
|
|
6917
6934
|
}
|
|
6918
6935
|
}
|
|
6936
|
+
function slowCycleReport({ cycleMs, slowAfterMs, phasesMs }) {
|
|
6937
|
+
if (cycleMs <= slowAfterMs) return void 0;
|
|
6938
|
+
const phases = Object.entries(phasesMs).filter(([, ms]) => ms > 0).sort(([, a], [, b]) => b - a).map(([phase, ms]) => `${phase} ${ms}ms`);
|
|
6939
|
+
return `took ${Math.round(cycleMs)}ms, longer than the publish interval of ${slowAfterMs}ms: ${phases.join(", ")}`;
|
|
6940
|
+
}
|
|
6941
|
+
function reportCycleIfSlow({ community, cycleMs, phasesMs, log }) {
|
|
6942
|
+
const report = slowCycleReport({
|
|
6943
|
+
cycleMs,
|
|
6944
|
+
slowAfterMs: community._pkc.publishInterval,
|
|
6945
|
+
phasesMs
|
|
6946
|
+
});
|
|
6947
|
+
if (report) log.error(`A publish cycle of community`, community.address, report);
|
|
6948
|
+
}
|
|
6919
6949
|
async function syncIpnsWithDb(community) {
|
|
6920
6950
|
const log = logger_default("pkc-js:local-community:sync");
|
|
6921
6951
|
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
6952
|
+
const cycleStartedAtMs = performance.now();
|
|
6953
|
+
const phasesMs = {};
|
|
6954
|
+
const timed = async (phase, run) => {
|
|
6955
|
+
const phaseStartedAtMs = performance.now();
|
|
6956
|
+
try {
|
|
6957
|
+
return await run();
|
|
6958
|
+
} finally {
|
|
6959
|
+
phasesMs[phase] = Math.round(performance.now() - phaseStartedAtMs);
|
|
6960
|
+
}
|
|
6961
|
+
};
|
|
6922
6962
|
try {
|
|
6923
|
-
await community._listenToIncomingRequests();
|
|
6924
|
-
await providePubsubTopicRoutingCidsIfNeeded(community);
|
|
6925
|
-
await adjustPostUpdatesBucketsIfNeeded(community);
|
|
6963
|
+
await timed("listenToIncomingRequests", () => community._listenToIncomingRequests());
|
|
6964
|
+
await timed("providePubsubTopicRoutingCids", () => providePubsubTopicRoutingCidsIfNeeded(community));
|
|
6965
|
+
await timed("adjustPostUpdatesBuckets", () => adjustPostUpdatesBucketsIfNeeded(community));
|
|
6926
6966
|
community._setStartedStateWithEmission("publishing-ipns");
|
|
6927
6967
|
community._clientsManager.updateKuboRpcState("publishing-ipns", kuboRpc.url);
|
|
6928
|
-
await purgeDisapprovedCommentsOlderThan(community);
|
|
6929
|
-
await syncWithRegistries(community);
|
|
6930
|
-
const cidsUpdatedInThisCycle = await updateCommentsAndWritePostUpdates(community);
|
|
6931
|
-
if (community._mfsPathsToRemove.size > 0) await rmUnneededMfsPaths(community);
|
|
6968
|
+
await timed("purgeDisapprovedComments", () => purgeDisapprovedCommentsOlderThan(community));
|
|
6969
|
+
await timed("syncWithRegistries", () => syncWithRegistries(community));
|
|
6970
|
+
const cidsUpdatedInThisCycle = await timed("updateCommentsAndWritePostUpdates", () => updateCommentsAndWritePostUpdates(community));
|
|
6971
|
+
if (community._mfsPathsToRemove.size > 0) await timed("rmUnneededMfsPaths", () => rmUnneededMfsPaths(community));
|
|
6932
6972
|
requireCommunityUpdateIfModQueueChanged(community);
|
|
6933
|
-
await updateCommunityIpnsIfNeeded(community, cidsUpdatedInThisCycle);
|
|
6934
|
-
await cleanUpIpfsRepoIfDue(community);
|
|
6973
|
+
await timed("updateCommunityIpns", () => updateCommunityIpnsIfNeeded(community, cidsUpdatedInThisCycle));
|
|
6974
|
+
await timed("cleanUpIpfsRepo", () => cleanUpIpfsRepoIfDue(community));
|
|
6975
|
+
reportCycleIfSlow({
|
|
6976
|
+
community,
|
|
6977
|
+
cycleMs: performance.now() - cycleStartedAtMs,
|
|
6978
|
+
phasesMs,
|
|
6979
|
+
log
|
|
6980
|
+
});
|
|
6935
6981
|
} catch (e) {
|
|
6982
|
+
reportCycleIfSlow({
|
|
6983
|
+
community,
|
|
6984
|
+
cycleMs: performance.now() - cycleStartedAtMs,
|
|
6985
|
+
phasesMs,
|
|
6986
|
+
log
|
|
6987
|
+
});
|
|
6936
6988
|
e.details = {
|
|
6937
6989
|
...e.details,
|
|
6938
6990
|
communityAddress: community.address
|
|
@@ -6944,6 +6996,51 @@ async function syncIpnsWithDb(community) {
|
|
|
6944
6996
|
throw e;
|
|
6945
6997
|
}
|
|
6946
6998
|
}
|
|
6999
|
+
const EVENT_LOOP_CHECK_PERIOD_MS = 1e4;
|
|
7000
|
+
const EVENT_LOOP_DELAY_RESOLUTION_MS = 20;
|
|
7001
|
+
let watch$1;
|
|
7002
|
+
function eventLoopDelayToReport({ maxNs, p99Ns, resolutionMs = EVENT_LOOP_DELAY_RESOLUTION_MS, reportMs = 200 }) {
|
|
7003
|
+
const maxLateMs = Math.round(maxNs / 1e6 - resolutionMs);
|
|
7004
|
+
if (maxLateMs < reportMs) return void 0;
|
|
7005
|
+
return {
|
|
7006
|
+
maxLateMs,
|
|
7007
|
+
p99LateMs: Math.max(0, Math.round(p99Ns / 1e6 - resolutionMs))
|
|
7008
|
+
};
|
|
7009
|
+
}
|
|
7010
|
+
function holdEventLoopWatch() {
|
|
7011
|
+
if (!watch$1) {
|
|
7012
|
+
const log = logger_default("pkc-js:event-loop-watch");
|
|
7013
|
+
const histogram = monitorEventLoopDelay({ resolution: EVENT_LOOP_DELAY_RESOLUTION_MS });
|
|
7014
|
+
histogram.enable();
|
|
7015
|
+
const checkTimer = setInterval(() => {
|
|
7016
|
+
const report = eventLoopDelayToReport({
|
|
7017
|
+
maxNs: histogram.max,
|
|
7018
|
+
p99Ns: histogram.percentile(99)
|
|
7019
|
+
});
|
|
7020
|
+
histogram.reset();
|
|
7021
|
+
if (report) log.error(`The main thread was blocked for up to ${report.maxLateMs}ms in the last ${EVENT_LOOP_CHECK_PERIOD_MS / 1e3}s (99% of timers were at most ${report.p99LateMs}ms late). Everything this process does waited that long.`);
|
|
7022
|
+
}, EVENT_LOOP_CHECK_PERIOD_MS);
|
|
7023
|
+
checkTimer.unref();
|
|
7024
|
+
watch$1 = {
|
|
7025
|
+
histogram,
|
|
7026
|
+
checkTimer,
|
|
7027
|
+
holders: 0
|
|
7028
|
+
};
|
|
7029
|
+
}
|
|
7030
|
+
watch$1.holders++;
|
|
7031
|
+
let released = false;
|
|
7032
|
+
return () => {
|
|
7033
|
+
if (released || !watch$1) return;
|
|
7034
|
+
released = true;
|
|
7035
|
+
if (--watch$1.holders > 0) return;
|
|
7036
|
+
clearInterval(watch$1.checkTimer);
|
|
7037
|
+
watch$1.histogram.disable();
|
|
7038
|
+
watch$1 = void 0;
|
|
7039
|
+
};
|
|
7040
|
+
}
|
|
7041
|
+
//#endregion
|
|
7042
|
+
//#region dist/node/runtime/node/community/local-community/reprovide-on-address-change.js
|
|
7043
|
+
const ADDRESS_REPROVIDE_POLL_INTERVAL_MS = 60 * 1e3;
|
|
6947
7044
|
function normalizeSelfAddrsForProvider(addrs, peerId) {
|
|
6948
7045
|
const suffix = `/p2p/${peerId}`;
|
|
6949
7046
|
return n$3(addrs.map((addr) => addr.endsWith(suffix) ? addr.slice(0, -suffix.length) : addr));
|
|
@@ -6951,12 +7048,34 @@ function normalizeSelfAddrsForProvider(addrs, peerId) {
|
|
|
6951
7048
|
function isBrowserDialableAddr(addr) {
|
|
6952
7049
|
return addr.includes("/webrtc") || addr.includes("/ws") || addr.includes("/webtransport") && addr.includes("/certhash/");
|
|
6953
7050
|
}
|
|
6954
|
-
async function getBrowserDialableSelfAddrs(client) {
|
|
6955
|
-
const idRes = await client.id();
|
|
7051
|
+
async function getBrowserDialableSelfAddrs(client, options) {
|
|
7052
|
+
const idRes = await client.id(options);
|
|
6956
7053
|
const peerId = idRes.id.toString();
|
|
6957
|
-
const swarmListeningAddresses = (await client.swarm.addrs()).filter((swarmAddr) => swarmAddr.id.toString() === peerId);
|
|
7054
|
+
const swarmListeningAddresses = (await client.swarm.addrs(options)).filter((swarmAddr) => swarmAddr.id.toString() === peerId);
|
|
6958
7055
|
return n$3(normalizeSelfAddrsForProvider([...idRes.addresses.map((addr) => addr.toString()), ...n$5(swarmListeningAddresses.map((swarmAddr) => swarmAddr.addrs.map((addr) => addr.toString())))], peerId).filter(isBrowserDialableAddr)).sort();
|
|
6959
7056
|
}
|
|
7057
|
+
const sharedSelfAddrsByClient = /* @__PURE__ */ new WeakMap();
|
|
7058
|
+
async function getBrowserDialableSelfAddrsShared({ client, maxAgeMs }) {
|
|
7059
|
+
let shared = sharedSelfAddrsByClient.get(client);
|
|
7060
|
+
if (!shared) {
|
|
7061
|
+
shared = {};
|
|
7062
|
+
sharedSelfAddrsByClient.set(client, shared);
|
|
7063
|
+
}
|
|
7064
|
+
const sharedOfClient = shared;
|
|
7065
|
+
if (sharedOfClient.stored && Date.now() - sharedOfClient.stored.readAtMs < maxAgeMs) return sharedOfClient.stored;
|
|
7066
|
+
if (sharedOfClient.inFlight) return sharedOfClient.inFlight;
|
|
7067
|
+
const inFlight = getBrowserDialableSelfAddrs(client, { timeout: SHARED_KUBO_READ_TIMEOUT_MS }).then((addrs) => {
|
|
7068
|
+
sharedOfClient.stored = {
|
|
7069
|
+
addrs,
|
|
7070
|
+
readAtMs: Date.now()
|
|
7071
|
+
};
|
|
7072
|
+
return sharedOfClient.stored;
|
|
7073
|
+
}).finally(() => {
|
|
7074
|
+
if (sharedOfClient.inFlight === inFlight) sharedOfClient.inFlight = void 0;
|
|
7075
|
+
});
|
|
7076
|
+
sharedOfClient.inFlight = inFlight;
|
|
7077
|
+
return inFlight;
|
|
7078
|
+
}
|
|
6960
7079
|
function connectionCriticalCids(community) {
|
|
6961
7080
|
return n$3([community.pubsubTopicRoutingCid, community.ipnsPubsubTopicRoutingCid].filter((cid) => typeof cid === "string"));
|
|
6962
7081
|
}
|
|
@@ -6968,23 +7087,31 @@ function connectionCriticalCids(community) {
|
|
|
6968
7087
|
* The first observation only establishes a baseline (start() already force-provides these CIDs with fresh
|
|
6969
7088
|
* addresses via providePubsubTopicRoutingCidsIfNeeded); subsequent changes trigger a re-provide.
|
|
6970
7089
|
*/
|
|
6971
|
-
async function reprovideConnectionCidsIfBrowserAddrsChanged(community) {
|
|
7090
|
+
async function reprovideConnectionCidsIfBrowserAddrsChanged(community, { selfAddrsMaxAgeMs = 0 } = {}) {
|
|
6972
7091
|
const log = logger_default("pkc-js:local-community:_reprovideConnectionCidsIfBrowserAddrsChanged");
|
|
6973
7092
|
const client = community._clientsManager.getDefaultKuboRpcClient()._client;
|
|
6974
|
-
const current = await
|
|
7093
|
+
const { addrs: current, readAtMs: browserAddrsReadAtMs } = selfAddrsMaxAgeMs > 0 ? await getBrowserDialableSelfAddrsShared({
|
|
7094
|
+
client,
|
|
7095
|
+
maxAgeMs: selfAddrsMaxAgeMs
|
|
7096
|
+
}) : {
|
|
7097
|
+
addrs: await getBrowserDialableSelfAddrs(client),
|
|
7098
|
+
readAtMs: Date.now()
|
|
7099
|
+
};
|
|
6975
7100
|
const previous = community._lastProvidedBrowserDialableSelfAddrs;
|
|
6976
7101
|
if (previous === void 0) {
|
|
6977
7102
|
community._lastProvidedBrowserDialableSelfAddrs = current;
|
|
6978
7103
|
return {
|
|
6979
7104
|
reprovided: false,
|
|
6980
7105
|
providedCids: [],
|
|
6981
|
-
browserAddrs: current
|
|
7106
|
+
browserAddrs: current,
|
|
7107
|
+
browserAddrsReadAtMs
|
|
6982
7108
|
};
|
|
6983
7109
|
}
|
|
6984
7110
|
if (t$8(previous, current)) return {
|
|
6985
7111
|
reprovided: false,
|
|
6986
7112
|
providedCids: [],
|
|
6987
|
-
browserAddrs: current
|
|
7113
|
+
browserAddrs: current,
|
|
7114
|
+
browserAddrsReadAtMs
|
|
6988
7115
|
};
|
|
6989
7116
|
community._lastProvidedBrowserDialableSelfAddrs = current;
|
|
6990
7117
|
const cidStrings = connectionCriticalCids(community);
|
|
@@ -7009,7 +7136,8 @@ async function reprovideConnectionCidsIfBrowserAddrsChanged(community) {
|
|
|
7009
7136
|
return {
|
|
7010
7137
|
reprovided: providedCids.length > 0,
|
|
7011
7138
|
providedCids,
|
|
7012
|
-
browserAddrs: current
|
|
7139
|
+
browserAddrs: current,
|
|
7140
|
+
browserAddrsReadAtMs
|
|
7013
7141
|
};
|
|
7014
7142
|
}
|
|
7015
7143
|
/**
|
|
@@ -7021,10 +7149,12 @@ async function reprovideOnAddressChangeIfDue(community) {
|
|
|
7021
7149
|
const now = Date.now();
|
|
7022
7150
|
if (typeof community._lastAddressReprovideCheckAt === "number" && now - community._lastAddressReprovideCheckAt < 6e4) return;
|
|
7023
7151
|
community._lastAddressReprovideCheckAt = now;
|
|
7024
|
-
await reprovideConnectionCidsIfBrowserAddrsChanged(community);
|
|
7152
|
+
const { browserAddrsReadAtMs } = await reprovideConnectionCidsIfBrowserAddrsChanged(community, { selfAddrsMaxAgeMs: ADDRESS_REPROVIDE_POLL_INTERVAL_MS / 4 });
|
|
7153
|
+
community._lastAddressReprovideCheckAt = Math.min(now, browserAddrsReadAtMs);
|
|
7025
7154
|
}
|
|
7026
7155
|
//#endregion
|
|
7027
7156
|
//#region dist/node/runtime/node/community/local-community/lifecycle.js
|
|
7157
|
+
const MIN_MS_BETWEEN_PUBLISH_CYCLES = 100;
|
|
7028
7158
|
async function publishLoop(community, syncIntervalMs) {
|
|
7029
7159
|
const log = logger_default("pkc-js:local-community:_publishLoop");
|
|
7030
7160
|
let syncFailedSinceStop = false;
|
|
@@ -7032,50 +7162,67 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
7032
7162
|
return community.state !== "started" || community._stopHasBeenCalled && (community._pendingEditProps.length === 0 || syncFailedSinceStop);
|
|
7033
7163
|
};
|
|
7034
7164
|
const waitUntilNextSync = async ({ lastSyncFailed }) => {
|
|
7035
|
-
|
|
7036
|
-
if (
|
|
7037
|
-
const
|
|
7165
|
+
calculateLatestUpdateTrigger(community);
|
|
7166
|
+
if (shouldStopPublishLoop()) return;
|
|
7167
|
+
const recordAlreadyRequested = !lastSyncFailed && community._communityUpdateTrigger;
|
|
7168
|
+
const minPauseMs = Math.min(MIN_MS_BETWEEN_PUBLISH_CYCLES, syncIntervalMs);
|
|
7169
|
+
const idleSleepMs = lastSyncFailed ? syncIntervalMs : Math.min(syncIntervalMs, Math.max(minPauseMs, msUntilLastPublishIsTooOld(community)));
|
|
7170
|
+
const sleepingSince = Date.now();
|
|
7038
7171
|
await new Promise((resolve) => {
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
if (
|
|
7043
|
-
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7172
|
+
let timer;
|
|
7173
|
+
const endSleep = () => {
|
|
7174
|
+
clearTimeout(timer);
|
|
7175
|
+
if (community._wakePublishLoop === wake) community._wakePublishLoop = void 0;
|
|
7176
|
+
resolve();
|
|
7177
|
+
};
|
|
7178
|
+
const wake = () => {
|
|
7179
|
+
const pauseLeftMs = minPauseMs - (Date.now() - sleepingSince);
|
|
7180
|
+
if (pauseLeftMs <= 0 || shouldStopPublishLoop()) return endSleep();
|
|
7181
|
+
clearTimeout(timer);
|
|
7182
|
+
timer = setTimeout(endSleep, pauseLeftMs);
|
|
7183
|
+
};
|
|
7184
|
+
timer = setTimeout(endSleep, recordAlreadyRequested ? minPauseMs : idleSleepMs);
|
|
7185
|
+
community._wakePublishLoop = wake;
|
|
7047
7186
|
});
|
|
7048
7187
|
};
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7188
|
+
const releaseEventLoopWatch = holdEventLoopWatch();
|
|
7189
|
+
try {
|
|
7190
|
+
await runCyclesUntilStopped();
|
|
7191
|
+
} finally {
|
|
7192
|
+
releaseEventLoopWatch();
|
|
7193
|
+
}
|
|
7194
|
+
log("Stopping the publishing loop of community", community.address);
|
|
7195
|
+
async function runCyclesUntilStopped() {
|
|
7196
|
+
while (!shouldStopPublishLoop()) {
|
|
7197
|
+
if (isCommunityStartTakenByAnotherInstance(community, log)) {
|
|
7198
|
+
const error = new PKCError("ERR_COMMUNITY_START_TAKEN_BY_ANOTHER_PKC_INSTANCE", {
|
|
7199
|
+
address: community.address,
|
|
7200
|
+
dataPath: community._pkc.dataPath
|
|
7201
|
+
});
|
|
7202
|
+
log.error(error);
|
|
7203
|
+
community._startTakenByAnotherInstance = true;
|
|
7204
|
+
try {
|
|
7205
|
+
community.emit("error", error);
|
|
7206
|
+
} catch (e) {
|
|
7207
|
+
log.error(`A listener of the error of community (${community.address}) threw, or there is none`, e);
|
|
7208
|
+
}
|
|
7209
|
+
community.stop().catch((e) => log.error(`Failed to stop community (${community.address}) after its start was taken`, e));
|
|
7210
|
+
break;
|
|
7211
|
+
}
|
|
7212
|
+
let lastSyncFailed = false;
|
|
7057
7213
|
try {
|
|
7058
|
-
community
|
|
7214
|
+
await syncIpnsWithDb(community);
|
|
7215
|
+
await reprovideOnAddressChangeIfDue(community).catch((e) => log.error("Failed to re-provide connection CIDs on address change", e));
|
|
7216
|
+
await reprovideAnchorRecordIfDue(community).catch((e) => log.error("Failed to re-provide the anchor record", e));
|
|
7059
7217
|
} catch (e) {
|
|
7060
|
-
|
|
7218
|
+
lastSyncFailed = true;
|
|
7219
|
+
if (community._stopHasBeenCalled) syncFailedSinceStop = true;
|
|
7220
|
+
community.emit("error", e);
|
|
7221
|
+
} finally {
|
|
7222
|
+
await waitUntilNextSync({ lastSyncFailed });
|
|
7061
7223
|
}
|
|
7062
|
-
community.stop().catch((e) => log.error(`Failed to stop community (${community.address}) after its start was taken`, e));
|
|
7063
|
-
break;
|
|
7064
|
-
}
|
|
7065
|
-
let lastSyncFailed = false;
|
|
7066
|
-
try {
|
|
7067
|
-
await syncIpnsWithDb(community);
|
|
7068
|
-
await reprovideOnAddressChangeIfDue(community).catch((e) => log.error("Failed to re-provide connection CIDs on address change", e));
|
|
7069
|
-
await reprovideAnchorRecordIfDue(community).catch((e) => log.error("Failed to re-provide the anchor record", e));
|
|
7070
|
-
} catch (e) {
|
|
7071
|
-
lastSyncFailed = true;
|
|
7072
|
-
if (community._stopHasBeenCalled) syncFailedSinceStop = true;
|
|
7073
|
-
community.emit("error", e);
|
|
7074
|
-
} finally {
|
|
7075
|
-
await waitUntilNextSync({ lastSyncFailed });
|
|
7076
7224
|
}
|
|
7077
7225
|
}
|
|
7078
|
-
log("Stopping the publishing loop of community", community.address);
|
|
7079
7226
|
}
|
|
7080
7227
|
function isCommunityStartTakenByAnotherInstance(community, log) {
|
|
7081
7228
|
try {
|
|
@@ -7361,6 +7508,7 @@ async function stop(community) {
|
|
|
7361
7508
|
await (community._startOrUpdateInFlight ?? community._stopInFlight ?? Promise.allSettled([...community._editStoresInFlight]));
|
|
7362
7509
|
community._stopHasBeenCalled = true;
|
|
7363
7510
|
}
|
|
7511
|
+
community._wakePublishLoop?.();
|
|
7364
7512
|
let settle;
|
|
7365
7513
|
const stopInFlight = new Promise((resolve) => settle = resolve);
|
|
7366
7514
|
community._stopInFlight = stopInFlight;
|
|
@@ -8126,6 +8274,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8126
8274
|
set _communityUpdateTrigger(value) {
|
|
8127
8275
|
if (value) this._updateTriggerGeneration++;
|
|
8128
8276
|
this._communityUpdateTriggerValue = value;
|
|
8277
|
+
if (value) this._wakePublishLoop?.();
|
|
8129
8278
|
}
|
|
8130
8279
|
constructor(pkc) {
|
|
8131
8280
|
super(pkc);
|
|
@@ -8147,6 +8296,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8147
8296
|
this._mfsPathRemovalWatchers = /* @__PURE__ */ new Set();
|
|
8148
8297
|
this._communityUpdateTriggerValue = false;
|
|
8149
8298
|
this._updateTriggerGeneration = 0;
|
|
8299
|
+
this._wakePublishLoop = void 0;
|
|
8150
8300
|
this._combinedHashOfPendingCommentsCids = (0, import_sha256.sha256)("");
|
|
8151
8301
|
this._pageSorts = void 0;
|
|
8152
8302
|
this._pageSortFactories = void 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $ as retryKuboIpfsAdd, At as ChallengeAnswerMessageSchema, Br as messages, C as hideClassPrivateProps, Cr as e, D as isIpfsCid, Dt as require_sha256, E as isAbortError, Er as r, Et as untrackUpdatingCommunity, Fr as FailedToFetchCommentUpdateFromGatewaysError, In as CommentUpdateForChallengeVerificationSchema, It as ChallengeVerificationMessageSchema, Jt as version_default, Mt as ChallengeMessageSchema, Nr as require_retry$1, Ot as TimeoutError, Pr as FailedToFetchCommentIpfsFromGatewaysError, Pt as ChallengeRequestMessageSchema, Rr as FailedToFetchPageIpfsFromGatewaysError, Sr as t$1, St as trackUpdatingComment, T as ipnsNameToIpnsOverPubsubTopic, Tt as untrackUpdatingComment, U as rejectWhenAbortSignalFires, Vr as logger_default, W as rejectWhenCommunityStopsOrAborts, Wr as setErrorMap, X as replaceXWithY, Y as removeUndefinedValuesRecursively, Z as resolveWhenPredicateIsTrue, _t as listUpdatingCommunities, a as calculateStringSizeSameAsIpfsAddCidV0Sync, at as throwIfAbortSignalAborted, br as n$1, cn as CommunityAnchorSchema, d as deepMergeRuntimeFields, dt as findStartedCommunity, et as retryKuboIpfsAddAndProvide, ft as findUpdatingComment, gr as isStringDomain, gt as listUpdatingComments, ht as listStartedCommunities, i as calculateStringSizeSameAsIpfsAddCidV0, ii as en_default, jn as CommentIpfsSchema, k as isIpns, kt as pTimeout, nt as shortifyCid, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, rt as sleepUntilTimeoutOrAbort, st as waitForUpdateInCommunityInstanceWithErrorAndTimeout, tt as shortifyAddress, u as createAbortError, vr as n$2, vt as refreshTrackedCommentAliases, wr as e$1, x as getPostUpdateTimestampRange, xn as PubsubTopicSchema, z as linkAbortSignals, zn as CommentUpdateSchema, zr as PKCError } from "./util-
|
|
3
|
-
import { $r as
|
|
4
|
-
import { s as getHeliaDebugContext } from "./util-
|
|
2
|
+
import { $ as retryKuboIpfsAdd, At as ChallengeAnswerMessageSchema, Br as messages, C as hideClassPrivateProps, Cr as e, D as isIpfsCid, Dt as require_sha256, E as isAbortError, Er as r, Et as untrackUpdatingCommunity, Fr as FailedToFetchCommentUpdateFromGatewaysError, In as CommentUpdateForChallengeVerificationSchema, It as ChallengeVerificationMessageSchema, Jt as version_default, Mt as ChallengeMessageSchema, Nr as require_retry$1, Ot as TimeoutError, Pr as FailedToFetchCommentIpfsFromGatewaysError, Pt as ChallengeRequestMessageSchema, Rr as FailedToFetchPageIpfsFromGatewaysError, Sr as t$1, St as trackUpdatingComment, T as ipnsNameToIpnsOverPubsubTopic, Tt as untrackUpdatingComment, U as rejectWhenAbortSignalFires, Vr as logger_default, W as rejectWhenCommunityStopsOrAborts, Wr as setErrorMap, X as replaceXWithY, Y as removeUndefinedValuesRecursively, Z as resolveWhenPredicateIsTrue, _t as listUpdatingCommunities, a as calculateStringSizeSameAsIpfsAddCidV0Sync, at as throwIfAbortSignalAborted, br as n$1, cn as CommunityAnchorSchema, d as deepMergeRuntimeFields, dt as findStartedCommunity, et as retryKuboIpfsAddAndProvide, ft as findUpdatingComment, gr as isStringDomain, gt as listUpdatingComments, ht as listStartedCommunities, i as calculateStringSizeSameAsIpfsAddCidV0, ii as en_default, jn as CommentIpfsSchema, k as isIpns, kt as pTimeout, nt as shortifyCid, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, rt as sleepUntilTimeoutOrAbort, st as waitForUpdateInCommunityInstanceWithErrorAndTimeout, tt as shortifyAddress, u as createAbortError, vr as n$2, vt as refreshTrackedCommentAliases, wr as e$1, x as getPostUpdateTimestampRange, xn as PubsubTopicSchema, z as linkAbortSignals, zn as CommentUpdateSchema, zr as PKCError } from "./util-DDsWXOtP.js";
|
|
3
|
+
import { $n as getAuthorNameFromWire, $r as n$3, $t as RpcPublishAnchorRecordParamSchema, A as findCommentInParsedPages, An as signCommunityEdit, At as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, B as GenericStateClient, Bn as verifyCommentPubsubMessage, Bt as RpcCommentRepliesPageParamSchema, C as RepliesPages, Cr as createKuboRpcClient, Ct as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, D as extractCommunityRuntimeFieldsFromParsedPages, Dt as parseDecryptedChallengeVerification, En as signCommentModeration, Et as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, F as cloneCrosspostForRuntime, Fr as markLocalCommunityDbAsBeingWritten, Ft as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, Gn as verifyVote, Gt as RpcExportCommunityModLogsParamSchema, Hr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, Ht as RpcCommunityIdentifierParamSchema, I as collectCrosspostAuthorsToResolve, In as verifyChallengeVerification, Ir as monitorCommunitiesDirectory, It as RpcAnchorPublishPreparationResultSchema, J as decodeRpcChallengeAnswerPubsubMsg, Jn as mergeAuthorProps, Jt as RpcExportCommunityResultSchema, Kn as assignUnknownProps, Kr as findCommunitiesEntry, Kt as RpcExportCommunityModLogsResultSchema, Ln as verifyCommentEdit, Lt as RpcAuthorNameParamSchema, M as parseRawPages, Mn as signVote, Mt as parseRpcCommentUpdateEventWithPKCErrorIfItFails, Nt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, O as findCommentInPageInstance, Or as findLocalCommunityAddress, Ot as parseDecryptedChallengeWithPKCErrorIfItFails, P as applyNameResolvedCacheToCrosspost, Pn as verifyChallengeMessage, Pr as isLocalCommunityAddress, Qn as getAuthorNameFromRuntime, Qr as t$3, Qt as RpcFetchCommunityListResultSchema, R as stripNameResolvedFromCrosspost, Rn as verifyCommentIpfs, Rr as registerLocalCommunity, Rt as RpcCancelExportParamSchema, Sn as signChallengeRequest, Tn as signCommentEdit, Tt as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, U as InflightFetchManager, Un as verifyCommunityEdit, Ut as RpcCommunityPageParamSchema, Vn as verifyCommentUpdate, Vr as setNativeFunctions$1, Vt as RpcCommunitiesChangeEventResultSchema, W as InflightResourceTypes, Wn as verifyCommunityList, Wt as RpcEditCommunityParamSchema, X as decodeRpcChallengeRequestPubsubMsg, Xn as buildRuntimeAuthor, Xt as RpcFetchCidResultSchema, Y as decodeRpcChallengePubsubMsg, Yn as withoutForbiddenKeys, Yr as t$5, Yt as RpcFetchCidParamSchema, Z as decodeRpcChallengeVerificationPubsubMsg, Zn as cleanWireAuthor, Zt as RpcFetchCommunityListParamSchema, _r as getPKCAddressFromPublicKeySync, _t as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, ai as NAME_RESOLVED_TRUE_TTL_MS, an as RpcSubscriptionIdResultSchema, at as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, b as KeyvBetterSqlite3, bn as signChallengeAnswer, bt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, cn as findCommunityRecordNameMismatch, cr as getCommunityAddressFromRecord, ct as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, dr as normalizeCommunityInputFromCommunity, dt as parseCommunityAddressWithPKCErrorIfItFails, en as RpcPublishChallengeAnswersParamSchema, er as normalizeCreatePublicationAuthor, fn as createSigner, fr as decode, gn as encryptEd25519AesGcm, gt as parseCommunityListSchemaWithPKCErrorIfItFails, ii as NAME_RESOLVED_FALSE_TTL_MS, in as RpcResolveAuthorNameResultSchema, ir as MAX_COMMUNITY_LIST_SIZE_BYTES, jn as signCommunityList, jr as getDefaultDataPath, jt as parseRpcCommentEventWithPKCErrorIfItFails, k as findCommentInPageInstanceRecursively, kt as parseJsonWithPKCErrorIfFails, l as pkcJsPageSorts, li as nativeFunctions$2, ln as verifyAuthorWalletEntry, lr as getCommunityNameFromWire, lt as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, m as pkcJsChallenges, mn as decryptEd25519AesGcm, mr as getBufferedPKCAddressFromPublicKey, mt as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, ni as t$4, nn as RpcPublishCommunityListResultSchema, nr as CreateCommunityListWithCidOptionsSchema, nt as parseCidStringSchemaWithPKCErrorIfItFails, oi as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, on as RpcSuccessResultSchema, ot as parseCommentIpfsSchemaWithPKCErrorIfItFails, pn as createAnchorIpnsRecord$1, q as PKCTypedEmitter, qr as toCommunitiesEntry, qt as RpcExportCommunityParamSchema, ri as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, rn as RpcPublishedAnchorRecordResultSchema, rr as CreateNewCommunityListOptionsSchema, sn as RpcUnsubscribeParamSchema, sr as buildRuntimeCommunityFields, t as RpcLocalCommunity, ti as t$2, tn as RpcPublishCommunityListParamSchema, un as require_lib$1, ur as getCommunityPublicKeyFromWire, ut as parseCommentUpdateSchemaWithPKCErrorIfItFails, v as TrackedInstanceRegistry, vt as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, wn as signComment, wt as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, x as RemoteCommunity, y as LRUCache, yn as cleanUpBeforePublishing, yt as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, z as PKCClientsManager, zn as verifyCommentModeration, zt as RpcCidParamSchema } from "./rpc-local-community-BjIHRbYy.js";
|
|
4
|
+
import { s as getHeliaDebugContext } from "./util-Bu3ItQsN.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import assert from "assert";
|
|
7
7
|
import fs from "fs";
|
|
@@ -36383,7 +36383,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
36383
36383
|
this.clients.libp2pJsClients = {};
|
|
36384
36384
|
if (!this.libp2pJsClientsOptions) return;
|
|
36385
36385
|
if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
|
|
36386
|
-
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-
|
|
36386
|
+
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-BT2UmDem.js");
|
|
36387
36387
|
for (const clientOptions of this.libp2pJsClientsOptions) {
|
|
36388
36388
|
const heliaNode = await createLibp2pJsClientOrUseExistingOne({
|
|
36389
36389
|
...clientOptions,
|
|
@@ -36760,7 +36760,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
36760
36760
|
const log = logger_default("pkc-js:pkc:createLocalCommunity");
|
|
36761
36761
|
log.trace("Received community options to create a local community instance:", options);
|
|
36762
36762
|
if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
|
|
36763
|
-
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-
|
|
36763
|
+
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-BexngGU7.js");
|
|
36764
36764
|
const isLocalCommunity = isLocalCommunityAddress(this, options.address);
|
|
36765
36765
|
const community = new LocalCommunity(this);
|
|
36766
36766
|
if (isLocalCommunity) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bn as PageSortFileSchema, gr as isStringDomain, v as getEquivalentCommunityAddresses } from "./util-
|
|
1
|
+
import { bn as PageSortFileSchema, gr as isStringDomain, v as getEquivalentCommunityAddresses } from "./util-DDsWXOtP.js";
|
|
2
2
|
//#region dist/node/pages/page-sort-scoring.js
|
|
3
3
|
function validatePageSortFile(rawFile) {
|
|
4
4
|
const validated = PageSortFileSchema.parse(rawFile);
|