77 * License v3.0 only", or the "Server Side Public License, v 1".
88 */
99
10- import type { ObjectType } from '@kbn/config-schema' ;
10+ import type { ObjectType , Type } from '@kbn/config-schema' ;
1111import type { getDrilldownRegistry } from '../drilldowns/registry' ;
1212import type { EmbeddableServerDefinition } from './types' ;
1313
1414export function getEmbeddableServerRegistry (
1515 drilldownRegistry : ReturnType < typeof getDrilldownRegistry >
1616) {
1717 const registry : { [ key : string ] : EmbeddableServerDefinition < any , any > } = { } ;
18+ const schemaCache : Record < string , Type < object > > = { } ;
19+
20+ function getCachedSchema ( type : string ) {
21+ if ( schemaCache [ type ] ) {
22+ return schemaCache [ type ] ;
23+ }
24+
25+ const { getSchema } = registry [ type ] ?? { } ;
26+ if ( ! getSchema ) return ;
27+ const schema = getSchema ( drilldownRegistry . getSchema ) ;
28+ if ( ! schema ) return ;
29+ schemaCache [ type ] = schema ;
30+ return schema ;
31+ }
1832
1933 return {
2034 registerEmbeddableServerDefinition : (
@@ -30,7 +44,7 @@ export function getEmbeddableServerRegistry(
3044 getAllEmbeddableSchemas : ( ) => {
3145 const schemas : { [ key : string ] : { schema : ObjectType ; title : string } } = { } ;
3246 Object . entries ( registry ) . forEach ( ( [ type , definition ] ) => {
33- const schema = definition ?. getSchema ?. ( drilldownRegistry . getSchema ) ;
47+ const schema = getCachedSchema ( type ) ;
3448 if ( schema ) {
3549 schemas [ type ] = {
3650 schema : schema as ObjectType ,
@@ -41,10 +55,11 @@ export function getEmbeddableServerRegistry(
4155 return schemas ;
4256 } ,
4357 getEmbeddableTransforms : ( type : string ) => {
44- const { getTransforms, getSchema, throwOnUnmappedPanel } = registry [ type ] ?? { } ;
58+ const { getTransforms, throwOnUnmappedPanel } = registry [ type ] ?? { } ;
59+ const schema = getCachedSchema ( type ) ;
4560 return {
4661 ...getTransforms ?.( drilldownRegistry . transforms ) ,
47- ...( getSchema ? { schema : getSchema ( drilldownRegistry . getSchema ) } : { } ) ,
62+ ...( schema ? { schema } : { } ) ,
4863 ...( typeof throwOnUnmappedPanel === 'boolean' ? { throwOnUnmappedPanel } : { } ) ,
4964 } ;
5065 } ,
0 commit comments