-
Notifications
You must be signed in to change notification settings - Fork 2
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
Code review & reflections #10
Conversation
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.
@ynhhoJ, I made a quick look, added some comments
``` |
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.
missed a blank line
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.
Added
@@ -10,4 +11,4 @@ yarn ts-node ./examples/searchAuthors.ts [author name] [page number] [items limi | |||
|
|||
```powershell | |||
yarn ts-node ./examples/searchBooksBySeries.ts [book name] [page number] [items limit count] |
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.
To run examples, we need to install ts-node
(a dev dependency), so will be great to have a note about that
For example, npm install --include dev
(or yarn
variant, ideally both)
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.
Btw, what about using npm scripts (package.json
scripts section) here instead of full commands?
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.
Yeah, i just added scripts for paginated API and without pagination
@@ -1,3 +1,4 @@ | |||
<!--- --> | |||
### Search book by name | |||
Commands: | |||
```powershell |
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 general comment:
In common case, better to use ```sh
for shell commands since we do not have here any PowerShell specific stuff
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.
Added
@@ -1,3 +1,4 @@ | |||
|
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.
Missed a lock file*, please commit it
package-lock.json
oryarn.lock
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.
Added
{ | ||
"name": "flibusta-api", | ||
"version": "0.2.0", | ||
"main": "index.js", | ||
"main": "index.js" , |
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.
not have a main script here since we have not build artifacts (e.g. js bundle)
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.
Removed main, maybe i will add it back later
@@ -22,6 +23,7 @@ class FlibustaAPI { | |||
this.GetAuthors = new GetAuthors(axiosController); | |||
} | |||
|
|||
// | |||
getBooksByName(name: string, page = 0, limit = 50) { |
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.
I have an API design question (here and below)
Preamble:
With the current design, I as an API user, need to make other API calls if a page is not last.
I'd like to get items (books) with one call.
What about encapsulate that kind of logic into internals?
Pagination is a good thing as an option but should we use it as default? I see, it heavily depends on internal logic but we can make a more friendly interface
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.
Good tip!
Add two different APIs, for paginated result and just raw items.
} | ||
|
||
// NOTE: 584 книг | ||
const [booksItemsCountAsString] = stringMatch; | ||
const booksCountOnlyNumbers = StringUtils.getNumbersFromString(booksItemsCountAsString); | ||
|
||
return parseInt(booksCountOnlyNumbers, 10); | ||
return parseInt(booksCountOnlyNumbers, 10); // |
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.
In other places, we use modular variant: Number.parseInt()
, I guess here we have to do it as well (for consistency reasons)
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.
Thx, added it!
@@ -89,14 +93,14 @@ abstract class FlibustaAPIHelper { | |||
const stringMatch = StringUtils.getStringMatches(booksOrTranslationsAsString, regexRule); | |||
|
|||
if (isNil(stringMatch)) { | |||
return FlibustaAPIHelper.NIL_RESULT; | |||
return FlibustaAPIHelper.NIL_RESULT; // | |||
} | |||
|
|||
// NOTE: 584 книг |
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.
an unnecessary comment
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.
removed!
import AxiosController from './axiosController'; | ||
import { PagesInformation } from '../types/pagesInformation'; | ||
import { HTMLElement, parse, Node } from 'node-html-parser'; | ||
import { isEmpty, isNil, parseInt } from 'lodash'; | ||
import Author from '../types/authors'; | ||
import Book from '../types/book'; | ||
import StringUtils from './utils/string'; | ||
import StringUtils from './utils/string'; // | ||
|
||
abstract class FlibustaAPIHelper { | ||
private static NIL_RESULT = -1; |
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.
Looks like a pure C thing :)
Since we have a strong type-system in TS, I'd like to suggest use Nullable
-like result type
Some reflections -- it is easy to forget to check result value with some magic constant but if it will be a nullable value we have to do that on a type basis
My personal opinion regarding interface design in general: if the type system is strongly typed out of the box we need to use it to protect API users
Another point, any checks with magic constants is a runtime thing but type checking is a compiling (read transpiling) time thing
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.
Implemented nullable type instead of "magic constant", thx
@@ -1,16 +1,18 @@ | |||
// | |||
import AxiosController from './axiosController'; | |||
import { PagesInformation } from '../types/pagesInformation'; |
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 general optional comment regarding this module cohesion
I'd like to suggest taking a look at the page model conception (https://testcafe.io/documentation/402826/guides/concepts/page-model)
It helps reduce dependencies in code by moving page-related things into separate classes.
I see you use the raw HTML parsing approach -- maybe for the next projects, I propose to play around Testcase framework. It can run a browser in headless mode and interact with pages as a user would do
QA automation guys usually use this approach to test any kind of frontends (not only sites, even native desktop applications). Since here we have a classical scraping task, we can use it too
Dude, where are your tests? Your code is weak against unpredictable layout changes. |
Just added tests for Flibusta API. Help is still wanted for 100% coverage or advices how tests should be written. I have small experience on work with it. |
You've made great progress. Thank you for your work. |
A draft PR to be able to add GitHub comments at the current code
Here we go 🚀
PS. NOT FOR MERGE