@pkcprotocol/pkc-js 0.0.114 → 0.0.116

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.
Files changed (149) hide show
  1. package/dist/browser/challenges.d.ts +1 -0
  2. package/dist/browser/challenges.js +1 -1
  3. package/dist/browser/challenges.js.map +1 -1
  4. package/dist/browser/clients/base-client-manager.js +25 -2
  5. package/dist/browser/clients/base-client-manager.js.map +1 -1
  6. package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +2 -2
  7. package/dist/browser/clients/rpc-client/schema.d.ts +7 -7
  8. package/dist/browser/community/schema.d.ts +72 -72
  9. package/dist/browser/constants.d.ts +2 -1
  10. package/dist/browser/constants.js +3 -0
  11. package/dist/browser/constants.js.map +1 -1
  12. package/dist/browser/errors.d.ts +1 -0
  13. package/dist/browser/errors.js +1 -0
  14. package/dist/browser/errors.js.map +1 -1
  15. package/dist/browser/generated-version.d.ts +1 -1
  16. package/dist/browser/generated-version.js +1 -1
  17. package/dist/browser/index-with-compile-cache.d.ts +4 -4
  18. package/dist/browser/index.d.ts +8 -8
  19. package/dist/browser/page-sorts.d.ts +2 -0
  20. package/dist/browser/page-sorts.js +2 -0
  21. package/dist/browser/page-sorts.js.map +1 -0
  22. package/dist/browser/pages/schema.d.ts +17 -17
  23. package/dist/browser/pkc-error.d.ts +1 -1
  24. package/dist/browser/publications/comment/schema.d.ts +18 -18
  25. package/dist/browser/publications/comment-edit/schema.d.ts +5 -5
  26. package/dist/browser/publications/comment-moderation/schema.d.ts +4 -4
  27. package/dist/browser/publications/community-edit/schema.d.ts +4 -4
  28. package/dist/browser/pubsub-messages/schema.d.ts +9 -9
  29. package/dist/browser/rpc/src/index.d.ts +2 -0
  30. package/dist/browser/rpc/src/index.js +22 -0
  31. package/dist/browser/rpc/src/index.js.map +1 -1
  32. package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +4 -4
  33. package/dist/browser/rpc/src/lib/pkc-js/index.js +3 -1
  34. package/dist/browser/rpc/src/lib/pkc-js/index.js.map +1 -1
  35. package/dist/browser/rpc/src/schema.d.ts +30 -30
  36. package/dist/browser/runtime/node/community/db-handler.d.ts +6 -0
  37. package/dist/browser/runtime/node/community/db-handler.js +33 -1
  38. package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
  39. package/dist/browser/runtime/node/community/local-community/challenges.js +0 -2
  40. package/dist/browser/runtime/node/community/local-community/challenges.js.map +1 -1
  41. package/dist/browser/runtime/node/community/local-community/cleanup.d.ts +4 -2
  42. package/dist/browser/runtime/node/community/local-community/cleanup.js +11 -6
  43. package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -1
  44. package/dist/browser/runtime/node/community/local-community/editing.d.ts +2 -1
  45. package/dist/browser/runtime/node/community/local-community/editing.js +10 -7
  46. package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
  47. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +11 -1
  48. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
  49. package/dist/browser/runtime/node/community/local-community/lifecycle.js +7 -3
  50. package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
  51. package/dist/browser/runtime/node/community/local-community/publication-store.js +51 -27
  52. package/dist/browser/runtime/node/community/local-community/publication-store.js.map +1 -1
  53. package/dist/browser/runtime/node/community/local-community/registry-sync.d.ts +7 -0
  54. package/dist/browser/runtime/node/community/local-community/registry-sync.js +80 -0
  55. package/dist/browser/runtime/node/community/local-community/registry-sync.js.map +1 -0
  56. package/dist/browser/runtime/node/community/local-community.d.ts +2 -1
  57. package/dist/browser/runtime/node/community/local-community.js +3 -0
  58. package/dist/browser/runtime/node/community/local-community.js.map +1 -1
  59. package/dist/browser/runtime/node/community/page-sorts/index.d.ts +9 -0
  60. package/dist/browser/runtime/node/community/page-sorts/index.js +64 -6
  61. package/dist/browser/runtime/node/community/page-sorts/index.js.map +1 -1
  62. package/dist/browser/schema/schema-util.d.ts +12 -12
  63. package/dist/browser/schema.d.ts +32 -32
  64. package/dist/browser/test/test-util.d.ts +30 -30
  65. package/dist/browser/validate-package-factories.d.ts +7 -0
  66. package/dist/browser/validate-package-factories.js +37 -0
  67. package/dist/browser/validate-package-factories.js.map +1 -0
  68. package/dist/bundled/bundle-manifest.json +62 -27
  69. package/dist/bundled/challenges.js +2 -1
  70. package/dist/bundled/chunks/{helia-for-pkc-hSpmyI9D.js → helia-for-pkc-BvltkMx7.js} +2 -2
  71. package/dist/bundled/chunks/{local-community-Dc_fNPrx.js → local-community-Cm4X7RjW.js} +1 -1
  72. package/dist/bundled/chunks/{local-community-EeQMdfYM.js → local-community-nSmHRx5s.js} +165 -46
  73. package/dist/bundled/chunks/{node-apYZl3B3.js → node-CaeXEQ5O.js} +5 -5
  74. package/dist/bundled/chunks/page-sort-scoring-Bj73WnwW.js +112 -0
  75. package/dist/bundled/chunks/{rpc-local-community-C_0FRCqg.js → rpc-local-community-DfJ3wj-p.js} +80 -124
  76. package/dist/bundled/chunks/{util-B2SuJZg-.js → util-DkyQHyK7.js} +1 -1
  77. package/dist/bundled/chunks/{util-DFGl6QDd.js → util-vJMTa4rC.js} +2 -1
  78. package/dist/bundled/chunks/validate-package-factories-tZC8XxoO.js +41 -0
  79. package/dist/bundled/index.js +1 -1
  80. package/dist/bundled/page-sorts.js +2 -0
  81. package/dist/bundled/rpc/src/index.js +17 -4
  82. package/dist/node/challenges.d.ts +1 -0
  83. package/dist/node/challenges.js +1 -1
  84. package/dist/node/challenges.js.map +1 -1
  85. package/dist/node/clients/base-client-manager.js +25 -2
  86. package/dist/node/clients/base-client-manager.js.map +1 -1
  87. package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +2 -2
  88. package/dist/node/clients/rpc-client/schema.d.ts +7 -7
  89. package/dist/node/community/schema.d.ts +72 -72
  90. package/dist/node/constants.d.ts +2 -1
  91. package/dist/node/constants.js +3 -0
  92. package/dist/node/constants.js.map +1 -1
  93. package/dist/node/errors.d.ts +1 -0
  94. package/dist/node/errors.js +1 -0
  95. package/dist/node/errors.js.map +1 -1
  96. package/dist/node/generated-version.d.ts +1 -1
  97. package/dist/node/generated-version.js +1 -1
  98. package/dist/node/index-with-compile-cache.d.ts +4 -4
  99. package/dist/node/index.d.ts +8 -8
  100. package/dist/node/page-sorts.d.ts +2 -0
  101. package/dist/node/page-sorts.js +2 -0
  102. package/dist/node/page-sorts.js.map +1 -0
  103. package/dist/node/pages/schema.d.ts +17 -17
  104. package/dist/node/pkc-error.d.ts +1 -1
  105. package/dist/node/publications/comment/schema.d.ts +18 -18
  106. package/dist/node/publications/comment-edit/schema.d.ts +5 -5
  107. package/dist/node/publications/comment-moderation/schema.d.ts +4 -4
  108. package/dist/node/publications/community-edit/schema.d.ts +4 -4
  109. package/dist/node/pubsub-messages/schema.d.ts +9 -9
  110. package/dist/node/rpc/src/index.d.ts +2 -0
  111. package/dist/node/rpc/src/index.js +22 -0
  112. package/dist/node/rpc/src/index.js.map +1 -1
  113. package/dist/node/rpc/src/lib/pkc-js/index.d.ts +4 -4
  114. package/dist/node/rpc/src/lib/pkc-js/index.js +3 -1
  115. package/dist/node/rpc/src/lib/pkc-js/index.js.map +1 -1
  116. package/dist/node/rpc/src/schema.d.ts +30 -30
  117. package/dist/node/runtime/node/community/db-handler.d.ts +6 -0
  118. package/dist/node/runtime/node/community/db-handler.js +33 -1
  119. package/dist/node/runtime/node/community/db-handler.js.map +1 -1
  120. package/dist/node/runtime/node/community/local-community/challenges.js +0 -2
  121. package/dist/node/runtime/node/community/local-community/challenges.js.map +1 -1
  122. package/dist/node/runtime/node/community/local-community/cleanup.d.ts +4 -2
  123. package/dist/node/runtime/node/community/local-community/cleanup.js +11 -6
  124. package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -1
  125. package/dist/node/runtime/node/community/local-community/editing.d.ts +2 -1
  126. package/dist/node/runtime/node/community/local-community/editing.js +10 -7
  127. package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
  128. package/dist/node/runtime/node/community/local-community/ipns-publishing.js +11 -1
  129. package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
  130. package/dist/node/runtime/node/community/local-community/lifecycle.js +7 -3
  131. package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
  132. package/dist/node/runtime/node/community/local-community/publication-store.js +51 -27
  133. package/dist/node/runtime/node/community/local-community/publication-store.js.map +1 -1
  134. package/dist/node/runtime/node/community/local-community/registry-sync.d.ts +7 -0
  135. package/dist/node/runtime/node/community/local-community/registry-sync.js +80 -0
  136. package/dist/node/runtime/node/community/local-community/registry-sync.js.map +1 -0
  137. package/dist/node/runtime/node/community/local-community.d.ts +2 -1
  138. package/dist/node/runtime/node/community/local-community.js +3 -0
  139. package/dist/node/runtime/node/community/local-community.js.map +1 -1
  140. package/dist/node/runtime/node/community/page-sorts/index.d.ts +9 -0
  141. package/dist/node/runtime/node/community/page-sorts/index.js +64 -6
  142. package/dist/node/runtime/node/community/page-sorts/index.js.map +1 -1
  143. package/dist/node/schema/schema-util.d.ts +12 -12
  144. package/dist/node/schema.d.ts +32 -32
  145. package/dist/node/test/test-util.d.ts +30 -30
  146. package/dist/node/validate-package-factories.d.ts +7 -0
  147. package/dist/node/validate-package-factories.js +37 -0
  148. package/dist/node/validate-package-factories.js.map +1 -0
  149. package/package.json +6 -1
