import { InternalCoreStart } from './internal_types' ; import { OpenSearchDashboardsRequest } from './http/router' ; import { SavedObjectsClientContract } from './saved_objects/types' ; import { InternalSavedObjectsServiceStart , ISavedObjectTypeRegistry } from './saved_objects' ; import { InternalOpenSearchServiceStart , IScopedClusterClient , LegacyScopedClusterClient , } from './opensearch' ; import { Auditor } from './audit_trail' ; import { InternalUiSettingsServiceStart , IUiSettingsClient } from './ui_settings' ; class CoreOpenSearchRouteHandlerContext { #client ? : IScopedClusterClient ; #legacy ? : { client : Pick < LegacyScopedClusterClient , 'callAsInternalUser' | 'callAsCurrentUser' > ; } ; constructor ( private readonly opensearchStart , private readonly request ) { } public get client ( ) { if ( this . #client == null ) { this . #client = this . opensearchStart . client . asScoped ( this . request ) ; } return this . #client ; } public get legacy ( ) { if ( this . #legacy == null ) { this . #legacy = { client : this . opensearchStart . legacy . client . asScoped ( this . request ) , } ; } return this . #legacy ; } } class CoreSavedObjectsRouteHandlerContext { constructor ( private readonly savedObjectsStart , private readonly request ) { } #scopedSavedObjectsClient ? : SavedObjectsClientContract ; #typeRegistry ? : ISavedObjectTypeRegistry ; public get client ( ) { if ( this . #scopedSavedObjectsClient == null ) { this . #scopedSavedObjectsClient = this . savedObjectsStart . getScopedClient ( this . request ) ; } return this . #scopedSavedObjectsClient ; } public get typeRegistry ( ) { if ( this . #typeRegistry == null ) { this . #typeRegistry = this . savedObjectsStart . getTypeRegistry ( ) ; } return this . #typeRegistry ; } } class CoreUiSettingsRouteHandlerContext { #client ? : IUiSettingsClient ; constructor ( private readonly uiSettingsStart , private readonly savedObjectsRouterHandlerContext ) { } public get client ( ) { if ( this . #client == null ) { this . #client = this . uiSettingsStart . asScopedToClient ( this . savedObjectsRouterHandlerContext . client ) ; } return this . #client ; } } export class CoreRouteHandlerContext { #auditor ? : Auditor ; readonly opensearch : CoreOpenSearchRouteHandlerContext ; readonly savedObjects : CoreSavedObjectsRouteHandlerContext ; readonly uiSettings : CoreUiSettingsRouteHandlerContext ; constructor ( private readonly coreStart , private readonly request ) { this . opensearch = new CoreOpenSearchRouteHandlerContext ( this . coreStart . opensearch , this . request ) ; this . savedObjects = new CoreSavedObjectsRouteHandlerContext ( this . coreStart . savedObjects , this . request ) ; this . uiSettings = new CoreUiSettingsRouteHandlerContext ( this . coreStart . uiSettings , this . savedObjects ) ; } public get auditor ( ) { if ( this . #auditor == null ) { this . #auditor = this . coreStart . auditTrail . asScoped ( this . request ) ; } return this . #auditor ; } }