From 2fb949754f45eef78ac77aaae0d4b9dabc58a8f5 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Wed, 24 Jun 2026 23:28:53 -0400 Subject: [PATCH] refactor(schema): reuse id constructors --- packages/schema/src/pty.ts | 11 +++++++---- packages/schema/src/question.ts | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/schema/src/pty.ts b/packages/schema/src/pty.ts index 7791046f6e..1392ece55f 100644 --- a/packages/schema/src/pty.ts +++ b/packages/schema/src/pty.ts @@ -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 diff --git a/packages/schema/src/question.ts b/packages/schema/src/question.ts index b5c9dd1366..aba5ebfbaf 100644 --- a/packages/schema/src/question.ts +++ b/packages/schema/src/question.ts @@ -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