-
Notifications
You must be signed in to change notification settings - Fork 1k
Export correct types for RequestHandlerContext.dataSource
for plugins
#6045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@joshuali925 are you looking for export that interface here?
@Flyingliuhub @BionIT would you confirm with @joshuali925 and work with team to help plugin teams |
@seraphjiang yes, or would be better to make declare module '../../../src/core/server' {
interface RequestHandlerContext {
dataSource: DataSourcePluginRequestContext;
}
} doesn't need to be added and maintained manually by each plugin |
@zhyuanqi would you help this |
Hi @joshuali925, since data source plugin is also a plugin which does not exist in src/core, core plugins can consume the merged declaration to consume data source context interface, while external plugins can not. We suggest each external plugin to use the following to consume the type, and in the PR, we have exported the DataSourcePluginRequestContext at top level and I saw that search relevance plugin uses the following as well to declare merge, and the change only involves adding data source with import from data source server path. Hope it makes sense.
|
Is your feature request related to a problem? Please describe.
currently in plugins when we do
context.dataSource
in route handler, typescript complainsProperty '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
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 exportthis 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
The text was updated successfully, but these errors were encountered: