Remove redundant ID Zod overrides (#26633)
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
|
|
||||||
import { Identifier } from "@/id/id"
|
import { Identifier } from "@/id/id"
|
||||||
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
|
import { zod } from "@opencode-ai/core/effect-zod"
|
||||||
import { withStatics } from "@opencode-ai/core/schema"
|
import { withStatics } from "@opencode-ai/core/schema"
|
||||||
|
|
||||||
const workspaceIdSchema = Schema.String.check(Schema.isStartsWith("wrk"))
|
const workspaceIdSchema = Schema.String.check(Schema.isStartsWith("wrk")).pipe(Schema.brand("WorkspaceID"))
|
||||||
.annotate({ [ZodOverride]: Identifier.schema("workspace") })
|
|
||||||
.pipe(Schema.brand("WorkspaceID"))
|
|
||||||
|
|
||||||
export type WorkspaceID = typeof workspaceIdSchema.Type
|
export type WorkspaceID = typeof workspaceIdSchema.Type
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import z from "zod"
|
|
||||||
import { randomBytes } from "crypto"
|
import { randomBytes } from "crypto"
|
||||||
|
|
||||||
const prefixes = {
|
const prefixes = {
|
||||||
@@ -7,19 +6,12 @@ const prefixes = {
|
|||||||
message: "msg",
|
message: "msg",
|
||||||
permission: "per",
|
permission: "per",
|
||||||
question: "que",
|
question: "que",
|
||||||
user: "usr",
|
|
||||||
part: "prt",
|
part: "prt",
|
||||||
pty: "pty",
|
pty: "pty",
|
||||||
tool: "tool",
|
tool: "tool",
|
||||||
workspace: "wrk",
|
workspace: "wrk",
|
||||||
entry: "ent",
|
|
||||||
account: "act",
|
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export function schema(prefix: keyof typeof prefixes) {
|
|
||||||
return z.string().startsWith(prefixes[prefix])
|
|
||||||
}
|
|
||||||
|
|
||||||
const LENGTH = 26
|
const LENGTH = 26
|
||||||
|
|
||||||
// State for monotonic ID generation
|
// State for monotonic ID generation
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
|
|
||||||
import { Identifier } from "@/id/id"
|
import { Identifier } from "@/id/id"
|
||||||
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
|
import { zod } from "@opencode-ai/core/effect-zod"
|
||||||
import { Newtype } from "@opencode-ai/core/schema"
|
import { Newtype } from "@opencode-ai/core/schema"
|
||||||
|
|
||||||
export class PermissionID extends Newtype<PermissionID>()(
|
export class PermissionID extends Newtype<PermissionID>()(
|
||||||
"PermissionID",
|
"PermissionID",
|
||||||
Schema.String.check(Schema.isStartsWith("per")).annotate({ [ZodOverride]: Identifier.schema("permission") }),
|
Schema.String.check(Schema.isStartsWith("per")),
|
||||||
) {
|
) {
|
||||||
static ascending(id?: string): PermissionID {
|
static ascending(id?: string): PermissionID {
|
||||||
return this.make(Identifier.ascending("permission", id))
|
return this.make(Identifier.ascending("permission", id))
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
|
|
||||||
import { Identifier } from "@/id/id"
|
import { Identifier } from "@/id/id"
|
||||||
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
|
import { zod } from "@opencode-ai/core/effect-zod"
|
||||||
import { withStatics } from "@opencode-ai/core/schema"
|
import { withStatics } from "@opencode-ai/core/schema"
|
||||||
|
|
||||||
const ptyIdSchema = Schema.String.check(Schema.isStartsWith("pty"))
|
const ptyIdSchema = Schema.String.check(Schema.isStartsWith("pty")).pipe(Schema.brand("PtyID"))
|
||||||
.annotate({ [ZodOverride]: Identifier.schema("pty") })
|
|
||||||
.pipe(Schema.brand("PtyID"))
|
|
||||||
|
|
||||||
export type PtyID = typeof ptyIdSchema.Type
|
export type PtyID = typeof ptyIdSchema.Type
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
|
|
||||||
import { Identifier } from "@/id/id"
|
import { Identifier } from "@/id/id"
|
||||||
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
|
import { zod } from "@opencode-ai/core/effect-zod"
|
||||||
import { Newtype } from "@opencode-ai/core/schema"
|
import { Newtype } from "@opencode-ai/core/schema"
|
||||||
|
|
||||||
export class QuestionID extends Newtype<QuestionID>()(
|
export class QuestionID extends Newtype<QuestionID>()("QuestionID", Schema.String.check(Schema.isStartsWith("que"))) {
|
||||||
"QuestionID",
|
|
||||||
Schema.String.check(Schema.isStartsWith("que")).annotate({ [ZodOverride]: Identifier.schema("question") }),
|
|
||||||
) {
|
|
||||||
static ascending(id?: string): QuestionID {
|
static ascending(id?: string): QuestionID {
|
||||||
return this.make(Identifier.ascending("question", id))
|
return this.make(Identifier.ascending("question", id))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,35 @@
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
|
|
||||||
import { Identifier } from "@/id/id"
|
import { Identifier } from "@/id/id"
|
||||||
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
|
import { zod } from "@opencode-ai/core/effect-zod"
|
||||||
import { withStatics } from "@opencode-ai/core/schema"
|
import { withStatics } from "@opencode-ai/core/schema"
|
||||||
|
|
||||||
export const SessionID = Schema.String.check(Schema.isStartsWith("ses"))
|
export const SessionID = Schema.String.check(Schema.isStartsWith("ses")).pipe(
|
||||||
.annotate({
|
Schema.brand("SessionID"),
|
||||||
[ZodOverride]: Identifier.schema("session"),
|
withStatics((s) => ({
|
||||||
})
|
descending: (id?: string) => s.make(Identifier.descending("session", id)),
|
||||||
.pipe(
|
zod: zod(s),
|
||||||
Schema.brand("SessionID"),
|
})),
|
||||||
withStatics((s) => ({
|
)
|
||||||
descending: (id?: string) => s.make(Identifier.descending("session", id)),
|
|
||||||
zod: zod(s),
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
|
|
||||||
export type SessionID = Schema.Schema.Type<typeof SessionID>
|
export type SessionID = Schema.Schema.Type<typeof SessionID>
|
||||||
|
|
||||||
export const MessageID = Schema.String.check(Schema.isStartsWith("msg"))
|
export const MessageID = Schema.String.check(Schema.isStartsWith("msg")).pipe(
|
||||||
.annotate({
|
Schema.brand("MessageID"),
|
||||||
[ZodOverride]: Identifier.schema("message"),
|
withStatics((s) => ({
|
||||||
})
|
ascending: (id?: string) => s.make(Identifier.ascending("message", id)),
|
||||||
.pipe(
|
zod: zod(s),
|
||||||
Schema.brand("MessageID"),
|
})),
|
||||||
withStatics((s) => ({
|
)
|
||||||
ascending: (id?: string) => s.make(Identifier.ascending("message", id)),
|
|
||||||
zod: zod(s),
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
|
|
||||||
export type MessageID = Schema.Schema.Type<typeof MessageID>
|
export type MessageID = Schema.Schema.Type<typeof MessageID>
|
||||||
|
|
||||||
export const PartID = Schema.String.check(Schema.isStartsWith("prt"))
|
export const PartID = Schema.String.check(Schema.isStartsWith("prt")).pipe(
|
||||||
.annotate({
|
Schema.brand("PartID"),
|
||||||
[ZodOverride]: Identifier.schema("part"),
|
withStatics((s) => ({
|
||||||
})
|
ascending: (id?: string) => s.make(Identifier.ascending("part", id)),
|
||||||
.pipe(
|
zod: zod(s),
|
||||||
Schema.brand("PartID"),
|
})),
|
||||||
withStatics((s) => ({
|
)
|
||||||
ascending: (id?: string) => s.make(Identifier.ascending("part", id)),
|
|
||||||
zod: zod(s),
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
|
|
||||||
export type PartID = Schema.Schema.Type<typeof PartID>
|
export type PartID = Schema.Schema.Type<typeof PartID>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
|
|
||||||
import { Identifier } from "@/id/id"
|
import { Identifier } from "@/id/id"
|
||||||
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
|
import { zod } from "@opencode-ai/core/effect-zod"
|
||||||
import { withStatics } from "@opencode-ai/core/schema"
|
import { withStatics } from "@opencode-ai/core/schema"
|
||||||
|
|
||||||
export const EventID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("event") }).pipe(
|
export const EventID = Schema.String.check(Schema.isStartsWith("evt")).pipe(
|
||||||
Schema.brand("EventID"),
|
Schema.brand("EventID"),
|
||||||
withStatics((s) => ({
|
withStatics((s) => ({
|
||||||
ascending: (id?: string) => s.make(Identifier.ascending("event", id)),
|
ascending: (id?: string) => s.make(Identifier.ascending("event", id)),
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
|
|
||||||
import { Identifier } from "@/id/id"
|
import { Identifier } from "@/id/id"
|
||||||
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
|
import { zod } from "@opencode-ai/core/effect-zod"
|
||||||
import { withStatics } from "@opencode-ai/core/schema"
|
import { withStatics } from "@opencode-ai/core/schema"
|
||||||
|
|
||||||
const toolIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("tool") }).pipe(Schema.brand("ToolID"))
|
const toolIdSchema = Schema.String.check(Schema.isStartsWith("tool")).pipe(Schema.brand("ToolID"))
|
||||||
|
|
||||||
export type ToolID = typeof toolIdSchema.Type
|
export type ToolID = typeof toolIdSchema.Type
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user