From 89480d9029cbfc893f2fcb3b77d4a88d34394089 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 21 May 2023 14:06:11 +0000 Subject: [PATCH] wip --- packages/frontend/src/scripts/api.ts | 16 ++++++++-------- packages/misskey-js/src/api.ts | 6 +++--- packages/misskey-js/src/index.ts | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/frontend/src/scripts/api.ts b/packages/frontend/src/scripts/api.ts index ab8d70e4b8..e3f30a9082 100644 --- a/packages/frontend/src/scripts/api.ts +++ b/packages/frontend/src/scripts/api.ts @@ -5,9 +5,9 @@ import { $i } from '@/account'; export const pendingApiRequestsCount = ref(0); // Implements Misskey.api.ApiClient.request -export function api, D extends IEndpointMeta = Endpoints[E]>( +export function api, M extends IEndpointMeta = Endpoints[E]>( endpoint: E, params?: P, token?: string | null | undefined, signal?: AbortSignal -): Promise> { +): Promise> { const data: (P | Record) & { i?: string | null } = params ?? {}; pendingApiRequestsCount.value++; @@ -16,7 +16,7 @@ export function api | void>((resolve, reject) => { + const promise = new Promise | void>((resolve, reject) => { // Append a credential if ($i) data.i = $i.token; if (token !== undefined) data.i = token; @@ -46,13 +46,13 @@ export function api>; + return promise as Promise>; } // Implements Misskey.api.ApiClient.request -export function apiGet, D extends IEndpointMeta = Endpoints[E]>( +export function apiGet, M extends IEndpointMeta = Endpoints[E]>( endpoint: E, params?: P, token?: string | null | undefined, signal?: AbortSignal -): Promise> { +): Promise> { pendingApiRequestsCount.value++; const onFinally = () => { @@ -61,7 +61,7 @@ export function apiGet); - const promise = new Promise | void>((resolve, reject) => { + const promise = new Promise | void>((resolve, reject) => { // Send request window.fetch(`${apiUrl}/${endpoint}?${query}`, { method: 'GET', @@ -82,5 +82,5 @@ export function apiGet>; + return promise as Promise>; } diff --git a/packages/misskey-js/src/api.ts b/packages/misskey-js/src/api.ts index ebade16931..ebb2a263ba 100644 --- a/packages/misskey-js/src/api.ts +++ b/packages/misskey-js/src/api.ts @@ -42,9 +42,9 @@ export class APIClient { this.fetch = opts.fetch ?? ((...args) => fetch(...args)); } - public request, D extends IEndpointMeta = Endpoints[E], R = ResponseOf>( + public request, M extends IEndpointMeta = Endpoints[E]>( endpoint: E, params: P, credential?: string | null | undefined, - ): Promise + ): Promise> { const promise = new Promise((resolve, reject) => { this.fetch(`${this.origin}/api/${endpoint}`, { @@ -74,6 +74,6 @@ export class APIClient { }).catch(reject); }); - return promise as any; + return promise as Promise>; } } diff --git a/packages/misskey-js/src/index.ts b/packages/misskey-js/src/index.ts index 797f10a4ef..457a2742f5 100644 --- a/packages/misskey-js/src/index.ts +++ b/packages/misskey-js/src/index.ts @@ -1,4 +1,4 @@ -import { Endpoints } from './api.types.js'; +import { Endpoints } from './endpoints.types.js'; import Stream, { Connection } from './streaming.js'; import { Channels } from './streaming.types.js'; import { Acct } from './acct.js';