From dee53a749f58f36dbbb4c83158a797e687063c48 Mon Sep 17 00:00:00 2001 From: Maxim <102874843+maxim-01@users.noreply.github.com> Date: Tue, 28 Nov 2023 21:27:04 +0000 Subject: [PATCH] Fix ESLint violations --- traffic/v2/index.ts | 10 +- traffic/v2/server.ts | 2 +- traffic/v2/traffic.ts | 16 +- web/v2/ban.ts | 2 +- web/v2/event.ts | 4 +- web/v2/player.ts | 328 --------------------------------------- web/v2/player/index.ts | 246 +++++++++++++++++++++++++++++ web/v2/player/patreon.ts | 90 +++++++++++ 8 files changed, 353 insertions(+), 345 deletions(-) delete mode 100644 web/v2/player.ts create mode 100644 web/v2/player/index.ts create mode 100644 web/v2/player/patreon.ts diff --git a/traffic/v2/index.ts b/traffic/v2/index.ts index 567f9ed..1f02d88 100644 --- a/traffic/v2/index.ts +++ b/traffic/v2/index.ts @@ -1,9 +1,9 @@ -import type { APITrafficServerGameName } from "./server"; +import type { APITrafficServerGameName } from './server'; -export * from "./server"; -export * from "./traffic"; +export * from './server'; +export * from './traffic'; -export const APITrafficVersion = "2" as const; +export const APITrafficVersion = '2' as const; export const APITrafficRoutes = { /** @@ -13,7 +13,7 @@ export const APITrafficRoutes = { * @returns APIResponse */ servers() { - return "/public/servers.json" as const; + return '/public/servers.json' as const; }, /** diff --git a/traffic/v2/server.ts b/traffic/v2/server.ts index db15a7a..1d0af95 100644 --- a/traffic/v2/server.ts +++ b/traffic/v2/server.ts @@ -1,7 +1,7 @@ /** * A short name of a game map type. */ -export type APITrafficServerGameName = "ets2" | "promods" | "ats"; +export type APITrafficServerGameName = 'ets2' | 'promods' | 'ats'; /** * Basic information of a TruckersMP server. diff --git a/traffic/v2/traffic.ts b/traffic/v2/traffic.ts index 45a76a3..d14a912 100644 --- a/traffic/v2/traffic.ts +++ b/traffic/v2/traffic.ts @@ -1,14 +1,14 @@ -import type { APITrafficServer } from "./server"; +import type { APITrafficServer } from './server'; /** * The congestion severity of the given location. */ export type APITrafficLocationSeverity = - | "Empty" - | "Low" - | "Moderate" - | "Congested" - | "Heavy"; + | 'Empty' + | 'Low' + | 'Moderate' + | 'Congested' + | 'Heavy'; /** * Information about a traffic location on the map. @@ -54,7 +54,7 @@ export interface APITrafficServerTop { * Basic information of a TruckersMP server. * @see https://truckersmp.com/developers/api#operation/get-servers */ - server?: Omit; + server?: Omit; /** * 8 busiest locations on the map (descending order). @@ -77,7 +77,7 @@ export type APITrafficServerTraffic = * Basic information of a TruckersMP server. * @see https://truckersmp.com/developers/api#operation/get-servers */ - server: Omit; + server: Omit; /** * All locations on the map. diff --git a/web/v2/ban.ts b/web/v2/ban.ts index f1cd1b6..59d7b57 100644 --- a/web/v2/ban.ts +++ b/web/v2/ban.ts @@ -30,7 +30,7 @@ export interface APIPlayerBan { * Name of the admin that banned the user. This field is no longer provided. * @see https://forum.truckersmp.com/index.php?/topic/112993-website-v221-release/#comment-1111277 */ - adminName: "Game Moderator"; + adminName: 'Game Moderator'; /** * @deprecated - v2.21.1.0 diff --git a/web/v2/event.ts b/web/v2/event.ts index cc541c8..c18b806 100644 --- a/web/v2/event.ts +++ b/web/v2/event.ts @@ -61,7 +61,7 @@ export interface APIGameEventType { /** * The event's type key. */ - key: "convoy" | "truck_show" | "truck_show_and_convoy"; + key: 'convoy' | 'truck_show' | 'truck_show_and_convoy'; /** * The event's type name. @@ -305,7 +305,7 @@ export interface APIGameEvent { * The event's required DLCs. * * - Empty array when no DLCs are required; - * - Record when 1 or more DLCs are required, where the key is the Steam app ID and value is the DLC's name. + * - Record when DLCs are required, where the key is the Steam app ID and value is the DLC's name. */ dlcs: Record | []; diff --git a/web/v2/player.ts b/web/v2/player.ts deleted file mode 100644 index 5189fb5..0000000 --- a/web/v2/player.ts +++ /dev/null @@ -1,328 +0,0 @@ -/** - * Information about player's Patreon status. - */ -type APIPlayerPatreon = APIPlayerPatreon.InfoHidden | APIPlayerPatreon.NonPatron | APIPlayerPatreon.Patron; -namespace APIPlayerPatreon { - /** Base interface containing property annotations */ - interface _Base { - /** - * If the user has donated or is currently donating via Patreon. - */ - isPatron: boolean | null; - - /** - * If the user has an active Patreon subscription. - */ - active: boolean | null; - - /** - * HEX code for subscribed tier. - */ - color: string | null; - - /** - * The tier ID of current pledge. - */ - tierId: number | null; - - /** - * Current pledge in cents. - */ - currentPledge: number | null; - - /** - * Lifetime pledge in cents. - */ - lifetimePledge: number | null; - - /** - * Next pledge in cents. - */ - nextPledge: number | null; - - /** - * If user has their Patreon information hidden. - */ - hidden: boolean | null; - } - - /** Properties specific to the `patreon` field when the information is public (not hidden) */ - interface _VisiblePartial { - lifetimePledge: number | null; - hidden: false | null; - } - - /** Properties specific to the `patreon` field when the user is an inactive patron */ - interface _InactivePartial extends _VisiblePartial { - active: false; - color: null; - tierId: null; - currentPledge: null; - nextPledge: null; - } - - /** Properties specific to the `patreon` field when the user is an active patron */ - interface _ActivePartial extends _VisiblePartial { - active: true; - color: string; - tierId: number; - currentPledge: number; - nextPledge: number | null; - } - - /** `patreon` field when the user has their Patreon information hidden */ - export interface InfoHidden extends _Base { - isPatron: false | null; - active: null; - color: null; - tierId: null; - currentPledge: null; - lifetimePledge: null; - nextPledge: null; - hidden: true; - } - - /** `patreon` field when the user is a patron (active or not) */ - export type Patron = _Base & ({ isPatron: true } & (_InactivePartial | _ActivePartial)); - - /** `patreon` field when the user is not a patron (ie. has never donated) */ - export interface NonPatron extends _InactivePartial { isPatron: false }; -} -export { APIPlayerPatreon }; - -export interface APIPlayerPermissions { - /** - * If the user is a TruckersMP staff member. - */ - isStaff: boolean; - - /** - * If the user is part of upper staff within the TruckersMP team. - */ - isUpperStaff: boolean; - - /** - * If the user has Game Moderator permissions. - */ - isGameAdmin: boolean; -} - -/** - * Information about player's membership in a virtual trucking company. - */ -export type APIPlayerCompanyMember = { - /** - * ID of the company the user belongs to or 0 if not in a company. - */ - id: 0; - - /** - * Name of the company the user belongs to or empty if not in a company. - */ - name: ""; - - /** - * Tag of the company the user belongs to or empty if not in a company. - */ - tag: ""; - - /** - * If the user is in a company. - */ - inVTC: false; - - /** - * Company member ID or 0 if not in a company. - */ - memberID: 0; -} | { - /** - * ID of the company the user belongs to or 0 if not in a company. - */ - id: number; - - /** - * Name of the company the user belongs to or empty if not in a company. - */ - name: string; - - /** - * Tag of the company the user belongs to or empty if not in a company. - */ - tag: string; - - /** - * If the user is in a company. - */ - inVTC: true; - - /** - * Company member ID or 0 if not in a company. - */ - memberID: number; -} - -/** - * Entry with brief information of the company the player was previously in. - */ -export interface APIPlayerCompanyHistory { - /** - * ID of the company. - */ - id: number; - - /** - * Name of the company. - */ - name: string; - - /** - * If the company is verified. - */ - verified: boolean; - - /** - * Date and time the user joined the company (UTC). - */ - joinDate: string; - - /** - * Date and time the user left the company (UTC). - */ - leftDate: string; -} - -/** - * Information about a TruckersMP player. - * @see https://truckersmp.com/developers/api#operation/get-player-id - */ -export type APIPlayer = APIPlayer.Player; -namespace APIPlayer { - /** Base interface containing property annotations */ - interface _Base { - /** - * The ID of the requested user. - */ - id: number; - - /** - * The name of the user. - */ - name: string; - - /** - * URL to the avatar used on the website. - */ - avatar: string; - - /** - * URL to the avatar used on the website (32px x 32px). - */ - smallAvatar: string; - - /** - * The date and time the user registered (UTC). - */ - joinDate: string; - - /** - * The SteamID64 of the user. - */ - steamID64: bigint; - - /** - * The SteamID64 of the user. - */ - steamID: string; - - /** - * The Discord account linked to the user or `null` if not linked or private. - */ - discordSnowflake: string | null; - - /** - * If the user's company history is visible. - */ - displayVTCHistory: boolean; - - /** - * The name of the group the user belongs to. - */ - groupName: string; - - /** - * The color of the group. - */ - groupColor: string; - - /** - * The ID of the group the user belongs to. - */ - groupID: number; - - /** - * If the user is currently banned. - */ - banned: boolean; - - /** - * @deprecated - * This field is no longer available and will be returned as `null`. - */ - bannedUntil: null; - - /** - * The number of active bans a user has or `null` if private. - */ - bansCount: number | null; - - /** - * If the user has their bans hidden. - */ - displayBans: boolean; - - /** - * Data of the player's Patreon status. - */ - patreon: APIPlayerPatreon; - - /** - * Permissions that the player has. - */ - permissions: APIPlayerPermissions; - - /** - * Information about player's membership in a virtual trucking company. - */ - vtc: APIPlayerCompanyMember; - - /** - * Entries with brief information of a company the player was in. - * - * If the user does not allow to see their company history, `null` will be returned instead. - */ - vtcHistory: APIPlayerCompanyHistory[] | null; - } - - interface _VTCHistoryHidden extends Pick<_Base, "displayVTCHistory" | "vtcHistory"> { - displayVTCHistory: false; - vtcHistory: null; - } - interface _VTCHistoryPublic extends Pick<_Base, "displayVTCHistory" | "vtcHistory"> { - displayVTCHistory: true; - vtcHistory: APIPlayerCompanyHistory[]; - } - type _VTCHistory = _VTCHistoryHidden | _VTCHistoryPublic; - - interface _BansHidden extends Pick<_Base, "displayBans" | "bansCount"> { - displayBans: false; - bansCount: null; - } - interface _BansPublic extends Pick<_Base, "displayBans" | "bansCount"> { - displayBans: true; - bansCount: number; - } - type _BanData = _BansHidden | _BansPublic; - - export type Player = _Base & _VTCHistory & _BanData; -} diff --git a/web/v2/player/index.ts b/web/v2/player/index.ts new file mode 100644 index 0000000..5d94ea8 --- /dev/null +++ b/web/v2/player/index.ts @@ -0,0 +1,246 @@ +import APIPlayerPatreon from './patreon'; +export { type APIPlayerPatreon }; + +export interface APIPlayerPermissions { + /** + * If the user is a TruckersMP staff member. + */ + isStaff: boolean; + + /** + * If the user is part of upper staff within the TruckersMP team. + */ + isUpperStaff: boolean; + + /** + * If the user has Game Moderator permissions. + */ + isGameAdmin: boolean; +} + +/** + * Information about player's membership in a virtual trucking company. + */ +export type APIPlayerCompanyMember = { + /** + * ID of the company the user belongs to or 0 if not in a company. + */ + id: 0; + + /** + * Name of the company the user belongs to or empty if not in a company. + */ + name: ''; + + /** + * Tag of the company the user belongs to or empty if not in a company. + */ + tag: ''; + + /** + * If the user is in a company. + */ + inVTC: false; + + /** + * Company member ID or 0 if not in a company. + */ + memberID: 0; +} | { + /** + * ID of the company the user belongs to or 0 if not in a company. + */ + id: number; + + /** + * Name of the company the user belongs to or empty if not in a company. + */ + name: string; + + /** + * Tag of the company the user belongs to or empty if not in a company. + */ + tag: string; + + /** + * If the user is in a company. + */ + inVTC: true; + + /** + * Company member ID or 0 if not in a company. + */ + memberID: number; +} + +/** + * Entry with brief information of the company the player was previously in. + */ +export interface APIPlayerCompanyHistory { + /** + * ID of the company. + */ + id: number; + + /** + * Name of the company. + */ + name: string; + + /** + * If the company is verified. + */ + verified: boolean; + + /** + * Date and time the user joined the company (UTC). + */ + joinDate: string; + + /** + * Date and time the user left the company (UTC). + */ + leftDate: string; +} + +/** + * Information about a TruckersMP player. + * @see https://truckersmp.com/developers/api#operation/get-player-id + */ +export type APIPlayer = _Base & _VTCHistory & _BanData; + +// #region APIPlayer + +/** Base interface containing property annotations */ +interface _Base { + /** + * The ID of the requested user. + */ + id: number; + + /** + * The name of the user. + */ + name: string; + + /** + * URL to the avatar used on the website. + */ + avatar: string; + + /** + * URL to the avatar used on the website (32px x 32px). + */ + smallAvatar: string; + + /** + * The date and time the user registered (UTC). + */ + joinDate: string; + + /** + * The SteamID64 of the user. + */ + steamID64: bigint; + + /** + * The SteamID64 of the user. + */ + steamID: string; + + /** + * The Discord account linked to the user or `null` if not linked or private. + */ + discordSnowflake: string | null; + + /** + * If the user's company history is visible. + */ + displayVTCHistory: boolean; + + /** + * The name of the group the user belongs to. + */ + groupName: string; + + /** + * The color of the group. + */ + groupColor: string; + + /** + * The ID of the group the user belongs to. + */ + groupID: number; + + /** + * If the user is currently banned. + */ + banned: boolean; + + /** + * @deprecated + * This field is no longer available and will be returned as `null`. + */ + bannedUntil: null; + + /** + * The number of active bans a user has or `null` if private. + */ + bansCount: number | null; + + /** + * If the user has their bans hidden. + */ + displayBans: boolean; + + /** + * Data of the player's Patreon status. + */ + patreon: APIPlayerPatreon; + + /** + * Permissions that the player has. + */ + permissions: APIPlayerPermissions; + + /** + * Information about player's membership in a virtual trucking company. + */ + vtc: APIPlayerCompanyMember; + + /** + * Entries with brief information of a company the player was in. + * + * If the user does not allow to see their company history, `null` will be returned instead. + */ + vtcHistory: APIPlayerCompanyHistory[] | null; +} + +/** Properties specific to the player resource when VTC information is hidden */ +interface _VTCHistoryHidden extends Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> { + displayVTCHistory: false; + vtcHistory: null; +} + +/** Properties specific to the player resource when VTC information is public */ +interface _VTCHistoryPublic extends Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> { + displayVTCHistory: true; + vtcHistory: APIPlayerCompanyHistory[]; +} +type _VTCHistory = _VTCHistoryHidden | _VTCHistoryPublic; + +/** Properties specific to the player resource when ban information is hidden */ +interface _BansHidden extends Pick<_Base, 'displayBans' | 'bansCount'> { + displayBans: false; + bansCount: null; +} + +/** Properties specific to the player resource when ban information is public */ +interface _BansPublic extends Pick<_Base, 'displayBans' | 'bansCount'> { + displayBans: true; + bansCount: number; +} +type _BanData = _BansHidden | _BansPublic; + +// #endregion APIPlayer diff --git a/web/v2/player/patreon.ts b/web/v2/player/patreon.ts new file mode 100644 index 0000000..2a811e0 --- /dev/null +++ b/web/v2/player/patreon.ts @@ -0,0 +1,90 @@ +/** Base interface containing property annotations */ +interface _Base { + /** + * If the user has donated or is currently donating via Patreon. + */ + isPatron: boolean | null; + + /** + * If the user has an active Patreon subscription. + */ + active: boolean | null; + + /** + * HEX code for subscribed tier. + */ + color: string | null; + + /** + * The tier ID of current pledge. + */ + tierId: number | null; + + /** + * Current pledge in cents. + */ + currentPledge: number | null; + + /** + * Lifetime pledge in cents. + */ + lifetimePledge: number | null; + + /** + * Next pledge in cents. + */ + nextPledge: number | null; + + /** + * If user has their Patreon information hidden. + */ + hidden: boolean | null; +} + +/** Properties specific to the `patreon` field when the information is public (not hidden) */ +interface _VisiblePartial { + lifetimePledge: number | null; + hidden: false | null; +} + +/** Properties specific to the `patreon` field when the user is an inactive patron */ +interface _InactivePartial extends _VisiblePartial { + active: false; + color: null; + tierId: null; + currentPledge: null; + nextPledge: null; +} + +/** Properties specific to the `patreon` field when the user is an active patron */ +interface _ActivePartial extends _VisiblePartial { + active: true; + color: string; + tierId: number; + currentPledge: number; + nextPledge: number | null; +} + +/** `patreon` field when the user has their Patreon information hidden */ +export interface InfoHidden extends _Base { + isPatron: false | null; + active: null; + color: null; + tierId: null; + currentPledge: null; + lifetimePledge: null; + nextPledge: null; + hidden: true; +} + +/** `patreon` field when the user is a patron (active or not) */ +export type Patron = _Base & ({ isPatron: true } & (_InactivePartial | _ActivePartial)); + +/** `patreon` field when the user is not a patron (ie. has never donated) */ +export interface NonPatron extends _InactivePartial { isPatron: false } + +/** + * Information about player's Patreon status. + */ +type APIPlayerPatreon = InfoHidden | NonPatron | Patron; +export default APIPlayerPatreon;