Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: @discordjs/structures #8417

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft

Conversation

ckohen
Copy link
Member

@ckohen ckohen commented Aug 3, 2022

Please describe the changes this PR makes and why it should be merged:

Introduces a generic structure implementation for the main lib (and others) to build on.

⚠️ This is currently in a very early proof of concept stage published as a PR to formulate ideas and solidify the intended structure (ha) of the module.

TODO:

  • Application
  • Audit Log
  • Auto Moderation
  • Channel
    • Channels
    • Mixins
      • DM
      • Guild
      • Text
      • Permissions
      • Webhooks
      • Thread
      • ThreadOnly
      • Voice
    • Message
  • Emoji
  • Guild
    • Guild
    • Guild Preview
    • Guild Widget
    • Guild Member
    • Integration
    • Guild Ban
    • Membership Screening Oh wait...this is still undocumented
  • Guild Scheduled Event
  • Guild Template
  • Interactions (Need more thoughts on this)
  • Invite
  • Stage Instance
  • Sticker
    • Sticker
    • Sticker Pack
  • Teams
  • User
    • User
    • Connection
  • Voice
    • Voice State
    • Voice Region
  • Webhook

@vercel
Copy link

vercel bot commented Aug 3, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Jan 14, 2025 3:19am
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Jan 14, 2025 3:19am

@vercel vercel bot temporarily deployed to Preview August 3, 2022 08:56 Inactive
@vercel vercel bot temporarily deployed to Preview August 3, 2022 09:24 Inactive
@iCrawl iCrawl added the blocked label Aug 15, 2022
@github-actions
Copy link

github-actions bot commented Sep 2, 2023

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 81
🟠 Accessibility 87
🟢 Best practices 100
🟠 SEO 58
🔴 PWA 33

Lighthouse ran on https://discord-js-git-fork-ckohen-feat-structures-discordjs.vercel.app/

@ckohen ckohen force-pushed the feat/structures branch 2 times, most recently from e4cc324 to 98b83f1 Compare December 5, 2023 10:15
* The user's id
*/
public get id() {
return this[kData].id as 'id' extends Omitted ? never : APIUser['id'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we'll have to add this return type for each getter

  1. let's add it as the return type, if we can, else keep it as a cast
  2. Let's make a utility type for this (NeverIfOmitted<Omitted, 'id', APIUser['id']>)

Copy link
Member Author

@ckohen ckohen Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely utility type. I wish it didn't have to cast, but [value of thing] is not assignable to never (or undefined). Maybe we can add | never to all the types in Structure[kData] though and then it works? I'll try that, cause it'd make it a lot easier if it were a merged type.

Edit: still doesn't work :( (obviously not with never, but also not with partial)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't there be a get method?

get<Key extends keyof Omit<Data, Omitted>>(property: Key) {
    return this.data[property] as Key extends Omitted ? never : Data[Key];
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not no. One, it's not as nice of an interface for consumers. Two, this doesn't allow us to convert from snake_case to camelCase.

I would love to do it this way, since it's a lot easier to maintain for us, but I think prioritizing the consumer interface is more important here. These base structures are a lot to implement at first, but shouldn't need to be touched super often once implemented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think I got something better than all of this thanks to starting to write the utility type, fd45e9c implements this.

packages/structures/src/users/User.ts Outdated Show resolved Hide resolved
}

public override _patch(data: Partial<APIExtendedInvite>) {
super._patch(data, { template: Invite.DataTemplate });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't Structure class implement DataTemplate static property so that you don't need to pass it in super?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static properties are a bit weird, especially in TS.
TS has no idea what this.constructor is, other than a function. This is technically correct, since this.constructor refers to whatever was constructed, not the current class.

I would love to write this as an abstract static property, but typescript really doesn't do that (yet).
I'm also not sure what the behavior in js would be if it were implemented on the base class and a consumer changed the value in a subclass like Message.DataTemplate = {}, and I'm not inclined to trust that even once I test it

packages/structures/src/invites/Invite.ts Outdated Show resolved Hide resolved
packages/structures/src/invites/Invite.ts Outdated Show resolved Hide resolved
Copy link

codecov bot commented Feb 12, 2024

Codecov Report

Attention: Patch coverage is 30.89431% with 255 lines in your changes missing coverage. Please review.

Project coverage is 37.85%. Comparing base (5f7d335) to head (e5fb7f5).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
packages/structures/src/invites/Invite.ts 0.00% 86 Missing ⚠️
packages/structures/src/users/User.ts 0.00% 71 Missing ⚠️
packages/structures/src/channels/Channel.ts 0.00% 53 Missing ⚠️
packages/structures/src/users/Connection.ts 0.00% 39 Missing ⚠️
packages/structures/src/Mixin.ts 94.44% 5 Missing ⚠️
apps/website/src/util/constants.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8417      +/-   ##
==========================================
- Coverage   38.00%   37.85%   -0.16%     
==========================================
  Files         239      246       +7     
  Lines       14894    15257     +363     
  Branches     1389     1422      +33     
==========================================
+ Hits         5661     5775     +114     
- Misses       9221     9470     +249     
  Partials       12       12              
Flag Coverage Δ
brokers 27.71% <ø> (ø)
builders 80.38% <ø> (ø)
collection 100.00% <ø> (ø)
formatters 99.63% <ø> (ø)
guide 0.58% <ø> (ø)
proxy 64.63% <ø> (ø)
rest 72.87% <30.97%> (-14.47%) ⬇️
util 41.42% <ø> (ø)
utilities 100.00% <ø> (ø)
voice 69.99% <ø> (ø)
website 0.00% <0.00%> (ø)
ws 34.68% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

*
* @privateRemarks Overriden to `true` on `TextChannelMixin`
*/
public iSTextBased() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public iSTextBased() {
public isTextBased() {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Review in Progress
Development

Successfully merging this pull request may close these issues.

5 participants