@@ -1,6 +1,7 @@
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-DFGl6QDd.js";
3
- import { $ as coerceSchemaRowJson, $n as getPKCAddressFromPublicKeySync, An as verifyCommentModeration, Cr as t$8, D as TIMEFRAMES_TO_SECONDS, Dr as t$9, En as verifyChallengeRequest, Fn as verifyVote, Gn as getCommunityNameFromWire, Hn as effectiveMaxCrosspostDepth, In as buildRuntimeAuthor, Jn as decode, K as pLimit, Kn as getCommunityPublicKeyFromWire, Ln as cleanWireAuthor, Mn as verifyCommentUpdate, Nn as verifyCommunity, Nr as STORAGE_KEYS, On as verifyCommentEdit, Or as stringify, Ot as parseJsonWithPKCErrorIfFails, P as iterateOverPageCidsToFindAllCids, Pn as verifyCommunityEdit, Pr as require_lodash_merge, Q as coerceSchemaRowBoolean, Qn as getPKCAddressFromPublicKey, S as LRUCache, Sr as r$2, T as KeyvBetterSqlite3, Tr as n$4, Tt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Vn as crosspostChainDepthUpTo, Yn as encode, Zn as getIpfsKeyFromPrivateKey, _ as pkcJsChallenges, _n as signCommentEdit, _r as resolveDbPostsCidRefs, a as loadPageSortsForStartedCommunity, b as createAuthorIdentityMatcher, bn as signCommentUpdateForChallengeVerification, br as t$10, c as createDescendantsLookup, cr as deriveDbPosts, d as partitionPageCommentsForSort, dn as cleanUpBeforePublishing, er as getPublicKeyFromPrivateKey, et as collectSchemaRowCoercions, f as scorePageCommentsWithFile, fr as getThumbnailPropsOfLink, g as loadChallengeFileFromCommunityChallengeSettings, gn as signComment, gr as moveCommunityDbToDeletedDirectory, h as getCommunityChallengeFromCommunityChallengeSettings, hn as signChallengeVerification, ht as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, i as generatePagesReportingFailedSorts, ir as calculateInlineRepliesBudget, jn as verifyCommentPubsubMessage, kn as verifyCommentIpfs, l as filterRepliesForPageSort, ln as encryptEd25519AesGcmPublicKeyBuffer, lr as deriveDbReplies, m as getChallengeVerification, nr as backupCommunityDb, o as resolvePageSortsOrThrow, or as deleteOldCommunityInWindows, p as stripRepliesFromPageComment, pn as signChallengeMessage, pr as importSignerIntoKuboNode, pt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, r as derivePublicPageSorts, rn as SignerWithPublicKeyAddress, rr as calculateExpectedSignatureSize, sn as decryptEd25519AesGcmPublicKeyBuffer, sr as deriveCommentIpfsFromCommentTableRow, t as RpcLocalCommunity, tr as BackupAbortError, tt as createSchemaRowParser, u as orderPageCommentsByScore, un as _validateSignatureOfPKCRecord, ur as getDefaultCommunityDbConfig, v as authorIdentityMatcherForRequest, w as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, wn as verifyChallengeAnswer, wr as n$5, x as TrackedInstanceRegistry, xn as signCommunity, xr as t$11, y as authorNameResolveFailureReason, yn as signCommentUpdate, zn as getAuthorNameFromWire } from "./rpc-local-community-C_0FRCqg.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-vJMTa4rC.js";
3
+ import { $n as calculateExpectedSignatureSize, $t as SignerWithPublicKeyAddress, A as iterateOverPageCidsToFindAllCids, An as verifyCommunityEdit, Ar as require_lodash_merge, C as TIMEFRAMES_TO_SECONDS, Cr as t$9, Dn as verifyCommentPubsubMessage, En as verifyCommentModeration, Fn as getAuthorNameFromWire, Gn as encode, H as pLimit, Hn as getCommunityPublicKeyFromWire, J as coerceSchemaRowBoolean, Jn as getPKCAddressFromPublicKey, Ln as crosspostChainDepthUpTo, Mn as buildRuntimeAuthor, Nn as cleanWireAuthor, On as verifyCommentUpdate, Qn as backupCommunityDb, Rn as effectiveMaxCrosspostDepth, Sn as verifyChallengeRequest, Tn as verifyCommentIpfs, Vn as getCommunityNameFromWire, Wn as decode, X as collectSchemaRowCoercions, Xn as getPublicKeyFromPrivateKey, Y as coerceSchemaRowJson, Yn as getPKCAddressFromPublicKeySync, Z as createSchemaRowParser, Zn as BackupAbortError, _ as TrackedInstanceRegistry, _n as signCommunity, _r as t$11, a as generatePagesReportingFailedSorts, an as encryptEd25519AesGcmPublicKeyBuffer, ar as deriveDbReplies, b as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, bn as verifyChallengeAnswer, br as n$5, c as resolvePageSortsOrThrow, cr as getThumbnailPropsOfLink, d as getCommunityChallengeFromCommunityChallengeSettings, dn as signChallengeVerification, dt as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, er as calculateInlineRepliesBudget, f as loadChallengeFileFromCommunityChallengeSettings, fn as signComment, fr as moveCommunityDbToDeletedDirectory, g as createAuthorIdentityMatcher, gn as signCommentUpdateForChallengeVerification, gr as t$10, h as authorNameResolveFailureReason, hn as signCommentUpdate, i as derivePublicPageSorts, ir as deriveDbPosts, jn as verifyVote, kn as verifyCommunity, kr as STORAGE_KEYS, ln as signChallengeMessage, lr as importSignerIntoKuboNode, lt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, m as authorIdentityMatcherForRequest, nr as deleteOldCommunityInWindows, o as loadPageSortsForStartedCommunity, on as _validateSignatureOfPKCRecord, or as getDefaultCommunityDbConfig, p as pkcJsChallenges, pn as signCommentEdit, pr as resolveDbPostsCidRefs, qn as getIpfsKeyFromPrivateKey, r as computePageSortsFingerprint, rn as decryptEd25519AesGcmPublicKeyBuffer, rr as deriveCommentIpfsFromCommentTableRow, s as lookupPageSortFactories, sn as cleanUpBeforePublishing, t as RpcLocalCommunity, u as getChallengeVerification, v as LRUCache, vr as r$2, wn as verifyCommentEdit, wr as stringify, wt as parseJsonWithPKCErrorIfFails, x as KeyvBetterSqlite3, xr as n$4, xt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, yr as t$8 } from "./rpc-local-community-DfJ3wj-p.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-Bj73WnwW.js";
4
5
  import { randomFillSync, randomUUID } from "node:crypto";
