Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(misskey-js): metaの型定義をパラメータで分岐できるように #13783

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/misskey-js/etc/misskey-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,13 @@ class APIClient {
// (undocumented)
fetch: FetchLike;
// (undocumented)
getMiAuthURL(options: {
name?: string;
icon?: string;
callback?: string;
permission?: typeof permissions_2[number][];
}, sessionId?: string): string;
// (undocumented)
origin: string;
}

Expand Down Expand Up @@ -1085,6 +1092,22 @@ export type Endpoints = Overwrite<Endpoints_2, {
};
};
};
'meta': {
req: MetaRequest;
res: {
$switch: {
$cases: [
[
{
detail: true;
},
MetaDetailed
]
];
$default: MetaLite;
};
};
};
'signup': {
req: SignupRequest;
res: SignupResponse;
Expand All @@ -1097,6 +1120,10 @@ export type Endpoints = Overwrite<Endpoints_2, {
req: SigninRequest;
res: SigninResponse;
};
'miauth/placeholder/check': {
req: EmptyRequest;
res: MiAuthCheckResponse;
};
}>;

// @public (undocumented)
Expand All @@ -1122,6 +1149,7 @@ declare namespace entities {
SignupPendingResponse,
SigninRequest,
SigninResponse,
MiAuthCheckResponse,
EmptyRequest,
EmptyResponse,
AdminMetaResponse,
Expand Down Expand Up @@ -2248,6 +2276,12 @@ type MetaRequest = operations['meta']['requestBody']['content']['application/jso
// @public (undocumented)
type MetaResponse = operations['meta']['responses']['200']['content']['application/json'];

// @public (undocumented)
type MiAuthCheckResponse = {
token: string;
user: UserDetailedNotMe;
};

// @public (undocumented)
type MiauthGenTokenRequest = operations['miauth___gen-token']['requestBody']['content']['application/json'];

Expand Down Expand Up @@ -3110,6 +3144,7 @@ type UsersUpdateMemoRequest = operations['users___update-memo']['requestBody']['

// Warnings were encountered during analysis:
//
// src/api.ts:90:3 - (ae-forgotten-export) The symbol "permissions_2" needs to be exported by the entry point index.d.ts
// src/entities.ts:25:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)
Expand Down
17 changes: 15 additions & 2 deletions packages/misskey-js/src/api.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Endpoints as Gen } from './autogen/endpoint.js';
import { UserDetailed } from './autogen/models.js';
import { UsersShowRequest } from './autogen/entities.js';
import { MetaDetailed, MetaLite, UserDetailed } from './autogen/models.js';
import { MetaRequest, UsersShowRequest } from './autogen/entities.js';
import {
SigninRequest,
SigninResponse,
Expand All @@ -27,12 +27,12 @@

type IsCaseMatched<E extends keyof Endpoints, P extends Endpoints[E]['req'], C extends number> =
Endpoints[E]['res'] extends SwitchCase
? IsNeverType<StrictExtract<Endpoints[E]['res']['$switch']['$cases'][C], [P, any]>> extends false ? true : false

Check warning on line 30 in packages/misskey-js/src/api.types.ts

View workflow job for this annotation

GitHub Actions / lint (misskey-js)

Unexpected any. Specify a different type
: false

type GetCaseResult<E extends keyof Endpoints, P extends Endpoints[E]['req'], C extends number> =
Endpoints[E]['res'] extends SwitchCase
? StrictExtract<Endpoints[E]['res']['$switch']['$cases'][C], [P, any]>[1]

Check warning on line 35 in packages/misskey-js/src/api.types.ts

View workflow job for this annotation

GitHub Actions / lint (misskey-js)

Unexpected any. Specify a different type
: never

export type SwitchCaseResponseType<E extends keyof Endpoints, P extends Endpoints[E]['req']> = Endpoints[E]['res'] extends SwitchCase
Expand Down Expand Up @@ -64,6 +64,19 @@
};
};
},
'meta': {
req: MetaRequest;
res: {
$switch: {
$cases: [[
{
detail: false;
}, MetaLite,
]];
$default: MetaDetailed;
}
}
},
// api.jsonには載せないものなのでここで定義
'signup': {
req: SignupRequest;
Expand Down
Loading