| 1 | import { Credentials } from "@distilled.cloud/gcp/Credentials"; |
| 2 | import * as recommendationengine from "@distilled.cloud/gcp/recommendationengine_v1beta1"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as HttpClient from "effect/http/HttpClient"; |
| 6 | import type { CatalogsCatalogItem } from "./CatalogsCatalogItem.ts"; |
| 7 | import { bindGcpHost } from "../Host.ts"; |
| 8 | import { |
| 9 | GetCatalogItem, |
| 10 | type GetCatalogItemRequest, |
| 11 | } from "./GetCatalogItem.ts"; |
| 12 | |
| 13 | /** |
| 14 | * HTTP implementation of {@link GetCatalogItem}. |
| 15 | * |
| 16 | * @layer |
| 17 | * @provides GCP.RecommendationEngine.GetCatalogItem |
| 18 | */ |
| 19 | export const GetCatalogItemHttp: Layer.Layer< |
| 20 | GetCatalogItem, |
| 21 | never, |
| 22 | Credentials | HttpClient.HttpClient |
| 23 | > = Layer.effect( |
| 24 | GetCatalogItem, |
| 25 | Effect.gen(function* () { |
| 26 | const run = |
| 27 | yield* recommendationengine.getProjectsLocationsCatalogsCatalogItems; |
| 28 | return Effect.fn(function* (item: CatalogsCatalogItem) { |
| 29 | yield* bindGcpHost({ |
| 30 | tag: "GCP.RecommendationEngine.GetCatalogItem", |
| 31 | resource: item, |
| 32 | iam: [{ role: "roles/automlrecommendations.viewer" }], |
| 33 | }); |
| 34 | const name = yield* item.name; |
| 35 | return Effect.fn( |
| 36 | `GCP.RecommendationEngine.GetCatalogItem(${item.LogicalId})`, |
| 37 | )(function* (_request?: GetCatalogItemRequest) { |
| 38 | return yield* run({ name: yield* name }); |
| 39 | }); |
| 40 | }); |
| 41 | }), |
| 42 | ); |