pl-api: Handle moved accounts correctly

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-10-09 12:56:46 +02:00
parent 36a019b419
commit 085eb13783
2 changed files with 6 additions and 3 deletions

View file

@ -85,6 +85,7 @@ const baseAccountSchema = z.object({
group: z.boolean().catch(false),
discoverable: z.boolean().catch(false),
noindex: z.boolean().nullable().catch(null),
moved: z.null().catch(null),
suspended: z.boolean().optional().catch(undefined),
limited: z.boolean().optional().catch(undefined),
created_at: z.string().datetime().catch(new Date().toUTCString()),
@ -127,13 +128,15 @@ const baseAccountSchema = z.object({
});
const accountWithMovedAccountSchema = baseAccountSchema.extend({
moved: baseAccountSchema.optional().catch(undefined),
moved: z.lazy((): typeof baseAccountSchema => accountWithMovedAccountSchema as any).nullable().catch(null),
});
/** @see {@link https://docs.joinmastodon.org/entities/Account/} */
const accountSchema = z.preprocess(preprocessAccount, accountWithMovedAccountSchema);
type Account = z.infer<typeof accountSchema>;
type Account = z.infer<typeof baseAccountSchema> & {
moved: Account | null;
};
const credentialAccountSchema = z.preprocess(preprocessAccount, accountWithMovedAccountSchema.extend({
source: z.object({

View file

@ -1,6 +1,6 @@
{
"name": "pl-api",
"version": "0.0.37",
"version": "0.0.38",
"type": "module",
"homepage": "https://github.com/mkljczk/pl-fe/tree/fork/packages/pl-api",
"repository": {