Refactor stores and types for improved data handling and schema definitions
All checks were successful
SteamWarCI Build successful
All checks were successful
SteamWarCI Build successful
- Consolidated player fetching logic in stores.ts to utilize dataRepo. - Introduced teams fetching logic in stores.ts. - Updated permissions structure in stores.ts for better clarity. - Enhanced data schemas in data.ts with new ResponseUser and ResponseTeam schemas. - Expanded event-related schemas in event.ts to include groups, relations, and event creation/update structures. - Improved code formatting for consistency and readability across files.
This commit is contained in:
@@ -17,41 +17,45 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import type {Player, SchematicType} from "@type/data";
|
||||
import {PlayerSchema} from "@type/data.ts";
|
||||
import {cached, cachedFamily} from "./cached";
|
||||
import type {Team} from "@type/team.ts";
|
||||
import {TeamSchema} from "@type/team";
|
||||
import {derived, get, writable} from "svelte/store";
|
||||
import {z} from "zod";
|
||||
import {fetchWithToken, tokenStore} from "@repo/repo.ts";
|
||||
import {pageRepo} from "@repo/page.ts";
|
||||
import {dataRepo} from "@repo/data.ts";
|
||||
import {permsRepo} from "@repo/perms.ts";
|
||||
import type { Player, SchematicType } from "@type/data";
|
||||
import { PlayerSchema } from "@type/data.ts";
|
||||
import { cached, cachedFamily } from "./cached";
|
||||
import type { Team } from "@type/team.ts";
|
||||
import { TeamSchema } from "@type/team";
|
||||
import { derived, get, writable } from "svelte/store";
|
||||
import { z } from "zod";
|
||||
import { fetchWithToken, tokenStore } from "@repo/repo.ts";
|
||||
import { pageRepo } from "@repo/page.ts";
|
||||
import { dataRepo } from "@repo/data.ts";
|
||||
import { permsRepo } from "@repo/perms.ts";
|
||||
|
||||
export const schemTypes = cached<SchematicType[]>([], () =>
|
||||
fetchWithToken(get(tokenStore), "/data/admin/schematicTypes")
|
||||
.then(res => res.json()));
|
||||
export const schemTypes = cached<SchematicType[]>([], () => fetchWithToken(get(tokenStore), "/data/admin/schematicTypes").then((res) => res.json()));
|
||||
|
||||
export const players = cached<Player[]>([], async () => {
|
||||
const res = await fetchWithToken(get(tokenStore), "/data/admin/users");
|
||||
return z.array(PlayerSchema).parse(await res.json());
|
||||
return get(dataRepo).getPlayers();
|
||||
});
|
||||
|
||||
export const permissions = cached({
|
||||
perms: [],
|
||||
prefixes: {},
|
||||
}, async () => {
|
||||
return get(permsRepo).listPerms();
|
||||
export const teams = cached<Team[]>([], async () => {
|
||||
return get(dataRepo).getTeams();
|
||||
});
|
||||
|
||||
export const permissions = cached(
|
||||
{
|
||||
perms: [],
|
||||
prefixes: {},
|
||||
},
|
||||
async () => {
|
||||
return get(permsRepo).listPerms();
|
||||
}
|
||||
);
|
||||
|
||||
export const gamemodes = cached<string[]>([], async () => {
|
||||
const res = await fetchWithToken(get(tokenStore), "/data/admin/gamemodes");
|
||||
return z.array(z.string()).parse(await res.json());
|
||||
});
|
||||
|
||||
export const maps = cachedFamily<string, string[]>([], async (gamemode) => {
|
||||
if (get(gamemodes).every(value => value !== gamemode)) return [];
|
||||
if (get(gamemodes).every((value) => value !== gamemode)) return [];
|
||||
|
||||
const res = await fetchWithToken(get(tokenStore), `/data/admin/gamemodes/${gamemode}/maps`);
|
||||
if (!res.ok) {
|
||||
@@ -66,17 +70,12 @@ export const groups = cached<string[]>([], async () => {
|
||||
return z.array(z.string()).parse(await res.json());
|
||||
});
|
||||
|
||||
export const teams = cached<Team[]>([], async () => {
|
||||
const res = await fetchWithToken(get(tokenStore), "/team");
|
||||
return z.array(TeamSchema).parse(await res.json());
|
||||
});
|
||||
|
||||
export const branches = cached<string[]>([], async () => {
|
||||
const res = await get(pageRepo).getBranches();
|
||||
return z.array(z.string()).parse(res);
|
||||
});
|
||||
|
||||
export const server = derived(dataRepo, $dataRepo => $dataRepo.getServer());
|
||||
export const server = derived(dataRepo, ($dataRepo) => $dataRepo.getServer());
|
||||
|
||||
export const isWide = writable(typeof window !== "undefined" && window.innerWidth >= 640);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user