Skip to content

Commit 66e8c57

Browse files
authored
refactor(schema): inline branded ID schemas (anomalyco#17504)
1 parent b698f14 commit 66e8c57

1 file changed

Lines changed: 23 additions & 26 deletions

File tree

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
11
import { Schema } from "effect"
22
import z from "zod"
33

4-
import { withStatics } from "@/util/schema"
54
import { Identifier } from "@/id/id"
5+
import { withStatics } from "@/util/schema"
66

7-
const sessionIdSchema = Schema.String.pipe(Schema.brand("SessionID"))
8-
9-
export type SessionID = typeof sessionIdSchema.Type
10-
11-
export const SessionID = sessionIdSchema.pipe(
12-
withStatics((schema: typeof sessionIdSchema) => ({
13-
make: (id: string) => schema.makeUnsafe(id),
14-
descending: (id?: string) => schema.makeUnsafe(Identifier.descending("session", id)),
15-
zod: Identifier.schema("session").pipe(z.custom<SessionID>()),
7+
export const SessionID = Schema.String.pipe(
8+
Schema.brand("SessionID"),
9+
withStatics((s) => ({
10+
make: (id: string) => s.makeUnsafe(id),
11+
descending: (id?: string) => s.makeUnsafe(Identifier.descending("session", id)),
12+
zod: Identifier.schema("session").pipe(z.custom<Schema.Schema.Type<typeof s>>()),
1613
})),
1714
)
1815

19-
const messageIdSchema = Schema.String.pipe(Schema.brand("MessageID"))
16+
export type SessionID = Schema.Schema.Type<typeof SessionID>
2017

21-
export type MessageID = typeof messageIdSchema.Type
22-
23-
export const MessageID = messageIdSchema.pipe(
24-
withStatics((schema: typeof messageIdSchema) => ({
25-
make: (id: string) => schema.makeUnsafe(id),
26-
ascending: (id?: string) => schema.makeUnsafe(Identifier.ascending("message", id)),
27-
zod: Identifier.schema("message").pipe(z.custom<MessageID>()),
18+
export const MessageID = Schema.String.pipe(
19+
Schema.brand("MessageID"),
20+
withStatics((s) => ({
21+
make: (id: string) => s.makeUnsafe(id),
22+
ascending: (id?: string) => s.makeUnsafe(Identifier.ascending("message", id)),
23+
zod: Identifier.schema("message").pipe(z.custom<Schema.Schema.Type<typeof s>>()),
2824
})),
2925
)
3026

31-
const partIdSchema = Schema.String.pipe(Schema.brand("PartID"))
32-
33-
export type PartID = typeof partIdSchema.Type
27+
export type MessageID = Schema.Schema.Type<typeof MessageID>
3428

35-
export const PartID = partIdSchema.pipe(
36-
withStatics((schema: typeof partIdSchema) => ({
37-
make: (id: string) => schema.makeUnsafe(id),
38-
ascending: (id?: string) => schema.makeUnsafe(Identifier.ascending("part", id)),
39-
zod: Identifier.schema("part").pipe(z.custom<PartID>()),
29+
export const PartID = Schema.String.pipe(
30+
Schema.brand("PartID"),
31+
withStatics((s) => ({
32+
make: (id: string) => s.makeUnsafe(id),
33+
ascending: (id?: string) => s.makeUnsafe(Identifier.ascending("part", id)),
34+
zod: Identifier.schema("part").pipe(z.custom<Schema.Schema.Type<typeof s>>()),
4035
})),
4136
)
37+
38+
export type PartID = Schema.Schema.Type<typeof PartID>

0 commit comments

Comments
 (0)