classの定義を一本化
This commit is contained in:
parent
c578015b63
commit
ee59196663
|
@ -728,6 +728,7 @@ type ApGetResponse = operations['ap___get']['responses']['200']['content']['appl
|
||||||
declare namespace api {
|
declare namespace api {
|
||||||
export {
|
export {
|
||||||
isAPIError,
|
isAPIError,
|
||||||
|
ErrPromise,
|
||||||
SwitchCaseResponseType,
|
SwitchCaseResponseType,
|
||||||
APIError,
|
APIError,
|
||||||
FetchLike,
|
FetchLike,
|
||||||
|
@ -2707,6 +2708,11 @@ export { entities }
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
type Error_2 = components['schemas']['Error'];
|
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)
|
// @public (undocumented)
|
||||||
type ExportCustomEmojisErrors = EndpointsErrors['export-custom-emojis'][keyof EndpointsErrors['export-custom-emojis']];
|
type ExportCustomEmojisErrors = EndpointsErrors['export-custom-emojis'][keyof EndpointsErrors['export-custom-emojis']];
|
||||||
|
|
||||||
|
|
|
@ -284,15 +284,6 @@ async function generateApiClientJSDoc(
|
||||||
endpointOutputLine.push(`import type { Endpoints } from '${toImportPath(endpointsFileName)}';`);
|
endpointOutputLine.push(`import type { Endpoints } from '${toImportPath(endpointsFileName)}';`);
|
||||||
endpointOutputLine.push('');
|
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(`declare module '${toImportPath(apiClientFileName)}' {`);
|
||||||
endpointOutputLine.push(' export interface APIClient {');
|
endpointOutputLine.push(' export interface APIClient {');
|
||||||
for (let i = 0; i < endpoints.length; i++) {
|
for (let i = 0; i < endpoints.length; i++) {
|
||||||
|
@ -306,7 +297,7 @@ async function generateApiClientJSDoc(
|
||||||
' endpoint: E,',
|
' endpoint: E,',
|
||||||
' params: P,',
|
' params: P,',
|
||||||
' credential?: string | null,',
|
' credential?: string | null,',
|
||||||
' ): IErrPromise<SwitchCaseResponseType<E, P>, RE>;',
|
' ): ErrPromise<SwitchCaseResponseType<E, P>, RE>;',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (i < endpoints.length - 1) {
|
if (i < endpoints.length - 1) {
|
||||||
|
|
|
@ -3,13 +3,7 @@ import './autogen/apiClientJSDoc.js';
|
||||||
import { SwitchCaseResponseType } from './api.types.js';
|
import { SwitchCaseResponseType } from './api.types.js';
|
||||||
import type { Endpoints } from './api.types.js';
|
import type { Endpoints } from './api.types.js';
|
||||||
|
|
||||||
interface IErrPromise<TSuccess, TError = unknown> {
|
export class ErrPromise<TSuccess, TError> extends Promise<TSuccess> {
|
||||||
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> {
|
|
||||||
constructor(executor: (resolve: (value: TSuccess | PromiseLike<TSuccess>) => void, reject: (reason: TError) => void) => void) {
|
constructor(executor: (resolve: (value: TSuccess | PromiseLike<TSuccess>) => void, reject: (reason: TError) => void) => void) {
|
||||||
super(executor);
|
super(executor);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +59,7 @@ export class APIClient {
|
||||||
endpoint: E,
|
endpoint: E,
|
||||||
params: P = {} as P,
|
params: P = {} as P,
|
||||||
credential?: string | null,
|
credential?: string | null,
|
||||||
): IErrPromise<SwitchCaseResponseType<E, P>, RE> {
|
): ErrPromise<SwitchCaseResponseType<E, P>, RE> {
|
||||||
return new ErrPromise((resolve, reject) => {
|
return new ErrPromise((resolve, reject) => {
|
||||||
this.fetch(`${this.origin}/api/${endpoint}`, {
|
this.fetch(`${this.origin}/api/${endpoint}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue