@pkcprotocol/pkc-js 0.0.131 → 0.0.133

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 (98) hide show
  1. package/README.md +17 -7
  2. package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +2 -0
  3. package/dist/browser/clients/rpc-client/schema.d.ts +24 -0
  4. package/dist/browser/community/schema.d.ts +193 -0
  5. package/dist/browser/community/schema.js +4 -0
  6. package/dist/browser/community/schema.js.map +1 -1
  7. package/dist/browser/errors.d.ts +9 -1
  8. package/dist/browser/errors.js +9 -1
  9. package/dist/browser/errors.js.map +1 -1
  10. package/dist/browser/generated-version.d.ts +1 -1
  11. package/dist/browser/generated-version.js +1 -1
  12. package/dist/browser/index-with-compile-cache.d.ts +32 -0
  13. package/dist/browser/index.d.ts +64 -0
  14. package/dist/browser/pages/schema.d.ts +44 -0
  15. package/dist/browser/pkc-error.d.ts +1 -1
  16. package/dist/browser/publications/comment/comment.d.ts +1 -0
  17. package/dist/browser/publications/comment/comment.js +2 -0
  18. package/dist/browser/publications/comment/comment.js.map +1 -1
  19. package/dist/browser/publications/comment/schema.d.ts +133 -1
  20. package/dist/browser/publications/comment/schema.js +21 -6
  21. package/dist/browser/publications/comment/schema.js.map +1 -1
  22. package/dist/browser/publications/comment/types.d.ts +2 -1
  23. package/dist/browser/publications/community-edit/schema.d.ts +8 -0
  24. package/dist/browser/pubsub-messages/schema.d.ts +37 -0
  25. package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +32 -0
  26. package/dist/browser/rpc/src/schema.d.ts +192 -0
  27. package/dist/browser/runtime/node/community/db-handler.js +3 -2
  28. package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
  29. package/dist/browser/runtime/node/community/local-community/editing.js +60 -7
  30. package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
  31. package/dist/browser/runtime/node/community/local-community/publication-validation.js +41 -17
  32. package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -1
  33. package/dist/browser/runtime/node/polyfill.js +3 -1
  34. package/dist/browser/runtime/node/polyfill.js.map +1 -1
  35. package/dist/browser/schema/schema-util.d.ts +82 -0
  36. package/dist/browser/schema.d.ts +256 -0
  37. package/dist/browser/signer/signatures.js +18 -6
  38. package/dist/browser/signer/signatures.js.map +1 -1
  39. package/dist/browser/test/test-util.d.ts +40 -0
  40. package/dist/browser/version.js +1 -1
  41. package/dist/bundled/bundle-manifest.json +434 -211
  42. package/dist/bundled/challenges.js +1 -1
  43. package/dist/bundled/chunks/{helia-for-pkc-C7_eLx63.js → helia-for-pkc-B6cVl9Fj.js} +2 -2
  44. package/dist/bundled/chunks/{local-community-CtL1aSwt.js → local-community-CEsw9IC3.js} +1 -1
  45. package/dist/bundled/chunks/{local-community-RlYLG5QV.js → local-community-JxRohlLp.js} +114 -47
  46. package/dist/bundled/chunks/node-DsWFSaNV.js +36843 -0
  47. package/dist/bundled/chunks/{page-sort-scoring-CaoGFyhT.js → page-sort-scoring-iqMGLuRC.js} +1 -1
  48. package/dist/bundled/chunks/{rpc-local-community-BXt7eK9l.js → rpc-local-community-jndojGZl.js} +56870 -33780
  49. package/dist/bundled/chunks/{src-B07ldGHS.js → src-BggJ_InF.js} +435 -149
  50. package/dist/bundled/chunks/{src-629pKfxo.js → src-BsiPSkhv.js} +2 -2
  51. package/dist/bundled/chunks/{src-BOzgM7Fp.js → src-evzEHW9W.js} +26 -9
  52. package/dist/bundled/chunks/{util-CaL93qd4.js → util-Bna9pur0.js} +32 -9
  53. package/dist/bundled/chunks/{util-cD0RAlzC.js → util-CYgZRMVL.js} +1 -1
  54. package/dist/bundled/chunks/{validate-package-factories-DWI4TSli.js → validate-package-factories-FeyM9Tw1.js} +2 -2
  55. package/dist/bundled/index.js +1 -1
  56. package/dist/bundled/page-sorts.js +1 -1
  57. package/dist/bundled/rpc/src/index.js +4 -4
  58. package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +2 -0
  59. package/dist/node/clients/rpc-client/schema.d.ts +24 -0
  60. package/dist/node/community/schema.d.ts +193 -0
  61. package/dist/node/community/schema.js +4 -0
  62. package/dist/node/community/schema.js.map +1 -1
  63. package/dist/node/errors.d.ts +9 -1
  64. package/dist/node/errors.js +9 -1
  65. package/dist/node/errors.js.map +1 -1
  66. package/dist/node/generated-version.d.ts +1 -1
  67. package/dist/node/generated-version.js +1 -1
  68. package/dist/node/index-with-compile-cache.d.ts +32 -0
  69. package/dist/node/index.d.ts +64 -0
  70. package/dist/node/pages/schema.d.ts +44 -0
  71. package/dist/node/pkc-error.d.ts +1 -1
  72. package/dist/node/publications/comment/comment.d.ts +1 -0
  73. package/dist/node/publications/comment/comment.js +2 -0
  74. package/dist/node/publications/comment/comment.js.map +1 -1
  75. package/dist/node/publications/comment/schema.d.ts +133 -1
  76. package/dist/node/publications/comment/schema.js +21 -6
  77. package/dist/node/publications/comment/schema.js.map +1 -1
  78. package/dist/node/publications/comment/types.d.ts +2 -1
  79. package/dist/node/publications/community-edit/schema.d.ts +8 -0
  80. package/dist/node/pubsub-messages/schema.d.ts +37 -0
  81. package/dist/node/rpc/src/lib/pkc-js/index.d.ts +32 -0
  82. package/dist/node/rpc/src/schema.d.ts +192 -0
  83. package/dist/node/runtime/node/community/db-handler.js +3 -2
  84. package/dist/node/runtime/node/community/db-handler.js.map +1 -1
  85. package/dist/node/runtime/node/community/local-community/editing.js +60 -7
  86. package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
  87. package/dist/node/runtime/node/community/local-community/publication-validation.js +41 -17
  88. package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -1
  89. package/dist/node/runtime/node/polyfill.js +3 -1
  90. package/dist/node/runtime/node/polyfill.js.map +1 -1
  91. package/dist/node/schema/schema-util.d.ts +82 -0
  92. package/dist/node/schema.d.ts +256 -0
  93. package/dist/node/signer/signatures.js +18 -6
  94. package/dist/node/signer/signatures.js.map +1 -1
  95. package/dist/node/test/test-util.d.ts +40 -0
  96. package/dist/node/version.js +1 -1
  97. package/package.json +18 -18
  98. package/dist/bundled/chunks/node-DFp6m62Y.js +0 -9770
