-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Wrap rison-node to improve types #146649
Wrap rison-node to improve types #146649
Conversation
487b716
to
82a08b9
Compare
82a08b9
to
924c5d2
Compare
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Any counts in public APIs
Async chunks
Page load bundle
Unknown metric groupsAPI count
ESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Pinging @elastic/kibana-operations (Team:Operations) |
Pinging @elastic/apm-ui (Team:APM) |
Pinging @elastic/fleet (Team:Fleet) |
Pinging @elastic/uptime (Team:uptime) |
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.
Visualizations team changes LGTM
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.
Core changes LGTM!
Q: Should we add an Eslint rule to promote @kbn/rison
over rison-node
?
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.
kibana-gis changes LGTM
code review
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.
Fleet changes 🚀
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 from @elastic/security-onboarding-and-lifecycle-mgt team
…147218) Addresses: #140263 This PR was inspired by #146649 and while working on persistent rules table state #145111. ## Summary It includes improvements for url search parameters manipulation functionality. In particular `useGetInitialUrlParamValue` and `useReplaceUrlParams` hooks. The main idea is to isolate the encoding layer ([rison](https://github.com/Nanonid/rison)) as an implementation detail so `useGetInitialUrlParamValue` and `useReplaceUrlParams` consumers can just provide types they wish and the hooks serialize/desirealize the data into appropriate format under the hood. On top of that after `@kbn/rison` was added in #146649 it's possible to use this package directly to encode and decode parameters whenever necessary. The improvements include - store unserialized url parameters state in the redux store - encode and decode data by using functions from `@kbn/rison` directly - let `useReplaceUrlParams` accept an updater object ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
@maximpn brought up the issues caused by the types required by the rison-node package, which attempted to communicate that "encoded values must be primitive values, or recursive arrays/object of primitive values". This isn't actually expressible in TypeScript, which lead to many instances of
rison.encode(value as unknown as RisonValue)
which is useless. Additionally, the rison-node library actually supports any value and will either produce valid rison orundefined
for that value.To address this I'm adding a wrapper function which accepts
any
and returns astring
. If rison-node is totally unable to produce any rison for the value (because the value isundefined
or some other type like Symbol or BigInt) theencode()
function will throw. If you're accepting arbitrary input you can use theencodeUnknown()
function, which will return a string or undefined, if the value you provided has zero rison representation.Like JSON.stringify() any non-circular primitive, object, or array can be encoded with either function. If the values within those objects are not encodable (functions, RegExps, etc) then they will be skipped. Any object/array with the
toJSON()
method will be converted to JSON first, and if the prototype of the object has theencode_rison()
method it will be used to convert he value into rison.The changes in this PR are mostly updating usage of rison-node to use
@kbn/rison
(which is also enforced by eslint). There are also several changes which remove unnecessary casting.