@storacha/clawracha 0.2.1 → 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/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
  */
@@ -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;AAWxE,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,QAAQ,CAAoC;gBAExC,SAAS,EAAE,MAAM;IAK7B;;;OAGG;IACG,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC/C;;OAEG;IACH,OAAO,CAAC,cAAc;IAOtB;;;OAGG;IACG,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1D;;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vC,OAAO,CAAC,QAAQ,CAAoC;gBAExC,SAAS,EAAE,MAAM;IAK7B;;;OAGG;IACG,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC/C;;OAEG;IACH,OAAO,CAAC,cAAc;IAOtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;;OAGG;IACG,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1D;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAMb,UAAU;IAwDxB;;OAEG;YACW,iBAAiB;IAe/B;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAc5C;;OAEG;YACW,kBAAkB;IAUhC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;YAMrB,gBAAgB;IA0B9B;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC;QACvB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,SAAS,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC/B,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,UAAU,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,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 = { running: false };
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.requireRunning();
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.1",
3
+ "version": "0.2.2",
4
4
  "description": "OpenClaw plugin for Storacha workspace sync via UCN Pail",
5
5
  "type": "module",
6
6
  "files": [