Skip to content

Commit fb4bab8

Browse files
authored
Remove redundant ID Zod overrides (#26633)
1 parent b3526f6 commit fb4bab8

8 files changed

Lines changed: 34 additions & 61 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { withStatics } from "@opencode-ai/core/schema"
66

7-
const workspaceIdSchema = Schema.String.check(Schema.isStartsWith("wrk"))
8-
.annotate({ [ZodOverride]: Identifier.schema("workspace") })
9-
.pipe(Schema.brand("WorkspaceID"))
7+
const workspaceIdSchema = Schema.String.check(Schema.isStartsWith("wrk")).pipe(Schema.brand("WorkspaceID"))
108

119
export type WorkspaceID = typeof workspaceIdSchema.Type
1210

packages/opencode/src/id/id.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import z from "zod"
21
import { randomBytes } from "crypto"
32

43
const prefixes = {
@@ -7,19 +6,12 @@ const prefixes = {
76
message: "msg",
87
permission: "per",
98
question: "que",
10-
user: "usr",
119
part: "prt",
1210
pty: "pty",
1311
tool: "tool",
1412
workspace: "wrk",
15-
entry: "ent",
16-
account: "act",
1713
} as const
1814

19-
export function schema(prefix: keyof typeof prefixes) {
20-
return z.string().startsWith(prefixes[prefix])
21-
}
22-
2315
const LENGTH = 26
2416

2517
// State for monotonic ID generation

packages/opencode/src/permission/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { Newtype } from "@opencode-ai/core/schema"
66

77
export class PermissionID extends Newtype<PermissionID>()(
88
"PermissionID",
9-
Schema.String.check(Schema.isStartsWith("per")).annotate({ [ZodOverride]: Identifier.schema("permission") }),
9+
Schema.String.check(Schema.isStartsWith("per")),
1010
) {
1111
static ascending(id?: string): PermissionID {
1212
return this.make(Identifier.ascending("permission", id))

packages/opencode/src/pty/schema.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { withStatics } from "@opencode-ai/core/schema"
66

7-
const ptyIdSchema = Schema.String.check(Schema.isStartsWith("pty"))
8-
.annotate({ [ZodOverride]: Identifier.schema("pty") })
9-
.pipe(Schema.brand("PtyID"))
7+
const ptyIdSchema = Schema.String.check(Schema.isStartsWith("pty")).pipe(Schema.brand("PtyID"))
108

119
export type PtyID = typeof ptyIdSchema.Type
1210

packages/opencode/src/question/schema.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { Newtype } from "@opencode-ai/core/schema"
66

7-
export class QuestionID extends Newtype<QuestionID>()(
8-
"QuestionID",
9-
Schema.String.check(Schema.isStartsWith("que")).annotate({ [ZodOverride]: Identifier.schema("question") }),
10-
) {
7+
export class QuestionID extends Newtype<QuestionID>()("QuestionID", Schema.String.check(Schema.isStartsWith("que"))) {
118
static ascending(id?: string): QuestionID {
129
return this.make(Identifier.ascending("question", id))
1310
}
Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,35 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { withStatics } from "@opencode-ai/core/schema"
66

7-
export const SessionID = Schema.String.check(Schema.isStartsWith("ses"))
8-
.annotate({
9-
[ZodOverride]: Identifier.schema("session"),
10-
})
11-
.pipe(
12-
Schema.brand("SessionID"),
13-
withStatics((s) => ({
14-
descending: (id?: string) => s.make(Identifier.descending("session", id)),
15-
zod: zod(s),
16-
})),
17-
)
7+
export const SessionID = Schema.String.check(Schema.isStartsWith("ses")).pipe(
8+
Schema.brand("SessionID"),
9+
withStatics((s) => ({
10+
descending: (id?: string) => s.make(Identifier.descending("session", id)),
11+
zod: zod(s),
12+
})),
13+
)
1814

1915
export type SessionID = Schema.Schema.Type<typeof SessionID>
2016

21-
export const MessageID = Schema.String.check(Schema.isStartsWith("msg"))
22-
.annotate({
23-
[ZodOverride]: Identifier.schema("message"),
24-
})
25-
.pipe(
26-
Schema.brand("MessageID"),
27-
withStatics((s) => ({
28-
ascending: (id?: string) => s.make(Identifier.ascending("message", id)),
29-
zod: zod(s),
30-
})),
31-
)
17+
export const MessageID = Schema.String.check(Schema.isStartsWith("msg")).pipe(
18+
Schema.brand("MessageID"),
19+
withStatics((s) => ({
20+
ascending: (id?: string) => s.make(Identifier.ascending("message", id)),
21+
zod: zod(s),
22+
})),
23+
)
3224

3325
export type MessageID = Schema.Schema.Type<typeof MessageID>
3426

35-
export const PartID = Schema.String.check(Schema.isStartsWith("prt"))
36-
.annotate({
37-
[ZodOverride]: Identifier.schema("part"),
38-
})
39-
.pipe(
40-
Schema.brand("PartID"),
41-
withStatics((s) => ({
42-
ascending: (id?: string) => s.make(Identifier.ascending("part", id)),
43-
zod: zod(s),
44-
})),
45-
)
27+
export const PartID = Schema.String.check(Schema.isStartsWith("prt")).pipe(
28+
Schema.brand("PartID"),
29+
withStatics((s) => ({
30+
ascending: (id?: string) => s.make(Identifier.ascending("part", id)),
31+
zod: zod(s),
32+
})),
33+
)
4634

4735
export type PartID = Schema.Schema.Type<typeof PartID>

packages/opencode/src/sync/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { withStatics } from "@opencode-ai/core/schema"
66

7-
export const EventID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("event") }).pipe(
7+
export const EventID = Schema.String.check(Schema.isStartsWith("evt")).pipe(
88
Schema.brand("EventID"),
99
withStatics((s) => ({
1010
ascending: (id?: string) => s.make(Identifier.ascending("event", id)),

packages/opencode/src/tool/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { withStatics } from "@opencode-ai/core/schema"
66

7-
const toolIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("tool") }).pipe(Schema.brand("ToolID"))
7+
const toolIdSchema = Schema.String.check(Schema.isStartsWith("tool")).pipe(Schema.brand("ToolID"))
88

99
export type ToolID = typeof toolIdSchema.Type
1010

0 commit comments

Comments
 (0)