GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(control-plane): migrate workspace DTO schemas (#24056) · githubhjs/opencode@31d01d4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode
    • specs/effect
      • schema.md
    • src
      • control-plane
        • adaptors
          • index.ts
          • worktree.ts
        • types.ts
        • workspace.ts
      • server/routes/control
        • workspace.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/specs/effect/schema.md‎

Copy file name to clipboardExpand all lines: packages/opencode/specs/effect/schema.md
+3-3Lines changed: 3 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ piecewise.
354354
- [ ] `src/cli/cmd/tui/event.ts`
355355
- [ ] `src/cli/ui.ts`
356356
- [ ] `src/command/index.ts`
357-
- [ ] `src/control-plane/adaptors/worktree.ts`
358-
- [ ] `src/control-plane/types.ts`
359-
- [ ] `src/control-plane/workspace.ts`
357+
- [x] `src/control-plane/adaptors/worktree.ts`
358+
- [x] `src/control-plane/types.ts`
359+
- [x] `src/control-plane/workspace.ts`
360360
- [ ] `src/file/index.ts`
361361
- [ ] `src/file/ripgrep.ts`
362362
- [ ] `src/file/watcher.ts`
Collapse file

‎packages/opencode/src/control-plane/adaptors/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/control-plane/adaptors/index.ts
+1-7Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { lazy } from "@/util/lazy"
22
import type { ProjectID } from "@/project/schema"
3-
import type { WorkspaceAdaptor } from "../types"
4-
5-
export type WorkspaceAdaptorEntry = {
6-
type: string
7-
name: string
8-
description: string
9-
}
3+
import type { WorkspaceAdaptor, WorkspaceAdaptorEntry } from "../types"
104

115
const BUILTIN: Record<string, () => Promise<WorkspaceAdaptor>> = {
126
worktree: lazy(async () => (await import("./worktree")).WorktreeAdaptor),
Collapse file

‎packages/opencode/src/control-plane/adaptors/worktree.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/control-plane/adaptors/worktree.ts
+11-9Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import z from "zod"
1+
import { Schema } from "effect"
22
import { AppRuntime } from "@/effect/app-runtime"
33
import { Worktree } from "@/worktree"
44
import { type WorkspaceAdaptor, WorkspaceInfo } from "../types"
5+
import { zod } from "@/util/effect-zod"
6+
import { withStatics } from "@/util/schema"
57

6-
const WorktreeConfig = z.object({
7-
name: WorkspaceInfo.shape.name,
8-
branch: WorkspaceInfo.shape.branch.unwrap(),
9-
directory: WorkspaceInfo.shape.directory.unwrap(),
10-
})
8+
const WorktreeConfig = Schema.Struct({
9+
name: WorkspaceInfo.fields.name,
10+
branch: Schema.String,
11+
directory: Schema.String,
12+
}).pipe(withStatics((s) => ({ zod: zod(s) })))
1113

1214
export const WorktreeAdaptor: WorkspaceAdaptor = {
1315
name: "Worktree",
@@ -22,7 +24,7 @@ export const WorktreeAdaptor: WorkspaceAdaptor = {
2224
}
2325
},
2426
async create(info) {
25-
const config = WorktreeConfig.parse(info)
27+
const config = WorktreeConfig.zod.parse(info)
2628
await AppRuntime.runPromise(
2729
Worktree.Service.use((svc) =>
2830
svc.createFromInfo({
@@ -34,11 +36,11 @@ export const WorktreeAdaptor: WorkspaceAdaptor = {
3436
)
3537
},
3638
async remove(info) {
37-
const config = WorktreeConfig.parse(info)
39+
const config = WorktreeConfig.zod.parse(info)
3840
await AppRuntime.runPromise(Worktree.Service.use((svc) => svc.remove({ directory: config.directory })))
3941
},
4042
target(info) {
41-
const config = WorktreeConfig.parse(info)
43+
const config = WorktreeConfig.zod.parse(info)
4244
return {
4345
type: "local",
4446
directory: config.directory,
Collapse file

‎packages/opencode/src/control-plane/types.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/control-plane/types.ts
+21-10Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
import z from "zod"
1+
import { Schema } from "effect"
22
import { ProjectID } from "@/project/schema"
33
import { WorkspaceID } from "./schema"
4+
import { zod } from "@/util/effect-zod"
5+
import { type DeepMutable, withStatics } from "@/util/schema"
46

5-
export const WorkspaceInfo = z.object({
6-
id: WorkspaceID.zod,
7-
type: z.string(),
8-
name: z.string(),
9-
branch: z.string().nullable(),
10-
directory: z.string().nullable(),
11-
extra: z.unknown().nullable(),
12-
projectID: ProjectID.zod,
7+
export const WorkspaceInfo = Schema.Struct({
8+
id: WorkspaceID,
9+
type: Schema.String,
10+
name: Schema.String,
11+
branch: Schema.NullOr(Schema.String),
12+
directory: Schema.NullOr(Schema.String),
13+
extra: Schema.NullOr(Schema.Unknown),
14+
projectID: ProjectID,
1315
})
14-
export type WorkspaceInfo = z.infer<typeof WorkspaceInfo>
16+
.annotate({ identifier: "Workspace" })
17+
.pipe(withStatics((s) => ({ zod: zod(s) })))
18+
export type WorkspaceInfo = DeepMutable<Schema.Schema.Type<typeof WorkspaceInfo>>
19+
20+
export const WorkspaceAdaptorEntry = Schema.Struct({
21+
type: Schema.String,
22+
name: Schema.String,
23+
description: Schema.String,
24+
}).pipe(withStatics((s) => ({ zod: zod(s) })))
25+
export type WorkspaceAdaptorEntry = Schema.Schema.Type<typeof WorkspaceAdaptorEntry>
1526

1627
export type Target =
1728
| {
Collapse file

‎packages/opencode/src/control-plane/workspace.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/control-plane/workspace.ts
+20-20Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import z from "zod"
21
import { Schema } from "effect"
32
import { setTimeout as sleep } from "node:timers/promises"
43
import { fn } from "@/util/fn"
@@ -16,7 +15,7 @@ import { ProjectID } from "@/project/schema"
1615
import { Slug } from "@opencode-ai/shared/util/slug"
1716
import { WorkspaceTable } from "./workspace.sql"
1817
import { getAdaptor } from "./adaptors"
19-
import { WorkspaceInfo } from "./types"
18+
import { type WorkspaceInfo, WorkspaceInfo as WorkspaceInfoSchema } from "./types"
2019
import { WorkspaceID } from "./schema"
2120
import { parseSSE } from "./sse"
2221
import { Session } from "@/session"
@@ -26,12 +25,11 @@ import { errorData } from "@/util/error"
2625
import { AppRuntime } from "@/effect/app-runtime"
2726
import { waitEvent } from "./util"
2827
import { WorkspaceContext } from "./workspace-context"
29-
import { NonNegativeInt } from "@/util/schema"
28+
import { NonNegativeInt, withStatics } from "@/util/schema"
29+
import { zod as effectZod, zodObject } from "@/util/effect-zod"
3030

31-
export const Info = WorkspaceInfo.meta({
32-
ref: "Workspace",
33-
})
34-
export type Info = z.infer<typeof Info>
31+
export const Info = WorkspaceInfoSchema
32+
export type Info = WorkspaceInfo
3533

3634
export const ConnectionStatus = Schema.Struct({
3735
workspaceID: WorkspaceID,
@@ -75,15 +73,16 @@ function fromRow(row: typeof WorkspaceTable.$inferSelect): Info {
7573
}
7674
}
7775

78-
const CreateInput = z.object({
79-
id: WorkspaceID.zod.optional(),
80-
type: Info.shape.type,
81-
branch: Info.shape.branch,
82-
projectID: ProjectID.zod,
83-
extra: Info.shape.extra,
84-
})
76+
export const CreateInput = Schema.Struct({
77+
id: Schema.optional(WorkspaceID),
78+
type: Info.fields.type,
79+
branch: Info.fields.branch,
80+
projectID: ProjectID,
81+
extra: Info.fields.extra,
82+
}).pipe(withStatics((s) => ({ zod: effectZod(s), zodObject: zodObject(s) })))
83+
export type CreateInput = Schema.Schema.Type<typeof CreateInput>
8584

86-
export const create = fn(CreateInput, async (input) => {
85+
export const create = fn(CreateInput.zod, async (input) => {
8786
const id = WorkspaceID.ascending(input.id)
8887
const adaptor = await getAdaptor(input.projectID, input.type)
8988

@@ -139,12 +138,13 @@ export const create = fn(CreateInput, async (input) => {
139138
return info
140139
})
141140

142-
const SessionRestoreInput = z.object({
143-
workspaceID: WorkspaceID.zod,
144-
sessionID: SessionID.zod,
145-
})
141+
export const SessionRestoreInput = Schema.Struct({
142+
workspaceID: WorkspaceID,
143+
sessionID: SessionID,
144+
}).pipe(withStatics((s) => ({ zod: effectZod(s), zodObject: zodObject(s) })))
145+
export type SessionRestoreInput = Schema.Schema.Type<typeof SessionRestoreInput>
146146

147-
export const sessionRestore = fn(SessionRestoreInput, async (input) => {
147+
export const sessionRestore = fn(SessionRestoreInput.zod, async (input) => {
148148
log.info("session restore requested", {
149149
workspaceID: input.workspaceID,
150150
sessionID: input.sessionID,
Collapse file

‎packages/opencode/src/server/routes/control/workspace.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/server/routes/control/workspace.ts
+11-16Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describeRoute, resolver, validator } from "hono-openapi"
33
import z from "zod"
44
import { listAdaptors } from "@/control-plane/adaptors"
55
import { Workspace } from "@/control-plane/workspace"
6+
import { WorkspaceAdaptorEntry } from "@/control-plane/types"
67
import { zodObject } from "@/util/effect-zod"
78
import { Instance } from "@/project/instance"
89
import { errors } from "../../error"
@@ -26,13 +27,7 @@ export const WorkspaceRoutes = lazy(() =>
2627
content: {
2728
"application/json": {
2829
schema: resolver(
29-
z.array(
30-
z.object({
31-
type: z.string(),
32-
name: z.string(),
33-
description: z.string(),
34-
}),
35-
),
30+
z.array(zodObject(WorkspaceAdaptorEntry)),
3631
),
3732
},
3833
},
@@ -54,7 +49,7 @@ export const WorkspaceRoutes = lazy(() =>
5449
description: "Workspace created",
5550
content: {
5651
"application/json": {
57-
schema: resolver(Workspace.Info),
52+
schema: resolver(Workspace.Info.zod),
5853
},
5954
},
6055
},
@@ -63,12 +58,12 @@ export const WorkspaceRoutes = lazy(() =>
6358
}),
6459
validator(
6560
"json",
66-
Workspace.create.schema.omit({
61+
Workspace.CreateInput.zodObject.omit({
6762
projectID: true,
6863
}),
6964
),
7065
async (c) => {
71-
const body = c.req.valid("json")
66+
const body = c.req.valid("json") as Omit<Workspace.CreateInput, "projectID">
7267
const workspace = await Workspace.create({
7368
projectID: Instance.project.id,
7469
...body,
@@ -87,7 +82,7 @@ export const WorkspaceRoutes = lazy(() =>
8782
description: "Workspaces",
8883
content: {
8984
"application/json": {
90-
schema: resolver(z.array(Workspace.Info)),
85+
schema: resolver(z.array(Workspace.Info.zod)),
9186
},
9287
},
9388
},
@@ -130,7 +125,7 @@ export const WorkspaceRoutes = lazy(() =>
130125
description: "Workspace removed",
131126
content: {
132127
"application/json": {
133-
schema: resolver(Workspace.Info.optional()),
128+
schema: resolver(Workspace.Info.zod.optional()),
134129
},
135130
},
136131
},
@@ -140,7 +135,7 @@ export const WorkspaceRoutes = lazy(() =>
140135
validator(
141136
"param",
142137
z.object({
143-
id: Workspace.Info.shape.id,
138+
id: zodObject(Workspace.Info).shape.id,
144139
}),
145140
),
146141
async (c) => {
@@ -170,11 +165,11 @@ export const WorkspaceRoutes = lazy(() =>
170165
...errors(400),
171166
},
172167
}),
173-
validator("param", z.object({ id: Workspace.Info.shape.id })),
174-
validator("json", Workspace.sessionRestore.schema.omit({ workspaceID: true })),
168+
validator("param", z.object({ id: zodObject(Workspace.Info).shape.id })),
169+
validator("json", Workspace.SessionRestoreInput.zodObject.omit({ workspaceID: true })),
175170
async (c) => {
176171
const { id } = c.req.valid("param")
177-
const body = c.req.valid("json")
172+
const body = c.req.valid("json") as Omit<Workspace.SessionRestoreInput, "workspaceID">
178173
log.info("session restore route requested", {
179174
workspaceID: id,
180175
sessionID: body.sessionID,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.