@@ -1,2 +1,2 @@
1
- import { t as validateChallengeFileFactory } from "./chunks/validate-package-factories-DWI4TSli.js";
1
+ import { t as validateChallengeFileFactory } from "./chunks/validate-package-factories-FeyM9Tw1.js";
2
2
  export { validateChallengeFileFactory };
@@ -1,6 +1,6 @@
1
1
  import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { C as hideClassPrivateProps, Lr as PKCError, T as ipnsNameToIpnsOverPubsubTopic, n as binaryKeyToPubsubTopic, zr as logger_default } from "./util-CaL93qd4.js";
3
- import { a as directFetchIpnsRecordFromProviders, c as readFreshCachedIpnsRecordFromPubsubLocalStore, i as connectToPubsubPeers, l as selectBitswapSessionSeedPeers, n as REACHABILITY_DOCS_URL, o as fetchBlockWithStalledSessionFailover, r as cacheIpnsRecordInPubsubLocalStore, s as getHeliaDebugContext, u as summarizeProviderReachability } from "./util-cD0RAlzC.js";
2
+ import { C as hideClassPrivateProps, Lr as PKCError, T as ipnsNameToIpnsOverPubsubTopic, n as binaryKeyToPubsubTopic, zr as logger_default } from "./util-Bna9pur0.js";
3
+ import { a as directFetchIpnsRecordFromProviders, c as readFreshCachedIpnsRecordFromPubsubLocalStore, i as connectToPubsubPeers, l as selectBitswapSessionSeedPeers, n as REACHABILITY_DOCS_URL, o as fetchBlockWithStalledSessionFailover, r as cacheIpnsRecordInPubsubLocalStore, s as getHeliaDebugContext, u as summarizeProviderReachability } from "./util-CYgZRMVL.js";
4
4
  import { t as map } from "./src-Cpx2Sts8.js";
5
5
  import { t as parallelBatch } from "./src-DKntVmyX.js";
6
6
  import { fileURLToPath } from "node:url";
@@ -1,2 +1,2 @@
1
- import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-RlYLG5QV.js";
1
+ import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-JxRohlLp.js";
2
2
  export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
@@ -1,16 +1,15 @@
1
1
  import { i as __toESM } from "./chunk-2rV9d50f.js";
