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 @@ -16,6 +16,7 @@
"@databricks/sdk-files",
"@databricks/sdk-genie",
"@databricks/sdk-jobs",
"@databricks/sdk-postgres",
"@databricks/sdk-uc-tables",
"@databricks/sdk-vectorsearch",
"@databricks/sdk-options",
Expand Down
1 change: 1 addition & 0 deletions packages/appkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"@databricks/sdk-uc-tables": "0.52.0",
"@databricks/sdk-vectorsearch": "0.51.0",
"@databricks/sdk-options": "0.51.0",
"@databricks/sdk-postgres": "0.52.0",
"@databricks/sdk-scim": "0.51.0",
"@databricks/sdk-statementexecution": "0.52.0",
"@databricks/sdk-warehouses": "0.53.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 @@ -71,6 +71,7 @@ const FACADE_SERVICES = [
"jobs",
"vectorSearch",
"tables",
"postgres",
"statementExecution",
"servingEndpoints",
"currentUser",
Expand Down
1 change: 1 addition & 0 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@databricks/sdk-uc-tables": "0.52.0",
"@databricks/sdk-vectorsearch": "0.51.0",
"@databricks/sdk-options": "0.51.0",
"@databricks/sdk-postgres": "0.52.0",
"@databricks/sdk-scim": "0.51.0",
"@databricks/sdk-statementexecution": "0.52.0",
"@databricks/sdk-warehouses": "0.53.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/shared/src/workspace-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
type FilesClient,
buildTablesClient,
type TablesClient,
buildPostgresClient,
type PostgresClient,
buildVectorSearchClient,
type VectorSearchClient,
type StatementExecutionClient,
Expand All @@ -47,6 +49,7 @@ export class AppKitWorkspaceClient implements WorkspaceClient {
#files?: FilesClient;
#vectorSearch?: VectorSearchClient;
#tables?: TablesClient;
#postgres?: PostgresClient;

constructor(opts: WorkspaceClientOptions) {
this.#opts = opts;
Expand Down Expand Up @@ -100,6 +103,14 @@ export class AppKitWorkspaceClient implements WorkspaceClient {
return this.#tables;
}

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

// Migrated to the modular SDK — built lazily, independent of the legacy client.
get statementExecution(): StatementExecutionClient {
if (!this.#statementExecution) {
Expand Down
16 changes: 16 additions & 0 deletions packages/shared/src/workspace-client/modular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import type { FilesClient } from "@databricks/sdk-files/v2";
import type { GenieClient } from "@databricks/sdk-genie/v1";
import type { JobsClient } from "@databricks/sdk-jobs/v2";
import type { ClientOptions } from "@databricks/sdk-options/client";
import type { PostgresClient } from "@databricks/sdk-postgres/v1";
import { ScimClient } from "@databricks/sdk-scim/v1";
import { StatementExecutionClient } from "@databricks/sdk-statementexecution/v1";
import type { TablesClient } from "@databricks/sdk-uc-tables/v1";
Expand Down Expand Up @@ -623,6 +624,20 @@ export function buildTablesClient(opts: WorkspaceClientOptions): TablesClient {
);
}

/**
* Build a modular Lakebase Postgres (autoscaling: projects, branches,
* endpoints) client from wrapper options. Distinct from the provisioned
* `/api/2.0/database` instance API.
*/
export function buildPostgresClient(
opts: WorkspaceClientOptions,
): PostgresClient {
return lazyClient(
() => import("@databricks/sdk-postgres/v1").then((m) => m.PostgresClient),
mapToClientOptions(opts),
);
}

// ── Client type re-exports (for the facade accessor types) ───────────────
export type { FilesClient } from "@databricks/sdk-files/v2";
export type {
Expand All @@ -631,6 +646,7 @@ export type {
} from "@databricks/sdk-files/v2";
export type { GenieClient } from "@databricks/sdk-genie/v1";
export type { JobsClient } from "@databricks/sdk-jobs/v2";
export type { PostgresClient } from "@databricks/sdk-postgres/v1";
export type { ScimClient } from "@databricks/sdk-scim/v1";
export type { StatementExecutionClient } from "@databricks/sdk-statementexecution/v1";
export type { TablesClient } from "@databricks/sdk-uc-tables/v1";
Expand Down
34 changes: 34 additions & 0 deletions packages/shared/src/workspace-client/tests/modular.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ vi.mock("@databricks/sdk-genie/v1", () => ({
};
}),
}));
vi.mock("@databricks/sdk-postgres/v1", () => ({
PostgresClient: vi.fn().mockImplementation((opts) => {
ctorOpts.push(opts);
return { opts, getEndpoint: async () => ({}) };
}),
}));
vi.mock("@databricks/sdk-auth/credentials", () => ({
newPatCredentials: vi.fn((token: string) => {
patTokens.push(token);
Expand Down Expand Up @@ -120,6 +126,7 @@ import { ApiError } from "../errors";
import {
buildGenieClient,
buildWarehousesClient,
buildPostgresClient,
buildWorkspaceAuth,
} from "../modular";

Expand Down Expand Up @@ -345,6 +352,33 @@ describe("modular mapToClientOptions (via buildWarehousesClient)", () => {
expect(Reflect.get(client, "then")).toBeUndefined();
});

test("postgres normalizes the host and passes SP M2M credentials", async () => {
process.env.DATABRICKS_HOST = "envhost.cloud.databricks.com";
process.env.DATABRICKS_CLIENT_ID = "sp-client-id";
process.env.DATABRICKS_CLIENT_SECRET = "sp-secret";
await buildPostgresClient({}).getEndpoint({ name: "e" });
expect(ctorOpts[0].host).toBe("https://envhost.cloud.databricks.com");
expect((ctorOpts[0].credentials as { name: () => string }).name()).toBe(
"oauth-m2m",
);
});

test("postgres (asUser) uses the OBO token as PAT, not the SP env creds", async () => {
process.env.DATABRICKS_CLIENT_ID = "sp-client-id";
process.env.DATABRICKS_CLIENT_SECRET = "sp-secret";
await buildPostgresClient({
token: "user-token",
host: "https://x",
}).getEndpoint({
name: "e",
});
expect(ctorOpts[0].credentials).toMatchObject({
kind: "pat",
token: "user-token",
});
expect(m2mOpts).toEqual([]);
});

test("no product configured (build-time) → transport adds no AppKit User-Agent", async () => {
buildWarehousesClient({ host: "https://x" });
expect(await sentUserAgent(ctorOpts[0].httpClient)).toBeNull();
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/workspace-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
FilesClient,
TablesClient,
VectorSearchClient,
PostgresClient,
} from "./modular";

// Legacy SDK type namespaces for un-migrated services, re-exported so AppKit
Expand Down Expand Up @@ -64,6 +65,8 @@ export interface WorkspaceClient extends WorkspaceAuth {

/** Unity Catalog Tables (modular SDK). */
readonly tables: TablesClient;
/** Lakebase Postgres: autoscaling projects, branches, endpoints (modular SDK). */
readonly postgres: PostgresClient;

/** Statement Execution (modular SDK). */
readonly statementExecution: StatementExecutionClient;
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