-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3/4] Improve: Small Cleanup / Tech Debt Reduction Around NexusWebApi…
… / V2 Types. (#2095) * WIP: Documentation for Update Detection * Added: Additional Edge Cases to Update Logic Docs * Added: Extra case of `Archived in the Middle` * Fixed: Indentation for `file_updates` field. * Finalized 'Updating Mods' doc with simplified Implementation requested. * Fixed: Minor Notes from older Research Doc * Fixed: Added Missing 'Updating Mods' mkdocs sidebar item. * [Working WIP] Added: Initial Implementation of Generic Page Caching System used by Mod Pages * Tech Debt Reduction: Add additional V2 GraphQL Types and Correct Sizes of Existing Types * Added: Missing 'UInt32' types in attribute definitions * Improved: Accuracy of documentation for FileId struct. * Added: Method for constructing UidForMod and UidForFile from GraphQL API Results * Rename: ICanGetUid to ICanGetUidForMod * Added: Tests for UidForModTests and UidForFileTests * Removed: Unused Tests.cs file --------- Co-authored-by: halgari <[email protected]>
- Loading branch information
Showing
36 changed files
with
923 additions
and
79 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/Abstractions/NexusMods.Abstractions.Collections/Json/ModSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/Abstractions/NexusMods.Abstractions.NexusModsLibrary/NexusModsFileMetadata.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/Abstractions/NexusMods.Abstractions.NexusWebApi/INexusApiClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/Abstractions/NexusMods.Abstractions.NexusWebApi/NexusModsArchiveMetadata.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
src/Abstractions/NexusMods.Abstractions.NexusWebApi/Types/FileId.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Abstractions/NexusMods.Abstractions.NexusWebApi/Types/V2/FileId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using NexusMods.MnemonicDB.Abstractions; | ||
using NexusMods.MnemonicDB.Abstractions.Attributes; | ||
using NexusMods.MnemonicDB.Abstractions.ElementComparers; | ||
using TransparentValueObjects; | ||
namespace NexusMods.Abstractions.NexusWebApi.Types.V2; | ||
|
||
/// <summary> | ||
/// Unique ID for a mod file associated with a game (<see cref="GameId"/>). | ||
/// Querying mod pages returns items of this type. | ||
/// </summary> | ||
[ValueObject<uint>] // Matches backend. Do not change. | ||
public readonly partial struct FileId : IAugmentWith<DefaultValueAugment>, IAugmentWith<JsonAugment> | ||
{ | ||
/// <inheritdoc/> | ||
public static FileId DefaultValue => From(default(uint)); | ||
} | ||
|
||
/// <summary> | ||
/// File ID attribute, for NexusMods API file IDs. | ||
/// </summary> | ||
public class FileIdAttribute(string ns, string name) : | ||
ScalarAttribute<FileId, uint>(ValueTags.UInt32, ns, name) | ||
{ | ||
/// <inheritdoc /> | ||
protected override uint ToLowLevel(FileId value) => value.Value; | ||
|
||
/// <inheritdoc /> | ||
protected override FileId FromLowLevel(uint value, ValueTags tags, AttributeResolver resolver) => FileId.From(value); | ||
} |
7 changes: 3 additions & 4 deletions
7
....Abstractions.NexusWebApi/Types/GameId.cs → ...stractions.NexusWebApi/Types/V2/GameId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
using TransparentValueObjects; | ||
|
||
namespace NexusMods.Abstractions.NexusWebApi.Types; | ||
namespace NexusMods.Abstractions.NexusWebApi.Types.V2; | ||
|
||
/// <summary> | ||
/// Unique identifier for an individual game hosted on Nexus. | ||
/// </summary> | ||
[ValueObject<int>] | ||
[ValueObject<uint>] // Matches backend. Do not change. | ||
public readonly partial struct GameId : IAugmentWith<DefaultValueAugment> | ||
{ | ||
/// <inheritdoc/> | ||
public static GameId DefaultValue => From(default); | ||
public static GameId DefaultValue => From(default(uint)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/Abstractions/NexusMods.Abstractions.NexusWebApi/Types/V2/Uid/UidForFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
namespace NexusMods.Abstractions.NexusWebApi.Types.V2.Uid; | ||
|
||
/// <summary> | ||
/// This represents a unique ID of an individual file as stored on Nexus Mods. | ||
/// | ||
/// This is a composite key of <see cref="FileId"/> and <see cref="GameId"/>, where | ||
/// the upper 4 bytes represent the <see cref="FileId"/> and the lower 4 bytes represent | ||
/// the <see cref="GameId"/>. | ||
/// | ||
/// This is consistent with how the Nexus Mods backend produces the UID and is not | ||
/// expected to change. | ||
/// </summary> | ||
[StructLayout(LayoutKind.Sequential, Pack = 1)] | ||
public struct UidForFile | ||
{ | ||
/// <summary> | ||
/// Unique identifier for the file, within the specific <see cref="GameId"/>. | ||
/// </summary> | ||
public FileId FileId; | ||
|
||
/// <summary> | ||
/// Unique identifier for the game. | ||
/// </summary> | ||
public GameId GameId; | ||
|
||
/// <summary> | ||
/// Decodes a Nexus Mods API result which contains an 'uid' field into a <see cref="UidForFile"/>. | ||
/// </summary> | ||
/// <param name="uid">The 'uid' field of a GraphQL API query. This should be an 8 byte number represented as a string.</param> | ||
/// <remarks> | ||
/// This throws if <param name="uid"/> is not a valid number. | ||
/// </remarks> | ||
public static UidForFile FromV2Api(string uid) => FromUlong(ulong.Parse(uid)); | ||
|
||
/// <summary> | ||
/// Reinterprets the current <see cref="UidForFile"/> as a single <see cref="ulong"/>. | ||
/// </summary> | ||
public ulong AsUlong => Unsafe.As<UidForFile, ulong>(ref this); | ||
|
||
/// <summary> | ||
/// Reinterprets a given <see cref="ulong"/> into a <see cref="UidForFile"/>. | ||
/// </summary> | ||
public static UidForFile FromUlong(ulong value) => Unsafe.As<ulong, UidForFile>(ref value); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Abstractions/NexusMods.Abstractions.NexusWebApi/Types/V2/Uid/UidForMod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
namespace NexusMods.Abstractions.NexusWebApi.Types.V2.Uid; | ||
|
||
/// <summary> | ||
/// This represents a unique ID of an individual mod page as stored on Nexus Mods. | ||
/// | ||
/// This is a composite key of <see cref="ModId"/> and <see cref="GameId"/>, where | ||
/// the upper 4 bytes represent the <see cref="ModId"/> and the lower 4 bytes represent | ||
/// the <see cref="GameId"/>. Values are stored in little endian byte order. | ||
/// | ||
/// When transferred over the wire via the API, the resulting `ulong` is converted into | ||
/// a string. | ||
/// | ||
/// This is consistent with how the Nexus Mods backend produces the UID and is not | ||
/// expected to change. | ||
/// </summary> | ||
[StructLayout(LayoutKind.Sequential, Pack = 1)] | ||
public struct UidForMod | ||
{ | ||
/// <summary> | ||
/// Unique identifier for the mod, within the specific <see cref="GameId"/>. | ||
/// </summary> | ||
public ModId ModId; | ||
|
||
/// <summary> | ||
/// Unique identifier for the game. | ||
/// </summary> | ||
public GameId GameId; | ||
|
||
/// <summary> | ||
/// Decodes a Nexus Mods API result which contains an 'uid' field into a <see cref="UidForFile"/>. | ||
/// </summary> | ||
/// <param name="uid">The 'uid' field of a GraphQL API query. This should be an 8 byte number represented as a string.</param> | ||
/// <remarks> | ||
/// This throws if <param name="uid"/> is not a valid number. | ||
/// </remarks> | ||
public static UidForMod FromV2Api(string uid) => FromUlong(ulong.Parse(uid)); | ||
|
||
/// <summary> | ||
/// Reinterprets the current <see cref="UidForMod"/> as a single <see cref="ulong"/>. | ||
/// </summary> | ||
public ulong AsUlong => Unsafe.As<UidForMod, ulong>(ref this); | ||
|
||
/// <summary> | ||
/// Reinterprets a given <see cref="ulong"/> into a <see cref="UidForMod"/>. | ||
/// </summary> | ||
public static UidForMod FromUlong(ulong value) => Unsafe.As<ulong, UidForMod>(ref value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/Games/NexusMods.Games.RedEngine/Cyberpunk2077/Emitters/PatternDefinitions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.