From ac99cdce8bd54ef6ba6669a6e773e81a81a1aa93 Mon Sep 17 00:00:00 2001 From: tamaina Date: Wed, 10 May 2023 17:48:21 +0000 Subject: [PATCH] wip --- packages/backend/package.json | 5 +++-- packages/backend/src/misc/json-schema.ts | 5 +++-- packages/backend/src/server/api/endpoint-base.ts | 2 +- .../backend/src/server/api/endpoints/ap/show.ts | 2 +- packages/backend/src/server/api/openapi/schemas.ts | 2 +- packages/misskey-js/src/index.ts | 5 +++++ packages/misskey-js/src/schemas.ts | 14 +++----------- pnpm-lock.yaml | 5 +++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index e0ece2bfe..0b49de692 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -102,8 +102,8 @@ "jsdom": "21.1.1", "json5": "2.2.3", "jsonld": "8.1.1", - "meilisearch": "0.32.3", "jsrsasign": "10.8.6", + "meilisearch": "0.32.3", "mfm-js": "0.23.3", "mime-types": "2.1.35", "misskey-js": "workspace:*", @@ -210,6 +210,7 @@ "eslint-plugin-import": "2.27.5", "execa": "6.1.0", "jest": "29.5.0", - "jest-mock": "29.5.0" + "jest-mock": "29.5.0", + "schema-type": "github:misskey-dev/schema-type" } } diff --git a/packages/backend/src/misc/json-schema.ts b/packages/backend/src/misc/json-schema.ts index e748f93a2..74a308fe2 100644 --- a/packages/backend/src/misc/json-schema.ts +++ b/packages/backend/src/misc/json-schema.ts @@ -1,3 +1,6 @@ +export type Packed = SchemaType; + + import { packedUserLiteSchema, packedUserDetailedNotMeOnlySchema, @@ -64,8 +67,6 @@ export const refs = { Flash: packedFlashSchema, }; -export type Packed = SchemaType; - type TypeStringef = 'null' | 'boolean' | 'integer' | 'number' | 'string' | 'array' | 'object' | 'any'; type StringDefToType = T extends 'null' ? null : diff --git a/packages/backend/src/server/api/endpoint-base.ts b/packages/backend/src/server/api/endpoint-base.ts index 1555a3ca4..a3e903f30 100644 --- a/packages/backend/src/server/api/endpoint-base.ts +++ b/packages/backend/src/server/api/endpoint-base.ts @@ -1,6 +1,6 @@ import * as fs from 'node:fs'; import Ajv from 'ajv'; -import type { Schema, SchemaType } from '@/misc/json-schema.js'; +import type { JSONSchema7, SchemaType } from 'schema-type'; import type { LocalUser } from '@/models/entities/User.js'; import type { AccessToken } from '@/models/entities/AccessToken.js'; import { ApiError } from './error.js'; diff --git a/packages/backend/src/server/api/endpoints/ap/show.ts b/packages/backend/src/server/api/endpoints/ap/show.ts index a103d4196..e626c6569 100644 --- a/packages/backend/src/server/api/endpoints/ap/show.ts +++ b/packages/backend/src/server/api/endpoints/ap/show.ts @@ -5,7 +5,7 @@ import type { UsersRepository, NotesRepository } from '@/models/index.js'; import type { Note } from '@/models/entities/Note.js'; import type { LocalUser, User } from '@/models/entities/User.js'; import { isActor, isPost, getApId } from '@/core/activitypub/type.js'; -import type { SchemaType } from '@/misc/json-schema.js'; +import type { SchemaType } from 'schema-type'; import { ApResolverService } from '@/core/activitypub/ApResolverService.js'; import { ApDbResolverService } from '@/core/activitypub/ApDbResolverService.js'; import { MetaService } from '@/core/MetaService.js'; diff --git a/packages/backend/src/server/api/openapi/schemas.ts b/packages/backend/src/server/api/openapi/schemas.ts index 0cef361ca..6af2ba8bd 100644 --- a/packages/backend/src/server/api/openapi/schemas.ts +++ b/packages/backend/src/server/api/openapi/schemas.ts @@ -1,5 +1,5 @@ import type { Schema } from '@/misc/json-schema.js'; -import { refs } from '@/misc/json-schema.js'; +import { refs } from 'misskey-js'; export function convertSchemaToOpenApiSchema(schema: Schema) { const res: any = schema; diff --git a/packages/misskey-js/src/index.ts b/packages/misskey-js/src/index.ts index d5cb5123d..797f10a4e 100644 --- a/packages/misskey-js/src/index.ts +++ b/packages/misskey-js/src/index.ts @@ -2,6 +2,8 @@ import { Endpoints } from './api.types.js'; import Stream, { Connection } from './streaming.js'; import { Channels } from './streaming.types.js'; import { Acct } from './acct.js'; +import type { Packed, Def } from './schemas.js'; +import { refs as _refs } from './schemas.js'; import * as consts from './consts.js'; export { @@ -10,8 +12,11 @@ export { Connection as ChannelConnection, Channels, Acct, + Packed, Def, }; +export const refs = _refs; + export const permissions = consts.permissions; export const notificationTypes = consts.notificationTypes; export const obsoleteNotificationTypes = consts.obsoleteNotificationTypes; diff --git a/packages/misskey-js/src/schemas.ts b/packages/misskey-js/src/schemas.ts index f75a5f26e..ddf213a46 100644 --- a/packages/misskey-js/src/schemas.ts +++ b/packages/misskey-js/src/schemas.ts @@ -33,6 +33,8 @@ import { packedFlashSchema } from './schemas/flash.js'; import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type'; export const refs = { + Id: IdSchema, + UserLite: packedUserLiteSchema, UserDetailedNotMeOnly: packedUserDetailedNotMeOnlySchema, MeDetailedOnly: packedMeDetailedOnlySchema, @@ -66,17 +68,7 @@ export const refs = { Flash: packedFlashSchema, } as const satisfies { [x: string]: JSONSchema7Definition }; -type Refs = typeof refs[keyof typeof refs]; - -export type References = [ - typeof IdSchema, - ...UnionToArray, -]; +type References = GetRefs; 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/pnpm-lock.yaml b/pnpm-lock.yaml index d2d9cc330..7badfa713 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -621,6 +621,9 @@ importers: jest-mock: specifier: 29.5.0 version: 29.5.0 + schema-type: + specifier: github:misskey-dev/schema-type + version: github.com/misskey-dev/schema-type/c771673a44d514658d4d5a4dd2c201b2294f225b(typescript@5.0.4) packages/frontend: dependencies: @@ -18896,7 +18899,6 @@ packages: typescript: '>=4.1.0' dependencies: typescript: 5.0.4 - dev: false /ts-map@1.0.3: resolution: {integrity: sha512-vDWbsl26LIcPGmDpoVzjEP6+hvHZkBkLW7JpvwbCv/5IYPJlsbzCVXY3wsCeAxAUeTclNOUZxnLdGh3VBD/J6w==} @@ -20332,7 +20334,6 @@ packages: tsd: 0.28.1 transitivePeerDependencies: - typescript - dev: false github.com/misskey-dev/sharp-read-bmp/02d9dc189fa7df0c4bea09330be26741772dac01: resolution: {tarball: https://codeload.github.com/misskey-dev/sharp-read-bmp/tar.gz/02d9dc189fa7df0c4bea09330be26741772dac01}