chore: format

This commit is contained in:
naskya 2024-02-09 04:14:28 +09:00
parent 78c9911788
commit 99c592f4dd
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
113 changed files with 801 additions and 749 deletions

View file

@ -67,7 +67,7 @@ export const refs = {
Emoji: packedEmojiSchema, Emoji: packedEmojiSchema,
}; };
export type Packed<x extends keyof typeof refs> = SchemaType<typeof refs[x]>; export type Packed<x extends keyof typeof refs> = SchemaType<(typeof refs)[x]>;
type TypeStringef = type TypeStringef =
| "null" | "null"
@ -210,9 +210,13 @@ export type SchemaTypeDef<p extends Schema> = p["type"] extends "null"
? p["items"]["anyOf"] extends ReadonlyArray<Schema> ? p["items"]["anyOf"] extends ReadonlyArray<Schema>
? UnionSchemaType<NonNullable<p["items"]["anyOf"]>>[] ? UnionSchemaType<NonNullable<p["items"]["anyOf"]>>[]
: p["items"]["oneOf"] extends ReadonlyArray<Schema> : p["items"]["oneOf"] extends ReadonlyArray<Schema>
? ArrayUnion<UnionSchemaType<NonNullable<p["items"]["oneOf"]>>> ? ArrayUnion<
UnionSchemaType<NonNullable<p["items"]["oneOf"]>>
>
: p["items"]["allOf"] extends ReadonlyArray<Schema> : p["items"]["allOf"] extends ReadonlyArray<Schema>
? UnionToIntersection<UnionSchemaType<NonNullable<p["items"]["allOf"]>>>[] ? UnionToIntersection<
UnionSchemaType<NonNullable<p["items"]["allOf"]>>
>[]
: never : never
: p["items"] extends NonNullable<Schema> : p["items"] extends NonNullable<Schema>
? SchemaTypeDef<p["items"]>[] ? SchemaTypeDef<p["items"]>[]

View file

@ -51,5 +51,5 @@ export class MutedNote {
enum: mutedNoteReasons, enum: mutedNoteReasons,
comment: "The reason of the MutedNote.", comment: "The reason of the MutedNote.",
}) })
public reason: typeof mutedNoteReasons[number]; public reason: (typeof mutedNoteReasons)[number];
} }

View file

