import { omit } from 'lodash' ; import { IUiSettingsClient , UiSettingsParams , PublicUiSettingsParams , UserProvidedValues , } from './types' ; import { Logger } from '../logging' ; export interface BaseUiSettingsDefaultsClientOptions { overrides ? : Record < string , any > ; defaults ? : Record < string , UiSettingsParams > ; log : Logger ; } /**
 * Base implementation of the  IUiSettingsClient .
  export abstract class BaseUiSettingsClient implements IUiSettingsClient { private readonly defaults : NonNullable < BaseUiSettingsDefaultsClientOptions [ 'defaults' ] > ; private readonly defaultValues : Record < string , unknown > ; protected readonly overrides : NonNullable < BaseUiSettingsDefaultsClientOptions [ 'overrides' ] > ; protected readonly log : Logger ; protected constructor ( options ) { const { defaults = { } , overrides = { } , log } = options ; this . log = log ; this . overrides = overrides ; this . defaults = defaults ; this . defaultValues = Object . fromEntries ( Object . entries ( this . defaults ) . map ( ( [ key , { value } ] ) => [ key , value ] ) ) ; } getRegistered ( ) { const copiedDefaults = { } ; for ( const [ key , value ] of Object . entries ( this . defaults ) ) { copiedDefaults [ key ] = omit ( value , 'schema' ) ; } return copiedDefaults ; } async get < T = any > ( key ) { const all = await this . getAll ( ) ; return all [ key ] as T ; } async getAll < T = any > ( ) { const result = { ... this . defaultValues } ; const userProvided = await this . getUserProvided ( ) ; Object . keys ( userProvided ) . forEach ( ( key ) => { if ( userProvided [ key ] . userValue !== undefined ) { result [ key ] = userProvided [ key ] . userValue ; } } ) ; return Object . freeze ( result ) as Record < string , T > ; } isOverridden ( key ) { return this . overrides . hasOwnProperty ( key ) ; } isSensitive ( key ) { const definition = this . defaults [ key ] ; return ! ! definition ?. sensitive ; } protected validateKey ( key , value ) { const definition = this . defaults [ key ] ; if ( value === null || definition === undefined ) return ; if ( definition . schema ) { definition . schema . validate ( value , { } , `validation [${ key }]` ) ; } } abstract getUserProvided < T = any > ( ) ; abstract setMany ( changes ) ; abstract set ( key , value ) ; abstract remove ( key ) ; abstract removeMany ( keys ) ; }