@effect/platform-bun 0.87.0 → 4.0.0-beta.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/BunChildProcessSpawner.d.ts +7 -0
- package/dist/BunChildProcessSpawner.d.ts.map +1 -0
- package/dist/BunChildProcessSpawner.js +7 -0
- package/dist/BunChildProcessSpawner.js.map +1 -0
- package/dist/BunClusterHttp.d.ts +45 -0
- package/dist/BunClusterHttp.d.ts.map +1 -0
- package/dist/BunClusterHttp.js +48 -0
- package/dist/BunClusterHttp.js.map +1 -0
- package/dist/BunClusterSocket.d.ts +46 -0
- package/dist/BunClusterSocket.d.ts.map +1 -0
- package/dist/BunClusterSocket.js +60 -0
- package/dist/BunClusterSocket.js.map +1 -0
- package/dist/BunFileSystem.d.ts +8 -0
- package/dist/BunFileSystem.d.ts.map +1 -0
- package/dist/BunFileSystem.js.map +1 -0
- package/dist/BunHttpClient.d.ts +9 -0
- package/dist/BunHttpClient.d.ts.map +1 -0
- package/dist/BunHttpClient.js +9 -0
- package/dist/BunHttpClient.js.map +1 -0
- package/dist/BunHttpPlatform.d.ts +8 -0
- package/dist/BunHttpPlatform.d.ts.map +1 -0
- package/dist/BunHttpPlatform.js +35 -0
- package/dist/BunHttpPlatform.js.map +1 -0
- package/dist/BunHttpServer.d.ts +71 -0
- package/dist/BunHttpServer.d.ts.map +1 -0
- package/dist/{esm/internal/httpServer.js → BunHttpServer.js} +149 -118
- package/dist/BunHttpServer.js.map +1 -0
- package/dist/BunHttpServerRequest.d.ts +10 -0
- package/dist/BunHttpServerRequest.d.ts.map +1 -0
- package/dist/BunHttpServerRequest.js +6 -0
- package/dist/BunHttpServerRequest.js.map +1 -0
- package/dist/BunMultipart.d.ts +20 -0
- package/dist/BunMultipart.d.ts.map +1 -0
- package/dist/BunMultipart.js +17 -0
- package/dist/BunMultipart.js.map +1 -0
- package/dist/BunPath.d.ts +18 -0
- package/dist/BunPath.d.ts.map +1 -0
- package/dist/BunPath.js.map +1 -0
- package/dist/BunRedis.d.ts +35 -0
- package/dist/BunRedis.d.ts.map +1 -0
- package/dist/BunRedis.js +51 -0
- package/dist/BunRedis.js.map +1 -0
- package/dist/BunRuntime.d.ts +94 -0
- package/dist/BunRuntime.d.ts.map +1 -0
- package/dist/BunRuntime.js +33 -0
- package/dist/BunRuntime.js.map +1 -0
- package/dist/BunServices.d.ts +20 -0
- package/dist/BunServices.d.ts.map +1 -0
- package/dist/BunServices.js +12 -0
- package/dist/BunServices.js.map +1 -0
- package/dist/BunSink.d.ts.map +1 -0
- package/dist/BunSink.js.map +1 -0
- package/dist/BunSocket.d.ts +26 -0
- package/dist/BunSocket.d.ts.map +1 -0
- package/dist/BunSocket.js +18 -0
- package/dist/BunSocket.js.map +1 -0
- package/dist/BunSocketServer.d.ts.map +1 -0
- package/dist/BunSocketServer.js.map +1 -0
- package/dist/BunStdio.d.ts +8 -0
- package/dist/BunStdio.d.ts.map +1 -0
- package/dist/BunStdio.js +10 -0
- package/dist/BunStdio.js.map +1 -0
- package/dist/BunStream.d.ts +18 -0
- package/dist/BunStream.d.ts.map +1 -0
- package/dist/BunStream.js +44 -0
- package/dist/BunStream.js.map +1 -0
- package/dist/{dts/BunTerminal.d.ts → BunTerminal.d.ts} +2 -2
- package/dist/BunTerminal.d.ts.map +1 -0
- package/dist/{esm/BunTerminal.js → BunTerminal.js} +1 -1
- package/dist/BunTerminal.js.map +1 -0
- package/dist/BunWorker.d.ts +13 -0
- package/dist/BunWorker.d.ts.map +1 -0
- package/dist/BunWorker.js +59 -0
- package/dist/BunWorker.js.map +1 -0
- package/dist/BunWorkerRunner.d.ts +8 -0
- package/dist/BunWorkerRunner.d.ts.map +1 -0
- package/dist/BunWorkerRunner.js +88 -0
- package/dist/BunWorkerRunner.js.map +1 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{esm/index.js → index.js} +21 -7
- package/dist/index.js.map +1 -0
- package/package.json +51 -195
- package/src/BunChildProcessSpawner.ts +6 -0
- package/src/BunClusterHttp.ts +48 -35
- package/src/BunClusterSocket.ts +55 -21
- package/src/BunFileSystem.ts +3 -3
- package/src/BunHttpClient.ts +9 -0
- package/src/BunHttpPlatform.ts +28 -9
- package/src/BunHttpServer.ts +510 -58
- package/src/BunHttpServerRequest.ts +4 -4
- package/src/BunMultipart.ts +22 -11
- package/src/BunPath.ts +5 -6
- package/src/BunRedis.ts +74 -0
- package/src/BunRuntime.ts +95 -3
- package/src/BunServices.ts +33 -0
- package/src/BunSocket.ts +20 -10
- package/src/BunStdio.ts +12 -0
- package/src/BunStream.ts +51 -0
- package/src/BunTerminal.ts +2 -2
- package/src/BunWorker.ts +63 -21
- package/src/BunWorkerRunner.ts +92 -11
- package/src/index.ts +37 -19
- package/BunClusterHttp/package.json +0 -6
- package/BunClusterSocket/package.json +0 -6
- package/BunCommandExecutor/package.json +0 -6
- package/BunContext/package.json +0 -6
- package/BunFileSystem/ParcelWatcher/package.json +0 -6
- package/BunFileSystem/package.json +0 -6
- package/BunHttpPlatform/package.json +0 -6
- package/BunHttpServer/package.json +0 -6
- package/BunHttpServerRequest/package.json +0 -6
- package/BunKeyValueStore/package.json +0 -6
- package/BunMultipart/package.json +0 -6
- package/BunPath/package.json +0 -6
- package/BunRuntime/package.json +0 -6
- package/BunSink/package.json +0 -6
- package/BunSocket/package.json +0 -6
- package/BunSocketServer/package.json +0 -6
- package/BunStream/package.json +0 -6
- package/BunTerminal/package.json +0 -6
- package/BunWorker/package.json +0 -6
- package/BunWorkerRunner/package.json +0 -6
- package/dist/cjs/BunClusterHttp.js +0 -59
- package/dist/cjs/BunClusterHttp.js.map +0 -1
- package/dist/cjs/BunClusterSocket.js +0 -55
- package/dist/cjs/BunClusterSocket.js.map +0 -1
- package/dist/cjs/BunCommandExecutor.js +0 -18
- package/dist/cjs/BunCommandExecutor.js.map +0 -1
- package/dist/cjs/BunContext.js +0 -20
- package/dist/cjs/BunContext.js.map +0 -1
- package/dist/cjs/BunFileSystem/ParcelWatcher.js +0 -18
- package/dist/cjs/BunFileSystem/ParcelWatcher.js.map +0 -1
- package/dist/cjs/BunFileSystem.js +0 -18
- package/dist/cjs/BunFileSystem.js.map +0 -1
- package/dist/cjs/BunHttpPlatform.js +0 -19
- package/dist/cjs/BunHttpPlatform.js.map +0 -1
- package/dist/cjs/BunHttpServer.js +0 -48
- package/dist/cjs/BunHttpServer.js.map +0 -1
- package/dist/cjs/BunHttpServerRequest.js +0 -14
- package/dist/cjs/BunHttpServerRequest.js.map +0 -1
- package/dist/cjs/BunKeyValueStore.js +0 -18
- package/dist/cjs/BunKeyValueStore.js.map +0 -1
- package/dist/cjs/BunMultipart.js +0 -19
- package/dist/cjs/BunMultipart.js.map +0 -1
- package/dist/cjs/BunPath.js +0 -28
- package/dist/cjs/BunPath.js.map +0 -1
- package/dist/cjs/BunRuntime.js +0 -18
- package/dist/cjs/BunRuntime.js.map +0 -1
- package/dist/cjs/BunSink.js +0 -17
- package/dist/cjs/BunSink.js.map +0 -1
- package/dist/cjs/BunSocket.js +0 -45
- package/dist/cjs/BunSocket.js.map +0 -1
- package/dist/cjs/BunSocketServer.js +0 -17
- package/dist/cjs/BunSocketServer.js.map +0 -1
- package/dist/cjs/BunStream.js +0 -17
- package/dist/cjs/BunStream.js.map +0 -1
- package/dist/cjs/BunTerminal.js +0 -23
- package/dist/cjs/BunTerminal.js.map +0 -1
- package/dist/cjs/BunWorker.js +0 -29
- package/dist/cjs/BunWorker.js.map +0 -1
- package/dist/cjs/BunWorkerRunner.js +0 -21
- package/dist/cjs/BunWorkerRunner.js.map +0 -1
- package/dist/cjs/index.js +0 -46
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/internal/httpPlatform.js +0 -36
- package/dist/cjs/internal/httpPlatform.js.map +0 -1
- package/dist/cjs/internal/httpServer.js +0 -356
- package/dist/cjs/internal/httpServer.js.map +0 -1
- package/dist/cjs/internal/multipart.js +0 -160
- package/dist/cjs/internal/multipart.js.map +0 -1
- package/dist/cjs/internal/worker.js +0 -63
- package/dist/cjs/internal/worker.js.map +0 -1
- package/dist/cjs/internal/workerRunner.js +0 -84
- package/dist/cjs/internal/workerRunner.js.map +0 -1
- package/dist/dts/BunClusterHttp.d.ts +0 -30
- package/dist/dts/BunClusterHttp.d.ts.map +0 -1
- package/dist/dts/BunClusterSocket.d.ts +0 -35
- package/dist/dts/BunClusterSocket.d.ts.map +0 -1
- package/dist/dts/BunCommandExecutor.d.ts +0 -9
- package/dist/dts/BunCommandExecutor.d.ts.map +0 -1
- package/dist/dts/BunContext.d.ts +0 -20
- package/dist/dts/BunContext.d.ts.map +0 -1
- package/dist/dts/BunFileSystem/ParcelWatcher.d.ts +0 -8
- package/dist/dts/BunFileSystem/ParcelWatcher.d.ts.map +0 -1
- package/dist/dts/BunFileSystem.d.ts +0 -8
- package/dist/dts/BunFileSystem.d.ts.map +0 -1
- package/dist/dts/BunHttpPlatform.d.ts +0 -19
- package/dist/dts/BunHttpPlatform.d.ts.map +0 -1
- package/dist/dts/BunHttpServer.d.ts +0 -72
- package/dist/dts/BunHttpServer.d.ts.map +0 -1
- package/dist/dts/BunHttpServerRequest.d.ts +0 -10
- package/dist/dts/BunHttpServerRequest.d.ts.map +0 -1
- package/dist/dts/BunKeyValueStore.d.ts +0 -9
- package/dist/dts/BunKeyValueStore.d.ts.map +0 -1
- package/dist/dts/BunMultipart.d.ts +0 -20
- package/dist/dts/BunMultipart.d.ts.map +0 -1
- package/dist/dts/BunPath.d.ts +0 -21
- package/dist/dts/BunPath.d.ts.map +0 -1
- package/dist/dts/BunRuntime.d.ts +0 -7
- package/dist/dts/BunRuntime.d.ts.map +0 -1
- package/dist/dts/BunSink.d.ts.map +0 -1
- package/dist/dts/BunSocket.d.ts +0 -22
- package/dist/dts/BunSocket.d.ts.map +0 -1
- package/dist/dts/BunSocketServer.d.ts.map +0 -1
- package/dist/dts/BunStream.d.ts +0 -8
- package/dist/dts/BunStream.d.ts.map +0 -1
- package/dist/dts/BunTerminal.d.ts.map +0 -1
- package/dist/dts/BunWorker.d.ts +0 -26
- package/dist/dts/BunWorker.d.ts.map +0 -1
- package/dist/dts/BunWorkerRunner.d.ts +0 -17
- package/dist/dts/BunWorkerRunner.d.ts.map +0 -1
- package/dist/dts/index.d.ts +0 -77
- package/dist/dts/index.d.ts.map +0 -1
- package/dist/dts/internal/httpPlatform.d.ts +0 -2
- package/dist/dts/internal/httpPlatform.d.ts.map +0 -1
- package/dist/dts/internal/httpServer.d.ts +0 -2
- package/dist/dts/internal/httpServer.d.ts.map +0 -1
- package/dist/dts/internal/multipart.d.ts +0 -2
- package/dist/dts/internal/multipart.d.ts.map +0 -1
- package/dist/dts/internal/worker.d.ts +0 -2
- package/dist/dts/internal/worker.d.ts.map +0 -1
- package/dist/dts/internal/workerRunner.d.ts +0 -2
- package/dist/dts/internal/workerRunner.d.ts.map +0 -1
- package/dist/esm/BunClusterHttp.js +0 -50
- package/dist/esm/BunClusterHttp.js.map +0 -1
- package/dist/esm/BunClusterSocket.js +0 -45
- package/dist/esm/BunClusterSocket.js.map +0 -1
- package/dist/esm/BunCommandExecutor.js +0 -10
- package/dist/esm/BunCommandExecutor.js.map +0 -1
- package/dist/esm/BunContext.js +0 -13
- package/dist/esm/BunContext.js.map +0 -1
- package/dist/esm/BunFileSystem/ParcelWatcher.js +0 -10
- package/dist/esm/BunFileSystem/ParcelWatcher.js.map +0 -1
- package/dist/esm/BunFileSystem.js.map +0 -1
- package/dist/esm/BunHttpPlatform.js +0 -12
- package/dist/esm/BunHttpPlatform.js.map +0 -1
- package/dist/esm/BunHttpServer.js +0 -41
- package/dist/esm/BunHttpServer.js.map +0 -1
- package/dist/esm/BunHttpServerRequest.js +0 -7
- package/dist/esm/BunHttpServerRequest.js.map +0 -1
- package/dist/esm/BunKeyValueStore.js +0 -10
- package/dist/esm/BunKeyValueStore.js.map +0 -1
- package/dist/esm/BunMultipart.js +0 -12
- package/dist/esm/BunMultipart.js.map +0 -1
- package/dist/esm/BunPath.js.map +0 -1
- package/dist/esm/BunRuntime.js +0 -10
- package/dist/esm/BunRuntime.js.map +0 -1
- package/dist/esm/BunSink.js.map +0 -1
- package/dist/esm/BunSocket.js +0 -20
- package/dist/esm/BunSocket.js.map +0 -1
- package/dist/esm/BunSocketServer.js.map +0 -1
- package/dist/esm/BunStream.js +0 -8
- package/dist/esm/BunStream.js.map +0 -1
- package/dist/esm/BunTerminal.js.map +0 -1
- package/dist/esm/BunWorker.js +0 -22
- package/dist/esm/BunWorker.js.map +0 -1
- package/dist/esm/BunWorkerRunner.js +0 -13
- package/dist/esm/BunWorkerRunner.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/internal/httpPlatform.js +0 -29
- package/dist/esm/internal/httpPlatform.js.map +0 -1
- package/dist/esm/internal/httpServer.js.map +0 -1
- package/dist/esm/internal/multipart.js +0 -151
- package/dist/esm/internal/multipart.js.map +0 -1
- package/dist/esm/internal/worker.js +0 -54
- package/dist/esm/internal/worker.js.map +0 -1
- package/dist/esm/internal/workerRunner.js +0 -77
- package/dist/esm/internal/workerRunner.js.map +0 -1
- package/dist/esm/package.json +0 -4
- package/index/package.json +0 -6
- package/src/BunCommandExecutor.ts +0 -13
- package/src/BunContext.ts +0 -40
- package/src/BunFileSystem/ParcelWatcher.ts +0 -12
- package/src/BunKeyValueStore.ts +0 -15
- package/src/internal/httpPlatform.ts +0 -25
- package/src/internal/httpServer.ts +0 -478
- package/src/internal/multipart.ts +0 -149
- package/src/internal/worker.ts +0 -68
- package/src/internal/workerRunner.ts +0 -87
- /package/dist/{esm/BunFileSystem.js → BunFileSystem.js} +0 -0
- /package/dist/{esm/BunPath.js → BunPath.js} +0 -0
- /package/dist/{dts/BunSink.d.ts → BunSink.d.ts} +0 -0
- /package/dist/{esm/BunSink.js → BunSink.js} +0 -0
- /package/dist/{dts/BunSocketServer.d.ts → BunSocketServer.d.ts} +0 -0
- /package/dist/{esm/BunSocketServer.js → BunSocketServer.js} +0 -0
package/src/BunPath.ts
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
4
|
import * as NodePath from "@effect/platform-node-shared/NodePath"
|
|
6
|
-
import type
|
|
7
|
-
import type {
|
|
5
|
+
import type * as Layer from "effect/Layer"
|
|
6
|
+
import type { Path } from "effect/Path"
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @since 1.0.0
|
|
11
10
|
* @category layer
|
|
12
11
|
*/
|
|
13
|
-
export const layer: Layer<Path> = NodePath.layer
|
|
12
|
+
export const layer: Layer.Layer<Path> = NodePath.layer
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* @since 1.0.0
|
|
17
16
|
* @category layer
|
|
18
17
|
*/
|
|
19
|
-
export const layerPosix: Layer<Path> = NodePath.layerPosix
|
|
18
|
+
export const layerPosix: Layer.Layer<Path> = NodePath.layerPosix
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* @since 1.0.0
|
|
23
22
|
* @category layer
|
|
24
23
|
*/
|
|
25
|
-
export const layerWin32: Layer<Path> = NodePath.layerWin32
|
|
24
|
+
export const layerWin32: Layer.Layer<Path> = NodePath.layerWin32
|
package/src/BunRedis.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import { RedisClient, type RedisOptions } from "bun"
|
|
5
|
+
import * as Config from "effect/Config"
|
|
6
|
+
import * as Effect from "effect/Effect"
|
|
7
|
+
import * as Fn from "effect/Function"
|
|
8
|
+
import * as Layer from "effect/Layer"
|
|
9
|
+
import * as Scope from "effect/Scope"
|
|
10
|
+
import * as ServiceMap from "effect/ServiceMap"
|
|
11
|
+
import * as Redis from "effect/unstable/persistence/Redis"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
* @category Service
|
|
16
|
+
*/
|
|
17
|
+
export class BunRedis extends ServiceMap.Service<BunRedis, {
|
|
18
|
+
readonly client: RedisClient
|
|
19
|
+
readonly use: <A>(f: (client: RedisClient) => Promise<A>) => Effect.Effect<A, Redis.RedisError>
|
|
20
|
+
}>()("@effect/platform-bun/BunRedis") {}
|
|
21
|
+
|
|
22
|
+
const make = Effect.fnUntraced(function*(
|
|
23
|
+
options?: {
|
|
24
|
+
readonly url?: string
|
|
25
|
+
} & RedisOptions
|
|
26
|
+
) {
|
|
27
|
+
const scope = yield* Effect.scope
|
|
28
|
+
yield* Scope.addFinalizer(scope, Effect.sync(() => client.close()))
|
|
29
|
+
const client = new RedisClient(options?.url, options)
|
|
30
|
+
|
|
31
|
+
const use = <A>(f: (client: RedisClient) => Promise<A>) =>
|
|
32
|
+
Effect.tryPromise({
|
|
33
|
+
try: () => f(client),
|
|
34
|
+
catch: (cause) => new Redis.RedisError({ cause })
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const redis = yield* Redis.make({
|
|
38
|
+
send: <A = unknown>(command: string, ...args: ReadonlyArray<string>) =>
|
|
39
|
+
Effect.tryPromise({
|
|
40
|
+
try: () => client.send(command, args as Array<string>) as Promise<A>,
|
|
41
|
+
catch: (cause) => new Redis.RedisError({ cause })
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const bunRedis = Fn.identity<BunRedis["Service"]>({
|
|
46
|
+
client,
|
|
47
|
+
use
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
return ServiceMap.make(BunRedis, bunRedis).pipe(
|
|
51
|
+
ServiceMap.add(Redis.Redis, redis)
|
|
52
|
+
)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
* @category Layers
|
|
58
|
+
*/
|
|
59
|
+
export const layer = (
|
|
60
|
+
options?: ({ readonly url?: string } & RedisOptions) | undefined
|
|
61
|
+
): Layer.Layer<Redis.Redis | BunRedis> => Layer.effectServices(make(options))
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @since 1.0.0
|
|
65
|
+
* @category Layers
|
|
66
|
+
*/
|
|
67
|
+
export const layerConfig = (
|
|
68
|
+
options: Config.Wrap<{ readonly url?: string } & RedisOptions>
|
|
69
|
+
): Layer.Layer<Redis.Redis | BunRedis, Config.ConfigError> =>
|
|
70
|
+
Layer.effectServices(
|
|
71
|
+
Config.unwrap(options).asEffect().pipe(
|
|
72
|
+
Effect.flatMap(make)
|
|
73
|
+
)
|
|
74
|
+
)
|
package/src/BunRuntime.ts
CHANGED
|
@@ -2,10 +2,102 @@
|
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
4
|
import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime"
|
|
5
|
-
import type {
|
|
5
|
+
import type { Effect } from "effect/Effect"
|
|
6
|
+
import type { Teardown } from "effect/Runtime"
|
|
6
7
|
|
|
7
8
|
/**
|
|
9
|
+
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
10
|
+
*
|
|
11
|
+
* **Details**
|
|
12
|
+
*
|
|
13
|
+
* This function launches an Effect as the main entry point, setting exit codes
|
|
14
|
+
* based on success or failure, handling interrupts (e.g., Ctrl+C), and optionally
|
|
15
|
+
* logging errors. By default, it logs errors and uses a "pretty" format, but both
|
|
16
|
+
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
17
|
+
* finalize resources or produce different exit codes.
|
|
18
|
+
*
|
|
19
|
+
* **Options**
|
|
20
|
+
*
|
|
21
|
+
* An optional object that can include:
|
|
22
|
+
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
23
|
+
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
24
|
+
* - `teardown`: Provide custom finalization logic.
|
|
25
|
+
*
|
|
26
|
+
* **When to Use**
|
|
27
|
+
*
|
|
28
|
+
* Use this function to run an Effect as your application’s main program, especially
|
|
29
|
+
* when you need structured error handling, log management, interrupt support,
|
|
30
|
+
* or advanced teardown capabilities.
|
|
31
|
+
*
|
|
8
32
|
* @since 1.0.0
|
|
9
|
-
* @category
|
|
33
|
+
* @category Run main
|
|
10
34
|
*/
|
|
11
|
-
export const runMain:
|
|
35
|
+
export const runMain: {
|
|
36
|
+
/**
|
|
37
|
+
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
38
|
+
*
|
|
39
|
+
* **Details**
|
|
40
|
+
*
|
|
41
|
+
* This function launches an Effect as the main entry point, setting exit codes
|
|
42
|
+
* based on success or failure, handling interrupts (e.g., Ctrl+C), and optionally
|
|
43
|
+
* logging errors. By default, it logs errors and uses a "pretty" format, but both
|
|
44
|
+
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
45
|
+
* finalize resources or produce different exit codes.
|
|
46
|
+
*
|
|
47
|
+
* **Options**
|
|
48
|
+
*
|
|
49
|
+
* An optional object that can include:
|
|
50
|
+
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
51
|
+
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
52
|
+
* - `teardown`: Provide custom finalization logic.
|
|
53
|
+
*
|
|
54
|
+
* **When to Use**
|
|
55
|
+
*
|
|
56
|
+
* Use this function to run an Effect as your application’s main program, especially
|
|
57
|
+
* when you need structured error handling, log management, interrupt support,
|
|
58
|
+
* or advanced teardown capabilities.
|
|
59
|
+
*
|
|
60
|
+
* @since 1.0.0
|
|
61
|
+
* @category Run main
|
|
62
|
+
*/
|
|
63
|
+
(
|
|
64
|
+
options?: {
|
|
65
|
+
readonly disableErrorReporting?: boolean | undefined
|
|
66
|
+
readonly teardown?: Teardown | undefined
|
|
67
|
+
}
|
|
68
|
+
): <E, A>(effect: Effect<A, E>) => void
|
|
69
|
+
/**
|
|
70
|
+
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
71
|
+
*
|
|
72
|
+
* **Details**
|
|
73
|
+
*
|
|
74
|
+
* This function launches an Effect as the main entry point, setting exit codes
|
|
75
|
+
* based on success or failure, handling interrupts (e.g., Ctrl+C), and optionally
|
|
76
|
+
* logging errors. By default, it logs errors and uses a "pretty" format, but both
|
|
77
|
+
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
78
|
+
* finalize resources or produce different exit codes.
|
|
79
|
+
*
|
|
80
|
+
* **Options**
|
|
81
|
+
*
|
|
82
|
+
* An optional object that can include:
|
|
83
|
+
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
84
|
+
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
85
|
+
* - `teardown`: Provide custom finalization logic.
|
|
86
|
+
*
|
|
87
|
+
* **When to Use**
|
|
88
|
+
*
|
|
89
|
+
* Use this function to run an Effect as your application’s main program, especially
|
|
90
|
+
* when you need structured error handling, log management, interrupt support,
|
|
91
|
+
* or advanced teardown capabilities.
|
|
92
|
+
*
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
* @category Run main
|
|
95
|
+
*/
|
|
96
|
+
<E, A>(
|
|
97
|
+
effect: Effect<A, E>,
|
|
98
|
+
options?: {
|
|
99
|
+
readonly disableErrorReporting?: boolean | undefined
|
|
100
|
+
readonly teardown?: Teardown | undefined
|
|
101
|
+
}
|
|
102
|
+
): void
|
|
103
|
+
} = NodeRuntime.runMain
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type { FileSystem } from "effect/FileSystem"
|
|
5
|
+
import * as Layer from "effect/Layer"
|
|
6
|
+
import type { Path } from "effect/Path"
|
|
7
|
+
import type { Stdio } from "effect/Stdio"
|
|
8
|
+
import type { Terminal } from "effect/Terminal"
|
|
9
|
+
import type { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner"
|
|
10
|
+
import * as BunChildProcessSpawner from "./BunChildProcessSpawner.ts"
|
|
11
|
+
import * as BunFileSystem from "./BunFileSystem.ts"
|
|
12
|
+
import * as BunPath from "./BunPath.ts"
|
|
13
|
+
import * as BunStdio from "./BunStdio.ts"
|
|
14
|
+
import * as BunTerminal from "./BunTerminal.ts"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
* @category models
|
|
19
|
+
*/
|
|
20
|
+
export type BunServices = ChildProcessSpawner | FileSystem | Path | Terminal | Stdio
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
* @category layer
|
|
25
|
+
*/
|
|
26
|
+
export const layer: Layer.Layer<BunServices> = BunChildProcessSpawner.layer.pipe(
|
|
27
|
+
Layer.provideMerge(Layer.mergeAll(
|
|
28
|
+
BunFileSystem.layer,
|
|
29
|
+
BunPath.layer,
|
|
30
|
+
BunStdio.layer,
|
|
31
|
+
BunTerminal.layer
|
|
32
|
+
))
|
|
33
|
+
)
|
package/src/BunSocket.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import * as
|
|
4
|
+
import type * as Duration from "effect/Duration"
|
|
5
|
+
import type { Effect } from "effect/Effect"
|
|
6
|
+
import { flow } from "effect/Function"
|
|
5
7
|
import * as Layer from "effect/Layer"
|
|
8
|
+
import * as Socket from "effect/unstable/socket/Socket"
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* @since 1.0.0
|
|
@@ -13,18 +16,25 @@ export * from "@effect/platform-node-shared/NodeSocket"
|
|
|
13
16
|
* @since 1.0.0
|
|
14
17
|
* @category layers
|
|
15
18
|
*/
|
|
16
|
-
export const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
19
|
+
export const layerWebSocketConstructor: Layer.Layer<
|
|
20
|
+
Socket.WebSocketConstructor
|
|
21
|
+
> = Layer.succeed(Socket.WebSocketConstructor)(
|
|
22
|
+
(url, protocols) => new globalThis.WebSocket(url, protocols)
|
|
23
|
+
)
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* @since 1.0.0
|
|
25
27
|
* @category layers
|
|
26
28
|
*/
|
|
27
|
-
export const
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
export const layerWebSocket: (
|
|
30
|
+
url: string | Effect<string>,
|
|
31
|
+
options?: {
|
|
32
|
+
readonly closeCodeIsError?: ((code: number) => boolean) | undefined
|
|
33
|
+
readonly openTimeout?: Duration.DurationInput | undefined
|
|
34
|
+
readonly protocols?: string | Array<string> | undefined
|
|
35
|
+
} | undefined
|
|
36
|
+
) => Layer.Layer<Socket.Socket, never, never> = flow(
|
|
37
|
+
Socket.makeWebSocket,
|
|
38
|
+
Layer.effect(Socket.Socket),
|
|
39
|
+
Layer.provide(layerWebSocketConstructor)
|
|
30
40
|
)
|
package/src/BunStdio.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as NodeStdio from "@effect/platform-node-shared/NodeStdio"
|
|
5
|
+
import type * as Layer from "effect/Layer"
|
|
6
|
+
import type { Stdio } from "effect/Stdio"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
* @category layer
|
|
11
|
+
*/
|
|
12
|
+
export const layer: Layer.Layer<Stdio> = NodeStdio.layer
|
package/src/BunStream.ts
CHANGED
|
@@ -1,8 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
+
import * as Arr from "effect/Array"
|
|
5
|
+
import * as Cause from "effect/Cause"
|
|
6
|
+
import * as Channel from "effect/Channel"
|
|
7
|
+
import * as Effect from "effect/Effect"
|
|
8
|
+
import type { LazyArg } from "effect/Function"
|
|
9
|
+
import type * as Pull from "effect/Pull"
|
|
10
|
+
import * as Scope from "effect/Scope"
|
|
11
|
+
import * as Stream from "effect/Stream"
|
|
4
12
|
|
|
5
13
|
/**
|
|
6
14
|
* @since 1.0.0
|
|
7
15
|
*/
|
|
8
16
|
export * from "@effect/platform-node-shared/NodeStream"
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* An optimized version of `Stream.fromReadableStream` that uses the Bun
|
|
20
|
+
* .readMany API to read multiple values at once from a `ReadableStream`.
|
|
21
|
+
*
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
export const fromReadableStream = <A, E>(
|
|
25
|
+
options: {
|
|
26
|
+
readonly evaluate: LazyArg<ReadableStream<A>>
|
|
27
|
+
readonly onError: (error: unknown) => E
|
|
28
|
+
readonly releaseLockOnEnd?: boolean | undefined
|
|
29
|
+
}
|
|
30
|
+
): Stream.Stream<A, E> =>
|
|
31
|
+
Stream.fromChannel(Channel.fromTransform(Effect.fnUntraced(function*(_, scope) {
|
|
32
|
+
const reader = options.evaluate().getReader()
|
|
33
|
+
yield* Scope.addFinalizer(
|
|
34
|
+
scope,
|
|
35
|
+
options.releaseLockOnEnd ? Effect.sync(() => reader.releaseLock()) : Effect.promise(() => reader.cancel())
|
|
36
|
+
)
|
|
37
|
+
const readMany = Effect.callback<Bun.ReadableStreamDefaultReadManyResult<A>, E>((resume) => {
|
|
38
|
+
const result = reader.readMany()
|
|
39
|
+
if ("then" in result) {
|
|
40
|
+
result.then((_) => resume(Effect.succeed(_)), (e) => resume(Effect.fail(options.onError(e))))
|
|
41
|
+
} else {
|
|
42
|
+
resume(Effect.succeed(result))
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
// @effect-diagnostics-next-line returnEffectInGen:off
|
|
46
|
+
return Effect.flatMap(
|
|
47
|
+
readMany,
|
|
48
|
+
function loop(
|
|
49
|
+
{ done, value }
|
|
50
|
+
): Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E> {
|
|
51
|
+
if (done) {
|
|
52
|
+
return Cause.done()
|
|
53
|
+
} else if (!Arr.isReadonlyArrayNonEmpty(value)) {
|
|
54
|
+
return Effect.flatMap(readMany, loop)
|
|
55
|
+
}
|
|
56
|
+
return Effect.succeed(value)
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
})))
|
package/src/BunTerminal.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
4
|
import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal"
|
|
5
|
-
import type { Terminal, UserInput } from "@effect/platform/Terminal"
|
|
6
5
|
import type { Effect } from "effect/Effect"
|
|
7
6
|
import type { Layer } from "effect/Layer"
|
|
8
7
|
import type { Scope } from "effect/Scope"
|
|
8
|
+
import type { Terminal, UserInput } from "effect/Terminal"
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @since 1.0.0
|
|
@@ -15,6 +15,6 @@ export const make: (shouldQuit?: (input: UserInput) => boolean) => Effect<Termin
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @since 1.0.0
|
|
18
|
-
* @category
|
|
18
|
+
* @category layers
|
|
19
19
|
*/
|
|
20
20
|
export const layer: Layer<Terminal> = NodeTerminal.layer
|
package/src/BunWorker.ts
CHANGED
|
@@ -1,34 +1,76 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import * as
|
|
4
|
+
import * as Deferred from "effect/Deferred"
|
|
5
|
+
import * as Effect from "effect/Effect"
|
|
6
|
+
import * as Exit from "effect/Exit"
|
|
7
|
+
import * as Layer from "effect/Layer"
|
|
8
|
+
import * as Scope from "effect/Scope"
|
|
9
|
+
import * as Worker from "effect/unstable/workers/Worker"
|
|
10
|
+
import { WorkerError, WorkerUnknownError } from "effect/unstable/workers/WorkerError"
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* @since 1.0.0
|
|
10
14
|
* @category layers
|
|
11
15
|
*/
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @since 1.0.0
|
|
22
|
-
* @category layers
|
|
23
|
-
*/
|
|
24
|
-
export const layer: (
|
|
25
|
-
spawn: (id: number) => Worker
|
|
26
|
-
) => Layer.Layer<Worker.WorkerManager | Worker.Spawner, never, never> = internal.layer
|
|
16
|
+
export const layer = (
|
|
17
|
+
spawn: (id: number) => globalThis.Worker
|
|
18
|
+
): Layer.Layer<Worker.WorkerPlatform | Worker.Spawner> =>
|
|
19
|
+
Layer.merge(
|
|
20
|
+
layerPlatform,
|
|
21
|
+
Layer.succeed(Worker.Spawner)(spawn)
|
|
22
|
+
)
|
|
27
23
|
|
|
28
24
|
/**
|
|
29
25
|
* @since 1.0.0
|
|
30
26
|
* @category layers
|
|
31
27
|
*/
|
|
32
|
-
export const layerPlatform
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
export const layerPlatform = Layer.succeed(Worker.WorkerPlatform)(
|
|
29
|
+
Worker.makePlatform<globalThis.Worker>()({
|
|
30
|
+
setup({ scope, worker }) {
|
|
31
|
+
const closeDeferred = Deferred.makeUnsafe<void>()
|
|
32
|
+
worker.addEventListener("close", () => {
|
|
33
|
+
Deferred.doneUnsafe(closeDeferred, Exit.void)
|
|
34
|
+
})
|
|
35
|
+
return Effect.as(
|
|
36
|
+
Scope.addFinalizer(
|
|
37
|
+
scope,
|
|
38
|
+
Effect.suspend(() => {
|
|
39
|
+
worker.postMessage([1])
|
|
40
|
+
return Deferred.await(closeDeferred)
|
|
41
|
+
}).pipe(
|
|
42
|
+
Effect.interruptible,
|
|
43
|
+
Effect.timeout(5000),
|
|
44
|
+
Effect.catchCause(() => Effect.sync(() => worker.terminate()))
|
|
45
|
+
)
|
|
46
|
+
),
|
|
47
|
+
worker
|
|
48
|
+
)
|
|
49
|
+
},
|
|
50
|
+
listen({ deferred, emit, port, scope }) {
|
|
51
|
+
function onMessage(event: MessageEvent) {
|
|
52
|
+
emit(event.data)
|
|
53
|
+
}
|
|
54
|
+
function onError(event: ErrorEvent) {
|
|
55
|
+
Deferred.doneUnsafe(
|
|
56
|
+
deferred,
|
|
57
|
+
new WorkerError({
|
|
58
|
+
reason: new WorkerUnknownError({
|
|
59
|
+
message: "An error event was emitted",
|
|
60
|
+
cause: event.error ?? event.message
|
|
61
|
+
})
|
|
62
|
+
}).asEffect()
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
port.addEventListener("message", onMessage)
|
|
66
|
+
port.addEventListener("error", onError)
|
|
67
|
+
return Scope.addFinalizer(
|
|
68
|
+
scope,
|
|
69
|
+
Effect.sync(() => {
|
|
70
|
+
port.removeEventListener("message", onMessage)
|
|
71
|
+
port.removeEventListener("error", onError)
|
|
72
|
+
})
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
)
|
package/src/BunWorkerRunner.ts
CHANGED
|
@@ -1,20 +1,101 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import * as
|
|
4
|
+
import * as Cause from "effect/Cause"
|
|
5
|
+
import * as Deferred from "effect/Deferred"
|
|
6
|
+
import * as Effect from "effect/Effect"
|
|
7
|
+
import * as Exit from "effect/Exit"
|
|
8
|
+
import * as Fiber from "effect/Fiber"
|
|
9
|
+
import { identity } from "effect/Function"
|
|
10
|
+
import * as Layer from "effect/Layer"
|
|
11
|
+
import * as Scope from "effect/Scope"
|
|
12
|
+
import { WorkerError, WorkerReceiveError, WorkerSpawnError } from "effect/unstable/workers/WorkerError"
|
|
13
|
+
import * as WorkerRunner from "effect/unstable/workers/WorkerRunner"
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @since 1.0.0
|
|
11
|
-
* @category re-exports
|
|
12
|
-
*/
|
|
13
|
-
launch
|
|
14
|
-
} from "@effect/platform/WorkerRunner"
|
|
15
|
+
declare const self: MessagePort
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* @since 1.0.0
|
|
18
19
|
* @category layers
|
|
19
20
|
*/
|
|
20
|
-
export const layer: Layer.Layer<
|
|
21
|
+
export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succeed(WorkerRunner.WorkerRunnerPlatform)({
|
|
22
|
+
start: Effect.fnUntraced(function*<O = unknown, I = unknown>() {
|
|
23
|
+
if (!("postMessage" in self)) {
|
|
24
|
+
return yield* new WorkerError({
|
|
25
|
+
reason: new WorkerSpawnError({ message: "not in a Worker context" })
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
const port = self
|
|
29
|
+
const run = <A, E, R>(
|
|
30
|
+
handler: (portId: number, message: I) => Effect.Effect<A, E, R> | void
|
|
31
|
+
) =>
|
|
32
|
+
Effect.scopedWith(Effect.fnUntraced(function*(scope) {
|
|
33
|
+
const closeLatch = Deferred.makeUnsafe<void, WorkerError>()
|
|
34
|
+
const trackFiber = Fiber.runIn(scope)
|
|
35
|
+
const services = yield* Effect.services<R>()
|
|
36
|
+
const runFork = Effect.runForkWith(services)
|
|
37
|
+
const onExit = (exit: Exit.Exit<any, E>) => {
|
|
38
|
+
if (exit._tag === "Failure" && !Cause.hasInterruptsOnly(exit.cause)) {
|
|
39
|
+
runFork(Effect.logError("unhandled error in worker", exit.cause))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function onMessage(event: MessageEvent) {
|
|
44
|
+
const message = (event as MessageEvent).data as WorkerRunner.PlatformMessage<I>
|
|
45
|
+
if (message[0] === 0) {
|
|
46
|
+
const result = handler(0, message[1])
|
|
47
|
+
if (Effect.isEffect(result)) {
|
|
48
|
+
const fiber = runFork(result)
|
|
49
|
+
fiber.addObserver(onExit)
|
|
50
|
+
trackFiber(fiber)
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
port.close()
|
|
54
|
+
Deferred.doneUnsafe(closeLatch, Exit.void)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function onMessageError(error: MessageEvent) {
|
|
58
|
+
Deferred.doneUnsafe(
|
|
59
|
+
closeLatch,
|
|
60
|
+
new WorkerError({
|
|
61
|
+
reason: new WorkerReceiveError({
|
|
62
|
+
message: "received messageerror event",
|
|
63
|
+
cause: error.data
|
|
64
|
+
})
|
|
65
|
+
}).asEffect()
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
function onError(error: MessageEvent) {
|
|
69
|
+
Deferred.doneUnsafe(
|
|
70
|
+
closeLatch,
|
|
71
|
+
new WorkerError({
|
|
72
|
+
reason: new WorkerReceiveError({
|
|
73
|
+
message: "received error event",
|
|
74
|
+
cause: error.data
|
|
75
|
+
})
|
|
76
|
+
}).asEffect()
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
yield* Scope.addFinalizer(
|
|
80
|
+
scope,
|
|
81
|
+
Effect.sync(() => {
|
|
82
|
+
port.removeEventListener("message", onMessage)
|
|
83
|
+
port.removeEventListener("messageerror", onError)
|
|
84
|
+
})
|
|
85
|
+
)
|
|
86
|
+
port.addEventListener("message", onMessage)
|
|
87
|
+
port.addEventListener("messageerror", onMessageError)
|
|
88
|
+
port.postMessage([0])
|
|
89
|
+
|
|
90
|
+
return yield* Deferred.await(closeLatch)
|
|
91
|
+
}))
|
|
92
|
+
|
|
93
|
+
const sendUnsafe = (_portId: number, message: O, transfer?: ReadonlyArray<unknown>) =>
|
|
94
|
+
port.postMessage([1, message], {
|
|
95
|
+
transfer: transfer as any
|
|
96
|
+
})
|
|
97
|
+
const send = (_portId: number, message: O, transfer?: ReadonlyArray<unknown>) =>
|
|
98
|
+
Effect.sync(() => sendUnsafe(0, message, transfer))
|
|
99
|
+
return identity<WorkerRunner.WorkerRunner<any, any>>({ run, send, sendUnsafe })
|
|
100
|
+
})
|
|
101
|
+
})
|