pokenode-ts 2.3.0 → 3.0.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/LICENSE +1 -1
- package/README.md +35 -36
- package/lib/index.cjs +4187 -11
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +721 -425
- package/lib/index.d.ts +721 -425
- package/lib/index.js +4095 -11
- package/lib/index.js.map +1 -1
- package/lib/rolldown-runtime-BOlb2svz.js +19 -0
- package/package.json +13 -13
- package/lib/rolldown-runtime-mLzODkzB.js +0 -16
package/lib/index.cjs
CHANGED
|
@@ -1,17 +1,4193 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* _
|
|
3
|
-
* |_) _ | _ _ _ _| _ __ _|_ _
|
|
4
|
-
* | (_) |< (/_ | | (_) (_| (/_ |_ _>
|
|
2
|
+
* _
|
|
3
|
+
* |_) _ | _ _ _ _| _ __ _|_ _
|
|
4
|
+
* | (_) |< (/_ | | (_) (_| (/_ |_ _>
|
|
5
|
+
*
|
|
6
|
+
* pokenode-ts v3.0.0 — A typed PokéAPI client with zero runtime dependencies.
|
|
7
|
+
*
|
|
8
|
+
* Docs: https://pokenode-ts.vercel.app/
|
|
9
|
+
* Author: Gabb-c <https://github.com/Gabb-c>
|
|
10
|
+
* License: MIT
|
|
11
|
+
*
|
|
12
|
+
* @license MIT
|
|
13
|
+
* @preserve
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
16
|
+
//#region \0rolldown/runtime.js
|
|
17
|
+
var __defProp = Object.defineProperty;
|
|
18
|
+
var __exportAll = (all, no_symbols) => {
|
|
19
|
+
let target = {};
|
|
20
|
+
for (var name in all) {
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (!no_symbols) {
|
|
27
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
28
|
+
}
|
|
29
|
+
return target;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/constants/berries.ts
|
|
34
|
+
/** Enum of Berries (NAME - ID) */
|
|
35
|
+
const BERRIES = {
|
|
36
|
+
CHERI: 1,
|
|
37
|
+
CHESTO: 2,
|
|
38
|
+
PECHA: 3,
|
|
39
|
+
RAWST: 4,
|
|
40
|
+
ASPEAR: 5,
|
|
41
|
+
LEPPA: 6,
|
|
42
|
+
ORAN: 7,
|
|
43
|
+
PERSIM: 8,
|
|
44
|
+
LUM: 9,
|
|
45
|
+
SITRUS: 10,
|
|
46
|
+
FIGY: 11,
|
|
47
|
+
WIKI: 12,
|
|
48
|
+
MAGO: 13,
|
|
49
|
+
AGUAV: 14,
|
|
50
|
+
IAPAPA: 15,
|
|
51
|
+
RAZZ: 16,
|
|
52
|
+
BLUK: 17,
|
|
53
|
+
NANAB: 18,
|
|
54
|
+
WEPEAR: 19,
|
|
55
|
+
PINAP: 20,
|
|
56
|
+
POMEG: 21,
|
|
57
|
+
KELPSY: 22,
|
|
58
|
+
QUALOT: 23,
|
|
59
|
+
HONDEW: 24,
|
|
60
|
+
GREPA: 25,
|
|
61
|
+
TAMATO: 26,
|
|
62
|
+
CORNN: 27,
|
|
63
|
+
MAGOST: 28,
|
|
64
|
+
RABUTA: 29,
|
|
65
|
+
NOMEL: 30,
|
|
66
|
+
SPELON: 31,
|
|
67
|
+
PAMTRE: 32,
|
|
68
|
+
WATMEL: 33,
|
|
69
|
+
DURIN: 34,
|
|
70
|
+
BELUE: 35,
|
|
71
|
+
OCCA: 36,
|
|
72
|
+
PASSHO: 37,
|
|
73
|
+
WACAN: 38,
|
|
74
|
+
RINDO: 39,
|
|
75
|
+
YACHE: 40,
|
|
76
|
+
CHOPLE: 41,
|
|
77
|
+
KEBIA: 42,
|
|
78
|
+
SHUCA: 43,
|
|
79
|
+
COBA: 44,
|
|
80
|
+
PAYAPA: 45,
|
|
81
|
+
TANGA: 46,
|
|
82
|
+
CHARTI: 47,
|
|
83
|
+
KASIB: 48,
|
|
84
|
+
HABAN: 49,
|
|
85
|
+
COLBUR: 50,
|
|
86
|
+
BABIRI: 51,
|
|
87
|
+
CHILAN: 52,
|
|
88
|
+
LIECHI: 53,
|
|
89
|
+
GANLON: 54,
|
|
90
|
+
SALAC: 55,
|
|
91
|
+
PETAYA: 56,
|
|
92
|
+
APICOT: 57,
|
|
93
|
+
LANSAT: 58,
|
|
94
|
+
STARF: 59,
|
|
95
|
+
ENIGMA: 60,
|
|
96
|
+
MICLE: 61,
|
|
97
|
+
CUSTAP: 62,
|
|
98
|
+
JABOCA: 63,
|
|
99
|
+
ROWAP: 64,
|
|
100
|
+
KEE: 65,
|
|
101
|
+
MARANGA: 66,
|
|
102
|
+
HOPO: 67,
|
|
103
|
+
ROSELI: 68
|
|
104
|
+
};
|
|
105
|
+
/** Enum of Berry Firmnesses (NAME - ID) */
|
|
106
|
+
const BERRY_FIRMNESSES = {
|
|
107
|
+
VERY_SOFT: 1,
|
|
108
|
+
SOFT: 2,
|
|
109
|
+
HARD: 3,
|
|
110
|
+
VERY_HARD: 4,
|
|
111
|
+
SUPER_HARD: 5
|
|
112
|
+
};
|
|
113
|
+
const BERRY_FLAVORS = {
|
|
114
|
+
SPICY: 1,
|
|
115
|
+
DRY: 2,
|
|
116
|
+
SWEET: 3,
|
|
117
|
+
BITTER: 4,
|
|
118
|
+
SOUR: 5
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/constants/contests.ts
|
|
123
|
+
const CONTEST_TYPES = {
|
|
124
|
+
COOL: 1,
|
|
125
|
+
BEAUTY: 2,
|
|
126
|
+
CUTE: 3,
|
|
127
|
+
SMART: 4,
|
|
128
|
+
TOUGH: 5
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/constants/currencies.ts
|
|
133
|
+
const CURRENCIES = {
|
|
134
|
+
POKE_DOLLAR: 1,
|
|
135
|
+
COIN: 2,
|
|
136
|
+
VOLCANIC_ASH: 3,
|
|
137
|
+
POKE_COUPON: 4,
|
|
138
|
+
BERRY_POWDER: 5,
|
|
139
|
+
BATTLE_POINT: 6,
|
|
140
|
+
SPHERE: 7,
|
|
141
|
+
CASTLE_POINT: 8,
|
|
142
|
+
WATT: 9,
|
|
143
|
+
ATHLETE_POINT: 10,
|
|
144
|
+
DREAM_POINT: 11,
|
|
145
|
+
DREAM_WORLD_BERRY: 12,
|
|
146
|
+
POKE_MILE: 13,
|
|
147
|
+
FESTIVAL_COIN: 14,
|
|
148
|
+
POKE_BEAN: 15,
|
|
149
|
+
HOME_POINT: 16,
|
|
150
|
+
MERIT_POINT: 17,
|
|
151
|
+
LEAGUE_POINT: 18,
|
|
152
|
+
BLUEBERRY_POINT: 19
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/constants/encounters.ts
|
|
157
|
+
const ENCOUNTER_METHODS = {
|
|
158
|
+
WALK: 1,
|
|
159
|
+
OLD_ROD: 2,
|
|
160
|
+
GOOD_ROD: 3,
|
|
161
|
+
SUPER_ROD: 4,
|
|
162
|
+
SURF: 5,
|
|
163
|
+
ROCK_SMASH: 6,
|
|
164
|
+
HEADBUTT: 7,
|
|
165
|
+
DARK_GRASS: 8,
|
|
166
|
+
GRASS_SPOTS: 9,
|
|
167
|
+
CAVE_SPOTS: 10,
|
|
168
|
+
BRIDGE_SPOTS: 11,
|
|
169
|
+
SUPER_ROD_SPOTS: 12,
|
|
170
|
+
SURF_SPOTS: 13,
|
|
171
|
+
YELLOW_FLOWERS: 14,
|
|
172
|
+
PURPLE_FLOWERS: 15,
|
|
173
|
+
RED_FLOWERS: 16,
|
|
174
|
+
ROUGH_TERRAIN: 17,
|
|
175
|
+
GIFT: 18,
|
|
176
|
+
GIFT_EGG: 19,
|
|
177
|
+
STATIC: 20,
|
|
178
|
+
POKEFLUTE: 21,
|
|
179
|
+
HEADBUTT_LOW: 22,
|
|
180
|
+
HEADBUTT_NORMAL: 23,
|
|
181
|
+
HEADBUTT_HIGH: 24,
|
|
182
|
+
SQUIRT_BOTTLE: 25,
|
|
183
|
+
WAILMER_PAIL: 26,
|
|
184
|
+
SEAWEED: 27,
|
|
185
|
+
ROAMING_GRASS: 28,
|
|
186
|
+
ROAMING_WATER: 29,
|
|
187
|
+
DEVON_SCOPE: 30,
|
|
188
|
+
FEEBAS_TILE_FISHING: 31,
|
|
189
|
+
ISLAND_SCAN: 32,
|
|
190
|
+
SOS: 33,
|
|
191
|
+
BUBBLING_SPOTS: 34,
|
|
192
|
+
BERRY_TREES: 35,
|
|
193
|
+
NPC_TRADE: 36,
|
|
194
|
+
SOS_FROM_BUBBLING_SPOT: 37,
|
|
195
|
+
OVERWORLD: 38,
|
|
196
|
+
OVERWORLD_WATER: 39,
|
|
197
|
+
OVERWORLD_FLYING: 40,
|
|
198
|
+
OVERWORLD_SPECIAL: 41,
|
|
199
|
+
OVERWORLD_FLYING_SPECIAL: 42,
|
|
200
|
+
OVERWORLD_WATER_SPECIAL: 43,
|
|
201
|
+
HORDE: 44,
|
|
202
|
+
COLOSSEUM_BONUS_DISC_US: 45,
|
|
203
|
+
COLOSSEUM_BONUS_DISC_JPN: 46,
|
|
204
|
+
POKEMON_CHANNEL_PAL: 47,
|
|
205
|
+
POKEMON_RANGER: 48,
|
|
206
|
+
POKEMON_BATTLE_REVOLUTION: 49,
|
|
207
|
+
NEW_YORK_POKECENTER_WISH_EGGS: 50,
|
|
208
|
+
SNAG: 51,
|
|
209
|
+
SNAG_REMATCH: 52,
|
|
210
|
+
POKESPOT: 53,
|
|
211
|
+
HIDDEN_GROTTO: 54,
|
|
212
|
+
HONEY_TREE: 55,
|
|
213
|
+
OVERWORLD_DIRT: 56,
|
|
214
|
+
WANDERER: 57,
|
|
215
|
+
WANDERER_WATER: 58,
|
|
216
|
+
CHASE_WATER: 59,
|
|
217
|
+
DYNAMAX_ADVENTURE: 60,
|
|
218
|
+
MAX_RAID: 61,
|
|
219
|
+
TRASH_CAN_AMBUSH: 62,
|
|
220
|
+
RUSTLING_BUSH_AMBUSH: 63,
|
|
221
|
+
CEILING_AMBUSH: 64,
|
|
222
|
+
GROUND_AMBUSH: 65,
|
|
223
|
+
SKY_AMBUSH: 66,
|
|
224
|
+
/**
|
|
225
|
+
* @deprecated Misspelled: the endpoint names this `headbutt-high`.
|
|
226
|
+
* Use {@link ENCOUNTER_METHODS.HEADBUTT_HIGH}. Removed in 3.0.
|
|
227
|
+
*/
|
|
228
|
+
HEADBUT_HIGH: 24,
|
|
229
|
+
/**
|
|
230
|
+
* @deprecated The endpoint names this `static` now.
|
|
231
|
+
* Use {@link ENCOUNTER_METHODS.STATIC}. Removed in 3.0.
|
|
232
|
+
*/
|
|
233
|
+
ONLY_ONE: 20
|
|
234
|
+
};
|
|
235
|
+
const ENCOUNTER_CONDITIONS = {
|
|
236
|
+
SWARM: 1,
|
|
237
|
+
TIME: 2,
|
|
238
|
+
RADAR: 3,
|
|
239
|
+
SLOT2: 4,
|
|
240
|
+
RADIO: 5,
|
|
241
|
+
SEASON: 6,
|
|
242
|
+
STARTER: 7,
|
|
243
|
+
TV_OPTION: 8,
|
|
244
|
+
STORY_PROGRESS: 9,
|
|
245
|
+
OTHER: 10,
|
|
246
|
+
ITEM: 11,
|
|
247
|
+
WEEKDAY: 12,
|
|
248
|
+
FIRST_PARTY_POKEMON: 13,
|
|
249
|
+
SPECIAL_ENCOUNTER: 14,
|
|
250
|
+
TRADE: 15,
|
|
251
|
+
COINS: 16,
|
|
252
|
+
FRIEND_SAFARI_SLOT: 17,
|
|
253
|
+
GREAT_MARSH_DAILY_SLOT: 18,
|
|
254
|
+
HONEY_TREE_GROUP: 19,
|
|
255
|
+
HEADBUTT_TREE: 20,
|
|
256
|
+
BACKLOT: 21,
|
|
257
|
+
BUG_CATCHING_CONTEST: 22,
|
|
258
|
+
SAVE_DATA: 23,
|
|
259
|
+
ALOLAN_DIGLETT_FOUND: 24,
|
|
260
|
+
WEATHER: 25,
|
|
261
|
+
JOHTO_SAFARI_BLOCKS: 26,
|
|
262
|
+
MAX_DEN_RARITY: 27,
|
|
263
|
+
MAX_DEN_RATING: 28,
|
|
264
|
+
BERRY_TREE_TYPE: 29,
|
|
265
|
+
TRASH_CAN_TYPE: 30
|
|
266
|
+
};
|
|
267
|
+
const ENCOUNTER_CONDITION_VALUES = {
|
|
268
|
+
SWARM_YES: 1,
|
|
269
|
+
SWARM_NO: 2,
|
|
270
|
+
TIME_MORNING: 3,
|
|
271
|
+
TIME_DAY: 4,
|
|
272
|
+
TIME_NIGHT: 5,
|
|
273
|
+
RADAR_ON: 6,
|
|
274
|
+
RADAR_OFF: 7,
|
|
275
|
+
SLOT2_NONE: 8,
|
|
276
|
+
SLOT2_RUBY: 9,
|
|
277
|
+
SLOT2_SAPPHIRE: 10,
|
|
278
|
+
SLOT2_EMERALD: 11,
|
|
279
|
+
SLOT2_FIRERED: 12,
|
|
280
|
+
SLOT2_LEAFGREEN: 13,
|
|
281
|
+
RADIO_OFF: 14,
|
|
282
|
+
RADIO_HOENN: 15,
|
|
283
|
+
RADIO_SINNOH: 16,
|
|
284
|
+
SEASON_SPRING: 17,
|
|
285
|
+
SEASON_SUMMER: 18,
|
|
286
|
+
SEASON_AUTUMN: 19,
|
|
287
|
+
SEASON_WINTER: 20,
|
|
288
|
+
STARTER_BULBASAUR: 21,
|
|
289
|
+
STARTER_SQUIRTLE: 22,
|
|
290
|
+
STARTER_CHARMANDER: 23,
|
|
291
|
+
STARTER_CHESPIN: 24,
|
|
292
|
+
STARTER_FENNEKIN: 25,
|
|
293
|
+
STARTER_FROAKIE: 26,
|
|
294
|
+
TV_OPTION_BLUE: 27,
|
|
295
|
+
TV_OPTION_RED: 28,
|
|
296
|
+
STORY_PROGRESS_AWAKENED_BEASTS: 29,
|
|
297
|
+
STORY_PROGRESS_BEAT_GALACTIC_CORONET: 30,
|
|
298
|
+
STORY_PROGRESS_OAK_ETERNA_CITY: 31,
|
|
299
|
+
STORY_PROGRESS_VERMILION_COPYCAT: 32,
|
|
300
|
+
STORY_PROGRESS_MET_TORNADUS_THUNDURUS: 33,
|
|
301
|
+
STORY_PROGRESS_BEAT_ELITE_FOUR_ROUND_TWO: 34,
|
|
302
|
+
STORY_PROGRESS_HALL_OF_FAME: 35,
|
|
303
|
+
STORY_PROGRESS_NONE: 36,
|
|
304
|
+
STORY_PROGRESS_NATIONAL_DEX: 37,
|
|
305
|
+
OTHER_NONE: 38,
|
|
306
|
+
OTHER_SNORLAX_11_BEAT_LEAGUE: 39,
|
|
307
|
+
OTHER_VIRTUAL_CONSOLE: 40,
|
|
308
|
+
STORY_PROGRESS_CURE_ELDRITCH_NIGHTMARES: 41,
|
|
309
|
+
OTHER_TALK_TO_CYNTHIAS_GRANDMOTHER: 42,
|
|
310
|
+
ITEM_NONE: 43,
|
|
311
|
+
ITEM_ADAMANT_ORB: 44,
|
|
312
|
+
ITEM_LUSTROUS_ORB: 45,
|
|
313
|
+
ITEM_HELIX_FOSSIL: 46,
|
|
314
|
+
ITEM_DOME_FOSSIL: 47,
|
|
315
|
+
ITEM_OLD_AMBER: 48,
|
|
316
|
+
ITEM_ROOT_FOSSIL: 49,
|
|
317
|
+
ITEM_CLAW_FOSSIL: 50,
|
|
318
|
+
STORY_PROGRESS_DEFEAT_JUPITER: 51,
|
|
319
|
+
STORY_PROGRESS_BEAT_TEAM_GALACTIC_IRON_ISLAND: 52,
|
|
320
|
+
OTHER_CORRECT_PASSWORD: 53,
|
|
321
|
+
STORY_PROGRESS_ZEPHYR_BADGE: 54,
|
|
322
|
+
STORY_PROGRESS_BEAT_RED: 55,
|
|
323
|
+
OTHER_RECEIVED_KANTO_STARTER: 56,
|
|
324
|
+
STORY_PROGRESS_RECEIVE_TM_FROM_CLAIRE: 57,
|
|
325
|
+
OTHER_REGIROCK_REGICE_REGISTEEL_IN_PARTY: 58,
|
|
326
|
+
WEEKDAY_SUNDAY: 59,
|
|
327
|
+
WEEKDAY_MONDAY: 60,
|
|
328
|
+
WEEKDAY_TUESDAY: 61,
|
|
329
|
+
WEEKDAY_WEDNESDAY: 62,
|
|
330
|
+
WEEKDAY_THURSDAY: 63,
|
|
331
|
+
WEEKDAY_FRIDAY: 64,
|
|
332
|
+
WEEKDAY_SATURDAY: 65,
|
|
333
|
+
FIRST_PARTY_POKEMON_HIGH_FRIENDSHIP: 66,
|
|
334
|
+
STORY_PROGRESS_DEFEAT_MARS: 67,
|
|
335
|
+
ITEM_ODD_KEYSTONE: 68,
|
|
336
|
+
OTHER_TALKED_TO_32_PEOPLE_UNDERGROUND: 69,
|
|
337
|
+
STORY_PROGRESS_RETURNED_MACHINE_PART: 70,
|
|
338
|
+
OTHER_EVENT_ARCEUS_IN_PARTY: 71,
|
|
339
|
+
SPECIAL_ENCOUNTER_COULDNT_CAPTURE_BEFORE: 72,
|
|
340
|
+
ITEM_ICE_KEY: 73,
|
|
341
|
+
ITEM_IRON_KEY: 74,
|
|
342
|
+
STORY_PROGRESS_JUNIPER_CAVE_OF_BEING: 75,
|
|
343
|
+
ITEM_LUNAR_WING: 76,
|
|
344
|
+
STORY_PROGRESS_QUAKE_BADGE: 77,
|
|
345
|
+
ITEM_LIGHT_STONE: 78,
|
|
346
|
+
ITEM_DARK_STONE: 79,
|
|
347
|
+
OTHER_CAPTURED_RESHIRAM_OR_ZEKROM: 80,
|
|
348
|
+
DEFEATED_GHETSIS: 81,
|
|
349
|
+
OTHER_FOUND_11_TIMES_ROAMING: 82,
|
|
350
|
+
TIME_MINUTE_00_TO_19: 83,
|
|
351
|
+
TIME_MINUTE_20_TO_39: 84,
|
|
352
|
+
TIME_MINUTE_40_TO_59: 85,
|
|
353
|
+
TIME_04_00_TO_19_59: 86,
|
|
354
|
+
TIME_20_00_TO_21_59: 87,
|
|
355
|
+
TIME_21_00_TO_03_59: 88,
|
|
356
|
+
ITEM_TIDAL_BELL: 89,
|
|
357
|
+
ITEM_CLEAR_BELL: 90,
|
|
358
|
+
STORY_PROGRESS_DEFEATED_GROUDON_OR_KYOGRE: 91,
|
|
359
|
+
OTHER_UXIE_MESPRIT_AZELF_IN_PARTY: 92,
|
|
360
|
+
OTHER_NICKNAMED_COLD_ITEM_REGICE_REGIROCK_REGISTEEL3: 93,
|
|
361
|
+
OTHER_DIALGA_OR_PALKIA_IN_PARTY: 94,
|
|
362
|
+
OTHER_CASTFORM_IN_PARTY: 95,
|
|
363
|
+
OTHER_LEVEL_100_POKEMON_IN_PARTY: 96,
|
|
364
|
+
OTHER_TORNADUS_THUNDURUS_IN_PARTY: 97,
|
|
365
|
+
OTHER_RESHIRAM_ZEKROM_IN_PARTY: 98,
|
|
366
|
+
OTHER_CAPTURED_ALL_ULTRA_BEASTS: 99,
|
|
367
|
+
STORY_PROGRESS_FINISHED_LOOKER_SIDEQUEST: 100,
|
|
368
|
+
STORY_PROGRESS_BEAT_OLIVIAS_TRIAL: 101,
|
|
369
|
+
OTHER_RAIKOU_ENTEI_IN_PARTY: 102,
|
|
370
|
+
OTHER_GROUDON_KYOGRE_IN_PARTY: 103,
|
|
371
|
+
OTHER_DIALGA_PALKIA_IN_PARTY: 104,
|
|
372
|
+
OTHER_SCAN_QR_CODE: 105,
|
|
373
|
+
OTHER_CAUGHT_ARTICUNO: 106,
|
|
374
|
+
OTHER_CAUGHT_ZAPDOS: 107,
|
|
375
|
+
OTHER_CAUGHT_MOLTRES: 108,
|
|
376
|
+
TRADE_TOGEPI_OR_TOGETIC: 109,
|
|
377
|
+
TRADE_TRAPINCH: 110,
|
|
378
|
+
TRADE_SURSKIT: 111,
|
|
379
|
+
TRADE_WOOPER: 112,
|
|
380
|
+
STORY_PROGRESS_CATCH_ALL_SHADOW_POKEMON: 113,
|
|
381
|
+
OTHER_COMPLETE_MT_BATTLE: 114,
|
|
382
|
+
COINS_180: 115,
|
|
383
|
+
COINS_500: 116,
|
|
384
|
+
COINS_1200: 117,
|
|
385
|
+
COINS_2800: 118,
|
|
386
|
+
COINS_5500: 119,
|
|
387
|
+
COINS_9999: 120,
|
|
388
|
+
COINS_120: 121,
|
|
389
|
+
COINS_750: 122,
|
|
390
|
+
COINS_2500: 123,
|
|
391
|
+
COINS_4600: 124,
|
|
392
|
+
COINS_6500: 125,
|
|
393
|
+
COINS_230: 126,
|
|
394
|
+
COINS_1000: 127,
|
|
395
|
+
COINS_2680: 128,
|
|
396
|
+
COINS_3333: 129,
|
|
397
|
+
COINS_6666: 130,
|
|
398
|
+
COINS_200: 131,
|
|
399
|
+
COINS_700: 132,
|
|
400
|
+
COINS_2100: 133,
|
|
401
|
+
COINS_100: 134,
|
|
402
|
+
COINS_800: 135,
|
|
403
|
+
COINS_1500: 136,
|
|
404
|
+
COINS_2222: 137,
|
|
405
|
+
COINS_5555: 138,
|
|
406
|
+
COINS_8888: 139,
|
|
407
|
+
COINS_150: 140,
|
|
408
|
+
COINS_620: 141,
|
|
409
|
+
COINS_2880: 142,
|
|
410
|
+
COINS_5400: 143,
|
|
411
|
+
COINS_8300: 144,
|
|
412
|
+
TRADE_ABRA: 145,
|
|
413
|
+
TRADE_NIDORAN_M: 146,
|
|
414
|
+
TRADE_NIDORINO: 147,
|
|
415
|
+
TRADE_SLOWBRO: 148,
|
|
416
|
+
TRADE_POLIWHIRL: 149,
|
|
417
|
+
TRADE_SPEAROW: 150,
|
|
418
|
+
TRADE_RAICHU: 151,
|
|
419
|
+
TRADE_VENONAT: 152,
|
|
420
|
+
TRADE_PONYTA: 153,
|
|
421
|
+
TRADE_CLEFAIRY: 154,
|
|
422
|
+
TRADE_CUBONE: 155,
|
|
423
|
+
TRADE_LICKITUNG: 156,
|
|
424
|
+
TRADE_TANGELA: 157,
|
|
425
|
+
TRADE_GOLDUCK: 158,
|
|
426
|
+
TRADE_GROWLITHE: 159,
|
|
427
|
+
TRADE_KANGASKHAN: 160,
|
|
428
|
+
TRADE_BELLSPROUT: 161,
|
|
429
|
+
TRADE_DROWZEE: 162,
|
|
430
|
+
TRADE_KRABBY: 163,
|
|
431
|
+
TRADE_DRAGONAIR: 164,
|
|
432
|
+
TRADE_CHANSEY: 165,
|
|
433
|
+
TRADE_GLOOM: 166,
|
|
434
|
+
TRADE_HAUNTER: 167,
|
|
435
|
+
TRADE_DUGTRIO: 168,
|
|
436
|
+
TRADE_SLAKOTH: 169,
|
|
437
|
+
TRADE_PIKACHU: 170,
|
|
438
|
+
TRADE_BELLOSSOM: 171,
|
|
439
|
+
TRADE_RALTS: 172,
|
|
440
|
+
TRADE_VOLBEAT: 173,
|
|
441
|
+
TRADE_BAGON: 174,
|
|
442
|
+
TRADE_SKITTY: 175,
|
|
443
|
+
FRIEND_SAFARI_SLOT_1: 176,
|
|
444
|
+
FRIEND_SAFARI_SLOT_2: 177,
|
|
445
|
+
FRIEND_SAFARI_SLOT_3: 178,
|
|
446
|
+
ITEM_SKULL_FOSSIL: 179,
|
|
447
|
+
ITEM_ARMOR_FOSSIL: 180,
|
|
448
|
+
GREAT_MARSH_DAILY_SLOT_NONE: 181,
|
|
449
|
+
GREAT_MARSH_DAILY_SLOT_1_OF_32: 182,
|
|
450
|
+
GREAT_MARSH_DAILY_SLOT_2_OF_32: 183,
|
|
451
|
+
GREAT_MARSH_DAILY_SLOT_3_OF_32: 184,
|
|
452
|
+
GREAT_MARSH_DAILY_SLOT_5_OF_32: 185,
|
|
453
|
+
STORY_PROGRESS_BEFORE_NATIONAL_DEX: 186,
|
|
454
|
+
GREAT_MARSH_DAILY_SLOT_4_OF_32: 187,
|
|
455
|
+
GREAT_MARSH_DAILY_SLOT_15_OF_32: 188,
|
|
456
|
+
HONEY_TREE_GROUP_A: 189,
|
|
457
|
+
HONEY_TREE_GROUP_B: 190,
|
|
458
|
+
HONEY_TREE_GROUP_C: 191,
|
|
459
|
+
HEADBUTT_TREE_COMMON: 192,
|
|
460
|
+
HEADBUTT_TREE_RARE: 193,
|
|
461
|
+
HEADBUTT_TREE_SECRET: 194,
|
|
462
|
+
TRADE_COTTONEE: 195,
|
|
463
|
+
TRADE_PETILIL: 196,
|
|
464
|
+
TRADE_EMOLGA: 197,
|
|
465
|
+
TRADE_MANTINE: 198,
|
|
466
|
+
TRADE_DITTO: 199,
|
|
467
|
+
TRADE_EXCADRILL: 200,
|
|
468
|
+
TRADE_HIPPOWDON: 201,
|
|
469
|
+
BACKLOT_NOT_MENTIONED: 202,
|
|
470
|
+
BACKLOT_MENTIONED: 203,
|
|
471
|
+
BUG_CATCHING_CONTEST_NO: 204,
|
|
472
|
+
BUG_CATCHING_CONTEST_YES: 205,
|
|
473
|
+
SAVE_DATA_FROM_LETS_GO_PIKACHU: 206,
|
|
474
|
+
SAVE_DATA_FROM_LETS_GO_EEVEE: 207,
|
|
475
|
+
ITEM_FOSSILIZED_BIRD: 208,
|
|
476
|
+
ITEM_FOSSILIZED_DRAKE: 209,
|
|
477
|
+
ITEM_FOSSILIZED_DINO: 210,
|
|
478
|
+
ITEM_FOSSILIZED_FISH: 211,
|
|
479
|
+
STORY_PROGRESS_MASTER_DOJO_COMPLETE_FIRST_TRIAL: 212,
|
|
480
|
+
STORY_PROGRESS_MASTER_DOJO_COMPLETE_THIRD_TRIAL: 213,
|
|
481
|
+
ALOLAN_DIGLETT_FOUND_5: 214,
|
|
482
|
+
ALOLAN_DIGLETT_FOUND_10: 215,
|
|
483
|
+
ALOLAN_DIGLETT_FOUND_20: 216,
|
|
484
|
+
ALOLAN_DIGLETT_FOUND_30: 217,
|
|
485
|
+
ALOLAN_DIGLETT_FOUND_40: 218,
|
|
486
|
+
ALOLAN_DIGLETT_FOUND_50: 219,
|
|
487
|
+
ALOLAN_DIGLETT_FOUND_75: 220,
|
|
488
|
+
ALOLAN_DIGLETT_FOUND_100: 221,
|
|
489
|
+
ALOLAN_DIGLETT_FOUND_150: 222,
|
|
490
|
+
STARTER_GROOKEY: 223,
|
|
491
|
+
STARTER_SCORBUNNY: 224,
|
|
492
|
+
STARTER_SOBBLE: 225,
|
|
493
|
+
STORY_PROGRESS_SAVE_VILLAGE_FROM_GLASTRIER_SPECTRIER: 226,
|
|
494
|
+
STORY_PROGRESS_CATCH_FIVE_ULTRA_BEASTS: 227,
|
|
495
|
+
TRADE_BUNNELBY: 228,
|
|
496
|
+
TRADE_MEOWTH_GALAR: 229,
|
|
497
|
+
TRADE_MINCCINO: 230,
|
|
498
|
+
TRADE_TOXEL: 231,
|
|
499
|
+
TRADE_MARACTUS: 232,
|
|
500
|
+
TRADE_YAMASK_GALAR: 233,
|
|
501
|
+
TRADE_VANILLISH: 234,
|
|
502
|
+
TRADE_OBSTAGOON: 235,
|
|
503
|
+
TRADE_FROSMOTH: 236,
|
|
504
|
+
TRADE_FARFETCHD_GALAR: 237,
|
|
505
|
+
TRADE_CORSOLA_GALAR: 238,
|
|
506
|
+
TRADE_PONYTA_GALAR: 239,
|
|
507
|
+
TRADE_MR_MIME_GALAR: 240,
|
|
508
|
+
TRADE_DARUMAKA_GALAR: 241,
|
|
509
|
+
TRADE_ZIGZAGOON_GALAR: 242,
|
|
510
|
+
TRADE_STUNFISK_GALAR: 243,
|
|
511
|
+
TRADE_WEEZING_GALAR: 244,
|
|
512
|
+
TRADE_EXEGGUTOR: 245,
|
|
513
|
+
TRADE_MAROWAK: 246,
|
|
514
|
+
WEATHER_NORMAL: 247,
|
|
515
|
+
WEATHER_OVERCAST: 248,
|
|
516
|
+
WEATHER_RAINING: 249,
|
|
517
|
+
WEATHER_THUNDERSTORM: 250,
|
|
518
|
+
WEATHER_SNOWING: 251,
|
|
519
|
+
WEATHER_SNOWSTORM: 252,
|
|
520
|
+
WEATHER_SANDSTORM: 253,
|
|
521
|
+
WEATHER_INTENSE_SUN: 254,
|
|
522
|
+
WEATHER_FOG: 255,
|
|
523
|
+
STORY_PROGRESS_BEFORE_HALL_OF_FAME: 256,
|
|
524
|
+
JOHTO_SAFARI_BLOCKS_INACTIVE: 257,
|
|
525
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_2: 258,
|
|
526
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_3: 259,
|
|
527
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_4: 260,
|
|
528
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_5: 261,
|
|
529
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_6: 262,
|
|
530
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_10: 263,
|
|
531
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_12: 264,
|
|
532
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_14: 265,
|
|
533
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_15: 266,
|
|
534
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_24: 267,
|
|
535
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_28: 268,
|
|
536
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_35: 269,
|
|
537
|
+
JOHTO_SAFARI_BLOCKS_PLAINS_MIN_49: 270,
|
|
538
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_3: 271,
|
|
539
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_4: 272,
|
|
540
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_5: 273,
|
|
541
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_8: 274,
|
|
542
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_10: 275,
|
|
543
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_14: 276,
|
|
544
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_15: 277,
|
|
545
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_18: 278,
|
|
546
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_20: 279,
|
|
547
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_28: 280,
|
|
548
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_35: 281,
|
|
549
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_42: 282,
|
|
550
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_49: 283,
|
|
551
|
+
JOHTO_SAFARI_BLOCKS_FOREST_MIN_56: 284,
|
|
552
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_3: 285,
|
|
553
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_4: 286,
|
|
554
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_5: 287,
|
|
555
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_6: 288,
|
|
556
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_8: 289,
|
|
557
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_10: 290,
|
|
558
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_15: 291,
|
|
559
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_21: 292,
|
|
560
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_24: 293,
|
|
561
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_28: 294,
|
|
562
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_35: 295,
|
|
563
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_42: 296,
|
|
564
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_49: 297,
|
|
565
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_56: 298,
|
|
566
|
+
JOHTO_SAFARI_BLOCKS_PEAK_MIN_63: 299,
|
|
567
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_2: 300,
|
|
568
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_3: 301,
|
|
569
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_4: 302,
|
|
570
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_5: 303,
|
|
571
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_6: 304,
|
|
572
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_7: 305,
|
|
573
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_8: 306,
|
|
574
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_9: 307,
|
|
575
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_10: 308,
|
|
576
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_12: 309,
|
|
577
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_13: 310,
|
|
578
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_14: 311,
|
|
579
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_15: 312,
|
|
580
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_16: 313,
|
|
581
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_18: 314,
|
|
582
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_20: 315,
|
|
583
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_24: 316,
|
|
584
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_28: 317,
|
|
585
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_35: 318,
|
|
586
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_42: 319,
|
|
587
|
+
JOHTO_SAFARI_BLOCKS_WATER_MIN_49: 320,
|
|
588
|
+
ITEM_COVER_FOSSIL: 321,
|
|
589
|
+
ITEM_PLUME_FOSSIL: 322,
|
|
590
|
+
OTHER_GIRATINA_NOT_CAUGHT_IN_DISTORTION_WORLD: 323,
|
|
591
|
+
OTHER_FIND_50_CAVERN_FOOTPRINTS: 324,
|
|
592
|
+
OTHER_FIND_50_GRASSLAND_FOOTPRINTS: 325,
|
|
593
|
+
OTHER_FIND_50_IRON_WILL_FOOTPRINTS: 326,
|
|
594
|
+
OTHER_REGIROCK_REGICE_REGISTEEL_REGIELEKI_REGIDRAGO_IN_PARTY: 327,
|
|
595
|
+
OTHER_CHOOSE_REGIELEKI_PATTERN: 328,
|
|
596
|
+
OTHER_CHOOSE_REGIDRAGO_PATTERN: 329,
|
|
597
|
+
OTHER_GROW_ICEROOT_CARROT: 330,
|
|
598
|
+
OTHER_GROW_SHADEROOT_CARROT: 331,
|
|
599
|
+
OTHER_TALKED_TO_32_PEOPLE: 332,
|
|
600
|
+
OTHER_EAT_CURRY_WITH_COBALION_TERRAKION_VIRIZION: 333,
|
|
601
|
+
ITEM_REINS_OF_UNITY: 334,
|
|
602
|
+
OTHER_WITNESS_GALARIAN_BIRD_FIGHT: 335,
|
|
603
|
+
MAX_DEN_RARITY_COMMON: 336,
|
|
604
|
+
MAX_DEN_RARITY_RARE: 337,
|
|
605
|
+
MAX_DEN_RATING_1_STAR: 338,
|
|
606
|
+
MAX_DEN_RATING_2_STAR: 339,
|
|
607
|
+
MAX_DEN_RATING_3_STAR: 340,
|
|
608
|
+
MAX_DEN_RATING_4_STAR: 341,
|
|
609
|
+
MAX_DEN_RATING_5_STAR: 342,
|
|
610
|
+
MAX_DEN_RARITY_SPECIAL: 343,
|
|
611
|
+
BERRY_TREE_TYPE_RED: 344,
|
|
612
|
+
BERRY_TREE_TYPE_BLUE: 345,
|
|
613
|
+
BERRY_TREE_TYPE_PURPLE: 346,
|
|
614
|
+
BERRY_TREE_TYPE_GREEN: 347,
|
|
615
|
+
BERRY_TREE_TYPE_YELLOW: 348,
|
|
616
|
+
BERRY_TREE_TYPE_PINK: 349,
|
|
617
|
+
TRASH_CAN_TYPE_DAILY: 350,
|
|
618
|
+
TRASH_CAN_TYPE_TUESDAY: 351,
|
|
619
|
+
TRASH_CAN_TYPE_THURSDAY: 352,
|
|
620
|
+
TRADE_NIDORAN_F: 353,
|
|
621
|
+
TRADE_NIDORINA: 354,
|
|
622
|
+
TRADE_MACHOP: 355,
|
|
623
|
+
TRADE_BUIZEL: 356,
|
|
624
|
+
TRADE_MEDICHAM: 357,
|
|
625
|
+
TRADE_FINNEON: 358,
|
|
626
|
+
TRADE_FORRETRESS: 359,
|
|
627
|
+
TRADE_BONSLY: 360,
|
|
628
|
+
TRADE_ANY_POKEMON: 361,
|
|
629
|
+
/**
|
|
630
|
+
* @deprecated Misspelled: the endpoint names this `other-snorlax-11-beat-league`.
|
|
631
|
+
* Use {@link ENCOUNTER_CONDITION_VALUES.OTHER_SNORLAX_11_BEAT_LEAGUE}. Removed in 3.0.
|
|
632
|
+
*/
|
|
633
|
+
OTHER_SNORLAX_LL_BEAT_LEAGUE: 39,
|
|
634
|
+
/**
|
|
635
|
+
* @deprecated Misspelled: the endpoint names this `radio-hoenn`.
|
|
636
|
+
* Use {@link ENCOUNTER_CONDITION_VALUES.RADIO_HOENN}. Removed in 3.0.
|
|
637
|
+
*/
|
|
638
|
+
RADIO_HOEN: 15,
|
|
639
|
+
/**
|
|
640
|
+
* @deprecated Misspelled: the endpoint names this `slot2-sapphire`.
|
|
641
|
+
* Use {@link ENCOUNTER_CONDITION_VALUES.SLOT2_SAPPHIRE}. Removed in 3.0.
|
|
642
|
+
*/
|
|
643
|
+
SLOT2_SAPHIRE: 10,
|
|
644
|
+
/**
|
|
645
|
+
* @deprecated The endpoint names this `story-progress-vermilion-copycat` now.
|
|
646
|
+
* Use {@link ENCOUNTER_CONDITION_VALUES.STORY_PROGRESS_VERMILION_COPYCAT}. Removed in 3.0.
|
|
647
|
+
*/
|
|
648
|
+
STORY_PROGRESS_OAK_VERMILION_COPYCAT: 32,
|
|
649
|
+
/**
|
|
650
|
+
* @deprecated Misspelled: the endpoint names this `season-autumn`.
|
|
651
|
+
* Use {@link ENCOUNTER_CONDITION_VALUES.SEASON_AUTUMN}. Removed in 3.0.
|
|
652
|
+
*/
|
|
653
|
+
SWASON_AUTUMN: 19
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
//#endregion
|
|
657
|
+
//#region src/constants/endpoints.ts
|
|
658
|
+
/**
|
|
659
|
+
* Endpoints of the PokéAPI
|
|
660
|
+
*/
|
|
661
|
+
const ENDPOINTS = {
|
|
662
|
+
BERRY: "/berry",
|
|
663
|
+
BERRY_FIRMNESS: "/berry-firmness",
|
|
664
|
+
BERRY_FLAVOR: "/berry-flavor",
|
|
665
|
+
CONTEST_TYPE: "/contest-type",
|
|
666
|
+
CONTEST_EFFECT: "/contest-effect",
|
|
667
|
+
SUPER_CONTEST_EFFECT: "/super-contest-effect",
|
|
668
|
+
CURRENCY: "/currency",
|
|
669
|
+
ENCOUNTER_METHOD: "/encounter-method",
|
|
670
|
+
ENCOUNTER_CONDITION: "/encounter-condition",
|
|
671
|
+
ENCOUNTER_CONDITION_VALUE: "/encounter-condition-value",
|
|
672
|
+
EVOLUTION_CHAIN: "/evolution-chain",
|
|
673
|
+
EVOLUTION_TRIGGER: "/evolution-trigger",
|
|
674
|
+
EVOLUTION_VARIABLE: "/evolution-variable",
|
|
675
|
+
GENERATION: "/generation",
|
|
676
|
+
POKEDEX: "/pokedex",
|
|
677
|
+
VERSION: "/version",
|
|
678
|
+
VERSION_GROUP: "/version-group",
|
|
679
|
+
ITEM: "/item",
|
|
680
|
+
ITEM_ATTRIBUTE: "/item-attribute",
|
|
681
|
+
ITEM_CATEGORY: "/item-category",
|
|
682
|
+
ITEM_FLING_EFFECT: "/item-fling-effect",
|
|
683
|
+
ITEM_POCKET: "/item-pocket",
|
|
684
|
+
LOCATION: "/location",
|
|
685
|
+
LOCATION_AREA: "/location-area",
|
|
686
|
+
PALPARK_AREA: "/pal-park-area",
|
|
687
|
+
REGION: "/region",
|
|
688
|
+
MACHINE: "/machine",
|
|
689
|
+
MOVE: "/move",
|
|
690
|
+
MOVE_AILMENT: "/move-ailment",
|
|
691
|
+
MOVE_BATTLE_STYLE: "/move-battle-style",
|
|
692
|
+
MOVE_CATEGORY: "/move-category",
|
|
693
|
+
MOVE_DAMAGE_CLASS: "/move-damage-class",
|
|
694
|
+
MOVE_LEARN_METHOD: "/move-learn-method",
|
|
695
|
+
MOVE_TARGET: "/move-target",
|
|
696
|
+
ABILITY: "/ability",
|
|
697
|
+
CHARACTERISTIC: "/characteristic",
|
|
698
|
+
EGG_GROUP: "/egg-group",
|
|
699
|
+
GENDER: "/gender",
|
|
700
|
+
GROWTH_RATE: "/growth-rate",
|
|
701
|
+
NATURE: "/nature",
|
|
702
|
+
POKEATHLON_STAT: "/pokeathlon-stat",
|
|
703
|
+
POKEMON: "/pokemon",
|
|
704
|
+
POKEMON_COLOR: "/pokemon-color",
|
|
705
|
+
POKEMON_FORM: "/pokemon-form",
|
|
706
|
+
POKEMON_HABITAT: "/pokemon-habitat",
|
|
707
|
+
POKEMON_SHAPE: "/pokemon-shape",
|
|
708
|
+
POKEMON_SPECIES: "/pokemon-species",
|
|
709
|
+
STAT: "/stat",
|
|
710
|
+
TYPE: "/type",
|
|
711
|
+
LANGUAGE: "/language"
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
//#endregion
|
|
715
|
+
//#region src/constants/evolutions.ts
|
|
716
|
+
const EVOLUTION_TRIGGERS = {
|
|
717
|
+
LEVEL_UP: 1,
|
|
718
|
+
TRADE: 2,
|
|
719
|
+
USE_ITEM: 3,
|
|
720
|
+
SHED: 4,
|
|
721
|
+
SPIN: 5,
|
|
722
|
+
TOWER_OF_DARKNESS: 6,
|
|
723
|
+
TOWER_OF_WATERS: 7,
|
|
724
|
+
THREE_CRITICAL_HITS: 8,
|
|
725
|
+
TAKE_DAMAGE: 9,
|
|
726
|
+
IN_BATTLE_LEVEL_UP: 10,
|
|
727
|
+
AGILE_STYLE_MOVE: 11,
|
|
728
|
+
STRONG_STYLE_MOVE: 12,
|
|
729
|
+
RECOIL_DAMAGE: 13,
|
|
730
|
+
USE_MOVE: 14,
|
|
731
|
+
THREE_DEFEATED_BISHARP: 15,
|
|
732
|
+
GIMMIGHOUL_COINS: 16,
|
|
733
|
+
MELTAN_CANDIES: 17,
|
|
734
|
+
UNCLASSIFIED: 18,
|
|
735
|
+
/**
|
|
736
|
+
* @deprecated Misspelled: the endpoint names this trigger `tower-of-waters`.
|
|
737
|
+
* Use {@link EVOLUTION_TRIGGERS.TOWER_OF_WATERS}. Removed in 3.0.
|
|
738
|
+
*/
|
|
739
|
+
TOWER_OF_WATER: 7
|
|
740
|
+
};
|
|
741
|
+
const EVOLUTION_VARIABLES = {
|
|
742
|
+
ENCRYPTION_CONSTANT: 1,
|
|
743
|
+
PERSONALITY_VALUE: 2,
|
|
744
|
+
SPIN_DIRECTION: 3,
|
|
745
|
+
SPIN_DURATION: 4
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
//#endregion
|
|
749
|
+
//#region src/constants/games.ts
|
|
750
|
+
const GENERATIONS = {
|
|
751
|
+
GENERATION_I: 1,
|
|
752
|
+
GENERATION_II: 2,
|
|
753
|
+
GENERATION_III: 3,
|
|
754
|
+
GENERATION_IV: 4,
|
|
755
|
+
GENERATION_V: 5,
|
|
756
|
+
GENERATION_VI: 6,
|
|
757
|
+
GENERATION_VII: 7,
|
|
758
|
+
GENERATION_VIII: 8,
|
|
759
|
+
GENERATION_IX: 9
|
|
760
|
+
};
|
|
761
|
+
const POKEDEXES = {
|
|
762
|
+
NATIONAL: 1,
|
|
763
|
+
KANTO: 2,
|
|
764
|
+
ORIGINAL_JOHTO: 3,
|
|
765
|
+
HOENN: 4,
|
|
766
|
+
ORIGINAL_SINNOH: 5,
|
|
767
|
+
EXTENDED_SINNOH: 6,
|
|
768
|
+
UPDATED_JOHTO: 7,
|
|
769
|
+
ORIGINAL_UNOVA: 8,
|
|
770
|
+
UPDATED_UNOVA: 9,
|
|
771
|
+
CONQUEST_GALLERY: 11,
|
|
772
|
+
KALOS_CENTRAL: 12,
|
|
773
|
+
KALOS_COASTAL: 13,
|
|
774
|
+
KALOS_MOUNTAIN: 14,
|
|
775
|
+
UPDATED_HOENN: 15,
|
|
776
|
+
ORIGINAL_ALOLA: 16,
|
|
777
|
+
ORIGINAL_MELEMELE: 17,
|
|
778
|
+
ORIGINAL_AKALA: 18,
|
|
779
|
+
ORIGINAL_ULAULA: 19,
|
|
780
|
+
ORIGINAL_PONI: 20,
|
|
781
|
+
UPDATED_ALOLA: 21,
|
|
782
|
+
UPDATED_MELEMELE: 22,
|
|
783
|
+
UPDATED_AKALA: 23,
|
|
784
|
+
UPDATED_ULAULA: 24,
|
|
785
|
+
UPDATED_PONI: 25,
|
|
786
|
+
LETSGO_KANTO: 26,
|
|
787
|
+
GALAR: 27,
|
|
788
|
+
ISLE_OF_ARMOR: 28,
|
|
789
|
+
CROWN_TUNDRA: 29,
|
|
790
|
+
HISUI: 30,
|
|
791
|
+
PALDEA: 31,
|
|
792
|
+
KITAKAMI: 32,
|
|
793
|
+
BLUEBERRY: 33,
|
|
794
|
+
LUMIOSE_CITY: 34,
|
|
795
|
+
HYPERSPACE: 35,
|
|
796
|
+
CHAMPIONS: 36,
|
|
797
|
+
/**
|
|
798
|
+
* @deprecated Misspelled: the endpoint names this `kalos-mountain`.
|
|
799
|
+
* Use {@link POKEDEXES.KALOS_MOUNTAIN}. Removed in 3.0.
|
|
800
|
+
*/
|
|
801
|
+
KALOS_MONTAIN: 14,
|
|
802
|
+
/**
|
|
803
|
+
* @deprecated The endpoint names this `letsgo-kanto` now.
|
|
804
|
+
* Use {@link POKEDEXES.LETSGO_KANTO}. Removed in 3.0.
|
|
805
|
+
*/
|
|
806
|
+
UPDATED_KANTO: 26
|
|
807
|
+
};
|
|
808
|
+
const VERSIONS = {
|
|
809
|
+
RED: 1,
|
|
810
|
+
BLUE: 2,
|
|
811
|
+
YELLOW: 3,
|
|
812
|
+
GOLD: 4,
|
|
813
|
+
SILVER: 5,
|
|
814
|
+
CRYSTAL: 6,
|
|
815
|
+
RUBY: 7,
|
|
816
|
+
SAPPHIRE: 8,
|
|
817
|
+
EMERALD: 9,
|
|
818
|
+
FIRERED: 10,
|
|
819
|
+
LEAFGREEN: 11,
|
|
820
|
+
DIAMOND: 12,
|
|
821
|
+
PEARL: 13,
|
|
822
|
+
PLATINUM: 14,
|
|
823
|
+
HEARTGOLD: 15,
|
|
824
|
+
SOULSILVER: 16,
|
|
825
|
+
BLACK: 17,
|
|
826
|
+
WHITE: 18,
|
|
827
|
+
COLOSSEUM: 19,
|
|
828
|
+
XD: 20,
|
|
829
|
+
BLACK_2: 21,
|
|
830
|
+
WHITE_2: 22,
|
|
831
|
+
X: 23,
|
|
832
|
+
Y: 24,
|
|
833
|
+
OMEGA_RUBY: 25,
|
|
834
|
+
ALPHA_SAPPHIRE: 26,
|
|
835
|
+
SUN: 27,
|
|
836
|
+
MOON: 28,
|
|
837
|
+
ULTRA_SUN: 29,
|
|
838
|
+
ULTRA_MOON: 30,
|
|
839
|
+
LETS_GO_PIKACHU: 31,
|
|
840
|
+
LETS_GO_EEVEE: 32,
|
|
841
|
+
SWORD: 33,
|
|
842
|
+
SHIELD: 34,
|
|
843
|
+
THE_ISLE_OF_ARMOR_SWORD: 35,
|
|
844
|
+
THE_CROWN_TUNDRA_SWORD: 36,
|
|
845
|
+
BRILLIANT_DIAMOND: 37,
|
|
846
|
+
SHINING_PEARL: 38,
|
|
847
|
+
LEGENDS_ARCEUS: 39,
|
|
848
|
+
SCARLET: 40,
|
|
849
|
+
VIOLET: 41,
|
|
850
|
+
THE_TEAL_MASK_SCARLET: 42,
|
|
851
|
+
THE_INDIGO_DISK_SCARLET: 43,
|
|
852
|
+
RED_JAPAN: 44,
|
|
853
|
+
GREEN_JAPAN: 45,
|
|
854
|
+
BLUE_JAPAN: 46,
|
|
855
|
+
LEGENDS_ZA: 47,
|
|
856
|
+
MEGA_DIMENSION: 48,
|
|
857
|
+
CHAMPIONS: 49,
|
|
858
|
+
THE_ISLE_OF_ARMOR_SHIELD: 50,
|
|
859
|
+
THE_CROWN_TUNDRA_SHIELD: 51,
|
|
860
|
+
THE_TEAL_MASK_VIOLET: 52,
|
|
861
|
+
THE_INDIGO_DISK_VIOLET: 53,
|
|
862
|
+
/**
|
|
863
|
+
* @deprecated The endpoint names this `the-crown-tundra-sword` now.
|
|
864
|
+
* Use {@link VERSIONS.THE_CROWN_TUNDRA_SWORD}. Removed in 3.0.
|
|
865
|
+
*/
|
|
866
|
+
THE_CROWN_TUNDRA: 36,
|
|
867
|
+
/**
|
|
868
|
+
* @deprecated The endpoint names this `the-isle-of-armor-sword` now.
|
|
869
|
+
* Use {@link VERSIONS.THE_ISLE_OF_ARMOR_SWORD}. Removed in 3.0.
|
|
870
|
+
*/
|
|
871
|
+
THE_ISLE_OF_ARMOR: 35
|
|
872
|
+
};
|
|
873
|
+
const VERSION_GROUPS = {
|
|
874
|
+
RED_BLUE: 1,
|
|
875
|
+
YELLOW: 2,
|
|
876
|
+
GOLD_SILVER: 3,
|
|
877
|
+
CRYSTAL: 4,
|
|
878
|
+
RUBY_SAPPHIRE: 5,
|
|
879
|
+
EMERALD: 6,
|
|
880
|
+
FIRERED_LEAFGREEN: 7,
|
|
881
|
+
DIAMOND_PEARL: 8,
|
|
882
|
+
PLATINUM: 9,
|
|
883
|
+
HEARTGOLD_SOULSILVER: 10,
|
|
884
|
+
BLACK_WHITE: 11,
|
|
885
|
+
COLOSSEUM: 12,
|
|
886
|
+
XD: 13,
|
|
887
|
+
BLACK_2_WHITE_2: 14,
|
|
888
|
+
X_Y: 15,
|
|
889
|
+
OMEGA_RUBY_ALPHA_SAPPHIRE: 16,
|
|
890
|
+
SUN_MOON: 17,
|
|
891
|
+
ULTRA_SUN_ULTRA_MOON: 18,
|
|
892
|
+
LETS_GO_PIKACHU_LETS_GO_EEVEE: 19,
|
|
893
|
+
SWORD_SHIELD: 20,
|
|
894
|
+
THE_ISLE_OF_ARMOR: 21,
|
|
895
|
+
THE_CROWN_TUNDRA: 22,
|
|
896
|
+
BRILLIANT_DIAMOND_SHINING_PEARL: 23,
|
|
897
|
+
LEGENDS_ARCEUS: 24,
|
|
898
|
+
SCARLET_VIOLET: 25,
|
|
899
|
+
THE_TEAL_MASK: 26,
|
|
900
|
+
THE_INDIGO_DISK: 27,
|
|
901
|
+
RED_GREEN_JAPAN: 28,
|
|
902
|
+
BLUE_JAPAN: 29,
|
|
903
|
+
LEGENDS_ZA: 30,
|
|
904
|
+
MEGA_DIMENSION: 31,
|
|
905
|
+
CHAMPIONS: 32,
|
|
906
|
+
/**
|
|
907
|
+
* @deprecated The endpoint names this `brilliant-diamond-shining-pearl` now.
|
|
908
|
+
* Use {@link VERSION_GROUPS.BRILLIANT_DIAMOND_SHINING_PEARL}. Removed in 3.0.
|
|
909
|
+
*/
|
|
910
|
+
BRILLIANT_DIAMOND_AND_SHINING_PEARL: 23,
|
|
911
|
+
/**
|
|
912
|
+
* @deprecated The endpoint names this `lets-go-pikachu-lets-go-eevee` now.
|
|
913
|
+
* Use {@link VERSION_GROUPS.LETS_GO_PIKACHU_LETS_GO_EEVEE}. Removed in 3.0.
|
|
914
|
+
*/
|
|
915
|
+
LETS_GO: 19
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
//#endregion
|
|
919
|
+
//#region src/constants/items.ts
|
|
920
|
+
const ITEM_ATTRIBUTES = {
|
|
921
|
+
COUNTABLE: 1,
|
|
922
|
+
CONSUMABLE: 2,
|
|
923
|
+
USABLE_OVERWORLD: 3,
|
|
924
|
+
USABLE_IN_BATTLE: 4,
|
|
925
|
+
HOLDABLE: 5,
|
|
926
|
+
HOLDABLE_PASSIVE: 6,
|
|
927
|
+
HOLDABLE_ACTIVE: 7,
|
|
928
|
+
UNDERGROUND: 8
|
|
929
|
+
};
|
|
930
|
+
const ITEM_CATEGORIES = {
|
|
931
|
+
STAT_BOOSTS: 1,
|
|
932
|
+
EFFORT_DROP: 2,
|
|
933
|
+
MEDICINE: 3,
|
|
934
|
+
OTHER: 4,
|
|
935
|
+
IN_A_PINCH: 5,
|
|
936
|
+
PICKY_HEALING: 6,
|
|
937
|
+
TYPE_PROTECTION: 7,
|
|
938
|
+
BAKING_ONLY: 8,
|
|
939
|
+
COLLECTIBLES: 9,
|
|
940
|
+
EVOLUTION: 10,
|
|
941
|
+
SPELUNKING: 11,
|
|
942
|
+
HELD_ITEMS: 12,
|
|
943
|
+
CHOICE: 13,
|
|
944
|
+
EFFORT_TRAINING: 14,
|
|
945
|
+
BAD_HELD_ITEMS: 15,
|
|
946
|
+
TRAINING: 16,
|
|
947
|
+
PLATES: 17,
|
|
948
|
+
SPECIES_SPECIFIC: 18,
|
|
949
|
+
TYPE_ENHANCEMENT: 19,
|
|
950
|
+
EVENT_ITEMS: 20,
|
|
951
|
+
GAMEPLAY: 21,
|
|
952
|
+
PLOT_ADVANCEMENT: 22,
|
|
953
|
+
UNUSED: 23,
|
|
954
|
+
LOOT: 24,
|
|
955
|
+
ALL_MAIL: 25,
|
|
956
|
+
VITAMINS: 26,
|
|
957
|
+
HEALING: 27,
|
|
958
|
+
PP_RECOVERY: 28,
|
|
959
|
+
REVIVAL: 29,
|
|
960
|
+
STATUS_CURES: 30,
|
|
961
|
+
MULCH: 32,
|
|
962
|
+
SPECIAL_BALLS: 33,
|
|
963
|
+
STANDARD_BALLS: 34,
|
|
964
|
+
DEX_COMPLETION: 35,
|
|
965
|
+
SCARVES: 36,
|
|
966
|
+
ALL_MACHINES: 37,
|
|
967
|
+
FLUTES: 38,
|
|
968
|
+
APRICORN_BALLS: 39,
|
|
969
|
+
APRICORN_BOX: 40,
|
|
970
|
+
DATA_CARDS: 41,
|
|
971
|
+
JEWELS: 42,
|
|
972
|
+
MIRACLE_SHOOTER: 43,
|
|
973
|
+
MEGA_STONES: 44,
|
|
974
|
+
MEMORIES: 45,
|
|
975
|
+
Z_CRYSTALS: 46,
|
|
976
|
+
SPECIES_CANDIES: 47,
|
|
977
|
+
CATCHING_BONUS: 48,
|
|
978
|
+
DYNAMAX_CRYSTALS: 49,
|
|
979
|
+
NATURE_MINTS: 50,
|
|
980
|
+
CURRY_INGREDIENTS: 51,
|
|
981
|
+
TERA_SHARD: 52,
|
|
982
|
+
SANDWICH_INGREDIENTS: 53,
|
|
983
|
+
TM_MATERIALS: 54,
|
|
984
|
+
PICNIC: 55,
|
|
985
|
+
/**
|
|
986
|
+
* @deprecated Misspelled: the endpoint names this `dynamax-crystals`.
|
|
987
|
+
* Use {@link ITEM_CATEGORIES.DYNAMAX_CRYSTALS}. Removed in 3.0.
|
|
988
|
+
*/
|
|
989
|
+
DYNAMAX_CRISTALS: 49
|
|
990
|
+
};
|
|
991
|
+
const ITEM_FLING_EFFECTS = {
|
|
992
|
+
BADLY_POISON: 1,
|
|
993
|
+
BURN: 2,
|
|
994
|
+
BERRY_EFFECT: 3,
|
|
995
|
+
HERB_EFFECT: 4,
|
|
996
|
+
PARALYZE: 5,
|
|
997
|
+
POISON: 6,
|
|
998
|
+
FLINCH: 7
|
|
999
|
+
};
|
|
1000
|
+
const ITEM_POCKETS = {
|
|
1001
|
+
MISC: 1,
|
|
1002
|
+
MEDICINE: 2,
|
|
1003
|
+
POKEBALLS: 3,
|
|
1004
|
+
MACHINES: 4,
|
|
1005
|
+
BERRIES: 5,
|
|
1006
|
+
MAIL: 6,
|
|
1007
|
+
BATTLE: 7,
|
|
1008
|
+
KEY: 8
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
//#endregion
|
|
1012
|
+
//#region src/constants/locations.ts
|
|
1013
|
+
const REGIONS = {
|
|
1014
|
+
KANTO: 1,
|
|
1015
|
+
JOHTO: 2,
|
|
1016
|
+
HOENN: 3,
|
|
1017
|
+
SINNOH: 4,
|
|
1018
|
+
UNOVA: 5,
|
|
1019
|
+
KALOS: 6,
|
|
1020
|
+
ALOLA: 7,
|
|
1021
|
+
GALAR: 8,
|
|
1022
|
+
HISUI: 9,
|
|
1023
|
+
PALDEA: 10,
|
|
1024
|
+
ORRE: 11
|
|
1025
|
+
};
|
|
1026
|
+
const PAL_PARK_AREAS = {
|
|
1027
|
+
FOREST: 1,
|
|
1028
|
+
FIELD: 2,
|
|
1029
|
+
MOUNTAIN: 3,
|
|
1030
|
+
POND: 4,
|
|
1031
|
+
SEA: 5
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
//#endregion
|
|
1035
|
+
//#region src/constants/moves.ts
|
|
1036
|
+
const MOVE_AILMENTS = {
|
|
1037
|
+
UNKNOWN: -1,
|
|
1038
|
+
NONE: 0,
|
|
1039
|
+
PARALYSIS: 1,
|
|
1040
|
+
SLEEP: 2,
|
|
1041
|
+
FREEZE: 3,
|
|
1042
|
+
BURN: 4,
|
|
1043
|
+
POISON: 5,
|
|
1044
|
+
CONFUSION: 6,
|
|
1045
|
+
INFATUATION: 7,
|
|
1046
|
+
TRAP: 8,
|
|
1047
|
+
NIGHTMARE: 9,
|
|
1048
|
+
TORMENT: 12,
|
|
1049
|
+
DISABLE: 13,
|
|
1050
|
+
YAWN: 14,
|
|
1051
|
+
HEAL_BLOCK: 15,
|
|
1052
|
+
NO_TYPE_IMMUNITY: 17,
|
|
1053
|
+
LEECH_SEED: 18,
|
|
1054
|
+
EMBARGO: 19,
|
|
1055
|
+
PERISH_SONG: 20,
|
|
1056
|
+
INGRAIN: 21,
|
|
1057
|
+
SILENCE: 24,
|
|
1058
|
+
TAR_SHOT: 42,
|
|
1059
|
+
PROTECT: 43
|
|
1060
|
+
};
|
|
1061
|
+
const MOVE_BATTLE_STYLES = {
|
|
1062
|
+
ATTACK: 1,
|
|
1063
|
+
DEFENSE: 2,
|
|
1064
|
+
SUPPORT: 3
|
|
1065
|
+
};
|
|
1066
|
+
const MOVE_CATEGORIES = {
|
|
1067
|
+
DAMAGE: 0,
|
|
1068
|
+
AILMENT: 1,
|
|
1069
|
+
NET_GOOD_STATS: 2,
|
|
1070
|
+
HEAL: 3,
|
|
1071
|
+
DAMAGE_AILMENT: 4,
|
|
1072
|
+
SWAGGER: 5,
|
|
1073
|
+
DAMAGE_LOWER: 6,
|
|
1074
|
+
DAMAGE_RAISE: 7,
|
|
1075
|
+
DAMAGE_HEAL: 8,
|
|
1076
|
+
OHKO: 9,
|
|
1077
|
+
WHOLE_FIELD_EFFECT: 10,
|
|
1078
|
+
FIELD_EFFECT: 11,
|
|
1079
|
+
FORCE_SWITCH: 12,
|
|
1080
|
+
UNIQUE: 13
|
|
1081
|
+
};
|
|
1082
|
+
const MOVE_DAMAGE_CLASSES = {
|
|
1083
|
+
STATUS: 1,
|
|
1084
|
+
PHYSICAL: 2,
|
|
1085
|
+
SPECIAL: 3
|
|
1086
|
+
};
|
|
1087
|
+
const MOVE_LEARN_METHODS = {
|
|
1088
|
+
LEVEL_UP: 1,
|
|
1089
|
+
EGG: 2,
|
|
1090
|
+
TUTOR: 3,
|
|
1091
|
+
MACHINE: 4,
|
|
1092
|
+
STADIUM_SURFING_PIKACHU: 5,
|
|
1093
|
+
LIGHT_BALL_EGG: 6,
|
|
1094
|
+
COLOSSEUM_PURIFICATION: 7,
|
|
1095
|
+
XD_SHADOW: 8,
|
|
1096
|
+
XD_PURIFICATION: 9,
|
|
1097
|
+
FORM_CHANGE: 10,
|
|
1098
|
+
ZYGARDE_CUBE: 11,
|
|
1099
|
+
TRAIN: 12
|
|
1100
|
+
};
|
|
1101
|
+
const MOVE_TARGETS = {
|
|
1102
|
+
SPECIFIC_MOVE: 1,
|
|
1103
|
+
SELECTED_POKEMON_ME_FIRST: 2,
|
|
1104
|
+
ALLY: 3,
|
|
1105
|
+
USERS_FIELD: 4,
|
|
1106
|
+
USER_OR_ALLY: 5,
|
|
1107
|
+
OPPONENTS_FIELD: 6,
|
|
1108
|
+
USER: 7,
|
|
1109
|
+
RANDOM_OPPONENT: 8,
|
|
1110
|
+
ALL_OTHER_POKEMON: 9,
|
|
1111
|
+
SELECTED_POKEMON: 10,
|
|
1112
|
+
ALL_OPPONENTS: 11,
|
|
1113
|
+
ENTIRE_FIELD: 12,
|
|
1114
|
+
USER_AND_ALLIES: 13,
|
|
1115
|
+
ALL_POKEMON: 14,
|
|
1116
|
+
ALL_ALLIES: 15,
|
|
1117
|
+
FAINTING_POKEMON: 16,
|
|
1118
|
+
/**
|
|
1119
|
+
* @deprecated Misspelled: the endpoint names this `user-and-allies`.
|
|
1120
|
+
* Use {@link MOVE_TARGETS.USER_AND_ALLIES}. Removed in 3.0.
|
|
1121
|
+
*/
|
|
1122
|
+
USER_AND_ALIES: 13
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1125
|
+
//#endregion
|
|
1126
|
+
//#region src/constants/pokemon.ts
|
|
1127
|
+
const EGG_GROUPS = {
|
|
1128
|
+
MONSTER: 1,
|
|
1129
|
+
WATER1: 2,
|
|
1130
|
+
BUG: 3,
|
|
1131
|
+
FLYING: 4,
|
|
1132
|
+
GROUND: 5,
|
|
1133
|
+
FAIRY: 6,
|
|
1134
|
+
PLANT: 7,
|
|
1135
|
+
HUMANSHAPE: 8,
|
|
1136
|
+
WATER3: 9,
|
|
1137
|
+
MINERAL: 10,
|
|
1138
|
+
INDETERMINATE: 11,
|
|
1139
|
+
WATER2: 12,
|
|
1140
|
+
DITTO: 13,
|
|
1141
|
+
DRAGON: 14,
|
|
1142
|
+
NO_EGGS: 15
|
|
1143
|
+
};
|
|
1144
|
+
const GENDERS = {
|
|
1145
|
+
FEMALE: 1,
|
|
1146
|
+
MALE: 2,
|
|
1147
|
+
GENDERLESS: 3
|
|
1148
|
+
};
|
|
1149
|
+
const GROWTH_RATES = {
|
|
1150
|
+
SLOW: 1,
|
|
1151
|
+
MEDIUM: 2,
|
|
1152
|
+
FAST: 3,
|
|
1153
|
+
MEDIUM_SLOW: 4,
|
|
1154
|
+
SLOW_THEN_VERY_FAST: 5,
|
|
1155
|
+
FAST_THEN_VERY_SLOW: 6
|
|
1156
|
+
};
|
|
1157
|
+
const NATURES = {
|
|
1158
|
+
HARDY: 1,
|
|
1159
|
+
BOLD: 2,
|
|
1160
|
+
MODEST: 3,
|
|
1161
|
+
CALM: 4,
|
|
1162
|
+
TIMID: 5,
|
|
1163
|
+
LONELY: 6,
|
|
1164
|
+
DOCILE: 7,
|
|
1165
|
+
MILD: 8,
|
|
1166
|
+
GENTLE: 9,
|
|
1167
|
+
HASTY: 10,
|
|
1168
|
+
ADAMANT: 11,
|
|
1169
|
+
IMPISH: 12,
|
|
1170
|
+
BASHFUL: 13,
|
|
1171
|
+
CAREFUL: 14,
|
|
1172
|
+
RASH: 15,
|
|
1173
|
+
JOLLY: 16,
|
|
1174
|
+
NAUGHTY: 17,
|
|
1175
|
+
LAX: 18,
|
|
1176
|
+
QUIRKY: 19,
|
|
1177
|
+
NAIVE: 20,
|
|
1178
|
+
BRAVE: 21,
|
|
1179
|
+
RELAXED: 22,
|
|
1180
|
+
QUIET: 23,
|
|
1181
|
+
SASSY: 24,
|
|
1182
|
+
SERIOUS: 25
|
|
1183
|
+
};
|
|
1184
|
+
const POKEATHLON_STATS = {
|
|
1185
|
+
SPEED: 1,
|
|
1186
|
+
POWER: 2,
|
|
1187
|
+
SKILL: 3,
|
|
1188
|
+
STAMINA: 4,
|
|
1189
|
+
JUMP: 5
|
|
1190
|
+
};
|
|
1191
|
+
const POKEMON_COLORS = {
|
|
1192
|
+
BLACK: 1,
|
|
1193
|
+
BLUE: 2,
|
|
1194
|
+
BROWN: 3,
|
|
1195
|
+
GRAY: 4,
|
|
1196
|
+
GREEN: 5,
|
|
1197
|
+
PINK: 6,
|
|
1198
|
+
PURPLE: 7,
|
|
1199
|
+
RED: 8,
|
|
1200
|
+
WHITE: 9,
|
|
1201
|
+
YELLOW: 10
|
|
1202
|
+
};
|
|
1203
|
+
const POKEMON_HABITATS = {
|
|
1204
|
+
CAVE: 1,
|
|
1205
|
+
FOREST: 2,
|
|
1206
|
+
GRASSLAND: 3,
|
|
1207
|
+
MOUNTAIN: 4,
|
|
1208
|
+
RARE: 5,
|
|
1209
|
+
ROUGH_TERRAIN: 6,
|
|
1210
|
+
SEA: 7,
|
|
1211
|
+
URBAN: 8,
|
|
1212
|
+
WATERS_EDGE: 9,
|
|
1213
|
+
/**
|
|
1214
|
+
* @deprecated Misspelled: the endpoint names this `mountain`.
|
|
1215
|
+
* Use {@link POKEMON_HABITATS.MOUNTAIN}. Removed in 3.0.
|
|
1216
|
+
*/
|
|
1217
|
+
MONTAIN: 4
|
|
1218
|
+
};
|
|
1219
|
+
const POKEMON_SHAPES = {
|
|
1220
|
+
BALL: 1,
|
|
1221
|
+
SQUIGGLE: 2,
|
|
1222
|
+
FISH: 3,
|
|
1223
|
+
ARMS: 4,
|
|
1224
|
+
BLOB: 5,
|
|
1225
|
+
UPRIGHT: 6,
|
|
1226
|
+
LEGS: 7,
|
|
1227
|
+
QUADRUPED: 8,
|
|
1228
|
+
WINGS: 9,
|
|
1229
|
+
TENTACLES: 10,
|
|
1230
|
+
HEADS: 11,
|
|
1231
|
+
HUMANOID: 12,
|
|
1232
|
+
BUG_WINGS: 13,
|
|
1233
|
+
ARMOR: 14
|
|
1234
|
+
};
|
|
1235
|
+
const STATS = {
|
|
1236
|
+
HP: 1,
|
|
1237
|
+
ATTACK: 2,
|
|
1238
|
+
DEFENSE: 3,
|
|
1239
|
+
SPECIAL_ATTACK: 4,
|
|
1240
|
+
SPECIAL_DEFENSE: 5,
|
|
1241
|
+
SPEED: 6,
|
|
1242
|
+
ACCURACY: 7,
|
|
1243
|
+
EVASION: 8,
|
|
1244
|
+
SPECIAL: 9
|
|
1245
|
+
};
|
|
1246
|
+
const TYPES = {
|
|
1247
|
+
NORMAL: 1,
|
|
1248
|
+
FIGHTING: 2,
|
|
1249
|
+
FLYING: 3,
|
|
1250
|
+
POISON: 4,
|
|
1251
|
+
GROUND: 5,
|
|
1252
|
+
ROCK: 6,
|
|
1253
|
+
BUG: 7,
|
|
1254
|
+
GHOST: 8,
|
|
1255
|
+
STEEL: 9,
|
|
1256
|
+
FIRE: 10,
|
|
1257
|
+
WATER: 11,
|
|
1258
|
+
GRASS: 12,
|
|
1259
|
+
ELECTRIC: 13,
|
|
1260
|
+
PSYCHIC: 14,
|
|
1261
|
+
ICE: 15,
|
|
1262
|
+
DRAGON: 16,
|
|
1263
|
+
DARK: 17,
|
|
1264
|
+
FAIRY: 18,
|
|
1265
|
+
STELLAR: 19,
|
|
1266
|
+
UNKNOWN: 10001,
|
|
1267
|
+
SHADOW: 10002
|
|
1268
|
+
};
|
|
1269
|
+
|
|
1270
|
+
//#endregion
|
|
1271
|
+
//#region src/constants/urls.ts
|
|
1272
|
+
const BASE_URL = {
|
|
1273
|
+
REST: "https://pokeapi.co/api/v2",
|
|
1274
|
+
/** Root of the sprite repository the API's own sprite URLs point at. */
|
|
1275
|
+
SPRITES: "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites"
|
|
1276
|
+
};
|
|
1277
|
+
|
|
1278
|
+
//#endregion
|
|
1279
|
+
//#region src/constants/utilities.ts
|
|
1280
|
+
const LANGUAGES = {
|
|
1281
|
+
JA_HRKT: 1,
|
|
1282
|
+
JA_ROMA: 2,
|
|
1283
|
+
KO: 3,
|
|
1284
|
+
ZH_HANT: 4,
|
|
1285
|
+
FR: 5,
|
|
1286
|
+
DE: 6,
|
|
1287
|
+
ES: 7,
|
|
1288
|
+
IT: 8,
|
|
1289
|
+
EN: 9,
|
|
1290
|
+
CS: 10,
|
|
1291
|
+
JA: 11,
|
|
1292
|
+
ZH_HANS: 12,
|
|
1293
|
+
PT_BR: 13,
|
|
1294
|
+
ES_419: 14
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
//#endregion
|
|
1298
|
+
//#region src/constants/index.ts
|
|
1299
|
+
var constants_exports = /* @__PURE__ */ __exportAll({
|
|
1300
|
+
BASE_URL: () => BASE_URL,
|
|
1301
|
+
BERRIES: () => BERRIES,
|
|
1302
|
+
BERRY_FIRMNESSES: () => BERRY_FIRMNESSES,
|
|
1303
|
+
BERRY_FLAVORS: () => BERRY_FLAVORS,
|
|
1304
|
+
CONTEST_TYPES: () => CONTEST_TYPES,
|
|
1305
|
+
CURRENCIES: () => CURRENCIES,
|
|
1306
|
+
EGG_GROUPS: () => EGG_GROUPS,
|
|
1307
|
+
ENCOUNTER_CONDITIONS: () => ENCOUNTER_CONDITIONS,
|
|
1308
|
+
ENCOUNTER_CONDITION_VALUES: () => ENCOUNTER_CONDITION_VALUES,
|
|
1309
|
+
ENCOUNTER_METHODS: () => ENCOUNTER_METHODS,
|
|
1310
|
+
ENDPOINTS: () => ENDPOINTS,
|
|
1311
|
+
EVOLUTION_TRIGGERS: () => EVOLUTION_TRIGGERS,
|
|
1312
|
+
EVOLUTION_VARIABLES: () => EVOLUTION_VARIABLES,
|
|
1313
|
+
GENDERS: () => GENDERS,
|
|
1314
|
+
GENERATIONS: () => GENERATIONS,
|
|
1315
|
+
GROWTH_RATES: () => GROWTH_RATES,
|
|
1316
|
+
ITEM_ATTRIBUTES: () => ITEM_ATTRIBUTES,
|
|
1317
|
+
ITEM_CATEGORIES: () => ITEM_CATEGORIES,
|
|
1318
|
+
ITEM_FLING_EFFECTS: () => ITEM_FLING_EFFECTS,
|
|
1319
|
+
ITEM_POCKETS: () => ITEM_POCKETS,
|
|
1320
|
+
LANGUAGES: () => LANGUAGES,
|
|
1321
|
+
MOVE_AILMENTS: () => MOVE_AILMENTS,
|
|
1322
|
+
MOVE_BATTLE_STYLES: () => MOVE_BATTLE_STYLES,
|
|
1323
|
+
MOVE_CATEGORIES: () => MOVE_CATEGORIES,
|
|
1324
|
+
MOVE_DAMAGE_CLASSES: () => MOVE_DAMAGE_CLASSES,
|
|
1325
|
+
MOVE_LEARN_METHODS: () => MOVE_LEARN_METHODS,
|
|
1326
|
+
MOVE_TARGETS: () => MOVE_TARGETS,
|
|
1327
|
+
NATURES: () => NATURES,
|
|
1328
|
+
PAL_PARK_AREAS: () => PAL_PARK_AREAS,
|
|
1329
|
+
POKEATHLON_STATS: () => POKEATHLON_STATS,
|
|
1330
|
+
POKEDEXES: () => POKEDEXES,
|
|
1331
|
+
POKEMON_COLORS: () => POKEMON_COLORS,
|
|
1332
|
+
POKEMON_HABITATS: () => POKEMON_HABITATS,
|
|
1333
|
+
POKEMON_SHAPES: () => POKEMON_SHAPES,
|
|
1334
|
+
REGIONS: () => REGIONS,
|
|
1335
|
+
STATS: () => STATS,
|
|
1336
|
+
TYPES: () => TYPES,
|
|
1337
|
+
VERSIONS: () => VERSIONS,
|
|
1338
|
+
VERSION_GROUPS: () => VERSION_GROUPS
|
|
1339
|
+
});
|
|
1340
|
+
|
|
1341
|
+
//#endregion
|
|
1342
|
+
//#region src/config/cache.ts
|
|
1343
|
+
/** Five minutes. */
|
|
1344
|
+
const DEFAULT_TTL = 3e5;
|
|
1345
|
+
const DEFAULT_MAX_ENTRIES = 500;
|
|
1346
|
+
/** Default namespace for the keys {@link WebStorageCache} owns. */
|
|
1347
|
+
const DEFAULT_PREFIX = "pokenode:";
|
|
1348
|
+
/**
|
|
1349
|
+
* How many entries a bounded store keeps.
|
|
1350
|
+
*
|
|
1351
|
+
* A non-finite limit falls back to the default rather than being clamped:
|
|
1352
|
+
* `size >= NaN` is never true, and a bound that is never reached is not a bound
|
|
1353
|
+
* — `maxEntries` is exactly the sort of option that arrives as
|
|
1354
|
+
* `Number(process.env.CACHE_SIZE)`. Zero and below keep nothing.
|
|
1355
|
+
*/
|
|
1356
|
+
const entryLimit = (value, fallback) => value !== void 0 && Number.isFinite(value) ? Math.max(Math.floor(value), 0) : fallback;
|
|
1357
|
+
/**
|
|
1358
|
+
* ## Memory Cache
|
|
1359
|
+
* The default {@link CacheStore}: a bounded, time-to-live cache held in memory.
|
|
1360
|
+
*
|
|
1361
|
+
* Values are stored and returned by reference — mutating a response also mutates
|
|
1362
|
+
* what later cache hits return, so treat responses as read-only.
|
|
1363
|
+
*/
|
|
1364
|
+
var MemoryCache = class {
|
|
1365
|
+
entries = /* @__PURE__ */ new Map();
|
|
1366
|
+
ttl;
|
|
1367
|
+
maxEntries;
|
|
1368
|
+
constructor(options) {
|
|
1369
|
+
this.ttl = options?.ttl ?? DEFAULT_TTL;
|
|
1370
|
+
this.maxEntries = entryLimit(options?.maxEntries, DEFAULT_MAX_ENTRIES);
|
|
1371
|
+
}
|
|
1372
|
+
get(key) {
|
|
1373
|
+
const entry = this.entries.get(key);
|
|
1374
|
+
if (!entry) return;
|
|
1375
|
+
if (entry.expiresAt <= Date.now()) {
|
|
1376
|
+
this.entries.delete(key);
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
this.entries.delete(key);
|
|
1380
|
+
this.entries.set(key, entry);
|
|
1381
|
+
return entry.value;
|
|
1382
|
+
}
|
|
1383
|
+
set(key, value) {
|
|
1384
|
+
this.entries.delete(key);
|
|
1385
|
+
if (this.maxEntries === 0) return;
|
|
1386
|
+
if (this.entries.size >= this.maxEntries) {
|
|
1387
|
+
const oldest = this.entries.keys().next();
|
|
1388
|
+
if (!oldest.done) this.entries.delete(oldest.value);
|
|
1389
|
+
}
|
|
1390
|
+
this.entries.set(key, {
|
|
1391
|
+
value,
|
|
1392
|
+
expiresAt: Date.now() + this.ttl
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
delete(key) {
|
|
1396
|
+
this.entries.delete(key);
|
|
1397
|
+
}
|
|
1398
|
+
clear() {
|
|
1399
|
+
this.entries.clear();
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
/** How many URLs an {@link EtagStore} remembers before evicting the oldest. */
|
|
1403
|
+
const DEFAULT_ETAG_ENTRIES = 500;
|
|
1404
|
+
/**
|
|
1405
|
+
* ## Etag Store
|
|
1406
|
+
* Remembers the `ETag` each URL answered with, and the body it identified, so an
|
|
1407
|
+
* expired cache entry can be revalidated instead of downloaded again.
|
|
1408
|
+
*
|
|
1409
|
+
* Deliberately not a {@link CacheStore}: the two answer different questions. A
|
|
1410
|
+
* `CacheStore` says "this response is still fresh, use it"; this says "here is
|
|
1411
|
+
* what the response was last time, ask the server whether it still holds". They
|
|
1412
|
+
* are kept apart so that a store someone else owns — a shared Redis — is never
|
|
1413
|
+
* given a second key shape, and `cache.get(url)` keeps returning the resource
|
|
1414
|
+
* itself.
|
|
1415
|
+
*
|
|
1416
|
+
* Entries live in memory and are never persisted: an `ETag` is only worth what
|
|
1417
|
+
* the body beside it is, and the body is what would cost memory to keep.
|
|
1418
|
+
*/
|
|
1419
|
+
var EtagStore = class {
|
|
1420
|
+
entries = /* @__PURE__ */ new Map();
|
|
1421
|
+
maxEntries;
|
|
1422
|
+
constructor(options) {
|
|
1423
|
+
this.maxEntries = entryLimit(options?.maxEntries, DEFAULT_ETAG_ENTRIES);
|
|
1424
|
+
}
|
|
1425
|
+
get(url) {
|
|
1426
|
+
const entry = this.entries.get(url);
|
|
1427
|
+
if (!entry) return;
|
|
1428
|
+
this.entries.delete(url);
|
|
1429
|
+
this.entries.set(url, entry);
|
|
1430
|
+
return entry;
|
|
1431
|
+
}
|
|
1432
|
+
set(url, entry) {
|
|
1433
|
+
this.entries.delete(url);
|
|
1434
|
+
if (this.maxEntries === 0) return;
|
|
1435
|
+
if (this.entries.size >= this.maxEntries) {
|
|
1436
|
+
const oldest = this.entries.keys().next();
|
|
1437
|
+
if (!oldest.done) this.entries.delete(oldest.value);
|
|
1438
|
+
}
|
|
1439
|
+
this.entries.set(url, entry);
|
|
1440
|
+
}
|
|
1441
|
+
clear() {
|
|
1442
|
+
this.entries.clear();
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
/**
|
|
1446
|
+
* ## Web Storage Cache
|
|
1447
|
+
* A {@link CacheStore} backed by `localStorage` or `sessionStorage`, so a cached
|
|
1448
|
+
* response survives a page reload.
|
|
1449
|
+
*
|
|
1450
|
+
* ```ts
|
|
1451
|
+
* const api = new PokemonClient({ cache: new WebStorageCache({ storage: localStorage }) });
|
|
1452
|
+
* ```
|
|
1453
|
+
*
|
|
1454
|
+
* Only keys under {@link WebStorageCacheOptions.prefix} are ever read, evicted or
|
|
1455
|
+
* cleared — the storage is assumed to be shared with the surrounding application.
|
|
1456
|
+
*
|
|
1457
|
+
* Values round-trip through JSON, so unlike {@link MemoryCache} every hit returns a
|
|
1458
|
+
* fresh copy. Anything a `JSON.stringify` cannot represent does not survive, which
|
|
1459
|
+
* covers every PokéAPI response.
|
|
1460
|
+
*
|
|
1461
|
+
* A storage that throws instead of answering is treated as empty: a read is a miss
|
|
1462
|
+
* and a write is dropped, because neither is worth failing the request that
|
|
1463
|
+
* triggered it over.
|
|
1464
|
+
*/
|
|
1465
|
+
var WebStorageCache = class {
|
|
1466
|
+
storage;
|
|
1467
|
+
ttl;
|
|
1468
|
+
prefix;
|
|
1469
|
+
constructor(options) {
|
|
1470
|
+
this.storage = options.storage;
|
|
1471
|
+
this.ttl = options.ttl ?? DEFAULT_TTL;
|
|
1472
|
+
this.prefix = options.prefix ?? DEFAULT_PREFIX;
|
|
1473
|
+
}
|
|
1474
|
+
async get(key) {
|
|
1475
|
+
const entry = await this.read(this.prefix + key);
|
|
1476
|
+
if (!entry) return;
|
|
1477
|
+
if (entry.expiresAt <= Date.now()) {
|
|
1478
|
+
await this.remove(this.prefix + key);
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
return entry.value;
|
|
1482
|
+
}
|
|
1483
|
+
async set(key, value) {
|
|
1484
|
+
const entry = JSON.stringify({
|
|
1485
|
+
value,
|
|
1486
|
+
expiresAt: Date.now() + this.ttl
|
|
1487
|
+
});
|
|
1488
|
+
try {
|
|
1489
|
+
await this.storage.setItem(this.prefix + key, entry);
|
|
1490
|
+
} catch {
|
|
1491
|
+
await this.evict();
|
|
1492
|
+
try {
|
|
1493
|
+
await this.storage.setItem(this.prefix + key, entry);
|
|
1494
|
+
} catch {
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
async delete(key) {
|
|
1500
|
+
await this.storage.removeItem(this.prefix + key);
|
|
1501
|
+
}
|
|
1502
|
+
async clear() {
|
|
1503
|
+
for (const key of await this.ownKeys()) await this.remove(key);
|
|
1504
|
+
}
|
|
1505
|
+
/** Reads a namespaced key, treating unreadable content as a miss. */
|
|
1506
|
+
async read(key) {
|
|
1507
|
+
let stored;
|
|
1508
|
+
try {
|
|
1509
|
+
stored = await this.storage.getItem(key);
|
|
1510
|
+
} catch {
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1513
|
+
if (stored === null) return;
|
|
1514
|
+
try {
|
|
1515
|
+
return JSON.parse(stored);
|
|
1516
|
+
} catch {
|
|
1517
|
+
await this.remove(key);
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Frees space by dropping expired entries, falling back to the ones closest to
|
|
1523
|
+
* expiring when nothing has expired yet.
|
|
1524
|
+
*/
|
|
1525
|
+
async evict() {
|
|
1526
|
+
const keys = await this.ownKeys();
|
|
1527
|
+
const entries = await Promise.all(keys.map(async (key) => ({
|
|
1528
|
+
key,
|
|
1529
|
+
expiresAt: (await this.read(key))?.expiresAt
|
|
1530
|
+
})));
|
|
1531
|
+
const now = Date.now();
|
|
1532
|
+
const expired = entries.filter(({ expiresAt }) => expiresAt === void 0 || expiresAt <= now);
|
|
1533
|
+
if (expired.length > 0) {
|
|
1534
|
+
for (const { key } of expired) await this.remove(key);
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
const soonest = entries.sort((a, b) => (a.expiresAt ?? 0) - (b.expiresAt ?? 0));
|
|
1538
|
+
for (const { key } of soonest.slice(0, Math.ceil(soonest.length / 4))) await this.remove(key);
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Collects this store's keys before any removal: `key(index)` walks a list that
|
|
1542
|
+
* shifts underneath a loop that deletes as it goes.
|
|
1543
|
+
*/
|
|
1544
|
+
async ownKeys() {
|
|
1545
|
+
return (await this.allKeys()).filter((key) => key.startsWith(this.prefix));
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Every key the storage holds, however it is willing to list them. A storage
|
|
1549
|
+
* offering no enumeration at all reports none, which leaves eviction and
|
|
1550
|
+
* `clear` as no-ops rather than an error on a path that only tidies up.
|
|
1551
|
+
*/
|
|
1552
|
+
async allKeys() {
|
|
1553
|
+
try {
|
|
1554
|
+
if (this.storage.getAllKeys !== void 0) return [...await this.storage.getAllKeys()];
|
|
1555
|
+
const { key, length } = this.storage;
|
|
1556
|
+
if (key === void 0 || length === void 0) return [];
|
|
1557
|
+
const keys = [];
|
|
1558
|
+
for (let index = 0; index < length; index += 1) {
|
|
1559
|
+
const found = key.call(this.storage, index);
|
|
1560
|
+
if (found !== null) keys.push(found);
|
|
1561
|
+
}
|
|
1562
|
+
return keys;
|
|
1563
|
+
} catch {
|
|
1564
|
+
return [];
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
/** Removes a key on a path that is only tidying up, where a refusal is moot. */
|
|
1568
|
+
async remove(key) {
|
|
1569
|
+
try {
|
|
1570
|
+
await this.storage.removeItem(key);
|
|
1571
|
+
} catch {}
|
|
1572
|
+
}
|
|
1573
|
+
};
|
|
1574
|
+
|
|
1575
|
+
//#endregion
|
|
1576
|
+
//#region src/config/errors.ts
|
|
1577
|
+
/**
|
|
1578
|
+
* Brands the error, so the guard can match on it instead of the prototype chain:
|
|
1579
|
+
* a tree loading both the ESM and the CJS build has two distinct classes.
|
|
1580
|
+
*/
|
|
1581
|
+
const ERROR_KIND = "pokenode:http";
|
|
1582
|
+
/**
|
|
1583
|
+
* ## Pokenode Error
|
|
1584
|
+
* Thrown when the PokéAPI answers with a non-2xx status. Transport failures are
|
|
1585
|
+
* not wrapped — the native error propagates untouched.
|
|
1586
|
+
*/
|
|
1587
|
+
var PokenodeError = class extends Error {
|
|
1588
|
+
name = "PokenodeError";
|
|
1589
|
+
kind = ERROR_KIND;
|
|
1590
|
+
/** HTTP status code of the response. */
|
|
1591
|
+
status;
|
|
1592
|
+
/** HTTP status text of the response. */
|
|
1593
|
+
statusText;
|
|
1594
|
+
/** URL that produced the error. */
|
|
1595
|
+
url;
|
|
1596
|
+
/** Parsed response body, when the error response carried JSON. */
|
|
1597
|
+
body;
|
|
1598
|
+
/**
|
|
1599
|
+
* @param message Overrides the default text, for a status whose failure is not
|
|
1600
|
+
* self-explanatory.
|
|
1601
|
+
*/
|
|
1602
|
+
constructor(response, body, message) {
|
|
1603
|
+
super(message ?? `Request to ${response.url} failed with status ${response.status}`);
|
|
1604
|
+
this.status = response.status;
|
|
1605
|
+
this.statusText = response.statusText;
|
|
1606
|
+
this.url = response.url;
|
|
1607
|
+
this.body = body;
|
|
1608
|
+
}
|
|
1609
|
+
/** Whether the error came from a pokenode-ts client. */
|
|
1610
|
+
static isPokenodeError(error) {
|
|
1611
|
+
return typeof error === "object" && error !== null && "kind" in error && error.kind === ERROR_KIND;
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
/**
|
|
1615
|
+
* Builds a {@link PokenodeError} from a failed response, reading the body when
|
|
1616
|
+
* it is JSON. The PokéAPI answers 404s with plain text, so a parse failure is
|
|
1617
|
+
* expected and leaves `body` undefined.
|
|
1618
|
+
*/
|
|
1619
|
+
const toPokenodeError = async (response, message) => {
|
|
1620
|
+
let body;
|
|
1621
|
+
try {
|
|
1622
|
+
body = await response.json();
|
|
1623
|
+
} catch {
|
|
1624
|
+
body = void 0;
|
|
1625
|
+
}
|
|
1626
|
+
return new PokenodeError(response, body, message);
|
|
1627
|
+
};
|
|
1628
|
+
|
|
1629
|
+
//#endregion
|
|
1630
|
+
//#region src/config/logger.ts
|
|
1631
|
+
/**
|
|
1632
|
+
* Builds the message keys both logging families expect. Internal — the payload
|
|
1633
|
+
* types are the public contract.
|
|
1634
|
+
*/
|
|
1635
|
+
const logMessage = (text) => ({
|
|
1636
|
+
msg: text,
|
|
1637
|
+
message: text
|
|
1638
|
+
});
|
|
1639
|
+
/**
|
|
1640
|
+
* A {@link Logger} that writes the request lifecycle to the console as one
|
|
1641
|
+
* formatted line per event.
|
|
1642
|
+
*
|
|
1643
|
+
* `console` itself is a valid {@link Logger} and logs the payload as an object;
|
|
1644
|
+
* this is for when the terminal should stay readable.
|
|
1645
|
+
*/
|
|
1646
|
+
const consoleLogger = {
|
|
1647
|
+
debug(payload) {
|
|
1648
|
+
if (payload.event === "request") {
|
|
1649
|
+
console.log(`[ Request Config ] ${payload.method} | ${payload.url}`);
|
|
1650
|
+
return;
|
|
1651
|
+
}
|
|
1652
|
+
if (payload.event === "retry") {
|
|
1653
|
+
console.log(`[ Retry ] ATTEMPT ${payload.attempt} | STATUS ${payload.status ?? "NONE"} | IN ${payload.delayMs.toFixed(0)}ms | ${payload.url}`);
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
if (payload.event === "cancelled") {
|
|
1657
|
+
console.log(`[ Cancelled ] ${payload.url} | AFTER ${payload.durationMs.toFixed(1)}ms`);
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
console.log(`[ Response ] STATUS ${payload.status} | ${payload.source.toUpperCase()} | ${payload.durationMs.toFixed(1)}ms`);
|
|
1661
|
+
},
|
|
1662
|
+
error({ url, err }) {
|
|
1663
|
+
const { name, message } = err instanceof Error ? err : {
|
|
1664
|
+
name: "UNKNOWN",
|
|
1665
|
+
message: String(err)
|
|
1666
|
+
};
|
|
1667
|
+
console.error(`[ Response Error ] ${url} | CODE ${name} | ${message}`);
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
|
|
1671
|
+
//#endregion
|
|
1672
|
+
//#region src/internal/inflight.ts
|
|
1673
|
+
/**
|
|
1674
|
+
* ## In Flight
|
|
1675
|
+
* The requests currently on the wire, keyed by URL, so concurrent callers asking
|
|
1676
|
+
* for the same one share a single round trip.
|
|
1677
|
+
*
|
|
1678
|
+
* Held by a transport's shared state and passed by reference, so a scoped
|
|
1679
|
+
* transport joins the requests already running rather than starting its own.
|
|
1680
|
+
*
|
|
1681
|
+
* Internal, and deliberately ignorant of what a request resolves to: it owns the
|
|
1682
|
+
* bookkeeping — who is still waiting, who may cancel, when an entry is forgotten
|
|
1683
|
+
* — and nothing about HTTP.
|
|
1684
|
+
*/
|
|
1685
|
+
var InFlight = class {
|
|
1686
|
+
requests = /* @__PURE__ */ new Map();
|
|
1687
|
+
/**
|
|
1688
|
+
* Resolves `key` through the request already running for it, or through a new
|
|
1689
|
+
* one started by `start`.
|
|
1690
|
+
*
|
|
1691
|
+
* `start` is handed the signal to cancel with, which is not the caller's: the
|
|
1692
|
+
* callers sharing a request come and go, and only the last one to leave may
|
|
1693
|
+
* cancel it.
|
|
1694
|
+
*/
|
|
1695
|
+
async share(key, signal, start) {
|
|
1696
|
+
const pending = this.requests.get(key);
|
|
1697
|
+
const entry = pending ?? this.dispatch(key, signal, start);
|
|
1698
|
+
return {
|
|
1699
|
+
value: await this.join(key, entry, signal),
|
|
1700
|
+
joined: pending !== void 0
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
/** Issues a request and remembers it, so a concurrent caller can share it. */
|
|
1704
|
+
dispatch(key, signal, start) {
|
|
1705
|
+
const controller = signal ? new AbortController() : void 0;
|
|
1706
|
+
const entry = {
|
|
1707
|
+
promise: start(controller?.signal),
|
|
1708
|
+
controller,
|
|
1709
|
+
waiters: 0
|
|
1710
|
+
};
|
|
1711
|
+
entry.promise = entry.promise.finally(() => this.release(key, entry));
|
|
1712
|
+
entry.promise.catch(() => {});
|
|
1713
|
+
this.requests.set(key, entry);
|
|
1714
|
+
return entry;
|
|
1715
|
+
}
|
|
1716
|
+
/**
|
|
1717
|
+
* Forgets a request, unless a later caller has already replaced it: a request
|
|
1718
|
+
* that was aborted leaves the map before it settles, and the one dispatched in
|
|
1719
|
+
* its place must survive its predecessor finishing.
|
|
1720
|
+
*/
|
|
1721
|
+
release(key, entry) {
|
|
1722
|
+
if (this.requests.get(key) === entry) this.requests.delete(key);
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* Awaits a request, cancelling it if this caller was the last one interested.
|
|
1726
|
+
*
|
|
1727
|
+
* A caller with no signal never leaves early, so it holds the request open for
|
|
1728
|
+
* everyone — including a scoped caller that joined later and gave up.
|
|
1729
|
+
*/
|
|
1730
|
+
join(key, entry, signal) {
|
|
1731
|
+
entry.waiters += 1;
|
|
1732
|
+
if (!signal) return entry.promise;
|
|
1733
|
+
return new Promise((resolve, reject) => {
|
|
1734
|
+
const leave = () => {
|
|
1735
|
+
entry.waiters -= 1;
|
|
1736
|
+
if (entry.waiters > 0) return;
|
|
1737
|
+
this.release(key, entry);
|
|
1738
|
+
entry.controller?.abort(signal.reason);
|
|
1739
|
+
};
|
|
1740
|
+
if (signal.aborted) {
|
|
1741
|
+
leave();
|
|
1742
|
+
reject(signal.reason);
|
|
1743
|
+
return;
|
|
1744
|
+
}
|
|
1745
|
+
const onAbort = () => {
|
|
1746
|
+
leave();
|
|
1747
|
+
reject(signal.reason);
|
|
1748
|
+
};
|
|
1749
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1750
|
+
entry.promise.then((value) => {
|
|
1751
|
+
signal.removeEventListener("abort", onAbort);
|
|
1752
|
+
resolve(value);
|
|
1753
|
+
}, (error) => {
|
|
1754
|
+
signal.removeEventListener("abort", onAbort);
|
|
1755
|
+
reject(error);
|
|
1756
|
+
});
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
|
|
1761
|
+
//#endregion
|
|
1762
|
+
//#region src/internal/pool.ts
|
|
1763
|
+
/**
|
|
1764
|
+
* How many requests the helpers that fetch many resources at once will run in
|
|
1765
|
+
* parallel. Kept low on purpose: see the PokéAPI fair-use policy.
|
|
1766
|
+
*/
|
|
1767
|
+
const DEFAULT_CONCURRENCY = 4;
|
|
1768
|
+
/**
|
|
1769
|
+
* Runs `task` over `items` with at most `concurrency` of them in flight, and
|
|
1770
|
+
* returns the results in the order the items came in.
|
|
1771
|
+
*
|
|
1772
|
+
* Internal: the PokéAPI's fair-use policy asks clients not to flood it, so the
|
|
1773
|
+
* places that resolve many links at once go through here rather than
|
|
1774
|
+
* `Promise.all`.
|
|
1775
|
+
*
|
|
1776
|
+
* The first failure stops the pool — workers check before taking more work, so
|
|
1777
|
+
* a rejection does not leave a tail of requests running for a result nobody will
|
|
1778
|
+
* read.
|
|
1779
|
+
*/
|
|
1780
|
+
const mapWithConcurrency = async (items, concurrency, task) => {
|
|
1781
|
+
const results = new Array(items.length);
|
|
1782
|
+
let cursor = 0;
|
|
1783
|
+
let failed = false;
|
|
1784
|
+
const worker = async () => {
|
|
1785
|
+
while (cursor < items.length && !failed) {
|
|
1786
|
+
const index = cursor;
|
|
1787
|
+
cursor += 1;
|
|
1788
|
+
try {
|
|
1789
|
+
results[index] = await task(items[index]);
|
|
1790
|
+
} catch (error) {
|
|
1791
|
+
failed = true;
|
|
1792
|
+
throw error;
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
};
|
|
1796
|
+
const requested = Number.isFinite(concurrency) ? concurrency : 4;
|
|
1797
|
+
const workers = Array.from({ length: Math.min(Math.max(requested, 1), items.length) }, () => worker());
|
|
1798
|
+
await Promise.all(workers);
|
|
1799
|
+
return results;
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1802
|
+
//#endregion
|
|
1803
|
+
//#region src/internal/paginate.ts
|
|
1804
|
+
/**
|
|
1805
|
+
* The PokéAPI's own default, and `Transport.list`'s, so a walk pages the way a
|
|
1806
|
+
* hand-written loop would.
|
|
1807
|
+
*/
|
|
1808
|
+
const DEFAULT_PAGE_SIZE = 20;
|
|
1809
|
+
/**
|
|
1810
|
+
* Walks every page of a list, yielding one entry at a time.
|
|
1811
|
+
*
|
|
1812
|
+
* `resolve` is passed in rather than a transport: this module would otherwise
|
|
1813
|
+
* have to import the one that imports it.
|
|
1814
|
+
*/
|
|
1815
|
+
async function* walk(list, resolve, options) {
|
|
1816
|
+
const pageSize = options?.pageSize ?? 20;
|
|
1817
|
+
const concurrency = options?.concurrency ?? 4;
|
|
1818
|
+
let offset = 0;
|
|
1819
|
+
while (true) {
|
|
1820
|
+
const page = await list(offset, pageSize);
|
|
1821
|
+
if (page.results.length === 0) return;
|
|
1822
|
+
if (options?.resolve) yield* await mapWithConcurrency(page.results, concurrency, resolve);
|
|
1823
|
+
else yield* page.results;
|
|
1824
|
+
offset += page.results.length;
|
|
1825
|
+
if (page.results.length < pageSize || offset >= page.count) return;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
//#endregion
|
|
1830
|
+
//#region src/internal/retry.ts
|
|
1831
|
+
const DEFAULT_RETRY_ATTEMPTS = 3;
|
|
1832
|
+
const DEFAULT_INITIAL_DELAY = 300;
|
|
1833
|
+
const DEFAULT_MAX_DELAY = 5e3;
|
|
1834
|
+
/** Transient by definition: rate limiting, and the gateway failures around it. */
|
|
1835
|
+
const DEFAULT_RETRY_STATUSES = [
|
|
1836
|
+
429,
|
|
1837
|
+
500,
|
|
1838
|
+
502,
|
|
1839
|
+
503,
|
|
1840
|
+
504
|
|
1841
|
+
];
|
|
1842
|
+
/**
|
|
1843
|
+
* How many attempts a request gets, the first one included. A fractional count
|
|
1844
|
+
* is rounded down, so `2.5` is two attempts rather than the three that
|
|
1845
|
+
* `attempt >= attempts` would otherwise allow.
|
|
1846
|
+
*
|
|
1847
|
+
* A non-finite count falls back to the default rather than being clamped:
|
|
1848
|
+
* `Math.max(NaN, 1)` is `NaN`, and an attempt loop bounded by `NaN` never ends.
|
|
1849
|
+
* `attempts` is exactly the sort of option that arrives as
|
|
1850
|
+
* `Number(process.env.RETRIES)`.
|
|
1851
|
+
*/
|
|
1852
|
+
const attemptCount = (retry) => {
|
|
1853
|
+
if (!retry) return 1;
|
|
1854
|
+
const requested = retry.attempts ?? DEFAULT_RETRY_ATTEMPTS;
|
|
1855
|
+
return Number.isFinite(requested) ? Math.max(Math.floor(requested), 1) : DEFAULT_RETRY_ATTEMPTS;
|
|
1856
|
+
};
|
|
1857
|
+
/**
|
|
1858
|
+
* A configured wait, in milliseconds, or the default when it is not a number
|
|
1859
|
+
* this client can wait for.
|
|
1860
|
+
*
|
|
1861
|
+
* A non-finite value falls back for the reason given on {@link attemptCount}:
|
|
1862
|
+
* `setTimeout` reads a `NaN` delay as zero, and `x > NaN` is false, so an
|
|
1863
|
+
* unusable option spends every attempt at once — or accepts any `Retry-After`
|
|
1864
|
+
* it is sent.
|
|
1865
|
+
*/
|
|
1866
|
+
const delayOption = (value, fallback) => value !== void 0 && Number.isFinite(value) ? Math.max(value, 0) : fallback;
|
|
1867
|
+
/**
|
|
1868
|
+
* Reads `Retry-After`, which RFC 9110 allows to be either a number of seconds or
|
|
1869
|
+
* an HTTP date. Returns milliseconds, or nothing when the header is absent or
|
|
1870
|
+
* unparseable.
|
|
1871
|
+
*/
|
|
1872
|
+
const toRetryAfterMs = (header) => {
|
|
1873
|
+
if (header === null) return;
|
|
1874
|
+
const value = header.trim();
|
|
1875
|
+
if (value === "") return;
|
|
1876
|
+
const seconds = Number(value);
|
|
1877
|
+
if (Number.isFinite(seconds)) return Math.max(seconds, 0) * 1e3;
|
|
1878
|
+
const date = Date.parse(value);
|
|
1879
|
+
return Number.isNaN(date) ? void 0 : Math.max(date - Date.now(), 0);
|
|
1880
|
+
};
|
|
1881
|
+
/**
|
|
1882
|
+
* Whether an error is a request being cancelled rather than failing. A cancelled
|
|
1883
|
+
* request is never retried: someone asked for it to stop.
|
|
1884
|
+
*/
|
|
1885
|
+
const isAbort = (error, signal) => signal?.aborted === true || error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
|
|
1886
|
+
/** Waits, unless the request is cancelled first. */
|
|
1887
|
+
const sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
1888
|
+
if (signal?.aborted) {
|
|
1889
|
+
reject(signal.reason);
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
const timer = setTimeout(() => {
|
|
1893
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1894
|
+
resolve();
|
|
1895
|
+
}, ms);
|
|
1896
|
+
timer.unref?.();
|
|
1897
|
+
const onAbort = () => {
|
|
1898
|
+
clearTimeout(timer);
|
|
1899
|
+
reject(signal?.reason);
|
|
1900
|
+
};
|
|
1901
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1902
|
+
});
|
|
1903
|
+
/**
|
|
1904
|
+
* How long `Retry-After` asks this client to wait, or nothing when the wait is
|
|
1905
|
+
* {@link backoff}'s to calculate.
|
|
1906
|
+
*
|
|
1907
|
+
* @throws {PokenodeError} If the failure is not one this client attempts again.
|
|
1908
|
+
*/
|
|
1909
|
+
const retryDelay = async (response, isLast, retry) => {
|
|
1910
|
+
const statuses = retry?.statuses ?? DEFAULT_RETRY_STATUSES;
|
|
1911
|
+
const maxDelay = delayOption(retry?.maxDelay, DEFAULT_MAX_DELAY);
|
|
1912
|
+
if (isLast || !statuses.includes(response.status)) throw await toPokenodeError(response);
|
|
1913
|
+
const retryAfter = toRetryAfterMs(response.headers.get("Retry-After"));
|
|
1914
|
+
if (retryAfter !== void 0 && retryAfter > maxDelay) throw await toPokenodeError(response);
|
|
1915
|
+
return retryAfter;
|
|
1916
|
+
};
|
|
1917
|
+
/**
|
|
1918
|
+
* Waits before the next attempt, and says so through the logger.
|
|
1919
|
+
*
|
|
1920
|
+
* The wait is half of a doubling window plus jitter over the other half, so
|
|
1921
|
+
* clients that failed together do not come back together, and none of them
|
|
1922
|
+
* comes back immediately. `Retry-After` replaces the calculation outright.
|
|
1923
|
+
*/
|
|
1924
|
+
const backoff = async (options) => {
|
|
1925
|
+
const { url, attempt, status, retryAfter, signal, retry, logger } = options;
|
|
1926
|
+
const initialDelay = delayOption(retry?.initialDelay, DEFAULT_INITIAL_DELAY);
|
|
1927
|
+
const maxDelay = delayOption(retry?.maxDelay, DEFAULT_MAX_DELAY);
|
|
1928
|
+
const window = Math.min(initialDelay * 2 ** (attempt - 1), maxDelay);
|
|
1929
|
+
const delayMs = retryAfter ?? window / 2 + Math.random() * (window / 2);
|
|
1930
|
+
logger?.debug({
|
|
1931
|
+
event: "retry",
|
|
1932
|
+
...logMessage("pokeapi request failed, retrying"),
|
|
1933
|
+
url,
|
|
1934
|
+
attempt,
|
|
1935
|
+
delayMs,
|
|
1936
|
+
...status === void 0 ? {} : { status }
|
|
1937
|
+
});
|
|
1938
|
+
await sleep(delayMs, signal);
|
|
1939
|
+
};
|
|
1940
|
+
|
|
1941
|
+
//#endregion
|
|
1942
|
+
//#region src/internal/url.ts
|
|
1943
|
+
/**
|
|
1944
|
+
* Scanned rather than matched with `/\/+$/`: that pattern backtracks through
|
|
1945
|
+
* every slash of a long run that turns out not to end the string, which is
|
|
1946
|
+
* quadratic on a URL an untrusted caller supplies. This walks each character
|
|
1947
|
+
* once.
|
|
1948
|
+
*/
|
|
1949
|
+
const trimTrailingSlash = (url) => {
|
|
1950
|
+
let end = url.length;
|
|
1951
|
+
while (end > 0 && url[end - 1] === "/") end -= 1;
|
|
1952
|
+
return url.slice(0, end);
|
|
1953
|
+
};
|
|
1954
|
+
/** Builds the paginated request path shared by both list methods. */
|
|
1955
|
+
const listPath = (endpoint, offset, limit) => {
|
|
1956
|
+
return `${endpoint}?${new URLSearchParams({
|
|
1957
|
+
offset: String(offset),
|
|
1958
|
+
limit: String(limit)
|
|
1959
|
+
})}`;
|
|
1960
|
+
};
|
|
1961
|
+
/**
|
|
1962
|
+
* Drops the trailing slash from a request URL, leaving any query string alone.
|
|
1963
|
+
*
|
|
1964
|
+
* Both call paths must produce one cache key: `Transport.resource` builds
|
|
1965
|
+
* `/berry/1`, while the PokéAPI's own links end in a slash.
|
|
1966
|
+
*
|
|
1967
|
+
* Split at the query rather than matched with a lookahead, for the reason given
|
|
1968
|
+
* on {@link trimTrailingSlash}.
|
|
1969
|
+
*/
|
|
1970
|
+
const normalizeURL = (url) => {
|
|
1971
|
+
const queryAt = url.indexOf("?");
|
|
1972
|
+
if (queryAt === -1) return trimTrailingSlash(url);
|
|
1973
|
+
return trimTrailingSlash(url.slice(0, queryAt)) + url.slice(queryAt);
|
|
1974
|
+
};
|
|
1975
|
+
/** A path segment naming an API version, as in `/api/v2/berry/1`. */
|
|
1976
|
+
const API_VERSION_SEGMENT = /^v\d+$/;
|
|
1977
|
+
/**
|
|
1978
|
+
* Percent-decodes one userinfo component, leaving a component that cannot be
|
|
1979
|
+
* decoded as it stands: `URL` accepts sequences `decodeURIComponent` rejects —
|
|
1980
|
+
* `us%zzer` parses and then throws — and a credential nobody can decode is still
|
|
1981
|
+
* worth sending as written rather than failing the request over.
|
|
1982
|
+
*/
|
|
1983
|
+
const decodeUserinfo = (component) => {
|
|
1984
|
+
try {
|
|
1985
|
+
return decodeURIComponent(component);
|
|
1986
|
+
} catch {
|
|
1987
|
+
return component;
|
|
1988
|
+
}
|
|
1989
|
+
};
|
|
1990
|
+
/** Base64-encodes userinfo as RFC 7617 wants it: UTF-8 bytes, percent-decoded. */
|
|
1991
|
+
const toBasicAuth = (username, password) => {
|
|
1992
|
+
const userinfo = `${decodeUserinfo(username)}:${decodeUserinfo(password)}`;
|
|
1993
|
+
const bytes = new TextEncoder().encode(userinfo);
|
|
1994
|
+
let latin1 = "";
|
|
1995
|
+
for (const byte of bytes) latin1 += String.fromCodePoint(byte);
|
|
1996
|
+
return `Basic ${btoa(latin1)}`;
|
|
1997
|
+
};
|
|
1998
|
+
/**
|
|
1999
|
+
* Moves any credentials a URL carries into an `Authorization` header.
|
|
2000
|
+
*
|
|
2001
|
+
* A self-hosted instance behind basic auth is configured as
|
|
2002
|
+
* `https://user:secret@host/api/v2`, and that password must not reach the wire
|
|
2003
|
+
* as userinfo: `fetch` rejects a credentialed URL outright, and everything
|
|
2004
|
+
* downstream of the URL — the log payload, the cache key — would carry it.
|
|
2005
|
+
*
|
|
2006
|
+
* A URL too malformed to parse cannot carry credentials in the first place, and
|
|
2007
|
+
* `fetch` is about to reject it anyway, so it is passed through untouched.
|
|
2008
|
+
*
|
|
2009
|
+
* The URL that comes back is what everything downstream keys on — the cache
|
|
2010
|
+
* entry, the in-flight map, the log line — so two calls to the same host under
|
|
2011
|
+
* different credentials share a cache entry and a round trip. That is the trade
|
|
2012
|
+
* this exists for: one instance behind one set of credentials. A client per
|
|
2013
|
+
* identity needs a `CacheStore` per identity to go with it.
|
|
2014
|
+
*/
|
|
2015
|
+
const splitCredentials = (url) => {
|
|
2016
|
+
if (!url.includes("@")) return {
|
|
2017
|
+
url,
|
|
2018
|
+
authorization: void 0
|
|
2019
|
+
};
|
|
2020
|
+
let parsed;
|
|
2021
|
+
try {
|
|
2022
|
+
parsed = new URL(url);
|
|
2023
|
+
} catch {
|
|
2024
|
+
return {
|
|
2025
|
+
url,
|
|
2026
|
+
authorization: void 0
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
2029
|
+
if (!parsed.username && !parsed.password) return {
|
|
2030
|
+
url,
|
|
2031
|
+
authorization: void 0
|
|
2032
|
+
};
|
|
2033
|
+
const authorization = toBasicAuth(parsed.username, parsed.password);
|
|
2034
|
+
parsed.username = "";
|
|
2035
|
+
parsed.password = "";
|
|
2036
|
+
return {
|
|
2037
|
+
url: parsed.toString(),
|
|
2038
|
+
authorization
|
|
2039
|
+
};
|
|
2040
|
+
};
|
|
2041
|
+
/**
|
|
2042
|
+
* Reduces an absolute resource URL to the endpoint path to request.
|
|
2043
|
+
*
|
|
2044
|
+
* When the URL belongs to `baseURL`, the path is simply what follows it.
|
|
2045
|
+
* Otherwise — a link from pokeapi.co handed to a client aimed at a self-hosted
|
|
2046
|
+
* instance — the path after the API version segment is used, so the resource is
|
|
2047
|
+
* re-resolved against the client's own base rather than fetched from elsewhere.
|
|
2048
|
+
*
|
|
2049
|
+
* The version segment is matched on parsed URL components: a raw-string search
|
|
2050
|
+
* also matches a host like `api.v2.example.com`.
|
|
2051
|
+
*/
|
|
2052
|
+
const toEndpointPath = (resourceURL, baseURL) => {
|
|
2053
|
+
const resource = new URL(resourceURL);
|
|
2054
|
+
const base = new URL(baseURL);
|
|
2055
|
+
const basePath = trimTrailingSlash(base.pathname);
|
|
2056
|
+
if (resource.origin === base.origin && (resource.pathname === basePath || resource.pathname.startsWith(`${basePath}/`))) return `${resource.pathname.slice(basePath.length)}${resource.search}`;
|
|
2057
|
+
const segments = resource.pathname.split("/");
|
|
2058
|
+
const version = segments.findIndex((segment) => API_VERSION_SEGMENT.test(segment));
|
|
2059
|
+
if (version === -1) throw new TypeError(`Cannot resolve "${resourceURL}" against the base URL "${baseURL}"`);
|
|
2060
|
+
return `/${segments.slice(version + 1).join("/")}${resource.search}`;
|
|
2061
|
+
};
|
|
2062
|
+
|
|
2063
|
+
//#endregion
|
|
2064
|
+
//#region src/internal/transport.ts
|
|
2065
|
+
/** Where a resolution came from, as the response log reports it. */
|
|
2066
|
+
const responseSource = (joined, revalidated) => {
|
|
2067
|
+
if (joined) return "in-flight";
|
|
2068
|
+
return revalidated === true ? "revalidated" : "network";
|
|
2069
|
+
};
|
|
2070
|
+
/** Resolves the `revalidate` option to the store the client will keep, if any. */
|
|
2071
|
+
const toEtagStore = (revalidate) => {
|
|
2072
|
+
if (!revalidate) return;
|
|
2073
|
+
return revalidate === true ? new EtagStore() : revalidate;
|
|
2074
|
+
};
|
|
2075
|
+
/**
|
|
2076
|
+
* ## Transport
|
|
2077
|
+
* Everything a client does that is not naming an endpoint: requests, caching,
|
|
2078
|
+
* retries, revalidation and logging. The rules it works to live beside it, one
|
|
2079
|
+
* concern per module — `./url`, `./retry`, `./paginate`, and `./inflight` for
|
|
2080
|
+
* the coalescing of concurrent requests.
|
|
2081
|
+
*
|
|
2082
|
+
* Internal. One transport is built per `MainClient` and handed to all twelve of
|
|
2083
|
+
* its section clients, which is what makes a resource fetched through one of
|
|
2084
|
+
* them cached — and coalesced — for the rest.
|
|
2085
|
+
*/
|
|
2086
|
+
var Transport = class Transport {
|
|
2087
|
+
config;
|
|
2088
|
+
state;
|
|
2089
|
+
scope;
|
|
2090
|
+
constructor(config, state, scope = {}) {
|
|
2091
|
+
this.config = config;
|
|
2092
|
+
this.state = state;
|
|
2093
|
+
this.scope = scope;
|
|
2094
|
+
}
|
|
2095
|
+
/** Builds a transport, and the state it will share, from public options. */
|
|
2096
|
+
static create(clientOptions) {
|
|
2097
|
+
return new Transport({
|
|
2098
|
+
baseURL: trimTrailingSlash(clientOptions?.baseURL ?? BASE_URL.REST),
|
|
2099
|
+
fetch: clientOptions?.fetch ?? ((input, init) => globalThis.fetch(input, init)),
|
|
2100
|
+
logger: clientOptions?.logger,
|
|
2101
|
+
retry: clientOptions?.retry
|
|
2102
|
+
}, {
|
|
2103
|
+
cache: clientOptions?.cache === false ? void 0 : clientOptions?.cache ?? new MemoryCache(),
|
|
2104
|
+
etags: toEtagStore(clientOptions?.revalidate),
|
|
2105
|
+
inFlight: new InFlight(),
|
|
2106
|
+
counts: {
|
|
2107
|
+
network: 0,
|
|
2108
|
+
cache: 0,
|
|
2109
|
+
"in-flight": 0,
|
|
2110
|
+
revalidated: 0
|
|
2111
|
+
},
|
|
2112
|
+
roundTrips: { count: 0 }
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
/** The counts so far, as a snapshot: the state behind them keeps moving. */
|
|
2116
|
+
get stats() {
|
|
2117
|
+
const { network, cache, revalidated } = this.state.counts;
|
|
2118
|
+
return {
|
|
2119
|
+
network,
|
|
2120
|
+
cache,
|
|
2121
|
+
inFlight: this.state.counts["in-flight"],
|
|
2122
|
+
revalidated,
|
|
2123
|
+
roundTrips: this.state.roundTrips.count
|
|
2124
|
+
};
|
|
2125
|
+
}
|
|
2126
|
+
/** The store backing this transport, or `undefined` when caching is disabled. */
|
|
2127
|
+
get cache() {
|
|
2128
|
+
return this.state.cache;
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* Derives a transport whose requests carry a signal, a timeout, or both.
|
|
2132
|
+
*
|
|
2133
|
+
* The derived transport shares this one's state, so a scoped call still joins
|
|
2134
|
+
* an identical unscoped one instead of repeating it.
|
|
2135
|
+
*/
|
|
2136
|
+
with(scope) {
|
|
2137
|
+
return new Transport(this.config, this.state, {
|
|
2138
|
+
...this.scope,
|
|
2139
|
+
...scope
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
/**
|
|
2143
|
+
* Drops every cached response, and the validators held for them: an
|
|
2144
|
+
* {@link EtagStore} keeps the bodies it learned, so leaving it would answer
|
|
2145
|
+
* the next request with the very body that was just dropped.
|
|
2146
|
+
*
|
|
2147
|
+
* A {@link CacheStore} that does not implement `clear` is left alone.
|
|
2148
|
+
*/
|
|
2149
|
+
async clear() {
|
|
2150
|
+
await this.state.cache?.clear?.();
|
|
2151
|
+
this.state.etags?.clear();
|
|
2152
|
+
}
|
|
2153
|
+
/**
|
|
2154
|
+
* Retrieves a single resource by its endpoint and identifier.
|
|
2155
|
+
*
|
|
2156
|
+
* Every segment is percent-encoded. A name reaches here as whatever the caller
|
|
2157
|
+
* passed — `getBerryByName(req.query.name)` is the shape that call takes — and
|
|
2158
|
+
* unencoded a `?` in it becomes a query, a `/` another endpoint, and a `#` a
|
|
2159
|
+
* fragment that is dropped before the wire but not before the cache key. A
|
|
2160
|
+
* path below the endpoint is given as separate segments for that reason.
|
|
2161
|
+
*/
|
|
2162
|
+
async resource(endpoint, ...segments) {
|
|
2163
|
+
const path = segments.map((segment) => encodeURIComponent(segment)).join("/");
|
|
2164
|
+
return this.request(path === "" ? endpoint : `${endpoint}/${path}`);
|
|
2165
|
+
}
|
|
2166
|
+
/** Retrieves a resource by its URL, or by a link taken from another response. */
|
|
2167
|
+
async byURL(resource, baseURL = this.config.baseURL) {
|
|
2168
|
+
const url = typeof resource === "string" ? resource : resource.url;
|
|
2169
|
+
return this.request(toEndpointPath(url, baseURL), baseURL);
|
|
2170
|
+
}
|
|
2171
|
+
/** Retrieves one page of a list endpoint. */
|
|
2172
|
+
async list(endpoint, offset = 0, limit = 20) {
|
|
2173
|
+
return this.request(listPath(endpoint, offset, limit));
|
|
2174
|
+
}
|
|
2175
|
+
/** Fetches what several links point at, in the order they were given. */
|
|
2176
|
+
async resolveAll(resources, concurrency = 4) {
|
|
2177
|
+
return mapWithConcurrency(resources, concurrency, (resource) => this.byURL(resource));
|
|
2178
|
+
}
|
|
2179
|
+
/** Walks every page of a list endpoint, yielding one entry at a time. */
|
|
2180
|
+
walk(list, options) {
|
|
2181
|
+
return walk(list, (link) => this.byURL(link), options);
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Resolves a resource through the cache, then through any identical request
|
|
2185
|
+
* already in flight, and only then over the network.
|
|
2186
|
+
*
|
|
2187
|
+
* The URL is joined by concatenation: `new URL(path, base)` would discard the
|
|
2188
|
+
* base's own `/api/v2` path.
|
|
2189
|
+
*/
|
|
2190
|
+
async request(path, baseURL = this.config.baseURL) {
|
|
2191
|
+
const rooted = path.startsWith("/") ? path : `/${path}`;
|
|
2192
|
+
const { url, authorization } = splitCredentials(normalizeURL(`${trimTrailingSlash(baseURL)}${rooted}`));
|
|
2193
|
+
const startedAt = performance.now();
|
|
2194
|
+
this.config.logger?.debug({
|
|
2195
|
+
event: "request",
|
|
2196
|
+
...logMessage("pokeapi request"),
|
|
2197
|
+
method: "GET",
|
|
2198
|
+
url
|
|
2199
|
+
});
|
|
2200
|
+
const signal = this.requestSignal();
|
|
2201
|
+
try {
|
|
2202
|
+
if (signal?.aborted) throw signal.reason;
|
|
2203
|
+
const cached = await this.state.cache?.get(url);
|
|
2204
|
+
if (cached !== void 0) {
|
|
2205
|
+
this.recordResponse(url, 200, "cache", startedAt);
|
|
2206
|
+
return cached;
|
|
2207
|
+
}
|
|
2208
|
+
const { value, joined } = await this.state.inFlight.share(url, signal, (requestSignal) => this.fetchResource(url, authorization, requestSignal));
|
|
2209
|
+
this.recordResponse(url, value.status, responseSource(joined, value.revalidated), startedAt);
|
|
2210
|
+
return value.data;
|
|
2211
|
+
} catch (error) {
|
|
2212
|
+
if (isAbort(error, signal)) {
|
|
2213
|
+
this.config.logger?.debug({
|
|
2214
|
+
event: "cancelled",
|
|
2215
|
+
...logMessage("pokeapi request cancelled"),
|
|
2216
|
+
url,
|
|
2217
|
+
reason: error,
|
|
2218
|
+
durationMs: performance.now() - startedAt
|
|
2219
|
+
});
|
|
2220
|
+
throw error;
|
|
2221
|
+
}
|
|
2222
|
+
this.config.logger?.error({
|
|
2223
|
+
event: "error",
|
|
2224
|
+
...logMessage("pokeapi request failed"),
|
|
2225
|
+
url,
|
|
2226
|
+
err: error,
|
|
2227
|
+
error
|
|
2228
|
+
});
|
|
2229
|
+
throw error;
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
/**
|
|
2233
|
+
* The signal this scope puts on a request, or none when it has nothing to
|
|
2234
|
+
* cancel with. A timeout is created per request, not per scope: a scope is
|
|
2235
|
+
* derived once and used many times.
|
|
2236
|
+
*/
|
|
2237
|
+
requestSignal() {
|
|
2238
|
+
const { signal, timeout } = this.scope;
|
|
2239
|
+
if (timeout === void 0) return signal;
|
|
2240
|
+
const expiry = AbortSignal.timeout(timeout);
|
|
2241
|
+
return signal ? AbortSignal.any([signal, expiry]) : expiry;
|
|
2242
|
+
}
|
|
2243
|
+
async fetchResource(url, authorization, signal) {
|
|
2244
|
+
const known = this.state.etags?.get(url);
|
|
2245
|
+
const headers = {
|
|
2246
|
+
Accept: "application/json",
|
|
2247
|
+
...authorization === void 0 ? {} : { Authorization: authorization },
|
|
2248
|
+
...known === void 0 ? {} : { "If-None-Match": known.etag }
|
|
2249
|
+
};
|
|
2250
|
+
const init = signal ? {
|
|
2251
|
+
headers,
|
|
2252
|
+
signal
|
|
2253
|
+
} : { headers };
|
|
2254
|
+
const { retry, logger } = this.config;
|
|
2255
|
+
const attempts = attemptCount(retry);
|
|
2256
|
+
for (let attempt = 1;; attempt += 1) {
|
|
2257
|
+
const isLast = attempt >= attempts;
|
|
2258
|
+
let response;
|
|
2259
|
+
try {
|
|
2260
|
+
this.state.roundTrips.count += 1;
|
|
2261
|
+
response = await this.config.fetch(url, init);
|
|
2262
|
+
} catch (error) {
|
|
2263
|
+
if (isLast || isAbort(error, signal)) throw error;
|
|
2264
|
+
await backoff({
|
|
2265
|
+
url,
|
|
2266
|
+
attempt,
|
|
2267
|
+
status: void 0,
|
|
2268
|
+
retryAfter: void 0,
|
|
2269
|
+
signal,
|
|
2270
|
+
retry,
|
|
2271
|
+
logger
|
|
2272
|
+
});
|
|
2273
|
+
continue;
|
|
2274
|
+
}
|
|
2275
|
+
const resolved = await this.resolveResponse(url, response, known);
|
|
2276
|
+
if (resolved !== void 0) return resolved;
|
|
2277
|
+
const retryAfter = await retryDelay(response, isLast, retry);
|
|
2278
|
+
response.body?.cancel().catch(() => {});
|
|
2279
|
+
await backoff({
|
|
2280
|
+
url,
|
|
2281
|
+
attempt,
|
|
2282
|
+
status: response.status,
|
|
2283
|
+
retryAfter,
|
|
2284
|
+
signal,
|
|
2285
|
+
retry,
|
|
2286
|
+
logger
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
/**
|
|
2291
|
+
* The resource a response carries, or nothing when it carries none and another
|
|
2292
|
+
* attempt is the question.
|
|
2293
|
+
*/
|
|
2294
|
+
async resolveResponse(url, response, known) {
|
|
2295
|
+
if (response.status === 304) {
|
|
2296
|
+
if (known === void 0) throw await toPokenodeError(response, `Request to ${response.url} was answered 304, but this client holds no response to reuse`);
|
|
2297
|
+
const refreshed = response.headers.get("ETag");
|
|
2298
|
+
if (refreshed !== null && refreshed !== known.etag) this.state.etags?.set(url, {
|
|
2299
|
+
etag: refreshed,
|
|
2300
|
+
value: known.value
|
|
2301
|
+
});
|
|
2302
|
+
await this.state.cache?.set(url, known.value);
|
|
2303
|
+
return {
|
|
2304
|
+
data: known.value,
|
|
2305
|
+
status: response.status,
|
|
2306
|
+
revalidated: true
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
if (!response.ok) return;
|
|
2310
|
+
const data = await response.json();
|
|
2311
|
+
const etag = response.headers.get("ETag");
|
|
2312
|
+
if (etag !== null) this.state.etags?.set(url, {
|
|
2313
|
+
etag,
|
|
2314
|
+
value: data
|
|
2315
|
+
});
|
|
2316
|
+
await this.state.cache?.set(url, data);
|
|
2317
|
+
return {
|
|
2318
|
+
data,
|
|
2319
|
+
status: response.status
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
/**
|
|
2323
|
+
* The one place a resolution is accounted for, however it was resolved — which
|
|
2324
|
+
* is what keeps {@link Transport.stats} and the response log saying the same
|
|
2325
|
+
* thing about the same request.
|
|
2326
|
+
*/
|
|
2327
|
+
recordResponse(url, status, source, startedAt) {
|
|
2328
|
+
this.state.counts[source] += 1;
|
|
2329
|
+
this.config.logger?.debug({
|
|
2330
|
+
event: "response",
|
|
2331
|
+
...logMessage("pokeapi response"),
|
|
2332
|
+
url,
|
|
2333
|
+
status,
|
|
2334
|
+
source,
|
|
2335
|
+
durationMs: performance.now() - startedAt
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
};
|
|
2339
|
+
|
|
2340
|
+
//#endregion
|
|
2341
|
+
//#region src/clients/base.ts
|
|
2342
|
+
/**
|
|
2343
|
+
* ## Client Facade
|
|
2344
|
+
* What every client is, underneath: something that owns a transport and talks
|
|
2345
|
+
* to it. Holds the members {@link BaseClient} and {@link MainClient} would
|
|
2346
|
+
* otherwise each declare — the cache, the scope, and following a link.
|
|
2347
|
+
*
|
|
2348
|
+
* The transport is a `#private` field rather than a `protected` one so that
|
|
2349
|
+
* nothing about it reaches the published types: a `protected` member keeps its
|
|
2350
|
+
* type in the emitted `.d.ts`, which would put the whole internal transport
|
|
2351
|
+
* surface in front of consumers who cannot name it.
|
|
2352
|
+
*/
|
|
2353
|
+
var ClientFacade = class {
|
|
2354
|
+
#transport;
|
|
2355
|
+
constructor(source) {
|
|
2356
|
+
this.#transport = source instanceof Transport ? source : Transport.create(source);
|
|
2357
|
+
}
|
|
2358
|
+
/** The store backing this client, or `undefined` when caching is disabled. */
|
|
2359
|
+
get cache() {
|
|
2360
|
+
return this.#transport.cache;
|
|
2361
|
+
}
|
|
2362
|
+
/**
|
|
2363
|
+
* How many resolutions came from where.
|
|
2364
|
+
*
|
|
2365
|
+
* ```ts
|
|
2366
|
+
* await api.pokemon.getPokemonByName('luxray');
|
|
2367
|
+
* await api.pokemon.getPokemonByName('luxray');
|
|
2368
|
+
*
|
|
2369
|
+
* api.stats; // { network: 1, cache: 1, inFlight: 0, revalidated: 0, roundTrips: 1 }
|
|
2370
|
+
* ```
|
|
2371
|
+
*
|
|
2372
|
+
* The counts are the transport's, so they cover every section of a
|
|
2373
|
+
* {@link MainClient} and every client derived with {@link ClientFacade.with} —
|
|
2374
|
+
* the same sharing that makes one cache serve all of them.
|
|
2375
|
+
*
|
|
2376
|
+
* A snapshot, read at the moment it is asked for. Keeping one to compare
|
|
2377
|
+
* against later means keeping the object, not the client.
|
|
2378
|
+
*/
|
|
2379
|
+
get stats() {
|
|
2380
|
+
return this.#transport.stats;
|
|
2381
|
+
}
|
|
2382
|
+
/**
|
|
2383
|
+
* What has been counted since `snapshot` was taken.
|
|
2384
|
+
*
|
|
2385
|
+
* ```ts
|
|
2386
|
+
* const before = api.stats;
|
|
2387
|
+
* await renderTeam();
|
|
2388
|
+
*
|
|
2389
|
+
* api.statsSince(before).roundTrips; // what that render cost
|
|
2390
|
+
* ```
|
|
2391
|
+
*
|
|
2392
|
+
* There is no way to reset the counts, and this is why: the transport behind
|
|
2393
|
+
* them is shared by every section of a {@link MainClient} and by every client
|
|
2394
|
+
* derived with {@link ClientFacade.with}, so zeroing it for one measurement
|
|
2395
|
+
* zeroes it for whatever else is measuring. Subtraction is the same answer
|
|
2396
|
+
* without the shared mutation.
|
|
2397
|
+
*/
|
|
2398
|
+
statsSince(snapshot) {
|
|
2399
|
+
const now = this.#transport.stats;
|
|
2400
|
+
return {
|
|
2401
|
+
network: now.network - snapshot.network,
|
|
2402
|
+
cache: now.cache - snapshot.cache,
|
|
2403
|
+
inFlight: now.inFlight - snapshot.inFlight,
|
|
2404
|
+
revalidated: now.revalidated - snapshot.revalidated,
|
|
2405
|
+
roundTrips: now.roundTrips - snapshot.roundTrips
|
|
2406
|
+
};
|
|
2407
|
+
}
|
|
2408
|
+
/**
|
|
2409
|
+
* Derives a client whose requests carry a signal, a timeout, or both.
|
|
2410
|
+
*
|
|
2411
|
+
* The clone shares this client's transport — its cache, its validators and the
|
|
2412
|
+
* requests already on the wire — so a scoped call still joins an identical
|
|
2413
|
+
* unscoped one instead of repeating it. Cloning is cheap, but not free: derive
|
|
2414
|
+
* one per unit of work — a request handler, a job — rather than one per call.
|
|
2415
|
+
*
|
|
2416
|
+
* ```ts
|
|
2417
|
+
* const scoped = api.with({ signal: request.signal, timeout: 2_000 });
|
|
2418
|
+
* ```
|
|
2419
|
+
*/
|
|
2420
|
+
with(scope) {
|
|
2421
|
+
const Client = this.constructor;
|
|
2422
|
+
return new Client(this.#transport.with(scope));
|
|
2423
|
+
}
|
|
2424
|
+
/**
|
|
2425
|
+
* Drops every cached response, and any `ETag` learned for one — otherwise the
|
|
2426
|
+
* next request revalidates and is answered with the body just dropped.
|
|
2427
|
+
*
|
|
2428
|
+
* A {@link CacheStore} that does not implement `clear` is left alone.
|
|
2429
|
+
*
|
|
2430
|
+
* The store is the transport's, so a client sharing one with others clears
|
|
2431
|
+
* theirs too.
|
|
2432
|
+
*/
|
|
2433
|
+
async clearCache() {
|
|
2434
|
+
await this.#transport.clear();
|
|
2435
|
+
}
|
|
2436
|
+
/**
|
|
2437
|
+
* Fetches what a link points at, through this client's cache and scope.
|
|
2438
|
+
*
|
|
2439
|
+
* A link carries what it points at, so the result is typed without saying so:
|
|
2440
|
+
*
|
|
2441
|
+
* ```ts
|
|
2442
|
+
* const pokemon = await api.getPokemonByName('luxray');
|
|
2443
|
+
* const species = await api.resolve(pokemon.species);
|
|
2444
|
+
* // ^? PokemonSpecies
|
|
2445
|
+
* ```
|
|
2446
|
+
*
|
|
2447
|
+
* A link names a resource, not a section, so any client resolves any link.
|
|
2448
|
+
*
|
|
2449
|
+
* @throws {TypeError} If the URL is not valid, or names no PokéAPI endpoint.
|
|
2450
|
+
*/
|
|
2451
|
+
async resolve(resource) {
|
|
2452
|
+
return this.#transport.byURL(resource);
|
|
2453
|
+
}
|
|
2454
|
+
/**
|
|
2455
|
+
* Fetches what several links point at, in the order they were given.
|
|
2456
|
+
*
|
|
2457
|
+
* At most `concurrency` requests run at a time — four by default, because the
|
|
2458
|
+
* PokéAPI's fair-use policy asks clients not to flood it. The first failure
|
|
2459
|
+
* rejects, and no further link is fetched.
|
|
2460
|
+
*
|
|
2461
|
+
* ```ts
|
|
2462
|
+
* const types = await api.resolveAll(pokemon.types.map((slot) => slot.type));
|
|
2463
|
+
* // ^? Type[]
|
|
2464
|
+
* ```
|
|
2465
|
+
*/
|
|
2466
|
+
async resolveAll(resources, options) {
|
|
2467
|
+
return this.#transport.resolveAll(resources, options?.concurrency);
|
|
2468
|
+
}
|
|
2469
|
+
/**
|
|
2470
|
+
* Retrieves a single resource from the PokéAPI by its endpoint and identifier.
|
|
2471
|
+
*
|
|
2472
|
+
* @param segments - The identifier of the resource, followed by any path below
|
|
2473
|
+
* it. Each is percent-encoded, so pass `id, 'encounters'` rather than
|
|
2474
|
+
* `` `${id}/encounters` ``. Omit them to address the endpoint itself.
|
|
2475
|
+
*/
|
|
2476
|
+
async getResource(endpoint, ...segments) {
|
|
2477
|
+
return this.#transport.resource(endpoint, ...segments);
|
|
2478
|
+
}
|
|
2479
|
+
/**
|
|
2480
|
+
* Retrieves a resource by its URL, or by a link taken from another response.
|
|
2481
|
+
*
|
|
2482
|
+
* A link knows what it points at, so passing one infers `T`; a bare string
|
|
2483
|
+
* does not, and needs `T` named.
|
|
2484
|
+
*
|
|
2485
|
+
* @throws {TypeError} If the URL is not valid, or names no endpoint under `baseURL`.
|
|
2486
|
+
*/
|
|
2487
|
+
async getResourceByURL(resource, baseURL) {
|
|
2488
|
+
return this.#transport.byURL(resource, baseURL);
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* Retrieves a list of resources from the PokéAPI with pagination support.
|
|
2492
|
+
*
|
|
2493
|
+
* @template T - What the listed links resolve to.
|
|
2494
|
+
*/
|
|
2495
|
+
async getListResource(endpoint, offset, limit) {
|
|
2496
|
+
return this.#transport.list(endpoint, offset, limit);
|
|
2497
|
+
}
|
|
2498
|
+
/**
|
|
2499
|
+
* Retrieves a list of resources that have no name to list, with pagination support.
|
|
2500
|
+
*
|
|
2501
|
+
* @template T - What the listed links resolve to.
|
|
2502
|
+
*/
|
|
2503
|
+
async getUnnamedListResource(endpoint, offset, limit) {
|
|
2504
|
+
return this.#transport.list(endpoint, offset, limit);
|
|
2505
|
+
}
|
|
2506
|
+
/**
|
|
2507
|
+
* Walks every page of a list, yielding one entry at a time. The bridge
|
|
2508
|
+
* {@link BaseClient.paginate} reaches the transport through, so that no
|
|
2509
|
+
* signature here has to name one.
|
|
2510
|
+
*/
|
|
2511
|
+
walk(list, options) {
|
|
2512
|
+
return this.#transport.walk(list, options);
|
|
2513
|
+
}
|
|
2514
|
+
};
|
|
2515
|
+
/**
|
|
2516
|
+
* ## Base Client
|
|
2517
|
+
* Base class for every section client. Names endpoints; the transport behind
|
|
2518
|
+
* {@link ClientFacade} does everything else — requests, caching, coalescing,
|
|
2519
|
+
* retries and logs.
|
|
2520
|
+
*
|
|
2521
|
+
* A {@link MainClient} builds one transport and hands it to all twelve of its
|
|
2522
|
+
* section clients, which is what makes them share a cache and a round trip.
|
|
2523
|
+
*/
|
|
2524
|
+
var BaseClient = class extends ClientFacade {
|
|
2525
|
+
paginate(list, options) {
|
|
2526
|
+
const listPage = typeof list === "function" ? list : (offset, limit) => this[list](offset, limit);
|
|
2527
|
+
return this.walk(listPage, options);
|
|
2528
|
+
}
|
|
2529
|
+
};
|
|
2530
|
+
|
|
2531
|
+
//#endregion
|
|
2532
|
+
//#region src/clients/berry.client.ts
|
|
2533
|
+
/**
|
|
2534
|
+
* ### Berry Client
|
|
2535
|
+
*
|
|
2536
|
+
* Client used to access the Berry Endpoints:
|
|
2537
|
+
*
|
|
2538
|
+
* - [Berries](https://pokeapi.co/docs/v2#berries)
|
|
2539
|
+
* - [Berry Firmnesses](https://pokeapi.co/docs/v2#berry-firmnesses)
|
|
2540
|
+
* - [Berry Flavors](https://pokeapi.co/docs/v2#berry-flavors)
|
|
2541
|
+
*
|
|
2542
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#berries-section)
|
|
2543
|
+
*/
|
|
2544
|
+
var BerryClient = class extends BaseClient {
|
|
2545
|
+
/** Get a Berry by its name. */
|
|
2546
|
+
async getBerryByName(name) {
|
|
2547
|
+
return this.getResource(ENDPOINTS.BERRY, name);
|
|
2548
|
+
}
|
|
2549
|
+
/** Get a Berry by its ID. */
|
|
2550
|
+
async getBerryById(id) {
|
|
2551
|
+
return this.getResource(ENDPOINTS.BERRY, id);
|
|
2552
|
+
}
|
|
2553
|
+
/** Get a Berry Firmness by its ID. */
|
|
2554
|
+
async getBerryFirmnessById(id) {
|
|
2555
|
+
return this.getResource(ENDPOINTS.BERRY_FIRMNESS, id);
|
|
2556
|
+
}
|
|
2557
|
+
/** Get a Berry Firmness by its name. */
|
|
2558
|
+
async getBerryFirmnessByName(name) {
|
|
2559
|
+
return this.getResource(ENDPOINTS.BERRY_FIRMNESS, name);
|
|
2560
|
+
}
|
|
2561
|
+
/** Get a Berry Flavor by its ID. */
|
|
2562
|
+
async getBerryFlavorById(id) {
|
|
2563
|
+
return this.getResource(ENDPOINTS.BERRY_FLAVOR, id);
|
|
2564
|
+
}
|
|
2565
|
+
/** Get a Berry Flavor by its name. */
|
|
2566
|
+
async getBerryFlavorByName(name) {
|
|
2567
|
+
return this.getResource(ENDPOINTS.BERRY_FLAVOR, name);
|
|
2568
|
+
}
|
|
2569
|
+
/** List Berries. Page defaults to 20 entries from offset 0. */
|
|
2570
|
+
async listBerries(offset, limit) {
|
|
2571
|
+
return this.getListResource(ENDPOINTS.BERRY, offset, limit);
|
|
2572
|
+
}
|
|
2573
|
+
/** List Berry Firmnesses. Page defaults to 20 entries from offset 0. */
|
|
2574
|
+
async listBerryFirmnesses(offset, limit) {
|
|
2575
|
+
return this.getListResource(ENDPOINTS.BERRY_FIRMNESS, offset, limit);
|
|
2576
|
+
}
|
|
2577
|
+
/** List Berry Flavors. Page defaults to 20 entries from offset 0. */
|
|
2578
|
+
async listBerryFlavors(offset, limit) {
|
|
2579
|
+
return this.getListResource(ENDPOINTS.BERRY_FLAVOR, offset, limit);
|
|
2580
|
+
}
|
|
2581
|
+
};
|
|
2582
|
+
|
|
2583
|
+
//#endregion
|
|
2584
|
+
//#region src/clients/contest.client.ts
|
|
2585
|
+
/**
|
|
2586
|
+
* ### Contest Client
|
|
2587
|
+
*
|
|
2588
|
+
* Client used to access the Contest Endpoints:
|
|
2589
|
+
*
|
|
2590
|
+
* - [Contest Types](https://pokeapi.co/docs/v2#contest-types)
|
|
2591
|
+
* - [Contest Effects](https://pokeapi.co/docs/v2#contest-effects)
|
|
2592
|
+
* - [Super Contest Effects](https://pokeapi.co/docs/v2#super-contest-effects)
|
|
2593
|
+
*
|
|
2594
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#contests-section)
|
|
2595
|
+
*/
|
|
2596
|
+
var ContestClient = class extends BaseClient {
|
|
2597
|
+
/** Get a Contest Type by its name. */
|
|
2598
|
+
async getContestTypeByName(name) {
|
|
2599
|
+
return this.getResource(ENDPOINTS.CONTEST_TYPE, name);
|
|
2600
|
+
}
|
|
2601
|
+
/** Get a Contest Type by its ID. */
|
|
2602
|
+
async getContestTypeById(id) {
|
|
2603
|
+
return this.getResource(ENDPOINTS.CONTEST_TYPE, id);
|
|
2604
|
+
}
|
|
2605
|
+
/** Get a Contest Effect by its ID. */
|
|
2606
|
+
async getContestEffectById(id) {
|
|
2607
|
+
return this.getResource(ENDPOINTS.CONTEST_EFFECT, id);
|
|
2608
|
+
}
|
|
2609
|
+
/** Get a Super Contest Effect by its ID. */
|
|
2610
|
+
async getSuperContestEffectById(id) {
|
|
2611
|
+
return this.getResource(ENDPOINTS.SUPER_CONTEST_EFFECT, id);
|
|
2612
|
+
}
|
|
2613
|
+
/** List Contest Types. Page defaults to 20 entries from offset 0. */
|
|
2614
|
+
async listContestTypes(offset, limit) {
|
|
2615
|
+
return this.getListResource(ENDPOINTS.CONTEST_TYPE, offset, limit);
|
|
2616
|
+
}
|
|
2617
|
+
/** List Contest Effects. Page defaults to 20 entries from offset 0. */
|
|
2618
|
+
async listContestEffects(offset, limit) {
|
|
2619
|
+
return this.getUnnamedListResource(ENDPOINTS.CONTEST_EFFECT, offset, limit);
|
|
2620
|
+
}
|
|
2621
|
+
/** List Super Contest Effects. Page defaults to 20 entries from offset 0. */
|
|
2622
|
+
async listSuperContestEffects(offset, limit) {
|
|
2623
|
+
return this.getUnnamedListResource(ENDPOINTS.SUPER_CONTEST_EFFECT, offset, limit);
|
|
2624
|
+
}
|
|
2625
|
+
};
|
|
2626
|
+
|
|
2627
|
+
//#endregion
|
|
2628
|
+
//#region src/clients/currency.client.ts
|
|
2629
|
+
/**
|
|
2630
|
+
* ### Currency Client
|
|
2631
|
+
*
|
|
2632
|
+
* Client used to access the Currency Endpoints:
|
|
2633
|
+
*
|
|
2634
|
+
* - [Currencies](https://pokeapi.co/docs/v2#currencies)
|
|
2635
|
+
*
|
|
2636
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#currencies-section)
|
|
2637
|
+
*/
|
|
2638
|
+
var CurrencyClient = class extends BaseClient {
|
|
2639
|
+
/** Get a Currency by its name. */
|
|
2640
|
+
async getCurrencyByName(name) {
|
|
2641
|
+
return this.getResource(ENDPOINTS.CURRENCY, name);
|
|
2642
|
+
}
|
|
2643
|
+
/** Get a Currency by its ID. */
|
|
2644
|
+
async getCurrencyById(id) {
|
|
2645
|
+
return this.getResource(ENDPOINTS.CURRENCY, id);
|
|
2646
|
+
}
|
|
2647
|
+
/** List Currencies. Page defaults to 20 entries from offset 0. */
|
|
2648
|
+
async listCurrencies(offset, limit) {
|
|
2649
|
+
return this.getListResource(ENDPOINTS.CURRENCY, offset, limit);
|
|
2650
|
+
}
|
|
2651
|
+
};
|
|
2652
|
+
|
|
2653
|
+
//#endregion
|
|
2654
|
+
//#region src/clients/encounter.client.ts
|
|
2655
|
+
/**
|
|
2656
|
+
* ### Encounter Client
|
|
2657
|
+
*
|
|
2658
|
+
* Client used to access the Encounter Endpoints:
|
|
2659
|
+
*
|
|
2660
|
+
* - [Encounter Methods](https://pokeapi.co/docs/v2#encounter-methods)
|
|
2661
|
+
* - [Encounter Conditions](https://pokeapi.co/docs/v2#encounter-conditions)
|
|
2662
|
+
* - [Encounter Condition Values](https://pokeapi.co/docs/v2#encounter-condition-values)
|
|
2663
|
+
*
|
|
2664
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#encounters-section)
|
|
2665
|
+
*/
|
|
2666
|
+
var EncounterClient = class extends BaseClient {
|
|
2667
|
+
/** Get an Encounter Method by its name. */
|
|
2668
|
+
async getEncounterMethodByName(name) {
|
|
2669
|
+
return this.getResource(ENDPOINTS.ENCOUNTER_METHOD, name);
|
|
2670
|
+
}
|
|
2671
|
+
/** Get an Encounter Method by its ID. */
|
|
2672
|
+
async getEncounterMethodById(id) {
|
|
2673
|
+
return this.getResource(ENDPOINTS.ENCOUNTER_METHOD, id);
|
|
2674
|
+
}
|
|
2675
|
+
/** Get an Encounter Condition by its ID. */
|
|
2676
|
+
async getEncounterConditionById(id) {
|
|
2677
|
+
return this.getResource(ENDPOINTS.ENCOUNTER_CONDITION, id);
|
|
2678
|
+
}
|
|
2679
|
+
/** Get an Encounter Condition by its name. */
|
|
2680
|
+
async getEncounterConditionByName(name) {
|
|
2681
|
+
return this.getResource(ENDPOINTS.ENCOUNTER_CONDITION, name);
|
|
2682
|
+
}
|
|
2683
|
+
/** Get an Encounter Condition Value by its name. */
|
|
2684
|
+
async getEncounterConditionValueByName(name) {
|
|
2685
|
+
return this.getResource(ENDPOINTS.ENCOUNTER_CONDITION_VALUE, name);
|
|
2686
|
+
}
|
|
2687
|
+
/** Get an Encounter Condition Value by its ID. */
|
|
2688
|
+
async getEncounterConditionValueById(id) {
|
|
2689
|
+
return this.getResource(ENDPOINTS.ENCOUNTER_CONDITION_VALUE, id);
|
|
2690
|
+
}
|
|
2691
|
+
/** List Encounter Methods. Page defaults to 20 entries from offset 0. */
|
|
2692
|
+
async listEncounterMethods(offset, limit) {
|
|
2693
|
+
return this.getListResource(ENDPOINTS.ENCOUNTER_METHOD, offset, limit);
|
|
2694
|
+
}
|
|
2695
|
+
/** List Encounter Conditions. Page defaults to 20 entries from offset 0. */
|
|
2696
|
+
async listEncounterConditions(offset, limit) {
|
|
2697
|
+
return this.getListResource(ENDPOINTS.ENCOUNTER_CONDITION, offset, limit);
|
|
2698
|
+
}
|
|
2699
|
+
/** List Encounter Condition Values. Page defaults to 20 entries from offset 0. */
|
|
2700
|
+
async listEncounterConditionValues(offset, limit) {
|
|
2701
|
+
return this.getListResource(ENDPOINTS.ENCOUNTER_CONDITION_VALUE, offset, limit);
|
|
2702
|
+
}
|
|
2703
|
+
};
|
|
2704
|
+
|
|
2705
|
+
//#endregion
|
|
2706
|
+
//#region src/clients/evolution.client.ts
|
|
2707
|
+
/**
|
|
2708
|
+
* ### Evolution Client
|
|
2709
|
+
*
|
|
2710
|
+
* Client used to access the Evolution Endpoints:
|
|
2711
|
+
*
|
|
2712
|
+
* - [Evolution Chains](https://pokeapi.co/docs/v2#evolution-chains)
|
|
2713
|
+
* - [Evolution Triggers](https://pokeapi.co/docs/v2#evolution-triggers)
|
|
2714
|
+
* - [Evolution Variables](https://pokeapi.co/docs/v2#evolution-variables)
|
|
2715
|
+
*
|
|
2716
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#evolution-section)
|
|
2717
|
+
*/
|
|
2718
|
+
var EvolutionClient = class extends BaseClient {
|
|
2719
|
+
/** Get an Evolution Chain by its ID. */
|
|
2720
|
+
async getEvolutionChainById(id) {
|
|
2721
|
+
return this.getResource(ENDPOINTS.EVOLUTION_CHAIN, id);
|
|
2722
|
+
}
|
|
2723
|
+
/** Get an Evolution Trigger by its ID. */
|
|
2724
|
+
async getEvolutionTriggerById(id) {
|
|
2725
|
+
return this.getResource(ENDPOINTS.EVOLUTION_TRIGGER, id);
|
|
2726
|
+
}
|
|
2727
|
+
/** Get an Evolution Trigger by its name. */
|
|
2728
|
+
async getEvolutionTriggerByName(name) {
|
|
2729
|
+
return this.getResource(ENDPOINTS.EVOLUTION_TRIGGER, name);
|
|
2730
|
+
}
|
|
2731
|
+
/** Get an Evolution Variable by its ID. */
|
|
2732
|
+
async getEvolutionVariableById(id) {
|
|
2733
|
+
return this.getResource(ENDPOINTS.EVOLUTION_VARIABLE, id);
|
|
2734
|
+
}
|
|
2735
|
+
/** Get an Evolution Variable by its name. */
|
|
2736
|
+
async getEvolutionVariableByName(name) {
|
|
2737
|
+
return this.getResource(ENDPOINTS.EVOLUTION_VARIABLE, name);
|
|
2738
|
+
}
|
|
2739
|
+
/** List Evolution Chains. Page defaults to 20 entries from offset 0. */
|
|
2740
|
+
async listEvolutionChains(offset, limit) {
|
|
2741
|
+
return this.getUnnamedListResource(ENDPOINTS.EVOLUTION_CHAIN, offset, limit);
|
|
2742
|
+
}
|
|
2743
|
+
/** List Evolution Triggers. Page defaults to 20 entries from offset 0. */
|
|
2744
|
+
async listEvolutionTriggers(offset, limit) {
|
|
2745
|
+
return this.getListResource(ENDPOINTS.EVOLUTION_TRIGGER, offset, limit);
|
|
2746
|
+
}
|
|
2747
|
+
/** List Evolution Variables. Page defaults to 20 entries from offset 0. */
|
|
2748
|
+
async listEvolutionVariables(offset, limit) {
|
|
2749
|
+
return this.getListResource(ENDPOINTS.EVOLUTION_VARIABLE, offset, limit);
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2752
|
+
|
|
2753
|
+
//#endregion
|
|
2754
|
+
//#region src/clients/game.client.ts
|
|
2755
|
+
/**
|
|
2756
|
+
* ### Game Client
|
|
2757
|
+
*
|
|
2758
|
+
* Client used to access the Game Endpoints:
|
|
2759
|
+
*
|
|
2760
|
+
* - [Generations](https://pokeapi.co/docs/v2#generations)
|
|
2761
|
+
* - [Pokédexes](https://pokeapi.co/docs/v2#pokedexes)
|
|
2762
|
+
* - [Versions](https://pokeapi.co/docs/v2#version)
|
|
2763
|
+
* - [Version Groups](https://pokeapi.co/docs/v2#version-groups)
|
|
2764
|
+
*
|
|
2765
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#games-section)
|
|
2766
|
+
*/
|
|
2767
|
+
var GameClient = class extends BaseClient {
|
|
2768
|
+
/** Get a Generation by its name. */
|
|
2769
|
+
async getGenerationByName(name) {
|
|
2770
|
+
return this.getResource(ENDPOINTS.GENERATION, name);
|
|
2771
|
+
}
|
|
2772
|
+
/** Get a Generation by its ID. */
|
|
2773
|
+
async getGenerationById(id) {
|
|
2774
|
+
return this.getResource(ENDPOINTS.GENERATION, id);
|
|
2775
|
+
}
|
|
2776
|
+
/** Get a Pokédex by its name. */
|
|
2777
|
+
async getPokedexByName(name) {
|
|
2778
|
+
return this.getResource(ENDPOINTS.POKEDEX, name);
|
|
2779
|
+
}
|
|
2780
|
+
/** Get a Pokédex by its ID. */
|
|
2781
|
+
async getPokedexById(id) {
|
|
2782
|
+
return this.getResource(ENDPOINTS.POKEDEX, id);
|
|
2783
|
+
}
|
|
2784
|
+
/** Get a Version by its name. */
|
|
2785
|
+
async getVersionByName(name) {
|
|
2786
|
+
return this.getResource(ENDPOINTS.VERSION, name);
|
|
2787
|
+
}
|
|
2788
|
+
/** Get a Version by its ID. */
|
|
2789
|
+
async getVersionById(id) {
|
|
2790
|
+
return this.getResource(ENDPOINTS.VERSION, id);
|
|
2791
|
+
}
|
|
2792
|
+
/** Get a Version Group by its name. */
|
|
2793
|
+
async getVersionGroupByName(name) {
|
|
2794
|
+
return this.getResource(ENDPOINTS.VERSION_GROUP, name);
|
|
2795
|
+
}
|
|
2796
|
+
/** Get a Version Group by its ID. */
|
|
2797
|
+
async getVersionGroupById(id) {
|
|
2798
|
+
return this.getResource(ENDPOINTS.VERSION_GROUP, id);
|
|
2799
|
+
}
|
|
2800
|
+
/** List Generations. Page defaults to 20 entries from offset 0. */
|
|
2801
|
+
async listGenerations(offset, limit) {
|
|
2802
|
+
return this.getListResource(ENDPOINTS.GENERATION, offset, limit);
|
|
2803
|
+
}
|
|
2804
|
+
/** List Pokédexes. Page defaults to 20 entries from offset 0. */
|
|
2805
|
+
async listPokedexes(offset, limit) {
|
|
2806
|
+
return this.getListResource(ENDPOINTS.POKEDEX, offset, limit);
|
|
2807
|
+
}
|
|
2808
|
+
/** List Versions. Page defaults to 20 entries from offset 0. */
|
|
2809
|
+
async listVersions(offset, limit) {
|
|
2810
|
+
return this.getListResource(ENDPOINTS.VERSION, offset, limit);
|
|
2811
|
+
}
|
|
2812
|
+
/** List Version Groups. Page defaults to 20 entries from offset 0. */
|
|
2813
|
+
async listVersionGroups(offset, limit) {
|
|
2814
|
+
return this.getListResource(ENDPOINTS.VERSION_GROUP, offset, limit);
|
|
2815
|
+
}
|
|
2816
|
+
};
|
|
2817
|
+
|
|
2818
|
+
//#endregion
|
|
2819
|
+
//#region src/clients/item.client.ts
|
|
2820
|
+
/**
|
|
2821
|
+
* ### Item Client
|
|
2822
|
+
*
|
|
2823
|
+
* Client used to access the Item Endpoints:
|
|
2824
|
+
*
|
|
2825
|
+
* - [Items](https://pokeapi.co/docs/v2#item)
|
|
2826
|
+
* - [Item Attributes](https://pokeapi.co/docs/v2#item-attributes)
|
|
2827
|
+
* - [Item Categories](https://pokeapi.co/docs/v2#item-categories)
|
|
2828
|
+
* - [Item Fling Effects](https://pokeapi.co/docs/v2#item-fling-effects)
|
|
2829
|
+
* - [Item Pockets](https://pokeapi.co/docs/v2#item-pockets)
|
|
2830
|
+
*
|
|
2831
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#items-section)
|
|
2832
|
+
*/
|
|
2833
|
+
var ItemClient = class extends BaseClient {
|
|
2834
|
+
/** Get an Item by its name. */
|
|
2835
|
+
async getItemByName(name) {
|
|
2836
|
+
return this.getResource(ENDPOINTS.ITEM, name);
|
|
2837
|
+
}
|
|
2838
|
+
/** Get an Item by its ID. */
|
|
2839
|
+
async getItemById(id) {
|
|
2840
|
+
return this.getResource(ENDPOINTS.ITEM, id);
|
|
2841
|
+
}
|
|
2842
|
+
/** Get an Item Attribute by its name. */
|
|
2843
|
+
async getItemAttributeByName(name) {
|
|
2844
|
+
return this.getResource(ENDPOINTS.ITEM_ATTRIBUTE, name);
|
|
2845
|
+
}
|
|
2846
|
+
/** Get an Item Attribute by its ID. */
|
|
2847
|
+
async getItemAttributeById(id) {
|
|
2848
|
+
return this.getResource(ENDPOINTS.ITEM_ATTRIBUTE, id);
|
|
2849
|
+
}
|
|
2850
|
+
/** Get an Item Category by its name. */
|
|
2851
|
+
async getItemCategoryByName(name) {
|
|
2852
|
+
return this.getResource(ENDPOINTS.ITEM_CATEGORY, name);
|
|
2853
|
+
}
|
|
2854
|
+
/** Get an Item Category by its ID. */
|
|
2855
|
+
async getItemCategoryById(id) {
|
|
2856
|
+
return this.getResource(ENDPOINTS.ITEM_CATEGORY, id);
|
|
2857
|
+
}
|
|
2858
|
+
/** Get an Item Fling Effect by its name. */
|
|
2859
|
+
async getItemFlingEffectByName(name) {
|
|
2860
|
+
return this.getResource(ENDPOINTS.ITEM_FLING_EFFECT, name);
|
|
2861
|
+
}
|
|
2862
|
+
/** Get an Item Fling Effect by its ID. */
|
|
2863
|
+
async getItemFlingEffectById(id) {
|
|
2864
|
+
return this.getResource(ENDPOINTS.ITEM_FLING_EFFECT, id);
|
|
2865
|
+
}
|
|
2866
|
+
/** Get an Item Pocket by its name. */
|
|
2867
|
+
async getItemPocketByName(name) {
|
|
2868
|
+
return this.getResource(ENDPOINTS.ITEM_POCKET, name);
|
|
2869
|
+
}
|
|
2870
|
+
/** Get an Item Pocket by its ID. */
|
|
2871
|
+
async getItemPocketById(id) {
|
|
2872
|
+
return this.getResource(ENDPOINTS.ITEM_POCKET, id);
|
|
2873
|
+
}
|
|
2874
|
+
/** List Items. Page defaults to 20 entries from offset 0. */
|
|
2875
|
+
async listItems(offset, limit) {
|
|
2876
|
+
return this.getListResource(ENDPOINTS.ITEM, offset, limit);
|
|
2877
|
+
}
|
|
2878
|
+
/** List Item Attributes. Page defaults to 20 entries from offset 0. */
|
|
2879
|
+
async listItemAttributes(offset, limit) {
|
|
2880
|
+
return this.getListResource(ENDPOINTS.ITEM_ATTRIBUTE, offset, limit);
|
|
2881
|
+
}
|
|
2882
|
+
/** List Item Categories. Page defaults to 20 entries from offset 0. */
|
|
2883
|
+
async listItemCategories(offset, limit) {
|
|
2884
|
+
return this.getListResource(ENDPOINTS.ITEM_CATEGORY, offset, limit);
|
|
2885
|
+
}
|
|
2886
|
+
/** List Item Fling Effects. Page defaults to 20 entries from offset 0. */
|
|
2887
|
+
async listItemFlingEffects(offset, limit) {
|
|
2888
|
+
return this.getListResource(ENDPOINTS.ITEM_FLING_EFFECT, offset, limit);
|
|
2889
|
+
}
|
|
2890
|
+
/** List Item Pockets. Page defaults to 20 entries from offset 0. */
|
|
2891
|
+
async listItemPockets(offset, limit) {
|
|
2892
|
+
return this.getListResource(ENDPOINTS.ITEM_POCKET, offset, limit);
|
|
2893
|
+
}
|
|
2894
|
+
};
|
|
2895
|
+
|
|
2896
|
+
//#endregion
|
|
2897
|
+
//#region src/clients/location.client.ts
|
|
2898
|
+
/**
|
|
2899
|
+
* ### Location Client
|
|
2900
|
+
*
|
|
2901
|
+
* Client used to access the Location Endpoints:
|
|
2902
|
+
*
|
|
2903
|
+
* - [Locations](https://pokeapi.co/docs/v2#locations)
|
|
2904
|
+
* - [Location Areas](https://pokeapi.co/docs/v2#location-areas)
|
|
2905
|
+
* - [Pal Park Areas](https://pokeapi.co/docs/v2#pal-park-areas)
|
|
2906
|
+
* - [Regions](https://pokeapi.co/docs/v2#regions)
|
|
2907
|
+
*
|
|
2908
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#locations-section)
|
|
2909
|
+
*/
|
|
2910
|
+
var LocationClient = class extends BaseClient {
|
|
2911
|
+
/** Get a Location by its name. */
|
|
2912
|
+
async getLocationByName(name) {
|
|
2913
|
+
return this.getResource(ENDPOINTS.LOCATION, name);
|
|
2914
|
+
}
|
|
2915
|
+
/** Get a Location by its ID. */
|
|
2916
|
+
async getLocationById(id) {
|
|
2917
|
+
return this.getResource(ENDPOINTS.LOCATION, id);
|
|
2918
|
+
}
|
|
2919
|
+
/** Get a Location Area by its name. */
|
|
2920
|
+
async getLocationAreaByName(name) {
|
|
2921
|
+
return this.getResource(ENDPOINTS.LOCATION_AREA, name);
|
|
2922
|
+
}
|
|
2923
|
+
/** Get a Location Area by its ID. */
|
|
2924
|
+
async getLocationAreaById(id) {
|
|
2925
|
+
return this.getResource(ENDPOINTS.LOCATION_AREA, id);
|
|
2926
|
+
}
|
|
2927
|
+
/** Get a Pal Park Area by its name. */
|
|
2928
|
+
async getPalParkAreaByName(name) {
|
|
2929
|
+
return this.getResource(ENDPOINTS.PALPARK_AREA, name);
|
|
2930
|
+
}
|
|
2931
|
+
/** Get a Pal Park Area by its ID. */
|
|
2932
|
+
async getPalParkAreaById(id) {
|
|
2933
|
+
return this.getResource(ENDPOINTS.PALPARK_AREA, id);
|
|
2934
|
+
}
|
|
2935
|
+
/** Get a Region by its name. */
|
|
2936
|
+
async getRegionByName(name) {
|
|
2937
|
+
return this.getResource(ENDPOINTS.REGION, name);
|
|
2938
|
+
}
|
|
2939
|
+
/** Get a Region by its ID. */
|
|
2940
|
+
async getRegionById(id) {
|
|
2941
|
+
return this.getResource(ENDPOINTS.REGION, id);
|
|
2942
|
+
}
|
|
2943
|
+
/** List Locations. Page defaults to 20 entries from offset 0. */
|
|
2944
|
+
async listLocations(offset, limit) {
|
|
2945
|
+
return this.getListResource(ENDPOINTS.LOCATION, offset, limit);
|
|
2946
|
+
}
|
|
2947
|
+
/** List Location Areas. Page defaults to 20 entries from offset 0. */
|
|
2948
|
+
async listLocationAreas(offset, limit) {
|
|
2949
|
+
return this.getListResource(ENDPOINTS.LOCATION_AREA, offset, limit);
|
|
2950
|
+
}
|
|
2951
|
+
/** List Pal Park Areas. Page defaults to 20 entries from offset 0. */
|
|
2952
|
+
async listPalParkAreas(offset, limit) {
|
|
2953
|
+
return this.getListResource(ENDPOINTS.PALPARK_AREA, offset, limit);
|
|
2954
|
+
}
|
|
2955
|
+
/** List Regions. Page defaults to 20 entries from offset 0. */
|
|
2956
|
+
async listRegions(offset, limit) {
|
|
2957
|
+
return this.getListResource(ENDPOINTS.REGION, offset, limit);
|
|
2958
|
+
}
|
|
2959
|
+
};
|
|
2960
|
+
|
|
2961
|
+
//#endregion
|
|
2962
|
+
//#region src/clients/machine.client.ts
|
|
2963
|
+
/**
|
|
2964
|
+
* ### Machine Client
|
|
2965
|
+
*
|
|
2966
|
+
* Client used to access the Machine Endpoints:
|
|
2967
|
+
*
|
|
2968
|
+
* - [Machines](https://pokeapi.co/docs/v2#machines)
|
|
2969
|
+
*
|
|
2970
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#machines-section)
|
|
2971
|
+
*/
|
|
2972
|
+
var MachineClient = class extends BaseClient {
|
|
2973
|
+
/** Get a Machine by its ID. */
|
|
2974
|
+
async getMachineById(id) {
|
|
2975
|
+
return this.getResource(ENDPOINTS.MACHINE, id);
|
|
2976
|
+
}
|
|
2977
|
+
/** List Machines. Page defaults to 20 entries from offset 0. */
|
|
2978
|
+
async listMachines(offset, limit) {
|
|
2979
|
+
return this.getUnnamedListResource(ENDPOINTS.MACHINE, offset, limit);
|
|
2980
|
+
}
|
|
2981
|
+
};
|
|
2982
|
+
|
|
2983
|
+
//#endregion
|
|
2984
|
+
//#region src/clients/move.client.ts
|
|
2985
|
+
/**
|
|
2986
|
+
* ### Move Client
|
|
2987
|
+
*
|
|
2988
|
+
* Client used to access the Move Endpoints:
|
|
2989
|
+
*
|
|
2990
|
+
* - [Moves](https://pokeapi.co/docs/v2#moves)
|
|
2991
|
+
* - [Move Ailments](https://pokeapi.co/docs/v2#move-ailments)
|
|
2992
|
+
* - [Move Battle Styles](https://pokeapi.co/docs/v2#move-battle-styles)
|
|
2993
|
+
* - [Move Categories](https://pokeapi.co/docs/v2#move-categories)
|
|
2994
|
+
* - [Move Damage Classes](https://pokeapi.co/docs/v2#move-damage-classes)
|
|
2995
|
+
* - [Move Learn Methods](https://pokeapi.co/docs/v2#move-learn-methods)
|
|
2996
|
+
* - [Move Targets](https://pokeapi.co/docs/v2#move-targets)
|
|
2997
|
+
*
|
|
2998
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#moves-section)
|
|
2999
|
+
*/
|
|
3000
|
+
var MoveClient = class extends BaseClient {
|
|
3001
|
+
/** Get a Move by its name. */
|
|
3002
|
+
async getMoveByName(name) {
|
|
3003
|
+
return this.getResource(ENDPOINTS.MOVE, name);
|
|
3004
|
+
}
|
|
3005
|
+
/** Get a Move by its ID. */
|
|
3006
|
+
async getMoveById(id) {
|
|
3007
|
+
return this.getResource(ENDPOINTS.MOVE, id);
|
|
3008
|
+
}
|
|
3009
|
+
/** Get a Move Ailment by its name. */
|
|
3010
|
+
async getMoveAilmentByName(name) {
|
|
3011
|
+
return this.getResource(ENDPOINTS.MOVE_AILMENT, name);
|
|
3012
|
+
}
|
|
3013
|
+
/** Get a Move Ailment by its ID. */
|
|
3014
|
+
async getMoveAilmentById(id) {
|
|
3015
|
+
return this.getResource(ENDPOINTS.MOVE_AILMENT, id);
|
|
3016
|
+
}
|
|
3017
|
+
/** Get a Move Battle Style by its name. */
|
|
3018
|
+
async getMoveBattleStyleByName(name) {
|
|
3019
|
+
return this.getResource(ENDPOINTS.MOVE_BATTLE_STYLE, name);
|
|
3020
|
+
}
|
|
3021
|
+
/** Get a Move Battle Style by its ID. */
|
|
3022
|
+
async getMoveBattleStyleById(id) {
|
|
3023
|
+
return this.getResource(ENDPOINTS.MOVE_BATTLE_STYLE, id);
|
|
3024
|
+
}
|
|
3025
|
+
/** Get a Move Category by its name. */
|
|
3026
|
+
async getMoveCategoryByName(name) {
|
|
3027
|
+
return this.getResource(ENDPOINTS.MOVE_CATEGORY, name);
|
|
3028
|
+
}
|
|
3029
|
+
/** Get a Move Category by its ID. */
|
|
3030
|
+
async getMoveCategoryById(id) {
|
|
3031
|
+
return this.getResource(ENDPOINTS.MOVE_CATEGORY, id);
|
|
3032
|
+
}
|
|
3033
|
+
/** Get a Move Damage Class by its name. */
|
|
3034
|
+
async getMoveDamageClassByName(name) {
|
|
3035
|
+
return this.getResource(ENDPOINTS.MOVE_DAMAGE_CLASS, name);
|
|
3036
|
+
}
|
|
3037
|
+
/** Get a Move Damage Class by its ID. */
|
|
3038
|
+
async getMoveDamageClassById(id) {
|
|
3039
|
+
return this.getResource(ENDPOINTS.MOVE_DAMAGE_CLASS, id);
|
|
3040
|
+
}
|
|
3041
|
+
/** Get a Move Learn Method by its name. */
|
|
3042
|
+
async getMoveLearnMethodByName(name) {
|
|
3043
|
+
return this.getResource(ENDPOINTS.MOVE_LEARN_METHOD, name);
|
|
3044
|
+
}
|
|
3045
|
+
/** Get a Move Learn Method by its ID. */
|
|
3046
|
+
async getMoveLearnMethodById(id) {
|
|
3047
|
+
return this.getResource(ENDPOINTS.MOVE_LEARN_METHOD, id);
|
|
3048
|
+
}
|
|
3049
|
+
/** Get a Move Target by its name. */
|
|
3050
|
+
async getMoveTargetByName(name) {
|
|
3051
|
+
return this.getResource(ENDPOINTS.MOVE_TARGET, name);
|
|
3052
|
+
}
|
|
3053
|
+
/** Get a Move Target by its ID. */
|
|
3054
|
+
async getMoveTargetById(id) {
|
|
3055
|
+
return this.getResource(ENDPOINTS.MOVE_TARGET, id);
|
|
3056
|
+
}
|
|
3057
|
+
/** List Moves. Page defaults to 20 entries from offset 0. */
|
|
3058
|
+
async listMoves(offset, limit) {
|
|
3059
|
+
return this.getListResource(ENDPOINTS.MOVE, offset, limit);
|
|
3060
|
+
}
|
|
3061
|
+
/** List Move Ailments. Page defaults to 20 entries from offset 0. */
|
|
3062
|
+
async listMoveAilments(offset, limit) {
|
|
3063
|
+
return this.getListResource(ENDPOINTS.MOVE_AILMENT, offset, limit);
|
|
3064
|
+
}
|
|
3065
|
+
/** List Move Battle Styles. Page defaults to 20 entries from offset 0. */
|
|
3066
|
+
async listMoveBattleStyles(offset, limit) {
|
|
3067
|
+
return this.getListResource(ENDPOINTS.MOVE_BATTLE_STYLE, offset, limit);
|
|
3068
|
+
}
|
|
3069
|
+
/** List Move Categories. Page defaults to 20 entries from offset 0. */
|
|
3070
|
+
async listMoveCategories(offset, limit) {
|
|
3071
|
+
return this.getListResource(ENDPOINTS.MOVE_CATEGORY, offset, limit);
|
|
3072
|
+
}
|
|
3073
|
+
/** List Move Damage Classes. Page defaults to 20 entries from offset 0. */
|
|
3074
|
+
async listMoveDamageClasses(offset, limit) {
|
|
3075
|
+
return this.getListResource(ENDPOINTS.MOVE_DAMAGE_CLASS, offset, limit);
|
|
3076
|
+
}
|
|
3077
|
+
/** List Move Learn Methods. Page defaults to 20 entries from offset 0. */
|
|
3078
|
+
async listMoveLearnMethods(offset, limit) {
|
|
3079
|
+
return this.getListResource(ENDPOINTS.MOVE_LEARN_METHOD, offset, limit);
|
|
3080
|
+
}
|
|
3081
|
+
/** List Move Targets. Page defaults to 20 entries from offset 0. */
|
|
3082
|
+
async listMoveTargets(offset, limit) {
|
|
3083
|
+
return this.getListResource(ENDPOINTS.MOVE_TARGET, offset, limit);
|
|
3084
|
+
}
|
|
3085
|
+
};
|
|
3086
|
+
|
|
3087
|
+
//#endregion
|
|
3088
|
+
//#region src/clients/pokemon.client.ts
|
|
3089
|
+
/**
|
|
3090
|
+
* ### Pokémon Client
|
|
3091
|
+
*
|
|
3092
|
+
* Client used to access the Pokémon Endpoints:
|
|
3093
|
+
*
|
|
3094
|
+
* - [Abilities](https://pokeapi.co/docs/v2#abilities)
|
|
3095
|
+
* - [Characteristics](https://pokeapi.co/docs/v2#characteristics)
|
|
3096
|
+
* - [Egg Groups](https://pokeapi.co/docs/v2#egg-groups)
|
|
3097
|
+
* - [Genders](https://pokeapi.co/docs/v2#genders)
|
|
3098
|
+
* - [Growth Rates](https://pokeapi.co/docs/v2#growth-rates)
|
|
3099
|
+
* - [Natures](https://pokeapi.co/docs/v2#natures)
|
|
3100
|
+
* - [Pokéathlon Stats](https://pokeapi.co/docs/v2#pokeathlon-stats)
|
|
3101
|
+
* - [Pokémon](https://pokeapi.co/docs/v2#pokemon)
|
|
3102
|
+
* - [Pokémon Location Areas](https://pokeapi.co/docs/v2#pokemon-location-areas)
|
|
3103
|
+
* - [Pokémon Colors](https://pokeapi.co/docs/v2#pokemon-colors)
|
|
3104
|
+
* - [Pokémon Forms](https://pokeapi.co/docs/v2#pokemon-forms)
|
|
3105
|
+
* - [Pokémon Habitats](https://pokeapi.co/docs/v2#pokemon-habitats)
|
|
3106
|
+
* - [Pokémon Shapes](https://pokeapi.co/docs/v2#pokemon-shapes)
|
|
3107
|
+
* - [Pokémon Species](https://pokeapi.co/docs/v2#pokemon-species)
|
|
3108
|
+
* - [Stats](https://pokeapi.co/docs/v2#stats)
|
|
3109
|
+
* - [Types](https://pokeapi.co/docs/v2#types)
|
|
3110
|
+
*
|
|
3111
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#pokemon-section)
|
|
3112
|
+
*/
|
|
3113
|
+
var PokemonClient = class extends BaseClient {
|
|
3114
|
+
/** Get an Ability by its name. */
|
|
3115
|
+
async getAbilityByName(name) {
|
|
3116
|
+
return this.getResource(ENDPOINTS.ABILITY, name);
|
|
3117
|
+
}
|
|
3118
|
+
/** Get an Ability by its ID. */
|
|
3119
|
+
async getAbilityById(id) {
|
|
3120
|
+
return this.getResource(ENDPOINTS.ABILITY, id);
|
|
3121
|
+
}
|
|
3122
|
+
/** Get a Characteristic by its ID. */
|
|
3123
|
+
async getCharacteristicById(id) {
|
|
3124
|
+
return this.getResource(ENDPOINTS.CHARACTERISTIC, id);
|
|
3125
|
+
}
|
|
3126
|
+
/** Get an Egg Group by its name. */
|
|
3127
|
+
async getEggGroupByName(name) {
|
|
3128
|
+
return this.getResource(ENDPOINTS.EGG_GROUP, name);
|
|
3129
|
+
}
|
|
3130
|
+
/** Get an Egg Group by its ID. */
|
|
3131
|
+
async getEggGroupById(id) {
|
|
3132
|
+
return this.getResource(ENDPOINTS.EGG_GROUP, id);
|
|
3133
|
+
}
|
|
3134
|
+
/** Get a Gender by its name. */
|
|
3135
|
+
async getGenderByName(name) {
|
|
3136
|
+
return this.getResource(ENDPOINTS.GENDER, name);
|
|
3137
|
+
}
|
|
3138
|
+
/** Get a Gender by its ID. */
|
|
3139
|
+
async getGenderById(id) {
|
|
3140
|
+
return this.getResource(ENDPOINTS.GENDER, id);
|
|
3141
|
+
}
|
|
3142
|
+
/** Get a Growth Rate by its name. */
|
|
3143
|
+
async getGrowthRateByName(name) {
|
|
3144
|
+
return this.getResource(ENDPOINTS.GROWTH_RATE, name);
|
|
3145
|
+
}
|
|
3146
|
+
/** Get a Growth Rate by its ID. */
|
|
3147
|
+
async getGrowthRateById(id) {
|
|
3148
|
+
return this.getResource(ENDPOINTS.GROWTH_RATE, id);
|
|
3149
|
+
}
|
|
3150
|
+
/** Get a Nature by its name. */
|
|
3151
|
+
async getNatureByName(name) {
|
|
3152
|
+
return this.getResource(ENDPOINTS.NATURE, name);
|
|
3153
|
+
}
|
|
3154
|
+
/** Get a Nature by its ID. */
|
|
3155
|
+
async getNatureById(id) {
|
|
3156
|
+
return this.getResource(ENDPOINTS.NATURE, id);
|
|
3157
|
+
}
|
|
3158
|
+
/** Get a Pokéathlon Stat by its name. */
|
|
3159
|
+
async getPokeathlonStatByName(name) {
|
|
3160
|
+
return this.getResource(ENDPOINTS.POKEATHLON_STAT, name);
|
|
3161
|
+
}
|
|
3162
|
+
/** Get a Pokéathlon Stat by its ID. */
|
|
3163
|
+
async getPokeathlonStatById(id) {
|
|
3164
|
+
return this.getResource(ENDPOINTS.POKEATHLON_STAT, id);
|
|
3165
|
+
}
|
|
3166
|
+
/** Get a Pokémon by its name. */
|
|
3167
|
+
async getPokemonByName(name) {
|
|
3168
|
+
return this.getResource(ENDPOINTS.POKEMON, name);
|
|
3169
|
+
}
|
|
3170
|
+
/** Get a Pokémon by its ID. */
|
|
3171
|
+
async getPokemonById(id) {
|
|
3172
|
+
return this.getResource(ENDPOINTS.POKEMON, id);
|
|
3173
|
+
}
|
|
3174
|
+
/**
|
|
3175
|
+
* Get the areas a Pokémon can be encountered in, by its ID.
|
|
3176
|
+
* @returns Every location area the Pokémon appears in, with its encounter details.
|
|
3177
|
+
*/
|
|
3178
|
+
async getPokemonLocationAreaById(id) {
|
|
3179
|
+
return this.getResource(ENDPOINTS.POKEMON, id, "encounters");
|
|
3180
|
+
}
|
|
3181
|
+
/** Get a Pokémon Color by its name. */
|
|
3182
|
+
async getPokemonColorByName(name) {
|
|
3183
|
+
return this.getResource(ENDPOINTS.POKEMON_COLOR, name);
|
|
3184
|
+
}
|
|
3185
|
+
/** Get a Pokémon Color by its ID. */
|
|
3186
|
+
async getPokemonColorById(id) {
|
|
3187
|
+
return this.getResource(ENDPOINTS.POKEMON_COLOR, id);
|
|
3188
|
+
}
|
|
3189
|
+
/** Get a Pokémon Form by its name. */
|
|
3190
|
+
async getPokemonFormByName(name) {
|
|
3191
|
+
return this.getResource(ENDPOINTS.POKEMON_FORM, name);
|
|
3192
|
+
}
|
|
3193
|
+
/** Get a Pokémon Form by its ID. */
|
|
3194
|
+
async getPokemonFormById(id) {
|
|
3195
|
+
return this.getResource(ENDPOINTS.POKEMON_FORM, id);
|
|
3196
|
+
}
|
|
3197
|
+
/** Get a Pokémon Habitat by its name. */
|
|
3198
|
+
async getPokemonHabitatByName(name) {
|
|
3199
|
+
return this.getResource(ENDPOINTS.POKEMON_HABITAT, name);
|
|
3200
|
+
}
|
|
3201
|
+
/** Get a Pokémon Habitat by its ID. */
|
|
3202
|
+
async getPokemonHabitatById(id) {
|
|
3203
|
+
return this.getResource(ENDPOINTS.POKEMON_HABITAT, id);
|
|
3204
|
+
}
|
|
3205
|
+
/** Get a Pokémon Shape by its name. */
|
|
3206
|
+
async getPokemonShapeByName(name) {
|
|
3207
|
+
return this.getResource(ENDPOINTS.POKEMON_SHAPE, name);
|
|
3208
|
+
}
|
|
3209
|
+
/** Get a Pokémon Shape by its ID. */
|
|
3210
|
+
async getPokemonShapeById(id) {
|
|
3211
|
+
return this.getResource(ENDPOINTS.POKEMON_SHAPE, id);
|
|
3212
|
+
}
|
|
3213
|
+
/** Get a Pokémon Species by its name. */
|
|
3214
|
+
async getPokemonSpeciesByName(name) {
|
|
3215
|
+
return this.getResource(ENDPOINTS.POKEMON_SPECIES, name);
|
|
3216
|
+
}
|
|
3217
|
+
/** Get a Pokémon Species by its ID. */
|
|
3218
|
+
async getPokemonSpeciesById(id) {
|
|
3219
|
+
return this.getResource(ENDPOINTS.POKEMON_SPECIES, id);
|
|
3220
|
+
}
|
|
3221
|
+
/** Get a Stat by its name. */
|
|
3222
|
+
async getStatByName(name) {
|
|
3223
|
+
return this.getResource(ENDPOINTS.STAT, name);
|
|
3224
|
+
}
|
|
3225
|
+
/** Get a Stat by its ID. */
|
|
3226
|
+
async getStatById(id) {
|
|
3227
|
+
return this.getResource(ENDPOINTS.STAT, id);
|
|
3228
|
+
}
|
|
3229
|
+
/** Get a Type by its name. */
|
|
3230
|
+
async getTypeByName(name) {
|
|
3231
|
+
return this.getResource(ENDPOINTS.TYPE, name);
|
|
3232
|
+
}
|
|
3233
|
+
/** Get a Type by its ID. */
|
|
3234
|
+
async getTypeById(id) {
|
|
3235
|
+
return this.getResource(ENDPOINTS.TYPE, id);
|
|
3236
|
+
}
|
|
3237
|
+
/** List Abilities. Page defaults to 20 entries from offset 0. */
|
|
3238
|
+
async listAbilities(offset, limit) {
|
|
3239
|
+
return this.getListResource(ENDPOINTS.ABILITY, offset, limit);
|
|
3240
|
+
}
|
|
3241
|
+
/** List Characteristics. Page defaults to 20 entries from offset 0. */
|
|
3242
|
+
async listCharacteristics(offset, limit) {
|
|
3243
|
+
return this.getUnnamedListResource(ENDPOINTS.CHARACTERISTIC, offset, limit);
|
|
3244
|
+
}
|
|
3245
|
+
/** List Egg Groups. Page defaults to 20 entries from offset 0. */
|
|
3246
|
+
async listEggGroups(offset, limit) {
|
|
3247
|
+
return this.getListResource(ENDPOINTS.EGG_GROUP, offset, limit);
|
|
3248
|
+
}
|
|
3249
|
+
/** List Genders. Page defaults to 20 entries from offset 0. */
|
|
3250
|
+
async listGenders(offset, limit) {
|
|
3251
|
+
return this.getListResource(ENDPOINTS.GENDER, offset, limit);
|
|
3252
|
+
}
|
|
3253
|
+
/** List Growth Rates. Page defaults to 20 entries from offset 0. */
|
|
3254
|
+
async listGrowthRates(offset, limit) {
|
|
3255
|
+
return this.getListResource(ENDPOINTS.GROWTH_RATE, offset, limit);
|
|
3256
|
+
}
|
|
3257
|
+
/** List Natures. Page defaults to 20 entries from offset 0. */
|
|
3258
|
+
async listNatures(offset, limit) {
|
|
3259
|
+
return this.getListResource(ENDPOINTS.NATURE, offset, limit);
|
|
3260
|
+
}
|
|
3261
|
+
/** List Pokéathlon Stats. Page defaults to 20 entries from offset 0. */
|
|
3262
|
+
async listPokeathlonStats(offset, limit) {
|
|
3263
|
+
return this.getListResource(ENDPOINTS.POKEATHLON_STAT, offset, limit);
|
|
3264
|
+
}
|
|
3265
|
+
/** List Pokémon. Page defaults to 20 entries from offset 0. */
|
|
3266
|
+
async listPokemons(offset, limit) {
|
|
3267
|
+
return this.getListResource(ENDPOINTS.POKEMON, offset, limit);
|
|
3268
|
+
}
|
|
3269
|
+
/** List Pokémon Colors. Page defaults to 20 entries from offset 0. */
|
|
3270
|
+
async listPokemonColors(offset, limit) {
|
|
3271
|
+
return this.getListResource(ENDPOINTS.POKEMON_COLOR, offset, limit);
|
|
3272
|
+
}
|
|
3273
|
+
/** List Pokémon Forms. Page defaults to 20 entries from offset 0. */
|
|
3274
|
+
async listPokemonForms(offset, limit) {
|
|
3275
|
+
return this.getListResource(ENDPOINTS.POKEMON_FORM, offset, limit);
|
|
3276
|
+
}
|
|
3277
|
+
/** List Pokémon Habitats. Page defaults to 20 entries from offset 0. */
|
|
3278
|
+
async listPokemonHabitats(offset, limit) {
|
|
3279
|
+
return this.getListResource(ENDPOINTS.POKEMON_HABITAT, offset, limit);
|
|
3280
|
+
}
|
|
3281
|
+
/** List Pokémon Shapes. Page defaults to 20 entries from offset 0. */
|
|
3282
|
+
async listPokemonShapes(offset, limit) {
|
|
3283
|
+
return this.getListResource(ENDPOINTS.POKEMON_SHAPE, offset, limit);
|
|
3284
|
+
}
|
|
3285
|
+
/** List Pokémon Species. Page defaults to 20 entries from offset 0. */
|
|
3286
|
+
async listPokemonSpecies(offset, limit) {
|
|
3287
|
+
return this.getListResource(ENDPOINTS.POKEMON_SPECIES, offset, limit);
|
|
3288
|
+
}
|
|
3289
|
+
/** List Stats. Page defaults to 20 entries from offset 0. */
|
|
3290
|
+
async listStats(offset, limit) {
|
|
3291
|
+
return this.getListResource(ENDPOINTS.STAT, offset, limit);
|
|
3292
|
+
}
|
|
3293
|
+
/** List Types. Page defaults to 20 entries from offset 0. */
|
|
3294
|
+
async listTypes(offset, limit) {
|
|
3295
|
+
return this.getListResource(ENDPOINTS.TYPE, offset, limit);
|
|
3296
|
+
}
|
|
3297
|
+
};
|
|
3298
|
+
|
|
3299
|
+
//#endregion
|
|
3300
|
+
//#region src/clients/utility.client.ts
|
|
3301
|
+
/**
|
|
3302
|
+
* ### Utility Client
|
|
3303
|
+
*
|
|
3304
|
+
* Client used to access the Utility Endpoints:
|
|
3305
|
+
*
|
|
3306
|
+
* - [Languages](https://pokeapi.co/docs/v2#languages)
|
|
3307
|
+
* - [Resources](https://pokeapi.co/docs/v2#resource-listspagination-section)
|
|
3308
|
+
*
|
|
3309
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2#utility-section)
|
|
3310
|
+
*/
|
|
3311
|
+
var UtilityClient = class extends BaseClient {
|
|
3312
|
+
/** Get a Language by its ID. */
|
|
3313
|
+
async getLanguageById(id) {
|
|
3314
|
+
return this.getResource(ENDPOINTS.LANGUAGE, id);
|
|
3315
|
+
}
|
|
3316
|
+
/** Get a Language by its name. */
|
|
3317
|
+
async getLanguageByName(name) {
|
|
3318
|
+
return this.getResource(ENDPOINTS.LANGUAGE, name);
|
|
3319
|
+
}
|
|
3320
|
+
/**
|
|
3321
|
+
* Get any resource by its URL, or by a link taken from another response.
|
|
3322
|
+
*
|
|
3323
|
+
* ```ts
|
|
3324
|
+
* const pokemon = await api.pokemon.getPokemonByName('luxray');
|
|
3325
|
+
* const species = await api.utility.getResourceByUrl(pokemon.species);
|
|
3326
|
+
* // ^? PokemonSpecies
|
|
3327
|
+
* ```
|
|
3328
|
+
*
|
|
3329
|
+
* Every client carries {@link BaseClient.resolve}, which does the same thing;
|
|
3330
|
+
* this is the name it went out under, and it stays.
|
|
3331
|
+
*
|
|
3332
|
+
* @param resource The absolute URL of the resource, or a link to it.
|
|
3333
|
+
* @returns The resource the URL points at.
|
|
3334
|
+
* @throws {TypeError} If the URL is not valid, or names no PokéAPI endpoint.
|
|
3335
|
+
*/
|
|
3336
|
+
async getResourceByUrl(resource) {
|
|
3337
|
+
return this.resolve(resource);
|
|
3338
|
+
}
|
|
3339
|
+
/** List Languages. Page defaults to 20 entries from offset 0. */
|
|
3340
|
+
listLanguages(offset, limit) {
|
|
3341
|
+
return this.getListResource(ENDPOINTS.LANGUAGE, offset, limit);
|
|
3342
|
+
}
|
|
3343
|
+
};
|
|
3344
|
+
|
|
3345
|
+
//#endregion
|
|
3346
|
+
//#region src/clients/main.client.ts
|
|
3347
|
+
/**
|
|
3348
|
+
* ### Main Client
|
|
3349
|
+
*
|
|
3350
|
+
* The main client used to access all the PokéAPI Endpoints:
|
|
3351
|
+
*
|
|
3352
|
+
* - [Berries](https://pokeapi.co/docs/v2#berries-section)
|
|
3353
|
+
* - [Contests](https://pokeapi.co/docs/v2#contests-section)
|
|
3354
|
+
* - [Currencies](https://pokeapi.co/docs/v2#currencies-section)
|
|
3355
|
+
* - [Encounters](https://pokeapi.co/docs/v2#encounters-section)
|
|
3356
|
+
* - [Evolution](https://pokeapi.co/docs/v2#evolution-section)
|
|
3357
|
+
* - [Games](https://pokeapi.co/docs/v2#games-section)
|
|
3358
|
+
* - [Items](https://pokeapi.co/docs/v2#items-section)
|
|
3359
|
+
* - [Locations](https://pokeapi.co/docs/v2#locations-section)
|
|
3360
|
+
* - [Machines](https://pokeapi.co/docs/v2#machines-section)
|
|
3361
|
+
* - [Moves](https://pokeapi.co/docs/v2#moves-section)
|
|
3362
|
+
* - [Pokémon](https://pokeapi.co/docs/v2#pokemon-section)
|
|
3363
|
+
* - [Utility](https://pokeapi.co/docs/v2#utility-section)
|
|
3364
|
+
*
|
|
3365
|
+
* All the clients below share a single transport, so a resource fetched through
|
|
3366
|
+
* one of them is served from cache by the rest — and two of them asking for the
|
|
3367
|
+
* same URL at once make one round trip, not two.
|
|
3368
|
+
*
|
|
3369
|
+
* Composes its sections rather than inheriting from them: it extends
|
|
3370
|
+
* {@link ClientFacade}, not {@link BaseClient}, so it carries no endpoint of its
|
|
3371
|
+
* own.
|
|
3372
|
+
*
|
|
3373
|
+
* See [PokéAPI Documentation](https://pokeapi.co/docs/v2)
|
|
3374
|
+
*/
|
|
3375
|
+
var MainClient = class extends ClientFacade {
|
|
3376
|
+
berry;
|
|
3377
|
+
contest;
|
|
3378
|
+
currency;
|
|
3379
|
+
encounter;
|
|
3380
|
+
evolution;
|
|
3381
|
+
game;
|
|
3382
|
+
item;
|
|
3383
|
+
location;
|
|
3384
|
+
machine;
|
|
3385
|
+
move;
|
|
3386
|
+
pokemon;
|
|
3387
|
+
utility;
|
|
3388
|
+
constructor(source) {
|
|
3389
|
+
const transport = source instanceof Transport ? source : Transport.create(source);
|
|
3390
|
+
super(transport);
|
|
3391
|
+
this.berry = new BerryClient(transport);
|
|
3392
|
+
this.contest = new ContestClient(transport);
|
|
3393
|
+
this.currency = new CurrencyClient(transport);
|
|
3394
|
+
this.encounter = new EncounterClient(transport);
|
|
3395
|
+
this.evolution = new EvolutionClient(transport);
|
|
3396
|
+
this.game = new GameClient(transport);
|
|
3397
|
+
this.item = new ItemClient(transport);
|
|
3398
|
+
this.location = new LocationClient(transport);
|
|
3399
|
+
this.machine = new MachineClient(transport);
|
|
3400
|
+
this.move = new MoveClient(transport);
|
|
3401
|
+
this.pokemon = new PokemonClient(transport);
|
|
3402
|
+
this.utility = new UtilityClient(transport);
|
|
3403
|
+
}
|
|
3404
|
+
};
|
|
3405
|
+
|
|
3406
|
+
//#endregion
|
|
3407
|
+
//#region src/utils/evolution.ts
|
|
3408
|
+
/** The details of a link, narrowed to one version group when asked for. */
|
|
3409
|
+
const detailsFor = (link, versionGroup) => versionGroup === void 0 ? link.evolution_details : link.evolution_details.filter((detail) => detail.version_group.name === versionGroup);
|
|
3410
|
+
/**
|
|
3411
|
+
* Flattens an evolution chain into one step per evolution, depth-first in the
|
|
3412
|
+
* order the API lists them.
|
|
3413
|
+
*
|
|
3414
|
+
* ```ts
|
|
3415
|
+
* const species = await api.pokemon.getPokemonSpeciesByName('eevee');
|
|
3416
|
+
* const chain = await api.resolve(species.evolution_chain);
|
|
3417
|
+
*
|
|
3418
|
+
* for (const step of flattenChain(chain)) {
|
|
3419
|
+
* console.log(`${step.from.name} → ${step.to.name}`);
|
|
3420
|
+
* }
|
|
3421
|
+
* ```
|
|
3422
|
+
*
|
|
3423
|
+
* The root is not a step: it is what the chain starts from, and the API gives it
|
|
3424
|
+
* no `evolution_details` to describe.
|
|
3425
|
+
*
|
|
3426
|
+
* `versionGroup` keeps only the details tagged with that version group, which is
|
|
3427
|
+
* what picks the Leaf Stone out of Leafeon's six alternatives:
|
|
3428
|
+
*
|
|
3429
|
+
* ```ts
|
|
3430
|
+
* flattenChain(chain, { versionGroup: 'sword-shield' });
|
|
3431
|
+
* ```
|
|
3432
|
+
*
|
|
3433
|
+
* That tag is the game which *introduced* the method, not every game it applies
|
|
3434
|
+
* in: Eevee's Water Stone is tagged `red-blue` alone, so filtering to
|
|
3435
|
+
* `sword-shield` drops Vaporeon even though Sword/Shield evolves it the same way
|
|
3436
|
+
* it always did. The question this answers is what a game changed.
|
|
3437
|
+
*
|
|
3438
|
+
* A step with nothing left after that is dropped, but the chain below it is
|
|
3439
|
+
* still walked — every edge is filtered on its own terms, and `depth` stays the
|
|
3440
|
+
* position in the chain rather than in the result.
|
|
3441
|
+
*/
|
|
3442
|
+
const flattenChain = (chain, options) => {
|
|
3443
|
+
const collect = (link, depth) => link.evolves_to.flatMap((next) => {
|
|
3444
|
+
const details = detailsFor(next, options?.versionGroup);
|
|
3445
|
+
const below = collect(next, depth + 1);
|
|
3446
|
+
if (details.length === 0) return below;
|
|
3447
|
+
return [{
|
|
3448
|
+
from: link.species,
|
|
3449
|
+
to: next.species,
|
|
3450
|
+
details,
|
|
3451
|
+
depth,
|
|
3452
|
+
isBaby: next.is_baby
|
|
3453
|
+
}, ...below];
|
|
3454
|
+
});
|
|
3455
|
+
return collect(chain.chain, 1);
|
|
3456
|
+
};
|
|
3457
|
+
/**
|
|
3458
|
+
* The steps leading from the root of a chain to `species`.
|
|
3459
|
+
*
|
|
3460
|
+
* ```ts
|
|
3461
|
+
* pathTo(chain, 'dustox')?.map((step) => step.to.name); // ['cascoon', 'dustox']
|
|
3462
|
+
* ```
|
|
3463
|
+
*
|
|
3464
|
+
* Matched against the name the API gives a species, which is not the name a game
|
|
3465
|
+
* displays: `localize(species.names)` is `Papilord` in French and finds nothing
|
|
3466
|
+
* here. Pass the link itself when you have one.
|
|
3467
|
+
*
|
|
3468
|
+
* @returns The steps, `[]` when `species` is the root the chain starts from, and
|
|
3469
|
+
* `undefined` when the chain does not contain it. The two empty answers are
|
|
3470
|
+
* different questions, so they are different values.
|
|
3471
|
+
*/
|
|
3472
|
+
const pathTo = (chain, species) => {
|
|
3473
|
+
const wanted = typeof species === "string" ? species : species.name;
|
|
3474
|
+
const search = (link, trail) => {
|
|
3475
|
+
if (link.species.name === wanted) return trail;
|
|
3476
|
+
for (const next of link.evolves_to) {
|
|
3477
|
+
const step = {
|
|
3478
|
+
from: link.species,
|
|
3479
|
+
to: next.species,
|
|
3480
|
+
details: next.evolution_details,
|
|
3481
|
+
depth: trail.length + 1,
|
|
3482
|
+
isBaby: next.is_baby
|
|
3483
|
+
};
|
|
3484
|
+
const found = search(next, [...trail, step]);
|
|
3485
|
+
if (found !== void 0) return found;
|
|
3486
|
+
}
|
|
3487
|
+
};
|
|
3488
|
+
return search(chain.chain, []);
|
|
3489
|
+
};
|
|
3490
|
+
/**
|
|
3491
|
+
* One reader per field an {@link EvolutionDetail} can set, in the order the
|
|
3492
|
+
* requirements come out, each `null` when its field is unset.
|
|
3493
|
+
*/
|
|
3494
|
+
const READERS = [
|
|
3495
|
+
({ item }) => item === null ? null : {
|
|
3496
|
+
kind: "item",
|
|
3497
|
+
item
|
|
3498
|
+
},
|
|
3499
|
+
({ held_item: item }) => item === null ? null : {
|
|
3500
|
+
kind: "held-item",
|
|
3501
|
+
item
|
|
3502
|
+
},
|
|
3503
|
+
({ min_level: level }) => level === null ? null : {
|
|
3504
|
+
kind: "min-level",
|
|
3505
|
+
level
|
|
3506
|
+
},
|
|
3507
|
+
({ min_happiness: happiness }) => happiness === null ? null : {
|
|
3508
|
+
kind: "min-happiness",
|
|
3509
|
+
happiness
|
|
3510
|
+
},
|
|
3511
|
+
({ min_beauty: beauty }) => beauty === null ? null : {
|
|
3512
|
+
kind: "min-beauty",
|
|
3513
|
+
beauty
|
|
3514
|
+
},
|
|
3515
|
+
({ min_affection: affection }) => affection === null ? null : {
|
|
3516
|
+
kind: "min-affection",
|
|
3517
|
+
affection
|
|
3518
|
+
},
|
|
3519
|
+
({ known_move: move }) => move === null ? null : {
|
|
3520
|
+
kind: "known-move",
|
|
3521
|
+
move
|
|
3522
|
+
},
|
|
3523
|
+
({ known_move_type: type }) => type === null ? null : {
|
|
3524
|
+
kind: "known-move-type",
|
|
3525
|
+
type
|
|
3526
|
+
},
|
|
3527
|
+
({ used_move: move }) => move === null ? null : {
|
|
3528
|
+
kind: "used-move",
|
|
3529
|
+
move
|
|
3530
|
+
},
|
|
3531
|
+
({ min_move_count: count }) => count === null ? null : {
|
|
3532
|
+
kind: "min-move-count",
|
|
3533
|
+
count
|
|
3534
|
+
},
|
|
3535
|
+
({ min_steps: steps }) => steps === null ? null : {
|
|
3536
|
+
kind: "min-steps",
|
|
3537
|
+
steps
|
|
3538
|
+
},
|
|
3539
|
+
({ min_damage_taken: damage }) => damage === null ? null : {
|
|
3540
|
+
kind: "min-damage-taken",
|
|
3541
|
+
damage
|
|
3542
|
+
},
|
|
3543
|
+
({ location }) => location === null ? null : {
|
|
3544
|
+
kind: "location",
|
|
3545
|
+
location
|
|
3546
|
+
},
|
|
3547
|
+
({ region }) => region === null ? null : {
|
|
3548
|
+
kind: "region",
|
|
3549
|
+
region
|
|
3550
|
+
},
|
|
3551
|
+
({ time_of_day: time }) => time === "" ? null : {
|
|
3552
|
+
kind: "time-of-day",
|
|
3553
|
+
time
|
|
3554
|
+
},
|
|
3555
|
+
({ gender }) => gender === null ? null : {
|
|
3556
|
+
kind: "gender",
|
|
3557
|
+
gender
|
|
3558
|
+
},
|
|
3559
|
+
({ relative_physical_stats: comparison }) => comparison === null ? null : {
|
|
3560
|
+
kind: "relative-physical-stats",
|
|
3561
|
+
comparison
|
|
3562
|
+
},
|
|
3563
|
+
({ party_species: species }) => species === null ? null : {
|
|
3564
|
+
kind: "party-species",
|
|
3565
|
+
species
|
|
3566
|
+
},
|
|
3567
|
+
({ party_type: type }) => type === null ? null : {
|
|
3568
|
+
kind: "party-type",
|
|
3569
|
+
type
|
|
3570
|
+
},
|
|
3571
|
+
({ trade_species: species }) => species === null ? null : {
|
|
3572
|
+
kind: "trade-species",
|
|
3573
|
+
species
|
|
3574
|
+
},
|
|
3575
|
+
({ required_pokemon_form: form }) => form === null ? null : {
|
|
3576
|
+
kind: "required-form",
|
|
3577
|
+
form
|
|
3578
|
+
},
|
|
3579
|
+
({ evolved_pokemon_form: form }) => form === null ? null : {
|
|
3580
|
+
kind: "evolved-form",
|
|
3581
|
+
form
|
|
3582
|
+
},
|
|
3583
|
+
({ allowed_natures: natures }) => natures === null ? null : {
|
|
3584
|
+
kind: "allowed-natures",
|
|
3585
|
+
natures
|
|
3586
|
+
},
|
|
3587
|
+
({ condition_expression: condition }) => condition === null ? null : {
|
|
3588
|
+
kind: "condition",
|
|
3589
|
+
condition
|
|
3590
|
+
},
|
|
3591
|
+
({ needs_overworld_rain: rain }) => rain ? { kind: "needs-overworld-rain" } : null,
|
|
3592
|
+
({ turn_upside_down: upsideDown }) => upsideDown ? { kind: "turn-upside-down" } : null,
|
|
3593
|
+
({ near_special_rock: rock }) => rock ? { kind: "near-special-rock" } : null,
|
|
3594
|
+
({ needs_multiplayer: multiplayer }) => multiplayer ? { kind: "needs-multiplayer" } : null
|
|
3595
|
+
];
|
|
3596
|
+
/**
|
|
3597
|
+
* The conditions one {@link EvolutionDetail} sets out, with everything it left
|
|
3598
|
+
* unset dropped.
|
|
3599
|
+
*
|
|
3600
|
+
* ```ts
|
|
3601
|
+
* requirementsOf(step.details[0]); // eevee → umbreon
|
|
3602
|
+
* // [
|
|
3603
|
+
* // { kind: 'trigger', trigger: { name: 'level-up', … } },
|
|
3604
|
+
* // { kind: 'min-happiness', happiness: 160 },
|
|
3605
|
+
* // { kind: 'time-of-day', time: 'night' },
|
|
3606
|
+
* // { kind: 'required-form', form: { name: 'eevee', … } },
|
|
3607
|
+
* // ]
|
|
3608
|
+
* ```
|
|
3609
|
+
*
|
|
3610
|
+
* The trigger leads, so rendering the result is a walk over one array.
|
|
3611
|
+
*
|
|
3612
|
+
* Every field is tested against the value the API uses for "unset" rather than
|
|
3613
|
+
* for truthiness: `relative_physical_stats` is `0` when Attack has to equal
|
|
3614
|
+
* Defense, and `time_of_day` is `''`.
|
|
3615
|
+
*/
|
|
3616
|
+
const requirementsOf = (detail) => [{
|
|
3617
|
+
kind: "trigger",
|
|
3618
|
+
trigger: detail.trigger
|
|
3619
|
+
}, ...READERS.flatMap((read) => read(detail) ?? [])];
|
|
3620
|
+
/**
|
|
3621
|
+
* Every trigger as a verb phrase. Exhaustive over {@link EvolutionTriggerName},
|
|
3622
|
+
* so a trigger added to that union has to be given words here too.
|
|
3623
|
+
*/
|
|
3624
|
+
const TRIGGERS = {
|
|
3625
|
+
"level-up": "level up",
|
|
3626
|
+
trade: "trade",
|
|
3627
|
+
"use-item": "use an item",
|
|
3628
|
+
shed: "shed",
|
|
3629
|
+
spin: "spin",
|
|
3630
|
+
"tower-of-darkness": "train in the Tower of Darkness",
|
|
3631
|
+
"tower-of-waters": "train in the Tower of Waters",
|
|
3632
|
+
"three-critical-hits": "land three critical hits in one battle",
|
|
3633
|
+
"take-damage": "take damage",
|
|
3634
|
+
"in-battle-level-up": "level up during a battle",
|
|
3635
|
+
"agile-style-move": "use agile style moves",
|
|
3636
|
+
"strong-style-move": "use strong style moves",
|
|
3637
|
+
"recoil-damage": "take recoil damage",
|
|
3638
|
+
"use-move": "use a move",
|
|
3639
|
+
"three-defeated-bisharp": "defeat three pack-leading Bisharp",
|
|
3640
|
+
"gimmighoul-coins": "collect Gimmighoul Coins",
|
|
3641
|
+
"meltan-candies": "feed Meltan Candies in Pokémon GO",
|
|
3642
|
+
unclassified: "an unclassified method"
|
|
3643
|
+
};
|
|
3644
|
+
/** A resource name as prose: the API writes them kebab-cased and lower case. */
|
|
3645
|
+
const spaced = (resource) => resource.name.replaceAll("-", " ");
|
|
3646
|
+
/**
|
|
3647
|
+
* Every time of day as a phrase. Exhaustive over {@link EvolutionTimeOfDay}, so
|
|
3648
|
+
* a value added to that union has to be given words here too — `dusk` and
|
|
3649
|
+
* `full-moon` do not fit the "during the …" the other two take.
|
|
3650
|
+
*/
|
|
3651
|
+
const TIMES = {
|
|
3652
|
+
day: "during the day",
|
|
3653
|
+
night: "during the night",
|
|
3654
|
+
dusk: "at dusk",
|
|
3655
|
+
"full-moon": "under a full moon"
|
|
3656
|
+
};
|
|
3657
|
+
const GENDERS$1 = {
|
|
3658
|
+
1: "female",
|
|
3659
|
+
2: "male",
|
|
3660
|
+
3: "genderless"
|
|
3661
|
+
};
|
|
3662
|
+
/** Unknown ids name themselves, so a gender added upstream still renders. */
|
|
3663
|
+
const genderName = (gender) => GENDERS$1[gender] ?? `gender ${gender}`;
|
|
3664
|
+
const COMPARISONS = {
|
|
3665
|
+
"1": ">",
|
|
3666
|
+
"0": "=",
|
|
3667
|
+
"-1": "<"
|
|
3668
|
+
};
|
|
3669
|
+
/**
|
|
3670
|
+
* Builds the English table around a way of naming resources.
|
|
3671
|
+
*
|
|
3672
|
+
* Everything except the name is fixed; `namer` is the one thing a caller who
|
|
3673
|
+
* keeps the English sentence still has to replace, because `spaced` prints what
|
|
3674
|
+
* the API calls a resource and no localized name is derivable from it.
|
|
3675
|
+
*
|
|
3676
|
+
* ```ts
|
|
3677
|
+
* const names = new Map([['water-stone', 'Pedra da Água']]);
|
|
3678
|
+
*
|
|
3679
|
+
* requirementPhrases((resource) => names.get(resource.name) ?? resource.name);
|
|
3680
|
+
* ```
|
|
3681
|
+
*
|
|
3682
|
+
* @param namer How to write a resource out. Defaults to the API's own name, with
|
|
3683
|
+
* the hyphens turned to spaces.
|
|
3684
|
+
*/
|
|
3685
|
+
const requirementPhrases = (namer = spaced) => ({
|
|
3686
|
+
trigger: ({ trigger }) => TRIGGERS[trigger.name] ?? namer(trigger),
|
|
3687
|
+
item: ({ item }) => `use ${namer(item)}`,
|
|
3688
|
+
"held-item": ({ item }) => `holding ${namer(item)}`,
|
|
3689
|
+
"min-level": ({ level }) => `at level ${level}`,
|
|
3690
|
+
"min-happiness": ({ happiness }) => `with at least ${happiness} happiness`,
|
|
3691
|
+
"min-beauty": ({ beauty }) => `with at least ${beauty} beauty`,
|
|
3692
|
+
"min-affection": ({ affection }) => `with at least ${affection} affection`,
|
|
3693
|
+
"known-move": ({ move }) => `knowing ${namer(move)}`,
|
|
3694
|
+
"known-move-type": ({ type }) => `knowing a ${namer(type)}-type move`,
|
|
3695
|
+
"used-move": ({ move }) => `after using ${namer(move)}`,
|
|
3696
|
+
"min-move-count": ({ count }) => `${count} times`,
|
|
3697
|
+
"min-steps": ({ steps }) => `after ${steps} steps`,
|
|
3698
|
+
"min-damage-taken": ({ damage }) => `after taking ${damage} damage`,
|
|
3699
|
+
location: ({ location }) => `at ${namer(location)}`,
|
|
3700
|
+
region: ({ region }) => `in ${namer(region)}`,
|
|
3701
|
+
"time-of-day": ({ time }) => TIMES[time],
|
|
3702
|
+
gender: ({ gender }) => `as a ${genderName(gender)}`,
|
|
3703
|
+
"relative-physical-stats": ({ comparison }) => `with Attack ${COMPARISONS[String(comparison)]} Defense`,
|
|
3704
|
+
"party-species": ({ species }) => `with ${namer(species)} in the party`,
|
|
3705
|
+
"party-type": ({ type }) => `with a ${namer(type)}-type in the party`,
|
|
3706
|
+
"trade-species": ({ species }) => `traded for ${namer(species)}`,
|
|
3707
|
+
"required-form": ({ form }) => `in its ${namer(form)} form`,
|
|
3708
|
+
"evolved-form": ({ form }) => `into its ${namer(form)} form`,
|
|
3709
|
+
"allowed-natures": ({ natures }) => `with a ${natures.map((nature) => namer(nature)).join(" or ")} nature`,
|
|
3710
|
+
condition: ({ condition }) => condition.percentage_chance === null ? "" : `with a ${condition.percentage_chance}% chance`,
|
|
3711
|
+
"needs-overworld-rain": () => "while it is raining",
|
|
3712
|
+
"turn-upside-down": () => "with the console upside down",
|
|
3713
|
+
"near-special-rock": () => "near a special rock",
|
|
3714
|
+
"needs-multiplayer": () => "in multiplayer"
|
|
3715
|
+
});
|
|
3716
|
+
/**
|
|
3717
|
+
* ## Requirement Phrases
|
|
3718
|
+
* The English {@link formatRequirements} renders with, naming resources the way
|
|
3719
|
+
* the API does. Exported so a caller can replace the wording of one kind — or
|
|
3720
|
+
* all of them, in another language — without rebuilding the rest of the renderer
|
|
3721
|
+
* around it, and so an override can fall back to the default for what it does
|
|
3722
|
+
* not handle.
|
|
3723
|
+
*
|
|
3724
|
+
* ```ts
|
|
3725
|
+
* formatRequirements(requirements, {
|
|
3726
|
+
* phrases: { 'min-happiness': ({ happiness }) => `com ${happiness} de felicidade` },
|
|
3727
|
+
* });
|
|
3728
|
+
*
|
|
3729
|
+
* formatRequirements(requirements, {
|
|
3730
|
+
* phrases: {
|
|
3731
|
+
* trigger: (requirement) => MINE[requirement.trigger.name] ?? REQUIREMENT_PHRASES.trigger(requirement),
|
|
3732
|
+
* },
|
|
3733
|
+
* });
|
|
3734
|
+
* ```
|
|
3735
|
+
*/
|
|
3736
|
+
const REQUIREMENT_PHRASES = requirementPhrases();
|
|
3737
|
+
/**
|
|
3738
|
+
* The table built for a namer, kept so that rendering a list does not rebuild
|
|
3739
|
+
* twenty-nine closures per row. Weak, so a namer closed over a component's
|
|
3740
|
+
* props is not held alive by having been used once.
|
|
3741
|
+
*/
|
|
3742
|
+
const tables = /* @__PURE__ */ new WeakMap();
|
|
3743
|
+
const tableFor = (namer) => {
|
|
3744
|
+
if (namer === void 0) return REQUIREMENT_PHRASES;
|
|
3745
|
+
const built = tables.get(namer) ?? requirementPhrases(namer);
|
|
3746
|
+
tables.set(namer, built);
|
|
3747
|
+
return built;
|
|
3748
|
+
};
|
|
3749
|
+
/**
|
|
3750
|
+
* The table is keyed by `kind` and the union is discriminated by it, so the two
|
|
3751
|
+
* are known to line up — but only one entry at a time, which is not something an
|
|
3752
|
+
* index of the whole table can be written to say.
|
|
3753
|
+
*/
|
|
3754
|
+
const phrase = (requirement, phrases) => phrases[requirement.kind](requirement);
|
|
3755
|
+
/**
|
|
3756
|
+
* Renders requirements as an English phrase.
|
|
3757
|
+
*
|
|
3758
|
+
* ```ts
|
|
3759
|
+
* formatRequirements(requirementsOf(detail)); // eevee → umbreon
|
|
3760
|
+
* // 'level up, with at least 160 happiness, during the night, in its eevee form'
|
|
3761
|
+
* ```
|
|
3762
|
+
*
|
|
3763
|
+
* The only English in the library, and a separate export for that reason: an
|
|
3764
|
+
* application rendering its own copy — in its own language, or as anything other
|
|
3765
|
+
* than a sentence — drops this and the phrase table with it. Use
|
|
3766
|
+
* {@link requirementsOf} for that, or `phrases` to keep the sentence and change
|
|
3767
|
+
* the words:
|
|
3768
|
+
*
|
|
3769
|
+
* ```ts
|
|
3770
|
+
* formatRequirements(requirements, { phrases: { trade: () => 'by trade' } });
|
|
3771
|
+
* ```
|
|
3772
|
+
*
|
|
3773
|
+
* Resources are named the way the API names them, not the way a game displays
|
|
3774
|
+
* them. `localize(item.names)` is the display name, it costs a request, and
|
|
3775
|
+
* `name` is where it goes:
|
|
3776
|
+
*
|
|
3777
|
+
* ```ts
|
|
3778
|
+
* const items = await api.resolveAll(links);
|
|
3779
|
+
* const display = new Map(items.map((item) => [item.name, localize(item.names)?.name]));
|
|
3780
|
+
*
|
|
3781
|
+
* formatRequirements(requirements, { name: (resource) => display.get(resource.name) ?? resource.name });
|
|
3782
|
+
* // 'use Water Stone'
|
|
3783
|
+
* ```
|
|
3784
|
+
*
|
|
3785
|
+
* The two options are the two halves of a translation and are independent:
|
|
3786
|
+
* `phrases` is the words the library supplies, `name` the words the API does.
|
|
3787
|
+
*
|
|
3788
|
+
* A `use-item` trigger and the item it uses are one phrase, since "use an item,
|
|
3789
|
+
* use water stone" says it twice. That holds under `phrases` too: the trigger is
|
|
3790
|
+
* dropped before anything is rendered, so an overridden `item` is still what says
|
|
3791
|
+
* the item is used.
|
|
3792
|
+
*
|
|
3793
|
+
* A phrase that renders as `""` is left out of the sentence. The default table
|
|
3794
|
+
* does this for a `condition` with no `percentage_chance` — Milcery's spin, which
|
|
3795
|
+
* the trigger already names — and an override can do it to hide any kind.
|
|
3796
|
+
*/
|
|
3797
|
+
const formatRequirements = (requirements, options) => {
|
|
3798
|
+
const phrases = {
|
|
3799
|
+
...tableFor(options?.name),
|
|
3800
|
+
...options?.phrases
|
|
3801
|
+
};
|
|
3802
|
+
const usesItem = requirements.some((requirement) => requirement.kind === "item") && requirements.some((requirement) => requirement.kind === "trigger" && requirement.trigger.name === "use-item");
|
|
3803
|
+
return requirements.filter((requirement) => !(usesItem && requirement.kind === "trigger")).map((requirement) => phrase(requirement, phrases)).filter((text) => text !== "").join(", ");
|
|
3804
|
+
};
|
|
3805
|
+
|
|
3806
|
+
//#endregion
|
|
3807
|
+
//#region src/utils/localize.ts
|
|
3808
|
+
const optionsOf = (language) => {
|
|
3809
|
+
const options = typeof language === "string" ? { language } : language ?? {};
|
|
3810
|
+
return {
|
|
3811
|
+
...options,
|
|
3812
|
+
language: options.language ?? "en"
|
|
3813
|
+
};
|
|
3814
|
+
};
|
|
3815
|
+
/** Every entry written in one language, matched without regard to case. */
|
|
3816
|
+
const inLanguage = (entries, language) => {
|
|
3817
|
+
const wanted = language.toLowerCase();
|
|
3818
|
+
return entries.filter((entry) => entry.language.name.toLowerCase() === wanted);
|
|
3819
|
+
};
|
|
3820
|
+
/**
|
|
3821
|
+
* Picks the entry written in `language`, by the name the PokéAPI gives that
|
|
3822
|
+
* language: `en`, `ja`, `ja-hrkt`, `zh-hans`, `es-419`, and so on.
|
|
3823
|
+
*
|
|
3824
|
+
* ```ts
|
|
3825
|
+
* const species = await api.pokemon.getPokemonSpeciesByName('eevee');
|
|
3826
|
+
*
|
|
3827
|
+
* localize(species.names)?.name; // 'Eevee'
|
|
3828
|
+
* localize(species.names, 'ja')?.name; // 'イーブイ'
|
|
3829
|
+
* localize(species.names, { language: 'gd', fallback: 'en' })?.name; // 'Eevee'
|
|
3830
|
+
* ```
|
|
3831
|
+
*
|
|
3832
|
+
* Matched without regard to case: the PokéAPI writes these tags in lower case,
|
|
3833
|
+
* while BCP 47 capitalizes the script subtag — `ja-Hrkt` is the form anyone used
|
|
3834
|
+
* to language tags will reach for, and it should not silently match nothing.
|
|
3835
|
+
*
|
|
3836
|
+
* A section may list several entries for one language — flavor text, one per
|
|
3837
|
+
* version — and the first is the one returned. {@link localizeAll} is the way to
|
|
3838
|
+
* see the rest and pick by version.
|
|
3839
|
+
*
|
|
3840
|
+
* @returns The entry, the one in `fallback` when that language is absent, or
|
|
3841
|
+
* `undefined` when neither is there.
|
|
3842
|
+
*/
|
|
3843
|
+
const localize = (entries, language) => localizeAll(entries, language)[0];
|
|
3844
|
+
/**
|
|
3845
|
+
* Every entry written in `language`, in the order the API lists them.
|
|
3846
|
+
*
|
|
3847
|
+
* ```ts
|
|
3848
|
+
* const species = await api.pokemon.getPokemonSpeciesByName('eevee');
|
|
3849
|
+
*
|
|
3850
|
+
* const entries = localizeAll(species.flavor_text_entries, 'en');
|
|
3851
|
+
* entries.find((entry) => entry.version.name === 'sword')?.flavor_text;
|
|
3852
|
+
* ```
|
|
3853
|
+
*
|
|
3854
|
+
* Which is what a section publishing one entry per version needs: `localize`
|
|
3855
|
+
* answers with the first, and the first is an arbitrary game's Pokédex entry
|
|
3856
|
+
* rather than the one asked for. The version is on the entry — `version` on
|
|
3857
|
+
* flavor text, `version_group` on the sections that change per group — so the
|
|
3858
|
+
* filter belongs to the caller, who knows which of the two is there.
|
|
3859
|
+
*
|
|
3860
|
+
* @returns The entries, those in `fallback` when the language is absent, or `[]`
|
|
3861
|
+
* when neither is there.
|
|
3862
|
+
*/
|
|
3863
|
+
const localizeAll = (entries, language) => {
|
|
3864
|
+
const options = optionsOf(language);
|
|
3865
|
+
const matched = inLanguage(entries, options.language);
|
|
3866
|
+
if (matched.length > 0 || options.fallback === void 0) return matched;
|
|
3867
|
+
return inLanguage(entries, options.fallback);
|
|
3868
|
+
};
|
|
3869
|
+
|
|
3870
|
+
//#endregion
|
|
3871
|
+
//#region src/utils/resource-id.ts
|
|
3872
|
+
/**
|
|
3873
|
+
* The trailing id of a PokéAPI resource URL, with or without the final slash.
|
|
3874
|
+
*
|
|
3875
|
+
* Signed: `move-ailment/-1` is the "unknown" ailment, and it is a resource the
|
|
3876
|
+
* API lists and serves like any other.
|
|
3877
|
+
*/
|
|
3878
|
+
const TRAILING_ID = /\/(-?\d+)\/?$/;
|
|
3879
|
+
/**
|
|
3880
|
+
* The id inside a resource URL, without a request.
|
|
3881
|
+
*
|
|
3882
|
+
* ```ts
|
|
3883
|
+
* const page = await api.pokemon.listPokemons(0, 20);
|
|
3884
|
+
*
|
|
3885
|
+
* page.results.map((link) => getPokemonSpriteUrl(resourceId(link)));
|
|
3886
|
+
* ```
|
|
3887
|
+
*
|
|
3888
|
+
* A list page gives names and URLs and no ids, while the sprite repository is
|
|
3889
|
+
* keyed by id alone — this is what joins the two, and it is what lets a grid of
|
|
3890
|
+
* every Pokémon render off one list request instead of one request per card.
|
|
3891
|
+
*
|
|
3892
|
+
* The id is read off the URL rather than fetched, so it is only as good as the
|
|
3893
|
+
* link: a URL the API did not write is not promised to end in one.
|
|
3894
|
+
*
|
|
3895
|
+
* @param resource The link, as a URL or as the resource object carrying one.
|
|
3896
|
+
* @returns The id.
|
|
3897
|
+
* @throws {TypeError} If the URL does not end in an id.
|
|
3898
|
+
*/
|
|
3899
|
+
const resourceId = (resource) => {
|
|
3900
|
+
const url = typeof resource === "string" ? resource : resource.url;
|
|
3901
|
+
const match = TRAILING_ID.exec(url);
|
|
3902
|
+
if (match === null) throw new TypeError(`No resource id in URL: ${url}`);
|
|
3903
|
+
return Number(match[1]);
|
|
3904
|
+
};
|
|
3905
|
+
|
|
3906
|
+
//#endregion
|
|
3907
|
+
//#region src/utils/sprites.ts
|
|
3908
|
+
const VARIANTS = {
|
|
3909
|
+
default: {
|
|
3910
|
+
directory: "",
|
|
3911
|
+
extension: "png"
|
|
3912
|
+
},
|
|
3913
|
+
"official-artwork": {
|
|
3914
|
+
directory: "other/official-artwork",
|
|
3915
|
+
extension: "png"
|
|
3916
|
+
},
|
|
3917
|
+
home: {
|
|
3918
|
+
directory: "other/home",
|
|
3919
|
+
extension: "png"
|
|
3920
|
+
},
|
|
3921
|
+
"dream-world": {
|
|
3922
|
+
directory: "other/dream-world",
|
|
3923
|
+
extension: "svg"
|
|
3924
|
+
},
|
|
3925
|
+
showdown: {
|
|
3926
|
+
directory: "other/showdown",
|
|
3927
|
+
extension: "gif"
|
|
3928
|
+
}
|
|
3929
|
+
};
|
|
3930
|
+
/**
|
|
3931
|
+
* Builds the URL of a Pokémon sprite, without a request.
|
|
3932
|
+
*
|
|
3933
|
+
* ```ts
|
|
3934
|
+
* getPokemonSpriteUrl(25); // front, default set
|
|
3935
|
+
* getPokemonSpriteUrl(25, { variant: "official-artwork" });
|
|
3936
|
+
* getPokemonSpriteUrl(25, { variant: "showdown", back: true, shiny: true });
|
|
3937
|
+
* ```
|
|
3938
|
+
*
|
|
3939
|
+
* The sprite repository does not hold every combination for every Pokémon — a
|
|
3940
|
+
* back-facing sprite of a recent generation, or a gendered form of a species with
|
|
3941
|
+
* one appearance, simply does not exist. This builds a well-formed URL; it does
|
|
3942
|
+
* not promise the file is there.
|
|
3943
|
+
*
|
|
3944
|
+
* @param id The Pokémon ID. Names are not addressable — the sprites are keyed by ID.
|
|
3945
|
+
* @param options Which sprite set and which facing to build for.
|
|
3946
|
+
* @returns The URL of the sprite.
|
|
3947
|
+
*/
|
|
3948
|
+
const getPokemonSpriteUrl = (id, options = {}) => {
|
|
3949
|
+
const { variant = "default", shiny = false, back = false, female = false } = options;
|
|
3950
|
+
const { directory, extension } = VARIANTS[variant];
|
|
3951
|
+
const segments = [
|
|
3952
|
+
directory,
|
|
3953
|
+
back && "back",
|
|
3954
|
+
shiny && "shiny",
|
|
3955
|
+
female && "female"
|
|
3956
|
+
];
|
|
3957
|
+
return [
|
|
3958
|
+
BASE_URL.SPRITES,
|
|
3959
|
+
"pokemon",
|
|
3960
|
+
...segments.filter(Boolean),
|
|
3961
|
+
`${id}.${extension}`
|
|
3962
|
+
].join("/");
|
|
3963
|
+
};
|
|
3964
|
+
|
|
3965
|
+
//#endregion
|
|
3966
|
+
//#region src/utils/type-chart.ts
|
|
3967
|
+
/**
|
|
3968
|
+
* The names {@link TypeName} declares, at runtime. Read off {@link TYPES} by id
|
|
3969
|
+
* rather than written out a second time: `unknown` and `shadow` are the ids above
|
|
3970
|
+
* 10000, the way every other section marks what is not part of the main games.
|
|
3971
|
+
*
|
|
3972
|
+
* `constants.live.spec.ts` is what holds the two to the same set — the ids are
|
|
3973
|
+
* upstream's, and a type arriving above 10000 that does belong in a matchup would
|
|
3974
|
+
* pass here unnoticed.
|
|
3975
|
+
*/
|
|
3976
|
+
const TYPE_NAMES = new Set(Object.entries(TYPES).filter(([, id]) => id < 1e4).map(([key]) => key.toLowerCase()));
|
|
3977
|
+
const isTypeName = (name) => TYPE_NAMES.has(name);
|
|
3978
|
+
/** A generation {@link GENERATIONS} does not know, which is one this build predates. */
|
|
3979
|
+
const UNKNOWN = -1;
|
|
3980
|
+
/**
|
|
3981
|
+
* The id {@link GENERATIONS} gives a generation, or {@link UNKNOWN} for a name
|
|
3982
|
+
* that is not one. Generations are compared by this rather than by name, which
|
|
3983
|
+
* does not sort.
|
|
3984
|
+
*/
|
|
3985
|
+
const rank = (name) => {
|
|
3986
|
+
const key = name.toUpperCase().replaceAll("-", "_");
|
|
3987
|
+
return GENERATIONS[key] ?? UNKNOWN;
|
|
3988
|
+
};
|
|
3989
|
+
/** The offensive arrays of a {@link TypeRelations}, and what each one means. */
|
|
3990
|
+
const MULTIPLIERS = [
|
|
3991
|
+
["no_damage_to", 0],
|
|
3992
|
+
["half_damage_to", .5],
|
|
3993
|
+
["double_damage_to", 2]
|
|
3994
|
+
];
|
|
3995
|
+
/** The defensive arrays, which say the same thing from the other side. */
|
|
3996
|
+
const INCOMING = [
|
|
3997
|
+
["no_damage_from", 0],
|
|
3998
|
+
["half_damage_from", .5],
|
|
3999
|
+
["double_damage_from", 2]
|
|
4000
|
+
];
|
|
4001
|
+
/** Looks one type up in a set of arrays. Unlisted is neutral. */
|
|
4002
|
+
const lookup = (relations, arrays, name) => {
|
|
4003
|
+
for (const [key, multiplier] of arrays) if (relations[key].some((type) => type.name === name)) return multiplier;
|
|
4004
|
+
return 1;
|
|
4005
|
+
};
|
|
4006
|
+
/** What one attacking type does to one defending type. */
|
|
4007
|
+
const against = (relations, defending) => lookup(relations, MULTIPLIERS, defending);
|
|
4008
|
+
/** The multiplier a set of relations produces against every defending type. */
|
|
4009
|
+
const multiply = (relations, defending) => defending.reduce((total, type) => total * against(relations, type.name), 1);
|
|
4010
|
+
/**
|
|
4011
|
+
* The damage relations `type` had in `generation`, or the current ones when no
|
|
4012
|
+
* generation is named.
|
|
4013
|
+
*
|
|
4014
|
+
* ```ts
|
|
4015
|
+
* const ghost = await api.pokemon.getTypeByName('ghost');
|
|
4016
|
+
*
|
|
4017
|
+
* relationsFor(ghost).half_damage_to; // [dark]
|
|
4018
|
+
* relationsFor(ghost, 'generation-iii')?.half_damage_to; // [dark, steel]
|
|
4019
|
+
* ```
|
|
4020
|
+
*
|
|
4021
|
+
* Each entry in `past_damage_relations` records the *last* generation it applied
|
|
4022
|
+
* to, so the chart in force is the first entry still at or after the generation
|
|
4023
|
+
* asked for — Ghost's `generation-v` entry is what Ghost looked like from II
|
|
4024
|
+
* through V, and the current relations take over at VI.
|
|
4025
|
+
*
|
|
4026
|
+
* @returns The relations, or `undefined` when `type` did not exist yet in
|
|
4027
|
+
* `generation`. Nothing is guessed: Steel in generation I has no chart, and a
|
|
4028
|
+
* neutral one would be a confidently wrong answer rather than a missing one.
|
|
4029
|
+
*/
|
|
4030
|
+
const relationsFor = (type, generation) => {
|
|
4031
|
+
if (generation === void 0) return type.damage_relations;
|
|
4032
|
+
const wanted = rank(generation);
|
|
4033
|
+
if (wanted === UNKNOWN) return type.damage_relations;
|
|
4034
|
+
if (wanted < rank(type.generation.name)) return;
|
|
4035
|
+
return [...type.past_damage_relations].sort((left, right) => rank(left.generation.name) - rank(right.generation.name)).find((entry) => rank(entry.generation.name) >= wanted)?.damage_relations ?? type.damage_relations;
|
|
4036
|
+
};
|
|
4037
|
+
function effectiveness(attacking, defending, options) {
|
|
4038
|
+
const relations = relationsFor(attacking, options?.generation);
|
|
4039
|
+
return relations === void 0 ? void 0 : multiply(relations, defending);
|
|
4040
|
+
}
|
|
4041
|
+
/**
|
|
4042
|
+
* What every one of `types` does to a defender that has `defending` types, keyed
|
|
4043
|
+
* by attacking type name — the "what is this Pokémon weak to" table.
|
|
4044
|
+
*
|
|
4045
|
+
* ```ts
|
|
4046
|
+
* const types: Type[] = [];
|
|
4047
|
+
* for await (const type of api.pokemon.paginate('listTypes', { resolve: true })) {
|
|
4048
|
+
* types.push(type);
|
|
4049
|
+
* }
|
|
4050
|
+
*
|
|
4051
|
+
* const profile = defensiveProfile(types, gengar.types.map((slot) => slot.type));
|
|
4052
|
+
* profile.psychic; // 2
|
|
4053
|
+
* profile.normal; // 0
|
|
4054
|
+
* ```
|
|
4055
|
+
*
|
|
4056
|
+
* The whole `type` section is one cached walk, and every lookup after that is
|
|
4057
|
+
* local. A type that did not exist in the generation asked for is left out of the
|
|
4058
|
+
* table rather than reported as neutral.
|
|
4059
|
+
*
|
|
4060
|
+
* `Partial` because of that, and because `types` is whatever the caller resolved:
|
|
4061
|
+
* an entry is there when the attacking type is, so every lookup is `number |
|
|
4062
|
+
* undefined`. `unknown` and `shadow` are not {@link TypeName}s and are skipped —
|
|
4063
|
+
* they hold no damage relations, so they have no place in a matchup table.
|
|
4064
|
+
*
|
|
4065
|
+
* Reach for {@link defensiveProfileFrom} unless you are asking about a past
|
|
4066
|
+
* generation: it answers the same question from the defender's own types, which
|
|
4067
|
+
* is one or two resources rather than the whole section. This is the form that
|
|
4068
|
+
* takes a `generation`, because only the attacking type carries the history.
|
|
4069
|
+
*
|
|
4070
|
+
* Keyed by the name the API gives a type, which is not the name a game displays:
|
|
4071
|
+
* `localize(type.names)` is what a table headed in French needs, and it is a
|
|
4072
|
+
* property of the resource rather than of this table.
|
|
4073
|
+
*/
|
|
4074
|
+
const defensiveProfile = (types, defending, options) => {
|
|
4075
|
+
const profile = {};
|
|
4076
|
+
for (const attacking of types) {
|
|
4077
|
+
if (!isTypeName(attacking.name)) continue;
|
|
4078
|
+
const relations = relationsFor(attacking, options?.generation);
|
|
4079
|
+
if (relations !== void 0) profile[attacking.name] = multiply(relations, defending);
|
|
4080
|
+
}
|
|
4081
|
+
return profile;
|
|
4082
|
+
};
|
|
4083
|
+
/**
|
|
4084
|
+
* The same table, read off the defending types themselves — what every type does
|
|
4085
|
+
* to a Pokémon that has `defending` types.
|
|
4086
|
+
*
|
|
4087
|
+
* ```ts
|
|
4088
|
+
* const gengar = await api.pokemon.getPokemonByName('gengar');
|
|
4089
|
+
* const types = await api.resolveAll(gengar.types.map((slot) => slot.type));
|
|
4090
|
+
*
|
|
4091
|
+
* const profile = defensiveProfileFrom(types);
|
|
4092
|
+
* profile.psychic; // 2
|
|
4093
|
+
* profile.normal; // 0
|
|
4094
|
+
* ```
|
|
5
4095
|
*
|
|
6
|
-
*
|
|
4096
|
+
* Two requests for a dual-typed Pokémon, against the whole `type` section that
|
|
4097
|
+
* {@link defensiveProfile} needs — the answer is the same because the chart is
|
|
4098
|
+
* symmetric, which `tests/live/relations.live.spec.ts` is what keeps honest.
|
|
7
4099
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
4100
|
+
* Every {@link TypeName} is present: the defending types name every attacker
|
|
4101
|
+
* they interact with, and the rest are neutral rather than unknown. There is no
|
|
4102
|
+
* `generation` option for exactly the reason the entries are total — a defending
|
|
4103
|
+
* type's arrays are the current chart, and they have no way to say that an
|
|
4104
|
+
* attacking type did not exist yet. That question needs {@link defensiveProfile}.
|
|
12
4105
|
*
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
4106
|
+
* Keyed by the API's name for a type, as {@link defensiveProfile} is;
|
|
4107
|
+
* `localize(type.names)` is the displayed one.
|
|
15
4108
|
*/
|
|
16
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};const n={CHERI:1,CHESTO:2,PECHA:3,RAWST:4,ASPEAR:5,LEPPA:6,ORAN:7,PERSIM:8,LUM:9,SITRUS:10,FIGY:11,WIKI:12,MAGO:13,AGUAV:14,IAPAPA:15,RAZZ:16,BLUK:17,NANAB:18,WEPEAR:19,PINAP:20,POMEG:21,KELPSY:22,QUALOT:23,HONDEW:24,GREPA:25,TAMATO:26,CORNN:27,MAGOST:28,RABUTA:29,NOMEL:30,SPELON:31,PAMTRE:32,WATMEL:33,DURIN:34,BELUE:35,OCCA:36,PASSHO:37,WACAN:38,RINDO:39,YACHE:40,CHOPLE:41,KEBIA:42,SHUCA:43,COBA:44,PAYAPA:45,TANGA:46,CHARTI:47,KASIB:48,HABAN:49,COLBUR:50,BABIRI:51,CHILAN:52,LIECHI:53,GANLON:54,SALAC:55,PETAYA:56,APICOT:57,LANSAT:58,STARF:59,ENIGMA:60,MICLE:61,CUSTAP:62,JABOCA:63,ROWAP:64,KEE:65,MARANGA:66,HOPO:67,ROSELI:68},r={VERY_SOFT:1,SOFT:2,HARD:3,VERY_HARD:4,SUPER_HARD:5},i={SPICY:1,DRY:2,SWEET:3,BITTER:4,SOUR:5},a={COOL:1,BEAUTY:2,CUTE:3,SMART:4,TOUGH:5},o={POKE_DOLLAR:1,COIN:2,VOLCANIC_ASH:3,POKE_COUPON:4,BERRY_POWDER:5,BATTLE_POINT:6,SPHERE:7,CASTLE_POINT:8,WATT:9,ATHLETE_POINT:10,DREAM_POINT:11,DREAM_WORLD_BERRY:12,POKE_MILE:13,FESTIVAL_COIN:14,POKE_BEAN:15,HOME_POINT:16,MERIT_POINT:17,LEAGUE_POINT:18,BLUEBERRY_POINT:19},s={WALK:1,OLD_ROD:2,GOOD_ROD:3,SUPER_ROD:4,SURF:5,ROCK_SMASH:6,HEADBUTT:7,DARK_GRASS:8,GRASS_SPOTS:9,CAVE_SPOTS:10,BRIDGE_SPOTS:11,SUPER_ROD_SPOTS:12,SURF_SPOTS:13,YELLOW_FLOWERS:14,PURPLE_FLOWERS:15,RED_FLOWERS:16,ROUGH_TERRAIN:17,GIFT:18,GIFT_EGG:19,STATIC:20,POKEFLUTE:21,HEADBUTT_LOW:22,HEADBUTT_NORMAL:23,HEADBUTT_HIGH:24,SQUIRT_BOTTLE:25,WAILMER_PAIL:26,SEAWEED:27,ROAMING_GRASS:28,ROAMING_WATER:29,DEVON_SCOPE:30,FEEBAS_TILE_FISHING:31,ISLAND_SCAN:32,SOS:33,BUBBLING_SPOTS:34,BERRY_TREES:35,NPC_TRADE:36,SOS_FROM_BUBBLING_SPOT:37,OVERWORLD:38,OVERWORLD_WATER:39,OVERWORLD_FLYING:40,OVERWORLD_SPECIAL:41,OVERWORLD_FLYING_SPECIAL:42,OVERWORLD_WATER_SPECIAL:43,HORDE:44,COLOSSEUM_BONUS_DISC_US:45,COLOSSEUM_BONUS_DISC_JPN:46,POKEMON_CHANNEL_PAL:47,POKEMON_RANGER:48,POKEMON_BATTLE_REVOLUTION:49,NEW_YORK_POKECENTER_WISH_EGGS:50,SNAG:51,SNAG_REMATCH:52,POKESPOT:53,HIDDEN_GROTTO:54,HONEY_TREE:55,OVERWORLD_DIRT:56,WANDERER:57,WANDERER_WATER:58,CHASE_WATER:59,DYNAMAX_ADVENTURE:60,MAX_RAID:61,TRASH_CAN_AMBUSH:62,RUSTLING_BUSH_AMBUSH:63,CEILING_AMBUSH:64,GROUND_AMBUSH:65,SKY_AMBUSH:66,HEADBUT_HIGH:24,ONLY_ONE:20},c={SWARM:1,TIME:2,RADAR:3,SLOT2:4,RADIO:5,SEASON:6,STARTER:7,TV_OPTION:8,STORY_PROGRESS:9,OTHER:10,ITEM:11,WEEKDAY:12,FIRST_PARTY_POKEMON:13,SPECIAL_ENCOUNTER:14,TRADE:15,COINS:16,FRIEND_SAFARI_SLOT:17,GREAT_MARSH_DAILY_SLOT:18,HONEY_TREE_GROUP:19,HEADBUTT_TREE:20,BACKLOT:21,BUG_CATCHING_CONTEST:22,SAVE_DATA:23,ALOLAN_DIGLETT_FOUND:24,WEATHER:25,JOHTO_SAFARI_BLOCKS:26,MAX_DEN_RARITY:27,MAX_DEN_RATING:28,BERRY_TREE_TYPE:29,TRASH_CAN_TYPE:30},l={SWARM_YES:1,SWARM_NO:2,TIME_MORNING:3,TIME_DAY:4,TIME_NIGHT:5,RADAR_ON:6,RADAR_OFF:7,SLOT2_NONE:8,SLOT2_RUBY:9,SLOT2_SAPPHIRE:10,SLOT2_EMERALD:11,SLOT2_FIRERED:12,SLOT2_LEAFGREEN:13,RADIO_OFF:14,RADIO_HOENN:15,RADIO_SINNOH:16,SEASON_SPRING:17,SEASON_SUMMER:18,SEASON_AUTUMN:19,SEASON_WINTER:20,STARTER_BULBASAUR:21,STARTER_SQUIRTLE:22,STARTER_CHARMANDER:23,STARTER_CHESPIN:24,STARTER_FENNEKIN:25,STARTER_FROAKIE:26,TV_OPTION_BLUE:27,TV_OPTION_RED:28,STORY_PROGRESS_AWAKENED_BEASTS:29,STORY_PROGRESS_BEAT_GALACTIC_CORONET:30,STORY_PROGRESS_OAK_ETERNA_CITY:31,STORY_PROGRESS_VERMILION_COPYCAT:32,STORY_PROGRESS_MET_TORNADUS_THUNDURUS:33,STORY_PROGRESS_BEAT_ELITE_FOUR_ROUND_TWO:34,STORY_PROGRESS_HALL_OF_FAME:35,STORY_PROGRESS_NONE:36,STORY_PROGRESS_NATIONAL_DEX:37,OTHER_NONE:38,OTHER_SNORLAX_11_BEAT_LEAGUE:39,OTHER_VIRTUAL_CONSOLE:40,STORY_PROGRESS_CURE_ELDRITCH_NIGHTMARES:41,OTHER_TALK_TO_CYNTHIAS_GRANDMOTHER:42,ITEM_NONE:43,ITEM_ADAMANT_ORB:44,ITEM_LUSTROUS_ORB:45,ITEM_HELIX_FOSSIL:46,ITEM_DOME_FOSSIL:47,ITEM_OLD_AMBER:48,ITEM_ROOT_FOSSIL:49,ITEM_CLAW_FOSSIL:50,STORY_PROGRESS_DEFEAT_JUPITER:51,STORY_PROGRESS_BEAT_TEAM_GALACTIC_IRON_ISLAND:52,OTHER_CORRECT_PASSWORD:53,STORY_PROGRESS_ZEPHYR_BADGE:54,STORY_PROGRESS_BEAT_RED:55,OTHER_RECEIVED_KANTO_STARTER:56,STORY_PROGRESS_RECEIVE_TM_FROM_CLAIRE:57,OTHER_REGIROCK_REGICE_REGISTEEL_IN_PARTY:58,WEEKDAY_SUNDAY:59,WEEKDAY_MONDAY:60,WEEKDAY_TUESDAY:61,WEEKDAY_WEDNESDAY:62,WEEKDAY_THURSDAY:63,WEEKDAY_FRIDAY:64,WEEKDAY_SATURDAY:65,FIRST_PARTY_POKEMON_HIGH_FRIENDSHIP:66,STORY_PROGRESS_DEFEAT_MARS:67,ITEM_ODD_KEYSTONE:68,OTHER_TALKED_TO_32_PEOPLE_UNDERGROUND:69,STORY_PROGRESS_RETURNED_MACHINE_PART:70,OTHER_EVENT_ARCEUS_IN_PARTY:71,SPECIAL_ENCOUNTER_COULDNT_CAPTURE_BEFORE:72,ITEM_ICE_KEY:73,ITEM_IRON_KEY:74,STORY_PROGRESS_JUNIPER_CAVE_OF_BEING:75,ITEM_LUNAR_WING:76,STORY_PROGRESS_QUAKE_BADGE:77,ITEM_LIGHT_STONE:78,ITEM_DARK_STONE:79,OTHER_CAPTURED_RESHIRAM_OR_ZEKROM:80,DEFEATED_GHETSIS:81,OTHER_FOUND_11_TIMES_ROAMING:82,TIME_MINUTE_00_TO_19:83,TIME_MINUTE_20_TO_39:84,TIME_MINUTE_40_TO_59:85,TIME_04_00_TO_19_59:86,TIME_20_00_TO_21_59:87,TIME_21_00_TO_03_59:88,ITEM_TIDAL_BELL:89,ITEM_CLEAR_BELL:90,STORY_PROGRESS_DEFEATED_GROUDON_OR_KYOGRE:91,OTHER_UXIE_MESPRIT_AZELF_IN_PARTY:92,OTHER_NICKNAMED_COLD_ITEM_REGICE_REGIROCK_REGISTEEL3:93,OTHER_DIALGA_OR_PALKIA_IN_PARTY:94,OTHER_CASTFORM_IN_PARTY:95,OTHER_LEVEL_100_POKEMON_IN_PARTY:96,OTHER_TORNADUS_THUNDURUS_IN_PARTY:97,OTHER_RESHIRAM_ZEKROM_IN_PARTY:98,OTHER_CAPTURED_ALL_ULTRA_BEASTS:99,STORY_PROGRESS_FINISHED_LOOKER_SIDEQUEST:100,STORY_PROGRESS_BEAT_OLIVIAS_TRIAL:101,OTHER_RAIKOU_ENTEI_IN_PARTY:102,OTHER_GROUDON_KYOGRE_IN_PARTY:103,OTHER_DIALGA_PALKIA_IN_PARTY:104,OTHER_SCAN_QR_CODE:105,OTHER_CAUGHT_ARTICUNO:106,OTHER_CAUGHT_ZAPDOS:107,OTHER_CAUGHT_MOLTRES:108,TRADE_TOGEPI_OR_TOGETIC:109,TRADE_TRAPINCH:110,TRADE_SURSKIT:111,TRADE_WOOPER:112,STORY_PROGRESS_CATCH_ALL_SHADOW_POKEMON:113,OTHER_COMPLETE_MT_BATTLE:114,COINS_180:115,COINS_500:116,COINS_1200:117,COINS_2800:118,COINS_5500:119,COINS_9999:120,COINS_120:121,COINS_750:122,COINS_2500:123,COINS_4600:124,COINS_6500:125,COINS_230:126,COINS_1000:127,COINS_2680:128,COINS_3333:129,COINS_6666:130,COINS_200:131,COINS_700:132,COINS_2100:133,COINS_100:134,COINS_800:135,COINS_1500:136,COINS_2222:137,COINS_5555:138,COINS_8888:139,COINS_150:140,COINS_620:141,COINS_2880:142,COINS_5400:143,COINS_8300:144,TRADE_ABRA:145,TRADE_NIDORAN_M:146,TRADE_NIDORINO:147,TRADE_SLOWBRO:148,TRADE_POLIWHIRL:149,TRADE_SPEAROW:150,TRADE_RAICHU:151,TRADE_VENONAT:152,TRADE_PONYTA:153,TRADE_CLEFAIRY:154,TRADE_CUBONE:155,TRADE_LICKITUNG:156,TRADE_TANGELA:157,TRADE_GOLDUCK:158,TRADE_GROWLITHE:159,TRADE_KANGASKHAN:160,TRADE_BELLSPROUT:161,TRADE_DROWZEE:162,TRADE_KRABBY:163,TRADE_DRAGONAIR:164,TRADE_CHANSEY:165,TRADE_GLOOM:166,TRADE_HAUNTER:167,TRADE_DUGTRIO:168,TRADE_SLAKOTH:169,TRADE_PIKACHU:170,TRADE_BELLOSSOM:171,TRADE_RALTS:172,TRADE_VOLBEAT:173,TRADE_BAGON:174,TRADE_SKITTY:175,FRIEND_SAFARI_SLOT_1:176,FRIEND_SAFARI_SLOT_2:177,FRIEND_SAFARI_SLOT_3:178,ITEM_SKULL_FOSSIL:179,ITEM_ARMOR_FOSSIL:180,GREAT_MARSH_DAILY_SLOT_NONE:181,GREAT_MARSH_DAILY_SLOT_1_OF_32:182,GREAT_MARSH_DAILY_SLOT_2_OF_32:183,GREAT_MARSH_DAILY_SLOT_3_OF_32:184,GREAT_MARSH_DAILY_SLOT_5_OF_32:185,STORY_PROGRESS_BEFORE_NATIONAL_DEX:186,GREAT_MARSH_DAILY_SLOT_4_OF_32:187,GREAT_MARSH_DAILY_SLOT_15_OF_32:188,HONEY_TREE_GROUP_A:189,HONEY_TREE_GROUP_B:190,HONEY_TREE_GROUP_C:191,HEADBUTT_TREE_COMMON:192,HEADBUTT_TREE_RARE:193,HEADBUTT_TREE_SECRET:194,TRADE_COTTONEE:195,TRADE_PETILIL:196,TRADE_EMOLGA:197,TRADE_MANTINE:198,TRADE_DITTO:199,TRADE_EXCADRILL:200,TRADE_HIPPOWDON:201,BACKLOT_NOT_MENTIONED:202,BACKLOT_MENTIONED:203,BUG_CATCHING_CONTEST_NO:204,BUG_CATCHING_CONTEST_YES:205,SAVE_DATA_FROM_LETS_GO_PIKACHU:206,SAVE_DATA_FROM_LETS_GO_EEVEE:207,ITEM_FOSSILIZED_BIRD:208,ITEM_FOSSILIZED_DRAKE:209,ITEM_FOSSILIZED_DINO:210,ITEM_FOSSILIZED_FISH:211,STORY_PROGRESS_MASTER_DOJO_COMPLETE_FIRST_TRIAL:212,STORY_PROGRESS_MASTER_DOJO_COMPLETE_THIRD_TRIAL:213,ALOLAN_DIGLETT_FOUND_5:214,ALOLAN_DIGLETT_FOUND_10:215,ALOLAN_DIGLETT_FOUND_20:216,ALOLAN_DIGLETT_FOUND_30:217,ALOLAN_DIGLETT_FOUND_40:218,ALOLAN_DIGLETT_FOUND_50:219,ALOLAN_DIGLETT_FOUND_75:220,ALOLAN_DIGLETT_FOUND_100:221,ALOLAN_DIGLETT_FOUND_150:222,STARTER_GROOKEY:223,STARTER_SCORBUNNY:224,STARTER_SOBBLE:225,STORY_PROGRESS_SAVE_VILLAGE_FROM_GLASTRIER_SPECTRIER:226,STORY_PROGRESS_CATCH_FIVE_ULTRA_BEASTS:227,TRADE_BUNNELBY:228,TRADE_MEOWTH_GALAR:229,TRADE_MINCCINO:230,TRADE_TOXEL:231,TRADE_MARACTUS:232,TRADE_YAMASK_GALAR:233,TRADE_VANILLISH:234,TRADE_OBSTAGOON:235,TRADE_FROSMOTH:236,TRADE_FARFETCHD_GALAR:237,TRADE_CORSOLA_GALAR:238,TRADE_PONYTA_GALAR:239,TRADE_MR_MIME_GALAR:240,TRADE_DARUMAKA_GALAR:241,TRADE_ZIGZAGOON_GALAR:242,TRADE_STUNFISK_GALAR:243,TRADE_WEEZING_GALAR:244,TRADE_EXEGGUTOR:245,TRADE_MAROWAK:246,WEATHER_NORMAL:247,WEATHER_OVERCAST:248,WEATHER_RAINING:249,WEATHER_THUNDERSTORM:250,WEATHER_SNOWING:251,WEATHER_SNOWSTORM:252,WEATHER_SANDSTORM:253,WEATHER_INTENSE_SUN:254,WEATHER_FOG:255,STORY_PROGRESS_BEFORE_HALL_OF_FAME:256,JOHTO_SAFARI_BLOCKS_INACTIVE:257,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_2:258,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_3:259,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_4:260,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_5:261,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_6:262,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_10:263,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_12:264,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_14:265,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_15:266,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_24:267,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_28:268,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_35:269,JOHTO_SAFARI_BLOCKS_PLAINS_MIN_49:270,JOHTO_SAFARI_BLOCKS_FOREST_MIN_3:271,JOHTO_SAFARI_BLOCKS_FOREST_MIN_4:272,JOHTO_SAFARI_BLOCKS_FOREST_MIN_5:273,JOHTO_SAFARI_BLOCKS_FOREST_MIN_8:274,JOHTO_SAFARI_BLOCKS_FOREST_MIN_10:275,JOHTO_SAFARI_BLOCKS_FOREST_MIN_14:276,JOHTO_SAFARI_BLOCKS_FOREST_MIN_15:277,JOHTO_SAFARI_BLOCKS_FOREST_MIN_18:278,JOHTO_SAFARI_BLOCKS_FOREST_MIN_20:279,JOHTO_SAFARI_BLOCKS_FOREST_MIN_28:280,JOHTO_SAFARI_BLOCKS_FOREST_MIN_35:281,JOHTO_SAFARI_BLOCKS_FOREST_MIN_42:282,JOHTO_SAFARI_BLOCKS_FOREST_MIN_49:283,JOHTO_SAFARI_BLOCKS_FOREST_MIN_56:284,JOHTO_SAFARI_BLOCKS_PEAK_MIN_3:285,JOHTO_SAFARI_BLOCKS_PEAK_MIN_4:286,JOHTO_SAFARI_BLOCKS_PEAK_MIN_5:287,JOHTO_SAFARI_BLOCKS_PEAK_MIN_6:288,JOHTO_SAFARI_BLOCKS_PEAK_MIN_8:289,JOHTO_SAFARI_BLOCKS_PEAK_MIN_10:290,JOHTO_SAFARI_BLOCKS_PEAK_MIN_15:291,JOHTO_SAFARI_BLOCKS_PEAK_MIN_21:292,JOHTO_SAFARI_BLOCKS_PEAK_MIN_24:293,JOHTO_SAFARI_BLOCKS_PEAK_MIN_28:294,JOHTO_SAFARI_BLOCKS_PEAK_MIN_35:295,JOHTO_SAFARI_BLOCKS_PEAK_MIN_42:296,JOHTO_SAFARI_BLOCKS_PEAK_MIN_49:297,JOHTO_SAFARI_BLOCKS_PEAK_MIN_56:298,JOHTO_SAFARI_BLOCKS_PEAK_MIN_63:299,JOHTO_SAFARI_BLOCKS_WATER_MIN_2:300,JOHTO_SAFARI_BLOCKS_WATER_MIN_3:301,JOHTO_SAFARI_BLOCKS_WATER_MIN_4:302,JOHTO_SAFARI_BLOCKS_WATER_MIN_5:303,JOHTO_SAFARI_BLOCKS_WATER_MIN_6:304,JOHTO_SAFARI_BLOCKS_WATER_MIN_7:305,JOHTO_SAFARI_BLOCKS_WATER_MIN_8:306,JOHTO_SAFARI_BLOCKS_WATER_MIN_9:307,JOHTO_SAFARI_BLOCKS_WATER_MIN_10:308,JOHTO_SAFARI_BLOCKS_WATER_MIN_12:309,JOHTO_SAFARI_BLOCKS_WATER_MIN_13:310,JOHTO_SAFARI_BLOCKS_WATER_MIN_14:311,JOHTO_SAFARI_BLOCKS_WATER_MIN_15:312,JOHTO_SAFARI_BLOCKS_WATER_MIN_16:313,JOHTO_SAFARI_BLOCKS_WATER_MIN_18:314,JOHTO_SAFARI_BLOCKS_WATER_MIN_20:315,JOHTO_SAFARI_BLOCKS_WATER_MIN_24:316,JOHTO_SAFARI_BLOCKS_WATER_MIN_28:317,JOHTO_SAFARI_BLOCKS_WATER_MIN_35:318,JOHTO_SAFARI_BLOCKS_WATER_MIN_42:319,JOHTO_SAFARI_BLOCKS_WATER_MIN_49:320,ITEM_COVER_FOSSIL:321,ITEM_PLUME_FOSSIL:322,OTHER_GIRATINA_NOT_CAUGHT_IN_DISTORTION_WORLD:323,OTHER_FIND_50_CAVERN_FOOTPRINTS:324,OTHER_FIND_50_GRASSLAND_FOOTPRINTS:325,OTHER_FIND_50_IRON_WILL_FOOTPRINTS:326,OTHER_REGIROCK_REGICE_REGISTEEL_REGIELEKI_REGIDRAGO_IN_PARTY:327,OTHER_CHOOSE_REGIELEKI_PATTERN:328,OTHER_CHOOSE_REGIDRAGO_PATTERN:329,OTHER_GROW_ICEROOT_CARROT:330,OTHER_GROW_SHADEROOT_CARROT:331,OTHER_TALKED_TO_32_PEOPLE:332,OTHER_EAT_CURRY_WITH_COBALION_TERRAKION_VIRIZION:333,ITEM_REINS_OF_UNITY:334,OTHER_WITNESS_GALARIAN_BIRD_FIGHT:335,MAX_DEN_RARITY_COMMON:336,MAX_DEN_RARITY_RARE:337,MAX_DEN_RATING_1_STAR:338,MAX_DEN_RATING_2_STAR:339,MAX_DEN_RATING_3_STAR:340,MAX_DEN_RATING_4_STAR:341,MAX_DEN_RATING_5_STAR:342,MAX_DEN_RARITY_SPECIAL:343,BERRY_TREE_TYPE_RED:344,BERRY_TREE_TYPE_BLUE:345,BERRY_TREE_TYPE_PURPLE:346,BERRY_TREE_TYPE_GREEN:347,BERRY_TREE_TYPE_YELLOW:348,BERRY_TREE_TYPE_PINK:349,TRASH_CAN_TYPE_DAILY:350,TRASH_CAN_TYPE_TUESDAY:351,TRASH_CAN_TYPE_THURSDAY:352,TRADE_NIDORAN_F:353,TRADE_NIDORINA:354,TRADE_MACHOP:355,TRADE_BUIZEL:356,TRADE_MEDICHAM:357,TRADE_FINNEON:358,TRADE_FORRETRESS:359,TRADE_BONSLY:360,TRADE_ANY_POKEMON:361,OTHER_SNORLAX_LL_BEAT_LEAGUE:39,RADIO_HOEN:15,SLOT2_SAPHIRE:10,STORY_PROGRESS_OAK_VERMILION_COPYCAT:32,SWASON_AUTUMN:19},u={BERRY:`/berry`,BERRY_FIRMNESS:`/berry-firmness`,BERRY_FLAVOR:`/berry-flavor`,CONTEST_TYPE:`/contest-type`,CONTEST_EFFECT:`/contest-effect`,SUPER_CONTEST_EFFECT:`/super-contest-effect`,CURRENCY:`/currency`,ENCOUNTER_METHOD:`/encounter-method`,ENCOUNTER_CONDITION:`/encounter-condition`,ENCOUNTER_CONDITION_VALUE:`/encounter-condition-value`,EVOLUTION_CHAIN:`/evolution-chain`,EVOLUTION_TRIGGER:`/evolution-trigger`,GENERATION:`/generation`,POKEDEX:`/pokedex`,VERSION:`/version`,VERSION_GROUP:`/version-group`,ITEM:`/item`,ITEM_ATTRIBUTE:`/item-attribute`,ITEM_CATEGORY:`/item-category`,ITEM_FLING_EFFECT:`/item-fling-effect`,ITEM_POCKET:`/item-pocket`,LOCATION:`/location`,LOCATION_AREA:`/location-area`,PALPARK_AREA:`/pal-park-area`,REGION:`/region`,MACHINE:`/machine`,MOVE:`/move`,MOVE_AILMENT:`/move-ailment`,MOVE_BATTLE_STYLE:`/move-battle-style`,MOVE_CATEGORY:`/move-category`,MOVE_DAMAGE_CLASS:`/move-damage-class`,MOVE_LEARN_METHOD:`/move-learn-method`,MOVE_TARGET:`/move-target`,ABILITY:`/ability`,CHARACTERISTIC:`/characteristic`,EGG_GROUP:`/egg-group`,GENDER:`/gender`,GROWTH_RATE:`/growth-rate`,NATURE:`/nature`,POKEATHLON_STAT:`/pokeathlon-stat`,POKEMON:`/pokemon`,POKEMON_COLOR:`/pokemon-color`,POKEMON_FORM:`/pokemon-form`,POKEMON_HABITAT:`/pokemon-habitat`,POKEMON_SHAPE:`/pokemon-shape`,POKEMON_SPECIES:`/pokemon-species`,STAT:`/stat`,TYPE:`/type`,LANGUAGE:`/language`},d={LEVEL_UP:1,TRADE:2,USE_ITEM:3,SHED:4,SPIN:5,TOWER_OF_DARKNESS:6,TOWER_OF_WATERS:7,THREE_CRITICAL_HITS:8,TAKE_DAMAGE:9,OTHER:10,AGILE_STYLE_MOVE:11,STRONG_STYLE_MOVE:12,RECOIL_DAMAGE:13,USE_MOVE:14,THREE_DEFEATED_BISHARP:15,GIMMIGHOUL_COINS:16,TOWER_OF_WATER:7},f={GENERATION_I:1,GENERATION_II:2,GENERATION_III:3,GENERATION_IV:4,GENERATION_V:5,GENERATION_VI:6,GENERATION_VII:7,GENERATION_VIII:8,GENERATION_IX:9},p={NATIONAL:1,KANTO:2,ORIGINAL_JOHTO:3,HOENN:4,ORIGINAL_SINNOH:5,EXTENDED_SINNOH:6,UPDATED_JOHTO:7,ORIGINAL_UNOVA:8,UPDATED_UNOVA:9,CONQUEST_GALLERY:11,KALOS_CENTRAL:12,KALOS_COASTAL:13,KALOS_MOUNTAIN:14,UPDATED_HOENN:15,ORIGINAL_ALOLA:16,ORIGINAL_MELEMELE:17,ORIGINAL_AKALA:18,ORIGINAL_ULAULA:19,ORIGINAL_PONI:20,UPDATED_ALOLA:21,UPDATED_MELEMELE:22,UPDATED_AKALA:23,UPDATED_ULAULA:24,UPDATED_PONI:25,LETSGO_KANTO:26,GALAR:27,ISLE_OF_ARMOR:28,CROWN_TUNDRA:29,HISUI:30,PALDEA:31,KITAKAMI:32,BLUEBERRY:33,LUMIOSE_CITY:34,HYPERSPACE:35,CHAMPIONS:36,KALOS_MONTAIN:14,UPDATED_KANTO:26},m={RED:1,BLUE:2,YELLOW:3,GOLD:4,SILVER:5,CRYSTAL:6,RUBY:7,SAPPHIRE:8,EMERALD:9,FIRERED:10,LEAFGREEN:11,DIAMOND:12,PEARL:13,PLATINUM:14,HEARTGOLD:15,SOULSILVER:16,BLACK:17,WHITE:18,COLOSSEUM:19,XD:20,BLACK_2:21,WHITE_2:22,X:23,Y:24,OMEGA_RUBY:25,ALPHA_SAPPHIRE:26,SUN:27,MOON:28,ULTRA_SUN:29,ULTRA_MOON:30,LETS_GO_PIKACHU:31,LETS_GO_EEVEE:32,SWORD:33,SHIELD:34,THE_ISLE_OF_ARMOR_SWORD:35,THE_CROWN_TUNDRA_SWORD:36,BRILLIANT_DIAMOND:37,SHINING_PEARL:38,LEGENDS_ARCEUS:39,SCARLET:40,VIOLET:41,THE_TEAL_MASK_SCARLET:42,THE_INDIGO_DISK_SCARLET:43,RED_JAPAN:44,GREEN_JAPAN:45,BLUE_JAPAN:46,LEGENDS_ZA:47,MEGA_DIMENSION:48,CHAMPIONS:49,THE_ISLE_OF_ARMOR_SHIELD:50,THE_CROWN_TUNDRA_SHIELD:51,THE_TEAL_MASK_VIOLET:52,THE_INDIGO_DISK_VIOLET:53,THE_CROWN_TUNDRA:36,THE_ISLE_OF_ARMOR:35},h={RED_BLUE:1,YELLOW:2,GOLD_SILVER:3,CRYSTAL:4,RUBY_SAPPHIRE:5,EMERALD:6,FIRERED_LEAFGREEN:7,DIAMOND_PEARL:8,PLATINUM:9,HEARTGOLD_SOULSILVER:10,BLACK_WHITE:11,COLOSSEUM:12,XD:13,BLACK_2_WHITE_2:14,X_Y:15,OMEGA_RUBY_ALPHA_SAPPHIRE:16,SUN_MOON:17,ULTRA_SUN_ULTRA_MOON:18,LETS_GO_PIKACHU_LETS_GO_EEVEE:19,SWORD_SHIELD:20,THE_ISLE_OF_ARMOR:21,THE_CROWN_TUNDRA:22,BRILLIANT_DIAMOND_SHINING_PEARL:23,LEGENDS_ARCEUS:24,SCARLET_VIOLET:25,THE_TEAL_MASK:26,THE_INDIGO_DISK:27,RED_GREEN_JAPAN:28,BLUE_JAPAN:29,LEGENDS_ZA:30,MEGA_DIMENSION:31,CHAMPIONS:32,BRILLIANT_DIAMOND_AND_SHINING_PEARL:23,LETS_GO:19},g={COUNTABLE:1,CONSUMABLE:2,USABLE_OVERWORLD:3,USABLE_IN_BATTLE:4,HOLDABLE:5,HOLDABLE_PASSIVE:6,HOLDABLE_ACTIVE:7,UNDERGROUND:8},ee={STAT_BOOSTS:1,EFFORT_DROP:2,MEDICINE:3,OTHER:4,IN_A_PINCH:5,PICKY_HEALING:6,TYPE_PROTECTION:7,BAKING_ONLY:8,COLLECTIBLES:9,EVOLUTION:10,SPELUNKING:11,HELD_ITEMS:12,CHOICE:13,EFFORT_TRAINING:14,BAD_HELD_ITEMS:15,TRAINING:16,PLATES:17,SPECIES_SPECIFIC:18,TYPE_ENHANCEMENT:19,EVENT_ITEMS:20,GAMEPLAY:21,PLOT_ADVANCEMENT:22,UNUSED:23,LOOT:24,ALL_MAIL:25,VITAMINS:26,HEALING:27,PP_RECOVERY:28,REVIVAL:29,STATUS_CURES:30,MULCH:32,SPECIAL_BALLS:33,STANDARD_BALLS:34,DEX_COMPLETION:35,SCARVES:36,ALL_MACHINES:37,FLUTES:38,APRICORN_BALLS:39,APRICORN_BOX:40,DATA_CARDS:41,JEWELS:42,MIRACLE_SHOOTER:43,MEGA_STONES:44,MEMORIES:45,Z_CRYSTALS:46,SPECIES_CANDIES:47,CATCHING_BONUS:48,DYNAMAX_CRYSTALS:49,NATURE_MINTS:50,CURRY_INGREDIENTS:51,TERA_SHARD:52,SANDWICH_INGREDIENTS:53,TM_MATERIALS:54,PICNIC:55,DYNAMAX_CRISTALS:49},_={BADLY_POISON:1,BURN:2,BERRY_EFFECT:3,HERB_EFFECT:4,PARALYZE:5,POISON:6,FLINCH:7},v={MISC:1,MEDICINE:2,POKEBALLS:3,MACHINES:4,BERRIES:5,MAIL:6,BATTLE:7,KEY:8},te={KANTO:1,JOHTO:2,HOENN:3,SINNOH:4,UNOVA:5,KALOS:6,ALOLA:7,GALAR:8,HISUI:9,PALDEA:10,ORRE:11},ne={FOREST:1,FIELD:2,MOUNTAIN:3,POND:4,SEA:5},re={UNKNOWN:-1,NONE:0,PARALYSIS:1,SLEEP:2,FREEZE:3,BURN:4,POISON:5,CONFUSION:6,INFATUATION:7,TRAP:8,NIGHTMARE:9,TORMENT:12,DISABLE:13,YAWN:14,HEAL_BLOCK:15,NO_TYPE_IMMUNITY:17,LEECH_SEED:18,EMBARGO:19,PERISH_SONG:20,INGRAIN:21,SILENCE:24,TAR_SHOT:42},ie={ATTACK:1,DEFENSE:2,SUPPORT:3},ae={DAMAGE:0,AILMENT:1,NET_GOOD_STATS:2,HEAL:3,DAMAGE_AILMENT:4,SWAGGER:5,DAMAGE_LOWER:6,DAMAGE_RAISE:7,DAMAGE_HEAL:8,OHKO:9,WHOLE_FIELD_EFFECT:10,FIELD_EFFECT:11,FORCE_SWITCH:12,UNIQUE:13},oe={STATUS:1,PHYSICAL:2,SPECIAL:3},y={LEVEL_UP:1,EGG:2,TUTOR:3,MACHINE:4,STADIUM_SURFING_PIKACHU:5,LIGHT_BALL_EGG:6,COLOSSEUM_PURIFICATION:7,XD_SHADOW:8,XD_PURIFICATION:9,FORM_CHANGE:10,ZYGARDE_CUBE:11,TRAIN:12},b={SPECIFIC_MOVE:1,SELECTED_POKEMON_ME_FIRST:2,ALLY:3,USERS_FIELD:4,USER_OR_ALLY:5,OPPONENTS_FIELD:6,USER:7,RANDOM_OPPONENT:8,ALL_OTHER_POKEMON:9,SELECTED_POKEMON:10,ALL_OPPONENTS:11,ENTIRE_FIELD:12,USER_AND_ALLIES:13,ALL_POKEMON:14,ALL_ALLIES:15,FAINTING_POKEMON:16,USER_AND_ALIES:13},x={MONSTER:1,WATER1:2,BUG:3,FLYING:4,GROUND:5,FAIRY:6,PLANT:7,HUMANSHAPE:8,WATER3:9,MINERAL:10,INDETERMINATE:11,WATER2:12,DITTO:13,DRAGON:14,NO_EGGS:15},S={FEMALE:1,MALE:2,GENDERLESS:3},C={SLOW:1,MEDIUM:2,FAST:3,MEDIUM_SLOW:4,SLOW_THEN_VERY_FAST:5,FAST_THEN_VERY_SLOW:6},w={HARDY:1,BOLD:2,MODEST:3,CALM:4,TIMID:5,LONELY:6,DOCILE:7,MILD:8,GENTLE:9,HASTY:10,ADAMANT:11,IMPISH:12,BASHFUL:13,CAREFUL:14,RASH:15,JOLLY:16,NAUGHTY:17,LAX:18,QUIRKY:19,NAIVE:20,BRAVE:21,RELAXED:22,QUIET:23,SASSY:24,SERIOUS:25},T={SPEED:1,POWER:2,SKILL:3,STAMINA:4,JUMP:5},E={BLACK:1,BLUE:2,BROWN:3,GRAY:4,GREEN:5,PINK:6,PURPLE:7,RED:8,WHITE:9,YELLOW:10},D={CAVE:1,FOREST:2,GRASSLAND:3,MOUNTAIN:4,RARE:5,ROUGH_TERRAIN:6,SEA:7,URBAN:8,WATERS_EDGE:9,MONTAIN:4},O={BALL:1,SQUIGGLE:2,FISH:3,ARMS:4,BLOB:5,UPRIGHT:6,LEGS:7,QUADRUPED:8,WINGS:9,TENTACLES:10,HEADS:11,HUMANOID:12,BUG_WINGS:13,ARMOR:14},k={HP:1,ATTACK:2,DEFENSE:3,SPECIAL_ATTACK:4,SPECIAL_DEFENSE:5,SPEED:6,ACCURACY:7,EVASION:8,SPECIAL:9},A={NORMAL:1,FIGHTING:2,FLYING:3,POISON:4,GROUND:5,ROCK:6,BUG:7,GHOST:8,STEEL:9,FIRE:10,WATER:11,GRASS:12,ELECTRIC:13,PSYCHIC:14,ICE:15,DRAGON:16,DARK:17,FAIRY:18,STELLAR:19,UNKNOWN:10001,SHADOW:10002},j={REST:`https://pokeapi.co/api/v2`,SPRITES:`https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites`},M={JA_HRKT:1,JA_ROMA:2,KO:3,ZH_HANT:4,FR:5,DE:6,ES:7,IT:8,EN:9,CS:10,JA:11,ZH_HANS:12,PT_BR:13,ES_419:14};var se=t({BASE_URL:()=>j,BERRIES:()=>n,BERRY_FIRMNESSES:()=>r,BERRY_FLAVORS:()=>i,CONTEST_TYPES:()=>a,CURRENCIES:()=>o,EGG_GROUPS:()=>x,ENCOUNTER_CONDITIONS:()=>c,ENCOUNTER_CONDITION_VALUES:()=>l,ENCOUNTER_METHODS:()=>s,ENDPOINTS:()=>u,EVOLUTION_TRIGGERS:()=>d,GENDERS:()=>S,GENERATIONS:()=>f,GROWTH_RATES:()=>C,ITEM_ATTRIBUTES:()=>g,ITEM_CATEGORIES:()=>ee,ITEM_FLING_EFFECTS:()=>_,ITEM_POCKETS:()=>v,LANGUAGES:()=>M,MOVE_AILMENTS:()=>re,MOVE_BATTLE_STYLES:()=>ie,MOVE_CATEGORIES:()=>ae,MOVE_DAMAGE_CLASSES:()=>oe,MOVE_LEARN_METHODS:()=>y,MOVE_TARGETS:()=>b,NATURES:()=>w,PAL_PARK_AREAS:()=>ne,POKEATHLON_STATS:()=>T,POKEDEXES:()=>p,POKEMON_COLORS:()=>E,POKEMON_HABITATS:()=>D,POKEMON_SHAPES:()=>O,REGIONS:()=>te,STATS:()=>k,TYPES:()=>A,VERSIONS:()=>m,VERSION_GROUPS:()=>h});const N=3e5,P=(e,t)=>e!==void 0&&Number.isFinite(e)?Math.max(Math.floor(e),0):t;var F=class{entries=new Map;ttl;maxEntries;constructor(e){this.ttl=e?.ttl??N,this.maxEntries=P(e?.maxEntries,500)}get(e){let t=this.entries.get(e);if(t){if(t.expiresAt<=Date.now()){this.entries.delete(e);return}return this.entries.delete(e),this.entries.set(e,t),t.value}}set(e,t){if(this.entries.delete(e),this.maxEntries!==0){if(this.entries.size>=this.maxEntries){let e=this.entries.keys().next();e.done||this.entries.delete(e.value)}this.entries.set(e,{value:t,expiresAt:Date.now()+this.ttl})}}delete(e){this.entries.delete(e)}clear(){this.entries.clear()}},I=class{entries=new Map;maxEntries;constructor(e){this.maxEntries=P(e?.maxEntries,500)}get(e){let t=this.entries.get(e);if(t)return this.entries.delete(e),this.entries.set(e,t),t}set(e,t){if(this.entries.delete(e),this.maxEntries!==0){if(this.entries.size>=this.maxEntries){let e=this.entries.keys().next();e.done||this.entries.delete(e.value)}this.entries.set(e,t)}}clear(){this.entries.clear()}},ce=class{storage;ttl;prefix;constructor(e){this.storage=e.storage,this.ttl=e.ttl??N,this.prefix=e.prefix??`pokenode:`}async get(e){let t=await this.read(this.prefix+e);if(t){if(t.expiresAt<=Date.now()){await this.remove(this.prefix+e);return}return t.value}}async set(e,t){let n=JSON.stringify({value:t,expiresAt:Date.now()+this.ttl});try{await this.storage.setItem(this.prefix+e,n)}catch{await this.evict();try{await this.storage.setItem(this.prefix+e,n)}catch{return}}}async delete(e){await this.storage.removeItem(this.prefix+e)}async clear(){for(let e of await this.ownKeys())await this.remove(e)}async read(e){let t;try{t=await this.storage.getItem(e)}catch{return}if(t!==null)try{return JSON.parse(t)}catch{await this.remove(e);return}}async evict(){let e=await this.ownKeys(),t=await Promise.all(e.map(async e=>({key:e,expiresAt:(await this.read(e))?.expiresAt}))),n=Date.now(),r=t.filter(({expiresAt:e})=>e===void 0||e<=n);if(r.length>0){for(let{key:e}of r)await this.remove(e);return}let i=t.sort((e,t)=>(e.expiresAt??0)-(t.expiresAt??0));for(let{key:e}of i.slice(0,Math.ceil(i.length/4)))await this.remove(e)}async ownKeys(){return(await this.allKeys()).filter(e=>e.startsWith(this.prefix))}async allKeys(){try{if(this.storage.getAllKeys!==void 0)return[...await this.storage.getAllKeys()];let{key:e,length:t}=this.storage;if(e===void 0||t===void 0)return[];let n=[];for(let r=0;r<t;r+=1){let t=e.call(this.storage,r);t!==null&&n.push(t)}return n}catch{return[]}}async remove(e){try{await this.storage.removeItem(e)}catch{}}};const L=`pokenode:http`;var R=class extends Error{name=`PokenodeError`;kind=L;status;statusText;url;body;constructor(e,t,n){super(n??`Request to ${e.url} failed with status ${e.status}`),this.status=e.status,this.statusText=e.statusText,this.url=e.url,this.body=t}static isPokenodeError(e){return typeof e==`object`&&!!e&&`kind`in e&&e.kind===L}};const z=async(e,t)=>{let n;try{n=await e.json()}catch{n=void 0}return new R(e,n,t)},B=e=>({msg:e,message:e}),le={debug(e){if(e.event===`request`){console.log(`[ Request Config ] ${e.method} | ${e.url}`);return}if(e.event===`retry`){console.log(`[ Retry ] ATTEMPT ${e.attempt} | STATUS ${e.status??`NONE`} | IN ${e.delayMs.toFixed(0)}ms | ${e.url}`);return}if(e.event===`cancelled`){console.log(`[ Cancelled ] ${e.url} | AFTER ${e.durationMs.toFixed(1)}ms`);return}console.log(`[ Response ] STATUS ${e.status} | ${e.source.toUpperCase()} | ${e.durationMs.toFixed(1)}ms`)},error({url:e,err:t}){let{name:n,message:r}=t instanceof Error?t:{name:`UNKNOWN`,message:String(t)};console.error(`[ Response Error ] ${e} | CODE ${n} | ${r}`)}};var ue=class{requests=new Map;async share(e,t,n){let r=this.requests.get(e),i=r??this.dispatch(e,t,n);return{value:await this.join(e,i,t),joined:r!==void 0}}dispatch(e,t,n){let r=t?new AbortController:void 0,i={promise:n(r?.signal),controller:r,waiters:0};return i.promise=i.promise.finally(()=>this.release(e,i)),i.promise.catch(()=>{}),this.requests.set(e,i),i}release(e,t){this.requests.get(e)===t&&this.requests.delete(e)}join(e,t,n){return t.waiters+=1,n?new Promise((r,i)=>{let a=()=>{--t.waiters,!(t.waiters>0)&&(this.release(e,t),t.controller?.abort(n.reason))};if(n.aborted){a(),i(n.reason);return}let o=()=>{a(),i(n.reason)};n.addEventListener(`abort`,o,{once:!0}),t.promise.then(e=>{n.removeEventListener(`abort`,o),r(e)},e=>{n.removeEventListener(`abort`,o),i(e)})}):t.promise}};const V=async(e,t,n)=>{let r=Array(e.length),i=0,a=!1,o=async()=>{for(;i<e.length&&!a;){let t=i;i+=1;try{r[t]=await n(e[t])}catch(e){throw a=!0,e}}},s=Number.isFinite(t)?t:4,c=Array.from({length:Math.min(Math.max(s,1),e.length)},()=>o());return await Promise.all(c),r};async function*de(e,t,n){let r=n?.pageSize??20,i=n?.concurrency??4,a=0;for(;;){let o=await e(a,r);if(o.results.length===0||(n?.resolve?yield*await V(o.results,i,t):yield*o.results,a+=o.results.length,o.results.length<r||a>=o.count))return}}const H=5e3,fe=[429,500,502,503,504],pe=e=>{if(!e)return 1;let t=e.attempts??3;return Number.isFinite(t)?Math.max(Math.floor(t),1):3},U=(e,t)=>e!==void 0&&Number.isFinite(e)?Math.max(e,0):t,me=e=>{if(e===null)return;let t=e.trim();if(t===``)return;let n=Number(t);if(Number.isFinite(n))return Math.max(n,0)*1e3;let r=Date.parse(t);return Number.isNaN(r)?void 0:Math.max(r-Date.now(),0)},W=(e,t)=>t?.aborted===!0||e instanceof Error&&(e.name===`AbortError`||e.name===`TimeoutError`),he=(e,t)=>new Promise((n,r)=>{if(t?.aborted){r(t.reason);return}let i=setTimeout(()=>{t?.removeEventListener(`abort`,a),n()},e);i.unref?.();let a=()=>{clearTimeout(i),r(t?.reason)};t?.addEventListener(`abort`,a,{once:!0})}),ge=async(e,t,n)=>{let r=n?.statuses??fe,i=U(n?.maxDelay,H);if(t||!r.includes(e.status))throw await z(e);let a=me(e.headers.get(`Retry-After`));if(a!==void 0&&a>i)throw await z(e);return a},G=async e=>{let{url:t,attempt:n,status:r,retryAfter:i,signal:a,retry:o,logger:s}=e,c=U(o?.initialDelay,300),l=U(o?.maxDelay,H),u=Math.min(c*2**(n-1),l),d=i??u/2+u/2*Math.random();s?.debug({event:`retry`,...B(`pokeapi request failed, retrying`),url:t,attempt:n,delayMs:d,...r===void 0?{}:{status:r}}),await he(d,a)},K=e=>{let t=e.length;for(;t>0&&e[t-1]===`/`;)--t;return e.slice(0,t)},_e=(e,t,n)=>`${e}?${new URLSearchParams({offset:String(t),limit:String(n)})}`,ve=e=>{let t=e.indexOf(`?`);return t===-1?K(e):K(e.slice(0,t))+e.slice(t)},ye=/^v\d+$/,q=e=>{try{return decodeURIComponent(e)}catch{return e}},be=(e,t)=>{let n=`${q(e)}:${q(t)}`,r=new TextEncoder().encode(n),i=``;for(let e of r)i+=String.fromCodePoint(e);return`Basic ${btoa(i)}`},xe=e=>{if(!e.includes(`@`))return{url:e,authorization:void 0};let t;try{t=new URL(e)}catch{return{url:e,authorization:void 0}}if(!t.username&&!t.password)return{url:e,authorization:void 0};let n=be(t.username,t.password);return t.username=``,t.password=``,{url:t.toString(),authorization:n}},Se=(e,t)=>{let n=new URL(e),r=new URL(t),i=K(r.pathname);if(n.origin===r.origin&&(n.pathname===i||n.pathname.startsWith(`${i}/`)))return`${n.pathname.slice(i.length)}${n.search}`;let a=n.pathname.split(`/`),o=a.findIndex(e=>ye.test(e));if(o===-1)throw TypeError(`Cannot resolve "${e}" against the base URL "${t}"`);return`/${a.slice(o+1).join(`/`)}${n.search}`},Ce=(e,t)=>e?`in-flight`:t===!0?`revalidated`:`network`,we=e=>{if(e)return e===!0?new I:e};var J=class e{config;state;scope;constructor(e,t,n={}){this.config=e,this.state=t,this.scope=n}static create(t){return new e({baseURL:K(t?.baseURL??j.REST),fetch:t?.fetch??((e,t)=>globalThis.fetch(e,t)),logger:t?.logger,retry:t?.retry},{cache:t?.cache===!1?void 0:t?.cache??new F,etags:we(t?.revalidate),inFlight:new ue,counts:{network:0,cache:0,"in-flight":0,revalidated:0},roundTrips:{count:0}})}get stats(){let{network:e,cache:t,revalidated:n}=this.state.counts;return{network:e,cache:t,inFlight:this.state.counts[`in-flight`],revalidated:n,roundTrips:this.state.roundTrips.count}}get cache(){return this.state.cache}with(t){return new e(this.config,this.state,{...this.scope,...t})}async clear(){await this.state.cache?.clear?.(),this.state.etags?.clear()}async resource(e,...t){let n=t.map(e=>encodeURIComponent(e)).join(`/`);return this.request(n===``?e:`${e}/${n}`)}async byURL(e,t=this.config.baseURL){let n=typeof e==`string`?e:e.url;return this.request(Se(n,t),t)}async list(e,t=0,n=20){return this.request(_e(e,t,n))}async resolveAll(e,t=4){return V(e,t,e=>this.byURL(e))}walk(e,t){return de(e,e=>this.byURL(e),t)}async request(e,t=this.config.baseURL){let n=e.startsWith(`/`)?e:`/${e}`,{url:r,authorization:i}=xe(ve(`${K(t)}${n}`)),a=performance.now();this.config.logger?.debug({event:`request`,...B(`pokeapi request`),method:`GET`,url:r});let o=this.requestSignal();try{if(o?.aborted)throw o.reason;let e=await this.state.cache?.get(r);if(e!==void 0)return this.recordResponse(r,200,`cache`,a),e;let{value:t,joined:n}=await this.state.inFlight.share(r,o,e=>this.fetchResource(r,i,e));return this.recordResponse(r,t.status,Ce(n,t.revalidated),a),t.data}catch(e){throw W(e,o)?(this.config.logger?.debug({event:`cancelled`,...B(`pokeapi request cancelled`),url:r,reason:e,durationMs:performance.now()-a}),e):(this.config.logger?.error({event:`error`,...B(`pokeapi request failed`),url:r,err:e,error:e}),e)}}requestSignal(){let{signal:e,timeout:t}=this.scope;if(t===void 0)return e;let n=AbortSignal.timeout(t);return e?AbortSignal.any([e,n]):n}async fetchResource(e,t,n){let r=this.state.etags?.get(e),i={Accept:`application/json`,...t===void 0?{}:{Authorization:t},...r===void 0?{}:{"If-None-Match":r.etag}},a=n?{headers:i,signal:n}:{headers:i},{retry:o,logger:s}=this.config,c=pe(o);for(let t=1;;t+=1){let i=t>=c,l;try{this.state.roundTrips.count+=1,l=await this.config.fetch(e,a)}catch(r){if(i||W(r,n))throw r;await G({url:e,attempt:t,status:void 0,retryAfter:void 0,signal:n,retry:o,logger:s});continue}let u=await this.resolveResponse(e,l,r);if(u!==void 0)return u;let d=await ge(l,i,o);l.body?.cancel().catch(()=>{}),await G({url:e,attempt:t,status:l.status,retryAfter:d,signal:n,retry:o,logger:s})}}async resolveResponse(e,t,n){if(t.status===304){if(n===void 0)throw await z(t,`Request to ${t.url} was answered 304, but this client holds no response to reuse`);let r=t.headers.get(`ETag`);return r!==null&&r!==n.etag&&this.state.etags?.set(e,{etag:r,value:n.value}),await this.state.cache?.set(e,n.value),{data:n.value,status:t.status,revalidated:!0}}if(!t.ok)return;let r=await t.json(),i=t.headers.get(`ETag`);return i!==null&&this.state.etags?.set(e,{etag:i,value:r}),await this.state.cache?.set(e,r),{data:r,status:t.status}}recordResponse(e,t,n,r){this.state.counts[n]+=1,this.config.logger?.debug({event:`response`,...B(`pokeapi response`),url:e,status:t,source:n,durationMs:performance.now()-r})}},Te=class{#e;constructor(e){this.#e=e instanceof J?e:J.create(e)}get cache(){return this.#e.cache}get stats(){return this.#e.stats}statsSince(e){let t=this.#e.stats;return{network:t.network-e.network,cache:t.cache-e.cache,inFlight:t.inFlight-e.inFlight,revalidated:t.revalidated-e.revalidated,roundTrips:t.roundTrips-e.roundTrips}}with(e){let t=this.constructor;return new t(this.#e.with(e))}async clearCache(){await this.#e.clear()}async resolve(e){return this.#e.byURL(e)}async resolveAll(e,t){return this.#e.resolveAll(e,t?.concurrency)}async getResource(e,...t){return this.#e.resource(e,...t)}async getResourceByURL(e,t){return this.#e.byURL(e,t)}async getListResource(e,t,n){return this.#e.list(e,t,n)}async getUnnamedListResource(e,t,n){return this.#e.list(e,t,n)}walk(e,t){return this.#e.walk(e,t)}},Y=class extends Te{paginate(e,t){let n=typeof e==`function`?e:(t,n)=>this[e](t,n);return this.walk(n,t)}},Ee=class extends Y{async getBerryByName(e){return this.getResource(u.BERRY,e)}async getBerryById(e){return this.getResource(u.BERRY,e)}async getBerryFirmnessById(e){return this.getResource(u.BERRY_FIRMNESS,e)}async getBerryFirmnessByName(e){return this.getResource(u.BERRY_FIRMNESS,e)}async getBerryFlavorById(e){return this.getResource(u.BERRY_FLAVOR,e)}async getBerryFlavorByName(e){return this.getResource(u.BERRY_FLAVOR,e)}async listBerries(e,t){return this.getListResource(u.BERRY,e,t)}async listBerryFirmnesses(e,t){return this.getListResource(u.BERRY_FIRMNESS,e,t)}async listBerryFlavors(e,t){return this.getListResource(u.BERRY_FLAVOR,e,t)}},De=class extends Y{async getContestTypeByName(e){return this.getResource(u.CONTEST_TYPE,e)}async getContestTypeById(e){return this.getResource(u.CONTEST_TYPE,e)}async getContestEffectById(e){return this.getResource(u.CONTEST_EFFECT,e)}async getSuperContestEffectById(e){return this.getResource(u.SUPER_CONTEST_EFFECT,e)}async listContestTypes(e,t){return this.getListResource(u.CONTEST_TYPE,e,t)}async listContestEffects(e,t){return this.getUnnamedListResource(u.CONTEST_EFFECT,e,t)}async listSuperContestEffects(e,t){return this.getUnnamedListResource(u.SUPER_CONTEST_EFFECT,e,t)}},Oe=class extends Y{async getCurrencyByName(e){return this.getResource(u.CURRENCY,e)}async getCurrencyById(e){return this.getResource(u.CURRENCY,e)}async listCurrencies(e,t){return this.getListResource(u.CURRENCY,e,t)}},ke=class extends Y{async getEncounterMethodByName(e){return this.getResource(u.ENCOUNTER_METHOD,e)}async getEncounterMethodById(e){return this.getResource(u.ENCOUNTER_METHOD,e)}async getEncounterConditionById(e){return this.getResource(u.ENCOUNTER_CONDITION,e)}async getEncounterConditionByName(e){return this.getResource(u.ENCOUNTER_CONDITION,e)}async getEncounterConditionValueByName(e){return this.getResource(u.ENCOUNTER_CONDITION_VALUE,e)}async getEncounterConditionValueById(e){return this.getResource(u.ENCOUNTER_CONDITION_VALUE,e)}async listEncounterMethods(e,t){return this.getListResource(u.ENCOUNTER_METHOD,e,t)}async listEncounterConditions(e,t){return this.getListResource(u.ENCOUNTER_CONDITION,e,t)}async listEncounterConditionValues(e,t){return this.getListResource(u.ENCOUNTER_CONDITION_VALUE,e,t)}},Ae=class extends Y{async getEvolutionChainById(e){return this.getResource(u.EVOLUTION_CHAIN,e)}async getEvolutionTriggerById(e){return this.getResource(u.EVOLUTION_TRIGGER,e)}async getEvolutionTriggerByName(e){return this.getResource(u.EVOLUTION_TRIGGER,e)}async listEvolutionChains(e,t){return this.getUnnamedListResource(u.EVOLUTION_CHAIN,e,t)}async listEvolutionTriggers(e,t){return this.getListResource(u.EVOLUTION_TRIGGER,e,t)}},je=class extends Y{async getGenerationByName(e){return this.getResource(u.GENERATION,e)}async getGenerationById(e){return this.getResource(u.GENERATION,e)}async getPokedexByName(e){return this.getResource(u.POKEDEX,e)}async getPokedexById(e){return this.getResource(u.POKEDEX,e)}async getVersionByName(e){return this.getResource(u.VERSION,e)}async getVersionById(e){return this.getResource(u.VERSION,e)}async getVersionGroupByName(e){return this.getResource(u.VERSION_GROUP,e)}async getVersionGroupById(e){return this.getResource(u.VERSION_GROUP,e)}async listGenerations(e,t){return this.getListResource(u.GENERATION,e,t)}async listPokedexes(e,t){return this.getListResource(u.POKEDEX,e,t)}async listVersions(e,t){return this.getListResource(u.VERSION,e,t)}async listVersionGroups(e,t){return this.getListResource(u.VERSION_GROUP,e,t)}},Me=class extends Y{async getItemByName(e){return this.getResource(u.ITEM,e)}async getItemById(e){return this.getResource(u.ITEM,e)}async getItemAttributeByName(e){return this.getResource(u.ITEM_ATTRIBUTE,e)}async getItemAttributeById(e){return this.getResource(u.ITEM_ATTRIBUTE,e)}async getItemCategoryByName(e){return this.getResource(u.ITEM_CATEGORY,e)}async getItemCategoryById(e){return this.getResource(u.ITEM_CATEGORY,e)}async getItemFlingEffectByName(e){return this.getResource(u.ITEM_FLING_EFFECT,e)}async getItemFlingEffectById(e){return this.getResource(u.ITEM_FLING_EFFECT,e)}async getItemPocketByName(e){return this.getResource(u.ITEM_POCKET,e)}async getItemPocketById(e){return this.getResource(u.ITEM_POCKET,e)}async listItems(e,t){return this.getListResource(u.ITEM,e,t)}async listItemAttributes(e,t){return this.getListResource(u.ITEM_ATTRIBUTE,e,t)}async listItemCategories(e,t){return this.getListResource(u.ITEM_CATEGORY,e,t)}async listItemFlingEffects(e,t){return this.getListResource(u.ITEM_FLING_EFFECT,e,t)}async listItemPockets(e,t){return this.getListResource(u.ITEM_POCKET,e,t)}},Ne=class extends Y{async getLocationByName(e){return this.getResource(u.LOCATION,e)}async getLocationById(e){return this.getResource(u.LOCATION,e)}async getLocationAreaByName(e){return this.getResource(u.LOCATION_AREA,e)}async getLocationAreaById(e){return this.getResource(u.LOCATION_AREA,e)}async getPalParkAreaByName(e){return this.getResource(u.PALPARK_AREA,e)}async getPalParkAreaById(e){return this.getResource(u.PALPARK_AREA,e)}async getRegionByName(e){return this.getResource(u.REGION,e)}async getRegionById(e){return this.getResource(u.REGION,e)}async listLocations(e,t){return this.getListResource(u.LOCATION,e,t)}async listLocationAreas(e,t){return this.getListResource(u.LOCATION_AREA,e,t)}async listPalParkAreas(e,t){return this.getListResource(u.PALPARK_AREA,e,t)}async listRegions(e,t){return this.getListResource(u.REGION,e,t)}},Pe=class extends Y{async getMachineById(e){return this.getResource(u.MACHINE,e)}async listMachines(e,t){return this.getUnnamedListResource(u.MACHINE,e,t)}},Fe=class extends Y{async getMoveByName(e){return this.getResource(u.MOVE,e)}async getMoveById(e){return this.getResource(u.MOVE,e)}async getMoveAilmentByName(e){return this.getResource(u.MOVE_AILMENT,e)}async getMoveAilmentById(e){return this.getResource(u.MOVE_AILMENT,e)}async getMoveBattleStyleByName(e){return this.getResource(u.MOVE_BATTLE_STYLE,e)}async getMoveBattleStyleById(e){return this.getResource(u.MOVE_BATTLE_STYLE,e)}async getMoveCategoryByName(e){return this.getResource(u.MOVE_CATEGORY,e)}async getMoveCategoryById(e){return this.getResource(u.MOVE_CATEGORY,e)}async getMoveDamageClassByName(e){return this.getResource(u.MOVE_DAMAGE_CLASS,e)}async getMoveDamageClassById(e){return this.getResource(u.MOVE_DAMAGE_CLASS,e)}async getMoveLearnMethodByName(e){return this.getResource(u.MOVE_LEARN_METHOD,e)}async getMoveLearnMethodById(e){return this.getResource(u.MOVE_LEARN_METHOD,e)}async getMoveTargetByName(e){return this.getResource(u.MOVE_TARGET,e)}async getMoveTargetById(e){return this.getResource(u.MOVE_TARGET,e)}async listMoves(e,t){return this.getListResource(u.MOVE,e,t)}async listMoveAilments(e,t){return this.getListResource(u.MOVE_AILMENT,e,t)}async listMoveBattleStyles(e,t){return this.getListResource(u.MOVE_BATTLE_STYLE,e,t)}async listMoveCategories(e,t){return this.getListResource(u.MOVE_CATEGORY,e,t)}async listMoveDamageClasses(e,t){return this.getListResource(u.MOVE_DAMAGE_CLASS,e,t)}async listMoveLearnMethods(e,t){return this.getListResource(u.MOVE_LEARN_METHOD,e,t)}async listMoveTargets(e,t){return this.getListResource(u.MOVE_TARGET,e,t)}},Ie=class extends Y{async getAbilityByName(e){return this.getResource(u.ABILITY,e)}async getAbilityById(e){return this.getResource(u.ABILITY,e)}async getCharacteristicById(e){return this.getResource(u.CHARACTERISTIC,e)}async getEggGroupByName(e){return this.getResource(u.EGG_GROUP,e)}async getEggGroupById(e){return this.getResource(u.EGG_GROUP,e)}async getGenderByName(e){return this.getResource(u.GENDER,e)}async getGenderById(e){return this.getResource(u.GENDER,e)}async getGrowthRateByName(e){return this.getResource(u.GROWTH_RATE,e)}async getGrowthRateById(e){return this.getResource(u.GROWTH_RATE,e)}async getNatureByName(e){return this.getResource(u.NATURE,e)}async getNatureById(e){return this.getResource(u.NATURE,e)}async getPokeathlonStatByName(e){return this.getResource(u.POKEATHLON_STAT,e)}async getPokeathlonStatById(e){return this.getResource(u.POKEATHLON_STAT,e)}async getPokemonByName(e){return this.getResource(u.POKEMON,e)}async getPokemonById(e){return this.getResource(u.POKEMON,e)}async getPokemonLocationAreaById(e){return this.getResource(u.POKEMON,e,`encounters`)}async getPokemonColorByName(e){return this.getResource(u.POKEMON_COLOR,e)}async getPokemonColorById(e){return this.getResource(u.POKEMON_COLOR,e)}async getPokemonFormByName(e){return this.getResource(u.POKEMON_FORM,e)}async getPokemonFormById(e){return this.getResource(u.POKEMON_FORM,e)}async getPokemonHabitatByName(e){return this.getResource(u.POKEMON_HABITAT,e)}async getPokemonHabitatById(e){return this.getResource(u.POKEMON_HABITAT,e)}async getPokemonShapeByName(e){return this.getResource(u.POKEMON_SHAPE,e)}async getPokemonShapeById(e){return this.getResource(u.POKEMON_SHAPE,e)}async getPokemonSpeciesByName(e){return this.getResource(u.POKEMON_SPECIES,e)}async getPokemonSpeciesById(e){return this.getResource(u.POKEMON_SPECIES,e)}async getStatByName(e){return this.getResource(u.STAT,e)}async getStatById(e){return this.getResource(u.STAT,e)}async getTypeByName(e){return this.getResource(u.TYPE,e)}async getTypeById(e){return this.getResource(u.TYPE,e)}async listAbilities(e,t){return this.getListResource(u.ABILITY,e,t)}async listCharacteristics(e,t){return this.getUnnamedListResource(u.CHARACTERISTIC,e,t)}async listEggGroups(e,t){return this.getListResource(u.EGG_GROUP,e,t)}async listGenders(e,t){return this.getListResource(u.GENDER,e,t)}async listGrowthRates(e,t){return this.getListResource(u.GROWTH_RATE,e,t)}async listNatures(e,t){return this.getListResource(u.NATURE,e,t)}async listPokeathlonStats(e,t){return this.getListResource(u.POKEATHLON_STAT,e,t)}async listPokemons(e,t){return this.getListResource(u.POKEMON,e,t)}async listPokemonColors(e,t){return this.getListResource(u.POKEMON_COLOR,e,t)}async listPokemonForms(e,t){return this.getListResource(u.POKEMON_FORM,e,t)}async listPokemonHabitats(e,t){return this.getListResource(u.POKEMON_HABITAT,e,t)}async listPokemonShapes(e,t){return this.getListResource(u.POKEMON_SHAPE,e,t)}async listPokemonSpecies(e,t){return this.getListResource(u.POKEMON_SPECIES,e,t)}async listStats(e,t){return this.getListResource(u.STAT,e,t)}async listTypes(e,t){return this.getListResource(u.TYPE,e,t)}},Le=class extends Y{async getLanguageById(e){return this.getResource(u.LANGUAGE,e)}async getLanguageByName(e){return this.getResource(u.LANGUAGE,e)}async getResourceByUrl(e){return this.resolve(e)}listLanguages(e,t){return this.getListResource(u.LANGUAGE,e,t)}},Re=class extends Te{berry;contest;currency;encounter;evolution;game;item;location;machine;move;pokemon;utility;constructor(e){let t=e instanceof J?e:J.create(e);super(t),this.berry=new Ee(t),this.contest=new De(t),this.currency=new Oe(t),this.encounter=new ke(t),this.evolution=new Ae(t),this.game=new je(t),this.item=new Me(t),this.location=new Ne(t),this.machine=new Pe(t),this.move=new Fe(t),this.pokemon=new Ie(t),this.utility=new Le(t)}};const ze=(e,t)=>t===void 0?e.evolution_details:e.evolution_details.filter(e=>e.version_group.name===t),Be=(e,t)=>{let n=(e,r)=>e.evolves_to.flatMap(i=>{let a=ze(i,t?.versionGroup),o=n(i,r+1);return a.length===0?o:[{from:e.species,to:i.species,details:a,depth:r,isBaby:i.is_baby},...o]});return n(e.chain,1)},Ve=(e,t)=>{let n=typeof t==`string`?t:t.name,r=(e,t)=>{if(e.species.name===n)return t;for(let n of e.evolves_to){let i={from:e.species,to:n.species,details:n.evolution_details,depth:t.length+1,isBaby:n.is_baby},a=r(n,[...t,i]);if(a!==void 0)return a}};return r(e.chain,[])},He=[({item:e})=>e===null?null:{kind:`item`,item:e},({held_item:e})=>e===null?null:{kind:`held-item`,item:e},({min_level:e})=>e===null?null:{kind:`min-level`,level:e},({min_happiness:e})=>e===null?null:{kind:`min-happiness`,happiness:e},({min_beauty:e})=>e===null?null:{kind:`min-beauty`,beauty:e},({min_affection:e})=>e===null?null:{kind:`min-affection`,affection:e},({known_move:e})=>e===null?null:{kind:`known-move`,move:e},({known_move_type:e})=>e===null?null:{kind:`known-move-type`,type:e},({used_move:e})=>e===null?null:{kind:`used-move`,move:e},({min_move_count:e})=>e===null?null:{kind:`min-move-count`,count:e},({min_steps:e})=>e===null?null:{kind:`min-steps`,steps:e},({min_damage_taken:e})=>e===null?null:{kind:`min-damage-taken`,damage:e},({location:e})=>e===null?null:{kind:`location`,location:e},({region:e})=>e===null?null:{kind:`region`,region:e},({time_of_day:e})=>e===``?null:{kind:`time-of-day`,time:e},({gender:e})=>e===null?null:{kind:`gender`,gender:e},({relative_physical_stats:e})=>e===null?null:{kind:`relative-physical-stats`,comparison:e},({party_species:e})=>e===null?null:{kind:`party-species`,species:e},({party_type:e})=>e===null?null:{kind:`party-type`,type:e},({trade_species:e})=>e===null?null:{kind:`trade-species`,species:e},({base_form:e})=>e===null?null:{kind:`base-form`,form:e},({evolved_form:e})=>e===null?null:{kind:`evolved-form`,form:e},({needs_overworld_rain:e})=>e?{kind:`needs-overworld-rain`}:null,({turn_upside_down:e})=>e?{kind:`turn-upside-down`}:null,({near_special_rock:e})=>e?{kind:`near-special-rock`}:null,({needs_multiplayer:e})=>e?{kind:`needs-multiplayer`}:null],Ue=e=>[{kind:`trigger`,trigger:e.trigger},...He.flatMap(t=>t(e)??[])],We={"level-up":`level up`,trade:`trade`,"use-item":`use an item`,shed:`shed`,spin:`spin`,"tower-of-darkness":`train in the Tower of Darkness`,"tower-of-waters":`train in the Tower of Waters`,"three-critical-hits":`land three critical hits in one battle`,"take-damage":`take damage`,other:`an in-game event`,"agile-style-move":`use agile style moves`,"strong-style-move":`use strong style moves`,"recoil-damage":`take recoil damage`,"use-move":`use a move`,"three-defeated-bisharp":`defeat three pack-leading Bisharp`,"gimmighoul-coins":`collect Gimmighoul Coins`},Ge=e=>e.name.replaceAll(`-`,` `),Ke={day:`during the day`,night:`during the night`,dusk:`at dusk`,"full-moon":`under a full moon`},qe={1:`female`,2:`male`,3:`genderless`},Je=e=>qe[e]??`gender ${e}`,Ye={1:`>`,0:`=`,"-1":`<`},X=(e=Ge)=>({trigger:({trigger:t})=>We[t.name]??e(t),item:({item:t})=>`use ${e(t)}`,"held-item":({item:t})=>`holding ${e(t)}`,"min-level":({level:e})=>`at level ${e}`,"min-happiness":({happiness:e})=>`with at least ${e} happiness`,"min-beauty":({beauty:e})=>`with at least ${e} beauty`,"min-affection":({affection:e})=>`with at least ${e} affection`,"known-move":({move:t})=>`knowing ${e(t)}`,"known-move-type":({type:t})=>`knowing a ${e(t)}-type move`,"used-move":({move:t})=>`after using ${e(t)}`,"min-move-count":({count:e})=>`${e} times`,"min-steps":({steps:e})=>`after ${e} steps`,"min-damage-taken":({damage:e})=>`after taking ${e} damage`,location:({location:t})=>`at ${e(t)}`,region:({region:t})=>`in ${e(t)}`,"time-of-day":({time:e})=>Ke[e],gender:({gender:e})=>`as a ${Je(e)}`,"relative-physical-stats":({comparison:e})=>`with Attack ${Ye[String(e)]} Defense`,"party-species":({species:t})=>`with ${e(t)} in the party`,"party-type":({type:t})=>`with a ${e(t)}-type in the party`,"trade-species":({species:t})=>`traded for ${e(t)}`,"base-form":({form:t})=>`in its ${e(t)} form`,"evolved-form":({form:t})=>`into its ${e(t)} form`,"needs-overworld-rain":()=>`while it is raining`,"turn-upside-down":()=>`with the console upside down`,"near-special-rock":()=>`near a special rock`,"needs-multiplayer":()=>`in multiplayer`}),Xe=X(),Ze=new WeakMap,Qe=e=>{if(e===void 0)return Xe;let t=Ze.get(e)??X(e);return Ze.set(e,t),t},$e=(e,t)=>t[e.kind](e),et=(e,t)=>{let n={...Qe(t?.name),...t?.phrases},r=e.some(e=>e.kind===`item`)&&e.some(e=>e.kind===`trigger`&&e.trigger.name===`use-item`);return e.filter(e=>!(r&&e.kind===`trigger`)).map(e=>$e(e,n)).join(`, `)},tt=e=>{let t=typeof e==`string`?{language:e}:e??{};return{...t,language:t.language??`en`}},nt=(e,t)=>{let n=t.toLowerCase();return e.filter(e=>e.language.name.toLowerCase()===n)},rt=(e,t)=>it(e,t)[0],it=(e,t)=>{let n=tt(t),r=nt(e,n.language);return r.length>0||n.fallback===void 0?r:nt(e,n.fallback)},at=/\/(-?\d+)\/?$/,ot=e=>{let t=typeof e==`string`?e:e.url,n=at.exec(t);if(n===null)throw TypeError(`No resource id in URL: ${t}`);return Number(n[1])},st={default:{directory:``,extension:`png`},"official-artwork":{directory:`other/official-artwork`,extension:`png`},home:{directory:`other/home`,extension:`png`},"dream-world":{directory:`other/dream-world`,extension:`svg`},showdown:{directory:`other/showdown`,extension:`gif`}},ct=(e,t={})=>{let{variant:n=`default`,shiny:r=!1,back:i=!1,female:a=!1}=t,{directory:o,extension:s}=st[n],c=[o,i&&`back`,r&&`shiny`,a&&`female`];return[j.SPRITES,`pokemon`,...c.filter(Boolean),`${e}.${s}`].join(`/`)},lt=new Set(Object.entries(A).filter(([,e])=>e<1e4).map(([e])=>e.toLowerCase())),ut=e=>lt.has(e),Z=e=>{let t=e.toUpperCase().replaceAll(`-`,`_`);return f[t]??-1},dt=[[`no_damage_to`,0],[`half_damage_to`,.5],[`double_damage_to`,2]],ft=[[`no_damage_from`,0],[`half_damage_from`,.5],[`double_damage_from`,2]],Q=(e,t,n)=>{for(let[r,i]of t)if(e[r].some(e=>e.name===n))return i;return 1},pt=(e,t)=>Q(e,dt,t),mt=(e,t)=>t.reduce((t,n)=>t*pt(e,n.name),1),$=(e,t)=>{if(t===void 0)return e.damage_relations;let n=Z(t);if(n===-1)return e.damage_relations;if(!(n<Z(e.generation.name)))return[...e.past_damage_relations].sort((e,t)=>Z(e.generation.name)-Z(t.generation.name)).find(e=>Z(e.generation.name)>=n)?.damage_relations??e.damage_relations};function ht(e,t,n){let r=$(e,n?.generation);return r===void 0?void 0:mt(r,t)}const gt=(e,t,n)=>{let r={};for(let i of e){if(!ut(i.name))continue;let e=$(i,n?.generation);e!==void 0&&(r[i.name]=mt(e,t))}return r},_t=e=>{let t={};for(let n of lt)t[n]=e.reduce((e,t)=>e*Q(t.damage_relations,ft,n),1);return t};exports.BASE_URL=j,exports.BERRIES=n,exports.BERRY_FIRMNESSES=r,exports.BERRY_FLAVORS=i,exports.BerryClient=Ee,Object.defineProperty(exports,"CONSTANTS",{enumerable:!0,get:function(){return se}}),exports.CONTEST_TYPES=a,exports.CURRENCIES=o,exports.ContestClient=De,exports.CurrencyClient=Oe,exports.EGG_GROUPS=x,exports.ENCOUNTER_CONDITIONS=c,exports.ENCOUNTER_CONDITION_VALUES=l,exports.ENCOUNTER_METHODS=s,exports.ENDPOINTS=u,exports.EVOLUTION_TRIGGERS=d,exports.EncounterClient=ke,exports.EtagStore=I,exports.EvolutionClient=Ae,exports.GENDERS=S,exports.GENERATIONS=f,exports.GROWTH_RATES=C,exports.GameClient=je,exports.ITEM_ATTRIBUTES=g,exports.ITEM_CATEGORIES=ee,exports.ITEM_FLING_EFFECTS=_,exports.ITEM_POCKETS=v,exports.ItemClient=Me,exports.LANGUAGES=M,exports.LocationClient=Ne,exports.MOVE_AILMENTS=re,exports.MOVE_BATTLE_STYLES=ie,exports.MOVE_CATEGORIES=ae,exports.MOVE_DAMAGE_CLASSES=oe,exports.MOVE_LEARN_METHODS=y,exports.MOVE_TARGETS=b,exports.MachineClient=Pe,exports.MainClient=Re,exports.MemoryCache=F,exports.MoveClient=Fe,exports.NATURES=w,exports.PAL_PARK_AREAS=ne,exports.POKEATHLON_STATS=T,exports.POKEDEXES=p,exports.POKEMON_COLORS=E,exports.POKEMON_HABITATS=D,exports.POKEMON_SHAPES=O,exports.PokemonClient=Ie,exports.PokenodeError=R,exports.REGIONS=te,exports.REQUIREMENT_PHRASES=Xe,exports.STATS=k,exports.TYPES=A,exports.UtilityClient=Le,exports.VERSIONS=m,exports.VERSION_GROUPS=h,exports.WebStorageCache=ce,exports.consoleLogger=le,exports.defensiveProfile=gt,exports.defensiveProfileFrom=_t,exports.effectiveness=ht,exports.flattenChain=Be,exports.formatRequirements=et,exports.getPokemonSpriteUrl=ct,exports.localize=rt,exports.localizeAll=it,exports.pathTo=Ve,exports.relationsFor=$,exports.requirementPhrases=X,exports.requirementsOf=Ue,exports.resourceId=ot;
|
|
4109
|
+
const defensiveProfileFrom = (defending) => {
|
|
4110
|
+
const profile = {};
|
|
4111
|
+
for (const name of TYPE_NAMES) profile[name] = defending.reduce((total, type) => total * lookup(type.damage_relations, INCOMING, name), 1);
|
|
4112
|
+
return profile;
|
|
4113
|
+
};
|
|
4114
|
+
|
|
4115
|
+
//#endregion
|
|
4116
|
+
exports.BASE_URL = BASE_URL;
|
|
4117
|
+
exports.BERRIES = BERRIES;
|
|
4118
|
+
exports.BERRY_FIRMNESSES = BERRY_FIRMNESSES;
|
|
4119
|
+
exports.BERRY_FLAVORS = BERRY_FLAVORS;
|
|
4120
|
+
exports.BerryClient = BerryClient;
|
|
4121
|
+
Object.defineProperty(exports, 'CONSTANTS', {
|
|
4122
|
+
enumerable: true,
|
|
4123
|
+
get: function () {
|
|
4124
|
+
return constants_exports;
|
|
4125
|
+
}
|
|
4126
|
+
});
|
|
4127
|
+
exports.CONTEST_TYPES = CONTEST_TYPES;
|
|
4128
|
+
exports.CURRENCIES = CURRENCIES;
|
|
4129
|
+
exports.ContestClient = ContestClient;
|
|
4130
|
+
exports.CurrencyClient = CurrencyClient;
|
|
4131
|
+
exports.EGG_GROUPS = EGG_GROUPS;
|
|
4132
|
+
exports.ENCOUNTER_CONDITIONS = ENCOUNTER_CONDITIONS;
|
|
4133
|
+
exports.ENCOUNTER_CONDITION_VALUES = ENCOUNTER_CONDITION_VALUES;
|
|
4134
|
+
exports.ENCOUNTER_METHODS = ENCOUNTER_METHODS;
|
|
4135
|
+
exports.ENDPOINTS = ENDPOINTS;
|
|
4136
|
+
exports.EVOLUTION_TRIGGERS = EVOLUTION_TRIGGERS;
|
|
4137
|
+
exports.EVOLUTION_VARIABLES = EVOLUTION_VARIABLES;
|
|
4138
|
+
exports.EncounterClient = EncounterClient;
|
|
4139
|
+
exports.EtagStore = EtagStore;
|
|
4140
|
+
exports.EvolutionClient = EvolutionClient;
|
|
4141
|
+
exports.GENDERS = GENDERS;
|
|
4142
|
+
exports.GENERATIONS = GENERATIONS;
|
|
4143
|
+
exports.GROWTH_RATES = GROWTH_RATES;
|
|
4144
|
+
exports.GameClient = GameClient;
|
|
4145
|
+
exports.ITEM_ATTRIBUTES = ITEM_ATTRIBUTES;
|
|
4146
|
+
exports.ITEM_CATEGORIES = ITEM_CATEGORIES;
|
|
4147
|
+
exports.ITEM_FLING_EFFECTS = ITEM_FLING_EFFECTS;
|
|
4148
|
+
exports.ITEM_POCKETS = ITEM_POCKETS;
|
|
4149
|
+
exports.ItemClient = ItemClient;
|
|
4150
|
+
exports.LANGUAGES = LANGUAGES;
|
|
4151
|
+
exports.LocationClient = LocationClient;
|
|
4152
|
+
exports.MOVE_AILMENTS = MOVE_AILMENTS;
|
|
4153
|
+
exports.MOVE_BATTLE_STYLES = MOVE_BATTLE_STYLES;
|
|
4154
|
+
exports.MOVE_CATEGORIES = MOVE_CATEGORIES;
|
|
4155
|
+
exports.MOVE_DAMAGE_CLASSES = MOVE_DAMAGE_CLASSES;
|
|
4156
|
+
exports.MOVE_LEARN_METHODS = MOVE_LEARN_METHODS;
|
|
4157
|
+
exports.MOVE_TARGETS = MOVE_TARGETS;
|
|
4158
|
+
exports.MachineClient = MachineClient;
|
|
4159
|
+
exports.MainClient = MainClient;
|
|
4160
|
+
exports.MemoryCache = MemoryCache;
|
|
4161
|
+
exports.MoveClient = MoveClient;
|
|
4162
|
+
exports.NATURES = NATURES;
|
|
4163
|
+
exports.PAL_PARK_AREAS = PAL_PARK_AREAS;
|
|
4164
|
+
exports.POKEATHLON_STATS = POKEATHLON_STATS;
|
|
4165
|
+
exports.POKEDEXES = POKEDEXES;
|
|
4166
|
+
exports.POKEMON_COLORS = POKEMON_COLORS;
|
|
4167
|
+
exports.POKEMON_HABITATS = POKEMON_HABITATS;
|
|
4168
|
+
exports.POKEMON_SHAPES = POKEMON_SHAPES;
|
|
4169
|
+
exports.PokemonClient = PokemonClient;
|
|
4170
|
+
exports.PokenodeError = PokenodeError;
|
|
4171
|
+
exports.REGIONS = REGIONS;
|
|
4172
|
+
exports.REQUIREMENT_PHRASES = REQUIREMENT_PHRASES;
|
|
4173
|
+
exports.STATS = STATS;
|
|
4174
|
+
exports.TYPES = TYPES;
|
|
4175
|
+
exports.UtilityClient = UtilityClient;
|
|
4176
|
+
exports.VERSIONS = VERSIONS;
|
|
4177
|
+
exports.VERSION_GROUPS = VERSION_GROUPS;
|
|
4178
|
+
exports.WebStorageCache = WebStorageCache;
|
|
4179
|
+
exports.consoleLogger = consoleLogger;
|
|
4180
|
+
exports.defensiveProfile = defensiveProfile;
|
|
4181
|
+
exports.defensiveProfileFrom = defensiveProfileFrom;
|
|
4182
|
+
exports.effectiveness = effectiveness;
|
|
4183
|
+
exports.flattenChain = flattenChain;
|
|
4184
|
+
exports.formatRequirements = formatRequirements;
|
|
4185
|
+
exports.getPokemonSpriteUrl = getPokemonSpriteUrl;
|
|
4186
|
+
exports.localize = localize;
|
|
4187
|
+
exports.localizeAll = localizeAll;
|
|
4188
|
+
exports.pathTo = pathTo;
|
|
4189
|
+
exports.relationsFor = relationsFor;
|
|
4190
|
+
exports.requirementPhrases = requirementPhrases;
|
|
4191
|
+
exports.requirementsOf = requirementsOf;
|
|
4192
|
+
exports.resourceId = resourceId;
|
|
17
4193
|
//# sourceMappingURL=index.cjs.map
|