Files
t3code/apps/server/src/workspace/Services/WorkspaceFileSystem.ts
T

51 lines
1.5 KiB
TypeScript

/**
* 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 { Schema, ServiceMap } from "effect";
import type { Effect } from "effect";
import type { 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),
},
) {}
/**
* WorkspaceFileSystemShape - Service API for workspace-relative file operations.
*/
export interface WorkspaceFileSystemShape {
/**
* 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 ServiceMap.Service<
WorkspaceFileSystem,
WorkspaceFileSystemShape
>()("t3/workspace/Services/WorkspaceFileSystem") {}