-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
TypeScript migration #309
TypeScript migration #309
Conversation
Since we also need them here, they will be deleted from there later.
This version includes type definitions.
Also use consistent names for inserted and fetched models: * ModelT * ModelWithIdT * LazyLoadedModelT
An alias only needs an id during updates if it is not a new one. As long as one item of an alias set is marked as default, the others do not need this attribute.
Currently all its properties except for `bookshelf` have an inferred type of `any`, but that's a start at least. The situation will improve as soon as the Bookshelf models have types.
Consequent usage of this type seems to also have revealed a bug...
Replace deprecated usage of `String.substr`.
- Batch-rename all JS modules: `rename .js .ts src/models/{*,*/*}.js` - Import and add Bookshelf type to each model using global search and replace - Adapt helper function in edition.ts - Update test to refer to the generated JS files in the lib/ directory Tests are passing but the bookshelf models still cause type errors caused by their non-standard inheritance.
https://bookshelfjs.org/api.html#Model-static-forge > A simple helper function to instantiate a new Model without needing new. Using the constructor syntax avoids a few type errors with chained calls.
We currently have
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A valiant effort !
This is going to make the ORM a lot easier to work with, indeed.
I do have a couple of suggestions and queries below:
|
||
/** | ||
* Types for parsed entities, used for imports. | ||
* TODO: Investigate whether these are also useful elsewhere, e.g. for form validation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Investigate whether these are also useful elsewhere, e.g. for form validation
I would say most likely. For example for import userscripts one day:
https://github.com/tr1ten/bookbrainz-userscripts/blob/amazon-import/src/amazon-import.user.js
Co-authored-by: Monkey Do <[email protected]>
Regarding the TS errors that are left:
|
Co-authored-by: Monkey Do <[email protected]>
Co-authored-by: Monkey Do <[email protected]>
I've added
Good catch, changed in 10f9b55. Now the 7 type errors related to the models are gone, only 4+2 remaining which should be solvable by two changes (which I still have to find). |
Four out of the six type errors have been resolved by improving the types for parsed entities, which has resulted in one new type error (in the apparently unused
The new types also revealed an issue where the P.S. I fail to see how these type-only changes suddenly cause one test to fail... |
Nice work ! I looked into the failing test and downloaded the test results file, which gives a bit more details of the expected vs. actual value.
The new column was merged into BB-site master branch only recently. /me opens a PR to fix the test in question |
Type was copied from bookbrainz-utils, where it has been removed.
Finally the first test import of a random OpenLibrary author succeeded!
Ok, I think this is now ready for the final review. Lots of new type definitions, all relevant linter and type errors fixed, and the BBIQ consumer is finally working with these changes. The remaining three type errors all originate from unused code, i.e. the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, the ORM looks a lot cleaner now, and is much more usable when it comes to the importer project ! 🚀
It also paves the way for a future ORM change; having types will undoubtedly prove useful when converting.
Thanks for the hard work
Problem
Our ORM and its utility functions are still mostly plain JavaScript which makes it hard to use its deeply nested methods without having the definitions open side by side with the current code.
I had already started to sprinkle in a few minimal type definitions in #304 but going forward we realized that there are too many variations of how a model's data can look like (missing and additional properties for different usage scenarios) and that my initial naming schema was not sufficient to cover these.
Solution
The changes also include a few TODO items where our code should potentially be refactored to avoid confusing types and/or wrong usage in the future.
(Of course eslint is complaining about these...)
Pending Tasks