@ -125,7 +125,7 @@ export class Note {
* specified ... visibleUserIds * specified ... visibleUserIds
*/ */
@Column("enum", { enum: noteVisibilities }) @Column("enum", { enum: noteVisibilities })
public visibility: typeof noteVisibilities[number]; public visibility: (typeof noteVisibilities)[number];
@Index({ unique: true }) @Index({ unique: true })
@Column("varchar", { @Column("varchar", {

View file

@ -78,7 +78,7 @@ export class Notification {
enum: notificationTypes, enum: notificationTypes,
comment: "The type of the Notification.", comment: "The type of the Notification.",
}) })
public type: typeof notificationTypes[number]; public type: (typeof notificationTypes)[number];
/** /**
* Whether the notification was read. * Whether the notification was read.

View file

@ -47,7 +47,7 @@ export class Poll {
enum: noteVisibilities, enum: noteVisibilities,
comment: "[Denormalized]", comment: "[Denormalized]",
}) })
public noteVisibility: typeof noteVisibilities[number]; public noteVisibility: (typeof noteVisibilities)[number];
@Index() @Index()
@Column({ @Column({

View file

@ -99,7 +99,7 @@ export class UserProfile {
enum: ffVisibility, enum: ffVisibility,
default: "public", default: "public",
}) })
public ffVisibility: typeof ffVisibility[number]; public ffVisibility: (typeof ffVisibility)[number];
@Column("varchar", { @Column("varchar", {
length: 128, length: 128,
@ -238,7 +238,7 @@ export class UserProfile {
array: true, array: true,
default: [], default: [],
}) })
public mutingNotificationTypes: typeof notificationTypes[number][]; public mutingNotificationTypes: (typeof notificationTypes)[number][];
//#region Denormalized fields //#region Denormalized fields
@Index() @Index()

View file

@ -55,7 +55,7 @@ export class Webhook {
array: true, array: true,
default: "{}", default: "{}",
}) })
public on: typeof webhookEventTypes[number][]; public on: (typeof webhookEventTypes)[number][];
@Column("varchar", { @Column("varchar", {
length: 1024, length: 1024,

View file

@ -80,9 +80,9 @@ export const PageRepository = db.getRepository(Page).extend({
? await DriveFiles.pack(page.eyeCatchingImageId) ? await DriveFiles.pack(page.eyeCatchingImageId)
: null, : null,
attachedFiles: DriveFiles.packMany( attachedFiles: DriveFiles.packMany(
( (await Promise.all(attachedFiles)).filter(
await Promise.all(attachedFiles) (x): x is DriveFile => x != null,
).filter((x): x is DriveFile => x != null), ),
), ),
likedCount: page.likedCount, likedCount: page.likedCount,
isLiked: meId isLiked: meId

View file

@ -17,7 +17,15 @@ export function dateUTC(time: number[]): Date {
: time.length === 6 : time.length === 6
? Date.UTC(time[0], time[1], time[2], time[3], time[4], time[5]) ? Date.UTC(time[0], time[1], time[2], time[3], time[4], time[5])
: time.length === 7 : time.length === 7
? Date.UTC(time[0], time[1], time[2], time[3], time[4], time[5], time[6]) ? Date.UTC(
time[0],
time[1],
time[2],
time[3],
time[4],
time[5],
time[6],
)
: null; : null;
if (!d) throw new Error("wrong number of arguments"); if (!d) throw new Error("wrong number of arguments");

View file

@ -492,7 +492,7 @@ export function createIndexAllNotesJob(data = {}) {
export function webhookDeliver( export function webhookDeliver(
webhook: Webhook, webhook: Webhook,
type: typeof webhookEventTypes[number], type: (typeof webhookEventTypes)[number],
content: unknown, content: unknown,
) { ) {
const data = { const data = {

View file

@ -10,9 +10,12 @@ import { ApiError } from "./error.js";
const userIpHistories = new Map<User["id"], Set<string>>(); const userIpHistories = new Map<User["id"], Set<string>>();
setInterval(() => { setInterval(
() => {
userIpHistories.clear(); userIpHistories.clear();
}, 1000 * 60 * 60); },
1000 * 60 * 60,
);
export default (endpoint: IEndpoint, ctx: Koa.Context) => export default (endpoint: IEndpoint, ctx: Koa.Context) =>
new Promise<void>((res) => { new Promise<void>((res) => {

View file

@ -99,7 +99,7 @@ export default define(meta, paramDef, async (ps, me) => {
async function fetchAny( async function fetchAny(
uri: string, uri: string,
me: CacheableLocalUser | null | undefined, me: CacheableLocalUser | null | undefined,
): Promise<SchemaType<typeof meta["res"]> | null> { ): Promise<SchemaType<(typeof meta)["res"]> | null> {
// Wait if blocked. // Wait if blocked.
if (await shouldBlockInstance(extractDbHost(uri))) return null; if (await shouldBlockInstance(extractDbHost(uri))) return null;

View file

@ -189,7 +189,7 @@ export default define(meta, paramDef, async (ps, _user, token) => {
profileUpdates.mutedInstances = ps.mutedInstances; profileUpdates.mutedInstances = ps.mutedInstances;
if (ps.mutingNotificationTypes !== undefined) if (ps.mutingNotificationTypes !== undefined)
profileUpdates.mutingNotificationTypes = profileUpdates.mutingNotificationTypes =
ps.mutingNotificationTypes as typeof notificationTypes[number][]; ps.mutingNotificationTypes as (typeof notificationTypes)[number][];
if (typeof ps.isLocked === "boolean") updates.isLocked = ps.isLocked; if (typeof ps.isLocked === "boolean") updates.isLocked = ps.isLocked;
if (typeof ps.isExplorable === "boolean") if (typeof ps.isExplorable === "boolean")
updates.isExplorable = ps.isExplorable; updates.isExplorable = ps.isExplorable;

View file

@ -61,11 +61,14 @@ export const initializeStreamingServer = (server: http.Server) => {
); );
const intervalId = user const intervalId = user
? setInterval(() => { ? setInterval(
() => {
Users.update(user.id, { Users.update(user.id, {
lastActiveDate: new Date(), lastActiveDate: new Date(),
}); });
}, 1000 * 60 * 5) },
1000 * 60 * 5,
)
: null; : null;
if (user) { if (user) {
Users.update(user.id, { Users.update(user.id, {

View file

@ -44,13 +44,13 @@ type KeyToColumnName<T extends string> = T extends `${infer R1}.${infer R2}`
: T; : T;
type Columns<S extends Schema> = { type Columns<S extends Schema> = {
[K in [K in keyof S as `${typeof columnPrefix}${KeyToColumnName<
keyof S as `${typeof columnPrefix}${KeyToColumnName<string & K>}`]: number; string & K
>}`]: number;
}; };
type TempColumnsForUnique<S extends Schema> = { type TempColumnsForUnique<S extends Schema> = {
[K in [K in keyof S as `${typeof uniqueTempColumnPrefix}${KeyToColumnName<
keyof S as `${typeof uniqueTempColumnPrefix}${KeyToColumnName<
string & K string & K
>}`]: S[K]["uniqueIncrement"] extends true ? string[] : never; >}`]: S[K]["uniqueIncrement"] extends true ? string[] : never;
}; };
@ -325,7 +325,7 @@ export default abstract class Chart<T extends Schema> {
private getNewLog(latest: KVs<T> | null): KVs<T> { private getNewLog(latest: KVs<T> | null): KVs<T> {
const log = {} as Record<keyof T, number>; const log = {} as Record<keyof T, number>;
for (const [k, v] of Object.entries(this.schema) as [ for (const [k, v] of Object.entries(this.schema) as [
keyof typeof this["schema"], keyof (typeof this)["schema"],
this["schema"][string], this["schema"][string],
][]) { ][]) {
if (v.accumulate && latest) { if (v.accumulate && latest) {

View file

@ -42,10 +42,13 @@ const charts = [
]; ];
// 20分おきにメモリ情報をDBに書き込み // 20分おきにメモリ情報をDBに書き込み
setInterval(() => { setInterval(
() => {
for (const chart of charts) { for (const chart of charts) {
chart.save(); chart.save();
} }
}, 1000 * 60 * 20); },
1000 * 60 * 20,
);
beforeShutdown(() => Promise.all(charts.map((chart) => chart.save()))); beforeShutdown(() => Promise.all(charts.map((chart) => chart.save())));

View file

@ -22,7 +22,7 @@ describe("ユーザー", () => {
// エンティティとしてのユーザーを主眼においたテストを記述する // エンティティとしてのユーザーを主眼においたテストを記述する
// (Userを返すエンドポイントとUserエンティティを書き換えるエンドポイントをテストする) // (Userを返すエンドポイントとUserエンティティを書き換えるエンドポイントをテストする)
const stripUndefined = <T extends { [key: string]: any },>( const stripUndefined = <T extends { [key: string]: any }>(
orig: T, orig: T,
): Partial<T> => { ): Partial<T> => {
return Object.entries({ ...orig }) return Object.entries({ ...orig })
@ -224,11 +224,15 @@ describe("ユーザー", () => {
let userFollowRequesting: User; let userFollowRequesting: User;
let userFollowRequested: User; let userFollowRequested: User;
beforeAll(async () => { beforeAll(
async () => {
app = await startServer(); app = await startServer();
}, 1000 * 60 * 2); },
1000 * 60 * 2,
);
beforeAll(async () => { beforeAll(
async () => {
root = await signup({ username: "root" }); root = await signup({ username: "root" });
alice = await signup({ username: "alice" }); alice = await signup({ username: "alice" });
aliceNote = (await post(alice, { text: "test" })) as any; aliceNote = (await post(alice, { text: "test" })) as any;
@ -245,15 +249,21 @@ describe("ユーザー", () => {
// @alice -> @replyingへのリプライ。Promise.allで一気に作るとtimeoutしてしまうのでreduceで一つ一つawaitする // @alice -> @replyingへのリプライ。Promise.allで一気に作るとtimeoutしてしまうのでreduceで一つ一つawaitする
usersReplying = await [...Array(10)] usersReplying = await [...Array(10)]
.map((_, i) => i) .map((_, i) => i)
.reduce(async (acc, i) => { .reduce(
async (acc, i) => {
const u = await signup({ username: `replying${i}` }); const u = await signup({ username: `replying${i}` });
for (let j = 0; j < 10 - i; j++) { for (let j = 0; j < 10 - i; j++) {
const p = await post(u, { text: `test${j}` }); const p = await post(u, { text: `test${j}` });
await post(alice, { text: `@${u.username} test${j}`, replyId: p.id }); await post(alice, {
text: `@${u.username} test${j}`,
replyId: p.id,
});
} }
return (await acc).concat(u); return (await acc).concat(u);
}, Promise.resolve([] as User[])); },
Promise.resolve([] as User[]),
);
userNoNote = await signup({ username: "userNoNote" }); userNoNote = await signup({ username: "userNoNote" });
userNotExplorable = await signup({ username: "userNotExplorable" }); userNotExplorable = await signup({ username: "userNotExplorable" });
@ -263,7 +273,10 @@ describe("ユーザー", () => {
await post(userLocking, { text: "test" }); await post(userLocking, { text: "test" });
await api("i/update", { isLocked: true }, userLocking); await api("i/update", { isLocked: true }, userLocking);
userAdmin = await signup({ username: "userAdmin" }); userAdmin = await signup({ username: "userAdmin" });
roleAdmin = await role(root, { isAdministrator: true, name: "Admin Role" }); roleAdmin = await role(root, {
isAdministrator: true,
name: "Admin Role",
});
await api( await api(
"admin/roles/assign", "admin/roles/assign",
{ userId: userAdmin.id, roleId: roleAdmin.id }, { userId: userAdmin.id, roleId: roleAdmin.id },
@ -325,7 +338,11 @@ describe("ユーザー", () => {
); );
userDeletedByAdmin = await signup({ username: "userDeletedByAdmin" }); userDeletedByAdmin = await signup({ username: "userDeletedByAdmin" });
await post(userDeletedByAdmin, { text: "test" }); await post(userDeletedByAdmin, { text: "test" });
await api("admin/delete-account", { userId: userDeletedByAdmin.id }, root); await api(
"admin/delete-account",
{ userId: userDeletedByAdmin.id },
root,
);
userFollowingAlice = await signup({ username: "userFollowingAlice" }); userFollowingAlice = await signup({ username: "userFollowingAlice" });
await post(userFollowingAlice, { text: "test" }); await post(userFollowingAlice, { text: "test" });
await api("following/create", { userId: alice.id }, userFollowingAlice); await api("following/create", { userId: alice.id }, userFollowingAlice);
@ -358,7 +375,9 @@ describe("ユーザー", () => {
{ userId: userFollowRequested.id }, { userId: userFollowRequested.id },
userFollowRequesting, userFollowRequesting,
); );
}, 1000 * 60 * 10); },
1000 * 60 * 10,
);
afterAll(async () => { afterAll(async () => {
await app.close(); await app.close();

View file

@ -1476,7 +1476,8 @@
(a.weightSizeMin > 0 && a.weightSizeMax > a.weightSizeMin (a.weightSizeMin > 0 && a.weightSizeMax > a.weightSizeMin
? (this.textHeight = ? (this.textHeight =
a.weightSize * a.weightSize *
(a.weightSizeMin + (a.weightSizeMax - a.weightSizeMin) * c)) (a.weightSizeMin +
(a.weightSizeMax - a.weightSizeMin) * c))
: (this.textHeight = g(1, b * a.weightSize))); : (this.textHeight = g(1, b * a.weightSize)));
}), }),
(d.SetShadowColourFixed = function (a, b, c) { (d.SetShadowColourFixed = function (a, b, c) {

View file

@ -1023,8 +1023,9 @@ async function post() {
if (postAccount.value) { if (postAccount.value) {
const storedAccounts = await getAccounts(); const storedAccounts = await getAccounts();
token = storedAccounts.find((x) => x.id === postAccount.value.id) token = storedAccounts.find(
?.token; (x) => x.id === postAccount.value.id,
)?.token;
} }
posting.value = true; posting.value = true;

View file

@ -62,7 +62,9 @@ const relative = computed<string>(() => {
n: Math.floor(ago / 3600).toString(), n: Math.floor(ago / 3600).toString(),
}) })
: ago >= 60 : ago >= 60
? i18n.t("_ago.minutesAgo", { n: (~~(ago / 60)).toString() }) ? i18n.t("_ago.minutesAgo", {
n: (~~(ago / 60)).toString(),
})
: ago >= 10 : ago >= 10
? i18n.t("_ago.secondsAgo", { ? i18n.t("_ago.secondsAgo", {
n: (~~(ago % 60)).toString(), n: (~~(ago % 60)).toString(),

View file

@ -7,7 +7,7 @@ export const i18n = markRaw(new I18n(locale));
// このファイルに書きたくないけどここに書かないと何故かVeturが認識しない // このファイルに書きたくないけどここに書かないと何故かVeturが認識しない
declare module "@vue/runtime-core" { declare module "@vue/runtime-core" {
interface ComponentCustomProperties { interface ComponentCustomProperties {
$t: typeof i18n["t"]; $t: (typeof i18n)["t"];
$ts: typeof i18n["locale"]; $ts: (typeof i18n)["locale"];
} }
} }

View file

@ -6,7 +6,7 @@ import { defaultStore } from "@/store";
export interface UnicodeEmojiDef { export interface UnicodeEmojiDef {
emoji: string; emoji: string;
category: typeof unicodeEmojiCategories[number]; category: (typeof unicodeEmojiCategories)[number];
skin_tone_support: boolean; skin_tone_support: boolean;
slug: string; slug: string;
keywords?: string[]; keywords?: string[];

View file

@ -17,7 +17,15 @@ export function dateUTC(time: number[]): Date {
: time.length === 6 : time.length === 6
? Date.UTC(time[0], time[1], time[2], time[3], time[4], time[5]) ? Date.UTC(time[0], time[1], time[2], time[3], time[4], time[5])
: time.length === 7 : time.length === 7
? Date.UTC(time[0], time[1], time[2], time[3], time[4], time[5], time[6]) ? Date.UTC(
time[0],
time[1],
time[2],
time[3],
time[4],
time[5],
time[6],
)
: null; : null;
if (!d) throw "wrong number of arguments"; if (!d) throw "wrong number of arguments";

View file

@ -421,7 +421,7 @@ export class ColdDeviceStorage {
public static get<T extends keyof typeof ColdDeviceStorage.default>( public static get<T extends keyof typeof ColdDeviceStorage.default>(
key: T, key: T,
): typeof ColdDeviceStorage.default[T] { ): (typeof ColdDeviceStorage.default)[T] {
// TODO: indexedDBにする // TODO: indexedDBにする
// ただしその際はnullチェックではなくキー存在チェックにしないとダメ // ただしその際はnullチェックではなくキー存在チェックにしないとダメ
// (indexedDBはnullを保存できるため、ユーザーが意図してnullを格納した可能性がある) // (indexedDBはnullを保存できるため、ユーザーが意図してnullを格納した可能性がある)
@ -435,7 +435,7 @@ export class ColdDeviceStorage {
public static set<T extends keyof typeof ColdDeviceStorage.default>( public static set<T extends keyof typeof ColdDeviceStorage.default>(
key: T, key: T,
value: typeof ColdDeviceStorage.default[T], value: (typeof ColdDeviceStorage.default)[T],
): void { ): void {
// 呼び出し側のバグ等で undefined が来ることがある // 呼び出し側のバグ等で undefined が来ることがある
// undefined を文字列として localStorage に入れると参照する際の JSON.parse でコケて不具合の元になるため無視 // undefined を文字列として localStorage に入れると参照する際の JSON.parse でコケて不具合の元になるため無視

View file

@ -31,7 +31,7 @@ export interface Column {
antennaId?: string; antennaId?: string;
channelId?: string; channelId?: string;
listId?: string; listId?: string;
includingTypes?: typeof notificationTypes[number][]; includingTypes?: (typeof notificationTypes)[number][];
tl?: "home" | "local" | "social" | "recommended" | "global"; tl?: "home" | "local" | "social" | "recommended" | "global";
} }