1/**
2 * vinext data-cache adapter builder for S3.
3 *
4 * AWS.Website.Vinext injects this adapter automatically.
5 * The runtime factory reads `CACHE_BUCKET_NAME` from the Lambda
6 * environment (Alchemy's `AWS.Website.Vinext` sets it). The runtime
7 * talks distilled `@distilled.cloud/aws/s3`, the same client
8 * `AWS.S3.GetObject` / `PutObject` wrap.
9 *
10 * If the bucket env is missing (local `vinext start`), vinext logs and
11 * falls back to the in-memory handler.
12 */
13import { fileURLToPath } from "node:url";
14import type { S3AdapterOptions } from "./s3-runtime.ts";
15
16export type { S3AdapterOptions } from "./s3-runtime.ts";
17
18export const DEFAULT_CACHE_BUCKET_ENV = "CACHE_BUCKET_NAME";
19export const DEFAULT_CACHE_PREFIX = "vinext-cache/";
20
21export const s3Adapter = (options?: S3AdapterOptions) => {
22 if (
23 options?.bucketEnv !== undefined &&
24 typeof options.bucketEnv !== "string"
25 ) {
26 throw new TypeError(
27 "[vinext] s3Adapter({ bucketEnv }) must be a string env var name.",
28 );
29 }
30 return {
31 adapter: fileURLToPath(new URL("./s3-runtime.js", import.meta.url)),
32 options,
33 };
34};