-
Notifications
You must be signed in to change notification settings - Fork 4
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
V12 #151
base: master
Are you sure you want to change the base?
Conversation
lib/request.ts
Outdated
if (options == null) { | ||
options = {}; | ||
options = {} as BalenaRequestOptions; |
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 should not need to be cast, if options
is actually optional and therefore every property is actually optional then the types should reflect that and not need casting. In fairness though I wouldn't be surprised if it's actually required and this defaulting should be removed
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.
So as part of this commit I just converted to TS, but I agree on removing all such defaulting so that we can get rid of this weird casting.
tsconfig.json
Outdated
@@ -1,7 +1,7 @@ | |||
{ | |||
"compilerOptions": { | |||
"module": "commonjs", | |||
"declaration": false, | |||
"declaration": true, | |||
"outDir": "build", | |||
"noImplicitAny": false, |
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.
If you've converted it all to typescript then you can set this to true
"noImplicitAny": false, | |
"noImplicitAny": true, |
and also remove the checkJs/allowJs below
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.
Going for "strict": true,
instead since it enables this as well.
package.json
Outdated
"lint": "balena-lint -e js -e ts --typescript lib", | ||
"lint-fix": "balena-lint -e js -e ts --typescript --fix lib", |
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.
Is there still any js? If not you can remove the extension args altogether
lib/request.ts
Outdated
return exports.interceptors | ||
.slice() | ||
.reverse() | ||
.reduce(function (promise, { response, responseError }) { | ||
if (response != null || responseError != null) { | ||
return promise.then(response, responseError); | ||
} else { | ||
return promise; | ||
} | ||
}, initialPromise); |
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.
If you're able to simplify this reduce promise chain building usign async/await I would love that
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.
Let me try that as a minor after we gather all the breaking changes.
lib/request.ts
Outdated
return exports.interceptors | ||
.slice() | ||
.reverse() |
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 think it'd be worth thinking about making the exposed interface be addInterceptor: (interceptor: Interceptor) => void
instead of interceptions: Interceptor[]
, that way internally addInterceptor
can do interceptors.unshift(interceptor)
and we can avoid the need to clone/reverse the array for every request and therefore reduce GC pressure
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 like the idea but this would require a breaking change probably in the SDK, and we are doing major releases often enough there lately 🤔
lib/request.ts
Outdated
@@ -328,7 +388,6 @@ export function getRequest({ | |||
* throw error | |||
* ) | |||
*/ | |||
exports.interceptors = interceptors; |
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.
All the docs for inteceptors
are directly above this, I think you'll need to move the docs somewhere else now for it to all format/generate correctly
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.
Had some trouble to get this right but eventually I had to take a shortcut. Hope you are fine with it :)
Fun fact, the doc generation was already broken on master...
lib/request.ts
Outdated
async function refreshToken({ | ||
baseUrl, | ||
}: Pick<BalenaRequestOptions, 'baseUrl'>): Promise<string> { |
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.
There is a question to be asked here as to whether "balena-request" should know about refreshing tokens or whether that should actually be moved into "balena-auth" instead?
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 wasn't part of the discussion when this was added, but I'm guessing that the reason might be that balena-auth doesn't have access to the balena-request instance, but it's the other way around.
And since balena-request atm does refresh the token when before doing a request when the token is old enough, so we will have to think about a way that we don't have a weird circular dependency schema.
lib/progress.ts
Outdated
if (requestAsync == null) { | ||
requestAsync = utils.getRequestAsync(); | ||
} |
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 think it's worth converting all these nullish defaults to es6 defaults instead since we're doing a breaking
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.
Will do.
lib/progress.ts
Outdated
@@ -105,13 +110,13 @@ export function estimate(requestAsync, isBrowser) { | |||
|
|||
const stream = require('stream'); |
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.
Can you go through and make sure all requires like this have an added as typeof import...
- in javascript the require
call itself is typed when possible but in typescript you have to explicitly type it, meaning with the conversion we'll actually have lost typings in some places
Change-type: squash Signed-off-by: Thodoris Greasidis <[email protected]>
Change-type: squash Signed-off-by: Thodoris Greasidis <[email protected]>
Resolves: #96 Change-type: major Signed-off-by: Thodoris Greasidis <[email protected]>
baseUrl
parameterrefreshToken
to true only when the target providedrequest.send
baseUrl
/url
option matches the defaultbaseUrl
option passed to the factory function./user/v1/refresh-token
See: https://www.flowdock.com/app/rulemotion/resin-frontend/threads/XVvB7BhMFMXAXsQNwACFg5seFyQ