@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 79 lines 2.14 KB
Raw
1 /**
2 * Node-backed provider for Effect's `Path` service.
3 *
4 * This module turns Node's `node:path` and `node:url` APIs into `Path` layers.
5 * `layer` uses the host platform path implementation, while `layerPosix` and
6 * `layerWin32` provide fixed POSIX and Windows variants. All three layers also
7 * include helpers for converting between file paths and file URLs.
8 *
9 * @stability unstable
10 * @since 4.0.0
11 */
12 import * as Effect from "effect/Effect"
13 import * as Layer from "effect/Layer"
14 import { make, Path } from "effect/Path"
15 import { BadArgument } from "effect/PlatformError"
16 import * as NodePath from "node:path"
17 import * as NodeUrl from "node:url"
18
19 const fileUrlOps = (windows: boolean | undefined) => ({
20 fromFileUrl: (url: URL): Effect.Effect<string, BadArgument> =>
21 Effect.try({
22 try: () => NodeUrl.fileURLToPath(url, { windows }),
23 catch: (cause) =>
24 new BadArgument({
25 module: "Path",
26 method: "fromFileUrl",
27 cause
28 })
29 }),
30 toFileUrl: (path: string): Effect.Effect<URL, BadArgument> =>
31 Effect.try({
32 try: () => NodeUrl.pathToFileURL(path, { windows }),
33 catch: (cause) =>
34 new BadArgument({
35 module: "Path",
36 method: "toFileUrl",
37 cause
38 })
39 })
40 })
41
42 /**
43 * Provides the `Path` service using Node's POSIX path implementation plus
44 * file URL conversion helpers.
45 *
46 * @stability unstable
47 * @category layers
48 * @since 4.0.0
49 */
50 export const layerPosix: Layer.Layer<Path> = Layer.succeed(Path)(make({
51 ...NodePath.posix,
52 ...fileUrlOps(false)
53 }))
54
55 /**
56 * Provides the `Path` service using Node's Windows path implementation plus
57 * file URL conversion helpers.
58 *
59 * @stability unstable
60 * @category layers
61 * @since 4.0.0
62 */
63 export const layerWin32: Layer.Layer<Path> = Layer.succeed(Path)(make({
64 ...NodePath.win32,
65 ...fileUrlOps(true)
66 }))
67
68 /**
69 * Provides the default `Path` service using the host platform's Node path
70 * implementation plus file URL conversion helpers.
71 *
72 * @stability unstable
73 * @category layers
74 * @since 4.0.0
75 */
76 export const layer: Layer.Layer<Path> = Layer.succeed(Path)(make({
77 ...NodePath,
78 ...fileUrlOps(undefined)
79 }))