effect-start 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/README.md +3 -3
  2. package/dist/Development.d.ts +8 -3
  3. package/dist/Development.js +14 -7
  4. package/dist/Effectify.d.ts +212 -0
  5. package/dist/Effectify.js +19 -0
  6. package/dist/FilePathPattern.d.ts +29 -0
  7. package/dist/FilePathPattern.js +86 -0
  8. package/dist/FileRouter.d.ts +39 -41
  9. package/dist/FileRouter.js +104 -158
  10. package/dist/FileRouterCodegen.d.ts +7 -8
  11. package/dist/FileRouterCodegen.js +97 -66
  12. package/dist/PlatformError.d.ts +46 -0
  13. package/dist/PlatformError.js +43 -0
  14. package/dist/PlatformRuntime.d.ts +27 -0
  15. package/dist/PlatformRuntime.js +51 -0
  16. package/dist/Route.d.ts +6 -2
  17. package/dist/Route.js +22 -0
  18. package/dist/RouteBody.d.ts +1 -1
  19. package/dist/RouteHttp.d.ts +1 -1
  20. package/dist/RouteHttp.js +12 -19
  21. package/dist/RouteMount.d.ts +2 -1
  22. package/dist/Start.d.ts +33 -6
  23. package/dist/Start.js +31 -13
  24. package/dist/Unique.d.ts +50 -0
  25. package/dist/Unique.js +187 -0
  26. package/dist/bun/BunHttpServer.js +5 -6
  27. package/dist/bun/BunPlatformHttpServer.d.ts +10 -0
  28. package/dist/bun/BunPlatformHttpServer.js +53 -0
  29. package/dist/bun/BunRoute.d.ts +4 -6
  30. package/dist/bun/BunRoute.js +10 -18
  31. package/dist/bun/BunRuntime.d.ts +2 -1
  32. package/dist/bun/BunRuntime.js +10 -5
  33. package/dist/bun/BunServer.d.ts +33 -0
  34. package/dist/bun/BunServer.js +133 -0
  35. package/dist/bun/BunServerRequest.d.ts +60 -0
  36. package/dist/bun/BunServerRequest.js +252 -0
  37. package/dist/bun/index.d.ts +1 -1
  38. package/dist/bun/index.js +1 -1
  39. package/dist/datastar/actions/fetch.d.ts +30 -0
  40. package/dist/datastar/actions/fetch.js +411 -0
  41. package/dist/datastar/actions/peek.d.ts +1 -0
  42. package/dist/datastar/actions/peek.js +14 -0
  43. package/dist/datastar/actions/setAll.d.ts +1 -0
  44. package/dist/datastar/actions/setAll.js +13 -0
  45. package/dist/datastar/actions/toggleAll.d.ts +1 -0
  46. package/dist/datastar/actions/toggleAll.js +13 -0
  47. package/dist/datastar/attributes/attr.d.ts +1 -0
  48. package/dist/datastar/attributes/attr.js +49 -0
  49. package/dist/datastar/attributes/bind.d.ts +1 -0
  50. package/dist/datastar/attributes/bind.js +183 -0
  51. package/dist/datastar/attributes/class.d.ts +1 -0
  52. package/dist/datastar/attributes/class.js +50 -0
  53. package/dist/datastar/attributes/computed.d.ts +1 -0
  54. package/dist/datastar/attributes/computed.js +27 -0
  55. package/dist/datastar/attributes/effect.d.ts +1 -0
  56. package/dist/datastar/attributes/effect.js +10 -0
  57. package/dist/datastar/attributes/indicator.d.ts +1 -0
  58. package/dist/datastar/attributes/indicator.js +32 -0
  59. package/dist/datastar/attributes/init.d.ts +1 -0
  60. package/dist/datastar/attributes/init.js +27 -0
  61. package/dist/datastar/attributes/jsonSignals.d.ts +1 -0
  62. package/dist/datastar/attributes/jsonSignals.js +31 -0
  63. package/dist/datastar/attributes/on.d.ts +1 -0
  64. package/dist/datastar/attributes/on.js +59 -0
  65. package/dist/datastar/attributes/onIntersect.d.ts +1 -0
  66. package/dist/datastar/attributes/onIntersect.js +54 -0
  67. package/dist/datastar/attributes/onInterval.d.ts +1 -0
  68. package/dist/datastar/attributes/onInterval.js +31 -0
  69. package/dist/datastar/attributes/onSignalPatch.d.ts +1 -0
  70. package/dist/datastar/attributes/onSignalPatch.js +44 -0
  71. package/dist/datastar/attributes/ref.d.ts +1 -0
  72. package/dist/datastar/attributes/ref.js +11 -0
  73. package/dist/datastar/attributes/show.d.ts +1 -0
  74. package/dist/datastar/attributes/show.js +32 -0
  75. package/dist/datastar/attributes/signals.d.ts +1 -0
  76. package/dist/datastar/attributes/signals.js +18 -0
  77. package/dist/datastar/attributes/style.d.ts +1 -0
  78. package/dist/datastar/attributes/style.js +56 -0
  79. package/dist/datastar/attributes/text.d.ts +1 -0
  80. package/dist/datastar/attributes/text.js +27 -0
  81. package/dist/datastar/engine.d.ts +156 -0
  82. package/dist/datastar/engine.js +971 -0
  83. package/dist/datastar/index.d.ts +24 -0
  84. package/dist/datastar/index.js +24 -0
  85. package/dist/datastar/load.d.ts +24 -0
  86. package/dist/datastar/load.js +24 -0
  87. package/dist/datastar/utils.d.ts +51 -0
  88. package/dist/datastar/utils.js +205 -0
  89. package/dist/datastar/watchers/patchElements.d.ts +1 -0
  90. package/dist/datastar/watchers/patchElements.js +420 -0
  91. package/dist/datastar/watchers/patchSignals.d.ts +1 -0
  92. package/dist/datastar/watchers/patchSignals.js +15 -0
  93. package/dist/index.d.ts +1 -0
  94. package/dist/index.js +1 -0
  95. package/dist/node/Effectify.d.ts +209 -0
  96. package/dist/node/Effectify.js +19 -0
  97. package/dist/node/FileSystem.d.ts +3 -5
  98. package/dist/node/FileSystem.js +42 -62
  99. package/dist/node/NodeFileSystem.d.ts +7 -0
  100. package/dist/node/NodeFileSystem.js +420 -0
  101. package/dist/node/NodeUtils.d.ts +2 -0
  102. package/dist/node/NodeUtils.js +20 -0
  103. package/dist/node/PlatformError.d.ts +46 -0
  104. package/dist/node/PlatformError.js +43 -0
  105. package/dist/testing/TestLogger.js +1 -1
  106. package/dist/x/tailwind/plugin.js +1 -1
  107. package/package.json +18 -7
  108. package/src/Development.ts +36 -40
  109. package/src/Effectify.ts +269 -0
  110. package/src/FilePathPattern.ts +115 -0
  111. package/src/FileRouter.ts +178 -255
  112. package/src/FileRouterCodegen.ts +135 -92
  113. package/src/PlatformError.ts +117 -0
  114. package/src/PlatformRuntime.ts +108 -0
  115. package/src/Route.ts +31 -2
  116. package/src/RouteBody.ts +1 -1
  117. package/src/RouteHttp.ts +15 -29
  118. package/src/RouteMount.ts +1 -1
  119. package/src/Start.ts +61 -27
  120. package/src/Unique.ts +232 -0
  121. package/src/bun/BunPlatformHttpServer.ts +88 -0
  122. package/src/bun/BunRoute.ts +14 -24
  123. package/src/bun/BunRuntime.ts +21 -5
  124. package/src/bun/BunServer.ts +228 -0
  125. package/src/bun/index.ts +1 -1
  126. package/src/datastar/README.md +18 -0
  127. package/src/datastar/actions/fetch.ts +609 -0
  128. package/src/datastar/actions/peek.ts +17 -0
  129. package/src/datastar/actions/setAll.ts +20 -0
  130. package/src/datastar/actions/toggleAll.ts +20 -0
  131. package/src/datastar/attributes/attr.ts +50 -0
  132. package/src/datastar/attributes/bind.ts +220 -0
  133. package/src/datastar/attributes/class.ts +57 -0
  134. package/src/datastar/attributes/computed.ts +33 -0
  135. package/src/datastar/attributes/effect.ts +11 -0
  136. package/src/datastar/attributes/indicator.ts +39 -0
  137. package/src/datastar/attributes/init.ts +35 -0
  138. package/src/datastar/attributes/jsonSignals.ts +38 -0
  139. package/src/datastar/attributes/on.ts +71 -0
  140. package/src/datastar/attributes/onIntersect.ts +65 -0
  141. package/src/datastar/attributes/onInterval.ts +39 -0
  142. package/src/datastar/attributes/onSignalPatch.ts +63 -0
  143. package/src/datastar/attributes/ref.ts +12 -0
  144. package/src/datastar/attributes/show.ts +33 -0
  145. package/src/datastar/attributes/signals.ts +22 -0
  146. package/src/datastar/attributes/style.ts +63 -0
  147. package/src/datastar/attributes/text.ts +30 -0
  148. package/src/datastar/engine.ts +1341 -0
  149. package/src/datastar/index.ts +25 -0
  150. package/src/datastar/utils.ts +286 -0
  151. package/src/datastar/watchers/patchElements.ts +554 -0
  152. package/src/datastar/watchers/patchSignals.ts +15 -0
  153. package/src/index.ts +1 -0
  154. package/src/node/{FileSystem.ts → NodeFileSystem.ts} +59 -97
  155. package/src/node/{Utils.ts → NodeUtils.ts} +2 -0
  156. package/src/testing/TestLogger.ts +1 -1
  157. package/src/x/tailwind/plugin.ts +1 -1
  158. package/dist/Random.d.ts +0 -5
  159. package/dist/Random.js +0 -49
  160. package/src/Commander.test.ts +0 -1639
  161. package/src/ContentNegotiation.test.ts +0 -603
  162. package/src/Development.test.ts +0 -119
  163. package/src/Entity.test.ts +0 -592
  164. package/src/FileRouterCodegen.todo.ts +0 -1133
  165. package/src/FileRouterPattern.test.ts +0 -147
  166. package/src/FileRouterPattern.ts +0 -59
  167. package/src/FileRouter_files.test.ts +0 -64
  168. package/src/FileRouter_path.test.ts +0 -145
  169. package/src/FileRouter_tree.test.ts +0 -132
  170. package/src/Http.test.ts +0 -319
  171. package/src/HttpAppExtra.test.ts +0 -103
  172. package/src/HttpUtils.test.ts +0 -85
  173. package/src/PathPattern.test.ts +0 -648
  174. package/src/Random.ts +0 -59
  175. package/src/RouteBody.test.ts +0 -232
  176. package/src/RouteHook.test.ts +0 -40
  177. package/src/RouteHttp.test.ts +0 -2909
  178. package/src/RouteMount.test.ts +0 -481
  179. package/src/RouteSchema.test.ts +0 -427
  180. package/src/RouteSse.test.ts +0 -249
  181. package/src/RouteTree.test.ts +0 -494
  182. package/src/RouteTrie.test.ts +0 -322
  183. package/src/RouterPattern.test.ts +0 -676
  184. package/src/RouterPattern.ts +0 -416
  185. package/src/StartApp.ts +0 -47
  186. package/src/Values.test.ts +0 -263
  187. package/src/bun/BunBundle.test.ts +0 -268
  188. package/src/bun/BunBundle_imports.test.ts +0 -48
  189. package/src/bun/BunHttpServer.test.ts +0 -251
  190. package/src/bun/BunHttpServer.ts +0 -306
  191. package/src/bun/BunImportTrackerPlugin.test.ts +0 -77
  192. package/src/bun/BunRoute.test.ts +0 -162
  193. package/src/bundler/BundleHttp.test.ts +0 -132
  194. package/src/effect/HttpRouter.test.ts +0 -548
  195. package/src/experimental/EncryptedCookies.test.ts +0 -488
  196. package/src/hyper/HyperHtml.test.ts +0 -209
  197. package/src/hyper/HyperRoute.test.tsx +0 -197
  198. package/src/middlewares/BasicAuthMiddleware.test.ts +0 -84
  199. package/src/testing/TestHttpClient.test.ts +0 -83
  200. package/src/testing/TestLogger.test.ts +0 -51
  201. package/src/x/datastar/Datastar.test.ts +0 -266
  202. package/src/x/tailwind/TailwindPlugin.test.ts +0 -333
  203. /package/src/bun/{BunHttpServer_web.ts → BunServerRequest.ts} +0 -0
@@ -1,9 +1,7 @@
1
- import * as Error from "@effect/platform/Error";
2
- import type { PlatformError } from "@effect/platform/Error";
3
- import { SystemError } from "@effect/platform/Error";
4
1
  import * as FileSystem from "@effect/platform/FileSystem";
5
2
  import * as Layer from "effect/Layer";
6
3
  import * as NFS from "node:fs";
4
+ import * as PlatformError from "./PlatformError.ts";
7
5
  export declare const layer: Layer.Layer<FileSystem.FileSystem, never, never>;
8
- export { Error, FileSystem, };
9
- export declare function handleErrnoException(module: SystemError["module"], method: string): (err: NodeJS.ErrnoException, [path]: [path: NFS.PathLike | number, ...args: Array<any>]) => PlatformError;
6
+ export { FileSystem, PlatformError as Error, };
7
+ export declare function handleErrnoException(module: PlatformError.SystemError["module"], method: string): (err: NodeJS.ErrnoException, [path]: [path: NFS.PathLike | number, ...args: Array<any>]) => PlatformError.PlatformError;
@@ -1,27 +1,25 @@
1
1
  /*
2
2
  * Adapted from @effect/platform
3
3
  */
4
- import { effectify } from "@effect/platform/Effectify";
5
- import * as Error from "@effect/platform/Error";
6
- import { SystemError } from "@effect/platform/Error";
7
4
  import * as FileSystem from "@effect/platform/FileSystem";
