@effect/platform-bun 4.0.0-beta.99 → 4.0.0-rc.109
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/AGENTS.md +395 -0
- package/CLAUDE.md +395 -0
- package/README.md +10 -3
- package/ai-docs/README.md +44 -0
- package/ai-docs/package.json +36 -0
- package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +39 -0
- package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
- package/ai-docs/src/01_effect/01_basics/index.md +5 -0
- package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
- package/ai-docs/src/01_effect/02_schema/index.md +7 -0
- package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
- package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
- package/ai-docs/src/01_effect/03_services/index.md +5 -0
- package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
- package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
- package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
- package/ai-docs/src/01_effect/04_errors/index.md +1 -0
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
- package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
- package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
- package/ai-docs/src/01_effect/05_resources/index.md +3 -0
- package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
- package/ai-docs/src/01_effect/06_running/index.md +1 -0
- package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
- package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
- package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
- package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
- package/ai-docs/src/03_stream/30_encoding.ts +165 -0
- package/ai-docs/src/03_stream/index.md +4 -0
- package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
- package/ai-docs/src/04_integration/index.md +5 -0
- package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
- package/ai-docs/src/05_batching/index.md +3 -0
- package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
- package/ai-docs/src/06_schedule/index.md +3 -0
- package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
- package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
- package/ai-docs/src/07_datetime/index.md +5 -0
- package/ai-docs/src/08_observability/10_logging.ts +66 -0
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
- package/ai-docs/src/08_observability/index.md +7 -0
- package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
- package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
- package/ai-docs/src/09_testing/index.md +1 -0
- package/ai-docs/src/10_predicate/01_basics.ts +14 -0
- package/ai-docs/src/10_predicate/index.md +9 -0
- package/ai-docs/src/40_sql/10_basics.ts +175 -0
- package/ai-docs/src/40_sql/index.md +6 -0
- package/ai-docs/src/50_http-client/10_basics.ts +102 -0
- package/ai-docs/src/50_http-client/index.md +3 -0
- package/ai-docs/src/51_http-server/10_basics.ts +118 -0
- package/ai-docs/src/51_http-server/20_testing.ts +100 -0
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +107 -0
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +21 -0
- package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
- package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +37 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +80 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +183 -0
- package/ai-docs/src/51_http-server/index.md +3 -0
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
- package/ai-docs/src/60_child-process/index.md +3 -0
- package/ai-docs/src/70_cli/10_basics.ts +160 -0
- package/ai-docs/src/70_cli/index.md +5 -0
- package/ai-docs/src/71_ai/10_language-model.ts +156 -0
- package/ai-docs/src/71_ai/20_tools.ts +226 -0
- package/ai-docs/src/71_ai/30_chat.ts +158 -0
- package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
- package/ai-docs/src/71_ai/index.md +5 -0
- package/ai-docs/src/80_cluster/10_entities.ts +97 -0
- package/ai-docs/src/80_cluster/index.md +4 -0
- package/ai-docs/src/index.md +10 -0
- package/ai-docs/tsconfig.json +24 -0
- package/dist/BunClusterHttp.d.ts +1 -0
- package/dist/BunClusterHttp.d.ts.map +1 -1
- package/dist/BunClusterHttp.js +6 -1
- package/dist/BunClusterHttp.js.map +1 -1
- package/dist/BunClusterSocket.d.ts +1 -0
- package/dist/BunClusterSocket.d.ts.map +1 -1
- package/dist/BunClusterSocket.js +6 -1
- package/dist/BunClusterSocket.js.map +1 -1
- package/dist/BunCrypto.js.map +1 -1
- package/dist/BunFileSystem.js.map +1 -1
- package/dist/BunHttpPlatform.d.ts.map +1 -1
- package/dist/BunHttpPlatform.js +25 -2
- package/dist/BunHttpPlatform.js.map +1 -1
- package/dist/BunHttpServer.d.ts +20 -1
- package/dist/BunHttpServer.d.ts.map +1 -1
- package/dist/BunHttpServer.js +7 -6
- package/dist/BunHttpServer.js.map +1 -1
- package/dist/BunHttpServerRequest.js.map +1 -1
- package/dist/BunMultipart.d.ts.map +1 -1
- package/dist/BunMultipart.js +6 -7
- package/dist/BunMultipart.js.map +1 -1
- package/dist/BunPath.js.map +1 -1
- package/dist/BunRedis.js.map +1 -1
- package/dist/BunRuntime.js.map +1 -1
- package/dist/BunServices.js.map +1 -1
- package/dist/BunSocket.js.map +1 -1
- package/dist/BunStdio.js.map +1 -1
- package/dist/BunStream.js.map +1 -1
- package/dist/BunTerminal.js.map +1 -1
- package/dist/BunWorker.js.map +1 -1
- package/dist/BunWorkerRunner.d.ts.map +1 -1
- package/dist/BunWorkerRunner.js +1 -9
- package/dist/BunWorkerRunner.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -9
- package/src/BunClusterHttp.ts +6 -2
- package/src/BunClusterSocket.ts +6 -2
- package/src/BunHttpPlatform.ts +18 -3
- package/src/BunHttpServer.ts +32 -7
- package/src/BunMultipart.ts +7 -8
- package/src/BunWorkerRunner.ts +1 -12
package/dist/BunWorkerRunner.js
CHANGED
|
@@ -69,17 +69,9 @@ export const layer = /*#__PURE__*/Layer.succeed(WorkerRunner.WorkerRunnerPlatfor
|
|
|
69
69
|
})
|
|
70
70
|
}));
|
|
71
71
|
}
|
|
72
|
-
function onError(error) {
|
|
73
|
-
Deferred.doneUnsafe(closeLatch, new WorkerError({
|
|
74
|
-
reason: new WorkerReceiveError({
|
|
75
|
-
message: "received error event",
|
|
76
|
-
cause: error.data
|
|
77
|
-
})
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
72
|
yield* Scope.addFinalizer(scope, Effect.sync(() => {
|
|
81
73
|
port.removeEventListener("message", onMessage);
|
|
82
|
-
port.removeEventListener("messageerror",
|
|
74
|
+
port.removeEventListener("messageerror", onMessageError);
|
|
83
75
|
}));
|
|
84
76
|
port.addEventListener("message", onMessage);
|
|
85
77
|
port.addEventListener("messageerror", onMessageError);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BunWorkerRunner.js","names":[
|
|
1
|
+
{"version":3,"file":"BunWorkerRunner.js","names":[],"sources":["../src/BunWorkerRunner.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;AAWA,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,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C,CAAC;IAEL,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,OAAU,EAAE,QAAiC,KAChF,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE;MAC7B,QAAQ,EAAE;KACX,CAAC;IACJ,MAAM,IAAI,GAAG,CAAC,OAAe,EAAE,OAAU,EAAE,QAAiC,KAC1E,MAAM,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrD,OAAO,QAAQ,CAAsC;MAAE,GAAG;MAAE,IAAI;MAAE;IAAU,CAAE,CAAC;EACjF,CAAC;CACF,CAAC","ignoreList":[]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;AAGA,OAAO,KAAK,sBAAsB,MAAM,6BAA6B;AAErE;;;AAGA,OAAO,KAAK,cAAc,MAAM,qBAAqB;AAErD;;;AAGA,OAAO,KAAK,gBAAgB,MAAM,uBAAuB;AAEzD;;;AAGA,OAAO,KAAK,SAAS,MAAM,gBAAgB;AAE3C;;;AAGA,OAAO,KAAK,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAK,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAK,eAAe,MAAM,sBAAsB;AAEvD;;;AAGA,OAAO,KAAK,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAK,oBAAoB,MAAM,2BAA2B;AAEjE;;;AAGA,OAAO,KAAK,YAAY,MAAM,mBAAmB;AAEjD;;;AAGA,OAAO,KAAK,OAAO,MAAM,cAAc;AAEvC;;;AAGA,OAAO,KAAK,QAAQ,MAAM,eAAe;AAEzC;;;AAGA,OAAO,KAAK,UAAU,MAAM,iBAAiB;AAE7C;;;AAGA,OAAO,KAAK,WAAW,MAAM,kBAAkB;AAE/C;;;AAGA,OAAO,KAAK,OAAO,MAAM,cAAc;AAEvC;;;AAGA,OAAO,KAAK,SAAS,MAAM,gBAAgB;AAE3C;;;AAGA,OAAO,KAAK,eAAe,MAAM,sBAAsB;AAEvD;;;AAGA,OAAO,KAAK,QAAQ,MAAM,eAAe;AAEzC;;;AAGA,OAAO,KAAK,SAAS,MAAM,gBAAgB;AAE3C;;;AAGA,OAAO,KAAK,WAAW,MAAM,kBAAkB;AAE/C;;;AAGA,OAAO,KAAK,SAAS,MAAM,gBAAgB;AAE3C;;;AAGA,OAAO,KAAK,eAAe,MAAM,sBAAsB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/platform-bun",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-
|
|
4
|
+
"version": "4.0.0-rc.109",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Platform specific implementations for the Bun runtime",
|
|
7
7
|
"homepage": "https://effect.website",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/Effect-TS/effect.git",
|
|
11
|
-
"directory": "packages/platform
|
|
11
|
+
"directory": "packages/platform/bun"
|
|
12
12
|
},
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/Effect-TS/effect/issues"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
".": "./dist/index.js",
|
|
32
32
|
"./*": "./dist/*.js",
|
|
33
33
|
"./internal/*": null,
|
|
34
|
+
"./index": null,
|
|
34
35
|
"./*/index": null
|
|
35
36
|
},
|
|
36
37
|
"files": [
|
|
@@ -38,28 +39,29 @@
|
|
|
38
39
|
"dist/**/*.js",
|
|
39
40
|
"dist/**/*.js.map",
|
|
40
41
|
"dist/**/*.d.ts",
|
|
41
|
-
"dist/**/*.d.ts.map"
|
|
42
|
+
"dist/**/*.d.ts.map",
|
|
43
|
+
"AGENTS.md",
|
|
44
|
+
"CLAUDE.md",
|
|
45
|
+
"ai-docs/**/*"
|
|
42
46
|
],
|
|
43
47
|
"publishConfig": {
|
|
44
48
|
"access": "public",
|
|
45
49
|
"provenance": true
|
|
46
50
|
},
|
|
47
51
|
"peerDependencies": {
|
|
48
|
-
"effect": "^4.0.0-
|
|
52
|
+
"effect": "^4.0.0-rc.109"
|
|
49
53
|
},
|
|
50
54
|
"dependencies": {
|
|
51
|
-
"@effect/platform-node-shared": "^4.0.0-
|
|
55
|
+
"@effect/platform-node-shared": "^4.0.0-rc.109"
|
|
52
56
|
},
|
|
53
57
|
"devDependencies": {
|
|
54
58
|
"@types/bun": "^1.3.14",
|
|
55
|
-
"effect": "^4.0.0-
|
|
59
|
+
"effect": "^4.0.0-rc.109"
|
|
56
60
|
},
|
|
57
61
|
"scripts": {
|
|
58
62
|
"codegen": "effect-utils codegen",
|
|
59
63
|
"build": "tsc -b tsconfig.json && pnpm babel",
|
|
60
64
|
"babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
|
|
61
|
-
"check": "tsc -b tsconfig.json"
|
|
62
|
-
"test": "vitest",
|
|
63
|
-
"coverage": "vitest --coverage"
|
|
65
|
+
"check": "tsc -b tsconfig.json"
|
|
64
66
|
}
|
|
65
67
|
}
|
package/src/BunClusterHttp.ts
CHANGED
|
@@ -29,6 +29,7 @@ import type { ServeError } from "effect/unstable/http/HttpServerError"
|
|
|
29
29
|
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization"
|
|
30
30
|
import type { SqlClient } from "effect/unstable/sql/SqlClient"
|
|
31
31
|
import { layerK8sHttpClient } from "./BunClusterSocket.ts"
|
|
32
|
+
import * as BunCrypto from "./BunCrypto.ts"
|
|
32
33
|
import * as BunFileSystem from "./BunFileSystem.ts"
|
|
33
34
|
import * as BunHttpServer from "./BunHttpServer.ts"
|
|
34
35
|
import type { BunServices } from "./BunServices.ts"
|
|
@@ -102,6 +103,7 @@ export const layer = <
|
|
|
102
103
|
>(options: {
|
|
103
104
|
readonly transport: "http" | "websocket"
|
|
104
105
|
readonly serialization?: "msgpack" | "ndjson" | undefined
|
|
106
|
+
readonly serializationMaxBufferSize?: number | "unbounded" | undefined
|
|
105
107
|
readonly clientOnly?: ClientOnly | undefined
|
|
106
108
|
readonly storage?: Storage | undefined
|
|
107
109
|
readonly runnerHealth?: "ping" | "k8s" | undefined
|
|
@@ -157,7 +159,7 @@ export const layer = <
|
|
|
157
159
|
? MessageStorage.layerNoop
|
|
158
160
|
: options?.storage === "byo"
|
|
159
161
|
? Layer.empty
|
|
160
|
-
: Layer.orDie(SqlMessageStorage.layer)
|
|
162
|
+
: Layer.orDie(SqlMessageStorage.layer).pipe(Layer.provide(BunCrypto.layer))
|
|
161
163
|
),
|
|
162
164
|
Layer.provide(
|
|
163
165
|
options?.storage === "local"
|
|
@@ -168,7 +170,9 @@ export const layer = <
|
|
|
168
170
|
),
|
|
169
171
|
Layer.provide(ShardingConfig.layerFromEnv(options?.shardingConfig)),
|
|
170
172
|
Layer.provide(
|
|
171
|
-
options?.serialization === "ndjson"
|
|
173
|
+
options?.serialization === "ndjson"
|
|
174
|
+
? RpcSerialization.layerNdjsonWith({ maxBufferSize: options.serializationMaxBufferSize })
|
|
175
|
+
: RpcSerialization.layerMsgPackWith({ maxBufferSize: options.serializationMaxBufferSize })
|
|
172
176
|
)
|
|
173
177
|
) as any
|
|
174
178
|
}
|
package/src/BunClusterSocket.ts
CHANGED
|
@@ -28,6 +28,7 @@ import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient"
|
|
|
28
28
|
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization"
|
|
29
29
|
import type * as SocketServer from "effect/unstable/socket/SocketServer"
|
|
30
30
|
import type { SqlClient } from "effect/unstable/sql/SqlClient"
|
|
31
|
+
import * as BunCrypto from "./BunCrypto.ts"
|
|
31
32
|
import * as BunFileSystem from "./BunFileSystem.ts"
|
|
32
33
|
|
|
33
34
|
export {
|
|
@@ -61,6 +62,7 @@ export const layer = <
|
|
|
61
62
|
>(
|
|
62
63
|
options?: {
|
|
63
64
|
readonly serialization?: "msgpack" | "ndjson" | undefined
|
|
65
|
+
readonly serializationMaxBufferSize?: number | "unbounded" | undefined
|
|
64
66
|
readonly clientOnly?: ClientOnly | undefined
|
|
65
67
|
readonly storage?: Storage | undefined
|
|
66
68
|
readonly runnerHealth?: "ping" | "k8s" | undefined
|
|
@@ -109,7 +111,7 @@ export const layer = <
|
|
|
109
111
|
? MessageStorage.layerNoop
|
|
110
112
|
: options?.storage === "byo"
|
|
111
113
|
? Layer.empty
|
|
112
|
-
: Layer.orDie(SqlMessageStorage.layer)
|
|
114
|
+
: Layer.orDie(SqlMessageStorage.layer).pipe(Layer.provide(BunCrypto.layer))
|
|
113
115
|
),
|
|
114
116
|
Layer.provide(
|
|
115
117
|
options?.storage === "local"
|
|
@@ -120,7 +122,9 @@ export const layer = <
|
|
|
120
122
|
),
|
|
121
123
|
Layer.provide(ShardingConfig.layerFromEnv(options?.shardingConfig)),
|
|
122
124
|
Layer.provide(
|
|
123
|
-
options?.serialization === "ndjson"
|
|
125
|
+
options?.serialization === "ndjson"
|
|
126
|
+
? RpcSerialization.layerNdjsonWith({ maxBufferSize: options?.serializationMaxBufferSize })
|
|
127
|
+
: RpcSerialization.layerMsgPackWith({ maxBufferSize: options?.serializationMaxBufferSize })
|
|
124
128
|
)
|
|
125
129
|
) as any
|
|
126
130
|
}
|
package/src/BunHttpPlatform.ts
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @since 4.0.0
|
|
11
11
|
*/
|
|
12
|
-
import
|
|
12
|
+
import * as NodeHttpCompression from "@effect/platform-node-shared/NodeHttpCompression"
|
|
13
|
+
import type * as Effect from "effect/Effect"
|
|
13
14
|
import type { FileSystem } from "effect/FileSystem"
|
|
14
15
|
import * as Layer from "effect/Layer"
|
|
15
16
|
import * as Etag from "effect/unstable/http/Etag"
|
|
@@ -17,6 +18,13 @@ import * as Platform from "effect/unstable/http/HttpPlatform"
|
|
|
17
18
|
import * as Response from "effect/unstable/http/HttpServerResponse"
|
|
18
19
|
import * as BunFileSystem from "./BunFileSystem.ts"
|
|
19
20
|
|
|
21
|
+
// Bun's CompressionStream supports an extended format set covering brotli and
|
|
22
|
+
// zstd
|
|
23
|
+
const compression = NodeHttpCompression.make(Platform.makeCompressionWeb({
|
|
24
|
+
algorithms: ["gzip", "deflate", "br", "zstd"],
|
|
25
|
+
transform: (algorithm) => Platform.compressionTransformWeb(algorithm === "br" ? "brotli" : algorithm)
|
|
26
|
+
}))
|
|
27
|
+
|
|
20
28
|
/**
|
|
21
29
|
* @category constructors
|
|
22
30
|
* @since 4.0.0
|
|
@@ -26,6 +34,8 @@ const make: Effect.Effect<
|
|
|
26
34
|
never,
|
|
27
35
|
FileSystem | Etag.Generator
|
|
28
36
|
> = Platform.make({
|
|
37
|
+
platform: "bun",
|
|
38
|
+
compression,
|
|
29
39
|
fileResponse(path, status, statusText, headers, start, end, _contentLength) {
|
|
30
40
|
let file = Bun.file(path)
|
|
31
41
|
if (start > 0 || end !== undefined) {
|
|
@@ -33,8 +43,13 @@ const make: Effect.Effect<
|
|
|
33
43
|
}
|
|
34
44
|
return Response.raw(file, { headers, status, statusText })
|
|
35
45
|
},
|
|
36
|
-
fileWebResponse(file, status, statusText, headers,
|
|
37
|
-
|
|
46
|
+
fileWebResponse(file, status, statusText, headers, options) {
|
|
47
|
+
const start = Number(options?.offset ?? 0)
|
|
48
|
+
const end = options?.bytesToRead !== undefined ? start + Number(options.bytesToRead) : undefined
|
|
49
|
+
const body = start > 0 || end !== undefined
|
|
50
|
+
? (file as File).slice(start, end, file.type)
|
|
51
|
+
: file
|
|
52
|
+
return Response.raw(body, { headers, status, statusText })
|
|
38
53
|
}
|
|
39
54
|
})
|
|
40
55
|
|
package/src/BunHttpServer.ts
CHANGED
|
@@ -66,6 +66,25 @@ export type ServeOptions<R extends string> =
|
|
|
66
66
|
)
|
|
67
67
|
& { readonly routes?: Bun.Serve.Routes<WebSocketContext, R> }
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* WebSocket tuning options forwarded to `Bun.serve`'s `websocket` handler.
|
|
71
|
+
*
|
|
72
|
+
* **Details**
|
|
73
|
+
*
|
|
74
|
+
* The lifecycle handlers (`open`, `message`, `close`, ...) are managed by the
|
|
75
|
+
* server and cannot be overridden; everything else — such as
|
|
76
|
+
* `perMessageDeflate` compression, payload limits, and idle timeouts — passes
|
|
77
|
+
* through, e.g.
|
|
78
|
+
* `BunHttpServer.layer({ port: 3000, websocket: { perMessageDeflate: true } })`.
|
|
79
|
+
*
|
|
80
|
+
* @category options
|
|
81
|
+
* @since 4.0.0
|
|
82
|
+
*/
|
|
83
|
+
export type WebSocketOptions = Omit<
|
|
84
|
+
Bun.WebSocketHandler<WebSocketContext>,
|
|
85
|
+
"open" | "message" | "close" | "drain" | "ping" | "pong" | "data" | "binaryType"
|
|
86
|
+
>
|
|
87
|
+
|
|
69
88
|
/**
|
|
70
89
|
* Creates a scoped Bun `HttpServer` from `Bun.serve` options, stopping the server on scope finalization with optional graceful shutdown settings.
|
|
71
90
|
*
|
|
@@ -77,6 +96,7 @@ export const make = Effect.fnUntraced(
|
|
|
77
96
|
options: ServeOptions<R> & {
|
|
78
97
|
readonly disablePreemptiveShutdown?: boolean | undefined
|
|
79
98
|
readonly gracefulShutdownTimeout?: Duration.Input | undefined
|
|
99
|
+
readonly websocket?: WebSocketOptions | undefined
|
|
80
100
|
}
|
|
81
101
|
) {
|
|
82
102
|
const scope = yield* Effect.scope
|
|
@@ -90,6 +110,7 @@ export const make = Effect.fnUntraced(
|
|
|
90
110
|
...options as ServeOptions<R>,
|
|
91
111
|
fetch: handlerStack[0],
|
|
92
112
|
websocket: {
|
|
113
|
+
...options.websocket,
|
|
93
114
|
open(ws) {
|
|
94
115
|
Deferred.doneUnsafe(ws.data.deferred, Exit.succeed(ws))
|
|
95
116
|
},
|
|
@@ -137,12 +158,12 @@ export const make = Effect.fnUntraced(
|
|
|
137
158
|
|
|
138
159
|
function handler(request: Request, server: BunServer<WebSocketContext>) {
|
|
139
160
|
return new Promise<Response>((resolve, _reject) => {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
ServerRequest.HttpServerRequest
|
|
161
|
+
const context = Context.add(
|
|
162
|
+
services,
|
|
163
|
+
ServerRequest.HttpServerRequest,
|
|
143
164
|
new BunServerRequest(request, resolve, removeHost(request.url), server)
|
|
144
165
|
)
|
|
145
|
-
const fiber = Fiber.runIn(Effect.runForkWith(
|
|
166
|
+
const fiber = Fiber.runIn(Effect.runForkWith(context)(httpEffect), scope)
|
|
146
167
|
request.signal.addEventListener("abort", () => {
|
|
147
168
|
fiber.interruptUnsafe(parent.id, Error.ClientAbort.annotation)
|
|
148
169
|
}, { once: true })
|
|
@@ -150,9 +171,10 @@ export const make = Effect.fnUntraced(
|
|
|
150
171
|
}
|
|
151
172
|
|
|
152
173
|
yield* Scope.addFinalizerExit(serveScope, () => {
|
|
153
|
-
handlerStack.
|
|
174
|
+
const index = handlerStack.indexOf(handler)
|
|
175
|
+
if (index !== -1) handlerStack.splice(index, 1)
|
|
154
176
|
server.reload({ fetch: handlerStack[handlerStack.length - 1] })
|
|
155
|
-
return preemptiveShutdown
|
|
177
|
+
return handlerStack.length === 1 ? preemptiveShutdown : Effect.void
|
|
156
178
|
})
|
|
157
179
|
handlerStack.push(handler)
|
|
158
180
|
server.reload({ fetch: handler })
|
|
@@ -233,6 +255,7 @@ export const layerServer: <R extends string>(
|
|
|
233
255
|
options: ServeOptions<R> & {
|
|
234
256
|
readonly disablePreemptiveShutdown?: boolean | undefined
|
|
235
257
|
readonly gracefulShutdownTimeout?: Duration.Input | undefined
|
|
258
|
+
readonly websocket?: WebSocketOptions | undefined
|
|
236
259
|
}
|
|
237
260
|
) => Layer.Layer<Server.HttpServer> = flow(make, Layer.effect(Server.HttpServer)) as any
|
|
238
261
|
|
|
@@ -262,6 +285,7 @@ export const layer = <R extends string>(
|
|
|
262
285
|
options: ServeOptions<R> & {
|
|
263
286
|
readonly disablePreemptiveShutdown?: boolean | undefined
|
|
264
287
|
readonly gracefulShutdownTimeout?: Duration.Input | undefined
|
|
288
|
+
readonly websocket?: WebSocketOptions | undefined
|
|
265
289
|
}
|
|
266
290
|
): Layer.Layer<
|
|
267
291
|
| Server.HttpServer
|
|
@@ -273,7 +297,7 @@ export const layer = <R extends string>(
|
|
|
273
297
|
/**
|
|
274
298
|
* Layer that starts a Bun HTTP server on an ephemeral port for tests.
|
|
275
299
|
*
|
|
276
|
-
* @category
|
|
300
|
+
* @category testing
|
|
277
301
|
* @since 4.0.0
|
|
278
302
|
*/
|
|
279
303
|
export const layerTest: Layer.Layer<
|
|
@@ -296,6 +320,7 @@ export const layerConfig = <R extends string>(
|
|
|
296
320
|
ServeOptions<R> & {
|
|
297
321
|
readonly disablePreemptiveShutdown?: boolean | undefined
|
|
298
322
|
readonly gracefulShutdownTimeout?: Duration.Input | undefined
|
|
323
|
+
readonly websocket?: WebSocketOptions | undefined
|
|
299
324
|
}
|
|
300
325
|
>
|
|
301
326
|
): Layer.Layer<
|
package/src/BunMultipart.ts
CHANGED
|
@@ -24,19 +24,18 @@ import * as BunStream from "./BunStream.ts"
|
|
|
24
24
|
*/
|
|
25
25
|
export const stream = (source: Request): Stream.Stream<Multipart.Part, Multipart.MultipartError> =>
|
|
26
26
|
BunStream.fromReadableStream({
|
|
27
|
-
evaluate: () =>
|
|
27
|
+
evaluate: () =>
|
|
28
|
+
source.body ?? new ReadableStream({
|
|
29
|
+
start(controller) {
|
|
30
|
+
controller.enqueue(new Uint8Array())
|
|
31
|
+
controller.close()
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
28
34
|
onError: (cause) => Multipart.MultipartError.fromReason("InternalError", cause)
|
|
29
35
|
}).pipe(
|
|
30
36
|
Stream.pipeThroughChannel(Multipart.makeChannel(Object.fromEntries(source.headers)))
|
|
31
37
|
)
|
|
32
38
|
|
|
33
|
-
const emptyReadbleStream = new ReadableStream({
|
|
34
|
-
start(controller) {
|
|
35
|
-
controller.enqueue(new Uint8Array())
|
|
36
|
-
controller.close()
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
|
|
40
39
|
/**
|
|
41
40
|
* Parses and persists multipart data from a Bun `Request`, requiring file-system, path, and scope services.
|
|
42
41
|
*
|
package/src/BunWorkerRunner.ts
CHANGED
|
@@ -77,22 +77,11 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
77
77
|
})
|
|
78
78
|
)
|
|
79
79
|
}
|
|
80
|
-
function onError(error: MessageEvent) {
|
|
81
|
-
Deferred.doneUnsafe(
|
|
82
|
-
closeLatch,
|
|
83
|
-
new WorkerError({
|
|
84
|
-
reason: new WorkerReceiveError({
|
|
85
|
-
message: "received error event",
|
|
86
|
-
cause: error.data
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
80
|
yield* Scope.addFinalizer(
|
|
92
81
|
scope,
|
|
93
82
|
Effect.sync(() => {
|
|
94
83
|
port.removeEventListener("message", onMessage)
|
|
95
|
-
port.removeEventListener("messageerror",
|
|
84
|
+
port.removeEventListener("messageerror", onMessageError)
|
|
96
85
|
})
|
|
97
86
|
)
|
|
98
87
|
port.addEventListener("message", onMessage)
|