5
6
  import { fileURLToPath, pathToFileURL } from "node:url";
6
7
  import path from "node:path";
@@ -2714,6 +2715,7 @@ function deriveAliasOriginalAuthorSignerAddress(originalAuthorPublicKey) {
2714
2715
  }
2715
2716
  var DbHandler = class {
2716
2717
  constructor(community) {
2718
+ this._transactionGeneration = 0;
2717
2719
  this._publicationWriteGeneration = 0;
2718
2720
  this._community = community;
2719
2721
  this._transactionDepth = 0;
@@ -2824,9 +2826,31 @@ var DbHandler = class {
2824
2826
  log("Destroyed DB connection to community", this._community.address, "successfully");
2825
2827
  }
2826
2828
  createTransaction() {
2827
- if (this._transactionDepth === 0) this._db.exec("BEGIN");
2829
+ if (this._transactionDepth === 0) {
2830
+ this._db.exec("BEGIN");
2831
+ this._guardAgainstTransactionAcrossAwait();
2832
+ }
2828
2833
  this._transactionDepth++;
2829
2834
  }
2835
+ _guardAgainstTransactionAcrossAwait() {
2836
+ const transactionGeneration = ++this._transactionGeneration;
2837
+ queueMicrotask(() => {
2838
+ if (this._transactionDepth === 0 || this._transactionGeneration !== transactionGeneration) return;
2839
+ const error = /* @__PURE__ */ new Error("A DB transaction was left open across an await. Transactions must open and close synchronously (issue #417)");
2840
+ logger_default("pkc-js:local-community:db-handler:createTransaction").error(error);
2841
+ if (process.env["VITEST"]) throw error;
2842
+ });
2843
+ }
2844
+ readBackWithoutStoring(opts) {
2845
+ this._db.exec("SAVEPOINT read_back_without_storing");
2846
+ try {
2847
+ opts.write();
2848
+ return opts.read();
2849
+ } finally {
2850
+ this._db.exec("ROLLBACK TO read_back_without_storing");
2851
+ this._db.exec("RELEASE read_back_without_storing");
2852
+ }
2853
+ }
2830
2854
  commitTransaction() {
2831
2855
  if (this._transactionDepth > 0) {
2832
2856
  this._transactionDepth--;
@@ -3337,7 +3361,7 @@ var DbHandler = class {
3337
3361
  `).all();
3338
3362
  for (const { cid } of duplicateCids) {
3339
3363
  const purgedRows = this.purgeComment(cid);
3340
- for (const row of purgedRows) await addAllCidsUnderPurgedCommentToBeRemoved(this._community, row);
3364
+ for (const row of purgedRows) addAllCidsUnderPurgedCommentToBeRemoved(this._community, row);
3341
3365
  }
3342
3366
  log(`Purged ${duplicateCids.length} duplicate comment row(s) based on signature.signature with higher rowid values.`);
3343
3367
  continue;
@@ -5728,7 +5752,7 @@ async function unpinStaleCids(community, options = {}) {
5728
5752
  log.trace(`unpinned ${sizeBefore - community._cidsToUnPin.size} stale cids from ipfs node for community (${community.address})`);
5729
5753
  }
5730
5754
  }
5731
- async function rmUnneededMfsPaths(community) {
5755
+ async function rmUnneededMfsPaths(community, opts) {
5732
5756
  const log = logger_default("pkc-js:local-community:sync:_rmUnneededMfsPaths");
5733
5757
  if (community._mfsPathsToRemove.size > 0) {
5734
5758
  const toDeleteMfsPaths = Array.from(community._mfsPathsToRemove.values());
@@ -5737,14 +5761,17 @@ async function rmUnneededMfsPaths(community) {
5737
5761
  await removeMfsFilesSafely({
5738
5762
  kuboRpcClient: kuboRpc,
5739
5763
  paths: toDeleteMfsPaths,
5740
- log
5764
+ log,
5765
+ inputNumOfRetries: opts?.numOfRetries
5741
5766
  });
5742
5767
  toDeleteMfsPaths.forEach((path) => community._mfsPathsToRemove.delete(path));
5743
5768
  return toDeleteMfsPaths;
5744
5769
  } catch (e) {
5745
5770
  const error = e;
5746
- if (error.message.includes("file does not exist")) return toDeleteMfsPaths;
5747
- else {
5771
+ if (error.message.includes("file does not exist")) {
5772
+ toDeleteMfsPaths.forEach((path) => community._mfsPathsToRemove.delete(path));
5773
+ return toDeleteMfsPaths;
5774
+ } else {
5748
5775
  log.error("Failed to remove paths from MFS", toDeleteMfsPaths, e);
5749
5776
  throw error;
5750
5777
  }
@@ -5846,7 +5873,7 @@ async function _runRepoGcIfDue({ community, kuboUrl, force, log }) {
5846
5873
  after: repoSizeAfter
5847
5874
  }));
5848
5875
  }
5849
- async function addAllCidsUnderPurgedCommentToBeRemoved(community, purgedCommentAndCommentUpdate) {
5876
+ function addAllCidsUnderPurgedCommentToBeRemoved(community, purgedCommentAndCommentUpdate) {
5850
5877
  communitiesWithPendingPurgeFlush.set(community, Date.now());
5851
5878
  community._cidsToUnPin.add(purgedCommentAndCommentUpdate.commentTableRow.cid);
5852
5879
  community._blocksToRm.push(purgedCommentAndCommentUpdate.commentTableRow.cid);
@@ -5868,7 +5895,7 @@ async function purgeDisapprovedCommentsOlderThan(community) {
5868
5895
  const purgedComments = community._dbHandler.purgeDisapprovedCommentsOlderThan(community.settings.purgeDisapprovedCommentsOlderThan);
5869
5896
  if (!purgedComments || purgedComments.length === 0) return;
5870
5897
  log("Purged disapproved comments", purgedComments, "because retention time has passed and it's time to purge them from DB and pages");
5871
- for (const purgedComment of purgedComments) for (const purgedCommentAndCommentUpdate of purgedComment.purgedTableRows) await addAllCidsUnderPurgedCommentToBeRemoved(community, purgedCommentAndCommentUpdate);
5898
+ for (const purgedComment of purgedComments) for (const purgedCommentAndCommentUpdate of purgedComment.purgedTableRows) addAllCidsUnderPurgedCommentToBeRemoved(community, purgedCommentAndCommentUpdate);
5872
5899
  if (community._mfsPathsToRemove.size > 0) await rmUnneededMfsPaths(community);
5873
5900
  if (community.updateCid) {
5874
5901
  community._blocksToRm.push(community.updateCid);
@@ -6460,13 +6487,11 @@ async function handleChallengeExchange(community, pubsubMsg) {
6460
6487
  await handleChallengeRequest(community, parsedPubsubMsg, false);
6461
6488
  } catch (e) {
6462
6489
  log.error(`Failed to process challenge request message received at (${timeReceived})`, e);
6463
- community._dbHandler.rollbackTransaction();
6464
6490
  }
6465
6491
  else if (parsedPubsubMsg.type === "CHALLENGEANSWER") try {
6466
6492
  await handleChallengeAnswer(community, parsedPubsubMsg);
6467
6493
  } catch (e) {
6468
6494
  log.error(`Failed to process challenge answer message received at (${timeReceived})`, e);
6469
- community._dbHandler.rollbackTransaction();
6470
6495
  }
6471
6496
  }
6472
6497
  //#endregion
@@ -6896,9 +6921,12 @@ async function prepareCommentEditWithAlias(community, originalEdit) {
6896
6921
  return commentEditSignedByAlias;
6897
6922
  }
6898
6923
  async function assertStoredCommentIsVerbatim(opts) {
6899
- const { community, commentCid, log } = opts;
6900
- const storedRow = community._dbHandler.queryComment(commentCid);
6901
- if (!storedRow) throw Error(`Comment ${commentCid} is missing from the DB inside the transaction that inserted it`);
6924
+ const { community, commentRow, commentCid, log } = opts;
6925
+ const storedRow = community._dbHandler.readBackWithoutStoring({
6926
+ write: () => community._dbHandler.insertComments([commentRow]),
6927
+ read: () => community._dbHandler.queryComment(commentCid)
6928
+ });
6929
+ if (!storedRow) throw Error(`Comment ${commentCid} could not be read back from the DB after inserting it`);
6902
6930
  const storedComment = deriveCommentIpfsFromCommentTableRow(storedRow);
6903
6931
  const storedCid = await calculateIpfsCidV0(stringify(storedComment));
6904
6932
  const storedValidity = await verifyCommentIpfs({
@@ -6919,9 +6947,12 @@ async function assertStoredCommentIsVerbatim(opts) {
6919
6947
  throw error;
6920
6948
  }
6921
6949
  async function assertStoredAuthorEditIsVerbatim(opts) {
6922
- const { community, commentEditRaw, authorSignerAddress, log } = opts;
6923
- const storedEdit = community._dbHandler.queryLatestAuthorEdit(commentEditRaw.commentCid, authorSignerAddress);
6924
- if (!storedEdit || storedEdit.signature.signature !== commentEditRaw.signature.signature) throw Error(`Edit of comment ${commentEditRaw.commentCid} is missing from the DB inside the transaction that inserted it`);
6950
+ const { community, editTableRow, commentEditRaw, authorSignerAddress, log } = opts;
6951
+ const storedEdit = community._dbHandler.readBackWithoutStoring({
6952
+ write: () => community._dbHandler.insertCommentEdits([editTableRow]),
6953
+ read: () => community._dbHandler.queryLatestAuthorEdit(commentEditRaw.commentCid, authorSignerAddress)
6954
+ });
6955
+ if (!storedEdit || storedEdit.signature.signature !== commentEditRaw.signature.signature) throw Error(`Edit of comment ${commentEditRaw.commentCid} could not be read back from the DB after inserting it`);
6925
6956
  const storedValidity = await _validateSignatureOfPKCRecord(storedEdit);
6926
6957
  if (storedValidity.valid) return;
6927
6958
  const error = new PKCError("ERR_COMMUNITY_CANNOT_STORE_PUBLICATION_VERBATIM", {
@@ -6954,20 +6985,14 @@ async function storeCommentEdit(community, commentEditRaw, challengeRequestId) {
6954
6985
  editTableRow.extraProps = t$10(commentEditRaw, extraPropsInEdit);
6955
6986
  }
6956
6987
  if (community._dbHandler.hasCommentEditWithSignatureEncoded(editTableRow.signature.signature)) throw new PKCError("ERR_DUPLICATE_COMMENT_EDIT", { editTableRow });
6957
- community._dbHandler.createTransaction();
6958
- try {
6959
- community._dbHandler.insertCommentEdits([editTableRow]);
6960
- if (editSignedByOriginalAuthor) await assertStoredAuthorEditIsVerbatim({
6961
- community,
6962
- commentEditRaw,
6963
- authorSignerAddress,
6964
- log
6965
- });
6966
- community._dbHandler.commitTransaction();
6967
- } catch (e) {
6968
- community._dbHandler.rollbackTransaction();
6969
- throw e;
6970
- }
6988
+ if (editSignedByOriginalAuthor) await assertStoredAuthorEditIsVerbatim({
6989
+ community,
6990
+ editTableRow,
6991
+ commentEditRaw,
6992
+ authorSignerAddress,
6993
+ log
6994
+ });
6995
+ community._dbHandler.insertCommentEdits([editTableRow]);
6971
6996
  if (commentEditRaw.deleted === true) {
6972
6997
  const isPending = commentToBeEdited.pendingApproval;
6973
6998
  const disapprovalResult = community._dbHandler._queryIsCommentApproved(commentToBeEdited);
@@ -7016,14 +7041,29 @@ async function storeCommentModeration(community, commentModRaw, challengeRequest
7016
7041
  if (modTableRow.commentModeration.purged) {
7017
7042
  log("commentModeration.purged=true, and therefore will delete the post/comment and all its reply tree from the db as well as unpin the cids from ipfs", "comment cid is", modTableRow.commentCid);
7018
7043
  if (!community._dbHandler.queryComment(modTableRow.commentCid)) throw Error("Comment to purge not found");
7019
- const purgedTableRows = community._dbHandler.purgeComment(modTableRow.commentCid);
7020
- for (const purgedTableRow of purgedTableRows) await addAllCidsUnderPurgedCommentToBeRemoved(community, purgedTableRow);
7021
- log("Purged comment", modTableRow.commentCid, "and its comment and comment update children", "out of DB and IPFS");
7022
- await rmUnneededMfsPaths(community);
7044
+ community._dbHandler.createTransaction();
7045
+ let purgedTableRows;
7046
+ try {
7047
+ purgedTableRows = community._dbHandler.purgeComment(modTableRow.commentCid);
7048
+ community._dbHandler.insertCommentModerations([modTableRow]);
7049
+ community._dbHandler.commitTransaction();
7050
+ } catch (e) {
7051
+ community._dbHandler.rollbackTransaction();
7052
+ throw e;
7053
+ }
7054
+ for (const purgedTableRow of purgedTableRows) addAllCidsUnderPurgedCommentToBeRemoved(community, purgedTableRow);
7023
7055
  if (community.updateCid) {
7024
7056
  community._blocksToRm.push(community.updateCid);
7025
7057
  community._cidsToUnPin.add(community.updateCid);
7026
7058
  }
7059
+ community._communityUpdateTrigger = true;
7060
+ log("Purged comment", modTableRow.commentCid, "and its comment and comment update children", "out of DB and IPFS");
7061
+ try {
7062
+ await rmUnneededMfsPaths(community, { numOfRetries: 0 });
7063
+ } catch (e) {
7064
+ log.error("Failed to remove MFS paths of purged comment", modTableRow.commentCid, "the sync loop will retry", e);
7065
+ }
7066
+ return;
7027
7067
  } else if ("approved" in modTableRow.commentModeration) if (modTableRow.commentModeration.approved) {
7028
7068
  log("commentModeration.approved=true, and therefore move comment from pending approval and add it to IPFS", "comment cid is", modTableRow.commentCid);
7029
7069
  await community._addCommentRowToIPFS(commentToBeEdited, logger_default("pkc-js:local-community:storeCommentModeration:_addCommentRowToIPFS"));
@@ -7123,6 +7163,12 @@ async function storeComment(community, opts) {
7123
7163
  }
7124
7164
  if (challengeAggregate?.aggregatedCommentUpdate && Object.keys(challengeAggregate.aggregatedCommentUpdate).length > 0) commentRow.challengeCommentUpdate = challengeAggregate.aggregatedCommentUpdate;
7125
7165
  if (originalCommentSignatureEncoded) commentRow.originalCommentSignatureEncoded = originalCommentSignatureEncoded;
7166
+ await assertStoredCommentIsVerbatim({
7167
+ community,
7168
+ commentRow,
7169
+ commentCid,
7170
+ log
7171
+ });
7126
7172
  community._dbHandler.createTransaction();
7127
7173
  try {
7128
7174
  if (!pendingApproval) {
@@ -7131,11 +7177,6 @@ async function storeComment(community, opts) {
7131
7177
  if (typeof postNumber === "number") commentRow.postNumber = postNumber;
7132
7178
  }
7133
7179
  community._dbHandler.insertComments([commentRow]);
7134
- await assertStoredCommentIsVerbatim({
7135
- community,
7136
- commentCid,
7137
- log
7138
- });
7139
7180
  if (typeof community.settings?.maxPendingApprovalCount === "number") community._dbHandler.removeOldestPendingCommentIfWeHitMaxPendingCount(community.settings.maxPendingApprovalCount);
7140
7181
  community._dbHandler.commitTransaction();
7141
7182
  } catch (e) {
@@ -7263,6 +7304,74 @@ async function providePubsubTopicRoutingCidsIfNeeded(community, force = false) {
7263
7304
  }
7264
7305
  }
7265
7306
  //#endregion
7307
+ //#region dist/node/runtime/node/community/local-community/registry-sync.js
7308
+ const PAGE_SORTS_FINGERPRINT_KEY = STORAGE_KEYS[STORAGE_KEYS.PAGE_SORTS_FINGERPRINT];
7309
+ async function setResolvedPageSorts(community, resolved, factories) {
7310
+ const pagesSettings = community.settings?.pages;
7311
+ community._pageSorts = resolved;
7312
+ community._pageSortFactories = factories;
7313
+ community.pageSorts = derivePublicPageSorts({
7314
+ pagesSettings,
7315
+ resolved
7316
+ });
7317
+ await community._dbHandler.keyvSet(PAGE_SORTS_FINGERPRINT_KEY, computePageSortsFingerprint({
7318
+ pagesSettings,
7319
+ resolved,
7320
+ factories
7321
+ }));
7322
+ }
7323
+ const sameFactories = (a, b) => a !== void 0 && a.length === b.length && a.every((factory, i) => factory === b[i]);
7324
+ async function syncPageSortsWithRegistry(community) {
7325
+ const log = logger_default("pkc-js:local-community:registry-sync:page-sorts");
7326
+ await community._dbHandler.initDbIfNeeded();
7327
+ const pagesSettings = community.settings?.pages;
7328
+ const currentFactories = lookupPageSortFactories({
7329
+ pagesSettings,
7330
+ pkc: community._pkc
7331
+ });
7332
+ const inMemory = community._pageSorts !== void 0 && community._pageSortFactories !== void 0;
7333
+ if (inMemory && sameFactories(community._pageSortFactories, currentFactories)) return;
7334
+ const previousFingerprint = community._dbHandler.keyvGet(PAGE_SORTS_FINGERPRINT_KEY);
7335
+ const previousPublicPageSorts = stringify(community.pageSorts ?? null);
7336
+ const resolved = await loadPageSortsForStartedCommunity(community);
7337
+ const factories = community._pageSortFactories;
7338
+ const fingerprint = computePageSortsFingerprint({
7339
+ pagesSettings,
7340
+ resolved,
7341
+ factories
7342
+ });
7343
+ const changed = inMemory || previousFingerprint !== void 0 && previousFingerprint !== fingerprint;
7344
+ await setResolvedPageSorts(community, resolved, factories);
7345
+ if (changed) {
7346
+ log("Page sort factories changed in the registry, regenerating every CommentUpdate", community.address);
7347
+ community._dbHandler.forceUpdateOnAllComments();
7348
+ community._communityUpdateTrigger = true;
7349
+ } else if (stringify(community.pageSorts ?? null) !== previousPublicPageSorts) community._communityUpdateTrigger = true;
7350
+ }
7351
+ async function syncChallengesWithRegistry(community) {
7352
+ const log = logger_default("pkc-js:local-community:registry-sync:challenges");
7353
+ const challengeSettings = community.settings?.challenges;
7354
+ if (!Array.isArray(challengeSettings)) return;
7355
+ let challenges;
7356
+ try {
7357
+ challenges = await Promise.all(challengeSettings.map(async (cs) => (await getCommunityChallengeFromCommunityChallengeSettings({
7358
+ communityChallengeSettings: cs,
7359
+ pkc: community._pkc
7360
+ })).communityChallenge));
7361
+ } catch (e) {
7362
+ log.error("Could not recompute community.challenges from the registry, keeping the previous ones", community.address, e);
7363
+ return;
7364
+ }
7365
+ if (stringify(challenges) === stringify(community.challenges ?? null)) return;
7366
+ log("community.challenges changed in the registry, republishing", community.address);
7367
+ community.challenges = challenges;
7368
+ community._communityUpdateTrigger = true;
7369
+ }
7370
+ async function syncWithRegistries(community) {
7371
+ await syncChallengesWithRegistry(community);
7372
+ await syncPageSortsWithRegistry(community);
7373
+ }
7374
+ //#endregion
7266
7375
  //#region dist/node/runtime/node/community/local-community/ipns-publishing.js
7267
7376
  async function calculateNewPostUpdates(community) {
7268
7377
  const postUpdates = {};
@@ -7517,7 +7626,9 @@ async function syncIpnsWithDb(community) {
7517
7626
  community._setStartedStateWithEmission("publishing-ipns");
7518
7627
  community._clientsManager.updateKuboRpcState("publishing-ipns", kuboRpc.url);
7519
7628
  await purgeDisapprovedCommentsOlderThan(community);
7629
+ await syncWithRegistries(community);
7520
7630
  const cidsUpdatedInThisCycle = await updateCommentsAndWritePostUpdates(community);
7631
+ if (community._mfsPathsToRemove.size > 0) await rmUnneededMfsPaths(community);
7521
7632
  requireCommunityUpdateIfModQueueChanged(community);
7522
7633
  await updateCommunityIpnsIfNeeded(community, cidsUpdatedInThisCycle);
7523
7634
  await cleanUpIpfsRepoIfDue(community);
@@ -7734,7 +7845,9 @@ async function start(community) {
7734
7845
  pkc: community._pkc
7735
7846
  })).communityChallenge));
7736
7847
  await emitChallengeSettingsValidationErrors(community, log);
7737
- await community._loadPageSorts();
7848
+ community._pageSorts = void 0;
7849
+ community._pageSortFactories = void 0;
7850
+ await syncPageSortsWithRegistry(community);
7738
7851
  } catch (e) {
7739
7852
  await community.stop();
7740
7853
  e.details = {
@@ -8068,6 +8181,10 @@ async function parseChallengesToEdit(community, newChallengeSettings) {
8068
8181
  }
8069
8182
  async function parsePagesToEdit(community, newSettings) {
8070
8183
  await community._dbHandler.initDbIfNeeded();
8184
+ const factories = lookupPageSortFactories({
8185
+ pagesSettings: newSettings.pages,
8186
+ pkc: community._pkc
8187
+ });
8071
8188
  const resolved = await resolvePageSortsOrThrow({
8072
8189
  pagesSettings: newSettings.pages,
8073
8190
  pkc: community._pkc,
@@ -8080,13 +8197,14 @@ async function parsePagesToEdit(community, newSettings) {
8080
8197
  resolved
8081
8198
  }),
8082
8199
  resolved,
8200
+ factories,
8083
8201
  pagesChanged
8084
8202
  };
8085
8203
  }
8086
- function applyPagesEdit(community, pagesEdit) {
8204
+ async function applyPagesEdit(community, pagesEdit) {
8087
8205
  if (!pagesEdit) return;
8088
8206
  if (pagesEdit.pagesChanged) community._dbHandler.forceUpdateOnAllComments();
8089
- community._pageSorts = pagesEdit.resolved;
8207
+ await setResolvedPageSorts(community, pagesEdit.resolved, pagesEdit.factories);
8090
8208
  }
8091
8209
  async function validateNewAddressBeforeEditing(community, newAddress, log) {
8092
8210
  if (doesDomainAddressHaveCapitalLetter(newAddress)) throw new PKCError("ERR_COMMUNITY_NAME_HAS_CAPITAL_LETTER", { communityAddress: newAddress });
@@ -8128,7 +8246,7 @@ async function editPropsOnStartedCommunity(community, parsedEditOptions, pagesEd
8128
8246
  ...parsedEditOptions,
8129
8247
  _internalStateUpdateId: uniqueEditId
8130
8248
  });
8131
- applyPagesEdit(community, pagesEdit);
8249
+ await applyPagesEdit(community, pagesEdit);
8132
8250
  community._communityUpdateTrigger = true;
8133
8251
  log(`Community (${community.address}) props (${t$6(parsedEditOptions)}) has been edited. Will be including edited props in next update: `, t$10(community, t$6(parsedEditOptions)));
8134
8252
  community.emit("update", community);
@@ -8156,7 +8274,7 @@ async function editPropsOnNotStartedCommunity(community, parsedEditOptions, page
8156
8274
  const mergedInternalState = await updateDbInternalState(community, parsedEditOptions);
8157
8275
  if ("updatedAt" in mergedInternalState && mergedInternalState.updatedAt) await community.initInternalCommunityAfterFirstUpdateNoMerge(mergedInternalState);
8158
8276
  else await community.initInternalCommunityBeforeFirstUpdateNoMerge(mergedInternalState);
8159
- applyPagesEdit(community, pagesEdit);
8277
+ await applyPagesEdit(community, pagesEdit);
8160
8278
  await community._dbHandler.destoryConnection();
8161
8279
  community.emit("update", community);
8162
8280
  return community;
@@ -8415,6 +8533,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
8415
8533
  this._communityUpdateTrigger = false;
8416
8534
  this._combinedHashOfPendingCommentsCids = (0, import_sha256.sha256)("");
8417
8535
  this._pageSorts = void 0;
8536
+ this._pageSortFactories = void 0;
8418
8537
  this._publishLoopPromise = void 0;
8419
8538
  this._updateLoopPromise = void 0;
8420
8539
  this._firstUpdateAfterStart = true;
@@ -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-DFGl6QDd.js";
3
- import { $n as getPKCAddressFromPublicKeySync, $t as RpcSubscriptionIdResultSchema, A as extractCommunityRuntimeFieldsFromParsedPages, An as verifyCommentModeration, Ar as NAME_RESOLVED_FALSE_TTL_MS, At as parseRpcCommentEventWithPKCErrorIfItFails, B as stripNameResolvedFromCrosspost, Bn as normalizeCreatePublicationAuthor, Bt as RpcCommunityIdentifierParamSchema, C as RemoteCommunity, Cn as signVote, Cr as t$3, Ct as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, Dn as verifyChallengeVerification, Dr as t$4, Dt as parseDecryptedChallengeWithPKCErrorIfItFails, E as RepliesPages, Er as t$2, Et as parseDecryptedChallengeVerification, F as parseRawPages, Fn as verifyVote, Fr as nativeFunctions$2, Ft as RpcAnchorPublishPreparationResultSchema, Gn as getCommunityNameFromWire, Gt as RpcExportCommunityParamSchema, H as GenericStateClient, Ht as RpcEditCommunityParamSchema, I as applyNameResolvedCacheToCrosspost, In as buildRuntimeAuthor, Ir as require_undici, It as RpcAuthorNameParamSchema, J as decodeRpcChallengeAnswerPubsubMsg, Jn as decode, Jt as RpcFetchCidResultSchema, Kn as getCommunityPublicKeyFromWire, Kt as RpcExportCommunityResultSchema, L as cloneCrosspostForRuntime, Ln as cleanWireAuthor, Lt as RpcCancelExportParamSchema, M as findCommentInPageInstanceRecursively, Mn as verifyCommentUpdate, Mr as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, Mt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, N as findCommentInParsedPages, On as verifyCommentEdit, Ot as parseJsonWithPKCErrorIfFails, Pn as verifyCommunityEdit, Pt as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, Qt as RpcResolveAuthorNameResultSchema, R as collectCrosspostAuthorsToResolve, Rn as getAuthorNameFromRuntime, Rt as RpcCidParamSchema, S as LRUCache, Sn as signCommunityEdit, St as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, T as KeyvBetterSqlite3, Tn as verifyChallengeMessage, Tt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, U as InflightFetchManager, Un as buildRuntimeCommunityFields, Ut as RpcExportCommunityModLogsParamSchema, V as PKCClientsManager, Vt as RpcCommunityPageParamSchema, W as InflightResourceTypes, Wn as getCommunityAddressFromRecord, Wt as RpcExportCommunityModLogsResultSchema, X as decodeRpcChallengeRequestPubsubMsg, Xn as getBufferedPKCAddressFromPublicKey, Xt as RpcPublishChallengeAnswersParamSchema, Y as decodeRpcChallengePubsubMsg, Yt as RpcPublishAnchorRecordParamSchema, Z as decodeRpcChallengeVerificationPubsubMsg, Zt as RpcPublishedAnchorRecordResultSchema, _ as pkcJsChallenges, _n as signCommentEdit, _t as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, an as createAnchorIpnsRecord$1, ar as createKuboRpcClient, at as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, br as t$5, cn as encryptEd25519AesGcm, ct as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, dn as cleanUpBeforePublishing, dr as getDefaultDataPath, dt as parseCommunityAddressWithPKCErrorIfItFails, en as RpcSuccessResultSchema, fn as signChallengeAnswer, gn as signComment, gt as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, hr as monitorCommunitiesDirectory, in as createSigner, j as findCommentInPageInstance, jn as verifyCommentPubsubMessage, jr as NAME_RESOLVED_TRUE_TTL_MS, jt as parseRpcCommentUpdateEventWithPKCErrorIfItFails, kn as verifyCommentIpfs, kr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, kt as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, lt as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, mn as signChallengeRequest, mr as listCommunitiesSync, mt as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as require_lib$1, nt as parseCidStringSchemaWithPKCErrorIfItFails, on as decryptEd25519AesGcm, ot as parseCommentIpfsSchemaWithPKCErrorIfItFails, q as PKCTypedEmitter, qn as normalizeCommunityInputFromCommunity, qt as RpcFetchCidParamSchema, s as pkcJsPageSorts, t as RpcLocalCommunity, tn as RpcUnsubscribeParamSchema, ut as parseCommentUpdateSchemaWithPKCErrorIfItFails, vn as signCommentModeration, vr as setNativeFunctions$1, vt as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, wr as n$3, wt as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, x as TrackedInstanceRegistry, yr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, yt as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, zt as RpcCommentRepliesPageParamSchema } from "./rpc-local-community-C_0FRCqg.js";
4
- import { s as getHeliaDebugContext } from "./util-B2SuJZg-.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-vJMTa4rC.js";
3
+ import { An as verifyCommunityEdit, At as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, B as InflightResourceTypes, Bn as getCommunityAddressFromRecord, Bt as RpcExportCommunityModLogsResultSchema, Cn as verifyChallengeVerification, Cr as t$4, Ct as parseDecryptedChallengeWithPKCErrorIfItFails, D as findCommentInPageInstance, Dn as verifyCommentPubsubMessage, Dr as NAME_RESOLVED_TRUE_TTL_MS, Dt as parseRpcCommentUpdateEventWithPKCErrorIfItFails, E as extractCommunityRuntimeFieldsFromParsedPages, En as verifyCommentModeration, Er as NAME_RESOLVED_FALSE_TTL_MS, Et as parseRpcCommentEventWithPKCErrorIfItFails, Ft as RpcCommentRepliesPageParamSchema, G as decodeRpcChallengePubsubMsg, Gt as RpcPublishAnchorRecordParamSchema, Hn as getCommunityPublicKeyFromWire, Ht as RpcExportCommunityResultSchema, I as stripNameResolvedFromCrosspost, In as normalizeCreatePublicationAuthor, It as RpcCommunityIdentifierParamSchema, Jt as RpcResolveAuthorNameResultSchema, K as decodeRpcChallengeRequestPubsubMsg, Kn as getBufferedPKCAddressFromPublicKey, Kt as RpcPublishChallengeAnswersParamSchema, L as PKCClientsManager, Lt as RpcCommunityPageParamSchema, M as applyNameResolvedCacheToCrosspost, Mn as buildRuntimeAuthor, Mr as require_undici, Mt as RpcAuthorNameParamSchema, N as cloneCrosspostForRuntime, Nn as cleanWireAuthor, Nt as RpcCancelExportParamSchema, O as findCommentInPageInstanceRecursively, On as verifyCommentUpdate, Or as NAME_RESOLVE_FAILED_RETRY_FLOOR_MS, Ot as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, P as collectCrosspostAuthorsToResolve, Pn as getAuthorNameFromRuntime, Pt as RpcCidParamSchema, Q as parseCidStringSchemaWithPKCErrorIfItFails, Qt as require_lib$1, R as GenericStateClient, Rt as RpcEditCommunityParamSchema, S as RepliesPages, Sr as t$2, St as parseDecryptedChallengeVerification, Tn as verifyCommentIpfs, Tr as MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE, Tt as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, U as PKCTypedEmitter, Un as normalizeCommunityInputFromCommunity, Ut as RpcFetchCidParamSchema, Vn as getCommunityNameFromWire, Vt as RpcExportCommunityParamSchema, W as decodeRpcChallengeAnswerPubsubMsg, Wn as decode, Wt as RpcFetchCidResultSchema, Xt as RpcSuccessResultSchema, Yn as getPKCAddressFromPublicKeySync, Yt as RpcSubscriptionIdResultSchema, Zt as RpcUnsubscribeParamSchema, _ as TrackedInstanceRegistry, at as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, br as n$3, bt as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, cn as signChallengeAnswer, dr as monitorCommunitiesDirectory, en as createSigner, fn as signComment, ft as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, gr as t$5, hr as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, ht as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, in as encryptEd25519AesGcm, it as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, j as parseRawPages, jn as verifyVote, jr as nativeFunctions$2, jt as RpcAnchorPublishPreparationResultSchema, k as findCommentInParsedPages, l as pkcJsPageSorts, mn as signCommentModeration, mr as setNativeFunctions$1, mt as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, n as RpcRemoteCommunity, nn as decryptEd25519AesGcm, nt as parseCommentIpfsSchemaWithPKCErrorIfItFails, ot as parseCommentUpdateSchemaWithPKCErrorIfItFails, p as pkcJsChallenges, pn as signCommentEdit, pt as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, q as decodeRpcChallengeVerificationPubsubMsg, qt as RpcPublishedAnchorRecordResultSchema, sn as cleanUpBeforePublishing, sr as getDefaultDataPath, st as parseCommunityAddressWithPKCErrorIfItFails, t as RpcLocalCommunity, tn as createAnchorIpnsRecord$1, tr as createKuboRpcClient, tt as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, un as signChallengeRequest, ur as listCommunitiesSync, ut as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, v as LRUCache, vn as signCommunityEdit, vt as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, wn as verifyCommentEdit, wt as parseJsonWithPKCErrorIfFails, x as KeyvBetterSqlite3, xn as verifyChallengeMessage, xt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, y as RemoteCommunity, yn as signVote, yr as t$3, yt as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, z as InflightFetchManager, zn as buildRuntimeCommunityFields, zt as RpcExportCommunityModLogsParamSchema } from "./rpc-local-community-DfJ3wj-p.js";
4
+ import { s as getHeliaDebugContext } from "./util-DkyQHyK7.js";
5
5
  import path from "path";
6
6
  import assert from "assert";
7
7
  import fs from "fs";
@@ -8254,7 +8254,7 @@ var PKC$1 = class extends PKCTypedEmitter {
8254
8254
  this.clients.libp2pJsClients = {};
8255
8255
  if (!this.libp2pJsClientsOptions) return;
8256
8256
  if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
8257
- const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-hSpmyI9D.js");
8257
+ const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-BvltkMx7.js");
8258
8258
  for (const clientOptions of this.libp2pJsClientsOptions) {
8259
8259
  const heliaNode = await createLibp2pJsClientOrUseExistingOne({
8260
8260
  ...clientOptions,
@@ -8533,7 +8533,7 @@ var PKC$1 = class extends PKCTypedEmitter {
8533
8533
  const log = logger_default("pkc-js:pkc:createLocalCommunity");
8534
8534
  log.trace("Received community options to create a local community instance:", options);
8535
8535
  if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
8536
- const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-Dc_fNPrx.js");
8536
+ const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-Cm4X7RjW.js");
8537
8537
  const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
8538
8538
  const community = new LocalCommunity(this);
8539
8539
  if (isLocalCommunity) {
@@ -0,0 +1,112 @@
1
+ import { _ as getEquivalentCommunityAddresses, vn as PageSortFileSchema } from "./util-vJMTa4rC.js";
2
+ //#region dist/node/pages/page-sort-scoring.js
3
+ function validatePageSortFile(rawFile) {
4
+ const validated = PageSortFileSchema.parse(rawFile);
5
+ const raw = rawFile;
6
+ return {
7
+ ...validated,
8
+ score: raw.score,
9
+ ...raw.validatePageSortSettings ? { validatePageSortSettings: raw.validatePageSortSettings } : {}
10
+ };
11
+ }
12
+ function applyPageSortExclusions({ comments, exclusions, communityAddress }) {
13
+ const equivalentAddresses = communityAddress ? new Set(getEquivalentCommunityAddresses(communityAddress)) : void 0;
14
+ return comments.filter(({ comment, commentUpdate }) => {
15
+ if (exclusions.excludeRemovedComments && commentUpdate.removed === true) return false;
16
+ if (exclusions.excludeDeletedComments && commentUpdate.edit?.deleted === true) return false;
17
+ if (exclusions.excludeCommentWithApprovedFalse && commentUpdate.approved === false) return false;
18
+ if (exclusions.excludeCommentPendingApproval && commentUpdate.pendingApproval === true) return false;
19
+ if (exclusions.excludeCommentsWithDifferentCommunityAddress && equivalentAddresses) {
20
+ if (!((comment.communityPublicKey ? equivalentAddresses.has(comment.communityPublicKey) : false) || (comment.communityName ? equivalentAddresses.has(comment.communityName) : false))) return false;
21
+ }
22
+ return true;
23
+ });
24
+ }
25
+ function filterRepliesForPageSort({ replies, communityAddress }) {
26
+ return applyPageSortExclusions({
27
+ comments: replies,
28
+ exclusions: {
29
+ excludeRemovedComments: false,
30
+ excludeDeletedComments: false,
31
+ excludeCommentWithApprovedFalse: false,
32
+ excludeCommentPendingApproval: false,
33
+ excludeCommentsWithDifferentCommunityAddress: true
34
+ },
35
+ communityAddress
36
+ });
37
+ }
38
+ function partitionPageCommentsForSort({ comments, reserved, baseTimestamp }) {
39
+ const pinned = reserved.pinnedFirst ? comments.filter((entry) => entry.commentUpdate.pinned === true) : [];
40
+ let unpinned = reserved.pinnedFirst ? comments.filter((entry) => entry.commentUpdate.pinned !== true) : comments;
41
+ if (typeof reserved.maxAgeSeconds === "number") {
42
+ const timestampLower = baseTimestamp - reserved.maxAgeSeconds;
43
+ unpinned = unpinned.filter((entry) => entry.comment.timestamp >= timestampLower);
44
+ }
45
+ return {
46
+ pinned,
47
+ unpinned
48
+ };
49
+ }
50
+ function orderPageCommentsByScore({ pinned, unpinned, scoreOf, sortName }) {
51
+ const kept = (entries) => {
52
+ const scored = [];
53
+ for (const entry of entries) {
54
+ const score = scoreOf(entry);
55
+ if (score === null) continue;
56
+ if (typeof score !== "number" || Number.isNaN(score)) throw Error(`Page sort ${sortName} returned no numeric score for comment ${entry.commentUpdate.cid}`);
57
+ scored.push({
58
+ entry,
59
+ score
60
+ });
61
+ }
62
+ return scored.sort((a, b) => b.score - a.score).map(({ entry }) => entry);
63
+ };
64
+ return kept(pinned).concat(kept(unpinned));
65
+ }
66
+ function stripRepliesFromPageComment(entry) {
67
+ if (!("replies" in entry.commentUpdate)) return entry;
68
+ const { replies: _replies, ...commentUpdate } = entry.commentUpdate;
69
+ return {
70
+ comment: entry.comment,
71
+ commentUpdate
72
+ };
73
+ }
74
+ function createDescendantsLookup(replies) {
75
+ const childrenByParent = /* @__PURE__ */ new Map();
76
+ for (const entry of replies) {
77
+ const stripped = stripRepliesFromPageComment(entry);
78
+ const parentCid = stripped.comment.parentCid;
79
+ if (!parentCid) continue;
80
+ const siblings = childrenByParent.get(parentCid);
81
+ if (siblings) siblings.push(stripped);
82
+ else childrenByParent.set(parentCid, [stripped]);
83
+ }
84
+ return (cid) => {
85
+ const collected = [];
86
+ const stack = [cid];
87
+ while (stack.length) {
88
+ const children = childrenByParent.get(stack.pop());
89
+ if (!children) continue;
90
+ for (const child of children) {
91
+ collected.push(child);
92
+ stack.push(child.commentUpdate.cid);
93
+ }
94
+ }
95
+ return collected;
96
+ };
97
+ }
98
+ function scorePageCommentsWithFile({ file, options, baseTimestamp, replies, stripEntry = stripRepliesFromPageComment, descendantsOf: descendantsOfOverride }) {
99
+ const descendantsOf = file.requireReplies ? descendantsOfOverride ?? createDescendantsLookup(replies ?? []) : void 0;
100
+ return (entry) => {
101
+ const { comment, commentUpdate } = stripEntry(entry);
102
+ return file.score({
103
+ comment,
104
+ commentUpdate,
105
+ options,
106
+ baseTimestamp,
107
+ ...descendantsOf ? { replies: descendantsOf(commentUpdate.cid) } : {}
108
+ });
109
+ };
110
+ }
111
+ //#endregion
112
+ export { scorePageCommentsWithFile as a, partitionPageCommentsForSort as i, filterRepliesForPageSort as n, stripRepliesFromPageComment as o, orderPageCommentsByScore as r, validatePageSortFile as s, createDescendantsLookup as t };