refactor(schema): inline branded ID schemas (#17504)
This commit is contained in:
@@ -1,41 +1,38 @@
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
import z from "zod"
|
import z from "zod"
|
||||||
|
|
||||||
import { withStatics } from "@/util/schema"
|
|
||||||
import { Identifier } from "@/id/id"
|
import { Identifier } from "@/id/id"
|
||||||
|
import { withStatics } from "@/util/schema"
|
||||||
|
|
||||||
const sessionIdSchema = Schema.String.pipe(Schema.brand("SessionID"))
|
export const SessionID = Schema.String.pipe(
|
||||||
|
Schema.brand("SessionID"),
|
||||||
export type SessionID = typeof sessionIdSchema.Type
|
withStatics((s) => ({
|
||||||
|
make: (id: string) => s.makeUnsafe(id),
|
||||||
export const SessionID = sessionIdSchema.pipe(
|
descending: (id?: string) => s.makeUnsafe(Identifier.descending("session", id)),
|
||||||
withStatics((schema: typeof sessionIdSchema) => ({
|
zod: Identifier.schema("session").pipe(z.custom<Schema.Schema.Type<typeof s>>()),
|
||||||
make: (id: string) => schema.makeUnsafe(id),
|
|
||||||
descending: (id?: string) => schema.makeUnsafe(Identifier.descending("session", id)),
|
|
||||||
zod: Identifier.schema("session").pipe(z.custom<SessionID>()),
|
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
const messageIdSchema = Schema.String.pipe(Schema.brand("MessageID"))
|
export type SessionID = Schema.Schema.Type<typeof SessionID>
|
||||||
|
|
||||||
export type MessageID = typeof messageIdSchema.Type
|
export const MessageID = Schema.String.pipe(
|
||||||
|
Schema.brand("MessageID"),
|
||||||
export const MessageID = messageIdSchema.pipe(
|
withStatics((s) => ({
|
||||||
withStatics((schema: typeof messageIdSchema) => ({
|
make: (id: string) => s.makeUnsafe(id),
|
||||||
make: (id: string) => schema.makeUnsafe(id),
|
ascending: (id?: string) => s.makeUnsafe(Identifier.ascending("message", id)),
|
||||||
ascending: (id?: string) => schema.makeUnsafe(Identifier.ascending("message", id)),
|
zod: Identifier.schema("message").pipe(z.custom<Schema.Schema.Type<typeof s>>()),
|
||||||
zod: Identifier.schema("message").pipe(z.custom<MessageID>()),
|
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
const partIdSchema = Schema.String.pipe(Schema.brand("PartID"))
|
export type MessageID = Schema.Schema.Type<typeof MessageID>
|
||||||
|
|
||||||
export type PartID = typeof partIdSchema.Type
|
export const PartID = Schema.String.pipe(
|
||||||
|
Schema.brand("PartID"),
|
||||||
export const PartID = partIdSchema.pipe(
|
withStatics((s) => ({
|
||||||
withStatics((schema: typeof partIdSchema) => ({
|
make: (id: string) => s.makeUnsafe(id),
|
||||||
make: (id: string) => schema.makeUnsafe(id),
|
ascending: (id?: string) => s.makeUnsafe(Identifier.ascending("part", id)),
|
||||||
ascending: (id?: string) => schema.makeUnsafe(Identifier.ascending("part", id)),
|
zod: Identifier.schema("part").pipe(z.custom<Schema.Schema.Type<typeof s>>()),
|
||||||
zod: Identifier.schema("part").pipe(z.custom<PartID>()),
|
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export type PartID = Schema.Schema.Type<typeof PartID>
|
||||||
|
|||||||
Reference in New Issue
Block a user