import { SimpleObj, SimpleSchema } from './simple-schema'; import { packedUserSchema } from '@/models/repositories/user'; import { packedNoteSchema } from '@/models/repositories/note'; import { packedUserListSchema } from '@/models/repositories/user-list'; import { packedAppSchema } from '@/models/repositories/app'; import { packedMessagingMessageSchema } from '@/models/repositories/messaging-message'; import { packedNotificationSchema } from '@/models/repositories/notification'; import { packedDriveFileSchema } from '@/models/repositories/drive-file'; import { packedDriveFolderSchema } from '@/models/repositories/drive-folder'; import { packedFollowingSchema } from '@/models/repositories/following'; import { packedMutingSchema } from '@/models/repositories/muting'; import { packedBlockingSchema } from '@/models/repositories/blocking'; import { packedNoteReactionSchema } from '@/models/repositories/note-reaction'; import { packedHashtagSchema } from '@/models/repositories/hashtag'; import { packedPageSchema } from '@/models/repositories/page'; import { packedUserGroupSchema } from '@/models/repositories/user-group'; import { packedNoteFavoriteSchema } from '@/models/repositories/note-favorite'; import { packedChannelSchema } from '@/models/repositories/channel'; import { packedAntennaSchema } from '@/models/repositories/antenna'; import { packedClipSchema } from '@/models/repositories/clip'; import { packedFederationInstanceSchema } from '@/models/repositories/federation-instance'; import { packedQueueCountSchema } from '@/models/repositories/queue'; import { packedGalleryPostSchema } from '@/models/repositories/gallery-post'; import { packedEmojiSchema } from '@/models/repositories/emoji'; export const refs = { User: packedUserSchema, UserList: packedUserListSchema, UserGroup: packedUserGroupSchema, App: packedAppSchema, MessagingMessage: packedMessagingMessageSchema, Note: packedNoteSchema, NoteReaction: packedNoteReactionSchema, NoteFavorite: packedNoteFavoriteSchema, Notification: packedNotificationSchema, DriveFile: packedDriveFileSchema, DriveFolder: packedDriveFolderSchema, Following: packedFollowingSchema, Muting: packedMutingSchema, Blocking: packedBlockingSchema, Hashtag: packedHashtagSchema, Page: packedPageSchema, Channel: packedChannelSchema, QueueCount: packedQueueCountSchema, Antenna: packedAntennaSchema, Clip: packedClipSchema, FederationInstance: packedFederationInstanceSchema, GalleryPost: packedGalleryPostSchema, Emoji: packedEmojiSchema, }; export type Packed = ObjType<(typeof refs[x])['properties']>; export interface Schema extends SimpleSchema { items?: Schema; properties?: Obj; ref?: keyof typeof refs; } type NonUndefinedPropertyNames = { [K in keyof T]: T[K]['optional'] extends true ? never : K }[keyof T]; type UndefinedPropertyNames = { [K in keyof T]: T[K]['optional'] extends true ? K : never }[keyof T]; type OnlyRequired = Pick>; type OnlyOptional = Pick>; export interface Obj extends SimpleObj { [key: string]: Schema; } export type ObjType = { [P in keyof OnlyOptional]?: SchemaType } & { [P in keyof OnlyRequired]: SchemaType }; // https://qiita.com/hrsh7th@github/items/84e8968c3601009cdcf2 type MyType = { 0: any; 1: SchemaType; }[T extends Schema ? 1 : 0]; type NullOrUndefined

= p['nullable'] extends true ? p['optional'] extends true ? (T | null | undefined) : (T | null) : p['optional'] extends true ? (T | undefined) : T; 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' ? ( p['ref'] extends keyof typeof refs ? NullOrUndefined> : NullOrUndefined>> ) : p['type'] extends 'any' ? NullOrUndefined : any;