mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* Some basic types for top level legacy plugin registration * put typescript interface closer to implementation * Use default export, you have to * fix build and address code review comments
This commit is contained in:
parent
71b1b60f70
commit
fc2176ecd7
11 changed files with 73 additions and 13 deletions
5
kibana.d.ts
vendored
5
kibana.d.ts
vendored
|
@ -25,6 +25,7 @@ export * from './target/types/type_exports';
|
|||
* All exports from TS ambient definitions (where types are added for JS source in a .d.ts file).
|
||||
*/
|
||||
import * as LegacyElasticsearch from './src/legacy/core_plugins/elasticsearch';
|
||||
import * as LegacyKibanaPluginSpec from './src/legacy/plugin_discovery/plugin_spec/plugin_spec_options';
|
||||
import * as LegacyKibanaServer from './src/legacy/server/kbn_server';
|
||||
|
||||
/**
|
||||
|
@ -40,6 +41,10 @@ export namespace Legacy {
|
|||
export type SavedObjectsService = LegacyKibanaServer.SavedObjectsService;
|
||||
export type Server = LegacyKibanaServer.Server;
|
||||
|
||||
export type InitPluginFunction = LegacyKibanaPluginSpec.InitPluginFunction;
|
||||
export type UiExports = LegacyKibanaPluginSpec.UiExports;
|
||||
export type PluginSpecOptions = LegacyKibanaPluginSpec.PluginSpecOptions;
|
||||
|
||||
export namespace Plugins {
|
||||
export namespace elasticsearch {
|
||||
export type Plugin = LegacyElasticsearch.ElasticsearchPlugin;
|
||||
|
|
|
@ -18,10 +18,12 @@
|
|||
*/
|
||||
|
||||
import { resolve } from 'path';
|
||||
import init from './init';
|
||||
import { Legacy } from '../../../../kibana';
|
||||
import { init } from './init';
|
||||
|
||||
export default function (kibana) {
|
||||
return new kibana.Plugin({
|
||||
// tslint:disable-next-line
|
||||
export default function InterpreterPlugin(kibana: any) {
|
||||
const config: Legacy.PluginSpecOptions = {
|
||||
id: 'interpreter',
|
||||
require: ['kibana', 'elasticsearch'],
|
||||
publicDir: resolve(__dirname, 'public'),
|
||||
|
@ -29,6 +31,7 @@ export default function (kibana) {
|
|||
injectDefaultVars: server => ({ serverBasePath: server.config().get('server.basePath') }),
|
||||
},
|
||||
init,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return new kibana.Plugin(config);
|
||||
}
|
|
@ -17,17 +17,26 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { routes } from './server/routes';
|
||||
// @ts-ignore
|
||||
import { registryFactory } from '@kbn/interpreter/common';
|
||||
|
||||
// @ts-ignore
|
||||
import { registries } from '@kbn/interpreter/server';
|
||||
|
||||
export default async function (server /*options*/) {
|
||||
// @ts-ignore
|
||||
import { routes } from './server/routes';
|
||||
|
||||
import { Legacy } from '../../../../kibana';
|
||||
|
||||
export async function init(server: Legacy.Server /*options*/) {
|
||||
server.injectUiAppVars('canvas', () => {
|
||||
const config = server.config();
|
||||
const basePath = config.get('server.basePath');
|
||||
const reportingBrowserType = (() => {
|
||||
const configKey = 'xpack.reporting.capture.browser.type';
|
||||
if (!config.has(configKey)) return null;
|
||||
if (!config.has(configKey)) {
|
||||
return null;
|
||||
}
|
||||
return config.get(configKey);
|
||||
})();
|
||||
|
32
src/legacy/plugin_discovery/plugin_spec/plugin_spec_options.d.ts
vendored
Normal file
32
src/legacy/plugin_discovery/plugin_spec/plugin_spec_options.d.ts
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { Server } from '../../server/kbn_server';
|
||||
|
||||
export type InitPluginFunction = (server: Server) => void;
|
||||
export interface UiExports {
|
||||
injectDefaultVars: (server: Server) => { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface PluginSpecOptions {
|
||||
id: string;
|
||||
require: string[];
|
||||
publicDir: string;
|
||||
uiExports?: UiExports;
|
||||
init: InitPluginFunction;
|
||||
}
|
2
src/legacy/server/kbn_server.d.ts
vendored
2
src/legacy/server/kbn_server.d.ts
vendored
|
@ -27,6 +27,7 @@ import { SavedObjectsClient, SavedObjectsService } from './saved_objects';
|
|||
|
||||
export interface KibanaConfig {
|
||||
get<T>(key: string): T;
|
||||
has(key: string): boolean;
|
||||
}
|
||||
|
||||
// Extend the defaults with the plugins and server methods we need.
|
||||
|
@ -43,6 +44,7 @@ declare module 'hapi' {
|
|||
config: () => KibanaConfig;
|
||||
indexPatternsServiceFactory: IndexPatternsServiceFactory;
|
||||
savedObjects: SavedObjectsService;
|
||||
injectUiAppVars: (pluginName: string, getAppVars: () => { [key: string]: any }) => void;
|
||||
}
|
||||
|
||||
interface Request {
|
||||
|
|
|
@ -39,6 +39,9 @@ export function createMockServer(config: { [key: string]: any } = defaultConfig)
|
|||
get(key: string) {
|
||||
return config[key];
|
||||
},
|
||||
has(key: string) {
|
||||
return config.hasOwnProperty(key);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@ describe('timeseriesFetcher', () => {
|
|||
end: 1528977600000,
|
||||
client: clientSpy,
|
||||
config: {
|
||||
get: () => 'myIndex' as any
|
||||
get: () => 'myIndex' as any,
|
||||
has: () => true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -24,7 +24,8 @@ describe('transactionGroupsFetcher', () => {
|
|||
case 'xpack.apm.ui.transactionGroupBucketSize':
|
||||
return 100;
|
||||
}
|
||||
})
|
||||
}),
|
||||
has: () => true
|
||||
}
|
||||
};
|
||||
const bodyQuery = { my: 'bodyQuery' };
|
||||
|
|
|
@ -26,7 +26,8 @@ describe('getAnomalySeries', () => {
|
|||
end: 500000,
|
||||
client: clientSpy,
|
||||
config: {
|
||||
get: () => 'myIndex' as any
|
||||
get: () => 'myIndex' as any,
|
||||
has: () => true
|
||||
}
|
||||
}
|
||||
})) as AnomalyTimeSeriesResponse;
|
||||
|
|
|
@ -22,7 +22,8 @@ describe('timeseriesFetcher', () => {
|
|||
end: 1528977600000,
|
||||
client: clientSpy,
|
||||
config: {
|
||||
get: () => 'myIndex' as any
|
||||
get: () => 'myIndex' as any,
|
||||
has: () => true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -10,6 +10,7 @@ interface TestSetup extends Setup {
|
|||
client: jest.Mock;
|
||||
config: {
|
||||
get: jest.Mock;
|
||||
has: () => boolean;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -22,7 +23,8 @@ export function getSetupMock(overrides: Partial<TestSetup> = {}) {
|
|||
term: { field: 'test.esfilter.query' }
|
||||
},
|
||||
config: {
|
||||
get: jest.fn()
|
||||
get: jest.fn(),
|
||||
has: () => true
|
||||
},
|
||||
...overrides
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue