Change zod schemas location

This commit is contained in:
Kalle (Sendou) 2022-01-16 21:59:33 +02:00
parent 5ed5af2465
commit c8377f5a98
15 changed files with 44 additions and 46 deletions

View File

@ -1,7 +1,7 @@
import * as React from "react";
import { Links, LiveReload, Meta, Outlet, Scripts, useCatch } from "remix";
import type { LinksFunction, LoaderFunction } from "remix";
import { LoggedInUserSchema } from "~/validators/user";
import { LoggedInUserSchema } from "~/utils/schemas";
import { Layout } from "./components/Layout";
import { Catcher } from "./components/Catcher";
import resetStyles from "~/styles/reset.css";

3
app/utils/assertType.ts Normal file
View File

@ -0,0 +1,3 @@
/** @link https://stackoverflow.com/a/69413184 */
// @ts-expect-error helper to assert type to be another compile time
export const assertType = <A, B extends A>() => {}; // eslint-disable-line

View File

@ -1,7 +1,7 @@
import * as React from "react";
import { useMatches } from "remix";
import { z } from "zod";
import { LoggedInUserSchema } from "~/validators/user";
import { LoggedInUserSchema } from "~/utils/schemas";
export const useUser = () => {
const [root] = useMatches();

View File

@ -3,7 +3,7 @@ import type { CSSProperties } from "react";
import { json, useLocation } from "remix";
import type { EventTargetRecorder } from "server/events";
import { z } from "zod";
import { LoggedInUserSchema } from "~/validators/user";
import { LoggedInUserSchema } from "~/utils/schemas";
export function makeTitle(endOfTitle?: string) {
return endOfTitle ? `sendou.ink | ${endOfTitle}` : "sendou.ink";
@ -90,10 +90,6 @@ export function safeJSONParse(value: unknown): unknown {
}
}
/** @link https://stackoverflow.com/a/69413184 */
// @ts-expect-error helper to assert type to be another compile time
export const assertType = <A, B extends A>() => {}; // eslint-disable-line
export type Serialized<T> = {
[P in keyof T]: T[P] extends Date
? string

31
app/utils/schemas.ts Normal file
View File

@ -0,0 +1,31 @@
import type { Mode } from ".prisma/client";
import { z } from "zod";
import type { Unpacked } from "~/utils";
import { assertType } from "./assertType";
type MapList = z.infer<typeof ModeSchema>;
assertType<Unpacked<MapList>, Mode>();
export const ModeSchema = z.enum(["TW", "SZ", "TC", "RM", "CB"]);
export type SeedVariations = z.infer<typeof SeedVariationsSchema>;
export const SeedVariationsSchema = z.enum([
"check-in",
"match",
"tournament-start",
]);
export type LoggedInUser = NonNullable<
z.infer<typeof LoggedInUserSchema>
>["user"];
export const LoggedInUserSchema = z
.object({
user: z
.object({
id: z.string(),
discordId: z.string(),
discordAvatar: z.string().nullable(),
})
.nullish(),
})
.nullish();

View File

@ -1,5 +1,5 @@
import { z } from "zod";
import { ModeSchema } from "~/validators/mode";
import { ModeSchema } from "~/utils/schemas";
export function mapPoolForTest() {
const mapPool: unknown = JSON.parse(

View File

@ -1,8 +0,0 @@
import { Mode } from ".prisma/client";
import { z } from "zod";
import { assertType, Unpacked } from "~/utils";
type MapList = z.infer<typeof ModeSchema>;
assertType<Unpacked<MapList>, Mode>();
export const ModeSchema = z.enum(["TW", "SZ", "TC", "RM", "CB"]);

View File

@ -1,8 +0,0 @@
import { z } from "zod";
export type SeedVariations = z.infer<typeof SeedVariationsSchema>;
export const SeedVariationsSchema = z.enum([
"check-in",
"match",
"tournament-start",
]);

View File

@ -1,16 +0,0 @@
import { z } from "zod";
export type LoggedInUser = NonNullable<
z.infer<typeof LoggedInUserSchema>
>["user"];
export const LoggedInUserSchema = z
.object({
user: z
.object({
id: z.string(),
discordId: z.string(),
discordAvatar: z.string().nullable(),
})
.nullish(),
})
.nullish();

View File

@ -1,4 +1,4 @@
import { LoggedInUser } from "~/validators/user";
import { LoggedInUser } from "~/utils/schemas";
import {
ADMIN_TEST_AVATAR,
ADMIN_TEST_DISCORD_ID,

View File

@ -1,5 +1,5 @@
import { PrismaClient } from "@prisma/client";
import { SeedVariationsSchema } from "~/validators/seedVariations";
import { SeedVariationsSchema } from "~/utils/schemas";
const prisma = new PrismaClient();
import { seed } from "./script";

View File

@ -14,7 +14,7 @@ import { readFile } from "fs/promises";
import path from "path";
import { createTournamentRounds } from "../../app/services/tournament";
import invariant from "tiny-invariant";
import { SeedVariations } from "~/validators/seedVariations";
import { SeedVariations } from "~/utils/schemas";
import { v4 as uuidv4 } from "uuid";
const prisma = new PrismaClient();

View File

@ -6,7 +6,7 @@ import compression from "compression";
import express from "express";
import morgan from "morgan";
import path from "path";
import { LoggedInUser } from "~/validators/user";
import { LoggedInUser } from "~/utils/schemas";
import { setUpAuth } from "./auth";
import { EventTargetRecorder, setUpEvents } from "./events";
import { setUpMockAuth } from "./mock-auth";

View File

@ -2,7 +2,7 @@ import { User } from "@prisma/client";
import type { Express } from "express";
import { z } from "zod";
import { db } from "~/utils/db.server";
import type { LoggedInUser } from "~/validators/user";
import type { LoggedInUser } from "~/utils/schemas";
export function setUpMockAuth(
app: Express,

View File

@ -1,4 +1,4 @@
import { SeedVariationsSchema } from "~/validators/seedVariations";
import { SeedVariationsSchema } from "~/utils/schemas";
import { seed } from "../prisma/seed/script";
import type { Express } from "express";