1
0
forked from mirror/misskey
This commit is contained in:
tamaina 2021-09-06 03:26:19 +09:00
parent 7ab97004d9
commit c86ac1c6ec
15 changed files with 84 additions and 84 deletions

View File

@ -1,5 +1,50 @@
import { packedNoteSchema } from "@/models/repositories/note"; import { packedUserSchema } from '@/models/repositories/user';
import { packedNotificationSchema } from "@/models/repositories/notification"; 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';
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,
};
export type Schema = { export type Schema = {
type: 'boolean' | 'number' | 'string' | 'array' | 'object' | 'any'; type: 'boolean' | 'number' | 'string' | 'array' | 'object' | 'any';
@ -10,8 +55,9 @@ export type Schema = {
description?: string; description?: string;
example?: any; example?: any;
format?: string; format?: string;
ref?: string; ref?: keyof typeof refs;
enum?: string[]; enum?: string[];
default?: boolean | null;
}; };
type NonUndefinedPropertyNames<T extends Obj> = { type NonUndefinedPropertyNames<T extends Obj> = {
@ -46,19 +92,15 @@ type NullOrUndefined<p extends Schema, T> =
? (T | undefined) ? (T | undefined)
: T; : T;
export const refs = {
Note: packedNoteSchema,
Notification: packedNotificationSchema,
};
export type SchemaType<p extends Schema> = export type SchemaType<p extends Schema> =
p['type'] extends 'number' ? NullOrUndefined<p, number> : p['type'] extends 'number' ? NullOrUndefined<p, number> :
p['type'] extends 'string' ? NullOrUndefined<p, string> : p['type'] extends 'string' ? NullOrUndefined<p, string> :
p['type'] extends 'boolean' ? NullOrUndefined<p, boolean> : p['type'] extends 'boolean' ? NullOrUndefined<p, boolean> :
p['type'] extends 'array' ? NullOrUndefined<p, MyType<NonNullable<p['items']>>[]> : p['type'] extends 'array' ? NullOrUndefined<p, MyType<NonNullable<p['items']>>[]> :
p['type'] extends 'object' ? p['type'] extends 'object' ? (
( p['ref'] extends keyof typeof refs ? p['ref'] extends keyof typeof refs
NullOrUndefined<p, SchemaType<typeof refs[p['ref']]>> : ? NullOrUndefined<p, SchemaType<typeof refs[p['ref']]>>
NullOrUndefined<p, ObjType<NonNullable<p['properties']>>> ) : : NullOrUndefined<p, ObjType<NonNullable<p['properties']>>>
) :
p['type'] extends 'any' ? NullOrUndefined<p, any> : p['type'] extends 'any' ? NullOrUndefined<p, any> :
any; any;

View File

@ -53,7 +53,7 @@ export const packedClipSchema = {
}, },
user: { user: {
type: 'object' as const, type: 'object' as const,
ref: 'User', ref: 'User' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
}, },
name: { name: {

View File

@ -234,7 +234,7 @@ export const packedDriveFileSchema = {
folder: { folder: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
ref: 'DriveFolder' ref: 'DriveFolder' as const,
}, },
userId: { userId: {
type: 'string' as const, type: 'string' as const,
@ -245,7 +245,7 @@ export const packedDriveFileSchema = {
user: { user: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
ref: 'User' ref: 'User' as const,
} }
}, },
}; };

View File

@ -87,7 +87,7 @@ export const packedDriveFolderSchema = {
parent: { parent: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
ref: 'DriveFolder' ref: 'DriveFolder' as const,
}, },
}, },
}; };

View File

@ -110,7 +110,7 @@ export const packedFollowingSchema = {
followee: { followee: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: false as const, optional: true as const, nullable: false as const,
ref: 'User', ref: 'User' as const,
}, },
followerId: { followerId: {
type: 'string' as const, type: 'string' as const,
@ -120,7 +120,7 @@ export const packedFollowingSchema = {
follower: { follower: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: false as const, optional: true as const, nullable: false as const,
ref: 'User', ref: 'User' as const,
}, },
} }
}; };

View File

