@pkcprotocol/pkc-js 0.0.34 → 0.0.36

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 (114) hide show
  1. package/README.md +18 -0
  2. package/dist/browser/community/remote-community.d.ts +3 -3
  3. package/dist/browser/community/remote-community.js.map +1 -1
  4. package/dist/browser/generated-version.d.ts +1 -1
  5. package/dist/browser/generated-version.js +1 -1
  6. package/dist/browser/helia/helia-for-pkc.js +30 -12
  7. package/dist/browser/helia/helia-for-pkc.js.map +1 -1
  8. package/dist/browser/helia/util.js +142 -42
  9. package/dist/browser/helia/util.js.map +1 -1
  10. package/dist/browser/pkc/pkc.js +3 -3
  11. package/dist/browser/pkc/pkc.js.map +1 -1
  12. package/dist/browser/runtime/browser/community/local-community.d.ts +2 -0
  13. package/dist/browser/runtime/browser/community/local-community.js +6 -0
  14. package/dist/browser/runtime/browser/community/local-community.js.map +1 -1
  15. package/dist/browser/runtime/node/community/db-handler.js +6 -4
  16. package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
  17. package/dist/browser/runtime/node/community/local-community/challenges.d.ts +26 -0
  18. package/dist/browser/runtime/node/community/local-community/challenges.js +519 -0
  19. package/dist/browser/runtime/node/community/local-community/challenges.js.map +1 -0
  20. package/dist/browser/runtime/node/community/local-community/cleanup.d.ts +9 -0
  21. package/dist/browser/runtime/node/community/local-community/cleanup.js +165 -0
  22. package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -0
  23. package/dist/browser/runtime/node/community/local-community/comment-updates.d.ts +11 -0
  24. package/dist/browser/runtime/node/community/local-community/comment-updates.js +218 -0
  25. package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -0
  26. package/dist/browser/runtime/node/community/local-community/db-state.d.ts +15 -0
  27. package/dist/browser/runtime/node/community/local-community/db-state.js +323 -0
  28. package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -0
  29. package/dist/browser/runtime/node/community/local-community/defaults.d.ts +12 -0
  30. package/dist/browser/runtime/node/community/local-community/defaults.js +29 -0
  31. package/dist/browser/runtime/node/community/local-community/defaults.js.map +1 -0
  32. package/dist/browser/runtime/node/community/local-community/editing.d.ts +10 -0
  33. package/dist/browser/runtime/node/community/local-community/editing.js +188 -0
  34. package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -0
  35. package/dist/browser/runtime/node/community/local-community/ipns-publishing.d.ts +12 -0
  36. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +340 -0
  37. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -0
  38. package/dist/browser/runtime/node/community/local-community/lifecycle.d.ts +11 -0
  39. package/dist/browser/runtime/node/community/local-community/lifecycle.js +428 -0
  40. package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -0
  41. package/dist/browser/runtime/node/community/local-community/publication-store.d.ts +100 -0
  42. package/dist/browser/runtime/node/community/local-community/publication-store.js +395 -0
  43. package/dist/browser/runtime/node/community/local-community/publication-store.js.map +1 -0
  44. package/dist/browser/runtime/node/community/local-community/publication-validation.d.ts +9 -0
  45. package/dist/browser/runtime/node/community/local-community/publication-validation.js +493 -0
  46. package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -0
  47. package/dist/browser/runtime/node/community/local-community/pubsub.d.ts +3 -0
  48. package/dist/browser/runtime/node/community/local-community/pubsub.js +43 -0
  49. package/dist/browser/runtime/node/community/local-community/pubsub.js.map +1 -0
  50. package/dist/browser/runtime/node/community/local-community/registry.d.ts +3 -0
  51. package/dist/browser/runtime/node/community/local-community/registry.js +4 -0
  52. package/dist/browser/runtime/node/community/local-community/registry.js.map +1 -0
  53. package/dist/browser/runtime/node/community/local-community.d.ts +68 -105
  54. package/dist/browser/runtime/node/community/local-community.js +127 -2927
  55. package/dist/browser/runtime/node/community/local-community.js.map +1 -1
  56. package/dist/browser/test/test-util.js +0 -1
  57. package/dist/browser/test/test-util.js.map +1 -1
  58. package/dist/node/community/remote-community.d.ts +3 -3
  59. package/dist/node/community/remote-community.js.map +1 -1
  60. package/dist/node/generated-version.d.ts +1 -1
  61. package/dist/node/generated-version.js +1 -1
  62. package/dist/node/helia/helia-for-pkc.js +30 -12
  63. package/dist/node/helia/helia-for-pkc.js.map +1 -1
  64. package/dist/node/helia/util.js +142 -42
  65. package/dist/node/helia/util.js.map +1 -1
  66. package/dist/node/pkc/pkc.js +3 -3
  67. package/dist/node/pkc/pkc.js.map +1 -1
  68. package/dist/node/runtime/browser/community/local-community.d.ts +2 -0
  69. package/dist/node/runtime/browser/community/local-community.js +6 -0
  70. package/dist/node/runtime/browser/community/local-community.js.map +1 -1
  71. package/dist/node/runtime/node/community/db-handler.js +6 -4
  72. package/dist/node/runtime/node/community/db-handler.js.map +1 -1
  73. package/dist/node/runtime/node/community/local-community/challenges.d.ts +26 -0
  74. package/dist/node/runtime/node/community/local-community/challenges.js +519 -0
  75. package/dist/node/runtime/node/community/local-community/challenges.js.map +1 -0
  76. package/dist/node/runtime/node/community/local-community/cleanup.d.ts +9 -0
  77. package/dist/node/runtime/node/community/local-community/cleanup.js +165 -0
  78. package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -0
  79. package/dist/node/runtime/node/community/local-community/comment-updates.d.ts +11 -0
  80. package/dist/node/runtime/node/community/local-community/comment-updates.js +218 -0
  81. package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -0
  82. package/dist/node/runtime/node/community/local-community/db-state.d.ts +15 -0
  83. package/dist/node/runtime/node/community/local-community/db-state.js +323 -0
  84. package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -0
  85. package/dist/node/runtime/node/community/local-community/defaults.d.ts +12 -0
  86. package/dist/node/runtime/node/community/local-community/defaults.js +29 -0
  87. package/dist/node/runtime/node/community/local-community/defaults.js.map +1 -0
  88. package/dist/node/runtime/node/community/local-community/editing.d.ts +10 -0
  89. package/dist/node/runtime/node/community/local-community/editing.js +188 -0
  90. package/dist/node/runtime/node/community/local-community/editing.js.map +1 -0
  91. package/dist/node/runtime/node/community/local-community/ipns-publishing.d.ts +12 -0
  92. package/dist/node/runtime/node/community/local-community/ipns-publishing.js +340 -0
  93. package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -0
  94. package/dist/node/runtime/node/community/local-community/lifecycle.d.ts +11 -0
  95. package/dist/node/runtime/node/community/local-community/lifecycle.js +428 -0
  96. package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -0
  97. package/dist/node/runtime/node/community/local-community/publication-store.d.ts +100 -0
  98. package/dist/node/runtime/node/community/local-community/publication-store.js +395 -0
  99. package/dist/node/runtime/node/community/local-community/publication-store.js.map +1 -0
  100. package/dist/node/runtime/node/community/local-community/publication-validation.d.ts +9 -0
  101. package/dist/node/runtime/node/community/local-community/publication-validation.js +493 -0
  102. package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -0
  103. package/dist/node/runtime/node/community/local-community/pubsub.d.ts +3 -0
  104. package/dist/node/runtime/node/community/local-community/pubsub.js +43 -0
  105. package/dist/node/runtime/node/community/local-community/pubsub.js.map +1 -0
  106. package/dist/node/runtime/node/community/local-community/registry.d.ts +3 -0
  107. package/dist/node/runtime/node/community/local-community/registry.js +4 -0
  108. package/dist/node/runtime/node/community/local-community/registry.js.map +1 -0
  109. package/dist/node/runtime/node/community/local-community.d.ts +68 -105
  110. package/dist/node/runtime/node/community/local-community.js +127 -2927
  111. package/dist/node/runtime/node/community/local-community.js.map +1 -1
  112. package/dist/node/test/test-util.js +0 -1
  113. package/dist/node/test/test-util.js.map +1 -1
  114. package/package.json +3 -2
@@ -1,133 +1,96 @@
1
1
  import Logger from "../../../logger.js";
2
2
  import { PKC } from "../../../pkc/pkc.js";
3
- import type { CreateNewLocalCommunityParsedOptions, InternalCommunityRecordBeforeFirstUpdateType, InternalCommunityRecordAfterFirstUpdateType, ParsedCommunityEditOptions, CommunityChallengeSetting, CommunityEditOptions, RpcInternalCommunityRecordBeforeFirstUpdateType, RpcInternalCommunityRecordAfterFirstUpdateType } from "../../../community/types.js";
3
+ import type { CommunityEditOptions, CreateNewLocalCommunityParsedOptions, InternalCommunityRecordBeforeFirstUpdateType, InternalCommunityRecordAfterFirstUpdateType, ParsedCommunityEditOptions, CommunityChallengeSetting, CommunityIpfsType, RpcInternalCommunityRecordBeforeFirstUpdateType, RpcInternalCommunityRecordAfterFirstUpdateType, CommunityEvents } from "../../../community/types.js";
4
+ import { LRUCache } from "lru-cache";
5
+ import { PageGenerator } from "./page-generator.js";
4
6
  import { DbHandler } from "./db-handler.js";
5
- import type { PurgedCommentTableRows } from "./db-handler-types.js";
6
- import type { ChallengeAnswerMessageType, ChallengeRequestMessageType } from "../../../pubsub-messages/types.js";
7
+ import type { ChallengeAnswerMessageType, ChallengeRequestMessageType, DecryptedChallengeAnswer, DecryptedChallengeRequestMessageType } from "../../../pubsub-messages/types.js";
8
+ import type { IpfsHttpClientPubsubMessage } from "../../../types.js";
7
9
  import { SignerWithPublicKeyAddress } from "../../../signer/index.js";
