From ad6c5275ece6458eb4d6309d495379d6d362627d Mon Sep 17 00:00:00 2001 From: tamaina Date: Wed, 10 May 2023 16:22:21 +0000 Subject: [PATCH] wip --- packages/misskey-js/src/schemas/queue.ts | 18 +- .../misskey-js/src/schemas/renote-muting.ts | 32 +- packages/misskey-js/src/schemas/user-list.ts | 27 +- packages/misskey-js/src/schemas/user.ts | 475 ++++++++++-------- 4 files changed, 292 insertions(+), 260 deletions(-) diff --git a/packages/misskey-js/src/schemas/queue.ts b/packages/misskey-js/src/schemas/queue.ts index 7ceeda26a..5dfcfb6f0 100644 --- a/packages/misskey-js/src/schemas/queue.ts +++ b/packages/misskey-js/src/schemas/queue.ts @@ -1,25 +1,31 @@ +import type { JSONSchema7Definition } from 'schema-type'; + export const packedQueueCountSchema = { + $id: 'https://misskey-hub.net/api/schemas/QueueCount', + 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; + required: [ + 'waiting', + 'active', + 'completed', + 'failed', + 'delayed', + ], +} as const satisfies JSONSchema7Definition; diff --git a/packages/misskey-js/src/schemas/renote-muting.ts b/packages/misskey-js/src/schemas/renote-muting.ts index 69ed8510d..3344e9f37 100644 --- a/packages/misskey-js/src/schemas/renote-muting.ts +++ b/packages/misskey-js/src/schemas/renote-muting.ts @@ -1,26 +1,22 @@ +import type { JSONSchema7Definition } from 'schema-type'; + export const packedRenoteMutingSchema = { + $id: 'https://misskey-hub.net/api/schemas/RenoteMuting', + type: 'object', properties: { - id: { - type: 'string', - optional: false, nullable: false, - format: 'id', - example: 'xxxxxxxxxx', - }, + id: { $ref: 'https://misskey-hub.net/api/schemas/Id' }, 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', - }, + muteeId: { $ref: 'https://misskey-hub.net/api/schemas/Id' }, + mutee: { $ref: 'https://misskey-hub.net/api/schemas/UserDetailed' }, }, -} as const; + required: [ + 'id', + 'createdAt', + 'muteeId', + 'mutee', + ], +} as const satisfies JSONSchema7Definition; diff --git a/packages/misskey-js/src/schemas/user-list.ts b/packages/misskey-js/src/schemas/user-list.ts index 3ba5dc4a8..7ebda6527 100644 --- a/packages/misskey-js/src/schemas/user-list.ts +++ b/packages/misskey-js/src/schemas/user-list.ts @@ -1,29 +1,26 @@ +import type { JSONSchema7Definition } from 'schema-type'; + export const packedUserListSchema = { + $id: 'https://misskey-hub.net/api/schemas/UserList', + type: 'object', properties: { - id: { - type: 'string', - optional: false, nullable: false, - format: 'id', - example: 'xxxxxxxxxx', - }, + id: { $ref: 'https://misskey-hub.net/api/schemas/Id' }, 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', - }, + items: { $ref: 'https://misskey-hub.net/api/schemas/Id' }, }, }, -} as const; + required: [ + 'id', + 'createdAt', + 'name', + ], +} as const satisfies JSONSchema7Definition; diff --git a/packages/misskey-js/src/schemas/user.ts b/packages/misskey-js/src/schemas/user.ts index 5c1cbfebf..29ddc00d0 100644 --- a/packages/misskey-js/src/schemas/user.ts +++ b/packages/misskey-js/src/schemas/user.ts @@ -1,267 +1,300 @@ +import type { JSONSchema7Definition } from 'schema-type'; + export const packedUserLiteSchema = { + $id: 'https://misskey-hub.net/api/schemas/UserLite', + type: 'object', properties: { - id: { - type: 'string', - nullable: false, optional: false, - format: 'id', - example: 'xxxxxxxxxx', - }, + id: { $ref: 'https://misskey-hub.net/api/schemas/Id' }, name: { - type: 'string', - nullable: true, optional: false, - example: '藍', + type: ['string', 'null'], + examples: '藍', }, username: { type: 'string', - nullable: false, optional: false, - example: 'ai', + examples: 'ai', }, host: { - type: 'string', - nullable: true, optional: false, - example: 'misskey.example.com', + type: ['string', 'null'], + examples: 'misskey.example.com', description: 'The local host is represented with `null`.', }, avatarUrl: { - type: 'string', - format: 'url', - nullable: true, optional: false, + oneOf: [{ + type: 'string', + format: 'url', + }, { + type: 'null', + }], }, avatarBlurhash: { - type: 'string', - nullable: true, optional: false, + type: ['string', 'null'], }, 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'], + type: ['string', 'null'], + enum: ['unknown', 'online', 'active', 'offline', null], }, }, -} as const; + required: [ + 'id', + 'name', + 'username', + 'host', + 'avatarUrl', + 'avatarBlurhash', + 'onlineStatus', + ], +} as const satisfies JSONSchema7Definition; 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: { + $id: 'https://misskey-hub.net/api/schemas/UserDetailedNotMeOnly', + + oneOf: [{ + $ref: '#/$defs/base', + }, { + allOf: [{ $ref: '#/$defs/base', }, { $ref: '#/$defs/relations' }], + }], + $defs: { + base: { + type: 'object', + properties: { + url: { + oneOf: [{ type: 'string', - nullable: false, optional: false, - }, - value: { + format: 'url', + }, { + type: 'null', + }], + }, + uri: { + oneOf: [{ type: 'string', - nullable: false, optional: false, + format: 'uri', + }, { + type: 'null', + }], + }, + movedToUri: { + oneOf: [{ + type: 'string', + format: 'uri', + }, { + type: 'null', + }], + }, + alsoKnownAs: { + oneOf: [{ + type: 'array', + items: { $ref: 'https://misskey-hub.net/api/schemas/Id' }, + }, { + type: 'null', + }], + }, + createdAt: { + type: 'string', + format: 'date-time', + }, + updatedAt: { + oneOf: [{ + type: 'string', + format: 'date-time', + }, { + type: 'null', + }], + }, + lastFetchedAt: { + oneOf: [{ + type: 'string', + format: 'date-time', + }, { + type: 'null', + }], + }, + bannerUrl: { + oneOf: [{ + type: 'string', + format: 'url', + }, { + type: 'null', + }], + }, + bannerBlurhash: { + type: ['string', 'null'], + }, + isLocked: { + type: 'boolean', + }, + isSilenced: { + type: 'boolean', + }, + isSuspended: { + type: 'boolean', + examples: false, + }, + description: { + type: ['string', 'null'], + examples: 'Hi masters, I am Ai!', + }, + location: { + type: ['string', 'null'], + }, + birthday: { + type: ['string', 'null'], + examples: '2018-03-12', + }, + lang: { + type: ['string', 'null'], + examples: 'ja-JP', + }, + fields: { + type: 'array', + maxLength: 4, + items: { + type: 'object', + properties: { + name: { + type: 'string', + }, + value: { + type: 'string', + }, + }, + required: ['name', 'value'], }, }, - maxLength: 4, + followersCount: { + type: 'number', + }, + followingCount: { + type: 'number', + }, + notesCount: { + type: 'number', + }, + pinnedNoteIds: { + type: 'array', + items: { $ref: 'https://misskey-hub.net/api/schemas/Id' }, + }, + pinnedNotes: { + type: 'array', + items: { $ref: 'https://misskey-hub.net/api/schemas/Note' }, + }, + pinnedPageId: { + type: ['string', 'null'], + }, + pinnedPage: { + oneOf: [{ + $ref: 'https://misskey-hub.net/api/schemas/Page', + }, { + type: 'null', + }], + }, + publicReactions: { + type: 'boolean', + }, + twoFactorEnabled: { + type: 'boolean', + default: false, + }, + usePasswordLessLogin: { + type: 'boolean', + default: false, + }, + securityKeys: { + type: 'boolean', + default: false, + }, }, + required: [ + 'url', + 'uri', + 'movedToUri', + 'alsoKnownAs', + 'createdAt', + 'updatedAt', + 'lastFetchedAt', + 'bannerUrl', + 'bannerBlurhash', + 'isLocked', + 'isSilenced', + 'isSuspended', + 'description', + 'location', + 'birthday', + 'lang', + 'fields', + 'followersCount', + 'followingCount', + 'notesCount', + 'pinnedNoteIds', + 'pinnedNotes', + 'pinnedPageId', + 'pinnedPage', + 'publicReactions', + 'twoFactorEnabled', + 'usePasswordLessLogin', + 'securityKeys', + ], }, - 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: { + relations: { type: 'object', - nullable: true, optional: false, - ref: 'Page', + properties: { + isFollowing: { + type: 'boolean', + }, + isFollowed: { + type: 'boolean', + }, + hasPendingFollowRequestFromYou: { + type: 'boolean', + }, + hasPendingFollowRequestToYou: { + type: 'boolean', + }, + isBlocking: { + type: 'boolean', + }, + isBlocked: { + type: 'boolean', + }, + isMuted: { + type: 'boolean', + }, + isRenoteMuted: { + type: 'boolean', + }, + memo: { + type: 'string', + }, + }, + required: [ + 'isFollowing', + 'isFollowed', + 'hasPendingFollowRequestFromYou', + 'hasPendingFollowRequestToYou', + 'isBlocking', + 'isBlocked', + 'isMuted', + 'isRenoteMuted', + 'memo', + ], }, - 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; +} as const satisfies JSONSchema7Definition; export const packedMeDetailedOnlySchema = { type: 'object',