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

Implement all data model classes, with methods that wrap the REST api #5

Open
1 task
paperdave opened this issue Jul 8, 2022 · 2 comments · May be fixed by #76
Open
1 task

Implement all data model classes, with methods that wrap the REST api #5

paperdave opened this issue Jul 8, 2022 · 2 comments · May be fixed by #76
Assignees
Milestone

Comments

@paperdave
Copy link
Member

paperdave commented Jul 8, 2022

the structure/"data model" classes are things like Interaction, and all of them primarily function by wrapping a raw data object passed to the constructor then accessor methods for every property, converting sub objects into more rich types & adding methods that wrap the rest api. these structures are mostly immutable.

one system I have to get better typed classes for things such as a partial channel (where you only have a string id), I have a typescript type that casts a class to an empty looking one, where supported properties and methods are available. for example, the PartialUser class does not have banner data but it does have a name and discriminator, and the fetch method will fetch the full user object.

before we go and blindly implement everything under this system, it might be worth a lot to consider a different approach to creating all these rich data models (I now really like that name name, "rich data models"). this might involve a mini library that assists in creating classes that wrap a data object, where each computed property defines a list of dependencies, and then with typescript types we can create an infinite amount of partials in any shape we need, with an interface like PartialModel<User, "id">, where id refers to the raw data, generating a class definition that only shows properties and methods that would be safe to call. under this system and the current one, the actual class object that js runs would always be the same.

I dont have a code example of what the library would look like, but it should be easy to add new properties to models, and hopefully not perform too slowly compared to just writing a plain class (maybe run faster if we allow computed props to be cached, maybe not).

  • decide if we want a different system for defining rich models
  • TODO, insert a checklist of every class we need. and all rest methods.
@paperdave paperdave added this to the Purplet 2.0.0 stable milestone Jul 8, 2022
@paperdave paperdave pinned this issue Jul 9, 2022
@paperdave
Copy link
Member Author

For the record, #7 must be merged before we continue dev on the data models

@paperdave
Copy link
Member Author

While i love the naming of model, it might be better to call it structures as

  • other libs call it that
  • discord api library does that too

unless we wanted to split the utilities for creating structures into a model package, but unsure if that has a lot of true merit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants