MCPcopy
hub / github.com/Effect-TS/effect / fromFileSystem

Function fromFileSystem

packages/sql/src/Migrator/FileSystem.ts:14–43  ·  view source on GitHub ↗
(directory: string)

Source from the content-addressed store, hash-verified

12 * @category loaders
13 */
14export const fromFileSystem = (directory: string): Loader<FileSystem> =>
15 FileSystem.pipe(
16 Effect.flatMap((FS) => FS.readDirectory(directory)),
17 Effect.mapError((error) => new MigrationError({ reason: "failed", message: error.message })),
18 Effect.map((files): ReadonlyArray<ResolvedMigration> =>
19 files
20 .map((file) => Option.fromNullable(file.match(/^(?:.*\/)?(\d+)_([^.]+)\.(js|ts)$/)))
21 .flatMap(
22 Option.match({
23 onNone: () => [],
24 onSome: ([basename, id, name]): ReadonlyArray<ResolvedMigration> =>
25 [
26 [
27 Number(id),
28 name,
29 Effect.promise(
30 () =>
31 import(
32 /* @vite-ignore */
33 /* webpackIgnore: true */
34 `${directory}/${basename}`
35 )
36 )
37 ]
38 ] as const
39 })
40 )
41 .sort(([a], [b]) => a - b)
42 )
43 )

Callers

nothing calls this directly

Calls 3

NumberInterface · 0.85
pipeMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected