Skip to content

Commit 44eaec8

Browse files
authored
refactor: toPlugin api (#133)
1 parent 43c5f94 commit 44eaec8

26 files changed

Lines changed: 118 additions & 112 deletions

apps/dev-playground/server/lakebase-examples-plugin.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { getUsernameWithApiLookup, Plugin, toPlugin } from "@databricks/appkit";
1+
import {
2+
getUsernameWithApiLookup,
3+
Plugin,
4+
type PluginManifest,
5+
toPlugin,
6+
} from "@databricks/appkit";
27
import type { IAppRouter } from "shared";
38
import * as drizzleExample from "./lakebase-examples/drizzle-example";
49
import * as rawExample from "./lakebase-examples/raw-driver-example";
@@ -19,7 +24,6 @@ import * as typeormExample from "./lakebase-examples/typeorm-example";
1924
*/
2025

2126
export class LakebaseExamplesPlugin extends Plugin {
22-
public name = "lakebase-examples";
2327
protected envVars: string[] = [];
2428

2529
static manifest = {
@@ -30,7 +34,7 @@ export class LakebaseExamplesPlugin extends Plugin {
3034
required: [],
3135
optional: [],
3236
},
33-
};
37+
} satisfies PluginManifest<"lakebase-examples">;
3438

3539
async setup() {
3640
// Check if Lakebase is configured
@@ -80,8 +84,4 @@ export class LakebaseExamplesPlugin extends Plugin {
8084
}
8185
}
8286

83-
export const lakebaseExamples = toPlugin<
84-
typeof LakebaseExamplesPlugin,
85-
Record<string, never>,
86-
"lakebase-examples"
87-
>(LakebaseExamplesPlugin, "lakebase-examples");
87+
export const lakebaseExamples = toPlugin(LakebaseExamplesPlugin);

apps/dev-playground/server/reconnect-plugin.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin, toPlugin } from "@databricks/appkit";
1+
import { Plugin, type PluginManifest, toPlugin } from "@databricks/appkit";
22
import type { IAppRouter, StreamExecutionSettings } from "shared";
33

