chore: format

This commit is contained in:
naskya 2024-02-12 02:50:57 +09:00
parent b432b88923
commit 49fa0975ca
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
113 changed files with 799 additions and 755 deletions

View file

@ -67,7 +67,7 @@ export const refs = {
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 =
| "null"
@ -210,9 +210,13 @@ export type SchemaTypeDef<p extends Schema> = p["type"] extends "null"
? p["items"]["anyOf"] extends ReadonlyArray<Schema>
? UnionSchemaType<NonNullable<p["items"]["anyOf"]>>[]
: p["items"]["oneOf"] extends ReadonlyArray<Schema>
? ArrayUnion<UnionSchemaType<NonNullable<p["items"]["oneOf"]>>>
? ArrayUnion<
UnionSchemaType<NonNullable<p["items"]["oneOf"]>>
>
: p["items"]["allOf"] extends ReadonlyArray<Schema>
? UnionToIntersection<UnionSchemaType<NonNullable<p["items"]["allOf"]>>>[]
? UnionToIntersection<
UnionSchemaType<NonNullable<p["items"]["allOf"]>>
>[]
: never
: p["items"] extends NonNullable<Schema>
? SchemaTypeDef<p["items"]>[]

View file

@ -51,5 +51,5 @@ export class MutedNote {
enum: mutedNoteReasons,
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
*/
@Column("enum", { enum: noteVisibilities })
public visibility: typeof noteVisibilities[number];
public visibility: (typeof noteVisibilities)[number];
@Index({ unique: true })
@Column("varchar", {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -99,7 +99,7 @@ export default define(meta, paramDef, async (ps, me) => {
async function fetchAny(
uri: string,
me: CacheableLocalUser | null | undefined,
): Promise<SchemaType<typeof meta["res"]> | null> {
): Promise<SchemaType<(typeof meta)["res"]> | null> {
// Wait if blocked.
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;
if (ps.mutingNotificationTypes !== undefined)
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.isExplorable === "boolean")
updates.isExplorable = ps.isExplorable;

View file

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

View file

@ -44,13 +44,13 @@ type KeyToColumnName<T extends string> = T extends `${infer R1}.${infer R2}`
: T;
type Columns<S extends Schema> = {
[K in
keyof S as `${typeof columnPrefix}${KeyToColumnName<string & K>}`]: number;
[K in keyof S as `${typeof columnPrefix}${KeyToColumnName<
string & K
>}`]: number;
};
type TempColumnsForUnique<S extends Schema> = {
[K in
keyof S as `${typeof uniqueTempColumnPrefix}${KeyToColumnName<
[K in keyof S as `${typeof uniqueTempColumnPrefix}${KeyToColumnName<
string & K
>}`]: 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> {
const log = {} as Record<keyof T, number>;
for (const [k, v] of Object.entries(this.schema) as [
keyof typeof this["schema"],
keyof (typeof this)["schema"],
this["schema"][string],
][]) {
if (v.accumulate && latest) {

View file

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

View file

@ -224,11 +224,15 @@ describe("ユーザー", () => {
let userFollowRequesting: User;
let userFollowRequested: User;
beforeAll(async () => {
beforeAll(
async () => {
app = await startServer();
}, 1000 * 60 * 2);
},
1000 * 60 * 2,
);
beforeAll(async () => {
beforeAll(
async () => {
root = await signup({ username: "root" });
alice = await signup({ username: "alice" });
aliceNote = (await post(alice, { text: "test" })) as any;
@ -245,7 +249,8 @@ describe("ユーザー", () => {
// @alice -> @replyingへのリプライ。Promise.allで一気に作るとtimeoutしてしまうのでreduceで一つ一つawaitする
usersReplying = await [...Array(10)]
.map((_, i) => i)
.reduce(async (acc, i) => {
.reduce(
async (acc, i) => {
const u = await signup({ username: `replying${i}` });
for (let j = 0; j < 10 - i; j++) {
const p = await post(u, { text: `test${j}` });
@ -256,7 +261,9 @@ describe("ユーザー", () => {
}
return (await acc).concat(u);
}, Promise.resolve([] as User[]));
},
Promise.resolve([] as User[]),
);
userNoNote = await signup({ username: "userNoNote" });
userNotExplorable = await signup({ username: "userNotExplorable" });
@ -331,7 +338,11 @@ describe("ユーザー", () => {
);
userDeletedByAdmin = await signup({ username: "userDeletedByAdmin" });
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" });
await post(userFollowingAlice, { text: "test" });
await api("following/create", { userId: alice.id }, userFollowingAlice);
@ -364,7 +375,9 @@ describe("ユーザー", () => {
{ userId: userFollowRequested.id },
userFollowRequesting,
);
}, 1000 * 60 * 10);
},
1000 * 60 * 10,
);
afterAll(async () => {
await app.close();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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