diff --git a/packages/misskey-js/api-extractor.json b/packages/misskey-js/api-extractor.json index 9659d250df..0961dd24b9 100644 --- a/packages/misskey-js/api-extractor.json +++ b/packages/misskey-js/api-extractor.json @@ -79,7 +79,7 @@ * SUPPORTED TOKENS: , , * DEFAULT VALUE: "/tsconfig.json" */ - "tsconfigFilePath": "/tsconfig.lib.json", + "tsconfigFilePath": "/src/tsconfig.json", /** * Provides a compiler configuration that will be used instead of reading the tsconfig.json file from disk. * The object must conform to the TypeScript tsconfig schema: diff --git a/packages/misskey-js/eslint.config.js b/packages/misskey-js/eslint.config.js index 8c3d08fc5b..e205054a3b 100644 --- a/packages/misskey-js/eslint.config.js +++ b/packages/misskey-js/eslint.config.js @@ -8,11 +8,10 @@ export default [ { ignores: [ 'generator', - '**/lib/', - '**/temp/', - '**/built/', - '**/coverage/', - '**/node_modules/', + 'temp', + 'built', + 'coverage', + 'node_modules', ], }, { @@ -20,7 +19,7 @@ export default [ languageOptions: { parserOptions: { parser: tsParser, - project: ['./tsconfig.lib.json'], + project: ['src/tsconfig.json'], sourceType: 'module', tsconfigRootDir: import.meta.dirname, }, @@ -31,7 +30,7 @@ export default [ languageOptions: { parserOptions: { parser: tsParser, - projectService: ['./tsconfig.test.json'], + projectService: ['test/tsconfig.json'], sourceType: 'module', tsconfigRootDir: import.meta.dirname, }, @@ -42,18 +41,18 @@ export default [ languageOptions: { parserOptions: { parser: tsParser, - projectService: ['./tsconfig.test-d.json'], + projectService: ['test-d/tsconfig.json'], sourceType: 'module', tsconfigRootDir: import.meta.dirname, }, }, }, { - files: ['*.ts', '*.js', 'scripts/**/*'], + files: ['*.ts', '*.js', 'scripts/**/*.ts', 'scripts/**/*.js', 'scripts/**/*.mjs', 'scripts/**/*.cjs'], languageOptions: { parserOptions: { parser: tsParser, - project: ['./tsconfig.scripts.json'], + project: ['tsconfig.scripts.json'], sourceType: 'module', tsconfigRootDir: import.meta.dirname, }, diff --git a/packages/misskey-js/etc/misskey-js.api.md b/packages/misskey-js/etc/misskey-js.api.md index 4cbab42680..46bc9101ad 100644 --- a/packages/misskey-js/etc/misskey-js.api.md +++ b/packages/misskey-js/etc/misskey-js.api.md @@ -6,8 +6,8 @@ import type { AuthenticationResponseJSON } from '@simplewebauthn/types'; import { EventEmitter } from 'eventemitter3'; -import { Options } from 'reconnecting-websocket'; -import type { PublicKeyCredentialRequestOptionsJSON as PublicKeyCredentialRequestOptionsJSON_2 } from '@simplewebauthn/types'; +import type { Options } from 'reconnecting-websocket'; +import type { PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types'; import _ReconnectingWebSocket from 'reconnecting-websocket'; // Warning: (ae-forgotten-export) The symbol "components" needs to be exported by the entry point index.d.ts @@ -24,7 +24,7 @@ export type Acct = { declare namespace acct { export { parse, - toString_2 as toString, + toString, Acct } } @@ -155,21 +155,12 @@ type AdminCaptchaSaveRequest = operations['admin___captcha___save']['requestBody // @public (undocumented) type AdminCwInstanceRequest = operations['admin___cw-instance']['requestBody']['content']['application/json']; -// @public (undocumented) -type AdminCwInstanceResponse = operations['admin___cw-instance']['responses']['200']['content']['application/json']; - // @public (undocumented) type AdminCwNoteRequest = operations['admin___cw-note']['requestBody']['content']['application/json']; -// @public (undocumented) -type AdminCwNoteResponse = operations['admin___cw-note']['responses']['200']['content']['application/json']; - // @public (undocumented) type AdminCwUserRequest = operations['admin___cw-user']['requestBody']['content']['application/json']; -// @public (undocumented) -type AdminCwUserResponse = operations['admin___cw-user']['responses']['200']['content']['application/json']; - // @public (undocumented) type AdminDeclineUserRequest = operations['admin___decline-user']['requestBody']['content']['application/json']; @@ -568,6 +559,12 @@ class APIClient { fetch: FetchLike; // (undocumented) origin: string; + // Warning: (ae-forgotten-export) The symbol "EndpointsWithOptionalParams" needs to be exported by the entry point index.d.ts + // + // (undocumented) + request(endpoint: E, params?: Record, credential?: string | null): Promise>; + // (undocumented) + request(endpoint: E, params: P, credential?: string | null): Promise>; } // @public (undocumented) @@ -685,7 +682,7 @@ export type Channels = { main: { params: null; events: { - notification: (payload: Notification_2) => void; + notification: (payload: Notification) => void; mention: (payload: Note) => void; reply: (payload: Note) => void; renote: (payload: Note) => void; @@ -699,7 +696,7 @@ export type Channels = { file: DriveFile; }) => void; readAllNotifications: () => void; - unreadNotification: (payload: Notification_2) => void; + unreadNotification: (payload: Notification) => void; notificationFlushed: () => void; unreadAntenna: (payload: Antenna) => void; newChatMessage: (payload: ChatMessage) => void; @@ -1564,11 +1561,8 @@ declare namespace entities { AdminCaptchaCurrentResponse, AdminCaptchaSaveRequest, AdminCwInstanceRequest, - AdminCwInstanceResponse, AdminCwNoteRequest, - AdminCwNoteResponse, AdminCwUserRequest, - AdminCwUserResponse, AdminDeclineUserRequest, AdminDeleteAccountRequest, AdminDeleteAllFilesOfAUserRequest, @@ -1973,7 +1967,6 @@ declare namespace entities { IReadAnnouncementRequest, IRegenerateTokenRequest, IRegistryGetRequest, - IRegistryGetResponse, IRegistryGetAllRequest, IRegistryGetAllResponse, IRegistryGetDetailRequest, @@ -2211,7 +2204,7 @@ declare namespace entities { Note, NoteReaction, NoteFavorite, - Notification_2 as Notification, + Notification, DriveFile, DriveFolder, Following, @@ -2330,8 +2323,8 @@ type FetchExternalResourcesResponse = operations['fetch-external-resources']['re type FetchLike = (input: string, init?: { method?: string; body?: Blob | FormData | string; - credentials?: RequestCredentials; - cache?: RequestCache; + credentials?: 'include' | 'omit' | 'same-origin'; + cache?: 'default' | 'force-cache' | 'no-cache' | 'no-store' | 'only-if-cached' | 'reload'; headers: { [key in string]: string; }; @@ -2737,9 +2730,6 @@ type IRegistryGetDetailResponse = operations['i___registry___get-detail']['respo // @public (undocumented) type IRegistryGetRequest = operations['i___registry___get']['requestBody']['content']['application/json']; -// @public (undocumented) -type IRegistryGetResponse = operations['i___registry___get']['responses']['200']['content']['application/json']; - // @public (undocumented) type IRegistryGetUnsecureRequest = operations['i___registry___get-unsecure']['requestBody']['content']['application/json']; @@ -3366,7 +3356,7 @@ type NotesVersionsResponse = operations['notes___versions']['responses']['200'][ export const noteVisibilities: readonly ["public", "home", "followers", "specified"]; // @public (undocumented) -type Notification_2 = components['schemas']['Notification']; +type Notification = components['schemas']['Notification']; // @public (undocumented) type NotificationsCreateRequest = operations['notifications___create']['requestBody']['content']['application/json']; @@ -3649,12 +3639,12 @@ type SigninFlowResponse = { } | { finished: false; next: 'passkey'; - authRequest: PublicKeyCredentialRequestOptionsJSON_2; + authRequest: PublicKeyCredentialRequestOptionsJSON; }; // @public (undocumented) type SigninWithPasskeyInitResponse = { - option: PublicKeyCredentialRequestOptionsJSON_2; + option: PublicKeyCredentialRequestOptionsJSON; context: string; }; @@ -3785,7 +3775,7 @@ type TestRequest = operations['test']['requestBody']['content']['application/jso type TestResponse = operations['test']['responses']['200']['content']['application/json']; // @public (undocumented) -function toString_2(acct: Acct): string; +function toString(acct: Acct): string; // @public (undocumented) type User = components['schemas']['User']; @@ -3982,7 +3972,7 @@ type V2AdminEmojiListResponse = operations['v2___admin___emoji___list']['respons // Warnings were encountered during analysis: // // built/entities.d.ts:32:5 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts -// built/streaming.d.ts:39:9 - (ae-forgotten-export) The symbol "ReconnectingWebSocket" needs to be exported by the entry point index.d.ts +// built/streaming.d.ts:40:9 - (ae-forgotten-export) The symbol "ReconnectingWebSocket" needs to be exported by the entry point index.d.ts // built/streaming.types.d.ts:219:13 - (ae-forgotten-export) The symbol "ReversiUpdateKey" needs to be exported by the entry point index.d.ts // built/streaming.types.d.ts:233:13 - (ae-forgotten-export) The symbol "ReversiUpdateSettings" needs to be exported by the entry point index.d.ts diff --git a/packages/misskey-js/generator/eslint.config.js b/packages/misskey-js/generator/eslint.config.js index bb6fd7a6b3..970865b36b 100644 --- a/packages/misskey-js/generator/eslint.config.js +++ b/packages/misskey-js/generator/eslint.config.js @@ -33,7 +33,7 @@ export default [ languageOptions: { parserOptions: { parser: tsParser, - project: ['./jsconfig.scripts.json'], + project: ['./tsconfig.scripts.json'], sourceType: 'module', tsconfigRootDir: import.meta.dirname, }, diff --git a/packages/misskey-js/generator/jsconfig.scripts.json b/packages/misskey-js/generator/jsconfig.scripts.json deleted file mode 100644 index 5bf3d9a2d2..0000000000 --- a/packages/misskey-js/generator/jsconfig.scripts.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "extends": "../../shared/jsconfig.node.json", - "compilerOptions": { - "typeRoots": [ - "./node_modules/@types" - ] - }, - "include": [ - "*.js" - ], - "exclude": [ - "node_modules" - ] -} diff --git a/packages/misskey-js/generator/package.json b/packages/misskey-js/generator/package.json index d5fef55e44..91f3101362 100644 --- a/packages/misskey-js/generator/package.json +++ b/packages/misskey-js/generator/package.json @@ -10,7 +10,7 @@ "typecheck": "pnpm run typecheck:generator && pnpm run typecheck:autogen && pnpm run typecheck:scripts", "typecheck:generator": "tsc -p tsconfig.generator.json --noEmit", "typecheck:autogen": "tsc -p tsconfig.autogen.json --noEmit", - "typecheck:scripts": "tsc -p jsconfig.scripts.json --noEmit", + "typecheck:scripts": "tsc -p tsconfig.scripts.json --noEmit", "lint": "pnpm typecheck && pnpm eslint" }, "devDependencies": { diff --git a/packages/misskey-js/generator/tsconfig.autogen.json b/packages/misskey-js/generator/tsconfig.autogen.json index b143f440f1..038a07d107 100644 --- a/packages/misskey-js/generator/tsconfig.autogen.json +++ b/packages/misskey-js/generator/tsconfig.autogen.json @@ -1,9 +1,7 @@ { "$schema": "https://json.schemastore.org/tsconfig", - "extends": "../../shared/tsconfig.web.json", + "extends": "../../shared/tsconfig.lib.jsonc", "compilerOptions": { - "noImplicitAny": false, - "isolatedModules": false, "rootDirs": [ "built", "../built" diff --git a/packages/misskey-js/generator/tsconfig.generator.json b/packages/misskey-js/generator/tsconfig.generator.json index f7c54755fe..b1e8629b35 100644 --- a/packages/misskey-js/generator/tsconfig.generator.json +++ b/packages/misskey-js/generator/tsconfig.generator.json @@ -1,6 +1,6 @@ { "$schema": "https://json.schemastore.org/tsconfig", - "extends": "../../shared/tsconfig.node.json", + "extends": "../../shared/tsconfig.scripts.jsonc", "include": [ "src/**/*.ts" ], diff --git a/packages/misskey-js/generator/tsconfig.json b/packages/misskey-js/generator/tsconfig.json index 73a6ed5189..c078fb3f82 100644 --- a/packages/misskey-js/generator/tsconfig.json +++ b/packages/misskey-js/generator/tsconfig.json @@ -5,6 +5,6 @@ "references": [ { "path": "./tsconfig.generator.json" }, { "path": "./tsconfig.autogen.json" }, - { "path": "./jsconfig.scripts.json" } + { "path": "./tsconfig.scripts.json" } ] } diff --git a/packages/misskey-js/generator/tsconfig.scripts.json b/packages/misskey-js/generator/tsconfig.scripts.json new file mode 100644 index 0000000000..3150eb8969 --- /dev/null +++ b/packages/misskey-js/generator/tsconfig.scripts.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "../../shared/tsconfig.scripts.jsonc", + "include": [ + "*.js", + "*.ts" + ] +} diff --git a/packages/misskey-js/jest.config.ts b/packages/misskey-js/jest.config.ts index cca319c457..b12801c5d2 100644 --- a/packages/misskey-js/jest.config.ts +++ b/packages/misskey-js/jest.config.ts @@ -7,7 +7,7 @@ import { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'; const presetConfig = createDefaultEsmPreset({ - tsconfig: '/tsconfig.lib.json' + tsconfig: '/test/tsconfig.json', }); export default { @@ -32,7 +32,7 @@ export default { collectCoverageFrom: ['src/**/*.ts'], // The directory where Jest should output its coverage files - coverageDirectory: "coverage", + coverageDirectory: 'coverage', // An array of regexp pattern strings used to skip coverage collection // coveragePathIgnorePatterns: [ @@ -40,7 +40,7 @@ export default { // ], // Indicates which provider should be used to instrument code for coverage - coverageProvider: "v8", + coverageProvider: 'v8', // A list of reporter names that Jest uses when writing coverage reports // coverageReporters: [ @@ -90,8 +90,8 @@ export default { // "node" // ], moduleFileExtensions: [ - "ts", - "js" + 'ts', + 'js', ], // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module @@ -143,7 +143,7 @@ export default { // A list of paths to directories that Jest should use to search for files in roots: [ - "/test" + '/test', ], // Allows you to use a custom runner instead of Jest's default test runner @@ -162,7 +162,7 @@ export default { // snapshotSerializers: [], // The test environment that will be used for testing - testEnvironment: "node", + testEnvironment: 'node', // Options that will be passed to the testEnvironment // testEnvironmentOptions: {}, @@ -172,7 +172,7 @@ export default { // The glob patterns Jest uses to detect test files testMatch: [ - "/test/**/*.ts" + '/test/**/*.ts', ], // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped diff --git a/packages/misskey-js/package.json b/packages/misskey-js/package.json index 8c78d409bd..e3e0475c6f 100644 --- a/packages/misskey-js/package.json +++ b/packages/misskey-js/package.json @@ -8,17 +8,17 @@ "types": "./built/index.d.ts", "scripts": { "clean": "node scripts/clean.mjs", - "build": "tsc -p tsconfig.lib.json && node scripts/post-build.mjs", - "rebuild": "pnpm clean && pnpm build", + "build": "tsc -p src/tsconfig.json && node scripts/post-build.mjs", + "rebuild": "pnpm run clean && pnpm run build", "tsd": "tsd --types \"./temp/built/src/index.d.ts\" --files \"./temp/built/test-d/**/*.ts\"", "api": "pnpm api-extractor run --local --verbose", "api-prod": "pnpm api-extractor run --verbose", "eslint": "eslint --quiet --cache -c eslint.config.js .", "typecheck-all": "pnpm run --no-bail typecheck:lib && pnpm run --no-bail typecheck:test && pnpm run --no-bail typecheck:test-d && pnpm run --no-bail typecheck:scripts", "typecheck": "pnpm run typecheck:lib && pnpm run typecheck:test && pnpm run typecheck:test-d && pnpm run typecheck:scripts", - "typecheck:lib": "tsc -p tsconfig.lib.json --noEmit", - "typecheck:test": "tsc -p tsconfig.test.json --noEmit", - "typecheck:test-d": "tsc -p tsconfig.test-d.json --noEmit", + "typecheck:lib": "tsc -p src/tsconfig.json --noEmit", + "typecheck:test": "tsc -p test/tsconfig.json --noEmit", + "typecheck:test-d": "tsc -p test-d/tsconfig.json --noEmit", "typecheck:scripts": "tsc -p tsconfig.scripts.json --noEmit", "lint": "pnpm typecheck && pnpm eslint", "jest": "node --no-experimental-require-module --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --coverage --detectOpenHandles", diff --git a/packages/misskey-js/scripts/post-build.mjs b/packages/misskey-js/scripts/post-build.mjs index 142e95ab4e..66b290e029 100644 --- a/packages/misskey-js/scripts/post-build.mjs +++ b/packages/misskey-js/scripts/post-build.mjs @@ -4,14 +4,16 @@ */ import { libBuild, outDir, testDBuild, testDSource } from './_common.mjs'; -import { rm, cp } from 'fs/promises'; +import { rm, cp, mkdir } from 'fs/promises'; // Always clean the output, because artifacts are cached in the build directory instead. console.log(`Cleaning output directory ${outDir}...`); await rm(outDir, { recursive: true, force: true }); // Copy built lib to output directory. +await mkdir(outDir, { recursive: true }); await cp(libBuild, outDir, { recursive: true }); // Stage test-d sources in the build directory so tsd will work. +await mkdir(testDBuild, { recursive: true }); await cp(testDSource, testDBuild, { recursive: true }); diff --git a/packages/misskey-js/src/acct.ts b/packages/misskey-js/src/acct.ts index aa8658cdbd..627eb38d2a 100644 --- a/packages/misskey-js/src/acct.ts +++ b/packages/misskey-js/src/acct.ts @@ -6,7 +6,7 @@ export type Acct = { export function parse(_acct: string): Acct { let acct = _acct; if (acct.startsWith('@')) acct = acct.substring(1); - const split = acct.split('@', 2); + const split = acct.split('@', 2) as [string, ...string[]]; return { username: split[0], host: split[1] || null }; } diff --git a/packages/misskey-js/src/api.ts b/packages/misskey-js/src/api.ts index 4b26cb55e7..860e5fc0a4 100644 --- a/packages/misskey-js/src/api.ts +++ b/packages/misskey-js/src/api.ts @@ -1,7 +1,6 @@ -import './autogen/apiClientJSDoc.js'; - import { endpointReqTypes } from './autogen/endpoint.js'; -import type { SwitchCaseResponseType, Endpoints } from './api.types.js'; +import type { SwitchCaseResponseType, Endpoints, EndpointsWithOptionalParams } from './api.types.js'; +import type { EmptyRequest } from './autogen/entities.js'; export type { SwitchCaseResponseType, @@ -29,8 +28,8 @@ export function isAPIError(reason: unknown): reason is APIError { export type FetchLike = (input: string, init?: { method?: string; body?: Blob | FormData | string; - credentials?: RequestCredentials; - cache?: RequestCache; + credentials?: 'include' | 'omit' | 'same-origin'; + cache?: 'default' | 'force-cache' | 'no-cache' | 'no-store' | 'only-if-cached' | 'reload'; headers: { [key in string]: string } }) => Promise<{ status: number; @@ -64,7 +63,17 @@ export class APIClient { return ep in endpointReqTypes; } - public request( + public request( + endpoint: E, + params?: Record, + credential?: string | null, + ): Promise>; + public request( + endpoint: E, + params: P, + credential?: string | null, + ): Promise>; + public request( endpoint: E, params: P = {} as P, credential?: string | null, diff --git a/packages/misskey-js/src/api.types.ts b/packages/misskey-js/src/api.types.ts index e20a2e355d..17f71a7111 100644 --- a/packages/misskey-js/src/api.types.ts +++ b/packages/misskey-js/src/api.types.ts @@ -1,6 +1,11 @@ import type { Endpoints as Gen } from './autogen/endpoint.js'; import type { UserDetailed } from './autogen/models.js'; -import type { AdminRolesCreateRequest, AdminRolesCreateResponse, UsersShowRequest } from './autogen/entities.js'; +import type { + AdminRolesCreateRequest, + AdminRolesCreateResponse, + UsersShowRequest, + EmptyRequest, +} from './autogen/entities.js'; import type { PartialRolePolicyOverride, SigninFlowRequest, @@ -109,3 +114,7 @@ export type Endpoints = Overwrite< } } >; + +export type EndpointsWithOptionalParams = { + [E in keyof Endpoints]: EmptyRequest extends Endpoints[E]['req'] ? Endpoints[E] : never; +}; diff --git a/packages/misskey-js/src/autogen/apiClientJSDoc.ts b/packages/misskey-js/src/autogen/apiClientJSDoc.ts index 0212fd30d6..7555fabe2f 100644 --- a/packages/misskey-js/src/autogen/apiClientJSDoc.ts +++ b/packages/misskey-js/src/autogen/apiClientJSDoc.ts @@ -257,7 +257,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -356,7 +356,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -588,7 +588,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -599,7 +599,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -610,7 +610,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -654,7 +654,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -698,7 +698,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -709,7 +709,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -753,7 +753,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -797,7 +797,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -830,7 +830,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -929,7 +929,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -1006,7 +1006,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -1287,7 +1287,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -1364,7 +1364,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -1508,7 +1508,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -1541,7 +1541,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2069,7 +2069,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2080,7 +2080,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2146,7 +2146,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2366,7 +2366,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2388,7 +2388,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2400,7 +2400,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2731,7 +2731,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2819,7 +2819,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2830,7 +2830,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2874,7 +2874,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -2896,7 +2896,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3063,7 +3063,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3075,7 +3075,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3087,7 +3087,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3099,7 +3099,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3111,7 +3111,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3135,7 +3135,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3147,7 +3147,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3159,7 +3159,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3443,7 +3443,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3569,7 +3569,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3614,7 +3614,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -3636,7 +3636,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4165,7 +4165,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4176,7 +4176,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4187,7 +4187,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4232,7 +4232,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4287,7 +4287,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4364,7 +4364,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4386,7 +4386,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4419,7 +4419,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4474,7 +4474,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4518,7 +4518,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; @@ -4540,7 +4540,7 @@ declare module '../api.js' { */ request( endpoint: E, - params: P, + params?: P, credential?: string | null, ): Promise>; diff --git a/packages/misskey-js/src/autogen/endpoint.ts b/packages/misskey-js/src/autogen/endpoint.ts index f4f944dda2..a8c4bceecb 100644 --- a/packages/misskey-js/src/autogen/endpoint.ts +++ b/packages/misskey-js/src/autogen/endpoint.ts @@ -39,11 +39,8 @@ import type { AdminCaptchaCurrentResponse, AdminCaptchaSaveRequest, AdminCwInstanceRequest, - AdminCwInstanceResponse, AdminCwNoteRequest, - AdminCwNoteResponse, AdminCwUserRequest, - AdminCwUserResponse, AdminDeclineUserRequest, AdminDeleteAccountRequest, AdminDeleteAllFilesOfAUserRequest, @@ -448,7 +445,6 @@ import type { IReadAnnouncementRequest, IRegenerateTokenRequest, IRegistryGetRequest, - IRegistryGetResponse, IRegistryGetAllRequest, IRegistryGetAllResponse, IRegistryGetDetailRequest, @@ -700,9 +696,9 @@ export type Endpoints = { 'admin/avatar-decorations/update': { req: AdminAvatarDecorationsUpdateRequest; res: EmptyResponse }; 'admin/captcha/current': { req: EmptyRequest; res: AdminCaptchaCurrentResponse }; 'admin/captcha/save': { req: AdminCaptchaSaveRequest; res: EmptyResponse }; - 'admin/cw-instance': { req: AdminCwInstanceRequest; res: AdminCwInstanceResponse }; - 'admin/cw-note': { req: AdminCwNoteRequest; res: AdminCwNoteResponse }; - 'admin/cw-user': { req: AdminCwUserRequest; res: AdminCwUserResponse }; + 'admin/cw-instance': { req: AdminCwInstanceRequest; res: EmptyResponse }; + 'admin/cw-note': { req: AdminCwNoteRequest; res: EmptyResponse }; + 'admin/cw-user': { req: AdminCwUserRequest; res: EmptyResponse }; 'admin/decline-user': { req: AdminDeclineUserRequest; res: EmptyResponse }; 'admin/delete-account': { req: AdminDeleteAccountRequest; res: EmptyResponse }; 'admin/delete-all-files-of-a-user': { req: AdminDeleteAllFilesOfAUserRequest; res: EmptyResponse }; @@ -977,7 +973,7 @@ export type Endpoints = { 'i/pin': { req: IPinRequest; res: IPinResponse }; 'i/read-announcement': { req: IReadAnnouncementRequest; res: EmptyResponse }; 'i/regenerate-token': { req: IRegenerateTokenRequest; res: EmptyResponse }; - 'i/registry/get': { req: IRegistryGetRequest; res: IRegistryGetResponse }; + 'i/registry/get': { req: IRegistryGetRequest; res: EmptyResponse }; 'i/registry/get-all': { req: IRegistryGetAllRequest; res: IRegistryGetAllResponse }; 'i/registry/get-detail': { req: IRegistryGetDetailRequest; res: IRegistryGetDetailResponse }; 'i/registry/get-unsecure': { req: IRegistryGetUnsecureRequest; res: EmptyResponse }; diff --git a/packages/misskey-js/src/autogen/entities.ts b/packages/misskey-js/src/autogen/entities.ts index b060f5817b..0049c5c090 100644 --- a/packages/misskey-js/src/autogen/entities.ts +++ b/packages/misskey-js/src/autogen/entities.ts @@ -42,11 +42,8 @@ export type AdminAvatarDecorationsUpdateRequest = operations['admin___avatar-dec export type AdminCaptchaCurrentResponse = operations['admin___captcha___current']['responses']['200']['content']['application/json']; export type AdminCaptchaSaveRequest = operations['admin___captcha___save']['requestBody']['content']['application/json']; export type AdminCwInstanceRequest = operations['admin___cw-instance']['requestBody']['content']['application/json']; -export type AdminCwInstanceResponse = operations['admin___cw-instance']['responses']['200']['content']['application/json']; export type AdminCwNoteRequest = operations['admin___cw-note']['requestBody']['content']['application/json']; -export type AdminCwNoteResponse = operations['admin___cw-note']['responses']['200']['content']['application/json']; export type AdminCwUserRequest = operations['admin___cw-user']['requestBody']['content']['application/json']; -export type AdminCwUserResponse = operations['admin___cw-user']['responses']['200']['content']['application/json']; export type AdminDeclineUserRequest = operations['admin___decline-user']['requestBody']['content']['application/json']; export type AdminDeleteAccountRequest = operations['admin___delete-account']['requestBody']['content']['application/json']; export type AdminDeleteAllFilesOfAUserRequest = operations['admin___delete-all-files-of-a-user']['requestBody']['content']['application/json']; @@ -451,7 +448,6 @@ export type IPinResponse = operations['i___pin']['responses']['200']['content'][ export type IReadAnnouncementRequest = operations['i___read-announcement']['requestBody']['content']['application/json']; export type IRegenerateTokenRequest = operations['i___regenerate-token']['requestBody']['content']['application/json']; export type IRegistryGetRequest = operations['i___registry___get']['requestBody']['content']['application/json']; -export type IRegistryGetResponse = operations['i___registry___get']['responses']['200']['content']['application/json']; export type IRegistryGetAllRequest = operations['i___registry___get-all']['requestBody']['content']['application/json']; export type IRegistryGetAllResponse = operations['i___registry___get-all']['responses']['200']['content']['application/json']; export type IRegistryGetDetailRequest = operations['i___registry___get-detail']['requestBody']['content']['application/json']; diff --git a/packages/misskey-js/src/autogen/types.ts b/packages/misskey-js/src/autogen/types.ts index 5efc5a830f..d5295a2dc8 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -13595,14 +13595,12 @@ export interface operations { }; }; responses: { - /** @description OK (with results) */ - 200: { + /** @description OK (without any results) */ + 204: { headers: { [name: string]: unknown; }; - content: { - 'application/json': unknown; - }; + content?: never; }; /** @description Client error */ 400: { @@ -13668,14 +13666,12 @@ export interface operations { }; }; responses: { - /** @description OK (with results) */ - 200: { + /** @description OK (without any results) */ + 204: { headers: { [name: string]: unknown; }; - content: { - 'application/json': unknown; - }; + content?: never; }; /** @description Client error */ 400: { @@ -13741,14 +13737,12 @@ export interface operations { }; }; responses: { - /** @description OK (with results) */ - 200: { + /** @description OK (without any results) */ + 204: { headers: { [name: string]: unknown; }; - content: { - 'application/json': unknown; - }; + content?: never; }; /** @description Client error */ 400: { @@ -14242,7 +14236,7 @@ export interface operations { /** Format: misskey:id */ fileId?: string; url?: string; - } | unknown | unknown; + }; }; }; responses: { @@ -15275,7 +15269,7 @@ export interface operations { isSensitive?: boolean; localOnly?: boolean; roleIdsThatCanBeUsedThisEmojiAsReaction?: string[]; - } | unknown | unknown; + }; }; }; responses: { @@ -27957,7 +27951,7 @@ export interface operations { /** Format: misskey:id */ fileId?: string; url?: string; - } | unknown | unknown; + }; }; }; responses: { @@ -36226,14 +36220,12 @@ export interface operations { }; }; responses: { - /** @description OK (with results) */ - 200: { + /** @description OK (without any results) */ + 204: { headers: { [name: string]: unknown; }; - content: { - 'application/json': unknown; - }; + content?: never; }; /** @description Client error */ 400: { @@ -36958,7 +36950,7 @@ export interface operations { /** Format: misskey:id */ tokenId?: string; token?: string | null; - } | unknown | unknown; + }; }; }; responses: { @@ -37257,145 +37249,25 @@ export interface operations { chatScope?: 'everyone' | 'followers' | 'following' | 'mutual' | 'none'; /** Format: misskey:id */ pinnedPageId?: string | null; - mutedWords?: (string[] | string)[]; - hardMutedWords?: (string[] | string)[]; + mutedWords?: unknown[]; + hardMutedWords?: unknown[]; mutedInstances?: string[]; notificationRecieveConfig?: { - note?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - follow?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - mention?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - reply?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - renote?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - quote?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - reaction?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - pollEnded?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - receiveFollowRequest?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - followRequestAccepted?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - roleAssigned?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - chatRoomInvitationReceived?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - achievementEarned?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - app?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; - test?: { - /** @enum {string} */ - type: 'all' | 'following' | 'follower' | 'mutualFollow' | 'followingOrFollower' | 'never'; - } | { - /** @enum {string} */ - type: 'list'; - /** Format: misskey:id */ - userListId: string; - }; + note?: Record; + follow?: Record; + mention?: Record; + reply?: Record; + renote?: Record; + quote?: Record; + reaction?: Record; + pollEnded?: Record; + receiveFollowRequest?: Record; + followRequestAccepted?: Record; + roleAssigned?: Record; + chatRoomInvitationReceived?: Record; + achievementEarned?: Record; + app?: Record; + test?: Record; }; emailNotificationTypes?: string[]; alsoKnownAs?: string[]; @@ -41160,7 +41032,7 @@ export interface operations { scheduleNote: { scheduledAt?: number; }; - } | unknown | unknown | unknown | unknown | unknown; + }; }; }; responses: { @@ -41545,7 +41417,7 @@ export interface operations { tag?: string; /** @description The outer arrays are chained with OR, the inner arrays are chained with AND. */ query?: string[][]; - } | unknown | unknown; + }; }; }; responses: { @@ -43110,7 +42982,7 @@ export interface operations { pageId?: string; name?: string; username?: string; - } | unknown | unknown; + }; }; }; responses: { @@ -46301,7 +46173,7 @@ export interface operations { username?: string; /** @description The local host is represented with `null`. */ host?: string | null; - } | unknown | unknown; + }; }; }; responses: { @@ -46392,7 +46264,7 @@ export interface operations { /** @description The local host is represented with `null`. */ host?: string | null; birthday?: string | null; - } | unknown | unknown; + }; }; }; responses: { @@ -48002,7 +47874,7 @@ export interface operations { requestBody: { content: { 'application/json': { - userId: string | string[]; + userId: unknown; }; }; }; @@ -48285,7 +48157,7 @@ export interface operations { detail?: boolean; username?: string | null; host?: string | null; - } | unknown | unknown; + }; }; }; responses: { @@ -48372,7 +48244,7 @@ export interface operations { host?: string | null; /** @default true */ detail?: boolean; - } | unknown | unknown | unknown; + }; }; }; responses: { diff --git a/packages/misskey-js/src/consts.ts b/packages/misskey-js/src/consts.ts index 37be439eda..0b7f8f4eac 100644 --- a/packages/misskey-js/src/consts.ts +++ b/packages/misskey-js/src/consts.ts @@ -9,7 +9,6 @@ import type { Role, ReversiGameDetailed, SystemWebhook, - UserLite, ChatRoom, } from './autogen/models.js'; diff --git a/packages/misskey-js/src/streaming.ts b/packages/misskey-js/src/streaming.ts index bc3650ab5d..3898ae66a3 100644 --- a/packages/misskey-js/src/streaming.ts +++ b/packages/misskey-js/src/streaming.ts @@ -3,9 +3,8 @@ import ReconnectingWebSocket from 'reconnecting-websocket'; import type { Options } from 'reconnecting-websocket'; import type { BroadcastEvents, Channels } from './streaming.types.js'; -// // コンストラクタとクラスそのものの定義が上手く解決出来ないため再定義 -// const ReconnectingWebSocketConstructor = _ReconnectingWebSocket.default; -// type ReconnectingWebSocket = _ReconnectingWebSocket.default; +// コンストラクタとクラスそのものの定義が上手く解決出来ないため再定義 +const ReconnectingWebSocketConstructor = ReconnectingWebSocket as unknown as typeof ReconnectingWebSocket.default; export function urlQuery(obj: Record): string { const params = Object.entries(obj) @@ -46,7 +45,7 @@ export interface IStream extends EventEmitter { */ // eslint-disable-next-line import/no-default-export export default class Stream extends EventEmitter implements IStream { - private stream: ReconnectingWebSocket; + private stream: ReconnectingWebSocket.default; public state: 'initializing' | 'reconnecting' | 'connected' = 'initializing'; private sharedConnectionPools: Pool[] = []; private sharedConnections: SharedConnection[] = []; @@ -55,7 +54,7 @@ export default class Stream extends EventEmitter implements IStrea constructor(origin: string, user: { token: string; } | null, options?: { WebSocket?: Options['WebSocket']; - binaryType?: ReconnectingWebSocket['binaryType']; + binaryType?: 'arraybuffer' | 'blob'; }) { super(); @@ -84,7 +83,7 @@ export default class Stream extends EventEmitter implements IStrea const wsOrigin = origin.replace('http://', 'ws://').replace('https://', 'wss://'); - this.stream = new ReconnectingWebSocket(`${wsOrigin}/streaming?${query}`, '', { + this.stream = new ReconnectingWebSocketConstructor(`${wsOrigin}/streaming?${query}`, '', { minReconnectionDelay: 1, // https://github.com/pladaria/reconnecting-websocket/issues/91 WebSocket: options.WebSocket, }); diff --git a/packages/misskey-js/src/tsconfig.json b/packages/misskey-js/src/tsconfig.json new file mode 100644 index 0000000000..3b5903046c --- /dev/null +++ b/packages/misskey-js/src/tsconfig.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "../../shared/tsconfig.lib.jsonc", + "compilerOptions": { + // Checking + "exactOptionalPropertyTypes": true, + + // Output + "outDir": "../temp/built/src", + "tsBuildInfoFile": "../temp/built/src/tsconfig.lib.tsbuildinfo" + }, + "include": [ + "**/*" + ] +} diff --git a/packages/misskey-js/test-d/api.ts b/packages/misskey-js/test-d/api.ts index ca6d8dcb88..1bd5829645 100644 --- a/packages/misskey-js/test-d/api.ts +++ b/packages/misskey-js/test-d/api.ts @@ -5,7 +5,7 @@ describe('API', () => { test('success', async () => { const cli = new Misskey.api.APIClient({ origin: 'https://misskey.test', - credential: 'TOKEN' + credential: 'TOKEN', }); const res = await cli.request('meta', { detail: true }); expectType(res); @@ -14,7 +14,7 @@ describe('API', () => { test('conditional response type (meta)', async () => { const cli = new Misskey.api.APIClient({ origin: 'https://misskey.test', - credential: 'TOKEN' + credential: 'TOKEN', }); const res = await cli.request('meta', { detail: true }); @@ -33,7 +33,7 @@ describe('API', () => { test('conditional response type (users/show)', async () => { const cli = new Misskey.api.APIClient({ origin: 'https://misskey.test', - credential: 'TOKEN' + credential: 'TOKEN', }); const res = await cli.request('users/show', { userId: 'xxxxxxxx' }); diff --git a/packages/misskey-js/test-d/tsconfig.json b/packages/misskey-js/test-d/tsconfig.json new file mode 100644 index 0000000000..b3009a01c3 --- /dev/null +++ b/packages/misskey-js/test-d/tsconfig.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "../../shared/tsconfig.lib.jsonc", + "compilerOptions": { + "outDir": "../temp/built/test-d/", + "rootDir": "." + }, + "references": [ + { "path": "../src/tsconfig.json" } + ], + "include": [ + "**/*" + ] +} diff --git a/packages/misskey-js/test/api.ts b/packages/misskey-js/test/api.ts index 856d167113..62499b1c3f 100644 --- a/packages/misskey-js/test/api.ts +++ b/packages/misskey-js/test/api.ts @@ -1,9 +1,12 @@ -import fetchMock from 'jest-fetch-mock'; +import _fetchMock from 'jest-fetch-mock'; import { APIClient, isAPIError } from '../src/api.js'; +import type { Endpoints } from '../src/index.js'; -fetchMock.enableMocks(); +_fetchMock.enableFetchMocks(); +const fetchMock = _fetchMock.default; -function getFetchCall(call: any[]) { +function getFetchCall(call: any[] | undefined) { + if (!call) return undefined; const { body, method } = call[1]; const contentType = call[1].headers['Content-Type']; if ( @@ -25,7 +28,7 @@ describe('API', () => { test('success', async () => { fetchMock.resetMocks(); fetchMock.mockResponse(async (req) => { - const body = await req.json(); + const body = await req.json() as Record; if (req.method === 'POST' && req.url === 'https://misskey.test/api/i') { if (body.i === 'TOKEN') { return JSON.stringify({ id: 'foo' }); @@ -59,7 +62,7 @@ describe('API', () => { test('with params', async () => { fetchMock.resetMocks(); fetchMock.mockResponse(async (req) => { - const body = await req.json(); + const body = await req.json() as Record; if (req.method === 'POST' && req.url === 'https://misskey.test/api/notes/show') { if (body.i === 'TOKEN' && body.noteId === 'aaaaa') { return JSON.stringify({ id: 'foo' }); @@ -161,7 +164,7 @@ describe('API', () => { test('インスタンスの credential が指定されていても引数で credential が null ならば null としてリクエストされる', async () => { fetchMock.resetMocks(); fetchMock.mockResponse(async (req) => { - const body = await req.json(); + const body = await req.json() as Record; if (req.method === 'POST' && req.url === 'https://misskey.test/api/i') { if (typeof body.i === 'string') { return JSON.stringify({ id: 'foo' }); @@ -196,7 +199,7 @@ describe('API', () => { test('api error', async () => { fetchMock.resetMocks(); - fetchMock.mockResponse(async (req) => { + fetchMock.mockResponse(async () => { return { status: 500, body: JSON.stringify({ @@ -241,7 +244,7 @@ describe('API', () => { test('json parse error', async () => { fetchMock.resetMocks(); - fetchMock.mockResponse(async (req) => { + fetchMock.mockResponse(async () => { return { status: 500, body: 'I AM NOT JSON', @@ -274,7 +277,7 @@ describe('API', () => { origin: 'https://misskey.test', credential: 'TOKEN', }); - await cli.request('admin/roles/create', { + await cli.request<'admin/roles/create', Endpoints['admin/roles/create']['req']>('admin/roles/create', { name: 'aaa', asBadge: false, canEditMembersByModerator: false, diff --git a/packages/misskey-js/test/tsconfig.json b/packages/misskey-js/test/tsconfig.json new file mode 100644 index 0000000000..bf98f76319 --- /dev/null +++ b/packages/misskey-js/test/tsconfig.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "../../shared/tsconfig.lib.jsonc", + "compilerOptions": { + // Checking + "rootDir": ".", + + // Output + "outDir": "../temp/built/test/" + }, + "references": [ + { "path": "../src/tsconfig.json" } + ], + "include": [ + "**/*" + ] +} diff --git a/packages/misskey-js/tsconfig.json b/packages/misskey-js/tsconfig.json index 207df95f9b..32ab78c967 100644 --- a/packages/misskey-js/tsconfig.json +++ b/packages/misskey-js/tsconfig.json @@ -3,9 +3,9 @@ "files": [], // WebStorm only reads one tsconfig per directory, so this tricks it into loading both. "references": [ - { "path": "./tsconfig.lib.json" }, - { "path": "./tsconfig.test.json" }, - { "path": "./tsconfig.test-d.json" }, + { "path": "./src/tsconfig.json" }, + { "path": "./test/tsconfig.json" }, + { "path": "./test-d/tsconfig.json" }, { "path": "./tsconfig.scripts.json" } ] } diff --git a/packages/misskey-js/tsconfig.lib.json b/packages/misskey-js/tsconfig.lib.json deleted file mode 100644 index 95279184fa..0000000000 --- a/packages/misskey-js/tsconfig.lib.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "extends": "../shared/tsconfig.web.json", - "compilerOptions": { - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "inlineSources": true, - "outDir": "./temp/built/", - "rootDir": ".", - "exactOptionalPropertyTypes": true, - "composite": true, - "typeRoots": [ - "./node_modules/@types" - ] - }, - "include": [ - "src/**/*", - "test/**/*", - "test-d/**/*" - ], - "exclude": [ - "node_modules" - ] -} diff --git a/packages/misskey-js/tsconfig.scripts.json b/packages/misskey-js/tsconfig.scripts.json index c1969bd759..30e19775e9 100644 --- a/packages/misskey-js/tsconfig.scripts.json +++ b/packages/misskey-js/tsconfig.scripts.json @@ -1,15 +1,18 @@ { "$schema": "https://json.schemastore.org/tsconfig", - "extends": "../shared/tsconfig.node.json", + "extends": "../shared/tsconfig.scripts.jsonc", "compilerOptions": { - "noImplicitAny": false + "rootDirs": [ + "./scripts", + "." + ] }, "include": [ "*.ts", "*.js", - "scripts/**/*" - ], - "exclude": [ - "node_modules" + "scripts/**/*.ts", + "scripts/**/*.js", + "scripts/**/*.mjs", + "scripts/**/*.cjs" ] } diff --git a/packages/misskey-js/tsconfig.test-d.json b/packages/misskey-js/tsconfig.test-d.json deleted file mode 100644 index d3c9c91e74..0000000000 --- a/packages/misskey-js/tsconfig.test-d.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "extends": "./tsconfig.lib.json", - "compilerOptions": { - "composite": false, - "declaration": false, - "declarationMap": false, - "sourceMap": false, - "inlineSources": false, - "outDir": "./temp/built/test-d/", - "rootDir": "." - }, - "references": [ - { "path": "./tsconfig.lib.json" } - ], - "include": [ - "test-d/**/*" - ] -} diff --git a/packages/misskey-js/tsconfig.test.json b/packages/misskey-js/tsconfig.test.json deleted file mode 100644 index dbe065f0d8..0000000000 --- a/packages/misskey-js/tsconfig.test.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "extends": "./tsconfig.lib.json", - "compilerOptions": { - "composite": false, - "declaration": false, - "declarationMap": false, - "sourceMap": false, - "inlineSources": false, - "module": "nodenext", - "moduleResolution": "nodenext", - "outDir": "./temp/built/test/", - "rootDir": "./test/" - }, - "references": [ - { "path": "./tsconfig.lib.json" } - ], - "include": [ - "test/**/*" - ] -}