// ../../adapters/fs/src/fs-blob-store.ts
import { mkdir, readFile, rm, writeFile } from "fs/promises";
import { dirname, join } from "path";
var FsBlobStore = class {
  constructor(root) {
    this.root = root;
  }
  root;
  resolve(key) {
    return join(this.root, ...key.split("/").filter((segment) => segment !== ""));
  }
  async get(key) {
    try {
      return new Uint8Array(await readFile(this.resolve(key)));
    } catch (error) {
      if (error.code === "ENOENT") return void 0;
      throw error;
    }
  }
  async put(key, bytes) {
    const dest = this.resolve(key);
    await mkdir(dirname(dest), { recursive: true });
    await writeFile(dest, bytes);
  }
  async delete(key) {
    await rm(this.resolve(key), { force: true });
  }
};

// ../../adapters/fs/src/fs-artifact-sink.ts
import { mkdir as mkdir2, rm as rm2, writeFile as writeFile2 } from "fs/promises";
import { dirname as dirname2, join as join2 } from "path";
var FsArtifactSink = class {
  constructor(root) {
    this.root = root;
  }
  root;
  resolve(path) {
    return join2(this.root, ...path.split("/").filter((segment) => segment !== ""));
  }
  async write(path, contents) {
    const dest = this.resolve(path);
    await mkdir2(dirname2(dest), { recursive: true });
    await writeFile2(dest, contents);
  }
  /** Empty the output directory before a republish. A missing directory is a no-op. */
  async wipe() {
    await rm2(this.root, { recursive: true, force: true });
  }
};
export {
  FsArtifactSink,
  FsBlobStore
};
