cojson 0.18.0 → 0.18.2
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/coValueCore/branching.d.ts +36 -0
- package/dist/coValueCore/branching.d.ts.map +1 -0
- package/dist/coValueCore/branching.js +122 -0
- package/dist/coValueCore/branching.js.map +1 -0
- package/dist/coValueCore/coValueCore.d.ts +71 -5
- package/dist/coValueCore/coValueCore.d.ts.map +1 -1
- package/dist/coValueCore/coValueCore.js +162 -53
- package/dist/coValueCore/coValueCore.js.map +1 -1
- package/dist/coValueCore/decodeTransactionChangesAndMeta.d.ts +3 -0
- package/dist/coValueCore/decodeTransactionChangesAndMeta.d.ts.map +1 -0
- package/dist/coValueCore/decodeTransactionChangesAndMeta.js +59 -0
- package/dist/coValueCore/decodeTransactionChangesAndMeta.js.map +1 -0
- package/dist/coValueCore/utils.d.ts.map +1 -1
- package/dist/coValueCore/utils.js +3 -0
- package/dist/coValueCore/utils.js.map +1 -1
- package/dist/coValueCore/verifiedState.d.ts.map +1 -1
- package/dist/coValues/coList.d.ts +3 -3
- package/dist/coValues/coList.d.ts.map +1 -1
- package/dist/coValues/coList.js +4 -7
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.d.ts +3 -3
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coMap.js +6 -6
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.d.ts +3 -3
- package/dist/coValues/coStream.d.ts.map +1 -1
- package/dist/coValues/coStream.js +4 -4
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js.map +1 -1
- package/dist/jsonStringify.d.ts +1 -0
- package/dist/jsonStringify.d.ts.map +1 -1
- package/dist/jsonStringify.js +8 -0
- package/dist/jsonStringify.js.map +1 -1
- package/dist/localNode.d.ts +6 -0
- package/dist/localNode.d.ts.map +1 -1
- package/dist/localNode.js +27 -0
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.d.ts +2 -7
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +75 -71
- package/dist/permissions.js.map +1 -1
- package/dist/tests/branching.test.d.ts +2 -0
- package/dist/tests/branching.test.d.ts.map +1 -0
- package/dist/tests/branching.test.js +287 -0
- package/dist/tests/branching.test.js.map +1 -0
- package/dist/tests/coValueCore.test.js +2 -3
- package/dist/tests/coValueCore.test.js.map +1 -1
- package/dist/tests/group.removeMember.test.js +63 -116
- package/dist/tests/group.removeMember.test.js.map +1 -1
- package/dist/tests/sync.load.test.js +36 -0
- package/dist/tests/sync.load.test.js.map +1 -1
- package/dist/tests/sync.storage.test.js +39 -3
- package/dist/tests/sync.storage.test.js.map +1 -1
- package/dist/tests/sync.upload.test.js +39 -3
- package/dist/tests/sync.upload.test.js.map +1 -1
- package/package.json +2 -2
- package/src/coValueCore/branching.ts +198 -0
- package/src/coValueCore/coValueCore.ts +255 -72
- package/src/coValueCore/decodeTransactionChangesAndMeta.ts +81 -0
- package/src/coValueCore/utils.ts +4 -0
- package/src/coValueCore/verifiedState.ts +1 -1
- package/src/coValues/coList.ts +8 -10
- package/src/coValues/coMap.ts +8 -11
- package/src/coValues/coStream.ts +7 -8
- package/src/ids.ts +4 -1
- package/src/jsonStringify.ts +8 -0
- package/src/localNode.ts +40 -0
- package/src/permissions.ts +83 -90
- package/src/tests/branching.test.ts +425 -0
- package/src/tests/coValueCore.test.ts +2 -3
- package/src/tests/group.removeMember.test.ts +116 -214
- package/src/tests/sync.load.test.ts +48 -0
- package/src/tests/sync.storage.test.ts +54 -3
- package/src/tests/sync.upload.test.ts +53 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.upload.test.js","sourceRoot":"","sources":["../../src/tests/sync.upload.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,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QAChD,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;QACjC,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,aAAa;QACrC,MAAM,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;QAEpC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAEnE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAChC,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC;YACtB,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QACvC,CAAC;QAED,MAAM,iBAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;QAElD,MAAM,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QAElC,MAAM,CACJ,eAAe,CAAC,WAAW,CAAC;YAC1B,KAAK,EAAE,KAAK,CAAC,IAAI;YACjB,GAAG,EAAE,QAAQ,CAAC,IAAI;SACnB,CAAC,CACH,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCvB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"type": "module",
|
|
27
27
|
"license": "MIT",
|
|
28
|
-
"version": "0.18.
|
|
28
|
+
"version": "0.18.2",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@opentelemetry/sdk-metrics": "^2.0.0",
|
|
31
31
|
"libsql": "^0.5.13",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@scure/base": "1.2.1",
|
|
40
40
|
"neverthrow": "^7.0.1",
|
|
41
41
|
"unicode-segmenter": "^0.12.0",
|
|
42
|
-
"cojson-core-wasm": "0.18.
|
|
42
|
+
"cojson-core-wasm": "0.18.2"
|
|
43
43
|
},
|
|
44
44
|
"gitHead": "33c27053293b4801b968c61d5c4c989f93a67d13",
|
|
45
45
|
"scripts": {
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { CoValueCore } from "../exports.js";
|
|
2
|
+
import { RawCoID, SessionID } from "../ids.js";
|
|
3
|
+
import { AvailableCoValueCore, idforHeader } from "./coValueCore.js";
|
|
4
|
+
import { CoValueHeader } from "./verifiedState.js";
|
|
5
|
+
import { CoValueKnownState } from "../sync.js";
|
|
6
|
+
|
|
7
|
+
export function getBranchHeader({
|
|
8
|
+
type,
|
|
9
|
+
branchName,
|
|
10
|
+
ownerId,
|
|
11
|
+
sourceId,
|
|
12
|
+
}: {
|
|
13
|
+
type: CoValueHeader["type"];
|
|
14
|
+
branchName: string;
|
|
15
|
+
ownerId: RawCoID;
|
|
16
|
+
sourceId: RawCoID;
|
|
17
|
+
}): CoValueHeader {
|
|
18
|
+
return {
|
|
19
|
+
type,
|
|
20
|
+
// Branch name and source id are stored in the meta field
|
|
21
|
+
// and used to generate the unique id for the branch
|
|
22
|
+
meta: {
|
|
23
|
+
branch: branchName,
|
|
24
|
+
source: sourceId,
|
|
25
|
+
},
|
|
26
|
+
ruleset: {
|
|
27
|
+
type: "ownedByGroup",
|
|
28
|
+
// The owner is part of the id generation, making it possible to have multiple branches with the same name
|
|
29
|
+
// but different owners
|
|
30
|
+
group: ownerId,
|
|
31
|
+
},
|
|
32
|
+
// The meta is enough to have reproducible unique id for the branch
|
|
33
|
+
uniqueness: "",
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Given a coValue, a branch name and an owner id, returns the id for the branch
|
|
39
|
+
*/
|
|
40
|
+
export function getBranchId(
|
|
41
|
+
coValue: CoValueCore,
|
|
42
|
+
name: string,
|
|
43
|
+
ownerId: RawCoID,
|
|
44
|
+
): RawCoID {
|
|
45
|
+
if (!coValue.verified) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"CoValueCore: getBranchId called on coValue without verified state",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const header = getBranchHeader({
|
|
52
|
+
type: coValue.verified.header.type,
|
|
53
|
+
branchName: name,
|
|
54
|
+
ownerId,
|
|
55
|
+
sourceId: coValue.id,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return idforHeader(header, coValue.node.crypto);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type BranchCommit = {
|
|
62
|
+
branch: CoValueKnownState["sessions"];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Given a coValue, a branch name and an owner id, creates a new branch CoValue
|
|
67
|
+
*/
|
|
68
|
+
export function createBranch(
|
|
69
|
+
coValue: CoValueCore,
|
|
70
|
+
name: string,
|
|
71
|
+
ownerId: RawCoID,
|
|
72
|
+
): CoValueCore {
|
|
73
|
+
if (!coValue.verified) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
"CoValueCore: createBranch called on coValue without verified state",
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const header = getBranchHeader({
|
|
80
|
+
type: coValue.verified.header.type,
|
|
81
|
+
branchName: name,
|
|
82
|
+
ownerId,
|
|
83
|
+
sourceId: coValue.id,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const value = coValue.node.createCoValue(header);
|
|
87
|
+
|
|
88
|
+
// Create a branch commit to identify the starting point of the branch
|
|
89
|
+
value.makeTransaction([], "private", {
|
|
90
|
+
branch: coValue.knownState().sessions,
|
|
91
|
+
} satisfies BranchCommit);
|
|
92
|
+
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Given a branch coValue, returns the source coValue if available
|
|
98
|
+
*/
|
|
99
|
+
export function getBranchSource(
|
|
100
|
+
coValue: CoValueCore,
|
|
101
|
+
): AvailableCoValueCore | undefined {
|
|
102
|
+
if (!coValue.verified) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const sourceId = coValue.verified.header.meta?.source;
|
|
107
|
+
|
|
108
|
+
if (!sourceId) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const source = coValue.node.getCoValue(sourceId as RawCoID);
|
|
113
|
+
|
|
114
|
+
if (!source.isAvailable()) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return source;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type MergeCommit = {
|
|
122
|
+
// The point where the branch was merged
|
|
123
|
+
merge: CoValueKnownState["sessions"];
|
|
124
|
+
// The id of the branch that was merged
|
|
125
|
+
id: RawCoID;
|
|
126
|
+
// The number of transactions that were merged, will be used in the future to handle the edits history properly
|
|
127
|
+
count: number;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Given a branch coValue, merges the branch into the source coValue
|
|
132
|
+
*/
|
|
133
|
+
export function mergeBranch(branch: CoValueCore): CoValueCore {
|
|
134
|
+
if (!branch.verified) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
"CoValueCore: mergeBranch called on coValue without verified state",
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const sourceId = branch.verified.header.meta?.source;
|
|
141
|
+
|
|
142
|
+
if (!sourceId) {
|
|
143
|
+
throw new Error("CoValueCore: mergeBranch called on a non-branch coValue");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const target = getBranchSource(branch);
|
|
147
|
+
|
|
148
|
+
if (!target) {
|
|
149
|
+
throw new Error("CoValueCore: unable to find source branch");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Look for previous merge commits, to see which transactions needs to be merged
|
|
153
|
+
// Done mostly for performance reasons, as we could merge all the transactions every time and nothing would change
|
|
154
|
+
const mergedTransactions = target.mergeCommits.reduce(
|
|
155
|
+
(acc, { commit }) => {
|
|
156
|
+
if (commit.id !== branch.id) {
|
|
157
|
+
return acc;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
for (const [sessionID, count] of Object.entries(commit.merge) as [
|
|
161
|
+
SessionID,
|
|
162
|
+
number,
|
|
163
|
+
][]) {
|
|
164
|
+
acc[sessionID] = Math.max(acc[sessionID] ?? 0, count);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return acc;
|
|
168
|
+
},
|
|
169
|
+
{} as CoValueKnownState["sessions"],
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
// Get the valid transactions from the branch, skipping the branch source and the previously merged transactions
|
|
173
|
+
const branchValidTransactions = branch
|
|
174
|
+
.getValidTransactions({
|
|
175
|
+
from: mergedTransactions,
|
|
176
|
+
ignorePrivateTransactions: false,
|
|
177
|
+
skipBranchSource: true,
|
|
178
|
+
})
|
|
179
|
+
.filter((tx) => tx.changes.length > 0);
|
|
180
|
+
|
|
181
|
+
// If there are no valid transactions to merge, we don't want to create a merge commit
|
|
182
|
+
if (branchValidTransactions.length === 0) {
|
|
183
|
+
return target;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Create a merge commit to identify the merge point
|
|
187
|
+
target.makeTransaction([], "private", {
|
|
188
|
+
merge: { ...branch.knownState().sessions },
|
|
189
|
+
id: branch.id,
|
|
190
|
+
count: branchValidTransactions.length,
|
|
191
|
+
} satisfies MergeCommit);
|
|
192
|
+
|
|
193
|
+
for (const { tx, changes } of branchValidTransactions) {
|
|
194
|
+
target.makeTransaction(changes, tx.privacy);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return target;
|
|
198
|
+
}
|
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
Signature,
|
|
16
16
|
SignerID,
|
|
17
17
|
} from "../crypto/crypto.js";
|
|
18
|
-
import { RawCoID, SessionID, TransactionID } from "../ids.js";
|
|
18
|
+
import { AgentID, RawCoID, SessionID, TransactionID } from "../ids.js";
|
|
19
19
|
import { JsonObject, JsonValue } from "../jsonValue.js";
|
|
20
|
-
import { parseJSON } from "../jsonStringify.js";
|
|
20
|
+
import { parseJSON, safeParseJSON } from "../jsonStringify.js";
|
|
21
21
|
import { LocalNode, ResolveAccountAgentError } from "../localNode.js";
|
|
22
22
|
import { logger } from "../logger.js";
|
|
23
23
|
import { determineValidTransactions } from "../permissions.js";
|
|
@@ -27,6 +27,15 @@ import { expectGroup } from "../typeUtils/expectGroup.js";
|
|
|
27
27
|
import { getDependedOnCoValuesFromRawData } from "./utils.js";
|
|
28
28
|
import { CoValueHeader, Transaction, VerifiedState } from "./verifiedState.js";
|
|
29
29
|
import { SessionMap } from "./SessionMap.js";
|
|
30
|
+
import {
|
|
31
|
+
MergeCommit,
|
|
32
|
+
createBranch,
|
|
33
|
+
getBranchId,
|
|
34
|
+
getBranchSource,
|
|
35
|
+
mergeBranch,
|
|
36
|
+
} from "./branching.js";
|
|
37
|
+
import { type RawAccountID } from "../coValues/account.js";
|
|
38
|
+
import { decodeTransactionChangesAndMeta } from "./decodeTransactionChangesAndMeta.js";
|
|
30
39
|
|
|
31
40
|
export function idforHeader(
|
|
32
41
|
header: CoValueHeader,
|
|
@@ -36,11 +45,38 @@ export function idforHeader(
|
|
|
36
45
|
return `co_z${hash.slice("shortHash_z".length)}`;
|
|
37
46
|
}
|
|
38
47
|
|
|
48
|
+
export type VerifiedTransaction = {
|
|
49
|
+
// The account or agent that made the transaction
|
|
50
|
+
author: RawAccountID | AgentID;
|
|
51
|
+
// An object containing the session ID and the transaction index
|
|
52
|
+
txID: TransactionID;
|
|
53
|
+
tx: Transaction;
|
|
54
|
+
// The Unix time when the transaction was made
|
|
55
|
+
madeAt: number;
|
|
56
|
+
// Whether the transaction has been validated, used to track if determinedValidTransactions needs to be check this
|
|
57
|
+
isValidated: boolean;
|
|
58
|
+
// The decoded changes of the transaction
|
|
59
|
+
changes: JsonValue[] | undefined;
|
|
60
|
+
// The decoded meta information of the transaction
|
|
61
|
+
meta: JsonObject | undefined;
|
|
62
|
+
|
|
63
|
+
// Whether the transaction is valid, as per membership rules
|
|
64
|
+
isValid: boolean;
|
|
65
|
+
|
|
66
|
+
// True if we encountered an error while decoding the changes
|
|
67
|
+
hasInvalidChanges: boolean;
|
|
68
|
+
// True if we encountered an error while parsing the meta
|
|
69
|
+
hasInvalidMeta: boolean;
|
|
70
|
+
|
|
71
|
+
// True if the meta information has been parsed and loaded in the CoValueCore
|
|
72
|
+
hasMetaBeenParsed: boolean;
|
|
73
|
+
};
|
|
74
|
+
|
|
39
75
|
export type DecryptedTransaction = {
|
|
40
76
|
txID: TransactionID;
|
|
41
77
|
changes: JsonValue[];
|
|
42
78
|
madeAt: number;
|
|
43
|
-
|
|
79
|
+
tx: Transaction;
|
|
44
80
|
};
|
|
45
81
|
|
|
46
82
|
export type AvailableCoValueCore = CoValueCore & { verified: VerifiedState };
|
|
@@ -82,10 +118,6 @@ export class CoValueCore {
|
|
|
82
118
|
private _cachedContent?: RawCoValue;
|
|
83
119
|
readonly listeners: Set<(core: CoValueCore, unsub: () => void) => void> =
|
|
84
120
|
new Set();
|
|
85
|
-
private readonly _decryptionCache: {
|
|
86
|
-
[key: Encrypted<JsonValue[], JsonValue>]: JsonValue[] | undefined;
|
|
87
|
-
[key: Encrypted<JsonObject, JsonValue>]: JsonObject | undefined;
|
|
88
|
-
} = {};
|
|
89
121
|
private _cachedDependentOn?: Set<RawCoID>;
|
|
90
122
|
private counter: UpDownCounter;
|
|
91
123
|
|
|
@@ -340,13 +372,13 @@ export class CoValueCore {
|
|
|
340
372
|
);
|
|
341
373
|
}
|
|
342
374
|
this._verified = state.clone();
|
|
343
|
-
this.
|
|
344
|
-
this._cachedDependentOn = undefined;
|
|
375
|
+
this.internalShamefullyResetCachedContent();
|
|
345
376
|
}
|
|
346
377
|
|
|
347
378
|
internalShamefullyResetCachedContent() {
|
|
348
379
|
this._cachedContent = undefined;
|
|
349
380
|
this._cachedDependentOn = undefined;
|
|
381
|
+
this.resetParsedTransactions();
|
|
350
382
|
}
|
|
351
383
|
|
|
352
384
|
groupInvalidationSubscription?: () => void;
|
|
@@ -368,7 +400,8 @@ export class CoValueCore {
|
|
|
368
400
|
|
|
369
401
|
if (entry.isAvailable()) {
|
|
370
402
|
this.groupInvalidationSubscription = entry.subscribe((_groupUpdate) => {
|
|
371
|
-
|
|
403
|
+
// When the group is updated, we need to reset the cached content because the transactions validity might have changed
|
|
404
|
+
this.internalShamefullyResetCachedContent();
|
|
372
405
|
this.notifyUpdate("immediate");
|
|
373
406
|
}, false);
|
|
374
407
|
} else {
|
|
@@ -588,14 +621,6 @@ export class CoValueCore {
|
|
|
588
621
|
keySecret,
|
|
589
622
|
meta,
|
|
590
623
|
);
|
|
591
|
-
|
|
592
|
-
if (result.transaction.privacy === "private") {
|
|
593
|
-
this._decryptionCache[result.transaction.encryptedChanges] = changes;
|
|
594
|
-
|
|
595
|
-
if (result.transaction.meta) {
|
|
596
|
-
this._decryptionCache[result.transaction.meta] = meta;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
624
|
} else {
|
|
600
625
|
result = this.verified.makeNewTrustingTransaction(
|
|
601
626
|
sessionID,
|
|
@@ -609,6 +634,9 @@ export class CoValueCore {
|
|
|
609
634
|
|
|
610
635
|
this.node.syncManager.recordTransactionsSize([transaction], "local");
|
|
611
636
|
|
|
637
|
+
// We pre-populate the parsed transactions and meta for the new transaction, to skip the parsing step later
|
|
638
|
+
this.loadVerifiedTransactionsFromLogs({ transaction, changes, meta });
|
|
639
|
+
|
|
612
640
|
const session = this.verified.sessions.get(sessionID);
|
|
613
641
|
const txIdx = session ? session.transactions.length - 1 : 0;
|
|
614
642
|
|
|
@@ -646,86 +674,235 @@ export class CoValueCore {
|
|
|
646
674
|
return newContent;
|
|
647
675
|
}
|
|
648
676
|
|
|
677
|
+
// The starting point of the branch, in case this CoValue is a branch
|
|
678
|
+
branchStart:
|
|
679
|
+
| { branch: CoValueKnownState["sessions"]; madeAt: number }
|
|
680
|
+
| undefined;
|
|
681
|
+
|
|
682
|
+
// The list of merge commits that have been made
|
|
683
|
+
mergeCommits: { commit: MergeCommit; madeAt: number }[] = [];
|
|
684
|
+
|
|
685
|
+
// Reset the parsed transactions and branches, to validate them again from scratch when the group is updated
|
|
686
|
+
resetParsedTransactions() {
|
|
687
|
+
this.branchStart = undefined;
|
|
688
|
+
this.mergeCommits = [];
|
|
689
|
+
|
|
690
|
+
for (const transaction of this.verifiedTransactions) {
|
|
691
|
+
transaction.isValidated = false;
|
|
692
|
+
transaction.hasMetaBeenParsed = false;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
verifiedTransactions: VerifiedTransaction[] = [];
|
|
697
|
+
private verifiedTransactionsKnownSessions: CoValueKnownState["sessions"] = {};
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Loads the new transaction from the SessionMap into verifiedTransactions as a VerifiedTransaction.
|
|
701
|
+
*
|
|
702
|
+
* If the transaction is already loaded from the SessionMap in the past, it will not be loaded again.
|
|
703
|
+
*
|
|
704
|
+
* Used to have a fast way to iterate over the CoValue transactions, and track their validation/decoding state.
|
|
705
|
+
*
|
|
706
|
+
* @param preload - Optional preload object containing the transaction, changes, and meta.
|
|
707
|
+
* If provided, the transaction will be preloaded with the given changes and meta.
|
|
708
|
+
*
|
|
709
|
+
* @internal
|
|
710
|
+
* */
|
|
711
|
+
loadVerifiedTransactionsFromLogs(preload?: {
|
|
712
|
+
transaction: Transaction;
|
|
713
|
+
changes: JsonValue[];
|
|
714
|
+
meta: JsonObject | undefined;
|
|
715
|
+
}) {
|
|
716
|
+
if (!this.verified) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
for (const [sessionID, sessionLog] of this.verified.sessions.entries()) {
|
|
721
|
+
const count = this.verifiedTransactionsKnownSessions[sessionID] ?? 0;
|
|
722
|
+
|
|
723
|
+
sessionLog.transactions.forEach((tx, txIndex) => {
|
|
724
|
+
if (txIndex < count) {
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
this.verifiedTransactions.push({
|
|
729
|
+
author: accountOrAgentIDfromSessionID(sessionID),
|
|
730
|
+
txID: {
|
|
731
|
+
sessionID,
|
|
732
|
+
txIndex,
|
|
733
|
+
},
|
|
734
|
+
madeAt: tx.madeAt,
|
|
735
|
+
isValidated: false,
|
|
736
|
+
isValid: false,
|
|
737
|
+
changes: tx === preload?.transaction ? preload.changes : undefined,
|
|
738
|
+
meta: tx === preload?.transaction ? preload.meta : undefined,
|
|
739
|
+
hasInvalidChanges: false,
|
|
740
|
+
hasInvalidMeta: false,
|
|
741
|
+
hasMetaBeenParsed: false,
|
|
742
|
+
tx,
|
|
743
|
+
});
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
this.verifiedTransactionsKnownSessions[sessionID] =
|
|
747
|
+
sessionLog.transactions.length;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Iterates over the verifiedTransactions and marks them as valid or invalid, based on the group membership of the authors of the transactions .
|
|
753
|
+
*/
|
|
754
|
+
private determineValidTransactions() {
|
|
755
|
+
determineValidTransactions(this);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Parses the meta information of a transaction, and set the branchStart and mergeCommits.
|
|
760
|
+
*/
|
|
761
|
+
private parseMetaInformation(transaction: VerifiedTransaction) {
|
|
762
|
+
if (
|
|
763
|
+
!transaction.meta ||
|
|
764
|
+
!transaction.isValid ||
|
|
765
|
+
transaction.hasMetaBeenParsed
|
|
766
|
+
) {
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
transaction.hasMetaBeenParsed = true;
|
|
771
|
+
|
|
772
|
+
if (
|
|
773
|
+
transaction.meta?.["branch"] &&
|
|
774
|
+
(!this.branchStart || transaction.madeAt < this.branchStart.madeAt)
|
|
775
|
+
) {
|
|
776
|
+
this.branchStart = {
|
|
777
|
+
branch: transaction.meta.branch as CoValueKnownState["sessions"],
|
|
778
|
+
madeAt: transaction.madeAt,
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
if (transaction.meta?.["merge"]) {
|
|
783
|
+
const mergeCommit = transaction.meta as MergeCommit;
|
|
784
|
+
|
|
785
|
+
this.mergeCommits.push({
|
|
786
|
+
commit: mergeCommit,
|
|
787
|
+
madeAt: transaction.madeAt,
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* Loads the new transactions from SessionMap and:
|
|
794
|
+
* - Validates each transaction based on the group membership of the authors
|
|
795
|
+
* - Decodes the changes & meta for each transaction
|
|
796
|
+
* - Parses the meta information of the transaction
|
|
797
|
+
*/
|
|
798
|
+
private parseNewTransactions(ignorePrivateTransactions: boolean) {
|
|
799
|
+
if (!this.isAvailable()) {
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
this.loadVerifiedTransactionsFromLogs();
|
|
804
|
+
this.determineValidTransactions();
|
|
805
|
+
|
|
806
|
+
for (const transaction of this.verifiedTransactions) {
|
|
807
|
+
decodeTransactionChangesAndMeta(
|
|
808
|
+
this,
|
|
809
|
+
transaction,
|
|
810
|
+
ignorePrivateTransactions,
|
|
811
|
+
);
|
|
812
|
+
this.parseMetaInformation(transaction);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Returns the valid transactions matching the criteria specified in the options
|
|
818
|
+
*/
|
|
649
819
|
getValidTransactions(options?: {
|
|
650
820
|
ignorePrivateTransactions: boolean;
|
|
651
|
-
|
|
821
|
+
// The range, described as knownState sessions, to filter the transactions returned
|
|
822
|
+
from?: CoValueKnownState["sessions"];
|
|
823
|
+
to?: CoValueKnownState["sessions"];
|
|
824
|
+
|
|
825
|
+
// The transactions that have already been processed, used for the incremental builds of the content views
|
|
826
|
+
knownTransactions?: Set<Transaction>;
|
|
827
|
+
|
|
828
|
+
// If true, the branch source transactions will be skipped. Used to gather the transactions for the merge operation.
|
|
829
|
+
skipBranchSource?: boolean;
|
|
652
830
|
}): DecryptedTransaction[] {
|
|
653
831
|
if (!this.verified) {
|
|
654
|
-
|
|
655
|
-
"CoValueCore: getValidTransactions called on coValue without verified state",
|
|
656
|
-
);
|
|
832
|
+
return [];
|
|
657
833
|
}
|
|
658
834
|
|
|
659
|
-
|
|
660
|
-
this,
|
|
661
|
-
options?.knownTransactions,
|
|
662
|
-
);
|
|
835
|
+
this.parseNewTransactions(options?.ignorePrivateTransactions ?? false);
|
|
663
836
|
|
|
664
|
-
const
|
|
837
|
+
const matchingTransactions: DecryptedTransaction[] = [];
|
|
665
838
|
|
|
666
|
-
for (const
|
|
667
|
-
if (
|
|
839
|
+
for (const transaction of this.verifiedTransactions) {
|
|
840
|
+
if (!isValidTransactionWithChanges(transaction)) {
|
|
668
841
|
continue;
|
|
669
842
|
}
|
|
670
843
|
|
|
671
|
-
|
|
844
|
+
if (options?.knownTransactions?.has(transaction.tx)) {
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
672
847
|
|
|
673
|
-
|
|
674
|
-
if (options?.ignorePrivateTransactions) {
|
|
675
|
-
continue;
|
|
676
|
-
}
|
|
848
|
+
options?.knownTransactions?.add(transaction.tx);
|
|
677
849
|
|
|
678
|
-
|
|
850
|
+
const { txID, madeAt } = transaction;
|
|
679
851
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
852
|
+
const from = options?.from?.[txID.sessionID] ?? -1;
|
|
853
|
+
const to = options?.to?.[txID.sessionID] ?? Infinity;
|
|
683
854
|
|
|
684
|
-
|
|
855
|
+
// The txIndex starts at 0 and from/to are referring to the count of transactions
|
|
856
|
+
if (from > txID.txIndex || to < txID.txIndex) {
|
|
857
|
+
continue;
|
|
858
|
+
}
|
|
685
859
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
txID.sessionID,
|
|
689
|
-
txID.txIndex,
|
|
690
|
-
readKey,
|
|
691
|
-
);
|
|
860
|
+
matchingTransactions.push(transaction);
|
|
861
|
+
}
|
|
692
862
|
|
|
693
|
-
|
|
694
|
-
}
|
|
863
|
+
const source = getBranchSource(this);
|
|
695
864
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
865
|
+
// If this is a branch, we load the valid transactions from the source
|
|
866
|
+
if (source && this.branchStart && !options?.skipBranchSource) {
|
|
867
|
+
const sourceTransactions = source.getValidTransactions({
|
|
868
|
+
to: this.branchStart.branch,
|
|
869
|
+
ignorePrivateTransactions: options?.ignorePrivateTransactions ?? false,
|
|
870
|
+
knownTransactions: options?.knownTransactions,
|
|
871
|
+
});
|
|
702
872
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
}
|
|
873
|
+
for (const { changes, tx, madeAt, txID } of sourceTransactions) {
|
|
874
|
+
matchingTransactions.push({
|
|
875
|
+
txID: {
|
|
876
|
+
sessionID: `${txID.sessionID}_branch_${source.id}`,
|
|
877
|
+
txIndex: txID.txIndex,
|
|
878
|
+
},
|
|
879
|
+
madeAt,
|
|
880
|
+
changes,
|
|
881
|
+
tx,
|
|
882
|
+
});
|
|
713
883
|
}
|
|
714
|
-
|
|
715
|
-
allTransactions.push({
|
|
716
|
-
txID,
|
|
717
|
-
madeAt: tx.madeAt,
|
|
718
|
-
changes,
|
|
719
|
-
trusting: tx.privacy === "trusting",
|
|
720
|
-
});
|
|
721
884
|
}
|
|
722
885
|
|
|
723
|
-
return
|
|
886
|
+
return matchingTransactions;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
createBranch(name: string, ownerId: RawCoID) {
|
|
890
|
+
return createBranch(this, name, ownerId);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
mergeBranch() {
|
|
894
|
+
return mergeBranch(this);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
getBranchId(name: string, ownerId: RawCoID) {
|
|
898
|
+
return getBranchId(this, name, ownerId);
|
|
724
899
|
}
|
|
725
900
|
|
|
726
901
|
getValidSortedTransactions(options?: {
|
|
727
902
|
ignorePrivateTransactions: boolean;
|
|
728
|
-
|
|
903
|
+
|
|
904
|
+
// The transactions that have already been processed, used for the incremental builds of the content views
|
|
905
|
+
knownTransactions?: Set<Transaction>;
|
|
729
906
|
}): DecryptedTransaction[] {
|
|
730
907
|
const allTransactions = this.getValidTransactions(options);
|
|
731
908
|
|
|
@@ -1001,3 +1178,9 @@ export type TryAddTransactionsError =
|
|
|
1001
1178
|
| ResolveAccountAgentError
|
|
1002
1179
|
| InvalidHashError
|
|
1003
1180
|
| InvalidSignatureError;
|
|
1181
|
+
|
|
1182
|
+
function isValidTransactionWithChanges(
|
|
1183
|
+
transaction: VerifiedTransaction,
|
|
1184
|
+
): transaction is VerifiedTransaction & { changes: JsonValue[] } {
|
|
1185
|
+
return Boolean(transaction.isValid && transaction.changes);
|
|
1186
|
+
}
|