feat(misskey-js): `POST admin/roles/create`の型を具象化 (#14167)

* feat(misskey-js): `POST admin/roles/create`の型を具象化

* fix

* docs: CHANGELOG.md

* test(misskey-js): admin/roles/createの型が合うことを表明

* test(misskey-js): single quote

* test(misskey-js): 無を読もうとして爆発するのを修正

* test(misskey-js): fix comment
This commit is contained in:
Kisaragi 2024-07-10 20:40:04 +09:00 committed by GitHub
parent 02e0a86b12
commit 52d8a54fc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 76 additions and 3 deletions

View File

@ -37,6 +37,7 @@
### Misskey.js
- Feat: `/drive/files/create` のリクエストに対応(`multipart/form-data`に対応)
- Feat: `/admin/role/create` のロールポリシーの型を修正
## 2024.5.0

View File

@ -1160,6 +1160,12 @@ export type Endpoints = Overwrite<Endpoints_2, {
req: SigninRequest;
res: SigninResponse;
};
'admin/roles/create': {
req: Overwrite<AdminRolesCreateRequest, {
policies: PartialRolePolicyOverride;
}>;
res: AdminRolesCreateResponse;
};
}>;
// @public (undocumented)
@ -1185,6 +1191,7 @@ declare namespace entities {
SignupPendingResponse,
SigninRequest,
SigninResponse,
PartialRolePolicyOverride,
EmptyRequest,
EmptyResponse,
AdminMetaResponse,
@ -2725,6 +2732,15 @@ type PagesUpdateRequest = operations['pages___update']['requestBody']['content']
// @public (undocumented)
function parse(acct: string): Acct;
// Warning: (ae-forgotten-export) The symbol "Values" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type PartialRolePolicyOverride = Partial<{
[k in keyof RolePolicies]: Omit<Values<Role['policies']>, 'value'> & {
value: RolePolicies[k];
};
}>;
// @public (undocumented)
export const permissions: readonly ["read:account", "write:account", "read:blocks", "write:blocks", "read:drive", "write:drive", "read:favorites", "write:favorites", "read:following", "write:following", "read:messaging", "write:messaging", "read:mutes", "write:mutes", "write:notes", "read:notifications", "write:notifications", "read:reactions", "write:reactions", "write:votes", "read:pages", "write:pages", "write:page-likes", "read:page-likes", "read:user-groups", "write:user-groups", "read:channels", "write:channels", "read:gallery", "write:gallery", "read:gallery-likes", "write:gallery-likes", "read:flash", "write:flash", "read:flash-likes", "write:flash-likes", "read:admin:abuse-user-reports", "write:admin:delete-account", "write:admin:delete-all-files-of-a-user", "read:admin:index-stats", "read:admin:table-stats", "read:admin:user-ips", "read:admin:meta", "write:admin:reset-password", "write:admin:resolve-abuse-user-report", "write:admin:send-email", "read:admin:server-info", "read:admin:show-moderation-log", "read:admin:show-user", "write:admin:suspend-user", "write:admin:unset-user-avatar", "write:admin:unset-user-banner", "write:admin:unsuspend-user", "write:admin:meta", "write:admin:user-note", "write:admin:roles", "read:admin:roles", "write:admin:relays", "read:admin:relays", "write:admin:invite-codes", "read:admin:invite-codes", "write:admin:announcements", "read:admin:announcements", "write:admin:avatar-decorations", "read:admin:avatar-decorations", "write:admin:federation", "write:admin:account", "read:admin:account", "write:admin:emoji", "read:admin:emoji", "write:admin:queue", "read:admin:queue", "write:admin:promo", "write:admin:drive", "read:admin:drive", "write:admin:ad", "read:admin:ad", "write:invite-codes", "read:invite-codes", "write:clip-favorite", "read:clip-favorite", "read:federation", "write:report-abuse"];
@ -3213,7 +3229,7 @@ type UsersUpdateMemoRequest = operations['users___update-memo']['requestBody']['
// Warnings were encountered during analysis:
//
// src/entities.ts:25:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts
// src/entities.ts:34:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts
// (No @packageDocumentation comment for this package)

View File

@ -1,7 +1,8 @@
import { Endpoints as Gen } from './autogen/endpoint.js';
import { UserDetailed } from './autogen/models.js';
import { UsersShowRequest } from './autogen/entities.js';
import { AdminRolesCreateRequest, AdminRolesCreateResponse, UsersShowRequest } from './autogen/entities.js';
import {
PartialRolePolicyOverride,
SigninRequest,
SigninResponse,
SignupPendingRequest,
@ -79,5 +80,9 @@ export type Endpoints = Overwrite<
req: SigninRequest;
res: SigninResponse;
},
'admin/roles/create': {
req: Overwrite<AdminRolesCreateRequest, { policies: PartialRolePolicyOverride }>;
res: AdminRolesCreateResponse;
}
}
>

View File

@ -1,5 +1,14 @@
import { ModerationLogPayloads } from './consts.js';
import { Announcement, EmojiDetailed, MeDetailed, Page, User, UserDetailedNotMe } from './autogen/models.js';
import {
Announcement,
EmojiDetailed,
MeDetailed,
Page,
Role,
RolePolicies,
User,
UserDetailedNotMe
} from './autogen/models.js';
export * from './autogen/entities.js';
export * from './autogen/models.js';
@ -236,3 +245,7 @@ export type SigninResponse = {
id: User['id'],
i: string,
};
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] }}>;

View File

@ -259,4 +259,42 @@ describe('API', () => {
expect(isAPIError(e)).toEqual(false);
}
});
test('admin/roles/create の型が合う', async() => {
fetchMock.resetMocks();
fetchMock.mockResponse(async () => {
return {
// 本来返すべき値は`Role`型だが、テストなのでお茶を濁す
status: 200,
body: '{}'
};
});
const cli = new APIClient({
origin: 'https://misskey.test',
credential: 'TOKEN',
});
await cli.request('admin/roles/create', {
name: 'aaa',
asBadge: false,
canEditMembersByModerator: false,
color: '#123456',
condFormula: {},
description: '',
displayOrder: 0,
iconUrl: '',
isAdministrator: false,
isExplorable: false,
isModerator: false,
isPublic: false,
policies: {
ltlAvailable: {
value: true,
priority: 0,
useDefault: false,
},
},
target: 'manual',
});
})
});