Skip to content

Commit

Permalink
[uiSettings] improves browser-side public types (elastic#149645)
Browse files Browse the repository at this point in the history
Co-authored-by: kibanamachine <[email protected]>
fix elastic#137609
  • Loading branch information
TinaHeiligers authored and darnautov committed Feb 7, 2023
1 parent c951d42 commit a7fc864
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

import UiSharedDepsNpm from '@kbn/ui-shared-deps-npm';
import * as UiSharedDepsSrc from '@kbn/ui-shared-deps-src';
import type { PublicUiSettingsParams, UserProvidedValues } from '@kbn/core-ui-settings-common';
import type { UiSettingsParams, UserProvidedValues } from '@kbn/core-ui-settings-common';

export const getSettingValue = <T>(
settingName: string,
settings: {
user?: Record<string, UserProvidedValues<unknown>>;
defaults: Readonly<Record<string, PublicUiSettingsParams>>;
defaults: Readonly<Record<string, Omit<UiSettingsParams, 'schema'>>>;
},
convert: (raw: unknown) => T
): T => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import { cloneDeep, defaultsDeep } from 'lodash';
import { Observable, Subject, concat, defer, of } from 'rxjs';
import { filter, map } from 'rxjs/operators';

import { UserProvidedValues, PublicUiSettingsParams } from '@kbn/core-ui-settings-common';
import { IUiSettingsClient, UiSettingsState } from '@kbn/core-ui-settings-browser';
import { UserProvidedValues } from '@kbn/core-ui-settings-common';
import {
IUiSettingsClient,
UiSettingsState,
PublicUiSettingsParams,
} from '@kbn/core-ui-settings-browser';

import { UiSettingsApi } from './ui_settings_api';

Expand Down
8 changes: 7 additions & 1 deletion packages/core/ui-settings/core-ui-settings-browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
* Side Public License, v 1.
*/

export type { UiSettingsState, IUiSettingsClient, SettingsStart, SettingsSetup } from './src/types';
export type {
PublicUiSettingsParams,
UiSettingsState,
IUiSettingsClient,
SettingsStart,
SettingsSetup,
} from './src/types';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

import type { Observable } from 'rxjs';
import type { PublicUiSettingsParams, UserProvidedValues } from '@kbn/core-ui-settings-common';
import type { UiSettingsParams, UserProvidedValues } from '@kbn/core-ui-settings-common';

export type PublicUiSettingsParams = Omit<UiSettingsParams, 'schema'>;

/** @public */
export interface UiSettingsState {
Expand Down
1 change: 0 additions & 1 deletion packages/core/ui-settings/core-ui-settings-common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type {
UiSettingsType,
DeprecationSettings,
UiSettingsParams,
PublicUiSettingsParams,
UserProvidedValues,
UiSettingsScope,
} from './src/ui_settings';
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ export interface UiSettingsParams<T = unknown> {
scope?: UiSettingsScope;
}

/**
* A sub-set of {@link UiSettingsParams} exposed to the client-side.
* @public
* */
export type PublicUiSettingsParams = Omit<UiSettingsParams, 'schema'>;

/**
* Describes the values explicitly set by user.
* @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

import { omit } from 'lodash';
import type { Logger } from '@kbn/logging';
import type {
UiSettingsParams,
PublicUiSettingsParams,
UserProvidedValues,
} from '@kbn/core-ui-settings-common';
import type { UiSettingsParams, UserProvidedValues } from '@kbn/core-ui-settings-common';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-server';

export interface BaseUiSettingsDefaultsClientOptions {
Expand Down Expand Up @@ -42,7 +38,7 @@ export abstract class BaseUiSettingsClient implements IUiSettingsClient {
}

getRegistered() {
const copiedDefaults: Record<string, PublicUiSettingsParams> = {};
const copiedDefaults: Record<string, Omit<UiSettingsParams, 'schema'>> = {};
for (const [key, value] of Object.entries(this.defaults)) {
copiedDefaults[key] = omit(value, 'schema');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import type { UserProvidedValues, PublicUiSettingsParams } from '@kbn/core-ui-settings-common';
import type { UserProvidedValues, UiSettingsParams } from '@kbn/core-ui-settings-common';

/**
* Server-side client that provides access to the advanced settings stored in elasticsearch.
Expand All @@ -20,7 +20,7 @@ export interface IUiSettingsClient {
/**
* Returns registered uiSettings values {@link UiSettingsParams}
*/
getRegistered: () => Readonly<Record<string, PublicUiSettingsParams>>;
getRegistered: () => Readonly<Record<string, Omit<UiSettingsParams, 'schema'>>>;
/**
* Retrieves uiSettings values set by the user with fallbacks to default values if not specified.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export type {
FatalErrorsStart,
FatalErrorInfo,
} from '@kbn/core-fatal-errors-browser';
export type { UiSettingsState, IUiSettingsClient } from '@kbn/core-ui-settings-browser';
export type {
UiSettingsState,
IUiSettingsClient,
PublicUiSettingsParams,
} from '@kbn/core-ui-settings-browser';
export type { Capabilities } from '@kbn/core-capabilities-common';
export type { SavedObjectsStart } from '@kbn/core-saved-objects-browser';
export type { NotificationsSetup, NotificationsStart } from '@kbn/core-notifications-browser';
Expand Down Expand Up @@ -76,7 +80,6 @@ export {
} from '@kbn/core-application-common';
export type {
UiSettingsParams,
PublicUiSettingsParams,
UserProvidedValues,
UiSettingsType,
} from '@kbn/core-ui-settings-common';
Expand Down
1 change: 0 additions & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ export type {

export type {
UiSettingsParams,
PublicUiSettingsParams,
UiSettingsType,
UserProvidedValues,
DeprecationSettings,
Expand Down
1 change: 0 additions & 1 deletion src/core/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export type {
UiSettingsType,
DeprecationSettings,
UiSettingsParams,
PublicUiSettingsParams,
UserProvidedValues,
} from '@kbn/core-ui-settings-common';

0 comments on commit a7fc864

Please sign in to comment.