@ -1,6 +1,6 @@
import { EntityRepository, Repository } from 'typeorm'; import { EntityRepository, Repository } from 'typeorm';
import { GalleryPost } from '@/models/entities/gallery-post'; import { GalleryPost } from '@/models/entities/gallery-post';
import { SchemaType } from '../../misc/schema'; import { SchemaType } from '@/misc/schema';
import { Users, DriveFiles, GalleryLikes } from '../index'; import { Users, DriveFiles, GalleryLikes } from '../index';
import { awaitAll } from '@/prelude/await-all'; import { awaitAll } from '@/prelude/await-all';
import { User } from '@/models/entities/user'; import { User } from '@/models/entities/user';
@ -76,7 +76,7 @@ export const packedGalleryPostSchema = {
}, },
user: { user: {
type: 'object' as const, type: 'object' as const,
ref: 'User', ref: 'User' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
}, },
fileIds: { fileIds: {
@ -94,7 +94,7 @@ export const packedGalleryPostSchema = {
items: { items: {
type: 'object' as const, type: 'object' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
ref: 'DriveFile' ref: 'DriveFile' as const,
} }
}, },
tags: { tags: {

View File

@ -67,7 +67,7 @@ export const packedMessagingMessageSchema = {
}, },
user: { user: {
type: 'object' as const, type: 'object' as const,
ref: 'User', ref: 'User' as const,
optional: true as const, nullable: false as const, optional: true as const, nullable: false as const,
}, },
text: { text: {
@ -82,7 +82,7 @@ export const packedMessagingMessageSchema = {
file: { file: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
ref: 'DriveFile', ref: 'DriveFile' as const,
}, },
recipientId: { recipientId: {
type: 'string' as const, type: 'string' as const,
@ -92,7 +92,7 @@ export const packedMessagingMessageSchema = {
recipient: { recipient: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
ref: 'User' ref: 'User' as const,
}, },
groupId: { groupId: {
type: 'string' as const, type: 'string' as const,
@ -102,7 +102,7 @@ export const packedMessagingMessageSchema = {
group: { group: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
ref: 'UserGroup' ref: 'UserGroup' as const,
}, },
isRead: { isRead: {
type: 'boolean' as const, type: 'boolean' as const,

View File

@ -56,7 +56,7 @@ export const packedMutingSchema = {
mutee: { mutee: {
type: 'object' as const, type: 'object' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
ref: 'User', ref: 'User' as const,
}, },
} }
}; };

View File

@ -45,7 +45,7 @@ export const packedNoteFavoriteSchema = {
note: { note: {
type: 'object' as const, type: 'object' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
ref: 'Note', ref: 'Note' as const,
}, },
noteId: { noteId: {
type: 'string' as const, type: 'string' as const,

View File

@ -42,7 +42,7 @@ export const packedNoteReactionSchema = {
user: { user: {
type: 'object' as const, type: 'object' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
ref: 'User', ref: 'User' as const,
}, },
type: { type: {
type: 'string' as const, type: 'string' as const,

View File

@ -3,7 +3,7 @@ import * as mfm from 'mfm-js';
import { Note } from '@/models/entities/note'; import { Note } from '@/models/entities/note';
import { User } from '@/models/entities/user'; import { User } from '@/models/entities/user';
import { Users, PollVotes, DriveFiles, NoteReactions, Followings, Polls, Channels } from '../index'; import { Users, PollVotes, DriveFiles, NoteReactions, Followings, Polls, Channels } from '../index';
import { SchemaType } from '@/misc/schema'; import { Schema, SchemaType } from '@/misc/schema';
import { nyaize } from '@/misc/nyaize'; import { nyaize } from '@/misc/nyaize';
import { awaitAll } from '@/prelude/await-all'; import { awaitAll } from '@/prelude/await-all';
import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '@/misc/reaction-lib'; import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '@/misc/reaction-lib';
@ -353,7 +353,7 @@ export const packedNoteSchema = {
}, },
user: { user: {
type: 'object' as const, type: 'object' as const,
ref: 'User', ref: 'User' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
}, },
replyId: { replyId: {
@ -371,12 +371,12 @@ export const packedNoteSchema = {
reply: { reply: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
ref: 'Note' ref: 'Note' as const,
}, },
renote: { renote: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
ref: 'Note' ref: 'Note' as const,
}, },
viaMobile: { viaMobile: {
type: 'boolean' as const, type: 'boolean' as const,
@ -423,7 +423,7 @@ export const packedNoteSchema = {
items: { items: {
type: 'object' as const, type: 'object' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
ref: 'DriveFile' ref: 'DriveFile' as const,
} }
}, },
tags: { tags: {
@ -447,7 +447,7 @@ export const packedNoteSchema = {
channel: { channel: {
type: 'object' as const, type: 'object' as const,
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
ref: 'Channel' ref: 'Channel' as const,
}, },
localOnly: { localOnly: {
type: 'boolean' as const, type: 'boolean' as const,

View File

@ -136,7 +136,7 @@ export const packedNotificationSchema = {
}, },
user: { user: {
type: 'object' as const, type: 'object' as const,
ref: 'User', ref: 'User' as const,
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
}, },
userId: { userId: {
@ -159,7 +159,6 @@ export const packedNotificationSchema = {
}, },
invitation: { invitation: {
type: 'object' as const, type: 'object' as const,
ref: 'Note',
optional: true as const, nullable: true as const, optional: true as const, nullable: true as const,
}, },
body: { body: {

View File

@ -137,7 +137,7 @@ export const packedPageSchema = {
}, },
user: { user: {
type: 'object' as const, type: 'object' as const,
ref: 'User', ref: 'User' as const,
optional: false as const, nullable: false as const, optional: false as const, nullable: false as const,
}, },
} }

View File

@ -520,7 +520,7 @@ export const packedUserSchema = {
items: { items: {
type: 'object' as const, type: 'object' as const,
nullable: false as const, optional: false as const, nullable: false as const, optional: false as const,
ref: 'Note' ref: 'Note' as const,
} }
}, },
pinnedPageId: { pinnedPageId: {
@ -530,7 +530,7 @@ export const packedUserSchema = {
pinnedPage: { pinnedPage: {
type: 'object' as const, type: 'object' as const,
nullable: true as const, optional: false as const, nullable: true as const, optional: false as const,
ref: 'Page' ref: 'Page' as const,
}, },
twoFactorEnabled: { twoFactorEnabled: {
type: 'boolean' as const, type: 'boolean' as const,

View File

@ -1,26 +1,4 @@
import { packedUserSchema } from '@/models/repositories/user'; import { refs, Schema } from '@/misc/schema';
import { Schema } from '@/misc/schema';
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';
export function convertSchemaToOpenApiSchema(schema: Schema) { export function convertSchemaToOpenApiSchema(schema: Schema) {
const res: any = schema; const res: any = schema;
@ -72,26 +50,7 @@ export const schemas = {
required: ['error'] required: ['error']
}, },
User: convertSchemaToOpenApiSchema(packedUserSchema), ...Object.fromEntries(
UserList: convertSchemaToOpenApiSchema(packedUserListSchema), Object.entries(refs).map(([key, schema]) => [key, convertSchemaToOpenApiSchema(schema)])
UserGroup: convertSchemaToOpenApiSchema(packedUserGroupSchema), ),
App: convertSchemaToOpenApiSchema(packedAppSchema),
MessagingMessage: convertSchemaToOpenApiSchema(packedMessagingMessageSchema),
Note: convertSchemaToOpenApiSchema(packedNoteSchema),
NoteReaction: convertSchemaToOpenApiSchema(packedNoteReactionSchema),
NoteFavorite: convertSchemaToOpenApiSchema(packedNoteFavoriteSchema),
Notification: convertSchemaToOpenApiSchema(packedNotificationSchema),
DriveFile: convertSchemaToOpenApiSchema(packedDriveFileSchema),
DriveFolder: convertSchemaToOpenApiSchema(packedDriveFolderSchema),
Following: convertSchemaToOpenApiSchema(packedFollowingSchema),
Muting: convertSchemaToOpenApiSchema(packedMutingSchema),
Blocking: convertSchemaToOpenApiSchema(packedBlockingSchema),
Hashtag: convertSchemaToOpenApiSchema(packedHashtagSchema),
Page: convertSchemaToOpenApiSchema(packedPageSchema),
Channel: convertSchemaToOpenApiSchema(packedChannelSchema),
QueueCount: convertSchemaToOpenApiSchema(packedQueueCountSchema),
Antenna: convertSchemaToOpenApiSchema(packedAntennaSchema),
Clip: convertSchemaToOpenApiSchema(packedClipSchema),
FederationInstance: convertSchemaToOpenApiSchema(packedFederationInstanceSchema),
GalleryPost: convertSchemaToOpenApiSchema(packedGalleryPostSchema),
}; };