History

Format Effect refactors

Cursor Agent committed 4 months ago

Commit faf9d871 parent 6cc87a32 files · +39 −24Browse files

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

Unified · Split

apps/server/src/workspace/WorkspaceFileSystem.ts+35−22
@@ -131,20 +131,22 @@ export const make = Effect.gen(function* () { · 130 unmodified lines
131131 const workspacePaths = yield* WorkspacePaths.WorkspacePaths;
132132 const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
133133
134− const operationError = (
135− input: ProjectReadFileInput | ProjectWriteFileInput,
136− resolvedPath: string,
137− operationPath: string,
138− operation: WorkspaceFileSystemOperationError["operation"],
139− ) => (cause: unknown) =>
140− new WorkspaceFileSystemOperationError({
141− workspaceRoot: input.cwd,
142− relativePath: input.relativePath,
143− resolvedPath,
144− operationPath,
145− operation,
146− cause,
147− });
134+ const operationError =
135+ (
136+ input: ProjectReadFileInput | ProjectWriteFileInput,
137+ resolvedPath: string,
138+ operationPath: string,
139+ operation: WorkspaceFileSystemOperationError["operation"],
140+ ) =>
141+ (cause: unknown) =>
142+ new WorkspaceFileSystemOperationError({
143+ workspaceRoot: input.cwd,
144+ relativePath: input.relativePath,
145+ resolvedPath,
146+ operationPath,
147+ operation,
148+ cause,
149+ });
148150
149151 const readFile: WorkspaceFileSystem["Service"]["readFile"] = Effect.fn(
150152 "WorkspaceFileSystem.readFile",
@@ -203,10 +205,12 @@ export const make = Effect.gen(function* () { · 52 unmodified lines
203205 const fileBytes =
204206 bytesToRead === 0
205207 ? new Uint8Array()
206− : yield* file.readAlloc(bytesToRead).pipe(
207− Effect.map(Option.getOrElse(() => new Uint8Array())),
208− Effect.mapError(operationError(input, realTargetPath, realTargetPath, "read")),
209− );
208+ : yield* file
209+ .readAlloc(bytesToRead)
210+ .pipe(
211+ Effect.map(Option.getOrElse(() => new Uint8Array())),
212+ Effect.mapError(operationError(input, realTargetPath, realTargetPath, "read")),
213+ );
210214 if (fileBytes.includes(0)) {
211215 return yield* new WorkspaceBinaryFileError({
212216 workspaceRoot: input.cwd,
@@ -237,12 +241,21 @@ export const make = Effect.gen(function* () { · 24 unmodified lines
237241 .makeDirectory(path.dirname(target.absolutePath), { recursive: true })
238242 .pipe(
239243 Effect.mapError(
240− operationError(input, target.absolutePath, path.dirname(target.absolutePath), "make-directory"),
244+ operationError(
245+ input,
246+ target.absolutePath,
247+ path.dirname(target.absolutePath),
248+ "make-directory",
249+ ),
250+ ),
251+ );
252+ yield* fileSystem
253+ .writeFileString(target.absolutePath, input.contents)
254+ .pipe(
255+ Effect.mapError(
256+ operationError(input, target.absolutePath, target.absolutePath, "write-file"),
241257 ),
242258 );
243− yield* fileSystem.writeFileString(target.absolutePath, input.contents).pipe(
244− Effect.mapError(operationError(input, target.absolutePath, target.absolutePath, "write-file")),
245− );
246259 yield* workspaceEntries.refresh(input.cwd);
247260 return { relativePath: target.relativePath };
248261 });