From 7ab97004d9d3630218e8f4a1754e2db1b0510cb4 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 6 Sep 2021 02:49:21 +0900 Subject: [PATCH 1/6] fix --- src/models/repositories/notification.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/models/repositories/notification.ts b/src/models/repositories/notification.ts index 584e3d8061..983fdaf6e8 100644 --- a/src/models/repositories/notification.ts +++ b/src/models/repositories/notification.ts @@ -162,18 +162,6 @@ export const packedNotificationSchema = { ref: 'Note', 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, - optional: true as const, nullable: true as const, - }, body: { type: 'string' as const, optional: true as const, nullable: true as const, From c86ac1c6eca687f510fbbea26ab8b5040eadc0ab Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 6 Sep 2021 03:26:19 +0900 Subject: [PATCH 2/6] yatta --- src/misc/schema.ts | 66 ++++++++++++++++---- src/models/repositories/clip.ts | 2 +- src/models/repositories/drive-file.ts | 4 +- src/models/repositories/drive-folder.ts | 2 +- src/models/repositories/following.ts | 4 +- src/models/repositories/gallery-post.ts | 6 +- src/models/repositories/messaging-message.ts | 8 +-- src/models/repositories/muting.ts | 2 +- src/models/repositories/note-favorite.ts | 2 +- src/models/repositories/note-reaction.ts | 2 +- src/models/repositories/note.ts | 12 ++-- src/models/repositories/notification.ts | 3 +- src/models/repositories/page.ts | 2 +- src/models/repositories/user.ts | 4 +- src/server/api/openapi/schemas.ts | 49 ++------------- 15 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/misc/schema.ts b/src/misc/schema.ts index 8854ab5303..c4ca80249d 100644 --- a/src/misc/schema.ts +++ b/src/misc/schema.ts @@ -1,5 +1,50 @@ -import { packedNoteSchema } from "@/models/repositories/note"; -import { packedNotificationSchema } from "@/models/repositories/notification"; +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'; + +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 = { type: 'boolean' | 'number' | 'string' | 'array' | 'object' | 'any'; @@ -10,8 +55,9 @@ export type Schema = { description?: string; example?: any; format?: string; - ref?: string; + ref?: keyof typeof refs; enum?: string[]; + default?: boolean | null; }; type NonUndefinedPropertyNames = { @@ -46,19 +92,15 @@ 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' ? - ( p['ref'] extends keyof typeof refs ? - NullOrUndefined> : - 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/clip.ts b/src/models/repositories/clip.ts index 49dc3a332e..e3d718bef4 100644 --- a/src/models/repositories/clip.ts +++ b/src/models/repositories/clip.ts @@ -53,7 +53,7 @@ export const packedClipSchema = { }, user: { type: 'object' as const, - ref: 'User', + ref: 'User' as const, optional: false as const, nullable: false as const, }, name: { diff --git a/src/models/repositories/drive-file.ts b/src/models/repositories/drive-file.ts index 42a60ff03c..63bd020cbe 100644 --- a/src/models/repositories/drive-file.ts +++ b/src/models/repositories/drive-file.ts @@ -234,7 +234,7 @@ export const packedDriveFileSchema = { folder: { type: 'object' as const, optional: true as const, nullable: true as const, - ref: 'DriveFolder' + ref: 'DriveFolder' as const, }, userId: { type: 'string' as const, @@ -245,7 +245,7 @@ export const packedDriveFileSchema = { user: { type: 'object' as const, optional: true as const, nullable: true as const, - ref: 'User' + ref: 'User' as const, } }, }; diff --git a/src/models/repositories/drive-folder.ts b/src/models/repositories/drive-folder.ts index 4228284f82..bc73018f29 100644 --- a/src/models/repositories/drive-folder.ts +++ b/src/models/repositories/drive-folder.ts @@ -87,7 +87,7 @@ export const packedDriveFolderSchema = { parent: { type: 'object' as const, optional: true as const, nullable: true as const, - ref: 'DriveFolder' + ref: 'DriveFolder' as const, }, }, }; diff --git a/src/models/repositories/following.ts b/src/models/repositories/following.ts index 3bb120bc4b..24ddd0d676 100644 --- a/src/models/repositories/following.ts +++ b/src/models/repositories/following.ts @@ -110,7 +110,7 @@ export const packedFollowingSchema = { followee: { type: 'object' as const, optional: true as const, nullable: false as const, - ref: 'User', + ref: 'User' as const, }, followerId: { type: 'string' as const, @@ -120,7 +120,7 @@ export const packedFollowingSchema = { follower: { type: 'object' as const, optional: true as const, nullable: false as const, - ref: 'User', + ref: 'User' as const, }, } }; diff --git a/src/models/repositories/gallery-post.ts b/src/models/repositories/gallery-post.ts index 03edb35213..afa22e9edf 100644 --- a/src/models/repositories/gallery-post.ts +++ b/src/models/repositories/gallery-post.ts @@ -1,6 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { GalleryPost } from '@/models/entities/gallery-post'; -import { SchemaType } from '../../misc/schema'; +import { SchemaType } from '@/misc/schema'; import { Users, DriveFiles, GalleryLikes } from '../index'; import { awaitAll } from '@/prelude/await-all'; import { User } from '@/models/entities/user'; @@ -76,7 +76,7 @@ export const packedGalleryPostSchema = { }, user: { type: 'object' as const, - ref: 'User', + ref: 'User' as const, optional: false as const, nullable: false as const, }, fileIds: { @@ -94,7 +94,7 @@ export const packedGalleryPostSchema = { items: { type: 'object' as const, optional: false as const, nullable: false as const, - ref: 'DriveFile' + ref: 'DriveFile' as const, } }, tags: { diff --git a/src/models/repositories/messaging-message.ts b/src/models/repositories/messaging-message.ts index 1a4a8eecc4..f97905af2f 100644 --- a/src/models/repositories/messaging-message.ts +++ b/src/models/repositories/messaging-message.ts @@ -67,7 +67,7 @@ export const packedMessagingMessageSchema = { }, user: { type: 'object' as const, - ref: 'User', + ref: 'User' as const, optional: true as const, nullable: false as const, }, text: { @@ -82,7 +82,7 @@ export const packedMessagingMessageSchema = { file: { type: 'object' as const, optional: true as const, nullable: true as const, - ref: 'DriveFile', + ref: 'DriveFile' as const, }, recipientId: { type: 'string' as const, @@ -92,7 +92,7 @@ export const packedMessagingMessageSchema = { recipient: { type: 'object' as const, optional: true as const, nullable: true as const, - ref: 'User' + ref: 'User' as const, }, groupId: { type: 'string' as const, @@ -102,7 +102,7 @@ export const packedMessagingMessageSchema = { group: { type: 'object' as const, optional: true as const, nullable: true as const, - ref: 'UserGroup' + ref: 'UserGroup' as const, }, isRead: { type: 'boolean' as const, diff --git a/src/models/repositories/muting.ts b/src/models/repositories/muting.ts index e46f4ae448..d957b1792d 100644 --- a/src/models/repositories/muting.ts +++ b/src/models/repositories/muting.ts @@ -56,7 +56,7 @@ export const packedMutingSchema = { mutee: { type: 'object' as const, optional: false as const, nullable: false as const, - ref: 'User', + ref: 'User' as const, }, } }; diff --git a/src/models/repositories/note-favorite.ts b/src/models/repositories/note-favorite.ts index 3248c32ded..47586a9116 100644 --- a/src/models/repositories/note-favorite.ts +++ b/src/models/repositories/note-favorite.ts @@ -45,7 +45,7 @@ export const packedNoteFavoriteSchema = { note: { type: 'object' as const, optional: false as const, nullable: false as const, - ref: 'Note', + ref: 'Note' as const, }, noteId: { type: 'string' as const, diff --git a/src/models/repositories/note-reaction.ts b/src/models/repositories/note-reaction.ts index c349edf182..e73a832109 100644 --- a/src/models/repositories/note-reaction.ts +++ b/src/models/repositories/note-reaction.ts @@ -42,7 +42,7 @@ export const packedNoteReactionSchema = { user: { type: 'object' as const, optional: false as const, nullable: false as const, - ref: 'User', + ref: 'User' as const, }, type: { type: 'string' as const, diff --git a/src/models/repositories/note.ts b/src/models/repositories/note.ts index 9e0f5e55f0..ac4df222dc 100644 --- a/src/models/repositories/note.ts +++ b/src/models/repositories/note.ts @@ -3,7 +3,7 @@ import * as mfm from 'mfm-js'; import { Note } from '@/models/entities/note'; import { User } from '@/models/entities/user'; 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 { awaitAll } from '@/prelude/await-all'; import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '@/misc/reaction-lib'; @@ -353,7 +353,7 @@ export const packedNoteSchema = { }, user: { type: 'object' as const, - ref: 'User', + ref: 'User' as const, optional: false as const, nullable: false as const, }, replyId: { @@ -371,12 +371,12 @@ export const packedNoteSchema = { reply: { type: 'object' as const, optional: true as const, nullable: true as const, - ref: 'Note' + ref: 'Note' as const, }, renote: { type: 'object' as const, optional: true as const, nullable: true as const, - ref: 'Note' + ref: 'Note' as const, }, viaMobile: { type: 'boolean' as const, @@ -423,7 +423,7 @@ export const packedNoteSchema = { items: { type: 'object' as const, optional: false as const, nullable: false as const, - ref: 'DriveFile' + ref: 'DriveFile' as const, } }, tags: { @@ -447,7 +447,7 @@ export const packedNoteSchema = { channel: { type: 'object' as const, optional: true as const, nullable: true as const, - ref: 'Channel' + ref: 'Channel' as const, }, localOnly: { type: 'boolean' as const, diff --git a/src/models/repositories/notification.ts b/src/models/repositories/notification.ts index 983fdaf6e8..b7f9e3643c 100644 --- a/src/models/repositories/notification.ts +++ b/src/models/repositories/notification.ts @@ -136,7 +136,7 @@ export const packedNotificationSchema = { }, user: { type: 'object' as const, - ref: 'User', + ref: 'User' as const, optional: true as const, nullable: true as const, }, userId: { @@ -159,7 +159,6 @@ export const packedNotificationSchema = { }, invitation: { type: 'object' as const, - ref: 'Note', optional: true as const, nullable: true as const, }, body: { diff --git a/src/models/repositories/page.ts b/src/models/repositories/page.ts index 757aaa5a3f..1a61e2c99c 100644 --- a/src/models/repositories/page.ts +++ b/src/models/repositories/page.ts @@ -137,7 +137,7 @@ export const packedPageSchema = { }, user: { type: 'object' as const, - ref: 'User', + ref: 'User' as const, optional: false as const, nullable: false as const, }, } diff --git a/src/models/repositories/user.ts b/src/models/repositories/user.ts index d4bb995ce2..4a6534b557 100644 --- a/src/models/repositories/user.ts +++ b/src/models/repositories/user.ts @@ -520,7 +520,7 @@ export const packedUserSchema = { items: { type: 'object' as const, nullable: false as const, optional: false as const, - ref: 'Note' + ref: 'Note' as const, } }, pinnedPageId: { @@ -530,7 +530,7 @@ export const packedUserSchema = { pinnedPage: { type: 'object' as const, nullable: true as const, optional: false as const, - ref: 'Page' + ref: 'Page' as const, }, twoFactorEnabled: { type: 'boolean' as const, diff --git a/src/server/api/openapi/schemas.ts b/src/server/api/openapi/schemas.ts index 5402dc6f48..12fc207c47 100644 --- a/src/server/api/openapi/schemas.ts +++ b/src/server/api/openapi/schemas.ts @@ -1,26 +1,4 @@ -import { packedUserSchema } from '@/models/repositories/user'; -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'; +import { refs, Schema } from '@/misc/schema'; export function convertSchemaToOpenApiSchema(schema: Schema) { const res: any = schema; @@ -72,26 +50,7 @@ export const schemas = { required: ['error'] }, - User: convertSchemaToOpenApiSchema(packedUserSchema), - UserList: convertSchemaToOpenApiSchema(packedUserListSchema), - 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), + ...Object.fromEntries( + Object.entries(refs).map(([key, schema]) => [key, convertSchemaToOpenApiSchema(schema)]) + ), }; From 93fd76f84127c6e0523d6eb731c2a9fcf2f4c349 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 6 Sep 2021 03:32:52 +0900 Subject: [PATCH 3/6] remove no longer needed "as PackedUser/PackedNote" --- src/models/repositories/note.ts | 2 +- src/server/api/stream/channels/global-timeline.ts | 2 +- src/server/api/stream/channels/home-timeline.ts | 2 +- src/server/api/stream/channels/hybrid-timeline.ts | 5 ++--- src/server/api/stream/channels/local-timeline.ts | 5 ++--- src/server/api/stream/index.ts | 4 ++-- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/models/repositories/note.ts b/src/models/repositories/note.ts index ac4df222dc..52f841b526 100644 --- a/src/models/repositories/note.ts +++ b/src/models/repositories/note.ts @@ -95,7 +95,7 @@ export class NoteRepository extends Repository { hide = true; } else if (meId === packedNote.userId) { hide = false; - } else if (packedNote.reply && (meId === (packedNote.reply as PackedNote).userId)) { + } else if (packedNote.reply && (meId === packedNote.reply.userId)) { // 自分の投稿に対するリプライ hide = false; } else if (packedNote.mentions && packedNote.mentions.some(id => meId === id)) { diff --git a/src/server/api/stream/channels/global-timeline.ts b/src/server/api/stream/channels/global-timeline.ts index 2cb138966f..384ed61409 100644 --- a/src/server/api/stream/channels/global-timeline.ts +++ b/src/server/api/stream/channels/global-timeline.ts @@ -43,7 +43,7 @@ export default class extends Channel { // 関係ない返信は除外 if (note.reply) { - const reply = note.reply as PackedNote; + const reply = note.reply; // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合 if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return; } diff --git a/src/server/api/stream/channels/home-timeline.ts b/src/server/api/stream/channels/home-timeline.ts index c7a9728741..0e21ab552e 100644 --- a/src/server/api/stream/channels/home-timeline.ts +++ b/src/server/api/stream/channels/home-timeline.ts @@ -51,7 +51,7 @@ export default class extends Channel { // 関係ない返信は除外 if (note.reply) { - const reply = note.reply as PackedNote; + const reply = note.reply; // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合 if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return; } diff --git a/src/server/api/stream/channels/hybrid-timeline.ts b/src/server/api/stream/channels/hybrid-timeline.ts index 5c454764ec..0b28ff616b 100644 --- a/src/server/api/stream/channels/hybrid-timeline.ts +++ b/src/server/api/stream/channels/hybrid-timeline.ts @@ -4,7 +4,6 @@ import Channel from '../channel'; import { fetchMeta } from '@/misc/fetch-meta'; import { Notes } from '@/models/index'; import { PackedNote } from '@/models/repositories/note'; -import { PackedUser } from '@/models/repositories/user'; import { checkWordMute } from '@/misc/check-word-mute'; import { isBlockerUserRelated } from '@/misc/is-blocker-user-related'; @@ -31,7 +30,7 @@ export default class extends Channel { if (!( (note.channelId == null && this.user!.id === note.userId) || (note.channelId == null && this.following.has(note.userId)) || - (note.channelId == null && ((note.user as PackedUser).host == null && note.visibility === 'public')) || + (note.channelId == null && (note.user.host == null && note.visibility === 'public')) || (note.channelId != null && this.followingChannels.has(note.channelId)) )) return; @@ -60,7 +59,7 @@ export default class extends Channel { // 関係ない返信は除外 if (note.reply) { - const reply = note.reply as PackedNote; + const reply = note.reply; // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合 if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return; } diff --git a/src/server/api/stream/channels/local-timeline.ts b/src/server/api/stream/channels/local-timeline.ts index 4bf0d02ed3..20061410c4 100644 --- a/src/server/api/stream/channels/local-timeline.ts +++ b/src/server/api/stream/channels/local-timeline.ts @@ -4,7 +4,6 @@ import Channel from '../channel'; import { fetchMeta } from '@/misc/fetch-meta'; import { Notes } from '@/models/index'; import { PackedNote } from '@/models/repositories/note'; -import { PackedUser } from '@/models/repositories/user'; import { checkWordMute } from '@/misc/check-word-mute'; import { isBlockerUserRelated } from '@/misc/is-blocker-user-related'; @@ -26,7 +25,7 @@ export default class extends Channel { @autobind private async onNote(note: PackedNote) { - if ((note.user as PackedUser).host !== null) return; + if (note.user.host !== null) return; if (note.visibility !== 'public') return; if (note.channelId != null && !this.followingChannels.has(note.channelId)) return; @@ -45,7 +44,7 @@ export default class extends Channel { // 関係ない返信は除外 if (note.reply) { - const reply = note.reply as PackedNote; + const reply = note.reply; // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合 if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return; } diff --git a/src/server/api/stream/index.ts b/src/server/api/stream/index.ts index 469f28f11c..f83bc9331e 100644 --- a/src/server/api/stream/index.ts +++ b/src/server/api/stream/index.ts @@ -165,8 +165,8 @@ export default class Connection { }; add(note); - if (note.reply) add(note.reply as PackedNote); - if (note.renote) add(note.renote as PackedNote); + if (note.reply) add(note.reply); + if (note.renote) add(note.renote); } @autobind From f89a326d7f56eacfbfd77062d7250b008f657279 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 6 Sep 2021 03:34:21 +0900 Subject: [PATCH 4/6] clean up --- src/models/repositories/note.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/repositories/note.ts b/src/models/repositories/note.ts index 52f841b526..77fedd791f 100644 --- a/src/models/repositories/note.ts +++ b/src/models/repositories/note.ts @@ -3,7 +3,7 @@ import * as mfm from 'mfm-js'; import { Note } from '@/models/entities/note'; import { User } from '@/models/entities/user'; import { Users, PollVotes, DriveFiles, NoteReactions, Followings, Polls, Channels } from '../index'; -import { Schema, SchemaType } from '@/misc/schema'; +import { SchemaType } from '@/misc/schema'; import { nyaize } from '@/misc/nyaize'; import { awaitAll } from '@/prelude/await-all'; import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '@/misc/reaction-lib'; From abbeb9a0718759c8d92bd2ec4db51010ee64767f Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 6 Sep 2021 12:59:51 +0900 Subject: [PATCH 5/6] add simple-schema --- src/misc/schema.ts | 14 +++----------- src/misc/simple-schema.ts | 15 +++++++++++++++ src/server/api/endpoints.ts | 4 ++-- src/services/chart/core.ts | 14 +++++++------- test/utils.ts | 2 +- 5 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 src/misc/simple-schema.ts diff --git a/src/misc/schema.ts b/src/misc/schema.ts index c4ca80249d..f6fb128751 100644 --- a/src/misc/schema.ts +++ b/src/misc/schema.ts @@ -1,3 +1,4 @@ +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'; @@ -46,18 +47,9 @@ export const refs = { GalleryPost: packedGalleryPostSchema, }; -export type Schema = { - type: 'boolean' | 'number' | 'string' | 'array' | 'object' | 'any'; - nullable: boolean; - optional: boolean; - items?: Schema; +export interface Schema extends SimpleSchema { properties?: Obj; - description?: string; - example?: any; - format?: string; ref?: keyof typeof refs; - enum?: string[]; - default?: boolean | null; }; type NonUndefinedPropertyNames = { @@ -71,7 +63,7 @@ type UndefinedPropertyNames = { type OnlyRequired = Pick>; type OnlyOptional = Pick>; -export type Obj = { [key: string]: Schema }; +export interface Obj extends SimpleObj { [key: string]: Schema }; export type ObjType = { [P in keyof OnlyOptional]?: SchemaType } & diff --git a/src/misc/simple-schema.ts b/src/misc/simple-schema.ts new file mode 100644 index 0000000000..83590edbf2 --- /dev/null +++ b/src/misc/simple-schema.ts @@ -0,0 +1,15 @@ +export interface SimpleSchema { + type: 'boolean' | 'number' | 'string' | 'array' | 'object' | 'any'; + nullable: boolean; + optional: boolean; + items?: SimpleSchema; + properties?: SimpleObj; + description?: string; + example?: any; + format?: string; + ref?: string; + enum?: string[]; + default?: boolean | null; +}; + +export type SimpleObj = { [key: string]: SimpleSchema }; diff --git a/src/server/api/endpoints.ts b/src/server/api/endpoints.ts index 640b14ed6a..6d9d2b0782 100644 --- a/src/server/api/endpoints.ts +++ b/src/server/api/endpoints.ts @@ -3,7 +3,7 @@ import { dirname } from 'path'; import { Context } from 'cafy'; import * as path from 'path'; import * as glob from 'glob'; -import { Schema } from '@/misc/schema'; +import { SimpleSchema } from '@/misc/simple-schema'; //const _filename = fileURLToPath(import.meta.url); const _filename = __filename; @@ -34,7 +34,7 @@ export interface IEndpointMeta { }; }; - res?: Schema; + res?: SimpleSchema; /** * このエンドポイントにリクエストするのにユーザー情報が必須か否か diff --git a/src/services/chart/core.ts b/src/services/chart/core.ts index eee7d20efb..c0d3280c2b 100644 --- a/src/services/chart/core.ts +++ b/src/services/chart/core.ts @@ -7,7 +7,7 @@ import * as nestedProperty from 'nested-property'; import autobind from 'autobind-decorator'; import Logger from '../logger'; -import { Schema } from '@/misc/schema'; +import { SimpleSchema } from '@/misc/simple-schema'; import { EntitySchema, getRepository, Repository, LessThan, Between } from 'typeorm'; import { dateUTC, isTimeSame, isTimeBefore, subtractTime, addTime } from '@/prelude/time'; import { getChartInsertLock } from '@/misc/app-lock'; @@ -56,7 +56,7 @@ export default abstract class Chart> { diff: DeepPartial; group: string | null; }[] = []; - public schema: Schema; + public schema: SimpleSchema; protected repository: Repository; protected abstract genNewLog(latest: T): DeepPartial; @@ -69,7 +69,7 @@ export default abstract class Chart> { protected abstract fetchActual(group: string | null): Promise>; @autobind - private static convertSchemaToFlatColumnDefinitions(schema: Schema) { + private static convertSchemaToFlatColumnDefinitions(schema: SimpleSchema) { const columns = {} as any; const flatColumns = (x: Obj, path?: string) => { for (const [k, v] of Object.entries(x)) { @@ -181,7 +181,7 @@ export default abstract class Chart> { } @autobind - public static schemaToEntity(name: string, schema: Schema): EntitySchema { + public static schemaToEntity(name: string, schema: SimpleSchema): EntitySchema { return new EntitySchema({ name: `__chart__${camelToSnake(name)}`, columns: { @@ -211,7 +211,7 @@ export default abstract class Chart> { }); } - constructor(name: string, schema: Schema, grouped = false) { + constructor(name: string, schema: SimpleSchema, grouped = false) { this.name = name; this.schema = schema; const entity = Chart.schemaToEntity(name, schema); @@ -546,8 +546,8 @@ export default abstract class Chart> { } } -export function convertLog(logSchema: Schema): Schema { - const v: Schema = JSON.parse(JSON.stringify(logSchema)); // copy +export function convertLog(logSchema: SimpleSchema): SimpleSchema { + const v: SimpleSchema = JSON.parse(JSON.stringify(logSchema)); // copy if (v.type === 'number') { v.type = 'array'; v.items = { diff --git a/test/utils.ts b/test/utils.ts index 1a0c54463d..253c410bf0 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -158,7 +158,7 @@ export async function initTestDb(justBorrow = false, initEntities?: any[]) { await conn.close(); } catch (e) {} - return await createConnection({ + return createConnection({ type: 'postgres', host: config.db.host, port: config.db.port, From 02dbdc54c310be173550709a4ae43b885800c92d Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 6 Sep 2021 13:08:51 +0900 Subject: [PATCH 6/6] fix lint --- src/misc/schema.ts | 4 ++-- src/misc/simple-schema.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/misc/schema.ts b/src/misc/schema.ts index f6fb128751..90d4c3b715 100644 --- a/src/misc/schema.ts +++ b/src/misc/schema.ts @@ -50,7 +50,7 @@ export const refs = { export interface Schema extends SimpleSchema { properties?: Obj; ref?: keyof typeof refs; -}; +} type NonUndefinedPropertyNames = { [K in keyof T]: T[K]['optional'] extends true ? never : K @@ -63,7 +63,7 @@ type UndefinedPropertyNames = { type OnlyRequired = Pick>; type OnlyOptional = Pick>; -export interface Obj extends SimpleObj { [key: string]: Schema }; +export interface Obj extends SimpleObj { [key: string]: Schema; } export type ObjType = { [P in keyof OnlyOptional]?: SchemaType } & diff --git a/src/misc/simple-schema.ts b/src/misc/simple-schema.ts index 83590edbf2..abbb348e24 100644 --- a/src/misc/simple-schema.ts +++ b/src/misc/simple-schema.ts @@ -10,6 +10,6 @@ export interface SimpleSchema { ref?: string; enum?: string[]; default?: boolean | null; -}; +} -export type SimpleObj = { [key: string]: SimpleSchema }; +export interface SimpleObj { [key: string]: SimpleSchema; }