classの定義を一本化

This commit is contained in:
kakkokari-gtyih 2024-06-23 01:29:07 +09:00
parent c578015b63
commit ee59196663
4 changed files with 388 additions and 403 deletions

View File

@ -728,6 +728,7 @@ type ApGetResponse = operations['ap___get']['responses']['200']['content']['appl
declare namespace api {
export {
isAPIError,
ErrPromise,
SwitchCaseResponseType,
APIError,
FetchLike,
@ -2707,6 +2708,11 @@ export { entities }
// @public (undocumented)
type Error_2 = components['schemas']['Error'];
// @public (undocumented)
class ErrPromise<TSuccess, TError> extends Promise<TSuccess> {
constructor(executor: (resolve: (value: TSuccess | PromiseLike<TSuccess>) => void, reject: (reason: TError) => void) => void);
}
// @public (undocumented)
type ExportCustomEmojisErrors = EndpointsErrors['export-custom-emojis'][keyof EndpointsErrors['export-custom-emojis']];

View File

@ -284,15 +284,6 @@ async function generateApiClientJSDoc(
endpointOutputLine.push(`import type { Endpoints } from '${toImportPath(endpointsFileName)}';`);
endpointOutputLine.push('');
endpointOutputLine.push(
'interface IErrPromise<TSuccess, TError = unknown> {',
' then<TResult1 = TSuccess, TResult2 = never>(onfulfilled?: ((value: TSuccess) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: TError) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;',
'',
' catch<TResult = never>(onrejected?: ((reason: TError) => TResult | PromiseLike<TResult>) | undefined | null): Promise<TSuccess | TResult>;',
'}',
);
endpointOutputLine.push('');
endpointOutputLine.push(`declare module '${toImportPath(apiClientFileName)}' {`);
endpointOutputLine.push(' export interface APIClient {');
for (let i = 0; i < endpoints.length; i++) {
@ -306,7 +297,7 @@ async function generateApiClientJSDoc(
' endpoint: E,',
' params: P,',
' credential?: string | null,',
' ): IErrPromise<SwitchCaseResponseType<E, P>, RE>;',
' ): ErrPromise<SwitchCaseResponseType<E, P>, RE>;',
);
if (i < endpoints.length - 1) {

View File

@ -3,13 +3,7 @@ import './autogen/apiClientJSDoc.js';
import { SwitchCaseResponseType } from './api.types.js';
import type { Endpoints } from './api.types.js';
interface IErrPromise<TSuccess, TError = unknown> {
then<TResult1 = TSuccess, TResult2 = never>(onfulfilled?: ((value: TSuccess) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: TError) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
catch<TResult = never>(onrejected?: ((reason: TError) => TResult | PromiseLike<TResult>) | undefined | null): Promise<TSuccess | TResult>;
}
class ErrPromise<TSuccess, TError> extends Promise<TSuccess> implements IErrPromise<TSuccess, TError> {
export class ErrPromise<TSuccess, TError> extends Promise<TSuccess> {
constructor(executor: (resolve: (value: TSuccess | PromiseLike<TSuccess>) => void, reject: (reason: TError) => void) => void) {
super(executor);
}
@ -65,7 +59,7 @@ export class APIClient {
endpoint: E,
params: P = {} as P,
credential?: string | null,
): IErrPromise<SwitchCaseResponseType<E, P>, RE> {
): ErrPromise<SwitchCaseResponseType<E, P>, RE> {
return new ErrPromise((resolve, reject) => {
this.fetch(`${this.origin}/api/${endpoint}`, {
method: 'POST',

File diff suppressed because it is too large Load Diff