pl-api: More blind search and replace before actual testing

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-10-14 20:54:44 +02:00
parent a6bc160caa
commit ea3addf388
47 changed files with 253 additions and 251 deletions

View File

@ -17,13 +17,13 @@ import { dateSchema, filteredArray } from './utils';
const statusEventSchema = v.object({
name: v.fallback(v.string(), ''),
start_time: z.string().datetime().nullable().catch(null),
end_time: z.string().datetime().nullable().catch(null),
join_mode: z.enum(['free', 'restricted', 'invite']).nullable().catch(null),
start_time: v.fallback(v.nullable(z.string().datetime()), null),
end_time: v.fallback(v.nullable(z.string().datetime()), null),
join_mode: v.fallback(v.nullable(v.picklist(['free', 'restricted', 'invite'])), null),
participants_count: v.fallback(v.number(), 0),
location: v.object({
location: v.fallback(v.nullable(v.object({
name: v.fallback(v.string(), ''),
url: z.string().url().catch(''),
url: v.fallback(v.pipe(v.string(), v.url()), ''),
latitude: v.fallback(v.number(), 0),
longitude: v.fallback(v.number(), 0),
street: v.fallback(v.string(), ''),
@ -31,14 +31,14 @@ const statusEventSchema = v.object({
locality: v.fallback(v.string(), ''),
region: v.fallback(v.string(), ''),
country: v.fallback(v.string(), ''),
}).nullable().catch(null),
join_state: z.enum(['pending', 'reject', 'accept']).nullable().catch(null),
})), null),
join_state: v.fallback(v.nullable(v.picklist(['pending', 'reject', 'accept'])), null),
});
/** @see {@link https://docs.joinmastodon.org/entities/Status/} */
const baseStatusSchema = v.object({
id: v.string(),
uri: z.string().url().catch(''),
uri: v.fallback(v.pipe(v.string(), v.url()), ''),
created_at: dateSchema,
account: accountSchema,
content: v.fallback(v.string(), ''),
@ -46,55 +46,55 @@ const baseStatusSchema = v.object({
sensitive: z.coerce.boolean(),
spoiler_text: v.fallback(v.string(), ''),
media_attachments: filteredArray(mediaAttachmentSchema),
application: v.object({
application: v.fallback(v.nullable(v.object({
name: v.string(),
website: z.string().url().nullable().catch(null),
}).nullable().catch(null),
website: v.fallback(v.nullable(z.string().url()), null),
})), null),
mentions: filteredArray(mentionSchema),
tags: filteredArray(tagSchema),
emojis: filteredArray(customEmojiSchema),
reblogs_count: v.fallback(v.number(), 0),
favourites_count: v.fallback(v.number(), 0),
replies_count: v.fallback(v.number(), 0),
url: z.string().url().catch(''),
url: v.fallback(v.pipe(v.string(), v.url()), ''),
in_reply_to_id: v.fallback(v.nullable(v.string()), null),
in_reply_to_account_id: v.fallback(v.nullable(v.string()), null),
poll: v.fallback(v.nullable(pollSchema), null),
card: v.fallback(v.nullable(previewCardSchema), null),
language: v.fallback(v.nullable(v.string()), null),
text: v.fallback(v.nullable(v.string()), null),
edited_at: z.string().datetime().nullable().catch(null),
edited_at: v.fallback(v.nullable(z.string().datetime()), null),
favourited: z.coerce.boolean(),
reblogged: z.coerce.boolean(),
muted: z.coerce.boolean(),
bookmarked: z.coerce.boolean(),
pinned: z.coerce.boolean(),
filtered: filteredArray(filterResultSchema),
approval_status: z.enum(['pending', 'approval', 'rejected']).nullable().catch(null),
approval_status: v.fallback(v.nullable(v.picklist(['pending', 'approval', 'rejected'])), null),
group: v.fallback(v.nullable(groupSchema), null),
scheduled_at: z.null().catch(null),
scheduled_at: v.fallback(v.null(), null),
quote_id: v.fallback(v.nullable(v.string()), null),
local: v.fallback(v.optional(v.boolean()), undefined),
conversation_id: v.fallback(v.optional(v.string()), undefined),
direct_conversation_id: v.fallback(v.optional(v.string()), undefined),
in_reply_to_account_acct: v.fallback(v.optional(v.string()), undefined),
expires_at: z.string().datetime({ offset: true }).optional().catch(undefined),
expires_at: v.fallback(v.optional(z.string().datetime({ offset: true })), undefined),
thread_muted: v.fallback(v.optional(v.boolean()), undefined),
emoji_reactions: filteredArray(emojiReactionSchema),
parent_visible: v.fallback(v.optional(v.boolean()), undefined),
pinned_at: z.string().datetime({ offset: true }).nullable().catch(null),
pinned_at: v.fallback(v.nullable(z.string().datetime({ offset: true })), null),
quote_visible: v.fallback(v.optional(v.boolean()), undefined),
quote_url: v.fallback(v.optional(v.string()), undefined),
quotes_count: v.fallback(v.number(), 0),
bookmark_folder: v.fallback(v.nullable(v.string()), null),
event: v.fallback(v.nullable(statusEventSchema), null),
translation: translationSchema.nullable().or(z.literal(false)).catch(null),
translation: translationSchema.nullable().or(v.literal(false)).catch(null),
content_map: z.record(v.string()).nullable().catch(null),
text_map: z.record(v.string()).nullable().catch(null),
spoiler_text_map: z.record(v.string()).nullable().catch(null),
content_map: v.fallback(v.nullable(v.record(v.string(), v.string())), null),
text_map: v.fallback(v.nullable(v.record(v.string(), v.string())), null),
spoiler_text_map: v.fallback(v.nullable(v.record(v.string(), v.string())), null),
dislikes_count: v.fallback(v.number(), 0),
disliked: z.coerce.boolean().catch(false),
@ -135,16 +135,16 @@ const preprocess = (status: any) => {
};
const statusSchema: z.ZodType<Status> = z.preprocess(preprocess, baseStatusSchema.extend({
reblog: z.lazy(() => statusSchema).nullable().catch(null),
reblog: v.fallback(v.nullable(z.lazy(() => statusSchema)), null),
quote: z.lazy(() => statusSchema).nullable().catch(null),
quote: v.fallback(v.nullable(z.lazy(() => statusSchema)), null),
})) as any;
const statusWithoutAccountSchema = z.preprocess(preprocess, baseStatusSchema.omit({ account: true }).extend({
account: v.fallback(v.nullable(accountSchema), null),
reblog: z.lazy(() => statusSchema).nullable().catch(null),
reblog: v.fallback(v.nullable(z.lazy(() => statusSchema)), null),
quote: z.lazy(() => statusSchema).nullable().catch(null),
quote: v.fallback(v.nullable(z.lazy(() => statusSchema)), null),
}));
type Status = v.InferOutput<typeof baseStatusSchema> & {