Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .cursor/worktrees.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"setup-worktree": ["pnpm install", "pnpm run build"]
"setup-worktree": [
"pnpm install",
"pnpm run build",
"cp $ROOT_WORKTREE_PATH/apps/dev-playground/.env apps/dev-playground/.env",
"cp $ROOT_WORKTREE_PATH/apps/clean-app/.env apps/clean-app/.env"
]
}
7 changes: 2 additions & 5 deletions apps/dev-playground/server/lakebase-examples-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as typeormExample from "./lakebase-examples/typeorm-example";
*/

export class LakebaseExamplesPlugin extends Plugin {
static override readonly name = "lakebase-examples";
public name = "lakebase-examples";
protected envVars: string[] = [];

Expand Down Expand Up @@ -80,8 +81,4 @@ export class LakebaseExamplesPlugin extends Plugin {
}
}

export const lakebaseExamples = toPlugin<
typeof LakebaseExamplesPlugin,
Record<string, never>,
"lakebase-examples"
>(LakebaseExamplesPlugin, "lakebase-examples");
export const lakebaseExamples = toPlugin(LakebaseExamplesPlugin);
7 changes: 2 additions & 5 deletions apps/dev-playground/server/reconnect-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface ReconnectStreamResponse {
}

export class ReconnectPlugin extends Plugin {
static override readonly name = "reconnect";
public name = "reconnect";

static manifest = {
Expand Down Expand Up @@ -84,8 +85,4 @@ export class ReconnectPlugin extends Plugin {
}
}

export const reconnect = toPlugin<
typeof ReconnectPlugin,
Record<string, never>,
"reconnect"
>(ReconnectPlugin, "reconnect");
export const reconnect = toPlugin(ReconnectPlugin);
7 changes: 2 additions & 5 deletions apps/dev-playground/server/telemetry-example-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import type { Request, Response, Router } from "express";

class TelemetryExamples extends Plugin {
static override readonly name = "telemetry-examples";
public name = "telemetry-examples" as const;

static manifest = {
Expand Down Expand Up @@ -522,8 +523,4 @@ class TelemetryExamples extends Plugin {
}
}

export const telemetryExamples = toPlugin<
typeof TelemetryExamples,
BasePluginConfig,
"telemetryExamples"
>(TelemetryExamples, "telemetryExamples");
export const telemetryExamples = toPlugin(TelemetryExamples);
18 changes: 11 additions & 7 deletions packages/appkit/src/plugin/to-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import type { PluginData, ToPlugin } from "shared";
import type { PluginConstructor, PluginData, ToPlugin } from "shared";

/**
* Wraps a plugin class so it can be passed to createApp with optional config.
* Infers config type from the constructor and plugin name from the static `name` property.
*
* @internal
*/
export function toPlugin<T, U, N extends string>(
export function toPlugin<T extends PluginConstructor & { name: string }>(
plugin: T,
name: N,
): ToPlugin<T, U, N> {
return (config: U = {} as U): PluginData<T, U, N> => ({
): ToPlugin<T, ConstructorParameters<T>[0], T["name"]> {
type Config = ConstructorParameters<T>[0];
type Name = T["name"];
return (config: Config = {} as Config): PluginData<T, Config, Name> => ({
plugin: plugin as T,
config: config as U,
name,
config: config as Config,
name: plugin.name as Name,
});
}
7 changes: 2 additions & 5 deletions packages/appkit/src/plugins/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
const logger = createLogger("analytics");

export class AnalyticsPlugin extends Plugin {
static override readonly name = "analytics";
name = "analytics";

/** Plugin manifest declaring metadata and resource requirements */
Expand Down Expand Up @@ -285,8 +286,4 @@ export class AnalyticsPlugin extends Plugin {
/**
* @internal
*/
export const analytics = toPlugin<
typeof AnalyticsPlugin,
IAnalyticsConfig,
"analytics"
>(AnalyticsPlugin, "analytics");
export const analytics = toPlugin(AnalyticsPlugin);
6 changes: 2 additions & 4 deletions packages/appkit/src/plugins/genie/genie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
const logger = createLogger("genie");

export class GeniePlugin extends Plugin {
static override readonly name = "genie";
name = "genie";

static manifest = genieManifest;
Expand Down Expand Up @@ -230,7 +231,4 @@ export class GeniePlugin extends Plugin {
/**
* @internal
*/
export const genie = toPlugin<typeof GeniePlugin, IGenieConfig, "genie">(
GeniePlugin,
"genie",
);
export const genie = toPlugin(GeniePlugin);
7 changes: 2 additions & 5 deletions packages/appkit/src/plugins/lakebase/lakebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const logger = createLogger("lakebase");
* ```
*/
export class LakebasePlugin extends Plugin {
static override readonly name = "lakebase";
name = "lakebase";

/** Plugin manifest declaring metadata and resource requirements */
Expand Down Expand Up @@ -117,8 +118,4 @@ export class LakebasePlugin extends Plugin {
/**
* @internal
*/
export const lakebase = toPlugin<
typeof LakebasePlugin,
ILakebaseConfig,
"lakebase"
>(LakebasePlugin, "lakebase");
export const lakebase = toPlugin(LakebasePlugin);
6 changes: 2 additions & 4 deletions packages/appkit/src/plugins/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class ServerPlugin extends Plugin {
/** Plugin manifest declaring metadata and resource requirements */
static manifest = serverManifest;

static override readonly name = "server";
public name = "server" as const;
private serverApplication: express.Application;
private server: HTTPServer | null;
Expand Down Expand Up @@ -354,10 +355,7 @@ const EXCLUDED_PLUGINS = [ServerPlugin.name];
/**
* @internal
*/
export const server = toPlugin<typeof ServerPlugin, ServerConfig, "server">(
ServerPlugin,
"server",
);
export const server = toPlugin(ServerPlugin);

// Export manifest and types
export { serverManifest } from "./manifest";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe("ServerPlugin with custom plugin", () => {

// Create a simple test plugin
class TestPlugin extends Plugin {
static override readonly name = "test-plugin";
static manifest = {
name: "test-plugin",
displayName: "Test Plugin",
Expand All @@ -117,10 +118,7 @@ describe("ServerPlugin with custom plugin", () => {
}
}

const testPlugin = toPlugin<typeof TestPlugin, any, "test-plugin">(
TestPlugin,
"test-plugin",
);
const testPlugin = toPlugin(TestPlugin);

const app = await createApp({
plugins: [
Expand Down
11 changes: 5 additions & 6 deletions packages/shared/src/cli/commands/plugin/create/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ export const manifest = JSON.parse(
const pluginTs = `import { Plugin, toPlugin, type IAppRouter } from "@databricks/appkit";
import { manifest } from "./manifest.js";

export { manifest };

export class ${className} extends Plugin {
static override readonly name = "${answers.name}";
name = "${answers.name}";

static manifest = manifest;
Expand All @@ -150,16 +153,12 @@ export class ${className} extends Plugin {
}
}

export const ${exportName} = toPlugin<
typeof ${className},
Record<string, never>,
"${answers.name}"
>(${className}, "${answers.name}");
export const ${exportName} = toPlugin(${className});
`;

writeTracked(path.join(targetDir, `${answers.name}.ts`), pluginTs, written);

const indexTs = `export { ${className}, ${exportName} } from "./${answers.name}.js";
const indexTs = `export { ${className}, ${exportName}, manifest } from "./${answers.name}.js";
`;

writeTracked(path.join(targetDir, "index.ts"), indexTs, written);
Expand Down