From 56a1e436f371194397db61fd2a15789d303a56a7 Mon Sep 17 00:00:00 2001 From: tamaina Date: Wed, 10 May 2023 16:55:36 +0000 Subject: [PATCH] wip --- packages/misskey-js/src/schemas.ts | 8 +- packages/misskey-js/src/schemas/user.ts | 364 ++++++++++++------------ pnpm-lock.yaml | 16 +- 3 files changed, 192 insertions(+), 196 deletions(-) diff --git a/packages/misskey-js/src/schemas.ts b/packages/misskey-js/src/schemas.ts index 8aa40ac3a..f75a5f26e 100644 --- a/packages/misskey-js/src/schemas.ts +++ b/packages/misskey-js/src/schemas.ts @@ -64,19 +64,19 @@ export const refs = { EmojiSimple: packedEmojiSimpleSchema, EmojiDetailed: packedEmojiDetailedSchema, Flash: packedFlashSchema, -} as const /*satisfies { [x: string]: JSONSchema7Definition }*/; +} as const satisfies { [x: string]: JSONSchema7Definition }; -type Refs = typeof packedAntennaSchema | typeof packedNoteSchema; // TODO: typeof refs[keyof typeof refs]; +type Refs = typeof refs[keyof typeof refs]; export type References = [ typeof IdSchema, - typeof packedAntennaSchema, - typeof packedNoteSchema, + ...UnionToArray, ]; export type Packed> = GetDef; export type Def> = GetDef; export type PackedNote = Packed<'Note'>; +export type PackedUser = Packed<'User'>; export type DefNote = Def<'https://misskey-hub.net/api/schemas/Note'>; let renote: PackedNote['reply']; diff --git a/packages/misskey-js/src/schemas/user.ts b/packages/misskey-js/src/schemas/user.ts index 29ddc00d0..6da5205a1 100644 --- a/packages/misskey-js/src/schemas/user.ts +++ b/packages/misskey-js/src/schemas/user.ts @@ -1,4 +1,4 @@ -import type { JSONSchema7Definition } from 'schema-type'; +import type { JSONSchema7, JSONSchema7Definition } from 'schema-type'; export const packedUserLiteSchema = { $id: 'https://misskey-hub.net/api/schemas/UserLite', @@ -63,6 +63,7 @@ export const packedUserLiteSchema = { export const packedUserDetailedNotMeOnlySchema = { $id: 'https://misskey-hub.net/api/schemas/UserDetailedNotMeOnly', + type: 'object', oneOf: [{ $ref: '#/$defs/base', }, { @@ -297,204 +298,199 @@ export const packedUserDetailedNotMeOnlySchema = { } as const satisfies JSONSchema7Definition; export const packedMeDetailedOnlySchema = { + $id: 'https://misskey-hub.net/api/schemas/MeDetailedOnly', + 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, - }, - preventAiLarning: { - type: 'boolean', - nullable: false, 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, + 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', + }], }, }, }, - mutedInstances: { - type: 'array', - nullable: true, optional: false, - items: { - type: 'string', - nullable: false, optional: false, + secrets: { + type: 'object', + properties: { + email: { + type: ['string', 'null'], + }, + emailVerified: { + type: ['boolean', 'null'], + }, + securityKeysList: { + type: 'array', + items: { + type: 'object', + additionalProperties: true, + }, + }, }, + required: [ + 'email', + 'emailVerified', + 'securityKeysList', + ], }, - 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; +} as const satisfies JSONSchema7Definition; export const packedUserDetailedNotMeSchema = { + $id: 'https://misskey-hub.net/api/schemas/UserDetailedNotMe', + type: 'object', - allOf: [ - { - type: 'object', - ref: 'UserLite', - }, - { - type: 'object', - ref: 'UserDetailedNotMeOnly', - }, - ], -} as const; + allOf: [{ + $ref: 'https://misskey-hub.net/api/schemas/UserLite', + }, { + $ref: 'https://misskey-hub.net/api/schemas/UserDetailedNotMeOnly', + }], +} as const satisfies JSONSchema7Definition; export const packedMeDetailedSchema = { + $id: 'https://misskey-hub.net/api/schemas/MeDetailed', + type: 'object', - allOf: [ - { - type: 'object', - ref: 'UserLite', - }, - { - type: 'object', - ref: 'UserDetailedNotMeOnly', - }, - { - type: 'object', - ref: 'MeDetailedOnly', - }, - ], -} as const; + 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; export const packedUserDetailedSchema = { - oneOf: [ - { - type: 'object', - ref: 'UserDetailedNotMe', - }, - { - type: 'object', - ref: 'MeDetailed', - }, - ], -} as const; + $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; export const packedUserSchema = { - oneOf: [ - { - type: 'object', - ref: 'UserLite', - }, - { - type: 'object', - ref: 'UserDetailed', - }, - ], -} as const; + $id: 'https://misskey-hub.net/api/schemas/User', -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; + type: 'object', + oneOf: [{ + $ref: 'https://misskey-hub.net/api/schemas/UserLite', + }, { + $ref: 'https://misskey-hub.net/api/schemas/UserDetailed', + }], +} as const satisfies JSONSchema7Definition; + +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; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 32df48a96..d2d9cc330 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -348,7 +348,7 @@ importers: version: 2.1.0 summaly: specifier: github:misskey-dev/summaly - version: github.com/misskey-dev/summaly/2d63e2a0066f89871e777cc81d43c1ade8c97517 + version: github.com/misskey-dev/summaly/77dd5654bb82280b38c1f50e51a771c33f3df503 systeminformation: specifier: 5.17.12 version: 5.17.12 @@ -984,7 +984,7 @@ importers: version: github.com/misskey-dev/storybook-addon-misskey-theme/cf583db098365b2ccc81a82f63ca9c93bc32b640(@storybook/blocks@7.0.7)(@storybook/components@7.0.7)(@storybook/core-events@7.0.7)(@storybook/manager-api@7.0.7)(@storybook/preview-api@7.0.7)(@storybook/theming@7.0.7)(@storybook/types@7.0.7)(react-dom@18.2.0)(react@18.2.0) summaly: specifier: github:misskey-dev/summaly - version: github.com/misskey-dev/summaly/2d63e2a0066f89871e777cc81d43c1ade8c97517 + version: github.com/misskey-dev/summaly/77dd5654bb82280b38c1f50e51a771c33f3df503 vite-plugin-turbosnap: specifier: 1.0.2 version: 1.0.2 @@ -1020,7 +1020,7 @@ importers: version: 4.4.0 schema-type: specifier: github:misskey-dev/schema-type - version: github.com/misskey-dev/schema-type/d50e5ea86b7aeb3a6ddfba0717e44c016ac42854(typescript@5.0.4) + version: github.com/misskey-dev/schema-type/c771673a44d514658d4d5a4dd2c201b2294f225b(typescript@5.0.4) ts-essentials: specifier: ^9.3.2 version: 9.3.2(typescript@5.0.4) @@ -20321,9 +20321,9 @@ packages: version: 2.2.1-misskey.3 dev: false - github.com/misskey-dev/schema-type/d50e5ea86b7aeb3a6ddfba0717e44c016ac42854(typescript@5.0.4): - resolution: {tarball: https://codeload.github.com/misskey-dev/schema-type/tar.gz/d50e5ea86b7aeb3a6ddfba0717e44c016ac42854} - id: github.com/misskey-dev/schema-type/d50e5ea86b7aeb3a6ddfba0717e44c016ac42854 + github.com/misskey-dev/schema-type/c771673a44d514658d4d5a4dd2c201b2294f225b(typescript@5.0.4): + resolution: {tarball: https://codeload.github.com/misskey-dev/schema-type/tar.gz/c771673a44d514658d4d5a4dd2c201b2294f225b} + id: github.com/misskey-dev/schema-type/c771673a44d514658d4d5a4dd2c201b2294f225b name: schema-type version: 1.0.0 dependencies: @@ -20376,8 +20376,8 @@ packages: react-dom: 18.2.0(react@18.2.0) dev: true - github.com/misskey-dev/summaly/2d63e2a0066f89871e777cc81d43c1ade8c97517: - resolution: {tarball: https://codeload.github.com/misskey-dev/summaly/tar.gz/2d63e2a0066f89871e777cc81d43c1ade8c97517} + github.com/misskey-dev/summaly/77dd5654bb82280b38c1f50e51a771c33f3df503: + resolution: {tarball: https://codeload.github.com/misskey-dev/summaly/tar.gz/77dd5654bb82280b38c1f50e51a771c33f3df503} name: summaly version: 4.0.2 dependencies: