History

Extract project/workspace related functionality to Effect services (#1524)

Julius Marminge committed 7 months ago

Commit 2d038471 parent d303ac326 files · +2077 −1140Browse files

Showing the changes to apps/server/src/workspace/Services/WorkspaceFileSystem.ts (1 of 26 files). Show all

Unified · Split

apps/server/src/workspace/Services/WorkspaceFileSystem.ts+50−0
@@ -0,0 +1,50 @@
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+ */
9+import { Schema, ServiceMap } from "effect";
10+import type { Effect } from "effect";
11+
12+import type { ProjectWriteFileInput, ProjectWriteFileResult } from "@t3tools/contracts";
13+import { WorkspacePathOutsideRootError } from "./WorkspacePaths.ts";
14+
15+export 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+ */
29+export 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+ >;
42+}
43+
44+/**
45+ * WorkspaceFileSystem - Service tag for workspace file operations.
46+ */
47+export class WorkspaceFileSystem extends ServiceMap.Service<
48+ WorkspaceFileSystem,
49+ WorkspaceFileSystemShape
50+>()("t3/workspace/Services/WorkspaceFileSystem") {}