Conversation
|
This is exactly what I had in mind. It makes it incredibly easy to plug in features quickly that integrate directly with the data source. I was able to create this example in a minutes time to test it and verify that a My first thought would be for us to remove the Some superb work here 👏 |
|
Great to hear! What are your thoughts on making the plugins workspace packages? If we add tests and things it may make it easier to manage, or publish them as external packages etc? |
For clarity, are you imagining the folder structure being the the following but still kept within this /plugins |
|
Yes, there's a couple like that already in my branch, but they're not packages, just separate directories with the code in them |
I'm perfectly content with them becoming packages. That's how the current Would love to get your idea of the 🚀 |
Purpose
This is a PR primarily designed to discuss Starbase plugins.
At it's core, the main purpose of Starbase is to query a database, whether that be a DO or external one. Other functionality such as studio, import/export, websockets etc are additional functionality. Currently it's possible to disable/enable this functionality through feature flags... but it's not possible to extend Starbase. Plugins breakout this functionality and allow users to extend Starbase how they see fit.
This PR proposes being able to do the following:
The signature for a function is currently:
If implemented, the
registermethod of a plugin will be called early on in the lifecycle, whereappis the Hono app instance - this allows users to add routes, apply middleware etc as they normally would.This PR also passes the
dataSourceandconfiginto Hono context, allowing plugins to access (or modify) this. Plugins are applied in-order and have an async register API.Later on, it may make sense to pass this context (
StarbaseContext) around everywhere, rather than dealing with individual function arguments - but one for later.Other plugins can be created easily (assuming this api is ok) for import, export, litrest, cors, etc.
## Other use-cases
### Auth
There is currently a manual auth template which users would be expected to bind to the worker and call themselves. This could be instead extracted out into a plugin:
Hooks
In this PR there is a
StarbasePluginRegistryclass. The idea here is that we could export useful methods to allow plugin authors to subscribe to events, e.g.By having a registry, we could simply call
registry.onBeforeQuery(args)where needed, and internally it'd call every pluginsonBeforeQuerymethod.