From 09c5b71154cf5fee8e35bfb779430900ee2e8a32 Mon Sep 17 00:00:00 2001 From: Revan0809 Date: Sun, 4 Oct 2026 09:51:17 +0530 Subject: [PATCH] Return pseuds as an array instead of a joined string getUserProfilePseuds already built pseudsArray internally but joined it into a single ", "-separated string before returning, so callers had to parse it back apart to get individual pseuds. Return the array directly instead. Updates the User.pseuds type and regenerates the zod schemas. Fixes #202 --- src/users/getters.ts | 3 +-- src/users/index.ts | 1 - tests/user.test.ts | 2 +- types/entities.ts | 2 +- types/zod/generated/schemas.ts | 5 +++-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/users/getters.ts b/src/users/getters.ts index 80c0b250..04f8f422 100644 --- a/src/users/getters.ts +++ b/src/users/getters.ts @@ -16,7 +16,6 @@ export const getUserProfileName = ($userProfile: UserProfile) => { return $userProfile(".user.profile .header h2").text().trim(); }; -const PSEUD_SUFFIX = ", "; export const getUserProfilePseuds = ($userProfile: UserProfile) => { const pseuds = $userProfile("dd.pseuds a"); const pseudsArray: string[] = []; @@ -29,7 +28,7 @@ export const getUserProfilePseuds = ($userProfile: UserProfile) => { pseudsArray.push(decodeURI(pseud)); }); } - return pseudsArray.join(PSEUD_SUFFIX); + return pseudsArray; }; //Trim the results to only the date: diff --git a/src/users/index.ts b/src/users/index.ts index d1ac4e7d..0f565f21 100644 --- a/src/users/index.ts +++ b/src/users/index.ts @@ -30,7 +30,6 @@ export const getUser = async ({ return { // We use this because capitalization might be different username: getUserProfileName(profilePage), - // TODO: this should really be an array pseuds: getUserProfilePseuds(profilePage), id: getUserProfileId(profilePage), joined: getUserProfileJoined(profilePage), diff --git a/tests/user.test.ts b/tests/user.test.ts index bb0321b9..11f70ef5 100644 --- a/tests/user.test.ts +++ b/tests/user.test.ts @@ -13,7 +13,7 @@ describe("User/data", () => { username: "astolat", id: 8, url: "https://archiveofourown.org/users/astolat/profile", - pseuds: "astolat, shalott, the lady of shalott", + pseuds: ["astolat", "shalott", "the lady of shalott"], joined: "2008-09-13", } satisfies Partial); }); diff --git a/types/entities.ts b/types/entities.ts index 75b7c9e6..29927a94 100644 --- a/types/entities.ts +++ b/types/entities.ts @@ -74,7 +74,7 @@ export interface TagSearchResultSummary { export interface User { id: ArchiveId; username: string; - pseuds: string; + pseuds: string[]; url: string; shortUrl: string; icon: string; diff --git a/types/zod/generated/schemas.ts b/types/zod/generated/schemas.ts index 03e33a65..f2e0d4e0 100644 --- a/types/zod/generated/schemas.ts +++ b/types/zod/generated/schemas.ts @@ -21,7 +21,8 @@ export const tagSchema = z.object({ subTags: z.array(z.object({ tagName: z.string(), parentSubTag: z.string().nullable() - })) + })), + tagsWithSameMeaning: z.array(z.string()) }); export const tagSearchTypeSchema = z.union([z.literal("fandom"), z.literal("character"), z.literal("relationship"), z.literal("freeform"), z.literal("any")]); @@ -56,7 +57,7 @@ export const tagSearchResultSummarySchema = z.object({ export const userSchema = z.object({ id: archiveIdSchema, username: z.string(), - pseuds: z.string(), + pseuds: z.array(z.string()), url: z.string(), shortUrl: z.string(), icon: z.string(),