Description
Is your feature request related to a problem? Please describe.
currently in plugins when we do context.dataSource
in route handler, typescript complains Property 'dataSource' does not exist on type 'RequestHandlerContext'.
, and it's hard for developers to know the schema of available methods under it.
Describe the solution you'd like
Core to provide types correctly for RequestHandlerContext
Describe alternatives you've considered
I'm aware that plugins can add
declare module '../../../src/core/server' {
interface RequestHandlerContext {
dataSource: DataSourcePluginRequestContext;
}
}
But this is unreliable and duplicate work for all plugins, especially because plugins have to also add DataSourcePluginRequestContext
definition since it's not a top level export
export interface DataSourcePluginRequestContext {
opensearch: {
getClient: (dataSourceId: string) => Promise<OpenSearchClient>;
legacy: {
getClient: (
dataSourceId: string
) => {
callAPI: (
endpoint: string,
clientParams: Record<string, any>,
options?: LegacyCallAPIOptions
) => Promise<unknown>;
};
};
};
}
this can cause issues if upstream API changes and types become inconsistent. For something like dataSource
that should be universal rather than plugin specific, can this be made available to plugins in core?
Additional context
somewhat related #4274