Add jest and linter

do NOT update string-width, It destroys jest. I spent more time debugging this than I will writing the actual code, I do not wish this anguish upon my greatest enemy and have thus given fair warning...
This commit is contained in:
Ohm Patel 2024-02-18 22:39:00 -05:00
parent 23d0fb41e3
commit 2fbccbc523
21 changed files with 2862 additions and 374 deletions

7
.editorconfig Normal file
View File

@ -0,0 +1,7 @@
[*]
charset = utf-8
insert_final_newline = true
end_of_line = lf
indent_style = tab
indent_size = 2
max_line_length = 80

View File

@ -4,7 +4,7 @@ module.exports = {
node: true,
},
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
plugins: ["@typescript-eslint", "jest"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
@ -27,4 +27,14 @@ module.exports = {
"react/display-name": "off",
"react/no-unescaped-entities": "off",
},
overrides: [
{
files: ["**/*.test.ts", "**/*.test.js"],
env: {
"jest/globals": true
},
plugins: ["jest"],
extends: ["plugin:jest/recommended"],
},
]
};

8
.prettierrc Normal file
View File

@ -0,0 +1,8 @@
{
"plugins": ["prettier-plugin-tailwindcss"],
"tailwindConfig": "./tailwind.config.ts",
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"useTabs": true
}

8
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,8 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"bradlc.vscode-tailwindcss",
"drknoxy.eslint-disable-snippets"
]
}

25
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,25 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.run": "onSave",
"editor.formatOnSave": true,
"editor.quickSuggestions": {
"strings": "on"
},
"vscord.status.buttons.button1.git.active.enabled": false,
"editor.tabSize": 2,
"editor.insertSpaces": false,
"editor.detectIndentation": false,
"prettier.enable": true,
"files.associations": {
"*.css": "tailwindcss"
},
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"prettier.configPath": ".prettierrc"
}

View File

@ -0,0 +1,85 @@
import { DetailedBook } from "@/lib/book";
test("Correct book full", () => {
expect(
() =>
new DetailedBook({
id: 1,
title: "The Title",
category: ["fiction", "signed"],
last_updated: new Date(),
deleted: false,
subtitle: "🐄🐮🐄🐮🐄",
authors: "Polish cow",
isbn: "1234567890",
lccn: "1234567890",
edition: "1st",
publisher: "The Publisher",
publish_year: 2021,
publish_month: "January",
publish_location: "Poland",
pages: 100,
weight: "100g",
})
).not.toThrow();
});
test("Correct book partial", () => {
expect(
() =>
new DetailedBook({
id: 1,
title: "The Title",
category: ["fiction", "signed"],
last_updated: new Date("2021-01-01T00:00:00Z"),
deleted: false,
})
).not.toThrow();
});
test("Incorrect book no title", () => {
expect(
() =>
new DetailedBook({
id: 1,
category: ["fiction", "signed"],
last_updated: new Date("2021-01-01T00:00:00Z"),
deleted: false,
subtitle: "🐄🐮🐄🐮🐄",
authors: "Polish cow",
isbn: "1234567890",
lccn: "1234567890",
edition: "1st",
publisher: "The Publisher",
publish_year: 2021,
publish_month: "January",
publish_location: "Poland",
pages: 100,
weight: "100g",
} as unknown as DetailedBook)
).toThrow();
});
test("Incorrect book bad date", () => {
expect(
() =>
new DetailedBook({
id: 1,
title: "The Title",
category: ["fiction", "signed"],
last_updated: "banana",
deleted: false,
subtitle: "🐄🐮🐄🐮🐄",
authors: "Polish cow",
isbn: "1234567890",
lccn: "1234567890",
edition: "1st",
publisher: "The Publisher",
publish_year: 2021,
publish_month: "January",
publish_location: "Poland",
pages: 100,
weight: "100g",
} as unknown as DetailedBook)
).toThrow();
});

16
jest.config.js Normal file
View File

@ -0,0 +1,16 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const nextJest = require("next/jest");
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
});
// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
testEnvironment: "jsdom",
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);

2
jest.setup.js Normal file
View File

@ -0,0 +1,2 @@
// Learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom";

View File

@ -1,32 +1,44 @@
{
"name": "librarian-web",
"version": "0.0.0",
"main": "index.js",
"repository": "https://git.csclub.uwaterloo.ca/o32patel/librarian-web.git",
"author": "Ohm Patel <ohm.patel@uwaterloo.ca>",
"license": "GPL-3.0-or-later",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"daisyui": "^4.7.2",
"next": "^14.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^20.11.19",
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"autoprefixer": "^10.4.17",
"eslint": "^8.56.0",
"eslint-config-next": "^14.1.0",
"postcss": "^8.4.35",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
}
"name": "librarian-web",
"version": "0.0.0",
"main": "index.js",
"repository": "https://git.csclub.uwaterloo.ca/o32patel/librarian-web.git",
"author": "Ohm Patel <ohm.patel@uwaterloo.ca>",
"license": "GPL-3.0-or-later",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "prettier -w ./__tests__ ./src && next lint && eslint ./__tests__ --fix",
"test": "jest",
"test:ci": "jest --ci --coverage"
},
"dependencies": {
"daisyui": "^4.7.2",
"next": "^14.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"zod": "^3.22.4"
},
"devDependencies": {
"@testing-library/jest-dom": "6.1.5",
"@testing-library/react": "14.1.2",
"@types/jest": "29.5.11",
"@types/node": "^20.11.19",
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"autoprefixer": "^10.4.17",
"eslint": "^8.56.0",
"eslint-config-next": "^14.1.0",
"eslint-plugin-jest": "^27.9.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"postcss": "^8.4.35",
"prettier": "^3.2.5",
"prettier-plugin-tailwindcss": "^0.5.11",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3",
"string-width": "4.2.3"
}
}

View File

@ -1,6 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};

View File

@ -1,4 +0,0 @@
module.exports = {
plugins: [require("prettier-plugin-tailwindcss")],
tailwindConfig: "./tailwind.config.js",
};

View File

@ -3,31 +3,31 @@
@tailwind utilities;
:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}
@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}
body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}
@layer utilities {
.text-balance {
text-wrap: balance;
}
.text-balance {
text-wrap: balance;
}
}

View File

@ -5,18 +5,18 @@ import "./globals.css";
const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
children,
}: Readonly<{
children: React.ReactNode;
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
}

View File

