Skip to content

Commit eb1f3a9

Browse files
Apply PR #18266: effectify Installation service, drop Effect suffix from namespaces
2 parents 3b446f8 + af69bc1 commit eb1f3a9

14 files changed

Lines changed: 501 additions & 315 deletions

File tree

packages/opencode/src/account/effect.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AccountRepo, type AccountRow } from "./repo"
66
import {
77
type AccountError,
88
AccessToken,
9-
Account,
9+
Account as AccountSchema,
1010
AccountID,
1111
DeviceCode,
1212
RefreshToken,
@@ -24,10 +24,30 @@ import {
2424
UserCode,
2525
} from "./schema"
2626

27-
export * from "./schema"
27+
export {
28+
Account as AccountSchema,
29+
AccountID,
30+
type AccountError,
31+
AccountRepoError,
32+
AccountServiceError,
33+
AccessToken,
34+
RefreshToken,
35+
DeviceCode,
36+
UserCode,
37+
Org,
38+
OrgID,
39+
Login,
40+
PollSuccess,
41+
PollPending,
42+
PollSlow,
43+
PollExpired,
44+
PollDenied,
45+
PollError,
46+
PollResult,
47+
} from "./schema"
2848

2949
export type AccountOrgs = {
30-
account: Account
50+
account: AccountSchema
3151
orgs: readonly Org[]
3252
}
3353

@@ -108,10 +128,10 @@ const mapAccountServiceError =
108128
),
109129
)
110130

111-
export namespace AccountEffect {
131+
export namespace Account {
112132
export interface Interface {
113-
readonly active: () => Effect.Effect<Option.Option<Account>, AccountError>
114-
readonly list: () => Effect.Effect<Account[], AccountError>
133+
readonly active: () => Effect.Effect<Option.Option<AccountSchema>, AccountError>
134+
readonly list: () => Effect.Effect<AccountSchema[], AccountError>
115135
readonly orgsByAccount: () => Effect.Effect<readonly AccountOrgs[], AccountError>
116136
readonly remove: (accountID: AccountID) => Effect.Effect<void, AccountError>
117137
readonly use: (accountID: AccountID, orgID: Option.Option<OrgID>) => Effect.Effect<void, AccountError>

packages/opencode/src/account/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { Effect, Option } from "effect"
22

33
import {
4-
Account as AccountSchema,
4+
Account as S,
5+
AccountSchema,
56
type AccountError,
67
type AccessToken,
78
AccountID,
8-
AccountEffect,
99
OrgID,
1010
} from "./effect"
1111

1212
export { AccessToken, AccountID, OrgID } from "./effect"
1313

1414
import { runtime } from "@/effect/runtime"
1515

16-
function runSync<A>(f: (service: AccountEffect.Interface) => Effect.Effect<A, AccountError>) {
17-
return runtime.runSync(AccountEffect.Service.use(f))
16+
function runSync<A>(f: (service: S.Interface) => Effect.Effect<A, AccountError>) {
17+
return runtime.runSync(S.Service.use(f))
1818
}
1919

20-
function runPromise<A>(f: (service: AccountEffect.Interface) => Effect.Effect<A, AccountError>) {
21-
return runtime.runPromise(AccountEffect.Service.use(f))
20+
function runPromise<A>(f: (service: S.Interface) => Effect.Effect<A, AccountError>) {
21+
return runtime.runPromise(S.Service.use(f))
2222
}
2323

2424
export namespace Account {

packages/opencode/src/auth/effect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const file = path.join(Global.Path.data, "auth.json")
3737

3838
const fail = (message: string) => (cause: unknown) => new AuthError({ message, cause })
3939

40-
export namespace AuthEffect {
40+
export namespace Auth {
4141
export interface Interface {
4242
readonly get: (providerID: string) => Effect.Effect<Info | undefined, AuthError>
4343
readonly all: () => Effect.Effect<Record<string, Info>, AuthError>

packages/opencode/src/auth/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as S from "./effect"
55

66
export { OAUTH_DUMMY_KEY } from "./effect"
77

8-
function runPromise<A>(f: (service: S.AuthEffect.Interface) => Effect.Effect<A, S.AuthError>) {
9-
return runtime.runPromise(S.AuthEffect.Service.use(f))
8+
function runPromise<A>(f: (service: S.Auth.Interface) => Effect.Effect<A, S.AuthError>) {
9+
return runtime.runPromise(S.Auth.Service.use(f))
1010
}
1111

1212
export namespace Auth {

packages/opencode/src/cli/cmd/account.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { cmd } from "./cmd"
22
import { Duration, Effect, Match, Option } from "effect"
33
import { UI } from "../ui"
44
import { runtime } from "@/effect/runtime"
5-
import { AccountID, AccountEffect, OrgID, PollExpired, type PollResult } from "@/account/effect"
5+
import { AccountID, Account, OrgID, PollExpired, type PollResult } from "@/account/effect"
66
import { type AccountError } from "@/account/schema"
77
import * as Prompt from "../effect/prompt"
88
import open from "open"
@@ -17,7 +17,7 @@ const isActiveOrgChoice = (
1717
) => Option.isSome(active) && active.value.id === choice.accountID && active.value.active_org_id === choice.orgID
1818

1919
const loginEffect = Effect.fn("login")(function* (url: string) {
20-
const service = yield* AccountEffect.Service
20+
const service = yield* Account.Service
2121

2222
yield* Prompt.intro("Log in")
2323
const login = yield* service.login(url)
@@ -58,7 +58,7 @@ const loginEffect = Effect.fn("login")(function* (url: string) {
5858
})
5959

6060
const logoutEffect = Effect.fn("logout")(function* (email?: string) {
61-
const service = yield* AccountEffect.Service
61+
const service = yield* Account.Service
6262
const accounts = yield* service.list()
6363
if (accounts.length === 0) return yield* println("Not logged in")
6464

@@ -98,7 +98,7 @@ interface OrgChoice {
9898
}
9999

100100
const switchEffect = Effect.fn("switch")(function* () {
101-
const service = yield* AccountEffect.Service
101+
const service = yield* Account.Service
102102

103103
const groups = yield* service.orgsByAccount()
104104
if (groups.length === 0) return yield* println("Not logged in")
@@ -129,7 +129,7 @@ const switchEffect = Effect.fn("switch")(function* () {
129129
})
130130

131131
const orgsEffect = Effect.fn("orgs")(function* () {
132-
const service = yield* AccountEffect.Service
132+
const service = yield* Account.Service
133133

134134
const groups = yield* service.orgsByAccount()
135135
if (groups.length === 0) return yield* println("No accounts found")

packages/opencode/src/cli/cmd/upgrade.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ export const UpgradeCommand = {
5858
spinner.stop("Upgrade failed", 1)
5959
if (err instanceof Installation.UpgradeFailedError) {
6060
// necessary because choco only allows install/upgrade in elevated terminals
61-
if (method === "choco" && err.data.stderr.includes("not running from an elevated command shell")) {
61+
if (method === "choco" && err.stderr.includes("not running from an elevated command shell")) {
6262
prompts.log.error("Please run the terminal as Administrator and try again")
6363
} else {
64-
prompts.log.error(err.data.stderr)
64+
prompts.log.error(err.stderr)
6565
}
6666
} else if (err instanceof Error) prompts.log.error(err.message)
6767
prompts.outro("Done")

packages/opencode/src/effect/runtime.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { Effect, Layer, ManagedRuntime } from "effect"
2-
import { AccountEffect } from "@/account/effect"
3-
import { AuthEffect } from "@/auth/effect"
2+
import { Account } from "@/account/effect"
3+
import { Auth } from "@/auth/effect"
44
import { Instances } from "@/effect/instances"
55
import type { InstanceServices } from "@/effect/instances"
6-
import { TruncateEffect } from "@/tool/truncate-effect"
6+
import { Installation } from "@/installation"
7+
import { Truncate } from "@/tool/truncate-effect"
78
import { Instance } from "@/project/instance"
89

910
export const runtime = ManagedRuntime.make(
1011
Layer.mergeAll(
11-
AccountEffect.defaultLayer, //
12-
TruncateEffect.defaultLayer,
12+
Account.defaultLayer, //
13+
Installation.defaultLayer,
14+
Truncate.defaultLayer,
1315
Instances.layer,
14-
).pipe(Layer.provideMerge(AuthEffect.layer)),
16+
).pipe(Layer.provideMerge(Auth.layer)),
1517
)
1618

1719
export function runPromiseInstance<A, E>(effect: Effect.Effect<A, E, InstanceServices>) {

0 commit comments

Comments
 (0)