Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

WorkspaceFileSystem.ts

50 lines1.5 KB

1/**
2 * WorkspaceFileSystem - Effect service contract for workspace file mutations.
3 *
4 * Owns workspace-root-relative file write operations and their associated
5 * safety checks and cache invalidation hooks.
6 *
7 * @module WorkspaceFileSystem
8 */
9import { Schema, Context } from "effect";
10import type { Effect } from "effect";
11​
12import type { ProjectWriteFileInput, ProjectWriteFileResult } from "@t3tools/contracts";
13import { WorkspacePathOutsideRootError } from "./WorkspacePaths.ts";
14​
15export class WorkspaceFileSystemError extends Schema.TaggedErrorClass<WorkspaceFileSystemError>()(
16 "WorkspaceFileSystemError",
17 {
18 cwd: Schema.String,
19 relativePath: Schema.optional(Schema.String),
20 operation: Schema.String,
21 detail: Schema.String,
22 cause: Schema.optional(Schema.Defect),
23 },
24) {}
25​
26/**
27 * WorkspaceFileSystemShape - Service API for workspace-relative file operations.
28 */
29export interface WorkspaceFileSystemShape {
30 /**
31 * Write a file relative to the workspace root.
32 *
33 * Creates parent directories as needed and rejects paths that escape the
34 * workspace root.
35 */
36 readonly writeFile: (
37 input: ProjectWriteFileInput,
38 ) => Effect.Effect<
39 ProjectWriteFileResult,
40 WorkspaceFileSystemError | WorkspacePathOutsideRootError
41 >;
43​
44/**
45 * WorkspaceFileSystem - Service tag for workspace file operations.
46 */
47export class WorkspaceFileSystem extends Context.Service<
48 WorkspaceFileSystem,
49 WorkspaceFileSystemShape
50>()("t3/workspace/Services/WorkspaceFileSystem") {}