@effect/platform-node 4.0.0-beta.66 → 4.0.0-beta.68
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/Mime.d.ts +3 -3
- package/dist/Mime.js +3 -3
- package/dist/NodeChildProcessSpawner.d.ts +1 -1
- package/dist/NodeChildProcessSpawner.js +1 -1
- package/dist/NodeClusterHttp.d.ts +47 -7
- package/dist/NodeClusterHttp.d.ts.map +1 -1
- package/dist/NodeClusterHttp.js +13 -6
- package/dist/NodeClusterHttp.js.map +1 -1
- package/dist/NodeClusterSocket.d.ts +51 -11
- package/dist/NodeClusterSocket.d.ts.map +1 -1
- package/dist/NodeClusterSocket.js +51 -11
- package/dist/NodeClusterSocket.js.map +1 -1
- package/dist/NodeCrypto.d.ts +10 -0
- package/dist/NodeCrypto.d.ts.map +1 -0
- package/dist/NodeCrypto.js +14 -0
- package/dist/NodeCrypto.js.map +1 -0
- package/dist/NodeFileSystem.d.ts +4 -2
- package/dist/NodeFileSystem.d.ts.map +1 -1
- package/dist/NodeFileSystem.js +22 -3
- package/dist/NodeFileSystem.js.map +1 -1
- package/dist/NodeHttpClient.d.ts +91 -19
- package/dist/NodeHttpClient.d.ts.map +1 -1
- package/dist/NodeHttpClient.js +91 -19
- package/dist/NodeHttpClient.js.map +1 -1
- package/dist/NodeHttpIncomingMessage.d.ts +22 -4
- package/dist/NodeHttpIncomingMessage.d.ts.map +1 -1
- package/dist/NodeHttpIncomingMessage.js +22 -4
- package/dist/NodeHttpIncomingMessage.js.map +1 -1
- package/dist/NodeHttpPlatform.d.ts +10 -4
- package/dist/NodeHttpPlatform.d.ts.map +1 -1
- package/dist/NodeHttpPlatform.js +32 -5
- package/dist/NodeHttpPlatform.js.map +1 -1
- package/dist/NodeHttpServer.d.ts +39 -12
- package/dist/NodeHttpServer.d.ts.map +1 -1
- package/dist/NodeHttpServer.js +69 -13
- package/dist/NodeHttpServer.js.map +1 -1
- package/dist/NodeHttpServerRequest.d.ts +29 -3
- package/dist/NodeHttpServerRequest.d.ts.map +1 -1
- package/dist/NodeHttpServerRequest.js +9 -2
- package/dist/NodeHttpServerRequest.js.map +1 -1
- package/dist/NodeMultipart.d.ts +32 -4
- package/dist/NodeMultipart.d.ts.map +1 -1
- package/dist/NodeMultipart.js +32 -4
- package/dist/NodeMultipart.js.map +1 -1
- package/dist/NodePath.d.ts +15 -6
- package/dist/NodePath.d.ts.map +1 -1
- package/dist/NodePath.js +30 -7
- package/dist/NodePath.js.map +1 -1
- package/dist/NodeRedis.d.ts +36 -7
- package/dist/NodeRedis.d.ts.map +1 -1
- package/dist/NodeRedis.js +36 -7
- package/dist/NodeRedis.js.map +1 -1
- package/dist/NodeRuntime.d.ts +6 -6
- package/dist/NodeRuntime.d.ts.map +1 -1
- package/dist/NodeRuntime.js +17 -3
- package/dist/NodeRuntime.js.map +1 -1
- package/dist/NodeServices.d.ts +29 -5
- package/dist/NodeServices.d.ts.map +1 -1
- package/dist/NodeServices.js +7 -3
- package/dist/NodeServices.js.map +1 -1
- package/dist/NodeSink.d.ts +2 -2
- package/dist/NodeSink.js +2 -2
- package/dist/NodeSocket.d.ts +14 -4
- package/dist/NodeSocket.d.ts.map +1 -1
- package/dist/NodeSocket.js +32 -5
- package/dist/NodeSocket.js.map +1 -1
- package/dist/NodeSocketServer.d.ts +2 -2
- package/dist/NodeSocketServer.js +2 -2
- package/dist/NodeStdio.d.ts +5 -2
- package/dist/NodeStdio.d.ts.map +1 -1
- package/dist/NodeStdio.js +22 -3
- package/dist/NodeStdio.js.map +1 -1
- package/dist/NodeStream.d.ts +2 -2
- package/dist/NodeStream.js +2 -2
- package/dist/NodeTerminal.d.ts +8 -2
- package/dist/NodeTerminal.d.ts.map +1 -1
- package/dist/NodeTerminal.js +19 -3
- package/dist/NodeTerminal.js.map +1 -1
- package/dist/NodeWorker.d.ts +9 -2
- package/dist/NodeWorker.d.ts.map +1 -1
- package/dist/NodeWorker.js +28 -3
- package/dist/NodeWorker.js.map +1 -1
- package/dist/NodeWorkerRunner.d.ts +5 -1
- package/dist/NodeWorkerRunner.d.ts.map +1 -1
- package/dist/NodeWorkerRunner.js +24 -2
- package/dist/NodeWorkerRunner.js.map +1 -1
- package/dist/Undici.d.ts +3 -3
- package/dist/Undici.js +3 -3
- package/dist/index.d.ts +376 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +376 -24
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/Mime.ts +3 -3
- package/src/NodeChildProcessSpawner.ts +1 -1
- package/src/NodeClusterHttp.ts +47 -7
- package/src/NodeClusterSocket.ts +51 -11
- package/src/NodeCrypto.ts +16 -0
- package/src/NodeFileSystem.ts +22 -3
- package/src/NodeHttpClient.ts +91 -19
- package/src/NodeHttpIncomingMessage.ts +22 -4
- package/src/NodeHttpPlatform.ts +32 -5
- package/src/NodeHttpServer.ts +69 -13
- package/src/NodeHttpServerRequest.ts +29 -3
- package/src/NodeMultipart.ts +32 -4
- package/src/NodePath.ts +30 -7
- package/src/NodeRedis.ts +36 -7
- package/src/NodeRuntime.ts +21 -7
- package/src/NodeServices.ts +31 -5
- package/src/NodeSink.ts +2 -2
- package/src/NodeSocket.ts +32 -5
- package/src/NodeSocketServer.ts +2 -2
- package/src/NodeStdio.ts +22 -3
- package/src/NodeStream.ts +2 -2
- package/src/NodeTerminal.ts +19 -3
- package/src/NodeWorker.ts +28 -3
- package/src/NodeWorkerRunner.ts +24 -2
- package/src/Undici.ts +3 -3
- package/src/index.ts +377 -24
package/src/NodeClusterSocket.ts
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `NodeClusterSocket` module provides the Node.js socket transport for
|
|
3
|
+
* Effect Cluster runners. It wires `SocketRunner` to Node TCP sockets, supplies
|
|
4
|
+
* RPC client and server protocol layers, and builds a complete sharding layer
|
|
5
|
+
* with serialization, runner health, runner storage, and message storage.
|
|
6
|
+
*
|
|
7
|
+
* **Common tasks**
|
|
8
|
+
*
|
|
9
|
+
* - Run a Node process as a cluster runner over raw TCP sockets with
|
|
10
|
+
* {@link layer}
|
|
11
|
+
* - Connect a client-only process to an existing socket cluster without
|
|
12
|
+
* starting a runner server
|
|
13
|
+
* - Use SQL-backed storage for durable multi-process clusters, `local` storage
|
|
14
|
+
* for short-lived development, or `byo` storage when the deployment owns the
|
|
15
|
+
* persistence boundary
|
|
16
|
+
* - Check runner health with socket pings or Kubernetes pod readiness through
|
|
17
|
+
* {@link layerK8sHttpClient}
|
|
18
|
+
*
|
|
19
|
+
* **Gotchas**
|
|
20
|
+
*
|
|
21
|
+
* - `runnerAddress` is the host and port advertised to other runners; set
|
|
22
|
+
* `runnerListenAddress` when the local bind address differs from the
|
|
23
|
+
* externally reachable address
|
|
24
|
+
* - The socket transport is point-to-point RPC, not cluster gossip: runner
|
|
25
|
+
* membership, shard ownership, and persisted delivery are coordinated through
|
|
26
|
+
* `RunnerStorage`, `MessageStorage`, and `RunnerHealth`
|
|
27
|
+
* - `clientOnly` does not start a socket server or receive shard assignments
|
|
28
|
+
* - Ping health checks use the same socket protocol, so unreachable ports,
|
|
29
|
+
* firewalls, or serialization mismatches can make a runner appear unhealthy
|
|
30
|
+
*
|
|
31
|
+
* @since 4.0.0
|
|
3
32
|
*/
|
|
4
33
|
import { layerClientProtocol, layerSocketServer } from "@effect/platform-node-shared/NodeClusterSocket"
|
|
5
34
|
import type { ConfigError } from "effect/Config"
|
|
@@ -25,20 +54,24 @@ import * as Undici from "./Undici.ts"
|
|
|
25
54
|
|
|
26
55
|
export {
|
|
27
56
|
/**
|
|
28
|
-
* @
|
|
29
|
-
* @
|
|
57
|
+
* @category re-exports
|
|
58
|
+
* @since 4.0.0
|
|
30
59
|
*/
|
|
31
60
|
layerClientProtocol,
|
|
32
61
|
/**
|
|
33
|
-
* @
|
|
34
|
-
* @
|
|
62
|
+
* @category re-exports
|
|
63
|
+
* @since 4.0.0
|
|
35
64
|
*/
|
|
36
65
|
layerSocketServer
|
|
37
66
|
}
|
|
38
67
|
|
|
39
68
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
69
|
+
* Builds the Node cluster socket sharding layer, configuring RPC
|
|
70
|
+
* serialization, message storage, runner health checks, and optional
|
|
71
|
+
* client-only mode.
|
|
72
|
+
*
|
|
73
|
+
* @category layers
|
|
74
|
+
* @since 4.0.0
|
|
42
75
|
*/
|
|
43
76
|
export const layer = <
|
|
44
77
|
const ClientOnly extends boolean = false,
|
|
@@ -111,8 +144,12 @@ export const layer = <
|
|
|
111
144
|
}
|
|
112
145
|
|
|
113
146
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
147
|
+
* Provides an Undici dispatcher for Kubernetes API calls, using the service
|
|
148
|
+
* account CA certificate when it is available and falling back to the default
|
|
149
|
+
* dispatcher otherwise.
|
|
150
|
+
*
|
|
151
|
+
* @category layers
|
|
152
|
+
* @since 4.0.0
|
|
116
153
|
*/
|
|
117
154
|
export const layerDispatcherK8s: Layer.Layer<NodeHttpClient.Dispatcher> = Layer.effect(NodeHttpClient.Dispatcher)(
|
|
118
155
|
Effect.gen(function*() {
|
|
@@ -140,8 +177,11 @@ export const layerDispatcherK8s: Layer.Layer<NodeHttpClient.Dispatcher> = Layer.
|
|
|
140
177
|
)
|
|
141
178
|
|
|
142
179
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
180
|
+
* Provides a `K8sHttpClient` backed by the Undici HTTP client and the
|
|
181
|
+
* Kubernetes-aware dispatcher.
|
|
182
|
+
*
|
|
183
|
+
* @category layers
|
|
184
|
+
* @since 4.0.0
|
|
145
185
|
*/
|
|
146
186
|
export const layerK8sHttpClient: Layer.Layer<K8sHttpClient.K8sHttpClient> = K8sHttpClient.layer.pipe(
|
|
147
187
|
Layer.provide(Layer.fresh(NodeHttpClient.layerUndiciNoDispatcher)),
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js platform Crypto service layer.
|
|
3
|
+
*
|
|
4
|
+
* @since 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
7
|
+
import type * as Crypto from "effect/Crypto"
|
|
8
|
+
import type * as Layer from "effect/Layer"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A layer that provides the Node.js Crypto service implementation.
|
|
12
|
+
*
|
|
13
|
+
* @category layers
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
export const layer: Layer.Layer<Crypto.Crypto> = NodeCrypto.layer
|
package/src/NodeFileSystem.ts
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides the Node.js `FileSystem` layer for Effect programs.
|
|
3
|
+
*
|
|
4
|
+
* Use this module when a Node application, CLI, script, or test needs to
|
|
5
|
+
* satisfy the `FileSystem` service with real filesystem access for reading and
|
|
6
|
+
* writing files, creating directories and temporary files, inspecting metadata,
|
|
7
|
+
* managing links, or watching paths for changes.
|
|
8
|
+
*
|
|
9
|
+
* This module only exposes the Node-backed layer; filesystem operations are
|
|
10
|
+
* accessed through the `FileSystem` service from `effect/FileSystem`. Provide
|
|
11
|
+
* `NodeFileSystem.layer` at the edge of the program, or use
|
|
12
|
+
* `NodeServices.layer` when you also want the standard Node path, stdio,
|
|
13
|
+
* terminal, and child process services. The implementation is shared with
|
|
14
|
+
* other Node-compatible platform packages, so optional services such as
|
|
15
|
+
* `FileSystem.WatchBackend` are honored when present; otherwise file watching
|
|
16
|
+
* follows Node's `node:fs.watch` behavior. Paths are interpreted by Node, so
|
|
17
|
+
* relative paths use the current working directory and platform path rules.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem"
|
|
5
22
|
import type { FileSystem } from "effect/FileSystem"
|
|
6
23
|
import type * as Layer from "effect/Layer"
|
|
7
24
|
|
|
8
25
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
26
|
+
* Provides the `FileSystem` service backed by Node filesystem APIs.
|
|
27
|
+
*
|
|
28
|
+
* @category layers
|
|
29
|
+
* @since 4.0.0
|
|
11
30
|
*/
|
|
12
31
|
export const layer: Layer.Layer<FileSystem> = NodeFileSystem.layer
|
package/src/NodeHttpClient.ts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node.js implementations of the Effect `HttpClient`.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the Node-specific layers and constructors for sending
|
|
5
|
+
* Effect HTTP client requests. It re-exports the fetch-based client for
|
|
6
|
+
* programs that want to use `globalThis.fetch`, provides an Undici-backed
|
|
7
|
+
* client for applications that need Undici dispatcher control, and provides a
|
|
8
|
+
* lower-level `node:http` / `node:https` client for integrations that need
|
|
9
|
+
* native Node agent configuration.
|
|
10
|
+
*
|
|
11
|
+
* Use these clients in server-side applications, CLIs, tests, and integrations
|
|
12
|
+
* where requests should participate in Effect resource management, interruption,
|
|
13
|
+
* streaming, and typed transport / decode errors. The Undici path sends each
|
|
14
|
+
* request through the current `Dispatcher`; `layerUndici` owns a scoped
|
|
15
|
+
* `Agent`, while `dispatcherLayerGlobal` uses Undici's process-global dispatcher
|
|
16
|
+
* without destroying it. The `node:http` path uses separate scoped HTTP and
|
|
17
|
+
* HTTPS agents, making it the right choice when native agent options such as
|
|
18
|
+
* TLS, proxy, keep-alive, or socket behavior need to be configured directly.
|
|
19
|
+
*
|
|
20
|
+
* The backends are not completely interchangeable. Fetch, Undici, and
|
|
21
|
+
* `node:http` expose different agent and dispatcher hooks, body implementations,
|
|
22
|
+
* abort behavior, upgrade support, and response body readers. This module
|
|
23
|
+
* converts Effect request bodies to the selected runtime representation:
|
|
24
|
+
* streams remain streaming, `FormData` may contribute generated content headers,
|
|
25
|
+
* and body read failures are reported as `HttpClientError` decode or transport
|
|
26
|
+
* errors.
|
|
27
|
+
*
|
|
28
|
+
* @since 4.0.0
|
|
3
29
|
*/
|
|
4
30
|
import * as Context from "effect/Context"
|
|
5
31
|
import * as Effect from "effect/Effect"
|
|
@@ -36,18 +62,18 @@ import * as Undici from "./Undici.ts"
|
|
|
36
62
|
|
|
37
63
|
export {
|
|
38
64
|
/**
|
|
39
|
-
* @since 1.0.0
|
|
40
65
|
* @category Fetch
|
|
66
|
+
* @since 4.0.0
|
|
41
67
|
*/
|
|
42
68
|
Fetch,
|
|
43
69
|
/**
|
|
44
|
-
* @since 1.0.0
|
|
45
70
|
* @category Fetch
|
|
71
|
+
* @since 4.0.0
|
|
46
72
|
*/
|
|
47
73
|
layer as layerFetch,
|
|
48
74
|
/**
|
|
49
|
-
* @since 1.0.0
|
|
50
75
|
* @category Fetch
|
|
76
|
+
* @since 4.0.0
|
|
51
77
|
*/
|
|
52
78
|
RequestInit
|
|
53
79
|
} from "effect/unstable/http/FetchHttpClient"
|
|
@@ -57,16 +83,22 @@ export {
|
|
|
57
83
|
// -----------------------------------------------------------------------------
|
|
58
84
|
|
|
59
85
|
/**
|
|
60
|
-
*
|
|
86
|
+
* Service tag for the Undici `Dispatcher` used by the Undici-backed HTTP
|
|
87
|
+
* client.
|
|
88
|
+
*
|
|
61
89
|
* @category Dispatcher
|
|
90
|
+
* @since 4.0.0
|
|
62
91
|
*/
|
|
63
92
|
export class Dispatcher extends Context.Service<Dispatcher, Undici.Dispatcher>()(
|
|
64
93
|
"@effect/platform-node/NodeHttpClient/Dispatcher"
|
|
65
94
|
) {}
|
|
66
95
|
|
|
67
96
|
/**
|
|
68
|
-
*
|
|
97
|
+
* Acquires a new Undici `Agent` dispatcher and destroys it when the enclosing
|
|
98
|
+
* scope is finalized.
|
|
99
|
+
*
|
|
69
100
|
* @category Dispatcher
|
|
101
|
+
* @since 4.0.0
|
|
70
102
|
*/
|
|
71
103
|
export const makeDispatcher: Effect.Effect<Undici.Dispatcher, never, Scope.Scope> = Effect.acquireRelease(
|
|
72
104
|
Effect.sync(() => new Undici.Agent()),
|
|
@@ -74,20 +106,28 @@ export const makeDispatcher: Effect.Effect<Undici.Dispatcher, never, Scope.Scope
|
|
|
74
106
|
)
|
|
75
107
|
|
|
76
108
|
/**
|
|
77
|
-
*
|
|
109
|
+
* Provides the `Dispatcher` service using a scoped Undici `Agent`.
|
|
110
|
+
*
|
|
78
111
|
* @category Dispatcher
|
|
112
|
+
* @since 4.0.0
|
|
79
113
|
*/
|
|
80
114
|
export const layerDispatcher: Layer.Layer<Dispatcher> = Layer.effect(Dispatcher)(makeDispatcher)
|
|
81
115
|
|
|
82
116
|
/**
|
|
83
|
-
*
|
|
117
|
+
* Provides the `Dispatcher` service from Undici's process-global dispatcher,
|
|
118
|
+
* without creating or owning a new agent.
|
|
119
|
+
*
|
|
84
120
|
* @category Dispatcher
|
|
121
|
+
* @since 4.0.0
|
|
85
122
|
*/
|
|
86
123
|
export const dispatcherLayerGlobal: Layer.Layer<Dispatcher> = Layer.sync(Dispatcher)(() => Undici.getGlobalDispatcher())
|
|
87
124
|
|
|
88
125
|
/**
|
|
89
|
-
*
|
|
126
|
+
* Fiber reference containing default Undici request options applied to requests
|
|
127
|
+
* sent by `makeUndici`.
|
|
128
|
+
*
|
|
90
129
|
* @category undici
|
|
130
|
+
* @since 4.0.0
|
|
91
131
|
*/
|
|
92
132
|
export const UndiciOptions = Context.Reference<Partial<Undici.Dispatcher.RequestOptions>>(
|
|
93
133
|
"@effect/platform-node/NodeHttpClient/UndiciOptions",
|
|
@@ -95,8 +135,12 @@ export const UndiciOptions = Context.Reference<Partial<Undici.Dispatcher.Request
|
|
|
95
135
|
)
|
|
96
136
|
|
|
97
137
|
/**
|
|
98
|
-
*
|
|
138
|
+
* Creates an `HttpClient` that sends requests through the current Undici
|
|
139
|
+
* `Dispatcher`, converts Effect HTTP bodies to Undici bodies, and maps
|
|
140
|
+
* transport and decode failures to `HttpClientError`.
|
|
141
|
+
*
|
|
99
142
|
* @category undici
|
|
143
|
+
* @since 4.0.0
|
|
100
144
|
*/
|
|
101
145
|
export const makeUndici = Effect.gen(function*() {
|
|
102
146
|
const dispatcher = yield* Dispatcher
|
|
@@ -309,8 +353,11 @@ class UndiciResponse extends Inspectable.Class implements HttpClientResponse, Pi
|
|
|
309
353
|
}
|
|
310
354
|
|
|
311
355
|
/**
|
|
312
|
-
*
|
|
356
|
+
* Provides an Undici-backed `HttpClient` using the current `Dispatcher`
|
|
357
|
+
* service.
|
|
358
|
+
*
|
|
313
359
|
* @category Undici
|
|
360
|
+
* @since 4.0.0
|
|
314
361
|
*/
|
|
315
362
|
export const layerUndiciNoDispatcher: Layer.Layer<
|
|
316
363
|
Client.HttpClient,
|
|
@@ -319,8 +366,11 @@ export const layerUndiciNoDispatcher: Layer.Layer<
|
|
|
319
366
|
> = Client.layerMergedContext(makeUndici)
|
|
320
367
|
|
|
321
368
|
/**
|
|
322
|
-
*
|
|
369
|
+
* Provides an Undici-backed `HttpClient` together with a scoped default
|
|
370
|
+
* Undici `Agent` dispatcher.
|
|
371
|
+
*
|
|
323
372
|
* @category Undici
|
|
373
|
+
* @since 4.0.0
|
|
324
374
|
*/
|
|
325
375
|
export const layerUndici: Layer.Layer<Client.HttpClient> = Layer.provide(layerUndiciNoDispatcher, layerDispatcher)
|
|
326
376
|
|
|
@@ -329,8 +379,11 @@ export const layerUndici: Layer.Layer<Client.HttpClient> = Layer.provide(layerUn
|
|
|
329
379
|
// -----------------------------------------------------------------------------
|
|
330
380
|
|
|
331
381
|
/**
|
|
332
|
-
*
|
|
382
|
+
* Service tag for the paired Node `http` and `https` agents used by the
|
|
383
|
+
* node:http-backed HTTP client.
|
|
384
|
+
*
|
|
333
385
|
* @category HttpAgent
|
|
386
|
+
* @since 4.0.0
|
|
334
387
|
*/
|
|
335
388
|
export class HttpAgent extends Context.Service<HttpAgent, {
|
|
336
389
|
readonly http: Http.Agent
|
|
@@ -338,8 +391,11 @@ export class HttpAgent extends Context.Service<HttpAgent, {
|
|
|
338
391
|
}>()("@effect/platform-node/NodeHttpClient/HttpAgent") {}
|
|
339
392
|
|
|
340
393
|
/**
|
|
341
|
-
*
|
|
394
|
+
* Acquires Node `http` and `https` agents with the supplied options and
|
|
395
|
+
* destroys both agents when the enclosing scope is finalized.
|
|
396
|
+
*
|
|
342
397
|
* @category HttpAgent
|
|
398
|
+
* @since 4.0.0
|
|
343
399
|
*/
|
|
344
400
|
export const makeAgent = (options?: Https.AgentOptions): Effect.Effect<HttpAgent["Service"], never, Scope.Scope> =>
|
|
345
401
|
Effect.zipWith(
|
|
@@ -355,22 +411,32 @@ export const makeAgent = (options?: Https.AgentOptions): Effect.Effect<HttpAgent
|
|
|
355
411
|
)
|
|
356
412
|
|
|
357
413
|
/**
|
|
358
|
-
*
|
|
414
|
+
* Provides the `HttpAgent` service using scoped Node `http` and `https`
|
|
415
|
+
* agents configured with the supplied options.
|
|
416
|
+
*
|
|
359
417
|
* @category HttpAgent
|
|
418
|
+
* @since 4.0.0
|
|
360
419
|
*/
|
|
361
420
|
export const layerAgentOptions: (options?: Https.AgentOptions | undefined) => Layer.Layer<
|
|
362
421
|
HttpAgent
|
|
363
422
|
> = flow(makeAgent, Layer.effect(HttpAgent))
|
|
364
423
|
|
|
365
424
|
/**
|
|
366
|
-
*
|
|
425
|
+
* Provides the `HttpAgent` service using default scoped Node `http` and
|
|
426
|
+
* `https` agents.
|
|
427
|
+
*
|
|
367
428
|
* @category HttpAgent
|
|
429
|
+
* @since 4.0.0
|
|
368
430
|
*/
|
|
369
431
|
export const layerAgent: Layer.Layer<HttpAgent> = layerAgentOptions()
|
|
370
432
|
|
|
371
433
|
/**
|
|
372
|
-
*
|
|
434
|
+
* Creates an `HttpClient` backed by Node `http` and `https`, using the
|
|
435
|
+
* current `HttpAgent`, streaming request bodies, and wrapping Node responses
|
|
436
|
+
* as `HttpClientResponse` values.
|
|
437
|
+
*
|
|
373
438
|
* @category node:http
|
|
439
|
+
* @since 4.0.0
|
|
374
440
|
*/
|
|
375
441
|
export const makeNodeHttp = Effect.gen(function*() {
|
|
376
442
|
const agent = yield* HttpAgent
|
|
@@ -579,8 +645,11 @@ class NodeHttpResponse extends NodeHttpIncomingMessage<Error.HttpClientError> im
|
|
|
579
645
|
}
|
|
580
646
|
|
|
581
647
|
/**
|
|
582
|
-
*
|
|
648
|
+
* Provides a node:http-backed `HttpClient` using the current `HttpAgent`
|
|
649
|
+
* service.
|
|
650
|
+
*
|
|
583
651
|
* @category node:http
|
|
652
|
+
* @since 4.0.0
|
|
584
653
|
*/
|
|
585
654
|
export const layerNodeHttpNoAgent: Layer.Layer<
|
|
586
655
|
Client.HttpClient,
|
|
@@ -589,7 +658,10 @@ export const layerNodeHttpNoAgent: Layer.Layer<
|
|
|
589
658
|
> = Client.layerMergedContext(makeNodeHttp)
|
|
590
659
|
|
|
591
660
|
/**
|
|
592
|
-
*
|
|
661
|
+
* Provides a node:http-backed `HttpClient` together with default scoped Node
|
|
662
|
+
* `http` and `https` agents.
|
|
663
|
+
*
|
|
593
664
|
* @category node:http
|
|
665
|
+
* @since 4.0.0
|
|
594
666
|
*/
|
|
595
667
|
export const layerNodeHttp: Layer.Layer<Client.HttpClient> = Layer.provide(layerNodeHttpNoAgent, layerAgent)
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Utilities for adapting Node `http.IncomingMessage` values to the Effect HTTP
|
|
3
|
+
* incoming message interface used by the platform Node server and client
|
|
4
|
+
* implementations.
|
|
5
|
+
*
|
|
6
|
+
* This module is useful when code needs to keep access to Node's request or
|
|
7
|
+
* response object while also exposing Effect's typed headers, remote address,
|
|
8
|
+
* body decoders, and stream interface. The body helpers consume Node's readable
|
|
9
|
+
* stream, cache decoded text and array-buffer results, and honor the
|
|
10
|
+
* `HttpIncomingMessage.MaxBodySize` fiber ref. Prefer a single body access
|
|
11
|
+
* strategy per message: raw `stream` access is not cached, and Node request
|
|
12
|
+
* bodies cannot be replayed once the underlying stream has been consumed.
|
|
13
|
+
*
|
|
14
|
+
* @since 4.0.0
|
|
3
15
|
*/
|
|
4
16
|
import * as Effect from "effect/Effect"
|
|
5
17
|
import * as Inspectable from "effect/Inspectable"
|
|
@@ -13,14 +25,20 @@ import type * as Http from "node:http"
|
|
|
13
25
|
import * as NodeStream from "./NodeStream.ts"
|
|
14
26
|
|
|
15
27
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
28
|
+
* Base adapter from Node `IncomingMessage` to Effect HTTP incoming messages,
|
|
29
|
+
* exposing headers, remote address, stream access, and cached text, JSON, URL
|
|
30
|
+
* parameter, and array-buffer body decoders with caller-provided error mapping.
|
|
31
|
+
*
|
|
32
|
+
* @category constructors
|
|
33
|
+
* @since 4.0.0
|
|
18
34
|
*/
|
|
19
35
|
export abstract class NodeHttpIncomingMessage<E> extends Inspectable.Class
|
|
20
36
|
implements IncomingMessage.HttpIncomingMessage<E>
|
|
21
37
|
{
|
|
22
38
|
/**
|
|
23
|
-
*
|
|
39
|
+
* Marks this value as an HTTP incoming message for runtime guards.
|
|
40
|
+
*
|
|
41
|
+
* @since 4.0.0
|
|
24
42
|
*/
|
|
25
43
|
readonly [IncomingMessage.TypeId]: typeof IncomingMessage.TypeId
|
|
26
44
|
readonly source: Http.IncomingMessage
|
package/src/NodeHttpPlatform.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node.js implementation of the Effect HTTP platform service.
|
|
3
|
+
*
|
|
4
|
+
* This module connects the portable `HttpPlatform` file response helpers to
|
|
5
|
+
* Node runtime primitives. It is used by Node HTTP servers and static file
|
|
6
|
+
* handlers when returning local files, public assets, downloads, byte ranges,
|
|
7
|
+
* or Web `File` values as `HttpServerResponse` bodies.
|
|
8
|
+
*
|
|
9
|
+
* Path-based responses are served with `node:fs.createReadStream`; Web `File`
|
|
10
|
+
* responses are bridged with `Readable.fromWeb`. The implementation fills in
|
|
11
|
+
* `content-type` from `Mime`, falls back to `application/octet-stream`, and
|
|
12
|
+
* writes the `content-length` for the selected range or whole file. Node's
|
|
13
|
+
* stream `end` option is inclusive, so the platform converts Effect's half-open
|
|
14
|
+
* range before reading. Empty bodies use an empty readable stream.
|
|
15
|
+
*
|
|
16
|
+
* Provide `layer` at the Node runtime edge when file responses, static serving,
|
|
17
|
+
* or response bodies created from files need real filesystem and ETag support.
|
|
18
|
+
* These responses are raw Node streams, so they are intended for the Node HTTP
|
|
19
|
+
* server adapter; keep files available until the response body has been
|
|
20
|
+
* consumed and prefer the portable `HttpServerResponse` constructors when a
|
|
21
|
+
* response does not depend on Node file or stream behavior.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
3
24
|
*/
|
|
4
25
|
import { pipe } from "effect/Function"
|
|
5
26
|
import * as Layer from "effect/Layer"
|
|
@@ -13,8 +34,11 @@ import Mime from "./Mime.ts"
|
|
|
13
34
|
import * as NodeFileSystem from "./NodeFileSystem.ts"
|
|
14
35
|
|
|
15
36
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
37
|
+
* Creates the Node `HttpPlatform`, serving file responses from Node readable
|
|
38
|
+
* streams and adding MIME type and content-length headers when needed.
|
|
39
|
+
*
|
|
40
|
+
* @category constructors
|
|
41
|
+
* @since 4.0.0
|
|
18
42
|
*/
|
|
19
43
|
export const make = Platform.make({
|
|
20
44
|
fileResponse(path, status, statusText, headers, start, end, contentLength) {
|
|
@@ -47,8 +71,11 @@ export const make = Platform.make({
|
|
|
47
71
|
})
|
|
48
72
|
|
|
49
73
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
74
|
+
* Provides the Node `HttpPlatform` together with the filesystem and ETag
|
|
75
|
+
* services it needs for file responses.
|
|
76
|
+
*
|
|
77
|
+
* @category layers
|
|
78
|
+
* @since 4.0.0
|
|
52
79
|
*/
|
|
53
80
|
export const layer: Layer.Layer<Platform.HttpPlatform> = pipe(
|
|
54
81
|
Layer.effect(Platform.HttpPlatform)(make),
|
package/src/NodeHttpServer.ts
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node.js implementation of the Effect `HttpServer`.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts a supplied Node `http.Server` into Effect's
|
|
5
|
+
* platform-independent HTTP server service. It starts the server with Node
|
|
6
|
+
* `listen` options, converts `request` events into `HttpServerRequest` values,
|
|
7
|
+
* writes `HttpServerResponse` bodies through Node's `ServerResponse`, and
|
|
8
|
+
* handles `upgrade` events by exposing the upgraded socket through
|
|
9
|
+
* `HttpServerRequest.upgrade`.
|
|
10
|
+
*
|
|
11
|
+
* Common use cases include serving an Effect HTTP application with {@link layer}
|
|
12
|
+
* or {@link layerConfig}, embedding request or upgrade handlers into an
|
|
13
|
+
* existing Node server with {@link makeHandler} and {@link makeUpgradeHandler},
|
|
14
|
+
* and using {@link layerTest} for integration tests that need an ephemeral
|
|
15
|
+
* listening port and a client pointed at it.
|
|
16
|
+
*
|
|
17
|
+
* Listen options are passed directly to Node, so host, port, backlog, and Unix
|
|
18
|
+
* socket path behavior follow `node:http`. The server begins listening when the
|
|
19
|
+
* `HttpServer` is acquired, and handlers are installed when `serve` is run.
|
|
20
|
+
* Request fibers are interrupted with `ClientAbort` when the client disconnects
|
|
21
|
+
* before a response finishes. WebSocket support only applies to Node `upgrade`
|
|
22
|
+
* requests, and ordinary HTTP requests fail if their application attempts to use
|
|
23
|
+
* `HttpServerRequest.upgrade`.
|
|
24
|
+
*
|
|
25
|
+
* Scope ownership is important: the server is closed when the acquiring scope
|
|
26
|
+
* finalizes, while each `serve` call installs its own request and upgrade
|
|
27
|
+
* listeners and removes them on finalization. Unless preemptive shutdown is
|
|
28
|
+
* disabled, finalizing a serve scope also starts a graceful server close, using
|
|
29
|
+
* the configured timeout or the default timeout.
|
|
30
|
+
*
|
|
31
|
+
* @since 4.0.0
|
|
3
32
|
*/
|
|
4
33
|
import * as Cause from "effect/Cause"
|
|
5
34
|
import * as Config from "effect/Config"
|
|
@@ -52,8 +81,12 @@ import * as NodeServices from "./NodeServices.ts"
|
|
|
52
81
|
import { NodeWS } from "./NodeSocket.ts"
|
|
53
82
|
|
|
54
83
|
/**
|
|
55
|
-
*
|
|
84
|
+
* Creates a scoped `HttpServer` from a Node `http.Server`, starts listening
|
|
85
|
+
* with the supplied options, registers request and upgrade handling, and closes
|
|
86
|
+
* the server during scope finalization with optional graceful-shutdown control.
|
|
87
|
+
*
|
|
56
88
|
* @category constructors
|
|
89
|
+
* @since 4.0.0
|
|
57
90
|
*/
|
|
58
91
|
export const make = Effect.fnUntraced(function*(
|
|
59
92
|
evaluate: LazyArg<Http.Server>,
|
|
@@ -145,8 +178,12 @@ export const make = Effect.fnUntraced(function*(
|
|
|
145
178
|
})
|
|
146
179
|
|
|
147
180
|
/**
|
|
148
|
-
*
|
|
181
|
+
* Creates a Node `request` event handler for an Effect HTTP application,
|
|
182
|
+
* injecting a `HttpServerRequest` and interrupting the request fiber if the
|
|
183
|
+
* client closes the response before it finishes.
|
|
184
|
+
*
|
|
149
185
|
* @category Handlers
|
|
186
|
+
* @since 4.0.0
|
|
150
187
|
*/
|
|
151
188
|
export const makeHandler = <
|
|
152
189
|
R,
|
|
@@ -183,8 +220,12 @@ export const makeHandler = <
|
|
|
183
220
|
}
|
|
184
221
|
|
|
185
222
|
/**
|
|
186
|
-
*
|
|
223
|
+
* Creates a Node `upgrade` event handler for an Effect HTTP application,
|
|
224
|
+
* exposing the upgraded WebSocket as the request's `upgrade` effect and
|
|
225
|
+
* interrupting the request fiber when the socket closes early.
|
|
226
|
+
*
|
|
187
227
|
* @category Handlers
|
|
228
|
+
* @since 4.0.0
|
|
188
229
|
*/
|
|
189
230
|
export const makeUpgradeHandler = <
|
|
190
231
|
R,
|
|
@@ -366,8 +407,11 @@ class ServerRequestImpl extends NodeHttpIncomingMessage<HttpServerError> impleme
|
|
|
366
407
|
}
|
|
367
408
|
|
|
368
409
|
/**
|
|
369
|
-
*
|
|
370
|
-
*
|
|
410
|
+
* Provides an `HttpServer` by creating and managing a scoped Node
|
|
411
|
+
* `http.Server` with the supplied listen and shutdown options.
|
|
412
|
+
*
|
|
413
|
+
* @category layers
|
|
414
|
+
* @since 4.0.0
|
|
371
415
|
*/
|
|
372
416
|
export const layerServer: (
|
|
373
417
|
evaluate: LazyArg<Http.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse>>,
|
|
@@ -378,8 +422,11 @@ export const layerServer: (
|
|
|
378
422
|
) => Layer.Layer<HttpServer.HttpServer, ServeError> = flow(make, Layer.effect(HttpServer.HttpServer))
|
|
379
423
|
|
|
380
424
|
/**
|
|
381
|
-
*
|
|
382
|
-
*
|
|
425
|
+
* Provides the Node HTTP support services used by `NodeHttpServer`, including
|
|
426
|
+
* the HTTP platform, ETag generator, and core Node platform services.
|
|
427
|
+
*
|
|
428
|
+
* @category layers
|
|
429
|
+
* @since 4.0.0
|
|
383
430
|
*/
|
|
384
431
|
export const layerHttpServices: Layer.Layer<
|
|
385
432
|
NodeServices.NodeServices | HttpPlatform.HttpPlatform | Etag.Generator
|
|
@@ -390,8 +437,11 @@ export const layerHttpServices: Layer.Layer<
|
|
|
390
437
|
)
|
|
391
438
|
|
|
392
439
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
440
|
+
* Provides a Node `HttpServer` together with the Node HTTP platform, ETag, and
|
|
441
|
+
* core platform services required to serve requests.
|
|
442
|
+
*
|
|
443
|
+
* @category layers
|
|
444
|
+
* @since 4.0.0
|
|
395
445
|
*/
|
|
396
446
|
export const layer = (
|
|
397
447
|
evaluate: LazyArg<Http.Server>,
|
|
@@ -409,8 +459,11 @@ export const layer = (
|
|
|
409
459
|
)
|
|
410
460
|
|
|
411
461
|
/**
|
|
412
|
-
*
|
|
413
|
-
*
|
|
462
|
+
* Provides a Node `HttpServer` and HTTP support services, reading the listen
|
|
463
|
+
* and shutdown options from a `Config` value.
|
|
464
|
+
*
|
|
465
|
+
* @category layers
|
|
466
|
+
* @since 4.0.0
|
|
414
467
|
*/
|
|
415
468
|
export const layerConfig = (
|
|
416
469
|
evaluate: LazyArg<Http.Server>,
|
|
@@ -432,8 +485,11 @@ export const layerConfig = (
|
|
|
432
485
|
)
|
|
433
486
|
|
|
434
487
|
/**
|
|
435
|
-
*
|
|
488
|
+
* Provides a test HTTP server listening on an ephemeral port together with a
|
|
489
|
+
* Fetch-backed `HttpClient` configured for server integration tests.
|
|
490
|
+
*
|
|
436
491
|
* @category Testing
|
|
492
|
+
* @since 4.0.0
|
|
437
493
|
*/
|
|
438
494
|
export const layerTest: Layer.Layer<
|
|
439
495
|
| HttpServer.HttpServer
|
|
@@ -1,18 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Accessors for the Node.js objects backing a platform Node
|
|
3
|
+
* `HttpServerRequest`.
|
|
4
|
+
*
|
|
5
|
+
* Use this module at interop boundaries when an Effect HTTP handler needs the
|
|
6
|
+
* original `http.IncomingMessage` or `http.ServerResponse` for APIs that are
|
|
7
|
+
* specific to Node, such as existing middleware, socket inspection, raw stream
|
|
8
|
+
* piping, or response customization that cannot be expressed with the portable
|
|
9
|
+
* `HttpServerRequest` and `HttpServerResponse` interfaces.
|
|
10
|
+
*
|
|
11
|
+
* The returned request is the original Node request supplied to the server. It
|
|
12
|
+
* does not reflect Effect request overrides made by middleware, such as a
|
|
13
|
+
* rewritten URL, adjusted headers, or a substituted remote address. Its body is
|
|
14
|
+
* also Node's one-shot readable stream, so avoid mixing raw stream consumption
|
|
15
|
+
* with Effect body, multipart, or stream helpers unless ownership of the body
|
|
16
|
+
* is clear. The returned response is the Node response owned by the platform
|
|
17
|
+
* server; writing to it directly bypasses the usual Effect response writer and
|
|
18
|
+
* must be coordinated carefully to avoid duplicate writes. Upgrade requests may
|
|
19
|
+
* create that response lazily when it is first requested.
|
|
20
|
+
*
|
|
21
|
+
* @since 4.0.0
|
|
3
22
|
*/
|
|
4
23
|
import type { HttpServerRequest } from "effect/unstable/http/HttpServerRequest"
|
|
5
24
|
import type * as Http from "node:http"
|
|
6
25
|
|
|
7
26
|
/**
|
|
8
|
-
*
|
|
27
|
+
* Returns the underlying Node `IncomingMessage` for a platform Node
|
|
28
|
+
* `HttpServerRequest`.
|
|
29
|
+
*
|
|
9
30
|
* @category Accessors
|
|
31
|
+
* @since 4.0.0
|
|
10
32
|
*/
|
|
11
33
|
export const toIncomingMessage = (self: HttpServerRequest): Http.IncomingMessage => self.source as any
|
|
12
34
|
|
|
13
35
|
/**
|
|
14
|
-
*
|
|
36
|
+
* Returns the underlying Node `ServerResponse` for a platform Node
|
|
37
|
+
* `HttpServerRequest`, evaluating the stored response thunk when the response
|
|
38
|
+
* was created lazily.
|
|
39
|
+
*
|
|
15
40
|
* @category Accessors
|
|
41
|
+
* @since 4.0.0
|
|
16
42
|
*/
|
|
17
43
|
export const toServerResponse = (self: HttpServerRequest): Http.ServerResponse => {
|
|
18
44
|
const res = (self as any).response
|