@wise-old-man/utils 2.0.3 → 2.0.6

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/dist/index.d.ts CHANGED
@@ -1473,7 +1473,6 @@ declare type NameChangeDetails = {
1473
1473
  };
1474
1474
  };
1475
1475
 
1476
- declare type PlayerResolvable = Partial<Pick<Player, 'id' | 'username'>>;
1477
1476
  interface PlayerDetails extends Player {
1478
1477
  combatLevel: number;
1479
1478
  latestSnapshot: FormattedSnapshot;
@@ -1677,8 +1676,9 @@ declare function isSkill(metric: Metric | string): metric is Skill;
1677
1676
  declare function isActivity(metric: Metric | string): metric is Activity;
1678
1677
  declare function isBoss(metric: Metric | string): metric is Boss;
1679
1678
  declare function isComputedMetric(metric: Metric | string): metric is ComputedMetric;
1680
- declare function getMetricRankKey(metric: Metric): string;
1681
- declare function getMetricValueKey(metric: Metric): string;
1679
+ declare function getMetricRankKey<T extends Metric>(metric: T): `${T}Rank`;
1680
+ declare type MetricValueKey = `${Skill}Experience` | `${Boss}Kills` | `${Activity}Score` | `${ComputedMetric}Value`;
1681
+ declare function getMetricValueKey(metric: Metric): MetricValueKey;
1682
1682
  declare function getMetricMeasure(metric: Metric): MetricMeasure;
1683
1683
  declare function getMetricName(metric: Metric): string;
1684
1684
  declare function getMinimumValue(metric: Metric): number;
@@ -1752,10 +1752,7 @@ interface CreateGroupResponse {
1752
1752
  group: GroupDetails;
1753
1753
  verificationCode: string;
1754
1754
  }
1755
- interface ChangeMemberRolePayload {
1756
- username: string;
1757
- role: GroupRole;
1758
- }
1755
+ declare type ChangeMemberRolePayload = Required<GroupMemberFragment>;
1759
1756
  declare type GetGroupGainsFilter = {
1760
1757
  metric: Metric;
1761
1758
  } & TimeRangeFilter;
@@ -1808,7 +1805,7 @@ declare type NameChangesSearchFilter = {
1808
1805
  */
1809
1806
  interface RecordLeaderboardFilter extends BasePlayerFilter {
1810
1807
  metric: Metric;
1811
- period: Period | string;
1808
+ period: Period;
1812
1809
  }
1813
1810
  /**
1814
1811
  * Player Client Types
@@ -1958,72 +1955,67 @@ declare class PlayersClient extends BaseAPIClient {
1958
1955
  * Updates/tracks a player.
1959
1956
  * @returns The player's new details, including the latest snapshot.
1960
1957
  */
1961
- updatePlayer(player: PlayerResolvable): Promise<PlayerDetails>;
1958
+ updatePlayer(username: string): Promise<PlayerDetails>;
1962
1959
  /**
1963
1960
  * Asserts (and attempts to fix, if necessary) a player's game-mode type.
1964
1961
  * @returns The updated player, and an indication of whether the type was changed.
1965
1962
  */
1966
- assertPlayerType(player: PlayerResolvable): Promise<AssertPlayerTypeResponse>;
1967
- /**
1968
- * Attempts to import a player's snapshot history from CrystalMathLabs.
1969
- * @returns The number of snapshots that were imported.
1970
- */
1971
- importPlayer(player: PlayerResolvable): Promise<GenericCountMessageResponse>;
1963
+ assertPlayerType(username: string): Promise<AssertPlayerTypeResponse>;
1972
1964
  /**
1973
1965
  * Fetches a player's details.
1974
1966
  * @returns The player's details, including the latest snapshot.
1975
1967
  */
1976
- getPlayerDetails(player: PlayerResolvable): Promise<PlayerDetails>;
1968
+ getPlayerDetails(username: string): Promise<PlayerDetails>;
1977
1969
  /**
1978
1970
  * Fetches a player's current achievements.
1979
1971
  * @returns A list of achievements.
1980
1972
  */
1981
- getPlayerAchievements(player: PlayerResolvable): Promise<ExtendedAchievement[]>;
1973
+ getPlayerAchievements(username: string): Promise<ExtendedAchievement[]>;
1982
1974
  /**
1983
1975
  * Fetches a player's current achievement progress.
1984
1976
  * @returns A list of achievements (completed or otherwise), with their respective relative/absolute progress percentage.
1985
1977
  */
1986
- getPlayerAchievementProgress(player: PlayerResolvable): Promise<AchievementProgress[]>;
1978
+ getPlayerAchievementProgress(username: string): Promise<AchievementProgress[]>;
1987
1979
  /**
1988
1980
  * Fetches all of the player's competition participations.
1989
1981
  * @returns A list of participations, with the respective competition included.
1990
1982
  */
1991
- getPlayerCompetitions(player: PlayerResolvable, filter?: PlayerCompetitionsFilter, pagination?: PaginationOptions): Promise<ParticipationWithCompetition[]>;
1983
+ getPlayerCompetitions(username: string, filter?: PlayerCompetitionsFilter, pagination?: PaginationOptions): Promise<ParticipationWithCompetition[]>;
1992
1984
  /**
1993
1985
  * Fetches all of the player's competition participations' standings.
1994
1986
  * @returns A list of participations, with the respective competition, rank and progress included.
1995
1987
  */
1996
- getPlayerCompetitionStandings(player: PlayerResolvable, filter: PlayerCompetitionsFilter): Promise<ParticipationWithCompetitionAndStandings[]>;
1988
+ getPlayerCompetitionStandings(username: string, filter: PlayerCompetitionsFilter): Promise<ParticipationWithCompetitionAndStandings[]>;
1997
1989
  /**
1998
1990
  * Fetches all of the player's group memberships.
1999
1991
  * @returns A list of memberships, with the respective group included.
2000
1992
  */
2001
- getPlayerGroups(player: PlayerResolvable, pagination?: PaginationOptions): Promise<MembershipWithGroup[]>;
1993
+ getPlayerGroups(username: string, pagination?: PaginationOptions): Promise<MembershipWithGroup[]>;
2002
1994
  /**
2003
1995
  * Fetches a player's gains, for a specific period or time range, as a [metric: data] map.
2004
1996
  * @returns A map of each metric's gained data.
2005
1997
  */
2006
- getPlayerGains(player: PlayerResolvable, options: TimeRangeFilter): Promise<GetPlayerGainsResponse<PlayerDeltasMap>>;
1998
+ getPlayerGains(username: string, options: TimeRangeFilter): Promise<GetPlayerGainsResponse<PlayerDeltasMap>>;
2007
1999
  /**
2008
2000
  * Fetches a player's gains, for a specific period or time range, as an array.
2009
2001
  * @returns An array of each metric's gained data.
2010
2002
  */
2011
- getPlayerGainsAsArray(player: PlayerResolvable, options: TimeRangeFilter): Promise<GetPlayerGainsResponse<PlayerDeltasArray>>;
2003
+ getPlayerGainsAsArray(username: string, options: TimeRangeFilter): Promise<GetPlayerGainsResponse<PlayerDeltasArray>>;
2012
2004
  /**
2013
2005
  * Fetches all of the player's records.
2014
2006
  * @returns A list of records.
2015
2007
  */
2016
- getPlayerRecords(player: PlayerResolvable, options?: PlayerRecordsFilter): Promise<Record[]>;
2008
+ getPlayerRecords(username: string, options?: PlayerRecordsFilter): Promise<Record[]>;
2017
2009
  /**
2018
2010
  * Fetches all of the player's past snapshots.
2019
2011
  * @returns A list of snapshots.
2020
2012
  */
2021
- getPlayerSnapshots(player: PlayerResolvable, options?: TimeRangeFilter): Promise<FormattedSnapshot[]>;
2013
+ getPlayerSnapshots(username: string, options?: TimeRangeFilter, pagination?: PaginationOptions): Promise<FormattedSnapshot[]>;
2022
2014
  /**
2023
2015
  * Fetches all of the player's approved name changes.
2024
2016
  * @returns A list of name changes.
2025
2017
  */
2026
- getPlayerNames(player: PlayerResolvable): Promise<NameChange[]>;
2018
+ getPlayerNames(username: string): Promise<NameChange[]>;
2027
2019
  }
2028
2020
 
2029
2021
  declare class RecordsClient extends BaseAPIClient {
@@ -2145,4 +2137,4 @@ declare class WOMClient {
2145
2137
  constructor(options?: WOMClientOptions);
2146
2138
  }
2147
2139
 
2148
- export { ACTIVITIES, Achievement, AchievementDefinition, AchievementProgress, AchievementTemplate, Activity, ActivityDelta, ActivityValue, AlgorithmCache, AssertPlayerTypeResponse, BOSSES, Bonus, BonusType, Boss, BossDelta, BossMetaConfig, BossValue, CAPPED_MAX_TOTAL_XP, CMLGroupData, COMBAT_SKILLS, COMPETITION_STATUSES, COMPETITION_TYPES, COMPUTED_METRICS, COUNTRY_CODES, ChangeMemberRolePayload, CompetitionDetails, CompetitionListItem, CompetitionStatus, CompetitionStatusProps, CompetitionType, CompetitionTypeProps, CompetitionWithParticipations, CompetitionsSearchFilter, ComputedMetric, ComputedMetricDelta, ComputedMetricValue, Country, CountryDetails, CountryProps, CreateCompetitionPayload, CreateCompetitionResponse, CreateGroupPayload, CreateGroupResponse, DeltaLeaderboardEntry, DeltaLeaderboardFilter, EditCompetitionPayload, EditGroupPayload, EfficiencyAlgorithm, EfficiencyAlgorithmType, EfficiencyAlgorithmTypeUnion, EfficiencyLeaderboardsFilter, EfficiencyMap, ExperienceMap, ExtendedAchievement, F2P_BOSSES, FormattedSnapshot, GROUP_ROLES, GenericCountMessageResponse, GenericMessageResponse, GetGroupGainsFilter, GetPlayerGainsResponse, GroupDetails, GroupHiscoresActivityItem, GroupHiscoresBossItem, GroupHiscoresComputedMetricItem, GroupHiscoresEntry, GroupHiscoresSkillItem, GroupListItem, GroupMemberFragment, GroupRecordsFilter, GroupRole, GroupRoleProps, GroupStatistics, KillcountMap, MAX_LEVEL, MAX_SKILL_EXP, MAX_VIRTUAL_LEVEL, MEMBER_SKILLS, METRICS, MapOf, MeasuredDeltaProgress, MemberInput, MembershipWithGroup, MembershipWithPlayer, Metric, MetricMeasure, MetricProps, MetricType, MigrationDataSource, NameChangeDetails, NameChangeStatus, NameChangesSearchFilter, PERIODS, PLAYER_BUILDS, PLAYER_TYPES, PRIVELEGED_GROUP_ROLES, ParticipationWithCompetition, ParticipationWithCompetitionAndStandings, ParticipationWithPlayer, ParticipationWithPlayerAndProgress, Period, PeriodProps, Player, PlayerBuild, PlayerBuildProps, PlayerCompetitionStandingsFilter, PlayerCompetitionsFilter, PlayerDeltasArray, PlayerDeltasMap, PlayerDetails, PlayerRecordsFilter, PlayerResolvable, PlayerType, PlayerTypeProps, REAL_SKILLS, Record, RecordLeaderboardEntry, RecordLeaderboardFilter, SKILLS, SKILL_EXP_AT_99, Skill, SkillDelta, SkillMetaConfig, SkillValue, Snapshot, SnapshotDataSource, SnapshotFragment, Team, TempleGroupData, TimeRangeFilter, Top5ProgressResult, WOMClient, findCountry, findCountryByCode, findCountryByName, findGroupRole, findMetric, findPeriod, findPlayerBuild, findPlayerType, formatNumber, getCombatLevel, getExpForLevel, getLevel, getMetricMeasure, getMetricName, getMetricRankKey, getMetricValueKey, getMinimumValue, getParentEfficiencyMetric, isActivity, isBoss, isCompetitionStatus, isCompetitionType, isComputedMetric, isCountry, isGroupRole, isMetric, isPeriod, isPlayerBuild, isPlayerType, isSkill, padNumber, parseMetricAbbreviation, parsePeriodExpression, round };
2140
+ export { ACTIVITIES, Achievement, AchievementDefinition, AchievementProgress, AchievementTemplate, Activity, ActivityDelta, ActivityValue, AlgorithmCache, AssertPlayerTypeResponse, BOSSES, Bonus, BonusType, Boss, BossDelta, BossMetaConfig, BossValue, CAPPED_MAX_TOTAL_XP, CMLGroupData, COMBAT_SKILLS, COMPETITION_STATUSES, COMPETITION_TYPES, COMPUTED_METRICS, COUNTRY_CODES, ChangeMemberRolePayload, CompetitionDetails, CompetitionListItem, CompetitionStatus, CompetitionStatusProps, CompetitionType, CompetitionTypeProps, CompetitionWithParticipations, CompetitionsSearchFilter, ComputedMetric, ComputedMetricDelta, ComputedMetricValue, Country, CountryDetails, CountryProps, CreateCompetitionPayload, CreateCompetitionResponse, CreateGroupPayload, CreateGroupResponse, DeltaLeaderboardEntry, DeltaLeaderboardFilter, EditCompetitionPayload, EditGroupPayload, EfficiencyAlgorithm, EfficiencyAlgorithmType, EfficiencyAlgorithmTypeUnion, EfficiencyLeaderboardsFilter, EfficiencyMap, ExperienceMap, ExtendedAchievement, F2P_BOSSES, FormattedSnapshot, GROUP_ROLES, GenericCountMessageResponse, GenericMessageResponse, GetGroupGainsFilter, GetPlayerGainsResponse, GroupDetails, GroupHiscoresActivityItem, GroupHiscoresBossItem, GroupHiscoresComputedMetricItem, GroupHiscoresEntry, GroupHiscoresSkillItem, GroupListItem, GroupMemberFragment, GroupRecordsFilter, GroupRole, GroupRoleProps, GroupStatistics, KillcountMap, MAX_LEVEL, MAX_SKILL_EXP, MAX_VIRTUAL_LEVEL, MEMBER_SKILLS, METRICS, MapOf, MeasuredDeltaProgress, MemberInput, MembershipWithGroup, MembershipWithPlayer, Metric, MetricMeasure, MetricProps, MetricType, MetricValueKey, MigrationDataSource, NameChangeDetails, NameChangeStatus, NameChangesSearchFilter, PERIODS, PLAYER_BUILDS, PLAYER_TYPES, PRIVELEGED_GROUP_ROLES, ParticipationWithCompetition, ParticipationWithCompetitionAndStandings, ParticipationWithPlayer, ParticipationWithPlayerAndProgress, Period, PeriodProps, Player, PlayerBuild, PlayerBuildProps, PlayerCompetitionStandingsFilter, PlayerCompetitionsFilter, PlayerDeltasArray, PlayerDeltasMap, PlayerDetails, PlayerRecordsFilter, PlayerType, PlayerTypeProps, REAL_SKILLS, Record, RecordLeaderboardEntry, RecordLeaderboardFilter, SKILLS, SKILL_EXP_AT_99, Skill, SkillDelta, SkillMetaConfig, SkillValue, Snapshot, SnapshotDataSource, SnapshotFragment, Team, TempleGroupData, TimeRangeFilter, Top5ProgressResult, WOMClient, findCountry, findCountryByCode, findCountryByName, findGroupRole, findMetric, findPeriod, findPlayerBuild, findPlayerType, formatNumber, getCombatLevel, getExpForLevel, getLevel, getMetricMeasure, getMetricName, getMetricRankKey, getMetricValueKey, getMinimumValue, getParentEfficiencyMetric, isActivity, isBoss, isCompetitionStatus, isCompetitionType, isComputedMetric, isCountry, isGroupRole, isMetric, isPeriod, isPlayerBuild, isPlayerType, isSkill, padNumber, parseMetricAbbreviation, parsePeriodExpression, round };
package/dist/index.js CHANGED
@@ -321,110 +321,94 @@ class PlayersClient extends BaseAPIClient {
321
321
  * Updates/tracks a player.
322
322
  * @returns The player's new details, including the latest snapshot.
323
323
  */
324
- updatePlayer(player) {
325
- return this.postRequest(getPlayerURL(player));
324
+ updatePlayer(username) {
325
+ return this.postRequest(`/players/${username}`);
326
326
  }
327
327
  /**
328
328
  * Asserts (and attempts to fix, if necessary) a player's game-mode type.
329
329
  * @returns The updated player, and an indication of whether the type was changed.
330
330
  */
331
- assertPlayerType(player) {
332
- return this.postRequest(`${getPlayerURL(player)}/assert-type`);
333
- }
334
- /**
335
- * Attempts to import a player's snapshot history from CrystalMathLabs.
336
- * @returns The number of snapshots that were imported.
337
- */
338
- importPlayer(player) {
339
- return this.postRequest(`${getPlayerURL(player)}/import-history`);
331
+ assertPlayerType(username) {
332
+ return this.postRequest(`/players/${username}/assert-type`);
340
333
  }
341
334
  /**
342
335
  * Fetches a player's details.
343
336
  * @returns The player's details, including the latest snapshot.
344
337
  */
345
- getPlayerDetails(player) {
346
- return this.getRequest(getPlayerURL(player));
338
+ getPlayerDetails(username) {
339
+ return this.getRequest(`/players/${username}`);
347
340
  }
348
341
  /**
349
342
  * Fetches a player's current achievements.
350
343
  * @returns A list of achievements.
351
344
  */
352
- getPlayerAchievements(player) {
353
- return this.getRequest(`${getPlayerURL(player)}/achievements`);
345
+ getPlayerAchievements(username) {
346
+ return this.getRequest(`/players/${username}/achievements`);
354
347
  }
355
348
  /**
356
349
  * Fetches a player's current achievement progress.
357
350
  * @returns A list of achievements (completed or otherwise), with their respective relative/absolute progress percentage.
358
351
  */
359
- getPlayerAchievementProgress(player) {
360
- return this.getRequest(`${getPlayerURL(player)}/achievements/progress`);
352
+ getPlayerAchievementProgress(username) {
353
+ return this.getRequest(`/players/${username}/achievements/progress`);
361
354
  }
362
355
  /**
363
356
  * Fetches all of the player's competition participations.
364
357
  * @returns A list of participations, with the respective competition included.
365
358
  */
366
- getPlayerCompetitions(player, filter, pagination) {
367
- return this.getRequest(`${getPlayerURL(player)}/competitions`, Object.assign(Object.assign({}, filter), pagination));
359
+ getPlayerCompetitions(username, filter, pagination) {
360
+ return this.getRequest(`/players/${username}/competitions`, Object.assign(Object.assign({}, filter), pagination));
368
361
  }
369
362
  /**
370
363
  * Fetches all of the player's competition participations' standings.
371
364
  * @returns A list of participations, with the respective competition, rank and progress included.
372
365
  */
373
- getPlayerCompetitionStandings(player, filter) {
374
- return this.getRequest(`${getPlayerURL(player)}/competitions/standings`, filter);
366
+ getPlayerCompetitionStandings(username, filter) {
367
+ return this.getRequest(`/players/${username}/competitions/standings`, filter);
375
368
  }
376
369
  /**
377
370
  * Fetches all of the player's group memberships.
378
371
  * @returns A list of memberships, with the respective group included.
379
372
  */
380
- getPlayerGroups(player, pagination) {
381
- return this.getRequest(`${getPlayerURL(player)}/groups`, pagination);
373
+ getPlayerGroups(username, pagination) {
374
+ return this.getRequest(`/players/${username}/groups`, pagination);
382
375
  }
383
376
  /**
384
377
  * Fetches a player's gains, for a specific period or time range, as a [metric: data] map.
385
378
  * @returns A map of each metric's gained data.
386
379
  */
387
- getPlayerGains(player, options) {
388
- return this.getRequest(`${getPlayerURL(player)}/gained`, options);
380
+ getPlayerGains(username, options) {
381
+ return this.getRequest(`/players/${username}/gained`, options);
389
382
  }
390
383
  /**
391
384
  * Fetches a player's gains, for a specific period or time range, as an array.
392
385
  * @returns An array of each metric's gained data.
393
386
  */
394
- getPlayerGainsAsArray(player, options) {
395
- return this.getRequest(`${getPlayerURL(player)}/gained`, Object.assign(Object.assign({}, options), { formatting: 'array' }));
387
+ getPlayerGainsAsArray(username, options) {
388
+ return this.getRequest(`/players/${username}/gained`, Object.assign(Object.assign({}, options), { formatting: 'array' }));
396
389
  }
397
390
  /**
398
391
  * Fetches all of the player's records.
399
392
  * @returns A list of records.
400
393
  */
401
- getPlayerRecords(player, options) {
402
- return this.getRequest(`${getPlayerURL(player)}/records`, options);
394
+ getPlayerRecords(username, options) {
395
+ return this.getRequest(`/players/${username}/records`, options);
403
396
  }
404
397
  /**
405
398
  * Fetches all of the player's past snapshots.
406
399
  * @returns A list of snapshots.
407
400
  */
408
- getPlayerSnapshots(player, options) {
409
- return this.getRequest(`${getPlayerURL(player)}/snapshots`, options);
401
+ getPlayerSnapshots(username, options, pagination) {
402
+ return this.getRequest(`/players/${username}/snapshots`, Object.assign(Object.assign({}, options), pagination));
410
403
  }
411
404
  /**
412
405
  * Fetches all of the player's approved name changes.
413
406
  * @returns A list of name changes.
414
407
  */
415
- getPlayerNames(player) {
416
- return this.getRequest(`${getPlayerURL(player)}/names`);
408
+ getPlayerNames(username) {
409
+ return this.getRequest(`/players/${username}/names`);
417
410
  }
418
411
  }
419
- function getPlayerURL(player) {
420
- if (typeof player === 'string') {
421
- return `/players/${player}`;
422
- }
423
- if (player.id) {
424
- return `/players/id/${player.id}`;
425
- }
426
- return `/players/${player.username}`;
427
- }
428
412
 
429
413
  class RecordsClient extends BaseAPIClient {
430
414
  /**
@@ -1925,8 +1909,18 @@ function isComputedMetric(metric) {
1925
1909
  function getMetricRankKey(metric) {
1926
1910
  return `${metric}Rank`;
1927
1911
  }
1912
+ // Maybe someday I'll be good enough with TS to restrict the return type to the input metric type
1928
1913
  function getMetricValueKey(metric) {
1929
- return `${metric}${lodash.capitalize(MetricProps[metric].measure)}`;
1914
+ if (isSkill(metric)) {
1915
+ return `${metric}Experience`;
1916
+ }
1917
+ if (isBoss(metric)) {
1918
+ return `${metric}Kills`;
1919
+ }
1920
+ if (isActivity(metric)) {
1921
+ return `${metric}Score`;
1922
+ }
1923
+ return `${metric}Value`;
1930
1924
  }
1931
1925
  function getMetricMeasure(metric) {
1932
1926
  return MetricProps[metric].measure;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise-old-man/utils",
3
- "version": "2.0.3",
3
+ "version": "2.0.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,6 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
+ "lint": "eslint . --ext .ts",
11
12
  "prepublish": "npm run build",
12
13
  "prebuild": "cd ../server && npm run prisma:generate",
13
14
  "build": "rm -rf ./dist && npx rollup -c && node prisma-transform.js && tsc dist/index.d.ts"
@@ -17,9 +18,12 @@
17
18
  "license": "ISC",
18
19
  "devDependencies": {
19
20
  "@rollup/plugin-typescript": "^8.3.4",
20
- "@typescript-eslint/eslint-plugin": "^5.34.0",
21
- "@typescript-eslint/parser": "^5.34.0",
22
- "eslint": "^8.22.0",
21
+ "@typescript-eslint/eslint-plugin": "^5.40.1",
22
+ "@typescript-eslint/parser": "^5.40.1",
23
+ "eslint": "^8.26.0",
24
+ "eslint-config-prettier": "^8.5.0",
25
+ "eslint-plugin-prettier": "^4.2.1",
26
+ "prettier": "^2.7.1",
23
27
  "rollup": "^2.78.0",
24
28
  "rollup-plugin-dts": "^4.2.2",
25
29
  "tslib": "^2.4.0",