Skip to content

Commit 7d660fc

Browse files
committed
add broadcast and log object
1 parent 22845c8 commit 7d660fc

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@beekeeperstudio/plugin",
3-
"version": "1.4.0-beta.4",
3+
"version": "1.4.0-beta.5",
44
"description": "A simple TypeScript wrapper to send messages from your Beekeeper Studio plugin to the main app.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/comms.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const pendingRequests = new Map<
2929

3030
let debugComms = false;
3131

32-
export function setDebugComms(value: boolean) {
33-
debugComms = value;
32+
export function setDebugComms(enabled: boolean) {
33+
debugComms = enabled;
3434
}
3535

3636
window.addEventListener("message", (event) => {

src/index.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { request } from "./comms";
1+
import { JsonValue } from "./commonTypes";
2+
import { addNotificationListener, notify, request } from "./comms";
23
import type {
34
GetTablesRequest,
45
GetColumnsRequest,
@@ -213,7 +214,34 @@ export async function openTab(type: OpenTabRequest['args']['type'], args?: Omit<
213214
return await request({ name: "openTab", args: { type, ...args } });
214215
}
215216

216-
/** Clipboard interface. */
217+
/** @since Beekeeper Studio 5.4.0 */
218+
export const broadcast = {
219+
post<T extends JsonValue = JsonValue>(message: T) {
220+
return notify("broadcast", { message });
221+
},
222+
on<T extends JsonValue = JsonValue>(handler: (message: T) => void) {
223+
addNotificationListener<T>("broadcast", (params) => {
224+
handler(params.message);
225+
});
226+
},
227+
}
228+
229+
/** @since Beekeeper Studio 5.3.0 */
230+
export const log = {
231+
error(err: string | Error) {
232+
return notify("pluginError", {
233+
name: err.name || "Error",
234+
message: err.message || err,
235+
stack: err.stack,
236+
});
237+
},
238+
}
239+
240+
/**
241+
* Clipboard interface.
242+
*
243+
* @since Beekeeper Studio 5.3.0
244+
**/
217245
export const clipboard = {
218246
/** Write text to the Electron clipboard. */
219247
async writeText(text: string): Promise<void> {

src/responseTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface GetConnectionInfoResponse extends BaseResponse {
4040
result: {
4141
/** @deprecated Use `databaseType` instead */
4242
connectionType: string;
43-
databaseType: string;
43+
databaseType: 'postgresql' | 'mysql' | 'mariadb' | 'sqlite' | 'sqlserver' | 'oracle' | 'mongodb' | 'cassandra' | 'clickhouse' | 'firebird' | 'bigquery' | 'redshift' | 'duckdb' | 'libsql' | 'redis' | 'surrealdb' | 'trino';
4444
databaseTypeDisplayName: string;
4545
databaseName: string;
4646
defaultSchema?: string;

0 commit comments

Comments
 (0)