Extract project/workspace related functionality to Effect services (#1524)
This commit is contained in:
1 parent
d303ac39cb
commit
2d03847ccd
26 files changed
+2079
-1142
No files matched your search
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 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") {}
|
||||
Reference in new issue
Block a user