@effect/platform-bun 4.0.0-beta.7 → 4.0.0-beta.71
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 +1 -1
- package/dist/BunChildProcessSpawner.js +1 -1
- package/dist/BunClusterHttp.d.ts +70 -7
- package/dist/BunClusterHttp.d.ts.map +1 -1
- package/dist/BunClusterHttp.js +41 -10
- package/dist/BunClusterHttp.js.map +1 -1
- package/dist/BunClusterSocket.d.ts +54 -9
- package/dist/BunClusterSocket.d.ts.map +1 -1
- package/dist/BunClusterSocket.js +54 -9
- package/dist/BunClusterSocket.js.map +1 -1
- package/dist/BunCrypto.d.ts +10 -0
- package/dist/BunCrypto.d.ts.map +1 -0
- package/dist/BunCrypto.js +22 -0
- package/dist/BunCrypto.js.map +1 -0
- package/dist/BunFileSystem.d.ts +4 -2
- package/dist/BunFileSystem.d.ts.map +1 -1
- package/dist/BunFileSystem.js +27 -3
- package/dist/BunFileSystem.js.map +1 -1
- package/dist/BunHttpClient.d.ts +2 -2
- package/dist/BunHttpClient.js +2 -2
- package/dist/BunHttpPlatform.d.ts +4 -2
- package/dist/BunHttpPlatform.d.ts.map +1 -1
- package/dist/BunHttpPlatform.js +5 -3
- package/dist/BunHttpPlatform.js.map +1 -1
- package/dist/BunHttpServer.d.ts +77 -19
- package/dist/BunHttpServer.d.ts.map +1 -1
- package/dist/BunHttpServer.js +63 -36
- package/dist/BunHttpServer.js.map +1 -1
- package/dist/BunHttpServerRequest.d.ts +26 -2
- package/dist/BunHttpServerRequest.d.ts.map +1 -1
- package/dist/BunHttpServerRequest.js +3 -1
- package/dist/BunHttpServerRequest.js.map +1 -1
- package/dist/BunMultipart.d.ts +28 -5
- package/dist/BunMultipart.d.ts.map +1 -1
- package/dist/BunMultipart.js +15 -5
- package/dist/BunMultipart.js.map +1 -1
- package/dist/BunPath.d.ts +12 -6
- package/dist/BunPath.d.ts.map +1 -1
- package/dist/BunPath.js +42 -7
- package/dist/BunPath.js.map +1 -1
- package/dist/BunRedis.d.ts +48 -9
- package/dist/BunRedis.d.ts.map +1 -1
- package/dist/BunRedis.js +51 -12
- package/dist/BunRedis.js.map +1 -1
- package/dist/BunRuntime.d.ts +24 -30
- package/dist/BunRuntime.d.ts.map +1 -1
- package/dist/BunRuntime.js +38 -11
- package/dist/BunRuntime.js.map +1 -1
- package/dist/BunServices.d.ts +32 -5
- package/dist/BunServices.d.ts.map +1 -1
- package/dist/BunServices.js +7 -3
- package/dist/BunServices.js.map +1 -1
- package/dist/BunSink.d.ts +2 -2
- package/dist/BunSink.js +2 -2
- package/dist/BunSocket.d.ts +30 -4
- package/dist/BunSocket.d.ts.map +1 -1
- package/dist/BunSocket.js +10 -3
- package/dist/BunSocket.js.map +1 -1
- package/dist/BunSocketServer.d.ts +2 -2
- package/dist/BunSocketServer.js +2 -2
- package/dist/BunStdio.d.ts +5 -2
- package/dist/BunStdio.d.ts.map +1 -1
- package/dist/BunStdio.js +36 -3
- package/dist/BunStdio.js.map +1 -1
- package/dist/BunStream.d.ts +3 -2
- package/dist/BunStream.d.ts.map +1 -1
- package/dist/BunStream.js +34 -3
- package/dist/BunStream.js.map +1 -1
- package/dist/BunTerminal.d.ts +8 -2
- package/dist/BunTerminal.d.ts.map +1 -1
- package/dist/BunTerminal.js +41 -3
- package/dist/BunTerminal.js.map +1 -1
- package/dist/BunWorker.d.ts +9 -2
- package/dist/BunWorker.d.ts.map +1 -1
- package/dist/BunWorker.js +46 -4
- package/dist/BunWorker.js.map +1 -1
- package/dist/BunWorkerRunner.d.ts +5 -1
- package/dist/BunWorkerRunner.d.ts.map +1 -1
- package/dist/BunWorkerRunner.js +41 -5
- package/dist/BunWorkerRunner.js.map +1 -1
- package/dist/index.d.ts +25 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -23
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/BunChildProcessSpawner.ts +1 -1
- package/src/BunClusterHttp.ts +75 -11
- package/src/BunClusterSocket.ts +54 -9
- package/src/BunCrypto.ts +24 -0
- package/src/BunFileSystem.ts +27 -3
- package/src/BunHttpClient.ts +2 -2
- package/src/BunHttpPlatform.ts +28 -4
- package/src/BunHttpServer.ts +128 -56
- package/src/BunHttpServerRequest.ts +26 -2
- package/src/BunMultipart.ts +36 -6
- package/src/BunPath.ts +42 -7
- package/src/BunRedis.ts +53 -14
- package/src/BunRuntime.ts +54 -31
- package/src/BunServices.ts +34 -5
- package/src/BunSink.ts +2 -2
- package/src/BunSocket.ts +30 -4
- package/src/BunSocketServer.ts +2 -2
- package/src/BunStdio.ts +36 -3
- package/src/BunStream.ts +34 -3
- package/src/BunTerminal.ts +41 -3
- package/src/BunWorker.ts +46 -4
- package/src/BunWorkerRunner.ts +41 -5
- package/src/index.ts +26 -23
package/dist/BunSocket.d.ts
CHANGED
|
@@ -1,22 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun platform socket entry point for Effect sockets backed by Bun-compatible
|
|
3
|
+
* Node streams and Bun's native WebSocket implementation.
|
|
4
|
+
*
|
|
5
|
+
* This module re-exports the shared Node socket constructors for TCP clients,
|
|
6
|
+
* Unix domain socket clients, and adapters from existing Node `Duplex` streams,
|
|
7
|
+
* then adds Bun-specific WebSocket layers using `globalThis.WebSocket`. Use it
|
|
8
|
+
* in Bun applications that connect to raw socket protocols, Unix sockets,
|
|
9
|
+
* realtime WebSocket services, or Effect RPC transports that need a
|
|
10
|
+
* `Socket.Socket` layer.
|
|
11
|
+
*
|
|
12
|
+
* TCP lifecycle behavior comes from the shared Node layer: sockets are scoped,
|
|
13
|
+
* finalizers close or destroy the underlying stream, open timeouts become
|
|
14
|
+
* socket open errors, and read, write, and close events are mapped to
|
|
15
|
+
* `SocketError` values. TLS concerns depend on the transport being used: `wss:`
|
|
16
|
+
* URLs are handled by Bun's WebSocket implementation, while TLS-wrapped
|
|
17
|
+
* `Duplex` streams can be adapted after they have been created elsewhere.
|
|
18
|
+
* When closing intentionally, send `Socket.CloseEvent` values so the close code
|
|
19
|
+
* and reason are preserved through the socket lifecycle.
|
|
20
|
+
*
|
|
21
|
+
* @since 4.0.0
|
|
3
22
|
*/
|
|
4
23
|
import type * as Duration from "effect/Duration";
|
|
5
24
|
import type { Effect } from "effect/Effect";
|
|
6
25
|
import * as Layer from "effect/Layer";
|
|
7
26
|
import * as Socket from "effect/unstable/socket/Socket";
|
|
8
27
|
/**
|
|
9
|
-
* @since
|
|
28
|
+
* @since 4.0.0
|
|
10
29
|
*/
|
|
11
30
|
export * from "@effect/platform-node-shared/NodeSocket";
|
|
12
31
|
/**
|
|
13
|
-
*
|
|
32
|
+
* Provides a `Socket.WebSocketConstructor` backed by Bun's global
|
|
33
|
+
* `WebSocket` implementation.
|
|
34
|
+
*
|
|
14
35
|
* @category layers
|
|
36
|
+
* @since 4.0.0
|
|
15
37
|
*/
|
|
16
38
|
export declare const layerWebSocketConstructor: Layer.Layer<Socket.WebSocketConstructor>;
|
|
17
39
|
/**
|
|
18
|
-
*
|
|
40
|
+
* Creates a `Socket.Socket` layer for a WebSocket URL using Bun's global
|
|
41
|
+
* `WebSocket` constructor, honoring protocol, open-timeout, and close-code
|
|
42
|
+
* error options.
|
|
43
|
+
*
|
|
19
44
|
* @category layers
|
|
45
|
+
* @since 4.0.0
|
|
20
46
|
*/
|
|
21
47
|
export declare const layerWebSocket: (url: string | Effect<string>, options?: {
|
|
22
48
|
readonly closeCodeIsError?: ((code: number) => boolean) | undefined;
|
package/dist/BunSocket.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunSocket.d.ts","sourceRoot":"","sources":["../src/BunSocket.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"BunSocket.d.ts","sourceRoot":"","sources":["../src/BunSocket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAEvD;;GAEG;AACH,cAAc,yCAAyC,CAAA;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,KAAK,CACjD,MAAM,CAAC,oBAAoB,CAG5B,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,CAC3B,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAC5B,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,CAAA;IACnE,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAA;IACjD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;CACxD,GAAG,SAAS,KACV,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAI3C,CAAA"}
|
package/dist/BunSocket.js
CHANGED
|
@@ -2,17 +2,24 @@ import { flow } from "effect/Function";
|
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
3
|
import * as Socket from "effect/unstable/socket/Socket";
|
|
4
4
|
/**
|
|
5
|
-
* @since
|
|
5
|
+
* @since 4.0.0
|
|
6
6
|
*/
|
|
7
7
|
export * from "@effect/platform-node-shared/NodeSocket";
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Provides a `Socket.WebSocketConstructor` backed by Bun's global
|
|
10
|
+
* `WebSocket` implementation.
|
|
11
|
+
*
|
|
10
12
|
* @category layers
|
|
13
|
+
* @since 4.0.0
|
|
11
14
|
*/
|
|
12
15
|
export const layerWebSocketConstructor = /*#__PURE__*/Layer.succeed(Socket.WebSocketConstructor)((url, protocols) => new globalThis.WebSocket(url, protocols));
|
|
13
16
|
/**
|
|
14
|
-
*
|
|
17
|
+
* Creates a `Socket.Socket` layer for a WebSocket URL using Bun's global
|
|
18
|
+
* `WebSocket` constructor, honoring protocol, open-timeout, and close-code
|
|
19
|
+
* error options.
|
|
20
|
+
*
|
|
15
21
|
* @category layers
|
|
22
|
+
* @since 4.0.0
|
|
16
23
|
*/
|
|
17
24
|
export const layerWebSocket = /*#__PURE__*/flow(Socket.makeWebSocket, /*#__PURE__*/Layer.effect(Socket.Socket), /*#__PURE__*/Layer.provide(layerWebSocketConstructor));
|
|
18
25
|
//# sourceMappingURL=BunSocket.js.map
|
package/dist/BunSocket.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunSocket.js","names":["flow","Layer","Socket","layerWebSocketConstructor","succeed","WebSocketConstructor","url","protocols","globalThis","WebSocket","layerWebSocket","makeWebSocket","effect","provide"],"sources":["../src/BunSocket.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"file":"BunSocket.js","names":["flow","Layer","Socket","layerWebSocketConstructor","succeed","WebSocketConstructor","url","protocols","globalThis","WebSocket","layerWebSocket","makeWebSocket","effect","provide"],"sources":["../src/BunSocket.ts"],"sourcesContent":[null],"mappings":"AAwBA,SAASA,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,+BAA+B;AAEvD;;;AAGA,cAAc,yCAAyC;AAEvD;;;;;;;AAOA,OAAO,MAAMC,yBAAyB,gBAElCF,KAAK,CAACG,OAAO,CAACF,MAAM,CAACG,oBAAoB,CAAC,CAC5C,CAACC,GAAG,EAAEC,SAAS,KAAK,IAAIC,UAAU,CAACC,SAAS,CAACH,GAAG,EAAEC,SAAS,CAAC,CAC7D;AAED;;;;;;;;AAQA,OAAO,MAAMG,cAAc,gBAOqBV,IAAI,CAClDE,MAAM,CAACS,aAAa,eACpBV,KAAK,CAACW,MAAM,CAACV,MAAM,CAACA,MAAM,CAAC,eAC3BD,KAAK,CAACY,OAAO,CAACV,yBAAyB,CAAC,CACzC","ignoreList":[]}
|
package/dist/BunSocketServer.js
CHANGED
package/dist/BunStdio.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type * as Layer from "effect/Layer";
|
|
2
2
|
import type { Stdio } from "effect/Stdio";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Provides the `Stdio` service backed by the current process arguments,
|
|
5
|
+
* stdin, stdout, and stderr streams.
|
|
6
|
+
*
|
|
7
|
+
* @category layers
|
|
8
|
+
* @since 4.0.0
|
|
6
9
|
*/
|
|
7
10
|
export declare const layer: Layer.Layer<Stdio>;
|
|
8
11
|
//# sourceMappingURL=BunStdio.d.ts.map
|
package/dist/BunStdio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunStdio.d.ts","sourceRoot":"","sources":["../src/BunStdio.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BunStdio.d.ts","sourceRoot":"","sources":["../src/BunStdio.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAmB,CAAA"}
|
package/dist/BunStdio.js
CHANGED
|
@@ -1,10 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Process stdio for Bun applications.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the Bun layer for Effect's `Stdio` service by adapting
|
|
5
|
+
* the current process arguments and standard streams. Arguments come from
|
|
6
|
+
* `process.argv`, input is read from `process.stdin`, and output and error
|
|
7
|
+
* output write to `process.stdout` and `process.stderr`.
|
|
8
|
+
*
|
|
9
|
+
* **Mental model**
|
|
10
|
+
*
|
|
11
|
+
* `BunStdio.layer` is a thin Bun-facing wrapper around the shared
|
|
12
|
+
* Node-compatible stdio implementation. It does not create private streams for
|
|
13
|
+
* an application; it exposes the global streams owned by the running Bun
|
|
14
|
+
* process through the `Stdio` service.
|
|
15
|
+
*
|
|
16
|
+
* **Common tasks**
|
|
17
|
+
*
|
|
18
|
+
* - Provide `Stdio` for Bun CLIs, scripts, command runners, and tests.
|
|
19
|
+
* - Read process arguments or standard input through Effect services.
|
|
20
|
+
* - Write normal output and diagnostics without depending directly on
|
|
21
|
+
* `process.stdout` or `process.stderr`.
|
|
22
|
+
*
|
|
23
|
+
* **Gotchas**
|
|
24
|
+
*
|
|
25
|
+
* The layer keeps stdin open and does not end stdout or stderr by default,
|
|
26
|
+
* which avoids closing handles that prompts, loggers, or other code may still
|
|
27
|
+
* use. Stdio may be attached to a TTY, pipe, or redirected file, so
|
|
28
|
+
* terminal-specific behavior such as raw mode, echo, colors, cursor control,
|
|
29
|
+
* and terminal dimensions should be handled with terminal APIs such as
|
|
30
|
+
* `BunTerminal`, not inferred from this layer.
|
|
31
|
+
*
|
|
32
|
+
* @since 4.0.0
|
|
3
33
|
*/
|
|
4
34
|
import * as NodeStdio from "@effect/platform-node-shared/NodeStdio";
|
|
5
35
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
36
|
+
* Provides the `Stdio` service backed by the current process arguments,
|
|
37
|
+
* stdin, stdout, and stderr streams.
|
|
38
|
+
*
|
|
39
|
+
* @category layers
|
|
40
|
+
* @since 4.0.0
|
|
8
41
|
*/
|
|
9
42
|
export const layer = NodeStdio.layer;
|
|
10
43
|
//# sourceMappingURL=BunStdio.js.map
|
package/dist/BunStdio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunStdio.js","names":["NodeStdio","layer"],"sources":["../src/BunStdio.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"BunStdio.js","names":["NodeStdio","layer"],"sources":["../src/BunStdio.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,OAAO,KAAKA,SAAS,MAAM,wCAAwC;AAInE;;;;;;;AAOA,OAAO,MAAMC,KAAK,GAAuBD,SAAS,CAACC,KAAK","ignoreList":[]}
|
package/dist/BunStream.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { LazyArg } from "effect/Function";
|
|
2
2
|
import * as Stream from "effect/Stream";
|
|
3
3
|
/**
|
|
4
|
-
* @since
|
|
4
|
+
* @since 4.0.0
|
|
5
5
|
*/
|
|
6
6
|
export * from "@effect/platform-node-shared/NodeStream";
|
|
7
7
|
/**
|
|
8
8
|
* An optimized version of `Stream.fromReadableStream` that uses the Bun
|
|
9
9
|
* .readMany API to read multiple values at once from a `ReadableStream`.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @category constructors
|
|
12
|
+
* @since 4.0.0
|
|
12
13
|
*/
|
|
13
14
|
export declare const fromReadableStream: <A, E>(options: {
|
|
14
15
|
readonly evaluate: LazyArg<ReadableStream<A>>;
|
package/dist/BunStream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunStream.d.ts","sourceRoot":"","sources":["../src/BunStream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BunStream.d.ts","sourceRoot":"","sources":["../src/BunStream.ts"],"names":[],"mappings":"AAqCA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAG9C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;GAEG;AACH,cAAc,yCAAyC,CAAA;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAAE,CAAC,EACrC,SAAS;IACP,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7C,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,CAAA;IACvC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAChD,KACA,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CA6Bf,CAAA"}
|
package/dist/BunStream.js
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun stream interoperability for Effect streams.
|
|
3
|
+
*
|
|
4
|
+
* This module is the Bun entry point for adapting runtime streams into Effect's
|
|
5
|
+
* streaming model. It re-exports the shared Node stream adapters for Bun's
|
|
6
|
+
* Node-compatible stream APIs and adds {@link fromReadableStream}, a Web
|
|
7
|
+
* `ReadableStream` adapter that uses Bun's `readMany` reader method to pull
|
|
8
|
+
* batches of values into an Effect `Stream`.
|
|
9
|
+
*
|
|
10
|
+
* **Mental model**
|
|
11
|
+
*
|
|
12
|
+
* Consuming the returned `Stream` drives reads from the underlying
|
|
13
|
+
* `ReadableStreamDefaultReader`. Each pull asks Bun for the next batch, empty
|
|
14
|
+
* batches are skipped, read failures are translated with `onError`, and the
|
|
15
|
+
* reader is finalized with the surrounding Effect scope.
|
|
16
|
+
*
|
|
17
|
+
* **Common tasks**
|
|
18
|
+
*
|
|
19
|
+
* Use {@link fromReadableStream} for Bun `Request` and `Response` bodies,
|
|
20
|
+
* multipart uploads, and other Web stream sources that should be transformed,
|
|
21
|
+
* decoded, or piped with Effect stream operators. Use the re-exported Node
|
|
22
|
+
* stream adapters for APIs that expose Bun's Node-compatible `stream` types.
|
|
23
|
+
*
|
|
24
|
+
* **Gotchas**
|
|
25
|
+
*
|
|
26
|
+
* Web stream readers hold an exclusive lock. Request and response bodies are
|
|
27
|
+
* also one-shot; once consumed they are disturbed and should not be read through
|
|
28
|
+
* another API. By default finalization cancels the reader; set
|
|
29
|
+
* `releaseLockOnEnd` when the stream is externally owned and only the reader
|
|
30
|
+
* lock should be released.
|
|
31
|
+
*
|
|
32
|
+
* @since 4.0.0
|
|
3
33
|
*/
|
|
4
34
|
import * as Arr from "effect/Array";
|
|
5
35
|
import * as Cause from "effect/Cause";
|
|
@@ -8,14 +38,15 @@ import * as Effect from "effect/Effect";
|
|
|
8
38
|
import * as Scope from "effect/Scope";
|
|
9
39
|
import * as Stream from "effect/Stream";
|
|
10
40
|
/**
|
|
11
|
-
* @since
|
|
41
|
+
* @since 4.0.0
|
|
12
42
|
*/
|
|
13
43
|
export * from "@effect/platform-node-shared/NodeStream";
|
|
14
44
|
/**
|
|
15
45
|
* An optimized version of `Stream.fromReadableStream` that uses the Bun
|
|
16
46
|
* .readMany API to read multiple values at once from a `ReadableStream`.
|
|
17
47
|
*
|
|
18
|
-
* @
|
|
48
|
+
* @category constructors
|
|
49
|
+
* @since 4.0.0
|
|
19
50
|
*/
|
|
20
51
|
export const fromReadableStream = options => Stream.fromChannel(Channel.fromTransform(Effect.fnUntraced(function* (_, scope) {
|
|
21
52
|
const reader = options.evaluate().getReader();
|
package/dist/BunStream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunStream.js","names":["Arr","Cause","Channel","Effect","Scope","Stream","fromReadableStream","options","fromChannel","fromTransform","fnUntraced","_","scope","reader","evaluate","getReader","addFinalizer","releaseLockOnEnd","sync","releaseLock","promise","cancel","readMany","callback","resume","result","then","succeed","e","fail","onError","flatMap","loop","done","value","isReadonlyArrayNonEmpty"],"sources":["../src/BunStream.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"BunStream.js","names":["Arr","Cause","Channel","Effect","Scope","Stream","fromReadableStream","options","fromChannel","fromTransform","fnUntraced","_","scope","reader","evaluate","getReader","addFinalizer","releaseLockOnEnd","sync","releaseLock","promise","cancel","readMany","callback","resume","result","then","succeed","e","fail","onError","flatMap","loop","done","value","isReadonlyArrayNonEmpty"],"sources":["../src/BunStream.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,OAAO,KAAKA,GAAG,MAAM,cAAc;AACnC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAGvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC;;;AAGA,cAAc,yCAAyC;AAEvD;;;;;;;AAOA,OAAO,MAAMC,kBAAkB,GAC7BC,OAIC,IAEDF,MAAM,CAACG,WAAW,CAACN,OAAO,CAACO,aAAa,CAACN,MAAM,CAACO,UAAU,CAAC,WAAUC,CAAC,EAAEC,KAAK;EAC3E,MAAMC,MAAM,GAAGN,OAAO,CAACO,QAAQ,EAAE,CAACC,SAAS,EAAE;EAC7C,OAAOX,KAAK,CAACY,YAAY,CACvBJ,KAAK,EACLL,OAAO,CAACU,gBAAgB,GAAGd,MAAM,CAACe,IAAI,CAAC,MAAML,MAAM,CAACM,WAAW,EAAE,CAAC,GAAGhB,MAAM,CAACiB,OAAO,CAAC,MAAMP,MAAM,CAACQ,MAAM,EAAE,CAAC,CAC3G;EACD,MAAMC,QAAQ,GAAGnB,MAAM,CAACoB,QAAQ,CAAiDC,MAAM,IAAI;IACzF,MAAMC,MAAM,GAAGZ,MAAM,CAACS,QAAQ,EAAE;IAChC,IAAI,MAAM,IAAIG,MAAM,EAAE;MACpBA,MAAM,CAACC,IAAI,CAAEf,CAAC,IAAKa,MAAM,CAACrB,MAAM,CAACwB,OAAO,CAAChB,CAAC,CAAC,CAAC,EAAGiB,CAAC,IAAKJ,MAAM,CAACrB,MAAM,CAAC0B,IAAI,CAACtB,OAAO,CAACuB,OAAO,CAACF,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/F,CAAC,MAAM;MACLJ,MAAM,CAACrB,MAAM,CAACwB,OAAO,CAACF,MAAM,CAAC,CAAC;IAChC;EACF,CAAC,CAAC;EACF;EACA,OAAOtB,MAAM,CAAC4B,OAAO,CACnBT,QAAQ,EACR,SAASU,IAAIA,CACX;IAAEC,IAAI;IAAEC;EAAK,CAAE;IAEf,IAAID,IAAI,EAAE;MACR,OAAOhC,KAAK,CAACgC,IAAI,EAAE;IACrB,CAAC,MAAM,IAAI,CAACjC,GAAG,CAACmC,uBAAuB,CAACD,KAAK,CAAC,EAAE;MAC9C,OAAO/B,MAAM,CAAC4B,OAAO,CAACT,QAAQ,EAAEU,IAAI,CAAC;IACvC;IACA,OAAO7B,MAAM,CAACwB,OAAO,CAACO,KAAK,CAAC;EAC9B,CAAC,CACF;AACH,CAAC,CAAC,CAAC,CAAC","ignoreList":[]}
|
package/dist/BunTerminal.d.ts
CHANGED
|
@@ -3,13 +3,19 @@ import type { Layer } from "effect/Layer";
|
|
|
3
3
|
import type { Scope } from "effect/Scope";
|
|
4
4
|
import type { Terminal, UserInput } from "effect/Terminal";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Creates a scoped `Terminal` service backed by process stdin/stdout, using the
|
|
7
|
+
* optional predicate to decide when key input should end the input stream.
|
|
8
|
+
*
|
|
7
9
|
* @category constructors
|
|
10
|
+
* @since 4.0.0
|
|
8
11
|
*/
|
|
9
12
|
export declare const make: (shouldQuit?: (input: UserInput) => boolean) => Effect<Terminal, never, Scope>;
|
|
10
13
|
/**
|
|
11
|
-
*
|
|
14
|
+
* Provides the default process-backed `Terminal` service, ending key input on
|
|
15
|
+
* the default quit keys.
|
|
16
|
+
*
|
|
12
17
|
* @category layers
|
|
18
|
+
* @since 4.0.0
|
|
13
19
|
*/
|
|
14
20
|
export declare const layer: Layer<Terminal>;
|
|
15
21
|
//# sourceMappingURL=BunTerminal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunTerminal.d.ts","sourceRoot":"","sources":["../src/BunTerminal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BunTerminal.d.ts","sourceRoot":"","sources":["../src/BunTerminal.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE1D;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAqB,CAAA;AAErH;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAsB,CAAA"}
|
package/dist/BunTerminal.js
CHANGED
|
@@ -1,15 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun-backed implementation of Effect's `Terminal` service.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts Bun's Node-compatible `stdin`, `stdout`, and `readline`
|
|
5
|
+
* support into a scoped `Terminal` service. It is intended for Bun CLIs,
|
|
6
|
+
* prompts, REPLs, and terminal interfaces that need prompt output, line input,
|
|
7
|
+
* keypress input, or terminal dimensions through Effect services.
|
|
8
|
+
*
|
|
9
|
+
* **Mental model**
|
|
10
|
+
*
|
|
11
|
+
* - {@link make} creates a scoped terminal from the current process streams.
|
|
12
|
+
* - {@link layer} provides the default live terminal service for Bun programs.
|
|
13
|
+
* - The implementation reuses the shared Node-compatible terminal adapter, so
|
|
14
|
+
* behavior follows the capabilities of Bun's process streams and readline
|
|
15
|
+
* support.
|
|
16
|
+
*
|
|
17
|
+
* **Common tasks**
|
|
18
|
+
*
|
|
19
|
+
* - Provide terminal access at the edge of a Bun CLI with {@link layer}.
|
|
20
|
+
* - Customize which key ends keypress input by calling {@link make} directly.
|
|
21
|
+
* - Read lines, read keypresses, display prompts, and inspect terminal size
|
|
22
|
+
* through the `Terminal` service once it is provided.
|
|
23
|
+
*
|
|
24
|
+
* **Gotchas**
|
|
25
|
+
*
|
|
26
|
+
* - The service uses global process streams. Acquire it with a scope, or
|
|
27
|
+
* provide {@link layer}, so raw mode and readline listeners are cleaned up.
|
|
28
|
+
* - When `stdin` is a TTY, raw mode is enabled while the terminal is active and
|
|
29
|
+
* restored when the scope closes; this changes how keys are delivered and can
|
|
30
|
+
* affect other stdin consumers.
|
|
31
|
+
* - In pipes, redirected input, or CI, raw mode may be unavailable, keypress
|
|
32
|
+
* input is limited, and stdout dimensions may be reported as zero.
|
|
33
|
+
*
|
|
34
|
+
* @since 4.0.0
|
|
3
35
|
*/
|
|
4
36
|
import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal";
|
|
5
37
|
/**
|
|
6
|
-
*
|
|
38
|
+
* Creates a scoped `Terminal` service backed by process stdin/stdout, using the
|
|
39
|
+
* optional predicate to decide when key input should end the input stream.
|
|
40
|
+
*
|
|
7
41
|
* @category constructors
|
|
42
|
+
* @since 4.0.0
|
|
8
43
|
*/
|
|
9
44
|
export const make = NodeTerminal.make;
|
|
10
45
|
/**
|
|
11
|
-
*
|
|
46
|
+
* Provides the default process-backed `Terminal` service, ending key input on
|
|
47
|
+
* the default quit keys.
|
|
48
|
+
*
|
|
12
49
|
* @category layers
|
|
50
|
+
* @since 4.0.0
|
|
13
51
|
*/
|
|
14
52
|
export const layer = NodeTerminal.layer;
|
|
15
53
|
//# sourceMappingURL=BunTerminal.js.map
|
package/dist/BunTerminal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunTerminal.js","names":["NodeTerminal","make","layer"],"sources":["../src/BunTerminal.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"BunTerminal.js","names":["NodeTerminal","make","layer"],"sources":["../src/BunTerminal.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,OAAO,KAAKA,YAAY,MAAM,2CAA2C;AAMzE;;;;;;;AAOA,OAAO,MAAMC,IAAI,GAAmFD,YAAY,CAACC,IAAI;AAErH;;;;;;;AAOA,OAAO,MAAMC,KAAK,GAAoBF,YAAY,CAACE,KAAK","ignoreList":[]}
|
package/dist/BunWorker.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import * as Layer from "effect/Layer";
|
|
2
2
|
import * as Worker from "effect/unstable/workers/Worker";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Provides the Bun `WorkerPlatform` together with a `Worker.Spawner` created
|
|
5
|
+
* from the supplied worker spawning function.
|
|
6
|
+
*
|
|
5
7
|
* @category layers
|
|
8
|
+
* @since 4.0.0
|
|
6
9
|
*/
|
|
7
10
|
export declare const layer: (spawn: (id: number) => globalThis.Worker) => Layer.Layer<Worker.WorkerPlatform | Worker.Spawner>;
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
12
|
+
* Provides the Bun `WorkerPlatform`, wiring worker messages and errors into
|
|
13
|
+
* Effect workers and requesting graceful worker shutdown during scope
|
|
14
|
+
* finalization before terminating on timeout.
|
|
15
|
+
*
|
|
10
16
|
* @category layers
|
|
17
|
+
* @since 4.0.0
|
|
11
18
|
*/
|
|
12
19
|
export declare const layerPlatform: Layer.Layer<Worker.WorkerPlatform, never, never>;
|
|
13
20
|
//# sourceMappingURL=BunWorker.d.ts.map
|
package/dist/BunWorker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunWorker.d.ts","sourceRoot":"","sources":["../src/BunWorker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BunWorker.d.ts","sourceRoot":"","sources":["../src/BunWorker.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,MAAM,MAAM,gCAAgC,CAAA;AAGxD;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,GAChB,OAAO,CAAC,EAAE,EAAE,MAAM,KAAK,UAAU,CAAC,MAAM,KACvC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,OAAO,CAIlD,CAAA;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,kDAgDzB,CAAA"}
|
package/dist/BunWorker.js
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Parent-side worker support for Bun applications.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the `WorkerPlatform` used by Bun programs that spawn and
|
|
5
|
+
* communicate with `globalThis.Worker` instances through Effect's worker
|
|
6
|
+
* protocol. Pair it with `BunWorkerRunner` in the worker entrypoint when
|
|
7
|
+
* building worker-backed RPC clients, moving CPU-bound work off the main
|
|
8
|
+
* thread, isolating Bun-only services, or hosting long-lived handlers behind a
|
|
9
|
+
* typed message boundary.
|
|
10
|
+
*
|
|
11
|
+
* **Mental model**
|
|
12
|
+
*
|
|
13
|
+
* `layer(spawn)` installs both the Bun `WorkerPlatform` and a `Worker.Spawner`.
|
|
14
|
+
* The supplied `spawn` function creates the Bun worker for each numeric worker
|
|
15
|
+
* id. The platform listens for worker messages and errors, wraps outgoing data
|
|
16
|
+
* in the Effect worker protocol, and buffers `send` calls until the worker
|
|
17
|
+
* runner posts its ready signal.
|
|
18
|
+
*
|
|
19
|
+
* **Common tasks**
|
|
20
|
+
*
|
|
21
|
+
* - Run Effect worker clients in a Bun parent process.
|
|
22
|
+
* - Move RPC handlers, CPU-bound computations, or Bun-only services into a
|
|
23
|
+
* dedicated worker.
|
|
24
|
+
* - Provide custom worker creation logic while keeping message handling and
|
|
25
|
+
* cleanup inside Effect scopes.
|
|
26
|
+
*
|
|
27
|
+
* **Gotchas**
|
|
28
|
+
*
|
|
29
|
+
* This module is for the parent side only; the worker entrypoint must start
|
|
30
|
+
* `BunWorkerRunner`. If the runner never starts or never posts readiness,
|
|
31
|
+
* buffered messages will not be delivered. Payloads and transfer lists use
|
|
32
|
+
* Bun's worker cloning and transfer semantics, so they must be accepted by the
|
|
33
|
+
* Bun worker runtime. Scope finalization sends the Effect worker close signal,
|
|
34
|
+
* waits for Bun's `close` event for a short grace period, and then terminates
|
|
35
|
+
* the worker if graceful shutdown does not complete.
|
|
36
|
+
*
|
|
37
|
+
* @since 4.0.0
|
|
3
38
|
*/
|
|
4
39
|
import * as Deferred from "effect/Deferred";
|
|
5
40
|
import * as Effect from "effect/Effect";
|
|
@@ -9,13 +44,20 @@ import * as Scope from "effect/Scope";
|
|
|
9
44
|
import * as Worker from "effect/unstable/workers/Worker";
|
|
10
45
|
import { WorkerError, WorkerUnknownError } from "effect/unstable/workers/WorkerError";
|
|
11
46
|
/**
|
|
12
|
-
*
|
|
47
|
+
* Provides the Bun `WorkerPlatform` together with a `Worker.Spawner` created
|
|
48
|
+
* from the supplied worker spawning function.
|
|
49
|
+
*
|
|
13
50
|
* @category layers
|
|
51
|
+
* @since 4.0.0
|
|
14
52
|
*/
|
|
15
53
|
export const layer = spawn => Layer.merge(layerPlatform, Layer.succeed(Worker.Spawner)(spawn));
|
|
16
54
|
/**
|
|
17
|
-
*
|
|
55
|
+
* Provides the Bun `WorkerPlatform`, wiring worker messages and errors into
|
|
56
|
+
* Effect workers and requesting graceful worker shutdown during scope
|
|
57
|
+
* finalization before terminating on timeout.
|
|
58
|
+
*
|
|
18
59
|
* @category layers
|
|
60
|
+
* @since 4.0.0
|
|
19
61
|
*/
|
|
20
62
|
export const layerPlatform = /*#__PURE__*/Layer.succeed(Worker.WorkerPlatform)(/*#__PURE__*/Worker.makePlatform()({
|
|
21
63
|
setup({
|
|
@@ -46,7 +88,7 @@ export const layerPlatform = /*#__PURE__*/Layer.succeed(Worker.WorkerPlatform)(/
|
|
|
46
88
|
message: "An error event was emitted",
|
|
47
89
|
cause: event.error ?? event.message
|
|
48
90
|
})
|
|
49
|
-
})
|
|
91
|
+
}));
|
|
50
92
|
}
|
|
51
93
|
port.addEventListener("message", onMessage);
|
|
52
94
|
port.addEventListener("error", onError);
|
package/dist/BunWorker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunWorker.js","names":["Deferred","Effect","Exit","Layer","Scope","Worker","WorkerError","WorkerUnknownError","layer","spawn","merge","layerPlatform","succeed","Spawner","WorkerPlatform","makePlatform","setup","scope","worker","closeDeferred","makeUnsafe","addEventListener","doneUnsafe","void","as","addFinalizer","suspend","postMessage","await","pipe","interruptible","timeout","catchCause","sync","terminate","listen","deferred","emit","port","onMessage","event","data","onError","reason","message","cause","error","
|
|
1
|
+
{"version":3,"file":"BunWorker.js","names":["Deferred","Effect","Exit","Layer","Scope","Worker","WorkerError","WorkerUnknownError","layer","spawn","merge","layerPlatform","succeed","Spawner","WorkerPlatform","makePlatform","setup","scope","worker","closeDeferred","makeUnsafe","addEventListener","doneUnsafe","void","as","addFinalizer","suspend","postMessage","await","pipe","interruptible","timeout","catchCause","sync","terminate","listen","deferred","emit","port","onMessage","event","data","onError","reason","message","cause","error","removeEventListener"],"sources":["../src/BunWorker.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,OAAO,KAAKA,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,gCAAgC;AACxD,SAASC,WAAW,EAAEC,kBAAkB,QAAQ,qCAAqC;AAErF;;;;;;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Q,CAACsB,UAAU,CACjBc,QAAQ,EACR,IAAI9B,WAAW,CAAC;QACdqC,MAAM,EAAE,IAAIpC,kBAAkB,CAAC;UAC7BqC,OAAO,EAAE,4BAA4B;UACrCC,KAAK,EAAEL,KAAK,CAACM,KAAK,IAAIN,KAAK,CAACI;SAC7B;OACF,CAAC,CACH;IACH;IACAN,IAAI,CAACjB,gBAAgB,CAAC,SAAS,EAAEkB,SAAS,CAAC;IAC3CD,IAAI,CAACjB,gBAAgB,CAAC,OAAO,EAAEqB,OAAO,CAAC;IACvC,OAAOtC,KAAK,CAACqB,YAAY,CACvBR,KAAK,EACLhB,MAAM,CAACgC,IAAI,CAAC,MAAK;MACfK,IAAI,CAACS,mBAAmB,CAAC,SAAS,EAAER,SAAS,CAAC;MAC9CD,IAAI,CAACS,mBAAmB,CAAC,OAAO,EAAEL,OAAO,CAAC;IAC5C,CAAC,CAAC,CACH;EACH;CACD,CAAC,CACH","ignoreList":[]}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import * as Layer from "effect/Layer";
|
|
2
2
|
import * as WorkerRunner from "effect/unstable/workers/WorkerRunner";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Provides the `WorkerRunnerPlatform` for code running inside a Bun worker,
|
|
5
|
+
* routing parent messages to the registered handler and sending responses back
|
|
6
|
+
* through the worker port.
|
|
7
|
+
*
|
|
5
8
|
* @category layers
|
|
9
|
+
* @since 4.0.0
|
|
6
10
|
*/
|
|
7
11
|
export declare const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform>;
|
|
8
12
|
//# sourceMappingURL=BunWorkerRunner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunWorkerRunner.d.ts","sourceRoot":"","sources":["../src/BunWorkerRunner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BunWorkerRunner.d.ts","sourceRoot":"","sources":["../src/BunWorkerRunner.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,YAAY,MAAM,sCAAsC,CAAA;AAIpE;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,oBAAoB,CAgF/D,CAAA"}
|
package/dist/BunWorkerRunner.js
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Worker-entrypoint support for Bun worker runners.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the Bun `WorkerRunnerPlatform` for code already running
|
|
5
|
+
* inside a Bun `Worker`. It receives request messages from the parent-side
|
|
6
|
+
* `BunWorker` platform, runs the handler registered with `WorkerRunner.run`,
|
|
7
|
+
* and posts responses back through Bun's worker `postMessage` channel.
|
|
8
|
+
*
|
|
9
|
+
* **Mental model**
|
|
10
|
+
*
|
|
11
|
+
* The parent process installs `BunWorker.layer`; the worker entrypoint installs
|
|
12
|
+
* this `layer` and starts `WorkerRunner`. Bun exposes one worker port to this
|
|
13
|
+
* runner, so every message uses port id `0`. The first message sent by this
|
|
14
|
+
* layer is the ready signal consumed by the parent platform before buffered
|
|
15
|
+
* sends are flushed.
|
|
16
|
+
*
|
|
17
|
+
* **Common tasks**
|
|
18
|
+
*
|
|
19
|
+
* - Host Effect worker or RPC handlers inside a Bun worker entrypoint.
|
|
20
|
+
* - Move CPU-bound work or Bun-only services behind Effect's worker protocol.
|
|
21
|
+
* - Send structured-clone payloads and transferables back to the parent with
|
|
22
|
+
* `WorkerRunner.send`.
|
|
23
|
+
*
|
|
24
|
+
* **Gotchas**
|
|
25
|
+
*
|
|
26
|
+
* Start this layer only in the worker entrypoint; it fails when
|
|
27
|
+
* `self.postMessage` is unavailable. Parent shutdown arrives as the worker
|
|
28
|
+
* close message and closes the port, so long-running handlers should stay
|
|
29
|
+
* interruptible and keep cleanup in scopes. Payloads, transfer lists, and
|
|
30
|
+
* `messageerror` events follow Bun's worker runtime behavior.
|
|
31
|
+
*
|
|
32
|
+
* @see {@link layer} for the Bun worker-runner platform layer.
|
|
33
|
+
*
|
|
34
|
+
* @since 4.0.0
|
|
3
35
|
*/
|
|
4
36
|
import * as Cause from "effect/Cause";
|
|
5
37
|
import * as Deferred from "effect/Deferred";
|
|
@@ -12,8 +44,12 @@ import * as Scope from "effect/Scope";
|
|
|
12
44
|
import { WorkerError, WorkerReceiveError, WorkerSpawnError } from "effect/unstable/workers/WorkerError";
|
|
13
45
|
import * as WorkerRunner from "effect/unstable/workers/WorkerRunner";
|
|
14
46
|
/**
|
|
15
|
-
*
|
|
47
|
+
* Provides the `WorkerRunnerPlatform` for code running inside a Bun worker,
|
|
48
|
+
* routing parent messages to the registered handler and sending responses back
|
|
49
|
+
* through the worker port.
|
|
50
|
+
*
|
|
16
51
|
* @category layers
|
|
52
|
+
* @since 4.0.0
|
|
17
53
|
*/
|
|
18
54
|
export const layer = /*#__PURE__*/Layer.succeed(WorkerRunner.WorkerRunnerPlatform)({
|
|
19
55
|
start: /*#__PURE__*/Effect.fnUntraced(function* () {
|
|
@@ -28,7 +64,7 @@ export const layer = /*#__PURE__*/Layer.succeed(WorkerRunner.WorkerRunnerPlatfor
|
|
|
28
64
|
const run = handler => Effect.scopedWith(Effect.fnUntraced(function* (scope) {
|
|
29
65
|
const closeLatch = Deferred.makeUnsafe();
|
|
30
66
|
const trackFiber = Fiber.runIn(scope);
|
|
31
|
-
const services = yield* Effect.
|
|
67
|
+
const services = yield* Effect.context();
|
|
32
68
|
const runFork = Effect.runForkWith(services);
|
|
33
69
|
const onExit = exit => {
|
|
34
70
|
if (exit._tag === "Failure" && !Cause.hasInterruptsOnly(exit.cause)) {
|
|
@@ -55,7 +91,7 @@ export const layer = /*#__PURE__*/Layer.succeed(WorkerRunner.WorkerRunnerPlatfor
|
|
|
55
91
|
message: "received messageerror event",
|
|
56
92
|
cause: error.data
|
|
57
93
|
})
|
|
58
|
-
})
|
|
94
|
+
}));
|
|
59
95
|
}
|
|
60
96
|
function onError(error) {
|
|
61
97
|
Deferred.doneUnsafe(closeLatch, new WorkerError({
|
|
@@ -63,7 +99,7 @@ export const layer = /*#__PURE__*/Layer.succeed(WorkerRunner.WorkerRunnerPlatfor
|
|
|
63
99
|
message: "received error event",
|
|
64
100
|
cause: error.data
|
|
65
101
|
})
|
|
66
|
-
})
|
|
102
|
+
}));
|
|
67
103
|
}
|
|
68
104
|
yield* Scope.addFinalizer(scope, Effect.sync(() => {
|
|
69
105
|
port.removeEventListener("message", onMessage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunWorkerRunner.js","names":["Cause","Deferred","Effect","Exit","Fiber","identity","Layer","Scope","WorkerError","WorkerReceiveError","WorkerSpawnError","WorkerRunner","layer","succeed","WorkerRunnerPlatform","start","fnUntraced","self","reason","message","port","run","handler","scopedWith","scope","closeLatch","makeUnsafe","trackFiber","runIn","services","runFork","runForkWith","onExit","exit","_tag","hasInterruptsOnly","cause","logError","onMessage","event","data","result","isEffect","fiber","addObserver","close","doneUnsafe","void","onMessageError","error","
|
|
1
|
+
{"version":3,"file":"BunWorkerRunner.js","names":["Cause","Deferred","Effect","Exit","Fiber","identity","Layer","Scope","WorkerError","WorkerReceiveError","WorkerSpawnError","WorkerRunner","layer","succeed","WorkerRunnerPlatform","start","fnUntraced","self","reason","message","port","run","handler","scopedWith","scope","closeLatch","makeUnsafe","trackFiber","runIn","services","context","runFork","runForkWith","onExit","exit","_tag","hasInterruptsOnly","cause","logError","onMessage","event","data","result","isEffect","fiber","addObserver","close","doneUnsafe","void","onMessageError","error","onError","addFinalizer","sync","removeEventListener","addEventListener","postMessage","await","sendUnsafe","_portId","transfer","send"],"sources":["../src/BunWorkerRunner.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,O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