Tests
All checks were successful
Lint / lint (push) Successful in 38s

This commit is contained in:
Julien Valverdé
2026-01-24 03:07:59 +01:00
parent c1a52d29d4
commit fb2ae4c3ce
3 changed files with 89 additions and 8 deletions

View File

@@ -38,7 +38,9 @@
"clean:modules": "rm -rf node_modules"
},
"devDependencies": {
"@effect/platform-node": "^0.104.1"
"@effect/platform-node": "^0.104.1",
"tsx": "^4.21.0",
"undici": "^7.19.0"
},
"peerDependencies": {
"@effect/platform": "^0.94.2",

View File

@@ -2,24 +2,39 @@ import net from "node:net"
import { HttpClient } from "@effect/platform"
import { NodeHttpClient, NodeRuntime } from "@effect/platform-node"
import { Effect, Layer } from "effect"
import { Agent } from "undici"
const DockerSocketAgent = Effect.acquireRelease(
Effect.sync(() => net.createConnection({ path: "/var/run/docker.sock" })),
socket => Effect.sync(() => socket.end()),
const DockerNodeSocketAgent = Effect.acquireUseRelease(
Effect.sync(() => {
console.log("acquire")
return net.createConnection({ path: "/var/run/docker.sock" })
}),
socket => Effect.sync(() => {
socket.on("connect", console.log)
socket.on("data", console.log)
return socket
}),
socket => Effect.sync(() => {
console.log("release")
socket.end()
}),
).pipe(
Effect.andThen(socket => NodeHttpClient.makeAgentLayer({ socket })),
Layer.unwrapScoped,
)
const DockerNodeHttpClient = Layer.provide(NodeHttpClient.layerWithoutAgent, DockerNodeSocketAgent)
const DockerHttpClient = Layer.provide(NodeHttpClient.layerWithoutAgent, DockerSocketAgent)
const DockerUndiciDispatcher = Layer.succeed(NodeHttpClient.Dispatcher, new Agent({
socketPath: "/var/run/docker.sock"
}))
const DockerUndiciHttpClient = Layer.provide(NodeHttpClient.layerUndiciWithoutDispatcher, DockerUndiciDispatcher)
Effect.gen(function*() {
const client = yield* HttpClient.HttpClient
const response = yield* client.get("http://localhost/containers/json")
const response = yield* client.get("http://localhost/images/json")
console.log(yield* response.json)
}).pipe(
Effect.provide(DockerHttpClient),
Effect.provide(DockerUndiciHttpClient),
NodeRuntime.runMain,
)