@ -1,113 +1,113 @@
import Image from "next/image";
export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by editing&nbsp;
<code className="font-mono font-bold">src/app/page.tsx</code>
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{" "}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className="dark:invert"
width={100}
height={24}
priority
/>
</a>
</div>
</div>
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:dark:bg-zinc-800/30">
Get started by editing&nbsp;
<code className="font-mono font-bold">src/app/page.tsx</code>
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white lg:static lg:h-auto lg:w-auto lg:bg-none dark:from-black dark:via-black">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{" "}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className="dark:invert"
width={100}
height={24}
priority
/>
</a>
</div>
</div>
<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-full sm:before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-full sm:after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40 before:lg:h-[360px] z-[-1]">
<Image
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>
<div className="relative z-[-1] flex place-items-center before:absolute before:h-[300px] before:w-full before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-full after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] sm:before:w-[480px] sm:after:w-[240px] before:lg:h-[360px] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40">
<Image
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>
<div className="mb-32 grid text-center lg:max-w-5xl lg:w-full lg:mb-0 lg:grid-cols-4 lg:text-left">
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Docs{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Find in-depth information about Next.js features and API.
</p>
</a>
<div className="mb-32 grid text-center lg:mb-0 lg:w-full lg:max-w-5xl lg:grid-cols-4 lg:text-left">
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={"mb-3 text-2xl font-semibold"}>
Docs{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={"m-0 max-w-[30ch] text-sm opacity-50"}>
Find in-depth information about Next.js features and API.
</p>
</a>
<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Learn{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Learn about Next.js in an interactive course with&nbsp;quizzes!
</p>
</a>
<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={"mb-3 text-2xl font-semibold"}>
Learn{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={"m-0 max-w-[30ch] text-sm opacity-50"}>
Learn about Next.js in an interactive course with&nbsp;quizzes!
</p>
</a>
<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Templates{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Explore starter templates for Next.js.
</p>
</a>
<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={"mb-3 text-2xl font-semibold"}>
Templates{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={"m-0 max-w-[30ch] text-sm opacity-50"}>
Explore starter templates for Next.js.
</p>
</a>
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Deploy{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50 text-balance`}>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>
</main>
);
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={"mb-3 text-2xl font-semibold"}>
Deploy{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={"m-0 max-w-[30ch] text-balance text-sm opacity-50"}>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>
</main>
);
}

View File

@ -1,78 +1,61 @@
import { BookDetailedSchema, DateSchema } from "@/models/book";
import { z } from "zod";
import { Book, BookDetailedSchema } from "@/models/book";
// We do not implement Book or ModifyBook and instead only implement DetailedBook for homogeneity
export class DetailedBook {
id: number;
title: string;
category: string[];
last_updated: string;
deleted: boolean;
subtitle?: string;
authors?: string;
isbn?: string;
lccn?: string;
edition?: string;
publisher?: string;
publish_year?: number;
publish_month?: string;
publish_location?: string;
pages?: number;
weight?: string;
id: number;
title: string;
category: string[];
last_updated: Date;
deleted: boolean;
subtitle?: string;
authors?: string;
isbn?: string;
lccn?: string;
edition?: string;
publisher?: string;
publish_year?: number;
publish_month?: string;
publish_location?: string;
pages?: number;
weight?: string;
constructor (book: z.infer<typeof BookDetailedSchema>) {
this.id = book.id;
this.title = book.title;
this.category = book.category;
this.deleted = book.deleted;
this.last_updated = book.last_updated;
// Optional fields ↓
this.subtitle = book.subtitle;
this.authors = book.authors;
this.isbn = book.isbn;
this.lccn = book.lccn;
this.edition = book.edition;
this.publisher = book.publisher;
this.publish_year = book.publish_year;
this.publish_month = book.publish_month;
this.publish_location = book.publish_location;
this.pages = book.pages;
this.weight = book.weight;
constructor(book: Book) {
this.id = book.id;
this.title = book.title;
this.category = book.category;
this.deleted = book.deleted;
this.last_updated = book.last_updated;
// Optional fields ↓
this.subtitle = book.subtitle;
this.authors = book.authors;
this.isbn = book.isbn;
this.lccn = book.lccn;
this.edition = book.edition;
this.publisher = book.publisher;
this.publish_year = book.publish_year;
this.publish_month = book.publish_month;
this.publish_location = book.publish_location;
this.pages = book.pages;
this.weight = book.weight;
// Validate the book object
const result = BookDetailedSchema.safeParse(book);
if (!result.success) {
let error = "";
result.error.errors.forEach(err => {
error += err.message;
});
throw new Error(error);
}
}
// Validate the book object
const result = BookDetailedSchema.safeParse(book);
if (!result.success) {
let error = "";
result.error.errors.forEach((err) => {
error += err.message;
});
throw new Error(error);
}
}
// Getters
get authorsList() {
return this.authors?.split(",") || [];
}
// Getters
get authorsList() {
return this.authors?.split(",") || [];
}
get lastUpdated() {
return new Date(this.last_updated);
}
// Setters
set authorsList(authors: string[]) {
this.authors = authors.join(", ");
}
set lastUpdated(date: Date) {
const encodedDate = date.toISOString();
// Validate the date
const result = DateSchema.safeParse(encodedDate);
if (!result.success) {
throw new Error("Failed to encode last_updated date.");
}
this.last_updated = encodedDate;
}
}
// Setters
set authorsList(authors: string[]) {
this.authors = authors.join(", ");
}
}

View File

@ -1,50 +0,0 @@
const rfc3339Regex = /^(\d\d\d\d)\-(\d\d)\-(\d\d)T(\d\d):(\d\d):(\d\d)(\.\d+)?(Z|([+\-])(\d\d):(\d\d))$/;
export function ValidateRFC3339(datestring: string): boolean {
const match = datestring.match(rfc3339Regex);
if (match === null) {
return false;
}
const [, , year, month, day, hour, minute, second, , offset] = match;
const parsedYear = parseInt(year, 10);
const parsedMonth = parseInt(month, 10);
const parsedDay = parseInt(day, 10);
const parsedHour = parseInt(hour, 10);
const parsedMinute = parseInt(minute, 10);
const parsedSecond = parseInt(second, 10);
if (!(1 <= parsedYear && parsedYear <= 9999)) {
return false;
}
if (!(1 <= parsedMonth && parsedMonth <= 12)) {
return false;
}
const maxDay = new Date(parsedYear, parsedMonth, 0).getDate();
if (!(1 <= parsedDay && parsedDay <= maxDay)) {
return false;
}
if (!(0 <= parsedHour && parsedHour <= 23 && 0 <= parsedMinute && parsedMinute <= 59 && 0 <= parsedSecond && parsedSecond <= 59)) {
return false;
}
if (offset !== "Z") {
const match = offset.match(/([+-])(\d{2}):(\d{2})/);
if (match === null) {
return false;
}
const [, , , offsetHours, offsetMins] = match;
const parsedOffsetHours = parseInt(offsetHours, 10);
const parsedOffsetMins = parseInt(offsetMins, 10);
if (!(0 <= parsedOffsetHours && parsedOffsetHours <= 23 && 0 <= parsedOffsetMins && parsedOffsetMins <= 59)) {
return false;
}
}
return true;
}

View File

@ -1,27 +1,24 @@
import { ValidateRFC3339 } from "@/lib/utils";
import z from "zod";
export const DateSchema = z.string().refine(value => ValidateRFC3339(value), {
message: "Invalid date format, expected RFC3339",
});
export type Book = z.infer<typeof BookDetailedSchema>;
export const BookDetailedSchema = z.object({
id: z.number(),
title: z.string(),
subtitle: z.string().optional(),
authors: z.string().optional(),
category: z.array(z.string()),
isbn: z.string().optional(),
lccn: z.string().optional(),
edition: z.string().optional(),
publisher: z.string().optional(),
publish_year: z.number().optional(),
publish_month: z.string().optional(),
publish_location: z.string().optional(),
pages: z.number().optional(),
weight: z.string().optional(),
last_updated: DateSchema, // may want to use z.date() instead
deleted: z.boolean(),
id: z.number(),
title: z.string(),
subtitle: z.string().optional(),
authors: z.string().optional(),
category: z.array(z.string()),
isbn: z.string().optional(),
lccn: z.string().optional(),
edition: z.string().optional(),
publisher: z.string().optional(),
publish_year: z.number().optional(),
publish_month: z.string().optional(),
publish_location: z.string().optional(),
pages: z.number().optional(),
weight: z.string().optional(),
last_updated: z.date(),
deleted: z.boolean(),
});
/*
@ -35,4 +32,4 @@ export const BookSchema = z.object({
authors: z.string().optional(),
category: z.array(z.string()),
});
*/
*/

View File

@ -1,20 +1,20 @@
import type { Config } from "tailwindcss";
const config: Config = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
backgroundImage: {
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
"gradient-conic":
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
},
},
},
plugins: [],
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
backgroundImage: {
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
"gradient-conic":
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
},
},
},
plugins: [],
};
export default config;

View File

@ -1,5 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
@ -12,15 +13,23 @@
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@tests/*": ["./__tests__/*"]
},
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"types.d.ts",
".next/types/**/*.ts",
],
"exclude": ["node_modules"]
}
}

6
types.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
declare module "*module.css" {
const styles: {
[className: string]: string;
};
export default styles;
}

2456
yarn.lock

File diff suppressed because it is too large Load Diff