Skip to content
Merged
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
1 change: 1 addition & 0 deletions knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"packages/appkit": {
"ignoreDependencies": [
"vitest",
"@databricks/sdk-apps",
"@databricks/sdk-auth",
"@databricks/sdk-core",
"@databricks/sdk-experimental",
Expand Down
1 change: 1 addition & 0 deletions packages/appkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"dependencies": {
"@ast-grep/napi": "0.37.0",
"@databricks/lakebase": "workspace:*",
"@databricks/sdk-apps": "0.54.0",
"@databricks/sdk-auth": "0.51.0",
"@databricks/sdk-core": "0.51.0",
"@databricks/sdk-experimental": "0.17.0",
Expand Down
1 change: 1 addition & 0 deletions packages/appkit/src/testing/mock-workspace-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const FACADE_SERVICES = [
"warehouses",
"genie",
"database",
"apps",
"jobs",
"experiments",
"vectorSearch",
Expand Down
1 change: 1 addition & 0 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"dependencies": {
"@ast-grep/napi": "0.37.0",
"@clack/prompts": "1.0.1",
"@databricks/sdk-apps": "0.54.0",
"@databricks/sdk-auth": "0.51.0",
"@databricks/sdk-core": "0.51.0",
"@databricks/sdk-experimental": "0.17.0",
Expand Down
20 changes: 16 additions & 4 deletions packages/shared/src/workspace-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* `AppKitWorkspaceClient` — the facade implementation. Construct via
* `createWorkspaceClient(...)`; this class is internal.
*
* Every service accessor delegates to a single lazily-constructed legacy SDK
* client. This is the seam: to migrate a service to the modular SDK, replace
* its getter here with a modular client instance (and update its connector +
* the accessor type in `types.ts`). No other AppKit module touches the SDK.
* Migrated service accessors build their modular client lazily (see
* `modular.ts`); the rest (`servingEndpoints`, `config`, `apiClient`) delegate
* to a single lazily-constructed legacy SDK client. To migrate one, replace its
* getter here with a modular client instance (and update its connector + the
* accessor type in `types.ts`). No other AppKit module touches the SDK.
*/
import {
buildLegacyWorkspaceClient,
Expand All @@ -24,6 +25,8 @@ import {
buildGenieClient,
type FunctionsClient,
type GenieClient,
buildAppsClient,
type AppsClient,
buildJobsClient,
buildExperimentsClient,
type ExperimentsClient,
Expand Down Expand Up @@ -58,6 +61,7 @@ export class AppKitWorkspaceClient implements WorkspaceClient {
#currentUser?: ScimClient;
#genie?: GenieClient;
#database?: DatabaseClient;
#apps?: AppsClient;
#jobs?: JobsClient;
#modelServing?: ModelServingClient;
#experiments?: ExperimentsClient;
Expand Down Expand Up @@ -97,6 +101,14 @@ export class AppKitWorkspaceClient implements WorkspaceClient {
return this.#genie;
}

// Migrated to the modular SDK — built lazily, independent of the legacy client.
get apps(): AppsClient {
if (!this.#apps) {
this.#apps = buildAppsClient(this.#opts);
}
return this.#apps;
}

// Migrated to the modular SDK — built lazily, independent of the legacy client.
get database(): DatabaseClient {
if (!this.#database) {
Expand Down
26 changes: 22 additions & 4 deletions packages/shared/src/workspace-client/modular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
*
* Migrated services are built here as per-service clients; the facade delegates
* their accessors to these instead of the legacy monolithic client. Currently
* `warehouses`, `statementExecution`, `currentUser` (SCIM), `genie`, `jobs`, `vectorSearch`
* and `tables` (UC) are migrated, plus the auth + raw-request seam ({@link buildWorkspaceAuth});
* every other service still routes through `legacy.ts`.
* `warehouses`, `statementExecution`, `currentUser` (SCIM), `genie`, `jobs`,
* `files`, `vectorSearch`, `tables`, `modelServing`, `volumes`, `functions`,
* `connections`, `database`, `postgres`, `experiments` and `apps` are
* migrated, plus the auth + raw-request seam ({@link buildWorkspaceAuth}).
* Only `servingEndpoints`, `config` and `apiClient` still route through
* `legacy.ts`.
*
* NOTE: statementExecution relies on a pinned pnpm patch
* (`patches/@databricks__sdk-statementexecution@0.46.0.patch`) that restores the
* (`patches/@databricks__sdk-statementexecution@0.52.0.patch`) that restores the
* undocumented Reyden `attachment` response field, which the SDK's generated
* unmarshal transform would otherwise strip.
*
Expand All @@ -33,6 +36,7 @@ import { execFile } from "node:child_process";
import { STATUS_CODES } from "node:http";
import { promisify } from "node:util";

import type { AppsClient } from "@databricks/sdk-apps/v1";
import {
type Credentials,
newTokenCredentials,
Expand Down Expand Up @@ -547,6 +551,14 @@ export function buildScimClient(opts: WorkspaceClientOptions): ScimClient {
return new ScimClient(mapToClientOptions(opts));
}

/** Build a modular Apps client from wrapper options. */
export function buildAppsClient(opts: WorkspaceClientOptions): AppsClient {
return lazyClient(
() => import("@databricks/sdk-apps/v1").then((m) => m.AppsClient),
mapToClientOptions(opts),
);
}

/**
* Defer loading an SDK client's module until its first method call, so app
* boot doesn't pay for clients it never uses. Generated methods return either
Expand Down Expand Up @@ -715,6 +727,7 @@ export function buildPostgresClient(
// ── Client type re-exports (for the facade accessor types) ───────────────
export type { DatabaseClient } from "@databricks/sdk-database/v1";
export type { ExperimentsClient } from "@databricks/sdk-experiments/v1";
export type { AppsClient } from "@databricks/sdk-apps/v1";
export type { FilesClient } from "@databricks/sdk-files/v2";
export type {
DirectoryEntry as FilesDirectoryEntry,
Expand Down Expand Up @@ -766,6 +779,11 @@ export type {
ListDatabaseInstancesRequest,
ListDatabaseInstancesResponse,
} from "@databricks/sdk-database/v1";
export type {
App,
ListAppsRequest,
ListAppsResponse,
} from "@databricks/sdk-apps/v1";
export type {
GenieGetMessageQueryResultResponse,
GenieMessage,
Expand Down
27 changes: 27 additions & 0 deletions packages/shared/src/workspace-client/tests/modular.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ vi.mock("@databricks/sdk-warehouses/v1", () => ({
vi.mock("@databricks/sdk-statementexecution/v1", () => ({
StatementExecutionClient: vi.fn().mockImplementation((opts) => ({ opts })),
}));
vi.mock("@databricks/sdk-apps/v1", () => ({
AppsClient: vi.fn().mockImplementation((opts) => {
ctorOpts.push(opts);
return { opts, getApp: async () => ({}) };
}),
}));
vi.mock("@databricks/sdk-experiments/v1", () => ({
ExperimentsClient: vi.fn().mockImplementation((opts) => {
ctorOpts.push(opts);
Expand Down Expand Up @@ -164,6 +170,7 @@ import {
buildConnectionsClient,
buildDatabaseClient,
buildExperimentsClient,
buildAppsClient,
buildGenieClient,
buildModelServingClient,
buildVolumesClient,
Expand Down Expand Up @@ -394,6 +401,26 @@ describe("modular mapToClientOptions (via buildWarehousesClient)", () => {
expect(Reflect.get(client, "then")).toBeUndefined();
});

test("apps passes the mapped options (normalized host, credentials) to the client", async () => {
await buildAppsClient({
host: "x.cloud.databricks.com",
token: "user-token",
clientOptions: {
product: "@databricks/appkit",
productVersion: "0.64.0",
},
} as never).getApp({} as never);
expect(ctorOpts[0].host).toBe("https://x.cloud.databricks.com");
expect(ctorOpts[0].credentials).toMatchObject({
kind: "pat",
token: "user-token",
});
expect(m2mOpts).toEqual([]);
expect(await sentUserAgent(ctorOpts[0].httpClient)).toBe(
"@databricks/appkit/0.64.0",
);
});

test("database maps host normalization + SP M2M credentials through mapToClientOptions", async () => {
process.env.DATABRICKS_CLIENT_ID = "sp-client-id";
process.env.DATABRICKS_CLIENT_SECRET = "sp-secret";
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/src/workspace-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
WarehousesClient,
WorkspaceAuth,
ScimClient,
AppsClient,
GenieClient,
DatabaseClient,
JobsClient,
Expand Down Expand Up @@ -66,6 +67,9 @@ export interface WorkspaceClient extends WorkspaceAuth {
/** Lakebase provisioned database instances + credentials (modular SDK). */
readonly database: DatabaseClient;

/** Databricks Apps (modular SDK). */
readonly apps: AppsClient;

/** Jobs (modular SDK, Jobs API 2.2). */
readonly jobs: JobsClient;

Expand Down
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading