Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/rename-platform-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@effect/platform-node": patch
"@effect/platform-bun": patch
---

Rename platform service collection modules from `NodeServices` and `BunServices` to `NodeContext` and `BunContext`.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* This example shows how to collect process output, compose pipelines, and stream long-running command output.
*/
import { NodeServices } from "@effect/platform-node"
import { NodeContext } from "@effect/platform-node"
import { Console, Context, Effect, Layer, Schema, Stream, String } from "effect"
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"

Expand Down Expand Up @@ -100,8 +100,8 @@ export class DevTools extends Context.Service<DevTools, {
})
})
).pipe(
// Provide the `ChildProcessSpawner` dependency from `NodeServices.layer`.
Layer.provide(NodeServices.layer)
// Provide the `ChildProcessSpawner` dependency from `NodeContext.layer`.
Layer.provide(NodeContext.layer)
)
}

Expand All @@ -112,6 +112,6 @@ export const program = Effect.gen(function*() {
yield* Effect.log(`node=${version}`)
}).pipe(
// `ChildProcess` requires a platform implementation of
// `ChildProcessSpawner`. In Node.js, `NodeServices.layer` provides it.
// `ChildProcessSpawner`. In Node.js, `NodeContext.layer` provides it.
Effect.provide(DevTools.layer)
)
4 changes: 2 additions & 2 deletions ai-docs/src/70_cli/10_basics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Build a command-line app with typed arguments and flags, then wire subcommand
* handlers into a single executable command.
*/
import { NodeRuntime, NodeServices } from "@effect/platform-node"
import { NodeContext, NodeRuntime } from "@effect/platform-node"
import { Console, Effect } from "effect"
import { Argument, Command, Flag } from "effect/unstable/cli"

Expand Down Expand Up @@ -131,6 +131,6 @@ tasks.pipe(
}),
// Provide the services for the platform you are targeting. In this case,
// Node.js
Effect.provide(NodeServices.layer),
Effect.provide(NodeContext.layer),
NodeRuntime.runMain
)
6 changes: 3 additions & 3 deletions packages/effect/src/unstable/process/ChildProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @example
* ```ts
* import { NodeServices } from "@effect/platform-node"
* import { NodeContext } from "@effect/platform-node"
* import { Effect, Stream } from "effect"
* import { ChildProcess } from "effect/unstable/process"
*
Expand All @@ -20,7 +20,7 @@
* const chunks = yield* Stream.runCollect(handle.stdout)
* const exitCode = yield* handle.exitCode
* return { chunks, exitCode }
* }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))
* }).pipe(Effect.scoped, Effect.provide(NodeContext.layer))
*
* // With options
* const withOptions = ChildProcess.make({ cwd: "/tmp" })`ls -la`
Expand All @@ -35,7 +35,7 @@
* const handle = yield* pipeline
* const chunks = yield* Stream.runCollect(handle.stdout)
* return chunks
* }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))
* }).pipe(Effect.scoped, Effect.provide(NodeContext.layer))
* ```
*
* @since 4.0.0
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/unstable/process/ChildProcessSpawner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export interface ChildProcessHandle {
*
* @example
* ```ts
* import { NodeServices } from "@effect/platform-node"
* import { NodeContext } from "@effect/platform-node"
* import { Effect } from "effect"
* import { ChildProcess } from "effect/unstable/process"
*
Expand All @@ -149,7 +149,7 @@ export interface ChildProcessHandle {
*
* yield* reref
* return yield* handle.exitCode
* }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))
* }).pipe(Effect.scoped, Effect.provide(NodeContext.layer))
* ```
*/
readonly unref: Effect.Effect<Reref, PlatformError.PlatformError>
Expand Down
6 changes: 3 additions & 3 deletions packages/effect/src/unstable/process/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @example
* ```ts
* import { NodeServices } from "@effect/platform-node"
* import { NodeContext } from "@effect/platform-node"
* import { Effect, Stream } from "effect"
* import { ChildProcess } from "effect/unstable/process"
*
Expand All @@ -26,7 +26,7 @@
* const chunks = yield* Stream.runCollect(handle.stdout)
* const exitCode = yield* handle.exitCode
* return { chunks, exitCode }
* }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))
* }).pipe(Effect.scoped, Effect.provide(NodeContext.layer))
*
* // With options
* const withOptions = ChildProcess.make({ cwd: "/tmp" })`ls -la`
Expand All @@ -41,7 +41,7 @@
* const handle = yield* pipeline
* const chunks = yield* Stream.runCollect(handle.stdout)
* return chunks
* }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))
* }).pipe(Effect.scoped, Effect.provide(NodeContext.layer))
* ```
*
* @since 4.0.0
Expand Down
4 changes: 2 additions & 2 deletions packages/platform-bun/src/BunClusterHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import type { ServeError } from "effect/unstable/http/HttpServerError"
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization"
import type { SqlClient } from "effect/unstable/sql/SqlClient"
import { layerK8sHttpClient } from "./BunClusterSocket.ts"
import type { BunContext } from "./BunContext.ts"
import * as BunFileSystem from "./BunFileSystem.ts"
import * as BunHttpServer from "./BunHttpServer.ts"
import type { BunServices } from "./BunServices.ts"
import * as BunSocket from "./BunSocket.ts"

export {
Expand All @@ -42,7 +42,7 @@ export {
export const layerHttpServer: Layer.Layer<
| HttpPlatform
| Etag.Generator
| BunServices
| BunContext
| HttpServer,
ServeError,
ShardingConfig.ShardingConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import * as BunTerminal from "./BunTerminal.ts"
* @since 1.0.0
* @category models
*/
export type BunServices = ChildProcessSpawner | FileSystem | Path | Terminal | Stdio
export type BunContext = ChildProcessSpawner | FileSystem | Path | Terminal | Stdio

/**
* @since 1.0.0
* @category layer
*/
export const layer: Layer.Layer<BunServices> = BunChildProcessSpawner.layer.pipe(
export const layer: Layer.Layer<BunContext> = BunChildProcessSpawner.layer.pipe(
Layer.provideMerge(Layer.mergeAll(
BunFileSystem.layer,
BunPath.layer,
Expand Down
8 changes: 4 additions & 4 deletions packages/platform-bun/src/BunHttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import type * as ServerResponse from "effect/unstable/http/HttpServerResponse"
import type * as Multipart from "effect/unstable/http/Multipart"
import * as UrlParams from "effect/unstable/http/UrlParams"
import * as Socket from "effect/unstable/socket/Socket"
import * as BunContext from "./BunContext.ts"
import * as Platform from "./BunHttpPlatform.ts"
import * as BunMultipart from "./BunMultipart.ts"
import * as BunServices from "./BunServices.ts"
import * as BunStream from "./BunStream.ts"

/**
Expand Down Expand Up @@ -227,11 +227,11 @@ export const layerServer: <R extends string>(
export const layerHttpServices: Layer.Layer<
| HttpPlatform
| Etag.Generator
| BunServices.BunServices
| BunContext.BunContext
> = Layer.mergeAll(
Platform.layer,
Etag.layerWeak,
BunServices.layer
BunContext.layer
)

/**
Expand All @@ -247,7 +247,7 @@ export const layer = <R extends string>(
| Server.HttpServer
| HttpPlatform
| Etag.Generator
| BunServices.BunServices
| BunContext.BunContext
> => Layer.mergeAll(layerServer(options), layerHttpServices)

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/platform-bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export * as BunClusterHttp from "./BunClusterHttp.ts"
*/
export * as BunClusterSocket from "./BunClusterSocket.ts"

/**
* @since 1.0.0
*/
export * as BunContext from "./BunContext.ts"

/**
* @since 1.0.0
*/
Expand Down Expand Up @@ -66,11 +71,6 @@ export * as BunRedis from "./BunRedis.ts"
*/
export * as BunRuntime from "./BunRuntime.ts"

/**
* @since 1.0.0
*/
export * as BunServices from "./BunServices.ts"

/**
* @since 1.0.0
*/
Expand Down
34 changes: 17 additions & 17 deletions packages/platform-node-shared/test/NodeChildProcessSpawner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"

const TEST_BASH_SCRIPTS_PATH = [__dirname, "fixtures", "bash"]

const NodeServices = NodeChildProcessSpawner.layer.pipe(
const NodeContext = NodeChildProcessSpawner.layer.pipe(
Layer.provideMerge(Layer.mergeAll(
NodeFileSystem.layer,
NodePath.layer
Expand All @@ -41,7 +41,7 @@ const decodeByteStream = Effect.fnUntraced(
)

describe("NodeChildProcessSpawner", () => {
it.layer(NodeServices)((it) => {
it.layer(NodeContext)((it) => {
describe("spawn", () => {
describe("basic spawning", () => {
it.effect("should spawn a simple command and collect output", () =>
Expand Down Expand Up @@ -925,36 +925,36 @@ describe("NodeChildProcessSpawner", () => {
const handle = yield* Scope.provide(scope)(Effect.gen(function*() {
return yield* longRunningCommand()
})).pipe(
Effect.provide(NodeServices)
Effect.provide(NodeContext)
)

yield* Scope.provide(scope)(handle.unref).pipe(Effect.provide(NodeServices))
yield* Scope.provide(scope)(handle.unref).pipe(Effect.provide(NodeContext))
yield* Scope.close(scope, Exit.void)
yield* TestClock.withLive(Effect.sleep("100 millis"))

const isRunning = yield* handle.isRunning
assert.isTrue(isRunning)

yield* handle.kill({ killSignal: "SIGKILL" })
}).pipe(Effect.provide(NodeServices)))
}).pipe(Effect.provide(NodeContext)))

it.effect("should kill a restored process when scope closes", () =>
Effect.gen(function*() {
const scope = yield* Scope.make()
const handle = yield* Scope.provide(scope)(Effect.gen(function*() {
return yield* longRunningCommand()
})).pipe(
Effect.provide(NodeServices)
Effect.provide(NodeContext)
)

const reref = yield* Scope.provide(scope)(handle.unref).pipe(Effect.provide(NodeServices))
const reref = yield* Scope.provide(scope)(handle.unref).pipe(Effect.provide(NodeContext))
yield* reref
yield* Scope.close(scope, Exit.void)
yield* TestClock.withLive(Effect.sleep("100 millis"))

const isRunning = yield* handle.isRunning
assert.isFalse(isRunning)
}).pipe(Effect.provide(NodeServices)))
}).pipe(Effect.provide(NodeContext)))

it.effect("should resolve exitCode after closing the original scope of an unrefed process", () =>
Effect.gen(function*() {
Expand All @@ -965,14 +965,14 @@ describe("NodeChildProcessSpawner", () => {
stdout: "ignore",
stderr: "ignore"
})
})).pipe(Effect.provide(NodeServices))
})).pipe(Effect.provide(NodeContext))

yield* Scope.provide(scope)(handle.unref).pipe(Effect.provide(NodeServices))
yield* Scope.provide(scope)(handle.unref).pipe(Effect.provide(NodeContext))
yield* Scope.close(scope, Exit.void)

const exitCode = yield* handle.exitCode
assert.strictEqual(exitCode, ChildProcessSpawner.ExitCode(0))
}).pipe(Effect.provide(NodeServices)))
}).pipe(Effect.provide(NodeContext)))

it.effect("should cleanup descendants after an unrefed parent exits non-zero", () =>
Effect.gen(function*() {
Expand All @@ -982,9 +982,9 @@ describe("NodeChildProcessSpawner", () => {

const handle = yield* Scope.provide(scope)(Effect.gen(function*() {
return yield* ChildProcess.make({ cwd })`./parent-exits-early.sh`
})).pipe(Effect.provide(NodeServices))
})).pipe(Effect.provide(NodeContext))

yield* Scope.provide(scope)(handle.unref).pipe(Effect.provide(NodeServices))
yield* Scope.provide(scope)(handle.unref).pipe(Effect.provide(NodeContext))
yield* Scope.close(scope, Exit.void)

const exitCode = yield* handle.exitCode
Expand All @@ -994,7 +994,7 @@ describe("NodeChildProcessSpawner", () => {

const remaining = yield* countMatchingProcesses("sleep 30")
assert.strictEqual(remaining, 0)
}).pipe(Effect.provide(NodeServices)))
}).pipe(Effect.provide(NodeContext)))

it.effect("should unref every process in a pipeline", () =>
Effect.gen(function*() {
Expand All @@ -1016,9 +1016,9 @@ describe("NodeChildProcessSpawner", () => {
})
)
)
})).pipe(Effect.provide(NodeServices))
})).pipe(Effect.provide(NodeContext))

