sailfork / t3code-github / .repos/ alchemy-effect/ packages/ aws/ src/ CloudFront/ PutKey.ts

import type * as kvs from "@distilled.cloud/aws/cloudfront-keyvaluestore";
import * as Binding from "alchemy/Binding";
import type * as Effect from "effect/Effect";
import type { KeyValueStore } from "./KeyValueStore.ts";

export interface PutKeyRequest extends Omit<kvs.PutKeyRequest, "KvsARN"> {}

/**
 * Runtime binding for `cloudfront-keyvaluestore:PutKey`.
 *
 * Creates or replaces a single key in the bound KeyValueStore's data plane.
 * Writes use optimistic concurrency: pass the store's current `ETag` as
 * `IfMatch` (from {@link DescribeKeyValueStore} or a previous write's
 * response). Provide the implementation with
 * `Effect.provide(AWS.CloudFront.PutKeyHttp)`.
 * ### Writing KeyValueStore Data
 * **Example:** Put a Key
 * ```typescript
 * // init — bind the operations to the store
 * const describeStore = yield* CloudFront.DescribeKeyValueStore(store);
 * const putKey = yield* CloudFront.PutKey(store);
 *
 * // runtime
 * const meta = yield* describeStore({});
 * const res = yield* putKey({
 *   Key: "routes:/about",
 *   Value: "/about.html",
 *   IfMatch: meta.ETag,
 * });
 * // res.ETag is the store's new entity tag
 * ```
 *
 * @binding
 */
export interface PutKey extends Binding.Service<
  PutKey,
  "AWS.CloudFront.PutKey",
  (
    store: KeyValueStore,
  ) => Effect.Effect<(request: PutKeyRequest) => Effect.Effect<kvs.PutKeyResponse, kvs.PutKeyError>>
> {}

export const PutKey = Binding.Service<PutKey>("AWS.CloudFront.PutKey");