Skip to content

Commit

Permalink
add ServiceConfigDescriptor type
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Jan 6, 2020
1 parent 76c5bfe commit 6c06e70
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
18 changes: 18 additions & 0 deletions src/core/server/internal_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
* under the License.
*/

import { Type } from '@kbn/config-schema';

import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
import { ConfigDeprecationProvider } from './config';
import { ContextSetup } from './context';
import { InternalElasticsearchServiceSetup } from './elasticsearch';
import { InternalHttpServiceSetup } from './http';
Expand Down Expand Up @@ -47,3 +50,18 @@ export interface InternalCoreStart {
savedObjects: InternalSavedObjectsServiceStart;
uiSettings: InternalUiSettingsServiceStart;
}

/**
* @internal
*/
export interface ServiceConfigDescriptor<T = any> {
path: string;
/**
* Schema to use to validate the configuration.
*/
schema: Type<T>;
/**
* Provider for the {@link ConfigDeprecation} to apply to the plugin configuration.
*/
deprecations?: ConfigDeprecationProvider;
}
5 changes: 4 additions & 1 deletion src/core/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ export class Server {
];

this.configService.addDeprecationProvider(rootConfigPath, coreDeprecationProvider);
this.configService.addDeprecationProvider(uiSettingsConfig.path, uiSettingsConfig.deprecations);
this.configService.addDeprecationProvider(
uiSettingsConfig.path,
uiSettingsConfig.deprecations!
);

for (const [path, schema] of schemas) {
await this.configService.setSchema(path, schema);
Expand Down
39 changes: 21 additions & 18 deletions src/core/server/ui_settings/ui_settings_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,34 @@

import { schema, TypeOf } from '@kbn/config-schema';
import { ConfigDeprecationProvider } from 'src/core/server';
import { ServiceConfigDescriptor } from '../internal_types';

const deprecations: ConfigDeprecationProvider = ({ unused, renameFromRoot }) => [
unused('enabled'),
renameFromRoot('server.defaultRoute', 'uiSettings.overrides.defaultRoute'),
];

export type UiSettingsConfigType = TypeOf<typeof config.schema>;
const configSchema = schema.object({
overrides: schema.object(
{
defaultRoute: schema.maybe(
schema.string({
validate(value) {
if (!value.startsWith('/')) {
return 'must start with a slash';
}
},
})
),
},
{ allowUnknowns: true }
),
});

export const config = {
export type UiSettingsConfigType = TypeOf<typeof configSchema>;

export const config: ServiceConfigDescriptor<UiSettingsConfigType> = {
path: 'uiSettings',
schema: schema.object({
overrides: schema.object(
{
defaultRoute: schema.maybe(
schema.string({
validate(value) {
if (!value.startsWith('/')) {
return 'must start with a slash';
}
},
})
),
},
{ allowUnknowns: true }
),
}),
schema: configSchema,
deprecations,
};

0 comments on commit 6c06e70

Please sign in to comment.