import type { Logger } from 'kibana/server' ; import { ExtensionPoint , ExtensionPointStorageClientInterface , ExtensionPointStorageInterface , NarrowExtensionPointToType , } from './types' ; import { ExtensionPointStorageClient } from './extension_point_storage_client' ; export class ExtensionPointStorage implements ExtensionPointStorageInterface { private readonly store = new Map < ExtensionPoint [ 'type' ] , Set < ExtensionPoint > > ( ) ; private readonly registeredFrom = new Map < ExtensionPoint , string > ( ) ; constructor ( private readonly logger ) { } add ( extension ) { if ( ! this . store . has ( extension . type ) ) { this . store . set ( extension . type , new Set ( ) ) ; } const extensionPointsForType = this . store . get ( extension . type ) ; if ( extensionPointsForType ) { extensionPointsForType . add ( extension ) ; const from = new Error ( 'REGISTERED FROM:' ) . stack ?? 'REGISTERED FROM: unknown' ; this . registeredFrom . set ( extension , from . substring ( from . indexOf ( 'REGISTERED FROM:' ) ) . concat ( '\n    ----------------------' ) ) ; } } clear ( ) { this . store . clear ( ) ; this . registeredFrom . clear ( ) ; } getExtensionRegistrationSource ( extensionPoint ) { return this . registeredFrom . get ( extensionPoint ) ; } get < T extends ExtensionPoint [ 'type' ] > ( extensionType ) { const extensionDefinitions = this . store . get ( extensionType ) ; if ( extensionDefinitions ) { return extensionDefinitions as Set < NarrowExtensionPointToType < T > > ; } return undefined ; } /**
     * returns a client interface that does not expose the full set of methods available in the storage
     */ getClient ( ) { return new ExtensionPointStorageClient ( this , this . logger ) ; } }