Skip to content

Commit bd52e76

Browse files
committed
refactor: remove pluginRegistry for now (will be attacked on another pr)
1 parent 5bd8189 commit bd52e76

File tree

17 files changed

+10
-843
lines changed

17 files changed

+10
-843
lines changed

apps/dev-playground/client/src/appKitTypes.d.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,6 @@
33
import "@databricks/app-kit-ui/react";
44

55
declare module "@databricks/app-kit-ui/react" {
6-
interface PluginRegistry {
7-
"analytics": {
8-
"/users/me/query/:query_key": {
9-
chunk_index: number
10-
row_offset: number
11-
row_count: number
12-
data: any[]
13-
};
14-
"/query/:query_key": {
15-
chunk_index: number
16-
row_offset: number
17-
row_count: number
18-
data: any[]
19-
};
20-
};
21-
"reconnect": {
22-
"/": {
23-
message: string
24-
};
25-
"/stream": {
26-
type: number
27-
count: number
28-
total: number
29-
timestamp: string
30-
content: string
31-
};
32-
};
33-
}
346
interface QueryRegistry {
357
apps_list: {
368
name: "apps_list";

packages/app-kit-ui/src/react/hooks/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ export type {
66
} from "./types";
77
export { useAnalyticsQuery } from "./use-analytics-query";
88
export { useChartData } from "./use-chart-data";
9-
export { useCustomPlugin } from "./use-custom-plugin";

packages/app-kit-ui/src/react/hooks/types.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,3 @@ export type InferParams<K> = K extends AugmentedRegistry<QueryRegistry>
7777
export interface PluginRegistry {
7878
[key: string]: Record<string, any>;
7979
}
80-
81-
export type PluginName = AugmentedRegistry<PluginRegistry> extends never
82-
? string
83-
: AugmentedRegistry<PluginRegistry>;
84-
85-
export type PluginRoutes<P extends PluginName> =
86-
P extends AugmentedRegistry<PluginRegistry>
87-
? AugmentedRegistry<PluginRegistry[P]>
88-
: string;
89-
90-
export type RouteResponse<
91-
P extends PluginName,
92-
R extends PluginRoutes<P>,
93-
> = P extends keyof PluginRegistry
94-
? R extends keyof PluginRegistry[P]
95-
? PluginRegistry[P][R]
96-
: unknown
97-
: unknown;

packages/app-kit-ui/src/react/hooks/use-custom-plugin.ts

Lines changed: 0 additions & 88 deletions
This file was deleted.

packages/app-kit/bin/generate-types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const rootDir = positionalArgs[0] || process.cwd();
1212
const outFile =
1313
positionalArgs[1] || path.join(process.cwd(), "client/src/appKitTypes.d.ts");
1414

15-
const pluginEntryPoint = path.join(rootDir, "server/index.ts");
1615
const queryFolder = path.join(rootDir, "config/queries");
1716

1817
const warehouseId = positionalArgs[2] || process.env.DATABRICKS_WAREHOUSE_ID;
@@ -21,7 +20,6 @@ if (!warehouseId) {
2120
}
2221

2322
await generateFromEntryPoint({
24-
pluginEntryPoint,
2523
queryFolder,
2624
outFile,
2725
warehouseId,

packages/app-kit/src/server/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { PluginPhase } from "shared";
77
import { Plugin, toPlugin } from "../plugin";
88
import { instrumentations } from "../telemetry";
99
import { databricksClientMiddleware, isRemoteServerEnabled } from "../utils";
10-
import { generatePluginRegistryTypes } from "../utils/type-generator";
1110
import { DevModeManager } from "./dev-mode";
1211
import type { ServerConfig } from "./types";
1312
import { getQueries, getRoutes } from "./utils";

packages/app-kit/src/type-generator/index.ts

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,16 @@
11
import fs from "node:fs";
2-
import path from "node:path";
32
import dotenv from "dotenv";
4-
import ts from "typescript";
5-
import {
6-
extractRoutesFromFile,
7-
findPluginFiles,
8-
getAllImportedFiles,
9-
type PluginRoutes,
10-
} from "./plugin-registry";
113
import { generateQueriesFromExplain, type QuerySchema } from "./query-registry";
124

135
dotenv.config();
146

157
/**
16-
* Generate type declarations for PluginRegistry and QueryRegistry
8+
* Generate type declarations for QueryRegistry
179
* Create the d.ts file from the plugin routes and query schemas
18-
* @param plugins - the list of plugin routes
1910
* @param querySchemas - the list of query schemas
2011
* @returns - the type declarations as a string
2112
*/
22-
function generateTypeDeclarations(
23-
plugins: PluginRoutes[],
24-
querySchemas: QuerySchema[] = [],
25-
): string {
26-
const registryEntries = plugins
27-
.map(({ pluginName, routes }) => {
28-
const routeEntries = routes
29-
.map(({ path, responseType }) => {
30-
const indentedType = responseType
31-
.split("\n")
32-
.map((line, i) => (i === 0 ? line : ` ${line}`))
33-
.join("\n");
34-
return ` "${path}": ${indentedType}`;
35-
})
36-
.join(";\n");
37-
38-
return ` "${pluginName}": {\n${routeEntries};\n }`;
39-
})
40-
.join(";\n");
41-
13+
function generateTypeDeclarations(querySchemas: QuerySchema[] = []): string {
4214
const queryEntries = querySchemas
4315
.map(({ name, type }) => {
4416
const indentedType = type
@@ -56,9 +28,6 @@ function generateTypeDeclarations(
5628
import "@databricks/app-kit-ui/react";
5729
5830
declare module "@databricks/app-kit-ui/react" {
59-
interface PluginRegistry {
60-
${registryEntries};
61-
}
6231
interface QueryRegistry {${querySection}}
6332
}
6433
`;
@@ -72,61 +41,22 @@ ${registryEntries};
7241
* @param options.querySchemaFile - optional path to query schema file (e.g. config/queries/schema.ts)
7342
*/
7443
export async function generateFromEntryPoint(options: {
75-
pluginEntryPoint: string;
7644
outFile: string;
7745
queryFolder?: string;
7846
warehouseId: string;
7947
noCache?: boolean;
8048
}) {
81-
const { pluginEntryPoint, outFile, queryFolder, warehouseId, noCache } =
82-
options;
49+
const { outFile, queryFolder, warehouseId, noCache } = options;
8350

8451
console.log("\n[AppKit] Starting type generation...\n");
8552

86-
const allFiles = getAllImportedFiles(pluginEntryPoint);
87-
88-
const configPath = ts.findConfigFile(
89-
path.dirname(pluginEntryPoint),
90-
ts.sys.fileExists,
91-
"tsconfig.json",
92-
);
93-
94-
const configFile = configPath
95-
? ts.readConfigFile(configPath, ts.sys.readFile)
96-
: { config: {} };
97-
98-
const parsedConfig = ts.parseJsonConfigFileContent(
99-
configFile.config,
100-
ts.sys,
101-
path.dirname(configPath || pluginEntryPoint),
102-
);
103-
104-
const program = ts.createProgram(allFiles, {
105-
...parsedConfig.options,
106-
noEmit: true,
107-
});
108-
109-
const pluginFiles = findPluginFiles(allFiles, program);
110-
111-
const allPluginRoutes: PluginRoutes[] = [];
112-
113-
for (const pluginFile of pluginFiles) {
114-
const routes = extractRoutesFromFile(pluginFile, program);
115-
if (routes) {
116-
allPluginRoutes.push(routes);
117-
}
118-
}
119-
12053
let queryRegistry: QuerySchema[] = [];
12154
if (queryFolder)
12255
queryRegistry = await generateQueriesFromExplain(queryFolder, warehouseId, {
12356
noCache,
12457
});
12558

126-
const typeDeclarations = generateTypeDeclarations(
127-
allPluginRoutes,
128-
queryRegistry,
129-
);
59+
const typeDeclarations = generateTypeDeclarations(queryRegistry);
13060

13161
fs.writeFileSync(outFile, typeDeclarations, "utf-8");
13262

0 commit comments

Comments
 (0)