@storacha/clawracha 0.2.0 → 0.2.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/dist/mdsync/index.d.ts.map +1 -1
- package/dist/mdsync/index.js +19 -8
- package/dist/sync.d.ts +5 -0
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +25 -4
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mdsync/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EACL,YAAY,EAGZ,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mdsync/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EACL,YAAY,EAGZ,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAuJ1C,UAAU,cAAc;IACtB,UAAU,EAAE,GAAG,CAAC;IAChB,SAAS,EAAE,KAAK,EAAE,CAAC;CACpB;AAyBD;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,cAAc,CAEvE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,GAAG,GACd,QAAQ,YAAY,EACpB,SAAS,SAAS,EAClB,KAAK,MAAM,EACX,aAAa,MAAM,KAClB,OAAO,CAAC,cAAc,GAAG,IAAI,CAkC/B,CAAC;AAkSF;;;GAGG;AACH,eAAO,MAAM,GAAG,GACd,QAAQ,YAAY,EACpB,SAAS,SAAS,EAClB,KAAK,MAAM,KACV,OAAO,CAAC,MAAM,GAAG,SAAS,CAM5B,CAAC"}
|
package/dist/mdsync/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { MemoryBlockstore, withCache } from "@storacha/ucn/block";
|
|
|
16
16
|
import * as CRDT from "@web3-storage/pail/crdt";
|
|
17
17
|
import { CID } from "multiformats";
|
|
18
18
|
import * as cbor from "@ipld/dag-cbor";
|
|
19
|
-
import { fromMarkdown, encodeTree, encodeRGA, RGA, decodeRGA, decodeTree, computeChangeSet, applyRGAChangeSet, encodeChangeSet, decodeChangeSet, toMarkdown, } from "@storacha/md-merge";
|
|
19
|
+
import { fromMarkdown, encodeTree, encodeRGA, RGA, decodeRGA, decodeTree, computeChangeSet, applyRGAChangeSet, encodeChangeSet, decodeChangeSet, toMarkdown, mergeRGATrees, } from "@storacha/md-merge";
|
|
20
20
|
import * as Pail from "@web3-storage/pail";
|
|
21
21
|
import { decode, encode } from "multiformats/block";
|
|
22
22
|
import { sha256 } from "multiformats/hashes/sha2";
|
|
@@ -318,15 +318,26 @@ const resolveValue = async (blocks, current, key) => {
|
|
|
318
318
|
const newMDEntry = await getMarkdownEntry(blocks, mdEntryCid);
|
|
319
319
|
if (newMDEntry.type === "initial") {
|
|
320
320
|
// First write for this key — bootstrap from the stored entry.
|
|
321
|
+
const newEventRGA = await getEventRGAFromCID(blocks, newMDEntry.events);
|
|
322
|
+
const newRoot = await getRGATreeFromRootCID(blocks, newMDEntry.root, newEventRGA);
|
|
321
323
|
if (mdEntry) {
|
|
322
|
-
|
|
324
|
+
// Concurrent initial — two branches independently created this key.
|
|
325
|
+
// Merge event histories and merge the two RGA trees.
|
|
326
|
+
mdEntry.events.merge(newEventRGA);
|
|
327
|
+
const comparator = makeComparator(mdEntry.events);
|
|
328
|
+
mdEntry = {
|
|
329
|
+
type: "initial",
|
|
330
|
+
events: mdEntry.events,
|
|
331
|
+
root: mergeRGATrees(mdEntry.root, newRoot, comparator),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
mdEntry = {
|
|
336
|
+
type: "initial",
|
|
337
|
+
events: newEventRGA,
|
|
338
|
+
root: newRoot,
|
|
339
|
+
};
|
|
323
340
|
}
|
|
324
|
-
const eventRGA = await getEventRGAFromCID(blocks, newMDEntry.events);
|
|
325
|
-
mdEntry = {
|
|
326
|
-
type: "initial",
|
|
327
|
-
events: eventRGA,
|
|
328
|
-
root: await getRGATreeFromRootCID(blocks, newMDEntry.root, eventRGA),
|
|
329
|
-
};
|
|
330
341
|
}
|
|
331
342
|
else {
|
|
332
343
|
// Update — merge event histories, then apply the changeset.
|
package/dist/sync.d.ts
CHANGED
|
@@ -29,6 +29,10 @@ export declare class SyncEngine {
|
|
|
29
29
|
* Require running state or throw.
|
|
30
30
|
*/
|
|
31
31
|
private requireRunning;
|
|
32
|
+
/**
|
|
33
|
+
* Require state is initialized or throw.
|
|
34
|
+
*/
|
|
35
|
+
private requireInitialized;
|
|
32
36
|
/**
|
|
33
37
|
* Process a batch of file changes.
|
|
34
38
|
* Can be called even when not running (accumulates pending ops).
|
|
@@ -60,6 +64,7 @@ export declare class SyncEngine {
|
|
|
60
64
|
* Used by join to overwrite local with remote before watcher starts.
|
|
61
65
|
*/
|
|
62
66
|
pullRemote(): Promise<number>;
|
|
67
|
+
private _pullRemoteInner;
|
|
63
68
|
/**
|
|
64
69
|
* Inspect internal state for debugging.
|
|
65
70
|
*/
|
package/dist/sync.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAEV,YAAY,EACb,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,E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AAC,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC5D,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IAkBI,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC;IAW5B,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;YAM5B,WAAW;CAK1B"}
|
package/dist/sync.js
CHANGED
|
@@ -21,7 +21,7 @@ import { decodeDelegation, encodeDelegation } from "./utils/delegation.js";
|
|
|
21
21
|
export class SyncEngine {
|
|
22
22
|
workspace;
|
|
23
23
|
blocks;
|
|
24
|
-
state = { running: false };
|
|
24
|
+
state = { initialized: false, running: false };
|
|
25
25
|
current = null;
|
|
26
26
|
pendingOps = [];
|
|
27
27
|
carFile = null;
|
|
@@ -57,7 +57,7 @@ export class SyncEngine {
|
|
|
57
57
|
// First device — create a new name
|
|
58
58
|
name = await Name.create(agent);
|
|
59
59
|
}
|
|
60
|
-
this.state = { running: true, name, storachaClient };
|
|
60
|
+
this.state = { initialized: true, running: true, name, storachaClient };
|
|
61
61
|
try {
|
|
62
62
|
const result = await Revision.resolve(this.blocks, name);
|
|
63
63
|
this.current = result.value;
|
|
@@ -77,6 +77,15 @@ export class SyncEngine {
|
|
|
77
77
|
*/
|
|
78
78
|
requireRunning() {
|
|
79
79
|
if (!this.state.running) {
|
|
80
|
+
throw new Error("Sync engine not running");
|
|
81
|
+
}
|
|
82
|
+
return this.state;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Require state is initialized or throw.
|
|
86
|
+
*/
|
|
87
|
+
requireInitialized() {
|
|
88
|
+
if (!this.state.initialized) {
|
|
80
89
|
throw new Error("Sync engine not initialized");
|
|
81
90
|
}
|
|
82
91
|
return this.state;
|
|
@@ -201,7 +210,14 @@ export class SyncEngine {
|
|
|
201
210
|
*/
|
|
202
211
|
async stop() {
|
|
203
212
|
this.syncLock = this.syncLock.then(() => {
|
|
204
|
-
this.state =
|
|
213
|
+
this.state = this.state.initialized
|
|
214
|
+
? {
|
|
215
|
+
initialized: true,
|
|
216
|
+
running: false,
|
|
217
|
+
name: this.state.name,
|
|
218
|
+
storachaClient: this.state.storachaClient,
|
|
219
|
+
}
|
|
220
|
+
: { initialized: false, running: false };
|
|
205
221
|
});
|
|
206
222
|
return this.syncLock;
|
|
207
223
|
}
|
|
@@ -210,6 +226,11 @@ export class SyncEngine {
|
|
|
210
226
|
* Used by join to overwrite local with remote before watcher starts.
|
|
211
227
|
*/
|
|
212
228
|
async pullRemote() {
|
|
229
|
+
const op = this.syncLock.then(() => this._pullRemoteInner());
|
|
230
|
+
this.syncLock = op.then(() => void 0).catch(() => { }); // heal chain so subsequent syncs run
|
|
231
|
+
return op;
|
|
232
|
+
}
|
|
233
|
+
async _pullRemoteInner() {
|
|
213
234
|
const { name } = this.requireRunning();
|
|
214
235
|
try {
|
|
215
236
|
const result = await Revision.resolve(this.blocks, name, {
|
|
@@ -263,7 +284,7 @@ export class SyncEngine {
|
|
|
263
284
|
};
|
|
264
285
|
}
|
|
265
286
|
async exportNameArchive() {
|
|
266
|
-
const { name } = this.
|
|
287
|
+
const { name } = this.requireInitialized();
|
|
267
288
|
const bytes = await name.archive();
|
|
268
289
|
return encodeDelegation(bytes);
|
|
269
290
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storacha/clawracha",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "OpenClaw plugin for Storacha workspace sync via UCN Pail",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@ipld/car": "^5.2.0",
|
|
30
30
|
"@ipld/dag-cbor": "^9.2.5",
|
|
31
31
|
"@storacha/client": "^2.0.4",
|
|
32
|
-
"@storacha/md-merge": "0.
|
|
32
|
+
"@storacha/md-merge": "0.7.0",
|
|
33
33
|
"@storacha/ucn": "1.1.1-rc.3",
|
|
34
34
|
"@storacha/upload-client": "^1.3.9",
|
|
35
35
|
"@ucanto/interface": "^11.0.1",
|