Skip to content

Commit

Permalink
use declared base class
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Jun 3, 2024
1 parent 849f199 commit 16e9e07
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 86 deletions.
4 changes: 2 additions & 2 deletions src/server/backend/$base/server/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export abstract class AdminProvider<Id> extends IdTransformable {
>,
]
>
abstract userDetail(query: { id: Id }): PromiseLike<UserCompact<Id> & UserOptional>
abstract updateUserDetail(query: { id: Id }, updateFields: Partial<UserCompact<Id> & UserOptional>): PromiseLike<UserCompact<Id> & UserOptional>
abstract userDetail(query: { id: Id }): Promise<UserCompact<Id> & UserOptional>
abstract updateUserDetail(query: { id: Id }, updateFields: Partial<UserCompact<Id> & UserOptional>): Promise<UserCompact<Id> & UserOptional>
}
6 changes: 3 additions & 3 deletions src/server/backend/$base/server/article/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export abstract class ArticleProvider {
abstract get(opt: {
slug: string
fallback: boolean
user: UserCompact<any>
}): PromiseLike<(ArticleProvider.Content & ArticleProvider.Meta & ArticleProvider.Version & ArticleProvider.AccessControl) | undefined>
user?: UserCompact<any>
}): Promise<(ArticleProvider.Content & ArticleProvider.Meta & ArticleProvider.Version & ArticleProvider.AccessControl) | undefined>

abstract save(opt: {
slug: string
json: ArticleProvider.JSONContent
privilege: ArticleProvider.Meta['privilege']
user: UserCompact<any>
}): PromiseLike<void>
}): Promise<void>

async delete(opt: { slug: string; user: UserCompact<any> }) {
return ArticleProvider.deleteLocal(opt)
Expand Down
13 changes: 7 additions & 6 deletions src/server/backend/$base/server/clan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import type { PaginatedResult } from '~/def/pagination'
import type { RankingSystemScore } from '~/def/score'

export abstract class ClanProvider<Id> extends IdTransformable {
abstract search(opt: ClanProvider.SearchParam): PromiseLike<ClanProvider.SearchResult<Id>>
abstract detail(opt: ClanProvider.DetailParam<Id>): PromiseLike<ClanProvider.DetailResult<Id>>
abstract users(opt: ClanProvider.UsersParam<Id>): PromiseLike<ClanProvider.UsersResult<Id>>
abstract getClanRelation(opt: ClanProvider.ChangeRelationRequestParam<Id>): PromiseLike<ClanRelation>
abstract joinRequest(opt: ClanProvider.ChangeRelationRequestParam<Id>): PromiseLike<ClanRelation>
abstract leaveRequest(opt: ClanProvider.ChangeRelationRequestParam<Id>): PromiseLike<ClanRelation>
abstract search(opt: ClanProvider.SearchParam): Promise<ClanProvider.SearchResult<Id>>
abstract detail(opt: ClanProvider.DetailParam<Id>): Promise<ClanProvider.DetailResult<Id>>
abstract users(opt: ClanProvider.UsersParam<Id>): Promise<ClanProvider.UsersResult<Id>>
abstract getClanRelation(opt: ClanProvider.ChangeRelationRequestParam<Id>): Promise<ClanRelation>
abstract joinRequest(opt: ClanProvider.ChangeRelationRequestParam<Id>): Promise<ClanRelation>
abstract leaveRequest(opt: ClanProvider.ChangeRelationRequestParam<Id>): Promise<ClanRelation>
abstract bests(opt: ClanProvider.BestsParam<Id>): Promise<ClanProvider.BestsResult<Id>>
}

export namespace ClanProvider {
Expand Down
10 changes: 5 additions & 5 deletions src/server/backend/$base/server/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ export namespace MapProvider {
| LocalBeatmapCompact<Id> & { beatmapset: LocalBeatmapset<Id> }
}
export abstract class MapProvider<Id, ForeignId> extends IdTransformable {
abstract getBeatmapset(query: MapProvider.IdQuery<Id>): PromiseLike<MapProvider.BeatmapsetWithMaps<Id, ForeignId>>
abstract getBeatmapset(query: MapProvider.IdQuery<Id>): Promise<MapProvider.BeatmapsetWithMaps<Id, ForeignId>>
abstract getBeatmap(
query: string
): PromiseLike<BeatmapWithMeta<
): Promise<BeatmapWithMeta<
RankingStatus,
Id,
unknown
ForeignId
>>
abstract searchBeatmap(opt: { keyword: string; limit: number; filters?: Tag[] }): PromiseLike<
abstract searchBeatmap(opt: { keyword: string; limit: number; filters?: Tag[] }): Promise<
MapProvider.BeatmapWithBeamapset<Id, ForeignId>[]
>
abstract searchBeatmapset(opt: {
keyword: string
limit: number
filters?: Tag[]
}): PromiseLike<Beatmapset<Id, unknown>[]>
}): Promise<Beatmapset<Id, ForeignId>[]>
}
8 changes: 4 additions & 4 deletions src/server/backend/$base/server/rank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ export abstract class RankProvider<Id> extends IdTransformable {
query: RankProvider.BaseQuery & RankProvider.Pagination & {
rankingSystem: LeaderboardRankingSystem
}
): PromiseLike<ComponentLeaderboard<Id>[]>
): Promise<ComponentLeaderboard<Id>[]>

