Skip to content

Commit

Permalink
raw collections always include keys
Browse files Browse the repository at this point in the history
used to be like 50/50 for either way, also fixed incorrect types

mostly did this for better bot backups
  • Loading branch information
3vorp committed Nov 15, 2023
1 parent fd94dec commit 1b78008
Show file tree
Hide file tree
Showing 30 changed files with 151 additions and 144 deletions.
2 changes: 1 addition & 1 deletion src/v2/controller/contributions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ContributionsController extends Controller {
* Get the raw collection of contributions
*/
@Get("raw")
public async getRaw(): Promise<Contributions> {
public async getRaw(): Promise<Record<string, Contribution>> {
return this.service.getRaw();
}

Expand Down
3 changes: 2 additions & 1 deletion src/v2/controller/file.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Controller, Get, Route, Tags, Security } from "tsoa";
import { FileService } from "../service/file.service";
import { File } from "../interfaces";

@Route("files")
@Tags("Files")
Expand All @@ -11,7 +12,7 @@ export class FileController extends Controller {
*/
@Get("raw")
@Security("bot")
public async getRaw(): Promise<any> {
public async getRaw(): Promise<Record<string, File>> {
return this.service.getRaw();
}
}
4 changes: 2 additions & 2 deletions src/v2/controller/modpacks.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Get, Path, Request, Route, SuccessResponse, Tags } from "tsoa";
import { Request as ExRequest, Response as ExResponse } from "express";
import { Modpacks } from "../interfaces";
import { Modpack } from "../interfaces";
import ModpacksService from "../service/modpacks.service";
import cache from "../tools/cache";

Expand All @@ -13,7 +13,7 @@ export class ModpacksController extends Controller {
* Get the raw collection of mods
*/
@Get("raw")
public async getRaw(): Promise<Modpacks> {
public async getRaw(): Promise<Record<string, Modpack>> {
return this.service.getRaw();
}

Expand Down
4 changes: 2 additions & 2 deletions src/v2/controller/mods.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Get, Path, Request, Route, SuccessResponse, Tags, Response } from "tsoa";
import { Request as ExRequest, Response as ExResponse } from "express";
import { Mods, PackVersions } from "../interfaces";
import { Mod, PackVersions } from "../interfaces";
import { NotFoundError } from "../tools/ApiError";
import ModsService from "../service/mods.service";
import cache from "../tools/cache";
Expand All @@ -14,7 +14,7 @@ export class ModsController extends Controller {
* Get the raw collection of mods
*/
@Get("raw")
public async getRaw(): Promise<Mods> {
public async getRaw(): Promise<Record<string, Mod>> {
return this.service.getRaw();
}

Expand Down
4 changes: 2 additions & 2 deletions src/v2/controller/path.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Body,
Put,
} from "tsoa";
import { Path, InputPath, Paths, PathNewVersionParam } from "../interfaces";
import { Path, InputPath, PathNewVersionParam } from "../interfaces";
import PathService from "../service/path.service";

@Route("paths")
Expand All @@ -22,7 +22,7 @@ export class PathsController extends Controller {
* Get the raw collection of paths
*/
@Get("raw")
public async getRaw(): Promise<Paths> {
public async getRaw(): Promise<Record<string, Path>> {
return this.service.getRaw();
}

Expand Down
2 changes: 1 addition & 1 deletion src/v2/controller/settings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class SettingsController extends Controller {
*/
@SuccessResponse(200)
@Get("raw")
public async getRaw(): Promise<any> {
public async getRaw(): Promise<Record<string, any>> {
return this.settingsService.raw();
}

Expand Down
2 changes: 1 addition & 1 deletion src/v2/controller/texture.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class TextureController extends Controller {
* Get the raw collection of textures
*/
@Get("raw")
public async getRaw(): Promise<Textures> {
public async getRaw(): Promise<Record<string, Texture>> {
return this.service.getRaw();
}

Expand Down
2 changes: 1 addition & 1 deletion src/v2/controller/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class UserController extends Controller {
* Get the raw collection of users
*/
@Get("raw")
public async getRaw(): Promise<Users> {
public async getRaw(): Promise<Record<string, User>> {
return this.userService.getRaw();
}

Expand Down
2 changes: 1 addition & 1 deletion src/v2/controller/uses.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class UsesController extends Controller {
* @returns {Promise<Uses>}
*/
@Get("raw")
public async getRaw(): Promise<Uses> {
public async getRaw(): Promise<Record<string, Use>> {
return this.service.getRaw();
}

Expand Down
2 changes: 1 addition & 1 deletion src/v2/firestorm/textures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const textures = firestorm.collection("textures", (el) => {

return settings
.read_raw()
.then((settings_file: { [key: string]: any }) => {
.then((settings_file: Record<string, any>) => {
urls = settings_file.repositories.raw[pack];
return el.paths();
})
Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export interface FileRepository {
removeFilesByParent(parent: FileParent): Promise<void>;
removeFilesByParentAndUse(parent: FileParent, use: FileUse): Promise<void>;
removeFileByPath(path: string): Promise<void>;
getRaw(): Promise<Files>;
getRaw(): Promise<Record<string, File>>;
}
2 changes: 1 addition & 1 deletion src/v2/interfaces/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface PathRepository {
modifyVersion(old_version: string, new_version: string): void | PromiseLike<void>;
removePathById(path_id: string): Promise<void>;
removePathsByBulk(path_ids: string[]): Promise<void>;
getRaw(): Promise<Paths>;
getRaw(): Promise<Record<string, Path>>;
}

export interface PathNewVersionParam {
Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface SettingsRepository {
getRaw(): Promise<any>;
getRaw(): Promise<Record<string, any>>;
update(body: any): Promise<void>;
}
2 changes: 1 addition & 1 deletion src/v2/interfaces/textures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type TextureProperty = "uses" | "paths" | "contributions" | "mcmeta" | "a

export interface TextureRepository {
changeTexture(id: string, body: TextureCreationParam): Promise<Texture>;
getRaw(): Promise<Textures>;
getRaw(): Promise<Record<string, Texture>>;
getByNameIdAndTag(
tag: string | undefined,
search: string | undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface UserRepository {
getProfileOrCreate(id: string): User | PromiseLike<User>;
getUserProfiles(authors: string[]): Promise<UserProfile[]>;
getNameById(id: string): Promise<UserName>;
getRaw(): Promise<Users>;
getRaw(): Promise<Record<string, User>>;
getNames(): Promise<any>;
getUserById(id: string): Promise<User>;
getUsersByName(name: string): Promise<Users>;
Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/uses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface Uses extends Array<Use> {}
export interface UseRepository {
getUsesByIdAndEdition(id_arr: number[], edition: string): Promise<Uses>;
getUsesByEdition(edition: string): Promise<Uses>;
getRaw(): Promise<Uses>;
getRaw(): Promise<Record<string, Use>>;
getUseByIdOrName(id_or_name: string): Promise<Uses | Use>;
deleteUse(id: string): Promise<void>;
set(use: Use): Promise<Use>;
Expand Down
2 changes: 1 addition & 1 deletion src/v2/repository/firestorm/files.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class FilesFirestormRepository implements FileRepository {
return firestorm.files.delete(path).then(() => {});
}

getRaw(): Promise<Files> {
getRaw(): Promise<Record<string, File>> {
return files.read_raw();
}
}
2 changes: 1 addition & 1 deletion src/v2/repository/firestorm/path.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class PathFirestormRepository implements PathRepository {
.then(() => {});
}

getRaw() {
getRaw(): Promise<Record<string, Path>> {
return paths.read_raw();
}
}
2 changes: 1 addition & 1 deletion src/v2/repository/firestorm/settings.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { settings } from "../../firestorm/index";
import { SettingsRepository } from "../../interfaces";

export default class SettingsFirestormRepository implements SettingsRepository {
getRaw(): Promise<any> {
getRaw(): Promise<Record<string, any>> {
return settings.read_raw();
}

Expand Down
6 changes: 3 additions & 3 deletions src/v2/repository/firestorm/texture.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class TextureFirestormRepository implements TextureRepository {
): Promise<Textures> {
// * none, read raw
if (tag === undefined && search === undefined) {
return this.getRaw();
return this.getRaw().then((res: any) => Object.values(res));
}

// * number id: get + includes tag?
Expand Down Expand Up @@ -75,8 +75,8 @@ export default class TextureFirestormRepository implements TextureRepository {
return textures.search(criterias);
}

public getRaw() {
return textures.read_raw().then((res: any) => Object.values(res));
public getRaw(): Promise<Record<string, Texture>> {
return textures.read_raw();
}

public getURLById(id: number, pack: KnownPacks, version: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/v2/repository/firestorm/use.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export default class UseFirestormRepository implements UseRepository {
]);
}

getRaw(): Promise<Uses> {
return uses.read_raw().then((res: any) => Object.values(res));
getRaw(): Promise<Record<string, Use>> {
return uses.read_raw();
}

getUseByIdOrName(id_or_name: string): Promise<Uses | Use> {
Expand Down
32 changes: 17 additions & 15 deletions src/v2/repository/firestorm/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ import {
} from "../../interfaces";

// eslint-disable-next-line no-underscore-dangle
function __transformUser(user: any): User {
const __transformUser = (user: any): User => ({
// falsy checking and remove warns field (unused)
return {
id: user.id,
username: user.username || "",
uuid: user.uuid || "",
roles: user.roles || [],
media: user.media,
anonymous: user.anonymous || false,
};
}
id: user.id,
username: user.username || "",
uuid: user.uuid || "",
roles: user.roles || [],
media: user.media,
anonymous: user.anonymous || false,
});

export default class UserFirestormRepository implements UserRepository {
getNameById(id: string): Promise<UserName> {
Expand All @@ -34,11 +32,15 @@ export default class UserFirestormRepository implements UserRepository {
}));
}

getRaw(): Promise<Users> {
return users
.read_raw()
.then((res: any) => Object.values(res))
.then((arr: Array<User>) => arr.map((el) => __transformUser(el)));
getRaw(): Promise<Record<string, User>> {
return (
users
.read_raw()
.then((res: Record<string, User>) => Object.entries(res))
// convert to entries to map, convert back to object after mapping done
.then((arr: [string, User][]) => arr.map(([key, el]) => [key, __transformUser(el)]))
.then((arr: [string, User][]) => Object.fromEntries(arr))
);
}

getNames(): Promise<UserNames> {
Expand Down
Loading

0 comments on commit 1b78008

Please sign in to comment.