worldstate-emitter 2.1.3 → 2.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worldstate-emitter",
3
- "version": "2.1.3",
3
+ "version": "2.2.0",
4
4
  "description": "Event emitter for worldstate & other warframe events",
5
5
  "keywords": [
6
6
  "warframe",
@@ -122,7 +122,7 @@
122
122
  "@commitlint/cli": "^19.2.1",
123
123
  "@commitlint/config-conventional": "^19.1.0",
124
124
  "@wfcd/eslint-config": "latest",
125
- "c8": "^9.1.0",
125
+ "c8": "^10.1.2",
126
126
  "chai": "^4.3.4",
127
127
  "coveralls": "^3.1.0",
128
128
  "husky": "^9.0.11",
@@ -134,7 +134,7 @@
134
134
  },
135
135
  "peerDependencies": {
136
136
  "warframe-worldstate-data": "^2.x",
137
- "warframe-worldstate-parser": "^3.x"
137
+ "warframe-worldstate-parser": "^4.x"
138
138
  },
139
139
  "optionalDependencies": {
140
140
  "colors": "^1.4.0",
@@ -1,4 +1,4 @@
1
- import Worldstate from 'warframe-worldstate-parser';
1
+ import WorldState from 'warframe-worldstate-parser';
2
2
 
3
3
  import { logger } from './index.js';
4
4
 
@@ -16,7 +16,7 @@ export default class WSCache {
16
16
 
17
17
  /**
18
18
  * Set up a cache checking for data and updates to a specific worldstate set
19
- * @param {string} language Langauge/translation to track
19
+ * @param {string} language Language/translation to track
20
20
  * @param {Cache} kuvaCache Cache of kuva data, provided by Semlar
21
21
  * @param {Cache} sentientCache Cache of sentient outpost data, provided by Semlar
22
22
  * @param {EventEmitter} eventEmitter Emitter to push new worldstate updates to
@@ -29,6 +29,27 @@ export default class WSCache {
29
29
  this.#emitter = eventEmitter;
30
30
  }
31
31
 
32
+ /**
33
+ * Update the current data with new data
34
+ * @param {string} newData updated worldstate data
35
+ * @returns {Promise<void>}
36
+ */
37
+ #update = async (newData) => {
38
+ const t = await WorldState.build(newData, {
39
+ locale: this.#language,
40
+ kuvaData: JSON.parse(await this.#kuvaCache.get()),
41
+ sentientData: JSON.parse(await this.#sentientCache.get()),
42
+ });
43
+ if (!t.timestamp) return;
44
+
45
+ this.#inner = t;
46
+ this.#emitter.emit('ws:update:parsed', {
47
+ language: this.#language,
48
+ platform: this.#platform,
49
+ data: t,
50
+ });
51
+ };
52
+
32
53
  /**
33
54
  * Get the latest worldstate data from this cache
34
55
  * @returns {Object} Current worldstate data
@@ -43,21 +64,7 @@ export default class WSCache {
43
64
  */
44
65
  set data(newData) {
45
66
  logger.debug(`got new data for ${this.#language}, parsing...`);
46
- setTimeout(async () => {
47
- const t = new Worldstate(newData, {
48
- locale: this.#language,
49
- kuvaData: JSON.parse(await this.#kuvaCache.get()),
50
- sentientData: JSON.parse(await this.#sentientCache.get()),
51
- });
52
- if (!t.timestamp) return;
53
-
54
- this.#inner = t;
55
- this.#emitter.emit('ws:update:parsed', {
56
- language: this.#language,
57
- platform: this.#platform,
58
- data: t,
59
- });
60
- }, 0);
67
+ this.#update(newData);
61
68
  }
62
69
 
63
70
  /**