-
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
Draft: composition and defaults #508
Conversation
gut reactions:
i don't feel strongly, but i'd prefer them flipped.
i'm actually fine with advertising that the new helper methods can't be used by TypeScript developers to wrap
i don't think allowing folks to use you're right that most of our API is already wrappers, but i've seen lots of folks just using
i'm fine with kicking the can down the road on this one. |
@jgravois allowing syntax like: request({
url: "https://"
}) isn't actually a breaking change. What would be a breaking change (at least internally) in that in order to make The breaking change to |
I'm pickin up what you're puttin down. if it's only 17 tests, I can help rejigger the relevant methods. I just don't want to deprecate |
I really like the idea of being able to set defaults. However, I've run into problems using module scoped variables for things like user sessions in server-rendered apps. When there's only one instance of the server running that is handling multiple requests, the request module will be shared across those requests. So if request A sets Module scoped variables work fine in the client, and they work fine on the server for things that can be and probably should be shared between requests, like the way you set Also, rather than |
I think we should follow FP patterns |
It's great that @patrickarlt has spiked through thinking how these related features will interact, but when it comes to actually merging PRs I think it would be good to decouple as much of this as possible. It seems the sticky bit in all this is changing the signature of It seems like @patrickarlt is coming to the conclusion that supporting either a |
Setting up a default As a compromise could we export a function like: export function setDefaultRequestOptions(options, hideWarnings = false) {
if(options.authentication && !hideWarnings){
warn("warn users about the dangers of globally setting authentication and link to doc.")
}
DEFAULT_REQUEST_OPTIONS = options;
}
@tomwayson right now inconsistant method signatures are causing a bit of pain with request(url, options);
queryLayer(query, {
url: "..."
}) It is impossible to make request({
url: "..."
}) Which means we can consistently make the last options be queryLayer(url, {
query: "..."
}) Just makes this problem even MORE difficult since searchItems(searchQuery) In this case the first param could also be a string. You are absolutely right that we are burying the lead to |
I'll flip the method signatures since it seems we prefer: withURL("url", fn);
withOptions({
foo:"bar"
}, fn); and I'll move these into |
I know. Me too. I like your proposal for how we can warn users by default, but still let power users who (at least think they) know what they are doing set it and kill the warnings. |
I'm fine w/ adding
I think @jgravois has tried and didn't find that to be easy. Also, in this particular case, This also raises a question of, how should those fns treat Or do we turn the existing No matter what we decide, I agree that this is more of a docs issue than anything, and that we will be able to find some solution even if it's a matter of always forcing |
d89be63
to
38b3500
Compare
@jgravois This should also be ready for review. I've moved |
@jgravois I also reverts all the changes to |
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.
nice work @patrickarlt!
thanks for taking the time to split out all the utilities in request
into their own files while you were digging around in there.
this branch has been synced and the PR base is now set to v2.0.0
.
disclaimer: withOptions()
now lives inside of request
.
I'm sorry! This is a wrong commit. Please ignore it. |
@tomwayson @dbouwman @jgravois I've been wanted to spend some in REST JS land so I thought I would take a crack at 2 related things:
withUrl()
andwithOptions()
from facilitate composition of our low level functional API to reduce end user friction #339.options
for all requests likeauthentication
.All of this works pretty well. Here is a summary of the changes:
request.ts
into separate files.request
to accept:request(url)
request(url, options)
request(options)
- with aurl
in the options, this is new and needed forwithUrl()
whenwithUrl()
is used withrequest
requestOptions
includingparams
andheaders
are now merged with a globally exposted constantDEFAULT_ARCGIS_REQUEST_OPTIONS
which can accept anyIRequestOptions
and use them as the default options for all requests.rollup-plugin-typescript
which doesn't bundle its own TS version.This PR is still a draft and I need do a few things:
DEFAULT_ARCGIS_REQUEST_OPTIONS
,withUrl()
andwithOptions()
as well as a guide topics for themwithSession
if we decide to add itThere are also still a few things to discuss:
I made the method signatures
withUrl(fn, url)
andwithOptions(fn, options)
since I thought it looked better and it makes the typing a little cleaner. I think this differs from most FP patterns which would normally write these aswithUrl(url, fn)
andwithOptions(options, fn)
. I'm fine with flipping these.Currently
request
does not work withwithUrl()
. This can be fixed but breaks other code and tests. You can see the commitment out fix here. This problem exists becauserequest
has a different method signature then every other method where it accepts theurl
as the first param rather then in the options.There are also issues with
withUrl(request, "the url")
and TypeScript. I cannot figure out how to properly make TypeScript accept thatrequestWithUrl
fromvar requestWithUrl = withUrl(request, "the url")
can be called likerequestWithUrl()
. TypeScript INSISTS on forcingrequestWithUrl("")
There are 3 options:
request
prefer theurl
inoptions
over the actual URL param. This will break a bunch of tests for things likegetAttachments
which just format aurl
and pass as the first param forrequest
. The fix for this is REALLY easy thoughrequest
cannot be properly typed withwithURL()
and document that fact for TypeScript users. JS users can still do this to their hearts content.options
with aurl
in the key. Since most usage of the library is NOTrequest
most of this can be an internal change.Where should these helpers live? If we decide that
withUrl()
shouldn't work withrequest
should it really live in thearcgis-rest-request
package? Or should both of these live inarcgis-rest-request
BECAUSEarcgis-rest-request
is a dependency for every other package?Do we still want to add
withSession
toarcgis-rest-authentication
?