Open History to see the last commit
1import * as aoss from "@distilled.cloud/aws/opensearchserverless";
2import * as Output from "alchemy/Output";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import * as AWSBindings from "../AWSBindings.ts";
6import type { Collection } from "./Collection.ts";
7import { GetCollection } from "./GetCollection.ts";
8
9// Bespoke (not the shared scaffolding): BatchGetCollection takes an `ids`
10// array rather than a single injected `id`, and the callable unwraps the
11// batch response to the bound collection's detail.
12export const GetCollectionHttp = Layer.effect(
13 GetCollection,
14 Effect.gen(function* () {
15 const bind = yield* AWSBindings.Bind;
16 const op = yield* AWSBindings.withCredentials(aoss.batchGetCollection);
17
18 return Effect.fn(function* (collection: Collection) {
19 const CollectionId = yield* collection.collectionId;
20 if (!globalThis.__ALCHEMY_RUNTIME__) {
21 yield* bind`AWS.OpenSearchServerless.GetCollection(${collection})`({
22 policyStatements: [
23 {
24 Effect: "Allow",
25 Action: ["aoss:BatchGetCollection"],
26 Resource: [Output.interpolate`${collection.collectionArn}`],
27 },
28 ],
29 });
30 }
31 return Effect.fn(`AWS.OpenSearchServerless.GetCollection(${collection.LogicalId})`)(
32 function* () {
33 const response = yield* op({ ids: [yield* CollectionId] });
34 return response.collectionDetails?.[0];
35 },
36 );
37 });
38 }),
39);