worldstate-emitter 2.1.3 → 2.2.1

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/.babelrc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "plugins": ["@babel/plugin-transform-class-properties", "@babel/plugin-transform-private-methods"],
3
+ "presets": ["@babel/preset-env"]
4
+ }
@@ -0,0 +1,5 @@
1
+ extends:
2
+ - '@commitlint/config-conventional'
3
+ rules:
4
+ body-max-line-length:
5
+ - 0
package/.eslintignore ADDED
@@ -0,0 +1,4 @@
1
+ .github/**
2
+ docs/**
3
+ resources/**
4
+ types/**
package/.eslintrc.yml ADDED
@@ -0,0 +1,9 @@
1
+ parser: '@babel/eslint-parser'
2
+ parserOptions:
3
+ ecmaFeatures:
4
+ modules: true
5
+ ecmaVersion: 6
6
+ sourceType: module
7
+ extends: '@wfcd/eslint-config/esm'
8
+ rules:
9
+ no-underscore-dangle: 'off'
@@ -0,0 +1,9 @@
1
+ '*.js':
2
+ - eslint --cache --fix
3
+ - npm test
4
+ package*.json:
5
+ - prettier --write
6
+ - npm dedupe
7
+ - npx sort-package-json
8
+ '*.{json,yml,yaml}':
9
+ - prettier --write
package/.mocharc.yml ADDED
@@ -0,0 +1,3 @@
1
+ exit: true
2
+ spec: test/specs/**/*.spec.js
3
+ timeout: 20000
package/.nycrc.yml ADDED
@@ -0,0 +1,4 @@
1
+ reporter:
2
+ - lcov
3
+ - text
4
+ skip-full: true
package/.prettierrc ADDED
@@ -0,0 +1 @@
1
+ "@wfcd/eslint-config/prettier"
package/handlers/RSS.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import RssFeedEmitter from 'rss-feed-emitter';
2
2
 
3
- import feeds from '../resources/rssFeeds.json' assert { type: 'json' };
3
+ import feeds from '../resources/rssFeeds.json' with { type: 'json' };
4
4
  import { logger } from '../utilities/index.js';
5
5
 
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import Twitter from 'twitter';
2
2
 
3
- import toWatch from '../resources/tweeters.json' assert { type: 'json' };
3
+ import toWatch from '../resources/tweeters.json' with { type: 'json' };
4
4
  import { logger } from '../utilities/index.js';
5
5
  import { twiClientInfo, TWITTER_TIMEOUT } from '../utilities/env.js';
6
6
 
package/index.js CHANGED
@@ -70,6 +70,14 @@ export default class WorldstateEmitter extends EventEmitter {
70
70
  return this.#worldstate?.get(language);
71
71
  }
72
72
 
73
+ get debug() {
74
+ return {
75
+ rss: this.getRss(),
76
+ worldstate: this.#worldstate?.get(),
77
+ twitter: this.#twitter?.clientInfoValid ? this.#twitter.getData() : undefined,
78
+ };
79
+ }
80
+
73
81
  /**
74
82
  * Get Twitter data
75
83
  * @returns {Promise} promised twitter data
package/nodemon.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "delay": 5000,
3
+ "env": {
4
+ "LOG_LEVEL": "debug",
5
+ "CACHE_TIMEOUT": 60000,
6
+ "SEMLAR_TIMEOUT": 300000
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worldstate-emitter",
3
- "version": "2.1.3",
3
+ "version": "2.2.1",
4
4
  "description": "Event emitter for worldstate & other warframe events",
5
5
  "keywords": [
6
6
  "warframe",
@@ -19,6 +19,9 @@
19
19
  "license": "Apache-2.0",
20
20
  "author": "tobiah <tobiah@protonmail.com>",
21
21
  "type": "module",
22
+ "exports": {
23
+ ".": "./index.js"
24
+ },
22
25
  "main": "index.js",
23
26
  "directories": {
24
27
  "test": "test/specs"
@@ -29,92 +32,18 @@
29
32
  "dev": "nodemon test/tester.js",
30
33
  "lint": "eslint .",
31
34
  "lint:fix": "eslint . --fix",
32
- "prepare": "husky && install-peerdeps @wfcd/eslint-config@latest -S",
35
+ "prepare": "husky && npx install-peerdeps @wfcd/eslint-config@latest -S",
33
36
  "report": "c8 report --reporter=text-lcov",
34
37
  "test": "c8 mocha",
35
38
  "validate": "npm ls"
36
39
  },
37
40
  "pre-commit": [
38
41
  "lint",
39
- "test",
40
- "validate"
42
+ "validate",
43
+ "test"
41
44
  ],
42
- "commitlint": {
43
- "extends": [
44
- "@commitlint/config-conventional"
45
- ],
46
- "rules": {
47
- "body-max-line-length": [
48
- 0
49
- ]
50
- }
51
- },
52
- "lint-staged": {
53
- "*.js": [
54
- "eslint --cache --fix",
55
- "npm test"
56
- ],
57
- "package*.json": [
58
- "prettier --write",
59
- "npm dedupe",
60
- "npx sort-package-json"
61
- ],
62
- "*.{json,yml,yaml}": [
63
- "prettier --write"
64
- ]
65
- },
66
- "nodemonConfig": {
67
- "delay": 5000,
68
- "env": {
69
- "LOG_LEVEL": "debug",
70
- "CACHE_TIMEOUT": 60000,
71
- "SEMLAR_TIMEOUT": 300000
72
- }
73
- },
74
- "babel": {
75
- "plugins": [
76
- "@babel/plugin-transform-class-properties",
77
- "@babel/plugin-transform-private-methods"
78
- ],
79
- "presets": [
80
- "@babel/preset-env"
81
- ]
82
- },
83
- "prettier": "@wfcd/eslint-config/prettier",
84
- "eslintConfig": {
85
- "parser": "@babel/eslint-parser",
86
- "parserOptions": {
87
- "ecmaFeatures": {
88
- "modules": true
89
- },
90
- "ecmaVersion": 6,
91
- "sourceType": "module"
92
- },
93
- "extends": "@wfcd/eslint-config/esm",
94
- "rules": {
95
- "no-underscore-dangle": "off"
96
- }
97
- },
98
- "eslintIgnore": [
99
- ".github/**",
100
- "docs/**",
101
- "resources/**",
102
- "types/**"
103
- ],
104
- "mocha": {
105
- "exit": true,
106
- "spec": "test/specs/**/*.spec.js",
107
- "timeout": 20000
108
- },
109
- "c8": {
110
- "reporter": [
111
- "lcov",
112
- "text"
113
- ],
114
- "skip-full": true
115
- },
116
45
  "dependencies": {
117
- "cron": "^3.1.6",
46
+ "cron": "^4.0.0",
118
47
  "rss-feed-emitter": "^3.2.2",
119
48
  "twitter": "^1.7.1"
120
49
  },
@@ -122,19 +51,19 @@
122
51
  "@commitlint/cli": "^19.2.1",
123
52
  "@commitlint/config-conventional": "^19.1.0",
124
53
  "@wfcd/eslint-config": "latest",
125
- "c8": "^9.1.0",
126
- "chai": "^4.3.4",
54
+ "c8": "^10.1.2",
55
+ "chai": "^5.1.2",
127
56
  "coveralls": "^3.1.0",
128
57
  "husky": "^9.0.11",
129
58
  "install-peerdeps": "^3.0.3",
130
59
  "lint-staged": "^15.2.2",
131
- "mocha": "^10.0.0",
60
+ "mocha": "^11.0.1",
132
61
  "nodemon": "^3.0.3",
133
62
  "prettier": "^3.2.5"
134
63
  },
135
64
  "peerDependencies": {
136
65
  "warframe-worldstate-data": "^2.x",
137
- "warframe-worldstate-parser": "^3.x"
66
+ "warframe-worldstate-parser": "^4.x"
138
67
  },
139
68
  "optionalDependencies": {
140
69
  "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,39 @@ 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 deps = {
39
+ locale: this.#language,
40
+ kuvaData: {},
41
+ sentientData: {},
42
+ };
43
+ try {
44
+ deps.kuvaData = JSON.parse(await this.#kuvaCache.get());
45
+ } catch (err) {
46
+ logger.warn(`Error parsing kuva data for ${this.#language}: ${err}`);
47
+ }
48
+ try {
49
+ deps.sentientData = JSON.parse(await this.#sentientCache.get());
50
+ } catch (err) {
51
+ logger.warn(`Error parsing sentient data for ${this.#language}: ${err}`);
52
+ }
53
+
54
+ const t = await WorldState.build(newData, deps);
55
+ if (!t.timestamp) return;
56
+
57
+ this.#inner = t;
58
+ this.#emitter.emit('ws:update:parsed', {
59
+ language: this.#language,
60
+ platform: this.#platform,
61
+ data: t,
62
+ });
63
+ };
64
+
32
65
  /**
33
66
  * Get the latest worldstate data from this cache
34
67
  * @returns {Object} Current worldstate data
@@ -43,21 +76,7 @@ export default class WSCache {
43
76
  */
44
77
  set data(newData) {
45
78
  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);
79
+ this.#update(newData);
61
80
  }
62
81
 
63
82
  /**