66
77import {
88 CoreSetup ,
9+ CoreStart ,
10+ SavedObjectsServiceStart ,
911 Logger ,
1012 PluginInitializerContext ,
1113 RecursiveReadonly ,
1214} from '../../../../src/core/server' ;
1315import { Capabilities as UICapabilities } from '../../../../src/core/server' ;
1416import { deepFreeze } from '../../../../src/core/server' ;
15- import { XPackInfo } from '../../../legacy/plugins/xpack_main/server/lib/xpack_info' ;
1617import { PluginSetupContract as TimelionSetupContract } from '../../../../src/plugins/vis_type_timelion/server' ;
1718import { FeatureRegistry } from './feature_registry' ;
1819import { Feature , FeatureConfig } from '../common/feature' ;
@@ -25,39 +26,26 @@ import { defineRoutes } from './routes';
2526 */
2627export interface PluginSetupContract {
2728 registerFeature ( feature : FeatureConfig ) : void ;
29+ /*
30+ * Calling this function during setup will crash Kibana.
31+ * Use start contract instead.
32+ * @deprecated
33+ * */
2834 getFeatures ( ) : Feature [ ] ;
2935 getFeaturesUICapabilities ( ) : UICapabilities ;
30- registerLegacyAPI : ( legacyAPI : LegacyAPI ) => void ;
3136}
3237
3338export interface PluginStartContract {
3439 getFeatures ( ) : Feature [ ] ;
3540}
3641
37- /**
38- * Describes a set of APIs that are available in the legacy platform only and required by this plugin
39- * to function properly.
40- */
41- export interface LegacyAPI {
42- xpackInfo : Pick < XPackInfo , 'license' > ;
43- savedObjectTypes : string [ ] ;
44- }
45-
4642/**
4743 * Represents Features Plugin instance that will be managed by the Kibana plugin system.
4844 */
4945export class Plugin {
5046 private readonly logger : Logger ;
51-
5247 private readonly featureRegistry : FeatureRegistry = new FeatureRegistry ( ) ;
53-
54- private legacyAPI ?: LegacyAPI ;
55- private readonly getLegacyAPI = ( ) => {
56- if ( ! this . legacyAPI ) {
57- throw new Error ( 'Legacy API is not registered!' ) ;
58- }
59- return this . legacyAPI ;
60- } ;
48+ private isTimelionEnabled : boolean = false ;
6149
6250 constructor ( private readonly initializerContext : PluginInitializerContext ) {
6351 this . logger = this . initializerContext . logger . get ( ) ;
@@ -67,39 +55,49 @@ export class Plugin {
6755 core : CoreSetup ,
6856 { visTypeTimelion } : { visTypeTimelion ?: TimelionSetupContract }
6957 ) : Promise < RecursiveReadonly < PluginSetupContract > > {
58+ this . isTimelionEnabled = visTypeTimelion !== undefined && visTypeTimelion . uiEnabled ;
59+
7060 defineRoutes ( {
7161 router : core . http . createRouter ( ) ,
7262 featureRegistry : this . featureRegistry ,
73- getLegacyAPI : this . getLegacyAPI ,
7463 } ) ;
7564
7665 return deepFreeze ( {
7766 registerFeature : this . featureRegistry . register . bind ( this . featureRegistry ) ,
7867 getFeatures : this . featureRegistry . getAll . bind ( this . featureRegistry ) ,
7968 getFeaturesUICapabilities : ( ) => uiCapabilitiesForFeatures ( this . featureRegistry . getAll ( ) ) ,
80-
81- registerLegacyAPI : ( legacyAPI : LegacyAPI ) => {
82- this . legacyAPI = legacyAPI ;
83-
84- // Register OSS features.
85- for ( const feature of buildOSSFeatures ( {
86- savedObjectTypes : this . legacyAPI . savedObjectTypes ,
87- includeTimelion : visTypeTimelion !== undefined && visTypeTimelion . uiEnabled ,
88- } ) ) {
89- this . featureRegistry . register ( feature ) ;
90- }
91- } ,
9269 } ) ;
9370 }
9471
95- public start ( ) : RecursiveReadonly < PluginStartContract > {
96- this . logger . debug ( 'Starting plugin' ) ;
72+ public start ( core : CoreStart ) : RecursiveReadonly < PluginStartContract > {
73+ this . registerOssFeatures ( core . savedObjects ) ;
74+
9775 return deepFreeze ( {
9876 getFeatures : this . featureRegistry . getAll . bind ( this . featureRegistry ) ,
9977 } ) ;
10078 }
10179
102- public stop ( ) {
103- this . logger . debug ( 'Stopping plugin' ) ;
80+ public stop ( ) { }
81+
82+ private registerOssFeatures ( savedObjects : SavedObjectsServiceStart ) {
83+ const registry = savedObjects . getTypeRegistry ( ) ;
84+ const savedObjectTypes = registry
85+ . getAllTypes ( )
86+ . filter ( t => ! t . hidden )
87+ . map ( t => t . name ) ;
88+
89+ this . logger . debug (
90+ `Registering OSS features with SO types: ${ savedObjectTypes . join ( ', ' ) } . "includeTimelion": ${
91+ this . isTimelionEnabled
92+ } .`
93+ ) ;
94+ const features = buildOSSFeatures ( {
95+ savedObjectTypes,
96+ includeTimelion : this . isTimelionEnabled ,
97+ } ) ;
98+
99+ for ( const feature of features ) {
100+ this . featureRegistry . register ( feature ) ;
101+ }
104102 }
105103}
0 commit comments