From ea92254b731807fe7bc4bfe45339007459f5c91c Mon Sep 17 00:00:00 2001 From: noonworks Date: Mon, 20 Feb 2023 08:13:37 +0900 Subject: refactor: 型エラー修正 / Fix type errors backend (#9983) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: fix type errors in backend * revert some changes * なるべくJS挙動を変えない方法に修正 * Update packages/backend/src/server/api/ApiCallService.ts Co-authored-by: Acid Chicken (硫酸鶏) * コンフリクトするファイルを削除 --------- Co-authored-by: Acid Chicken (硫酸鶏) --- packages/backend/src/core/PushNotificationService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/backend/src/core/PushNotificationService.ts') diff --git a/packages/backend/src/core/PushNotificationService.ts b/packages/backend/src/core/PushNotificationService.ts index 75bf4b0e01..4b7ca5c968 100644 --- a/packages/backend/src/core/PushNotificationService.ts +++ b/packages/backend/src/core/PushNotificationService.ts @@ -23,7 +23,7 @@ type pushNotificationsTypes = { // Reduce length because push message servers have character limits function truncateBody(type: T, body: pushNotificationsTypes[T]): pushNotificationsTypes[T] { - if (body === undefined) return body; + if (typeof body !== 'object') return body; return { ...body, -- cgit v1.2.3-freya From a6fb6150a3557245f722ba1c084b0c081e6970e1 Mon Sep 17 00:00:00 2001 From: dojineko Date: Wed, 22 Feb 2023 14:51:34 +0900 Subject: chore: add tiny definition for redis-lock (#9971) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add tiny definition for redis-lock * Update packages/backend/src/@types/redis-lock.d.ts Co-authored-by: Acid Chicken (硫酸鶏) * fix type name * add @typescript-eslint/naming-convention * define taskToPerform type * chore: use default settings for `@typescript-eslint/naming-convention` * set `format:none` to typeParameter (default) * ignore lines to be treated as exceptions * chore: fix naming --------- Co-authored-by: Acid Chicken (硫酸鶏) Co-authored-by: syuilo --- packages/backend/src/@types/redis-lock.d.ts | 8 ++++++++ packages/backend/src/core/PushNotificationService.ts | 4 ++-- packages/backend/src/core/activitypub/type.ts | 4 ++-- packages/backend/src/server/api/endpoint-base.ts | 4 ++-- packages/shared/.eslintrc.js | 11 +++++++++++ 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 packages/backend/src/@types/redis-lock.d.ts (limited to 'packages/backend/src/core/PushNotificationService.ts') diff --git a/packages/backend/src/@types/redis-lock.d.ts b/packages/backend/src/@types/redis-lock.d.ts new file mode 100644 index 0000000000..9242656a98 --- /dev/null +++ b/packages/backend/src/@types/redis-lock.d.ts @@ -0,0 +1,8 @@ +declare module 'redis-lock' { + import type Redis from 'ioredis'; + + type Lock = (lockName: string, timeout?: number, taskToPerform?: () => Promise) => void; + function redisLock(client: Redis.Redis, retryDelay: number): Lock; + + export = redisLock; +} diff --git a/packages/backend/src/core/PushNotificationService.ts b/packages/backend/src/core/PushNotificationService.ts index 4b7ca5c968..545f86d764 100644 --- a/packages/backend/src/core/PushNotificationService.ts +++ b/packages/backend/src/core/PushNotificationService.ts @@ -9,7 +9,7 @@ import { MetaService } from '@/core/MetaService.js'; import { bindThis } from '@/decorators.js'; // Defined also packages/sw/types.ts#L13 -type pushNotificationsTypes = { +type PushNotificationsTypes = { 'notification': Packed<'Notification'>; 'unreadAntennaNote': { antenna: { id: string, name: string }; @@ -56,7 +56,7 @@ export class PushNotificationService { } @bindThis - public async pushNotification(userId: string, type: T, body: pushNotificationsTypes[T]) { + public async pushNotification(userId: string, type: T, body: PushNotificationsTypes[T]) { const meta = await this.metaService.fetch(); if (!meta.enableServiceWorker || meta.swPublicKey == null || meta.swPrivateKey == null) return; diff --git a/packages/backend/src/core/activitypub/type.ts b/packages/backend/src/core/activitypub/type.ts index 268bf99119..7f2ca9c05e 100644 --- a/packages/backend/src/core/activitypub/type.ts +++ b/packages/backend/src/core/activitypub/type.ts @@ -1,8 +1,8 @@ -export type obj = { [x: string]: any }; +export type Obj = { [x: string]: any }; export type ApObject = IObject | string | (IObject | string)[]; export interface IObject { - '@context'?: string | string[] | obj | obj[]; + '@context'?: string | string[] | Obj | Obj[]; type: string | string[]; id?: string; name?: string | null; diff --git a/packages/backend/src/server/api/endpoint-base.ts b/packages/backend/src/server/api/endpoint-base.ts index 115526d997..ed283eb834 100644 --- a/packages/backend/src/server/api/endpoint-base.ts +++ b/packages/backend/src/server/api/endpoint-base.ts @@ -20,14 +20,14 @@ type File = { }; // TODO: paramsの型をT['params']のスキーマ定義から推論する -type executor = +type Executor = (params: SchemaType, user: T['requireCredential'] extends true ? LocalUser : LocalUser | null, token: AccessToken | null, file?: File, cleanup?: () => any, ip?: string | null, headers?: Record | null) => Promise>>; export abstract class Endpoint { public exec: (params: any, user: T['requireCredential'] extends true ? LocalUser : LocalUser | null, token: AccessToken | null, file?: File, ip?: string | null, headers?: Record | null) => Promise; - constructor(meta: T, paramDef: Ps, cb: executor) { + constructor(meta: T, paramDef: Ps, cb: Executor) { const validate = ajv.compile(paramDef); this.exec = (params: any, user: T['requireCredential'] extends true ? LocalUser : LocalUser | null, token: AccessToken | null, file?: File, ip?: string | null, headers?: Record | null) => { diff --git a/packages/shared/.eslintrc.js b/packages/shared/.eslintrc.js index 6d38a9fb9f..7c979a93dc 100644 --- a/packages/shared/.eslintrc.js +++ b/packages/shared/.eslintrc.js @@ -77,6 +77,17 @@ module.exports = { '@typescript-eslint/prefer-nullish-coalescing': [ 'error', ], + '@typescript-eslint/naming-convention': [ + 'error', + { + "selector": "typeLike", + "format": ["PascalCase"] + }, + { + "selector": "typeParameter", + "format": [] + } + ], 'import/no-unresolved': ['off'], 'import/no-default-export': ['warn'], 'import/order': ['warn', { -- cgit v1.2.3-freya From 5ec07ede7ce904ab135cad1d425a4957515de3a9 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 22 Feb 2023 14:58:41 +0900 Subject: fix types --- packages/backend/src/core/AppLockService.ts | 2 +- packages/backend/src/core/PushNotificationService.ts | 2 +- .../src/server/api/endpoints/users/search-by-username-and-host.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'packages/backend/src/core/PushNotificationService.ts') diff --git a/packages/backend/src/core/AppLockService.ts b/packages/backend/src/core/AppLockService.ts index 5f3072a415..ee179b7f01 100644 --- a/packages/backend/src/core/AppLockService.ts +++ b/packages/backend/src/core/AppLockService.ts @@ -12,7 +12,7 @@ const retryDelay = 100; @Injectable() export class AppLockService { - private lock: (key: string, timeout?: number) => Promise<() => void>; + private lock: (key: string, timeout?: number, _?: (() => Promise) | undefined) => Promise<() => void>; constructor( @Inject(DI.redis) diff --git a/packages/backend/src/core/PushNotificationService.ts b/packages/backend/src/core/PushNotificationService.ts index 545f86d764..2cad1bc07e 100644 --- a/packages/backend/src/core/PushNotificationService.ts +++ b/packages/backend/src/core/PushNotificationService.ts @@ -22,7 +22,7 @@ type PushNotificationsTypes = { }; // Reduce length because push message servers have character limits -function truncateBody(type: T, body: pushNotificationsTypes[T]): pushNotificationsTypes[T] { +function truncateBody(type: T, body: PushNotificationsTypes[T]): PushNotificationsTypes[T] { if (typeof body !== 'object') return body; return { diff --git a/packages/backend/src/server/api/endpoints/users/search-by-username-and-host.ts b/packages/backend/src/server/api/endpoints/users/search-by-username-and-host.ts index 34827547b0..1cefcf2707 100644 --- a/packages/backend/src/server/api/endpoints/users/search-by-username-and-host.ts +++ b/packages/backend/src/server/api/endpoints/users/search-by-username-and-host.ts @@ -37,13 +37,13 @@ export const paramDef = { properties: { username: { type: 'string', nullable: true }, }, - required: ['username'] + required: ['username'], }, { properties: { host: { type: 'string', nullable: true }, }, - required: ['host'] + required: ['host'], }, ], } as const; @@ -68,7 +68,7 @@ export default class extends Endpoint { super(meta, paramDef, async (ps, me) => { const setUsernameAndHostQuery = (query = this.usersRepository.createQueryBuilder('user')) => { if (ps.username) { - query.andWhere('user.usernameLower LIKE :username', { username: sqlLikeEscape(ps.username.toLowerCase()) + '%' }) + query.andWhere('user.usernameLower LIKE :username', { username: sqlLikeEscape(ps.username.toLowerCase()) + '%' }); } if (ps.host) { @@ -76,7 +76,7 @@ export default class extends Endpoint { query.andWhere('user.host IS NULL'); } else { query.andWhere('user.host LIKE :host', { - host: sqlLikeEscape(ps.host.toLowerCase()) + '%' + host: sqlLikeEscape(ps.host.toLowerCase()) + '%', }); } } -- cgit v1.2.3-freya