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

158 lines
4.8 KiB
TypeScript
Raw Normal View History

2023-05-10 17:50:15 +02:00
import type { JSONSchema7Definition } from 'schema-type';
2023-05-10 21:18:48 +02:00
import { ACHIEVEMENT_TYPES, notificationTypes } from '../consts';
2023-05-02 14:05:17 +02:00
2023-05-29 19:03:20 +02:00
export const notificationTypeSchema = {
$id: 'https://misskey-hub.net/api/schemas/NotificationTypes',
enum: [...notificationTypes],
} as const satisfies JSONSchema7Definition;
2023-05-02 14:05:17 +02:00
export const packedNotificationSchema = {
2023-05-10 17:50:15 +02:00
$id: 'https://misskey-hub.net/api/schemas/Notification',
2023-05-02 14:05:17 +02:00
type: 'object',
2023-05-10 21:18:48 +02:00
properties: {
id: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
createdAt: {
type: 'string',
format: 'date-time',
},
2023-05-29 19:03:20 +02:00
type: { $ref: 'https://misskey-hub.net/api/schemas/NotificationType' },
2023-05-10 21:18:48 +02:00
userId: {
oneOf: [
{ $ref: 'https://misskey-hub.net/api/schemas/Id' },
{ type: 'null' },
]
},
user: { $ref: 'https://misskey-hub.net/api/schemas/UserLite' },
note: { $ref: 'https://misskey-hub.net/api/schemas/Note' },
reaction: { type: ['string', 'null'] },
achievement: {
oneOf: [
{ enum: [...ACHIEVEMENT_TYPES] },
{ type: 'null' },
],
},
header: { type: ['string', 'null'] },
body: { type: ['string', 'null'] },
icon: { type: ['string', 'null'] },
},
required: ['id', 'createdAt'],
} as const satisfies JSONSchema7Definition;
export const packedNotificationStrictSchema = {
2023-05-21 18:35:48 +02:00
$id: 'https://misskey-hub.net/api/schemas/NotificationStrict',
2023-05-10 21:18:48 +02:00
type: 'object',
allOf: [
2023-05-10 17:50:15 +02:00
{
2023-05-02 14:05:17 +02:00
type: 'object',
2023-05-10 17:50:15 +02:00
properties: {
2023-05-10 21:18:48 +02:00
id: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
createdAt: {
type: 'string',
format: 'date-time',
},
2023-05-10 17:50:15 +02:00
},
2023-05-10 21:18:48 +02:00
required: ['id', 'createdAt'],
},
{
2023-05-10 17:50:15 +02:00
type: 'object',
2023-05-10 21:18:48 +02:00
oneOf: [{
type: 'object',
properties: {
type: { const: 'follow' },
userId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
user: { $ref: 'https://misskey-hub.net/api/schemas/UserLite' },
},
required: ['type', 'userId', 'user'],
}, {
type: 'object',
properties: {
type: { const: 'mention' },
userId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
user: { $ref: 'https://misskey-hub.net/api/schemas/UserLite' },
note: { $ref: 'https://misskey-hub.net/api/schemas/Note' },
},
required: ['type', 'userId', 'user', 'note'],
}, {
type: 'object',
properties: {
type: { const: 'reply' },
userId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
user: { $ref: 'https://misskey-hub.net/api/schemas/UserLite' },
note: { $ref: 'https://misskey-hub.net/api/schemas/Note' },
},
required: ['type', 'userId', 'user', 'note'],
}, {
type: 'object',
properties: {
type: { const: 'renote' },
userId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
user: { $ref: 'https://misskey-hub.net/api/schemas/UserLite' },
note: { $ref: 'https://misskey-hub.net/api/schemas/Note' },
},
required: ['type', 'userId', 'user', 'note'],
}, {
type: 'object',
properties: {
type: { const: 'quote' },
userId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
user: { $ref: 'https://misskey-hub.net/api/schemas/UserLite' },
note: { $ref: 'https://misskey-hub.net/api/schemas/Note' },
},
required: ['type', 'userId', 'user', 'note'],
}, {
type: 'object',
properties: {
type: { const: 'reaction' },
reaction: { type: 'string' },
userId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
user: { $ref: 'https://misskey-hub.net/api/schemas/UserLite' },
note: { $ref: 'https://misskey-hub.net/api/schemas/Note' },
},
required: ['type', 'reaction', 'userId', 'user', 'note'],
}, {
type: 'object',
properties: {
type: { const: 'pollEnded' },
userId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
user: { $ref: 'https://misskey-hub.net/api/schemas/UserLite' },
note: { $ref: 'https://misskey-hub.net/api/schemas/Note' },
},
required: ['type', 'userId', 'user', 'note'],
}, {
type: 'object',
properties: {
type: { const: 'receiveFollowRequest' },
userId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
user: { $ref: 'https://misskey-hub.net/api/schemas/UserLite' },
},
required: ['type', 'userId', 'user'],
}, {
type: 'object',
properties: {
type: { const: 'followRequestAccepted' },
userId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
user: { $ref: 'https://misskey-hub.net/api/schemas/UserLite' },
},
required: ['type', 'userId', 'user'],
}, {
type: 'object',
properties: {
type: { const: 'achievementEarned' },
achievement: { enum: [...ACHIEVEMENT_TYPES] },
},
required: ['type', 'achievement'],
}, {
type: 'object',
properties: {
type: { const: 'app' },
header: { type: ['string', 'null'] },
body: { type: 'string' },
icon: { type: ['string', 'null'] },
},
required: ['type'],
}],
},
],
2023-05-10 17:50:15 +02:00
} as const satisfies JSONSchema7Definition;