70 lines · 1.9 KB · TypeScript
RawDownload
/** * WorkspaceFileSystem - Effect service contract for workspace file mutations. * * Owns workspace-root-relative file write operations and their associated * safety checks and cache invalidation hooks. * * @module WorkspaceFileSystem */import * as Schema from "effect/Schema";import * as Context from "effect/Context";import type * as Effect from "effect/Effect"; import type {  ProjectReadFileInput,  ProjectReadFileResult,  ProjectWriteFileInput,  ProjectWriteFileResult,} from "@t3tools/contracts";import { WorkspacePathOutsideRootError } from "./WorkspacePaths.ts"; export class WorkspaceFileSystemError extends Schema.TaggedErrorClass<WorkspaceFileSystemError>()(  "WorkspaceFileSystemError",  {    cwd: Schema.String,    relativePath: Schema.optional(Schema.String),    operation: Schema.String,    detail: Schema.String,    cause: Schema.optional(Schema.Defect()),  },) {  override get message(): string {    return this.detail;  }} /** * WorkspaceFileSystemShape - Service API for workspace-relative file operations. */export interface WorkspaceFileSystemShape {  /**   * Read a UTF-8 text file relative to the workspace root.   */  readonly readFile: (    input: ProjectReadFileInput,  ) => Effect.Effect<    ProjectReadFileResult,    WorkspaceFileSystemError | WorkspacePathOutsideRootError  >;   /**   * Write a file relative to the workspace root.   *   * Creates parent directories as needed and rejects paths that escape the   * workspace root.   */  readonly writeFile: (    input: ProjectWriteFileInput,  ) => Effect.Effect<    ProjectWriteFileResult,    WorkspaceFileSystemError | WorkspacePathOutsideRootError  >;} /** * WorkspaceFileSystem - Service tag for workspace file operations. */export class WorkspaceFileSystem extends Context.Service<  WorkspaceFileSystem,  WorkspaceFileSystemShape>()("t3/workspace/Services/WorkspaceFileSystem") {}