abstract countLeaderboard(
query: RankProvider.BaseQuery & {
rankingSystem: LeaderboardRankingSystem
}
): PromiseLike<number>
): Promise<number>

abstract beatmap(
query: RankProvider.BaseQueryOptionalMode & RankProvider.Pagination & {
rankingSystem: RankingSystem
md5: string
}
): PromiseLike<BeatmapLeaderboard<Id>[]>
): Promise<BeatmapLeaderboard<Id>[]>

abstract countBeatmap(
query: RankProvider.BaseQueryOptionalMode & {
rankingSystem: RankingSystem
md5: string
}
): PromiseLike<number>
): Promise<number>
}
6 changes: 3 additions & 3 deletions src/server/backend/$base/server/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export namespace ScoreProvider {
}

export abstract class ScoreProvider<TScoreId, TId> extends Mixin(IdTransformable, ScoreIdTransformable) {
abstract id(id: TScoreId): PromiseLike<
abstract id(id: TScoreId): Promise<
| (RulesetScore<TScoreId, TId, ActiveMode, ActiveRuleset, PPRankingSystem> & {
user: UserCompact<TId>
})
>
abstract findOne(opt: ScoreProvider.SearchQuery<TId>): PromiseLike<ScoreProvider.ScoreWithUser<TScoreId, TId>>
abstract findMany(opt: ScoreProvider.SearchQuery<TId>): PromiseLike<ScoreProvider.ScoreWithUser<TScoreId, TId>[]>
abstract findOne(opt: ScoreProvider.SearchQuery<TId>): Promise<ScoreProvider.ScoreWithUser<TScoreId, TId>>
abstract findMany(opt: ScoreProvider.SearchQuery<TId>): Promise<ScoreProvider.ScoreWithUser<TScoreId, TId>[]>

// abstract recents(opt: ClanProvider.RecentScoresParam<Id, M extends Mode, R extends AvailableRuleset<M>, RS extends LeaderboardRankingSystem>): Promise<ScoreP<Id, Mode, R, RS>[]>
// abstract tops(opt: ClanProvider.TopScoresParam<Id, M extends Mode, R extends AvailableRuleset<M>, RS extends LeaderboardRankingSystem>): Promise<ScoreP<Id, Mode, R, RS>[]>
Expand Down
14 changes: 7 additions & 7 deletions src/server/backend/$base/server/session/session-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export const sessionConfig = {

export abstract class SessionStore<TSession extends Session<any>, TSessionId extends SessionIdType<TSession> = SessionIdType<TSession>> implements Monitored {
abstract [Monitored.status]: Monitored[typeof Monitored.status]
abstract get(key: TSessionId): PromiseLike<Readonly<TSession> | undefined>
abstract set(key: TSessionId, value: TSession): PromiseLike<[TSessionId, Readonly<TSession>]>
abstract destroy(key: TSessionId): PromiseLike<boolean>
abstract forEach(cb: (session: TSession, id: TSessionId) => void | PromiseLike<void>): PromiseLike<void>
abstract findAll(query: Partial<Pick<TSession, 'OS' | 'userId'>>): PromiseLike<Record<TSessionId, Readonly<TSession>>>
abstract get(key: TSessionId): Promise<Readonly<TSession> | undefined>
abstract set(key: TSessionId, value: TSession): Promise<[TSessionId, Readonly<TSession>]>
abstract destroy(key: TSessionId): Promise<boolean>
abstract forEach(cb: (session: TSession, id: TSessionId) => void | Promise<void>): Promise<void>
abstract findAll(query: Partial<Pick<TSession, 'OS' | 'userId'>>): Promise<Record<TSessionId, Readonly<TSession>>>
}

export abstract class HouseKeeperSession<TSession extends Session<any>, TSessionId extends SessionIdType<TSession> = SessionIdType<TSession>> extends SessionStore<TSession> implements SessionStore<TSession> {
#houseKeeping: Partial<Record<'minutely' | 'hourly' | 'daily', (store: SessionStore<TSession>, _config: typeof sessionConfig) => PromiseLike<void>>> = {
#houseKeeping: Partial<Record<'minutely' | 'hourly' | 'daily', (store: SessionStore<TSession>, _config: typeof sessionConfig) => Promise<void>>> = {
async minutely(this: MemorySessionStore<TSession>, sessionStore) {
sessionStore.forEach((session, sessionId) => this.#removeIfExpired(session, sessionId))
},
Expand Down Expand Up @@ -64,7 +64,7 @@ export class MemorySessionStore<TSession extends Session<any>, TSessionId extend
return this.store.delete(key)
}

async forEach(cb: (session: TSession, id: TSessionId) => void | PromiseLike<void>): Promise<void> {
async forEach(cb: (session: TSession, id: TSessionId) => void | Promise<void>): Promise<void> {
return this.store.forEach(cb)
}

Expand Down
20 changes: 16 additions & 4 deletions src/server/backend/$base/server/user-relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@ import type { UserCompact } from '~/def/user'
import type { UserRelationship } from '~/def/user-relationship'

export abstract class UserRelationProvider<Id> extends IdTransformable {
abstract get(query: { user: { id: Id } }): PromiseLike<Array<UserCompact<Id> & UserRelationship>>
abstract get(query: { user: { id: Id } }): Promise<Array<UserCompact<Id> & UserRelationship>>
abstract getOne(
fromUser: { id: Id },
toUser: { id: Id }
): PromiseLike<Relationship | void>
): Promise<Relationship | void>
abstract removeOne(query: {
fromUser: UserCompact<Id>
targetUser: UserCompact<Id>
type: Relationship
}): PromiseLike<void>
}): Promise<void>
abstract count(query: {
user: UserCompact<Id>
type: Relationship
}): PromiseLike<number>
}): Promise<number>

