effect-start 0.23.1 → 0.25.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 (355) hide show
  1. package/dist/ChildProcess.js +32 -20
  2. package/dist/Commander.js +377 -293
  3. package/dist/ContentNegotiation.js +424 -318
  4. package/dist/Cookies.js +340 -271
  5. package/dist/Development.js +85 -49
  6. package/dist/Effectify.js +22 -14
  7. package/dist/Entity.js +260 -195
  8. package/dist/Fetch.js +192 -0
  9. package/dist/FilePathPattern.js +88 -77
  10. package/dist/FileRouter.js +192 -136
  11. package/dist/FileRouterCodegen.js +262 -191
  12. package/dist/FileSystem.js +126 -64
  13. package/dist/Http.js +96 -77
  14. package/dist/PathPattern.js +311 -273
  15. package/dist/PlatformError.js +36 -21
  16. package/dist/PlatformRuntime.js +65 -40
  17. package/dist/Route.js +122 -79
  18. package/dist/RouteBody.js +83 -58
  19. package/dist/RouteError.js +46 -25
  20. package/dist/RouteHook.js +58 -34
  21. package/dist/RouteHttp.js +346 -237
  22. package/dist/RouteHttpTracer.js +86 -58
  23. package/dist/RouteMount.js +81 -58
  24. package/dist/RouteSchema.js +253 -170
  25. package/dist/RouteSse.js +87 -72
  26. package/dist/RouteTree.js +99 -73
  27. package/dist/RouteTrie.js +160 -133
  28. package/dist/SchemaExtra.js +87 -62
  29. package/dist/Socket.js +32 -21
  30. package/dist/SqlIntrospect.js +317 -268
  31. package/dist/Start.js +55 -25
  32. package/dist/StartApp.js +3 -21
  33. package/dist/StreamExtra.js +109 -74
  34. package/dist/System.js +37 -21
  35. package/dist/TuplePathPattern.js +64 -58
  36. package/dist/Unique.js +159 -120
  37. package/dist/Values.js +48 -32
  38. package/dist/bun/BunBundle.js +158 -109
  39. package/dist/bun/BunChildProcessSpawner.js +121 -82
  40. package/dist/bun/BunImportTrackerPlugin.js +85 -63
  41. package/dist/bun/BunRoute.js +135 -99
  42. package/dist/bun/BunRuntime.js +39 -29
  43. package/dist/bun/BunServer.js +268 -140
  44. package/dist/bun/BunVirtualFilesPlugin.js +47 -33
  45. package/dist/bun/_BunEnhancedResolve.js +107 -82
  46. package/dist/bun/index.js +5 -5
  47. package/dist/bundler/Bundle.js +82 -38
  48. package/dist/bundler/BundleFiles.js +140 -82
  49. package/dist/bundler/BundleRoute.js +49 -38
  50. package/dist/client/Overlay.js +29 -28
  51. package/dist/client/ScrollState.js +94 -82
  52. package/dist/client/index.js +79 -61
  53. package/dist/console/Console.js +40 -24
  54. package/dist/console/ConsoleErrors.js +189 -178
  55. package/dist/console/ConsoleLogger.js +52 -43
  56. package/dist/console/ConsoleMetrics.js +69 -58
  57. package/dist/console/ConsoleProcess.js +57 -47
  58. package/dist/console/ConsoleStore.js +56 -45
  59. package/dist/console/ConsoleTracer.js +101 -88
  60. package/dist/console/Simulation.js +714 -563
  61. package/dist/console/index.js +3 -3
  62. package/dist/console/routes/tree.js +29 -28
  63. package/dist/datastar/actions/fetch.js +514 -381
  64. package/dist/datastar/actions/peek.js +12 -12
  65. package/dist/datastar/actions/setAll.js +18 -11
  66. package/dist/datastar/actions/toggleAll.js +18 -11
  67. package/dist/datastar/attributes/attr.js +48 -47
  68. package/dist/datastar/attributes/bind.js +186 -167
  69. package/dist/datastar/attributes/class.js +51 -44
  70. package/dist/datastar/attributes/computed.js +23 -24
  71. package/dist/datastar/attributes/effect.js +9 -8
  72. package/dist/datastar/attributes/indicator.js +32 -29
  73. package/dist/datastar/attributes/init.js +26 -25
  74. package/dist/datastar/attributes/jsonSignals.js +32 -29
  75. package/dist/datastar/attributes/on.js +76 -73
  76. package/dist/datastar/attributes/onIntersect.js +51 -51
  77. package/dist/datastar/attributes/onInterval.js +30 -29
  78. package/dist/datastar/attributes/onSignalPatch.js +49 -40
  79. package/dist/datastar/attributes/ref.js +10 -9
  80. package/dist/datastar/attributes/show.js +31 -30
  81. package/dist/datastar/attributes/signals.js +17 -16
  82. package/dist/datastar/attributes/style.js +56 -49
  83. package/dist/datastar/attributes/text.js +28 -25
  84. package/dist/datastar/engine.js +1079 -933
  85. package/dist/datastar/index.js +25 -24
  86. package/dist/datastar/utils.js +203 -155
  87. package/dist/datastar/watchers/patchElements.js +459 -372
  88. package/dist/datastar/watchers/patchSignals.js +13 -13
  89. package/dist/experimental/EncryptedCookies.js +305 -189
  90. package/dist/experimental/index.js +1 -1
  91. package/dist/hyper/Hyper.js +22 -17
  92. package/dist/hyper/HyperHtml.js +138 -123
  93. package/dist/hyper/HyperNode.js +11 -9
  94. package/dist/hyper/HyperRoute.js +41 -28
  95. package/dist/hyper/html.js +27 -27
  96. package/dist/hyper/index.js +5 -5
  97. package/dist/hyper/jsx-runtime.js +11 -5
  98. package/dist/index.js +8 -8
  99. package/dist/node/NodeFileSystem.js +606 -341
  100. package/dist/node/NodeUtils.js +21 -18
  101. package/dist/sql/Sql.js +8 -0
  102. package/dist/sql/bun/index.js +134 -67
  103. package/dist/sql/index.js +1 -0
  104. package/dist/sql/libsql/index.js +156 -0
  105. package/dist/sql/mssql/docker.js +103 -60
  106. package/dist/sql/mssql/index.js +182 -101
  107. package/dist/testing/TestLogger.js +39 -29
  108. package/dist/testing/index.js +2 -2
  109. package/dist/testing/utils.js +45 -23
  110. package/dist/x/cloudflare/CloudflareTunnel.js +61 -28
  111. package/dist/x/cloudflare/index.js +1 -1
  112. package/dist/x/tailscale/TailscaleTunnel.js +86 -60
  113. package/dist/x/tailscale/index.js +1 -1
  114. package/dist/x/tailwind/TailwindPlugin.js +280 -205
  115. package/dist/x/tailwind/compile.js +185 -129
  116. package/dist/x/tailwind/plugin.js +13 -11
  117. package/package.json +1 -1
  118. package/src/Development.ts +3 -1
  119. package/src/Entity.ts +17 -0
  120. package/src/Fetch.ts +271 -0
  121. package/src/SqlIntrospect.ts +64 -70
  122. package/src/Start.ts +21 -24
  123. package/src/StartApp.ts +1 -1
  124. package/src/bun/BunServer.ts +42 -10
  125. package/src/hyper/HyperHtml.ts +0 -1
  126. package/src/sql/bun/index.ts +1 -1
  127. package/src/sql/index.ts +1 -0
  128. package/src/sql/libsql/index.ts +173 -0
  129. package/src/sql/libsql/libsql.d.ts +39 -0
  130. package/src/sql/mssql/index.ts +1 -1
  131. package/dist/BlobStore.d.ts +0 -80
  132. package/dist/BlobStore.js +0 -19
  133. package/dist/ChildProcess.d.ts +0 -60
  134. package/dist/Commander.d.ts +0 -100
  135. package/dist/ContentNegotiation.d.ts +0 -12
  136. package/dist/Cookies.d.ts +0 -47
  137. package/dist/Development.d.ts +0 -39
  138. package/dist/Effectify.d.ts +0 -209
  139. package/dist/Entity.d.ts +0 -47
  140. package/dist/FilePathPattern.d.ts +0 -29
  141. package/dist/FileRouter.d.ts +0 -56
  142. package/dist/FileRouterCodegen.d.ts +0 -18
  143. package/dist/FileRouterPattern.d.ts +0 -9
  144. package/dist/FileRouterPattern.js +0 -35
  145. package/dist/FileSystem.d.ts +0 -158
  146. package/dist/Http.d.ts +0 -37
  147. package/dist/HttpAppExtra.d.ts +0 -7
  148. package/dist/HttpAppExtra.js +0 -320
  149. package/dist/HttpUtils.d.ts +0 -3
  150. package/dist/HttpUtils.js +0 -11
  151. package/dist/PathPattern.d.ts +0 -134
  152. package/dist/PlatformError.d.ts +0 -38
  153. package/dist/PlatformRuntime.d.ts +0 -27
  154. package/dist/Route.d.ts +0 -97
  155. package/dist/RouteBody.d.ts +0 -47
  156. package/dist/RouteError.d.ts +0 -98
  157. package/dist/RouteHook.d.ts +0 -12
  158. package/dist/RouteHttp.d.ts +0 -21
  159. package/dist/RouteHttpTracer.d.ts +0 -10
  160. package/dist/RouteMount.d.ts +0 -86
  161. package/dist/RouteSchema.d.ts +0 -86
  162. package/dist/RouteSse.d.ts +0 -21
  163. package/dist/RouteTree.d.ts +0 -57
  164. package/dist/RouteTrie.d.ts +0 -20
  165. package/dist/RouterPattern.d.ts +0 -118
  166. package/dist/RouterPattern.js +0 -269
  167. package/dist/SchemaExtra.d.ts +0 -7
  168. package/dist/Socket.d.ts +0 -27
  169. package/dist/Sql.d.ts +0 -34
  170. package/dist/Sql.js +0 -5
  171. package/dist/SqlIntrospect.d.ts +0 -91
  172. package/dist/Start.d.ts +0 -44
  173. package/dist/StartApp.d.ts +0 -19
  174. package/dist/StreamExtra.d.ts +0 -28
  175. package/dist/System.d.ts +0 -7
  176. package/dist/TuplePathPattern.d.ts +0 -9
  177. package/dist/Unique.d.ts +0 -50
  178. package/dist/Values.d.ts +0 -27
  179. package/dist/bun/BunBlobStoreDisk.d.ts +0 -6
  180. package/dist/bun/BunBlobStoreDisk.js +0 -116
  181. package/dist/bun/BunBlobStoreS3.d.ts +0 -11
  182. package/dist/bun/BunBlobStoreS3.js +0 -89
  183. package/dist/bun/BunBlobWatcherDisk.d.ts +0 -6
  184. package/dist/bun/BunBlobWatcherDisk.js +0 -60
  185. package/dist/bun/BunBlobWatcherQueue.d.ts +0 -6
  186. package/dist/bun/BunBlobWatcherQueue.js +0 -17
  187. package/dist/bun/BunBundle.d.ts +0 -11
  188. package/dist/bun/BunChildProcessSpawner.d.ts +0 -3
  189. package/dist/bun/BunHttpServer.d.ts +0 -44
  190. package/dist/bun/BunHttpServer.js +0 -186
  191. package/dist/bun/BunHttpServer_web.d.ts +0 -60
  192. package/dist/bun/BunHttpServer_web.js +0 -252
  193. package/dist/bun/BunImportTrackerPlugin.d.ts +0 -13
  194. package/dist/bun/BunPlatformHttpServer.d.ts +0 -10
  195. package/dist/bun/BunPlatformHttpServer.js +0 -53
  196. package/dist/bun/BunRoute.d.ts +0 -48
  197. package/dist/bun/BunRuntime.d.ts +0 -2
  198. package/dist/bun/BunServer.d.ts +0 -40
  199. package/dist/bun/BunServerRequest.d.ts +0 -60
  200. package/dist/bun/BunServerRequest.js +0 -252
  201. package/dist/bun/BunSql.d.ts +0 -4
  202. package/dist/bun/BunSql.js +0 -81
  203. package/dist/bun/BunVirtualFilesPlugin.d.ts +0 -4
  204. package/dist/bun/_BunEnhancedResolve.d.ts +0 -45
  205. package/dist/bun/index.d.ts +0 -5
  206. package/dist/bundler/Bundle.d.ts +0 -61
  207. package/dist/bundler/BundleFiles.d.ts +0 -13
  208. package/dist/bundler/BundleHttp.d.ts +0 -45
  209. package/dist/bundler/BundleHttp.js +0 -176
  210. package/dist/bundler/BundleRoute.d.ts +0 -27
  211. package/dist/client/Overlay.d.ts +0 -2
  212. package/dist/client/ScrollState.d.ts +0 -6
  213. package/dist/client/index.d.ts +0 -6
  214. package/dist/console/Console.d.ts +0 -6
  215. package/dist/console/ConsoleErrors.d.ts +0 -3
  216. package/dist/console/ConsoleLogger.d.ts +0 -3
  217. package/dist/console/ConsoleMetrics.d.ts +0 -3
  218. package/dist/console/ConsoleProcess.d.ts +0 -3
  219. package/dist/console/ConsoleStore.d.ts +0 -144
  220. package/dist/console/ConsoleTracer.d.ts +0 -3
  221. package/dist/console/Simulation.d.ts +0 -2
  222. package/dist/console/index.d.ts +0 -3
  223. package/dist/console/routes/errors/route.d.ts +0 -10
  224. package/dist/console/routes/errors/route.js +0 -47
  225. package/dist/console/routes/fiberDetail.d.ts +0 -16
  226. package/dist/console/routes/fiberDetail.js +0 -38
  227. package/dist/console/routes/fibers/route.d.ts +0 -10
  228. package/dist/console/routes/fibers/route.js +0 -19
  229. package/dist/console/routes/git/route.d.ts +0 -11
  230. package/dist/console/routes/git/route.js +0 -33
  231. package/dist/console/routes/layout.d.ts +0 -9
  232. package/dist/console/routes/layout.js +0 -3
  233. package/dist/console/routes/logs/route.d.ts +0 -10
  234. package/dist/console/routes/logs/route.js +0 -32
  235. package/dist/console/routes/metrics/route.d.ts +0 -10
  236. package/dist/console/routes/metrics/route.js +0 -17
  237. package/dist/console/routes/route.d.ts +0 -6
  238. package/dist/console/routes/route.js +0 -5
  239. package/dist/console/routes/routes/route.d.ts +0 -6
  240. package/dist/console/routes/routes/route.js +0 -20
  241. package/dist/console/routes/services/route.d.ts +0 -6
  242. package/dist/console/routes/services/route.js +0 -12
  243. package/dist/console/routes/system/route.d.ts +0 -10
  244. package/dist/console/routes/system/route.js +0 -18
  245. package/dist/console/routes/traceDetail.d.ts +0 -16
  246. package/dist/console/routes/traceDetail.js +0 -14
  247. package/dist/console/routes/traces/route.d.ts +0 -10
  248. package/dist/console/routes/traces/route.js +0 -39
  249. package/dist/console/routes/tree.d.ts +0 -153
  250. package/dist/console/ui/Errors.d.ts +0 -4
  251. package/dist/console/ui/Errors.js +0 -15
  252. package/dist/console/ui/Fibers.d.ts +0 -24
  253. package/dist/console/ui/Fibers.js +0 -121
  254. package/dist/console/ui/Git.d.ts +0 -20
  255. package/dist/console/ui/Git.js +0 -95
  256. package/dist/console/ui/Logs.d.ts +0 -4
  257. package/dist/console/ui/Logs.js +0 -25
  258. package/dist/console/ui/Metrics.d.ts +0 -4
  259. package/dist/console/ui/Metrics.js +0 -26
  260. package/dist/console/ui/Routes.d.ts +0 -8
  261. package/dist/console/ui/Routes.js +0 -70
  262. package/dist/console/ui/Services.d.ts +0 -10
  263. package/dist/console/ui/Services.js +0 -246
  264. package/dist/console/ui/Shell.d.ts +0 -10
  265. package/dist/console/ui/Shell.js +0 -7
  266. package/dist/console/ui/System.d.ts +0 -4
  267. package/dist/console/ui/System.js +0 -35
  268. package/dist/console/ui/Traces.d.ts +0 -12
  269. package/dist/console/ui/Traces.js +0 -179
  270. package/dist/datastar/actions/fetch.d.ts +0 -30
  271. package/dist/datastar/actions/peek.d.ts +0 -1
  272. package/dist/datastar/actions/setAll.d.ts +0 -1
  273. package/dist/datastar/actions/toggleAll.d.ts +0 -1
  274. package/dist/datastar/attributes/attr.d.ts +0 -1
  275. package/dist/datastar/attributes/bind.d.ts +0 -1
  276. package/dist/datastar/attributes/class.d.ts +0 -1
  277. package/dist/datastar/attributes/computed.d.ts +0 -1
  278. package/dist/datastar/attributes/effect.d.ts +0 -1
  279. package/dist/datastar/attributes/indicator.d.ts +0 -1
  280. package/dist/datastar/attributes/init.d.ts +0 -1
  281. package/dist/datastar/attributes/jsonSignals.d.ts +0 -1
  282. package/dist/datastar/attributes/on.d.ts +0 -1
  283. package/dist/datastar/attributes/onIntersect.d.ts +0 -1
  284. package/dist/datastar/attributes/onInterval.d.ts +0 -1
  285. package/dist/datastar/attributes/onSignalPatch.d.ts +0 -1
  286. package/dist/datastar/attributes/ref.d.ts +0 -1
  287. package/dist/datastar/attributes/show.d.ts +0 -1
  288. package/dist/datastar/attributes/signals.d.ts +0 -1
  289. package/dist/datastar/attributes/style.d.ts +0 -1
  290. package/dist/datastar/attributes/text.d.ts +0 -1
  291. package/dist/datastar/engine.d.ts +0 -162
  292. package/dist/datastar/happydom.d.ts +0 -1
  293. package/dist/datastar/happydom.js +0 -8
  294. package/dist/datastar/index.d.ts +0 -24
  295. package/dist/datastar/load.d.ts +0 -24
  296. package/dist/datastar/load.js +0 -24
  297. package/dist/datastar/utils.d.ts +0 -51
  298. package/dist/datastar/watchers/patchElements.d.ts +0 -1
  299. package/dist/datastar/watchers/patchSignals.d.ts +0 -1
  300. package/dist/experimental/EncryptedCookies.d.ts +0 -48
  301. package/dist/experimental/SseHttpResponse.d.ts +0 -7
  302. package/dist/experimental/SseHttpResponse.js +0 -28
  303. package/dist/experimental/index.d.ts +0 -1
  304. package/dist/hyper/Hyper.d.ts +0 -25
  305. package/dist/hyper/HyperHtml.d.ts +0 -23
  306. package/dist/hyper/HyperHtml.test.d.ts +0 -1
  307. package/dist/hyper/HyperHtml.test.js +0 -197
  308. package/dist/hyper/HyperNode.d.ts +0 -14
  309. package/dist/hyper/HyperRoute.d.ts +0 -8
  310. package/dist/hyper/HyperRoute.test.d.ts +0 -1
  311. package/dist/hyper/HyperRoute.test.js +0 -83
  312. package/dist/hyper/html.d.ts +0 -11
  313. package/dist/hyper/index.d.ts +0 -6
  314. package/dist/hyper/jsx-runtime.d.ts +0 -7
  315. package/dist/index.d.ts +0 -8
  316. package/dist/inference_check.d.ts +0 -1
  317. package/dist/inference_check.js +0 -15
  318. package/dist/lint/plugin.d.ts +0 -86
  319. package/dist/lint/plugin.js +0 -341
  320. package/dist/middlewares/BasicAuthMiddleware.d.ts +0 -8
  321. package/dist/middlewares/BasicAuthMiddleware.js +0 -22
  322. package/dist/middlewares/index.d.ts +0 -1
  323. package/dist/middlewares/index.js +0 -1
  324. package/dist/node/Effectify.d.ts +0 -209
  325. package/dist/node/Effectify.js +0 -19
  326. package/dist/node/FileSystem.d.ts +0 -7
  327. package/dist/node/FileSystem.js +0 -420
  328. package/dist/node/NodeFileSystem.d.ts +0 -7
  329. package/dist/node/NodeUtils.d.ts +0 -2
  330. package/dist/node/PlatformError.d.ts +0 -46
  331. package/dist/node/PlatformError.js +0 -43
  332. package/dist/node/Utils.d.ts +0 -1
  333. package/dist/node/Utils.js +0 -19
  334. package/dist/repro_fail.d.ts +0 -1
  335. package/dist/repro_fail.js +0 -14
  336. package/dist/sql/bun/index.d.ts +0 -3
  337. package/dist/sql/mssql/docker.d.ts +0 -2
  338. package/dist/sql/mssql/index.d.ts +0 -21
  339. package/dist/testing/TestHttpClient.d.ts +0 -13
  340. package/dist/testing/TestHttpClient.js +0 -68
  341. package/dist/testing/TestLogger.d.ts +0 -13
  342. package/dist/testing/index.d.ts +0 -2
  343. package/dist/testing/utils.d.ts +0 -9
  344. package/dist/x/cloudflare/CloudflareTunnel.d.ts +0 -10
  345. package/dist/x/cloudflare/index.d.ts +0 -1
  346. package/dist/x/datastar/Datastar.d.ts +0 -6
  347. package/dist/x/datastar/Datastar.js +0 -47
  348. package/dist/x/datastar/index.d.ts +0 -1
  349. package/dist/x/datastar/index.js +0 -1
  350. package/dist/x/tailscale/TailscaleTunnel.d.ts +0 -15
  351. package/dist/x/tailscale/index.d.ts +0 -1
  352. package/dist/x/tailwind/TailwindPlugin.d.ts +0 -23
  353. package/dist/x/tailwind/compile.d.ts +0 -19
  354. package/dist/x/tailwind/plugin.d.ts +0 -2
  355. /package/src/{Sql.ts → sql/Sql.ts} +0 -0
@@ -1,347 +1,597 @@
1
- import * as Effect from "effect/Effect";
2
- import * as Function from "effect/Function";
3
- import * as Layer from "effect/Layer";
4
- import * as Option from "effect/Option";
5
- import * as FileSystem from "../FileSystem.js";
6
- import * as Stream from "effect/Stream";
7
- import * as NCrypto from "node:crypto";
8
- import * as NFS from "node:fs";
9
- import * as NOS from "node:os";
10
- import * as NPath from "node:path";
11
- import * as PlatformError from "../PlatformError.js";
12
- import * as Effectify from "../Effectify.js";
13
- const handleBadArgument = (method) => (cause) => new PlatformError.BadArgument({
1
+ /*
2
+ * Adapted from @effect/platform
3
+ */
4
+ import * as Effect from "effect/Effect"
5
+ import * as Function from "effect/Function"
6
+ import * as Layer from "effect/Layer"
7
+ import * as Option from "effect/Option"
8
+ import * as FileSystem from "../FileSystem.js"
9
+ import * as Stream from "effect/Stream"
10
+ import * as NCrypto from "node:crypto"
11
+ import * as NFS from "node:fs"
12
+ import * as NOS from "node:os"
13
+ import * as NPath from "node:path"
14
+ import * as PlatformError from "../PlatformError.js"
15
+ import * as Effectify from "../Effectify.js"
16
+
17
+ const handleBadArgument = (method) => (cause) =>
18
+ new PlatformError.BadArgument({
14
19
  module: "FileSystem",
15
20
  method,
16
21
  cause,
17
- });
22
+ })
23
+
18
24
  const access = (() => {
19
- const nodeAccess = Effectify.effectify(NFS.access, handleErrnoException("FileSystem", "access"), handleBadArgument("access"));
20
- return (path, options) => {
21
- let mode = NFS.constants.F_OK;
22
- if (options?.readable) {
23
- mode |= NFS.constants.R_OK;
24
- }
25
- if (options?.writable) {
26
- mode |= NFS.constants.W_OK;
27
- }
28
- return nodeAccess(path, mode);
29
- };
30
- })();
25
+ const nodeAccess = Effectify.effectify(
26
+ NFS.access,
27
+ handleErrnoException("FileSystem", "access"),
28
+ handleBadArgument("access"),
29
+ )
30
+ return (path, options) => {
31
+ let mode = NFS.constants.F_OK
32
+ if (options?.readable) {
33
+ mode |= NFS.constants.R_OK
34
+ }
35
+ if (options?.writable) {
36
+ mode |= NFS.constants.W_OK
37
+ }
38
+ return nodeAccess(path, mode)
39
+ }
40
+ })()
41
+
31
42
  const copy = (() => {
32
- const nodeCp = Effectify.effectify(NFS.cp, handleErrnoException("FileSystem", "copy"), handleBadArgument("copy"));
33
- return (fromPath, toPath, options) => nodeCp(fromPath, toPath, {
34
- force: options?.overwrite ?? false,
35
- preserveTimestamps: options?.preserveTimestamps ?? false,
36
- recursive: true,
37
- });
38
- })();
43
+ const nodeCp = Effectify.effectify(
44
+ NFS.cp,
45
+ handleErrnoException("FileSystem", "copy"),
46
+ handleBadArgument("copy"),
47
+ )
48
+ return (fromPath, toPath, options) =>
49
+ nodeCp(fromPath, toPath, {
50
+ force: options?.overwrite ?? false,
51
+ preserveTimestamps: options?.preserveTimestamps ?? false,
52
+ recursive: true,
53
+ })
54
+ })()
55
+
39
56
  const copyFile = (() => {
40
- const nodeCopyFile = Effectify.effectify(NFS.copyFile, handleErrnoException("FileSystem", "copyFile"), handleBadArgument("copyFile"));
41
- return (fromPath, toPath) => nodeCopyFile(fromPath, toPath);
42
- })();
57
+ const nodeCopyFile = Effectify.effectify(
58
+ NFS.copyFile,
59
+ handleErrnoException("FileSystem", "copyFile"),
60
+ handleBadArgument("copyFile"),
61
+ )
62
+ return (fromPath, toPath) => nodeCopyFile(fromPath, toPath)
63
+ })()
64
+
43
65
  const chmod = (() => {
44
- const nodeChmod = Effectify.effectify(NFS.chmod, handleErrnoException("FileSystem", "chmod"), handleBadArgument("chmod"));
45
- return (path, mode) => nodeChmod(path, mode);
46
- })();
66
+ const nodeChmod = Effectify.effectify(
67
+ NFS.chmod,
68
+ handleErrnoException("FileSystem", "chmod"),
69
+ handleBadArgument("chmod"),
70
+ )
71
+ return (path, mode) => nodeChmod(path, mode)
72
+ })()
73
+
47
74
  const chown = (() => {
48
- const nodeChown = Effectify.effectify(NFS.chown, handleErrnoException("FileSystem", "chown"), handleBadArgument("chown"));
49
- return (path, uid, gid) => nodeChown(path, uid, gid);
50
- })();
75
+ const nodeChown = Effectify.effectify(
76
+ NFS.chown,
77
+ handleErrnoException("FileSystem", "chown"),
78
+ handleBadArgument("chown"),
79
+ )
80
+ return (path, uid, gid) => nodeChown(path, uid, gid)
81
+ })()
82
+
51
83
  const link = (() => {
52
- const nodeLink = Effectify.effectify(NFS.link, handleErrnoException("FileSystem", "link"), handleBadArgument("link"));
53
- return (existingPath, newPath) => nodeLink(existingPath, newPath);
54
- })();
84
+ const nodeLink = Effectify.effectify(
85
+ NFS.link,
86
+ handleErrnoException("FileSystem", "link"),
87
+ handleBadArgument("link"),
88
+ )
89
+ return (existingPath, newPath) => nodeLink(existingPath, newPath)
90
+ })()
91
+
55
92
  const makeDirectory = (() => {
56
- const nodeMkdir = Effectify.effectify(NFS.mkdir, handleErrnoException("FileSystem", "makeDirectory"), handleBadArgument("makeDirectory"));
57
- return (path, options) => nodeMkdir(path, {
58
- recursive: options?.recursive ?? false,
59
- mode: options?.mode,
60
- });
61
- })();
93
+ const nodeMkdir = Effectify.effectify(
94
+ NFS.mkdir,
95
+ handleErrnoException("FileSystem", "makeDirectory"),
96
+ handleBadArgument("makeDirectory"),
97
+ )
98
+ return (path, options) =>
99
+ nodeMkdir(path, {
100
+ recursive: options?.recursive ?? false,
101
+ mode: options?.mode,
102
+ })
103
+ })()
104
+
62
105
  const makeTempDirectoryFactory = (method) => {
63
- const nodeMkdtemp = Effectify.effectify(NFS.mkdtemp, handleErrnoException("FileSystem", method), handleBadArgument(method));
64
- return (options) => Effect.suspend(() => {
65
- const prefix = options?.prefix ?? "";
66
- const directory = typeof options?.directory === "string" ? NPath.join(options.directory, ".") : NOS.tmpdir();
67
- return nodeMkdtemp(prefix ? NPath.join(directory, prefix) : directory + "/");
68
- });
69
- };
70
- const makeTempDirectory = makeTempDirectoryFactory("makeTempDirectory");
106
+ const nodeMkdtemp = Effectify.effectify(
107
+ NFS.mkdtemp,
108
+ handleErrnoException("FileSystem", method),
109
+ handleBadArgument(method),
110
+ )
111
+ return (options) =>
112
+ Effect.suspend(() => {
113
+ const prefix = options?.prefix ?? ""
114
+ const directory =
115
+ typeof options?.directory === "string" ? NPath.join(options.directory, ".") : NOS.tmpdir()
116
+
117
+ return nodeMkdtemp(prefix ? NPath.join(directory, prefix) : directory + "/")
118
+ })
119
+ }
120
+ const makeTempDirectory = makeTempDirectoryFactory("makeTempDirectory")
121
+
71
122
  const removeFactory = (method) => {
72
- const nodeRm = Effectify.effectify(NFS.rm, handleErrnoException("FileSystem", method), handleBadArgument(method));
73
- return (path, options) => nodeRm(path, {
74
- recursive: options?.recursive ?? false,
75
- force: options?.force ?? false,
76
- });
77
- };
78
- const remove = removeFactory("remove");
123
+ const nodeRm = Effectify.effectify(
124
+ NFS.rm,
125
+ handleErrnoException("FileSystem", method),
126
+ handleBadArgument(method),
127
+ )
128
+ return (path, options) =>
129
+ nodeRm(path, {
130
+ recursive: options?.recursive ?? false,
131
+ force: options?.force ?? false,
132
+ })
133
+ }
134
+ const remove = removeFactory("remove")
135
+
79
136
  const makeTempDirectoryScoped = (() => {
80
- const makeDirectory = makeTempDirectoryFactory("makeTempDirectoryScoped");
81
- const removeDirectory = removeFactory("makeTempDirectoryScoped");
82
- return (options) => Effect.acquireRelease(makeDirectory(options), (directory) => Effect.orDie(removeDirectory(directory, { recursive: true })));
83
- })();
137
+ const makeDirectory = makeTempDirectoryFactory("makeTempDirectoryScoped")
138
+ const removeDirectory = removeFactory("makeTempDirectoryScoped")
139
+ return (options) =>
140
+ Effect.acquireRelease(makeDirectory(options), (directory) =>
141
+ Effect.orDie(removeDirectory(directory, { recursive: true })),
142
+ )
143
+ })()
144
+
84
145
  const openFactory = (method) => {
85
- const nodeOpen = Effectify.effectify(NFS.open, handleErrnoException("FileSystem", method), handleBadArgument(method));
86
- const nodeClose = Effectify.effectify(NFS.close, handleErrnoException("FileSystem", method), handleBadArgument(method));
87
- 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)));
88
- };
89
- const open = openFactory("open");
146
+ const nodeOpen = Effectify.effectify(
147
+ NFS.open,
148
+ handleErrnoException("FileSystem", method),
149
+ handleBadArgument(method),
150
+ )
151
+ const nodeClose = Effectify.effectify(
152
+ NFS.close,
153
+ handleErrnoException("FileSystem", method),
154
+ handleBadArgument(method),
155
+ )
156
+
157
+ return (path, options) =>
158
+ Function.pipe(
159
+ Effect.acquireRelease(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) =>
160
+ Effect.orDie(nodeClose(fd)),
161
+ ),
162
+ Effect.map((fd) =>
163
+ makeFile(FileSystem.FileDescriptor(fd), options?.flag?.startsWith("a") ?? false),
164
+ ),
165
+ )
166
+ }
167
+ const open = openFactory("open")
168
+
90
169
  const makeFile = (() => {
91
- const nodeReadFactory = (method) => Effectify.effectify(NFS.read, handleErrnoException("FileSystem", method), handleBadArgument(method));
92
- const nodeRead = nodeReadFactory("read");
93
- const nodeReadAlloc = nodeReadFactory("readAlloc");
94
- const nodeStat = Effectify.effectify(NFS.fstat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
95
- const nodeTruncate = Effectify.effectify(NFS.ftruncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
96
- const nodeSync = Effectify.effectify(NFS.fsync, handleErrnoException("FileSystem", "sync"), handleBadArgument("sync"));
97
- const nodeWriteFactory = (method) => Effectify.effectify(NFS.write, handleErrnoException("FileSystem", method), handleBadArgument(method));
98
- const nodeWrite = nodeWriteFactory("write");
99
- const nodeWriteAll = nodeWriteFactory("writeAll");
100
- class FileImpl {
101
- [FileSystem.FileTypeId];
102
- fd;
103
- append;
104
- semaphore = Effect.unsafeMakeSemaphore(1);
105
- position = 0n;
106
- constructor(fd, append) {
107
- this[FileSystem.FileTypeId] = FileSystem.FileTypeId;
108
- this.fd = fd;
109
- this.append = append;
110
- }
111
- get stat() {
112
- return Effect.map(nodeStat(this.fd), makeFileInfo);
113
- }
114
- get sync() {
115
- return nodeSync(this.fd);
116
- }
117
- seek(offset, from) {
118
- const offsetSize = FileSystem.Size(offset);
119
- return this.semaphore.withPermits(1)(Effect.sync(() => {
120
- if (from === "start") {
121
- this.position = offsetSize;
122
- }
123
- else if (from === "current") {
124
- this.position = this.position + offsetSize;
125
- }
126
- return this.position;
127
- }));
128
- }
129
- read(buffer) {
130
- return this.semaphore.withPermits(1)(Effect.map(Effect.suspend(() => nodeRead(this.fd, {
131
- buffer,
132
- position: this.position,
133
- })), (bytesRead) => {
134
- const sizeRead = FileSystem.Size(bytesRead);
135
- this.position = this.position + sizeRead;
136
- return sizeRead;
137
- }));
138
- }
139
- readAlloc(size) {
140
- const sizeNumber = Number(size);
141
- return this.semaphore.withPermits(1)(Effect.flatMap(Effect.sync(() => Buffer.allocUnsafeSlow(sizeNumber)), (buffer) => Effect.map(nodeReadAlloc(this.fd, {
170
+ const nodeReadFactory = (method) =>
171
+ Effectify.effectify(
172
+ NFS.read,
173
+ handleErrnoException("FileSystem", method),
174
+ handleBadArgument(method),
175
+ )
176
+ const nodeRead = nodeReadFactory("read")
177
+ const nodeReadAlloc = nodeReadFactory("readAlloc")
178
+ const nodeStat = Effectify.effectify(
179
+ NFS.fstat,
180
+ handleErrnoException("FileSystem", "stat"),
181
+ handleBadArgument("stat"),
182
+ )
183
+ const nodeTruncate = Effectify.effectify(
184
+ NFS.ftruncate,
185
+ handleErrnoException("FileSystem", "truncate"),
186
+ handleBadArgument("truncate"),
187
+ )
188
+
189
+ const nodeSync = Effectify.effectify(
190
+ NFS.fsync,
191
+ handleErrnoException("FileSystem", "sync"),
192
+ handleBadArgument("sync"),
193
+ )
194
+
195
+ const nodeWriteFactory = (method) =>
196
+ Effectify.effectify(
197
+ NFS.write,
198
+ handleErrnoException("FileSystem", method),
199
+ handleBadArgument(method),
200
+ )
201
+ const nodeWrite = nodeWriteFactory("write")
202
+ const nodeWriteAll = nodeWriteFactory("writeAll")
203
+
204
+ class FileImpl {
205
+ [FileSystem.FileTypeId]
206
+ fd
207
+ append
208
+
209
+ semaphore = Effect.unsafeMakeSemaphore(1)
210
+ position = 0n
211
+
212
+ constructor(fd, append) {
213
+ this[FileSystem.FileTypeId] = FileSystem.FileTypeId
214
+ this.fd = fd
215
+ this.append = append
216
+ }
217
+
218
+ get stat() {
219
+ return Effect.map(nodeStat(this.fd), makeFileInfo)
220
+ }
221
+
222
+ get sync() {
223
+ return nodeSync(this.fd)
224
+ }
225
+
226
+ seek(offset, from) {
227
+ const offsetSize = FileSystem.Size(offset)
228
+ return this.semaphore.withPermits(1)(
229
+ Effect.sync(() => {
230
+ if (from === "start") {
231
+ this.position = offsetSize
232
+ } else if (from === "current") {
233
+ this.position = this.position + offsetSize
234
+ }
235
+
236
+ return this.position
237
+ }),
238
+ )
239
+ }
240
+
241
+ read(buffer) {
242
+ return this.semaphore.withPermits(1)(
243
+ Effect.map(
244
+ Effect.suspend(() =>
245
+ nodeRead(this.fd, {
246
+ buffer,
247
+ position: this.position,
248
+ }),
249
+ ),
250
+ (bytesRead) => {
251
+ const sizeRead = FileSystem.Size(bytesRead)
252
+ this.position = this.position + sizeRead
253
+ return sizeRead
254
+ },
255
+ ),
256
+ )
257
+ }
258
+
259
+ readAlloc(size) {
260
+ const sizeNumber = Number(size)
261
+ return this.semaphore.withPermits(1)(
262
+ Effect.flatMap(
263
+ Effect.sync(() => Buffer.allocUnsafeSlow(sizeNumber)),
264
+ (buffer) =>
265
+ Effect.map(
266
+ nodeReadAlloc(this.fd, {
142
267
  buffer,
143
268
  position: this.position,
144
- }), (bytesRead) => {
269
+ }),
270
+ (bytesRead) => {
145
271
  if (bytesRead === 0) {
146
- return Option.none();
272
+ return Option.none()
147
273
  }
148
- this.position = this.position + BigInt(bytesRead);
274
+
275
+ this.position = this.position + BigInt(bytesRead)
149
276
  if (bytesRead === sizeNumber) {
150
- return Option.some(buffer);
277
+ return Option.some(buffer)
151
278
  }
152
- const dst = Buffer.allocUnsafeSlow(bytesRead);
153
- buffer.copy(dst, 0, 0, bytesRead);
154
- return Option.some(dst);
155
- })));
156
- }
157
- truncate(length) {
158
- return this.semaphore.withPermits(1)(Effect.map(nodeTruncate(this.fd, length ? Number(length) : undefined), () => {
159
- if (!this.append) {
160
- const len = BigInt(length ?? 0);
161
- if (this.position > len) {
162
- this.position = len;
163
- }
164
- }
165
- }));
166
- }
167
- write(buffer) {
168
- return this.semaphore.withPermits(1)(Effect.map(Effect.suspend(() => nodeWrite(this.fd, buffer, undefined, undefined, this.append ? undefined : Number(this.position))), (bytesWritten) => {
169
- const sizeWritten = FileSystem.Size(bytesWritten);
170
- if (!this.append) {
171
- this.position = this.position + sizeWritten;
172
- }
173
- return sizeWritten;
174
- }));
175
- }
176
- writeAllChunk(buffer) {
177
- return Effect.flatMap(Effect.suspend(() => nodeWriteAll(this.fd, buffer, undefined, undefined, this.append ? undefined : Number(this.position))), (bytesWritten) => {
178
- if (bytesWritten === 0) {
179
- return Effect.fail(new PlatformError.SystemError({
180
- module: "FileSystem",
181
- method: "writeAll",
182
- reason: "WriteZero",
183
- pathOrDescriptor: this.fd,
184
- description: "write returned 0 bytes written",
185
- }));
186
- }
187
- if (!this.append) {
188
- this.position = this.position + BigInt(bytesWritten);
189
- }
190
- return bytesWritten < buffer.length
191
- ? this.writeAllChunk(buffer.subarray(bytesWritten))
192
- : Effect.void;
193
- });
194
- }
195
- writeAll(buffer) {
196
- return this.semaphore.withPermits(1)(this.writeAllChunk(buffer));
197
- }
279
+
280
+ const dst = Buffer.allocUnsafeSlow(bytesRead)
281
+ buffer.copy(dst, 0, 0, bytesRead)
282
+ return Option.some(dst)
283
+ },
284
+ ),
285
+ ),
286
+ )
287
+ }
288
+
289
+ truncate(length) {
290
+ return this.semaphore.withPermits(1)(
291
+ Effect.map(nodeTruncate(this.fd, length ? Number(length) : undefined), () => {
292
+ if (!this.append) {
293
+ const len = BigInt(length ?? 0)
294
+ if (this.position > len) {
295
+ this.position = len
296
+ }
297
+ }
298
+ }),
299
+ )
300
+ }
301
+
302
+ write(buffer) {
303
+ return this.semaphore.withPermits(1)(
304
+ Effect.map(
305
+ Effect.suspend(() =>
306
+ nodeWrite(
307
+ this.fd,
308
+ buffer,
309
+ undefined,
310
+ undefined,
311
+ this.append ? undefined : Number(this.position),
312
+ ),
313
+ ),
314
+ (bytesWritten) => {
315
+ const sizeWritten = FileSystem.Size(bytesWritten)
316
+ if (!this.append) {
317
+ this.position = this.position + sizeWritten
318
+ }
319
+
320
+ return sizeWritten
321
+ },
322
+ ),
323
+ )
324
+ }
325
+
326
+ writeAllChunk(buffer) {
327
+ return Effect.flatMap(
328
+ Effect.suspend(() =>
329
+ nodeWriteAll(
330
+ this.fd,
331
+ buffer,
332
+ undefined,
333
+ undefined,
334
+ this.append ? undefined : Number(this.position),
335
+ ),
336
+ ),
337
+ (bytesWritten) => {
338
+ if (bytesWritten === 0) {
339
+ return Effect.fail(
340
+ new PlatformError.SystemError({
341
+ module: "FileSystem",
342
+ method: "writeAll",
343
+ reason: "WriteZero",
344
+ pathOrDescriptor: this.fd,
345
+ description: "write returned 0 bytes written",
346
+ }),
347
+ )
348
+ }
349
+
350
+ if (!this.append) {
351
+ this.position = this.position + BigInt(bytesWritten)
352
+ }
353
+
354
+ return bytesWritten < buffer.length
355
+ ? this.writeAllChunk(buffer.subarray(bytesWritten))
356
+ : Effect.void
357
+ },
358
+ )
359
+ }
360
+
361
+ writeAll(buffer) {
362
+ return this.semaphore.withPermits(1)(this.writeAllChunk(buffer))
198
363
  }
199
- return (fd, append) => new FileImpl(fd, append);
200
- })();
364
+ }
365
+
366
+ return (fd, append) =>
367
+ new FileImpl(fd, append)
368
+ })()
369
+
201
370
  const makeTempFileFactory = (method) => {
202
- const makeDirectory = makeTempDirectoryFactory(method);
203
- const open = openFactory(method);
204
- const randomHexString = (bytes) => Effect.sync(() => NCrypto.randomBytes(bytes).toString("hex"));
205
- 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+" }))));
206
- };
207
- const makeTempFile = makeTempFileFactory("makeTempFile");
371
+ const makeDirectory = makeTempDirectoryFactory(method)
372
+ const open = openFactory(method)
373
+ const randomHexString = (bytes) =>
374
+ Effect.sync(() => NCrypto.randomBytes(bytes).toString("hex"))
375
+ return (options) =>
376
+ Function.pipe(
377
+ Effect.zip(makeDirectory(options), randomHexString(6)),
378
+ Effect.map(([directory, random]) => NPath.join(directory, random + (options?.suffix ?? ""))),
379
+ Effect.tap((path) => Effect.scoped(open(path, { flag: "w+" }))),
380
+ )
381
+ }
382
+ const makeTempFile = makeTempFileFactory("makeTempFile")
383
+
208
384
  const makeTempFileScoped = (() => {
209
- const makeFile = makeTempFileFactory("makeTempFileScoped");
210
- const removeDirectory = removeFactory("makeTempFileScoped");
211
- return (options) => Effect.acquireRelease(makeFile(options), (file) => Effect.orDie(removeDirectory(NPath.dirname(file), { recursive: true })));
212
- })();
213
- const readDirectory = (path, options) => Effect.tryPromise({
385
+ const makeFile = makeTempFileFactory("makeTempFileScoped")
386
+ const removeDirectory = removeFactory("makeTempFileScoped")
387
+ return (options) =>
388
+ Effect.acquireRelease(makeFile(options), (file) =>
389
+ Effect.orDie(removeDirectory(NPath.dirname(file), { recursive: true })),
390
+ )
391
+ })()
392
+
393
+ const readDirectory = (path, options) =>
394
+ Effect.tryPromise({
214
395
  try: () => NFS.promises.readdir(path, options),
215
396
  catch: (err) => handleErrnoException("FileSystem", "readDirectory")(err, [path]),
216
- });
217
- const readFile = (path) => Effect.async((resume, signal) => {
397
+ })
398
+
399
+ const readFile = (path) =>
400
+ Effect.async((resume, signal) => {
218
401
  try {
219
- NFS.readFile(path, { signal }, (err, data) => {
220
- if (err) {
221
- resume(Effect.fail(handleErrnoException("FileSystem", "readFile")(err, [path])));
222
- }
223
- else {
224
- resume(Effect.succeed(data));
225
- }
226
- });
227
- }
228
- catch (err) {
229
- resume(Effect.fail(handleBadArgument("readFile")(err)));
402
+ NFS.readFile(path, { signal }, (err, data) => {
403
+ if (err) {
404
+ resume(Effect.fail(handleErrnoException("FileSystem", "readFile")(err, [path])))
405
+ } else {
406
+ resume(Effect.succeed(data))
407
+ }
408
+ })
409
+ } catch (err) {
410
+ resume(Effect.fail(handleBadArgument("readFile")(err)))
230
411
  }
231
- });
412
+ })
413
+
232
414
  const readLink = (() => {
233
- const nodeReadLink = Effectify.effectify(NFS.readlink, handleErrnoException("FileSystem", "readLink"), handleBadArgument("readLink"));
234
- return (path) => nodeReadLink(path);
235
- })();
415
+ const nodeReadLink = Effectify.effectify(
416
+ NFS.readlink,
417
+ handleErrnoException("FileSystem", "readLink"),
418
+ handleBadArgument("readLink"),
419
+ )
420
+ return (path) => nodeReadLink(path)
421
+ })()
422
+
236
423
  const realPath = (() => {
237
- const nodeRealPath = Effectify.effectify(NFS.realpath, handleErrnoException("FileSystem", "realPath"), handleBadArgument("realPath"));
238
- return (path) => nodeRealPath(path);
239
- })();
424
+ const nodeRealPath = Effectify.effectify(
425
+ NFS.realpath,
426
+ handleErrnoException("FileSystem", "realPath"),
427
+ handleBadArgument("realPath"),
428
+ )
429
+ return (path) => nodeRealPath(path)
430
+ })()
431
+
240
432
  const rename = (() => {
241
- const nodeRename = Effectify.effectify(NFS.rename, handleErrnoException("FileSystem", "rename"), handleBadArgument("rename"));
242
- return (oldPath, newPath) => nodeRename(oldPath, newPath);
243
- })();
433
+ const nodeRename = Effectify.effectify(
434
+ NFS.rename,
435
+ handleErrnoException("FileSystem", "rename"),
436
+ handleBadArgument("rename"),
437
+ )
438
+ return (oldPath, newPath) => nodeRename(oldPath, newPath)
439
+ })()
440
+
244
441
  const makeFileInfo = (stat) => ({
245
- type: stat.isFile()
246
- ? "File"
247
- : stat.isDirectory()
248
- ? "Directory"
249
- : stat.isSymbolicLink()
250
- ? "SymbolicLink"
251
- : stat.isBlockDevice()
252
- ? "BlockDevice"
253
- : stat.isCharacterDevice()
254
- ? "CharacterDevice"
255
- : stat.isFIFO()
256
- ? "FIFO"
257
- : stat.isSocket()
258
- ? "Socket"
259
- : "Unknown",
260
- mtime: Option.fromNullable(stat.mtime),
261
- atime: Option.fromNullable(stat.atime),
262
- birthtime: Option.fromNullable(stat.birthtime),
263
- dev: stat.dev,
264
- rdev: Option.fromNullable(stat.rdev),
265
- ino: Option.fromNullable(stat.ino),
266
- mode: stat.mode,
267
- nlink: Option.fromNullable(stat.nlink),
268
- uid: Option.fromNullable(stat.uid),
269
- gid: Option.fromNullable(stat.gid),
270
- size: FileSystem.Size(stat.size),
271
- blksize: Option.map(Option.fromNullable(stat.blksize), FileSystem.Size),
272
- blocks: Option.fromNullable(stat.blocks),
273
- });
442
+ type: stat.isFile()
443
+ ? "File"
444
+ : stat.isDirectory()
445
+ ? "Directory"
446
+ : stat.isSymbolicLink()
447
+ ? "SymbolicLink"
448
+ : stat.isBlockDevice()
449
+ ? "BlockDevice"
450
+ : stat.isCharacterDevice()
451
+ ? "CharacterDevice"
452
+ : stat.isFIFO()
453
+ ? "FIFO"
454
+ : stat.isSocket()
455
+ ? "Socket"
456
+ : "Unknown",
457
+ mtime: Option.fromNullable(stat.mtime),
458
+ atime: Option.fromNullable(stat.atime),
459
+ birthtime: Option.fromNullable(stat.birthtime),
460
+ dev: stat.dev,
461
+ rdev: Option.fromNullable(stat.rdev),
462
+ ino: Option.fromNullable(stat.ino),
463
+ mode: stat.mode,
464
+ nlink: Option.fromNullable(stat.nlink),
465
+ uid: Option.fromNullable(stat.uid),
466
+ gid: Option.fromNullable(stat.gid),
467
+ size: FileSystem.Size(stat.size),
468
+ blksize: Option.map(Option.fromNullable(stat.blksize), FileSystem.Size),
469
+ blocks: Option.fromNullable(stat.blocks),
470
+ })
274
471
  const stat = (() => {
275
- const nodeStat = Effectify.effectify(NFS.stat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
276
- return (path) => Effect.map(nodeStat(path), makeFileInfo);
277
- })();
472
+ const nodeStat = Effectify.effectify(
473
+ NFS.stat,
474
+ handleErrnoException("FileSystem", "stat"),
475
+ handleBadArgument("stat"),
476
+ )
477
+ return (path) => Effect.map(nodeStat(path), makeFileInfo)
478
+ })()
479
+
278
480
  const symlink = (() => {
279
- const nodeSymlink = Effectify.effectify(NFS.symlink, handleErrnoException("FileSystem", "symlink"), handleBadArgument("symlink"));
280
- return (target, path) => nodeSymlink(target, path);
281
- })();
481
+ const nodeSymlink = Effectify.effectify(
482
+ NFS.symlink,
483
+ handleErrnoException("FileSystem", "symlink"),
484
+ handleBadArgument("symlink"),
485
+ )
486
+ return (target, path) => nodeSymlink(target, path)
487
+ })()
488
+
282
489
  const truncate = (() => {
283
- const nodeTruncate = Effectify.effectify(NFS.truncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
284
- return (path, length) => nodeTruncate(path, length !== undefined ? Number(length) : undefined);
285
- })();
490
+ const nodeTruncate = Effectify.effectify(
491
+ NFS.truncate,
492
+ handleErrnoException("FileSystem", "truncate"),
493
+ handleBadArgument("truncate"),
494
+ )
495
+ return (path, length) =>
496
+ nodeTruncate(path, length !== undefined ? Number(length) : undefined)
497
+ })()
498
+
286
499
  const utimes = (() => {
287
- const nodeUtimes = Effectify.effectify(NFS.utimes, handleErrnoException("FileSystem", "utime"), handleBadArgument("utime"));
288
- return (path, atime, mtime) => nodeUtimes(path, atime, mtime);
289
- })();
290
- const watchNode = (path, options) => Stream.asyncScoped((emit) => Effect.acquireRelease(Effect.sync(() => {
291
- const watcher = NFS.watch(path, { recursive: options?.recursive }, (event, path) => {
292
- if (!path)
293
- return;
294
- switch (event) {
500
+ const nodeUtimes = Effectify.effectify(
501
+ NFS.utimes,
502
+ handleErrnoException("FileSystem", "utime"),
503
+ handleBadArgument("utime"),
504
+ )
505
+ return (path, atime, mtime) =>
506
+ nodeUtimes(path, atime, mtime)
507
+ })()
508
+
509
+ const watchNode = (path, options) =>
510
+ Stream.asyncScoped((emit) =>
511
+ Effect.acquireRelease(
512
+ Effect.sync(() => {
513
+ const watcher = NFS.watch(path, { recursive: options?.recursive }, (event, path) => {
514
+ if (!path) return
515
+ switch (event) {
295
516
  case "rename": {
296
- emit.fromEffect(Effect.matchEffect(stat(path), {
297
- onSuccess: (_) => Effect.succeed(FileSystem.WatchEventCreate({ path })),
298
- onFailure: (err) => err._tag === "SystemError" && err.reason === "NotFound"
299
- ? Effect.succeed(FileSystem.WatchEventRemove({ path }))
300
- : Effect.fail(err),
301
- }));
302
- return;
517
+ emit.fromEffect(
518
+ Effect.matchEffect(stat(path), {
519
+ onSuccess: (_) => Effect.succeed(FileSystem.WatchEventCreate({ path })),
520
+ onFailure: (err) =>
521
+ err._tag === "SystemError" && err.reason === "NotFound"
522
+ ? Effect.succeed(FileSystem.WatchEventRemove({ path }))
523
+ : Effect.fail(err),
524
+ }),
525
+ )
526
+ return
303
527
  }
304
528
  case "change": {
305
- emit.single(FileSystem.WatchEventUpdate({ path }));
306
- return;
529
+ emit.single(FileSystem.WatchEventUpdate({ path }))
530
+ return
307
531
  }
308
- }
309
- });
310
- watcher.on("error", (error) => {
311
- emit.fail(new PlatformError.SystemError({
312
- module: "FileSystem",
313
- reason: "Unknown",
314
- method: "watch",
315
- pathOrDescriptor: path,
316
- cause: error,
317
- }));
318
- });
319
- watcher.on("close", () => {
320
- emit.end();
321
- });
322
- return watcher;
323
- }), (watcher) => Effect.sync(() => watcher.close())));
324
- 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);
325
- const writeFile = (path, data, options) => Effect.async((resume, signal) => {
532
+ }
533
+ })
534
+ watcher.on("error", (error) => {
535
+ emit.fail(
536
+ new PlatformError.SystemError({
537
+ module: "FileSystem",
538
+ reason: "Unknown",
539
+ method: "watch",
540
+ pathOrDescriptor: path,
541
+ cause: error,
542
+ }),
543
+ )
544
+ })
545
+ watcher.on("close", () => {
546
+ emit.end()
547
+ })
548
+ return watcher
549
+ }),
550
+ (watcher) => Effect.sync(() => watcher.close()),
551
+ ),
552
+ )
553
+
554
+ const watch = (
555
+ backend,
556
+ path,
557
+ options,
558
+ ) =>
559
+ stat(path).pipe(
560
+ Effect.map((stat) =>
561
+ backend.pipe(
562
+ Option.flatMap((_) => _.register(path, stat, options)),
563
+ Option.getOrElse(() => watchNode(path, options)),
564
+ ),
565
+ ),
566
+ Stream.unwrap,
567
+ )
568
+
569
+ const writeFile = (path, data, options) =>
570
+ Effect.async((resume, signal) => {
326
571
  try {
327
- NFS.writeFile(path, data, {
328
- signal,
329
- flag: options?.flag,
330
- mode: options?.mode,
331
- }, (err) => {
332
- if (err) {
333
- resume(Effect.fail(handleErrnoException("FileSystem", "writeFile")(err, [path])));
334
- }
335
- else {
336
- resume(Effect.void);
337
- }
338
- });
339
- }
340
- catch (err) {
341
- resume(Effect.fail(handleBadArgument("writeFile")(err)));
572
+ NFS.writeFile(
573
+ path,
574
+ data,
575
+ {
576
+ signal,
577
+ flag: options?.flag,
578
+ mode: options?.mode,
579
+ },
580
+ (err) => {
581
+ if (err) {
582
+ resume(Effect.fail(handleErrnoException("FileSystem", "writeFile")(err, [path])))
583
+ } else {
584
+ resume(Effect.void)
585
+ }
586
+ },
587
+ )
588
+ } catch (err) {
589
+ resume(Effect.fail(handleBadArgument("writeFile")(err)))
342
590
  }
343
- });
344
- const make = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend) => FileSystem.make({
591
+ })
592
+
593
+ const make = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend) =>
594
+ FileSystem.make({
345
595
  access,
346
596
  chmod,
347
597
  chown,
@@ -365,46 +615,61 @@ const make = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend)
365
615
  truncate,
366
616
  utimes,
367
617
  watch(path, options) {
368
- return watch(backend, path, options);
618
+ return watch(backend, path, options)
369
619
  },
370
620
  writeFile,
371
- }));
372
- export const layer = Layer.effect(FileSystem.FileSystem, make);
373
- export { PlatformError as Error };
621
+ }),
622
+ )
623
+
624
+ export const layer = Layer.effect(FileSystem.FileSystem, make)
625
+
626
+ export { PlatformError as Error }
627
+
374
628
  export function handleErrnoException(module, method) {
375
- return function (err, [path]) {
376
- let reason = "Unknown";
377
- switch (err.code) {
378
- case "ENOENT":
379
- reason = "NotFound";
380
- break;
381
- case "EACCES":
382
- reason = "PermissionDenied";
383
- break;
384
- case "EEXIST":
385
- reason = "AlreadyExists";
386
- break;
387
- case "EISDIR":
388
- reason = "BadResource";
389
- break;
390
- case "ENOTDIR":
391
- reason = "BadResource";
392
- break;
393
- case "EBUSY":
394
- reason = "Busy";
395
- break;
396
- case "ELOOP":
397
- reason = "BadResource";
398
- break;
399
- }
400
- return new PlatformError.SystemError({
401
- reason,
402
- module,
403
- method,
404
- pathOrDescriptor: path,
405
- syscall: err.syscall,
406
- description: err.message,
407
- cause: err,
408
- });
409
- };
629
+ return function (
630
+ err,
631
+ [path],
632
+ ) {
633
+ let reason = "Unknown"
634
+
635
+ switch (err.code) {
636
+ case "ENOENT":
637
+ reason = "NotFound"
638
+ break
639
+
640
+ case "EACCES":
641
+ reason = "PermissionDenied"
642
+ break
643
+
644
+ case "EEXIST":
645
+ reason = "AlreadyExists"
646
+ break
647
+
648
+ case "EISDIR":
649
+ reason = "BadResource"
650
+ break
651
+
652
+ case "ENOTDIR":
653
+ reason = "BadResource"
654
+ break
655
+
656
+ case "EBUSY":
657
+ reason = "Busy"
658
+ break
659
+
660
+ case "ELOOP":
661
+ reason = "BadResource"
662
+ break
663
+ }
664
+
665
+ return new PlatformError.SystemError({
666
+ reason,
667
+ module,
668
+ method,
669
+ pathOrDescriptor: path,
670
+ syscall: err.syscall,
671
+ description: err.message,
672
+ cause: err,
673
+ })
674
+ }
410
675
  }