Skip to content

Data Models

The lib/models.js file defines the fundamental data structures used throughout UnderDeckLib. These model classes ensure the consistency and typing of data that flows between the library, the REST API, and WebSocket communication. Understanding these models is essential for effectively interacting with the library and interpreting the data returned by its methods.

Each model class is designed to represent a specific entity in the UnderDeck ecosystem, such as users, PCs, profile styles, and relationship lists. They often include a constructor that accepts a raw data object and maps it to the instance’s properties, facilitating the creation of typed objects from API responses.

Represents a computer registered in the UnderDeck system. This class encapsulates the basic identification information of a machine.

  • Properties:

    • id (string): The unique identifier of the PC.
    • name (string): The name of the PC.
    • mac (string): The MAC address of the PC.
  • Usage Example:

    const pcData = { id: "pc123", name: "My Computer", mac: "00:11:22:33:44:55" };
    const myPc = new Models.PC(pcData);
    console.log(myPc.name); // Output: My Computer

Represents a user on the UnderDeck platform. This is one of the most complex model classes, containing a wide range of information about the user’s profile, status, relationships, and customizations.

  • Properties:

    • id (string): The unique identifier of the user.
    • status (string): The user’s current status (online, offline, etc.).
    • username (string): The username.
    • name (string): The user’s display name.
    • createdDate (string): The account creation date.
    • email (string): The user’s email address.
    • avatar (string): The URL of the user’s avatar.
    • emailVerified (string): Indicates whether the user’s email has been verified.
    • premium (boolean): Indicates whether the user has a premium subscription.
    • premiumLevel (number): The premium subscription level.
    • premiumStartDate (string): Start date of the premium subscription.
    • premiumFinishDate (string): End date of the premium subscription.
    • friends (Friends): An instance of the Friends class that manages the user’s friend list.
    • profileStyle (ProfileStyle): An instance of the ProfileStyle class that defines the visual style of the user’s profile.
    • tags (Tags): An instance of the Tags class that manages the tags associated with the user.
  • Methods:

    • GetAvatar(): Returns the URL of the user’s avatar or null if none exists.
  • Usage Example:

    const userData = {
    id: "user456",
    username: "john.doe",
    name: "John Doe",
    friends: [], // Raw friends array
    profileStyle: {}, // Raw profile style object
    tags: [] // Raw tags array
    };
    const myUser = new Models.User(userData);
    console.log(myUser.username); // Output: john.doe
    console.log(myUser.friends instanceof Models.Friends); // Output: true

Defines the visual customization options for a user’s profile, including themes, nameplates, and backgrounds.

  • Properties:

    • theme (object):
      • uri (string): Theme URI.
      • color (string): Main theme color.
      • background (string): Theme background image.
    • namePlate (string): The nameplate identifier.
    • namePlateColor (string): Nameplate color.
    • namePlateBackground (string): Nameplate background image.
    • isDuplicateNamePlate (string): Indicates if the nameplate is duplicated (internal use).
  • Usage Example:

    const styleData = {
    theme: { uri: "/themes/dark", color: "#000", background: "/bg/dark.png" },
    namePlate: "gold",
    namePlateColor: "#FFD700"
    };
    const profileStyle = new Models.ProfileStyle(styleData);
    console.log(profileStyle.namePlate); // Output: gold

A class that extends Map to manage a user’s friend list. It processes an array of raw friend data and converts them into typed User objects, storing them by user ID.

  • Usage Example:

    const rawFriends = [
    { user: { id: "friend1", username: "alice" }, friends: true, refused: false, blocked: false, RequestId: "req1" },
    { user: { id: "friend2", username: "bob" }, friends: true, refused: false, blocked: false, RequestId: "req2" }
    ];
    const userFriends = new Models.Friends(rawFriends);
    userFriends.forEach(friend => console.log(friend.username)); // Output: alice, bob

A class that extends Map to manage the tags associated with a user. It converts an array of raw tag data into a map where the key is the tag’s key.

  • Usage Example:

    const rawTags = [
    { key: "developer", value: "true" },
    { key: "premium", value: "true" }
    ];
    const userTags = new Models.Tags(rawTags);
    console.log(userTags.get("developer")); // Output: { key: "developer", value: "true" }

A class that extends Map to manage user lists. It is used to group multiple User objects, such as the results of a user search.

  • Usage Example:

    const rawUsers = [
    { id: "user789", username: "charlie" },
    { id: "user012", username: "diana" }
    ];
    const searchResults = new Models.UsersList(rawUsers);
    searchResults.forEach(user => console.log(user.username)); // Output: charlie, diana

A class that extends Map to manage user PC permissions. It stores information about which users have permission to interact with which PCs.

  • Usage Example:

    const rawPermissions = [
    { pcId: "pc123", user: { id: "user456", username: "john.doe" }, permission: "read" }
    ];
    const pcPermissions = new Models.UsersPcPermissionsList(rawPermissions);
    console.log(pcPermissions.get("pc123").user.username); // Output: john.doe

These models provide a solid foundation for data manipulation within UnderDeckLib, ensuring that information is structured and easily accessible in a consistent format.