abstract createOneRelationship({
fromUser,
targetUser,
type,
}: {
fromUser: UserCompact<Id>
targetUser: UserCompact<Id>
type: Relationship
}): Promise<void>

abstract notMutual(user: { id: Id }): Promise<UserCompact<Id>[]>
}
51 changes: 28 additions & 23 deletions src/server/backend/$base/server/user.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { JSONContent } from '@tiptap/core'
import type { ExtractLocationSettings, ExtractSettingType } from '../@define-setting'
import type { Composition } from './@common'
import { IdTransformable } from './@extends'
import type { MailTokenProvider } from './mail-token'
import { type ArticleProvider } from '.'
import type { settings } from '$active/dynamic-settings'
import type { Mode, Ruleset } from '~/def'
import type { BeatmapSource, RankingStatus } from '~/def/beatmap'
Expand Down Expand Up @@ -43,23 +43,23 @@ export namespace UserProvider {
mode: Mode
ruleset: Ruleset
rankingSystem: RankingSystem
rankingStatus: RankingStatus[]
rankingStatus?: RankingStatus[]
}

export type UserCompact<Id> = UserCompact$2<Id>
}

export abstract class UserProvider<Id, ScoreId> extends IdTransformable {
abstract uniqueIdent(input: string): PromiseLike<boolean>
abstract uniqueIdent(input: string): Promise<boolean>

abstract getCompact(
opt: UserProvider.OptType & { scope: Scope }
): Promise<UserCompact<Id>>

abstract testPassword(
opt: UserProvider.OptType & { scope: Scope },
opt: UserProvider.OptType,
hashedPassword: string,
): Promise<[boolean, UserCompact<Id> | undefined]>
): Promise<[boolean, UserCompact<Id>]>

abstract getCompactById(id: Id): Promise<UserCompact<Id>>

Expand All @@ -68,7 +68,7 @@ export abstract class UserProvider<Id, ScoreId> extends IdTransformable {
abstract getStatistics(query: {
id: Id
flag: CountryCode
}): PromiseLike<UserStatistic>
}): Promise<UserStatistic>

abstract getFull<
Excludes extends Partial<
Expand Down Expand Up @@ -119,29 +119,29 @@ export abstract class UserProvider<Id, ScoreId> extends IdTransformable {
}
}

abstract changeEmail(user: { id: Id }, newEmail: MailTokenProvider.Email): PromiseLike<Pick<UserOptional, 'email'>>
abstract changeEmail(user: { id: Id }, newEmail: MailTokenProvider.Email): Promise<Pick<UserOptional, 'email'>>

abstract changeSettings(
user: { id: Id },
input: {
// email?: string
name?: string
flag?: CountryCode
preferredMode: {
preferredMode?: {
mode: Mode
ruleset: Ruleset
}
}
): PromiseLike<UserCompact<Id>>
): Promise<UserCompact<Id>>

abstract changeUserpage(
user: { id: Id },
input: {
profile: JSONContent
profile: ArticleProvider.JSONContent
}
): PromiseLike<{
): Promise<{
html: string
raw: JSONContent
raw: ArticleProvider.JSONContent
}>

abstract changeVisibility(
Expand All @@ -151,28 +151,28 @@ export abstract class UserProvider<Id, ScoreId> extends IdTransformable {
name?: string
userpageContent?: string
}
): PromiseLike<UserCompact<Id>>
): Promise<UserCompact<Id>>

