-
Notifications
You must be signed in to change notification settings - Fork 220
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
fix(price-service-sdk): make price-service-sdk portable #2242
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
d46cac4
to
8c0f107
Compare
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.
lgtm! version bump?
The price-service-sdk package previously used `Buffers` in it's interface in many places. However, `Buffer` is a node-specific interface which does not exist in browsers. Many browsers ship [a polyfill](https://github.com/feross/buffer), however I've discovered that the polyfill is not actually fully compatible with the Node module. In particular, while the Node module [supports aliases such as `readUint8` for `readUInt8`](https://nodejs.org/api/buffer.html#bufreaduint8offset) (note the difference in capitalization), [the polyfill does not](https://github.com/feross/buffer/blob/master/index.d.ts). As a result, attempting to utilize `price-service-sdk` in the browser was either going to cause errors because the Buffer sdk isn't present, or it would cause errors because of the use of aliased function names. There were three options to fix this issue: 1. Switch everything to using unaliased function names. This would work portably, but only assuming that the Buffer polyfill is present. 2. Switch everything to using [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), which is a more generic [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) and largely supersedes the need to use the `Buffer` class at all. This would work, however it would be a breaking change. 3. Switch everything to using a generic interface which accepts anything which extends `Uint8Array`. This requires a few gross typescript hacks to type check correctly and avoid anything being a breaking change, but it makes the code the most portable without requiring any major version or any consumer code changes. This commit implements option 3.
8c0f107
to
7727d3c
Compare
thanks @tejasbadadare , I updated the version |
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.
Seems to pass the tests, but it's a bit complicated imo tbh
The price-service-sdk package previously used
Buffers
in it's interface in many places. However,Buffer
is a node-specific interface which does not exist in browsers.Many browsers ship a polyfill, however I've discovered that the polyfill is not actually fully compatible with the Node module. In particular, while the Node module supports aliases such as
readUint8
forreadUInt8
(note the difference in capitalization), the polyfill does not.As a result, attempting to utilize
price-service-sdk
in the browser was either going to cause errors because the Buffer polyfill isn't present, or it would cause errors because of the use of aliased function names.There were three options to fix this issue:
Switch everything to using unaliased function names. This would work portably, but only assuming that the Buffer polyfill is present.
Switch everything to using
Uint8Array
, which is a more generic typed array and largely supersedes the need to use theBuffer
class at all (and which is a superclass ofBuffer
). This would work, however it would be a breaking change.Switch everything to using a generic interface which accepts anything which extends
Uint8Array
(includingBuffer
), and useUint8Array
methods exclusively insideprice-service-sdk
. This requires a few gross typescript hacks to type check correctly and avoid anything being a breaking change, but it makes the code the most portable without requiring any polyfills or requiring a major version bump.This commit implements option 3.