From e9355bf918f5a1577183a5c5a48d1ac8ffe0e213 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 2 May 2023 12:05:17 +0000 Subject: [PATCH] wip --- packages/misskey-js/src/endpoints.ts | 162 ++++++ packages/misskey-js/src/schema/antenna.ts | 89 ++++ packages/misskey-js/src/schema/app.ts | 33 ++ packages/misskey-js/src/schema/blocking.ts | 26 + packages/misskey-js/src/schema/channel.ts | 67 +++ packages/misskey-js/src/schema/clip.ts | 51 ++ packages/misskey-js/src/schema/drive-file.ts | 107 ++++ .../misskey-js/src/schema/drive-folder.ts | 39 ++ packages/misskey-js/src/schema/emoji.ts | 67 +++ .../src/schema/federation-instance.ts | 97 ++++ packages/misskey-js/src/schema/flash.ts | 51 ++ packages/misskey-js/src/schema/following.ts | 36 ++ .../misskey-js/src/schema/gallery-post.ts | 69 +++ packages/misskey-js/src/schema/hashtag.ts | 34 ++ packages/misskey-js/src/schema/muting.ts | 31 ++ .../misskey-js/src/schema/note-favorite.ts | 26 + .../misskey-js/src/schema/note-reaction.ts | 25 + packages/misskey-js/src/schema/note.ts | 174 +++++++ .../misskey-js/src/schema/notification.ts | 62 +++ packages/misskey-js/src/schema/page.ts | 51 ++ packages/misskey-js/src/schema/queue.ts | 25 + .../misskey-js/src/schema/renote-muting.ts | 26 + packages/misskey-js/src/schema/user-list.ts | 29 ++ packages/misskey-js/src/schema/user.ts | 463 ++++++++++++++++++ 24 files changed, 1840 insertions(+) create mode 100644 packages/misskey-js/src/endpoints.ts create mode 100644 packages/misskey-js/src/schema/antenna.ts create mode 100644 packages/misskey-js/src/schema/app.ts create mode 100644 packages/misskey-js/src/schema/blocking.ts create mode 100644 packages/misskey-js/src/schema/channel.ts create mode 100644 packages/misskey-js/src/schema/clip.ts create mode 100644 packages/misskey-js/src/schema/drive-file.ts create mode 100644 packages/misskey-js/src/schema/drive-folder.ts create mode 100644 packages/misskey-js/src/schema/emoji.ts create mode 100644 packages/misskey-js/src/schema/federation-instance.ts create mode 100644 packages/misskey-js/src/schema/flash.ts create mode 100644 packages/misskey-js/src/schema/following.ts create mode 100644 packages/misskey-js/src/schema/gallery-post.ts create mode 100644 packages/misskey-js/src/schema/hashtag.ts create mode 100644 packages/misskey-js/src/schema/muting.ts create mode 100644 packages/misskey-js/src/schema/note-favorite.ts create mode 100644 packages/misskey-js/src/schema/note-reaction.ts create mode 100644 packages/misskey-js/src/schema/note.ts create mode 100644 packages/misskey-js/src/schema/notification.ts create mode 100644 packages/misskey-js/src/schema/page.ts create mode 100644 packages/misskey-js/src/schema/queue.ts create mode 100644 packages/misskey-js/src/schema/renote-muting.ts create mode 100644 packages/misskey-js/src/schema/user-list.ts create mode 100644 packages/misskey-js/src/schema/user.ts diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts new file mode 100644 index 000000000..164ce7b5f --- /dev/null +++ b/packages/misskey-js/src/endpoints.ts @@ -0,0 +1,162 @@ +import { localUsernameSchema, passwordSchema } from "./schema/user"; + +export type RolePolicies = { + gtlAvailable: boolean; + ltlAvailable: boolean; + canPublicNote: boolean; + canInvite: boolean; + canManageCustomEmojis: boolean; + canSearchNotes: boolean; + canHideAds: boolean; + driveCapacityMb: number; + pinLimit: number; + antennaLimit: number; + wordMuteLimit: number; + webhookLimit: number; + clipLimit: number; + noteEachClipsLimit: number; + userListLimit: number; + userEachUserListsLimit: number; + rateLimitFactor: number; +}; + +export interface IEndpointMeta { + readonly stability?: 'deprecated' | 'experimental' | 'stable'; + + readonly tags?: ReadonlyArray; + + readonly errors?: { + readonly [key: string]: { + readonly message: string; + readonly code: string; + readonly id: string; + }; + }; + + readonly defines: { req: Schema | undefined; res: Schema | undefined; }[]; + + /** + * このエンドポイントにリクエストするのにユーザー情報が必須か否か + * 省略した場合は false として解釈されます。 + */ + readonly requireCredential?: boolean; + + /** + * isModeratorなロールを必要とするか + */ + readonly requireModerator?: boolean; + + /** + * isAdministratorなロールを必要とするか + */ + readonly requireAdmin?: boolean; + + readonly requireRolePolicy?: keyof RolePolicies; + + /** + * 引っ越し済みのユーザーによるリクエストを禁止するか + * 省略した場合は false として解釈されます。 + */ + readonly prohibitMoved?: boolean; + + /** + * エンドポイントのリミテーションに関するやつ + * 省略した場合はリミテーションは無いものとして解釈されます。 + */ + readonly limit?: { + + /** + * 複数のエンドポイントでリミットを共有したい場合に指定するキー + */ + readonly key?: string; + + /** + * リミットを適用する期間(ms) + * このプロパティを設定する場合、max プロパティも設定する必要があります。 + */ + readonly duration?: number; + + /** + * durationで指定した期間内にいくつまでリクエストできるのか + * このプロパティを設定する場合、duration プロパティも設定する必要があります。 + */ + readonly max?: number; + + /** + * 最低でもどれくらいの間隔を開けてリクエストしなければならないか(ms) + */ + readonly minInterval?: number; + }; + + /** + * ファイルの添付を必要とするか否か + * 省略した場合は false として解釈されます。 + */ + readonly requireFile?: boolean; + + /** + * サードパーティアプリからはリクエストすることができないか否か + * 省略した場合は false として解釈されます。 + */ + readonly secure?: boolean; + + /** + * エンドポイントの種類 + * パーミッションの実現に利用されます。 + */ + readonly kind?: string; + + readonly description?: string; + + /** + * GETでのリクエストを許容するか否か + */ + readonly allowGet?: boolean; + + /** + * 正常応答をキャッシュ (Cache-Control: public) する秒数 + */ + readonly cacheSec?: number; +} + +export const endpoints = { + "admin/accounts/create": { + tags: ['admin'], + defines: [{ + req: { + type: 'object', + properties: { + username: localUsernameSchema, + password: passwordSchema, + }, + required: ['username', 'password'], + }, + res: { + type: 'object', + ref: 'User', + properties: { + token: { + type: 'string', + }, + required: ['token'], + }, + }, + }], + }, + "admin/accounts/delete": { + tags: ['admin'], + + requireCredential: true, + requireAdmin: true, + defines: [{ + req: { + type: 'object', + properties: { + userId: { type: 'string', format: 'misskey:id' }, + }, + required: ['userId'], + }, + res: undefined, + }], + }, +} as const; diff --git a/packages/misskey-js/src/schema/antenna.ts b/packages/misskey-js/src/schema/antenna.ts new file mode 100644 index 000000000..d0c7e7c23 --- /dev/null +++ b/packages/misskey-js/src/schema/antenna.ts @@ -0,0 +1,89 @@ +export const packedAntennaSchema = { + type: 'object', + properties: { + id: { + type: 'string', + format: 'id', + }, + createdAt: { + type: 'string', + format: 'date-time', + }, + name: { + type: 'string', + }, + keywords: { + type: 'array', + items: { + type: 'array', + items: { + type: 'string', + }, + }, + }, + excludeKeywords: { + type: 'array', + items: { + type: 'array', + items: { + type: 'string', + }, + }, + }, + src: { + type: 'string', + enum: ['home', 'all', 'users', 'list'], + }, + userListId: { + oneOf: [{ + type: 'string', + format: 'id', + }, { + type: 'null', + }], + }, + users: { + type: 'array', + items: { + type: 'string', + }, + }, + caseSensitive: { + type: 'boolean', + default: false, + }, + notify: { + type: 'boolean', + }, + withReplies: { + type: 'boolean', + default: false, + }, + withFile: { + type: 'boolean', + }, + isActive: { + type: 'boolean', + }, + hasUnreadNote: { + type: 'boolean', + default: false, + }, + required: [ + 'id', + 'createdAt', + 'name', + 'keywords', + 'excludeKeywords', + 'src', + 'userListId', + 'users', + 'caseSensitive', + 'notify', + 'withReplies', + 'withFile', + 'isActive', + 'hasUnreadNote', + ], + }, +} as const; diff --git a/packages/misskey-js/src/schema/app.ts b/packages/misskey-js/src/schema/app.ts new file mode 100644 index 000000000..c80dc81c3 --- /dev/null +++ b/packages/misskey-js/src/schema/app.ts @@ -0,0 +1,33 @@ +export const packedAppSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + }, + name: { + type: 'string', + optional: false, nullable: false, + }, + callbackUrl: { + type: 'string', + optional: false, nullable: true, + }, + permission: { + type: 'array', + optional: false, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + }, + }, + secret: { + type: 'string', + optional: true, nullable: false, + }, + isAuthorized: { + type: 'boolean', + optional: true, nullable: false, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/blocking.ts b/packages/misskey-js/src/schema/blocking.ts new file mode 100644 index 000000000..553232242 --- /dev/null +++ b/packages/misskey-js/src/schema/blocking.ts @@ -0,0 +1,26 @@ +export const packedBlockingSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + blockeeId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + blockee: { + type: 'object', + optional: false, nullable: false, + ref: 'UserDetailed', + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/channel.ts b/packages/misskey-js/src/schema/channel.ts new file mode 100644 index 000000000..cb42c782b --- /dev/null +++ b/packages/misskey-js/src/schema/channel.ts @@ -0,0 +1,67 @@ +export const packedChannelSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + lastNotedAt: { + type: 'string', + optional: false, nullable: true, + format: 'date-time', + }, + name: { + type: 'string', + optional: false, nullable: false, + }, + description: { + type: 'string', + nullable: true, optional: false, + }, + bannerUrl: { + type: 'string', + format: 'url', + nullable: true, optional: false, + }, + notesCount: { + type: 'number', + nullable: false, optional: false, + }, + usersCount: { + type: 'number', + nullable: false, optional: false, + }, + isFollowing: { + type: 'boolean', + optional: true, nullable: false, + }, + isFavorited: { + type: 'boolean', + optional: true, nullable: false, + }, + userId: { + type: 'string', + nullable: true, optional: false, + format: 'id', + }, + pinnedNoteIds: { + type: 'array', + nullable: false, optional: false, + items: { + type: 'string', + format: 'id', + }, + }, + color: { + type: 'string', + optional: false, nullable: false, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/clip.ts b/packages/misskey-js/src/schema/clip.ts new file mode 100644 index 000000000..7310e5901 --- /dev/null +++ b/packages/misskey-js/src/schema/clip.ts @@ -0,0 +1,51 @@ +export const packedClipSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + lastClippedAt: { + type: 'string', + optional: false, nullable: true, + format: 'date-time', + }, + userId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + user: { + type: 'object', + ref: 'UserLite', + optional: false, nullable: false, + }, + name: { + type: 'string', + optional: false, nullable: false, + }, + description: { + type: 'string', + optional: false, nullable: true, + }, + isPublic: { + type: 'boolean', + optional: false, nullable: false, + }, + isFavorited: { + type: 'boolean', + optional: true, nullable: false, + }, + favoritedCount: { + type: 'number', + optional: false, nullable: false, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/drive-file.ts b/packages/misskey-js/src/schema/drive-file.ts new file mode 100644 index 000000000..435907661 --- /dev/null +++ b/packages/misskey-js/src/schema/drive-file.ts @@ -0,0 +1,107 @@ +export const packedDriveFileSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + name: { + type: 'string', + optional: false, nullable: false, + example: 'lenna.jpg', + }, + type: { + type: 'string', + optional: false, nullable: false, + example: 'image/jpeg', + }, + md5: { + type: 'string', + optional: false, nullable: false, + format: 'md5', + example: '15eca7fba0480996e2245f5185bf39f2', + }, + size: { + type: 'number', + optional: false, nullable: false, + example: 51469, + }, + isSensitive: { + type: 'boolean', + optional: false, nullable: false, + }, + blurhash: { + type: 'string', + optional: false, nullable: true, + }, + properties: { + type: 'object', + optional: false, nullable: false, + properties: { + width: { + type: 'number', + optional: true, nullable: false, + example: 1280, + }, + height: { + type: 'number', + optional: true, nullable: false, + example: 720, + }, + orientation: { + type: 'number', + optional: true, nullable: false, + example: 8, + }, + avgColor: { + type: 'string', + optional: true, nullable: false, + example: 'rgb(40,65,87)', + }, + }, + }, + url: { + type: 'string', + optional: false, nullable: true, + format: 'url', + }, + thumbnailUrl: { + type: 'string', + optional: false, nullable: true, + format: 'url', + }, + comment: { + type: 'string', + optional: false, nullable: true, + }, + folderId: { + type: 'string', + optional: false, nullable: true, + format: 'id', + example: 'xxxxxxxxxx', + }, + folder: { + type: 'object', + optional: true, nullable: true, + ref: 'DriveFolder', + }, + userId: { + type: 'string', + optional: false, nullable: true, + format: 'id', + example: 'xxxxxxxxxx', + }, + user: { + type: 'object', + optional: true, nullable: true, + ref: 'UserLite', + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/drive-folder.ts b/packages/misskey-js/src/schema/drive-folder.ts new file mode 100644 index 000000000..88cb8ab4a --- /dev/null +++ b/packages/misskey-js/src/schema/drive-folder.ts @@ -0,0 +1,39 @@ +export const packedDriveFolderSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + name: { + type: 'string', + optional: false, nullable: false, + }, + foldersCount: { + type: 'number', + optional: true, nullable: false, + }, + filesCount: { + type: 'number', + optional: true, nullable: false, + }, + parentId: { + type: 'string', + optional: false, nullable: true, + format: 'id', + example: 'xxxxxxxxxx', + }, + parent: { + type: 'object', + optional: true, nullable: true, + ref: 'DriveFolder', + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/emoji.ts b/packages/misskey-js/src/schema/emoji.ts new file mode 100644 index 000000000..db4fd62cf --- /dev/null +++ b/packages/misskey-js/src/schema/emoji.ts @@ -0,0 +1,67 @@ +export const packedEmojiSimpleSchema = { + type: 'object', + properties: { + aliases: { + type: 'array', + optional: false, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + }, + name: { + type: 'string', + optional: false, nullable: false, + }, + category: { + type: 'string', + optional: false, nullable: true, + }, + url: { + type: 'string', + optional: false, nullable: false, + }, + }, +} as const; + +export const packedEmojiDetailedSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + aliases: { + type: 'array', + optional: false, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + }, + name: { + type: 'string', + optional: false, nullable: false, + }, + category: { + type: 'string', + optional: false, nullable: true, + }, + host: { + type: 'string', + optional: false, nullable: true, + description: 'The local host is represented with `null`.', + }, + url: { + type: 'string', + optional: false, nullable: false, + }, + license: { + type: 'string', + optional: false, nullable: true, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/federation-instance.ts b/packages/misskey-js/src/schema/federation-instance.ts new file mode 100644 index 000000000..42d93dfac --- /dev/null +++ b/packages/misskey-js/src/schema/federation-instance.ts @@ -0,0 +1,97 @@ +export const packedFederationInstanceSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + firstRetrievedAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + host: { + type: 'string', + optional: false, nullable: false, + example: 'misskey.example.com', + }, + usersCount: { + type: 'number', + optional: false, nullable: false, + }, + notesCount: { + type: 'number', + optional: false, nullable: false, + }, + followingCount: { + type: 'number', + optional: false, nullable: false, + }, + followersCount: { + type: 'number', + optional: false, nullable: false, + }, + isNotResponding: { + type: 'boolean', + optional: false, nullable: false, + }, + isSuspended: { + type: 'boolean', + optional: false, nullable: false, + }, + isBlocked: { + type: 'boolean', + optional: false, nullable: false, + }, + softwareName: { + type: 'string', + optional: false, nullable: true, + example: 'misskey', + }, + softwareVersion: { + type: 'string', + optional: false, nullable: true, + }, + openRegistrations: { + type: 'boolean', + optional: false, nullable: true, + example: true, + }, + name: { + type: 'string', + optional: false, nullable: true, + }, + description: { + type: 'string', + optional: false, nullable: true, + }, + maintainerName: { + type: 'string', + optional: false, nullable: true, + }, + maintainerEmail: { + type: 'string', + optional: false, nullable: true, + }, + iconUrl: { + type: 'string', + optional: false, nullable: true, + format: 'url', + }, + faviconUrl: { + type: 'string', + optional: false, nullable: true, + format: 'url', + }, + themeColor: { + type: 'string', + optional: false, nullable: true, + }, + infoUpdatedAt: { + type: 'string', + optional: false, nullable: true, + format: 'date-time', + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/flash.ts b/packages/misskey-js/src/schema/flash.ts new file mode 100644 index 000000000..8471a138e --- /dev/null +++ b/packages/misskey-js/src/schema/flash.ts @@ -0,0 +1,51 @@ +export const packedFlashSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + updatedAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + title: { + type: 'string', + optional: false, nullable: false, + }, + summary: { + type: 'string', + optional: false, nullable: false, + }, + script: { + type: 'string', + optional: false, nullable: false, + }, + userId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + user: { + type: 'object', + ref: 'UserLite', + optional: false, nullable: false, + }, + likedCount: { + type: 'number', + optional: false, nullable: true, + }, + isLiked: { + type: 'boolean', + optional: true, nullable: false, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/following.ts b/packages/misskey-js/src/schema/following.ts new file mode 100644 index 000000000..2bcffbfc4 --- /dev/null +++ b/packages/misskey-js/src/schema/following.ts @@ -0,0 +1,36 @@ +export const packedFollowingSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + followeeId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + followee: { + type: 'object', + optional: true, nullable: false, + ref: 'UserDetailed', + }, + followerId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + follower: { + type: 'object', + optional: true, nullable: false, + ref: 'UserDetailed', + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/gallery-post.ts b/packages/misskey-js/src/schema/gallery-post.ts new file mode 100644 index 000000000..fc503d4a6 --- /dev/null +++ b/packages/misskey-js/src/schema/gallery-post.ts @@ -0,0 +1,69 @@ +export const packedGalleryPostSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + updatedAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + title: { + type: 'string', + optional: false, nullable: false, + }, + description: { + type: 'string', + optional: false, nullable: true, + }, + userId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + user: { + type: 'object', + ref: 'UserLite', + optional: false, nullable: false, + }, + fileIds: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + }, + files: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'object', + optional: false, nullable: false, + ref: 'DriveFile', + }, + }, + tags: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + }, + }, + isSensitive: { + type: 'boolean', + optional: false, nullable: false, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/hashtag.ts b/packages/misskey-js/src/schema/hashtag.ts new file mode 100644 index 000000000..98f882764 --- /dev/null +++ b/packages/misskey-js/src/schema/hashtag.ts @@ -0,0 +1,34 @@ +export const packedHashtagSchema = { + type: 'object', + properties: { + tag: { + type: 'string', + optional: false, nullable: false, + example: 'misskey', + }, + mentionedUsersCount: { + type: 'number', + optional: false, nullable: false, + }, + mentionedLocalUsersCount: { + type: 'number', + optional: false, nullable: false, + }, + mentionedRemoteUsersCount: { + type: 'number', + optional: false, nullable: false, + }, + attachedUsersCount: { + type: 'number', + optional: false, nullable: false, + }, + attachedLocalUsersCount: { + type: 'number', + optional: false, nullable: false, + }, + attachedRemoteUsersCount: { + type: 'number', + optional: false, nullable: false, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/muting.ts b/packages/misskey-js/src/schema/muting.ts new file mode 100644 index 000000000..3ab99e17e --- /dev/null +++ b/packages/misskey-js/src/schema/muting.ts @@ -0,0 +1,31 @@ +export const packedMutingSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + expiresAt: { + type: 'string', + optional: false, nullable: true, + format: 'date-time', + }, + muteeId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + mutee: { + type: 'object', + optional: false, nullable: false, + ref: 'UserDetailed', + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/note-favorite.ts b/packages/misskey-js/src/schema/note-favorite.ts new file mode 100644 index 000000000..d133f7367 --- /dev/null +++ b/packages/misskey-js/src/schema/note-favorite.ts @@ -0,0 +1,26 @@ +export const packedNoteFavoriteSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + note: { + type: 'object', + optional: false, nullable: false, + ref: 'Note', + }, + noteId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/note-reaction.ts b/packages/misskey-js/src/schema/note-reaction.ts new file mode 100644 index 000000000..0d8fc5449 --- /dev/null +++ b/packages/misskey-js/src/schema/note-reaction.ts @@ -0,0 +1,25 @@ +export const packedNoteReactionSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + user: { + type: 'object', + optional: false, nullable: false, + ref: 'UserLite', + }, + type: { + type: 'string', + optional: false, nullable: false, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/note.ts b/packages/misskey-js/src/schema/note.ts new file mode 100644 index 000000000..58ef425dc --- /dev/null +++ b/packages/misskey-js/src/schema/note.ts @@ -0,0 +1,174 @@ +export const packedNoteSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + deletedAt: { + type: 'string', + optional: true, nullable: true, + format: 'date-time', + }, + text: { + type: 'string', + optional: false, nullable: true, + }, + cw: { + type: 'string', + optional: true, nullable: true, + }, + userId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + user: { + type: 'object', + ref: 'UserLite', + optional: false, nullable: false, + }, + replyId: { + type: 'string', + optional: true, nullable: true, + format: 'id', + example: 'xxxxxxxxxx', + }, + renoteId: { + type: 'string', + optional: true, nullable: true, + format: 'id', + example: 'xxxxxxxxxx', + }, + reply: { + type: 'object', + optional: true, nullable: true, + ref: 'Note', + }, + renote: { + type: 'object', + optional: true, nullable: true, + ref: 'Note', + }, + isHidden: { + type: 'boolean', + optional: true, nullable: false, + }, + visibility: { + type: 'string', + optional: false, nullable: false, + }, + mentions: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + }, + visibleUserIds: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + }, + fileIds: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + }, + files: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'object', + optional: false, nullable: false, + ref: 'DriveFile', + }, + }, + tags: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + }, + }, + poll: { + type: 'object', + optional: true, nullable: true, + }, + channelId: { + type: 'string', + optional: true, nullable: true, + format: 'id', + example: 'xxxxxxxxxx', + }, + channel: { + type: 'object', + optional: true, nullable: true, + items: { + type: 'object', + optional: false, nullable: false, + properties: { + id: { + type: 'string', + optional: false, nullable: false, + }, + name: { + type: 'string', + optional: false, nullable: true, + }, + }, + }, + }, + localOnly: { + type: 'boolean', + optional: true, nullable: false, + }, + reactionAcceptance: { + type: 'string', + optional: false, nullable: true, + }, + reactions: { + type: 'object', + optional: false, nullable: false, + }, + renoteCount: { + type: 'number', + optional: false, nullable: false, + }, + repliesCount: { + type: 'number', + optional: false, nullable: false, + }, + uri: { + type: 'string', + optional: true, nullable: false, + }, + url: { + type: 'string', + optional: true, nullable: false, + }, + + myReaction: { + type: 'object', + optional: true, nullable: true, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/notification.ts b/packages/misskey-js/src/schema/notification.ts new file mode 100644 index 000000000..e88ca61ba --- /dev/null +++ b/packages/misskey-js/src/schema/notification.ts @@ -0,0 +1,62 @@ +import { notificationTypes } from '@/types.js'; + +export const packedNotificationSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + type: { + type: 'string', + optional: false, nullable: false, + enum: [...notificationTypes], + }, + user: { + type: 'object', + ref: 'UserLite', + optional: true, nullable: true, + }, + userId: { + type: 'string', + optional: true, nullable: true, + format: 'id', + }, + note: { + type: 'object', + ref: 'Note', + optional: true, nullable: true, + }, + reaction: { + type: 'string', + optional: true, nullable: true, + }, + choice: { + type: 'number', + optional: true, nullable: true, + }, + invitation: { + type: 'object', + optional: true, nullable: true, + }, + body: { + type: 'string', + optional: true, nullable: true, + }, + header: { + type: 'string', + optional: true, nullable: true, + }, + icon: { + type: 'string', + optional: true, nullable: true, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/page.ts b/packages/misskey-js/src/schema/page.ts new file mode 100644 index 000000000..55ba3ce7f --- /dev/null +++ b/packages/misskey-js/src/schema/page.ts @@ -0,0 +1,51 @@ +export const packedPageSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + updatedAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + title: { + type: 'string', + optional: false, nullable: false, + }, + name: { + type: 'string', + optional: false, nullable: false, + }, + summary: { + type: 'string', + optional: false, nullable: true, + }, + content: { + type: 'array', + optional: false, nullable: false, + }, + variables: { + type: 'array', + optional: false, nullable: false, + }, + userId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + user: { + type: 'object', + ref: 'UserLite', + optional: false, nullable: false, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/queue.ts b/packages/misskey-js/src/schema/queue.ts new file mode 100644 index 000000000..7ceeda26a --- /dev/null +++ b/packages/misskey-js/src/schema/queue.ts @@ -0,0 +1,25 @@ +export const packedQueueCountSchema = { + type: 'object', + properties: { + waiting: { + type: 'number', + optional: false, nullable: false, + }, + active: { + type: 'number', + optional: false, nullable: false, + }, + completed: { + type: 'number', + optional: false, nullable: false, + }, + failed: { + type: 'number', + optional: false, nullable: false, + }, + delayed: { + type: 'number', + optional: false, nullable: false, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/renote-muting.ts b/packages/misskey-js/src/schema/renote-muting.ts new file mode 100644 index 000000000..69ed8510d --- /dev/null +++ b/packages/misskey-js/src/schema/renote-muting.ts @@ -0,0 +1,26 @@ +export const packedRenoteMutingSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + muteeId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + mutee: { + type: 'object', + optional: false, nullable: false, + ref: 'UserDetailed', + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/user-list.ts b/packages/misskey-js/src/schema/user-list.ts new file mode 100644 index 000000000..3ba5dc4a8 --- /dev/null +++ b/packages/misskey-js/src/schema/user-list.ts @@ -0,0 +1,29 @@ +export const packedUserListSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + name: { + type: 'string', + optional: false, nullable: false, + }, + userIds: { + type: 'array', + nullable: false, optional: true, + items: { + type: 'string', + nullable: false, optional: false, + format: 'id', + }, + }, + }, +} as const; diff --git a/packages/misskey-js/src/schema/user.ts b/packages/misskey-js/src/schema/user.ts new file mode 100644 index 000000000..fac95a9a5 --- /dev/null +++ b/packages/misskey-js/src/schema/user.ts @@ -0,0 +1,463 @@ +export const packedUserLiteSchema = { + type: 'object', + properties: { + id: { + type: 'string', + nullable: false, optional: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + name: { + type: 'string', + nullable: true, optional: false, + example: '藍', + }, + username: { + type: 'string', + nullable: false, optional: false, + example: 'ai', + }, + host: { + type: 'string', + nullable: true, optional: false, + example: 'misskey.example.com', + description: 'The local host is represented with `null`.', + }, + avatarUrl: { + type: 'string', + format: 'url', + nullable: true, optional: false, + }, + avatarBlurhash: { + type: 'string', + nullable: true, optional: false, + }, + isAdmin: { + type: 'boolean', + nullable: false, optional: true, + default: false, + }, + isModerator: { + type: 'boolean', + nullable: false, optional: true, + default: false, + }, + isBot: { + type: 'boolean', + nullable: false, optional: true, + }, + isCat: { + type: 'boolean', + nullable: false, optional: true, + }, + onlineStatus: { + type: 'string', + format: 'url', + nullable: true, optional: false, + enum: ['unknown', 'online', 'active', 'offline'], + }, + }, +} as const; + +export const packedUserDetailedNotMeOnlySchema = { + type: 'object', + properties: { + url: { + type: 'string', + format: 'url', + nullable: true, optional: false, + }, + uri: { + type: 'string', + format: 'uri', + nullable: true, optional: false, + }, + movedToUri: { + type: 'string', + format: 'uri', + nullable: true, + optional: false, + }, + alsoKnownAs: { + type: 'array', + nullable: true, + optional: false, + items: { + type: 'string', + format: 'id', + nullable: false, + optional: false, + }, + }, + createdAt: { + type: 'string', + nullable: false, optional: false, + format: 'date-time', + }, + updatedAt: { + type: 'string', + nullable: true, optional: false, + format: 'date-time', + }, + lastFetchedAt: { + type: 'string', + nullable: true, optional: false, + format: 'date-time', + }, + bannerUrl: { + type: 'string', + format: 'url', + nullable: true, optional: false, + }, + bannerBlurhash: { + type: 'string', + nullable: true, optional: false, + }, + isLocked: { + type: 'boolean', + nullable: false, optional: false, + }, + isSilenced: { + type: 'boolean', + nullable: false, optional: false, + }, + isSuspended: { + type: 'boolean', + nullable: false, optional: false, + example: false, + }, + description: { + type: 'string', + nullable: true, optional: false, + example: 'Hi masters, I am Ai!', + }, + location: { + type: 'string', + nullable: true, optional: false, + }, + birthday: { + type: 'string', + nullable: true, optional: false, + example: '2018-03-12', + }, + lang: { + type: 'string', + nullable: true, optional: false, + example: 'ja-JP', + }, + fields: { + type: 'array', + nullable: false, optional: false, + items: { + type: 'object', + nullable: false, optional: false, + properties: { + name: { + type: 'string', + nullable: false, optional: false, + }, + value: { + type: 'string', + nullable: false, optional: false, + }, + }, + maxLength: 4, + }, + }, + followersCount: { + type: 'number', + nullable: false, optional: false, + }, + followingCount: { + type: 'number', + nullable: false, optional: false, + }, + notesCount: { + type: 'number', + nullable: false, optional: false, + }, + pinnedNoteIds: { + type: 'array', + nullable: false, optional: false, + items: { + type: 'string', + nullable: false, optional: false, + format: 'id', + }, + }, + pinnedNotes: { + type: 'array', + nullable: false, optional: false, + items: { + type: 'object', + nullable: false, optional: false, + ref: 'Note', + }, + }, + pinnedPageId: { + type: 'string', + nullable: true, optional: false, + }, + pinnedPage: { + type: 'object', + nullable: true, optional: false, + ref: 'Page', + }, + publicReactions: { + type: 'boolean', + nullable: false, optional: false, + }, + twoFactorEnabled: { + type: 'boolean', + nullable: false, optional: false, + default: false, + }, + usePasswordLessLogin: { + type: 'boolean', + nullable: false, optional: false, + default: false, + }, + securityKeys: { + type: 'boolean', + nullable: false, optional: false, + default: false, + }, + //#region relations + isFollowing: { + type: 'boolean', + nullable: false, optional: true, + }, + isFollowed: { + type: 'boolean', + nullable: false, optional: true, + }, + hasPendingFollowRequestFromYou: { + type: 'boolean', + nullable: false, optional: true, + }, + hasPendingFollowRequestToYou: { + type: 'boolean', + nullable: false, optional: true, + }, + isBlocking: { + type: 'boolean', + nullable: false, optional: true, + }, + isBlocked: { + type: 'boolean', + nullable: false, optional: true, + }, + isMuted: { + type: 'boolean', + nullable: false, optional: true, + }, + isRenoteMuted: { + type: 'boolean', + nullable: false, optional: true, + }, + memo: { + type: 'string', + nullable: false, optional: true, + }, + //#endregion + }, +} as const; + +export const packedMeDetailedOnlySchema = { + type: 'object', + properties: { + avatarId: { + type: 'string', + nullable: true, optional: false, + format: 'id', + }, + bannerId: { + type: 'string', + nullable: true, optional: false, + format: 'id', + }, + injectFeaturedNote: { + type: 'boolean', + nullable: true, optional: false, + }, + receiveAnnouncementEmail: { + type: 'boolean', + nullable: true, optional: false, + }, + alwaysMarkNsfw: { + type: 'boolean', + nullable: true, optional: false, + }, + autoSensitive: { + type: 'boolean', + nullable: true, optional: false, + }, + carefulBot: { + type: 'boolean', + nullable: true, optional: false, + }, + autoAcceptFollowed: { + type: 'boolean', + nullable: true, optional: false, + }, + noCrawle: { + type: 'boolean', + nullable: true, optional: false, + }, + isExplorable: { + type: 'boolean', + nullable: false, optional: false, + }, + isDeleted: { + type: 'boolean', + nullable: false, optional: false, + }, + hideOnlineStatus: { + type: 'boolean', + nullable: false, optional: false, + }, + hasUnreadSpecifiedNotes: { + type: 'boolean', + nullable: false, optional: false, + }, + hasUnreadMentions: { + type: 'boolean', + nullable: false, optional: false, + }, + hasUnreadAnnouncement: { + type: 'boolean', + nullable: false, optional: false, + }, + hasUnreadAntenna: { + type: 'boolean', + nullable: false, optional: false, + }, + hasUnreadNotification: { + type: 'boolean', + nullable: false, optional: false, + }, + hasPendingReceivedFollowRequest: { + type: 'boolean', + nullable: false, optional: false, + }, + mutedWords: { + type: 'array', + nullable: false, optional: false, + items: { + type: 'array', + nullable: false, optional: false, + items: { + type: 'string', + nullable: false, optional: false, + }, + }, + }, + mutedInstances: { + type: 'array', + nullable: true, optional: false, + items: { + type: 'string', + nullable: false, optional: false, + }, + }, + mutingNotificationTypes: { + type: 'array', + nullable: true, optional: false, + items: { + type: 'string', + nullable: false, optional: false, + }, + }, + emailNotificationTypes: { + type: 'array', + nullable: true, optional: false, + items: { + type: 'string', + nullable: false, optional: false, + }, + }, + //#region secrets + email: { + type: 'string', + nullable: true, optional: true, + }, + emailVerified: { + type: 'boolean', + nullable: true, optional: true, + }, + securityKeysList: { + type: 'array', + nullable: false, optional: true, + items: { + type: 'object', + nullable: false, optional: false, + }, + }, + //#endregion + }, +} as const; + +export const packedUserDetailedNotMeSchema = { + type: 'object', + allOf: [ + { + type: 'object', + ref: 'UserLite', + }, + { + type: 'object', + ref: 'UserDetailedNotMeOnly', + }, + ], +} as const; + +export const packedMeDetailedSchema = { + type: 'object', + allOf: [ + { + type: 'object', + ref: 'UserLite', + }, + { + type: 'object', + ref: 'UserDetailedNotMeOnly', + }, + { + type: 'object', + ref: 'MeDetailedOnly', + }, + ], +} as const; + +export const packedUserDetailedSchema = { + oneOf: [ + { + type: 'object', + ref: 'UserDetailedNotMe', + }, + { + type: 'object', + ref: 'MeDetailed', + }, + ], +} as const; + +export const packedUserSchema = { + oneOf: [ + { + type: 'object', + ref: 'UserLite', + }, + { + type: 'object', + ref: 'UserDetailed', + }, + ], +} as const; + +export const localUsernameSchema = { type: 'string', pattern: /^\w{1,20}$/.toString().slice(1, -1) } as const; +export const passwordSchema = { type: 'string', minLength: 1 } as const; +export const nameSchema = { type: 'string', minLength: 1, maxLength: 50 } as const; +export const descriptionSchema = { type: 'string', minLength: 1, maxLength: 1500 } as const; +export const locationSchema = { type: 'string', minLength: 1, maxLength: 50 } as const; +export const birthdaySchema = { type: 'string', pattern: /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.toString().slice(1, -1) } as const;