yield* Scope.provide(scope)(handle.unref).pipe(Effect.provide(NodeServices))
yield* Scope.provide(scope)(handle.unref).pipe(Effect.provide(NodeContext))
yield* Scope.close(scope, Exit.void)
yield* TestClock.withLive(Effect.sleep("100 millis"))

Expand All @@ -1029,7 +1029,7 @@ describe("NodeChildProcessSpawner", () => {

yield* killMatchingProcesses(rootMarker)
yield* killMatchingProcesses(tailMarker)
}).pipe(Effect.provide(NodeServices)))
}).pipe(Effect.provide(NodeContext)))
})

it.effect("should not deadlock on large stdout output", () =>
Expand Down
4 changes: 2 additions & 2 deletions packages/platform-node/src/NodeClusterHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization"
import type { SqlClient } from "effect/unstable/sql/SqlClient"
import { createServer } from "node:http"
import { layerK8sHttpClient } from "./NodeClusterSocket.ts"
import type { NodeContext } from "./NodeContext.ts"
import * as NodeHttpClient from "./NodeHttpClient.ts"
import * as NodeHttpServer from "./NodeHttpServer.ts"
import type { NodeServices } from "./NodeServices.ts"
import * as NodeSocket from "./NodeSocket.ts"

export {
Expand Down Expand Up @@ -123,7 +123,7 @@ export const layer = <
export const layerHttpServer: Layer.Layer<
| HttpPlatform
| Etag.Generator
| NodeServices
| NodeContext
| HttpServer,
ServeError,
ShardingConfig.ShardingConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import * as NodeTerminal from "./NodeTerminal.ts"
* @since 1.0.0
* @category models
*/
export type NodeServices = ChildProcessSpawner | FileSystem | Path | Stdio | Terminal
export type NodeContext = ChildProcessSpawner | FileSystem | Path | Stdio | Terminal

/**
* @since 1.0.0
* @category layer
*/
export const layer: Layer.Layer<NodeServices> = Layer.provideMerge(
export const layer: Layer.Layer<NodeContext> = Layer.provideMerge(
NodeChildProcessSpawner.layer,
Layer.mergeAll(
NodeFileSystem.layer,
Expand Down
Loading
Loading