44
interface ReconnectResponse {
@@ -14,8 +14,6 @@ interface ReconnectStreamResponse {
1414
}
1515

1616
export class ReconnectPlugin extends Plugin {
17-
public name = "reconnect";
18-
1917
static manifest = {
2018
name: "reconnect",
2119
displayName: "Reconnect Plugin",
@@ -24,7 +22,7 @@ export class ReconnectPlugin extends Plugin {
2422
required: [],
2523
optional: [],
2624
},
27-
};
25+
} satisfies PluginManifest<"reconnect">;
2826

2927
injectRoutes(router: IAppRouter): void {
3028
this.route<ReconnectResponse>(router, {
@@ -84,8 +82,4 @@ export class ReconnectPlugin extends Plugin {
8482
}
8583
}
8684

87-
export const reconnect = toPlugin<
88-
typeof ReconnectPlugin,
89-
Record<string, never>,
90-
"reconnect"
91-
>(ReconnectPlugin, "reconnect");
85+
export const reconnect = toPlugin(ReconnectPlugin);

apps/dev-playground/server/telemetry-example-plugin.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type Counter,
99
type Histogram,
1010
Plugin,
11+
type PluginManifest,
1112
SeverityNumber,
1213
type Span,
1314
SpanStatusCode,
@@ -16,8 +17,6 @@ import {
1617
import type { Request, Response, Router } from "express";
1718

1819
class TelemetryExamples extends Plugin {
19-
public name = "telemetry-examples" as const;
20-
2120
static manifest = {
2221
name: "telemetry-examples",
2322
displayName: "Telemetry Examples Plugin",
@@ -26,7 +25,7 @@ class TelemetryExamples extends Plugin {
2625
required: [],
2726
optional: [],
2827
},
29-
};
28+
} satisfies PluginManifest<"telemetry-examples">;
3029

3130
private requestCounter: Counter;
3231
private durationHistogram: Histogram;
@@ -522,8 +521,4 @@ class TelemetryExamples extends Plugin {
522521
}
523522
}
524523

525-
export const telemetryExamples = toPlugin<
526-
typeof TelemetryExamples,
527-
BasePluginConfig,
528-
"telemetryExamples"
529-
>(TelemetryExamples, "telemetryExamples");
524+
export const telemetryExamples = toPlugin(TelemetryExamples);

apps/dev-playground/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"compilerOptions": {
44
"baseUrl": ".",
55
"outDir": "./build",
6+
"declaration": false,
7+
"declarationMap": false,
68
"experimentalDecorators": true,
79
"emitDecoratorMetadata": true
810
},

docs/docs/api/appkit/Class.Plugin.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const myManifest: PluginManifest = {
3535

3636
class MyPlugin extends Plugin<MyConfig> {
3737
static manifest = myManifest;
38-
name = 'myPlugin';
3938
}
4039
```
4140

@@ -58,8 +57,7 @@ const myManifest: PluginManifest = {
5857
};
5958

6059
class MyPlugin extends Plugin<MyConfig> {
61-
static manifest = myManifest;
62-
name = 'myPlugin';
60+
static manifest = myManifest<"myPlugin">;
6361

6462
// Runtime method: converts optional resources to required based on config
6563
static getResourceRequirements(config: MyConfig) {
@@ -327,7 +325,6 @@ and adds `asUser(req)` for user-scoped execution.
327325

328326
```ts
329327
class MyPlugin extends Plugin {
330-
name = "myPlugin";
331328
private getData() { return []; }
332329

333330
exports() {

docs/docs/api/appkit/Class.ResourceRegistry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ For each plugin, loads its manifest (required) and runtime resource requirements
4545

4646
| Parameter | Type | Description |
4747
| ------ | ------ | ------ |
48-
| `rawPlugins` | `PluginData`\<`PluginConstructor`, `unknown`, `string`\>[] | Array of plugin data entries from createApp configuration |
48+
| `rawPlugins` | [`PluginData`](TypeAlias.PluginData.md)\<`PluginConstructor`, `unknown`, `string`\>[] | Array of plugin data entries from createApp configuration |
4949

5050
#### Returns
5151

docs/docs/api/appkit/Function.createApp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ with an `asUser(req)` method for user-scoped execution.
2020

2121
| Type Parameter |
2222
| ------ |
23-
| `T` *extends* `PluginData`\<`PluginConstructor`, `unknown`, `string`\>[] |
23+
| `T` *extends* [`PluginData`](TypeAlias.PluginData.md)\<`PluginConstructor`, `unknown`, `string`\>[] |
2424

2525
## Parameters
2626

docs/docs/api/appkit/Interface.PluginManifest.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
# Interface: PluginManifest
1+
# Interface: PluginManifest\<TName\>
22

33
Plugin manifest that declares metadata and resource requirements.
44
Attached to plugin classes as a static property.
55

6+
## Type Parameters
7+
8+
| Type Parameter | Default type |
9+
| ------ | ------ |
10+
| `TName` *extends* `string` | `string` |
11+
612
## Properties
713

814
### author?
@@ -83,10 +89,10 @@ optional license: string;
8389
### name
8490

8591
```ts
86-
name: string;
92+
name: TName;
8793
```
8894

89-
Plugin identifier (matches plugin.name)
95+
Plugin identifier — the single source of truth for the plugin's name
9096

9197
***
9298

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Type Alias: PluginData\<T, U, N\>
2+
3+
```ts
4+
type PluginData<T, U, N> = {
5+
config: U;
6+
name: N;
7+
plugin: T;
8+
};
9+
```
10+
11+
## Type Parameters
12+
13+
| Type Parameter |
14+
| ------ |
15+
| `T` |
16+
| `U` |
17+
| `N` |
18+
19+
## Properties
20+
21+
### config
22+
23+
```ts
24+
config: U;
25+
```
26+
27+
***
28+
29+
### name
30+
31+
```ts
32+
name: N;
33+
```
34+
35+
***
36+
37+
### plugin
38+
39+
```ts
40+
plugin: T;
41+
```

docs/docs/api/appkit/TypeAlias.ToPlugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ type ToPlugin<T, U, N> = (config?: U) => PluginData<T, U, N>;
2020

2121
## Returns
2222

23-
`PluginData`\<`T`, `U`, `N`\>
23+
[`PluginData`](TypeAlias.PluginData.md)\<`T`, `U`, `N`\>

0 commit comments

Comments
 (0)