1 | |
2 |
|
3 | export type DynSelect_catalog = string |
4 |
|
5 | |
6 | export async function catalog(auth: RT.Databricks) { |
7 | const base = auth.workspace_url.replace(/\/$/, "") |
8 | const response = await fetch(`${base}/api/2.1/unity-catalog/catalogs`, { |
9 | headers: { |
10 | Authorization: `Bearer ${auth.token}`, |
11 | Accept: "application/json", |
12 | }, |
13 | }) |
14 | if (!response.ok) { |
15 | throw new Error(`${response.status} ${await response.text()}`) |
16 | } |
17 | const { catalogs } = (await response.json()) as { |
18 | catalogs?: { name: string }[] |
19 | } |
20 | return (catalogs ?? []).map((c) => ({ value: c.name, label: c.name })) |
21 | } |
22 |
|
23 | |
24 | * List Schemas |
25 | * List the schemas within a Unity Catalog catalog. Paginate with page_token. |
26 | */ |
27 | export async function main( |
28 | auth: RT.Databricks, |
29 | catalog: DynSelect_catalog, |
30 | max_results: number | undefined, |
31 | page_token: string | undefined |
32 | ) { |
33 | const base = auth.workspace_url.replace(/\/$/, "") |
34 | const url = new URL(`${base}/api/2.1/unity-catalog/schemas`) |
35 | url.searchParams.append("catalog_name", catalog) |
36 | if (max_results !== undefined) |
37 | url.searchParams.append("max_results", String(max_results)) |
38 | if (page_token !== undefined && page_token !== "") |
39 | url.searchParams.append("page_token", page_token) |
40 |
|
41 | const response = await fetch(url, { |
42 | method: "GET", |
43 | headers: { |
44 | Authorization: `Bearer ${auth.token}`, |
45 | Accept: "application/json", |
46 | }, |
47 | }) |
48 |
|
49 | if (!response.ok) { |
50 | throw new Error(`${response.status} ${await response.text()}`) |
51 | } |
52 |
|
53 | return await response.json() |
54 | } |
55 |
|