Skip to content

Commit

Permalink
Additional general style changes requested in #2
Browse files Browse the repository at this point in the history
- generalised `as const` where applicable
- renamed the base interface for `APIPlayer` to align with `APIPlayerPatreon`
  • Loading branch information
maxim-01 committed Apr 28, 2024
1 parent 5c28f32 commit c3bfceb
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 74 deletions.
82 changes: 41 additions & 41 deletions web/v2/ban.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
/**
* Information about a current player's ban.
* @see https://truckersmp.com/developers/api#operation/get-bans-id
*/
export interface APIPlayerBan {
/**
* The time the ban will expire.
*/
expiration: string | null;

/**
* The time the ban was issued.
*/
timeAdded: string;

/**
* If the ban is still active.
*
* For the user to be banned the `expiration` date has to be passed or `active` has to be false.
*/
active: boolean;

/**
* The reason for the ban.
*/
reason: string;

/**
* @deprecated - v2.21.1.0
* 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';

/**
* @deprecated - v2.21.1.0
* TruckersMP ID for 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
*/
adminID: null;
}
/**
* Information about a current player's ban.
* @see https://truckersmp.com/developers/api#operation/get-bans-id
*/
export interface APIPlayerBan {
/**
* The time the ban will expire.
*/
expiration: string | null;

/**
* The time the ban was issued.
*/
timeAdded: string;

/**
* If the ban is still active.
*
* For the user to be banned the `expiration` date has to be passed or `active` has to be false.
*/
active: boolean;

/**
* The reason for the ban.
*/
reason: string;

/**
* @deprecated - v2.21.1.0
* 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';

/**
* @deprecated - v2.21.1.0
* TruckersMP ID for 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
*/
adminID: null;
}
2 changes: 1 addition & 1 deletion web/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from './rules';
export * from './server';
export * from './version';

export const APIWebVersion = '2';
export const APIWebVersion = '2' as const;

export const APIWebRoutes = {
/**
Expand Down
22 changes: 13 additions & 9 deletions web/v2/player/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ export interface APIPlayerCompanyHistory {
* Information about a TruckersMP player.
* @see https://truckersmp.com/developers/api#operation/get-player-id
*/
export type APIPlayer = _Base & _APIPlayerVTCHistory & _APIPlayerBanData;
export type APIPlayer = _APIPlayerBase & _APIPlayerVTCHistory & _APIPlayerBanData;

// #region APIPlayer

/** Base interface containing property annotations */
interface _Base {
/**
* Base interface containing property annotations
*/
interface _APIPlayerBase {
/**
* The ID of the requested user.
*/
Expand Down Expand Up @@ -217,7 +217,10 @@ interface _Base {
vtcHistory: APIPlayerCompanyHistory[] | null;
}

type _APIPlayerVTCHistory = Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> &
/**
* Specific properties of the player object regarding their VTC history
*/
type _APIPlayerVTCHistory = Pick<_APIPlayerBase, 'displayVTCHistory' | 'vtcHistory'> &
(
| {
displayVTCHistory: false;
Expand All @@ -229,7 +232,10 @@ type _APIPlayerVTCHistory = Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> &
}
);

type _APIPlayerBanData = Pick<_Base, 'displayBans' | 'bansCount'> &
/**
* Specific properties of the player object regarding bans
*/
type _APIPlayerBanData = Pick<_APIPlayerBase, 'displayBans' | 'bansCount'> &
(
| {
displayBans: false;
Expand All @@ -240,5 +246,3 @@ type _APIPlayerBanData = Pick<_Base, 'displayBans' | 'bansCount'> &
bansCount: number;
}
);

// #endregion APIPlayer
64 changes: 41 additions & 23 deletions web/v2/player/patreon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
/** Base interface containing property type annotations and documentation. */
/**
* Information about player's Patreon status.
*/
type APIPlayerPatreon =
| _APIPlayerPatreonPrivate
| _APIPlayerPatreonNonPatron
| _APIPlayerPatreonIsPatron;
export default APIPlayerPatreon;

/**
* Base interface containing property type annotations and documentation.
*/
interface _APIPlayerPatreonBase {
/**
* If the user has donated or is currently donating via Patreon.
Expand Down Expand Up @@ -41,8 +52,10 @@ interface _APIPlayerPatreonBase {
hidden: boolean | null;
}

/** `patreon` field when the user has their Patreon information hidden */
interface _APIPartialPlayerPatreonPrivate extends _APIPlayerPatreonBase {
/**
* `patreon` field when the user has their Patreon information hidden
*/
interface _APIPlayerPatreonPrivate extends _APIPlayerPatreonBase {
isPatron: false | null;
active: null;
color: null;
Expand All @@ -53,45 +66,50 @@ interface _APIPartialPlayerPatreonPrivate extends _APIPlayerPatreonBase {
hidden: true;
}

// #region Properties specific to the `patreon` field when the information is public

/** Base interface for public Patreon information */
/**
* Base interface for public Patreon information
*/
interface _APIPartialPlayerPatreonPublicBase {
lifetimePledge: number | null;
hidden: false | null;
}

/** Properties specific to the `patreon` field when the user is an inactive patron */
interface _APIPartialPlayerPatreonInactive extends _APIPartialPlayerPatreonPublicBase {
/**
* Properties specific to the `patreon` field when the user is an inactive patron
*/
interface _APIPartialPlayerPatreonPublicInactive
extends _APIPartialPlayerPatreonPublicBase {
active: false;
color: null;
tierId: null;
currentPledge: null;
nextPledge: null;
}

/** Properties specific to the `patreon` field when the user is an active patron */
interface _APIPartialPlayerPatreonActive extends _APIPartialPlayerPatreonPublicBase {
/**
* Properties specific to the `patreon` field when the user is an active patron
*/
interface _APIPartialPlayerPatreonPublicActive
extends _APIPartialPlayerPatreonPublicBase {
active: true;
color: string;
tierId: number;
currentPledge: number;
nextPledge: number | null;
}

/** `patreon` field when the user is a current or former patron */
type _APIPlayerPatreonIsPatron =
& _APIPlayerPatreonBase
& { isPatron: true }
& (_APIPartialPlayerPatreonInactive | _APIPartialPlayerPatreonActive);

/** `patreon` field when the user is not a patron (ie. has never donated) */
interface _APIPlayerPatreonNonPatron extends _APIPartialPlayerPatreonInactive { isPatron: false }

// #endregion
/**
* `patreon` field when the user is not a patron (ie. has never donated)
*/
interface _APIPlayerPatreonNonPatron
extends _APIPartialPlayerPatreonPublicInactive {
isPatron: false;
}

/**
* Information about player's Patreon status.
* `patreon` field when the user is a current or former patron
*/
type APIPlayerPatreon = _APIPartialPlayerPatreonPrivate | _APIPlayerPatreonNonPatron | _APIPlayerPatreonIsPatron;
export default APIPlayerPatreon;
type _APIPlayerPatreonIsPatron = _APIPlayerPatreonBase & { isPatron: true } & (
| _APIPartialPlayerPatreonPublicInactive
| _APIPartialPlayerPatreonPublicActive
);

0 comments on commit c3bfceb

Please sign in to comment.