8
10
  import { RpcLocalCommunity } from "../../../community/rpc-local-community.js";
11
+ import type { CommentsTableRow } from "../../../publications/comment/types.js";
12
+ import { AllPageCids } from "../../../pages/types.js";
13
+ import { createNewLocalCommunityDb, updateDbInternalState, updateInstancePropsWithStartedCommunityOrDb } from "./local-community/db-state.js";
14
+ export { createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
15
+ import { publishChallengeVerification, publishIdempotentDuplicateVerification } from "./local-community/challenges.js";
16
+ import { checkPublicationValidity } from "./local-community/publication-validation.js";
17
+ import { calculateLocalMfsPathForCommentUpdate } from "./local-community/comment-updates.js";
18
+ import { addOldPageCidsToCidsToUnpin, updateCommunityIpnsIfNeeded } from "./local-community/ipns-publishing.js";
9
19
  export declare class LocalCommunity extends RpcLocalCommunity implements CreateNewLocalCommunityParsedOptions {
10
20
  signer: SignerWithPublicKeyAddress;
11
21
  raw: RpcLocalCommunity["raw"];
12
- private _postUpdatesBuckets;
13
- private static _defaultChallengeQuestionText;
14
- static _generateDefaultChallenges(answer?: string): CommunityChallengeSetting[];
15
- static _isDefaultChallengeStructure(challenges: CommunityChallengeSetting[] | undefined): boolean;
22
+ _postUpdatesBuckets: number[];
16
23
  _defaultCommunityChallenges: CommunityChallengeSetting[];
17
- private _challengeAnswerPromises;
18
- private _challengeAnswerResolveReject;
19
- private _ongoingChallengeExchanges;
20
- private _duplicatePublicationAttempts;
21
- private _challengeExchangesFromLocalPublishers;
24
+ _challengeAnswerPromises: LRUCache<string, Promise<DecryptedChallengeAnswer["challengeAnswers"]>>;
25
+ _challengeAnswerResolveReject: LRUCache<string, {
26
+ resolve: (answers: DecryptedChallengeAnswer["challengeAnswers"]) => void;
27
+ reject: (error: Error) => void;
28
+ }>;
29
+ _ongoingChallengeExchanges: LRUCache<string, boolean>;
30
+ _duplicatePublicationAttempts: LRUCache<string, number>;
31
+ _challengeExchangesFromLocalPublishers: Record<string, boolean>;
22
32
  _cidsToUnPin: Set<string>;
23
33
  _mfsPathsToRemove: Set<string>;
24
- private _communityUpdateTrigger;
25
- private _combinedHashOfPendingCommentsCids;
26
- private _pageGenerator;
34
+ _communityUpdateTrigger: boolean;
35
+ _combinedHashOfPendingCommentsCids: string;
36
+ _pageGenerator: PageGenerator;
27
37
  _dbHandler: DbHandler;
28
- private _stopHasBeenCalled;
29
- private _publishLoopPromise?;
30
- private _updateLoopPromise?;
31
- private _updateLoopAbortController?;
32
- private _firstUpdateAfterStart;
33
- private _internalStateUpdateId;
34
- private _lastPubsubTopicRoutingProvideAt?;
35
- private _mirroredStartedOrUpdatingCommunity?;
36
- private _pendingEditProps;
38
+ _stopHasBeenCalled: boolean;
39
+ _publishLoopPromise?: Promise<void>;
40
+ _updateLoopPromise?: Promise<void>;
41
+ _updateLoopAbortController?: AbortController;
42
+ _firstUpdateAfterStart: boolean;
43
+ _internalStateUpdateId: InternalCommunityRecordBeforeFirstUpdateType["_internalStateUpdateId"];
44
+ _lastPubsubTopicRoutingProvideAt?: number;
45
+ _mirroredStartedOrUpdatingCommunity?: {
46
+ community: LocalCommunity;
47
+ } & Pick<CommunityEvents, "error" | "updatingstatechange" | "update" | "statechange" | "startedstatechange" | "challengerequest" | "challengeverification" | "challenge" | "challengeanswer">;
48
+ _pendingEditProps: Partial<ParsedCommunityEditOptions & {
49
+ editId: string;
50
+ }>[];
37
51
  _blocksToRm: string[];
38
- private _postsAllPageCids;
52
+ _postsAllPageCids: AllPageCids | undefined;
39
53
  constructor(pkc: PKC);
40
54
  toJSONInternalAfterFirstUpdate(): InternalCommunityRecordAfterFirstUpdateType;
41
55
  toJSONInternalBeforeFirstUpdate(): InternalCommunityRecordBeforeFirstUpdateType;
42
56
  toJSONInternalRpcAfterFirstUpdate(): RpcInternalCommunityRecordAfterFirstUpdateType;
43
57
  toJSONInternalRpcBeforeFirstUpdate(): RpcInternalCommunityRecordBeforeFirstUpdateType;
44
- private _updateStartedValue;
58
+ _updateStartedValue(): Promise<void>;
45
59
  initNewLocalCommunityPropsNoMerge(newProps: CreateNewLocalCommunityParsedOptions): Promise<void>;
46
60
  initInternalCommunityAfterFirstUpdateNoMerge(newProps: InternalCommunityRecordAfterFirstUpdateType): Promise<void>;
47
61
  initInternalCommunityBeforeFirstUpdateNoMerge(newProps: InternalCommunityRecordBeforeFirstUpdateType): Promise<void>;
48
- private initDbHandlerIfNeeded;
49
- _updateInstancePropsWithStartedCommunityOrDb(): Promise<void>;
50
- private _importCommunitySignerIntoIpfsIfNeeded;
51
- _updateDbInternalState(props: Partial<InternalCommunityRecordBeforeFirstUpdateType | InternalCommunityRecordAfterFirstUpdateType>): Promise<InternalCommunityRecordBeforeFirstUpdateType | InternalCommunityRecordAfterFirstUpdateType>;
52
- private _getDbInternalState;
53
- private _updateInstanceStateWithDbState;
54
- _setChallengesToDefaultIfNotDefined(log: Logger): Promise<void>;
55
- _createNewLocalCommunityDb(): Promise<void>;
56
- private _calculateNewPostUpdates;
57
- private _calculateLatestUpdateTrigger;
58
- private _requireCommunityUpdateIfModQueueChanged;
59
- _resolveIpnsAndLogIfPotentialProblematicSequence(): Promise<void>;
60
- private _addOldPageCidsToCidsToUnpin;
61
- private updateCommunityIpnsIfNeeded;
62
- private shouldResolveDomainForVerification;
63
- private _validateCommunitySizeSchemaAndSignatureBeforePublishing;
64
- private storeCommentEdit;
65
- private storeCommentModeration;
66
- private storeVote;
67
- private storeCommunityEditPublication;
68
- private isPublicationReply;
69
- private isPublicationPost;
70
- private _calculateLinkProps;
71
- private _calculateLatestPostProps;
72
- private _calculateReplyProps;
73
- private _resolveAliasPrivateKeyForCommentPublication;
74
- private _prepareCommentWithAnonymity;
75
- private _prepareCommentEditWithAlias;
76
- private storeComment;
77
- private storePublication;
78
- private _decryptOrRespondWithFailure;
79
- private _respondWithErrorIfSignatureOfPublicationIsInvalid;
80
- private _publishChallenges;
81
- private _publishFailedChallengeVerification;
82
- private _publishIdempotentDuplicateVerification;
83
- private _storePublicationAndEncryptForChallengeVerification;
84
- private _publishChallengeVerification;
85
- private _isPublicationAuthorPartOfRoles;
86
- private _checkPublicationValidity;
87
- private _parseChallengeRequestPublicationOrRespondWithFailure;
88
- private _buildRuntimeChallengeRequestPublication;
89
- private _buildRuntimeChallengeRequest;
62
+ initDbHandlerIfNeeded(): Promise<void>;
63
+ _validateCommunitySizeSchemaAndSignatureBeforePublishing(recordToPublishRaw: CommunityIpfsType): Promise<void>;
90
64
  handleChallengeRequest(request: ChallengeRequestMessageType, isLocalPublisher: boolean): Promise<void>;
91
- private _cleanUpChallengeAnswerPromise;
92
- private _isFlairInAllowedList;
93
- private _parseChallengeAnswerOrRespondWithFailure;
94
65
  handleChallengeAnswer(challengeAnswer: ChallengeAnswerMessageType): Promise<void>;
95
- private handleChallengeExchange;
96
- private _calculateLocalMfsPathForCommentUpdate;
97
- private _calculateNewCommentUpdate;
98
- private _validateCommentUpdateSignature;
99
- private _listenToIncomingRequests;
100
- private _movePostUpdatesFolderToNewAddress;
101
- private _updateCommentsThatNeedToBeUpdated;
102
- private _addCommentRowToIPFS;
103
- private _repinCommentsIPFSIfNeeded;
104
- private _unpinStaleCids;
105
- private _rmUnneededMfsPaths;
106
- private pubsubTopicWithfallback;
107
- private _repinCommentUpdateIfNeeded;
108
- private _syncPostUpdatesWithIpfs;
109
- private _adjustPostUpdatesBucketsIfNeeded;
110
- private _cleanUpIpfsRepoRarely;
111
- private _providePubsubTopicRoutingCidsIfNeeded;
112
- _addAllCidsUnderPurgedCommentToBeRemoved(purgedCommentAndCommentUpdate: PurgedCommentTableRows): Promise<void>;
113
- private _purgeDisapprovedCommentsOlderThan;
114
- private syncIpnsWithDb;
115
- private _assertDomainResolvesCorrectly;
116
- private _initSignerProps;
117
- private _publishLoop;
118
- private _initBeforeStarting;
119
- private _parseRolesToEdit;
120
- private _parseChallengesToEdit;
121
- _validateNewAddressBeforeEditing(newAddress: string, log: Logger): Promise<void>;
122
- _editPropsOnStartedCommunity(parsedEditOptions: ParsedCommunityEditOptions): Promise<typeof this>;
123
- _editPropsOnNotStartedCommunity(parsedEditOptions: ParsedCommunityEditOptions): Promise<typeof this>;
124
- edit(newCommunityOptions: CommunityEditOptions): Promise<typeof this>;
66
+ handleChallengeExchange(pubsubMsg: IpfsHttpClientPubsubMessage): Promise<void>;
67
+ _addCommentRowToIPFS(unpinnedCommentRow: CommentsTableRow, log: Logger): Promise<void>;
68
+ _assertDomainResolvesCorrectly(newAddressAsDomain: string): Promise<void>;
125
69
  start(): Promise<void>;
126
- private _initMirroringStartedOrUpdatingCommunity;
127
- private _cleanUpMirroredStartedOrUpdatingCommunity;
128
- private _updateOnce;
129
- private _updateLoop;
130
70
  update(): Promise<void>;
131
71
  stop(): Promise<void>;
132
72
  delete(): Promise<void>;
73
+ edit(newCommunityOptions: CommunityEditOptions): Promise<typeof this>;
74
+ _getDbInternalState(includeMutable?: boolean): Promise<InternalCommunityRecordBeforeFirstUpdateType | InternalCommunityRecordAfterFirstUpdateType>;
75
+ _listenToIncomingRequests(): Promise<void>;
76
+ _repinCommentsIPFSIfNeeded(): Promise<void>;
77
+ storePublication(request: DecryptedChallengeRequestMessageType, pendingApproval?: boolean): Promise<{
78
+ comment: import("../../../publications/comment/types.js").CommentIpfsType;
79
+ cid: import("../../../publications/comment/types.js").CommentUpdateType["cid"];
80
+ } | undefined>;
81
+ updateCommunityIpnsIfNeeded(args: {
82
+ commentUpdateRowsToPublishToIpfs: Parameters<typeof updateCommunityIpnsIfNeeded>[1];
83
+ }): Promise<void>;
84
+ _addOldPageCidsToCidsToUnpin(curPages: Parameters<typeof addOldPageCidsToCidsToUnpin>[1], newPages: Parameters<typeof addOldPageCidsToCidsToUnpin>[2], addToBlockRm?: boolean): Promise<void>;
85
+ private shouldResolveDomainForVerification;
86
+ _calculateNewPostUpdates(): Promise<Record<string, string> | undefined>;
87
+ _calculateLatestUpdateTrigger(): void;
88
+ _resolveIpnsAndLogIfPotentialProblematicSequence(): Promise<void>;
89
+ _updateDbInternalState(props: Parameters<typeof updateDbInternalState>[1]): Promise<InternalCommunityRecordBeforeFirstUpdateType | InternalCommunityRecordAfterFirstUpdateType>;
90
+ _updateCommentsThatNeedToBeUpdated(): Promise<import("./local-community/defaults.js").CommentUpdateToWriteToDbAndPublishToIpfs[]>;
91
+ _purgeDisapprovedCommentsOlderThan(): Promise<void>;
92
+ _publishChallengeVerification(challengeResult: Parameters<typeof publishChallengeVerification>[1], request: Parameters<typeof publishChallengeVerification>[2]): Promise<void>;
93
+ _publishIdempotentDuplicateVerification(...args: Parameters<typeof publishIdempotentDuplicateVerification> extends [unknown, ...infer Rest] ? Rest : never): Promise<void>;
94
+ _checkPublicationValidity(...args: Parameters<typeof checkPublicationValidity> extends [unknown, ...infer Rest] ? Rest : never): Promise<import("../../../errors.js").messages | undefined>;
95
+ _calculateLocalMfsPathForCommentUpdate(...args: Parameters<typeof calculateLocalMfsPathForCommentUpdate> extends [unknown, ...infer Rest] ? Rest : never): string;
133
96
  }