2
- import { $ as retryKuboIpfsAddAndProvide, $n as CommentEditsTableRowSchema, At as ChallengeAnswerMessageSchema, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Ct as trackUpdatingCommunity, Dt as require_sha256, En as VotePubsubReservedFields, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeMfsFilesSafely, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, Jt as version_default, Lr as PKCError, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, On as VoteTablesRowSchema, Or as t$4, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Rr as messages, Sr as e, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Tr as t$3, Vn as CommentUpdateTableRowSchema, W as removeBlocksFromKuboNode, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Z as retryKuboBlockPutPinAndProvidePubsubTopic, Zn as CommentEditReservedFields, _ as genToArray, _r as t$7, at as timestamp, b as getIpnsRecordInLocalKuboNode, br as t$6, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeysDeep, dt as findStartedCommunity, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as n$3, hr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as require_retry, kr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as writeKuboFilesWithTimeout, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, nt as sleepUntilTimeoutOrAbort, o as calculateUnixFsDagSizeCidV0, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, q as removeNullUndefinedValues, r as calculateIpfsCidV0, rt as statMfsPathSafely, s as contentContainsMarkdownAudio, st as withSortedKeys, ti as ZodError, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$2, wr as r$1, wt as untrackStartedCommunity, xr as e$1, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$5, z as pubsubTopicToDhtKey, zn as CommentUpdateSchema, zr as logger_default, zt as DecryptedChallengeRequestPublicationSchema } from "./util-CaL93qd4.js";
3
- import { $ as createSchemaRowParser, An as verifyChallengeAnswer, Bn as verifyCommunityEdit, Br as t$8, Cr as getThumbnailPropsOfLink, Dr as moveCommunityDbToDeletedDirectory, Dt as parseJsonWithPKCErrorIfFails, En as signCommunity, Fn as verifyCommentIpfs, Fr as isCommunityStartLocked, Gr as stringify, Hn as verifyVote, Hr as n$4, In as verifyCommentModeration, Ir as require_src, Kn as getAuthorNameFromWire, Ln as verifyCommentPubsubMessage, Lr as t$10, Mn as verifyChallengeRequest, Mr as findCommunitiesEntry, N as MAX_PAGE_SIZE_BYTES, Or as refreshCommunitiesList, Pn as verifyCommentEdit, Q as collectSchemaRowCoercions, Qn as effectiveMaxCrosspostDepth, Rn as verifyCommentUpdate, Rr as t$11, S as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, Sn as signCommentEdit, Tn as signCommentUpdateForChallengeVerification, Un as buildRuntimeAuthor, Vr as n$5, W as pLimit, Wn as cleanWireAuthor, Wr as t$9, X as coerceSchemaRowBoolean, Xr as STORAGE_KEYS, Z as coerceSchemaRowJson, Zn as crosspostChainDepthUpTo, Zr as require_lodash_merge, _ as createAuthorIdentityMatcher, _r as deriveCommentIpfsFromCommentTableRow, a as generatePagesReportingFailedSorts, ar as encode, b as KeyvBetterSqlite3, bn as signChallengeVerification, c as resolvePageSortsOrThrow, cn as SignerWithPublicKeyAddress, cr as getPKCAddressFromPublicKey, d as getChallengeVerification, dr as BackupAbortError, dt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, f as getCommunityChallengeFromCommunityChallengeSettings, fn as decryptEd25519AesGcmPublicKeyBuffer, fr as backupCommunityDb, g as authorNameResolveFailureReason, gn as cleanUpBeforePublishing, gr as deleteOldCommunityInWindows, h as authorIdentityMatcherForRequest, hn as _validateSignatureOfPKCRecord, i as derivePublicPageSorts, ir as decode, j as iterateOverPageCidsToFindAllCids, kr as resolveDbPostsCidRefs, lr as getPKCAddressFromPublicKeySync, m as pkcJsChallenges, mn as encryptEd25519AesGcmPublicKeyBuffer, mr as calculateInlineRepliesBudget, nr as getCommunityPublicKeyFromWire, o as loadPageSortsForStartedCommunity, p as loadChallengeFileFromCommunityChallengeSettings, pr as calculateExpectedSignatureSize, pt as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, r as computePageSortsFingerprint, s as lookupPageSortFactories, sr as getIpfsKeyFromPrivateKey, t as RpcLocalCommunity, tr as getCommunityNameFromWire, u as deriveCommunityChallengesOrThrow, ur as getPublicKeyFromPrivateKey, v as TrackedInstanceRegistry, vn as signChallengeMessage, vr as deriveDbPosts, w as TIMEFRAMES_TO_SECONDS, wn as signCommentUpdate, wr as importSignerIntoKuboNode, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, xn as signComment, xr as getDefaultCommunityDbConfig, y as LRUCache, yr as deriveDbReplies, zn as verifyCommunity, zr as r$2 } from "./rpc-local-community-BXt7eK9l.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-CaoGFyhT.js";
5
- import { randomFillSync, randomUUID } from "node:crypto";
2
+ import { $ as retryKuboIpfsAddAndProvide, $n as CommentEditsTableRowSchema, At as ChallengeAnswerMessageSchema, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Ct as trackUpdatingCommunity, Dt as require_sha256, En as VotePubsubReservedFields, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeMfsFilesSafely, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, Jt as version_default, Lr as PKCError, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, On as VoteTablesRowSchema, Or as t$4, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Rr as messages, Sr as e, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Tr as t$3, Vn as CommentUpdateTableRowSchema, W as removeBlocksFromKuboNode, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Z as retryKuboBlockPutPinAndProvidePubsubTopic, Zn as CommentEditReservedFields, _ as genToArray, _r as t$7, at as timestamp, b as getIpnsRecordInLocalKuboNode, br as t$6, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeysDeep, dt as findStartedCommunity, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as n$3, hr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as require_retry, kr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as writeKuboFilesWithTimeout, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, nt as sleepUntilTimeoutOrAbort, o as calculateUnixFsDagSizeCidV0, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, q as removeNullUndefinedValues, r as calculateIpfsCidV0, rt as statMfsPathSafely, s as contentContainsMarkdownAudio, st as withSortedKeys, ti as ZodError, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$2, wr as r$1, wt as untrackStartedCommunity, xr as e$1, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$5, z as pubsubTopicToDhtKey, zn as CommentUpdateSchema, zr as logger_default, zt as DecryptedChallengeRequestPublicationSchema } from "./util-Bna9pur0.js";
3
+ import { $ as createSchemaRowParser, An as verifyChallengeAnswer, Bn as verifyCommunityEdit, Br as t$8, Cr as getThumbnailPropsOfLink, Dr as moveCommunityDbToDeletedDirectory, Dt as parseJsonWithPKCErrorIfFails, En as signCommunity, Fn as verifyCommentIpfs, Fr as isCommunityStartLocked, Gr as stringify, Hn as verifyVote, Hr as n$4, In as verifyCommentModeration, Ir as require_src, Kn as getAuthorNameFromWire, Ln as verifyCommentPubsubMessage, Lr as t$10, Mn as verifyChallengeRequest, Mr as findCommunitiesEntry, N as MAX_PAGE_SIZE_BYTES, Or as refreshCommunitiesList, Pn as verifyCommentEdit, Q as collectSchemaRowCoercions, Qn as effectiveMaxCrosspostDepth, Rn as verifyCommentUpdate, Rr as t$11, S as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, Sn as signCommentEdit, Tn as signCommentUpdateForChallengeVerification, Un as buildRuntimeAuthor, Vr as n$5, W as pLimit, Wn as cleanWireAuthor, Wr as t$9, X as coerceSchemaRowBoolean, Xr as STORAGE_KEYS, Z as coerceSchemaRowJson, Zn as crosspostChainDepthUpTo, Zr as require_lodash_merge, _ as createAuthorIdentityMatcher, _r as deriveCommentIpfsFromCommentTableRow, a as generatePagesReportingFailedSorts, ar as encode, b as KeyvBetterSqlite3, bn as signChallengeVerification, c as resolvePageSortsOrThrow, cn as SignerWithPublicKeyAddress, cr as getPKCAddressFromPublicKey, d as getChallengeVerification, dr as BackupAbortError, dt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, f as getCommunityChallengeFromCommunityChallengeSettings, fn as decryptEd25519AesGcmPublicKeyBuffer, fr as backupCommunityDb, g as authorNameResolveFailureReason, gn as cleanUpBeforePublishing, gr as deleteOldCommunityInWindows, h as authorIdentityMatcherForRequest, hn as _validateSignatureOfPKCRecord, i as derivePublicPageSorts, ir as decode, j as iterateOverPageCidsToFindAllCids, kr as resolveDbPostsCidRefs, lr as getPKCAddressFromPublicKeySync, m as pkcJsChallenges, mn as encryptEd25519AesGcmPublicKeyBuffer, mr as calculateInlineRepliesBudget, nr as getCommunityPublicKeyFromWire, o as loadPageSortsForStartedCommunity, p as loadChallengeFileFromCommunityChallengeSettings, pr as calculateExpectedSignatureSize, pt as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, r as computePageSortsFingerprint, s as lookupPageSortFactories, sr as getIpfsKeyFromPrivateKey, t as RpcLocalCommunity, tr as getCommunityNameFromWire, u as deriveCommunityChallengesOrThrow, ur as getPublicKeyFromPrivateKey, v as TrackedInstanceRegistry, vn as signChallengeMessage, vr as deriveDbPosts, w as TIMEFRAMES_TO_SECONDS, wn as signCommentUpdate, wr as importSignerIntoKuboNode, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, xn as signComment, xr as getDefaultCommunityDbConfig, y as LRUCache, yr as deriveDbReplies, zn as verifyCommunity, zr as r$2 } from "./rpc-local-community-jndojGZl.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-iqMGLuRC.js";
6
5
  import { fileURLToPath, pathToFileURL } from "node:url";