8
5
  import * as Effect from "effect/Effect";
9
- import { pipe } from "effect/Function";
6
+ import * as Function from "effect/Function";
10
7
  import * as Layer from "effect/Layer";
11
8
  import * as Option from "effect/Option";
12
9
  import * as Stream from "effect/Stream";
13
- import * as Crypto from "node:crypto";
10
+ import * as NCrypto from "node:crypto";
14
11
  import * as NFS from "node:fs";
15
12
  import * as NOS from "node:os";
16
13
  import * as NPath from "node:path";
17
- const handleBadArgument = (method) => (cause) => new Error.BadArgument({
14
+ import * as Effectify from "./Effectify.js";
15
+ import * as PlatformError from "./PlatformError.js";
16
+ const handleBadArgument = (method) => (cause) => new PlatformError.BadArgument({
18
17
  module: "FileSystem",
19
18
  method,
20
19
  cause,
21
20
  });
22
- // == access
23
21
  const access = (() => {
24
- const nodeAccess = effectify(NFS.access, handleErrnoException("FileSystem", "access"), handleBadArgument("access"));
22
+ const nodeAccess = Effectify.effectify(NFS.access, handleErrnoException("FileSystem", "access"), handleBadArgument("access"));
25
23
  return (path, options) => {
26
24
  let mode = NFS.constants.F_OK;
27
25
  if (options?.readable) {
@@ -33,46 +31,39 @@ const access = (() => {
33
31
  return nodeAccess(path, mode);
34
32
  };
35
33
  })();
36
- // == copy
37
34
  const copy = (() => {
38
- const nodeCp = effectify(NFS.cp, handleErrnoException("FileSystem", "copy"), handleBadArgument("copy"));
35
+ const nodeCp = Effectify.effectify(NFS.cp, handleErrnoException("FileSystem", "copy"), handleBadArgument("copy"));
39
36
  return (fromPath, toPath, options) => nodeCp(fromPath, toPath, {
40
37
  force: options?.overwrite ?? false,
41
38
  preserveTimestamps: options?.preserveTimestamps ?? false,
42
39
  recursive: true,
43
40
  });
44
41
  })();
45
- // == copyFile
46
42
  const copyFile = (() => {
47
- const nodeCopyFile = effectify(NFS.copyFile, handleErrnoException("FileSystem", "copyFile"), handleBadArgument("copyFile"));
43
+ const nodeCopyFile = Effectify.effectify(NFS.copyFile, handleErrnoException("FileSystem", "copyFile"), handleBadArgument("copyFile"));
48
44
  return (fromPath, toPath) => nodeCopyFile(fromPath, toPath);
49
45
  })();
50
- // == chmod
51
46
  const chmod = (() => {
52
- const nodeChmod = effectify(NFS.chmod, handleErrnoException("FileSystem", "chmod"), handleBadArgument("chmod"));
47
+ const nodeChmod = Effectify.effectify(NFS.chmod, handleErrnoException("FileSystem", "chmod"), handleBadArgument("chmod"));
53
48
  return (path, mode) => nodeChmod(path, mode);
54
49
  })();
55
- // == chown
56
50
  const chown = (() => {
57
- const nodeChown = effectify(NFS.chown, handleErrnoException("FileSystem", "chown"), handleBadArgument("chown"));
51
+ const nodeChown = Effectify.effectify(NFS.chown, handleErrnoException("FileSystem", "chown"), handleBadArgument("chown"));
58
52
  return (path, uid, gid) => nodeChown(path, uid, gid);
59
53
  })();
60
- // == link
61
54
  const link = (() => {
62
- const nodeLink = effectify(NFS.link, handleErrnoException("FileSystem", "link"), handleBadArgument("link"));
55
+ const nodeLink = Effectify.effectify(NFS.link, handleErrnoException("FileSystem", "link"), handleBadArgument("link"));
63
56
  return (existingPath, newPath) => nodeLink(existingPath, newPath);
64
57
  })();
65
- // == makeDirectory
66
58
  const makeDirectory = (() => {
67
- const nodeMkdir = effectify(NFS.mkdir, handleErrnoException("FileSystem", "makeDirectory"), handleBadArgument("makeDirectory"));
59
+ const nodeMkdir = Effectify.effectify(NFS.mkdir, handleErrnoException("FileSystem", "makeDirectory"), handleBadArgument("makeDirectory"));
68
60
  return (path, options) => nodeMkdir(path, {
69
61
  recursive: options?.recursive ?? false,
70
62
  mode: options?.mode,
71
63
  });
72
64
  })();
73
- // == makeTempDirectory
74
65
  const makeTempDirectoryFactory = (method) => {
75
- const nodeMkdtemp = effectify(NFS.mkdtemp, handleErrnoException("FileSystem", method), handleBadArgument(method));
66
+ const nodeMkdtemp = Effectify.effectify(NFS.mkdtemp, handleErrnoException("FileSystem", method), handleBadArgument(method));
76
67
  return (options) => Effect.suspend(() => {
77
68
  const prefix = options?.prefix ?? "";
78
69
  const directory = typeof options?.directory === "string"
@@ -82,36 +73,33 @@ const makeTempDirectoryFactory = (method) => {
82
73
  });
83
74
  };
84
75
  const makeTempDirectory = makeTempDirectoryFactory("makeTempDirectory");
85
- // == remove
86
76
  const removeFactory = (method) => {
87
- const nodeRm = effectify(NFS.rm, handleErrnoException("FileSystem", method), handleBadArgument(method));
77
+ const nodeRm = Effectify.effectify(NFS.rm, handleErrnoException("FileSystem", method), handleBadArgument(method));
88
78
  return (path, options) => nodeRm(path, {
89
79
  recursive: options?.recursive ?? false,
90
80
  force: options?.force ?? false,
91
81
  });
92
82
  };
93
83
  const remove = removeFactory("remove");
94
- // == makeTempDirectoryScoped
95
84
  const makeTempDirectoryScoped = (() => {
96
85
  const makeDirectory = makeTempDirectoryFactory("makeTempDirectoryScoped");
97
86
  const removeDirectory = removeFactory("makeTempDirectoryScoped");
98
87
  return (options) => Effect.acquireRelease(makeDirectory(options), (directory) => Effect.orDie(removeDirectory(directory, { recursive: true })));
99
88
  })();
100
- // == open
101
89
  const openFactory = (method) => {
102
- const nodeOpen = effectify(NFS.open, handleErrnoException("FileSystem", method), handleBadArgument(method));
103
- const nodeClose = effectify(NFS.close, handleErrnoException("FileSystem", method), handleBadArgument(method));
104
- return (path, options) => pipe(Effect.acquireRelease(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) => Effect.orDie(nodeClose(fd))), Effect.map((fd) => makeFile(FileSystem.FileDescriptor(fd), options?.flag?.startsWith("a") ?? false)));
90
+ const nodeOpen = Effectify.effectify(NFS.open, handleErrnoException("FileSystem", method), handleBadArgument(method));
91
+ const nodeClose = Effectify.effectify(NFS.close, handleErrnoException("FileSystem", method), handleBadArgument(method));
92
+ return (path, options) => Function.pipe(Effect.acquireRelease(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) => Effect.orDie(nodeClose(fd))), Effect.map((fd) => makeFile(FileSystem.FileDescriptor(fd), options?.flag?.startsWith("a") ?? false)));
105
93
  };
106
94
  const open = openFactory("open");
107
95
  const makeFile = (() => {
108
- const nodeReadFactory = (method) => effectify(NFS.read, handleErrnoException("FileSystem", method), handleBadArgument(method));
96
+ const nodeReadFactory = (method) => Effectify.effectify(NFS.read, handleErrnoException("FileSystem", method), handleBadArgument(method));
109
97
  const nodeRead = nodeReadFactory("read");
110
98
  const nodeReadAlloc = nodeReadFactory("readAlloc");
111
- const nodeStat = effectify(NFS.fstat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
112
- const nodeTruncate = effectify(NFS.ftruncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
113
- const nodeSync = effectify(NFS.fsync, handleErrnoException("FileSystem", "sync"), handleBadArgument("sync"));
114
- const nodeWriteFactory = (method) => effectify(NFS.write, handleErrnoException("FileSystem", method), handleBadArgument(method));
99
+ const nodeStat = Effectify.effectify(NFS.fstat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
100
+ const nodeTruncate = Effectify.effectify(NFS.ftruncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
101
+ const nodeSync = Effectify.effectify(NFS.fsync, handleErrnoException("FileSystem", "sync"), handleBadArgument("sync"));
102
+ const nodeWriteFactory = (method) => Effectify.effectify(NFS.write, handleErrnoException("FileSystem", method), handleBadArgument(method));
115
103
  const nodeWrite = nodeWriteFactory("write");
116
104
  const nodeWriteAll = nodeWriteFactory("writeAll");
117
105
  class FileImpl {
@@ -193,7 +181,7 @@ const makeFile = (() => {
193
181
  writeAllChunk(buffer) {
194
182
  return Effect.flatMap(Effect.suspend(() => nodeWriteAll(this.fd, buffer, undefined, undefined, this.append ? undefined : Number(this.position))), (bytesWritten) => {
195
183
  if (bytesWritten === 0) {
196
- return Effect.fail(new Error.SystemError({
184
+ return Effect.fail(new PlatformError.SystemError({
197
185
  module: "FileSystem",
198
186
  method: "writeAll",
199
187
  reason: "WriteZero",
@@ -215,26 +203,22 @@ const makeFile = (() => {
215
203
  }
216
204
  return (fd, append) => new FileImpl(fd, append);
217
205
  })();
218
- // == makeTempFile
219
206
  const makeTempFileFactory = (method) => {
220
207
  const makeDirectory = makeTempDirectoryFactory(method);
221
208
  const open = openFactory(method);
222
- const randomHexString = (bytes) => Effect.sync(() => Crypto.randomBytes(bytes).toString("hex"));
223
- return (options) => pipe(Effect.zip(makeDirectory(options), randomHexString(6)), Effect.map(([directory, random]) => NPath.join(directory, random + (options?.suffix ?? ""))), Effect.tap((path) => Effect.scoped(open(path, { flag: "w+" }))));
209
+ const randomHexString = (bytes) => Effect.sync(() => NCrypto.randomBytes(bytes).toString("hex"));
210
+ return (options) => Function.pipe(Effect.zip(makeDirectory(options), randomHexString(6)), Effect.map(([directory, random]) => NPath.join(directory, random + (options?.suffix ?? ""))), Effect.tap((path) => Effect.scoped(open(path, { flag: "w+" }))));
224
211
  };
225
212
  const makeTempFile = makeTempFileFactory("makeTempFile");
226
- // == makeTempFileScoped
227
213
  const makeTempFileScoped = (() => {
228
214
  const makeFile = makeTempFileFactory("makeTempFileScoped");
229
215
  const removeDirectory = removeFactory("makeTempFileScoped");
230
216
  return (options) => Effect.acquireRelease(makeFile(options), (file) => Effect.orDie(removeDirectory(NPath.dirname(file), { recursive: true })));
231
217
  })();
232
- // == readDirectory
233
218
  const readDirectory = (path, options) => Effect.tryPromise({
234
219
  try: () => NFS.promises.readdir(path, options),
235
220
  catch: (err) => handleErrnoException("FileSystem", "readDirectory")(err, [path]),
236
221
  });
237
- // == readFile
238
222
  const readFile = (path) => Effect.async((resume, signal) => {
239
223
  try {
240
224
  NFS.readFile(path, { signal }, (err, data) => {
@@ -250,22 +234,18 @@ const readFile = (path) => Effect.async((resume, signal) => {
250
234
  resume(Effect.fail(handleBadArgument("readFile")(err)));
251
235
  }
252
236
  });
253
- // == readLink
254
237
  const readLink = (() => {
255
- const nodeReadLink = effectify(NFS.readlink, handleErrnoException("FileSystem", "readLink"), handleBadArgument("readLink"));
238
+ const nodeReadLink = Effectify.effectify(NFS.readlink, handleErrnoException("FileSystem", "readLink"), handleBadArgument("readLink"));
256
239
  return (path) => nodeReadLink(path);
257
240
  })();
258
- // == realPath
259
241
  const realPath = (() => {
260
- const nodeRealPath = effectify(NFS.realpath, handleErrnoException("FileSystem", "realPath"), handleBadArgument("realPath"));
242
+ const nodeRealPath = Effectify.effectify(NFS.realpath, handleErrnoException("FileSystem", "realPath"), handleBadArgument("realPath"));
261
243
  return (path) => nodeRealPath(path);
262
244
  })();
263
- // == rename
264
245
  const rename = (() => {
265
- const nodeRename = effectify(NFS.rename, handleErrnoException("FileSystem", "rename"), handleBadArgument("rename"));
246
+ const nodeRename = Effectify.effectify(NFS.rename, handleErrnoException("FileSystem", "rename"), handleBadArgument("rename"));
266
247
  return (oldPath, newPath) => nodeRename(oldPath, newPath);
267
248
  })();
268
- // == stat
269
249
  const makeFileInfo = (stat) => ({
270
250
  type: stat.isFile()
271
251
  ? "File"
@@ -297,25 +277,21 @@ const makeFileInfo = (stat) => ({
297
277
  blocks: Option.fromNullable(stat.blocks),
298
278
  });
299
279
  const stat = (() => {
300
- const nodeStat = effectify(NFS.stat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
280
+ const nodeStat = Effectify.effectify(NFS.stat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
301
281
  return (path) => Effect.map(nodeStat(path), makeFileInfo);
302
282
  })();
303
- // == symlink
304
283
  const symlink = (() => {
305
- const nodeSymlink = effectify(NFS.symlink, handleErrnoException("FileSystem", "symlink"), handleBadArgument("symlink"));
284
+ const nodeSymlink = Effectify.effectify(NFS.symlink, handleErrnoException("FileSystem", "symlink"), handleBadArgument("symlink"));
306
285
  return (target, path) => nodeSymlink(target, path);
307
286
  })();
308
- // == truncate
309
287
  const truncate = (() => {
310
- const nodeTruncate = effectify(NFS.truncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
288
+ const nodeTruncate = Effectify.effectify(NFS.truncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
311
289
  return (path, length) => nodeTruncate(path, length !== undefined ? Number(length) : undefined);
312
290
  })();
313
- // == utimes
314
291
  const utimes = (() => {
315
- const nodeUtimes = effectify(NFS.utimes, handleErrnoException("FileSystem", "utime"), handleBadArgument("utime"));
292
+ const nodeUtimes = Effectify.effectify(NFS.utimes, handleErrnoException("FileSystem", "utime"), handleBadArgument("utime"));
316
293
  return (path, atime, mtime) => nodeUtimes(path, atime, mtime);
317
294
  })();
318
- // == watch
319
295
  const watchNode = (path, options) => Stream.asyncScoped((emit) => Effect.acquireRelease(Effect.sync(() => {
320
296
  const watcher = NFS.watch(path, { recursive: options?.recursive }, (event, path) => {
321
297
  if (!path)
@@ -337,7 +313,7 @@ const watchNode = (path, options) => Stream.asyncScoped((emit) => Effect.acquire
337
313
  }
338
314
  });
339
315
  watcher.on("error", (error) => {
340
- emit.fail(new Error.SystemError({
316
+ emit.fail(new PlatformError.SystemError({
341
317
  module: "FileSystem",
342
318
  reason: "Unknown",
343
319
  method: "watch",
@@ -351,7 +327,6 @@ const watchNode = (path, options) => Stream.asyncScoped((emit) => Effect.acquire
351
327
  return watcher;
352
328
  }), (watcher) => Effect.sync(() => watcher.close())));
353
329
  const watch = (backend, path, options) => stat(path).pipe(Effect.map((stat) => backend.pipe(Option.flatMap((_) => _.register(path, stat, options)), Option.getOrElse(() => watchNode(path, options)))), Stream.unwrap);
354
- // == writeFile
355
330
  const writeFile = (path, data, options) => Effect.async((resume, signal) => {
356
331
  try {
357
332
  NFS.writeFile(path, data, {
@@ -371,7 +346,7 @@ const writeFile = (path, data, options) => Effect.async((resume, signal) => {
371
346
  resume(Effect.fail(handleBadArgument("writeFile")(err)));
372
347
  }
373
348
  });
374
- const makeFileSystem = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend) => FileSystem.make({
349
+ const make = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend) => FileSystem.make({
375
350
  access,
376
351
  chmod,
377
352
  chown,
@@ -399,8 +374,13 @@ const makeFileSystem = Effect.map(Effect.serviceOption(FileSystem.WatchBackend),
399
374
  },
400
375
  writeFile,
401
376
  }));
402
- export const layer = Layer.effect(FileSystem.FileSystem, makeFileSystem);
403
- export { Error, FileSystem, };
377
+ export const layer = Layer.unwrapEffect(Effect
378
+ .gen(function* () {
379
+ const mod = yield* Effect.tryPromise(() => import("@effect/platform/FileSystem"));
380
+ return Layer.effect(mod.FileSystem, make);
381
+ })
382
+ .pipe(Effect.catchAll(() => Effect.die(new globalThis.Error("@effect/platform is not installed")))));
383
+ export { FileSystem, PlatformError as Error, };
404
384
  export function handleErrnoException(module, method) {
405
385
  return function (err, [path]) {
406
386
  let reason = "Unknown";
@@ -427,7 +407,7 @@ export function handleErrnoException(module, method) {
427
407
  reason = "BadResource";
428
408
  break;
429
409
  }
430
- return new SystemError({
410
+ return new PlatformError.SystemError({
431
411
  reason,
432
412
  module,
433
413
  method,
@@ -0,0 +1,7 @@
1
+ import * as FileSystem from "@effect/platform/FileSystem";
2
+ import * as Layer from "effect/Layer";
3
+ import * as NFS from "node:fs";
4
+ import * as PlatformError from "../PlatformError.ts";
5
+ export declare const layer: Layer.Layer<FileSystem.FileSystem, never, never>;
6
+ export { FileSystem, PlatformError as Error, };
7
+ export declare function handleErrnoException(module: PlatformError.SystemError["module"], method: string): (err: NodeJS.ErrnoException, [path]: [path: NFS.PathLike | number, ...args: Array<any>]) => PlatformError.PlatformError;