MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeFileSystem

Function makeFileSystem

packages/effect/test/FileSystem.test.ts:37–64  ·  view source on GitHub ↗
(overrides: {
  readonly directories?: Record<string, ReadonlyArray<string>>
  readonly readDirectory?: (path: string) => Effect.Effect<Array<string>, PlatformError.PlatformError> | undefined
  readonly stat?: (path: string) => Effect.Effect<FileSystem.File.Info, PlatformError.PlatformError> | undefined
  readonly readLink?: (path: string) => Effect.Effect<string, PlatformError.PlatformError>
})

Source from the content-addressed store, hash-verified

35// Each directory holds the file `x.ts`. Listings report every entry as
36// `"Unknown"`, so `glob` learns entry types from `stat` and `readLink`.
37const makeFileSystem = (overrides: {
38 readonly directories?: Record<string, ReadonlyArray<string>>
39 readonly readDirectory?: (path: string) => Effect.Effect<Array<string>, PlatformError.PlatformError> | undefined
40 readonly stat?: (path: string) => Effect.Effect<FileSystem.File.Info, PlatformError.PlatformError> | undefined
41 readonly readLink?: (path: string) => Effect.Effect<string, PlatformError.PlatformError>
42}) => {
43 const directories = overrides.directories ?? { ".": ["a"], "a": ["x.ts"] }
44 const readDirectory = (path: string) =>
45 overrides.readDirectory?.(path) ??
46 (path in directories
47 ? Effect.succeed([...directories[path]])
48 : Effect.fail(failure("NotFound", "readDirectory", path)))
49 return FileSystem.make({
50 ...FileSystem.makeNoop({}),
51 readDirectory,
52 readDirectoryEntries: (path) =>
53 Effect.map(readDirectory(path), (names) => names.map((name) => ({ name, type: "Unknown" as const }))),
54 stat: (path) =>
55 overrides.stat?.(path) ??
56 (path in directories
57 ? Effect.succeed(info("Directory"))
58 : path.endsWith("/x.ts") && path.slice(0, -5) in directories
59 ? Effect.succeed(info("File"))
60 : Effect.fail(failure("NotFound", "stat", path))),
61 // Node and Deno report EINVAL as "Unknown" for a path that is not a link
62 readLink: overrides.readLink ?? ((path) => Effect.fail(failure("Unknown", "readLink", path)))
63 })
64}
65
66// `secret` and `src` are named by literal pattern segments below, and `open`
67// is only reached through wildcards

Callers 2

pendingInlineFunction · 0.85
FileSystem.test.tsFile · 0.85

Calls 9

sliceMethod · 0.80
readDirectoryFunction · 0.70
infoFunction · 0.70
failureFunction · 0.70
makeMethod · 0.65
failMethod · 0.65
mapMethod · 0.45
statMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected