@databricks/appkit-ui 0.88.1 → 0.89.0
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/CLAUDE.md +7 -2
- package/dist/cli/commands/doctor/checks-existence.js +16 -16
- package/dist/cli/commands/doctor/checks-existence.js.map +1 -1
- package/dist/cli/commands/doctor/checks.js +15 -18
- package/dist/cli/commands/doctor/checks.js.map +1 -1
- package/dist/cli/commands/doctor/databricks-client.js +8 -6
- package/dist/cli/commands/doctor/databricks-client.js.map +1 -1
- package/dist/cli/commands/registry/workspace-picker.js +34 -24
- package/dist/cli/commands/registry/workspace-picker.js.map +1 -1
- package/dist/react/genie/genie-chart-inference.js.map +1 -1
- package/dist/react/genie/genie-query-transform.d.ts +5 -2
- package/dist/react/genie/genie-query-transform.d.ts.map +1 -1
- package/dist/react/genie/genie-query-transform.js +14 -8
- package/dist/react/genie/genie-query-transform.js.map +1 -1
- package/dist/shared/src/genie.d.ts +9 -3
- package/dist/shared/src/genie.d.ts.map +1 -1
- package/dist/shared/src/workspace-client/factory.d.ts +0 -1
- package/dist/shared/src/workspace-client/index.d.ts +1 -2
- package/dist/shared/src/workspace-client/modular.d.ts +19 -0
- package/dist/shared/src/workspace-client/types.d.ts +1 -2
- package/dist/workspace-client/client.js +81 -23
- package/dist/workspace-client/client.js.map +1 -1
- package/dist/workspace-client/errors.d.ts +14 -2
- package/dist/workspace-client/errors.d.ts.map +1 -0
- package/dist/workspace-client/errors.js +45 -2
- package/dist/workspace-client/errors.js.map +1 -0
- package/dist/workspace-client/factory.d.ts +1 -1
- package/dist/workspace-client/factory.js.map +1 -1
- package/dist/workspace-client/index.d.ts +4 -3
- package/dist/workspace-client/index.js +2 -2
- package/dist/workspace-client/modular.d.ts +109 -0
- package/dist/workspace-client/modular.d.ts.map +1 -0
- package/dist/workspace-client/modular.js +447 -0
- package/dist/workspace-client/modular.js.map +1 -0
- package/dist/workspace-client/options.d.ts +29 -0
- package/dist/workspace-client/options.d.ts.map +1 -0
- package/dist/workspace-client/types.d.ts +35 -38
- package/dist/workspace-client/types.d.ts.map +1 -1
- package/docs/api/appkit/Class.ApiError.md +110 -0
- package/docs/api/appkit/Class.DatabricksAdapter.md +2 -2
- package/docs/api/appkit/Class.SupervisorApiAdapter.md +1 -1
- package/docs/api/appkit/Function.generateDatabaseCredential.md +2 -2
- package/docs/api/appkit/Function.getWorkspaceClient.md +2 -2
- package/docs/api/appkit/Interface.DirectoryEntry.md +62 -0
- package/docs/api/appkit/Interface.DownloadResponse.md +45 -0
- package/docs/api/appkit/Interface.JobAPI.md +20 -12
- package/docs/api/appkit/Interface.LakebasePoolConfig.md +1 -1
- package/docs/api/appkit/Interface.WorkspaceClient.md +168 -26
- package/docs/api/appkit/Interface.WorkspaceClientOptions.md +1 -14
- package/docs/api/appkit/TypeAlias.FilesDirectoryEntry.md +8 -0
- package/docs/api/appkit/TypeAlias.FilesDownloadResponse.md +8 -0
- package/docs/api/appkit/TypeAlias.JobsExport.md +1 -1
- package/docs/api/appkit/TypeAlias.WorkspaceClientLike.md +16 -0
- package/docs/api/appkit.md +7 -2
- package/docs/plugins/files.md +20 -3
- package/docs/plugins/jobs.md +9 -9
- package/docs/plugins/testing.md +10 -8
- package/llms.txt +7 -2
- package/node_modules/@databricks/sdk-genie/LICENSE +203 -0
- package/node_modules/@databricks/sdk-genie/README.md +23 -0
- package/node_modules/@databricks/sdk-genie/dist/package.js +7 -0
- package/node_modules/@databricks/sdk-genie/dist/package.js.map +1 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/client.d.ts +175 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/client.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/client.js +829 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/client.js.map +1 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/index.d.ts +3 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/index.js +4 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/model.d.ts +1799 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/model.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/model.js +1097 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/model.js.map +1 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/transport.d.ts +37 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/transport.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/transport.js +73 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/transport.js.map +1 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/utils.d.ts +43 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/utils.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/utils.js +130 -0
- package/node_modules/@databricks/sdk-genie/dist/v1/utils.js.map +1 -0
- package/node_modules/@databricks/sdk-genie/package.json +46 -0
- package/node_modules/@databricks/sdk-statementexecution/LICENSE +203 -0
- package/node_modules/@databricks/sdk-statementexecution/README.md +23 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/package.js +7 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/package.js.map +1 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/client.d.ts +91 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/client.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/client.js +183 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/client.js.map +1 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/index.d.ts +3 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/index.js +4 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/model.d.ts +506 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/model.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/model.js +302 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/model.js.map +1 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/transport.d.ts +37 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/transport.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/transport.js +73 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/transport.js.map +1 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/utils.d.ts +25 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/utils.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/utils.js +87 -0
- package/node_modules/@databricks/sdk-statementexecution/dist/v1/utils.js.map +1 -0
- package/node_modules/@databricks/sdk-statementexecution/package.json +46 -0
- package/node_modules/@databricks/sdk-vectorsearch/LICENSE +203 -0
- package/node_modules/@databricks/sdk-vectorsearch/README.md +23 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/package.js +7 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/package.js.map +1 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/client.d.ts +70 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/client.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/client.js +474 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/client.js.map +1 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/index.d.ts +3 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/index.js +4 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/model.d.ts +704 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/model.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/model.js +635 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/model.js.map +1 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/transport.d.ts +37 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/transport.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/transport.js +73 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/transport.js.map +1 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/utils.d.ts +37 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/utils.d.ts.map +1 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/utils.js +104 -0
- package/node_modules/@databricks/sdk-vectorsearch/dist/v1/utils.js.map +1 -0
- package/node_modules/@databricks/sdk-vectorsearch/package.json +46 -0
- package/package.json +29 -4
- package/sbom.cdx.json +1 -1
- package/dist/shared/src/workspace-client/errors.d.ts +0 -1
- package/dist/shared/src/workspace-client/legacy.d.ts +0 -3
- package/dist/workspace-client/legacy.d.ts +0 -34
- package/dist/workspace-client/legacy.d.ts.map +0 -1
- package/dist/workspace-client/legacy.js +0 -23
- package/dist/workspace-client/legacy.js.map +0 -1
- package/docs/api/appkit/Interface.WorkspaceClientLike.md +0 -67
package/CLAUDE.md
CHANGED
|
@@ -64,6 +64,7 @@ npx @databricks/appkit docs <query>
|
|
|
64
64
|
## appkit API reference [collapsed]
|
|
65
65
|
|
|
66
66
|
- [@databricks/appkit](./docs/api/appkit.md): Documentation merge entry for Typedoc — combines the stable @databricks/appkit
|
|
67
|
+
- [Class: ApiError](./docs/api/appkit/Class.ApiError.md): Extends
|
|
67
68
|
- [Abstract Class: AppKitError](./docs/api/appkit/Class.AppKitError.md): Base error class for all AppKit errors.
|
|
68
69
|
- [Class: AppKitMcpClient](./docs/api/appkit/Class.AppKitMcpClient.md): Lightweight MCP client for Databricks-hosted MCP servers.
|
|
69
70
|
- [Class: AuthenticationError](./docs/api/appkit/Class.AuthenticationError.md): Error thrown when authentication fails.
|
|
@@ -194,8 +195,10 @@ npx @databricks/appkit docs <query>
|
|
|
194
195
|
- [Interface: DatabaseValidationIssue](./docs/api/appkit/Interface.DatabaseValidationIssue.md): One rejected field; path names public columns, never their values.
|
|
195
196
|
- [Interface: DatabricksAuth](./docs/api/appkit/Interface.DatabricksAuth.md): Resolved Databricks host + bearer token for the eval runner's REST calls.
|
|
196
197
|
- [Interface: DatasetRow](./docs/api/appkit/Interface.DatasetRow.md): One row of a managed evaluation dataset. inputs are the kwargs passed to the
|
|
198
|
+
- [Interface: DirectoryEntry](./docs/api/appkit/Interface.DirectoryEntry.md): A single entry returned when listing a directory (Files API wire shape).
|
|
197
199
|
- [Interface: DiscoveredEval](./docs/api/appkit/Interface.DiscoveredEval.md): An eval file found under server/agents//evals/.
|
|
198
200
|
- [Interface: DiscoveredEvalConfig](./docs/api/appkit/Interface.DiscoveredEvalConfig.md): A per-agent evals.config.ts found under server/agents//evals/.
|
|
201
|
+
- [Interface: DownloadResponse](./docs/api/appkit/Interface.DownloadResponse.md): Response object for file downloads containing a readable stream.
|
|
199
202
|
- [Interface: DriveResult](./docs/api/appkit/Interface.DriveResult.md): What a driver returns for a single t.send.
|
|
200
203
|
- [Interface: EndpointConfig](./docs/api/appkit/Interface.EndpointConfig.md): Properties
|
|
201
204
|
- [Interface: EntityMutationHooks<TTable>](./docs/api/appkit/Interface.EntityMutationHooks.md): Mutation lifecycle for one entity. A before hook may return a replacement
|
|
@@ -268,8 +271,7 @@ npx @databricks/appkit docs <query>
|
|
|
268
271
|
- [Interface: ToolProvider](./docs/api/appkit/Interface.ToolProvider.md): Methods
|
|
269
272
|
- [Interface: ValidationResult](./docs/api/appkit/Interface.ValidationResult.md): Result of validating all registered resources against the environment.
|
|
270
273
|
- [Interface: WorkspaceClient](./docs/api/appkit/Interface.WorkspaceClient.md): AppKit's workspace client facade. Mirrors the multi-client shape of the
|
|
271
|
-
- [Interface:
|
|
272
|
-
- [Interface: WorkspaceClientOptions](./docs/api/appkit/Interface.WorkspaceClientOptions.md): Options used to construct the wrapper. Mirrors the subset of the old SDK's
|
|
274
|
+
- [Interface: WorkspaceClientOptions](./docs/api/appkit/Interface.WorkspaceClientOptions.md): Properties
|
|
273
275
|
- [Type Alias: AgentAuth](./docs/api/appkit/TypeAlias.AgentAuth.md): Identity an agent runs under. The only value is on-behalf-of-user.
|
|
274
276
|
- [Type Alias: AgentEvent](./docs/api/appkit/TypeAlias.AgentEvent.md): Type Declaration
|
|
275
277
|
- [Type Alias: AgentTool](./docs/api/appkit/TypeAlias.AgentTool.md): Any tool an agent can invoke: inline function tools (tool()), hosted MCP
|
|
@@ -289,6 +291,8 @@ npx @databricks/appkit docs <query>
|
|
|
289
291
|
- [Type Alias: ExecutionResult<T>](./docs/api/appkit/TypeAlias.ExecutionResult.md): Discriminated union for plugin execution results.
|
|
290
292
|
- [Type Alias: FileAction](./docs/api/appkit/TypeAlias.FileAction.md): Every action the files plugin can perform.
|
|
291
293
|
- [Type Alias: FilePolicy()](./docs/api/appkit/TypeAlias.FilePolicy.md): A policy function that decides whether user may perform action on
|
|
294
|
+
- [Type Alias: FilesDirectoryEntry](./docs/api/appkit/TypeAlias.FilesDirectoryEntry.md): A single directory entry in the modular SDK shape (camelCase). list() and
|
|
295
|
+
- [Type Alias: FilesDownloadResponse](./docs/api/appkit/TypeAlias.FilesDownloadResponse.md): Download response in the modular SDK shape (contentLength is a bigint).
|
|
292
296
|
- [Type Alias: HostedTool](./docs/api/appkit/TypeAlias.HostedTool.md)
|
|
293
297
|
- [Type Alias: IAppRouter](./docs/api/appkit/TypeAlias.IAppRouter.md): Express router type for plugin route registration
|
|
294
298
|
- [Type Alias: IDatabaseConfig<TSchema>](./docs/api/appkit/TypeAlias.IDatabaseConfig.md): Configuration for one schema-bound DatabasePlugin instance.
|
|
@@ -310,6 +314,7 @@ npx @databricks/appkit docs <query>
|
|
|
310
314
|
- [Type Alias: TransactionClient](./docs/api/appkit/TypeAlias.TransactionClient.md): Entity and SQL capabilities bound to one transaction.
|
|
311
315
|
- [Type Alias: UserContext](./docs/api/appkit/TypeAlias.UserContext.md): Deprecated
|
|
312
316
|
- [Type Alias: UserScopedApp<U>](./docs/api/appkit/TypeAlias.UserScopedApp.md): Type Declaration
|
|
317
|
+
- [Type Alias: WorkspaceClientLike](./docs/api/appkit/TypeAlias.WorkspaceClientLike.md): Structural shape of a Databricks SDK client used by fromSupervisorApi.
|
|
313
318
|
- [Variable: agents](./docs/api/appkit/Variable.agents.md): Plugin factory for the agents plugin. Discovers agents from
|
|
314
319
|
- [Variable: aiSearch](./docs/api/appkit/Variable.aiSearch.md)
|
|
315
320
|
- [Variable: READ_ACTIONS](./docs/api/appkit/Variable.READ_ACTIONS.md): Actions that only read data.
|
|
@@ -6,7 +6,7 @@ import { AppkitNotInstalledError, getLakebasePool } from "./databricks-client.js
|
|
|
6
6
|
* Layer: existence — per-resource-type probes that prove a declared resource
|
|
7
7
|
* exists and is reachable via the cheapest read the SDK offers.
|
|
8
8
|
*
|
|
9
|
-
* The client is typed structurally
|
|
9
|
+
* The client is typed structurally against the facade's modular clients.
|
|
10
10
|
*/
|
|
11
11
|
/** A passing existence check. Shared, never mutated by callers. */
|
|
12
12
|
const EXISTENCE_OK = {
|
|
@@ -14,16 +14,16 @@ const EXISTENCE_OK = {
|
|
|
14
14
|
status: "ok"
|
|
15
15
|
};
|
|
16
16
|
function statusCodeOf(err) {
|
|
17
|
-
if (err
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (!err || typeof err !== "object") return void 0;
|
|
18
|
+
const e = err;
|
|
19
|
+
const code = e.statusCode ?? e.httpStatusCode;
|
|
20
|
+
return typeof code === "number" && code >= 0 ? code : void 0;
|
|
21
21
|
}
|
|
22
22
|
function errorCodeOf(err) {
|
|
23
|
-
if (err
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
if (!err || typeof err !== "object") return void 0;
|
|
24
|
+
const e = err;
|
|
25
|
+
const code = e.errorCode ?? e.code;
|
|
26
|
+
return typeof code === "string" && code.length > 0 ? code : void 0;
|
|
27
27
|
}
|
|
28
28
|
function cleanMessage(err) {
|
|
29
29
|
const raw = errorMessage(err);
|
|
@@ -89,7 +89,7 @@ const probeWarehouse = async (client, target) => {
|
|
|
89
89
|
const id = field(target, "id");
|
|
90
90
|
if (!id) return missingField("id");
|
|
91
91
|
try {
|
|
92
|
-
const state = (await client.warehouses.
|
|
92
|
+
const state = (await client.warehouses.getWarehouse({ id })).state;
|
|
93
93
|
if (state && state !== "RUNNING") return {
|
|
94
94
|
layer: "existence",
|
|
95
95
|
status: "warn",
|
|
@@ -107,7 +107,7 @@ const probeServing = async (client, target) => {
|
|
|
107
107
|
const value = name ?? idOnly;
|
|
108
108
|
if (!value) return missingField("name");
|
|
109
109
|
try {
|
|
110
|
-
await client.
|
|
110
|
+
await client.modelServing.getInferenceEndpoint({ name: value });
|
|
111
111
|
return EXISTENCE_OK;
|
|
112
112
|
} catch (err) {
|
|
113
113
|
const result = classifyError(err, target);
|
|
@@ -119,7 +119,7 @@ const probeGenie = async (client, target) => {
|
|
|
119
119
|
const spaceId = field(target, "id");
|
|
120
120
|
if (!spaceId) return missingField("id");
|
|
121
121
|
try {
|
|
122
|
-
await client.genie.
|
|
122
|
+
await client.genie.genieGetSpace({ spaceId });
|
|
123
123
|
return EXISTENCE_OK;
|
|
124
124
|
} catch (err) {
|
|
125
125
|
return classifyError(err, target);
|
|
@@ -136,7 +136,7 @@ const probeJob = async (client, target) => {
|
|
|
136
136
|
detail: `"${raw}" is not a valid job id (expected an integer)`
|
|
137
137
|
};
|
|
138
138
|
try {
|
|
139
|
-
await client.jobs.
|
|
139
|
+
await client.jobs.getJob({ jobId: BigInt(id) });
|
|
140
140
|
return EXISTENCE_OK;
|
|
141
141
|
} catch (err) {
|
|
142
142
|
return classifyError(err, target);
|
|
@@ -153,7 +153,7 @@ const probeVolume = async (client, target) => {
|
|
|
153
153
|
detail: `"${raw}" is not a valid volume path (expected /Volumes/catalog/schema/volume or catalog.schema.volume)`
|
|
154
154
|
};
|
|
155
155
|
try {
|
|
156
|
-
await client.volumes.
|
|
156
|
+
await client.volumes.getVolume({ fullNameArg: name });
|
|
157
157
|
return EXISTENCE_OK;
|
|
158
158
|
} catch (err) {
|
|
159
159
|
return classifyError(err, target);
|
|
@@ -163,7 +163,7 @@ const probeVectorIndex = async (client, target) => {
|
|
|
163
163
|
const name = field(target, "indexName", "index_name", "name");
|
|
164
164
|
if (!name) return missingField("indexName");
|
|
165
165
|
try {
|
|
166
|
-
await client.
|
|
166
|
+
await client.vectorSearch.getVectorIndex({ name });
|
|
167
167
|
return EXISTENCE_OK;
|
|
168
168
|
} catch (err) {
|
|
169
169
|
return classifyError(err, target);
|
|
@@ -173,7 +173,7 @@ const probeFunction = async (client, target) => {
|
|
|
173
173
|
const name = field(target, "name");
|
|
174
174
|
if (!name) return missingField("name");
|
|
175
175
|
try {
|
|
176
|
-
await client.functions.
|
|
176
|
+
await client.functions.getFunction({ fullNameArg: name });
|
|
177
177
|
return EXISTENCE_OK;
|
|
178
178
|
} catch (err) {
|
|
179
179
|
return classifyError(err, target);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checks-existence.js","names":[],"sources":["../../../../src/cli/commands/doctor/checks-existence.ts"],"sourcesContent":["/**\n * Layer: existence — per-resource-type probes that prove a declared resource\n * exists and is reachable via the cheapest read the SDK offers.\n *\n * The client is typed structurally (not via the SDK) so `shared` stays SDK-free.\n */\n\nimport {\n AppkitNotInstalledError,\n getLakebasePool,\n type LakebasePoolHandle,\n} from \"./databricks-client\";\nimport type { LayerResult, ResourceTarget } from \"./types\";\nimport { errorMessage } from \"./utils\";\n\n/** A passing existence check. Shared, never mutated by callers. */\nconst EXISTENCE_OK: LayerResult = { layer: \"existence\", status: \"ok\" };\n\ninterface DoctorWorkspaceClient {\n warehouses: {\n get: (r: { id: string }) => Promise<{ state?: string }>;\n };\n servingEndpoints: {\n get: (r: { name: string }) => Promise<unknown>;\n };\n genie: {\n getSpace: (r: { space_id: string }) => Promise<unknown>;\n };\n jobs: {\n get: (r: { job_id: number }) => Promise<unknown>;\n };\n volumes: {\n read: (r: { name: string }) => Promise<unknown>;\n };\n vectorSearchIndexes: {\n getIndex: (r: { index_name: string }) => Promise<unknown>;\n };\n functions: {\n get: (r: { name: string }) => Promise<unknown>;\n };\n}\n\ntype ExistenceProbe = (\n client: DoctorWorkspaceClient,\n target: ResourceTarget,\n) => Promise<LayerResult>;\n\n// Read statusCode/errorCode off the SDK's ApiError structurally.\nfunction statusCodeOf(err: unknown): number | undefined {\n if (err && typeof err === \"object\" && \"statusCode\" in err) {\n const code = (err as { statusCode?: unknown }).statusCode;\n if (typeof code === \"number\") return code;\n }\n return undefined;\n}\n\nfunction errorCodeOf(err: unknown): string | undefined {\n if (err && typeof err === \"object\" && \"errorCode\" in err) {\n const code = (err as { errorCode?: unknown }).errorCode;\n if (typeof code === \"string\" && code.length > 0) return code;\n }\n return undefined;\n}\n\n// The SDK message often embeds a JSON blob; pull the inner `message` out so\n// doctor prints one clean line, not a dump.\nfunction cleanMessage(err: unknown): string {\n const raw = errorMessage(err);\n const m = raw.match(/\"message\"\\s*:\\s*\"([^\"]+)\"/);\n return m ? m[1] : raw;\n}\n\n/** The resource's configured identifier (id / name / path / host), for short\n * messages. */\nfunction displayId(target: ResourceTarget): string | null {\n return field(target, \"id\", \"name\", \"path\", \"index_name\", \"indexName\", \"host\");\n}\n\nfunction classifyError(err: unknown, target: ResourceTarget): LayerResult {\n const status = statusCodeOf(err);\n const errorCode = errorCodeOf(err);\n const message = cleanMessage(err);\n const id = displayId(target);\n const quoted = id ? `\"${id}\"` : null;\n\n if (status === 404 || errorCode === \"RESOURCE_DOES_NOT_EXIST\") {\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"NOT_FOUND\",\n detail: quoted ? `${quoted} not found` : \"not found\",\n };\n }\n // A malformed id/name often comes back as 400 rather than 404.\n if (status === 400 || errorCode === \"INVALID_PARAMETER_VALUE\") {\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"INVALID_VALUE\",\n detail: quoted\n ? `${quoted} is not a valid id/name`\n : `invalid id/name: ${message}`,\n };\n }\n // A 403 is genuinely ambiguous: several APIs (jobs, warehouses) return it for a\n // resource that doesn't exist as well as for one you can't read, so claiming\n // \"no permission\" outright would misdiagnose a wrong id. Say both.\n if (status === 403 || errorCode === \"PERMISSION_DENIED\") {\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"ACCESS_DENIED\",\n detail: quoted\n ? `${quoted} not found, or you don't have access to it`\n : \"not found, or you don't have access to it\",\n };\n }\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"PROBE_FAILED\",\n detail: quoted\n ? `read failed for ${quoted}: ${message}`\n : `read failed: ${message}`,\n };\n}\n\n/** Normalizes a field key so camelCase (`indexName`) and snake_case\n * (`index_name`) spellings match. */\nfunction normalizeKey(key: string): string {\n return key.toLowerCase().replace(/[_-]/g, \"\");\n}\n\n/** Looks up a resolved field value by any of the accepted key spellings. */\nfunction field(target: ResourceTarget, ...names: string[]): string | null {\n const wanted = new Set(names.map(normalizeKey));\n for (const [key, value] of Object.entries(target.fieldValues)) {\n if (wanted.has(normalizeKey(key)) && value.length > 0) return value;\n }\n return null;\n}\n\nfunction missingField(fieldName: string): LayerResult {\n return {\n layer: \"existence\",\n status: \"skipped\",\n code: \"MISSING_FIELD\",\n detail: `no ${fieldName} configured — can't probe`,\n };\n}\n\nconst probeWarehouse: ExistenceProbe = async (client, target) => {\n const id = field(target, \"id\");\n if (!id) return missingField(\"id\");\n try {\n const wh = await client.warehouses.get({ id });\n const state = wh.state;\n if (state && state !== \"RUNNING\") {\n return {\n layer: \"existence\",\n status: \"warn\",\n code: \"WAREHOUSE_NOT_RUNNING\",\n detail: `warehouse exists but is ${state} (will cold-start on first query)`,\n };\n }\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nconst probeServing: ExistenceProbe = async (client, target) => {\n const name = field(target, \"name\");\n // The API only accepts a name; if configured by id, probe with it anyway and\n // flag the likely cause on failure.\n const idOnly = name === null ? field(target, \"id\") : null;\n const value = name ?? idOnly;\n if (!value) return missingField(\"name\");\n try {\n await client.servingEndpoints.get({ name: value });\n return EXISTENCE_OK;\n } catch (err) {\n const result = classifyError(err, target);\n if (idOnly && result.status === \"error\") {\n result.hint =\n \"Serving endpoints are looked up by name, but this resource is configured by id. Set DATABRICKS_SERVING_ENDPOINT_NAME to the endpoint's name.\";\n }\n return result;\n }\n};\n\nconst probeGenie: ExistenceProbe = async (client, target) => {\n const spaceId = field(target, \"id\");\n if (!spaceId) return missingField(\"id\");\n try {\n await client.genie.getSpace({ space_id: spaceId });\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nconst probeJob: ExistenceProbe = async (client, target) => {\n const raw = field(target, \"id\");\n if (!raw) return missingField(\"id\");\n const id = raw.trim();\n // Validate the digits directly rather than via Number(): job ids are int64, so\n // past 2^53 Number() silently rounds (and Number.isInteger still passes),\n // which would probe a *different* job and report a false not-found. A string\n // check also rejects \"1e3\" and \"0x10\", both of which Number() would accept.\n if (!/^\\d+$/.test(id)) {\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"INVALID_ID\",\n detail: `\"${raw}\" is not a valid job id (expected an integer)`,\n };\n }\n try {\n // Pass the digits through unconverted to preserve int64 precision; the SDK\n // serialises them straight into the request, so a string works even though\n // the type says number.\n await client.jobs.get({ job_id: id as unknown as number });\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nconst probeVolume: ExistenceProbe = async (client, target) => {\n // The read API wants the 3-level name (catalog.schema.volume), but the env\n // value is usually a /Volumes/... path.\n const raw = field(target, \"path\", \"name\");\n if (!raw) return missingField(\"path\");\n const name = toThreeLevelVolumeName(raw);\n if (!name) {\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"INVALID_NAME\",\n detail: `\"${raw}\" is not a valid volume path (expected /Volumes/catalog/schema/volume or catalog.schema.volume)`,\n };\n }\n try {\n await client.volumes.read({ name });\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nconst probeVectorIndex: ExistenceProbe = async (client, target) => {\n const name = field(target, \"indexName\", \"index_name\", \"name\");\n if (!name) return missingField(\"indexName\");\n try {\n await client.vectorSearchIndexes.getIndex({ index_name: name });\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nconst probeFunction: ExistenceProbe = async (client, target) => {\n const name = field(target, \"name\");\n if (!name) return missingField(\"name\");\n try {\n await client.functions.get({ name });\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nfunction lakebaseAuthHint(message: string): string | undefined {\n if (/password authentication failed/i.test(message)) {\n return (\n \"Lakebase uses an OAuth token as the password, so this usually means the\" +\n \" PGUSER/role doesn't match your identity. Check PGUSER is your exact\" +\n \" login.\"\n );\n }\n return undefined;\n}\n\n// Lakebase has no cheap control-plane `.get()`, so existence is proven by a\n// real connection + `SELECT 1`.\nconst probePostgres: ExistenceProbe = async (client, target) => {\n if (!field(target, \"endpointPath\") && !field(target, \"host\")) {\n return missingField(\"host/endpoint\");\n }\n\n let pool: LakebasePoolHandle | null = null;\n try {\n pool = await getLakebasePool(client);\n await pool.query(\"SELECT 1\");\n return EXISTENCE_OK;\n } catch (err) {\n if (err instanceof AppkitNotInstalledError) {\n return {\n layer: \"existence\",\n status: \"skipped\",\n code: \"APPKIT_NOT_INSTALLED\",\n detail: err.message,\n };\n }\n const message = cleanMessage(err);\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"CONNECTION_FAILED\",\n detail: `could not connect to Lakebase Postgres: ${message}`,\n hint: lakebaseAuthHint(message),\n };\n } finally {\n if (pool) {\n try {\n await pool.end();\n } catch {\n // best-effort close\n }\n }\n }\n};\n\n/**\n * Normalizes a volume reference to the SDK's 3-level `catalog.schema.volume`\n * name, accepting either an already-dotted name or a `/Volumes/c/s/v/...` path.\n */\nexport function toThreeLevelVolumeName(raw: string): string | null {\n const trimmed = raw.trim();\n if (/^[^./\\s]+\\.[^./\\s]+\\.[^./\\s]+$/.test(trimmed)) return trimmed;\n\n const m = trimmed.match(/^\\/Volumes\\/([^/]+)\\/([^/]+)\\/([^/]+)/);\n if (m) return `${m[1]}.${m[2]}.${m[3]}`;\n\n return null;\n}\n\n// Unlisted types fall through to NOT_IMPLEMENTED in runExistenceProbe.\nconst PROBES: Record<string, ExistenceProbe> = {\n sql_warehouse: probeWarehouse,\n serving_endpoint: probeServing,\n genie_space: probeGenie,\n job: probeJob,\n volume: probeVolume,\n vector_search_index: probeVectorIndex,\n uc_function: probeFunction,\n postgres: probePostgres,\n};\n\nexport async function runExistenceProbe(\n client: unknown,\n target: ResourceTarget,\n): Promise<LayerResult> {\n const probe = PROBES[target.type];\n if (!probe) {\n return {\n layer: \"existence\",\n status: \"skipped\",\n code: \"NOT_IMPLEMENTED\",\n detail: `existence check not implemented for ${target.type}`,\n };\n }\n return probe(client as DoctorWorkspaceClient, target);\n}\n"],"mappings":";;;;;;;;;;;AAgBA,MAAM,eAA4B;CAAE,OAAO;CAAa,QAAQ;CAAM;AAgCtE,SAAS,aAAa,KAAkC;AACtD,KAAI,OAAO,OAAO,QAAQ,YAAY,gBAAgB,KAAK;EACzD,MAAM,OAAQ,IAAiC;AAC/C,MAAI,OAAO,SAAS,SAAU,QAAO;;;AAKzC,SAAS,YAAY,KAAkC;AACrD,KAAI,OAAO,OAAO,QAAQ,YAAY,eAAe,KAAK;EACxD,MAAM,OAAQ,IAAgC;AAC9C,MAAI,OAAO,SAAS,YAAY,KAAK,SAAS,EAAG,QAAO;;;AAO5D,SAAS,aAAa,KAAsB;CAC1C,MAAM,MAAM,aAAa,IAAI;CAC7B,MAAM,IAAI,IAAI,MAAM,4BAA4B;AAChD,QAAO,IAAI,EAAE,KAAK;;;;AAKpB,SAAS,UAAU,QAAuC;AACxD,QAAO,MAAM,QAAQ,MAAM,QAAQ,QAAQ,cAAc,aAAa,OAAO;;AAG/E,SAAS,cAAc,KAAc,QAAqC;CACxE,MAAM,SAAS,aAAa,IAAI;CAChC,MAAM,YAAY,YAAY,IAAI;CAClC,MAAM,UAAU,aAAa,IAAI;CACjC,MAAM,KAAK,UAAU,OAAO;CAC5B,MAAM,SAA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,iBAAiB,QAAQ;GAChC;WACO;AACR,MAAI,KACF,KAAI;AACF,SAAM,KAAK,KAAK;UACV;;;;;;;AAWd,SAAgB,uBAAuB,KAA4B;CACjE,MAAM,UAAU,IAAI,MAAM;AAC1B,KAAI,iCAAiC,KAAK,QAAQ,CAAE,QAAO;CAE3D,MAAM,IAAI,QAAQ,MAAM,wCAAwC;AAChE,KAAI,EAAG,QAAO,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE;AAEnC,QAAO;;AAIT,MAAM,SAAyC;CAC7C,eAAe;CACf,kBAAkB;CAClB,aAAa;CACb,KAAK;CACL,QAAQ;CACR,qBAAqB;CACrB,aAAa;CACb,UAAU;CACX;AAED,eAAsB,kBACpB,QACA,QACsB;CACtB,MAAM,QAAQ,OAAO,OAAO;AAC5B,KAAI,CAAC,MACH,QAAO;EACL,OAAO;EACP,QAAQ;EACR,MAAM;EACN,QAAQ,uCAAuC,OAAO;EACvD;AAEH,QAAO,MAAM,QAAiC,OAAO"}
|
|
1
|
+
{"version":3,"file":"checks-existence.js","names":[],"sources":["../../../../src/cli/commands/doctor/checks-existence.ts"],"sourcesContent":["/**\n * Layer: existence — per-resource-type probes that prove a declared resource\n * exists and is reachable via the cheapest read the SDK offers.\n *\n * The client is typed structurally against the facade's modular clients.\n */\n\nimport {\n AppkitNotInstalledError,\n getLakebasePool,\n type LakebasePoolHandle,\n} from \"./databricks-client\";\nimport type { LayerResult, ResourceTarget } from \"./types\";\nimport { errorMessage } from \"./utils\";\n\n/** A passing existence check. Shared, never mutated by callers. */\nconst EXISTENCE_OK: LayerResult = { layer: \"existence\", status: \"ok\" };\n\ninterface DoctorWorkspaceClient {\n warehouses: {\n getWarehouse: (r: { id: string }) => Promise<{ state?: string }>;\n };\n genie: {\n genieGetSpace: (r: { spaceId: string }) => Promise<unknown>;\n };\n jobs: {\n getJob: (r: { jobId: bigint }) => Promise<unknown>;\n };\n vectorSearch: {\n getVectorIndex: (r: { name: string }) => Promise<unknown>;\n };\n modelServing: {\n getInferenceEndpoint: (r: { name: string }) => Promise<unknown>;\n };\n volumes: {\n getVolume: (r: { fullNameArg: string }) => Promise<unknown>;\n };\n functions: {\n getFunction: (r: { fullNameArg: string }) => Promise<unknown>;\n };\n}\n\ntype ExistenceProbe = (\n client: DoctorWorkspaceClient,\n target: ResourceTarget,\n) => Promise<LayerResult>;\n\n// Read the HTTP status / Databricks error code off an ApiError structurally.\n// Two shapes can reach here: the wrapper's `ApiError` (`statusCode` /\n// `errorCode`) and the modular SDK's (`httpStatusCode` / `code`).\nfunction statusCodeOf(err: unknown): number | undefined {\n if (!err || typeof err !== \"object\") return undefined;\n const e = err as { statusCode?: unknown; httpStatusCode?: unknown };\n const code = e.statusCode ?? e.httpStatusCode;\n return typeof code === \"number\" && code >= 0 ? code : undefined;\n}\n\nfunction errorCodeOf(err: unknown): string | undefined {\n if (!err || typeof err !== \"object\") return undefined;\n const e = err as { errorCode?: unknown; code?: unknown };\n const code = e.errorCode ?? e.code;\n return typeof code === \"string\" && code.length > 0 ? code : undefined;\n}\n\n// The SDK message often embeds a JSON blob; pull the inner `message` out so\n// doctor prints one clean line, not a dump.\nfunction cleanMessage(err: unknown): string {\n const raw = errorMessage(err);\n const m = raw.match(/\"message\"\\s*:\\s*\"([^\"]+)\"/);\n return m ? m[1] : raw;\n}\n\n/** The resource's configured identifier (id / name / path / host), for short\n * messages. */\nfunction displayId(target: ResourceTarget): string | null {\n return field(target, \"id\", \"name\", \"path\", \"index_name\", \"indexName\", \"host\");\n}\n\nfunction classifyError(err: unknown, target: ResourceTarget): LayerResult {\n const status = statusCodeOf(err);\n const errorCode = errorCodeOf(err);\n const message = cleanMessage(err);\n const id = displayId(target);\n const quoted = id ? `\"${id}\"` : null;\n\n if (status === 404 || errorCode === \"RESOURCE_DOES_NOT_EXIST\") {\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"NOT_FOUND\",\n detail: quoted ? `${quoted} not found` : \"not found\",\n };\n }\n // A malformed id/name often comes back as 400 rather than 404.\n if (status === 400 || errorCode === \"INVALID_PARAMETER_VALUE\") {\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"INVALID_VALUE\",\n detail: quoted\n ? `${quoted} is not a valid id/name`\n : `invalid id/name: ${message}`,\n };\n }\n // A 403 is genuinely ambiguous: several APIs (jobs, warehouses) return it for a\n // resource that doesn't exist as well as for one you can't read, so claiming\n // \"no permission\" outright would misdiagnose a wrong id. Say both.\n if (status === 403 || errorCode === \"PERMISSION_DENIED\") {\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"ACCESS_DENIED\",\n detail: quoted\n ? `${quoted} not found, or you don't have access to it`\n : \"not found, or you don't have access to it\",\n };\n }\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"PROBE_FAILED\",\n detail: quoted\n ? `read failed for ${quoted}: ${message}`\n : `read failed: ${message}`,\n };\n}\n\n/** Normalizes a field key so camelCase (`indexName`) and snake_case\n * (`index_name`) spellings match. */\nfunction normalizeKey(key: string): string {\n return key.toLowerCase().replace(/[_-]/g, \"\");\n}\n\n/** Looks up a resolved field value by any of the accepted key spellings. */\nfunction field(target: ResourceTarget, ...names: string[]): string | null {\n const wanted = new Set(names.map(normalizeKey));\n for (const [key, value] of Object.entries(target.fieldValues)) {\n if (wanted.has(normalizeKey(key)) && value.length > 0) return value;\n }\n return null;\n}\n\nfunction missingField(fieldName: string): LayerResult {\n return {\n layer: \"existence\",\n status: \"skipped\",\n code: \"MISSING_FIELD\",\n detail: `no ${fieldName} configured — can't probe`,\n };\n}\n\nconst probeWarehouse: ExistenceProbe = async (client, target) => {\n const id = field(target, \"id\");\n if (!id) return missingField(\"id\");\n try {\n const wh = await client.warehouses.getWarehouse({ id });\n const state = wh.state;\n if (state && state !== \"RUNNING\") {\n return {\n layer: \"existence\",\n status: \"warn\",\n code: \"WAREHOUSE_NOT_RUNNING\",\n detail: `warehouse exists but is ${state} (will cold-start on first query)`,\n };\n }\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nconst probeServing: ExistenceProbe = async (client, target) => {\n const name = field(target, \"name\");\n // The API only accepts a name; if configured by id, probe with it anyway and\n // flag the likely cause on failure.\n const idOnly = name === null ? field(target, \"id\") : null;\n const value = name ?? idOnly;\n if (!value) return missingField(\"name\");\n try {\n await client.modelServing.getInferenceEndpoint({ name: value });\n return EXISTENCE_OK;\n } catch (err) {\n const result = classifyError(err, target);\n if (idOnly && result.status === \"error\") {\n result.hint =\n \"Serving endpoints are looked up by name, but this resource is configured by id. Set DATABRICKS_SERVING_ENDPOINT_NAME to the endpoint's name.\";\n }\n return result;\n }\n};\n\nconst probeGenie: ExistenceProbe = async (client, target) => {\n const spaceId = field(target, \"id\");\n if (!spaceId) return missingField(\"id\");\n try {\n await client.genie.genieGetSpace({ spaceId });\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nconst probeJob: ExistenceProbe = async (client, target) => {\n const raw = field(target, \"id\");\n if (!raw) return missingField(\"id\");\n const id = raw.trim();\n // Validate the digits directly rather than via Number(): job ids are int64, so\n // past 2^53 Number() silently rounds (and Number.isInteger still passes),\n // which would probe a *different* job and report a false not-found. A string\n // check also rejects \"1e3\" and \"0x10\", both of which Number() would accept.\n if (!/^\\d+$/.test(id)) {\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"INVALID_ID\",\n detail: `\"${raw}\" is not a valid job id (expected an integer)`,\n };\n }\n try {\n // BigInt keeps int64 precision (the digits were validated above).\n await client.jobs.getJob({ jobId: BigInt(id) });\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nconst probeVolume: ExistenceProbe = async (client, target) => {\n // The read API wants the 3-level name (catalog.schema.volume), but the env\n // value is usually a /Volumes/... path.\n const raw = field(target, \"path\", \"name\");\n if (!raw) return missingField(\"path\");\n const name = toThreeLevelVolumeName(raw);\n if (!name) {\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"INVALID_NAME\",\n detail: `\"${raw}\" is not a valid volume path (expected /Volumes/catalog/schema/volume or catalog.schema.volume)`,\n };\n }\n try {\n await client.volumes.getVolume({ fullNameArg: name });\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nconst probeVectorIndex: ExistenceProbe = async (client, target) => {\n const name = field(target, \"indexName\", \"index_name\", \"name\");\n if (!name) return missingField(\"indexName\");\n try {\n await client.vectorSearch.getVectorIndex({ name });\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nconst probeFunction: ExistenceProbe = async (client, target) => {\n const name = field(target, \"name\");\n if (!name) return missingField(\"name\");\n try {\n await client.functions.getFunction({ fullNameArg: name });\n return EXISTENCE_OK;\n } catch (err) {\n return classifyError(err, target);\n }\n};\n\nfunction lakebaseAuthHint(message: string): string | undefined {\n if (/password authentication failed/i.test(message)) {\n return (\n \"Lakebase uses an OAuth token as the password, so this usually means the\" +\n \" PGUSER/role doesn't match your identity. Check PGUSER is your exact\" +\n \" login.\"\n );\n }\n return undefined;\n}\n\n// Lakebase has no cheap control-plane `.get()`, so existence is proven by a\n// real connection + `SELECT 1`.\nconst probePostgres: ExistenceProbe = async (client, target) => {\n if (!field(target, \"endpointPath\") && !field(target, \"host\")) {\n return missingField(\"host/endpoint\");\n }\n\n let pool: LakebasePoolHandle | null = null;\n try {\n pool = await getLakebasePool(client);\n await pool.query(\"SELECT 1\");\n return EXISTENCE_OK;\n } catch (err) {\n if (err instanceof AppkitNotInstalledError) {\n return {\n layer: \"existence\",\n status: \"skipped\",\n code: \"APPKIT_NOT_INSTALLED\",\n detail: err.message,\n };\n }\n const message = cleanMessage(err);\n return {\n layer: \"existence\",\n status: \"error\",\n code: \"CONNECTION_FAILED\",\n detail: `could not connect to Lakebase Postgres: ${message}`,\n hint: lakebaseAuthHint(message),\n };\n } finally {\n if (pool) {\n try {\n await pool.end();\n } catch {\n // best-effort close\n }\n }\n }\n};\n\n/**\n * Normalizes a volume reference to the SDK's 3-level `catalog.schema.volume`\n * name, accepting either an already-dotted name or a `/Volumes/c/s/v/...` path.\n */\nexport function toThreeLevelVolumeName(raw: string): string | null {\n const trimmed = raw.trim();\n if (/^[^./\\s]+\\.[^./\\s]+\\.[^./\\s]+$/.test(trimmed)) return trimmed;\n\n const m = trimmed.match(/^\\/Volumes\\/([^/]+)\\/([^/]+)\\/([^/]+)/);\n if (m) return `${m[1]}.${m[2]}.${m[3]}`;\n\n return null;\n}\n\n// Unlisted types fall through to NOT_IMPLEMENTED in runExistenceProbe.\nconst PROBES: Record<string, ExistenceProbe> = {\n sql_warehouse: probeWarehouse,\n serving_endpoint: probeServing,\n genie_space: probeGenie,\n job: probeJob,\n volume: probeVolume,\n vector_search_index: probeVectorIndex,\n uc_function: probeFunction,\n postgres: probePostgres,\n};\n\nexport async function runExistenceProbe(\n client: unknown,\n target: ResourceTarget,\n): Promise<LayerResult> {\n const probe = PROBES[target.type];\n if (!probe) {\n return {\n layer: \"existence\",\n status: \"skipped\",\n code: \"NOT_IMPLEMENTED\",\n detail: `existence check not implemented for ${target.type}`,\n };\n }\n return probe(client as DoctorWorkspaceClient, target);\n}\n"],"mappings":";;;;;;;;;;;AAgBA,MAAM,eAA4B;CAAE,OAAO;CAAa,QAAQ;CAAM;AAkCtE,SAAS,aAAa,KAAkC;AACtD,KAAI,CAAC,OAAO,OAAO,QAAQ,SAAU,QAAO;CAC5C,MAAM,IAAI;CACV,MAAM,OAAO,EAAE,cAAc,EAAE;AAC/B,QAAO,OAAO,SAAS,YAAY,QAAQ,IAAI,OAAO;;AAGxD,SAAS,YAAY,KAAkC;AACrD,KAAI,CAAC,OAAO,OAAO,QAAQ,SAAU,QAAO;CAC5C,MAAM,IAAI;CACV,MAAM,OAAO,EAAE,aAAa,EAAE;AAC9B,QAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,OAAO;;AAK9D,SAAS,aAAa,KAAsB;CAC1C,MAAM,MAAM,aAAa,IAAI;CAC7B,MAAM,IAAI,IAAI,MAAM,4BAA4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AAI,OAAkC;AACtC,KAAI;AACF,SAAO,MAAM,gBAAgB,OAAO;AACpC,QAAM,KAAK,MAAM,WAAW;AAC5B,SAAO;UACA,KAAK;AACZ,MAAI,eAAe,wBACjB,QAAO;GACL,OAAO;GACP,QAAQ;GACR,MAAM;GACN,QAAQ,IAAI;GACb;EAEH,MAAM,UAAU,aAAa,IAAI;AACjC,SAAO;GACL,OAAO;GACP,QAAQ;GACR,MAAM;GACN,QAAQ,2CAA2C;GACnD,MAAM,iBAAiB,QAAQ;GAChC;WACO;AACR,MAAI,KACF,KAAI;AACF,SAAM,KAAK,KAAK;UACV;;;;;;;AAWd,SAAgB,uBAAuB,KAA4B;CACjE,MAAM,UAAU,IAAI,MAAM;AAC1B,KAAI,iCAAiC,KAAK,QAAQ,CAAE,QAAO;CAE3D,MAAM,IAAI,QAAQ,MAAM,wCAAwC;AAChE,KAAI,EAAG,QAAO,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE;AAEnC,QAAO;;AAIT,MAAM,SAAyC;CAC7C,eAAe;CACf,kBAAkB;CAClB,aAAa;CACb,KAAK;CACL,QAAQ;CACR,qBAAqB;CACrB,aAAa;CACb,UAAU;CACX;AAED,eAAsB,kBACpB,QACA,QACsB;CACtB,MAAM,QAAQ,OAAO,OAAO;AAC5B,KAAI,CAAC,MACH,QAAO;EACL,OAAO;EACP,QAAQ;EACR,MAAM;EACN,QAAQ,uCAAuC,OAAO;EACvD;AAEH,QAAO,MAAM,QAAiC,OAAO"}
|
|
@@ -11,12 +11,17 @@ import { SdkNotInstalledError, getProfileHost, getServiceClient } from "./databr
|
|
|
11
11
|
* contacted: `DATABRICKS_HOST` wins the host when set, but a profile supplies it
|
|
12
12
|
* otherwise, so the env var alone can't tell you the workspace in play.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
* the
|
|
14
|
+
* Resolved from env + profile only (no network), so it's available even when
|
|
15
|
+
* the credentials fail. Undefined when resolution itself fails (e.g. a missing
|
|
16
|
+
* profile, or no host anywhere).
|
|
16
17
|
*/
|
|
17
|
-
function resolvedHostOf(client) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
async function resolvedHostOf(client) {
|
|
19
|
+
try {
|
|
20
|
+
const host = await client?.getHost?.();
|
|
21
|
+
return typeof host === "string" && host.length > 0 ? host : void 0;
|
|
22
|
+
} catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
/** Compares hosts ignoring scheme, trailing slash, and case, so
|
|
22
27
|
* `https://foo.com/` and `foo.com` count as the same workspace. */
|
|
@@ -38,14 +43,6 @@ async function hostProfileConflict(envHost, profile) {
|
|
|
38
43
|
return `DATABRICKS_HOST (${envHost}) and profile "${profile}" (${profileHost}) point at different workspaces. DATABRICKS_HOST wins the host while the profile still supplies credentials — unset one of them.`;
|
|
39
44
|
}
|
|
40
45
|
/**
|
|
41
|
-
* Last-resort host recovery for when the client never got built: the SDK's
|
|
42
|
-
* ConfigError appends the resolved config as `host=<url>, profile=…`.
|
|
43
|
-
*/
|
|
44
|
-
function hostFromError(message) {
|
|
45
|
-
const match = message.match(/host=([^\s,]+)/);
|
|
46
|
-
return match ? match[1].replace(/[.,]+$/, "") : void 0;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
46
|
* Strips URL userinfo (`user:pass@`) from a host, so credentials someone
|
|
50
47
|
* embedded in `DATABRICKS_HOST` never reach the report or `--json`. Returns the
|
|
51
48
|
* input unchanged when it has no userinfo or isn't a parseable URL.
|
|
@@ -105,9 +102,9 @@ async function checkAuth(options) {
|
|
|
105
102
|
try {
|
|
106
103
|
const { client } = await getServiceClient(options.profile);
|
|
107
104
|
built = client;
|
|
108
|
-
const me = await withTimeout(client.currentUser.me());
|
|
105
|
+
const me = await withTimeout(client.currentUser.me({}));
|
|
109
106
|
const who = me.userName ?? me.id ?? "unknown";
|
|
110
|
-
const resolvedHost = sanitizeHost(resolvedHostOf(client)) ?? host;
|
|
107
|
+
const resolvedHost = sanitizeHost(await resolvedHostOf(client)) ?? host;
|
|
111
108
|
if (conflict) return {
|
|
112
109
|
client,
|
|
113
110
|
result: {
|
|
@@ -140,7 +137,7 @@ async function checkAuth(options) {
|
|
|
140
137
|
const sdkProfile = raw.match(/--profile\s+(\S+)/)?.[1];
|
|
141
138
|
const usedProfile = profile ?? sdkProfile;
|
|
142
139
|
const shownProfile = profile ?? (sdkProfile ? `${sdkProfile} (resolved)` : void 0);
|
|
143
|
-
const shownHost = sanitizeHost(resolvedHostOf(built)
|
|
140
|
+
const shownHost = sanitizeHost(await resolvedHostOf(built)) ?? host;
|
|
144
141
|
return { result: {
|
|
145
142
|
status: "error",
|
|
146
143
|
code: "AUTH_FAILED",
|
|
@@ -163,8 +160,8 @@ async function checkAuth(options) {
|
|
|
163
160
|
function authFailureHint(message, profile) {
|
|
164
161
|
const loginCmd = profile ? `databricks auth login --profile ${profile}` : "databricks auth login";
|
|
165
162
|
if (/ENOTFOUND|EAI_AGAIN|ECONNREFUSED|ECONNRESET|ETIMEDOUT|getaddrinfo|certificate|self.signed|unable to verify|TLS/i.test(message)) return "Check that the workspace host is correct and reachable (verify DATABRICKS_HOST or the profile's host, and that you're online).";
|
|
166
|
-
if (/has no .* profile configured|profile .*
|
|
167
|
-
if (/cannot get access token|refresh token|reauthenticate|databricks auth token|token .*expired|cannot configure default credentials|default auth|no .*credentials/i.test(message)) return `Run \`${loginCmd}\` and confirm the profile/host is the one you intend.`;
|
|
163
|
+
if (/has no .* profile configured|profile .*(does not exist|not found)/i.test(message)) return `Run \`${loginCmd}\`, or pass an existing profile via --profile.`;
|
|
164
|
+
if (/cannot get access token|refresh token|reauthenticate|databricks auth token|token .*expired|cannot configure default credentials|default auth|no .*credentials|host is required/i.test(message)) return `Run \`${loginCmd}\` and confirm the profile/host is the one you intend.`;
|
|
168
165
|
}
|
|
169
166
|
/** The default local env file, matching the `.env` the CLI auto-loads. */
|
|
170
167
|
const DEFAULT_ENV_FILE = ".env";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checks.js","names":[],"sources":["../../../../src/cli/commands/doctor/checks.ts"],"sourcesContent":["/**\n * The `auth` and `config` layer checks. (The `existence` layer's per-type\n * probes live in `checks-existence.ts`.)\n */\n\nimport {\n getProfileHost,\n getServiceClient,\n SdkNotInstalledError,\n} from \"./databricks-client\";\nimport type {\n AuthCheckResult,\n DoctorOptions,\n LayerResult,\n ResourceTarget,\n} from \"./types\";\nimport { errorMessage, withTimeout } from \"./utils\";\n\n/** The auth result plus the resolved client (present only on success). */\nexport interface AuthOutcome {\n result: AuthCheckResult;\n client?: unknown;\n}\n\ninterface CurrentUserClient {\n currentUser: {\n me: () => Promise<{ id?: string; userName?: string }>;\n };\n}\n\n/** Just the resolved config off a WorkspaceClient, read structurally to keep\n * `shared` SDK-free. */\ninterface ConfiguredClient {\n config?: { host?: unknown };\n}\n\n/**\n * The host the SDK actually resolved. This is the authority for what was\n * contacted: `DATABRICKS_HOST` wins the host when set, but a profile supplies it\n * otherwise, so the env var alone can't tell you the workspace in play.\n *\n * Only populated once the SDK has resolved its config, which it does lazily on\n * the first API call — reading it right after construction yields undefined.\n */\nfunction resolvedHostOf(client: unknown): string | undefined {\n const host = (client as ConfiguredClient | undefined)?.config?.host;\n return typeof host === \"string\" && host.length > 0 ? host : undefined;\n}\n\n/** Compares hosts ignoring scheme, trailing slash, and case, so\n * `https://foo.com/` and `foo.com` count as the same workspace. */\nfunction sameHost(a: string, b: string): boolean {\n const normalize = (h: string) =>\n h\n .trim()\n .toLowerCase()\n .replace(/^https?:\\/\\//, \"\")\n .replace(/\\/+$/, \"\");\n return normalize(a) === normalize(b);\n}\n\n/**\n * Warns when `DATABRICKS_HOST` and the named profile point at different\n * workspaces. The SDK resolves these per-field — env wins the host while the\n * profile still supplies the credentials — so this combination silently\n * authenticates with one workspace's token against another's URL. Almost always\n * a mistake, and the resulting 401/403 gives no hint of the split.\n */\nasync function hostProfileConflict(\n envHost: string | undefined,\n profile: string | undefined,\n): Promise<string | undefined> {\n if (!envHost || !profile) return undefined;\n const profileHost = await getProfileHost(profile);\n if (!profileHost || sameHost(envHost, profileHost)) return undefined;\n return (\n `DATABRICKS_HOST (${envHost}) and profile \"${profile}\" ` +\n `(${profileHost}) point at different workspaces. DATABRICKS_HOST wins the ` +\n `host while the profile still supplies credentials — unset one of them.`\n );\n}\n\n/**\n * Last-resort host recovery for when the client never got built: the SDK's\n * ConfigError appends the resolved config as `host=<url>, profile=…`.\n */\nfunction hostFromError(message: string): string | undefined {\n const match = message.match(/host=([^\\s,]+)/);\n // The config list is prose-terminated (\"…databricks.com.\"), so drop trailing\n // punctuation the capture picked up.\n return match ? match[1].replace(/[.,]+$/, \"\") : undefined;\n}\n\n/**\n * Strips URL userinfo (`user:pass@`) from a host, so credentials someone\n * embedded in `DATABRICKS_HOST` never reach the report or `--json`. Returns the\n * input unchanged when it has no userinfo or isn't a parseable URL.\n */\nexport function sanitizeHost(host: string | undefined): string | undefined {\n if (host === undefined) return undefined;\n try {\n const url = new URL(host);\n if (!url.username && !url.password) return host;\n url.username = \"\";\n url.password = \"\";\n return url.toString();\n } catch {\n // An unparseable host still can't be echoed verbatim — a typo'd scheme\n // (`ht!tp://user:pass@x`) keeps its credentials otherwise. Strip any\n // `userinfo@` span textually, since URL parsing is unavailable here. Covers\n // both a scheme-prefixed host and a bare `user:pass@host`.\n return host.replace(/^([^/@]*\\/\\/)?[^/@]*@/, (_, scheme) => scheme ?? \"\");\n }\n}\n\n/**\n * Validates `DATABRICKS_HOST` before the SDK sees it, so an unfilled placeholder\n * gets a clear message instead of the SDK's opaque credentials error. Returns an\n * error message, or null when the host is acceptable or unset.\n *\n * Every message quotes the **sanitized** host: `detail` prints unconditionally in\n * both the human report and `--json` (only `raw` is `--detail`-gated), so echoing\n * the raw value would leak `user:pass@` credentials into CI logs.\n */\nexport function validateHost(host: string | undefined): string | null {\n if (host === undefined || host.trim().length === 0) return null;\n const shown = sanitizeHost(host);\n\n let url: URL;\n try {\n url = new URL(host);\n } catch {\n return `DATABRICKS_HOST is not a valid URL: \"${shown}\"`;\n }\n\n if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n return `DATABRICKS_HOST must be an http(s) URL: \"${shown}\"`;\n }\n\n // Reject only what can't name a host at all: a hostname with no alphanumeric\n // character, e.g. the template's unfilled \"https://...\". Requiring a dotted\n // label instead would reject legitimate single-label hosts — `localhost`, a\n // tunnel, or an internal DNS name.\n if (!/[a-z0-9]/i.test(url.hostname)) {\n return `DATABRICKS_HOST looks like an unfilled placeholder: \"${shown}\"`;\n }\n\n return null;\n}\n\n/**\n * Layer: auth. Runs once, app-wide; a failure short-circuits every resource's\n * existence check (they all need the client).\n */\nexport async function checkAuth(options: DoctorOptions): Promise<AuthOutcome> {\n // Validate the raw value, but only ever store/report the sanitized one so\n // credentials embedded in the URL (user:pass@) never reach the report/--json.\n const rawHost = process.env.DATABRICKS_HOST;\n const host = sanitizeHost(rawHost);\n // The identity source shown in the report: explicit --profile, else the env\n // var the SDK would pick up.\n const profile = options.profile ?? process.env.DATABRICKS_CONFIG_PROFILE;\n const hostError = validateHost(rawHost);\n if (hostError) {\n return {\n result: {\n status: \"error\",\n code: \"HOST_INVALID\",\n detail: hostError,\n host,\n profile,\n },\n };\n }\n\n // An env/profile split is a config problem, so it's worth reporting whether or\n // not the credentials happen to work. Resolved offline from ~/.databrickscfg.\n const conflict = await hostProfileConflict(host, profile);\n\n // Holds the client so the catch block can read the host the SDK resolved\n // (which may have come from the profile, not env).\n let built: unknown;\n try {\n const { client } = await getServiceClient(options.profile);\n built = client;\n // Bound the live call so an unresponsive workspace can't hang the CLI; a\n // timeout throws and is reported as an auth failure below.\n const me = await withTimeout(\n (client as CurrentUserClient).currentUser.me(),\n );\n const who = me.userName ?? me.id ?? \"unknown\";\n // Read only now: the SDK resolves its config lazily on the first call, so\n // before me() the host is still undefined.\n const resolvedHost = sanitizeHost(resolvedHostOf(client)) ?? host;\n\n // Credentials work, but the env/profile split still needs fixing — surface\n // it as a warning rather than letting a green tick imply all is well.\n if (conflict) {\n return {\n client,\n result: {\n status: \"warn\",\n code: \"HOST_PROFILE_CONFLICT\",\n detail: `authenticated as ${who}`,\n hint: conflict,\n host: resolvedHost,\n profile,\n },\n };\n }\n\n return {\n client,\n result: {\n status: \"ok\",\n code: \"AUTH_OK\",\n detail: `authenticated as ${who}`,\n host: resolvedHost,\n profile,\n },\n };\n } catch (err) {\n if (err instanceof SdkNotInstalledError) {\n return {\n result: {\n status: \"error\",\n code: \"SDK_NOT_INSTALLED\",\n detail: err.message,\n profile,\n },\n };\n }\n const raw = errorMessage(err);\n // When no profile was given up front, recover the one the SDK resolved (it's\n // embedded in the error) and mark it \"(resolved)\".\n const sdkProfile = raw.match(/--profile\\s+(\\S+)/)?.[1];\n const usedProfile = profile ?? sdkProfile;\n const shownProfile =\n profile ?? (sdkProfile ? `${sdkProfile} (resolved)` : undefined);\n // Prefer the host the SDK resolved (covers a profile-supplied host), then\n // the one embedded in its error, then the raw env var.\n const shownHost =\n sanitizeHost(resolvedHostOf(built) ?? hostFromError(raw)) ?? host;\n return {\n result: {\n status: \"error\",\n code: \"AUTH_FAILED\",\n detail: \"authentication failed\",\n // A conflict explains the failure better than a generic login hint.\n hint: conflict ?? authFailureHint(raw, usedProfile),\n host: shownHost,\n profile: shownProfile,\n raw,\n },\n };\n }\n}\n\n/**\n * Suggests a next action for common auth failures, matched most specific first.\n * Returns undefined for an unrecognized failure.\n *\n * `profile` is the explicit --profile, else the one the SDK resolved (DEFAULT /\n * DATABRICKS_CONFIG_PROFILE) and embedded in its error, so the login hint\n * targets what actually failed.\n */\nfunction authFailureHint(\n message: string,\n profile?: string,\n): string | undefined {\n const loginCmd = profile\n ? `databricks auth login --profile ${profile}`\n : \"databricks auth login\";\n // Network-level failure (unreachable host, DNS, TLS). Matched first — more\n // specific than a credential problem and needs a different fix.\n if (\n /ENOTFOUND|EAI_AGAIN|ECONNREFUSED|ECONNRESET|ETIMEDOUT|getaddrinfo|certificate|self.signed|unable to verify|TLS/i.test(\n message,\n )\n ) {\n return \"Check that the workspace host is correct and reachable (verify DATABRICKS_HOST or the profile's host, and that you're online).\";\n }\n if (\n /has no .* profile configured|profile .* (does not exist|not found)/i.test(\n message,\n )\n ) {\n return `Run \\`${loginCmd}\\`, or pass an existing profile via --profile.`;\n }\n // Expired/failed token, or no credentials resolved: same next action.\n if (\n /cannot get access token|refresh token|reauthenticate|databricks auth token|token .*expired|cannot configure default credentials|default auth|no .*credentials/i.test(\n message,\n )\n ) {\n return `Run \\`${loginCmd}\\` and confirm the profile/host is the one you intend.`;\n }\n return undefined;\n}\n\n/** The default local env file, matching the `.env` the CLI auto-loads. */\nexport const DEFAULT_ENV_FILE = \".env\";\n\n/** What the config layer needs beyond the target to name the *right* file and\n * give advice that fits the app's actual deploy wiring. */\nexport interface ConfigCheckContext {\n /** Where local values were loaded from: `.env`, or `--env-file`'s path. Named\n * in the message so it's clear this is the local env file, not `app.yaml` /\n * `databricks.yml`. */\n envFile: string;\n /** Env vars `app.yaml` already wires. Lets the hint be dropped entirely for a\n * var whose deploy wiring is already correct. */\n wiredEnvVars: ReadonlySet<string>;\n}\n\n/**\n * Layer: config. Offline presence check of each declared env var; whether a set\n * value points at a real resource is the existence layer's job.\n *\n * The message names the env file explicitly, because \"not set\" alone reads as\n * ambiguous between the three files a var can be declared in — the local env\n * file, `app.yaml`, and `databricks.yml`. This layer only ever means the first.\n */\nexport function checkConfig(\n target: ResourceTarget,\n ctx: ConfigCheckContext,\n): LayerResult {\n const missing: string[] = [];\n\n for (const envVar of target.envVars) {\n const value = process.env[envVar];\n if (value === undefined || value.trim().length === 0) {\n missing.push(envVar);\n }\n }\n\n if (missing.length > 0) {\n const plural = missing.length > 1;\n const names = missing.join(\", \");\n const them = plural ? \"them\" : \"it\";\n // Deploy reads app.yaml, never the env file. When wiring is already correct\n // there's nothing to add beyond \"set it\", which the detail line just said —\n // so no hint at all. Only genuinely-missing wiring earns one.\n const allWired = missing.every((name) => ctx.wiredEnvVars.has(name));\n return {\n layer: \"config\",\n status: target.required ? \"error\" : \"warn\",\n code: target.required ? \"ENV_MISSING\" : \"ENV_MISSING_OPTIONAL\",\n detail: `${names} ${plural ? \"are\" : \"is\"} not set in \\`${ctx.envFile}\\`${\n target.required ? \"\" : \" (optional)\"\n }`,\n hint: allWired\n ? undefined\n : `Add ${them} to \\`${ctx.envFile}\\` to run locally, and wire ${them} through app.yaml + databricks.yml for deploy.`,\n };\n }\n\n return { layer: \"config\", status: \"ok\" };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4CA,SAAS,eAAe,QAAqC;CAC3D,MAAM,OAAQ,QAAyC,QAAQ;AAC/D,QAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,OAAO;;;;AAK9D,SAAS,SAAS,GAAW,GAAoB;CAC/C,MAAM,aAAa,MACjB,EACG,MAAM,CACN,aAAa,CACb,QAAQ,gBAAgB,GAAG,CAC3B,QAAQ,QAAQ,GAAG;AACxB,QAAO,UAAU,EAAE,KAAK,UAAU,EAAE;;;;;;;;;AAUtC,eAAe,oBACb,SACA,SAC6B;AAC7B,KAAI,CAAC,WAAW,CAAC,QAAS,QAAO;CACjC,MAAM,cAAc,MAAM,eAAe,QAAQ;AACjD,KAAI,CAAC,eAAe,SAAS,SAAS,YAAY,CAAE,QAAO;AAC3D,QACE,oBAAoB,QAAQ,iBAAiB,QAAQ,KACjD,YAAY;;;;;;AASpB,SAAS,cAAc,SAAqC;CAC1D,MAAM,QAAQ,QAAQ,MAAM,iBAAiB;AAG7C,QAAO,QAAQ,MAAM,GAAG,QAAQ,UAAU,GAAG,GAAG;;;;;;;AAQlD,SAAgB,aAAa,MAA8C;AACzE,KAAI,SAAS,OAAW,QAAO;AAC/B,KAAI;EACF,MAAM,MAAM,IAAI,IAAI,KAAK;AACzB,MAAI,CAAC,IAAI,YAAY,CAAC,IAAI,SAAU,QAAO;AAC3C,MAAI,WAAW;AACf,MAAI,WAAW;AACf,SAAO,IAAI,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KAAK,gBAAgB,IAAI,QAAQ,IACpE,OAAO,WAAW,KAAK;GAEzB,MAAM,WACF,SACA,OAAO,KAAK,QAAQ,IAAI,QAAQ,8BAA8B,KAAK;GACxE;;AAGH,QAAO;EAAE,OAAO;EAAU,QAAQ;EAAM"}
|
|
1
|
+
{"version":3,"file":"checks.js","names":[],"sources":["../../../../src/cli/commands/doctor/checks.ts"],"sourcesContent":["/**\n * The `auth` and `config` layer checks. (The `existence` layer's per-type\n * probes live in `checks-existence.ts`.)\n */\n\nimport {\n getProfileHost,\n getServiceClient,\n SdkNotInstalledError,\n} from \"./databricks-client\";\nimport type {\n AuthCheckResult,\n DoctorOptions,\n LayerResult,\n ResourceTarget,\n} from \"./types\";\nimport { errorMessage, withTimeout } from \"./utils\";\n\n/** The auth result plus the resolved client (present only on success). */\nexport interface AuthOutcome {\n result: AuthCheckResult;\n client?: unknown;\n}\n\ninterface CurrentUserClient {\n currentUser: {\n me: (req: object) => Promise<{ id?: string; userName?: string }>;\n };\n}\n\n/** The host resolver off a WorkspaceClient, read structurally. */\ninterface HostClient {\n getHost?: () => Promise<string>;\n}\n\n/**\n * The host the SDK actually resolved. This is the authority for what was\n * contacted: `DATABRICKS_HOST` wins the host when set, but a profile supplies it\n * otherwise, so the env var alone can't tell you the workspace in play.\n *\n * Resolved from env + profile only (no network), so it's available even when\n * the credentials fail. Undefined when resolution itself fails (e.g. a missing\n * profile, or no host anywhere).\n */\nasync function resolvedHostOf(client: unknown): Promise<string | undefined> {\n try {\n const host = await (client as HostClient | undefined)?.getHost?.();\n return typeof host === \"string\" && host.length > 0 ? host : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** Compares hosts ignoring scheme, trailing slash, and case, so\n * `https://foo.com/` and `foo.com` count as the same workspace. */\nfunction sameHost(a: string, b: string): boolean {\n const normalize = (h: string) =>\n h\n .trim()\n .toLowerCase()\n .replace(/^https?:\\/\\//, \"\")\n .replace(/\\/+$/, \"\");\n return normalize(a) === normalize(b);\n}\n\n/**\n * Warns when `DATABRICKS_HOST` and the named profile point at different\n * workspaces. The SDK resolves these per-field — env wins the host while the\n * profile still supplies the credentials — so this combination silently\n * authenticates with one workspace's token against another's URL. Almost always\n * a mistake, and the resulting 401/403 gives no hint of the split.\n */\nasync function hostProfileConflict(\n envHost: string | undefined,\n profile: string | undefined,\n): Promise<string | undefined> {\n if (!envHost || !profile) return undefined;\n const profileHost = await getProfileHost(profile);\n if (!profileHost || sameHost(envHost, profileHost)) return undefined;\n return (\n `DATABRICKS_HOST (${envHost}) and profile \"${profile}\" ` +\n `(${profileHost}) point at different workspaces. DATABRICKS_HOST wins the ` +\n `host while the profile still supplies credentials — unset one of them.`\n );\n}\n\n/**\n * Strips URL userinfo (`user:pass@`) from a host, so credentials someone\n * embedded in `DATABRICKS_HOST` never reach the report or `--json`. Returns the\n * input unchanged when it has no userinfo or isn't a parseable URL.\n */\nexport function sanitizeHost(host: string | undefined): string | undefined {\n if (host === undefined) return undefined;\n try {\n const url = new URL(host);\n if (!url.username && !url.password) return host;\n url.username = \"\";\n url.password = \"\";\n return url.toString();\n } catch {\n // An unparseable host still can't be echoed verbatim — a typo'd scheme\n // (`ht!tp://user:pass@x`) keeps its credentials otherwise. Strip any\n // `userinfo@` span textually, since URL parsing is unavailable here. Covers\n // both a scheme-prefixed host and a bare `user:pass@host`.\n return host.replace(/^([^/@]*\\/\\/)?[^/@]*@/, (_, scheme) => scheme ?? \"\");\n }\n}\n\n/**\n * Validates `DATABRICKS_HOST` before the SDK sees it, so an unfilled placeholder\n * gets a clear message instead of the SDK's opaque credentials error. Returns an\n * error message, or null when the host is acceptable or unset.\n *\n * Every message quotes the **sanitized** host: `detail` prints unconditionally in\n * both the human report and `--json` (only `raw` is `--detail`-gated), so echoing\n * the raw value would leak `user:pass@` credentials into CI logs.\n */\nexport function validateHost(host: string | undefined): string | null {\n if (host === undefined || host.trim().length === 0) return null;\n const shown = sanitizeHost(host);\n\n let url: URL;\n try {\n url = new URL(host);\n } catch {\n return `DATABRICKS_HOST is not a valid URL: \"${shown}\"`;\n }\n\n if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n return `DATABRICKS_HOST must be an http(s) URL: \"${shown}\"`;\n }\n\n // Reject only what can't name a host at all: a hostname with no alphanumeric\n // character, e.g. the template's unfilled \"https://...\". Requiring a dotted\n // label instead would reject legitimate single-label hosts — `localhost`, a\n // tunnel, or an internal DNS name.\n if (!/[a-z0-9]/i.test(url.hostname)) {\n return `DATABRICKS_HOST looks like an unfilled placeholder: \"${shown}\"`;\n }\n\n return null;\n}\n\n/**\n * Layer: auth. Runs once, app-wide; a failure short-circuits every resource's\n * existence check (they all need the client).\n */\nexport async function checkAuth(options: DoctorOptions): Promise<AuthOutcome> {\n // Validate the raw value, but only ever store/report the sanitized one so\n // credentials embedded in the URL (user:pass@) never reach the report/--json.\n const rawHost = process.env.DATABRICKS_HOST;\n const host = sanitizeHost(rawHost);\n // The identity source shown in the report: explicit --profile, else the env\n // var the SDK would pick up.\n const profile = options.profile ?? process.env.DATABRICKS_CONFIG_PROFILE;\n const hostError = validateHost(rawHost);\n if (hostError) {\n return {\n result: {\n status: \"error\",\n code: \"HOST_INVALID\",\n detail: hostError,\n host,\n profile,\n },\n };\n }\n\n // An env/profile split is a config problem, so it's worth reporting whether or\n // not the credentials happen to work. Resolved offline from ~/.databrickscfg.\n const conflict = await hostProfileConflict(host, profile);\n\n // Holds the client so the catch block can read the host the SDK resolved\n // (which may have come from the profile, not env).\n let built: unknown;\n try {\n const { client } = await getServiceClient(options.profile);\n built = client;\n // Bound the live call so an unresponsive workspace can't hang the CLI; a\n // timeout throws and is reported as an auth failure below.\n const me = await withTimeout(\n (client as CurrentUserClient).currentUser.me({}),\n );\n const who = me.userName ?? me.id ?? \"unknown\";\n const resolvedHost = sanitizeHost(await resolvedHostOf(client)) ?? host;\n\n // Credentials work, but the env/profile split still needs fixing — surface\n // it as a warning rather than letting a green tick imply all is well.\n if (conflict) {\n return {\n client,\n result: {\n status: \"warn\",\n code: \"HOST_PROFILE_CONFLICT\",\n detail: `authenticated as ${who}`,\n hint: conflict,\n host: resolvedHost,\n profile,\n },\n };\n }\n\n return {\n client,\n result: {\n status: \"ok\",\n code: \"AUTH_OK\",\n detail: `authenticated as ${who}`,\n host: resolvedHost,\n profile,\n },\n };\n } catch (err) {\n if (err instanceof SdkNotInstalledError) {\n return {\n result: {\n status: \"error\",\n code: \"SDK_NOT_INSTALLED\",\n detail: err.message,\n profile,\n },\n };\n }\n const raw = errorMessage(err);\n // When no profile was given up front, recover the one the SDK resolved (it's\n // embedded in the error) and mark it \"(resolved)\".\n const sdkProfile = raw.match(/--profile\\s+(\\S+)/)?.[1];\n const usedProfile = profile ?? sdkProfile;\n const shownProfile =\n profile ?? (sdkProfile ? `${sdkProfile} (resolved)` : undefined);\n // Prefer the host the SDK resolved (covers a profile-supplied host), then\n // the raw env var.\n const shownHost = sanitizeHost(await resolvedHostOf(built)) ?? host;\n return {\n result: {\n status: \"error\",\n code: \"AUTH_FAILED\",\n detail: \"authentication failed\",\n // A conflict explains the failure better than a generic login hint.\n hint: conflict ?? authFailureHint(raw, usedProfile),\n host: shownHost,\n profile: shownProfile,\n raw,\n },\n };\n }\n}\n\n/**\n * Suggests a next action for common auth failures, matched most specific first.\n * Returns undefined for an unrecognized failure.\n *\n * `profile` is the explicit --profile, else the one the SDK resolved (DEFAULT /\n * DATABRICKS_CONFIG_PROFILE) and embedded in its error, so the login hint\n * targets what actually failed.\n */\nfunction authFailureHint(\n message: string,\n profile?: string,\n): string | undefined {\n const loginCmd = profile\n ? `databricks auth login --profile ${profile}`\n : \"databricks auth login\";\n // Network-level failure (unreachable host, DNS, TLS). Matched first — more\n // specific than a credential problem and needs a different fix.\n if (\n /ENOTFOUND|EAI_AGAIN|ECONNREFUSED|ECONNRESET|ETIMEDOUT|getaddrinfo|certificate|self.signed|unable to verify|TLS/i.test(\n message,\n )\n ) {\n return \"Check that the workspace host is correct and reachable (verify DATABRICKS_HOST or the profile's host, and that you're online).\";\n }\n if (\n /has no .* profile configured|profile .*(does not exist|not found)/i.test(\n message,\n )\n ) {\n return `Run \\`${loginCmd}\\`, or pass an existing profile via --profile.`;\n }\n // Expired/failed token, or no credentials resolved: same next action.\n if (\n /cannot get access token|refresh token|reauthenticate|databricks auth token|token .*expired|cannot configure default credentials|default auth|no .*credentials|host is required/i.test(\n message,\n )\n ) {\n return `Run \\`${loginCmd}\\` and confirm the profile/host is the one you intend.`;\n }\n return undefined;\n}\n\n/** The default local env file, matching the `.env` the CLI auto-loads. */\nexport const DEFAULT_ENV_FILE = \".env\";\n\n/** What the config layer needs beyond the target to name the *right* file and\n * give advice that fits the app's actual deploy wiring. */\nexport interface ConfigCheckContext {\n /** Where local values were loaded from: `.env`, or `--env-file`'s path. Named\n * in the message so it's clear this is the local env file, not `app.yaml` /\n * `databricks.yml`. */\n envFile: string;\n /** Env vars `app.yaml` already wires. Lets the hint be dropped entirely for a\n * var whose deploy wiring is already correct. */\n wiredEnvVars: ReadonlySet<string>;\n}\n\n/**\n * Layer: config. Offline presence check of each declared env var; whether a set\n * value points at a real resource is the existence layer's job.\n *\n * The message names the env file explicitly, because \"not set\" alone reads as\n * ambiguous between the three files a var can be declared in — the local env\n * file, `app.yaml`, and `databricks.yml`. This layer only ever means the first.\n */\nexport function checkConfig(\n target: ResourceTarget,\n ctx: ConfigCheckContext,\n): LayerResult {\n const missing: string[] = [];\n\n for (const envVar of target.envVars) {\n const value = process.env[envVar];\n if (value === undefined || value.trim().length === 0) {\n missing.push(envVar);\n }\n }\n\n if (missing.length > 0) {\n const plural = missing.length > 1;\n const names = missing.join(\", \");\n const them = plural ? \"them\" : \"it\";\n // Deploy reads app.yaml, never the env file. When wiring is already correct\n // there's nothing to add beyond \"set it\", which the detail line just said —\n // so no hint at all. Only genuinely-missing wiring earns one.\n const allWired = missing.every((name) => ctx.wiredEnvVars.has(name));\n return {\n layer: \"config\",\n status: target.required ? \"error\" : \"warn\",\n code: target.required ? \"ENV_MISSING\" : \"ENV_MISSING_OPTIONAL\",\n detail: `${names} ${plural ? \"are\" : \"is\"} not set in \\`${ctx.envFile}\\`${\n target.required ? \"\" : \" (optional)\"\n }`,\n hint: allWired\n ? undefined\n : `Add ${them} to \\`${ctx.envFile}\\` to run locally, and wire ${them} through app.yaml + databricks.yml for deploy.`,\n };\n }\n\n return { layer: \"config\", status: \"ok\" };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA4CA,eAAe,eAAe,QAA8C;AAC1E,KAAI;EACF,MAAM,OAAO,MAAO,QAAmC,WAAW;AAClE,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,OAAO;SACtD;AACN;;;;;AAMJ,SAAS,SAAS,GAAW,GAAoB;CAC/C,MAAM,aAAa,MACjB,EACG,MAAM,CACN,aAAa,CACb,QAAQ,gBAAgB,GAAG,CAC3B,QAAQ,QAAQ,GAAG;AACxB,QAAO,UAAU,EAAE,KAAK,UAAU,EAAE;;;;;;;;;AAUtC,eAAe,oBACb,SACA,SAC6B;AAC7B,KAAI,CAAC,WAAW,CAAC,QAAS,QAAO;CACjC,MAAM,cAAc,MAAM,eAAe,QAAQ;AACjD,KAAI,CAAC,eAAe,SAAS,SAAS,YAAY,CAAE,QAAO;AAC3D,QACE,oBAAoB,QAAQ,iBAAiB,QAAQ,KACjD,YAAY;;;;;;;AAUpB,SAAgB,aAAa,MAA8C;AACzE,KAAI,SAAS,OAAW,QAAO;AAC/B,KAAI;EACF,MAAM,MAAM,IAAI,IAAI,KAAK;AACzB,MAAI,CAAC,IAAI,YAAY,CAAC,IAAI,SAAU,QAAO;AAC3C,MAAI,WAAW;AACf,MAAI,WAAW;AACf,SAAO,IAAI,UAAU;SACf;AAKN,SAAO,KAAK,QAAQ,0BAA0B,GAAG,WAAW,UAAU,GAAG;;;;;;;;;;;;AAa7E,SAAgB,aAAa,MAAyC;AACpE,KAAI,SAAS,UAAa,KAAK,MAAM,CAAC,WAAW,EAAG,QAAO;CAC3D,MAAM,QAAQ,aAAa,K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@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveProfile } from "../../../workspace-client/modular.js";
|
|
2
2
|
import { createWorkspaceClient } from "../../../workspace-client/factory.js";
|
|
3
3
|
|
|
4
4
|
//#region src/cli/commands/doctor/databricks-client.ts
|
|
@@ -25,10 +25,10 @@ function isModuleNotFound(err) {
|
|
|
25
25
|
return err instanceof Error && (err.message.includes("Cannot find module") || err.message.includes("Cannot find package") || err.code === "ERR_MODULE_NOT_FOUND");
|
|
26
26
|
}
|
|
27
27
|
/** Constructs a workspace client via the SDK's unified-auth chain. An explicit
|
|
28
|
-
* `profile` is passed
|
|
29
|
-
*
|
|
28
|
+
* `profile` is passed as a client option rather than mutating `process.env`, so
|
|
29
|
+
* it doesn't leak beyond this call. */
|
|
30
30
|
async function getServiceClient(profile) {
|
|
31
|
-
return { client: createWorkspaceClient(profile ? { profile } : {})
|
|
31
|
+
return { client: createWorkspaceClient(profile ? { profile } : {}) };
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* The host a named profile declares in `~/.databrickscfg`, read offline. Doctor
|
|
@@ -39,8 +39,10 @@ async function getServiceClient(profile) {
|
|
|
39
39
|
*/
|
|
40
40
|
async function getProfileHost(profile) {
|
|
41
41
|
try {
|
|
42
|
-
const {
|
|
43
|
-
|
|
42
|
+
const { host } = await resolveProfile({
|
|
43
|
+
profile,
|
|
44
|
+
disableEnv: true
|
|
45
|
+
});
|
|
44
46
|
return typeof host === "string" && host.length > 0 ? host : void 0;
|
|
45
47
|
} catch {
|
|
46
48
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"databricks-client.js","names":[],"sources":["../../../../src/cli/commands/doctor/databricks-client.ts"],"sourcesContent":["/**\n * The seam where `appkit doctor` crosses into the Databricks SDK. It reaches\n * the SDK through the shared `workspace-client` facade — the one sanctioned SDK\n * import site — so no dynamic import or `noRestrictedImports` suppression is\n * needed. (The Lakebase probe still dynamically imports `@databricks/appkit`\n * below, since that's an optional peer `shared` deliberately doesn't depend on.)\n */\n\nimport {\n createWorkspaceClient,\n
|
|
1
|
+
{"version":3,"file":"databricks-client.js","names":[],"sources":["../../../../src/cli/commands/doctor/databricks-client.ts"],"sourcesContent":["/**\n * The seam where `appkit doctor` crosses into the Databricks SDK. It reaches\n * the SDK through the shared `workspace-client` facade — the one sanctioned SDK\n * import site — so no dynamic import or `noRestrictedImports` suppression is\n * needed. (The Lakebase probe still dynamically imports `@databricks/appkit`\n * below, since that's an optional peer `shared` deliberately doesn't depend on.)\n */\n\nimport {\n createWorkspaceClient,\n resolveProfile,\n type WorkspaceClient,\n} from \"../../../workspace-client\";\n\n/**\n * Retained for backward compatibility. Since `shared` now depends on the SDK\n * (reached via the workspace-client facade), the SDK is always resolvable at\n * runtime and this is no longer thrown; kept exported so existing callers and\n * the `SDK_NOT_INSTALLED` diagnostic branch keep compiling.\n */\nexport class SdkNotInstalledError extends Error {\n constructor() {\n super(\n \"The 'doctor' command requires the Databricks SDK (a dependency of @databricks/appkit).\",\n );\n this.name = \"SdkNotInstalledError\";\n }\n}\n\ninterface ServiceClientHandle {\n /** WorkspaceClient, typed as unknown to keep doctor's call sites SDK-agnostic. */\n client: unknown;\n}\n\nfunction isModuleNotFound(err: unknown): boolean {\n return (\n err instanceof Error &&\n (err.message.includes(\"Cannot find module\") ||\n err.message.includes(\"Cannot find package\") ||\n (err as NodeJS.ErrnoException).code === \"ERR_MODULE_NOT_FOUND\")\n );\n}\n\n/** Constructs a workspace client via the SDK's unified-auth chain. An explicit\n * `profile` is passed as a client option rather than mutating `process.env`, so\n * it doesn't leak beyond this call. */\nexport async function getServiceClient(\n profile?: string,\n): Promise<ServiceClientHandle> {\n const client = createWorkspaceClient(profile ? { profile } : {});\n return { client };\n}\n\n/**\n * The host a named profile declares in `~/.databrickscfg`, read offline. Doctor\n * uses it to detect a profile/host conflict, so it must not depend on the\n * resolved config (where `DATABRICKS_HOST` has already won). Returns undefined\n * for any unreadable file, missing profile, or hostless profile — a conflict we\n * can't prove isn't worth reporting.\n */\nexport async function getProfileHost(\n profile: string,\n): Promise<string | undefined> {\n try {\n // `disableEnv`: only the file's value counts; `DATABRICKS_HOST` already won.\n const { host } = await resolveProfile({ profile, disableEnv: true });\n return typeof host === \"string\" && host.length > 0 ? host : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** Raised when `@databricks/appkit` (needed for the Lakebase probe) is absent. */\nexport class AppkitNotInstalledError extends Error {\n constructor() {\n super(\n \"The Lakebase connection check requires @databricks/appkit. Please install it to run this check.\",\n );\n this.name = \"AppkitNotInstalledError\";\n }\n}\n\n/** Minimal `pg.Pool`-shaped handle. The caller owns it and must call `end()`. */\nexport interface LakebasePoolHandle {\n query: (sql: string) => Promise<unknown>;\n end: () => Promise<void>;\n}\n\n/** Builds a Lakebase pool via `createLakebasePool`. Connection settings\n * (`PGHOST`, `LAKEBASE_ENDPOINT`, …) come from the environment; we inject only\n * the resolved workspace client for OAuth token minting. */\nexport async function getLakebasePool(\n client: unknown,\n): Promise<LakebasePoolHandle> {\n // A variable specifier stops TS from statically resolving `@databricks/appkit`,\n // an optional peer that `shared` has no dependency on.\n const appkitPkg = \"@databricks/appkit\";\n let appkit: {\n createLakebasePool: (cfg: Record<string, unknown>) => unknown;\n };\n try {\n appkit = await import(appkitPkg);\n } catch (err) {\n if (isModuleNotFound(err)) {\n throw new AppkitNotInstalledError();\n }\n throw err;\n }\n\n // Silence Lakebase's own logger. It defaults to an error-only console logger\n // that dumps the raw SDK ApiError (stack + full response blob) to stderr on a\n // failed token fetch. doctor classifies and prints that failure itself, so the\n // library's dump is just noise on top of our clean one-line report.\n // Lakebase takes the facade as is: it uses `request` and the typed `postgres`.\n const pool = appkit.createLakebasePool({\n workspaceClient: client as WorkspaceClient,\n logger: { error: false },\n });\n return pool as unknown as LakebasePoolHandle;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,IAAa,uBAAb,cAA0C,MAAM;CAC9C,cAAc;AACZ,QACE,yFACD;AACD,OAAK,OAAO;;;AAShB,SAAS,iBAAiB,KAAuB;AAC/C,QACE,eAAe,UACd,IAAI,QAAQ,SAAS,qBAAqB,IACzC,IAAI,QAAQ,SAAS,sBAAsB,IAC1C,IAA8B,SAAS;;;;;AAO9C,eAAsB,iBACpB,SAC8B;AAE9B,QAAO,EAAE,QADM,sBAAsB,UAAU,EAAE,SAAS,GAAG,EAAE,CAAC,EAC/C;;;;;;;;;AAUnB,eAAsB,eACpB,SAC6B;AAC7B,KAAI;EAEF,MAAM,EAAE,SAAS,MAAM,eAAe;GAAE;GAAS,YAAY;GAAM,CAAC;AACpE,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,OAAO;SACtD;AACN;;;;AAKJ,IAAa,0BAAb,cAA6C,MAAM;CACjD,cAAc;AACZ,QACE,kGACD;AACD,OAAK,OAAO;;;;;;AAahB,eAAsB,gBACpB,QAC6B;CAG7B,MAAM,YAAY;CAClB,IAAI;AAGJ,KAAI;AACF,WAAS,MAAM,OAAO;UACf,KAAK;AACZ,MAAI,iBAAiB,IAAI,CACvB,OAAM,IAAI,yBAAyB;AAErC,QAAM;;AAYR,QAJa,OAAO,mBAAmB;EACrC,iBAAiB;EACjB,QAAQ,EAAE,OAAO,OAAO;EACzB,CAAC"}
|
|
@@ -14,58 +14,70 @@ function choiceFrom(item, idField, labelField) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* repeated-token guard avoids an infinite loop if the API echoes a token back.
|
|
17
|
+
* Follows page tokens until exhausted. The repeated-token guard avoids an
|
|
18
|
+
* infinite loop if the API echoes a token back.
|
|
20
19
|
*/
|
|
21
|
-
async function*
|
|
20
|
+
async function* paginate(fetchPage) {
|
|
22
21
|
let pageToken;
|
|
23
22
|
do {
|
|
24
|
-
const
|
|
25
|
-
for (const
|
|
26
|
-
const next = res.next_page_token;
|
|
23
|
+
const { items, next } = await fetchPage(pageToken);
|
|
24
|
+
for (const item of items ?? []) yield item;
|
|
27
25
|
if (next && next === pageToken) break;
|
|
28
26
|
pageToken = next;
|
|
29
27
|
} while (pageToken);
|
|
30
28
|
}
|
|
29
|
+
/** listInferenceEndpoints is unpaginated; adapt its single page. */
|
|
30
|
+
async function* iterateServingEndpoints(client) {
|
|
31
|
+
yield* (await client.modelServing.listInferenceEndpoints({})).endpoints ?? [];
|
|
32
|
+
}
|
|
33
|
+
/** Genie listSpaces returns a single page; follow `nextPageToken`. */
|
|
34
|
+
function iterateGenieSpaces(client) {
|
|
35
|
+
return paginate(async (pageToken) => {
|
|
36
|
+
const res = await client.genie.genieListSpaces(pageToken ? { pageToken } : {});
|
|
37
|
+
return {
|
|
38
|
+
items: res.spaces,
|
|
39
|
+
next: res.nextPageToken
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
31
43
|
/** Flat, top-level listable resource types, backed by SDK services. */
|
|
32
44
|
const SDK_LISTERS = {
|
|
33
45
|
sql_warehouse: {
|
|
34
|
-
list: (c) => c.warehouses.
|
|
46
|
+
list: (c) => c.warehouses.listWarehousesIter({}),
|
|
35
47
|
toChoice: (i) => choiceFrom(i, "id", "name")
|
|
36
48
|
},
|
|
37
49
|
job: {
|
|
38
|
-
list: (c) => c.jobs.
|
|
50
|
+
list: (c) => c.jobs.listJobsIter({}),
|
|
39
51
|
toChoice: (i) => {
|
|
40
52
|
const settings = i.settings;
|
|
41
53
|
return choiceFrom({
|
|
42
54
|
...i,
|
|
43
55
|
name: settings?.name
|
|
44
|
-
}, "
|
|
56
|
+
}, "jobId", "name");
|
|
45
57
|
}
|
|
46
58
|
},
|
|
47
59
|
serving_endpoint: {
|
|
48
|
-
list:
|
|
60
|
+
list: iterateServingEndpoints,
|
|
49
61
|
toChoice: (i) => choiceFrom(i, "name", "name")
|
|
50
62
|
},
|
|
51
63
|
uc_connection: {
|
|
52
|
-
list: (c) => c.connections.
|
|
53
|
-
toChoice: (i) => choiceFrom(i, "name", "
|
|
64
|
+
list: (c) => c.connections.listConnectionsIter({}),
|
|
65
|
+
toChoice: (i) => choiceFrom(i, "name", "fullName")
|
|
54
66
|
},
|
|
55
67
|
database: {
|
|
56
|
-
list: (c) => c.database.
|
|
68
|
+
list: (c) => c.database.listDatabaseInstancesIter({}),
|
|
57
69
|
toChoice: (i) => choiceFrom(i, "name", "name")
|
|
58
70
|
},
|
|
59
71
|
genie_space: {
|
|
60
72
|
list: iterateGenieSpaces,
|
|
61
|
-
toChoice: (i) => choiceFrom(i, "
|
|
73
|
+
toChoice: (i) => choiceFrom(i, "spaceId", "title")
|
|
62
74
|
},
|
|
63
75
|
experiment: {
|
|
64
|
-
list: (c) => c.experiments.
|
|
65
|
-
toChoice: (i) => choiceFrom(i, "
|
|
76
|
+
list: (c) => c.experiments.listExperimentsIter({}),
|
|
77
|
+
toChoice: (i) => choiceFrom(i, "experimentId", "name")
|
|
66
78
|
},
|
|
67
79
|
app: {
|
|
68
|
-
list: (c) => c.apps.
|
|
80
|
+
list: (c) => c.apps.listAppsIter({}),
|
|
69
81
|
toChoice: (i) => choiceFrom(i, "name", "name")
|
|
70
82
|
}
|
|
71
83
|
};
|
|
@@ -74,16 +86,14 @@ function isFlatListable(resourceType) {
|
|
|
74
86
|
return resourceType in SDK_LISTERS;
|
|
75
87
|
}
|
|
76
88
|
/**
|
|
77
|
-
* Constructs a
|
|
78
|
-
*
|
|
79
|
-
* escape hatch because the picker needs services (connections, database,
|
|
80
|
-
* experiments, apps) the facade doesn't yet proxy directly.
|
|
89
|
+
* Constructs a workspace client for the given profile (or default resolution),
|
|
90
|
+
* via the sanctioned `workspace-client` facade.
|
|
81
91
|
*/
|
|
82
92
|
function makeWorkspaceClient(profile) {
|
|
83
|
-
return createWorkspaceClient(profile ? { profile } : {})
|
|
93
|
+
return createWorkspaceClient(profile ? { profile } : {});
|
|
84
94
|
}
|
|
85
95
|
/**
|
|
86
|
-
* Max resources fetched for the picker. `list()`
|
|
96
|
+
* Max resources fetched for the picker. `list()` paginates lazily, so on a large
|
|
87
97
|
* workspace (5000+ warehouses) breaking out at the cap stops pagination early;
|
|
88
98
|
* the picker's "Enter manually" option covers anything beyond it.
|
|
89
99
|
*/
|