-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
misskey-js: admin/roles/createのpoliciesのスキーマを具現化する #14161
Comments
openapi-typescriptのupstream issue (works as intentional): openapi-ts/openapi-typescript#1686 |
@kakkokari-gtyih |
多分この辺を読んでいただくのが良いかと(Blobはこの通りにやった) |
related: #14147 |
diff --git a/packages/backend/src/server/api/endpoints/admin/roles/create.ts b/packages/backend/src/server/api/endpoints/admin/roles/create.ts
index e0c02f7a5d..5853a69b02 100644
--- a/packages/backend/src/server/api/endpoints/admin/roles/create.ts
+++ b/packages/backend/src/server/api/endpoints/admin/roles/create.ts
@@ -6,7 +6,8 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { RoleEntityService } from '@/core/entities/RoleEntityService.js';
-import { RoleService } from '@/core/RoleService.js';
+import { type RolePolicies, RoleService } from '@/core/RoleService.js';
+import { MiRole } from "@/models/Role.js";
export const meta = {
tags: ['admin', 'role'],
@@ -59,8 +60,31 @@ export const paramDef = {
],
} as const;
+type RequiredKeys<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T];
+
+type Compile<T> = T extends boolean
+ ? { readonly type: 'boolean' }
+ : T extends Record<string, unknown>
+ ? Readonly<{
+ type: 'object',
+ properties: Readonly<{[k in keyof T]: Compile<T[k]>}>
+ required: readonly RequiredKeys<T>[]
+ }>
+ : T extends string
+ ? { readonly type: 'string' }
+ : T extends number
+ ? { readonly type: 'number' }
+ : never;
+
+type Values<T extends Record<PropertyKey, unknown>> = T[keyof T];
+
+// Omitしないとanyに化ける
+type PartialRolePolicy = Partial<{[k in keyof RolePolicies]: Omit<Values<MiRole["policies"]>, "value"> & { value: RolePolicies[k] }}>;
+
+type PartialRolePolicyOverrideSchema = Compile<{ policies: PartialRolePolicy }>;
+
@Injectable()
-export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
+export default class extends Endpoint<typeof meta, typeof paramDef & PartialRolePolicyOverrideSchema> { // eslint-disable-line import/no-default-export
constructor(
private roleEntityService: RoleEntityService,
private roleService: RoleService, 型システム的にはこれでいいが、ajvに引き渡すために値が必要なのでもうすこし工夫する必要がある |
misskey-jsの表面上で型を変えるだけでいいなら |
→ #14167 |
Summary
admin/roles/create
のpolicies
はRecord<string, never>
ではないPurpose
backend/test/e2e/note.tsで実際に使用されていて、基礎ロールに対するオーバーライドとして機能しているため:
misskey/packages/backend/test/e2e/note.ts
Lines 471 to 477 in a540713
Do you want to implement this feature yourself?
The text was updated successfully, but these errors were encountered: