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 15 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 Ignored Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Mar 13, 2024 0:32am
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Mar 13, 2024 0:32am

@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
@ckohen ckohen force-pushed the feat/structures branch 2 times, most recently from 6a953a7 to 1e9cf03 Compare February 8, 2024 05:55
Copy link

codecov bot commented Feb 12, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (597340f) 58.55% compared to head (c8b1f33) 58.54%.
Report is 5 commits behind head on main.

Files Patch % Lines
apps/website/src/util/constants.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8417      +/-   ##
==========================================
- Coverage   58.55%   58.54%   -0.01%     
==========================================
  Files         244      245       +1     
  Lines       17315    17338      +23     
  Branches     1250     1250              
==========================================
+ Hits        10138    10150      +12     
- Misses       7132     7143      +11     
  Partials       45       45              
Flag Coverage Δ
brokers 63.49% <ø> (ø)
builders 95.56% <ø> (ø)
collection 99.32% <ø> (ø)
formatters 99.31% <ø> (ø)
guide 0.00% <ø> (ø)
next ∅ <ø> (∅)
proxy 75.00% <ø> (ø)
rest 92.58% <ø> (ø)
util 68.86% <ø> (-1.84%) ⬇️
utilities 100.00% <ø> (ø)
voice 63.64% <ø> (ø)
website 0.00% <0.00%> (ø)
ws 52.52% <ø> (+0.08%) ⬆️

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.

None yet

5 participants