Skip to content

Commit 8ba60a4

Browse files
authored
bump query-string version to remove manual type definitions (#78143)
* bump query-string version to remove manual type definitions * remove manual type declaration * fix cypress tests * add )
1 parent 3f2e9f7 commit 8ba60a4

File tree

17 files changed

+81
-221
lines changed

17 files changed

+81
-221
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
"p-map": "^4.0.0",
196196
"pegjs": "0.10.0",
197197
"proxy-from-env": "1.0.0",
198-
"query-string": "5.1.1",
198+
"query-string": "^6.13.2",
199199
"re2": "^1.15.4",
200200
"react": "^16.12.0",
201201
"react-color": "^2.13.8",

packages/kbn-std/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ export { mapToObject } from './map_to_object';
2424
export { merge } from './merge';
2525
export { pick } from './pick';
2626
export { withTimeout } from './promise';
27-
export { isRelativeUrl, modifyUrl, URLMeaningfulParts, ParsedQuery } from './url';
27+
export { isRelativeUrl, modifyUrl, URLMeaningfulParts } from './url';
2828
export { unset } from './unset';
2929
export { getFlattenedObject } from './get_flattened_object';

packages/kbn-std/src/url.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
*/
1919

2020
import { format as formatUrl, parse as parseUrl, UrlObject } from 'url';
21-
22-
// duplicate type from 'query-string' to avoid adding the d.ts file to all packages depending on kbn-std
23-
export interface ParsedQuery<T = string> {
24-
[key: string]: T | T[] | null | undefined;
25-
}
21+
import type { ParsedQuery } from 'query-string';
2622

2723
/**
2824
* We define our own typings because the current version of @types/node

src/core/typings.ts

-28
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
declare module 'query-string' {
21-
type ArrayFormat = 'bracket' | 'index' | 'none';
22-
23-
export interface ParseOptions {
24-
arrayFormat?: ArrayFormat;
25-
sort: ((itemLeft: string, itemRight: string) => number) | false;
26-
}
27-
28-
export interface ParsedQuery<T = string> {
29-
[key: string]: T | T[] | null | undefined;
30-
}
31-
32-
export function parse(str: string, options?: ParseOptions): ParsedQuery;
33-
34-
export function parseUrl(str: string, options?: ParseOptions): { url: string; query: any };
35-
36-
export interface StringifyOptions {
37-
strict?: boolean;
38-
encode?: boolean;
39-
arrayFormat?: ArrayFormat;
40-
sort: ((itemLeft: string, itemRight: string) => number) | false;
41-
}
42-
43-
export function stringify(obj: object, options?: StringifyOptions): string;
44-
45-
export function extract(str: string): string;
46-
}
47-
4820
type DeeplyMockedKeys<T> = {
4921
[P in keyof T]: T[P] extends (...args: any[]) => any
5022
? jest.MockInstance<ReturnType<T[P]>, Parameters<T[P]>>

src/plugins/dashboard/public/url_utils/url_helper.test.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ describe('', () => {
2424
const id = '123eb456cd';
2525
const url =
2626
"/pep/app/dashboards#/create?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&_a=(description:'',filters:!())";
27-
expect(addEmbeddableToDashboardUrl(url, id, 'visualization')).toEqual(
28-
`/pep/app/dashboards#/create?_a=%28description%3A%27%27%2Cfilters%3A%21%28%29%29&_g=%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29&addEmbeddableId=${id}&addEmbeddableType=visualization`
27+
28+
expect(addEmbeddableToDashboardUrl(url, id, 'visualization')).toBe(
29+
'/pep/app/dashboards?addEmbeddableId=123eb456cd&addEmbeddableType=visualization#%2Fcreate%3F_g%3D%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29%26_a%3D%28description%3A%27%27%2Cfilters%3A%21%28%29%29'
2930
);
3031
});
3132
it('addEmbeddableToDashboardUrl when dashboard is saved', () => {
3233
const id = '123eb456cd';
3334
const url =
3435
"/pep/app/dashboards#/view/9b780cd0-3dd3-11e8-b2b9-5d5dc1715159?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&_a=(description:'',filters:!())";
35-
expect(addEmbeddableToDashboardUrl(url, id, 'visualization')).toEqual(
36-
`/pep/app/dashboards#/view/9b780cd0-3dd3-11e8-b2b9-5d5dc1715159?_a=%28description%3A%27%27%2Cfilters%3A%21%28%29%29&_g=%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29&addEmbeddableId=${id}&addEmbeddableType=visualization`
36+
expect(addEmbeddableToDashboardUrl(url, id, 'visualization')).toBe(
37+
'/pep/app/dashboards?addEmbeddableId=123eb456cd&addEmbeddableType=visualization#%2Fview%2F9b780cd0-3dd3-11e8-b2b9-5d5dc1715159%3F_g%3D%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29%26_a%3D%28description%3A%27%27%2Cfilters%3A%21%28%29%29'
3738
);
3839
});
3940
});

src/plugins/dashboard/public/url_utils/url_helper.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
import { parseUrl, stringify } from 'query-string';
20+
import { parseUrl, stringifyUrl } from 'query-string';
2121
import { DashboardConstants } from '../index';
2222

2323
/** *
@@ -34,12 +34,14 @@ export function addEmbeddableToDashboardUrl(
3434
embeddableId: string,
3535
embeddableType: string
3636
) {
37-
const { url, query } = parseUrl(dashboardUrl);
37+
const { url, query, fragmentIdentifier } = parseUrl(dashboardUrl, {
38+
parseFragmentIdentifier: true,
39+
});
3840

3941
if (embeddableId) {
4042
query[DashboardConstants.ADD_EMBEDDABLE_TYPE] = embeddableType;
4143
query[DashboardConstants.ADD_EMBEDDABLE_ID] = embeddableId;
4244
}
4345

44-
return `${url}?${stringify(query)}`;
46+
return stringifyUrl({ url, query, fragmentIdentifier });
4547
}

test/typings/query_string.d.ts

-46
This file was deleted.

typings/query_string.d.ts

-46
This file was deleted.

x-pack/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@
361361
"proper-lockfile": "^3.2.0",
362362
"puid": "1.0.7",
363363
"puppeteer-core": "^1.19.0",
364-
"query-string": "5.1.1",
364+
"query-string": "^6.13.2",
365365
"raw-loader": "3.1.0",
366366
"react": "^16.12.0",
367367
"react-datetime": "^2.14.0",

x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('RedirectToLogs component', () => {
1919

2020
expect(component).toMatchInlineSnapshot(`
2121
<Redirect
22-
to="/stream?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'',kind:kuery)"
22+
to="/stream?sourceId=default&logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&logFilter=(expression:'',kind:kuery)"
2323
/>
2424
`);
2525
});
@@ -33,7 +33,7 @@ describe('RedirectToLogs component', () => {
3333

3434
expect(component).toMatchInlineSnapshot(`
3535
<Redirect
36-
to="/stream?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"
36+
to="/stream?sourceId=default&logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&logFilter=(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"
3737
/>
3838
`);
3939
});

x-pack/plugins/infra/public/utils/url_state.tsx

+8-10
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,14 @@ export const replaceStateKeyInQueryString = <UrlState extends any>(
156156
urlState: UrlState | undefined
157157
) => (queryString: string) => {
158158
const previousQueryValues = parse(queryString, { sort: false });
159-
const encodedUrlState =
160-
typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined;
161-
162-
return stringify(
163-
url.encodeQuery({
164-
...previousQueryValues,
165-
[stateKey]: encodedUrlState,
166-
}),
167-
{ sort: false, encode: false }
168-
);
159+
const newValue =
160+
typeof urlState === 'undefined'
161+
? previousQueryValues
162+
: {
163+
...previousQueryValues,
164+
[stateKey]: encodeRisonUrlState(urlState),
165+
};
166+
return stringify(url.encodeQuery(newValue), { sort: false, encode: false });
169167
};
170168

171169
const replaceQueryStringInLocation = (location: Location, queryString: string): Location => {

x-pack/plugins/infra/public/utils/use_url_state.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,15 @@ export const replaceStateKeyInQueryString = <UrlState extends any>(
111111
urlState: UrlState | undefined
112112
) => (queryString: string) => {
113113
const previousQueryValues = parse(queryString, { sort: false });
114-
const encodedUrlState =
115-
typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined;
116-
117-
return stringify(
118-
url.encodeQuery({
119-
...previousQueryValues,
120-
[stateKey]: encodedUrlState,
121-
}),
122-
{ sort: false, encode: false }
123-
);
114+
const newValue =
115+
typeof urlState === 'undefined'
116+
? previousQueryValues
117+
: {
118+
...previousQueryValues,
119+
[stateKey]: encodeRisonUrlState(urlState),
120+
};
121+
122+
return stringify(url.encodeQuery(newValue), { sort: false, encode: false });
124123
};
125124

126125
const replaceQueryStringInLocation = (location: Location, queryString: string): Location => {

0 commit comments

Comments
 (0)