mizzkey/packages/misskey-js/src/schemas/user.ts

498 lines
9.8 KiB
TypeScript
Raw Normal View History

2023-05-10 18:55:36 +02:00
import type { JSONSchema7, JSONSchema7Definition } from 'schema-type';
2023-05-10 18:22:21 +02:00
2023-05-02 14:05:17 +02:00
export const packedUserLiteSchema = {
2023-05-10 18:22:21 +02:00
$id: 'https://misskey-hub.net/api/schemas/UserLite',
2023-05-02 14:05:17 +02:00
type: 'object',
properties: {
2023-05-10 18:22:21 +02:00
id: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
2023-05-02 14:05:17 +02:00
name: {
2023-05-10 18:22:21 +02:00
type: ['string', 'null'],
examples: '藍',
2023-05-02 14:05:17 +02:00
},
username: {
type: 'string',
2023-05-10 18:22:21 +02:00
examples: 'ai',
2023-05-02 14:05:17 +02:00
},
host: {
2023-05-10 18:22:21 +02:00
type: ['string', 'null'],
examples: 'misskey.example.com',
2023-05-02 14:05:17 +02:00
description: 'The local host is represented with `null`.',
},
avatarUrl: {
2023-05-10 18:22:21 +02:00
oneOf: [{
type: 'string',
format: 'url',
}, {
type: 'null',
}],
2023-05-02 14:05:17 +02:00
},
avatarBlurhash: {
2023-05-10 18:22:21 +02:00
type: ['string', 'null'],
2023-05-02 14:05:17 +02:00
},
isAdmin: {
type: 'boolean',
default: false,
},
isModerator: {
type: 'boolean',
default: false,
},
isBot: {
type: 'boolean',
},
isCat: {
type: 'boolean',
},
onlineStatus: {
2023-05-10 18:22:21 +02:00
type: ['string', 'null'],
enum: ['unknown', 'online', 'active', 'offline', null],
2023-05-02 14:05:17 +02:00
},
},
2023-05-10 18:22:21 +02:00
required: [
'id',
'name',
'username',
'host',
'avatarUrl',
'avatarBlurhash',
'onlineStatus',
],
} as const satisfies JSONSchema7Definition;
2023-05-02 14:05:17 +02:00
export const packedUserDetailedNotMeOnlySchema = {
2023-05-10 18:22:21 +02:00
$id: 'https://misskey-hub.net/api/schemas/UserDetailedNotMeOnly',
2023-05-10 18:55:36 +02:00
type: 'object',
2023-05-10 18:22:21 +02:00
oneOf: [{
$ref: '#/$defs/base',
}, {
allOf: [{ $ref: '#/$defs/base', }, { $ref: '#/$defs/relations' }],
}],
$defs: {
base: {
type: 'object',
properties: {
url: {
oneOf: [{
2023-05-02 14:05:17 +02:00
type: 'string',
2023-05-10 18:22:21 +02:00
format: 'url',
}, {
type: 'null',
}],
},
uri: {
oneOf: [{
2023-05-02 14:05:17 +02:00
type: 'string',
2023-05-10 18:22:21 +02:00
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'],
2023-05-02 14:05:17 +02:00
},
},
2023-05-10 18:22:21 +02:00
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,
},
2023-05-02 14:05:17 +02:00
},
2023-05-10 18:22:21 +02:00
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',
],
},
relations: {
2023-05-02 14:05:17 +02:00
type: 'object',
2023-05-10 18:22:21 +02:00
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',
],
2023-05-02 14:05:17 +02:00
},
},
2023-05-10 18:22:21 +02:00
} as const satisfies JSONSchema7Definition;
2023-05-02 14:05:17 +02:00
export const packedMeDetailedOnlySchema = {
2023-05-10 18:55:36 +02:00
$id: 'https://misskey-hub.net/api/schemas/MeDetailedOnly',
2023-05-02 14:05:17 +02:00
type: 'object',
2023-05-10 18:55:36 +02:00
oneOf: [{
$ref: '#/$defs/base',
}, {
allOf: [{ $ref: '#/$defs/base' }, { $ref: '#/$defs/secrets' }],
}],
$defs: {
base: {
type: 'object',
properties: {
avatarId: {
oneOf: [{
$ref: 'https://misskey-hub.net/api/schemas/Id',
}, {
type: 'null',
}],
},
bannerId: {
oneOf: [{
$ref: 'https://misskey-hub.net/api/schemas/Id',
}, {
type: 'null',
}],
},
injectFeaturedNote: {
type: ['boolean', 'null'],
},
receiveAnnouncementEmail: {
type: ['boolean', 'null'],
},
alwaysMarkNsfw: {
type: ['boolean', 'null'],
},
autoSensitive: {
type: ['boolean', 'null'],
},
carefulBot: {
type: ['boolean', 'null'],
},
autoAcceptFollowed: {
type: ['boolean', 'null'],
},
noCrawle: {
type: ['boolean', 'null'],
},
preventAiLarning: {
type: 'boolean',
},
isExplorable: {
type: 'boolean',
},
isDeleted: {
type: 'boolean',
},
hideOnlineStatus: {
type: 'boolean',
},
hasUnreadSpecifiedNotes: {
type: 'boolean',
},
hasUnreadMentions: {
type: 'boolean',
},
hasUnreadAnnouncement: {
type: 'boolean',
},
hasUnreadAntenna: {
type: 'boolean',
},
hasUnreadNotification: {
type: 'boolean',
},
hasPendingReceivedFollowRequest: {
type: 'boolean',
},
mutedWords: {
type: 'array',
items: {
type: 'array',
items: {
type: 'string',
},
},
},
mutedInstances: {
oneOf: [{
type: 'array',
items: {
type: 'string',
},
}, {
type: 'null',
}],
},
mutingNotificationTypes: {
oneOf: [{
type: 'array',
items: {
type: 'string',
},
}, {
type: 'null',
}],
},
emailNotificationTypes: {
oneOf: [{
type: 'array',
items: {
type: 'string',
},
}, {
type: 'null',
}],
2023-05-02 14:05:17 +02:00
},
},
},
2023-05-10 18:55:36 +02:00
secrets: {
type: 'object',
properties: {
email: {
type: ['string', 'null'],
},
emailVerified: {
type: ['boolean', 'null'],
},
securityKeysList: {
type: 'array',
items: {
type: 'object',
additionalProperties: true,
},
},
2023-05-02 14:05:17 +02:00
},
2023-05-10 18:55:36 +02:00
required: [
'email',
'emailVerified',
'securityKeysList',
],
2023-05-02 14:05:17 +02:00
},
},
2023-05-10 18:55:36 +02:00
} as const satisfies JSONSchema7Definition;
2023-05-02 14:05:17 +02:00
export const packedUserDetailedNotMeSchema = {
2023-05-10 18:55:36 +02:00
$id: 'https://misskey-hub.net/api/schemas/UserDetailedNotMe',
2023-05-02 14:05:17 +02:00
type: 'object',
2023-05-10 18:55:36 +02:00
allOf: [{
$ref: 'https://misskey-hub.net/api/schemas/UserLite',
}, {
$ref: 'https://misskey-hub.net/api/schemas/UserDetailedNotMeOnly',
}],
} as const satisfies JSONSchema7Definition;
2023-05-02 14:05:17 +02:00
export const packedMeDetailedSchema = {
2023-05-10 18:55:36 +02:00
$id: 'https://misskey-hub.net/api/schemas/MeDetailed',
2023-05-02 14:05:17 +02:00
type: 'object',
2023-05-10 18:55:36 +02:00
allOf: [{
$ref: 'https://misskey-hub.net/api/schemas/UserLite',
}, {
$ref: 'https://misskey-hub.net/api/schemas/UserDetailedNotMeOnly',
}, {
$ref: 'https://misskey-hub.net/api/schemas/MeDetailedOnly',
}],
} as const satisfies JSONSchema7Definition;
2023-05-02 14:05:17 +02:00
export const packedUserDetailedSchema = {
2023-05-10 18:55:36 +02:00
$id: 'https://misskey-hub.net/api/schemas/UserDetailed',
type: 'object',
oneOf: [{
$ref: 'https://misskey-hub.net/api/schemas/UserDetailedNotMe',
}, {
$ref: 'https://misskey-hub.net/api/schemas/MeDetailed',
}],
} as const satisfies JSONSchema7Definition;
2023-05-02 14:05:17 +02:00
2023-05-12 09:54:50 +02:00
// NOTE: 極力この型を使うのは避け、UserLite か UserDetailed か明示するように
2023-05-02 14:05:17 +02:00
export const packedUserSchema = {
2023-05-10 18:55:36 +02:00
$id: 'https://misskey-hub.net/api/schemas/User',
type: 'object',
oneOf: [{
$ref: 'https://misskey-hub.net/api/schemas/UserLite',
}, {
$ref: 'https://misskey-hub.net/api/schemas/UserDetailed',
}],
} as const satisfies JSONSchema7Definition;
2023-05-02 14:05:17 +02:00
2023-05-10 18:55:36 +02:00
export const localUsernameSchema = { type: 'string', pattern: /^\w{1,20}$/.toString().slice(1, -1) } as const satisfies JSONSchema7;
export const passwordSchema = { type: 'string', minLength: 1 } as const satisfies JSONSchema7;
export const nameSchema = { type: 'string', minLength: 1, maxLength: 50 } as const satisfies JSONSchema7;
export const descriptionSchema = { type: 'string', minLength: 1, maxLength: 1500 } as const satisfies JSONSchema7;
export const locationSchema = { type: 'string', minLength: 1, maxLength: 50 } as const satisfies JSONSchema7;
export const birthdaySchema = { type: 'string', pattern: /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.toString().slice(1, -1) } as const satisfies JSONSchema7;