-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Plugin System Documentation #3240
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the docs need a bit of a reorganize, and also need expanding on a little.
Long term I want you to think about using actual methods, vs a generic request
method.
|
||
## Plugin Types | ||
|
||
### Tab Plugins (Shell Type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some other plugin types that you've planned, but are 'coming soon'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who are plugins available to? Make this clear both here and in the user docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A basic 'how plugins work' here is helpful, say stuff like:
Plugin installation is handled natively by the Beekeeper Studio application, community plugins are published on the Beekeeper Studio community plugin repository (link)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need a version of this for the user docs too, with screenshots
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some other plugin types that you've planned, but are 'coming soon'?
Only sidebar plugins currently (beside json sidebar). But before that, we probably want to have sidebar tabs that can be dragged around. For example, JSON Viewer can be moved to the global sidebar and vice versa with mouse drag. Not sure, would love to discuss about that.
!!! warning "Beta Feature" | ||
The plugin system is currently in beta. APIs and functionality may change in future releases. Please provide feedback and report issues to help us improve the system. | ||
|
||
The Beekeeper Studio Plugin System allows developers to extend the application's functionality through web-based plugins. Plugins run in secure, sandboxed environments and communicate with the main application through a structured API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a screenshot
@@ -109,6 +109,11 @@ nav: | |||
- user_guide/backup-restore.md | |||
- Cloud Sync: user_guide/cloud-storage-team-workspaces.md | |||
- user_guide/privacy-mode.md | |||
- Plugin Development: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a 'Plugins' page in the user guide for users of plugins, detailing what they are, who they're available to, and how to install them
|
||
## Getting Started | ||
|
||
### For Users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a separate page in the user guide
import { getTables, runQuery, setTabTitle } from '@beekeeperstudio/plugin'; | ||
``` | ||
|
||
### Key Components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these key components for the developer? Not really.
I'd have this be plugin lifecycle
and say stuff like:
- Install the beekeeper plugin API
- Create your plugin
- Push to your own repository
- Publish a build on GitHub
- Submit a PR to the Beekeeper Studio community plugins repository
Install the plugin package from GitHub: | ||
|
||
```bash | ||
npm install github:beekeeper-studio/plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have an NPM package for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add them today or next week.
import { request, notify, addNotificationListener } from '@beekeeperstudio/plugin'; | ||
``` | ||
|
||
## How It Works |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the example plugin (the one you have screenshots of) link here, so folks can look at the real code?
|
||
The plugin API consists of three main functions: | ||
|
||
### `request(name, args?)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why implement these like bks.request('getTables')
rather than bks.getTables()
? The second way means that for each method we can add details JSDocs and then publish those as the reference using TypeDoc or JSDoc binaries.
No? Is there some advantage to this system that I'm missing?
To be clear: I'm fine with this for now, but seems like a lot more work to maintain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request
is a very thin wrapper of window.parent.postMessage()
. Basically it is this:
export async function request(name, args) {
return new Promise((resolve, reject) => {
const id = generateUUID();
const data = { id, name, args };
pendingRequests.set(id, { name, resolve, reject });
window.parent.postMessage(data, "*");
});
}
It's the very basic function for communicating that can't be replaced. In Beekeeper Studio, it is like this.$util.send
.
I think we could add JSDocs to request function too right? the request function is typed. We could then add JSDocs this way:
/** jsdocs here */
export async function request(name: "getTables", args?: GetTablesRequest["args"]): Promise<GetTablesResponse>;
/** jsdocs here */
export async function request(name: "getColumns", args: GetColumnsRequest["args"]): Promise<GetColumnsResponse>;
/** jsdocs here */
export async function request(name: "getConnectionInfo"): Promise<GetConnectionInfoResponse>;
I'd be down to do bks.getTables
too if it's better. It's gonna be a wrapper of the request
function.
The plugin API consists of three main functions: | ||
|
||
### `request(name, args?)` | ||
Send requests to Beekeeper Studio to retrieve data or execute actions. Internally uses `window.parent.postMessage()` with a unique ID and waits for a response. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are errors handled with request functions? What if malformed request is sent? How should the user debug?
Are there error classes or codes they should pay attention to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add those to the docs.
If you call request
and there is an error, it will just throw an error.
When error happens, it usually happens in the plugin system, so the plugin system will respond with an object that goes { error: "Error message here" }
.
We don't have custom classes for errors yet. I just used simple Error
class with a message text.
Also, you can debug the messages by calling setDebugComms(true)
which will log the three main functions.
### `request(name, args?)` | ||
Send requests to Beekeeper Studio to retrieve data or execute actions. Internally uses `window.parent.postMessage()` with a unique ID and waits for a response. | ||
|
||
### `notify(name, args)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this return when the notification is successful / unsuccessful? What errors can be thrown here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the communication module was inspired by LSP which basically has two ways of communications:
- Request/Response: If a plugin requests something, it expects something in return
- Notification: If the plugin system notifies the plugin, it does not expect a return
An example to notification is switchTheme
: when user chooses a theme, the plugin system notifies all plugins (without expecting an answer from all plugin) with switchTheme
.
But good questions though, will make the docs clearer.
@azmy60 some changes requested here before we merge |
No description provided.