@dbx-tools/databricks 0.9.154 → 0.9.157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,9 +10,9 @@ import {
10
10
  createWorkspaceClient as _createWorkspaceClient,
11
11
  type WorkspaceClient as AppKitWorkspaceClient,
12
12
  } from "@databricks/appkit";
13
- import { appkit } from "@dbx-tools/appkit";
14
- import { client as authClient, type AuthClient, type DatabricksAuthOptions } from "@dbx-tools/auth";
15
- import { functionUtils, net, stringUtils } from "@dbx-tools/shared-core";
13
+ import { tryGetExecutionContext } from "@dbx-tools/appkit";
14
+ import { type AuthClient, type DatabricksAuthOptions, createAuthClient } from "@dbx-tools/auth";
15
+ import { memoize, type UrlBuilder, urlBuilder, trimToUndefined } from "@dbx-tools/shared-core";
16
16
 
17
17
  /** Databricks workspace ids are a 10-20 digit run embedded in the host. */
18
18
  const WORKSPACE_ID_REGEX = /\d{10,20}/;
@@ -34,7 +34,7 @@ type Config = WorkspaceClient["config"];
34
34
  export async function createWorkspaceClient(
35
35
  options: DatabricksAuthOptions = {},
36
36
  ): Promise<AppKitWorkspaceClient> {
37
- const auth = await authClient.createAuthClient(options);
37
+ const auth = await createAuthClient(options);
38
38
  const client = _createWorkspaceClient({ host: auth.host });
39
39
  client.config.credentials = {
40
40
  name: "pat",
@@ -76,7 +76,7 @@ export function toLegacyWorkspaceClient(
76
76
  * construction happens at most once per process. Used only when there's no
77
77
  * AppKit execution context to borrow a client from.
78
78
  */
79
- const getDefaultWorkspaceClient = functionUtils.memoize(async () =>
79
+ const getDefaultWorkspaceClient = memoize(async () =>
80
80
  (await createWorkspaceClient()).toLegacyWorkspaceClient(),
81
81
  );
82
82
 
@@ -86,7 +86,7 @@ const getDefaultWorkspaceClient = functionUtils.memoize(async () =>
86
86
  * missing AppKit scope.
87
87
  */
88
88
  export function tryGetWorkspaceClient(): WorkspaceClient | undefined {
89
- return appkit.tryGetExecutionContext()?.client.toLegacyWorkspaceClient();
89
+ return tryGetExecutionContext()?.client.toLegacyWorkspaceClient();
90
90
  }
91
91
 
92
92
  /**
@@ -118,7 +118,7 @@ async function getWorkspaceConfig(): Promise<Config | undefined> {
118
118
  * calls `currentUser.me()` on {@link client} (or {@link getWorkspaceClient}).
119
119
  */
120
120
  export async function getCurrentUserName(client?: WorkspaceClient): Promise<string> {
121
- const contextUser = readContextUserName(appkit.tryGetExecutionContext());
121
+ const contextUser = readContextUserName(tryGetExecutionContext());
122
122
  if (contextUser) return contextUser;
123
123
 
124
124
  const resolved = client ?? (await getWorkspaceClient());
@@ -134,20 +134,20 @@ export async function getCurrentUserName(client?: WorkspaceClient): Promise<stri
134
134
  function readContextUserName(ctx: unknown): string | undefined {
135
135
  if (typeof ctx !== "object" || ctx === null || !("userName" in ctx)) return undefined;
136
136
  const value = (ctx as { userName?: unknown }).userName;
137
- return stringUtils.trimToUndefined(value);
137
+ return trimToUndefined(value);
138
138
  }
139
139
 
140
140
  /**
141
141
  * Resolve the current workspace host as a `net.UrlBuilder`: the workspace
142
142
  * `Config` host first, then the `DATABRICKS_HOST` env var, else `undefined`.
143
143
  */
144
- export async function getWorkspaceUrl(): Promise<net.UrlBuilder | undefined> {
144
+ export async function getWorkspaceUrl(): Promise<UrlBuilder | undefined> {
145
145
  const config = await getWorkspaceConfig();
146
146
  if (config) {
147
- const configHost = net.urlBuilder(await config.getHost());
147
+ const configHost = urlBuilder(await config.getHost());
148
148
  if (configHost) return configHost;
149
149
  }
150
- const databricksHost = net.urlBuilder(process.env.DATABRICKS_HOST);
150
+ const databricksHost = urlBuilder(process.env.DATABRICKS_HOST);
151
151
  if (databricksHost) return databricksHost;
152
152
  return undefined;
153
153
  }