diff --git a/src/misc/schema.ts b/src/misc/schema.ts index e14e6e0dd7..8854ab5303 100644 --- a/src/misc/schema.ts +++ b/src/misc/schema.ts @@ -1,3 +1,6 @@ +import { packedNoteSchema } from "@/models/repositories/note"; +import { packedNotificationSchema } from "@/models/repositories/notification"; + export type Schema = { type: 'boolean' | 'number' | 'string' | 'array' | 'object' | 'any'; nullable: boolean; @@ -43,11 +46,19 @@ type NullOrUndefined

= ? (T | undefined) : T; +export const refs = { + Note: packedNoteSchema, + Notification: packedNotificationSchema, +}; + export type SchemaType

= p['type'] extends 'number' ? NullOrUndefined : p['type'] extends 'string' ? NullOrUndefined : p['type'] extends 'boolean' ? NullOrUndefined : p['type'] extends 'array' ? NullOrUndefined>[]> : - p['type'] extends 'object' ? NullOrUndefined>> : + p['type'] extends 'object' ? + ( p['ref'] extends keyof typeof refs ? + NullOrUndefined> : + NullOrUndefined>> ) : p['type'] extends 'any' ? NullOrUndefined : any; diff --git a/src/models/repositories/blocking.ts b/src/models/repositories/blocking.ts index dd3a10905c..515b3a6b16 100644 --- a/src/models/repositories/blocking.ts +++ b/src/models/repositories/blocking.ts @@ -56,7 +56,7 @@ export const packedBlockingSchema = { blockee: { type: 'object' as const, optional: false as const, nullable: false as const, - ref: 'User', + ref: 'User' as const, }, } }; diff --git a/src/models/repositories/notification.ts b/src/models/repositories/notification.ts index ed9de7ef4c..584e3d8061 100644 --- a/src/models/repositories/notification.ts +++ b/src/models/repositories/notification.ts @@ -145,6 +145,19 @@ export const packedNotificationSchema = { format: 'id', }, note: { + type: 'object' as const, + ref: 'Note' as const, + optional: true as const, nullable: true as const, + }, + reaction: { + type: 'string' as const, + optional: true as const, nullable: true as const, + }, + choice: { + type: 'number' as const, + optional: true as const, nullable: true as const, + }, + invitation: { type: 'object' as const, ref: 'Note', optional: true as const, nullable: true as const,