2023-07-27 07:31:52 +02:00
|
|
|
|
/*
|
2024-02-13 16:59:27 +01:00
|
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
|
import {
|
|
|
|
|
packedUserLiteSchema,
|
|
|
|
|
packedUserDetailedNotMeOnlySchema,
|
|
|
|
|
packedMeDetailedOnlySchema,
|
|
|
|
|
packedUserDetailedNotMeSchema,
|
|
|
|
|
packedMeDetailedSchema,
|
|
|
|
|
packedUserDetailedSchema,
|
|
|
|
|
packedUserSchema,
|
2023-03-10 06:22:37 +01:00
|
|
|
|
} from '@/models/json-schema/user.js';
|
|
|
|
|
import { packedNoteSchema } from '@/models/json-schema/note.js';
|
|
|
|
|
import { packedUserListSchema } from '@/models/json-schema/user-list.js';
|
|
|
|
|
import { packedAppSchema } from '@/models/json-schema/app.js';
|
|
|
|
|
import { packedNotificationSchema } from '@/models/json-schema/notification.js';
|
|
|
|
|
import { packedDriveFileSchema } from '@/models/json-schema/drive-file.js';
|
|
|
|
|
import { packedDriveFolderSchema } from '@/models/json-schema/drive-folder.js';
|
|
|
|
|
import { packedFollowingSchema } from '@/models/json-schema/following.js';
|
|
|
|
|
import { packedMutingSchema } from '@/models/json-schema/muting.js';
|
|
|
|
|
import { packedRenoteMutingSchema } from '@/models/json-schema/renote-muting.js';
|
|
|
|
|
import { packedBlockingSchema } from '@/models/json-schema/blocking.js';
|
|
|
|
|
import { packedNoteReactionSchema } from '@/models/json-schema/note-reaction.js';
|
|
|
|
|
import { packedHashtagSchema } from '@/models/json-schema/hashtag.js';
|
2023-07-15 02:57:58 +02:00
|
|
|
|
import { packedInviteCodeSchema } from '@/models/json-schema/invite-code.js';
|
2024-01-30 11:53:53 +01:00
|
|
|
|
import { packedPageSchema, packedPageBlockSchema } from '@/models/json-schema/page.js';
|
2023-03-10 06:22:37 +01:00
|
|
|
|
import { packedNoteFavoriteSchema } from '@/models/json-schema/note-favorite.js';
|
|
|
|
|
import { packedChannelSchema } from '@/models/json-schema/channel.js';
|
|
|
|
|
import { packedAntennaSchema } from '@/models/json-schema/antenna.js';
|
|
|
|
|
import { packedClipSchema } from '@/models/json-schema/clip.js';
|
|
|
|
|
import { packedFederationInstanceSchema } from '@/models/json-schema/federation-instance.js';
|
|
|
|
|
import { packedQueueCountSchema } from '@/models/json-schema/queue.js';
|
|
|
|
|
import { packedGalleryPostSchema } from '@/models/json-schema/gallery-post.js';
|
|
|
|
|
import { packedEmojiDetailedSchema, packedEmojiSimpleSchema } from '@/models/json-schema/emoji.js';
|
|
|
|
|
import { packedFlashSchema } from '@/models/json-schema/flash.js';
|
2023-08-13 13:12:29 +02:00
|
|
|
|
import { packedAnnouncementSchema } from '@/models/json-schema/announcement.js';
|
2023-12-03 04:45:18 +01:00
|
|
|
|
import { packedSigninSchema } from '@/models/json-schema/signin.js';
|
2024-02-16 06:27:33 +01:00
|
|
|
|
import {
|
|
|
|
|
packedRoleLiteSchema,
|
|
|
|
|
packedRoleSchema,
|
|
|
|
|
packedRolePoliciesSchema,
|
|
|
|
|
packedRoleCondFormulaLogicsSchema,
|
|
|
|
|
packedRoleCondFormulaValueNot,
|
|
|
|
|
packedRoleCondFormulaValueIsLocalOrRemoteSchema,
|
|
|
|
|
packedRoleCondFormulaValueCreatedSchema,
|
|
|
|
|
packedRoleCondFormulaFollowersOrFollowingOrNotesSchema,
|
|
|
|
|
packedRoleCondFormulaValueSchema,
|
|
|
|
|
} from '@/models/json-schema/role.js';
|
2023-12-21 08:57:05 +01:00
|
|
|
|
import { packedAdSchema } from '@/models/json-schema/ad.js';
|
2024-01-19 12:51:49 +01:00
|
|
|
|
import { packedReversiGameLiteSchema, packedReversiGameDetailedSchema } from '@/models/json-schema/reversi-game.js';
|
2024-02-23 02:47:17 +01:00
|
|
|
|
import {
|
|
|
|
|
packedMetaLiteSchema,
|
|
|
|
|
packedMetaDetailedOnlySchema,
|
|
|
|
|
packedMetaDetailedSchema,
|
|
|
|
|
} from '@/models/json-schema/meta.js';
|
2021-09-11 18:12:23 +02:00
|
|
|
|
|
|
|
|
|
export const refs = {
|
2022-01-18 14:27:10 +01:00
|
|
|
|
UserLite: packedUserLiteSchema,
|
|
|
|
|
UserDetailedNotMeOnly: packedUserDetailedNotMeOnlySchema,
|
|
|
|
|
MeDetailedOnly: packedMeDetailedOnlySchema,
|
|
|
|
|
UserDetailedNotMe: packedUserDetailedNotMeSchema,
|
|
|
|
|
MeDetailed: packedMeDetailedSchema,
|
|
|
|
|
UserDetailed: packedUserDetailedSchema,
|
2021-09-11 18:12:23 +02:00
|
|
|
|
User: packedUserSchema,
|
2022-01-18 14:27:10 +01:00
|
|
|
|
|
2021-09-11 18:12:23 +02:00
|
|
|
|
UserList: packedUserListSchema,
|
2023-12-21 08:57:05 +01:00
|
|
|
|
Ad: packedAdSchema,
|
2023-08-13 13:12:29 +02:00
|
|
|
|
Announcement: packedAnnouncementSchema,
|
2021-09-11 18:12:23 +02:00
|
|
|
|
App: packedAppSchema,
|
|
|
|
|
Note: packedNoteSchema,
|
|
|
|
|
NoteReaction: packedNoteReactionSchema,
|
|
|
|
|
NoteFavorite: packedNoteFavoriteSchema,
|
|
|
|
|
Notification: packedNotificationSchema,
|
|
|
|
|
DriveFile: packedDriveFileSchema,
|
|
|
|
|
DriveFolder: packedDriveFolderSchema,
|
|
|
|
|
Following: packedFollowingSchema,
|
|
|
|
|
Muting: packedMutingSchema,
|
2023-03-08 00:56:09 +01:00
|
|
|
|
RenoteMuting: packedRenoteMutingSchema,
|
2021-09-11 18:12:23 +02:00
|
|
|
|
Blocking: packedBlockingSchema,
|
|
|
|
|
Hashtag: packedHashtagSchema,
|
2023-07-15 02:57:58 +02:00
|
|
|
|
InviteCode: packedInviteCodeSchema,
|
2021-09-11 18:12:23 +02:00
|
|
|
|
Page: packedPageSchema,
|
2024-01-30 11:53:53 +01:00
|
|
|
|
PageBlock: packedPageBlockSchema,
|
2021-09-11 18:12:23 +02:00
|
|
|
|
Channel: packedChannelSchema,
|
|
|
|
|
QueueCount: packedQueueCountSchema,
|
|
|
|
|
Antenna: packedAntennaSchema,
|
|
|
|
|
Clip: packedClipSchema,
|
|
|
|
|
FederationInstance: packedFederationInstanceSchema,
|
|
|
|
|
GalleryPost: packedGalleryPostSchema,
|
2023-02-17 07:36:36 +01:00
|
|
|
|
EmojiSimple: packedEmojiSimpleSchema,
|
|
|
|
|
EmojiDetailed: packedEmojiDetailedSchema,
|
2023-02-17 07:06:52 +01:00
|
|
|
|
Flash: packedFlashSchema,
|
2023-12-03 04:45:18 +01:00
|
|
|
|
Signin: packedSigninSchema,
|
2024-02-16 06:27:33 +01:00
|
|
|
|
RoleCondFormulaLogics: packedRoleCondFormulaLogicsSchema,
|
|
|
|
|
RoleCondFormulaValueNot: packedRoleCondFormulaValueNot,
|
|
|
|
|
RoleCondFormulaValueIsLocalOrRemote: packedRoleCondFormulaValueIsLocalOrRemoteSchema,
|
|
|
|
|
RoleCondFormulaValueCreated: packedRoleCondFormulaValueCreatedSchema,
|
|
|
|
|
RoleCondFormulaFollowersOrFollowingOrNotes: packedRoleCondFormulaFollowersOrFollowingOrNotesSchema,
|
|
|
|
|
RoleCondFormulaValue: packedRoleCondFormulaValueSchema,
|
2023-12-06 07:47:57 +01:00
|
|
|
|
RoleLite: packedRoleLiteSchema,
|
|
|
|
|
Role: packedRoleSchema,
|
2024-01-30 11:53:53 +01:00
|
|
|
|
RolePolicies: packedRolePoliciesSchema,
|
2024-01-19 12:51:49 +01:00
|
|
|
|
ReversiGameLite: packedReversiGameLiteSchema,
|
|
|
|
|
ReversiGameDetailed: packedReversiGameDetailedSchema,
|
2024-02-23 02:47:17 +01:00
|
|
|
|
MetaLite: packedMetaLiteSchema,
|
|
|
|
|
MetaDetailedOnly: packedMetaDetailedOnlySchema,
|
|
|
|
|
MetaDetailed: packedMetaDetailedSchema,
|
2021-09-11 18:12:23 +02:00
|
|
|
|
};
|
|
|
|
|
|
2022-02-19 15:21:28 +01:00
|
|
|
|
export type Packed<x extends keyof typeof refs> = SchemaType<typeof refs[x]>;
|
2022-01-18 14:27:10 +01:00
|
|
|
|
|
2024-01-30 11:53:53 +01:00
|
|
|
|
export type KeyOf<x extends keyof typeof refs> = PropertiesToUnion<typeof refs[x]>;
|
|
|
|
|
type PropertiesToUnion<p extends Schema> = p['properties'] extends NonNullable<Obj> ? keyof p['properties'] : never;
|
|
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
|
type TypeStringef = 'null' | 'boolean' | 'integer' | 'number' | 'string' | 'array' | 'object' | 'any';
|
2022-01-18 14:27:10 +01:00
|
|
|
|
type StringDefToType<T extends TypeStringef> =
|
2022-02-19 06:05:32 +01:00
|
|
|
|
T extends 'null' ? null :
|
2022-01-18 14:27:10 +01:00
|
|
|
|
T extends 'boolean' ? boolean :
|
2022-02-19 06:05:32 +01:00
|
|
|
|
T extends 'integer' ? number :
|
2022-01-18 14:27:10 +01:00
|
|
|
|
T extends 'number' ? number :
|
|
|
|
|
T extends 'string' ? string | Date :
|
|
|
|
|
T extends 'array' ? ReadonlyArray<any> :
|
|
|
|
|
T extends 'object' ? Record<string, any> :
|
|
|
|
|
any;
|
|
|
|
|
|
|
|
|
|
// https://swagger.io/specification/?sbsearch=optional#schema-object
|
|
|
|
|
type OfSchema = {
|
2022-02-19 06:05:32 +01:00
|
|
|
|
readonly anyOf?: ReadonlyArray<Schema>;
|
|
|
|
|
readonly oneOf?: ReadonlyArray<Schema>;
|
|
|
|
|
readonly allOf?: ReadonlyArray<Schema>;
|
2022-01-18 14:27:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
|
export interface Schema extends OfSchema {
|
2022-01-18 14:27:10 +01:00
|
|
|
|
readonly type?: TypeStringef;
|
|
|
|
|
readonly nullable?: boolean;
|
|
|
|
|
readonly optional?: boolean;
|
2022-02-19 06:05:32 +01:00
|
|
|
|
readonly items?: Schema;
|
2022-01-18 14:27:10 +01:00
|
|
|
|
readonly properties?: Obj;
|
2022-04-24 04:43:15 +02:00
|
|
|
|
readonly required?: ReadonlyArray<Extract<keyof NonNullable<this['properties']>, string>>;
|
2022-01-18 14:27:10 +01:00
|
|
|
|
readonly description?: string;
|
|
|
|
|
readonly example?: any;
|
|
|
|
|
readonly format?: string;
|
|
|
|
|
readonly ref?: keyof typeof refs;
|
2024-02-02 04:47:07 +01:00
|
|
|
|
readonly selfRef?: boolean;
|
2023-03-08 00:56:47 +01:00
|
|
|
|
readonly enum?: ReadonlyArray<string | null>;
|
2022-01-18 14:27:10 +01:00
|
|
|
|
readonly default?: (this['type'] extends TypeStringef ? StringDefToType<this['type']> : any) | null;
|
|
|
|
|
readonly maxLength?: number;
|
|
|
|
|
readonly minLength?: number;
|
2022-04-27 03:49:00 +02:00
|
|
|
|
readonly maximum?: number;
|
|
|
|
|
readonly minimum?: number;
|
|
|
|
|
readonly pattern?: string;
|
2022-01-18 14:27:10 +01:00
|
|
|
|
}
|
2021-09-22 15:35:55 +02:00
|
|
|
|
|
2022-02-19 15:21:28 +01:00
|
|
|
|
type RequiredPropertyNames<s extends Obj> = {
|
|
|
|
|
[K in keyof s]:
|
|
|
|
|
// K is not optional
|
|
|
|
|
s[K]['optional'] extends false ? K :
|
|
|
|
|
// K has default value
|
2022-04-27 03:49:00 +02:00
|
|
|
|
s[K]['default'] extends null | string | number | boolean | Record<string, unknown> ? K :
|
|
|
|
|
never
|
2022-02-19 15:21:28 +01:00
|
|
|
|
}[keyof s];
|
2019-04-23 15:35:26 +02:00
|
|
|
|
|
2022-04-27 03:49:00 +02:00
|
|
|
|
export type Obj = Record<string, Schema>;
|
2019-02-24 01:45:27 +01:00
|
|
|
|
|
2022-04-27 03:49:00 +02:00
|
|
|
|
// https://github.com/misskey-dev/misskey/issues/8535
|
|
|
|
|
// To avoid excessive stack depth error,
|
|
|
|
|
// deceive TypeScript with UnionToIntersection (or more precisely, `infer` expression within it).
|
2023-02-26 03:28:05 +01:00
|
|
|
|
export type ObjType<s extends Obj, RequiredProps extends ReadonlyArray<keyof s>> =
|
2022-04-27 03:49:00 +02:00
|
|
|
|
UnionToIntersection<
|
|
|
|
|
{ -readonly [R in RequiredPropertyNames<s>]-?: SchemaType<s[R]> } &
|
2023-02-26 03:28:05 +01:00
|
|
|
|
{ -readonly [R in RequiredProps[number]]-?: SchemaType<s[R]> } &
|
2022-04-27 03:49:00 +02:00
|
|
|
|
{ -readonly [P in keyof s]?: SchemaType<s[P]> }
|
|
|
|
|
>;
|
2019-02-24 01:45:27 +01:00
|
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
|
type NullOrUndefined<p extends Schema, T> =
|
2022-04-27 03:49:00 +02:00
|
|
|
|
| (p['nullable'] extends true ? null : never)
|
|
|
|
|
| (p['optional'] extends true ? undefined : never)
|
|
|
|
|
| T;
|
2019-04-23 15:35:26 +02:00
|
|
|
|
|
2022-02-19 15:21:28 +01:00
|
|
|
|
// https://stackoverflow.com/questions/54938141/typescript-convert-union-to-intersection
|
2023-07-08 00:08:16 +02:00
|
|
|
|
// Get intersection from union
|
2022-01-18 14:27:10 +01:00
|
|
|
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
2023-02-01 12:04:01 +01:00
|
|
|
|
type PartialIntersection<T> = Partial<UnionToIntersection<T>>;
|
2022-01-18 14:27:10 +01:00
|
|
|
|
|
|
|
|
|
// https://github.com/misskey-dev/misskey/pull/8144#discussion_r785287552
|
2022-02-19 15:21:28 +01:00
|
|
|
|
// To get union, we use `Foo extends any ? Hoge<Foo> : never`
|
2022-02-19 06:05:32 +01:00
|
|
|
|
type UnionSchemaType<a extends readonly any[], X extends Schema = a[number]> = X extends any ? SchemaType<X> : never;
|
2023-02-26 03:28:05 +01:00
|
|
|
|
//type UnionObjectSchemaType<a extends readonly any[], X extends Schema = a[number]> = X extends any ? ObjectSchemaType<X> : never;
|
|
|
|
|
type UnionObjType<s extends Obj, a extends readonly any[], X extends ReadonlyArray<keyof s> = a[number]> = X extends any ? ObjType<s, X> : never;
|
2023-02-01 12:04:01 +01:00
|
|
|
|
type ArrayUnion<T> = T extends any ? Array<T> : never;
|
|
|
|
|
|
|
|
|
|
type ObjectSchemaTypeDef<p extends Schema> =
|
|
|
|
|
p['ref'] extends keyof typeof refs ? Packed<p['ref']> :
|
|
|
|
|
p['properties'] extends NonNullable<Obj> ?
|
2023-02-26 03:28:05 +01:00
|
|
|
|
p['anyOf'] extends ReadonlyArray<Schema> ? p['anyOf'][number]['required'] extends ReadonlyArray<keyof p['properties']> ?
|
|
|
|
|
UnionObjType<p['properties'], NonNullable<p['anyOf'][number]['required']>> & ObjType<p['properties'], NonNullable<p['required']>>
|
|
|
|
|
: never
|
|
|
|
|
: ObjType<p['properties'], NonNullable<p['required']>>
|
2023-02-01 12:04:01 +01:00
|
|
|
|
:
|
2023-02-26 03:28:05 +01:00
|
|
|
|
p['anyOf'] extends ReadonlyArray<Schema> ? never : // see CONTRIBUTING.md
|
2023-02-01 12:04:01 +01:00
|
|
|
|
p['allOf'] extends ReadonlyArray<Schema> ? UnionToIntersection<UnionSchemaType<p['allOf']>> :
|
|
|
|
|
any
|
|
|
|
|
|
|
|
|
|
type ObjectSchemaType<p extends Schema> = NullOrUndefined<p, ObjectSchemaTypeDef<p>>;
|
2022-01-18 14:27:10 +01:00
|
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
|
export type SchemaTypeDef<p extends Schema> =
|
|
|
|
|
p['type'] extends 'null' ? null :
|
|
|
|
|
p['type'] extends 'integer' ? number :
|
2022-01-18 14:27:10 +01:00
|
|
|
|
p['type'] extends 'number' ? number :
|
|
|
|
|
p['type'] extends 'string' ? (
|
2023-03-08 00:56:47 +01:00
|
|
|
|
p['enum'] extends readonly (string | null)[] ?
|
2022-04-27 03:49:00 +02:00
|
|
|
|
p['enum'][number] :
|
|
|
|
|
p['format'] extends 'date-time' ? string : // Dateにする??
|
|
|
|
|
string
|
2022-01-18 14:27:10 +01:00
|
|
|
|
) :
|
|
|
|
|
p['type'] extends 'boolean' ? boolean :
|
2023-02-01 12:04:01 +01:00
|
|
|
|
p['type'] extends 'object' ? ObjectSchemaTypeDef<p> :
|
2022-01-18 14:27:10 +01:00
|
|
|
|
p['type'] extends 'array' ? (
|
|
|
|
|
p['items'] extends OfSchema ? (
|
2022-02-19 06:05:32 +01:00
|
|
|
|
p['items']['anyOf'] extends ReadonlyArray<Schema> ? UnionSchemaType<NonNullable<p['items']['anyOf']>>[] :
|
|
|
|
|
p['items']['oneOf'] extends ReadonlyArray<Schema> ? ArrayUnion<UnionSchemaType<NonNullable<p['items']['oneOf']>>> :
|
|
|
|
|
p['items']['allOf'] extends ReadonlyArray<Schema> ? UnionToIntersection<UnionSchemaType<NonNullable<p['items']['allOf']>>>[] :
|
2022-01-18 14:27:10 +01:00
|
|
|
|
never
|
|
|
|
|
) :
|
2022-02-19 06:05:32 +01:00
|
|
|
|
p['items'] extends NonNullable<Schema> ? SchemaTypeDef<p['items']>[] :
|
2022-01-18 14:27:10 +01:00
|
|
|
|
any[]
|
2021-09-11 18:12:23 +02:00
|
|
|
|
) :
|
2023-02-01 12:04:01 +01:00
|
|
|
|
p['anyOf'] extends ReadonlyArray<Schema> ? UnionSchemaType<p['anyOf']> & PartialIntersection<UnionSchemaType<p['anyOf']>> :
|
2022-02-19 06:05:32 +01:00
|
|
|
|
p['oneOf'] extends ReadonlyArray<Schema> ? UnionSchemaType<p['oneOf']> :
|
2019-02-24 01:45:27 +01:00
|
|
|
|
any;
|
2022-01-18 14:27:10 +01:00
|
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
|
export type SchemaType<p extends Schema> = NullOrUndefined<p, SchemaTypeDef<p>>;
|