@lunarislab/state-sync 1.1.15 → 1.1.17

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/classes/Syncer.js CHANGED
@@ -23,25 +23,22 @@ class Syncer extends SimpleEmitter_1.SimpleEmitter {
23
23
  }
24
24
  ;
25
25
  async _commit() {
26
- const date = Date.now();
27
- // If the last push was less than waitTime ago, don't commit
28
- if (this.lastPush > date - this.commitInterval)
29
- return;
30
- this.lastPush = date;
31
- // Wait for commit interval to avoid letting some logs in the queue
32
- await new Promise(x => setTimeout(x, this.commitInterval));
33
- // Clear queue and save logs
34
26
  const logs = this.logs.splice(0, this.logs.length);
35
27
  const commits = await this.saver.saveLogs(logs);
36
28
  this.emit("commit", { commits });
29
+ // start the recursive commit process
30
+ await new Promise(x => setTimeout(x, this.commitInterval));
31
+ this._commit();
37
32
  }
33
+ ;
38
34
  async start() {
39
35
  await this.saver.init();
40
36
  this.watcher.on('log', async (log) => {
37
+ this.emit('log', { log: log });
41
38
  this.logs.push(log);
42
- await this._commit();
43
39
  });
44
40
  await this.watcher.start();
41
+ this._commit();
45
42
  }
46
43
  ;
47
44
  async addContracts(contracts) {
@@ -31,7 +31,7 @@ class Watcher {
31
31
  address: contracts,
32
32
  event: (0, viem_1.parseAbiItem)(this.event),
33
33
  });
34
- logs.forEach(l => this.emitter.emit("logs", l));
34
+ logs.forEach(l => this.emitter.emit("log", l));
35
35
  block = block + gap > this.currentBlockNum ? this.currentBlockNum : block + gap;
36
36
  }
37
37
  catch (e) {
@@ -56,7 +56,7 @@ class Watcher {
56
56
  address: this.contracts,
57
57
  event: (0, viem_1.parseAbiItem)(this.event),
58
58
  });
59
- logs.forEach(l => this.emitter.emit("logs", l));
59
+ logs.forEach(l => this.emitter.emit("log", l));
60
60
  });
61
61
  });
62
62
  }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "viem": "^2.21.58"
9
9
  },
10
10
  "name": "@lunarislab/state-sync",
11
- "version": "1.1.15",
11
+ "version": "1.1.17",
12
12
  "main": "index.js",
13
13
  "scripts": {
14
14
  "test": "ts-node ./test.ts",