instanceSchema: get rid of any() fields

This commit is contained in:
Alex Gleason 2023-09-26 12:29:35 -05:00
parent 4b52f20776
commit 0986055222
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 20 additions and 3 deletions

View file

@ -3,7 +3,8 @@ import z from 'zod';
import { accountSchema } from './account';
import { mrfSimpleSchema } from './pleroma';
import { coerceObject, mimeSchema } from './utils';
import { ruleSchema } from './rule';
import { coerceObject, filteredArray, mimeSchema } from './utils';
const configurationSchema = coerceObject({
chats: coerceObject({
@ -51,7 +52,11 @@ const pleromaSchema = coerceObject({
mrf_policies: z.string().array().optional().catch(undefined),
mrf_simple: mrfSimpleSchema,
}),
fields_limits: z.any(),
fields_limits: coerceObject({
max_fields: z.number().nonnegative().catch(4),
name_length: z.number().nonnegative().catch(255),
value_length: z.number().nonnegative().catch(2047),
}),
migration_cooldown_period: z.number().optional().catch(undefined),
restrict_unauthenticated: coerceObject({
activities: coerceObject({
@ -111,7 +116,7 @@ const instanceSchema = coerceObject({
nostr: nostrSchema.optional().catch(undefined),
pleroma: pleromaSchema,
registrations: z.boolean().catch(false),
rules: z.any(),
rules: filteredArray(ruleSchema),
short_description: z.string().catch(''),
stats: statsSchema,
thumbnail: z.string().catch(''),

12
src/schemas/rule.ts Normal file
View file

@ -0,0 +1,12 @@
import { z } from 'zod';
import { coerceObject } from './utils';
const ruleSchema = coerceObject({
id: z.string(),
text: z.string().catch(''),
});
type Rule = z.infer<typeof ruleSchema>;
export { ruleSchema, type Rule };