@axiapps/gw2-data 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +156 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # @axiapps/gw2-data
2
+
3
+ Data library for Guild Wars 2 — wiki scraping, GW2 API access, and stat computation engine. Used by [AxiForge](https://axiforge.com).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @axiapps/gw2-data
9
+ ```
10
+
11
+ ## Modules
12
+
13
+ The package exposes four subpath imports:
14
+
15
+ | Import | Description |
16
+ |--------|-------------|
17
+ | `@axiapps/gw2-data/wiki` | Wiki scraping and wikitext parsing |
18
+ | `@axiapps/gw2-data/api` | GW2 API client with batching and retries |
19
+ | `@axiapps/gw2-data/facts` | Fact merging for PvE/WvW balance splits |
20
+ | `@axiapps/gw2-data/engine` | Stat computation, tooltips, boon analysis |
21
+
22
+ ## Wiki Client
23
+
24
+ Fetch and parse skill/trait data from the GW2 Wiki with built-in caching and rate limiting.
25
+
26
+ ```js
27
+ const { WikiClient } = require("@axiapps/gw2-data/wiki");
28
+
29
+ const wiki = new WikiClient();
30
+
31
+ // Fetch wikitext for a single page
32
+ const wikitext = await wiki.getWikitext("Fireball");
33
+
34
+ // Batch-fetch multiple pages (up to 50 per request)
35
+ const pages = await wiki.getWikitextBatch(["Fireball", "Meteor Shower", "Lava Font"]);
36
+
37
+ // Parse skill/trait facts from wikitext
38
+ const { facts, hasPveOnly, splitGrouping } = wiki.parseFacts(wikitext);
39
+
40
+ // Search for pages by prefix
41
+ const matches = await wiki.prefixSearch("Fire", 10);
42
+
43
+ // Invalidate cache for recently changed pages
44
+ const changed = await wiki.refresh();
45
+ ```
46
+
47
+ ### Constructor Options
48
+
49
+ | Option | Default | Description |
50
+ |--------|---------|-------------|
51
+ | `cache` | `MemoryCache` | Cache adapter (MemoryCache or DiskCache) |
52
+ | `fetch` | `globalThis.fetch` | Fetch implementation |
53
+ | `wikiApiRoot` | `https://wiki.guildwars2.com/api.php` | Wiki API endpoint |
54
+ | `cacheTTL` | 4 hours | Cache TTL in milliseconds |
55
+
56
+ ## GW2 API Client
57
+
58
+ Fetch data from the official GW2 API with automatic chunking, retries, and 429 handling.
59
+
60
+ ```js
61
+ const { Gw2ApiClient } = require("@axiapps/gw2-data/api");
62
+
63
+ const api = new Gw2ApiClient();
64
+
65
+ // Fetch skills by ID (automatically chunked into 180-ID batches)
66
+ const skills = await api.fetchByIds("/v2/skills", [5489, 5536, 5501]);
67
+
68
+ // Fetch with caching
69
+ const data = await api.fetchCached("my-key", "https://api.guildwars2.com/v2/skills/5489", 3600000);
70
+ ```
71
+
72
+ ### Constructor Options
73
+
74
+ | Option | Default | Description |
75
+ |--------|---------|-------------|
76
+ | `cache` | `MemoryCache` | Cache adapter |
77
+ | `fetch` | `globalThis.fetch` | Fetch implementation |
78
+ | `apiRoot` | `https://api.guildwars2.com` | API root URL |
79
+ | `lang` | `"en"` | Language code |
80
+
81
+ ## Fact Merging
82
+
83
+ Merge base (PvE) facts with WvW/PvP split facts, marking which values changed.
84
+
85
+ ```js
86
+ const { mergeFacts } = require("@axiapps/gw2-data/facts");
87
+
88
+ const merged = mergeFacts(baseFacts, splitFacts);
89
+ // Changed facts have _splitFact: true
90
+ // New facts (WvW-only) have _newFact: true
91
+ ```
92
+
93
+ ## Engine
94
+
95
+ Compute final build stats, skill tooltips, boon uptime, and combo interactions.
96
+
97
+ ```js
98
+ const {
99
+ computeAttributes,
100
+ collectModifiers,
101
+ computeTooltip,
102
+ analyzeBoons,
103
+ analyzeCombos,
104
+ STAT_COMBOS_BY_LABEL,
105
+ } = require("@axiapps/gw2-data/engine");
106
+
107
+ // Compute final attributes for a build
108
+ const attrs = computeAttributes({
109
+ profession: "Elementalist",
110
+ specializations: [...],
111
+ equipment: { statPackage: "Berserker" },
112
+ }, catalogs);
113
+
114
+ // Collect all stat modifiers from traits, sigils, etc.
115
+ const modifiers = collectModifiers(ctx, catalogs, overrides);
116
+
117
+ // Compute a skill tooltip with modifiers applied
118
+ const tooltip = computeTooltip(attrs, skill, "Staff", modifiers);
119
+
120
+ // Analyze boon output across a skill set
121
+ const boons = analyzeBoons(skills, traits, overrides);
122
+
123
+ // Detect combo field/finisher interactions
124
+ const combos = analyzeCombos(skills, traits);
125
+ ```
126
+
127
+ ### StatEngine Class
128
+
129
+ For repeated computations, use the class to avoid re-loading overrides:
130
+
131
+ ```js
132
+ const { StatEngine } = require("@axiapps/gw2-data/engine");
133
+
134
+ const engine = new StatEngine(catalogs);
135
+ const attrs = engine.computeAttributes(ctx);
136
+ const tooltip = engine.computeTooltip(ctx, skill, "Sword");
137
+ const boons = engine.analyzeBoons(skills, traits);
138
+ ```
139
+
140
+ ## Caching
141
+
142
+ Both clients accept a cache adapter. Two are included:
143
+
144
+ ```js
145
+ const { MemoryCache, DiskCache } = require("@axiapps/gw2-data/wiki");
146
+
147
+ // In-memory (default)
148
+ const wiki = new WikiClient({ cache: new MemoryCache() });
149
+
150
+ // Disk-backed (persists across restarts)
151
+ const wiki = new WikiClient({ cache: new DiskCache("/tmp/gw2-wiki-cache") });
152
+ ```
153
+
154
+ ## License
155
+
156
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiapps/gw2-data",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "GW2 data library — wiki-sourced facts, GW2 API structural data, and stat computation",
5
5
  "main": "src/index.js",
6
6
  "exports": {