refactor(schema): reuse id constructors
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user