kibana/packages/kbn-ui-shared-deps-npm
Spencer 2e314db2ce
Wrap rison-node to improve types (#146649)
@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 or `undefined` for that value.

To address this I'm adding a wrapper function which accepts `any` and
returns a `string`. If rison-node is totally unable to produce any rison
for the value (because the value is `undefined` or some other type like
Symbol or BigInt) the `encode()` function will throw. If you're
accepting arbitrary input you can use the `encodeUnknown()` 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 the `encode_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.
2022-12-01 08:33:56 -07:00
..
src add kibana.jsonc files to existing packages (#138965) 2022-09-08 13:31:57 -07:00
BUILD.bazel Wrap rison-node to improve types (#146649) 2022-12-01 08:33:56 -07:00
index.d.ts [ts] add stub index.d.ts in @kbn/ui-shared-deps-npm 2022-10-28 19:11:57 -05:00
index.js chore(NA): remove src folder requirement from packages (part 2) (#138476) 2022-08-30 15:57:35 +01:00
kibana.jsonc add kibana.jsonc files to existing packages (#138965) 2022-09-08 13:31:57 -07:00
package.json [auto] migrate existing plugin/package configs 2022-10-28 14:06:46 -05:00
README.mdx docs(NA): adds @kbn/ui-shared-deps-npm into ops devdocs (#132761) 2022-05-25 19:28:40 -07:00
tsconfig.json fix(NA): wrongly spread stripInternal and rootDir configs across packages (#144463) 2022-11-03 01:04:55 +00:00
webpack.config.js Wrap rison-node to improve types (#146649) 2022-12-01 08:33:56 -07:00

---
id: kibDevDocsOpsUiSharedDepsNpm
slug: /kibana-dev-docs/ops/ui-shared-deps-npm
title: "@kbn/ui-shared-deps-npm"
description: A package to share single instances of npm external packages across bundles
date: 2022-05-24
tags: ['kibana', 'dev', 'contributor', 'operations', 'ui', 'shared', 'deps', 'npm']
---

This is a package of shared dependencies that must only have a single instance and are from the NPM external to 
the Kibana repository. To consume them, import the package and merge the `externals` export into your webpack 
externals config so that all references to the supported modules will be remapped to use the global versions.