From 2e314db2ce57103b2eb4f051b883cdd8ba9393a3 Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 1 Dec 2022 08:33:56 -0700 Subject: [PATCH] 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. --- .github/CODEOWNERS | 1 + package.json | 1 + packages/BUILD.bazel | 2 + packages/kbn-eslint-config/.eslintrc.js | 4 + packages/kbn-rison/BUILD.bazel | 123 ++++++++++++++++++ packages/kbn-rison/README.md | 3 + packages/kbn-rison/index.ts | 20 +++ packages/kbn-rison/jest.config.js | 13 ++ packages/kbn-rison/kbn_rison.test.ts | 99 ++++++++++++++ packages/kbn-rison/kbn_rison.ts | 59 +++++++++ packages/kbn-rison/kibana.jsonc | 7 + packages/kbn-rison/package.json | 8 ++ packages/kbn-rison/tsconfig.json | 15 +++ packages/kbn-ui-shared-deps-npm/BUILD.bazel | 2 - .../kbn-ui-shared-deps-npm/webpack.config.js | 1 - packages/kbn-ui-shared-deps-src/BUILD.bazel | 3 +- .../kbn-ui-shared-deps-src/src/definitions.js | 2 +- packages/kbn-ui-shared-deps-src/src/entry.js | 2 +- src/dev/bazel/ts_project.bzl | 12 +- .../components/top_nav/open_search_panel.tsx | 2 +- .../state_encoder/encode_decode_state.ts | 10 +- .../state_hash/state_hash.test.ts | 2 +- .../drilldowns/url_drilldown/handlebars.ts | 4 +- .../components/lib/replace_vars.ts | 4 +- .../visualizations/common/locator_location.ts | 2 +- test/functional/page_objects/context_page.ts | 2 +- tsconfig.base.json | 2 + typings/rison_node.d.ts | 28 ---- .../log_categorization/use_discover_links.ts | 2 +- .../aiops/public/hooks/use_url_state.tsx | 2 +- .../links/discover_links/discover_link.tsx | 4 +- .../public/common/hooks/use_url_query.ts | 3 +- .../public/common/navigation/query_utils.ts | 6 +- .../latest_findings_container.test.tsx | 3 +- .../application/common/util/url_state.tsx | 2 +- .../index_data_visualizer.tsx | 2 +- .../index_data_visualizer/locator/locator.ts | 2 +- .../components/agent_logs/agent_logs.tsx | 2 +- .../graph/public/helpers/kql_encoder.ts | 2 +- .../graph/public/helpers/outlink_encoders.ts | 2 +- .../public/state_management/url_templates.ts | 2 +- .../common/alerting/metrics/alert_link.ts | 2 +- .../category_example_message.tsx | 2 +- .../log_entry_rate/page_results_content.tsx | 4 +- .../sections/anomalies/log_entry_example.tsx | 2 +- .../components/helpers/create_tsvb_link.ts | 2 +- .../public/utils/logs_overview_fetchers.ts | 2 +- .../plugins/infra/public/utils/url_state.tsx | 2 +- .../infra/public/utils/use_url_state.ts | 2 +- x-pack/plugins/lens/common/constants.ts | 2 +- .../plugins/maps/common/mvt_request_body.ts | 5 +- .../feature_geometry_filter_form.tsx | 6 +- x-pack/plugins/maps/public/locators.ts | 10 +- .../get_initial_layers_from_url_param.ts | 37 ++++-- .../components/anomalies_table/links_menu.tsx | 2 +- .../components/custom_url_editor/utils.js | 2 +- .../new_job/job_from_lens/route_resolver.ts | 2 +- .../application/util/custom_url_utils.ts | 4 +- .../ml/public/application/util/url_state.tsx | 2 +- .../ml/server/lib/alerts/alerting_service.ts | 2 +- .../configurations/exploratory_view_url.ts | 4 +- .../exploratory_view/configurations/utils.ts | 4 +- .../public/hooks/use_link_props.test.tsx | 2 +- .../packs/scheduled_query_errors_table.tsx | 2 +- .../reporting_api_client.ts | 2 +- .../generate/generate_from_jobparams.ts | 2 +- .../generation_from_jobparams.test.ts | 2 +- .../conditional_links/add_entities_to_kql.ts | 4 +- .../conditional_links/remove_kql_variables.ts | 4 +- .../replace_kql_commas_with_or.ts | 4 +- .../ml/conditional_links/rison_helpers.ts | 6 +- .../utils/global_query_string/helpers.ts | 2 +- .../pages/endpoint_hosts/store/selectors.ts | 2 +- .../view/components/search_bar.tsx | 7 +- .../store/panel_view_and_parameters.ts | 2 +- .../public/resolver/store/ui/selectors.ts | 2 +- .../resolver/test_utilities/url_search.ts | 2 +- .../components/monitor/ml/ml_job_link.tsx | 5 +- .../fix_deprecation_logs/external_links.tsx | 2 +- .../page_objects/infra_logs_page.ts | 4 +- .../services/scenarios.ts | 8 +- yarn.lock | 4 + 82 files changed, 491 insertions(+), 144 deletions(-) create mode 100644 packages/kbn-rison/BUILD.bazel create mode 100644 packages/kbn-rison/README.md create mode 100644 packages/kbn-rison/index.ts create mode 100644 packages/kbn-rison/jest.config.js create mode 100644 packages/kbn-rison/kbn_rison.test.ts create mode 100644 packages/kbn-rison/kbn_rison.ts create mode 100644 packages/kbn-rison/kibana.jsonc create mode 100644 packages/kbn-rison/package.json create mode 100644 packages/kbn-rison/tsconfig.json delete mode 100644 typings/rison_node.d.ts diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b84b2443fc4f8..4b598ff43309d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -966,6 +966,7 @@ packages/kbn-plugin-helpers @elastic/kibana-operations packages/kbn-react-field @elastic/kibana-app-services packages/kbn-repo-source-classifier @elastic/kibana-operations packages/kbn-repo-source-classifier-cli @elastic/kibana-operations +packages/kbn-rison @elastic/kibana-operations packages/kbn-rule-data-utils @elastic/security-detections-response @elastic/actionable-observability @elastic/response-ops packages/kbn-safer-lodash-set @elastic/kibana-security packages/kbn-securitysolution-autocomplete @elastic/security-solution-platform diff --git a/package.json b/package.json index 2740c43750680..882212d45f443 100644 --- a/package.json +++ b/package.json @@ -356,6 +356,7 @@ "@kbn/osquery-io-ts-types": "link:bazel-bin/packages/kbn-osquery-io-ts-types", "@kbn/plugin-discovery": "link:bazel-bin/packages/kbn-plugin-discovery", "@kbn/react-field": "link:bazel-bin/packages/kbn-react-field", + "@kbn/rison": "link:bazel-bin/packages/kbn-rison", "@kbn/rule-data-utils": "link:bazel-bin/packages/kbn-rule-data-utils", "@kbn/safer-lodash-set": "link:bazel-bin/packages/kbn-safer-lodash-set", "@kbn/securitysolution-autocomplete": "link:bazel-bin/packages/kbn-securitysolution-autocomplete", diff --git a/packages/BUILD.bazel b/packages/BUILD.bazel index 8a784cd002045..78e7a74fa0b32 100644 --- a/packages/BUILD.bazel +++ b/packages/BUILD.bazel @@ -276,6 +276,7 @@ filegroup( "//packages/kbn-react-field:build", "//packages/kbn-repo-source-classifier:build", "//packages/kbn-repo-source-classifier-cli:build", + "//packages/kbn-rison:build", "//packages/kbn-rule-data-utils:build", "//packages/kbn-safer-lodash-set:build", "//packages/kbn-securitysolution-autocomplete:build", @@ -640,6 +641,7 @@ filegroup( "//packages/kbn-react-field:build_types", "//packages/kbn-repo-source-classifier:build_types", "//packages/kbn-repo-source-classifier-cli:build_types", + "//packages/kbn-rison:build_types", "//packages/kbn-rule-data-utils:build_types", "//packages/kbn-safer-lodash-set:build_types", "//packages/kbn-securitysolution-autocomplete:build_types", diff --git a/packages/kbn-eslint-config/.eslintrc.js b/packages/kbn-eslint-config/.eslintrc.js index f2b6e93649cdd..f10e5f233efa5 100644 --- a/packages/kbn-eslint-config/.eslintrc.js +++ b/packages/kbn-eslint-config/.eslintrc.js @@ -131,6 +131,10 @@ module.exports = { from: '@elastic/apm-synthtrace', to: '@kbn/apm-synthtrace', }, + { + from: 'rison-node', + to: '@kbn/rison', + }, ], ], diff --git a/packages/kbn-rison/BUILD.bazel b/packages/kbn-rison/BUILD.bazel new file mode 100644 index 0000000000000..948affb52f443 --- /dev/null +++ b/packages/kbn-rison/BUILD.bazel @@ -0,0 +1,123 @@ +load("@npm//@bazel/typescript:index.bzl", "ts_config") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") +load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") + +PKG_DIRNAME = "kbn-rison" +PKG_REQUIRE_NAME = "@kbn/rison" + +SOURCE_FILES = glob( + [ + "**/*.ts", + ], + exclude = [ + "**/*.config.js", + "**/*.mock.*", + "**/*.test.*", + "**/*.stories.*", + "**/__snapshots__/**", + "**/integration_tests/**", + "**/mocks/**", + "**/scripts/**", + "**/storybook/**", + "**/test_fixtures/**", + "**/test_helpers/**", + ], +) + +SRCS = SOURCE_FILES + +filegroup( + name = "srcs", + srcs = SRCS, +) + +NPM_MODULE_EXTRA_FILES = [ + "package.json", +] + +# In this array place runtime dependencies, including other packages and NPM packages +# which must be available for this code to run. +# +# To reference other packages use: +# "//repo/relative/path/to/package" +# eg. "//packages/kbn-utils" +# +# To reference a NPM package use: +# "@npm//name-of-package" +# eg. "@npm//lodash" +RUNTIME_DEPS = [ + "@npm//rison-node", +] + +# In this array place dependencies necessary to build the types, which will include the +# :npm_module_types target of other packages and packages from NPM, including @types/* +# packages. +# +# To reference the types for another package use: +# "//repo/relative/path/to/package:npm_module_types" +# eg. "//packages/kbn-utils:npm_module_types" +# +# References to NPM packages work the same as RUNTIME_DEPS +TYPES_DEPS = [ + "@npm//@types/node", + "@npm//@types/jest", +] + +jsts_transpiler( + name = "target_node", + srcs = SRCS, + build_pkg_name = package_name(), +) + +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = [ + "//:tsconfig.base.json", + "//:tsconfig.bazel.json", + ], +) + +ts_project( + name = "tsc_types", + args = ['--pretty'], + srcs = SRCS, + deps = TYPES_DEPS, + declaration = True, + emit_declaration_only = True, + out_dir = "target_types", + tsconfig = ":tsconfig", +) + +js_library( + name = PKG_DIRNAME, + srcs = NPM_MODULE_EXTRA_FILES, + deps = RUNTIME_DEPS + [":target_node"], + package_name = PKG_REQUIRE_NAME, + visibility = ["//visibility:public"], +) + +js_library( + name = "npm_module_types", + srcs = NPM_MODULE_EXTRA_FILES, + deps = RUNTIME_DEPS + [":target_node", ":tsc_types"], + package_name = PKG_REQUIRE_NAME, + visibility = ["//visibility:public"], +) + +pkg_npm( + name = "npm_module", + deps = [":" + PKG_DIRNAME], +) + +filegroup( + name = "build", + srcs = [":npm_module"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "build_types", + srcs = [":npm_module_types"], + visibility = ["//visibility:public"], +) diff --git a/packages/kbn-rison/README.md b/packages/kbn-rison/README.md new file mode 100644 index 0000000000000..eb1c6d288239d --- /dev/null +++ b/packages/kbn-rison/README.md @@ -0,0 +1,3 @@ +# @kbn/rison + +A simple wrapper around [rison-node](https://github.com/w33ble/rison-node) which gives us types and ensures that values are always encoded to a string. diff --git a/packages/kbn-rison/index.ts b/packages/kbn-rison/index.ts new file mode 100644 index 0000000000000..09ca54aba64cd --- /dev/null +++ b/packages/kbn-rison/index.ts @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export * from './kbn_rison'; + +import { encode, encodeUnknown, decode, encodeArray, decodeArray } from './kbn_rison'; +// maintain compatibility with 'rison-node' and include a default export +// eslint-disable-next-line import/no-default-export +export default { + encode, + encodeUnknown, + decode, + encodeArray, + decodeArray, +}; diff --git a/packages/kbn-rison/jest.config.js b/packages/kbn-rison/jest.config.js new file mode 100644 index 0000000000000..f43b1327c98f2 --- /dev/null +++ b/packages/kbn-rison/jest.config.js @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../..', + roots: ['/packages/kbn-rison'], +}; diff --git a/packages/kbn-rison/kbn_rison.test.ts b/packages/kbn-rison/kbn_rison.test.ts new file mode 100644 index 0000000000000..0a3e49cacf485 --- /dev/null +++ b/packages/kbn-rison/kbn_rison.test.ts @@ -0,0 +1,99 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import * as Rison from './kbn_rison'; + +describe('encoding', () => { + it('encodes basic values', () => { + expect(Rison.encode(false)).toMatchInlineSnapshot(`"!f"`); + expect(Rison.encode(true)).toMatchInlineSnapshot(`"!t"`); + expect(Rison.encode(1)).toMatchInlineSnapshot(`"1"`); + expect(Rison.encode([1])).toMatchInlineSnapshot(`"!(1)"`); + expect(Rison.encode(['1'])).toMatchInlineSnapshot(`"!('1')"`); + expect(Rison.encode([null])).toMatchInlineSnapshot(`"!(!n)"`); + expect(Rison.encode([undefined])).toMatchInlineSnapshot(`"!()"`); + expect(Rison.encode(null)).toMatchInlineSnapshot(`"!n"`); + }); + it('throws if it received undefined', () => { + expect(() => Rison.encode(undefined)).toThrowErrorMatchingInlineSnapshot( + `"unable to encode value into rison, expected a primative value array or object"` + ); + }); + it('encodes a complex object', () => { + expect( + Rison.encode({ + foo: 1, + bar: { + bax: 1, + bar: [ + 'x', + { + a: /foo/, + b: new Date(0), + }, + ], + }, + }) + ).toMatchInlineSnapshot(`"(bar:(bar:!(x,(a:(),b:'1970-01-01T00:00:00.000Z')),bax:1),foo:1)"`); + }); + it('encodes arrays directly as well', () => { + expect(Rison.encodeArray([1, 2, 3])).toMatchInlineSnapshot(`"1,2,3"`); + }); +}); + +describe('decoding', () => { + it('decodes a simple rison string', () => { + expect(Rison.decode('!f')).toMatchInlineSnapshot(`false`); + expect(Rison.decode('!t')).toMatchInlineSnapshot(`true`); + expect(Rison.decode('1')).toMatchInlineSnapshot(`1`); + expect(Rison.decode('!(1)')).toMatchInlineSnapshot(` + Array [ + 1, + ] + `); + expect(Rison.decode("!('1')")).toMatchInlineSnapshot(` + Array [ + "1", + ] + `); + expect(Rison.decode('!(!n)')).toMatchInlineSnapshot(` + Array [ + null, + ] + `); + expect(Rison.decode('!()')).toMatchInlineSnapshot(`Array []`); + expect(Rison.decode('!n')).toMatchInlineSnapshot(`null`); + }); + it('decodes a complex rison string', () => { + expect(Rison.decode(`(bar:(bar:!(x,(a:(),b:'1970-01-01T00:00:00.000Z')),bax:1),foo:1)`)) + .toMatchInlineSnapshot(` + Object { + "bar": Object { + "bar": Array [ + "x", + Object { + "a": Object {}, + "b": "1970-01-01T00:00:00.000Z", + }, + ], + "bax": 1, + }, + "foo": 1, + } + `); + }); + it('decodes an encoded array', () => { + expect(Rison.decodeArray('1,2,3')).toMatchInlineSnapshot(` + Array [ + 1, + 2, + 3, + ] + `); + }); +}); diff --git a/packages/kbn-rison/kbn_rison.ts b/packages/kbn-rison/kbn_rison.ts new file mode 100644 index 0000000000000..4b2fe7958704c --- /dev/null +++ b/packages/kbn-rison/kbn_rison.ts @@ -0,0 +1,59 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +// @ts-expect-error untyped module from npm +// eslint-disable-next-line @kbn/eslint/module_migration +import Rison from 'rison-node'; + +export type RisonValue = + | boolean + | string + | number + | RisonValue[] + | { [key: string]: RisonValue } + | null; + +export function encodeUnknown(obj: any): string | undefined { + return Rison.encode(obj); +} + +/** + * rison-encode a javascript structure + */ +export function encode(obj: any) { + const rison = encodeUnknown(obj); + if (rison === undefined) { + throw new Error( + 'unable to encode value into rison, expected a primative value array or object' + ); + } + return rison; +} + +/** + * parse a rison string into a javascript structure. + */ +export function decode(rison: string): RisonValue { + return Rison.decode(rison); +} + +/** + * rison-encode a javascript array without surrounding parens + */ +export function encodeArray(array: any[]) { + return Rison.encode_array(array); +} + +/** + * parse an a-rison string into a javascript structure. + * + * this simply adds array markup around the string before parsing. + */ +export function decodeArray(rison: string): RisonValue[] { + return Rison.decode_array(rison); +} diff --git a/packages/kbn-rison/kibana.jsonc b/packages/kbn-rison/kibana.jsonc new file mode 100644 index 0000000000000..e2543dbebbc1b --- /dev/null +++ b/packages/kbn-rison/kibana.jsonc @@ -0,0 +1,7 @@ +{ + "type": "shared-common", + "id": "@kbn/rison", + "owner": "@elastic/kibana-operations", + "runtimeDeps": [], + "typeDeps": [], +} diff --git a/packages/kbn-rison/package.json b/packages/kbn-rison/package.json new file mode 100644 index 0000000000000..692d31de22435 --- /dev/null +++ b/packages/kbn-rison/package.json @@ -0,0 +1,8 @@ +{ + "name": "@kbn/rison", + "private": true, + "version": "1.0.0", + "main": "./target_node/index.js", + "types": "./target_types/index.d.ts", + "license": "SSPL-1.0 OR Elastic License 2.0" +} diff --git a/packages/kbn-rison/tsconfig.json b/packages/kbn-rison/tsconfig.json new file mode 100644 index 0000000000000..292157c18591a --- /dev/null +++ b/packages/kbn-rison/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../tsconfig.bazel.json", + "compilerOptions": { + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "target_types", + "types": [ + "jest", + "node" + ] + }, + "include": [ + "**/*.ts", + ] +} diff --git a/packages/kbn-ui-shared-deps-npm/BUILD.bazel b/packages/kbn-ui-shared-deps-npm/BUILD.bazel index fe0e97913fa49..3bb1873156be4 100644 --- a/packages/kbn-ui-shared-deps-npm/BUILD.bazel +++ b/packages/kbn-ui-shared-deps-npm/BUILD.bazel @@ -62,7 +62,6 @@ RUNTIME_DEPS = [ "@npm//react-router-dom", "@npm//react-router", "@npm//react", - "@npm//rison-node", "@npm//rxjs", "@npm//styled-components", "@npm//symbol-observable", @@ -98,7 +97,6 @@ TYPES_DEPS = [ "@npm//react-is", "@npm//react-router", "@npm//react-router-dom", - "@npm//rison-node", "@npm//rxjs", "@npm//styled-components", "@npm//symbol-observable", diff --git a/packages/kbn-ui-shared-deps-npm/webpack.config.js b/packages/kbn-ui-shared-deps-npm/webpack.config.js index 68396a15e371d..791af0ebe1885 100644 --- a/packages/kbn-ui-shared-deps-npm/webpack.config.js +++ b/packages/kbn-ui-shared-deps-npm/webpack.config.js @@ -100,7 +100,6 @@ module.exports = (_, argv) => { 'react-router-dom', 'react-router', 'react', - 'rison-node', 'rxjs', 'rxjs/operators', 'styled-components', diff --git a/packages/kbn-ui-shared-deps-src/BUILD.bazel b/packages/kbn-ui-shared-deps-src/BUILD.bazel index 91d64b9159be9..4dc31e5a51a6d 100644 --- a/packages/kbn-ui-shared-deps-src/BUILD.bazel +++ b/packages/kbn-ui-shared-deps-src/BUILD.bazel @@ -51,6 +51,7 @@ RUNTIME_DEPS = [ "//packages/kbn-ui-shared-deps-npm", "//packages/kbn-ui-theme", "//packages/kbn-peggy-loader", + "//packages/kbn-rison", ] TYPES_DEPS = [ @@ -107,7 +108,7 @@ webpack( "$(location webpack.config.js)", "--output-path", "$(@D)", - "--no-stats" + "--stats=errors-only" ], ) diff --git a/packages/kbn-ui-shared-deps-src/src/definitions.js b/packages/kbn-ui-shared-deps-src/src/definitions.js index 96826b0616761..d975a39e76a3b 100644 --- a/packages/kbn-ui-shared-deps-src/src/definitions.js +++ b/packages/kbn-ui-shared-deps-src/src/definitions.js @@ -77,7 +77,7 @@ const externals = { '@kbn/es-query': '__kbnSharedDeps__.KbnEsQuery', '@kbn/std': '__kbnSharedDeps__.KbnStd', '@kbn/safer-lodash-set': '__kbnSharedDeps__.SaferLodashSet', - 'rison-node': '__kbnSharedDeps__.RisonNode', + '@kbn/rison': '__kbnSharedDeps__.KbnRison', history: '__kbnSharedDeps__.History', classnames: '__kbnSharedDeps__.Classnames', '@tanstack/react-query': '__kbnSharedDeps__.ReactQuery', diff --git a/packages/kbn-ui-shared-deps-src/src/entry.js b/packages/kbn-ui-shared-deps-src/src/entry.js index c7c8f5e95342e..146efce495eaf 100644 --- a/packages/kbn-ui-shared-deps-src/src/entry.js +++ b/packages/kbn-ui-shared-deps-src/src/entry.js @@ -57,7 +57,7 @@ export const KbnAnalytics = require('@kbn/analytics'); export const KbnEsQuery = require('@kbn/es-query'); export const KbnStd = require('@kbn/std'); export const SaferLodashSet = require('@kbn/safer-lodash-set'); -export const RisonNode = require('rison-node'); +export const KbnRison = require('@kbn/rison'); export const History = require('history'); export const Classnames = require('classnames'); export const ReactQuery = require('@tanstack/react-query'); diff --git a/src/dev/bazel/ts_project.bzl b/src/dev/bazel/ts_project.bzl index afd28fa513164..5c4009d46fd19 100644 --- a/src/dev/bazel/ts_project.bzl +++ b/src/dev/bazel/ts_project.bzl @@ -2,7 +2,13 @@ load("@npm//@bazel/typescript:index.bzl", _ts_project = "ts_project") -def ts_project(validate = False, **kwargs): +def contains(list, item): + for i in list: + if i == item: + return True + return False + +def ts_project(validate = False, deps = [], **kwargs): """A macro around the upstream ts_project rule. Args: @@ -10,7 +16,11 @@ def ts_project(validate = False, **kwargs): **kwargs: the rest """ + if contains(deps, "@npm//tslib") == False: + deps = deps + ["@npm//tslib"] + _ts_project( validate = validate, + deps = deps, **kwargs ) diff --git a/src/plugins/discover/public/application/main/components/top_nav/open_search_panel.tsx b/src/plugins/discover/public/application/main/components/top_nav/open_search_panel.tsx index 81572cf1ebb53..665ed87323188 100644 --- a/src/plugins/discover/public/application/main/components/top_nav/open_search_panel.tsx +++ b/src/plugins/discover/public/application/main/components/top_nav/open_search_panel.tsx @@ -7,7 +7,7 @@ */ import React from 'react'; -import rison from 'rison-node'; +import rison from '@kbn/rison'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { diff --git a/src/plugins/kibana_utils/public/state_management/state_encoder/encode_decode_state.ts b/src/plugins/kibana_utils/public/state_management/state_encoder/encode_decode_state.ts index 3fa11164fad28..952463b2b7b37 100644 --- a/src/plugins/kibana_utils/public/state_management/state_encoder/encode_decode_state.ts +++ b/src/plugins/kibana_utils/public/state_management/state_encoder/encode_decode_state.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import rison, { RisonValue } from 'rison-node'; +import rison from '@kbn/rison'; import { isStateHash, retrieveState, persistState } from '../state_hash'; // should be: @@ -22,14 +22,14 @@ export function decodeState(expandedOrHashedState: string): State { } // should be: -// export function encodeState(expandedOrHashedState: string) -// but this leads to the chain of types mismatches up to BaseStateContainer interfaces, -// as in state containers we don't have any restrictions on state shape +// export function encodeState but this leads to the chain of +// types mismatches up to BaseStateContainer interfaces, as in state containers we don't +// have any restrictions on state shape export function encodeState(state: State, useHash: boolean): string { if (useHash) { return persistState(state); } else { - return rison.encode(state as unknown as RisonValue); + return rison.encodeUnknown(state) ?? ''; } } diff --git a/src/plugins/kibana_utils/public/state_management/state_hash/state_hash.test.ts b/src/plugins/kibana_utils/public/state_management/state_hash/state_hash.test.ts index b1b6bc3c8107d..cd850c25b71c3 100644 --- a/src/plugins/kibana_utils/public/state_management/state_hash/state_hash.test.ts +++ b/src/plugins/kibana_utils/public/state_management/state_hash/state_hash.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { encode as encodeRison } from 'rison-node'; +import { encode as encodeRison } from '@kbn/rison'; import { mockStorage } from '../../storage/hashed_item_store/mock'; import { createStateHash, isStateHash } from './state_hash'; diff --git a/src/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/handlebars.ts b/src/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/handlebars.ts index 9dbeb270a9d72..14e1832c48afb 100644 --- a/src/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/handlebars.ts +++ b/src/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/handlebars.ts @@ -7,7 +7,7 @@ */ import Handlebars from '@kbn/handlebars'; -import { encode, RisonValue } from 'rison-node'; +import { encode } from '@kbn/rison'; import dateMath from '@kbn/datemath'; import moment, { Moment } from 'moment'; import numeral from '@elastic/numeral'; @@ -44,7 +44,7 @@ function createSerializationHelper( handlebars.registerHelper('json', createSerializationHelper('json', JSON.stringify)); handlebars.registerHelper( 'rison', - createSerializationHelper('rison', (v) => encode(v as RisonValue)) + createSerializationHelper('rison', (v) => encode(v)) ); handlebars.registerHelper('date', (...args) => { diff --git a/src/plugins/vis_types/timeseries/public/application/components/lib/replace_vars.ts b/src/plugins/vis_types/timeseries/public/application/components/lib/replace_vars.ts index d3a63f9f2421d..77ac817d53d28 100644 --- a/src/plugins/vis_types/timeseries/public/application/components/lib/replace_vars.ts +++ b/src/plugins/vis_types/timeseries/public/application/components/lib/replace_vars.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { encode, RisonValue } from 'rison-node'; +import { encode } from '@kbn/rison'; import Handlebars, { ExtendedCompileOptions, compileFnName } from '@kbn/handlebars'; import { i18n } from '@kbn/i18n'; import { emptyLabel } from '../../../../common/empty_label'; @@ -41,7 +41,7 @@ function createSerializationHelper( handlebars.registerHelper( 'rison', - createSerializationHelper('rison', (v) => encode(v as RisonValue)) + createSerializationHelper('rison', (v) => encode(v)) ); handlebars.registerHelper('encodeURIComponent', (component: unknown) => { diff --git a/src/plugins/visualizations/common/locator_location.ts b/src/plugins/visualizations/common/locator_location.ts index c4c86007fd124..e43fc9fcbd5e5 100644 --- a/src/plugins/visualizations/common/locator_location.ts +++ b/src/plugins/visualizations/common/locator_location.ts @@ -10,7 +10,7 @@ import type { Serializable } from '@kbn/utility-types'; import { omitBy } from 'lodash'; import type { ParsedQuery } from 'query-string'; import { stringify } from 'query-string'; -import rison from 'rison-node'; +import rison from '@kbn/rison'; import { isFilterPinned } from '@kbn/es-query'; import { url } from '@kbn/kibana-utils-plugin/common'; import { GLOBAL_STATE_STORAGE_KEY, STATE_STORAGE_KEY, VisualizeConstants } from './constants'; diff --git a/test/functional/page_objects/context_page.ts b/test/functional/page_objects/context_page.ts index 05ea89cb65b3d..2bb3d7fb84a2a 100644 --- a/test/functional/page_objects/context_page.ts +++ b/test/functional/page_objects/context_page.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import rison from 'rison-node'; +import rison from '@kbn/rison'; import { getUrl } from '@kbn/test'; import { FtrService } from '../ftr_provider_context'; diff --git a/tsconfig.base.json b/tsconfig.base.json index 230b433f2578f..787992f6e2133 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -540,6 +540,8 @@ "@kbn/repo-source-classifier/*": ["packages/kbn-repo-source-classifier/*"], "@kbn/repo-source-classifier-cli": ["packages/kbn-repo-source-classifier-cli"], "@kbn/repo-source-classifier-cli/*": ["packages/kbn-repo-source-classifier-cli/*"], + "@kbn/rison": ["packages/kbn-rison"], + "@kbn/rison/*": ["packages/kbn-rison/*"], "@kbn/rule-data-utils": ["packages/kbn-rule-data-utils"], "@kbn/rule-data-utils/*": ["packages/kbn-rule-data-utils/*"], "@kbn/safer-lodash-set": ["packages/kbn-safer-lodash-set"], diff --git a/typings/rison_node.d.ts b/typings/rison_node.d.ts deleted file mode 100644 index dacb2524907be..0000000000000 --- a/typings/rison_node.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -declare module 'rison-node' { - export type RisonValue = undefined | null | boolean | number | string | RisonObject | RisonArray; - - // eslint-disable-next-line @typescript-eslint/no-empty-interface - export interface RisonArray extends Array {} - - export interface RisonObject { - [key: string]: RisonValue; - } - - export const decode: (input: string) => RisonValue; - - // eslint-disable-next-line @typescript-eslint/naming-convention - export const decode_object: (input: string) => RisonObject; - - export const encode: (input: Input) => string; - - // eslint-disable-next-line @typescript-eslint/naming-convention - export const encode_object: (input: Input) => string; -} diff --git a/x-pack/plugins/aiops/public/components/log_categorization/use_discover_links.ts b/x-pack/plugins/aiops/public/components/log_categorization/use_discover_links.ts index 8a1c438199878..a56d5c0cdfc6e 100644 --- a/x-pack/plugins/aiops/public/components/log_categorization/use_discover_links.ts +++ b/x-pack/plugins/aiops/public/components/log_categorization/use_discover_links.ts @@ -5,7 +5,7 @@ * 2.0. */ -import rison from 'rison-node'; +import rison from '@kbn/rison'; import moment from 'moment'; import type { TimeRangeBounds } from '@kbn/data-plugin/common'; diff --git a/x-pack/plugins/aiops/public/hooks/use_url_state.tsx b/x-pack/plugins/aiops/public/hooks/use_url_state.tsx index c4d84163f887e..94273a204f5cc 100644 --- a/x-pack/plugins/aiops/public/hooks/use_url_state.tsx +++ b/x-pack/plugins/aiops/public/hooks/use_url_state.tsx @@ -8,7 +8,7 @@ import React, { FC } from 'react'; import { parse, stringify } from 'query-string'; import { createContext, useCallback, useContext, useMemo } from 'react'; -import { decode, encode } from 'rison-node'; +import { decode, encode } from '@kbn/rison'; import { useHistory, useLocation } from 'react-router-dom'; import { isEqual } from 'lodash'; diff --git a/x-pack/plugins/apm/public/components/shared/links/discover_links/discover_link.tsx b/x-pack/plugins/apm/public/components/shared/links/discover_links/discover_link.tsx index e052688d73474..1455e53730a78 100644 --- a/x-pack/plugins/apm/public/components/shared/links/discover_links/discover_link.tsx +++ b/x-pack/plugins/apm/public/components/shared/links/discover_links/discover_link.tsx @@ -10,7 +10,7 @@ import { Location } from 'history'; import { IBasePath } from '@kbn/core/public'; import React from 'react'; import { useLocation } from 'react-router-dom'; -import rison, { RisonValue } from 'rison-node'; +import rison from '@kbn/rison'; import url from 'url'; import { APM_STATIC_DATA_VIEW_ID } from '../../../../../common/data_view_constants'; import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context'; @@ -53,7 +53,7 @@ export const getDiscoverHref = ({ const href = url.format({ pathname: basePath.prepend('/app/discover'), hash: `/?_g=${rison.encode(risonQuery._g)}&_a=${rison.encode( - risonQuery._a as RisonValue + risonQuery._a )}`, }); return href; diff --git a/x-pack/plugins/cloud_security_posture/public/common/hooks/use_url_query.ts b/x-pack/plugins/cloud_security_posture/public/common/hooks/use_url_query.ts index 0573d77e6f9c8..8bc6ff96b4c4f 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/hooks/use_url_query.ts +++ b/x-pack/plugins/cloud_security_posture/public/common/hooks/use_url_query.ts @@ -6,7 +6,6 @@ */ import { useEffect, useCallback, useMemo } from 'react'; import { useHistory, useLocation } from 'react-router-dom'; -import type { RisonObject } from 'rison-node'; import { decodeQuery, encodeQuery } from '../navigation/query_utils'; /** @@ -35,7 +34,7 @@ export const useUrlQuery = (getDefaultQuery: () => T) => { useEffect(() => { if (search) return; - replace({ search: encodeQuery(getDefaultQuery() as RisonObject) }); + replace({ search: encodeQuery(getDefaultQuery()) }); }, [getDefaultQuery, search, replace]); return { diff --git a/x-pack/plugins/cloud_security_posture/public/common/navigation/query_utils.ts b/x-pack/plugins/cloud_security_posture/public/common/navigation/query_utils.ts index 601ad3097b7a8..3a051456733a6 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/navigation/query_utils.ts +++ b/x-pack/plugins/cloud_security_posture/public/common/navigation/query_utils.ts @@ -4,10 +4,10 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { encode, decode, type RisonObject } from 'rison-node'; +import { encode, decode } from '@kbn/rison'; import type { LocationDescriptorObject } from 'history'; -const encodeRison = (v: RisonObject): string | undefined => { +const encodeRison = (v: any): string | undefined => { try { return encode(v); } catch (e) { @@ -27,7 +27,7 @@ const decodeRison = (query: string): T | undefined => { const QUERY_PARAM_KEY = 'cspq'; -export const encodeQuery = (query: RisonObject): LocationDescriptorObject['search'] => { +export const encodeQuery = (query: any): LocationDescriptorObject['search'] => { const risonQuery = encodeRison(query); if (!risonQuery) return; return `${QUERY_PARAM_KEY}=${risonQuery}`; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/findings/latest_findings/latest_findings_container.test.tsx b/x-pack/plugins/cloud_security_posture/public/pages/findings/latest_findings/latest_findings_container.test.tsx index 2d709433e7fc5..3c6b51f881989 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/findings/latest_findings/latest_findings_container.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/findings/latest_findings/latest_findings_container.test.tsx @@ -16,7 +16,6 @@ import { TestProvider } from '../../../test/test_provider'; import { getFindingsQuery } from './use_latest_findings'; import { encodeQuery } from '../../../common/navigation/query_utils'; import { useLocation } from 'react-router-dom'; -import { RisonObject } from 'rison-node'; import { buildEsQuery } from '@kbn/es-query'; import { getPaginationQuery } from '../utils/utils'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; @@ -52,7 +51,7 @@ describe('', () => { }); (useLocation as jest.Mock).mockReturnValue({ - search: encodeQuery(query as unknown as RisonObject), + search: encodeQuery(query), }); render( diff --git a/x-pack/plugins/data_visualizer/public/application/common/util/url_state.tsx b/x-pack/plugins/data_visualizer/public/application/common/util/url_state.tsx index 355793881ca1f..24f9be6639900 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/util/url_state.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/util/url_state.tsx @@ -7,7 +7,7 @@ import { parse } from 'query-string'; import { createContext, useCallback, useContext, useMemo } from 'react'; -import { decode } from 'rison-node'; +import { decode } from '@kbn/rison'; export interface Dictionary { [id: string]: TValue; diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/index_data_visualizer.tsx b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/index_data_visualizer.tsx index 719986b7ae2ea..d3b390b92c313 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/index_data_visualizer.tsx +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/index_data_visualizer.tsx @@ -9,7 +9,7 @@ import React, { FC, useCallback, useEffect, useState } from 'react'; import { useHistory, useLocation } from 'react-router-dom'; import { parse, stringify } from 'query-string'; import { isEqual } from 'lodash'; -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import { SimpleSavedObject } from '@kbn/core/public'; import { i18n } from '@kbn/i18n'; import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/locator/locator.ts b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/locator/locator.ts index a08a468bab656..0d1b90aa0a124 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/locator/locator.ts +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/locator/locator.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import { stringify } from 'query-string'; import { SerializableRecord } from '@kbn/utility-types'; import { Filter, TimeRange } from '@kbn/es-query'; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_logs/agent_logs.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_logs/agent_logs.tsx index c49d1b36cd5a2..12bf5627cc429 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_logs/agent_logs.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_logs/agent_logs.tsx @@ -10,7 +10,7 @@ import { stringify } from 'querystring'; import React, { memo, useMemo, useState, useCallback, useEffect } from 'react'; import styled from 'styled-components'; -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import { EuiFlexGroup, EuiFlexItem, diff --git a/x-pack/plugins/graph/public/helpers/kql_encoder.ts b/x-pack/plugins/graph/public/helpers/kql_encoder.ts index 55ac25debe047..25ac6b9c4280d 100644 --- a/x-pack/plugins/graph/public/helpers/kql_encoder.ts +++ b/x-pack/plugins/graph/public/helpers/kql_encoder.ts @@ -5,7 +5,7 @@ * 2.0. */ -import rison from 'rison-node'; +import rison from '@kbn/rison'; import { Workspace } from '../types'; diff --git a/x-pack/plugins/graph/public/helpers/outlink_encoders.ts b/x-pack/plugins/graph/public/helpers/outlink_encoders.ts index 46415a71457d8..6e72fb4dfa9f3 100644 --- a/x-pack/plugins/graph/public/helpers/outlink_encoders.ts +++ b/x-pack/plugins/graph/public/helpers/outlink_encoders.ts @@ -5,7 +5,7 @@ * 2.0. */ -import rison from 'rison-node'; +import rison from '@kbn/rison'; import { i18n } from '@kbn/i18n'; import { Workspace } from '../types'; diff --git a/x-pack/plugins/graph/public/state_management/url_templates.ts b/x-pack/plugins/graph/public/state_management/url_templates.ts index 678b418c36fae..bd390f75025bd 100644 --- a/x-pack/plugins/graph/public/state_management/url_templates.ts +++ b/x-pack/plugins/graph/public/state_management/url_templates.ts @@ -9,7 +9,7 @@ import actionCreatorFactory from 'typescript-fsa'; import { reducerWithInitialState } from 'typescript-fsa-reducers/dist'; import { i18n } from '@kbn/i18n'; import { modifyUrl } from '@kbn/std'; -import rison from 'rison-node'; +import rison from '@kbn/rison'; import { takeEvery } from 'redux-saga/effects'; import { format, parse } from 'url'; import { GraphState, GraphStoreDependencies } from './store'; diff --git a/x-pack/plugins/infra/common/alerting/metrics/alert_link.ts b/x-pack/plugins/infra/common/alerting/metrics/alert_link.ts index a531911b7746b..2f80f158ef3a2 100644 --- a/x-pack/plugins/infra/common/alerting/metrics/alert_link.ts +++ b/x-pack/plugins/infra/common/alerting/metrics/alert_link.ts @@ -6,7 +6,7 @@ */ import { ALERT_RULE_PARAMETERS, TIMESTAMP } from '@kbn/rule-data-utils'; -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import { stringify } from 'query-string'; import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common/parse_technical_fields'; diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/sections/top_categories/category_example_message.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/sections/top_categories/category_example_message.tsx index 091cbb1ba07b7..254c3730388db 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/sections/top_categories/category_example_message.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/sections/top_categories/category_example_message.tsx @@ -7,7 +7,7 @@ import React, { useState, useCallback } from 'react'; import { i18n } from '@kbn/i18n'; -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import moment from 'moment'; import { useUiTracker, useLinkProps } from '@kbn/observability-plugin/public'; diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx index fc87ba8cd3cb9..399e5563780e1 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx @@ -10,7 +10,7 @@ import type { Query } from '@kbn/es-query'; import moment from 'moment'; import { stringify } from 'query-string'; import React, { useCallback, useMemo } from 'react'; -import { encode, RisonValue } from 'rison-node'; +import { encode } from '@kbn/rison'; import { useKibana } from '@kbn/kibana-react-plugin/public'; import { MLJobsAwaitingNodeWarning } from '@kbn/ml-plugin/public'; import { useTrackPageview } from '@kbn/observability-plugin/public'; @@ -112,7 +112,7 @@ export const LogEntryRateResultsContent: React.FunctionComponent<{ const params = { logPosition: encode({ end: moment(timeRange.value.endTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'), - position: timeKey as RisonValue, + position: timeKey, start: moment(timeRange.value.startTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'), streamLive: false, }), diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/log_entry_example.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/log_entry_example.tsx index 0e15a51f02d35..71eb32f1e69f2 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/log_entry_example.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/log_entry_example.tsx @@ -7,7 +7,7 @@ import React, { useMemo, useCallback, useState } from 'react'; import moment from 'moment'; -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import { i18n } from '@kbn/i18n'; import { useMlHref, ML_PAGES } from '@kbn/ml-plugin/public'; import { euiStyled } from '@kbn/kibana-react-plugin/common'; diff --git a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.ts b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.ts index a4e5cc4b92791..30d521392d584 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.ts +++ b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import uuid from 'uuid'; import { set } from '@kbn/safer-lodash-set'; import { LinkDescriptor } from '@kbn/observability-plugin/public'; diff --git a/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts b/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts index 3ca7540e52bc1..825a070ed15dc 100644 --- a/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts +++ b/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts @@ -6,7 +6,7 @@ */ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import { FetchData, FetchDataParams, diff --git a/x-pack/plugins/infra/public/utils/url_state.tsx b/x-pack/plugins/infra/public/utils/url_state.tsx index c45b47074f8ca..e793ade8ff5ae 100644 --- a/x-pack/plugins/infra/public/utils/url_state.tsx +++ b/x-pack/plugins/infra/public/utils/url_state.tsx @@ -9,7 +9,7 @@ import { parse, stringify } from 'query-string'; import { History, Location } from 'history'; import React from 'react'; import { Route, RouteProps } from 'react-router-dom'; -import { decode, encode, RisonValue } from 'rison-node'; +import { decode, encode, RisonValue } from '@kbn/rison'; import { url } from '@kbn/kibana-utils-plugin/public'; import { throttle } from 'lodash'; diff --git a/x-pack/plugins/infra/public/utils/use_url_state.ts b/x-pack/plugins/infra/public/utils/use_url_state.ts index 309bdd3106f89..1718d7b89245a 100644 --- a/x-pack/plugins/infra/public/utils/use_url_state.ts +++ b/x-pack/plugins/infra/public/utils/use_url_state.ts @@ -8,7 +8,7 @@ import { parse, stringify } from 'query-string'; import { Location } from 'history'; import { useCallback, useEffect, useMemo, useState } from 'react'; -import { decode, encode, RisonValue } from 'rison-node'; +import { decode, encode, RisonValue } from '@kbn/rison'; import { useHistory } from 'react-router-dom'; import { url } from '@kbn/kibana-utils-plugin/public'; diff --git a/x-pack/plugins/lens/common/constants.ts b/x-pack/plugins/lens/common/constants.ts index 1e3d51a6941c8..329b1cb7d182b 100644 --- a/x-pack/plugins/lens/common/constants.ts +++ b/x-pack/plugins/lens/common/constants.ts @@ -5,7 +5,7 @@ * 2.0. */ -import rison from 'rison-node'; +import rison from '@kbn/rison'; import type { TimeRange } from '@kbn/data-plugin/common/query'; export const PLUGIN_ID = 'lens'; diff --git a/x-pack/plugins/maps/common/mvt_request_body.ts b/x-pack/plugins/maps/common/mvt_request_body.ts index 137ea761f0104..dbf719d685c46 100644 --- a/x-pack/plugins/maps/common/mvt_request_body.ts +++ b/x-pack/plugins/maps/common/mvt_request_body.ts @@ -5,8 +5,7 @@ * 2.0. */ -import type { RisonValue } from 'rison-node'; -import rison from 'rison-node'; +import rison from '@kbn/rison'; import { RENDER_AS } from './constants'; export function decodeMvtResponseBody(encodedRequestBody: string): object { @@ -18,7 +17,7 @@ export function encodeMvtResponseBody(unencodedRequestBody: object): string { // encodeURIComponent does not encode '%' // This causes preexisting '%' to break decoding because they are not valid URL encoding // To prevent this, properly url encode '%' before calling encodeURIComponent - return encodeURIComponent(rison.encode(unencodedRequestBody as RisonValue).replace('%', '%25')); + return encodeURIComponent(rison.encode(unencodedRequestBody).replace('%', '%25')); } export function getAggsTileRequest({ diff --git a/x-pack/plugins/maps/public/connected_components/mb_map/tooltip_control/features_tooltip/feature_geometry_filter_form.tsx b/x-pack/plugins/maps/public/connected_components/mb_map/tooltip_control/features_tooltip/feature_geometry_filter_form.tsx index b9691c8a650a8..85e33edcdef37 100644 --- a/x-pack/plugins/maps/public/connected_components/mb_map/tooltip_control/features_tooltip/feature_geometry_filter_form.tsx +++ b/x-pack/plugins/maps/public/connected_components/mb_map/tooltip_control/features_tooltip/feature_geometry_filter_form.tsx @@ -11,7 +11,7 @@ import { i18n } from '@kbn/i18n'; import { Filter } from '@kbn/es-query'; import { ActionExecutionContext, Action } from '@kbn/ui-actions-plugin/public'; import { MultiPolygon, Polygon } from 'geojson'; -import rison, { RisonObject } from 'rison-node'; +import rison from '@kbn/rison'; import { URL_MAX_LENGTH } from '@kbn/core/public'; import { ACTION_GLOBAL_APPLY_FILTER } from '@kbn/unified-search-plugin/public'; import { buildGeoShapeFilter, PreIndexedShape } from '../../../../../common/elasticsearch_util'; @@ -99,9 +99,7 @@ export class FeatureGeometryFilterForm extends Component { // Ensure filter will not overflow URL. Filters that contain geometry can be extremely large. // No elasticsearch support for pre-indexed shapes and geo_point spatial queries. if ( - window.location.href.length + - rison.encode(filter as unknown as RisonObject).length + - META_OVERHEAD > + window.location.href.length + rison.encode(filter).length + META_OVERHEAD > URL_MAX_LENGTH ) { this.setState({ diff --git a/x-pack/plugins/maps/public/locators.ts b/x-pack/plugins/maps/public/locators.ts index c4d7bb6f3d6bb..ff2ac6590708e 100644 --- a/x-pack/plugins/maps/public/locators.ts +++ b/x-pack/plugins/maps/public/locators.ts @@ -7,7 +7,7 @@ /* eslint-disable max-classes-per-file */ -import rison from 'rison-node'; +import rison from '@kbn/rison'; import type { DataViewSpec } from '@kbn/data-views-plugin/public'; import type { SerializableRecord } from '@kbn/utility-types'; import { type Filter, isFilterPinned, type TimeRange, type Query } from '@kbn/es-query'; @@ -97,13 +97,7 @@ export class MapsAppLocatorDefinition implements LocatorDefinition string; - } - ).encode_array(initialLayers); + const risonEncodedInitialLayers = rison.encodeArray(initialLayers); path = `${path}&${INITIAL_LAYERS_KEY}=${encodeURIComponent(risonEncodedInitialLayers)}`; } diff --git a/x-pack/plugins/maps/public/routes/map_page/saved_map/get_initial_layers_from_url_param.ts b/x-pack/plugins/maps/public/routes/map_page/saved_map/get_initial_layers_from_url_param.ts index 4dc4cbccb2f94..127d7fdc42621 100644 --- a/x-pack/plugins/maps/public/routes/map_page/saved_map/get_initial_layers_from_url_param.ts +++ b/x-pack/plugins/maps/public/routes/map_page/saved_map/get_initial_layers_from_url_param.ts @@ -5,7 +5,7 @@ * 2.0. */ -import rison from 'rison-node'; +import rison from '@kbn/rison'; import { i18n } from '@kbn/i18n'; import '../../../classes/sources/wms_source'; import '../../../classes/sources/ems_file_source'; @@ -13,26 +13,47 @@ import '../../../classes/sources/es_search_source'; import '../../../classes/sources/es_pew_pew_source'; import '../../../classes/sources/es_geo_grid_source'; import '../../../classes/sources/xyz_tms_source'; +import { LayerDescriptor } from '../../../../common'; import { getToasts } from '../../../kibana_services'; import { INITIAL_LAYERS_KEY } from '../../../../common/constants'; -export function getInitialLayersFromUrlParam() { +function isObj(v: unknown): v is Record { + return typeof v === 'object' && v !== null; +} + +function parseLayerDescriptors(mapInitLayers: string): LayerDescriptor[] { + const raw: any[] = rison.decodeArray(mapInitLayers); + + return raw.flatMap((desc, i) => { + if (isObj(desc) && typeof desc.id === 'string') { + return desc as LayerDescriptor; + } + + // we shouldn't end up here, but if we do it's likely only in testing or local dev so a console error is suitable + // eslint-disable-next-line no-console + console.error(`item ${i} in mapInitLayers is not a valid LayerDescriptor and was ignored`); + return []; + }); +} + +export function getInitialLayersFromUrlParam(): LayerDescriptor[] { const locationSplit = window.location.href.split('?'); if (locationSplit.length <= 1) { return []; } const mapAppParams = new URLSearchParams(locationSplit[1]); - if (!mapAppParams.has(INITIAL_LAYERS_KEY)) { + let mapInitLayers = mapAppParams.get(INITIAL_LAYERS_KEY); + if (!mapInitLayers) { return []; } try { - let mapInitLayers = mapAppParams.get(INITIAL_LAYERS_KEY); - if (mapInitLayers![mapInitLayers!.length - 1] === '#') { - mapInitLayers = mapInitLayers!.substr(0, mapInitLayers!.length - 1); + // strip # from the end of the param + if (mapInitLayers.endsWith('#')) { + mapInitLayers = mapInitLayers.slice(0, -1); } - // @ts-ignore - return rison.decode_array(mapInitLayers); + + return parseLayerDescriptors(mapInitLayers); } catch (e) { getToasts().addWarning({ title: i18n.translate('xpack.maps.initialLayers.unableToParseTitle', { diff --git a/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.tsx b/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.tsx index efd07615e6d8d..39dbd1d168179 100644 --- a/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.tsx +++ b/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.tsx @@ -7,7 +7,7 @@ import { cloneDeep } from 'lodash'; import moment from 'moment'; -import rison, { RisonValue } from 'rison-node'; +import rison, { RisonValue } from '@kbn/rison'; import React, { FC, useEffect, useMemo, useState } from 'react'; import { APP_ID as MAPS_APP_ID } from '@kbn/maps-plugin/common'; import { diff --git a/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/utils.js b/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/utils.js index 1c61985dfe951..14b91168b3427 100644 --- a/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/utils.js +++ b/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/utils.js @@ -7,7 +7,7 @@ import { TIME_RANGE_TYPE, URL_TYPE } from './constants'; -import rison from 'rison-node'; +import rison from '@kbn/rison'; import url from 'url'; import { diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/job_from_lens/route_resolver.ts b/x-pack/plugins/ml/public/application/jobs/new_job/job_from_lens/route_resolver.ts index 843399313d49c..8b39f68f075fb 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/job_from_lens/route_resolver.ts +++ b/x-pack/plugins/ml/public/application/jobs/new_job/job_from_lens/route_resolver.ts @@ -5,7 +5,7 @@ * 2.0. */ -import rison from 'rison-node'; +import rison from '@kbn/rison'; import type { Query } from '@kbn/es-query'; import { Filter } from '@kbn/es-query'; import type { LensSavedObjectAttributes } from '@kbn/lens-plugin/public'; diff --git a/x-pack/plugins/ml/public/application/util/custom_url_utils.ts b/x-pack/plugins/ml/public/application/util/custom_url_utils.ts index 5c8c78fc3839f..eba352ccd89a7 100644 --- a/x-pack/plugins/ml/public/application/util/custom_url_utils.ts +++ b/x-pack/plugins/ml/public/application/util/custom_url_utils.ts @@ -9,7 +9,7 @@ import { get, flow } from 'lodash'; import moment from 'moment'; -import rison, { RisonObject, RisonValue } from 'rison-node'; +import rison, { type RisonValue } from '@kbn/rison'; import { parseInterval } from '../../../common/util/parse_interval'; import { escapeForElasticsearchQuery, replaceStringTokens } from './string_utils'; import { @@ -133,7 +133,7 @@ export function escapeForKQL(value: string | number): string { type GetResultTokenValue = (v: string) => string; -export const isRisonObject = (value: RisonValue): value is RisonObject => { +export const isRisonObject = (value: RisonValue): value is Record => { return value !== null && typeof value === 'object'; }; diff --git a/x-pack/plugins/ml/public/application/util/url_state.tsx b/x-pack/plugins/ml/public/application/util/url_state.tsx index 7e09942412644..8aca531286a42 100644 --- a/x-pack/plugins/ml/public/application/util/url_state.tsx +++ b/x-pack/plugins/ml/public/application/util/url_state.tsx @@ -16,7 +16,7 @@ import React, { useEffect, } from 'react'; import { isEqual } from 'lodash'; -import { decode, encode } from 'rison-node'; +import { decode, encode } from '@kbn/rison'; import { useHistory, useLocation } from 'react-router-dom'; import { BehaviorSubject, Observable } from 'rxjs'; diff --git a/x-pack/plugins/ml/server/lib/alerts/alerting_service.ts b/x-pack/plugins/ml/server/lib/alerts/alerting_service.ts index d354e0a4eca3c..45eef7f63226a 100644 --- a/x-pack/plugins/ml/server/lib/alerts/alerting_service.ts +++ b/x-pack/plugins/ml/server/lib/alerts/alerting_service.ts @@ -7,7 +7,7 @@ import Boom from '@hapi/boom'; import { i18n } from '@kbn/i18n'; -import rison from 'rison-node'; +import rison from '@kbn/rison'; import { Duration } from 'moment/moment'; import { memoize } from 'lodash'; import { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/exploratory_view_url.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/exploratory_view_url.ts index 40ca09e428d11..57b2b8e71049c 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/exploratory_view_url.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/exploratory_view_url.ts @@ -5,7 +5,7 @@ * 2.0. */ -import rison, { RisonValue } from 'rison-node'; +import rison from '@kbn/rison'; import { URL_KEYS } from './constants/url_constants'; import type { ReportViewType, SeriesUrl } from '../types'; import type { AllSeries } from '../../../..'; @@ -51,7 +51,7 @@ export function createExploratoryViewUrl( return ( baseHref + `/app/${appId}/exploratory-view/#?reportType=${reportType}&sr=${encodeUriIfNeeded( - rison.encode(allShortSeries as unknown as RisonValue) + rison.encode(allShortSeries) )}` ); } diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/utils.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/utils.ts index e5a41739f7dd3..c8848e50f917f 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/utils.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/utils.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import rison, { RisonValue } from 'rison-node'; +import rison from '@kbn/rison'; import { buildQueryFilter, PhraseFilter, @@ -29,7 +29,7 @@ export function createExploratoryViewRoutePath({ const allShortSeries: AllShortSeries = allSeries.map((series) => convertToShortUrl(series)); return `/exploratory-view/#?reportType=${reportType}&sr=${encodeUriIfNeeded( - rison.encode(allShortSeries as unknown as RisonValue) + rison.encode(allShortSeries) )}`; } diff --git a/x-pack/plugins/observability/public/hooks/use_link_props.test.tsx b/x-pack/plugins/observability/public/hooks/use_link_props.test.tsx index c2c5f1f478953..43650406cc929 100644 --- a/x-pack/plugins/observability/public/hooks/use_link_props.test.tsx +++ b/x-pack/plugins/observability/public/hooks/use_link_props.test.tsx @@ -9,7 +9,7 @@ import { renderHook } from '@testing-library/react-hooks'; import { createMemoryHistory } from 'history'; import React, { PropsWithChildren } from 'react'; import { Router } from 'react-router-dom'; -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import { coreMock } from '@kbn/core/public/mocks'; import { CoreScopedHistory } from '@kbn/core/public'; import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public'; diff --git a/x-pack/plugins/osquery/public/packs/scheduled_query_errors_table.tsx b/x-pack/plugins/osquery/public/packs/scheduled_query_errors_table.tsx index 5a9a85fbc94b2..99b614a2c53f9 100644 --- a/x-pack/plugins/osquery/public/packs/scheduled_query_errors_table.tsx +++ b/x-pack/plugins/osquery/public/packs/scheduled_query_errors_table.tsx @@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n'; import { EuiInMemoryTable, EuiCodeBlock, EuiToolTip, EuiButtonIcon } from '@elastic/eui'; import React, { useCallback, useMemo } from 'react'; -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import { stringify } from 'querystring'; import { useKibana, isModifiedEvent, isLeftClickEvent } from '../common/lib/kibana'; diff --git a/x-pack/plugins/reporting/public/lib/reporting_api_client/reporting_api_client.ts b/x-pack/plugins/reporting/public/lib/reporting_api_client/reporting_api_client.ts index b217332856c21..91abac38f4d66 100644 --- a/x-pack/plugins/reporting/public/lib/reporting_api_client/reporting_api_client.ts +++ b/x-pack/plugins/reporting/public/lib/reporting_api_client/reporting_api_client.ts @@ -7,7 +7,7 @@ import { i18n } from '@kbn/i18n'; import moment from 'moment'; import { stringify } from 'query-string'; -import rison from 'rison-node'; +import rison from '@kbn/rison'; import type { HttpFetchQuery } from '@kbn/core/public'; import { HttpSetup, IUiSettingsClient } from '@kbn/core/public'; import { buildKibanaPath } from '../../../common/build_kibana_path'; diff --git a/x-pack/plugins/reporting/server/routes/generate/generate_from_jobparams.ts b/x-pack/plugins/reporting/server/routes/generate/generate_from_jobparams.ts index d84e2bc5620df..a76058315f185 100644 --- a/x-pack/plugins/reporting/server/routes/generate/generate_from_jobparams.ts +++ b/x-pack/plugins/reporting/server/routes/generate/generate_from_jobparams.ts @@ -6,7 +6,7 @@ */ import { schema } from '@kbn/config-schema'; -import rison from 'rison-node'; +import rison from '@kbn/rison'; import type { Logger } from '@kbn/core/server'; import type { ReportingCore } from '../..'; import { API_BASE_URL } from '../../../common/constants'; diff --git a/x-pack/plugins/reporting/server/routes/generate/integration_tests/generation_from_jobparams.test.ts b/x-pack/plugins/reporting/server/routes/generate/integration_tests/generation_from_jobparams.test.ts index 4c3f5d4d851b0..985ed9d1de7c7 100644 --- a/x-pack/plugins/reporting/server/routes/generate/integration_tests/generation_from_jobparams.test.ts +++ b/x-pack/plugins/reporting/server/routes/generate/integration_tests/generation_from_jobparams.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import rison from 'rison-node'; +import rison from '@kbn/rison'; import { BehaviorSubject } from 'rxjs'; import { loggingSystemMock } from '@kbn/core/server/mocks'; import { setupServer } from '@kbn/core-test-helpers-test-utils'; diff --git a/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/add_entities_to_kql.ts b/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/add_entities_to_kql.ts index 1d01e7c282a01..3edf9fccdee9d 100644 --- a/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/add_entities_to_kql.ts +++ b/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/add_entities_to_kql.ts @@ -5,8 +5,8 @@ * 2.0. */ -import type { RisonValue } from 'rison-node'; -import { encode } from 'rison-node'; +import type { RisonValue } from '@kbn/rison'; +import { encode } from '@kbn/rison'; import { decodeRison, isRisonObject, isRegularString } from './rison_helpers'; export const entityToKql = (entityNames: string[], entity: string): string => { diff --git a/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/remove_kql_variables.ts b/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/remove_kql_variables.ts index 1bba71ab604ce..18ad035debf08 100644 --- a/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/remove_kql_variables.ts +++ b/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/remove_kql_variables.ts @@ -5,8 +5,8 @@ * 2.0. */ -import type { RisonValue } from 'rison-node'; -import { encode } from 'rison-node'; +import type { RisonValue } from '@kbn/rison'; +import { encode } from '@kbn/rison'; import { decodeRison, isRisonObject, isRegularString } from './rison_helpers'; export const operators = ['and', 'or', 'not']; diff --git a/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/replace_kql_commas_with_or.ts b/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/replace_kql_commas_with_or.ts index be565d7609f22..1f96615811fc7 100644 --- a/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/replace_kql_commas_with_or.ts +++ b/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/replace_kql_commas_with_or.ts @@ -5,8 +5,8 @@ * 2.0. */ -import type { RisonValue } from 'rison-node'; -import { encode } from 'rison-node'; +import type { RisonValue } from '@kbn/rison'; +import { encode } from '@kbn/rison'; import { decodeRison, isRisonObject, isRegularString } from './rison_helpers'; export const replacement = (match: string, p1: string, p2: string) => { diff --git a/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/rison_helpers.ts b/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/rison_helpers.ts index 120fedf133b8f..656765484eeaf 100644 --- a/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/rison_helpers.ts +++ b/x-pack/plugins/security_solution/public/common/components/ml/conditional_links/rison_helpers.ts @@ -5,8 +5,8 @@ * 2.0. */ -import type { RisonValue, RisonObject } from 'rison-node'; -import { decode } from 'rison-node'; +import type { RisonValue } from '@kbn/rison'; +import { decode } from '@kbn/rison'; import { isObject, isString } from 'lodash/fp'; export const decodeRison = (value: string): RisonValue => { @@ -17,7 +17,7 @@ export const decodeRison = (value: string): RisonValue => { } }; -export const isRisonObject = (value: RisonValue): value is RisonObject => { +export const isRisonObject = (value: RisonValue): value is Record => { return isObject(value); }; diff --git a/x-pack/plugins/security_solution/public/common/utils/global_query_string/helpers.ts b/x-pack/plugins/security_solution/public/common/utils/global_query_string/helpers.ts index a5f7e93146750..0f3c1ab413fd0 100644 --- a/x-pack/plugins/security_solution/public/common/utils/global_query_string/helpers.ts +++ b/x-pack/plugins/security_solution/public/common/utils/global_query_string/helpers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { decode, encode } from 'rison-node'; +import { decode, encode } from '@kbn/rison'; import type { ParsedQuery } from 'query-string'; import { parse, stringify } from 'query-string'; import { url } from '@kbn/kibana-utils-plugin/public'; diff --git a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/store/selectors.ts b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/store/selectors.ts index 7665de64fa246..c70293502a20c 100644 --- a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/store/selectors.ts +++ b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/store/selectors.ts @@ -9,7 +9,7 @@ import querystring from 'querystring'; import { createSelector } from 'reselect'; import { matchPath } from 'react-router-dom'; -import { decode } from 'rison-node'; +import { decode } from '@kbn/rison'; import type { Query } from '@kbn/es-query'; import type { Immutable, HostMetadata } from '../../../../../common/endpoint/types'; import { HostStatus } from '../../../../../common/endpoint/types'; diff --git a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/components/search_bar.tsx b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/components/search_bar.tsx index 8b7f668df439d..0789fb44ba1c6 100644 --- a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/components/search_bar.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/components/search_bar.tsx @@ -7,8 +7,7 @@ import React, { memo, useCallback, useMemo } from 'react'; import { useHistory } from 'react-router-dom'; -import type { RisonValue } from 'rison-node'; -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import type { Query } from '@kbn/es-query'; import { TimeHistory } from '@kbn/data-plugin/public'; import type { DataView } from '@kbn/data-views-plugin/public'; @@ -37,9 +36,7 @@ export const AdminSearchBar = memo(() => { // if query is changed, reset back to first page // so that user is not (possibly) being left on an invalid page page_index: params.query?.query === searchBarQuery.query ? queryParams.page_index : '0', - ...(params.query?.query.trim() - ? { admin_query: encode(params.query as unknown as RisonValue) } - : {}), + ...(params.query?.query.trim() ? { admin_query: encode(params.query) } : {}), }) ); }, diff --git a/x-pack/plugins/security_solution/public/resolver/store/panel_view_and_parameters.ts b/x-pack/plugins/security_solution/public/resolver/store/panel_view_and_parameters.ts index 34f5adc868a9c..cb2d7915eb439 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/panel_view_and_parameters.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/panel_view_and_parameters.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { decode } from 'rison-node'; +import { decode } from '@kbn/rison'; import { isPanelViewAndParameters } from '../models/location_search'; import type { PanelViewAndParameters } from '../types'; import { parameterName } from './parameter_name'; diff --git a/x-pack/plugins/security_solution/public/resolver/store/ui/selectors.ts b/x-pack/plugins/security_solution/public/resolver/store/ui/selectors.ts index 95b1a286f1f51..7643cac07125c 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/ui/selectors.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/ui/selectors.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import { createSelector } from 'reselect'; import type { PanelViewAndParameters, ResolverUIState } from '../../types'; diff --git a/x-pack/plugins/security_solution/public/resolver/test_utilities/url_search.ts b/x-pack/plugins/security_solution/public/resolver/test_utilities/url_search.ts index d6e850d6b1287..c7b951a5eac5b 100644 --- a/x-pack/plugins/security_solution/public/resolver/test_utilities/url_search.ts +++ b/x-pack/plugins/security_solution/public/resolver/test_utilities/url_search.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import type { PanelViewAndParameters } from '../types'; /** diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor/ml/ml_job_link.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor/ml/ml_job_link.tsx index 2e9d771e11150..d782b20c6176a 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor/ml/ml_job_link.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor/ml/ml_job_link.tsx @@ -8,7 +8,7 @@ import React from 'react'; import url from 'url'; import { EuiButtonEmpty } from '@elastic/eui'; -import rison, { RisonValue } from 'rison-node'; +import rison from '@kbn/rison'; import { getMLJobId } from '../../../../../common/lib'; interface Props { @@ -42,8 +42,7 @@ export const getMLJobLinkHref = ({ basePath, monitorId, dateRange }: Props) => { return url.format({ pathname: basePath + '/app/ml', hash: - `${path}?_g=${rison.encode(query as RisonValue)}` + - (monitorId ? `&_a=${rison.encode(queryParams as RisonValue)}` : ''), + `${path}?_g=${rison.encode(query)}` + (monitorId ? `&_a=${rison.encode(queryParams)}` : ''), }); }; diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecation_logs/fix_deprecation_logs/external_links.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecation_logs/fix_deprecation_logs/external_links.tsx index 37bb16a9ba4d7..37bcf0e0c8a95 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecation_logs/fix_deprecation_logs/external_links.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecation_logs/fix_deprecation_logs/external_links.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { encode } from 'rison-node'; +import { encode } from '@kbn/rison'; import React, { FunctionComponent, useState, useEffect } from 'react'; import { buildPhrasesFilter, PhraseFilter } from '@kbn/es-query'; diff --git a/x-pack/test/functional/page_objects/infra_logs_page.ts b/x-pack/test/functional/page_objects/infra_logs_page.ts index 0bcbff031005c..040495cd754c3 100644 --- a/x-pack/test/functional/page_objects/infra_logs_page.ts +++ b/x-pack/test/functional/page_objects/infra_logs_page.ts @@ -8,7 +8,7 @@ import { FlyoutOptionsUrlState } from '@kbn/infra-plugin/public/containers/logs/log_flyout'; import { LogPositionUrlState } from '@kbn/infra-plugin/public/containers/logs/log_position'; import querystring from 'querystring'; -import { encode, RisonValue } from 'rison-node'; +import { encode } from '@kbn/rison'; import { FtrProviderContext } from '../ftr_provider_context'; export interface TabsParams { @@ -37,7 +37,7 @@ export function InfraLogsPageProvider({ getPageObjects, getService }: FtrProvide for (const key in params) { if (params.hasOwnProperty(key)) { - const value = params[key] as unknown as RisonValue; + const value = params[key]; parsedParams[key] = encode(value); } } diff --git a/x-pack/test/reporting_api_integration/services/scenarios.ts b/x-pack/test/reporting_api_integration/services/scenarios.ts index c61bb809da3a4..181af370e42c6 100644 --- a/x-pack/test/reporting_api_integration/services/scenarios.ts +++ b/x-pack/test/reporting_api_integration/services/scenarios.ts @@ -5,7 +5,7 @@ * 2.0. */ -import rison, { RisonValue } from 'rison-node'; +import rison from '@kbn/rison'; import { API_GET_ILM_POLICY_STATUS, API_MIGRATE_ILM_POLICY_URL, @@ -143,7 +143,7 @@ export function createScenarios({ getService }: Pick { - const jobParams = rison.encode(job as object as RisonValue); + const jobParams = rison.encode(job); return await supertestWithoutAuth .post(`/api/reporting/generate/printablePdf`) .auth(username, password) @@ -151,7 +151,7 @@ export function createScenarios({ getService }: Pick { - const jobParams = rison.encode(job as object as RisonValue); + const jobParams = rison.encode(job); return await supertestWithoutAuth .post(`/api/reporting/generate/png`) .auth(username, password) @@ -163,7 +163,7 @@ export function createScenarios({ getService }: Pick { - const jobParams = rison.encode(job as object as RisonValue); + const jobParams = rison.encode(job); return await supertestWithoutAuth .post(`/api/reporting/generate/csv_searchsource`) diff --git a/yarn.lock b/yarn.lock index 779d53211903a..20973a4dc8af9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3785,6 +3785,10 @@ version "0.0.0" uid "" +"@kbn/rison@link:bazel-bin/packages/kbn-rison": + version "0.0.0" + uid "" + "@kbn/rule-data-utils@link:bazel-bin/packages/kbn-rule-data-utils": version "0.0.0" uid ""