@pkcprotocol/pkc-js 0.0.116 → 0.0.117

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 (39) hide show
  1. package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +16 -0
  2. package/dist/browser/clients/rpc-client/pkc-rpc-client.js +199 -43
  3. package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
  4. package/dist/browser/errors.d.ts +2 -0
  5. package/dist/browser/errors.js +2 -0
  6. package/dist/browser/errors.js.map +1 -1
  7. package/dist/browser/generated-version.d.ts +1 -1
  8. package/dist/browser/generated-version.js +1 -1
  9. package/dist/browser/pkc-error.d.ts +1 -1
  10. package/dist/browser/rpc/src/index.d.ts +5 -1
  11. package/dist/browser/rpc/src/index.js +28 -2
  12. package/dist/browser/rpc/src/index.js.map +1 -1
  13. package/dist/bundled/bundle-manifest.json +34 -34
  14. package/dist/bundled/challenges.js +1 -1
  15. package/dist/bundled/chunks/{helia-for-pkc-BvltkMx7.js → helia-for-pkc-DuG274FA.js} +2 -2
  16. package/dist/bundled/chunks/{local-community-Cm4X7RjW.js → local-community-BsALoql_.js} +1 -1
  17. package/dist/bundled/chunks/{local-community-nSmHRx5s.js → local-community-XUj49rN_.js} +3 -3
  18. package/dist/bundled/chunks/{node-CaeXEQ5O.js → node-DkNDHK6w.js} +169 -53
  19. package/dist/bundled/chunks/{page-sort-scoring-Bj73WnwW.js → page-sort-scoring-Cd97obb3.js} +1 -1
  20. package/dist/bundled/chunks/{rpc-local-community-DfJ3wj-p.js → rpc-local-community-7uUa4lxH.js} +2 -2
  21. package/dist/bundled/chunks/{util-DkyQHyK7.js → util-BMGkXifx.js} +1 -1
  22. package/dist/bundled/chunks/{util-vJMTa4rC.js → util-Bm9ef_d5.js} +3 -1
  23. package/dist/bundled/chunks/{validate-package-factories-tZC8XxoO.js → validate-package-factories-DHupf8eD.js} +2 -2
  24. package/dist/bundled/index.js +1 -1
  25. package/dist/bundled/page-sorts.js +1 -1
  26. package/dist/bundled/rpc/src/index.js +23 -6
  27. package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +16 -0
  28. package/dist/node/clients/rpc-client/pkc-rpc-client.js +199 -43
  29. package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
  30. package/dist/node/errors.d.ts +2 -0
  31. package/dist/node/errors.js +2 -0
  32. package/dist/node/errors.js.map +1 -1
  33. package/dist/node/generated-version.d.ts +1 -1
  34. package/dist/node/generated-version.js +1 -1
  35. package/dist/node/pkc-error.d.ts +1 -1
  36. package/dist/node/rpc/src/index.d.ts +5 -1
  37. package/dist/node/rpc/src/index.js +28 -2
  38. package/dist/node/rpc/src/index.js.map +1 -1
  39. package/package.json +1 -1
