refactor(schema): reuse id constructors

This commit is contained in:
Kit Langton
2026-06-24 23:28:53 -04:00
parent 3cb81aebe5
commit 2fb949754f
2 changed files with 14 additions and 8 deletions
+7 -4
View File
@@ -9,10 +9,13 @@ import { NonNegativeInt, PositiveInt, statics } from "./schema"
const IDSchema = Schema.String.check(Schema.isStartsWith("pty")).pipe(Schema.brand("PtyID"))
export const ID = IDSchema.pipe(
statics((schema: typeof IDSchema) => ({
create: () => schema.make("pty_" + ascending()),
ascending: (id?: string) => schema.make(id ?? "pty_" + ascending()),
})),
statics((schema: typeof IDSchema) => {
const create = () => schema.make("pty_" + ascending())
return {
create,
ascending: (id?: string) => (id === undefined ? create() : schema.make(id)),
}
}),
)
export type ID = typeof ID.Type
+7 -4
View File
@@ -9,10 +9,13 @@ import { statics } from "./schema"
export const ID = Schema.String.check(Schema.isStartsWith("que")).pipe(
Schema.brand("QuestionV2.ID"),
statics((schema) => ({
create: () => schema.make("que_" + ascending()),
ascending: (id?: string) => schema.make(id ?? "que_" + ascending()),
})),
statics((schema) => {
const create = () => schema.make("que_" + ascending())
return {
create,
ascending: (id?: string) => (id === undefined ? create() : schema.make(id)),
}
}),
)
export type ID = typeof ID.Type