I have a general question here, but after several days searching, I don't find the information I'm looking for.
I have some development skills (PHP, Javascript, React, HTML, etc) that I've picked up over time and self-taught. But I've reached a point where I lack the logic or skills to achieve what I need.
The backbone of the (music) app i'm working on is JSPF datas, which is a standard JSON format for music playlists. Here is an example of a JSPF dataset on the official website.
I'm looking for information to create some sort of toolkit for manipulating those datasets through my application - whether it's loading it, validating it, manipulating it, cleaning it up before it is saved in the DB, etc.
The idea is to use this toolkit as a module across the entire application (backend and frontend), so it needs to be perfectly designed because the whole app will rely on it - data will, among others, be processed by users; so validation is important.
I would like to create something (a class? a model? an interface ? Is there a name for this concept ?) that allows me to manage this data.
In the case of a playlist, I would need, for example
- methods to manage the tracks (add/remove/empty/reindex...)
- methods to import (fill) or export data in JSON
- methods to validate (for a user form, for example) or clean (before saving in the DB) this data.
a draft of this could be something like
class Playlist = {
//fill the object based on a JSON string
public fromJson(json: string){}
//converts the object to a JSON string
public toJson(): string {}
//compare datas to a schema, check if valid, trace errors...
public validate(schema){}
//clean data (strip what's not good) eg. before storing it in DB
public sanitize(){}
//some methods for tracks
public addTracks(tracks:JSPFTrack[]){}
public removeTracks(tracks:JSPFTrack[]){}
public reindexTracks(tracks:JSPFTrack[],startNum:number){}
public clearTracks(){}
//....
}
I started looking at TypeScript, to, among other things, define strong types, but it's more complicated than I thought. I get a little confused between types, interfaces, classes, and most importantly, I realized that TypeScript is useful at compile time, not at run time.
I looked at the validation side, but there are a ton of recommended modules, like yup, zod - is there one that everybody agrees on ?
I also looked closely at a module that seems intuitive enough for me but is quite new and doesn't seem to be widely used - so I'm hesitant to rely on that even if it seems to fit my needs: Object Model.
What I'm looking for is probably... what many developers do design all the time. I just lack the resources to name those concepts and find good documentation on it.
Is there good ressources, or a clear example/tutorial that explains how to manage a simple dataset from start to finish like I would like to do, so I could improve my understanding on all this ?
Thank you very much!!!
Here is the current state of my TypeScript types designed according to this dataset.
Aucun commentaire:
Enregistrer un commentaire