effect-start 0.23.0 → 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.
- package/dist/ChildProcess.js +32 -20
- package/dist/Commander.js +377 -293
- package/dist/ContentNegotiation.js +424 -318
- package/dist/Cookies.js +340 -271
- package/dist/Development.js +85 -49
- package/dist/Effectify.js +22 -14
- package/dist/Entity.js +260 -195
- package/dist/Fetch.js +192 -0
- package/dist/FilePathPattern.js +88 -77
- package/dist/FileRouter.js +192 -136
- package/dist/FileRouterCodegen.js +262 -191
- package/dist/FileSystem.js +126 -64
- package/dist/Http.js +96 -77
- package/dist/PathPattern.js +311 -273
- package/dist/PlatformError.js +36 -21
- package/dist/PlatformRuntime.js +65 -40
- package/dist/Route.js +122 -79
- package/dist/RouteBody.js +83 -58
- package/dist/RouteError.js +46 -25
- package/dist/RouteHook.js +58 -34
- package/dist/RouteHttp.js +346 -237
- package/dist/RouteHttpTracer.js +86 -58
- package/dist/RouteMount.js +81 -58
- package/dist/RouteSchema.js +253 -170
- package/dist/RouteSse.js +87 -72
- package/dist/RouteTree.js +99 -73
- package/dist/RouteTrie.js +160 -133
- package/dist/SchemaExtra.js +87 -62
- package/dist/Socket.js +32 -21
- package/dist/SqlIntrospect.js +317 -268
- package/dist/Start.js +55 -25
- package/dist/StartApp.js +3 -21
- package/dist/StreamExtra.js +109 -74
- package/dist/System.js +37 -21
- package/dist/TuplePathPattern.js +64 -58
- package/dist/Unique.js +159 -120
- package/dist/Values.js +48 -32
- package/dist/bun/BunBundle.js +158 -109
- package/dist/bun/BunChildProcessSpawner.js +121 -82
- package/dist/bun/BunImportTrackerPlugin.js +85 -63
- package/dist/bun/BunRoute.js +135 -99
- package/dist/bun/BunRuntime.js +39 -29
- package/dist/bun/BunServer.js +268 -140
- package/dist/bun/BunVirtualFilesPlugin.js +47 -33
- package/dist/bun/_BunEnhancedResolve.js +107 -82
- package/dist/bun/index.js +5 -5
- package/dist/bundler/Bundle.js +82 -38
- package/dist/bundler/BundleFiles.js +140 -82
- package/dist/bundler/BundleRoute.js +49 -38
- package/dist/client/Overlay.js +29 -28
- package/dist/client/ScrollState.js +94 -82
- package/dist/client/index.js +79 -61
- package/dist/console/Console.js +40 -24
- package/dist/console/ConsoleErrors.js +189 -178
- package/dist/console/ConsoleLogger.js +52 -43
- package/dist/console/ConsoleMetrics.js +69 -58
- package/dist/console/ConsoleProcess.js +57 -47
- package/dist/console/ConsoleStore.js +56 -45
- package/dist/console/ConsoleTracer.js +101 -88
- package/dist/console/Simulation.js +714 -563
- package/dist/console/index.js +3 -3
- package/dist/console/routes/tree.js +29 -28
- package/dist/datastar/actions/fetch.js +514 -381
- package/dist/datastar/actions/peek.js +12 -12
- package/dist/datastar/actions/setAll.js +18 -11
- package/dist/datastar/actions/toggleAll.js +18 -11
- package/dist/datastar/attributes/attr.js +48 -47
- package/dist/datastar/attributes/bind.js +186 -167
- package/dist/datastar/attributes/class.js +51 -44
- package/dist/datastar/attributes/computed.js +23 -24
- package/dist/datastar/attributes/effect.js +9 -8
- package/dist/datastar/attributes/indicator.js +32 -29
- package/dist/datastar/attributes/init.js +26 -25
- package/dist/datastar/attributes/jsonSignals.js +32 -29
- package/dist/datastar/attributes/on.js +76 -73
- package/dist/datastar/attributes/onIntersect.js +51 -51
- package/dist/datastar/attributes/onInterval.js +30 -29
- package/dist/datastar/attributes/onSignalPatch.js +49 -40
- package/dist/datastar/attributes/ref.js +10 -9
- package/dist/datastar/attributes/show.js +31 -30
- package/dist/datastar/attributes/signals.js +17 -16
- package/dist/datastar/attributes/style.js +56 -49
- package/dist/datastar/attributes/text.js +28 -25
- package/dist/datastar/engine.js +1079 -933
- package/dist/datastar/index.js +25 -24
- package/dist/datastar/utils.js +203 -155
- package/dist/datastar/watchers/patchElements.js +459 -372
- package/dist/datastar/watchers/patchSignals.js +13 -13
- package/dist/experimental/EncryptedCookies.js +305 -189
- package/dist/experimental/index.js +1 -1
- package/dist/hyper/Hyper.js +22 -17
- package/dist/hyper/HyperHtml.js +138 -123
- package/dist/hyper/HyperNode.js +11 -9
- package/dist/hyper/HyperRoute.js +41 -28
- package/dist/hyper/html.js +27 -27
- package/dist/hyper/index.js +5 -5
- package/dist/hyper/jsx-runtime.js +11 -5
- package/dist/index.js +8 -8
- package/dist/node/NodeFileSystem.js +606 -341
- package/dist/node/NodeUtils.js +21 -18
- package/dist/sql/Sql.js +8 -0
- package/dist/sql/bun/index.js +134 -67
- package/dist/sql/index.js +1 -0
- package/dist/sql/libsql/index.js +156 -0
- package/dist/sql/mssql/docker.js +103 -60
- package/dist/sql/mssql/index.js +182 -101
- package/dist/testing/TestLogger.js +39 -29
- package/dist/testing/index.js +2 -2
- package/dist/testing/utils.js +45 -23
- package/dist/x/cloudflare/CloudflareTunnel.js +61 -28
- package/dist/x/cloudflare/index.js +1 -1
- package/dist/x/tailscale/TailscaleTunnel.js +86 -60
- package/dist/x/tailscale/index.js +1 -1
- package/dist/x/tailwind/TailwindPlugin.js +280 -205
- package/dist/x/tailwind/compile.js +185 -129
- package/dist/x/tailwind/plugin.js +13 -11
- package/package.json +1 -1
- package/src/Development.ts +3 -1
- package/src/Entity.ts +17 -0
- package/src/Fetch.ts +271 -0
- package/src/SqlIntrospect.ts +64 -70
- package/src/Start.ts +24 -22
- package/src/StartApp.ts +11 -0
- package/src/bun/BunServer.ts +89 -16
- package/src/hyper/HyperHtml.ts +0 -1
- package/src/sql/bun/index.ts +1 -1
- package/src/sql/index.ts +1 -0
- package/src/sql/libsql/index.ts +173 -0
- package/src/sql/libsql/libsql.d.ts +39 -0
- package/src/sql/mssql/index.ts +1 -1
- package/src/x/tailscale/TailscaleTunnel.ts +7 -5
- package/dist/BlobStore.d.ts +0 -80
- package/dist/BlobStore.js +0 -19
- package/dist/ChildProcess.d.ts +0 -60
- package/dist/Commander.d.ts +0 -100
- package/dist/ContentNegotiation.d.ts +0 -12
- package/dist/Cookies.d.ts +0 -47
- package/dist/Development.d.ts +0 -39
- package/dist/Effectify.d.ts +0 -209
- package/dist/Entity.d.ts +0 -47
- package/dist/FilePathPattern.d.ts +0 -29
- package/dist/FileRouter.d.ts +0 -56
- package/dist/FileRouterCodegen.d.ts +0 -18
- package/dist/FileRouterPattern.d.ts +0 -9
- package/dist/FileRouterPattern.js +0 -35
- package/dist/FileSystem.d.ts +0 -158
- package/dist/Http.d.ts +0 -37
- package/dist/HttpAppExtra.d.ts +0 -7
- package/dist/HttpAppExtra.js +0 -320
- package/dist/HttpUtils.d.ts +0 -3
- package/dist/HttpUtils.js +0 -11
- package/dist/PathPattern.d.ts +0 -134
- package/dist/PlatformError.d.ts +0 -38
- package/dist/PlatformRuntime.d.ts +0 -27
- package/dist/Route.d.ts +0 -97
- package/dist/RouteBody.d.ts +0 -47
- package/dist/RouteError.d.ts +0 -98
- package/dist/RouteHook.d.ts +0 -12
- package/dist/RouteHttp.d.ts +0 -21
- package/dist/RouteHttpTracer.d.ts +0 -10
- package/dist/RouteMount.d.ts +0 -86
- package/dist/RouteSchema.d.ts +0 -86
- package/dist/RouteSse.d.ts +0 -21
- package/dist/RouteTree.d.ts +0 -57
- package/dist/RouteTrie.d.ts +0 -20
- package/dist/RouterPattern.d.ts +0 -118
- package/dist/RouterPattern.js +0 -269
- package/dist/SchemaExtra.d.ts +0 -7
- package/dist/Socket.d.ts +0 -27
- package/dist/Sql.d.ts +0 -34
- package/dist/Sql.js +0 -5
- package/dist/SqlIntrospect.d.ts +0 -91
- package/dist/Start.d.ts +0 -44
- package/dist/StartApp.d.ts +0 -19
- package/dist/StreamExtra.d.ts +0 -28
- package/dist/System.d.ts +0 -7
- package/dist/TuplePathPattern.d.ts +0 -9
- package/dist/Unique.d.ts +0 -50
- package/dist/Values.d.ts +0 -27
- package/dist/bun/BunBlobStoreDisk.d.ts +0 -6
- package/dist/bun/BunBlobStoreDisk.js +0 -116
- package/dist/bun/BunBlobStoreS3.d.ts +0 -11
- package/dist/bun/BunBlobStoreS3.js +0 -89
- package/dist/bun/BunBlobWatcherDisk.d.ts +0 -6
- package/dist/bun/BunBlobWatcherDisk.js +0 -60
- package/dist/bun/BunBlobWatcherQueue.d.ts +0 -6
- package/dist/bun/BunBlobWatcherQueue.js +0 -17
- package/dist/bun/BunBundle.d.ts +0 -11
- package/dist/bun/BunChildProcessSpawner.d.ts +0 -3
- package/dist/bun/BunHttpServer.d.ts +0 -44
- package/dist/bun/BunHttpServer.js +0 -186
- package/dist/bun/BunHttpServer_web.d.ts +0 -60
- package/dist/bun/BunHttpServer_web.js +0 -252
- package/dist/bun/BunImportTrackerPlugin.d.ts +0 -13
- package/dist/bun/BunPlatformHttpServer.d.ts +0 -10
- package/dist/bun/BunPlatformHttpServer.js +0 -53
- package/dist/bun/BunRoute.d.ts +0 -48
- package/dist/bun/BunRuntime.d.ts +0 -2
- package/dist/bun/BunServer.d.ts +0 -40
- package/dist/bun/BunServerRequest.d.ts +0 -60
- package/dist/bun/BunServerRequest.js +0 -252
- package/dist/bun/BunSql.d.ts +0 -4
- package/dist/bun/BunSql.js +0 -81
- package/dist/bun/BunVirtualFilesPlugin.d.ts +0 -4
- package/dist/bun/_BunEnhancedResolve.d.ts +0 -45
- package/dist/bun/index.d.ts +0 -5
- package/dist/bundler/Bundle.d.ts +0 -61
- package/dist/bundler/BundleFiles.d.ts +0 -13
- package/dist/bundler/BundleHttp.d.ts +0 -45
- package/dist/bundler/BundleHttp.js +0 -176
- package/dist/bundler/BundleRoute.d.ts +0 -27
- package/dist/client/Overlay.d.ts +0 -2
- package/dist/client/ScrollState.d.ts +0 -6
- package/dist/client/index.d.ts +0 -6
- package/dist/console/Console.d.ts +0 -6
- package/dist/console/ConsoleErrors.d.ts +0 -3
- package/dist/console/ConsoleLogger.d.ts +0 -3
- package/dist/console/ConsoleMetrics.d.ts +0 -3
- package/dist/console/ConsoleProcess.d.ts +0 -3
- package/dist/console/ConsoleStore.d.ts +0 -144
- package/dist/console/ConsoleTracer.d.ts +0 -3
- package/dist/console/Simulation.d.ts +0 -2
- package/dist/console/index.d.ts +0 -3
- package/dist/console/routes/errors/route.d.ts +0 -10
- package/dist/console/routes/errors/route.js +0 -47
- package/dist/console/routes/fiberDetail.d.ts +0 -16
- package/dist/console/routes/fiberDetail.js +0 -38
- package/dist/console/routes/fibers/route.d.ts +0 -10
- package/dist/console/routes/fibers/route.js +0 -19
- package/dist/console/routes/git/route.d.ts +0 -11
- package/dist/console/routes/git/route.js +0 -33
- package/dist/console/routes/layout.d.ts +0 -9
- package/dist/console/routes/layout.js +0 -3
- package/dist/console/routes/logs/route.d.ts +0 -10
- package/dist/console/routes/logs/route.js +0 -32
- package/dist/console/routes/metrics/route.d.ts +0 -10
- package/dist/console/routes/metrics/route.js +0 -17
- package/dist/console/routes/route.d.ts +0 -6
- package/dist/console/routes/route.js +0 -5
- package/dist/console/routes/routes/route.d.ts +0 -6
- package/dist/console/routes/routes/route.js +0 -20
- package/dist/console/routes/services/route.d.ts +0 -6
- package/dist/console/routes/services/route.js +0 -12
- package/dist/console/routes/system/route.d.ts +0 -10
- package/dist/console/routes/system/route.js +0 -18
- package/dist/console/routes/traceDetail.d.ts +0 -16
- package/dist/console/routes/traceDetail.js +0 -14
- package/dist/console/routes/traces/route.d.ts +0 -10
- package/dist/console/routes/traces/route.js +0 -39
- package/dist/console/routes/tree.d.ts +0 -153
- package/dist/console/ui/Errors.d.ts +0 -4
- package/dist/console/ui/Errors.js +0 -15
- package/dist/console/ui/Fibers.d.ts +0 -24
- package/dist/console/ui/Fibers.js +0 -121
- package/dist/console/ui/Git.d.ts +0 -20
- package/dist/console/ui/Git.js +0 -95
- package/dist/console/ui/Logs.d.ts +0 -4
- package/dist/console/ui/Logs.js +0 -25
- package/dist/console/ui/Metrics.d.ts +0 -4
- package/dist/console/ui/Metrics.js +0 -26
- package/dist/console/ui/Routes.d.ts +0 -8
- package/dist/console/ui/Routes.js +0 -70
- package/dist/console/ui/Services.d.ts +0 -10
- package/dist/console/ui/Services.js +0 -246
- package/dist/console/ui/Shell.d.ts +0 -10
- package/dist/console/ui/Shell.js +0 -7
- package/dist/console/ui/System.d.ts +0 -4
- package/dist/console/ui/System.js +0 -35
- package/dist/console/ui/Traces.d.ts +0 -12
- package/dist/console/ui/Traces.js +0 -179
- package/dist/datastar/actions/fetch.d.ts +0 -30
- package/dist/datastar/actions/peek.d.ts +0 -1
- package/dist/datastar/actions/setAll.d.ts +0 -1
- package/dist/datastar/actions/toggleAll.d.ts +0 -1
- package/dist/datastar/attributes/attr.d.ts +0 -1
- package/dist/datastar/attributes/bind.d.ts +0 -1
- package/dist/datastar/attributes/class.d.ts +0 -1
- package/dist/datastar/attributes/computed.d.ts +0 -1
- package/dist/datastar/attributes/effect.d.ts +0 -1
- package/dist/datastar/attributes/indicator.d.ts +0 -1
- package/dist/datastar/attributes/init.d.ts +0 -1
- package/dist/datastar/attributes/jsonSignals.d.ts +0 -1
- package/dist/datastar/attributes/on.d.ts +0 -1
- package/dist/datastar/attributes/onIntersect.d.ts +0 -1
- package/dist/datastar/attributes/onInterval.d.ts +0 -1
- package/dist/datastar/attributes/onSignalPatch.d.ts +0 -1
- package/dist/datastar/attributes/ref.d.ts +0 -1
- package/dist/datastar/attributes/show.d.ts +0 -1
- package/dist/datastar/attributes/signals.d.ts +0 -1
- package/dist/datastar/attributes/style.d.ts +0 -1
- package/dist/datastar/attributes/text.d.ts +0 -1
- package/dist/datastar/engine.d.ts +0 -162
- package/dist/datastar/happydom.d.ts +0 -1
- package/dist/datastar/happydom.js +0 -8
- package/dist/datastar/index.d.ts +0 -24
- package/dist/datastar/load.d.ts +0 -24
- package/dist/datastar/load.js +0 -24
- package/dist/datastar/utils.d.ts +0 -51
- package/dist/datastar/watchers/patchElements.d.ts +0 -1
- package/dist/datastar/watchers/patchSignals.d.ts +0 -1
- package/dist/experimental/EncryptedCookies.d.ts +0 -48
- package/dist/experimental/SseHttpResponse.d.ts +0 -7
- package/dist/experimental/SseHttpResponse.js +0 -28
- package/dist/experimental/index.d.ts +0 -1
- package/dist/hyper/Hyper.d.ts +0 -25
- package/dist/hyper/HyperHtml.d.ts +0 -23
- package/dist/hyper/HyperHtml.test.d.ts +0 -1
- package/dist/hyper/HyperHtml.test.js +0 -197
- package/dist/hyper/HyperNode.d.ts +0 -14
- package/dist/hyper/HyperRoute.d.ts +0 -8
- package/dist/hyper/HyperRoute.test.d.ts +0 -1
- package/dist/hyper/HyperRoute.test.js +0 -83
- package/dist/hyper/html.d.ts +0 -11
- package/dist/hyper/index.d.ts +0 -6
- package/dist/hyper/jsx-runtime.d.ts +0 -7
- package/dist/index.d.ts +0 -8
- package/dist/inference_check.d.ts +0 -1
- package/dist/inference_check.js +0 -15
- package/dist/lint/plugin.d.ts +0 -86
- package/dist/lint/plugin.js +0 -341
- package/dist/middlewares/BasicAuthMiddleware.d.ts +0 -8
- package/dist/middlewares/BasicAuthMiddleware.js +0 -22
- package/dist/middlewares/index.d.ts +0 -1
- package/dist/middlewares/index.js +0 -1
- package/dist/node/Effectify.d.ts +0 -209
- package/dist/node/Effectify.js +0 -19
- package/dist/node/FileSystem.d.ts +0 -7
- package/dist/node/FileSystem.js +0 -420
- package/dist/node/NodeFileSystem.d.ts +0 -7
- package/dist/node/NodeUtils.d.ts +0 -2
- package/dist/node/PlatformError.d.ts +0 -46
- package/dist/node/PlatformError.js +0 -43
- package/dist/node/Utils.d.ts +0 -1
- package/dist/node/Utils.js +0 -19
- package/dist/repro_fail.d.ts +0 -1
- package/dist/repro_fail.js +0 -14
- package/dist/sql/bun/index.d.ts +0 -3
- package/dist/sql/mssql/docker.d.ts +0 -2
- package/dist/sql/mssql/index.d.ts +0 -21
- package/dist/testing/TestHttpClient.d.ts +0 -13
- package/dist/testing/TestHttpClient.js +0 -68
- package/dist/testing/TestLogger.d.ts +0 -13
- package/dist/testing/index.d.ts +0 -2
- package/dist/testing/utils.d.ts +0 -9
- package/dist/x/cloudflare/CloudflareTunnel.d.ts +0 -10
- package/dist/x/cloudflare/index.d.ts +0 -1
- package/dist/x/datastar/Datastar.d.ts +0 -6
- package/dist/x/datastar/Datastar.js +0 -47
- package/dist/x/datastar/index.d.ts +0 -1
- package/dist/x/datastar/index.js +0 -1
- package/dist/x/tailscale/TailscaleTunnel.d.ts +0 -15
- package/dist/x/tailscale/index.d.ts +0 -1
- package/dist/x/tailwind/TailwindPlugin.d.ts +0 -23
- package/dist/x/tailwind/compile.d.ts +0 -19
- package/dist/x/tailwind/plugin.d.ts +0 -2
- /package/src/{Sql.ts → sql/Sql.ts} +0 -0
|
@@ -1,347 +1,597 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
11
|
-
import * as
|
|
12
|
-
import * as
|
|
13
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
41
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
269
|
+
}),
|
|
270
|
+
(bytesRead) => {
|
|
145
271
|
if (bytesRead === 0) {
|
|
146
|
-
|
|
272
|
+
return Option.none()
|
|
147
273
|
}
|
|
148
|
-
|
|
274
|
+
|
|
275
|
+
this.position = this.position + BigInt(bytesRead)
|
|
149
276
|
if (bytesRead === sizeNumber) {
|
|
150
|
-
|
|
277
|
+
return Option.some(buffer)
|
|
151
278
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
200
|
-
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return (fd, append) =>
|
|
367
|
+
new FileImpl(fd, append)
|
|
368
|
+
})()
|
|
369
|
+
|
|
201
370
|
const makeTempFileFactory = (method) => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
397
|
+
})
|
|
398
|
+
|
|
399
|
+
const readFile = (path) =>
|
|
400
|
+
Effect.async((resume, signal) => {
|
|
218
401
|
try {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
234
|
-
|
|
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
|
-
|
|
238
|
-
|
|
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
|
-
|
|
242
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
276
|
-
|
|
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
|
-
|
|
280
|
-
|
|
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
|
-
|
|
284
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
|
|
306
|
-
|
|
529
|
+
emit.single(FileSystem.WatchEventUpdate({ path }))
|
|
530
|
+
return
|
|
307
531
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
})
|
|
324
|
-
|
|
325
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
|
|
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
|
-
|
|
618
|
+
return watch(backend, path, options)
|
|
369
619
|
},
|
|
370
620
|
writeFile,
|
|
371
|
-
})
|
|
372
|
-
|
|
373
|
-
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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
|
}
|