@pkcprotocol/pkc-js 0.0.35 → 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.
- package/README.md +18 -0
- package/dist/browser/community/remote-community.d.ts +3 -3
- package/dist/browser/community/remote-community.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/pkc/pkc.js +3 -3
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/runtime/browser/community/local-community.d.ts +2 -0
- package/dist/browser/runtime/browser/community/local-community.js +6 -0
- package/dist/browser/runtime/browser/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/community/db-handler.js +6 -4
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/challenges.d.ts +26 -0
- package/dist/browser/runtime/node/community/local-community/challenges.js +519 -0
- package/dist/browser/runtime/node/community/local-community/challenges.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/cleanup.d.ts +9 -0
- package/dist/browser/runtime/node/community/local-community/cleanup.js +165 -0
- package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/comment-updates.d.ts +11 -0
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +218 -0
- package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/db-state.d.ts +15 -0
- package/dist/browser/runtime/node/community/local-community/db-state.js +323 -0
- package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/defaults.d.ts +12 -0
- package/dist/browser/runtime/node/community/local-community/defaults.js +29 -0
- package/dist/browser/runtime/node/community/local-community/defaults.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/editing.d.ts +10 -0
- package/dist/browser/runtime/node/community/local-community/editing.js +188 -0
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.d.ts +12 -0
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +340 -0
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.d.ts +11 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +428 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/publication-store.d.ts +100 -0
- package/dist/browser/runtime/node/community/local-community/publication-store.js +395 -0
- package/dist/browser/runtime/node/community/local-community/publication-store.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/publication-validation.d.ts +9 -0
- package/dist/browser/runtime/node/community/local-community/publication-validation.js +493 -0
- package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/pubsub.d.ts +3 -0
- package/dist/browser/runtime/node/community/local-community/pubsub.js +43 -0
- package/dist/browser/runtime/node/community/local-community/pubsub.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/registry.d.ts +3 -0
- package/dist/browser/runtime/node/community/local-community/registry.js +4 -0
- package/dist/browser/runtime/node/community/local-community/registry.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community.d.ts +68 -105
- package/dist/browser/runtime/node/community/local-community.js +127 -2927
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/test/test-util.js +0 -1
- package/dist/browser/test/test-util.js.map +1 -1
- package/dist/node/community/remote-community.d.ts +3 -3
- package/dist/node/community/remote-community.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/pkc/pkc.js +3 -3
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/runtime/browser/community/local-community.d.ts +2 -0
- package/dist/node/runtime/browser/community/local-community.js +6 -0
- package/dist/node/runtime/browser/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/community/db-handler.js +6 -4
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/challenges.d.ts +26 -0
- package/dist/node/runtime/node/community/local-community/challenges.js +519 -0
- package/dist/node/runtime/node/community/local-community/challenges.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/cleanup.d.ts +9 -0
- package/dist/node/runtime/node/community/local-community/cleanup.js +165 -0
- package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/comment-updates.d.ts +11 -0
- package/dist/node/runtime/node/community/local-community/comment-updates.js +218 -0
- package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/db-state.d.ts +15 -0
- package/dist/node/runtime/node/community/local-community/db-state.js +323 -0
- package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/defaults.d.ts +12 -0
- package/dist/node/runtime/node/community/local-community/defaults.js +29 -0
- package/dist/node/runtime/node/community/local-community/defaults.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/editing.d.ts +10 -0
- package/dist/node/runtime/node/community/local-community/editing.js +188 -0
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/ipns-publishing.d.ts +12 -0
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +340 -0
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.d.ts +11 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.js +428 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/publication-store.d.ts +100 -0
- package/dist/node/runtime/node/community/local-community/publication-store.js +395 -0
- package/dist/node/runtime/node/community/local-community/publication-store.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/publication-validation.d.ts +9 -0
- package/dist/node/runtime/node/community/local-community/publication-validation.js +493 -0
- package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/pubsub.d.ts +3 -0
- package/dist/node/runtime/node/community/local-community/pubsub.js +43 -0
- package/dist/node/runtime/node/community/local-community/pubsub.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/registry.d.ts +3 -0
- package/dist/node/runtime/node/community/local-community/registry.js +4 -0
- package/dist/node/runtime/node/community/local-community/registry.js.map +1 -0
- package/dist/node/runtime/node/community/local-community.d.ts +68 -105
- package/dist/node/runtime/node/community/local-community.js +127 -2927
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/test/test-util.js +0 -1
- package/dist/node/test/test-util.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import Logger from "../../../../logger.js";
|
|
2
|
+
import * as remeda from "remeda";
|
|
3
|
+
import { LRUCache } from "lru-cache";
|
|
4
|
+
import { PKCError } from "../../../../pkc-error.js";
|
|
5
|
+
import env from "../../../../version.js";
|
|
6
|
+
import { removeMfsFilesSafely } from "../../../../util.js";
|
|
7
|
+
import { moveCommunityDbToDeletedDirectory } from "../../util.js";
|
|
8
|
+
import { getCommunityChallengeFromCommunityChallengeSettings } from "../challenges/index.js";
|
|
9
|
+
import { findCommunityInRegistry, findStartedCommunity, findUpdatingCommunity, syncCommunityRegistryEntry, trackStartedCommunity, trackUpdatingCommunity, untrackStartedCommunity, untrackUpdatingCommunity } from "../../../../pkc/tracked-instance-registry-util.js";
|
|
10
|
+
import { LocalCommunity } from "../local-community.js";
|
|
11
|
+
import { processStartedCommunities } from "./registry.js";
|
|
12
|
+
import { pubsubTopicWithfallback } from "./comment-updates.js";
|
|
13
|
+
import { providePubsubTopicRoutingCidsIfNeeded } from "./pubsub.js";
|
|
14
|
+
import { repinCommentUpdateIfNeeded, unpinStaleCids } from "./cleanup.js";
|
|
15
|
+
import { importCommunitySignerIntoIpfsIfNeeded, setChallengesToDefaultIfNotDefined, updateDbInternalState, updateInstancePropsWithStartedCommunityOrDb, updateInstanceStateWithDbState } from "./db-state.js";
|
|
16
|
+
import { calculateLatestUpdateTrigger, syncIpnsWithDb } from "./ipns-publishing.js";
|
|
17
|
+
export async function publishLoop(community, syncIntervalMs) {
|
|
18
|
+
const log = Logger("pkc-js:local-community:_publishLoop");
|
|
19
|
+
// we need to continue the loop if there's at least one pending edit
|
|
20
|
+
const shouldStopPublishLoop = () => {
|
|
21
|
+
return community.state !== "started" || (community._stopHasBeenCalled && community._pendingEditProps.length === 0);
|
|
22
|
+
};
|
|
23
|
+
const waitUntilNextSync = async () => {
|
|
24
|
+
const doneWithLoopTime = Date.now();
|
|
25
|
+
await new Promise((resolve) => {
|
|
26
|
+
const checkInterval = setInterval(() => {
|
|
27
|
+
const syncIntervalMsPassedSinceDoneWithLoop = Date.now() - doneWithLoopTime >= syncIntervalMs;
|
|
28
|
+
calculateLatestUpdateTrigger(community); // will update community._communityUpdateTrigger
|
|
29
|
+
if (community._communityUpdateTrigger || shouldStopPublishLoop() || syncIntervalMsPassedSinceDoneWithLoop) {
|
|
30
|
+
clearInterval(checkInterval);
|
|
31
|
+
resolve(1);
|
|
32
|
+
}
|
|
33
|
+
}, 100);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
while (!shouldStopPublishLoop()) {
|
|
37
|
+
try {
|
|
38
|
+
await syncIpnsWithDb(community);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
community.emit("error", e);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
await waitUntilNextSync();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
log("Stopping the publishing loop of community", community.address);
|
|
48
|
+
}
|
|
49
|
+
export async function initBeforeStarting(community) {
|
|
50
|
+
community.protocolVersion = env.PROTOCOL_VERSION;
|
|
51
|
+
if (!community.signer?.address)
|
|
52
|
+
throw new PKCError("ERR_COMMUNITY_SIGNER_NOT_DEFINED");
|
|
53
|
+
if (!community._challengeAnswerPromises)
|
|
54
|
+
community._challengeAnswerPromises = new LRUCache({
|
|
55
|
+
max: 1000,
|
|
56
|
+
ttl: 600000
|
|
57
|
+
});
|
|
58
|
+
if (!community._challengeAnswerResolveReject)
|
|
59
|
+
community._challengeAnswerResolveReject = new LRUCache({
|
|
60
|
+
max: 1000,
|
|
61
|
+
ttl: 600000
|
|
62
|
+
});
|
|
63
|
+
if (!community._ongoingChallengeExchanges)
|
|
64
|
+
community._ongoingChallengeExchanges = new LRUCache({
|
|
65
|
+
max: 1000,
|
|
66
|
+
ttl: 600000
|
|
67
|
+
});
|
|
68
|
+
if (!community._duplicatePublicationAttempts)
|
|
69
|
+
community._duplicatePublicationAttempts = new LRUCache({
|
|
70
|
+
max: 1000,
|
|
71
|
+
ttl: 600000
|
|
72
|
+
});
|
|
73
|
+
await community._dbHandler.initDbIfNeeded();
|
|
74
|
+
}
|
|
75
|
+
export async function start(community) {
|
|
76
|
+
const log = Logger("pkc-js:local-community:start");
|
|
77
|
+
if (community.state === "updating")
|
|
78
|
+
throw new PKCError("ERR_NEED_TO_STOP_UPDATING_COMMUNITY_BEFORE_STARTING", { address: community.address });
|
|
79
|
+
community._stopHasBeenCalled = false;
|
|
80
|
+
community._firstUpdateAfterStart = true;
|
|
81
|
+
if (!community._clientsManager.getDefaultKuboRpcClientOrHelia())
|
|
82
|
+
throw Error("You need to define an IPFS client in your pkc instance to be able to start a local community");
|
|
83
|
+
await community.initDbHandlerIfNeeded();
|
|
84
|
+
await community._updateStartedValue();
|
|
85
|
+
if (community.started ||
|
|
86
|
+
findStartedCommunity(community._pkc, { publicKey: community.publicKey, name: community.name }) ||
|
|
87
|
+
findCommunityInRegistry(processStartedCommunities, { publicKey: community.publicKey, name: community.name }))
|
|
88
|
+
throw new PKCError("ERR_COMMUNITY_ALREADY_STARTED", { address: community.address });
|
|
89
|
+
try {
|
|
90
|
+
await initBeforeStarting(community);
|
|
91
|
+
// update started value twice because it could be started prior lockCommunityStart
|
|
92
|
+
community._setState("started");
|
|
93
|
+
await community._updateStartedValue();
|
|
94
|
+
await community._dbHandler.lockCommunityStart(); // Will throw if community is locked already
|
|
95
|
+
trackStartedCommunity(community._pkc, community);
|
|
96
|
+
syncCommunityRegistryEntry(processStartedCommunities, community);
|
|
97
|
+
await community._updateStartedValue();
|
|
98
|
+
await community._dbHandler.initDbIfNeeded();
|
|
99
|
+
await community._dbHandler.createOrMigrateTablesIfNeeded();
|
|
100
|
+
await updateInstanceStateWithDbState(community); // sync in-memory state after potential migration
|
|
101
|
+
await setChallengesToDefaultIfNotDefined(community, log);
|
|
102
|
+
// Import community keys onto ipfs node
|
|
103
|
+
await importCommunitySignerIntoIpfsIfNeeded(community);
|
|
104
|
+
await providePubsubTopicRoutingCidsIfNeeded(community, true);
|
|
105
|
+
community._communityUpdateTrigger = true;
|
|
106
|
+
community._setStartedStateWithEmission("publishing-ipns");
|
|
107
|
+
await community._repinCommentsIPFSIfNeeded();
|
|
108
|
+
await repinCommentUpdateIfNeeded(community);
|
|
109
|
+
await community._listenToIncomingRequests();
|
|
110
|
+
community.challenges = await Promise.all(community.settings.challenges.map(async (cs) => (await getCommunityChallengeFromCommunityChallengeSettings({ communityChallengeSettings: cs, pkc: community._pkc }))
|
|
111
|
+
.communityChallenge)); // make sure community.challenges is using latest props from settings.challenges
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
await community.stop(); // Make sure to reset the community state
|
|
115
|
+
//@ts-expect-error
|
|
116
|
+
e.details = { ...e.details, communityAddress: community.address };
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
119
|
+
community._publishLoopPromise = publishLoop(community, community._pkc.publishInterval).catch((err) => {
|
|
120
|
+
log.error(err);
|
|
121
|
+
community.emit("error", err);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
export async function initMirroringStartedOrUpdatingCommunity(community, startedCommunity) {
|
|
125
|
+
const updatingStateChangeListener = (newState) => {
|
|
126
|
+
community._setUpdatingStateWithEventEmissionIfNewState(newState);
|
|
127
|
+
};
|
|
128
|
+
const startedStateChangeListener = (newState) => {
|
|
129
|
+
community._setStartedStateWithEmission(newState);
|
|
130
|
+
updatingStateChangeListener(newState);
|
|
131
|
+
};
|
|
132
|
+
const updateListener = async (updatedCommunity) => {
|
|
133
|
+
const startedCommunity = updatedCommunity;
|
|
134
|
+
if (startedCommunity.updateCid)
|
|
135
|
+
await community.initInternalCommunityAfterFirstUpdateNoMerge(startedCommunity.toJSONInternalAfterFirstUpdate());
|
|
136
|
+
else
|
|
137
|
+
await community.initInternalCommunityBeforeFirstUpdateNoMerge(startedCommunity.toJSONInternalBeforeFirstUpdate());
|
|
138
|
+
community.started = startedCommunity.started;
|
|
139
|
+
community.emit("update", community);
|
|
140
|
+
};
|
|
141
|
+
const stateChangeListener = async (newState) => {
|
|
142
|
+
// pkc._startedCommunities[address].stop() has been called, we need to stop mirroring
|
|
143
|
+
// or pkc._updatingCommunities[address].stop(), we need to stop mirroring
|
|
144
|
+
if (newState === "stopped")
|
|
145
|
+
await cleanUpMirroredStartedOrUpdatingCommunity(community);
|
|
146
|
+
};
|
|
147
|
+
community._mirroredStartedOrUpdatingCommunity = {
|
|
148
|
+
community: startedCommunity,
|
|
149
|
+
updatingstatechange: updatingStateChangeListener,
|
|
150
|
+
update: updateListener,
|
|
151
|
+
statechange: stateChangeListener,
|
|
152
|
+
startedstatechange: startedStateChangeListener,
|
|
153
|
+
error: (err) => community.emit("error", err),
|
|
154
|
+
challengerequest: (challengeRequest) => community.emit("challengerequest", challengeRequest),
|
|
155
|
+
challengeverification: (challengeVerification) => community.emit("challengeverification", challengeVerification),
|
|
156
|
+
challengeanswer: (challengeAnswer) => community.emit("challengeanswer", challengeAnswer),
|
|
157
|
+
challenge: (challenge) => community.emit("challenge", challenge)
|
|
158
|
+
};
|
|
159
|
+
community._mirroredStartedOrUpdatingCommunity.community.on("update", community._mirroredStartedOrUpdatingCommunity.update);
|
|
160
|
+
community._mirroredStartedOrUpdatingCommunity.community.on("startedstatechange", community._mirroredStartedOrUpdatingCommunity.startedstatechange);
|
|
161
|
+
community._mirroredStartedOrUpdatingCommunity.community.on("updatingstatechange", community._mirroredStartedOrUpdatingCommunity.updatingstatechange);
|
|
162
|
+
community._mirroredStartedOrUpdatingCommunity.community.on("statechange", community._mirroredStartedOrUpdatingCommunity.statechange);
|
|
163
|
+
community._mirroredStartedOrUpdatingCommunity.community.on("error", community._mirroredStartedOrUpdatingCommunity.error);
|
|
164
|
+
community._mirroredStartedOrUpdatingCommunity.community.on("challengerequest", community._mirroredStartedOrUpdatingCommunity.challengerequest);
|
|
165
|
+
community._mirroredStartedOrUpdatingCommunity.community.on("challengeverification", community._mirroredStartedOrUpdatingCommunity.challengeverification);
|
|
166
|
+
community._mirroredStartedOrUpdatingCommunity.community.on("challengeanswer", community._mirroredStartedOrUpdatingCommunity.challengeanswer);
|
|
167
|
+
community._mirroredStartedOrUpdatingCommunity.community.on("challenge", community._mirroredStartedOrUpdatingCommunity.challenge);
|
|
168
|
+
const clientKeys = remeda.keys.strict(community.clients);
|
|
169
|
+
for (const clientType of clientKeys)
|
|
170
|
+
if (community.clients[clientType])
|
|
171
|
+
for (const clientUrl of Object.keys(community.clients[clientType]))
|
|
172
|
+
if (clientUrl in community._mirroredStartedOrUpdatingCommunity.community.clients[clientType])
|
|
173
|
+
community.clients[clientType][clientUrl].mirror(community._mirroredStartedOrUpdatingCommunity.community.clients[clientType][clientUrl]);
|
|
174
|
+
if (startedCommunity.updateCid)
|
|
175
|
+
await community.initInternalCommunityAfterFirstUpdateNoMerge(startedCommunity.toJSONInternalAfterFirstUpdate());
|
|
176
|
+
else
|
|
177
|
+
await community.initInternalCommunityBeforeFirstUpdateNoMerge(startedCommunity.toJSONInternalBeforeFirstUpdate());
|
|
178
|
+
community.emit("update", community);
|
|
179
|
+
}
|
|
180
|
+
export async function cleanUpMirroredStartedOrUpdatingCommunity(community) {
|
|
181
|
+
if (!community._mirroredStartedOrUpdatingCommunity)
|
|
182
|
+
return;
|
|
183
|
+
community._mirroredStartedOrUpdatingCommunity.community.removeListener("update", community._mirroredStartedOrUpdatingCommunity.update);
|
|
184
|
+
community._mirroredStartedOrUpdatingCommunity.community.removeListener("updatingstatechange", community._mirroredStartedOrUpdatingCommunity.updatingstatechange);
|
|
185
|
+
community._mirroredStartedOrUpdatingCommunity.community.removeListener("startedstatechange", community._mirroredStartedOrUpdatingCommunity.startedstatechange);
|
|
186
|
+
community._mirroredStartedOrUpdatingCommunity.community.removeListener("statechange", community._mirroredStartedOrUpdatingCommunity.statechange);
|
|
187
|
+
community._mirroredStartedOrUpdatingCommunity.community.removeListener("error", community._mirroredStartedOrUpdatingCommunity.error);
|
|
188
|
+
community._mirroredStartedOrUpdatingCommunity.community.removeListener("challengerequest", community._mirroredStartedOrUpdatingCommunity.challengerequest);
|
|
189
|
+
community._mirroredStartedOrUpdatingCommunity.community.removeListener("challengeverification", community._mirroredStartedOrUpdatingCommunity.challengeverification);
|
|
190
|
+
community._mirroredStartedOrUpdatingCommunity.community.removeListener("challengeanswer", community._mirroredStartedOrUpdatingCommunity.challengeanswer);
|
|
191
|
+
community._mirroredStartedOrUpdatingCommunity.community.removeListener("challenge", community._mirroredStartedOrUpdatingCommunity.challenge);
|
|
192
|
+
const clientKeys = remeda.keys.strict(community.clients);
|
|
193
|
+
for (const clientType of clientKeys)
|
|
194
|
+
if (community.clients[clientType])
|
|
195
|
+
for (const clientUrl of Object.keys(community.clients[clientType]))
|
|
196
|
+
community.clients[clientType][clientUrl].unmirror();
|
|
197
|
+
community._mirroredStartedOrUpdatingCommunity = undefined;
|
|
198
|
+
}
|
|
199
|
+
export async function updateOnce(community) {
|
|
200
|
+
const log = Logger("pkc-js:local-community:_updateOnce");
|
|
201
|
+
await community.initDbHandlerIfNeeded();
|
|
202
|
+
await community._updateStartedValue();
|
|
203
|
+
const startedCommunity = ((findStartedCommunity(community._pkc, { publicKey: community.publicKey, name: community.name }) ||
|
|
204
|
+
findCommunityInRegistry(processStartedCommunities, { publicKey: community.publicKey, name: community.name })));
|
|
205
|
+
if (community._mirroredStartedOrUpdatingCommunity)
|
|
206
|
+
return; // we're already mirroring a started or updating community
|
|
207
|
+
else if (startedCommunity) {
|
|
208
|
+
// let's mirror the started community in this process
|
|
209
|
+
await initMirroringStartedOrUpdatingCommunity(community, startedCommunity);
|
|
210
|
+
untrackUpdatingCommunity(community._pkc, community);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
const updatingCommunity = findUpdatingCommunity(community._pkc, { publicKey: community.publicKey, name: community.name });
|
|
215
|
+
if (updatingCommunity instanceof LocalCommunity && updatingCommunity !== community) {
|
|
216
|
+
// different instance is updating, let's mirror it
|
|
217
|
+
await initMirroringStartedOrUpdatingCommunity(community, updatingCommunity);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
// this community is not started or updated anywhere, but maybe another process will call edit() on it
|
|
221
|
+
trackUpdatingCommunity(community._pkc, community);
|
|
222
|
+
const oldUpdateId = remeda.clone(community._internalStateUpdateId);
|
|
223
|
+
await updateInstancePropsWithStartedCommunityOrDb(community); // will update this instance props with DB
|
|
224
|
+
if (community._internalStateUpdateId !== oldUpdateId) {
|
|
225
|
+
log(`Local Community (${community.address}) received a new update from db with updatedAt (${community.updatedAt}). Will emit an update event`);
|
|
226
|
+
community._changeStateEmitEventEmitStateChangeEvent({
|
|
227
|
+
event: { name: "update", args: [community] },
|
|
228
|
+
newUpdatingState: "succeeded"
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
export async function updateLoop(community) {
|
|
234
|
+
const log = Logger("pkc-js:local-community:update:_updateLoop");
|
|
235
|
+
while (community.state === "updating" && !community._stopHasBeenCalled) {
|
|
236
|
+
try {
|
|
237
|
+
await updateOnce(community);
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
240
|
+
log.error("Error in update loop", e);
|
|
241
|
+
community.emit("error", e);
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
await new Promise((resolve) => {
|
|
245
|
+
if (community._updateLoopAbortController?.signal.aborted)
|
|
246
|
+
return resolve();
|
|
247
|
+
const timer = setTimeout(resolve, community._pkc.updateInterval);
|
|
248
|
+
community._updateLoopAbortController?.signal.addEventListener("abort", () => {
|
|
249
|
+
clearTimeout(timer);
|
|
250
|
+
resolve();
|
|
251
|
+
}, { once: true });
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
export async function update(community) {
|
|
257
|
+
if (community.state === "started")
|
|
258
|
+
throw new PKCError("ERR_COMMUNITY_ALREADY_STARTED", { address: community.address });
|
|
259
|
+
if (community.state === "updating")
|
|
260
|
+
return;
|
|
261
|
+
community._stopHasBeenCalled = false;
|
|
262
|
+
community._setState("updating");
|
|
263
|
+
try {
|
|
264
|
+
await updateOnce(community);
|
|
265
|
+
}
|
|
266
|
+
catch (e) {
|
|
267
|
+
community.emit("error", e);
|
|
268
|
+
}
|
|
269
|
+
community._updateLoopAbortController = new AbortController();
|
|
270
|
+
community._updateLoopPromise = updateLoop(community);
|
|
271
|
+
}
|
|
272
|
+
export async function stop(community) {
|
|
273
|
+
const log = Logger("pkc-js:local-community:stop");
|
|
274
|
+
community._stopHasBeenCalled = true;
|
|
275
|
+
if (community._updateLoopAbortController) {
|
|
276
|
+
community._updateLoopAbortController.abort();
|
|
277
|
+
}
|
|
278
|
+
community.posts._stop();
|
|
279
|
+
if (community.state === "started") {
|
|
280
|
+
log("Stopping running community", community.address);
|
|
281
|
+
try {
|
|
282
|
+
await community._clientsManager.pubsubUnsubscribe(pubsubTopicWithfallback(community), community.handleChallengeExchange);
|
|
283
|
+
}
|
|
284
|
+
catch (e) {
|
|
285
|
+
log.error("Failed to unsubscribe from challenge exchange pubsub when stopping community", e);
|
|
286
|
+
}
|
|
287
|
+
if (community._publishLoopPromise) {
|
|
288
|
+
try {
|
|
289
|
+
await community._publishLoopPromise;
|
|
290
|
+
}
|
|
291
|
+
catch (e) {
|
|
292
|
+
log.error(`Failed to stop community publish loop`, e);
|
|
293
|
+
}
|
|
294
|
+
community._publishLoopPromise = undefined;
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
await unpinStaleCids(community);
|
|
298
|
+
}
|
|
299
|
+
catch (e) {
|
|
300
|
+
log.error("Failed to unpin stale cids and remove mfs paths before stopping", e);
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
await updateDbInternalState(community, community.updateCid ? community.toJSONInternalAfterFirstUpdate() : community.toJSONInternalBeforeFirstUpdate());
|
|
304
|
+
}
|
|
305
|
+
catch (e) {
|
|
306
|
+
log.error("Failed to update db internal state before stopping", e);
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
await community._dbHandler.unlockCommunityStart();
|
|
310
|
+
}
|
|
311
|
+
catch (e) {
|
|
312
|
+
log.error(`Failed to unlock start lock on community (${community.address})`, e);
|
|
313
|
+
}
|
|
314
|
+
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
315
|
+
const pubsubClient = community._clientsManager.getDefaultKuboPubsubClient();
|
|
316
|
+
community._setStartedStateWithEmission("stopped");
|
|
317
|
+
untrackStartedCommunity(community._pkc, community);
|
|
318
|
+
processStartedCommunities.untrack(community);
|
|
319
|
+
community._duplicatePublicationAttempts?.clear();
|
|
320
|
+
await community._dbHandler.rollbackAllTransactions();
|
|
321
|
+
await community._dbHandler.unlockCommunityState();
|
|
322
|
+
await community._updateStartedValue();
|
|
323
|
+
community._clientsManager.updateKuboRpcState("stopped", kuboRpcClient.url);
|
|
324
|
+
community._clientsManager.updateKuboRpcPubsubState("stopped", pubsubClient.url);
|
|
325
|
+
if (community._dbHandler)
|
|
326
|
+
community._dbHandler.destoryConnection();
|
|
327
|
+
log(`Stopped the running of local community (${community.address})`);
|
|
328
|
+
community._setState("stopped");
|
|
329
|
+
}
|
|
330
|
+
else if (community.state === "updating") {
|
|
331
|
+
if (community._updateLoopPromise) {
|
|
332
|
+
await community._updateLoopPromise;
|
|
333
|
+
community._updateLoopPromise = undefined;
|
|
334
|
+
}
|
|
335
|
+
community._updateLoopAbortController = undefined;
|
|
336
|
+
if (community._dbHandler)
|
|
337
|
+
community._dbHandler.destoryConnection();
|
|
338
|
+
if (community._mirroredStartedOrUpdatingCommunity)
|
|
339
|
+
await cleanUpMirroredStartedOrUpdatingCommunity(community);
|
|
340
|
+
if (findUpdatingCommunity(community._pkc, { publicKey: community.publicKey, name: community.name }) === community)
|
|
341
|
+
untrackUpdatingCommunity(community._pkc, community);
|
|
342
|
+
community._setUpdatingStateWithEventEmissionIfNewState("stopped");
|
|
343
|
+
log(`Stopped the updating of local community (${community.address})`);
|
|
344
|
+
community._setState("stopped");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
export async function deleteCommunity(community) {
|
|
348
|
+
const log = Logger("pkc-js:local-community:delete");
|
|
349
|
+
log.trace(`Attempting to stop the community (${community.address}) before deleting, if needed`);
|
|
350
|
+
const startedCommunity = ((findStartedCommunity(community._pkc, { publicKey: community.publicKey, name: community.name }) ||
|
|
351
|
+
findCommunityInRegistry(processStartedCommunities, { publicKey: community.publicKey, name: community.name })));
|
|
352
|
+
if (startedCommunity && startedCommunity !== community) {
|
|
353
|
+
await startedCommunity.delete();
|
|
354
|
+
await community.stop();
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (community.state === "updating" || community.state === "started")
|
|
358
|
+
await community.stop();
|
|
359
|
+
const kuboClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
360
|
+
if (!kuboClient)
|
|
361
|
+
throw Error("Ipfs client is not defined");
|
|
362
|
+
if (typeof community.signer?.ipnsKeyName === "string")
|
|
363
|
+
// Key may not exist on ipfs node
|
|
364
|
+
try {
|
|
365
|
+
await kuboClient._client.key.rm(community.signer.ipnsKeyName);
|
|
366
|
+
}
|
|
367
|
+
catch (e) {
|
|
368
|
+
log.error("Failed to delete ipns key", community.signer.ipnsKeyName, e);
|
|
369
|
+
}
|
|
370
|
+
try {
|
|
371
|
+
await removeMfsFilesSafely({ kuboRpcClient: kuboClient, paths: ["/" + community.address], log });
|
|
372
|
+
}
|
|
373
|
+
catch (e) {
|
|
374
|
+
log.error("Failed to delete community mfs folder", "/" + community.address, e);
|
|
375
|
+
}
|
|
376
|
+
// sceneario 1: we call delete() on a community that is not started or updating
|
|
377
|
+
// scenario 2: we call delete() on a community that is updating
|
|
378
|
+
// scenario 3: we call delete() on a community that is started
|
|
379
|
+
// scenario 4: we call delete() on a community that is not started, but the same community is started in pkc._startedCommunities[address]
|
|
380
|
+
try {
|
|
381
|
+
await community._addOldPageCidsToCidsToUnpin(community.raw?.communityIpfs?.posts, undefined);
|
|
382
|
+
}
|
|
383
|
+
catch (e) {
|
|
384
|
+
log.error("Failed to add old page cids from community.posts to be unpinned", e);
|
|
385
|
+
}
|
|
386
|
+
if (community.ipnsPubsubTopicRoutingCid)
|
|
387
|
+
community._cidsToUnPin.add(community.ipnsPubsubTopicRoutingCid);
|
|
388
|
+
if (community.pubsubTopicRoutingCid)
|
|
389
|
+
community._cidsToUnPin.add(community.pubsubTopicRoutingCid);
|
|
390
|
+
try {
|
|
391
|
+
await community.initDbHandlerIfNeeded();
|
|
392
|
+
await community._dbHandler.initDbIfNeeded();
|
|
393
|
+
const cidsAndReplies = community._dbHandler.queryAllCommentCidsAndTheirReplies();
|
|
394
|
+
for (const comment of cidsAndReplies) {
|
|
395
|
+
community._cidsToUnPin.add(comment.cid);
|
|
396
|
+
for (const pageCid of comment.allPageCids) {
|
|
397
|
+
community._cidsToUnPin.add(pageCid);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
catch (e) {
|
|
402
|
+
log.error("Failed to query all cids under this community to delete them", e);
|
|
403
|
+
}
|
|
404
|
+
if (community.updateCid)
|
|
405
|
+
community._cidsToUnPin.add(community.updateCid);
|
|
406
|
+
if (community.statsCid)
|
|
407
|
+
community._cidsToUnPin.add(community.statsCid);
|
|
408
|
+
try {
|
|
409
|
+
await unpinStaleCids(community);
|
|
410
|
+
}
|
|
411
|
+
catch (e) {
|
|
412
|
+
log.error("Failed to unpin stale cids before deleting", e);
|
|
413
|
+
}
|
|
414
|
+
try {
|
|
415
|
+
await updateDbInternalState(community, typeof community.updatedAt === "number"
|
|
416
|
+
? community.toJSONInternalAfterFirstUpdate()
|
|
417
|
+
: community.toJSONInternalBeforeFirstUpdate());
|
|
418
|
+
}
|
|
419
|
+
catch (e) {
|
|
420
|
+
log.error("Failed to update db internal state before deleting", e);
|
|
421
|
+
}
|
|
422
|
+
finally {
|
|
423
|
+
community._dbHandler.destoryConnection();
|
|
424
|
+
}
|
|
425
|
+
await moveCommunityDbToDeletedDirectory(community.address, community._pkc);
|
|
426
|
+
log(`Deleted community (${community.address}) successfully`);
|
|
427
|
+
}
|
|
428
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../../../../../src/runtime/browser/community/local-community/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAC3C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,GAAG,MAAM,wBAAwB,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,mDAAmD,EAAE,MAAM,wBAAwB,CAAC;AAC7F,OAAO,EACH,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EAC3B,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,cAAc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CAAC,QAAQ,CAAC,CAAC;IAEvE,IAAI,CAAC;QACD,MAAM,cAAc,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,GAAG,CAAC,KAAK,CAAC,4CAA4C,EAAE,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,CAAC;QACD,MAAM,qBAAqB,CACvB,SAAS,EACT,OAAO,SAAS,CAAC,SAAS,KAAK,QAAQ;YACnC,CAAC,CAAC,SAAS,CAAC,8BAA8B,EAAE;YAC5C,CAAC,CAAC,SAAS,CAAC,+BAA+B,EAAE,CACpD,CAAC;IACN,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,GAAG,CAAC,KAAK,CAAC,oDAAoD,EAAE,CAAC,CAAC,CAAC;IACvE,CAAC;YAAS,CAAC;QACP,SAAS,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAC;IAC7C,CAAC;IAED,MAAM,iCAAiC,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;IAE3E,GAAG,CAAC,sBAAsB,SAAS,CAAC,OAAO,gBAAgB,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { CommentEditPubsubMessagePublication } from "../../../../publications/comment-edit/types.js";
|
|
2
|
+
import type { CommentIpfsType, CommentPubsubMessagePublication, CommentUpdateType, PostPubsubMessageWithCommunityAuthor, ReplyPubsubMessageWithCommunityAuthor } from "../../../../publications/comment/types.js";
|
|
3
|
+
import type { CommentModerationPubsubMessagePublication } from "../../../../publications/comment-moderation/types.js";
|
|
4
|
+
import type { VotePubsubMessagePublication } from "../../../../publications/vote/types.js";
|
|
5
|
+
import type { CommunityEditPubsubMessagePublication } from "../../../../publications/community-edit/types.js";
|
|
6
|
+
import type { PseudonymityAliasRow } from "../db-handler-types.js";
|
|
7
|
+
import type { ChallengeRequestMessageType, DecryptedChallengeRequestMessageType } from "../../../../pubsub-messages/types.js";
|
|
8
|
+
import type { LocalCommunity } from "../local-community.js";
|
|
9
|
+
export declare function isPublicationReply(publication: CommentPubsubMessagePublication): publication is ReplyPubsubMessageWithCommunityAuthor;
|
|
10
|
+
export declare function isPublicationPost(publication: CommentPubsubMessagePublication): publication is PostPubsubMessageWithCommunityAuthor;
|
|
11
|
+
export declare function calculateLinkProps(community: LocalCommunity, link: CommentPubsubMessagePublication["link"]): Promise<Pick<CommentIpfsType, "thumbnailUrl" | "thumbnailUrlWidth" | "thumbnailUrlHeight"> | undefined>;
|
|
12
|
+
export declare function calculateLatestPostProps(community: LocalCommunity): Promise<Pick<CommentIpfsType, "previousCid" | "depth">>;
|
|
13
|
+
export declare function calculateReplyProps(community: LocalCommunity, comment: CommentPubsubMessagePublication): Promise<Pick<CommentIpfsType, "previousCid" | "depth" | "postCid">>;
|
|
14
|
+
export declare function resolveAliasPrivateKeyForCommentPublication(community: LocalCommunity, opts: {
|
|
15
|
+
mode: PseudonymityAliasRow["mode"];
|
|
16
|
+
originalAuthorPublicKey: PseudonymityAliasRow["originalAuthorPublicKey"];
|
|
17
|
+
postCid?: string;
|
|
18
|
+
}): Promise<string>;
|
|
19
|
+
export declare function prepareCommentWithAnonymity(community: LocalCommunity, originalComment: CommentPubsubMessagePublication): Promise<{
|
|
20
|
+
publication: CommentPubsubMessagePublication;
|
|
21
|
+
anonymity?: {
|
|
22
|
+
aliasPrivateKey: PseudonymityAliasRow["aliasPrivateKey"];
|
|
23
|
+
originalAuthorPublicKey: PseudonymityAliasRow["originalAuthorPublicKey"];
|
|
24
|
+
mode: PseudonymityAliasRow["mode"];
|
|
25
|
+
originalComment: CommentPubsubMessagePublication;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
export declare function prepareCommentEditWithAlias(community: LocalCommunity, originalEdit: CommentEditPubsubMessagePublication): Promise<{
|
|
29
|
+
timestamp: number;
|
|
30
|
+
signature: {
|
|
31
|
+
type: string;
|
|
32
|
+
signature: string;
|
|
33
|
+
publicKey: string;
|
|
34
|
+
signedPropertyNames: string[];
|
|
35
|
+
};
|
|
36
|
+
protocolVersion: string;
|
|
37
|
+
commentCid: string;
|
|
38
|
+
flairs?: {
|
|
39
|
+
[x: string]: unknown;
|
|
40
|
+
text: string;
|
|
41
|
+
backgroundColor?: string | undefined;
|
|
42
|
+
textColor?: string | undefined;
|
|
43
|
+
expiresAt?: number | undefined;
|
|
44
|
+
}[] | undefined;
|
|
45
|
+
author?: {
|
|
46
|
+
name?: string | undefined;
|
|
47
|
+
previousCommentCid?: string | undefined;
|
|
48
|
+
displayName?: string | undefined;
|
|
49
|
+
wallets?: Record<string, {
|
|
50
|
+
address: string;
|
|
51
|
+
timestamp: number;
|
|
52
|
+
signature: {
|
|
53
|
+
signature: string;
|
|
54
|
+
type: string;
|
|
55
|
+
};
|
|
56
|
+
}> | undefined;
|
|
57
|
+
avatar?: {
|
|
58
|
+
[x: string]: unknown;
|
|
59
|
+
chainTicker: string;
|
|
60
|
+
address: string;
|
|
61
|
+
id: string;
|
|
62
|
+
timestamp: number;
|
|
63
|
+
signature: {
|
|
64
|
+
signature: string;
|
|
65
|
+
type: string;
|
|
66
|
+
};
|
|
67
|
+
} | undefined;
|
|
68
|
+
flairs?: {
|
|
69
|
+
[x: string]: unknown;
|
|
70
|
+
text: string;
|
|
71
|
+
backgroundColor?: string | undefined;
|
|
72
|
+
textColor?: string | undefined;
|
|
73
|
+
expiresAt?: number | undefined;
|
|
74
|
+
}[] | undefined;
|
|
75
|
+
} | undefined;
|
|
76
|
+
communityPublicKey?: string | undefined;
|
|
77
|
+
communityName?: string | undefined;
|
|
78
|
+
spoiler?: boolean | undefined;
|
|
79
|
+
nsfw?: boolean | undefined;
|
|
80
|
+
reason?: string | undefined;
|
|
81
|
+
content?: string | undefined;
|
|
82
|
+
deleted?: boolean | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
export declare function storeCommentEdit(community: LocalCommunity, commentEditRaw: CommentEditPubsubMessagePublication, challengeRequestId: ChallengeRequestMessageType["challengeRequestId"]): Promise<undefined>;
|
|
85
|
+
export declare function storeCommentModeration(community: LocalCommunity, commentModRaw: CommentModerationPubsubMessagePublication, challengeRequestId: ChallengeRequestMessageType["challengeRequestId"]): Promise<undefined>;
|
|
86
|
+
export declare function storeVote(community: LocalCommunity, newVoteProps: VotePubsubMessagePublication, challengeRequestId: ChallengeRequestMessageType["challengeRequestId"]): Promise<undefined>;
|
|
87
|
+
export declare function storeCommunityEditPublication(community: LocalCommunity, editProps: CommunityEditPubsubMessagePublication, challengeRequestId: ChallengeRequestMessageType["challengeRequestId"]): Promise<undefined>;
|
|
88
|
+
export declare function storeComment(community: LocalCommunity, opts: {
|
|
89
|
+
commentPubsub: CommentPubsubMessagePublication;
|
|
90
|
+
pendingApproval?: boolean;
|
|
91
|
+
pseudonymityMode?: PseudonymityAliasRow["mode"];
|
|
92
|
+
originalCommentSignatureEncoded?: string;
|
|
93
|
+
}): Promise<{
|
|
94
|
+
comment: CommentIpfsType;
|
|
95
|
+
cid: CommentUpdateType["cid"];
|
|
96
|
+
}>;
|
|
97
|
+
export declare function storePublication(community: LocalCommunity, request: DecryptedChallengeRequestMessageType, pendingApproval?: boolean): Promise<{
|
|
98
|
+
comment: CommentIpfsType;
|
|
99
|
+
cid: CommentUpdateType["cid"];
|
|
100
|
+
} | undefined>;
|