-
Notifications
You must be signed in to change notification settings - Fork 26
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
Refactor and async/await #87
Conversation
Tests broke when replacing request due to different form handling. Will look into that |
👌I think if we push the current master to a V2 branch, and supply hotfixes via that, we can merge your new work against master each time |
returning the promise is a backwards incompatible change
The "delete this._streams[name]" code not a good idea, because it causes a race condition: If the user calls createAssembly immediately after addFile, it throws correctly as per the test requirement. However if if there is a delay between calling addFile and createAssembly, the 'error' event is emitted after createAssembly can get _streams and _streams will be empty so createAssembly will not throw the expected error
the reduce code was broken and was giving only NaN thus uploadProgress never worked
directly under createAssembly it was a duplicated functionality of the fields inside params
I think it would be cool to release an
Then we'll be able to drive out some early bugs and give more feedback before releasing the final major. |
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.
Great work, Mikael! I couldn't spot anything that stuck out badly. But it's a huge PR and it's already late, so bugs will likely be in there.
Very grateful for this! Agreeing with @kvz on the dogfooding and deployment strategy.
I'm for the declarative API, it's simple and works 👍 Also it's more obvious where state is coming from. Downside: If we adapt our internal api2 test helper to match this api, we need to rewrite a lot of tests. |
I feel for declarative too.
Options:
|
The current imperative API is actually dangerous: const transloadit = ...
for (const item of items) {
transloadit.addFile('foo', 'bar')
transloadit.createAssembly()
} It's dangerous because |
oh that's right, i think someone actually hit that |
I think the culprit is this: node-sdk/src/TransloaditClient.js Line 148 in 9bb622e
You can see that it is being called AFTER remoteJson finishes (which is definitely not in the same tick) However in the new rewrite I think it should be safe to do what you did, because I reset node-sdk/src/TransloaditClient.js Line 182 in f7e52b7
However if we want to keep the imperative API, then I believe we should definitely write a unit test for that corner case of creating multiple assemblies without awaiting between! |
Would be cool if we can get a decision on this fast so I can merge this and release the RC1 so that people can start using and testing it. |
Oh wait, it is not safe with my code either, because I call an await before that. node-sdk/src/TransloaditClient.js Line 168 in f7e52b7
But I can easily pull the this._streams = {} to the top of the function and add a comment that it must be kept on the top
|
Have now fixed the issue and added a test for it, so it should be safe now. An option to not have to rewrite a lot of tests if we want to have a declarative API: |
Best option so far! |
will be provided in legacy api
Have now made the API declarative and created a backward compatible TransloaditClientLegacy So in theory we can now do this in old code: -const TransloaditClient = require('transloadit')
+const TransloaditClient = require('transloadit/src/TransloaditClientLegacy') Should work roughly like the old API. Note that certain things like Errors and retry logic is different. |
This PR is for changes related to #85
Other future improvements moved here: #88 #89
Breaking changes‼️
I have made some changes to make the API more consistent and easy to understand. This is an almost complete rewrite so there may be some unforeseen changes. These are the known breaking changes:
replayAssembly(opts)
changed toreplayAssembly(assemblyId, params)
(previouslyassemblyId
was a key inside opts, but it was not optional, it was required)replayAssemblyNotification(opts)
changed toreplayAssemblyNotification(assemblyId, params)
(previously assemblyId was a key inside opts, but it was not optional, it was required)deleteAssembly
renamed tocancelAssembly
to reflect the official terminologyfields
option (directly undercreateAssembly(opts)
). Please use thefields
key insideparams
instead.createAssembly(options[, onProgress])
to:createAssembly({ onUploadProgress: Function({ uploadedBytes, totalBytes }), onAssemblyProgress: Function(assembly) })
(see readme)waitForCompletion
with the assembly result instead of throwing unknown error if result.ok isASSEMBLY_CANCELED
orREQUEST_ABORTED
Declarative createAssembly
addFile
andaddStream
have been removed and are instead part ofcreateAssembly
:Auto retry logic
assembly_url == null
orassembly_ssl_url == null
. Will instead throw aTransloaditClient.InconsistentResponseError
. (relevant code)Errors
Thrown errors have changed:
When HTTP response code is not successful, the error will now be a
TransloaditClient.HTTPError
object with an additionaltransloaditErrorCode
property (used to be a normalError
object)Error
propertyerror
has been renamed totransloaditErrorCode
Error
propertyassembly_id
has been renamed toassemblyId
Error
object, but can instead be found inHTTPError.response.body
.HTTPError.response?.body
(e.g.catch (err) { err.response.assembly_id }
) - Note thaterr.response
will be undefined for non-server errorsASSEMBLY_REPLAYING
whenwaitForCompletion
assembly.error
) (but HTTP 200) will now result in an error thrown also when callingreplayAssembly
, to make it consistent withcreateAssembly
TransloaditClient.HTTPError
(previously 404 gave a successful result)See also README
All finished changes
request
withgot
this._streams
"node" : ">=10.0.0"
(current version run with tests)node-sdk/src/TransloaditClient.js
Line 647 in 9bb622e
node-sdk/src/TransloaditClient.js
Line 710 in 9bb622e
node-sdk/src/TransloaditClient.js
Line 705 in 9bb622e
debug
module?node-sdk/src/TransloaditClient.js
Line 619 in 9bb622e
5 sec
except createassembly which is24h
RATE_LIMIT_REACHED
(or disable retry)?Async
prefix to all methods (breaking change). If not, usecallbackify
. Depracate callback strategy?createAssembly
with a callback function nownode-sdk/src/TransloaditClient.js
Line 151 in 9bb622e
ok
status? Maybe throw a custom error typeInconsistentResponseError
?node-sdk/src/TransloaditClient.js
Line 13 in 9bb622e
README.md / documentation
Tests
Declarative API
Suggested change of the API (breaking). Example:
With existing API:
With proposed new declarative API:
Advantages of existing API:
for y of arr: transloadit.addFile(x, y)
)Advantages of declarative API:
Cleanup