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

[#101] add query params for all REST methods #102

Conversation

sewera
Copy link

@sewera sewera commented Dec 7, 2022

Resolves #101.

Brief summary of what I did:

  • make interfaces small and composable
  • fix typos in log messages and comments
  • I will rebuild the project once all the changes are approved

My proposed solution for this issue was to make
a couple of different interfaces describing
the capabilities of different requests.
Please find more ideas in the in-code comments.

- make interfaces small and composable
- fix typos in log messages and comments
Copy link
Author

@sewera sewera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put some additional ideas about the changes I made in the code review comments.

I will run the build task after getting an approval of the changes.

src/Client.ts Show resolved Hide resolved
@@ -32,7 +33,7 @@ export default class AdminService extends CrudService<Admin> {
* If the current `client.authStore.model` matches with the updated id, then
* on success the `client.authStore.model` will be updated with the result.
*/
update<T = Admin>(id: string, bodyParams = {}, queryParams = {}): Promise<T> {
update<T = Admin>(id: string, bodyParams = {}, queryParams: BaseQueryParams = {}): Promise<T> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in other methods with queryParams: BaseQueryParams, I just assumed that all those methods will have only $autoCancel and $cancelKey, because I couldn't find anything more in the documentation.

@@ -11,7 +16,7 @@ export default class LogService extends BaseService {
/**
* Returns paginated logged requests list.
*/
getRequestsList(page = 1, perPage = 30, queryParams = {}): Promise<ListResult<LogRequest>> {
getRequestsList(page = 1, perPage = 30, queryParams: ListLogsQueryParams = {}): Promise<ListResult<LogRequest>> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could argue that GetRequestsListQueryParams is a better name, but I'll leave it to the reviewer.

@@ -52,10 +57,20 @@ export default class LogService extends BaseService {
/**
* Returns request logs statistics.
*/
getRequestsStats(queryParams = {}): Promise<Array<HourlyStats>> {
getRequestsStats(queryParams: LogStatsQueryParams = {}): Promise<Array<HourlyStats>> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in line 19, but with GetRequestStatsQueryParams.

expand?: string;
}

export interface PaginatedQueryParams {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paginable didn't sound right for me, but maybe it's better for consistency, I'll leave it to a reviewer's taste.

@sewera sewera marked this pull request as ready for review December 7, 2022 11:54
@ganigeorgiev
Copy link
Member

@sewera Thank you for working on this. Sometime later this week, after the blocker in pocketbase/pocketbase#1187, I'll review it in more details and will let you know if something need to change.

@ganigeorgiev
Copy link
Member

ganigeorgiev commented Dec 8, 2022

@sewera To avoid the back-and-forth, I've squash merged your changes locally + applied some minor nitpickings:

  • I've decided to move all query param types under services/utils/QueryParam.ts since it is easier to import this way without having to remember where the type was defined (the parameter types list also wouldn't grow significantly so it shouldn't be an issue, at least for now).

  • I've removed the small interfaces because it was starting to become verbose and just by reading the name (eg. PaginatedQueryParams) wasn't clear whether this type was extending the BaseQueryParams or define only a small set of fields. I've merged the parameters in the following types:

    BaseQueryParams
    ListQueryParams (base + page + sort + filter fields)
    RecordQueryParams (base + expand)
    RecordListQueryParams (list + expand)
    LogStatsQueryParams (base + filter)
    FileQueryParams (base + thumb)

You can find the changes in e860e34 (ignore the dist folder) and if you are not ok with them, please leave a review comment and I may reconsider it.
I'm planning a v0.8.4 release sometime this weekend.

@sewera
Copy link
Author

sewera commented Dec 8, 2022

Alright, I'll drop something in if I have anything to add by tomorrow.

@sewera
Copy link
Author

sewera commented Dec 9, 2022

@ganigeorgiev, I've written my comment, you can find it here.

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

Successfully merging this pull request may close these issues.

[Types] Make queryParams strongly-typed
2 participants