Merge branch 'develop' into ed25519

This commit is contained in:
tamaina
2024-07-17 15:10:45 +09:00
263 changed files with 9833 additions and 6425 deletions

View File

@@ -1,8 +0,0 @@
node_modules
/built
/coverage
/.eslintrc.js
/jest.config.ts
/test
/test-d
build.js

View File

@@ -1,9 +0,0 @@
module.exports = {
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
extends: [
'../shared/.eslintrc.js',
],
};

View File

@@ -1,32 +1,32 @@
import * as esbuild from "esbuild";
import { build } from "esbuild";
import { globSync } from "glob";
import { execa } from "execa";
import fs from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname } from "node:path";
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import * as esbuild from 'esbuild';
import { build } from 'esbuild';
import { globSync } from 'glob';
import { execa } from 'execa';
const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename);
const _package = JSON.parse(fs.readFileSync(_dirname + '/package.json', 'utf-8'));
const entryPoints = globSync("./src/**/**.{ts,tsx}");
const entryPoints = globSync('./src/**/**.{ts,tsx}');
/** @type {import('esbuild').BuildOptions} */
const options = {
entryPoints,
minify: process.env.NODE_ENV === 'production',
outdir: "./built",
target: "es2022",
platform: "browser",
format: "esm",
outdir: './built',
target: 'es2022',
platform: 'browser',
format: 'esm',
sourcemap: 'linked',
};
// built配下をすべて削除する
fs.rmSync('./built', { recursive: true, force: true });
if (process.argv.map(arg => arg.toLowerCase()).includes("--watch")) {
if (process.argv.map(arg => arg.toLowerCase()).includes('--watch')) {
await watchSrc();
} else {
await buildSrc();
@@ -36,7 +36,7 @@ async function buildSrc() {
console.log(`[${_package.name}] start building...`);
await build(options)
.then(it => {
.then(() => {
console.log(`[${_package.name}] build succeeded.`);
})
.catch((err) => {
@@ -65,7 +65,7 @@ function buildDts() {
{
stdout: process.stdout,
stderr: process.stderr,
}
},
);
}
@@ -86,7 +86,7 @@ async function watchSrc() {
},
}];
console.log(`[${_package.name}] start watching...`)
console.log(`[${_package.name}] start watching...`);
const context = await esbuild.context({ ...options, plugins });
await context.watch();
@@ -95,7 +95,6 @@ async function watchSrc() {
process.on('SIGHUP', resolve);
process.on('SIGINT', resolve);
process.on('SIGTERM', resolve);
process.on('SIGKILL', resolve);
process.on('uncaughtException', reject);
process.on('exit', resolve);
}).finally(async () => {

View File

@@ -0,0 +1,28 @@
import tsParser from '@typescript-eslint/parser';
import sharedConfig from '../shared/eslint.config.js';
export default [
...sharedConfig,
{
ignores: [
'**/node_modules',
'built',
'coverage',
'jest.config.ts',
'test',
'test-d',
'generator',
],
},
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parserOptions: {
parser: tsParser,
project: ['./tsconfig.json'],
sourceType: 'module',
tsconfigRootDir: import.meta.dirname,
},
},
},
];

View File

@@ -1160,6 +1160,12 @@ export type Endpoints = Overwrite<Endpoints_2, {
req: SigninRequest;
res: SigninResponse;
};
'admin/roles/create': {
req: Overwrite<AdminRolesCreateRequest, {
policies: PartialRolePolicyOverride;
}>;
res: AdminRolesCreateResponse;
};
}>;
// @public (undocumented)
@@ -1185,6 +1191,7 @@ declare namespace entities {
SignupPendingResponse,
SigninRequest,
SigninResponse,
PartialRolePolicyOverride,
EmptyRequest,
EmptyResponse,
AdminMetaResponse,
@@ -1869,7 +1876,7 @@ type FetchExternalResourcesResponse = operations['fetch-external-resources']['re
// @public (undocumented)
type FetchLike = (input: string, init?: {
method?: string;
body?: string;
body?: Blob | FormData | string;
credentials?: RequestCredentials;
cache?: RequestCache;
headers: {
@@ -2725,6 +2732,15 @@ type PagesUpdateRequest = operations['pages___update']['requestBody']['content']
// @public (undocumented)
function parse(acct: string): Acct;
// Warning: (ae-forgotten-export) The symbol "Values" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type PartialRolePolicyOverride = Partial<{
[k in keyof RolePolicies]: Omit<Values<Role['policies']>, 'value'> & {
value: RolePolicies[k];
};
}>;
// @public (undocumented)
export const permissions: readonly ["read:account", "write:account", "read:blocks", "write:blocks", "read:drive", "write:drive", "read:favorites", "write:favorites", "read:following", "write:following", "read:messaging", "write:messaging", "read:mutes", "write:mutes", "write:notes", "read:notifications", "write:notifications", "read:reactions", "write:reactions", "write:votes", "read:pages", "write:pages", "write:page-likes", "read:page-likes", "read:user-groups", "write:user-groups", "read:channels", "write:channels", "read:gallery", "write:gallery", "read:gallery-likes", "write:gallery-likes", "read:flash", "write:flash", "read:flash-likes", "write:flash-likes", "read:admin:abuse-user-reports", "write:admin:delete-account", "write:admin:delete-all-files-of-a-user", "read:admin:index-stats", "read:admin:table-stats", "read:admin:user-ips", "read:admin:meta", "write:admin:reset-password", "write:admin:resolve-abuse-user-report", "write:admin:send-email", "read:admin:server-info", "read:admin:show-moderation-log", "read:admin:show-user", "write:admin:suspend-user", "write:admin:unset-user-avatar", "write:admin:unset-user-banner", "write:admin:unsuspend-user", "write:admin:meta", "write:admin:user-note", "write:admin:roles", "read:admin:roles", "write:admin:relays", "read:admin:relays", "write:admin:invite-codes", "read:admin:invite-codes", "write:admin:announcements", "read:admin:announcements", "write:admin:avatar-decorations", "read:admin:avatar-decorations", "write:admin:federation", "write:admin:account", "read:admin:account", "write:admin:emoji", "read:admin:emoji", "write:admin:queue", "read:admin:queue", "write:admin:promo", "write:admin:drive", "read:admin:drive", "write:admin:ad", "read:admin:ad", "write:invite-codes", "read:invite-codes", "write:clip-favorite", "read:clip-favorite", "read:federation", "write:report-abuse"];
@@ -3213,7 +3229,7 @@ type UsersUpdateMemoRequest = operations['users___update-memo']['requestBody']['
// Warnings were encountered during analysis:
//
// src/entities.ts:25:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts
// src/entities.ts:34:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts
// (No @packageDocumentation comment for this package)

View File

@@ -1,9 +0,0 @@
module.exports = {
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
extends: [
'../../shared/.eslintrc.js',
],
};

View File

@@ -0,0 +1,17 @@
import tsParser from '@typescript-eslint/parser';
import sharedConfig from '../../shared/eslint.config.js';
export default [
...sharedConfig,
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parserOptions: {
parser: tsParser,
project: ['./tsconfig.json'],
sourceType: 'module',
tsconfigRootDir: import.meta.dirname,
},
},
},
];

View File

@@ -4,15 +4,13 @@
"description": "Misskey TypeGenerator",
"type": "module",
"scripts": {
"generate": "tsx src/generator.ts && eslint ./built/**/* --ext .ts --fix"
"generate": "tsx src/generator.ts && eslint ./built/**/*.ts --fix"
},
"devDependencies": {
"@misskey-dev/eslint-plugin": "^1.0.0",
"@readme/openapi-parser": "2.5.0",
"@types/node": "20.9.1",
"@typescript-eslint/eslint-plugin": "6.11.0",
"@typescript-eslint/parser": "6.11.0",
"eslint": "8.53.0",
"openapi-types": "12.1.3",
"openapi-typescript": "6.7.3",
"ts-case-convert": "2.0.2",

View File

@@ -20,7 +20,14 @@ async function generateBaseTypes(
}
lines.push('');
const generatedTypes = await openapiTS(openApiJsonPath, { exportType: true });
const generatedTypes = await openapiTS(openApiJsonPath, {
exportType: true,
transform(schemaObject) {
if ('format' in schemaObject && schemaObject.format === 'binary') {
return schemaObject.nullable ? 'Blob | null' : 'Blob';
}
},
});
lines.push(generatedTypes);
lines.push('');
@@ -56,6 +63,8 @@ async function generateEndpoints(
endpointOutputPath: string,
) {
const endpoints: Endpoint[] = [];
const endpointReqMediaTypes: EndpointReqMediaType[] = [];
const endpointReqMediaTypesSet = new Set<string>();
// misskey-jsはPOST固定で送っているので、こちらも決め打ちする。別メソッドに対応することがあればこちらも直す必要あり
const paths = openApiDocs.paths ?? {};
@@ -78,13 +87,24 @@ async function generateEndpoints(
const supportMediaTypes = Object.keys(reqContent);
if (supportMediaTypes.length > 0) {
// いまのところ複数のメディアタイプをとるエンドポイントは無いので決め打ちする
endpoint.request = new OperationTypeAlias(
const req = new OperationTypeAlias(
operationId,
path,
supportMediaTypes[0],
OperationsAliasType.REQUEST,
);
endpoint.request = req;
const reqType = new EndpointReqMediaType(path, req);
endpointReqMediaTypesSet.add(reqType.getMediaType());
endpointReqMediaTypes.push(reqType);
} else {
endpointReqMediaTypesSet.add('application/json');
endpointReqMediaTypes.push(new EndpointReqMediaType(path, undefined, 'application/json'));
}
} else {
endpointReqMediaTypesSet.add('application/json');
endpointReqMediaTypes.push(new EndpointReqMediaType(path, undefined, 'application/json'));
}
if (operation.responses && isResponseObject(operation.responses['200']) && operation.responses['200'].content) {
@@ -137,6 +157,19 @@ async function generateEndpoints(
endpointOutputLine.push('}');
endpointOutputLine.push('');
function generateEndpointReqMediaTypesType() {
return `Record<keyof Endpoints, ${[...endpointReqMediaTypesSet].map((t) => `'${t}'`).join(' | ')}>`;
}
endpointOutputLine.push(`export const endpointReqTypes: ${generateEndpointReqMediaTypesType()} = {`);
endpointOutputLine.push(
...endpointReqMediaTypes.map(it => '\t' + it.toLine()),
);
endpointOutputLine.push('};');
endpointOutputLine.push('');
await writeFile(endpointOutputPath, endpointOutputLine.join('\n'));
}
@@ -314,6 +347,26 @@ class Endpoint {
}
}
class EndpointReqMediaType {
public readonly path: string;
public readonly mediaType: string;
constructor(path: string, request: OperationTypeAlias, mediaType?: undefined);
constructor(path: string, request: undefined, mediaType: string);
constructor(path: string, request: OperationTypeAlias | undefined, mediaType?: string) {
this.path = path;
this.mediaType = mediaType ?? request?.mediaType ?? 'application/json';
}
getMediaType(): string {
return this.mediaType;
}
toLine(): string {
return `'${this.path}': '${this.mediaType}',`;
}
}
async function main() {
const generatePath = './built/autogen';
await mkdir(generatePath, { recursive: true });

View File

@@ -22,7 +22,7 @@
"tsd": "tsd",
"api": "pnpm api-extractor run --local --verbose",
"api-prod": "pnpm api-extractor run --verbose",
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx",
"eslint": "eslint './**/*.{js,jsx,ts,tsx}'",
"typecheck": "tsc --noEmit",
"lint": "pnpm typecheck && pnpm eslint",
"jest": "jest --coverage --detectOpenHandles",
@@ -35,25 +35,23 @@
"directory": "packages/misskey-js"
},
"devDependencies": {
"@microsoft/api-extractor": "7.43.1",
"@misskey-dev/eslint-plugin": "1.0.0",
"@microsoft/api-extractor": "7.47.0",
"@swc/jest": "0.2.36",
"@types/jest": "29.5.12",
"@types/node": "20.12.7",
"@typescript-eslint/eslint-plugin": "7.7.1",
"@typescript-eslint/parser": "7.7.1",
"eslint": "8.57.0",
"@types/node": "20.14.9",
"@typescript-eslint/eslint-plugin": "7.15.0",
"@typescript-eslint/parser": "7.15.0",
"jest": "29.7.0",
"jest-fetch-mock": "3.0.3",
"jest-websocket-mock": "2.5.0",
"mock-socket": "9.3.1",
"ncp": "2.0.0",
"nodemon": "3.1.0",
"execa": "8.0.1",
"tsd": "0.30.7",
"typescript": "5.5.2",
"esbuild": "0.19.11",
"glob": "10.3.12"
"nodemon": "3.1.4",
"execa": "9.2.0",
"tsd": "0.31.1",
"typescript": "5.5.3",
"esbuild": "0.22.0",
"glob": "10.4.2"
},
"files": [
"built"

View File

@@ -1,7 +1,7 @@
import './autogen/apiClientJSDoc.js';
import { SwitchCaseResponseType } from './api.types.js';
import type { Endpoints } from './api.types.js';
import { endpointReqTypes } from './autogen/endpoint.js';
import type { SwitchCaseResponseType, Endpoints } from './api.types.js';
export type {
SwitchCaseResponseType,
@@ -23,7 +23,7 @@ export function isAPIError(reason: Record<PropertyKey, unknown>): reason is APIE
export type FetchLike = (input: string, init?: {
method?: string;
body?: string;
body?: Blob | FormData | string;
credentials?: RequestCredentials;
cache?: RequestCache;
headers: { [key in string]: string }
@@ -49,20 +49,55 @@ export class APIClient {
this.fetch = opts.fetch ?? ((...args) => fetch(...args));
}
private assertIsRecord<T>(obj: T): obj is T & Record<string, any> {
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
}
public request<E extends keyof Endpoints, P extends Endpoints[E]['req']>(
endpoint: E,
params: P = {} as P,
credential?: string | null,
): Promise<SwitchCaseResponseType<E, P>> {
return new Promise((resolve, reject) => {
this.fetch(`${this.origin}/api/${endpoint}`, {
method: 'POST',
body: JSON.stringify({
let mediaType = 'application/json';
if (endpoint in endpointReqTypes) {
mediaType = endpointReqTypes[endpoint];
}
let payload: FormData | string = '{}';
if (mediaType === 'application/json') {
payload = JSON.stringify({
...params,
i: credential !== undefined ? credential : this.credential,
}),
});
} else if (mediaType === 'multipart/form-data') {
payload = new FormData();
const i = credential !== undefined ? credential : this.credential;
if (i != null) {
payload.append('i', i);
}
if (this.assertIsRecord(params)) {
for (const key in params) {
const value = params[key];
if (value == null) continue;
if (value instanceof File || value instanceof Blob) {
payload.append(key, value);
} else if (typeof value === 'object') {
payload.append(key, JSON.stringify(value));
} else {
payload.append(key, value);
}
}
}
}
this.fetch(`${this.origin}/api/${endpoint}`, {
method: 'POST',
body: payload,
headers: {
'Content-Type': 'application/json',
'Content-Type': endpointReqTypes[endpoint],
},
credentials: 'omit',
cache: 'no-cache',

View File

@@ -1,7 +1,8 @@
import { Endpoints as Gen } from './autogen/endpoint.js';
import { UserDetailed } from './autogen/models.js';
import { UsersShowRequest } from './autogen/entities.js';
import { AdminRolesCreateRequest, AdminRolesCreateResponse, UsersShowRequest } from './autogen/entities.js';
import {
PartialRolePolicyOverride,
SigninRequest,
SigninResponse,
SignupPendingRequest,
@@ -79,5 +80,9 @@ export type Endpoints = Overwrite<
req: SigninRequest;
res: SigninResponse;
},
'admin/roles/create': {
req: Overwrite<AdminRolesCreateRequest, { policies: PartialRolePolicyOverride }>;
res: AdminRolesCreateResponse;
}
}
>

View File

@@ -954,3 +954,385 @@ export type Endpoints = {
'reversi/surrender': { req: ReversiSurrenderRequest; res: EmptyResponse };
'reversi/verify': { req: ReversiVerifyRequest; res: ReversiVerifyResponse };
}
export const endpointReqTypes: Record<keyof Endpoints, 'application/json' | 'multipart/form-data'> = {
'admin/meta': 'application/json',
'admin/abuse-user-reports': 'application/json',
'admin/abuse-report/notification-recipient/list': 'application/json',
'admin/abuse-report/notification-recipient/show': 'application/json',
'admin/abuse-report/notification-recipient/create': 'application/json',
'admin/abuse-report/notification-recipient/update': 'application/json',
'admin/abuse-report/notification-recipient/delete': 'application/json',
'admin/accounts/create': 'application/json',
'admin/accounts/delete': 'application/json',
'admin/accounts/find-by-email': 'application/json',
'admin/ad/create': 'application/json',
'admin/ad/delete': 'application/json',
'admin/ad/list': 'application/json',
'admin/ad/update': 'application/json',
'admin/announcements/create': 'application/json',
'admin/announcements/delete': 'application/json',
'admin/announcements/list': 'application/json',
'admin/announcements/update': 'application/json',
'admin/avatar-decorations/create': 'application/json',
'admin/avatar-decorations/delete': 'application/json',
'admin/avatar-decorations/list': 'application/json',
'admin/avatar-decorations/update': 'application/json',
'admin/delete-all-files-of-a-user': 'application/json',
'admin/unset-user-avatar': 'application/json',
'admin/unset-user-banner': 'application/json',
'admin/drive/clean-remote-files': 'application/json',
'admin/drive/cleanup': 'application/json',
'admin/drive/files': 'application/json',
'admin/drive/show-file': 'application/json',
'admin/emoji/add-aliases-bulk': 'application/json',
'admin/emoji/add': 'application/json',
'admin/emoji/copy': 'application/json',
'admin/emoji/delete-bulk': 'application/json',
'admin/emoji/delete': 'application/json',
'admin/emoji/import-zip': 'application/json',
'admin/emoji/list-remote': 'application/json',
'admin/emoji/list': 'application/json',
'admin/emoji/remove-aliases-bulk': 'application/json',
'admin/emoji/set-aliases-bulk': 'application/json',
'admin/emoji/set-category-bulk': 'application/json',
'admin/emoji/set-license-bulk': 'application/json',
'admin/emoji/update': 'application/json',
'admin/federation/delete-all-files': 'application/json',
'admin/federation/refresh-remote-instance-metadata': 'application/json',
'admin/federation/remove-all-following': 'application/json',
'admin/federation/update-instance': 'application/json',
'admin/get-index-stats': 'application/json',
'admin/get-table-stats': 'application/json',
'admin/get-user-ips': 'application/json',
'admin/invite/create': 'application/json',
'admin/invite/list': 'application/json',
'admin/promo/create': 'application/json',
'admin/queue/clear': 'application/json',
'admin/queue/deliver-delayed': 'application/json',
'admin/queue/inbox-delayed': 'application/json',
'admin/queue/promote': 'application/json',
'admin/queue/stats': 'application/json',
'admin/relays/add': 'application/json',
'admin/relays/list': 'application/json',
'admin/relays/remove': 'application/json',
'admin/reset-password': 'application/json',
'admin/resolve-abuse-user-report': 'application/json',
'admin/send-email': 'application/json',
'admin/server-info': 'application/json',
'admin/show-moderation-logs': 'application/json',
'admin/show-user': 'application/json',
'admin/show-users': 'application/json',
'admin/suspend-user': 'application/json',
'admin/unsuspend-user': 'application/json',
'admin/update-meta': 'application/json',
'admin/delete-account': 'application/json',
'admin/update-user-note': 'application/json',
'admin/roles/create': 'application/json',
'admin/roles/delete': 'application/json',
'admin/roles/list': 'application/json',
'admin/roles/show': 'application/json',
'admin/roles/update': 'application/json',
'admin/roles/assign': 'application/json',
'admin/roles/unassign': 'application/json',
'admin/roles/update-default-policies': 'application/json',
'admin/roles/users': 'application/json',
'admin/system-webhook/create': 'application/json',
'admin/system-webhook/delete': 'application/json',
'admin/system-webhook/list': 'application/json',
'admin/system-webhook/show': 'application/json',
'admin/system-webhook/update': 'application/json',
'announcements': 'application/json',
'announcements/show': 'application/json',
'antennas/create': 'application/json',
'antennas/delete': 'application/json',
'antennas/list': 'application/json',
'antennas/notes': 'application/json',
'antennas/show': 'application/json',
'antennas/update': 'application/json',
'ap/get': 'application/json',
'ap/show': 'application/json',
'app/create': 'application/json',
'app/show': 'application/json',
'auth/accept': 'application/json',
'auth/session/generate': 'application/json',
'auth/session/show': 'application/json',
'auth/session/userkey': 'application/json',
'blocking/create': 'application/json',
'blocking/delete': 'application/json',
'blocking/list': 'application/json',
'channels/create': 'application/json',
'channels/featured': 'application/json',
'channels/follow': 'application/json',
'channels/followed': 'application/json',
'channels/owned': 'application/json',
'channels/show': 'application/json',
'channels/timeline': 'application/json',
'channels/unfollow': 'application/json',
'channels/update': 'application/json',
'channels/favorite': 'application/json',
'channels/unfavorite': 'application/json',
'channels/my-favorites': 'application/json',
'channels/search': 'application/json',
'charts/active-users': 'application/json',
'charts/ap-request': 'application/json',
'charts/drive': 'application/json',
'charts/federation': 'application/json',
'charts/instance': 'application/json',
'charts/notes': 'application/json',
'charts/user/drive': 'application/json',
'charts/user/following': 'application/json',
'charts/user/notes': 'application/json',
'charts/user/pv': 'application/json',
'charts/user/reactions': 'application/json',
'charts/users': 'application/json',
'clips/add-note': 'application/json',
'clips/remove-note': 'application/json',
'clips/create': 'application/json',
'clips/delete': 'application/json',
'clips/list': 'application/json',
'clips/notes': 'application/json',
'clips/show': 'application/json',
'clips/update': 'application/json',
'clips/favorite': 'application/json',
'clips/unfavorite': 'application/json',
'clips/my-favorites': 'application/json',
'drive': 'application/json',
'drive/files': 'application/json',
'drive/files/attached-notes': 'application/json',
'drive/files/check-existence': 'application/json',
'drive/files/create': 'multipart/form-data',
'drive/files/delete': 'application/json',
'drive/files/find-by-hash': 'application/json',
'drive/files/find': 'application/json',
'drive/files/show': 'application/json',
'drive/files/update': 'application/json',
'drive/files/upload-from-url': 'application/json',
'drive/folders': 'application/json',
'drive/folders/create': 'application/json',
'drive/folders/delete': 'application/json',
'drive/folders/find': 'application/json',
'drive/folders/show': 'application/json',
'drive/folders/update': 'application/json',
'drive/stream': 'application/json',
'email-address/available': 'application/json',
'endpoint': 'application/json',
'endpoints': 'application/json',
'export-custom-emojis': 'application/json',
'federation/followers': 'application/json',
'federation/following': 'application/json',
'federation/instances': 'application/json',
'federation/show-instance': 'application/json',
'federation/update-remote-user': 'application/json',
'federation/users': 'application/json',
'federation/stats': 'application/json',
'following/create': 'application/json',
'following/delete': 'application/json',
'following/update': 'application/json',
'following/update-all': 'application/json',
'following/invalidate': 'application/json',
'following/requests/accept': 'application/json',
'following/requests/cancel': 'application/json',
'following/requests/list': 'application/json',
'following/requests/reject': 'application/json',
'gallery/featured': 'application/json',
'gallery/popular': 'application/json',
'gallery/posts': 'application/json',
'gallery/posts/create': 'application/json',
'gallery/posts/delete': 'application/json',
'gallery/posts/like': 'application/json',
'gallery/posts/show': 'application/json',
'gallery/posts/unlike': 'application/json',
'gallery/posts/update': 'application/json',
'get-online-users-count': 'application/json',
'get-avatar-decorations': 'application/json',
'hashtags/list': 'application/json',
'hashtags/search': 'application/json',
'hashtags/show': 'application/json',
'hashtags/trend': 'application/json',
'hashtags/users': 'application/json',
'i': 'application/json',
'i/2fa/done': 'application/json',
'i/2fa/key-done': 'application/json',
'i/2fa/password-less': 'application/json',
'i/2fa/register-key': 'application/json',
'i/2fa/register': 'application/json',
'i/2fa/update-key': 'application/json',
'i/2fa/remove-key': 'application/json',
'i/2fa/unregister': 'application/json',
'i/apps': 'application/json',
'i/authorized-apps': 'application/json',
'i/claim-achievement': 'application/json',
'i/change-password': 'application/json',
'i/delete-account': 'application/json',
'i/export-blocking': 'application/json',
'i/export-following': 'application/json',
'i/export-mute': 'application/json',
'i/export-notes': 'application/json',
'i/export-clips': 'application/json',
'i/export-favorites': 'application/json',
'i/export-user-lists': 'application/json',
'i/export-antennas': 'application/json',
'i/favorites': 'application/json',
'i/gallery/likes': 'application/json',
'i/gallery/posts': 'application/json',
'i/import-blocking': 'application/json',
'i/import-following': 'application/json',
'i/import-muting': 'application/json',
'i/import-user-lists': 'application/json',
'i/import-antennas': 'application/json',
'i/notifications': 'application/json',
'i/notifications-grouped': 'application/json',
'i/page-likes': 'application/json',
'i/pages': 'application/json',
'i/pin': 'application/json',
'i/read-all-unread-notes': 'application/json',
'i/read-announcement': 'application/json',
'i/regenerate-token': 'application/json',
'i/registry/get-all': 'application/json',
'i/registry/get-detail': 'application/json',
'i/registry/get': 'application/json',
'i/registry/keys-with-type': 'application/json',
'i/registry/keys': 'application/json',
'i/registry/remove': 'application/json',
'i/registry/scopes-with-domain': 'application/json',
'i/registry/set': 'application/json',
'i/revoke-token': 'application/json',
'i/signin-history': 'application/json',
'i/unpin': 'application/json',
'i/update-email': 'application/json',
'i/update': 'application/json',
'i/move': 'application/json',
'i/webhooks/create': 'application/json',
'i/webhooks/list': 'application/json',
'i/webhooks/show': 'application/json',
'i/webhooks/update': 'application/json',
'i/webhooks/delete': 'application/json',
'invite/create': 'application/json',
'invite/delete': 'application/json',
'invite/list': 'application/json',
'invite/limit': 'application/json',
'meta': 'application/json',
'emojis': 'application/json',
'emoji': 'application/json',
'miauth/gen-token': 'application/json',
'mute/create': 'application/json',
'mute/delete': 'application/json',
'mute/list': 'application/json',
'renote-mute/create': 'application/json',
'renote-mute/delete': 'application/json',
'renote-mute/list': 'application/json',
'my/apps': 'application/json',
'notes': 'application/json',
'notes/children': 'application/json',
'notes/clips': 'application/json',
'notes/conversation': 'application/json',
'notes/create': 'application/json',
'notes/delete': 'application/json',
'notes/favorites/create': 'application/json',
'notes/favorites/delete': 'application/json',
'notes/featured': 'application/json',
'notes/global-timeline': 'application/json',
'notes/hybrid-timeline': 'application/json',
'notes/local-timeline': 'application/json',
'notes/mentions': 'application/json',
'notes/polls/recommendation': 'application/json',
'notes/polls/vote': 'application/json',
'notes/reactions': 'application/json',
'notes/reactions/create': 'application/json',
'notes/reactions/delete': 'application/json',
'notes/renotes': 'application/json',
'notes/replies': 'application/json',
'notes/search-by-tag': 'application/json',
'notes/search': 'application/json',
'notes/show': 'application/json',
'notes/state': 'application/json',
'notes/thread-muting/create': 'application/json',
'notes/thread-muting/delete': 'application/json',
'notes/timeline': 'application/json',
'notes/translate': 'application/json',
'notes/unrenote': 'application/json',
'notes/user-list-timeline': 'application/json',
'notifications/create': 'application/json',
'notifications/flush': 'application/json',
'notifications/mark-all-as-read': 'application/json',
'notifications/test-notification': 'application/json',
'page-push': 'application/json',
'pages/create': 'application/json',
'pages/delete': 'application/json',
'pages/featured': 'application/json',
'pages/like': 'application/json',
'pages/show': 'application/json',
'pages/unlike': 'application/json',
'pages/update': 'application/json',
'flash/create': 'application/json',
'flash/delete': 'application/json',
'flash/featured': 'application/json',
'flash/like': 'application/json',
'flash/show': 'application/json',
'flash/unlike': 'application/json',
'flash/update': 'application/json',
'flash/my': 'application/json',
'flash/my-likes': 'application/json',
'ping': 'application/json',
'pinned-users': 'application/json',
'promo/read': 'application/json',
'roles/list': 'application/json',
'roles/show': 'application/json',
'roles/users': 'application/json',
'roles/notes': 'application/json',
'request-reset-password': 'application/json',
'reset-db': 'application/json',
'reset-password': 'application/json',
'server-info': 'application/json',
'stats': 'application/json',
'sw/show-registration': 'application/json',
'sw/update-registration': 'application/json',
'sw/register': 'application/json',
'sw/unregister': 'application/json',
'test': 'application/json',
'username/available': 'application/json',
'users': 'application/json',
'users/clips': 'application/json',
'users/followers': 'application/json',
'users/following': 'application/json',
'users/gallery/posts': 'application/json',
'users/get-frequently-replied-users': 'application/json',
'users/featured-notes': 'application/json',
'users/lists/create': 'application/json',
'users/lists/delete': 'application/json',
'users/lists/list': 'application/json',
'users/lists/pull': 'application/json',
'users/lists/push': 'application/json',
'users/lists/show': 'application/json',
'users/lists/favorite': 'application/json',
'users/lists/unfavorite': 'application/json',
'users/lists/update': 'application/json',
'users/lists/create-from-public': 'application/json',
'users/lists/update-membership': 'application/json',
'users/lists/get-memberships': 'application/json',
'users/notes': 'application/json',
'users/pages': 'application/json',
'users/flashs': 'application/json',
'users/reactions': 'application/json',
'users/recommendation': 'application/json',
'users/relation': 'application/json',
'users/report-abuse': 'application/json',
'users/search-by-username-and-host': 'application/json',
'users/search': 'application/json',
'users/show': 'application/json',
'users/achievements': 'application/json',
'users/update-memo': 'application/json',
'fetch-rss': 'application/json',
'fetch-external-resources': 'application/json',
'retention': 'application/json',
'bubble-game/register': 'application/json',
'bubble-game/ranking': 'application/json',
'reversi/cancel-match': 'application/json',
'reversi/games': 'application/json',
'reversi/match': 'application/json',
'reversi/invitations': 'application/json',
'reversi/show-game': 'application/json',
'reversi/surrender': 'application/json',
'reversi/verify': 'application/json',
};

View File

@@ -4299,7 +4299,7 @@ export type components = {
id: string;
/** Format: date-time */
createdAt: string;
/** @example lenna.jpg */
/** @example 192.jpg */
name: string;
/** @example image/jpeg */
type: string;
@@ -4787,6 +4787,7 @@ export type components = {
canHideAds: boolean;
driveCapacityMb: number;
alwaysMarkNsfw: boolean;
canUpdateBioMedia: boolean;
pinLimit: number;
antennaLimit: number;
wordMuteLimit: number;
@@ -6800,7 +6801,7 @@ export type operations = {
* @example 15eca7fba0480996e2245f5185bf39f2
*/
md5: string;
/** @example lenna.jpg */
/** @example 192.jpg */
name: string;
/** @example image/jpeg */
type: string;
@@ -13851,7 +13852,7 @@ export type operations = {
* Format: binary
* @description The file contents.
*/
file: string;
file: Blob;
};
};
};

View File

@@ -1,5 +1,14 @@
import { ModerationLogPayloads } from './consts.js';
import { Announcement, EmojiDetailed, MeDetailed, Page, User, UserDetailedNotMe } from './autogen/models.js';
import {
Announcement,
EmojiDetailed,
MeDetailed,
Page,
Role,
RolePolicies,
User,
UserDetailedNotMe
} from './autogen/models.js';
export * from './autogen/entities.js';
export * from './autogen/models.js';
@@ -236,3 +245,7 @@ export type SigninResponse = {
id: User['id'],
i: string,
};
type Values<T extends Record<PropertyKey, unknown>> = T[keyof T];
export type PartialRolePolicyOverride = Partial<{[k in keyof RolePolicies]: Omit<Values<Role['policies']>, 'value'> & { value: RolePolicies[k] }}>;

View File

@@ -291,7 +291,9 @@ export abstract class Connection<Channel extends AnyOf<Channels> = any> extends
this.stream = stream;
this.channel = channel;
this.name = name;
if (name !== undefined) {
this.name = name;
}
}
public send<T extends keyof Channel['receives']>(type: T, body: Channel['receives'][T]): void {

View File

@@ -5,13 +5,19 @@ enableFetchMocks();
function getFetchCall(call: any[]) {
const { body, method } = call[1];
if (body != null && typeof body != 'string') {
const contentType = call[1].headers['Content-Type'];
if (
body == null ||
(contentType === 'application/json' && typeof body !== 'string') ||
(contentType === 'multipart/form-data' && !(body instanceof FormData))
) {
throw new Error('invalid body');
}
return {
url: call[0],
method: method,
body: JSON.parse(body as any)
contentType: contentType,
body: body instanceof FormData ? Object.fromEntries(body.entries()) : JSON.parse(body),
};
}
@@ -45,6 +51,7 @@ describe('API', () => {
expect(getFetchCall(fetchMock.mock.calls[0])).toEqual({
url: 'https://misskey.test/api/i',
method: 'POST',
contentType: 'application/json',
body: { i: 'TOKEN' }
});
});
@@ -78,10 +85,52 @@ describe('API', () => {
expect(getFetchCall(fetchMock.mock.calls[0])).toEqual({
url: 'https://misskey.test/api/notes/show',
method: 'POST',
contentType: 'application/json',
body: { i: 'TOKEN', noteId: 'aaaaa' }
});
});
test('multipart/form-data', async () => {
fetchMock.resetMocks();
fetchMock.mockResponse(async (req) => {
if (req.method == 'POST' && req.url == 'https://misskey.test/api/drive/files/create') {
if (req.headers.get('Content-Type')?.includes('multipart/form-data')) {
return JSON.stringify({ id: 'foo' });
} else {
return { status: 400 };
}
} else {
return { status: 404 };
}
});
const cli = new APIClient({
origin: 'https://misskey.test',
credential: 'TOKEN',
});
const testFile = new File([], 'foo.txt');
const res = await cli.request('drive/files/create', {
file: testFile,
name: null, // nullのパラメータは消える
});
expect(res).toEqual({
id: 'foo'
});
expect(getFetchCall(fetchMock.mock.calls[0])).toEqual({
url: 'https://misskey.test/api/drive/files/create',
method: 'POST',
contentType: 'multipart/form-data',
body: {
i: 'TOKEN',
file: testFile,
}
});
});
test('204 No Content で null が返る', async () => {
fetchMock.resetMocks();
fetchMock.mockResponse(async (req) => {
@@ -104,6 +153,7 @@ describe('API', () => {
expect(getFetchCall(fetchMock.mock.calls[0])).toEqual({
url: 'https://misskey.test/api/reset-password',
method: 'POST',
contentType: 'application/json',
body: { i: 'TOKEN', token: 'aaa', password: 'aaa' }
});
});
@@ -209,4 +259,42 @@ describe('API', () => {
expect(isAPIError(e)).toEqual(false);
}
});
test('admin/roles/create の型が合う', async() => {
fetchMock.resetMocks();
fetchMock.mockResponse(async () => {
return {
// 本来返すべき値は`Role`型だが、テストなのでお茶を濁す
status: 200,
body: '{}'
};
});
const cli = new APIClient({
origin: 'https://misskey.test',
credential: 'TOKEN',
});
await cli.request('admin/roles/create', {
name: 'aaa',
asBadge: false,
canEditMembersByModerator: false,
color: '#123456',
condFormula: {},
description: '',
displayOrder: 0,
iconUrl: '',
isAdministrator: false,
isExplorable: false,
isModerator: false,
isPublic: false,
policies: {
ltlAvailable: {
value: true,
priority: 0,
useDefault: false,
},
},
target: 'manual',
});
})
});

View File

@@ -15,6 +15,7 @@
"experimentalDecorators": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"exactOptionalPropertyTypes": true,
"typeRoots": [
"./node_modules/@types"
],