@storacha/clawracha 0.1.13 → 0.1.15

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
@@ -18,6 +18,7 @@ export declare class SyncEngine {
18
18
  private pendingOps;
19
19
  private carFile;
20
20
  private lastSync;
21
+ private syncLock;
21
22
  constructor(workspace: string);
22
23
  /**
23
24
  * Initialize sync engine with device config.
@@ -37,6 +38,7 @@ export declare class SyncEngine {
37
38
  * Execute sync: generate revision, publish, upload, apply remote changes.
38
39
  */
39
40
  sync(): Promise<void>;
41
+ private _syncInner;
40
42
  /**
41
43
  * Create CAR and upload to Storacha.
42
44
  */
@@ -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;gBAE3B,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;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAoD3B;;OAEG;YACW,iBAAiB;IA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G,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;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAMb,UAAU;IAyDxB;;OAEG;YACW,iBAAiB;IAe/B;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAc5C;;OAEG;YACW,kBAAkB;IAUhC;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IA0BnC;;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
@@ -26,6 +26,7 @@ export class SyncEngine {
26
26
  pendingOps = [];
27
27
  carFile = null;
28
28
  lastSync = null;
29
+ syncLock = Promise.resolve();
29
30
  constructor(workspace) {
30
31
  this.workspace = workspace;
31
32
  this.blocks = createWorkspaceBlockstore(workspace);
@@ -95,10 +96,14 @@ export class SyncEngine {
95
96
  * Execute sync: generate revision, publish, upload, apply remote changes.
96
97
  */
97
98
  async sync() {
99
+ const op = this.syncLock.then(() => this._syncInner());
100
+ this.syncLock = op.catch(() => { }); // heal chain so subsequent syncs run
101
+ return op;
102
+ }
103
+ async _syncInner() {
98
104
  const { name } = this.requireRunning();
99
105
  const beforeEntries = await this.getPailEntries();
100
- let pendingOps = this.pendingOps;
101
- if (pendingOps.length === 0) {
106
+ if (this.pendingOps.length === 0) {
102
107
  // No pending ops — just pull remote
103
108
  try {
104
109
  const result = await Revision.resolve(this.blocks, name, {
@@ -113,28 +118,35 @@ export class SyncEngine {
113
118
  }
114
119
  }
115
120
  else {
116
- while (pendingOps.length > 0) {
117
- if (!this.carFile) {
118
- throw new Error("CAR file not initialized");
119
- }
120
- const { current, revisionBlocks, event, remainingOps } = await applyPendingOps(this.blocks, name, this.current, pendingOps);
121
- this.current = current;
122
- for (const block of revisionBlocks) {
123
- await this.carFile.put(block);
124
- }
125
- await this.storeBlocks(revisionBlocks);
126
- if (event) {
127
- await this.carFile.put(event);
128
- await this.storeBlocks([event]);
129
- }
130
- pendingOps = remainingOps;
131
- await this.possiblyUploadCAR();
132
- if (pendingOps.length > 0) {
133
- this.carFile = await makeTempCar();
121
+ let pendingOps = [...this.pendingOps];
122
+ this.pendingOps = [];
123
+ try {
124
+ while (pendingOps.length > 0) {
125
+ if (!this.carFile) {
126
+ throw new Error("CAR file not initialized");
127
+ }
128
+ const { current, revisionBlocks, event, remainingOps } = await applyPendingOps(this.blocks, name, this.current, pendingOps);
129
+ this.current = current;
130
+ for (const block of revisionBlocks) {
131
+ await this.carFile.put(block);
132
+ }
133
+ await this.storeBlocks(revisionBlocks);
134
+ if (event) {
135
+ await this.carFile.put(event);
136
+ await this.storeBlocks([event]);
137
+ }
138
+ pendingOps = remainingOps;
139
+ await this.possiblyUploadCAR();
140
+ if (pendingOps.length > 0) {
141
+ this.carFile = await makeTempCar();
142
+ }
134
143
  }
135
144
  }
145
+ catch (err) {
146
+ this.pendingOps.unshift(...pendingOps);
147
+ throw err;
148
+ }
136
149
  }
137
- this.pendingOps = [];
138
150
  // Apply remote changes
139
151
  const afterEntries = await this.getPailEntries();
140
152
  const remoteChanges = diffRemoteChanges(beforeEntries, afterEntries);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storacha/clawracha",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "OpenClaw plugin for Storacha workspace sync via UCN Pail",
5
5
  "type": "module",
6
6
  "files": [