Skip to content

Commit ad7ae73

Browse files
authored
refactor(core): derive all schema.ts leaves' .zod via effect-zod walker (#23754)
1 parent 8043cfa commit ad7ae73

9 files changed

Lines changed: 26 additions & 33 deletions

File tree

packages/opencode/specs/effect/schema.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ Schema at source.
159159
These are the highest-priority next targets. Each is a small, self-contained
160160
schema module with a clear domain.
161161

162-
- [ ] `src/control-plane/schema.ts`
163-
- [ ] `src/permission/schema.ts`
164-
- [ ] `src/project/schema.ts`
162+
- [x] `src/control-plane/schema.ts`
163+
- [x] `src/permission/schema.ts`
164+
- [x] `src/project/schema.ts`
165165
- [x] `src/provider/schema.ts`
166-
- [ ] `src/pty/schema.ts`
167-
- [ ] `src/question/schema.ts`
168-
- [ ] `src/session/schema.ts`
169-
- [ ] `src/sync/schema.ts`
170-
- [ ] `src/tool/schema.ts`
166+
- [x] `src/pty/schema.ts`
167+
- [x] `src/question/schema.ts`
168+
- [x] `src/session/schema.ts`
169+
- [x] `src/sync/schema.ts`
170+
- [x] `src/tool/schema.ts`
171171

172172
### Session domain
173173

packages/opencode/src/control-plane/schema.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Schema } from "effect"
2-
import z from "zod"
32

43
import { Identifier } from "@/id/id"
5-
import { ZodOverride } from "@/util/effect-zod"
4+
import { zod, ZodOverride } from "@/util/effect-zod"
65
import { withStatics } from "@/util/schema"
76

87
const workspaceIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("workspace") }).pipe(
@@ -14,6 +13,6 @@ export type WorkspaceID = typeof workspaceIdSchema.Type
1413
export const WorkspaceID = workspaceIdSchema.pipe(
1514
withStatics((schema: typeof workspaceIdSchema) => ({
1615
ascending: (id?: string) => schema.make(Identifier.ascending("workspace", id)),
17-
zod: Identifier.schema("workspace").pipe(z.custom<WorkspaceID>()),
16+
zod: zod(schema),
1817
})),
1918
)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Schema } from "effect"
2-
import z from "zod"
32

43
import { Identifier } from "@/id/id"
5-
import { ZodOverride } from "@/util/effect-zod"
4+
import { zod, ZodOverride } from "@/util/effect-zod"
65
import { Newtype } from "@/util/schema"
76

87
export class PermissionID extends Newtype<PermissionID>()(
@@ -13,5 +12,5 @@ export class PermissionID extends Newtype<PermissionID>()(
1312
return this.make(Identifier.ascending("permission", id))
1413
}
1514

16-
static readonly zod = Identifier.schema("permission") as unknown as z.ZodType<PermissionID>
15+
static readonly zod = zod(this)
1716
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Schema } from "effect"
2-
import z from "zod"
32

3+
import { zod } from "@/util/effect-zod"
44
import { withStatics } from "@/util/schema"
55

66
const projectIdSchema = Schema.String.pipe(Schema.brand("ProjectID"))
@@ -10,6 +10,6 @@ export type ProjectID = typeof projectIdSchema.Type
1010
export const ProjectID = projectIdSchema.pipe(
1111
withStatics((schema: typeof projectIdSchema) => ({
1212
global: schema.make("global"),
13-
zod: z.string().pipe(z.custom<ProjectID>()),
13+
zod: zod(schema),
1414
})),
1515
)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Schema } from "effect"
2-
import z from "zod"
32

43
import { Identifier } from "@/id/id"
5-
import { ZodOverride } from "@/util/effect-zod"
4+
import { zod, ZodOverride } from "@/util/effect-zod"
65
import { withStatics } from "@/util/schema"
76

87
const ptyIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("pty") }).pipe(Schema.brand("PtyID"))
@@ -12,6 +11,6 @@ export type PtyID = typeof ptyIdSchema.Type
1211
export const PtyID = ptyIdSchema.pipe(
1312
withStatics((schema: typeof ptyIdSchema) => ({
1413
ascending: (id?: string) => schema.make(Identifier.ascending("pty", id)),
15-
zod: Identifier.schema("pty").pipe(z.custom<PtyID>()),
14+
zod: zod(schema),
1615
})),
1716
)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Schema } from "effect"
2-
import z from "zod"
32

43
import { Identifier } from "@/id/id"
5-
import { ZodOverride } from "@/util/effect-zod"
4+
import { zod, ZodOverride } from "@/util/effect-zod"
65
import { Newtype } from "@/util/schema"
76

87
export class QuestionID extends Newtype<QuestionID>()(
@@ -13,5 +12,5 @@ export class QuestionID extends Newtype<QuestionID>()(
1312
return this.make(Identifier.ascending("question", id))
1413
}
1514

16-
static readonly zod = Identifier.schema("question") as unknown as z.ZodType<QuestionID>
15+
static readonly zod = zod(this)
1716
}

packages/opencode/src/session/schema.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { Schema } from "effect"
2-
import z from "zod"
32

43
import { Identifier } from "@/id/id"
5-
import { ZodOverride } from "@/util/effect-zod"
4+
import { zod, ZodOverride } from "@/util/effect-zod"
65
import { withStatics } from "@/util/schema"
76

87
export const SessionID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("session") }).pipe(
98
Schema.brand("SessionID"),
109
withStatics((s) => ({
1110
descending: (id?: string) => s.make(Identifier.descending("session", id)),
12-
zod: Identifier.schema("session").pipe(z.custom<Schema.Schema.Type<typeof s>>()),
11+
zod: zod(s),
1312
})),
1413
)
1514

@@ -19,7 +18,7 @@ export const MessageID = Schema.String.annotate({ [ZodOverride]: Identifier.sche
1918
Schema.brand("MessageID"),
2019
withStatics((s) => ({
2120
ascending: (id?: string) => s.make(Identifier.ascending("message", id)),
22-
zod: Identifier.schema("message").pipe(z.custom<Schema.Schema.Type<typeof s>>()),
21+
zod: zod(s),
2322
})),
2423
)
2524

@@ -29,7 +28,7 @@ export const PartID = Schema.String.annotate({ [ZodOverride]: Identifier.schema(
2928
Schema.brand("PartID"),
3029
withStatics((s) => ({
3130
ascending: (id?: string) => s.make(Identifier.ascending("part", id)),
32-
zod: Identifier.schema("part").pipe(z.custom<Schema.Schema.Type<typeof s>>()),
31+
zod: zod(s),
3332
})),
3433
)
3534

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { Schema } from "effect"
2-
import z from "zod"
32

43
import { Identifier } from "@/id/id"
5-
import { ZodOverride } from "@/util/effect-zod"
4+
import { zod, ZodOverride } from "@/util/effect-zod"
65
import { withStatics } from "@/util/schema"
76

87
export const EventID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("event") }).pipe(
98
Schema.brand("EventID"),
109
withStatics((s) => ({
1110
ascending: (id?: string) => s.make(Identifier.ascending("event", id)),
12-
zod: Identifier.schema("event").pipe(z.custom<Schema.Schema.Type<typeof s>>()),
11+
zod: zod(s),
1312
})),
1413
)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Schema } from "effect"
2-
import z from "zod"
32

43
import { Identifier } from "@/id/id"
5-
import { ZodOverride } from "@/util/effect-zod"
4+
import { zod, ZodOverride } from "@/util/effect-zod"
65
import { withStatics } from "@/util/schema"
76

87
const toolIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("tool") }).pipe(Schema.brand("ToolID"))
@@ -12,6 +11,6 @@ export type ToolID = typeof toolIdSchema.Type
1211
export const ToolID = toolIdSchema.pipe(
1312
withStatics((schema: typeof toolIdSchema) => ({
1413
ascending: (id?: string) => schema.make(Identifier.ascending("tool", id)),
15-
zod: Identifier.schema("tool").pipe(z.custom<ToolID>()),
14+
zod: zod(schema),
1615
})),
1716
)

0 commit comments

Comments
 (0)