-
Notifications
You must be signed in to change notification settings - Fork 119
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
Search param builder #509
Search param builder #509
Conversation
cc/ @pranavkulkarni |
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.
Impressive @patrickarlt! I didn't look too deeply into the code, but at the macro level I like the direction you are headed.
Definitely wise to scope down to SearchQueryBuilder
and IParamBuilder
. The API looks good to me.
I'm cool w/ classes, and am thankful for all the thought you've put into the alternatives. The more "own special hells" we can avoid the better.
I'm especially cool w/ classes if we can move the builders into their own package as I suggest here: #137 (comment)
Finally, I assume the reason you brought withOptions()
and withUrl()
into this is just to that they play nicely w/ the builders, right? In general, I'd like to see those decoupled from the builder, and maybe even defaults (full disclosure, I haven't looked at #508 yet). I mean, it seems like they could be PR'd against master today, right?
This is awesome. I am currently porting some of the existing query building logic opendata-ui to hub.js/search. I could use this SearchQueryBuilder which is very intuitive and will help develop hub.js better. Any idea when this will roll out tentatively? |
our goal is to include this in a if you could symlink pat's branch in the meantime and provide more detailed feedback, that would be really cool. |
@pranavkulkarni I would really want to land this in 2.0.0 next week. @jgravois I'm probably going to be in Redlands sometime next week but I might only have 1-2 meetings do you and maybe @tomwayson want to spend a day on releasing 2.0.0? |
7b6204d
to
c3dd95a
Compare
for. sure. |
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'd say rename it to toParam()
and this is g2g!
it seems like they could be PR'd against master today, right?
it could, but i think we should release with v2.0.0
. its a great 🥕.
Since most people seem ok with the API I went ahead a wrote a pretty full test suite and added a bunch of warnings when people do stupid things like: const query = new SearchQueryBuilder()
.match("test")
.not()
.and()
.toParam(); I would still like to write at least API doc for this. I'll do written doc some time after this merges. I also might replace |
Since this will go into 2.0.0 I'm also going to handle #137 (comment). |
d89be63
to
38b3500
Compare
@jgravois @tomwayson OK I have done some major refactoring of Does the following:
This has 100% test coverage and should be ready to merge. @jgravois feel free to refactor this and change the base to the 2.0.0 branch. |
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'm happy to see searchForm
go bye bye!
@@ -13,7 +13,8 @@ | |||
"dist/**" | |||
], | |||
"dependencies": { | |||
"tslib": "^1.9.3" | |||
"tslib": "^1.9.3", | |||
"@esri/arcgis-rest-request": "^1.19.2" |
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.
should this be a devDependency
?
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'd say yes. fixed in 99300a8
@@ -29,6 +27,7 @@ export interface ISearchResult { | |||
num: number; | |||
nextStart: number; | |||
results: IItem[]; | |||
nextPage?: () => Promise<ISearchResult>; |
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.
This is clever. Should we also include a previousPage()
?
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.
gotta save something for 2.1!
Codecov Report
@@ Coverage Diff @@
## v2.0.0 #509 +/- ##
=======================================
Coverage ? 100%
=======================================
Files ? 93
Lines ? 1317
Branches ? 231
=======================================
Hits ? 1317
Misses ? 0
Partials ? 0
Continue to review full report at Codecov.
|
i just pushed up two more commits with a handful of tweaks to get tests passing on CI and use @patrickarlt's new appendCustomParams method in doing this helped me catch (and fix) a couple more edge cases in the refactored utility method. if @tomwayson is happy, i can rebase this branch on top of v2.0.0 and resolve the conflicts. |
@jgravois your commits LGTM. I'll let you refactor this into 2.0.0. |
After some initial research in #384 (comment) I decided to implement a builder for search queries. Here is some basics of the API:
Instead of trying to implement all sorts of crazy helpers like
andHasTags
andorHasTags
ect... I sent for a simpler approach that matches what the REST API search query thing is. This simply tries to build the string as best as possible and should allow for almost ANY permutation of what can be passed to the search API.In the end there is no way to type option 2 from #384 (comment) without a TON of extra work (it might not even be possible at all) so I went with a class based approach.
I think that eventually we will want both
IParamBuilder
for building a single param andIParamsBuilder
for returning an object with multiple params. This PR limits itself toIParamBuilder
for now and leavesIParamsBuilder
open for things like routing or feature layer/webmap creation later. I think that for building complex JSON objects we could use something like https://medium.com/@bensammons/building-a-fluent-interface-with-typescript-using-generics-in-typescript-3-4d206f00dba5 would be 💯 but I'll play around with it later.This PR is still in draft while:
IParamBuilder
SearchQueryBuilder
SearchQueryBuilder
to be more forgiving of stupid things likenew SearchQueryBuilder().endGroup().and().or().from("foo").and().not("bar")
SearchQueryBuilder
IParamBuilder
SearchQueryBuilder