@dbx-tools/databricks 0.9.153 → 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.
- package/index.ts +5 -4
- package/lib/index.d.ts +5 -4
- package/lib/index.js +6 -5
- package/lib/src/cloud.d.ts +3 -3
- package/lib/src/cloud.js +15 -15
- package/lib/src/databricks-fs.js +18 -18
- package/lib/src/databricks-path.d.ts +0 -3
- package/lib/src/databricks-path.js +12 -14
- package/lib/src/net.d.ts +2 -2
- package/lib/src/net.js +6 -6
- package/lib/src/workspace-client.d.ts +2 -2
- package/lib/src/workspace-client.js +11 -11
- package/package.json +8 -56
- package/src/cloud.ts +29 -16
- package/src/databricks-fs.ts +18 -18
- package/src/databricks-path.ts +17 -14
- package/src/net.ts +12 -6
- package/src/workspace-client.ts +11 -11
package/src/workspace-client.ts
CHANGED
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
createWorkspaceClient as _createWorkspaceClient,
|
|
11
11
|
type WorkspaceClient as AppKitWorkspaceClient,
|
|
12
12
|
} from "@databricks/appkit";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
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
|
|
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 =
|
|
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
|
|
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(
|
|
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
|
|
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<
|
|
144
|
+
export async function getWorkspaceUrl(): Promise<UrlBuilder | undefined> {
|
|
145
145
|
const config = await getWorkspaceConfig();
|
|
146
146
|
if (config) {
|
|
147
|
-
const configHost =
|
|
147
|
+
const configHost = urlBuilder(await config.getHost());
|
|
148
148
|
if (configHost) return configHost;
|
|
149
149
|
}
|
|
150
|
-
const databricksHost =
|
|
150
|
+
const databricksHost = urlBuilder(process.env.DATABRICKS_HOST);
|
|
151
151
|
if (databricksHost) return databricksHost;
|
|
152
152
|
return undefined;
|
|
153
153
|
}
|