| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import { makeAmpWorkspaceHttpBinding, toPromTime } from "./BindingHttp.ts"; |
| 4 | import { |
| 5 | GetLabels, |
| 6 | type GetLabelsClient, |
| 7 | type GetLabelsRequest, |
| 8 | type GetLabelValuesRequest, |
| 9 | } from "./GetLabels.ts"; |
| 10 | |
| 11 | const rangeParams = (request: GetLabelsRequest) => ({ |
| 12 | "match[]": request.match, |
| 13 | start: request.start !== undefined ? toPromTime(request.start) : undefined, |
| 14 | end: request.end !== undefined ? toPromTime(request.end) : undefined, |
| 15 | }); |
| 16 | |
| 17 | export const GetLabelsHttp = Layer.effect( |
| 18 | GetLabels, |
| 19 | makeAmpWorkspaceHttpBinding({ |
| 20 | name: "GetLabels", |
| 21 | iamActions: ["aps:GetLabels"], |
| 22 | makeClient: (send): GetLabelsClient => ({ |
| 23 | labelNames: (request: GetLabelsRequest = {}) => |
| 24 | send({ |
| 25 | method: "GET", |
| 26 | path: "api/v1/labels", |
| 27 | query: rangeParams(request), |
| 28 | }).pipe(Effect.map((data) => data as string[])), |
| 29 | labelValues: (request: GetLabelValuesRequest) => |
| 30 | send({ |
| 31 | method: "GET", |
| 32 | path: `api/v1/label/${encodeURIComponent(request.label)}/values`, |
| 33 | query: rangeParams(request), |
| 34 | }).pipe(Effect.map((data) => data as string[])), |
| 35 | }), |
| 36 | }), |
| 37 | ); |