7
6
  import path from "node:path";
8
7
  import os from "os";
9
- import { existsSync, promises } from "node:fs";
8
+ import fs, { existsSync, promises } from "node:fs";
10
9
  import path$1 from "path";
11
10
  import assert from "assert";
12
11
  import { Buffer as Buffer$1 } from "buffer";
13
- import fs from "fs";
12
+ import fs$1 from "fs";
14
13
  import Database from "better-sqlite3";
15
14
  import { CID } from "multiformats/cid";
16
15
  import { peerIdFromString } from "@libp2p/peer-id";
@@ -184,18 +183,10 @@ async function reprovideAnchorRecordIfDue(community) {
184
183
  await reprovideAnchorRecordIfNeeded(community);
185
184
  }
186
185
  //#endregion
187
- //#region node_modules/uuid/dist-node/native.js
188
- var native_default = { randomUUID };
189
- //#endregion
190
186
  //#region node_modules/uuid/dist-node/rng.js
191
- const rnds8Pool = new Uint8Array(256);
192
- let poolPtr = rnds8Pool.length;
187
+ const rnds8 = new Uint8Array(16);
193
188
  function rng() {
194
- if (poolPtr > rnds8Pool.length - 16) {
195
- randomFillSync(rnds8Pool);
196
- poolPtr = 0;
197
- }
198
- return rnds8Pool.slice(poolPtr, poolPtr += 16);
189
+ return crypto.getRandomValues(rnds8);
199
190
  }
200
191
  //#endregion
201
192
  //#region node_modules/uuid/dist-node/stringify.js
@@ -206,6 +197,10 @@ function unsafeStringify(arr, offset = 0) {
206
197
  }
207
198
  //#endregion
208
199
  //#region node_modules/uuid/dist-node/v4.js
200
+ function v4(options, buf, offset) {
201
+ if (!buf && !options && crypto.randomUUID) return crypto.randomUUID();
202
+ return _v4(options, buf, offset);
203
+ }
209
204
  function _v4(options, buf, offset) {
210
205
  options = options || {};
211
206
  const rnds = options.random ?? options.rng?.() ?? rng();
@@ -220,10 +215,6 @@ function _v4(options, buf, offset) {
220
215
  }
221
216
  return unsafeStringify(rnds);
222
217
  }
