Skip to content

Commit 9b77430

Browse files
authored
refactor: collapse env barrel into env/index.ts (#22900)
1 parent 1045a43 commit 9b77430

2 files changed

Lines changed: 37 additions & 36 deletions

File tree

packages/opencode/src/env/env.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

packages/opencode/src/env/index.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,37 @@
1-
export * as Env from "./env"
1+
import { Context, Effect, Layer } from "effect"
2+
import { InstanceState } from "@/effect"
3+
4+
type State = Record<string, string | undefined>
5+
6+
export interface Interface {
7+
readonly get: (key: string) => Effect.Effect<string | undefined>
8+
readonly all: () => Effect.Effect<State>
9+
readonly set: (key: string, value: string) => Effect.Effect<void>
10+
readonly remove: (key: string) => Effect.Effect<void>
11+
}
12+
13+
export class Service extends Context.Service<Service, Interface>()("@opencode/Env") {}
14+
15+
export const layer = Layer.effect(
16+
Service,
17+
Effect.gen(function* () {
18+
const state = yield* InstanceState.make<State>(Effect.fn("Env.state")(() => Effect.succeed({ ...process.env })))
19+
20+
const get = Effect.fn("Env.get")((key: string) => InstanceState.use(state, (env) => env[key]))
21+
const all = Effect.fn("Env.all")(() => InstanceState.get(state))
22+
const set = Effect.fn("Env.set")(function* (key: string, value: string) {
23+
const env = yield* InstanceState.get(state)
24+
env[key] = value
25+
})
26+
const remove = Effect.fn("Env.remove")(function* (key: string) {
27+
const env = yield* InstanceState.get(state)
28+
delete env[key]
29+
})
30+
31+
return Service.of({ get, all, set, remove })
32+
}),
33+
)
34+
35+
export const defaultLayer = layer
36+
37+
export * as Env from "."

0 commit comments

Comments
 (0)