@@ -3,7 +3,7 @@
3
3
  "challenges.js": {
4
4
  "isEntry": true,
5
5
  "imports": [
6
- "chunks/validate-package-factories-tZC8XxoO.js"
6
+ "chunks/validate-package-factories-DHupf8eD.js"
7
7
  ],
8
8
  "dynamicImports": [],
9
9
  "inputs": [
@@ -16,7 +16,7 @@
16
16
  "node:module"
17
17
  ],
18
18
  "dynamicImports": [
19
- "chunks/node-CaeXEQ5O.js"
19
+ "chunks/node-DkNDHK6w.js"
20
20
  ],
21
21
  "inputs": [
22
22
  "dist/node/runtime/node/compile-cache.js",
@@ -26,7 +26,7 @@
26
26
  "index.js": {
27
27
  "isEntry": true,
28
28
  "imports": [
29
- "chunks/node-CaeXEQ5O.js"
29
+ "chunks/node-DkNDHK6w.js"
30
30
  ],
31
31
  "dynamicImports": [],
32
32
  "inputs": []
@@ -34,7 +34,7 @@
34
34
  "page-sorts.js": {
35
35
  "isEntry": true,
36
36
  "imports": [
37
- "chunks/validate-package-factories-tZC8XxoO.js"
37
+ "chunks/validate-package-factories-DHupf8eD.js"
38
38
  ],
39
39
  "dynamicImports": [],
40
40
  "inputs": [
@@ -44,10 +44,10 @@
44
44
  "rpc/src/index.js": {
45
45
  "isEntry": true,
46
46
  "imports": [
47
- "chunks/rpc-local-community-DfJ3wj-p.js",
48
- "chunks/node-CaeXEQ5O.js",
49
- "chunks/util-vJMTa4rC.js",
50
- "chunks/local-community-nSmHRx5s.js",
47
+ "chunks/rpc-local-community-7uUa4lxH.js",
48
+ "chunks/node-DkNDHK6w.js",
49
+ "chunks/util-Bm9ef_d5.js",
50
+ "chunks/local-community-XUj49rN_.js",
51
51
  "node:url",
52
52
  "path",
53
53
  "assert",
@@ -77,12 +77,12 @@
77
77
  "\u0000rolldown/runtime.js"
78
78
  ]
79
79
  },
80
- "chunks/helia-for-pkc-BvltkMx7.js": {
80
+ "chunks/helia-for-pkc-DuG274FA.js": {
81
81
  "isEntry": false,
82
82
  "imports": [
83
83
  "chunks/chunk-2rV9d50f.js",
84
- "chunks/util-vJMTa4rC.js",
85
- "chunks/util-DkyQHyK7.js",
84
+ "chunks/util-Bm9ef_d5.js",
85
+ "chunks/util-BMGkXifx.js",
86
86
  "chunks/src-DKntVmyX.js",
87
87
  "chunks/src-Cpx2Sts8.js",
88
88
  "node:url",
@@ -201,21 +201,21 @@
201
201
  "dist/node/helia/helia-for-pkc.js"
202
202
  ]
203
203
  },
204
- "chunks/local-community-Cm4X7RjW.js": {
204
+ "chunks/local-community-BsALoql_.js": {
205
205
  "isEntry": false,
206
206
  "imports": [
207
- "chunks/local-community-nSmHRx5s.js"
207
+ "chunks/local-community-XUj49rN_.js"
208
208
  ],
209
209
  "dynamicImports": [],
210
210
  "inputs": []
211
211
  },
212
- "chunks/local-community-nSmHRx5s.js": {
212
+ "chunks/local-community-XUj49rN_.js": {
213
213
  "isEntry": false,
214
214
  "imports": [
215
215
  "chunks/chunk-2rV9d50f.js",
216
- "chunks/rpc-local-community-DfJ3wj-p.js",
217
- "chunks/util-vJMTa4rC.js",
218
- "chunks/page-sort-scoring-Bj73WnwW.js",
216
+ "chunks/rpc-local-community-7uUa4lxH.js",
217
+ "chunks/util-Bm9ef_d5.js",
218
+ "chunks/page-sort-scoring-Cd97obb3.js",
219
219
  "node:crypto",
220
220
  "node:url",
221
221
  "node:path",
@@ -274,13 +274,13 @@
274
274
  "dist/node/runtime/node/community/local-community.js"
275
275
  ]
276
276
  },
277
- "chunks/node-CaeXEQ5O.js": {
277
+ "chunks/node-DkNDHK6w.js": {
278
278
  "isEntry": false,
279
279
  "imports": [
280
280
  "chunks/chunk-2rV9d50f.js",
281
- "chunks/rpc-local-community-DfJ3wj-p.js",
282
- "chunks/util-vJMTa4rC.js",
283
- "chunks/util-DkyQHyK7.js",
281
+ "chunks/rpc-local-community-7uUa4lxH.js",
282
+ "chunks/util-Bm9ef_d5.js",
283
+ "chunks/util-BMGkXifx.js",
284
284
  "path",
285
285
  "assert",
286
286
  "fs",
@@ -291,8 +291,8 @@
291
291
  "rpc-websockets"
292
292
  ],
293
293
  "dynamicImports": [
294
- "chunks/helia-for-pkc-BvltkMx7.js",
295
- "chunks/local-community-nSmHRx5s.js"
294
+ "chunks/helia-for-pkc-DuG274FA.js",
295
+ "chunks/local-community-XUj49rN_.js"
296
296
  ],
297
297
  "inputs": [
298
298
  "node_modules/zod/v4/locales/en.js",
@@ -339,22 +339,22 @@
339
339
  "dist/node/index.js"
340
340
  ]
341
341
  },
342
- "chunks/page-sort-scoring-Bj73WnwW.js": {
342
+ "chunks/page-sort-scoring-Cd97obb3.js": {
343
343
  "isEntry": false,
344
344
  "imports": [
345
- "chunks/util-vJMTa4rC.js"
345
+ "chunks/util-Bm9ef_d5.js"
346
346
  ],
347
347
  "dynamicImports": [],
348
348
  "inputs": [
349
349
  "dist/node/pages/page-sort-scoring.js"
350
350
  ]
351
351
  },
352
- "chunks/rpc-local-community-DfJ3wj-p.js": {
352
+ "chunks/rpc-local-community-7uUa4lxH.js": {
353
353
  "isEntry": false,
354
354
  "imports": [
355
355
  "chunks/chunk-2rV9d50f.js",
356
- "chunks/util-vJMTa4rC.js",
357
- "chunks/page-sort-scoring-Bj73WnwW.js",
356
+ "chunks/util-Bm9ef_d5.js",
357
+ "chunks/page-sort-scoring-Cd97obb3.js",
358
358
  "chunks/src-CYIMjhjK.js",
359
359
  "node:crypto",
360
360
  "node:url",
@@ -1302,10 +1302,10 @@
1302
1302
  "node_modules/it-parallel-batch/dist/src/index.js"
1303
1303
  ]
1304
1304
  },
1305
- "chunks/util-DkyQHyK7.js": {
1305
+ "chunks/util-BMGkXifx.js": {
1306
1306
  "isEntry": false,
1307
1307
  "imports": [
1308
- "chunks/util-vJMTa4rC.js",
1308
+ "chunks/util-Bm9ef_d5.js",
1309
1309
  "ipns/selector",
1310
1310
  "ipns/validator",
1311
1311
  "ipns",
@@ -1316,7 +1316,7 @@
1316
1316
  "dist/node/helia/util.js"
1317
1317
  ]
1318
1318
  },
1319
- "chunks/util-vJMTa4rC.js": {
1319
+ "chunks/util-Bm9ef_d5.js": {
1320
1320
  "isEntry": false,
1321
1321
  "imports": [
1322
1322
  "chunks/chunk-2rV9d50f.js",
@@ -1410,11 +1410,11 @@
1410
1410
  "dist/node/util.js"
1411
1411
  ]
1412
1412
  },
1413
- "chunks/validate-package-factories-tZC8XxoO.js": {
1413
+ "chunks/validate-package-factories-DHupf8eD.js": {
1414
1414
  "isEntry": false,
1415
1415
  "imports": [
1416
- "chunks/util-vJMTa4rC.js",
1417
- "chunks/page-sort-scoring-Bj73WnwW.js"
1416
+ "chunks/util-Bm9ef_d5.js",
1417
+ "chunks/page-sort-scoring-Cd97obb3.js"
1418
1418
  ],
1419
1419
  "dynamicImports": [],
1420
1420
  "inputs": [
@@ -1,2 +1,2 @@
1
- import { t as validateChallengeFileFactory } from "./chunks/validate-package-factories-tZC8XxoO.js";
1
+ import { t as validateChallengeFileFactory } from "./chunks/validate-package-factories-DHupf8eD.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 { Ar as PKCError, Mr as logger_default, S as hideClassPrivateProps, n as binaryKeyToPubsubTopic, w as ipnsNameToIpnsOverPubsubTopic } from "./util-vJMTa4rC.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-DkyQHyK7.js";
2
+ import { Ar as PKCError, Mr as logger_default, S as hideClassPrivateProps, n as binaryKeyToPubsubTopic, w as ipnsNameToIpnsOverPubsubTopic } from "./util-Bm9ef_d5.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-BMGkXifx.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-nSmHRx5s.js";
1
+ import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-XUj49rN_.js";
2
2
  export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
@@ -1,7 +1,7 @@
1
1
  import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { $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";
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-Bm9ef_d5.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-7uUa4lxH.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-Cd97obb3.js";
5
5
  import { randomFillSync, randomUUID } from "node:crypto";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
7
7
  import path from "node:path";
@@ -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-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";
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-Bm9ef_d5.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-7uUa4lxH.js";
4
+ import { s as getHeliaDebugContext } from "./util-BMGkXifx.js";
5
5
  import path from "path";
6
6
  import assert from "assert";
7
7
  import fs from "fs";
@@ -3439,10 +3439,26 @@ const log = logger_default("pkc-js:PKCRpcClient");
3439
3439
  const WEBSOCKET_READY_STATE_CLOSED = 3;
3440
3440
  const DESTROY_SOCKET_CLOSE_TIMEOUT_MS = 5e3;
3441
3441
  const scheduleMacrotask = setTimeout.bind(globalThis);
3442
+ function isRpcSubscriptionNotification(message) {
3443
+ if (typeof message !== "object" || message === null || !("params" in message)) return false;
3444
+ const params = message.params;
3445
+ if (typeof params !== "object" || params === null) return false;
3446
+ const { subscription, event } = params;
3447
+ return typeof subscription === "number" && subscription > 0 && typeof event === "string";
3448
+ }
3442
3449
  var PKCRpcClient = class extends import_lib.TypedEmitter {
3443
3450
  constructor(rpcServerUrl) {
3444
3451
  super();
3445
3452
  this._pendingSubscriptionMsgs = {};
3453
+ this._serverIdByLocalId = /* @__PURE__ */ new Map();
3454
+ this._localIdByServerId = /* @__PURE__ */ new Map();
3455
+ this._resubscribeCalls = /* @__PURE__ */ new Map();
3456
+ this._publishSubscriptionIds = /* @__PURE__ */ new Set();
3457
+ this._hasConnectedBefore = false;
3458
+ this._socketsWithNotificationHandler = /* @__PURE__ */ new WeakSet();
3459
+ this._reconnectBaseIntervalMs = 1e3;
3460
+ this._reconnectMaxIntervalMs = 3e4;
3461
+ this._reconnectIntervalMs = this._reconnectBaseIntervalMs;
3446
3462
  assert(rpcServerUrl, "pkc.pkcRpcClientsOptions needs to be defined to create a new rpc client");
3447
3463
  this._websocketServerUrl = rpcServerUrl;
3448
3464
  this._timeoutSeconds = 20;
@@ -3475,26 +3491,24 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
3475
3491
  let lastWebsocketError;
3476
3492
  if (!(this._webSocketClient instanceof Client)) {
3477
3493
  this.setState("connecting");
3478
- this._webSocketClient = new Client(this._websocketServerUrl);
3479
- log("Created a new WebSocket instance with url " + this._websocketServerUrl);
3480
- this._webSocketClient.socket.on("message", (jsonMessage) => {
3481
- const message = JSON.parse(jsonMessage);
3482
- const subscriptionId = message?.params?.subscription;
3483
- if (subscriptionId) {
3484
- this._initSubscriptionEvent(subscriptionId);
3485
- if (message?.params?.event === "error") {
3486
- message.params.result = this._deserializeRpcError(message.params.result);
3487
- delete message.params.result.stack;
3488
- }
3489
- if (this._subscriptionEvents[subscriptionId].listenerCount(message?.params?.event) === 0) this._pendingSubscriptionMsgs[subscriptionId].push(message);
3490
- else this._subscriptionEvents[subscriptionId].emit(message?.params?.event, message);
3491
- }
3494
+ this._webSocketClient = new Client(this._websocketServerUrl, {
3495
+ reconnect_interval: this._reconnectIntervalMs,
3496
+ max_reconnects: 0
3492
3497
  });
3498
+ log("Created a new WebSocket instance with url " + this._websocketServerUrl);
3499
+ this._attachNotificationHandler();
3493
3500
  this._webSocketClient.on("open", () => {
3494
3501
  log("Connected to RPC server", this._websocketServerUrl);
3502
+ this._attachNotificationHandler();
3503
+ this._reconnectIntervalMs = this._reconnectBaseIntervalMs;
3504
+ this._webSocketClient.setReconnectInterval(this._reconnectIntervalMs);
3505
+ const isReconnect = this._hasConnectedBefore;
3506
+ this._hasConnectedBefore = true;
3495
3507
  this.setState("connected");
3508
+ if (isReconnect) this._resubscribeAllAfterReconnect();
3496
3509
  });
3497
3510
  this._webSocketClient.on("error", (error) => {
3511
+ this._backOffReconnectInterval();
3498
3512
  lastWebsocketError = error;
3499
3513
  if (this._destroyRequested) {
3500
3514
  log("Ignoring websocket error emitted after destroy request", error);
@@ -3507,12 +3521,17 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
3507
3521
  this.setState("failed");
3508
3522
  return;
3509
3523
  }
3510
- this.emit("error", error);
3524
+ try {
3525
+ this.emit("error", error);
3526
+ } catch (emitError) {
3527
+ log.error("No listener received the RPC websocket error", this._websocketServerUrl, emitError);
3528
+ }
3511
3529
  });
3512
3530
  this._webSocketClient.on("close", () => {
3513
3531
  if (!this._destroyRequested) log.error("connection with web socket has been closed", this._websocketServerUrl);
3514
3532
  this._openConnectionPromise = void 0;
3515
3533
  this.setState("stopped");
3534
+ if (!this._destroyRequested) this._failPublicationsLostWithConnection();
3516
3535
  });
3517
3536
  const originalWebsocketCall = this._webSocketClient.call.bind(this._webSocketClient);
3518
3537
  this._webSocketClient.call = async (...args) => {
@@ -3577,9 +3596,14 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
3577
3596
  log.error("Failed to unsubscribe to subscription ID", subscriptionId, e);
3578
3597
  cleanupSubscriptionLocally(subscriptionId);
3579
3598
  }
3599
+ this._resubscribeCalls.clear();
3600
+ this._publishSubscriptionIds.clear();
3601
+ this._serverIdByLocalId.clear();
3602
+ this._localIdByServerId.clear();
3580
3603
  try {
3581
3604
  if (this._webSocketClient instanceof Client) {
3582
3605
  this._webSocketClient.setAutoReconnect(false);
3606
+ clearTimeout(this._webSocketClient.reconnect_timer_id);
3583
3607
  const socketClosed = this._waitForSocketClose();
3584
3608
  this._webSocketClient.close();
3585
3609
  await socketClosed;
@@ -3607,11 +3631,123 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
3607
3631
  else return this._subscriptionEvents[subscriptionId];
3608
3632
  }
3609
3633
  async unsubscribe(subscriptionId) {
3610
- await this._webSocketClient.call("unsubscribe", [{ subscriptionId }]);
3634
+ const liveOnServer = this.state === "connected" && (this._resubscribeCalls.has(subscriptionId) || this._publishSubscriptionIds.has(subscriptionId));
3635
+ const serverSubscriptionId = this._serverIdByLocalId.get(subscriptionId) ?? subscriptionId;
3636
+ this._resubscribeCalls.delete(subscriptionId);
3637
+ this._publishSubscriptionIds.delete(subscriptionId);
3638
+ if (liveOnServer) await this._webSocketClient.call("unsubscribe", [{ subscriptionId: serverSubscriptionId }]);
3639
+ this._serverIdByLocalId.delete(subscriptionId);
3640
+ this._localIdByServerId.delete(serverSubscriptionId);
3611
3641
  if (this._subscriptionEvents[subscriptionId]) this._subscriptionEvents[subscriptionId].removeAllListeners();
3612
3642
  delete this._subscriptionEvents[subscriptionId];
3613
3643
  delete this._pendingSubscriptionMsgs[subscriptionId];
3614
3644
  }
3645
+ _attachNotificationHandler() {
3646
+ const socket = this._webSocketClient.socket;
3647
+ if (!socket || this._socketsWithNotificationHandler.has(socket)) return;
3648
+ this._socketsWithNotificationHandler.add(socket);
3649
+ socket.on("message", (jsonMessage) => {
3650
+ const message = JSON.parse(jsonMessage);
3651
+ if (!isRpcSubscriptionNotification(message)) return;
3652
+ const serverSubscriptionId = message.params.subscription;
3653
+ const subscriptionId = this._localIdByServerId.get(serverSubscriptionId) ?? serverSubscriptionId;
3654
+ message.params.subscription = subscriptionId;
3655
+ this._dispatchNotification(subscriptionId, message);
3656
+ });
3657
+ }
3658
+ _dispatchNotification(subscriptionId, message) {
3659
+ this._initSubscriptionEvent(subscriptionId);
3660
+ if (message.params.event === "error" && !(message.params.result instanceof Error)) {
3661
+ const error = this._deserializeRpcError(message.params.result);
3662
+ delete error.stack;
3663
+ message.params.result = error;
3664
+ }
3665
+ if (this._subscriptionEvents[subscriptionId].listenerCount(message.params.event) === 0) this._pendingSubscriptionMsgs[subscriptionId].push(message);
3666
+ else this._subscriptionEvents[subscriptionId].emit(message.params.event, message);
3667
+ }
3668
+ _backOffReconnectInterval() {
3669
+ if (!(this._webSocketClient instanceof Client)) return;
3670
+ this._reconnectIntervalMs = Math.min(this._reconnectIntervalMs * 2, this._reconnectMaxIntervalMs);
3671
+ this._webSocketClient.setReconnectInterval(this._reconnectIntervalMs);
3672
+ }
3673
+ async _subscribe(method, params, onReconnect, resubscribeMethod = method) {
3674
+ const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call(method, params));
3675
+ this._initSubscriptionEvent(res.subscriptionId);
3676
+ if (onReconnect === "resubscribe") this._resubscribeCalls.set(res.subscriptionId, {
3677
+ method: resubscribeMethod,
3678
+ params
3679
+ });
3680
+ else this._publishSubscriptionIds.add(res.subscriptionId);
3681
+ return res;
3682
+ }
3683
+ _resubscribeAllAfterReconnect() {
3684
+ for (const subscriptionId of [...this._resubscribeCalls.keys()]) this._resubscribe(subscriptionId).catch((error) => {
3685
+ if (this._destroyRequested) return;
3686
+ if (error?.code === "ERR_RPC_COMMUNITY_NOT_RUNNING") {
3687
+ log("Not re-establishing start(), the community was stopped on purpose", subscriptionId);
3688
+ this._resubscribeCalls.delete(subscriptionId);
3689
+ this._dispatchNotification(subscriptionId, { params: {
3690
+ event: "startedstatechange",
3691
+ subscription: subscriptionId,
3692
+ result: { state: "stopped" }
3693
+ } });
3694
+ return;
3695
+ }
3696
+ log.error("Failed to re-subscribe after reconnecting to the RPC server", subscriptionId, error);
3697
+ this._dispatchNotification(subscriptionId, { params: {
3698
+ event: "error",
3699
+ subscription: subscriptionId,
3700
+ result: error
3701
+ } });
3702
+ });
3703
+ }
3704
+ async _resubscribe(subscriptionId) {
3705
+ const call = this._resubscribeCalls.get(subscriptionId);
3706
+ if (!call || this._destroyRequested) return;
3707
+ const { subscriptionId: serverSubscriptionId } = parseRpcSubscriptionIdResult(await this._webSocketClient.call(call.method, call.params));
3708
+ const earlyMessages = serverSubscriptionId === subscriptionId ? [] : this._pendingSubscriptionMsgs[serverSubscriptionId] ?? [];
3709
+ if (serverSubscriptionId !== subscriptionId) {
3710
+ delete this._pendingSubscriptionMsgs[serverSubscriptionId];
3711
+ delete this._subscriptionEvents[serverSubscriptionId];
3712
+ }
3713
+ if (this._resubscribeCalls.get(subscriptionId) !== call || this._destroyRequested) {
3714
+ if (!this._destroyRequested) await this._webSocketClient.call("unsubscribe", [{ subscriptionId: serverSubscriptionId }]).catch((error) => {
3715
+ log.error("Failed to unsubscribe a subscription re-issued after it was unsubscribed", error);
3716
+ });
3717
+ return;
3718
+ }
3719
+ const previousServerSubscriptionId = this._serverIdByLocalId.get(subscriptionId);
3720
+ if (previousServerSubscriptionId !== void 0) this._localIdByServerId.delete(previousServerSubscriptionId);
3721
+ this._serverIdByLocalId.set(subscriptionId, serverSubscriptionId);
3722
+ this._localIdByServerId.set(serverSubscriptionId, subscriptionId);
3723
+ log("Re-subscribed after reconnecting", call.method, {
3724
+ subscriptionId,
3725
+ serverSubscriptionId
3726
+ });
3727
+ for (const message of earlyMessages) {
3728
+ message.params.subscription = subscriptionId;
3729
+ this._dispatchNotification(subscriptionId, message);
3730
+ }
3731
+ }
3732
+ _failPublicationsLostWithConnection() {
3733
+ for (const subscriptionId of [...this._publishSubscriptionIds]) {
3734
+ this._publishSubscriptionIds.delete(subscriptionId);
3735
+ const error = new PKCError("ERR_RPC_PUBLICATION_LOST_WITH_CONNECTION", {
3736
+ rpcServerUrl: this._websocketServerUrl,
3737
+ publishThrowError: true
3738
+ });
3739
+ this._dispatchNotification(subscriptionId, { params: {
3740
+ event: "publishingstatechange",
3741
+ subscription: subscriptionId,
3742
+ result: { state: "failed" }
3743
+ } });
3744
+ this._dispatchNotification(subscriptionId, { params: {
3745
+ event: "error",
3746
+ subscription: subscriptionId,
3747
+ result: error
3748
+ } });
3749
+ }
3750
+ }
3615
3751
  _deserializeRpcError(errorPayload) {
3616
3752
  if (!errorPayload || typeof errorPayload !== "object") {
3617
3753
  const genericError = /* @__PURE__ */ new Error("Received malformed RPC error payload");
@@ -3687,7 +3823,7 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
3687
3823
  while (pendingMessages.length > 0) {
3688
3824
  if (!shouldDeliver()) return;
3689
3825
  const message = pendingMessages.shift();
3690
- this._subscriptionEvents[subscriptionId].emit(message?.params?.event, message);
3826
+ this._subscriptionEvents[subscriptionId].emit(message.params.event, message);
3691
3827
  }
3692
3828
  delete this._pendingSubscriptionMsgs[subscriptionId];
3693
3829
  }
@@ -3717,9 +3853,7 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
3717
3853
  }
3718
3854
  async startCommunity(communityIdentifier) {
3719
3855
  const parsedStartCommunityArgs = parseRpcCommunityIdentifierParam(communityIdentifier);
3720
- const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call("startCommunity", [parsedStartCommunityArgs]));
3721
- this._initSubscriptionEvent(res.subscriptionId);
3722
- return res;
3856
+ return await this._subscribe("startCommunity", [parsedStartCommunityArgs], "resubscribe", "startedCommunitySubscribe");
3723
3857
  }
3724
3858
  async stopCommunity(communityIdentifier) {
3725
3859
  const parsedStopCommunityArgs = parseRpcCommunityIdentifierParam(communityIdentifier);
@@ -3747,40 +3881,26 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
3747
3881
  }
3748
3882
  async communityUpdateSubscribe(communityIdentifier) {
3749
3883
  const parsedCommunityUpdateArgs = parseRpcCommunityIdentifierParam(communityIdentifier);
3750
- const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call("communityUpdateSubscribe", [parsedCommunityUpdateArgs]));
3751
- this._initSubscriptionEvent(res.subscriptionId);
3752
- return res;
3884
+ return await this._subscribe("communityUpdateSubscribe", [parsedCommunityUpdateArgs], "resubscribe");
3753
3885
  }
3754
3886
  async publishComment(commentProps) {
3755
- const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call("publishComment", [commentProps]));
3756
- this._initSubscriptionEvent(res.subscriptionId);
3757
- return res;
3887
+ return await this._subscribe("publishComment", [commentProps], "fail");
3758
3888
  }
3759
3889
  async publishCommentEdit(commentEditProps) {
3760
- const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call("publishCommentEdit", [commentEditProps]));
3761
- this._initSubscriptionEvent(res.subscriptionId);
3762
- return res;
3890
+ return await this._subscribe("publishCommentEdit", [commentEditProps], "fail");
3763
3891
  }
3764
3892
  async publishCommentModeration(commentModProps) {
3765
- const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call("publishCommentModeration", [commentModProps]));
3766
- this._initSubscriptionEvent(res.subscriptionId);
3767
- return res;
3893
+ return await this._subscribe("publishCommentModeration", [commentModProps], "fail");
3768
3894
  }
3769
3895
  async publishVote(voteProps) {
3770
- const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call("publishVote", [voteProps]));
3771
- this._initSubscriptionEvent(res.subscriptionId);
3772
- return res;
3896
+ return await this._subscribe("publishVote", [voteProps], "fail");
3773
3897
  }
3774
3898
  async publishCommunityEdit(communityEdit) {
3775
- const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call("publishCommunityEdit", [communityEdit]));
3776
- this._initSubscriptionEvent(res.subscriptionId);
3777
- return res;
3899
+ return await this._subscribe("publishCommunityEdit", [communityEdit], "fail");
3778
3900
  }
3779
3901
  async commentUpdateSubscribe(args) {
3780
3902
  const parsedCommentUpdateArgs = parseRpcCidParam(args);
3781
- const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call("commentUpdateSubscribe", [parsedCommentUpdateArgs]));
3782
- this._initSubscriptionEvent(res.subscriptionId);
3783
- return res;
3903
+ return await this._subscribe("commentUpdateSubscribe", [parsedCommentUpdateArgs], "resubscribe");
3784
3904
  }
3785
3905
  async publishChallengeAnswers(args) {
3786
3906
  return parseRpcSuccessResult(await this._webSocketClient.call("publishChallengeAnswers", [args]));
@@ -3790,16 +3910,14 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
3790
3910
  return parseRpcResolveAuthorNameResult(await this._webSocketClient.call("resolveAuthorName", [resolveAuthorNameArgs]));
3791
3911
  }
3792
3912
  async initalizeCommunitieschangeEvent() {
3793
- const { subscriptionId } = parseRpcSubscriptionIdResult(await this._webSocketClient.call("communitiesSubscribe", []));
3794
- this._initSubscriptionEvent(subscriptionId);
3913
+ const { subscriptionId } = await this._subscribe("communitiesSubscribe", [], "resubscribe");
3795
3914
  this.getSubscription(subscriptionId).on("communitieschange", (res) => {
3796
3915
  this.emit("communitieschange", res.params.result.communities);
3797
3916
  });
3798
3917
  this.emitAllPendingMessages(subscriptionId);
3799
3918
  }
3800
3919
  async initalizeSettingschangeEvent() {
3801
- const { subscriptionId } = parseRpcSubscriptionIdResult(await this._webSocketClient.call("settingsSubscribe", []));
3802
- this._initSubscriptionEvent(subscriptionId);
3920
+ const { subscriptionId } = await this._subscribe("settingsSubscribe", [], "resubscribe");
3803
3921
  this.getSubscription(subscriptionId).on("settingschange", (res) => {
3804
3922
  this.emit("settingschange", res.params.result);
3805
3923
  });
@@ -3830,9 +3948,7 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
3830
3948
  }
3831
3949
  async exportsSubscribe(args) {
3832
3950
  const parsedArgs = parseRpcCommunityIdentifierParam(args);
3833
- const res = parseRpcSubscriptionIdResult(await this._webSocketClient.call("exportsSubscribe", [parsedArgs]));
3834
- this._initSubscriptionEvent(res.subscriptionId);
3835
- return res;
3951
+ return await this._subscribe("exportsSubscribe", [parsedArgs], "resubscribe");
3836
3952
  }
3837
3953
  async cancelExport(args) {
3838
3954
  const parsedArgs = parseRpcCancelExportParam(args);
@@ -8254,7 +8370,7 @@ var PKC$1 = class extends PKCTypedEmitter {
8254
8370
  this.clients.libp2pJsClients = {};
8255
8371
  if (!this.libp2pJsClientsOptions) return;
8256
8372
  if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
8257
- const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-BvltkMx7.js");
8373
+ const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-DuG274FA.js");
8258
8374
  for (const clientOptions of this.libp2pJsClientsOptions) {
8259
8375
  const heliaNode = await createLibp2pJsClientOrUseExistingOne({
8260
8376
  ...clientOptions,
@@ -8533,7 +8649,7 @@ var PKC$1 = class extends PKCTypedEmitter {
8533
8649
  const log = logger_default("pkc-js:pkc:createLocalCommunity");
8534
8650
  log.trace("Received community options to create a local community instance:", options);
8535
8651
  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-Cm4X7RjW.js");
8652
+ const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-BsALoql_.js");
8537
8653
  const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
8538
8654
  const community = new LocalCommunity(this);
8539
8655
  if (isLocalCommunity) {
@@ -1,4 +1,4 @@
1
- import { _ as getEquivalentCommunityAddresses, vn as PageSortFileSchema } from "./util-vJMTa4rC.js";
1
+ import { _ as getEquivalentCommunityAddresses, vn as PageSortFileSchema } from "./util-Bm9ef_d5.js";
2
2
  //#region dist/node/pages/page-sort-scoring.js
3
3
  function validatePageSortFile(rawFile) {
4
4
  const validated = PageSortFileSchema.parse(rawFile);