Revert "fix"

This reverts commit 22adc78906.
This commit is contained in:
kakkokari-gtyih 2024-09-07 01:10:08 +09:00
parent 2898add86a
commit c90c32d62a
4 changed files with 20 additions and 23 deletions

View File

@ -3,8 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import type { SomeJTDSchemaType } from 'ajv/dist/core.js';
import {
packedMeDetailedOnlySchema,
packedMeDetailedSchema,
@ -136,19 +134,19 @@ type StringDefToType<T extends TypeStringef> =
any;
// https://swagger.io/specification/?sbsearch=optional#schema-object
type OfSchema<T> = {
readonly anyOf?: ReadonlyArray<T>;
readonly oneOf?: ReadonlyArray<T>;
readonly allOf?: ReadonlyArray<T>;
type OfSchema = {
readonly anyOf?: ReadonlyArray<Schema>;
readonly oneOf?: ReadonlyArray<Schema>;
readonly allOf?: ReadonlyArray<Schema>;
}
interface SchemaFactory<T> extends OfSchema<T> {
export interface Schema extends OfSchema {
readonly type?: TypeStringef;
readonly nullable?: boolean;
readonly optional?: boolean;
readonly prefixItems?: ReadonlyArray<T>;
readonly items?: T;
readonly unevaluatedItems?: T | boolean;
readonly prefixItems?: ReadonlyArray<Schema>;
readonly items?: Schema;
readonly unevaluatedItems?: Schema | boolean;
readonly properties?: Obj;
readonly required?: ReadonlyArray<Extract<keyof NonNullable<this['properties']>, string>>;
readonly description?: string;
@ -165,10 +163,6 @@ interface SchemaFactory<T> extends OfSchema<T> {
readonly pattern?: string;
}
export type Schema = SchemaFactory<Schema>;
export type ValidatableSchema = SchemaFactory<Schema & SomeJTDSchemaType> & SomeJTDSchemaType;
type RequiredPropertyNames<s extends Obj> = {
[K in keyof s]:
// K is not optional
@ -235,7 +229,7 @@ export type SchemaTypeDef<p extends Schema> =
p['type'] extends 'boolean' ? boolean :
p['type'] extends 'object' ? ObjectSchemaTypeDef<p> :
p['type'] extends 'array' ? (
p['items'] extends OfSchema<p> ? (
p['items'] extends OfSchema ? (
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']>>>[] :

View File

@ -4,8 +4,7 @@
*/
import { permissions } from 'misskey-js';
import type { ApiErrorInput } from '@/server/api/error.js';
import type { KeyOf, ValidatableSchema } from '@/misc/json-schema.js';
import type { KeyOf, Schema } from '@/misc/json-schema.js';
import * as ep___admin_abuseReport_notificationRecipient_list
from '@/server/api/endpoints/admin/abuse-report/notification-recipient/list.js';
@ -781,10 +780,14 @@ interface IEndpointMetaBase {
readonly tags?: ReadonlyArray<string>;
readonly errors?: {
readonly [key: string]: ApiErrorInput;
readonly [key: string]: {
readonly message: string;
readonly code: string;
readonly id: string;
};
};
readonly res?: ValidatableSchema;
readonly res?: Schema;
/**
*

View File

@ -6,7 +6,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { IEndpointMeta } from '@/server/api/endpoints.js';
import type { Schema, ValidatableSchema } from '@/misc/json-schema.js';
import type { Schema } from '@/misc/json-schema.js';
import type { AppsRepository } from '@/models/_.js';
import { IdService } from '@/core/IdService.js';
import { unique } from '@/misc/prelude/array.js';
@ -37,7 +37,7 @@ export const paramDef = {
callbackUrl: { type: 'string', nullable: true },
},
required: ['name', 'description', 'permission'],
} as const satisfies ValidatableSchema;
} as const satisfies Schema;
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export

View File

@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
export type ApiErrorInput = { message: string, code: string, id: string, kind?: 'client' | 'server' | 'permission', httpStatusCode?: number };
type E = { message: string, code: string, id: string, kind?: 'client' | 'server' | 'permission', httpStatusCode?: number };
export class ApiError extends Error {
public message: string;
@ -13,7 +13,7 @@ export class ApiError extends Error {
public httpStatusCode?: number;
public info?: any;
constructor(err?: ApiErrorInput | null | undefined, info?: any | null | undefined) {
constructor(err?: E | null | undefined, info?: any | null | undefined) {
if (err == null) err = {
message: 'Internal error occurred. Please contact us if the error persists.',
code: 'INTERNAL_ERROR',