223
- function v4(options, buf, offset) {
224
- if (native_default.randomUUID && !buf && !options) return native_default.randomUUID();
225
- return _v4(options, buf, offset);
226
- }
227
218
  //#endregion
228
219
  //#region dist/node/runtime/node/community/local-community/defaults.js
229
220
  const DUPLICATE_PUBLICATION_ERRORS = new Set([
@@ -328,7 +319,7 @@ function normalizeRegistryDataPath(dataPath) {
328
319
  let existing = resolved;
329
320
  let tail = "";
330
321
  while (true) try {
331
- return path$1.join(fs.realpathSync.native(existing), tail);
322
+ return path$1.join(fs$1.realpathSync.native(existing), tail);
332
323
  } catch {
333
324
  const parent = path$1.dirname(existing);
334
325
  if (parent === existing) return resolved;
@@ -1549,6 +1540,7 @@ var DbHandler = class {
1549
1540
  pseudonymityMode TEXT NULLABLE,
1550
1541
  quotedCids TEXT NULLABLE, -- JSON array
1551
1542
  crosspost TEXT NULLABLE, -- JSON: {cid, comment} of the comment this one reposts, stored verbatim so the embedded record keeps reproducing its cid
1543
+ gallery TEXT NULLABLE, -- JSON array of media items, stored verbatim since items are loose and author-signed
1552
1544
  extraProps TEXT NULLABLE, -- JSON
1553
1545
  challengeCommentUpdate TEXT NULLABLE, -- JSON: challenge-supplied partial CommentUpdate seeded into queryCalculatedCommentUpdate with lowest priority
1554
1546
  protocolVersion TEXT NOT NULL,
@@ -1708,13 +1700,13 @@ var DbHandler = class {
1708
1700
  const needToMigrate = currentDbVersion < version_default.DB_VERSION;
1709
1701
  const dbPath = this._dbConfig.filename;
1710
1702
  let backupDbPath;
1711
- const dbExistsAlready = fs.existsSync(dbPath);
1703
+ const dbExistsAlready = fs$1.existsSync(dbPath);
1712
1704
  if (needToMigrate) {
1713
1705
  if (dbExistsAlready && currentDbVersion > 0) {
1714
1706
  this.destoryConnection();
1715
1707
  backupDbPath = path$1.join(path$1.dirname(dbPath), ".backup_before_migration", `${path$1.basename(dbPath)}.${currentDbVersion}.${timestamp()}`);
1716
1708
  log(`Copying db ${path$1.basename(dbPath)} to ${backupDbPath} before migration`);
1717
- if (!fs.existsSync(path$1.dirname(backupDbPath))) await fs.promises.mkdir(path$1.dirname(backupDbPath), { recursive: true });
1709
+ if (!fs$1.existsSync(path$1.dirname(backupDbPath))) await fs$1.promises.mkdir(path$1.dirname(backupDbPath), { recursive: true });
1718
1710
  const sourceDb = new Database(dbPath, { fileMustExist: true });
1719
1711
  await sourceDb.backup(backupDbPath);
1720
1712
  sourceDb.close();
@@ -1797,7 +1789,7 @@ var DbHandler = class {
1797
1789
  this._columnNamesByTable = {};
1798
1790
  this._preparedStatements.clear();
1799
1791
  if (needToMigrate) log(`Created/migrated the tables to the latest (${newDbVersion}) version and saved to path`, this._dbConfig.filename);
1800
- if (backupDbPath) await fs.promises.rm(backupDbPath);
1792
+ if (backupDbPath) await fs$1.promises.rm(backupDbPath);
1801
1793
  }
1802
1794
  _tableExists(tableName) {
1803
1795
  return !!this._db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = ?").get(tableName);
@@ -2117,8 +2109,8 @@ var DbHandler = class {
2117
2109
  const columnNames = this._getColumnNames(TABLES.COMMENTS);
2118
2110
  const stmt = this._db.prepare(`
2119
2111
  INSERT INTO ${TABLES.COMMENTS}
2120
- (cid, authorSignerAddress, author, link, linkWidth, linkHeight, thumbnailUrl, thumbnailUrlWidth, thumbnailUrlHeight, parentCid, postCid, previousCid, communityPublicKey, communityName, content, timestamp, signature, originalCommentSignatureEncoded, title, depth, linkHtmlTagName, flairs, spoiler, pendingApproval, number, postNumber, nsfw, pseudonymityMode, quotedCids, crosspost, extraProps, challengeCommentUpdate, protocolVersion, insertedAt)
2121
- VALUES (@cid, @authorSignerAddress, @author, @link, @linkWidth, @linkHeight, @thumbnailUrl, @thumbnailUrlWidth, @thumbnailUrlHeight, @parentCid, @postCid, @previousCid, @communityPublicKey, @communityName, @content, @timestamp, @signature, @originalCommentSignatureEncoded, @title, @depth, @linkHtmlTagName, @flairs, @spoiler, @pendingApproval, @number, @postNumber, @nsfw, @pseudonymityMode, @quotedCids, @crosspost, @extraProps, @challengeCommentUpdate, @protocolVersion, @insertedAt)
2112
+ (cid, authorSignerAddress, author, link, linkWidth, linkHeight, thumbnailUrl, thumbnailUrlWidth, thumbnailUrlHeight, parentCid, postCid, previousCid, communityPublicKey, communityName, content, timestamp, signature, originalCommentSignatureEncoded, title, depth, linkHtmlTagName, flairs, spoiler, pendingApproval, number, postNumber, nsfw, pseudonymityMode, quotedCids, crosspost, gallery, extraProps, challengeCommentUpdate, protocolVersion, insertedAt)
2113
+ VALUES (@cid, @authorSignerAddress, @author, @link, @linkWidth, @linkHeight, @thumbnailUrl, @thumbnailUrlWidth, @thumbnailUrlHeight, @parentCid, @postCid, @previousCid, @communityPublicKey, @communityName, @content, @timestamp, @signature, @originalCommentSignatureEncoded, @title, @depth, @linkHtmlTagName, @flairs, @spoiler, @pendingApproval, @number, @postNumber, @nsfw, @pseudonymityMode, @quotedCids, @crosspost, @gallery, @extraProps, @challengeCommentUpdate, @protocolVersion, @insertedAt)
2122
2114
  `);
2123
2115
  const defaults = t$5(columnNames, (column) => [column, null]);
2124
2116
  this._db.transaction((items) => {
@@ -3815,16 +3807,16 @@ var DbHandler = class {
3815
3807
  const dataPath = this._community._pkc.dataPath;
3816
3808
  const oldPathString = path$1.join(dataPath, "communities", oldDbName);
3817
3809
  const newPathString = path$1.join(dataPath, "communities", newDbName);
3818
- await fs.promises.mkdir(path$1.dirname(oldPathString), { recursive: true });
3819
- await fs.promises.mkdir(path$1.dirname(newPathString), { recursive: true });
3810
+ await fs$1.promises.mkdir(path$1.dirname(oldPathString), { recursive: true });
3811
+ await fs$1.promises.mkdir(path$1.dirname(newPathString), { recursive: true });
3820
3812
  try {
3821
- if (!fs.existsSync(oldPathString)) log(`Old DB file ${oldPathString} does not exist. Cannot backup/rename.`);
3813
+ if (!fs$1.existsSync(oldPathString)) log(`Old DB file ${oldPathString} does not exist. Cannot backup/rename.`);
3822
3814
  else {
3823
3815
  const sourceDb = new Database(oldPathString, { fileMustExist: true });
3824
3816
  await sourceDb.backup(newPathString);
3825
3817
  sourceDb.close();
3826
3818
  if (os.type() === "Windows_NT") await deleteOldCommunityInWindows(oldPathString, this._community._pkc);
3827
- else await fs.promises.rm(oldPathString, { force: true });
3819
+ else await fs$1.promises.rm(oldPathString, { force: true });
3828
3820
  }
3829
3821
  } catch (error) {
3830
3822
  log.error(`Failed to backup/rename database from ${oldPathString} to ${newPathString}: `, error);
@@ -3862,7 +3854,7 @@ var DbHandler = class {
3862
3854
  log.trace(`Attempting to unlock the start of community (${communityAddress})`);
3863
3855
  const lockfilePath = path$1.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
3864
3856
  const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", communityAddress);
3865
- if (!fs.existsSync(lockfilePath) || !fs.existsSync(communityDbPath)) return;
3857
+ if (!fs$1.existsSync(lockfilePath) || !fs$1.existsSync(communityDbPath)) return;
3866
3858
  try {
3867
3859
  await import_src.default.unlock(communityDbPath, { lockfilePath });
3868
3860
  log(`Unlocked start of community (${communityAddress})`);
@@ -3899,7 +3891,7 @@ var DbHandler = class {
3899
3891
  const log = logger_default("pkc-js:local-community:db-handler:lock:unlockCommunityState");
3900
3892
  const lockfilePath = path$1.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
3901
3893
  const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", this._community.address);
3902
- if (!fs.existsSync(lockfilePath)) return;
3894
+ if (!fs$1.existsSync(lockfilePath)) return;
3903
3895
  try {
3904
3896
  await import_src.default.unlock(communityDbPath, { lockfilePath });
3905
3897
  } catch (e) {
@@ -3909,7 +3901,7 @@ var DbHandler = class {
3909
3901
  }
3910
3902
  communityDbExists() {
3911
3903
  const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", this._community.address);
3912
- return fs.existsSync(communityDbPath);
3904
+ return fs$1.existsSync(communityDbPath);
3913
3905
  }
3914
3906
  markCommentsAsPublishedToPostUpdates(commentCids) {
3915
3907
  if (commentCids.length === 0) return;
@@ -5245,6 +5237,24 @@ async function checkParentAndPostState(community, request, publication, authorId
5245
5237
  if (isCommentDisapproved && !isCommentDisapproved.approved && !("commentModeration" in request) && !(request.commentEdit?.deleted === true)) return messages.ERR_USER_PUBLISHED_UNDER_DISAPPROVED_COMMENT;
5246
5238
  }
5247
5239
  }
5240
+ const GALLERY_HTML_TAG_NAME_BY_MIME_CATEGORY = {
5241
+ image: "img",
5242
+ video: "video",
5243
+ audio: "audio"
5244
+ };
5245
+ function checkCommentGallery(community, commentPublication) {
5246
+ const gallery = commentPublication.gallery;
5247
+ if (!gallery) return void 0;
5248
+ const isReply = Boolean(commentPublication.parentCid);
5249
+ const maxItems = isReply ? community.features?.maxReplyGalleryItems : community.features?.maxPostGalleryItems;
5250
+ if (!maxItems) return isReply ? messages.ERR_REPLY_GALLERY_NOT_ALLOWED : messages.ERR_POST_GALLERY_NOT_ALLOWED;
5251
+ if (gallery.length > maxItems) return isReply ? messages.ERR_REPLY_GALLERY_EXCEEDS_MAX_ITEMS : messages.ERR_POST_GALLERY_EXCEEDS_MAX_ITEMS;
5252
+ for (const item of gallery) {
5253
+ if (!isLinkValid(item.url) || !isLinkOfMedia(item.url)) return messages.ERR_GALLERY_ITEM_NOT_MEDIA;
5254
+ const mimeCategory = isLinkOfImage(item.url) ? "image" : isLinkOfVideo(item.url) ? "video" : "audio";
5255
+ if (item.htmlTagName !== GALLERY_HTML_TAG_NAME_BY_MIME_CATEGORY[mimeCategory]) return messages.ERR_GALLERY_ITEM_HTML_TAG_NAME_MISMATCH;
5256
+ }
5257
+ }
5248
5258
  async function checkCommentPublication(community, request) {
5249
5259
  if (!request.comment) return void 0;
5250
5260
  const commentPublication = request.comment;
@@ -5253,17 +5263,23 @@ async function checkCommentPublication(community, request) {
5253
5263
  if (community.features?.requirePostLinkIsMedia && commentPublication.link && (!isLinkValid(commentPublication.link) || !isLinkOfMedia(commentPublication.link))) return messages.ERR_POST_LINK_IS_NOT_OF_MEDIA;
5254
5264
  if (community.features?.requireReplyLink && commentPublication.parentCid && (!commentPublication.link || !community.features?.requireReplyLinkIsMedia && !isLinkValid(commentPublication.link))) return messages.ERR_REPLY_HAS_INVALID_LINK_FIELD;
5255
5265
  if (community.features?.requireReplyLinkIsMedia && commentPublication.parentCid && commentPublication.link && (!isLinkValid(commentPublication.link) || !isLinkOfMedia(commentPublication.link))) return messages.ERR_REPLY_LINK_IS_NOT_OF_MEDIA;
5266
+ const galleryError = checkCommentGallery(community, commentPublication);
5267
+ if (galleryError) return galleryError;
5256
5268
  if (community.features?.noMarkdownImages && commentPublication.content && contentContainsMarkdownImages(commentPublication.content)) return messages.ERR_COMMENT_CONTENT_CONTAINS_MARKDOWN_IMAGE;
5257
5269
  if (community.features?.noMarkdownVideos && commentPublication.content && contentContainsMarkdownVideos(commentPublication.content)) return messages.ERR_COMMENT_CONTENT_CONTAINS_MARKDOWN_VIDEO;
5258
5270
  if (community.features?.noMarkdownAudio && commentPublication.content && contentContainsMarkdownAudio(commentPublication.content)) return messages.ERR_COMMENT_CONTENT_CONTAINS_MARKDOWN_AUDIO;
5259
- if (community.features?.noImages && commentPublication.link && isLinkOfImage(commentPublication.link)) return messages.ERR_COMMENT_HAS_LINK_THAT_IS_IMAGE;
5260
- if (community.features?.noVideos && commentPublication.link && (isLinkOfVideo(commentPublication.link) || isLinkOfAnimatedImage(commentPublication.link))) return messages.ERR_COMMENT_HAS_LINK_THAT_IS_VIDEO;
5271
+ const mediaUrls = [...commentPublication.link ? [commentPublication.link] : [], ...commentPublication.gallery?.map((item) => item.url) ?? []];
5272
+ const hasImage = mediaUrls.some(isLinkOfImage);
5273
+ const hasVideo = mediaUrls.some((url) => isLinkOfVideo(url) || isLinkOfAnimatedImage(url));
5274
+ const hasAudio = mediaUrls.some(isLinkOfAudio);
5275
+ if (community.features?.noImages && hasImage) return messages.ERR_COMMENT_HAS_LINK_THAT_IS_IMAGE;
5276
+ if (community.features?.noVideos && hasVideo) return messages.ERR_COMMENT_HAS_LINK_THAT_IS_VIDEO;
5261
5277
  if (community.features?.noSpoilers && commentPublication.spoiler === true) return messages.ERR_COMMENT_HAS_SPOILER_ENABLED;
5262
- if (community.features?.noImageReplies && commentPublication.parentCid && commentPublication.link && isLinkOfImage(commentPublication.link)) return messages.ERR_REPLY_HAS_LINK_THAT_IS_IMAGE;
5263
- if (community.features?.noVideoReplies && commentPublication.parentCid && commentPublication.link && (isLinkOfVideo(commentPublication.link) || isLinkOfAnimatedImage(commentPublication.link))) return messages.ERR_REPLY_HAS_LINK_THAT_IS_VIDEO;
5278
+ if (community.features?.noImageReplies && commentPublication.parentCid && hasImage) return messages.ERR_REPLY_HAS_LINK_THAT_IS_IMAGE;
5279
+ if (community.features?.noVideoReplies && commentPublication.parentCid && hasVideo) return messages.ERR_REPLY_HAS_LINK_THAT_IS_VIDEO;
5264
5280
  if (community.features?.noReplyLinks && commentPublication.parentCid && commentPublication.link) return messages.ERR_REPLY_HAS_LINK;
5265
- if (community.features?.noAudio && commentPublication.link && isLinkOfAudio(commentPublication.link)) return messages.ERR_COMMENT_HAS_LINK_THAT_IS_AUDIO;
5266
- if (community.features?.noAudioReplies && commentPublication.parentCid && commentPublication.link && isLinkOfAudio(commentPublication.link)) return messages.ERR_REPLY_HAS_LINK_THAT_IS_AUDIO;
5281
+ if (community.features?.noAudio && hasAudio) return messages.ERR_COMMENT_HAS_LINK_THAT_IS_AUDIO;
5282
+ if (community.features?.noAudioReplies && commentPublication.parentCid && hasAudio) return messages.ERR_REPLY_HAS_LINK_THAT_IS_AUDIO;
5267
5283
  if (community.features?.noSpoilerReplies && commentPublication.parentCid && commentPublication.spoiler === true) return messages.ERR_REPLY_HAS_SPOILER_ENABLED;
5268
5284
  if (community.features?.noNestedReplies && commentPublication.parentCid) {
5269
5285
  const parent = community._dbHandler.queryComment(commentPublication.parentCid);
@@ -6886,22 +6902,73 @@ function deriveNameAndAddressEdit(community, editOptions) {
6886
6902
  function listRenamedCommunityNow(community) {
6887
6903
  refreshCommunitiesList(community._pkc);
6888
6904
  }
6905
+ async function restoreCommunityAfterFailedRename({ community, oldAddress, newAddress, postUpdatesFolderMoved, log }) {
6906
+ try {
6907
+ if (postUpdatesFolderMoved) await movePostUpdatesFolderToNewAddress(community, newAddress, oldAddress);
6908
+ await community.start();
6909
+ } catch (restoreError) {
6910
+ log.error(`Failed to restore community (${oldAddress}) after its rename to ${newAddress} failed`, restoreError);
6911
+ community.emit("error", restoreError);
6912
+ }
6913
+ }
6914
+ async function removePartialDbCopy({ community, oldAddress, newAddress, log }) {
6915
+ const communitiesPath = path.join(community._pkc.dataPath, "communities");
6916
+ if (!fs.existsSync(path.join(communitiesPath, oldAddress))) return;
6917
+ try {
6918
+ await fs.promises.rm(path.join(communitiesPath, newAddress), { force: true });
6919
+ } catch (e) {
6920
+ log.error(`Failed to remove the partial DB copy of community (${oldAddress}) at ${newAddress}`, e);
6921
+ }
6922
+ }
6889
6923
  async function editPropsOnStartedCommunity(community, parsedEditOptions, pagesEdit) {
6890
6924
  const log = logger_default("pkc-js:local-community:start:editPropsOnStartedCommunity");
6891
6925
  const oldAddress = t$9(community.address);
6926
+ const uniqueEditId = (0, import_sha256.sha256)(stringify(parsedEditOptions));
6892
6927
  if (typeof parsedEditOptions.address === "string" && community.address !== parsedEditOptions.address) {
6893
- await validateNewAddressBeforeEditing(community, parsedEditOptions.address, log);
6894
- log(`Attempting to edit community.address from ${oldAddress} to ${parsedEditOptions.address}. We will stop community first`);
6928
+ const newAddress = parsedEditOptions.address;
6929
+ await validateNewAddressBeforeEditing(community, newAddress, log);
6930
+ log(`Attempting to edit community.address from ${oldAddress} to ${newAddress}. We will stop community first`);
6895
6931
  await community.stop();
6896
- await community._dbHandler.changeDbFilename(oldAddress, parsedEditOptions.address);
6932
+ try {
6933
+ await movePostUpdatesFolderToNewAddress(community, oldAddress, newAddress);
6934
+ } catch (e) {
6935
+ await restoreCommunityAfterFailedRename({
6936
+ community,
6937
+ oldAddress,
6938
+ newAddress,
6939
+ postUpdatesFolderMoved: false,
6940
+ log
6941
+ });
6942
+ throw e;
6943
+ }
6944
+ try {
6945
+ await community._dbHandler.changeDbFilename(oldAddress, newAddress);
6946
+ } catch (e) {
6947
+ await removePartialDbCopy({
6948
+ community,
6949
+ oldAddress,
6950
+ newAddress,
6951
+ log
6952
+ });
6953
+ await restoreCommunityAfterFailedRename({
6954
+ community,
6955
+ oldAddress,
6956
+ newAddress,
6957
+ postUpdatesFolderMoved: true,
6958
+ log
6959
+ });
6960
+ throw e;
6961
+ }
6897
6962
  listRenamedCommunityNow(community);
6898
- community.setAddress(parsedEditOptions.address);
6963
+ community.setAddress(newAddress);
6899
6964
  await community._dbHandler.initDbIfNeeded();
6965
+ await updateDbInternalState(community, { ...parsedEditOptions });
6966
+ community._pendingEditProps.push({
6967
+ ...parsedEditOptions,
6968
+ editId: uniqueEditId
6969
+ });
6900
6970
  await community.start();
6901
- await movePostUpdatesFolderToNewAddress(community, oldAddress, parsedEditOptions.address);
6902
- }
6903
- const uniqueEditId = (0, import_sha256.sha256)(stringify(parsedEditOptions));
6904
- community._pendingEditProps.push({
6971
+ } else community._pendingEditProps.push({
6905
6972
  ...parsedEditOptions,
6906
6973
  editId: uniqueEditId
6907
6974
  });