abstract changePasswordNoCheck(user: { id: Id }, newPassword: string): PromiseLike<void>
abstract changePasswordNoCheck(user: { id: Id }, newPassword: string): Promise<void>

abstract changePassword(
user: { id: Id },
oldPasswordMD5: string,
newPasswordMD5: string
): PromiseLike<UserCompact<Id>>
): Promise<UserCompact<Id>>

abstract changeAvatar(user: { id: Id }, avatar: Uint8Array): PromiseLike<string>
abstract changeAvatar(user: { id: Id }, avatar: Uint8Array): Promise<string>

abstract search(opt: {
keyword: string
limit: number
}): PromiseLike<Array<UserCompact<Id> & { clan: UserClan<Id> | null }>>
}): Promise<Array<UserCompact<Id> & { clan: UserClan<Id> | null }>>

abstract count(opt: {
keyword?: string
}): PromiseLike<number>
}): Promise<number>

abstract status({ id }: { id: Id }): PromiseLike<{
abstract status({ id }: { id: Id }): Promise<{
status: UserStatus.Offline
lastSeen: Date
} | {
Expand All @@ -186,7 +186,7 @@ export abstract class UserProvider<Id, ScoreId> extends IdTransformable {
md5: string
version: string
creator: string
beatmapset?: {
beatmapset: {
id: number
foreignId: number
meta: {
Expand All @@ -200,7 +200,12 @@ export abstract class UserProvider<Id, ScoreId> extends IdTransformable {
}
} | null>

abstract register(opt: { name: string; safeName: string; email: string; passwordMd5: string }): PromiseLike<UserCompact<Id>>
abstract register(opt: {
name: string
safeName?: string
email: string
passwordMd5: string
}): Promise<UserCompact<Id>>

abstract getDynamicSettings(user: { id: Id }): Promise<ExtractSettingType<ExtractLocationSettings<DynamicSettingStore.Server, typeof settings>>>

Expand All @@ -210,13 +215,13 @@ export abstract class UserProvider<Id, ScoreId> extends IdTransformable {
Mode extends ActiveMode,
Ruleset extends ActiveRuleset,
RankingSystem extends LeaderboardRankingSystem,
>(query: UserProvider.BaseQuery<Id, Mode, Ruleset, RankingSystem>): PromiseLike<RankingSystemScore<ScoreId, Id, Mode, RankingSystem>[]>
>(query: UserProvider.BaseQuery<Id, Mode, Ruleset, RankingSystem>): Promise<RankingSystemScore<ScoreId, Id, Mode, RankingSystem>[]>

abstract getTops<
Mode extends ActiveMode,
Ruleset extends ActiveRuleset,
RankingSystem extends LeaderboardRankingSystem,
>(query: UserProvider.BaseQuery<Id, Mode, Ruleset, RankingSystem>): PromiseLike<{
>(query: UserProvider.BaseQuery<Id, Mode, Ruleset, RankingSystem>): Promise<{
count: number
scores: RankingSystemScore<ScoreId, Id, Mode, RankingSystem>[]
}>
Expand Down
6 changes: 3 additions & 3 deletions src/server/backend/bancho.py/api-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type LiveUserStatus =
status: 200
statusText: string
ok: true
json: () => PromiseLike<
json: () => Promise<
| {
status: 'success'
player_status: {
Expand Down Expand Up @@ -71,13 +71,13 @@ type LiveUserStatus =
ok: false
status: 404
statusText: string
json: () => PromiseLike<{ status: 'Player not found.' }>
json: () => Promise<{ status: 'Player not found.' }>
}
| {
ok: false
status: 400
statusText: string
json: () => PromiseLike<{ status: 'Must provide either id OR name!' }>
json: () => Promise<{ status: 'Must provide either id OR name!' }>
}

function createFetch(endpoint: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/backend/bancho.py/server/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ArticleProvider as Base } from '$base/server/article'
import type { UserCompact } from '~/def/user'

export class ArticleProvider extends Base {
async get(opt: { slug: string; fallback?: boolean; user?: UserCompact<unknown> }) {
async get(opt: { slug: string; fallback: boolean; user?: UserCompact<unknown> }) {
const content = await this.getLocal(opt)
if (!content) {
return undefined
Expand Down
2 changes: 1 addition & 1 deletion src/server/backend/bancho.py/server/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class MapProvider implements Base<Id, Id> {
keyword: string
limit: number
filters?: Tag[]
}): Promise<Beatmapset<number, unknown>[]> {
}): Promise<Beatmapset<Id, Id>[]> {
const idKw = stringToId(keyword)
const sql = this.drizzle.select({
id: schema.sources.id,
Expand Down
Loading

0 comments on commit 16e9e07

Please sign in to comment.