Skip to content

Commit

Permalink
Platform lodash4 tweaks (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover authored Jun 26, 2020
1 parent bfeeb25 commit 554456d
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 22 deletions.
12 changes: 4 additions & 8 deletions src/core/public/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,23 @@ describe('PluginsService', () => {
context: contextServiceMock.createSetupContract(),
fatalErrors: fatalErrorsServiceMock.createSetupContract(),
http: httpServiceMock.createSetupContract(),
injectedMetadata: pick(
injectedMetadataServiceMock.createStartContract(),
'getInjectedVar'
) as any,
injectedMetadata: injectedMetadataServiceMock.createStartContract(),
notifications: notificationServiceMock.createSetupContract(),
uiSettings: uiSettingsServiceMock.createSetupContract(),
};
mockSetupContext = {
...mockSetupDeps,
application: expect.any(Object),
getStartServices: expect.any(Function),
injectedMetadata: pick(mockSetupDeps.injectedMetadata, 'getInjectedVar'),
};
mockStartDeps = {
application: applicationServiceMock.createInternalStartContract(),
docLinks: docLinksServiceMock.createStartContract(),
http: httpServiceMock.createStartContract(),
chrome: chromeServiceMock.createStartContract(),
i18n: i18nServiceMock.createStartContract(),
injectedMetadata: pick(
injectedMetadataServiceMock.createStartContract(),
'getInjectedVar'
) as any,
injectedMetadata: injectedMetadataServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
overlays: overlayServiceMock.createStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract(),
Expand All @@ -123,6 +118,7 @@ describe('PluginsService', () => {
...mockStartDeps,
application: expect.any(Object),
chrome: omit(mockStartDeps.chrome, 'getComponent'),
injectedMetadata: pick(mockStartDeps.injectedMetadata, 'getInjectedVar'),
};

// Reset these for each test.
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/saved_objects/simple_saved_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class SimpleSavedObject<T = unknown> {
}

public set(key: string, value: any): T {
return set(this.attributes as any, key, value) as any;
return set(this.attributes as any, key, value);
}

public has(key: string): boolean {
Expand Down
5 changes: 1 addition & 4 deletions src/core/server/config/deprecation/core_deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ const dataPathDeprecation: ConfigDeprecation = (settings, fromPath, log) => {
};

const xsrfDeprecation: ConfigDeprecation = (settings, fromPath, log) => {
if (
has(settings, 'server.xsrf.whitelist') &&
get<unknown[]>(settings, 'server.xsrf.whitelist' as any).length > 0
) {
if ((settings.server?.xsrf?.whitelist ?? []).length > 0) {
log(
'It is not recommended to disable xsrf protections for API endpoints via [server.xsrf.whitelist]. ' +
'It will be removed in 8.0 release. Instead, supply the "kbn-xsrf" header.'
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/elasticsearch/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ElasticsearchErrorHelpers {

public static decorateNotAuthorizedError(error: Error, reason?: string) {
const decoratedError = decorate(error, ErrorCode.NOT_AUTHORIZED, 401, reason);
const wwwAuthHeader = get<string>(error as any, 'body.error.header[WWW-Authenticate]' as any);
const wwwAuthHeader = (error as any).body?.header?.['WWW-Authenticate'] as string;

decoratedError.output.headers['WWW-Authenticate'] =
wwwAuthHeader || 'Basic realm="Authorization Required"';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function buildActiveMigrations(
return {
...migrations,
[type.name]: {
latestVersion: (_.last(transforms) as Record<string, any>).version,
latestVersion: _.last(transforms)!.version,
transforms,
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ export class SavedObjectsRepository {
// method transparently to the specified namespace.
private _rawToSavedObject<T = unknown>(raw: SavedObjectsRawDoc): SavedObject<T> {
const savedObject = this._serializer.rawToSavedObject(raw);
return omit(savedObject, 'namespace') as SavedObject<any>;
return omit(savedObject, 'namespace') as SavedObject<T>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const SavedObjectsTablePage = ({
}}
canGoInApp={(savedObject) => {
const { inAppUrl } = savedObject.meta;
return inAppUrl ? (get(capabilities, inAppUrl.uiCapabilitiesPath) as any) : false;
return inAppUrl ? Boolean(get(capabilities, inAppUrl.uiCapabilitiesPath)) : false;
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import _ from 'lodash';
import { Capabilities as UICapabilities } from '../../../../src/core/server';
import { Feature } from '../common/feature';

const ELIGIBLE_FLAT_MERGE_KEYS = ['catalogue'];
const ELIGIBLE_FLAT_MERGE_KEYS = ['catalogue'] as const;

interface FeatureCapabilities {
[featureId: string]: Record<string, boolean>;
Expand Down Expand Up @@ -67,10 +67,7 @@ function getCapabilitiesFromFeature(feature: Feature): FeatureCapabilities {

function buildCapabilities(...allFeatureCapabilities: FeatureCapabilities[]): UICapabilities {
return allFeatureCapabilities.reduce<UICapabilities>((acc, capabilities) => {
const mergableCapabilities: UICapabilities = _.omit(
capabilities,
...ELIGIBLE_FLAT_MERGE_KEYS
) as UICapabilities;
const mergableCapabilities = _.omit(capabilities, ...ELIGIBLE_FLAT_MERGE_KEYS);

const mergedFeatureCapabilities = {
...mergableCapabilities,
Expand Down

0 comments on commit 554456d

Please sign in to comment.