diff --git a/cli/hub.ts b/cli/hub.ts index 3dfe4c7514..6943369ec0 100644 --- a/cli/hub.ts +++ b/cli/hub.ts @@ -9,6 +9,14 @@ import { deepEqual } from "./utils.ts"; const DEFAULT_HUB_BASE_URL = "https://hub.windmill.dev"; +interface HubResourceType { + id: number; + name: string; + schema: string; + app: string; + description: string; +} + export async function pull(opts: GlobalOptions) { const workspace = await resolveWorkspace(opts); @@ -39,50 +47,16 @@ export async function pull(opts: GlobalOptions) { headers["X-uid"] = uid; } - let preList = await fetch(hubBaseUrl + "/resource_types/list", { + let list = await fetch(hubBaseUrl + "/resource_types/list", { headers, - }).then((r) => r.json() as Promise<{ id: number; name: string }[]>); + }).then((r) => r.json() as Promise); - if (preList && preList.length === 0 && hubBaseUrl !== DEFAULT_HUB_BASE_URL) { - preList = await fetch(DEFAULT_HUB_BASE_URL + "/resource_types/list", { + if (list && list.length === 0 && hubBaseUrl !== DEFAULT_HUB_BASE_URL) { + list = await fetch(DEFAULT_HUB_BASE_URL + "/resource_types/list", { headers, - }).then((r) => r.json() as Promise<{ id: number; name: string }[]>); + }).then((r) => r.json() as Promise); } - let list: { - id: number; - name: string; - schema: string; - approved: boolean; - app: string; - description: string; - created_by: string; - created_at: Date; - comments: never[]; - }[] = await Promise.all( - preList.map((x) => - fetch(hubBaseUrl + "/resource_types/" + x.id + "/" + x.name, { - headers: { - Accept: "application/json", - }, - }) - ) - ) - .then((x) => - x.map((x) => - x.json().catch((e) => { - log.info(e); - return undefined; - }) - ) - ) - .then((x) => Promise.all(x)) - .then((x) => - (x as { resource_type: any }[]) - .filter((x) => x) - .map((x) => x.resource_type) - ); - const resourceTypes = await wmill.listResourceType({ workspace: workspace.workspaceId, });