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): miauth checkの型を追加 #14885

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
(Cherry-picked from https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/711)

### Misskey.js
- Enhance: `/miauth/{sessionId}/check` の型を追加
- Fix: Stream初期化時、別途WebSocketを指定する場合の型定義を修正

## 2024.10.1
Expand Down
14 changes: 14 additions & 0 deletions packages/misskey-js/etc/misskey-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,10 @@ export type Endpoints = Overwrite<Endpoints_2, {
}>;
res: AdminRolesCreateResponse;
};
[ep: `miauth/${string}/check`]: {
req: EmptyRequest;
res: MiAuthCheckResponse;
};
}>;

// @public (undocumented)
Expand Down Expand Up @@ -1223,6 +1227,7 @@ declare namespace entities {
SigninWithPasskeyRequest,
SigninWithPasskeyInitResponse,
SigninWithPasskeyResponse,
MiAuthCheckResponse,
PartialRolePolicyOverride,
EmptyRequest,
EmptyResponse,
Expand Down Expand Up @@ -2439,6 +2444,15 @@ type MetaRequest = operations['meta']['requestBody']['content']['application/jso
// @public (undocumented)
type MetaResponse = operations['meta']['responses']['200']['content']['application/json'];

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

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

Expand Down
7 changes: 6 additions & 1 deletion 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 { AdminRolesCreateRequest, AdminRolesCreateResponse, UsersShowRequest } from './autogen/entities.js';
import { AdminRolesCreateRequest, AdminRolesCreateResponse, UsersShowRequest, EmptyRequest } from './autogen/entities.js';
import {
PartialRolePolicyOverride,
SigninFlowRequest,
Expand All @@ -12,6 +12,7 @@ import {
SignupPendingResponse,
SignupRequest,
SignupResponse,
MiAuthCheckResponse,
} from './entities.js';

type Overwrite<T, U extends { [Key in keyof T]?: unknown }> = Omit<
Expand Down Expand Up @@ -104,6 +105,10 @@ export type Endpoints = Overwrite<
'admin/roles/create': {
req: Overwrite<AdminRolesCreateRequest, { policies: PartialRolePolicyOverride }>;
res: AdminRolesCreateResponse;
},
[ep: `miauth/${string}/check`]: {
req: EmptyRequest;
res: MiAuthCheckResponse;
}
Copy link
Member

@anatawa12 anatawa12 Nov 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここ消して治るならOverwriteの検査でtypescriptの回数制限に達した可能性あるかも(よく知らないけどなんか型チェックが一定の複雑度を超えると打ち切りが発生することがあるらしい?よくわからないけど。メモ化とかの都合もあって色々複雑らしいというのを聞いたことがある)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

足してるだけのもの(自動生成で生成されないとわかっているもの)は単に|でつなげるようにすればいい?

Copy link
Member

@anatawa12 anatawa12 Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

その方が良い可能性が高いと思います

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あーでもSwitchCaseResponseTypeの適用はここじゃないのか。場合によっては変わらないかも

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overwriteから出したけど変わらなかった

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SwitchCaseResponseType側をいい感じにする必要がありそうか....

ちょっと調べてみる

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっといろいろ調べた感じ、複雑性は関係なかった。

miauth/${string}/check${string}timeline (timeline testで使われてるタイムラインエンドポイントの表現)とマッチする扱いをtypescript compilerに受けて、戻り値の方がcomponents['schemas']['Note'][] | MiAuthCheckResponseになる扱いを受けてるっぽいので、miauth/${string}/check${string}をいい感じに変えるといいかもしれないけどmiauthの仕様的には変えられないか。

またはテスト側の型の宣言を('antennas/notes' | 'notes/global-timeline' | 'notes/timeline' | 'notes/hybrid-timeline' | 'notes/local-timeline' | 'roles/notes' | 'notes/search-by-tag' | 'notes/user-list-timeline')にする事もできる。

Copy link
Member

@anatawa12 anatawa12 Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@anatawa12 anatawa12 Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typescriptの方針的に`miauth/${string}/check` & `${string}timeline` を never にするかは不透明なので、
'antennas/notes' | 'notes/global-timeline' | 'notes/timeline' | 'notes/hybrid-timeline' | 'notes/local-timeline' | 'roles/notes' | 'notes/search-by-tag' | 'notes/user-list-timeline' に書き換えたほうが良さそう。

また、Notesとしてmisskey jsのchangesとして書いておいたほうが良さそう。keyof Misskey.Endpoints & `${string}timeline` みたいなのは動かなくなるかもしれないよって

}
>
8 changes: 8 additions & 0 deletions packages/misskey-js/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ export type SigninWithPasskeyResponse = {
signinResponse: SigninFlowResponse & { finished: true };
};

export type MiAuthCheckResponse = {
ok: true;
token: string;
user: UserDetailedNotMe;
} | {
ok: false;
};

type Values<T extends Record<PropertyKey, unknown>> = T[keyof T];

export type PartialRolePolicyOverride = Partial<{[k in keyof RolePolicies]: Omit<Values<Role['policies']>, 'value'> & { value: RolePolicies[k] }}>;
Loading